@jean2/client 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -464,4 +464,4 @@ ${n}`:e.content}function O5(e){const n=e.trimStart();if(!n.startsWith("/"))retur
|
|
|
464
464
|
`))+1))}const u="#".repeat(o),f=a.enter("headingAtx"),p=a.enter("phrasing");s.move(u+" ");let m=a.containerPhrasing(e,{before:"# ",after:`
|
|
465
465
|
`,...s.current()});return/^[\t ]/.test(m)&&(m=ms(m.charCodeAt(0))+m.slice(1)),m=m?u+" "+m:u,a.options.closeAtx&&(m+=" "+u),p(),f(),m}iE.peek=Y9;function iE(e){return e.value||""}function Y9(){return"<"}oE.peek=X9;function oE(e,n,a,l){const o=bg(a),s=o==='"'?"Quote":"Apostrophe",u=a.enter("image");let f=a.enter("label");const p=a.createTracker(l);let m=p.move("![");return m+=p.move(a.safe(e.alt,{before:m,after:"]",...p.current()})),m+=p.move("]("),f(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(f=a.enter("destinationLiteral"),m+=p.move("<"),m+=p.move(a.safe(e.url,{before:m,after:">",...p.current()})),m+=p.move(">")):(f=a.enter("destinationRaw"),m+=p.move(a.safe(e.url,{before:m,after:e.title?" ":")",...p.current()}))),f(),e.title&&(f=a.enter(`title${s}`),m+=p.move(" "+o),m+=p.move(a.safe(e.title,{before:m,after:o,...p.current()})),m+=p.move(o),f()),m+=p.move(")"),u(),m}function X9(){return"!"}sE.peek=K9;function sE(e,n,a,l){const o=e.referenceType,s=a.enter("imageReference");let u=a.enter("label");const f=a.createTracker(l);let p=f.move("![");const m=a.safe(e.alt,{before:p,after:"]",...f.current()});p+=f.move(m+"]["),u();const y=a.stack;a.stack=[],u=a.enter("reference");const g=a.safe(a.associationId(e),{before:p,after:"]",...f.current()});return u(),a.stack=y,s(),o==="full"||!m||m!==g?p+=f.move(g+"]"):o==="shortcut"?p=p.slice(0,-1):p+=f.move("]"),p}function K9(){return"!"}cE.peek=Q9;function cE(e,n,a){let l=e.value||"",o="`",s=-1;for(;new RegExp("(^|[^`])"+o+"([^`]|$)").test(l);)o+="`";for(/[^ \r\n]/.test(l)&&(/^[ \r\n]/.test(l)&&/[ \r\n]$/.test(l)||/^`|`$/.test(l))&&(l=" "+l+" ");++s<a.unsafe.length;){const u=a.unsafe[s],f=a.compilePattern(u);let p;if(u.atBreak)for(;p=f.exec(l);){let m=p.index;l.charCodeAt(m)===10&&l.charCodeAt(m-1)===13&&m--,l=l.slice(0,m)+" "+l.slice(p.index+1)}}return o+l+o}function Q9(){return"`"}function uE(e,n){const a=ug(e);return!!(!n.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(a===e.url||"mailto:"+a===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}dE.peek=Z9;function dE(e,n,a,l){const o=bg(a),s=o==='"'?"Quote":"Apostrophe",u=a.createTracker(l);let f,p;if(uE(e,a)){const y=a.stack;a.stack=[],f=a.enter("autolink");let g=u.move("<");return g+=u.move(a.containerPhrasing(e,{before:g,after:">",...u.current()})),g+=u.move(">"),f(),a.stack=y,g}f=a.enter("link"),p=a.enter("label");let m=u.move("[");return m+=u.move(a.containerPhrasing(e,{before:m,after:"](",...u.current()})),m+=u.move("]("),p(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(p=a.enter("destinationLiteral"),m+=u.move("<"),m+=u.move(a.safe(e.url,{before:m,after:">",...u.current()})),m+=u.move(">")):(p=a.enter("destinationRaw"),m+=u.move(a.safe(e.url,{before:m,after:e.title?" ":")",...u.current()}))),p(),e.title&&(p=a.enter(`title${s}`),m+=u.move(" "+o),m+=u.move(a.safe(e.title,{before:m,after:o,...u.current()})),m+=u.move(o),p()),m+=u.move(")"),f(),m}function Z9(e,n,a){return uE(e,a)?"<":"["}fE.peek=W9;function fE(e,n,a,l){const o=e.referenceType,s=a.enter("linkReference");let u=a.enter("label");const f=a.createTracker(l);let p=f.move("[");const m=a.containerPhrasing(e,{before:p,after:"]",...f.current()});p+=f.move(m+"]["),u();const y=a.stack;a.stack=[],u=a.enter("reference");const g=a.safe(a.associationId(e),{before:p,after:"]",...f.current()});return u(),a.stack=y,s(),o==="full"||!m||m!==g?p+=f.move(g+"]"):o==="shortcut"?p=p.slice(0,-1):p+=f.move("]"),p}function W9(){return"["}function vg(e){const n=e.options.bullet||"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bullet`, expected `*`, `+`, or `-`");return n}function J9(e){const n=vg(e),a=e.options.bulletOther;if(!a)return n==="*"?"-":"*";if(a!=="*"&&a!=="+"&&a!=="-")throw new Error("Cannot serialize items with `"+a+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(a===n)throw new Error("Expected `bullet` (`"+n+"`) and `bulletOther` (`"+a+"`) to be different");return a}function eB(e){const n=e.options.bulletOrdered||".";if(n!=="."&&n!==")")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOrdered`, expected `.` or `)`");return n}function pE(e){const n=e.options.rule||"*";if(n!=="*"&&n!=="-"&&n!=="_")throw new Error("Cannot serialize rules with `"+n+"` for `options.rule`, expected `*`, `-`, or `_`");return n}function tB(e,n,a,l){const o=a.enter("list"),s=a.bulletCurrent;let u=e.ordered?eB(a):vg(a);const f=e.ordered?u==="."?")":".":J9(a);let p=n&&a.bulletLastUsed?u===a.bulletLastUsed:!1;if(!e.ordered){const y=e.children?e.children[0]:void 0;if((u==="*"||u==="-")&&y&&(!y.children||!y.children[0])&&a.stack[a.stack.length-1]==="list"&&a.stack[a.stack.length-2]==="listItem"&&a.stack[a.stack.length-3]==="list"&&a.stack[a.stack.length-4]==="listItem"&&a.indexStack[a.indexStack.length-1]===0&&a.indexStack[a.indexStack.length-2]===0&&a.indexStack[a.indexStack.length-3]===0&&(p=!0),pE(a)===u&&y){let g=-1;for(;++g<e.children.length;){const b=e.children[g];if(b&&b.type==="listItem"&&b.children&&b.children[0]&&b.children[0].type==="thematicBreak"){p=!0;break}}}}p&&(u=f),a.bulletCurrent=u;const m=a.containerFlow(e,l);return a.bulletLastUsed=u,a.bulletCurrent=s,o(),m}function nB(e){const n=e.options.listItemIndent||"one";if(n!=="tab"&&n!=="one"&&n!=="mixed")throw new Error("Cannot serialize items with `"+n+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return n}function rB(e,n,a,l){const o=nB(a);let s=a.bulletCurrent||vg(a);n&&n.type==="list"&&n.ordered&&(s=(typeof n.start=="number"&&n.start>-1?n.start:1)+(a.options.incrementListMarker===!1?0:n.children.indexOf(e))+s);let u=s.length+1;(o==="tab"||o==="mixed"&&(n&&n.type==="list"&&n.spread||e.spread))&&(u=Math.ceil(u/4)*4);const f=a.createTracker(l);f.move(s+" ".repeat(u-s.length)),f.shift(u);const p=a.enter("listItem"),m=a.indentLines(a.containerFlow(e,f.current()),y);return p(),m;function y(g,b,w){return b?(w?"":" ".repeat(u))+g:(w?s:s+" ".repeat(u-s.length))+g}}function aB(e,n,a,l){const o=a.enter("paragraph"),s=a.enter("phrasing"),u=a.containerPhrasing(e,l);return s(),o(),u}const lB=Ed(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function iB(e,n,a,l){return(e.children.some(function(u){return lB(u)})?a.containerPhrasing:a.containerFlow).call(a,e,l)}function oB(e){const n=e.options.strong||"*";if(n!=="*"&&n!=="_")throw new Error("Cannot serialize strong with `"+n+"` for `options.strong`, expected `*`, or `_`");return n}mE.peek=sB;function mE(e,n,a,l){const o=oB(a),s=a.enter("strong"),u=a.createTracker(l),f=u.move(o+o);let p=u.move(a.containerPhrasing(e,{after:o,before:f,...u.current()}));const m=p.charCodeAt(0),y=Bu(l.before.charCodeAt(l.before.length-1),m,o);y.inside&&(p=ms(m)+p.slice(1));const g=p.charCodeAt(p.length-1),b=Bu(l.after.charCodeAt(0),g,o);b.inside&&(p=p.slice(0,-1)+ms(g));const w=u.move(o+o);return s(),a.attentionEncodeSurroundingInfo={after:b.outside,before:y.outside},f+p+w}function sB(e,n,a){return a.options.strong||"*"}function cB(e,n,a,l){return a.safe(e.value,l)}function uB(e){const n=e.options.ruleRepetition||3;if(n<3)throw new Error("Cannot serialize rules with repetition `"+n+"` for `options.ruleRepetition`, expected `3` or more");return n}function dB(e,n,a){const l=(pE(a)+(a.options.ruleSpaces?" ":"")).repeat(uB(a));return a.options.ruleSpaces?l.slice(0,-1):l}const hE={blockquote:D9,break:i1,code:F9,definition:H9,emphasis:lE,hardBreak:i1,heading:G9,html:iE,image:oE,imageReference:sE,inlineCode:cE,link:dE,linkReference:fE,list:tB,listItem:rB,paragraph:aB,root:iB,strong:mE,text:cB,thematicBreak:dB};function fB(){return{enter:{table:pB,tableData:o1,tableHeader:o1,tableRow:hB},exit:{codeText:gB,table:mB,tableData:Cm,tableHeader:Cm,tableRow:Cm}}}function pB(e){const n=e._align;this.enter({type:"table",align:n.map(function(a){return a==="none"?null:a}),children:[]},e),this.data.inTable=!0}function mB(e){this.exit(e),this.data.inTable=void 0}function hB(e){this.enter({type:"tableRow",children:[]},e)}function Cm(e){this.exit(e)}function o1(e){this.enter({type:"tableCell",children:[]},e)}function gB(e){let n=this.resume();this.data.inTable&&(n=n.replace(/\\([\\|])/g,yB));const a=this.stack[this.stack.length-1];a.type,a.value=n,this.exit(e)}function yB(e,n){return n==="|"?n:e}function xB(e){const n=e||{},a=n.tableCellPadding,l=n.tablePipeAlign,o=n.stringLength,s=a?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
466
466
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:b,table:u,tableCell:p,tableRow:f}};function u(w,k,S,E){return m(y(w,S,E),w.align)}function f(w,k,S,E){const A=g(w,S,E),N=m([A]);return N.slice(0,N.indexOf(`
|
|
467
|
-
`))}function p(w,k,S,E){const A=S.enter("tableCell"),N=S.enter("phrasing"),j=S.containerPhrasing(w,{...E,before:s,after:s});return N(),A(),j}function m(w,k){return M9(w,{align:k,alignDelimiters:l,padding:a,stringLength:o})}function y(w,k,S){const E=w.children;let A=-1;const N=[],j=k.enter("table");for(;++A<E.length;)N[A]=g(E[A],k,S);return j(),N}function g(w,k,S){const E=w.children;let A=-1;const N=[],j=k.enter("tableRow");for(;++A<E.length;)N[A]=p(E[A],w,k,S);return j(),N}function b(w,k,S){let E=hE.inlineCode(w,k,S);return S.stack.includes("tableCell")&&(E=E.replace(/\|/g,"\\$&")),E}}function bB(){return{exit:{taskListCheckValueChecked:s1,taskListCheckValueUnchecked:s1,paragraph:wB}}}function vB(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:SB}}}function s1(e){const n=this.stack[this.stack.length-2];n.type,n.checked=e.type==="taskListCheckValueChecked"}function wB(e){const n=this.stack[this.stack.length-2];if(n&&n.type==="listItem"&&typeof n.checked=="boolean"){const a=this.stack[this.stack.length-1];a.type;const l=a.children[0];if(l&&l.type==="text"){const o=n.children;let s=-1,u;for(;++s<o.length;){const f=o[s];if(f.type==="paragraph"){u=f;break}}u===a&&(l.value=l.value.slice(1),l.value.length===0?a.children.shift():a.position&&l.position&&typeof l.position.start.offset=="number"&&(l.position.start.column++,l.position.start.offset++,a.position.start=Object.assign({},l.position.start)))}}this.exit(e)}function SB(e,n,a,l){const o=e.children[0],s=typeof e.checked=="boolean"&&o&&o.type==="paragraph",u="["+(e.checked?"x":" ")+"] ",f=a.createTracker(l);s&&f.move(u);let p=hE.listItem(e,n,a,{...l,...f.current()});return s&&(p=p.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,m)),p;function m(y){return y+u}}function kB(){return[t9(),S9(),A9(),fB(),bB()]}function CB(e){return{extensions:[n9(),k9(e),N9(),xB(e),vB()]}}const EB={tokenize:RB,partial:!0},gE={tokenize:MB,partial:!0},yE={tokenize:OB,partial:!0},xE={tokenize:DB,partial:!0},AB={tokenize:zB,partial:!0},bE={name:"wwwAutolink",tokenize:TB,previous:wE},vE={name:"protocolAutolink",tokenize:_B,previous:SE},qr={name:"emailAutolink",tokenize:jB,previous:kE},yr={};function NB(){return{text:yr}}let sl=48;for(;sl<123;)yr[sl]=qr,sl++,sl===58?sl=65:sl===91&&(sl=97);yr[43]=qr;yr[45]=qr;yr[46]=qr;yr[95]=qr;yr[72]=[qr,vE];yr[104]=[qr,vE];yr[87]=[qr,bE];yr[119]=[qr,bE];function jB(e,n,a){const l=this;let o,s;return u;function u(g){return!ah(g)||!kE.call(l,l.previous)||wg(l.events)?a(g):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),f(g))}function f(g){return ah(g)?(e.consume(g),f):g===64?(e.consume(g),p):a(g)}function p(g){return g===46?e.check(AB,y,m)(g):g===45||g===95||Zt(g)?(s=!0,e.consume(g),p):y(g)}function m(g){return e.consume(g),o=!0,p}function y(g){return s&&o&&nn(l.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),n(g)):a(g)}}function TB(e,n,a){const l=this;return o;function o(u){return u!==87&&u!==119||!wE.call(l,l.previous)||wg(l.events)?a(u):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(EB,e.attempt(gE,e.attempt(yE,s),a),a)(u))}function s(u){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),n(u)}}function _B(e,n,a){const l=this;let o="",s=!1;return u;function u(g){return(g===72||g===104)&&SE.call(l,l.previous)&&!wg(l.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(g),e.consume(g),f):a(g)}function f(g){if(nn(g)&&o.length<5)return o+=String.fromCodePoint(g),e.consume(g),f;if(g===58){const b=o.toLowerCase();if(b==="http"||b==="https")return e.consume(g),p}return a(g)}function p(g){return g===47?(e.consume(g),s?m:(s=!0,p)):a(g)}function m(g){return g===null||zu(g)||dt(g)||gl(g)||Sd(g)?a(g):e.attempt(gE,e.attempt(yE,y),a)(g)}function y(g){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),n(g)}}function RB(e,n,a){let l=0;return o;function o(u){return(u===87||u===119)&&l<3?(l++,e.consume(u),o):u===46&&l===3?(e.consume(u),s):a(u)}function s(u){return u===null?a(u):n(u)}}function MB(e,n,a){let l,o,s;return u;function u(m){return m===46||m===95?e.check(xE,p,f)(m):m===null||dt(m)||gl(m)||m!==45&&Sd(m)?p(m):(s=!0,e.consume(m),u)}function f(m){return m===95?l=!0:(o=l,l=void 0),e.consume(m),u}function p(m){return o||l||!s?a(m):n(m)}}function OB(e,n){let a=0,l=0;return o;function o(u){return u===40?(a++,e.consume(u),o):u===41&&l<a?s(u):u===33||u===34||u===38||u===39||u===41||u===42||u===44||u===46||u===58||u===59||u===60||u===63||u===93||u===95||u===126?e.check(xE,n,s)(u):u===null||dt(u)||gl(u)?n(u):(e.consume(u),o)}function s(u){return u===41&&l++,e.consume(u),o}}function DB(e,n,a){return l;function l(f){return f===33||f===34||f===39||f===41||f===42||f===44||f===46||f===58||f===59||f===63||f===95||f===126?(e.consume(f),l):f===38?(e.consume(f),s):f===93?(e.consume(f),o):f===60||f===null||dt(f)||gl(f)?n(f):a(f)}function o(f){return f===null||f===40||f===91||dt(f)||gl(f)?n(f):l(f)}function s(f){return nn(f)?u(f):a(f)}function u(f){return f===59?(e.consume(f),l):nn(f)?(e.consume(f),u):a(f)}}function zB(e,n,a){return l;function l(s){return e.consume(s),o}function o(s){return Zt(s)?a(s):n(s)}}function wE(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||dt(e)}function SE(e){return!nn(e)}function kE(e){return!(e===47||ah(e))}function ah(e){return e===43||e===45||e===46||e===95||Zt(e)}function wg(e){let n=e.length,a=!1;for(;n--;){const l=e[n][1];if((l.type==="labelLink"||l.type==="labelImage")&&!l._balanced){a=!0;break}if(l._gfmAutolinkLiteralWalkedInto){a=!1;break}}return e.length>0&&!a&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),a}const LB={tokenize:VB,partial:!0};function IB(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:UB,continuation:{tokenize:HB},exit:$B}},text:{91:{name:"gfmFootnoteCall",tokenize:FB},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:BB,resolveTo:PB}}}}function BB(e,n,a){const l=this;let o=l.events.length;const s=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let u;for(;o--;){const p=l.events[o][1];if(p.type==="labelImage"){u=p;break}if(p.type==="gfmFootnoteCall"||p.type==="labelLink"||p.type==="label"||p.type==="image"||p.type==="link")break}return f;function f(p){if(!u||!u._balanced)return a(p);const m=er(l.sliceSerialize({start:u.end,end:l.now()}));return m.codePointAt(0)!==94||!s.includes(m.slice(1))?a(p):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),n(p))}}function PB(e,n){let a=e.length;for(;a--;)if(e[a][1].type==="labelImage"&&e[a][0]==="enter"){e[a][1];break}e[a+1][1].type="data",e[a+3][1].type="gfmFootnoteCallLabelMarker";const l={type:"gfmFootnoteCall",start:Object.assign({},e[a+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[a+3][1].end),end:Object.assign({},e[a+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},u={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},f=[e[a+1],e[a+2],["enter",l,n],e[a+3],e[a+4],["enter",o,n],["exit",o,n],["enter",s,n],["enter",u,n],["exit",u,n],["exit",s,n],e[e.length-2],e[e.length-1],["exit",l,n]];return e.splice(a,e.length-a+1,...f),e}function FB(e,n,a){const l=this,o=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let s=0,u;return f;function f(g){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(g),e.exit("gfmFootnoteCallLabelMarker"),p}function p(g){return g!==94?a(g):(e.enter("gfmFootnoteCallMarker"),e.consume(g),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",m)}function m(g){if(s>999||g===93&&!u||g===null||g===91||dt(g))return a(g);if(g===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return o.includes(er(l.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(g),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),n):a(g)}return dt(g)||(u=!0),s++,e.consume(g),g===92?y:m}function y(g){return g===91||g===92||g===93?(e.consume(g),s++,m):m(g)}}function UB(e,n,a){const l=this,o=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let s,u=0,f;return p;function p(k){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),m}function m(k){return k===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",y):a(k)}function y(k){if(u>999||k===93&&!f||k===null||k===91||dt(k))return a(k);if(k===93){e.exit("chunkString");const S=e.exit("gfmFootnoteDefinitionLabelString");return s=er(l.sliceSerialize(S)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return dt(k)||(f=!0),u++,e.consume(k),k===92?g:y}function g(k){return k===91||k===92||k===93?(e.consume(k),u++,y):y(k)}function b(k){return k===58?(e.enter("definitionMarker"),e.consume(k),e.exit("definitionMarker"),o.includes(s)||o.push(s),Je(e,w,"gfmFootnoteDefinitionWhitespace")):a(k)}function w(k){return n(k)}}function HB(e,n,a){return e.check(Os,n,e.attempt(LB,n,a))}function $B(e){e.exit("gfmFootnoteDefinition")}function VB(e,n,a){const l=this;return Je(e,o,"gfmFootnoteDefinitionIndent",5);function o(s){const u=l.events[l.events.length-1];return u&&u[1].type==="gfmFootnoteDefinitionIndent"&&u[2].sliceSerialize(u[1],!0).length===4?n(s):a(s)}}function qB(e){let a=(e||{}).singleTilde;const l={name:"strikethrough",tokenize:s,resolveAll:o};return a==null&&(a=!0),{text:{126:l},insideSpan:{null:[l]},attentionMarkers:{null:[126]}};function o(u,f){let p=-1;for(;++p<u.length;)if(u[p][0]==="enter"&&u[p][1].type==="strikethroughSequenceTemporary"&&u[p][1]._close){let m=p;for(;m--;)if(u[m][0]==="exit"&&u[m][1].type==="strikethroughSequenceTemporary"&&u[m][1]._open&&u[p][1].end.offset-u[p][1].start.offset===u[m][1].end.offset-u[m][1].start.offset){u[p][1].type="strikethroughSequence",u[m][1].type="strikethroughSequence";const y={type:"strikethrough",start:Object.assign({},u[m][1].start),end:Object.assign({},u[p][1].end)},g={type:"strikethroughText",start:Object.assign({},u[m][1].end),end:Object.assign({},u[p][1].start)},b=[["enter",y,f],["enter",u[m][1],f],["exit",u[m][1],f],["enter",g,f]],w=f.parser.constructs.insideSpan.null;w&&_n(b,b.length,0,kd(w,u.slice(m+1,p),f)),_n(b,b.length,0,[["exit",g,f],["enter",u[p][1],f],["exit",u[p][1],f],["exit",y,f]]),_n(u,m-1,p-m+3,b),p=m+b.length-2;break}}for(p=-1;++p<u.length;)u[p][1].type==="strikethroughSequenceTemporary"&&(u[p][1].type="data");return u}function s(u,f,p){const m=this.previous,y=this.events;let g=0;return b;function b(k){return m===126&&y[y.length-1][1].type!=="characterEscape"?p(k):(u.enter("strikethroughSequenceTemporary"),w(k))}function w(k){const S=ki(m);if(k===126)return g>1?p(k):(u.consume(k),g++,w);if(g<2&&!a)return p(k);const E=u.exit("strikethroughSequenceTemporary"),A=ki(k);return E._open=!A||A===2&&!!S,E._close=!S||S===2&&!!A,f(k)}}}class GB{constructor(){this.map=[]}add(n,a,l){YB(this,n,a,l)}consume(n){if(this.map.sort(function(s,u){return s[0]-u[0]}),this.map.length===0)return;let a=this.map.length;const l=[];for(;a>0;)a-=1,l.push(n.slice(this.map[a][0]+this.map[a][1]),this.map[a][2]),n.length=this.map[a][0];l.push(n.slice()),n.length=0;let o=l.pop();for(;o;){for(const s of o)n.push(s);o=l.pop()}this.map.length=0}}function YB(e,n,a,l){let o=0;if(!(a===0&&l.length===0)){for(;o<e.map.length;){if(e.map[o][0]===n){e.map[o][1]+=a,e.map[o][2].push(...l);return}o+=1}e.map.push([n,a,l])}}function XB(e,n){let a=!1;const l=[];for(;n<e.length;){const o=e[n];if(a){if(o[0]==="enter")o[1].type==="tableContent"&&l.push(e[n+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[n-1][1].type==="tableDelimiterMarker"){const s=l.length-1;l[s]=l[s]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(a=!0);n+=1}return l}function KB(){return{flow:{null:{name:"table",tokenize:QB,resolveAll:ZB}}}}function QB(e,n,a){const l=this;let o=0,s=0,u;return f;function f(B){let G=l.events.length-1;for(;G>-1;){const ne=l.events[G][1].type;if(ne==="lineEnding"||ne==="linePrefix")G--;else break}const q=G>-1?l.events[G][1].type:null,me=q==="tableHead"||q==="tableRow"?M:p;return me===M&&l.parser.lazy[l.now().line]?a(B):me(B)}function p(B){return e.enter("tableHead"),e.enter("tableRow"),m(B)}function m(B){return B===124||(u=!0,s+=1),y(B)}function y(B){return B===null?a(B):Re(B)?s>1?(s=0,l.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(B),e.exit("lineEnding"),w):a(B):Ke(B)?Je(e,y,"whitespace")(B):(s+=1,u&&(u=!1,o+=1),B===124?(e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),u=!0,y):(e.enter("data"),g(B)))}function g(B){return B===null||B===124||dt(B)?(e.exit("data"),y(B)):(e.consume(B),B===92?b:g)}function b(B){return B===92||B===124?(e.consume(B),g):g(B)}function w(B){return l.interrupt=!1,l.parser.lazy[l.now().line]?a(B):(e.enter("tableDelimiterRow"),u=!1,Ke(B)?Je(e,k,"linePrefix",l.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(B):k(B))}function k(B){return B===45||B===58?E(B):B===124?(u=!0,e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),S):z(B)}function S(B){return Ke(B)?Je(e,E,"whitespace")(B):E(B)}function E(B){return B===58?(s+=1,u=!0,e.enter("tableDelimiterMarker"),e.consume(B),e.exit("tableDelimiterMarker"),A):B===45?(s+=1,A(B)):B===null||Re(B)?O(B):z(B)}function A(B){return B===45?(e.enter("tableDelimiterFiller"),N(B)):z(B)}function N(B){return B===45?(e.consume(B),N):B===58?(u=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(B),e.exit("tableDelimiterMarker"),j):(e.exit("tableDelimiterFiller"),j(B))}function j(B){return Ke(B)?Je(e,O,"whitespace")(B):O(B)}function O(B){return B===124?k(B):B===null||Re(B)?!u||o!==s?z(B):(e.exit("tableDelimiterRow"),e.exit("tableHead"),n(B)):z(B)}function z(B){return a(B)}function M(B){return e.enter("tableRow"),F(B)}function F(B){return B===124?(e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),F):B===null||Re(B)?(e.exit("tableRow"),n(B)):Ke(B)?Je(e,F,"whitespace")(B):(e.enter("data"),U(B))}function U(B){return B===null||B===124||dt(B)?(e.exit("data"),F(B)):(e.consume(B),B===92?Y:U)}function Y(B){return B===92||B===124?(e.consume(B),U):U(B)}}function ZB(e,n){let a=-1,l=!0,o=0,s=[0,0,0,0],u=[0,0,0,0],f=!1,p=0,m,y,g;const b=new GB;for(;++a<e.length;){const w=e[a],k=w[1];w[0]==="enter"?k.type==="tableHead"?(f=!1,p!==0&&(c1(b,n,p,m,y),y=void 0,p=0),m={type:"table",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(a,0,[["enter",m,n]])):k.type==="tableRow"||k.type==="tableDelimiterRow"?(l=!0,g=void 0,s=[0,0,0,0],u=[0,a+1,0,0],f&&(f=!1,y={type:"tableBody",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(a,0,[["enter",y,n]])),o=k.type==="tableDelimiterRow"?2:y?3:1):o&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")?(l=!1,u[2]===0&&(s[1]!==0&&(u[0]=u[1],g=uu(b,n,s,o,void 0,g),s=[0,0,0,0]),u[2]=a)):k.type==="tableCellDivider"&&(l?l=!1:(s[1]!==0&&(u[0]=u[1],g=uu(b,n,s,o,void 0,g)),s=u,u=[s[1],a,0,0])):k.type==="tableHead"?(f=!0,p=a):k.type==="tableRow"||k.type==="tableDelimiterRow"?(p=a,s[1]!==0?(u[0]=u[1],g=uu(b,n,s,o,a,g)):u[1]!==0&&(g=uu(b,n,u,o,a,g)),o=0):o&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")&&(u[3]=a)}for(p!==0&&c1(b,n,p,m,y),b.consume(n.events),a=-1;++a<n.events.length;){const w=n.events[a];w[0]==="enter"&&w[1].type==="table"&&(w[1]._align=XB(n.events,a))}return e}function uu(e,n,a,l,o,s){const u=l===1?"tableHeader":l===2?"tableDelimiter":"tableData",f="tableContent";a[0]!==0&&(s.end=Object.assign({},di(n.events,a[0])),e.add(a[0],0,[["exit",s,n]]));const p=di(n.events,a[1]);if(s={type:u,start:Object.assign({},p),end:Object.assign({},p)},e.add(a[1],0,[["enter",s,n]]),a[2]!==0){const m=di(n.events,a[2]),y=di(n.events,a[3]),g={type:f,start:Object.assign({},m),end:Object.assign({},y)};if(e.add(a[2],0,[["enter",g,n]]),l!==2){const b=n.events[a[2]],w=n.events[a[3]];if(b[1].end=Object.assign({},w[1].end),b[1].type="chunkText",b[1].contentType="text",a[3]>a[2]+1){const k=a[2]+1,S=a[3]-a[2]-1;e.add(k,S,[])}}e.add(a[3]+1,0,[["exit",g,n]])}return o!==void 0&&(s.end=Object.assign({},di(n.events,o)),e.add(o,0,[["exit",s,n]]),s=void 0),s}function c1(e,n,a,l,o){const s=[],u=di(n.events,a);o&&(o.end=Object.assign({},u),s.push(["exit",o,n])),l.end=Object.assign({},u),s.push(["exit",l,n]),e.add(a+1,0,s)}function di(e,n){const a=e[n],l=a[0]==="enter"?"start":"end";return a[1][l]}const WB={name:"tasklistCheck",tokenize:eP};function JB(){return{text:{91:WB}}}function eP(e,n,a){const l=this;return o;function o(p){return l.previous!==null||!l._gfmTasklistFirstContentOfListItem?a(p):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(p),e.exit("taskListCheckMarker"),s)}function s(p){return dt(p)?(e.enter("taskListCheckValueUnchecked"),e.consume(p),e.exit("taskListCheckValueUnchecked"),u):p===88||p===120?(e.enter("taskListCheckValueChecked"),e.consume(p),e.exit("taskListCheckValueChecked"),u):a(p)}function u(p){return p===93?(e.enter("taskListCheckMarker"),e.consume(p),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),f):a(p)}function f(p){return Re(p)?n(p):Ke(p)?e.check({tokenize:tP},n,a)(p):a(p)}}function tP(e,n,a){return Je(e,l,"whitespace");function l(o){return o===null?a(o):n(o)}}function nP(e){return DC([NB(),IB(),qB(e),KB(),JB()])}const rP={};function aP(e){const n=this,a=e||rP,l=n.data(),o=l.micromarkExtensions||(l.micromarkExtensions=[]),s=l.fromMarkdownExtensions||(l.fromMarkdownExtensions=[]),u=l.toMarkdownExtensions||(l.toMarkdownExtensions=[]);o.push(nP(a)),s.push(kB()),u.push(CB(a))}function CE({children:e,className:n,inverted:a=!1}){return d.jsx("div",{className:ge("markdown-render break-words",n),children:d.jsx(q8,{remarkPlugins:[aP],components:{code({className:l,children:o,...s}){const u=/language-(\w+)/.exec(l||""),f=u?u[1]:"",p=!f,m=Array.isArray(o)?o.join(""):String(o);return!p&&f?d.jsx("div",{className:"w-full max-w-full overflow-x-auto my-2 min-w-0",children:d.jsx(rg,{theme:a?fs.nightOwl:fs.oneDark,code:m.trim(),language:f,children:({className:y,style:g,tokens:b,getLineProps:w,getTokenProps:k})=>d.jsx("pre",{className:ge("rounded-lg text-sm p-3",y),style:g,children:b.map((S,E)=>d.jsx("div",{...w({line:S}),children:S.map((A,N)=>d.jsx("span",{...k({token:A})},N))},E))})})}):d.jsx("code",{className:ge("px-1.5 py-0.5 rounded text-sm font-mono break-all",a?"bg-primary-foreground/20 text-primary-foreground":"bg-muted",l),...s,children:o})},a({href:l,children:o,...s}){return d.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:ge("underline underline-offset-2 transition-colors",a?"text-primary-foreground/80 hover:text-primary-foreground":"text-primary hover:text-primary/80"),...s,children:o})},p({children:l}){return d.jsx("p",{className:"last:mb-0 leading-relaxed wrap-break-words",children:l})},ul({children:l}){return d.jsx("ul",{className:"list-outside list-disc pl-4",children:l})},ol({children:l}){return d.jsx("ol",{className:"list-outside list-decimal pl-4",children:l})},li({children:l,className:o}){const s=o==null?void 0:o.includes("nested");return d.jsx("li",{className:ge("leading-snug",s&&"ml-4"),children:l})},h1({children:l}){return d.jsx("h1",{className:"text-lg font-semibold mb-1.5 mt-3 first:mt-0",children:l})},h2({children:l}){return d.jsx("h2",{className:"text-base font-semibold mb-1.5 mt-2.5 first:mt-0",children:l})},h3({children:l}){return d.jsx("h3",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0",children:l})},blockquote({children:l}){return d.jsx("blockquote",{className:ge("border-l-2 pl-3 my-1.5 italic",a?"border-primary-foreground/40 text-primary-foreground/70":"border-muted-foreground/40 text-muted-foreground"),children:l})},strong({children:l}){return d.jsx("strong",{className:ge("font-semibold",a&&"text-primary-foreground"),children:l})},em({children:l}){return d.jsx("em",{className:"italic",children:l})},hr(){return d.jsx("hr",{className:ge("my-3",a?"border-primary-foreground/30":"border-border")})},table({children:l}){return d.jsx("div",{className:"my-2 overflow-x-auto max-w-full",children:d.jsx("table",{className:"w-full border-collapse text-sm",children:l})})},th({children:l}){return d.jsx("th",{className:ge("border border-border px-2 py-1.5 text-left font-semibold",a?"bg-primary-foreground/10 text-primary-foreground":"bg-muted"),children:l})},td({children:l}){return d.jsx("td",{className:ge("border px-2 py-1.5",a?"border-primary-foreground/20":"border-border"),children:l})}},children:e})})}function lP(e){return e.filter(n=>n.type==="text").map(n=>n.text).join("")}function iP(e,n){const a=n.findIndex(l=>l.message.id===e);if(a<=0)return null;for(let l=a-1;l>=0;l--){const o=n[l];if(o.message.role==="assistant"&&o.message.status!=="streaming")return o.message.id}return null}function oP(e,n){const a=e.map(u=>({message:u.message,parts:u.parts,isQueued:!1})),l=n.map(u=>({message:{id:u.id,role:"user",sessionId:u.sessionId,createdAt:u.createdAt},parts:[{id:`${u.id}-part`,messageId:u.id,createdAt:u.createdAt,type:"text",text:u.content}],isQueued:!0,queueId:u.id})),o=[...a].sort((u,f)=>u.message.createdAt-f.message.createdAt),s=[...l].sort((u,f)=>u.message.createdAt-f.message.createdAt);return[...o,...s]}function sP({part:e}){const[n,a]=v.useState(!1);return d.jsxs("div",{className:"flex flex-col items-center my-4",children:[d.jsxs("button",{onClick:()=>a(!n),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[n?d.jsx(Ci,{className:"size-3"}):d.jsx(Ta,{className:"size-3"}),d.jsxs("span",{className:"border-b border-dashed border-muted-foreground/40 pb-px",children:[e.compactedMessageIds.length," messages compacted"]})]}),n&&d.jsx("div",{className:"mt-2 max-w-lg w-full rounded-lg border border-border bg-muted/50 px-4 py-3 text-sm text-muted-foreground",children:d.jsx(CE,{children:e.summary})})]})}function cP({parts:e,pendingPermissions:n,onPermissionResponse:a,onNavigateToSubagent:l,inverted:o=!1}){const s=[...e].sort((u,f)=>u.createdAt-f.createdAt);return d.jsx(d.Fragment,{children:s.map(u=>{switch(u.type){case"text":return d.jsx("div",{className:"min-w-0",children:d.jsx(CE,{inverted:o,children:u.text||"..."})},u.id);case"reasoning":return d.jsx("div",{className:"text-muted-foreground text-sm italic border-l-2 border-muted-foreground/30 pl-3 my-2 wrap-break-word",children:u.text},u.id);case"tool":return d.jsx(T5,{part:u,pendingPermissions:n,onPermissionResponse:a,onNavigateToSubagent:l},u.id);case"image":return d.jsx("img",{src:u.url,alt:"",className:"max-w-full rounded-lg mt-2"},u.id);case"file":return d.jsx("div",{className:"mt-2 p-2 bg-muted rounded text-sm",children:u.filename||"unnamed"},u.id);default:return null}})})}function uP({session:e,messagesWithParts:n,queuedMessages:a,preconfigs:l,prompts:o,models:s,defaultModel:u,onSendMessage:f,onRemoveFromQueue:p,onChangePreconfig:m,onChangeModel:y,pendingPermissions:g,onPermissionResponse:b,onRename:w,usage:k,modelName:S,onNavigateToSubagent:E,onNavigateBack:A,isStreaming:N,onInterrupt:j,onRevert:O,onFork:z,onCompact:M,isCompacting:F,serverUrl:U,apiToken:Y}){const B=v.useRef(null),[G,q]=v.useState(!0),me=150,ne=oP(n,a);v.useEffect(()=>{q(!0),B.current&&(B.current.scrollTop=B.current.scrollHeight)},[e.id]),v.useEffect(()=>{B.current&&G&&(B.current.scrollTop=B.current.scrollHeight)},[n,G]),v.useEffect(()=>{const I=B.current;if(!I)return;const X=()=>{const{scrollHeight:J,scrollTop:Z,clientHeight:R}=I,D=J-Z-R;q(D<me)};return I.addEventListener("scroll",X,{passive:!0}),()=>I.removeEventListener("scroll",X)},[]);const ee=g.filter(I=>!n.some(X=>X.parts.some(J=>J.type==="tool"&&J.callId===I.toolCallId)));return d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx(c3,{session:e,preconfigs:l,models:s,defaultModel:u,usage:k,modelName:S,onChangePreconfig:m,onChangeModel:y,onRename:w,onNavigateBack:A,isStreaming:N,onInterrupt:j,onCompact:M,isCompacting:F,canCompact:n.length>=4}),e.status==="closed"&&d.jsx(hu,{className:"mx-4 mt-4",children:d.jsx(gu,{children:"This session is archived. You can reopen it from the sidebar."})}),d.jsx(Oa,{className:"flex-1 min-h-0",ref:B,children:d.jsxs("div",{className:"p-4",children:[ne.length===0?d.jsxs("div",{className:"text-center py-16 text-muted-foreground",children:[d.jsx("p",{className:"text-lg mb-2",children:"Start a conversation"}),d.jsx("p",{className:"text-sm",children:"Send a message below to begin."})]}):ne.map(I=>{const X=I.parts.find(R=>R.type==="compaction");if(X)return d.jsx(sP,{part:X},I.message.id);const J=!I.isQueued&&I.message.role==="user",Z=J?iP(I.message.id,n):null;return d.jsx(u3,{message:I.message,textContent:lP(I.parts),isQueued:I.isQueued,onRemove:I.isQueued?()=>p(I.queueId):void 0,canRevert:J&&Z!==null,onRevert:Z?()=>O==null?void 0:O(e.id,Z):void 0,canFork:J&&Z!==null,onFork:Z?()=>z==null?void 0:z(e.id,I.message.id):void 0,children:I.parts.length===0?d.jsx("span",{className:"opacity-50",children:"..."}):d.jsx(cP,{parts:I.parts,pendingPermissions:g,onPermissionResponse:b,onNavigateToSubagent:E,inverted:I.message.role==="user"})},I.message.id)}),ee.length>0&&d.jsx("div",{className:"mt-4 flex flex-col gap-2",children:ee.map(I=>d.jsxs("div",{className:"p-3 bg-warning/10 border border-warning/30 rounded-lg",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx("span",{className:"text-sm font-medium",children:I.toolName}),d.jsx("span",{className:"text-xs text-muted-foreground",children:I.permissionType})]}),d.jsx("p",{className:"text-sm mb-3",children:I.message}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>b(I.toolCallId,!1,!1),children:"Deny"}),d.jsx(Ne,{size:"sm",onClick:()=>b(I.toolCallId,!0,!1),children:"Approve"})]})]},I.toolCallId))})]})}),e.status==="active"&&!e.parentId&&d.jsx(D5,{onSendMessage:f,disabled:F,workspaceId:e.workspaceId,serverUrl:U,apiToken:Y,prompts:o}),e.parentId&&d.jsxs("div",{className:"p-4 border-t border-border bg-muted/50 text-center flex items-center justify-center gap-2 text-sm text-muted-foreground",children:[d.jsx(IN,{className:"size-4"}),"This is a subagent session (read-only)"]})]})}function dP({className:e,orientation:n="horizontal",...a}){return d.jsx(jD,{"data-slot":"tabs","data-orientation":n,className:ge("group/tabs flex gap-2 data-horizontal:flex-col",e),...a})}const fP=Ai("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function pP({className:e,variant:n="default",...a}){return d.jsx(TD,{"data-slot":"tabs-list","data-variant":n,className:ge(fP({variant:n}),e),...a})}function Em({className:e,...n}){return d.jsx(_D,{"data-slot":"tabs-trigger",className:ge("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent","data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",e),...n})}function Am({className:e,...n}){return d.jsx(RD,{"data-slot":"tabs-content",className:ge("flex-1 text-sm outline-none",e),...n})}function u1(e){return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function d1({permission:e,onRevoke:n}){const a=!!e.revokedAt;return d.jsxs("div",{className:"flex items-start justify-between gap-4 py-3 border-b border-border last:border-0",children:[d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(jn,{variant:a?"outline":"secondary",children:[d.jsx(S1,{className:"size-3","data-icon":"inline-start"}),e.permissionType]}),a&&d.jsx(jn,{variant:"outline",className:"text-muted-foreground",children:"Revoked"})]}),d.jsx("p",{className:"text-sm font-mono truncate text-muted-foreground",children:e.permissionKey}),d.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Granted ",u1(e.grantedAt),e.revokedAt&&` • Revoked ${u1(e.revokedAt)}`]})]}),!a&&d.jsx(Ne,{variant:"ghost",size:"icon",onClick:()=>n(e.id),className:"size-8 text-destructive hover:text-destructive",children:d.jsx(gs,{className:"size-4"})})]})}function mP({open:e,onOpenChange:n,title:a,description:l,confirmLabel:o="Confirm",cancelLabel:s="Cancel",variant:u="default",onConfirm:f,onCancel:p}){const m=()=>{p==null||p(),n(!1)},y=()=>{f(),n(!1)};return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[425px]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:a}),d.jsx(_s,{children:l})]}),d.jsxs(hd,{children:[d.jsx(Ne,{variant:"outline",onClick:m,children:s}),d.jsx(Ne,{variant:u==="destructive"?"destructive":"default",onClick:y,children:o})]})]})})}function hP({token:e,onLogout:n}){return d.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-md bg-muted",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[d.jsx("span",{className:"text-muted-foreground",children:"Token:"}),d.jsx("code",{className:"font-mono text-foreground bg-background px-1.5 py-0.5 rounded text-[10px]",children:Mj(e)})]}),d.jsx(Ne,{variant:"destructive",size:"sm",onClick:n,title:"Disconnect and clear token",children:"Logout"})]})}function gP({open:e,onOpenChange:n,permissions:a,onRefreshPermissions:l,onRevokePermission:o,onRevokeAllPermissions:s,apiToken:u,onLogout:f}){const{theme:p,setTheme:m}=HA(),[y,g]=v.useState(!1),b=a.filter(k=>!k.revokedAt),w=a.filter(k=>k.revokedAt);return d.jsxs(Mi,{open:e,onOpenChange:n,children:[d.jsxs(Oi,{className:"sm:max-w-[500px] max-h-[80vh]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:"Settings"}),d.jsx(_s,{children:"Manage your preferences and permissions"})]}),d.jsxs(dP,{defaultValue:"account",className:"mt-4",children:[d.jsxs(pP,{className:"grid w-full grid-cols-3",children:[d.jsx(Em,{value:"account",children:"Account"}),d.jsx(Em,{value:"appearance",children:"Appearance"}),d.jsxs(Em,{value:"permissions",children:[d.jsx(S1,{className:"size-3","data-icon":"inline-start"}),"Permissions",b.length>0&&d.jsx("span",{className:"ml-1.5 px-1.5 py-0.5 text-xs bg-primary text-primary-foreground rounded-full",children:b.length})]})]}),d.jsx(Am,{value:"account",className:"mt-4",children:d.jsx("div",{className:"flex flex-col gap-4",children:d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Session"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Manage your current session"}),u?d.jsx(hP,{token:u,onLogout:f}):d.jsx("p",{className:"text-sm text-muted-foreground",children:"No active session"})]})})}),d.jsx(Am,{value:"appearance",className:"mt-4",children:d.jsx("div",{className:"flex flex-col gap-4",children:d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Theme"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Choose your preferred color scheme"}),d.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[d.jsxs(Ne,{variant:p==="light"?"default":"outline",className:"justify-start",onClick:()=>m("light"),children:[d.jsx(dj,{className:"size-4","data-icon":"inline-start"}),"Light"]}),d.jsxs(Ne,{variant:p==="dark"?"default":"outline",className:"justify-start",onClick:()=>m("dark"),children:[d.jsx(qN,{className:"size-4","data-icon":"inline-start"}),"Dark"]}),d.jsxs(Ne,{variant:p==="system"?"default":"outline",className:"justify-start",onClick:()=>m("system"),children:[d.jsx($N,{className:"size-4","data-icon":"inline-start"}),"System"]})]})]})})}),d.jsx(Am,{value:"permissions",className:"mt-4",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Always-allowed Operations"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Tools you've approved to run without asking"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ne,{variant:"outline",size:"icon",onClick:l,className:"size-8",children:d.jsx(pi,{className:"size-4"})}),b.length>0&&d.jsxs(Ne,{variant:"destructive",size:"sm",onClick:()=>g(!0),children:[d.jsx(gs,{className:"size-4","data-icon":"inline-start"}),"Revoke All"]})]})]}),d.jsx(Ko,{}),d.jsxs(Oa,{className:"h-[300px]",children:[b.length===0&&w.length===0&&d.jsxs("div",{className:"text-center py-8 text-muted-foreground text-sm",children:["No permissions granted yet.",d.jsx("br",{}),'Approve tool requests with "Always allow" to add them here.']}),b.length>0&&d.jsxs("div",{className:"mb-4",children:[d.jsxs("h4",{className:"text-xs uppercase text-muted-foreground mb-2 font-medium",children:["Active (",b.length,")"]}),b.map(k=>d.jsx(d1,{permission:k,onRevoke:o},k.id))]}),w.length>0&&d.jsxs("div",{children:[d.jsxs("h4",{className:"text-xs uppercase text-muted-foreground mb-2 font-medium",children:["Revoked (",w.length,")"]}),w.map(k=>d.jsx(d1,{permission:k,onRevoke:o},k.id))]})]})]})})]})]}),d.jsx(mP,{open:y,onOpenChange:g,title:"Revoke All Permissions",description:"This will revoke all always-allowed permissions for this workspace. You'll need to approve these tools again when they're used.",confirmLabel:"Revoke All",variant:"destructive",onConfirm:()=>{s(),g(!1)}})]})}function yP({status:e}){switch(e.status){case"connected":return d.jsxs(jn,{variant:"default",className:"bg-green-600",children:[d.jsx(hs,{className:"size-3 mr-1"}),"Connected"]});case"disabled":return d.jsxs(jn,{variant:"secondary",children:[d.jsx(Fu,{className:"size-3 mr-1"}),"Disabled"]});case"failed":return d.jsxs(jn,{variant:"destructive",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Failed"]});case"needs_auth":return d.jsxs(jn,{variant:"outline",className:"border-yellow-500 text-yellow-600",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Needs Auth"]});case"needs_client_registration":return d.jsxs(jn,{variant:"outline",className:"border-orange-500 text-orange-600",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Needs Registration"]});default:return d.jsx(jn,{variant:"secondary",children:"Unknown"})}}function xP({open:e,onOpenChange:n,workspaceId:a,workspacePath:l,serverUrl:o,apiToken:s}){const{fetchWithAuth:u}=Ts(),[f,p]=v.useState({}),[m,y]=v.useState(!1),[g,b]=v.useState(null),[w,k]=v.useState(null),S=v.useCallback(async()=>{if(a){y(!0),k(null);try{const O=await u(`/api/workspaces/${a}/mcp/status`,{},{serverUrl:o,token:s});if(!O.ok)throw new Error("Failed to load MCP status");const z=await O.json();p(z.status||{})}catch(O){const z=O instanceof Error?O.message:"Unknown error";k(z)}finally{y(!1)}}},[a,u,o,s]);v.useEffect(()=>{e&&a&&S()},[e,a,S]);const E=async O=>{if(a){b(O);try{if(!(await u(`/api/workspaces/${a}/mcp/connect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s})).ok)throw new Error("Failed to connect");await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},A=async O=>{if(a){b(O);try{if(!(await u(`/api/workspaces/${a}/mcp/disconnect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s})).ok)throw new Error("Failed to disconnect");await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},N=async O=>{if(a){b(O);try{const z=await u(`/api/workspaces/${a}/mcp/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s});if(!z.ok)throw new Error("Failed to start auth");const M=await z.json();M.authorizationUrl&&window.open(M.authorizationUrl,"_blank"),await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},j=Object.entries(f);return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[600px] max-h-[80vh]",children:[d.jsxs(Di,{children:[d.jsxs(zi,{className:"flex items-center gap-2",children:[d.jsx(ul,{className:"size-5"}),"MCP Servers"]}),d.jsx(_s,{children:"Manage Model Context Protocol servers for this workspace"})]}),d.jsxs("div",{className:"mt-4 space-y-4",children:[w&&d.jsxs(hu,{variant:"destructive",children:[d.jsx(Qo,{className:"size-4"}),d.jsx(gu,{children:w})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure servers in ",d.jsx("code",{className:"text-xs bg-muted px-1 rounded",children:".jean2/mcp.json"})]}),d.jsx(Ne,{variant:"outline",size:"sm",onClick:S,disabled:m,children:d.jsx(pi,{className:`size-4 ${m?"animate-spin":""}`})})]}),d.jsx(Oa,{className:"h-[400px]",children:m&&j.length===0?d.jsx("div",{className:"flex items-center justify-center py-8",children:d.jsx(Vn,{className:"size-6 animate-spin text-muted-foreground"})}):j.length===0?d.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[d.jsx(ul,{className:"size-12 mx-auto mb-3 opacity-50"}),d.jsx("p",{className:"font-medium",children:"No MCP servers configured"}),d.jsxs("p",{className:"text-sm mt-1",children:["Create ",d.jsx("code",{className:"text-xs bg-muted px-1 rounded",children:".jean2/mcp.json"})," in your workspace to add servers."]})]}):d.jsx("div",{className:"space-y-3",children:j.map(([O,{config:z,status:M}])=>{var F;return d.jsxs("div",{className:"border rounded-lg p-4",children:[d.jsxs("div",{className:"flex items-start justify-between",children:[d.jsxs("div",{className:"flex items-start gap-3",children:[d.jsx(ul,{className:"size-5 text-muted-foreground mt-0.5"}),d.jsxs("div",{children:[d.jsx("div",{className:"font-medium",children:O}),d.jsx("div",{className:"text-sm text-muted-foreground",children:(z==null?void 0:z.type)==="local"?d.jsxs("span",{children:["Local - ",((F=z.command)==null?void 0:F[0])||"command"]}):(z==null?void 0:z.type)==="remote"?d.jsxs("span",{className:"flex items-center gap-1",children:["Remote - ",z.url]}):"Unknown type"}),M.status==="failed"&&"error"in M&&d.jsx(hu,{variant:"destructive",className:"mt-2 py-2",children:d.jsx(gu,{className:"text-xs",children:M.error})}),M.status==="needs_client_registration"&&"error"in M&&d.jsx(hu,{className:"mt-2 py-2 border-orange-500",children:d.jsx(gu,{className:"text-xs",children:M.error})})]})]}),d.jsx("div",{className:"flex items-center gap-2",children:d.jsx(yP,{status:M})})]}),d.jsxs("div",{className:"flex items-center gap-2 mt-3 pt-3 border-t",children:[M.status==="connected"&&d.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>A(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(KN,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Disconnect"})]}),(M.status==="disabled"||M.status==="failed")&&d.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>E(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(ZN,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Connect"})]}),M.status==="needs_auth"&&d.jsxs(Ne,{variant:"default",size:"sm",onClick:()=>N(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(jm,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Authenticate"})]})]})]},O)})})})]})]})})}function f1({message:e="Connecting to server..."}){return d.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-muted-foreground",children:[d.jsx(Vn,{className:"size-8 animate-spin"}),d.jsx("p",{className:"text-sm",children:e})]})}const bP=({serverUrl:e,authError:n,retryCount:a,nextRetryIn:l,onRetry:o,onLogout:s})=>d.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] px-4 text-center",children:[d.jsx(C1,{className:"size-12 text-destructive mb-4"}),d.jsx("h2",{className:"text-xl font-semibold text-foreground mb-2",children:"Unable to connect to server"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-[400px]",children:n||"Please check that the server is running."}),e&&d.jsx("p",{className:"text-xs text-muted-foreground mb-6 font-mono bg-muted px-3 py-1.5 rounded",children:e}),d.jsxs("div",{className:"flex flex-col items-center gap-4",children:[d.jsxs("p",{className:"text-sm text-muted-foreground",children:["Retrying in ",l,"s..."]}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs(Ne,{onClick:o,variant:"default",children:[d.jsx(pi,{className:"size-4 mr-2","data-icon":"inline-start"}),"Retry Now"]}),d.jsx(Ne,{onClick:s,variant:"ghost",children:"Change Server"})]}),a>0&&d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Retry attempt: ",a]})]})]});function p1({onServerAdded:e,error:n}){const[a,l]=v.useState(""),[o,s]=v.useState(""),[u,f]=v.useState(""),[p,m]=v.useState(!1),[y,g]=v.useState(null),b=w=>{w.preventDefault();const k=a.trim(),S=o.trim(),E=u.trim();if(!k){g("Please enter a server name");return}if(!S){g("Please enter a server URL");return}if(!E){g("Please enter an API token");return}if(!A1(E)){g("Invalid token format. Token should be 64 hex characters (0-9, a-f).");return}const A=bu(S),N={id:crypto.randomUUID(),name:k,url:A,token:E,createdAt:new Date().toISOString()};e(N)};return d.jsx("div",{className:"w-full h-full flex items-center justify-center bg-background dark:bg-gradient-to-br dark:from-muted dark:via-background dark:to-muted p-4",children:d.jsx("div",{className:"w-full max-w-md",children:d.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl overflow-hidden",children:[d.jsxs("div",{className:"px-6 pt-6 pb-4 text-center border-b border-border",children:[d.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Add your first server"}),d.jsx("p",{className:"text-muted-foreground mt-1",children:"Connect to a Jean2 server to get started"})]}),d.jsxs("form",{onSubmit:b,className:"p-6 space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"serverName",className:"text-sm font-medium text-foreground",children:"Server Name"}),d.jsx("input",{id:"serverName",type:"text",value:a,onChange:w=>{l(w.target.value),g(null)},placeholder:"Production",className:"w-full px-3 py-2 bg-background border border-input rounded-lg text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"serverUrl",className:"text-sm font-medium text-foreground",children:"Server URL"}),d.jsx("input",{id:"serverUrl",type:"text",value:o,onChange:w=>{s(w.target.value),g(null)},placeholder:"localhost:3000",className:"w-full px-3 py-2 bg-background border border-input rounded-lg text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"token",className:"text-sm font-medium text-foreground",children:"API Token"}),d.jsxs("div",{className:"relative",children:[d.jsx("input",{id:"token",type:p?"text":"password",value:u,onChange:w=>{f(w.target.value),g(null)},placeholder:"Enter your 64-character token",className:"w-full px-3 py-2 pr-10 bg-background border border-input rounded-lg text-foreground font-mono text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"}),d.jsx("button",{type:"button",onClick:()=>m(!p),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground transition-colors","aria-label":p?"Hide token":"Show token",children:p?d.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})}):d.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]}),(y||n)&&d.jsx("div",{className:"px-3 py-2 bg-destructive/10 border border-destructive/20 rounded-lg text-destructive text-sm",children:y||n}),d.jsx("button",{type:"submit",className:"w-full py-2.5 bg-primary text-primary-foreground font-medium rounded-lg hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 transition-colors",children:"Add Server"})]})]})})})}function m1({onServerSwitch:e,onSelectWorkspace:n}){const[a,l]=v.useState(!1),o=v.useRef(!1),s=bd(),{quickConnections:u,switchServer:f,removeFromQuickConnections:p,isSwitching:m}=Ei(),y=w=>{f(w.serverId)&&(o.current=!0,e==null||e(),w.workspaceId&&n&&n(w.workspaceId))};v.useEffect(()=>{!m&&a&&o.current&&(l(!1),o.current=!1)},[m,a]);const g=(w,k)=>{w.stopPropagation(),p(k)},b=()=>d.jsx(Yh,{children:d.jsx(Xh,{className:"max-h-[50vh] overflow-y-auto",children:u.length>0?d.jsx(ls,{heading:"Quick Switch",children:u.map(w=>d.jsxs(gi,{onSelect:()=>y(w),className:"justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(ul,{className:"size-4 text-muted-foreground"}),d.jsxs("span",{children:[w.serverName,w.workspaceName&&d.jsxs("span",{className:"text-muted-foreground",children:[" / ",w.workspaceName]})]})]}),d.jsx("button",{className:"opacity-0 group-hover:opacity-100 hover:opacity-100 transition-opacity p-1 rounded hover:bg-destructive/10",onClick:k=>g(k,w.id),children:d.jsx(gs,{className:"size-3 text-destructive"})})]},w.id))}):d.jsx(Kh,{className:"py-6",children:d.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[d.jsx($p,{className:"size-8"}),d.jsx("p",{className:"text-sm font-medium",children:"No favorites yet"}),d.jsx("p",{className:"text-xs",children:"Star a workspace to add it here"})]})})})});return s?d.jsxs(Zh,{open:a,onOpenChange:l,children:[d.jsx(Az,{asChild:!0,children:d.jsx(Ne,{variant:"ghost",size:"icon-sm","aria-label":"Quick switch",children:d.jsx($p,{className:"size-4"})})}),d.jsxs(Wh,{side:"bottom",className:"max-h-[80vh]",children:[d.jsx(Jh,{children:d.jsx(eg,{children:"Quick Switch"})}),d.jsx("div",{className:"mt-4",children:b()})]})]}):d.jsxs(yd,{open:a,onOpenChange:l,children:[d.jsx(Qh,{asChild:!0,children:d.jsx(Ne,{variant:"ghost",size:"icon-sm","aria-label":"Quick switch",children:d.jsx($p,{className:"size-4"})})}),d.jsx(xd,{className:"w-[300px] p-0",align:"start",children:b()})]})}function vP({open:e,onOpenChange:n,editServer:a}){const{addServer:l,editServer:o}=Ei(),[s,u]=v.useState(""),[f,p]=v.useState(""),[m,y]=v.useState(""),[g,b]=v.useState(!1),[w,k]=v.useState(null),S=a!=null;v.useEffect(()=>{a?(u(a.name),p(a.url),y(a.token)):(u(""),p(""),y("")),k(null),b(!1)},[a,e]);const E=A=>{A.preventDefault(),k(null);const N=s.trim(),j=f.trim(),O=m.trim();if(!N){k("Name is required");return}if(!j){k("Server URL is required");return}if(!O){k("API token is required");return}if(!A1(O)){k("Token must be 64 hexadecimal characters");return}const z=bu(j);S?o(a.id,{name:N,url:z,token:O}):l(N,z,O),n(!1)};return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[425px]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:S?"Edit Server":"Add Server"}),d.jsx(_s,{children:S?"Update server details":"Enter your server details"})]}),d.jsxs("form",{onSubmit:E,children:[d.jsxs("div",{className:"grid gap-4 py-4",children:[d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-name",children:"Name"}),d.jsx(mu,{id:"server-name",value:s,onChange:A=>u(A.target.value),placeholder:"My Server"})]}),d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-url",children:"Server URL"}),d.jsx(mu,{id:"server-url",value:f,onChange:A=>p(A.target.value),placeholder:"localhost:3000"})]}),d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-token",children:"API Token"}),d.jsxs("div",{className:"relative",children:[d.jsx(mu,{id:"server-token",type:g?"text":"password",value:m,onChange:A=>y(A.target.value),placeholder:"64-character hex string",className:"pr-10"}),d.jsx("button",{type:"button",onClick:()=>b(!g),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-transparent",children:g?d.jsx(kN,{className:"size-4 text-muted-foreground"}):d.jsx(EN,{className:"size-4 text-muted-foreground"})})]})]}),w&&d.jsx("p",{className:"text-sm text-destructive",children:w})]}),d.jsxs(hd,{children:[d.jsx(Ne,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancel"}),d.jsx(Ne,{type:"submit",children:S?"Save":"Add"})]})]})]})})}const wP=(e,n)=>e&&n?`ws://${n}/ws?token=${e}`:null,Nm=e=>e?`http://${e}/api`:null;function SP(){var Fs,Xi,Ki,Us;const{servers:e,activeServer:n,addServer:a,removeServer:l,isSwitching:o,clearSwitchingState:s}=Ei(),[u,f]=v.useState([]),[p,m]=v.useState([]),[y,g]=v.useState([]),[b,w]=v.useState(null),[k,S]=v.useState({}),[E,A]=v.useState({}),[N,j]=v.useState(null),O=v.useRef(null),[z,M]=v.useState(!1),[F,U]=v.useState(null),[Y,B]=v.useState({promptTokens:0,completionTokens:0,totalTokens:0}),[G,q]=v.useState("gpt-4o"),[me,ne]=v.useState([]),[ee,I]=v.useState("gpt-4o"),[X,J]=v.useState([]),[Z,R]=v.useState(null),[D,L]=v.useState(!1),[T,te]=v.useState(!1),[ae,le]=v.useState(!1),[ie,be]=v.useState([]),[he,Te]=v.useState([]),[ze,Le]=v.useState({}),[ft,et]=v.useState(null),[Dt,Vt]=v.useState(!1),[Mn,Gr]=v.useState(null),[an,ln]=v.useState(!1),[on,xr]=v.useState(0),[Bi,vt]=v.useState(0),[Pi,se]=v.useState(0),xe=(Fs=b==null?void 0:b.compacting)!=null?Fs:!1,Oe=1e4,He=3e4,tt=1e3,zt=v.useRef(null),sn=v.useRef(null),[qt,yt]=v.useState(!1),Ge=(Xi=n==null?void 0:n.token)!=null?Xi:null,De=(Ki=n==null?void 0:n.url)!=null?Ki:null;v.useEffect(()=>{O.current=N},[N]);const yn=v.useRef(null),Jt=v.useRef(!1),zs=v.useCallback(H=>{a(H.name,H.url,H.token)},[a]),On=v.useCallback(()=>{n&&l(n.id),O.current&&O.current.close(),j(null),M(!1),ln(!1),xr(0),vt(0)},[n,l]),Sl=v.useCallback(()=>{xr(H=>H+1),ln(!1),vt(0)},[]),Yr=v.useCallback(()=>{O.current&&O.current.close(),j(null),M(!1),ln(!1),xr(0),vt(0),f([]),m([]),w(null),S({}),A({}),U(null),B({promptTokens:0,completionTokens:0,totalTokens:0}),q("gpt-4o"),ne([]),J([]),R(null),be([]),Te([]),Le({}),se(H=>H+1)},[]),Gt=v.useCallback(async(H,we={})=>{if(!Ge)throw new Error("No API token available");const ce=new Headers(we.headers||{});ce.set("Authorization",`Bearer ${Ge}`);const de=await fetch(H,{...we,signal:we.signal,headers:ce});if(de.status===401)throw et("Authentication failed. Your token may have been regenerated."),On(),new Error("Unauthorized");return de},[Ge,On]),kl=v.useCallback(H=>{const we=k[H]||[],ce=E[H]||{};return we.map(de=>({message:de,parts:(ce[de.id]||[]).sort((Be,St)=>Be.createdAt-St.createdAt)}))},[k,E]);v.useEffect(()=>{if(!Ge||!De)return;const H=wP(Ge,De);if(!H)return;const we=new WebSocket(H);return we.onopen=()=>{M(!0),et(null),xr(0),ln(!1)},we.onclose=ce=>{M(!1),(ce.code===1008||ce.code===401)&&(et("Authentication failed. Please check your token."),On())},we.onerror=ce=>{console.error("WebSocket error:",ce)},we.onmessage=ce=>{var Be;const de=JSON.parse(ce.data);(Be=yn.current)==null||Be.call(yn,de)},j(we),()=>we.close()},[Ge,De,On,Pi]),v.useEffect(()=>{if(Ge&&De&&!z&&!an){const H=setTimeout(()=>{z||ln(!0)},Oe);return()=>clearTimeout(H)}},[Ge,De,z,an]),v.useEffect(()=>{if(an&&!z&&Ge&&De){const H=Math.min(tt*Math.pow(2,on),He);let we=Math.floor(H/1e3);vt(we);const ce=setInterval(()=>{we-=1,vt(Math.max(0,we))},1e3),de=setTimeout(()=>{xr(Be=>Be+1),se(Be=>Be+1)},H);return()=>{clearInterval(ce),clearTimeout(de)}}},[an,z,Ge,De,on]),v.useEffect(()=>{var ce;if(!Ge||!De)return;(ce=zt.current)==null||ce.abort(),zt.current=new AbortController;const H=zt.current.signal,we=Nm(De);if(we)return yt(!0),Promise.all([Gt(`${we}/sessions`,{signal:H}).then(de=>de.json()),Gt(`${we}/preconfigs`,{signal:H}).then(de=>de.json()),Gt(`${we}/prompts`,{signal:H}).then(de=>de.json()),Gt(`${we}/models`,{signal:H}).then(de=>de.json()),Gt(`${we}/workspaces`,{signal:H}).then(de=>de.json())]).then(([de,Be,St,en,Xn])=>{f(de.sessions||[]),m(Be.preconfigs||[]),g(St.prompts||[]),ne(en.models||[]),I(en.defaultModel||"gpt-4o");const Dn=Xn.workspaces||[];if(J(Dn),sn.current){const Cl=Dn.find(Kt=>Kt.id===sn.current);Cl&&R(Cl),sn.current=null}else{const Cl=localStorage.getItem("activeWorkspaceId"),Kt=Dn.find(Qi=>Qi.id===Cl);R(Kt||Dn[0])}s(),yt(!1)}).catch(de=>{var Be;if(de.name==="AbortError"){console.log("Fetch aborted due to server switch");return}console.error("Failed to load server data:",de),yt(!1),(Be=de.message)!=null&&Be.includes("Unauthorized")||et("Failed to connect to server")}),()=>{var de;(de=zt.current)==null||de.abort()}},[Ge,De,Gt,s]),v.useEffect(()=>{Z&&localStorage.setItem("activeWorkspaceId",Z.id)},[Z]);const Xr=async(H,we,ce)=>{const de=Nm(De);if(!de)return;const St=await(await Gt(`${de}/workspaces`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:H,path:we,isVirtual:ce})})).json();return J(en=>[...en,St.workspace]),St.workspace},Nd=H=>{R(H),w(null)},Fi=H=>{sn.current=H},Ui=async H=>{const we=Nm(De);we&&(await Gt(`${we}/workspaces/${H}`,{method:"DELETE"}),J(ce=>ce.filter(de=>de.id!==H)),(Z==null?void 0:Z.id)===H&&R(X[0]||null))},Ua=async()=>{const H=`Workspace ${X.length+1}`,we=`~/.jean2/workspaces/${crypto.randomUUID()}`;await Xr(H,we,!0)},jd=async H=>{const we=H.split("/").pop()||H.split("\\").pop()||"Workspace";await Xr(we,H,!1)},Hi=v.useCallback(H=>{var we;switch(H.type){case"session.created":f(ce=>[H.session,...ce]),Jt.current&&(w(H.session),S(ce=>({...ce,[H.session.id]:[]})),A(ce=>({...ce,[H.session.id]:{}})),B({promptTokens:0,completionTokens:0,totalTokens:0}),q(ee),Jt.current=!1);break;case"session.resumed":w(H.session),H.isRunning&&U(H.session.id),H.messages&&(S(ce=>({...ce,[H.session.id]:H.messages.map(de=>de.message)})),A(ce=>{const de={...ce};de[H.session.id]={};for(const Be of H.messages)de[H.session.id][Be.message.id]=Be.parts;return de})),B((we=H.usage)!=null?we:{promptTokens:0,completionTokens:0,totalTokens:0}),q(H.session.selectedModel||ee);break;case"message.created":S(ce=>({...ce,[H.message.sessionId]:[...ce[H.message.sessionId]||[],H.message]})),A(ce=>({...ce,[H.message.sessionId]:{...ce[H.message.sessionId],[H.message.id]:[]}})),"status"in H.message&&H.message.status==="streaming"&&U(H.message.sessionId);break;case"message.updated":S(ce=>({...ce,[H.message.sessionId]:(ce[H.message.sessionId]||[]).map(de=>de.id===H.message.id?H.message:de)})),"status"in H.message&&H.message.status!=="streaming"&&U(ce=>ce===H.message.sessionId?null:ce);break;case"part.created":A(ce=>{const de=ce[H.sessionId]||{},Be=de[H.part.messageId]||[];return{...ce,[H.sessionId]:{...de,[H.part.messageId]:[...Be,H.part]}}});break;case"part.updated":A(ce=>{const de=ce[H.sessionId]||{},Be=de[H.part.messageId]||[];return{...ce,[H.sessionId]:{...de,[H.part.messageId]:Be.map(St=>St.id===H.part.id?H.part:St)}}});break;case"part.append":U(H.sessionId),A(ce=>{const de=ce[H.sessionId]||{};for(const Be of Object.keys(de)){const St=de[Be],en=St.findIndex(Xn=>Xn.id===H.partId);if(en!==-1){const Xn=St[en];if(Xn.type==="text"||Xn.type==="reasoning"){const Dn=[...St];return Dn[en]={...Xn,text:Xn.text+H.delta},{...ce,[H.sessionId]:{...de,[Be]:Dn}}}}}return ce});break;case"chat.usage":if(H.sessionId!==(b==null?void 0:b.id))return;B({promptTokens:H.usage.promptTokens,completionTokens:H.usage.completionTokens,totalTokens:H.usage.totalTokens}),q(H.model);break;case"error":console.error("Server error:",H.code,H.message);break;case"session.closed":f(ce=>ce.map(de=>de.id===H.sessionId?{...de,status:"closed"}:de)),S(ce=>{const de={...ce};return delete de[H.sessionId],de}),A(ce=>{const de={...ce};return delete de[H.sessionId],de}),(b==null?void 0:b.id)===H.sessionId&&w(null);break;case"session.reopened":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"session.deleted":f(ce=>ce.filter(de=>de.id!==H.sessionId)),S(ce=>{const de={...ce};return delete de[H.sessionId],de}),A(ce=>{const de={...ce};return delete de[H.sessionId],de}),(b==null?void 0:b.id)===H.sessionId&&w(null);break;case"session.updated":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"session.renamed":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"permission.list":be(H.permissions);break;case"permission.revoked":be(ce=>ce.map(de=>de.id===H.permissionId?{...de,revokedAt:new Date().toISOString()}:de));break;case"permission.all_revoked":be(ce=>{const de=new Date().toISOString();return ce.map(Be=>({...Be,revokedAt:de}))});break;case"permission.request":{const ce={toolCallId:H.toolCallId,toolName:H.toolName,args:H.args,permissionType:H.permissionType,permissionKey:H.permissionKey,message:H.message,details:H.details,dangerous:H.dangerous,childSessionId:H.childSessionId,subagentName:H.subagentName};Te(de=>[...de,ce]);break}case"permission.granted":Te(ce=>ce.filter(de=>de.toolCallId!==H.toolCallId));break;case"session.interrupted":F===H.sessionId&&U(null),H.result.cascadedTo.length>0&&console.log(`Session ${H.sessionId} interrupted. Cascaded to:`,H.result.cascadedTo);break;case"queue.list":Le(ce=>({...ce,[H.sessionId]:H.messages}));break;case"queue.added":Le(ce=>({...ce,[H.sessionId]:[...ce[H.sessionId]||[],H.message]}));break;case"queue.removed":Le(ce=>({...ce,[H.sessionId]:(ce[H.sessionId]||[]).filter(de=>de.id!==H.queueId)}));break;case"queue.sending":Le(ce=>({...ce,[H.sessionId]:(ce[H.sessionId]||[]).filter(de=>de.id!==H.queueId)}));break;case"session.reverted":console.log(`Session reverted to message ${H.revertedTo.messageId}, removed ${H.removed.messageIds.length} messages`);break;case"compaction.complete":break;case"session.forked":{const{forkedSession:ce,messages:de}=H;f(Be=>[ce,...Be]),S(Be=>({...Be,[ce.id]:de.map(St=>St.message)})),A(Be=>{const St={...Be};St[ce.id]={};for(const en of de)St[ce.id][en.message.id]=en.parts;return St}),w(ce),B({promptTokens:0,completionTokens:0,totalTokens:0});break}case"session.state":S(ce=>({...ce,[H.sessionId]:H.messages.map(de=>de.message)})),A(ce=>{const de={...ce};de[H.sessionId]={};for(const Be of H.messages)de[H.sessionId][Be.message.id]=Be.parts;return de}),F===H.sessionId&&U(null);break}},[b,ee,F]);v.useEffect(()=>{yn.current=Hi},[Hi]),v.useEffect(()=>{const H=async we=>{const ce=we.target;if(!(ce.tagName==="INPUT"||ce.tagName==="TEXTAREA"||ce.isContentEditable)&&(we.metaKey||we.ctrlKey)&&we.key==="n"){we.preventDefault();try{await $A("create_new_window")}catch(Be){console.error("Failed to create new window:",Be)}}};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[]);const $e=v.useCallback((H,we)=>{N&&N.readyState===WebSocket.OPEN&&N.send(JSON.stringify({type:H,...we}))},[N]),Ls=v.useCallback((H,we)=>{Jt.current=!0,$e("session.create",{preconfigId:H,title:we,workspaceId:Z==null?void 0:Z.id})},[$e,Z]),Kr=v.useCallback(H=>{Te([]),U(null),$e("session.resume",{sessionId:H})},[$e]),$i=v.useCallback(H=>{$e("session.close",{sessionId:H})},[$e]),Is=v.useCallback((H,we)=>{$e("session.revert",{sessionId:H,messageId:we})},[$e]),Bs=v.useCallback((H,we)=>{$e("session.fork",{sessionId:H,messageId:we})},[$e]),ar=v.useCallback((H,we)=>{$e("session.compact",{sessionId:H,messageIds:we})},[$e]),_t=v.useCallback(H=>{$e("session.reopen",{sessionId:H})},[$e]),Yt=v.useCallback(H=>{$e("session.delete",{sessionId:H})},[$e]),Qr=v.useCallback(H=>{b&&$e("session.update",{sessionId:b.id,preconfigId:H})},[b,$e]),Vi=v.useCallback((H,we)=>{b&&$e("session.update_model",{sessionId:b.id,modelId:H,providerId:we})},[b,$e]),Td=v.useCallback((H,we)=>{$e("session.rename",{sessionId:H,title:we})},[$e]),_d=v.useCallback(()=>{b!=null&&b.parentId&&Kr(b.parentId)},[b,Kr]),qi=v.useCallback((H,we)=>{$e("queue.add",{sessionId:H,content:we})},[$e]),Ha=v.useCallback(H=>{$e("queue.remove",{queueId:H})},[$e]),Gi=v.useCallback(H=>{!b||xe||(F===b.id?qi(b.id,H):$e("chat.message",{sessionId:b.id,content:H}))},[b,F,xe,$e,qi]),Zr=v.useCallback((H,we,ce)=>{Te(de=>de.filter(Be=>Be.toolCallId!==H)),$e("permission.response",{toolCallId:H,allowed:we,alwaysAllow:ce})},[$e]),Wr=v.useCallback(()=>{b&&$e("session.interrupt",{sessionId:b.id})},[b,$e]),$a=v.useCallback(()=>{Z&&$e("permission.list",{workspaceId:Z.id})},[Z,$e]),Jr=u.filter(H=>H.workspaceId===(Z==null?void 0:Z.id)),wt=b?kl(b.id):[],Yi=p.filter(H=>H.mode!=="subagent"),Ps=!(b!=null&&b.parentId),Xt=!!n,ea=()=>e.length===0?d.jsx(p1,{onServerAdded:zs,error:ft||void 0}):Xt?o?d.jsx("div",{className:"flex flex-col w-full h-full items-center justify-center bg-background gap-4",children:d.jsx(f1,{message:`Connecting to ${(n==null?void 0:n.name)||"server"}...`})}):!z&&u.length===0?an?d.jsx("div",{className:"flex w-full h-full items-center justify-center bg-background",children:d.jsx(bP,{serverUrl:De,authError:ft,retryCount:on,nextRetryIn:Bi,onRetry:Sl,onLogout:On})}):d.jsxs("div",{className:"flex flex-col w-full h-full items-center justify-center bg-background gap-4",children:[d.jsx(f1,{}),d.jsx(Ne,{variant:"ghost",size:"sm",onClick:On,className:"text-muted-foreground",children:"Change Server"})]}):d.jsx(d.Fragment,{children:b?d.jsx(uP,{session:b,messagesWithParts:wt,queuedMessages:ze[b.id]||[],preconfigs:Ps?Yi:p,prompts:y,models:me,defaultModel:ee,onSendMessage:Gi,onRemoveFromQueue:Ha,onChangePreconfig:Qr,onChangeModel:Vi,pendingPermissions:he,onPermissionResponse:Zr,onRename:Td,usage:Y,modelName:G,onNavigateToSubagent:Kr,onNavigateBack:_d,isStreaming:F===b.id,onInterrupt:Wr,onRevert:Is,onFork:Bs,onCompact:(()=>{const H=wt.filter(we=>we.message.role!=="system"&&!we.parts.some(ce=>ce.type==="compaction"));return H.length>=4?()=>{const we=H.slice(0,H.length-2).map(ce=>ce.message.id);we.length>0&&ar(b.id,we)}:void 0})(),isCompacting:xe,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0}):d.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center text-muted-foreground px-6",children:[d.jsx("h2",{className:"mb-2",children:"Select or create a session"}),d.jsx("p",{children:"Choose a session from the sidebar or create a new one to start chatting."})]})}):d.jsx(p1,{onServerAdded:zs,error:ft||void 0});return d.jsxs(Lz,{defaultOpen:!0,children:[Xt&&d.jsx(Xz,{sessions:Jr,currentSession:b,currentSessionId:(Us=b==null?void 0:b.id)!=null?Us:null,streamingSessionId:F,connected:z,workspaces:X,activeWorkspace:Z,onCreateSession:()=>{var H;return Ls((H=Yi[0])==null?void 0:H.id)},onResumeSession:Kr,onCloseSession:$i,onReopenSession:_t,onDeleteSession:Yt,onSelectWorkspace:Nd,onCreateVirtualWorkspace:Ua,onCreatePhysicalWorkspace:jd,onDeleteWorkspace:Ui,onOpenSettings:()=>L(!0),onOpenMCP:()=>le(!0),onOpenAddServer:()=>Vt(!0),onServerSwitch:Yr}),d.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden",style:{paddingTop:"env(safe-area-inset-top, 0)",paddingBottom:"env(safe-area-inset-bottom, 0)"},children:[d.jsxs("header",{className:"md:hidden flex items-center justify-between p-3 border-b border-border bg-background sticky top-0 z-10",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(o0,{}),d.jsx("span",{className:"font-semibold",children:"Jean2"})]}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(m1,{onServerSwitch:Yr,onSelectWorkspace:Fi}),Xt&&Z&&d.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>te(!T),title:T?"Hide Files":"Show Files",children:d.jsx(Tm,{className:"w-4 h-4"})})]})]}),d.jsxs("header",{className:"hidden md:flex items-center justify-between p-3 border-b border-border",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(o0,{}),d.jsx("span",{className:"font-semibold",children:"Jean2"})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(m1,{onServerSwitch:Yr,onSelectWorkspace:Fi}),Xt&&Z&&d.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>te(!T),title:T?"Hide Files":"Show Files",children:d.jsx(Tm,{className:"w-4 h-4"})})]})]}),ea()]}),Xt&&d.jsxs(d.Fragment,{children:[d.jsx(Zz,{workspaceId:Z==null?void 0:Z.id,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0,isOpen:T,onClose:()=>te(!1)}),d.jsx(gP,{open:D,onOpenChange:L,permissions:ie,onRefreshPermissions:$a,onRevokePermission:H=>{$e("permission.revoke",{permissionId:H})},onRevokeAllPermissions:()=>{$e("permission.revoke_all",{workspaceId:Z==null?void 0:Z.id})},apiToken:Ge,onLogout:On}),d.jsx(xP,{open:ae,onOpenChange:le,workspaceId:Z==null?void 0:Z.id,workspacePath:Z==null?void 0:Z.path,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0})]}),d.jsx(vP,{open:Dt,onOpenChange:H=>{Vt(H),H||Gr(null)},editServer:Mn})]})}function kP(){return d.jsx(Oj,{children:d.jsx(SP,{})})}PA.createRoot(document.getElementById("root")).render(d.jsx(v.StrictMode,{children:d.jsx(UA,{defaultTheme:"dark",storageKey:"jean2-theme",children:d.jsx(kP,{})})}));
|
|
467
|
+
`))}function p(w,k,S,E){const A=S.enter("tableCell"),N=S.enter("phrasing"),j=S.containerPhrasing(w,{...E,before:s,after:s});return N(),A(),j}function m(w,k){return M9(w,{align:k,alignDelimiters:l,padding:a,stringLength:o})}function y(w,k,S){const E=w.children;let A=-1;const N=[],j=k.enter("table");for(;++A<E.length;)N[A]=g(E[A],k,S);return j(),N}function g(w,k,S){const E=w.children;let A=-1;const N=[],j=k.enter("tableRow");for(;++A<E.length;)N[A]=p(E[A],w,k,S);return j(),N}function b(w,k,S){let E=hE.inlineCode(w,k,S);return S.stack.includes("tableCell")&&(E=E.replace(/\|/g,"\\$&")),E}}function bB(){return{exit:{taskListCheckValueChecked:s1,taskListCheckValueUnchecked:s1,paragraph:wB}}}function vB(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:SB}}}function s1(e){const n=this.stack[this.stack.length-2];n.type,n.checked=e.type==="taskListCheckValueChecked"}function wB(e){const n=this.stack[this.stack.length-2];if(n&&n.type==="listItem"&&typeof n.checked=="boolean"){const a=this.stack[this.stack.length-1];a.type;const l=a.children[0];if(l&&l.type==="text"){const o=n.children;let s=-1,u;for(;++s<o.length;){const f=o[s];if(f.type==="paragraph"){u=f;break}}u===a&&(l.value=l.value.slice(1),l.value.length===0?a.children.shift():a.position&&l.position&&typeof l.position.start.offset=="number"&&(l.position.start.column++,l.position.start.offset++,a.position.start=Object.assign({},l.position.start)))}}this.exit(e)}function SB(e,n,a,l){const o=e.children[0],s=typeof e.checked=="boolean"&&o&&o.type==="paragraph",u="["+(e.checked?"x":" ")+"] ",f=a.createTracker(l);s&&f.move(u);let p=hE.listItem(e,n,a,{...l,...f.current()});return s&&(p=p.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,m)),p;function m(y){return y+u}}function kB(){return[t9(),S9(),A9(),fB(),bB()]}function CB(e){return{extensions:[n9(),k9(e),N9(),xB(e),vB()]}}const EB={tokenize:RB,partial:!0},gE={tokenize:MB,partial:!0},yE={tokenize:OB,partial:!0},xE={tokenize:DB,partial:!0},AB={tokenize:zB,partial:!0},bE={name:"wwwAutolink",tokenize:TB,previous:wE},vE={name:"protocolAutolink",tokenize:_B,previous:SE},qr={name:"emailAutolink",tokenize:jB,previous:kE},yr={};function NB(){return{text:yr}}let sl=48;for(;sl<123;)yr[sl]=qr,sl++,sl===58?sl=65:sl===91&&(sl=97);yr[43]=qr;yr[45]=qr;yr[46]=qr;yr[95]=qr;yr[72]=[qr,vE];yr[104]=[qr,vE];yr[87]=[qr,bE];yr[119]=[qr,bE];function jB(e,n,a){const l=this;let o,s;return u;function u(g){return!ah(g)||!kE.call(l,l.previous)||wg(l.events)?a(g):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),f(g))}function f(g){return ah(g)?(e.consume(g),f):g===64?(e.consume(g),p):a(g)}function p(g){return g===46?e.check(AB,y,m)(g):g===45||g===95||Zt(g)?(s=!0,e.consume(g),p):y(g)}function m(g){return e.consume(g),o=!0,p}function y(g){return s&&o&&nn(l.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),n(g)):a(g)}}function TB(e,n,a){const l=this;return o;function o(u){return u!==87&&u!==119||!wE.call(l,l.previous)||wg(l.events)?a(u):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(EB,e.attempt(gE,e.attempt(yE,s),a),a)(u))}function s(u){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),n(u)}}function _B(e,n,a){const l=this;let o="",s=!1;return u;function u(g){return(g===72||g===104)&&SE.call(l,l.previous)&&!wg(l.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(g),e.consume(g),f):a(g)}function f(g){if(nn(g)&&o.length<5)return o+=String.fromCodePoint(g),e.consume(g),f;if(g===58){const b=o.toLowerCase();if(b==="http"||b==="https")return e.consume(g),p}return a(g)}function p(g){return g===47?(e.consume(g),s?m:(s=!0,p)):a(g)}function m(g){return g===null||zu(g)||dt(g)||gl(g)||Sd(g)?a(g):e.attempt(gE,e.attempt(yE,y),a)(g)}function y(g){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),n(g)}}function RB(e,n,a){let l=0;return o;function o(u){return(u===87||u===119)&&l<3?(l++,e.consume(u),o):u===46&&l===3?(e.consume(u),s):a(u)}function s(u){return u===null?a(u):n(u)}}function MB(e,n,a){let l,o,s;return u;function u(m){return m===46||m===95?e.check(xE,p,f)(m):m===null||dt(m)||gl(m)||m!==45&&Sd(m)?p(m):(s=!0,e.consume(m),u)}function f(m){return m===95?l=!0:(o=l,l=void 0),e.consume(m),u}function p(m){return o||l||!s?a(m):n(m)}}function OB(e,n){let a=0,l=0;return o;function o(u){return u===40?(a++,e.consume(u),o):u===41&&l<a?s(u):u===33||u===34||u===38||u===39||u===41||u===42||u===44||u===46||u===58||u===59||u===60||u===63||u===93||u===95||u===126?e.check(xE,n,s)(u):u===null||dt(u)||gl(u)?n(u):(e.consume(u),o)}function s(u){return u===41&&l++,e.consume(u),o}}function DB(e,n,a){return l;function l(f){return f===33||f===34||f===39||f===41||f===42||f===44||f===46||f===58||f===59||f===63||f===95||f===126?(e.consume(f),l):f===38?(e.consume(f),s):f===93?(e.consume(f),o):f===60||f===null||dt(f)||gl(f)?n(f):a(f)}function o(f){return f===null||f===40||f===91||dt(f)||gl(f)?n(f):l(f)}function s(f){return nn(f)?u(f):a(f)}function u(f){return f===59?(e.consume(f),l):nn(f)?(e.consume(f),u):a(f)}}function zB(e,n,a){return l;function l(s){return e.consume(s),o}function o(s){return Zt(s)?a(s):n(s)}}function wE(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||dt(e)}function SE(e){return!nn(e)}function kE(e){return!(e===47||ah(e))}function ah(e){return e===43||e===45||e===46||e===95||Zt(e)}function wg(e){let n=e.length,a=!1;for(;n--;){const l=e[n][1];if((l.type==="labelLink"||l.type==="labelImage")&&!l._balanced){a=!0;break}if(l._gfmAutolinkLiteralWalkedInto){a=!1;break}}return e.length>0&&!a&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),a}const LB={tokenize:VB,partial:!0};function IB(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:UB,continuation:{tokenize:HB},exit:$B}},text:{91:{name:"gfmFootnoteCall",tokenize:FB},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:BB,resolveTo:PB}}}}function BB(e,n,a){const l=this;let o=l.events.length;const s=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let u;for(;o--;){const p=l.events[o][1];if(p.type==="labelImage"){u=p;break}if(p.type==="gfmFootnoteCall"||p.type==="labelLink"||p.type==="label"||p.type==="image"||p.type==="link")break}return f;function f(p){if(!u||!u._balanced)return a(p);const m=er(l.sliceSerialize({start:u.end,end:l.now()}));return m.codePointAt(0)!==94||!s.includes(m.slice(1))?a(p):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),n(p))}}function PB(e,n){let a=e.length;for(;a--;)if(e[a][1].type==="labelImage"&&e[a][0]==="enter"){e[a][1];break}e[a+1][1].type="data",e[a+3][1].type="gfmFootnoteCallLabelMarker";const l={type:"gfmFootnoteCall",start:Object.assign({},e[a+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[a+3][1].end),end:Object.assign({},e[a+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},u={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},f=[e[a+1],e[a+2],["enter",l,n],e[a+3],e[a+4],["enter",o,n],["exit",o,n],["enter",s,n],["enter",u,n],["exit",u,n],["exit",s,n],e[e.length-2],e[e.length-1],["exit",l,n]];return e.splice(a,e.length-a+1,...f),e}function FB(e,n,a){const l=this,o=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let s=0,u;return f;function f(g){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(g),e.exit("gfmFootnoteCallLabelMarker"),p}function p(g){return g!==94?a(g):(e.enter("gfmFootnoteCallMarker"),e.consume(g),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",m)}function m(g){if(s>999||g===93&&!u||g===null||g===91||dt(g))return a(g);if(g===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return o.includes(er(l.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(g),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),n):a(g)}return dt(g)||(u=!0),s++,e.consume(g),g===92?y:m}function y(g){return g===91||g===92||g===93?(e.consume(g),s++,m):m(g)}}function UB(e,n,a){const l=this,o=l.parser.gfmFootnotes||(l.parser.gfmFootnotes=[]);let s,u=0,f;return p;function p(k){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),m}function m(k){return k===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",y):a(k)}function y(k){if(u>999||k===93&&!f||k===null||k===91||dt(k))return a(k);if(k===93){e.exit("chunkString");const S=e.exit("gfmFootnoteDefinitionLabelString");return s=er(l.sliceSerialize(S)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return dt(k)||(f=!0),u++,e.consume(k),k===92?g:y}function g(k){return k===91||k===92||k===93?(e.consume(k),u++,y):y(k)}function b(k){return k===58?(e.enter("definitionMarker"),e.consume(k),e.exit("definitionMarker"),o.includes(s)||o.push(s),Je(e,w,"gfmFootnoteDefinitionWhitespace")):a(k)}function w(k){return n(k)}}function HB(e,n,a){return e.check(Os,n,e.attempt(LB,n,a))}function $B(e){e.exit("gfmFootnoteDefinition")}function VB(e,n,a){const l=this;return Je(e,o,"gfmFootnoteDefinitionIndent",5);function o(s){const u=l.events[l.events.length-1];return u&&u[1].type==="gfmFootnoteDefinitionIndent"&&u[2].sliceSerialize(u[1],!0).length===4?n(s):a(s)}}function qB(e){let a=(e||{}).singleTilde;const l={name:"strikethrough",tokenize:s,resolveAll:o};return a==null&&(a=!0),{text:{126:l},insideSpan:{null:[l]},attentionMarkers:{null:[126]}};function o(u,f){let p=-1;for(;++p<u.length;)if(u[p][0]==="enter"&&u[p][1].type==="strikethroughSequenceTemporary"&&u[p][1]._close){let m=p;for(;m--;)if(u[m][0]==="exit"&&u[m][1].type==="strikethroughSequenceTemporary"&&u[m][1]._open&&u[p][1].end.offset-u[p][1].start.offset===u[m][1].end.offset-u[m][1].start.offset){u[p][1].type="strikethroughSequence",u[m][1].type="strikethroughSequence";const y={type:"strikethrough",start:Object.assign({},u[m][1].start),end:Object.assign({},u[p][1].end)},g={type:"strikethroughText",start:Object.assign({},u[m][1].end),end:Object.assign({},u[p][1].start)},b=[["enter",y,f],["enter",u[m][1],f],["exit",u[m][1],f],["enter",g,f]],w=f.parser.constructs.insideSpan.null;w&&_n(b,b.length,0,kd(w,u.slice(m+1,p),f)),_n(b,b.length,0,[["exit",g,f],["enter",u[p][1],f],["exit",u[p][1],f],["exit",y,f]]),_n(u,m-1,p-m+3,b),p=m+b.length-2;break}}for(p=-1;++p<u.length;)u[p][1].type==="strikethroughSequenceTemporary"&&(u[p][1].type="data");return u}function s(u,f,p){const m=this.previous,y=this.events;let g=0;return b;function b(k){return m===126&&y[y.length-1][1].type!=="characterEscape"?p(k):(u.enter("strikethroughSequenceTemporary"),w(k))}function w(k){const S=ki(m);if(k===126)return g>1?p(k):(u.consume(k),g++,w);if(g<2&&!a)return p(k);const E=u.exit("strikethroughSequenceTemporary"),A=ki(k);return E._open=!A||A===2&&!!S,E._close=!S||S===2&&!!A,f(k)}}}class GB{constructor(){this.map=[]}add(n,a,l){YB(this,n,a,l)}consume(n){if(this.map.sort(function(s,u){return s[0]-u[0]}),this.map.length===0)return;let a=this.map.length;const l=[];for(;a>0;)a-=1,l.push(n.slice(this.map[a][0]+this.map[a][1]),this.map[a][2]),n.length=this.map[a][0];l.push(n.slice()),n.length=0;let o=l.pop();for(;o;){for(const s of o)n.push(s);o=l.pop()}this.map.length=0}}function YB(e,n,a,l){let o=0;if(!(a===0&&l.length===0)){for(;o<e.map.length;){if(e.map[o][0]===n){e.map[o][1]+=a,e.map[o][2].push(...l);return}o+=1}e.map.push([n,a,l])}}function XB(e,n){let a=!1;const l=[];for(;n<e.length;){const o=e[n];if(a){if(o[0]==="enter")o[1].type==="tableContent"&&l.push(e[n+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[n-1][1].type==="tableDelimiterMarker"){const s=l.length-1;l[s]=l[s]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(a=!0);n+=1}return l}function KB(){return{flow:{null:{name:"table",tokenize:QB,resolveAll:ZB}}}}function QB(e,n,a){const l=this;let o=0,s=0,u;return f;function f(B){let G=l.events.length-1;for(;G>-1;){const ne=l.events[G][1].type;if(ne==="lineEnding"||ne==="linePrefix")G--;else break}const q=G>-1?l.events[G][1].type:null,me=q==="tableHead"||q==="tableRow"?M:p;return me===M&&l.parser.lazy[l.now().line]?a(B):me(B)}function p(B){return e.enter("tableHead"),e.enter("tableRow"),m(B)}function m(B){return B===124||(u=!0,s+=1),y(B)}function y(B){return B===null?a(B):Re(B)?s>1?(s=0,l.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(B),e.exit("lineEnding"),w):a(B):Ke(B)?Je(e,y,"whitespace")(B):(s+=1,u&&(u=!1,o+=1),B===124?(e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),u=!0,y):(e.enter("data"),g(B)))}function g(B){return B===null||B===124||dt(B)?(e.exit("data"),y(B)):(e.consume(B),B===92?b:g)}function b(B){return B===92||B===124?(e.consume(B),g):g(B)}function w(B){return l.interrupt=!1,l.parser.lazy[l.now().line]?a(B):(e.enter("tableDelimiterRow"),u=!1,Ke(B)?Je(e,k,"linePrefix",l.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(B):k(B))}function k(B){return B===45||B===58?E(B):B===124?(u=!0,e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),S):z(B)}function S(B){return Ke(B)?Je(e,E,"whitespace")(B):E(B)}function E(B){return B===58?(s+=1,u=!0,e.enter("tableDelimiterMarker"),e.consume(B),e.exit("tableDelimiterMarker"),A):B===45?(s+=1,A(B)):B===null||Re(B)?O(B):z(B)}function A(B){return B===45?(e.enter("tableDelimiterFiller"),N(B)):z(B)}function N(B){return B===45?(e.consume(B),N):B===58?(u=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(B),e.exit("tableDelimiterMarker"),j):(e.exit("tableDelimiterFiller"),j(B))}function j(B){return Ke(B)?Je(e,O,"whitespace")(B):O(B)}function O(B){return B===124?k(B):B===null||Re(B)?!u||o!==s?z(B):(e.exit("tableDelimiterRow"),e.exit("tableHead"),n(B)):z(B)}function z(B){return a(B)}function M(B){return e.enter("tableRow"),F(B)}function F(B){return B===124?(e.enter("tableCellDivider"),e.consume(B),e.exit("tableCellDivider"),F):B===null||Re(B)?(e.exit("tableRow"),n(B)):Ke(B)?Je(e,F,"whitespace")(B):(e.enter("data"),U(B))}function U(B){return B===null||B===124||dt(B)?(e.exit("data"),F(B)):(e.consume(B),B===92?Y:U)}function Y(B){return B===92||B===124?(e.consume(B),U):U(B)}}function ZB(e,n){let a=-1,l=!0,o=0,s=[0,0,0,0],u=[0,0,0,0],f=!1,p=0,m,y,g;const b=new GB;for(;++a<e.length;){const w=e[a],k=w[1];w[0]==="enter"?k.type==="tableHead"?(f=!1,p!==0&&(c1(b,n,p,m,y),y=void 0,p=0),m={type:"table",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(a,0,[["enter",m,n]])):k.type==="tableRow"||k.type==="tableDelimiterRow"?(l=!0,g=void 0,s=[0,0,0,0],u=[0,a+1,0,0],f&&(f=!1,y={type:"tableBody",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(a,0,[["enter",y,n]])),o=k.type==="tableDelimiterRow"?2:y?3:1):o&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")?(l=!1,u[2]===0&&(s[1]!==0&&(u[0]=u[1],g=uu(b,n,s,o,void 0,g),s=[0,0,0,0]),u[2]=a)):k.type==="tableCellDivider"&&(l?l=!1:(s[1]!==0&&(u[0]=u[1],g=uu(b,n,s,o,void 0,g)),s=u,u=[s[1],a,0,0])):k.type==="tableHead"?(f=!0,p=a):k.type==="tableRow"||k.type==="tableDelimiterRow"?(p=a,s[1]!==0?(u[0]=u[1],g=uu(b,n,s,o,a,g)):u[1]!==0&&(g=uu(b,n,u,o,a,g)),o=0):o&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")&&(u[3]=a)}for(p!==0&&c1(b,n,p,m,y),b.consume(n.events),a=-1;++a<n.events.length;){const w=n.events[a];w[0]==="enter"&&w[1].type==="table"&&(w[1]._align=XB(n.events,a))}return e}function uu(e,n,a,l,o,s){const u=l===1?"tableHeader":l===2?"tableDelimiter":"tableData",f="tableContent";a[0]!==0&&(s.end=Object.assign({},di(n.events,a[0])),e.add(a[0],0,[["exit",s,n]]));const p=di(n.events,a[1]);if(s={type:u,start:Object.assign({},p),end:Object.assign({},p)},e.add(a[1],0,[["enter",s,n]]),a[2]!==0){const m=di(n.events,a[2]),y=di(n.events,a[3]),g={type:f,start:Object.assign({},m),end:Object.assign({},y)};if(e.add(a[2],0,[["enter",g,n]]),l!==2){const b=n.events[a[2]],w=n.events[a[3]];if(b[1].end=Object.assign({},w[1].end),b[1].type="chunkText",b[1].contentType="text",a[3]>a[2]+1){const k=a[2]+1,S=a[3]-a[2]-1;e.add(k,S,[])}}e.add(a[3]+1,0,[["exit",g,n]])}return o!==void 0&&(s.end=Object.assign({},di(n.events,o)),e.add(o,0,[["exit",s,n]]),s=void 0),s}function c1(e,n,a,l,o){const s=[],u=di(n.events,a);o&&(o.end=Object.assign({},u),s.push(["exit",o,n])),l.end=Object.assign({},u),s.push(["exit",l,n]),e.add(a+1,0,s)}function di(e,n){const a=e[n],l=a[0]==="enter"?"start":"end";return a[1][l]}const WB={name:"tasklistCheck",tokenize:eP};function JB(){return{text:{91:WB}}}function eP(e,n,a){const l=this;return o;function o(p){return l.previous!==null||!l._gfmTasklistFirstContentOfListItem?a(p):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(p),e.exit("taskListCheckMarker"),s)}function s(p){return dt(p)?(e.enter("taskListCheckValueUnchecked"),e.consume(p),e.exit("taskListCheckValueUnchecked"),u):p===88||p===120?(e.enter("taskListCheckValueChecked"),e.consume(p),e.exit("taskListCheckValueChecked"),u):a(p)}function u(p){return p===93?(e.enter("taskListCheckMarker"),e.consume(p),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),f):a(p)}function f(p){return Re(p)?n(p):Ke(p)?e.check({tokenize:tP},n,a)(p):a(p)}}function tP(e,n,a){return Je(e,l,"whitespace");function l(o){return o===null?a(o):n(o)}}function nP(e){return DC([NB(),IB(),qB(e),KB(),JB()])}const rP={};function aP(e){const n=this,a=e||rP,l=n.data(),o=l.micromarkExtensions||(l.micromarkExtensions=[]),s=l.fromMarkdownExtensions||(l.fromMarkdownExtensions=[]),u=l.toMarkdownExtensions||(l.toMarkdownExtensions=[]);o.push(nP(a)),s.push(kB()),u.push(CB(a))}function CE({children:e,className:n,inverted:a=!1}){return d.jsx("div",{className:ge("visualization-container markdown-render overflow-x-auto wrap-break-words break",n),children:d.jsx(q8,{remarkPlugins:[aP],components:{code({className:l,children:o,...s}){const u=/language-(\w+)/.exec(l||""),f=u?u[1]:"",p=!f,m=Array.isArray(o)?o.join(""):String(o);return!p&&f?d.jsx("div",{className:"w-full max-w-full overflow-x-auto my-2 min-w-0",children:d.jsx(rg,{theme:a?fs.nightOwl:fs.oneDark,code:m.trim(),language:f,children:({className:y,style:g,tokens:b,getLineProps:w,getTokenProps:k})=>d.jsx("pre",{className:ge("rounded-lg text-sm p-3",y),style:g,children:b.map((S,E)=>d.jsx("div",{...w({line:S}),children:S.map((A,N)=>d.jsx("span",{...k({token:A})},N))},E))})})}):d.jsx("code",{className:ge("px-1.5 py-0.5 rounded text-sm font-mono",a?"bg-primary-foreground/20 text-primary-foreground":"bg-muted",l),...s,children:o})},a({href:l,children:o,...s}){return d.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:ge("underline underline-offset-2 transition-colors",a?"text-primary-foreground/80 hover:text-primary-foreground":"text-primary hover:text-primary/80"),...s,children:o})},p({children:l}){return d.jsx("p",{className:"last:mb-0 leading-relaxed wrap-break-words",children:l})},ul({children:l}){return d.jsx("ul",{className:"list-outside list-disc pl-4",children:l})},ol({children:l}){return d.jsx("ol",{className:"list-outside list-decimal pl-4",children:l})},li({children:l,className:o}){const s=o==null?void 0:o.includes("nested");return d.jsx("li",{className:ge("leading-snug",s&&"ml-4"),children:l})},h1({children:l}){return d.jsx("h1",{className:"text-lg font-semibold mb-1.5 mt-3 first:mt-0",children:l})},h2({children:l}){return d.jsx("h2",{className:"text-base font-semibold mb-1.5 mt-2.5 first:mt-0",children:l})},h3({children:l}){return d.jsx("h3",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0",children:l})},blockquote({children:l}){return d.jsx("blockquote",{className:ge("border-l-2 pl-3 my-1.5 italic",a?"border-primary-foreground/40 text-primary-foreground/70":"border-muted-foreground/40 text-muted-foreground"),children:l})},strong({children:l}){return d.jsx("strong",{className:ge("font-semibold",a&&"text-primary-foreground"),children:l})},em({children:l}){return d.jsx("em",{className:"italic",children:l})},hr(){return d.jsx("hr",{className:ge("my-3",a?"border-primary-foreground/30":"border-border")})},table({children:l}){return d.jsx("div",{className:"my-2 overflow-x-auto max-w-full",children:d.jsx("table",{className:"w-full border-collapse text-sm",children:l})})},th({children:l}){return d.jsx("th",{className:ge("border border-border px-2 py-1.5 text-left font-semibold",a?"bg-primary-foreground/10 text-primary-foreground":"bg-muted"),children:l})},td({children:l}){return d.jsx("td",{className:ge("border px-2 py-1.5",a?"border-primary-foreground/20":"border-border"),children:l})}},children:e})})}function lP(e){return e.filter(n=>n.type==="text").map(n=>n.text).join("")}function iP(e,n){const a=n.findIndex(l=>l.message.id===e);if(a<=0)return null;for(let l=a-1;l>=0;l--){const o=n[l];if(o.message.role==="assistant"&&o.message.status!=="streaming")return o.message.id}return null}function oP(e,n){const a=e.map(u=>({message:u.message,parts:u.parts,isQueued:!1})),l=n.map(u=>({message:{id:u.id,role:"user",sessionId:u.sessionId,createdAt:u.createdAt},parts:[{id:`${u.id}-part`,messageId:u.id,createdAt:u.createdAt,type:"text",text:u.content}],isQueued:!0,queueId:u.id})),o=[...a].sort((u,f)=>u.message.createdAt-f.message.createdAt),s=[...l].sort((u,f)=>u.message.createdAt-f.message.createdAt);return[...o,...s]}function sP({part:e}){const[n,a]=v.useState(!1);return d.jsxs("div",{className:"flex flex-col items-center my-4",children:[d.jsxs("button",{onClick:()=>a(!n),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[n?d.jsx(Ci,{className:"size-3"}):d.jsx(Ta,{className:"size-3"}),d.jsxs("span",{className:"border-b border-dashed border-muted-foreground/40 pb-px",children:[e.compactedMessageIds.length," messages compacted"]})]}),n&&d.jsx("div",{className:"mt-2 max-w-lg w-full rounded-lg border border-border bg-muted/50 px-4 py-3 text-sm text-muted-foreground",children:d.jsx(CE,{children:e.summary})})]})}function cP({parts:e,pendingPermissions:n,onPermissionResponse:a,onNavigateToSubagent:l,inverted:o=!1}){const s=[...e].sort((u,f)=>u.createdAt-f.createdAt);return d.jsx(d.Fragment,{children:s.map(u=>{switch(u.type){case"text":return d.jsx("div",{className:"min-w-0",children:d.jsx(CE,{inverted:o,children:u.text||"..."})},u.id);case"reasoning":return d.jsx("div",{className:"visualization-container text-muted-foreground text-sm italic border-l-2 border-muted-foreground/30 pl-3 my-2 wrap-break-word",children:u.text},u.id);case"tool":return d.jsx(T5,{part:u,pendingPermissions:n,onPermissionResponse:a,onNavigateToSubagent:l},u.id);case"image":return d.jsx("img",{src:u.url,alt:"",className:"max-w-full rounded-lg mt-2"},u.id);case"file":return d.jsx("div",{className:"mt-2 p-2 bg-muted rounded text-sm",children:u.filename||"unnamed"},u.id);default:return null}})})}function uP({session:e,messagesWithParts:n,queuedMessages:a,preconfigs:l,prompts:o,models:s,defaultModel:u,onSendMessage:f,onRemoveFromQueue:p,onChangePreconfig:m,onChangeModel:y,pendingPermissions:g,onPermissionResponse:b,onRename:w,usage:k,modelName:S,onNavigateToSubagent:E,onNavigateBack:A,isStreaming:N,onInterrupt:j,onRevert:O,onFork:z,onCompact:M,isCompacting:F,serverUrl:U,apiToken:Y}){const B=v.useRef(null),[G,q]=v.useState(!0),me=150,ne=oP(n,a);v.useEffect(()=>{q(!0),B.current&&(B.current.scrollTop=B.current.scrollHeight)},[e.id]),v.useEffect(()=>{B.current&&G&&(B.current.scrollTop=B.current.scrollHeight)},[n,G]),v.useEffect(()=>{const I=B.current;if(!I)return;const X=()=>{const{scrollHeight:J,scrollTop:Z,clientHeight:R}=I,D=J-Z-R;q(D<me)};return I.addEventListener("scroll",X,{passive:!0}),()=>I.removeEventListener("scroll",X)},[]);const ee=g.filter(I=>!n.some(X=>X.parts.some(J=>J.type==="tool"&&J.callId===I.toolCallId)));return d.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[d.jsx(c3,{session:e,preconfigs:l,models:s,defaultModel:u,usage:k,modelName:S,onChangePreconfig:m,onChangeModel:y,onRename:w,onNavigateBack:A,isStreaming:N,onInterrupt:j,onCompact:M,isCompacting:F,canCompact:n.length>=4}),e.status==="closed"&&d.jsx(hu,{className:"mx-4 mt-4",children:d.jsx(gu,{children:"This session is archived. You can reopen it from the sidebar."})}),d.jsx(Oa,{className:"flex-1 min-h-0",ref:B,children:d.jsxs("div",{className:"p-4",children:[ne.length===0?d.jsxs("div",{className:"text-center py-16 text-muted-foreground",children:[d.jsx("p",{className:"text-lg mb-2",children:"Start a conversation"}),d.jsx("p",{className:"text-sm",children:"Send a message below to begin."})]}):ne.map(I=>{const X=I.parts.find(R=>R.type==="compaction");if(X)return d.jsx(sP,{part:X},I.message.id);const J=!I.isQueued&&I.message.role==="user",Z=J?iP(I.message.id,n):null;return d.jsx(u3,{message:I.message,textContent:lP(I.parts),isQueued:I.isQueued,onRemove:I.isQueued?()=>p(I.queueId):void 0,canRevert:J&&Z!==null,onRevert:Z?()=>O==null?void 0:O(e.id,Z):void 0,canFork:J&&Z!==null,onFork:Z?()=>z==null?void 0:z(e.id,I.message.id):void 0,children:I.parts.length===0?d.jsx("span",{className:"opacity-50",children:"..."}):d.jsx(cP,{parts:I.parts,pendingPermissions:g,onPermissionResponse:b,onNavigateToSubagent:E,inverted:I.message.role==="user"})},I.message.id)}),ee.length>0&&d.jsx("div",{className:"mt-4 flex flex-col gap-2",children:ee.map(I=>d.jsxs("div",{className:"p-3 bg-warning/10 border border-warning/30 rounded-lg",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx("span",{className:"text-sm font-medium",children:I.toolName}),d.jsx("span",{className:"text-xs text-muted-foreground",children:I.permissionType})]}),d.jsx("p",{className:"text-sm mb-3",children:I.message}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>b(I.toolCallId,!1,!1),children:"Deny"}),d.jsx(Ne,{size:"sm",onClick:()=>b(I.toolCallId,!0,!1),children:"Approve"})]})]},I.toolCallId))})]})}),e.status==="active"&&!e.parentId&&d.jsx(D5,{onSendMessage:f,disabled:F,workspaceId:e.workspaceId,serverUrl:U,apiToken:Y,prompts:o}),e.parentId&&d.jsxs("div",{className:"p-4 border-t border-border bg-muted/50 text-center flex items-center justify-center gap-2 text-sm text-muted-foreground",children:[d.jsx(IN,{className:"size-4"}),"This is a subagent session (read-only)"]})]})}function dP({className:e,orientation:n="horizontal",...a}){return d.jsx(jD,{"data-slot":"tabs","data-orientation":n,className:ge("group/tabs flex gap-2 data-horizontal:flex-col",e),...a})}const fP=Ai("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function pP({className:e,variant:n="default",...a}){return d.jsx(TD,{"data-slot":"tabs-list","data-variant":n,className:ge(fP({variant:n}),e),...a})}function Em({className:e,...n}){return d.jsx(_D,{"data-slot":"tabs-trigger",className:ge("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent","data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",e),...n})}function Am({className:e,...n}){return d.jsx(RD,{"data-slot":"tabs-content",className:ge("flex-1 text-sm outline-none",e),...n})}function u1(e){return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function d1({permission:e,onRevoke:n}){const a=!!e.revokedAt;return d.jsxs("div",{className:"flex items-start justify-between gap-4 py-3 border-b border-border last:border-0",children:[d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(jn,{variant:a?"outline":"secondary",children:[d.jsx(S1,{className:"size-3","data-icon":"inline-start"}),e.permissionType]}),a&&d.jsx(jn,{variant:"outline",className:"text-muted-foreground",children:"Revoked"})]}),d.jsx("p",{className:"text-sm font-mono truncate text-muted-foreground",children:e.permissionKey}),d.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Granted ",u1(e.grantedAt),e.revokedAt&&` • Revoked ${u1(e.revokedAt)}`]})]}),!a&&d.jsx(Ne,{variant:"ghost",size:"icon",onClick:()=>n(e.id),className:"size-8 text-destructive hover:text-destructive",children:d.jsx(gs,{className:"size-4"})})]})}function mP({open:e,onOpenChange:n,title:a,description:l,confirmLabel:o="Confirm",cancelLabel:s="Cancel",variant:u="default",onConfirm:f,onCancel:p}){const m=()=>{p==null||p(),n(!1)},y=()=>{f(),n(!1)};return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[425px]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:a}),d.jsx(_s,{children:l})]}),d.jsxs(hd,{children:[d.jsx(Ne,{variant:"outline",onClick:m,children:s}),d.jsx(Ne,{variant:u==="destructive"?"destructive":"default",onClick:y,children:o})]})]})})}function hP({token:e,onLogout:n}){return d.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-md bg-muted",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[d.jsx("span",{className:"text-muted-foreground",children:"Token:"}),d.jsx("code",{className:"font-mono text-foreground bg-background px-1.5 py-0.5 rounded text-[10px]",children:Mj(e)})]}),d.jsx(Ne,{variant:"destructive",size:"sm",onClick:n,title:"Disconnect and clear token",children:"Logout"})]})}function gP({open:e,onOpenChange:n,permissions:a,onRefreshPermissions:l,onRevokePermission:o,onRevokeAllPermissions:s,apiToken:u,onLogout:f}){const{theme:p,setTheme:m}=HA(),[y,g]=v.useState(!1),b=a.filter(k=>!k.revokedAt),w=a.filter(k=>k.revokedAt);return d.jsxs(Mi,{open:e,onOpenChange:n,children:[d.jsxs(Oi,{className:"sm:max-w-[500px] max-h-[80vh]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:"Settings"}),d.jsx(_s,{children:"Manage your preferences and permissions"})]}),d.jsxs(dP,{defaultValue:"account",className:"mt-4",children:[d.jsxs(pP,{className:"grid w-full grid-cols-3",children:[d.jsx(Em,{value:"account",children:"Account"}),d.jsx(Em,{value:"appearance",children:"Appearance"}),d.jsxs(Em,{value:"permissions",children:[d.jsx(S1,{className:"size-3","data-icon":"inline-start"}),"Permissions",b.length>0&&d.jsx("span",{className:"ml-1.5 px-1.5 py-0.5 text-xs bg-primary text-primary-foreground rounded-full",children:b.length})]})]}),d.jsx(Am,{value:"account",className:"mt-4",children:d.jsx("div",{className:"flex flex-col gap-4",children:d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Session"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Manage your current session"}),u?d.jsx(hP,{token:u,onLogout:f}):d.jsx("p",{className:"text-sm text-muted-foreground",children:"No active session"})]})})}),d.jsx(Am,{value:"appearance",className:"mt-4",children:d.jsx("div",{className:"flex flex-col gap-4",children:d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Theme"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Choose your preferred color scheme"}),d.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[d.jsxs(Ne,{variant:p==="light"?"default":"outline",className:"justify-start",onClick:()=>m("light"),children:[d.jsx(dj,{className:"size-4","data-icon":"inline-start"}),"Light"]}),d.jsxs(Ne,{variant:p==="dark"?"default":"outline",className:"justify-start",onClick:()=>m("dark"),children:[d.jsx(qN,{className:"size-4","data-icon":"inline-start"}),"Dark"]}),d.jsxs(Ne,{variant:p==="system"?"default":"outline",className:"justify-start",onClick:()=>m("system"),children:[d.jsx($N,{className:"size-4","data-icon":"inline-start"}),"System"]})]})]})})}),d.jsx(Am,{value:"permissions",className:"mt-4",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(ja,{className:"text-sm font-medium",children:"Always-allowed Operations"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Tools you've approved to run without asking"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ne,{variant:"outline",size:"icon",onClick:l,className:"size-8",children:d.jsx(pi,{className:"size-4"})}),b.length>0&&d.jsxs(Ne,{variant:"destructive",size:"sm",onClick:()=>g(!0),children:[d.jsx(gs,{className:"size-4","data-icon":"inline-start"}),"Revoke All"]})]})]}),d.jsx(Ko,{}),d.jsxs(Oa,{className:"h-[300px]",children:[b.length===0&&w.length===0&&d.jsxs("div",{className:"text-center py-8 text-muted-foreground text-sm",children:["No permissions granted yet.",d.jsx("br",{}),'Approve tool requests with "Always allow" to add them here.']}),b.length>0&&d.jsxs("div",{className:"mb-4",children:[d.jsxs("h4",{className:"text-xs uppercase text-muted-foreground mb-2 font-medium",children:["Active (",b.length,")"]}),b.map(k=>d.jsx(d1,{permission:k,onRevoke:o},k.id))]}),w.length>0&&d.jsxs("div",{children:[d.jsxs("h4",{className:"text-xs uppercase text-muted-foreground mb-2 font-medium",children:["Revoked (",w.length,")"]}),w.map(k=>d.jsx(d1,{permission:k,onRevoke:o},k.id))]})]})]})})]})]}),d.jsx(mP,{open:y,onOpenChange:g,title:"Revoke All Permissions",description:"This will revoke all always-allowed permissions for this workspace. You'll need to approve these tools again when they're used.",confirmLabel:"Revoke All",variant:"destructive",onConfirm:()=>{s(),g(!1)}})]})}function yP({status:e}){switch(e.status){case"connected":return d.jsxs(jn,{variant:"default",className:"bg-green-600",children:[d.jsx(hs,{className:"size-3 mr-1"}),"Connected"]});case"disabled":return d.jsxs(jn,{variant:"secondary",children:[d.jsx(Fu,{className:"size-3 mr-1"}),"Disabled"]});case"failed":return d.jsxs(jn,{variant:"destructive",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Failed"]});case"needs_auth":return d.jsxs(jn,{variant:"outline",className:"border-yellow-500 text-yellow-600",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Needs Auth"]});case"needs_client_registration":return d.jsxs(jn,{variant:"outline",className:"border-orange-500 text-orange-600",children:[d.jsx(Qo,{className:"size-3 mr-1"}),"Needs Registration"]});default:return d.jsx(jn,{variant:"secondary",children:"Unknown"})}}function xP({open:e,onOpenChange:n,workspaceId:a,workspacePath:l,serverUrl:o,apiToken:s}){const{fetchWithAuth:u}=Ts(),[f,p]=v.useState({}),[m,y]=v.useState(!1),[g,b]=v.useState(null),[w,k]=v.useState(null),S=v.useCallback(async()=>{if(a){y(!0),k(null);try{const O=await u(`/api/workspaces/${a}/mcp/status`,{},{serverUrl:o,token:s});if(!O.ok)throw new Error("Failed to load MCP status");const z=await O.json();p(z.status||{})}catch(O){const z=O instanceof Error?O.message:"Unknown error";k(z)}finally{y(!1)}}},[a,u,o,s]);v.useEffect(()=>{e&&a&&S()},[e,a,S]);const E=async O=>{if(a){b(O);try{if(!(await u(`/api/workspaces/${a}/mcp/connect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s})).ok)throw new Error("Failed to connect");await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},A=async O=>{if(a){b(O);try{if(!(await u(`/api/workspaces/${a}/mcp/disconnect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s})).ok)throw new Error("Failed to disconnect");await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},N=async O=>{if(a){b(O);try{const z=await u(`/api/workspaces/${a}/mcp/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O})},{serverUrl:o,token:s});if(!z.ok)throw new Error("Failed to start auth");const M=await z.json();M.authorizationUrl&&window.open(M.authorizationUrl,"_blank"),await S()}catch(z){const M=z instanceof Error?z.message:"Unknown error";k(M)}finally{b(null)}}},j=Object.entries(f);return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[600px] max-h-[80vh]",children:[d.jsxs(Di,{children:[d.jsxs(zi,{className:"flex items-center gap-2",children:[d.jsx(ul,{className:"size-5"}),"MCP Servers"]}),d.jsx(_s,{children:"Manage Model Context Protocol servers for this workspace"})]}),d.jsxs("div",{className:"mt-4 space-y-4",children:[w&&d.jsxs(hu,{variant:"destructive",children:[d.jsx(Qo,{className:"size-4"}),d.jsx(gu,{children:w})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure servers in ",d.jsx("code",{className:"text-xs bg-muted px-1 rounded",children:".jean2/mcp.json"})]}),d.jsx(Ne,{variant:"outline",size:"sm",onClick:S,disabled:m,children:d.jsx(pi,{className:`size-4 ${m?"animate-spin":""}`})})]}),d.jsx(Oa,{className:"h-[400px]",children:m&&j.length===0?d.jsx("div",{className:"flex items-center justify-center py-8",children:d.jsx(Vn,{className:"size-6 animate-spin text-muted-foreground"})}):j.length===0?d.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[d.jsx(ul,{className:"size-12 mx-auto mb-3 opacity-50"}),d.jsx("p",{className:"font-medium",children:"No MCP servers configured"}),d.jsxs("p",{className:"text-sm mt-1",children:["Create ",d.jsx("code",{className:"text-xs bg-muted px-1 rounded",children:".jean2/mcp.json"})," in your workspace to add servers."]})]}):d.jsx("div",{className:"space-y-3",children:j.map(([O,{config:z,status:M}])=>{var F;return d.jsxs("div",{className:"border rounded-lg p-4",children:[d.jsxs("div",{className:"flex items-start justify-between",children:[d.jsxs("div",{className:"flex items-start gap-3",children:[d.jsx(ul,{className:"size-5 text-muted-foreground mt-0.5"}),d.jsxs("div",{children:[d.jsx("div",{className:"font-medium",children:O}),d.jsx("div",{className:"text-sm text-muted-foreground",children:(z==null?void 0:z.type)==="local"?d.jsxs("span",{children:["Local - ",((F=z.command)==null?void 0:F[0])||"command"]}):(z==null?void 0:z.type)==="remote"?d.jsxs("span",{className:"flex items-center gap-1",children:["Remote - ",z.url]}):"Unknown type"}),M.status==="failed"&&"error"in M&&d.jsx(hu,{variant:"destructive",className:"mt-2 py-2",children:d.jsx(gu,{className:"text-xs",children:M.error})}),M.status==="needs_client_registration"&&"error"in M&&d.jsx(hu,{className:"mt-2 py-2 border-orange-500",children:d.jsx(gu,{className:"text-xs",children:M.error})})]})]}),d.jsx("div",{className:"flex items-center gap-2",children:d.jsx(yP,{status:M})})]}),d.jsxs("div",{className:"flex items-center gap-2 mt-3 pt-3 border-t",children:[M.status==="connected"&&d.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>A(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(KN,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Disconnect"})]}),(M.status==="disabled"||M.status==="failed")&&d.jsxs(Ne,{variant:"outline",size:"sm",onClick:()=>E(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(ZN,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Connect"})]}),M.status==="needs_auth"&&d.jsxs(Ne,{variant:"default",size:"sm",onClick:()=>N(O),disabled:g===O,children:[g===O?d.jsx(Vn,{className:"size-4 animate-spin"}):d.jsx(jm,{className:"size-4"}),d.jsx("span",{className:"ml-1",children:"Authenticate"})]})]})]},O)})})})]})]})})}function f1({message:e="Connecting to server..."}){return d.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-muted-foreground",children:[d.jsx(Vn,{className:"size-8 animate-spin"}),d.jsx("p",{className:"text-sm",children:e})]})}const bP=({serverUrl:e,authError:n,retryCount:a,nextRetryIn:l,onRetry:o,onLogout:s})=>d.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] px-4 text-center",children:[d.jsx(C1,{className:"size-12 text-destructive mb-4"}),d.jsx("h2",{className:"text-xl font-semibold text-foreground mb-2",children:"Unable to connect to server"}),d.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-[400px]",children:n||"Please check that the server is running."}),e&&d.jsx("p",{className:"text-xs text-muted-foreground mb-6 font-mono bg-muted px-3 py-1.5 rounded",children:e}),d.jsxs("div",{className:"flex flex-col items-center gap-4",children:[d.jsxs("p",{className:"text-sm text-muted-foreground",children:["Retrying in ",l,"s..."]}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs(Ne,{onClick:o,variant:"default",children:[d.jsx(pi,{className:"size-4 mr-2","data-icon":"inline-start"}),"Retry Now"]}),d.jsx(Ne,{onClick:s,variant:"ghost",children:"Change Server"})]}),a>0&&d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Retry attempt: ",a]})]})]});function p1({onServerAdded:e,error:n}){const[a,l]=v.useState(""),[o,s]=v.useState(""),[u,f]=v.useState(""),[p,m]=v.useState(!1),[y,g]=v.useState(null),b=w=>{w.preventDefault();const k=a.trim(),S=o.trim(),E=u.trim();if(!k){g("Please enter a server name");return}if(!S){g("Please enter a server URL");return}if(!E){g("Please enter an API token");return}if(!A1(E)){g("Invalid token format. Token should be 64 hex characters (0-9, a-f).");return}const A=bu(S),N={id:crypto.randomUUID(),name:k,url:A,token:E,createdAt:new Date().toISOString()};e(N)};return d.jsx("div",{className:"w-full h-full flex items-center justify-center bg-background dark:bg-gradient-to-br dark:from-muted dark:via-background dark:to-muted p-4",children:d.jsx("div",{className:"w-full max-w-md",children:d.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl overflow-hidden",children:[d.jsxs("div",{className:"px-6 pt-6 pb-4 text-center border-b border-border",children:[d.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Add your first server"}),d.jsx("p",{className:"text-muted-foreground mt-1",children:"Connect to a Jean2 server to get started"})]}),d.jsxs("form",{onSubmit:b,className:"p-6 space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"serverName",className:"text-sm font-medium text-foreground",children:"Server Name"}),d.jsx("input",{id:"serverName",type:"text",value:a,onChange:w=>{l(w.target.value),g(null)},placeholder:"Production",className:"w-full px-3 py-2 bg-background border border-input rounded-lg text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"serverUrl",className:"text-sm font-medium text-foreground",children:"Server URL"}),d.jsx("input",{id:"serverUrl",type:"text",value:o,onChange:w=>{s(w.target.value),g(null)},placeholder:"localhost:3000",className:"w-full px-3 py-2 bg-background border border-input rounded-lg text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("label",{htmlFor:"token",className:"text-sm font-medium text-foreground",children:"API Token"}),d.jsxs("div",{className:"relative",children:[d.jsx("input",{id:"token",type:p?"text":"password",value:u,onChange:w=>{f(w.target.value),g(null)},placeholder:"Enter your 64-character token",className:"w-full px-3 py-2 pr-10 bg-background border border-input rounded-lg text-foreground font-mono text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent transition-colors"}),d.jsx("button",{type:"button",onClick:()=>m(!p),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground transition-colors","aria-label":p?"Hide token":"Show token",children:p?d.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})}):d.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]}),(y||n)&&d.jsx("div",{className:"px-3 py-2 bg-destructive/10 border border-destructive/20 rounded-lg text-destructive text-sm",children:y||n}),d.jsx("button",{type:"submit",className:"w-full py-2.5 bg-primary text-primary-foreground font-medium rounded-lg hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 transition-colors",children:"Add Server"})]})]})})})}function m1({onServerSwitch:e,onSelectWorkspace:n}){const[a,l]=v.useState(!1),o=v.useRef(!1),s=bd(),{quickConnections:u,switchServer:f,removeFromQuickConnections:p,isSwitching:m}=Ei(),y=w=>{f(w.serverId)&&(o.current=!0,e==null||e(),w.workspaceId&&n&&n(w.workspaceId))};v.useEffect(()=>{!m&&a&&o.current&&(l(!1),o.current=!1)},[m,a]);const g=(w,k)=>{w.stopPropagation(),p(k)},b=()=>d.jsx(Yh,{children:d.jsx(Xh,{className:"max-h-[50vh] overflow-y-auto",children:u.length>0?d.jsx(ls,{heading:"Quick Switch",children:u.map(w=>d.jsxs(gi,{onSelect:()=>y(w),className:"justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(ul,{className:"size-4 text-muted-foreground"}),d.jsxs("span",{children:[w.serverName,w.workspaceName&&d.jsxs("span",{className:"text-muted-foreground",children:[" / ",w.workspaceName]})]})]}),d.jsx("button",{className:"opacity-0 group-hover:opacity-100 hover:opacity-100 transition-opacity p-1 rounded hover:bg-destructive/10",onClick:k=>g(k,w.id),children:d.jsx(gs,{className:"size-3 text-destructive"})})]},w.id))}):d.jsx(Kh,{className:"py-6",children:d.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[d.jsx($p,{className:"size-8"}),d.jsx("p",{className:"text-sm font-medium",children:"No favorites yet"}),d.jsx("p",{className:"text-xs",children:"Star a workspace to add it here"})]})})})});return s?d.jsxs(Zh,{open:a,onOpenChange:l,children:[d.jsx(Az,{asChild:!0,children:d.jsx(Ne,{variant:"ghost",size:"icon-sm","aria-label":"Quick switch",children:d.jsx($p,{className:"size-4"})})}),d.jsxs(Wh,{side:"bottom",className:"max-h-[80vh]",children:[d.jsx(Jh,{children:d.jsx(eg,{children:"Quick Switch"})}),d.jsx("div",{className:"mt-4",children:b()})]})]}):d.jsxs(yd,{open:a,onOpenChange:l,children:[d.jsx(Qh,{asChild:!0,children:d.jsx(Ne,{variant:"ghost",size:"icon-sm","aria-label":"Quick switch",children:d.jsx($p,{className:"size-4"})})}),d.jsx(xd,{className:"w-[300px] p-0",align:"start",children:b()})]})}function vP({open:e,onOpenChange:n,editServer:a}){const{addServer:l,editServer:o}=Ei(),[s,u]=v.useState(""),[f,p]=v.useState(""),[m,y]=v.useState(""),[g,b]=v.useState(!1),[w,k]=v.useState(null),S=a!=null;v.useEffect(()=>{a?(u(a.name),p(a.url),y(a.token)):(u(""),p(""),y("")),k(null),b(!1)},[a,e]);const E=A=>{A.preventDefault(),k(null);const N=s.trim(),j=f.trim(),O=m.trim();if(!N){k("Name is required");return}if(!j){k("Server URL is required");return}if(!O){k("API token is required");return}if(!A1(O)){k("Token must be 64 hexadecimal characters");return}const z=bu(j);S?o(a.id,{name:N,url:z,token:O}):l(N,z,O),n(!1)};return d.jsx(Mi,{open:e,onOpenChange:n,children:d.jsxs(Oi,{className:"sm:max-w-[425px]",children:[d.jsxs(Di,{children:[d.jsx(zi,{children:S?"Edit Server":"Add Server"}),d.jsx(_s,{children:S?"Update server details":"Enter your server details"})]}),d.jsxs("form",{onSubmit:E,children:[d.jsxs("div",{className:"grid gap-4 py-4",children:[d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-name",children:"Name"}),d.jsx(mu,{id:"server-name",value:s,onChange:A=>u(A.target.value),placeholder:"My Server"})]}),d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-url",children:"Server URL"}),d.jsx(mu,{id:"server-url",value:f,onChange:A=>p(A.target.value),placeholder:"localhost:3000"})]}),d.jsxs("div",{className:"grid gap-2",children:[d.jsx(ja,{htmlFor:"server-token",children:"API Token"}),d.jsxs("div",{className:"relative",children:[d.jsx(mu,{id:"server-token",type:g?"text":"password",value:m,onChange:A=>y(A.target.value),placeholder:"64-character hex string",className:"pr-10"}),d.jsx("button",{type:"button",onClick:()=>b(!g),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-transparent",children:g?d.jsx(kN,{className:"size-4 text-muted-foreground"}):d.jsx(EN,{className:"size-4 text-muted-foreground"})})]})]}),w&&d.jsx("p",{className:"text-sm text-destructive",children:w})]}),d.jsxs(hd,{children:[d.jsx(Ne,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancel"}),d.jsx(Ne,{type:"submit",children:S?"Save":"Add"})]})]})]})})}const wP=(e,n)=>e&&n?`ws://${n}/ws?token=${e}`:null,Nm=e=>e?`http://${e}/api`:null;function SP(){var Fs,Xi,Ki,Us;const{servers:e,activeServer:n,addServer:a,removeServer:l,isSwitching:o,clearSwitchingState:s}=Ei(),[u,f]=v.useState([]),[p,m]=v.useState([]),[y,g]=v.useState([]),[b,w]=v.useState(null),[k,S]=v.useState({}),[E,A]=v.useState({}),[N,j]=v.useState(null),O=v.useRef(null),[z,M]=v.useState(!1),[F,U]=v.useState(null),[Y,B]=v.useState({promptTokens:0,completionTokens:0,totalTokens:0}),[G,q]=v.useState("gpt-4o"),[me,ne]=v.useState([]),[ee,I]=v.useState("gpt-4o"),[X,J]=v.useState([]),[Z,R]=v.useState(null),[D,L]=v.useState(!1),[T,te]=v.useState(!1),[ae,le]=v.useState(!1),[ie,be]=v.useState([]),[he,Te]=v.useState([]),[ze,Le]=v.useState({}),[ft,et]=v.useState(null),[Dt,Vt]=v.useState(!1),[Mn,Gr]=v.useState(null),[an,ln]=v.useState(!1),[on,xr]=v.useState(0),[Bi,vt]=v.useState(0),[Pi,se]=v.useState(0),xe=(Fs=b==null?void 0:b.compacting)!=null?Fs:!1,Oe=1e4,He=3e4,tt=1e3,zt=v.useRef(null),sn=v.useRef(null),[qt,yt]=v.useState(!1),Ge=(Xi=n==null?void 0:n.token)!=null?Xi:null,De=(Ki=n==null?void 0:n.url)!=null?Ki:null;v.useEffect(()=>{O.current=N},[N]);const yn=v.useRef(null),Jt=v.useRef(!1),zs=v.useCallback(H=>{a(H.name,H.url,H.token)},[a]),On=v.useCallback(()=>{n&&l(n.id),O.current&&O.current.close(),j(null),M(!1),ln(!1),xr(0),vt(0)},[n,l]),Sl=v.useCallback(()=>{xr(H=>H+1),ln(!1),vt(0)},[]),Yr=v.useCallback(()=>{O.current&&O.current.close(),j(null),M(!1),ln(!1),xr(0),vt(0),f([]),m([]),w(null),S({}),A({}),U(null),B({promptTokens:0,completionTokens:0,totalTokens:0}),q("gpt-4o"),ne([]),J([]),R(null),be([]),Te([]),Le({}),se(H=>H+1)},[]),Gt=v.useCallback(async(H,we={})=>{if(!Ge)throw new Error("No API token available");const ce=new Headers(we.headers||{});ce.set("Authorization",`Bearer ${Ge}`);const de=await fetch(H,{...we,signal:we.signal,headers:ce});if(de.status===401)throw et("Authentication failed. Your token may have been regenerated."),On(),new Error("Unauthorized");return de},[Ge,On]),kl=v.useCallback(H=>{const we=k[H]||[],ce=E[H]||{};return we.map(de=>({message:de,parts:(ce[de.id]||[]).sort((Be,St)=>Be.createdAt-St.createdAt)}))},[k,E]);v.useEffect(()=>{if(!Ge||!De)return;const H=wP(Ge,De);if(!H)return;const we=new WebSocket(H);return we.onopen=()=>{M(!0),et(null),xr(0),ln(!1)},we.onclose=ce=>{M(!1),(ce.code===1008||ce.code===401)&&(et("Authentication failed. Please check your token."),On())},we.onerror=ce=>{console.error("WebSocket error:",ce)},we.onmessage=ce=>{var Be;const de=JSON.parse(ce.data);(Be=yn.current)==null||Be.call(yn,de)},j(we),()=>we.close()},[Ge,De,On,Pi]),v.useEffect(()=>{if(Ge&&De&&!z&&!an){const H=setTimeout(()=>{z||ln(!0)},Oe);return()=>clearTimeout(H)}},[Ge,De,z,an]),v.useEffect(()=>{if(an&&!z&&Ge&&De){const H=Math.min(tt*Math.pow(2,on),He);let we=Math.floor(H/1e3);vt(we);const ce=setInterval(()=>{we-=1,vt(Math.max(0,we))},1e3),de=setTimeout(()=>{xr(Be=>Be+1),se(Be=>Be+1)},H);return()=>{clearInterval(ce),clearTimeout(de)}}},[an,z,Ge,De,on]),v.useEffect(()=>{var ce;if(!Ge||!De)return;(ce=zt.current)==null||ce.abort(),zt.current=new AbortController;const H=zt.current.signal,we=Nm(De);if(we)return yt(!0),Promise.all([Gt(`${we}/sessions`,{signal:H}).then(de=>de.json()),Gt(`${we}/preconfigs`,{signal:H}).then(de=>de.json()),Gt(`${we}/prompts`,{signal:H}).then(de=>de.json()),Gt(`${we}/models`,{signal:H}).then(de=>de.json()),Gt(`${we}/workspaces`,{signal:H}).then(de=>de.json())]).then(([de,Be,St,en,Xn])=>{f(de.sessions||[]),m(Be.preconfigs||[]),g(St.prompts||[]),ne(en.models||[]),I(en.defaultModel||"gpt-4o");const Dn=Xn.workspaces||[];if(J(Dn),sn.current){const Cl=Dn.find(Kt=>Kt.id===sn.current);Cl&&R(Cl),sn.current=null}else{const Cl=localStorage.getItem("activeWorkspaceId"),Kt=Dn.find(Qi=>Qi.id===Cl);R(Kt||Dn[0])}s(),yt(!1)}).catch(de=>{var Be;if(de.name==="AbortError"){console.log("Fetch aborted due to server switch");return}console.error("Failed to load server data:",de),yt(!1),(Be=de.message)!=null&&Be.includes("Unauthorized")||et("Failed to connect to server")}),()=>{var de;(de=zt.current)==null||de.abort()}},[Ge,De,Gt,s]),v.useEffect(()=>{Z&&localStorage.setItem("activeWorkspaceId",Z.id)},[Z]);const Xr=async(H,we,ce)=>{const de=Nm(De);if(!de)return;const St=await(await Gt(`${de}/workspaces`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:H,path:we,isVirtual:ce})})).json();return J(en=>[...en,St.workspace]),St.workspace},Nd=H=>{R(H),w(null)},Fi=H=>{sn.current=H},Ui=async H=>{const we=Nm(De);we&&(await Gt(`${we}/workspaces/${H}`,{method:"DELETE"}),J(ce=>ce.filter(de=>de.id!==H)),(Z==null?void 0:Z.id)===H&&R(X[0]||null))},Ua=async()=>{const H=`Workspace ${X.length+1}`,we=`~/.jean2/workspaces/${crypto.randomUUID()}`;await Xr(H,we,!0)},jd=async H=>{const we=H.split("/").pop()||H.split("\\").pop()||"Workspace";await Xr(we,H,!1)},Hi=v.useCallback(H=>{var we;switch(H.type){case"session.created":f(ce=>[H.session,...ce]),Jt.current&&(w(H.session),S(ce=>({...ce,[H.session.id]:[]})),A(ce=>({...ce,[H.session.id]:{}})),B({promptTokens:0,completionTokens:0,totalTokens:0}),q(ee),Jt.current=!1);break;case"session.resumed":w(H.session),H.isRunning&&U(H.session.id),H.messages&&(S(ce=>({...ce,[H.session.id]:H.messages.map(de=>de.message)})),A(ce=>{const de={...ce};de[H.session.id]={};for(const Be of H.messages)de[H.session.id][Be.message.id]=Be.parts;return de})),B((we=H.usage)!=null?we:{promptTokens:0,completionTokens:0,totalTokens:0}),q(H.session.selectedModel||ee);break;case"message.created":S(ce=>({...ce,[H.message.sessionId]:[...ce[H.message.sessionId]||[],H.message]})),A(ce=>({...ce,[H.message.sessionId]:{...ce[H.message.sessionId],[H.message.id]:[]}})),"status"in H.message&&H.message.status==="streaming"&&U(H.message.sessionId);break;case"message.updated":S(ce=>({...ce,[H.message.sessionId]:(ce[H.message.sessionId]||[]).map(de=>de.id===H.message.id?H.message:de)})),"status"in H.message&&H.message.status!=="streaming"&&U(ce=>ce===H.message.sessionId?null:ce);break;case"part.created":A(ce=>{const de=ce[H.sessionId]||{},Be=de[H.part.messageId]||[];return{...ce,[H.sessionId]:{...de,[H.part.messageId]:[...Be,H.part]}}});break;case"part.updated":A(ce=>{const de=ce[H.sessionId]||{},Be=de[H.part.messageId]||[];return{...ce,[H.sessionId]:{...de,[H.part.messageId]:Be.map(St=>St.id===H.part.id?H.part:St)}}});break;case"part.append":U(H.sessionId),A(ce=>{const de=ce[H.sessionId]||{};for(const Be of Object.keys(de)){const St=de[Be],en=St.findIndex(Xn=>Xn.id===H.partId);if(en!==-1){const Xn=St[en];if(Xn.type==="text"||Xn.type==="reasoning"){const Dn=[...St];return Dn[en]={...Xn,text:Xn.text+H.delta},{...ce,[H.sessionId]:{...de,[Be]:Dn}}}}}return ce});break;case"chat.usage":if(H.sessionId!==(b==null?void 0:b.id))return;B({promptTokens:H.usage.promptTokens,completionTokens:H.usage.completionTokens,totalTokens:H.usage.totalTokens}),q(H.model);break;case"error":console.error("Server error:",H.code,H.message);break;case"session.closed":f(ce=>ce.map(de=>de.id===H.sessionId?{...de,status:"closed"}:de)),S(ce=>{const de={...ce};return delete de[H.sessionId],de}),A(ce=>{const de={...ce};return delete de[H.sessionId],de}),(b==null?void 0:b.id)===H.sessionId&&w(null);break;case"session.reopened":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"session.deleted":f(ce=>ce.filter(de=>de.id!==H.sessionId)),S(ce=>{const de={...ce};return delete de[H.sessionId],de}),A(ce=>{const de={...ce};return delete de[H.sessionId],de}),(b==null?void 0:b.id)===H.sessionId&&w(null);break;case"session.updated":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"session.renamed":f(ce=>ce.map(de=>de.id===H.session.id?H.session:de)),(b==null?void 0:b.id)===H.session.id&&w(H.session);break;case"permission.list":be(H.permissions);break;case"permission.revoked":be(ce=>ce.map(de=>de.id===H.permissionId?{...de,revokedAt:new Date().toISOString()}:de));break;case"permission.all_revoked":be(ce=>{const de=new Date().toISOString();return ce.map(Be=>({...Be,revokedAt:de}))});break;case"permission.request":{const ce={toolCallId:H.toolCallId,toolName:H.toolName,args:H.args,permissionType:H.permissionType,permissionKey:H.permissionKey,message:H.message,details:H.details,dangerous:H.dangerous,childSessionId:H.childSessionId,subagentName:H.subagentName};Te(de=>[...de,ce]);break}case"permission.granted":Te(ce=>ce.filter(de=>de.toolCallId!==H.toolCallId));break;case"session.interrupted":F===H.sessionId&&U(null),H.result.cascadedTo.length>0&&console.log(`Session ${H.sessionId} interrupted. Cascaded to:`,H.result.cascadedTo);break;case"queue.list":Le(ce=>({...ce,[H.sessionId]:H.messages}));break;case"queue.added":Le(ce=>({...ce,[H.sessionId]:[...ce[H.sessionId]||[],H.message]}));break;case"queue.removed":Le(ce=>({...ce,[H.sessionId]:(ce[H.sessionId]||[]).filter(de=>de.id!==H.queueId)}));break;case"queue.sending":Le(ce=>({...ce,[H.sessionId]:(ce[H.sessionId]||[]).filter(de=>de.id!==H.queueId)}));break;case"session.reverted":console.log(`Session reverted to message ${H.revertedTo.messageId}, removed ${H.removed.messageIds.length} messages`);break;case"compaction.complete":break;case"session.forked":{const{forkedSession:ce,messages:de}=H;f(Be=>[ce,...Be]),S(Be=>({...Be,[ce.id]:de.map(St=>St.message)})),A(Be=>{const St={...Be};St[ce.id]={};for(const en of de)St[ce.id][en.message.id]=en.parts;return St}),w(ce),B({promptTokens:0,completionTokens:0,totalTokens:0});break}case"session.state":S(ce=>({...ce,[H.sessionId]:H.messages.map(de=>de.message)})),A(ce=>{const de={...ce};de[H.sessionId]={};for(const Be of H.messages)de[H.sessionId][Be.message.id]=Be.parts;return de}),F===H.sessionId&&U(null);break}},[b,ee,F]);v.useEffect(()=>{yn.current=Hi},[Hi]),v.useEffect(()=>{const H=async we=>{const ce=we.target;if(!(ce.tagName==="INPUT"||ce.tagName==="TEXTAREA"||ce.isContentEditable)&&(we.metaKey||we.ctrlKey)&&we.key==="n"){we.preventDefault();try{await $A("create_new_window")}catch(Be){console.error("Failed to create new window:",Be)}}};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[]);const $e=v.useCallback((H,we)=>{N&&N.readyState===WebSocket.OPEN&&N.send(JSON.stringify({type:H,...we}))},[N]),Ls=v.useCallback((H,we)=>{Jt.current=!0,$e("session.create",{preconfigId:H,title:we,workspaceId:Z==null?void 0:Z.id})},[$e,Z]),Kr=v.useCallback(H=>{Te([]),U(null),$e("session.resume",{sessionId:H})},[$e]),$i=v.useCallback(H=>{$e("session.close",{sessionId:H})},[$e]),Is=v.useCallback((H,we)=>{$e("session.revert",{sessionId:H,messageId:we})},[$e]),Bs=v.useCallback((H,we)=>{$e("session.fork",{sessionId:H,messageId:we})},[$e]),ar=v.useCallback((H,we)=>{$e("session.compact",{sessionId:H,messageIds:we})},[$e]),_t=v.useCallback(H=>{$e("session.reopen",{sessionId:H})},[$e]),Yt=v.useCallback(H=>{$e("session.delete",{sessionId:H})},[$e]),Qr=v.useCallback(H=>{b&&$e("session.update",{sessionId:b.id,preconfigId:H})},[b,$e]),Vi=v.useCallback((H,we)=>{b&&$e("session.update_model",{sessionId:b.id,modelId:H,providerId:we})},[b,$e]),Td=v.useCallback((H,we)=>{$e("session.rename",{sessionId:H,title:we})},[$e]),_d=v.useCallback(()=>{b!=null&&b.parentId&&Kr(b.parentId)},[b,Kr]),qi=v.useCallback((H,we)=>{$e("queue.add",{sessionId:H,content:we})},[$e]),Ha=v.useCallback(H=>{$e("queue.remove",{queueId:H})},[$e]),Gi=v.useCallback(H=>{!b||xe||(F===b.id?qi(b.id,H):$e("chat.message",{sessionId:b.id,content:H}))},[b,F,xe,$e,qi]),Zr=v.useCallback((H,we,ce)=>{Te(de=>de.filter(Be=>Be.toolCallId!==H)),$e("permission.response",{toolCallId:H,allowed:we,alwaysAllow:ce})},[$e]),Wr=v.useCallback(()=>{b&&$e("session.interrupt",{sessionId:b.id})},[b,$e]),$a=v.useCallback(()=>{Z&&$e("permission.list",{workspaceId:Z.id})},[Z,$e]),Jr=u.filter(H=>H.workspaceId===(Z==null?void 0:Z.id)),wt=b?kl(b.id):[],Yi=p.filter(H=>H.mode!=="subagent"),Ps=!(b!=null&&b.parentId),Xt=!!n,ea=()=>e.length===0?d.jsx(p1,{onServerAdded:zs,error:ft||void 0}):Xt?o?d.jsx("div",{className:"flex flex-col w-full h-full items-center justify-center bg-background gap-4",children:d.jsx(f1,{message:`Connecting to ${(n==null?void 0:n.name)||"server"}...`})}):!z&&u.length===0?an?d.jsx("div",{className:"flex w-full h-full items-center justify-center bg-background",children:d.jsx(bP,{serverUrl:De,authError:ft,retryCount:on,nextRetryIn:Bi,onRetry:Sl,onLogout:On})}):d.jsxs("div",{className:"flex flex-col w-full h-full items-center justify-center bg-background gap-4",children:[d.jsx(f1,{}),d.jsx(Ne,{variant:"ghost",size:"sm",onClick:On,className:"text-muted-foreground",children:"Change Server"})]}):d.jsx(d.Fragment,{children:b?d.jsx(uP,{session:b,messagesWithParts:wt,queuedMessages:ze[b.id]||[],preconfigs:Ps?Yi:p,prompts:y,models:me,defaultModel:ee,onSendMessage:Gi,onRemoveFromQueue:Ha,onChangePreconfig:Qr,onChangeModel:Vi,pendingPermissions:he,onPermissionResponse:Zr,onRename:Td,usage:Y,modelName:G,onNavigateToSubagent:Kr,onNavigateBack:_d,isStreaming:F===b.id,onInterrupt:Wr,onRevert:Is,onFork:Bs,onCompact:(()=>{const H=wt.filter(we=>we.message.role!=="system"&&!we.parts.some(ce=>ce.type==="compaction"));return H.length>=4?()=>{const we=H.slice(0,H.length-2).map(ce=>ce.message.id);we.length>0&&ar(b.id,we)}:void 0})(),isCompacting:xe,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0}):d.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center text-muted-foreground px-6",children:[d.jsx("h2",{className:"mb-2",children:"Select or create a session"}),d.jsx("p",{children:"Choose a session from the sidebar or create a new one to start chatting."})]})}):d.jsx(p1,{onServerAdded:zs,error:ft||void 0});return d.jsxs(Lz,{defaultOpen:!0,children:[Xt&&d.jsx(Xz,{sessions:Jr,currentSession:b,currentSessionId:(Us=b==null?void 0:b.id)!=null?Us:null,streamingSessionId:F,connected:z,workspaces:X,activeWorkspace:Z,onCreateSession:()=>{var H;return Ls((H=Yi[0])==null?void 0:H.id)},onResumeSession:Kr,onCloseSession:$i,onReopenSession:_t,onDeleteSession:Yt,onSelectWorkspace:Nd,onCreateVirtualWorkspace:Ua,onCreatePhysicalWorkspace:jd,onDeleteWorkspace:Ui,onOpenSettings:()=>L(!0),onOpenMCP:()=>le(!0),onOpenAddServer:()=>Vt(!0),onServerSwitch:Yr}),d.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden",style:{paddingTop:"env(safe-area-inset-top, 0)",paddingBottom:"env(safe-area-inset-bottom, 0)"},children:[d.jsxs("header",{className:"md:hidden flex items-center justify-between p-3 border-b border-border bg-background sticky top-0 z-10",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(o0,{}),d.jsx("span",{className:"font-semibold",children:"Jean2"})]}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(m1,{onServerSwitch:Yr,onSelectWorkspace:Fi}),Xt&&Z&&d.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>te(!T),title:T?"Hide Files":"Show Files",children:d.jsx(Tm,{className:"w-4 h-4"})})]})]}),d.jsxs("header",{className:"hidden md:flex items-center justify-between p-3 border-b border-border",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(o0,{}),d.jsx("span",{className:"font-semibold",children:"Jean2"})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[Xt&&d.jsx(m1,{onServerSwitch:Yr,onSelectWorkspace:Fi}),Xt&&Z&&d.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>te(!T),title:T?"Hide Files":"Show Files",children:d.jsx(Tm,{className:"w-4 h-4"})})]})]}),ea()]}),Xt&&d.jsxs(d.Fragment,{children:[d.jsx(Zz,{workspaceId:Z==null?void 0:Z.id,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0,isOpen:T,onClose:()=>te(!1)}),d.jsx(gP,{open:D,onOpenChange:L,permissions:ie,onRefreshPermissions:$a,onRevokePermission:H=>{$e("permission.revoke",{permissionId:H})},onRevokeAllPermissions:()=>{$e("permission.revoke_all",{workspaceId:Z==null?void 0:Z.id})},apiToken:Ge,onLogout:On}),d.jsx(xP,{open:ae,onOpenChange:le,workspaceId:Z==null?void 0:Z.id,workspacePath:Z==null?void 0:Z.path,serverUrl:De!=null?De:void 0,apiToken:Ge!=null?Ge:void 0})]}),d.jsx(vP,{open:Dt,onOpenChange:H=>{Vt(H),H||Gr(null)},editServer:Mn})]})}function kP(){return d.jsx(Oj,{children:d.jsx(SP,{})})}PA.createRoot(document.getElementById("root")).render(d.jsx(v.StrictMode,{children:d.jsx(UA,{defaultTheme:"dark",storageKey:"jean2-theme",children:d.jsx(kP,{})})}));
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="mobile-web-app-capable" content="yes" />
|
|
7
7
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
8
8
|
<title>AI Agent Client</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-B-55iQwA.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-CP7Exzb0.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|