@rudderhq/server 0.2.8-canary.1 → 0.2.8-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/ui-dist/assets/{_basePickBy-CD-7Z_jN.js → _basePickBy-BboKqixH.js} +1 -1
- package/ui-dist/assets/{_baseUniq-CzQLGbtB.js → _baseUniq-B_G9qqt8.js} +1 -1
- package/ui-dist/assets/{arc-CjtF_Ren.js → arc-DiBPwl_i.js} +1 -1
- package/ui-dist/assets/{architectureDiagram-2XIMDMQ5-sV7uLBl5.js → architectureDiagram-2XIMDMQ5-DMs8dbsD.js} +1 -1
- package/ui-dist/assets/{blockDiagram-WCTKOSBZ-NGVDHpcW.js → blockDiagram-WCTKOSBZ-DChWbSb9.js} +1 -1
- package/ui-dist/assets/{c4Diagram-IC4MRINW-DrZWSRZy.js → c4Diagram-IC4MRINW-d3q58hg-.js} +1 -1
- package/ui-dist/assets/channel-DLKLnF_p.js +1 -0
- package/ui-dist/assets/{chunk-4BX2VUAB-CXiI5Zxj.js → chunk-4BX2VUAB-JsdxQzQR.js} +1 -1
- package/ui-dist/assets/{chunk-55IACEB6-BHgWSKNA.js → chunk-55IACEB6-Bd3SCwSF.js} +1 -1
- package/ui-dist/assets/{chunk-FMBD7UC4-DlfWhCeg.js → chunk-FMBD7UC4-BJA_WOms.js} +1 -1
- package/ui-dist/assets/{chunk-JSJVCQXG-BvgMJz5N.js → chunk-JSJVCQXG-Dx1fLK1x.js} +1 -1
- package/ui-dist/assets/{chunk-KX2RTZJC-DNOel2qU.js → chunk-KX2RTZJC-BlUr9hHd.js} +1 -1
- package/ui-dist/assets/{chunk-NQ4KR5QH-Cqbc6zOn.js → chunk-NQ4KR5QH-DWakv6k1.js} +1 -1
- package/ui-dist/assets/{chunk-QZHKN3VN-DiaVbBqT.js → chunk-QZHKN3VN-i5yGN1TY.js} +1 -1
- package/ui-dist/assets/{chunk-WL4C6EOR-IWXjfoWY.js → chunk-WL4C6EOR-DZ-6bnGF.js} +1 -1
- package/ui-dist/assets/classDiagram-VBA2DB6C-CPxg1XU4.js +1 -0
- package/ui-dist/assets/classDiagram-v2-RAHNMMFH-CPxg1XU4.js +1 -0
- package/ui-dist/assets/clone-CE45jyYH.js +1 -0
- package/ui-dist/assets/{cose-bilkent-S5V4N54A-C5tDUuDS.js → cose-bilkent-S5V4N54A-CK0iaHG8.js} +1 -1
- package/ui-dist/assets/{dagre-KLK3FWXG-DcfSsEBq.js → dagre-KLK3FWXG-cvwIbkup.js} +1 -1
- package/ui-dist/assets/{diagram-E7M64L7V-4pD0Z5q8.js → diagram-E7M64L7V-WCSvvYqO.js} +1 -1
- package/ui-dist/assets/{diagram-IFDJBPK2-BDJ6ZWZb.js → diagram-IFDJBPK2-BPQ3MleE.js} +1 -1
- package/ui-dist/assets/{diagram-P4PSJMXO-4JlUr5_d.js → diagram-P4PSJMXO-BpIhnNb4.js} +1 -1
- package/ui-dist/assets/{erDiagram-INFDFZHY-CKPTwwLW.js → erDiagram-INFDFZHY-7XzNcvPu.js} +1 -1
- package/ui-dist/assets/{flowDiagram-PKNHOUZH-OpXKp4se.js → flowDiagram-PKNHOUZH-CyhmUfdi.js} +1 -1
- package/ui-dist/assets/{ganttDiagram-A5KZAMGK-C27rKcZK.js → ganttDiagram-A5KZAMGK-CpUdQEtZ.js} +1 -1
- package/ui-dist/assets/{gitGraphDiagram-K3NZZRJ6-RMvHz1GX.js → gitGraphDiagram-K3NZZRJ6-7sNC5pqT.js} +1 -1
- package/ui-dist/assets/{graph-DBGDvFJJ.js → graph-BQcY4r7W.js} +1 -1
- package/ui-dist/assets/{index-DQIgDJJD.js → index-5lcSAjys.js} +1 -1
- package/ui-dist/assets/{index-RDOFpY3r.js → index-BPhU17F-.js} +1 -1
- package/ui-dist/assets/{index-BhoFRFOJ.js → index-BbKuqhjE.js} +5 -5
- package/ui-dist/assets/{index-IQg-mKY2.js → index-BnmdXCVY.js} +1 -1
- package/ui-dist/assets/{index-BwOeluhm.js → index-BqP6-nxC.js} +1 -1
- package/ui-dist/assets/{index-CBJ1GRlx.js → index-BwdvPKUU.js} +1 -1
- package/ui-dist/assets/{index-DyAGGhVR.js → index-CA-0GwR6.js} +1 -1
- package/ui-dist/assets/{index-CUmK5YNa.js → index-CGAxHUbg.js} +1 -1
- package/ui-dist/assets/{index-PghKETw5.js → index-CWst-Gyr.js} +1 -1
- package/ui-dist/assets/{index-Br5zwB0Z.js → index-CkIb_TPD.js} +1 -1
- package/ui-dist/assets/{index-D_H502gP.js → index-CliJxRSL.js} +1 -1
- package/ui-dist/assets/{index-DtA8NpRC.js → index-CmVicMGL.js} +1 -1
- package/ui-dist/assets/{index-HtPOAsph.js → index-CumScFRR.js} +1 -1
- package/ui-dist/assets/{index-BjDcoM23.js → index-DD81Lphy.js} +1 -1
- package/ui-dist/assets/{index-BNFWBcMX.js → index-DGFP2wZj.js} +1 -1
- package/ui-dist/assets/{index-CzGK9k2W.js → index-DMwAQqnu.js} +1 -1
- package/ui-dist/assets/{index-Cnn7Ze7A.js → index-DZhqrklZ.js} +1 -1
- package/ui-dist/assets/{index-DooRYrN2.js → index-DhQquf6V.js} +1 -1
- package/ui-dist/assets/{index-CxutLWF3.js → index-Dp3z6CO7.js} +1 -1
- package/ui-dist/assets/{index-D7g9B35Q.js → index-DtC5ZMkw.js} +1 -1
- package/ui-dist/assets/{index-DRi3oX80.js → index-NidjZwyA.js} +1 -1
- package/ui-dist/assets/{index-BF94W45f.js → index-X1myEhaI.js} +1 -1
- package/ui-dist/assets/{index-RV97u8HI.js → index-eH8xDFNd.js} +1 -1
- package/ui-dist/assets/{infoDiagram-LFFYTUFH-CCPehB1n.js → infoDiagram-LFFYTUFH-LX-H5a3w.js} +1 -1
- package/ui-dist/assets/{ishikawaDiagram-PHBUUO56-QRUyM-bG.js → ishikawaDiagram-PHBUUO56-CBOuBxhN.js} +1 -1
- package/ui-dist/assets/{journeyDiagram-4ABVD52K-C-WTAun9.js → journeyDiagram-4ABVD52K-DSNiZ_sR.js} +1 -1
- package/ui-dist/assets/{kanban-definition-K7BYSVSG-CoDdCWNo.js → kanban-definition-K7BYSVSG-SWLrtuT8.js} +1 -1
- package/ui-dist/assets/{layout-BcfquhXG.js → layout-B66DUxKl.js} +1 -1
- package/ui-dist/assets/{linear-CExWNwJu.js → linear-BmqTQykD.js} +1 -1
- package/ui-dist/assets/{mermaid.core-D3HFVWWP.js → mermaid.core-B2JfLRuZ.js} +4 -4
- package/ui-dist/assets/{mindmap-definition-YRQLILUH-DIDhRQwy.js → mindmap-definition-YRQLILUH-CyZVew2K.js} +1 -1
- package/ui-dist/assets/{pieDiagram-SKSYHLDU-CjRK9Kys.js → pieDiagram-SKSYHLDU-DstP6Df0.js} +1 -1
- package/ui-dist/assets/{quadrantDiagram-337W2JSQ-Dm0v6QP8.js → quadrantDiagram-337W2JSQ-DCDV90j-.js} +1 -1
- package/ui-dist/assets/{requirementDiagram-Z7DCOOCP-BOXs5Exi.js → requirementDiagram-Z7DCOOCP-FfMq8cCz.js} +1 -1
- package/ui-dist/assets/{sankeyDiagram-WA2Y5GQK-BeewOrIM.js → sankeyDiagram-WA2Y5GQK-DJuvtLVb.js} +1 -1
- package/ui-dist/assets/{sequenceDiagram-2WXFIKYE-05PicUdw.js → sequenceDiagram-2WXFIKYE-BViBjo5o.js} +1 -1
- package/ui-dist/assets/{stateDiagram-RAJIS63D-DfqrUrOu.js → stateDiagram-RAJIS63D-BBg6azND.js} +1 -1
- package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-BHLPmnxU.js +1 -0
- package/ui-dist/assets/{timeline-definition-YZTLITO2-BkgwCWCZ.js → timeline-definition-YZTLITO2-CjWHHPcG.js} +1 -1
- package/ui-dist/assets/{treemap-KZPCXAKY-Cz2TPBTj.js → treemap-KZPCXAKY-DaSF8YS0.js} +1 -1
- package/ui-dist/assets/{vennDiagram-LZ73GAT5-DiMknW2W.js → vennDiagram-LZ73GAT5-BvsV6owN.js} +1 -1
- package/ui-dist/assets/{xychartDiagram-JWTSCODW-CmGBeabL.js → xychartDiagram-JWTSCODW-CYzWz-n4.js} +1 -1
- package/ui-dist/index.html +1 -1
- package/ui-dist/assets/channel-CVPeuk8A.js +0 -1
- package/ui-dist/assets/classDiagram-VBA2DB6C-DECsXiYo.js +0 -1
- package/ui-dist/assets/classDiagram-v2-RAHNMMFH-DECsXiYo.js +0 -1
- package/ui-dist/assets/clone-DJBMNZbG.js +0 -1
- package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-DnlcW2tI.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CumScFRR.js","assets/index-DMwAQqnu.js","assets/index-BnmdXCVY.js","assets/index-CkIb_TPD.js","assets/index-CA-0GwR6.js","assets/index-CGAxHUbg.js","assets/index-X1myEhaI.js","assets/index-CliJxRSL.js","assets/index-BPhU17F-.js","assets/index-DtC5ZMkw.js","assets/index-DGFP2wZj.js","assets/index-eH8xDFNd.js","assets/index-BwdvPKUU.js","assets/index-DZhqrklZ.js","assets/index-DD81Lphy.js","assets/index-5lcSAjys.js","assets/index-Dp3z6CO7.js","assets/index-NidjZwyA.js","assets/index-CWst-Gyr.js","assets/index-BqP6-nxC.js","assets/dockerfile-BKs6k2Af.js","assets/simple-mode-GW_nhZxv.js","assets/factor-kuTfRLto.js","assets/nsis-LdVXkNf5.js","assets/pug-DeIclll2.js","assets/javascript-iXu5QeM3.js","assets/index-DhQquf6V.js","assets/index-CmVicMGL.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var B9e=Object.defineProperty;var rG=e=>{throw TypeError(e)};var U9e=(e,t,n)=>t in e?B9e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Bi=(e,t,n)=>U9e(e,typeof t!="symbol"?t+"":t,n),DT=(e,t,n)=>t.has(e)||rG("Cannot "+n);var ze=(e,t,n)=>(DT(e,t,"read from private field"),n?n.call(e):t.get(e)),An=(e,t,n)=>t.has(e)?rG("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Zt=(e,t,n,r)=>(DT(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),xr=(e,t,n)=>(DT(e,t,"access private method"),n);var Ow=(e,t,n,r)=>({set _(i){Zt(e,t,i,n)},get _(){return ze(e,t,r)}});function boe(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const a=Object.getOwnPropertyDescriptor(r,i);a&&Object.defineProperty(e,i,a.get?a:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const o of a.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=n(i);fetch(i.href,a)}})();var sG=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function U5(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function J_t(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}),n}var LT={exports:{}},Bb={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -1294,7 +1294,7 @@ When you submit the join request, use:
|
|
|
1294
1294
|
`))};if((Qt.mac||Qt.android)&&f.from==o-1&&/^\. ?$/.test(r.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:c,insert:ls.of([r.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let h=this.to-this.from+(f.to-f.from+f.insert.length);Oq(t,f,bt.single(this.toEditorPos(r.selectionStart,h),this.toEditorPos(r.selectionEnd,h)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let i=[],a=null;for(let o=this.toEditorPos(r.rangeStart),l=this.toEditorPos(r.rangeEnd);o<l;o++){let c=t.coordsForChar(o);a=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||a||new DOMRect,i.push(a)}n.updateCharacterBounds(r.rangeStart,i)},this.handlers.textformatupdate=r=>{let i=[];for(let a of r.getTextFormats()){let o=a.underlineStyle,l=a.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let c=this.toEditorPos(a.rangeStart),u=this.toEditorPos(a.rangeEnd);if(c<u){let d=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;i.push($n.mark({attributes:{style:d}}).range(c,u))}}}t.dispatch({effects:K3e.of($n.set(i))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(t.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let i=A6(r.root);i&&i.rangeCount&&this.editContext.updateSelectionBounds(i.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let n=0,r=!1,i=this.pendingContextChange;return t.changes.iterChanges((a,o,l,c,u)=>{if(r)return;let d=u.length-(o-a);if(i&&o>=i.to)if(i.from==a&&i.to==o&&i.insert.eq(u)){i=this.pendingContextChange=null,n+=d,this.to+=d;return}else i=null,this.revertPending(t.state);if(a+=n,o+=n,o<=this.from)this.from+=d,this.to+=d;else if(a<this.to){if(a<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(a),this.toContextPos(o),u.toString()),this.to+=d}n+=d}),i&&!r&&this.revertPending(t.state),!r}update(t){let n=this.pendingContextChange,r=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(r.from,r.to)&&t.transactions.some(i=>!i.isUserEvent("input.type")&&i.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||n)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:n}=t.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(t.doc.length,n+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),t.doc.sliceString(n.from,n.to))}setSelection(t){let{main:n}=t.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),i=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=i)&&this.editContext.updateSelection(r,i)}rangeIsValid(t){let{head:n}=t.selection.main;return!(this.from>0&&n-this.from<500||this.to<t.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(t,n=this.to-this.from){t=Math.min(t,n);let r=this.composing;return r&&r.drifted?r.editorBase+(t-r.contextBase):t+this.from}toContextPos(t){let n=this.composing;return n&&n.drifted?n.contextBase+(t-n.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class Yt{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:r}=t;this.dispatchTransactions=t.dispatchTransactions||r&&(i=>i.forEach(a=>r(a,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||$it(t.parent)||document,this.viewState=new bte(this,t.state||Yr.create(t)),t.scrollTo&&t.scrollTo.is(p9)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(l3).map(i=>new xM(i));for(let i of this.plugins)i.update(this);this.observer=new oot(this),this.inputState=new Tat(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ite(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let n=t.length==1&&t[0]instanceof ja?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(n,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,i,a=this.state;for(let h of t){if(h.startState!=a)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");a=h.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,l=0,c=null;t.some(h=>h.annotation(a5e))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=o5e(a,o),c||(l=1));let u=this.observer.delayedAndroidKey,d=null;if(u?(this.observer.clearDelayedAndroidKey(),d=this.observer.readChange(),(d&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(d=null)):this.observer.clear(),a.facet(Yr.phrases)!=this.state.facet(Yr.phrases))return this.setState(a);i=$N.create(this,a,t),i.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let h of t){if(f&&(f=f.map(h.changes)),h.scrollIntoView){let{main:g}=h.state.selection;f=new _3(g.empty?g:bt.cursor(g.head,g.head>g.anchor?-1:1))}for(let g of h.effects)g.is(p9)&&(f=g.value.clip(this.state))}this.viewState.update(i,f),this.bidiCache=qN.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),n=this.docView.update(i),this.state.facet(Vy)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(h=>h.isUserEvent("select.pointer")))}finally{this.updateState=0}if(i.startState.facet(w9)!=i.state.facet(w9)&&(this.viewState.mustMeasureContent=!0),(n||r||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!i.empty)for(let h of this.state.facet(NL))try{h(i)}catch(g){rc(this.state,g,"update listener")}(c||d)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),d&&!X3e(this,d)&&u.force&&S3(this.contentDOM,u.key,u.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new bte(this,t),this.plugins=t.facet(l3).map(r=>new xM(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new ite(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(t){let n=t.startState.facet(l3),r=t.state.facet(l3);if(n!=r){let i=[];for(let a of r){let o=n.indexOf(a);if(o<0)i.push(new xM(a));else{let l=this.plugins[o];l.mustUpdate=t,i.push(l)}}for(let a of this.plugins)a.mustUpdate!=t&&a.destroy(this);this.plugins=i,this.pluginMap.clear()}else for(let i of this.plugins)i.mustUpdate=t;for(let i=0;i<this.plugins.length;i++)this.plugins[i].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let n=t.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){rc(this.state,r,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,i=this.viewState.getScrollOffset(),{scrollAnchorPos:a,scrollAnchorHeight:o}=this.viewState;Math.abs(i-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(_3e(r||this.win))a=-1,o=this.viewState.heightMap.height;else{let g=this.viewState.scrollAnchorAt(i);a=g.from,o=g.top}this.updateState=1;let c=this.viewState.measure();if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let u=[];c&4||([this.measureRequests,u]=[u,this.measureRequests]);let d=u.map(g=>{try{return g.read(this)}catch(b){return rc(this.state,b),jte}}),f=$N.create(this,this.state,[]),h=!1;f.flags|=c,n?n.flags|=c:n=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let g=0;g<u.length;g++)if(d[g]!=jte)try{let b=u[g];b.write&&b.write(d[g],this)}catch(b){rc(this.state,b)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let b=((a<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(a).top)-o)/this.scaleY;if((b>1||b<-1)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){i=i+b,r?r.scrollTop+=b:this.win.scrollBy(0,b),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(NL))l(n)}get themeClasses(){return TL+" "+(this.state.facet(EL)?d5e:u5e)+" "+this.state.facet(w9)}updateAttrs(){let t=Nte(this,H3e,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Gm)?"true":"false",class:"cm-content",style:`${Qt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),Nte(this,Iq,n);let r=this.observer.ignore(()=>{let i=Xee(this.contentDOM,this.contentAttrs,n),a=Xee(this.dom,this.editorAttrs,t);return i||a});return this.editorAttrs=t,this.contentAttrs=n,r}showAnnouncements(t){let n=!0;for(let r of t)for(let i of r.effects)if(i.is(Yt.announce)){n&&(this.announceDOM.textContent=""),n=!1;let a=this.announceDOM.appendChild(document.createElement("div"));a.textContent=i.value}}mountStyles(){this.styleModules=this.state.facet(Vy);let t=this.state.facet(Yt.cspNonce);Bp.mount(this.root,this.styleModules.concat(iot).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===t.key){this.measureRequests[n]=t;return}}this.measureRequests.push(t)}}plugin(t){let n=this.pluginMap.get(t);return(n===void 0||n&&n.plugin!=t)&&this.pluginMap.set(t,n=this.plugins.find(r=>r.plugin==t)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,n,r){return wM(this,t,ate(this,t,n,r))}moveByGroup(t,n){return wM(this,t,ate(this,t,n,r=>vat(this,t.head,r)))}visualLineSide(t,n){let r=this.bidiSpans(t),i=this.textDirectionAt(t.from),a=r[n?r.length-1:0];return bt.cursor(a.side(n,i)+t.from,a.forward(!n,i)?1:-1)}moveToLineBoundary(t,n,r=!0){return yat(this,t,n,r)}moveVertically(t,n,r){return wM(this,t,wat(this,t,n,r))}domAtPos(t,n=1){return this.docView.domAtPos(t,n)}posAtDOM(t,n=0){return this.docView.posFromDOM(t,n)}posAtCoords(t,n=!0){this.readMeasured();let r=_L(this,t,n);return r&&r.pos}posAndSideAtCoords(t,n=!0){return this.readMeasured(),_L(this,t,n)}coordsAtPos(t,n=1){this.readMeasured();let r=this.docView.coordsAt(t,n);if(!r||r.left==r.right)return r;let i=this.state.doc.lineAt(t),a=this.bidiSpans(i),o=a[Af.find(a,t-i.from,-1,n)];return LN(r,o.dir==Hs.LTR==n>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(B3e)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>uot)return R3e(t.length);let n=this.textDirectionAt(t.from),r;for(let a of this.bidiCache)if(a.from==t.from&&a.dir==n&&(a.fresh||M3e(a.isolates,r=nte(this,t))))return a.order;r||(r=nte(this,t));let i=Vit(t.text,n,r);return this.bidiCache.push(new qN(t.from,t.to,n,r,!0,i)),i}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Qt.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{S3e(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,n={}){return p9.of(new _3(typeof t=="number"?bt.cursor(t):t,n.y,n.x,n.yMargin,n.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(t);return p9.of(new _3(bt.cursor(r.from),"start","start",r.top-t,n,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ia.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ia.define(()=>({}),{eventObservers:t})}static theme(t,n){let r=Bp.newName(),i=[w9.of(r),Vy.of(IL(`.${r}`,t))];return n&&n.dark&&i.push(EL.of(!0)),i}static baseTheme(t){return lg.lowest(Vy.of(IL("."+TL,t,f5e)))}static findFromDOM(t){var n;let r=t.querySelector(".cm-content"),i=r&&Zi.get(r)||Zi.get(t);return((n=i==null?void 0:i.root)===null||n===void 0?void 0:n.view)||null}}Yt.styleModule=Vy;Yt.inputHandler=F3e;Yt.clipboardInputFilter=Eq;Yt.clipboardOutputFilter=Tq;Yt.scrollHandler=q3e;Yt.focusChangeEffect=z3e;Yt.perLineTextDirection=B3e;Yt.exceptionSink=$3e;Yt.updateListener=NL;Yt.editable=Gm;Yt.mouseSelectionStyle=L3e;Yt.dragMovesSelection=D3e;Yt.clickAddsSelectionRange=P3e;Yt.decorations=H_;Yt.blockWrappers=V3e;Yt.outerDecorations=Mq;Yt.atomicRanges=K7;Yt.bidiIsolatedRanges=W3e;Yt.scrollMargins=Z3e;Yt.darkTheme=EL;Yt.cspNonce=Jt.define({combine:e=>e.length?e[0]:""});Yt.contentAttributes=Iq;Yt.editorAttributes=H3e;Yt.lineWrapping=Yt.contentAttributes.of({class:"cm-lineWrapping"});Yt.announce=ir.define();const uot=4096,jte={};class qN{constructor(t,n,r,i,a,o){this.from=t,this.to=n,this.dir=r,this.isolates=i,this.fresh=a,this.order=o}static update(t,n){if(n.empty&&!t.some(a=>a.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:Hs.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==i&&!n.touchesRange(o.from,o.to)&&r.push(new qN(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function Nte(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let a=r[i],o=typeof a=="function"?a(e):a;o&&Sq(o,n)}return n}const dot=Qt.mac?"mac":Qt.windows?"win":Qt.linux?"linux":"key";function fot(e,t){const n=e.split(/-(?!$)/);let r=n[n.length-1];r=="Space"&&(r=" ");let i,a,o,l;for(let c=0;c<n.length-1;++c){const u=n[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))i=!0;else if(/^(c|ctrl|control)$/i.test(u))a=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))t=="mac"?l=!0:a=!0;else throw new Error("Unrecognized modifier name: "+u)}return i&&(r="Alt-"+r),a&&(r="Ctrl-"+r),l&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function k9(e,t,n){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n!==!1&&t.shiftKey&&(e="Shift-"+e),e}const mot=lg.default(Yt.domEventHandlers({keydown(e,t){return h5e(m5e(t.state),e,t,"editor")}})),H7=Jt.define({enables:mot}),Cte=new WeakMap;function m5e(e){let t=e.facet(H7),n=Cte.get(t);return n||Cte.set(t,n=got(t.reduce((r,i)=>r.concat(i),[]))),n}function hot(e,t,n){return h5e(m5e(e.state),t,e,n)}let Dh=null;const pot=4e3;function got(e,t=dot){let n=Object.create(null),r=Object.create(null),i=(o,l)=>{let c=r[o];if(c==null)r[o]=l;else if(c!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},a=(o,l,c,u,d)=>{var f,h;let g=n[o]||(n[o]=Object.create(null)),b=l.split(/ (?!$)/).map(k=>fot(k,t));for(let k=1;k<b.length;k++){let w=b.slice(0,k).join(" ");i(w,!0),g[w]||(g[w]={preventDefault:!0,stopPropagation:!1,run:[N=>{let C=Dh={view:N,prefix:w,scope:o};return setTimeout(()=>{Dh==C&&(Dh=null)},pot),!0}]})}let v=b.join(" ");i(v,!1);let j=g[v]||(g[v]={preventDefault:!1,stopPropagation:!1,run:((h=(f=g._any)===null||f===void 0?void 0:f.run)===null||h===void 0?void 0:h.slice())||[]});c&&j.run.push(c),u&&(j.preventDefault=!0),d&&(j.stopPropagation=!0)};for(let o of e){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of l){let d=n[u]||(n[u]=Object.create(null));d._any||(d._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let h in d)d[h].run.push(g=>f(g,ML))}let c=o[t]||o.key;if(c)for(let u of l)a(u,c,o.run,o.preventDefault,o.stopPropagation),o.shift&&a(u,"Shift-"+c,o.shift,o.preventDefault,o.stopPropagation)}return n}let ML=null;function h5e(e,t,n,r){ML=t;let i=Tit(t),a=Xl(i,0),o=wf(a)==i.length&&i!=" ",l="",c=!1,u=!1,d=!1;Dh&&Dh.view==n&&Dh.scope==r&&(l=Dh.prefix+" ",n5e.indexOf(t.keyCode)<0&&(u=!0,Dh=null));let f=new Set,h=j=>{if(j){for(let k of j.run)if(!f.has(k)&&(f.add(k),k(n)))return j.stopPropagation&&(d=!0),!0;j.preventDefault&&(j.stopPropagation&&(d=!0),u=!0)}return!1},g=e[r],b,v;return g&&(h(g[l+k9(i,t,!o)])?c=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Qt.windows&&t.ctrlKey&&t.altKey)&&!(Qt.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(b=Up[t.keyCode])&&b!=i?(h(g[l+k9(b,t,!0)])||t.shiftKey&&(v=S6[t.keyCode])!=i&&v!=b&&h(g[l+k9(v,t,!1)]))&&(c=!0):o&&t.shiftKey&&h(g[l+k9(i,t,!0)])&&(c=!0),!c&&h(g._any)&&(c=!0)),u&&(c=!0),c&&d&&t.stopPropagation(),ML=null,c}class A2{constructor(t,n,r,i,a){this.className=t,this.left=n,this.top=r,this.width=i,this.height=a}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,n){return n.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,n,r){if(r.empty){let i=t.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let a=p5e(t);return[new A2(n,i.left-a.left,i.top-a.top,null,i.bottom-i.top)]}else return xot(t,n,r)}}function p5e(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==Hs.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function Ste(e,t,n,r){let i=e.coordsAtPos(t,n*2);if(!i)return r;let a=e.dom.getBoundingClientRect(),o=(i.top+i.bottom)/2,l=e.posAtCoords({x:a.left+1,y:o}),c=e.posAtCoords({x:a.right-1,y:o});return l==null||c==null?r:{from:Math.max(r.from,Math.min(l,c)),to:Math.min(r.to,Math.max(l,c))}}function xot(e,t,n){if(n.to<=e.viewport.from||n.from>=e.viewport.to)return[];let r=Math.max(n.from,e.viewport.from),i=Math.min(n.to,e.viewport.to),a=e.textDirection==Hs.LTR,o=e.contentDOM,l=o.getBoundingClientRect(),c=p5e(e),u=o.querySelector(".cm-line"),d=u&&window.getComputedStyle(u),f=l.left+(d?parseInt(d.paddingLeft)+Math.min(0,parseInt(d.textIndent)):0),h=l.right-(d?parseInt(d.paddingRight):0),g=SL(e,r,1),b=SL(e,i,-1),v=g.type==Do.Text?g:null,j=b.type==Do.Text?b:null;if(v&&(e.lineWrapping||g.widgetLineBreaks)&&(v=Ste(e,r,1,v)),j&&(e.lineWrapping||b.widgetLineBreaks)&&(j=Ste(e,i,-1,j)),v&&j&&v.from==j.from&&v.to==j.to)return w(N(n.from,n.to,v));{let A=v?N(n.from,null,v):C(g,!1),_=j?N(null,n.to,j):C(b,!0),E=[];return(v||g).to<(j||b).from-(v&&j?1:0)||g.widgetLineBreaks>1&&A.bottom+e.defaultLineHeight/2<_.top?E.push(k(f,A.bottom,h,_.top)):A.bottom<_.top&&e.elementAtHeight((A.bottom+_.top)/2).type==Do.Text&&(A.bottom=_.top=(A.bottom+_.top)/2),w(A).concat(E).concat(w(_))}function k(A,_,E,T){return new A2(t,A-c.left,_-c.top,Math.max(0,E-A),T-_)}function w({top:A,bottom:_,horizontal:E}){let T=[];for(let M=0;M<E.length;M+=2)T.push(k(E[M],A,E[M+1],_));return T}function N(A,_,E){let T=1e9,M=-1e9,O=[];function P(Q,ee,B,F,Z){let W=e.coordsAtPos(Q,Q==E.to?-2:2),$=e.coordsAtPos(B,B==E.from?2:-2);!W||!$||(T=Math.min(W.top,$.top,T),M=Math.max(W.bottom,$.bottom,M),Z==Hs.LTR?O.push(a&&ee?f:W.left,a&&F?h:$.right):O.push(!a&&F?f:$.left,!a&&ee?h:W.right))}let z=A??E.from,L=_??E.to;for(let Q of e.visibleRanges)if(Q.to>z&&Q.from<L)for(let ee=Math.max(Q.from,z),B=Math.min(Q.to,L);;){let F=e.state.doc.lineAt(ee);for(let Z of e.bidiSpans(F)){let W=Z.from+F.from,$=Z.to+F.from;if(W>=B)break;$>ee&&P(Math.max(W,ee),A==null&&W<=z,Math.min($,B),_==null&&$>=L,Z.dir)}if(ee=F.to+1,ee>=B)break}return O.length==0&&P(z,A==null,L,_==null,e.textDirection),{top:T,bottom:M,horizontal:O}}function C(A,_){let E=l.top+(_?A.top:A.bottom);return{top:E,bottom:E,horizontal:[]}}}function bot(e,t){return e.constructor==t.constructor&&e.eq(t)}class yot{constructor(t,n){this.view=t,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,t)}update(t){t.startState.facet(Wk)!=t.state.facet(Wk)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let n=0,r=t.facet(Wk);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:n}=this.view;(t!=this.scaleX||n!=this.scaleY)&&(this.scaleX=t,this.scaleY=n,this.dom.style.transform=`scale(${1/t}, ${1/n})`)}draw(t){if(t.length!=this.drawn.length||t.some((n,r)=>!bot(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let i of t)i.update&&n&&i.constructor&&this.drawn[r].constructor&&i.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(i.draw(),n);for(;n;){let i=n.nextSibling;n.remove(),n=i}this.drawn=t,Qt.safari&&Qt.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Wk=Jt.define();function g5e(e){return[ia.define(t=>new yot(t,e)),Wk.of(e)]}const E5=Jt.define({combine(e){return im(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,n)=>Math.min(t,n),drawRangeCursor:(t,n)=>t||n})}});function vot(e={}){return[E5.of(e),wot,kot,jot,U3e.of(!0)]}function x5e(e){return e.startState.facet(E5)!=e.state.facet(E5)}const wot=g5e({above:!0,markers(e){let{state:t}=e,n=t.facet(E5),r=[];for(let i of t.selection.ranges){let a=i==t.selection.main;if(i.empty||n.drawRangeCursor&&!(a&&Qt.ios&&n.iosSelectionHandles)){let o=a?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=i.empty?i:bt.cursor(i.head,i.assoc);for(let c of A2.forRange(e,o,l))r.push(c)}}return r},update(e,t){e.transactions.some(r=>r.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=x5e(e);return n&&_te(e.state,t),e.docChanged||e.selectionSet||n},mount(e,t){_te(t.state,e)},class:"cm-cursorLayer"});function _te(e,t){t.style.animationDuration=e.facet(E5).cursorBlinkRate+"ms"}const kot=g5e({above:!1,markers(e){let t=[],{main:n,ranges:r}=e.state.selection;for(let i of r)if(!i.empty)for(let a of A2.forRange(e,"cm-selectionBackground",i))t.push(a);if(Qt.ios&&!n.empty&&e.state.facet(E5).iosSelectionHandles){for(let i of A2.forRange(e,"cm-selectionHandle cm-selectionHandle-start",bt.cursor(n.from,1)))t.push(i);for(let i of A2.forRange(e,"cm-selectionHandle cm-selectionHandle-end",bt.cursor(n.to,1)))t.push(i)}return t},update(e,t){return e.docChanged||e.selectionSet||e.viewportChanged||x5e(e)},class:"cm-selectionLayer"}),jot=lg.highest(Yt.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),b5e=ir.define({map(e,t){return e==null?null:t.mapPos(e)}}),Zy=qo.define({create(){return null},update(e,t){return e!=null&&(e=t.changes.mapPos(e)),t.effects.reduce((n,r)=>r.is(b5e)?r.value:n,e)}}),Not=ia.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let n=e.state.field(Zy);n==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(Zy)!=n||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(Zy),n=t!=null&&e.coordsAtPos(t);if(!n)return null;let r=e.scrollDOM.getBoundingClientRect();return{left:n.left-r.left+e.scrollDOM.scrollLeft*e.scaleX,top:n.top-r.top+e.scrollDOM.scrollTop*e.scaleY,height:n.bottom-n.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:n}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/n+"px",this.cursor.style.height=e.height/n+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(Zy)!=e&&this.view.dispatch({effects:b5e.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){(e.target==this.view.contentDOM||!this.view.contentDOM.contains(e.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Cot(){return[Zy,Not]}function Ate(e,t,n,r,i){t.lastIndex=0;for(let a=e.iterRange(n,r),o=n,l;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;l=t.exec(a.value);)i(o+l.index,l)}function Sot(e,t){let n=e.visibleRanges;if(n.length==1&&n[0].from==e.viewport.from&&n[0].to==e.viewport.to)return n;let r=[];for(let{from:i,to:a}of n)i=Math.max(e.state.doc.lineAt(i).from,i-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),r.length&&r[r.length-1].to>=i?r[r.length-1].to=a:r.push({from:i,to:a});return r}class _ot{constructor(t){const{regexp:n,decoration:r,decorate:i,boundary:a,maxLength:o=1e3}=t;if(!n.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=n,i)this.addMatch=(l,c,u,d)=>i(d,u,u+l[0].length,l,c);else if(typeof r=="function")this.addMatch=(l,c,u,d)=>{let f=r(l,c,u);f&&d(u,u+l[0].length,f)};else if(r)this.addMatch=(l,c,u,d)=>d(u,u+l[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=a,this.maxLength=o}createDeco(t){let n=new S1,r=n.add.bind(n);for(let{from:i,to:a}of Sot(t,this.maxLength))Ate(t.state.doc,this.regexp,i,a,(o,l)=>this.addMatch(l,t,o,r));return n.finish()}updateDeco(t,n){let r=1e9,i=-1;return t.docChanged&&t.changes.iterChanges((a,o,l,c)=>{c>=t.view.viewport.from&&l<=t.view.viewport.to&&(r=Math.min(l,r),i=Math.max(c,i))}),t.viewportMoved||i-r>1e3?this.createDeco(t.view):i>-1?this.updateRange(t.view,n.map(t.changes),r,i):n}updateRange(t,n,r,i){for(let a of t.visibleRanges){let o=Math.max(a.from,r),l=Math.min(a.to,i);if(l>=o){let c=t.state.doc.lineAt(o),u=c.to<l?t.state.doc.lineAt(l):c,d=Math.max(a.from,c.from),f=Math.min(a.to,u.to);if(this.boundary){for(;o>c.from;o--)if(this.boundary.test(c.text[o-1-c.from])){d=o;break}for(;l<u.to;l++)if(this.boundary.test(u.text[l-u.from])){f=l;break}}let h=[],g,b=(v,j,k)=>h.push(k.range(v,j));if(c==u)for(this.regexp.lastIndex=d-c.from;(g=this.regexp.exec(c.text))&&g.index<f-c.from;)this.addMatch(g,t,g.index+c.from,b);else Ate(t.state.doc,this.regexp,d,f,(v,j)=>this.addMatch(j,t,v,b));n=n.update({filterFrom:d,filterTo:f,filter:(v,j)=>v<d||j>f,add:h})}}return n}}const RL=/x/.unicode!=null?"gu":"g",Aot=new RegExp(`[\0-\b
|
|
1295
1295
|
--\u2028\u2029\uFEFF-]`,RL),Eot={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let NM=null;function Tot(){var e;if(NM==null&&typeof document<"u"&&document.body){let t=document.body.style;NM=((e=t.tabSize)!==null&&e!==void 0?e:t.MozTabSize)!=null}return NM||!1}const Zk=Jt.define({combine(e){let t=im(e,{render:null,specialChars:Aot,addSpecialChars:null});return(t.replaceTabs=!Tot())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,RL)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,RL)),t}});function Iot(e={}){return[Zk.of(e),Mot()]}let Ete=null;function Mot(){return Ete||(Ete=ia.fromClass(class{constructor(e){this.view=e,this.decorations=$n.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(Zk)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new _ot({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:i}=n.state,a=Xl(t[0],0);if(a==9){let o=i.lineAt(r),l=n.state.tabSize,c=I4(o.text,l,r-o.from);return $n.replace({widget:new Dot((l-c%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=$n.replace({widget:new Pot(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(Zk);e.startState.facet(Zk)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))}const Rot="•";function Oot(e){return e>=32?Rot:e==10?"":String.fromCharCode(9216+e)}class Pot extends am{constructor(t,n){super(),this.options=t,this.code=n}eq(t){return t.code==this.code}toDOM(t){let n=Oot(this.code),r=t.state.phrase("Control character")+" "+(Eot[this.code]||"0x"+this.code.toString(16)),i=this.options.render&&this.options.render(this.code,r,n);if(i)return i;let a=document.createElement("span");return a.textContent=n,a.title=r,a.setAttribute("aria-label",r),a.className="cm-specialChar",a}ignoreEvent(){return!1}}class Dot extends am{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function Lot(){return Fot}const $ot=$n.line({class:"cm-activeLine"}),Fot=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,n=[];for(let r of e.state.selection.ranges){let i=e.lineBlockAt(r.head);i.from>t&&(n.push($ot.range(i.from)),t=i.from)}return $n.set(n)}},{decorations:e=>e.decorations}),OL=2e3;function zot(e,t,n){let r=Math.min(t.line,n.line),i=Math.max(t.line,n.line),a=[];if(t.off>OL||n.off>OL||t.col<0||n.col<0){let o=Math.min(t.off,n.off),l=Math.max(t.off,n.off);for(let c=r;c<=i;c++){let u=e.doc.line(c);u.length<=l&&a.push(bt.range(u.from+o,u.to+l))}}else{let o=Math.min(t.col,n.col),l=Math.max(t.col,n.col);for(let c=r;c<=i;c++){let u=e.doc.line(c),d=mL(u.text,o,e.tabSize,!0);if(d<0)a.push(bt.cursor(u.to));else{let f=mL(u.text,l,e.tabSize);a.push(bt.range(u.from+d,u.from+f))}}}return a}function Bot(e,t){let n=e.coordsAtPos(e.viewport.from);return n?Math.round(Math.abs((n.left-t)/e.defaultCharacterWidth)):-1}function Tte(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1),r=e.state.doc.lineAt(n),i=n-r.from,a=i>OL?-1:i==r.length?Bot(e,t.clientX):I4(r.text,e.state.tabSize,n-r.from);return{line:r.number,col:a,off:i}}function Uot(e,t){let n=Tte(e,t),r=e.state.selection;return n?{update(i){if(i.docChanged){let a=i.changes.mapPos(i.startState.doc.line(n.line).from),o=i.state.doc.lineAt(a);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},r=r.map(i.changes)}},get(i,a,o){let l=Tte(e,i);if(!l)return r;let c=zot(e.state,n,l);return c.length?o?bt.create(c.concat(r.ranges)):bt.create(c):r}}:null}function qot(e){let t=(n=>n.altKey&&n.button==0);return Yt.mouseSelectionStyle.of((n,r)=>t(r)?Uot(n,r):null)}const Kot={Alt:[18,e=>!!e.altKey],Control:[17,e=>!!e.ctrlKey],Shift:[16,e=>!!e.shiftKey],Meta:[91,e=>!!e.metaKey]},Hot={style:"cursor: crosshair"};function Vot(e={}){let[t,n]=Kot[e.key||"Alt"],r=ia.fromClass(class{constructor(i){this.view=i,this.isDown=!1}set(i){this.isDown!=i&&(this.isDown=i,this.view.update([]))}},{eventObservers:{keydown(i){this.set(i.keyCode==t||n(i))},keyup(i){(i.keyCode==t||!n(i))&&this.set(!1)},mousemove(i){this.set(n(i))}}});return[r,Yt.contentAttributes.of(i=>{var a;return!((a=i.plugin(r))===null||a===void 0)&&a.isDown?Hot:null})]}const j9="-10000px";class y5e{constructor(t,n,r,i){this.facet=n,this.createTooltipView=r,this.removeTooltipView=i,this.input=t.state.facet(n),this.tooltips=this.input.filter(o=>o);let a=null;this.tooltipViews=this.tooltips.map(o=>a=r(o,a))}update(t,n){var r;let i=t.state.facet(this.facet),a=i.filter(c=>c);if(i===this.input){for(let c of this.tooltipViews)c.update&&c.update(t);return!1}let o=[],l=n?[]:null;for(let c=0;c<a.length;c++){let u=a[c],d=-1;if(u){for(let f=0;f<this.tooltips.length;f++){let h=this.tooltips[f];h&&h.create==u.create&&(d=f)}if(d<0)o[c]=this.createTooltipView(u,c?o[c-1]:null),l&&(l[c]=!!u.above);else{let f=o[c]=this.tooltipViews[d];l&&(l[c]=n[d]),f.update&&f.update(t)}}}for(let c of this.tooltipViews)o.indexOf(c)<0&&(this.removeTooltipView(c),(r=c.destroy)===null||r===void 0||r.call(c));return n&&(l.forEach((c,u)=>n[u]=c),n.length=l.length),this.input=i,this.tooltips=a,this.tooltipViews=o,!0}}function Wot(e){let t=e.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const CM=Jt.define({combine:e=>{var t,n,r;return{position:Qt.ios?"absolute":((t=e.find(i=>i.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((n=e.find(i=>i.parent))===null||n===void 0?void 0:n.parent)||null,tooltipSpace:((r=e.find(i=>i.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||Wot}}}),Ite=new WeakMap,Lq=ia.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(CM);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new y5e(e,$q,(n,r)=>this.createTooltip(n,r),n=>{this.resizeObserver&&this.resizeObserver.unobserve(n.dom),n.dom.remove()}),this.above=this.manager.tooltips.map(n=>!!n.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(n=>{Date.now()>this.lastTransaction-50&&n.length>0&&n[n.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let n=t||e.geometryChanged,r=e.state.facet(CM);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let i of this.manager.tooltipViews)i.dom.style.position=this.position;n=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let i of this.manager.tooltipViews)this.container.appendChild(i.dom);n=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);n&&this.maybeMeasure()}createTooltip(e,t){let n=e.create(this.view),r=t?t.dom:null;if(n.dom.classList.add("cm-tooltip"),e.arrow&&!n.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let i=document.createElement("div");i.className="cm-tooltip-arrow",n.dom.appendChild(i)}return n.dom.style.position=this.position,n.dom.style.top=j9,n.dom.style.left="0px",this.container.insertBefore(n.dom,r),n.mount&&n.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(n.dom),n}destroy(){var e,t,n;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(e=r.destroy)===null||e===void 0||e.call(r);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=1,t=1,n=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:a}=this.manager.tooltipViews[0];if(Qt.safari){let o=a.getBoundingClientRect();n=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else n=!!a.offsetParent&&a.offsetParent!=this.container.ownerDocument.body}if(n||this.position=="absolute")if(this.parent){let a=this.parent.getBoundingClientRect();a.width&&a.height&&(e=a.width/this.parent.offsetWidth,t=a.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),i=Rq(this.view);return{visible:{left:r.left+i.left,top:r.top+i.top,right:r.right-i.right,bottom:r.bottom-i.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((a,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(a.pos):this.view.coordsAtPos(a.pos)}),size:this.manager.tooltipViews.map(({dom:a})=>a.getBoundingClientRect()),space:this.view.state.facet(CM).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:n}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:n,space:r,scaleX:i,scaleY:a}=e,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let c=this.manager.tooltips[l],u=this.manager.tooltipViews[l],{dom:d}=u,f=e.pos[l],h=e.size[l];if(!f||c.clip!==!1&&(f.bottom<=Math.max(n.top,r.top)||f.top>=Math.min(n.bottom,r.bottom)||f.right<Math.max(n.left,r.left)-.1||f.left>Math.min(n.right,r.right)+.1)){d.style.top=j9;continue}let g=c.arrow?u.dom.querySelector(".cm-tooltip-arrow"):null,b=g?7:0,v=h.right-h.left,j=(t=Ite.get(u))!==null&&t!==void 0?t:h.bottom-h.top,k=u.offset||Got,w=this.view.textDirection==Hs.LTR,N=h.width>r.right-r.left?w?r.left:r.right-h.width:w?Math.max(r.left,Math.min(f.left-(g?14:0)+k.x,r.right-v)):Math.min(Math.max(r.left,f.left-v+(g?14:0)-k.x),r.right-v),C=this.above[l];!c.strictSide&&(C?f.top-j-b-k.y<r.top:f.bottom+j+b+k.y>r.bottom)&&C==r.bottom-f.bottom>f.top-r.top&&(C=this.above[l]=!C);let A=(C?f.top-r.top:r.bottom-f.bottom)-b;if(A<j&&u.resize!==!1){if(A<this.view.defaultLineHeight){d.style.top=j9;continue}Ite.set(u,j),d.style.height=(j=A)/a+"px"}else d.style.height&&(d.style.height="");let _=C?f.top-j-b-k.y:f.bottom+b+k.y,E=N+v;if(u.overlap!==!0)for(let T of o)T.left<E&&T.right>N&&T.top<_+j&&T.bottom>_&&(_=C?T.top-j-2-b:T.bottom+b+2);if(this.position=="absolute"?(d.style.top=(_-e.parent.top)/a+"px",Mte(d,(N-e.parent.left)/i)):(d.style.top=_/a+"px",Mte(d,N/i)),g){let T=f.left+(w?k.x:-k.x)-(N+14-7);g.style.left=T/i+"px"}u.overlap!==!0&&o.push({left:N,top:_,right:E,bottom:_+j}),d.classList.toggle("cm-tooltip-above",C),d.classList.toggle("cm-tooltip-below",!C),u.positioned&&u.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=j9}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Mte(e,t){let n=parseInt(e.style.left,10);(isNaN(n)||Math.abs(t-n)>1)&&(e.style.left=t+"px")}const Zot=Yt.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Got={x:0,y:0},$q=Jt.define({enables:[Lq,Zot]}),KN=Jt.define({combine:e=>e.reduce((t,n)=>t.concat(n),[])});class G_{static create(t){return new G_(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new y5e(t,KN,(n,r)=>this.createHostedView(n,r),n=>n.dom.remove())}createHostedView(t,n){let r=t.create(this.view);return r.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(r.dom,n?n.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}mount(t){for(let n of this.manager.tooltipViews)n.mount&&n.mount(t);this.mounted=!0}positioned(t){for(let n of this.manager.tooltipViews)n.positioned&&n.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let n of this.manager.tooltipViews)(t=n.destroy)===null||t===void 0||t.call(n)}passProp(t){let n;for(let r of this.manager.tooltipViews){let i=r[t];if(i!==void 0){if(n===void 0)n=i;else if(n!==i)return}}return n}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Qot=$q.compute([KN],e=>{let t=e.facet(KN);return t.length===0?null:{pos:Math.min(...t.map(n=>n.pos)),end:Math.max(...t.map(n=>{var r;return(r=n.end)!==null&&r!==void 0?r:n.pos})),create:G_.create,above:t[0].above,arrow:t.some(n=>n.arrow)}});class Yot{constructor(t,n,r,i,a){this.view=t,this.source=n,this.field=r,this.setHover=i,this.hoverTime=a,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:n}=this,r=t.docView.tile.nearest(n.target);if(!r)return;let i,a=1;if(r.isWidget())i=r.posAtStart;else{if(i=t.posAtCoords(n),i==null)return;let l=t.coordsAtPos(i);if(!l||n.y<l.top||n.y>l.bottom||n.x<l.left-t.defaultCharacterWidth||n.x>l.right+t.defaultCharacterWidth)return;let c=t.bidiSpans(t.state.doc.lineAt(i)).find(d=>d.from<=i&&d.to>=i),u=c&&c.dir==Hs.RTL?-1:1;a=n.x<l.left?-u:u}let o=this.source(t,i,a);if(o!=null&&o.then){let l=this.pending={pos:i};o.then(c=>{this.pending==l&&(this.pending=null,c&&!(Array.isArray(c)&&!c.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(c)?c:[c])}))},c=>rc(t.state,c,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(Lq),n=t?t.manager.tooltips.findIndex(r=>r.create==G_.create):-1;return n>-1?t.manager.tooltipViews[n]:null}mousemove(t){var n,r;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:i,tooltip:a}=this;if(i.length&&a&&!Jot(a.dom,t)||this.pending){let{pos:o}=i[0]||this.pending,l=(r=(n=i[0])===null||n===void 0?void 0:n.end)!==null&&r!==void 0?r:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!Xot(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:n}=this;if(n.length){let{tooltip:r}=this;r&&r.dom.contains(t.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let n=r=>{t.removeEventListener("mouseleave",n),this.active.length&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",n)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const N9=4;function Jot(e,t){let{left:n,right:r,top:i,bottom:a}=e.getBoundingClientRect(),o;if(o=e.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();i=Math.min(l.top,i),a=Math.max(l.bottom,a)}return t.clientX>=n-N9&&t.clientX<=r+N9&&t.clientY>=i-N9&&t.clientY<=a+N9}function Xot(e,t,n,r,i,a){let o=e.scrollDOM.getBoundingClientRect(),l=e.documentTop+e.documentPadding.top+e.contentHeight;if(o.left>r||o.right<r||o.top>i||Math.min(o.bottom,l)<i)return!1;let c=e.posAtCoords({x:r,y:i},!1);return c>=t&&c<=n}function elt(e,t={}){let n=ir.define(),r=qo.define({create(){return[]},update(i,a){if(i.length&&(t.hideOnChange&&(a.docChanged||a.selection)?i=[]:t.hideOn&&(i=i.filter(o=>!t.hideOn(a,o))),a.docChanged)){let o=[];for(let l of i){let c=a.changes.mapPos(l.pos,-1,To.TrackDel);if(c!=null){let u=Object.assign(Object.create(null),l);u.pos=c,u.end!=null&&(u.end=a.changes.mapPos(u.end)),o.push(u)}}i=o}for(let o of a.effects)o.is(n)&&(i=o.value),o.is(tlt)&&(i=[]);return i},provide:i=>KN.from(i)});return{active:r,extension:[r,ia.define(i=>new Yot(i,e,r,n,t.hoverTime||300)),Qot]}}function v5e(e,t){let n=e.plugin(Lq);if(!n)return null;let r=n.manager.tooltips.indexOf(t);return r<0?null:n.manager.tooltipViews[r]}const tlt=ir.define(),Rte=Jt.define({combine(e){let t,n;for(let r of e)t=t||r.topContainer,n=n||r.bottomContainer;return{topContainer:t,bottomContainer:n}}});function Fq(e,t){let n=e.plugin(w5e),r=n?n.specs.indexOf(t):-1;return r>-1?n.panels[r]:null}const w5e=ia.fromClass(class{constructor(e){this.input=e.state.facet(T6),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(e));let t=e.state.facet(Rte);this.top=new C9(e,!0,t.topContainer),this.bottom=new C9(e,!1,t.bottomContainer),this.top.sync(this.panels.filter(n=>n.top)),this.bottom.sync(this.panels.filter(n=>!n.top));for(let n of this.panels)n.dom.classList.add("cm-panel"),n.mount&&n.mount()}update(e){let t=e.state.facet(Rte);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new C9(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new C9(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=e.state.facet(T6);if(n!=this.input){let r=n.filter(c=>c),i=[],a=[],o=[],l=[];for(let c of r){let u=this.specs.indexOf(c),d;u<0?(d=c(e.view),l.push(d)):(d=this.panels[u],d.update&&d.update(e)),i.push(d),(d.top?a:o).push(d)}this.specs=r,this.panels=i,this.top.sync(a),this.bottom.sync(o);for(let c of l)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let r of this.panels)r.update&&r.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class C9{constructor(t,n,r){this.view=t,this.top=n,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let n of this.panels)n.destroy&&t.indexOf(n)<0&&n.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let n=this.container||this.view.dom;n.insertBefore(this.dom,this.top?n.firstChild:null)}let t=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;t!=n.dom;)t=Ote(t);t=t.nextSibling}else this.dom.insertBefore(n.dom,t);for(;t;)t=Ote(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Ote(e){let t=e.nextSibling;return e.remove(),t}const T6=Jt.define({enables:w5e});function nlt(e,t){let n,r=new Promise(o=>n=o),i=o=>rlt(o,t,n);e.state.field(SM,!1)?e.dispatch({effects:k5e.of(i)}):e.dispatch({effects:ir.appendConfig.of(SM.init(()=>[i]))});let a=j5e.of(i);return{close:a,result:r.then(o=>((e.win.queueMicrotask||(c=>e.win.setTimeout(c,10)))(()=>{e.state.field(SM).indexOf(i)>-1&&e.dispatch({effects:a})}),o))}}const SM=qo.define({create(){return[]},update(e,t){for(let n of t.effects)n.is(k5e)?e=[n.value].concat(e):n.is(j5e)&&(e=e.filter(r=>r!=n.value));return e},provide:e=>T6.computeN([e],t=>t.field(e))}),k5e=ir.define(),j5e=ir.define();function rlt(e,t,n){let r=t.content?t.content(e,()=>o(null)):null;if(!r){if(r=Ps("form"),t.input){let l=Ps("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),r.appendChild(Ps("label",(t.label||"")+": ",l))}else r.appendChild(document.createTextNode(t.label||""));r.appendChild(document.createTextNode(" ")),r.appendChild(Ps("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let i=r.nodeName=="FORM"?[r]:r.querySelectorAll("form");for(let l=0;l<i.length;l++){let c=i[l];c.addEventListener("keydown",u=>{u.keyCode==27?(u.preventDefault(),o(null)):u.keyCode==13&&(u.preventDefault(),o(c))}),c.addEventListener("submit",u=>{u.preventDefault(),o(c)})}let a=Ps("div",r,Ps("button",{onclick:()=>o(null),"aria-label":e.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(a.className=t.class),a.classList.add("cm-dialog");function o(l){a.contains(a.ownerDocument.activeElement)&&e.focus(),n(l)}return{dom:a,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=r.querySelector(t.focus):l=r.querySelector("input")||r.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class A1 extends zp{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}A1.prototype.elementClass="";A1.prototype.toDOM=void 0;A1.prototype.mapMode=To.TrackBefore;A1.prototype.startSide=A1.prototype.endSide=-1;A1.prototype.point=!0;const Gk=Jt.define(),slt=Jt.define(),ilt={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Lr.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Cv=Jt.define();function alt(e){return[N5e(),Cv.of({...ilt,...e})]}const Pte=Jt.define({combine:e=>e.some(t=>t)});function N5e(e){return[olt]}const olt=ia.fromClass(class{constructor(e){this.view=e,this.domAfter=null,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(Cv).map(t=>new Lte(e,t)),this.fixed=!e.state.facet(Pte);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(e){if(this.updateGutters(e)){let t=this.prevViewport,n=e.view.viewport,r=Math.min(t.to,n.to)-Math.max(t.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(e.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Pte)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=Lr.iter(this.view.state.facet(Gk),this.view.viewport.from),r=[],i=this.gutters.map(a=>new llt(a,this.view.viewport,-this.view.documentPadding.top));for(let a of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(a.type)){let o=!0;for(let l of a.type)if(l.type==Do.Text&&o){PL(n,r,l.from);for(let c of i)c.line(this.view,l,r);o=!1}else if(l.widget)for(let c of i)c.widget(this.view,l)}else if(a.type==Do.Text){PL(n,r,a.from);for(let o of i)o.line(this.view,a,r)}else if(a.widget)for(let o of i)o.widget(this.view,a);for(let a of i)a.finish();e&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(e){let t=e.startState.facet(Cv),n=e.state.facet(Cv),r=e.docChanged||e.heightChanged||e.viewportChanged||!Lr.eq(e.startState.facet(Gk),e.state.facet(Gk),e.view.viewport.from,e.view.viewport.to);if(t==n)for(let i of this.gutters)i.update(e)&&(r=!0);else{r=!0;let i=[];for(let a of n){let o=t.indexOf(a);o<0?i.push(new Lte(this.view,a)):(this.gutters[o].update(e),i.push(this.gutters[o]))}for(let a of this.gutters)a.dom.remove(),i.indexOf(a)<0&&a.destroy();for(let a of i)a.config.side=="after"?this.getDOMAfter().appendChild(a.dom):this.dom.appendChild(a.dom);this.gutters=i}return r}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*t.scaleX,i=n.domAfter?n.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==Hs.LTR?{left:r,right:i}:{right:r,left:i}})});function Dte(e){return Array.isArray(e)?e:[e]}function PL(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}class llt{constructor(t,n,r){this.gutter=t,this.height=r,this.i=0,this.cursor=Lr.iter(t.markers,n.from)}addElement(t,n,r){let{gutter:i}=this,a=(n.top-this.height)/t.scaleY,o=n.height/t.scaleY;if(this.i==i.elements.length){let l=new C5e(t,o,a,r);i.elements.push(l),i.dom.appendChild(l.dom)}else i.elements[this.i].update(t,o,a,r);this.height=n.bottom,this.i++}line(t,n,r){let i=[];PL(this.cursor,i,n.from),r.length&&(i=i.concat(r));let a=this.gutter.config.lineMarker(t,n,i);a&&i.unshift(a);let o=this.gutter;i.length==0&&!o.config.renderEmptyElements||this.addElement(t,n,i)}widget(t,n){let r=this.gutter.config.widgetMarker(t,n.widget,n),i=r?[r]:null;for(let a of t.state.facet(slt)){let o=a(t,n.widget,n);o&&(i||(i=[])).push(o)}i&&this.addElement(t,n,i)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let n=t.elements.pop();t.dom.removeChild(n.dom),n.destroy()}}}class Lte{constructor(t,n){this.view=t,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,i=>{let a=i.target,o;if(a!=this.dom&&this.dom.contains(a)){for(;a.parentNode!=this.dom;)a=a.parentNode;let c=a.getBoundingClientRect();o=(c.top+c.bottom)/2}else o=i.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);n.domEventHandlers[r](t,l,i)&&i.preventDefault()});this.markers=Dte(n.markers(t)),n.initialSpacer&&(this.spacer=new C5e(t,0,0,[n.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let n=this.markers;if(this.markers=Dte(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let i=this.config.updateSpacer(this.spacer.markers[0],t);i!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[i])}let r=t.view.viewport;return!Lr.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class C5e{constructor(t,n,r,i){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,n,r,i)}update(t,n,r,i){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),clt(this.markers,i)||this.setMarkers(t,i)}setMarkers(t,n){let r="cm-gutterElement",i=this.dom.firstChild;for(let a=0,o=0;;){let l=o,c=a<n.length?n[a++]:null,u=!1;if(c){let d=c.elementClass;d&&(r+=" "+d);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(c)){l=f,u=!0;break}}else l=this.markers.length;for(;o<l;){let d=this.markers[o++];if(d.toDOM){d.destroy(i);let f=i.nextSibling;i.remove(),i=f}}if(!c)break;c.toDOM&&(u?i=i.nextSibling:this.dom.insertBefore(c.toDOM(t),i)),u&&o++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}}function clt(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].compare(t[n]))return!1;return!0}const ult=Jt.define(),dlt=Jt.define(),c3=Jt.define({combine(e){return im(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,n){let r=Object.assign({},t);for(let i in n){let a=r[i],o=n[i];r[i]=a?(l,c,u)=>a(l,c,u)||o(l,c,u):o}return r}})}});class _M extends A1{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function AM(e,t){return e.state.facet(c3).formatNumber(t,e.state)}const flt=Cv.compute([c3],e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(ult)},lineMarker(t,n,r){return r.some(i=>i.toDOM)?null:new _M(AM(t,t.state.doc.lineAt(n.from).number))},widgetMarker:(t,n,r)=>{for(let i of t.state.facet(dlt)){let a=i(t,n,r);if(a)return a}return null},lineMarkerChange:t=>t.startState.facet(c3)!=t.state.facet(c3),initialSpacer(t){return new _M(AM(t,$te(t.state.doc.lines)))},updateSpacer(t,n){let r=AM(n.view,$te(n.view.state.doc.lines));return r==t.number?t:new _M(r)},domEventHandlers:e.facet(c3).domEventHandlers,side:"before"}));function S5e(e={}){return[c3.of(e),N5e(),flt]}function $te(e){let t=9;for(;t<e;)t=t*10+9;return t}const mlt=new class extends A1{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},hlt=Gk.compute(["selection"],e=>{let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.head).from;i>n&&(n=i,t.push(mlt.range(i)))}return Lr.of(t)});function plt(){return hlt}const glt=1024;let xlt=0,vu=class{constructor(t,n){this.from=t,this.to=n}};class Or{constructor(t={}){this.id=xlt++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=Ll.match(t)),n=>{let r=t(n);return r===void 0?null:[this,r]}}}Or.closedBy=new Or({deserialize:e=>e.split(" ")});Or.openedBy=new Or({deserialize:e=>e.split(" ")});Or.group=new Or({deserialize:e=>e.split(" ")});Or.isolate=new Or({deserialize:e=>{if(e&&e!="rtl"&&e!="ltr"&&e!="auto")throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}});Or.contextHash=new Or({perNode:!0});Or.lookAhead=new Or({perNode:!0});Or.mounted=new Or({perNode:!0});class A3{constructor(t,n,r,i=!1){this.tree=t,this.overlay=n,this.parser=r,this.bracketed=i}static get(t){return t&&t.props&&t.props[Or.mounted.id]}}const blt=Object.create(null);class Ll{constructor(t,n,r,i=0){this.name=t,this.props=n,this.id=r,this.flags=i}static define(t){let n=t.props&&t.props.length?Object.create(null):blt,r=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new Ll(t.name||"",n,t.id,r);if(t.props){for(let a of t.props)if(Array.isArray(a)||(a=a(i)),a){if(a[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[a[0].id]=a[1]}}return i}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let n=this.prop(Or.group);return n?n.indexOf(t)>-1:!1}return this.id==t}static match(t){let n=Object.create(null);for(let r in t)for(let i of r.split(" "))n[i]=t[r];return r=>{for(let i=r.prop(Or.group),a=-1;a<(i?i.length:0);a++){let o=n[a<0?r.name:i[a]];if(o)return o}}}}Ll.none=new Ll("",Object.create(null),0,8);class zq{constructor(t){this.types=t;for(let n=0;n<t.length;n++)if(t[n].id!=n)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let n=[];for(let r of this.types){let i=null;for(let a of t){let o=a(r);if(o){i||(i=Object.assign({},r.props));let l=o[1],c=o[0];c.combine&&c.id in i&&(l=c.combine(i[c.id],l)),i[c.id]=l}}n.push(i?new Ll(r.name,i,r.id,r.flags):r)}return new zq(n)}}const S9=new WeakMap,Fte=new WeakMap;var Ks;(function(e){e[e.ExcludeBuffers=1]="ExcludeBuffers",e[e.IncludeAnonymous=2]="IncludeAnonymous",e[e.IgnoreMounts=4]="IgnoreMounts",e[e.IgnoreOverlays=8]="IgnoreOverlays",e[e.EnterBracketed=16]="EnterBracketed"})(Ks||(Ks={}));class Vs{constructor(t,n,r,i,a){if(this.type=t,this.children=n,this.positions=r,this.length=i,this.props=null,a&&a.length){this.props=Object.create(null);for(let[o,l]of a)this.props[typeof o=="number"?o:o.id]=l}}toString(){let t=A3.get(this);if(t&&!t.overlay)return t.tree.toString();let n="";for(let r of this.children){let i=r.toString();i&&(n&&(n+=","),n+=i)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(t=0){return new HN(this.topNode,t)}cursorAt(t,n=0,r=0){let i=S9.get(this)||this.topNode,a=new HN(i);return a.moveTo(t,n),S9.set(this,a._tree),a}get topNode(){return new al(this,0,0,null)}resolve(t,n=0){let r=I6(S9.get(this)||this.topNode,t,n,!1);return S9.set(this,r),r}resolveInner(t,n=0){let r=I6(Fte.get(this)||this.topNode,t,n,!0);return Fte.set(this,r),r}resolveStack(t,n=0){return wlt(this,t,n)}iterate(t){let{enter:n,leave:r,from:i=0,to:a=this.length}=t,o=t.mode||0,l=(o&Ks.IncludeAnonymous)>0;for(let c=this.cursor(o|Ks.IncludeAnonymous);;){let u=!1;if(c.from<=a&&c.to>=i&&(!l&&c.type.isAnonymous||n(c)!==!1)){if(c.firstChild())continue;u=!0}for(;u&&r&&(l||!c.type.isAnonymous)&&r(c),!c.nextSibling();){if(!c.parent())return;u=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let n in this.props)t.push([+n,this.props[n]]);return t}balance(t={}){return this.children.length<=8?this:qq(Ll.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,i)=>new Vs(this.type,n,r,i,this.propValues),t.makeTree||((n,r,i)=>new Vs(Ll.none,n,r,i)))}static build(t){return klt(t)}}Vs.empty=new Vs(Ll.none,[],[],0);class Bq{constructor(t,n){this.buffer=t,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Bq(this.buffer,this.index)}}class Kp{constructor(t,n,r){this.buffer=t,this.length=n,this.set=r}get type(){return Ll.none}toString(){let t=[];for(let n=0;n<this.buffer.length;)t.push(this.childString(n)),n=this.buffer[n+3];return t.join(",")}childString(t){let n=this.buffer[t],r=this.buffer[t+3],i=this.set.types[n],a=i.name;if(/\W/.test(a)&&!i.isError&&(a=JSON.stringify(a)),t+=4,r==t)return a;let o=[];for(;t<r;)o.push(this.childString(t)),t=this.buffer[t+3];return a+"("+o.join(",")+")"}findChild(t,n,r,i,a){let{buffer:o}=this,l=-1;for(let c=t;c!=n&&!(_5e(a,i,o[c+1],o[c+2])&&(l=c,r>0));c=o[c+3]);return l}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let l=t,c=0;l<n;){a[c++]=i[l++],a[c++]=i[l++]-r;let u=a[c++]=i[l++]-r;a[c++]=i[l++]-t,o=Math.max(o,u)}return new Kp(a,o,this.set)}}function _5e(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function I6(e,t,n,r){for(var i;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let o=!r&&e instanceof al&&e.index<0?null:e.parent;if(!o)return e;e=o}let a=r?0:Ks.IgnoreOverlays;if(r)for(let o=e,l=o.parent;l;o=l,l=o.parent)o instanceof al&&o.index<0&&((i=l.enter(t,n,a))===null||i===void 0?void 0:i.from)!=o.from&&(e=l);for(;;){let o=e.enter(t,n,a);if(!o)return e;e=o}}class A5e{cursor(t=0){return new HN(this,t)}getChild(t,n=null,r=null){let i=zte(this,t,n,r);return i.length?i[0]:null}getChildren(t,n=null,r=null){return zte(this,t,n,r)}resolve(t,n=0){return I6(this,t,n,!1)}resolveInner(t,n=0){return I6(this,t,n,!0)}matchContext(t){return DL(this.parent,t)}enterUnfinishedNodesBefore(t){let n=this.childBefore(t),r=this;for(;n;){let i=n.lastChild;if(!i||i.to!=n.to)break;i.type.isError&&i.from==i.to?(r=n,n=i.prevSibling):n=i}return r}get node(){return this}get next(){return this.parent}}class al extends A5e{constructor(t,n,r,i){super(),this._tree=t,this.from=n,this.index=r,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:l,positions:c}=o._tree,u=n>0?l.length:-1;t!=u;t+=n){let d=l[t],f=c[t]+o.from,h;if(!(!(a&Ks.EnterBracketed&&d instanceof Vs&&(h=A3.get(d))&&!h.overlay&&h.bracketed&&r>=f&&r<=f+d.length)&&!_5e(i,r,f,f+d.length))){if(d instanceof Kp){if(a&Ks.ExcludeBuffers)continue;let g=d.findChild(0,d.buffer.length,n,r-f,i);if(g>-1)return new Ef(new ylt(o,d,t,f),null,g)}else if(a&Ks.IncludeAnonymous||!d.type.isAnonymous||Uq(d)){let g;if(!(a&Ks.IgnoreMounts)&&(g=A3.get(d))&&!g.overlay)return new al(g.tree,f,t,o);let b=new al(d,f,t,o);return a&Ks.IncludeAnonymous||!b.type.isAnonymous?b:b.nextChild(n<0?d.children.length-1:0,n,r,i,a)}}}if(a&Ks.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+n:t=n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,n,r=0){let i;if(!(r&Ks.IgnoreOverlays)&&(i=A3.get(this._tree))&&i.overlay){let a=t-this.from,o=r&Ks.EnterBracketed&&i.bracketed;for(let{from:l,to:c}of i.overlay)if((n>0||o?l<=a:l<a)&&(n<0||o?c>=a:c>a))return new al(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function zte(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let o=!1;!o;)if(o=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function DL(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}class ylt{constructor(t,n,r,i){this.parent=t,this.buffer=n,this.index=r,this.start=i}}class Ef extends A5e{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,n,r){super(),this.context=t,this._parent=n,this.index=r,this.type=t.buffer.set.types[t.buffer.buffer[r]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new Ef(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,n,r=0){if(r&Ks.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new Ef(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new Ef(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new Ef(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],n=[],{buffer:r}=this.context,i=this.index+4,a=r.buffer[this.index+3];if(a>i){let o=r.buffer[this.index+1];t.push(r.slice(i,a,o)),n.push(0)}return new Vs(this.type,t,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function E5e(e){if(!e.length)return null;let t=0,n=e[0];for(let a=1;a<e.length;a++){let o=e[a];(o.from>n.from||o.to<n.to)&&(n=o,t=a)}let r=n instanceof al&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new vlt(i,n)}class vlt{constructor(t,n){this.heads=t,this.node=n}get next(){return E5e(this.heads)}}function wlt(e,t,n){let r=e.resolveInner(t,n),i=null;for(let a=r instanceof al?r:r.context.parent;a;a=a.parent)if(a.index<0){let o=a.parent;(i||(i=[r])).push(o.resolve(t,n)),a=o}else{let o=A3.get(a.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new al(o.tree,o.overlay[0].from+a.from,-1,a);(i||(i=[r])).push(I6(l,t,n,!1))}}return i?E5e(i):r}class HN{get name(){return this.type.name}constructor(t,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~Ks.EnterBracketed,t instanceof al)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let r=t._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,n){this.index=t;let{start:r,buffer:i}=this.buffer;return this.type=n||i.set.types[i.buffer[t]],this.from=r+i.buffer[t+1],this.to=r+i.buffer[t+2],!0}yield(t){return t?t instanceof al?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,n,r,this.mode));let{buffer:i}=this.buffer,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.buffer.start,r);return a<0?!1:(this.stack.push(this.index),this.yieldBuf(a))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,n,r=this.mode){return this.buffer?r&Ks.ExcludeBuffers?!1:this.enterChild(1,t,n):this.yield(this._tree.enter(t,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Ks.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Ks.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(t<0){let i=r<0?0:this.stack[r]+4;if(this.index!=i)return this.yieldBuf(n.findChild(i,this.index,-1,0,4))}else{let i=n.buffer[this.index+3];if(i<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(i)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let n,r,{buffer:i}=this;if(i){if(t>0){if(this.index<i.buffer.buffer.length)return!1}else for(let a=0;a<this.index;a++)if(i.buffer.buffer[a+3]<this.index)return!1;({index:n,parent:r}=i)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let a=n+t,o=t<0?-1:r._tree.children.length;a!=o;a+=t){let l=r._tree.children[a];if(this.mode&Ks.IncludeAnonymous||l instanceof Kp||!l.type.isAnonymous||Uq(l))return!1}return!0}move(t,n){if(n&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,n=0){for(;(this.from==this.to||(n<1?this.from>=t:this.from>t)||(n>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,n););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,n=null,r=0;if(t&&t.context==this.buffer)e:for(let i=this.index,a=this.stack.length;a>=0;){for(let o=t;o;o=o._parent)if(o.index==i){if(i==this.index)return o;n=o,r=a+1;break e}i=this.stack[--a]}for(let i=r;i<this.stack.length;i++)n=new Ef(this.buffer,n,this.stack[i]);return this.bufferNode=new Ef(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,n){for(let r=0;;){let i=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(i=!0)}for(;;){if(i&&n&&n(this),i=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,i=!0}}}matchContext(t){if(!this.buffer)return DL(this.node.parent,t);let{buffer:n}=this.buffer,{types:r}=n.set;for(let i=t.length-1,a=this.stack.length-1;i>=0;a--){if(a<0)return DL(this._tree,t,i);let o=r[n.buffer[this.stack[a]]];if(!o.isAnonymous){if(t[i]&&t[i]!=o.name)return!1;i--}}return!0}}function Uq(e){return e.children.some(t=>t instanceof Kp||!t.type.isAnonymous||Uq(t))}function klt(e){var t;let{buffer:n,nodeSet:r,maxBufferLength:i=glt,reused:a=[],minRepeatType:o=r.types.length}=e,l=Array.isArray(n)?new Bq(n,n.length):n,c=r.types,u=0,d=0;function f(A,_,E,T,M,O){let{id:P,start:z,end:L,size:Q}=l,ee=d,B=u;if(Q<0)if(l.next(),Q==-1){let Y=a[P];E.push(Y),T.push(z-A);return}else if(Q==-3){u=P;return}else if(Q==-4){d=P;return}else throw new RangeError(`Unrecognized record size: ${Q}`);let F=c[P],Z,W,$=z-A;if(L-z<=i&&(W=j(l.pos-_,M))){let Y=new Uint16Array(W.size-W.skip),V=l.pos-W.size,H=Y.length;for(;l.pos>V;)H=k(W.start,Y,H);Z=new Kp(Y,L-W.start,r),$=W.start-A}else{let Y=l.pos-Q;l.next();let V=[],H=[],ae=P>=o?P:-1,le=0,fe=L;for(;l.pos>Y;)ae>=0&&l.id==ae&&l.size>=0?(l.end<=fe-i&&(b(V,H,z,le,l.end,fe,ae,ee,B),le=V.length,fe=l.end),l.next()):O>2500?h(z,Y,V,H):f(z,Y,V,H,ae,O+1);if(ae>=0&&le>0&&le<V.length&&b(V,H,z,le,z,fe,ae,ee,B),V.reverse(),H.reverse(),ae>-1&&le>0){let U=g(F,B);Z=qq(F,V,H,0,V.length,0,L-z,U,U)}else Z=v(F,V,H,L-z,ee-L,B)}E.push(Z),T.push($)}function h(A,_,E,T){let M=[],O=0,P=-1;for(;l.pos>_;){let{id:z,start:L,end:Q,size:ee}=l;if(ee>4)l.next();else{if(P>-1&&L<P)break;P<0&&(P=Q-i),M.push(z,L,Q),O++,l.next()}}if(O){let z=new Uint16Array(O*4),L=M[M.length-2];for(let Q=M.length-3,ee=0;Q>=0;Q-=3)z[ee++]=M[Q],z[ee++]=M[Q+1]-L,z[ee++]=M[Q+2]-L,z[ee++]=ee;E.push(new Kp(z,M[2]-L,r)),T.push(L-A)}}function g(A,_){return(E,T,M)=>{let O=0,P=E.length-1,z,L;if(P>=0&&(z=E[P])instanceof Vs){if(!P&&z.type==A&&z.length==M)return z;(L=z.prop(Or.lookAhead))&&(O=T[P]+z.length+L)}return v(A,E,T,M,O,_)}}function b(A,_,E,T,M,O,P,z,L){let Q=[],ee=[];for(;A.length>T;)Q.push(A.pop()),ee.push(_.pop()+E-M);A.push(v(r.types[P],Q,ee,O-M,z-O,L)),_.push(M-E)}function v(A,_,E,T,M,O,P){if(O){let z=[Or.contextHash,O];P=P?[z].concat(P):[z]}if(M>25){let z=[Or.lookAhead,M];P=P?[z].concat(P):[z]}return new Vs(A,_,E,T,P)}function j(A,_){let E=l.fork(),T=0,M=0,O=0,P=E.end-i,z={size:0,start:0,skip:0};e:for(let L=E.pos-A;E.pos>L;){let Q=E.size;if(E.id==_&&Q>=0){z.size=T,z.start=M,z.skip=O,O+=4,T+=4,E.next();continue}let ee=E.pos-Q;if(Q<0||ee<L||E.start<P)break;let B=E.id>=o?4:0,F=E.start;for(E.next();E.pos>ee;){if(E.size<0)if(E.size==-3||E.size==-4)B+=4;else break e;else E.id>=o&&(B+=4);E.next()}M=F,T+=Q,O+=B}return(_<0||T==A)&&(z.size=T,z.start=M,z.skip=O),z.size>4?z:void 0}function k(A,_,E){let{id:T,start:M,end:O,size:P}=l;if(l.next(),P>=0&&T<o){let z=E;if(P>4){let L=l.pos-(P-4);for(;l.pos>L;)E=k(A,_,E)}_[--E]=z,_[--E]=O-A,_[--E]=M-A,_[--E]=T}else P==-3?u=T:P==-4&&(d=T);return E}let w=[],N=[];for(;l.pos>0;)f(e.start||0,e.bufferStart||0,w,N,-1,0);let C=(t=e.length)!==null&&t!==void 0?t:w.length?N[0]+w[0].length:0;return new Vs(c[e.topID],w.reverse(),N.reverse(),C)}const Bte=new WeakMap;function Qk(e,t){if(!e.isAnonymous||t instanceof Kp||t.type!=e)return 1;let n=Bte.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof Vs)){n=1;break}n+=Qk(e,r)}Bte.set(t,n)}return n}function qq(e,t,n,r,i,a,o,l,c){let u=0;for(let b=r;b<i;b++)u+=Qk(e,t[b]);let d=Math.ceil(u*1.5/8),f=[],h=[];function g(b,v,j,k,w){for(let N=j;N<k;){let C=N,A=v[N],_=Qk(e,b[N]);for(N++;N<k;N++){let E=Qk(e,b[N]);if(_+E>=d)break;_+=E}if(N==C+1){if(_>d){let E=b[C];g(E.children,E.positions,0,E.children.length,v[C]+w);continue}f.push(b[C])}else{let E=v[N-1]+b[N-1].length-A;f.push(qq(e,b,v,C,N,A,E,null,c))}h.push(A+w-a)}}return g(t,n,r,i,0),(l||c)(f,h,o)}class lAt{constructor(){this.map=new WeakMap}setBuffer(t,n,r){let i=this.map.get(t);i||this.map.set(t,i=new Map),i.set(n,r)}getBuffer(t,n){let r=this.map.get(t);return r&&r.get(n)}set(t,n){t instanceof Ef?this.setBuffer(t.context.buffer,t.index,n):t instanceof al&&this.map.set(t.tree,n)}get(t){return t instanceof Ef?this.getBuffer(t.context.buffer,t.index):t instanceof al?this.map.get(t.tree):void 0}cursorSet(t,n){t.buffer?this.setBuffer(t.buffer.buffer,t.index,n):this.map.set(t.tree,n)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class o1{constructor(t,n,r,i,a=!1,o=!1){this.from=t,this.to=n,this.tree=r,this.offset=i,this.open=(a?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new o1(0,t.length,t,0,!1,r)];for(let a of n)a.to>t.length&&i.push(a);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let l=0,c=0,u=0;;l++){let d=l<n.length?n[l]:null,f=d?d.fromA:1e9;if(f-c>=r)for(;o&&o.from<f;){let h=o;if(c>=h.from||f<=h.to||u){let g=Math.max(h.from,c)-u,b=Math.min(h.to,f)-u;h=g>=b?null:new o1(g,b,h.tree,h.offset+u,l>0,!!d)}if(h&&i.push(h),o.to>f)break;o=a<t.length?t[a++]:null}if(!d)break;c=d.toA,u=d.toA-d.toB}return i}}class T5e{startParse(t,n,r){return typeof t=="string"&&(t=new jlt(t)),r=r?r.length?r.map(i=>new vu(i.from,i.to)):[new vu(0,0)]:[new vu(0,t.length)],this.createParse(t,n||[],r)}parse(t,n,r){let i=this.startParse(t,n,r);for(;;){let a=i.advance();if(a)return a}}}class jlt{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,n){return this.string.slice(t,n)}}function cAt(e){return(t,n,r,i)=>new Clt(t,e,n,r,i)}class Ute{constructor(t,n,r,i,a,o){this.parser=t,this.parse=n,this.overlay=r,this.bracketed=i,this.target=a,this.from=o}}function qte(e){if(!e.length||e.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(e))}class Nlt{constructor(t,n,r,i,a,o,l,c){this.parser=t,this.predicate=n,this.mounts=r,this.index=i,this.start=a,this.bracketed=o,this.target=l,this.prev=c,this.depth=0,this.ranges=[]}}const LL=new Or({perNode:!0});class Clt{constructor(t,n,r,i,a){this.nest=n,this.input=r,this.fragments=i,this.ranges=a,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let r=this.baseParse.advance();if(!r)return null;if(this.baseParse=null,this.baseTree=r,this.startInner(),this.stoppedAt!=null)for(let i of this.inner)i.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new Vs(r.type,r.children,r.positions,r.length,r.propValues.concat([[LL,this.stoppedAt]]))),r}let t=this.inner[this.innerDone],n=t.parse.advance();if(n){this.innerDone++;let r=Object.assign(Object.create(null),t.target.props);r[Or.mounted.id]=new A3(n,t.overlay,t.parser,t.bracketed),t.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].from<t&&(t=Math.min(t,this.inner[n].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].parse.stopAt(t)}startInner(){let t=new Alt(this.fragments),n=null,r=null,i=new HN(new al(this.baseTree,this.ranges[0].from,0,null),Ks.IncludeAnonymous|Ks.IgnoreMounts);e:for(let a,o;;){let l=!0,c;if(this.stoppedAt!=null&&i.from>=this.stoppedAt)l=!1;else if(t.hasNode(i)){if(n){let u=n.mounts.find(d=>d.frag.from<=i.from&&d.frag.to>=i.to&&d.mount.overlay);if(u)for(let d of u.mount.overlay){let f=d.from+u.pos,h=d.to+u.pos;f>=i.from&&h<=i.to&&!n.ranges.some(g=>g.from<h&&g.to>f)&&n.ranges.push({from:f,to:h})}}l=!1}else if(r&&(o=Slt(r.ranges,i.from,i.to)))l=o!=2;else if(!i.type.isAnonymous&&(a=this.nest(i,this.input))&&(i.from<i.to||!a.overlay)){i.tree||(_lt(i),n&&n.depth++,r&&r.depth++);let u=t.findMounts(i.from,a.parser);if(typeof a.overlay=="function")n=new Nlt(a.parser,a.overlay,u,this.inner.length,i.from,!!a.bracketed,i.tree,n);else{let d=Vte(this.ranges,a.overlay||(i.from<i.to?[new vu(i.from,i.to)]:[]));d.length&&qte(d),(d.length||!a.overlay)&&this.inner.push(new Ute(a.parser,d.length?a.parser.startParse(this.input,Wte(u,d),d):a.parser.startParse(""),a.overlay?a.overlay.map(f=>new vu(f.from-i.from,f.to-i.from)):null,!!a.bracketed,i.tree,d.length?d[0].from:i.from)),a.overlay?d.length&&(r={ranges:d,depth:0,prev:r}):l=!1}}else if(n&&(c=n.predicate(i))&&(c===!0&&(c=new vu(i.from,i.to)),c.from<c.to)){let u=n.ranges.length-1;u>=0&&n.ranges[u].to==c.from?n.ranges[u]={from:n.ranges[u].from,to:c.to}:n.ranges.push(c)}if(l&&i.firstChild())n&&n.depth++,r&&r.depth++;else for(;!i.nextSibling();){if(!i.parent())break e;if(n&&!--n.depth){let u=Vte(this.ranges,n.ranges);u.length&&(qte(u),this.inner.splice(n.index,0,new Ute(n.parser,n.parser.startParse(this.input,Wte(n.mounts,u),u),n.ranges.map(d=>new vu(d.from-n.start,d.to-n.start)),n.bracketed,n.target,u[0].from))),n=n.prev}r&&!--r.depth&&(r=r.prev)}}}}function Slt(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function Kte(e,t,n,r,i,a){if(t<n){let o=e.buffer[t+1];r.push(e.slice(t,n,o)),i.push(o-a)}}function _lt(e){let{node:t}=e,n=[],r=t.context.buffer;do n.push(e.index),e.parent();while(!e.tree);let i=e.tree,a=i.children.indexOf(r),o=i.children[a],l=o.buffer,c=[a];function u(d,f,h,g,b,v){let j=n[v],k=[],w=[];Kte(o,d,j,k,w,g);let N=l[j+1],C=l[j+2];c.push(k.length);let A=v?u(j+4,l[j+3],o.set.types[l[j]],N,C-N,v-1):t.toTree();return k.push(A),w.push(N-g),Kte(o,l[j+3],f,k,w,g),new Vs(h,k,w,b)}i.children[a]=u(0,l.length,Ll.none,0,o.length,n.length-1);for(let d of c){let f=e.tree.children[d],h=e.tree.positions[d];e.yield(new al(f,h+e.from,d,e._tree))}}class Hte{constructor(t,n){this.offset=n,this.done=!1,this.cursor=t.cursor(Ks.IncludeAnonymous|Ks.IgnoreMounts)}moveTo(t){let{cursor:n}=this,r=t-this.offset;for(;!this.done&&n.from<r;)n.to>=t&&n.enter(r,1,Ks.IgnoreOverlays|Ks.ExcludeBuffers)||n.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let n=this.cursor.tree;;){if(n==t.tree)return!0;if(n.children.length&&n.positions[0]==0&&n.children[0]instanceof Vs)n=n.children[0];else break}return!1}}class Alt{constructor(t){var n;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let r=this.curFrag=t[0];this.curTo=(n=r.tree.prop(LL))!==null&&n!==void 0?n:r.to,this.inner=new Hte(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let n=this.curFrag=this.fragments[this.fragI];this.curTo=(t=n.tree.prop(LL))!==null&&t!==void 0?t:n.to,this.inner=new Hte(n.tree,-n.offset)}}findMounts(t,n){var r;let i=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let a=this.inner.cursor.node;a;a=a.parent){let o=(r=a.tree)===null||r===void 0?void 0:r.prop(Or.mounted);if(o&&o.parser==n)for(let l=this.fragI;l<this.fragments.length;l++){let c=this.fragments[l];if(c.from>=a.to)break;c.tree==this.curFrag.tree&&i.push({frag:c,pos:a.from-c.offset,mount:o})}}}return i}}function Vte(e,t){let n=null,r=t;for(let i=1,a=0;i<e.length;i++){let o=e[i-1].to,l=e[i].from;for(;a<r.length;a++){let c=r[a];if(c.from>=l)break;c.to<=o||(n||(r=n=t.slice()),c.from<o?(n[a]=new vu(c.from,o),c.to>l&&n.splice(a+1,0,new vu(l,c.to))):c.to>l?n[a--]=new vu(l,c.to):n.splice(a--,1))}}return r}function Elt(e,t,n,r){let i=0,a=0,o=!1,l=!1,c=-1e9,u=[];for(;;){let d=i==e.length?1e9:o?e[i].to:e[i].from,f=a==t.length?1e9:l?t[a].to:t[a].from;if(o!=l){let h=Math.max(c,n),g=Math.min(d,f,r);h<g&&u.push(new vu(h,g))}if(c=Math.min(d,f),c==1e9)break;d==c&&(o?(o=!1,i++):o=!0),f==c&&(l?(l=!1,a++):l=!0)}return u}function Wte(e,t){let n=[];for(let{pos:r,mount:i,frag:a}of e){let o=r+(i.overlay?i.overlay[0].from:0),l=o+i.tree.length,c=Math.max(a.from,o),u=Math.min(a.to,l);if(i.overlay){let d=i.overlay.map(h=>new vu(h.from+r,h.to+r)),f=Elt(t,d,c,u);for(let h=0,g=c;;h++){let b=h==f.length,v=b?u:f[h].from;if(v>g&&n.push(new o1(g,v,i.tree,-o,a.from>=g||a.openStart,a.to<=v||a.openEnd)),b)break;g=f[h].to}}else n.push(new o1(c,u,i.tree,-o,a.from>=o||a.openStart,a.to<=l||a.openEnd))}return n}let Tlt=0;class hu{constructor(t,n,r,i){this.name=t,this.set=n,this.base=r,this.modified=i,this.id=Tlt++}toString(){let{name:t}=this;for(let n of this.modified)n.name&&(t=`${n.name}(${t})`);return t}static define(t,n){let r=typeof t=="string"?t:"?";if(t instanceof hu&&(n=t),n!=null&&n.base)throw new Error("Can not derive from a modified tag");let i=new hu(r,[],null,[]);if(i.set.push(i),n)for(let a of n.set)i.set.push(a);return i}static defineModifier(t){let n=new VN(t);return r=>r.modified.indexOf(n)>-1?r:VN.get(r.base||r,r.modified.concat(n).sort((i,a)=>i.id-a.id))}}let Ilt=0;class VN{constructor(t){this.name=t,this.instances=[],this.id=Ilt++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(l=>l.base==t&&Mlt(n,l.modified));if(r)return r;let i=[],a=new hu(t.name,i,t,n);for(let l of n)l.instances.push(a);let o=Rlt(n);for(let l of t.set)if(!l.modified.length)for(let c of o)i.push(VN.get(l,c));return a}}function Mlt(e,t){return e.length==t.length&&e.every((n,r)=>n==t[r])}function Rlt(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((n,r)=>r.length-n.length)}function Olt(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let i of n.split(" "))if(i){let a=[],o=2,l=i;for(let f=0;;){if(l=="..."&&f>0&&f+3==i.length){o=1;break}let h=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!h)throw new RangeError("Invalid path: "+i);if(a.push(h[0]=="*"?"":h[0][0]=='"'?JSON.parse(h[0]):h[0]),f+=h[0].length,f==i.length)break;let g=i[f++];if(f==i.length&&g=="!"){o=0;break}if(g!="/")throw new RangeError("Invalid path: "+i);l=i.slice(f)}let c=a.length-1,u=a[c];if(!u)throw new RangeError("Invalid path: "+i);let d=new M6(r,o,c>0?a.slice(0,c):null);t[u]=d.sort(t[u])}}return I5e.add(t)}const I5e=new Or({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth>=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new M6(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}});class M6{constructor(t,n,r,i){this.tags=t,this.mode=n,this.context=r,this.next=i}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}M6.empty=new M6([],2,null);function M5e(e,t){let n=Object.create(null);for(let a of e)if(!Array.isArray(a.tag))n[a.tag.id]=a.class;else for(let o of a.tag)n[o.id]=a.class;let{scope:r,all:i=null}=t||{};return{style:a=>{let o=i;for(let l of a)for(let c of l.set){let u=n[c.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function Plt(e,t){let n=null;for(let r of e){let i=r.style(t);i&&(n=n?n+" "+i:i)}return n}function Dlt(e,t,n,r=0,i=e.length){let a=new Llt(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,"",a.highlighters),a.flush(i)}class Llt{constructor(t,n,r){this.at=t,this.highlighters=n,this.span=r,this.class=""}startSpan(t,n){n!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=n)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,n,r,i,a){let{type:o,from:l,to:c}=t;if(l>=r||c<=n)return;o.isTop&&(a=this.highlighters.filter(g=>!g.scope||g.scope(o)));let u=i,d=$lt(t)||M6.empty,f=Plt(a,d.tags);if(f&&(u&&(u+=" "),u+=f,d.mode==1&&(i+=(i?" ":"")+f)),this.startSpan(Math.max(n,l),u),d.opaque)return;let h=t.tree&&t.tree.prop(Or.mounted);if(h&&h.overlay){let g=t.node.enter(h.overlay[0].from+l,1),b=this.highlighters.filter(j=>!j.scope||j.scope(h.tree.type)),v=t.firstChild();for(let j=0,k=l;;j++){let w=j<h.overlay.length?h.overlay[j]:null,N=w?w.from+l:c,C=Math.max(n,k),A=Math.min(r,N);if(C<A&&v)for(;t.from<A&&(this.highlightRange(t,C,A,i,a),this.startSpan(Math.min(A,t.to),u),!(t.to>=N||!t.nextSibling())););if(!w||N>r)break;k=w.to+l,k>n&&(this.highlightRange(g.cursor(),Math.max(n,w.from+l),Math.min(r,k),"",b),this.startSpan(Math.min(r,k),u))}v&&t.parent()}else if(t.firstChild()){h&&(i="");do if(!(t.to<=n)){if(t.from>=r)break;this.highlightRange(t,n,r,i,a),this.startSpan(Math.min(r,t.to),u)}while(t.nextSibling());t.parent()}}}function $lt(e){let t=e.type.prop(I5e);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}const Ht=hu.define,_9=Ht(),Mh=Ht(),Zte=Ht(Mh),Gte=Ht(Mh),Rh=Ht(),A9=Ht(Rh),EM=Ht(Rh),of=Ht(),Pg=Ht(of),Xd=Ht(),ef=Ht(),$L=Ht(),iy=Ht($L),E9=Ht(),dt={comment:_9,lineComment:Ht(_9),blockComment:Ht(_9),docComment:Ht(_9),name:Mh,variableName:Ht(Mh),typeName:Zte,tagName:Ht(Zte),propertyName:Gte,attributeName:Ht(Gte),className:Ht(Mh),labelName:Ht(Mh),namespace:Ht(Mh),macroName:Ht(Mh),literal:Rh,string:A9,docString:Ht(A9),character:Ht(A9),attributeValue:Ht(A9),number:EM,integer:Ht(EM),float:Ht(EM),bool:Ht(Rh),regexp:Ht(Rh),escape:Ht(Rh),color:Ht(Rh),url:Ht(Rh),keyword:Xd,self:Ht(Xd),null:Ht(Xd),atom:Ht(Xd),unit:Ht(Xd),modifier:Ht(Xd),operatorKeyword:Ht(Xd),controlKeyword:Ht(Xd),definitionKeyword:Ht(Xd),moduleKeyword:Ht(Xd),operator:ef,derefOperator:Ht(ef),arithmeticOperator:Ht(ef),logicOperator:Ht(ef),bitwiseOperator:Ht(ef),compareOperator:Ht(ef),updateOperator:Ht(ef),definitionOperator:Ht(ef),typeOperator:Ht(ef),controlOperator:Ht(ef),punctuation:$L,separator:Ht($L),bracket:iy,angleBracket:Ht(iy),squareBracket:Ht(iy),paren:Ht(iy),brace:Ht(iy),content:of,heading:Pg,heading1:Ht(Pg),heading2:Ht(Pg),heading3:Ht(Pg),heading4:Ht(Pg),heading5:Ht(Pg),heading6:Ht(Pg),contentSeparator:Ht(of),list:Ht(of),quote:Ht(of),emphasis:Ht(of),strong:Ht(of),link:Ht(of),monospace:Ht(of),strikethrough:Ht(of),inserted:Ht(),deleted:Ht(),changed:Ht(),invalid:Ht(),meta:E9,documentMeta:Ht(E9),annotation:Ht(E9),processingInstruction:Ht(E9),definition:hu.defineModifier("definition"),constant:hu.defineModifier("constant"),function:hu.defineModifier("function"),standard:hu.defineModifier("standard"),local:hu.defineModifier("local"),special:hu.defineModifier("special")};for(let e in dt){let t=dt[e];t instanceof hu&&(t.name=e)}M5e([{tag:dt.link,class:"tok-link"},{tag:dt.heading,class:"tok-heading"},{tag:dt.emphasis,class:"tok-emphasis"},{tag:dt.strong,class:"tok-strong"},{tag:dt.keyword,class:"tok-keyword"},{tag:dt.atom,class:"tok-atom"},{tag:dt.bool,class:"tok-bool"},{tag:dt.url,class:"tok-url"},{tag:dt.labelName,class:"tok-labelName"},{tag:dt.inserted,class:"tok-inserted"},{tag:dt.deleted,class:"tok-deleted"},{tag:dt.literal,class:"tok-literal"},{tag:dt.string,class:"tok-string"},{tag:dt.number,class:"tok-number"},{tag:[dt.regexp,dt.escape,dt.special(dt.string)],class:"tok-string2"},{tag:dt.variableName,class:"tok-variableName"},{tag:dt.local(dt.variableName),class:"tok-variableName tok-local"},{tag:dt.definition(dt.variableName),class:"tok-variableName tok-definition"},{tag:dt.special(dt.variableName),class:"tok-variableName2"},{tag:dt.definition(dt.propertyName),class:"tok-propertyName tok-definition"},{tag:dt.typeName,class:"tok-typeName"},{tag:dt.namespace,class:"tok-namespace"},{tag:dt.className,class:"tok-className"},{tag:dt.macroName,class:"tok-macroName"},{tag:dt.propertyName,class:"tok-propertyName"},{tag:dt.operator,class:"tok-operator"},{tag:dt.comment,class:"tok-comment"},{tag:dt.meta,class:"tok-meta"},{tag:dt.invalid,class:"tok-invalid"},{tag:dt.punctuation,class:"tok-punctuation"}]);var TM;const a2=new Or;function R5e(e){return Jt.define({combine:e?t=>t.concat(e):void 0})}const Flt=new Or;class wu{constructor(t,n,r=[],i=""){this.data=t,this.name=i,Yr.prototype.hasOwnProperty("tree")||Object.defineProperty(Yr.prototype,"tree",{get(){return Bo(this)}}),this.parser=n,this.extension=[Hp.of(this),Yr.languageData.of((a,o,l)=>{let c=Qte(a,o,l),u=c.type.prop(a2);if(!u)return[];let d=a.facet(u),f=c.type.prop(Flt);if(f){let h=c.resolve(o-c.from,l);for(let g of f)if(g.test(h,a)){let b=a.facet(g.facet);return g.type=="replace"?b:b.concat(d)}}return d})].concat(r)}isActiveAt(t,n,r=-1){return Qte(t,n,r).type.prop(a2)==this.data}findRegions(t){let n=t.facet(Hp);if((n==null?void 0:n.data)==this.data)return[{from:0,to:t.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],i=(a,o)=>{if(a.prop(a2)==this.data){r.push({from:o,to:o+a.length});return}let l=a.prop(Or.mounted);if(l){if(l.tree.prop(a2)==this.data){if(l.overlay)for(let c of l.overlay)r.push({from:c.from+o,to:c.to+o});else r.push({from:o,to:o+a.length});return}else if(l.overlay){let c=r.length;if(i(l.tree,l.overlay[0].from+o),r.length>c)return}}for(let c=0;c<a.children.length;c++){let u=a.children[c];u instanceof Vs&&i(u,a.positions[c]+o)}};return i(Bo(t),0),r}get allowsNesting(){return!0}}wu.setState=ir.define();function Qte(e,t,n){let r=e.facet(Hp),i=Bo(e).topNode;if(!r||r.allowsNesting)for(let a=i;a;a=a.enter(t,n,Ks.ExcludeBuffers|Ks.EnterBracketed))a.type.isTop&&(i=a);return i}class FL extends wu{constructor(t,n,r){super(t,n,[],r),this.parser=n}static define(t){let n=R5e(t.languageData);return new FL(n,t.parser.configure({props:[a2.add(r=>r.isTop?n:void 0)]}),t.name)}configure(t,n){return new FL(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Bo(e){let t=e.field(wu.state,!1);return t?t.tree:Vs.empty}class zlt{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,n){let r=this.cursorPos-this.string.length;return t<r||n>=this.cursorPos?this.doc.sliceString(t,n):this.string.slice(t-r,n-r)}}let ay=null;class T5{constructor(t,n,r=[],i,a,o,l,c){this.parser=t,this.state=n,this.fragments=r,this.tree=i,this.treeLen=a,this.viewport=o,this.skipped=l,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(t,n,r){return new T5(t,n,[],Vs.empty,0,r,[],null)}startParse(){return this.parser.startParse(new zlt(this.state.doc),this.fragments)}work(t,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=Vs.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof t=="number"){let i=Date.now()+t;t=()=>Date.now()>i}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(o1.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=i,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,n;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=t,this.tree=n,this.fragments=this.withoutTempSkipped(o1.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let n=ay;ay=this;try{return t()}finally{ay=n}}withoutTempSkipped(t){for(let n;n=this.tempSkipped.pop();)t=Yte(t,n.from,n.to);return t}changes(t,n){let{fragments:r,tree:i,treeLen:a,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let c=[];if(t.iterChangedRanges((u,d,f,h)=>c.push({fromA:u,toA:d,fromB:f,toB:h})),r=o1.applyChanges(r,c),i=Vs.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let u of this.skipped){let d=t.mapPos(u.from,1),f=t.mapPos(u.to,-1);d<f&&l.push({from:d,to:f})}}}return new T5(this.parser,n,r,i,a,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:i,to:a}=this.skipped[r];i<t.to&&a>t.from&&(this.fragments=Yte(this.fragments,i,a),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,n){this.skipped.push({from:t,to:n})}static getSkippingParser(t){return new class extends T5e{createParse(n,r,i){let a=i[0].from,o=i[i.length-1].to;return{parsedPos:a,advance(){let c=ay;if(c){for(let u of i)c.tempSkipped.push(u);t&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,t]):t)}return this.parsedPos=o,new Vs(Ll.none,[],[],o-a)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let n=this.fragments;return this.treeLen>=t&&n.length&&n[0].from==0&&n[0].to>=t}static get(){return ay}}function Yte(e,t,n){return o1.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}class I5{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new I5(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=T5.create(t.facet(Hp).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new I5(r)}}wu.state=qo.define({create:I5.init,update(e,t){for(let n of t.effects)if(n.is(wu.setState))return n.value;return t.startState.facet(Hp)!=t.state.facet(Hp)?I5.init(t.state):e.apply(t)}});let O5e=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(O5e=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const IM=typeof navigator<"u"&&(!((TM=navigator.scheduling)===null||TM===void 0)&&TM.isInputPending)?()=>navigator.scheduling.isInputPending():null,Blt=ia.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let n=this.view.state.field(wu.state).context;(n.updateViewport(t.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:t}=this.view,n=t.field(wu.state);(n.tree!=n.context.tree||!n.context.isDone(t.doc.length))&&(this.working=O5e(this.work))}work(t){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:i}}=this.view,a=r.field(wu.state);if(a.tree==a.context.tree&&a.context.isDone(i+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!IM?Math.max(25,t.timeRemaining()-5):1e9),l=a.context.treeLen<i&&r.doc.length>i+1e3,c=a.context.work(()=>IM&&IM()||Date.now()>o,i+(l?0:1e5));this.chunkBudget-=Date.now()-n,(c||this.chunkBudget<=0)&&(a.context.takeTree(),this.view.dispatch({effects:wu.setState.of(new I5(a.context))})),this.chunkBudget>0&&!(c&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(a.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(n=>rc(this.view.state,n)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Hp=Jt.define({combine(e){return e.length?e[0]:null},enables:e=>[wu.state,Blt,Yt.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]});class Ult{constructor(t,n=[]){this.language=t,this.support=n,this.extension=[t,n]}}class ot{constructor(t,n,r,i,a,o=void 0){this.name=t,this.alias=n,this.extensions=r,this.filename=i,this.loadFunc=a,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(t=>this.support=t,t=>{throw this.loading=null,t}))}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(r)}return new ot(t.name,(t.alias||[]).concat(t.name).map(i=>i.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(t,n){for(let i of t)if(i.filename&&i.filename.test(n))return i;let r=/\.([^.]+)$/.exec(n);if(r){for(let i of t)if(i.extensions.indexOf(r[1])>-1)return i}return null}static matchLanguageName(t,n,r=!0){n=n.toLowerCase();for(let i of t)if(i.alias.some(a=>a==n))return i;if(r)for(let i of t)for(let a of i.alias){let o=n.indexOf(a);if(o>-1&&(a.length>2||!/\w/.test(n[o-1])&&!/\w/.test(n[o+a.length])))return i}return null}}const qlt=Jt.define(),Q_=Jt.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(n=>n!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function h0(e){let t=e.facet(Q_);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function R6(e,t){let n="",r=e.tabSize,i=e.facet(Q_)[0];if(i==" "){for(;t>=r;)n+=" ",t-=r;i=" "}for(let a=0;a<t;a++)n+=i;return n}function Kq(e,t){e instanceof Yr&&(e=new Y_(e));for(let r of e.state.facet(qlt)){let i=r(e,t);if(i!==void 0)return i}let n=Bo(e.state);return n.length>=t?Klt(e,n,t):null}class Y_{constructor(t,n={}){this.state=t,this.options=n,this.unit=h0(t)}lineAt(t,n=1){let r=this.state.doc.lineAt(t),{simulateBreak:i,simulateDoubleBreak:a}=this.options;return i!=null&&i>=r.from&&i<=r.to?a&&i==t?{text:"",from:t}:(n<0?i<t:i<=t)?{text:r.text.slice(i-r.from),from:i}:{text:r.text.slice(0,i-r.from),from:r.from}:r}textAfterPos(t,n=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:r,from:i}=this.lineAt(t,n);return r.slice(t-i,Math.min(r.length,t+100-i))}column(t,n=1){let{text:r,from:i}=this.lineAt(t,n),a=this.countColumn(r,t-i),o=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return o>-1&&(a+=o-this.countColumn(r,r.search(/\S|$/))),a}countColumn(t,n=t.length){return I4(t,this.state.tabSize,n)}lineIndent(t,n=1){let{text:r,from:i}=this.lineAt(t,n),a=this.options.overrideIndentation;if(a){let o=a(i);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const P5e=new Or;function Klt(e,t,n){let r=t.resolveStack(n),i=t.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(i!=r.node){let a=[];for(let o=i;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)a.push(o);for(let o=a.length-1;o>=0;o--)r={node:a[o],next:r}}return D5e(r,e,n)}function D5e(e,t,n){for(let r=e;r;r=r.next){let i=Vlt(r.node);if(i)return i(Hq.create(t,n,r))}return 0}function Hlt(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function Vlt(e){let t=e.type.prop(P5e);if(t)return t;let n=e.firstChild,r;if(n&&(r=n.type.prop(Or.closedBy))){let i=e.lastChild,a=i&&r.indexOf(i.name)>-1;return o=>L5e(o,!0,1,void 0,a&&!Hlt(o)?i.from:void 0)}return e.parent==null?Wlt:null}function Wlt(){return 0}class Hq extends Y_{constructor(t,n,r){super(t.state,t.options),this.base=t,this.pos=n,this.context=r}get node(){return this.context.node}static create(t,n,r){return new Hq(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let n=this.state.doc.lineAt(t.from);for(;;){let r=t.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(Zlt(r,t))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return D5e(this.context.next,this.base,this.pos)}}function Zlt(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function Glt(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=i==null||i<=a.from?a.to:Math.min(a.to,i);for(let l=n.to;;){let c=t.childAfter(l);if(!c||c==r)return null;if(!c.type.isSkipped){if(c.from>=o)return null;let u=/^ */.exec(a.text.slice(n.to-a.from))[0].length;return{from:n.from,to:n.to+u}}l=c.to}}function dAt({closing:e,align:t=!0,units:n=1}){return r=>L5e(r,t,n,e)}function L5e(e,t,n,r,i){let a=e.textAfter,o=a.match(/^\s*/)[0].length,l=r&&a.slice(o,o+r.length)==r||i==e.pos+o,c=t?Glt(e):null;return c?l?e.column(c.from):e.column(c.to):e.baseIndent+(l?0:e.unit*n)}const fAt=e=>e.baseIndent;function mAt({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const Qlt=200;function Ylt(){return Yr.transactionFilter.of(e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let n=e.newDoc,{head:r}=e.newSelection.main,i=n.lineAt(r);if(r>i.from+Qlt)return e;let a=n.sliceString(i.from,r);if(!t.some(u=>u.test(a)))return e;let{state:o}=e,l=-1,c=[];for(let{head:u}of o.selection.ranges){let d=o.doc.lineAt(u);if(d.from==l)continue;l=d.from;let f=Kq(o,d.from);if(f==null)continue;let h=/^\s*/.exec(d.text)[0],g=R6(o,f);h!=g&&c.push({from:d.from,to:d.from+h.length,insert:g})}return c.length?[e,{changes:c,sequential:!0}]:e})}const Jlt=Jt.define(),Xlt=new Or;function hAt(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}function ect(e,t,n){let r=Bo(e);if(r.length<n)return null;let i=r.resolveStack(n,1),a=null;for(let o=i;o;o=o.next){let l=o.node;if(l.to<=n||l.from>n)continue;if(a&&l.from<t)break;let c=l.type.prop(Xlt);if(c&&(l.to<r.length-50||r.length==e.doc.length||!tct(l))){let u=c(l,e);u&&u.from<=n&&u.from>=t&&u.to>n&&(a=u)}}return a}function tct(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function WN(e,t,n){for(let r of e.facet(Jlt)){let i=r(e,t,n);if(i)return i}return ect(e,t,n)}function $5e(e,t){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);return n>=r?void 0:{from:n,to:r}}const J_=ir.define({map:$5e}),V7=ir.define({map:$5e});function F5e(e){let t=[];for(let{head:n}of e.state.selection.ranges)t.some(r=>r.from<=n&&r.to>=n)||t.push(e.lineBlockAt(n));return t}const p0=qo.define({create(){return $n.none},update(e,t){t.isUserEvent("delete")&&t.changes.iterChangedRanges((n,r)=>e=Jte(e,n,r)),e=e.map(t.changes);for(let n of t.effects)if(n.is(J_)&&!nct(e,n.value.from,n.value.to)){let{preparePlaceholder:r}=t.state.facet(U5e),i=r?$n.replace({widget:new cct(r(t.state,n.value))}):Xte;e=e.update({add:[i.range(n.value.from,n.value.to)]})}else n.is(V7)&&(e=e.update({filter:(r,i)=>n.value.from!=r||n.value.to!=i,filterFrom:n.value.from,filterTo:n.value.to}));return t.selection&&(e=Jte(e,t.selection.main.head)),e},provide:e=>Yt.decorations.from(e),toJSON(e,t){let n=[];return e.between(0,t.doc.length,(r,i)=>{n.push(r,i)}),n},fromJSON(e){if(!Array.isArray(e)||e.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let n=0;n<e.length;){let r=e[n++],i=e[n++];if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid JSON for fold state");t.push(Xte.range(r,i))}return $n.set(t,!0)}});function Jte(e,t,n=t){let r=!1;return e.between(t,n,(i,a)=>{i<n&&a>t&&(r=!0)}),r?e.update({filterFrom:t,filterTo:n,filter:(i,a)=>i>=n||a<=t}):e}function ZN(e,t,n){var r;let i=null;return(r=e.field(p0,!1))===null||r===void 0||r.between(t,n,(a,o)=>{(!i||i.from>a)&&(i={from:a,to:o})}),i}function nct(e,t,n){let r=!1;return e.between(t,t,(i,a)=>{i==t&&a==n&&(r=!0)}),r}function z5e(e,t){return e.field(p0,!1)?t:t.concat(ir.appendConfig.of(q5e()))}const rct=e=>{for(let t of F5e(e)){let n=WN(e.state,t.from,t.to);if(n)return e.dispatch({effects:z5e(e.state,[J_.of(n),B5e(e,n)])}),!0}return!1},sct=e=>{if(!e.state.field(p0,!1))return!1;let t=[];for(let n of F5e(e)){let r=ZN(e.state,n.from,n.to);r&&t.push(V7.of(r),B5e(e,r,!1))}return t.length&&e.dispatch({effects:t}),t.length>0};function B5e(e,t,n=!0){let r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(t.to).number;return Yt.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${e.state.phrase("to")} ${i}.`)}const ict=e=>{let{state:t}=e,n=[];for(let r=0;r<t.doc.length;){let i=e.lineBlockAt(r),a=WN(t,i.from,i.to);a&&n.push(J_.of(a)),r=(a?e.lineBlockAt(a.to):i).to+1}return n.length&&e.dispatch({effects:z5e(e.state,n)}),!!n.length},act=e=>{let t=e.state.field(p0,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,(r,i)=>{n.push(V7.of({from:r,to:i}))}),e.dispatch({effects:n}),!0},oct=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:rct},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:sct},{key:"Ctrl-Alt-[",run:ict},{key:"Ctrl-Alt-]",run:act}],lct={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},U5e=Jt.define({combine(e){return im(e,lct)}});function q5e(e){return[p0,fct]}function K5e(e,t){let{state:n}=e,r=n.facet(U5e),i=o=>{let l=e.lineBlockAt(e.posAtDOM(o.target)),c=ZN(e.state,l.from,l.to);c&&e.dispatch({effects:V7.of(c)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(e,i,t);let a=document.createElement("span");return a.textContent=r.placeholderText,a.setAttribute("aria-label",n.phrase("folded code")),a.title=n.phrase("unfold"),a.className="cm-foldPlaceholder",a.onclick=i,a}const Xte=$n.replace({widget:new class extends am{toDOM(e){return K5e(e,null)}}});class cct extends am{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return K5e(t,this.value)}}const uct={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class MM extends A1{constructor(t,n){super(),this.config=t,this.open=n}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let n=document.createElement("span");return n.textContent=this.open?this.config.openText:this.config.closedText,n.title=t.state.phrase(this.open?"Fold line":"Unfold line"),n}}function dct(e={}){let t={...uct,...e},n=new MM(t,!0),r=new MM(t,!1),i=ia.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Hp)!=o.state.facet(Hp)||o.startState.field(p0,!1)!=o.state.field(p0,!1)||Bo(o.startState)!=Bo(o.state)||t.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new S1;for(let c of o.viewportLineBlocks){let u=ZN(o.state,c.from,c.to)?r:WN(o.state,c.from,c.to)?n:null;u&&l.add(c.from,c.from,u)}return l.finish()}}),{domEventHandlers:a}=t;return[i,alt({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(i))===null||l===void 0?void 0:l.markers)||Lr.empty},initialSpacer(){return new MM(t,!1)},domEventHandlers:{...a,click:(o,l,c)=>{if(a.click&&a.click(o,l,c))return!0;let u=ZN(o.state,l.from,l.to);if(u)return o.dispatch({effects:V7.of(u)}),!0;let d=WN(o.state,l.from,l.to);return d?(o.dispatch({effects:J_.of(d)}),!0):!1}}}),q5e()]}const fct=Yt.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class W7{constructor(t,n){this.specs=t;let r;function i(l){let c=Bp.newName();return(r||(r=Object.create(null)))["."+c]=l,c}const a=typeof n.all=="string"?n.all:n.all?i(n.all):void 0,o=n.scope;this.scope=o instanceof wu?l=>l.prop(a2)==o.data:o?l=>l==o:void 0,this.style=M5e(t.map(l=>({tag:l.tag,class:l.class||i(Object.assign({},l,{tag:null}))})),{all:a}).style,this.module=r?new Bp(r):null,this.themeType=n.themeType}static define(t,n){return new W7(t,n||{})}}const zL=Jt.define(),H5e=Jt.define({combine(e){return e.length?[e[0]]:null}});function RM(e){let t=e.facet(zL);return t.length?t:e.facet(H5e)}function V5e(e,t){let n=[hct],r;return e instanceof W7&&(e.module&&n.push(Yt.styleModule.of(e.module)),r=e.themeType),t!=null&&t.fallback?n.push(H5e.of(e)):r?n.push(zL.computeN([Yt.darkTheme],i=>i.facet(Yt.darkTheme)==(r=="dark")?[e]:[])):n.push(zL.of(e)),n}class mct{constructor(t){this.markCache=Object.create(null),this.tree=Bo(t.state),this.decorations=this.buildDeco(t,RM(t.state)),this.decoratedTo=t.viewport.to}update(t){let n=Bo(t.state),r=RM(t.state),i=r!=RM(t.startState),{viewport:a}=t.view,o=t.changes.mapPos(this.decoratedTo,1);n.length<a.to&&!i&&n.type==this.tree.type&&o>=a.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(n!=this.tree||t.viewportChanged||i)&&(this.tree=n,this.decorations=this.buildDeco(t.view,r),this.decoratedTo=a.to)}buildDeco(t,n){if(!n||!this.tree.length)return $n.none;let r=new S1;for(let{from:i,to:a}of t.visibleRanges)Dlt(this.tree,n,(o,l,c)=>{r.add(o,l,this.markCache[c]||(this.markCache[c]=$n.mark({class:c})))},i,a);return r.finish()}}const hct=lg.high(ia.fromClass(mct,{decorations:e=>e.decorations})),pct=W7.define([{tag:dt.meta,color:"#404740"},{tag:dt.link,textDecoration:"underline"},{tag:dt.heading,textDecoration:"underline",fontWeight:"bold"},{tag:dt.emphasis,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold"},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.keyword,color:"#708"},{tag:[dt.atom,dt.bool,dt.url,dt.contentSeparator,dt.labelName],color:"#219"},{tag:[dt.literal,dt.inserted],color:"#164"},{tag:[dt.string,dt.deleted],color:"#a11"},{tag:[dt.regexp,dt.escape,dt.special(dt.string)],color:"#e40"},{tag:dt.definition(dt.variableName),color:"#00f"},{tag:dt.local(dt.variableName),color:"#30a"},{tag:[dt.typeName,dt.namespace],color:"#085"},{tag:dt.className,color:"#167"},{tag:[dt.special(dt.variableName),dt.macroName],color:"#256"},{tag:dt.definition(dt.propertyName),color:"#00c"},{tag:dt.comment,color:"#940"},{tag:dt.invalid,color:"#f00"}]),gct=Yt.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),W5e=1e4,Z5e="()[]{}",G5e=Jt.define({combine(e){return im(e,{afterCursor:!0,brackets:Z5e,maxScanDistance:W5e,renderMatch:yct})}}),xct=$n.mark({class:"cm-matchingBracket"}),bct=$n.mark({class:"cm-nonmatchingBracket"});function yct(e){let t=[],n=e.matched?xct:bct;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}function ene(e){let t=[],n=e.facet(G5e);for(let r of e.selection.ranges){if(!r.empty)continue;let i=Tf(e,r.head,-1,n)||r.head>0&&Tf(e,r.head-1,1,n)||n.afterCursor&&(Tf(e,r.head,1,n)||r.head<e.doc.length&&Tf(e,r.head+1,-1,n));i&&(t=t.concat(n.renderMatch(i,e)))}return $n.set(t,!0)}const vct=ia.fromClass(class{constructor(e){this.paused=!1,this.decorations=ene(e.state)}update(e){(e.docChanged||e.selectionSet||this.paused)&&(e.view.composing?(this.decorations=this.decorations.map(e.changes),this.paused=!0):(this.decorations=ene(e.state),this.paused=!1))}},{decorations:e=>e.decorations}),wct=[vct,gct];function kct(e={}){return[G5e.of(e),wct]}const jct=new Or;function BL(e,t,n){let r=e.prop(t<0?Or.openedBy:Or.closedBy);if(r)return r;if(e.name.length==1){let i=n.indexOf(e.name);if(i>-1&&i%2==(t<0?1:0))return[n[i+t]]}return null}function UL(e){let t=e.type.prop(jct);return t?t(e.node):e}function Tf(e,t,n,r={}){let i=r.maxScanDistance||W5e,a=r.brackets||Z5e,o=Bo(e),l=o.resolveInner(t,n);for(let c=l;c;c=c.parent){let u=BL(c.type,n,a);if(u&&c.from<c.to){let d=UL(c);if(d&&(n>0?t>=d.from&&t<d.to:t>d.from&&t<=d.to))return Nct(e,t,n,c,d,u,a)}}return Cct(e,t,n,o,l.type,i,a)}function Nct(e,t,n,r,i,a,o){let l=r.parent,c={from:i.from,to:i.to},u=0,d=l==null?void 0:l.cursor();if(d&&(n<0?d.childBefore(r.from):d.childAfter(r.to)))do if(n<0?d.to<=r.from:d.from>=r.to){if(u==0&&a.indexOf(d.type.name)>-1&&d.from<d.to){let f=UL(d);return{start:c,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(BL(d.type,n,o))u++;else if(BL(d.type,-n,o)){if(u==0){let f=UL(d);return{start:c,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}u--}}while(n<0?d.prevSibling():d.nextSibling());return{start:c,matched:!1}}function Cct(e,t,n,r,i,a,o){let l=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),c=o.indexOf(l);if(c<0||c%2==0!=n>0)return null;let u={from:n<0?t-1:t,to:n>0?t+1:t},d=e.doc.iterRange(t,n>0?e.doc.length:0),f=0;for(let h=0;!d.next().done&&h<=a;){let g=d.value;n<0&&(h+=g.length);let b=t+h*n;for(let v=n>0?0:g.length-1,j=n>0?g.length:-1;v!=j;v+=n){let k=o.indexOf(g[v]);if(!(k<0||r.resolveInner(b+v,1).type!=i))if(k%2==0==n>0)f++;else{if(f==1)return{start:u,end:{from:b+v,to:b+v+1},matched:k>>1==c>>1};f--}}n>0&&(h+=g.length)}return d.done?{start:u,matched:!1}:null}function tne(e,t,n,r=0,i=0){t==null&&(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));let a=i;for(let o=r;o<t;o++)e.charCodeAt(o)==9?a+=n-a%n:a++;return a}class Q5e{constructor(t,n,r,i){this.string=t,this.tabSize=n,this.indentUnit=r,this.overrideIndent=i,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(t){let n=this.string.charAt(this.pos),r;if(typeof t=="string"?r=n==t:r=n&&(t instanceof RegExp?t.test(n):t(n)),r)return++this.pos,n}eatWhile(t){let n=this.pos;for(;this.eat(t););return this.pos>n}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let n=this.string.indexOf(t,this.pos);if(n>-1)return this.pos=n,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=tne(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var t;return(t=this.overrideIndent)!==null&&t!==void 0?t:tne(this.string,null,this.tabSize)}match(t,n,r){if(typeof t=="string"){let i=o=>r?o.toLowerCase():o,a=this.string.substr(this.pos,t.length);return i(a)==i(t)?(n!==!1&&(this.pos+=t.length),!0):null}else{let i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&n!==!1&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function Sct(e){return{name:e.name||"",token:e.token,blankLine:e.blankLine||(()=>{}),startState:e.startState||(()=>!0),copyState:e.copyState||_ct,indent:e.indent||(()=>null),languageData:e.languageData||{},tokenTable:e.tokenTable||Zq,mergeTokens:e.mergeTokens!==!1}}function _ct(e){if(typeof e!="object")return e;let t={};for(let n in e){let r=e[n];t[n]=r instanceof Array?r.slice():r}return t}const nne=new WeakMap;class Vq extends wu{constructor(t){let n=R5e(t.languageData),r=Sct(t),i,a=new class extends T5e{createParse(o,l,c){return new Ect(i,o,l,c)}};super(n,a,[],t.name),this.topNode=Mct(n,this),i=this,this.streamParser=r,this.stateAfter=new Or({perNode:!0}),this.tokenTable=t.tokenTable?new e4e(r.tokenTable):Ict}static define(t){return new Vq(t)}getIndent(t){let n,{overrideIndentation:r}=t.options;r&&(n=nne.get(t.state),n!=null&&n<t.pos-1e4&&(n=void 0));let i=Wq(this,t.node.tree,t.node.from,t.node.from,n??t.pos),a,o;if(i?(o=i.state,a=i.pos+1):(o=this.streamParser.startState(t.unit),a=t.node.from),t.pos-a>1e4)return null;for(;a<t.pos;){let c=t.state.doc.lineAt(a),u=Math.min(t.pos,c.to);if(c.length){let d=r?r(c.from):-1,f=new Q5e(c.text,t.state.tabSize,t.unit,d<0?void 0:d);for(;f.pos<u-c.from;)J5e(this.streamParser.token,f,o)}else this.streamParser.blankLine(o,t.unit);if(u==t.pos)break;a=c.to+1}let l=t.lineAt(t.pos);return r&&n==null&&nne.set(t.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],t)}get allowsNesting(){return!1}}function Wq(e,t,n,r,i){let a=n>=r&&n+t.length<=i&&t.prop(e.stateAfter);if(a)return{state:e.streamParser.copyState(a),pos:n+t.length};for(let o=t.children.length-1;o>=0;o--){let l=t.children[o],c=n+t.positions[o],u=l instanceof Vs&&c<i&&Wq(e,l,c,r,i);if(u)return u}return null}function Y5e(e,t,n,r,i){if(i&&n<=0&&r>=t.length)return t;!i&&n==0&&t.type==e.topNode&&(i=!0);for(let a=t.children.length-1;a>=0;a--){let o=t.positions[a],l=t.children[a],c;if(o<r&&l instanceof Vs){if(!(c=Y5e(e,l,n-o,r-o,i)))break;return i?new Vs(t.type,t.children.slice(0,a).concat(c),t.positions.slice(0,a+1),o+c.length):c}}return null}function Act(e,t,n,r,i){for(let a of t){let o=a.from+(a.openStart?25:0),l=a.to-(a.openEnd?25:0),c=o<=n&&l>n&&Wq(e,a.tree,0-a.offset,n,l),u;if(c&&c.pos<=r&&(u=Y5e(e,a.tree,n+a.offset,c.pos+a.offset,!1)))return{state:c.state,tree:u}}return{state:e.streamParser.startState(i?h0(i):4),tree:Vs.empty}}class Ect{constructor(t,n,r,i){this.lang=t,this.input=n,this.fragments=r,this.ranges=i,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=i[i.length-1].to;let a=T5.get(),o=i[0].from,{state:l,tree:c}=Act(t,r,o,this.to,a==null?void 0:a.state);this.state=l,this.parsedPos=this.chunkStart=o+c.length;for(let u=0;u<c.children.length;u++)this.chunks.push(c.children[u]),this.chunkPos.push(c.positions[u]);a&&this.parsedPos<a.viewport.from-1e5&&i.some(u=>u.from<=a.viewport.from&&u.to>=a.viewport.from)&&(this.state=this.lang.streamParser.startState(h0(a.state)),a.skipUntilInView(this.parsedPos,a.viewport.from),this.parsedPos=a.viewport.from),this.moveRangeIndex()}advance(){let t=T5.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),r=Math.min(n,this.chunkStart+512);for(t&&(r=Math.min(r,t.viewport.to));this.parsedPos<r;)this.parseLine(t);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=n?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,n),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let n=this.input.chunk(t);if(this.input.lineChunks)n==`
|
|
1296
1296
|
`&&(n="");else{let r=n.indexOf(`
|
|
1297
|
-
`);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let i=this.rangeIndex;;){let a=this.ranges[i].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),i++,i==this.ranges.length))break;let o=this.ranges[i].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let i=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?i>a:i>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-i}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,i){let a=4;if(this.ranges.length>1){i=this.skipGapsTo(n,i,1),n+=i;let l=this.chunk.length;i=this.skipGapsTo(r,i,-1),r+=i,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),i}parseLine(t){let{line:n,end:r}=this.nextLine(),i=0,{streamParser:a}=this.lang,o=new Q5e(n,t?t.state.tabSize:4,t?h0(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=J5e(a.token,o,this.state);if(l&&(i=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,i)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=Vs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Tct,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new Vs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Vs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function J5e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let i=e(t,n);if(t.pos>t.start)return i}throw new Error("Stream parser failed to advance stream.")}const Zq=Object.create(null),O6=[Ll.none],Tct=new zq(O6),rne=[],sne=Object.create(null),X5e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])X5e[e]=t4e(Zq,t);class e4e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),X5e)}resolve(t){return t?this.table[t]||(this.table[t]=t4e(this.extra,t)):0}}const Ict=new e4e(Zq);function OM(e,t){rne.indexOf(e)>-1||(rne.push(e),console.warn(t))}function t4e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||dt[u];d?typeof d=="function"?c.length?c=c.map(d):OM(u,`Modifier ${u} used at start of tag`):c.length?OM(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:OM(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),i=r+" "+n.map(l=>l.id),a=sne[i];if(a)return a.id;let o=sne[i]=Ll.define({id:O6.length,name:r,props:[Olt({[r]:n})]});return O6.push(o),o.id}function Mct(e,t){let n=Ll.define({id:O6.length,name:"Document",props:[a2.add(()=>e),P5e.add(()=>r=>t.getIndent(r))],top:!0});return O6.push(n),n}Hs.RTL,Hs.LTR;class n4e{constructor(t,n,r,i){this.state=t,this.pos=n,this.explicit=r,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=Bo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),i=n.text.slice(r-n.from,this.pos-n.from),a=i.search(r4e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:i.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function ine(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Rct(e){let t=Object.create(null),n=Object.create(null);for(let{label:i}of e){t[i[0]]=!0;for(let a=1;a<i.length;a++)n[i[a]]=!0}let r=ine(t)+ine(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Oct(e){let t=e.map(i=>typeof i=="string"?{label:i}:i),[n,r]=t.every(i=>/^\w+$/.test(i.label))?[/\w*$/,/\w+$/]:Rct(t);return i=>{let a=i.matchBefore(r);return a||i.explicit?{from:a?a.from:i.pos,options:t,validFor:n}:null}}function pAt(e,t){return n=>{for(let r=Bo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class ane{constructor(t,n,r,i){this.completion=t,this.source=n,this.match=r,this.score=i}}function E2(e){return e.selection.main.from}function r4e(e,t){var n;let{source:r}=e,i=t&&r[0]!="^",a=r[r.length-1]!="$";return!i&&!a?e:new RegExp(`${i?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const Gq=q1.define();function Pct(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(l=>{if(l!=i&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==i.from?l.to:l.from+o,insert:c},range:bt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const one=new WeakMap;function Dct(e){if(!Array.isArray(e))return e;let t=one.get(e);return t||one.set(e,t=Oct(e)),t}const GN=ir.define(),P6=ir.define();class Lct{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Xl(t,n),i=wf(r);this.chars.push(r);let a=t.slice(n,n+i),o=a.toUpperCase();this.folded.push(Xl(o==a?a.toLowerCase():o,0)),n+=i}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:i,precise:a,byWord:o}=this;if(n.length==1){let w=Xl(t,0),N=wf(w),C=N==t.length?0:-100;if(w!=n[0])if(w==r[0])C+=-200;else return null;return this.ret(C,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let C=Xl(t,w);(C==n[u]||C==r[u])&&(i[u++]=w),w+=wf(C)}if(u<c)return null}let d=0,f=0,h=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),C=0;w<N&&f<c;){let A=Xl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=wq(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||C==0&&E!=0)&&(n[f]==A||r[f]==A&&(h=!0)?o[f++]=w:o.length&&(k=!1)),C=E,w+=wf(A)}return f==c&&o[0]==0&&k?this.result(-100+(h?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):f==c?this.result(-100+(h?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((i[0]?-700:0)+-200+-1100,i,t)}result(t,n,r){let i=[],a=0;for(let o of n){let l=o+(this.astral?wf(Xl(r,o)):1);a&&i[a-1]==o?i[a-1]=l:(i[a++]=o,i[a++]=l)}return this.ret(t-r.length,i)}}class $ct{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const ao=Jt.define({combine(e){return im(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Fct,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>lne(t(r),n(r)),optionClass:(t,n)=>r=>lne(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function lne(e,t){return e?t?e+" "+t:e:t}function Fct(e,t,n,r,i,a){let o=e.textDirection==Hs.RTL,l=o,c=!1,u="top",d,f,h=t.left-i.left,g=i.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&h<Math.min(b,g)?l=!1:!l&&g<Math.min(b,h)&&(l=!0),b<=(l?h:g))d=Math.max(i.top,Math.min(n.top,i.bottom-v))-t.top,f=Math.min(400,l?h:g);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let w=i.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${f/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const Qq=ir.define();function zct(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(i=>"cm-completionIcon-"+i)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,i,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],f=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let h=o.appendChild(document.createElement("span"));h.appendChild(document.createTextNode(l.slice(d,f))),h.className="cm-completionMatchedText",c=f}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function PM(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let i=Math.floor(t/n);return{from:i*n,to:(i+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Bct{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let i=t.state.field(n),{options:a,selected:o}=i.open,l=t.state.facet(ao);this.optionContent=zct(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=PM(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,f;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(f=/-(\d+)$/.exec(d.id))&&+f[1]<u.length){this.applyCompletion(t,u[+f[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:Qq.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet(ao).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:P6.of(null)})}),this.showOptions(a,i.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=i){let{options:a,selected:o,disabled:l}=r.open;(!i.open||i.open.options!=a)&&(this.range=PM(a.length,o,t.state.facet(ao).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=i.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=PM(n.options.length,n.selected,this.view.state.facet(ao).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:i}=n.options[n.selected],{info:a}=i;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(i);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,i)}).catch(l=>rc(this.view.state,l,"completion info")):(this.addInfoPane(o,i),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:i,destroy:a}=t;r.appendChild(i),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,i=this.range.from;r;r=r.nextSibling,i++)r.nodeName!="LI"||!r.id?i--:i==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&qct(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return i.top>Math.min(a.bottom,n.bottom)-10||i.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet(ao).positionInfo(this.view,n,i,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const i=document.createElement("ul");i.id=n,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",o=>{o.target==i&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let h=typeof u=="string"?u:u.name;if(h!=a&&(o>r.from||r.from==0))if(a=h,typeof u!="string"&&u.header)i.appendChild(u.header(u));else{let g=i.appendChild(document.createElement("completion-section"));g.textContent=h}}const d=i.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let f=this.optionClass(l);f&&(d.className=f);for(let h of this.optionContent){let g=h(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&i.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Uct(e,t){return n=>new Bct(n,e,t)}function qct(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function cne(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function Kct(e,t){let n=[],r=null,i=null,a=d=>{n.push(d);let{section:f}=d.completion;if(f){r||(r=[]);let h=typeof f=="string"?f:f.name;r.some(g=>g.name==h)||r.push(typeof f=="string"?{name:h}:f)}},o=t.facet(ao);for(let d of e)if(d.hasResult()){let f=d.result.getMatch;if(d.result.filter===!1)for(let h of d.result.options)a(new ane(h,d.source,f?f(h):[],1e9-n.length));else{let h=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new $ct(h):new Lct(h);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?f?f(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new ane(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;i||(i=Object.create(null)),i[w]=Math.max(k,i[w]||-1e9)}}}}if(r){let d=Object.create(null),f=0,h=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?i[b.name]-i[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(h))f-=1e5,d[g.name]=f;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((f,h)=>h.score-f.score||u(f.completion,h.completion))){let f=d.completion;!c||c.label!=f.label||c.detail!=f.detail||c.type!=null&&f.type!=null&&c.type!=f.type||c.apply!=f.apply||c.boost!=f.boost?l.push(d):cne(d.completion)>cne(c)&&(l[l.length-1]=d),c=d.completion}return l}class u3{constructor(t,n,r,i,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=i,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new u3(this.options,une(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(u=>u.isPending))return i.setDisabled();let l=Kct(t,n);if(!l.length)return i&&t.some(u=>u.isPending)?i.setDisabled():null;let c=n.facet(ao).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let u=i.options[i.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new u3(l,une(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Qct,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new u3(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new u3(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class QN{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new QN(Zct,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(ao),a=(r.override||n.languageDataAt("autocomplete",E2(n)).map(Dct)).map(c=>(this.active.find(d=>d.source==c)||new ku(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(Yq));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Hct(a,this.active)||l?o=u3.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ku(c.source,0):c));for(let c of t.effects)c.is(Qq)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new QN(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Vct:Wct}}function Hct(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}const Vct={"aria-autocomplete":"list"},Wct={};function une(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Zct=[];function s4e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(Gq);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ku{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=s4e(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new ku(i.source,0)),r&4&&i.state==0&&(i=new ku(this.source,1)),i=i.updateFor(t,r);for(let a of t.effects)if(a.is(GN))i=new ku(i.source,1,a.value);else if(a.is(P6))i=new ku(i.source,0);else if(a.is(Yq))for(let o of a.value)o.source==i.source&&(i=o);return i}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(E2(t.state))}}class E3 extends ku{constructor(t,n,r,i,a,o){super(t,3,n),this.limit=r,this.result=i,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=E2(t.state);if(l>o||!i||n&2&&(E2(t.startState)==this.from||l<this.limit))return new ku(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return Gct(i.validFor,t.state,a,o)?new E3(this.source,this.explicit,c,i,a,o):i.update&&(i=i.update(i,a,o,new n4e(t.state,l,!1)))?new E3(this.source,this.explicit,c,i,i.from,(r=i.to)!==null&&r!==void 0?r:E2(t.state)):new ku(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new E3(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ku(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function Gct(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e=="function"?e(i,n,r,t):r4e(e,!0).test(i)}const Yq=ir.define({map(e,t){return e.map(n=>n.map(t))}}),ec=qo.define({create(){return QN.start()},update(e,t){return e.update(t)},provide:e=>[$q.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function Jq(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(ec).active.find(i=>i.source==t.source);return r instanceof E3?(typeof n=="string"?e.dispatch({...Pct(e.state,n,r.from,r.to),annotations:Gq.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Qct=Uct(ec,Jq);function T9(e,t="option"){return n=>{let r=n.state.field(ec,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(ao).interactionDelay)return!1;let i=1,a;t=="page"&&(a=v5e(n,r.open.tooltip))&&(i=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+i*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:Qq.of(l)}),!0}}const Yct=e=>{let t=e.state.field(ec,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(ao).interactionDelay?!1:Jq(e,t.open.options[t.open.selected])},DM=e=>e.state.field(ec,!1)?(e.dispatch({effects:GN.of(!0)}),!0):!1,Jct=e=>{let t=e.state.field(ec,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:P6.of(null)}),!0)};class Xct{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const eut=50,tut=1e3,nut=ia.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(ec).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(ec),n=e.state.facet(ao);if(!e.selectionSet&&!e.docChanged&&e.startState.field(ec)==t)return;let r=e.transactions.some(a=>{let o=s4e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>eut&&Date.now()-o.time>tut){for(let l of o.context.abortListeners)try{l()}catch(c){rc(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(GN)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(ec);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=E2(t),r=new n4e(t,n,e.explicit,this.view),i=new Xct(e,r);this.running.push(i),Promise.resolve(e.source(r)).then(a=>{i.context.aborted||(i.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:P6.of(null)}),rc(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet(ao),r=this.view.state.field(ec);for(let i=0;i<this.running.length;i++){let a=this.running[i];if(a.done===void 0)continue;if(this.running.splice(i--,1),a.done){let l=E2(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new E3(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ku(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:Yq.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(ec,!1);if(t&&t.tooltip&&this.view.state.facet(ao).closeOnBlur){let n=t.open&&v5e(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:P6.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:GN.of(!1)}),20),this.composing=0}}}),rut=typeof navigator=="object"&&/Win/.test(navigator.platform),sut=lg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(ec,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(rut&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&Jq(t,r),!1}})),i4e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class iut{constructor(t,n,r,i){this.field=t,this.line=n,this.from=r,this.to=i}}class Xq{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,To.TrackDel),r=t.mapPos(this.to,1,To.TrackDel);return n==null||r==null?null:new Xq(this.field,n,r)}}class eK{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],i=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let f=0;f<d;f++)u+=t.facet(Q_);i.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new Xq(c.field,i[c.line]+c.from,i[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],i=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<n.length;f++)(l!=null?n[f].seq==l:d&&n[f].name==d)&&(u=f);if(u<0){let f=0;for(;f<n.length&&(l==null||n[f].seq!=null&&n[f].seq<l);)f++;n.splice(f,0,{seq:l,name:d}),u=f;for(let h of i)h.field>=u&&h.field++}for(let f of i)if(f.line==r.length&&f.from>a.index){let h=a[2]?3+(a[1]||"").length:2;f.from-=h,f.to-=h}i.push(new iut(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of i)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new eK(r,i)}}let aut=$n.widget({widget:new class extends am{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),out=$n.mark({class:"cm-snippetField"});class M4{constructor(t,n){this.ranges=t,this.active=n,this.deco=$n.set(t.map(r=>(r.from==r.to?aut:out).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let i=r.map(t);if(!i)return null;n.push(i)}return new M4(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Z7=ir.define({map(e,t){return e&&e.map(t)}}),lut=ir.define(),D6=qo.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Z7))return n.value;if(n.is(lut)&&e)return new M4(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:$n.none)});function tK(e,t){return bt.create(e.filter(n=>n.field==t).map(n=>bt.range(n.from,n.to)))}function cut(e){let t=eK.parse(e);return(n,r,i,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,i),{main:c}=n.state.selection,u={changes:{from:i,to:a==c.from?c.to:a,insert:ls.of(o)},scrollIntoView:!0,annotations:r?[Gq.of(r),ja.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=tK(l,0)),l.some(d=>d.field>0)){let d=new M4(l,0),f=u.effects=[Z7.of(d)];n.state.field(D6,!1)===void 0&&f.push(ir.appendConfig.of([D6,hut,put,i4e]))}n.dispatch(n.state.update(u))}}function a4e(e){return({state:t,dispatch:n})=>{let r=t.field(D6,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==i+e);return n(t.update({selection:tK(r.ranges,i),effects:Z7.of(a?null:new M4(r.ranges,i)),scrollIntoView:!0})),!0}}const uut=({state:e,dispatch:t})=>e.field(D6,!1)?(t(e.update({effects:Z7.of(null)})),!0):!1,dut=a4e(1),fut=a4e(-1),mut=[{key:"Tab",run:dut,shift:fut},{key:"Escape",run:uut}],dne=Jt.define({combine(e){return e.length?e[0]:mut}}),hut=lg.highest(H7.compute([dne],e=>e.facet(dne)));function gAt(e,t){return{...t,apply:cut(e)}}const put=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(D6,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(a=>a.from<=r&&a.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:tK(n.ranges,i.field),effects:Z7.of(n.ranges.some(a=>a.field>i.field)?new M4(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),L6={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},o2=ir.define({map(e,t){let n=t.mapPos(e,-1,To.TrackAfter);return n??void 0}}),nK=new class extends zp{};nK.startSide=1;nK.endSide=-1;const o4e=qo.define({create(){return Lr.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(o2)&&(e=e.update({add:[nK.range(n.value,n.value+1)]}));return e}});function gut(){return[but,o4e]}const LM="()[]{}<>«»»«[]{}";function l4e(e){for(let t=0;t<LM.length;t+=2)if(LM.charCodeAt(t)==e)return LM.charAt(t+1);return wq(e<128?e:e+1)}function c4e(e,t){return e.languageDataAt("closeBrackets",t)[0]||L6}const xut=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),but=Yt.inputHandler.of((e,t,n,r)=>{if((xut?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&wf(Xl(r,0))==1||t!=i.from||n!=i.to)return!1;let a=wut(e.state,r);return a?(e.dispatch(a),!0):!1}),yut=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=c4e(e,e.selection.main.head).brackets||L6.brackets,i=null,a=e.changeByRange(o=>{if(o.empty){let l=kut(e.doc,o.head);for(let c of r)if(c==l&&X_(e.doc,o.head)==l4e(Xl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:bt.cursor(o.head-c.length)}}return{range:i=o}});return i||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!i},vut=[{key:"Backspace",run:yut}];function wut(e,t){let n=c4e(e,e.selection.main.head),r=n.brackets||L6.brackets;for(let i of r){let a=l4e(Xl(i,0));if(t==i)return a==i?Cut(e,i,r.indexOf(i+i+i)>-1,n):jut(e,i,a,n.before||L6.before);if(t==a&&u4e(e,e.selection.main.from))return Nut(e,i,a)}return null}function u4e(e,t){let n=!1;return e.field(o4e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function X_(e,t){let n=e.sliceString(t,t+2);return n.slice(0,wf(Xl(n,0)))}function kut(e,t){let n=e.sliceString(t-2,t);return wf(Xl(n,0))==n.length?n:n.slice(1)}function jut(e,t,n,r){let i=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:o2.of(o.to+t.length),range:bt.range(o.anchor+t.length,o.head+t.length)};let l=X_(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:o2.of(o.head+t.length),range:bt.cursor(o.head+t.length)}:{range:i=o}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function Nut(e,t,n){let r=null,i=e.changeByRange(a=>a.empty&&X_(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:bt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function Cut(e,t,n,r){let i=r.stringPrefixes||L6.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:o2.of(l.to+t.length),range:bt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=X_(e.doc,c),d;if(u==t){if(fne(e,c))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(u4e(e,c)){let h=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+h.length,insert:h},range:bt.cursor(c+h.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=mne(e,c-2*t.length,i))>-1&&fne(e,d))return{changes:{insert:t+t+t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=yi.Word&&mne(e,c,i)>-1&&!Sut(e,c,t,i))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fne(e,t){let n=Bo(e).resolveInner(t+1);return n.parent&&n.from==t}function Sut(e,t,n,r){let i=Bo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=i.firstChild;for(;d&&d.from==i.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=i.to==t&&i.parent;if(!u)break;i=u}return!1}function mne(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=yi.Word)return t;for(let i of n){let a=t-i.length;if(e.sliceDoc(a,t)==i&&r(e.sliceDoc(a-1,a))!=yi.Word)return a}return-1}function _ut(e={}){return[sut,ec,ao.of(e),nut,Aut,i4e]}const d4e=[{key:"Ctrl-Space",run:DM},{mac:"Alt-`",run:DM},{mac:"Alt-i",run:DM},{key:"Escape",run:Jct},{key:"ArrowDown",run:T9(!0)},{key:"ArrowUp",run:T9(!1)},{key:"PageDown",run:T9(!0,"page")},{key:"PageUp",run:T9(!1,"page")},{key:"Enter",run:Yct}],Aut=lg.highest(H7.computeN([ao],e=>e.facet(ao).defaultKeymap?[d4e]:[])),Eut=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=sK(e.state,n.from);return r.line?Tut(e):r.block?Mut(e):!1};function rK(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const Tut=rK(Put,0),Iut=rK(f4e,0),Mut=rK((e,t)=>f4e(e,t,Out(t)),0);function sK(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const oy=50;function Rut(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-oy,r),o=e.sliceDoc(i,i+oy),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:i+c,margin:c&&1}};let d,f;i-r<=2*oy?d=f=e.sliceDoc(r,i):(d=e.sliceDoc(r,r+oy),f=e.sliceDoc(i-oy,i));let h=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(f)[0].length,b=f.length-g-n.length;return d.slice(h,h+t.length)==t&&f.slice(b,b+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(d.charAt(h+t.length))?1:0},close:{pos:i-g-n.length,margin:/\s/.test(f.charAt(b-1))?1:0}}:null}function Out(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function f4e(e,t,n=t.selection.ranges){let r=n.map(a=>sK(t,a.from).block);if(!r.every(a=>a))return null;let i=n.map((a,o)=>Rut(t,r[o],a.from,a.to));if(e!=2&&!i.every(a=>a))return{changes:t.changes(n.map((a,o)=>i[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&i.some(a=>a)){let a=[];for(let o=0,l;o<i.length;o++)if(l=i[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Put(e,t,n=t.selection.ranges){let r=[],i=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let f=t.doc.lineAt(d);if(u==null&&(u=sK(t,f.from).line,!u))continue e;if(f.from>i&&(a==o||o>f.from)){i=f.from;let h=/^\s*/.exec(f.text)[0].length,g=h==f.length,b=f.text.slice(h,h+u.length)==u?h:-1;h<f.text.length&&h<c&&(c=h),r.push({line:f,comment:b,token:u,indent:h,empty:g,single:!1})}d=f.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:f}of r)(f||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const qL=q1.define(),Dut=q1.define(),Lut=Jt.define(),m4e=Jt.define({combine(e){return im(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,i)=>t(r,i)||n(r,i)})}}),h4e=qo.define({create(){return If.empty},update(e,t){let n=t.state.facet(m4e),r=t.annotation(qL);if(r){let c=sc.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=YN(d,d.length,n.minDepth,c):d=x4e(d,t.startState.selection),new If(u==0?r.rest:d,u==0?d:r.rest)}let i=t.annotation(Dut);if((i=="full"||i=="before")&&(e=e.isolate()),t.annotation(ja.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=sc.fromTransaction(t),o=t.annotation(ja.time),l=t.annotation(ja.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(i=="full"||i=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new If(e.done.map(sc.fromJSON),e.undone.map(sc.fromJSON))}});function $ut(e={}){return[h4e,m4e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?p4e:t.inputType=="historyRedo"?KL:null;return r?(t.preventDefault(),r(n)):!1}})]}function eA(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(h4e,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const p4e=eA(0,!1),KL=eA(1,!1),Fut=eA(0,!0),zut=eA(1,!0);class sc{constructor(t,n,r,i,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=i,this.selectionsAfter=a}setSelAfter(t){return new sc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(t){return new sc(t.changes&&Oa.fromJSON(t.changes),[],t.mapped&&Ff.fromJSON(t.mapped),t.startSelection&&bt.fromJSON(t.startSelection),t.selectionsAfter.map(bt.fromJSON))}static fromTransaction(t,n){let r=ju;for(let i of t.startState.facet(Lut)){let a=i(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new sc(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,ju)}static selection(t){return new sc(void 0,ju,void 0,void 0,t)}}function YN(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function But(e,t){let n=[],r=!1;return e.iterChangedRanges((i,a)=>n.push(i,a)),t.iterChangedRanges((i,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Uut(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function g4e(e,t){return e.length?t.length?e.concat(t):e:t}const ju=[],qut=200;function x4e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-qut));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),YN(e,e.length-1,1e9,n.setSelAfter(r)))}else return[sc.selection([t])]}function Kut(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function $M(e,t){if(!e.length)return e;let n=e.length,r=ju;for(;n;){let i=Hut(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let a=e.slice(0,n);return a[n-1]=i,a}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[sc.selection(r)]:ju}function Hut(e,t,n){let r=g4e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):ju,n);if(!e.changes)return sc.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new sc(i,ir.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const Vut=/^(input\.type|delete)($|\.)/;class If{constructor(t,n,r=0,i=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=i}isolate(){return this.prevTime?new If(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||Vut.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,But(l.changes,t.changes))||r=="input.type.compose")?o=YN(o,o.length-1,i.minDepth,new sc(t.changes.compose(l.changes),g4e(ir.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,ju)):o=YN(o,o.length,i.minDepth,t),new If(o,ju,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:ju;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Uut(a[a.length-1],t)?this:new If(x4e(this.done,t),this.undone,n,r)}addMapping(t){return new If($M(this.done,t),$M(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let i=t==0?this.done:this.undone;if(i.length==0)return null;let a=i[i.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:qL.of({side:t,rest:Kut(i),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=i.length==1?ju:i.slice(0,i.length-1);return a.mapped&&(l=$M(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:qL.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}If.empty=new If(ju,ju);const Wut=[{key:"Mod-z",run:p4e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:KL,preventDefault:!0},{linux:"Ctrl-Shift-z",run:KL,preventDefault:!0},{key:"Mod-u",run:Fut,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:zut,preventDefault:!0}];function R4(e,t){return bt.create(e.ranges.map(t),e.mainIndex)}function Ud(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function qd({state:e,dispatch:t},n){let r=R4(e.selection,n);return r.eq(e.selection,!0)?!1:(t(Ud(e,r)),!0)}function tA(e,t){return bt.cursor(t?e.to:e.from)}function b4e(e,t){return qd(e,n=>n.empty?e.moveByChar(n,t):tA(n,t))}function dl(e){return e.textDirectionAt(e.state.selection.main.head)==Hs.LTR}const y4e=e=>b4e(e,!dl(e)),v4e=e=>b4e(e,dl(e));function w4e(e,t){return qd(e,n=>n.empty?e.moveByGroup(n,t):tA(n,t))}const Zut=e=>w4e(e,!dl(e)),Gut=e=>w4e(e,dl(e));function Qut(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function nA(e,t,n){let r=Bo(e).resolveInner(t.head),i=n?Or.closedBy:Or.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Qut(e,u,i)?r=u:c=n?u.to:u.from}let a=r.type.prop(i),o,l;return a&&(o=n?Tf(e,r.from,1):Tf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,bt.cursor(l,n?-1:1)}const Yut=e=>qd(e,t=>nA(e.state,t,!dl(e))),Jut=e=>qd(e,t=>nA(e.state,t,dl(e)));function k4e(e,t){return qd(e,n=>{if(!n.empty)return tA(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const j4e=e=>k4e(e,!1),N4e=e=>k4e(e,!0);function C4e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function S4e(e,t){let n=C4e(e),{state:r}=e,i=R4(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):tA(o,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(i.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(Ud(r,i),{effects:a}),!0}const hne=e=>S4e(e,!1),HL=e=>S4e(e,!0);function cg(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(i=bt.cursor(r.from+a))}return i}const Xut=e=>qd(e,t=>cg(e,t,!0)),edt=e=>qd(e,t=>cg(e,t,!1)),tdt=e=>qd(e,t=>cg(e,t,!dl(e))),ndt=e=>qd(e,t=>cg(e,t,dl(e))),rdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).from,1)),sdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).to,-1));function idt(e,t,n){let r=!1,i=R4(e.selection,a=>{let o=Tf(e,a.head,-1)||Tf(e,a.head,1)||a.head>0&&Tf(e,a.head-1,1)||a.head<e.doc.length&&Tf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return bt.cursor(l)});return r?(t(Ud(e,i)),!0):!1}const adt=({state:e,dispatch:t})=>idt(e,t);function Fu(e,t){let n=R4(e.state.selection,r=>{let i=t(r);return bt.range(r.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(Ud(e.state,n)),!0)}function _4e(e,t){return Fu(e,n=>e.moveByChar(n,t))}const A4e=e=>_4e(e,!dl(e)),E4e=e=>_4e(e,dl(e));function T4e(e,t){return Fu(e,n=>e.moveByGroup(n,t))}const odt=e=>T4e(e,!dl(e)),ldt=e=>T4e(e,dl(e)),cdt=e=>Fu(e,t=>nA(e.state,t,!dl(e))),udt=e=>Fu(e,t=>nA(e.state,t,dl(e)));function I4e(e,t){return Fu(e,n=>e.moveVertically(n,t))}const M4e=e=>I4e(e,!1),R4e=e=>I4e(e,!0);function O4e(e,t){return Fu(e,n=>e.moveVertically(n,t,C4e(e).height))}const pne=e=>O4e(e,!1),gne=e=>O4e(e,!0),ddt=e=>Fu(e,t=>cg(e,t,!0)),fdt=e=>Fu(e,t=>cg(e,t,!1)),mdt=e=>Fu(e,t=>cg(e,t,!dl(e))),hdt=e=>Fu(e,t=>cg(e,t,dl(e))),pdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).from)),gdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).to)),xne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:0})),!0),bne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.doc.length})),!0),yne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:0})),!0),vne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),xdt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),bdt=({state:e,dispatch:t})=>{let n=rA(e).map(({from:r,to:i})=>bt.range(r,Math.min(i+1,e.doc.length)));return t(e.update({selection:bt.create(n),userEvent:"select"})),!0},ydt=({state:e,dispatch:t})=>{let n=R4(e.selection,r=>{let i=Bo(e),a=i.resolveStack(r.from,1);if(r.empty){let o=i.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return bt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(Ud(e,n)),!0)};function P4e(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){i.some(u=>u.head==c.head)||i.push(c);break}else{if(c.head==l.head)break;l=c}}}return i.length==r.ranges.length?!1:(e.dispatch(Ud(n,bt.create(i,i.length-1))),!0)}const vdt=e=>P4e(e,!1),wdt=e=>P4e(e,!0),kdt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=bt.create([n.main]):n.main.empty||(r=bt.create([bt.cursor(n.main.head)])),r?(t(Ud(e,r)),!0):!1};function G7(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,i=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=I9(e,c,!1)):c>o&&(n="delete.forward",c=I9(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=I9(e,o,!1),l=I9(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:bt.cursor(o,o<a.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function I9(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(i=>i(e)))r.between(t,t,(i,a)=>{i<t&&a>t&&(t=n?a:i)});return t}const D4e=(e,t,n)=>G7(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),l,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,i-o.from))){if(l[l.length-1]==" ")return i-1;let u=I4(l,a.tabSize),d=u%h0(a)||h0(a);for(let f=0;f<d&&l[l.length-1-f]==" ";f++)i--;c=i}else c=lo(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=lo(o.text,c-o.from,!1,!1)+o.from);return c}),VL=e=>D4e(e,!1,!0),L4e=e=>D4e(e,!0,!1),$4e=(e,t)=>G7(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let c=lo(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),F4e=e=>$4e(e,!1),jdt=e=>$4e(e,!0),Ndt=e=>G7(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Cdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Sdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),_dt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ls.of(["",""])},range:bt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},Adt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let i=r.from,a=e.doc.lineAt(i),o=i==a.from?i-1:lo(a.text,i-a.from,!1)+a.from,l=i==a.to?i+1:lo(a.text,i-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(i,l).append(e.doc.slice(o,i))},range:bt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function rA(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function z4e(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let a of rA(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)i.push(bt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)i.push(bt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:bt.create(i,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Edt=({state:e,dispatch:t})=>z4e(e,t,!1),Tdt=({state:e,dispatch:t})=>z4e(e,t,!0);function B4e(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of rA(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Idt=({state:e,dispatch:t})=>B4e(e,t,!1),Mdt=({state:e,dispatch:t})=>B4e(e,t,!0),Rdt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(rA(t).map(({from:i,to:a})=>(i>0?i--:a<t.doc.length&&a++,{from:i,to:a}))),r=R4(t.selection,i=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(i.head),l=e.coordsAtPos(i.head,i.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(i,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Odt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Bo(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(Or.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const wne=U4e(!1),Pdt=U4e(!0);function U4e(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(i=>{let{from:a,to:o}=i,l=t.doc.lineAt(a),c=!e&&a==o&&Odt(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new Y_(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=Kq(u,a);for(d==null&&(d=I4(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let f=["",R6(t,d)];return c&&f.push(R6(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ls.of(f)},range:bt.cursor(a+1+f[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function iK(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,i,r),n=l.number),o=l.to+1}let a=e.changes(i);return{changes:i,range:bt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Ddt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Y_(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),i=iK(e,(a,o,l)=>{let c=Kq(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=R6(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return i.changes.empty||t(e.update(i,{userEvent:"indent"})),!0},q4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Q_)})}),{userEvent:"input.indent"})),!0),K4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{let i=/^\s*/.exec(n.text)[0];if(!i)return;let a=I4(i,e.tabSize),o=0,l=R6(e,Math.max(0,a-h0(e)));for(;o<i.length&&o<l.length&&i.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+i.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Ldt=e=>(e.setTabFocusMode(),!0),$dt=[{key:"Ctrl-b",run:y4e,shift:A4e,preventDefault:!0},{key:"Ctrl-f",run:v4e,shift:E4e},{key:"Ctrl-p",run:j4e,shift:M4e},{key:"Ctrl-n",run:N4e,shift:R4e},{key:"Ctrl-a",run:rdt,shift:pdt},{key:"Ctrl-e",run:sdt,shift:gdt},{key:"Ctrl-d",run:L4e},{key:"Ctrl-h",run:VL},{key:"Ctrl-k",run:Ndt},{key:"Ctrl-Alt-h",run:F4e},{key:"Ctrl-o",run:_dt},{key:"Ctrl-t",run:Adt},{key:"Ctrl-v",run:HL}],Fdt=[{key:"ArrowLeft",run:y4e,shift:A4e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Zut,shift:odt,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:tdt,shift:mdt,preventDefault:!0},{key:"ArrowRight",run:v4e,shift:E4e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Gut,shift:ldt,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ndt,shift:hdt,preventDefault:!0},{key:"ArrowUp",run:j4e,shift:M4e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xne,shift:yne},{mac:"Ctrl-ArrowUp",run:hne,shift:pne},{key:"ArrowDown",run:N4e,shift:R4e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:bne,shift:vne},{mac:"Ctrl-ArrowDown",run:HL,shift:gne},{key:"PageUp",run:hne,shift:pne},{key:"PageDown",run:HL,shift:gne},{key:"Home",run:edt,shift:fdt,preventDefault:!0},{key:"Mod-Home",run:xne,shift:yne},{key:"End",run:Xut,shift:ddt,preventDefault:!0},{key:"Mod-End",run:bne,shift:vne},{key:"Enter",run:wne,shift:wne},{key:"Mod-a",run:xdt},{key:"Backspace",run:VL,shift:VL,preventDefault:!0},{key:"Delete",run:L4e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:F4e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:jdt,preventDefault:!0},{mac:"Mod-Backspace",run:Cdt,preventDefault:!0},{mac:"Mod-Delete",run:Sdt,preventDefault:!0}].concat($dt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),zdt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Yut,shift:cdt},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Jut,shift:udt},{key:"Alt-ArrowUp",run:Edt},{key:"Shift-Alt-ArrowUp",run:Idt},{key:"Alt-ArrowDown",run:Tdt},{key:"Shift-Alt-ArrowDown",run:Mdt},{key:"Mod-Alt-ArrowUp",run:vdt},{key:"Mod-Alt-ArrowDown",run:wdt},{key:"Escape",run:kdt},{key:"Mod-Enter",run:Pdt},{key:"Alt-l",mac:"Ctrl-l",run:bdt},{key:"Mod-i",run:ydt,preventDefault:!0},{key:"Mod-[",run:K4e},{key:"Mod-]",run:q4e},{key:"Mod-Alt-\\",run:Ddt},{key:"Shift-Mod-k",run:Rdt},{key:"Shift-Mod-\\",run:adt},{key:"Mod-/",run:Eut},{key:"Alt-A",run:Iut},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Ldt}].concat(Fdt),Bdt={key:"Tab",run:q4e,shift:K4e};function Udt(e,t,n,r){const i=Wf(bi),a=Mc(C0e),o=se.useRef(null),{lexicalNode:l}=eL(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),f=se.useCallback(h=>{var g,b,v,j,k,w;if(h.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const C=N.doc.length,A=N.selection.ranges[0].to;C===A&&(c.current?(i==null||i.update(()=>{var _,E;const T=$f(e);T.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),T.selectNext()):T.insertAfter(Zs())}),c.current=!1):c.current=!0)}}else if(h.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(i==null||i.update(()=>{var A,_;const E=$f(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(h.key==="Enter")h.stopPropagation();else if(h.key==="Backspace"||h.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(i==null||i.update(()=>{$f(e).remove()}))}},[i,e]);return se.useEffect(()=>{const h=o.current;return setTimeout(()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.addEventListener("keydown",f)},300),()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",f)}},[o,d,f,n]),se.useEffect(()=>{r.subscribe(()=>{var h,g;(g=(h=o.current)==null?void 0:h.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function Ct(e){return new Ult(Vq.define(e))}function wh(e){return mt(()=>import("./index-HtPOAsph.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const qdt=[ot.of({name:"C",extensions:["c","h","ino"],load(){return mt(()=>import("./index-IQg-mKY2.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return mt(()=>import("./index-IQg-mKY2.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return wh("Cassandra")}}),ot.of({name:"CSS",extensions:["css"],load(){return mt(()=>import("./index-Br5zwB0Z.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),ot.of({name:"Go",extensions:["go"],load(){return mt(()=>import("./index-DyAGGhVR.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),ot.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return mt(()=>import("./index-CUmK5YNa.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),ot.of({name:"Java",extensions:["java"],load(){return mt(()=>import("./index-D_H502gP.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),ot.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),ot.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return mt(()=>import("./index-RDOFpY3r.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),ot.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return mt(()=>import("./index-D7g9B35Q.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),ot.of({name:"JSX",extensions:["jsx"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),ot.of({name:"LESS",extensions:["less"],load(){return mt(()=>import("./index-BNFWBcMX.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),ot.of({name:"Liquid",extensions:["liquid"],load(){return mt(()=>import("./index-RV97u8HI.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),ot.of({name:"MariaDB SQL",load(){return wh("MariaSQL")}}),ot.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return mt(()=>import("./index-CBJ1GRlx.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),ot.of({name:"MS SQL",load(){return wh("MSSQL")}}),ot.of({name:"MySQL",load(){return wh("MySQL")}}),ot.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return mt(()=>import("./index-Cnn7Ze7A.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),ot.of({name:"PLSQL",extensions:["pls"],load(){return wh("PLSQL")}}),ot.of({name:"PostgreSQL",load(){return wh("PostgreSQL")}}),ot.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return mt(()=>import("./index-BjDcoM23.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),ot.of({name:"Rust",extensions:["rs"],load(){return mt(()=>import("./index-DQIgDJJD.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),ot.of({name:"Sass",extensions:["sass"],load(){return mt(()=>import("./index-CxutLWF3.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),ot.of({name:"SCSS",extensions:["scss"],load(){return mt(()=>import("./index-CxutLWF3.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),ot.of({name:"SQL",extensions:["sql"],load(){return wh("StandardSQL")}}),ot.of({name:"SQLite",load(){return wh("SQLite")}}),ot.of({name:"TSX",extensions:["tsx"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),ot.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),ot.of({name:"WebAssembly",extensions:["wat","wast"],load(){return mt(()=>import("./index-DRi3oX80.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),ot.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return mt(()=>import("./index-PghKETw5.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),ot.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return mt(()=>import("./index-BwOeluhm.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),ot.of({name:"APL",extensions:["dyalog","apl"],load(){return mt(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>Ct(e.apl))}}),ot.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return mt(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>Ct(e.asciiArmor))}}),ot.of({name:"ASN.1",extensions:["asn","asn1"],load(){return mt(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>Ct(e.asn1({})))}}),ot.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return mt(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>Ct(e.asterisk))}}),ot.of({name:"Brainfuck",extensions:["b","bf"],load(){return mt(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>Ct(e.brainfuck))}}),ot.of({name:"Cobol",extensions:["cob","cpy"],load(){return mt(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>Ct(e.cobol))}}),ot.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.csharp))}}),ot.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"ClojureScript",extensions:["cljs"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return mt(()=>import("./css-BnMrqG3P.js"),[]).then(e=>Ct(e.gss))}}),ot.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return mt(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>Ct(e.cmake))}}),ot.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return mt(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>Ct(e.coffeeScript))}}),ot.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return mt(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>Ct(e.commonLisp))}}),ot.of({name:"Cypher",extensions:["cyp","cypher"],load(){return mt(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>Ct(e.cypher))}}),ot.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return mt(()=>import("./python-BuPzkPfP.js"),[]).then(e=>Ct(e.cython))}}),ot.of({name:"Crystal",extensions:["cr"],load(){return mt(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>Ct(e.crystal))}}),ot.of({name:"D",extensions:["d"],load(){return mt(()=>import("./d-pRatUO7H.js"),[]).then(e=>Ct(e.d))}}),ot.of({name:"Dart",extensions:["dart"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.dart))}}),ot.of({name:"diff",extensions:["diff","patch"],load(){return mt(()=>import("./diff-DbItnlRl.js"),[]).then(e=>Ct(e.diff))}}),ot.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return mt(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>Ct(e.dockerFile))}}),ot.of({name:"DTD",extensions:["dtd"],load(){return mt(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>Ct(e.dtd))}}),ot.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return mt(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>Ct(e.dylan))}}),ot.of({name:"EBNF",load(){return mt(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>Ct(e.ebnf))}}),ot.of({name:"ECL",extensions:["ecl"],load(){return mt(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>Ct(e.ecl))}}),ot.of({name:"edn",extensions:["edn"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Eiffel",extensions:["e"],load(){return mt(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>Ct(e.eiffel))}}),ot.of({name:"Elm",extensions:["elm"],load(){return mt(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>Ct(e.elm))}}),ot.of({name:"Erlang",extensions:["erl"],load(){return mt(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>Ct(e.erlang))}}),ot.of({name:"Esper",load(){return mt(()=>import("./sql-D0XecflT.js"),[]).then(e=>Ct(e.esper))}}),ot.of({name:"Factor",extensions:["factor"],load(){return mt(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>Ct(e.factor))}}),ot.of({name:"FCL",load(){return mt(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>Ct(e.fcl))}}),ot.of({name:"Forth",extensions:["forth","fth","4th"],load(){return mt(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>Ct(e.forth))}}),ot.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return mt(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>Ct(e.fortran))}}),ot.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.fSharp))}}),ot.of({name:"Gas",extensions:["s"],load(){return mt(()=>import("./gas-Bneqetm1.js"),[]).then(e=>Ct(e.gas))}}),ot.of({name:"Gherkin",extensions:["feature"],load(){return mt(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>Ct(e.gherkin))}}),ot.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return mt(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>Ct(e.groovy))}}),ot.of({name:"Haskell",extensions:["hs"],load(){return mt(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>Ct(e.haskell))}}),ot.of({name:"Haxe",extensions:["hx"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.haxe))}}),ot.of({name:"HXML",extensions:["hxml"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.hxml))}}),ot.of({name:"HTTP",load(){return mt(()=>import("./http-DBlCnlav.js"),[]).then(e=>Ct(e.http))}}),ot.of({name:"IDL",extensions:["pro"],load(){return mt(()=>import("./idl-BEugSyMb.js"),[]).then(e=>Ct(e.idl))}}),ot.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return mt(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>Ct(e.jsonld))}}),ot.of({name:"Julia",extensions:["jl"],load(){return mt(()=>import("./julia-DuME0IfC.js"),[]).then(e=>Ct(e.julia))}}),ot.of({name:"Kotlin",extensions:["kt","kts"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.kotlin))}}),ot.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return mt(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>Ct(e.liveScript))}}),ot.of({name:"Lua",extensions:["lua"],load(){return mt(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>Ct(e.lua))}}),ot.of({name:"mIRC",extensions:["mrc"],load(){return mt(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>Ct(e.mirc))}}),ot.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return mt(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>Ct(e.mathematica))}}),ot.of({name:"Modelica",extensions:["mo"],load(){return mt(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>Ct(e.modelica))}}),ot.of({name:"MUMPS",extensions:["mps"],load(){return mt(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>Ct(e.mumps))}}),ot.of({name:"Mbox",extensions:["mbox"],load(){return mt(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>Ct(e.mbox))}}),ot.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return mt(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>Ct(e.nginx))}}),ot.of({name:"NSIS",extensions:["nsh","nsi"],load(){return mt(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>Ct(e.nsis))}}),ot.of({name:"NTriples",extensions:["nt","nq"],load(){return mt(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>Ct(e.ntriples))}}),ot.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveC))}}),ot.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveCpp))}}),ot.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.oCaml))}}),ot.of({name:"Octave",extensions:["m"],load(){return mt(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>Ct(e.octave))}}),ot.of({name:"Oz",extensions:["oz"],load(){return mt(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>Ct(e.oz))}}),ot.of({name:"Pascal",extensions:["p","pas"],load(){return mt(()=>import("./pascal--L3eBynH.js"),[]).then(e=>Ct(e.pascal))}}),ot.of({name:"Perl",extensions:["pl","pm"],load(){return mt(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>Ct(e.perl))}}),ot.of({name:"Pig",extensions:["pig"],load(){return mt(()=>import("./pig-CevX1Tat.js"),[]).then(e=>Ct(e.pig))}}),ot.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return mt(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>Ct(e.powerShell))}}),ot.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return mt(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>Ct(e.properties))}}),ot.of({name:"ProtoBuf",extensions:["proto"],load(){return mt(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>Ct(e.protobuf))}}),ot.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return mt(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>Ct(e.pug))}}),ot.of({name:"Puppet",extensions:["pp"],load(){return mt(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>Ct(e.puppet))}}),ot.of({name:"Q",extensions:["q"],load(){return mt(()=>import("./q-pXgVlZs6.js"),[]).then(e=>Ct(e.q))}}),ot.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return mt(()=>import("./r-B6wPVr8A.js"),[]).then(e=>Ct(e.r))}}),ot.of({name:"RPM Changes",load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmChanges))}}),ot.of({name:"RPM Spec",extensions:["spec"],load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmSpec))}}),ot.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return mt(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>Ct(e.ruby))}}),ot.of({name:"SAS",extensions:["sas"],load(){return mt(()=>import("./sas-B4kiWyti.js"),[]).then(e=>Ct(e.sas))}}),ot.of({name:"Scala",extensions:["scala"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.scala))}}),ot.of({name:"Scheme",extensions:["scm","ss"],load(){return mt(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>Ct(e.scheme))}}),ot.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return mt(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>Ct(e.shell))}}),ot.of({name:"Sieve",extensions:["siv","sieve"],load(){return mt(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>Ct(e.sieve))}}),ot.of({name:"Smalltalk",extensions:["st"],load(){return mt(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>Ct(e.smalltalk))}}),ot.of({name:"Solr",load(){return mt(()=>import("./solr-DehyRSwq.js"),[]).then(e=>Ct(e.solr))}}),ot.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.sml))}}),ot.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return mt(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>Ct(e.sparql))}}),ot.of({name:"Spreadsheet",alias:["excel","formula"],load(){return mt(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>Ct(e.spreadsheet))}}),ot.of({name:"Squirrel",extensions:["nut"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.squirrel))}}),ot.of({name:"Stylus",extensions:["styl"],load(){return mt(()=>import("./stylus-B533Al4x.js"),[]).then(e=>Ct(e.stylus))}}),ot.of({name:"Swift",extensions:["swift"],load(){return mt(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>Ct(e.swift))}}),ot.of({name:"sTeX",load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"Tcl",extensions:["tcl"],load(){return mt(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>Ct(e.tcl))}}),ot.of({name:"Textile",extensions:["textile"],load(){return mt(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>Ct(e.textile))}}),ot.of({name:"TiddlyWiki",load(){return mt(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>Ct(e.tiddlyWiki))}}),ot.of({name:"Tiki wiki",load(){return mt(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>Ct(e.tiki))}}),ot.of({name:"TOML",extensions:["toml"],load(){return mt(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>Ct(e.toml))}}),ot.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return mt(()=>import("./troff-wAsdV37c.js"),[]).then(e=>Ct(e.troff))}}),ot.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return mt(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>Ct(e.ttcn))}}),ot.of({name:"TTCN_CFG",extensions:["cfg"],load(){return mt(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>Ct(e.ttcnCfg))}}),ot.of({name:"Turtle",extensions:["ttl"],load(){return mt(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>Ct(e.turtle))}}),ot.of({name:"Web IDL",extensions:["webidl"],load(){return mt(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>Ct(e.webIDL))}}),ot.of({name:"VB.NET",extensions:["vb"],load(){return mt(()=>import("./vb-CmGdzxic.js"),[]).then(e=>Ct(e.vb))}}),ot.of({name:"VBScript",extensions:["vbs"],load(){return mt(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>Ct(e.vbScript))}}),ot.of({name:"Velocity",extensions:["vtl"],load(){return mt(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>Ct(e.velocity))}}),ot.of({name:"Verilog",extensions:["v"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return mt(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>Ct(e.vhdl))}}),ot.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return mt(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>Ct(e.xQuery))}}),ot.of({name:"Yacas",extensions:["ys"],load(){return mt(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>Ct(e.yacas))}}),ot.of({name:"Z80",extensions:["z80"],load(){return mt(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>Ct(e.z80))}}),ot.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.mscgen))}}),ot.of({name:"Xù",extensions:["xu"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.xu))}}),ot.of({name:"MsGenny",extensions:["msgenny"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.msgenny))}}),ot.of({name:"Vue",extensions:["vue"],load(){return mt(()=>import("./index-DooRYrN2.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),ot.of({name:"Angular Template",load(){return mt(()=>import("./index-DtA8NpRC.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],kne="#2e3440",aK="#3b4252",jne="#434c5e",M9="#4c566a",Nne="#e5e9f0",WL="#eceff4",FM="#8fbcbb",Cne="#88c0d0",Kdt="#81a1c1",Gu="#5e81ac",Hdt="#bf616a",Rx="#d08770",zM="#ebcb8b",Sne="#a3be8c",Vdt="#b48ead",_ne="#d30102",oK=WL,BM=oK,Wdt="#ffffff",UM=aK,Zdt=oK,Ane=aK,Gdt=Yt.theme({"&":{color:kne,backgroundColor:Wdt},".cm-content":{caretColor:Ane},".cm-cursor, .cm-dropCursor":{borderLeftColor:Ane},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Zdt},".cm-panels":{backgroundColor:oK,color:M9},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${M9}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:Nne},".cm-activeLine":{backgroundColor:BM},".cm-selectionMatch":{backgroundColor:Nne},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${M9}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:WL},".cm-gutters":{backgroundColor:WL,color:kne,border:"none"},".cm-activeLineGutter":{backgroundColor:BM},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:UM},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:UM,borderBottomColor:UM},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:BM,color:M9}}},{dark:!1}),Qdt=W7.define([{tag:dt.keyword,color:Gu},{tag:[dt.name,dt.deleted,dt.character,dt.propertyName,dt.macroName],color:Rx},{tag:[dt.variableName],color:Rx},{tag:[dt.function(dt.variableName)],color:Gu},{tag:[dt.labelName],color:Kdt},{tag:[dt.color,dt.constant(dt.name),dt.standard(dt.name)],color:Gu},{tag:[dt.definition(dt.name),dt.separator],color:Sne},{tag:[dt.brace],color:FM},{tag:[dt.annotation],color:_ne},{tag:[dt.number,dt.changed,dt.annotation,dt.modifier,dt.self,dt.namespace],color:Cne},{tag:[dt.typeName,dt.className],color:zM},{tag:[dt.operator,dt.operatorKeyword],color:Sne},{tag:[dt.tagName],color:Vdt},{tag:[dt.squareBracket],color:Hdt},{tag:[dt.angleBracket],color:Rx},{tag:[dt.attributeName],color:zM},{tag:[dt.regexp],color:Gu},{tag:[dt.quote],color:aK},{tag:[dt.string],color:Rx},{tag:dt.link,color:FM,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[dt.url,dt.escape,dt.special(dt.string)],color:Rx},{tag:[dt.meta],color:Cne},{tag:[dt.comment],color:jne,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold",color:Gu},{tag:dt.emphasis,fontStyle:"italic",color:Gu},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.heading,fontWeight:"bold",color:Gu},{tag:dt.special(dt.heading1),fontWeight:"bold",color:Gu},{tag:dt.heading1,fontWeight:"bold",color:Gu},{tag:[dt.heading2,dt.heading3,dt.heading4],fontWeight:"bold",color:Gu},{tag:[dt.heading5,dt.heading6],color:Gu},{tag:[dt.atom,dt.bool,dt.special(dt.variableName)],color:Rx},{tag:[dt.processingInstruction,dt.inserted],color:FM},{tag:[dt.contentSeparator],color:zM},{tag:dt.invalid,color:jne,borderBottom:`1px dotted ${_ne}`}]),Ydt=[Gdt,V5e(Qdt)],Ene=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class M5{constructor(t,n,r=0,i=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,i),this.bufferStart=r,this.normalize=a?l=>a(Ene(l)):Ene,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Xl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=wq(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=wf(t);let i=this.normalize(n);if(i.length)for(let a=0,o=r;;a++){let l=i.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==i.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let i=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?i={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?i={from:n,to:r}:this.matches.push(1,n)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(M5.prototype[Symbol.iterator]=function(){return this});const H4e={from:-1,to:-1,match:/.*/.exec("")},lK="gm"+(/x/.unicode==null?"":"u");class V4e{constructor(t,n,r,i=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=H4e,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new W4e(t,n,r,i,a);this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(i);this.curLineStart=o.from,this.matchPos=JN(t,i),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,i=r+n[0].length;if(this.matchPos=JN(this.text,i+(r==i?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<i||r>this.value.to)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const qM=new WeakMap;class T3{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let i=qM.get(t);if(!i||i.from>=r||i.to<=n){let l=new T3(n,t.sliceString(n,r));return qM.set(t,l),l}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),qM.set(t,new T3(o,a)),new T3(n,a.slice(n-o,r-o))}}class W4e{constructor(t,n,r,i,a){this.text=t,this.to=a,this.done=!1,this.value=H4e,this.matchPos=JN(t,i),this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=T3.get(t,i,this.chunkEnd(i+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,i=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this.matchPos=JN(this.text,i+(r==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=T3.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(V4e.prototype[Symbol.iterator]=W4e.prototype[Symbol.iterator]=function(){return this});function Jdt(e){try{return new RegExp(e,lK),!0}catch{return!1}}function JN(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Xdt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=nlt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return i.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,f]=o,h=d?+d.slice(1):0,g=u?+u:l.number;if(u&&f){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=bt.cursor(b.from+Math.max(0,Math.min(h,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},eft={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},tft=Jt.define({combine(e){return im(e,eft,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function nft(e){return[oft,aft]}const rft=$n.mark({class:"cm-selectionMatch"}),sft=$n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Tne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=yi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=yi.Word)}function ift(e,t,n,r){return e(t.sliceDoc(n,n+1))==yi.Word&&e(t.sliceDoc(r-1,r))==yi.Word}const aft=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(tft),{state:n}=e,r=n.selection;if(r.ranges.length>1)return $n.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return $n.none;let c=n.wordAt(i.head);if(!c)return $n.none;o=n.charCategorizer(i.head),a=n.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<t.minSelectionLength||c>200)return $n.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Tne(o,n,i.from,i.to)&&ift(o,n,i.from,i.to)))return $n.none}else if(a=n.sliceDoc(i.from,i.to),!a)return $n.none}let l=[];for(let c of e.visibleRanges){let u=new M5(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:f}=u.value;if((!o||Tne(o,n,d,f))&&(i.empty&&d<=i.from&&f>=i.to?l.push(sft.range(d,f)):(d>=i.to||f<=i.from)&&l.push(rft.range(d,f)),l.length>t.maxMatches))return $n.none}}return $n.set(l)}},{decorations:e=>e.decorations}),oft=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),lft=({state:e,dispatch:t})=>{let{selection:n}=e,r=bt.create(n.ranges.map(i=>e.wordAt(i.head)||bt.cursor(i.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function cft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let o=!1,l=new M5(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new M5(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const uft=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return lft({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let i=cft(e,r);return i?(t(e.update({selection:e.selection.addRange(bt.range(i.from,i.to),!1),effects:Yt.scrollIntoView(i.to)})),!0):!1},O4=Jt.define({combine(e){return im(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Nft(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class Z4e{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Jdt(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
|
|
1297
|
+
`);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let i=this.rangeIndex;;){let a=this.ranges[i].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),i++,i==this.ranges.length))break;let o=this.ranges[i].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let i=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?i>a:i>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-i}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,i){let a=4;if(this.ranges.length>1){i=this.skipGapsTo(n,i,1),n+=i;let l=this.chunk.length;i=this.skipGapsTo(r,i,-1),r+=i,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),i}parseLine(t){let{line:n,end:r}=this.nextLine(),i=0,{streamParser:a}=this.lang,o=new Q5e(n,t?t.state.tabSize:4,t?h0(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=J5e(a.token,o,this.state);if(l&&(i=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,i)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=Vs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Tct,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new Vs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Vs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function J5e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let i=e(t,n);if(t.pos>t.start)return i}throw new Error("Stream parser failed to advance stream.")}const Zq=Object.create(null),O6=[Ll.none],Tct=new zq(O6),rne=[],sne=Object.create(null),X5e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])X5e[e]=t4e(Zq,t);class e4e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),X5e)}resolve(t){return t?this.table[t]||(this.table[t]=t4e(this.extra,t)):0}}const Ict=new e4e(Zq);function OM(e,t){rne.indexOf(e)>-1||(rne.push(e),console.warn(t))}function t4e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||dt[u];d?typeof d=="function"?c.length?c=c.map(d):OM(u,`Modifier ${u} used at start of tag`):c.length?OM(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:OM(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),i=r+" "+n.map(l=>l.id),a=sne[i];if(a)return a.id;let o=sne[i]=Ll.define({id:O6.length,name:r,props:[Olt({[r]:n})]});return O6.push(o),o.id}function Mct(e,t){let n=Ll.define({id:O6.length,name:"Document",props:[a2.add(()=>e),P5e.add(()=>r=>t.getIndent(r))],top:!0});return O6.push(n),n}Hs.RTL,Hs.LTR;class n4e{constructor(t,n,r,i){this.state=t,this.pos=n,this.explicit=r,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=Bo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),i=n.text.slice(r-n.from,this.pos-n.from),a=i.search(r4e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:i.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function ine(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Rct(e){let t=Object.create(null),n=Object.create(null);for(let{label:i}of e){t[i[0]]=!0;for(let a=1;a<i.length;a++)n[i[a]]=!0}let r=ine(t)+ine(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Oct(e){let t=e.map(i=>typeof i=="string"?{label:i}:i),[n,r]=t.every(i=>/^\w+$/.test(i.label))?[/\w*$/,/\w+$/]:Rct(t);return i=>{let a=i.matchBefore(r);return a||i.explicit?{from:a?a.from:i.pos,options:t,validFor:n}:null}}function pAt(e,t){return n=>{for(let r=Bo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class ane{constructor(t,n,r,i){this.completion=t,this.source=n,this.match=r,this.score=i}}function E2(e){return e.selection.main.from}function r4e(e,t){var n;let{source:r}=e,i=t&&r[0]!="^",a=r[r.length-1]!="$";return!i&&!a?e:new RegExp(`${i?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const Gq=q1.define();function Pct(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(l=>{if(l!=i&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==i.from?l.to:l.from+o,insert:c},range:bt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const one=new WeakMap;function Dct(e){if(!Array.isArray(e))return e;let t=one.get(e);return t||one.set(e,t=Oct(e)),t}const GN=ir.define(),P6=ir.define();class Lct{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Xl(t,n),i=wf(r);this.chars.push(r);let a=t.slice(n,n+i),o=a.toUpperCase();this.folded.push(Xl(o==a?a.toLowerCase():o,0)),n+=i}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:i,precise:a,byWord:o}=this;if(n.length==1){let w=Xl(t,0),N=wf(w),C=N==t.length?0:-100;if(w!=n[0])if(w==r[0])C+=-200;else return null;return this.ret(C,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let C=Xl(t,w);(C==n[u]||C==r[u])&&(i[u++]=w),w+=wf(C)}if(u<c)return null}let d=0,f=0,h=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),C=0;w<N&&f<c;){let A=Xl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=wq(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||C==0&&E!=0)&&(n[f]==A||r[f]==A&&(h=!0)?o[f++]=w:o.length&&(k=!1)),C=E,w+=wf(A)}return f==c&&o[0]==0&&k?this.result(-100+(h?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):f==c?this.result(-100+(h?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((i[0]?-700:0)+-200+-1100,i,t)}result(t,n,r){let i=[],a=0;for(let o of n){let l=o+(this.astral?wf(Xl(r,o)):1);a&&i[a-1]==o?i[a-1]=l:(i[a++]=o,i[a++]=l)}return this.ret(t-r.length,i)}}class $ct{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const ao=Jt.define({combine(e){return im(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Fct,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>lne(t(r),n(r)),optionClass:(t,n)=>r=>lne(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function lne(e,t){return e?t?e+" "+t:e:t}function Fct(e,t,n,r,i,a){let o=e.textDirection==Hs.RTL,l=o,c=!1,u="top",d,f,h=t.left-i.left,g=i.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&h<Math.min(b,g)?l=!1:!l&&g<Math.min(b,h)&&(l=!0),b<=(l?h:g))d=Math.max(i.top,Math.min(n.top,i.bottom-v))-t.top,f=Math.min(400,l?h:g);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let w=i.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${f/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const Qq=ir.define();function zct(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(i=>"cm-completionIcon-"+i)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,i,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],f=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let h=o.appendChild(document.createElement("span"));h.appendChild(document.createTextNode(l.slice(d,f))),h.className="cm-completionMatchedText",c=f}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function PM(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let i=Math.floor(t/n);return{from:i*n,to:(i+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Bct{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let i=t.state.field(n),{options:a,selected:o}=i.open,l=t.state.facet(ao);this.optionContent=zct(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=PM(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,f;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(f=/-(\d+)$/.exec(d.id))&&+f[1]<u.length){this.applyCompletion(t,u[+f[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:Qq.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet(ao).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:P6.of(null)})}),this.showOptions(a,i.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=i){let{options:a,selected:o,disabled:l}=r.open;(!i.open||i.open.options!=a)&&(this.range=PM(a.length,o,t.state.facet(ao).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=i.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=PM(n.options.length,n.selected,this.view.state.facet(ao).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:i}=n.options[n.selected],{info:a}=i;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(i);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,i)}).catch(l=>rc(this.view.state,l,"completion info")):(this.addInfoPane(o,i),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:i,destroy:a}=t;r.appendChild(i),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,i=this.range.from;r;r=r.nextSibling,i++)r.nodeName!="LI"||!r.id?i--:i==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&qct(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return i.top>Math.min(a.bottom,n.bottom)-10||i.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet(ao).positionInfo(this.view,n,i,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const i=document.createElement("ul");i.id=n,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",o=>{o.target==i&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let h=typeof u=="string"?u:u.name;if(h!=a&&(o>r.from||r.from==0))if(a=h,typeof u!="string"&&u.header)i.appendChild(u.header(u));else{let g=i.appendChild(document.createElement("completion-section"));g.textContent=h}}const d=i.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let f=this.optionClass(l);f&&(d.className=f);for(let h of this.optionContent){let g=h(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&i.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Uct(e,t){return n=>new Bct(n,e,t)}function qct(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function cne(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function Kct(e,t){let n=[],r=null,i=null,a=d=>{n.push(d);let{section:f}=d.completion;if(f){r||(r=[]);let h=typeof f=="string"?f:f.name;r.some(g=>g.name==h)||r.push(typeof f=="string"?{name:h}:f)}},o=t.facet(ao);for(let d of e)if(d.hasResult()){let f=d.result.getMatch;if(d.result.filter===!1)for(let h of d.result.options)a(new ane(h,d.source,f?f(h):[],1e9-n.length));else{let h=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new $ct(h):new Lct(h);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?f?f(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new ane(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;i||(i=Object.create(null)),i[w]=Math.max(k,i[w]||-1e9)}}}}if(r){let d=Object.create(null),f=0,h=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?i[b.name]-i[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(h))f-=1e5,d[g.name]=f;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((f,h)=>h.score-f.score||u(f.completion,h.completion))){let f=d.completion;!c||c.label!=f.label||c.detail!=f.detail||c.type!=null&&f.type!=null&&c.type!=f.type||c.apply!=f.apply||c.boost!=f.boost?l.push(d):cne(d.completion)>cne(c)&&(l[l.length-1]=d),c=d.completion}return l}class u3{constructor(t,n,r,i,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=i,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new u3(this.options,une(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(u=>u.isPending))return i.setDisabled();let l=Kct(t,n);if(!l.length)return i&&t.some(u=>u.isPending)?i.setDisabled():null;let c=n.facet(ao).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let u=i.options[i.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new u3(l,une(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Qct,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new u3(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new u3(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class QN{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new QN(Zct,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(ao),a=(r.override||n.languageDataAt("autocomplete",E2(n)).map(Dct)).map(c=>(this.active.find(d=>d.source==c)||new ku(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(Yq));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Hct(a,this.active)||l?o=u3.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ku(c.source,0):c));for(let c of t.effects)c.is(Qq)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new QN(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Vct:Wct}}function Hct(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}const Vct={"aria-autocomplete":"list"},Wct={};function une(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Zct=[];function s4e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(Gq);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ku{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=s4e(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new ku(i.source,0)),r&4&&i.state==0&&(i=new ku(this.source,1)),i=i.updateFor(t,r);for(let a of t.effects)if(a.is(GN))i=new ku(i.source,1,a.value);else if(a.is(P6))i=new ku(i.source,0);else if(a.is(Yq))for(let o of a.value)o.source==i.source&&(i=o);return i}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(E2(t.state))}}class E3 extends ku{constructor(t,n,r,i,a,o){super(t,3,n),this.limit=r,this.result=i,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=E2(t.state);if(l>o||!i||n&2&&(E2(t.startState)==this.from||l<this.limit))return new ku(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return Gct(i.validFor,t.state,a,o)?new E3(this.source,this.explicit,c,i,a,o):i.update&&(i=i.update(i,a,o,new n4e(t.state,l,!1)))?new E3(this.source,this.explicit,c,i,i.from,(r=i.to)!==null&&r!==void 0?r:E2(t.state)):new ku(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new E3(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ku(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function Gct(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e=="function"?e(i,n,r,t):r4e(e,!0).test(i)}const Yq=ir.define({map(e,t){return e.map(n=>n.map(t))}}),ec=qo.define({create(){return QN.start()},update(e,t){return e.update(t)},provide:e=>[$q.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function Jq(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(ec).active.find(i=>i.source==t.source);return r instanceof E3?(typeof n=="string"?e.dispatch({...Pct(e.state,n,r.from,r.to),annotations:Gq.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Qct=Uct(ec,Jq);function T9(e,t="option"){return n=>{let r=n.state.field(ec,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(ao).interactionDelay)return!1;let i=1,a;t=="page"&&(a=v5e(n,r.open.tooltip))&&(i=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+i*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:Qq.of(l)}),!0}}const Yct=e=>{let t=e.state.field(ec,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(ao).interactionDelay?!1:Jq(e,t.open.options[t.open.selected])},DM=e=>e.state.field(ec,!1)?(e.dispatch({effects:GN.of(!0)}),!0):!1,Jct=e=>{let t=e.state.field(ec,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:P6.of(null)}),!0)};class Xct{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const eut=50,tut=1e3,nut=ia.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(ec).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(ec),n=e.state.facet(ao);if(!e.selectionSet&&!e.docChanged&&e.startState.field(ec)==t)return;let r=e.transactions.some(a=>{let o=s4e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>eut&&Date.now()-o.time>tut){for(let l of o.context.abortListeners)try{l()}catch(c){rc(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(GN)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(ec);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=E2(t),r=new n4e(t,n,e.explicit,this.view),i=new Xct(e,r);this.running.push(i),Promise.resolve(e.source(r)).then(a=>{i.context.aborted||(i.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:P6.of(null)}),rc(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet(ao),r=this.view.state.field(ec);for(let i=0;i<this.running.length;i++){let a=this.running[i];if(a.done===void 0)continue;if(this.running.splice(i--,1),a.done){let l=E2(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new E3(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ku(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:Yq.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(ec,!1);if(t&&t.tooltip&&this.view.state.facet(ao).closeOnBlur){let n=t.open&&v5e(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:P6.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:GN.of(!1)}),20),this.composing=0}}}),rut=typeof navigator=="object"&&/Win/.test(navigator.platform),sut=lg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(ec,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(rut&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&Jq(t,r),!1}})),i4e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class iut{constructor(t,n,r,i){this.field=t,this.line=n,this.from=r,this.to=i}}class Xq{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,To.TrackDel),r=t.mapPos(this.to,1,To.TrackDel);return n==null||r==null?null:new Xq(this.field,n,r)}}class eK{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],i=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let f=0;f<d;f++)u+=t.facet(Q_);i.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new Xq(c.field,i[c.line]+c.from,i[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],i=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<n.length;f++)(l!=null?n[f].seq==l:d&&n[f].name==d)&&(u=f);if(u<0){let f=0;for(;f<n.length&&(l==null||n[f].seq!=null&&n[f].seq<l);)f++;n.splice(f,0,{seq:l,name:d}),u=f;for(let h of i)h.field>=u&&h.field++}for(let f of i)if(f.line==r.length&&f.from>a.index){let h=a[2]?3+(a[1]||"").length:2;f.from-=h,f.to-=h}i.push(new iut(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of i)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new eK(r,i)}}let aut=$n.widget({widget:new class extends am{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),out=$n.mark({class:"cm-snippetField"});class M4{constructor(t,n){this.ranges=t,this.active=n,this.deco=$n.set(t.map(r=>(r.from==r.to?aut:out).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let i=r.map(t);if(!i)return null;n.push(i)}return new M4(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Z7=ir.define({map(e,t){return e&&e.map(t)}}),lut=ir.define(),D6=qo.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Z7))return n.value;if(n.is(lut)&&e)return new M4(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:$n.none)});function tK(e,t){return bt.create(e.filter(n=>n.field==t).map(n=>bt.range(n.from,n.to)))}function cut(e){let t=eK.parse(e);return(n,r,i,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,i),{main:c}=n.state.selection,u={changes:{from:i,to:a==c.from?c.to:a,insert:ls.of(o)},scrollIntoView:!0,annotations:r?[Gq.of(r),ja.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=tK(l,0)),l.some(d=>d.field>0)){let d=new M4(l,0),f=u.effects=[Z7.of(d)];n.state.field(D6,!1)===void 0&&f.push(ir.appendConfig.of([D6,hut,put,i4e]))}n.dispatch(n.state.update(u))}}function a4e(e){return({state:t,dispatch:n})=>{let r=t.field(D6,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==i+e);return n(t.update({selection:tK(r.ranges,i),effects:Z7.of(a?null:new M4(r.ranges,i)),scrollIntoView:!0})),!0}}const uut=({state:e,dispatch:t})=>e.field(D6,!1)?(t(e.update({effects:Z7.of(null)})),!0):!1,dut=a4e(1),fut=a4e(-1),mut=[{key:"Tab",run:dut,shift:fut},{key:"Escape",run:uut}],dne=Jt.define({combine(e){return e.length?e[0]:mut}}),hut=lg.highest(H7.compute([dne],e=>e.facet(dne)));function gAt(e,t){return{...t,apply:cut(e)}}const put=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(D6,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(a=>a.from<=r&&a.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:tK(n.ranges,i.field),effects:Z7.of(n.ranges.some(a=>a.field>i.field)?new M4(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),L6={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},o2=ir.define({map(e,t){let n=t.mapPos(e,-1,To.TrackAfter);return n??void 0}}),nK=new class extends zp{};nK.startSide=1;nK.endSide=-1;const o4e=qo.define({create(){return Lr.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(o2)&&(e=e.update({add:[nK.range(n.value,n.value+1)]}));return e}});function gut(){return[but,o4e]}const LM="()[]{}<>«»»«[]{}";function l4e(e){for(let t=0;t<LM.length;t+=2)if(LM.charCodeAt(t)==e)return LM.charAt(t+1);return wq(e<128?e:e+1)}function c4e(e,t){return e.languageDataAt("closeBrackets",t)[0]||L6}const xut=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),but=Yt.inputHandler.of((e,t,n,r)=>{if((xut?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&wf(Xl(r,0))==1||t!=i.from||n!=i.to)return!1;let a=wut(e.state,r);return a?(e.dispatch(a),!0):!1}),yut=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=c4e(e,e.selection.main.head).brackets||L6.brackets,i=null,a=e.changeByRange(o=>{if(o.empty){let l=kut(e.doc,o.head);for(let c of r)if(c==l&&X_(e.doc,o.head)==l4e(Xl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:bt.cursor(o.head-c.length)}}return{range:i=o}});return i||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!i},vut=[{key:"Backspace",run:yut}];function wut(e,t){let n=c4e(e,e.selection.main.head),r=n.brackets||L6.brackets;for(let i of r){let a=l4e(Xl(i,0));if(t==i)return a==i?Cut(e,i,r.indexOf(i+i+i)>-1,n):jut(e,i,a,n.before||L6.before);if(t==a&&u4e(e,e.selection.main.from))return Nut(e,i,a)}return null}function u4e(e,t){let n=!1;return e.field(o4e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function X_(e,t){let n=e.sliceString(t,t+2);return n.slice(0,wf(Xl(n,0)))}function kut(e,t){let n=e.sliceString(t-2,t);return wf(Xl(n,0))==n.length?n:n.slice(1)}function jut(e,t,n,r){let i=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:o2.of(o.to+t.length),range:bt.range(o.anchor+t.length,o.head+t.length)};let l=X_(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:o2.of(o.head+t.length),range:bt.cursor(o.head+t.length)}:{range:i=o}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function Nut(e,t,n){let r=null,i=e.changeByRange(a=>a.empty&&X_(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:bt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function Cut(e,t,n,r){let i=r.stringPrefixes||L6.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:o2.of(l.to+t.length),range:bt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=X_(e.doc,c),d;if(u==t){if(fne(e,c))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(u4e(e,c)){let h=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+h.length,insert:h},range:bt.cursor(c+h.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=mne(e,c-2*t.length,i))>-1&&fne(e,d))return{changes:{insert:t+t+t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=yi.Word&&mne(e,c,i)>-1&&!Sut(e,c,t,i))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fne(e,t){let n=Bo(e).resolveInner(t+1);return n.parent&&n.from==t}function Sut(e,t,n,r){let i=Bo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=i.firstChild;for(;d&&d.from==i.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=i.to==t&&i.parent;if(!u)break;i=u}return!1}function mne(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=yi.Word)return t;for(let i of n){let a=t-i.length;if(e.sliceDoc(a,t)==i&&r(e.sliceDoc(a-1,a))!=yi.Word)return a}return-1}function _ut(e={}){return[sut,ec,ao.of(e),nut,Aut,i4e]}const d4e=[{key:"Ctrl-Space",run:DM},{mac:"Alt-`",run:DM},{mac:"Alt-i",run:DM},{key:"Escape",run:Jct},{key:"ArrowDown",run:T9(!0)},{key:"ArrowUp",run:T9(!1)},{key:"PageDown",run:T9(!0,"page")},{key:"PageUp",run:T9(!1,"page")},{key:"Enter",run:Yct}],Aut=lg.highest(H7.computeN([ao],e=>e.facet(ao).defaultKeymap?[d4e]:[])),Eut=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=sK(e.state,n.from);return r.line?Tut(e):r.block?Mut(e):!1};function rK(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const Tut=rK(Put,0),Iut=rK(f4e,0),Mut=rK((e,t)=>f4e(e,t,Out(t)),0);function sK(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const oy=50;function Rut(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-oy,r),o=e.sliceDoc(i,i+oy),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:i+c,margin:c&&1}};let d,f;i-r<=2*oy?d=f=e.sliceDoc(r,i):(d=e.sliceDoc(r,r+oy),f=e.sliceDoc(i-oy,i));let h=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(f)[0].length,b=f.length-g-n.length;return d.slice(h,h+t.length)==t&&f.slice(b,b+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(d.charAt(h+t.length))?1:0},close:{pos:i-g-n.length,margin:/\s/.test(f.charAt(b-1))?1:0}}:null}function Out(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function f4e(e,t,n=t.selection.ranges){let r=n.map(a=>sK(t,a.from).block);if(!r.every(a=>a))return null;let i=n.map((a,o)=>Rut(t,r[o],a.from,a.to));if(e!=2&&!i.every(a=>a))return{changes:t.changes(n.map((a,o)=>i[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&i.some(a=>a)){let a=[];for(let o=0,l;o<i.length;o++)if(l=i[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Put(e,t,n=t.selection.ranges){let r=[],i=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let f=t.doc.lineAt(d);if(u==null&&(u=sK(t,f.from).line,!u))continue e;if(f.from>i&&(a==o||o>f.from)){i=f.from;let h=/^\s*/.exec(f.text)[0].length,g=h==f.length,b=f.text.slice(h,h+u.length)==u?h:-1;h<f.text.length&&h<c&&(c=h),r.push({line:f,comment:b,token:u,indent:h,empty:g,single:!1})}d=f.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:f}of r)(f||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const qL=q1.define(),Dut=q1.define(),Lut=Jt.define(),m4e=Jt.define({combine(e){return im(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,i)=>t(r,i)||n(r,i)})}}),h4e=qo.define({create(){return If.empty},update(e,t){let n=t.state.facet(m4e),r=t.annotation(qL);if(r){let c=sc.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=YN(d,d.length,n.minDepth,c):d=x4e(d,t.startState.selection),new If(u==0?r.rest:d,u==0?d:r.rest)}let i=t.annotation(Dut);if((i=="full"||i=="before")&&(e=e.isolate()),t.annotation(ja.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=sc.fromTransaction(t),o=t.annotation(ja.time),l=t.annotation(ja.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(i=="full"||i=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new If(e.done.map(sc.fromJSON),e.undone.map(sc.fromJSON))}});function $ut(e={}){return[h4e,m4e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?p4e:t.inputType=="historyRedo"?KL:null;return r?(t.preventDefault(),r(n)):!1}})]}function eA(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(h4e,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const p4e=eA(0,!1),KL=eA(1,!1),Fut=eA(0,!0),zut=eA(1,!0);class sc{constructor(t,n,r,i,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=i,this.selectionsAfter=a}setSelAfter(t){return new sc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(t){return new sc(t.changes&&Oa.fromJSON(t.changes),[],t.mapped&&Ff.fromJSON(t.mapped),t.startSelection&&bt.fromJSON(t.startSelection),t.selectionsAfter.map(bt.fromJSON))}static fromTransaction(t,n){let r=ju;for(let i of t.startState.facet(Lut)){let a=i(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new sc(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,ju)}static selection(t){return new sc(void 0,ju,void 0,void 0,t)}}function YN(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function But(e,t){let n=[],r=!1;return e.iterChangedRanges((i,a)=>n.push(i,a)),t.iterChangedRanges((i,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Uut(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function g4e(e,t){return e.length?t.length?e.concat(t):e:t}const ju=[],qut=200;function x4e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-qut));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),YN(e,e.length-1,1e9,n.setSelAfter(r)))}else return[sc.selection([t])]}function Kut(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function $M(e,t){if(!e.length)return e;let n=e.length,r=ju;for(;n;){let i=Hut(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let a=e.slice(0,n);return a[n-1]=i,a}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[sc.selection(r)]:ju}function Hut(e,t,n){let r=g4e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):ju,n);if(!e.changes)return sc.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new sc(i,ir.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const Vut=/^(input\.type|delete)($|\.)/;class If{constructor(t,n,r=0,i=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=i}isolate(){return this.prevTime?new If(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||Vut.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,But(l.changes,t.changes))||r=="input.type.compose")?o=YN(o,o.length-1,i.minDepth,new sc(t.changes.compose(l.changes),g4e(ir.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,ju)):o=YN(o,o.length,i.minDepth,t),new If(o,ju,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:ju;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Uut(a[a.length-1],t)?this:new If(x4e(this.done,t),this.undone,n,r)}addMapping(t){return new If($M(this.done,t),$M(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let i=t==0?this.done:this.undone;if(i.length==0)return null;let a=i[i.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:qL.of({side:t,rest:Kut(i),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=i.length==1?ju:i.slice(0,i.length-1);return a.mapped&&(l=$M(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:qL.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}If.empty=new If(ju,ju);const Wut=[{key:"Mod-z",run:p4e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:KL,preventDefault:!0},{linux:"Ctrl-Shift-z",run:KL,preventDefault:!0},{key:"Mod-u",run:Fut,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:zut,preventDefault:!0}];function R4(e,t){return bt.create(e.ranges.map(t),e.mainIndex)}function Ud(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function qd({state:e,dispatch:t},n){let r=R4(e.selection,n);return r.eq(e.selection,!0)?!1:(t(Ud(e,r)),!0)}function tA(e,t){return bt.cursor(t?e.to:e.from)}function b4e(e,t){return qd(e,n=>n.empty?e.moveByChar(n,t):tA(n,t))}function dl(e){return e.textDirectionAt(e.state.selection.main.head)==Hs.LTR}const y4e=e=>b4e(e,!dl(e)),v4e=e=>b4e(e,dl(e));function w4e(e,t){return qd(e,n=>n.empty?e.moveByGroup(n,t):tA(n,t))}const Zut=e=>w4e(e,!dl(e)),Gut=e=>w4e(e,dl(e));function Qut(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function nA(e,t,n){let r=Bo(e).resolveInner(t.head),i=n?Or.closedBy:Or.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Qut(e,u,i)?r=u:c=n?u.to:u.from}let a=r.type.prop(i),o,l;return a&&(o=n?Tf(e,r.from,1):Tf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,bt.cursor(l,n?-1:1)}const Yut=e=>qd(e,t=>nA(e.state,t,!dl(e))),Jut=e=>qd(e,t=>nA(e.state,t,dl(e)));function k4e(e,t){return qd(e,n=>{if(!n.empty)return tA(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const j4e=e=>k4e(e,!1),N4e=e=>k4e(e,!0);function C4e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function S4e(e,t){let n=C4e(e),{state:r}=e,i=R4(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):tA(o,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(i.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(Ud(r,i),{effects:a}),!0}const hne=e=>S4e(e,!1),HL=e=>S4e(e,!0);function cg(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(i=bt.cursor(r.from+a))}return i}const Xut=e=>qd(e,t=>cg(e,t,!0)),edt=e=>qd(e,t=>cg(e,t,!1)),tdt=e=>qd(e,t=>cg(e,t,!dl(e))),ndt=e=>qd(e,t=>cg(e,t,dl(e))),rdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).from,1)),sdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).to,-1));function idt(e,t,n){let r=!1,i=R4(e.selection,a=>{let o=Tf(e,a.head,-1)||Tf(e,a.head,1)||a.head>0&&Tf(e,a.head-1,1)||a.head<e.doc.length&&Tf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return bt.cursor(l)});return r?(t(Ud(e,i)),!0):!1}const adt=({state:e,dispatch:t})=>idt(e,t);function Fu(e,t){let n=R4(e.state.selection,r=>{let i=t(r);return bt.range(r.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(Ud(e.state,n)),!0)}function _4e(e,t){return Fu(e,n=>e.moveByChar(n,t))}const A4e=e=>_4e(e,!dl(e)),E4e=e=>_4e(e,dl(e));function T4e(e,t){return Fu(e,n=>e.moveByGroup(n,t))}const odt=e=>T4e(e,!dl(e)),ldt=e=>T4e(e,dl(e)),cdt=e=>Fu(e,t=>nA(e.state,t,!dl(e))),udt=e=>Fu(e,t=>nA(e.state,t,dl(e)));function I4e(e,t){return Fu(e,n=>e.moveVertically(n,t))}const M4e=e=>I4e(e,!1),R4e=e=>I4e(e,!0);function O4e(e,t){return Fu(e,n=>e.moveVertically(n,t,C4e(e).height))}const pne=e=>O4e(e,!1),gne=e=>O4e(e,!0),ddt=e=>Fu(e,t=>cg(e,t,!0)),fdt=e=>Fu(e,t=>cg(e,t,!1)),mdt=e=>Fu(e,t=>cg(e,t,!dl(e))),hdt=e=>Fu(e,t=>cg(e,t,dl(e))),pdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).from)),gdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).to)),xne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:0})),!0),bne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.doc.length})),!0),yne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:0})),!0),vne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),xdt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),bdt=({state:e,dispatch:t})=>{let n=rA(e).map(({from:r,to:i})=>bt.range(r,Math.min(i+1,e.doc.length)));return t(e.update({selection:bt.create(n),userEvent:"select"})),!0},ydt=({state:e,dispatch:t})=>{let n=R4(e.selection,r=>{let i=Bo(e),a=i.resolveStack(r.from,1);if(r.empty){let o=i.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return bt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(Ud(e,n)),!0)};function P4e(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){i.some(u=>u.head==c.head)||i.push(c);break}else{if(c.head==l.head)break;l=c}}}return i.length==r.ranges.length?!1:(e.dispatch(Ud(n,bt.create(i,i.length-1))),!0)}const vdt=e=>P4e(e,!1),wdt=e=>P4e(e,!0),kdt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=bt.create([n.main]):n.main.empty||(r=bt.create([bt.cursor(n.main.head)])),r?(t(Ud(e,r)),!0):!1};function G7(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,i=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=I9(e,c,!1)):c>o&&(n="delete.forward",c=I9(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=I9(e,o,!1),l=I9(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:bt.cursor(o,o<a.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function I9(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(i=>i(e)))r.between(t,t,(i,a)=>{i<t&&a>t&&(t=n?a:i)});return t}const D4e=(e,t,n)=>G7(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),l,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,i-o.from))){if(l[l.length-1]==" ")return i-1;let u=I4(l,a.tabSize),d=u%h0(a)||h0(a);for(let f=0;f<d&&l[l.length-1-f]==" ";f++)i--;c=i}else c=lo(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=lo(o.text,c-o.from,!1,!1)+o.from);return c}),VL=e=>D4e(e,!1,!0),L4e=e=>D4e(e,!0,!1),$4e=(e,t)=>G7(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let c=lo(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),F4e=e=>$4e(e,!1),jdt=e=>$4e(e,!0),Ndt=e=>G7(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Cdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Sdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),_dt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ls.of(["",""])},range:bt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},Adt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let i=r.from,a=e.doc.lineAt(i),o=i==a.from?i-1:lo(a.text,i-a.from,!1)+a.from,l=i==a.to?i+1:lo(a.text,i-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(i,l).append(e.doc.slice(o,i))},range:bt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function rA(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function z4e(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let a of rA(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)i.push(bt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)i.push(bt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:bt.create(i,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Edt=({state:e,dispatch:t})=>z4e(e,t,!1),Tdt=({state:e,dispatch:t})=>z4e(e,t,!0);function B4e(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of rA(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Idt=({state:e,dispatch:t})=>B4e(e,t,!1),Mdt=({state:e,dispatch:t})=>B4e(e,t,!0),Rdt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(rA(t).map(({from:i,to:a})=>(i>0?i--:a<t.doc.length&&a++,{from:i,to:a}))),r=R4(t.selection,i=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(i.head),l=e.coordsAtPos(i.head,i.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(i,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Odt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Bo(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(Or.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const wne=U4e(!1),Pdt=U4e(!0);function U4e(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(i=>{let{from:a,to:o}=i,l=t.doc.lineAt(a),c=!e&&a==o&&Odt(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new Y_(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=Kq(u,a);for(d==null&&(d=I4(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let f=["",R6(t,d)];return c&&f.push(R6(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ls.of(f)},range:bt.cursor(a+1+f[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function iK(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,i,r),n=l.number),o=l.to+1}let a=e.changes(i);return{changes:i,range:bt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Ddt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Y_(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),i=iK(e,(a,o,l)=>{let c=Kq(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=R6(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return i.changes.empty||t(e.update(i,{userEvent:"indent"})),!0},q4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Q_)})}),{userEvent:"input.indent"})),!0),K4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{let i=/^\s*/.exec(n.text)[0];if(!i)return;let a=I4(i,e.tabSize),o=0,l=R6(e,Math.max(0,a-h0(e)));for(;o<i.length&&o<l.length&&i.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+i.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Ldt=e=>(e.setTabFocusMode(),!0),$dt=[{key:"Ctrl-b",run:y4e,shift:A4e,preventDefault:!0},{key:"Ctrl-f",run:v4e,shift:E4e},{key:"Ctrl-p",run:j4e,shift:M4e},{key:"Ctrl-n",run:N4e,shift:R4e},{key:"Ctrl-a",run:rdt,shift:pdt},{key:"Ctrl-e",run:sdt,shift:gdt},{key:"Ctrl-d",run:L4e},{key:"Ctrl-h",run:VL},{key:"Ctrl-k",run:Ndt},{key:"Ctrl-Alt-h",run:F4e},{key:"Ctrl-o",run:_dt},{key:"Ctrl-t",run:Adt},{key:"Ctrl-v",run:HL}],Fdt=[{key:"ArrowLeft",run:y4e,shift:A4e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Zut,shift:odt,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:tdt,shift:mdt,preventDefault:!0},{key:"ArrowRight",run:v4e,shift:E4e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Gut,shift:ldt,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ndt,shift:hdt,preventDefault:!0},{key:"ArrowUp",run:j4e,shift:M4e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xne,shift:yne},{mac:"Ctrl-ArrowUp",run:hne,shift:pne},{key:"ArrowDown",run:N4e,shift:R4e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:bne,shift:vne},{mac:"Ctrl-ArrowDown",run:HL,shift:gne},{key:"PageUp",run:hne,shift:pne},{key:"PageDown",run:HL,shift:gne},{key:"Home",run:edt,shift:fdt,preventDefault:!0},{key:"Mod-Home",run:xne,shift:yne},{key:"End",run:Xut,shift:ddt,preventDefault:!0},{key:"Mod-End",run:bne,shift:vne},{key:"Enter",run:wne,shift:wne},{key:"Mod-a",run:xdt},{key:"Backspace",run:VL,shift:VL,preventDefault:!0},{key:"Delete",run:L4e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:F4e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:jdt,preventDefault:!0},{mac:"Mod-Backspace",run:Cdt,preventDefault:!0},{mac:"Mod-Delete",run:Sdt,preventDefault:!0}].concat($dt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),zdt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Yut,shift:cdt},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Jut,shift:udt},{key:"Alt-ArrowUp",run:Edt},{key:"Shift-Alt-ArrowUp",run:Idt},{key:"Alt-ArrowDown",run:Tdt},{key:"Shift-Alt-ArrowDown",run:Mdt},{key:"Mod-Alt-ArrowUp",run:vdt},{key:"Mod-Alt-ArrowDown",run:wdt},{key:"Escape",run:kdt},{key:"Mod-Enter",run:Pdt},{key:"Alt-l",mac:"Ctrl-l",run:bdt},{key:"Mod-i",run:ydt,preventDefault:!0},{key:"Mod-[",run:K4e},{key:"Mod-]",run:q4e},{key:"Mod-Alt-\\",run:Ddt},{key:"Shift-Mod-k",run:Rdt},{key:"Shift-Mod-\\",run:adt},{key:"Mod-/",run:Eut},{key:"Alt-A",run:Iut},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Ldt}].concat(Fdt),Bdt={key:"Tab",run:q4e,shift:K4e};function Udt(e,t,n,r){const i=Wf(bi),a=Mc(C0e),o=se.useRef(null),{lexicalNode:l}=eL(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),f=se.useCallback(h=>{var g,b,v,j,k,w;if(h.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const C=N.doc.length,A=N.selection.ranges[0].to;C===A&&(c.current?(i==null||i.update(()=>{var _,E;const T=$f(e);T.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),T.selectNext()):T.insertAfter(Zs())}),c.current=!1):c.current=!0)}}else if(h.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(i==null||i.update(()=>{var A,_;const E=$f(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(h.key==="Enter")h.stopPropagation();else if(h.key==="Backspace"||h.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(i==null||i.update(()=>{$f(e).remove()}))}},[i,e]);return se.useEffect(()=>{const h=o.current;return setTimeout(()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.addEventListener("keydown",f)},300),()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",f)}},[o,d,f,n]),se.useEffect(()=>{r.subscribe(()=>{var h,g;(g=(h=o.current)==null?void 0:h.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function Ct(e){return new Ult(Vq.define(e))}function wh(e){return mt(()=>import("./index-CumScFRR.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const qdt=[ot.of({name:"C",extensions:["c","h","ino"],load(){return mt(()=>import("./index-BnmdXCVY.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return mt(()=>import("./index-BnmdXCVY.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return wh("Cassandra")}}),ot.of({name:"CSS",extensions:["css"],load(){return mt(()=>import("./index-CkIb_TPD.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),ot.of({name:"Go",extensions:["go"],load(){return mt(()=>import("./index-CA-0GwR6.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),ot.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return mt(()=>import("./index-CGAxHUbg.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),ot.of({name:"Java",extensions:["java"],load(){return mt(()=>import("./index-CliJxRSL.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),ot.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return mt(()=>import("./index-X1myEhaI.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),ot.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return mt(()=>import("./index-BPhU17F-.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),ot.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return mt(()=>import("./index-DtC5ZMkw.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),ot.of({name:"JSX",extensions:["jsx"],load(){return mt(()=>import("./index-X1myEhaI.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),ot.of({name:"LESS",extensions:["less"],load(){return mt(()=>import("./index-DGFP2wZj.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),ot.of({name:"Liquid",extensions:["liquid"],load(){return mt(()=>import("./index-eH8xDFNd.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),ot.of({name:"MariaDB SQL",load(){return wh("MariaSQL")}}),ot.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return mt(()=>import("./index-BwdvPKUU.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),ot.of({name:"MS SQL",load(){return wh("MSSQL")}}),ot.of({name:"MySQL",load(){return wh("MySQL")}}),ot.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return mt(()=>import("./index-DZhqrklZ.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),ot.of({name:"PLSQL",extensions:["pls"],load(){return wh("PLSQL")}}),ot.of({name:"PostgreSQL",load(){return wh("PostgreSQL")}}),ot.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return mt(()=>import("./index-DD81Lphy.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),ot.of({name:"Rust",extensions:["rs"],load(){return mt(()=>import("./index-5lcSAjys.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),ot.of({name:"Sass",extensions:["sass"],load(){return mt(()=>import("./index-Dp3z6CO7.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),ot.of({name:"SCSS",extensions:["scss"],load(){return mt(()=>import("./index-Dp3z6CO7.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),ot.of({name:"SQL",extensions:["sql"],load(){return wh("StandardSQL")}}),ot.of({name:"SQLite",load(){return wh("SQLite")}}),ot.of({name:"TSX",extensions:["tsx"],load(){return mt(()=>import("./index-X1myEhaI.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),ot.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return mt(()=>import("./index-X1myEhaI.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),ot.of({name:"WebAssembly",extensions:["wat","wast"],load(){return mt(()=>import("./index-NidjZwyA.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),ot.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return mt(()=>import("./index-CWst-Gyr.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),ot.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return mt(()=>import("./index-BqP6-nxC.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),ot.of({name:"APL",extensions:["dyalog","apl"],load(){return mt(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>Ct(e.apl))}}),ot.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return mt(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>Ct(e.asciiArmor))}}),ot.of({name:"ASN.1",extensions:["asn","asn1"],load(){return mt(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>Ct(e.asn1({})))}}),ot.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return mt(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>Ct(e.asterisk))}}),ot.of({name:"Brainfuck",extensions:["b","bf"],load(){return mt(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>Ct(e.brainfuck))}}),ot.of({name:"Cobol",extensions:["cob","cpy"],load(){return mt(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>Ct(e.cobol))}}),ot.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.csharp))}}),ot.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"ClojureScript",extensions:["cljs"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return mt(()=>import("./css-BnMrqG3P.js"),[]).then(e=>Ct(e.gss))}}),ot.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return mt(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>Ct(e.cmake))}}),ot.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return mt(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>Ct(e.coffeeScript))}}),ot.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return mt(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>Ct(e.commonLisp))}}),ot.of({name:"Cypher",extensions:["cyp","cypher"],load(){return mt(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>Ct(e.cypher))}}),ot.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return mt(()=>import("./python-BuPzkPfP.js"),[]).then(e=>Ct(e.cython))}}),ot.of({name:"Crystal",extensions:["cr"],load(){return mt(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>Ct(e.crystal))}}),ot.of({name:"D",extensions:["d"],load(){return mt(()=>import("./d-pRatUO7H.js"),[]).then(e=>Ct(e.d))}}),ot.of({name:"Dart",extensions:["dart"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.dart))}}),ot.of({name:"diff",extensions:["diff","patch"],load(){return mt(()=>import("./diff-DbItnlRl.js"),[]).then(e=>Ct(e.diff))}}),ot.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return mt(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>Ct(e.dockerFile))}}),ot.of({name:"DTD",extensions:["dtd"],load(){return mt(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>Ct(e.dtd))}}),ot.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return mt(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>Ct(e.dylan))}}),ot.of({name:"EBNF",load(){return mt(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>Ct(e.ebnf))}}),ot.of({name:"ECL",extensions:["ecl"],load(){return mt(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>Ct(e.ecl))}}),ot.of({name:"edn",extensions:["edn"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Eiffel",extensions:["e"],load(){return mt(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>Ct(e.eiffel))}}),ot.of({name:"Elm",extensions:["elm"],load(){return mt(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>Ct(e.elm))}}),ot.of({name:"Erlang",extensions:["erl"],load(){return mt(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>Ct(e.erlang))}}),ot.of({name:"Esper",load(){return mt(()=>import("./sql-D0XecflT.js"),[]).then(e=>Ct(e.esper))}}),ot.of({name:"Factor",extensions:["factor"],load(){return mt(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>Ct(e.factor))}}),ot.of({name:"FCL",load(){return mt(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>Ct(e.fcl))}}),ot.of({name:"Forth",extensions:["forth","fth","4th"],load(){return mt(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>Ct(e.forth))}}),ot.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return mt(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>Ct(e.fortran))}}),ot.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.fSharp))}}),ot.of({name:"Gas",extensions:["s"],load(){return mt(()=>import("./gas-Bneqetm1.js"),[]).then(e=>Ct(e.gas))}}),ot.of({name:"Gherkin",extensions:["feature"],load(){return mt(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>Ct(e.gherkin))}}),ot.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return mt(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>Ct(e.groovy))}}),ot.of({name:"Haskell",extensions:["hs"],load(){return mt(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>Ct(e.haskell))}}),ot.of({name:"Haxe",extensions:["hx"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.haxe))}}),ot.of({name:"HXML",extensions:["hxml"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.hxml))}}),ot.of({name:"HTTP",load(){return mt(()=>import("./http-DBlCnlav.js"),[]).then(e=>Ct(e.http))}}),ot.of({name:"IDL",extensions:["pro"],load(){return mt(()=>import("./idl-BEugSyMb.js"),[]).then(e=>Ct(e.idl))}}),ot.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return mt(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>Ct(e.jsonld))}}),ot.of({name:"Julia",extensions:["jl"],load(){return mt(()=>import("./julia-DuME0IfC.js"),[]).then(e=>Ct(e.julia))}}),ot.of({name:"Kotlin",extensions:["kt","kts"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.kotlin))}}),ot.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return mt(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>Ct(e.liveScript))}}),ot.of({name:"Lua",extensions:["lua"],load(){return mt(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>Ct(e.lua))}}),ot.of({name:"mIRC",extensions:["mrc"],load(){return mt(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>Ct(e.mirc))}}),ot.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return mt(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>Ct(e.mathematica))}}),ot.of({name:"Modelica",extensions:["mo"],load(){return mt(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>Ct(e.modelica))}}),ot.of({name:"MUMPS",extensions:["mps"],load(){return mt(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>Ct(e.mumps))}}),ot.of({name:"Mbox",extensions:["mbox"],load(){return mt(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>Ct(e.mbox))}}),ot.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return mt(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>Ct(e.nginx))}}),ot.of({name:"NSIS",extensions:["nsh","nsi"],load(){return mt(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>Ct(e.nsis))}}),ot.of({name:"NTriples",extensions:["nt","nq"],load(){return mt(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>Ct(e.ntriples))}}),ot.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveC))}}),ot.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveCpp))}}),ot.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.oCaml))}}),ot.of({name:"Octave",extensions:["m"],load(){return mt(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>Ct(e.octave))}}),ot.of({name:"Oz",extensions:["oz"],load(){return mt(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>Ct(e.oz))}}),ot.of({name:"Pascal",extensions:["p","pas"],load(){return mt(()=>import("./pascal--L3eBynH.js"),[]).then(e=>Ct(e.pascal))}}),ot.of({name:"Perl",extensions:["pl","pm"],load(){return mt(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>Ct(e.perl))}}),ot.of({name:"Pig",extensions:["pig"],load(){return mt(()=>import("./pig-CevX1Tat.js"),[]).then(e=>Ct(e.pig))}}),ot.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return mt(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>Ct(e.powerShell))}}),ot.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return mt(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>Ct(e.properties))}}),ot.of({name:"ProtoBuf",extensions:["proto"],load(){return mt(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>Ct(e.protobuf))}}),ot.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return mt(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>Ct(e.pug))}}),ot.of({name:"Puppet",extensions:["pp"],load(){return mt(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>Ct(e.puppet))}}),ot.of({name:"Q",extensions:["q"],load(){return mt(()=>import("./q-pXgVlZs6.js"),[]).then(e=>Ct(e.q))}}),ot.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return mt(()=>import("./r-B6wPVr8A.js"),[]).then(e=>Ct(e.r))}}),ot.of({name:"RPM Changes",load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmChanges))}}),ot.of({name:"RPM Spec",extensions:["spec"],load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmSpec))}}),ot.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return mt(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>Ct(e.ruby))}}),ot.of({name:"SAS",extensions:["sas"],load(){return mt(()=>import("./sas-B4kiWyti.js"),[]).then(e=>Ct(e.sas))}}),ot.of({name:"Scala",extensions:["scala"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.scala))}}),ot.of({name:"Scheme",extensions:["scm","ss"],load(){return mt(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>Ct(e.scheme))}}),ot.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return mt(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>Ct(e.shell))}}),ot.of({name:"Sieve",extensions:["siv","sieve"],load(){return mt(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>Ct(e.sieve))}}),ot.of({name:"Smalltalk",extensions:["st"],load(){return mt(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>Ct(e.smalltalk))}}),ot.of({name:"Solr",load(){return mt(()=>import("./solr-DehyRSwq.js"),[]).then(e=>Ct(e.solr))}}),ot.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.sml))}}),ot.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return mt(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>Ct(e.sparql))}}),ot.of({name:"Spreadsheet",alias:["excel","formula"],load(){return mt(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>Ct(e.spreadsheet))}}),ot.of({name:"Squirrel",extensions:["nut"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.squirrel))}}),ot.of({name:"Stylus",extensions:["styl"],load(){return mt(()=>import("./stylus-B533Al4x.js"),[]).then(e=>Ct(e.stylus))}}),ot.of({name:"Swift",extensions:["swift"],load(){return mt(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>Ct(e.swift))}}),ot.of({name:"sTeX",load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"Tcl",extensions:["tcl"],load(){return mt(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>Ct(e.tcl))}}),ot.of({name:"Textile",extensions:["textile"],load(){return mt(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>Ct(e.textile))}}),ot.of({name:"TiddlyWiki",load(){return mt(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>Ct(e.tiddlyWiki))}}),ot.of({name:"Tiki wiki",load(){return mt(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>Ct(e.tiki))}}),ot.of({name:"TOML",extensions:["toml"],load(){return mt(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>Ct(e.toml))}}),ot.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return mt(()=>import("./troff-wAsdV37c.js"),[]).then(e=>Ct(e.troff))}}),ot.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return mt(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>Ct(e.ttcn))}}),ot.of({name:"TTCN_CFG",extensions:["cfg"],load(){return mt(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>Ct(e.ttcnCfg))}}),ot.of({name:"Turtle",extensions:["ttl"],load(){return mt(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>Ct(e.turtle))}}),ot.of({name:"Web IDL",extensions:["webidl"],load(){return mt(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>Ct(e.webIDL))}}),ot.of({name:"VB.NET",extensions:["vb"],load(){return mt(()=>import("./vb-CmGdzxic.js"),[]).then(e=>Ct(e.vb))}}),ot.of({name:"VBScript",extensions:["vbs"],load(){return mt(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>Ct(e.vbScript))}}),ot.of({name:"Velocity",extensions:["vtl"],load(){return mt(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>Ct(e.velocity))}}),ot.of({name:"Verilog",extensions:["v"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return mt(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>Ct(e.vhdl))}}),ot.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return mt(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>Ct(e.xQuery))}}),ot.of({name:"Yacas",extensions:["ys"],load(){return mt(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>Ct(e.yacas))}}),ot.of({name:"Z80",extensions:["z80"],load(){return mt(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>Ct(e.z80))}}),ot.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.mscgen))}}),ot.of({name:"Xù",extensions:["xu"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.xu))}}),ot.of({name:"MsGenny",extensions:["msgenny"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.msgenny))}}),ot.of({name:"Vue",extensions:["vue"],load(){return mt(()=>import("./index-DhQquf6V.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),ot.of({name:"Angular Template",load(){return mt(()=>import("./index-CmVicMGL.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],kne="#2e3440",aK="#3b4252",jne="#434c5e",M9="#4c566a",Nne="#e5e9f0",WL="#eceff4",FM="#8fbcbb",Cne="#88c0d0",Kdt="#81a1c1",Gu="#5e81ac",Hdt="#bf616a",Rx="#d08770",zM="#ebcb8b",Sne="#a3be8c",Vdt="#b48ead",_ne="#d30102",oK=WL,BM=oK,Wdt="#ffffff",UM=aK,Zdt=oK,Ane=aK,Gdt=Yt.theme({"&":{color:kne,backgroundColor:Wdt},".cm-content":{caretColor:Ane},".cm-cursor, .cm-dropCursor":{borderLeftColor:Ane},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Zdt},".cm-panels":{backgroundColor:oK,color:M9},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${M9}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:Nne},".cm-activeLine":{backgroundColor:BM},".cm-selectionMatch":{backgroundColor:Nne},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${M9}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:WL},".cm-gutters":{backgroundColor:WL,color:kne,border:"none"},".cm-activeLineGutter":{backgroundColor:BM},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:UM},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:UM,borderBottomColor:UM},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:BM,color:M9}}},{dark:!1}),Qdt=W7.define([{tag:dt.keyword,color:Gu},{tag:[dt.name,dt.deleted,dt.character,dt.propertyName,dt.macroName],color:Rx},{tag:[dt.variableName],color:Rx},{tag:[dt.function(dt.variableName)],color:Gu},{tag:[dt.labelName],color:Kdt},{tag:[dt.color,dt.constant(dt.name),dt.standard(dt.name)],color:Gu},{tag:[dt.definition(dt.name),dt.separator],color:Sne},{tag:[dt.brace],color:FM},{tag:[dt.annotation],color:_ne},{tag:[dt.number,dt.changed,dt.annotation,dt.modifier,dt.self,dt.namespace],color:Cne},{tag:[dt.typeName,dt.className],color:zM},{tag:[dt.operator,dt.operatorKeyword],color:Sne},{tag:[dt.tagName],color:Vdt},{tag:[dt.squareBracket],color:Hdt},{tag:[dt.angleBracket],color:Rx},{tag:[dt.attributeName],color:zM},{tag:[dt.regexp],color:Gu},{tag:[dt.quote],color:aK},{tag:[dt.string],color:Rx},{tag:dt.link,color:FM,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[dt.url,dt.escape,dt.special(dt.string)],color:Rx},{tag:[dt.meta],color:Cne},{tag:[dt.comment],color:jne,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold",color:Gu},{tag:dt.emphasis,fontStyle:"italic",color:Gu},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.heading,fontWeight:"bold",color:Gu},{tag:dt.special(dt.heading1),fontWeight:"bold",color:Gu},{tag:dt.heading1,fontWeight:"bold",color:Gu},{tag:[dt.heading2,dt.heading3,dt.heading4],fontWeight:"bold",color:Gu},{tag:[dt.heading5,dt.heading6],color:Gu},{tag:[dt.atom,dt.bool,dt.special(dt.variableName)],color:Rx},{tag:[dt.processingInstruction,dt.inserted],color:FM},{tag:[dt.contentSeparator],color:zM},{tag:dt.invalid,color:jne,borderBottom:`1px dotted ${_ne}`}]),Ydt=[Gdt,V5e(Qdt)],Ene=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class M5{constructor(t,n,r=0,i=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,i),this.bufferStart=r,this.normalize=a?l=>a(Ene(l)):Ene,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Xl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=wq(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=wf(t);let i=this.normalize(n);if(i.length)for(let a=0,o=r;;a++){let l=i.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==i.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let i=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?i={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?i={from:n,to:r}:this.matches.push(1,n)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(M5.prototype[Symbol.iterator]=function(){return this});const H4e={from:-1,to:-1,match:/.*/.exec("")},lK="gm"+(/x/.unicode==null?"":"u");class V4e{constructor(t,n,r,i=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=H4e,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new W4e(t,n,r,i,a);this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(i);this.curLineStart=o.from,this.matchPos=JN(t,i),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,i=r+n[0].length;if(this.matchPos=JN(this.text,i+(r==i?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<i||r>this.value.to)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const qM=new WeakMap;class T3{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let i=qM.get(t);if(!i||i.from>=r||i.to<=n){let l=new T3(n,t.sliceString(n,r));return qM.set(t,l),l}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),qM.set(t,new T3(o,a)),new T3(n,a.slice(n-o,r-o))}}class W4e{constructor(t,n,r,i,a){this.text=t,this.to=a,this.done=!1,this.value=H4e,this.matchPos=JN(t,i),this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=T3.get(t,i,this.chunkEnd(i+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,i=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this.matchPos=JN(this.text,i+(r==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=T3.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(V4e.prototype[Symbol.iterator]=W4e.prototype[Symbol.iterator]=function(){return this});function Jdt(e){try{return new RegExp(e,lK),!0}catch{return!1}}function JN(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Xdt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=nlt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return i.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,f]=o,h=d?+d.slice(1):0,g=u?+u:l.number;if(u&&f){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=bt.cursor(b.from+Math.max(0,Math.min(h,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},eft={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},tft=Jt.define({combine(e){return im(e,eft,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function nft(e){return[oft,aft]}const rft=$n.mark({class:"cm-selectionMatch"}),sft=$n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Tne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=yi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=yi.Word)}function ift(e,t,n,r){return e(t.sliceDoc(n,n+1))==yi.Word&&e(t.sliceDoc(r-1,r))==yi.Word}const aft=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(tft),{state:n}=e,r=n.selection;if(r.ranges.length>1)return $n.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return $n.none;let c=n.wordAt(i.head);if(!c)return $n.none;o=n.charCategorizer(i.head),a=n.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<t.minSelectionLength||c>200)return $n.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Tne(o,n,i.from,i.to)&&ift(o,n,i.from,i.to)))return $n.none}else if(a=n.sliceDoc(i.from,i.to),!a)return $n.none}let l=[];for(let c of e.visibleRanges){let u=new M5(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:f}=u.value;if((!o||Tne(o,n,d,f))&&(i.empty&&d<=i.from&&f>=i.to?l.push(sft.range(d,f)):(d>=i.to||f<=i.from)&&l.push(rft.range(d,f)),l.length>t.maxMatches))return $n.none}}return $n.set(l)}},{decorations:e=>e.decorations}),oft=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),lft=({state:e,dispatch:t})=>{let{selection:n}=e,r=bt.create(n.ranges.map(i=>e.wordAt(i.head)||bt.cursor(i.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function cft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let o=!1,l=new M5(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new M5(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const uft=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return lft({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let i=cft(e,r);return i?(t(e.update({selection:e.selection.addRange(bt.range(i.from,i.to),!1),effects:Yt.scrollIntoView(i.to)})),!0):!1},O4=Jt.define({combine(e){return im(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Nft(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class Z4e{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Jdt(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
|
|
1298
1298
|
`:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new gft(this):new mft(this)}getCursor(t,n=0,r){let i=t.doc?t:Yr.create({doc:t});return r==null&&(r=i.doc.length),this.regexp?t3(this,i,n,r):e3(this,i,n,r)}}class G4e{constructor(t){this.spec=t}}function dft(e,t,n){return(r,i,a,o)=>{if(n&&!n(r,i,a,o))return!1;let l=r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i);return e(l,t,r,i)}}function e3(e,t,n,r){let i;return e.wholeWord&&(i=fft(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=dft(e.test,t,i)),new M5(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:a=>a.toLowerCase(),i)}function fft(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(XN(i,n-a))!=yi.Word||t(eC(i,n-a))!=yi.Word)&&(t(eC(i,r-a))!=yi.Word||t(XN(i,r-a))!=yi.Word))}class mft extends G4e{constructor(t){super(t)}nextMatch(t,n,r){let i=e3(this.spec,t,r,t.doc.length).nextOverlapping();if(i.done){let a=Math.min(t.doc.length,n+this.spec.unquoted.length);i=e3(this.spec,t,0,a).nextOverlapping()}return i.done||i.value.from==n&&i.value.to==r?null:i.value}prevMatchInRange(t,n,r){for(let i=r;;){let a=Math.max(n,i-1e4-this.spec.unquoted.length),o=e3(this.spec,t,a,i),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(a==n)return null;i-=1e4}}prevMatch(t,n,r){let i=this.prevMatchInRange(t,0,n);return i||(i=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),i&&(i.from!=n||i.to!=r)?i:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=e3(this.spec,t,0,t.doc.length),i=[];for(;!r.next().done;){if(i.length>=n)return null;i.push(r.value)}return i}highlight(t,n,r,i){let a=e3(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}function hft(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function t3(e,t,n,r){let i;return e.wholeWord&&(i=pft(t.charCategorizer(t.selection.main.head))),e.test&&(i=hft(e.test,t,i)),new V4e(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function XN(e,t){return e.slice(lo(e,t,!1),t)}function eC(e,t){return e.slice(t,lo(e,t))}function pft(e){return(t,n,r)=>!r[0].length||(e(XN(r.input,r.index))!=yi.Word||e(eC(r.input,r.index))!=yi.Word)&&(e(eC(r.input,r.index+r[0].length))!=yi.Word||e(XN(r.input,r.index+r[0].length))!=yi.Word)}class gft extends G4e{nextMatch(t,n,r){let i=t3(this.spec,t,r,t.doc.length).next();return i.done&&(i=t3(this.spec,t,0,n).next()),i.done?null:i.value}prevMatchInRange(t,n,r){for(let i=1;;i++){let a=Math.max(n,r-i*1e4),o=t3(this.spec,t,a,r),l=null;for(;!o.next().done;)l=o.value;if(l&&(a==n||l.from>a+10))return l;if(a==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let i=r.length;i>0;i--){let a=+r.slice(0,i);if(a>0&&a<t.match.length)return t.match[a]+r.slice(i)}return n})}matchAll(t,n){let r=t3(this.spec,t,0,t.doc.length),i=[];for(;!r.next().done;){if(i.length>=n)return null;i.push(r.value)}return i}highlight(t,n,r,i){let a=t3(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}const $6=ir.define(),cK=ir.define(),xp=qo.define({create(e){return new KM(ZL(e).create(),null)},update(e,t){for(let n of t.effects)n.is($6)?e=new KM(n.value.create(),e.panel):n.is(cK)&&(e=new KM(e.query,n.value?uK:null));return e},provide:e=>T6.from(e,t=>t.panel)});class KM{constructor(t,n){this.query=t,this.panel=n}}const xft=$n.mark({class:"cm-searchMatch"}),bft=$n.mark({class:"cm-searchMatch cm-searchMatch-selected"}),yft=ia.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(xp))}update(e){let t=e.state.field(xp);(t!=e.startState.field(xp)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return $n.none;let{view:n}=this,r=new S1;for(let i=0,a=n.visibleRanges,o=a.length;i<o;i++){let{from:l,to:c}=a[i];for(;i<o-1&&c>a[i+1].from-500;)c=a[++i].to;e.highlight(n.state,l,c,(u,d)=>{let f=n.state.selection.ranges.some(h=>h.from==u&&h.to==d);r.add(u,d,f?bft:xft)})}return r.finish()}},{decorations:e=>e.decorations});function Q7(e){return t=>{let n=t.state.field(xp,!1);return n&&n.query.spec.valid?e(t,n):J4e(t)}}const tC=Q7((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=bt.single(r.from,r.to),a=e.state.facet(O4);return e.dispatch({selection:i,effects:[dK(e,r),a.scrollToMatch(i.main,e)],userEvent:"select.search"}),Y4e(e),!0}),nC=Q7((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=bt.single(i.from,i.to),o=e.state.facet(O4);return e.dispatch({selection:a,effects:[dK(e,i),o.scrollToMatch(a.main,e)],userEvent:"select.search"}),Y4e(e),!0}),vft=Q7((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:bt.create(n.map(r=>bt.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),wft=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let l=new M5(e.doc,e.sliceDoc(r,i));!l.next().done;){if(a.length>1e3)return!1;l.value.from==r&&(o=a.length),a.push(bt.range(l.value.from,l.value.to))}return t(e.update({selection:bt.create(a,o),userEvent:"select.search.matches"})),!0},Ine=Q7((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,l=[],c,u,d=[];o.from==r&&o.to==i&&(u=n.toText(t.getReplacement(o)),l.push({from:o.from,to:o.to,insert:u}),o=t.nextMatch(n,o.from,o.to),d.push(Yt.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let f=e.state.changes(l);return o&&(c=bt.single(o.from,o.to).map(f),d.push(dK(e,o)),d.push(n.facet(O4).scrollToMatch(c.main,e))),e.dispatch({changes:f,selection:c,effects:d,userEvent:"input.replace"}),!0}),kft=Q7((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(i=>{let{from:a,to:o}=i;return{from:a,to:o,insert:t.getReplacement(i)}});if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:Yt.announce.of(r),userEvent:"input.replace.all"}),!0});function uK(e){return e.state.facet(O4).createPanel(e)}function ZL(e,t){var n,r,i,a,o;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let u=e.facet(O4);return new Z4e({search:((n=t==null?void 0:t.literal)!==null&&n!==void 0?n:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t==null?void 0:t.caseSensitive)!==null&&r!==void 0?r:u.caseSensitive,literal:(i=t==null?void 0:t.literal)!==null&&i!==void 0?i:u.literal,regexp:(a=t==null?void 0:t.regexp)!==null&&a!==void 0?a:u.regexp,wholeWord:(o=t==null?void 0:t.wholeWord)!==null&&o!==void 0?o:u.wholeWord})}function Q4e(e){let t=Fq(e,uK);return t&&t.dom.querySelector("[main-field]")}function Y4e(e){let t=Q4e(e);t&&t==e.root.activeElement&&t.select()}const J4e=e=>{let t=e.state.field(xp,!1);if(t&&t.panel){let n=Q4e(e);if(n&&n!=e.root.activeElement){let r=ZL(e.state,t.query.spec);r.valid&&e.dispatch({effects:$6.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[cK.of(!0),t?$6.of(ZL(e.state,t.query.spec)):ir.appendConfig.of(Sft)]});return!0},X4e=e=>{let t=e.state.field(xp,!1);if(!t||!t.panel)return!1;let n=Fq(e,uK);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:cK.of(!1)}),!0},jft=[{key:"Mod-f",run:J4e,scope:"editor search-panel"},{key:"F3",run:tC,shift:nC,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:tC,shift:nC,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:X4e,scope:"editor search-panel"},{key:"Mod-Shift-l",run:wft},{key:"Mod-Alt-g",run:Xdt},{key:"Mod-d",run:uft,preventDefault:!0}];class Nft{constructor(t){this.view=t;let n=this.query=t.state.field(xp).query.spec;this.commit=this.commit.bind(this),this.searchField=Ps("input",{value:n.search,placeholder:kc(t,"Find"),"aria-label":kc(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ps("input",{value:n.replace,placeholder:kc(t,"Replace"),"aria-label":kc(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ps("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Ps("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Ps("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(i,a,o){return Ps("button",{class:"cm-button",name:i,onclick:a,type:"button"},o)}this.dom=Ps("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,r("next",()=>tC(t),[kc(t,"next")]),r("prev",()=>nC(t),[kc(t,"previous")]),r("select",()=>vft(t),[kc(t,"all")]),Ps("label",null,[this.caseField,kc(t,"match case")]),Ps("label",null,[this.reField,kc(t,"regexp")]),Ps("label",null,[this.wordField,kc(t,"by word")]),...t.state.readOnly?[]:[Ps("br"),this.replaceField,r("replace",()=>Ine(t),[kc(t,"replace")]),r("replaceAll",()=>kft(t),[kc(t,"replace all")])],Ps("button",{name:"close",onclick:()=>X4e(t),"aria-label":kc(t,"close"),type:"button"},["×"])])}commit(){let t=new Z4e({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:$6.of(t)}))}keydown(t){hot(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?nC:tC)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Ine(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is($6)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(O4).top}}function kc(e,t){return e.state.phrase(t)}const R9=30,O9=/[\s\.,:;?!]/;function dK(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-R9),o=Math.min(i,n+R9),l=e.state.sliceDoc(a,o);if(a!=r.from){for(let c=0;c<R9;c++)if(!O9.test(l[c+1])&&O9.test(l[c])){l=l.slice(c);break}}if(o!=i){for(let c=l.length-1;c>l.length-R9;c--)if(!O9.test(l[c-1])&&O9.test(l[c])){l=l.slice(0,c);break}}return Yt.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${r.number}.`)}const Cft=Yt.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Sft=[xp,lg.low(yft),Cft];class Mne{constructor(t,n,r){this.from=t,this.to=n,this.diagnostic=r}}class Qg{constructor(t,n,r){this.diagnostics=t,this.panel=n,this.selected=r}static init(t,n,r){let i=r.facet(F6).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((g,b)=>g.from-b.from||g.to-b.to),o=new S1,l=[],c=0,u=r.doc.iter(),d=0,f=r.doc.length;for(let g=0;;){let b=g==a.length?null:a[g];if(!b&&!l.length)break;let v,j;if(l.length)v=c,j=l.reduce((N,C)=>Math.min(N,C.to),b&&b.from>v?b.from:1e8);else{if(v=b.from,v>f)break;j=b.to,l.push(b),g++}for(;g<a.length;){let N=a[g];if(N.from==v&&(N.to>N.from||N.to==v))l.push(N),g++,j=Math.min(N.to,j);else{j=Math.min(N.from,j);break}}j=Math.min(j,f);let k=!1;if(l.some(N=>N.from==v&&(N.to==j||j==f))&&(k=v==j,!k&&j-v<10)){let N=v-(d+u.value.length);N>0&&(u.next(N),d=v);for(let C=v;;){if(C>=j){k=!0;break}if(!u.lineBreak&&d+u.value.length>C)break;C=d+u.value.length,d+=u.value.length,u.next()}}let w=Fft(l);if(k)o.add(v,v,$n.widget({widget:new Pft(w),diagnostics:l.slice()}));else{let N=l.reduce((C,A)=>A.markClass?C+" "+A.markClass:C,"");o.add(v,j,$n.mark({class:"cm-lintRange cm-lintRange-"+w+N,diagnostics:l.slice(),inclusiveEnd:l.some(C=>C.to>j)}))}if(c=j,c==f)break;for(let N=0;N<l.length;N++)l[N].to<=c&&l.splice(N--,1)}let h=o.finish();return new Qg(h,n,Vp(h))}}function Vp(e,t=null,n=0){let r=null;return e.between(n,1e9,(i,a,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!r)r=new Mne(i,a,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new Mne(r.from,a,r.diagnostic)}}),r}function _ft(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(F6).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(o=>o.is(ebe))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Aft(e,t){return e.field(Oc,!1)?t:t.concat(ir.appendConfig.of(zft))}const ebe=ir.define(),fK=ir.define(),tbe=ir.define(),Oc=qo.define({create(){return new Qg($n.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let a=t.changes.mapPos(e.selected.from,1);r=Vp(n,e.selected.diagnostic,a)||Vp(n,null,a)}!n.size&&i&&t.state.facet(F6).autoPanel&&(i=null),e=new Qg(n,i,r)}for(let n of t.effects)if(n.is(ebe)){let r=t.state.facet(F6).autoPanel?n.value.length?z6.open:null:e.panel;e=Qg.init(n.value,r,t.state)}else n.is(fK)?e=new Qg(e.diagnostics,n.value?z6.open:null,e.selected):n.is(tbe)&&(e=new Qg(e.diagnostics,e.panel,n.value));return e},provide:e=>[T6.from(e,t=>t.panel),Yt.decorations.from(e,t=>t.diagnostics)]}),Eft=$n.mark({class:"cm-lintRange cm-lintRange-active"});function Tft(e,t,n){let{diagnostics:r}=e.state.field(Oc),i,a=-1,o=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(c,u,{spec:d})=>{if(t>=c&&t<=u&&(c==u||(t>c||n>0)&&(t<u||n<0)))return i=d.diagnostics,a=c,o=u,!1});let l=e.state.facet(F6).tooltipFilter;return i&&l&&(i=l(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Ift(e,i)}}}:null}function Ift(e,t){return Ps("ul",{class:"cm-tooltip-lint"},t.map(n=>rbe(e,n,!1)))}const Mft=e=>{let t=e.state.field(Oc,!1);(!t||!t.panel)&&e.dispatch({effects:Aft(e.state,[fK.of(!0)])});let n=Fq(e,z6.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},Rne=e=>{let t=e.state.field(Oc,!1);return!t||!t.panel?!1:(e.dispatch({effects:fK.of(!1)}),!0)},Rft=e=>{let t=e.state.field(Oc,!1);if(!t)return!1;let n=e.state.selection.main,r=Vp(t.diagnostics,null,n.to+1);return!r&&(r=Vp(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},Oft=[{key:"Mod-Shift-m",run:Mft,preventDefault:!0},{key:"F8",run:Rft}],F6=Jt.define({combine(e){return{sources:e.map(t=>t.source).filter(t=>t!=null),...im(e.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:One,tooltipFilter:One,needsRefresh:(t,n)=>t?n?r=>t(r)||n(r):t:n,hideOn:(t,n)=>t?n?(r,i,a)=>t(r,i,a)||n(r,i,a):t:n,autoPanel:(t,n)=>t||n})}}});function One(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function nbe(e){let t=[];if(e)e:for(let{name:n}of e){for(let r=0;r<n.length;r++){let i=n[r];if(/[a-zA-Z]/.test(i)&&!t.some(a=>a.toLowerCase()==i.toLowerCase())){t.push(i);continue e}}t.push("")}return t}function rbe(e,t,n){var r;let i=n?nbe(t.actions):[];return Ps("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Ps("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(r=t.actions)===null||r===void 0?void 0:r.map((a,o)=>{let l=!1,c=g=>{if(g.preventDefault(),l)return;l=!0;let b=Vp(e.state.field(Oc).diagnostics,t);b&&a.apply(e,b.from,b.to)},{name:u}=a,d=i[o]?u.indexOf(i[o]):-1,f=d<0?u:[u.slice(0,d),Ps("u",u.slice(d,d+1)),u.slice(d+1)],h=a.markClass?" "+a.markClass:"";return Ps("button",{type:"button",class:"cm-diagnosticAction"+h,onclick:c,onmousedown:c,"aria-label":` Action: ${u}${d<0?"":` (access key "${i[o]})"`}.`},f)}),t.source&&Ps("div",{class:"cm-diagnosticSource"},t.source))}class Pft extends am{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return Ps("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Pne{constructor(t,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=rbe(t,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class z6{constructor(t){this.view=t,this.items=[];let n=i=>{if(!(i.ctrlKey||i.altKey||i.metaKey)){if(i.keyCode==27)Rne(this.view),this.view.focus();else if(i.keyCode==38||i.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(i.keyCode==40||i.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(i.keyCode==36)this.moveSelection(0);else if(i.keyCode==35)this.moveSelection(this.items.length-1);else if(i.keyCode==13)this.view.focus();else if(i.keyCode>=65&&i.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:a}=this.items[this.selectedIndex],o=nbe(a.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==i.keyCode){let c=Vp(this.view.state.field(Oc).diagnostics,a);c&&a.actions[l].apply(t,c.from,c.to)}}else return;i.preventDefault()}},r=i=>{for(let a=0;a<this.items.length;a++)this.items[a].dom.contains(i.target)&&this.moveSelection(a)};this.list=Ps("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Ps("div",{class:"cm-panel-lint"},this.list,Ps("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Rne(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Oc).selected;if(!t)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==t.diagnostic)return n;return-1}update(){let{diagnostics:t,selected:n}=this.view.state.field(Oc),r=0,i=!1,a=null,o=new Set;for(t.between(0,this.view.state.doc.length,(l,c,{spec:u})=>{for(let d of u.diagnostics){if(o.has(d))continue;o.add(d);let f=-1,h;for(let g=r;g<this.items.length;g++)if(this.items[g].diagnostic==d){f=g;break}f<0?(h=new Pne(this.view,d),this.items.splice(r,0,h),i=!0):(h=this.items[f],f>r&&(this.items.splice(r,f-r),i=!0)),n&&h.diagnostic==n.diagnostic?h.dom.hasAttribute("aria-selected")||(h.dom.setAttribute("aria-selected","true"),a=h):h.dom.hasAttribute("aria-selected")&&h.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)i=!0,this.items.pop();this.items.length==0&&(this.items.push(new Pne(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),i=!0),a?(this.list.setAttribute("aria-activedescendant",a.id),this.view.requestMeasure({key:this,read:()=>({sel:a.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let u=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/u:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/u)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),i&&this.sync()}sync(){let t=this.list.firstChild;function n(){let r=t;t=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;t!=r.dom;)n();t=r.dom.nextSibling}else this.list.insertBefore(r.dom,t);for(;t;)n()}moveSelection(t){if(this.selectedIndex<0)return;let n=this.view.state.field(Oc),r=Vp(n.diagnostics,this.items[t].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:tbe.of(r)})}static open(t){return new z6(t)}}function Dft(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function P9(e){return Dft(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Lft=Yt.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:P9("#d11")},".cm-lintRange-warning":{backgroundImage:P9("orange")},".cm-lintRange-info":{backgroundImage:P9("#999")},".cm-lintRange-hint":{backgroundImage:P9("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function $ft(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function Fft(e){let t="hint",n=1;for(let r of e){let i=$ft(r.severity);i>n&&(n=i,t=r.severity)}return t}const zft=[Oc,Yt.decorations.compute([Oc],e=>{let{selected:t,panel:n}=e.field(Oc);return!t||!n||t.from==t.to?$n.none:$n.set([Eft.range(t.from,t.to)])}),elt(Tft,{hideOn:_ft}),Lft],Bft=[S5e(),plt(),Iot(),$ut(),dct(),vot(),Cot(),Yr.allowMultipleSelections.of(!0),Ylt(),V5e(pct,{fallback:!0}),kct(),gut(),_ut(),qot(),Vot(),Lot(),nft(),H7.of([...vut,...zdt,...jft,...Wut,...oct,...d4e,...Oft])],Uft=se.forwardRef(({title:e,children:t},n)=>{const r=Wf(O0);return se.createElement(cz,{delayDuration:100},se.createElement(uz,null,se.createElement(dz,{ref:n,asChild:!0},se.createElement("span",{className:Rt.tooltipTrigger},t)),se.createElement(fz,{container:r==null?void 0:r.current},se.createElement(mz,{className:Ds(Rt.tooltipContent),sideOffset:10},e))))}),qft=se.forwardRef(({children:e,className:t,...n},r)=>se.createElement(vde,{...n,ref:r,className:Ds(t,Rt.selectItem)},se.createElement(wde,null,e))),Kft=({title:e,placeholder:t,className:n})=>{const[r,i]=Ld(Id,F1);return se.createElement(Uft,{title:e},se.createElement(hde,{"aria-label":t,className:Ds(Rt.selectTrigger,n),"data-toolbar-item":!0,disabled:r},se.createElement(pde,{placeholder:t}),se.createElement(gde,{className:Rt.selectDropdownArrow},i("arrow_drop_down"))))},Hft=({children:e,className:t=Rt.selectContainer})=>{const n=Wf(O0);return se.createElement(xde,{container:n==null?void 0:n.current},se.createElement(bde,{className:Ds(t,"mdxeditor-select-content"),onCloseAutoFocus:r=>{r.preventDefault()},position:"popper"},se.createElement(yde,{"data-editor-dropdown":!0,style:{maxHeight:"var(--radix-select-content-available-height)"}},e)))},Vft=e=>se.createElement(mde,{value:e.value||"",onValueChange:e.onChange,disabled:e.disabled},se.createElement(Kft,{title:e.triggerTitle,placeholder:e.placeholder}),se.createElement(Hft,null,e.items.map((t,n)=>t==="separator"?se.createElement(QEe,{key:n}):se.createElement(qft,{key:n,value:t.value},t.label)))),sbe=({language:e,nodeKey:t,code:n,focusEmitter:r})=>{const i=z1(),{parentEditor:a,lexicalNode:o}=eL(),[l,c,u,d,f]=Ld(Id,JL,XL,F1,YL),h=Udt(t,"codeblock",e,r),{setCode:g}=eL(),b=se.useRef(null),v=se.useRef(null),j=se.useRef(g);return j.current=g,h.current={getCodemirror:()=>b.current},se.useEffect(()=>{const k=v.current;return(async()=>{const w=[...c,Bft,Ydt,S5e(),H7.of([Bdt]),Yt.lineWrapping,Yt.updateListener.of(({state:N})=>{j.current(N.doc.toString())}),Yt.domEventHandlers({focus:()=>{a.update(()=>{$u(null)})}})];if(l&&w.push(Yr.readOnly.of(!0)),e!==""&&u){const N=qdt.find(C=>C.name===e||C.alias.includes(e)||C.extensions.includes(e));if(N)try{const C=await N.load();w.push(C.extension)}catch{console.warn("failed to load language support for",e)}}k.innerHTML="",b.current=new Yt({parent:k,state:Yr.create({doc:n,extensions:w})}),k.addEventListener("keydown",Dne)})(),()=>{var w;(w=b.current)==null||w.destroy(),b.current=null,k.removeEventListener("keydown",Dne)}},[l,e,...c]),se.createElement("div",{className:Rt.codeMirrorWrapper},se.createElement("div",{className:Rt.codeMirrorToolbar},se.createElement(Vft,{disabled:l,value:f.keyMap[e]??e,onChange:k=>{a.update(()=>{o.setLanguage(k===GL?"":k),setTimeout(()=>{a.update(()=>{o.getLatest().select()})})})},triggerTitle:i("codeBlock.selectLanguage","Select code block language"),placeholder:i("codeBlock.inlineLanguage","Language"),items:f.items}),se.createElement("button",{className:Rt.iconButton,type:"button",disabled:l,title:i("codeblock.delete","Delete code block"),onClick:k=>{k.preventDefault(),a.update(()=>{o.remove()})}},d("delete_small"))),se.createElement("div",{ref:v}))};function Dne(e){e.stopPropagation()}const GL="__EMPTY_VALUE__";function QL(e){var t;const n=[],r={};if(Array.isArray(e))for(const i of e){const a=((t=i.alias)==null?void 0:t[0])??i.name.toLowerCase();if(n.push({value:a,label:i.name}),r[a]=a,i.alias)for(const o of i.alias)r[o]=a;if(i.extensions)for(const o of i.extensions)r[o]=a;r[i.name.toLowerCase()]=a}else{const i={};for(const[a,o]of Object.entries(e))o in i||(i[o]=a,n.push({value:a||GL,label:o})),r[a]=i[o]||GL}return{items:n,keyMap:r}}const YL=en(QL({js:"JavaScript",ts:"TypeScript",tsx:"TypeScript (React)",jsx:"JavaScript (React)",css:"CSS"})),Wft=oa(e=>{e.link(e.pipe(Wft,Mp(({language:t,code:n})=>({code:n,language:t,meta:""}))),e3e)}),JL=en([]),XL=en(!0),Zft=Uo({update(e,t){e.pubIn({[YL]:QL((t==null?void 0:t.codeBlockLanguages)??{}),[JL]:(t==null?void 0:t.codeMirrorExtensions)??[],[XL]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})},init(e,t){const n=QL((t==null?void 0:t.codeBlockLanguages)??{});e.pubIn({[YL]:n,[JL]:(t==null?void 0:t.codeMirrorExtensions)??[],[sit]:Gft(n),[XL]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})}});function Gft(e){return{match(t,n){return Object.hasOwn(e.keyMap,t??"")&&!n},priority:1,Editor:sbe}}function Qft({url:e,title:t,text:n,onSubmit:r,onCancel:i,linkAutocompleteSuggestions:a,showLinkTitleField:o,showAnchorTextField:l}){const{register:c,handleSubmit:u,control:d,setValue:f,reset:h}=Exe({values:{url:e,title:t,text:n}}),g=z1();return se.createElement("form",{onSubmit:b=>{u(r)(b),b.stopPropagation(),b.preventDefault()},onReset:b=>{b.stopPropagation(),i()},onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),i())},className:Ds(Rt.multiFieldForm,Rt.linkDialogEditForm)},se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-url"},g("createLink.url","URL")),se.createElement(Wxe,{register:c,initialInputValue:e,inputName:"url",suggestions:a,setValue:f,control:d,placeholder:g("createLink.urlPlaceholder","Select or paste an URL"),autofocus:!0})),l?se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-text",title:g("createLink.textTooltip","The text to be displayed for the link")},g("createLink.text","Anchor text")),se.createElement("input",{id:"link-text",className:Rt.textInput,size:40,...c("text")})):null,o?se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-title",title:g("createLink.titleTooltip","The link's title attribute, shown on hover")},g("createLink.title","Link title")),se.createElement("input",{id:"link-title",className:Rt.textInput,size:40,...c("title")})):null,se.createElement("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--spacing-2)"}},se.createElement("button",{type:"submit",title:g("createLink.saveTooltip","Set URL"),"aria-label":g("createLink.saveTooltip","Set URL"),className:Ds(Rt.primaryButton)},g("dialogControls.save","Save")),se.createElement("button",{type:"reset",title:g("createLink.cancelTooltip","Cancel change"),"aria-label":g("createLink.cancelTooltip","Cancel change"),className:Ds(Rt.secondaryButton)},g("dialogControls.cancel","Cancel"))))}const Yft=()=>{const[e,t,n,r,i,a,o]=Ld(O0,bi,F1,Zl,dbe,fbe,hbe),l=Mc(ibe),c=Mc(abe),u=Mc(obe),d=Mc(lbe),f=Mc(cbe);se.useEffect(()=>{const k=()=>{t==null||t.getEditorState().read(()=>{l(!0)})};return window.addEventListener("resize",k),window.addEventListener("scroll",k),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k)}},[t,l]);const[h,g]=se.useState(!1),b=z1();if(r.type==="inactive")return null;const v=r.rectangle,j=r.type==="preview"&&r.url.startsWith("http");return se.createElement(OS,{open:!0},se.createElement(Cue,{"data-visible":r.type==="edit",className:Rt.linkDialogAnchor,style:{top:`${v.top}px`,left:`${v.left}px`,width:`${v.width}px`,height:`${v.height}px`}}),se.createElement(PS,{container:e==null?void 0:e.current},se.createElement(Sue,{className:Ds(Rt.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:k=>{k.preventDefault()},key:r.linkNodeKey},r.type==="edit"&&se.createElement(Qft,{url:r.url,title:r.title,text:r.text,onSubmit:c,onCancel:u.bind(null),linkAutocompleteSuggestions:i,showLinkTitleField:o,showAnchorTextField:r.withAnchorText}),r.type==="preview"&&se.createElement(se.Fragment,null,se.createElement("a",{className:Rt.linkDialogPreviewAnchor,href:r.url,...j?{target:"_blank",rel:"noreferrer"}:{},onClick:k=>{a!==null&&(k.preventDefault(),a(r.url))},title:j?b("linkPreview.open","Open {{url}} in new window",{url:r.url}):r.url},se.createElement("span",null,r.url),j&&n("open_in_new")),se.createElement(HM,{onClick:()=>{d()},title:b("linkPreview.edit","Edit link URL"),"aria-label":b("linkPreview.edit","Edit link URL")},n("edit")),se.createElement(cz,null,se.createElement(uz,{open:h},se.createElement(dz,{asChild:!0},se.createElement(HM,{title:b("linkPreview.copyToClipboard","Copy to clipboard"),"aria-label":b("linkPreview.copyToClipboard","Copy to clipboard"),onClick:()=>{window.navigator.clipboard.writeText(r.url).then(()=>{g(!0),setTimeout(()=>{g(!1)},1e3)})}},n(h?"check":"content_copy"))),se.createElement(fz,{container:e==null?void 0:e.current},se.createElement(mz,{className:Ds(Rt.tooltipContent),sideOffset:5},b("linkPreview.copied","Copied!"),se.createElement(ofe,null))))),se.createElement(HM,{title:b("linkPreview.remove","Remove link"),"aria-label":b("linkPreview.remove","Remove link"),onClick:()=>{f()}},n("link_off"))),se.createElement(YF,{className:Rt.popoverArrow}))))},HM=se.forwardRef(({className:e,...t},n)=>se.createElement("button",{className:Ds(Rt.actionButton,e),ref:n,...t}));function e$(e){if(!e)return null;const t=Itt(e);if(t===null)return null;const n=t.getParent();return kl(n)?n:kl(t)?t:null}const ibe=oa(),Zl=en({type:"inactive"},e=>{e.pub(b6,t=>t.registerCommand(A_,()=>e.getValue(Zl).type==="preview"?(e.pub(Zl,{type:"inactive"}),!0):!1,ri)),e.sub(e.pipe(y6),t=>{t!=="rich-text"&&e.pub(Zl,{type:"inactive"})}),e.pub(b6,t=>t.registerCommand(Bge,n=>{if(n.key==="k"&&(J0e?n.metaKey:n.ctrlKey)&&!e.getValue(Id)){const r=an();return hn(r)?(e.pub(ube),n.stopPropagation(),n.preventDefault(),!0):!1}return!1},m6)),e.sub(e.pipe(lbe,Pi(Zl,bi)),([,t,n])=>{if(t.type==="preview")setTimeout(()=>{n==null||n.getEditorState().read(()=>{const r=$f(t.linkNodeKey),i=kl(r)?r.getTextContent().length>0&&r.getChildrenSize()<=1:!1,a=i&&r?r.getTextContent():"";e.pub(Zl,{type:"edit",initialUrl:t.url,url:t.url,title:t.title,text:a,withAnchorText:i,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle})})});else throw new Error("Cannot switch to edit mode when not in preview mode")}),e.sub(e.pipe(abe,Pi(bi,Zl,k5)),([t,n,r,i])=>{var a,o,l;const c=((a=t.text)==null?void 0:a.trim())??"",u=((o=t.url)==null?void 0:o.trim())??"",d=((l=t.title)==null?void 0:l.trim())??"";if(u!==""){if(i!=null&&i.isCollapsed()){const f=c||d||u;n==null||n.update(()=>{const h=e$(i);if(h)if(sd(h)){const g=C1(u,{title:d});g.append(Ru(c)),h.replace(g),g.select()}else h.setURL(u),h.setTitle(d),Lne(h.getFirstChild(),c);else{const g=C1(u,{title:d});g.append(Ru(f)),j4([g]),g.select()}},{discrete:!0})}else n==null||n.update(()=>{Lne(i==null?void 0:i.anchor.getNode(),c)}),n==null||n.dispatchCommand(j5,{url:u,title:d});e.pub(Zl,{type:"preview",linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:d,url:u})}else r.type==="edit"&&r.initialUrl!==""&&(n==null||n.dispatchCommand(j5,null)),e.pub(Zl,{type:"inactive"})}),e.link(e.pipe(obe,Pi(Zl,bi),Mp(([,t,n])=>{if(t.type==="edit")return n==null||n.focus(),t.initialUrl===""?{type:"inactive"}:{type:"preview",url:t.initialUrl,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle};throw new Error("Cannot cancel edit when not in edit mode")})),Zl),e.link(e.pipe(e.combine(k5,ibe),Pi(bi,Zl,Id),Mp(([[t],n,r,i])=>{if(hn(t)&&n&&!i){const a=e$(t);if(!t.isCollapsed())return{type:"inactive"};if(a){const o=G0e(n);return o?{type:"preview",url:a.getURL(),linkNodeKey:a.getKey(),title:a.getTitle(),rectangle:o}:{type:"inactive"}}else return{type:"inactive"}}else return{type:"inactive"}})),Zl)}),abe=oa(),obe=rg();rg();const lbe=rg(),cbe=rg(e=>{e.sub(e.pipe(cbe,Pi(bi)),([,t])=>{t==null||t.dispatchCommand(j5,null)})}),ube=rg(e=>{e.sub(e.pipe(ube,Pi(k5,bi),S7(([,t])=>hn(t))),([,t,n])=>{n==null||n.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{const r=e$(t),i=G0e(n),a=(r==null?void 0:r.getURL())??"",o=(r==null?void 0:r.getURL())??"",l=(r==null?void 0:r.getTitle())??"",c=(r==null?void 0:r.getKey())??"",u=r?r.getTextContent().length>0&&r.getChildrenSize()<=1:!!(t!=null&&t.isCollapsed()),d=u&&r?r.getTextContent():"";e.pub(Zl,{type:"edit",initialUrl:a,url:o,title:l,text:d,withAnchorText:u,linkNodeKey:c,rectangle:i})})})})})}),dbe=en([]),fbe=en(null),mbe=en(null,e=>{e.pub(b6,t=>{function n(r){const[i,a]=e.getValues([Id,mbe]);!i||a===null||t.update(()=>{const o=l0(r.target);if(o!==null){const l=gd(o,c=>c instanceof Bd);l!==null&&a(r,l,l.getURL())}})}return t.registerRootListener((r,i)=>{r&&r.addEventListener("click",n),i&&i.removeEventListener("click",n)})})});function Lne(e,t){cs(e)&&t&&(e.setTextContent(t),e.selectStart())}const hbe=en(!0),Jft=Uo({init(e,t){e.pub(P0,(t==null?void 0:t.LinkDialog)??Yft),e.pub(fbe,(t==null?void 0:t.onClickLinkCallback)??null),e.pub(mbe,(t==null?void 0:t.onReadOnlyClickLinkCallback)??null),e.pub(hbe,(t==null?void 0:t.showLinkTitleField)??!0)},update(e,t={}){e.pub(dbe,t.linkAutocompleteSuggestions??[])}});var VM={exports:{}},$ne;function Xft(){return $ne||($ne=1,(function(e){var t=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/**
|
|
1299
1299
|
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
1300
1300
|
*
|
|
@@ -1347,7 +1347,7 @@ ${c}`.trim();return[o,{kind:"tool_result",ts:t,toolUseId:_o(n.callID)||_o(n.id,r
|
|
|
1347
1347
|
- hire a founding engineer
|
|
1348
1348
|
- write a hiring plan`,mR="Getting Started",Dg="rudder.onboardingDraftOrganizationId";function dxt(e,t){return!e||e.length===0?[t]:e.findIndex(r=>r.id===t.id)<0?[...e,t]:e.map(r=>r.id===t.id?t:r)}const gC={list:e=>_e.get(`/orgs/${e}/secrets`),providers:e=>_e.get(`/orgs/${e}/secret-providers`),create:(e,t)=>_e.post(`/orgs/${e}/secrets`,t),rotate:(e,t)=>_e.post(`/secrets/${e}/rotate`,t),update:(e,t)=>_e.patch(`/secrets/${e}`,t),remove:e=>_e.delete(`/secrets/${e}`)};function LK({agents:e,value:t,onChange:n,disabled:r=!1,excludeAgentIds:i=[],disabledEmptyLabel:a="Reports to: N/A (CEO)",chooseLabel:o="Reports to..."}){const[l,c]=x.useState(!1),u=new Set(i),d=e.filter(b=>b.status!=="terminated"&&!u.has(b.id)),f=t?e.find(b=>b.id===t):null,h=(f==null?void 0:f.status)==="terminated",g=!!(t&&!f);return s.jsxs(qn,{open:l,onOpenChange:c,children:[s.jsx(Wn,{asChild:!0,children:s.jsx("button",{type:"button",className:G("inline-flex max-w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",h&&"border-amber-600/45 bg-amber-500/5",r&&"opacity-60 cursor-not-allowed"),disabled:r,children:g?s.jsxs(s.Fragment,{children:[s.jsx(Hf,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:"Unknown manager (stale ID)"})]}):f?s.jsxs(s.Fragment,{children:[s.jsx(ki,{icon:f.icon,role:f.role,className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:G("min-w-0 truncate",h&&"text-amber-900 dark:text-amber-200"),children:`Reports to ${f.name}${h?" (terminated)":""}`})]}):s.jsxs(s.Fragment,{children:[s.jsx(Hf,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate",children:r?a:o})]})})}),s.jsxs(Kn,{className:"w-48 p-1",align:"start",children:[s.jsx("button",{type:"button",className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",t===null&&"bg-accent"),onClick:()=>{n(null),c(!1)},children:"No manager"}),h&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:[s.jsx(ki,{icon:f.icon,role:f.role,className:"shrink-0 h-3 w-3"}),s.jsxs("span",{className:"min-w-0 truncate",children:["Current: ",f.name," (terminated)"]})]}),g&&s.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:"Saved manager is missing from this organization. Choose a new manager or clear."}),d.map(b=>s.jsxs("button",{type:"button",className:G("flex items-center gap-2 w-full min-w-0 px-2 py-1.5 text-xs rounded hover:bg-accent/50 overflow-hidden",b.id===t&&"bg-accent"),onClick:()=>{n(b.id),c(!1)},children:[s.jsx(ki,{icon:b.icon,role:b.role,className:"shrink-0 h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate",children:b.name}),s.jsx("span",{className:"text-muted-foreground ml-auto shrink-0",children:pC[b.role]??b.role})]},b.id))]})]})}const hR={identity:{},agentRuntimeConfig:{},heartbeat:{},runtime:{}},Bre={};function fxt(e){return Object.keys(e.identity).length>0||e.agentRuntimeType!==void 0||Object.keys(e.agentRuntimeConfig).length>0||Object.keys(e.heartbeat).length>0||Object.keys(e.runtime).length>0}const Rc="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";function mxt(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function hxt(e){return Array.isArray(e)?e.filter(t=>typeof t=="string").join(", "):typeof e=="string"?e:""}const pxt=[...rye("Auto",nye).map(e=>({id:e.value,label:e.label}))],gxt=[{id:"",label:"Auto"},{id:"minimal",label:"Minimal"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"max",label:"Max"}],xxt=[{id:"",label:"Auto"},{id:"plan",label:"Plan"},{id:"ask",label:"Ask"}],bxt=[{id:"",label:"Auto"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"}],yxt=["claude_local","codex_local","gemini_local","opencode_local","pi_local","cursor"];function s8(e){var t,n;return e==="claude_local"?((t=UP.find(r=>r.id.includes("sonnet")))==null?void 0:t.id)??((n=UP[0])==null?void 0:n.id)??"":e==="codex_local"?J2:e==="gemini_local"?p5:e==="cursor"?r6:e==="opencode_local"?"anthropic/claude-sonnet-4-5":e==="pi_local"?"xai/grok-4":""}function vve(e){return e==="codex_local"?"codex":e==="gemini_local"?"gemini":e==="pi_local"?"pi":e==="cursor"?"agent":e==="opencode_local"?"opencode":"claude"}function wve(e){const t={...yp,agentRuntimeType:e,model:s8(e),modelFallbacks:[],command:vve(e)};return e==="codex_local"&&(t.search=l_,t.dangerouslyBypassSandbox=o_),t}function D5(e){return T1(e).buildAdapterConfig(wve(e))}function vxt(e){return e==="claude_local"?"codex_local":"claude_local"}function kve(e){const t=vxt(e),n=D5(t),r=typeof n.model=="string"?n.model:s8(t);return{agentRuntimeType:t,model:r,config:n}}function wxt(e){return e==="codex_local"?"modelReasoningEffort":e==="cursor"?"mode":e==="opencode_local"?"variant":e==="pi_local"?"thinking":"effort"}function kxt(e){return e==="codex_local"?pxt:e==="cursor"?xxt:e==="opencode_local"||e==="pi_local"?gxt:bxt}function jxt(e){return e!=="gemini_local"}function Nxt(e){return Object.values(e).some(t=>t===void 0)}function Ure(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function P3(e,t){return{agentRuntimeType:e,model:t}}function D3(e,t){return F0(e,{agentRuntimeType:t.agentRuntimeType,model:""})}const jve="flex gap-3 overflow-x-auto overscroll-x-contain pb-2 pr-2 [-webkit-overflow-scrolling:touch]",L3="basis-[60%] min-w-[420px] shrink-0 grow-0";function qre(e){const t=gA[e.runtimeType]??e.runtimeType;return e.model?`${e.title} · ${t} · ${e.model}`:`${e.title} · ${t}`}function $K(e){return e==="warn"?"pass":e}function Nve(e){return e.checks.filter(t=>t.level==="error")}function Cxt({value:e,secrets:t,onCreateSecret:n,onChange:r}){const{promptText:i}=Wr();function a(j){return!j||typeof j!="object"?[{key:"",source:"plain",plainValue:"",secretId:""}]:[...Object.entries(j).map(([w,N])=>{if(typeof N=="string")return{key:w,source:"plain",plainValue:N,secretId:""};if(typeof N=="object"&&N!==null&&"type"in N&&N.type==="secret_ref"){const C=N;return{key:w,source:"secret",plainValue:"",secretId:typeof C.secretId=="string"?C.secretId:""}}if(typeof N=="object"&&N!==null&&"type"in N&&N.type==="plain"){const C=N;return{key:w,source:"plain",plainValue:typeof C.value=="string"?C.value:"",secretId:""}}return{key:w,source:"plain",plainValue:"",secretId:""}}),{key:"",source:"plain",plainValue:"",secretId:""}]}const[o,l]=x.useState(()=>a(e)),[c,u]=x.useState(null),d=x.useRef(e);x.useEffect(()=>{e!==d.current&&(d.current=e,l(a(e)))},[e]);function f(j){const k={};for(const w of j){const N=w.key.trim();if(N)if(w.source==="secret"){if(!w.secretId)continue;k[N]={type:"secret_ref",secretId:w.secretId,version:"latest"}}else k[N]={type:"plain",value:w.plainValue}}r(Object.keys(k).length>0?k:void 0)}function h(j,k){const w=o.map((N,C)=>C===j?{...N,...k}:N);(w[w.length-1].key||w[w.length-1].plainValue||w[w.length-1].secretId)&&w.push({key:"",source:"plain",plainValue:"",secretId:""}),l(w),f(w)}function g(j){const k=o.filter((w,N)=>N!==j);(k.length===0||k[k.length-1].key||k[k.length-1].plainValue||k[k.length-1].secretId)&&k.push({key:"",source:"plain",plainValue:"",secretId:""}),l(k),f(k)}function b(j){return j.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)}async function v(j){var _;const k=o[j];if(!k)return;const w=k.key.trim(),N=k.plainValue;if(!w||N.length===0)return;const C=b(w)||"secret",A=(_=await i({title:"Secret name",label:"Name",defaultValue:C,confirmLabel:"Create secret"}))==null?void 0:_.trim();if(A)try{u(null);const E=await n(A,N);h(j,{source:"secret",secretId:E.id})}catch(E){u(E instanceof Error?E.message:"Failed to create secret")}}return s.jsxs("div",{className:"space-y-1.5",children:[o.map((j,k)=>{const w=k===o.length-1&&!j.key&&!j.plainValue&&!j.secretId;return s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("input",{className:G(Rc,"flex-[2]"),placeholder:"KEY",value:j.key,onChange:N=>h(k,{key:N.target.value})}),s.jsxs("select",{className:G(Rc,"flex-[1] bg-background"),value:j.source,onChange:N=>h(k,{source:N.target.value==="secret"?"secret":"plain",...N.target.value==="plain"?{secretId:""}:{}}),children:[s.jsx("option",{value:"plain",children:"Plain"}),s.jsx("option",{value:"secret",children:"Secret"})]}),j.source==="secret"?s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:G(Rc,"flex-[3] bg-background"),value:j.secretId,onChange:N=>h(k,{secretId:N.target.value}),children:[s.jsx("option",{value:"",children:"Select secret..."}),t.map(N=>s.jsx("option",{value:N.id,children:N.name},N.id))]}),s.jsx("button",{type:"button",className:"inline-flex items-center rounded-md border border-border px-2 py-0.5 text-xs text-muted-foreground hover:bg-accent/50 transition-colors shrink-0",onClick:()=>v(k),disabled:!j.key.trim()||!j.plainValue,title:"Create secret from current plain value",children:"New"})]}):s.jsxs(s.Fragment,{children:[s.jsx("input",{className:G(Rc,"flex-[3]"),placeholder:"value",value:j.plainValue,onChange:N=>h(k,{plainValue:N.target.value})}),s.jsx("button",{type:"button",className:"inline-flex items-center rounded-md border border-border px-2 py-0.5 text-xs text-muted-foreground hover:bg-accent/50 transition-colors shrink-0",onClick:()=>v(k),disabled:!j.key.trim()||!j.plainValue,title:"Store value as secret and replace with reference",children:"Seal"})]}),w?s.jsx("div",{className:"w-[26px] shrink-0"}):s.jsx("button",{type:"button",className:"shrink-0 p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",onClick:()=>g(k),children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]},k)}),c&&s.jsx("p",{className:"text-[11px] text-destructive",children:c}),s.jsx("p",{className:"text-[11px] text-muted-foreground/60",children:"RUDDER_* variables are injected automatically at runtime."})]})}function Sxt({runtimeType:e,adapter:t,fieldProps:n,availableSecrets:r,onCreateSecret:i}){const{isCreate:a,values:o,set:l,config:c,eff:u,mark:d}=n,f=t.ConfigFields;return s.jsxs("div",{className:"space-y-3",children:[s.jsx(f,{...n}),e==="claude_local"&&s.jsx(f2t,{...n}),s.jsx(Gn,{label:"Command",hint:as.localCommand,children:s.jsx(Hi,{value:a?o.command:u("agentRuntimeConfig","command",String(c.command??"")),onCommit:h=>a?l({command:h}):d("agentRuntimeConfig","command",h||void 0),immediate:!0,className:Rc,placeholder:vve(e)})}),s.jsx(Gn,{label:"Extra args (comma-separated)",hint:as.extraArgs,children:s.jsx(Hi,{value:a?o.extraArgs:u("agentRuntimeConfig","extraArgs",hxt(c.extraArgs)),onCommit:h=>a?l({extraArgs:h}):d("agentRuntimeConfig","extraArgs",h?mxt(h):void 0),immediate:!0,className:Rc,placeholder:"e.g. --verbose, --foo=bar"})}),s.jsx(Gn,{label:"Environment variables",hint:as.envVars,children:s.jsx(Cxt,{value:a?o.envBindings??Bre:u("agentRuntimeConfig","env",c.env??Bre),secrets:r,onCreateSecret:i,onChange:h=>a?l({envBindings:h??{},envVars:""}):d("agentRuntimeConfig","env",h)})}),!a&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{label:"Timeout (sec)",hint:as.timeoutSec,children:s.jsx(O3,{value:u("agentRuntimeConfig","timeoutSec",Number(c.timeoutSec??0)),onCommit:h=>d("agentRuntimeConfig","timeoutSec",h),immediate:!0,className:Rc})}),s.jsx(Gn,{label:"Interrupt grace period (sec)",hint:as.graceSec,children:s.jsx(O3,{value:u("agentRuntimeConfig","graceSec",Number(c.graceSec??15)),onCommit:h=>d("agentRuntimeConfig","graceSec",h),immediate:!0,className:Rc})})]})]})}const _xt=new Set(["claude_local","codex_local","gemini_local","opencode_local","pi_local","cursor"]),Axt=[...N0.map(e=>({value:e,label:gA[e]??e,comingSoon:!_xt.has(e)}))];function Ext({value:e,onChange:t}){return s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e==="opencode_local"?s.jsx(iC,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:gA[e]??e})]}),s.jsx(fr,{className:"h-3 w-3 text-muted-foreground"})]})}),s.jsx(Kn,{className:"w-[var(--radix-popover-trigger-width)] p-1",align:"start",children:Axt.map(n=>s.jsxs("button",{disabled:n.comingSoon,className:G("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded",n.comingSoon?"opacity-40 cursor-not-allowed":"hover:bg-accent/50",n.value===e&&!n.comingSoon&&"bg-accent"),onClick:()=>{n.comingSoon||t(n.value)},children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.value==="opencode_local"?s.jsx(iC,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:n.label})]}),n.comingSoon&&s.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Coming soon"})]},n.value))})]})}function Txt({label:e,hint:t,models:n,value:r,onChange:i,open:a,onOpenChange:o,allowDefault:l,allowClear:c=!1,allowCustom:u=!1,required:d,groupByProvider:f,emptyLabel:h,triggerTestId:g}){const[b,v]=x.useState(""),j=n.find(A=>A.id===r),k=b.trim(),w=x.useMemo(()=>n.filter(A=>{if(!b.trim())return!0;const _=b.toLowerCase(),E=BP(A.id)??"";return A.id.toLowerCase().includes(_)||A.label.toLowerCase().includes(_)||E.toLowerCase().includes(_)}),[n,b]),N=u&&k.length>0&&!n.some(A=>A.id===k),C=x.useMemo(()=>{if(!f)return[{provider:"models",entries:[...w].sort((_,E)=>_.id.localeCompare(E.id))}];const A=new Map;for(const _ of w){const E=BP(_.id)??"other",T=A.get(E)??[];T.push(_),A.set(E,T)}return Array.from(A.entries()).sort(([_],[E])=>_.localeCompare(E)).map(([_,E])=>({provider:_,entries:[...E].sort((T,M)=>T.id.localeCompare(M.id))}))},[w,f]);return s.jsx(Gn,{label:e,hint:t,children:s.jsxs(qn,{open:a,onOpenChange:A=>{o(A),A||v("")},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between min-w-0","data-testid":g,children:[s.jsx("span",{className:G("truncate text-left",!r&&"text-muted-foreground"),children:j?j.label:r||h||(d?"Select model (required)":"Select model")}),s.jsx(fr,{className:"h-3 w-3 text-muted-foreground"})]})}),s.jsxs(Kn,{className:"w-[var(--radix-popover-trigger-width)] p-1",align:"start",children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search models...",value:b,onChange:A=>v(A.target.value),autoFocus:!0}),s.jsxs("div",{className:"max-h-[240px] overflow-y-auto",children:[l&&s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!r&&"bg-accent"),onClick:()=>{i(""),o(!1)},children:"Default"}),c&&s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!r&&"bg-accent"),onClick:()=>{i(""),o(!1)},children:"No fallback model"}),N&&s.jsx("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",onClick:()=>{i(k),o(!1)},children:s.jsxs("span",{className:"block w-full text-left truncate",title:k,children:['Use "',k,'"']})}),C.map(A=>s.jsxs("div",{className:"mb-1 last:mb-0",children:[f&&s.jsxs("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:[A.provider," (",A.entries.length,")"]}),A.entries.map(_=>s.jsx("button",{className:G("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",_.id===r&&"bg-accent"),onClick:()=>{i(_.id),o(!1)},children:s.jsx("span",{className:"block w-full text-left truncate",title:_.id,children:f?Phe(_.id):_.label})},_.id))]},A.provider)),w.length===0&&!N&&s.jsx("p",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No models found."})]})]})]})})}function Ixt({value:e,options:t,onChange:n,open:r,onOpenChange:i}){const a=t.find(o=>o.id===e)??t[0];return s.jsx(Gn,{label:"Thinking effort",hint:as.thinkingEffort,children:s.jsxs(qn,{open:r,onOpenChange:i,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[s.jsx("span",{className:G(!e&&"text-muted-foreground"),children:(a==null?void 0:a.label)??"Auto"}),s.jsx(fr,{className:"h-3 w-3 text-muted-foreground"})]})}),s.jsx(Kn,{className:"w-[var(--radix-popover-trigger-width)] p-1",align:"start",children:t.map(o=>s.jsxs("button",{className:G("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",o.id===e&&"bg-accent"),onClick:()=>{n(o.id),i(!1)},children:[s.jsx("span",{children:o.label}),o.id?s.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:o.id}):null]},o.id||"auto"))})]})})}function Mxt({result:e,label:t}){const n=$K(e.status)??"pass",r=Nve(e),i=n==="pass"?"Passed":"Failed",a=n==="pass"?"text-green-700 dark:text-green-300 border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10":"text-red-700 dark:text-red-300 border-red-300 dark:border-red-500/40 bg-red-50 dark:bg-red-500/10";return s.jsxs("div",{className:`rounded-md border px-3 py-2 text-xs ${a}`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"font-medium",children:t?`${t}: ${i}`:i}),s.jsx("span",{className:"text-[11px] opacity-80",children:Z2(e.testedAt)})]}),r.length>0?s.jsx("div",{className:"mt-2 space-y-1.5",children:r.map((o,l)=>s.jsxs("div",{className:"text-[11px] leading-relaxed break-words",children:[s.jsx("span",{className:"font-medium uppercase tracking-wide opacity-80",children:o.level}),s.jsx("span",{className:"mx-1 opacity-60",children:"·"}),s.jsx("span",{children:o.message}),o.detail&&s.jsxs("span",{className:"block opacity-75 break-all",children:["(",o.detail,")"]}),o.hint&&s.jsxs("span",{className:"block opacity-90 break-words",children:["Hint: ",o.hint]})]},`${o.code}-${l}`))}):null]})}function Rxt({label:e,message:t}){return s.jsxs("div",{className:"rounded-md border border-red-300 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-500/40 dark:bg-red-500/10 dark:text-red-300",children:[s.jsxs("div",{className:"font-medium",children:[e,": Failed"]}),s.jsx("div",{className:"mt-1 text-[11px] leading-relaxed break-words opacity-90",children:t})]})}function Oxt({status:e}){const t=$K(e);if(!t)return null;const n=t==="pass"?"Env passed":t==="testing"?"Testing env":"Env failed",r=t==="pass"?"border-green-300 bg-green-50 text-green-700 dark:border-green-500/40 dark:bg-green-500/10 dark:text-green-300":t==="testing"?"border-blue-300 bg-blue-50 text-blue-700 dark:border-blue-500/40 dark:bg-blue-500/10 dark:text-blue-300":"border-red-300 bg-red-50 text-red-700 dark:border-red-500/40 dark:bg-red-500/10 dark:text-red-300";return s.jsx("span",{className:G("shrink-0 rounded-full border px-2 py-0.5 text-[11px] font-medium",r),children:n})}function xC({title:e,className:t,runtimeType:n,model:r,config:i,selectedOrganizationId:a,externalModels:o,availableSecrets:l,onCreateSecret:c,onRuntimeTypeChange:u,onModelChange:d,onConfigFieldChange:f,onConfigPatchChange:h,onRemove:g,hideRuntimeType:b=!1,hideInstructionsFile:v=!1,runtimeTypeLabel:j="Runtime type",runtimeTypeHint:k=as.agentRuntimeType,createValues:w,createSet:N,environmentStatus:C,triggerTestId:A}){const[_,E]=x.useState(!1),[T,M]=x.useState(!1),[O,P]=x.useState(!1),z=x.useMemo(()=>T1(n),[n]),{data:L}=Ne({queryKey:a?q.agents.adapterModels(a,n):["agents","none","adapter-models",n],queryFn:()=>Bt.adapterModels(a,n),enabled:!!a}),Q=x.useMemo(()=>c_(n,L,o),[n,L,o]),ee=wxt(n),B=w?w.thinkingEffort:String(i[ee]??i.reasoningEffort??""),F={mode:w?"create":"edit",isCreate:!!w,agentRuntimeType:n,values:w??null,set:N??null,config:i,eff:(Z,W,$)=>Object.prototype.hasOwnProperty.call(i,W)?i[W]:$,mark:(Z,W,$)=>f(W,$),models:Q,hideInstructionsFile:v};return s.jsxs("div",{className:G("rounded-lg border border-border/80 bg-background/30 p-3",t),children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("div",{className:"truncate text-sm font-medium",children:e}),s.jsx(Oxt,{status:C})]}),g?s.jsx(ce,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-destructive",onClick:g,"aria-label":`Remove ${e}`,children:s.jsx(Sa,{className:"h-3.5 w-3.5"})}):null]}),s.jsxs("div",{className:"space-y-3",children:[!b&&s.jsx(Gn,{label:j,hint:k,children:s.jsx(Ext,{value:n,onChange:u})}),s.jsx(Txt,{label:"Model",hint:as.model,models:Q,value:r,onChange:d,open:_,onOpenChange:E,allowDefault:n!=="opencode_local"&&!g,required:n==="opencode_local"||!!g,groupByProvider:n==="opencode_local",emptyLabel:n==="opencode_local"||g?"Select model":"Default",allowCustom:!0,triggerTestId:A}),jxt(n)&&s.jsx(s.Fragment,{children:s.jsx(Ixt,{value:B,options:kxt(n),onChange:Z=>{N?N({thinkingEffort:Z}):n==="codex_local"?h==null||h({modelReasoningEffort:Z||void 0,reasoningEffort:void 0}):f(ee,Z||void 0)},open:T,onOpenChange:M})}),s.jsx(sve,{title:"Advanced options",bordered:!0,open:O,onToggle:()=>P(!O),children:s.jsx(Sxt,{runtimeType:n,adapter:z,fieldProps:F,availableSecrets:l,onCreateSecret:c})})]})]})}function FK(e){const{mode:t,adapterModels:n}=e,r=t==="create",i=e.sectionLayout==="cards",a=e.showAdapterTypeField??!0,o=e.showAdapterTestEnvironmentButton??!0,l=e.showCreateRunPolicySection??!0,c=e.hideInstructionsFile??!1,{selectedOrganizationId:u}=wn(),d=vn(),{data:f=[]}=Ne({queryKey:u?q.secrets.list(u):["secrets","none"],queryFn:()=>gC.list(u),enabled:!!u}),h=nt({mutationFn:X=>{if(!u)throw new Error("Select a organization to create secrets");return gC.create(u,X)},onSuccess:()=>{u&&d.invalidateQueries({queryKey:q.secrets.list(u)})}}),g=nt({mutationFn:async({file:X,namespace:ie})=>{if(!u)throw new Error("Select a organization to upload images");return E0.uploadImage(u,X,ie)}}),[b,v]=x.useState(hR),j=x.useRef(null);x.useEffect(()=>{r||(j.current!==null&&e.agent!==j.current&&v({...hR}),j.current=e.agent)},[r,r?void 0:e.agent]);const k=!r&&fxt(b);function w(X,ie,pe){const ke=b[X];return ie in ke?ke[ie]:pe}function N(X,ie,pe){v(ke=>({...ke,[X]:{...ke[X],[ie]:pe}}))}function C(X){v(ie=>({...ie,agentRuntimeConfig:{...ie.agentRuntimeConfig,...X}}))}const A=x.useCallback(()=>{v({...hR})},[]),_=x.useCallback(()=>{if(r||!k)return;const X=e.agent,ie={};if(Object.keys(b.identity).length>0&&Object.assign(ie,b.identity),b.agentRuntimeType!==void 0)ie.agentRuntimeType=b.agentRuntimeType,ie.agentRuntimeConfig=Ure(b.agentRuntimeConfig);else if(Object.keys(b.agentRuntimeConfig).length>0){const ke={...X.agentRuntimeConfig??{},...b.agentRuntimeConfig};ie.agentRuntimeConfig=Ure(ke),Nxt(b.agentRuntimeConfig)&&(ie.replaceAgentRuntimeConfig=!0)}if(Object.keys(b.heartbeat).length>0){const pe=X.runtimeConfig??{},ke=pe.heartbeat??{};ie.runtimeConfig={...pe,heartbeat:{...ke,...b.heartbeat}}}Object.keys(b.runtime).length>0&&Object.assign(ie,b.runtime),e.onSave(ie)},[r,k,b,e]);x.useEffect(()=>{var X,ie,pe;r||((X=e.onDirtyChange)==null||X.call(e,k),(ie=e.onSaveActionChange)==null||ie.call(e,_),(pe=e.onCancelActionChange)==null||pe.call(e,A))},[r,k,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange,_,A]),x.useEffect(()=>{if(!r)return()=>{var X,ie,pe;(X=e.onSaveActionChange)==null||X.call(e,null),(ie=e.onCancelActionChange)==null||ie.call(e,null),(pe=e.onDirtyChange)==null||pe.call(e,!1)}},[r,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange]);const E=r?{}:e.agent.agentRuntimeConfig??{},T=r?{}:e.agent.runtimeConfig??{},M=r?{}:T.heartbeat??{},O=r?e.values.agentRuntimeType:b.agentRuntimeType??e.agent.agentRuntimeType,P=yxt.includes(O),z=x.useMemo(()=>T1(O),[O]),{data:L,error:Q}=Ne({queryKey:u?q.agents.adapterModels(u,O):["agents","none","adapter-models",O],queryFn:()=>Bt.adapterModels(u,O),enabled:!!u});x.useMemo(()=>c_(O,L,n),[O,L,n]);const{data:ee=[]}=Ne({queryKey:u?q.agents.list(u):["agents","none","list"],queryFn:()=>Bt.list(u),enabled:!!(!r&&u)});r&&e.values;const[B,F]=x.useState(!1),[Z,W]=x.useState(!1),$=r?e.values:null,Y=r?X=>e.onChange(X):null;function V(){return r?z.buildAdapterConfig($):{...E,...b.agentRuntimeConfig}}const H=r?$.model:w("agentRuntimeConfig","model",String(E.model??"")),ae=D3(r?$.modelFallbacks:w("agentRuntimeConfig","modelFallbacks",E.modelFallbacks??[]),P3(O,H));function le(){const X={...V()};return delete X.modelFallbacks,[{key:"primary",title:"Primary",runtimeType:O,model:H,config:{...X,...H?{model:H}:{}}},...ae.map((ie,pe)=>({key:`fallback-${pe}`,title:`Fallback ${pe+1}`,runtimeType:ie.agentRuntimeType,model:ie.model,config:{...ie.config??{},...ie.model?{model:ie.model}:{}}}))]}const fe=nt({mutationFn:async()=>{if(!u)throw new Error("Select a organization to test runtime environment");const X=le(),ie=[];for(const pe of X)try{const ke=await Bt.testEnvironment(u,pe.runtimeType,{agentRuntimeConfig:pe.config});ie.push({...pe,result:ke})}catch(ke){ie.push({...pe,error:ke instanceof Error?ke:new Error(String(ke))})}return ie}}),U=x.useMemo(()=>new Map((fe.data??[]).map(X=>[X.key,X])),[fe.data]);function xe(X){var pe;if(fe.isPending)return"testing";const ie=U.get(X);if(ie)return ie.error?"error":(pe=ie.result)==null?void 0:pe.status}function re(X){const ie=D3(X,P3(O,H));r?Y({modelFallbacks:ie}):N("agentRuntimeConfig","modelFallbacks",ie)}return O==="codex_local"&&(r?$.search:w("agentRuntimeConfig","search",!!E.search)),x.useMemo(()=>{if(r)return{heartbeat:{enabled:$.heartbeatEnabled,intervalSec:$.intervalSec,preflightEnabled:$.preflightEnabled,maxConcurrentRuns:$.maxConcurrentRuns}};const X={...T.heartbeat&&typeof T.heartbeat=="object"?T.heartbeat:{},...b.heartbeat};return{...T,heartbeat:X}},[r,b.heartbeat,T,$]),s.jsxs("div",{className:G("relative",i&&"space-y-6"),children:[k&&!e.hideInlineSave&&s.jsx("div",{className:"sticky top-0 z-10 flex items-center justify-end px-4 py-2 bg-background/90 backdrop-blur-sm border-b border-primary/20",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Unsaved changes"}),s.jsx(ce,{size:"sm",onClick:_,disabled:!r&&e.isSaving,children:!r&&e.isSaving?"Saving...":"Save"})]})}),!r&&s.jsxs("div",{className:G(!i&&"border-b border-border"),children:[i?s.jsx("h3",{className:"text-sm font-medium mb-3",children:"Identity"}):s.jsx("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Identity"}),s.jsxs("div",{className:G(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[s.jsx(Gn,{label:"Name",hint:as.name,children:s.jsx(Hi,{value:w("identity","name",e.agent.name),onCommit:X=>N("identity","name",X),immediate:!0,className:Rc,placeholder:"Agent name"})}),s.jsx(Gn,{label:"Title",hint:as.title,children:s.jsx(Hi,{value:w("identity","title",e.agent.title??""),onCommit:X=>N("identity","title",X||null),immediate:!0,className:Rc,placeholder:"e.g. VP of Engineering"})}),s.jsx(Gn,{label:"Reports to",hint:as.reportsTo,children:s.jsx(LK,{agents:ee,value:w("identity","reportsTo",e.agent.reportsTo??null),onChange:X=>N("identity","reportsTo",X),excludeAgentIds:[e.agent.id],chooseLabel:"Choose manager…"})}),s.jsx(Gn,{label:"Capabilities",hint:as.capabilities,children:s.jsx(ol,{value:w("identity","capabilities",e.agent.capabilities??""),onChange:X=>N("identity","capabilities",X||null),placeholder:"Describe what this agent can do...",contentClassName:"min-h-[44px] text-sm font-mono",imageUploadHandler:async X=>(await g.mutateAsync({file:X,namespace:`agents/${e.agent.id}/capabilities`})).contentPath})}),P&&!e.hidePromptTemplate&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{label:"Prompt Template",hint:as.promptTemplate,children:s.jsx(ol,{value:w("agentRuntimeConfig","promptTemplate",String(E.promptTemplate??"")),onChange:X=>N("agentRuntimeConfig","promptTemplate",X??""),placeholder:"Use this only for compact per-run task framing...",contentClassName:"min-h-[88px] text-sm font-mono",imageUploadHandler:async X=>{const ie=`agents/${e.agent.id}/prompt-template`;return(await g.mutateAsync({file:X,namespace:ie})).contentPath}})}),s.jsx("div",{"data-testid":"prompt-template-helper",className:"rounded-md border border-border/70 bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:"Prompt template is replayed on every heartbeat for existing runtime configs. Keep it compact and dynamic to avoid recurring token cost and cache churn."})]})]})]}),s.jsxs("div",{className:G(!i&&(r?"border-t border-border":"border-b border-border")),children:[s.jsxs("div",{className:G(i?"flex items-center justify-between mb-3":"px-4 py-2 flex items-center justify-between gap-2"),children:[i?s.jsx("h3",{className:"text-sm font-medium",children:"Agent Runtime"}):s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent Runtime"}),o&&s.jsx(ce,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",onClick:()=>fe.mutate(),disabled:fe.isPending||!u,children:fe.isPending?"Testing runtime chain...":"Test runtime chain"})]}),s.jsxs("div",{className:G(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[fe.error&&s.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:fe.error instanceof Error?fe.error.message:"Runtime chain environment test failed"}),fe.data&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Runtime chain environment"}),fe.data.map(X=>{var ie;return X.result?s.jsx(Mxt,{result:X.result,label:qre(X)},X.key):s.jsx(Rxt,{label:qre(X),message:((ie=X.error)==null?void 0:ie.message)??"Environment test failed"},X.key)})]}),s.jsxs("div",{className:jve,children:[s.jsx(xC,{title:"Primary",className:L3,runtimeType:O,model:H,config:r?z.buildAdapterConfig($):{...E,...b.agentRuntimeConfig},selectedOrganizationId:u,externalModels:n,availableSecrets:f,onCreateSecret:(X,ie)=>h.mutateAsync({name:X,value:ie}),hideRuntimeType:!a,hideInstructionsFile:c,createValues:r?$:null,createSet:r?Y:null,onRuntimeTypeChange:X=>{if(r){Y(wve(X));return}v(ie=>({...ie,agentRuntimeType:X,agentRuntimeConfig:{...D5(X),modelFallbacks:[]}}))},onModelChange:X=>{const ie=D3(ae,P3(O,X));r?Y({model:X,modelFallbacks:ie}):(N("agentRuntimeConfig","model",X||void 0),N("agentRuntimeConfig","modelFallbacks",ie))},onConfigFieldChange:(X,ie)=>r?Y({[X]:ie}):N("agentRuntimeConfig",X,ie),onConfigPatchChange:X=>{r?Y(X):C(X)},environmentStatus:xe("primary"),triggerTestId:"agent-primary-model"}),ae.map((X,ie)=>s.jsx(xC,{title:`Fallback ${ie+1}`,className:L3,runtimeType:X.agentRuntimeType,model:X.model,config:{...X.config??{},model:X.model},selectedOrganizationId:u,externalModels:void 0,availableSecrets:f,onCreateSecret:(pe,ke)=>h.mutateAsync({name:pe,value:ke}),hideInstructionsFile:c,onRemove:()=>re(ae.filter((pe,ke)=>ke!==ie)),onRuntimeTypeChange:pe=>{const ke=D5(pe),Ce=[...ae];Ce[ie]={agentRuntimeType:pe,model:typeof ke.model=="string"?ke.model:s8(pe),config:ke},re(Ce)},onModelChange:pe=>{const ke=[...ae];ke[ie]={...X,model:pe,config:{...X.config??{},model:pe}},re(ke)},onConfigFieldChange:(pe,ke)=>{const Ce=[...ae];Ce[ie]={...X,config:{...X.config??{},[pe]:ke}},re(Ce)},onConfigPatchChange:pe=>{const ke=[...ae];ke[ie]={...X,config:{...X.config??{},...pe}},re(ke)},environmentStatus:xe(`fallback-${ie}`),triggerTestId:`agent-fallback-model-${ie+1}`},`${X.agentRuntimeType}-${ie}`)),s.jsx("button",{type:"button",className:G(L3,"min-h-[180px] rounded-lg border border-dashed border-border/80 px-4 py-4 text-left transition-colors hover:border-primary/50 hover:bg-accent/30"),onClick:()=>re([...ae,kve(O)]),children:s.jsxs("div",{className:"flex h-full min-h-[140px] flex-col items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx("span",{className:"rounded-full border border-border p-2",children:s.jsx(tr,{className:"h-4 w-4"})}),s.jsx("span",{children:"Add fallback model"})]})})]}),Q&&s.jsx("p",{className:"text-xs text-destructive",children:Q instanceof Error?Q.message:"Failed to load runtime models."}),P&&r&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{label:"Prompt Template",hint:as.promptTemplate,children:s.jsx(ol,{value:$.promptTemplate,onChange:X=>Y({promptTemplate:X}),placeholder:`# SOUL.md
|
|
1349
1349
|
|
|
1350
|
-
You are agent {{ agent.name }}. Your role is {{ agent.role }}...`,contentClassName:"min-h-[88px] text-sm font-mono",imageUploadHandler:async X=>(await g.mutateAsync({file:X,namespace:"agents/drafts/prompt-template"})).contentPath})}),s.jsx("div",{"data-testid":"prompt-template-helper",className:"rounded-md border border-border/70 bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:"For new local agents, Rudder materializes this as SOUL.md in the managed instructions bundle. Define role, scope, responsibilities, boundaries, and voice; leave Rudder's shared operating contract out."})]})]})]}),r&&l?s.jsxs("div",{className:G(!i&&"border-b border-border"),children:[i?s.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}):s.jsxs("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}),s.jsxs("div",{className:G(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[s.jsx(Ore,{label:"Heartbeat on interval",description:as.heartbeatInterval,checked:$.heartbeatEnabled,onCheckedChange:X=>Y({heartbeatEnabled:X}),number:$.intervalSec,onNumberChange:X=>Y({intervalSec:X}),numberLabel:"sec",numberPrefix:"Run heartbeat every",showNumber:$.heartbeatEnabled}),s.jsx(Gn,{label:"Agent run concurrency",description:as.maxConcurrentRuns,children:s.jsx(O3,{value:$.maxConcurrentRuns,onCommit:X=>Y({maxConcurrentRuns:X}),immediate:!0,min:xQ,max:bQ,step:1,"aria-label":"Agent run concurrency",className:Rc})}),s.jsx(bp,{label:"Preflight before timer run",description:as.heartbeatPreflight,checked:$.preflightEnabled,onChange:X=>Y({preflightEnabled:X})})]})]}):r?null:s.jsxs("div",{className:G(!i&&"border-b border-border"),children:[i?s.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}):s.jsxs("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}),s.jsxs("div",{className:G(i?"border border-border rounded-lg overflow-hidden":""),children:[s.jsxs("div",{className:G(i?"p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[s.jsx(Ore,{label:"Heartbeat on interval",description:as.heartbeatInterval,checked:w("heartbeat","enabled",M.enabled!==!1),onCheckedChange:X=>N("heartbeat","enabled",X),number:w("heartbeat","intervalSec",Number(M.intervalSec??300)),onNumberChange:X=>N("heartbeat","intervalSec",X),numberLabel:"sec",numberPrefix:"Run heartbeat every",showNumber:w("heartbeat","enabled",M.enabled!==!1)}),s.jsx(Gn,{label:"Agent run concurrency",description:as.maxConcurrentRuns,children:s.jsx(O3,{value:w("heartbeat","maxConcurrentRuns",Number(M.maxConcurrentRuns??gz)),onCommit:X=>N("heartbeat","maxConcurrentRuns",X),immediate:!0,min:xQ,max:bQ,step:1,"aria-label":"Agent run concurrency",className:Rc})}),s.jsx(bp,{label:"Preflight before timer run",description:as.heartbeatPreflight,checked:w("heartbeat","preflightEnabled",M.preflightEnabled!==!1&&M.timerPreflightEnabled!==!1),onChange:X=>N("heartbeat","preflightEnabled",X)})]}),s.jsx(sve,{title:"Advanced Run Policy",bordered:i,open:Z,onToggle:()=>W(!Z),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(bp,{label:"Wake on demand",description:as.wakeOnDemand,checked:w("heartbeat","wakeOnDemand",M.wakeOnDemand!==!1),onChange:X=>N("heartbeat","wakeOnDemand",X)}),s.jsx(Gn,{label:"Cooldown (sec)",description:as.cooldownSec,children:s.jsx(O3,{value:w("heartbeat","cooldownSec",Number(M.cooldownSec??10)),onCommit:X=>N("heartbeat","cooldownSec",X),immediate:!0,className:Rc})})]})})]})]})]})}function Pxt({result:e}){const t=$K(e.status)??"pass",n=Nve(e),r=t==="pass"?"Passed":"Failed",i=t==="pass"?"text-green-700 dark:text-green-300 border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10":"text-red-700 dark:text-red-300 border-red-300 dark:border-red-500/40 bg-red-50 dark:bg-red-500/10";return s.jsxs("div",{className:`rounded-md border px-2.5 py-2 text-[11px] ${i}`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"font-medium",children:r}),s.jsx("span",{className:"opacity-80",children:Z2(e.testedAt)})]}),n.length>0?s.jsx("div",{className:"mt-1.5 space-y-1",children:n.map((a,o)=>s.jsxs("div",{className:"leading-relaxed break-words",children:[s.jsx("span",{className:"font-medium uppercase tracking-wide opacity-80",children:a.level}),s.jsx("span",{className:"mx-1 opacity-60",children:"·"}),s.jsx("span",{children:a.message}),a.detail&&s.jsxs("span",{className:"block opacity-75 break-all",children:["(",a.detail,")"]}),a.hint&&s.jsxs("span",{className:"block opacity-90 break-words",children:["Hint: ",a.hint]})]},`${a.code}-${o}`))}):null]})}function Dxt(){const{onboardingOpen:e,onboardingOptions:t,closeOnboarding:n}=Wr(),{organizations:r,setSelectedOrganizationId:i,loading:a}=wn(),o=vn(),l=Ir(),c=Mn(),{orgPrefix:u}=ci(),[d,f]=x.useState(!1),h=u&&a?null:oxt({pathname:c.pathname,orgPrefix:u,organizations:r}),g=e||h!==null&&!d,b=e?t:h??{},v=b.orgId,j=v?2:1,k=v?2:1,[w,N]=x.useState(j),[C,A]=x.useState(j),[_,E]=x.useState(!1),[T,M]=x.useState(null),[O,P]=x.useState(!1),[z,L]=x.useState(""),[Q,ee]=x.useState(""),[B,F]=x.useState(""),[Z,W]=x.useState(!0),[$,Y]=x.useState(""),[V,H]=x.useState(null),[ae,le]=x.useState("claude_local"),[fe,U]=x.useState(""),[xe,re]=x.useState(""),[X,ie]=x.useState(""),[pe,ke]=x.useState(""),[Ce,$e]=x.useState(null),[Ue,he]=x.useState(null),[We,ct]=x.useState(!1),[Pe,Ae]=x.useState(!1),[oe,D]=x.useState(!1),[J,de]=x.useState(!1),[ue,me]=x.useState("Hire your first engineer and create a hiring plan"),[K,je]=x.useState(zre),Be=x.useRef(null),Ve=x.useRef(null),Me=x.useRef(!1),ht=x.useRef(!1),ve=x.useCallback(()=>{const Ye=Be.current;Ye&&(Ye.style.height="auto",Ye.style.height=Ye.scrollHeight+"px")},[]),[Le,Ie]=x.useState(v??null),[at,Je]=x.useState(null),[St,Pt]=x.useState(null),[_t,Lt]=x.useState(null),[It,Vt]=x.useState(null),[Sn,rt]=x.useState(null),[sn,tn]=x.useState(null),[xn,Se]=x.useState(!1),ye=x.useMemo(()=>Le?r.find(Ye=>Ye.id===Le)??null:null,[Le,r]),st=(ye==null?void 0:ye.name)??at??"",kt=(ye==null?void 0:ye.issuePrefix)??St??null,$t=!!Le,Nn=!!It,_n=x.useCallback(Ye=>{o.setQueryData(q.organizations.all,Nt=>dxt(Nt,Ye))},[o]),Ee=ue.trim().length>0,we=k===1&&$t,Ze="Everything is set up. Launching now will create the starter task, wake the agent, and open the issue.",Ot=x.useCallback(Ye=>Ye>=k&&Ye<=C,[C,k]),un=x.useMemo(()=>w===4?3:w===3?2:w===2&&we?1:null,[we,w]);x.useEffect(()=>{f(!1)},[c.pathname]),x.useEffect(()=>{if(!g)return;const Ye=b.orgId??null;N(Ye?2:1),A(Ye?2:1),Y(""),H(null),W(!0),ht.current=!1,Ie(Ye),Je(null),Pt(null),Lt(null),Vt(null),rt(null),tn(null),Se(!1)},[g,b.orgId]),x.useEffect(()=>{!g||!ye||(St||Pt(ye.issuePrefix),at||Je(ye.name))},[g,ye,at,St]),x.useEffect(()=>{w===3&&ve()},[w,K,ve]),x.useEffect(()=>{const Ye=xn&&Le!==null&&sn===null;Ve.current=Ye?Le:null,Me.current=Ye,!(typeof window>"u")&&Ye&&Le&&window.sessionStorage.setItem(Dg,Le)},[Le,sn,xn]);const Jn=x.useCallback(async Ye=>{const Nt=Ve.current;if(!Nt||!Me.current)return!1;if(Ye!=null&&Ye.keepalive)return fetch(`/api/orgs/${encodeURIComponent(Nt)}`,{method:"DELETE",credentials:"include",keepalive:!0}),!0;Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg);try{await Xn.remove(Nt)}catch(nn){if(!(nn instanceof Ml)||nn.status!==404)throw nn}return await o.invalidateQueries({queryKey:q.organizations.all}),!0},[o]);x.useEffect(()=>{if(typeof window>"u"||Me.current&&Ve.current!==null)return;const Ye=window.sessionStorage.getItem(Dg);if(!Ye)return;let Nt=!1;return(async()=>{try{try{await Xn.remove(Ye)}catch(nn){if(!(nn instanceof Ml)||nn.status!==404)throw nn}Nt||(window.sessionStorage.removeItem(Dg),await o.invalidateQueries({queryKey:q.organizations.all}))}catch(nn){Nt||M(nn instanceof Error?nn.message:"Failed to rollback the unfinished onboarding draft.")}})(),()=>{Nt=!0}},[g,o]);const{data:$s,error:Ci,isLoading:ar,isFetching:Ts}=Ne({queryKey:Le?q.agents.adapterModels(Le,ae):["agents","none","adapter-models",ae],queryFn:()=>Bt.adapterModels(Le,ae),enabled:!!Le&&g&&w===2}),{data:Gi}=Ne({queryKey:Le?q.agents.nameSuggestion(Le):["agents","none","name-suggestion"],queryFn:()=>Bt.suggestName(Le),enabled:!!Le&&g&&w===2});x.useEffect(()=>{if(w!==2)return;const Ye=(Gi==null?void 0:Gi.name.trim())??"";!Ye||ht.current||$.trim().length>0||(Y(Ye),H(Ye),ht.current=!0)},[$,Gi,w]);const qe=ae==="claude_local"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"||ae==="pi_local"||ae==="cursor",At=xe.trim()||(ae==="codex_local"?"codex":ae==="gemini_local"?"gemini":ae==="pi_local"?"pi":ae==="cursor"?"agent":ae==="opencode_local"?"opencode":"claude");x.useEffect(()=>{w===2&&($e(null),he(null))},[w,ae,fe,xe,X,pe]),x.useEffect(()=>{if(!g)return;const Ye=()=>{Jn({keepalive:!0})};return window.addEventListener("pagehide",Ye),()=>{window.removeEventListener("pagehide",Ye)}},[Jn,g]);const Ft=x.useMemo(()=>c_(ae,$s),[ae,$s]),Pn=Ft.find(Ye=>Ye.id===fe),En=(Ce==null?void 0:Ce.checks.some(Ye=>Ye.code==="claude_anthropic_api_key_overrides_subscription"))??!1,la=ae==="claude_local"&&(Ce==null?void 0:Ce.status)==="fail"&&En,ca=x.useMemo(()=>{const Ye=z.trim().toLowerCase();return Ft.filter(Nt=>{if(!Ye)return!0;const nn=av(Nt.id,"");return Nt.id.toLowerCase().includes(Ye)||Nt.label.toLowerCase().includes(Ye)||nn.toLowerCase().includes(Ye)})},[Ft,z]),Qi=x.useMemo(()=>{if(ae!=="opencode_local")return[{provider:"models",entries:[...ca].sort((Nt,nn)=>Nt.id.localeCompare(nn.id))}];const Ye=new Map;for(const Nt of ca){const nn=av(Nt.id),cr=Ye.get(nn)??[];cr.push(Nt),Ye.set(nn,cr)}return Array.from(Ye.entries()).sort(([Nt],[nn])=>Nt.localeCompare(nn)).map(([Nt,nn])=>({provider:Nt,entries:[...nn].sort((cr,ai)=>cr.id.localeCompare(ai.id))}))},[ca,ae]);function Qa(){N(1),E(!1),M(null),ee(""),F(""),W(!0),Y(""),H(null),ht.current=!1,le("claude_local"),U(""),re(""),ie(""),ke(""),$e(null),he(null),ct(!1),Ae(!1),D(!1),me("Hire your first engineer and create a hiring plan"),je(zre),Ie(null),Je(null),Pt(null),Lt(null),Vt(null),rt(null),tn(null),Se(!1)}async function fl(){if(!_){E(!0),M(null);try{await Jn(),Qa(),n()}catch(Ye){E(!1),M(Ye instanceof Error?Ye.message:"Failed to rollback the unfinished onboarding draft.")}}}function mo(){const Nt=T1(ae).buildAdapterConfig({...yp,agentRuntimeType:ae,model:ae==="codex_local"?fe||J2:ae==="gemini_local"?fe||p5:ae==="cursor"?fe||r6:fe,command:xe,args:X,url:pe,search:ae==="codex_local"?l_:yp.search,dangerouslySkipPermissions:ae==="claude_local",dangerouslyBypassSandbox:ae==="codex_local"?o_:yp.dangerouslyBypassSandbox});if(ae==="claude_local"&&Pe){const nn=typeof Nt.env=="object"&&Nt.env!==null&&!Array.isArray(Nt.env)?{...Nt.env}:{};nn.ANTHROPIC_API_KEY={type:"plain",value:""},Nt.env=nn}return Nt}async function $i(Ye){if(!Le)return N(1),he("Complete organization setup before testing the runtime."),null;ct(!0),he(null);try{const Nt=await Bt.testEnvironment(Le,ae,{agentRuntimeConfig:Ye??mo()});return $e(Nt),Nt}catch(Nt){return he(Nt instanceof Error?Nt.message:"Runtime environment test failed"),null}finally{ct(!1)}}async function Kc(){E(!0),M(null);try{const Ye=!Le,Nt=Le?await Xn.update(Le,{name:Q.trim()}):await Xn.create({name:Q.trim()});if(Ye&&(Ve.current=Nt.id,Me.current=!0,typeof window<"u"&&window.sessionStorage.setItem(Dg,Nt.id)),Ie(Nt.id),Je(Nt.name),Pt(Nt.issuePrefix),Se(nn=>nn||Ye),o.invalidateQueries({queryKey:q.organizations.all}),B.trim()){const nn=axt(B),cr=_t?await Al.update(_t,{title:nn.title,...nn.description?{description:nn.description}:{description:""}}):await Al.create(Nt.id,{title:nn.title,...nn.description?{description:nn.description}:{},level:"organization",status:"active"});Lt(cr.id),o.invalidateQueries({queryKey:q.goals.list(Nt.id)})}N(2),A(nn=>nn>2?nn:2)}catch(Ye){M(Ye instanceof Error?Ye.message:Le?"Failed to update organization":"Failed to create organization")}finally{E(!1)}}async function Te(Ye){const nn=(await ws.list(Ye)).find(ai=>!ai.archivedAt&&ai.name===mR);if(nn)return nn;const cr=await ws.create(Ye,{name:mR,status:"planned",description:null});return o.invalidateQueries({queryKey:q.projects.list(Ye)}),cr}async function De(Ye,Nt=!0){const nn=await Vgt.seedGettingStarted(Ye,{includeTutorial:Nt});return o.invalidateQueries({queryKey:q.projects.list(Ye)}),o.invalidateQueries({queryKey:q.issues.list(Ye)}),o.invalidateQueries({queryKey:q.issues.follows(Ye)}),nn}async function vt(){if(!Le){M("Complete organization setup before creating an agent."),N(1);return}E(!0),M(null);try{const Ye=$.trim();if(!Ye){M("Agent name is required.");return}if(ae==="opencode_local"){const ai=fe.trim();if(!ai){M("OpenCode requires an explicit model in provider/model format.");return}if(Ci){M(Ci instanceof Error?Ci.message:"Failed to load OpenCode models.");return}if(ar||Ts){M("OpenCode models are still loading. Please wait and try again.");return}const Hc=$s??[];if(!Hc.some(Vc=>Vc.id===ai)){M(Hc.length===0?"No OpenCode models discovered. Run `opencode models` and authenticate providers.":`Configured OpenCode model is unavailable: ${ai}`);return}}if(qe&&!(Ce??await $i()))return;const Nt={name:Ye,role:"ceo",agentRuntimeType:ae,agentRuntimeConfig:mo(),runtimeConfig:{heartbeat:{enabled:!0,intervalSec:3600,wakeOnDemand:!0,cooldownSec:10,preflightEnabled:!0,maxConcurrentRuns:gz}}},nn=It?await Bt.update(It,Nt,Le):await Bt.create(Le,Nt);Vt(nn.id),rt(nn.name);const cr=await Xn.get(Le);if(_n(cr),o.invalidateQueries({queryKey:q.agents.list(Le)}),xn){await De(Le,Z),Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg),i(Le),wY(),Qa(),n(),l(cr.issuePrefix?`/${cr.issuePrefix}/dashboard`:"/dashboard");return}N(3),A(ai=>ai>3?ai:3)}catch(Ye){M(Ye instanceof Error?Ye.message:It?"Failed to update agent":"Failed to create agent")}finally{E(!1)}}async function Cn(){if(!Le||oe)return;D(!0),M(null),he(null),Ae(!0);const Ye=(()=>{const Nt=mo(),nn=typeof Nt.env=="object"&&Nt.env!==null&&!Array.isArray(Nt.env)?{...Nt.env}:{};return nn.ANTHROPIC_API_KEY={type:"plain",value:""},Nt.env=nn,Nt})();try{It&&(await Bt.update(It,{agentRuntimeConfig:Ye},Le),o.invalidateQueries({queryKey:q.agents.list(Le)}));const Nt=await $i(Ye);(Nt==null?void 0:Nt.status)==="fail"&&M("Retried with ANTHROPIC_API_KEY unset in adapter config, but the environment test is still failing.")}catch(Nt){M(Nt instanceof Error?Nt.message:"Failed to unset ANTHROPIC_API_KEY and retry.")}finally{D(!1)}}async function mr(){if(!Le){M("Complete organization setup before continuing."),N(1);return}if(!It){M("Create the agent before continuing to task setup."),N(2);return}M(null),N(4),A(4)}async function Yi(){if(!Le){M("Complete organization setup before launching."),N(1);return}if(!It){M("Create the agent before launching."),N(2);return}E(!0),M(null);try{let Ye=sn;if(!Ye){let Nt;xn&&(Nt=(await Te(Le)).id);const nn=await ln.create(Le,{title:ue.trim(),...K.trim()?{description:K.trim()}:{},assigneeAgentId:It,status:"todo",...Nt?{projectId:Nt}:{}});Ye=nn.identifier??nn.id,tn(Ye),o.invalidateQueries({queryKey:q.issues.list(Le)})}Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg),i(Le),wY(),Qa(),n(),l(kt?`/${kt}/issues/${Ye}`:`/issues/${Ye}`)}catch(Ye){M(Ye instanceof Error?Ye.message:"Failed to create task")}finally{E(!1)}}function ho(Ye){Ye.key==="Enter"&&(Ye.metaKey||Ye.ctrlKey)&&(Ye.preventDefault(),w===1&&Q.trim()?Kc():w===2?vt():w===3&&ue.trim()?mr():w===4&&Yi())}return g?s.jsx(Ws,{open:g,onOpenChange:Ye=>{Ye||(f(!0),fl())},children:s.jsxs(Hme,{children:[s.jsx("div",{className:"fixed inset-0 z-50 bg-background"}),s.jsxs("div",{className:"fixed inset-0 z-50 flex",onKeyDown:ho,children:[s.jsxs("button",{onClick:()=>void fl(),className:G("absolute top-4 right-4 z-10 rounded-full border p-2 transition-colors",w===1?"border-white/15 bg-white/10 text-white/80 backdrop-blur-sm hover:bg-white/15 hover:text-white":"border-border/70 bg-background/85 text-muted-foreground shadow-sm backdrop-blur-sm hover:text-foreground"),children:[s.jsx(Gs,{className:"h-5 w-5"}),s.jsx("span",{className:"sr-only",children:"Close"})," "]}),s.jsxs("div",{className:G("w-full flex flex-col overflow-y-auto transition-[width] duration-500 ease-in-out",w===1?"md:w-1/2":"md:w-full"),children:[s.jsxs("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12 shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-0 mb-8 border-b border-border",children:[[{step:1,label:"Organization",icon:hI},{step:2,label:"Agent",icon:Oi},{step:3,label:"Task",icon:x3},{step:4,label:"Launch",icon:yP}].map(({step:Ye,label:Nt,icon:nn})=>{const cr=Ot(Ye);return s.jsxs("button",{type:"button","data-testid":`onboarding-step-tab-${Ye}`,"aria-current":Ye===w?"step":void 0,"aria-disabled":!cr,disabled:!cr,onClick:()=>{!cr||Ye===w||(M(null),N(Ye))},className:G("flex items-center gap-1.5 px-3 py-2 text-xs font-medium border-b-2 -mb-px transition-colors",Ye===w?"border-foreground text-foreground":cr?"border-transparent text-muted-foreground hover:text-foreground/70 hover:border-border cursor-pointer":"border-transparent text-muted-foreground/45 cursor-not-allowed"),children:[s.jsx(nn,{className:"h-3.5 w-3.5"}),Nt," "]},Ye)})," "]}),w===1&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(hI,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Name your organization"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"This is the organization your agents will work for."})," "]})," "]}),s.jsxs("div",{className:"mt-3 group",children:[s.jsx("label",{className:G("text-xs mb-1 block transition-colors",Q.trim()?"text-foreground":"text-muted-foreground group-focus-within:text-foreground"),children:"Organization name"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"Acme Corp",value:Q,onChange:Ye=>ee(Ye.target.value),autoFocus:!0})," "]}),s.jsxs("div",{className:"group",children:[s.jsx("label",{className:G("text-xs mb-1 block transition-colors",B.trim()?"text-foreground":"text-muted-foreground group-focus-within:text-foreground"),children:"Mission / goal (optional)"}),s.jsx("textarea",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50 resize-none min-h-[60px]",placeholder:"What is this organization trying to achieve?",value:B,onChange:Ye=>F(Ye.target.value)})," "]}),s.jsxs("label",{className:"flex items-start gap-2 rounded-md border border-border/70 px-3 py-2 text-xs",children:[s.jsx(eo,{checked:Z,onCheckedChange:Ye=>W(Ye===!0),className:"mt-0.5"}),s.jsxs("span",{children:[s.jsx("span",{className:"block font-medium text-foreground",children:"I’m new to Rudder"}),s.jsx("span",{className:"block text-muted-foreground",children:"Create guided Getting Started issues. Turn this off to seed only the welcome issue. "})," "]})]})," "]}),w===2&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(Oi,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Create your first agent"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose how this agent will run tasks."})," "]})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Agent name"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"Agent name",value:$,onChange:Ye=>{Y(Ye.target.value),V&&Ye.target.value!==V&&H(null)},autoFocus:!0})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-2 block",children:"Runtime type"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[[{value:"claude_local",label:"Claude Code",icon:Sd,desc:"Local Claude agent",recommended:!0},{value:"codex_local",label:"Codex",icon:Bz,desc:"Local Codex agent",recommended:!0}].map(Ye=>s.jsxs("button",{className:G("flex flex-col items-center gap-1.5 rounded-md border p-3 text-xs transition-colors relative",ae===Ye.value?"border-foreground bg-accent":"border-border hover:bg-accent/50"),onClick:()=>{const Nt=Ye.value;le(Nt),Nt==="codex_local"&&!fe&&U(J2),Nt!=="codex_local"&&U("")},children:[Ye.recommended&&s.jsx("span",{className:"absolute -top-1.5 right-1.5 bg-green-500 text-white text-[9px] font-semibold px-1.5 py-0.5 rounded-full leading-none",children:"Recommended "}),s.jsx(Ye.icon,{className:"h-4 w-4"}),s.jsx("span",{className:"font-medium",children:Ye.label}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[Ye.desc," "]})," "]},Ye.value))," "]}),s.jsxs("button",{className:"flex items-center gap-1.5 mt-3 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>de(Ye=>!Ye),children:[s.jsx(fr,{className:G("h-3 w-3 transition-transform",J?"rotate-0":"-rotate-90")}),"More Agent Runtime Types "]}),J&&s.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-2",children:[[{value:"gemini_local",label:"Gemini CLI",icon:Uz,desc:"Local Gemini agent"},{value:"opencode_local",label:"OpenCode",icon:iC,desc:"Local multi-provider agent"},{value:"pi_local",label:"Pi",icon:y7,desc:"Local Pi agent"},{value:"cursor",label:"Cursor",icon:Rme,desc:"Local Cursor agent"},{value:"openclaw_gateway",label:"OpenClaw Gateway",icon:Oi,desc:"Invoke OpenClaw via gateway protocol",comingSoon:!0,disabledLabel:"Configure OpenClaw within the App"}].map(Ye=>s.jsxs("button",{disabled:!!Ye.comingSoon,className:G("flex flex-col items-center gap-1.5 rounded-md border p-3 text-xs transition-colors relative",Ye.comingSoon?"border-border opacity-40 cursor-not-allowed":ae===Ye.value?"border-foreground bg-accent":"border-border hover:bg-accent/50"),onClick:()=>{if(Ye.comingSoon)return;const Nt=Ye.value;if(le(Nt),Nt==="gemini_local"&&!fe){U(p5);return}if(Nt==="cursor"&&!fe){U(r6);return}if(Nt==="opencode_local"){fe.includes("/")||U("");return}U("")},children:[s.jsx(Ye.icon,{className:"h-4 w-4"}),s.jsx("span",{className:"font-medium",children:Ye.label}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[Ye.comingSoon?Ye.disabledLabel??"Coming soon":Ye.desc," "]})," "]},Ye.value))," "]})," "]}),(ae==="claude_local"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"||ae==="pi_local"||ae==="cursor")&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Model"}),s.jsxs(qn,{open:O,onOpenChange:Ye=>{P(Ye),Ye||L("")},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[s.jsxs("span",{className:G(!fe&&"text-muted-foreground"),children:[Pn?Pn.label:fe||(ae==="opencode_local"?"Select model (required)":"Default")," "]}),s.jsx(fr,{className:"h-3 w-3 text-muted-foreground"})," "]})}),s.jsxs(Kn,{className:"w-[var(--radix-popover-trigger-width)] p-1",align:"start",children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search models...",value:z,onChange:Ye=>L(Ye.target.value),autoFocus:!0}),ae!=="opencode_local"&&s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!fe&&"bg-accent"),onClick:()=>{U(""),P(!1)},children:"Default "}),s.jsxs("div",{className:"max-h-[240px] overflow-y-auto",children:[Qi.map(Ye=>s.jsxs("div",{className:"mb-1 last:mb-0",children:[ae==="opencode_local"&&s.jsxs("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:[Ye.provider," (",Ye.entries.length,") "]}),Ye.entries.map(Nt=>s.jsxs("button",{className:G("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",Nt.id===fe&&"bg-accent"),onClick:()=>{U(Nt.id),P(!1)},children:[s.jsxs("span",{className:"block w-full text-left truncate",title:Nt.id,children:[ae==="opencode_local"?Phe(Nt.id):Nt.label," "]})," "]},Nt.id))," "]},Ye.provider))," "]}),ca.length===0&&s.jsx("p",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:ar||Ts?"Loading models...":"No models discovered."})]})]})," "]})," "]}),qe&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs font-medium",children:"Runtime environment check"}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Runs a live probe that asks the runtime CLI to respond with hello."})," "]}),s.jsx(ce,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",disabled:!$t||We,onClick:()=>void $i(),children:We?"Testing...":"Test now"})," "]}),Ue&&s.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-2.5 py-2 text-[11px] text-destructive",children:[Ue," "]}),Ce&&Ce.status==="pass"?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10 px-3 py-2 text-xs text-green-700 dark:text-green-300 animate-in fade-in slide-in-from-bottom-1 duration-300",children:[s.jsx(gs,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-medium",children:"Passed"})," "]}):Ce?s.jsx(Pxt,{result:Ce}):null,la&&s.jsxs("div",{className:"rounded-md border border-amber-300/60 bg-amber-50/40 px-2.5 py-2 space-y-2",children:[s.jsxs("p",{className:"text-[11px] text-amber-900/90 leading-relaxed",children:["Claude failed while"," ",s.jsx("span",{className:"font-mono",children:"ANTHROPIC_API_KEY"})," ","is set. You can clear it in this CEO adapter config and retry the probe."]}),s.jsx(ce,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",disabled:We||oe,onClick:()=>void Cn(),children:oe?"Retrying...":"Unset ANTHROPIC_API_KEY"})," "]}),Ce&&Ce.status==="fail"&&s.jsxs("div",{className:"rounded-md border border-border/70 bg-muted/20 px-2.5 py-2 text-[11px] space-y-1.5",children:[s.jsx("p",{className:"font-medium",children:"Manual debug"}),s.jsx("p",{className:"text-muted-foreground font-mono break-all",children:ae==="cursor"?`${At} -p --mode ask --output-format json "Respond with hello."`:ae==="codex_local"?`${At} exec --json -`:ae==="gemini_local"?`${At} --output-format json "Respond with hello."`:ae==="opencode_local"?`${At} run --format json "Respond with hello."`:`${At} --print - --output-format stream-json --verbose`}),s.jsxs("p",{className:"text-muted-foreground",children:["Prompt:"," ",s.jsx("span",{className:"font-mono",children:"Respond with hello."})]}),ae==="cursor"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"?s.jsxs("p",{className:"text-muted-foreground",children:["If auth fails, set"," ",s.jsx("span",{className:"font-mono",children:ae==="cursor"?"CURSOR_API_KEY":ae==="gemini_local"?"GEMINI_API_KEY":"OPENAI_API_KEY"})," ","in env or run"," ",s.jsxs("span",{className:"font-mono",children:[ae==="cursor"?"agent login":ae==="codex_local"?"codex login":ae==="gemini_local"?"gemini auth":"opencode auth login"," "]}),"."]}):s.jsxs("p",{className:"text-muted-foreground",children:["If login is required, run"," ",s.jsx("span",{className:"font-mono",children:"claude login"})," ","and retry."]})," "]})," "]}),(ae==="http"||ae==="openclaw_gateway")&&s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:ae==="openclaw_gateway"?"Gateway URL":"Webhook URL"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm font-mono outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:ae==="openclaw_gateway"?"ws://127.0.0.1:18789":"https://...",value:pe,onChange:Ye=>ke(Ye.target.value)})," "]})," "]}),w===3&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(x3,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Give it something to do"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Give your agent a small task to start with — a bug fix, a research question, writing a script."})," "]})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Task title"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"e.g. Research competitor pricing",value:ue,onChange:Ye=>me(Ye.target.value),autoFocus:!0})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Description (optional)"}),s.jsx("textarea",{ref:Be,className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50 resize-none min-h-[120px] max-h-[300px] overflow-y-auto",placeholder:"Add more detail about what the agent should do...",value:K,onChange:Ye=>je(Ye.target.value)})," "]})," "]}),w===4&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(yP,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Ready to launch"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:Ze})," "]})," "]}),s.jsxs("div",{className:"border border-border divide-y divide-border",children:[s.jsxs("div",{"data-testid":"onboarding-launch-summary-organization",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(hI,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:$t?st:"Organization setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Organization"})," "]}),$t?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]}),s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(Oi,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:Nn?(Sn??$.trim())||"Agent":"Agent setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:Nn?T1(ae).label:"Agent"})," "]}),Nn?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]}),xn?s.jsxs("div",{"data-testid":"onboarding-launch-summary-project",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(r4,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:mR}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Project"})," "]}),s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"})," "]}):null,s.jsxs("div",{"data-testid":"onboarding-launch-summary-task",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(x3,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:Ee?ue:"Task setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Task"})," "]}),Ee?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]})," "]})," "]}),T&&s.jsxs("div",{className:"mt-3",children:[s.jsx("p",{className:"text-xs text-destructive",children:T})," "]}),s.jsxs("div",{className:"flex items-center justify-between mt-8",children:[s.jsxs("div",{children:[un!==null&&s.jsxs(ce,{variant:"ghost",size:"sm",onClick:()=>{M(null),N(un)},disabled:_,children:[s.jsx(O1,{className:"h-3.5 w-3.5 mr-1"}),"Back"]})," "]}),s.jsxs("div",{className:"flex items-center gap-2",children:[w===1&&s.jsxs(ce,{size:"sm",disabled:!Q.trim()||_,onClick:Kc,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Next"]}),w===2&&s.jsxs(ce,{size:"sm",disabled:_||We,onClick:vt,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":xn?"Create & Open Dashboard":"Next"]}),w===3&&s.jsxs(ce,{size:"sm",disabled:!ue.trim()||_,onClick:mr,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Next"]}),w===4&&s.jsxs(ce,{size:"sm",disabled:_,onClick:Yi,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Create & Open Issue"]})," "]})," "]})," "]})," "]}),s.jsxs("div",{className:G("hidden md:block overflow-hidden bg-[#1d1d1d] transition-[width,opacity] duration-500 ease-in-out",w===1?"w-1/2 opacity-100":"w-0 opacity-0"),children:[s.jsx(yve,{})," "]})," "]})]})}):null}const xA={info:"border-sky-300 bg-sky-50 text-sky-900 dark:border-sky-500/25 dark:bg-sky-950/60 dark:text-sky-100",warn:"border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-500/25 dark:bg-amber-950/60 dark:text-amber-100",error:"border-red-300 bg-red-50 text-red-900 dark:border-red-500/30 dark:bg-red-950/60 dark:text-red-100"},bA={info:"border-sky-300/80 bg-sky-50/90 text-sky-800 dark:border-sky-500/25 dark:bg-sky-950/40 dark:text-sky-200",success:"border-emerald-300/80 bg-emerald-50/90 text-emerald-800 dark:border-emerald-500/25 dark:bg-emerald-950/40 dark:text-emerald-200",warn:"border-amber-300/80 bg-amber-50/90 text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/40 dark:text-amber-200",error:"border-red-300/80 bg-red-50/90 text-red-800 dark:border-red-500/30 dark:bg-red-950/40 dark:text-red-200"},c2={info:"text-sky-800 dark:text-sky-200",success:"text-emerald-800 dark:text-emerald-200",warn:"text-amber-800 dark:text-amber-200",error:"text-red-800 dark:text-red-200"},Lxt={info:"bg-sky-500 dark:bg-sky-400",success:"bg-emerald-500 dark:bg-emerald-400",warn:"bg-amber-500 dark:bg-amber-400",error:"bg-red-500 dark:bg-red-400"};function $xt({toast:e}){return e.icon==="download"?s.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-sm)] bg-muted text-muted-foreground",children:s.jsx(Kf,{className:"h-4 w-4"})}):s.jsx("span",{className:G("mt-2 h-2 w-2 shrink-0 rounded-full",Lxt[e.tone])})}function Fxt({toast:e,onDismiss:t}){if(!e.action)return null;const n=G("mt-2 inline-flex h-8 items-center justify-center rounded-[var(--radius-sm)] px-3 text-xs font-semibold transition-colors",e.icon==="download"?"bg-foreground text-background hover:bg-foreground/90":G("underline-offset-4 hover:opacity-90",c2[e.tone]));return e.action.onClick?s.jsx("button",{type:"button",onClick:()=>{var r,i;(i=(r=e.action)==null?void 0:r.onClick)==null||i.call(r),t(e.id)},className:n,children:e.action.label}):e.action.href?s.jsx(yt,{to:e.action.href,onClick:()=>t(e.id),className:n,children:e.action.label}):null}function zxt({toast:e,onDismiss:t}){const[n,r]=x.useState(!1);return x.useEffect(()=>{const i=requestAnimationFrame(()=>r(!0));return()=>cancelAnimationFrame(i)},[]),s.jsx("li",{className:G("pointer-events-auto overflow-hidden rounded-[var(--radius-md)] border border-border/70 bg-popover text-popover-foreground shadow-[0_16px_40px_rgba(15,23,42,0.16)] backdrop-blur-xl transition-[transform,opacity] duration-200 ease-out dark:shadow-[0_16px_44px_rgba(0,0,0,0.45)]",n?"translate-y-0 opacity-100":"translate-y-3 opacity-0"),children:s.jsxs("div",{className:"flex items-start gap-3 px-3.5 py-3",children:[s.jsx($xt,{toast:e}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm font-semibold leading-5",children:e.title}),e.body&&s.jsx("p",{className:"mt-0.5 text-xs leading-4 text-muted-foreground",children:e.body}),s.jsx(Fxt,{toast:e,onDismiss:t})]}),s.jsx("button",{type:"button","aria-label":"Dismiss notification",onClick:()=>t(e.id),className:"-mr-1 -mt-1 shrink-0 rounded-[var(--radius-sm)] p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})}function Bxt(){const{toasts:e,dismissToast:t}=_r();if(e.length===0)return null;const n=s.jsx("aside",{"aria-live":"polite","aria-atomic":"false",className:"pointer-events-none fixed bottom-4 right-4 z-[1000] w-[min(calc(100vw-2rem),20rem)]",children:s.jsx("ol",{className:"flex w-full flex-col-reverse gap-2",children:e.map(r=>s.jsx(zxt,{toast:r,onDismiss:t},r.id))})});return typeof document>"u"?n:oo.createPortal(n,document.body)}const Cve=x.createContext(null),Uxt={progress:null,dismissProgress:()=>{}};function qxt({children:e}){const[t,n]=x.useState(null),[r,i]=x.useState(null);x.useEffect(()=>{var c,u;const l=bs();if(l)return(c=l.getUpdateProgress)==null||c.call(l).then(d=>{d&&n(d)}).catch(()=>{}),(u=l.onUpdateProgress)==null?void 0:u.call(l,d=>{n(d),i(f=>f===d.updateId&&d.phase!=="failed"?f:null)})},[]);const a=(t==null?void 0:t.updateId)===r?null:t,o=x.useMemo(()=>({progress:a,dismissProgress:()=>{t&&i(t.updateId)}}),[t,a]);return s.jsx(Cve.Provider,{value:o,children:e})}function Sve(){return x.useContext(Cve)??Uxt}const Kre="https://github.com/Undertone0809/rudder/releases",Hre={starting:"about.updates.progress.phase.starting",resolving_release:"about.updates.progress.phase.resolving_release",downloading_checksums:"about.updates.progress.phase.downloading_checksums",downloading_asset:"about.updates.progress.phase.downloading_asset",verifying_checksum:"about.updates.progress.phase.verifying_checksum",ready_to_install:"about.updates.progress.phase.ready_to_install",waiting_for_active_runs:"about.updates.progress.phase.waiting_for_active_runs",preparing_restart:"about.updates.progress.phase.preparing_restart",closing:"about.updates.progress.phase.closing",failed:"about.updates.progress.phase.failed"};function Vre(e){if(typeof e!="number"||!Number.isFinite(e))return null;const t=["B","KB","MB","GB"];let n=Math.max(0,e),r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return r===0?`${Math.round(n)} ${t[r]}`:`${n.toFixed(1)} ${t[r]}`}function Kxt(e){return e==="failed"?"failed":e==="ready_to_install"||e==="closing"?"ready":"active"}function Hxt(){const{progress:e,dismissProgress:t}=Sve(),{t:n}=Es(),[r,i]=x.useState(null),[a,o]=x.useState(!1);if(!e)return null;const l=e,c=Kxt(l.phase),u=Vre(l.transferredBytes),d=Vre(l.totalBytes),f=typeof l.percent=="number"?Math.max(0,Math.min(100,l.percent)):null,h=f!==null,g=f!==null?`${f}%`:u?d?`${u} / ${d}`:u:null,b=c==="active"&&!h;async function v(){const w=bs();w&&(i(null),await w.installUpdate(l.version))}async function j(){const w=bs();if(i(null),!(w!=null&&w.applyUpdate)){i(n("about.updates.installUnavailable"));return}o(!0);try{const N=await w.applyUpdate(l.updateId);N.status!=="started"&&i(N.message||n("about.updates.installFailed"))}catch(N){i(N instanceof Error?N.message:n("about.updates.installFailed"))}finally{o(!1)}}async function k(){const w=bs();w?await w.openExternal(Kre):window.open(Kre,"_blank","noopener,noreferrer")}return s.jsx("aside",{"aria-live":"polite",className:"pointer-events-none fixed bottom-[calc(1rem+5.75rem)] right-4 z-[1001] w-[min(calc(100vw-2rem),20rem)] md:bottom-4",children:s.jsx("div",{className:G("pointer-events-auto overflow-hidden rounded-[var(--radius-md)] border bg-popover text-popover-foreground shadow-[0_16px_40px_rgba(15,23,42,0.16)] backdrop-blur-xl dark:shadow-[0_16px_44px_rgba(0,0,0,0.45)]",c==="failed"?"border-destructive/35":"border-border/70"),children:s.jsxs("div",{className:"flex items-start gap-3 px-3.5 py-3",children:[s.jsx("span",{className:G("flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-sm)] bg-muted text-muted-foreground",c==="failed"&&"bg-destructive/10 text-destructive",c==="ready"&&"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"),children:c==="failed"?s.jsx(Ad,{className:"h-4 w-4"}):c==="ready"?s.jsx(Mo,{className:"h-4 w-4"}):s.jsx(Kf,{className:"h-4 w-4"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("p",{className:"text-sm font-semibold leading-5",children:c==="failed"?n("about.updates.progress.failedTitle"):l.phase==="ready_to_install"?n("about.updates.progress.readyTitle"):n("about.updates.progress.title",{version:l.version.startsWith("v")?l.version:`v${l.version}`})}),g?s.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:g}):null]}),s.jsx("p",{className:"mt-0.5 text-xs leading-4 text-muted-foreground",children:l.error??n(Hre[l.phase])}),r?s.jsx("p",{className:"mt-2 rounded-[var(--radius-sm)] border border-destructive/25 bg-destructive/8 px-2.5 py-2 text-xs leading-4 text-destructive",children:r}):null,h?s.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-muted",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":f,children:s.jsx("div",{className:G("h-full rounded-full bg-emerald-700 transition-[width] duration-300",c==="failed"&&"bg-destructive"),style:{width:`${f}%`}})}):b?s.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-muted",role:"progressbar","aria-label":n(Hre[l.phase]),children:s.jsx("div",{className:"h-full w-2/5 rounded-full bg-emerald-700/70 animate-pulse"})}):null,l.phase==="ready_to_install"?s.jsx("div",{className:"mt-2",children:s.jsx(ce,{type:"button",size:"sm",className:"h-8 px-3 text-xs",disabled:a,onClick:()=>void j(),children:n(a?"about.updates.installing":"about.updates.progress.restartToUpdate")})}):null,c==="failed"?s.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[s.jsx(ce,{type:"button",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>void v(),children:n("about.updates.progress.retry")}),s.jsx(ce,{type:"button",variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>void k(),children:n("about.updates.progress.openReleases")})]}):null]}),s.jsx("button",{type:"button","aria-label":n("about.updates.progress.dismiss"),onClick:t,className:"-mr-1 -mt-1 shrink-0 rounded-[var(--radius-sm)] p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})})}function nf(e,t,n){const r=new URLSearchParams;e&&r.set("from",e),t&&r.set("to",t);for(const[a,o]of Object.entries(n??{}))o&&r.set(a,o);const i=r.toString();return i?`?${i}`:""}const Qo={summary:(e,t,n)=>_e.get(`/orgs/${e}/costs/summary${nf(t,n)}`),byAgent:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-agent${nf(t,n)}`),trend:(e,t,n,r)=>_e.get(`/orgs/${e}/costs/trend${nf(t,n,r)}`),byAgentModel:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-agent-model${nf(t,n)}`),byProject:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-project${nf(t,n)}`),byProvider:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-provider${nf(t,n)}`),byBiller:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-biller${nf(t,n)}`),financeSummary:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-summary${nf(t,n)}`),financeByBiller:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-by-biller${nf(t,n)}`),financeByKind:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-by-kind${nf(t,n)}`),financeEvents:(e,t,n,r=100)=>_e.get(`/orgs/${e}/costs/finance-events${Vxt(t,n,r)}`),windowSpend:e=>_e.get(`/orgs/${e}/costs/window-spend`),quotaWindows:e=>_e.get(`/orgs/${e}/costs/quota-windows`)};function Vxt(e,t,n){const r=new URLSearchParams;e&&r.set("from",e),t&&r.set("to",t),n&&r.set("limit",String(n));const i=r.toString();return i?`?${i}`:""}const l1={list:(e,t)=>{const n=new URLSearchParams;t!=null&&t.entityType&&n.set("entityType",t.entityType),t!=null&&t.entityId&&n.set("entityId",t.entityId),t!=null&&t.agentId&&n.set("agentId",t.agentId),t!=null&&t.userId&&n.set("userId",t.userId),t!=null&&t.actorType&&n.set("actorType",t.actorType),t!=null&&t.actorId&&n.set("actorId",t.actorId);const r=n.toString();return _e.get(`/orgs/${e}/activity${r?`?${r}`:""}`)},forIssue:e=>_e.get(`/issues/${e}/activity`),runsForIssue:e=>_e.get(`/issues/${e}/runs`),issuesForRun:e=>_e.get(`/heartbeat-runs/${e}/issues`)},Wxt="You";function zK(e,t=Wxt){return(e==null?void 0:e.trim())||t}function i8(){const{data:e}=Ne({queryKey:q.instance.profileSettings,queryFn:()=>ka.getProfile(),staleTime:qi});return zK(e==null?void 0:e.nickname)}function Zxt(e,t){var a;const n=t.match(/\d/g)??[],r=((a=e.match(/\d/g))==null?void 0:a.length)??0;let i=0;return Array.from(e).map((o,l,c)=>{if(!/\d/.test(o))return{key:`${l}-${o}`,current:o,previous:o,isDigit:!1};const d=r-1-i,f=n[n.length-1-d]??o;return i+=1,{key:`${c.length-l}-${o}`,current:o,previous:f,isDigit:!0}})}function Gxt({value:e}){const t=String(e),n=x.useRef(t),r=x.useRef(t),[i,a]=x.useState(0);x.useEffect(()=>{t!==n.current&&(r.current=n.current,n.current=t,a(l=>l+1))},[t]);const o=x.useMemo(()=>Zxt(t,r.current),[t,i]);return s.jsx("span",{"aria-label":t,className:"metric-value-motion","data-animated":i>0?"true":"false",children:o.map((l,c)=>l.isDigit?s.jsx("span",{"aria-hidden":"true",className:"metric-digit-window",style:{"--metric-glyph-index":c},children:s.jsxs("span",{className:"metric-digit-stack",children:[s.jsx("span",{children:l.previous}),s.jsx("span",{children:l.current})]})},`${i}-${l.key}`):s.jsx("span",{"aria-hidden":"true",className:"metric-symbol",style:{"--metric-glyph-index":c},children:l.current},`${i}-${l.key}`))})}function El({icon:e,value:t,label:n,description:r,to:i,onClick:a}){const o=!!(i||a),l=s.jsx("div",{className:G("surface-panel h-full rounded-[var(--radius-lg)] px-4 py-4 sm:px-5 sm:py-5 transition-[background-color,border-color,transform]",o&&"cursor-pointer hover:surface-active"),children:s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-2xl sm:text-3xl font-semibold tracking-tight tabular-nums text-foreground",children:s.jsx(Gxt,{value:t})}),s.jsx("p",{className:"mt-1 text-xs font-medium tracking-[0.06em] text-muted-foreground sm:text-sm",children:n}),r&&s.jsx("div",{className:"mt-2 hidden text-xs leading-5 text-muted-foreground/85 sm:block",children:r})]}),s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-[calc(var(--radius-sm)+2px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-inset)_92%,transparent)]",children:s.jsx(e,{className:"h-4 w-4 text-[color:var(--accent-strong)]"})})]})});return i?s.jsx(yt,{to:i,className:"no-underline text-inherit h-full",onClick:a,children:l}):a?s.jsx("div",{className:"h-full",onClick:a,children:l}):l}function Fr({icon:e,message:t,action:n,onAction:r,className:i}){return s.jsxs("div",{className:G("surface-panel mx-auto flex max-w-xl flex-col items-center justify-center rounded-[var(--radius-xl)] px-8 py-14 text-center",i),children:[s.jsx("div",{className:"mb-5 flex h-16 w-16 items-center justify-center rounded-[calc(var(--radius-md)+4px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-proposal)_72%,transparent)]",children:s.jsx(e,{className:"h-8 w-8 text-[color:var(--accent-base)]"})}),s.jsx("p",{className:"font-display text-[1.5rem] leading-tight text-foreground",children:"Nothing here yet"}),s.jsx("p",{className:"mt-3 max-w-md text-sm leading-6 text-muted-foreground",children:t}),n&&r&&s.jsxs(ce,{onClick:r,className:"mt-6",children:[s.jsx(tr,{className:"h-4 w-4 mr-1.5"}),n]})]})}function Qxt(e){const t=e.replace(/\s*\([^)]*\)\s*/g," ").trim()||e.trim(),n=t.split(/\s+/);return n.length>=2?(n[0][0]+n[n.length-1][0]).toUpperCase():t.slice(0,2).toUpperCase()}const Yxt={xs:"text-sm",sm:"text-xs",default:"text-sm",lg:"text-sm"};function Da({name:e,avatarUrl:t,initials:n,size:r="default",className:i}){const a=n??Qxt(e);return s.jsxs("span",{className:G("inline-flex gap-1.5",r==="xs"?"items-baseline gap-1":"items-center",r==="lg"&&"gap-2",i),children:[s.jsxs(vl,{size:r,className:r==="xs"?"relative -top-px":void 0,children:[t&&s.jsx(GKe,{src:t,alt:e}),s.jsx(wl,{children:a})]}),s.jsx("span",{className:G("truncate",Yxt[r]),children:e})]})}function a8(e,t,n,r){return e==="system"?"System":e==="user"?n&&t===n?zK(r):"Board":t||"Unknown"}function Jxt(e,t,n,r){var i;return e.actorType==="agent"?((i=t.get(e.actorId))==null?void 0:i.name)??e.actorId??"Unknown":a8(e.actorType,e.actorId,n,r)}const b$=60,y$=60*b$,bC=24*y$,Wre=7*bC,Zre=30*bC;function I1(e){const t=tm(),n=Date.now(),r=new Date(e).getTime(),i=Math.round((n-r)/1e3);if(i<b$)return t==="zh-CN"?"刚刚":"just now";if(i<y$){const o=Math.floor(i/b$);return t==="zh-CN"?`${o} 分钟前`:`${o}m ago`}if(i<bC){const o=Math.floor(i/y$);return t==="zh-CN"?`${o} 小时前`:`${o}h ago`}if(i<Wre){const o=Math.floor(i/bC);return t==="zh-CN"?`${o} 天前`:`${o}d ago`}if(i<Zre){const o=Math.floor(i/Wre);return t==="zh-CN"?`${o} 周前`:`${o}w ago`}const a=Math.floor(i/Zre);return t==="zh-CN"?Ha(e):`${a}mo ago`}const Xxt={"issue.created":"created","issue.updated":"updated","issue.checked_out":"checked out","issue.released":"released","issue.comment_added":"commented on","issue.code_committed":"committed","issue.attachment_added":"attached file to","issue.attachment_removed":"removed attachment from","issue.document_created":"created document for","issue.document_updated":"updated document on","issue.document_deleted":"deleted document from","issue.commented":"commented on","issue.human_intervention_required":"requested human intervention on","issue.deleted":"deleted","agent.created":"created","agent.updated":"updated","agent.paused":"paused","agent.resumed":"resumed","agent.terminated":"terminated","agent.key_created":"created API key for","agent.budget_updated":"updated budget for","agent.runtime_session_reset":"reset session for","heartbeat.invoked":"invoked heartbeat for","heartbeat.cancelled":"cancelled heartbeat for","approval.created":"requested approval","approval.approved":"approved","approval.rejected":"rejected","project.created":"created","project.updated":"updated","project.deleted":"deleted","goal.created":"created","goal.updated":"updated","goal.deleted":"deleted","cost.reported":"reported cost for","cost.recorded":"recorded cost for","organization.created":"created organization","organization.updated":"updated organization","organization.archived":"archived","organization.budget_updated":"updated budget for"};function Dx(e){return typeof e!="string"?String(e??"none"):e.replace(/_/g," ")}function e3t(e,t){if(e==="issue.code_committed"&&t){const n=typeof t.shortSha=="string"?t.shortSha:null,r=typeof t.subject=="string"?t.subject:null;if(n&&r)return`committed ${n}: ${r} to`;if(n)return`committed ${n} to`}if(e==="issue.updated"&&t){const n=t._previous??{};if(t.status!==void 0){const r=n.status;return r?`changed status from ${Dx(r)} to ${Dx(t.status)} on`:`changed status to ${Dx(t.status)} on`}if(t.priority!==void 0){const r=n.priority;return r?`changed priority from ${Lo(Dx(r))} to ${Lo(Dx(t.priority))} on`:`changed priority to ${Lo(Dx(t.priority))} on`}}return Xxt[e]??e.replace(/[._]/g," ")}function t3t(e,t,n){switch(e){case"issue":return`/issues/${n??t}`;case"agent":return`/agents/${t}`;case"project":return`/projects/${Iz(n,t)}`;case"goal":return`/goals/${t}`;case"approval":return`/messenger/approvals/${t}`;default:return null}}function n3t(e){switch(e){case"goal":return"goal";case"project":return"project";case"approval":return"approval";default:return null}}function BK({event:e,agentMap:t,entityNameMap:n,entityTitleMap:r,className:i,currentBoardUserId:a,operatorDisplayName:o}){var N,C;const l=e3t(e.action,e.details),c=e.entityType==="heartbeat_run",u=c?(N=e.details)==null?void 0:N.agentId:void 0,d=c?u?n.get(`agent:${u}`):null:n.get(`${e.entityType}:${e.entityId}`),f=typeof((C=e.details)==null?void 0:C.title)=="string"?e.details.title:null,h=(r==null?void 0:r.get(`${e.entityType}:${e.entityId}`))??f,g=c&&u?`/agents/${u}/runs/${e.entityId}`:t3t(e.entityType,e.entityId,d),b=e.actorType==="agent"?t.get(e.actorId):null,v=(b==null?void 0:b.name)??Jxt(e,t,a,o),j=n3t(e.entityType),k=s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("p",{className:"flex-1 min-w-0 truncate",children:[b?s.jsx(Za,{name:v,icon:b.icon,role:b.role,size:"xs",className:"align-baseline"}):s.jsx(Da,{name:v,size:"xs",className:"align-baseline"}),s.jsxs("span",{className:"text-muted-foreground ml-1",children:[l," "]}),j&&s.jsxs("span",{className:"text-muted-foreground",children:[j," "]}),d&&s.jsx("span",{className:"font-medium",children:d}),h&&h!==d&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["— ",h]})]}),s.jsx("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:I1(e.createdAt)})]}),w=G("px-4 py-2 text-sm",g&&"cursor-pointer hover:bg-accent/50 transition-colors",i);return g?s.jsx(yt,{to:g,className:G(w,"no-underline text-inherit block"),children:k}):s.jsx("div",{className:w,children:k})}const r3t=2e3,s3t=256e3;function i3t(e){return new TextEncoder().encode(e).length}function Xu(e){return typeof e=="string"&&e.trim().length>0?e:null}function a3t(e){return!e||typeof e!="object"?null:Xu(e.summary)}function Gre(e){const t=Xu(e.stdoutExcerpt)??a3t(e.resultJson);return t?[{kind:"assistant",ts:e.finishedAt??e.startedAt??e.createdAt,text:t}]:[]}function Qre(e){return e==="failed"||e==="timed_out"||e==="cancelled"||e==="succeeded"}function o3t(e,t,n){if(!t)return[];const r=`${e}:records`,a=`${n.get(r)??""}${t}`.split(`
|
|
1350
|
+
You are agent {{ agent.name }}. Your role is {{ agent.role }}...`,contentClassName:"min-h-[88px] text-sm font-mono",imageUploadHandler:async X=>(await g.mutateAsync({file:X,namespace:"agents/drafts/prompt-template"})).contentPath})}),s.jsx("div",{"data-testid":"prompt-template-helper",className:"rounded-md border border-border/70 bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:"For new local agents, Rudder materializes this as SOUL.md in the managed instructions bundle. Define role, scope, responsibilities, boundaries, and voice; leave Rudder's shared operating contract out."})]})]})]}),r&&l?s.jsxs("div",{className:G(!i&&"border-b border-border"),children:[i?s.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}):s.jsxs("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}),s.jsxs("div",{className:G(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[s.jsx(Ore,{label:"Heartbeat on interval",description:as.heartbeatInterval,checked:$.heartbeatEnabled,onCheckedChange:X=>Y({heartbeatEnabled:X}),number:$.intervalSec,onNumberChange:X=>Y({intervalSec:X}),numberLabel:"sec",numberPrefix:"Run heartbeat every",showNumber:$.heartbeatEnabled}),s.jsx(Gn,{label:"Agent run concurrency",description:as.maxConcurrentRuns,children:s.jsx(O3,{value:$.maxConcurrentRuns,onCommit:X=>Y({maxConcurrentRuns:X}),immediate:!0,min:xQ,max:bQ,step:1,"aria-label":"Agent run concurrency",className:Rc})}),s.jsx(bp,{label:"Preflight before timer run",description:as.heartbeatPreflight,checked:$.preflightEnabled,onChange:X=>Y({preflightEnabled:X})})]})]}):r?null:s.jsxs("div",{className:G(!i&&"border-b border-border"),children:[i?s.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}):s.jsxs("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[s.jsx(By,{className:"h-3 w-3"})," Run Policy"]}),s.jsxs("div",{className:G(i?"border border-border rounded-lg overflow-hidden":""),children:[s.jsxs("div",{className:G(i?"p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[s.jsx(Ore,{label:"Heartbeat on interval",description:as.heartbeatInterval,checked:w("heartbeat","enabled",M.enabled!==!1),onCheckedChange:X=>N("heartbeat","enabled",X),number:w("heartbeat","intervalSec",Number(M.intervalSec??300)),onNumberChange:X=>N("heartbeat","intervalSec",X),numberLabel:"sec",numberPrefix:"Run heartbeat every",showNumber:w("heartbeat","enabled",M.enabled!==!1)}),s.jsx(Gn,{label:"Agent run concurrency",description:as.maxConcurrentRuns,children:s.jsx(O3,{value:w("heartbeat","maxConcurrentRuns",Number(M.maxConcurrentRuns??gz)),onCommit:X=>N("heartbeat","maxConcurrentRuns",X),immediate:!0,min:xQ,max:bQ,step:1,"aria-label":"Agent run concurrency",className:Rc})}),s.jsx(bp,{label:"Preflight before timer run",description:as.heartbeatPreflight,checked:w("heartbeat","preflightEnabled",M.preflightEnabled!==!1&&M.timerPreflightEnabled!==!1),onChange:X=>N("heartbeat","preflightEnabled",X)})]}),s.jsx(sve,{title:"Advanced Run Policy",bordered:i,open:Z,onToggle:()=>W(!Z),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(bp,{label:"Wake on demand",description:as.wakeOnDemand,checked:w("heartbeat","wakeOnDemand",M.wakeOnDemand!==!1),onChange:X=>N("heartbeat","wakeOnDemand",X)}),s.jsx(Gn,{label:"Cooldown (sec)",description:as.cooldownSec,children:s.jsx(O3,{value:w("heartbeat","cooldownSec",Number(M.cooldownSec??10)),onCommit:X=>N("heartbeat","cooldownSec",X),immediate:!0,className:Rc})})]})})]})]})]})}function Pxt({result:e}){const t=$K(e.status)??"pass",n=Nve(e),r=t==="pass"?"Passed":"Failed",i=t==="pass"?"text-green-700 dark:text-green-300 border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10":"text-red-700 dark:text-red-300 border-red-300 dark:border-red-500/40 bg-red-50 dark:bg-red-500/10";return s.jsxs("div",{className:`rounded-md border px-2.5 py-2 text-[11px] ${i}`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"font-medium",children:r}),s.jsx("span",{className:"opacity-80",children:Z2(e.testedAt)})]}),n.length>0?s.jsx("div",{className:"mt-1.5 space-y-1",children:n.map((a,o)=>s.jsxs("div",{className:"leading-relaxed break-words",children:[s.jsx("span",{className:"font-medium uppercase tracking-wide opacity-80",children:a.level}),s.jsx("span",{className:"mx-1 opacity-60",children:"·"}),s.jsx("span",{children:a.message}),a.detail&&s.jsxs("span",{className:"block opacity-75 break-all",children:["(",a.detail,")"]}),a.hint&&s.jsxs("span",{className:"block opacity-90 break-words",children:["Hint: ",a.hint]})]},`${a.code}-${o}`))}):null]})}function Dxt(){const{onboardingOpen:e,onboardingOptions:t,closeOnboarding:n}=Wr(),{organizations:r,setSelectedOrganizationId:i,loading:a}=wn(),o=vn(),l=Ir(),c=Mn(),{orgPrefix:u}=ci(),[d,f]=x.useState(!1),h=u&&a?null:oxt({pathname:c.pathname,orgPrefix:u,organizations:r}),g=e||h!==null&&!d,b=e?t:h??{},v=b.orgId,j=v?2:1,k=v?2:1,[w,N]=x.useState(j),[C,A]=x.useState(j),[_,E]=x.useState(!1),[T,M]=x.useState(null),[O,P]=x.useState(!1),[z,L]=x.useState(""),[Q,ee]=x.useState(""),[B,F]=x.useState(""),[Z,W]=x.useState(!0),[$,Y]=x.useState(""),[V,H]=x.useState(null),[ae,le]=x.useState("claude_local"),[fe,U]=x.useState(""),[xe,re]=x.useState(""),[X,ie]=x.useState(""),[pe,ke]=x.useState(""),[Ce,$e]=x.useState(null),[Ue,he]=x.useState(null),[We,ct]=x.useState(!1),[Pe,Ae]=x.useState(!1),[oe,D]=x.useState(!1),[J,de]=x.useState(!1),[ue,me]=x.useState("Hire your first engineer and create a hiring plan"),[K,je]=x.useState(zre),Be=x.useRef(null),Ve=x.useRef(null),Me=x.useRef(!1),ht=x.useRef(!1),ve=x.useCallback(()=>{const Ye=Be.current;Ye&&(Ye.style.height="auto",Ye.style.height=Ye.scrollHeight+"px")},[]),[Le,Ie]=x.useState(v??null),[at,Je]=x.useState(null),[St,Pt]=x.useState(null),[_t,Lt]=x.useState(null),[It,Vt]=x.useState(null),[Sn,rt]=x.useState(null),[sn,tn]=x.useState(null),[xn,Se]=x.useState(!1),ye=x.useMemo(()=>Le?r.find(Ye=>Ye.id===Le)??null:null,[Le,r]),st=(ye==null?void 0:ye.name)??at??"",kt=(ye==null?void 0:ye.issuePrefix)??St??null,$t=!!Le,Nn=!!It,_n=x.useCallback(Ye=>{o.setQueryData(q.organizations.all,Nt=>dxt(Nt,Ye))},[o]),Ee=ue.trim().length>0,we=k===1&&$t,Ze="Everything is set up. Launching now will create the starter task, wake the agent, and open the issue.",Ot=x.useCallback(Ye=>Ye>=k&&Ye<=C,[C,k]),un=x.useMemo(()=>w===4?3:w===3?2:w===2&&we?1:null,[we,w]);x.useEffect(()=>{f(!1)},[c.pathname]),x.useEffect(()=>{if(!g)return;const Ye=b.orgId??null;N(Ye?2:1),A(Ye?2:1),Y(""),H(null),W(!0),ht.current=!1,Ie(Ye),Je(null),Pt(null),Lt(null),Vt(null),rt(null),tn(null),Se(!1)},[g,b.orgId]),x.useEffect(()=>{!g||!ye||(St||Pt(ye.issuePrefix),at||Je(ye.name))},[g,ye,at,St]),x.useEffect(()=>{w===3&&ve()},[w,K,ve]),x.useEffect(()=>{const Ye=xn&&Le!==null&&sn===null;Ve.current=Ye?Le:null,Me.current=Ye,!(typeof window>"u")&&Ye&&Le&&window.sessionStorage.setItem(Dg,Le)},[Le,sn,xn]);const Jn=x.useCallback(async Ye=>{const Nt=Ve.current;if(!Nt||!Me.current)return!1;if(Ye!=null&&Ye.keepalive)return fetch(`/api/orgs/${encodeURIComponent(Nt)}`,{method:"DELETE",credentials:"include",keepalive:!0}),!0;Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg);try{await Xn.remove(Nt)}catch(nn){if(!(nn instanceof Ml)||nn.status!==404)throw nn}return await o.invalidateQueries({queryKey:q.organizations.all}),!0},[o]);x.useEffect(()=>{if(typeof window>"u"||Me.current&&Ve.current!==null)return;const Ye=window.sessionStorage.getItem(Dg);if(!Ye)return;let Nt=!1;return(async()=>{try{try{await Xn.remove(Ye)}catch(nn){if(!(nn instanceof Ml)||nn.status!==404)throw nn}Nt||(window.sessionStorage.removeItem(Dg),await o.invalidateQueries({queryKey:q.organizations.all}))}catch(nn){Nt||M(nn instanceof Error?nn.message:"Failed to rollback the unfinished onboarding draft.")}})(),()=>{Nt=!0}},[g,o]);const{data:$s,error:Ci,isLoading:ar,isFetching:Ts}=Ne({queryKey:Le?q.agents.adapterModels(Le,ae):["agents","none","adapter-models",ae],queryFn:()=>Bt.adapterModels(Le,ae),enabled:!!Le&&g&&w===2}),{data:Gi}=Ne({queryKey:Le?q.agents.nameSuggestion(Le):["agents","none","name-suggestion"],queryFn:()=>Bt.suggestName(Le),enabled:!!Le&&g&&w===2});x.useEffect(()=>{if(w!==2)return;const Ye=(Gi==null?void 0:Gi.name.trim())??"";!Ye||ht.current||$.trim().length>0||(Y(Ye),H(Ye),ht.current=!0)},[$,Gi,w]);const qe=ae==="claude_local"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"||ae==="pi_local"||ae==="cursor",At=xe.trim()||(ae==="codex_local"?"codex":ae==="gemini_local"?"gemini":ae==="pi_local"?"pi":ae==="cursor"?"agent":ae==="opencode_local"?"opencode":"claude");x.useEffect(()=>{w===2&&($e(null),he(null))},[w,ae,fe,xe,X,pe]),x.useEffect(()=>{if(!g)return;const Ye=()=>{Jn({keepalive:!0})};return window.addEventListener("pagehide",Ye),()=>{window.removeEventListener("pagehide",Ye)}},[Jn,g]);const Ft=x.useMemo(()=>c_(ae,$s),[ae,$s]),Pn=Ft.find(Ye=>Ye.id===fe),En=(Ce==null?void 0:Ce.checks.some(Ye=>Ye.code==="claude_anthropic_api_key_overrides_subscription"))??!1,la=ae==="claude_local"&&(Ce==null?void 0:Ce.status)==="fail"&&En,ca=x.useMemo(()=>{const Ye=z.trim().toLowerCase();return Ft.filter(Nt=>{if(!Ye)return!0;const nn=av(Nt.id,"");return Nt.id.toLowerCase().includes(Ye)||Nt.label.toLowerCase().includes(Ye)||nn.toLowerCase().includes(Ye)})},[Ft,z]),Qi=x.useMemo(()=>{if(ae!=="opencode_local")return[{provider:"models",entries:[...ca].sort((Nt,nn)=>Nt.id.localeCompare(nn.id))}];const Ye=new Map;for(const Nt of ca){const nn=av(Nt.id),cr=Ye.get(nn)??[];cr.push(Nt),Ye.set(nn,cr)}return Array.from(Ye.entries()).sort(([Nt],[nn])=>Nt.localeCompare(nn)).map(([Nt,nn])=>({provider:Nt,entries:[...nn].sort((cr,ai)=>cr.id.localeCompare(ai.id))}))},[ca,ae]);function Qa(){N(1),E(!1),M(null),ee(""),F(""),W(!0),Y(""),H(null),ht.current=!1,le("claude_local"),U(""),re(""),ie(""),ke(""),$e(null),he(null),ct(!1),Ae(!1),D(!1),me("Hire your first engineer and create a hiring plan"),je(zre),Ie(null),Je(null),Pt(null),Lt(null),Vt(null),rt(null),tn(null),Se(!1)}async function fl(){if(!_){E(!0),M(null);try{await Jn(),Qa(),n()}catch(Ye){E(!1),M(Ye instanceof Error?Ye.message:"Failed to rollback the unfinished onboarding draft.")}}}function mo(){const Nt=T1(ae).buildAdapterConfig({...yp,agentRuntimeType:ae,model:ae==="codex_local"?fe||J2:ae==="gemini_local"?fe||p5:ae==="cursor"?fe||r6:fe,command:xe,args:X,url:pe,search:ae==="codex_local"?l_:yp.search,dangerouslySkipPermissions:ae==="claude_local",dangerouslyBypassSandbox:ae==="codex_local"?o_:yp.dangerouslyBypassSandbox});if(ae==="claude_local"&&Pe){const nn=typeof Nt.env=="object"&&Nt.env!==null&&!Array.isArray(Nt.env)?{...Nt.env}:{};nn.ANTHROPIC_API_KEY={type:"plain",value:""},Nt.env=nn}return Nt}async function $i(Ye){if(!Le)return N(1),he("Complete organization setup before testing the runtime."),null;ct(!0),he(null);try{const Nt=await Bt.testEnvironment(Le,ae,{agentRuntimeConfig:Ye??mo()});return $e(Nt),Nt}catch(Nt){return he(Nt instanceof Error?Nt.message:"Runtime environment test failed"),null}finally{ct(!1)}}async function Kc(){E(!0),M(null);try{const Ye=!Le,Nt=Le?await Xn.update(Le,{name:Q.trim()}):await Xn.create({name:Q.trim()});if(Ye&&(Ve.current=Nt.id,Me.current=!0,typeof window<"u"&&window.sessionStorage.setItem(Dg,Nt.id)),Ie(Nt.id),Je(Nt.name),Pt(Nt.issuePrefix),Se(nn=>nn||Ye),o.invalidateQueries({queryKey:q.organizations.all}),B.trim()){const nn=axt(B),cr=_t?await Al.update(_t,{title:nn.title,...nn.description?{description:nn.description}:{description:""}}):await Al.create(Nt.id,{title:nn.title,...nn.description?{description:nn.description}:{},level:"organization",status:"active"});Lt(cr.id),o.invalidateQueries({queryKey:q.goals.list(Nt.id)})}N(2),A(nn=>nn>2?nn:2)}catch(Ye){M(Ye instanceof Error?Ye.message:Le?"Failed to update organization":"Failed to create organization")}finally{E(!1)}}async function Te(Ye){const nn=(await ws.list(Ye)).find(ai=>!ai.archivedAt&&ai.name===mR);if(nn)return nn;const cr=await ws.create(Ye,{name:mR,status:"planned",description:null});return o.invalidateQueries({queryKey:q.projects.list(Ye)}),cr}async function De(Ye,Nt=!0){const nn=await Vgt.seedGettingStarted(Ye,{includeTutorial:Nt});return o.invalidateQueries({queryKey:q.projects.list(Ye)}),o.invalidateQueries({queryKey:q.issues.list(Ye)}),o.invalidateQueries({queryKey:q.issues.follows(Ye)}),nn}async function vt(){if(!Le){M("Complete organization setup before creating an agent."),N(1);return}E(!0),M(null);try{const Ye=$.trim();if(!Ye){M("Agent name is required.");return}if(ae==="opencode_local"){const ai=fe.trim();if(!ai){M("OpenCode requires an explicit model in provider/model format.");return}if(Ci){M(Ci instanceof Error?Ci.message:"Failed to load OpenCode models.");return}if(ar||Ts){M("OpenCode models are still loading. Please wait and try again.");return}const Hc=$s??[];if(!Hc.some(Vc=>Vc.id===ai)){M(Hc.length===0?"No OpenCode models discovered. Run `opencode models` and authenticate providers.":`Configured OpenCode model is unavailable: ${ai}`);return}}if(qe&&!(Ce??await $i()))return;const Nt={name:Ye,role:"ceo",agentRuntimeType:ae,agentRuntimeConfig:mo(),runtimeConfig:{heartbeat:{enabled:!0,intervalSec:3600,wakeOnDemand:!0,cooldownSec:10,preflightEnabled:!0,maxConcurrentRuns:gz}}},nn=It?await Bt.update(It,Nt,Le):await Bt.create(Le,Nt);Vt(nn.id),rt(nn.name);const cr=await Xn.get(Le);if(_n(cr),o.invalidateQueries({queryKey:q.agents.list(Le)}),xn){await De(Le,Z),Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg),i(Le),wY(),Qa(),n(),l(cr.issuePrefix?`/${cr.issuePrefix}/dashboard`:"/dashboard");return}N(3),A(ai=>ai>3?ai:3)}catch(Ye){M(Ye instanceof Error?Ye.message:It?"Failed to update agent":"Failed to create agent")}finally{E(!1)}}async function Cn(){if(!Le||oe)return;D(!0),M(null),he(null),Ae(!0);const Ye=(()=>{const Nt=mo(),nn=typeof Nt.env=="object"&&Nt.env!==null&&!Array.isArray(Nt.env)?{...Nt.env}:{};return nn.ANTHROPIC_API_KEY={type:"plain",value:""},Nt.env=nn,Nt})();try{It&&(await Bt.update(It,{agentRuntimeConfig:Ye},Le),o.invalidateQueries({queryKey:q.agents.list(Le)}));const Nt=await $i(Ye);(Nt==null?void 0:Nt.status)==="fail"&&M("Retried with ANTHROPIC_API_KEY unset in adapter config, but the environment test is still failing.")}catch(Nt){M(Nt instanceof Error?Nt.message:"Failed to unset ANTHROPIC_API_KEY and retry.")}finally{D(!1)}}async function mr(){if(!Le){M("Complete organization setup before continuing."),N(1);return}if(!It){M("Create the agent before continuing to task setup."),N(2);return}M(null),N(4),A(4)}async function Yi(){if(!Le){M("Complete organization setup before launching."),N(1);return}if(!It){M("Create the agent before launching."),N(2);return}E(!0),M(null);try{let Ye=sn;if(!Ye){let Nt;xn&&(Nt=(await Te(Le)).id);const nn=await ln.create(Le,{title:ue.trim(),...K.trim()?{description:K.trim()}:{},assigneeAgentId:It,status:"todo",...Nt?{projectId:Nt}:{}});Ye=nn.identifier??nn.id,tn(Ye),o.invalidateQueries({queryKey:q.issues.list(Le)})}Me.current=!1,Ve.current=null,typeof window<"u"&&window.sessionStorage.removeItem(Dg),i(Le),wY(),Qa(),n(),l(kt?`/${kt}/issues/${Ye}`:`/issues/${Ye}`)}catch(Ye){M(Ye instanceof Error?Ye.message:"Failed to create task")}finally{E(!1)}}function ho(Ye){Ye.key==="Enter"&&(Ye.metaKey||Ye.ctrlKey)&&(Ye.preventDefault(),w===1&&Q.trim()?Kc():w===2?vt():w===3&&ue.trim()?mr():w===4&&Yi())}return g?s.jsx(Ws,{open:g,onOpenChange:Ye=>{Ye||(f(!0),fl())},children:s.jsxs(Hme,{children:[s.jsx("div",{className:"fixed inset-0 z-50 bg-background"}),s.jsxs("div",{className:"fixed inset-0 z-50 flex",onKeyDown:ho,children:[s.jsxs("button",{onClick:()=>void fl(),className:G("absolute top-4 right-4 z-10 rounded-full border p-2 transition-colors",w===1?"border-white/15 bg-white/10 text-white/80 backdrop-blur-sm hover:bg-white/15 hover:text-white":"border-border/70 bg-background/85 text-muted-foreground shadow-sm backdrop-blur-sm hover:text-foreground"),children:[s.jsx(Gs,{className:"h-5 w-5"}),s.jsx("span",{className:"sr-only",children:"Close"})," "]}),s.jsxs("div",{className:G("w-full flex flex-col overflow-y-auto transition-[width] duration-500 ease-in-out",w===1?"md:w-1/2":"md:w-full"),children:[s.jsxs("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12 shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-0 mb-8 border-b border-border",children:[[{step:1,label:"Organization",icon:hI},{step:2,label:"Agent",icon:Oi},{step:3,label:"Task",icon:x3},{step:4,label:"Launch",icon:yP}].map(({step:Ye,label:Nt,icon:nn})=>{const cr=Ot(Ye);return s.jsxs("button",{type:"button","data-testid":`onboarding-step-tab-${Ye}`,"aria-current":Ye===w?"step":void 0,"aria-disabled":!cr,disabled:!cr,onClick:()=>{!cr||Ye===w||(M(null),N(Ye))},className:G("flex items-center gap-1.5 px-3 py-2 text-xs font-medium border-b-2 -mb-px transition-colors",Ye===w?"border-foreground text-foreground":cr?"border-transparent text-muted-foreground hover:text-foreground/70 hover:border-border cursor-pointer":"border-transparent text-muted-foreground/45 cursor-not-allowed"),children:[s.jsx(nn,{className:"h-3.5 w-3.5"}),Nt," "]},Ye)})," "]}),w===1&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(hI,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Name your organization"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"This is the organization your agents will work for."})," "]})," "]}),s.jsxs("div",{className:"mt-3 group",children:[s.jsx("label",{className:G("text-xs mb-1 block transition-colors",Q.trim()?"text-foreground":"text-muted-foreground group-focus-within:text-foreground"),children:"Organization name"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"Acme Corp",value:Q,onChange:Ye=>ee(Ye.target.value),autoFocus:!0})," "]}),s.jsxs("div",{className:"group",children:[s.jsx("label",{className:G("text-xs mb-1 block transition-colors",B.trim()?"text-foreground":"text-muted-foreground group-focus-within:text-foreground"),children:"Mission / goal (optional)"}),s.jsx("textarea",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50 resize-none min-h-[60px]",placeholder:"What is this organization trying to achieve?",value:B,onChange:Ye=>F(Ye.target.value)})," "]}),s.jsxs("label",{className:"flex items-start gap-2 rounded-md border border-border/70 px-3 py-2 text-xs",children:[s.jsx(eo,{checked:Z,onCheckedChange:Ye=>W(Ye===!0),className:"mt-0.5"}),s.jsxs("span",{children:[s.jsx("span",{className:"block font-medium text-foreground",children:"I’m new to Rudder"}),s.jsx("span",{className:"block text-muted-foreground",children:"Create guided Getting Started issues. Turn this off to seed only the welcome issue. "})," "]})]})," "]}),w===2&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(Oi,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Create your first agent"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose how this agent will run tasks."})," "]})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Agent name"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"Agent name",value:$,onChange:Ye=>{Y(Ye.target.value),V&&Ye.target.value!==V&&H(null)},autoFocus:!0})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-2 block",children:"Runtime type"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[[{value:"claude_local",label:"Claude Code",icon:Sd,desc:"Local Claude agent",recommended:!0},{value:"codex_local",label:"Codex",icon:Bz,desc:"Local Codex agent",recommended:!0}].map(Ye=>s.jsxs("button",{className:G("flex flex-col items-center gap-1.5 rounded-md border p-3 text-xs transition-colors relative",ae===Ye.value?"border-foreground bg-accent":"border-border hover:bg-accent/50"),onClick:()=>{const Nt=Ye.value;le(Nt),Nt==="codex_local"&&!fe&&U(J2),Nt!=="codex_local"&&U("")},children:[Ye.recommended&&s.jsx("span",{className:"absolute -top-1.5 right-1.5 bg-green-500 text-white text-[9px] font-semibold px-1.5 py-0.5 rounded-full leading-none",children:"Recommended "}),s.jsx(Ye.icon,{className:"h-4 w-4"}),s.jsx("span",{className:"font-medium",children:Ye.label}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[Ye.desc," "]})," "]},Ye.value))," "]}),s.jsxs("button",{className:"flex items-center gap-1.5 mt-3 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>de(Ye=>!Ye),children:[s.jsx(fr,{className:G("h-3 w-3 transition-transform",J?"rotate-0":"-rotate-90")}),"More Agent Runtime Types "]}),J&&s.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-2",children:[[{value:"gemini_local",label:"Gemini CLI",icon:Uz,desc:"Local Gemini agent"},{value:"opencode_local",label:"OpenCode",icon:iC,desc:"Local multi-provider agent"},{value:"pi_local",label:"Pi",icon:y7,desc:"Local Pi agent"},{value:"cursor",label:"Cursor",icon:Rme,desc:"Local Cursor agent"},{value:"openclaw_gateway",label:"OpenClaw Gateway",icon:Oi,desc:"Invoke OpenClaw via gateway protocol",comingSoon:!0,disabledLabel:"Configure OpenClaw within the App"}].map(Ye=>s.jsxs("button",{disabled:!!Ye.comingSoon,className:G("flex flex-col items-center gap-1.5 rounded-md border p-3 text-xs transition-colors relative",Ye.comingSoon?"border-border opacity-40 cursor-not-allowed":ae===Ye.value?"border-foreground bg-accent":"border-border hover:bg-accent/50"),onClick:()=>{if(Ye.comingSoon)return;const Nt=Ye.value;if(le(Nt),Nt==="gemini_local"&&!fe){U(p5);return}if(Nt==="cursor"&&!fe){U(r6);return}if(Nt==="opencode_local"){fe.includes("/")||U("");return}U("")},children:[s.jsx(Ye.icon,{className:"h-4 w-4"}),s.jsx("span",{className:"font-medium",children:Ye.label}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[Ye.comingSoon?Ye.disabledLabel??"Coming soon":Ye.desc," "]})," "]},Ye.value))," "]})," "]}),(ae==="claude_local"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"||ae==="pi_local"||ae==="cursor")&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Model"}),s.jsxs(qn,{open:O,onOpenChange:Ye=>{P(Ye),Ye||L("")},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[s.jsxs("span",{className:G(!fe&&"text-muted-foreground"),children:[Pn?Pn.label:fe||(ae==="opencode_local"?"Select model (required)":"Default")," "]}),s.jsx(fr,{className:"h-3 w-3 text-muted-foreground"})," "]})}),s.jsxs(Kn,{className:"w-[var(--radix-popover-trigger-width)] p-1",align:"start",children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search models...",value:z,onChange:Ye=>L(Ye.target.value),autoFocus:!0}),ae!=="opencode_local"&&s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!fe&&"bg-accent"),onClick:()=>{U(""),P(!1)},children:"Default "}),s.jsxs("div",{className:"max-h-[240px] overflow-y-auto",children:[Qi.map(Ye=>s.jsxs("div",{className:"mb-1 last:mb-0",children:[ae==="opencode_local"&&s.jsxs("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:[Ye.provider," (",Ye.entries.length,") "]}),Ye.entries.map(Nt=>s.jsxs("button",{className:G("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",Nt.id===fe&&"bg-accent"),onClick:()=>{U(Nt.id),P(!1)},children:[s.jsxs("span",{className:"block w-full text-left truncate",title:Nt.id,children:[ae==="opencode_local"?Phe(Nt.id):Nt.label," "]})," "]},Nt.id))," "]},Ye.provider))," "]}),ca.length===0&&s.jsx("p",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:ar||Ts?"Loading models...":"No models discovered."})]})]})," "]})," "]}),qe&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs font-medium",children:"Runtime environment check"}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Runs a live probe that asks the runtime CLI to respond with hello."})," "]}),s.jsx(ce,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",disabled:!$t||We,onClick:()=>void $i(),children:We?"Testing...":"Test now"})," "]}),Ue&&s.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-2.5 py-2 text-[11px] text-destructive",children:[Ue," "]}),Ce&&Ce.status==="pass"?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10 px-3 py-2 text-xs text-green-700 dark:text-green-300 animate-in fade-in slide-in-from-bottom-1 duration-300",children:[s.jsx(gs,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-medium",children:"Passed"})," "]}):Ce?s.jsx(Pxt,{result:Ce}):null,la&&s.jsxs("div",{className:"rounded-md border border-amber-300/60 bg-amber-50/40 px-2.5 py-2 space-y-2",children:[s.jsxs("p",{className:"text-[11px] text-amber-900/90 leading-relaxed",children:["Claude failed while"," ",s.jsx("span",{className:"font-mono",children:"ANTHROPIC_API_KEY"})," ","is set. You can clear it in this CEO adapter config and retry the probe."]}),s.jsx(ce,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",disabled:We||oe,onClick:()=>void Cn(),children:oe?"Retrying...":"Unset ANTHROPIC_API_KEY"})," "]}),Ce&&Ce.status==="fail"&&s.jsxs("div",{className:"rounded-md border border-border/70 bg-muted/20 px-2.5 py-2 text-[11px] space-y-1.5",children:[s.jsx("p",{className:"font-medium",children:"Manual debug"}),s.jsx("p",{className:"text-muted-foreground font-mono break-all",children:ae==="cursor"?`${At} -p --mode ask --output-format json "Respond with hello."`:ae==="codex_local"?`${At} exec --json -`:ae==="gemini_local"?`${At} --output-format json "Respond with hello."`:ae==="opencode_local"?`${At} run --format json "Respond with hello."`:`${At} --print - --output-format stream-json --verbose`}),s.jsxs("p",{className:"text-muted-foreground",children:["Prompt:"," ",s.jsx("span",{className:"font-mono",children:"Respond with hello."})]}),ae==="cursor"||ae==="codex_local"||ae==="gemini_local"||ae==="opencode_local"?s.jsxs("p",{className:"text-muted-foreground",children:["If auth fails, set"," ",s.jsx("span",{className:"font-mono",children:ae==="cursor"?"CURSOR_API_KEY":ae==="gemini_local"?"GEMINI_API_KEY":"OPENAI_API_KEY"})," ","in env or run"," ",s.jsxs("span",{className:"font-mono",children:[ae==="cursor"?"agent login":ae==="codex_local"?"codex login":ae==="gemini_local"?"gemini auth":"opencode auth login"," "]}),"."]}):s.jsxs("p",{className:"text-muted-foreground",children:["If login is required, run"," ",s.jsx("span",{className:"font-mono",children:"claude auth login"})," ","and retry."]})," "]})," "]}),(ae==="http"||ae==="openclaw_gateway")&&s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:ae==="openclaw_gateway"?"Gateway URL":"Webhook URL"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm font-mono outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:ae==="openclaw_gateway"?"ws://127.0.0.1:18789":"https://...",value:pe,onChange:Ye=>ke(Ye.target.value)})," "]})," "]}),w===3&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(x3,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Give it something to do"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Give your agent a small task to start with — a bug fix, a research question, writing a script."})," "]})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Task title"}),s.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",placeholder:"e.g. Research competitor pricing",value:ue,onChange:Ye=>me(Ye.target.value),autoFocus:!0})," "]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Description (optional)"}),s.jsx("textarea",{ref:Be,className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50 resize-none min-h-[120px] max-h-[300px] overflow-y-auto",placeholder:"Add more detail about what the agent should do...",value:K,onChange:Ye=>je(Ye.target.value)})," "]})," "]}),w===4&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[s.jsxs("div",{className:"bg-muted/50 p-2",children:[s.jsx(yP,{className:"h-5 w-5 text-muted-foreground"})," "]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Ready to launch"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:Ze})," "]})," "]}),s.jsxs("div",{className:"border border-border divide-y divide-border",children:[s.jsxs("div",{"data-testid":"onboarding-launch-summary-organization",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(hI,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:$t?st:"Organization setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Organization"})," "]}),$t?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]}),s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(Oi,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:Nn?(Sn??$.trim())||"Agent":"Agent setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:Nn?T1(ae).label:"Agent"})," "]}),Nn?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]}),xn?s.jsxs("div",{"data-testid":"onboarding-launch-summary-project",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(r4,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:mR}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Project"})," "]}),s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"})," "]}):null,s.jsxs("div",{"data-testid":"onboarding-launch-summary-task",className:"flex items-center gap-3 px-3 py-2.5",children:[s.jsx(x3,{className:"h-4 w-4 text-muted-foreground shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:Ee?ue:"Task setup incomplete"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Task"})," "]}),Ee?s.jsx(gs,{className:"h-4 w-4 text-green-500 shrink-0"}):null," "]})," "]})," "]}),T&&s.jsxs("div",{className:"mt-3",children:[s.jsx("p",{className:"text-xs text-destructive",children:T})," "]}),s.jsxs("div",{className:"flex items-center justify-between mt-8",children:[s.jsxs("div",{children:[un!==null&&s.jsxs(ce,{variant:"ghost",size:"sm",onClick:()=>{M(null),N(un)},disabled:_,children:[s.jsx(O1,{className:"h-3.5 w-3.5 mr-1"}),"Back"]})," "]}),s.jsxs("div",{className:"flex items-center gap-2",children:[w===1&&s.jsxs(ce,{size:"sm",disabled:!Q.trim()||_,onClick:Kc,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Next"]}),w===2&&s.jsxs(ce,{size:"sm",disabled:_||We,onClick:vt,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":xn?"Create & Open Dashboard":"Next"]}),w===3&&s.jsxs(ce,{size:"sm",disabled:!ue.trim()||_,onClick:mr,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Next"]}),w===4&&s.jsxs(ce,{size:"sm",disabled:_,onClick:Yi,children:[_?s.jsx(yr,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):s.jsx(Qh,{className:"h-3.5 w-3.5 mr-1"}),_?"Creating...":"Create & Open Issue"]})," "]})," "]})," "]})," "]}),s.jsxs("div",{className:G("hidden md:block overflow-hidden bg-[#1d1d1d] transition-[width,opacity] duration-500 ease-in-out",w===1?"w-1/2 opacity-100":"w-0 opacity-0"),children:[s.jsx(yve,{})," "]})," "]})]})}):null}const xA={info:"border-sky-300 bg-sky-50 text-sky-900 dark:border-sky-500/25 dark:bg-sky-950/60 dark:text-sky-100",warn:"border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-500/25 dark:bg-amber-950/60 dark:text-amber-100",error:"border-red-300 bg-red-50 text-red-900 dark:border-red-500/30 dark:bg-red-950/60 dark:text-red-100"},bA={info:"border-sky-300/80 bg-sky-50/90 text-sky-800 dark:border-sky-500/25 dark:bg-sky-950/40 dark:text-sky-200",success:"border-emerald-300/80 bg-emerald-50/90 text-emerald-800 dark:border-emerald-500/25 dark:bg-emerald-950/40 dark:text-emerald-200",warn:"border-amber-300/80 bg-amber-50/90 text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/40 dark:text-amber-200",error:"border-red-300/80 bg-red-50/90 text-red-800 dark:border-red-500/30 dark:bg-red-950/40 dark:text-red-200"},c2={info:"text-sky-800 dark:text-sky-200",success:"text-emerald-800 dark:text-emerald-200",warn:"text-amber-800 dark:text-amber-200",error:"text-red-800 dark:text-red-200"},Lxt={info:"bg-sky-500 dark:bg-sky-400",success:"bg-emerald-500 dark:bg-emerald-400",warn:"bg-amber-500 dark:bg-amber-400",error:"bg-red-500 dark:bg-red-400"};function $xt({toast:e}){return e.icon==="download"?s.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-sm)] bg-muted text-muted-foreground",children:s.jsx(Kf,{className:"h-4 w-4"})}):s.jsx("span",{className:G("mt-2 h-2 w-2 shrink-0 rounded-full",Lxt[e.tone])})}function Fxt({toast:e,onDismiss:t}){if(!e.action)return null;const n=G("mt-2 inline-flex h-8 items-center justify-center rounded-[var(--radius-sm)] px-3 text-xs font-semibold transition-colors",e.icon==="download"?"bg-foreground text-background hover:bg-foreground/90":G("underline-offset-4 hover:opacity-90",c2[e.tone]));return e.action.onClick?s.jsx("button",{type:"button",onClick:()=>{var r,i;(i=(r=e.action)==null?void 0:r.onClick)==null||i.call(r),t(e.id)},className:n,children:e.action.label}):e.action.href?s.jsx(yt,{to:e.action.href,onClick:()=>t(e.id),className:n,children:e.action.label}):null}function zxt({toast:e,onDismiss:t}){const[n,r]=x.useState(!1);return x.useEffect(()=>{const i=requestAnimationFrame(()=>r(!0));return()=>cancelAnimationFrame(i)},[]),s.jsx("li",{className:G("pointer-events-auto overflow-hidden rounded-[var(--radius-md)] border border-border/70 bg-popover text-popover-foreground shadow-[0_16px_40px_rgba(15,23,42,0.16)] backdrop-blur-xl transition-[transform,opacity] duration-200 ease-out dark:shadow-[0_16px_44px_rgba(0,0,0,0.45)]",n?"translate-y-0 opacity-100":"translate-y-3 opacity-0"),children:s.jsxs("div",{className:"flex items-start gap-3 px-3.5 py-3",children:[s.jsx($xt,{toast:e}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm font-semibold leading-5",children:e.title}),e.body&&s.jsx("p",{className:"mt-0.5 text-xs leading-4 text-muted-foreground",children:e.body}),s.jsx(Fxt,{toast:e,onDismiss:t})]}),s.jsx("button",{type:"button","aria-label":"Dismiss notification",onClick:()=>t(e.id),className:"-mr-1 -mt-1 shrink-0 rounded-[var(--radius-sm)] p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})}function Bxt(){const{toasts:e,dismissToast:t}=_r();if(e.length===0)return null;const n=s.jsx("aside",{"aria-live":"polite","aria-atomic":"false",className:"pointer-events-none fixed bottom-4 right-4 z-[1000] w-[min(calc(100vw-2rem),20rem)]",children:s.jsx("ol",{className:"flex w-full flex-col-reverse gap-2",children:e.map(r=>s.jsx(zxt,{toast:r,onDismiss:t},r.id))})});return typeof document>"u"?n:oo.createPortal(n,document.body)}const Cve=x.createContext(null),Uxt={progress:null,dismissProgress:()=>{}};function qxt({children:e}){const[t,n]=x.useState(null),[r,i]=x.useState(null);x.useEffect(()=>{var c,u;const l=bs();if(l)return(c=l.getUpdateProgress)==null||c.call(l).then(d=>{d&&n(d)}).catch(()=>{}),(u=l.onUpdateProgress)==null?void 0:u.call(l,d=>{n(d),i(f=>f===d.updateId&&d.phase!=="failed"?f:null)})},[]);const a=(t==null?void 0:t.updateId)===r?null:t,o=x.useMemo(()=>({progress:a,dismissProgress:()=>{t&&i(t.updateId)}}),[t,a]);return s.jsx(Cve.Provider,{value:o,children:e})}function Sve(){return x.useContext(Cve)??Uxt}const Kre="https://github.com/Undertone0809/rudder/releases",Hre={starting:"about.updates.progress.phase.starting",resolving_release:"about.updates.progress.phase.resolving_release",downloading_checksums:"about.updates.progress.phase.downloading_checksums",downloading_asset:"about.updates.progress.phase.downloading_asset",verifying_checksum:"about.updates.progress.phase.verifying_checksum",ready_to_install:"about.updates.progress.phase.ready_to_install",waiting_for_active_runs:"about.updates.progress.phase.waiting_for_active_runs",preparing_restart:"about.updates.progress.phase.preparing_restart",closing:"about.updates.progress.phase.closing",failed:"about.updates.progress.phase.failed"};function Vre(e){if(typeof e!="number"||!Number.isFinite(e))return null;const t=["B","KB","MB","GB"];let n=Math.max(0,e),r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return r===0?`${Math.round(n)} ${t[r]}`:`${n.toFixed(1)} ${t[r]}`}function Kxt(e){return e==="failed"?"failed":e==="ready_to_install"||e==="closing"?"ready":"active"}function Hxt(){const{progress:e,dismissProgress:t}=Sve(),{t:n}=Es(),[r,i]=x.useState(null),[a,o]=x.useState(!1);if(!e)return null;const l=e,c=Kxt(l.phase),u=Vre(l.transferredBytes),d=Vre(l.totalBytes),f=typeof l.percent=="number"?Math.max(0,Math.min(100,l.percent)):null,h=f!==null,g=f!==null?`${f}%`:u?d?`${u} / ${d}`:u:null,b=c==="active"&&!h;async function v(){const w=bs();w&&(i(null),await w.installUpdate(l.version))}async function j(){const w=bs();if(i(null),!(w!=null&&w.applyUpdate)){i(n("about.updates.installUnavailable"));return}o(!0);try{const N=await w.applyUpdate(l.updateId);N.status!=="started"&&i(N.message||n("about.updates.installFailed"))}catch(N){i(N instanceof Error?N.message:n("about.updates.installFailed"))}finally{o(!1)}}async function k(){const w=bs();w?await w.openExternal(Kre):window.open(Kre,"_blank","noopener,noreferrer")}return s.jsx("aside",{"aria-live":"polite",className:"pointer-events-none fixed bottom-[calc(1rem+5.75rem)] right-4 z-[1001] w-[min(calc(100vw-2rem),20rem)] md:bottom-4",children:s.jsx("div",{className:G("pointer-events-auto overflow-hidden rounded-[var(--radius-md)] border bg-popover text-popover-foreground shadow-[0_16px_40px_rgba(15,23,42,0.16)] backdrop-blur-xl dark:shadow-[0_16px_44px_rgba(0,0,0,0.45)]",c==="failed"?"border-destructive/35":"border-border/70"),children:s.jsxs("div",{className:"flex items-start gap-3 px-3.5 py-3",children:[s.jsx("span",{className:G("flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-sm)] bg-muted text-muted-foreground",c==="failed"&&"bg-destructive/10 text-destructive",c==="ready"&&"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"),children:c==="failed"?s.jsx(Ad,{className:"h-4 w-4"}):c==="ready"?s.jsx(Mo,{className:"h-4 w-4"}):s.jsx(Kf,{className:"h-4 w-4"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("p",{className:"text-sm font-semibold leading-5",children:c==="failed"?n("about.updates.progress.failedTitle"):l.phase==="ready_to_install"?n("about.updates.progress.readyTitle"):n("about.updates.progress.title",{version:l.version.startsWith("v")?l.version:`v${l.version}`})}),g?s.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:g}):null]}),s.jsx("p",{className:"mt-0.5 text-xs leading-4 text-muted-foreground",children:l.error??n(Hre[l.phase])}),r?s.jsx("p",{className:"mt-2 rounded-[var(--radius-sm)] border border-destructive/25 bg-destructive/8 px-2.5 py-2 text-xs leading-4 text-destructive",children:r}):null,h?s.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-muted",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":f,children:s.jsx("div",{className:G("h-full rounded-full bg-emerald-700 transition-[width] duration-300",c==="failed"&&"bg-destructive"),style:{width:`${f}%`}})}):b?s.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-muted",role:"progressbar","aria-label":n(Hre[l.phase]),children:s.jsx("div",{className:"h-full w-2/5 rounded-full bg-emerald-700/70 animate-pulse"})}):null,l.phase==="ready_to_install"?s.jsx("div",{className:"mt-2",children:s.jsx(ce,{type:"button",size:"sm",className:"h-8 px-3 text-xs",disabled:a,onClick:()=>void j(),children:n(a?"about.updates.installing":"about.updates.progress.restartToUpdate")})}):null,c==="failed"?s.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[s.jsx(ce,{type:"button",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>void v(),children:n("about.updates.progress.retry")}),s.jsx(ce,{type:"button",variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>void k(),children:n("about.updates.progress.openReleases")})]}):null]}),s.jsx("button",{type:"button","aria-label":n("about.updates.progress.dismiss"),onClick:t,className:"-mr-1 -mt-1 shrink-0 rounded-[var(--radius-sm)] p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})})}function nf(e,t,n){const r=new URLSearchParams;e&&r.set("from",e),t&&r.set("to",t);for(const[a,o]of Object.entries(n??{}))o&&r.set(a,o);const i=r.toString();return i?`?${i}`:""}const Qo={summary:(e,t,n)=>_e.get(`/orgs/${e}/costs/summary${nf(t,n)}`),byAgent:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-agent${nf(t,n)}`),trend:(e,t,n,r)=>_e.get(`/orgs/${e}/costs/trend${nf(t,n,r)}`),byAgentModel:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-agent-model${nf(t,n)}`),byProject:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-project${nf(t,n)}`),byProvider:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-provider${nf(t,n)}`),byBiller:(e,t,n)=>_e.get(`/orgs/${e}/costs/by-biller${nf(t,n)}`),financeSummary:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-summary${nf(t,n)}`),financeByBiller:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-by-biller${nf(t,n)}`),financeByKind:(e,t,n)=>_e.get(`/orgs/${e}/costs/finance-by-kind${nf(t,n)}`),financeEvents:(e,t,n,r=100)=>_e.get(`/orgs/${e}/costs/finance-events${Vxt(t,n,r)}`),windowSpend:e=>_e.get(`/orgs/${e}/costs/window-spend`),quotaWindows:e=>_e.get(`/orgs/${e}/costs/quota-windows`)};function Vxt(e,t,n){const r=new URLSearchParams;e&&r.set("from",e),t&&r.set("to",t),n&&r.set("limit",String(n));const i=r.toString();return i?`?${i}`:""}const l1={list:(e,t)=>{const n=new URLSearchParams;t!=null&&t.entityType&&n.set("entityType",t.entityType),t!=null&&t.entityId&&n.set("entityId",t.entityId),t!=null&&t.agentId&&n.set("agentId",t.agentId),t!=null&&t.userId&&n.set("userId",t.userId),t!=null&&t.actorType&&n.set("actorType",t.actorType),t!=null&&t.actorId&&n.set("actorId",t.actorId);const r=n.toString();return _e.get(`/orgs/${e}/activity${r?`?${r}`:""}`)},forIssue:e=>_e.get(`/issues/${e}/activity`),runsForIssue:e=>_e.get(`/issues/${e}/runs`),issuesForRun:e=>_e.get(`/heartbeat-runs/${e}/issues`)},Wxt="You";function zK(e,t=Wxt){return(e==null?void 0:e.trim())||t}function i8(){const{data:e}=Ne({queryKey:q.instance.profileSettings,queryFn:()=>ka.getProfile(),staleTime:qi});return zK(e==null?void 0:e.nickname)}function Zxt(e,t){var a;const n=t.match(/\d/g)??[],r=((a=e.match(/\d/g))==null?void 0:a.length)??0;let i=0;return Array.from(e).map((o,l,c)=>{if(!/\d/.test(o))return{key:`${l}-${o}`,current:o,previous:o,isDigit:!1};const d=r-1-i,f=n[n.length-1-d]??o;return i+=1,{key:`${c.length-l}-${o}`,current:o,previous:f,isDigit:!0}})}function Gxt({value:e}){const t=String(e),n=x.useRef(t),r=x.useRef(t),[i,a]=x.useState(0);x.useEffect(()=>{t!==n.current&&(r.current=n.current,n.current=t,a(l=>l+1))},[t]);const o=x.useMemo(()=>Zxt(t,r.current),[t,i]);return s.jsx("span",{"aria-label":t,className:"metric-value-motion","data-animated":i>0?"true":"false",children:o.map((l,c)=>l.isDigit?s.jsx("span",{"aria-hidden":"true",className:"metric-digit-window",style:{"--metric-glyph-index":c},children:s.jsxs("span",{className:"metric-digit-stack",children:[s.jsx("span",{children:l.previous}),s.jsx("span",{children:l.current})]})},`${i}-${l.key}`):s.jsx("span",{"aria-hidden":"true",className:"metric-symbol",style:{"--metric-glyph-index":c},children:l.current},`${i}-${l.key}`))})}function El({icon:e,value:t,label:n,description:r,to:i,onClick:a}){const o=!!(i||a),l=s.jsx("div",{className:G("surface-panel h-full rounded-[var(--radius-lg)] px-4 py-4 sm:px-5 sm:py-5 transition-[background-color,border-color,transform]",o&&"cursor-pointer hover:surface-active"),children:s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-2xl sm:text-3xl font-semibold tracking-tight tabular-nums text-foreground",children:s.jsx(Gxt,{value:t})}),s.jsx("p",{className:"mt-1 text-xs font-medium tracking-[0.06em] text-muted-foreground sm:text-sm",children:n}),r&&s.jsx("div",{className:"mt-2 hidden text-xs leading-5 text-muted-foreground/85 sm:block",children:r})]}),s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-[calc(var(--radius-sm)+2px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-inset)_92%,transparent)]",children:s.jsx(e,{className:"h-4 w-4 text-[color:var(--accent-strong)]"})})]})});return i?s.jsx(yt,{to:i,className:"no-underline text-inherit h-full",onClick:a,children:l}):a?s.jsx("div",{className:"h-full",onClick:a,children:l}):l}function Fr({icon:e,message:t,action:n,onAction:r,className:i}){return s.jsxs("div",{className:G("surface-panel mx-auto flex max-w-xl flex-col items-center justify-center rounded-[var(--radius-xl)] px-8 py-14 text-center",i),children:[s.jsx("div",{className:"mb-5 flex h-16 w-16 items-center justify-center rounded-[calc(var(--radius-md)+4px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-proposal)_72%,transparent)]",children:s.jsx(e,{className:"h-8 w-8 text-[color:var(--accent-base)]"})}),s.jsx("p",{className:"font-display text-[1.5rem] leading-tight text-foreground",children:"Nothing here yet"}),s.jsx("p",{className:"mt-3 max-w-md text-sm leading-6 text-muted-foreground",children:t}),n&&r&&s.jsxs(ce,{onClick:r,className:"mt-6",children:[s.jsx(tr,{className:"h-4 w-4 mr-1.5"}),n]})]})}function Qxt(e){const t=e.replace(/\s*\([^)]*\)\s*/g," ").trim()||e.trim(),n=t.split(/\s+/);return n.length>=2?(n[0][0]+n[n.length-1][0]).toUpperCase():t.slice(0,2).toUpperCase()}const Yxt={xs:"text-sm",sm:"text-xs",default:"text-sm",lg:"text-sm"};function Da({name:e,avatarUrl:t,initials:n,size:r="default",className:i}){const a=n??Qxt(e);return s.jsxs("span",{className:G("inline-flex gap-1.5",r==="xs"?"items-baseline gap-1":"items-center",r==="lg"&&"gap-2",i),children:[s.jsxs(vl,{size:r,className:r==="xs"?"relative -top-px":void 0,children:[t&&s.jsx(GKe,{src:t,alt:e}),s.jsx(wl,{children:a})]}),s.jsx("span",{className:G("truncate",Yxt[r]),children:e})]})}function a8(e,t,n,r){return e==="system"?"System":e==="user"?n&&t===n?zK(r):"Board":t||"Unknown"}function Jxt(e,t,n,r){var i;return e.actorType==="agent"?((i=t.get(e.actorId))==null?void 0:i.name)??e.actorId??"Unknown":a8(e.actorType,e.actorId,n,r)}const b$=60,y$=60*b$,bC=24*y$,Wre=7*bC,Zre=30*bC;function I1(e){const t=tm(),n=Date.now(),r=new Date(e).getTime(),i=Math.round((n-r)/1e3);if(i<b$)return t==="zh-CN"?"刚刚":"just now";if(i<y$){const o=Math.floor(i/b$);return t==="zh-CN"?`${o} 分钟前`:`${o}m ago`}if(i<bC){const o=Math.floor(i/y$);return t==="zh-CN"?`${o} 小时前`:`${o}h ago`}if(i<Wre){const o=Math.floor(i/bC);return t==="zh-CN"?`${o} 天前`:`${o}d ago`}if(i<Zre){const o=Math.floor(i/Wre);return t==="zh-CN"?`${o} 周前`:`${o}w ago`}const a=Math.floor(i/Zre);return t==="zh-CN"?Ha(e):`${a}mo ago`}const Xxt={"issue.created":"created","issue.updated":"updated","issue.checked_out":"checked out","issue.released":"released","issue.comment_added":"commented on","issue.code_committed":"committed","issue.attachment_added":"attached file to","issue.attachment_removed":"removed attachment from","issue.document_created":"created document for","issue.document_updated":"updated document on","issue.document_deleted":"deleted document from","issue.commented":"commented on","issue.human_intervention_required":"requested human intervention on","issue.deleted":"deleted","agent.created":"created","agent.updated":"updated","agent.paused":"paused","agent.resumed":"resumed","agent.terminated":"terminated","agent.key_created":"created API key for","agent.budget_updated":"updated budget for","agent.runtime_session_reset":"reset session for","heartbeat.invoked":"invoked heartbeat for","heartbeat.cancelled":"cancelled heartbeat for","approval.created":"requested approval","approval.approved":"approved","approval.rejected":"rejected","project.created":"created","project.updated":"updated","project.deleted":"deleted","goal.created":"created","goal.updated":"updated","goal.deleted":"deleted","cost.reported":"reported cost for","cost.recorded":"recorded cost for","organization.created":"created organization","organization.updated":"updated organization","organization.archived":"archived","organization.budget_updated":"updated budget for"};function Dx(e){return typeof e!="string"?String(e??"none"):e.replace(/_/g," ")}function e3t(e,t){if(e==="issue.code_committed"&&t){const n=typeof t.shortSha=="string"?t.shortSha:null,r=typeof t.subject=="string"?t.subject:null;if(n&&r)return`committed ${n}: ${r} to`;if(n)return`committed ${n} to`}if(e==="issue.updated"&&t){const n=t._previous??{};if(t.status!==void 0){const r=n.status;return r?`changed status from ${Dx(r)} to ${Dx(t.status)} on`:`changed status to ${Dx(t.status)} on`}if(t.priority!==void 0){const r=n.priority;return r?`changed priority from ${Lo(Dx(r))} to ${Lo(Dx(t.priority))} on`:`changed priority to ${Lo(Dx(t.priority))} on`}}return Xxt[e]??e.replace(/[._]/g," ")}function t3t(e,t,n){switch(e){case"issue":return`/issues/${n??t}`;case"agent":return`/agents/${t}`;case"project":return`/projects/${Iz(n,t)}`;case"goal":return`/goals/${t}`;case"approval":return`/messenger/approvals/${t}`;default:return null}}function n3t(e){switch(e){case"goal":return"goal";case"project":return"project";case"approval":return"approval";default:return null}}function BK({event:e,agentMap:t,entityNameMap:n,entityTitleMap:r,className:i,currentBoardUserId:a,operatorDisplayName:o}){var N,C;const l=e3t(e.action,e.details),c=e.entityType==="heartbeat_run",u=c?(N=e.details)==null?void 0:N.agentId:void 0,d=c?u?n.get(`agent:${u}`):null:n.get(`${e.entityType}:${e.entityId}`),f=typeof((C=e.details)==null?void 0:C.title)=="string"?e.details.title:null,h=(r==null?void 0:r.get(`${e.entityType}:${e.entityId}`))??f,g=c&&u?`/agents/${u}/runs/${e.entityId}`:t3t(e.entityType,e.entityId,d),b=e.actorType==="agent"?t.get(e.actorId):null,v=(b==null?void 0:b.name)??Jxt(e,t,a,o),j=n3t(e.entityType),k=s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("p",{className:"flex-1 min-w-0 truncate",children:[b?s.jsx(Za,{name:v,icon:b.icon,role:b.role,size:"xs",className:"align-baseline"}):s.jsx(Da,{name:v,size:"xs",className:"align-baseline"}),s.jsxs("span",{className:"text-muted-foreground ml-1",children:[l," "]}),j&&s.jsxs("span",{className:"text-muted-foreground",children:[j," "]}),d&&s.jsx("span",{className:"font-medium",children:d}),h&&h!==d&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["— ",h]})]}),s.jsx("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:I1(e.createdAt)})]}),w=G("px-4 py-2 text-sm",g&&"cursor-pointer hover:bg-accent/50 transition-colors",i);return g?s.jsx(yt,{to:g,className:G(w,"no-underline text-inherit block"),children:k}):s.jsx("div",{className:w,children:k})}const r3t=2e3,s3t=256e3;function i3t(e){return new TextEncoder().encode(e).length}function Xu(e){return typeof e=="string"&&e.trim().length>0?e:null}function a3t(e){return!e||typeof e!="object"?null:Xu(e.summary)}function Gre(e){const t=Xu(e.stdoutExcerpt)??a3t(e.resultJson);return t?[{kind:"assistant",ts:e.finishedAt??e.startedAt??e.createdAt,text:t}]:[]}function Qre(e){return e==="failed"||e==="timed_out"||e==="cancelled"||e==="succeeded"}function o3t(e,t,n){if(!t)return[];const r=`${e}:records`,a=`${n.get(r)??""}${t}`.split(`
|
|
1351
1351
|
`);n.set(r,a.pop()??"");const o=[];for(const l of a){const c=l.trim();if(c)try{const u=JSON.parse(c),d=u.stream==="stderr"||u.stream==="system"?u.stream:"stdout",f=typeof u.chunk=="string"?u.chunk:"",h=typeof u.ts=="string"?u.ts:new Date().toISOString();if(!f)continue;o.push({ts:h,stream:d,chunk:f,dedupeKey:`log:${e}:${h}:${d}:${f}`})}catch{}}return o}function o8({runs:e,orgId:t,maxChunksPerRun:n=200,includeRunEvents:r=!0}){const[i,a]=x.useState(new Map),o=x.useRef(new Set),l=x.useRef(new Map),c=x.useRef(new Map),{data:u}=Ne({queryKey:q.instance.generalSettings,queryFn:()=>ka.getGeneral()}),d=x.useMemo(()=>new Map(e.map(v=>[v.id,v])),[e]),f=x.useMemo(()=>new Set(e.filter(v=>!Qre(v.status)).map(v=>v.id)),[e]),h=x.useMemo(()=>e.map(v=>v.id).sort((v,j)=>v.localeCompare(j)).join(","),[e]),g=(v,j)=>{j.length!==0&&a(k=>{const w=new Map(k),N=[...w.get(v)??[]];let C=!1;for(const A of j)o.current.has(A.dedupeKey)||(o.current.add(A.dedupeKey),N.push({ts:A.ts,stream:A.stream,chunk:A.chunk}),C=!0);return C?(o.current.size>12e3&&o.current.clear(),w.set(v,N.slice(-n)),w):k})};return x.useEffect(()=>{const v=new Set(e.map(j=>j.id));a(j=>{const k=new Map;for(const[w,N]of j)v.has(w)&&k.set(w,N);return k.size===j.size?j:k});for(const j of l.current.keys()){const k=j.replace(/:records$/,"");v.has(k)||l.current.delete(j)}for(const j of c.current.keys())v.has(j)||c.current.delete(j)},[e]),x.useEffect(()=>{if(e.length===0)return;let v=!1;const j=async N=>{const C=c.current.get(N.id)??0;try{const A=await xs.log(N.id,C,s3t);if(v)return;if(g(N.id,o3t(N.id,A.content,l.current)),A.nextOffset!==void 0){c.current.set(N.id,A.nextOffset);return}if(A.endOffset!==void 0){c.current.set(N.id,A.endOffset);return}A.content.length>0&&c.current.set(N.id,C+i3t(A.content))}catch{}},k=async()=>{await Promise.all(e.map(N=>j(N)))};k();const w=window.setInterval(()=>{k()},r3t);return()=>{v=!0,window.clearInterval(w)}},[h,e]),x.useEffect(()=>{if(!t||f.size===0)return;let v=!1,j=null,k=null;const w=()=>{v||(j=window.setTimeout(N,1500))},N=()=>{if(v)return;const A=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/orgs/${encodeURIComponent(t)}/events/ws`;k=new WebSocket(A),k.onmessage=_=>{const E=typeof _.data=="string"?_.data:"";if(!E)return;let T;try{T=JSON.parse(E)}catch{return}if(T.orgId!==t)return;const M=T.payload??{},O=Xu(M.runId);if(!(!O||!f.has(O))&&d.has(O)){if(T.type==="heartbeat.run.log"){if(M.truncated===!0)return;const P=Xu(M.chunk);if(!P)return;const z=Xu(M.ts)??T.createdAt,L=Xu(M.stream)==="stderr"?"stderr":Xu(M.stream)==="system"?"system":"stdout";g(O,[{ts:z,stream:L,chunk:P,dedupeKey:`log:${O}:${z}:${L}:${P}`}]);return}if(r&&T.type==="heartbeat.run.event"){const P=typeof M.seq=="number"?M.seq:null,z=Xu(M.eventType)??"event",L=Xu(M.message)??z;g(O,[{ts:T.createdAt,stream:z==="error"?"stderr":"system",chunk:L,dedupeKey:`socket:event:${O}:${P??`${z}:${L}:${T.createdAt}`}`}]);return}if(r&&T.type==="heartbeat.run.status"){const P=Xu(M.status)??"updated";g(O,[{ts:T.createdAt,stream:Qre(P)&&P!=="succeeded"?"stderr":"system",chunk:`run ${P}`,dedupeKey:`socket:status:${O}:${P}:${Xu(M.finishedAt)??""}`}])}}},k.onerror=()=>{k==null||k.close()},k.onclose=()=>{w()}};return N(),()=>{v=!0,j!==null&&window.clearTimeout(j),k&&(k.onmessage=null,k.onerror=null,k.onclose=null,k.close(1e3,"live_run_transcripts_unmount"))}},[f,r,t,d]),{transcriptByRun:x.useMemo(()=>{const v=new Map,j=(u==null?void 0:u.censorUsernameInLogs)===!0;for(const k of e){const w=T1(k.agentRuntimeType),N=i.get(k.id)??[];v.set(k.id,N.length>0?gve(N,w.parseStdoutLine,{censorUsernameInLogs:j}):Gre(k))}return v},[i,u==null?void 0:u.censorUsernameInLogs,e]),hasOutputForRun(v){var k;const j=d.get(v);return(((k=i.get(v))==null?void 0:k.length)??0)>0||(j?Gre(j).length>0:!1)}}}const l3t=/^\d{4}-\d{2}-\d{2}T[^\s]+\s+ERROR\s+(?:codex_core::models_manager::manager|codex_models_manager::manager):\s+failed to refresh available models:\s+timeout waiting for child process to exit$/i;function c3t(e){return l3t.test(e.trim())}function _ve(e){return e.split(/\r?\n/).filter(t=>!c3t(t)).join(`
|
|
1352
1352
|
`).trim()}const u3t=new Set(["README","README.md","package.json","pnpm-lock.yaml","tsconfig.json","vite.config.ts","vitest.config.ts","playwright.config.ts","Dockerfile","Makefile","LICENSE"]),d3t=new Set(["apply_patch","patch","ed","tee","mv","cp","rm","mkdir","touch"]),f3t=900,m3t=8,h3t=["/Users/","/home/","/Volumes/","/tmp/","/var/","/opt/","/mnt/","/private/"];function Ei(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function p3t(e){try{const t=new URL(e);if(t.protocol!=="file:")return null;const n=decodeURIComponent(t.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n}catch{return null}}function g3t(e){const t=e==null?void 0:e.trim();if(!t)return null;const n=/^file:/i.test(t)?p3t(t):null;return n||(/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]+\\[^\\]+/.test(t)?t:/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith("//")?null:h3t.some(r=>t.startsWith(r))?t:null)}function x3t(e){return e.button===0&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey}function ji(e){return e.replace(/\s+/g," ").trim()}function b3t(e){return ji(e).toLowerCase()==="turn started"}function Ave(e){return!!/^\[rudder\](?:\s|$)/.test(e)}function Eve(e){return/^[\s./~,-]/.test(e)||/^[A-Za-z]:[\\/]/.test(e)}function y3t(e,t){if(t)return e.trim();let n=!1;return e.split(/\r?\n/).filter(r=>{const i=r.trim();return Ave(i)?(n=/:\s*$/.test(i),!1):n&&Eve(i)?!1:(n=!1,!0)}).join(`
|
|
1353
1353
|
`).trim()}function v3t(e){const t=e.trim();return/^WARN\b/i.test(t)||/^\d{4}-\d{2}-\d{2}T[^\s]+\s+WARN\s+/i.test(t)}function w3t(e){return/WARN\s+codex_analytics::analytics_client:\s+events failed with status 403 Forbidden:\s+<html>/i.test(e.trim())}function k3t(e,t){if(t!=null&&t.showDeveloperDiagnostics)return e;let n=!1;const r=[];for(const i of e){if(i.kind==="init")continue;if(i.kind!=="stderr"){r.push(i);continue}const a=[];let o=!1;for(const c of i.text.split(/\r?\n/)){const u=c.trim();if(n){/^<\/html>$/i.test(u)&&(n=!1);continue}if(w3t(u)){n=!0;continue}if(Ave(u)){o=/:\s*$/.test(u);continue}o&&Eve(u)||(o=!1,!v3t(u)&&a.push(c))}const l=_ve(a.join(`
|
|
@@ -1380,7 +1380,7 @@ ${u}`,c.ts=l.ts):r.push({type:"stdout",ts:l.ts,text:u})}if(!t)for(const l of r)(
|
|
|
1380
1380
|
`}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
|
|
1381
1381
|
`}),n}function mse(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function hse(e,t){const n=K4t(e,t),r=n.one(e,void 0),i=U4t(n),a=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&a.children.push({type:"text",value:`
|
|
1382
1382
|
`},i),a}function G4t(e,t){return e&&"run"in e?async function(n,r){const i=hse(n,{file:r,...t});await e.run(i,r)}:function(n,r){return hse(n,{file:r,...e||t})}}function pse(e){if(e)throw e}var bR,gse;function Q4t(){if(gse)return bR;gse=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]"},a=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var d=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!d&&!f)return!1;var h;for(h in u);return typeof h>"u"||e.call(u,h)},o=function(u,d){n&&d.name==="__proto__"?n(u,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):u[d.name]=d.newValue},l=function(u,d){if(d==="__proto__")if(e.call(u,d)){if(r)return r(u,d).value}else return;return u[d]};return bR=function c(){var u,d,f,h,g,b,v=arguments[0],j=1,k=arguments.length,w=!1;for(typeof v=="boolean"&&(w=v,v=arguments[1]||{},j=2),(v==null||typeof v!="object"&&typeof v!="function")&&(v={});j<k;++j)if(u=arguments[j],u!=null)for(d in u)f=l(v,d),h=l(u,d),v!==h&&(w&&h&&(a(h)||(g=i(h)))?(g?(g=!1,b=f&&i(f)?f:[]):b=f&&a(f)?f:{},o(v,{name:d,newValue:c(w,b,h)})):typeof h<"u"&&o(v,{name:d,newValue:h}));return v},bR}var Y4t=Q4t();const yR=U5(Y4t);function S$(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 J4t(){const e=[],t={run:n,use:r};return t;function n(...i){let a=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(c,...u){const d=e[++a];let f=-1;if(c){o(c);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,d?X4t(d,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function X4t(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(i);try{c=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return i(d)}l||(c&&c.then&&typeof c.then=="function"?c.then(a,i):c instanceof Error?i(c):a(c))}function i(o,...l){n||(n=!0,t(o,...l))}function a(o){i(null,o)}}const df={basename:ebt,dirname:tbt,extname:nbt,join:rbt,sep:"/"};function ebt(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');c8(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function tbt(e){if(c8(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 nbt(e){c8(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function rbt(...e){let t=-1,n;for(;++t<e.length;)c8(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":sbt(n)}function sbt(e){c8(e);const t=e.codePointAt(0)===47;let n=ibt(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function ibt(e,t){let n="",r=0,i=-1,a=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,a=0;continue}}else if(n.length>0){n="",r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function c8(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const abt={cwd:obt};function obt(){return"/"}function _$(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function lbt(e){if(typeof e=="string")e=new URL(e);else if(!_$(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 cbt(e)}function cbt(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 vR=["history","path","basename","stem","extname","dirname"];class y6e{constructor(t){let n;t?_$(t)?n={path:t}:typeof t=="string"||ubt(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":abt.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<vR.length;){const a=vR[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let i;for(i in n)vR.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?df.basename(this.path):void 0}set basename(t){kR(t,"basename"),wR(t,"basename"),this.path=df.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?df.dirname(this.path):void 0}set dirname(t){xse(this.basename,"dirname"),this.path=df.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?df.extname(this.path):void 0}set extname(t){if(wR(t,"extname"),xse(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=df.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){_$(t)&&(t=lbt(t)),kR(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?df.basename(this.path,this.extname):void 0}set stem(t){kR(t,"stem"),wR(t,"stem"),this.path=df.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 ps(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 wR(e,t){if(e&&e.includes(df.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+df.sep+"`")}function kR(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function xse(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function ubt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const dbt=(function(e){const r=this.constructor.prototype,i=r[e],a=function(){return i.apply(a,arguments)};return Object.setPrototypeOf(a,r),a}),fbt={}.hasOwnProperty;class nH extends dbt{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=J4t()}copy(){const t=new nH;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(yR(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(CR("data",this.frozen),this.namespace[t]=n,this):fbt.call(this.namespace,t)&&this.namespace[t]||void 0:t?(CR("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=Q9(t),r=this.parser||this.Parser;return jR("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),jR("process",this.parser||this.Parser),NR("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(a,o){const l=Q9(t),c=r.parse(l);r.run(c,l,function(d,f,h){if(d||!f||!h)return u(d);const g=f,b=r.stringify(g,h);pbt(b)?h.value=b:h.result=b,u(d,h)});function u(d,f){d||!f?o(d):a?a(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),jR("processSync",this.parser||this.Parser),NR("processSync",this.compiler||this.Compiler),this.process(t,i),yse("processSync","process",n),r;function i(a,o){n=!0,pse(a),r=o}}run(t,n,r){bse(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const c=Q9(n);i.run(t,c,u);function u(d,f,h){const g=f||t;d?l(d):o?o(g):r(void 0,g,h)}}}runSync(t,n){let r=!1,i;return this.run(t,n,a),yse("runSync","run",r),i;function a(o,l){pse(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=Q9(n),i=this.compiler||this.Compiler;return NR("stringify",i),bse(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(CR("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...f]=u;c(d,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=yR(!0,i.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const f=u[d];a(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,d){let f=-1,h=-1;for(;++f<r.length;)if(r[f][0]===u){h=f;break}if(h===-1)r.push([u,...d]);else if(d.length>0){let[g,...b]=d;const v=r[h][1];S$(v)&&S$(g)&&(g=yR(!0,v,g)),r[h]=[u,g,...b]}}}}const mbt=new nH().freeze();function jR(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function NR(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function CR(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 bse(e){if(!S$(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function yse(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Q9(e){return hbt(e)?e:new y6e(e)}function hbt(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function pbt(e){return typeof e=="string"||gbt(e)}function gbt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const xbt="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",vse=[],wse={allowDangerousHtml:!0},bbt=/^(https?|ircs?|mailto|xmpp)$/i,ybt=[{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 vbt(e){const t=wbt(e),n=kbt(e);return jbt(t.runSync(t.parse(n),n),e)}function wbt(e){const t=e.rehypePlugins||vse,n=e.remarkPlugins||vse,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...wse}:wse;return mbt().use(c4t).use(n).use(G4t,r).use(t)}function kbt(e){const t=e.children||"",n=new y6e;return typeof t=="string"&&(n.value=t),n}function jbt(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||Nbt;for(const d of ybt)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+xbt+d.id,void 0);return MU(e,u),W5t(e,{Fragment:s.Fragment,components:i,ignoreInvalidStyle:!0,jsx:s.jsx,jsxs:s.jsxs,passKeys:!0,passNode:!0});function u(d,f,h){if(d.type==="raw"&&h&&typeof f=="number")return o?h.children.splice(f,1):h.children[f]={type:"text",value:d.value},f;if(d.type==="element"){let g;for(g in xR)if(Object.hasOwn(xR,g)&&Object.hasOwn(d.properties,g)){const b=d.properties[g],v=xR[g];(v===null||v.includes(d.tagName))&&(d.properties[g]=c(String(b||""),g,d))}}if(d.type==="element"){let g=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!g&&r&&typeof f=="number"&&(g=!r(d,f,h)),g&&h&&typeof f=="number")return l&&d.children?h.children.splice(f,1,...d.children):h.children.splice(f,1),f}}}function Nbt(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||bbt.test(e.slice(0,t))?e:""}function Cbt(e,t,n){const i=O_((n||{}).ignore||[]),a=Sbt(t);let o=-1;for(;++o<a.length;)D2e(e,"text",l);function l(u,d){let f=-1,h;for(;++f<d.length;){const g=d[f],b=h?h.children:void 0;if(i(g,b?b.indexOf(g):void 0,h))return;h=g}if(h)return c(u,d)}function c(u,d){const f=d[d.length-1],h=a[o][0],g=a[o][1];let b=0;const j=f.children.indexOf(u);let k=!1,w=[];h.lastIndex=0;let N=h.exec(u.value);for(;N;){const C=N.index,A={index:N.index,input:N.input,stack:[...d,u]};let _=g(...N,A);if(typeof _=="string"&&(_=_.length>0?{type:"text",value:_}:void 0),_===!1?h.lastIndex=C+1:(b!==C&&w.push({type:"text",value:u.value.slice(b,C)}),Array.isArray(_)?w.push(..._):_&&w.push(_),b=C+N[0].length,k=!0),!h.global)break;N=h.exec(u.value)}return k?(b<u.value.length&&w.push({type:"text",value:u.value.slice(b)}),f.children.splice(j,1,...w)):w=[u],j+w.length}}function Sbt(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([_bt(i[0]),Abt(i[1])])}return t}function _bt(e){return typeof e=="string"?new RegExp(Vst(e),"g"):e}function Abt(e){return typeof e=="function"?e:function(){return e}}const SR="phrasing",_R=["autolink","link","image","label"];function Ebt(){return{transforms:[Dbt],enter:{literalAutolink:Ibt,literalAutolinkEmail:AR,literalAutolinkHttp:AR,literalAutolinkWww:AR},exit:{literalAutolink:Pbt,literalAutolinkEmail:Obt,literalAutolinkHttp:Mbt,literalAutolinkWww:Rbt}}}function Tbt(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:SR,notInConstruct:_R},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:SR,notInConstruct:_R},{character:":",before:"[ps]",after:"\\/",inConstruct:SR,notInConstruct:_R}]}}function Ibt(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function AR(e){this.config.enter.autolinkProtocol.call(this,e)}function Mbt(e){this.config.exit.autolinkProtocol.call(this,e)}function Rbt(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 Obt(e){this.config.exit.autolinkEmail.call(this,e)}function Pbt(e){this.exit(e)}function Dbt(e){Cbt(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Lbt],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),$bt]],{ignore:["link","linkReference"]})}function Lbt(e,t,n,r,i){let a="";if(!v6e(i)||(/^w/i.test(t)&&(n=t+n,t="",a="http://"),!Fbt(n)))return!1;const o=zbt(n+r);if(!o[0])return!1;const l={type:"link",title:null,url:a+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[l,{type:"text",value:o[1]}]:l}function $bt(e,t,n,r){return!v6e(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function Fbt(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 zbt(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=bN(e,"(");let a=bN(e,")");for(;r!==-1&&i>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),a++;return[e,n]}function v6e(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||yl(n)||R_(n))&&(!t||n!==47)}w6e.peek=Gbt;function Bbt(){this.buffer()}function Ubt(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function qbt(){this.buffer()}function Kbt(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Hbt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=xd(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Vbt(e){this.exit(e)}function Wbt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=xd(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zbt(e){this.exit(e)}function Gbt(){return"["}function w6e(e,t,n,r){const i=n.createTracker(r);let a=i.move("[^");const o=n.enter("footnoteReference"),l=n.enter("reference");return a+=i.move(n.safe(n.associationId(e),{after:"]",before:a})),l(),o(),a+=i.move("]"),a}function Qbt(){return{enter:{gfmFootnoteCallString:Bbt,gfmFootnoteCall:Ubt,gfmFootnoteDefinitionLabelString:qbt,gfmFootnoteDefinition:Kbt},exit:{gfmFootnoteCallString:Hbt,gfmFootnoteCall:Vbt,gfmFootnoteDefinitionLabelString:Wbt,gfmFootnoteDefinition:Zbt}}}function Ybt(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:w6e},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,a,o){const l=a.createTracker(o);let c=l.move("[^");const u=a.enter("footnoteDefinition"),d=a.enter("label");return c+=l.move(a.safe(a.associationId(r),{before:c,after:"]"})),d(),c+=l.move("]:"),r.children&&r.children.length>0&&(l.shift(4),c+=l.move((t?`
|
|
1383
|
-
`:" ")+a.indentLines(a.containerFlow(r,l.current()),t?k6e:Jbt))),u(),c}}function Jbt(e,t,n){return t===0?e:k6e(e,t,n)}function k6e(e,t,n){return(n?"":" ")+e}function Xbt(){return[Ebt(),Qbt(),g2e(),axe(),sxe()]}function eyt(e){return{extensions:[Tbt(),Ybt(e),x2e(),oxe(e),ixe()]}}const tyt={tokenize:oyt,partial:!0},j6e={tokenize:lyt,partial:!0},N6e={tokenize:cyt,partial:!0},C6e={tokenize:uyt,partial:!0},nyt={tokenize:dyt,partial:!0},S6e={name:"wwwAutolink",tokenize:iyt,previous:A6e},_6e={name:"protocolAutolink",tokenize:ayt,previous:E6e},K1={name:"emailAutolink",tokenize:syt,previous:T6e},om={};function ryt(){return{text:om}}let Lg=48;for(;Lg<123;)om[Lg]=K1,Lg++,Lg===58?Lg=65:Lg===91&&(Lg=97);om[43]=K1;om[45]=K1;om[46]=K1;om[95]=K1;om[72]=[K1,_6e];om[104]=[K1,_6e];om[87]=[K1,S6e];om[119]=[K1,S6e];function syt(e,t,n){const r=this;let i,a;return o;function o(f){return!A$(f)||!T6e.call(r,r.previous)||rH(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(f))}function l(f){return A$(f)?(e.consume(f),l):f===64?(e.consume(f),c):n(f)}function c(f){return f===46?e.check(nyt,d,u)(f):f===45||f===95||tl(f)?(a=!0,e.consume(f),c):d(f)}function u(f){return e.consume(f),i=!0,c}function d(f){return a&&i&&Cl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function iyt(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!A6e.call(r,r.previous)||rH(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(tyt,e.attempt(j6e,e.attempt(N6e,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function ayt(e,t,n){const r=this;let i="",a=!1;return o;function o(f){return(f===72||f===104)&&E6e.call(r,r.previous)&&!rH(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),l):n(f)}function l(f){if(Cl(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),l;if(f===58){const h=i.toLowerCase();if(h==="http"||h==="https")return e.consume(f),c}return n(f)}function c(f){return f===47?(e.consume(f),a?u:(a=!0,c)):n(f)}function u(f){return f===null||xN(f)||Jr(f)||yl(f)||R_(f)?n(f):e.attempt(j6e,e.attempt(N6e,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function oyt(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function lyt(e,t,n){let r,i,a;return o;function o(u){return u===46||u===95?e.check(C6e,c,l)(u):u===null||Jr(u)||yl(u)||u!==45&&R_(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function c(u){return i||r||!a?n(u):t(u)}}function cyt(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(C6e,t,a)(o):o===null||Jr(o)||yl(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&r++,e.consume(o),i}}function uyt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Jr(l)||yl(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Jr(l)||yl(l)?t(l):r(l)}function a(l){return Cl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):Cl(l)?(e.consume(l),o):n(l)}}function dyt(e,t,n){return r;function r(a){return e.consume(a),i}function i(a){return tl(a)?n(a):t(a)}}function A6e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jr(e)}function E6e(e){return!Cl(e)}function T6e(e){return!(e===47||A$(e))}function A$(e){return e===43||e===45||e===46||e===95||tl(e)}function rH(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 fyt={tokenize:vyt,partial:!0};function myt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:xyt,continuation:{tokenize:byt},exit:yyt}},text:{91:{name:"gfmFootnoteCall",tokenize:gyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:hyt,resolveTo:pyt}}}}function hyt(e,t,n){const r=this;let i=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=xd(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function pyt(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 a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function gyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),c}function c(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(a>999||f===93&&!o||f===null||f===91||Jr(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return i.includes(xd(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return Jr(f)||(o=!0),a++,e.consume(f),f===92?d:u}function d(f){return f===91||f===92||f===93?(e.consume(f),a++,u):u(f)}}function xyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||Jr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=xd(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return Jr(b)||(l=!0),o++,e.consume(b),b===92?f:d}function f(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function h(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),$r(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function byt(e,t,n){return e.check(P7,t,e.attempt(fyt,t,n))}function yyt(e){e.exit("gfmFootnoteDefinition")}function vyt(e,t,n){const r=this;return $r(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function wyt(e){return t0e([ryt(),myt(),p2e(e),lxe(),rxe()])}const kyt={};function jyt(e){const t=this,n=e||kyt,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(wyt(n)),a.push(Xbt()),o.push(eyt(n))}const I6e="rudder.theme",kse="#1f1f1d",jse="#f1f0ef",M6e=x.createContext(void 0);function Nyt(){return typeof window>"u"?null:window.desktopShell??null}function R6e(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Nse(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(I6e);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function tj(e){return e==="system"?R6e():e}function Cse(e){var a,o;if(typeof document>"u")return;const n=tj(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?kse:jse;const i=document.querySelector('meta[name="theme-color"]');i instanceof HTMLMetaElement&&i.setAttribute("content",n?kse:jse),(o=(a=Nyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Cyt({children:e}){const[t,n]=x.useState(()=>Nse()),[r,i]=x.useState(()=>tj(Nse())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>tj(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{Cse(t),i(tj(t));try{localStorage.setItem(I6e,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=R6e();i(d),Cse("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return s.jsx(M6e.Provider,{value:l,children:e})}function O6e(){const e=x.useContext(M6e);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Syt=190,_yt=178;function Ayt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Syt)),top:Math.min(t,Math.max(8,window.innerHeight-_yt))}}function Eyt(e){return e instanceof Error?e.message:String(e)}function Tyt(){try{return _r()}catch{return null}}function Iyt({alt:e,className:t,name:n,onInspect:r,src:i,...a}){const o=Tyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),f=wK();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const h=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Ayt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Eyt(w),tone:"error"})}};return s.jsxs("span",{className:"rudder-inspectable-image",children:[s.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:h,onDoubleClick:h,onContextMenu:g,children:[s.jsx("img",{...a,ref:c,src:i,alt:e??"",className:t,onContextMenu:g}),s.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:s.jsx(x1,{className:"size-3.5"})})]}),u&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>$mt(i)),children:[s.jsx(Bc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>yK(i,n),"Image copied"),children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Lbe(i,n)),children:[s.jsx(Kf,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),f?s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>vK(i,n)),children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function P6e({label:e,preview:t}){var c,u,d,f,h;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,i=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((f=t==null?void 0:t.locationLabel)==null?void 0:f.trim())||null,o=((h=t==null?void 0:t.detailsHref)==null?void 0:h.trim())||null,l=!!(r||i||a||o);return s.jsxs("span",{className:G("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[s.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?s.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[s.jsxs("span",{className:"flex items-start gap-3",children:[s.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:s.jsx(zc,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),i||a?s.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[i?s.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:i}):null,a?s.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?s.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?s.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[s.jsx("span",{children:"View details"}),s.jsx(p1,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let ER=null;function Myt(){return ER||(ER=mt(()=>import("./mermaid.core-D3HFVWWP.js").then(e=>e.bF),[]).then(e=>e.default)),ER}function Tv(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Tv(t)).join(""):""}function Y9(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function Ryt(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function Oyt(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function Pyt(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Tv(t.children).replace(/\n$/,"")}function Dyt(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const i=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return i?decodeURIComponent(i):"Image preview"}catch{return"Image preview"}}function Lyt(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),i=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!i&&!a?e:e.replace(/\\r\\n/g,`
|
|
1383
|
+
`:" ")+a.indentLines(a.containerFlow(r,l.current()),t?k6e:Jbt))),u(),c}}function Jbt(e,t,n){return t===0?e:k6e(e,t,n)}function k6e(e,t,n){return(n?"":" ")+e}function Xbt(){return[Ebt(),Qbt(),g2e(),axe(),sxe()]}function eyt(e){return{extensions:[Tbt(),Ybt(e),x2e(),oxe(e),ixe()]}}const tyt={tokenize:oyt,partial:!0},j6e={tokenize:lyt,partial:!0},N6e={tokenize:cyt,partial:!0},C6e={tokenize:uyt,partial:!0},nyt={tokenize:dyt,partial:!0},S6e={name:"wwwAutolink",tokenize:iyt,previous:A6e},_6e={name:"protocolAutolink",tokenize:ayt,previous:E6e},K1={name:"emailAutolink",tokenize:syt,previous:T6e},om={};function ryt(){return{text:om}}let Lg=48;for(;Lg<123;)om[Lg]=K1,Lg++,Lg===58?Lg=65:Lg===91&&(Lg=97);om[43]=K1;om[45]=K1;om[46]=K1;om[95]=K1;om[72]=[K1,_6e];om[104]=[K1,_6e];om[87]=[K1,S6e];om[119]=[K1,S6e];function syt(e,t,n){const r=this;let i,a;return o;function o(f){return!A$(f)||!T6e.call(r,r.previous)||rH(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(f))}function l(f){return A$(f)?(e.consume(f),l):f===64?(e.consume(f),c):n(f)}function c(f){return f===46?e.check(nyt,d,u)(f):f===45||f===95||tl(f)?(a=!0,e.consume(f),c):d(f)}function u(f){return e.consume(f),i=!0,c}function d(f){return a&&i&&Cl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function iyt(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!A6e.call(r,r.previous)||rH(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(tyt,e.attempt(j6e,e.attempt(N6e,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function ayt(e,t,n){const r=this;let i="",a=!1;return o;function o(f){return(f===72||f===104)&&E6e.call(r,r.previous)&&!rH(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),l):n(f)}function l(f){if(Cl(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),l;if(f===58){const h=i.toLowerCase();if(h==="http"||h==="https")return e.consume(f),c}return n(f)}function c(f){return f===47?(e.consume(f),a?u:(a=!0,c)):n(f)}function u(f){return f===null||xN(f)||Jr(f)||yl(f)||R_(f)?n(f):e.attempt(j6e,e.attempt(N6e,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function oyt(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function lyt(e,t,n){let r,i,a;return o;function o(u){return u===46||u===95?e.check(C6e,c,l)(u):u===null||Jr(u)||yl(u)||u!==45&&R_(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function c(u){return i||r||!a?n(u):t(u)}}function cyt(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(C6e,t,a)(o):o===null||Jr(o)||yl(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&r++,e.consume(o),i}}function uyt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Jr(l)||yl(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Jr(l)||yl(l)?t(l):r(l)}function a(l){return Cl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):Cl(l)?(e.consume(l),o):n(l)}}function dyt(e,t,n){return r;function r(a){return e.consume(a),i}function i(a){return tl(a)?n(a):t(a)}}function A6e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jr(e)}function E6e(e){return!Cl(e)}function T6e(e){return!(e===47||A$(e))}function A$(e){return e===43||e===45||e===46||e===95||tl(e)}function rH(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 fyt={tokenize:vyt,partial:!0};function myt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:xyt,continuation:{tokenize:byt},exit:yyt}},text:{91:{name:"gfmFootnoteCall",tokenize:gyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:hyt,resolveTo:pyt}}}}function hyt(e,t,n){const r=this;let i=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=xd(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function pyt(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 a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function gyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),c}function c(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(a>999||f===93&&!o||f===null||f===91||Jr(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return i.includes(xd(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return Jr(f)||(o=!0),a++,e.consume(f),f===92?d:u}function d(f){return f===91||f===92||f===93?(e.consume(f),a++,u):u(f)}}function xyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||Jr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=xd(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return Jr(b)||(l=!0),o++,e.consume(b),b===92?f:d}function f(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function h(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),$r(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function byt(e,t,n){return e.check(P7,t,e.attempt(fyt,t,n))}function yyt(e){e.exit("gfmFootnoteDefinition")}function vyt(e,t,n){const r=this;return $r(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function wyt(e){return t0e([ryt(),myt(),p2e(e),lxe(),rxe()])}const kyt={};function jyt(e){const t=this,n=e||kyt,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(wyt(n)),a.push(Xbt()),o.push(eyt(n))}const I6e="rudder.theme",kse="#1f1f1d",jse="#f1f0ef",M6e=x.createContext(void 0);function Nyt(){return typeof window>"u"?null:window.desktopShell??null}function R6e(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Nse(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(I6e);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function tj(e){return e==="system"?R6e():e}function Cse(e){var a,o;if(typeof document>"u")return;const n=tj(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?kse:jse;const i=document.querySelector('meta[name="theme-color"]');i instanceof HTMLMetaElement&&i.setAttribute("content",n?kse:jse),(o=(a=Nyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Cyt({children:e}){const[t,n]=x.useState(()=>Nse()),[r,i]=x.useState(()=>tj(Nse())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>tj(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{Cse(t),i(tj(t));try{localStorage.setItem(I6e,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=R6e();i(d),Cse("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return s.jsx(M6e.Provider,{value:l,children:e})}function O6e(){const e=x.useContext(M6e);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Syt=190,_yt=178;function Ayt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Syt)),top:Math.min(t,Math.max(8,window.innerHeight-_yt))}}function Eyt(e){return e instanceof Error?e.message:String(e)}function Tyt(){try{return _r()}catch{return null}}function Iyt({alt:e,className:t,name:n,onInspect:r,src:i,...a}){const o=Tyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),f=wK();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const h=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Ayt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Eyt(w),tone:"error"})}};return s.jsxs("span",{className:"rudder-inspectable-image",children:[s.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:h,onDoubleClick:h,onContextMenu:g,children:[s.jsx("img",{...a,ref:c,src:i,alt:e??"",className:t,onContextMenu:g}),s.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:s.jsx(x1,{className:"size-3.5"})})]}),u&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>$mt(i)),children:[s.jsx(Bc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>yK(i,n),"Image copied"),children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Lbe(i,n)),children:[s.jsx(Kf,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),f?s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>vK(i,n)),children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function P6e({label:e,preview:t}){var c,u,d,f,h;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,i=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((f=t==null?void 0:t.locationLabel)==null?void 0:f.trim())||null,o=((h=t==null?void 0:t.detailsHref)==null?void 0:h.trim())||null,l=!!(r||i||a||o);return s.jsxs("span",{className:G("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[s.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?s.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[s.jsxs("span",{className:"flex items-start gap-3",children:[s.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:s.jsx(zc,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),i||a?s.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[i?s.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:i}):null,a?s.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?s.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?s.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[s.jsx("span",{children:"View details"}),s.jsx(p1,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let ER=null;function Myt(){return ER||(ER=mt(()=>import("./mermaid.core-B2JfLRuZ.js").then(e=>e.bF),[]).then(e=>e.default)),ER}function Tv(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Tv(t)).join(""):""}function Y9(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function Ryt(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function Oyt(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function Pyt(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Tv(t.children).replace(/\n$/,"")}function Dyt(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const i=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return i?decodeURIComponent(i):"Image preview"}catch{return"Image preview"}}function Lyt(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),i=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!i&&!a?e:e.replace(/\\r\\n/g,`
|
|
1384
1384
|
`).replace(/\\n/g,`
|
|
1385
1385
|
`)}function $yt({source:e,darkMode:t}){const n=x.useId().replace(/[^a-zA-Z0-9_-]/g,""),[r,i]=x.useState(null),[a,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return i(null),o(null),Myt().then(async c=>{c.initialize({startOnLoad:!1,securityLevel:"strict",theme:t?"dark":"default",fontFamily:"inherit",suppressErrorRendering:!0});const u=await c.render(`rudder-mermaid-${n}`,e);l&&i(u.svg)}).catch(c=>{if(!l)return;const u=c instanceof Error&&c.message?c.message:"Failed to render Mermaid diagram.";o(u)}),()=>{l=!1}},[t,n,e]),s.jsx("div",{className:"rudder-mermaid",children:r?s.jsx("div",{dangerouslySetInnerHTML:{__html:r}}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:G("rudder-mermaid-status",a&&"rudder-mermaid-status-error"),children:a?`Unable to render Mermaid diagram: ${a}`:"Rendering Mermaid diagram..."}),s.jsx("pre",{className:"rudder-mermaid-source",children:s.jsx("code",{className:"language-mermaid",children:e})})]})})}function Aa({children:e,className:t,resolveImageSrc:n,onLinkClick:r,skillReferences:i,enableImagePreview:a=!0}){const{resolvedTheme:o}=O6e(),[l,c]=x.useState(null),u=new Map((i??[]).map(b=>[Y9(b.href),b]).filter(([b])=>b.length>0)),d=new Map((i??[]).map(b=>[Y9(b.label),b]).filter(([b])=>b.length>0)),f=Lyt(e),h=b=>{if(!a)return;const v=b.currentSrc||b.src;v&&c({alt:b.alt,name:Dyt(b),src:v,naturalSize:b.naturalWidth>0&&b.naturalHeight>0?{width:b.naturalWidth,height:b.naturalHeight}:null})},g={pre:({node:b,children:v,...j})=>{const k=Pyt(v);return k?s.jsx($yt,{source:k,darkMode:o==="dark"}):s.jsx("pre",{...j,children:v})},a:({href:b,children:v})=>{const j=b?ug(b):null;if(j){const A=J7(Tv(v)),_=j.kind==="project"?`/projects/${j.projectId}`:j.kind==="issue"?`/issues/${j.ref??j.issueId}`:`/agents/${j.agentId}`;return s.jsx("a",{href:_,className:G("rudder-mention-chip",`rudder-mention-chip--${j.kind}`,j.kind==="project"&&"rudder-project-mention-chip"),"data-mention-kind":j.kind,style:$be(j),children:A})}const k=m4(b,Tv(v));if(k){const A=u.get(Y9(k.href))??d.get(Y9(k.label))??null;return s.jsx(P6e,{label:k.label,preview:A})}const w=Tv(v),N=Ryt(b),C=N&&Oyt(w);return s.jsx("a",{href:b,target:N?"_blank":void 0,rel:N?"noreferrer noopener":"noreferrer",title:C?b:void 0,onClick:A=>{!b||!r||r({event:A,href:b,label:w})},children:v})}};return g.img=({node:b,src:v,alt:j,...k})=>{const N=(v&&n?n(v):null)??v??"";return a&&N?s.jsx(Iyt,{...k,src:N,alt:j??"",name:(j==null?void 0:j.trim())||"Markdown image",onInspect:h}):s.jsx("img",{...k,src:N,alt:j??""})},s.jsxs(s.Fragment,{children:[s.jsx("div",{className:G("rudder-markdown prose prose-sm max-w-none break-words overflow-hidden",o==="dark"&&"prose-invert",t),children:s.jsx(vbt,{remarkPlugins:[jyt],components:g,urlTransform:b=>b,children:f})}),a?s.jsx(kK,{preview:l,onOpenChange:b=>{b||c(null)},testId:"markdown-body-image-preview-dialog",titleFallback:"Image preview"}):null]})}function D6e({block:e,density:t,presentation:n="default",className:r,collapsibleSummary:i=!1,onMarkdownLinkClick:a}){const o=t==="compact",l=e.role==="user",c=l&&n!=="detail",[u,d]=x.useState(!0),f=s.jsx(Aa,{className:G("[&>*:first-child]:mt-0 [&>*:last-child]:mb-0",o?"text-xs leading-5 text-foreground/85":n==="detail"?"text-sm leading-7":"text-sm",r),onLinkClick:a,children:e.text});return!l||!i?s.jsxs("div",{title:uc(e.ts),children:[c&&s.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:[s.jsx(Hf,{className:o?"h-3.5 w-3.5":"h-4 w-4"}),s.jsx("span",{children:"User"})]}),f]}):s.jsxs("div",{className:"rounded-lg border border-border/30 bg-muted/10",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-2.5 py-2 text-left",onClick:()=>d(h=>!h),"aria-expanded":u,"aria-label":u?"Collapse user message":"Expand user message",children:[s.jsx(Pd,{open:u,className:"h-4 w-4 shrink-0 text-muted-foreground"}),s.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:[s.jsx(Hf,{className:o?"h-3.5 w-3.5":"h-4 w-4"}),s.jsx("span",{children:"User"})]})]}),u&&s.jsx("div",{className:"motion-disclosure-enter border-t border-border/20 px-2.5 pb-2.5 pt-2",children:f})]})}function L6e({block:e,density:t,className:n,collapsibleSummary:r=!1,onMarkdownLinkClick:i}){const[a,o]=x.useState(()=>!!e.streaming);x.useEffect(()=>{e.streaming&&o(!0)},[e.streaming]);const l=ji(e.text),c=bu(l,t==="compact"?100:160),u=s.jsx(Aa,{className:G("italic text-foreground/75 [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t==="compact"?"text-[11px] leading-5":"text-sm leading-6",n),onLinkClick:i,children:e.text});return r?s.jsxs("div",{className:"rounded-lg border border-border/30 bg-muted/10",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 px-2.5 py-2 text-left",onClick:()=>o(d=>!d),"aria-expanded":a,"aria-label":a?"Collapse thinking":"Expand thinking",children:[e.streaming?s.jsx(yr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground","aria-hidden":!0}):s.jsx(Pd,{open:a,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"text-[11px] font-medium tracking-wide text-muted-foreground",children:"Thinking"}),!a&&!e.streaming?s.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-5 text-foreground/55",children:c||"…"}):null]})]}),(a||e.streaming)&&s.jsx("div",{className:"motion-disclosure-enter border-t border-border/20 px-2.5 pb-2.5 pt-2",children:u})]}):u}function sH({block:e,index:t,density:n,presentation:r,collapseStdout:i,thinkingClassName:a,onMarkdownLinkClick:o}){return s.jsxs("div",{className:G(t===-1&&"hidden"),children:[e.type==="message"&&s.jsx(D6e,{block:e,density:n,presentation:r,collapsibleSummary:r==="chat",onMarkdownLinkClick:o}),e.type==="thinking"&&s.jsx(L6e,{block:e,density:n,className:a,onMarkdownLinkClick:o}),e.type==="tool"&&s.jsx(iH,{block:e,density:n,presentation:r}),e.type==="command_group"&&s.jsx(zyt,{block:e,density:n}),e.type==="todo_list"&&s.jsx(U6e,{block:e,density:n,presentation:r}),e.type==="stdout"&&s.jsx(K6e,{block:e,density:n,collapseByDefault:i,presentation:r}),e.type==="memory_update"&&s.jsx(Byt,{block:e,density:n}),e.type==="activity"&&s.jsx(B6e,{block:e,density:n}),e.type==="event"&&s.jsx(q6e,{block:e,density:n,presentation:r})]},`${e.type}-${e.ts}-${t}`)}function $6e({command:e,output:t,status:n,className:r}){return s.jsxs("div",{"data-testid":"command-terminal-detail",className:G("overflow-hidden rounded-xl border border-neutral-800 bg-[#0a0a0a] text-neutral-100 shadow-[0_18px_45px_-28px_rgb(0_0_0/0.75)]",r),children:[s.jsxs("div",{className:"flex h-8 items-center gap-1.5 border-b border-white/10 bg-[#171717] px-3",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#ff5f57]"}),s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#febc2e]"}),s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#28c840]"})]}),s.jsxs("div",{className:"p-4 font-mono text-[11px] leading-5",children:[s.jsxs("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-neutral-100",children:[s.jsx("span",{className:"select-none text-emerald-400",children:"$ "}),e]}),t?s.jsx("pre",{className:G("mt-3 overflow-x-auto whitespace-pre-wrap break-words",n==="error"?"text-red-300":"text-neutral-200"),children:t}):null]})]})}function Fyt(e){if(typeof e.input=="string"&&dg(e.name,e.input))return bd(e.input);const t=Ei(e.input);if(t){if(typeof t.command=="string")return bd(t.command);if(typeof t.cmd=="string")return bd(t.cmd)}return null}function iH({block:e,density:t,presentation:n="default"}){const[r,i]=x.useState(n!=="detail"&&e.status==="error"),a=t==="compact",o=n==="detail",l=Wp(e.name,e.input),c=dg(e.name,e.input),u=e.status==="running"?"Running":e.status==="error"?"Errored":c?null:"Completed",d=e.status==="running"?"text-cyan-700 dark:text-cyan-300":e.status==="error"?"text-red-700 dark:text-red-300":"text-emerald-700 dark:text-emerald-300",f=Rve(e.ts,e.endTs),h=Fyt(e),g=h??($5(e.input)||"<empty>"),b=h?Gve(e.result):e.result?$5(e.result):"Waiting for result...",v=G("space-y-3",e.status==="error"&&"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3",o&&"rounded-xl border border-border/40 bg-background/60 p-3"),j=l.summary,k=G(o&&"rounded-xl border border-border/60 bg-background/80 p-3 shadow-sm",e.status==="error"&&"rounded-xl border border-red-500/20 bg-red-500/[0.04] p-3");return s.jsxs("div",{className:k,title:uc(e.ts),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(V6,{category:l.category,status:e.status}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:l.label}),u?s.jsx("span",{className:G("text-[10px] font-semibold tracking-[0.05em]",d),children:u}):null,f&&s.jsx("span",{className:"text-[10px] font-medium tracking-[0.04em] text-muted-foreground",children:f})]}),s.jsx("div",{className:G("mt-1 break-words text-foreground/80",a?"text-xs":"text-sm"),children:j})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>i(w=>!w),"aria-expanded":r,"aria-label":r?`Collapse ${c?"command":"tool"} details`:`Expand ${c?"command":"tool"} details`,children:s.jsx(Pd,{open:r,className:"h-4 w-4"})})]}),r&&s.jsx("div",{className:"motion-disclosure-enter mt-3",children:h?s.jsx($6e,{command:g,output:b,status:e.status}):s.jsx("div",{className:v,children:s.jsxs("div",{className:G("grid gap-3",a?"grid-cols-1":"lg:grid-cols-2"),children:[s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Request"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:g})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Response"}),s.jsx("pre",{className:G("overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px]",e.status==="error"?"text-red-700 dark:text-red-300":"text-foreground/80"),children:b??"No response"})]})]})})})]})}function F6e(){var e;return typeof window>"u"?!1:(((e=window.getSelection())==null?void 0:e.toString().length)??0)>0}function Pd({open:e,className:t}){return s.jsx(Ls,{"data-state":e?"open":"closed",className:G("motion-disclosure-icon",t),"aria-hidden":!0})}function z6e(e){return e.length>0&&e.every(t=>t.status==="error")}function E$(e){return e.split(/[_\s-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function zyt({block:e,density:t}){const n=t==="compact",r=[...e.items].reverse().find(h=>h.status==="running"),i=z6e(e.items),[a,o]=x.useState(i),l=!!r,c=a&&i,u=e.items.map(h=>Wp(h.name,h.input)),d=Qve(u,0,{preferDirectSummary:!0}),f=e.items.slice(0,3).map((h,g)=>({category:(u[g]??Wp(h.name,h.input)).category,status:h.status==="error"?"error":h.status==="running"?"running":"completed"}));return s.jsxs("div",{className:G(c&&"rounded-xl border border-red-500/20 bg-red-500/[0.04] p-3"),title:uc(e.ts),children:[s.jsxs("div",{role:"button",tabIndex:0,className:"flex cursor-pointer items-start gap-2",onClick:()=>{F6e()||o(h=>!h)},onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),o(g=>!g))},children:[s.jsx(Mve,{icons:f,highlightError:c}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"text-[11px] font-semibold leading-none tracking-[0.05em] text-muted-foreground/70",children:"Command activity"}),s.jsx("div",{className:G("mt-1 break-words text-foreground/85",n?"text-xs":"text-sm"),children:d||(l?"Working with commands":"Command details")})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:h=>{h.stopPropagation(),o(g=>!g)},"aria-label":a?"Collapse command details":"Expand command details",children:s.jsx(Pd,{open:a,className:"h-4 w-4"})})]}),a&&s.jsx("div",{className:G("motion-disclosure-enter mt-3 space-y-3",i&&"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3"),children:e.items.map((h,g)=>s.jsx(iH,{block:h,density:t,presentation:"chat"},`${h.ts}-${g}`))})]})}function B6e({block:e,density:t}){return s.jsxs("div",{className:"flex items-start gap-2",title:uc(e.ts),children:[e.status==="completed"?s.jsx(gs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-300"}):s.jsxs("span",{className:"relative mt-1 flex h-2.5 w-2.5 shrink-0",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-cyan-400 opacity-70"}),s.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-cyan-500"})]}),s.jsx("div",{className:G("break-words text-foreground/80",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:e.name})]})}function U6e({block:e,density:t,presentation:n="default"}){const r=t==="compact",i=Yve(e.items),a=e.items.some(c=>c.status==="in_progress"),o=e.items.length>0&&i===e.items.length,l=n==="detail";return s.jsxs("div",{className:G("rounded-xl border border-border/45 bg-muted/10",l?"p-3":r?"p-2.5":"p-3"),title:uc(e.ts),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[a?s.jsx(yr,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-cyan-600 dark:text-cyan-300"}):o?s.jsx(gs,{className:"h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-300"}):s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("div",{className:"min-w-0 flex-1 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Todo List"}),s.jsxs("div",{className:"text-[10px] font-medium tabular-nums text-muted-foreground",children:[i,"/",e.items.length]})]}),s.jsx("ul",{className:G("mt-2 space-y-1.5",r?"text-xs leading-5":"text-sm leading-6"),children:e.items.map((c,u)=>s.jsxs("li",{className:"flex items-start gap-2 text-foreground/82",children:[s.jsx("span",{className:G("mt-[0.35em] inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-full border",c.status==="completed"?"border-emerald-500/40 bg-emerald-500/[0.10] text-emerald-700 dark:text-emerald-300":c.status==="in_progress"?"border-cyan-500/40 bg-cyan-500/[0.10] text-cyan-700 dark:text-cyan-300":"border-border bg-background text-transparent"),children:c.status==="completed"?s.jsx(gs,{className:"h-2.5 w-2.5"}):c.status==="in_progress"?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full"})}),s.jsx("span",{className:G("min-w-0 break-words",c.status==="completed"&&"text-muted-foreground line-through decoration-muted-foreground/40"),children:c.text})]},`${c.status}-${u}-${c.text}`))})]})}function Byt({block:e,density:t}){const[n,r]=x.useState(e.status==="error"&&!!e.failureReason),i=t==="compact",a=e.status==="error",o=a?"Memory update failed":"Agent memory updated",l=$3t(e.scope),c=e.agentName??"Agent",d=`${o}, ${c}, ${l}, ${n?"expanded":"collapsed"}`,f=e.changes.map(g=>g.path),h=[c,l,e.effect];return s.jsxs("div",{"data-transcript-memory-update":"true",className:G("rounded-lg border px-2.5 py-2",a?"border-red-500/20 bg-red-500/[0.04]":"border-border/45 bg-muted/10"),title:uc(e.ts),children:[s.jsxs("div",{role:"button",tabIndex:0,className:"flex cursor-pointer items-start gap-2 text-left",onClick:()=>{F6e()||r(g=>!g)},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),r(b=>!b))},"aria-expanded":n,"aria-label":d,children:[s.jsx(V6,{category:"memory",status:a?"error":"completed"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:G("font-semibold tracking-[0.05em]",i?"text-[11px]":"text-xs",a?"text-red-700 dark:text-red-300":"text-foreground/80"),children:o}),s.jsx("span",{className:"hidden text-[10px] font-medium tabular-nums text-muted-foreground sm:inline",children:Tve(e.ts)})]}),s.jsx("div",{className:G("mt-1 break-words text-foreground/82",i?"text-xs leading-5":"text-sm leading-6"),children:a&&e.failureReason?e.failureReason:e.summary}),s.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:h.map(g=>s.jsx("span",{className:"inline-flex max-w-full items-center rounded-md border border-border/55 bg-background/65 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:s.jsx("span",{className:"truncate",children:g})},g))})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:g=>{g.stopPropagation(),r(b=>!b)},"aria-expanded":n,"aria-label":n?"Collapse memory update details":"Expand memory update details",children:s.jsx(Pd,{open:n,className:"h-4 w-4"})})]}),n?s.jsxs("div",{className:"motion-disclosure-enter mt-2 space-y-2 border-t border-border/30 pt-2",children:[a&&e.failureReason?s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Failure"}),s.jsx("div",{className:"whitespace-pre-wrap break-words text-xs text-red-700 dark:text-red-300",children:e.failureReason})]}):null,s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Paths"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:f.join(`
|
|
1386
1386
|
`)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Raw event"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:e.rawText})]})]}):null]})}function q6e({block:e,density:t,presentation:n="default"}){const[r,i]=x.useState(!e.collapseByDefault),a=t==="compact",o=n==="detail",l=e.collapseByDefault===!0,c=bu(ji(e.text),a?96:140),u=e.tone==="error"?"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3 text-red-700 dark:text-red-300":e.tone==="warn"?"text-amber-700 dark:text-amber-300":e.tone==="info"?"text-sky-700 dark:text-sky-300":"text-foreground/75";return s.jsx("div",{className:u,title:uc(e.ts),children:s.jsxs("div",{className:"flex items-start gap-2",children:[e.tone==="error"?s.jsx(g1,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):e.tone==="warn"?s.jsx(Jz,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):s.jsx("span",{className:"mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-current/50"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[l&&s.jsxs("button",{type:"button",className:G("mb-1 inline-flex max-w-full items-center gap-1 rounded-md text-left font-medium transition-colors hover:text-red-800 dark:hover:text-red-100",a?"text-[11px]":"text-xs"),onClick:()=>i(d=>!d),"aria-expanded":r,"aria-label":r?"Collapse stderr details":"Expand stderr details",children:[s.jsx(Pd,{open:r,className:"h-3.5 w-3.5 shrink-0"}),s.jsxs("span",{className:"min-w-0 truncate",children:[E$(e.label),": ",c||"Details"]})]}),e.label==="result"&&e.tone!=="error"?s.jsx("div",{className:G("whitespace-pre-wrap break-words text-sky-700 dark:text-sky-300",a?"text-[11px]":"text-xs"),children:e.text}):l&&!r?null:o?s.jsx("div",{className:G(l&&r&&"motion-disclosure-enter","whitespace-pre-wrap break-words",a?"text-[11px]":"text-xs"),children:e.text}):s.jsxs("div",{className:G(l&&r&&"motion-disclosure-enter","whitespace-pre-wrap break-words",a?"text-[11px]":"text-xs"),children:[s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.05em] text-muted-foreground/70",children:E$(e.label)}),e.text?s.jsx("span",{className:"ml-2",children:e.text}):null]}),e.detail&&(!l||r)&&s.jsx("pre",{className:G(e.collapseByDefault&&r&&"motion-disclosure-enter","mt-2 overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/75"),children:e.detail})]})]})})}function K6e({block:e,density:t,collapseByDefault:n,presentation:r="default"}){const[i,a]=x.useState(!n),o=r==="detail";return s.jsxs("div",{title:uc(e.ts),children:[o?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>a(l=>!l),"aria-label":i?"Collapse stdout details":"Expand stdout details",children:s.jsx(Pd,{open:i,className:"h-4 w-4"})}),s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"details"})]}):s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Stdout"}),s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>a(l=>!l),"aria-label":i?"Collapse stdout":"Expand stdout",children:s.jsx(Pd,{open:i,className:"h-4 w-4"})})]}),i&&s.jsx("pre",{className:G("motion-disclosure-enter",o?"overflow-x-auto whitespace-pre-wrap break-words font-mono text-foreground/80":"mt-2 overflow-x-auto whitespace-pre-wrap break-words font-mono text-foreground/80",t==="compact"?"text-[11px]":"text-xs"),children:e.text})]})}function Uyt(e){const t=[];for(const n of e){if(n.type==="command_group"){n.items.forEach((r,i)=>{t.push({key:`tool-${r.ts}-${i}`,type:"tool",entry:r})});continue}if(n.type==="tool"){t.push({key:`tool-${n.ts}-${n.toolUseId??n.name}`,type:"tool",entry:{ts:n.ts,endTs:n.endTs,name:n.name,input:n.input,result:n.result,isError:n.isError,status:n.status}});continue}n.type==="stdout"&&t.push({key:`stdout-${n.ts}`,type:"stdout",entry:n})}return t}function qyt(e){if(typeof e.input=="string"&&dg(e.name,e.input))return bd(e.input);const t=Ei(e.input);if(t){if(typeof t.command=="string")return bd(t.command);if(typeof t.cmd=="string")return bd(t.cmd)}return null}function Kyt(e){return e.category==="read"||e.category==="skill"}function Hyt({block:e,density:t,inline:n=!1}){const[r,i]=x.useState(n),a=bu(ji(e.text),t==="compact"?80:120)||"Output";return n?s.jsx("div",{className:"py-1.5",title:uc(e.ts),children:s.jsxs("div",{className:"flex w-full items-start gap-2 text-left",children:[s.jsx(V6,{category:"stdout",status:"completed"}),s.jsx("pre",{className:G("min-w-0 flex-1 whitespace-pre-wrap break-words font-mono text-foreground/80",t==="compact"?"text-[11px] leading-5":"text-xs leading-6"),children:e.text})]})}):s.jsxs("div",{className:"py-1.5",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>i(o=>!o),"aria-expanded":r,"aria-label":r?"Collapse output details":"Expand output details",children:[s.jsx(V6,{category:"stdout",status:"completed"}),s.jsx("span",{className:G("min-w-0 flex-1 break-words text-foreground/82",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:a}),s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:r,className:"h-4 w-4"})})]}),r?s.jsx("pre",{className:G("motion-disclosure-enter","mt-2 overflow-x-auto whitespace-pre-wrap break-words rounded-lg border border-border/35 bg-muted/10 p-2.5 font-mono text-foreground/80",t==="compact"?"text-[11px]":"text-xs"),children:e.text}):null]})}function Vyt({block:e,density:t,inline:n=!1,defaultOpenOnError:r=!0,highlightError:i=!0}){const a=Wp(e.name,e.input),o=dg(e.name,e.input),l=qyt(e),c=l??($5(e.input)||"<empty>"),u=Kyt(a)?null:l?Gve(e.result):e.result?$5(e.result):e.status==="running"?"Waiting for result...":null,d=!!(l||u||!o&&c!=="<empty>"),[f,h]=x.useState(n||r&&e.status==="error"),g=Rve(e.ts,e.endTs),b=e.status==="error"?"Failed":e.status==="running"?"Running":null,v=e.status==="error"?"text-red-700 dark:text-red-300":e.status==="running"?"text-cyan-700 dark:text-cyan-300":"text-muted-foreground",j=e.status==="error"?"error":e.status==="running"?"running":"completed";return s.jsxs("div",{className:G("py-1.5",i&&e.status==="error"&&"rounded-lg bg-red-500/[0.04] px-2"),title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>{n||d&&h(k=>!k)},"aria-expanded":d&&!n?f:void 0,"aria-label":d&&!n?f?`Collapse ${o?"command":"tool"} details`:`Expand ${o?"command":"tool"} details`:void 0,children:[s.jsx(V6,{category:a.category,status:j}),s.jsx("span",{className:G("min-w-0 flex-1 break-words text-foreground/84",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:a.summary}),g?s.jsx("span",{className:"pt-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:g}):null,b?s.jsx("span",{className:G("pt-0.5 text-[10px] font-medium",v),children:b}):null,d&&!n?s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:f,className:"h-4 w-4"})}):null]}),d&&f?l?s.jsx($6e,{command:c,output:u,status:e.status,className:"motion-disclosure-enter ml-5 mt-2"}):s.jsxs("div",{className:"motion-disclosure-enter ml-5 mt-2 space-y-2 rounded-lg border border-border/35 bg-muted/10 p-2.5",children:[s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Input"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:c})]}),u?s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Response"}),s.jsx("pre",{className:G("overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px]",e.status==="error"?"text-red-700 dark:text-red-300":"text-foreground/80"),children:u})]}):null]}):null]})}function TR({action:e,density:t,inline:n=!1,defaultOpenOnError:r=!0,highlightError:i=!0}){return e.type==="stdout"?s.jsx(Hyt,{block:e.entry,density:t,inline:n}):s.jsx(Vyt,{block:e.entry,density:t,inline:n,defaultOpenOnError:r,highlightError:i})}function Wyt(e){return e.type==="tool"||e.type==="command_group"||e.type==="stdout"}function Zyt(e){const t=[];let n=[];const r=()=>{var a;if(n.length===0)return;const i=Uyt(n);i.length>0&&t.push({type:"actions",key:`actions-${((a=n[0])==null?void 0:a.ts)??t.length}-${t.length}`,actions:i}),n=[]};return e.forEach((i,a)=>{if(Wyt(i)){n.push(i);return}r(),t.push({type:"block",key:`${i.type}-${i.ts}-${a}`,block:i})}),r(),t}function Gyt(e){const t=e.filter(r=>r.type==="tool").map(r=>Wp(r.entry.name,r.entry.input)),n=e.filter(r=>r.type==="stdout").length;return Qve(t,n,{preferDirectSummary:!0})}function Qyt(e){return e.type==="stdout"?{category:"stdout",status:"completed"}:{category:Wp(e.entry.name,e.entry.input).category,status:e.entry.status==="error"?"error":e.entry.status==="running"?"running":"completed"}}function Yyt({actions:e,density:t,detailVariant:n,groupIndex:r,groupCount:i}){const a=t==="compact",o=e[0],l=e.length===1,c=e.filter(N=>N.type==="tool").map(N=>N.entry),u=z6e(c),d=l&&(o==null?void 0:o.type)==="stdout",f=l&&(o==null?void 0:o.type)==="tool",h=Gyt(e),g=u&&!n,[b,v]=x.useState(()=>n?!1:u),j=e.slice(0,3).map(Qyt);if(x.useEffect(()=>{!n&&u&&v(!0)},[n,u]),d)return s.jsx("div",{className:"divide-y divide-border/30",children:s.jsx(TR,{action:o,density:t,inline:!0})});if(f)return s.jsx("div",{className:"divide-y divide-border/30",children:s.jsx(TR,{action:o,density:t,defaultOpenOnError:!n,highlightError:!n})});const k=i>1?` group ${r+1}`:"",w=b?`Collapse tool activity${k}`:`Expand tool activity${k}`;return s.jsxs("div",{children:[s.jsxs("button",{type:"button",className:G("-mx-2 flex w-[calc(100%+1rem)] items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-colors",g?"hover:bg-red-500/[0.05]":"hover:bg-muted/10"),onClick:()=>v(N=>!N),"aria-expanded":b,"aria-label":w,children:[s.jsx(Mve,{icons:j,highlightError:g}),s.jsx("span",{className:"min-w-0 flex-1",children:s.jsx("span",{className:G("block break-words text-foreground/82",a?"text-xs":"text-sm"),children:h||"Tool details"})}),s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:b,className:"h-4 w-4"})})]}),b?s.jsx("div",{className:"motion-disclosure-enter mt-2 divide-y divide-border/30 border-l border-border/35 pl-3",children:e.map(N=>s.jsx(TR,{action:N,density:t},N.key))}):null]})}function H6e({turn:e,density:t,thinkingClassName:n,variant:r="chat",onMarkdownLinkClick:i}){const a=r==="detail",o=Zyt(e.blocks),l=o.filter(u=>u.type==="actions").length;return o.length>0?s.jsx("div",{className:"space-y-3",title:uc(e.ts),children:o.map((u,d)=>u.type==="block"?sH({block:u.block,index:d,density:t,presentation:a?"detail":"chat",collapseStdout:!0,thinkingClassName:n,onMarkdownLinkClick:i}):s.jsx(Yyt,{actions:u.actions,density:t,detailVariant:a,groupIndex:o.slice(0,d).filter(f=>f.type==="actions").length,groupCount:l},u.key))}):null}function xy(e){return e.replace(/\s+$/g,"")}function Jyt(e,t){let n=xy(t??"");if(!n)return e;const r=[];for(let i=e.length-1;i>=0;i-=1){const a=e[i];if(a.kind!=="assistant"||!n){r.push(a);continue}const o=xy(a.text);if(n=xy(n),!o){r.push(a);continue}if(n.endsWith(o)){n=xy(n.slice(0,n.length-o.length));continue}if(o.endsWith(n)){const l=xy(o.slice(0,o.length-n.length));n="",l&&r.push({...a,text:l});continue}r.push(a)}return n?e:r.reverse()}function Xyt(e,t){return t.hideAssistantMessages?e.filter(n=>n.kind!=="assistant"):Jyt(e,t.hiddenAssistantMessageText)}function evt({entries:e,density:t,streaming:n,collapseStdout:r,thinkingClassName:i,hideAssistantMessages:a,hiddenAssistantMessageText:o,showDeveloperDiagnostics:l,onMarkdownLinkClick:c}){const u=x.useMemo(()=>Xyt(e,{hideAssistantMessages:a,hiddenAssistantMessageText:o}),[e,a,o]),{preludeBlocks:d,turns:f}=x.useMemo(()=>e6e(u,n,{showDeveloperDiagnostics:l}),[u,n,l]);return s.jsxs("div",{className:"space-y-3",children:[d.map((h,g)=>sH({block:h,index:g,density:t,presentation:"chat",collapseStdout:r,thinkingClassName:i,onMarkdownLinkClick:c})),f.map(h=>s.jsx(H6e,{turn:h,density:t,thinkingClassName:i,onMarkdownLinkClick:c},h.key))]})}function tvt(e){const t=[];for(const n of e){if(n.type==="command_group"){n.items.forEach((r,i)=>{t.push({key:`${n.ts}-command-${i}-${r.ts}`,block:{type:"tool",ts:r.ts,endTs:r.endTs,name:r.name,input:r.input,result:r.result,isError:r.isError,status:r.status}})});continue}if(n.type==="message"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="thinking"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="tool"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="todo_list"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="activity"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="memory_update"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="event"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n})}return t}function nvt({entries:e,density:t,streaming:n,thinkingClassName:r,showDeveloperDiagnostics:i,onMarkdownLinkClick:a}){const{preludeBlocks:o,turns:l}=x.useMemo(()=>e6e(e,n,{showDeveloperDiagnostics:i}),[e,n,i]),c=tvt(o);return s.jsxs("div",{className:"space-y-3",children:[c.map(u=>s.jsxs(x.Fragment,{children:[u.block.type==="message"&&s.jsx(D6e,{block:u.block,density:t,presentation:"detail",className:"text-sm leading-7",collapsibleSummary:u.block.role==="user",onMarkdownLinkClick:a}),u.block.type==="thinking"&&s.jsx(L6e,{block:u.block,density:t,className:r,collapsibleSummary:!0,onMarkdownLinkClick:a}),u.block.type==="tool"&&s.jsx(iH,{block:u.block,density:t,presentation:"detail"}),u.block.type==="todo_list"&&s.jsx(U6e,{block:u.block,density:t,presentation:"detail"}),u.block.type==="activity"&&s.jsx(B6e,{block:u.block,density:t}),u.block.type==="event"&&s.jsx(q6e,{block:u.block,density:t,presentation:"detail"}),u.block.type==="stdout"&&s.jsx(K6e,{block:u.block,density:t,collapseByDefault:!0,presentation:"detail"})]},u.key)),l.map((u,d)=>s.jsx("div",{className:G(d===l.length-1&&n&&"animate-in fade-in slide-in-from-bottom-1 duration-300"),children:s.jsx(H6e,{turn:u,density:t,thinkingClassName:r,variant:"detail",onMarkdownLinkClick:a})},u.key))]})}function rvt({entries:e,density:t}){const n=t==="compact";return s.jsx("div",{className:G("font-mono",n?"space-y-1 text-[11px]":"space-y-1.5 text-xs"),children:e.map((r,i)=>s.jsxs("div",{className:G("grid gap-x-3","grid-cols-[auto_1fr]"),children:[s.jsx("span",{className:"text-[10px] tracking-[0.06em] text-muted-foreground",children:svt(r)}),s.jsx("pre",{className:"min-w-0 whitespace-pre-wrap break-words text-foreground/80",children:r.kind==="tool_call"?`${r.name}
|
|
@@ -1389,7 +1389,7 @@ ${rr(r.inputTokens)} / ${rr(r.outputTokens)} / $${r.costUsd.toFixed(6)}`:r.kind=
|
|
|
1389
1389
|
`)}const Lse=32;function r7e(e){return e===window}function Gvt(e){const t=window.getComputedStyle(e).overflowY;return t==="auto"||t==="scroll"||t==="overlay"}function Qvt(e){let t=(e==null?void 0:e.parentElement)??null;for(;t;){if(Gvt(t))return t;t=t.parentElement}return window}function ek(e){if(r7e(e)){const n=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),r=window.scrollY+window.innerHeight;return{scrollHeight:n,distanceFromBottom:Math.max(0,n-r)}}const t=e.scrollTop+e.clientHeight;return{scrollHeight:e.scrollHeight,distanceFromBottom:Math.max(0,e.scrollHeight-t)}}function $se(e,t="auto"){if(r7e(e)){const n=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);window.scrollTo({top:n,behavior:t});return}e.scrollTo({top:e.scrollHeight,behavior:t})}function Yvt(e){return e==="instructions"||e==="prompts"?"instructions":e==="configure"||e==="configuration"?"configuration":e==="skills"?"skills":e==="budget"?"budget":e==="runs"?e:"dashboard"}function by(e,...t){if(!e)return 0;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return 0}function Fse(e,...t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}return null}function Jvt(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function B4(e){const t=e.usageJson??null,n=e.resultJson??null,r=by(t,"inputTokens","input_tokens"),i=by(t,"outputTokens","output_tokens"),a=by(t,"cachedInputTokens","cached_input_tokens")+by(t,"cache_read_input_tokens")+by(t,"cache_creation_input_tokens"),o=Fse(t,"provider")??Fse(n,"provider"),l=hme(t,n),c=Nl({provider:o,inputTokens:r,cachedInputTokens:a,outputTokens:i});return{input:r,output:i,cached:a,uncachedInput:c.uncachedInputTokens,promptTokens:c.promptTokens,cost:l,totalTokens:c.totalTokens}}function Xvt(e){return Math.max(0,Math.floor(e)).toLocaleString()}function rf(e){return`${Xvt(e)} tokens`}function lH(e){return`${rr(e)} tokens`}function e6t(e,t){const n=UOe({inputTokens:t,cachedInputTokens:e});return n==null?"—":`${Math.round(n*100)}%`}function t6t(e){return e>0?`$${e.toFixed(4)}`:"—"}function LR(e,t){return e>0&&e/Math.max(1,t)*100>=9}function zse(e){return new TextEncoder().encode(e).length}function Bse(e){return`${e.ts}\0${e.stream}\0${e.chunk}`}function Ca(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function Nr(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function d3(e,t){const n=e==null?void 0:e[t];if(!Array.isArray(n))return[];const r=new Set,i=[];for(const a of n){const o=Ca(a),l=Nr(o==null?void 0:o.key)??Nr(o==null?void 0:o.runtimeName)??Nr(o==null?void 0:o.name);!l||r.has(l)||(r.add(l),i.push({key:l,label:Nr(o==null?void 0:o.runtimeName)??Nr(o==null?void 0:o.name)??l.split(/[/:]/).filter(Boolean).at(-1)??l}))}return i}function n6t({invocationPayload:e,usagePayload:t}){const n=[{key:"usedSkills",label:"Used by reading SKILL.md",skills:d3(t,"usedSkills")},{key:"runtimeUsedSkills",label:"Runtime reported",skills:d3(e,"usedSkills")},{key:"promptRequestedSkills",label:"Prompt requested",skills:d3(e,"promptRequestedSkills")},{key:"loadedSkills",label:"Loaded for run",skills:d3(e,"loadedSkills")}].filter(r=>r.skills.length>0);return n.length===0?null:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Skill usage"}),s.jsx("div",{className:"space-y-2",children:n.map(r=>s.jsxs("div",{className:"rounded-md border border-border/70 bg-background/60 px-2 py-1.5",children:[s.jsx("div",{className:"mb-1 text-[11px] font-medium text-muted-foreground",children:r.label}),s.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.skills.map(i=>s.jsx("span",{className:"rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium text-foreground",title:i.key,children:i.label},i.key))})]},r.key))})]})}function r6t(e){const t=[];for(const n of e.split(`
|
|
1390
1390
|
`)){const r=n.trim();if(r)try{const i=JSON.parse(r),a=i.stream==="stderr"||i.stream==="system"?i.stream:"stdout",o=typeof i.chunk=="string"?i.chunk:"",l=typeof i.ts=="string"?i.ts:new Date().toISOString();if(!o)continue;t.push({ts:l,stream:a,chunk:o})}catch{}}return t}function s6t({events:e,censorUsernameInLogs:t}){if(e.length===0)return null;const n={info:"text-foreground",warn:"text-yellow-600 dark:text-yellow-400",error:"text-red-600 dark:text-red-400"},r={stdout:"text-foreground",stderr:"text-red-600 dark:text-red-300",system:"text-blue-600 dark:text-blue-300"};return s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Events (",e.length,")"]}),s.jsx("div",{className:"rounded-lg bg-neutral-100 p-3 font-mono text-xs space-y-0.5 dark:bg-neutral-950",children:e.map(i=>{const a=i.color??(i.level?n[i.level]:null)??(i.stream?r[i.stream]:null)??"text-foreground",o=t7e(i,{redactText:l=>Nu(l,t),redactValue:l=>Lh(l,t)});return s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-neutral-400 dark:text-neutral-600 shrink-0 select-none w-16",children:new Date(i.createdAt).toLocaleTimeString("en-US",{hourCycle:"h23"})}),s.jsx("span",{className:G("shrink-0 w-14",i.stream?r[i.stream]??"text-neutral-500":"text-neutral-500"),children:i.stream?`[${i.stream}]`:""}),s.jsx("span",{className:G("break-all",a),children:o})]},i.id)})})]})}function i6t(e){switch(e){case"worktree_prepare":return"Worktree setup";case"workspace_provision":return"Provision";case"workspace_teardown":return"Teardown";case"worktree_cleanup":return"Worktree cleanup";default:return e}}function a6t(e){switch(e){case"succeeded":return"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-300";case"failed":return"border-red-500/20 bg-red-500/10 text-red-700 dark:text-red-300";case"running":return"border-cyan-500/20 bg-cyan-500/10 text-cyan-700 dark:text-cyan-300";case"skipped":return"border-yellow-500/20 bg-yellow-500/10 text-yellow-700 dark:text-yellow-300";default:return"border-border bg-muted/40 text-muted-foreground"}}function o6t({status:e}){return s.jsx("span",{className:G("inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium capitalize",a6t(e)),children:e.replace("_"," ")})}function l6t({operation:e,censorUsernameInLogs:t}){const[n,r]=x.useState(!1),{data:i,isLoading:a,error:o}=Ne({queryKey:["workspace-operation-log",e.id],queryFn:()=>xs.workspaceOperationLog(e.id),enabled:n&&!!e.logRef,refetchInterval:n&&e.status==="running"?2e3:!1}),l=x.useMemo(()=>i!=null&&i.content?r6t(i.content):[],[i==null?void 0:i.content]);return s.jsxs("div",{className:"space-y-2",children:[s.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground",onClick:()=>r(c=>!c),children:n?"Hide full log":"Show full log"}),n&&s.jsxs("div",{className:"rounded-md border border-border bg-background/70 p-2",children:[a&&s.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading log..."}),o&&s.jsx("div",{className:"text-xs text-destructive",children:o instanceof Error?o.message:"Failed to load workspace operation log"}),!a&&!o&&l.length===0&&s.jsx("div",{className:"text-xs text-muted-foreground",children:"No persisted log lines."}),l.length>0&&s.jsx("div",{className:"max-h-64 overflow-y-auto rounded bg-neutral-100 p-2 font-mono text-xs dark:bg-neutral-950",children:l.map((c,u)=>s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"shrink-0 text-neutral-500",children:new Date(c.ts).toLocaleTimeString("en-US",{hourCycle:"h23"})}),s.jsxs("span",{className:G("shrink-0 w-14",c.stream==="stderr"?"text-red-600 dark:text-red-300":c.stream==="system"?"text-blue-600 dark:text-blue-300":"text-muted-foreground"),children:["[",c.stream,"]"]}),s.jsx("span",{className:"whitespace-pre-wrap break-all",children:Nu(c.chunk,t)})]},`${c.ts}-${u}`))})]})]})}function c6t({operations:e,censorUsernameInLogs:t}){return e.length===0?null:s.jsxs("div",{className:"rounded-lg border border-border bg-background/60 p-3 space-y-3",children:[s.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:["Workspace (",e.length,")"]}),s.jsx("div",{className:"space-y-3",children:e.map(n=>{const r=Ca(n.metadata);return s.jsxs("div",{className:"rounded-md border border-border/70 bg-background/70 p-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"text-sm font-medium",children:i6t(n.phase)}),s.jsx(o6t,{status:n.status}),s.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[js(n.startedAt),n.finishedAt&&` to ${js(n.finishedAt)}`]})]}),n.command&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Command: "}),s.jsx("span",{className:"font-mono",children:n.command})]}),n.cwd&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),s.jsx("span",{className:"font-mono",children:n.cwd})]}),(Nr(r==null?void 0:r.branchName)||Nr(r==null?void 0:r.baseRef)||Nr(r==null?void 0:r.worktreePath)||Nr(r==null?void 0:r.repoRoot)||Nr(r==null?void 0:r.cleanupAction))&&s.jsxs("div",{className:"grid gap-1 text-xs sm:grid-cols-2",children:[Nr(r==null?void 0:r.branchName)&&s.jsxs("div",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Branch: "}),s.jsx("span",{className:"font-mono",children:r==null?void 0:r.branchName})]}),Nr(r==null?void 0:r.baseRef)&&s.jsxs("div",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Base ref: "}),s.jsx("span",{className:"font-mono",children:r==null?void 0:r.baseRef})]}),Nr(r==null?void 0:r.worktreePath)&&s.jsxs("div",{className:"break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Worktree: "}),s.jsx("span",{className:"font-mono",children:r==null?void 0:r.worktreePath})]}),Nr(r==null?void 0:r.repoRoot)&&s.jsxs("div",{className:"break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Repo root: "}),s.jsx("span",{className:"font-mono",children:r==null?void 0:r.repoRoot})]}),Nr(r==null?void 0:r.cleanupAction)&&s.jsxs("div",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Cleanup: "}),s.jsx("span",{className:"font-mono",children:r==null?void 0:r.cleanupAction})]})]}),typeof(r==null?void 0:r.created)=="boolean"&&s.jsx("div",{className:"text-xs text-muted-foreground",children:r.created?"Created by this run":"Reused existing workspace"}),n.stderrExcerpt&&n.stderrExcerpt.trim()&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-red-700 dark:text-red-300",children:"stderr excerpt"}),s.jsx("pre",{className:"rounded-md bg-red-50 p-2 text-xs whitespace-pre-wrap break-all text-red-800 dark:bg-neutral-950 dark:text-red-100",children:Nu(n.stderrExcerpt,t)})]}),n.stdoutExcerpt&&n.stdoutExcerpt.trim()&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"stdout excerpt"}),s.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs whitespace-pre-wrap break-all dark:bg-neutral-950",children:Nu(n.stdoutExcerpt,t)})]}),n.logRef&&s.jsx(l6t,{operation:n,censorUsernameInLogs:t})]},n.id)})})]})}function cH(e){const[t,n]=x.useState(()=>Date.now());return x.useEffect(()=>{if(!e)return;const r=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(r)},[e]),t}function $R(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function yy(e){return typeof e=="string"&&e.trim()?e.trim():null}function FR(e){return e.replaceAll("_"," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}function s7e(e){const t=$R(e.contextSnapshot),n=yy(t==null?void 0:t.wakeReason),r=yy(t==null?void 0:t.wakeSource)??yy(t==null?void 0:t.source),i=$R(t==null?void 0:t.recovery),a=$R(t==null?void 0:t.passiveFollowup);if(a||n==="issue_passive_followup"){const o=typeof(a==null?void 0:a.attempt)=="number"?a.attempt:null,l=typeof(a==null?void 0:a.maxAttempts)=="number"?a.maxAttempts:null;return{label:o&&l?`Follow-up ${o}/${l}`:"Follow-up",description:"Rudder started this run because the previous issue run did not leave a clear close-out.",tone:"followup"}}if(i||n==="process_lost_retry"){const o=yy(i==null?void 0:i.recoveryTrigger),l=yy(i==null?void 0:i.failureKind),c=o==="manual"||n==="retry_failed_run"||!!e.retryOfRunId;return{label:c?"Retry":"Recovery",description:l?`Rudder started this run to recover from ${FR(l).toLowerCase()}.`:c?"A user retried a failed or timed-out run.":"Rudder started this run to recover interrupted agent work.",tone:"recovery"}}switch(n){case"heartbeat_timer":return{label:"Scheduled heartbeat",description:"The agent's heartbeat schedule reached its next run time.",tone:"scheduled"};case"issue_assigned":return{label:"Task assigned",description:"This run started because an issue was assigned to the agent.",tone:"task"};case"issue_review_requested":return{label:"Review requested",description:"This run started because an issue is ready for this agent to review.",tone:"task"};case"issue_convergence_review_requested":return{label:"Convergence review",description:"This run started because the assignee did not converge the issue after follow-up.",tone:"followup"};case"issue_changes_requested":return{label:"Changes requested",description:"This run started because a reviewer requested changes on the issue.",tone:"task"};case"issue_commented":return{label:"Comment added",description:"This run started because someone commented on the agent's active issue.",tone:"followup"};case"issue_comment_mentioned":return{label:"Mentioned",description:"This run started because the agent was mentioned in an issue comment.",tone:"followup"};case"issue_reopened_via_comment":return{label:"Issue reopened",description:"This run started because a comment reopened the issue.",tone:"followup"};case"issue_status_changed":return{label:"Issue activated",description:"This run started because an assigned issue moved into active work.",tone:"task"};case"retry_failed_run":return{label:"Retry",description:"A user retried a failed or timed-out run.",tone:"recovery"};case"issue_execution_promoted":return{label:"Resumed task",description:"A deferred issue run was promoted after the agent became available.",tone:"task"}}return e.invocationSource==="timer"?{label:"Scheduled heartbeat",description:"The agent's heartbeat schedule started this run.",tone:"scheduled"}:e.invocationSource==="on_demand"?{label:e.triggerDetail==="ping"?"API heartbeat":"Manual heartbeat",description:e.triggerDetail==="ping"?"An API request manually woke the agent.":"A user manually started this heartbeat.",tone:"manual"}:e.invocationSource==="assignment"?{label:"Task assigned",description:"This run started because work was assigned to the agent.",tone:"task"}:e.invocationSource==="review"?{label:"Review requested",description:"This run started because an issue was routed to this agent for review.",tone:"task"}:r==="comment.mention"?{label:"Mentioned",description:"This run started because the agent was mentioned in an issue comment.",tone:"followup"}:n?{label:FR(n),description:`Rudder started this run because: ${FR(n).toLowerCase()}.`,tone:"auto"}:{label:"Auto run",description:"Rudder started this run automatically, but no more specific reason was recorded.",tone:"auto"}}function i7e(e){switch(e){case"scheduled":return"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300";case"manual":return"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300";case"task":return"bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300";case"followup":return"bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-300";case"recovery":return"bg-orange-100 text-orange-800 dark:bg-orange-900/50 dark:text-orange-300";case"auto":return"bg-muted text-muted-foreground"}}const u6t="workspace_permission_repair_needed";function uH(e){return _ve(e.stderrExcerpt??"")}function d6t(e){return uH(e)?e.status==="failed"||e.status==="timed_out":!1}function f6t(e){return e.errorCode===u6t}function dH(e){return!e.error&&!e.errorCode?null:f6t(e)?{title:"Workspace permission repair needed",body:e.error??"Rudder could not verify write access to its managed agent workspace before starting the run.",code:e.errorCode,actionLabel:"Open instance details",actionPath:"/instance/settings/about"}:{title:"Run failed",body:e.error??e.errorCode??"Run exited with an error.",code:e.errorCode}}function pu({leading:e,identifier:t,title:n,subtitle:r,trailing:i,selected:a,to:o,onClick:l,className:c}){const d=G("flex items-center gap-3 border-b panel-divider px-4 py-3 text-sm transition-[background-color,border-color,box-shadow]",!!(o||l)&&"cursor-pointer hover:bg-[color:color-mix(in_oklab,var(--surface-active)_58%,transparent)]",a&&"bg-[color:color-mix(in_oklab,var(--surface-active)_68%,transparent)]",c),f=s.jsxs(s.Fragment,{children:[e&&s.jsx("div",{className:"flex items-center gap-2 shrink-0",children:e}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx("span",{className:"relative top-[1px] shrink-0 font-mono text-[11px] text-muted-foreground",children:t}),s.jsx("span",{className:"truncate font-medium text-foreground",children:n})]}),r&&s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:r})]}),i&&s.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i})]});return o?s.jsx(yt,{to:o,className:G(d,"no-underline text-inherit"),onClick:l,children:f}):s.jsx("div",{className:d,onClick:l,children:f})}function m6t(e){return e.status==="queued"||e.status==="running"}function fH(e,t=Date.now()){const n=e.startedAt??e.createdAt,r=m6t(e),i=WS(n,r?null:e.finishedAt,t);return r?e.status==="queued"?i?`Queued for ${i}`:"Queued":i?`Live for ${i}`:"Live":e.finishedAt&&i?`Ran for ${i}`:e.startedAt&&i?`Ran for ${i}`:null}function mH(e){const t=[];return e.startedAt&&t.push(`Started ${wi(e.startedAt)}`),e.finishedAt&&t.push(`Finished ${wi(e.finishedAt)}`),t.length===0&&e.createdAt&&t.push(`Created ${wi(e.createdAt)}`),t.join(" · ")}function h6t({agentId:e,orgId:t}){const n=vn(),[r,i]=x.useState(""),[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(!1),{data:f,isLoading:h}=Ne({queryKey:q.agents.keys(e),queryFn:()=>Bt.listKeys(e,t)}),g=nt({mutationFn:()=>Bt.createKey(e,r.trim()||"Default",t),onSuccess:w=>{o(w.token),c(!0),i(""),n.invalidateQueries({queryKey:q.agents.keys(e)})}}),b=nt({mutationFn:w=>Bt.revokeKey(e,w,t),onSuccess:()=>{n.invalidateQueries({queryKey:q.agents.keys(e)})}});function v(){a&&(navigator.clipboard.writeText(a),d(!0),setTimeout(()=>d(!1),2e3))}const j=(f??[]).filter(w=>!w.revokedAt),k=(f??[]).filter(w=>w.revokedAt);return s.jsxs("div",{className:"space-y-6",children:[a&&s.jsxs("div",{className:"border border-yellow-300 dark:border-yellow-600/40 bg-yellow-50 dark:bg-yellow-500/5 rounded-lg p-4 space-y-2",children:[s.jsx("p",{className:"text-sm font-medium text-yellow-700 dark:text-yellow-400",children:"API key created — copy it now, it will not be shown again."}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"flex-1 bg-neutral-100 dark:bg-neutral-950 rounded px-3 py-1.5 text-xs font-mono text-green-700 dark:text-green-300 truncate",children:l?a:a.replace(/./g,"•")}),s.jsx(ce,{variant:"ghost",size:"icon-sm",onClick:()=>c(w=>!w),title:l?"Hide":"Show",children:l?s.jsx(Ap,{className:"h-3.5 w-3.5"}):s.jsx(x1,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{variant:"ghost",size:"icon-sm",onClick:v,title:"Copy",children:s.jsx(Ni,{className:"h-3.5 w-3.5"})}),u&&s.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),s.jsx(ce,{variant:"ghost",size:"sm",className:"text-muted-foreground text-xs",onClick:()=>o(null),children:"Dismiss"})]}),s.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[s.jsxs("h3",{className:"text-xs font-medium text-muted-foreground flex items-center gap-2",children:[s.jsx(HLe,{className:"h-3.5 w-3.5"}),"Create API Key"]}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"API keys allow this agent to authenticate calls to the Rudder server."}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{placeholder:"Key name (e.g. production)",value:r,onChange:w=>i(w.target.value),className:"h-8 text-sm",onKeyDown:w=>{w.key==="Enter"&&g.mutate()}}),s.jsxs(ce,{size:"sm",onClick:()=>g.mutate(),disabled:g.isPending,children:[s.jsx(tr,{className:"h-3.5 w-3.5 mr-1"}),"Create"]})]})]}),h&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading keys..."}),!h&&j.length===0&&!a&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"No active API keys."}),j.length>0&&s.jsxs("div",{children:[s.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Active Keys"}),s.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:j.map(w=>s.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-sm font-medium",children:w.name}),s.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Created ",Ha(w.createdAt)]})]}),s.jsx(ce,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive text-xs",onClick:()=>b.mutate(w.id),disabled:b.isPending,children:"Revoke"})]},w.id))})]}),k.length>0&&s.jsxs("div",{children:[s.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Revoked Keys"}),s.jsx("div",{className:"border border-border rounded-lg divide-y divide-border opacity-50",children:k.map(w=>s.jsx("div",{className:"flex items-center justify-between px-4 py-2.5",children:s.jsxs("div",{children:[s.jsx("span",{className:"text-sm line-through",children:w.name}),s.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Revoked ",w.revokedAt?Ha(w.revokedAt):""]})]})},w.id))})]})]})}function p6t({runs:e,agentId:t}){const n=cH(e.some(b=>b.status==="running"||b.status==="queued"));if(e.length===0)return null;const r=[...e].sort((b,v)=>new Date(v.createdAt).getTime()-new Date(b.createdAt).getTime()),a=r.find(b=>b.status==="running"||b.status==="queued")??r[0],o=a.status==="running"||a.status==="queued",l=n7e[a.status]??{icon:GS,color:"text-neutral-400"},c=l.icon,u=s7e(a),d=fH(a,n)??js(a.createdAt),f=mH(a),h=dH(a),g=a.resultJson?String(a.resultJson.summary??a.resultJson.result??""):h?`${h.title}: ${h.body}`:"";return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex w-full items-center justify-between",children:[s.jsxs("h3",{className:"flex items-center gap-2 text-sm font-medium",children:[o&&s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),o?"Live Run":"Latest Run"]}),s.jsx(yt,{to:`/agents/${t}/runs/${a.id}`,className:"shrink-0 text-xs text-muted-foreground hover:text-foreground transition-colors no-underline",children:"View details →"})]}),s.jsxs(yt,{to:`/agents/${t}/runs/${a.id}`,className:G("block border rounded-lg p-4 space-y-2 w-full no-underline transition-colors hover:bg-muted/50 cursor-pointer",o?"border-cyan-500/30 shadow-[0_0_12px_rgba(6,182,212,0.08)]":"border-border"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(c,{className:G("h-3.5 w-3.5",l.color,a.status==="running"&&"animate-spin")}),s.jsx(er,{status:a.status}),s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:a.id.slice(0,8)}),s.jsx("span",{className:G("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium",i7e(u.tone)),title:u.description,children:u.label}),s.jsx("span",{className:"ml-auto shrink-0 text-xs font-medium tabular-nums text-foreground",title:f||void 0,children:d})]}),g&&s.jsx("div",{className:"overflow-hidden max-h-16",children:s.jsx(Aa,{className:"[&>*:first-child]:mt-0 [&>*:last-child]:mb-0",children:g})})]})]})}function g6t({agent:e,runs:t,chartRuns:n,assignedIssues:r,chartIssues:i,runtimeState:a,skillAnalytics:o,agentId:l,agentRouteId:c,rangeLabel:u,chartDays:d,showDashboardFilters:f,dateFilterControl:h}){const g=o&&o.totalRunsWithSkills>0?o:null,b=g!==null;return s.jsxs("div",{className:"space-y-8",children:[h,s.jsx(p6t,{runs:t,agentId:c}),s.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[s.jsx(Rf,{title:"Run Activity",subtitle:`${u} · relative daily run volume · hover for details`,children:s.jsx(V6e,{runs:n,days:d})}),s.jsx(Rf,{title:"Issues by Priority",subtitle:`${u} · relative daily issue volume · hover for details`,children:s.jsx(aH,{issues:i,days:d})}),s.jsx(Rf,{title:"Issues by Status",subtitle:`${u} · relative daily issue volume · hover for details`,children:s.jsx(oH,{issues:i,days:d})}),s.jsx(Rf,{title:"Success Rate",subtitle:`${u} · daily success rate · hover for details`,children:s.jsx(W6e,{runs:n,days:d})})]}),f&&b?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-end justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium",children:"Skills"}),s.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Skill usage per run for ",u,". Hover a day to inspect the breakdown."]})]}),s.jsxs("div",{className:"text-right text-[11px] text-muted-foreground tabular-nums",children:[s.jsxs("div",{children:[g.totalCount," skill uses"]}),s.jsxs("div",{children:[g.totalRunsWithSkills," runs with skill usage"]})]})]}),s.jsx(Z6e,{analytics:g})]}):null,s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h3",{className:"text-sm font-medium",children:"Recent Issues"}),s.jsx(yt,{to:`/issues?participantAgentId=${l}`,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"See All →"})]}),r.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No recent issues."}):s.jsxs("div",{className:"border border-border rounded-lg",children:[r.slice(0,10).map(v=>s.jsx(pu,{identifier:v.identifier??v.id.slice(0,8),title:v.title,to:`/issues/${v.identifier??v.id}`,trailing:s.jsx(er,{status:v.status})},v.id)),r.length>10&&s.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground text-center border-t border-border",children:["+",r.length-10," more issues"]})]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-sm font-medium",children:"Costs"}),s.jsx(x6t,{runtimeState:a,runs:t,agentRouteId:c})]})]})}function x6t({runtimeState:e,runs:t,agentRouteId:n}){const r=t.map(d=>({run:d,metrics:B4(d)})).filter(({metrics:d})=>d.cost>0||d.input>0||d.output>0||d.cached>0).sort((d,f)=>new Date(f.run.createdAt).getTime()-new Date(d.run.createdAt).getTime()).slice(0,10),i=Math.max(1,...r.map(({metrics:d})=>d.totalTokens)),[a,o]=x.useState(null),l=Math.round(i/2),c=e?Nl({inputTokens:e.totalInputTokens,cachedInputTokens:e.totalCachedInputTokens,outputTokens:e.totalOutputTokens}):null,u=e?e6t(e.totalCachedInputTokens,e.totalInputTokens):"—";return s.jsxs("div",{className:"space-y-4",children:[e&&s.jsx("div",{className:"border border-border rounded-lg p-4",children:s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 tabular-nums",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-muted-foreground block",children:"Prompt input"}),s.jsx("span",{className:"text-lg font-semibold",children:rr((c==null?void 0:c.promptTokens)??e.totalInputTokens)})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-muted-foreground block",children:"Output tokens"}),s.jsx("span",{className:"text-lg font-semibold",children:rr(e.totalOutputTokens)})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-muted-foreground block",children:"Cached input"}),s.jsx("span",{className:"text-lg font-semibold",children:rr(e.totalCachedInputTokens)})]}),s.jsxs("div",{title:"Cached input tokens divided by total prompt input tokens.",children:[s.jsx("span",{className:"text-xs text-muted-foreground block",children:"Cache ratio"}),s.jsx("span",{className:"text-lg font-semibold",children:u})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-muted-foreground block",children:"Total cost"}),s.jsx("span",{className:"text-lg font-semibold",children:Dn(e.totalCostCents)})]})]})}),r.length>0?s.jsxs("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"agent-run-cost-chart",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border bg-accent/20 px-3 py-2 text-xs text-muted-foreground",children:[s.jsx("span",{children:"Recent run token mix"}),s.jsxs("div",{className:"flex items-center gap-3","data-testid":"agent-run-cost-legend",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-2 w-2 rounded-sm bg-sky-500"}),"Uncached input"]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-2 w-2 rounded-sm bg-violet-500"}),"Cached input"]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-2 w-2 rounded-sm bg-emerald-500"}),"Output"]})]})]}),s.jsx("div",{className:"divide-y divide-border",children:r.map(({run:d,metrics:f})=>{const h=f.totalTokens,g=h>0?Math.max(7,h/i*100):0,b=h>0?f.uncachedInput/h*100:0,v=h>0?f.cached/h*100:0,j=h>0?f.output/h*100:0,k=LR(f.uncachedInput,i),w=LR(f.cached,i),N=LR(f.output,i),C=d.id.slice(0,8),A=t6t(f.cost),_=`Run ${C} cost and token usage: ${rf(h)} total, ${rf(f.promptTokens)} prompt input, ${rf(f.uncachedInput)} uncached input, ${rf(f.cached)} cached input, ${rf(f.output)} output, ${A} cost`;return s.jsx(P1,{delayDuration:120,children:s.jsxs(za,{open:a===d.id,children:[s.jsx(Ba,{asChild:!0,children:s.jsxs(yt,{to:`/agents/${n}/runs/${d.id}`,"aria-label":_,"data-testid":"agent-run-cost-row",onFocus:()=>o(d.id),onBlur:()=>o(E=>E===d.id?null:E),onMouseEnter:()=>o(d.id),onMouseLeave:E=>{E.currentTarget!==document.activeElement&&o(T=>T===d.id?null:T)},className:"group grid grid-cols-[minmax(5.5rem,7rem)_minmax(0,1fr)_auto] items-center gap-3 px-3 py-3 text-xs no-underline text-inherit outline-none transition-colors hover:bg-accent/25 focus-visible:bg-accent/25 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",children:[s.jsxs("span",{className:"min-w-0 space-y-0.5",children:[s.jsx("span",{className:"block truncate text-muted-foreground",children:Ha(d.createdAt)}),s.jsx("span",{className:"block font-mono tabular-nums text-foreground",children:C})]}),s.jsx("span",{className:"relative h-9 rounded-sm bg-muted/45",style:{backgroundImage:"linear-gradient(to right, hsl(var(--border) / 0.75) 1px, transparent 1px)",backgroundSize:"25% 100%"},children:s.jsxs("span",{className:"relative z-10 flex h-full overflow-hidden rounded-sm border border-background/50 shadow-sm transition-opacity group-hover:opacity-95 group-focus-visible:opacity-95",style:{width:`${g}%`},children:[f.uncachedInput>0?s.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-sky-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${b}%`},children:k?rr(f.uncachedInput):null}):null,f.cached>0?s.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-violet-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${v}%`},children:w?rr(f.cached):null}):null,f.output>0?s.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-emerald-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${j}%`},children:N?rr(f.output):null}):null]})}),s.jsxs("span",{className:"min-w-[8.75rem] text-right tabular-nums",children:[s.jsx("span",{className:"block font-medium text-foreground",children:lH(h)}),s.jsxs("span",{className:"block font-mono text-[10px] text-muted-foreground",children:["in ",rr(f.promptTokens)," · cache ",rr(f.cached)," · out ",rr(f.output)]}),f.cost>0?s.jsx("span",{className:"block font-mono text-[11px] text-muted-foreground",children:A}):null]})]})}),s.jsx(Ua,{side:"top",align:"end",sideOffset:8,className:"w-72 p-3 text-xs",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"font-medium text-background",children:["Run ",C]}),s.jsx("div",{className:"font-mono text-[11px] text-background/70",children:d.id}),s.jsx("div",{className:"text-background/70",children:wi(d.createdAt)})]}),s.jsxs("dl",{className:"grid grid-cols-[1fr_auto] gap-x-4 gap-y-1.5",children:[s.jsx("dt",{className:"text-background/70",children:"Total tokens"}),s.jsx("dd",{className:"font-mono tabular-nums",children:rf(h)}),s.jsx("dt",{className:"text-background/70",children:"Prompt input"}),s.jsx("dd",{className:"font-mono tabular-nums",children:rf(f.promptTokens)}),s.jsx("dt",{className:"text-background/70",children:"Uncached input"}),s.jsx("dd",{className:"font-mono tabular-nums",children:rf(f.uncachedInput)}),s.jsx("dt",{className:"text-background/70",children:"Cached input"}),s.jsx("dd",{className:"font-mono tabular-nums",children:rf(f.cached)}),s.jsx("dt",{className:"text-background/70",children:"Output"}),s.jsx("dd",{className:"font-mono tabular-nums",children:rf(f.output)}),s.jsx("dt",{className:"text-background/70",children:"Cost"}),s.jsx("dd",{className:"font-mono tabular-nums",children:A})]})]})})]})},d.id)})}),s.jsxs("div",{className:"grid grid-cols-[minmax(5.5rem,7rem)_minmax(0,1fr)_minmax(7rem,auto)] gap-3 border-t border-border px-3 py-2 text-[10px] text-muted-foreground",children:[s.jsx("span",{}),s.jsxs("div",{className:"flex justify-between tabular-nums",children:[s.jsx("span",{children:"0"}),s.jsx("span",{children:rr(l)}),s.jsx("span",{children:rr(i)})]}),s.jsx("span",{className:"text-right",children:"Token scale"})]})]}):s.jsx("p",{className:"rounded-lg border border-dashed border-border px-3 py-4 text-sm text-muted-foreground",children:"No run cost or token data yet."})]})}function b6t({agent:e,agentId:t,orgId:n,onDirtyChange:r,onSaveActionChange:i,onCancelActionChange:a,onSavingChange:o,updatePermissions:l}){const c=vn(),[u,d]=x.useState(!1),{data:f}=Ne({queryKey:q.agents.configRevisions(e.id),queryFn:()=>Bt.listConfigRevisions(e.id,n)}),h=nt({mutationFn:g=>Bt.rollbackConfigRevision(e.id,g,n),onSuccess:()=>{c.invalidateQueries({queryKey:q.agents.detail(e.id)}),c.invalidateQueries({queryKey:q.agents.detail(e.urlKey)}),c.invalidateQueries({queryKey:q.agents.configRevisions(e.id)})}});return s.jsxs("div",{className:"max-w-3xl space-y-6",children:[s.jsx(y6t,{agent:e,onDirtyChange:r,onSaveActionChange:i,onCancelActionChange:a,onSavingChange:o,updatePermissions:l,orgId:n,hidePromptTemplate:!0,hideInstructionsFile:!0}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium mb-3",children:"API Keys"}),s.jsx(h6t,{agentId:t,orgId:n})]}),s.jsxs("div",{children:[s.jsxs("button",{className:"flex items-center gap-2 text-sm font-medium hover:text-foreground transition-colors",onClick:()=>d(g=>!g),children:[u?s.jsx(fr,{className:"h-3.5 w-3.5 text-muted-foreground"}):s.jsx(Ls,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Configuration Revisions",s.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:(f==null?void 0:f.length)??0})]}),u&&s.jsx("div",{className:"mt-3",children:(f??[]).length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No configuration revisions yet."}):s.jsx("div",{className:"space-y-2",children:(f??[]).slice(0,10).map(g=>s.jsxs("div",{className:"border border-border/70 rounded-md p-3 space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:g.id.slice(0,8)}),s.jsx("span",{className:"mx-1",children:"·"}),s.jsx("span",{children:Ha(g.createdAt)}),s.jsx("span",{className:"mx-1",children:"·"}),s.jsx("span",{children:g.source})]}),s.jsx(ce,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",onClick:()=>h.mutate(g.id),disabled:h.isPending,children:"Restore"})]}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["Changed:"," ",g.changedKeys.length>0?g.changedKeys.join(", "):"no tracked changes"]})]},g.id))})})]})]})}function y6t({agent:e,orgId:t,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:i,onSavingChange:a,updatePermissions:o,hidePromptTemplate:l,hideInstructionsFile:c}){var _,E,T;const u=vn(),{pushToast:d}=_r(),[f,h]=x.useState(!1),g=x.useRef(e),{data:b}=Ne({queryKey:t?q.agents.adapterModels(t,e.agentRuntimeType):["agents","none","adapter-models",e.agentRuntimeType],queryFn:()=>Bt.adapterModels(t,e.agentRuntimeType),enabled:!!t}),v=nt({mutationFn:M=>Bt.update(e.id,M,t),onMutate:()=>{h(!0)},onSuccess:()=>{u.invalidateQueries({queryKey:q.agents.detail(e.id)}),u.invalidateQueries({queryKey:q.agents.detail(e.urlKey)}),u.invalidateQueries({queryKey:q.agents.configRevisions(e.id)}),u.invalidateQueries({queryKey:q.agents.list(e.orgId)})},onError:M=>{h(!1);const O=M instanceof Ml||M instanceof Error?M.message:"Could not save agent";d({title:"Save failed",body:O,tone:"error"})}});x.useEffect(()=>{f&&e!==g.current&&h(!1),g.current=e},[e,f]);const j=v.isPending||f;x.useEffect(()=>{a(j)},[a,j]);const k=!!((_=e.permissions)!=null&&_.canCreateAgents),w=!!((E=e.access)!=null&&E.canAssignTasks),N=((T=e.access)==null?void 0:T.taskAssignSource)??"none",C=e.role==="ceo"||k,A=N==="ceo_role"?"Enabled automatically for CEO agents.":N==="agent_creator"?"Enabled automatically while this agent can create new agents.":N==="explicit_grant"?"Enabled via explicit organization permission grant.":"Disabled unless explicitly granted.";return s.jsxs("div",{className:"space-y-6",children:[s.jsx(FK,{mode:"edit",agent:e,onSave:M=>v.mutate(M),isSaving:j,adapterModels:b,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:i,hideInlineSave:!0,hidePromptTemplate:l,hideInstructionsFile:c,sectionLayout:"cards"}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium mb-3",children:"Permissions"}),s.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{children:"Can create new agents"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Lets this agent create or hire agents and implicitly assign tasks."})]}),s.jsx(Vf,{checked:k,size:"sm",tone:"success","aria-label":"Can create new agents",className:"shrink-0",onClick:()=>o.mutate({canCreateAgents:!k,canAssignTasks:k?w:!0}),disabled:o.isPending})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{children:"Can assign tasks"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:A})]}),s.jsx(Vf,{checked:w,size:"sm",tone:"success","aria-label":"Can assign tasks",className:"shrink-0",onClick:()=>o.mutate({canCreateAgents:k,canAssignTasks:!w}),disabled:o.isPending||C})]})]})]})]})}function O2({text:e,children:t,className:n,containerClassName:r,ariaLabel:i,title:a,copiedLabel:o="Copied!"}){const[l,c]=x.useState(!1),[u,d]=x.useState(o),f=x.useRef(void 0),h=x.useRef(null),g=x.useCallback(async()=>{try{await navigator.clipboard.writeText(e),d(o)}catch{d("Copy failed")}clearTimeout(f.current),c(!0),f.current=setTimeout(()=>c(!1),1500)},[o,e]);return s.jsxs("span",{className:G("relative inline-flex",r),children:[s.jsx("button",{ref:h,type:"button",className:G("cursor-copy hover:text-foreground transition-colors",n),onClick:g,"aria-label":i,title:a,children:t??e}),s.jsx("span",{role:"status","aria-live":"polite",className:G("pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1.5 rounded-md bg-foreground text-background px-2 py-1 text-xs whitespace-nowrap transition-opacity duration-300",l?"opacity-100":"opacity-0"),children:u})]})}const Use=16,qse=24,Kse="min-h-9";function P2(e,t){const n={children:[]};for(const i of Object.keys(e)){const a=i.split("/").filter(Boolean);let o=n,l="";for(let c=0;c<a.length;c++){const u=a[c];l=l?`${l}/${u}`:u;const d=c===a.length-1;let f=o.children.find(h=>h.name===u);f||(f={name:u,path:l,kind:d?"file":"dir",children:[],action:d?(t==null?void 0:t.get(i))??null:null},o.children.push(f)),o=f}}function r(i){i.children.sort((a,o)=>a.kind!==o.kind?a.kind==="file"?-1:1:a.name.localeCompare(o.name)),i.children.forEach(r)}return r(n),n.children}function hH(e){let t=0;for(const n of e)n.kind==="file"?t++:t+=hH(n.children);return t}function m8(e,t="all"){const n=new Set;for(const r of e){(t==="all"||r.kind===t)&&n.add(r.path);for(const i of m8(r.children,t))n.add(i)}return n}function v6t(e){return e.endsWith(".yaml")||e.endsWith(".yml")?QS:Nd}function a7e(e){const t=e.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);if(!t)return null;const n={},r=t[1],i=t[2];let a=null,o=null;for(const l of r.split(`
|
|
1391
1391
|
`)){const c=l.trim();if(!c||c.startsWith("#"))continue;if(c.startsWith("- ")&&a){o||(o=[]),o.push(c.slice(2).trim().replace(/^["']|["']$/g,""));continue}a&&o&&(n[a]=o,o=null,a=null);const u=c.match(/^([a-zA-Z_][\w-]*)\s*:\s*(.*)$/);if(u){const d=u[1],f=u[2].trim().replace(/^["']|["']$/g,"");if(f==="null"){a=null;continue}f?(n[d]=f,a=null):a=d}}return a&&o&&(n[a]=o),Object.keys(n).length>0?{data:n,body:i}:null}const o7e={name:"Name",title:"Title",kind:"Kind",reportsTo:"Reports to",skills:"Skills",status:"Status",description:"Description",priority:"Priority",assignee:"Assignee",project:"Project",recurring:"Recurring",targetDate:"Target date"};function U4({nodes:e,selectedFile:t,expandedDirs:n,checkedFiles:r,onToggleDir:i,onSelectFile:a,onToggleCheck:o,renderFileExtra:l,fileRowClassName:c,showCheckboxes:u=!0,depth:d=0}){const f=r??new Set;return s.jsx("div",{children:e.map(h=>{const g=h.kind==="dir"&&n.has(h.path);if(h.kind==="dir"){const k=m8(h.children,"file"),w=[...k].every(C=>f.has(C)),N=[...k].some(C=>f.has(C));return s.jsxs("div",{children:[s.jsxs("div",{className:G(u?"group grid w-full grid-cols-[auto_minmax(0,1fr)_2.25rem] items-center gap-x-1 pr-3 text-left text-sm text-muted-foreground hover:bg-accent/30 hover:text-foreground":"group grid w-full grid-cols-[minmax(0,1fr)_2.25rem] items-center gap-x-1 pr-3 text-left text-sm text-muted-foreground hover:bg-accent/30 hover:text-foreground",Kse),style:{paddingInlineStart:`${Use+d*qse-8}px`},children:[u&&s.jsx("label",{className:"flex items-center pl-2",children:s.jsx("input",{type:"checkbox",checked:w,ref:C=>{C&&(C.indeterminate=N&&!w)},onChange:()=>o==null?void 0:o(h.path,"dir"),className:"mr-2 accent-foreground"})}),s.jsxs("button",{type:"button",className:"flex min-w-0 items-center gap-2 py-1 text-left",onClick:()=>i(h.path),children:[s.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:g?s.jsx(C0,{className:"h-3.5 w-3.5"}):s.jsx(dc,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"truncate",children:h.name})]}),s.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center self-center rounded-sm text-muted-foreground opacity-70 transition-[background-color,color,opacity] hover:bg-accent hover:text-foreground group-hover:opacity-100",onClick:()=>i(h.path),children:g?s.jsx(fr,{className:"h-3.5 w-3.5"}):s.jsx(Ls,{className:"h-3.5 w-3.5"})})]}),g&&s.jsx(U4,{nodes:h.children,selectedFile:t,expandedDirs:n,checkedFiles:f,onToggleDir:i,onSelectFile:a,onToggleCheck:o,renderFileExtra:l,fileRowClassName:c,showCheckboxes:u,depth:d+1})]},h.path)}const b=v6t(h.name),v=f.has(h.path),j=c==null?void 0:c(h,v);return s.jsxs("div",{className:G("flex w-full items-center gap-1 pr-3 text-left text-sm text-muted-foreground hover:bg-accent/30 hover:text-foreground cursor-pointer",Kse,h.path===t&&"text-foreground bg-accent/20",j),style:{paddingInlineStart:`${Use+d*qse-8}px`},onClick:()=>a(h.path),children:[u&&s.jsx("label",{className:"flex items-center pl-2",children:s.jsx("input",{type:"checkbox",checked:v,onChange:()=>o==null?void 0:o(h.path,"file"),className:"mr-2 accent-foreground"})}),s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 py-1 text-left",onClick:()=>a(h.path),children:[s.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:s.jsx(b,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"truncate",children:h.name})]}),l==null?void 0:l(h,v)]},h.path)})})}const $g="SOUL.md";function w6t({agent:e,orgId:t,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:i,onSavingChange:a}){const o=vn(),{selectedOrganizationId:l}=wn(),{isMobile:c}=aa(),[u,d]=x.useState($g),[f,h]=x.useState(!1),[g,b]=x.useState(null),[v,j]=x.useState(null),[k,w]=x.useState(""),[N,C]=x.useState(!1),[A,_]=x.useState([]),[E,T]=x.useState(new Set),[M,O]=x.useState(260),P=x.useRef(null),[z,L]=x.useState(!1),Q=x.useRef(null),ee=x.useRef(null);x.useEffect(()=>{d($g),h(!1),b(null),j(null),w(""),C(!1),_([]),T(new Set),L(!1),Q.current=null,ee.current=null},[e.id]);const B=e.agentRuntimeType==="claude_local"||e.agentRuntimeType==="codex_local"||e.agentRuntimeType==="opencode_local"||e.agentRuntimeType==="pi_local"||e.agentRuntimeType==="hermes_local"||e.agentRuntimeType==="cursor",{data:F,isLoading:Z}=Ne({queryKey:q.agents.instructionsBundle(e.id),queryFn:()=>Bt.instructionsBundle(e.id,t),enabled:!!(t&&B)}),W=(F==null?void 0:F.mode)??"managed",$=W==="managed"?(F==null?void 0:F.managedRootPath)??(F==null?void 0:F.rootPath)??"":(F==null?void 0:F.rootPath)??"",Y=(v==null?void 0:v.mode)??W,V=(v==null?void 0:v.entryFile)??(F==null?void 0:F.entryFile)??$g,H=(v==null?void 0:v.rootPath)??$,ae=x.useMemo(()=>(F==null?void 0:F.files.map(D=>D.path))??[],[F]),le=!!(F&&Y===W&&V===F.entryFile&&H===$),fe=x.useMemo(()=>le?[...new Set([V,...ae,...A])]:[V,...A],[le,V,ae,A]),U=x.useMemo(()=>P2(Object.fromEntries(fe.map(D=>[D,""]))),[fe]),xe=u||V,re=le&&ae.includes(xe),X=(F==null?void 0:F.files.find(D=>D.path===xe))??null,{data:ie,isLoading:pe}=Ne({queryKey:q.agents.instructionsFile(e.id,xe),queryFn:()=>Bt.instructionsFile(e.id,xe,t),enabled:!!(t&&B&&re)}),ke=nt({mutationFn:D=>Bt.updateInstructionsBundle(e.id,D,t),onMutate:()=>L(!0),onSuccess:()=>{o.invalidateQueries({queryKey:q.agents.instructionsBundle(e.id)}),o.invalidateQueries({queryKey:q.agents.detail(e.id)}),o.invalidateQueries({queryKey:q.agents.detail(e.urlKey)})},onError:()=>L(!1)}),Ce=nt({mutationFn:D=>Bt.saveInstructionsFile(e.id,D,t),onMutate:()=>L(!0),onSuccess:(D,J)=>{_(de=>de.filter(ue=>ue!==J.path)),o.invalidateQueries({queryKey:q.agents.instructionsBundle(e.id)}),o.invalidateQueries({queryKey:q.agents.instructionsFile(e.id,J.path)}),o.invalidateQueries({queryKey:q.agents.detail(e.id)}),o.invalidateQueries({queryKey:q.agents.detail(e.urlKey)})},onError:()=>L(!1)}),$e=nt({mutationFn:async({file:D,namespace:J})=>{if(!l)throw new Error("Select a organization to upload images");return E0.uploadImage(l,D,J)}});x.useEffect(()=>{if(!F)return;if(!le){u!==V&&d(V);return}const D=F.files.map(J=>J.path);if(D.length===0){u!==F.entryFile&&d(F.entryFile);return}!D.includes(u)&&u!==V&&!A.includes(u)&&d(D.includes(F.entryFile)?F.entryFile:D[0])},[F,le,V,A,u]),x.useEffect(()=>{const D=new Set;for(const J of fe){const de=J.split("/");let ue="";for(let me=0;me<de.length-1;me++)ue=ue?`${ue}/${de[me]}`:de[me],D.add(ue)}T(J=>Jvt(J,D)?J:D)},[fe]),x.useEffect(()=>{const D=re&&ie?`${ie.path}:${ie.content}`:`draft:${Y}:${H}:${xe}`;if(z){L(!1),j(null),b(null),Q.current=D;return}Q.current!==D&&(b(null),Q.current=D)},[z,Y,H,ie,re,xe]),x.useEffect(()=>{F&&j(D=>D||{mode:W,rootPath:$,entryFile:F.entryFile})},[F,W,$]),x.useEffect(()=>{!F||Y!=="external"||(ee.current={rootPath:H,entryFile:V,selectedFile:xe})},[F,V,Y,H,xe]);const Ue=re?(ie==null?void 0:ie.content)??"":"",he=g??Ue,We=!!(v&&(v.mode!==W||v.rootPath!==$||v.entryFile!==((F==null?void 0:F.entryFile)??$g))),ct=g!==null&&g!==Ue,Pe=We||ct,Ae=ke.isPending||Ce.isPending||z;x.useEffect(()=>{a(Ae)},[a,Ae]),x.useEffect(()=>{n(Pe)},[n,Pe]),x.useEffect(()=>{r(Pe?()=>{(async()=>{const J=!!(F!=null&&F.legacyPromptTemplateActive)||!!(F!=null&&F.legacyBootstrapPromptTemplateActive);We&&v&&await ke.mutateAsync({mode:v.mode,rootPath:v.mode==="external"?v.rootPath:null,entryFile:v.entryFile}),ct&&await Ce.mutateAsync({path:xe,content:he,clearLegacyPromptTemplate:J})})().catch(()=>{})}:null)},[F,We,v,he,ct,Pe,r,Ce,xe,ke]),x.useEffect(()=>{i(Pe?()=>{b(null),F&&j({mode:W,rootPath:$,entryFile:F.entryFile})}:null)},[F,Pe,i,W,$]);const oe=x.useCallback(D=>{D.preventDefault();const J=D.clientX,de=M,ue=K=>{const je=K.clientX-J,Be=Math.max(180,Math.min(500,de+je));O(Be)},me=()=>{document.removeEventListener("mousemove",ue),document.removeEventListener("mouseup",me),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ue),document.addEventListener("mouseup",me),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[M]);return B?Z&&!F?s.jsx(k6t,{}):s.jsxs("div",{className:"max-w-6xl space-y-6",children:[((F==null?void 0:F.warnings)??[]).length>0&&s.jsx("div",{className:"space-y-2",children:((F==null?void 0:F.warnings)??[]).map(D=>s.jsx("div",{className:G("rounded-md border px-3 py-2 text-xs",xA.info),children:D},D))}),s.jsxs(L0,{defaultOpen:Y==="external",children:[s.jsxs(pA,{className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors group",children:[s.jsx(Ls,{className:"h-3 w-3 transition-transform group-data-[state=open]:rotate-90"}),"Advanced"]}),s.jsx($0,{className:"pt-4 pb-6",children:s.jsx(P1,{children:s.jsxs("div",{className:"grid gap-x-6 gap-y-4 sm:grid-cols-[auto_1fr_1fr]",children:[s.jsxs("label",{className:"space-y-1.5",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Mode",s.jsxs(za,{children:[s.jsx(Ba,{asChild:!0,children:s.jsx(g3,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),s.jsx(Ua,{side:"right",sideOffset:4,children:"Managed: Rudder stores and serves the instructions bundle. External: you provide a path on disk where the instructions live."})]})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(ce,{type:"button",size:"sm",variant:Y==="managed"?"default":"outline",onClick:()=>{Y==="external"&&(ee.current={rootPath:H,entryFile:V,selectedFile:xe});const D=V||$g;j({mode:"managed",rootPath:(F==null?void 0:F.managedRootPath)??H,entryFile:D}),d(D)},children:"Managed"}),s.jsx(ce,{type:"button",size:"sm",variant:Y==="external"?"default":"outline",onClick:()=>{const D=ee.current,J=(D==null?void 0:D.entryFile)??V??$g;j({mode:"external",rootPath:(D==null?void 0:D.rootPath)??((F==null?void 0:F.mode)==="external"?F.rootPath??"":""),entryFile:J}),d((D==null?void 0:D.selectedFile)??J)},children:"External"})]})]}),s.jsxs("label",{className:"space-y-1.5 min-w-0",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Root path",s.jsxs(za,{children:[s.jsx(Ba,{asChild:!0,children:s.jsx(g3,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),s.jsx(Ua,{side:"right",sideOffset:4,children:"The absolute directory on disk where the instructions bundle lives. In managed mode this is set by Rudder automatically."})]})]}),Y==="managed"?s.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-xs text-muted-foreground pt-1.5",children:[s.jsx("span",{className:"min-w-0 truncate",title:H||void 0,children:H||"(managed)"}),H&&s.jsx(O2,{text:H,className:"shrink-0",children:s.jsx(Ni,{className:"h-3.5 w-3.5"})})]}):s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(In,{value:H,onChange:D=>{const J=D.target.value;ee.current={rootPath:J,entryFile:V,selectedFile:xe},j({mode:"external",rootPath:J,entryFile:V})},className:"font-mono text-sm",placeholder:"/absolute/path/to/agent/prompts"}),H&&s.jsx(O2,{text:H,className:"shrink-0",children:s.jsx(Ni,{className:"h-3.5 w-3.5"})})]})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Entry file",s.jsxs(za,{children:[s.jsx(Ba,{asChild:!0,children:s.jsx(g3,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),s.jsx(Ua,{side:"right",sideOffset:4,children:"The main file the agent reads first when loading role and persona instructions. Defaults to SOUL.md."})]})]}),s.jsx(In,{value:V,onChange:D=>{const J=D.target.value||$g,de=xe===V?J:xe;Y==="external"&&(ee.current={rootPath:H,entryFile:J,selectedFile:de}),xe===V&&d(J),j({mode:Y,rootPath:H,entryFile:J})},className:"font-mono text-sm"})]})]})})})]}),s.jsxs("div",{ref:P,className:G("flex gap-0",c&&"flex-col gap-3"),children:[s.jsxs("div",{className:G("border border-border rounded-lg p-3 space-y-3 shrink-0",c&&f&&"block",c&&!f&&"hidden"),style:c?void 0:{width:M},children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h4",{className:"text-sm font-medium",children:"Files"}),s.jsxs("div",{className:"flex items-center gap-1",children:[!N&&s.jsx(ce,{type:"button",size:"icon",variant:"outline",className:"h-7 w-7",onClick:()=>C(!0),children:"+"}),c&&s.jsx(ce,{type:"button",size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>h(!1),children:"✕"})]})]}),N&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(In,{value:k,onChange:D=>w(D.target.value),placeholder:"TOOLS.md",className:"font-mono text-sm",autoFocus:!0,onKeyDown:D=>{D.key==="Escape"&&(C(!1),w(""))}}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(ce,{type:"button",size:"sm",variant:"default",className:"flex-1",disabled:!k.trim()||k.includes(".."),onClick:()=>{const D=k.trim();!D||D.includes("..")||(_(J=>J.includes(D)?J:[...J,D]),d(D),b(""),w(""),C(!1))},children:"Create"}),s.jsx(ce,{type:"button",size:"sm",variant:"outline",className:"flex-1",onClick:()=>{C(!1),w("")},children:"Cancel"})]})]}),s.jsx(U4,{nodes:U,selectedFile:xe,expandedDirs:E,checkedFiles:new Set,onToggleDir:D=>T(J=>{const de=new Set(J);return de.has(D)?de.delete(D):de.add(D),de}),onSelectFile:D=>{d(D),ae.includes(D)||b(""),c&&h(!1)},onToggleCheck:()=>{},showCheckboxes:!1,renderFileExtra:D=>{const J=F==null?void 0:F.files.find(de=>de.path===D.path);return J?J.deprecated?s.jsxs(za,{children:[s.jsx(Ba,{asChild:!0,children:s.jsx("span",{className:G("ml-3 shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide cursor-help",bA.warn),children:"virtual file"})}),s.jsx(Ua,{side:"right",sideOffset:4,children:"Legacy inline prompt — this deprecated virtual file preserves the old promptTemplate content"})]}):s.jsx("span",{className:"ml-3 shrink-0 rounded border border-border text-muted-foreground px-1.5 py-0.5 text-[10px] uppercase tracking-wide",children:J.isEntryFile?"entry":`${J.size}b`}):null}})]}),!c&&s.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-border active:bg-primary/50 rounded transition-colors mx-1",onMouseDown:oe}),s.jsxs("div",{className:G("border border-border rounded-lg p-4 space-y-3 min-w-0 flex-1",c&&f&&"hidden"),children:[s.jsx("div",{className:"flex items-center justify-between gap-3",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c&&s.jsx(ce,{type:"button",size:"icon",variant:"outline",className:"h-7 w-7 shrink-0",onClick:()=>h(!0),children:s.jsx(C0,{className:"h-3.5 w-3.5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h4",{className:"text-sm font-medium font-mono truncate",children:xe}),s.jsx("p",{className:"text-xs text-muted-foreground",children:re?X!=null&&X.deprecated?"Deprecated virtual file":`${(ie==null?void 0:ie.language)??"text"} file`:"New file in this bundle"})]})]})}),re&&pe&&!ie?s.jsx(l7e,{}):Wvt(xe)?s.jsx(ol,{value:he,onChange:D=>b(D??""),placeholder:"# Agent instructions",contentClassName:"min-h-[420px] text-sm font-mono",imageUploadHandler:async D=>{const J=`agents/${e.id}/instructions/${xe.replaceAll("/","-")}`;return(await $e.mutateAsync({file:D,namespace:J})).contentPath}},xe):s.jsx("textarea",{value:he,onChange:D=>b(D.target.value),className:"min-h-[420px] w-full rounded-md border border-border bg-transparent px-3 py-2 font-mono text-sm outline-none",placeholder:"File contents"})]})]})]}):s.jsx("div",{className:"max-w-3xl",children:s.jsx("p",{className:"text-sm text-muted-foreground",children:"Instructions bundles are only available for local adapters."})})}function k6t(){return s.jsxs("div",{className:"max-w-5xl space-y-4",children:[s.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"h-4 w-40"}),s.jsx(Et,{className:"h-4 w-[30rem] max-w-full"})]}),s.jsx(Et,{className:"h-4 w-16"})]}),s.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:Array.from({length:3}).map((e,t)=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"h-3 w-20"}),s.jsx(Et,{className:"h-10 w-full"})]},t))})]}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-[260px_minmax(0,1fr)]",children:[s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Et,{className:"h-4 w-12"}),s.jsx(Et,{className:"h-8 w-16"})]}),s.jsx(Et,{className:"h-10 w-full"}),s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,t)=>s.jsx(Et,{className:"h-9 w-full rounded-none"},t))})]}),s.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-3",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"h-4 w-48"}),s.jsx(Et,{className:"h-3 w-28"})]}),s.jsx(l7e,{})]})]})]})}function l7e(){return s.jsxs("div",{className:"space-y-3",children:[s.jsx(Et,{className:"h-10 w-full"}),s.jsx(Et,{className:"h-[420px] w-full"})]})}function vy(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function Iv(e){return Array.from(new Set(e)).sort((t,n)=>t.localeCompare(n))}function tk(e,t){const n=t instanceof Set?t:new Set(t);return[...e].sort((r,i)=>{const a=r.alwaysEnabled?0:n.has(r.selectionKey)?1:2,o=i.alwaysEnabled?0:n.has(i.selectionKey)?1:2;return a!==o?a-o:r.name.localeCompare(i.name)||r.selectionKey.localeCompare(i.selectionKey)})}function j6t(e){return e.sourceClass==="agent_home"||e.sourceClass==="global"||e.sourceClass==="adapter_home"}function Hse(e){return e.configurable}function Vse(e,t,n,r){if(!t.configurable)return Iv(e);const i=new Map(r.map(o=>[o.selectionKey,o])),a=e.filter(o=>{const l=i.get(o);return!l||!n?o!==t.selectionKey:o===t.selectionKey?!1:l.key!==t.key});return Iv(n?[...a,t.selectionKey]:a)}function N6t({agent:e,orgId:t}){const n=vn(),{pushToast:r}=_r(),[i,a]=x.useState([]),[o,l]=x.useState([]),[c,u]=x.useState(""),[d,f]=x.useState(!1),[h,g]=x.useState(!1),b=x.useRef([]),v=x.useRef([]),j=x.useRef(!1),k=x.useRef(null),w=x.useRef(null),{data:N,isLoading:C}=Ne({queryKey:q.agents.skills(e.id),queryFn:()=>Bt.skills(e.id,t),enabled:!!t}),{data:A,isLoading:_}=Ne({queryKey:q.organizationSkills.list(t??""),queryFn:()=>Co.list(t),enabled:!!t});w.current!==e.id&&(w.current=e.id,k.current=null),k.current===null&&N&&(k.current=Iv(N.desiredSkills));const E=nt({mutationFn:D=>Bt.syncSkills(e.id,D,t),onSuccess:async D=>{n.setQueryData(q.agents.skills(e.id),D),v.current=D.desiredSkills,l(D.desiredSkills),await Promise.all([n.invalidateQueries({queryKey:q.agents.detail(e.id)}),n.invalidateQueries({queryKey:q.agents.detail(e.urlKey)})])}}),T=nt({mutationFn:D=>Bt.createPrivateSkill(e.id,D,t),onSuccess:async D=>{g(!1),u(""),r({title:`Created ${D.key}`,body:"Enable it from the Agent skills section when you want Rudder to load it."}),await n.invalidateQueries({queryKey:q.agents.skills(e.id)})}});x.useEffect(()=>{a([]),b.current=[],l([]),u(""),f(!1),v.current=[],j.current=!1},[e.id]),x.useEffect(()=>{b.current=i},[i]),x.useEffect(()=>{if(!N)return;const D=Iv(N.desiredSkills),J=b.current,de=v.current,ue=!j.current||vy(J,de);j.current=!0,v.current=D,l(me=>vy(me,D)?me:D),ue&&(b.current=D,a(me=>vy(me,D)?me:D))},[N]);const M=(N==null?void 0:N.entries)??[],O=x.useMemo(()=>new Map(M.map(D=>[D.selectionKey,D])),[M]),P=x.useCallback(D=>uP(D)?`bundled:${D}`:`org:${D}`,[]),z=x.useCallback((D,J)=>{if(J)return"Bundled by Rudder";switch(D){case"community":return"Community preset";case"github":return"GitHub";case"local":return"Local";case"url":return"URL";case"skills_sh":return"skills.sh";case"catalog":return"Catalog";case"rudder":return"Rudder workspace";default:return null}},[]),L=x.useCallback(D=>{const J=uP(D.key)!==null;return{key:D.slug,selectionKey:P(D.key),runtimeName:D.slug,description:D.description??null,desired:J,configurable:!J,alwaysEnabled:J,managed:!0,state:J?"configured":"available",sourceClass:J?"bundled":"organization"}},[P]),Q=x.useMemo(()=>new Set(k.current??[]),[e.id,N]),ee=x.useMemo(()=>tk((A??[]).map(D=>{const J=O.get(P(D.key))??L(D),de=z(D.sourceBadge,J.alwaysEnabled);return{id:J.selectionKey,selectionKey:J.selectionKey,key:J.key,name:D.name,description:Qy(D.description??J.description??null),detail:Qy(J.detail??null),locationLabel:J.locationLabel??null,badgeLabel:de,metadataTokens:[D.sourceLabel].filter(ue=>!!ue).filter(ue=>ue!==de),linkTo:`/skills/${D.id}`,workspaceEditPath:D.workspaceEditPath,alwaysEnabled:J.alwaysEnabled,configurable:Hse(J),entry:J}}),Q),[L,O,z,P,A,Q]),B=x.useMemo(()=>M.filter(D=>j6t(D)).filter(D=>!qvt(D)).map(D=>({id:D.selectionKey,selectionKey:D.selectionKey,key:D.key,name:D.runtimeName??D.key,description:Qy(D.description??null),detail:Qy(D.detail??(D.sourceClass==="agent_home"?"Installed, not enabled. Future runs will not load it until enabled.":D.sourceClass==="global"?"Discovered in ~/.agents/skills. Enable it here to load it for this agent.":"Discovered in the current runtime adapter home. Enable it here to load it for this agent.")),locationLabel:D.locationLabel??null,badgeLabel:D.sourceClass==="agent_home"?D.desired?"Agent skill":"Installed, not enabled":D.sourceClass==="global"?"Global skill":"Adapter skill",metadataTokens:[D.locationLabel].filter(J=>!!J),linkTo:null,workspaceEditPath:D.workspaceEditPath??null,alwaysEnabled:D.alwaysEnabled,configurable:Hse(D),entry:D})).sort((D,J)=>D.name.localeCompare(J.name)||D.selectionKey.localeCompare(J.selectionKey)),[M]),F=x.useMemo(()=>tk(B.filter(D=>D.entry.sourceClass==="agent_home"),Q),[B,Q]),Z=x.useMemo(()=>B.filter(D=>D.entry.sourceClass!=="agent_home"),[B]),W=x.useMemo(()=>tk(Z.filter(D=>D.entry.sourceClass==="global"),Q),[Z,Q]),$=x.useMemo(()=>tk(Z.filter(D=>D.entry.sourceClass==="adapter_home"),Q),[Z,Q]),Y=x.useMemo(()=>{const D=c.trim().toLowerCase();return ee.filter(J=>D?[J.name,J.key,J.description??"",J.detail??"",...J.metadataTokens].join(" ").toLowerCase().includes(D):!0)},[ee,c]),V=x.useCallback(D=>{const J=c.trim().toLowerCase();return D.filter(de=>J?[de.name,de.key,de.description??"",de.detail??"",...de.metadataTokens].join(" ").toLowerCase().includes(J):!0)},[c]),H=x.useMemo(()=>V(W),[V,W]),ae=x.useMemo(()=>V(F),[F,V]),le=x.useMemo(()=>V($),[$,V]),fe=x.useMemo(()=>[...Y.filter(D=>!D.alwaysEnabled).map(D=>D.selectionKey),...ae.filter(D=>D.configurable).map(D=>D.selectionKey),...d?[...H,...le].filter(D=>D.configurable).map(D=>D.selectionKey):[]],[d,le,ae,H,Y]),U=x.useMemo(()=>new Set(M.map(D=>D.selectionKey)),[M]),xe=x.useMemo(()=>i.filter(D=>!U.has(D)),[U,i]),re=x.useMemo(()=>(N==null?void 0:N.mode)!=="unsupported"?null:e.agentRuntimeType==="openclaw_gateway"?"Rudder cannot manage OpenClaw skills here. Visit your OpenClaw instance to manage this agent's skills.":"Rudder cannot manage skills for this runtime yet. Manage them in the runtime directly.",[e.agentRuntimeType,N==null?void 0:N.mode]),X=x.useMemo(()=>Z.some(D=>i.includes(D.selectionKey)),[Z,i]),ie=C||_,pe=E.isPending?"Saving...":null,ke="Rudder always loads the bundled Rudder skills. Agent, organization, global, and adapter skills load only when enabled on this page.",Ce="Agent-private skills belong to this agent only. Edit them in Workspaces, then enable them here when you want Rudder to load them.",$e="Bundled Rudder skills are locked on. Community presets and other organization skills stay optional; workspace-backed skills can be edited from Workspaces.",Ue="Global and adapter skills are discovered from ~/.agents/skills and the current runtime adapter home. Discovery does not enable them; only the selections on this page determine runtime loading.",he=x.useCallback(D=>{const J=b.current,de=Iv(D(J));vy(J,de)||(b.current=de,a(de),vy(de,v.current)||E.mutate(de))},[E]),We=x.useCallback((D,J)=>{he(de=>Vse(de,D.entry,J,M))},[M,he]),ct=x.useCallback((D,J)=>{D.length!==0&&he(de=>D.reduce((ue,me)=>Vse(ue,me.entry,J,M),de))},[M,he]),Pe=x.useCallback(()=>{const D=[...Y.filter(J=>!J.alwaysEnabled),...ae,...d?[...H,...le]:[]];ct(D,!0)},[d,le,ae,H,Y,ct]),Ae=x.useCallback(()=>{const D=[...Y.filter(J=>!J.alwaysEnabled),...ae,...d?[...H,...le]:[]];ct(D,!1)},[d,le,ae,H,Y,ct]);x.useEffect(()=>{if(X){f(!0);return}c.trim().length>0&&Y.length===0&&ae.length===0&&(H.length>0||le.length>0)&&f(!0)},[le.length,ae.length,H.length,Y.length,X,c]);const oe=x.useCallback(D=>{const J=D.alwaysEnabled||i.includes(D.selectionKey),de=D.alwaysEnabled||!D.configurable||!!(re&&!D.alwaysEnabled),ue=D.workspaceEditPath?`/workspaces?path=${encodeURIComponent(D.workspaceEditPath)}`:null,me=Fvt(D.description,Dse(D.detail)?null:D.detail),K=D.detail&&D.detail!==D.description&&!Dse(D.detail)?D.detail:null,je=[zvt(D.locationLabel)?null:D.locationLabel,...D.metadataTokens].filter(Be=>!!Be).filter(Be=>Be!==D.badgeLabel&&Be!=="Bundled by Rudder");return s.jsxs("div",{className:G("flex h-full flex-col gap-2.5 rounded-lg border p-3 transition-colors",D.alwaysEnabled?"border-sky-200 bg-sky-50/50 dark:border-sky-500/30 dark:bg-sky-950/15":J?"border-border bg-background":"border-border/70 bg-muted/35 text-muted-foreground"),children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsx("div",{className:"min-w-0 space-y-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[D.linkTo?s.jsx(yt,{to:D.linkTo,className:G("truncate text-sm font-semibold no-underline transition-colors hover:text-foreground",D.alwaysEnabled||J?"text-foreground":"text-foreground/80"),children:D.name}):s.jsx("span",{className:G("truncate text-sm font-semibold",D.alwaysEnabled||J?"text-foreground":"text-foreground/80"),children:D.name}),D.badgeLabel?s.jsx("span",{className:"rounded-md border border-border bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground",children:D.badgeLabel}):null]})}),s.jsx(Bvt,{checked:J,disabled:de,label:D.name,onCheckedChange:Be=>We(D,Be)})]}),s.jsx("p",{className:G("line-clamp-2 text-xs leading-[1.15rem]",D.alwaysEnabled||J?"text-muted-foreground":"text-muted-foreground/90"),children:me}),K?s.jsx("p",{className:"line-clamp-2 text-[11px] leading-[1.05rem] text-muted-foreground/90",children:K}):null,je.length>0||ue?s.jsxs("div",{className:"mt-auto space-y-2",children:[je.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px] text-muted-foreground",children:je.map(Be=>s.jsx("span",{className:"max-w-full truncate rounded-md border border-border bg-muted/20 px-1.5 py-0.5",title:Be,children:Be},`${D.id}:${Be}`))}):null,ue?s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(ce,{asChild:!0,variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",children:s.jsxs(yt,{to:ue,children:[s.jsx(C0,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Edit in workspaces"})]})})}):null]}):null]},D.id)},[We,i,re]);return s.jsxs("div",{className:"max-w-6xl space-y-3",children:[s.jsxs("section",{className:"space-y-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Skills"}),s.jsx("p",{className:"max-w-3xl text-xs leading-5 text-muted-foreground",children:ke})]})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[s.jsxs("div",{className:"relative min-w-[16rem] max-w-md flex-1",children:[s.jsx(na,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),s.jsx(In,{value:c,onChange:D=>u(D.target.value),placeholder:"Search skills","aria-label":"Search skills",className:"h-9 pl-9"})]}),s.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[s.jsxs(ce,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>g(!0),disabled:(N==null?void 0:N.mode)==="unsupported"||T.isPending,children:[s.jsx(tr,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Create agent skill"})]}),pe?s.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[E.isPending?s.jsx(yr,{className:"h-3.5 w-3.5 animate-spin"}):null,s.jsx("span",{children:pe})]}):null,s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"icon-sm","aria-label":"More skill actions",children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsxs(zo,{align:"end",className:"surface-overlay text-foreground",children:[s.jsx(Hn,{onClick:Pe,disabled:fe.length===0||(N==null?void 0:N.mode)==="unsupported",children:"Enable visible"}),s.jsx(Hn,{onClick:Ae,disabled:fe.length===0||(N==null?void 0:N.mode)==="unsupported",children:"Disable visible"})]})]})]})]})]}),N!=null&&N.warnings.length?s.jsx("div",{className:"space-y-1 rounded-xl border border-amber-300/60 bg-amber-50/60 px-4 py-3 text-sm text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/20 dark:text-amber-200",children:N.warnings.map(D=>s.jsx("div",{children:D},D))}):null,re?s.jsx("div",{className:"rounded-xl border border-border px-4 py-3 text-sm text-muted-foreground",children:re}):null,ie?s.jsx(As,{variant:"list"}):s.jsxs(s.Fragment,{children:[ee.length===0&&F.length===0&&Z.length===0?s.jsx("section",{className:"rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:s.jsx("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Import or scan skills into the organization library first, then enable them here."})}):s.jsxs(s.Fragment,{children:[F.length>0?s.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[s.jsxs("div",{className:"border-b border-border px-4 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Agent skills"}),s.jsx("span",{className:"text-xs text-muted-foreground",children:F.length})]}),s.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:Ce})]}),s.jsx("div",{className:"px-3.5 py-3.5",children:ae.length===0?s.jsx("div",{className:"px-0.5 py-1 text-sm text-muted-foreground",children:"No skills match this search."}):s.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:ae.map(D=>oe(D))})})]}):null,s.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[s.jsxs("div",{className:"border-b border-border px-4 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Organization skills"}),s.jsx("span",{className:"text-xs text-muted-foreground",children:ee.length})]}),s.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:$e})]}),s.jsx("div",{className:"px-3.5 py-3.5",children:Y.length===0?s.jsx("div",{className:"px-0.5 py-1 text-sm text-muted-foreground",children:"No skills match this search."}):s.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:Y.map(D=>oe(D))})})]}),Z.length>0?s.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:G("flex w-full items-start justify-between gap-3 px-4 py-3 text-left",d&&"border-b border-border"),onClick:()=>f(D=>!D),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-sm font-semibold text-foreground",children:"External skills"}),s.jsx("span",{className:"text-xs text-muted-foreground",children:Z.length})]}),s.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:Ue})]}),d?s.jsx(fr,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):s.jsx(Ls,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"})]}),d?H.length===0&&le.length===0?s.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground",children:"No external skills match this search."}):s.jsxs("div",{className:"space-y-4 px-3.5 py-3.5",children:[H.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2 px-0.5",children:[s.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:"Global skills"}),s.jsx("span",{className:"text-[11px] text-muted-foreground",children:H.length})]}),s.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:H.map(D=>oe(D))})]}):null,le.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2 px-0.5",children:[s.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:"Adapter skills"}),s.jsx("span",{className:"text-[11px] text-muted-foreground",children:le.length})]}),s.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:le.map(D=>oe(D))})]}):null]}):null]}):null]}),xe.length>0?s.jsxs("div",{className:"rounded-xl border border-amber-300/60 bg-amber-50/60 px-4 py-3 text-sm text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/20 dark:text-amber-200",children:[s.jsx("div",{className:"font-medium",children:"Enabled skills currently unavailable"}),s.jsx("div",{className:"mt-1 text-xs",children:xe.join(", ")})]}):null,E.isError?s.jsx("p",{className:"text-xs text-destructive",children:E.error instanceof Error?E.error.message:"Failed to update skills"}):null]}),s.jsx(Uvt,{open:h,onOpenChange:g,onCreate:D=>T.mutate(D),isPending:T.isPending,error:T.error instanceof Error?T.error.message:null})]})}async function C6t(e){return xs.retry(e.id)}function Wse(){const e=document.getElementById("main-content");if(e instanceof HTMLElement){const t=window.getComputedStyle(e).overflowY;if((t==="auto"||t==="scroll"||t==="overlay")&&e.scrollHeight>e.clientHeight+1)return{type:"element",element:e}}return{type:"window"}}function S6t(e){return e.type==="element"?e.element.scrollHeight-e.element.scrollTop-e.element.clientHeight:(document.scrollingElement??document.documentElement).scrollHeight-window.scrollY-window.innerHeight}function c7e(){const[e,t]=x.useState(!1);x.useEffect(()=>{const r=()=>{t(S6t(Wse())>300)},i=document.getElementById("main-content");return r(),i==null||i.addEventListener("scroll",r,{passive:!0}),window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),()=>{i==null||i.removeEventListener("scroll",r),window.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[]);const n=x.useCallback(()=>{const r=Wse();if(r.type==="element"){r.element.scrollTo({top:r.element.scrollHeight,behavior:"smooth"});return}const i=document.scrollingElement??document.documentElement;window.scrollTo({top:i.scrollHeight,behavior:"smooth"})},[]);return e?s.jsx("button",{onClick:n,className:"fixed bottom-[calc(1.5rem+5rem+env(safe-area-inset-bottom))] right-6 z-40 flex h-9 w-9 items-center justify-center rounded-full border border-border bg-background shadow-md hover:bg-accent transition-colors md:bottom-6","aria-label":"Scroll to bottom",children:s.jsx(bme,{className:"h-4 w-4"})}):null}function Zse({isLive:e}){return e}function zR(e){return e?typeof e=="string"?e:e.toISOString():null}function _6t({run:e,agentRuntimeType:t}){var Ae;const[n,r]=x.useState([]),[i,a]=x.useState([]),[o,l]=x.useState(!0),[c,u]=x.useState(!!e.logRef),[d,f]=x.useState(null),[h,g]=x.useState(0),[b,v]=x.useState(!1),[j,k]=x.useState(!1),[w,N]=x.useState("nice"),[C,A]=x.useState("transcript"),_=dH(e),[E,T]=x.useState(!1),[M,O]=x.useState({fromX:"0px",fromY:"-16px",settleX:"0px",settleY:"0px",fromScaleX:"0.96",fromScaleY:"0.96"}),P=C==="transcript",z=x.useRef(null),L=x.useRef(null),Q=x.useRef(""),ee=x.useRef(new Set),B=x.useRef(null),F=x.useRef(!1),Z=x.useRef({scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY}),W=e.status==="running"||e.status==="queued",$=x.useMemo(()=>W?[{id:e.id,status:e.status,invocationSource:e.invocationSource,triggerDetail:e.triggerDetail,startedAt:zR(e.startedAt),finishedAt:zR(e.finishedAt),createdAt:zR(e.createdAt)??new Date().toISOString(),agentId:e.agentId,agentName:"",agentRuntimeType:t,issueId:null}]:[],[t,W,e.agentId,e.createdAt,e.finishedAt,e.id,e.invocationSource,e.startedAt,e.status,e.triggerDetail]),{transcriptByRun:Y}=o8({runs:$,orgId:e.orgId,maxChunksPerRun:500,includeRunEvents:!1}),{data:V=[]}=Ne({queryKey:q.runWorkspaceOperations(e.id),queryFn:()=>xs.workspaceOperations(e.id),refetchInterval:W?2e3:!1});function H(oe){return oe instanceof Ml&&oe.status===404}function ae(oe,D=!1){if(!oe&&!D)return;const de=`${Q.current}${oe}`.split(`
|
|
1392
|
-
`);Q.current=de.pop()??"",D&&Q.current&&(de.push(Q.current),Q.current="");const ue=[];for(const me of de){const K=me.trim();if(K)try{const je=JSON.parse(K),Be=je.stream==="stderr"||je.stream==="system"?je.stream:"stdout",Ve=typeof je.chunk=="string"?je.chunk:"",Me=typeof je.ts=="string"?je.ts:new Date().toISOString();if(!Ve)continue;ue.push({ts:Me,stream:Be,chunk:Ve})}catch{}}ue.length>0&&le(ue)}function le(oe){oe.length!==0&&a(D=>{const J=[];for(const de of oe){const ue=Bse(de);ee.current.has(ue)||(ee.current.add(ue),J.push(de))}return J.length===0?D:(ee.current.size>12e3&&(ee.current=new Set(J.map(Bse))),[...D,...J])})}const{data:fe}=Ne({queryKey:["run-events",e.id],queryFn:()=>xs.events(e.id,0,200)});x.useEffect(()=>{fe&&(r(fe),l(!1))},[fe]);const U=x.useCallback(()=>{if(B.current)return B.current;const oe=Qvt(z.current);return B.current=oe,oe},[]),xe=x.useCallback(()=>{const oe=U(),D=ek(oe);Z.current=D;const J=D.distanceFromBottom<=Lse;F.current=J,v(de=>de===J?de:J)},[U]);x.useEffect(()=>{if(B.current=null,Z.current={scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY},!W||!P){F.current=!1,v(!1);return}xe()},[W,e.id,P,xe]),x.useEffect(()=>{if(!W||!P)return;const oe=U();return xe(),oe===window?window.addEventListener("scroll",xe,{passive:!0}):oe.addEventListener("scroll",xe,{passive:!0}),window.addEventListener("resize",xe),()=>{oe===window?window.removeEventListener("scroll",xe):oe.removeEventListener("scroll",xe),window.removeEventListener("resize",xe)}},[W,e.id,P,U,xe]),x.useEffect(()=>{if(!W||!P||!F.current)return;const oe=U(),D=Z.current,J=ek(oe),de=Math.max(0,J.scrollHeight-D.scrollHeight),ue=D.distanceFromBottom+de;if(J.distanceFromBottom-ue>Lse){F.current=!1,v(!1),Z.current=J;return}$se(oe,"auto");const K=ek(oe);Z.current=K,F.current||(F.current=!0),v(je=>je||!0)},[n.length,i.length,W,P,U]),x.useEffect(()=>{let oe=!1;if(Q.current="",ee.current.clear(),a([]),g(0),f(null),!e.logRef&&!W)return u(!1),()=>{oe=!0};u(!0);const D=typeof e.logBytes=="number"&&e.logBytes>0?Math.min(Math.max(e.logBytes+1024,256e3),2e6):256e3;return(async()=>{try{let de=0,ue=!0;for(;!oe;){const me=await xs.log(e.id,de,ue?D:256e3);if(oe)break;ae(me.content,me.nextOffset===void 0);const K=me.nextOffset??me.endOffset??de+zse(me.content);if(g(K),de=K,ue=!1,me.nextOffset===void 0||W)break}}catch(de){if(!oe){if(W&&H(de)){u(!1);return}f(de instanceof Error?de.message:"Failed to load run log")}}finally{oe||u(!1)}})(),()=>{oe=!0}},[e.id,e.logRef,e.logBytes,W]),x.useEffect(()=>{if(!Zse({isLive:W}))return;const oe=setInterval(async()=>{const D=n.length>0?Math.max(...n.map(J=>J.seq)):0;try{const J=await xs.events(e.id,D,100);J.length>0&&r(de=>[...de,...J])}catch{}},2e3);return()=>clearInterval(oe)},[e.id,W,j,n]),x.useEffect(()=>{if(!Zse({isLive:W}))return;const oe=setInterval(async()=>{try{const D=await xs.log(e.id,h,256e3);D.content&&ae(D.content,D.nextOffset===void 0),D.nextOffset!==void 0?g(D.nextOffset):D.endOffset!==void 0?g(D.endOffset):D.content.length>0&&g(J=>J+zse(D.content))}catch(D){if(H(D))return}},2e3);return()=>clearInterval(oe)},[e.id,W,j,h]),x.useEffect(()=>{if(!W)return;let oe=!1,D=null,J=null;const de=()=>{oe||(D=window.setTimeout(ue,1500))},ue=()=>{if(oe)return;const K=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/orgs/${encodeURIComponent(e.orgId)}/events/ws`;J=new WebSocket(K),J.onopen=()=>{k(!0)},J.onmessage=je=>{const Be=typeof je.data=="string"?je.data:"";if(!Be)return;let Ve;try{Ve=JSON.parse(Be)}catch{return}if(Ve.orgId!==e.orgId)return;const Me=Ca(Ve.payload),ht=Nr(Me==null?void 0:Me.runId);if(!Me||ht!==e.id)return;if(Ve.type==="heartbeat.run.log"){if(Me.truncated===!0)return;const Pt=typeof Me.chunk=="string"?Me.chunk:"";if(!Pt)return;const _t=Nr(Me.stream),Lt=_t==="stderr"||_t==="system"?_t:"stdout",It=Nr(Me.ts)??Ve.createdAt;le([{ts:It,stream:Lt,chunk:Pt}]);return}if(Ve.type!=="heartbeat.run.event")return;const ve=typeof Me.seq=="number"?Me.seq:null;if(ve===null||!Number.isFinite(ve))return;const Le=Nr(Me.stream),Ie=Le==="stdout"||Le==="stderr"||Le==="system"?Le:null,at=Nr(Me.level),Je=at==="info"||at==="warn"||at==="error"?at:null,St={id:ve,orgId:e.orgId,runId:e.id,agentId:e.agentId,seq:ve,eventType:Nr(Me.eventType)??"event",stream:Ie,level:Je,color:Nr(Me.color),message:Nr(Me.message),payload:Ca(Me.payload),createdAt:new Date(Ve.createdAt)};r(Pt=>Pt.some(_t=>_t.seq===ve)?Pt:[...Pt,St])},J.onerror=()=>{J==null||J.close()},J.onclose=()=>{k(!1),de()}};return ue(),()=>{oe=!0,k(!1),D!==null&&window.clearTimeout(D),J&&(J.onopen=null,J.onmessage=null,J.onerror=null,J.onclose=null,J.close(1e3,"run_detail_unmount"))}},[W,e.orgId,e.id,e.agentId]);const re=((Ae=Ne({queryKey:q.instance.generalSettings,queryFn:()=>ka.getGeneral()}).data)==null?void 0:Ae.censorUsernameInLogs)===!0,X=uH(e),ie=x.useMemo(()=>{const oe=n.find(D=>D.eventType==="adapter.invoke");return Lh(Ca((oe==null?void 0:oe.payload)??null),re)},[re,n]),pe=x.useMemo(()=>{const oe=n.find(D=>D.eventType==="adapter.skill_usage");return Lh(Ca((oe==null?void 0:oe.payload)??null),re)},[re,n]),ke=x.useMemo(()=>T1(t),[t]),Ce=x.useMemo(()=>{const oe=gve(i,ke.parseStdoutLine,{censorUsernameInLogs:re}),D=Y.get(e.id)??[],J=D.length>oe.length?D:oe,de=n.map(ue=>Mvt(ue,{redactText:me=>Nu(me,re),redactValue:me=>Lh(me,re)}));return Rvt(J,de)},[ke,re,n,Y,i,e.id]),$e=!!ie,Ue=(ie==null?void 0:ie.prompt)!==void 0?Kvt(ie.prompt,re):null,he=`${Ce.length} ${Ce.length===1?"entry":"entries"}`,We=x.useCallback(()=>{var D;const oe=(D=L.current)==null?void 0:D.getBoundingClientRect();if(oe&&window.innerWidth>0&&window.innerHeight>0){const J=Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)||16,de=Math.min(window.innerWidth-24,window.innerWidth*.96,J*88),ue=Math.min(window.innerHeight*.92,J*54),me=oe.left+oe.width/2,K=oe.top+oe.height/2,je=Math.round(me-window.innerWidth/2),Be=Math.round(K-window.innerHeight/2);O({fromX:`${je}px`,fromY:`${Be}px`,settleX:`${Math.round(je*-.025)}px`,settleY:`${Math.round(Be*-.025)}px`,fromScaleX:`${Math.max(.035,Math.min(.18,oe.width/de)).toFixed(3)}`,fromScaleY:`${Math.max(.045,Math.min(.18,oe.height/ue)).toFixed(3)}`})}T(!0)},[]),ct={"--transcript-dialog-from-x":M.fromX,"--transcript-dialog-from-y":M.fromY,"--transcript-dialog-settle-x":M.settleX,"--transcript-dialog-settle-y":M.settleY,"--transcript-dialog-from-scale-x":M.fromScaleX,"--transcript-dialog-from-scale-y":M.fromScaleY},Pe=()=>s.jsx("div",{className:"inline-flex rounded-lg border border-border/70 bg-background/70 p-0.5",children:["nice","raw"].map(oe=>s.jsx("button",{type:"button",className:G("rounded-md px-2.5 py-1 text-[11px] font-medium capitalize transition-colors",w===oe?"bg-accent text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>N(oe),children:oe},oe))});return x.useEffect(()=>{N("nice"),A("transcript"),T(!1)},[e.id]),x.useEffect(()=>{!$e&&C==="invocation"&&A("transcript")},[C,$e]),o&&c?s.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading run logs..."}):n.length===0&&i.length===0&&!d?s.jsx("p",{className:"text-xs text-muted-foreground",children:"No log events."}):s.jsxs("div",{className:"space-y-3",children:[s.jsx(c6t,{operations:V,censorUsernameInLogs:re}),s.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/40",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-3 py-2 sm:px-4",children:[$e?s.jsx(Dc,{value:C,onValueChange:oe=>A(oe),children:s.jsx(c1,{items:[{value:"transcript",label:"Transcript"},{value:"invocation",label:"Invocation",mobileLabel:"Invocation",tooltip:"Exact adapter invoke payload"}],value:C,onValueChange:oe=>A(oe),align:"start",triggerClassName:"px-2 py-1 text-xs"})}):s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Transcript"}),P?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:he}),Pe(),s.jsxs(ce,{ref:L,variant:"ghost",size:"icon-sm",className:"group relative overflow-hidden text-muted-foreground transition-[background-color,border-color,color,box-shadow,transform] duration-200 hover:scale-[1.03] hover:shadow-sm active:scale-95",onClick:We,"aria-label":"Expand transcript",title:"Expand transcript",children:[s.jsx("span",{className:"absolute inset-0 rounded-[inherit] bg-accent/0 transition-colors duration-200 group-hover:bg-accent/70","aria-hidden":!0}),s.jsx(c5,{className:"relative h-4 w-4 transition-transform duration-200 ease-out group-hover:scale-110"})]}),W&&!b&&s.jsx(ce,{variant:"ghost",size:"xs",onClick:()=>{const oe=U();F.current=!0,v(!0),$se(oe,"auto"),Z.current=ek(oe)},children:"Jump to live"}),W&&s.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),"Live"]})]}):null]}),P?s.jsxs("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:[s.jsx(Qf,{entries:Ce,mode:w,streaming:W,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&s.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d}),s.jsx("div",{ref:z})]}):s.jsx("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:s.jsxs("div",{className:"space-y-3",children:[typeof(ie==null?void 0:ie.agentRuntimeType)=="string"&&s.jsxs("div",{className:"text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:"Runtime: "}),ie.agentRuntimeType]}),typeof(ie==null?void 0:ie.cwd)=="string"&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),s.jsx("span",{className:"font-mono",children:ie.cwd})]}),typeof(ie==null?void 0:ie.command)=="string"&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Command: "}),s.jsx("span",{className:"font-mono",children:[ie.command,...Array.isArray(ie.commandArgs)?ie.commandArgs.filter(oe=>typeof oe=="string"):[]].join(" ")})]}),Array.isArray(ie==null?void 0:ie.commandNotes)&&ie.commandNotes.length>0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Command notes"}),s.jsx("ul",{className:"list-disc space-y-1 pl-5",children:ie.commandNotes.filter(oe=>typeof oe=="string"&&oe.trim().length>0).map((oe,D)=>s.jsx("li",{className:"text-xs break-all font-mono",children:oe},`${D}-${oe}`))})]}),s.jsx(n6t,{invocationPayload:ie,usagePayload:pe}),Ue!==null&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Prompt"}),s.jsxs("div",{className:"relative",children:[s.jsx(O2,{text:Ue,ariaLabel:"Copy invocation prompt",title:"Copy prompt",containerClassName:"absolute right-2 top-2",className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/70 bg-background/80 text-muted-foreground shadow-sm hover:bg-muted/80 hover:text-foreground",children:s.jsx(Ni,{className:"h-3.5 w-3.5"})}),s.jsx("pre",{"data-testid":"invocation-prompt",className:"rounded-md bg-neutral-100 p-2 pr-11 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:Ue})]})]}),(ie==null?void 0:ie.context)!==void 0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Context"}),s.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:JSON.stringify(Lh(ie.context,re),null,2)})]}),(ie==null?void 0:ie.env)!==void 0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Environment"}),s.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs font-mono whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:Zvt(ie.env,re)})]}),n.length>0&&s.jsx(s6t,{events:n,censorUsernameInLogs:re})]})})]}),s.jsx(Ws,{open:E,onOpenChange:T,children:s.jsxs(ii,{overlayClassName:"transcript-modal-overlay",style:ct,className:"transcript-modal-content grid h-[min(92dvh,54rem)] max-w-[min(96vw,88rem)] grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden rounded-2xl p-0 sm:max-w-[min(96vw,88rem)]",children:[s.jsx(_a,{className:"transcript-modal-header border-b border-border/70 px-4 py-3 pr-12 text-left",children:s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(Wi,{className:"text-sm",children:"Transcript"}),s.jsxs(Va,{className:"sr-only",children:["Expanded transcript for run ",e.id,"."]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:he}),Pe(),W&&s.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-cyan-400"})]}),"Live"]})]})]})}),s.jsxs("div",{className:"transcript-modal-body min-h-0 overflow-y-auto p-3 sm:p-4",children:[s.jsx(Qf,{entries:Ce,mode:w,streaming:W,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&s.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d})]})]})}),(e.status==="failed"||e.status==="timed_out")&&s.jsxs("div",{className:"rounded-lg border border-red-300 dark:border-red-500/30 bg-red-50 dark:bg-red-950/20 p-3 space-y-2",children:[s.jsx("div",{className:"text-xs font-medium text-red-700 dark:text-red-300",children:"Failure details"}),_&&s.jsxs("div",{className:"text-xs text-red-600 dark:text-red-200",children:[s.jsxs("span",{className:"text-red-700 dark:text-red-300",children:[_.title,": "]}),Nu(_.body,re),_.actionPath&&_.actionLabel&&s.jsx("div",{className:"mt-1",children:s.jsx(yt,{to:_.actionPath,className:"text-xs font-medium text-red-700 underline dark:text-red-300",children:_.actionLabel})})]}),X&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stderr excerpt"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:Nu(X,re)})]}),e.resultJson&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"runtime result JSON"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:JSON.stringify(Lh(e.resultJson,re),null,2)})]}),e.stdoutExcerpt&&e.stdoutExcerpt.trim()&&!e.resultJson&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stdout excerpt"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:Nu(e.stdoutExcerpt,re)})]})]})]})}const pH=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"failed",label:"Failed"},{value:"issue",label:"Issue work"},{value:"retries",label:"Retries"},{value:"expensive",label:"Expensive"}],u7e={queued:"Queued",running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled",timed_out:"Timed out"},d7e={timer:"Timer",assignment:"Assignment",review:"Review",on_demand:"Manual",automation:"Automation"},AC={issue:"Issue-backed",retry:"Retry / recovery",followup:"Passive follow-up",process_lost:"Process lost"},EC={all:"Any time","24h":"24h","7d":"7d","30d":"30d"},TC={high_tokens:">500k tokens",long:">30m"},A6t=new Set(pH.map(e=>e.value)),E6t=new Set(eP),T6t=new Set(Ofe),I6t=new Set(Object.keys(AC)),M6t=new Set(Object.keys(EC)),R6t=new Set(Object.keys(TC)),O6t=["queued","running"],f7e=5e5,m7e=1800*1e3;function nk(e,t){if(!e)return[];const n=[],r=new Set;for(const i of e.split(",")){const a=i.trim();!t.has(a)||r.has(a)||(r.add(a),n.push(a))}return n}function wy(e){return e.length>0?e.join(","):null}function P6t(e){if(!e)return[];const t=[],n=new Set;for(const r of e.split(",")){const i=r.trim();!i||n.has(i)||(n.add(i),t.push(i))}return t}function ky(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function gH(e){var t;return Nr((t=Ca(e.contextSnapshot))==null?void 0:t.issueId)}function h7e(e){const t=Ca(e.contextSnapshot);return!!(e.retryOfRunId||Ca(t==null?void 0:t.recovery))}function D6t(e){const t=Ca(e.contextSnapshot);return!!Ca(t==null?void 0:t.passiveFollowup)}function p7e(e){if(!e.startedAt)return 0;const t=new Date(e.startedAt).getTime(),n=e.finishedAt?new Date(e.finishedAt).getTime():Date.now();return!Number.isFinite(t)||!Number.isFinite(n)||n<t?0:n-t}function L6t(e){return B4(e).totalTokens>=f7e||p7e(e)>=m7e}function $6t(e,t){switch(t){case"active":return O6t.includes(e.status);case"failed":return e.status==="failed"||e.status==="timed_out";case"issue":return!!gH(e);case"retries":return h7e(e);case"expensive":return L6t(e);case"all":default:return!0}}function F6t(e,t){switch(t){case"issue":return!!gH(e);case"retry":return h7e(e);case"followup":return D6t(e);case"process_lost":return e.errorCode==="process_lost"}}function z6t(e,t){if(t==="all")return!0;const n=new Date(e.createdAt).getTime();if(!Number.isFinite(n))return!1;const r=t==="24h"?1440*60*1e3:t==="7d"?10080*60*1e3:720*60*60*1e3;return n>=Date.now()-r}function B6t(e,t){return t==="high_tokens"?B4(e).totalTokens>=f7e:p7e(e)>=m7e}function U6t(e){const t=Ca(e);if(t){const r=Nr(t.key)??Nr(t.runtimeName)??Nr(t.name);return r?{key:r,label:Nr(t.runtimeName)??Nr(t.name)??r.split(/[/:]/).filter(Boolean).at(-1)??r}:null}const n=Nr(e);return n?{key:n,label:n.split(/[/:]/).filter(Boolean).at(-1)??n}:null}function Gse(e){if(!e)return[];const t=[...d3(e,"usedSkills"),...e.skillEvidenceType==="used"?d3(e,"skillEvidenceSkills"):[]],n=[...Array.isArray(e.usedSkillKeys)?e.usedSkillKeys:[],...e.skillEvidenceType==="used"&&Array.isArray(e.skillEvidenceKeys)?e.skillEvidenceKeys:[]].map(U6t).filter(a=>!!a),r=new Set,i=[];for(const a of[...t,...n])r.has(a.key)||(r.add(a.key),i.push(a));return i}function xH(e){const t=[...Gse(Ca(e.usageJson)),...Gse(Ca(e.resultJson))],n=new Set;return t.filter(r=>n.has(r.key)?!1:(n.add(r.key),!0))}function q6t(e){const t=new Map;for(const n of e)for(const r of xH(n)){const i=t.get(r.key);i?(i.count+=1,i.label===i.key&&r.label!==r.key&&(i.label=r.label)):t.set(r.key,{key:r.key,label:r.label,count:1})}return Array.from(t.values()).sort((n,r)=>r.count-n.count||n.label.localeCompare(r.label))}function K6t(e){const t=Ca(e.resultJson);return[e.id,e.status,e.invocationSource,e.triggerDetail,e.error,e.errorCode,gH(e),Nr(t==null?void 0:t.summary),Nr(t==null?void 0:t.result),...xH(e).flatMap(n=>[n.key,n.label])].filter(Boolean).join(" ").toLowerCase()}function g7e(e){var r;const t=e.get("runView"),n=e.get("runDate");return{view:t&&A6t.has(t)?t:"all",q:((r=e.get("runQ"))==null?void 0:r.trim())??"",statuses:nk(e.get("runStatus"),E6t),sources:nk(e.get("runSource"),T6t),contexts:nk(e.get("runContext"),I6t),skills:P6t(e.get("runSkill")),date:n&&M6t.has(n)?n:"all",cost:nk(e.get("runCost"),R6t)}}function Qse(e,t){const n={...g7e(e),...t},r=new URLSearchParams(e);n.view==="all"?r.delete("runView"):r.set("runView",n.view),n.q.trim()?r.set("runQ",n.q.trim()):r.delete("runQ");const i=[["runStatus",wy(n.statuses)],["runSource",wy(n.sources)],["runContext",wy(n.contexts)],["runSkill",wy(n.skills)],["runCost",wy(n.cost)],["runDate",n.date==="all"?null:n.date]];for(const[a,o]of i)o?r.set(a,o):r.delete(a);return r}function H6t(e){return x7e(e)>0}function x7e(e){return+(e.view!=="all")+ +(e.q.length>0)+ +(e.statuses.length>0)+ +(e.sources.length>0)+ +(e.contexts.length>0)+ +(e.skills.length>0)+ +(e.date!=="all")+ +(e.cost.length>0)}function V6t(e,t){const n=t.q.toLowerCase();return e.filter(r=>!(!$6t(r,t.view)||t.statuses.length>0&&!t.statuses.includes(r.status)||t.sources.length>0&&!t.sources.includes(r.invocationSource)||t.contexts.length>0&&!t.contexts.every(i=>F6t(r,i))||t.skills.length>0&&!xH(r).some(i=>t.skills.includes(i.key))||t.cost.length>0&&!t.cost.every(i=>B6t(r,i))||!z6t(r,t.date)||n&&!K6t(r).includes(n)))}function W6t(e){var n;const t=[];e.view!=="all"&&t.push(((n=pH.find(r=>r.value===e.view))==null?void 0:n.label)??e.view),e.q&&t.push(`Search: ${e.q}`),e.statuses.length>0&&t.push(`Status: ${e.statuses.map(r=>u7e[r]).join(", ")}`),e.sources.length>0&&t.push(`Source: ${e.sources.map(r=>d7e[r]).join(", ")}`);for(const r of e.contexts)t.push(AC[r]);e.skills.length>0&&t.push(`Skill: ${e.skills.join(", ")}`);for(const r of e.cost)t.push(TC[r]);return e.date!=="all"&&t.push(EC[e.date]),t}function Z6t({runs:e,filteredCount:t,state:n,onChange:r,onClear:i}){const a=x7e(n),o=x.useMemo(()=>{const c=new Map;for(const u of eP)c.set(u,0);for(const u of e)c.set(u.status,(c.get(u.status)??0)+1);return c},[e]),l=x.useMemo(()=>q6t(e),[e]);return s.jsx("div",{className:"pointer-events-none sticky top-2 z-20 mb-3 flex justify-end",children:s.jsxs("div",{className:"pointer-events-auto flex max-w-full flex-wrap items-center justify-end gap-2 rounded-lg border border-border bg-background/95 px-2.5 py-2 shadow-sm backdrop-blur supports-[backdrop-filter]:bg-background/85","data-testid":"run-filter-floating-toolbar",children:[s.jsx("div",{className:"flex items-center overflow-hidden rounded-md border border-border bg-muted/20",children:pH.map(c=>s.jsx("button",{type:"button",className:G("h-7 px-2.5 text-xs transition-colors",n.view===c.value?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/40"),onClick:()=>r({view:c.value}),children:c.label},c.value))}),s.jsxs("label",{className:"relative block w-[min(14rem,42vw)]",children:[s.jsx(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),s.jsx(In,{"aria-label":"Search runs",value:n.q,onChange:c=>r({q:c.target.value}),placeholder:"Search runs",className:"h-7 pl-7 pr-2 text-xs"})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",a>0&&"text-[color:var(--accent-strong)] bg-accent/30"),children:[s.jsx(o4,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:a>0?`Filter: ${a}`:"Filter"})]})}),s.jsx(Kn,{align:"end",sideOffset:8,className:"w-[min(440px,calc(100vw-2rem))] p-0","data-testid":"run-filter-popover",children:s.jsxs("div",{className:"space-y-3 p-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($j,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm font-medium",children:"Filter runs"})]}),a>0&&s.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:i,children:"Clear"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),s.jsx("div",{className:"grid grid-cols-2 gap-1",children:eP.map(c=>s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1 hover:bg-accent/50",children:[s.jsx(eo,{checked:n.statuses.includes(c),onCheckedChange:()=>r({statuses:ky(n.statuses,c)})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:u7e[c]}),s.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:o.get(c)??0})]},c))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Source"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Ofe.map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.sources.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({sources:ky(n.sources,c)}),children:d7e[c]},c))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Date"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(EC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.date===c?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({date:c}),children:EC[c]},c))})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Context"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(AC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.contexts.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({contexts:ky(n.contexts,c)}),children:AC[c]},c))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Used skill"}),l.length>0?s.jsx("div",{className:"max-h-28 overflow-y-auto pr-1",children:s.jsx("div",{className:"flex flex-wrap gap-1",children:l.map(c=>s.jsxs("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.skills.includes(c.key)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),title:c.key,onClick:()=>r({skills:ky(n.skills,c.key)}),children:[c.label,s.jsx("span",{className:"ml-1 opacity-70",children:c.count})]},c.key))})}):s.jsx("div",{className:"rounded-md border border-border/70 px-2 py-1.5 text-xs text-muted-foreground",children:"No used skills found in loaded runs."})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Cost & duration"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(TC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.cost.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({cost:ky(n.cost,c)}),children:TC[c]},c))})]}),s.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3 text-xs text-muted-foreground",children:[s.jsxs("span",{children:[t," matching run",t===1?"":"s"]}),s.jsxs("span",{children:[lH(e.reduce((c,u)=>c+B4(u).totalTokens,0))," total tokens loaded"]})]})]})})]}),a>0&&s.jsx("button",{type:"button",className:"rounded-sm p-1 text-muted-foreground hover:bg-accent hover:text-foreground",onClick:i,"aria-label":"Clear run filters",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})}function BR({run:e,isSelected:t,agentId:n}){const r=Ir(),{pushToast:i}=_r(),a=n7e[e.status]??{icon:GS,color:"text-neutral-400"},o=a.icon,l=B4(e),c=e.resultJson?String(e.resultJson.summary??e.resultJson.result??""):e.error??"",u=e.id.slice(0,8),d=s7e(e),f=t?`/agents/${n}/runs`:`/agents/${n}/runs/${e.id}`,h=e.status==="running"||e.status==="queued",g=cH(h),b=fH(e,g)??js(e.createdAt),v=mH(e),j=()=>{r(f)},k=N=>{N.target===N.currentTarget&&(N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),j()))},w=async N=>{N.preventDefault(),N.stopPropagation();try{await navigator.clipboard.writeText(e.id),i({title:"Run ID copied",body:"The full agent run ID is now in your clipboard.",tone:"success"})}catch(C){i({title:"Could not copy run ID",body:C instanceof Error?C.message:"Clipboard access was denied.",tone:"error"})}};return s.jsxs("div",{role:"link",tabIndex:0,"aria-label":`Open run ${u}`,className:G("flex flex-col gap-1 w-full px-3 py-2.5 text-left border-b border-border last:border-b-0 transition-colors no-underline text-inherit",t?"bg-accent/40":"hover:bg-accent/20"),onClick:j,onKeyDown:k,children:[s.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2",children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(o,{className:G("h-3.5 w-3.5 shrink-0",a.color,e.status==="running"&&"animate-spin")}),s.jsx("button",{type:"button",className:"min-w-0 truncate font-mono text-xs text-muted-foreground hover:text-foreground transition-colors cursor-copy","aria-label":`Copy run ID ${u}`,title:"Copy run ID",onClick:w,children:u}),s.jsx("span",{className:G("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium shrink-0",i7e(d.tone)),title:d.description,children:d.label})]}),s.jsx("span",{className:"shrink-0 whitespace-nowrap text-[11px] font-medium tabular-nums text-foreground",title:v||void 0,children:b})]}),c&&s.jsx("span",{className:"text-xs text-muted-foreground truncate pl-5.5",children:c.slice(0,60)}),(l.totalTokens>0||l.cost>0)&&s.jsxs("div",{className:"flex items-center gap-2 pl-5.5 text-[11px] text-muted-foreground tabular-nums",children:[l.totalTokens>0&&s.jsx("span",{children:lH(l.totalTokens)}),l.cost>0&&s.jsxs("span",{children:["$",l.cost.toFixed(3)]})]})]})}function G6t({runs:e,orgId:t,agentId:n,agentRouteId:r,selectedRunId:i,agentRuntimeType:a}){var _,E;const{isMobile:o}=aa(),[l,c]=Pu(),u=x.useMemo(()=>g7e(l),[l]);if(e.length===0)return s.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet."});const d=[...e].sort((T,M)=>new Date(M.createdAt).getTime()-new Date(T.createdAt).getTime()),f=V6t(d,u),h=W6t(u),g=H6t(u),b=T=>{c(Qse(l,T),{replace:!0})},v=()=>{c(Qse(l,{view:"all",q:"",statuses:[],sources:[],contexts:[],skills:[],date:"all",cost:[]}),{replace:!0})},j=o?i:i??((_=f[0])==null?void 0:_.id)??((E=d[0])==null?void 0:E.id)??null,k=d.find(T=>T.id===j)??null,w=!!(k&&g&&!f.some(T=>T.id===k.id)),N=w&&k?[k,...f.filter(T=>T.id!==k.id)]:f,C=g?"No runs match the current filters.":"No runs yet.",A=s.jsx(Z6t,{runs:d,filteredCount:f.length,state:u,onChange:b,onClear:v});return o?k?s.jsxs("div",{className:"space-y-3 min-w-0 overflow-x-hidden",children:[A,s.jsxs(yt,{to:`/agents/${r}/runs`,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors no-underline",children:[s.jsx(O1,{className:"h-3.5 w-3.5"}),"Back to runs"]}),s.jsx(Yse,{run:k,agentRouteId:r,agentRuntimeType:a},k.id)]}):s.jsxs("div",{className:"space-y-3",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v}),s.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:!1,agentId:r},T.id)):s.jsx(qR,{message:C})})]}):k?s.jsxs("div",{className:"min-w-0",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v,className:"mb-3 justify-end"}),s.jsxs("div",{className:"flex min-w-0 items-start gap-4",children:[s.jsx("div",{className:"min-w-0 flex-1 basis-0","data-testid":"agent-runs-detail-pane",children:s.jsx(Yse,{run:k,agentRouteId:r,agentRuntimeType:a},k.id)}),s.jsx("div",{className:"w-[clamp(18rem,24vw,24rem)] shrink-0 border border-border rounded-lg","data-testid":"agent-runs-list-pane",children:s.jsxs("div",{className:"sticky top-4 overflow-y-auto",style:{maxHeight:"calc(100vh - 2rem)"},children:[w&&s.jsx("div",{className:"border-b border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:"Selected run is outside the current filters."}),N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:T.id===j,agentId:r},T.id)):s.jsx(qR,{message:C})]})})]})]}):s.jsxs("div",{className:"space-y-3",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v}),s.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:!1,agentId:r},T.id)):s.jsx(qR,{message:C})})]})}function UR({chips:e,onClear:t,className:n}){return s.jsxs("div",{className:G("flex flex-wrap items-center gap-1.5",n),children:[e.map(r=>s.jsx("span",{className:"inline-flex h-6 items-center rounded-md border border-border bg-muted/30 px-2 text-xs text-muted-foreground",children:r},r)),s.jsx("button",{type:"button",className:"h-6 px-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:t,children:"Clear"})]})}function qR({message:e}){return s.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:e})}function Yse({run:e,agentRouteId:t,agentRuntimeType:n}){var ie,pe;const r=vn(),i=Ir(),{confirm:a}=Wr(),{data:o}=Ne({queryKey:q.runDetail(e.id),queryFn:()=>xs.get(e.id),enabled:!!e.id}),l=o??e,c=B4(l),[u,d]=x.useState(!1),[f,h]=x.useState(null);x.useEffect(()=>{h(null)},[l.id]);const g=nt({mutationFn:()=>xs.cancel(l.id),onSuccess:()=>{r.invalidateQueries({queryKey:q.heartbeats(l.orgId,l.agentId)})}}),b=l.errorCode==="process_lost"&&l.status==="failed",v=l.status==="failed"||l.status==="timed_out"||l.status==="cancelled",j=nt({mutationFn:async()=>C6t(l),onSuccess:ke=>{r.invalidateQueries({queryKey:q.heartbeats(l.orgId,l.agentId)}),i(`/agents/${t}/runs/${ke.id}`)}}),{data:k}=Ne({queryKey:q.runIssues(l.id),queryFn:()=>l1.issuesForRun(l.id)}),w=x.useMemo(()=>Array.from(new Set((k??[]).map(ke=>ke.issueId))),[k]),N=uH(l),C=dH(l),A=nt({mutationFn:async()=>w.length===0?0:(await Promise.all(w.map(ke=>Bt.resetSession(l.agentId,ke,l.orgId))),w.length),onSuccess:()=>{r.invalidateQueries({queryKey:q.agents.runtimeState(l.agentId)}),r.invalidateQueries({queryKey:q.agents.taskSessions(l.agentId)}),r.invalidateQueries({queryKey:q.runIssues(l.id)})}}),_=nt({mutationFn:()=>Bt.loginWithClaude(l.agentId,l.orgId),onSuccess:ke=>{h(ke)}}),E=l.status==="queued"||l.status==="running"&&!l.finishedAt,T=cH(E),M=fH(l,T),O=mH(l),P={hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"},z=l.startedAt?new Date(l.startedAt).toLocaleTimeString("en-US",P):null,L=l.finishedAt?new Date(l.finishedAt).toLocaleTimeString("en-US",P):null,Q=c.input>0||c.output>0||c.cached>0||c.cost>0,ee=!!(l.sessionIdBefore||l.sessionIdAfter),B=l.sessionIdBefore&&l.sessionIdAfter&&l.sessionIdBefore!==l.sessionIdAfter,F=l.exitCode!==null&&l.exitCode!==0,Z=Ca((ie=Ca(l.contextSnapshot))==null?void 0:ie.recovery),W=Nr(Z==null?void 0:Z.originalRunId)??l.retryOfRunId,$=Nr(Z==null?void 0:Z.failureKind),Y=Nr(Z==null?void 0:Z.failureSummary),V=Nr(Z==null?void 0:Z.recoveryTrigger),H=Nr(Z==null?void 0:Z.recoveryMode),ae=Ca((pe=Ca(l.contextSnapshot))==null?void 0:pe.passiveFollowup),le=Nr(ae==null?void 0:ae.originRunId),fe=Nr(ae==null?void 0:ae.previousRunId),U=Nr(ae==null?void 0:ae.reason),xe=typeof(ae==null?void 0:ae.attempt)=="number"?ae.attempt:null,re=typeof(ae==null?void 0:ae.maxAttempts)=="number"?ae.maxAttempts:null,X=l.status==="running"||l.status==="queued"?s.jsx(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs text-destructive hover:text-destructive",onClick:()=>g.mutate(),disabled:g.isPending,children:g.isPending?"Cancelling...":"Cancel"}):b?s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[s.jsx(Qv,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Resuming...":"Resume"]}):v?s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[s.jsx(Qv,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Retrying...":"Retry"]}):null;return s.jsxs("div",{className:"space-y-4 min-w-0",children:[s.jsxs("div",{className:"border border-border rounded-lg overflow-hidden","data-testid":"run-summary-card",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row",children:[s.jsxs("div",{className:"min-w-0 flex-1 p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsx("div",{className:"flex min-w-0 items-center gap-2",children:s.jsx(er,{status:l.status})}),X&&s.jsx("div",{className:"shrink-0",children:X})]}),j.isError&&s.jsx("div",{className:"text-xs text-destructive",children:j.error instanceof Error?j.error.message:"Failed to recover run"}),(M||z)&&s.jsxs("div",{className:"space-y-0.5",children:[M&&s.jsx("div",{className:"text-sm font-medium tabular-nums",children:M}),z&&s.jsxs("div",{className:"text-[11px] text-muted-foreground",title:O||void 0,children:[s.jsx("span",{className:"font-mono",children:z}),L&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:" → "}),s.jsx("span",{className:"font-mono",children:L})]})]})]}),C&&s.jsxs("div",{className:"text-xs",children:[s.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:C.title}),s.jsx("span",{className:"text-red-600 dark:text-red-400",children:C.body}),C.code&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",C.code,")"]}),C.actionPath&&C.actionLabel&&s.jsx("div",{className:"mt-1",children:s.jsx(yt,{to:C.actionPath,className:"text-xs font-medium text-red-700 underline dark:text-red-300",children:C.actionLabel})})]}),l.errorCode==="claude_auth_required"&&n==="claude_local"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(ce,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>_.mutate(),disabled:_.isPending,children:_.isPending?"Running claude login...":"Login to Claude Code"}),_.isError&&s.jsx("p",{className:"text-xs text-destructive",children:_.error instanceof Error?_.error.message:"Failed to run Claude login"}),(f==null?void 0:f.loginUrl)&&s.jsxs("p",{className:"text-xs",children:["Login URL:",s.jsx("a",{href:f.loginUrl,className:"text-blue-600 underline underline-offset-2 ml-1 break-all dark:text-blue-400",target:"_blank",rel:"noreferrer",children:f.loginUrl})]}),f&&s.jsxs(s.Fragment,{children:[!!f.stdout&&s.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:f.stdout}),!!f.stderr&&s.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:f.stderr})]})]}),F&&s.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400",children:["Exit code ",l.exitCode,l.signal&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["(signal: ",l.signal,")"]})]}),W&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/30 px-3 py-2 text-xs space-y-1",children:[s.jsx("div",{className:"font-medium text-foreground",children:"Recovery"}),s.jsxs("div",{className:"text-muted-foreground",children:["From run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${W}`,children:W})]}),(V||H)&&s.jsx("div",{className:"text-muted-foreground",children:[V,H].filter(Boolean).join(" · ")}),($||Y)&&s.jsx("div",{className:"text-muted-foreground",children:[$,Y].filter(Boolean).join(": ")})]}),le&&s.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs space-y-1",children:[s.jsx("div",{className:"font-medium text-foreground",children:"Passive follow-up"}),s.jsxs("div",{className:"text-muted-foreground",children:["Origin run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${le}`,children:le})]}),fe&&s.jsxs("div",{className:"text-muted-foreground",children:["Previous run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${fe}`,children:fe})]}),(xe||U)&&s.jsx("div",{className:"text-muted-foreground",children:[xe&&re?`attempt ${xe}/${re}`:null,U].filter(Boolean).join(" · ")})]})]}),Q&&s.jsxs("div",{className:"border-t sm:border-t-0 sm:border-l border-border p-4 grid grid-cols-2 gap-x-4 sm:gap-x-8 gap-y-3 content-center tabular-nums",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Prompt input"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.promptTokens)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Output"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.output)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Cached input"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.cached)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Cost"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:c.cost>0?`$${c.cost.toFixed(4)}`:"-"})]})]})]}),ee&&s.jsxs("div",{className:"border-t border-border",children:[s.jsxs("button",{className:"flex items-center gap-1.5 w-full px-4 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>d(ke=>!ke),children:[s.jsx(Ls,{className:G("h-3 w-3 transition-transform",u&&"rotate-90")}),"Session",B&&s.jsx("span",{className:"text-yellow-400 ml-1",children:"(changed)"})]}),u&&s.jsxs("div",{className:"px-4 pb-3 space-y-1 text-xs",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12 shrink-0",children:"Run ID"}),s.jsx(O2,{text:l.id,ariaLabel:`Copy run ID ${l.id.slice(0,8)}`,title:"Copy run ID",containerClassName:"min-w-0 max-w-full",className:"block min-w-0 break-all text-left font-mono"})]}),l.sessionIdBefore&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12",children:B?"Before":"ID"}),s.jsx(O2,{text:l.sessionIdBefore,className:"font-mono"})]}),B&&l.sessionIdAfter&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12",children:"After"}),s.jsx(O2,{text:l.sessionIdAfter,className:"font-mono"})]}),w.length>0&&s.jsxs("div",{className:"pt-1",children:[s.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground disabled:opacity-60",disabled:A.isPending,onClick:async()=>{const ke=w.length;await a({title:`Clear session for ${ke} issue${ke===1?"":"s"} touched by this run?`,confirmLabel:"Clear session",tone:"destructive"})&&A.mutate()},children:A.isPending?"clearing session...":"clear session for these issues"}),A.isError&&s.jsx("p",{className:"text-[11px] text-destructive mt-1",children:A.error instanceof Error?A.error.message:"Failed to clear sessions"})]})]})]})]}),k&&k.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Issues Touched (",k.length,")"]}),s.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:k.map(ke=>s.jsxs(yt,{to:`/issues/${ke.identifier??ke.issueId}`,className:"flex items-center justify-between w-full px-3 py-2 text-xs hover:bg-accent/20 transition-colors text-left no-underline text-inherit",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(er,{status:ke.status}),s.jsx("span",{className:"truncate",children:ke.title})]}),s.jsx("span",{className:"font-mono text-muted-foreground shrink-0 ml-2",children:ke.identifier??ke.issueId.slice(0,8)})]},ke.issueId))})]}),d6t(l)&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs font-medium text-red-600 dark:text-red-400",children:"stderr"}),s.jsx("pre",{"data-testid":"run-stderr-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:N})]}),l.stdoutExcerpt&&!l.logRef&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"stdout"}),s.jsx("pre",{"data-testid":"run-stdout-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:l.stdoutExcerpt})]}),s.jsx(_6t,{run:l,agentRuntimeType:n}),s.jsx(c7e,{})]})}function KR(){const{orgPrefix:e,agentId:t,tab:n,runId:r}=ci(),{organizations:i,selectedOrganizationId:a,setSelectedOrganizationId:o}=wn(),{closePanel:l}=oA(),{openNewIssue:c}=Wr(),{setBreadcrumbs:u}=zr(),d=vn(),f=Ir(),[h,g]=x.useState(null),[b,v]=x.useState(!1),[j,k]=x.useState(!1),w=r?"runs":Yvt(n??null),N=w==="dashboard",C=w==="runs"||!!r,A=N||C,[_,E]=x.useState("7d"),[T,M]=x.useState(!1),[O,P]=x.useState(""),[z,L]=x.useState(""),[Q,ee]=x.useState(!1),[B,F]=x.useState(!1),Z=x.useRef(null),W=x.useRef(null),{isMobile:$}=aa(),Y=t??"",H=x.useMemo(()=>{var rt;return e?((rt=Z5({organizations:i,organizationPrefix:e}))==null?void 0:rt.id)??null:null},[i,e])??a??void 0,ae=Y.length>0&&(Tz(Y)||!!H),le=x.useCallback(rt=>{Z.current=rt},[]),fe=x.useCallback(rt=>{W.current=rt},[]),{data:U,isLoading:xe,error:re}=Ne({queryKey:[...q.agents.detail(Y),H??null],queryFn:()=>Bt.get(Y,H),enabled:ae}),X=(U==null?void 0:U.orgId)??a,ie=U?r1(U):Y,pe=(U==null?void 0:U.id)??Y,ke=(U==null?void 0:U.id)??null,{data:Ce,isLoading:$e}=Ne({queryKey:q.agents.runtimeState(ke??Y),queryFn:()=>Bt.runtimeState(ke,X??void 0),enabled:!!ke&&N}),{from:Ue,to:he,customReady:We}=x.useMemo(()=>{const rt=new Date;if(_==="custom"){const xn=O?new Date(`${O}T00:00:00`):null,Se=z?new Date(`${z}T23:59:59.999`):null;return{from:xn?xn.toISOString():"",to:Se?Se.toISOString():"",customReady:!!O&&!!z}}const sn=_==="7d"?7:_==="15d"?15:30;return{from:new Date(rt.getFullYear(),rt.getMonth(),rt.getDate()-(sn-1),0,0,0,0).toISOString(),to:rt.toISOString(),customReady:!0}},[O,z,_]),ct=x.useMemo(()=>_==="7d"?DR(7):_==="15d"?DR(15):_==="30d"?DR(30):Lvt(O,z),[O,z,_]),Pe=x.useMemo(()=>$vt(_,O,z),[O,z,_]),{data:Ae,isLoading:oe}=Ne({queryKey:[...q.agents.skillsAnalytics(ke??Y),_,O,z],queryFn:()=>Bt.skillsAnalytics(ke,{orgId:X??void 0,..._==="custom"&&We?{startDate:O,endDate:z}:{windowDays:_==="7d"?7:_==="15d"?15:30}}),enabled:!!ke&&N&&(_!=="custom"||We)}),{data:D,isLoading:J}=Ne({queryKey:q.heartbeats(X,(U==null?void 0:U.id)??void 0),queryFn:()=>xs.list(X,(U==null?void 0:U.id)??void 0),enabled:!!X&&!!(U!=null&&U.id)&&A}),{data:de,isLoading:ue}=Ne({queryKey:[...q.issues.list(X),"participant-agent",ke??"__none__"],queryFn:()=>ln.list(X,{participantAgentId:ke}),enabled:!!X&&!!ke&&N}),{data:me}=Ne({queryKey:q.agents.list(X),queryFn:()=>Bt.list(X),enabled:!!X&&N}),{data:K}=Ne({queryKey:q.budgets.overview(X??"__none__"),queryFn:()=>R2.overview(X),enabled:!!X,refetchInterval:3e4,staleTime:5e3}),je=(de??[]).sort((rt,sn)=>new Date(sn.updatedAt).getTime()-new Date(rt.updatedAt).getTime()),Be=x.useMemo(()=>(D??[]).filter(rt=>Pse(rt.createdAt,Ue,he)),[Ue,D,he]),Ve=x.useMemo(()=>je.filter(rt=>Pse(rt.createdAt,Ue,he)),[je,Ue,he]),Me=x.useCallback(rt=>{if(rt==="custom"){if(!O||!z){const sn=new Date,tn=new Date(sn.getFullYear(),sn.getMonth(),sn.getDate()-6);P(SC(tn)),L(SC(sn))}E("custom"),M(!0);return}M(!1),E(rt)},[O,z]);(me??[]).find(rt=>rt.id===(U==null?void 0:U.reportsTo)),(me??[]).filter(rt=>rt.reportsTo===(U==null?void 0:U.id)&&rt.status!=="terminated");const ht=x.useMemo(()=>{const rt=K==null?void 0:K.policies.find(xn=>xn.scopeType==="agent"&&xn.scopeId===((U==null?void 0:U.id)??Y));if(rt)return rt;const sn=(U==null?void 0:U.budgetMonthlyCents)??0,tn=(U==null?void 0:U.spentMonthlyCents)??0;return{policyId:"",orgId:X??"",scopeType:"agent",scopeId:(U==null?void 0:U.id)??Y,scopeName:(U==null?void 0:U.name)??"Agent",metric:"billed_cents",windowKind:"calendar_month_utc",amount:sn,observedAmount:tn,remainingAmount:Math.max(0,sn-tn),utilizationPercent:sn>0?Number((tn/sn*100).toFixed(2)):0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:sn>0,status:sn>0&&tn>=sn?"hard_stop":"ok",paused:(U==null?void 0:U.status)==="paused",pauseReason:(U==null?void 0:U.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[U,K==null?void 0:K.policies,X,Y]),ve=x.useMemo(()=>(D??[]).find(rt=>rt.status==="running"||rt.status==="queued")??null,[D]);x.useEffect(()=>{if(!U)return;if(r){Y!==ie&&f(`/agents/${ie}/runs/${r}`,{replace:!0});return}const rt=w==="instructions"?"instructions":w==="configuration"?"configuration":w==="skills"?"skills":w==="runs"?"runs":w==="budget"?"budget":"dashboard";if(Y!==ie||n!==rt){f(`/agents/${ie}/${rt}`,{replace:!0});return}},[U,Y,ie,r,n,w,f]),x.useEffect(()=>{!(U!=null&&U.orgId)||U.orgId===a||o(U.orgId,{source:"route_sync"})},[U==null?void 0:U.orgId,a,o]);const Le=nt({mutationFn:async rt=>{if(!pe)return Promise.reject(new Error("No agent reference"));switch(rt){case"invoke":return Bt.invoke(pe,X??void 0);case"pause":return Bt.pause(pe,X??void 0);case"resume":return Bt.resume(pe,X??void 0);case"terminate":return Bt.terminate(pe,X??void 0)}},onSuccess:(rt,sn)=>{g(null),sn==="terminate"&&k(!1),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),d.invalidateQueries({queryKey:q.agents.runtimeState(pe)}),d.invalidateQueries({queryKey:q.agents.taskSessions(pe)}),X&&(d.invalidateQueries({queryKey:q.agents.list(X)}),U!=null&&U.id&&d.invalidateQueries({queryKey:q.heartbeats(X,U.id)})),sn==="invoke"&&rt&&typeof rt=="object"&&"id"in rt&&f(`/agents/${ie}/runs/${rt.id}`)},onError:rt=>{g(rt instanceof Error?rt.message:"Action failed")}}),Ie=nt({mutationFn:rt=>R2.upsertPolicy(X,{scopeType:"agent",scopeId:(U==null?void 0:U.id)??Y,amount:rt,windowKind:"calendar_month_utc"}),onSuccess:()=>{X&&(d.invalidateQueries({queryKey:q.budgets.overview(X)}),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),d.invalidateQueries({queryKey:q.agents.list(X)}),d.invalidateQueries({queryKey:q.dashboard(X)}))}}),at=nt({mutationFn:rt=>Bt.update(pe,{icon:rt},X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to update avatar")}}),Je=nt({mutationFn:rt=>Bt.uploadAvatar(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to upload avatar")}}),St=nt({mutationFn:rt=>Bt.resetSession(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.runtimeState(pe)}),d.invalidateQueries({queryKey:q.agents.taskSessions(pe)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to reset session")}}),Pt=nt({mutationFn:rt=>Bt.updatePermissions(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to update permissions")}});if(x.useEffect(()=>{const rt=[{label:"Agents",href:"/agents"}],sn=(U==null?void 0:U.name)??Y??"Agent";w==="dashboard"&&!r?rt.push({label:sn}):(rt.push({label:sn,href:`/agents/${ie}/dashboard`}),r?(rt.push({label:"Runs",href:`/agents/${ie}/runs`}),rt.push({label:`Run ${r.slice(0,8)}`})):w==="instructions"?rt.push({label:"Instructions"}):w==="configuration"?rt.push({label:"Configuration"}):w==="runs"?rt.push({label:"Runs"}):w==="budget"?rt.push({label:"Budget"}):rt.push({label:"Dashboard"})),u(rt)},[u,U,Y,ie,w,r]),x.useEffect(()=>(l(),()=>l()),[l]),Ije(x.useCallback(rt=>{Q&&(rt.preventDefault(),rt.returnValue="")},[Q])),xe)return s.jsx(As,{variant:"detail"});if(re)return s.jsx("p",{className:"text-sm text-destructive",children:re.message});if(!U)return null;if(!r&&!n)return s.jsx(es,{to:`/agents/${ie}/dashboard`,replace:!0});const _t=U.status==="pending_approval",Lt=(w==="configuration"||w==="instructions")&&(Q||B),It=_0(U.icon),Vt=N&&(J||ue||$e||oe),Sn=C&&J;return s.jsxs(s.Fragment,{children:[s.jsx(Ws,{open:j,onOpenChange:k,children:s.jsxs(ii,{className:"sm:max-w-md",children:[s.jsxs(_a,{children:[s.jsx(Wi,{children:"Terminate agent"}),s.jsx(Va,{children:"Stop this agent permanently. This action cannot be undone."})]}),s.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[s.jsxs("p",{children:[s.jsx("span",{className:"font-medium text-foreground",children:U.name})," will be marked as terminated and can no longer run or resume."]}),s.jsx("p",{children:"Future heartbeats will stay disabled until you create or replace it."})]}),s.jsxs(nl,{children:[s.jsx(ce,{variant:"ghost",onClick:()=>k(!1),disabled:Le.isPending,children:"Cancel"}),s.jsx(ce,{variant:"destructive",onClick:()=>Le.mutate("terminate"),disabled:Le.isPending,children:Le.isPending?"Terminating...":"Terminate"})]})]})}),s.jsxs("div",{className:G("space-y-6",$&&Lt&&"pb-24"),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx(A1e,{value:U.icon,onChange:rt=>at.mutate(rt),onUpload:rt=>Je.mutate(rt),uploadPending:Je.isPending,uploadError:Je.error instanceof Error?Je.error.message:null,children:s.jsx("button",{className:G("shrink-0 flex h-12 w-12 items-center justify-center transition-colors",It?"overflow-hidden rounded-full hover:opacity-85":"rounded-lg bg-accent hover:bg-accent/80"),"aria-label":"Change agent avatar",children:s.jsx(ki,{icon:U.icon,role:U.role,className:It?"h-full w-full":"h-7 w-7"})})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"text-2xl font-bold truncate",children:U.name}),s.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:[pC[U.role]??U.role,U.title?` - ${U.title}`:""]})]})]}),s.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 shrink-0",children:[s.jsxs(ce,{variant:"outline",size:"sm",onClick:()=>c({assigneeAgentId:U.id}),children:[s.jsx(tr,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Assign Task"})]}),s.jsx(ce,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs(yt,{to:{pathname:"/messenger/chat",search:`?agentId=${encodeURIComponent(U.id)}`},children:[s.jsx(fo,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Chat"})]})}),s.jsx(T$,{onClick:()=>Le.mutate("invoke"),disabled:Le.isPending||_t,label:"Run Heartbeat"}),s.jsx(I$,{isPaused:U.status==="paused",onPause:()=>Le.mutate("pause"),onResume:()=>Le.mutate("resume"),disabled:Le.isPending||_t}),s.jsx("span",{className:"hidden sm:inline",children:s.jsx(er,{status:U.status})}),ve&&s.jsxs(yt,{to:`/agents/${ie}/runs/${ve.id}`,className:"sm:hidden flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),s.jsx("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:"Live"})]}),s.jsxs(qn,{open:b,onOpenChange:v,children:[s.jsx(Wn,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"icon-xs","aria-label":"Agent actions",children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsxs(Kn,{className:"w-44 p-1",align:"end",children:[s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{navigator.clipboard.writeText(U.id),v(!1)},children:[s.jsx(Ni,{className:"h-3 w-3"}),"Copy Agent ID"]}),s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{St.mutate(null),v(!1)},children:[s.jsx(Qv,{className:"h-3 w-3"}),"Reset Sessions"]}),s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-destructive",onClick:()=>{v(!1),k(!0)},children:[s.jsx(Sa,{className:"h-3 w-3"}),"Terminate"]})]})]})]})]}),!r&&s.jsx(Dc,{value:w,onValueChange:rt=>f(`/agents/${ie}/${rt}`),children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsx(c1,{items:[{value:"dashboard",label:"Dashboard"},{value:"instructions",label:"Instructions"},{value:"skills",label:"Skills"},{value:"configuration",label:"Configuration"},{value:"runs",label:"Runs"},{value:"budget",label:"Budget"}],value:w,onValueChange:rt=>f(`/agents/${ie}/${rt}`)}),w==="dashboard"?s.jsx("div",{className:"hidden lg:block shrink-0",children:s.jsx(jC,{preset:_,customFrom:O,customTo:z,customOpen:T,onCustomOpenChange:M,onPresetSelect:Me,onCustomFromChange:P,onCustomToChange:L})}):null]})}),h&&s.jsx("p",{className:"text-sm text-destructive",children:h}),_t&&s.jsx("p",{className:"text-sm text-amber-500",children:"This agent is pending board approval and cannot be invoked yet."}),!$&&Lt&&s.jsx("div",{className:"sticky top-6 z-10 float-right transition-opacity duration-150",children:s.jsxs("div",{className:"flex items-center gap-2 bg-background/90 backdrop-blur-sm border border-border rounded-lg px-3 py-1.5 shadow-lg",children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>{var rt;return(rt=W.current)==null?void 0:rt.call(W)},disabled:B,children:"Cancel"}),s.jsx(ce,{size:"sm",onClick:()=>{var rt;return(rt=Z.current)==null?void 0:rt.call(Z)},disabled:B,children:B?"Saving…":"Save"})]})}),$&&Lt&&s.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t border-border bg-background/95 backdrop-blur-sm",children:s.jsxs("div",{className:"flex items-center justify-end gap-2 px-3 py-2",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.5rem)"},children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>{var rt;return(rt=W.current)==null?void 0:rt.call(W)},disabled:B,children:"Cancel"}),s.jsx(ce,{size:"sm",onClick:()=>{var rt;return(rt=Z.current)==null?void 0:rt.call(Z)},disabled:B,children:B?"Saving…":"Save"})]})}),w==="dashboard"&&(Vt?s.jsx(Q6t,{}):s.jsx(g6t,{agent:U,runs:D??[],chartRuns:Be,assignedIssues:je,chartIssues:Ve,runtimeState:Ce,skillAnalytics:Ae,agentId:U.id,agentRouteId:ie,rangeLabel:Pe,chartDays:ct,showDashboardFilters:_!=="custom"||We,dateFilterControl:s.jsx("div",{className:"lg:hidden",children:s.jsx(jC,{preset:_,customFrom:O,customTo:z,customOpen:T,onCustomOpenChange:M,onPresetSelect:Me,onCustomFromChange:P,onCustomToChange:L})})})),w==="instructions"&&s.jsx(w6t,{agent:U,orgId:X??void 0,onDirtyChange:ee,onSaveActionChange:le,onCancelActionChange:fe,onSavingChange:F}),w==="configuration"&&s.jsx(b6t,{agent:U,agentId:U.id,orgId:X??void 0,onDirtyChange:ee,onSaveActionChange:le,onCancelActionChange:fe,onSavingChange:F,updatePermissions:Pt}),w==="skills"&&s.jsx(N6t,{agent:U,orgId:X??void 0}),w==="runs"&&(Sn?s.jsx(Y6t,{}):s.jsx(G6t,{runs:D??[],orgId:X,agentId:U.id,agentRouteId:ie,selectedRunId:r??null,agentRuntimeType:U.agentRuntimeType})),w==="budget"&&X?s.jsx("div",{className:"max-w-3xl",children:s.jsx(NA,{summary:ht,isSaving:Ie.isPending,onSave:rt=>Ie.mutate(rt),variant:"plain"})}):null]})]})}function Q6t(){return s.jsxs("div",{"aria-busy":"true","aria-label":"Loading agent dashboard",className:"space-y-8","data-testid":"agent-dashboard-skeleton",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx(Et,{className:"h-4 w-24"}),s.jsx(Et,{className:"h-4 w-20"})]}),s.jsx(Et,{className:"h-24 w-full rounded-lg border border-border"})]}),s.jsx("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:Array.from({length:4}).map((e,t)=>s.jsx(Et,{className:"h-44 w-full rounded-lg border border-border"},t))}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Et,{className:"h-4 w-28"}),s.jsx(Et,{className:"h-4 w-16"})]}),s.jsx("div",{className:"space-y-1 rounded-lg border border-border p-3",children:Array.from({length:4}).map((e,t)=>s.jsx(Et,{className:"h-9 w-full rounded-sm"},t))})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Et,{className:"h-4 w-16"}),s.jsx(Et,{className:"h-36 w-full rounded-lg border border-border"})]})]})}function Y6t(){return s.jsxs("div",{"aria-busy":"true","aria-label":"Loading agent runs",className:"flex min-w-0 items-start gap-4","data-testid":"agent-runs-skeleton",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-0 space-y-4 rounded-lg border border-border p-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx(Et,{className:"h-5 w-44"}),s.jsx(Et,{className:"h-7 w-20"})]}),s.jsx(Et,{className:"h-28 w-full rounded-lg"}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsx(Et,{className:"h-20 w-full rounded-lg"}),s.jsx(Et,{className:"h-20 w-full rounded-lg"})]}),s.jsx(Et,{className:"h-64 w-full rounded-lg"})]}),s.jsx("div",{className:"hidden w-[14rem] shrink-0 space-y-1 rounded-lg border border-border p-2 xl:block",children:Array.from({length:5}).map((e,t)=>s.jsx(Et,{className:"h-16 w-full rounded-md"},t))})]})}function J6t(){const{selectedOrganizationId:e}=wn(),{openNewProject:t}=Wr(),{setBreadcrumbs:n}=zr();x.useEffect(()=>{n([{label:"Projects"}])},[n]);const{data:r,isLoading:i,error:a}=Ne({queryKey:q.projects.list(e),queryFn:()=>ws.list(e),enabled:!!e}),o=x.useMemo(()=>(r??[]).filter(l=>!l.archivedAt),[r]);return e?i?s.jsx(As,{variant:"list"}):o.length>0?s.jsx(es,{to:Kv(o[0]),replace:!0}):s.jsxs("div",{className:"space-y-4",children:[a&&s.jsx("p",{className:"text-sm text-destructive",children:a.message}),!i&&o.length===0&&s.jsx(Fr,{icon:Ep,message:"No projects yet.",action:"Add Project",onAction:t}),o.length>0&&s.jsx("div",{className:"border border-border",children:o.map(l=>s.jsx(pu,{title:l.name,subtitle:l.description??void 0,to:Kv(l),trailing:s.jsxs("div",{className:"flex items-center gap-3",children:[l.targetDate&&s.jsx("span",{className:"text-xs text-muted-foreground",children:Ha(l.targetDate)}),s.jsx(er,{status:l.status})]})},l.id))})]}):s.jsx(Fr,{icon:Ep,message:"Select a organization to view projects."})}function Lc({className:e,orientation:t="horizontal",decorative:n=!0,...r}){return s.jsx(jde,{"data-slot":"separator",decorative:n,orientation:t,className:G("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",e),...r})}const X6t=250,e7t=1600;function bH(){const[e,t]=x.useState("idle"),n=x.useRef(0),r=x.useRef(null),i=x.useRef(null),a=x.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null),i.current&&(clearTimeout(i.current),i.current=null)},[]);x.useEffect(()=>a,[a]);const o=x.useCallback(()=>{n.current+=1,a(),t("idle")},[a]),l=x.useCallback(()=>{a(),t("idle")},[a]),c=x.useCallback(async u=>{const d=n.current+1;n.current=d,a(),r.current=setTimeout(()=>{n.current===d&&t("saving")},X6t);try{if(await u(),n.current!==d)return;a(),t("saved"),i.current=setTimeout(()=>{n.current===d&&t("idle")},e7t)}catch(f){throw n.current!==d||(a(),t("error")),f}},[a]);return{state:e,markDirty:l,reset:o,runSave:c}}const Jse="px-1 -mx-1",t7t="px-1",n7t=900;function r7t(e){return e instanceof HTMLElement?e:e instanceof Node?e.parentElement:null}function zf({value:e,onSave:t,as:n="span",className:r,placeholder:i="Click to edit...",multiline:a=!1,imageUploadHandler:o,mentions:l}){const[c,u]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(e),b=x.useRef(null),v=x.useRef(null),j=x.useRef(null),{state:k,markDirty:w,reset:N,runSave:C}=bH();x.useEffect(()=>{a&&d||g(e)},[e,a,d]),x.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const A=x.useCallback(M=>{M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},[]);x.useEffect(()=>{c&&b.current&&(b.current.focus(),b.current.select(),b.current instanceof HTMLTextAreaElement&&A(b.current))},[c,A]),x.useEffect(()=>{if(!c||!a)return;const M=requestAnimationFrame(()=>{var O;(O=v.current)==null||O.focus()});return()=>cancelAnimationFrame(M)},[c,a]);const _=x.useCallback(async(M=h)=>{const O=M.trim();O&&O!==e?await Promise.resolve(t(O)):g(e),a||u(!1)},[h,a,t,e]);function E(M){M.key==="Enter"&&!a&&(M.preventDefault(),_()),M.key==="Escape"&&(j.current&&clearTimeout(j.current),N(),g(e),a?(f(!1),u(!1),document.activeElement instanceof HTMLElement&&document.activeElement.blur()):u(!1))}if(x.useEffect(()=>{if(!a||!d)return;const M=h.trim();if(!M||M===e){k!=="saved"&&N();return}return w(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{C(()=>_(M))},n7t),()=>{j.current&&clearTimeout(j.current)}},[k,_,h,w,a,d,N,C,e]),a&&c)return s.jsxs("div",{className:G(t7t,"rounded"),onFocusCapture:()=>f(!0),onBlurCapture:M=>{if(M.currentTarget.contains(M.relatedTarget))return;j.current&&clearTimeout(j.current),f(!1),u(!1);const O=h.trim();if(!O||O===e){N(),_();return}C(()=>_())},onKeyDown:E,children:[s.jsx(ol,{ref:v,value:h,onChange:g,placeholder:i,bordered:!1,className:"bg-transparent",contentClassName:G("rudder-edit-in-place-content",r),imageUploadHandler:o,mentions:l,onSubmit:()=>{const M=h.trim();if(!M||M===e){N(),_();return}C(()=>_())}}),s.jsx("div",{className:"flex min-h-4 items-center justify-end pr-1",children:s.jsx("span",{className:G("text-[11px] transition-opacity duration-150",k==="error"?"text-destructive":"text-muted-foreground",k==="idle"?"opacity-0":"opacity-100"),children:k==="saving"?"Autosaving...":k==="saved"?"Saved":k==="error"?"Could not save":"Idle"})})]});if(c)return s.jsx("textarea",{ref:b,value:h,rows:1,onChange:M=>{g(M.target.value),A(M.target)},onBlur:()=>{_()},onKeyDown:E,className:G("w-full bg-transparent rounded outline-none resize-none overflow-hidden",Jse,r)});const T=e&&a?"div":n;return s.jsx(T,{className:G("rounded overflow-hidden",a?"cursor-text":"cursor-pointer transition-colors hover:bg-accent/50",Jse,!e&&"text-muted-foreground italic",r),onClick:M=>{var O;(O=r7t(M.target))!=null&&O.closest("a")||u(!0)},children:e&&a?s.jsx(Aa,{onLinkClick:({event:M})=>{M.stopPropagation()},children:e}):e||i})}const s7t=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function i7t({state:e}){return e==="saving"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[s.jsx(yr,{className:"h-3 w-3 animate-spin"}),"Saving"]}):e==="saved"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-green-600 dark:text-green-400",children:[s.jsx(gs,{className:"h-3 w-3"}),"Saved"]}):e==="error"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-destructive",children:[s.jsx(g1,{className:"h-3 w-3"}),"Failed"]}):null}function Fg({label:e,state:t}){return s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:e}),s.jsx(i7t,{state:t})]})}function jh({label:e,children:t,alignStart:n=!1,valueClassName:r=""}){return s.jsxs("div",{className:G("flex gap-3 py-1.5",n?"items-start":"items-center"),children:[s.jsx("div",{className:"shrink-0 w-20",children:e}),s.jsx("div",{className:G("min-w-0 flex-1",n?"pt-0.5":"flex items-center gap-1.5",r),children:t})]})}function a7t({status:e,onChange:t}){const[n,r]=x.useState(!1),i=V1e[e]??W1e;return s.jsxs(qn,{open:n,onOpenChange:r,children:[s.jsx(Wn,{asChild:!0,children:s.jsx("button",{className:G("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0 cursor-pointer hover:opacity-80 transition-opacity",i),children:e.replace("_"," ")})}),s.jsx(Kn,{className:"w-40 p-1",align:"start",children:s7t.map(a=>s.jsx(ce,{variant:"ghost",size:"sm",className:G("w-full justify-start gap-2 text-xs",a.value===e&&"bg-accent"),onClick:()=>{t(a.value),r(!1)},children:a.label},a.value))})]})}function o7t({project:e,onArchive:t,archivePending:n}){const[r,i]=x.useState(!1),a=!e.archivedAt,o=a?"Archive":"Unarchive";return s.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:a?"Archive this project to hide it from the sidebar and project selectors.":"Unarchive this project to restore it in the sidebar and project selectors."}),n?s.jsxs(ce,{size:"sm",variant:"destructive",disabled:!0,children:[s.jsx(yr,{className:"h-3 w-3 animate-spin mr-1"}),a?"Archiving...":"Unarchiving..."]}):r?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"text-sm text-destructive font-medium",children:[o," “",e.name,"”?"]}),s.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>{i(!1),t(a)},children:"Confirm"}),s.jsx(ce,{size:"sm",variant:"outline",onClick:()=>i(!1),children:"Cancel"})]}):s.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>i(!0),children:a?s.jsxs(s.Fragment,{children:[s.jsx(o5,{className:"h-3 w-3 mr-1"}),o," project"]}):s.jsxs(s.Fragment,{children:[s.jsx(xme,{className:"h-3 w-3 mr-1"}),o," project"]})})]})}function b7e({project:e,onUpdate:t,onFieldUpdate:n,getFieldSaveState:r,onArchive:i,archivePending:a}){var k;const{selectedOrganizationId:o}=wn(),[l,c]=x.useState(!1),u=(w,N)=>{if(n){n(w,N);return}t==null||t(N)},d=w=>(r==null?void 0:r(w))??"idle",{data:f}=Ne({queryKey:q.goals.list(o),queryFn:()=>Al.list(o),enabled:!!o}),h=e.goalIds.length>0?e.goalIds:e.goalId?[e.goalId]:[],g=e.goals.length>0?e.goals:h.map(w=>{var N;return{id:w,title:((N=f==null?void 0:f.find(C=>C.id===w))==null?void 0:N.title)??w.slice(0,8)}}),b=(f??[]).filter(w=>!h.includes(w.id)),v=w=>{!t&&!n||u("goals",{goalIds:h.filter(N=>N!==w)})},j=w=>{!t&&!n||h.includes(w)||(u("goals",{goalIds:[...h,w]}),c(!1))};return s.jsxs("div",{children:[s.jsxs("div",{className:"space-y-1 pb-4",children:[s.jsx(jh,{label:s.jsx(Fg,{label:"Name",state:d("name")}),children:t||n?s.jsx(Hi,{value:e.name,onCommit:w=>u("name",{name:w}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-sm outline-none",placeholder:"Project name"}):s.jsx("span",{className:"text-sm",children:e.name})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Description",state:d("description")}),alignStart:!0,valueClassName:"space-y-0.5",children:t||n?s.jsx(zf,{value:e.description??"",onSave:w=>u("description",{description:w}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0}):s.jsx("p",{className:"text-sm text-muted-foreground",children:((k=e.description)==null?void 0:k.trim())||"No description"})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Status",state:d("status")}),children:t||n?s.jsx(a7t,{status:e.status,onChange:w=>u("status",{status:w})}):s.jsx(er,{status:e.status})}),e.leadAgentId&&s.jsx(jh,{label:"Lead",children:s.jsx("span",{className:"text-sm font-mono",children:e.leadAgentId.slice(0,8)})}),s.jsxs(jh,{label:s.jsx(Fg,{label:"Goals",state:d("goals")}),alignStart:!0,valueClassName:"space-y-2",children:[g.length>0&&s.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.map(w=>s.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[s.jsx(yt,{to:`/goals/${w.id}`,className:"hover:underline max-w-[220px] truncate",children:w.title}),(t||n)&&s.jsx("button",{className:"text-muted-foreground hover:text-foreground",type:"button",onClick:()=>v(w.id),"aria-label":`Remove goal ${w.title}`,children:s.jsx(Gs,{className:"h-3 w-3"})})]},w.id))}),(t||n)&&s.jsxs(qn,{open:l,onOpenChange:c,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"xs",className:G("h-6 w-fit px-2",g.length>0&&"ml-1"),disabled:b.length===0,children:[s.jsx(tr,{className:"h-3 w-3 mr-1"}),"Goal"]})}),s.jsx(Kn,{className:"w-56 p-1",align:"start",children:b.length===0?s.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals linked."}):b.map(w=>s.jsx("button",{className:"flex items-center w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>j(w.id),children:w.title},w.id))})]})]}),s.jsx(jh,{label:s.jsx(Fg,{label:"Created",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.createdAt)})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Updated",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.updatedAt)})}),e.targetDate&&s.jsx(jh,{label:s.jsx(Fg,{label:"Target Date",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.targetDate)})})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx(Lc,{className:"my-4"}),s.jsxs("div",{className:"space-y-4 py-4",children:[s.jsx("div",{className:"text-xs font-medium text-destructive uppercase tracking-wide",children:"Danger Zone"}),s.jsx(o7t,{project:e,onArchive:i,archivePending:a})]})]})]})}function Xse(){return{name:"",kind:"directory",locator:"",description:"",role:"working_set",note:""}}function eie(e){switch(e){case"directory":return dc;case"file":return Nd;case"connector_object":return zc;case"url":default:return G2}}function tie(e,t){return e.filter(n=>n.role===t).length}function l7t({project:e}){const{organizations:t}=wn(),{pushToast:n}=_r(),r=vn(),[i,a]=x.useState(!1),[o,l]=x.useState(!1),[c,u]=x.useState(Xse()),d=t.find(C=>C.id===e.orgId)??null,f=xf("/resources",(d==null?void 0:d.issuePrefix)??null),h=x.useMemo(()=>[...e.resources].sort((C,A)=>C.sortOrder-A.sortOrder),[e.resources]),{data:g}=Ne({queryKey:q.organizations.resources(e.orgId),queryFn:()=>Xn.listResources(e.orgId),enabled:!!e.orgId}),b=x.useMemo(()=>(g??[]).filter(C=>!e.resources.some(A=>A.resourceId===C.id)),[g,e.resources]),v=()=>{r.invalidateQueries({queryKey:["projects","detail"]}),r.invalidateQueries({queryKey:q.projects.list(e.orgId)}),r.invalidateQueries({queryKey:q.projects.resources(e.id)}),r.invalidateQueries({queryKey:q.organizations.resources(e.orgId)})},j=nt({mutationFn:C=>ws.attachResource(e.id,C,e.orgId),onSuccess:()=>{v(),n({title:"Project resource attached",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to attach project resource",tone:"error"})}}),k=nt({mutationFn:C=>ws.updateResourceAttachment(e.id,C.attachmentId,{role:C.role,note:C.note,sortOrder:C.sortOrder},e.orgId),onSuccess:()=>{v()},onError:C=>{n({title:C instanceof Error?C.message:"Failed to update project resource",tone:"error"})}}),w=nt({mutationFn:C=>ws.removeResourceAttachment(e.id,C,e.orgId),onSuccess:()=>{v(),n({title:"Project resource removed",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to remove project resource",tone:"error"})}}),N=nt({mutationFn:async()=>{const C=await Xn.createResource(e.orgId,{name:c.name.trim(),kind:c.kind,locator:c.locator.trim(),description:c.description.trim()||void 0});return ws.attachResource(e.id,{resourceId:C.id,role:c.role,note:c.note.trim()||void 0,sortOrder:e.resources.length},e.orgId)},onSuccess:()=>{v(),u(Xse()),l(!1),n({title:"Org resource created and attached",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to create and attach resource",tone:"error"})}});return s.jsxs("div",{className:"space-y-5",children:[s.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[s.jsxs("div",{className:"flex flex-col gap-4 border-b border-border px-5 py-4 md:flex-row md:items-start md:justify-between",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:"Project Context"}),s.jsx("div",{className:"text-base font-semibold text-foreground",children:"Resources"}),s.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Choose the repos, docs, URLs, and connector objects agents should actually use on this project. The org catalog stays canonical; this tab decides what matters here."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(qn,{open:i,onOpenChange:a,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"sm",disabled:b.length===0||j.isPending,children:[s.jsx(G2,{className:"mr-1.5 h-3.5 w-3.5"}),"Attach existing"]})}),s.jsxs(Kn,{align:"end",className:"w-[22rem] p-2",children:[s.jsxs("div",{className:"px-2 pb-2 pt-1",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attach from org catalog"}),s.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick an existing shared resource, then add project-specific role and note below."})]}),b.length===0?s.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"All org resources are already attached to this project."}):s.jsx("div",{className:"space-y-1",children:b.map(C=>{const A=eie(C.kind);return s.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[calc(var(--radius-sm)-1px)] border border-transparent px-2 py-2 text-left transition-colors hover:border-border hover:bg-accent/35",onClick:()=>{j.mutate({resourceId:C.id,role:"reference",sortOrder:e.resources.length}),a(!1)},children:[s.jsx("div",{className:"mt-0.5 rounded-md border border-border/70 bg-background/80 p-1.5 text-muted-foreground",children:s.jsx(A,{className:"h-3.5 w-3.5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:C.name}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:U6(C.kind)})]}),s.jsx("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:C.locator}),C.description?s.jsx("div",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:C.description}):null]})]},C.id)})})]})]}),s.jsxs(ce,{size:"sm",onClick:()=>l(!0),children:[s.jsx(hLe,{className:"mr-1.5 h-3.5 w-3.5"}),"Add resource"]}),s.jsx(ce,{asChild:!0,variant:"outline",size:"sm",children:s.jsxs(yt,{to:f,children:[s.jsx(Yz,{className:"mr-1.5 h-3.5 w-3.5"}),"Org catalog"]})})]})]}),s.jsxs("div",{className:"grid gap-3 px-5 py-4 md:grid-cols-3",children:[s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Attached"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:h.length}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Resources visible to agents on this project."})]}),s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Working Set"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:tie(h,"working_set")}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"The resources agents should actively work inside."})]}),s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Reference"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:tie(h,"reference")}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Background material that frames decisions and output."})]})]})]}),s.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[s.jsx("div",{className:"flex items-center justify-between gap-3 border-b border-border px-5 py-4",children:s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attached resources"}),s.jsx("div",{className:"text-xs text-muted-foreground",children:"Roles and notes here are project-local. They do not change the shared org catalog."})]})}),s.jsx("div",{className:"space-y-3 px-5 py-4",children:h.length===0?s.jsx("div",{className:"rounded-[var(--radius-md)] border border-dashed border-border/80 bg-background/35 px-4 py-5 text-sm text-muted-foreground",children:"No resources attached yet. Start with the repo, spec, tracking system, or any reference agents should not miss when working on this project."}):h.map(C=>{const A=eie(C.resource.kind);return s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/75 bg-[color:color-mix(in_oklab,var(--surface-elevated)_92%,transparent)] px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"rounded-md border border-border/70 bg-background/85 p-1.5 text-muted-foreground",children:s.jsx(A,{className:"h-3.5 w-3.5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:C.resource.name}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:U6(C.resource.kind)}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-emerald-300/50 bg-emerald-500/8 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-emerald-700 dark:text-emerald-300",children:cht(C.role)})]}),s.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-muted-foreground",children:C.resource.locator})]})]}),C.resource.description?s.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:C.resource.description}):null]}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>w.mutate(C.id),disabled:w.isPending,children:s.jsx(Sa,{className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-[180px_minmax(0,1fr)]",children:[s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project role"}),s.jsx("select",{value:C.role,onChange:_=>k.mutate({attachmentId:C.id,role:_.target.value,note:C.note,sortOrder:C.sortOrder}),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:sC.map(_=>s.jsx("option",{value:_.value,children:_.label},_.value))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project note"}),s.jsx(Hi,{value:C.note??"",onCommit:_=>k.mutate({attachmentId:C.id,role:C.role,note:_,sortOrder:C.sortOrder}),immediate:!0,className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",placeholder:"Optional project-specific guidance for agents"})]})]})]},C.id)})})]}),s.jsx(Ws,{open:o,onOpenChange:l,children:s.jsxs(ii,{className:"sm:max-w-2xl",children:[s.jsxs(_a,{children:[s.jsx(Wi,{children:"Add resource"}),s.jsx(Va,{children:"Create a new org resource and attach it to this project in one step. Keep the description concrete so agents know when this resource matters."})]}),s.jsxs("div",{className:"grid gap-4 py-1 md:grid-cols-2",children:[s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Name"}),s.jsx(In,{value:c.name,onChange:C=>u(A=>({...A,name:C.target.value})),placeholder:"Rudder app repo"})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Kind"}),s.jsxs("select",{value:c.kind,onChange:C=>u(A=>({...A,kind:C.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:[s.jsx("option",{value:"directory",children:"Directory"}),s.jsx("option",{value:"file",children:"File"}),s.jsx("option",{value:"url",children:"URL"}),s.jsx("option",{value:"connector_object",children:"Connector object"})]})]}),s.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Locator"}),s.jsx(aA,{kind:c.kind,value:c.locator,onChange:C=>u(A=>({...A,locator:C})),onPickedPath:C=>u(A=>({...A,locator:C,name:A.name.trim()?A.name:_K(C)})),disabled:N.isPending})]}),s.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Description"}),s.jsx(Na,{value:c.description,onChange:C=>u(A=>({...A,description:C.target.value})),placeholder:"What this resource contains and when agents should use it."})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Project role"}),s.jsx("select",{value:c.role,onChange:C=>u(A=>({...A,role:C.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:sC.map(C=>s.jsx("option",{value:C.value,children:C.label},C.value))})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Project note"}),s.jsx(In,{value:c.note,onChange:C=>u(A=>({...A,note:C.target.value})),placeholder:"Optional guidance for this project"})]})]}),s.jsxs(nl,{children:[s.jsx(ce,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),s.jsxs(ce,{onClick:()=>N.mutate(),disabled:N.isPending||!c.name.trim()||!c.locator.trim(),children:[N.isPending?s.jsx(yr,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Create and attach"]})]})]})})]})}function rk(e){return typeof e=="string"&&e.startsWith("plugin:")}function c7t(e,t){const n=e.split("/").filter(Boolean),r=n.indexOf("projects");if(r===-1||n[r+1]!==t)return null;const i=n[r+2];return i==="overview"?"configuration":i==="resources"?"resources":i==="configuration"?"configuration":i==="budget"?"budget":i==="issues"?"issues":null}function u7t({currentColor:e,onSelect:t}){const[n,r]=x.useState(!1),i=x.useRef(null);return x.useEffect(()=>{if(!n)return;function a(o){i.current&&!i.current.contains(o.target)&&r(!1)}return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[n]),s.jsxs("div",{className:"relative",ref:i,children:[s.jsx("button",{onClick:()=>r(!n),className:"shrink-0 h-5 w-5 rounded-md cursor-pointer shadow-[inset_0_0_0_1px_color-mix(in_oklab,white_24%,transparent),0_0_0_1px_color-mix(in_oklab,var(--border-base)_76%,transparent)] transition-[box-shadow] hover:ring-2 hover:ring-foreground/20",style:ic(e),"aria-label":"Change project color"}),n&&s.jsx("div",{className:"absolute top-full left-0 mt-2 p-2 bg-popover border border-border rounded-lg shadow-lg z-50 w-max",children:s.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Uv.map(a=>s.jsx("button",{onClick:()=>{t(a),r(!1)},className:`h-6 w-6 rounded-md cursor-pointer transition-[transform,box-shadow] duration-150 hover:scale-110 ${a===e?"ring-2 ring-foreground ring-offset-1 ring-offset-background":"hover:ring-2 hover:ring-foreground/30"}`,style:ic(a),"aria-label":`Select color ${a}`},a))})})]})}function zg(){const{orgPrefix:e,projectId:t}=ci(),{organizations:n,selectedOrganizationId:r,setSelectedOrganizationId:i}=wn(),{closePanel:a}=oA(),{setBreadcrumbs:o}=zr(),{pushToast:l}=_r(),c=vn(),u=Ir(),d=Mn(),[f,h]=x.useState({}),g=x.useRef({}),b=x.useRef({}),v=t??"",k=x.useMemo(()=>{var re;return e?((re=Z5({organizations:n,organizationPrefix:e}))==null?void 0:re.id)??null:null},[n,e])??r??void 0,w=v.length>0&&(Tz(v)||!!k),N=v?c7t(d.pathname,v):null,C=x.useMemo(()=>{const re=new URLSearchParams(d.search).get("tab");return rk(re)?re:null},[d.search]),A=N??C,{data:_,isLoading:E,error:T}=Ne({queryKey:[...q.projects.detail(v),k??null],queryFn:()=>ws.get(v,k),enabled:w}),M=_?Sp(_):v,O=(_==null?void 0:_.id)??v,P=(_==null?void 0:_.orgId)??r,z=x.useMemo(()=>{var re;return((re=n.find(X=>X.id===P))==null?void 0:re.issuePrefix)??e??null},[n,e,P]),L=x.useMemo(()=>_?xf(`/issues?projectId=${encodeURIComponent(_.id)}`,z):null,[_,z]),{slots:Q,isLoading:ee}=d4({slotTypes:["detailTab"],entityType:"project",enabled:!!P}),B=x.useMemo(()=>Q.map(re=>({value:`plugin:${re.pluginKey}:${re.id}`,label:re.displayName,slot:re})),[Q]),F=B.find(re=>re.value===A)??null;x.useEffect(()=>{!(_!=null&&_.orgId)||_.orgId===r||i(_.orgId,{source:"route_sync"})},[_==null?void 0:_.orgId,r,i]);const Z=()=>{c.invalidateQueries({queryKey:q.projects.detail(v)}),c.invalidateQueries({queryKey:q.projects.detail(O)}),P&&c.invalidateQueries({queryKey:q.projects.list(P)})},W=nt({mutationFn:re=>ws.update(O,re,P??k),onSuccess:Z}),$=nt({mutationFn:re=>ws.update(O,{archivedAt:re?new Date().toISOString():null},P??k),onSuccess:(re,X)=>{Z();const ie=(re==null?void 0:re.name)??(_==null?void 0:_.name)??"Project";X?(l({title:`"${ie}" has been archived`,tone:"success"}),u("/dashboard")):l({title:`"${ie}" has been unarchived`,tone:"success"})},onError:(re,X)=>{l({title:X?"Failed to archive project":"Failed to unarchive project",tone:"error"})}}),Y=nt({mutationFn:async()=>{if(!P||!_)throw new Error("Project is not ready");return Xr.create(P,{title:`Discuss ${_.name}`,contextLinks:[{entityType:"project",entityId:_.id}]})},onSuccess:re=>{c.invalidateQueries({queryKey:q.chats.list(P??"__none__")}),u(`/chat/${re.id}`)},onError:re=>{l({title:re instanceof Error?re.message:"Failed to open chat",tone:"error"})}}),{data:V}=Ne({queryKey:q.budgets.overview(P??"__none__"),queryFn:()=>R2.overview(P),enabled:!!P,refetchInterval:3e4,staleTime:5e3});x.useEffect(()=>{o([{label:"Projects",href:"/projects"},{label:(_==null?void 0:_.name)??v??"Project"}])},[o,_,v]),x.useEffect(()=>{if(_&&v!==M){if(rk(A)){u(`/projects/${M}?tab=${encodeURIComponent(A)}`,{replace:!0});return}if(A==="configuration"){u(`/projects/${M}/configuration`,{replace:!0});return}if(A==="resources"){u(`/projects/${M}/resources`,{replace:!0});return}if(A==="budget"){u(`/projects/${M}/budget`,{replace:!0});return}if(A==="issues"&&L){u(L,{replace:!0});return}u(`/projects/${M}`,{replace:!0})}},[_,v,M,A,u,L]),x.useEffect(()=>(a(),()=>a()),[a]),x.useEffect(()=>()=>{Object.values(b.current).forEach(re=>{re&&clearTimeout(re)})},[]);const H=x.useCallback((re,X)=>{h(ie=>({...ie,[re]:X}))},[]),ae=x.useCallback((re,X)=>{const ie=b.current[re];ie&&clearTimeout(ie),b.current[re]=setTimeout(()=>{h(pe=>{const ke={...pe};return delete ke[re],ke}),delete b.current[re]},X)},[]),le=x.useCallback(async(re,X)=>{const ie=(g.current[re]??0)+1;g.current[re]=ie,H(re,"saving");try{if(await ws.update(O,X,P??k),Z(),g.current[re]!==ie)return;H(re,"saved"),ae(re,1800)}catch(pe){if(g.current[re]!==ie)return;throw H(re,"error"),ae(re,3e3),pe}},[Z,k,O,P,ae,H]),fe=x.useMemo(()=>{const re=V==null?void 0:V.policies.find(X=>X.scopeType==="project"&&X.scopeId===((_==null?void 0:_.id)??v));return re||{policyId:"",orgId:P??"",scopeType:"project",scopeId:(_==null?void 0:_.id)??v,scopeName:(_==null?void 0:_.name)??"Project",metric:"billed_cents",windowKind:"lifetime",amount:0,observedAmount:0,remainingAmount:0,utilizationPercent:0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:!1,status:"ok",paused:!!(_!=null&&_.pausedAt),pauseReason:(_==null?void 0:_.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[V==null?void 0:V.policies,_,P,v]),U=nt({mutationFn:re=>R2.upsertPolicy(P,{scopeType:"project",scopeId:(_==null?void 0:_.id)??v,amount:re,windowKind:"lifetime"}),onSuccess:()=>{P&&(c.invalidateQueries({queryKey:q.budgets.overview(P)}),c.invalidateQueries({queryKey:q.projects.detail(v)}),c.invalidateQueries({queryKey:q.projects.detail(O)}),c.invalidateQueries({queryKey:q.projects.list(P)}),c.invalidateQueries({queryKey:q.dashboard(P)}))}});if(C&&!ee&&!F)return s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0});if(v&&A===null){let re=null;if(_!=null&&_.id)try{re=localStorage.getItem(`rudder:project-tab:${_.id}`)}catch{}return re==="configuration"?s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0}):re==="resources"?s.jsx(es,{to:`/projects/${M}/resources`,replace:!0}):re==="budget"?s.jsx(es,{to:`/projects/${M}/budget`,replace:!0}):(re==="issues"||re==="list")&&L?s.jsx(es,{to:L,replace:!0}):rk(re)?s.jsx(es,{to:`/projects/${M}?tab=${encodeURIComponent(re)}`,replace:!0}):s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0})}if(E)return s.jsx(As,{variant:"detail"});if(T)return s.jsx("p",{className:"text-sm text-destructive",children:T.message});if(!_)return null;const xe=re=>{if(re==="issues"){L&&u(L);return}if(_!=null&&_.id)try{localStorage.setItem(`rudder:project-tab:${_.id}`,re)}catch{}if(rk(re)){u(`/projects/${M}?tab=${encodeURIComponent(re)}`);return}u(re==="resources"?`/projects/${M}/resources`:re==="budget"?`/projects/${M}/budget`:re==="configuration"?`/projects/${M}/configuration`:`/projects/${M}/configuration`)};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"h-7 flex items-center",children:s.jsx(u7t,{currentColor:_.color??"#6366f1",onSelect:re=>W.mutate({color:re})})}),s.jsxs("div",{className:"min-w-0 space-y-2",children:[s.jsx(zf,{value:_.name,onSave:re=>W.mutate({name:re}),as:"h2",className:"text-xl font-bold"}),_.pauseReason==="budget"?s.jsxs("div",{className:G("inline-flex items-center gap-2 rounded-full border px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em]",bA.error),children:[s.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400"}),"Paused by budget hard stop"]}):null]})]}),s.jsxs(ce,{size:"sm",variant:"outline",className:"shrink-0",onClick:()=>Y.mutate(),disabled:Y.isPending,children:[s.jsx(fo,{className:"mr-1.5 h-3.5 w-3.5"}),"Chat"]})]}),s.jsx(y1,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"project",context:{orgId:P??null,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),s.jsx(_B,{placementZones:["toolbarButton"],entityType:"project",context:{orgId:P??null,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),s.jsx(Dc,{value:A??"configuration",onValueChange:re=>xe(re),children:s.jsx(c1,{items:[{value:"configuration",label:"Configuration"},{value:"resources",label:"Resources"},{value:"budget",label:"Budget"},{value:"issues",label:"Issues"},...B.map(re=>({value:re.value,label:re.label}))],align:"start",value:A??"configuration",onValueChange:re=>xe(re)})}),A==="configuration"&&s.jsx("div",{className:"max-w-4xl",children:s.jsx(b7e,{project:_,onUpdate:re=>W.mutate(re),onFieldUpdate:le,getFieldSaveState:re=>f[re]??"idle",onArchive:re=>$.mutate(re),archivePending:$.isPending})}),A==="resources"&&s.jsx("div",{className:"max-w-5xl",children:s.jsx(l7t,{project:_})}),A==="budget"&&P?s.jsx("div",{className:"max-w-3xl",children:s.jsx(NA,{summary:fe,variant:"plain",isSaving:U.isPending,onSave:re=>U.mutate(re)})}):null,F&&s.jsx(f4,{slot:F.slot,context:{orgId:P,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},missingBehavior:"placeholder"})]})}function jy(e,t){const n={};for(const r of e){const i=t(r);n[i]||(n[i]=[]),n[i].push(r)}return n}function M$({issue:e,issueLinkState:t,mobileLeading:n,desktopMetaLeading:r,desktopLeadingSpacer:i=!1,mobileMeta:a,desktopTrailing:o,trailingMeta:l,unreadState:c=null,onMarkRead:u,onOpen:d,className:f}){const h=e.identifier??e.id,g=e.identifier??e.id.slice(0,8),b=c!==null,v=c==="visible"||c==="fading";return s.jsxs(yt,{to:`/issues/${h}`,state:t,onClick:d,className:G("flex items-start gap-2 border-b panel-divider py-3 pl-3 pr-3 text-sm no-underline text-inherit transition-[background-color,border-color] hover:bg-[color:color-mix(in_oklab,var(--surface-active)_56%,transparent)] last:border-b-0 sm:items-center sm:py-2.5 sm:pl-2",f),children:[s.jsx("span",{className:"shrink-0 pt-px sm:hidden",children:n??s.jsx(os,{status:e.status})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[s.jsx("span",{className:"line-clamp-2 text-sm font-medium text-foreground sm:order-2 sm:min-w-0 sm:flex-1 sm:truncate sm:line-clamp-none",children:e.title}),s.jsxs("span",{className:"flex items-center gap-2 sm:order-1 sm:shrink-0",children:[i?s.jsx("span",{className:"hidden w-3.5 shrink-0 sm:block"}):null,r??s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"hidden shrink-0 sm:inline-flex",children:s.jsx(os,{status:e.status})}),s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:g})]}),a?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-xs text-muted-foreground sm:hidden","aria-hidden":"true",children:"·"}),s.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:a})]}):null]})]}),o||l?s.jsxs("span",{className:"ml-auto hidden shrink-0 items-center gap-2 sm:order-3 sm:flex sm:gap-3",children:[o,l?s.jsx("span",{className:"text-xs text-muted-foreground",children:l}):null]}):null,b?s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center self-center",children:v?s.jsx("button",{type:"button",onClick:j=>{j.preventDefault(),j.stopPropagation(),u==null||u()},onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),j.stopPropagation(),u==null||u())},className:"inline-flex h-4 w-4 items-center justify-center rounded-full transition-colors hover:bg-blue-500/20","aria-label":"Mark as read",children:s.jsx("span",{className:G("block h-2 w-2 rounded-full bg-blue-600 transition-opacity duration-300 dark:bg-blue-400",c==="fading"?"opacity-0":"opacity-100")})}):s.jsx("span",{className:"inline-flex h-4 w-4","aria-hidden":"true"})}):null]})}const IC=["in_progress","todo","backlog","in_review","blocked","done","cancelled"],MC=["critical","high","medium","low"],d7t=[{value:"manual",label:"Manual"},{value:"status",label:"Status"},{value:"priority",label:"Priority"},{value:"title",label:"Title"},{value:"created",label:"Created"},{value:"updated",label:"Updated"}];function sk(e,t){const n=e.indexOf(t);return n===-1?e.length:n}function op(e){return e?new Date(e).getTime():0}function f7t(e,t,n){switch(n){case"manual":return(e.boardOrder??0)-(t.boardOrder??0);case"status":return sk(IC,e.status)-sk(IC,t.status);case"priority":return sk(MC,e.priority)-sk(MC,t.priority);case"title":return e.title.localeCompare(t.title);case"created":return op(e.createdAt)-op(t.createdAt);case"updated":return op(e.updatedAt)-op(t.updatedAt)}}function y7e(e,t){const n=t.sortDir==="asc"?1:-1;return[...e].sort((r,i)=>{const a=f7t(r,i,t.sortField);if(a!==0)return n*a;const o=op(i.updatedAt)-op(r.updatedAt);if(o!==0)return o;const l=op(i.createdAt)-op(r.createdAt);return l!==0?l:(r.identifier??r.id).localeCompare(i.identifier??i.id)})}function RC(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function m7t(e,t){return RC(e).getTime()===RC(t).getTime()}function h7t(e,t){const n=RC(t);return n.setDate(n.getDate()-1),RC(e).getTime()===n.getTime()}function nie(e,t=new Date){const n=new Date(e),r=tm();if(Number.isNaN(n.getTime()))return"-";if(m7t(n,t))return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(n);if(h7t(n,t))return r==="zh-CN"?"昨天":"Yesterday";const i=r==="zh-CN"?"zh-CN":"en-US";return new Intl.DateTimeFormat(i,r==="zh-CN"?{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23",...n.getFullYear()===t.getFullYear()?{}:{year:"numeric"}}:{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23",...n.getFullYear()===t.getFullYear()?{}:{year:"numeric"}}).format(n)}const Jg=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],OC={backlog:{base:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",over:"border-[color:var(--border-strong)] bg-[color:color-mix(in_oklab,var(--surface-active)_86%,var(--surface-inset))]"},todo:{base:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",over:"border-blue-300/90 bg-blue-100/82 dark:border-blue-700/70 dark:bg-blue-900/34"},in_progress:{base:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",over:"border-amber-300/90 bg-amber-100/82 dark:border-amber-700/70 dark:bg-amber-900/34"},in_review:{base:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",over:"border-violet-300/90 bg-violet-100/82 dark:border-violet-700/70 dark:bg-violet-900/34"},blocked:{base:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",over:"border-red-300/90 bg-red-100/82 dark:border-red-700/70 dark:bg-red-900/34"},done:{base:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",over:"border-emerald-300/90 bg-emerald-100/82 dark:border-emerald-700/70 dark:bg-emerald-900/34"},cancelled:{base:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26",over:"border-neutral-300/85 bg-neutral-100/82 dark:border-neutral-700/75 dark:bg-neutral-800/36"}};function yH(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function p7t(){const e={};for(const t of Jg)e[t]=[];return e}function g7t(e,t){return e.length!==t.length?!1:e.every((n,r)=>n.id===t[r])}function x7t(e,t,n){if(!n)return e;const r=new Map(t.map(a=>[a.id,a])),i=Object.fromEntries(Jg.map(a=>[a,[...e[a]]]));for(const[a,o]of Object.entries(n.laneIdsByStatus))i[a]=o.map(l=>{const c=r.get(l);return c?c.status===a?c:{...c,status:a}:null}).filter(l=>!!l);return i}function b7t(e,t){return Object.entries(t.laneIdsByStatus).every(([n,r])=>g7t(e[n]??[],r))}const vH=["identifier","priority","assignee","reviewer","labels","project","created"];function v7e({status:e,onCreateIssue:t}){return t?s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground","data-testid":`kanban-column-add-${e}`,"aria-label":`Create ${yH(e)} issue`,onClick:()=>t(e),children:s.jsx(tr,{className:"h-3 w-3"})}):null}function rie({relationship:e,agent:t,userId:n,fallbackId:r,currentUserId:i,showRole:a=!0}){const o=e==="assignee"?"Assignee":"Reviewer",l=t?rl(t):n?Ol(n,i)??"User":r?r.slice(0,8):null;if(!l)return null;const c=e==="assignee"?Hf:Fme;return s.jsxs("span",{"data-slot":`kanban-card-${e}`,title:`${o}: ${l}`,className:"inline-flex min-w-0 max-w-full items-center gap-1.5 overflow-hidden rounded-sm bg-muted/35 px-1.5 py-1 text-muted-foreground ring-1 ring-border/35",children:[a?s.jsx("span",{"data-slot":"kanban-card-person-role",className:"shrink-0 text-[10px] font-medium leading-none text-muted-foreground/75",children:o}):null,t?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full flex-1 items-center gap-1 text-xs",children:[s.jsx(Zj,{icon:t.icon,role:t.role,className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:l})]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full flex-1 items-center gap-1 text-xs",children:[s.jsx(c,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:G("truncate",r&&"font-mono"),children:l})]})]})}function Ny({icon:e,label:t,children:n}){return s.jsxs("div",{"data-slot":"kanban-card-metadata-row",className:"grid min-w-0 grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-2 text-xs",children:[s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-muted-foreground/75",children:[s.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:e}),s.jsx("span",{className:"truncate",children:t})]}),s.jsx("span",{className:"min-w-0 overflow-hidden text-right text-muted-foreground",children:n})]})}function y7t({status:e,issues:t,agents:n,currentUserId:r,displayProperties:i=vH,liveIssueIds:a,issueLinkState:o,recentlyDroppedIssueIds:l,projects:c,onCreateIssue:u,onOpenIssue:d}){const{setNodeRef:f,isOver:h}=PK({id:e}),g=ns(),b=OC[e]??OC.backlog,v=x.useCallback(j=>{f(j),g(j)},[g,f]);return s.jsxs("div",{className:"flex h-full min-h-0 w-[260px] min-w-[260px] shrink-0 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 mb-1",children:[s.jsx(os,{status:e}),s.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:yH(e)}),s.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t.length}),s.jsx(v7e,{status:e,onCreateIssue:u})]})]}),s.jsx("div",{"data-testid":`kanban-column-${e}`,"data-over":h?"true":"false",ref:v,className:G("motion-kanban-lane scrollbar-auto-hide flex-1 min-h-[120px] overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5 space-y-1.5",h?b.over:b.base),children:s.jsx(Hye,{items:t.map(j=>j.id),strategy:Uye,children:t.map(j=>s.jsx(w7e,{issue:j,agents:n,currentUserId:r,displayProperties:i,isLive:a==null?void 0:a.has(j.id),issueLinkState:o,justDropped:l==null?void 0:l.has(j.id),projects:c,onOpenIssue:d},j.id))})})]})}function v7t({status:e,issueCount:t,onCreateIssue:n}){const{setNodeRef:r,isOver:i}=PK({id:e}),a=OC[e]??OC.backlog;return s.jsxs("div",{ref:r,"data-testid":`kanban-hidden-column-${e}`,"data-over":i?"true":"false",className:G("motion-kanban-lane flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",i?a.over:a.base),children:[s.jsx(os,{status:e}),s.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:yH(e)}),s.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t}),s.jsx(v7e,{status:e,onCreateIssue:n})]})}function w7e({issue:e,agents:t,currentUserId:n,displayProperties:r=vH,isLive:i,issueLinkState:a,isOverlay:o,justDropped:l,projects:c,onOpenIssue:u}){var F,Z;const{attributes:d,listeners:f,setNodeRef:h,transform:g,transition:b,isDragging:v}=Wye({id:e.id,data:{issue:e}}),j={transform:E1.Transform.toString(g),transition:b},k=new Set(r),w=e.assigneeAgentId?(t==null?void 0:t.find(W=>W.id===e.assigneeAgentId))??null:null,N=e.reviewerAgentId?(t==null?void 0:t.find(W=>W.id===e.reviewerAgentId))??null:null,C=e.projectId?((F=c==null?void 0:c.find(W=>W.id===e.projectId))==null?void 0:F.name)??((Z=e.project)==null?void 0:Z.name)??null:null,A=k.has("identifier"),_=k.has("priority"),E=k.has("assignee"),T=k.has("reviewer")&&!!(e.reviewerAgentId||e.reviewerUserId),M=k.has("labels")&&(e.labels??[]).length>0,O=k.has("project")&&!!C,P=k.has("updated"),z=k.has("created"),L=E?s.jsx(rie,{relationship:"assignee",agent:w,userId:e.assigneeUserId,fallbackId:!w&&e.assigneeAgentId?e.assigneeAgentId:null,currentUserId:n,showRole:!1}):null,Q=T?s.jsx(rie,{relationship:"reviewer",agent:N,userId:e.reviewerUserId,fallbackId:!N&&e.reviewerAgentId?e.reviewerAgentId:null,currentUserId:n,showRole:!1}):null,ee=_,B=!!(Q||O||M||P||z);return s.jsx("div",{ref:h,style:j,...d,...f,"data-testid":`kanban-card-${e.identifier??e.id}`,"data-dragging":v&&!o?"true":"false","data-overlay":o?"true":"false","data-live":i?"true":"false","data-just-dropped":l?"true":"false",className:G("motion-kanban-card overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5 cursor-grab active:cursor-grabbing",v&&!o?"opacity-30":"",o?"shadow-lg ring-1 ring-primary/20":"hover:shadow-sm"),children:s.jsxs(yt,{to:`/issues/${e.identifier??e.id}`,state:a,className:"block min-w-0 no-underline text-inherit",onClick:W=>{if(v){W.preventDefault();return}u==null||u(e)},children:[s.jsxs("div",{"data-slot":"kanban-card-primary",className:"space-y-2",children:[A||i||L?s.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[A?s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:e.identifier??e.id.slice(0,8)}):null,i&&s.jsx("span",{className:"motion-live-dot relative flex h-2 w-2 shrink-0 text-blue-500",children:s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-500"})})]}),L?s.jsx("span",{"data-slot":"kanban-card-primary-assignee",className:"min-w-0 max-w-[8.5rem] shrink overflow-hidden",children:L}):null]}):null,s.jsx("p",{className:"line-clamp-2 text-sm leading-snug",children:e.title}),ee?s.jsx("div",{"data-slot":"kanban-card-primary-metadata",className:"flex min-w-0 items-center gap-2 overflow-hidden",children:_?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground",title:`Priority: ${Lo(e.priority)}`,children:[s.jsx(ya,{priority:e.priority}),s.jsx("span",{className:"truncate",children:Lo(e.priority)})]}):null}):null]}),B?s.jsxs("div",{"data-slot":"kanban-card-metadata",className:"mt-2 space-y-1.5 border-t border-[color:var(--border-soft)] pt-2",children:[O?s.jsx(Ny,{icon:s.jsx(r4,{className:"h-3 w-3"}),label:"Project",children:s.jsx("span",{className:"block truncate",children:C})}):null,Q?s.jsx(Ny,{icon:s.jsx(Fme,{className:"h-3 w-3"}),label:"Reviewer",children:s.jsx("span",{className:"flex min-w-0 max-w-full justify-end overflow-hidden",children:Q})}):null,M?s.jsx(Ny,{icon:s.jsx($me,{className:"h-3 w-3"}),label:"Labels",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap justify-end gap-1",children:[(e.labels??[]).slice(0,3).map(W=>s.jsx(T2,{label:W},W.id)),(e.labels??[]).length>3?s.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(e.labels??[]).length-3]}):null]})}):null,P?s.jsx(Ny,{icon:s.jsx(Hv,{className:"h-3 w-3"}),label:"Updated",children:nie(e.updatedAt)}):null,z?s.jsx(Ny,{icon:s.jsx(Hv,{className:"h-3 w-3"}),label:"Created",children:nie(e.createdAt)}):null]}):null]})})}function w7t({issues:e,agents:t,currentUserId:n,displayProperties:r,sortState:i,liveIssueIds:a,issueLinkState:o,projects:l,onCreateIssue:c,onOpenIssue:u,onUpdateIssue:d,onReorderIssue:f}){const[h,g]=x.useState(null),[b,v]=x.useState(new Set),[j,k]=x.useState(null),w=ns(),N=x.useRef([]),C=kye(wye(fA,{activationConstraint:{distance:5}})),A=x.useMemo(()=>{const L=p7t();for(const Q of e)L[Q.status]&&L[Q.status].push(Q);if(i)for(const Q of Jg)L[Q]=y7e(L[Q]??[],i);return L},[e,i]),_=x.useMemo(()=>x7t(A,e,j),[A,e,j]),E=x.useMemo(()=>Jg.filter(L=>{var Q;return(((Q=_[L])==null?void 0:Q.length)??0)>0}),[_]),T=x.useMemo(()=>Jg.filter(L=>{var Q;return(((Q=_[L])==null?void 0:Q.length)??0)===0}),[_]),M=x.useMemo(()=>h?e.find(L=>L.id===h):null,[h,e]);x.useEffect(()=>()=>{for(const L of N.current)window.clearTimeout(L);N.current=[]},[]),x.useEffect(()=>{if(!j)return;if(b7t(A,j)){k(null);return}const L=window.setTimeout(()=>{k(null)},3e3);return()=>window.clearTimeout(L)},[A,j]);function O(L){g(L.active.id)}function P(L){var re,X;g(null);const{active:Q,over:ee}=L;if(!ee)return;const B=Q.id,F=e.find(ie=>ie.id===B);if(!F)return;let Z=null;if(Jg.includes(ee.id))Z=ee.id;else{const ie=e.find(pe=>pe.id===ee.id);ie&&(Z=ie.status)}if(!Z)return;const W=_[Z]??[],$=W.filter(ie=>ie.id!==B);let Y=$.length;if(!Jg.includes(ee.id)){const ie=W.findIndex(pe=>pe.id===ee.id);ie>=0&&(Y=ie)}const V=[...$];V.splice(Y,0,{...F,status:Z});const H=V.findIndex(ie=>ie.id===B),ae=H>0?(re=V[H-1])==null?void 0:re.id:null,le=H>=0&&H<V.length-1?(X=V[H+1])==null?void 0:X.id:null,fe=ae?le?void 0:"end":"start",U=W.map(ie=>ie.id).join(`
|
|
1392
|
+
`);Q.current=de.pop()??"",D&&Q.current&&(de.push(Q.current),Q.current="");const ue=[];for(const me of de){const K=me.trim();if(K)try{const je=JSON.parse(K),Be=je.stream==="stderr"||je.stream==="system"?je.stream:"stdout",Ve=typeof je.chunk=="string"?je.chunk:"",Me=typeof je.ts=="string"?je.ts:new Date().toISOString();if(!Ve)continue;ue.push({ts:Me,stream:Be,chunk:Ve})}catch{}}ue.length>0&&le(ue)}function le(oe){oe.length!==0&&a(D=>{const J=[];for(const de of oe){const ue=Bse(de);ee.current.has(ue)||(ee.current.add(ue),J.push(de))}return J.length===0?D:(ee.current.size>12e3&&(ee.current=new Set(J.map(Bse))),[...D,...J])})}const{data:fe}=Ne({queryKey:["run-events",e.id],queryFn:()=>xs.events(e.id,0,200)});x.useEffect(()=>{fe&&(r(fe),l(!1))},[fe]);const U=x.useCallback(()=>{if(B.current)return B.current;const oe=Qvt(z.current);return B.current=oe,oe},[]),xe=x.useCallback(()=>{const oe=U(),D=ek(oe);Z.current=D;const J=D.distanceFromBottom<=Lse;F.current=J,v(de=>de===J?de:J)},[U]);x.useEffect(()=>{if(B.current=null,Z.current={scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY},!W||!P){F.current=!1,v(!1);return}xe()},[W,e.id,P,xe]),x.useEffect(()=>{if(!W||!P)return;const oe=U();return xe(),oe===window?window.addEventListener("scroll",xe,{passive:!0}):oe.addEventListener("scroll",xe,{passive:!0}),window.addEventListener("resize",xe),()=>{oe===window?window.removeEventListener("scroll",xe):oe.removeEventListener("scroll",xe),window.removeEventListener("resize",xe)}},[W,e.id,P,U,xe]),x.useEffect(()=>{if(!W||!P||!F.current)return;const oe=U(),D=Z.current,J=ek(oe),de=Math.max(0,J.scrollHeight-D.scrollHeight),ue=D.distanceFromBottom+de;if(J.distanceFromBottom-ue>Lse){F.current=!1,v(!1),Z.current=J;return}$se(oe,"auto");const K=ek(oe);Z.current=K,F.current||(F.current=!0),v(je=>je||!0)},[n.length,i.length,W,P,U]),x.useEffect(()=>{let oe=!1;if(Q.current="",ee.current.clear(),a([]),g(0),f(null),!e.logRef&&!W)return u(!1),()=>{oe=!0};u(!0);const D=typeof e.logBytes=="number"&&e.logBytes>0?Math.min(Math.max(e.logBytes+1024,256e3),2e6):256e3;return(async()=>{try{let de=0,ue=!0;for(;!oe;){const me=await xs.log(e.id,de,ue?D:256e3);if(oe)break;ae(me.content,me.nextOffset===void 0);const K=me.nextOffset??me.endOffset??de+zse(me.content);if(g(K),de=K,ue=!1,me.nextOffset===void 0||W)break}}catch(de){if(!oe){if(W&&H(de)){u(!1);return}f(de instanceof Error?de.message:"Failed to load run log")}}finally{oe||u(!1)}})(),()=>{oe=!0}},[e.id,e.logRef,e.logBytes,W]),x.useEffect(()=>{if(!Zse({isLive:W}))return;const oe=setInterval(async()=>{const D=n.length>0?Math.max(...n.map(J=>J.seq)):0;try{const J=await xs.events(e.id,D,100);J.length>0&&r(de=>[...de,...J])}catch{}},2e3);return()=>clearInterval(oe)},[e.id,W,j,n]),x.useEffect(()=>{if(!Zse({isLive:W}))return;const oe=setInterval(async()=>{try{const D=await xs.log(e.id,h,256e3);D.content&&ae(D.content,D.nextOffset===void 0),D.nextOffset!==void 0?g(D.nextOffset):D.endOffset!==void 0?g(D.endOffset):D.content.length>0&&g(J=>J+zse(D.content))}catch(D){if(H(D))return}},2e3);return()=>clearInterval(oe)},[e.id,W,j,h]),x.useEffect(()=>{if(!W)return;let oe=!1,D=null,J=null;const de=()=>{oe||(D=window.setTimeout(ue,1500))},ue=()=>{if(oe)return;const K=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/orgs/${encodeURIComponent(e.orgId)}/events/ws`;J=new WebSocket(K),J.onopen=()=>{k(!0)},J.onmessage=je=>{const Be=typeof je.data=="string"?je.data:"";if(!Be)return;let Ve;try{Ve=JSON.parse(Be)}catch{return}if(Ve.orgId!==e.orgId)return;const Me=Ca(Ve.payload),ht=Nr(Me==null?void 0:Me.runId);if(!Me||ht!==e.id)return;if(Ve.type==="heartbeat.run.log"){if(Me.truncated===!0)return;const Pt=typeof Me.chunk=="string"?Me.chunk:"";if(!Pt)return;const _t=Nr(Me.stream),Lt=_t==="stderr"||_t==="system"?_t:"stdout",It=Nr(Me.ts)??Ve.createdAt;le([{ts:It,stream:Lt,chunk:Pt}]);return}if(Ve.type!=="heartbeat.run.event")return;const ve=typeof Me.seq=="number"?Me.seq:null;if(ve===null||!Number.isFinite(ve))return;const Le=Nr(Me.stream),Ie=Le==="stdout"||Le==="stderr"||Le==="system"?Le:null,at=Nr(Me.level),Je=at==="info"||at==="warn"||at==="error"?at:null,St={id:ve,orgId:e.orgId,runId:e.id,agentId:e.agentId,seq:ve,eventType:Nr(Me.eventType)??"event",stream:Ie,level:Je,color:Nr(Me.color),message:Nr(Me.message),payload:Ca(Me.payload),createdAt:new Date(Ve.createdAt)};r(Pt=>Pt.some(_t=>_t.seq===ve)?Pt:[...Pt,St])},J.onerror=()=>{J==null||J.close()},J.onclose=()=>{k(!1),de()}};return ue(),()=>{oe=!0,k(!1),D!==null&&window.clearTimeout(D),J&&(J.onopen=null,J.onmessage=null,J.onerror=null,J.onclose=null,J.close(1e3,"run_detail_unmount"))}},[W,e.orgId,e.id,e.agentId]);const re=((Ae=Ne({queryKey:q.instance.generalSettings,queryFn:()=>ka.getGeneral()}).data)==null?void 0:Ae.censorUsernameInLogs)===!0,X=uH(e),ie=x.useMemo(()=>{const oe=n.find(D=>D.eventType==="adapter.invoke");return Lh(Ca((oe==null?void 0:oe.payload)??null),re)},[re,n]),pe=x.useMemo(()=>{const oe=n.find(D=>D.eventType==="adapter.skill_usage");return Lh(Ca((oe==null?void 0:oe.payload)??null),re)},[re,n]),ke=x.useMemo(()=>T1(t),[t]),Ce=x.useMemo(()=>{const oe=gve(i,ke.parseStdoutLine,{censorUsernameInLogs:re}),D=Y.get(e.id)??[],J=D.length>oe.length?D:oe,de=n.map(ue=>Mvt(ue,{redactText:me=>Nu(me,re),redactValue:me=>Lh(me,re)}));return Rvt(J,de)},[ke,re,n,Y,i,e.id]),$e=!!ie,Ue=(ie==null?void 0:ie.prompt)!==void 0?Kvt(ie.prompt,re):null,he=`${Ce.length} ${Ce.length===1?"entry":"entries"}`,We=x.useCallback(()=>{var D;const oe=(D=L.current)==null?void 0:D.getBoundingClientRect();if(oe&&window.innerWidth>0&&window.innerHeight>0){const J=Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)||16,de=Math.min(window.innerWidth-24,window.innerWidth*.96,J*88),ue=Math.min(window.innerHeight*.92,J*54),me=oe.left+oe.width/2,K=oe.top+oe.height/2,je=Math.round(me-window.innerWidth/2),Be=Math.round(K-window.innerHeight/2);O({fromX:`${je}px`,fromY:`${Be}px`,settleX:`${Math.round(je*-.025)}px`,settleY:`${Math.round(Be*-.025)}px`,fromScaleX:`${Math.max(.035,Math.min(.18,oe.width/de)).toFixed(3)}`,fromScaleY:`${Math.max(.045,Math.min(.18,oe.height/ue)).toFixed(3)}`})}T(!0)},[]),ct={"--transcript-dialog-from-x":M.fromX,"--transcript-dialog-from-y":M.fromY,"--transcript-dialog-settle-x":M.settleX,"--transcript-dialog-settle-y":M.settleY,"--transcript-dialog-from-scale-x":M.fromScaleX,"--transcript-dialog-from-scale-y":M.fromScaleY},Pe=()=>s.jsx("div",{className:"inline-flex rounded-lg border border-border/70 bg-background/70 p-0.5",children:["nice","raw"].map(oe=>s.jsx("button",{type:"button",className:G("rounded-md px-2.5 py-1 text-[11px] font-medium capitalize transition-colors",w===oe?"bg-accent text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>N(oe),children:oe},oe))});return x.useEffect(()=>{N("nice"),A("transcript"),T(!1)},[e.id]),x.useEffect(()=>{!$e&&C==="invocation"&&A("transcript")},[C,$e]),o&&c?s.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading run logs..."}):n.length===0&&i.length===0&&!d?s.jsx("p",{className:"text-xs text-muted-foreground",children:"No log events."}):s.jsxs("div",{className:"space-y-3",children:[s.jsx(c6t,{operations:V,censorUsernameInLogs:re}),s.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/40",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-3 py-2 sm:px-4",children:[$e?s.jsx(Dc,{value:C,onValueChange:oe=>A(oe),children:s.jsx(c1,{items:[{value:"transcript",label:"Transcript"},{value:"invocation",label:"Invocation",mobileLabel:"Invocation",tooltip:"Exact adapter invoke payload"}],value:C,onValueChange:oe=>A(oe),align:"start",triggerClassName:"px-2 py-1 text-xs"})}):s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Transcript"}),P?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:he}),Pe(),s.jsxs(ce,{ref:L,variant:"ghost",size:"icon-sm",className:"group relative overflow-hidden text-muted-foreground transition-[background-color,border-color,color,box-shadow,transform] duration-200 hover:scale-[1.03] hover:shadow-sm active:scale-95",onClick:We,"aria-label":"Expand transcript",title:"Expand transcript",children:[s.jsx("span",{className:"absolute inset-0 rounded-[inherit] bg-accent/0 transition-colors duration-200 group-hover:bg-accent/70","aria-hidden":!0}),s.jsx(c5,{className:"relative h-4 w-4 transition-transform duration-200 ease-out group-hover:scale-110"})]}),W&&!b&&s.jsx(ce,{variant:"ghost",size:"xs",onClick:()=>{const oe=U();F.current=!0,v(!0),$se(oe,"auto"),Z.current=ek(oe)},children:"Jump to live"}),W&&s.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),"Live"]})]}):null]}),P?s.jsxs("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:[s.jsx(Qf,{entries:Ce,mode:w,streaming:W,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&s.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d}),s.jsx("div",{ref:z})]}):s.jsx("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:s.jsxs("div",{className:"space-y-3",children:[typeof(ie==null?void 0:ie.agentRuntimeType)=="string"&&s.jsxs("div",{className:"text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:"Runtime: "}),ie.agentRuntimeType]}),typeof(ie==null?void 0:ie.cwd)=="string"&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),s.jsx("span",{className:"font-mono",children:ie.cwd})]}),typeof(ie==null?void 0:ie.command)=="string"&&s.jsxs("div",{className:"text-xs break-all",children:[s.jsx("span",{className:"text-muted-foreground",children:"Command: "}),s.jsx("span",{className:"font-mono",children:[ie.command,...Array.isArray(ie.commandArgs)?ie.commandArgs.filter(oe=>typeof oe=="string"):[]].join(" ")})]}),Array.isArray(ie==null?void 0:ie.commandNotes)&&ie.commandNotes.length>0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Command notes"}),s.jsx("ul",{className:"list-disc space-y-1 pl-5",children:ie.commandNotes.filter(oe=>typeof oe=="string"&&oe.trim().length>0).map((oe,D)=>s.jsx("li",{className:"text-xs break-all font-mono",children:oe},`${D}-${oe}`))})]}),s.jsx(n6t,{invocationPayload:ie,usagePayload:pe}),Ue!==null&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Prompt"}),s.jsxs("div",{className:"relative",children:[s.jsx(O2,{text:Ue,ariaLabel:"Copy invocation prompt",title:"Copy prompt",containerClassName:"absolute right-2 top-2",className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/70 bg-background/80 text-muted-foreground shadow-sm hover:bg-muted/80 hover:text-foreground",children:s.jsx(Ni,{className:"h-3.5 w-3.5"})}),s.jsx("pre",{"data-testid":"invocation-prompt",className:"rounded-md bg-neutral-100 p-2 pr-11 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:Ue})]})]}),(ie==null?void 0:ie.context)!==void 0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Context"}),s.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:JSON.stringify(Lh(ie.context,re),null,2)})]}),(ie==null?void 0:ie.env)!==void 0&&s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Environment"}),s.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs font-mono whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:Zvt(ie.env,re)})]}),n.length>0&&s.jsx(s6t,{events:n,censorUsernameInLogs:re})]})})]}),s.jsx(Ws,{open:E,onOpenChange:T,children:s.jsxs(ii,{overlayClassName:"transcript-modal-overlay",style:ct,className:"transcript-modal-content grid h-[min(92dvh,54rem)] max-w-[min(96vw,88rem)] grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden rounded-2xl p-0 sm:max-w-[min(96vw,88rem)]",children:[s.jsx(_a,{className:"transcript-modal-header border-b border-border/70 px-4 py-3 pr-12 text-left",children:s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(Wi,{className:"text-sm",children:"Transcript"}),s.jsxs(Va,{className:"sr-only",children:["Expanded transcript for run ",e.id,"."]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:he}),Pe(),W&&s.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-cyan-400"})]}),"Live"]})]})]})}),s.jsxs("div",{className:"transcript-modal-body min-h-0 overflow-y-auto p-3 sm:p-4",children:[s.jsx(Qf,{entries:Ce,mode:w,streaming:W,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&s.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d})]})]})}),(e.status==="failed"||e.status==="timed_out")&&s.jsxs("div",{className:"rounded-lg border border-red-300 dark:border-red-500/30 bg-red-50 dark:bg-red-950/20 p-3 space-y-2",children:[s.jsx("div",{className:"text-xs font-medium text-red-700 dark:text-red-300",children:"Failure details"}),_&&s.jsxs("div",{className:"text-xs text-red-600 dark:text-red-200",children:[s.jsxs("span",{className:"text-red-700 dark:text-red-300",children:[_.title,": "]}),Nu(_.body,re),_.actionPath&&_.actionLabel&&s.jsx("div",{className:"mt-1",children:s.jsx(yt,{to:_.actionPath,className:"text-xs font-medium text-red-700 underline dark:text-red-300",children:_.actionLabel})})]}),X&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stderr excerpt"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:Nu(X,re)})]}),e.resultJson&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"runtime result JSON"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:JSON.stringify(Lh(e.resultJson,re),null,2)})]}),e.stdoutExcerpt&&e.stdoutExcerpt.trim()&&!e.resultJson&&s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stdout excerpt"}),s.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:Nu(e.stdoutExcerpt,re)})]})]})]})}const pH=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"failed",label:"Failed"},{value:"issue",label:"Issue work"},{value:"retries",label:"Retries"},{value:"expensive",label:"Expensive"}],u7e={queued:"Queued",running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled",timed_out:"Timed out"},d7e={timer:"Timer",assignment:"Assignment",review:"Review",on_demand:"Manual",automation:"Automation"},AC={issue:"Issue-backed",retry:"Retry / recovery",followup:"Passive follow-up",process_lost:"Process lost"},EC={all:"Any time","24h":"24h","7d":"7d","30d":"30d"},TC={high_tokens:">500k tokens",long:">30m"},A6t=new Set(pH.map(e=>e.value)),E6t=new Set(eP),T6t=new Set(Ofe),I6t=new Set(Object.keys(AC)),M6t=new Set(Object.keys(EC)),R6t=new Set(Object.keys(TC)),O6t=["queued","running"],f7e=5e5,m7e=1800*1e3;function nk(e,t){if(!e)return[];const n=[],r=new Set;for(const i of e.split(",")){const a=i.trim();!t.has(a)||r.has(a)||(r.add(a),n.push(a))}return n}function wy(e){return e.length>0?e.join(","):null}function P6t(e){if(!e)return[];const t=[],n=new Set;for(const r of e.split(",")){const i=r.trim();!i||n.has(i)||(n.add(i),t.push(i))}return t}function ky(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function gH(e){var t;return Nr((t=Ca(e.contextSnapshot))==null?void 0:t.issueId)}function h7e(e){const t=Ca(e.contextSnapshot);return!!(e.retryOfRunId||Ca(t==null?void 0:t.recovery))}function D6t(e){const t=Ca(e.contextSnapshot);return!!Ca(t==null?void 0:t.passiveFollowup)}function p7e(e){if(!e.startedAt)return 0;const t=new Date(e.startedAt).getTime(),n=e.finishedAt?new Date(e.finishedAt).getTime():Date.now();return!Number.isFinite(t)||!Number.isFinite(n)||n<t?0:n-t}function L6t(e){return B4(e).totalTokens>=f7e||p7e(e)>=m7e}function $6t(e,t){switch(t){case"active":return O6t.includes(e.status);case"failed":return e.status==="failed"||e.status==="timed_out";case"issue":return!!gH(e);case"retries":return h7e(e);case"expensive":return L6t(e);case"all":default:return!0}}function F6t(e,t){switch(t){case"issue":return!!gH(e);case"retry":return h7e(e);case"followup":return D6t(e);case"process_lost":return e.errorCode==="process_lost"}}function z6t(e,t){if(t==="all")return!0;const n=new Date(e.createdAt).getTime();if(!Number.isFinite(n))return!1;const r=t==="24h"?1440*60*1e3:t==="7d"?10080*60*1e3:720*60*60*1e3;return n>=Date.now()-r}function B6t(e,t){return t==="high_tokens"?B4(e).totalTokens>=f7e:p7e(e)>=m7e}function U6t(e){const t=Ca(e);if(t){const r=Nr(t.key)??Nr(t.runtimeName)??Nr(t.name);return r?{key:r,label:Nr(t.runtimeName)??Nr(t.name)??r.split(/[/:]/).filter(Boolean).at(-1)??r}:null}const n=Nr(e);return n?{key:n,label:n.split(/[/:]/).filter(Boolean).at(-1)??n}:null}function Gse(e){if(!e)return[];const t=[...d3(e,"usedSkills"),...e.skillEvidenceType==="used"?d3(e,"skillEvidenceSkills"):[]],n=[...Array.isArray(e.usedSkillKeys)?e.usedSkillKeys:[],...e.skillEvidenceType==="used"&&Array.isArray(e.skillEvidenceKeys)?e.skillEvidenceKeys:[]].map(U6t).filter(a=>!!a),r=new Set,i=[];for(const a of[...t,...n])r.has(a.key)||(r.add(a.key),i.push(a));return i}function xH(e){const t=[...Gse(Ca(e.usageJson)),...Gse(Ca(e.resultJson))],n=new Set;return t.filter(r=>n.has(r.key)?!1:(n.add(r.key),!0))}function q6t(e){const t=new Map;for(const n of e)for(const r of xH(n)){const i=t.get(r.key);i?(i.count+=1,i.label===i.key&&r.label!==r.key&&(i.label=r.label)):t.set(r.key,{key:r.key,label:r.label,count:1})}return Array.from(t.values()).sort((n,r)=>r.count-n.count||n.label.localeCompare(r.label))}function K6t(e){const t=Ca(e.resultJson);return[e.id,e.status,e.invocationSource,e.triggerDetail,e.error,e.errorCode,gH(e),Nr(t==null?void 0:t.summary),Nr(t==null?void 0:t.result),...xH(e).flatMap(n=>[n.key,n.label])].filter(Boolean).join(" ").toLowerCase()}function g7e(e){var r;const t=e.get("runView"),n=e.get("runDate");return{view:t&&A6t.has(t)?t:"all",q:((r=e.get("runQ"))==null?void 0:r.trim())??"",statuses:nk(e.get("runStatus"),E6t),sources:nk(e.get("runSource"),T6t),contexts:nk(e.get("runContext"),I6t),skills:P6t(e.get("runSkill")),date:n&&M6t.has(n)?n:"all",cost:nk(e.get("runCost"),R6t)}}function Qse(e,t){const n={...g7e(e),...t},r=new URLSearchParams(e);n.view==="all"?r.delete("runView"):r.set("runView",n.view),n.q.trim()?r.set("runQ",n.q.trim()):r.delete("runQ");const i=[["runStatus",wy(n.statuses)],["runSource",wy(n.sources)],["runContext",wy(n.contexts)],["runSkill",wy(n.skills)],["runCost",wy(n.cost)],["runDate",n.date==="all"?null:n.date]];for(const[a,o]of i)o?r.set(a,o):r.delete(a);return r}function H6t(e){return x7e(e)>0}function x7e(e){return+(e.view!=="all")+ +(e.q.length>0)+ +(e.statuses.length>0)+ +(e.sources.length>0)+ +(e.contexts.length>0)+ +(e.skills.length>0)+ +(e.date!=="all")+ +(e.cost.length>0)}function V6t(e,t){const n=t.q.toLowerCase();return e.filter(r=>!(!$6t(r,t.view)||t.statuses.length>0&&!t.statuses.includes(r.status)||t.sources.length>0&&!t.sources.includes(r.invocationSource)||t.contexts.length>0&&!t.contexts.every(i=>F6t(r,i))||t.skills.length>0&&!xH(r).some(i=>t.skills.includes(i.key))||t.cost.length>0&&!t.cost.every(i=>B6t(r,i))||!z6t(r,t.date)||n&&!K6t(r).includes(n)))}function W6t(e){var n;const t=[];e.view!=="all"&&t.push(((n=pH.find(r=>r.value===e.view))==null?void 0:n.label)??e.view),e.q&&t.push(`Search: ${e.q}`),e.statuses.length>0&&t.push(`Status: ${e.statuses.map(r=>u7e[r]).join(", ")}`),e.sources.length>0&&t.push(`Source: ${e.sources.map(r=>d7e[r]).join(", ")}`);for(const r of e.contexts)t.push(AC[r]);e.skills.length>0&&t.push(`Skill: ${e.skills.join(", ")}`);for(const r of e.cost)t.push(TC[r]);return e.date!=="all"&&t.push(EC[e.date]),t}function Z6t({runs:e,filteredCount:t,state:n,onChange:r,onClear:i}){const a=x7e(n),o=x.useMemo(()=>{const c=new Map;for(const u of eP)c.set(u,0);for(const u of e)c.set(u.status,(c.get(u.status)??0)+1);return c},[e]),l=x.useMemo(()=>q6t(e),[e]);return s.jsx("div",{className:"pointer-events-none sticky top-2 z-20 mb-3 flex justify-end",children:s.jsxs("div",{className:"pointer-events-auto flex max-w-full flex-wrap items-center justify-end gap-2 rounded-lg border border-border bg-background/95 px-2.5 py-2 shadow-sm backdrop-blur supports-[backdrop-filter]:bg-background/85","data-testid":"run-filter-floating-toolbar",children:[s.jsx("div",{className:"flex items-center overflow-hidden rounded-md border border-border bg-muted/20",children:pH.map(c=>s.jsx("button",{type:"button",className:G("h-7 px-2.5 text-xs transition-colors",n.view===c.value?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/40"),onClick:()=>r({view:c.value}),children:c.label},c.value))}),s.jsxs("label",{className:"relative block w-[min(14rem,42vw)]",children:[s.jsx(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),s.jsx(In,{"aria-label":"Search runs",value:n.q,onChange:c=>r({q:c.target.value}),placeholder:"Search runs",className:"h-7 pl-7 pr-2 text-xs"})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",a>0&&"text-[color:var(--accent-strong)] bg-accent/30"),children:[s.jsx(o4,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:a>0?`Filter: ${a}`:"Filter"})]})}),s.jsx(Kn,{align:"end",sideOffset:8,className:"w-[min(440px,calc(100vw-2rem))] p-0","data-testid":"run-filter-popover",children:s.jsxs("div",{className:"space-y-3 p-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($j,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm font-medium",children:"Filter runs"})]}),a>0&&s.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:i,children:"Clear"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),s.jsx("div",{className:"grid grid-cols-2 gap-1",children:eP.map(c=>s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1 hover:bg-accent/50",children:[s.jsx(eo,{checked:n.statuses.includes(c),onCheckedChange:()=>r({statuses:ky(n.statuses,c)})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:u7e[c]}),s.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:o.get(c)??0})]},c))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Source"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Ofe.map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.sources.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({sources:ky(n.sources,c)}),children:d7e[c]},c))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Date"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(EC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.date===c?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({date:c}),children:EC[c]},c))})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Context"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(AC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.contexts.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({contexts:ky(n.contexts,c)}),children:AC[c]},c))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Used skill"}),l.length>0?s.jsx("div",{className:"max-h-28 overflow-y-auto pr-1",children:s.jsx("div",{className:"flex flex-wrap gap-1",children:l.map(c=>s.jsxs("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.skills.includes(c.key)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),title:c.key,onClick:()=>r({skills:ky(n.skills,c.key)}),children:[c.label,s.jsx("span",{className:"ml-1 opacity-70",children:c.count})]},c.key))})}):s.jsx("div",{className:"rounded-md border border-border/70 px-2 py-1.5 text-xs text-muted-foreground",children:"No used skills found in loaded runs."})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Cost & duration"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(TC).map(c=>s.jsx("button",{type:"button",className:G("rounded-md border px-2 py-1 text-xs transition-colors",n.cost.includes(c)?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground hover:text-foreground"),onClick:()=>r({cost:ky(n.cost,c)}),children:TC[c]},c))})]}),s.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3 text-xs text-muted-foreground",children:[s.jsxs("span",{children:[t," matching run",t===1?"":"s"]}),s.jsxs("span",{children:[lH(e.reduce((c,u)=>c+B4(u).totalTokens,0))," total tokens loaded"]})]})]})})]}),a>0&&s.jsx("button",{type:"button",className:"rounded-sm p-1 text-muted-foreground hover:bg-accent hover:text-foreground",onClick:i,"aria-label":"Clear run filters",children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})})}function BR({run:e,isSelected:t,agentId:n}){const r=Ir(),{pushToast:i}=_r(),a=n7e[e.status]??{icon:GS,color:"text-neutral-400"},o=a.icon,l=B4(e),c=e.resultJson?String(e.resultJson.summary??e.resultJson.result??""):e.error??"",u=e.id.slice(0,8),d=s7e(e),f=t?`/agents/${n}/runs`:`/agents/${n}/runs/${e.id}`,h=e.status==="running"||e.status==="queued",g=cH(h),b=fH(e,g)??js(e.createdAt),v=mH(e),j=()=>{r(f)},k=N=>{N.target===N.currentTarget&&(N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),j()))},w=async N=>{N.preventDefault(),N.stopPropagation();try{await navigator.clipboard.writeText(e.id),i({title:"Run ID copied",body:"The full agent run ID is now in your clipboard.",tone:"success"})}catch(C){i({title:"Could not copy run ID",body:C instanceof Error?C.message:"Clipboard access was denied.",tone:"error"})}};return s.jsxs("div",{role:"link",tabIndex:0,"aria-label":`Open run ${u}`,className:G("flex flex-col gap-1 w-full px-3 py-2.5 text-left border-b border-border last:border-b-0 transition-colors no-underline text-inherit",t?"bg-accent/40":"hover:bg-accent/20"),onClick:j,onKeyDown:k,children:[s.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2",children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(o,{className:G("h-3.5 w-3.5 shrink-0",a.color,e.status==="running"&&"animate-spin")}),s.jsx("button",{type:"button",className:"min-w-0 truncate font-mono text-xs text-muted-foreground hover:text-foreground transition-colors cursor-copy","aria-label":`Copy run ID ${u}`,title:"Copy run ID",onClick:w,children:u}),s.jsx("span",{className:G("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium shrink-0",i7e(d.tone)),title:d.description,children:d.label})]}),s.jsx("span",{className:"shrink-0 whitespace-nowrap text-[11px] font-medium tabular-nums text-foreground",title:v||void 0,children:b})]}),c&&s.jsx("span",{className:"text-xs text-muted-foreground truncate pl-5.5",children:c.slice(0,60)}),(l.totalTokens>0||l.cost>0)&&s.jsxs("div",{className:"flex items-center gap-2 pl-5.5 text-[11px] text-muted-foreground tabular-nums",children:[l.totalTokens>0&&s.jsx("span",{children:lH(l.totalTokens)}),l.cost>0&&s.jsxs("span",{children:["$",l.cost.toFixed(3)]})]})]})}function G6t({runs:e,orgId:t,agentId:n,agentRouteId:r,selectedRunId:i,agentRuntimeType:a}){var _,E;const{isMobile:o}=aa(),[l,c]=Pu(),u=x.useMemo(()=>g7e(l),[l]);if(e.length===0)return s.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet."});const d=[...e].sort((T,M)=>new Date(M.createdAt).getTime()-new Date(T.createdAt).getTime()),f=V6t(d,u),h=W6t(u),g=H6t(u),b=T=>{c(Qse(l,T),{replace:!0})},v=()=>{c(Qse(l,{view:"all",q:"",statuses:[],sources:[],contexts:[],skills:[],date:"all",cost:[]}),{replace:!0})},j=o?i:i??((_=f[0])==null?void 0:_.id)??((E=d[0])==null?void 0:E.id)??null,k=d.find(T=>T.id===j)??null,w=!!(k&&g&&!f.some(T=>T.id===k.id)),N=w&&k?[k,...f.filter(T=>T.id!==k.id)]:f,C=g?"No runs match the current filters.":"No runs yet.",A=s.jsx(Z6t,{runs:d,filteredCount:f.length,state:u,onChange:b,onClear:v});return o?k?s.jsxs("div",{className:"space-y-3 min-w-0 overflow-x-hidden",children:[A,s.jsxs(yt,{to:`/agents/${r}/runs`,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors no-underline",children:[s.jsx(O1,{className:"h-3.5 w-3.5"}),"Back to runs"]}),s.jsx(Yse,{run:k,agentRouteId:r,agentRuntimeType:a},k.id)]}):s.jsxs("div",{className:"space-y-3",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v}),s.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:!1,agentId:r},T.id)):s.jsx(qR,{message:C})})]}):k?s.jsxs("div",{className:"min-w-0",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v,className:"mb-3 justify-end"}),s.jsxs("div",{className:"flex min-w-0 items-start gap-4",children:[s.jsx("div",{className:"min-w-0 flex-1 basis-0","data-testid":"agent-runs-detail-pane",children:s.jsx(Yse,{run:k,agentRouteId:r,agentRuntimeType:a},k.id)}),s.jsx("div",{className:"w-[clamp(18rem,24vw,24rem)] shrink-0 border border-border rounded-lg","data-testid":"agent-runs-list-pane",children:s.jsxs("div",{className:"sticky top-4 overflow-y-auto",style:{maxHeight:"calc(100vh - 2rem)"},children:[w&&s.jsx("div",{className:"border-b border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:"Selected run is outside the current filters."}),N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:T.id===j,agentId:r},T.id)):s.jsx(qR,{message:C})]})})]})]}):s.jsxs("div",{className:"space-y-3",children:[A,h.length>0&&s.jsx(UR,{chips:h,onClear:v}),s.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:N.length>0?N.map(T=>s.jsx(BR,{run:T,isSelected:!1,agentId:r},T.id)):s.jsx(qR,{message:C})})]})}function UR({chips:e,onClear:t,className:n}){return s.jsxs("div",{className:G("flex flex-wrap items-center gap-1.5",n),children:[e.map(r=>s.jsx("span",{className:"inline-flex h-6 items-center rounded-md border border-border bg-muted/30 px-2 text-xs text-muted-foreground",children:r},r)),s.jsx("button",{type:"button",className:"h-6 px-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:t,children:"Clear"})]})}function qR({message:e}){return s.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:e})}function Yse({run:e,agentRouteId:t,agentRuntimeType:n}){var ie,pe;const r=vn(),i=Ir(),{confirm:a}=Wr(),{data:o}=Ne({queryKey:q.runDetail(e.id),queryFn:()=>xs.get(e.id),enabled:!!e.id}),l=o??e,c=B4(l),[u,d]=x.useState(!1),[f,h]=x.useState(null);x.useEffect(()=>{h(null)},[l.id]);const g=nt({mutationFn:()=>xs.cancel(l.id),onSuccess:()=>{r.invalidateQueries({queryKey:q.heartbeats(l.orgId,l.agentId)})}}),b=l.errorCode==="process_lost"&&l.status==="failed",v=l.status==="failed"||l.status==="timed_out"||l.status==="cancelled",j=nt({mutationFn:async()=>C6t(l),onSuccess:ke=>{r.invalidateQueries({queryKey:q.heartbeats(l.orgId,l.agentId)}),i(`/agents/${t}/runs/${ke.id}`)}}),{data:k}=Ne({queryKey:q.runIssues(l.id),queryFn:()=>l1.issuesForRun(l.id)}),w=x.useMemo(()=>Array.from(new Set((k??[]).map(ke=>ke.issueId))),[k]),N=uH(l),C=dH(l),A=nt({mutationFn:async()=>w.length===0?0:(await Promise.all(w.map(ke=>Bt.resetSession(l.agentId,ke,l.orgId))),w.length),onSuccess:()=>{r.invalidateQueries({queryKey:q.agents.runtimeState(l.agentId)}),r.invalidateQueries({queryKey:q.agents.taskSessions(l.agentId)}),r.invalidateQueries({queryKey:q.runIssues(l.id)})}}),_=nt({mutationFn:()=>Bt.loginWithClaude(l.agentId,l.orgId),onSuccess:ke=>{h(ke)}}),E=l.status==="queued"||l.status==="running"&&!l.finishedAt,T=cH(E),M=fH(l,T),O=mH(l),P={hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"},z=l.startedAt?new Date(l.startedAt).toLocaleTimeString("en-US",P):null,L=l.finishedAt?new Date(l.finishedAt).toLocaleTimeString("en-US",P):null,Q=c.input>0||c.output>0||c.cached>0||c.cost>0,ee=!!(l.sessionIdBefore||l.sessionIdAfter),B=l.sessionIdBefore&&l.sessionIdAfter&&l.sessionIdBefore!==l.sessionIdAfter,F=l.exitCode!==null&&l.exitCode!==0,Z=Ca((ie=Ca(l.contextSnapshot))==null?void 0:ie.recovery),W=Nr(Z==null?void 0:Z.originalRunId)??l.retryOfRunId,$=Nr(Z==null?void 0:Z.failureKind),Y=Nr(Z==null?void 0:Z.failureSummary),V=Nr(Z==null?void 0:Z.recoveryTrigger),H=Nr(Z==null?void 0:Z.recoveryMode),ae=Ca((pe=Ca(l.contextSnapshot))==null?void 0:pe.passiveFollowup),le=Nr(ae==null?void 0:ae.originRunId),fe=Nr(ae==null?void 0:ae.previousRunId),U=Nr(ae==null?void 0:ae.reason),xe=typeof(ae==null?void 0:ae.attempt)=="number"?ae.attempt:null,re=typeof(ae==null?void 0:ae.maxAttempts)=="number"?ae.maxAttempts:null,X=l.status==="running"||l.status==="queued"?s.jsx(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs text-destructive hover:text-destructive",onClick:()=>g.mutate(),disabled:g.isPending,children:g.isPending?"Cancelling...":"Cancel"}):b?s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[s.jsx(Qv,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Resuming...":"Resume"]}):v?s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[s.jsx(Qv,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Retrying...":"Retry"]}):null;return s.jsxs("div",{className:"space-y-4 min-w-0",children:[s.jsxs("div",{className:"border border-border rounded-lg overflow-hidden","data-testid":"run-summary-card",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row",children:[s.jsxs("div",{className:"min-w-0 flex-1 p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsx("div",{className:"flex min-w-0 items-center gap-2",children:s.jsx(er,{status:l.status})}),X&&s.jsx("div",{className:"shrink-0",children:X})]}),j.isError&&s.jsx("div",{className:"text-xs text-destructive",children:j.error instanceof Error?j.error.message:"Failed to recover run"}),(M||z)&&s.jsxs("div",{className:"space-y-0.5",children:[M&&s.jsx("div",{className:"text-sm font-medium tabular-nums",children:M}),z&&s.jsxs("div",{className:"text-[11px] text-muted-foreground",title:O||void 0,children:[s.jsx("span",{className:"font-mono",children:z}),L&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:" → "}),s.jsx("span",{className:"font-mono",children:L})]})]})]}),C&&s.jsxs("div",{className:"text-xs",children:[s.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:C.title}),s.jsx("span",{className:"text-red-600 dark:text-red-400",children:C.body}),C.code&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",C.code,")"]}),C.actionPath&&C.actionLabel&&s.jsx("div",{className:"mt-1",children:s.jsx(yt,{to:C.actionPath,className:"text-xs font-medium text-red-700 underline dark:text-red-300",children:C.actionLabel})})]}),l.errorCode==="claude_auth_required"&&n==="claude_local"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(ce,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>_.mutate(),disabled:_.isPending,children:_.isPending?"Running Claude auth login...":"Login to Claude Code"}),_.isError&&s.jsx("p",{className:"text-xs text-destructive",children:_.error instanceof Error?_.error.message:"Failed to run Claude login"}),(f==null?void 0:f.loginUrl)&&s.jsxs("p",{className:"text-xs",children:["Login URL:",s.jsx("a",{href:f.loginUrl,className:"text-blue-600 underline underline-offset-2 ml-1 break-all dark:text-blue-400",target:"_blank",rel:"noreferrer",children:f.loginUrl})]}),f&&s.jsxs(s.Fragment,{children:[!!f.stdout&&s.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:f.stdout}),!!f.stderr&&s.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:f.stderr})]})]}),F&&s.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400",children:["Exit code ",l.exitCode,l.signal&&s.jsxs("span",{className:"text-muted-foreground ml-1",children:["(signal: ",l.signal,")"]})]}),W&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/30 px-3 py-2 text-xs space-y-1",children:[s.jsx("div",{className:"font-medium text-foreground",children:"Recovery"}),s.jsxs("div",{className:"text-muted-foreground",children:["From run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${W}`,children:W})]}),(V||H)&&s.jsx("div",{className:"text-muted-foreground",children:[V,H].filter(Boolean).join(" · ")}),($||Y)&&s.jsx("div",{className:"text-muted-foreground",children:[$,Y].filter(Boolean).join(": ")})]}),le&&s.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs space-y-1",children:[s.jsx("div",{className:"font-medium text-foreground",children:"Passive follow-up"}),s.jsxs("div",{className:"text-muted-foreground",children:["Origin run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${le}`,children:le})]}),fe&&s.jsxs("div",{className:"text-muted-foreground",children:["Previous run"," ",s.jsx(yt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${fe}`,children:fe})]}),(xe||U)&&s.jsx("div",{className:"text-muted-foreground",children:[xe&&re?`attempt ${xe}/${re}`:null,U].filter(Boolean).join(" · ")})]})]}),Q&&s.jsxs("div",{className:"border-t sm:border-t-0 sm:border-l border-border p-4 grid grid-cols-2 gap-x-4 sm:gap-x-8 gap-y-3 content-center tabular-nums",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Prompt input"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.promptTokens)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Output"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.output)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Cached input"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:rr(c.cached)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-muted-foreground",children:"Cost"}),s.jsx("div",{className:"text-sm font-medium font-mono",children:c.cost>0?`$${c.cost.toFixed(4)}`:"-"})]})]})]}),ee&&s.jsxs("div",{className:"border-t border-border",children:[s.jsxs("button",{className:"flex items-center gap-1.5 w-full px-4 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>d(ke=>!ke),children:[s.jsx(Ls,{className:G("h-3 w-3 transition-transform",u&&"rotate-90")}),"Session",B&&s.jsx("span",{className:"text-yellow-400 ml-1",children:"(changed)"})]}),u&&s.jsxs("div",{className:"px-4 pb-3 space-y-1 text-xs",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12 shrink-0",children:"Run ID"}),s.jsx(O2,{text:l.id,ariaLabel:`Copy run ID ${l.id.slice(0,8)}`,title:"Copy run ID",containerClassName:"min-w-0 max-w-full",className:"block min-w-0 break-all text-left font-mono"})]}),l.sessionIdBefore&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12",children:B?"Before":"ID"}),s.jsx(O2,{text:l.sessionIdBefore,className:"font-mono"})]}),B&&l.sessionIdAfter&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground w-12",children:"After"}),s.jsx(O2,{text:l.sessionIdAfter,className:"font-mono"})]}),w.length>0&&s.jsxs("div",{className:"pt-1",children:[s.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground disabled:opacity-60",disabled:A.isPending,onClick:async()=>{const ke=w.length;await a({title:`Clear session for ${ke} issue${ke===1?"":"s"} touched by this run?`,confirmLabel:"Clear session",tone:"destructive"})&&A.mutate()},children:A.isPending?"clearing session...":"clear session for these issues"}),A.isError&&s.jsx("p",{className:"text-[11px] text-destructive mt-1",children:A.error instanceof Error?A.error.message:"Failed to clear sessions"})]})]})]})]}),k&&k.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Issues Touched (",k.length,")"]}),s.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:k.map(ke=>s.jsxs(yt,{to:`/issues/${ke.identifier??ke.issueId}`,className:"flex items-center justify-between w-full px-3 py-2 text-xs hover:bg-accent/20 transition-colors text-left no-underline text-inherit",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(er,{status:ke.status}),s.jsx("span",{className:"truncate",children:ke.title})]}),s.jsx("span",{className:"font-mono text-muted-foreground shrink-0 ml-2",children:ke.identifier??ke.issueId.slice(0,8)})]},ke.issueId))})]}),d6t(l)&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs font-medium text-red-600 dark:text-red-400",children:"stderr"}),s.jsx("pre",{"data-testid":"run-stderr-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:N})]}),l.stdoutExcerpt&&!l.logRef&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"stdout"}),s.jsx("pre",{"data-testid":"run-stdout-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:l.stdoutExcerpt})]}),s.jsx(_6t,{run:l,agentRuntimeType:n}),s.jsx(c7e,{})]})}function KR(){const{orgPrefix:e,agentId:t,tab:n,runId:r}=ci(),{organizations:i,selectedOrganizationId:a,setSelectedOrganizationId:o}=wn(),{closePanel:l}=oA(),{openNewIssue:c}=Wr(),{setBreadcrumbs:u}=zr(),d=vn(),f=Ir(),[h,g]=x.useState(null),[b,v]=x.useState(!1),[j,k]=x.useState(!1),w=r?"runs":Yvt(n??null),N=w==="dashboard",C=w==="runs"||!!r,A=N||C,[_,E]=x.useState("7d"),[T,M]=x.useState(!1),[O,P]=x.useState(""),[z,L]=x.useState(""),[Q,ee]=x.useState(!1),[B,F]=x.useState(!1),Z=x.useRef(null),W=x.useRef(null),{isMobile:$}=aa(),Y=t??"",H=x.useMemo(()=>{var rt;return e?((rt=Z5({organizations:i,organizationPrefix:e}))==null?void 0:rt.id)??null:null},[i,e])??a??void 0,ae=Y.length>0&&(Tz(Y)||!!H),le=x.useCallback(rt=>{Z.current=rt},[]),fe=x.useCallback(rt=>{W.current=rt},[]),{data:U,isLoading:xe,error:re}=Ne({queryKey:[...q.agents.detail(Y),H??null],queryFn:()=>Bt.get(Y,H),enabled:ae}),X=(U==null?void 0:U.orgId)??a,ie=U?r1(U):Y,pe=(U==null?void 0:U.id)??Y,ke=(U==null?void 0:U.id)??null,{data:Ce,isLoading:$e}=Ne({queryKey:q.agents.runtimeState(ke??Y),queryFn:()=>Bt.runtimeState(ke,X??void 0),enabled:!!ke&&N}),{from:Ue,to:he,customReady:We}=x.useMemo(()=>{const rt=new Date;if(_==="custom"){const xn=O?new Date(`${O}T00:00:00`):null,Se=z?new Date(`${z}T23:59:59.999`):null;return{from:xn?xn.toISOString():"",to:Se?Se.toISOString():"",customReady:!!O&&!!z}}const sn=_==="7d"?7:_==="15d"?15:30;return{from:new Date(rt.getFullYear(),rt.getMonth(),rt.getDate()-(sn-1),0,0,0,0).toISOString(),to:rt.toISOString(),customReady:!0}},[O,z,_]),ct=x.useMemo(()=>_==="7d"?DR(7):_==="15d"?DR(15):_==="30d"?DR(30):Lvt(O,z),[O,z,_]),Pe=x.useMemo(()=>$vt(_,O,z),[O,z,_]),{data:Ae,isLoading:oe}=Ne({queryKey:[...q.agents.skillsAnalytics(ke??Y),_,O,z],queryFn:()=>Bt.skillsAnalytics(ke,{orgId:X??void 0,..._==="custom"&&We?{startDate:O,endDate:z}:{windowDays:_==="7d"?7:_==="15d"?15:30}}),enabled:!!ke&&N&&(_!=="custom"||We)}),{data:D,isLoading:J}=Ne({queryKey:q.heartbeats(X,(U==null?void 0:U.id)??void 0),queryFn:()=>xs.list(X,(U==null?void 0:U.id)??void 0),enabled:!!X&&!!(U!=null&&U.id)&&A}),{data:de,isLoading:ue}=Ne({queryKey:[...q.issues.list(X),"participant-agent",ke??"__none__"],queryFn:()=>ln.list(X,{participantAgentId:ke}),enabled:!!X&&!!ke&&N}),{data:me}=Ne({queryKey:q.agents.list(X),queryFn:()=>Bt.list(X),enabled:!!X&&N}),{data:K}=Ne({queryKey:q.budgets.overview(X??"__none__"),queryFn:()=>R2.overview(X),enabled:!!X,refetchInterval:3e4,staleTime:5e3}),je=(de??[]).sort((rt,sn)=>new Date(sn.updatedAt).getTime()-new Date(rt.updatedAt).getTime()),Be=x.useMemo(()=>(D??[]).filter(rt=>Pse(rt.createdAt,Ue,he)),[Ue,D,he]),Ve=x.useMemo(()=>je.filter(rt=>Pse(rt.createdAt,Ue,he)),[je,Ue,he]),Me=x.useCallback(rt=>{if(rt==="custom"){if(!O||!z){const sn=new Date,tn=new Date(sn.getFullYear(),sn.getMonth(),sn.getDate()-6);P(SC(tn)),L(SC(sn))}E("custom"),M(!0);return}M(!1),E(rt)},[O,z]);(me??[]).find(rt=>rt.id===(U==null?void 0:U.reportsTo)),(me??[]).filter(rt=>rt.reportsTo===(U==null?void 0:U.id)&&rt.status!=="terminated");const ht=x.useMemo(()=>{const rt=K==null?void 0:K.policies.find(xn=>xn.scopeType==="agent"&&xn.scopeId===((U==null?void 0:U.id)??Y));if(rt)return rt;const sn=(U==null?void 0:U.budgetMonthlyCents)??0,tn=(U==null?void 0:U.spentMonthlyCents)??0;return{policyId:"",orgId:X??"",scopeType:"agent",scopeId:(U==null?void 0:U.id)??Y,scopeName:(U==null?void 0:U.name)??"Agent",metric:"billed_cents",windowKind:"calendar_month_utc",amount:sn,observedAmount:tn,remainingAmount:Math.max(0,sn-tn),utilizationPercent:sn>0?Number((tn/sn*100).toFixed(2)):0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:sn>0,status:sn>0&&tn>=sn?"hard_stop":"ok",paused:(U==null?void 0:U.status)==="paused",pauseReason:(U==null?void 0:U.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[U,K==null?void 0:K.policies,X,Y]),ve=x.useMemo(()=>(D??[]).find(rt=>rt.status==="running"||rt.status==="queued")??null,[D]);x.useEffect(()=>{if(!U)return;if(r){Y!==ie&&f(`/agents/${ie}/runs/${r}`,{replace:!0});return}const rt=w==="instructions"?"instructions":w==="configuration"?"configuration":w==="skills"?"skills":w==="runs"?"runs":w==="budget"?"budget":"dashboard";if(Y!==ie||n!==rt){f(`/agents/${ie}/${rt}`,{replace:!0});return}},[U,Y,ie,r,n,w,f]),x.useEffect(()=>{!(U!=null&&U.orgId)||U.orgId===a||o(U.orgId,{source:"route_sync"})},[U==null?void 0:U.orgId,a,o]);const Le=nt({mutationFn:async rt=>{if(!pe)return Promise.reject(new Error("No agent reference"));switch(rt){case"invoke":return Bt.invoke(pe,X??void 0);case"pause":return Bt.pause(pe,X??void 0);case"resume":return Bt.resume(pe,X??void 0);case"terminate":return Bt.terminate(pe,X??void 0)}},onSuccess:(rt,sn)=>{g(null),sn==="terminate"&&k(!1),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),d.invalidateQueries({queryKey:q.agents.runtimeState(pe)}),d.invalidateQueries({queryKey:q.agents.taskSessions(pe)}),X&&(d.invalidateQueries({queryKey:q.agents.list(X)}),U!=null&&U.id&&d.invalidateQueries({queryKey:q.heartbeats(X,U.id)})),sn==="invoke"&&rt&&typeof rt=="object"&&"id"in rt&&f(`/agents/${ie}/runs/${rt.id}`)},onError:rt=>{g(rt instanceof Error?rt.message:"Action failed")}}),Ie=nt({mutationFn:rt=>R2.upsertPolicy(X,{scopeType:"agent",scopeId:(U==null?void 0:U.id)??Y,amount:rt,windowKind:"calendar_month_utc"}),onSuccess:()=>{X&&(d.invalidateQueries({queryKey:q.budgets.overview(X)}),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),d.invalidateQueries({queryKey:q.agents.list(X)}),d.invalidateQueries({queryKey:q.dashboard(X)}))}}),at=nt({mutationFn:rt=>Bt.update(pe,{icon:rt},X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to update avatar")}}),Je=nt({mutationFn:rt=>Bt.uploadAvatar(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to upload avatar")}}),St=nt({mutationFn:rt=>Bt.resetSession(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.runtimeState(pe)}),d.invalidateQueries({queryKey:q.agents.taskSessions(pe)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to reset session")}}),Pt=nt({mutationFn:rt=>Bt.updatePermissions(pe,rt,X??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:q.agents.detail(Y)}),d.invalidateQueries({queryKey:q.agents.detail(pe)}),X&&d.invalidateQueries({queryKey:q.agents.list(X)})},onError:rt=>{g(rt instanceof Error?rt.message:"Failed to update permissions")}});if(x.useEffect(()=>{const rt=[{label:"Agents",href:"/agents"}],sn=(U==null?void 0:U.name)??Y??"Agent";w==="dashboard"&&!r?rt.push({label:sn}):(rt.push({label:sn,href:`/agents/${ie}/dashboard`}),r?(rt.push({label:"Runs",href:`/agents/${ie}/runs`}),rt.push({label:`Run ${r.slice(0,8)}`})):w==="instructions"?rt.push({label:"Instructions"}):w==="configuration"?rt.push({label:"Configuration"}):w==="runs"?rt.push({label:"Runs"}):w==="budget"?rt.push({label:"Budget"}):rt.push({label:"Dashboard"})),u(rt)},[u,U,Y,ie,w,r]),x.useEffect(()=>(l(),()=>l()),[l]),Ije(x.useCallback(rt=>{Q&&(rt.preventDefault(),rt.returnValue="")},[Q])),xe)return s.jsx(As,{variant:"detail"});if(re)return s.jsx("p",{className:"text-sm text-destructive",children:re.message});if(!U)return null;if(!r&&!n)return s.jsx(es,{to:`/agents/${ie}/dashboard`,replace:!0});const _t=U.status==="pending_approval",Lt=(w==="configuration"||w==="instructions")&&(Q||B),It=_0(U.icon),Vt=N&&(J||ue||$e||oe),Sn=C&&J;return s.jsxs(s.Fragment,{children:[s.jsx(Ws,{open:j,onOpenChange:k,children:s.jsxs(ii,{className:"sm:max-w-md",children:[s.jsxs(_a,{children:[s.jsx(Wi,{children:"Terminate agent"}),s.jsx(Va,{children:"Stop this agent permanently. This action cannot be undone."})]}),s.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[s.jsxs("p",{children:[s.jsx("span",{className:"font-medium text-foreground",children:U.name})," will be marked as terminated and can no longer run or resume."]}),s.jsx("p",{children:"Future heartbeats will stay disabled until you create or replace it."})]}),s.jsxs(nl,{children:[s.jsx(ce,{variant:"ghost",onClick:()=>k(!1),disabled:Le.isPending,children:"Cancel"}),s.jsx(ce,{variant:"destructive",onClick:()=>Le.mutate("terminate"),disabled:Le.isPending,children:Le.isPending?"Terminating...":"Terminate"})]})]})}),s.jsxs("div",{className:G("space-y-6",$&&Lt&&"pb-24"),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx(A1e,{value:U.icon,onChange:rt=>at.mutate(rt),onUpload:rt=>Je.mutate(rt),uploadPending:Je.isPending,uploadError:Je.error instanceof Error?Je.error.message:null,children:s.jsx("button",{className:G("shrink-0 flex h-12 w-12 items-center justify-center transition-colors",It?"overflow-hidden rounded-full hover:opacity-85":"rounded-lg bg-accent hover:bg-accent/80"),"aria-label":"Change agent avatar",children:s.jsx(ki,{icon:U.icon,role:U.role,className:It?"h-full w-full":"h-7 w-7"})})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"text-2xl font-bold truncate",children:U.name}),s.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:[pC[U.role]??U.role,U.title?` - ${U.title}`:""]})]})]}),s.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 shrink-0",children:[s.jsxs(ce,{variant:"outline",size:"sm",onClick:()=>c({assigneeAgentId:U.id}),children:[s.jsx(tr,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Assign Task"})]}),s.jsx(ce,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs(yt,{to:{pathname:"/messenger/chat",search:`?agentId=${encodeURIComponent(U.id)}`},children:[s.jsx(fo,{className:"h-3.5 w-3.5 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Chat"})]})}),s.jsx(T$,{onClick:()=>Le.mutate("invoke"),disabled:Le.isPending||_t,label:"Run Heartbeat"}),s.jsx(I$,{isPaused:U.status==="paused",onPause:()=>Le.mutate("pause"),onResume:()=>Le.mutate("resume"),disabled:Le.isPending||_t}),s.jsx("span",{className:"hidden sm:inline",children:s.jsx(er,{status:U.status})}),ve&&s.jsxs(yt,{to:`/agents/${ie}/runs/${ve.id}`,className:"sm:hidden flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),s.jsx("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:"Live"})]}),s.jsxs(qn,{open:b,onOpenChange:v,children:[s.jsx(Wn,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"icon-xs","aria-label":"Agent actions",children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsxs(Kn,{className:"w-44 p-1",align:"end",children:[s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{navigator.clipboard.writeText(U.id),v(!1)},children:[s.jsx(Ni,{className:"h-3 w-3"}),"Copy Agent ID"]}),s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{St.mutate(null),v(!1)},children:[s.jsx(Qv,{className:"h-3 w-3"}),"Reset Sessions"]}),s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-destructive",onClick:()=>{v(!1),k(!0)},children:[s.jsx(Sa,{className:"h-3 w-3"}),"Terminate"]})]})]})]})]}),!r&&s.jsx(Dc,{value:w,onValueChange:rt=>f(`/agents/${ie}/${rt}`),children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsx(c1,{items:[{value:"dashboard",label:"Dashboard"},{value:"instructions",label:"Instructions"},{value:"skills",label:"Skills"},{value:"configuration",label:"Configuration"},{value:"runs",label:"Runs"},{value:"budget",label:"Budget"}],value:w,onValueChange:rt=>f(`/agents/${ie}/${rt}`)}),w==="dashboard"?s.jsx("div",{className:"hidden lg:block shrink-0",children:s.jsx(jC,{preset:_,customFrom:O,customTo:z,customOpen:T,onCustomOpenChange:M,onPresetSelect:Me,onCustomFromChange:P,onCustomToChange:L})}):null]})}),h&&s.jsx("p",{className:"text-sm text-destructive",children:h}),_t&&s.jsx("p",{className:"text-sm text-amber-500",children:"This agent is pending board approval and cannot be invoked yet."}),!$&&Lt&&s.jsx("div",{className:"sticky top-6 z-10 float-right transition-opacity duration-150",children:s.jsxs("div",{className:"flex items-center gap-2 bg-background/90 backdrop-blur-sm border border-border rounded-lg px-3 py-1.5 shadow-lg",children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>{var rt;return(rt=W.current)==null?void 0:rt.call(W)},disabled:B,children:"Cancel"}),s.jsx(ce,{size:"sm",onClick:()=>{var rt;return(rt=Z.current)==null?void 0:rt.call(Z)},disabled:B,children:B?"Saving…":"Save"})]})}),$&&Lt&&s.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t border-border bg-background/95 backdrop-blur-sm",children:s.jsxs("div",{className:"flex items-center justify-end gap-2 px-3 py-2",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.5rem)"},children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>{var rt;return(rt=W.current)==null?void 0:rt.call(W)},disabled:B,children:"Cancel"}),s.jsx(ce,{size:"sm",onClick:()=>{var rt;return(rt=Z.current)==null?void 0:rt.call(Z)},disabled:B,children:B?"Saving…":"Save"})]})}),w==="dashboard"&&(Vt?s.jsx(Q6t,{}):s.jsx(g6t,{agent:U,runs:D??[],chartRuns:Be,assignedIssues:je,chartIssues:Ve,runtimeState:Ce,skillAnalytics:Ae,agentId:U.id,agentRouteId:ie,rangeLabel:Pe,chartDays:ct,showDashboardFilters:_!=="custom"||We,dateFilterControl:s.jsx("div",{className:"lg:hidden",children:s.jsx(jC,{preset:_,customFrom:O,customTo:z,customOpen:T,onCustomOpenChange:M,onPresetSelect:Me,onCustomFromChange:P,onCustomToChange:L})})})),w==="instructions"&&s.jsx(w6t,{agent:U,orgId:X??void 0,onDirtyChange:ee,onSaveActionChange:le,onCancelActionChange:fe,onSavingChange:F}),w==="configuration"&&s.jsx(b6t,{agent:U,agentId:U.id,orgId:X??void 0,onDirtyChange:ee,onSaveActionChange:le,onCancelActionChange:fe,onSavingChange:F,updatePermissions:Pt}),w==="skills"&&s.jsx(N6t,{agent:U,orgId:X??void 0}),w==="runs"&&(Sn?s.jsx(Y6t,{}):s.jsx(G6t,{runs:D??[],orgId:X,agentId:U.id,agentRouteId:ie,selectedRunId:r??null,agentRuntimeType:U.agentRuntimeType})),w==="budget"&&X?s.jsx("div",{className:"max-w-3xl",children:s.jsx(NA,{summary:ht,isSaving:Ie.isPending,onSave:rt=>Ie.mutate(rt),variant:"plain"})}):null]})]})}function Q6t(){return s.jsxs("div",{"aria-busy":"true","aria-label":"Loading agent dashboard",className:"space-y-8","data-testid":"agent-dashboard-skeleton",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx(Et,{className:"h-4 w-24"}),s.jsx(Et,{className:"h-4 w-20"})]}),s.jsx(Et,{className:"h-24 w-full rounded-lg border border-border"})]}),s.jsx("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:Array.from({length:4}).map((e,t)=>s.jsx(Et,{className:"h-44 w-full rounded-lg border border-border"},t))}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Et,{className:"h-4 w-28"}),s.jsx(Et,{className:"h-4 w-16"})]}),s.jsx("div",{className:"space-y-1 rounded-lg border border-border p-3",children:Array.from({length:4}).map((e,t)=>s.jsx(Et,{className:"h-9 w-full rounded-sm"},t))})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Et,{className:"h-4 w-16"}),s.jsx(Et,{className:"h-36 w-full rounded-lg border border-border"})]})]})}function Y6t(){return s.jsxs("div",{"aria-busy":"true","aria-label":"Loading agent runs",className:"flex min-w-0 items-start gap-4","data-testid":"agent-runs-skeleton",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-0 space-y-4 rounded-lg border border-border p-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx(Et,{className:"h-5 w-44"}),s.jsx(Et,{className:"h-7 w-20"})]}),s.jsx(Et,{className:"h-28 w-full rounded-lg"}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsx(Et,{className:"h-20 w-full rounded-lg"}),s.jsx(Et,{className:"h-20 w-full rounded-lg"})]}),s.jsx(Et,{className:"h-64 w-full rounded-lg"})]}),s.jsx("div",{className:"hidden w-[14rem] shrink-0 space-y-1 rounded-lg border border-border p-2 xl:block",children:Array.from({length:5}).map((e,t)=>s.jsx(Et,{className:"h-16 w-full rounded-md"},t))})]})}function J6t(){const{selectedOrganizationId:e}=wn(),{openNewProject:t}=Wr(),{setBreadcrumbs:n}=zr();x.useEffect(()=>{n([{label:"Projects"}])},[n]);const{data:r,isLoading:i,error:a}=Ne({queryKey:q.projects.list(e),queryFn:()=>ws.list(e),enabled:!!e}),o=x.useMemo(()=>(r??[]).filter(l=>!l.archivedAt),[r]);return e?i?s.jsx(As,{variant:"list"}):o.length>0?s.jsx(es,{to:Kv(o[0]),replace:!0}):s.jsxs("div",{className:"space-y-4",children:[a&&s.jsx("p",{className:"text-sm text-destructive",children:a.message}),!i&&o.length===0&&s.jsx(Fr,{icon:Ep,message:"No projects yet.",action:"Add Project",onAction:t}),o.length>0&&s.jsx("div",{className:"border border-border",children:o.map(l=>s.jsx(pu,{title:l.name,subtitle:l.description??void 0,to:Kv(l),trailing:s.jsxs("div",{className:"flex items-center gap-3",children:[l.targetDate&&s.jsx("span",{className:"text-xs text-muted-foreground",children:Ha(l.targetDate)}),s.jsx(er,{status:l.status})]})},l.id))})]}):s.jsx(Fr,{icon:Ep,message:"Select a organization to view projects."})}function Lc({className:e,orientation:t="horizontal",decorative:n=!0,...r}){return s.jsx(jde,{"data-slot":"separator",decorative:n,orientation:t,className:G("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",e),...r})}const X6t=250,e7t=1600;function bH(){const[e,t]=x.useState("idle"),n=x.useRef(0),r=x.useRef(null),i=x.useRef(null),a=x.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null),i.current&&(clearTimeout(i.current),i.current=null)},[]);x.useEffect(()=>a,[a]);const o=x.useCallback(()=>{n.current+=1,a(),t("idle")},[a]),l=x.useCallback(()=>{a(),t("idle")},[a]),c=x.useCallback(async u=>{const d=n.current+1;n.current=d,a(),r.current=setTimeout(()=>{n.current===d&&t("saving")},X6t);try{if(await u(),n.current!==d)return;a(),t("saved"),i.current=setTimeout(()=>{n.current===d&&t("idle")},e7t)}catch(f){throw n.current!==d||(a(),t("error")),f}},[a]);return{state:e,markDirty:l,reset:o,runSave:c}}const Jse="px-1 -mx-1",t7t="px-1",n7t=900;function r7t(e){return e instanceof HTMLElement?e:e instanceof Node?e.parentElement:null}function zf({value:e,onSave:t,as:n="span",className:r,placeholder:i="Click to edit...",multiline:a=!1,imageUploadHandler:o,mentions:l}){const[c,u]=x.useState(!1),[d,f]=x.useState(!1),[h,g]=x.useState(e),b=x.useRef(null),v=x.useRef(null),j=x.useRef(null),{state:k,markDirty:w,reset:N,runSave:C}=bH();x.useEffect(()=>{a&&d||g(e)},[e,a,d]),x.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const A=x.useCallback(M=>{M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},[]);x.useEffect(()=>{c&&b.current&&(b.current.focus(),b.current.select(),b.current instanceof HTMLTextAreaElement&&A(b.current))},[c,A]),x.useEffect(()=>{if(!c||!a)return;const M=requestAnimationFrame(()=>{var O;(O=v.current)==null||O.focus()});return()=>cancelAnimationFrame(M)},[c,a]);const _=x.useCallback(async(M=h)=>{const O=M.trim();O&&O!==e?await Promise.resolve(t(O)):g(e),a||u(!1)},[h,a,t,e]);function E(M){M.key==="Enter"&&!a&&(M.preventDefault(),_()),M.key==="Escape"&&(j.current&&clearTimeout(j.current),N(),g(e),a?(f(!1),u(!1),document.activeElement instanceof HTMLElement&&document.activeElement.blur()):u(!1))}if(x.useEffect(()=>{if(!a||!d)return;const M=h.trim();if(!M||M===e){k!=="saved"&&N();return}return w(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{C(()=>_(M))},n7t),()=>{j.current&&clearTimeout(j.current)}},[k,_,h,w,a,d,N,C,e]),a&&c)return s.jsxs("div",{className:G(t7t,"rounded"),onFocusCapture:()=>f(!0),onBlurCapture:M=>{if(M.currentTarget.contains(M.relatedTarget))return;j.current&&clearTimeout(j.current),f(!1),u(!1);const O=h.trim();if(!O||O===e){N(),_();return}C(()=>_())},onKeyDown:E,children:[s.jsx(ol,{ref:v,value:h,onChange:g,placeholder:i,bordered:!1,className:"bg-transparent",contentClassName:G("rudder-edit-in-place-content",r),imageUploadHandler:o,mentions:l,onSubmit:()=>{const M=h.trim();if(!M||M===e){N(),_();return}C(()=>_())}}),s.jsx("div",{className:"flex min-h-4 items-center justify-end pr-1",children:s.jsx("span",{className:G("text-[11px] transition-opacity duration-150",k==="error"?"text-destructive":"text-muted-foreground",k==="idle"?"opacity-0":"opacity-100"),children:k==="saving"?"Autosaving...":k==="saved"?"Saved":k==="error"?"Could not save":"Idle"})})]});if(c)return s.jsx("textarea",{ref:b,value:h,rows:1,onChange:M=>{g(M.target.value),A(M.target)},onBlur:()=>{_()},onKeyDown:E,className:G("w-full bg-transparent rounded outline-none resize-none overflow-hidden",Jse,r)});const T=e&&a?"div":n;return s.jsx(T,{className:G("rounded overflow-hidden",a?"cursor-text":"cursor-pointer transition-colors hover:bg-accent/50",Jse,!e&&"text-muted-foreground italic",r),onClick:M=>{var O;(O=r7t(M.target))!=null&&O.closest("a")||u(!0)},children:e&&a?s.jsx(Aa,{onLinkClick:({event:M})=>{M.stopPropagation()},children:e}):e||i})}const s7t=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function i7t({state:e}){return e==="saving"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[s.jsx(yr,{className:"h-3 w-3 animate-spin"}),"Saving"]}):e==="saved"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-green-600 dark:text-green-400",children:[s.jsx(gs,{className:"h-3 w-3"}),"Saved"]}):e==="error"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-destructive",children:[s.jsx(g1,{className:"h-3 w-3"}),"Failed"]}):null}function Fg({label:e,state:t}){return s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:e}),s.jsx(i7t,{state:t})]})}function jh({label:e,children:t,alignStart:n=!1,valueClassName:r=""}){return s.jsxs("div",{className:G("flex gap-3 py-1.5",n?"items-start":"items-center"),children:[s.jsx("div",{className:"shrink-0 w-20",children:e}),s.jsx("div",{className:G("min-w-0 flex-1",n?"pt-0.5":"flex items-center gap-1.5",r),children:t})]})}function a7t({status:e,onChange:t}){const[n,r]=x.useState(!1),i=V1e[e]??W1e;return s.jsxs(qn,{open:n,onOpenChange:r,children:[s.jsx(Wn,{asChild:!0,children:s.jsx("button",{className:G("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0 cursor-pointer hover:opacity-80 transition-opacity",i),children:e.replace("_"," ")})}),s.jsx(Kn,{className:"w-40 p-1",align:"start",children:s7t.map(a=>s.jsx(ce,{variant:"ghost",size:"sm",className:G("w-full justify-start gap-2 text-xs",a.value===e&&"bg-accent"),onClick:()=>{t(a.value),r(!1)},children:a.label},a.value))})]})}function o7t({project:e,onArchive:t,archivePending:n}){const[r,i]=x.useState(!1),a=!e.archivedAt,o=a?"Archive":"Unarchive";return s.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:a?"Archive this project to hide it from the sidebar and project selectors.":"Unarchive this project to restore it in the sidebar and project selectors."}),n?s.jsxs(ce,{size:"sm",variant:"destructive",disabled:!0,children:[s.jsx(yr,{className:"h-3 w-3 animate-spin mr-1"}),a?"Archiving...":"Unarchiving..."]}):r?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"text-sm text-destructive font-medium",children:[o," “",e.name,"”?"]}),s.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>{i(!1),t(a)},children:"Confirm"}),s.jsx(ce,{size:"sm",variant:"outline",onClick:()=>i(!1),children:"Cancel"})]}):s.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>i(!0),children:a?s.jsxs(s.Fragment,{children:[s.jsx(o5,{className:"h-3 w-3 mr-1"}),o," project"]}):s.jsxs(s.Fragment,{children:[s.jsx(xme,{className:"h-3 w-3 mr-1"}),o," project"]})})]})}function b7e({project:e,onUpdate:t,onFieldUpdate:n,getFieldSaveState:r,onArchive:i,archivePending:a}){var k;const{selectedOrganizationId:o}=wn(),[l,c]=x.useState(!1),u=(w,N)=>{if(n){n(w,N);return}t==null||t(N)},d=w=>(r==null?void 0:r(w))??"idle",{data:f}=Ne({queryKey:q.goals.list(o),queryFn:()=>Al.list(o),enabled:!!o}),h=e.goalIds.length>0?e.goalIds:e.goalId?[e.goalId]:[],g=e.goals.length>0?e.goals:h.map(w=>{var N;return{id:w,title:((N=f==null?void 0:f.find(C=>C.id===w))==null?void 0:N.title)??w.slice(0,8)}}),b=(f??[]).filter(w=>!h.includes(w.id)),v=w=>{!t&&!n||u("goals",{goalIds:h.filter(N=>N!==w)})},j=w=>{!t&&!n||h.includes(w)||(u("goals",{goalIds:[...h,w]}),c(!1))};return s.jsxs("div",{children:[s.jsxs("div",{className:"space-y-1 pb-4",children:[s.jsx(jh,{label:s.jsx(Fg,{label:"Name",state:d("name")}),children:t||n?s.jsx(Hi,{value:e.name,onCommit:w=>u("name",{name:w}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-sm outline-none",placeholder:"Project name"}):s.jsx("span",{className:"text-sm",children:e.name})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Description",state:d("description")}),alignStart:!0,valueClassName:"space-y-0.5",children:t||n?s.jsx(zf,{value:e.description??"",onSave:w=>u("description",{description:w}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0}):s.jsx("p",{className:"text-sm text-muted-foreground",children:((k=e.description)==null?void 0:k.trim())||"No description"})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Status",state:d("status")}),children:t||n?s.jsx(a7t,{status:e.status,onChange:w=>u("status",{status:w})}):s.jsx(er,{status:e.status})}),e.leadAgentId&&s.jsx(jh,{label:"Lead",children:s.jsx("span",{className:"text-sm font-mono",children:e.leadAgentId.slice(0,8)})}),s.jsxs(jh,{label:s.jsx(Fg,{label:"Goals",state:d("goals")}),alignStart:!0,valueClassName:"space-y-2",children:[g.length>0&&s.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.map(w=>s.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[s.jsx(yt,{to:`/goals/${w.id}`,className:"hover:underline max-w-[220px] truncate",children:w.title}),(t||n)&&s.jsx("button",{className:"text-muted-foreground hover:text-foreground",type:"button",onClick:()=>v(w.id),"aria-label":`Remove goal ${w.title}`,children:s.jsx(Gs,{className:"h-3 w-3"})})]},w.id))}),(t||n)&&s.jsxs(qn,{open:l,onOpenChange:c,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"xs",className:G("h-6 w-fit px-2",g.length>0&&"ml-1"),disabled:b.length===0,children:[s.jsx(tr,{className:"h-3 w-3 mr-1"}),"Goal"]})}),s.jsx(Kn,{className:"w-56 p-1",align:"start",children:b.length===0?s.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals linked."}):b.map(w=>s.jsx("button",{className:"flex items-center w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>j(w.id),children:w.title},w.id))})]})]}),s.jsx(jh,{label:s.jsx(Fg,{label:"Created",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.createdAt)})}),s.jsx(jh,{label:s.jsx(Fg,{label:"Updated",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.updatedAt)})}),e.targetDate&&s.jsx(jh,{label:s.jsx(Fg,{label:"Target Date",state:"idle"}),children:s.jsx("span",{className:"text-sm",children:Ha(e.targetDate)})})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx(Lc,{className:"my-4"}),s.jsxs("div",{className:"space-y-4 py-4",children:[s.jsx("div",{className:"text-xs font-medium text-destructive uppercase tracking-wide",children:"Danger Zone"}),s.jsx(o7t,{project:e,onArchive:i,archivePending:a})]})]})]})}function Xse(){return{name:"",kind:"directory",locator:"",description:"",role:"working_set",note:""}}function eie(e){switch(e){case"directory":return dc;case"file":return Nd;case"connector_object":return zc;case"url":default:return G2}}function tie(e,t){return e.filter(n=>n.role===t).length}function l7t({project:e}){const{organizations:t}=wn(),{pushToast:n}=_r(),r=vn(),[i,a]=x.useState(!1),[o,l]=x.useState(!1),[c,u]=x.useState(Xse()),d=t.find(C=>C.id===e.orgId)??null,f=xf("/resources",(d==null?void 0:d.issuePrefix)??null),h=x.useMemo(()=>[...e.resources].sort((C,A)=>C.sortOrder-A.sortOrder),[e.resources]),{data:g}=Ne({queryKey:q.organizations.resources(e.orgId),queryFn:()=>Xn.listResources(e.orgId),enabled:!!e.orgId}),b=x.useMemo(()=>(g??[]).filter(C=>!e.resources.some(A=>A.resourceId===C.id)),[g,e.resources]),v=()=>{r.invalidateQueries({queryKey:["projects","detail"]}),r.invalidateQueries({queryKey:q.projects.list(e.orgId)}),r.invalidateQueries({queryKey:q.projects.resources(e.id)}),r.invalidateQueries({queryKey:q.organizations.resources(e.orgId)})},j=nt({mutationFn:C=>ws.attachResource(e.id,C,e.orgId),onSuccess:()=>{v(),n({title:"Project resource attached",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to attach project resource",tone:"error"})}}),k=nt({mutationFn:C=>ws.updateResourceAttachment(e.id,C.attachmentId,{role:C.role,note:C.note,sortOrder:C.sortOrder},e.orgId),onSuccess:()=>{v()},onError:C=>{n({title:C instanceof Error?C.message:"Failed to update project resource",tone:"error"})}}),w=nt({mutationFn:C=>ws.removeResourceAttachment(e.id,C,e.orgId),onSuccess:()=>{v(),n({title:"Project resource removed",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to remove project resource",tone:"error"})}}),N=nt({mutationFn:async()=>{const C=await Xn.createResource(e.orgId,{name:c.name.trim(),kind:c.kind,locator:c.locator.trim(),description:c.description.trim()||void 0});return ws.attachResource(e.id,{resourceId:C.id,role:c.role,note:c.note.trim()||void 0,sortOrder:e.resources.length},e.orgId)},onSuccess:()=>{v(),u(Xse()),l(!1),n({title:"Org resource created and attached",tone:"success"})},onError:C=>{n({title:C instanceof Error?C.message:"Failed to create and attach resource",tone:"error"})}});return s.jsxs("div",{className:"space-y-5",children:[s.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[s.jsxs("div",{className:"flex flex-col gap-4 border-b border-border px-5 py-4 md:flex-row md:items-start md:justify-between",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:"Project Context"}),s.jsx("div",{className:"text-base font-semibold text-foreground",children:"Resources"}),s.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Choose the repos, docs, URLs, and connector objects agents should actually use on this project. The org catalog stays canonical; this tab decides what matters here."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(qn,{open:i,onOpenChange:a,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"sm",disabled:b.length===0||j.isPending,children:[s.jsx(G2,{className:"mr-1.5 h-3.5 w-3.5"}),"Attach existing"]})}),s.jsxs(Kn,{align:"end",className:"w-[22rem] p-2",children:[s.jsxs("div",{className:"px-2 pb-2 pt-1",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attach from org catalog"}),s.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick an existing shared resource, then add project-specific role and note below."})]}),b.length===0?s.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"All org resources are already attached to this project."}):s.jsx("div",{className:"space-y-1",children:b.map(C=>{const A=eie(C.kind);return s.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[calc(var(--radius-sm)-1px)] border border-transparent px-2 py-2 text-left transition-colors hover:border-border hover:bg-accent/35",onClick:()=>{j.mutate({resourceId:C.id,role:"reference",sortOrder:e.resources.length}),a(!1)},children:[s.jsx("div",{className:"mt-0.5 rounded-md border border-border/70 bg-background/80 p-1.5 text-muted-foreground",children:s.jsx(A,{className:"h-3.5 w-3.5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:C.name}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:U6(C.kind)})]}),s.jsx("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:C.locator}),C.description?s.jsx("div",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:C.description}):null]})]},C.id)})})]})]}),s.jsxs(ce,{size:"sm",onClick:()=>l(!0),children:[s.jsx(hLe,{className:"mr-1.5 h-3.5 w-3.5"}),"Add resource"]}),s.jsx(ce,{asChild:!0,variant:"outline",size:"sm",children:s.jsxs(yt,{to:f,children:[s.jsx(Yz,{className:"mr-1.5 h-3.5 w-3.5"}),"Org catalog"]})})]})]}),s.jsxs("div",{className:"grid gap-3 px-5 py-4 md:grid-cols-3",children:[s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Attached"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:h.length}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Resources visible to agents on this project."})]}),s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Working Set"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:tie(h,"working_set")}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"The resources agents should actively work inside."})]}),s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Reference"}),s.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:tie(h,"reference")}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Background material that frames decisions and output."})]})]})]}),s.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[s.jsx("div",{className:"flex items-center justify-between gap-3 border-b border-border px-5 py-4",children:s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attached resources"}),s.jsx("div",{className:"text-xs text-muted-foreground",children:"Roles and notes here are project-local. They do not change the shared org catalog."})]})}),s.jsx("div",{className:"space-y-3 px-5 py-4",children:h.length===0?s.jsx("div",{className:"rounded-[var(--radius-md)] border border-dashed border-border/80 bg-background/35 px-4 py-5 text-sm text-muted-foreground",children:"No resources attached yet. Start with the repo, spec, tracking system, or any reference agents should not miss when working on this project."}):h.map(C=>{const A=eie(C.resource.kind);return s.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/75 bg-[color:color-mix(in_oklab,var(--surface-elevated)_92%,transparent)] px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"rounded-md border border-border/70 bg-background/85 p-1.5 text-muted-foreground",children:s.jsx(A,{className:"h-3.5 w-3.5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:C.resource.name}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:U6(C.resource.kind)}),s.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-emerald-300/50 bg-emerald-500/8 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-emerald-700 dark:text-emerald-300",children:cht(C.role)})]}),s.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-muted-foreground",children:C.resource.locator})]})]}),C.resource.description?s.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:C.resource.description}):null]}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>w.mutate(C.id),disabled:w.isPending,children:s.jsx(Sa,{className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-[180px_minmax(0,1fr)]",children:[s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project role"}),s.jsx("select",{value:C.role,onChange:_=>k.mutate({attachmentId:C.id,role:_.target.value,note:C.note,sortOrder:C.sortOrder}),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:sC.map(_=>s.jsx("option",{value:_.value,children:_.label},_.value))})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project note"}),s.jsx(Hi,{value:C.note??"",onCommit:_=>k.mutate({attachmentId:C.id,role:C.role,note:_,sortOrder:C.sortOrder}),immediate:!0,className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",placeholder:"Optional project-specific guidance for agents"})]})]})]},C.id)})})]}),s.jsx(Ws,{open:o,onOpenChange:l,children:s.jsxs(ii,{className:"sm:max-w-2xl",children:[s.jsxs(_a,{children:[s.jsx(Wi,{children:"Add resource"}),s.jsx(Va,{children:"Create a new org resource and attach it to this project in one step. Keep the description concrete so agents know when this resource matters."})]}),s.jsxs("div",{className:"grid gap-4 py-1 md:grid-cols-2",children:[s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Name"}),s.jsx(In,{value:c.name,onChange:C=>u(A=>({...A,name:C.target.value})),placeholder:"Rudder app repo"})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Kind"}),s.jsxs("select",{value:c.kind,onChange:C=>u(A=>({...A,kind:C.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:[s.jsx("option",{value:"directory",children:"Directory"}),s.jsx("option",{value:"file",children:"File"}),s.jsx("option",{value:"url",children:"URL"}),s.jsx("option",{value:"connector_object",children:"Connector object"})]})]}),s.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Locator"}),s.jsx(aA,{kind:c.kind,value:c.locator,onChange:C=>u(A=>({...A,locator:C})),onPickedPath:C=>u(A=>({...A,locator:C,name:A.name.trim()?A.name:_K(C)})),disabled:N.isPending})]}),s.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Description"}),s.jsx(Na,{value:c.description,onChange:C=>u(A=>({...A,description:C.target.value})),placeholder:"What this resource contains and when agents should use it."})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Project role"}),s.jsx("select",{value:c.role,onChange:C=>u(A=>({...A,role:C.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:sC.map(C=>s.jsx("option",{value:C.value,children:C.label},C.value))})]}),s.jsxs("label",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Project note"}),s.jsx(In,{value:c.note,onChange:C=>u(A=>({...A,note:C.target.value})),placeholder:"Optional guidance for this project"})]})]}),s.jsxs(nl,{children:[s.jsx(ce,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),s.jsxs(ce,{onClick:()=>N.mutate(),disabled:N.isPending||!c.name.trim()||!c.locator.trim(),children:[N.isPending?s.jsx(yr,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Create and attach"]})]})]})})]})}function rk(e){return typeof e=="string"&&e.startsWith("plugin:")}function c7t(e,t){const n=e.split("/").filter(Boolean),r=n.indexOf("projects");if(r===-1||n[r+1]!==t)return null;const i=n[r+2];return i==="overview"?"configuration":i==="resources"?"resources":i==="configuration"?"configuration":i==="budget"?"budget":i==="issues"?"issues":null}function u7t({currentColor:e,onSelect:t}){const[n,r]=x.useState(!1),i=x.useRef(null);return x.useEffect(()=>{if(!n)return;function a(o){i.current&&!i.current.contains(o.target)&&r(!1)}return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[n]),s.jsxs("div",{className:"relative",ref:i,children:[s.jsx("button",{onClick:()=>r(!n),className:"shrink-0 h-5 w-5 rounded-md cursor-pointer shadow-[inset_0_0_0_1px_color-mix(in_oklab,white_24%,transparent),0_0_0_1px_color-mix(in_oklab,var(--border-base)_76%,transparent)] transition-[box-shadow] hover:ring-2 hover:ring-foreground/20",style:ic(e),"aria-label":"Change project color"}),n&&s.jsx("div",{className:"absolute top-full left-0 mt-2 p-2 bg-popover border border-border rounded-lg shadow-lg z-50 w-max",children:s.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Uv.map(a=>s.jsx("button",{onClick:()=>{t(a),r(!1)},className:`h-6 w-6 rounded-md cursor-pointer transition-[transform,box-shadow] duration-150 hover:scale-110 ${a===e?"ring-2 ring-foreground ring-offset-1 ring-offset-background":"hover:ring-2 hover:ring-foreground/30"}`,style:ic(a),"aria-label":`Select color ${a}`},a))})})]})}function zg(){const{orgPrefix:e,projectId:t}=ci(),{organizations:n,selectedOrganizationId:r,setSelectedOrganizationId:i}=wn(),{closePanel:a}=oA(),{setBreadcrumbs:o}=zr(),{pushToast:l}=_r(),c=vn(),u=Ir(),d=Mn(),[f,h]=x.useState({}),g=x.useRef({}),b=x.useRef({}),v=t??"",k=x.useMemo(()=>{var re;return e?((re=Z5({organizations:n,organizationPrefix:e}))==null?void 0:re.id)??null:null},[n,e])??r??void 0,w=v.length>0&&(Tz(v)||!!k),N=v?c7t(d.pathname,v):null,C=x.useMemo(()=>{const re=new URLSearchParams(d.search).get("tab");return rk(re)?re:null},[d.search]),A=N??C,{data:_,isLoading:E,error:T}=Ne({queryKey:[...q.projects.detail(v),k??null],queryFn:()=>ws.get(v,k),enabled:w}),M=_?Sp(_):v,O=(_==null?void 0:_.id)??v,P=(_==null?void 0:_.orgId)??r,z=x.useMemo(()=>{var re;return((re=n.find(X=>X.id===P))==null?void 0:re.issuePrefix)??e??null},[n,e,P]),L=x.useMemo(()=>_?xf(`/issues?projectId=${encodeURIComponent(_.id)}`,z):null,[_,z]),{slots:Q,isLoading:ee}=d4({slotTypes:["detailTab"],entityType:"project",enabled:!!P}),B=x.useMemo(()=>Q.map(re=>({value:`plugin:${re.pluginKey}:${re.id}`,label:re.displayName,slot:re})),[Q]),F=B.find(re=>re.value===A)??null;x.useEffect(()=>{!(_!=null&&_.orgId)||_.orgId===r||i(_.orgId,{source:"route_sync"})},[_==null?void 0:_.orgId,r,i]);const Z=()=>{c.invalidateQueries({queryKey:q.projects.detail(v)}),c.invalidateQueries({queryKey:q.projects.detail(O)}),P&&c.invalidateQueries({queryKey:q.projects.list(P)})},W=nt({mutationFn:re=>ws.update(O,re,P??k),onSuccess:Z}),$=nt({mutationFn:re=>ws.update(O,{archivedAt:re?new Date().toISOString():null},P??k),onSuccess:(re,X)=>{Z();const ie=(re==null?void 0:re.name)??(_==null?void 0:_.name)??"Project";X?(l({title:`"${ie}" has been archived`,tone:"success"}),u("/dashboard")):l({title:`"${ie}" has been unarchived`,tone:"success"})},onError:(re,X)=>{l({title:X?"Failed to archive project":"Failed to unarchive project",tone:"error"})}}),Y=nt({mutationFn:async()=>{if(!P||!_)throw new Error("Project is not ready");return Xr.create(P,{title:`Discuss ${_.name}`,contextLinks:[{entityType:"project",entityId:_.id}]})},onSuccess:re=>{c.invalidateQueries({queryKey:q.chats.list(P??"__none__")}),u(`/chat/${re.id}`)},onError:re=>{l({title:re instanceof Error?re.message:"Failed to open chat",tone:"error"})}}),{data:V}=Ne({queryKey:q.budgets.overview(P??"__none__"),queryFn:()=>R2.overview(P),enabled:!!P,refetchInterval:3e4,staleTime:5e3});x.useEffect(()=>{o([{label:"Projects",href:"/projects"},{label:(_==null?void 0:_.name)??v??"Project"}])},[o,_,v]),x.useEffect(()=>{if(_&&v!==M){if(rk(A)){u(`/projects/${M}?tab=${encodeURIComponent(A)}`,{replace:!0});return}if(A==="configuration"){u(`/projects/${M}/configuration`,{replace:!0});return}if(A==="resources"){u(`/projects/${M}/resources`,{replace:!0});return}if(A==="budget"){u(`/projects/${M}/budget`,{replace:!0});return}if(A==="issues"&&L){u(L,{replace:!0});return}u(`/projects/${M}`,{replace:!0})}},[_,v,M,A,u,L]),x.useEffect(()=>(a(),()=>a()),[a]),x.useEffect(()=>()=>{Object.values(b.current).forEach(re=>{re&&clearTimeout(re)})},[]);const H=x.useCallback((re,X)=>{h(ie=>({...ie,[re]:X}))},[]),ae=x.useCallback((re,X)=>{const ie=b.current[re];ie&&clearTimeout(ie),b.current[re]=setTimeout(()=>{h(pe=>{const ke={...pe};return delete ke[re],ke}),delete b.current[re]},X)},[]),le=x.useCallback(async(re,X)=>{const ie=(g.current[re]??0)+1;g.current[re]=ie,H(re,"saving");try{if(await ws.update(O,X,P??k),Z(),g.current[re]!==ie)return;H(re,"saved"),ae(re,1800)}catch(pe){if(g.current[re]!==ie)return;throw H(re,"error"),ae(re,3e3),pe}},[Z,k,O,P,ae,H]),fe=x.useMemo(()=>{const re=V==null?void 0:V.policies.find(X=>X.scopeType==="project"&&X.scopeId===((_==null?void 0:_.id)??v));return re||{policyId:"",orgId:P??"",scopeType:"project",scopeId:(_==null?void 0:_.id)??v,scopeName:(_==null?void 0:_.name)??"Project",metric:"billed_cents",windowKind:"lifetime",amount:0,observedAmount:0,remainingAmount:0,utilizationPercent:0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:!1,status:"ok",paused:!!(_!=null&&_.pausedAt),pauseReason:(_==null?void 0:_.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[V==null?void 0:V.policies,_,P,v]),U=nt({mutationFn:re=>R2.upsertPolicy(P,{scopeType:"project",scopeId:(_==null?void 0:_.id)??v,amount:re,windowKind:"lifetime"}),onSuccess:()=>{P&&(c.invalidateQueries({queryKey:q.budgets.overview(P)}),c.invalidateQueries({queryKey:q.projects.detail(v)}),c.invalidateQueries({queryKey:q.projects.detail(O)}),c.invalidateQueries({queryKey:q.projects.list(P)}),c.invalidateQueries({queryKey:q.dashboard(P)}))}});if(C&&!ee&&!F)return s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0});if(v&&A===null){let re=null;if(_!=null&&_.id)try{re=localStorage.getItem(`rudder:project-tab:${_.id}`)}catch{}return re==="configuration"?s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0}):re==="resources"?s.jsx(es,{to:`/projects/${M}/resources`,replace:!0}):re==="budget"?s.jsx(es,{to:`/projects/${M}/budget`,replace:!0}):(re==="issues"||re==="list")&&L?s.jsx(es,{to:L,replace:!0}):rk(re)?s.jsx(es,{to:`/projects/${M}?tab=${encodeURIComponent(re)}`,replace:!0}):s.jsx(es,{to:`/projects/${M}/configuration`,replace:!0})}if(E)return s.jsx(As,{variant:"detail"});if(T)return s.jsx("p",{className:"text-sm text-destructive",children:T.message});if(!_)return null;const xe=re=>{if(re==="issues"){L&&u(L);return}if(_!=null&&_.id)try{localStorage.setItem(`rudder:project-tab:${_.id}`,re)}catch{}if(rk(re)){u(`/projects/${M}?tab=${encodeURIComponent(re)}`);return}u(re==="resources"?`/projects/${M}/resources`:re==="budget"?`/projects/${M}/budget`:re==="configuration"?`/projects/${M}/configuration`:`/projects/${M}/configuration`)};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"h-7 flex items-center",children:s.jsx(u7t,{currentColor:_.color??"#6366f1",onSelect:re=>W.mutate({color:re})})}),s.jsxs("div",{className:"min-w-0 space-y-2",children:[s.jsx(zf,{value:_.name,onSave:re=>W.mutate({name:re}),as:"h2",className:"text-xl font-bold"}),_.pauseReason==="budget"?s.jsxs("div",{className:G("inline-flex items-center gap-2 rounded-full border px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em]",bA.error),children:[s.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400"}),"Paused by budget hard stop"]}):null]})]}),s.jsxs(ce,{size:"sm",variant:"outline",className:"shrink-0",onClick:()=>Y.mutate(),disabled:Y.isPending,children:[s.jsx(fo,{className:"mr-1.5 h-3.5 w-3.5"}),"Chat"]})]}),s.jsx(y1,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"project",context:{orgId:P??null,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),s.jsx(_B,{placementZones:["toolbarButton"],entityType:"project",context:{orgId:P??null,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),s.jsx(Dc,{value:A??"configuration",onValueChange:re=>xe(re),children:s.jsx(c1,{items:[{value:"configuration",label:"Configuration"},{value:"resources",label:"Resources"},{value:"budget",label:"Budget"},{value:"issues",label:"Issues"},...B.map(re=>({value:re.value,label:re.label}))],align:"start",value:A??"configuration",onValueChange:re=>xe(re)})}),A==="configuration"&&s.jsx("div",{className:"max-w-4xl",children:s.jsx(b7e,{project:_,onUpdate:re=>W.mutate(re),onFieldUpdate:le,getFieldSaveState:re=>f[re]??"idle",onArchive:re=>$.mutate(re),archivePending:$.isPending})}),A==="resources"&&s.jsx("div",{className:"max-w-5xl",children:s.jsx(l7t,{project:_})}),A==="budget"&&P?s.jsx("div",{className:"max-w-3xl",children:s.jsx(NA,{summary:fe,variant:"plain",isSaving:U.isPending,onSave:re=>U.mutate(re)})}):null,F&&s.jsx(f4,{slot:F.slot,context:{orgId:P,orgPrefix:e??null,projectId:_.id,projectRef:M,entityId:_.id,entityType:"project"},missingBehavior:"placeholder"})]})}function jy(e,t){const n={};for(const r of e){const i=t(r);n[i]||(n[i]=[]),n[i].push(r)}return n}function M$({issue:e,issueLinkState:t,mobileLeading:n,desktopMetaLeading:r,desktopLeadingSpacer:i=!1,mobileMeta:a,desktopTrailing:o,trailingMeta:l,unreadState:c=null,onMarkRead:u,onOpen:d,className:f}){const h=e.identifier??e.id,g=e.identifier??e.id.slice(0,8),b=c!==null,v=c==="visible"||c==="fading";return s.jsxs(yt,{to:`/issues/${h}`,state:t,onClick:d,className:G("flex items-start gap-2 border-b panel-divider py-3 pl-3 pr-3 text-sm no-underline text-inherit transition-[background-color,border-color] hover:bg-[color:color-mix(in_oklab,var(--surface-active)_56%,transparent)] last:border-b-0 sm:items-center sm:py-2.5 sm:pl-2",f),children:[s.jsx("span",{className:"shrink-0 pt-px sm:hidden",children:n??s.jsx(os,{status:e.status})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[s.jsx("span",{className:"line-clamp-2 text-sm font-medium text-foreground sm:order-2 sm:min-w-0 sm:flex-1 sm:truncate sm:line-clamp-none",children:e.title}),s.jsxs("span",{className:"flex items-center gap-2 sm:order-1 sm:shrink-0",children:[i?s.jsx("span",{className:"hidden w-3.5 shrink-0 sm:block"}):null,r??s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"hidden shrink-0 sm:inline-flex",children:s.jsx(os,{status:e.status})}),s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:g})]}),a?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-xs text-muted-foreground sm:hidden","aria-hidden":"true",children:"·"}),s.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:a})]}):null]})]}),o||l?s.jsxs("span",{className:"ml-auto hidden shrink-0 items-center gap-2 sm:order-3 sm:flex sm:gap-3",children:[o,l?s.jsx("span",{className:"text-xs text-muted-foreground",children:l}):null]}):null,b?s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center self-center",children:v?s.jsx("button",{type:"button",onClick:j=>{j.preventDefault(),j.stopPropagation(),u==null||u()},onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),j.stopPropagation(),u==null||u())},className:"inline-flex h-4 w-4 items-center justify-center rounded-full transition-colors hover:bg-blue-500/20","aria-label":"Mark as read",children:s.jsx("span",{className:G("block h-2 w-2 rounded-full bg-blue-600 transition-opacity duration-300 dark:bg-blue-400",c==="fading"?"opacity-0":"opacity-100")})}):s.jsx("span",{className:"inline-flex h-4 w-4","aria-hidden":"true"})}):null]})}const IC=["in_progress","todo","backlog","in_review","blocked","done","cancelled"],MC=["critical","high","medium","low"],d7t=[{value:"manual",label:"Manual"},{value:"status",label:"Status"},{value:"priority",label:"Priority"},{value:"title",label:"Title"},{value:"created",label:"Created"},{value:"updated",label:"Updated"}];function sk(e,t){const n=e.indexOf(t);return n===-1?e.length:n}function op(e){return e?new Date(e).getTime():0}function f7t(e,t,n){switch(n){case"manual":return(e.boardOrder??0)-(t.boardOrder??0);case"status":return sk(IC,e.status)-sk(IC,t.status);case"priority":return sk(MC,e.priority)-sk(MC,t.priority);case"title":return e.title.localeCompare(t.title);case"created":return op(e.createdAt)-op(t.createdAt);case"updated":return op(e.updatedAt)-op(t.updatedAt)}}function y7e(e,t){const n=t.sortDir==="asc"?1:-1;return[...e].sort((r,i)=>{const a=f7t(r,i,t.sortField);if(a!==0)return n*a;const o=op(i.updatedAt)-op(r.updatedAt);if(o!==0)return o;const l=op(i.createdAt)-op(r.createdAt);return l!==0?l:(r.identifier??r.id).localeCompare(i.identifier??i.id)})}function RC(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function m7t(e,t){return RC(e).getTime()===RC(t).getTime()}function h7t(e,t){const n=RC(t);return n.setDate(n.getDate()-1),RC(e).getTime()===n.getTime()}function nie(e,t=new Date){const n=new Date(e),r=tm();if(Number.isNaN(n.getTime()))return"-";if(m7t(n,t))return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(n);if(h7t(n,t))return r==="zh-CN"?"昨天":"Yesterday";const i=r==="zh-CN"?"zh-CN":"en-US";return new Intl.DateTimeFormat(i,r==="zh-CN"?{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23",...n.getFullYear()===t.getFullYear()?{}:{year:"numeric"}}:{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23",...n.getFullYear()===t.getFullYear()?{}:{year:"numeric"}}).format(n)}const Jg=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],OC={backlog:{base:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",over:"border-[color:var(--border-strong)] bg-[color:color-mix(in_oklab,var(--surface-active)_86%,var(--surface-inset))]"},todo:{base:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",over:"border-blue-300/90 bg-blue-100/82 dark:border-blue-700/70 dark:bg-blue-900/34"},in_progress:{base:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",over:"border-amber-300/90 bg-amber-100/82 dark:border-amber-700/70 dark:bg-amber-900/34"},in_review:{base:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",over:"border-violet-300/90 bg-violet-100/82 dark:border-violet-700/70 dark:bg-violet-900/34"},blocked:{base:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",over:"border-red-300/90 bg-red-100/82 dark:border-red-700/70 dark:bg-red-900/34"},done:{base:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",over:"border-emerald-300/90 bg-emerald-100/82 dark:border-emerald-700/70 dark:bg-emerald-900/34"},cancelled:{base:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26",over:"border-neutral-300/85 bg-neutral-100/82 dark:border-neutral-700/75 dark:bg-neutral-800/36"}};function yH(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function p7t(){const e={};for(const t of Jg)e[t]=[];return e}function g7t(e,t){return e.length!==t.length?!1:e.every((n,r)=>n.id===t[r])}function x7t(e,t,n){if(!n)return e;const r=new Map(t.map(a=>[a.id,a])),i=Object.fromEntries(Jg.map(a=>[a,[...e[a]]]));for(const[a,o]of Object.entries(n.laneIdsByStatus))i[a]=o.map(l=>{const c=r.get(l);return c?c.status===a?c:{...c,status:a}:null}).filter(l=>!!l);return i}function b7t(e,t){return Object.entries(t.laneIdsByStatus).every(([n,r])=>g7t(e[n]??[],r))}const vH=["identifier","priority","assignee","reviewer","labels","project","created"];function v7e({status:e,onCreateIssue:t}){return t?s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground","data-testid":`kanban-column-add-${e}`,"aria-label":`Create ${yH(e)} issue`,onClick:()=>t(e),children:s.jsx(tr,{className:"h-3 w-3"})}):null}function rie({relationship:e,agent:t,userId:n,fallbackId:r,currentUserId:i,showRole:a=!0}){const o=e==="assignee"?"Assignee":"Reviewer",l=t?rl(t):n?Ol(n,i)??"User":r?r.slice(0,8):null;if(!l)return null;const c=e==="assignee"?Hf:Fme;return s.jsxs("span",{"data-slot":`kanban-card-${e}`,title:`${o}: ${l}`,className:"inline-flex min-w-0 max-w-full items-center gap-1.5 overflow-hidden rounded-sm bg-muted/35 px-1.5 py-1 text-muted-foreground ring-1 ring-border/35",children:[a?s.jsx("span",{"data-slot":"kanban-card-person-role",className:"shrink-0 text-[10px] font-medium leading-none text-muted-foreground/75",children:o}):null,t?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full flex-1 items-center gap-1 text-xs",children:[s.jsx(Zj,{icon:t.icon,role:t.role,className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:l})]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full flex-1 items-center gap-1 text-xs",children:[s.jsx(c,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:G("truncate",r&&"font-mono"),children:l})]})]})}function Ny({icon:e,label:t,children:n}){return s.jsxs("div",{"data-slot":"kanban-card-metadata-row",className:"grid min-w-0 grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-2 text-xs",children:[s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-muted-foreground/75",children:[s.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:e}),s.jsx("span",{className:"truncate",children:t})]}),s.jsx("span",{className:"min-w-0 overflow-hidden text-right text-muted-foreground",children:n})]})}function y7t({status:e,issues:t,agents:n,currentUserId:r,displayProperties:i=vH,liveIssueIds:a,issueLinkState:o,recentlyDroppedIssueIds:l,projects:c,onCreateIssue:u,onOpenIssue:d}){const{setNodeRef:f,isOver:h}=PK({id:e}),g=ns(),b=OC[e]??OC.backlog,v=x.useCallback(j=>{f(j),g(j)},[g,f]);return s.jsxs("div",{className:"flex h-full min-h-0 w-[260px] min-w-[260px] shrink-0 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 mb-1",children:[s.jsx(os,{status:e}),s.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:yH(e)}),s.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t.length}),s.jsx(v7e,{status:e,onCreateIssue:u})]})]}),s.jsx("div",{"data-testid":`kanban-column-${e}`,"data-over":h?"true":"false",ref:v,className:G("motion-kanban-lane scrollbar-auto-hide flex-1 min-h-[120px] overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5 space-y-1.5",h?b.over:b.base),children:s.jsx(Hye,{items:t.map(j=>j.id),strategy:Uye,children:t.map(j=>s.jsx(w7e,{issue:j,agents:n,currentUserId:r,displayProperties:i,isLive:a==null?void 0:a.has(j.id),issueLinkState:o,justDropped:l==null?void 0:l.has(j.id),projects:c,onOpenIssue:d},j.id))})})]})}function v7t({status:e,issueCount:t,onCreateIssue:n}){const{setNodeRef:r,isOver:i}=PK({id:e}),a=OC[e]??OC.backlog;return s.jsxs("div",{ref:r,"data-testid":`kanban-hidden-column-${e}`,"data-over":i?"true":"false",className:G("motion-kanban-lane flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",i?a.over:a.base),children:[s.jsx(os,{status:e}),s.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:yH(e)}),s.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t}),s.jsx(v7e,{status:e,onCreateIssue:n})]})}function w7e({issue:e,agents:t,currentUserId:n,displayProperties:r=vH,isLive:i,issueLinkState:a,isOverlay:o,justDropped:l,projects:c,onOpenIssue:u}){var F,Z;const{attributes:d,listeners:f,setNodeRef:h,transform:g,transition:b,isDragging:v}=Wye({id:e.id,data:{issue:e}}),j={transform:E1.Transform.toString(g),transition:b},k=new Set(r),w=e.assigneeAgentId?(t==null?void 0:t.find(W=>W.id===e.assigneeAgentId))??null:null,N=e.reviewerAgentId?(t==null?void 0:t.find(W=>W.id===e.reviewerAgentId))??null:null,C=e.projectId?((F=c==null?void 0:c.find(W=>W.id===e.projectId))==null?void 0:F.name)??((Z=e.project)==null?void 0:Z.name)??null:null,A=k.has("identifier"),_=k.has("priority"),E=k.has("assignee"),T=k.has("reviewer")&&!!(e.reviewerAgentId||e.reviewerUserId),M=k.has("labels")&&(e.labels??[]).length>0,O=k.has("project")&&!!C,P=k.has("updated"),z=k.has("created"),L=E?s.jsx(rie,{relationship:"assignee",agent:w,userId:e.assigneeUserId,fallbackId:!w&&e.assigneeAgentId?e.assigneeAgentId:null,currentUserId:n,showRole:!1}):null,Q=T?s.jsx(rie,{relationship:"reviewer",agent:N,userId:e.reviewerUserId,fallbackId:!N&&e.reviewerAgentId?e.reviewerAgentId:null,currentUserId:n,showRole:!1}):null,ee=_,B=!!(Q||O||M||P||z);return s.jsx("div",{ref:h,style:j,...d,...f,"data-testid":`kanban-card-${e.identifier??e.id}`,"data-dragging":v&&!o?"true":"false","data-overlay":o?"true":"false","data-live":i?"true":"false","data-just-dropped":l?"true":"false",className:G("motion-kanban-card overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5 cursor-grab active:cursor-grabbing",v&&!o?"opacity-30":"",o?"shadow-lg ring-1 ring-primary/20":"hover:shadow-sm"),children:s.jsxs(yt,{to:`/issues/${e.identifier??e.id}`,state:a,className:"block min-w-0 no-underline text-inherit",onClick:W=>{if(v){W.preventDefault();return}u==null||u(e)},children:[s.jsxs("div",{"data-slot":"kanban-card-primary",className:"space-y-2",children:[A||i||L?s.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[A?s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:e.identifier??e.id.slice(0,8)}):null,i&&s.jsx("span",{className:"motion-live-dot relative flex h-2 w-2 shrink-0 text-blue-500",children:s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-500"})})]}),L?s.jsx("span",{"data-slot":"kanban-card-primary-assignee",className:"min-w-0 max-w-[8.5rem] shrink overflow-hidden",children:L}):null]}):null,s.jsx("p",{className:"line-clamp-2 text-sm leading-snug",children:e.title}),ee?s.jsx("div",{"data-slot":"kanban-card-primary-metadata",className:"flex min-w-0 items-center gap-2 overflow-hidden",children:_?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground",title:`Priority: ${Lo(e.priority)}`,children:[s.jsx(ya,{priority:e.priority}),s.jsx("span",{className:"truncate",children:Lo(e.priority)})]}):null}):null]}),B?s.jsxs("div",{"data-slot":"kanban-card-metadata",className:"mt-2 space-y-1.5 border-t border-[color:var(--border-soft)] pt-2",children:[O?s.jsx(Ny,{icon:s.jsx(r4,{className:"h-3 w-3"}),label:"Project",children:s.jsx("span",{className:"block truncate",children:C})}):null,Q?s.jsx(Ny,{icon:s.jsx(Fme,{className:"h-3 w-3"}),label:"Reviewer",children:s.jsx("span",{className:"flex min-w-0 max-w-full justify-end overflow-hidden",children:Q})}):null,M?s.jsx(Ny,{icon:s.jsx($me,{className:"h-3 w-3"}),label:"Labels",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap justify-end gap-1",children:[(e.labels??[]).slice(0,3).map(W=>s.jsx(T2,{label:W},W.id)),(e.labels??[]).length>3?s.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(e.labels??[]).length-3]}):null]})}):null,P?s.jsx(Ny,{icon:s.jsx(Hv,{className:"h-3 w-3"}),label:"Updated",children:nie(e.updatedAt)}):null,z?s.jsx(Ny,{icon:s.jsx(Hv,{className:"h-3 w-3"}),label:"Created",children:nie(e.createdAt)}):null]}):null]})})}function w7t({issues:e,agents:t,currentUserId:n,displayProperties:r,sortState:i,liveIssueIds:a,issueLinkState:o,projects:l,onCreateIssue:c,onOpenIssue:u,onUpdateIssue:d,onReorderIssue:f}){const[h,g]=x.useState(null),[b,v]=x.useState(new Set),[j,k]=x.useState(null),w=ns(),N=x.useRef([]),C=kye(wye(fA,{activationConstraint:{distance:5}})),A=x.useMemo(()=>{const L=p7t();for(const Q of e)L[Q.status]&&L[Q.status].push(Q);if(i)for(const Q of Jg)L[Q]=y7e(L[Q]??[],i);return L},[e,i]),_=x.useMemo(()=>x7t(A,e,j),[A,e,j]),E=x.useMemo(()=>Jg.filter(L=>{var Q;return(((Q=_[L])==null?void 0:Q.length)??0)>0}),[_]),T=x.useMemo(()=>Jg.filter(L=>{var Q;return(((Q=_[L])==null?void 0:Q.length)??0)===0}),[_]),M=x.useMemo(()=>h?e.find(L=>L.id===h):null,[h,e]);x.useEffect(()=>()=>{for(const L of N.current)window.clearTimeout(L);N.current=[]},[]),x.useEffect(()=>{if(!j)return;if(b7t(A,j)){k(null);return}const L=window.setTimeout(()=>{k(null)},3e3);return()=>window.clearTimeout(L)},[A,j]);function O(L){g(L.active.id)}function P(L){var re,X;g(null);const{active:Q,over:ee}=L;if(!ee)return;const B=Q.id,F=e.find(ie=>ie.id===B);if(!F)return;let Z=null;if(Jg.includes(ee.id))Z=ee.id;else{const ie=e.find(pe=>pe.id===ee.id);ie&&(Z=ie.status)}if(!Z)return;const W=_[Z]??[],$=W.filter(ie=>ie.id!==B);let Y=$.length;if(!Jg.includes(ee.id)){const ie=W.findIndex(pe=>pe.id===ee.id);ie>=0&&(Y=ie)}const V=[...$];V.splice(Y,0,{...F,status:Z});const H=V.findIndex(ie=>ie.id===B),ae=H>0?(re=V[H-1])==null?void 0:re.id:null,le=H>=0&&H<V.length-1?(X=V[H+1])==null?void 0:X.id:null,fe=ae?le?void 0:"end":"start",U=W.map(ie=>ie.id).join(`
|
|
1393
1393
|
`),xe=V.map(ie=>ie.id).join(`
|
|
1394
1394
|
`);if(Z!==F.status||U!==xe){const ie={[Z]:V.map(ke=>ke.id)};Z!==F.status&&(ie[F.status]=(_[F.status]??[]).filter(ke=>ke.id!==B).map(ke=>ke.id)),k({laneIdsByStatus:ie}),v(ke=>{const Ce=new Set(ke);return Ce.add(B),Ce});const pe=window.setTimeout(()=>{v(ke=>{const Ce=new Set(ke);return Ce.delete(B),Ce}),N.current=N.current.filter(ke=>ke!==pe)},520);N.current.push(pe),f?f({issueId:B,targetStatus:Z,previousIssueId:ae,nextIssueId:le,...fe?{position:fe}:{}}):Z!==F.status&&d(B,{status:Z})}}function z(L){}return s.jsxs(Fye,{sensors:C,onDragStart:O,onDragOver:z,onDragEnd:P,children:[s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx("div",{ref:w,className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:s.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[E.map(L=>s.jsx(y7t,{status:L,issues:_[L]??[],agents:t,currentUserId:n,displayProperties:r,liveIssueIds:a,issueLinkState:o,recentlyDroppedIssueIds:b,projects:l,onCreateIssue:c,onOpenIssue:u},L)),T.length>0?s.jsxs("div",{"data-testid":"kanban-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[s.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),s.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:T.length})]}),s.jsx("div",{className:"space-y-2",children:T.map(L=>{var Q;return s.jsx(v7t,{status:L,issueCount:((Q=_[L])==null?void 0:Q.length)??0,onCreateIssue:c},L)})})]}):null]})})}),s.jsx(xgt,{children:M?s.jsx(w7e,{issue:M,agents:t,currentUserId:n,displayProperties:r,isOverlay:!0,projects:l}):null})]})}function sie(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}const k7e=[{value:"identifier",label:"Identifier"},{value:"priority",label:"Priority"},{value:"assignee",label:"Assignee"},{value:"reviewer",label:"Reviewer"},{value:"labels",label:"Labels"},{value:"project",label:"Project"},{value:"updated",label:"Updated"},{value:"created",label:"Created"}],k7t=new Set(k7e.map(e=>e.value)),j7e=[...vH],wH={statuses:[],priorities:[],assignees:[],labels:[],projects:[],displayProperties:j7e,sortField:"updated",sortDir:"desc",groupBy:"none",viewMode:"board",collapsedGroups:[]},j7t=[{label:"All",statuses:[]},{label:"Active",statuses:["todo","in_progress","in_review","blocked"]},{label:"Backlog",statuses:["backlog"]},{label:"Done",statuses:["done","cancelled"]}],N7t="Getting Started",C7t=["welcome","core","recommended","advanced","other"],iie={welcome:{label:"Welcome",description:"Reference issue for Rudder’s collaboration model."},core:{label:"Core loop",description:"Complete these issues to experience chat → issue → execution → review → project context."},recommended:{label:"Recommended next",description:"Bring real context and one real task into Rudder."},advanced:{label:"Advanced",description:"Optional next steps for goals, reusable workflows, agent roles, and recurring loops."},other:{label:"Other",description:"Additional issues in this project."}};function S7t(e){return e.title.startsWith("👋 Welcome to Rudder")?"welcome":/^[1-5]\./.test(e.title)?"core":/^[6-7]\./.test(e.title)?"recommended":/^(?:[8-9]|10|11)\./.test(e.title)?"advanced":"other"}function aie(e){if(e.title.startsWith("👋 Welcome to Rudder"))return 0;const t=/^(\d+)\./.exec(e.title);return t?Number(t[1]):99}function _7t(e){return[...e].sort((t,n)=>{const r=aie(t)-aie(n);return r!==0?r:t.title.localeCompare(n.title)})}function A7t(e){try{const t=localStorage.getItem(e);if(t){const n=JSON.parse(t);return I7t(n)}}catch{}return{...wH}}function E7t(e,t){localStorage.setItem(e,JSON.stringify(t))}function T7t(e){if(!Array.isArray(e))return[...j7e];const t=new Set,n=[];for(const r of e){if(!k7t.has(r))continue;const i=r;t.has(i)||(t.add(i),n.push(i))}return n}function I7t(e){return{...wH,...e,statuses:Array.isArray(e.statuses)?[...e.statuses]:[],priorities:Array.isArray(e.priorities)?[...e.priorities]:[],assignees:Array.isArray(e.assignees)?[...e.assignees]:[],labels:Array.isArray(e.labels)?[...e.labels]:[],projects:Array.isArray(e.projects)?[...e.projects]:[],collapsedGroups:Array.isArray(e.collapsedGroups)?[...e.collapsedGroups]:[],displayProperties:T7t(e.displayProperties)}}function M7t(e,t){if(e.length!==t.length)return!1;const n=[...e].sort(),r=[...t].sort();return n.every((i,a)=>i===r[a])}function Nh(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function R7t(e,t,n){let r=e;return t.statuses.length>0&&(r=r.filter(i=>t.statuses.includes(i.status))),t.priorities.length>0&&(r=r.filter(i=>t.priorities.includes(i.priority))),t.assignees.length>0&&(r=r.filter(i=>{for(const a of t.assignees)if(a==="__unassigned"&&!i.assigneeAgentId&&!i.assigneeUserId||a==="__me"&&n&&i.assigneeUserId===n||i.assigneeAgentId===a)return!0;return!1})),t.labels.length>0&&(r=r.filter(i=>(i.labelIds??[]).some(a=>t.labels.includes(a)))),t.projects.length>0&&(r=r.filter(i=>i.projectId!=null&&t.projects.includes(i.projectId))),r}function O7t(e){let t=0;return e.statuses.length>0&&t++,e.priorities.length>0&&t++,e.assignees.length>0&&t++,e.labels.length>0&&t++,e.projects.length>0&&t++,t}function P7t({issues:e,isLoading:t,error:n,agents:r,projects:i,liveIssueIds:a,projectId:o,viewStateKey:l,issueLinkState:c,initialAssignees:u,initialSearch:d,initialGroupBy:f,toolbarMode:h="full",starredIssueIds:g=[],onToggleStarredIssue:b,onOpenIssue:v,searchFilters:j,onSearchChange:k,onUpdateIssue:w,onReorderIssue:N}){var ue,me;const{selectedOrganizationId:C}=wn(),{openNewIssue:A}=Wr(),{data:_}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),E=((ue=_==null?void 0:_.user)==null?void 0:ue.id)??((me=_==null?void 0:_.session)==null?void 0:me.userId)??null,T=C?`${l}:${C}`:l,M=x.useCallback(()=>{const K=u?{...wH,assignees:u,statuses:[]}:A7t(T);return f?{...K,groupBy:f}:K},[u,f,T]),[O,P]=x.useState(()=>M()),[z,L]=x.useState(null),[Q,ee]=x.useState(""),[B,F]=x.useState(d??""),[Z,W]=x.useState(B),$=ns(),Y=ns(),V=ns(),H=ns(),ae=Z.trim();x.useEffect(()=>{F(d??"")},[d]),x.useEffect(()=>{const K=window.setTimeout(()=>{W(B)},300);return()=>window.clearTimeout(K)},[B]);const le=x.useRef(T);x.useEffect(()=>{le.current!==T&&(le.current=T,P(M()))},[M,T]);const fe=x.useCallback(K=>{P(je=>{const Be={...je,...K};return E7t(T,Be),Be})},[T]),{data:U=[]}=Ne({queryKey:[...q.issues.search(C,ae,o),j??{}],queryFn:()=>ln.list(C,{q:ae,projectId:o,...j}),enabled:!!C&&ae.length>0}),xe=x.useMemo(()=>new Map((r??[]).map(K=>[K.id,K])),[r]),re=x.useCallback(K=>{if(!K)return null;const je=xe.get(K);return je?rl(je):null},[xe]),X=x.useMemo(()=>{const K=ae.length>0?U:e,je=R7t(K,O,E);return y7e(je,O)},[e,U,O,ae,E]),ie=x.useMemo(()=>X.filter(K=>a==null?void 0:a.has(K.id)).length,[X,a]),pe=`${ie} ${ie===1?"issue":"issues"} working in current view`,{data:ke}=Ne({queryKey:q.issues.labels(C),queryFn:()=>ln.listLabels(C),enabled:!!C}),Ce=O7t(O),$e=x.useMemo(()=>{var K;return((K=i==null?void 0:i.find(je=>je.id===o))==null?void 0:K.name)??null},[o,i]),Ue=$e===N7t,he=x.useMemo(()=>ae.length>0?`No issues match “${ae}”. Try a different search or clear some filters.`:Ce>0?"No issues match the current filters. Adjust the filters or clear them to see more work.":$e?`${$e} does not have any issues yet. Create the first issue for this project.`:"There are no issues yet. Create one to start tracking work here.",[Ce,ae,$e]),We=ae.length===0&&Ce===0?"New Issue":void 0,ct=x.useMemo(()=>$e&&ae.length===0&&Ce===0?`${$e} does not have any issues yet. Use a lane + button to create the first one in the right status.`:ae.length>0||Ce>0?"No issues match the current board. Use a lane + button to create a new issue in the right status. Clear search or filters if it does not appear.":"No issues match the current board. Use a lane + button to create a new issue in the right status.",[Ce,ae,$e]),Pe=x.useMemo(()=>{var je;if(Ue&&O.groupBy==="none"){const Be=jy(X,S7t);return C7t.filter(Ve=>{var Me;return(Me=Be[Ve])==null?void 0:Me.length}).map(Ve=>({key:`onboarding:${Ve}`,label:iie[Ve].label,description:iie[Ve].description,items:_7t(Be[Ve])}))}if(O.groupBy==="none")return[{key:"__all",label:null,items:X}];if(O.groupBy==="status"){const Be=jy(X,Ve=>Ve.status);return IC.filter(Ve=>{var Me;return(Me=Be[Ve])==null?void 0:Me.length}).map(Ve=>({key:Ve,label:sie(Ve),items:Be[Ve]}))}if(O.groupBy==="priority"){const Be=jy(X,Ve=>Ve.priority);return MC.filter(Ve=>{var Me;return(Me=Be[Ve])==null?void 0:Me.length}).map(Ve=>({key:Ve,label:Lo(Ve),items:Be[Ve]}))}if(O.groupBy==="project"){const Be=jy(X,Me=>Me.projectId??"__no_project"),Ve=(i??[]).filter(Me=>{var ht;return(ht=Be[Me.id])==null?void 0:ht.length}).map(Me=>({key:Me.id,label:Me.name,items:Be[Me.id]}));return(je=Be.__no_project)!=null&&je.length&&Ve.push({key:"__no_project",label:"Unscoped",items:Be.__no_project}),Ve}const K=jy(X,Be=>Be.assigneeAgentId??(Be.assigneeUserId?`__user:${Be.assigneeUserId}`:"__unassigned"));return Object.keys(K).map(Be=>({key:Be,label:Be==="__unassigned"?"Unassigned":Be.startsWith("__user:")?Ol(Be.slice(7),E)??"User":re(Be)??Be.slice(0,8),items:K[Be]}))},[re,E,X,Ue,i,O.groupBy]),Ae=x.useMemo(()=>{const K={};if(o?K.projectId=o:O.projects.length===1&&(K.projectId=O.projects[0]),O.priorities.length===1&&(K.priority=O.priorities[0]),O.labels.length>0&&(K.labelIds=[...O.labels]),O.assignees.length===1){const je=O.assignees[0];je==="__me"&&E?K.assigneeUserId=E:je!=="__unassigned"&&(K.assigneeAgentId=je)}return K},[E,o,O.assignees,O.labels,O.priorities,O.projects]),oe=K=>{const je={...Ae};return K&&(O.groupBy==="status"?je.status=K:O.groupBy==="priority"?je.priority=K:O.groupBy==="project"&&K!=="__no_project"?je.projectId=K:O.groupBy==="assignee"&&K!=="__unassigned"&&(K.startsWith("__user:")?je.assigneeUserId=K.slice(7):je.assigneeAgentId=K)),je},D=(K,je,Be=null)=>{w(K,{assigneeAgentId:je,assigneeUserId:Be}),L(null),ee("")},J=K=>{if(!N){w(K.issueId,{status:K.targetStatus});return}(O.sortField!=="manual"||O.sortDir!=="asc")&&fe({sortField:"manual",sortDir:"asc"}),N(K)},de=K=>{L(je=>je===K?null:K),ee("")};return s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-4",children:[h!=="hidden"&&s.jsxs("div",{"data-testid":"issues-view-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 items-center gap-2 sm:gap-3",children:h==="full"?s.jsxs(s.Fragment,{children:[s.jsxs(ce,{size:"sm",variant:"outline",onClick:()=>A(oe()),children:[s.jsx(tr,{className:"h-4 w-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"New Issue"})]}),s.jsxs("div",{className:"relative w-48 sm:w-64 md:w-80",children:[s.jsx(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),s.jsx(In,{value:B,onChange:K=>{F(K.target.value),k==null||k(K.target.value)},placeholder:"Search issues...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search issues"})]})]}):s.jsx("div",{className:"flex min-w-0 items-center gap-2",children:s.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"Issues"})})}),s.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[s.jsxs("div",{"data-testid":"issues-working-count",className:"mr-1 inline-flex h-8 items-center rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-3 text-sm font-medium text-muted-foreground","aria-label":pe,title:pe,children:[ie," working"]}),s.jsxs("div",{className:"mr-1 flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[s.jsx("button",{className:`p-1.5 transition-colors ${O.viewMode==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>fe({viewMode:"list"}),title:"List view",children:s.jsx(Vz,{className:"h-3.5 w-3.5"})}),s.jsx("button",{className:`p-1.5 transition-colors ${O.viewMode==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>fe({viewMode:"board"}),title:"Board view",children:s.jsx(kme,{className:"h-3.5 w-3.5"})})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:`text-xs ${Ce>0?"text-[color:var(--accent-strong)]":""}`,children:[s.jsx($j,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:Ce>0?`Filters: ${Ce}`:"Filter"}),Ce>0&&s.jsx("span",{className:"sm:hidden text-[10px] font-medium ml-0.5",children:Ce}),Ce>0&&s.jsx(Gs,{className:"h-3 w-3 ml-1 hidden sm:block",onClick:K=>{K.stopPropagation(),fe({statuses:[],priorities:[],assignees:[],labels:[],projects:[]})}})]})}),s.jsx(Kn,{align:"end",className:"w-[min(480px,calc(100vw-2rem))] p-0",children:s.jsxs("div",{className:"p-3 space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Filters"}),Ce>0&&s.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>fe({statuses:[],priorities:[],assignees:[],labels:[],projects:[]}),children:"Clear"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Quick filters"}),s.jsx("div",{className:"flex flex-wrap gap-1.5",children:j7t.map(K=>{const je=M7t(O.statuses,K.statuses);return s.jsx("button",{className:`px-2.5 py-1 text-xs rounded-[calc(var(--radius-sm)-1px)] border transition-colors ${je?"bg-primary text-primary-foreground border-primary":"border-[color:var(--border-base)] text-muted-foreground hover:text-foreground hover:border-[color:var(--border-strong)]"}`,onClick:()=>fe({statuses:je?[]:[...K.statuses]}),children:K.label},K.label)})})]}),s.jsx("div",{className:"border-t panel-divider"}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),s.jsx("div",{className:"space-y-0.5",children:IC.map(K=>s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.statuses.includes(K),onCheckedChange:()=>fe({statuses:Nh(O.statuses,K)})}),s.jsx(os,{status:K}),s.jsx("span",{className:"text-sm",children:sie(K)})]},K))})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),s.jsx("div",{className:"space-y-0.5",children:MC.map(K=>s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.priorities.includes(K),onCheckedChange:()=>fe({priorities:Nh(O.priorities,K)})}),s.jsx(ya,{priority:K}),s.jsx("span",{className:"text-sm",children:Lo(K)})]},K))})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),s.jsxs("div",{ref:$,"data-testid":"issues-filter-assignee-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:[s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.assignees.includes("__unassigned"),onCheckedChange:()=>fe({assignees:Nh(O.assignees,"__unassigned")})}),s.jsx("span",{className:"text-sm",children:"No assignee"})]}),E&&s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.assignees.includes("__me"),onCheckedChange:()=>fe({assignees:Nh(O.assignees,"__me")})}),s.jsx(Hf,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm",children:"Me"})]}),(r??[]).map(K=>s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.assignees.includes(K.id),onCheckedChange:()=>fe({assignees:Nh(O.assignees,K.id)})}),s.jsx(ki,{icon:K.icon,role:K.role,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"text-sm",children:rl(K)})]},K.id))]})]}),ke&&ke.length>0&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Labels"}),s.jsx("div",{ref:Y,"data-testid":"issues-filter-labels-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:ke.map(K=>s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.labels.includes(K.id),onCheckedChange:()=>fe({labels:Nh(O.labels,K.id)})}),s.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:K.color}}),s.jsx("span",{className:"text-sm",children:K.name})]},K.id))})]}),i&&i.length>0&&s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:"Project"}),s.jsx("div",{ref:V,"data-testid":"issues-filter-projects-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:i.map(K=>s.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[s.jsx(eo,{checked:O.projects.includes(K.id),onCheckedChange:()=>fe({projects:Nh(O.projects,K.id)})}),s.jsx("span",{className:"text-sm",children:K.name})]},K.id))})]})]})]})]})})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:"text-xs",children:[s.jsx(hP,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),s.jsx(Kn,{align:"end",className:"w-48 p-0",children:s.jsx("div",{className:"p-2 space-y-0.5",children:d7t.map(K=>s.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${O.sortField===K.value?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>{O.sortField===K.value?fe({sortDir:O.sortDir==="asc"?"desc":"asc"}):fe({sortField:K.value,sortDir:"asc"})},children:[s.jsx("span",{children:K.label}),O.sortField===K.value&&s.jsx("span",{className:"text-xs text-muted-foreground",children:O.sortDir==="asc"?"↑":"↓"})]},K.value))})})]}),O.viewMode==="board"&&s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:"text-xs",children:[s.jsx(o4,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Display"})]})}),s.jsx(Kn,{align:"end",className:"w-52 p-0",children:s.jsx("div",{className:"p-2 space-y-0.5",children:k7e.map(K=>s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent/50",children:[s.jsx(eo,{checked:O.displayProperties.includes(K.value),onCheckedChange:()=>fe({displayProperties:Nh(O.displayProperties,K.value)})}),s.jsx("span",{children:K.label})]},K.value))})})]}),O.viewMode==="list"&&s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:"text-xs",children:[s.jsx(Kz,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Group"})]})}),s.jsx(Kn,{align:"end",className:"w-44 p-0",children:s.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["assignee","Assignee"],["project","Project"],["none","None"]].map(([K,je])=>s.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${O.groupBy===K?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>fe({groupBy:K}),children:[s.jsx("span",{children:je}),O.groupBy===K&&s.jsx(gs,{className:"h-3.5 w-3.5"})]},K))})})]})]})]}),t&&s.jsx(As,{variant:"issues-list"}),n&&s.jsx("p",{className:"text-sm text-destructive",children:n.message}),!t&&X.length===0&&O.viewMode!=="board"&&s.jsx("div",{className:"flex min-h-[58vh] items-center justify-center",children:s.jsx(Fr,{icon:nc,message:he,action:We,onAction:We?()=>A(oe()):void 0})}),!t&&O.viewMode==="board"&&s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[X.length===0?s.jsx("div",{className:"mb-3 rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-3 text-sm text-muted-foreground",children:ct}):null,s.jsx(w7t,{issues:X,agents:r,currentUserId:E,displayProperties:O.displayProperties,sortState:{sortField:O.sortField,sortDir:O.sortDir},liveIssueIds:a,issueLinkState:c,projects:i,onCreateIssue:K=>A({...Ae,status:K}),onOpenIssue:v,onUpdateIssue:w,onReorderIssue:J})]}),!t&&X.length>0&&O.viewMode!=="board"&&Pe.map(K=>s.jsxs(L0,{open:!O.collapsedGroups.includes(K.key),onOpenChange:je=>{fe({collapsedGroups:je?O.collapsedGroups.filter(Be=>Be!==K.key):[...O.collapsedGroups,K.key]})},children:[K.label&&s.jsxs("div",{className:"flex items-center py-1.5 pl-1 pr-3",children:[s.jsxs(pA,{className:"flex items-center gap-1.5",children:[s.jsx(Ls,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),s.jsxs("span",{className:"flex flex-col items-start gap-0.5 text-left",children:[s.jsx("span",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:K.label}),K.description?s.jsx("span",{className:"max-w-[68ch] text-xs font-normal normal-case tracking-normal text-muted-foreground/80",children:K.description}):null]})]}),s.jsx(ce,{variant:"ghost",size:"icon-xs",className:"ml-auto text-muted-foreground",onClick:()=>A(oe(K.key)),children:s.jsx(tr,{className:"h-3 w-3"})})]}),s.jsx($0,{children:K.items.map(je=>{var Be,Ve;return s.jsx(M$,{issue:je,issueLinkState:c,desktopLeadingSpacer:!0,mobileLeading:s.jsx("span",{onClick:Me=>{Me.preventDefault(),Me.stopPropagation()},children:s.jsx(os,{status:je.status,onChange:Me=>w(je.id,{status:Me})})}),desktopMetaLeading:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"hidden shrink-0 sm:inline-flex",onClick:Me=>{Me.preventDefault(),Me.stopPropagation()},children:s.jsx(os,{status:je.status,onChange:Me=>w(je.id,{status:Me})})}),s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:je.identifier??je.id.slice(0,8)}),(a==null?void 0:a.has(je.id))&&s.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-proposal)_80%,transparent)] px-1.5 py-0.5 sm:gap-1.5 sm:px-2",children:[s.jsxs("span",{className:"relative flex h-2 w-2",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-[color:var(--accent-base)] opacity-75"}),s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-[color:var(--accent-strong)]"})]}),s.jsx("span",{className:"hidden text-[11px] font-medium text-[color:var(--accent-strong)] sm:inline",children:"Live"})]})]}),mobileMeta:I1(je.updatedAt),desktopTrailing:s.jsxs(s.Fragment,{children:[b?s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:Me=>{Me.preventDefault(),Me.stopPropagation(),b(je.id)},title:g.includes(je.id)?"Unstar issue":"Star issue",children:s.jsx(Lme,{className:G("h-3.5 w-3.5",g.includes(je.id)&&"fill-current text-amber-500")})}):null,(je.labels??[]).length>0&&s.jsxs("span",{className:"hidden items-center gap-1 overflow-hidden md:flex md:max-w-[240px]",children:[(je.labels??[]).slice(0,3).map(Me=>s.jsx(T2,{label:Me},Me.id)),(je.labels??[]).length>3&&s.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(je.labels??[]).length-3]})]}),s.jsxs(qn,{open:z===je.id,onOpenChange:Me=>{L(Me?je.id:null),Me||ee("")},children:[s.jsx(FBe,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex w-[180px] shrink-0 items-center rounded-md px-2 py-1 transition-colors hover:bg-accent/50",onClick:Me=>{Me.preventDefault(),Me.stopPropagation(),de(je.id)},children:je.assigneeAgentId&&xe.get(je.assigneeAgentId)?s.jsx(Ki,{kind:"agent",label:xe.get(je.assigneeAgentId).name,badgeLabel:Q2(xe.get(je.assigneeAgentId)),agentIcon:(Be=xe.get(je.assigneeAgentId))==null?void 0:Be.icon,agentRole:(Ve=xe.get(je.assigneeAgentId))==null?void 0:Ve.role}):je.assigneeUserId?s.jsx(Ki,{kind:"user",label:Ol(je.assigneeUserId,E)??"User"}):s.jsx(Ki,{kind:"unassigned",label:"Assignee",muted:!0})})}),s.jsxs(Kn,{className:"w-56 p-1",align:"end",onClick:Me=>Me.stopPropagation(),onPointerDownOutside:()=>ee(""),children:[s.jsx("input",{className:"mb-1 w-full border-b border-border bg-transparent px-2 py-1.5 text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:Q,onChange:Me=>ee(Me.target.value),autoFocus:!0}),s.jsxs("div",{ref:H,"data-testid":"issue-row-assignee-picker-scroll",className:"scrollbar-auto-hide max-h-48 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-accent/50",!je.assigneeAgentId&&!je.assigneeUserId&&"bg-accent"),onClick:Me=>{Me.preventDefault(),Me.stopPropagation(),D(je.id,null,null)},children:s.jsx(Ki,{kind:"unassigned",label:"No assignee"})}),E&&s.jsx("button",{className:G("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",je.assigneeUserId===E&&"bg-accent"),onClick:Me=>{Me.preventDefault(),Me.stopPropagation(),D(je.id,null,E)},children:s.jsx(Ki,{kind:"user",label:"Me"})}),(r??[]).filter(Me=>Q.trim()?`${rl(Me)} ${Me.name} ${Me.role} ${Me.title??""}`.toLowerCase().includes(Q.toLowerCase()):!0).map(Me=>s.jsx("button",{className:G("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",je.assigneeAgentId===Me.id&&"bg-accent"),onClick:ht=>{ht.preventDefault(),ht.stopPropagation(),D(je.id,Me.id,null)},children:s.jsx(Ki,{kind:"agent",label:Me.name,badgeLabel:Q2(Me),agentIcon:Me.icon,agentRole:Me.role,className:"min-w-0"})},Me.id))]})]})]})]}),trailingMeta:Ha(je.createdAt),onOpen:()=>v==null?void 0:v(je)},je.id)})})]},K.key))]})}const Yy="rudder.linear",oie="page-bootstrap",lie="linear-catalog",HR="linear-issues",D7t="import-linear-issues",L7t=50,VR=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],N7e={backlog:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",todo:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",in_progress:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",in_review:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",blocked:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",done:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",cancelled:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26"};function $7t(e){return(e==null?void 0:e.find(t=>t.pluginKey===Yy))??null}function C7e(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function F7t(e){const t=[`Imported ${e.importedCount}`];return e.duplicateCount>0&&t.push(`${e.duplicateCount} duplicate`),e.fallbackCount>0&&t.push(`${e.fallbackCount} fallback`),e.adjustedCount>0&&t.push(`${e.adjustedCount} adjusted`),t.join(" / ")}function ik(e){return G("h-9 min-w-0 rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)] px-2.5 text-sm text-foreground outline-none transition-[border-color,box-shadow] focus:border-ring focus:ring-[3px] focus:ring-ring/40 disabled:cursor-not-allowed disabled:opacity-50",e)}function z7t(){if(typeof window>"u")return"board";const e=window.localStorage.getItem("rudder:linear-source-view-mode");return e==="list"||e==="board"?e:"board"}function B7t(e,t){var r;const n=t==null?void 0:t.find(i=>i.teamId===e.team.id);return((r=n==null?void 0:n.stateMappings.find(i=>i.linearStateId===e.state.id))==null?void 0:r.rudderStatus)??"backlog"}function cie(e,t){const n=e?Date.parse(e):0,r=t?Date.parse(t):0;return n-r}function U7t(e){const t=e.importedRudderIssueIdentifier??e.importedRudderIssueId;return t?`/issues/${t}`:null}function WR({label:e,children:t,className:n}){return s.jsxs("label",{className:G("flex min-w-0 flex-col gap-1",n),children:[s.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:e}),t]})}function S7e(){return s.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[calc(var(--radius-sm)-2px)] border border-emerald-300/60 bg-emerald-50 px-1.5 py-0.5 text-[11px] font-medium text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/28 dark:text-emerald-300",children:[s.jsx(gs,{className:"h-3 w-3"}),"Imported"]})}function q7t({row:e}){var t,n;return s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[s.jsx(os,{status:_7e(e.state.type)}),s.jsx("span",{className:"truncate",children:e.state.name})]}),s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[s.jsx(r4,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:((t=e.project)==null?void 0:t.name)??"No Linear project"})]}),s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[s.jsx(f5,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:((n=e.assignee)==null?void 0:n.name)??"Unassigned"})]}),s.jsxs("span",{children:["Updated ",I1(e.updatedAt)]})]})}function _7e(e){return e==="started"?"in_progress":e==="completed"?"done":e==="canceled"?"cancelled":e==="backlog"?"backlog":"todo"}function A7e({row:e,orgId:t}){if(!e.imported)return null;const n=U7t(e),r=!e.importedOrgId||e.importedOrgId===t;return n&&r?s.jsx(ce,{asChild:!0,variant:"ghost",size:"sm",children:s.jsx(yt,{to:n,children:"Open issue"})}):s.jsx("span",{className:"text-xs text-muted-foreground",children:"Imported elsewhere"})}function K7t({rows:e,selectedIssueIds:t,orgId:n,importing:r,onToggleSelected:i}){return s.jsx("div",{className:"min-h-0 overflow-hidden rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)]",children:e.map(a=>{const o=t.includes(a.id);return s.jsxs("article",{"data-testid":`linear-source-row-${a.id}`,className:"grid min-h-16 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 border-b border-[color:var(--border-soft)] px-3 py-3 last:border-b-0",children:[s.jsx("input",{type:"checkbox","data-testid":`linear-source-row-checkbox-${a.id}`,className:"h-4 w-4 rounded border-[color:var(--border-base)]",checked:o,disabled:a.imported||r,"aria-label":`Select ${a.identifier}`,onChange:()=>i(a.id)}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsxs("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"min-w-0 truncate text-sm font-medium text-foreground no-underline hover:underline",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:a.identifier})," ",a.title]}),a.imported?s.jsx(S7e,{}):null]}),s.jsx(q7t,{row:a})]}),s.jsx("div",{className:"flex shrink-0 items-center",children:s.jsx(A7e,{row:a,orgId:n})})]},a.id)})})}function H7t({status:e,issueCount:t}){return s.jsxs("div",{"data-testid":`linear-source-hidden-column-${e}`,className:G("flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",N7e[e]),children:[s.jsx(os,{status:e}),s.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:C7e(e)}),s.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t})]})}function V7t({rows:e,teamMappings:t,selectedIssueIds:n,orgId:r,importing:i,onToggleSelected:a}){const o=x.useMemo(()=>{var d;const u=new Map;for(const f of VR)u.set(f,[]);for(const f of e){const h=B7t(f,t);(d=u.get(h))==null||d.push(f)}return u},[e,t]),l=VR.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)>0}),c=VR.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)===0});return s.jsx("div",{className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:s.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[l.map(u=>{const d=o.get(u)??[];return s.jsxs("section",{className:"flex h-full min-h-0 w-[272px] min-w-[272px] shrink-0 flex-col",children:[s.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-2",children:[s.jsx(os,{status:u}),s.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:C7e(u)}),s.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:d.length})]}),s.jsx("div",{"data-testid":`linear-source-kanban-column-${u}`,className:G("scrollbar-auto-hide flex-1 space-y-1.5 overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5",N7e[u]),children:d.map(f=>{var h,g;return s.jsxs("article",{"data-testid":`linear-source-board-card-${f.id}`,className:"overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5",children:[s.jsxs("div",{className:"mb-1.5 flex min-w-0 items-start gap-2",children:[s.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 rounded border-[color:var(--border-base)]",checked:n.includes(f.id),disabled:f.imported||i,"aria-label":`Select ${f.identifier}`,onChange:()=>a(f.id)}),s.jsx("a",{href:f.url,target:"_blank",rel:"noreferrer",className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground no-underline hover:underline",children:f.identifier}),f.imported?s.jsx(S7e,{}):null]}),s.jsx("p",{className:"mb-2 line-clamp-2 text-sm leading-snug",children:f.title}),s.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground",children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(os,{status:_7e(f.state.type)}),s.jsx("span",{className:"truncate",children:f.state.name})]}),s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(r4,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:((h=f.project)==null?void 0:h.name)??"No Linear project"})]}),s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(f5,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:((g=f.assignee)==null?void 0:g.name)??"Unassigned"})]}),s.jsxs("span",{children:["Updated ",I1(f.updatedAt)]})]}),f.imported?s.jsx("div",{className:"mt-3 flex justify-end",children:s.jsx(A7e,{row:f,orgId:r})}):null]},f.id)})})]},u)}),c.length>0?s.jsxs("div",{"data-testid":"linear-source-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[s.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),s.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:c.length})]}),s.jsx("div",{className:"space-y-2",children:c.map(u=>{var d;return s.jsx(H7t,{status:u,issueCount:((d=o.get(u))==null?void 0:d.length)??0},u)})})]}):null]})})}function W7t({orgId:e,orgName:t,projects:n,linearTeamId:r="",linearProjectId:i="",initialSearch:a=""}){var Me,ht;const o=vn(),{pushToast:l}=_r(),[c,u]=x.useState(()=>z7t()),[d,f]=x.useState(!1),[h,g]=x.useState("selected"),[b,v]=x.useState(""),[j,k]=x.useState(""),[w,N]=x.useState(""),[C,A]=x.useState("updated"),[_,E]=x.useState("desc"),[T,M]=x.useState(a),[O,P]=x.useState(a),[z,L]=x.useState([]),Q=x.useRef(null),ee=(t==null?void 0:t.trim())||"this organization";x.useEffect(()=>{M(a),P(a)},[a]),x.useEffect(()=>{const ve=window.setTimeout(()=>P(T.trim()),300);return()=>window.clearTimeout(ve)},[T]),x.useEffect(()=>{L([])},[r,i,j,w,O]),x.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem("rudder:linear-source-view-mode",c)},[c]);const{data:B,isLoading:F}=Ne({queryKey:q.plugins.uiContributions,queryFn:()=>_s.listUiContributions()}),Z=x.useMemo(()=>$7t(B),[B]),W=(Z==null?void 0:Z.pluginId)??"",{data:$,isLoading:Y,error:V}=Ne({queryKey:["plugins",Yy,oie,e,W],queryFn:async()=>(await _s.bridgeGetData(W,oie,{orgId:e},e)).data,enabled:!!e&&!!W}),{data:H,isLoading:ae}=Ne({queryKey:["plugins",Yy,lie,e,W],queryFn:async()=>(await _s.bridgeGetData(W,lie,{orgId:e},e)).data,enabled:!!e&&!!W&&($==null?void 0:$.configured)!==!1}),le=["plugins",Yy,HR,e,W,r||"__all__",i||"__all__",j||"__all__",w||"__all__",O||"__none__"],{data:fe,isLoading:U,error:xe,hasNextPage:re,fetchNextPage:X,isFetchingNextPage:ie}=gNe({queryKey:le,initialPageParam:null,queryFn:async({pageParam:ve})=>{const Le=typeof ve=="string"&&ve?ve:void 0;return(await _s.bridgeGetData(W,HR,{orgId:e,limit:L7t,after:Le,teamId:r||void 0,projectId:i||void 0,stateId:j||void 0,assigneeId:w||void 0,query:O||void 0},e)).data},getNextPageParam:ve=>ve.hasNextPage&&ve.endCursor?ve.endCursor:void 0,enabled:!!e&&!!W&&($==null?void 0:$.configured)===!0}),pe=nt({mutationFn:async({mode:ve,issueIds:Le})=>{if(!b)throw new Error(`Choose a project in ${ee} before importing.`);return(await _s.bridgePerformAction(W,D7t,{orgId:e,targetProjectId:b,mode:ve,issueIds:Le,filters:{teamId:r||void 0,stateId:j||void 0,projectId:i||void 0,assigneeId:w||void 0,query:O||void 0}},e)).data},onSuccess:async ve=>{l({title:"Linear import complete",body:F7t(ve),tone:"success"}),L([]),f(!1),await Promise.all([o.invalidateQueries({queryKey:["plugins",Yy,HR,e]}),o.invalidateQueries({queryKey:q.issues.list(e)})])},onError:ve=>{l({title:"Linear import failed",body:ve instanceof Error?ve.message:String(ve),tone:"error"})}}),ke=x.useMemo(()=>{const ve=[...(fe==null?void 0:fe.pages.flatMap(Le=>Le.rows))??[]];return ve.sort((Le,Ie)=>{let at=0;return C==="updated"?at=cie(Le.updatedAt,Ie.updatedAt):C==="created"?at=cie(Le.createdAt,Ie.createdAt):at=Le.identifier.localeCompare(Ie.identifier),_==="asc"?at:-at}),ve},[fe==null?void 0:fe.pages,_,C]);x.useEffect(()=>{const ve=new Set(ke.map(Le=>Le.id));L(Le=>Le.filter(Ie=>ve.has(Ie)))},[ke]);const Ce=x.useMemo(()=>(H==null?void 0:H.teams.find(ve=>ve.id===r))??null,[H==null?void 0:H.teams,r]),$e=x.useMemo(()=>(H==null?void 0:H.projects.find(ve=>ve.id===i))??null,[H==null?void 0:H.projects,i]),Ue=$e?`${$e.name}${Ce?` / ${Ce.name}`:""}`:(Ce==null?void 0:Ce.name)??"All Linear teams",he=x.useMemo(()=>{var Le;return((Le=$==null?void 0:$.projects)!=null&&Le.length?$.projects:n??[]).filter(Ie=>!("archivedAt"in Ie)||!Ie.archivedAt)},[$==null?void 0:$.projects,n]);x.useEffect(()=>{if(he.length===0){b&&v("");return}he.some(ve=>ve.id===b)||v(he.length===1?he[0].id:"")},[b,he]);const We=x.useMemo(()=>{const ve=r?((H==null?void 0:H.teams)??[]).filter(Ie=>Ie.id===r):(H==null?void 0:H.teams)??[],Le=new Map;for(const Ie of ve)for(const at of Ie.states??[])Le.set(at.id,at.name);return[...Le.entries()].map(([Ie,at])=>({id:Ie,name:at}))},[H==null?void 0:H.teams,r]),ct=ke.filter(ve=>ve.imported).length,Pe=ke.filter(ve=>!ve.imported),Ae=pe.isPending,oe=F||Y||ae||U,D=V??xe,J=z.length,de=he.find(ve=>ve.id===b)??null,ue=ke.length,me=+!!j+ +!!w,K=((Me=We.find(ve=>ve.id===j))==null?void 0:Me.name)??"All states",je=((ht=H==null?void 0:H.users.find(ve=>ve.id===w))==null?void 0:ht.name)??"Anyone",Be=x.useCallback(ve=>{L(Le=>Le.includes(ve)?Le.filter(Ie=>Ie!==ve):[...Le,ve])},[]),Ve=x.useCallback(ve=>{g(ve),f(!0)},[]);return x.useEffect(()=>{const ve=Q.current;if(!ve||!re||oe||Ae||ie||typeof IntersectionObserver>"u")return;const Le=new IntersectionObserver(Ie=>{!Ie.some(Je=>Je.isIntersecting)||!re||ie||Ae||X()},{root:null,rootMargin:"280px 0px"});return Le.observe(ve),()=>Le.disconnect()},[X,re,Ae,ie,oe,ue]),!F&&!Z?s.jsx("div",{className:"flex min-h-[58vh] items-center justify-center","data-testid":"linear-source-board",children:s.jsx(Fr,{icon:Bc,message:"Linear is not installed or ready."})}):!Y&&($==null?void 0:$.configured)===!1?s.jsx("div",{className:"flex h-full min-h-0 flex-col px-1","data-testid":"linear-source-board",children:s.jsxs("div",{className:"rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-4 text-sm text-muted-foreground",children:[s.jsx("div",{className:"font-medium text-foreground",children:"Linear is not configured for this organization."}),s.jsx("div",{className:"mt-1",children:$.message??"Connect Linear and choose teams in plugin settings."}),s.jsx(ce,{asChild:!0,variant:"outline",size:"sm",className:"mt-3",children:s.jsx(yt,{to:"/instance/settings/plugins",children:"Open plugin settings"})})]})}):s.jsxs("div",{"data-testid":"linear-source-board",className:"flex h-full min-h-0 flex-col gap-4",children:[s.jsxs("div",{"data-testid":"linear-source-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-3",children:[s.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:Ue}),s.jsxs("div",{className:"hidden min-w-0 items-center gap-2 text-xs text-muted-foreground md:flex",children:[s.jsxs("span",{children:[ue," loaded"]}),ct>0?s.jsxs("span",{children:[ct," imported"]}):null,re?s.jsx("span",{children:"Loads as you scroll"}):null]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 sm:gap-1",children:[s.jsxs("div",{className:"flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[s.jsx("button",{className:G("p-1.5 transition-colors",c==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("list"),title:"List view","data-testid":"linear-source-view-list",children:s.jsx(Vz,{className:"h-3.5 w-3.5"})}),s.jsx("button",{className:G("p-1.5 transition-colors",c==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("board"),title:"Board view","data-testid":"linear-source-view-board",children:s.jsx(kme,{className:"h-3.5 w-3.5"})})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:G("text-xs",me>0&&"text-[color:var(--accent-strong)]"),children:[s.jsx($j,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:me>0?`Filters: ${me}`:"Filter"})]})}),s.jsx(Kn,{align:"end",className:"w-72 p-3",children:s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Filters"}),me>0?s.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>{k(""),N("")},children:"Clear"}):null]}),s.jsx(WR,{label:"State",children:s.jsxs("select",{className:ik("h-8 w-full"),value:j,"aria-label":"Filter by Linear state",onChange:ve=>k(ve.target.value),children:[s.jsx("option",{value:"",children:"All states"}),We.map(ve=>s.jsx("option",{value:ve.id,children:ve.name},ve.id))]})}),s.jsx(WR,{label:"Assignee",children:s.jsxs("select",{className:ik("h-8 w-full"),value:w,"aria-label":"Filter by Linear assignee",onChange:ve=>N(ve.target.value),children:[s.jsx("option",{value:"",children:"Anyone"}),((H==null?void 0:H.users)??[]).map(ve=>s.jsx("option",{value:ve.id,children:ve.name},ve.id))]})}),s.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-2.5 py-2 text-xs text-muted-foreground",children:[K," / ",je]})]})})]}),s.jsxs(qn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsxs(ce,{variant:"ghost",size:"sm",className:"text-xs",children:[s.jsx(hP,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),s.jsx(Kn,{align:"end",className:"w-56 p-3",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(WR,{label:"Sort by",children:s.jsxs("select",{className:ik("h-8 w-full"),value:C,"aria-label":"Sort Linear issues",onChange:ve=>A(ve.target.value),children:[s.jsx("option",{value:"updated",children:"Updated"}),s.jsx("option",{value:"created",children:"Created"}),s.jsx("option",{value:"identifier",children:"Identifier"})]})}),s.jsxs(ce,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-full justify-start",title:`Sort ${_==="asc"?"ascending":"descending"}`,onClick:()=>E(ve=>ve==="asc"?"desc":"asc"),children:[s.jsx(hP,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:_==="asc"?"Ascending":"Descending"})]})]})})]})]})]}),s.jsxs("div",{className:"surface-panel flex flex-col gap-3 rounded-[calc(var(--radius-sm)+1px)] px-3 py-2.5 md:flex-row md:items-center md:justify-between",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsxs(ce,{type:"button",variant:"ghost",size:"sm",disabled:Pe.length===0||Ae,onClick:()=>L(Pe.map(ve=>ve.id)),children:[s.jsx($j,{className:"h-3.5 w-3.5"}),"Select loaded"]}),s.jsx(ce,{type:"button",variant:"ghost",size:"sm",disabled:z.length===0||Ae,onClick:()=>L([]),children:"Clear"})]}),s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-end gap-2",children:[s.jsxs("span",{className:"text-xs text-muted-foreground",children:[J," selected"]}),s.jsxs(ce,{type:"button",variant:"outline",size:"sm","data-testid":"linear-source-import-selected",disabled:J===0||Ae,onClick:()=>Ve("selected"),children:[s.jsx(PQ,{className:"h-3.5 w-3.5"}),"Import selected"]}),s.jsx(ce,{type:"button",size:"sm",disabled:ue===0||Ae,onClick:()=>Ve("allMatching"),children:"Import matching"})]})]}),oe?s.jsx(As,{variant:"issues-list"}):null,D?s.jsx("p",{className:"text-sm text-destructive",children:D instanceof Error?D.message:String(D)}):null,!oe&&!D&&ke.length===0?s.jsx("div",{className:"flex min-h-[48vh] items-center justify-center",children:s.jsx(Fr,{icon:Bc,message:"No Linear issues match this source."})}):null,!oe&&!D&&ke.length>0&&c==="list"?s.jsx(K7t,{rows:ke,selectedIssueIds:z,orgId:e,importing:Ae,onToggleSelected:Be}):null,!oe&&!D&&ke.length>0&&c==="board"?s.jsx(V7t,{rows:ke,teamMappings:$==null?void 0:$.teamMappings,selectedIssueIds:z,orgId:e,importing:Ae,onToggleSelected:Be}):null,!oe&&!D&&ke.length>0?s.jsx("div",{ref:Q,"data-testid":"linear-source-load-more-sentinel",className:"flex min-h-8 items-center justify-between gap-3 text-xs text-muted-foreground",children:s.jsxs("span",{children:["Loaded ",ue," issue",ue===1?"":"s",ie?" - loading more":re?" - more load as you scroll":" - all matching issues loaded"]})}):null,s.jsx(Ws,{open:d,onOpenChange:f,children:s.jsxs(ii,{className:"sm:max-w-md",children:[s.jsxs(_a,{children:[s.jsx(Wi,{children:h==="selected"?"Import selected Linear issues":"Import matching Linear issues"}),s.jsxs(Va,{children:["Choose the project in ",ee," where these issues should land."]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("label",{className:"flex flex-col gap-1.5",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Project in ",ee]}),s.jsxs("select",{"data-testid":"linear-source-import-project",className:ik("w-full"),value:b,"aria-label":`Project in ${ee}`,onChange:ve=>v(ve.target.value),children:[s.jsxs("option",{value:"",children:["Choose a project in ",ee]}),he.map(ve=>s.jsx("option",{value:ve.id,children:ve.name},ve.id))]})]}),s.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-3 py-2 text-xs text-muted-foreground",children:[h==="selected"?`${J} selected Linear issue${J===1?"":"s"}`:`All matching Linear issues from ${Ue}`,de?` -> ${de.name}`:""]})]}),s.jsxs(nl,{children:[s.jsx(ce,{type:"button",variant:"outline",onClick:()=>f(!1),children:"Cancel"}),s.jsxs(ce,{type:"button","data-testid":"linear-source-confirm-import",disabled:!b||Ae||h==="selected"&&J===0,onClick:()=>{pe.mutate({mode:h,issueIds:h==="selected"?z:void 0})},children:[s.jsx(PQ,{className:"h-3.5 w-3.5"}),Ae?"Importing":"Import"]})]})]})})]})}function Z7t(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function G7t(e,t){var n;return e.projectId?((n=t==null?void 0:t.find(r=>r.id===e.projectId))==null?void 0:n.name)??null:null}function Q7t(e,t,n){var i;const r=cu(e.assigneeValue||e.assigneeId||"");return r.assigneeAgentId?((i=t==null?void 0:t.find(a=>a.id===r.assigneeAgentId))==null?void 0:i.name)??null:r.assigneeUserId?Ol(r.assigneeUserId,n):null}const Y7t=220;function J7t(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1}function X7t({description:e}){return e?s.jsx("div",{"data-testid":"issue-draft-description-preview",className:"mt-5 max-h-[4.5rem] w-full min-w-0 overflow-hidden",children:s.jsx(Aa,{className:"text-sm leading-6 text-muted-foreground [&_blockquote]:my-0 [&_h1]:my-0 [&_h1]:text-sm [&_h1]:leading-6 [&_h2]:my-0 [&_h2]:text-sm [&_h2]:leading-6 [&_h3]:my-0 [&_h3]:text-sm [&_h3]:leading-6 [&_img]:my-0 [&_img]:max-h-[4.5rem] [&_img]:w-full [&_img]:rounded-[calc(var(--radius-sm)-2px)] [&_img]:object-cover [&_ol]:my-0 [&_p]:my-0 [&_pre]:my-0 [&_ul]:my-0",children:e})}):s.jsx("p",{className:"mt-5 text-sm leading-6 text-muted-foreground",children:"Add description..."})}function e8t({drafts:e,agents:t,projects:n,currentUserId:r,deletingDraftIds:i,onOpenDraft:a,onDeleteDraft:o}){return e.length===0?s.jsx("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col",children:s.jsx(Fr,{icon:j2,message:"No draft issues."})}):s.jsxs("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col overflow-y-auto px-6 py-5",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-3",children:s.jsxs("div",{children:[s.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Draft Issues"}),s.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[e.length," saved draft",e.length===1?"":"s"]})]})}),s.jsx("section",{"aria-label":"Draft issues",className:"grid max-w-5xl grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:e.map(l=>{const c=(i==null?void 0:i.has(l.id))??!1,u=G7t(l,n),d=Q7t(l,t,r),f=[l.status?{key:"status",icon:s.jsx(nc,{className:"h-3 w-3 shrink-0"}),label:Z7t(l.status)}:null,l.priority?{key:"priority",icon:s.jsx(iA,{priority:l.priority,className:"h-3.5 w-4 shrink-0"}),label:Lo(l.priority)}:null,u?{key:"project",icon:s.jsx(r4,{className:"h-3 w-3 shrink-0"}),label:u}:null,d?{key:"assignee",icon:s.jsx(f5,{className:"h-3 w-3 shrink-0"}),label:d}:null,{key:"updated",icon:s.jsx(_p,{className:"h-3 w-3 shrink-0"}),label:js(l.updatedAt)}].filter(h=>!!h);return s.jsxs("article",{"data-testid":"issue-draft-card","data-deleting":c?"true":void 0,"aria-busy":c?"true":void 0,className:"motion-draft-issue-card group relative min-h-36 rounded-[var(--radius-sm)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_88%,transparent)] hover:border-[color:var(--border-strong)] hover:bg-[color:var(--surface-elevated)]",children:[s.jsx("button",{type:"button",disabled:c,"aria-label":`Open draft ${l.title}`,className:"absolute inset-0 z-10 rounded-[var(--radius-sm)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:()=>a(l)}),s.jsxs("div",{className:"pointer-events-none flex h-full min-h-36 w-full flex-col items-start px-4 py-3 text-left",children:[s.jsxs("div",{className:"flex w-full min-w-0 items-start gap-2 pr-9",children:[s.jsx(j2,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:l.title}),s.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:f.map(h=>s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[h.icon,s.jsx("span",{className:"max-w-[11rem] truncate",children:h.label})]},`${l.id}-${h.key}`))})]})]}),s.jsx(X7t,{description:l.description})]}),s.jsx("button",{type:"button","data-testid":"issue-draft-delete-button",disabled:c,"aria-label":`Delete draft ${l.title}`,onClick:h=>{h.preventDefault(),h.stopPropagation(),o(l)},className:"absolute right-3 top-3 z-20 inline-flex h-7 w-7 items-center justify-center rounded-[calc(var(--radius-sm)-2px)] text-muted-foreground opacity-100 transition-colors hover:bg-[color:color-mix(in_oklab,var(--destructive)_16%,transparent)] hover:text-destructive",children:s.jsx(Sa,{className:"h-3.5 w-3.5"})})]},l.id)})})]})}function t8t(){var re,X;const{selectedOrganizationId:e,selectedOrganization:t}=wn(),{setBreadcrumbs:n}=zr(),{openNewIssue:r,confirm:i}=Wr(),{pushToast:a}=_r(),o=Mn(),[l]=Pu(),c=vn(),u=l.get("q")??"",d=l.get("source")??"",f=l.get("scope")??"",h=f==="recent"?"":f,g=h==="drafts",b=d==="linear"&&!g,v=l.get("linearTeamId")??void 0,j=l.get("linearProjectId")??void 0,k=l.get("projectId")??void 0,w=l.get("participantAgentId")??void 0,N=l.get("groupBy"),C=N==="status"||N==="priority"||N==="assignee"||N==="project"||N==="none"?N:void 0,A=x.useRef(void 0),_=x.useCallback(ie=>{clearTimeout(A.current),A.current=setTimeout(()=>{const pe=ie.trim();if((new URLSearchParams(window.location.search).get("q")??"")===pe)return;const Ce=new URL(window.location.href);pe?Ce.searchParams.set("q",pe):Ce.searchParams.delete("q");const $e=`${Ce.pathname}${Ce.search}${Ce.hash}`;window.history.replaceState(window.history.state,"",$e)},300)},[]);x.useEffect(()=>()=>clearTimeout(A.current),[]),x.useEffect(()=>{if(f!=="recent"||typeof window>"u")return;const ie=new URLSearchParams(o.search);ie.delete("scope");const pe=ie.toString(),ke=`${o.pathname}${pe?`?${pe}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ke)},[f,o.hash,o.pathname,o.search]),x.useEffect(()=>{if(!l.has("view")||typeof window>"u")return;const ie=new URLSearchParams(o.search);ie.delete("view");const pe=ie.toString(),ke=`${o.pathname}${pe?`?${pe}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ke)},[o.hash,o.pathname,o.search,l]);const{data:E}=Ne({queryKey:q.agents.list(e),queryFn:()=>Bt.list(e),enabled:!!e}),{data:T}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),M=((re=T==null?void 0:T.user)==null?void 0:re.id)??((X=T==null?void 0:T.session)==null?void 0:X.userId)??null,[O,P]=x.useState(()=>Uj(e)),[z,L]=x.useState(()=>new Set),Q=x.useRef(new Set),{followedIssueIds:ee,toggleFollowIssue:B}=y1e(e),F=x.useCallback((ie,pe)=>{const ke=new Set(Q.current);pe?ke.add(ie):ke.delete(ie),Q.current=ke,L(ke)},[]),{data:Z}=Ne({queryKey:q.projects.list(e),queryFn:()=>ws.list(e),enabled:!!e}),{data:W}=Ne({queryKey:q.liveRuns(e),queryFn:()=>xs.liveRunsForCompany(e),enabled:!!e,refetchInterval:5e3}),$=x.useMemo(()=>{const ie=new Set;for(const pe of W??[])pe.issueId&&ie.add(pe.issueId);return ie},[W]),Y=x.useMemo(()=>Gj("Issues",`${o.pathname}${o.search}${o.hash}`),[o.pathname,o.search,o.hash]);x.useEffect(()=>{n([{label:g?"Draft Issues":b?"Linear Issues":"Issue Tracker"}])},[g,b,n]),x.useEffect(()=>{const ie=()=>{P(Uj(e))};if(ie(),!(typeof window>"u"))return window.addEventListener(t6,ie),window.addEventListener("storage",ie),()=>{window.removeEventListener(t6,ie),window.removeEventListener("storage",ie)}},[e]),x.useEffect(()=>{!e||w||g||b||Zze(e,{scope:h||void 0,projectId:k})},[h,g,b,w,k,e]);const V=x.useMemo(()=>SBe(h,M),[M,h]),{data:H,isLoading:ae,error:le}=Ne({queryKey:[...q.issues.list(e),"participant-agent",w??"__all__","scope",h||"__default__","user",M??"__none__","project",k??"__all__"],queryFn:()=>ln.list(e,{participantAgentId:w,projectId:k,...V}),enabled:!!e&&!g&&!b}),fe=x.useMemo(()=>{const ie=H??[];return h==="starred"?ie.filter(pe=>ee.has(pe.id)):h==="following"&&M?ie.filter(pe=>m1e(pe,M)):ie},[M,h,ee,H]),U=nt({mutationFn:({id:ie,data:pe})=>ln.update(ie,pe),onSuccess:()=>{c.invalidateQueries({queryKey:q.issues.list(e)})}}),xe=nt({mutationFn:ie=>ln.reorder(e,ie),onSuccess:()=>{c.invalidateQueries({queryKey:q.issues.list(e)})}});return e?g?s.jsx(e8t,{drafts:O,agents:E,projects:Z,currentUserId:M,deletingDraftIds:z,onOpenDraft:ie=>{r({draftId:ie.id})},onDeleteDraft:async ie=>{if(!await i({title:`Delete draft issue "${ie.title}"?`,description:"This cannot be undone.",confirmLabel:"Delete",tone:"destructive"})||Q.current.has(ie.id))return;F(ie.id,!0);const ke=()=>{TP(ie.id),F(ie.id,!1),a({title:"Draft issue deleted",tone:"success"})};if(J7t()){ke();return}window.setTimeout(ke,Y7t)}}):b?s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(W7t,{orgId:e,orgName:t==null?void 0:t.name,projects:Z,linearTeamId:v,linearProjectId:j,initialSearch:u})}):s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(P7t,{issues:fe,isLoading:ae,error:le,agents:E,projects:Z,liveIssueIds:$,projectId:k,viewStateKey:"rudder:issues-view",issueLinkState:Y,initialAssignees:l.get("assignee")?[l.get("assignee")]:void 0,initialSearch:u,initialGroupBy:C,toolbarMode:"controls-only",starredIssueIds:[...ee],onToggleStarredIssue:ie=>{B(ie)},onOpenIssue:ie=>{e&&cB(e,ie.id,s3(e))},onSearchChange:_,onUpdateIssue:(ie,pe)=>U.mutate({id:ie,data:pe}),onReorderIssue:ie=>xe.mutate(ie),searchFilters:w?{participantAgentId:w}:void 0})}):s.jsx(Fr,{icon:nc,message:"Select a organization to view issues."})}const n8t="image/*,application/pdf,text/plain,text/markdown,application/json,text/csv,text/html,.md,.markdown",r8t=800;function s8t(e){return e==="done"}function i8t(e){try{return localStorage.getItem(e)??""}catch{return""}}function a8t(e,t){try{t.trim()?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function o8t(e){try{localStorage.removeItem(e)}catch{}}function uie(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function l8t(e){var i;const t=uie((i=uie(e))==null?void 0:i.passiveFollowup),n=typeof(t==null?void 0:t.attempt)=="number"?t.attempt:null,r=typeof(t==null?void 0:t.maxAttempts)=="number"?t.maxAttempts:null;return t?n&&r?`Passive follow-up ${n}/${r}`:"Passive follow-up":null}function c8t({text:e}){const[t,n]=x.useState(!1);return s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors",title:"Copy as markdown",onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:t?s.jsx(gs,{className:"h-3 w-3"}):s.jsx(Ni,{className:"h-3 w-3"})})}const u8t=x.memo(function({timeline:t,agentMap:n,orgId:r,projectId:i,highlightCommentId:a,runTranscriptById:o,runHasOutput:l,operatorDisplayName:c,skillReferences:u,emptyMessage:d}){return t.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:d}):s.jsx("div",{className:"space-y-3",children:t.map(f=>{var b,v,j,k,w,N;if(f.kind==="activity")return s.jsx("div",{children:f.activity.node},`activity:${f.id}`);if(f.kind==="run"){const C=f.run,A=C.status==="queued"||C.status==="running",_=o.get(C.runId)??[],E=l(C.runId),T=l8t(C.contextSnapshot);return s.jsxs("div",{"aria-label":"Agent run output",className:"overflow-hidden rounded-sm border border-dashed border-border bg-muted/35 p-3",children:[s.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[s.jsx(e2,{to:`/agents/${C.agentId}`,className:"hover:underline",children:s.jsx(Za,{name:((b=n==null?void 0:n.get(C.agentId))==null?void 0:b.name)??C.agentId.slice(0,8),icon:(v=n==null?void 0:n.get(C.agentId))==null?void 0:v.icon,role:(j=n==null?void 0:n.get(C.agentId))==null?void 0:j.role,size:"sm"})}),s.jsx("div",{className:"shrink-0 text-right",children:s.jsx("span",{className:"block text-xs text-muted-foreground",children:wi(C.startedAt??C.createdAt)})})]}),s.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2 text-xs",children:[s.jsxs("span",{className:"inline-flex items-center gap-1 font-medium text-muted-foreground",children:[s.jsx(Jz,{className:"h-3.5 w-3.5"}),"Run output"]}),s.jsx(e2,{to:`/agents/${C.agentId}/runs/${C.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/40 px-2 py-1 font-mono text-muted-foreground hover:bg-accent/60 hover:text-foreground transition-colors",children:C.runId.slice(0,8)}),s.jsx(er,{status:C.status}),T&&s.jsx("span",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1 text-[11px] font-medium text-amber-700 dark:text-amber-300",children:T})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto pr-1",children:s.jsx(Qf,{entries:_,density:"compact",limit:4,streaming:A,collapseStdout:!0,emptyMessage:E?"Waiting for transcript parsing...":A?`Run ${C.status}. Waiting for output...`:"No run output captured."})})]},`run:${C.runId}`)}const h=f.comment,g=a===h.id;return s.jsxs("div",{id:`comment-${h.id}`,className:`border p-3 overflow-hidden min-w-0 rounded-sm transition-colors duration-1000 ${g?"border-primary/50 bg-primary/5":"border-border"}`,children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[h.authorAgentId?s.jsx(e2,{to:`/agents/${h.authorAgentId}`,className:"hover:underline",children:s.jsx(Za,{name:((k=n==null?void 0:n.get(h.authorAgentId))==null?void 0:k.name)??h.authorAgentId.slice(0,8),icon:(w=n==null?void 0:n.get(h.authorAgentId))==null?void 0:w.icon,role:(N=n==null?void 0:n.get(h.authorAgentId))==null?void 0:N.role,size:"sm"})}):s.jsx(Da,{name:zK(c),size:"sm"}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[r?s.jsx(y1,{slotTypes:["commentContextMenuItem"],entityType:"comment",context:{orgId:r,projectId:i??null,entityId:h.id,entityType:"comment",parentEntityId:h.issueId},className:"flex flex-wrap items-center gap-1.5",itemClassName:"inline-flex",missingBehavior:"placeholder"}):null,s.jsx("a",{href:`#comment-${h.id}`,className:"text-xs text-muted-foreground hover:text-foreground hover:underline transition-colors",children:wi(h.createdAt)}),s.jsx(c8t,{text:h.body})]})]}),s.jsx(Aa,{className:"text-sm",skillReferences:u,children:h.body}),r?s.jsx("div",{className:"mt-2 space-y-2",children:s.jsx(y1,{slotTypes:["commentAnnotation"],entityType:"comment",context:{orgId:r,projectId:i??null,entityId:h.id,entityType:"comment",parentEntityId:h.issueId},className:"space-y-2",itemClassName:"rounded-md",missingBehavior:"placeholder"})}):null,h.runId&&s.jsx("div",{className:"mt-2 pt-2 border-t border-border/60",children:h.runAgentId?s.jsxs(e2,{to:`/agents/${h.runAgentId}/runs/${h.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors",children:["run ",h.runId.slice(0,8)]}):s.jsxs("span",{className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground",children:["run ",h.runId.slice(0,8)]})})]},h.id)})})});function d8t({comments:e,linkedRuns:t=[],activityItems:n=[],orgId:r,projectId:i,onAdd:a,issueStatus:o,agentMap:l,imageUploadHandler:c,onAttachImage:u,draftKey:d,liveRunSlot:f,mentions:h,operatorDisplayName:g,heading:b,hideHeading:v=!1,emptyMessage:j="No comments or runs yet.",escapeBackWhenEmpty:k=!1}){const[w,N]=x.useState(""),C=s8t(o),[A,_]=x.useState(C),[E,T]=x.useState(!1),[M,O]=x.useState(!1),[P,z]=x.useState(null),L=x.useRef(null),Q=x.useRef(null),ee=x.useRef(null),B=x.useRef(null),F=Mn(),Z=x.useRef(null),W=x.useRef(null),$=x.useMemo(()=>{const re=e.map(ke=>({kind:"comment",id:ke.id,createdAtMs:new Date(ke.createdAt).getTime(),comment:ke})),X=t.map(ke=>({kind:"run",id:ke.runId,createdAtMs:new Date(ke.startedAt??ke.createdAt).getTime(),run:ke})),ie=n.map(ke=>({kind:"activity",id:ke.id,createdAtMs:new Date(ke.createdAt).getTime(),activity:ke})),pe={activity:0,comment:1,run:2};return[...re,...X,...ie].sort((ke,Ce)=>ke.createdAtMs!==Ce.createdAtMs?ke.createdAtMs-Ce.createdAtMs:ke.kind!==Ce.kind?pe[ke.kind]-pe[Ce.kind]:ke.kind===Ce.kind?ke.id.localeCompare(Ce.id):0)},[n,e,t]),Y=x.useMemo(()=>t.map(re=>{var ie;const X=l==null?void 0:l.get(re.agentId);return{id:re.runId,status:re.status,invocationSource:"issue_timeline",triggerDetail:null,startedAt:typeof re.startedAt=="string"?re.startedAt:((ie=re.startedAt)==null?void 0:ie.toISOString())??null,finishedAt:null,createdAt:typeof re.createdAt=="string"?re.createdAt:re.createdAt.toISOString(),agentId:re.agentId,agentName:(X==null?void 0:X.name)??re.agentId.slice(0,8),agentRuntimeType:(X==null?void 0:X.agentRuntimeType)??"process",issueId:null}}),[l,t]),{transcriptByRun:V,hasOutputForRun:H}=o8({runs:Y,orgId:r,maxChunksPerRun:120}),ae=x.useMemo(()=>h||(l?Array.from(l.values()).filter(re=>re.status!=="terminated").map(re=>({id:`agent:${re.id}`,name:rl(re),kind:"agent",agentId:re.id,agentIcon:re.icon,agentRole:re.role})):[]),[l,h]),le=x.useMemo(()=>ae.filter(re=>re.kind==="skill"&&re.skillMarkdownTarget).map(re=>({href:re.skillMarkdownTarget,label:re.skillRefLabel??re.name,displayName:re.skillDisplayName??re.name,description:re.skillDescription,categoryLabel:re.skillCategoryLabel,locationLabel:re.skillLocationLabel,detailsHref:re.skillDetailsHref})),[ae]);x.useEffect(()=>{d&&N(i8t(d))},[d]),x.useEffect(()=>{d&&(B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{a8t(d,w)},r8t))},[w,d]),x.useEffect(()=>()=>{B.current&&clearTimeout(B.current),W.current&&clearTimeout(W.current)},[]),x.useEffect(()=>{_(C)},[C]),x.useEffect(()=>{const re=F.hash;if(!re.startsWith("#comment-")||e.length===0)return;const X=re.slice(9),ie=`${F.key}:${re}`;if(Z.current===ie)return;const pe=document.getElementById(`comment-${X}`);pe&&(Z.current=ie,W.current&&clearTimeout(W.current),z(X),pe.scrollIntoView({behavior:"smooth",block:"center"}),W.current=setTimeout(()=>{z(null),W.current=null},3e3))},[F.hash,F.key,e.length]);async function fe(){const re=w.trim();if(!re)return;const X=C&&A?!0:void 0;T(!0);try{await a(re,X),N(""),d&&o8t(d),_(C)}finally{T(!1)}}async function U(re){var ie;const X=(ie=re.target.files)==null?void 0:ie[0];if(X){O(!0);try{if(c){const pe=await c(X),ke=X.name.replace(/[[\]]/g,"\\$&"),Ce=X.type.startsWith("image/")?``:`[${ke}](${pe})`;N($e=>$e?`${$e}
|
|
1395
1395
|
|