@leeoohoo/aichat 1.0.8-4 → 1.0.8-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -97,5 +97,5 @@ ${e}`,status:"completed",createdAt:new Date}];let s="";return await new ml(n,[],
97
97
  </div>`)}}p=p.replace(/^### (.*$)/gm,"<h3>$1</h3>"),p=p.replace(/^## (.*$)/gm,"<h2>$1</h2>"),p=p.replace(/^# (.*$)/gm,"<h1>$1</h1>"),p=p.replace(/^\* (.*$)/gm,"<li>• $1</li>"),p=p.replace(/^\d+\. (.*$)/gm,"<li>$1</li>"),p=p.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>"),p=p.replace(/\*(.*?)\*/g,"<em>$1</em>"),p=p.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),p=p.replace(/^> (.*$)/gm,"<blockquote>$1</blockquote>"),p=p.replace(/^---$/gm,"<hr>");const b=[];let y=0;return p=p.replace(/<[^>]+>[\s\S]*?<\/[^>]+>/g,_=>{const S=`__PROTECTED_HTML_${y++}__`;return b.push(_),S}),p=p.replace(/<[^>]+>/g,_=>{const S=`__PROTECTED_HTML_${y++}__`;return b.push(_),S}),p=p.replace(/\n\n/g,"</p><p>"),p=p.replace(/\n/g,"<br>"),b.forEach((_,S)=>{p=p.replace(`__PROTECTED_HTML_${S}__`,_)}),p&&!p.startsWith("<")&&(p=`<p>${p}</p>`),p},[e,s,n]),u=(h,p)=>h.replace(/</g,"&lt;").replace(/>/g,"&gt;"),g=M.useCallback(h=>{const w=h.target.closest("button");if(w){if(w.classList.contains("copy-btn")){const m=decodeURIComponent(w.getAttribute("data-code")||"");i(m)}else if(w.classList.contains("apply-btn")){const m=decodeURIComponent(w.getAttribute("data-code")||""),f=w.getAttribute("data-language")||"text";n==null||n(m,f)}else if(w.classList.contains("expand-btn")){const m=w.getAttribute("data-block-id");m&&l(m)}}},[i,n,l]);return o.jsxs("div",{className:`markdown-renderer ${t}`,onClick:g,children:[o.jsx("div",{dangerouslySetInnerHTML:{__html:d(r)}}),e&&o.jsx("span",{className:"streaming-cursor"})]})};function Hl(r){var e,t,n="";if(typeof r=="string"||typeof r=="number")n+=r;else if(typeof r=="object")if(Array.isArray(r)){var s=r.length;for(e=0;e<s;e++)r[e]&&(t=Hl(r[e]))&&(n&&(n+=" "),n+=t)}else for(t in r)r[t]&&(n&&(n+=" "),n+=t);return n}function Kf(){for(var r,e,t=0,n="",s=arguments.length;t<s;t++)(r=arguments[t])&&(e=Hl(r))&&(n&&(n+=" "),n+=e);return n}const mo="-",Yf=r=>{const e=Zf(r),{conflictingClassGroups:t,conflictingClassGroupModifiers:n}=r;return{getClassGroupId:i=>{const l=i.split(mo);return l[0]===""&&l.length!==1&&l.shift(),ql(l,e)||Qf(i)},getConflictingClassGroupIds:(i,l)=>{const d=t[i]||[];return l&&n[i]?[...d,...n[i]]:d}}},ql=(r,e)=>{var i;if(r.length===0)return e.classGroupId;const t=r[0],n=e.nextPart.get(t),s=n?ql(r.slice(1),n):void 0;if(s)return s;if(e.validators.length===0)return;const a=r.join(mo);return(i=e.validators.find(({validator:l})=>l(a)))==null?void 0:i.classGroupId},Sa=/^\[(.+)\]$/,Qf=r=>{if(Sa.test(r)){const e=Sa.exec(r)[1],t=e==null?void 0:e.substring(0,e.indexOf(":"));if(t)return"arbitrary.."+t}},Zf=r=>{const{theme:e,prefix:t}=r,n={nextPart:new Map,validators:[]};return th(Object.entries(r.classGroups),t).forEach(([a,i])=>{ws(i,n,a,e)}),n},ws=(r,e,t,n)=>{r.forEach(s=>{if(typeof s=="string"){const a=s===""?e:Ca(e,s);a.classGroupId=t;return}if(typeof s=="function"){if(eh(s)){ws(s(n),e,t,n);return}e.validators.push({validator:s,classGroupId:t});return}Object.entries(s).forEach(([a,i])=>{ws(i,Ca(e,a),t,n)})})},Ca=(r,e)=>{let t=r;return e.split(mo).forEach(n=>{t.nextPart.has(n)||t.nextPart.set(n,{nextPart:new Map,validators:[]}),t=t.nextPart.get(n)}),t},eh=r=>r.isThemeGetter,th=(r,e)=>e?r.map(([t,n])=>{const s=n.map(a=>typeof a=="string"?e+a:typeof a=="object"?Object.fromEntries(Object.entries(a).map(([i,l])=>[e+i,l])):a);return[t,s]}):r,rh=r=>{if(r<1)return{get:()=>{},set:()=>{}};let e=0,t=new Map,n=new Map;const s=(a,i)=>{t.set(a,i),e++,e>r&&(e=0,n=t,t=new Map)};return{get(a){let i=t.get(a);if(i!==void 0)return i;if((i=n.get(a))!==void 0)return s(a,i),i},set(a,i){t.has(a)?t.set(a,i):s(a,i)}}},zl="!",nh=r=>{const{separator:e,experimentalParseClassName:t}=r,n=e.length===1,s=e[0],a=e.length,i=l=>{const d=[];let u=0,g=0,h;for(let c=0;c<l.length;c++){let x=l[c];if(u===0){if(x===s&&(n||l.slice(c,c+a)===e)){d.push(l.slice(g,c)),g=c+a;continue}if(x==="/"){h=c;continue}}x==="["?u++:x==="]"&&u--}const p=d.length===0?l:l.substring(g),w=p.startsWith(zl),m=w?p.substring(1):p,f=h&&h>g?h-g:void 0;return{modifiers:d,hasImportantModifier:w,baseClassName:m,maybePostfixModifierPosition:f}};return t?l=>t({className:l,parseClassName:i}):i},sh=r=>{if(r.length<=1)return r;const e=[];let t=[];return r.forEach(n=>{n[0]==="["?(e.push(...t.sort(),n),t=[]):t.push(n)}),e.push(...t.sort()),e},oh=r=>({cache:rh(r.cacheSize),parseClassName:nh(r),...Yf(r)}),ah=/\s+/,ih=(r,e)=>{const{parseClassName:t,getClassGroupId:n,getConflictingClassGroupIds:s}=e,a=[],i=r.trim().split(ah);let l="";for(let d=i.length-1;d>=0;d-=1){const u=i[d],{modifiers:g,hasImportantModifier:h,baseClassName:p,maybePostfixModifierPosition:w}=t(u);let m=!!w,f=n(m?p.substring(0,w):p);if(!f){if(!m){l=u+(l.length>0?" "+l:l);continue}if(f=n(p),!f){l=u+(l.length>0?" "+l:l);continue}m=!1}const c=sh(g).join(":"),x=h?c+zl:c,b=x+f;if(a.includes(b))continue;a.push(b);const y=s(f,m);for(let _=0;_<y.length;++_){const S=y[_];a.push(x+S)}l=u+(l.length>0?" "+l:l)}return l};function lh(){let r=0,e,t,n="";for(;r<arguments.length;)(e=arguments[r++])&&(t=Jl(e))&&(n&&(n+=" "),n+=t);return n}const Jl=r=>{if(typeof r=="string")return r;let e,t="";for(let n=0;n<r.length;n++)r[n]&&(e=Jl(r[n]))&&(t&&(t+=" "),t+=e);return t};function ch(r,...e){let t,n,s,a=i;function i(d){const u=e.reduce((g,h)=>h(g),r());return t=oh(u),n=t.cache.get,s=t.cache.set,a=l,l(d)}function l(d){const u=n(d);if(u)return u;const g=ih(d,t);return s(d,g),g}return function(){return a(lh.apply(null,arguments))}}const oe=r=>{const e=t=>t[r]||[];return e.isThemeGetter=!0,e},Vl=/^\[(?:([a-z-]+):)?(.+)\]$/i,dh=/^\d+\/\d+$/,uh=new Set(["px","full","screen"]),fh=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,hh=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,mh=/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/,gh=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ph=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Be=r=>jt(r)||uh.has(r)||dh.test(r),Xe=r=>Ot(r,"length",Ch),jt=r=>!!r&&!Number.isNaN(Number(r)),Jn=r=>Ot(r,"number",jt),Ft=r=>!!r&&Number.isInteger(Number(r)),xh=r=>r.endsWith("%")&&jt(r.slice(0,-1)),ee=r=>Vl.test(r),Ke=r=>fh.test(r),bh=new Set(["length","size","percentage"]),yh=r=>Ot(r,bh,Gl),wh=r=>Ot(r,"position",Gl),vh=new Set(["image","url"]),_h=r=>Ot(r,vh,Ah),Sh=r=>Ot(r,"",jh),Ut=()=>!0,Ot=(r,e,t)=>{const n=Vl.exec(r);return n?n[1]?typeof e=="string"?n[1]===e:e.has(n[1]):t(n[2]):!1},Ch=r=>hh.test(r)&&!mh.test(r),Gl=()=>!1,jh=r=>gh.test(r),Ah=r=>ph.test(r),kh=()=>{const r=oe("colors"),e=oe("spacing"),t=oe("blur"),n=oe("brightness"),s=oe("borderColor"),a=oe("borderRadius"),i=oe("borderSpacing"),l=oe("borderWidth"),d=oe("contrast"),u=oe("grayscale"),g=oe("hueRotate"),h=oe("invert"),p=oe("gap"),w=oe("gradientColorStops"),m=oe("gradientColorStopPositions"),f=oe("inset"),c=oe("margin"),x=oe("opacity"),b=oe("padding"),y=oe("saturate"),_=oe("scale"),S=oe("sepia"),j=oe("skew"),v=oe("space"),I=oe("translate"),P=()=>["auto","contain","none"],T=()=>["auto","hidden","clip","visible","scroll"],L=()=>["auto",ee,e],C=()=>[ee,e],W=()=>["",Be,Xe],B=()=>["auto",jt,ee],z=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],O=()=>["solid","dashed","dotted","double","none"],U=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],J=()=>["start","end","center","between","around","evenly","stretch"],$=()=>["","0",ee],H=()=>["auto","avoid","all","avoid-page","page","left","right","column"],F=()=>[jt,ee];return{cacheSize:500,separator:":",theme:{colors:[Ut],spacing:[Be,Xe],blur:["none","",Ke,ee],brightness:F(),borderColor:[r],borderRadius:["none","","full",Ke,ee],borderSpacing:C(),borderWidth:W(),contrast:F(),grayscale:$(),hueRotate:F(),invert:$(),gap:C(),gradientColorStops:[r],gradientColorStopPositions:[xh,Xe],inset:L(),margin:L(),opacity:F(),padding:C(),saturate:F(),scale:F(),sepia:$(),skew:F(),space:C(),translate:C()},classGroups:{aspect:[{aspect:["auto","square","video",ee]}],container:["container"],columns:[{columns:[Ke]}],"break-after":[{"break-after":H()}],"break-before":[{"break-before":H()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...z(),ee]}],overflow:[{overflow:T()}],"overflow-x":[{"overflow-x":T()}],"overflow-y":[{"overflow-y":T()}],overscroll:[{overscroll:P()}],"overscroll-x":[{"overscroll-x":P()}],"overscroll-y":[{"overscroll-y":P()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[f]}],"inset-x":[{"inset-x":[f]}],"inset-y":[{"inset-y":[f]}],start:[{start:[f]}],end:[{end:[f]}],top:[{top:[f]}],right:[{right:[f]}],bottom:[{bottom:[f]}],left:[{left:[f]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",Ft,ee]}],basis:[{basis:L()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",ee]}],grow:[{grow:$()}],shrink:[{shrink:$()}],order:[{order:["first","last","none",Ft,ee]}],"grid-cols":[{"grid-cols":[Ut]}],"col-start-end":[{col:["auto",{span:["full",Ft,ee]},ee]}],"col-start":[{"col-start":B()}],"col-end":[{"col-end":B()}],"grid-rows":[{"grid-rows":[Ut]}],"row-start-end":[{row:["auto",{span:[Ft,ee]},ee]}],"row-start":[{"row-start":B()}],"row-end":[{"row-end":B()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",ee]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",ee]}],gap:[{gap:[p]}],"gap-x":[{"gap-x":[p]}],"gap-y":[{"gap-y":[p]}],"justify-content":[{justify:["normal",...J()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...J(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...J(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[b]}],px:[{px:[b]}],py:[{py:[b]}],ps:[{ps:[b]}],pe:[{pe:[b]}],pt:[{pt:[b]}],pr:[{pr:[b]}],pb:[{pb:[b]}],pl:[{pl:[b]}],m:[{m:[c]}],mx:[{mx:[c]}],my:[{my:[c]}],ms:[{ms:[c]}],me:[{me:[c]}],mt:[{mt:[c]}],mr:[{mr:[c]}],mb:[{mb:[c]}],ml:[{ml:[c]}],"space-x":[{"space-x":[v]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[v]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",ee,e]}],"min-w":[{"min-w":[ee,e,"min","max","fit"]}],"max-w":[{"max-w":[ee,e,"none","full","min","max","fit","prose",{screen:[Ke]},Ke]}],h:[{h:[ee,e,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[ee,e,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[ee,e,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[ee,e,"auto","min","max","fit"]}],"font-size":[{text:["base",Ke,Xe]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Jn]}],"font-family":[{font:[Ut]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",ee]}],"line-clamp":[{"line-clamp":["none",jt,Jn]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",Be,ee]}],"list-image":[{"list-image":["none",ee]}],"list-style-type":[{list:["none","disc","decimal",ee]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[r]}],"placeholder-opacity":[{"placeholder-opacity":[x]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[r]}],"text-opacity":[{"text-opacity":[x]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...O(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",Be,Xe]}],"underline-offset":[{"underline-offset":["auto",Be,ee]}],"text-decoration-color":[{decoration:[r]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:C()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",ee]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",ee]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[x]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...z(),wh]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",yh]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},_h]}],"bg-color":[{bg:[r]}],"gradient-from-pos":[{from:[m]}],"gradient-via-pos":[{via:[m]}],"gradient-to-pos":[{to:[m]}],"gradient-from":[{from:[w]}],"gradient-via":[{via:[w]}],"gradient-to":[{to:[w]}],rounded:[{rounded:[a]}],"rounded-s":[{"rounded-s":[a]}],"rounded-e":[{"rounded-e":[a]}],"rounded-t":[{"rounded-t":[a]}],"rounded-r":[{"rounded-r":[a]}],"rounded-b":[{"rounded-b":[a]}],"rounded-l":[{"rounded-l":[a]}],"rounded-ss":[{"rounded-ss":[a]}],"rounded-se":[{"rounded-se":[a]}],"rounded-ee":[{"rounded-ee":[a]}],"rounded-es":[{"rounded-es":[a]}],"rounded-tl":[{"rounded-tl":[a]}],"rounded-tr":[{"rounded-tr":[a]}],"rounded-br":[{"rounded-br":[a]}],"rounded-bl":[{"rounded-bl":[a]}],"border-w":[{border:[l]}],"border-w-x":[{"border-x":[l]}],"border-w-y":[{"border-y":[l]}],"border-w-s":[{"border-s":[l]}],"border-w-e":[{"border-e":[l]}],"border-w-t":[{"border-t":[l]}],"border-w-r":[{"border-r":[l]}],"border-w-b":[{"border-b":[l]}],"border-w-l":[{"border-l":[l]}],"border-opacity":[{"border-opacity":[x]}],"border-style":[{border:[...O(),"hidden"]}],"divide-x":[{"divide-x":[l]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[l]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[x]}],"divide-style":[{divide:O()}],"border-color":[{border:[s]}],"border-color-x":[{"border-x":[s]}],"border-color-y":[{"border-y":[s]}],"border-color-s":[{"border-s":[s]}],"border-color-e":[{"border-e":[s]}],"border-color-t":[{"border-t":[s]}],"border-color-r":[{"border-r":[s]}],"border-color-b":[{"border-b":[s]}],"border-color-l":[{"border-l":[s]}],"divide-color":[{divide:[s]}],"outline-style":[{outline:["",...O()]}],"outline-offset":[{"outline-offset":[Be,ee]}],"outline-w":[{outline:[Be,Xe]}],"outline-color":[{outline:[r]}],"ring-w":[{ring:W()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[r]}],"ring-opacity":[{"ring-opacity":[x]}],"ring-offset-w":[{"ring-offset":[Be,Xe]}],"ring-offset-color":[{"ring-offset":[r]}],shadow:[{shadow:["","inner","none",Ke,Sh]}],"shadow-color":[{shadow:[Ut]}],opacity:[{opacity:[x]}],"mix-blend":[{"mix-blend":[...U(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":U()}],filter:[{filter:["","none"]}],blur:[{blur:[t]}],brightness:[{brightness:[n]}],contrast:[{contrast:[d]}],"drop-shadow":[{"drop-shadow":["","none",Ke,ee]}],grayscale:[{grayscale:[u]}],"hue-rotate":[{"hue-rotate":[g]}],invert:[{invert:[h]}],saturate:[{saturate:[y]}],sepia:[{sepia:[S]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[t]}],"backdrop-brightness":[{"backdrop-brightness":[n]}],"backdrop-contrast":[{"backdrop-contrast":[d]}],"backdrop-grayscale":[{"backdrop-grayscale":[u]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[g]}],"backdrop-invert":[{"backdrop-invert":[h]}],"backdrop-opacity":[{"backdrop-opacity":[x]}],"backdrop-saturate":[{"backdrop-saturate":[y]}],"backdrop-sepia":[{"backdrop-sepia":[S]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[i]}],"border-spacing-x":[{"border-spacing-x":[i]}],"border-spacing-y":[{"border-spacing-y":[i]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",ee]}],duration:[{duration:F()}],ease:[{ease:["linear","in","out","in-out",ee]}],delay:[{delay:F()}],animate:[{animate:["none","spin","ping","pulse","bounce",ee]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[_]}],"scale-x":[{"scale-x":[_]}],"scale-y":[{"scale-y":[_]}],rotate:[{rotate:[Ft,ee]}],"translate-x":[{"translate-x":[I]}],"translate-y":[{"translate-y":[I]}],"skew-x":[{"skew-x":[j]}],"skew-y":[{"skew-y":[j]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",ee]}],accent:[{accent:["auto",r]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",ee]}],"caret-color":[{caret:[r]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":C()}],"scroll-mx":[{"scroll-mx":C()}],"scroll-my":[{"scroll-my":C()}],"scroll-ms":[{"scroll-ms":C()}],"scroll-me":[{"scroll-me":C()}],"scroll-mt":[{"scroll-mt":C()}],"scroll-mr":[{"scroll-mr":C()}],"scroll-mb":[{"scroll-mb":C()}],"scroll-ml":[{"scroll-ml":C()}],"scroll-p":[{"scroll-p":C()}],"scroll-px":[{"scroll-px":C()}],"scroll-py":[{"scroll-py":C()}],"scroll-ps":[{"scroll-ps":C()}],"scroll-pe":[{"scroll-pe":C()}],"scroll-pt":[{"scroll-pt":C()}],"scroll-pr":[{"scroll-pr":C()}],"scroll-pb":[{"scroll-pb":C()}],"scroll-pl":[{"scroll-pl":C()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",ee]}],fill:[{fill:[r,"none"]}],"stroke-w":[{stroke:[Be,Xe,Jn]}],stroke:[{stroke:[r,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},Nh=ch(kh);let Ir;const Mh=new Uint8Array(16);function Eh(){if(!Ir&&(Ir=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ir))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ir(Mh)}const me=[];for(let r=0;r<256;++r)me.push((r+256).toString(16).slice(1));function Ih(r,e=0){return me[r[e+0]]+me[r[e+1]]+me[r[e+2]]+me[r[e+3]]+"-"+me[r[e+4]]+me[r[e+5]]+"-"+me[r[e+6]]+me[r[e+7]]+"-"+me[r[e+8]]+me[r[e+9]]+"-"+me[r[e+10]]+me[r[e+11]]+me[r[e+12]]+me[r[e+13]]+me[r[e+14]]+me[r[e+15]]}const Ph=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ja={randomUUID:Ph};function Th(r,e,t){if(ja.randomUUID&&!r)return ja.randomUUID();r=r||{};const n=r.random||(r.rng||Eh)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ih(n)}const Xl=6048e5,Oh=864e5,Pr=43200,Aa=1440,ka=Symbol.for("constructDateFrom");function He(r,e){return typeof r=="function"?r(e):r&&typeof r=="object"&&ka in r?r[ka](e):r instanceof Date?new r.constructor(e):new Date(e)}function he(r,e){return He(e||r,r)}let Rh={};function pr(){return Rh}function nr(r,e){var l,d,u,g;const t=pr(),n=(e==null?void 0:e.weekStartsOn)??((d=(l=e==null?void 0:e.locale)==null?void 0:l.options)==null?void 0:d.weekStartsOn)??t.weekStartsOn??((g=(u=t.locale)==null?void 0:u.options)==null?void 0:g.weekStartsOn)??0,s=he(r,e==null?void 0:e.in),a=s.getDay(),i=(a<n?7:0)+a-n;return s.setDate(s.getDate()-i),s.setHours(0,0,0,0),s}function en(r,e){return nr(r,{...e,weekStartsOn:1})}function Kl(r,e){const t=he(r,e==null?void 0:e.in),n=t.getFullYear(),s=He(t,0);s.setFullYear(n+1,0,4),s.setHours(0,0,0,0);const a=en(s),i=He(t,0);i.setFullYear(n,0,4),i.setHours(0,0,0,0);const l=en(i);return t.getTime()>=a.getTime()?n+1:t.getTime()>=l.getTime()?n:n-1}function tn(r){const e=he(r),t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),+r-+t}function jn(r,...e){const t=He.bind(null,r||e.find(n=>typeof n=="object"));return e.map(t)}function Na(r,e){const t=he(r,e==null?void 0:e.in);return t.setHours(0,0,0,0),t}function $h(r,e,t){const[n,s]=jn(t==null?void 0:t.in,r,e),a=Na(n),i=Na(s),l=+a-tn(a),d=+i-tn(i);return Math.round((l-d)/Oh)}function Lh(r,e){const t=Kl(r,e),n=He(r,0);return n.setFullYear(t,0,4),n.setHours(0,0,0,0),en(n)}function qr(r,e){const t=+he(r)-+he(e);return t<0?-1:t>0?1:t}function Dh(r){return He(r,Date.now())}function Fh(r){return r instanceof Date||typeof r=="object"&&Object.prototype.toString.call(r)==="[object Date]"}function Uh(r){return!(!Fh(r)&&typeof r!="number"||isNaN(+he(r)))}function Bh(r,e,t){const[n,s]=jn(t==null?void 0:t.in,r,e),a=n.getFullYear()-s.getFullYear(),i=n.getMonth()-s.getMonth();return a*12+i}function Wh(r){return e=>{const n=(r?Math[r]:Math.trunc)(e);return n===0?0:n}}function Hh(r,e){return+he(r)-+he(e)}function qh(r,e){const t=he(r,e==null?void 0:e.in);return t.setHours(23,59,59,999),t}function zh(r,e){const t=he(r,e==null?void 0:e.in),n=t.getMonth();return t.setFullYear(t.getFullYear(),n+1,0),t.setHours(23,59,59,999),t}function Jh(r,e){const t=he(r,e==null?void 0:e.in);return+qh(t,e)==+zh(t,e)}function Vh(r,e,t){const[n,s,a]=jn(t==null?void 0:t.in,r,r,e),i=qr(s,a),l=Math.abs(Bh(s,a));if(l<1)return 0;s.getMonth()===1&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-i*l);let d=qr(s,a)===-i;Jh(n)&&l===1&&qr(n,a)===1&&(d=!1);const u=i*(l-+d);return u===0?0:u}function Gh(r,e,t){const n=Hh(r,e)/1e3;return Wh(t==null?void 0:t.roundingMethod)(n)}function Xh(r,e){const t=he(r,e==null?void 0:e.in);return t.setFullYear(t.getFullYear(),0,1),t.setHours(0,0,0,0),t}const Kh={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Yh=(r,e,t)=>{let n;const s=Kh[r];return typeof s=="string"?n=s:e===1?n=s.one:n=s.other.replace("{{count}}",e.toString()),t!=null&&t.addSuffix?t.comparison&&t.comparison>0?"in "+n:n+" ago":n};function Vn(r){return(e={})=>{const t=e.width?String(e.width):r.defaultWidth;return r.formats[t]||r.formats[r.defaultWidth]}}const Qh={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},Zh={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},em={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},tm={date:Vn({formats:Qh,defaultWidth:"full"}),time:Vn({formats:Zh,defaultWidth:"full"}),dateTime:Vn({formats:em,defaultWidth:"full"})},rm={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},nm=(r,e,t,n)=>rm[r];function Bt(r){return(e,t)=>{const n=t!=null&&t.context?String(t.context):"standalone";let s;if(n==="formatting"&&r.formattingValues){const i=r.defaultFormattingWidth||r.defaultWidth,l=t!=null&&t.width?String(t.width):i;s=r.formattingValues[l]||r.formattingValues[i]}else{const i=r.defaultWidth,l=t!=null&&t.width?String(t.width):r.defaultWidth;s=r.values[l]||r.values[i]}const a=r.argumentCallback?r.argumentCallback(e):e;return s[a]}}const sm={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},om={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},am={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},im={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},lm={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},cm={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},dm=(r,e)=>{const t=Number(r),n=t%100;if(n>20||n<10)switch(n%10){case 1:return t+"st";case 2:return t+"nd";case 3:return t+"rd"}return t+"th"},um={ordinalNumber:dm,era:Bt({values:sm,defaultWidth:"wide"}),quarter:Bt({values:om,defaultWidth:"wide",argumentCallback:r=>r-1}),month:Bt({values:am,defaultWidth:"wide"}),day:Bt({values:im,defaultWidth:"wide"}),dayPeriod:Bt({values:lm,defaultWidth:"wide",formattingValues:cm,defaultFormattingWidth:"wide"})};function Wt(r){return(e,t={})=>{const n=t.width,s=n&&r.matchPatterns[n]||r.matchPatterns[r.defaultMatchWidth],a=e.match(s);if(!a)return null;const i=a[0],l=n&&r.parsePatterns[n]||r.parsePatterns[r.defaultParseWidth],d=Array.isArray(l)?hm(l,h=>h.test(i)):fm(l,h=>h.test(i));let u;u=r.valueCallback?r.valueCallback(d):d,u=t.valueCallback?t.valueCallback(u):u;const g=e.slice(i.length);return{value:u,rest:g}}}function fm(r,e){for(const t in r)if(Object.prototype.hasOwnProperty.call(r,t)&&e(r[t]))return t}function hm(r,e){for(let t=0;t<r.length;t++)if(e(r[t]))return t}function mm(r){return(e,t={})=>{const n=e.match(r.matchPattern);if(!n)return null;const s=n[0],a=e.match(r.parsePattern);if(!a)return null;let i=r.valueCallback?r.valueCallback(a[0]):a[0];i=t.valueCallback?t.valueCallback(i):i;const l=e.slice(s.length);return{value:i,rest:l}}}const gm=/^(\d+)(th|st|nd|rd)?/i,pm=/\d+/i,xm={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},bm={any:[/^b/i,/^(a|c)/i]},ym={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},wm={any:[/1/i,/2/i,/3/i,/4/i]},vm={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},_m={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Sm={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},Cm={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},jm={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},Am={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},km={ordinalNumber:mm({matchPattern:gm,parsePattern:pm,valueCallback:r=>parseInt(r,10)}),era:Wt({matchPatterns:xm,defaultMatchWidth:"wide",parsePatterns:bm,defaultParseWidth:"any"}),quarter:Wt({matchPatterns:ym,defaultMatchWidth:"wide",parsePatterns:wm,defaultParseWidth:"any",valueCallback:r=>r+1}),month:Wt({matchPatterns:vm,defaultMatchWidth:"wide",parsePatterns:_m,defaultParseWidth:"any"}),day:Wt({matchPatterns:Sm,defaultMatchWidth:"wide",parsePatterns:Cm,defaultParseWidth:"any"}),dayPeriod:Wt({matchPatterns:jm,defaultMatchWidth:"any",parsePatterns:Am,defaultParseWidth:"any"})},Yl={code:"en-US",formatDistance:Yh,formatLong:tm,formatRelative:nm,localize:um,match:km,options:{weekStartsOn:0,firstWeekContainsDate:1}};function Nm(r,e){const t=he(r,e==null?void 0:e.in);return $h(t,Xh(t))+1}function Mm(r,e){const t=he(r,e==null?void 0:e.in),n=+en(t)-+Lh(t);return Math.round(n/Xl)+1}function Ql(r,e){var g,h,p,w;const t=he(r,e==null?void 0:e.in),n=t.getFullYear(),s=pr(),a=(e==null?void 0:e.firstWeekContainsDate)??((h=(g=e==null?void 0:e.locale)==null?void 0:g.options)==null?void 0:h.firstWeekContainsDate)??s.firstWeekContainsDate??((w=(p=s.locale)==null?void 0:p.options)==null?void 0:w.firstWeekContainsDate)??1,i=He((e==null?void 0:e.in)||r,0);i.setFullYear(n+1,0,a),i.setHours(0,0,0,0);const l=nr(i,e),d=He((e==null?void 0:e.in)||r,0);d.setFullYear(n,0,a),d.setHours(0,0,0,0);const u=nr(d,e);return+t>=+l?n+1:+t>=+u?n:n-1}function Em(r,e){var l,d,u,g;const t=pr(),n=(e==null?void 0:e.firstWeekContainsDate)??((d=(l=e==null?void 0:e.locale)==null?void 0:l.options)==null?void 0:d.firstWeekContainsDate)??t.firstWeekContainsDate??((g=(u=t.locale)==null?void 0:u.options)==null?void 0:g.firstWeekContainsDate)??1,s=Ql(r,e),a=He((e==null?void 0:e.in)||r,0);return a.setFullYear(s,0,n),a.setHours(0,0,0,0),nr(a,e)}function Im(r,e){const t=he(r,e==null?void 0:e.in),n=+nr(t,e)-+Em(t,e);return Math.round(n/Xl)+1}function re(r,e){const t=r<0?"-":"",n=Math.abs(r).toString().padStart(e,"0");return t+n}const Ye={y(r,e){const t=r.getFullYear(),n=t>0?t:1-t;return re(e==="yy"?n%100:n,e.length)},M(r,e){const t=r.getMonth();return e==="M"?String(t+1):re(t+1,2)},d(r,e){return re(r.getDate(),e.length)},a(r,e){const t=r.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return t.toUpperCase();case"aaa":return t;case"aaaaa":return t[0];case"aaaa":default:return t==="am"?"a.m.":"p.m."}},h(r,e){return re(r.getHours()%12||12,e.length)},H(r,e){return re(r.getHours(),e.length)},m(r,e){return re(r.getMinutes(),e.length)},s(r,e){return re(r.getSeconds(),e.length)},S(r,e){const t=e.length,n=r.getMilliseconds(),s=Math.trunc(n*Math.pow(10,t-3));return re(s,e.length)}},yt={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},Ma={G:function(r,e,t){const n=r.getFullYear()>0?1:0;switch(e){case"G":case"GG":case"GGG":return t.era(n,{width:"abbreviated"});case"GGGGG":return t.era(n,{width:"narrow"});case"GGGG":default:return t.era(n,{width:"wide"})}},y:function(r,e,t){if(e==="yo"){const n=r.getFullYear(),s=n>0?n:1-n;return t.ordinalNumber(s,{unit:"year"})}return Ye.y(r,e)},Y:function(r,e,t,n){const s=Ql(r,n),a=s>0?s:1-s;if(e==="YY"){const i=a%100;return re(i,2)}return e==="Yo"?t.ordinalNumber(a,{unit:"year"}):re(a,e.length)},R:function(r,e){const t=Kl(r);return re(t,e.length)},u:function(r,e){const t=r.getFullYear();return re(t,e.length)},Q:function(r,e,t){const n=Math.ceil((r.getMonth()+1)/3);switch(e){case"Q":return String(n);case"QQ":return re(n,2);case"Qo":return t.ordinalNumber(n,{unit:"quarter"});case"QQQ":return t.quarter(n,{width:"abbreviated",context:"formatting"});case"QQQQQ":return t.quarter(n,{width:"narrow",context:"formatting"});case"QQQQ":default:return t.quarter(n,{width:"wide",context:"formatting"})}},q:function(r,e,t){const n=Math.ceil((r.getMonth()+1)/3);switch(e){case"q":return String(n);case"qq":return re(n,2);case"qo":return t.ordinalNumber(n,{unit:"quarter"});case"qqq":return t.quarter(n,{width:"abbreviated",context:"standalone"});case"qqqqq":return t.quarter(n,{width:"narrow",context:"standalone"});case"qqqq":default:return t.quarter(n,{width:"wide",context:"standalone"})}},M:function(r,e,t){const n=r.getMonth();switch(e){case"M":case"MM":return Ye.M(r,e);case"Mo":return t.ordinalNumber(n+1,{unit:"month"});case"MMM":return t.month(n,{width:"abbreviated",context:"formatting"});case"MMMMM":return t.month(n,{width:"narrow",context:"formatting"});case"MMMM":default:return t.month(n,{width:"wide",context:"formatting"})}},L:function(r,e,t){const n=r.getMonth();switch(e){case"L":return String(n+1);case"LL":return re(n+1,2);case"Lo":return t.ordinalNumber(n+1,{unit:"month"});case"LLL":return t.month(n,{width:"abbreviated",context:"standalone"});case"LLLLL":return t.month(n,{width:"narrow",context:"standalone"});case"LLLL":default:return t.month(n,{width:"wide",context:"standalone"})}},w:function(r,e,t,n){const s=Im(r,n);return e==="wo"?t.ordinalNumber(s,{unit:"week"}):re(s,e.length)},I:function(r,e,t){const n=Mm(r);return e==="Io"?t.ordinalNumber(n,{unit:"week"}):re(n,e.length)},d:function(r,e,t){return e==="do"?t.ordinalNumber(r.getDate(),{unit:"date"}):Ye.d(r,e)},D:function(r,e,t){const n=Nm(r);return e==="Do"?t.ordinalNumber(n,{unit:"dayOfYear"}):re(n,e.length)},E:function(r,e,t){const n=r.getDay();switch(e){case"E":case"EE":case"EEE":return t.day(n,{width:"abbreviated",context:"formatting"});case"EEEEE":return t.day(n,{width:"narrow",context:"formatting"});case"EEEEEE":return t.day(n,{width:"short",context:"formatting"});case"EEEE":default:return t.day(n,{width:"wide",context:"formatting"})}},e:function(r,e,t,n){const s=r.getDay(),a=(s-n.weekStartsOn+8)%7||7;switch(e){case"e":return String(a);case"ee":return re(a,2);case"eo":return t.ordinalNumber(a,{unit:"day"});case"eee":return t.day(s,{width:"abbreviated",context:"formatting"});case"eeeee":return t.day(s,{width:"narrow",context:"formatting"});case"eeeeee":return t.day(s,{width:"short",context:"formatting"});case"eeee":default:return t.day(s,{width:"wide",context:"formatting"})}},c:function(r,e,t,n){const s=r.getDay(),a=(s-n.weekStartsOn+8)%7||7;switch(e){case"c":return String(a);case"cc":return re(a,e.length);case"co":return t.ordinalNumber(a,{unit:"day"});case"ccc":return t.day(s,{width:"abbreviated",context:"standalone"});case"ccccc":return t.day(s,{width:"narrow",context:"standalone"});case"cccccc":return t.day(s,{width:"short",context:"standalone"});case"cccc":default:return t.day(s,{width:"wide",context:"standalone"})}},i:function(r,e,t){const n=r.getDay(),s=n===0?7:n;switch(e){case"i":return String(s);case"ii":return re(s,e.length);case"io":return t.ordinalNumber(s,{unit:"day"});case"iii":return t.day(n,{width:"abbreviated",context:"formatting"});case"iiiii":return t.day(n,{width:"narrow",context:"formatting"});case"iiiiii":return t.day(n,{width:"short",context:"formatting"});case"iiii":default:return t.day(n,{width:"wide",context:"formatting"})}},a:function(r,e,t){const s=r.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return t.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"aaa":return t.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return t.dayPeriod(s,{width:"narrow",context:"formatting"});case"aaaa":default:return t.dayPeriod(s,{width:"wide",context:"formatting"})}},b:function(r,e,t){const n=r.getHours();let s;switch(n===12?s=yt.noon:n===0?s=yt.midnight:s=n/12>=1?"pm":"am",e){case"b":case"bb":return t.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"bbb":return t.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return t.dayPeriod(s,{width:"narrow",context:"formatting"});case"bbbb":default:return t.dayPeriod(s,{width:"wide",context:"formatting"})}},B:function(r,e,t){const n=r.getHours();let s;switch(n>=17?s=yt.evening:n>=12?s=yt.afternoon:n>=4?s=yt.morning:s=yt.night,e){case"B":case"BB":case"BBB":return t.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"BBBBB":return t.dayPeriod(s,{width:"narrow",context:"formatting"});case"BBBB":default:return t.dayPeriod(s,{width:"wide",context:"formatting"})}},h:function(r,e,t){if(e==="ho"){let n=r.getHours()%12;return n===0&&(n=12),t.ordinalNumber(n,{unit:"hour"})}return Ye.h(r,e)},H:function(r,e,t){return e==="Ho"?t.ordinalNumber(r.getHours(),{unit:"hour"}):Ye.H(r,e)},K:function(r,e,t){const n=r.getHours()%12;return e==="Ko"?t.ordinalNumber(n,{unit:"hour"}):re(n,e.length)},k:function(r,e,t){let n=r.getHours();return n===0&&(n=24),e==="ko"?t.ordinalNumber(n,{unit:"hour"}):re(n,e.length)},m:function(r,e,t){return e==="mo"?t.ordinalNumber(r.getMinutes(),{unit:"minute"}):Ye.m(r,e)},s:function(r,e,t){return e==="so"?t.ordinalNumber(r.getSeconds(),{unit:"second"}):Ye.s(r,e)},S:function(r,e){return Ye.S(r,e)},X:function(r,e,t){const n=r.getTimezoneOffset();if(n===0)return"Z";switch(e){case"X":return Ia(n);case"XXXX":case"XX":return st(n);case"XXXXX":case"XXX":default:return st(n,":")}},x:function(r,e,t){const n=r.getTimezoneOffset();switch(e){case"x":return Ia(n);case"xxxx":case"xx":return st(n);case"xxxxx":case"xxx":default:return st(n,":")}},O:function(r,e,t){const n=r.getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+Ea(n,":");case"OOOO":default:return"GMT"+st(n,":")}},z:function(r,e,t){const n=r.getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+Ea(n,":");case"zzzz":default:return"GMT"+st(n,":")}},t:function(r,e,t){const n=Math.trunc(+r/1e3);return re(n,e.length)},T:function(r,e,t){return re(+r,e.length)}};function Ea(r,e=""){const t=r>0?"-":"+",n=Math.abs(r),s=Math.trunc(n/60),a=n%60;return a===0?t+String(s):t+String(s)+e+re(a,2)}function Ia(r,e){return r%60===0?(r>0?"-":"+")+re(Math.abs(r)/60,2):st(r,e)}function st(r,e=""){const t=r>0?"-":"+",n=Math.abs(r),s=re(Math.trunc(n/60),2),a=re(n%60,2);return t+s+e+a}const Pa=(r,e)=>{switch(r){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});case"PPPP":default:return e.date({width:"full"})}},Zl=(r,e)=>{switch(r){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});case"pppp":default:return e.time({width:"full"})}},Pm=(r,e)=>{const t=r.match(/(P+)(p+)?/)||[],n=t[1],s=t[2];if(!s)return Pa(r,e);let a;switch(n){case"P":a=e.dateTime({width:"short"});break;case"PP":a=e.dateTime({width:"medium"});break;case"PPP":a=e.dateTime({width:"long"});break;case"PPPP":default:a=e.dateTime({width:"full"});break}return a.replace("{{date}}",Pa(n,e)).replace("{{time}}",Zl(s,e))},Tm={p:Zl,P:Pm},Om=/^D+$/,Rm=/^Y+$/,$m=["D","DD","YY","YYYY"];function Lm(r){return Om.test(r)}function Dm(r){return Rm.test(r)}function Fm(r,e,t){const n=Um(r,e,t);if(console.warn(n),$m.includes(r))throw new RangeError(n)}function Um(r,e,t){const n=r[0]==="Y"?"years":"days of the month";return`Use \`${r.toLowerCase()}\` instead of \`${r}\` (in \`${e}\`) for formatting ${n} to the input \`${t}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const Bm=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Wm=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Hm=/^'([^]*?)'?$/,qm=/''/g,zm=/[a-zA-Z]/;function go(r,e,t){var g,h,p,w;const n=pr(),s=n.locale??Yl,a=n.firstWeekContainsDate??((h=(g=n.locale)==null?void 0:g.options)==null?void 0:h.firstWeekContainsDate)??1,i=n.weekStartsOn??((w=(p=n.locale)==null?void 0:p.options)==null?void 0:w.weekStartsOn)??0,l=he(r,t==null?void 0:t.in);if(!Uh(l))throw new RangeError("Invalid time value");let d=e.match(Wm).map(m=>{const f=m[0];if(f==="p"||f==="P"){const c=Tm[f];return c(m,s.formatLong)}return m}).join("").match(Bm).map(m=>{if(m==="''")return{isToken:!1,value:"'"};const f=m[0];if(f==="'")return{isToken:!1,value:Jm(m)};if(Ma[f])return{isToken:!0,value:m};if(f.match(zm))throw new RangeError("Format string contains an unescaped latin alphabet character `"+f+"`");return{isToken:!1,value:m}});s.localize.preprocessor&&(d=s.localize.preprocessor(l,d));const u={firstWeekContainsDate:a,weekStartsOn:i,locale:s};return d.map(m=>{if(!m.isToken)return m.value;const f=m.value;(Dm(f)||Lm(f))&&Fm(f,e,String(r));const c=Ma[f[0]];return c(l,f,s.localize,u)}).join("")}function Jm(r){const e=r.match(Hm);return e?e[1].replace(qm,"'"):r}function Vm(r,e,t){const n=pr(),s=(t==null?void 0:t.locale)??n.locale??Yl,a=2520,i=qr(r,e);if(isNaN(i))throw new RangeError("Invalid time value");const l=Object.assign({},t,{addSuffix:t==null?void 0:t.addSuffix,comparison:i}),[d,u]=jn(t==null?void 0:t.in,...i>0?[e,r]:[r,e]),g=Gh(u,d),h=(tn(u)-tn(d))/1e3,p=Math.round((g-h)/60);let w;if(p<2)return t!=null&&t.includeSeconds?g<5?s.formatDistance("lessThanXSeconds",5,l):g<10?s.formatDistance("lessThanXSeconds",10,l):g<20?s.formatDistance("lessThanXSeconds",20,l):g<40?s.formatDistance("halfAMinute",0,l):g<60?s.formatDistance("lessThanXMinutes",1,l):s.formatDistance("xMinutes",1,l):p===0?s.formatDistance("lessThanXMinutes",1,l):s.formatDistance("xMinutes",p,l);if(p<45)return s.formatDistance("xMinutes",p,l);if(p<90)return s.formatDistance("aboutXHours",1,l);if(p<Aa){const m=Math.round(p/60);return s.formatDistance("aboutXHours",m,l)}else{if(p<a)return s.formatDistance("xDays",1,l);if(p<Pr){const m=Math.round(p/Aa);return s.formatDistance("xDays",m,l)}else if(p<Pr*2)return w=Math.round(p/Pr),s.formatDistance("aboutXMonths",w,l)}if(w=Vh(u,d),w<12){const m=Math.round(p/Pr);return s.formatDistance("xMonths",m,l)}else{const m=w%12,f=Math.trunc(w/12);return m<3?s.formatDistance("aboutXYears",f,l):m<9?s.formatDistance("overXYears",f,l):s.formatDistance("almostXYears",f+1,l)}}function Gm(r,e){return Vm(r,Dh(r),e)}function ve(...r){return Nh(Kf(r))}function Xm(){return Th()}function ec(r){if(!r)return"--:--";const e=typeof r=="string"?new Date(r):r;return!(e instanceof Date)||isNaN(e.getTime())?"--:--":go(e,"HH:mm")}function Km(r){if(!r)return"时间未知";const e=typeof r=="string"?new Date(r):r;return!(e instanceof Date)||isNaN(e.getTime())?"时间未知":Gm(e,{addSuffix:!0})}function Ym(r){if(!r)return"----/--/--";const e=typeof r=="string"?new Date(r):r;return!(e instanceof Date)||isNaN(e.getTime())?"----/--/--":go(e,"yyyy-MM-dd")}function Qm(r){if(!r)return"----/--/-- --:--:--";const e=typeof r=="string"?new Date(r):r;return!(e instanceof Date)||isNaN(e.getTime())?"----/--/-- --:--:--":go(e,"yyyy-MM-dd HH:mm:ss")}function Zm(r,e){return r.length<=e?r:r.slice(0,e)+"..."}function eg(r){return r.replace(/<[^>]*>/g,"").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').trim()}function tg(r){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)}function rg(r){try{return new URL(r),!0}catch{return!1}}function vs(r){if(r===null||typeof r!="object")return r;if(r instanceof Date)return isNaN(r.getTime())?new Date:new Date(r.getTime());if(r instanceof Array)return r.map(e=>vs(e));if(typeof r=="object"){const e={};for(const t in r)r.hasOwnProperty(t)&&(e[t]=vs(r[t]));return e}return r}function ng(r,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout(()=>r(...n),e)}}function sg(r,e){let t;return(...n)=>{t||(r(...n),t=!0,setTimeout(()=>t=!1,e))}}function tc(r){if(r===0)return"0 Bytes";const e=1024,t=["Bytes","KB","MB","GB","TB"],n=Math.floor(Math.log(r)/Math.log(e));return parseFloat((r/Math.pow(e,n)).toFixed(2))+" "+t[n]}function rc(r){return r.slice((r.lastIndexOf(".")-1>>>0)+2)}function og(r){const e=["jpg","jpeg","png","gif","bmp","webp","svg"],t=rc(r).toLowerCase();return e.includes(t)}function ag(){const r=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#84cc16","#f97316","#ec4899","#6366f1"];return r[Math.floor(Math.random()*r.length)]}async function ig(r){try{return await navigator.clipboard.writeText(r),!0}catch(e){return console.error("Failed to copy text to clipboard:",e),!1}}function lg(r,e,t="text/plain"){const n=new Blob([r],{type:t}),s=URL.createObjectURL(n),a=document.createElement("a");a.href=s,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}function cg(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function dg(){const r=navigator.userAgent;return r.indexOf("Win")!==-1?"Windows":r.indexOf("Mac")!==-1?"macOS":r.indexOf("Linux")!==-1?"Linux":r.indexOf("Android")!==-1?"Android":r.indexOf("iOS")!==-1?"iOS":"Unknown"}class ug extends Error{constructor(t,n="UNKNOWN_ERROR",s=500){super(t);V(this,"code");V(this,"statusCode");this.name="AppError",this.code=n,this.statusCode=s}}async function fg(r,e=3,t=1e3){let n;for(let s=1;s<=e;s++)try{return await r()}catch(a){if(n=a,s===e)break;await new Promise(i=>setTimeout(i,t*s))}throw n}const hg={get:(r,e)=>{try{const t=localStorage.getItem(r);return t?JSON.parse(t):e||null}catch{return e||null}},set:(r,e)=>{try{localStorage.setItem(r,JSON.stringify(e))}catch(t){console.error("Failed to save to localStorage:",t)}},remove:r=>{try{localStorage.removeItem(r)}catch(e){console.error("Failed to remove from localStorage:",e)}},clear:()=>{try{localStorage.clear()}catch(r){console.error("Failed to clear localStorage:",r)}}},nc=({attachment:r,customRenderer:e,className:t})=>{if(e)return o.jsx("div",{children:e(r)});const n=r.type==="image",s=r.type==="audio",a=()=>n?o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}):s?o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"})}):o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})});return o.jsxs("div",{className:ve("inline-flex items-center gap-2 p-2 bg-muted rounded-lg border max-w-sm",t),children:[o.jsx("div",{className:"flex-shrink-0 text-muted-foreground",children:a()}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-sm font-medium truncate",children:r.name}),o.jsx("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:tc(r.size)})]}),r.mimeType&&o.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:r.mimeType})]}),o.jsx("div",{className:"flex-shrink-0",children:n?o.jsx("button",{onClick:()=>window.open(r.url,"_blank"),className:"p-1 hover:bg-background rounded transition-colors",title:"View image",children:o.jsxs("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),o.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"})]})}):o.jsx("a",{href:r.url,download:r.name,className:"p-1 hover:bg-background rounded transition-colors inline-block",title:"Download file",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})})}),n&&o.jsx("div",{className:"w-full mt-2",children:o.jsx("img",{src:r.url,alt:r.name,className:"max-w-full h-auto rounded border",style:{maxHeight:"200px"},loading:"lazy"})}),s&&o.jsx("div",{className:"w-full mt-2",children:o.jsxs("audio",{controls:!0,className:"w-full",preload:"metadata",children:[o.jsx("source",{src:r.url,type:r.mimeType}),"Your browser does not support the audio element."]})})]})},_s=({toolCall:r,allMessages:e=[],className:t})=>{const[n,s]=M.useState(!1);console.log("🔍 ToolCallRenderer - 开始查找工具结果消息"),console.log("🔍 当前工具调用ID:",r.id),console.log("🔍 所有消息数量:",e.length),console.log("🔍 所有消息:",e.map(S=>{var j;return{id:S.id,role:S.role,tool_call_id:S.tool_call_id||S.toolCallId,metadata:S.metadata,content:((j=S.content)==null?void 0:j.substring(0,100))+"..."}}));const a=e.find(S=>{var I,P;if(S.role!=="tool")return!1;const j=S.tool_call_id||S.toolCallId,v=((I=S.metadata)==null?void 0:I.tool_call_id)||((P=S.metadata)==null?void 0:P.toolCallId);return j===r.id||v===r.id});console.log("🔍 找到的工具结果消息:",a),console.log("🎨 ToolCallRenderer - 工具调用:",r.id,"结果:",r.result,"工具消息:",a==null?void 0:a.content);const i=r.result||(a==null?void 0:a.content),l=!!r.error,d=!!i,g=(()=>{if(!r.arguments)return{};if(typeof r.arguments=="object")return r.arguments;if(typeof r.arguments=="string")try{return JSON.parse(r.arguments)}catch(S){return console.warn("Failed to parse tool arguments:",r.arguments,S),{}}return{}})(),h=g&&Object.keys(g).length>0,p=(S,j="")=>{const v={};for(const I in S)if(S.hasOwnProperty(I)){const P=S[I],T=j?`${j}.${I}`:I;P!==null&&typeof P=="object"&&!Array.isArray(P)?Object.assign(v,p(P,T)):v[T]=P}return v},m=(()=>{if(!h)return"";const S=p(g),j=Object.keys(S);let v=`| 参数 | 值 |
98
98
  |------|------|
99
99
  `;return j.forEach(I=>{const P=S[I];let T;typeof P=="string"?T=P.replace(/\n/g,"<br>").replace(/\|/g,"\\|"):Array.isArray(P)?T=`[${P.join(", ")}]`.replace(/\|/g,"\\|"):T=JSON.stringify(P).replace(/\|/g,"\\|"),v+=`| ${I} | ${T} |
100
- `}),v})(),c=(()=>{if(!d)return null;if(i&&typeof i=="object")return i;if(typeof i=="string")try{const S=JSON.parse(i);if(S&&typeof S=="object")return S}catch{return null}return null})(),x=!!(c&&typeof c=="object"),b=S=>{if(S===null)return"null";if(Array.isArray(S)){if(S.length===0)return"array []";const j=S[0],v=b(j);return v==="object"?"object []":`${v}[]`}switch(typeof S){case"string":return"string";case"number":return Number.isInteger(S)?"integer":"number";case"boolean":return"boolean";case"object":return"object";default:return typeof S}},y=(S,j="",v="")=>{const I=[];if(S==null)return I;if(Array.isArray(S)){const P={path:v||j||"list",name:j||"list",type:b(S),value:S,children:S.map((T,L)=>{const C=`${v||j||"list"}[${L}]`,W=b(T);return{path:C,name:`[${L}]`,type:W,value:T,children:W==="object"||Array.isArray(T)?y(T,`[${L}]`,C):[]}})};return I.push(P),I}return typeof S=="object"&&Object.keys(S).forEach(P=>{const T=S[P],L=v?`${v}.${P}`:P,C=b(T),W=C==="object"||Array.isArray(T)?y(T,P,L):[];I.push({path:L,name:P,type:C,value:T,children:W})}),I},_=({data:S})=>{const j=Array.isArray(S)?y(S,"list","list"):y(S,"",""),[v,I]=M.useState(()=>new Set(j.filter(C=>C.children.length>0).map(C=>C.path))),P=C=>{I(W=>{const B=new Set(W);return B.has(C)?B.delete(C):B.add(C),B})},T=C=>{if(C===null)return"null";if(Array.isArray(C))return`数组(${C.length})`;if(typeof C=="object")return"对象";if(typeof C=="string")return C;try{return JSON.stringify(C)}catch{return String(C)}},L=(C,W)=>C.map(B=>{const z=B.children&&B.children.length>0,O=v.has(B.path),U=z?O?"▾":"▸":"",J=T(B.value);return o.jsxs(M.Fragment,{children:[o.jsxs("tr",{children:[o.jsxs("td",{style:{paddingLeft:W*16},children:[z?o.jsx("button",{type:"button",onClick:()=>P(B.path),className:"mr-2 text-gray-600 dark:text-gray-300 hover:text-black dark:hover:text-white","aria-label":O?"收起":"展开",children:U}):o.jsx("span",{className:"mr-4"}),B.name]}),o.jsx("td",{style:{whiteSpace:"normal",wordBreak:"break-word"},children:J})]}),z&&O&&L(B.children,W+1)]},B.path)});return o.jsx("div",{className:"border-l-4 border-green-400 dark:border-green-500 rounded-lg overflow-hidden bg-green-50/50 dark:bg-green-900/20 mb-2",children:o.jsx("div",{className:"markdown-renderer",children:o.jsxs("table",{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"字段"}),o.jsx("th",{children:"值"})]})}),o.jsx("tbody",{children:L(j,0)})]})})})};return o.jsxs("div",{className:"tool-call-renderer tool-call-container",children:[o.jsxs("div",{className:"tool-header",children:[o.jsxs("span",{className:"tool-name",children:["@",r.name]}),l&&o.jsx("span",{className:"status-badge status-error",children:"错误"}),d&&!l&&o.jsx("span",{className:"status-badge status-success",children:"完成"}),!d&&!l&&o.jsx("span",{className:"status-badge status-pending",children:"等待中"}),(h||d||l)&&o.jsx("button",{onClick:()=>s(!n),className:"toggle-button",children:n?"收起详情":"查看详情"})]}),n&&o.jsxs("div",{className:"details-container",children:[h&&o.jsx("div",{children:m&&o.jsx("div",{className:"border-l-4 border-blue-400 dark:border-blue-500 rounded-lg overflow-hidden bg-blue-50/50 dark:bg-blue-900/20 mb-4",children:o.jsx(lt,{content:m})})}),d&&o.jsxs("div",{children:[o.jsx("div",{className:"details-title",children:"结果:"}),x?o.jsx(_,{data:c}):o.jsx(lt,{content:typeof i=="string"?i:JSON.stringify(i)})]}),l&&o.jsxs("div",{children:[o.jsx("div",{className:"details-title",children:"错误:"}),o.jsx("div",{className:"status-badge status-error",style:{display:"block",padding:"0.5rem"},children:r.error})]}),o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 border-t border-gray-200 dark:border-gray-700 pt-2",children:["执行时间: ",(()=>{const S=new Date(r.createdAt);return isNaN(S.getTime())?"时间未知":S.toLocaleString()})()]})]})]})},mg=({message:r,isLast:e=!1,isStreaming:t=!1,onEdit:n,onDelete:s,allMessages:a=[],customRenderer:i})=>{var v,I,P,T,L,C,W,B,z;console.log("🚀🚀🚀 MessageItem 组件被调用!消息ID:",r.id,"角色:",r.role),console.log("🚀🚀🚀 完整消息对象:",r);const[l,d]=M.useState(!1),[u,g]=M.useState(r.content),h=(O,U)=>{navigator.clipboard.writeText(O).then(()=>{console.log("代码已复制到剪贴板:",{code:O,language:U})}).catch(J=>{console.error("复制失败:",J)})},[p,w]=M.useState(!1),m=r.role==="user",f=r.role==="assistant",c=r.role==="system",x=r.role==="tool";if(x)return null;if(i!=null&&i.renderMessage)return o.jsx("div",{children:i.renderMessage(r)});const b=()=>{n&&u.trim()!==r.content&&n(r.id,u.trim()),d(!1)},y=()=>{g(r.content),d(!1)},_=async()=>{try{await navigator.clipboard.writeText(r.content)}catch(O){console.error("Failed to copy message:",O)}},S=((v=r.metadata)==null?void 0:v.attachments)||[],j=r.toolCalls||((I=r.metadata)==null?void 0:I.toolCalls)||[];return console.log("🔧 工具调用数据:",{顶层toolCalls:r.toolCalls,"metadata.toolCalls":(P=r.metadata)==null?void 0:P.toolCalls,最终toolCalls长度:j.length,消息ID:r.id,contentSegments:(T=r.metadata)==null?void 0:T.contentSegments,contentSegments长度:((C=(L=r.metadata)==null?void 0:L.contentSegments)==null?void 0:C.length)||0}),o.jsxs("div",{className:ve("group relative rounded-lg transition-colors",!f&&"flex gap-3 px-4 py-4",f&&"px-4 py-2",m&&"bg-user-message",c&&"bg-muted border-l-4 border-primary",x&&"bg-blue-50 dark:bg-blue-950/20 border-l-4 border-blue-500","hover:bg-opacity-80"),onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),children:[!f&&o.jsx("div",{className:"flex-shrink-0",children:o.jsx("div",{className:ve("w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium",m&&"bg-primary text-primary-foreground",c&&"bg-muted text-muted-foreground",x&&"bg-blue-500 text-white"),children:m?"U":x?"T":"S"})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[!f&&o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-sm font-medium",children:m?"You":x?"Tool Result":"System"}),o.jsx("span",{className:"text-xs text-muted-foreground",children:ec(r.createdAt)})]}),((W=r.metadata)==null?void 0:W.type)==="session_summary"&&o.jsxs("div",{className:"mb-3 border border-amber-300 dark:border-amber-600/50 bg-amber-50 dark:bg-amber-950/20 rounded-md p-3",children:[o.jsxs("div",{className:"text-xs text-amber-900 dark:text-amber-200 font-medium mb-1",children:["上下文已压缩为摘要",typeof((B=r.metadata)==null?void 0:B.keepLastN)=="number"?`(保留最近 ${r.metadata.keepLastN} 条)`:""]}),o.jsxs("details",{className:"group",children:[o.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground select-none",children:"查看摘要内容"}),o.jsx("div",{className:"mt-2 prose prose-sm max-w-none",children:o.jsx(lt,{content:(r.rawContent||((z=r.metadata)==null?void 0:z.summary)||"").toString(),isStreaming:!1,onApplyCode:()=>{}})})]})]}),S.length>0&&o.jsx("div",{className:"mb-3 space-y-2",children:S.map(O=>o.jsx(nc,{attachment:O,customRenderer:i==null?void 0:i.renderAttachment},O.id))}),l?o.jsxs("div",{className:"space-y-2",children:[o.jsx("textarea",{value:u,onChange:O=>g(O.target.value),className:"w-full p-2 border rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-primary",rows:3,autoFocus:!0}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("button",{onClick:b,className:"px-3 py-1 text-sm bg-primary text-primary-foreground rounded hover:bg-primary/90",children:"Save"}),o.jsx("button",{onClick:y,className:"px-3 py-1 text-sm bg-muted text-muted-foreground rounded hover:bg-muted/80",children:"Cancel"})]})]}):o.jsx("div",{className:"space-y-3",children:(()=>{var $;const O=(($=r.metadata)==null?void 0:$.contentSegments)||[],U=r.content&&r.content.trim().length>0,J=t&&e;return O.length>0?(console.log("🎨 使用分段渲染,分段数量:",O.length),console.log("🎨 分段详情:",O),o.jsx("div",{className:"space-y-0.5",children:O.map((H,F)=>{if(console.log(`🎨 渲染分段 ${F}:`,H),H.type==="text")return console.log(`🎨 渲染文本分段 ${F}:`,H.content),o.jsx("div",{className:"prose prose-sm max-w-none",children:o.jsx(lt,{content:H.content,isStreaming:J&&F===O.length-1,onApplyCode:h})},`segment-${F}`);if(H.type==="tool_call"){console.log(`🎨 渲染工具调用分段 ${F}:`,H);const k=j.find(A=>A.id===H.toolCallId);if(console.log(`🎨 查找工具调用 ${H.toolCallId}:`,k),k)return console.log("🎨 找到工具调用,开始渲染:",k),o.jsx("div",{children:o.jsx(_s,{toolCall:k,allMessages:a})},`tool-${k.id}`);console.log(`🎨 ❌ 未找到工具调用 ${H.toolCallId}`)}else if(H.type==="thinking")return console.log(`🎨 渲染思考分段 ${F}:`,H.content),o.jsxs("details",{className:"group border border-gray-200 dark:border-gray-700 rounded-md bg-muted px-3 py-2",children:[o.jsx("summary",{className:"cursor-pointer text-xs text-gray-500 dark:text-gray-400 select-none",children:"思考过程"}),o.jsx("div",{className:"mt-1",children:o.jsx(lt,{content:H.content||"",isStreaming:J&&F===O.length-1,onApplyCode:h,className:"thinking not-prose"})})]},`thinking-${F}`);return null})})):(console.log("🎨 使用传统渲染方式"),console.log("🎨 hasContent:",U),console.log("🎨 toolCalls.length:",j.length),o.jsxs("div",{className:"space-y-0.5",children:[U&&o.jsx("div",{className:"prose prose-sm max-w-none",children:o.jsx(lt,{content:r.content,isStreaming:J,onApplyCode:h})}),j.length>0&&o.jsxs("div",{className:"space-y-0.5",children:[o.jsx("div",{className:"text-sm text-muted-foreground font-medium",children:"工具调用:"}),j.map(H=>(console.log("🎨 传统方式渲染工具调用:",H),o.jsx("div",{children:o.jsx(_s,{toolCall:H,allMessages:a})},`tool-${H.id}`)))]})]}))})()}),r.tokensUsed&&o.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["Tokens used: ",r.tokensUsed]})]}),p&&!l&&o.jsxs("div",{className:"absolute top-2 right-2 flex gap-1 bg-background border rounded-md shadow-sm opacity-0 group-hover:opacity-100 transition-opacity",children:[o.jsx("button",{onClick:_,className:"p-1.5 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors",title:"Copy message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),m&&n&&o.jsx("button",{onClick:()=>d(!0),className:"p-1.5 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors",title:"Edit message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),s&&o.jsx("button",{onClick:()=>s(r.id),className:"p-1.5 hover:bg-destructive/10 rounded text-muted-foreground hover:text-destructive transition-colors",title:"Delete message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})},sc=M.memo(mg,(r,e)=>r.message.id===e.message.id&&r.message.content===e.message.content&&r.message.createdAt===e.message.createdAt&&r.isLast===e.isLast&&r.isStreaming===e.isStreaming&&JSON.stringify(r.message.metadata)===JSON.stringify(e.message.metadata)),oc=({size:r="md",className:e})=>{const t={sm:"w-4 h-4",md:"w-6 h-6",lg:"w-8 h-8"};return o.jsx("div",{className:ve("animate-spin rounded-full border-2 border-current border-t-transparent",t[r],e),role:"status","aria-label":"Loading",children:o.jsx("span",{className:"sr-only",children:"Loading..."})})},po=({messages:r,isLoading:e=!1,isStreaming:t=!1,hasMore:n=!1,onLoadMore:s,onMessageEdit:a,onMessageDelete:i,customRenderer:l})=>{const d=M.useRef(null),u=M.useRef(null),[g,h]=M.useState(!0),[p,w]=M.useState(!0),m=()=>{const b=d.current;return b?b.scrollHeight-b.scrollTop-b.clientHeight<=40:!0},f=(b=!0)=>{var y;(y=u.current)==null||y.scrollIntoView({behavior:b?"smooth":"auto"})};M.useEffect(()=>{t&&g&&f(!0)},[r,t,g]),M.useEffect(()=>{w(m())},[r,t]),M.useEffect(()=>{t&&p&&h(!0),t||h(!1)},[t,p]);const c=()=>{const b=m();w(b),b||h(!1)},x=()=>{f(!0),h(!0)};return r.length===0&&!e?o.jsx("div",{className:"flex items-center justify-center h-full",children:o.jsxs("div",{className:"text-center space-y-4",children:[o.jsx("div",{className:"w-16 h-16 mx-auto bg-muted rounded-full flex items-center justify-center",children:o.jsx("svg",{className:"w-8 h-8 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Start a conversation"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Send a message to begin your chat with AI"})]})]})}):o.jsxs("div",{className:"flex flex-col h-full relative",children:[o.jsxs("div",{ref:d,onScroll:c,className:"flex-1 overflow-y-auto px-4 py-6 space-y-1",style:{willChange:"scroll-position",transform:"translateZ(0)"},children:[n&&o.jsx("div",{className:"flex justify-center mb-2",children:o.jsx("button",{type:"button",onClick:s,className:"text-sm px-3 py-1 rounded border border-border text-foreground hover:bg-accent",children:"加载更多"})}),(r||[]).filter(b=>{var y;return!((y=b==null?void 0:b.metadata)!=null&&y.hidden)}).map((b,y,_)=>o.jsx(sc,{message:b,isLast:y===_.length-1,isStreaming:t&&y===_.length-1,onEdit:a,onDelete:i,allMessages:r,customRenderer:l},b.id)),e&&o.jsx("div",{className:"flex justify-start",children:o.jsxs("div",{className:"flex items-center space-x-2 bg-muted px-4 py-3 rounded-lg max-w-xs",children:[o.jsx(oc,{size:"sm"}),o.jsx("span",{className:"text-sm text-muted-foreground",children:"AI is thinking..."})]})}),o.jsx("div",{ref:u})]}),!p&&o.jsxs("button",{type:"button","aria-label":"回到底部",title:"回到底部",onClick:x,className:"absolute bottom-4 right-4 z-10 flex items-center gap-2 rounded-full bg-primary text-primary-foreground px-4 py-2 shadow-md hover:bg-primary/90",children:[o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M12 5v12"}),o.jsx("path",{d:"M19 12l-7 7-7-7"})]}),o.jsx("span",{className:"text-sm",children:"回到底部"})]})]})},xo=({onSend:r,onStop:e,disabled:t=!1,isStreaming:n=!1,placeholder:s="Type your message...",maxLength:a=4e3,allowAttachments:i=!1,supportedFileTypes:l=["image/*","text/*","application/pdf"],showModelSelector:d=!1,selectedModelId:u=null,availableModels:g=[],onModelChange:h,selectedAgentId:p=null,availableAgents:w=[],onAgentChange:m,sessionMcpSummary:f,sessionMcpTooltip:c})=>{const[x,b]=M.useState(""),[y,_]=M.useState([]),[S,j]=M.useState(!1),v=M.useRef(null),I=M.useRef(null);M.useEffect(()=>{console.log("InputArea - isStreaming 状态变化:",{isStreaming:n,disabled:t,onStop:!!e,timestamp:new Date().toISOString()})},[n,t,e]);const P=M.useCallback(()=>{const $=v.current;if($){$.style.height="auto";const H=$.scrollHeight,F=200;$.style.height=`${Math.min(H,F)}px`}},[]),T=$=>{const H=$.target.value;H.length<=a&&(b(H),P())},L=$=>{$.key==="Enter"&&!$.shiftKey&&($.preventDefault(),C())},C=()=>{const $=x.trim();if(!(!$&&y.length===0)&&!t){if(d&&!u&&!p){alert("请先选择一个模型或智能体");return}r($,y),b(""),_([]),v.current&&(v.current.style.height="auto")}},W=$=>{const H=Array.from($.target.files||[]);_(F=>[...F,...H]),I.current&&(I.current.value="")},B=$=>{_(H=>H.filter((F,k)=>k!==$))},z=$=>{$.preventDefault(),i&&!t&&j(!0)},O=$=>{$.preventDefault(),j(!1)},U=$=>{if($.preventDefault(),j(!1),!i||t)return;const H=Array.from($.dataTransfer.files);_(F=>[...F,...H])},J=$=>{if($===0)return"0 Bytes";const H=1024,F=["Bytes","KB","MB","GB"],k=Math.floor(Math.log($)/Math.log(H));return parseFloat(($/Math.pow(H,k)).toFixed(2))+" "+F[k]};return o.jsxs("div",{className:"border-t bg-background p-4",children:[d&&o.jsxs("div",{className:"mb-3 flex items-center gap-3 flex-wrap",children:[g.length>0||w.length>0?o.jsxs("select",{value:p?`agent:${p}`:u||"",onChange:$=>{const H=$.target.value;if(H.startsWith("agent:")){const F=H.replace("agent:","");m==null||m(F),h==null||h(null)}else h==null||h(H||null),m==null||m(null)},disabled:t,className:ve("w-80 max-w-full px-3 py-2 border border-input bg-background rounded-md","text-sm text-foreground placeholder:text-muted-foreground","focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent","disabled:opacity-50 disabled:cursor-not-allowed"),children:[o.jsx("option",{value:"",children:"请选择模型或智能体..."}),w&&w.filter($=>$.enabled).length>0&&o.jsx("optgroup",{label:"智能体",children:w.filter($=>$.enabled).map($=>o.jsxs("option",{value:`agent:${$.id}`,children:["[Agent] ",$.name]},$.id))}),g&&g.filter($=>$.enabled).length>0&&o.jsx("optgroup",{label:"模型",children:g.filter($=>$.enabled).map($=>o.jsxs("option",{value:$.id,children:[$.name," (",$.model_name,")"]},$.id))})]}):o.jsx("div",{className:"w-80 max-w-full px-3 py-2 border border-input bg-muted rounded-md text-sm text-muted-foreground",children:"暂无可用模型或智能体,请先在右上角配置"}),f?o.jsx("div",{className:"max-w-[360px] min-w-0 px-2 py-1 rounded-lg border border-border bg-muted/10 text-xs text-muted-foreground",title:c||f,children:o.jsx("span",{className:"truncate min-w-0 block",children:f})}):null]}),y.length>0&&o.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:y.map(($,H)=>o.jsxs("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-lg text-sm",children:[o.jsx("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})}),o.jsx("span",{className:"truncate max-w-32",children:$.name}),o.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",J($.size),")"]}),o.jsx("button",{onClick:()=>B(H),className:"text-muted-foreground hover:text-destructive transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},H))}),o.jsxs("div",{className:ve("relative flex items-end gap-2 p-3 border rounded-lg transition-colors","focus-within:border-primary",S&&"border-primary bg-primary/5",t&&"opacity-50 cursor-not-allowed"),onDragOver:z,onDragLeave:O,onDrop:U,children:[i&&o.jsx("button",{onClick:()=>{var $;return($=I.current)==null?void 0:$.click()},disabled:t,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Attach files",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}),o.jsx("textarea",{ref:v,value:x,onChange:T,onKeyDown:L,placeholder:s,disabled:t,className:ve("flex-1 resize-none bg-transparent border-none outline-none","placeholder:text-muted-foreground","disabled:cursor-not-allowed"),rows:1,style:{minHeight:"24px",maxHeight:"200px"}}),o.jsxs("div",{className:"flex-shrink-0 text-xs text-muted-foreground",children:[x.length,"/",a]}),n?o.jsx("button",{onClick:()=>{console.log("停止按钮被点击",{onStop:e,disabled:t}),e&&e()},disabled:!1,className:ve("flex-shrink-0 p-2 rounded-md transition-colors","bg-red-500 text-white hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),title:"停止生成",style:{backgroundColor:"#ef4444",color:"white"},children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 6h12v12H6z"})})}):o.jsx("button",{onClick:C,disabled:t||n||!x.trim()&&y.length===0,className:ve("flex-shrink-0 p-2 rounded-md transition-colors","disabled:opacity-50 disabled:cursor-not-allowed",(x.trim()||y.length>0)&&!t&&!n?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"),title:d&&!u?"请先选择AI模型":"Send message",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})}),i&&o.jsx("input",{ref:I,type:"file",multiple:!0,accept:l.join(","),onChange:W,className:"hidden"})]}),S&&i&&o.jsx("div",{className:"absolute inset-0 bg-primary/10 border-2 border-dashed border-primary rounded-lg flex items-center justify-center",children:o.jsxs("div",{className:"text-center",children:[o.jsx("svg",{className:"w-8 h-8 mx-auto text-primary mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})}),o.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files here to attach"})]})})]})},ac=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),ic=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"})}),Ss=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),lc=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),gg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),pg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),cc=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),xg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),bg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-9 4h10a1 1 0 001-1V7a1 1 0 00-1-1H7a1 1 0 00-1 1v10a1 1 0 001 1z"})}),yg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),xr=({isOpen:r,title:e,message:t,confirmText:n="确认",cancelText:s="取消",onConfirm:a,onCancel:i,type:l="danger",verificationText:d,verificationLabel:u,verificationPlaceholder:g,verificationHint:h})=>{if(!r)return null;const[p,w]=M.useState("");M.useEffect(()=>{r&&w("")},[r,d]);const m=!!d,f=m&&p.trim()!==(d==null?void 0:d.trim()),c=()=>{switch(l){case"danger":return"bg-red-600 hover:bg-red-700 text-white";case"warning":return"bg-yellow-600 hover:bg-yellow-700 text-white";default:return"bg-blue-600 hover:bg-blue-700 text-white"}};return o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-sm border border-border animate-breathing-border",children:o.jsxs("div",{className:"p-6",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-2",children:e}),o.jsx("p",{className:"text-muted-foreground text-sm mb-6",children:t}),m&&o.jsxs("div",{className:"mb-6",children:[o.jsx("label",{className:"block text-xs font-medium text-muted-foreground mb-2",children:u||"请输入以下内容以继续操作"}),o.jsx("div",{className:"px-3 py-2 bg-muted rounded-md text-sm font-mono text-foreground border border-border mb-2",children:d}),o.jsx("input",{type:"text",value:p,onChange:x=>w(x.target.value),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:g||"输入上方关键字以确认",autoFocus:!0}),o.jsx("p",{className:"text-[12px] text-muted-foreground mt-2",children:h||"为了防止误删,需要您再次确认此操作。"})]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{onClick:i,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors",children:s}),o.jsx("button",{onClick:a,disabled:f,className:`flex-1 px-4 py-2 text-sm rounded-md transition-colors ${c()} ${f?"opacity-50 cursor-not-allowed":""}`,children:n})]})]})})})},br=()=>{const[r,e]=M.useState({isOpen:!1,title:"",message:"",confirmText:"确认",cancelText:"取消",type:"danger"}),t=M.useCallback(i=>{e({isOpen:!0,title:i.title,message:i.message,confirmText:i.confirmText||"确认",cancelText:i.cancelText||"取消",type:i.type||"danger",onConfirm:i.onConfirm,onCancel:i.onCancel,verificationText:i.verificationText,verificationLabel:i.verificationLabel,verificationPlaceholder:i.verificationPlaceholder,verificationHint:i.verificationHint})},[]),n=M.useCallback(()=>{e(i=>({...i,isOpen:!1}))},[]),s=M.useCallback(()=>{var i;(i=r.onConfirm)==null||i.call(r),n()},[r.onConfirm,n]),a=M.useCallback(()=>{var i;(i=r.onCancel)==null||i.call(r),n()},[r.onCancel,n]);return{dialogState:r,showConfirmDialog:t,hideConfirmDialog:n,handleConfirm:s,handleCancel:a}},Tr=r=>r===!0||r===1||r==="1",Ta=(r,e)=>r.includes(e)?r.filter(t=>t!==e):[...r,e],Oa=({isOpen:r,onClose:e,onCreate:t,availableModels:n,availableMcpConfigs:s,availablePrompts:a,defaultTitle:i="New Chat",defaultModelId:l=null,initialMcpConfigIds:d,initialPromptIds:u,dialogTitle:g="新建会话",confirmText:h="创建"})=>{const p=M.useMemo(()=>(n||[]).filter(z=>Tr(z.enabled)),[n]),w=M.useMemo(()=>(s||[]).filter(z=>Tr(z.enabled)),[s]),m=M.useMemo(()=>s||[],[s]),[f,c]=M.useState(i),[x,b]=M.useState(""),[y,_]=M.useState([]),[S,j]=M.useState([]),[v,I]=M.useState(!1),[P,T]=M.useState(!1),[L,C]=M.useState(!1),W=M.useMemo(()=>(a||[]).filter(z=>Tr(z.isActive??z.is_active??!1)).map(z=>z.id),[a]);if(M.useEffect(()=>{var O;if(!r)return;c(i),_(Array.isArray(d)?d:w.map(U=>U.id)),j(Array.isArray(u)?u:W),I(!1),T(!1),C(!1);const z=((O=p[0])==null?void 0:O.id)||"";b(l||z)},[r]),M.useEffect(()=>{var O;if(!r||x)return;const z=((O=p[0])==null?void 0:O.id)||"";!l&&!z||b(l||z)},[r,x,l,p]),M.useEffect(()=>{r&&(Array.isArray(d)||P||y.length>0||w.length!==0&&_(w.map(z=>z.id)))},[r,d,P,y,w]),M.useEffect(()=>{r&&(Array.isArray(u)||L||S.length>0||W.length!==0&&j(W))},[r,u,L,S,W]),!r)return null;const B=!v&&!!x;return o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-lg border border-border animate-breathing-border",children:o.jsxs("div",{className:"p-6",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:g}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"会话标题"}),o.jsx("input",{value:f,onChange:z=>c(z.target.value),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"New Chat",disabled:v})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择模型(必选)"}),o.jsxs("select",{value:x,onChange:z=>b(z.target.value),disabled:v,className:"w-full px-3 py-2 border border-input bg-background rounded-md text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"",disabled:!0,children:"请选择模型..."}),p.map(z=>o.jsxs("option",{value:z.id,children:[z.name," (",z.model_name,")"]},z.id))]}),p.length===0&&o.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"暂无可用模型,请先在右上角配置。"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 MCP(多选)"}),m.length===0?o.jsx("p",{className:"text-xs text-muted-foreground",children:"暂无 MCP 配置。"}):o.jsx("div",{className:"max-h-40 overflow-auto rounded-md border border-border bg-background",children:m.map(z=>{const O=Tr(z.enabled);return o.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 text-sm hover:bg-accent",children:[o.jsx("input",{type:"checkbox",checked:y.includes(z.id),onChange:()=>{T(!0),_(U=>Ta(U,z.id))},disabled:v}),o.jsxs("span",{className:"truncate",title:z.name,children:[z.name,O?null:o.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(未启用)"})]})]},z.id)})})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 Prompt(多选)"}),a.length===0?o.jsx("p",{className:"text-xs text-muted-foreground",children:"暂无可用 Prompt(系统上下文)。"}):o.jsx("div",{className:"max-h-40 overflow-auto rounded-md border border-border bg-background",children:(a||[]).map(z=>{const O=z.isActive??z.is_active??!1;return o.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 text-sm hover:bg-accent",children:[o.jsx("input",{type:"checkbox",checked:S.includes(z.id),onChange:()=>{C(!0),j(U=>Ta(U,z.id))},disabled:v}),o.jsxs("span",{className:"truncate",title:z.name,children:[z.name,O?o.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(当前激活)"}):null]})]},z.id)})})]})]}),o.jsxs("div",{className:"flex gap-3 mt-6",children:[o.jsx("button",{onClick:e,disabled:v,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"取消"}),o.jsx("button",{onClick:async()=>{if(B){I(!0);try{await t({title:f.trim()||i,modelId:x,mcpConfigIds:y,promptIds:S}),e()}finally{I(!1)}}},disabled:!B,className:"flex-1 px-4 py-2 text-sm rounded-md transition-colors bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed",children:h})]})]})})})},wg=r=>{const e=new Date;let t;if(!r)return"时间未知";if(typeof r=="string"){const s=r.replace(" ","T")+"Z";t=new Date(s),isNaN(t.getTime())&&(t=new Date(r))}else t=r;if(!t||isNaN(t.getTime()))return"时间未知";const n=Math.floor((e.getTime()-t.getTime())/1e3);return n<60?"刚刚":n<3600?`${Math.floor(n/60)}分钟前`:n<86400?`${Math.floor(n/3600)}小时前`:n<2592e3?`${Math.floor(n/86400)}天前`:t.toLocaleDateString("zh-CN")},bo=({isOpen:r=!0,onClose:e,store:t,embedded:n=!1})=>{let s=null;try{s=tt()}catch{}const a=t?t():s;if(!a)throw new Error("SessionList must be used within a ChatStoreProvider or receive a store prop");const{sessions:i,currentSession:l,createSession:d,selectSession:u,deleteSession:g,updateSessionConfig:h,getSessionMcpConfigIds:p,aiModelConfigs:w,loadAiModelConfigs:m,mcpConfigs:f,loadMcpConfigs:c,systemContexts:x,loadSystemContexts:b,selectedModelId:y}=a,_=n?"relative h-full bg-card shadow-lg breathing-border":"fixed left-0 top-0 h-full bg-card z-40 shadow-xl breathing-border",S="transition-all duration-300 ease-in-out",[j,v]=M.useState(!1),[I,P]=M.useState(!1),[T,L]=M.useState(null),[C,W]=M.useState([]),[B,z]=M.useState(!r),{dialogState:O,showConfirmDialog:U,handleConfirm:J,handleCancel:$}=br(),H=()=>{z(!B)},F=async()=>{try{v(!0),m==null||m(),c==null||c(),b==null||b(),B&&z(!1)}catch(R){console.error("Failed to create session:",R)}},k=async R=>{try{await u(R)}catch(q){console.error("Failed to select session:",q)}},A=async R=>{const q=i.find(Q=>Q.id===R);U({title:"删除确认",message:`确定要删除会话 "${(q==null?void 0:q.title)||"Untitled"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",onConfirm:async()=>{try{await g(R)}catch(Q){console.error("Failed to delete session:",Q)}}})},N=R=>{const q=R==null?void 0:R.metadata;try{return typeof q=="string"?q?JSON.parse(q):{}:q&&typeof q=="object"?q:{}}catch{return{}}},D=async R=>{try{m==null||m(),c==null||c(),b==null||b();const q=await(p==null?void 0:p(R.id));W(Array.isArray(q)?q:[]),L(R),P(!0),B&&z(!1)}catch(q){console.error("Failed to open session editor:",q)}};return o.jsx("div",{className:`${_} ${S} ${B?"w-32":"w-80 sm:w-96"}`,children:o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:`flex ${B?"flex-col items-center justify-center p-2":"items-center justify-between p-4"} border-b border-border transition-all duration-300`,children:[!B&&o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"会话列表"}),o.jsxs("div",{className:`flex ${B?"flex-col space-y-2 items-center":"items-center space-x-2"}`,children:[o.jsx("button",{onClick:F,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"新建会话",children:o.jsx(ac,{className:"w-5 h-5"})}),o.jsx("button",{onClick:H,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:B?"展开":"收起",children:B?o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}):o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),e&&!B&&!n&&o.jsx("button",{onClick:e,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground",children:[o.jsx(cc,{className:"w-12 h-12 mb-4 opacity-50"}),!B&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm",children:"还没有会话"}),o.jsx("button",{onClick:F,className:"mt-2 px-4 py-2 text-sm bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors",children:"创建第一个会话"})]})]}):o.jsx("div",{className:"p-2 space-y-1",children:i.map(R=>o.jsxs("div",{className:`group relative flex items-center p-3 rounded-lg cursor-pointer transition-colors ${(l==null?void 0:l.id)===R.id?"bg-accent border border-border":"hover:bg-accent/50"}`,onClick:()=>k(R.id),children:[o.jsx("div",{className:"flex-1 min-w-0",children:o.jsxs(o.Fragment,{children:[o.jsx("h3",{className:`text-sm font-medium text-foreground truncate ${B?"text-center w-full":""}`,title:R.title,children:B&&R.title.length>4?R.title.slice(0,4)+"...":R.title}),!B&&o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:wg(R.updatedAt)})]})}),!B&&o.jsxs("div",{className:"relative flex items-center gap-1",children:[o.jsx("button",{className:"p-1 text-muted-foreground hover:text-foreground opacity-0 group-hover:opacity-100 transition-opacity",onClick:q=>{q.stopPropagation(),D(R)},title:"编辑",children:o.jsx(Ss,{className:"w-4 h-4"})}),o.jsx("button",{className:"p-1 text-muted-foreground hover:text-foreground opacity-0 group-hover:opacity-100 transition-opacity",onClick:q=>{q.stopPropagation();const Q=q.currentTarget.nextElementSibling;Q&&Q.classList.toggle("hidden")},children:o.jsx(ic,{className:"w-4 h-4"})}),o.jsx("div",{className:"hidden absolute right-0 z-10 mt-1 w-32 bg-popover border border-border rounded-md shadow-lg",children:o.jsxs("div",{className:"py-1",children:[o.jsxs("button",{onClick:q=>{q.stopPropagation(),D(R);const Q=q.currentTarget.closest(".absolute");Q&&Q.classList.add("hidden")},className:"flex items-center w-full px-3 py-2 text-sm text-popover-foreground hover:bg-accent",children:[o.jsx(Ss,{className:"w-4 h-4 mr-2"}),"编辑"]}),o.jsxs("button",{onClick:q=>{q.stopPropagation(),A(R.id);const Q=q.currentTarget.closest(".absolute");Q&&Q.classList.add("hidden")},className:"flex items-center w-full px-3 py-2 text-sm text-destructive hover:bg-destructive/10",children:[o.jsx(lc,{className:"w-4 h-4 mr-2"}),"删除"]})]})})]})]},R.id))})}),o.jsx(xr,{isOpen:O.isOpen,title:O.title,message:O.message,confirmText:O.confirmText,cancelText:O.cancelText,type:O.type,verificationText:O.verificationText,verificationLabel:O.verificationLabel,verificationPlaceholder:O.verificationPlaceholder,verificationHint:O.verificationHint,onConfirm:J,onCancel:$}),o.jsx(Oa,{isOpen:j,onClose:()=>v(!1),availableModels:w||[],availableMcpConfigs:f||[],availablePrompts:x||[],defaultModelId:y,dialogTitle:"新建会话",confirmText:"创建",onCreate:async R=>{try{await d({title:R.title,modelId:R.modelId,mcpConfigIds:R.mcpConfigIds,promptIds:R.promptIds})}catch(q){throw console.error("Failed to create session:",q),q}}}),o.jsx(Oa,{isOpen:I,onClose:()=>{P(!1),L(null),W([])},availableModels:w||[],availableMcpConfigs:f||[],availablePrompts:x||[],defaultTitle:(T==null?void 0:T.title)||"New Chat",defaultModelId:(()=>{const R=N(T);return R.ai_model_config_id||R.model_id||R.modelId||y||null})(),initialMcpConfigIds:C,initialPromptIds:(()=>{const R=N(T),q=R.prompt_ids||R.promptIds||[];return Array.isArray(q)?q.map(Q=>String(Q)).filter(Boolean):[]})(),dialogTitle:"编辑会话",confirmText:"保存",onCreate:async R=>{if(T)try{await(h==null?void 0:h(T.id,{title:R.title,modelId:R.modelId,mcpConfigIds:R.mcpConfigIds,promptIds:R.promptIds}))}catch(q){throw console.error("Failed to update session config:",q),q}}})]})})},dc=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Ra=r=>r==="system"?dc():r,Gn=r=>{if(typeof window>"u")return;const e=window.document.documentElement;e.classList.remove("light","dark"),e.classList.add(r);const t=document.querySelector('meta[name="theme-color"]');t&&t.setAttribute("content",r==="dark"?"#0f172a":"#ffffff")},$a=()=>typeof window>"u"?"system":localStorage.getItem("theme")||"system",vg=r=>{typeof window>"u"||localStorage.setItem("theme",r)},uc=()=>{const[r,e]=M.useState(()=>$a()),[t,n]=M.useState(()=>Ra($a())),s=i=>{e(i),vg(i);const l=Ra(i);n(l),Gn(l)},a=()=>{let i;switch(r){case"light":i="dark";break;case"dark":i="system";break;case"system":i="light";break;default:i="system"}s(i)};return M.useEffect(()=>{if(r!=="system")return;const i=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const d=dc();n(d),Gn(d)};return i.addEventListener("change",l),()=>i.removeEventListener("change",l)},[r]),M.useEffect(()=>{Gn(t)},[t]),{theme:r,actualTheme:t,setTheme:s,toggleTheme:a}},yo=({className:r=""})=>{const{theme:e,toggleTheme:t}=uc(),n=()=>{switch(e){case"light":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})});case"dark":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})});case"system":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})});default:return null}},s=()=>{switch(e){case"light":return"Light mode";case"dark":return"Dark mode";case"system":return"System theme";default:return"Toggle theme"}};return o.jsx("button",{onClick:t,className:`p-2 hover:bg-muted rounded-lg transition-colors ${r}`,title:s(),"aria-label":s(),children:n()})},_g={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Sg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})}),La=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Cg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),jg=({open:r,config:e,onClose:t})=>{const[n,s]=M.useState([]),[a,i]=M.useState(!1),[l,d]=M.useState(null),[u,g]=M.useState(null),[h,p]=M.useState(!1),[w,m]=M.useState({name:"",envJson:"",enabled:!1}),[f,c]=M.useState(null),[x,b]=M.useState({});if(M.useEffect(()=>{(async()=>{if(!(!r||!(e!=null&&e.id))){i(!0),d(null);try{const _=await te.getMcpConfigProfiles(e.id);s(Array.isArray(_)?_:[])}catch(_){d((_==null?void 0:_.message)||"获取配置档案失败")}finally{i(!1)}}})()},[r,e==null?void 0:e.id]),!r)return null;try{const y={id:e==null?void 0:e.id,name:e==null?void 0:e.name,type:e==null?void 0:e.type,command:e==null?void 0:e.command,cwd:e==null?void 0:e.cwd,args:e==null?void 0:e.args};typeof window<"u"}catch{}return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-3xl max-h-[85vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Sg,{}),o.jsxs("h3",{className:"text-lg font-semibold text-foreground",children:["配置档案 - ",e==null?void 0:e.name]})]}),o.jsx("button",{onClick:()=>t(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(La,{})})]}),o.jsxs("div",{className:"p-4 overflow-y-auto overflow-x-hidden",style:{maxHeight:"calc(85vh - 100px)"},children:[e&&o.jsxs("div",{className:"mb-4 p-3 rounded-md border border-border bg-muted/40",children:[o.jsx("div",{className:"text-sm font-medium mb-2 text-foreground",children:"基本信息"}),o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs text-muted-foreground",children:[o.jsxs("div",{children:["协议类型:",o.jsx("span",{className:"ml-1 text-foreground",children:e.type==="http"?"HTTP":"Stdio"})]}),o.jsxs("div",{children:[e.type==="http"?"URL:":"命令:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:e.command})]}),e.type==="stdio"&&e.cwd&&o.jsxs("div",{children:["cwd:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:String(e.cwd)})]}),e.type==="stdio"&&o.jsxs("div",{className:"sm:col-span-2",children:["args:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:(()=>{const y=e.args;if(!y)return"—";if(Array.isArray(y))return y.map(_=>String(_)).join(", ");if(typeof y=="string"){try{const _=JSON.parse(y);if(Array.isArray(_))return _.map(S=>String(S)).join(", ")}catch{}return y}return String(y)})()})]})]})]}),o.jsxs("div",{className:"flex items-center justify-between mb-3",children:[o.jsx("span",{className:"text-sm text-muted-foreground",children:"已保存的配置档案"}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{if(e!=null&&e.id){i(!0);try{const y=await te.getMcpConfigProfiles(e.id);s(Array.isArray(y)?y:[])}finally{i(!1)}}},children:"刷新列表"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{if(!(e!=null&&e.id))return;let y;try{const _=await te.getMcpConfigResource(e.id),S=_&&_.config||{};S&&typeof S=="object"&&(y=S)}catch{}m({name:`配置_${new Date().toLocaleString("zh-CN")}`,envJson:"",enabled:!1}),b(y||{}),g(null),p(!0)},children:"新增配置档案"})]})]}),a?o.jsx("div",{className:"text-xs text-muted-foreground",children:"加载中..."}):l?o.jsx("div",{className:"text-xs text-destructive",children:l}):n.length===0?o.jsx("div",{className:"text-xs text-muted-foreground",children:"暂无配置档案,点击右上角“新增配置档案”。"}):o.jsx("div",{className:"space-y-2",children:n.map(y=>o.jsx("div",{className:"px-2 py-2 border border-border rounded-md",children:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx("div",{className:"text-sm text-foreground font-medium truncate",title:y.name,children:y.name}),y.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{if(e!=null&&e.id)try{await te.activateMcpConfigProfile(e.id,y.id);const _=await te.getMcpConfigProfiles(e.id);s(Array.isArray(_)?_:[])}catch{}},children:"激活"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{g(y.id),m({name:y.name||"",envJson:(()=>{try{return JSON.stringify(y.env||{},null,2)}catch{return""}})(),enabled:!!y.enabled});const _=y.env||{},S={};Object.keys(_||{}).forEach(j=>{const v=_[j];if(typeof v=="string"){const I=v.trim();try{S[j]=JSON.parse(I)}catch{I.includes(",")?S[j]=I.split(",").map(P=>P.trim()).filter(Boolean):S[j]=I}}else S[j]=v}),b(S),p(!0)},children:"编辑"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-destructive text-destructive-foreground rounded-md hover:bg-destructive/80",onClick:async()=>{if(!(!(e!=null&&e.id)||!window.confirm(`确定删除配置档案 “${y.name}” 吗?`)))try{await te.deleteMcpConfigProfile(e.id,y.id);const S=await te.getMcpConfigProfiles(e.id);s(Array.isArray(S)?S:[])}catch(S){console.error("删除配置档案失败:",S)}},children:"删除"})]})]})},y.id))})]})]}),h&&o.jsxs("div",{className:"modal-container z-[100]",children:[o.jsx("div",{className:"fixed inset-0 bg-black/40 backdrop-blur-sm",onClick:()=>{p(!1),c(null)}}),o.jsx("div",{className:"fixed inset-0 flex items-center justify-center p-4",children:o.jsxs("div",{className:"modal-content w-full max-w-2xl transform overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Cg,{}),o.jsx("h3",{className:"text-base font-semibold text-foreground",children:u?"编辑配置档案":"新增配置档案"})]}),o.jsx("button",{onClick:()=>{p(!1),c(null)},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(La,{})})]}),o.jsxs("div",{className:"p-4",children:[f&&o.jsx("div",{className:"mb-2 text-xs text-destructive",children:f}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"名称"}),o.jsx("input",{type:"text",value:w.name,onChange:y=>m({...w,name:y.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md"})]}),o.jsx("div",{children:x&&Object.keys(x).length>0&&o.jsxs("div",{className:"mb-3",children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"动态参数"}),o.jsx("div",{className:"grid grid-cols-1 gap-3",children:Object.keys(x).map(y=>{const _=x[y],S=typeof _,j=Array.isArray(_);return o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs text-muted-foreground mb-1",children:y}),S==="boolean"?o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",checked:!!_,onChange:v=>b({...x,[y]:v.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("span",{className:"ml-2 text-xs",children:String(_)})]}):j?o.jsx("input",{type:"text",value:_.join(", "),onChange:v=>b({...x,[y]:v.target.value.split(",").map(I=>I.trim()).filter(Boolean)}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"}):S==="object"&&_!==null?o.jsx("textarea",{value:(()=>{try{return JSON.stringify(_,null,2)}catch{return String(_)}})(),onChange:v=>{try{const I=JSON.parse(v.target.value);b({...x,[y]:I})}catch{b({...x,[y]:v.target.value})}},rows:4,className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md font-mono text-xs"}):o.jsx("input",{type:S==="number"?"number":"text",value:_??"",onChange:v=>b({...x,[y]:S==="number"?Number(v.target.value):v.target.value}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"})]},y)})})]})})]}),o.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:()=>{p(!1),c(null)},children:"取消"}),o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{c(null);try{if(!(e!=null&&e.id))throw new Error("缺少配置ID");let y=null;if(x&&Object.keys(x).length>0)y=x;else{const j=(w.envJson||"").trim();if(j)try{const v=JSON.parse(j);v&&typeof v=="object"&&(y=v)}catch{throw new Error("env JSON 格式错误")}}let S=null;if(y&&typeof y=="object"){S={};for(const j of Object.keys(y)){const v=y[j];Array.isArray(v)?S[j]=v.join(","):typeof v=="boolean"||typeof v=="number"?S[j]=String(v):v==null?S[j]="":typeof v=="object"?S[j]=JSON.stringify(v):S[j]=String(v)}}if(u)if(await te.updateMcpConfigProfile(e.id,u,{name:w.name,env:S,enabled:w.enabled})){const v=await te.getMcpConfigProfiles(e.id);s(Array.isArray(v)?v:[]),p(!1),g(null)}else throw new Error("更新失败");else{const j=await te.createMcpConfigProfile(e.id,{name:w.name,env:S,enabled:w.enabled});if(j&&(j.id||j.success)){const v=await te.getMcpConfigProfiles(e.id);s(Array.isArray(v)?v:[]),p(!1)}else throw new Error("创建失败")}}catch(y){c((y==null?void 0:y.message)||"保存失败")}},children:"保存"})]})]})]})})]})]})},Ag={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Da=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})}),kg=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Ng=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Mg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),Eg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),wo=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{mcpConfigs:n,updateMcpConfig:s,deleteMcpConfig:a,loadMcpConfigs:i}=t,{dialogState:l,showConfirmDialog:d,handleConfirm:u,handleCancel:g}=br(),[h,p]=M.useState(!1),[w,m]=M.useState(null),[f,c]=M.useState({name:"",command:"",type:"stdio",enabled:!0,cwd:"",argsInput:""}),[x,b]=M.useState(!1),[y,_]=M.useState(null),[S,j]=M.useState({}),[v,I]=M.useState([]),[P,T]=M.useState(""),[L,C]=M.useState(!1),[W,B]=M.useState(null);M.useEffect(()=>{const k="__mcpManagerInitAt__",A=window[k]||0,N=Date.now();typeof A=="number"&&N-A<1e3||(window[k]=N,i())},[i]);const z=async k=>{B(k),C(!0);try{const A=await te.getMcpConfigProfiles(k.id);I(Array.isArray(A)?A:[])}catch{console.error("加载配置档案失败")}finally{}},O=()=>{c({name:"",command:"",type:"stdio",enabled:!0,cwd:"",argsInput:""}),m(null),p(!1),j({}),I([]),T("")},U=async k=>{var N,D;if(k.preventDefault(),!f.name.trim()||!f.command.trim())return;const A={name:f.name.trim(),command:f.command.trim(),type:f.type,enabled:f.enabled,cwd:(N=f.cwd)!=null&&N.trim()?f.cwd.trim():void 0,args:(D=f.argsInput)!=null&&D.trim()?f.argsInput.split(",").map(R=>R.trim()).filter(Boolean):void 0,createdAt:new Date,updatedAt:new Date};await s(A),O()},J=async k=>{var N,D;if(k.preventDefault(),!w||!f.name.trim()||!f.command.trim())return;const A={...w,name:f.name.trim(),command:f.command.trim(),type:f.type,enabled:f.enabled,cwd:(N=f.cwd)!=null&&N.trim()?f.cwd.trim():void 0,args:(D=f.argsInput)!=null&&D.trim()?f.argsInput.split(",").map(R=>R.trim()).filter(Boolean):void 0,updatedAt:new Date};await s(A),O()},$=k=>{m(k);let A="";const N=k.args;if(Array.isArray(N))A=N.map(D=>String(D)).join(", ");else if(typeof N=="string"&&N.trim()!=="")try{const D=JSON.parse(N);Array.isArray(D)?A=D.map(R=>String(R)).join(", "):A=N}catch{A=N}c({name:k.name,command:k.command,type:k.type||"stdio",enabled:k.enabled,cwd:k.cwd||"",argsInput:A}),p(!0),j({}),_(null),b(!1)},H=async k=>{var D;const A=n.find(R=>R.id===k),N=((D=A==null?void 0:A.name)==null?void 0:D.trim())||"删除";d({title:"删除 MCP 服务器",message:`确定要删除服务器 "${(A==null?void 0:A.name)||"Unknown"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:N,verificationLabel:"请键入服务器名称以确认删除",verificationPlaceholder:`输入 "${N}"`,verificationHint:"删除后无法恢复,请再次确认操作。",onConfirm:()=>a(k)})},F=async k=>{const A={...k,enabled:!k.enabled,updatedAt:new Date};await s(A)};return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:r}),o.jsxs("div",{className:"fixed right-0 top-0 h-full w-[520px] sm:w-[560px] bg-card z-50 shadow-xl breathing-border flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Da,{}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"MCP 服务器管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx(kg,{})})]}),o.jsxs("div",{className:"p-4 flex-1 overflow-y-auto overflow-x-hidden",children:[!h&&o.jsxs("button",{onClick:()=>p(!0),className:"w-full mb-6 p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Ng,{}),o.jsx("span",{children:"添加 MCP 服务器"})]}),h&&o.jsxs("form",{onSubmit:w?J:U,className:"mb-6 p-4 bg-muted rounded-lg",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:w?"编辑服务器":"添加新服务器"}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称"}),o.jsx("input",{type:"text",value:f.name,onChange:k=>c({...f,name:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: File System",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"协议类型"}),o.jsxs("select",{value:f.type,onChange:k=>c({...f,type:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"stdio",children:"Stdio (标准输入输出)"}),o.jsx("option",{value:"http",children:"HTTP (网络协议)"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:f.type==="http"?"URL地址":"命令"}),o.jsx("input",{type:"text",value:f.command,onChange:k=>c({...f,command:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:f.type==="http"?"https://api.example.com/mcp":"npx @modelcontextprotocol/server-filesystem /path/to/allowed/files",required:!0}),f.type==="stdio"&&o.jsx(o.Fragment,{})]}),f.type==="stdio"&&o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"可执行地址(cwd)"}),o.jsx("input",{type:"text",value:f.cwd,onChange:k=>c({...f,cwd:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"/absolute/path/to/executable"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"为空则使用当前页面的工作目录"}),o.jsx("div",{className:"mt-2 flex gap-2",children:o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{var k,A;if(f.command.trim()){b(!0),_(null);try{const N=await te.getMcpConfigResourceByCommand({type:f.type,command:f.command.trim(),args:(k=f.argsInput)!=null&&k.trim()?f.argsInput.split(",").map(D=>D.trim()).filter(Boolean):void 0,env:void 0,cwd:(A=f.cwd)!=null&&A.trim()?f.cwd.trim():void 0,alias:null});if(N&&N.success&&N.config){const D=N.config;if(j(D),w!=null&&w.id)try{const R=await te.getMcpConfigProfiles(w.id);I(Array.isArray(R)?R:[])}catch{}}else _("无法获取服务器可配置参数")}catch(N){_((N==null?void 0:N.message)||"获取配置失败")}finally{b(!1)}}},children:x?"获取中…":"获取配置"})})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"启动参数(args,逗号分隔)"}),o.jsx("input",{type:"text",value:f.argsInput,onChange:k=>c({...f,argsInput:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"--flag, value, --opt"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"将自动转换为参数数组"})]})]}),o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",id:"enabled",checked:f.enabled,onChange:k=>c({...f,enabled:k.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("label",{htmlFor:"enabled",className:"ml-2 block text-sm text-foreground",children:"启用此服务器"})]}),f.type==="stdio"&&Object.keys(S).length>0&&o.jsxs("div",{className:"mt-4 p-3 border border-border rounded-md bg-card",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"服务器可配置参数(动态解析)"}),x&&o.jsx("span",{className:"text-xs text-muted-foreground",children:"解析中…"})]}),y&&o.jsx("p",{className:"text-xs text-red-600 mb-2",children:y}),o.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[Object.keys(S).map(k=>{const A=S[k],N=typeof A,D=Array.isArray(A);return o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs text-muted-foreground mb-1",children:k}),N==="boolean"?o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",checked:!!A,onChange:R=>j({...S,[k]:R.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("span",{className:"ml-2 text-xs",children:String(A)})]}):D?o.jsx("input",{type:"text",value:A.join(", "),onChange:R=>j({...S,[k]:R.target.value.split(",").map(q=>q.trim()).filter(Boolean)}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"}):o.jsx("input",{type:N==="number"?"number":"text",value:A??"",onChange:R=>j({...S,[k]:N==="number"?Number(R.target.value):R.target.value}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"})]},k)}),(w==null?void 0:w.id)&&o.jsxs("div",{className:"mt-2 p-2 border border-dashed rounded-md",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("input",{type:"text",value:P,onChange:k=>T(k.target.value),className:"flex-1 px-2 py-1 border border-input bg-background text-foreground rounded-md",placeholder:"配置档案名称(例如:开发环境)"}),o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{var k,A;if(w!=null&&w.id)try{await te.createMcpConfigProfile(w.id,{name:P||`配置-${new Date().toLocaleString()}`,env:Object.keys(S).reduce((D,R)=>{const q=S[R];return D[R]=typeof q=="string"?q:String(q),D},{}),args:(k=f.argsInput)!=null&&k.trim()?f.argsInput.split(",").map(D=>D.trim()).filter(Boolean):void 0,cwd:(A=f.cwd)!=null&&A.trim()?f.cwd.trim():void 0,enabled:!1});const N=await te.getMcpConfigProfiles(w.id);I(Array.isArray(N)?N:[]),T("")}catch(N){console.error("保存配置档案失败:",N),_("保存配置档案失败")}},children:"保存为配置档案"})]}),v.length>0&&o.jsxs("div",{className:"mt-3 space-y-2",children:[o.jsx("div",{className:"text-xs text-muted-foreground",children:"已有配置档案:"}),v.map(k=>{const A=Array.isArray(k.args)?k.args.join(", "):"",N=k.env?Object.keys(k.env):[];return o.jsxs("div",{className:"px-2 py-1 border border-border rounded-md",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:"text-xs text-foreground font-medium",children:k.name}),k.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{await te.activateMcpConfigProfile(w.id,k.id);const D=await te.getMcpConfigProfiles(w.id);I(Array.isArray(D)?D:[])}catch{}},children:"激活"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{c(D=>({...D,argsInput:Array.isArray(k.args)?k.args.join(", "):D.argsInput,cwd:k.cwd??D.cwd})),j(k.env||{})},children:"应用到表单"})]})]}),o.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 text-xs text-foreground",children:[o.jsxs("div",{className:"truncate",title:k.cwd||"未设置",children:[o.jsx("span",{className:"text-muted-foreground",children:"cwd:"}),k.cwd||"未设置"]}),o.jsxs("div",{className:"truncate",title:A||"未设置",children:[o.jsx("span",{className:"text-muted-foreground",children:"args:"}),A||"未设置"]}),o.jsxs("div",{children:[o.jsxs("span",{className:"text-muted-foreground",children:["env(",N.length,"):"]}),N.length===0?"未设置":o.jsx("div",{className:"mt-1 grid grid-cols-1 gap-1",children:N.map(D=>o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-muted-foreground shrink-0",children:D}),o.jsx("span",{className:"text-foreground truncate",title:String(k.env[D]),children:String(k.env[D])})]},D))})]})]})]},k.id)})]})]})]})]})]}),(w==null?void 0:w.id)&&!h&&o.jsxs("div",{className:"mt-4 p-3 border border-border rounded-md bg-card",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"配置档案列表"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{const k=await te.getMcpConfigProfiles(w.id);I(Array.isArray(k)?k:[])}catch{}},children:"刷新"})]}),v.length===0?o.jsx("div",{className:"text-xs text-muted-foreground",children:"暂无配置档案"}):o.jsx("div",{className:"space-y-2",children:v.map(k=>{const A=Array.isArray(k.args)?k.args.join(", "):"",N=k.env?Object.keys(k.env):[];return o.jsxs("div",{className:"px-2 py-1 border border-border rounded-md",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:"text-xs text-foreground font-medium",children:k.name}),k.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{await te.activateMcpConfigProfile(w.id,k.id);const D=await te.getMcpConfigProfiles(w.id);I(Array.isArray(D)?D:[])}catch{}},children:"激活"})})]}),o.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 text-xs text-foreground",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-muted-foreground",children:"cwd:"}),k.cwd||"未设置"]}),o.jsxs("div",{children:[o.jsx("span",{className:"text-muted-foreground",children:"args:"}),A||"未设置"]}),o.jsxs("div",{children:[o.jsxs("span",{className:"text-muted-foreground",children:["env(",N.length,"):"]}),N.length===0?"未设置":o.jsx("div",{className:"mt-1 grid grid-cols-1 gap-1",children:N.map(D=>o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground",children:D}),o.jsx("span",{className:"text-foreground",children:String(k.env[D])})]},D))})]})]})]},k.id)})})]}),o.jsxs("div",{className:"flex space-x-3 mt-6",children:[o.jsx("button",{type:"submit",className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500",children:w?"更新":"添加"}),o.jsx("button",{type:"button",onClick:O,className:"px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80 focus:outline-none focus:ring-2 focus:ring-ring",children:"取消"})]})]}),o.jsx("div",{className:"space-y-3",children:n.length===0?o.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[o.jsx(Da,{}),o.jsx("p",{className:"mt-2",children:"暂无 MCP 服务器配置"}),o.jsx("p",{className:"text-sm",children:"点击上方按钮添加第一个服务器"})]}):n.map(k=>o.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 bg-card border border-border rounded-lg",children:[o.jsxs("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[o.jsx("div",{className:`w-3 h-3 rounded-full ${k.enabled?"bg-green-500":"bg-gray-400"}`}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center space-x-2 min-w-0",children:[o.jsx("h4",{className:"font-medium text-foreground truncate",title:k.name,children:k.name}),o.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${k.type==="http"?"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200":"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200"}`,children:k.type==="http"?"HTTP":"Stdio"})]}),o.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground truncate break-all font-mono",title:k.command,children:k.command}),typeof window<"u"&&Ag&&!1,k.type==="stdio"&&o.jsxs("div",{className:"mt-1 space-y-0.5 min-w-0",children:[k.cwd&&o.jsxs("div",{className:"text-xs text-muted-foreground truncate",title:String(k.cwd),children:["cwd: ",o.jsx("span",{className:"text-foreground",children:String(k.cwd)})]}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",title:(()=>{const A=k.args;let N=null,D=!1;if(Array.isArray(A))N=A.map(q=>String(q));else if(typeof A=="string"&&A.trim()!=="")try{const q=JSON.parse(A);Array.isArray(q)&&(N=q.map(Q=>String(Q)),D=!0)}catch{}const R=Array.isArray(N)&&N.length>0?N.join(", "):typeof A=="string"&&!D?A:"—";return String(R)})(),children:(()=>{const A=k.args;let N=null,D=!1;if(Array.isArray(A))N=A.map(q=>String(q));else if(typeof A=="string"&&A.trim()!=="")try{const q=JSON.parse(A);Array.isArray(q)&&(N=q.map(Q=>String(Q)),D=!0)}catch{}const R=Array.isArray(N)&&N.length>0?N.join(", "):typeof A=="string"&&!D?A:"—";return o.jsxs("span",{children:["参数(args):",o.jsx("span",{className:"text-foreground",children:R})]})})()})]})]})]}),o.jsxs("div",{className:"flex items-center space-x-2 shrink-0",children:[o.jsx("button",{onClick:()=>F(k),className:`px-3 py-1 text-xs rounded-full ${k.enabled?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-secondary text-secondary-foreground"}`,children:k.enabled?"已启用":"已禁用"}),o.jsx("button",{onClick:()=>z(k),className:"p-2 text-muted-foreground hover:text-indigo-600 transition-colors",title:"查看配置档案",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 7.5l7.5 3 7.5-3M3 7.5V18l7.5 3 7.5-3V7.5M10.5 10.5V21"})})}),o.jsx("button",{onClick:()=>$(k),className:"p-2 text-muted-foreground hover:text-blue-600 transition-colors",title:"编辑",children:o.jsx(Eg,{})}),o.jsx("button",{onClick:()=>H(k.id),className:"p-2 text-muted-foreground hover:text-red-600 transition-colors",title:"删除",children:o.jsx(Mg,{})})]})]},k.id))})]})]}),o.jsx(jg,{open:L,config:W,onClose:()=>{C(!1),B(null)}}),o.jsx(xr,{isOpen:l.isOpen,title:l.title,message:l.message,confirmText:l.confirmText,cancelText:l.cancelText,type:l.type,verificationText:l.verificationText,verificationLabel:l.verificationLabel,verificationPlaceholder:l.verificationPlaceholder,verificationHint:l.verificationHint,onConfirm:u,onCancel:g})]})},Fa=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})}),Ig=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Pg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Tg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),Og=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),vo=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{aiModelConfigs:n,loadAiModelConfigs:s,updateAiModelConfig:a,deleteAiModelConfig:i}=t,[l,d]=M.useState(!1),[u,g]=M.useState(null),[h,p]=M.useState({name:"",base_url:"",api_key:"",model_name:"",enabled:!0}),{dialogState:w,showConfirmDialog:m,handleConfirm:f,handleCancel:c}=br();M.useEffect(()=>{const v="__aiModelManagerInitAt__",I=window[v]||0,P=Date.now();typeof I=="number"&&P-I<1e3||(window[v]=P,s())},[s]);const x=()=>{p({name:"",base_url:"",api_key:"",model_name:"",enabled:!0}),g(null),d(!1)},b=async v=>{if(v.preventDefault(),!h.name.trim()||!h.base_url.trim()||!h.api_key.trim()||!h.model_name.trim())return;const I={id:Math.random().toString(36).substr(2,9),name:h.name.trim(),base_url:h.base_url.trim(),api_key:h.api_key.trim(),model_name:h.model_name.trim(),enabled:h.enabled,createdAt:new Date,updatedAt:new Date};await a(I),x()},y=async v=>{if(v.preventDefault(),!u||!h.name.trim()||!h.base_url.trim()||!h.api_key.trim()||!h.model_name.trim())return;const I={...u,name:h.name.trim(),base_url:h.base_url.trim(),api_key:h.api_key.trim(),model_name:h.model_name.trim(),enabled:h.enabled,updatedAt:new Date};await a(I),x()},_=v=>{g(v),p({name:v.name,base_url:v.base_url,api_key:v.api_key,model_name:v.model_name,enabled:v.enabled}),d(!0)},S=async v=>{var T;const I=n.find(L=>L.id===v),P=((T=I==null?void 0:I.name)==null?void 0:T.trim())||"删除";m({title:"删除确认",message:`确定要删除AI模型配置 "${(I==null?void 0:I.name)||"Unknown"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:P,verificationLabel:"请输入下方关键字确认删除",verificationPlaceholder:`输入 "${P}"`,verificationHint:"删除后无法恢复,请谨慎操作。",onConfirm:async()=>{await i(v)}})},j=async v=>{const I={...v,enabled:!v.enabled,updatedAt:new Date};await a(I)};return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-2xl max-h-[80vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Fa,{}),o.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"AI 模型管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Ig,{})})]}),o.jsxs("div",{className:"p-6 overflow-y-auto overflow-x-hidden max-h-[calc(80vh-120px)]",children:[!l&&o.jsxs("button",{onClick:()=>d(!0),className:"w-full mb-6 p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Pg,{}),o.jsx("span",{children:"添加 AI 模型"})]}),l&&o.jsxs("form",{onSubmit:u?y:b,className:"mb-6 p-4 bg-muted rounded-lg",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:u?"编辑 AI 模型":"添加 AI 模型"}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"配置名称"}),o.jsx("input",{type:"text",value:h.name,onChange:v=>p({...h,name:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: OpenAI GPT-4",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"Base URL"}),o.jsx("input",{type:"url",value:h.base_url,onChange:v=>p({...h,base_url:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: https://api.openai.com/v1",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"API Key"}),o.jsx("input",{type:"password",value:h.api_key,onChange:v=>p({...h,api_key:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"输入API密钥",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"模型名称"}),o.jsx("input",{type:"text",value:h.model_name,onChange:v=>p({...h,model_name:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: gpt-4",required:!0})]}),o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",id:"enabled",checked:h.enabled,onChange:v=>p({...h,enabled:v.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("label",{htmlFor:"enabled",className:"ml-2 block text-sm text-foreground",children:"启用此模型"})]})]}),o.jsxs("div",{className:"flex space-x-3 mt-6",children:[o.jsx("button",{type:"submit",className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500",children:u?"更新":"添加"}),o.jsx("button",{type:"button",onClick:x,className:"px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80 focus:outline-none focus:ring-2 focus:ring-ring",children:"取消"})]})]}),o.jsx("div",{className:"space-y-3",children:n.length===0?o.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[o.jsx(Fa,{}),o.jsx("p",{className:"mt-2",children:"暂无 AI 模型配置"}),o.jsx("p",{className:"text-sm",children:"点击上方按钮添加第一个模型"})]}):n.map(v=>o.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 bg-card border border-border rounded-lg hover:shadow-md transition-shadow",children:[o.jsxs("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[o.jsx("div",{className:`w-3 h-3 rounded-full ${v.enabled?"bg-green-500":"bg-gray-400"}`}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("h4",{className:"font-medium text-foreground truncate",title:v.name,children:v.name}),o.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground truncate",title:`${v.base_url} - ${v.model_name}`,children:[v.base_url," - ",v.model_name]})]})]}),o.jsxs("div",{className:"flex items-center space-x-2 shrink-0",children:[o.jsx("button",{onClick:()=>j(v),className:`px-3 py-1 text-xs rounded-full transition-colors ${v.enabled?"bg-green-100 text-green-800 hover:bg-green-200 dark:bg-green-900 dark:text-green-200":"bg-secondary text-secondary-foreground hover:bg-secondary/80"}`,children:v.enabled?"已启用":"已禁用"}),o.jsx("button",{onClick:()=>_(v),className:"p-2 text-muted-foreground hover:text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900 rounded transition-colors",title:"编辑",children:o.jsx(Tg,{})}),o.jsx("button",{onClick:()=>S(v.id),className:"p-2 text-muted-foreground hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded transition-colors",title:"删除",children:o.jsx(Og,{})})]})]},v.id))})]})]}),o.jsx(xr,{isOpen:w.isOpen,title:w.title,message:w.message,confirmText:w.confirmText,cancelText:w.cancelText,type:w.type,verificationText:w.verificationText,verificationLabel:w.verificationLabel,verificationPlaceholder:w.verificationPlaceholder,verificationHint:w.verificationHint,onConfirm:f,onCancel:c})]})},Ua=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),Rg=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),$g=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"})}),Lg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Dg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),Fg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),Ug=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),_o=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{systemContexts:n,activeSystemContext:s,loadSystemContexts:a,createSystemContext:i,updateSystemContext:l,deleteSystemContext:d,activateSystemContext:u}=t,[g,h]=M.useState("list"),[p,w]=M.useState(null),[m,f]=M.useState({name:"",content:""}),[c,x]=M.useState(!1),[b,y]=M.useState(!1),{dialogState:_,showConfirmDialog:S,handleConfirm:j,handleCancel:v}=br();M.useEffect(()=>{const O="__systemContextEditorInitAt__",U=window[O]||0,J=Date.now();if(typeof U=="number"&&J-U<1e3)return;window[O]=J,(async()=>{x(!0);try{await a()}catch(H){console.error("Failed to load system contexts:",H)}finally{x(!1)}})()},[a]);const I=()=>{f({name:"",content:""}),w(null),h("create")},P=O=>{f({name:O.name,content:O.content}),w(O),h("edit")},T=async()=>{if(!m.name.trim()||!m.content.trim()){alert("请填写名称和内容");return}y(!0);try{g==="create"?await i(m.name,m.content):g==="edit"&&p&&await l(p.id,m.name,m.content),h("list")}catch(O){console.error("Failed to save system context:",O),alert("保存失败,请重试")}finally{y(!1)}},L=async O=>{var U,J;S({title:"删除确认",message:`确定要删除上下文 "${O.name}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:((U=O.name)==null?void 0:U.trim())||"删除",verificationLabel:"请输入下方关键字确认删除",verificationPlaceholder:`输入 "${((J=O.name)==null?void 0:J.trim())||"删除"}"`,verificationHint:"为了防止误删,需要输入配置名称才能继续。",onConfirm:async()=>{try{await d(O.id)}catch($){console.error("Failed to delete system context:",$),alert("删除失败,请重试")}}})},C=async O=>{try{await u(O.id),await a()}catch(U){console.error("Failed to activate system context:",U),alert("激活失败,请重试")}},W=O=>{O.ctrlKey&&O.key==="s"&&(O.preventDefault(),g!=="list"&&T())},B=()=>o.jsxs("div",{className:"p-6 overflow-hidden flex flex-col",style:{height:"calc(90vh - 120px)"},children:[o.jsx("div",{className:"mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:o.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:[o.jsx("strong",{children:"系统上下文"}),"将作为每次对话的系统提示词,支持 Markdown 格式。 您可以创建多个上下文配置,但同一时间只能激活一个。"]})}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:c?o.jsx("div",{className:"flex items-center justify-center h-32",children:o.jsx("div",{className:"text-muted-foreground",children:"加载中..."})}):n.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-muted-foreground",children:[o.jsx(Ua,{}),o.jsx("p",{className:"mt-2",children:"暂无系统上下文配置"}),o.jsx("p",{className:"text-sm",children:'点击"新建"按钮创建第一个配置'})]}):o.jsx("div",{className:"space-y-3",children:n.map(O=>o.jsx("div",{className:`p-4 border rounded-lg transition-colors ${O.isActive?"border-green-500 bg-green-50 dark:bg-green-900/20":"border-border bg-card"}`,children:o.jsxs("div",{className:"flex items-start justify-between",children:[o.jsxs("div",{className:"flex-1",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("h3",{className:"font-medium text-foreground",children:O.name}),O.isActive&&o.jsxs("span",{className:"inline-flex items-center px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-full dark:bg-green-800 dark:text-green-100",children:[o.jsx(Ug,{}),o.jsx("span",{className:"ml-1",children:"已激活"})]})]}),o.jsxs("p",{className:"mt-1 text-sm text-muted-foreground line-clamp-2",children:[O.content.substring(0,100),O.content.length>100&&"..."]}),o.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["创建时间: ",new Date(O.createdAt).toLocaleString()]})]}),o.jsxs("div",{className:"flex items-center space-x-2 ml-4",children:[!O.isActive&&o.jsx("button",{onClick:()=>C(O),className:"px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors",children:"激活"}),o.jsx("button",{onClick:()=>P(O),className:"p-2 text-muted-foreground hover:text-blue-600 hover:bg-accent rounded transition-colors",children:o.jsx(Dg,{})}),o.jsx("button",{onClick:()=>L(O),className:"p-2 text-muted-foreground hover:text-red-600 hover:bg-accent rounded transition-colors",children:o.jsx(Fg,{})})]})]})},O.id))})})]}),z=()=>o.jsxs("div",{className:"p-6 overflow-hidden flex flex-col",style:{height:"calc(90vh - 120px)"},children:[o.jsxs("div",{className:"mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[o.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:g==="create"?"创建新的系统上下文配置":"编辑系统上下文配置"}),o.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-300 mt-2",children:"提示:使用 Ctrl+S 快速保存"})]}),o.jsxs("div",{className:"flex-1 flex flex-col space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"配置名称"}),o.jsx("input",{type:"text",value:m.name,onChange:O=>f({...m,name:O.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-lg focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:编程助手、翻译专家、创意写作等"})]}),o.jsxs("div",{className:"flex-1 flex flex-col",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("label",{className:"block text-sm font-medium text-foreground",children:"Markdown 内容"}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[m.content.length," 字符"]})]}),o.jsx("textarea",{value:m.content,onChange:O=>f({...m,content:O.target.value}),onKeyDown:W,className:"flex-1 w-full px-4 py-3 border border-input bg-background text-foreground rounded-lg focus:outline-none focus:ring-2 focus:ring-ring resize-none font-mono text-sm",placeholder:"请输入系统上下文内容,支持 Markdown 格式...\\n\\n例如:\\n# AI 助手角色设定\\n\\n你是一个专业的编程助手,具有以下特点:\\n- 提供准确、简洁的代码解决方案\\n- 遵循最佳实践和代码规范\\n- 耐心解答技术问题\\n\\n## 回答风格\\n- 使用中文回答\\n- 代码示例要完整可运行\\n- 提供必要的解释说明",spellCheck:!1})]}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[o.jsx("p",{children:"• 支持标准 Markdown 语法:标题、列表、代码块、链接等"}),o.jsx("p",{children:"• 内容将在每次对话开始时自动发送给 AI"}),o.jsx("p",{children:"• 留空则使用默认系统提示词"})]})]})]});return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-4xl max-h-[90vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Ua,{}),o.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"系统上下文设置"})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[g==="list"?o.jsxs("button",{onClick:I,className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",children:[o.jsx(Lg,{}),o.jsx("span",{children:"新建"})]}):o.jsxs(o.Fragment,{children:[o.jsxs("button",{onClick:T,disabled:b,className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[o.jsx($g,{}),o.jsx("span",{children:b?"保存中...":"保存"})]}),o.jsx("button",{onClick:()=>h("list"),className:"px-4 py-2 text-secondary-foreground border border-border rounded-md hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring transition-colors",children:"取消"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Rg,{})})]})]}),g==="list"?B():z()]}),o.jsx(xr,{isOpen:_.isOpen,title:_.title,message:_.message,confirmText:_.confirmText,cancelText:_.cancelText,type:_.type,verificationText:_.verificationText,verificationLabel:_.verificationLabel,verificationPlaceholder:_.verificationPlaceholder,verificationHint:_.verificationHint,onConfirm:j,onCancel:v})]})},Ba=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})}),Wa=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Bg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Wg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),fc=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{aiModelConfigs:n,loadAiModelConfigs:s,mcpConfigs:a,loadMcpConfigs:i,systemContexts:l,loadSystemContexts:d}=t,{userId:u}=Gf(),g=u||"custom_user_123",p=Xf()||te,[w,m]=M.useState([]),[f,c]=M.useState(!1),[x,b]=M.useState(!1),[y,_]=M.useState(null),[S,j]=M.useState(null),[v,I]=M.useState({name:"",description:"",ai_model_config_id:"",mcp_config_ids:[],system_context_id:void 0}),{dialogState:P,showConfirmDialog:T,handleConfirm:L,handleCancel:C}=br(),W=async()=>{c(!0);try{await Promise.all([s(),i(),d(),t.loadAgents?t.loadAgents():Promise.resolve()]);const A=t.agents&&Array.isArray(t.agents)?t.agents:await p.getAgents(g),N=Array.isArray(A)?A:[];m(N)}catch(A){console.error("加载智能体失败",A)}finally{c(!1)}},B=async A=>{for(let D=0;D<3;D++)try{t.loadAgents&&await t.loadAgents();const R=await p.getAgents(g),q=Array.isArray(R)?R:[];if(m(q),A&&Array.isArray(q)&&q.some(Q=>Q.id===A)||!A)break;await new Promise(Q=>setTimeout(Q,250))}catch(R){console.warn("刷新智能体列表失败,重试中…",R),await new Promise(q=>setTimeout(q,250))}};M.useEffect(()=>{const A="__agentManagerInitAt__",N=window[A]||0,D=Date.now();typeof N=="number"&&D-N<1e3||(window[A]=D,W())},[]);const z=()=>{I({name:"",description:"",ai_model_config_id:"",mcp_config_ids:[],system_context_id:void 0}),b(!1),j(null)},O=async A=>{var N;if(A.preventDefault(),!(!v.name.trim()||!v.ai_model_config_id))try{const D=await p.createAgent({name:v.name.trim(),description:((N=v.description)==null?void 0:N.trim())||void 0,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,user_id:g,enabled:!0});D&&D.id&&m(R=>R.some(Q=>Q.id===D.id)?R.map(Q=>Q.id===D.id?{...Q,...D}:Q):[D,...R]),await B(D==null?void 0:D.id),z()}catch(D){console.error("创建智能体失败",D),alert("创建失败,请重试")}},U=async A=>{if(A.preventDefault(),!!S)try{const N=await p.updateAgent(S.id,{name:v.name,description:v.description,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,enabled:!0});m(D=>D.map(R=>R.id===S.id?{...R,...N,name:v.name,description:v.description,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,enabled:!0}:R)),await B(S.id),z()}catch(N){console.error("更新智能体失败",N),alert("更新失败,请重试")}},J=A=>{var R;const N=w.find(q=>q.id===A),D=((R=N==null?void 0:N.name)==null?void 0:R.trim())||"删除";T({title:"删除智能体",message:`确定要删除智能体 "${(N==null?void 0:N.name)||"未命名"}" 吗?此操作将无法撤销。`,confirmText:"永久删除",cancelText:"取消",type:"danger",verificationText:D,verificationLabel:"请输入智能体名称以确认删除",verificationPlaceholder:`输入 "${D}"`,verificationHint:"删除后该智能体将从所有应用中移除且无法恢复。",onConfirm:async()=>{try{await p.deleteAgent(A),m(q=>q.filter(Q=>Q.id!==A)),await B()}catch(q){console.error("删除智能体失败",q),alert("删除失败,请重试")}}})},$=A=>{j(A),b(!0),I({name:A.name,description:A.description||"",ai_model_config_id:A.ai_model_config_id,mcp_config_ids:Array.isArray(A.mcp_config_ids)?A.mcp_config_ids:[],system_context_id:A.system_context_id})},H=A=>{const N=n.find(D=>D.id===A);return N?`${N.name}(${N.model_name})`:A},F=A=>{if(!A)return"未选择";const N=l.find(D=>D.id===A);return N?N.name:A},k=A=>A.map(D=>{const R=a.find(q=>q.id===D);return R?R.name:D}).join(",");return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:r}),o.jsxs("div",{className:"fixed right-0 top-0 h-full w-[520px] sm:w-[560px] bg-card z-50 shadow-xl breathing-border flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Ba,{}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"智能体管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx(Wa,{})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[!x&&o.jsxs("button",{onClick:()=>b(!0),className:"w-full p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Bg,{}),o.jsx("span",{children:"新增智能体"})]}),x&&o.jsxs("form",{onSubmit:S?U:O,className:"p-4 bg-muted rounded-lg space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"名称"}),o.jsx("input",{type:"text",value:v.name,onChange:A=>I({...v,name:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:项目助理",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"描述"}),o.jsx("textarea",{value:v.description,onChange:A=>I({...v,description:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"智能体用途说明",rows:3})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择模型(单选)"}),o.jsxs("select",{value:v.ai_model_config_id,onChange:A=>I({...v,ai_model_config_id:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",required:!0,children:[o.jsx("option",{value:"",children:"请选择模型"}),n.map(A=>o.jsxs("option",{value:A.id,children:[A.name,"(",A.model_name,")"]},A.id))]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 MCP 配置(多选)"}),o.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 border rounded-md",children:a.map(A=>o.jsxs("label",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"checkbox",checked:v.mcp_config_ids.includes(A.id),onChange:N=>{const D=N.target.checked;I(R=>({...R,mcp_config_ids:D?[...R.mcp_config_ids,A.id]:R.mcp_config_ids.filter(q=>q!==A.id)}))}}),o.jsx("span",{children:A.name})]},A.id))})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择系统上下文"}),o.jsxs("select",{value:v.system_context_id||"",onChange:A=>I({...v,system_context_id:A.target.value||void 0}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"",children:"不使用"}),l.map(A=>o.jsx("option",{value:A.id,children:A.name},A.id))]})]}),o.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[o.jsx("button",{type:"button",onClick:z,className:"px-3 py-2 rounded bg-muted text-muted-foreground hover:bg-accent",children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-2 rounded bg-blue-600 text-white hover:bg-blue-700",children:"保存"})]})]}),o.jsx("div",{children:f?o.jsx("div",{className:"text-muted-foreground",children:"加载中..."}):w.length===0?o.jsx("div",{className:"text-muted-foreground",children:"暂无智能体配置"}):o.jsx("div",{className:"space-y-3",children:w.map(A=>o.jsxs("div",{className:"p-4 border rounded-lg flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center space-x-2 min-w-0",children:[o.jsx("h3",{className:"font-medium text-foreground truncate",title:A.name,children:A.name}),!A.enabled&&o.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground",children:"未启用"})]}),A.description&&o.jsx("p",{className:"mt-1 text-sm text-muted-foreground truncate",title:A.description,children:A.description}),o.jsxs("p",{className:"mt-2 text-xs text-muted-foreground truncate",title:H(A.ai_model_config_id),children:["模型:",H(A.ai_model_config_id)]}),o.jsxs("p",{className:"mt-1 text-xs text-muted-foreground truncate",title:F(A.system_context_id),children:["系统上下文:",F(A.system_context_id)]}),o.jsxs("p",{className:"mt-1 text-xs text-muted-foreground truncate",title:k(A.mcp_config_ids||[]),children:["MCP配置:",k(A.mcp_config_ids||[])]})]}),o.jsxs("div",{className:"flex items-center space-x-2 ml-4 shrink-0",children:[o.jsx("button",{onClick:()=>_(A),className:"px-3 py-1 text-sm bg-muted text-foreground rounded hover:bg-accent transition-colors",children:"详情"}),o.jsx("button",{onClick:()=>$(A),className:"px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors",children:"编辑"}),o.jsxs("button",{onClick:()=>J(A.id),className:"px-3 py-1 text-sm bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors flex items-center space-x-1",children:[o.jsx(Wg,{}),o.jsx("span",{children:"删除"})]})]})]},A.id))})})]}),y&&o.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[o.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>_(null)}),o.jsxs("div",{className:"relative bg-card border border-border rounded-lg shadow-xl w-[520px] p-6",children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx(Ba,{}),o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"智能体详情"})]}),o.jsx("button",{onClick:()=>_(null),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Wa,{})})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"名称:"}),y.name]}),y.description&&o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"描述:"}),y.description]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"模型:"}),H(y.ai_model_config_id)]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"系统上下文:"}),F(y.system_context_id)]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"MCP配置:"}),k(y.mcp_config_ids||[])]}),Array.isArray(y.mcp_config_ids)&&y.mcp_config_ids.length>0&&o.jsx("div",{className:"mt-2 space-y-2",children:(y.mcp_config_ids||[]).map(A=>{var q,Q;const N=(a||[]).find(se=>se.id===A);if(!N)return null;let D="—";const R=N.args;if(Array.isArray(R))D=R.map(se=>String(se)).join(", ");else if(typeof R=="string"&&R.trim()!=="")try{const se=JSON.parse(R);Array.isArray(se)?D=se.map(Te=>String(Te)).join(", "):D=R}catch{D=R}return o.jsxs("div",{className:"p-2 rounded border border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:N.name}),o.jsx("span",{className:`px-1.5 py-0.5 text-xs rounded ${N.type==="http"?"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200":"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200"}`,children:((Q=(q=N.type)==null?void 0:q.toUpperCase)==null?void 0:Q.call(q))||N.type})]}),o.jsxs("div",{className:"mt-1 text-xs text-muted-foreground break-all",children:[N.type==="http"?"URL:":"命令:",o.jsx("span",{className:"text-foreground",children:N.command})]}),N.cwd&&o.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground break-all",children:["cwd:",o.jsx("span",{className:"text-foreground",children:String(N.cwd)})]}),N.type==="stdio"&&o.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground break-all",children:["args:",o.jsx("span",{className:"text-foreground",children:D})]})]},A)})}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:["创建时间:",y.created_at?new Date(y.created_at).toLocaleString():"-"]})]}),o.jsx("div",{className:"mt-4 flex justify-end space-x-2",children:o.jsx("button",{onClick:()=>_(null),className:"px-3 py-2 rounded bg-muted text-muted-foreground hover:bg-accent",children:"关闭"})})]})]})]}),o.jsx(xr,{isOpen:P.isOpen,title:P.title,message:P.message,confirmText:P.confirmText,cancelText:P.cancelText,type:P.type,verificationText:P.verificationText,verificationLabel:P.verificationLabel,verificationPlaceholder:P.verificationPlaceholder,verificationHint:P.verificationHint,onConfirm:L,onCancel:C})]})},Hg=r=>{const e=r==null?void 0:r.metadata;try{return typeof e=="string"?e?JSON.parse(e):{}:e&&typeof e=="object"?e:{}}catch{return{}}},qg=r=>{const e=Hg(r),t=e.prompt_text??e.promptText??e.session_prompt??e.sessionPrompt??null;return typeof t=="string"?t:""},hc=({className:r})=>{const{currentSession:e,updateSessionConfig:t}=tt(),n=M.useMemo(()=>qg(e),[e]),[s,a]=M.useState(!1),[i,l]=M.useState(""),[d,u]=M.useState(!1);if(M.useEffect(()=>{s&&l(n)},[s,n]),!e)return null;const g=n.trim().length>0,h=M.useMemo(()=>n.replace(/\s+/g," ").trim(),[n]),p=async()=>{if(e){u(!0);try{await t(e.id,{promptText:i}),a(!1)}finally{u(!1)}}};return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>a(!0),className:ve("inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-border bg-muted/10 hover:bg-accent","text-xs text-foreground max-w-[520px] min-w-0",r),title:g?n:"未设置会话 Prompt(点击编辑)",children:[o.jsx("span",{className:"shrink-0 text-muted-foreground",children:"Prompt"}),o.jsx("span",{className:ve("truncate min-w-0",g?"text-foreground":"text-muted-foreground"),children:g?h:"未设置"})]}),s&&o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-3xl border border-border",children:o.jsxs("div",{className:"p-6",children:[o.jsxs("div",{className:"flex items-center justify-between gap-4",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground",children:"编辑会话 Prompt"}),o.jsx("button",{type:"button",onClick:()=>!d&&a(!1),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors","aria-label":"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"此 Prompt 会在每次对话时作为 system prompt 使用(会话级,独立于全局激活 Prompt)。"}),o.jsx("textarea",{value:i,onChange:w=>l(w.target.value),className:"mt-4 w-full min-h-[220px] px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"输入会话 Prompt...",disabled:d}),o.jsxs("div",{className:"flex gap-3 mt-4",children:[o.jsx("button",{type:"button",onClick:()=>a(!1),disabled:d,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"取消"}),o.jsx("button",{type:"button",onClick:p,disabled:d,className:"flex-1 px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:d?"保存中...":"保存"})]})]})})})]})},mc=({isOpen:r,onClose:e,manageOnly:t=!1,title:n,layout:s="modal",onApplicationSelect:a})=>{let i;try{i=tt()}catch{i=mt()}const{applications:l,loadApplications:d,createApplication:u,updateApplication:g,deleteApplication:h}=i,p=M.useRef(new Map),[w,m]=M.useState(!!t),[f,c]=M.useState(!1),[x,b]=M.useState(null),[y,_]=M.useState({name:"",url:"",iconUrl:""});M.useEffect(()=>{try{console.log("[ApplicationsPanel] useEffect -> loadApplications"),d==null||d()}catch(C){console.error("[ApplicationsPanel] loadApplications error:",C)}},[d]);const S=()=>{b(null),_({name:"",url:"",iconUrl:""}),c(!1)},j=async C=>{C.preventDefault(),y.name.trim()&&(x?await(g==null?void 0:g(x,{name:y.name.trim(),url:y.url.trim(),iconUrl:y.iconUrl.trim()||void 0})):await(u==null?void 0:u(y.name.trim(),y.url.trim(),y.iconUrl.trim()||void 0)),S())},v=C=>{console.log("[ApplicationsPanel] closeAppWindow:",C);const W=p.current.get(C);W&&!W.closed&&W.close(),p.current.delete(C)},I=C=>{console.log("[ApplicationsPanel] handleAppClick - 应用被点击:",{id:C.id,name:C.name,url:C.url}),a?(console.log("[ApplicationsPanel] 调用 onApplicationSelect 回调"),a(C)):console.log("[ApplicationsPanel] ⚠️ 未提供 onApplicationSelect 回调"),e&&(console.log("[ApplicationsPanel] 关闭应用列表面板"),e())};if(!(s==="modal"?!!r:!0))return null;const T=t?!0:w,L=n??(T?"应用管理":"应用列表");return s==="modal"?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:e}),o.jsxs("div",{className:"fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-4xl h-[85vh] bg-card z-50 shadow-xl breathing-border flex flex-col rounded-lg",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-full bg-blue-500"}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:L})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[!t&&o.jsx("button",{onClick:()=>{m(!w),c(!1),S()},className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent transition-colors",children:T?"浏览模式":"管理模式"}),!T&&p.current.size>0&&o.jsx("button",{className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent",onClick:()=>{p.current.forEach((C,W)=>v(W))},children:"关闭全部"}),o.jsx("button",{onClick:e,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:T?o.jsxs("div",{className:"space-y-4",children:[!f&&o.jsxs("button",{type:"button",onClick:()=>c(!0),className:"w-full p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v12m6-6H6"})}),o.jsx("span",{children:"新增应用"})]}),f&&o.jsxs("form",{onSubmit:j,className:"p-4 bg-muted rounded-lg space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"名称"}),o.jsx("input",{type:"text",value:y.name,onChange:C=>_({...y,name:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:Jira、GitHub",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL"}),o.jsx("input",{type:"text",value:y.url,onChange:C=>_({...y,url:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"https://app.example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"图标URL"}),o.jsx("input",{type:"text",value:y.iconUrl,onChange:C=>_({...y,iconUrl:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"https://app.example.com/icon.png"})]}),o.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[o.jsx("button",{type:"button",className:"px-3 py-2 rounded bg-muted hover:bg-accent",onClick:S,children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-2 rounded bg-blue-600 text-white hover:bg-blue-700",children:x?"保存":"创建"})]})]}),o.jsxs("div",{className:"space-y-2",children:[l==null?void 0:l.map(C=>o.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border hover:bg-muted transition-colors",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center overflow-hidden shrink-0",children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("span",{className:"text-white text-sm font-bold",children:C.name.charAt(0).toUpperCase()})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium text-foreground",children:C.name}),C.url&&o.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-md",children:C.url})]})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("button",{className:"px-2 py-1 text-xs bg-muted rounded hover:bg-accent",onClick:()=>{b(C.id),c(!0),_({name:C.name,url:C.url||"",iconUrl:C.iconUrl||""})},children:"编辑"}),o.jsx("button",{className:"px-2 py-1 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90",onClick:()=>h==null?void 0:h(C.id),children:"删除"})]})]},C.id)),(l==null?void 0:l.length)===0&&o.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[o.jsx("svg",{className:"w-16 h-16 mx-auto mb-3 opacity-30",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm",children:"暂无应用,点击上方按钮添加"})]})]})]}):o.jsxs("div",{className:"grid grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-6",children:[l==null?void 0:l.map(C=>{const W=p.current.has(C.id);return o.jsxs("div",{className:"relative group/item",children:[o.jsxs("button",{className:"w-full flex flex-col items-center space-y-2 p-2 rounded-lg transition-all hover:bg-muted",onClick:()=>I(C),title:C.url||"",children:[o.jsxs("div",{className:`relative w-16 h-16 rounded-full flex items-center justify-center overflow-hidden transition-all ${W?"ring-2 ring-green-500 ring-offset-2 ring-offset-background scale-110":"bg-gradient-to-br from-blue-500/20 to-purple-500/20 group-hover/item:scale-105"}`,children:[C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center",children:o.jsx("span",{className:"text-white text-xl font-bold",children:C.name.charAt(0).toUpperCase()})}),W&&o.jsx("div",{className:"absolute -top-1 -right-1 w-5 h-5 bg-green-500 rounded-full border-2 border-background flex items-center justify-center",children:o.jsx("div",{className:"w-2 h-2 bg-white rounded-full animate-pulse"})})]}),o.jsx("div",{className:"text-xs font-medium text-foreground text-center truncate w-full px-1",children:C.name})]}),W&&o.jsx("button",{onClick:B=>{B.stopPropagation(),v(C.id)},className:"absolute top-0 left-0 w-5 h-5 bg-red-500 hover:bg-red-600 rounded-full flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-opacity z-10",title:"关闭",children:o.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M6 18L18 6M6 6l12 12"})})})]},C.id)}),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-20 text-center",children:[o.jsx("svg",{className:"w-20 h-20 text-muted-foreground/30 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用"}),o.jsx("button",{onClick:()=>m(!0),className:"text-sm text-blue-500 hover:text-blue-600 underline",children:"点击切换到管理模式添加应用"})]})]})})]})]}):o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border bg-card/50",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-blue-500"}),o.jsx("span",{className:"text-sm font-medium text-foreground",children:L})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[!t&&o.jsx("button",{onClick:()=>{m(!w),c(!1),S()},className:"px-2 py-1 text-xs rounded bg-muted hover:bg-accent transition-colors",children:T?"浏览模式":"管理模式"}),!T&&p.current.size>0&&o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-muted hover:bg-accent",onClick:()=>{p.current.forEach((C,W)=>v(W))},children:"关闭全部"}),e&&o.jsx("button",{onClick:e,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mb-4 flex items-center justify-between",children:o.jsx("button",{type:"button",onClick:()=>{b(null),_({name:"",url:"",iconUrl:""}),c(C=>!C)},className:"px-3 py-1.5 text-sm rounded bg-primary text-primary-foreground hover:opacity-90",children:f?"取消":"新增应用"})}),f&&o.jsxs("form",{onSubmit:C=>{var O,U,J;C.preventDefault();const W=((O=y.name)==null?void 0:O.trim())||"",B=((U=y.url)==null?void 0:U.trim())||"",z=((J=y.iconUrl)==null?void 0:J.trim())||void 0;W&&(x?g==null||g(x,{name:W,url:B,iconUrl:z}):u==null||u(W,B,z),c(!1),S())},className:"p-4 bg-muted rounded-lg space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"名称"}),o.jsx("input",{value:y.name,onChange:C=>_({...y,name:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"例如:飞书"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"URL"}),o.jsx("input",{value:y.url,onChange:C=>_({...y,url:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"https://example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"图标地址"}),o.jsx("input",{value:y.iconUrl,onChange:C=>_({...y,iconUrl:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"https://.../icon.png"})]}),o.jsxs("div",{className:"flex justify-end space-x-2",children:[o.jsx("button",{type:"button",onClick:()=>{c(!1),S(),b(null)},className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent",children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-1.5 text-sm rounded bg-primary text-primary-foreground hover:opacity-90",children:x?"保存":"创建"})]})]}),o.jsxs("div",{className:"space-y-2",children:[l==null?void 0:l.map(C=>o.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border hover:bg-muted transition-colors",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center overflow-hidden shrink-0",children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("span",{className:"text-white text-sm font-bold",children:C.name.charAt(0).toUpperCase()})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium text-foreground",children:C.name}),C.url&&o.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-md",children:C.url})]})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-background hover:bg-accent",onClick:()=>{c(!0),b(C.id),_({name:C.name||"",url:C.url||"",iconUrl:C.iconUrl||""})},children:"编辑"}),o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-destructive text-destructive-foreground hover:opacity-90",onClick:()=>h==null?void 0:h(C.id),children:"删除"})]})]},C.id)),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center",children:[o.jsx("svg",{className:"w-16 h-16 text-muted-foreground/30 mb-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用,点击上方按钮添加。"})]})]})]}):o.jsxs("div",{className:"grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4",children:[l==null?void 0:l.map(C=>{const W=p.current.has(C.id);return o.jsxs("div",{className:"relative group/item",children:[o.jsxs("button",{className:"w-full flex flex-col items-center space-y-2 p-2 rounded-lg transition-all hover:bg-muted",onClick:()=>I(C),title:C.url||"",children:[o.jsx("div",{className:`relative w-14 h-14 rounded-full flex items-center justify-center overflow-hidden transition-all ${W?"ring-2 ring-green-500 ring-offset-2 ring-offset-background scale-105":"bg-gradient-to-br from-blue-500/20 to-purple-500/20 group-hover/item:scale-105"}`,children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center",children:o.jsx("span",{className:"text-white text-lg font-bold",children:C.name.charAt(0).toUpperCase()})})}),o.jsx("div",{className:"text-xs font-medium text-foreground truncate max-w-full",children:C.name}),C.url&&o.jsx("div",{className:"text-[10px] text-muted-foreground truncate max-w-full",children:C.url})]}),W&&o.jsx("button",{onClick:B=>{B.stopPropagation(),v(C.id)},className:"absolute top-0 left-0 w-4 h-4 bg-red-500 hover:bg-red-600 rounded-full flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-opacity z-10",title:"关闭",children:o.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M6 18L18 6M6 6l12 12"})})})]},C.id)}),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-10 text-center",children:[o.jsx("svg",{className:"w-16 h-16 text-muted-foreground/30 mb-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用"}),o.jsx("button",{onClick:()=>m(!0),className:"text-sm text-blue-500 hover:text-blue-600 underline",children:"切换到管理模式以添加应用"})]})]})})]})},So=({className:r,apiBaseUrl:e,port:t,userId:n,projectId:s,showMcpManager:a=!0,showAiModelManager:i=!0,showSystemContextEditor:l=!0,showAgentManager:d=!0,onApplicationSelect:u})=>{const g=M.useMemo(()=>{if(e)return e;if(t)return`http://localhost:${t}/api`},[e,t]),h=M.useMemo(()=>{if(g)return new er(g)},[g]);return o.jsx(Vf,{userId:n,projectId:s,customApiClient:h,children:o.jsx(zg,{className:r,showMcpManager:a,showAiModelManager:i,showSystemContextEditor:l,showAgentManager:d,onApplicationSelect:u})})},zg=({className:r,showMcpManager:e,showAiModelManager:t,showSystemContextEditor:n,showAgentManager:s,onApplicationSelect:a})=>{const i=Wl(),{currentSession:l,messages:d,isLoading:u,isStreaming:g,hasMoreMessages:h,error:p,loadSessions:w,sendMessage:m,clearError:f,mcpConfigs:c,loadMcpConfigs:x,getSessionMcpConfigIds:b,sessionMcpRevision:y,aiModelConfigs:_,selectedModelId:S,setSelectedModel:j,loadAiModelConfigs:v,agents:I,selectedAgentId:P,setSelectedAgent:T,loadAgents:L,abortCurrentConversation:C,loadMoreMessages:W}=i(),B=M.useRef(null),[z,O]=M.useState(!1),[U,J]=M.useState(""),[$,H]=M.useState(""),[F,k]=M.useState(!1),[A,N]=M.useState(!1),[D,R]=M.useState(!1),[q,Q]=M.useState(!1),[se,Te]=M.useState(!1);M.useEffect(()=>{(window.__standaloneChatInterfaceDidInit__??!1)||(window.__standaloneChatInterfaceDidInit__=!0,w(),v(),x(),L())},[w,v,x,L]),M.useEffect(()=>{B.current&&B.current.scrollIntoView({behavior:"smooth"})},[d,g]),M.useEffect(()=>{let qe=!1;const Rt=Fe=>{if(Fe.length===0)return{summary:"MCP:未选择",tooltip:"未选择 MCP"};const $t=Fe.join(",");return Fe.length<=2?{summary:`MCP:${$t}`,tooltip:`MCP:${$t}`}:{summary:`MCP:${Fe.slice(0,2).join(",")} +${Fe.length-2}`,tooltip:`MCP:${$t}`}};return(async()=>{if(!(l!=null&&l.id)){J(""),H("");return}try{const Fe=await b(l.id);if(qe)return;const $t=new Map((c||[]).map(Lt=>[Lt.id,Lt.name])),gc=(Fe||[]).map(Lt=>$t.get(Lt)||Lt),{summary:pc,tooltip:xc}=Rt(gc);J(pc),H(xc)}catch(Fe){if(console.error("Failed to load session MCP summary:",Fe),qe)return;J("MCP:加载失败"),H("MCP:加载失败")}})(),()=>{qe=!0}},[l==null?void 0:l.id,y,c,b]);const An=async(qe,Rt)=>{try{await m(qe,Rt)}catch(ze){console.error("Failed to send message:",ze)}};return o.jsxs("div",{className:ve("flex flex-col h-screen bg-background text-foreground",r),children:[o.jsxs("div",{className:"flex items-center justify-between p-4 bg-card border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("button",{onClick:()=>O(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开会话列表",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"})})}),l&&o.jsx("div",{className:"flex-1 min-w-0",children:o.jsx("h1",{className:"text-lg font-semibold text-foreground truncate",children:l.title})}),o.jsx(hc,{})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[a&&o.jsx("button",{onClick:()=>{console.log("[StandaloneChat] open ApplicationsPanel button clicked"),Te(!0)},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开应用列表",children:o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:[o.jsx("path",{d:"M4 5h6v14H4z",strokeWidth:"2"}),o.jsx("path",{d:"M12 5h8v14h-8z",strokeWidth:"2"})]})}),e&&o.jsx("button",{onClick:()=>k(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"MCP服务管理",children:o.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z"}),o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),t&&o.jsx("button",{onClick:()=>N(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"AI配置管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z"})})}),n&&o.jsx("button",{onClick:()=>R(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"System Prompt编辑器",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}),s&&o.jsx("button",{onClick:()=>Q(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"智能体管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})})}),o.jsx(yo,{})]})]}),p&&o.jsx("div",{className:"mx-4 mt-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:o.jsxs("div",{className:"flex items中心 justify-between",children:[o.jsx("p",{className:"text-sm text-destructive",children:p}),o.jsx("button",{onClick:f,className:"text-destructive hover:text-destructive/80 transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),o.jsx("div",{className:"flex-1 flex overflow-hidden",children:o.jsxs("div",{className:"flex-1 overflow-hidden",children:[l?o.jsx("div",{className:"flex flex-col h-full",children:o.jsx("div",{className:"flex-1 overflow-hidden",children:o.jsx(po,{messages:d,isLoading:u,isStreaming:g,hasMore:h,onLoadMore:()=>l&&W(l.id)})})}):o.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:o.jsxs("div",{className:"text-center",children:[o.jsx("svg",{className:"w-16 h-16 mx-auto mb-4 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),o.jsx("p",{className:"text-lg mb-2",children:"欢迎使用AI聊天助手"}),o.jsx("p",{className:"text-sm",children:"点击左上角按钮创建新会话开始对话"})]})}),o.jsx("div",{ref:B})]})}),l&&o.jsx(xo,{onSend:An,onStop:C,disabled:u||g,isStreaming:g,selectedModelId:S,availableModels:_,onModelChange:j,showModelSelector:!0,selectedAgentId:P,availableAgents:I,onAgentChange:T,sessionMcpSummary:U,sessionMcpTooltip:$}),o.jsx(bo,{isOpen:z,onClose:()=>O(!1),store:i}),o.jsx(mc,{isOpen:se,onClose:()=>Te(!1),title:"应用列表",layout:"modal",onApplicationSelect:a}),F&&o.jsx(wo,{onClose:()=>k(!1),store:i}),A&&o.jsx(vo,{onClose:()=>N(!1),store:i}),s&&q&&o.jsx(fc,{onClose:()=>Q(!1),store:i}),D&&o.jsx(_o,{onClose:()=>R(!1),store:i})]})};class Jg{constructor(e,t,n,s,a=!0,i=!0,l=!0,d=!0,u){V(this,"userId");V(this,"projectId");V(this,"configUrl");V(this,"apiClient");V(this,"store");V(this,"className");V(this,"showMcpManager");V(this,"showAiModelManager");V(this,"showSystemContextEditor");V(this,"showAgentManager");V(this,"onApplicationSelect");this.userId=e,this.projectId=t,this.configUrl=n||"/api",this.className=s,this.showMcpManager=a,this.showAiModelManager=i,this.showSystemContextEditor=l,this.showAgentManager=d,this.onApplicationSelect=u,console.log("🔧 AiChat Constructor - configUrl:",this.configUrl),console.log("🔧 AiChat Constructor - Module Controls:",{showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,hasApplicationSelectCallback:!!this.onApplicationSelect}),this.apiClient=new er(this.configUrl),this.store=Zr(this.apiClient,{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl})}render(){return M.createElement(Vg,{className:this.className,userId:this.userId,projectId:this.projectId,configUrl:this.configUrl,showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,onApplicationSelect:this.onApplicationSelect})}getConfig(){return{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl,className:this.className,showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,onApplicationSelect:this.onApplicationSelect}}updateConfig(e){e.userId&&(this.userId=e.userId),e.projectId&&(this.projectId=e.projectId),e.configUrl&&(this.configUrl=e.configUrl,this.apiClient=new er(this.configUrl),this.store=Zr(this.apiClient,{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl})),e.className!==void 0&&(this.className=e.className),e.showMcpManager!==void 0&&(this.showMcpManager=e.showMcpManager),e.showAiModelManager!==void 0&&(this.showAiModelManager=e.showAiModelManager),e.showSystemContextEditor!==void 0&&(this.showSystemContextEditor=e.showSystemContextEditor),e.showAgentManager!==void 0&&(this.showAgentManager=e.showAgentManager),e.onApplicationSelect!==void 0&&(this.onApplicationSelect=e.onApplicationSelect)}getStore(){return this.store}getApiClient(){return this.apiClient}getSelectedApplication(){var s;const e=this.store.getState(),t=e.selectedApplicationId;if(console.log("[AiChat] getSelectedApplication called:",{id:t,applicationsCount:(s=e.applications)==null?void 0:s.length}),!t)return null;const n=e.applications.find(a=>a.id===t)||null;return console.log("[AiChat] getSelectedApplication result:",n),n}getSelectedApplicationUrl(){const e=this.getSelectedApplication();return e?e.url:null}subscribeSelectedApplication(e){console.log("[AiChat] subscribeSelectedApplication: 设置订阅"),console.log("[AiChat] store 对象:",this.store),console.log("[AiChat] store.subscribe 类型:",typeof this.store.subscribe);let t=this.store.getState().selectedApplicationId;console.log("[AiChat] 初始 previousId:",t);const n=this.store.subscribe(s=>{const a=s.selectedApplicationId;if(console.log("[AiChat] store.subscribe 被触发, currentId:",a,"previousId:",t),a!==t){console.log("[AiChat] selectedApplicationId 变化检测到:",{old:t,new:a}),t=a;const i=this.getSelectedApplication();console.log("[AiChat] 准备调用 listener,app:",i),e(i)}});return console.log("[AiChat] 首次调用 listener"),e(this.getSelectedApplication()),()=>{console.log("[AiChat] 取消订阅"),n()}}}const Vg=({className:r,userId:e,projectId:t,configUrl:n,showMcpManager:s,showAiModelManager:a,showSystemContextEditor:i,showAgentManager:l,onApplicationSelect:d})=>o.jsx(So,{className:r,apiBaseUrl:n,userId:e,projectId:t,showMcpManager:s,showAiModelManager:a,showSystemContextEditor:i,showAgentManager:l,onApplicationSelect:d}),Gg=({className:r,onMessageSend:e,customRenderer:t})=>{const{currentSession:n,messages:s,isLoading:a,isStreaming:i,hasMoreMessages:l,error:d,loadSessions:u,loadMoreMessages:g,sendMessage:h,clearError:p,mcpConfigs:w,loadMcpConfigs:m,getSessionMcpConfigIds:f,sessionMcpRevision:c,aiModelConfigs:x,selectedModelId:b,setSelectedModel:y,loadAiModelConfigs:_,agents:S,selectedAgentId:j,setSelectedAgent:v,loadAgents:I,abortCurrentConversation:P}=tt(),T=M.useRef(null),[L,C]=M.useState(!1),[W,B]=M.useState(!1),[z,O]=M.useState(!1),[U,J]=M.useState(!1),[$,H]=M.useState(!1),[F,k]=M.useState(""),[A,N]=M.useState("");M.useEffect(()=>{(window.__chatInterfaceDidInit__??!1)||(window.__chatInterfaceDidInit__=!0,u(),_(),m(),I())},[u,_,m,I]),M.useEffect(()=>{T.current&&T.current.scrollIntoView({behavior:"smooth"})},[s,i]),M.useEffect(()=>{let R=!1;const q=se=>{if(se.length===0)return{summary:"MCP:未选择",tooltip:"未选择 MCP"};const Te=se.join(",");return se.length<=2?{summary:`MCP:${Te}`,tooltip:`MCP:${Te}`}:{summary:`MCP:${se.slice(0,2).join(",")} +${se.length-2}`,tooltip:`MCP:${Te}`}};return(async()=>{if(!(n!=null&&n.id)){k(""),N("");return}try{const se=await f(n.id);if(R)return;const Te=new Map((w||[]).map(ze=>[ze.id,ze.name])),An=(se||[]).map(ze=>Te.get(ze)||ze),{summary:qe,tooltip:Rt}=q(An);k(qe),N(Rt)}catch(se){if(console.error("Failed to load session MCP summary:",se),R)return;k("MCP:加载失败"),N("MCP:加载失败")}})(),()=>{R=!0}},[n==null?void 0:n.id,c,w,f]);const D=async(R,q)=>{try{await h(R,q),e==null||e(R,[])}catch(Q){console.error("Failed to send message:",Q)}};return o.jsxs("div",{className:ve("flex flex-col h-screen bg-background text-foreground",r),children:[d&&o.jsx("div",{className:"mx-4 mt-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("p",{className:"text-sm text-destructive",children:d}),o.jsx("button",{onClick:p,className:"text-destructive hover:text-destructive/80 transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),o.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[o.jsx("div",{className:"flex flex-col h-full",children:o.jsx(bo,{embedded:!0})}),o.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n&&o.jsxs("div",{className:"flex items-center justify-between p-4 bg-card border-b border-border",children:[o.jsx("div",{className:"flex items-center space-x-3",children:o.jsx(hc,{})}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx(yo,{}),o.jsx("button",{onClick:()=>H(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开应用列表",children:o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:[o.jsx("path",{d:"M4 5h6v14H4z",strokeWidth:"2"}),o.jsx("path",{d:"M12 5h8v14h-8z",strokeWidth:"2"})]})}),o.jsx("button",{onClick:()=>C(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"MCP 服务器管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})})}),o.jsx("button",{onClick:()=>J(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"智能体管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})})}),o.jsx("button",{onClick:()=>B(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"AI 模型管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),o.jsx("button",{onClick:()=>O(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"系统上下文设置",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})})]})]}),n?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex-1 overflow-auto",children:[o.jsx(po,{messages:s,isLoading:a,isStreaming:i,hasMore:l,onLoadMore:()=>n&&g(n.id),customRenderer:t}),o.jsx("div",{ref:T})]}),o.jsx("div",{className:"border-t border-border",children:o.jsx(xo,{onSend:D,onStop:P,disabled:a,isStreaming:i,placeholder:"输入消息...",showModelSelector:!0,selectedModelId:b,availableModels:x,onModelChange:y,selectedAgentId:j,availableAgents:S,onAgentChange:v,sessionMcpSummary:F,sessionMcpTooltip:A})})]}):o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsxs("div",{className:"text-center",children:[o.jsx("h2",{className:"text-xl font-semibold text-muted-foreground mb-2",children:"欢迎使用 AI 聊天"}),o.jsx("p",{className:"text-muted-foreground mb-4",children:"从左侧会话列表选择会话,或创建新的会话开始对话"})]})})]})]}),L&&o.jsx(wo,{onClose:()=>C(!1)}),U&&o.jsx(fc,{onClose:()=>J(!1)}),W&&o.jsx(vo,{onClose:()=>B(!1)}),z&&o.jsx(_o,{onClose:()=>O(!1)}),o.jsx(mc,{isOpen:$,onClose:()=>H(!1),title:"应用列表",layout:"modal"})]})};class Xg extends M.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("ErrorBoundary caught an error:",e,t)}render(){var e;return this.state.hasError?this.props.fallback?this.props.fallback:o.jsx("div",{className:"flex items-center justify-center h-full p-8",children:o.jsxs("div",{className:"text-center space-y-4",children:[o.jsx("div",{className:"w-16 h-16 mx-auto bg-destructive/10 rounded-full flex items-center justify-center",children:o.jsx("svg",{className:"w-8 h-8 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Something went wrong"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:((e=this.state.error)==null?void 0:e.message)||"An unexpected error occurred"}),o.jsx("button",{onClick:()=>this.setState({hasError:!1,error:void 0}),className:"mt-4 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors",children:"Try again"})]})]})}):this.props.children}}const Kg="1.0.11";exports.AiChat=Jg;exports.AiModelManager=vo;exports.AiServer=Fl;exports.ApiClient=er;exports.AppError=ug;exports.AttachmentRenderer=nc;exports.ChatIcon=cc;exports.ChatInterface=Gg;exports.ChatService=Bl;exports.CheckIcon=gg;exports.ChevronDownIcon=yg;exports.CopyIcon=xg;exports.DatabaseService=As;exports.DotsVerticalIcon=ic;exports.ErrorBoundary=Xg;exports.InputArea=xo;exports.LoadingSpinner=oc;exports.MarkdownRenderer=lt;exports.McpManager=wo;exports.MessageItem=sc;exports.MessageList=po;exports.MessageManager=Ul;exports.PencilIcon=Ss;exports.PlayIcon=bg;exports.PlusIcon=ac;exports.SessionList=bo;exports.StandaloneChatInterface=So;exports.SystemContextEditor=_o;exports.ThemeToggle=yo;exports.ToolCallRenderer=_s;exports.TrashIcon=lc;exports.XIcon=pg;exports.apiClient=te;exports.cleanHtmlContent=eg;exports.cn=ve;exports.conversationsApi=Or;exports.copyToClipboard=ig;exports.debounce=ng;exports.deepClone=vs;exports.default=So;exports.downloadFile=lg;exports.formatDate=Ym;exports.formatDateTime=Qm;exports.formatFileSize=tc;exports.formatRelativeTime=Km;exports.formatTime=ec;exports.generateId=Xm;exports.generateRandomColor=ag;exports.getFileExtension=rc;exports.getOS=dg;exports.isImageFile=og;exports.isMobile=cg;exports.isValidEmail=tg;exports.isValidUrl=rg;exports.retry=fg;exports.storage=hg;exports.throttle=sg;exports.truncateText=Zm;exports.useChatStore=mt;exports.useTheme=uc;exports.version=Kg;
100
+ `}),v})(),c=(()=>{if(!d)return null;if(i&&typeof i=="object")return i;if(typeof i=="string")try{const S=JSON.parse(i);if(S&&typeof S=="object")return S}catch{return null}return null})(),x=!!(c&&typeof c=="object"),b=S=>{if(S===null)return"null";if(Array.isArray(S)){if(S.length===0)return"array []";const j=S[0],v=b(j);return v==="object"?"object []":`${v}[]`}switch(typeof S){case"string":return"string";case"number":return Number.isInteger(S)?"integer":"number";case"boolean":return"boolean";case"object":return"object";default:return typeof S}},y=(S,j="",v="")=>{const I=[];if(S==null)return I;if(Array.isArray(S)){const P={path:v||j||"list",name:j||"list",type:b(S),value:S,children:S.map((T,L)=>{const C=`${v||j||"list"}[${L}]`,W=b(T);return{path:C,name:`[${L}]`,type:W,value:T,children:W==="object"||Array.isArray(T)?y(T,`[${L}]`,C):[]}})};return I.push(P),I}return typeof S=="object"&&Object.keys(S).forEach(P=>{const T=S[P],L=v?`${v}.${P}`:P,C=b(T),W=C==="object"||Array.isArray(T)?y(T,P,L):[];I.push({path:L,name:P,type:C,value:T,children:W})}),I},_=({data:S})=>{const j=Array.isArray(S)?y(S,"list","list"):y(S,"",""),[v,I]=M.useState(()=>new Set(j.filter(C=>C.children.length>0).map(C=>C.path))),P=C=>{I(W=>{const B=new Set(W);return B.has(C)?B.delete(C):B.add(C),B})},T=C=>{if(C===null)return"null";if(Array.isArray(C))return`数组(${C.length})`;if(typeof C=="object")return"对象";if(typeof C=="string")return C;try{return JSON.stringify(C)}catch{return String(C)}},L=(C,W)=>C.map(B=>{const z=B.children&&B.children.length>0,O=v.has(B.path),U=z?O?"▾":"▸":"",J=T(B.value);return o.jsxs(M.Fragment,{children:[o.jsxs("tr",{children:[o.jsxs("td",{style:{paddingLeft:W*16},children:[z?o.jsx("button",{type:"button",onClick:()=>P(B.path),className:"mr-2 text-gray-600 dark:text-gray-300 hover:text-black dark:hover:text-white","aria-label":O?"收起":"展开",children:U}):o.jsx("span",{className:"mr-4"}),B.name]}),o.jsx("td",{style:{whiteSpace:"normal",wordBreak:"break-word"},children:J})]}),z&&O&&L(B.children,W+1)]},B.path)});return o.jsx("div",{className:"border-l-4 border-green-400 dark:border-green-500 rounded-lg overflow-hidden bg-green-50/50 dark:bg-green-900/20 mb-2",children:o.jsx("div",{className:"markdown-renderer",children:o.jsxs("table",{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"字段"}),o.jsx("th",{children:"值"})]})}),o.jsx("tbody",{children:L(j,0)})]})})})};return o.jsxs("div",{className:"tool-call-renderer tool-call-container",children:[o.jsxs("div",{className:"tool-header",children:[o.jsxs("span",{className:"tool-name",children:["@",r.name]}),l&&o.jsx("span",{className:"status-badge status-error",children:"错误"}),d&&!l&&o.jsx("span",{className:"status-badge status-success",children:"完成"}),!d&&!l&&o.jsx("span",{className:"status-badge status-pending",children:"等待中"}),(h||d||l)&&o.jsx("button",{onClick:()=>s(!n),className:"toggle-button",children:n?"收起详情":"查看详情"})]}),n&&o.jsxs("div",{className:"details-container",children:[h&&o.jsx("div",{children:m&&o.jsx("div",{className:"border-l-4 border-blue-400 dark:border-blue-500 rounded-lg overflow-hidden bg-blue-50/50 dark:bg-blue-900/20 mb-4",children:o.jsx(lt,{content:m})})}),d&&o.jsxs("div",{children:[o.jsx("div",{className:"details-title",children:"结果:"}),x?o.jsx(_,{data:c}):o.jsx(lt,{content:typeof i=="string"?i:JSON.stringify(i)})]}),l&&o.jsxs("div",{children:[o.jsx("div",{className:"details-title",children:"错误:"}),o.jsx("div",{className:"status-badge status-error",style:{display:"block",padding:"0.5rem"},children:r.error})]}),o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 border-t border-gray-200 dark:border-gray-700 pt-2",children:["执行时间: ",(()=>{const S=new Date(r.createdAt);return isNaN(S.getTime())?"时间未知":S.toLocaleString()})()]})]})]})},mg=({message:r,isLast:e=!1,isStreaming:t=!1,onEdit:n,onDelete:s,allMessages:a=[],customRenderer:i})=>{var v,I,P,T,L,C,W,B,z;console.log("🚀🚀🚀 MessageItem 组件被调用!消息ID:",r.id,"角色:",r.role),console.log("🚀🚀🚀 完整消息对象:",r);const[l,d]=M.useState(!1),[u,g]=M.useState(r.content),h=(O,U)=>{navigator.clipboard.writeText(O).then(()=>{console.log("代码已复制到剪贴板:",{code:O,language:U})}).catch(J=>{console.error("复制失败:",J)})},[p,w]=M.useState(!1),m=r.role==="user",f=r.role==="assistant",c=r.role==="system",x=r.role==="tool";if(x)return null;if(i!=null&&i.renderMessage)return o.jsx("div",{children:i.renderMessage(r)});const b=()=>{n&&u.trim()!==r.content&&n(r.id,u.trim()),d(!1)},y=()=>{g(r.content),d(!1)},_=async()=>{try{await navigator.clipboard.writeText(r.content)}catch(O){console.error("Failed to copy message:",O)}},S=((v=r.metadata)==null?void 0:v.attachments)||[],j=r.toolCalls||((I=r.metadata)==null?void 0:I.toolCalls)||[];return console.log("🔧 工具调用数据:",{顶层toolCalls:r.toolCalls,"metadata.toolCalls":(P=r.metadata)==null?void 0:P.toolCalls,最终toolCalls长度:j.length,消息ID:r.id,contentSegments:(T=r.metadata)==null?void 0:T.contentSegments,contentSegments长度:((C=(L=r.metadata)==null?void 0:L.contentSegments)==null?void 0:C.length)||0}),o.jsxs("div",{className:ve("group relative rounded-lg transition-colors",!f&&"flex gap-3 px-4 py-4",f&&"px-4 py-2",m&&"bg-user-message",c&&"bg-muted border-l-4 border-primary",x&&"bg-blue-50 dark:bg-blue-950/20 border-l-4 border-blue-500","hover:bg-opacity-80"),onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),children:[!f&&o.jsx("div",{className:"flex-shrink-0",children:o.jsx("div",{className:ve("w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium",m&&"bg-primary text-primary-foreground",c&&"bg-muted text-muted-foreground",x&&"bg-blue-500 text-white"),children:m?"U":x?"T":"S"})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[!f&&o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-sm font-medium",children:m?"You":x?"Tool Result":"System"}),o.jsx("span",{className:"text-xs text-muted-foreground",children:ec(r.createdAt)})]}),((W=r.metadata)==null?void 0:W.type)==="session_summary"&&o.jsxs("div",{className:"mb-3 border border-amber-300 dark:border-amber-600/50 bg-amber-50 dark:bg-amber-950/20 rounded-md p-3",children:[o.jsxs("div",{className:"text-xs text-amber-900 dark:text-amber-200 font-medium mb-1",children:["上下文已压缩为摘要",typeof((B=r.metadata)==null?void 0:B.keepLastN)=="number"?`(保留最近 ${r.metadata.keepLastN} 条)`:""]}),o.jsxs("details",{className:"group",children:[o.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground select-none",children:"查看摘要内容"}),o.jsx("div",{className:"mt-2 prose prose-sm max-w-none",children:o.jsx(lt,{content:(r.rawContent||((z=r.metadata)==null?void 0:z.summary)||"").toString(),isStreaming:!1,onApplyCode:()=>{}})})]})]}),S.length>0&&o.jsx("div",{className:"mb-3 space-y-2",children:S.map(O=>o.jsx(nc,{attachment:O,customRenderer:i==null?void 0:i.renderAttachment},O.id))}),l?o.jsxs("div",{className:"space-y-2",children:[o.jsx("textarea",{value:u,onChange:O=>g(O.target.value),className:"w-full p-2 border rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-primary",rows:3,autoFocus:!0}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("button",{onClick:b,className:"px-3 py-1 text-sm bg-primary text-primary-foreground rounded hover:bg-primary/90",children:"Save"}),o.jsx("button",{onClick:y,className:"px-3 py-1 text-sm bg-muted text-muted-foreground rounded hover:bg-muted/80",children:"Cancel"})]})]}):o.jsx("div",{className:"space-y-3",children:(()=>{var $;const O=(($=r.metadata)==null?void 0:$.contentSegments)||[],U=r.content&&r.content.trim().length>0,J=t&&e;return O.length>0?(console.log("🎨 使用分段渲染,分段数量:",O.length),console.log("🎨 分段详情:",O),o.jsx("div",{className:"space-y-0.5",children:O.map((H,F)=>{if(console.log(`🎨 渲染分段 ${F}:`,H),H.type==="text")return console.log(`🎨 渲染文本分段 ${F}:`,H.content),o.jsx("div",{className:"prose prose-sm max-w-none",children:o.jsx(lt,{content:H.content,isStreaming:J&&F===O.length-1,onApplyCode:h})},`segment-${F}`);if(H.type==="tool_call"){console.log(`🎨 渲染工具调用分段 ${F}:`,H);const k=j.find(A=>A.id===H.toolCallId);if(console.log(`🎨 查找工具调用 ${H.toolCallId}:`,k),k)return console.log("🎨 找到工具调用,开始渲染:",k),o.jsx("div",{children:o.jsx(_s,{toolCall:k,allMessages:a})},`tool-${k.id}`);console.log(`🎨 ❌ 未找到工具调用 ${H.toolCallId}`)}else if(H.type==="thinking")return console.log(`🎨 渲染思考分段 ${F}:`,H.content),o.jsxs("details",{className:"group border border-gray-200 dark:border-gray-700 rounded-md bg-muted px-3 py-2",children:[o.jsx("summary",{className:"cursor-pointer text-xs text-gray-500 dark:text-gray-400 select-none",children:"思考过程"}),o.jsx("div",{className:"mt-1",children:o.jsx(lt,{content:H.content||"",isStreaming:J&&F===O.length-1,onApplyCode:h,className:"thinking not-prose"})})]},`thinking-${F}`);return null})})):(console.log("🎨 使用传统渲染方式"),console.log("🎨 hasContent:",U),console.log("🎨 toolCalls.length:",j.length),o.jsxs("div",{className:"space-y-0.5",children:[U&&o.jsx("div",{className:"prose prose-sm max-w-none",children:o.jsx(lt,{content:r.content,isStreaming:J,onApplyCode:h})}),j.length>0&&o.jsxs("div",{className:"space-y-0.5",children:[o.jsx("div",{className:"text-sm text-muted-foreground font-medium",children:"工具调用:"}),j.map(H=>(console.log("🎨 传统方式渲染工具调用:",H),o.jsx("div",{children:o.jsx(_s,{toolCall:H,allMessages:a})},`tool-${H.id}`)))]})]}))})()}),r.tokensUsed&&o.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["Tokens used: ",r.tokensUsed]})]}),p&&!l&&o.jsxs("div",{className:"absolute top-2 right-2 flex gap-1 bg-background border rounded-md shadow-sm opacity-0 group-hover:opacity-100 transition-opacity",children:[o.jsx("button",{onClick:_,className:"p-1.5 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors",title:"Copy message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),m&&n&&o.jsx("button",{onClick:()=>d(!0),className:"p-1.5 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors",title:"Edit message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),s&&o.jsx("button",{onClick:()=>s(r.id),className:"p-1.5 hover:bg-destructive/10 rounded text-muted-foreground hover:text-destructive transition-colors",title:"Delete message",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})},sc=M.memo(mg,(r,e)=>r.message.id===e.message.id&&r.message.content===e.message.content&&r.message.createdAt===e.message.createdAt&&r.isLast===e.isLast&&r.isStreaming===e.isStreaming&&JSON.stringify(r.message.metadata)===JSON.stringify(e.message.metadata)),oc=({size:r="md",className:e})=>{const t={sm:"w-4 h-4",md:"w-6 h-6",lg:"w-8 h-8"};return o.jsx("div",{className:ve("animate-spin rounded-full border-2 border-current border-t-transparent",t[r],e),role:"status","aria-label":"Loading",children:o.jsx("span",{className:"sr-only",children:"Loading..."})})},po=({messages:r,isLoading:e=!1,isStreaming:t=!1,hasMore:n=!1,onLoadMore:s,onMessageEdit:a,onMessageDelete:i,customRenderer:l})=>{const d=M.useRef(null),u=M.useRef(null),[g,h]=M.useState(!0),[p,w]=M.useState(!0),m=()=>{const b=d.current;return b?b.scrollHeight-b.scrollTop-b.clientHeight<=40:!0},f=(b=!0)=>{var y;(y=u.current)==null||y.scrollIntoView({behavior:b?"smooth":"auto"})};M.useEffect(()=>{t&&g&&f(!0)},[r,t,g]),M.useEffect(()=>{w(m())},[r,t]),M.useEffect(()=>{t&&p&&h(!0),t||h(!1)},[t,p]);const c=()=>{const b=m();w(b),b||h(!1)},x=()=>{f(!0),h(!0)};return r.length===0&&!e?o.jsx("div",{className:"flex items-center justify-center h-full",children:o.jsxs("div",{className:"text-center space-y-4",children:[o.jsx("div",{className:"w-16 h-16 mx-auto bg-muted rounded-full flex items-center justify-center",children:o.jsx("svg",{className:"w-8 h-8 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Start a conversation"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Send a message to begin your chat with AI"})]})]})}):o.jsxs("div",{className:"flex flex-col h-full relative",children:[o.jsxs("div",{ref:d,onScroll:c,className:"flex-1 overflow-y-auto px-4 py-6 space-y-1",style:{willChange:"scroll-position",transform:"translateZ(0)"},children:[n&&o.jsx("div",{className:"flex justify-center mb-2",children:o.jsx("button",{type:"button",onClick:s,className:"text-sm px-3 py-1 rounded border border-border text-foreground hover:bg-accent",children:"加载更多"})}),(r||[]).filter(b=>{var y;return!((y=b==null?void 0:b.metadata)!=null&&y.hidden)}).map((b,y,_)=>o.jsx(sc,{message:b,isLast:y===_.length-1,isStreaming:t&&y===_.length-1,onEdit:a,onDelete:i,allMessages:r,customRenderer:l},b.id)),e&&o.jsx("div",{className:"flex justify-start",children:o.jsxs("div",{className:"flex items-center space-x-2 bg-muted px-4 py-3 rounded-lg max-w-xs",children:[o.jsx(oc,{size:"sm"}),o.jsx("span",{className:"text-sm text-muted-foreground",children:"AI is thinking..."})]})}),o.jsx("div",{ref:u})]}),!p&&o.jsxs("button",{type:"button","aria-label":"回到底部",title:"回到底部",onClick:x,className:"absolute bottom-4 right-4 z-10 flex items-center gap-2 rounded-full bg-primary text-primary-foreground px-4 py-2 shadow-md hover:bg-primary/90",children:[o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M12 5v12"}),o.jsx("path",{d:"M19 12l-7 7-7-7"})]}),o.jsx("span",{className:"text-sm",children:"回到底部"})]})]})},xo=({onSend:r,onStop:e,disabled:t=!1,isStreaming:n=!1,placeholder:s="Type your message...",maxLength:a=4e3,allowAttachments:i=!1,supportedFileTypes:l=["image/*","text/*","application/pdf"],showModelSelector:d=!1,selectedModelId:u=null,availableModels:g=[],onModelChange:h,selectedAgentId:p=null,availableAgents:w=[],onAgentChange:m,sessionMcpSummary:f,sessionMcpTooltip:c})=>{const[x,b]=M.useState(""),[y,_]=M.useState([]),[S,j]=M.useState(!1),v=M.useRef(null),I=M.useRef(null);M.useEffect(()=>{console.log("InputArea - isStreaming 状态变化:",{isStreaming:n,disabled:t,onStop:!!e,timestamp:new Date().toISOString()})},[n,t,e]);const P=M.useCallback(()=>{const $=v.current;if($){$.style.height="auto";const H=$.scrollHeight,F=200;$.style.height=`${Math.min(H,F)}px`}},[]),T=$=>{const H=$.target.value;H.length<=a&&(b(H),P())},L=$=>{$.key==="Enter"&&!$.shiftKey&&($.preventDefault(),C())},C=()=>{const $=x.trim();if(!(!$&&y.length===0)&&!t){if(d&&!u&&!p){alert("请先选择一个模型或智能体");return}r($,y),b(""),_([]),v.current&&(v.current.style.height="auto")}},W=$=>{const H=Array.from($.target.files||[]);_(F=>[...F,...H]),I.current&&(I.current.value="")},B=$=>{_(H=>H.filter((F,k)=>k!==$))},z=$=>{$.preventDefault(),i&&!t&&j(!0)},O=$=>{$.preventDefault(),j(!1)},U=$=>{if($.preventDefault(),j(!1),!i||t)return;const H=Array.from($.dataTransfer.files);_(F=>[...F,...H])},J=$=>{if($===0)return"0 Bytes";const H=1024,F=["Bytes","KB","MB","GB"],k=Math.floor(Math.log($)/Math.log(H));return parseFloat(($/Math.pow(H,k)).toFixed(2))+" "+F[k]};return o.jsxs("div",{className:"border-t bg-background p-4",children:[d&&o.jsxs("div",{className:"mb-3 flex items-center gap-3 flex-wrap",children:[g.length>0||w.length>0?o.jsxs("select",{value:p?`agent:${p}`:u||"",onChange:$=>{const H=$.target.value;if(H.startsWith("agent:")){const F=H.replace("agent:","");m==null||m(F),h==null||h(null)}else h==null||h(H||null),m==null||m(null)},disabled:t,className:ve("w-80 max-w-full px-3 py-2 border border-input bg-background rounded-md","text-sm text-foreground placeholder:text-muted-foreground","focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent","disabled:opacity-50 disabled:cursor-not-allowed"),children:[o.jsx("option",{value:"",children:"请选择模型或智能体..."}),w&&w.filter($=>$.enabled).length>0&&o.jsx("optgroup",{label:"智能体",children:w.filter($=>$.enabled).map($=>o.jsxs("option",{value:`agent:${$.id}`,children:["[Agent] ",$.name]},$.id))}),g&&g.filter($=>$.enabled).length>0&&o.jsx("optgroup",{label:"模型",children:g.filter($=>$.enabled).map($=>o.jsxs("option",{value:$.id,children:[$.name," (",$.model_name,")"]},$.id))})]}):o.jsx("div",{className:"w-80 max-w-full px-3 py-2 border border-input bg-muted rounded-md text-sm text-muted-foreground",children:"暂无可用模型或智能体,请先在右上角配置"}),f?o.jsx("div",{className:"max-w-[360px] min-w-0 px-2 py-1 rounded-lg border border-border bg-muted/10 text-xs text-muted-foreground",title:c||f,children:o.jsx("span",{className:"truncate min-w-0 block",children:f})}):null]}),y.length>0&&o.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:y.map(($,H)=>o.jsxs("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-lg text-sm",children:[o.jsx("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})}),o.jsx("span",{className:"truncate max-w-32",children:$.name}),o.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",J($.size),")"]}),o.jsx("button",{onClick:()=>B(H),className:"text-muted-foreground hover:text-destructive transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},H))}),o.jsxs("div",{className:ve("relative flex items-end gap-2 p-3 border rounded-lg transition-colors","focus-within:border-primary",S&&"border-primary bg-primary/5",t&&"opacity-50 cursor-not-allowed"),onDragOver:z,onDragLeave:O,onDrop:U,children:[i&&o.jsx("button",{onClick:()=>{var $;return($=I.current)==null?void 0:$.click()},disabled:t,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Attach files",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}),o.jsx("textarea",{ref:v,value:x,onChange:T,onKeyDown:L,placeholder:s,disabled:t,className:ve("flex-1 resize-none bg-transparent border-none outline-none","placeholder:text-muted-foreground","disabled:cursor-not-allowed"),rows:1,style:{minHeight:"24px",maxHeight:"200px"}}),o.jsxs("div",{className:"flex-shrink-0 text-xs text-muted-foreground",children:[x.length,"/",a]}),n?o.jsx("button",{onClick:()=>{console.log("停止按钮被点击",{onStop:e,disabled:t}),e&&e()},disabled:!1,className:ve("flex-shrink-0 p-2 rounded-md transition-colors","bg-red-500 text-white hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),title:"停止生成",style:{backgroundColor:"#ef4444",color:"white"},children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 6h12v12H6z"})})}):o.jsx("button",{onClick:C,disabled:t||n||!x.trim()&&y.length===0,className:ve("flex-shrink-0 p-2 rounded-md transition-colors","disabled:opacity-50 disabled:cursor-not-allowed",(x.trim()||y.length>0)&&!t&&!n?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"),title:d&&!u?"请先选择AI模型":"Send message",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})}),i&&o.jsx("input",{ref:I,type:"file",multiple:!0,accept:l.join(","),onChange:W,className:"hidden"})]}),S&&i&&o.jsx("div",{className:"absolute inset-0 bg-primary/10 border-2 border-dashed border-primary rounded-lg flex items-center justify-center",children:o.jsxs("div",{className:"text-center",children:[o.jsx("svg",{className:"w-8 h-8 mx-auto text-primary mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})}),o.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files here to attach"})]})})]})},ac=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),ic=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"})}),Ss=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),lc=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),gg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),pg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),cc=({className:r="w-5 h-5"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),xg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),bg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-9 4h10a1 1 0 001-1V7a1 1 0 00-1-1H7a1 1 0 00-1 1v10a1 1 0 001 1z"})}),yg=({className:r="w-4 h-4"})=>o.jsx("svg",{className:r,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),xr=({isOpen:r,title:e,message:t,confirmText:n="确认",cancelText:s="取消",onConfirm:a,onCancel:i,type:l="danger",verificationText:d,verificationLabel:u,verificationPlaceholder:g,verificationHint:h})=>{const[p,w]=M.useState("");if(M.useEffect(()=>{r&&w("")},[r,d]),!r)return null;const m=!!d,f=m&&p.trim()!==(d==null?void 0:d.trim()),c=()=>{switch(l){case"danger":return"bg-red-600 hover:bg-red-700 text-white";case"warning":return"bg-yellow-600 hover:bg-yellow-700 text-white";default:return"bg-blue-600 hover:bg-blue-700 text-white"}};return o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-sm border border-border animate-breathing-border",children:o.jsxs("div",{className:"p-6",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-2",children:e}),o.jsx("p",{className:"text-muted-foreground text-sm mb-6",children:t}),m&&o.jsxs("div",{className:"mb-6",children:[o.jsx("label",{className:"block text-xs font-medium text-muted-foreground mb-2",children:u||"请输入以下内容以继续操作"}),o.jsx("div",{className:"px-3 py-2 bg-muted rounded-md text-sm font-mono text-foreground border border-border mb-2",children:d}),o.jsx("input",{type:"text",value:p,onChange:x=>w(x.target.value),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:g||"输入上方关键字以确认",autoFocus:!0}),o.jsx("p",{className:"text-[12px] text-muted-foreground mt-2",children:h||"为了防止误删,需要您再次确认此操作。"})]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{onClick:i,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors",children:s}),o.jsx("button",{onClick:a,disabled:f,className:`flex-1 px-4 py-2 text-sm rounded-md transition-colors ${c()} ${f?"opacity-50 cursor-not-allowed":""}`,children:n})]})]})})})},br=()=>{const[r,e]=M.useState({isOpen:!1,title:"",message:"",confirmText:"确认",cancelText:"取消",type:"danger"}),t=M.useCallback(i=>{e({isOpen:!0,title:i.title,message:i.message,confirmText:i.confirmText||"确认",cancelText:i.cancelText||"取消",type:i.type||"danger",onConfirm:i.onConfirm,onCancel:i.onCancel,verificationText:i.verificationText,verificationLabel:i.verificationLabel,verificationPlaceholder:i.verificationPlaceholder,verificationHint:i.verificationHint})},[]),n=M.useCallback(()=>{e(i=>({...i,isOpen:!1}))},[]),s=M.useCallback(()=>{var i;(i=r.onConfirm)==null||i.call(r),n()},[r.onConfirm,n]),a=M.useCallback(()=>{var i;(i=r.onCancel)==null||i.call(r),n()},[r.onCancel,n]);return{dialogState:r,showConfirmDialog:t,hideConfirmDialog:n,handleConfirm:s,handleCancel:a}},Tr=r=>r===!0||r===1||r==="1",Ta=(r,e)=>r.includes(e)?r.filter(t=>t!==e):[...r,e],Oa=({isOpen:r,onClose:e,onCreate:t,availableModels:n,availableMcpConfigs:s,availablePrompts:a,defaultTitle:i="New Chat",defaultModelId:l=null,initialMcpConfigIds:d,initialPromptIds:u,dialogTitle:g="新建会话",confirmText:h="创建"})=>{const p=M.useMemo(()=>(n||[]).filter(z=>Tr(z.enabled)),[n]),w=M.useMemo(()=>(s||[]).filter(z=>Tr(z.enabled)),[s]),m=M.useMemo(()=>s||[],[s]),[f,c]=M.useState(i),[x,b]=M.useState(""),[y,_]=M.useState([]),[S,j]=M.useState([]),[v,I]=M.useState(!1),[P,T]=M.useState(!1),[L,C]=M.useState(!1),W=M.useMemo(()=>(a||[]).filter(z=>Tr(z.isActive??z.is_active??!1)).map(z=>z.id),[a]);if(M.useEffect(()=>{var O;if(!r)return;c(i),_(Array.isArray(d)?d:w.map(U=>U.id)),j(Array.isArray(u)?u:W),I(!1),T(!1),C(!1);const z=((O=p[0])==null?void 0:O.id)||"";b(l||z)},[r]),M.useEffect(()=>{var O;if(!r||x)return;const z=((O=p[0])==null?void 0:O.id)||"";!l&&!z||b(l||z)},[r,x,l,p]),M.useEffect(()=>{r&&(Array.isArray(d)||P||y.length>0||w.length!==0&&_(w.map(z=>z.id)))},[r,d,P,y,w]),M.useEffect(()=>{r&&(Array.isArray(u)||L||S.length>0||W.length!==0&&j(W))},[r,u,L,S,W]),!r)return null;const B=!v&&!!x;return o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-lg border border-border animate-breathing-border",children:o.jsxs("div",{className:"p-6",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:g}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"会话标题"}),o.jsx("input",{value:f,onChange:z=>c(z.target.value),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"New Chat",disabled:v})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择模型(必选)"}),o.jsxs("select",{value:x,onChange:z=>b(z.target.value),disabled:v,className:"w-full px-3 py-2 border border-input bg-background rounded-md text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"",disabled:!0,children:"请选择模型..."}),p.map(z=>o.jsxs("option",{value:z.id,children:[z.name," (",z.model_name,")"]},z.id))]}),p.length===0&&o.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"暂无可用模型,请先在右上角配置。"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 MCP(多选)"}),m.length===0?o.jsx("p",{className:"text-xs text-muted-foreground",children:"暂无 MCP 配置。"}):o.jsx("div",{className:"max-h-40 overflow-auto rounded-md border border-border bg-background",children:m.map(z=>{const O=Tr(z.enabled);return o.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 text-sm hover:bg-accent",children:[o.jsx("input",{type:"checkbox",checked:y.includes(z.id),onChange:()=>{T(!0),_(U=>Ta(U,z.id))},disabled:v}),o.jsxs("span",{className:"truncate",title:z.name,children:[z.name,O?null:o.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(未启用)"})]})]},z.id)})})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 Prompt(多选)"}),a.length===0?o.jsx("p",{className:"text-xs text-muted-foreground",children:"暂无可用 Prompt(系统上下文)。"}):o.jsx("div",{className:"max-h-40 overflow-auto rounded-md border border-border bg-background",children:(a||[]).map(z=>{const O=z.isActive??z.is_active??!1;return o.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 text-sm hover:bg-accent",children:[o.jsx("input",{type:"checkbox",checked:S.includes(z.id),onChange:()=>{C(!0),j(U=>Ta(U,z.id))},disabled:v}),o.jsxs("span",{className:"truncate",title:z.name,children:[z.name,O?o.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(当前激活)"}):null]})]},z.id)})})]})]}),o.jsxs("div",{className:"flex gap-3 mt-6",children:[o.jsx("button",{onClick:e,disabled:v,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"取消"}),o.jsx("button",{onClick:async()=>{if(B){I(!0);try{await t({title:f.trim()||i,modelId:x,mcpConfigIds:y,promptIds:S}),e()}finally{I(!1)}}},disabled:!B,className:"flex-1 px-4 py-2 text-sm rounded-md transition-colors bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed",children:h})]})]})})})},wg=r=>{const e=new Date;let t;if(!r)return"时间未知";if(typeof r=="string"){const s=r.replace(" ","T")+"Z";t=new Date(s),isNaN(t.getTime())&&(t=new Date(r))}else t=r;if(!t||isNaN(t.getTime()))return"时间未知";const n=Math.floor((e.getTime()-t.getTime())/1e3);return n<60?"刚刚":n<3600?`${Math.floor(n/60)}分钟前`:n<86400?`${Math.floor(n/3600)}小时前`:n<2592e3?`${Math.floor(n/86400)}天前`:t.toLocaleDateString("zh-CN")},bo=({isOpen:r=!0,onClose:e,store:t,embedded:n=!1})=>{let s=null;try{s=tt()}catch{}const a=t?t():s;if(!a)throw new Error("SessionList must be used within a ChatStoreProvider or receive a store prop");const{sessions:i,currentSession:l,createSession:d,selectSession:u,deleteSession:g,updateSessionConfig:h,getSessionMcpConfigIds:p,aiModelConfigs:w,loadAiModelConfigs:m,mcpConfigs:f,loadMcpConfigs:c,systemContexts:x,loadSystemContexts:b,selectedModelId:y}=a,_=n?"relative h-full bg-card shadow-lg breathing-border":"fixed left-0 top-0 h-full bg-card z-40 shadow-xl breathing-border",S="transition-all duration-300 ease-in-out",[j,v]=M.useState(!1),[I,P]=M.useState(!1),[T,L]=M.useState(null),[C,W]=M.useState([]),[B,z]=M.useState(!r),{dialogState:O,showConfirmDialog:U,handleConfirm:J,handleCancel:$}=br(),H=()=>{z(!B)},F=async()=>{try{v(!0),m==null||m(),c==null||c(),b==null||b(),B&&z(!1)}catch(R){console.error("Failed to create session:",R)}},k=async R=>{try{await u(R)}catch(q){console.error("Failed to select session:",q)}},A=async R=>{const q=i.find(Q=>Q.id===R);U({title:"删除确认",message:`确定要删除会话 "${(q==null?void 0:q.title)||"Untitled"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",onConfirm:async()=>{try{await g(R)}catch(Q){console.error("Failed to delete session:",Q)}}})},N=R=>{const q=R==null?void 0:R.metadata;try{return typeof q=="string"?q?JSON.parse(q):{}:q&&typeof q=="object"?q:{}}catch{return{}}},D=async R=>{try{m==null||m(),c==null||c(),b==null||b();const q=await(p==null?void 0:p(R.id));W(Array.isArray(q)?q:[]),L(R),P(!0),B&&z(!1)}catch(q){console.error("Failed to open session editor:",q)}};return o.jsx("div",{className:`${_} ${S} ${B?"w-32":"w-80 sm:w-96"}`,children:o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:`flex ${B?"flex-col items-center justify-center p-2":"items-center justify-between p-4"} border-b border-border transition-all duration-300`,children:[!B&&o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"会话列表"}),o.jsxs("div",{className:`flex ${B?"flex-col space-y-2 items-center":"items-center space-x-2"}`,children:[o.jsx("button",{onClick:F,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"新建会话",children:o.jsx(ac,{className:"w-5 h-5"})}),o.jsx("button",{onClick:H,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:B?"展开":"收起",children:B?o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}):o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),e&&!B&&!n&&o.jsx("button",{onClick:e,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground",children:[o.jsx(cc,{className:"w-12 h-12 mb-4 opacity-50"}),!B&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm",children:"还没有会话"}),o.jsx("button",{onClick:F,className:"mt-2 px-4 py-2 text-sm bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors",children:"创建第一个会话"})]})]}):o.jsx("div",{className:"p-2 space-y-1",children:i.map(R=>o.jsxs("div",{className:`group relative flex items-center p-3 rounded-lg cursor-pointer transition-colors ${(l==null?void 0:l.id)===R.id?"bg-accent border border-border":"hover:bg-accent/50"}`,onClick:()=>k(R.id),children:[o.jsx("div",{className:"flex-1 min-w-0",children:o.jsxs(o.Fragment,{children:[o.jsx("h3",{className:`text-sm font-medium text-foreground truncate ${B?"text-center w-full":""}`,title:R.title,children:B&&R.title.length>4?R.title.slice(0,4)+"...":R.title}),!B&&o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:wg(R.updatedAt)})]})}),!B&&o.jsxs("div",{className:"relative flex items-center gap-1",children:[o.jsx("button",{className:"p-1 text-muted-foreground hover:text-foreground opacity-0 group-hover:opacity-100 transition-opacity",onClick:q=>{q.stopPropagation(),D(R)},title:"编辑",children:o.jsx(Ss,{className:"w-4 h-4"})}),o.jsx("button",{className:"p-1 text-muted-foreground hover:text-foreground opacity-0 group-hover:opacity-100 transition-opacity",onClick:q=>{q.stopPropagation();const Q=q.currentTarget.nextElementSibling;Q&&Q.classList.toggle("hidden")},children:o.jsx(ic,{className:"w-4 h-4"})}),o.jsx("div",{className:"hidden absolute right-0 z-10 mt-1 w-32 bg-popover border border-border rounded-md shadow-lg",children:o.jsxs("div",{className:"py-1",children:[o.jsxs("button",{onClick:q=>{q.stopPropagation(),D(R);const Q=q.currentTarget.closest(".absolute");Q&&Q.classList.add("hidden")},className:"flex items-center w-full px-3 py-2 text-sm text-popover-foreground hover:bg-accent",children:[o.jsx(Ss,{className:"w-4 h-4 mr-2"}),"编辑"]}),o.jsxs("button",{onClick:q=>{q.stopPropagation(),A(R.id);const Q=q.currentTarget.closest(".absolute");Q&&Q.classList.add("hidden")},className:"flex items-center w-full px-3 py-2 text-sm text-destructive hover:bg-destructive/10",children:[o.jsx(lc,{className:"w-4 h-4 mr-2"}),"删除"]})]})})]})]},R.id))})}),o.jsx(xr,{isOpen:O.isOpen,title:O.title,message:O.message,confirmText:O.confirmText,cancelText:O.cancelText,type:O.type,verificationText:O.verificationText,verificationLabel:O.verificationLabel,verificationPlaceholder:O.verificationPlaceholder,verificationHint:O.verificationHint,onConfirm:J,onCancel:$}),o.jsx(Oa,{isOpen:j,onClose:()=>v(!1),availableModels:w||[],availableMcpConfigs:f||[],availablePrompts:x||[],defaultModelId:y,dialogTitle:"新建会话",confirmText:"创建",onCreate:async R=>{try{await d({title:R.title,modelId:R.modelId,mcpConfigIds:R.mcpConfigIds,promptIds:R.promptIds})}catch(q){throw console.error("Failed to create session:",q),q}}}),o.jsx(Oa,{isOpen:I,onClose:()=>{P(!1),L(null),W([])},availableModels:w||[],availableMcpConfigs:f||[],availablePrompts:x||[],defaultTitle:(T==null?void 0:T.title)||"New Chat",defaultModelId:(()=>{const R=N(T);return R.ai_model_config_id||R.model_id||R.modelId||y||null})(),initialMcpConfigIds:C,initialPromptIds:(()=>{const R=N(T),q=R.prompt_ids||R.promptIds||[];return Array.isArray(q)?q.map(Q=>String(Q)).filter(Boolean):[]})(),dialogTitle:"编辑会话",confirmText:"保存",onCreate:async R=>{if(T)try{await(h==null?void 0:h(T.id,{title:R.title,modelId:R.modelId,mcpConfigIds:R.mcpConfigIds,promptIds:R.promptIds}))}catch(q){throw console.error("Failed to update session config:",q),q}}})]})})},dc=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Ra=r=>r==="system"?dc():r,Gn=r=>{if(typeof window>"u")return;const e=window.document.documentElement;e.classList.remove("light","dark"),e.classList.add(r);const t=document.querySelector('meta[name="theme-color"]');t&&t.setAttribute("content",r==="dark"?"#0f172a":"#ffffff")},$a=()=>typeof window>"u"?"system":localStorage.getItem("theme")||"system",vg=r=>{typeof window>"u"||localStorage.setItem("theme",r)},uc=()=>{const[r,e]=M.useState(()=>$a()),[t,n]=M.useState(()=>Ra($a())),s=i=>{e(i),vg(i);const l=Ra(i);n(l),Gn(l)},a=()=>{let i;switch(r){case"light":i="dark";break;case"dark":i="system";break;case"system":i="light";break;default:i="system"}s(i)};return M.useEffect(()=>{if(r!=="system")return;const i=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const d=dc();n(d),Gn(d)};return i.addEventListener("change",l),()=>i.removeEventListener("change",l)},[r]),M.useEffect(()=>{Gn(t)},[t]),{theme:r,actualTheme:t,setTheme:s,toggleTheme:a}},yo=({className:r=""})=>{const{theme:e,toggleTheme:t}=uc(),n=()=>{switch(e){case"light":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})});case"dark":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})});case"system":return o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})});default:return null}},s=()=>{switch(e){case"light":return"Light mode";case"dark":return"Dark mode";case"system":return"System theme";default:return"Toggle theme"}};return o.jsx("button",{onClick:t,className:`p-2 hover:bg-muted rounded-lg transition-colors ${r}`,title:s(),"aria-label":s(),children:n()})},_g={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Sg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})}),La=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Cg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),jg=({open:r,config:e,onClose:t})=>{const[n,s]=M.useState([]),[a,i]=M.useState(!1),[l,d]=M.useState(null),[u,g]=M.useState(null),[h,p]=M.useState(!1),[w,m]=M.useState({name:"",envJson:"",enabled:!1}),[f,c]=M.useState(null),[x,b]=M.useState({});if(M.useEffect(()=>{(async()=>{if(!(!r||!(e!=null&&e.id))){i(!0),d(null);try{const _=await te.getMcpConfigProfiles(e.id);s(Array.isArray(_)?_:[])}catch(_){d((_==null?void 0:_.message)||"获取配置档案失败")}finally{i(!1)}}})()},[r,e==null?void 0:e.id]),!r)return null;try{const y={id:e==null?void 0:e.id,name:e==null?void 0:e.name,type:e==null?void 0:e.type,command:e==null?void 0:e.command,cwd:e==null?void 0:e.cwd,args:e==null?void 0:e.args};typeof window<"u"}catch{}return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-3xl max-h-[85vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Sg,{}),o.jsxs("h3",{className:"text-lg font-semibold text-foreground",children:["配置档案 - ",e==null?void 0:e.name]})]}),o.jsx("button",{onClick:()=>t(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(La,{})})]}),o.jsxs("div",{className:"p-4 overflow-y-auto overflow-x-hidden",style:{maxHeight:"calc(85vh - 100px)"},children:[e&&o.jsxs("div",{className:"mb-4 p-3 rounded-md border border-border bg-muted/40",children:[o.jsx("div",{className:"text-sm font-medium mb-2 text-foreground",children:"基本信息"}),o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs text-muted-foreground",children:[o.jsxs("div",{children:["协议类型:",o.jsx("span",{className:"ml-1 text-foreground",children:e.type==="http"?"HTTP":"Stdio"})]}),o.jsxs("div",{children:[e.type==="http"?"URL:":"命令:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:e.command})]}),e.type==="stdio"&&e.cwd&&o.jsxs("div",{children:["cwd:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:String(e.cwd)})]}),e.type==="stdio"&&o.jsxs("div",{className:"sm:col-span-2",children:["args:",o.jsx("span",{className:"ml-1 text-foreground break-all",children:(()=>{const y=e.args;if(!y)return"—";if(Array.isArray(y))return y.map(_=>String(_)).join(", ");if(typeof y=="string"){try{const _=JSON.parse(y);if(Array.isArray(_))return _.map(S=>String(S)).join(", ")}catch{}return y}return String(y)})()})]})]})]}),o.jsxs("div",{className:"flex items-center justify-between mb-3",children:[o.jsx("span",{className:"text-sm text-muted-foreground",children:"已保存的配置档案"}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{if(e!=null&&e.id){i(!0);try{const y=await te.getMcpConfigProfiles(e.id);s(Array.isArray(y)?y:[])}finally{i(!1)}}},children:"刷新列表"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{if(!(e!=null&&e.id))return;let y;try{const _=await te.getMcpConfigResource(e.id),S=_&&_.config||{};S&&typeof S=="object"&&(y=S)}catch{}m({name:`配置_${new Date().toLocaleString("zh-CN")}`,envJson:"",enabled:!1}),b(y||{}),g(null),p(!0)},children:"新增配置档案"})]})]}),a?o.jsx("div",{className:"text-xs text-muted-foreground",children:"加载中..."}):l?o.jsx("div",{className:"text-xs text-destructive",children:l}):n.length===0?o.jsx("div",{className:"text-xs text-muted-foreground",children:"暂无配置档案,点击右上角“新增配置档案”。"}):o.jsx("div",{className:"space-y-2",children:n.map(y=>o.jsx("div",{className:"px-2 py-2 border border-border rounded-md",children:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx("div",{className:"text-sm text-foreground font-medium truncate",title:y.name,children:y.name}),y.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{if(e!=null&&e.id)try{await te.activateMcpConfigProfile(e.id,y.id);const _=await te.getMcpConfigProfiles(e.id);s(Array.isArray(_)?_:[])}catch{}},children:"激活"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{g(y.id),m({name:y.name||"",envJson:(()=>{try{return JSON.stringify(y.env||{},null,2)}catch{return""}})(),enabled:!!y.enabled});const _=y.env||{},S={};Object.keys(_||{}).forEach(j=>{const v=_[j];if(typeof v=="string"){const I=v.trim();try{S[j]=JSON.parse(I)}catch{I.includes(",")?S[j]=I.split(",").map(P=>P.trim()).filter(Boolean):S[j]=I}}else S[j]=v}),b(S),p(!0)},children:"编辑"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-destructive text-destructive-foreground rounded-md hover:bg-destructive/80",onClick:async()=>{if(!(!(e!=null&&e.id)||!window.confirm(`确定删除配置档案 “${y.name}” 吗?`)))try{await te.deleteMcpConfigProfile(e.id,y.id);const S=await te.getMcpConfigProfiles(e.id);s(Array.isArray(S)?S:[])}catch(S){console.error("删除配置档案失败:",S)}},children:"删除"})]})]})},y.id))})]})]}),h&&o.jsxs("div",{className:"modal-container z-[100]",children:[o.jsx("div",{className:"fixed inset-0 bg-black/40 backdrop-blur-sm",onClick:()=>{p(!1),c(null)}}),o.jsx("div",{className:"fixed inset-0 flex items-center justify-center p-4",children:o.jsxs("div",{className:"modal-content w-full max-w-2xl transform overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Cg,{}),o.jsx("h3",{className:"text-base font-semibold text-foreground",children:u?"编辑配置档案":"新增配置档案"})]}),o.jsx("button",{onClick:()=>{p(!1),c(null)},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(La,{})})]}),o.jsxs("div",{className:"p-4",children:[f&&o.jsx("div",{className:"mb-2 text-xs text-destructive",children:f}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"名称"}),o.jsx("input",{type:"text",value:w.name,onChange:y=>m({...w,name:y.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md"})]}),o.jsx("div",{children:x&&Object.keys(x).length>0&&o.jsxs("div",{className:"mb-3",children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"动态参数"}),o.jsx("div",{className:"grid grid-cols-1 gap-3",children:Object.keys(x).map(y=>{const _=x[y],S=typeof _,j=Array.isArray(_);return o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs text-muted-foreground mb-1",children:y}),S==="boolean"?o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",checked:!!_,onChange:v=>b({...x,[y]:v.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("span",{className:"ml-2 text-xs",children:String(_)})]}):j?o.jsx("input",{type:"text",value:_.join(", "),onChange:v=>b({...x,[y]:v.target.value.split(",").map(I=>I.trim()).filter(Boolean)}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"}):S==="object"&&_!==null?o.jsx("textarea",{value:(()=>{try{return JSON.stringify(_,null,2)}catch{return String(_)}})(),onChange:v=>{try{const I=JSON.parse(v.target.value);b({...x,[y]:I})}catch{b({...x,[y]:v.target.value})}},rows:4,className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md font-mono text-xs"}):o.jsx("input",{type:S==="number"?"number":"text",value:_??"",onChange:v=>b({...x,[y]:S==="number"?Number(v.target.value):v.target.value}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"})]},y)})})]})})]}),o.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:()=>{p(!1),c(null)},children:"取消"}),o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{c(null);try{if(!(e!=null&&e.id))throw new Error("缺少配置ID");let y=null;if(x&&Object.keys(x).length>0)y=x;else{const j=(w.envJson||"").trim();if(j)try{const v=JSON.parse(j);v&&typeof v=="object"&&(y=v)}catch{throw new Error("env JSON 格式错误")}}let S=null;if(y&&typeof y=="object"){S={};for(const j of Object.keys(y)){const v=y[j];Array.isArray(v)?S[j]=v.join(","):typeof v=="boolean"||typeof v=="number"?S[j]=String(v):v==null?S[j]="":typeof v=="object"?S[j]=JSON.stringify(v):S[j]=String(v)}}if(u)if(await te.updateMcpConfigProfile(e.id,u,{name:w.name,env:S,enabled:w.enabled})){const v=await te.getMcpConfigProfiles(e.id);s(Array.isArray(v)?v:[]),p(!1),g(null)}else throw new Error("更新失败");else{const j=await te.createMcpConfigProfile(e.id,{name:w.name,env:S,enabled:w.enabled});if(j&&(j.id||j.success)){const v=await te.getMcpConfigProfiles(e.id);s(Array.isArray(v)?v:[]),p(!1)}else throw new Error("创建失败")}}catch(y){c((y==null?void 0:y.message)||"保存失败")}},children:"保存"})]})]})]})})]})]})},Ag={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Da=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})}),kg=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Ng=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Mg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),Eg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),wo=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{mcpConfigs:n,updateMcpConfig:s,deleteMcpConfig:a,loadMcpConfigs:i}=t,{dialogState:l,showConfirmDialog:d,handleConfirm:u,handleCancel:g}=br(),[h,p]=M.useState(!1),[w,m]=M.useState(null),[f,c]=M.useState({name:"",command:"",type:"stdio",enabled:!0,cwd:"",argsInput:""}),[x,b]=M.useState(!1),[y,_]=M.useState(null),[S,j]=M.useState({}),[v,I]=M.useState([]),[P,T]=M.useState(""),[L,C]=M.useState(!1),[W,B]=M.useState(null);M.useEffect(()=>{const k="__mcpManagerInitAt__",A=window[k]||0,N=Date.now();typeof A=="number"&&N-A<1e3||(window[k]=N,i())},[i]);const z=async k=>{B(k),C(!0);try{const A=await te.getMcpConfigProfiles(k.id);I(Array.isArray(A)?A:[])}catch{console.error("加载配置档案失败")}finally{}},O=()=>{c({name:"",command:"",type:"stdio",enabled:!0,cwd:"",argsInput:""}),m(null),p(!1),j({}),I([]),T("")},U=async k=>{var N,D;if(k.preventDefault(),!f.name.trim()||!f.command.trim())return;const A={name:f.name.trim(),command:f.command.trim(),type:f.type,enabled:f.enabled,cwd:(N=f.cwd)!=null&&N.trim()?f.cwd.trim():void 0,args:(D=f.argsInput)!=null&&D.trim()?f.argsInput.split(",").map(R=>R.trim()).filter(Boolean):void 0,createdAt:new Date,updatedAt:new Date};await s(A),O()},J=async k=>{var N,D;if(k.preventDefault(),!w||!f.name.trim()||!f.command.trim())return;const A={...w,name:f.name.trim(),command:f.command.trim(),type:f.type,enabled:f.enabled,cwd:(N=f.cwd)!=null&&N.trim()?f.cwd.trim():void 0,args:(D=f.argsInput)!=null&&D.trim()?f.argsInput.split(",").map(R=>R.trim()).filter(Boolean):void 0,updatedAt:new Date};await s(A),O()},$=k=>{m(k);let A="";const N=k.args;if(Array.isArray(N))A=N.map(D=>String(D)).join(", ");else if(typeof N=="string"&&N.trim()!=="")try{const D=JSON.parse(N);Array.isArray(D)?A=D.map(R=>String(R)).join(", "):A=N}catch{A=N}c({name:k.name,command:k.command,type:k.type||"stdio",enabled:k.enabled,cwd:k.cwd||"",argsInput:A}),p(!0),j({}),_(null),b(!1)},H=async k=>{var D;const A=n.find(R=>R.id===k),N=((D=A==null?void 0:A.name)==null?void 0:D.trim())||"删除";d({title:"删除 MCP 服务器",message:`确定要删除服务器 "${(A==null?void 0:A.name)||"Unknown"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:N,verificationLabel:"请键入服务器名称以确认删除",verificationPlaceholder:`输入 "${N}"`,verificationHint:"删除后无法恢复,请再次确认操作。",onConfirm:()=>a(k)})},F=async k=>{const A={...k,enabled:!k.enabled,updatedAt:new Date};await s(A)};return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:r}),o.jsxs("div",{className:"fixed right-0 top-0 h-full w-[520px] sm:w-[560px] bg-card z-50 shadow-xl breathing-border flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Da,{}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"MCP 服务器管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx(kg,{})})]}),o.jsxs("div",{className:"p-4 flex-1 overflow-y-auto overflow-x-hidden",children:[!h&&o.jsxs("button",{onClick:()=>p(!0),className:"w-full mb-6 p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Ng,{}),o.jsx("span",{children:"添加 MCP 服务器"})]}),h&&o.jsxs("form",{onSubmit:w?J:U,className:"mb-6 p-4 bg-muted rounded-lg",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:w?"编辑服务器":"添加新服务器"}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称"}),o.jsx("input",{type:"text",value:f.name,onChange:k=>c({...f,name:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: File System",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"协议类型"}),o.jsxs("select",{value:f.type,onChange:k=>c({...f,type:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"stdio",children:"Stdio (标准输入输出)"}),o.jsx("option",{value:"http",children:"HTTP (网络协议)"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:f.type==="http"?"URL地址":"命令"}),o.jsx("input",{type:"text",value:f.command,onChange:k=>c({...f,command:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:f.type==="http"?"https://api.example.com/mcp":"npx @modelcontextprotocol/server-filesystem /path/to/allowed/files",required:!0}),f.type==="stdio"&&o.jsx(o.Fragment,{})]}),f.type==="stdio"&&o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"可执行地址(cwd)"}),o.jsx("input",{type:"text",value:f.cwd,onChange:k=>c({...f,cwd:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"/absolute/path/to/executable"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"为空则使用当前页面的工作目录"}),o.jsx("div",{className:"mt-2 flex gap-2",children:o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{var k,A;if(f.command.trim()){b(!0),_(null);try{const N=await te.getMcpConfigResourceByCommand({type:f.type,command:f.command.trim(),args:(k=f.argsInput)!=null&&k.trim()?f.argsInput.split(",").map(D=>D.trim()).filter(Boolean):void 0,env:void 0,cwd:(A=f.cwd)!=null&&A.trim()?f.cwd.trim():void 0,alias:null});if(N&&N.success&&N.config){const D=N.config;if(j(D),w!=null&&w.id)try{const R=await te.getMcpConfigProfiles(w.id);I(Array.isArray(R)?R:[])}catch{}}else _("无法获取服务器可配置参数")}catch(N){_((N==null?void 0:N.message)||"获取配置失败")}finally{b(!1)}}},children:x?"获取中…":"获取配置"})})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"启动参数(args,逗号分隔)"}),o.jsx("input",{type:"text",value:f.argsInput,onChange:k=>c({...f,argsInput:k.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"--flag, value, --opt"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"将自动转换为参数数组"})]})]}),o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",id:"enabled",checked:f.enabled,onChange:k=>c({...f,enabled:k.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("label",{htmlFor:"enabled",className:"ml-2 block text-sm text-foreground",children:"启用此服务器"})]}),f.type==="stdio"&&Object.keys(S).length>0&&o.jsxs("div",{className:"mt-4 p-3 border border-border rounded-md bg-card",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"服务器可配置参数(动态解析)"}),x&&o.jsx("span",{className:"text-xs text-muted-foreground",children:"解析中…"})]}),y&&o.jsx("p",{className:"text-xs text-red-600 mb-2",children:y}),o.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[Object.keys(S).map(k=>{const A=S[k],N=typeof A,D=Array.isArray(A);return o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs text-muted-foreground mb-1",children:k}),N==="boolean"?o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",checked:!!A,onChange:R=>j({...S,[k]:R.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("span",{className:"ml-2 text-xs",children:String(A)})]}):D?o.jsx("input",{type:"text",value:A.join(", "),onChange:R=>j({...S,[k]:R.target.value.split(",").map(q=>q.trim()).filter(Boolean)}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"}):o.jsx("input",{type:N==="number"?"number":"text",value:A??"",onChange:R=>j({...S,[k]:N==="number"?Number(R.target.value):R.target.value}),className:"w-full px-2 py-1 border border-input bg-background text-foreground rounded-md"})]},k)}),(w==null?void 0:w.id)&&o.jsxs("div",{className:"mt-2 p-2 border border-dashed rounded-md",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("input",{type:"text",value:P,onChange:k=>T(k.target.value),className:"flex-1 px-2 py-1 border border-input bg-background text-foreground rounded-md",placeholder:"配置档案名称(例如:开发环境)"}),o.jsx("button",{type:"button",className:"px-3 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:async()=>{var k,A;if(w!=null&&w.id)try{await te.createMcpConfigProfile(w.id,{name:P||`配置-${new Date().toLocaleString()}`,env:Object.keys(S).reduce((D,R)=>{const q=S[R];return D[R]=typeof q=="string"?q:String(q),D},{}),args:(k=f.argsInput)!=null&&k.trim()?f.argsInput.split(",").map(D=>D.trim()).filter(Boolean):void 0,cwd:(A=f.cwd)!=null&&A.trim()?f.cwd.trim():void 0,enabled:!1});const N=await te.getMcpConfigProfiles(w.id);I(Array.isArray(N)?N:[]),T("")}catch(N){console.error("保存配置档案失败:",N),_("保存配置档案失败")}},children:"保存为配置档案"})]}),v.length>0&&o.jsxs("div",{className:"mt-3 space-y-2",children:[o.jsx("div",{className:"text-xs text-muted-foreground",children:"已有配置档案:"}),v.map(k=>{const A=Array.isArray(k.args)?k.args.join(", "):"",N=k.env?Object.keys(k.env):[];return o.jsxs("div",{className:"px-2 py-1 border border-border rounded-md",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:"text-xs text-foreground font-medium",children:k.name}),k.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{await te.activateMcpConfigProfile(w.id,k.id);const D=await te.getMcpConfigProfiles(w.id);I(Array.isArray(D)?D:[])}catch{}},children:"激活"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{c(D=>({...D,argsInput:Array.isArray(k.args)?k.args.join(", "):D.argsInput,cwd:k.cwd??D.cwd})),j(k.env||{})},children:"应用到表单"})]})]}),o.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 text-xs text-foreground",children:[o.jsxs("div",{className:"truncate",title:k.cwd||"未设置",children:[o.jsx("span",{className:"text-muted-foreground",children:"cwd:"}),k.cwd||"未设置"]}),o.jsxs("div",{className:"truncate",title:A||"未设置",children:[o.jsx("span",{className:"text-muted-foreground",children:"args:"}),A||"未设置"]}),o.jsxs("div",{children:[o.jsxs("span",{className:"text-muted-foreground",children:["env(",N.length,"):"]}),N.length===0?"未设置":o.jsx("div",{className:"mt-1 grid grid-cols-1 gap-1",children:N.map(D=>o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-muted-foreground shrink-0",children:D}),o.jsx("span",{className:"text-foreground truncate",title:String(k.env[D]),children:String(k.env[D])})]},D))})]})]})]},k.id)})]})]})]})]})]}),(w==null?void 0:w.id)&&!h&&o.jsxs("div",{className:"mt-4 p-3 border border-border rounded-md bg-card",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"配置档案列表"}),o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{const k=await te.getMcpConfigProfiles(w.id);I(Array.isArray(k)?k:[])}catch{}},children:"刷新"})]}),v.length===0?o.jsx("div",{className:"text-xs text-muted-foreground",children:"暂无配置档案"}):o.jsx("div",{className:"space-y-2",children:v.map(k=>{const A=Array.isArray(k.args)?k.args.join(", "):"",N=k.env?Object.keys(k.env):[];return o.jsxs("div",{className:"px-2 py-1 border border-border rounded-md",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:"text-xs text-foreground font-medium",children:k.name}),k.enabled&&o.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200",children:"已启用"})]}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx("button",{type:"button",className:"px-2 py-1 text-xs bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80",onClick:async()=>{try{await te.activateMcpConfigProfile(w.id,k.id);const D=await te.getMcpConfigProfiles(w.id);I(Array.isArray(D)?D:[])}catch{}},children:"激活"})})]}),o.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 text-xs text-foreground",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-muted-foreground",children:"cwd:"}),k.cwd||"未设置"]}),o.jsxs("div",{children:[o.jsx("span",{className:"text-muted-foreground",children:"args:"}),A||"未设置"]}),o.jsxs("div",{children:[o.jsxs("span",{className:"text-muted-foreground",children:["env(",N.length,"):"]}),N.length===0?"未设置":o.jsx("div",{className:"mt-1 grid grid-cols-1 gap-1",children:N.map(D=>o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground",children:D}),o.jsx("span",{className:"text-foreground",children:String(k.env[D])})]},D))})]})]})]},k.id)})})]}),o.jsxs("div",{className:"flex space-x-3 mt-6",children:[o.jsx("button",{type:"submit",className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500",children:w?"更新":"添加"}),o.jsx("button",{type:"button",onClick:O,className:"px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80 focus:outline-none focus:ring-2 focus:ring-ring",children:"取消"})]})]}),o.jsx("div",{className:"space-y-3",children:n.length===0?o.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[o.jsx(Da,{}),o.jsx("p",{className:"mt-2",children:"暂无 MCP 服务器配置"}),o.jsx("p",{className:"text-sm",children:"点击上方按钮添加第一个服务器"})]}):n.map(k=>o.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 bg-card border border-border rounded-lg",children:[o.jsxs("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[o.jsx("div",{className:`w-3 h-3 rounded-full ${k.enabled?"bg-green-500":"bg-gray-400"}`}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center space-x-2 min-w-0",children:[o.jsx("h4",{className:"font-medium text-foreground truncate",title:k.name,children:k.name}),o.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${k.type==="http"?"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200":"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200"}`,children:k.type==="http"?"HTTP":"Stdio"})]}),o.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground truncate break-all font-mono",title:k.command,children:k.command}),typeof window<"u"&&Ag&&!1,k.type==="stdio"&&o.jsxs("div",{className:"mt-1 space-y-0.5 min-w-0",children:[k.cwd&&o.jsxs("div",{className:"text-xs text-muted-foreground truncate",title:String(k.cwd),children:["cwd: ",o.jsx("span",{className:"text-foreground",children:String(k.cwd)})]}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",title:(()=>{const A=k.args;let N=null,D=!1;if(Array.isArray(A))N=A.map(q=>String(q));else if(typeof A=="string"&&A.trim()!=="")try{const q=JSON.parse(A);Array.isArray(q)&&(N=q.map(Q=>String(Q)),D=!0)}catch{}const R=Array.isArray(N)&&N.length>0?N.join(", "):typeof A=="string"&&!D?A:"—";return String(R)})(),children:(()=>{const A=k.args;let N=null,D=!1;if(Array.isArray(A))N=A.map(q=>String(q));else if(typeof A=="string"&&A.trim()!=="")try{const q=JSON.parse(A);Array.isArray(q)&&(N=q.map(Q=>String(Q)),D=!0)}catch{}const R=Array.isArray(N)&&N.length>0?N.join(", "):typeof A=="string"&&!D?A:"—";return o.jsxs("span",{children:["参数(args):",o.jsx("span",{className:"text-foreground",children:R})]})})()})]})]})]}),o.jsxs("div",{className:"flex items-center space-x-2 shrink-0",children:[o.jsx("button",{onClick:()=>F(k),className:`px-3 py-1 text-xs rounded-full ${k.enabled?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-secondary text-secondary-foreground"}`,children:k.enabled?"已启用":"已禁用"}),o.jsx("button",{onClick:()=>z(k),className:"p-2 text-muted-foreground hover:text-indigo-600 transition-colors",title:"查看配置档案",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 7.5l7.5 3 7.5-3M3 7.5V18l7.5 3 7.5-3V7.5M10.5 10.5V21"})})}),o.jsx("button",{onClick:()=>$(k),className:"p-2 text-muted-foreground hover:text-blue-600 transition-colors",title:"编辑",children:o.jsx(Eg,{})}),o.jsx("button",{onClick:()=>H(k.id),className:"p-2 text-muted-foreground hover:text-red-600 transition-colors",title:"删除",children:o.jsx(Mg,{})})]})]},k.id))})]})]}),o.jsx(jg,{open:L,config:W,onClose:()=>{C(!1),B(null)}}),o.jsx(xr,{isOpen:l.isOpen,title:l.title,message:l.message,confirmText:l.confirmText,cancelText:l.cancelText,type:l.type,verificationText:l.verificationText,verificationLabel:l.verificationLabel,verificationPlaceholder:l.verificationPlaceholder,verificationHint:l.verificationHint,onConfirm:u,onCancel:g})]})},Fa=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})}),Ig=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Pg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Tg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),Og=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),vo=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{aiModelConfigs:n,loadAiModelConfigs:s,updateAiModelConfig:a,deleteAiModelConfig:i}=t,[l,d]=M.useState(!1),[u,g]=M.useState(null),[h,p]=M.useState({name:"",base_url:"",api_key:"",model_name:"",enabled:!0}),{dialogState:w,showConfirmDialog:m,handleConfirm:f,handleCancel:c}=br();M.useEffect(()=>{const v="__aiModelManagerInitAt__",I=window[v]||0,P=Date.now();typeof I=="number"&&P-I<1e3||(window[v]=P,s())},[s]);const x=()=>{p({name:"",base_url:"",api_key:"",model_name:"",enabled:!0}),g(null),d(!1)},b=async v=>{if(v.preventDefault(),!h.name.trim()||!h.base_url.trim()||!h.api_key.trim()||!h.model_name.trim())return;const I={id:Math.random().toString(36).substr(2,9),name:h.name.trim(),base_url:h.base_url.trim(),api_key:h.api_key.trim(),model_name:h.model_name.trim(),enabled:h.enabled,createdAt:new Date,updatedAt:new Date};await a(I),x()},y=async v=>{if(v.preventDefault(),!u||!h.name.trim()||!h.base_url.trim()||!h.api_key.trim()||!h.model_name.trim())return;const I={...u,name:h.name.trim(),base_url:h.base_url.trim(),api_key:h.api_key.trim(),model_name:h.model_name.trim(),enabled:h.enabled,updatedAt:new Date};await a(I),x()},_=v=>{g(v),p({name:v.name,base_url:v.base_url,api_key:v.api_key,model_name:v.model_name,enabled:v.enabled}),d(!0)},S=async v=>{var T;const I=n.find(L=>L.id===v),P=((T=I==null?void 0:I.name)==null?void 0:T.trim())||"删除";m({title:"删除确认",message:`确定要删除AI模型配置 "${(I==null?void 0:I.name)||"Unknown"}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:P,verificationLabel:"请输入下方关键字确认删除",verificationPlaceholder:`输入 "${P}"`,verificationHint:"删除后无法恢复,请谨慎操作。",onConfirm:async()=>{await i(v)}})},j=async v=>{const I={...v,enabled:!v.enabled,updatedAt:new Date};await a(I)};return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-2xl max-h-[80vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Fa,{}),o.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"AI 模型管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Ig,{})})]}),o.jsxs("div",{className:"p-6 overflow-y-auto overflow-x-hidden max-h-[calc(80vh-120px)]",children:[!l&&o.jsxs("button",{onClick:()=>d(!0),className:"w-full mb-6 p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Pg,{}),o.jsx("span",{children:"添加 AI 模型"})]}),l&&o.jsxs("form",{onSubmit:u?y:b,className:"mb-6 p-4 bg-muted rounded-lg",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground mb-4",children:u?"编辑 AI 模型":"添加 AI 模型"}),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"配置名称"}),o.jsx("input",{type:"text",value:h.name,onChange:v=>p({...h,name:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: OpenAI GPT-4",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"Base URL"}),o.jsx("input",{type:"url",value:h.base_url,onChange:v=>p({...h,base_url:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: https://api.openai.com/v1",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"API Key"}),o.jsx("input",{type:"password",value:h.api_key,onChange:v=>p({...h,api_key:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"输入API密钥",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"模型名称"}),o.jsx("input",{type:"text",value:h.model_name,onChange:v=>p({...h,model_name:v.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如: gpt-4",required:!0})]}),o.jsxs("div",{className:"flex items-center",children:[o.jsx("input",{type:"checkbox",id:"enabled",checked:h.enabled,onChange:v=>p({...h,enabled:v.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),o.jsx("label",{htmlFor:"enabled",className:"ml-2 block text-sm text-foreground",children:"启用此模型"})]})]}),o.jsxs("div",{className:"flex space-x-3 mt-6",children:[o.jsx("button",{type:"submit",className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500",children:u?"更新":"添加"}),o.jsx("button",{type:"button",onClick:x,className:"px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/80 focus:outline-none focus:ring-2 focus:ring-ring",children:"取消"})]})]}),o.jsx("div",{className:"space-y-3",children:n.length===0?o.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[o.jsx(Fa,{}),o.jsx("p",{className:"mt-2",children:"暂无 AI 模型配置"}),o.jsx("p",{className:"text-sm",children:"点击上方按钮添加第一个模型"})]}):n.map(v=>o.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 bg-card border border-border rounded-lg hover:shadow-md transition-shadow",children:[o.jsxs("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[o.jsx("div",{className:`w-3 h-3 rounded-full ${v.enabled?"bg-green-500":"bg-gray-400"}`}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("h4",{className:"font-medium text-foreground truncate",title:v.name,children:v.name}),o.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground truncate",title:`${v.base_url} - ${v.model_name}`,children:[v.base_url," - ",v.model_name]})]})]}),o.jsxs("div",{className:"flex items-center space-x-2 shrink-0",children:[o.jsx("button",{onClick:()=>j(v),className:`px-3 py-1 text-xs rounded-full transition-colors ${v.enabled?"bg-green-100 text-green-800 hover:bg-green-200 dark:bg-green-900 dark:text-green-200":"bg-secondary text-secondary-foreground hover:bg-secondary/80"}`,children:v.enabled?"已启用":"已禁用"}),o.jsx("button",{onClick:()=>_(v),className:"p-2 text-muted-foreground hover:text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900 rounded transition-colors",title:"编辑",children:o.jsx(Tg,{})}),o.jsx("button",{onClick:()=>S(v.id),className:"p-2 text-muted-foreground hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded transition-colors",title:"删除",children:o.jsx(Og,{})})]})]},v.id))})]})]}),o.jsx(xr,{isOpen:w.isOpen,title:w.title,message:w.message,confirmText:w.confirmText,cancelText:w.cancelText,type:w.type,verificationText:w.verificationText,verificationLabel:w.verificationLabel,verificationPlaceholder:w.verificationPlaceholder,verificationHint:w.verificationHint,onConfirm:f,onCancel:c})]})},Ua=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),Rg=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),$g=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"})}),Lg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Dg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),Fg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),Ug=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),_o=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{systemContexts:n,activeSystemContext:s,loadSystemContexts:a,createSystemContext:i,updateSystemContext:l,deleteSystemContext:d,activateSystemContext:u}=t,[g,h]=M.useState("list"),[p,w]=M.useState(null),[m,f]=M.useState({name:"",content:""}),[c,x]=M.useState(!1),[b,y]=M.useState(!1),{dialogState:_,showConfirmDialog:S,handleConfirm:j,handleCancel:v}=br();M.useEffect(()=>{const O="__systemContextEditorInitAt__",U=window[O]||0,J=Date.now();if(typeof U=="number"&&J-U<1e3)return;window[O]=J,(async()=>{x(!0);try{await a()}catch(H){console.error("Failed to load system contexts:",H)}finally{x(!1)}})()},[a]);const I=()=>{f({name:"",content:""}),w(null),h("create")},P=O=>{f({name:O.name,content:O.content}),w(O),h("edit")},T=async()=>{if(!m.name.trim()||!m.content.trim()){alert("请填写名称和内容");return}y(!0);try{g==="create"?await i(m.name,m.content):g==="edit"&&p&&await l(p.id,m.name,m.content),h("list")}catch(O){console.error("Failed to save system context:",O),alert("保存失败,请重试")}finally{y(!1)}},L=async O=>{var U,J;S({title:"删除确认",message:`确定要删除上下文 "${O.name}" 吗?此操作无法撤销。`,confirmText:"删除",cancelText:"取消",type:"danger",verificationText:((U=O.name)==null?void 0:U.trim())||"删除",verificationLabel:"请输入下方关键字确认删除",verificationPlaceholder:`输入 "${((J=O.name)==null?void 0:J.trim())||"删除"}"`,verificationHint:"为了防止误删,需要输入配置名称才能继续。",onConfirm:async()=>{try{await d(O.id)}catch($){console.error("Failed to delete system context:",$),alert("删除失败,请重试")}}})},C=async O=>{try{await u(O.id),await a()}catch(U){console.error("Failed to activate system context:",U),alert("激活失败,请重试")}},W=O=>{O.ctrlKey&&O.key==="s"&&(O.preventDefault(),g!=="list"&&T())},B=()=>o.jsxs("div",{className:"p-6 overflow-hidden flex flex-col",style:{height:"calc(90vh - 120px)"},children:[o.jsx("div",{className:"mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:o.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:[o.jsx("strong",{children:"系统上下文"}),"将作为每次对话的系统提示词,支持 Markdown 格式。 您可以创建多个上下文配置,但同一时间只能激活一个。"]})}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:c?o.jsx("div",{className:"flex items-center justify-center h-32",children:o.jsx("div",{className:"text-muted-foreground",children:"加载中..."})}):n.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-muted-foreground",children:[o.jsx(Ua,{}),o.jsx("p",{className:"mt-2",children:"暂无系统上下文配置"}),o.jsx("p",{className:"text-sm",children:'点击"新建"按钮创建第一个配置'})]}):o.jsx("div",{className:"space-y-3",children:n.map(O=>o.jsx("div",{className:`p-4 border rounded-lg transition-colors ${O.isActive?"border-green-500 bg-green-50 dark:bg-green-900/20":"border-border bg-card"}`,children:o.jsxs("div",{className:"flex items-start justify-between",children:[o.jsxs("div",{className:"flex-1",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("h3",{className:"font-medium text-foreground",children:O.name}),O.isActive&&o.jsxs("span",{className:"inline-flex items-center px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-full dark:bg-green-800 dark:text-green-100",children:[o.jsx(Ug,{}),o.jsx("span",{className:"ml-1",children:"已激活"})]})]}),o.jsxs("p",{className:"mt-1 text-sm text-muted-foreground line-clamp-2",children:[O.content.substring(0,100),O.content.length>100&&"..."]}),o.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["创建时间: ",new Date(O.createdAt).toLocaleString()]})]}),o.jsxs("div",{className:"flex items-center space-x-2 ml-4",children:[!O.isActive&&o.jsx("button",{onClick:()=>C(O),className:"px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors",children:"激活"}),o.jsx("button",{onClick:()=>P(O),className:"p-2 text-muted-foreground hover:text-blue-600 hover:bg-accent rounded transition-colors",children:o.jsx(Dg,{})}),o.jsx("button",{onClick:()=>L(O),className:"p-2 text-muted-foreground hover:text-red-600 hover:bg-accent rounded transition-colors",children:o.jsx(Fg,{})})]})]})},O.id))})})]}),z=()=>o.jsxs("div",{className:"p-6 overflow-hidden flex flex-col",style:{height:"calc(90vh - 120px)"},children:[o.jsxs("div",{className:"mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[o.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:g==="create"?"创建新的系统上下文配置":"编辑系统上下文配置"}),o.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-300 mt-2",children:"提示:使用 Ctrl+S 快速保存"})]}),o.jsxs("div",{className:"flex-1 flex flex-col space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"配置名称"}),o.jsx("input",{type:"text",value:m.name,onChange:O=>f({...m,name:O.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-lg focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:编程助手、翻译专家、创意写作等"})]}),o.jsxs("div",{className:"flex-1 flex flex-col",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("label",{className:"block text-sm font-medium text-foreground",children:"Markdown 内容"}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[m.content.length," 字符"]})]}),o.jsx("textarea",{value:m.content,onChange:O=>f({...m,content:O.target.value}),onKeyDown:W,className:"flex-1 w-full px-4 py-3 border border-input bg-background text-foreground rounded-lg focus:outline-none focus:ring-2 focus:ring-ring resize-none font-mono text-sm",placeholder:"请输入系统上下文内容,支持 Markdown 格式...\\n\\n例如:\\n# AI 助手角色设定\\n\\n你是一个专业的编程助手,具有以下特点:\\n- 提供准确、简洁的代码解决方案\\n- 遵循最佳实践和代码规范\\n- 耐心解答技术问题\\n\\n## 回答风格\\n- 使用中文回答\\n- 代码示例要完整可运行\\n- 提供必要的解释说明",spellCheck:!1})]}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[o.jsx("p",{children:"• 支持标准 Markdown 语法:标题、列表、代码块、链接等"}),o.jsx("p",{children:"• 内容将在每次对话开始时自动发送给 AI"}),o.jsx("p",{children:"• 留空则使用默认系统提示词"})]})]})]});return o.jsxs("div",{className:"modal-container",children:[o.jsxs("div",{className:"modal-content w-full max-w-4xl max-h-[90vh] overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Ua,{}),o.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"系统上下文设置"})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[g==="list"?o.jsxs("button",{onClick:I,className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",children:[o.jsx(Lg,{}),o.jsx("span",{children:"新建"})]}):o.jsxs(o.Fragment,{children:[o.jsxs("button",{onClick:T,disabled:b,className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[o.jsx($g,{}),o.jsx("span",{children:b?"保存中...":"保存"})]}),o.jsx("button",{onClick:()=>h("list"),className:"px-4 py-2 text-secondary-foreground border border-border rounded-md hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring transition-colors",children:"取消"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Rg,{})})]})]}),g==="list"?B():z()]}),o.jsx(xr,{isOpen:_.isOpen,title:_.title,message:_.message,confirmText:_.confirmText,cancelText:_.cancelText,type:_.type,verificationText:_.verificationText,verificationLabel:_.verificationLabel,verificationPlaceholder:_.verificationPlaceholder,verificationHint:_.verificationHint,onConfirm:j,onCancel:v})]})},Ba=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})}),Wa=()=>o.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),Bg=()=>o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),Wg=()=>o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),fc=({onClose:r,store:e})=>{let t;if(e)t=e();else try{t=tt()}catch{t=mt()}const{aiModelConfigs:n,loadAiModelConfigs:s,mcpConfigs:a,loadMcpConfigs:i,systemContexts:l,loadSystemContexts:d}=t,{userId:u}=Gf(),g=u||"custom_user_123",p=Xf()||te,[w,m]=M.useState([]),[f,c]=M.useState(!1),[x,b]=M.useState(!1),[y,_]=M.useState(null),[S,j]=M.useState(null),[v,I]=M.useState({name:"",description:"",ai_model_config_id:"",mcp_config_ids:[],system_context_id:void 0}),{dialogState:P,showConfirmDialog:T,handleConfirm:L,handleCancel:C}=br(),W=async()=>{c(!0);try{await Promise.all([s(),i(),d(),t.loadAgents?t.loadAgents():Promise.resolve()]);const A=t.agents&&Array.isArray(t.agents)?t.agents:await p.getAgents(g),N=Array.isArray(A)?A:[];m(N)}catch(A){console.error("加载智能体失败",A)}finally{c(!1)}},B=async A=>{for(let D=0;D<3;D++)try{t.loadAgents&&await t.loadAgents();const R=await p.getAgents(g),q=Array.isArray(R)?R:[];if(m(q),A&&Array.isArray(q)&&q.some(Q=>Q.id===A)||!A)break;await new Promise(Q=>setTimeout(Q,250))}catch(R){console.warn("刷新智能体列表失败,重试中…",R),await new Promise(q=>setTimeout(q,250))}};M.useEffect(()=>{const A="__agentManagerInitAt__",N=window[A]||0,D=Date.now();typeof N=="number"&&D-N<1e3||(window[A]=D,W())},[]);const z=()=>{I({name:"",description:"",ai_model_config_id:"",mcp_config_ids:[],system_context_id:void 0}),b(!1),j(null)},O=async A=>{var N;if(A.preventDefault(),!(!v.name.trim()||!v.ai_model_config_id))try{const D=await p.createAgent({name:v.name.trim(),description:((N=v.description)==null?void 0:N.trim())||void 0,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,user_id:g,enabled:!0});D&&D.id&&m(R=>R.some(Q=>Q.id===D.id)?R.map(Q=>Q.id===D.id?{...Q,...D}:Q):[D,...R]),await B(D==null?void 0:D.id),z()}catch(D){console.error("创建智能体失败",D),alert("创建失败,请重试")}},U=async A=>{if(A.preventDefault(),!!S)try{const N=await p.updateAgent(S.id,{name:v.name,description:v.description,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,enabled:!0});m(D=>D.map(R=>R.id===S.id?{...R,...N,name:v.name,description:v.description,ai_model_config_id:v.ai_model_config_id,mcp_config_ids:v.mcp_config_ids,system_context_id:v.system_context_id,enabled:!0}:R)),await B(S.id),z()}catch(N){console.error("更新智能体失败",N),alert("更新失败,请重试")}},J=A=>{var R;const N=w.find(q=>q.id===A),D=((R=N==null?void 0:N.name)==null?void 0:R.trim())||"删除";T({title:"删除智能体",message:`确定要删除智能体 "${(N==null?void 0:N.name)||"未命名"}" 吗?此操作将无法撤销。`,confirmText:"永久删除",cancelText:"取消",type:"danger",verificationText:D,verificationLabel:"请输入智能体名称以确认删除",verificationPlaceholder:`输入 "${D}"`,verificationHint:"删除后该智能体将从所有应用中移除且无法恢复。",onConfirm:async()=>{try{await p.deleteAgent(A),m(q=>q.filter(Q=>Q.id!==A)),await B()}catch(q){console.error("删除智能体失败",q),alert("删除失败,请重试")}}})},$=A=>{j(A),b(!0),I({name:A.name,description:A.description||"",ai_model_config_id:A.ai_model_config_id,mcp_config_ids:Array.isArray(A.mcp_config_ids)?A.mcp_config_ids:[],system_context_id:A.system_context_id})},H=A=>{const N=n.find(D=>D.id===A);return N?`${N.name}(${N.model_name})`:A},F=A=>{if(!A)return"未选择";const N=l.find(D=>D.id===A);return N?N.name:A},k=A=>A.map(D=>{const R=a.find(q=>q.id===D);return R?R.name:D}).join(",");return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:r}),o.jsxs("div",{className:"fixed right-0 top-0 h-full w-[520px] sm:w-[560px] bg-card z-50 shadow-xl breathing-border flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx(Ba,{}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"智能体管理"})]}),o.jsx("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx(Wa,{})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[!x&&o.jsxs("button",{onClick:()=>b(!0),className:"w-full p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx(Bg,{}),o.jsx("span",{children:"新增智能体"})]}),x&&o.jsxs("form",{onSubmit:S?U:O,className:"p-4 bg-muted rounded-lg space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"名称"}),o.jsx("input",{type:"text",value:v.name,onChange:A=>I({...v,name:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:项目助理",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"描述"}),o.jsx("textarea",{value:v.description,onChange:A=>I({...v,description:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"智能体用途说明",rows:3})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择模型(单选)"}),o.jsxs("select",{value:v.ai_model_config_id,onChange:A=>I({...v,ai_model_config_id:A.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",required:!0,children:[o.jsx("option",{value:"",children:"请选择模型"}),n.map(A=>o.jsxs("option",{value:A.id,children:[A.name,"(",A.model_name,")"]},A.id))]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择 MCP 配置(多选)"}),o.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 border rounded-md",children:a.map(A=>o.jsxs("label",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"checkbox",checked:v.mcp_config_ids.includes(A.id),onChange:N=>{const D=N.target.checked;I(R=>({...R,mcp_config_ids:D?[...R.mcp_config_ids,A.id]:R.mcp_config_ids.filter(q=>q!==A.id)}))}}),o.jsx("span",{children:A.name})]},A.id))})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择系统上下文"}),o.jsxs("select",{value:v.system_context_id||"",onChange:A=>I({...v,system_context_id:A.target.value||void 0}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",children:[o.jsx("option",{value:"",children:"不使用"}),l.map(A=>o.jsx("option",{value:A.id,children:A.name},A.id))]})]}),o.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[o.jsx("button",{type:"button",onClick:z,className:"px-3 py-2 rounded bg-muted text-muted-foreground hover:bg-accent",children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-2 rounded bg-blue-600 text-white hover:bg-blue-700",children:"保存"})]})]}),o.jsx("div",{children:f?o.jsx("div",{className:"text-muted-foreground",children:"加载中..."}):w.length===0?o.jsx("div",{className:"text-muted-foreground",children:"暂无智能体配置"}):o.jsx("div",{className:"space-y-3",children:w.map(A=>o.jsxs("div",{className:"p-4 border rounded-lg flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center space-x-2 min-w-0",children:[o.jsx("h3",{className:"font-medium text-foreground truncate",title:A.name,children:A.name}),!A.enabled&&o.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground",children:"未启用"})]}),A.description&&o.jsx("p",{className:"mt-1 text-sm text-muted-foreground truncate",title:A.description,children:A.description}),o.jsxs("p",{className:"mt-2 text-xs text-muted-foreground truncate",title:H(A.ai_model_config_id),children:["模型:",H(A.ai_model_config_id)]}),o.jsxs("p",{className:"mt-1 text-xs text-muted-foreground truncate",title:F(A.system_context_id),children:["系统上下文:",F(A.system_context_id)]}),o.jsxs("p",{className:"mt-1 text-xs text-muted-foreground truncate",title:k(A.mcp_config_ids||[]),children:["MCP配置:",k(A.mcp_config_ids||[])]})]}),o.jsxs("div",{className:"flex items-center space-x-2 ml-4 shrink-0",children:[o.jsx("button",{onClick:()=>_(A),className:"px-3 py-1 text-sm bg-muted text-foreground rounded hover:bg-accent transition-colors",children:"详情"}),o.jsx("button",{onClick:()=>$(A),className:"px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors",children:"编辑"}),o.jsxs("button",{onClick:()=>J(A.id),className:"px-3 py-1 text-sm bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors flex items-center space-x-1",children:[o.jsx(Wg,{}),o.jsx("span",{children:"删除"})]})]})]},A.id))})})]}),y&&o.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[o.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>_(null)}),o.jsxs("div",{className:"relative bg-card border border-border rounded-lg shadow-xl w-[520px] p-6",children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx(Ba,{}),o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"智能体详情"})]}),o.jsx("button",{onClick:()=>_(null),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",children:o.jsx(Wa,{})})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"名称:"}),y.name]}),y.description&&o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"描述:"}),y.description]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"模型:"}),H(y.ai_model_config_id)]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"系统上下文:"}),F(y.system_context_id)]}),o.jsxs("p",{children:[o.jsx("span",{className:"text-muted-foreground",children:"MCP配置:"}),k(y.mcp_config_ids||[])]}),Array.isArray(y.mcp_config_ids)&&y.mcp_config_ids.length>0&&o.jsx("div",{className:"mt-2 space-y-2",children:(y.mcp_config_ids||[]).map(A=>{var q,Q;const N=(a||[]).find(se=>se.id===A);if(!N)return null;let D="—";const R=N.args;if(Array.isArray(R))D=R.map(se=>String(se)).join(", ");else if(typeof R=="string"&&R.trim()!=="")try{const se=JSON.parse(R);Array.isArray(se)?D=se.map(Te=>String(Te)).join(", "):D=R}catch{D=R}return o.jsxs("div",{className:"p-2 rounded border border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:N.name}),o.jsx("span",{className:`px-1.5 py-0.5 text-xs rounded ${N.type==="http"?"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200":"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200"}`,children:((Q=(q=N.type)==null?void 0:q.toUpperCase)==null?void 0:Q.call(q))||N.type})]}),o.jsxs("div",{className:"mt-1 text-xs text-muted-foreground break-all",children:[N.type==="http"?"URL:":"命令:",o.jsx("span",{className:"text-foreground",children:N.command})]}),N.cwd&&o.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground break-all",children:["cwd:",o.jsx("span",{className:"text-foreground",children:String(N.cwd)})]}),N.type==="stdio"&&o.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground break-all",children:["args:",o.jsx("span",{className:"text-foreground",children:D})]})]},A)})}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:["创建时间:",y.created_at?new Date(y.created_at).toLocaleString():"-"]})]}),o.jsx("div",{className:"mt-4 flex justify-end space-x-2",children:o.jsx("button",{onClick:()=>_(null),className:"px-3 py-2 rounded bg-muted text-muted-foreground hover:bg-accent",children:"关闭"})})]})]})]}),o.jsx(xr,{isOpen:P.isOpen,title:P.title,message:P.message,confirmText:P.confirmText,cancelText:P.cancelText,type:P.type,verificationText:P.verificationText,verificationLabel:P.verificationLabel,verificationPlaceholder:P.verificationPlaceholder,verificationHint:P.verificationHint,onConfirm:L,onCancel:C})]})},Hg=r=>{const e=r==null?void 0:r.metadata;try{return typeof e=="string"?e?JSON.parse(e):{}:e&&typeof e=="object"?e:{}}catch{return{}}},qg=r=>{const e=Hg(r),t=e.prompt_text??e.promptText??e.session_prompt??e.sessionPrompt??null;return typeof t=="string"?t:""},hc=({className:r})=>{const{currentSession:e,updateSessionConfig:t}=tt(),n=M.useMemo(()=>qg(e),[e]),s=M.useMemo(()=>n.replace(/\s+/g," ").trim(),[n]),[a,i]=M.useState(!1),[l,d]=M.useState(""),[u,g]=M.useState(!1);M.useEffect(()=>{a&&d(n)},[a,n]);const h=n.trim().length>0;if(!e)return null;const p=async()=>{if(e){g(!0);try{await t(e.id,{promptText:l}),i(!1)}finally{g(!1)}}};return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>i(!0),className:ve("inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-border bg-muted/10 hover:bg-accent","text-xs text-foreground max-w-[520px] min-w-0",r),title:h?n:"未设置会话 Prompt(点击编辑)",children:[o.jsx("span",{className:"shrink-0 text-muted-foreground",children:"Prompt"}),o.jsx("span",{className:ve("truncate min-w-0",h?"text-foreground":"text-muted-foreground"),children:h?s:"未设置"})]}),a&&o.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:o.jsx("div",{className:"bg-card rounded-lg shadow-lg w-full max-w-3xl border border-border",children:o.jsxs("div",{className:"p-6",children:[o.jsxs("div",{className:"flex items-center justify-between gap-4",children:[o.jsx("h3",{className:"text-lg font-medium text-foreground",children:"编辑会话 Prompt"}),o.jsx("button",{type:"button",onClick:()=>!u&&i(!1),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors","aria-label":"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"此 Prompt 会在每次对话时作为 system prompt 使用(会话级,独立于全局激活 Prompt)。"}),o.jsx("textarea",{value:l,onChange:w=>d(w.target.value),className:"mt-4 w-full min-h-[220px] px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"输入会话 Prompt...",disabled:u}),o.jsxs("div",{className:"flex gap-3 mt-4",children:[o.jsx("button",{type:"button",onClick:()=>i(!1),disabled:u,className:"flex-1 px-4 py-2 text-sm border border-border rounded-md hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"取消"}),o.jsx("button",{type:"button",onClick:p,disabled:u,className:"flex-1 px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:u?"保存中...":"保存"})]})]})})})]})},mc=({isOpen:r,onClose:e,manageOnly:t=!1,title:n,layout:s="modal",onApplicationSelect:a})=>{let i;try{i=tt()}catch{i=mt()}const{applications:l,loadApplications:d,createApplication:u,updateApplication:g,deleteApplication:h}=i,p=M.useRef(new Map),[w,m]=M.useState(!!t),[f,c]=M.useState(!1),[x,b]=M.useState(null),[y,_]=M.useState({name:"",url:"",iconUrl:""});M.useEffect(()=>{try{console.log("[ApplicationsPanel] useEffect -> loadApplications"),d==null||d()}catch(C){console.error("[ApplicationsPanel] loadApplications error:",C)}},[d]);const S=()=>{b(null),_({name:"",url:"",iconUrl:""}),c(!1)},j=async C=>{C.preventDefault(),y.name.trim()&&(x?await(g==null?void 0:g(x,{name:y.name.trim(),url:y.url.trim(),iconUrl:y.iconUrl.trim()||void 0})):await(u==null?void 0:u(y.name.trim(),y.url.trim(),y.iconUrl.trim()||void 0)),S())},v=C=>{console.log("[ApplicationsPanel] closeAppWindow:",C);const W=p.current.get(C);W&&!W.closed&&W.close(),p.current.delete(C)},I=C=>{console.log("[ApplicationsPanel] handleAppClick - 应用被点击:",{id:C.id,name:C.name,url:C.url}),a?(console.log("[ApplicationsPanel] 调用 onApplicationSelect 回调"),a(C)):console.log("[ApplicationsPanel] ⚠️ 未提供 onApplicationSelect 回调"),e&&(console.log("[ApplicationsPanel] 关闭应用列表面板"),e())};if(!(s==="modal"?!!r:!0))return null;const T=t?!0:w,L=n??(T?"应用管理":"应用列表");return s==="modal"?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-40",onClick:e}),o.jsxs("div",{className:"fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-4xl h-[85vh] bg-card z-50 shadow-xl breathing-border flex flex-col rounded-lg",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-full bg-blue-500"}),o.jsx("h2",{className:"text-lg font-semibold text-foreground",children:L})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[!t&&o.jsx("button",{onClick:()=>{m(!w),c(!1),S()},className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent transition-colors",children:T?"浏览模式":"管理模式"}),!T&&p.current.size>0&&o.jsx("button",{className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent",onClick:()=>{p.current.forEach((C,W)=>v(W))},children:"关闭全部"}),o.jsx("button",{onClick:e,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:T?o.jsxs("div",{className:"space-y-4",children:[!f&&o.jsxs("button",{type:"button",onClick:()=>c(!0),className:"w-full p-4 border-2 border-dashed border-border rounded-lg hover:border-blue-500 transition-colors flex items-center justify-center space-x-2 text-muted-foreground hover:text-blue-600",children:[o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v12m6-6H6"})}),o.jsx("span",{children:"新增应用"})]}),f&&o.jsxs("form",{onSubmit:j,className:"p-4 bg-muted rounded-lg space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"名称"}),o.jsx("input",{type:"text",value:y.name,onChange:C=>_({...y,name:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"例如:Jira、GitHub",required:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL"}),o.jsx("input",{type:"text",value:y.url,onChange:C=>_({...y,url:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"https://app.example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"图标URL"}),o.jsx("input",{type:"text",value:y.iconUrl,onChange:C=>_({...y,iconUrl:C.target.value}),className:"w-full px-3 py-2 border border-input bg-background text-foreground rounded-md focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"https://app.example.com/icon.png"})]}),o.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[o.jsx("button",{type:"button",className:"px-3 py-2 rounded bg-muted hover:bg-accent",onClick:S,children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-2 rounded bg-blue-600 text-white hover:bg-blue-700",children:x?"保存":"创建"})]})]}),o.jsxs("div",{className:"space-y-2",children:[l==null?void 0:l.map(C=>o.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border hover:bg-muted transition-colors",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center overflow-hidden shrink-0",children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("span",{className:"text-white text-sm font-bold",children:C.name.charAt(0).toUpperCase()})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium text-foreground",children:C.name}),C.url&&o.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-md",children:C.url})]})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("button",{className:"px-2 py-1 text-xs bg-muted rounded hover:bg-accent",onClick:()=>{b(C.id),c(!0),_({name:C.name,url:C.url||"",iconUrl:C.iconUrl||""})},children:"编辑"}),o.jsx("button",{className:"px-2 py-1 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90",onClick:()=>h==null?void 0:h(C.id),children:"删除"})]})]},C.id)),(l==null?void 0:l.length)===0&&o.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[o.jsx("svg",{className:"w-16 h-16 mx-auto mb-3 opacity-30",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm",children:"暂无应用,点击上方按钮添加"})]})]})]}):o.jsxs("div",{className:"grid grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-6",children:[l==null?void 0:l.map(C=>{const W=p.current.has(C.id);return o.jsxs("div",{className:"relative group/item",children:[o.jsxs("button",{className:"w-full flex flex-col items-center space-y-2 p-2 rounded-lg transition-all hover:bg-muted",onClick:()=>I(C),title:C.url||"",children:[o.jsxs("div",{className:`relative w-16 h-16 rounded-full flex items-center justify-center overflow-hidden transition-all ${W?"ring-2 ring-green-500 ring-offset-2 ring-offset-background scale-110":"bg-gradient-to-br from-blue-500/20 to-purple-500/20 group-hover/item:scale-105"}`,children:[C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center",children:o.jsx("span",{className:"text-white text-xl font-bold",children:C.name.charAt(0).toUpperCase()})}),W&&o.jsx("div",{className:"absolute -top-1 -right-1 w-5 h-5 bg-green-500 rounded-full border-2 border-background flex items-center justify-center",children:o.jsx("div",{className:"w-2 h-2 bg-white rounded-full animate-pulse"})})]}),o.jsx("div",{className:"text-xs font-medium text-foreground text-center truncate w-full px-1",children:C.name})]}),W&&o.jsx("button",{onClick:B=>{B.stopPropagation(),v(C.id)},className:"absolute top-0 left-0 w-5 h-5 bg-red-500 hover:bg-red-600 rounded-full flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-opacity z-10",title:"关闭",children:o.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M6 18L18 6M6 6l12 12"})})})]},C.id)}),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-20 text-center",children:[o.jsx("svg",{className:"w-20 h-20 text-muted-foreground/30 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用"}),o.jsx("button",{onClick:()=>m(!0),className:"text-sm text-blue-500 hover:text-blue-600 underline",children:"点击切换到管理模式添加应用"})]})]})})]})]}):o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border bg-card/50",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-blue-500"}),o.jsx("span",{className:"text-sm font-medium text-foreground",children:L})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[!t&&o.jsx("button",{onClick:()=>{m(!w),c(!1),S()},className:"px-2 py-1 text-xs rounded bg-muted hover:bg-accent transition-colors",children:T?"浏览模式":"管理模式"}),!T&&p.current.size>0&&o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-muted hover:bg-accent",onClick:()=>{p.current.forEach((C,W)=>v(W))},children:"关闭全部"}),e&&o.jsx("button",{onClick:e,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"关闭",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mb-4 flex items-center justify-between",children:o.jsx("button",{type:"button",onClick:()=>{b(null),_({name:"",url:"",iconUrl:""}),c(C=>!C)},className:"px-3 py-1.5 text-sm rounded bg-primary text-primary-foreground hover:opacity-90",children:f?"取消":"新增应用"})}),f&&o.jsxs("form",{onSubmit:C=>{var O,U,J;C.preventDefault();const W=((O=y.name)==null?void 0:O.trim())||"",B=((U=y.url)==null?void 0:U.trim())||"",z=((J=y.iconUrl)==null?void 0:J.trim())||void 0;W&&(x?g==null||g(x,{name:W,url:B,iconUrl:z}):u==null||u(W,B,z),c(!1),S())},className:"p-4 bg-muted rounded-lg space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"名称"}),o.jsx("input",{value:y.name,onChange:C=>_({...y,name:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"例如:飞书"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"URL"}),o.jsx("input",{value:y.url,onChange:C=>_({...y,url:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"https://example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-xs font-medium text-foreground mb-1",children:"图标地址"}),o.jsx("input",{value:y.iconUrl,onChange:C=>_({...y,iconUrl:C.target.value}),className:"w-full px-2 py-1 text-sm rounded border border-border bg-background",placeholder:"https://.../icon.png"})]}),o.jsxs("div",{className:"flex justify-end space-x-2",children:[o.jsx("button",{type:"button",onClick:()=>{c(!1),S(),b(null)},className:"px-3 py-1.5 text-sm rounded bg-muted hover:bg-accent",children:"取消"}),o.jsx("button",{type:"submit",className:"px-3 py-1.5 text-sm rounded bg-primary text-primary-foreground hover:opacity-90",children:x?"保存":"创建"})]})]}),o.jsxs("div",{className:"space-y-2",children:[l==null?void 0:l.map(C=>o.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border hover:bg-muted transition-colors",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center overflow-hidden shrink-0",children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("span",{className:"text-white text-sm font-bold",children:C.name.charAt(0).toUpperCase()})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium text-foreground",children:C.name}),C.url&&o.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-md",children:C.url})]})]}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-background hover:bg-accent",onClick:()=>{c(!0),b(C.id),_({name:C.name||"",url:C.url||"",iconUrl:C.iconUrl||""})},children:"编辑"}),o.jsx("button",{className:"px-2 py-1 text-xs rounded bg-destructive text-destructive-foreground hover:opacity-90",onClick:()=>h==null?void 0:h(C.id),children:"删除"})]})]},C.id)),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center",children:[o.jsx("svg",{className:"w-16 h-16 text-muted-foreground/30 mb-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用,点击上方按钮添加。"})]})]})]}):o.jsxs("div",{className:"grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4",children:[l==null?void 0:l.map(C=>{const W=p.current.has(C.id);return o.jsxs("div",{className:"relative group/item",children:[o.jsxs("button",{className:"w-full flex flex-col items-center space-y-2 p-2 rounded-lg transition-all hover:bg-muted",onClick:()=>I(C),title:C.url||"",children:[o.jsx("div",{className:`relative w-14 h-14 rounded-full flex items-center justify-center overflow-hidden transition-all ${W?"ring-2 ring-green-500 ring-offset-2 ring-offset-background scale-105":"bg-gradient-to-br from-blue-500/20 to-purple-500/20 group-hover/item:scale-105"}`,children:C.iconUrl?o.jsx("img",{src:C.iconUrl,alt:C.name,className:"w-full h-full object-cover"}):o.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center",children:o.jsx("span",{className:"text-white text-lg font-bold",children:C.name.charAt(0).toUpperCase()})})}),o.jsx("div",{className:"text-xs font-medium text-foreground truncate max-w-full",children:C.name}),C.url&&o.jsx("div",{className:"text-[10px] text-muted-foreground truncate max-w-full",children:C.url})]}),W&&o.jsx("button",{onClick:B=>{B.stopPropagation(),v(C.id)},className:"absolute top-0 left-0 w-4 h-4 bg-red-500 hover:bg-red-600 rounded-full flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-opacity z-10",title:"关闭",children:o.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M6 18L18 6M6 6l12 12"})})})]},C.id)}),((l==null?void 0:l.length)??0)===0&&o.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-10 text-center",children:[o.jsx("svg",{className:"w-16 h-16 text-muted-foreground/30 mb-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),o.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"暂无应用"}),o.jsx("button",{onClick:()=>m(!0),className:"text-sm text-blue-500 hover:text-blue-600 underline",children:"切换到管理模式以添加应用"})]})]})})]})},So=({className:r,apiBaseUrl:e,port:t,userId:n,projectId:s,showMcpManager:a=!0,showAiModelManager:i=!0,showSystemContextEditor:l=!0,showAgentManager:d=!0,onApplicationSelect:u})=>{const g=M.useMemo(()=>{if(e)return e;if(t)return`http://localhost:${t}/api`},[e,t]),h=M.useMemo(()=>{if(g)return new er(g)},[g]);return o.jsx(Vf,{userId:n,projectId:s,customApiClient:h,children:o.jsx(zg,{className:r,showMcpManager:a,showAiModelManager:i,showSystemContextEditor:l,showAgentManager:d,onApplicationSelect:u})})},zg=({className:r,showMcpManager:e,showAiModelManager:t,showSystemContextEditor:n,showAgentManager:s,onApplicationSelect:a})=>{const i=Wl(),{currentSession:l,messages:d,isLoading:u,isStreaming:g,hasMoreMessages:h,error:p,loadSessions:w,sendMessage:m,clearError:f,mcpConfigs:c,loadMcpConfigs:x,getSessionMcpConfigIds:b,sessionMcpRevision:y,aiModelConfigs:_,selectedModelId:S,setSelectedModel:j,loadAiModelConfigs:v,agents:I,selectedAgentId:P,setSelectedAgent:T,loadAgents:L,abortCurrentConversation:C,loadMoreMessages:W}=i(),B=M.useRef(null),[z,O]=M.useState(!1),[U,J]=M.useState(""),[$,H]=M.useState(""),[F,k]=M.useState(!1),[A,N]=M.useState(!1),[D,R]=M.useState(!1),[q,Q]=M.useState(!1),[se,Te]=M.useState(!1);M.useEffect(()=>{(window.__standaloneChatInterfaceDidInit__??!1)||(window.__standaloneChatInterfaceDidInit__=!0,w(),v(),x(),L())},[w,v,x,L]),M.useEffect(()=>{B.current&&B.current.scrollIntoView({behavior:"smooth"})},[d,g]),M.useEffect(()=>{let qe=!1;const Rt=Fe=>{if(Fe.length===0)return{summary:"MCP:未选择",tooltip:"未选择 MCP"};const $t=Fe.join(",");return Fe.length<=2?{summary:`MCP:${$t}`,tooltip:`MCP:${$t}`}:{summary:`MCP:${Fe.slice(0,2).join(",")} +${Fe.length-2}`,tooltip:`MCP:${$t}`}};return(async()=>{if(!(l!=null&&l.id)){J(""),H("");return}try{const Fe=await b(l.id);if(qe)return;const $t=new Map((c||[]).map(Lt=>[Lt.id,Lt.name])),gc=(Fe||[]).map(Lt=>$t.get(Lt)||Lt),{summary:pc,tooltip:xc}=Rt(gc);J(pc),H(xc)}catch(Fe){if(console.error("Failed to load session MCP summary:",Fe),qe)return;J("MCP:加载失败"),H("MCP:加载失败")}})(),()=>{qe=!0}},[l==null?void 0:l.id,y,c,b]);const An=async(qe,Rt)=>{try{await m(qe,Rt)}catch(ze){console.error("Failed to send message:",ze)}};return o.jsxs("div",{className:ve("flex flex-col h-screen bg-background text-foreground",r),children:[o.jsxs("div",{className:"flex items-center justify-between p-4 bg-card border-b border-border",children:[o.jsxs("div",{className:"flex items-center space-x-3",children:[o.jsx("button",{onClick:()=>O(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开会话列表",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"})})}),l&&o.jsx("div",{className:"flex-1 min-w-0",children:o.jsx("h1",{className:"text-lg font-semibold text-foreground truncate",children:l.title})}),o.jsx(hc,{})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[a&&o.jsx("button",{onClick:()=>{console.log("[StandaloneChat] open ApplicationsPanel button clicked"),Te(!0)},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开应用列表",children:o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:[o.jsx("path",{d:"M4 5h6v14H4z",strokeWidth:"2"}),o.jsx("path",{d:"M12 5h8v14h-8z",strokeWidth:"2"})]})}),e&&o.jsx("button",{onClick:()=>k(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"MCP服务管理",children:o.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z"}),o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),t&&o.jsx("button",{onClick:()=>N(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"AI配置管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z"})})}),n&&o.jsx("button",{onClick:()=>R(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"System Prompt编辑器",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}),s&&o.jsx("button",{onClick:()=>Q(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"智能体管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})})}),o.jsx(yo,{})]})]}),p&&o.jsx("div",{className:"mx-4 mt-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:o.jsxs("div",{className:"flex items中心 justify-between",children:[o.jsx("p",{className:"text-sm text-destructive",children:p}),o.jsx("button",{onClick:f,className:"text-destructive hover:text-destructive/80 transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),o.jsx("div",{className:"flex-1 flex overflow-hidden",children:o.jsxs("div",{className:"flex-1 overflow-hidden",children:[l?o.jsx("div",{className:"flex flex-col h-full",children:o.jsx("div",{className:"flex-1 overflow-hidden",children:o.jsx(po,{messages:d,isLoading:u,isStreaming:g,hasMore:h,onLoadMore:()=>l&&W(l.id)})})}):o.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:o.jsxs("div",{className:"text-center",children:[o.jsx("svg",{className:"w-16 h-16 mx-auto mb-4 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),o.jsx("p",{className:"text-lg mb-2",children:"欢迎使用AI聊天助手"}),o.jsx("p",{className:"text-sm",children:"点击左上角按钮创建新会话开始对话"})]})}),o.jsx("div",{ref:B})]})}),l&&o.jsx(xo,{onSend:An,onStop:C,disabled:u||g,isStreaming:g,selectedModelId:S,availableModels:_,onModelChange:j,showModelSelector:!0,selectedAgentId:P,availableAgents:I,onAgentChange:T,sessionMcpSummary:U,sessionMcpTooltip:$}),o.jsx(bo,{isOpen:z,onClose:()=>O(!1),store:i}),o.jsx(mc,{isOpen:se,onClose:()=>Te(!1),title:"应用列表",layout:"modal",onApplicationSelect:a}),F&&o.jsx(wo,{onClose:()=>k(!1),store:i}),A&&o.jsx(vo,{onClose:()=>N(!1),store:i}),s&&q&&o.jsx(fc,{onClose:()=>Q(!1),store:i}),D&&o.jsx(_o,{onClose:()=>R(!1),store:i})]})};class Jg{constructor(e,t,n,s,a=!0,i=!0,l=!0,d=!0,u){V(this,"userId");V(this,"projectId");V(this,"configUrl");V(this,"apiClient");V(this,"store");V(this,"className");V(this,"showMcpManager");V(this,"showAiModelManager");V(this,"showSystemContextEditor");V(this,"showAgentManager");V(this,"onApplicationSelect");this.userId=e,this.projectId=t,this.configUrl=n||"/api",this.className=s,this.showMcpManager=a,this.showAiModelManager=i,this.showSystemContextEditor=l,this.showAgentManager=d,this.onApplicationSelect=u,console.log("🔧 AiChat Constructor - configUrl:",this.configUrl),console.log("🔧 AiChat Constructor - Module Controls:",{showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,hasApplicationSelectCallback:!!this.onApplicationSelect}),this.apiClient=new er(this.configUrl),this.store=Zr(this.apiClient,{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl})}render(){return M.createElement(Vg,{className:this.className,userId:this.userId,projectId:this.projectId,configUrl:this.configUrl,showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,onApplicationSelect:this.onApplicationSelect})}getConfig(){return{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl,className:this.className,showMcpManager:this.showMcpManager,showAiModelManager:this.showAiModelManager,showSystemContextEditor:this.showSystemContextEditor,showAgentManager:this.showAgentManager,onApplicationSelect:this.onApplicationSelect}}updateConfig(e){e.userId&&(this.userId=e.userId),e.projectId&&(this.projectId=e.projectId),e.configUrl&&(this.configUrl=e.configUrl,this.apiClient=new er(this.configUrl),this.store=Zr(this.apiClient,{userId:this.userId,projectId:this.projectId,configUrl:this.configUrl})),e.className!==void 0&&(this.className=e.className),e.showMcpManager!==void 0&&(this.showMcpManager=e.showMcpManager),e.showAiModelManager!==void 0&&(this.showAiModelManager=e.showAiModelManager),e.showSystemContextEditor!==void 0&&(this.showSystemContextEditor=e.showSystemContextEditor),e.showAgentManager!==void 0&&(this.showAgentManager=e.showAgentManager),e.onApplicationSelect!==void 0&&(this.onApplicationSelect=e.onApplicationSelect)}getStore(){return this.store}getApiClient(){return this.apiClient}getSelectedApplication(){var s;const e=this.store.getState(),t=e.selectedApplicationId;if(console.log("[AiChat] getSelectedApplication called:",{id:t,applicationsCount:(s=e.applications)==null?void 0:s.length}),!t)return null;const n=e.applications.find(a=>a.id===t)||null;return console.log("[AiChat] getSelectedApplication result:",n),n}getSelectedApplicationUrl(){const e=this.getSelectedApplication();return e?e.url:null}subscribeSelectedApplication(e){console.log("[AiChat] subscribeSelectedApplication: 设置订阅"),console.log("[AiChat] store 对象:",this.store),console.log("[AiChat] store.subscribe 类型:",typeof this.store.subscribe);let t=this.store.getState().selectedApplicationId;console.log("[AiChat] 初始 previousId:",t);const n=this.store.subscribe(s=>{const a=s.selectedApplicationId;if(console.log("[AiChat] store.subscribe 被触发, currentId:",a,"previousId:",t),a!==t){console.log("[AiChat] selectedApplicationId 变化检测到:",{old:t,new:a}),t=a;const i=this.getSelectedApplication();console.log("[AiChat] 准备调用 listener,app:",i),e(i)}});return console.log("[AiChat] 首次调用 listener"),e(this.getSelectedApplication()),()=>{console.log("[AiChat] 取消订阅"),n()}}}const Vg=({className:r,userId:e,projectId:t,configUrl:n,showMcpManager:s,showAiModelManager:a,showSystemContextEditor:i,showAgentManager:l,onApplicationSelect:d})=>o.jsx(So,{className:r,apiBaseUrl:n,userId:e,projectId:t,showMcpManager:s,showAiModelManager:a,showSystemContextEditor:i,showAgentManager:l,onApplicationSelect:d}),Gg=({className:r,onMessageSend:e,customRenderer:t})=>{const{currentSession:n,messages:s,isLoading:a,isStreaming:i,hasMoreMessages:l,error:d,loadSessions:u,loadMoreMessages:g,sendMessage:h,clearError:p,mcpConfigs:w,loadMcpConfigs:m,getSessionMcpConfigIds:f,sessionMcpRevision:c,aiModelConfigs:x,selectedModelId:b,setSelectedModel:y,loadAiModelConfigs:_,agents:S,selectedAgentId:j,setSelectedAgent:v,loadAgents:I,abortCurrentConversation:P}=tt(),T=M.useRef(null),[L,C]=M.useState(!1),[W,B]=M.useState(!1),[z,O]=M.useState(!1),[U,J]=M.useState(!1),[$,H]=M.useState(!1),[F,k]=M.useState(""),[A,N]=M.useState("");M.useEffect(()=>{(window.__chatInterfaceDidInit__??!1)||(window.__chatInterfaceDidInit__=!0,u(),_(),m(),I())},[u,_,m,I]),M.useEffect(()=>{T.current&&T.current.scrollIntoView({behavior:"smooth"})},[s,i]),M.useEffect(()=>{let R=!1;const q=se=>{if(se.length===0)return{summary:"MCP:未选择",tooltip:"未选择 MCP"};const Te=se.join(",");return se.length<=2?{summary:`MCP:${Te}`,tooltip:`MCP:${Te}`}:{summary:`MCP:${se.slice(0,2).join(",")} +${se.length-2}`,tooltip:`MCP:${Te}`}};return(async()=>{if(!(n!=null&&n.id)){k(""),N("");return}try{const se=await f(n.id);if(R)return;const Te=new Map((w||[]).map(ze=>[ze.id,ze.name])),An=(se||[]).map(ze=>Te.get(ze)||ze),{summary:qe,tooltip:Rt}=q(An);k(qe),N(Rt)}catch(se){if(console.error("Failed to load session MCP summary:",se),R)return;k("MCP:加载失败"),N("MCP:加载失败")}})(),()=>{R=!0}},[n==null?void 0:n.id,c,w,f]);const D=async(R,q)=>{try{await h(R,q),e==null||e(R,[])}catch(Q){console.error("Failed to send message:",Q)}};return o.jsxs("div",{className:ve("flex flex-col h-screen bg-background text-foreground",r),children:[d&&o.jsx("div",{className:"mx-4 mt-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("p",{className:"text-sm text-destructive",children:d}),o.jsx("button",{onClick:p,className:"text-destructive hover:text-destructive/80 transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),o.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[o.jsx("div",{className:"flex flex-col h-full",children:o.jsx(bo,{embedded:!0})}),o.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n&&o.jsxs("div",{className:"flex items-center justify-between p-4 bg-card border-b border-border",children:[o.jsx("div",{className:"flex items-center space-x-3",children:o.jsx(hc,{})}),o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx(yo,{}),o.jsx("button",{onClick:()=>H(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"打开应用列表",children:o.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:[o.jsx("path",{d:"M4 5h6v14H4z",strokeWidth:"2"}),o.jsx("path",{d:"M12 5h8v14h-8z",strokeWidth:"2"})]})}),o.jsx("button",{onClick:()=>C(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"MCP 服务器管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"})})}),o.jsx("button",{onClick:()=>J(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"智能体管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6M9 16h6M6 8h12a2 2 0 012 2v8a2 2 0 01-2 2H6a2 2 0 01-2-2v-8a2 2 0 012-2z"})})}),o.jsx("button",{onClick:()=>B(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"AI 模型管理",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),o.jsx("button",{onClick:()=>O(!0),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"系统上下文设置",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})})]})]}),n?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex-1 overflow-auto",children:[o.jsx(po,{messages:s,isLoading:a,isStreaming:i,hasMore:l,onLoadMore:()=>n&&g(n.id),customRenderer:t}),o.jsx("div",{ref:T})]}),o.jsx("div",{className:"border-t border-border",children:o.jsx(xo,{onSend:D,onStop:P,disabled:a,isStreaming:i,placeholder:"输入消息...",showModelSelector:!0,selectedModelId:b,availableModels:x,onModelChange:y,selectedAgentId:j,availableAgents:S,onAgentChange:v,sessionMcpSummary:F,sessionMcpTooltip:A})})]}):o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsxs("div",{className:"text-center",children:[o.jsx("h2",{className:"text-xl font-semibold text-muted-foreground mb-2",children:"欢迎使用 AI 聊天"}),o.jsx("p",{className:"text-muted-foreground mb-4",children:"从左侧会话列表选择会话,或创建新的会话开始对话"})]})})]})]}),L&&o.jsx(wo,{onClose:()=>C(!1)}),U&&o.jsx(fc,{onClose:()=>J(!1)}),W&&o.jsx(vo,{onClose:()=>B(!1)}),z&&o.jsx(_o,{onClose:()=>O(!1)}),o.jsx(mc,{isOpen:$,onClose:()=>H(!1),title:"应用列表",layout:"modal"})]})};class Xg extends M.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("ErrorBoundary caught an error:",e,t)}render(){var e;return this.state.hasError?this.props.fallback?this.props.fallback:o.jsx("div",{className:"flex items-center justify-center h-full p-8",children:o.jsxs("div",{className:"text-center space-y-4",children:[o.jsx("div",{className:"w-16 h-16 mx-auto bg-destructive/10 rounded-full flex items-center justify-center",children:o.jsx("svg",{className:"w-8 h-8 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Something went wrong"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:((e=this.state.error)==null?void 0:e.message)||"An unexpected error occurred"}),o.jsx("button",{onClick:()=>this.setState({hasError:!1,error:void 0}),className:"mt-4 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors",children:"Try again"})]})]})}):this.props.children}}const Kg="1.0.11";exports.AiChat=Jg;exports.AiModelManager=vo;exports.AiServer=Fl;exports.ApiClient=er;exports.AppError=ug;exports.AttachmentRenderer=nc;exports.ChatIcon=cc;exports.ChatInterface=Gg;exports.ChatService=Bl;exports.CheckIcon=gg;exports.ChevronDownIcon=yg;exports.CopyIcon=xg;exports.DatabaseService=As;exports.DotsVerticalIcon=ic;exports.ErrorBoundary=Xg;exports.InputArea=xo;exports.LoadingSpinner=oc;exports.MarkdownRenderer=lt;exports.McpManager=wo;exports.MessageItem=sc;exports.MessageList=po;exports.MessageManager=Ul;exports.PencilIcon=Ss;exports.PlayIcon=bg;exports.PlusIcon=ac;exports.SessionList=bo;exports.StandaloneChatInterface=So;exports.SystemContextEditor=_o;exports.ThemeToggle=yo;exports.ToolCallRenderer=_s;exports.TrashIcon=lc;exports.XIcon=pg;exports.apiClient=te;exports.cleanHtmlContent=eg;exports.cn=ve;exports.conversationsApi=Or;exports.copyToClipboard=ig;exports.debounce=ng;exports.deepClone=vs;exports.default=So;exports.downloadFile=lg;exports.formatDate=Ym;exports.formatDateTime=Qm;exports.formatFileSize=tc;exports.formatRelativeTime=Km;exports.formatTime=ec;exports.generateId=Xm;exports.generateRandomColor=ag;exports.getFileExtension=rc;exports.getOS=dg;exports.isImageFile=og;exports.isMobile=cg;exports.isValidEmail=tg;exports.isValidUrl=rg;exports.retry=fg;exports.storage=hg;exports.throttle=sg;exports.truncateText=Zm;exports.useChatStore=mt;exports.useTheme=uc;exports.version=Kg;
101
101
  //# sourceMappingURL=index.cjs.js.map