2
0

page-9881369a3bac97e4.js 28 KB

1
  1. (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{6161:function(e,t,r){Promise.resolve().then(r.bind(r,6901))},6901:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return p}});var a=r(7437),s=r(2265),l=r(8652);function n(e){let{onSend:t,isLoading:r,onAbort:l}=e,[n,o]=(0,s.useState)(""),i=e=>{e.preventDefault(),n.trim()&&!r&&(t(n.trim()),o(""))};return(0,a.jsxs)("form",{onSubmit:i,className:"flex items-end space-x-2",children:[(0,a.jsx)("textarea",{value:n,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),i(e))},placeholder:"输入消息... (Shift+Enter 换行)",disabled:r,rows:1,className:"flex-1 resize-none border dark:border-gray-600 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",style:{minHeight:"40px",maxHeight:"200px"}}),r?(0,a.jsx)("button",{type:"button",onClick:l,className:"px-6 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors",children:"停止"}):(0,a.jsx)("button",{type:"submit",disabled:!n.trim(),className:"px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:bg-gray-300 disabled:cursor-not-allowed transition-colors",children:"发送"})]})}function o(e){let{role:t,content:r,isLoading:s}=e,l="user"===t;return(0,a.jsx)("div",{className:"flex ".concat(l?"justify-end":"justify-start"),children:(0,a.jsxs)("div",{className:"message-bubble ".concat(l?"user-message":"assistant-message"),children:[!l&&(0,a.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"AI 助手"}),(0,a.jsxs)("div",{className:"whitespace-pre-wrap break-words",children:[r,s&&(0,a.jsx)("span",{className:"inline-block ml-1 animate-pulse",children:"▊"})]})]})})}var i=r(7648);function c(){let{isAuthenticated:e,username:t,logout:r}=(0,l.aC)();return(0,a.jsx)("header",{className:"bg-white dark:bg-gray-800 border-b dark:border-gray-700 px-6 py-4",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,a.jsx)("h1",{className:"text-xl font-bold text-gray-800 dark:text-white",children:"AI MCP Web UI"}),(0,a.jsxs)("nav",{className:"flex space-x-4",children:[(0,a.jsx)(i.default,{href:"/",className:"text-gray-600 dark:text-gray-300 hover:text-blue-500",children:"聊天"}),(0,a.jsx)(i.default,{href:"/auth",className:"text-gray-600 dark:text-gray-300 hover:text-blue-500",children:"登录"})]})]}),(0,a.jsx)("div",{className:"flex items-center space-x-4",children:e?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("span",{className:"text-gray-600 dark:text-gray-300",children:["欢迎, ",t]}),(0,a.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm bg-gray-200 dark:bg-gray-700 rounded hover:bg-gray-300 dark:hover:bg-gray-600",children:"登出"})]}):(0,a.jsx)(i.default,{href:"/auth",className:"px-4 py-2 text-sm bg-blue-500 text-white rounded hover:bg-blue-600",children:"登录"})})]})})}function d(e){let{toolCalls:t,isLoading:r}=e;return(0,a.jsxs)("div",{className:"w-80 bg-white dark:bg-gray-800 border-l dark:border-gray-700 overflow-y-auto",children:[(0,a.jsx)("div",{className:"p-4 border-b dark:border-gray-700",children:(0,a.jsx)("h3",{className:"font-semibold text-gray-800 dark:text-white",children:"工具调用"})}),(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[0===t.length&&r&&(0,a.jsxs)("div",{className:"text-center text-gray-400 py-8",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500 mx-auto mb-2"}),(0,a.jsx)("p",{children:"AI 正在思考..."})]}),t.map((e,t)=>(0,a.jsxs)("div",{className:"tool-call",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,a.jsx)("span",{className:"font-medium text-purple-700",children:e.tool}),(0,a.jsxs)("span",{className:"text-xs text-gray-500",children:["#",t+1]})]}),(0,a.jsx)("pre",{className:"text-xs bg-gray-50 dark:bg-gray-900 p-2 rounded overflow-x-auto",children:JSON.stringify(e.result,null,2)})]},t)),r&&t.length>0&&(0,a.jsxs)("div",{className:"text-center text-gray-400 py-4",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-500 mx-auto"}),(0,a.jsx)("p",{className:"text-sm mt-2",children:"处理中..."})]})]})]})}let u=e=>{let{label:t,variant:r="default",onClick:s,disabled:l=!1,className:n}=e,o={default:"bg-gray-200 hover:bg-gray-300 text-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200",primary:"bg-blue-600 hover:bg-blue-700 text-white",secondary:"bg-purple-600 hover:bg-purple-700 text-white",ghost:"hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300",danger:"bg-red-600 hover:bg-red-700 text-white"},i=o[r]||o.default;return(0,a.jsx)("button",{onClick:()=>{if(s&&!l)try{Function("event",s)(new Event("click"))}catch(e){console.error("Error executing onClick:",e)}},disabled:l,className:"".concat(i," px-4 py-2 rounded-md font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ").concat(n||""),children:t})},x=e=>{let{placeholder:t,value:r,onChange:s,disabled:l=!1,className:n}=e;return(0,a.jsx)("input",{type:"text",placeholder:t,defaultValue:r,onChange:e=>{if(s)try{Function("event",s)(e)}catch(e){console.error("Error executing onChange:",e)}},disabled:l,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 ".concat(n||"")})},h=e=>{let{text:t,variant:r="default",className:s}=e,l={default:"bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200",success:"bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200",warning:"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200",error:"bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-200",info:"bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200"},n=l[r]||l.default;return(0,a.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md text-xs font-medium ".concat(n," ").concat(s||""),children:t})},g={card:e=>{let{title:t,children:r,className:s}=e;return(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border dark:border-gray-700 shadow-sm p-4 ".concat(s||""),children:[t&&(0,a.jsx)("h3",{className:"text-lg font-semibold mb-3 text-gray-900 dark:text-white",children:t}),r]})},stack:e=>{let{direction:t="column",spacing:r=2,align:s="start",children:l,className:n}=e;return(0,a.jsx)("div",{className:"flex ".concat("row"===t?"flex-row":"flex-col"," ").concat(r>0?"gap-".concat(r):""," ").concat("center"===s?"items-center":"end"===s?"items-end":"stretch"===s?"items-stretch":"items-start"," ").concat(n||""),children:l})},heading:e=>{let{level:t="h2",text:r,className:s}=e,l={h1:"text-3xl font-bold",h2:"text-2xl font-semibold",h3:"text-xl font-semibold",h4:"text-lg font-medium",h5:"text-base font-medium",h6:"text-sm font-medium"},n=l[t]||l.h2;return(0,a.jsx)(t,{className:"".concat(n," text-gray-900 dark:text-white ").concat(s||""),children:r})},text:e=>{let{content:t,variant:r="body",className:s}=e,l={body:"text-gray-700 dark:text-gray-300",muted:"text-gray-500 dark:text-gray-400",code:"font-mono text-sm bg-gray-100 dark:bg-gray-900 px-1 py-0.5 rounded"},n=l[r]||l.body;return(0,a.jsx)("p",{className:"".concat(n," ").concat(s||""),children:t})},button:u,input:x,badge:h,separator:e=>{let{orientation:t="horizontal",className:r}=e;return(0,a.jsx)("div",{className:"bg-gray-200 dark:bg-gray-700 ".concat("horizontal"===t?"h-px w-full":"w-px h-full"," ").concat(r||"")})},"translation-result":e=>{let{original:t,translated:r,sourceLang:s,targetLang:l,className:n}=e;return(0,a.jsxs)("div",{className:"translation-result bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-900/20 dark:to-purple-900/20 rounded-lg p-4 border border-blue-200 dark:border-blue-800 ".concat(n||""),children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,a.jsx)("span",{className:"text-lg",children:"\uD83C\uDF10"}),(0,a.jsx)("h4",{className:"font-semibold text-gray-900 dark:text-white",children:"Translation"}),s&&l&&(0,a.jsxs)("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:[s," → ",l]})]}),(0,a.jsxs)("div",{className:"grid md:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"Original"}),(0,a.jsx)("p",{className:"text-gray-800 dark:text-gray-200",children:t})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"Translated"}),(0,a.jsx)("p",{className:"text-gray-800 dark:text-gray-200 font-medium",children:r})]})]})]})},"novel-list":e=>{let{novels:t,className:r}=e;return(0,a.jsx)("div",{className:"novel-list space-y-3 ".concat(r||""),children:t.map(e=>{var t;return(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg border dark:border-gray-700 p-4 hover:shadow-md transition-shadow cursor-pointer",children:[(0,a.jsx)("h4",{className:"font-semibold text-lg text-gray-900 dark:text-white mb-1",children:e.title}),e.author&&(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-2",children:["By ",e.author]}),e.description&&(0,a.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-300 mb-2 line-clamp-2",children:e.description}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[e.chapterCount&&(0,a.jsx)(h,{text:"".concat(e.chapterCount," chapters"),variant:"info"}),null===(t=e.tags)||void 0===t?void 0:t.map(e=>(0,a.jsx)(h,{text:e,variant:"default"},e))]})]},e.id)})})},"chapter-reader":e=>{let{novelTitle:t,chapterTitle:r,content:s,chapterNumber:l,totalChapters:n,className:o}=e;return(0,a.jsxs)("div",{className:"chapter-reader bg-white dark:bg-gray-800 rounded-lg border dark:border-gray-700 p-6 ".concat(o||""),children:[(0,a.jsxs)("div",{className:"border-b dark:border-gray-700 pb-4 mb-4",children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-1",children:t}),(0,a.jsx)("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:r}),l&&n&&(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:["Chapter ",l," of ",n]})]}),(0,a.jsx)("div",{className:"prose dark:prose-invert max-w-none",children:(0,a.jsx)("p",{className:"text-gray-700 dark:text-gray-300 whitespace-pre-wrap leading-relaxed",children:s})})]})},"mcp-tool-call":e=>{let{tool:t,status:r,args:s,result:l,error:n,className:o}=e,i={pending:{icon:"⏳",color:"text-yellow-600",bg:"bg-yellow-50 dark:bg-yellow-900/20 border-yellow-300 dark:border-yellow-700"},running:{icon:"\uD83D\uDD04",color:"text-blue-600",bg:"bg-blue-50 dark:bg-blue-900/20 border-blue-300 dark:border-blue-700"},success:{icon:"✅",color:"text-green-600",bg:"bg-green-50 dark:bg-green-900/20 border-green-300 dark:border-green-700"},error:{icon:"❌",color:"text-red-600",bg:"bg-red-50 dark:bg-red-900/20 border-red-300 dark:border-red-700"}},c=i[r]||i.success;return(0,a.jsxs)("div",{className:"mcp-tool-call border-l-4 p-3 rounded-r ".concat(c.bg," ").concat(o||""),children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,a.jsx)("span",{className:"text-lg",children:c.icon}),(0,a.jsx)("span",{className:"font-mono text-sm font-medium ".concat(c.color),children:t})]}),s&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"Arguments:"}),(0,a.jsx)("pre",{className:"text-xs bg-gray-100 dark:bg-gray-900 p-2 rounded overflow-x-auto",children:JSON.stringify(s,null,2)})]}),l&&"success"===r&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"Result:"}),(0,a.jsx)("pre",{className:"text-xs bg-gray-100 dark:bg-gray-900 p-2 rounded overflow-x-auto",children:JSON.stringify(l,null,2)})]}),n&&"error"===r&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsx)("p",{className:"text-xs text-red-600 dark:text-red-400 mb-1",children:"Error:"}),(0,a.jsx)("p",{className:"text-sm text-red-700 dark:text-red-300",children:n})]})]})},"login-panel":e=>{let{server:t,email:r,className:s}=e;return(0,a.jsxs)("div",{className:"login-panel bg-white dark:bg-gray-800 rounded-lg border dark:border-gray-700 p-6 ".concat(s||""),children:[(0,a.jsxs)("div",{className:"text-center mb-6",children:[(0,a.jsx)("div",{className:"text-4xl mb-2",children:"\uD83D\uDD10"}),(0,a.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:t}),(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:"Sign in to continue"})]}),(0,a.jsxs)("form",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Email"}),(0,a.jsx)(x,{type:"email",placeholder:"your@email.com",defaultValue:r})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Password"}),(0,a.jsx)(x,{type:"password",placeholder:"••••••••"})]}),(0,a.jsx)(u,{label:"Sign In",variant:"primary",className:"w-full"})]})]})},"code-block":e=>{let{code:t,language:r="text",inline:s=!1,className:l}=e;return s?(0,a.jsx)("code",{className:"bg-gray-100 dark:bg-gray-900 px-1.5 py-0.5 rounded text-sm font-mono text-gray-800 dark:text-gray-200 ".concat(l||""),children:t}):(0,a.jsxs)("div",{className:"code-block bg-gray-900 dark:bg-gray-950 rounded-lg p-4 overflow-x-auto ".concat(l||""),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400 uppercase",children:r}),(0,a.jsx)("button",{onClick:()=>navigator.clipboard.writeText(t),className:"text-xs text-gray-400 hover:text-white transition-colors",children:"Copy"})]}),(0,a.jsx)("pre",{className:"text-sm text-gray-100 font-mono",children:(0,a.jsx)("code",{children:t})})]})},"data-table":e=>{let{columns:t,rows:r,className:s}=e;return(0,a.jsx)("div",{className:"data-table overflow-x-auto ".concat(s||""),children:(0,a.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,a.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-800",children:(0,a.jsx)("tr",{children:t.map(e=>(0,a.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:e.label},e.key))})}),(0,a.jsx)("tbody",{className:"bg-white dark:bg-gray-900 divide-y divide-gray-200 dark:divide-gray-700",children:r.map((e,r)=>(0,a.jsx)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-800",children:t.map(t=>{var r;return(0,a.jsx)("td",{className:"px-4 py-3 text-sm text-gray-700 dark:text-gray-300",children:String(null!==(r=e[t.key])&&void 0!==r?r:"")},t.key)})},r))})]})})}};function m(e){let{spec:t,specs:l,data:n,toolCalls:o,error:i,isLoading:c,className:d=""}=e,u=(0,s.useMemo)(()=>{let e=[];if(t&&e.push(t),l&&l.length>0&&e.push(...l),n&&"object"==typeof n&&null!==n&&"type"in n&&e.push(n),o&&o.length>0){let{specFromToolCall:t}=r(1803);for(let r of o){let a=t(r.tool,r.result);a&&e.push(a)}}return e},[t,l,n,o]);return c?(0,a.jsx)("div",{className:"json-renderer-loading ".concat(d),children:(0,a.jsxs)("div",{className:"flex items-center gap-3 p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-2 border-blue-500 border-t-transparent"}),(0,a.jsx)("span",{className:"text-blue-700 dark:text-blue-300",children:"Generating UI..."})]})}):i?(0,a.jsx)("div",{className:"json-renderer-error ".concat(d),children:(0,a.jsxs)("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-red-700 dark:text-red-300",children:[(0,a.jsx)("span",{children:"⚠️"}),(0,a.jsx)("span",{className:"font-medium",children:"Render Error"})]}),(0,a.jsx)("p",{className:"mt-2 text-sm text-red-600 dark:text-red-400",children:i.message})]})}):0===u.length?null:(0,a.jsx)("div",{className:"json-renderer space-y-4 ".concat(d),children:u.map((e,t)=>{let r=e.type,s=g[r];return s?(0,a.jsx)(s,{...e},t):(0,a.jsxs)("div",{className:"p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg border border-yellow-200 dark:border-yellow-800",children:[(0,a.jsxs)("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:["Unknown component type: ",r]}),(0,a.jsx)("pre",{className:"mt-2 text-xs bg-gray-100 dark:bg-gray-900 p-2 rounded overflow-x-auto",children:JSON.stringify(e,null,2)})]},t)})})}function p(){let[e,t]=(0,s.useState)([]),[r,i]=(0,s.useState)(""),{sendMessage:u,isLoading:x,response:h,toolCalls:g,error:p,abort:b}=(0,l.RJ)(),y=async r=>{i(r),t(e=>[...e,{role:"user",content:r}]),await u(r,e),t(e=>[...e,{role:"user",content:r},{role:"assistant",content:h,toolCalls:g.length>0?g:void 0}]),i("")},f=(0,s.useCallback)(()=>{b(),r&&t(e=>[...e,{role:"user",content:r}]),(h||g.length>0)&&t(e=>[...e,{role:"assistant",content:h,toolCalls:g.length>0?g:void 0}]),i("")},[b,r,h,g]);return(0,a.jsxs)("div",{className:"flex flex-col h-screen bg-gray-50 dark:bg-gray-900",children:[(0,a.jsx)(c,{}),(0,a.jsxs)("main",{className:"flex-1 overflow-hidden flex",children:[(0,a.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,a.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:0===e.length?(0,a.jsx)("div",{className:"flex items-center justify-center h-full text-gray-400",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("h2",{className:"text-2xl font-semibold mb-2",children:"欢迎使用 AI MCP Web UI"}),(0,a.jsx)("p",{children:"开始与 AI 对话,支持 MCP 工具调用和生成式 UI"}),(0,a.jsxs)("div",{className:"mt-4 text-sm space-y-1",children:[(0,a.jsx)("p",{children:"✨ 支持 json-render 动态组件渲染"}),(0,a.jsx)("p",{children:"\uD83D\uDD27 MCP 工具调用结果可视化"}),(0,a.jsx)("p",{children:"\uD83C\uDF10 翻译、小说阅读等专用组件"})]})]})}):(0,a.jsxs)("div",{className:"space-y-4",children:[e.map((e,t)=>(0,a.jsxs)("div",{children:[(0,a.jsx)(o,{role:e.role,content:e.content}),e.toolCalls&&e.toolCalls.length>0&&(0,a.jsx)("div",{className:"mt-3 ml-4",children:(0,a.jsx)(m,{toolCalls:e.toolCalls,className:"max-w-2xl"})}),e.specs&&e.specs.length>0&&(0,a.jsx)("div",{className:"mt-3 ml-4",children:(0,a.jsx)(m,{specs:e.specs,className:"max-w-2xl"})})]},t)),x&&h&&(0,a.jsx)(o,{role:"assistant",content:h,isLoading:!0}),x&&g.length>0&&(0,a.jsx)("div",{className:"ml-4 mt-3",children:(0,a.jsx)(m,{toolCalls:g,isLoading:!0,className:"max-w-2xl"})}),p&&(0,a.jsx)("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded",children:p})]})}),(0,a.jsx)("div",{className:"border-t dark:border-gray-700 p-4 bg-white dark:bg-gray-800",children:(0,a.jsx)(n,{onSend:y,isLoading:x,onAbort:f})})]}),(g.length>0||x)&&(0,a.jsx)(d,{toolCalls:g,isLoading:x})]})]})}},8652:function(e,t,r){"use strict";r.d(t,{aC:function(){return c},RJ:function(){return i}});var a=r(2265);let s=r(5126).n9;class l{setSession(e){this.sessionId=e}setMcpTokens(e){this.mcpTokens={...e}}getHeaders(){let e={"Content-Type":"application/json"};return this.sessionId&&(e["X-Session-ID"]=this.sessionId),Object.keys(this.mcpTokens).length>0&&(e["X-MCP-Tokens"]=JSON.stringify(this.mcpTokens)),e}async request(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r="".concat(this.baseUrl).concat(e),a=await fetch(r,{...t,headers:{...this.getHeaders(),...t.headers}});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||e.detail||"API request failed")}return a.json()}async health(){return this.request("/api/health")}async chat(e){var t;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.request("/api/chat",{method:"POST",body:(t={message:e,history:r},s.stringify(t))})}chatStream(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=new URL("".concat(this.baseUrl,"/api/chat/stream")),a={};return this.sessionId&&(a["X-Session-ID"]=this.sessionId),Object.keys(this.mcpTokens).length>0&&(a["X-MCP-Tokens"]=JSON.stringify(this.mcpTokens)),new n(r.toString(),{headers:a,method:"POST",body:JSON.stringify({message:e,history:t})})}async chatStreamFetch(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2?arguments[2]:void 0,a=arguments.length>3?arguments[3]:void 0,s=arguments.length>4?arguments[4]:void 0,l="".concat(this.baseUrl,"/api/chat/stream"),n=new AbortController;try{var o;let a=await fetch(l,{method:"POST",headers:this.getHeaders(),body:JSON.stringify({message:e,history:t}),signal:n.signal});if(!a.ok)throw Error("HTTP error! status: ".concat(a.status));let i=null===(o=a.body)||void 0===o?void 0:o.getReader(),c=new TextDecoder;if(!i)throw Error("Response body is null");let d="";for(;;){let{done:e,value:t}=await i.read();if(e){null==s||s();break}let a=(d+=c.decode(t,{stream:!0})).split("\n");for(let e of(d=a.pop()||"",a))if(e.startsWith("data: ")){let t=e.slice(6);try{r(new MessageEvent("message",{data:t}))}catch(e){console.error("Error parsing SSE data:",e)}}}}catch(e){e instanceof Error&&"AbortError"!==e.name&&(null==a||a(e))}return()=>n.abort()}async listMcpServers(){return this.request("/api/mcp/servers")}async listMcpTools(){return this.request("/api/mcp/tools")}async login(e,t){let r=await this.request("/api/auth/login",{method:"POST",body:JSON.stringify({email:e,password:t})});return r.session_id&&this.setSession(r.session_id),r}async adminLogin(e,t){let r=await this.request("/api/auth/admin-login",{method:"POST",body:JSON.stringify({email:e,password:t})});return r.session_id&&this.setSession(r.session_id),r}async register(e,t,r){return this.request("/api/auth/register",{method:"POST",body:JSON.stringify({email:e,username:t,password:r})})}async logout(){let e=await this.request("/api/auth/logout",{method:"POST",body:JSON.stringify({session_id:this.sessionId})});return this.sessionId=null,this.mcpTokens={},e}async authStatus(){return this.request("/api/auth/status")}constructor(e="http://localhost:8080"){this.sessionId=null,this.mcpTokens={},this.baseUrl=e}}class n{addEventListener(e,t){"message"===e&&(this.onmessage=t)}close(){var e;null===(e=this.eventSource)||void 0===e||e.close()}constructor(e,t){this.onmessage=null,this.onerror=null,this.eventSource=null,this.url=e,this.headers=t.headers}}let o=new l;function i(){let[e,t]=(0,a.useState)(!1),[r,s]=(0,a.useState)(""),[l,n]=(0,a.useState)([]),[i,c]=(0,a.useState)(null),d=(0,a.useRef)(null),u=(0,a.useCallback)(async function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];t(!0),s(""),n([]),c(null);try{d.current=await o.chatStreamFetch(e,r,e=>{try{let t=JSON.parse(e.data);x(t)}catch(e){console.error("Failed to parse SSE data:",e)}},e=>{c(e.message)},()=>{t(!1)})}catch(e){c(e instanceof Error?e.message:"Unknown error"),t(!1)}},[]),x=e=>{switch(e.type){case"token":e.text&&s(t=>t+e.text);break;case"tool_call":e.tool&&n(t=>[...t,{tool:e.tool,result:e.args}]);break;case"tool_done":e.tool&&n(t=>{let r=[...t],a=r.findLastIndex(t=>t.tool===e.tool);return a>=0&&(r[a]={tool:e.tool,result:e.result}),r});break;case"complete":e.response&&!r&&s(e.response),t(!1);break;case"error":c(e.error||"Unknown error"),t(!1)}};return{sendMessage:u,abort:(0,a.useCallback)(()=>{var e;null===(e=d.current)||void 0===e||e.call(d),t(!1)},[]),isLoading:e,response:r,toolCalls:l,error:i}}function c(){let[e,t]=(0,a.useState)(!1),[r,s]=(0,a.useState)(null),[l,n]=(0,a.useState)(!1),i=(0,a.useCallback)(async(e,r)=>{n(!0);try{let a=await o.login(e,r);if(a.success)return t(!0),s(a.username),a;throw Error("Login failed")}finally{n(!1)}},[]);return{isAuthenticated:e,username:r,isLoading:l,login:i,register:(0,a.useCallback)(async(e,t,r)=>{n(!0);try{return await o.register(e,t,r)}finally{n(!1)}},[]),logout:(0,a.useCallback)(async()=>{n(!0);try{await o.logout(),t(!1),s(null)}finally{n(!1)}},[]),checkStatus:(0,a.useCallback)(async()=>{try{let e=await o.authStatus();return t(e.authenticated),s(e.username||null),e}catch(e){return t(!1),s(null),null}},[])}}},1803:function(e,t,r){"use strict";r.r(t),r.d(t,{BadgeSchema:function(){return d},ButtonSchema:function(){return i},CardSchema:function(){return s},ChapterReaderSchema:function(){return g},CodeBlockSchema:function(){return b},ComponentSchema:function(){return f},DataTableSchema:function(){return y},HeadingSchema:function(){return n},InputSchema:function(){return c},LoginPanelSchema:function(){return p},McpToolCallSchema:function(){return m},NovelListSchema:function(){return h},SeparatorSchema:function(){return u},StackSchema:function(){return l},TextSchema:function(){return o},TranslationResultSchema:function(){return x},specFromToolCall:function(){return k},specsFromToolCalls:function(){return v},validateComponentSpec:function(){return j}});var a=r(19);let s=a.Ryn({type:a.i0J("card"),title:a.Z_8().optional(),children:a.IXX(a.YjB()).optional(),className:a.Z_8().optional()}),l=a.Ryn({type:a.i0J("stack"),direction:a.KmV(["row","column"]).optional(),spacing:a.Rxh().optional(),align:a.KmV(["start","center","end","stretch"]).optional(),children:a.IXX(a.YjB()).optional(),className:a.Z_8().optional()}),n=a.Ryn({type:a.i0J("heading"),level:a.KmV(["h1","h2","h3","h4","h5","h6"]).optional(),text:a.Z_8(),className:a.Z_8().optional()}),o=a.Ryn({type:a.i0J("text"),content:a.Z_8(),variant:a.KmV(["body","muted","code"]).optional(),className:a.Z_8().optional()}),i=a.Ryn({type:a.i0J("button"),label:a.Z_8(),variant:a.KmV(["default","primary","secondary","ghost","danger"]).optional(),onClick:a.Z_8().optional(),disabled:a.O72().optional(),className:a.Z_8().optional()}),c=a.Ryn({type:a.i0J("input"),placeholder:a.Z_8().optional(),value:a.Z_8().optional(),onChange:a.Z_8().optional(),disabled:a.O72().optional(),className:a.Z_8().optional()}),d=a.Ryn({type:a.i0J("badge"),text:a.Z_8(),variant:a.KmV(["default","success","warning","error","info"]).optional(),className:a.Z_8().optional()}),u=a.Ryn({type:a.i0J("separator"),orientation:a.KmV(["horizontal","vertical"]).optional(),className:a.Z_8().optional()}),x=a.Ryn({type:a.i0J("translation-result"),original:a.Z_8(),translated:a.Z_8(),sourceLang:a.Z_8().optional(),targetLang:a.Z_8().optional(),className:a.Z_8().optional()}),h=a.Ryn({type:a.i0J("novel-list"),novels:a.IXX(a.Ryn({id:a.Z_8(),title:a.Z_8(),author:a.Z_8().optional(),description:a.Z_8().optional(),chapterCount:a.Rxh().optional(),tags:a.IXX(a.Z_8()).optional()})),onSelect:a.Z_8().optional(),className:a.Z_8().optional()}),g=a.Ryn({type:a.i0J("chapter-reader"),novelTitle:a.Z_8(),chapterTitle:a.Z_8(),content:a.Z_8(),chapterNumber:a.Rxh().optional(),totalChapters:a.Rxh().optional(),onPrev:a.Z_8().optional(),onNext:a.Z_8().optional(),className:a.Z_8().optional()}),m=a.Ryn({type:a.i0J("mcp-tool-call"),tool:a.Z_8(),status:a.KmV(["pending","running","success","error"]),args:a.YjB().optional(),result:a.YjB().optional(),error:a.Z_8().optional(),timestamp:a.Z_8().optional(),className:a.Z_8().optional()}),p=a.Ryn({type:a.i0J("login-panel"),server:a.Z_8(),email:a.Z_8().optional(),onLogin:a.Z_8().optional(),loading:a.O72().optional(),className:a.Z_8().optional()}),b=a.Ryn({type:a.i0J("code-block"),code:a.Z_8(),language:a.Z_8().optional(),inline:a.O72().optional(),className:a.Z_8().optional()}),y=a.Ryn({type:a.i0J("data-table"),columns:a.IXX(a.Ryn({key:a.Z_8(),label:a.Z_8(),sortable:a.O72().optional()})),rows:a.IXX(a.IMB(a.Z_8(),a.YjB())),sortable:a.O72().optional(),onSort:a.Z_8().optional(),className:a.Z_8().optional()}),f=a.VKR("type",[s,l,n,o,i,c,d,u,x,h,g,m,p,b,y]);function j(e){let t=f.safeParse(e);return t.success?t.data:null}function k(e,t){switch(e){case"translate_text":return{type:"translation-result",original:t.original||"",translated:t.translated||"",sourceLang:t.source_lang,targetLang:t.target_lang};case"get_novels":return{type:"novel-list",novels:t.novels||[]};case"get_chapter":return{type:"chapter-reader",novelTitle:t.novel_title||"Unknown Novel",chapterTitle:t.chapter_title||"Chapter ".concat(t.chapter_number||1),content:t.content||"",chapterNumber:t.chapter_number,totalChapters:t.total_chapters};case"mcp_tool_call":return{type:"mcp-tool-call",tool:t.tool||e,status:t.status||"success",args:t.args,result:t.result,error:t.error,timestamp:t.timestamp};case"login":return{type:"login-panel",server:t.server||"Novel Platform",email:t.email};default:return{type:"code-block",code:JSON.stringify(t,null,2),language:"json"}}}function v(e){return e.map(e=>{let{tool:t,result:r}=e;return k(t,r)}).filter(e=>null!==e)}}},function(e){e.O(0,[126,210,971,117,744],function(){return e(e.s=6161)}),_N_E=e.O()}]);