super-agent-sdk 1.0.6 → 1.0.8

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/widget.cjs CHANGED
@@ -1,13 +1,15 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),ve=require("react-dom/client"),e=require("react/jsx-runtime");function U(a){const{sdk:t,sessionId:s,onSessionCreated:r,onStreamStart:n,onStreamEnd:o,onError:i,onMessageSend:l}=a,[d,p]=c.useState([]),[f,u]=c.useState("ready"),[m,w]=c.useState(null),y=c.useRef(null),g=c.useRef(!1),v=c.useRef(s);v.current=s;const x=c.useCallback(I=>{if(g.current)return;g.current=!0,l==null||l(I);const A={id:`user_${Date.now()}`,role:"user",parts:[{type:"text",content:I}],timestamp:Date.now()},k=`assistant_${Date.now()}`,T={id:k,role:"assistant",parts:[],timestamp:Date.now()};p(S=>[...S,A,T]),u("submitted"),w(null);const D=S=>{let M="",E="",$=[],N=!1;const L=()=>{const b=[...$];if(M){const O=b.findIndex(P=>P.type==="thinking");O>=0?b[O]={type:"thinking",content:M}:b.unshift({type:"thinking",content:M})}if(E){const O=b.findLastIndex(P=>P.type==="text");O>=0?b[O]={type:"text",content:E}:b.push({type:"text",content:E})}p(O=>O.map(P=>P.id===k?{...P,parts:b}:P))};y.current=t.chat({sessionId:S,message:I,stream:!0,onMessage:b=>{switch(N||(N=!0,u("streaming")),b.type){case"thinking":M+=b.content;break;case"ai":E+=b.content;break;case"tool_call":$.push({type:"tool_call",toolName:b.toolName,toolCallId:b.toolCallId,args:b.args??"{}"});break;case"tool_result":$.push({type:"tool_result",toolName:b.toolName??"",toolCallId:b.toolCallId,content:b.content,artifacts:b.artifacts,renderMode:b.renderMode,html:b.html}),E&&($.push({type:"text",content:E}),E="");break;case"interrupt":b.interrupt&&$.push({type:"interrupt",interrupt:b.interrupt,resolved:!1});break}L()},onDone:b=>{(E||$.length>0||M)&&L(),b.messageId&&p(O=>O.map(P=>P.id===k?{...P,id:b.messageId}:P)),b.sessionId&&b.sessionId!==v.current&&(r==null||r(b.sessionId)),o==null||o(b.sessionId||S),u("ready"),g.current=!1,y.current=null},onError:b=>{$.push({type:"error",content:b.message}),L(),w(b),u("error"),i==null||i(b),g.current=!1,y.current=null}}),n==null||n(S)};v.current?D(v.current):t.createSession().then(S=>{v.current=S,r==null||r(S),D(S)}).catch(S=>{w(S instanceof Error?S:new Error(String(S))),u("error"),i==null||i(S instanceof Error?S:new Error(String(S))),g.current=!1})},[t,r,n,o,i,l]),h=c.useCallback(()=>{var I;(I=y.current)==null||I.abort(),y.current=null,u("ready"),g.current=!1},[]),C=c.useCallback(()=>{if(g.current)return;const I=d.findLastIndex(k=>k.role==="user");if(I<0)return;const A=d[I].parts.filter(k=>k.type==="text").map(k=>k.content).join("");p(k=>k.slice(0,I)),x(A)},[d,x]),z=c.useCallback((I,A)=>{p(N=>N.map(L=>({...L,parts:L.parts.map(b=>b.type==="interrupt"&&b.interrupt.interruptId===I?{...b,resolved:!0,response:A}:b)})));const k=v.current;if(!k)return;const T=`assistant_${Date.now()}`,D={id:T,role:"assistant",parts:[],timestamp:Date.now()};p(N=>[...N,D]),u("streaming");let S="",M="",E=[];const $=()=>{const N=[...E];if(S){const L=N.findIndex(b=>b.type==="thinking");L>=0?N[L]={type:"thinking",content:S}:N.unshift({type:"thinking",content:S})}if(M){const L=N.findLastIndex(b=>b.type==="text");L>=0?N[L]={type:"text",content:M}:N.push({type:"text",content:M})}p(L=>L.map(b=>b.id===T?{...b,parts:N}:b))};t.respondInterrupt(I,k,A,N=>{switch(N.type){case"thinking":S+=N.content;break;case"ai":M+=N.content;break;case"tool_call":E.push({type:"tool_call",toolName:N.toolName,toolCallId:N.toolCallId,args:N.args??"{}"});break;case"tool_result":E.push({type:"tool_result",toolName:N.toolName??"",toolCallId:N.toolCallId,content:N.content,artifacts:N.artifacts,renderMode:N.renderMode,html:N.html}),M&&(E.push({type:"text",content:M}),M="");break;case"interrupt":N.interrupt&&E.push({type:"interrupt",interrupt:N.interrupt,resolved:!1});break;case"done":N.messageId&&p(L=>L.map(b=>b.id===T?{...b,id:N.messageId}:b)),u("ready");break}$()},N=>{E.push({type:"error",content:N.message}),$(),w(N),u("error"),i==null||i(N)}).catch(N=>{i==null||i(N instanceof Error?N:new Error(String(N))),u("error")})},[t,i]);return{messages:d,status:f,error:m,sendMessage:x,stop:h,regenerate:C,setMessages:p,respondToInterrupt:z}}const _="sa_active_conversation";function K(){try{return localStorage.getItem(_)}catch{return null}}function we(a){try{a?localStorage.setItem(_,a):localStorage.removeItem(_)}catch{}}function X(a){const{sdk:t,onConversationChange:s}=a,[r,n]=c.useState([]),[o,i]=c.useState(()=>K()),[l,d]=c.useState(!1),p=c.useRef(!0);c.useEffect(()=>()=>{p.current=!1},[]);const f=c.useCallback(x=>{i(x),we(x),x&&(s==null||s(x))},[s]),u=c.useCallback(async()=>{d(!0);try{const x=await t.listConversations({page:1,size:100});if(!p.current)return;n(x.items);const h=K();h&&!x.items.find(C=>C.sessionId===h)&&f(null)}catch{}finally{p.current&&d(!1)}},[t,f]),m=c.useCallback(async x=>(f(x),await t.getMessages(x)),[t,f]),w=c.useCallback(()=>{f(null)},[f]),y=c.useCallback(async x=>{await t.deleteConversation(x),n(h=>h.filter(C=>C.sessionId!==x)),o===x&&f(null)},[t,o,f]),g=c.useCallback(async(x,h)=>{await t.renameConversation(x,h),n(C=>C.map(z=>z.sessionId===x?{...z,title:h}:z))},[t]),{enabled:v=!0}=a;return c.useEffect(()=>{v&&u()},[v,u]),{conversations:r,activeConversationId:o,loading:l,loadConversations:u,switchConversation:m,newConversation:w,deleteConversation:y,renameConversation:g,setActiveConversationId:f}}function J(a){return!a&&a!==0?"":a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:`${(a/1024/1024).toFixed(1)} MB`}function G(a){return a==="pdf"?"PDF":a==="docx"?"DOC":a==="html"?"HTM":a.slice(0,3).toUpperCase()||"FILE"}function Z(a){if(!a)return[];const t=[];for(const s of a)s.type==="file"&&s.data&&t.push({id:s.data.id??"",type:s.data.fileType??s.data.type??"",filename:s.data.name??s.data.filename??"",url:s.data.url??"",mime:s.data.mime,size:s.data.size,summary:s.data.summary});return t}async function H(a){try{const t=await fetch(a.url);if(!t.ok)throw new Error(`HTTP ${t.status}`);const s=await t.blob(),r=URL.createObjectURL(s),n=document.createElement("a");n.href=r,n.download=a.filename,document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(r),4e3)}catch{const t=document.createElement("a");t.href=a.url,t.download=a.filename,t.target="_blank",document.body.appendChild(t),t.click(),t.remove()}}const Q=c.createContext(null);function B(){const a=c.useContext(Q);if(!a)throw new Error("useChatContext must be used within ChatProvider");return a}function W({sdk:a,hooks:t,children:s}){const[r,n]=c.useState(!1),[o,i]=c.useState(!1),[l,d]=c.useState(null),[p,f]=c.useState(!1);c.useEffect(()=>{a.getToken().then(()=>{f(!0)}).catch(()=>{f(!0)})},[a]);const u=X({sdk:a,onConversationChange:t==null?void 0:t.onConversationChange,enabled:p}),m=U({sdk:a,sessionId:u.activeConversationId,onSessionCreated:k=>{u.setActiveConversationId(k),u.loadConversations()},onStreamStart:t==null?void 0:t.onStreamStart,onStreamEnd:k=>{var T;(T=t==null?void 0:t.onStreamEnd)==null||T.call(t,k),u.loadConversations()},onError:t==null?void 0:t.onError,onMessageSend:t==null?void 0:t.onMessageSend}),w=c.useCallback(async k=>{const T=await u.switchConversation(k);m.setMessages(T),n(!1)},[u,m]),y=c.useCallback(()=>{u.newConversation(),m.setMessages([]),n(!1)},[u,m]),g=c.useCallback(async k=>{await u.deleteConversation(k),u.activeConversationId===k&&m.setMessages([])},[u,m]);c.useEffect(()=>{u.activeConversationId&&m.messages.length===0&&a.getMessages(u.activeConversationId).then(k=>{m.setMessages(k)}).catch(()=>{})},[]);const v=c.useCallback(()=>{n(k=>!k)},[]),x=c.useCallback(()=>{i(k=>!k),d(k=>null)},[]),h=c.useCallback(k=>{d(k),i(!0)},[]),C=c.useMemo(()=>{const k=new Set,T=[];for(const D of m.messages)for(const S of D.parts)if(S.type==="tool_result"&&S.artifacts)for(const M of Z(S.artifacts)){const E=M.id||`${M.url}:${M.filename}`;k.has(E)||(k.add(E),T.push(M))}return T},[m.messages]),z=c.useCallback((k,T,D)=>{a.feedback(k,T,D).catch(()=>{})},[a]),I=c.useCallback(k=>{a.cancelFeedback(k).catch(()=>{})},[a]),A=c.useMemo(()=>({status:m.status,error:m.error,messages:m.messages,conversations:u.conversations,activeConversationId:u.activeConversationId,isThreadListOpen:r,isArtifactDrawerOpen:o,allArtifacts:C,activePreviewArtifact:l,sendMessage:m.sendMessage,stop:m.stop,regenerate:m.regenerate,switchConversation:w,newConversation:y,deleteConversation:g,renameConversation:u.renameConversation,toggleThreadList:v,toggleArtifactDrawer:x,openArtifactPreview:h,feedback:z,cancelFeedback:I,respondToInterrupt:m.respondToInterrupt}),[m.status,m.error,m.messages,m.sendMessage,m.stop,m.regenerate,m.respondToInterrupt,u.conversations,u.activeConversationId,u.renameConversation,r,o,C,l,w,y,g,v,x,h,z,I]);return e.jsx(Q.Provider,{value:A,children:s})}function j({name:a,size:t=16,color:s="currentColor",className:r,style:n}){return e.jsx("svg",{className:r,style:{width:t,height:t,fill:s,verticalAlign:"middle",...n},"aria-hidden":"true",children:e.jsx("use",{href:`#icon-${a}`})})}function ee({isOpen:a,onClick:t}){return e.jsx("button",{className:`sa-trigger ${a?"sa-trigger-open":""}`,onClick:t,children:a?e.jsx(j,{name:"x",size:24,color:"#fff"}):e.jsx(j,{name:"message-square",size:24,color:"#fff"})})}function ae({title:a,onClose:t,onToggleThreadList:s,showClose:r=!0,artifactCount:n=0,onToggleArtifactDrawer:o}){return e.jsxs("div",{className:"sa-header",children:[e.jsxs("div",{className:"sa-header-left",children:[e.jsx("div",{className:"sa-header-avatar",children:"A"}),e.jsxs("div",{className:"sa-header-info",children:[e.jsx("div",{className:"sa-header-title",children:a}),e.jsx("div",{className:"sa-header-status",children:"● Online"})]})]}),e.jsxs("div",{className:"sa-header-actions",children:[n>0&&o&&e.jsxs("button",{className:"sa-header-btn sa-header-btn-artifact",onClick:o,title:"会话产物",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{children:"产物"})]}),e.jsx("button",{className:"sa-header-btn",onClick:s,title:"会话列表",children:e.jsx(j,{name:"menu",size:16})}),r&&e.jsx("button",{className:"sa-header-btn",onClick:t,title:"关闭",children:e.jsx(j,{name:"x",size:16})})]})]})}function ke(a){const t=new Date,s=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=s-6*864e5,n=[],o=[],i=[];for(const d of a){const p=new Date(d.updateTime).getTime();p>=s?n.push(d):p>=r?o.push(d):i.push(d)}const l=[];return n.length&&l.push({label:"今天",items:n}),o.length&&l.push({label:"最近 7 天",items:o}),i.length&&l.push({label:"更早",items:i}),l}function te(){const{conversations:a,activeConversationId:t,switchConversation:s,newConversation:r,deleteConversation:n,renameConversation:o,isThreadListOpen:i,toggleThreadList:l}=B(),[d,p]=c.useState(null),[f,u]=c.useState(""),m=c.useCallback((g,v)=>{p(g),u(v??"")},[]),w=c.useCallback(g=>{f.trim()&&o(g,f.trim()),p(null)},[f,o]),y=c.useMemo(()=>ke(a),[a]);return i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-thread-list-overlay",onClick:l}),e.jsxs("div",{className:"sa-thread-list",children:[e.jsxs("div",{className:"sa-thread-list-header",children:[e.jsx("span",{className:"sa-thread-list-title",children:"会话记录"}),e.jsxs("button",{className:"sa-thread-list-new",onClick:r,children:[e.jsx(j,{name:"plus",size:14})," 新会话"]})]}),e.jsxs("div",{className:"sa-thread-list-items",children:[a.length===0&&e.jsx("div",{className:"sa-thread-list-empty",children:"暂无会话"}),y.map(g=>e.jsxs("div",{className:"sa-thread-group",children:[e.jsx("div",{className:"sa-thread-group-label",children:g.label}),g.items.map(v=>e.jsxs("div",{className:`sa-thread-item ${v.sessionId===t?"active":""}`,onClick:()=>s(v.sessionId),children:[d===v.sessionId?e.jsx("input",{className:"sa-thread-item-edit",value:f,onChange:x=>u(x.target.value),onBlur:()=>w(v.sessionId),onKeyDown:x=>{x.key==="Enter"&&w(v.sessionId),x.key==="Escape"&&p(null)},onClick:x=>x.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"sa-thread-item-title",onDoubleClick:x=>{x.stopPropagation(),m(v.sessionId,v.title)},children:v.title||"新会话"}),e.jsx("button",{className:"sa-thread-item-delete",onClick:x=>{x.stopPropagation(),n(v.sessionId)},title:"删除",children:e.jsx(j,{name:"trash2",size:14})})]},v.sessionId))]},g.label))]})]})]}):null}function se(a){const t=c.useRef(null),s=c.useRef(!1),r=c.useRef(0),n=c.useCallback(()=>{const i=t.current;if(!i)return;const{scrollTop:l,scrollHeight:d,clientHeight:p}=i,f=d-l-p<40;l<r.current&&!f&&(s.current=!0),f&&(s.current=!1),r.current=l},[]);c.useEffect(()=>{const i=t.current;if(i)return i.addEventListener("scroll",n,{passive:!0}),()=>i.removeEventListener("scroll",n)},[n]),c.useEffect(()=>{if(s.current)return;const i=t.current;i&&requestAnimationFrame(()=>{i.scrollTop=i.scrollHeight})},a);const o=c.useCallback(()=>{s.current=!1;const i=t.current;i&&(i.scrollTop=i.scrollHeight)},[]);return{containerRef:t,scrollToBottom:o}}function R(a){return a.value++}function F(a,t){const s=[],r=[],n=()=>{r.length>0&&(s.push(r.join("")),r.length=0)};let o=0;for(;o<a.length;){const i=a[o];if(i==="`"){const l=a.indexOf("`",o+1);if(l!==-1){n(),s.push(e.jsx("code",{className:"sa-inline-code",children:a.slice(o+1,l)},R(t))),o=l+1;continue}}else if(i==="*"&&a[o+1]==="*"){const l=a.indexOf("**",o+2);if(l!==-1){n(),s.push(e.jsx("strong",{children:F(a.slice(o+2,l),t)},R(t))),o=l+2;continue}}else if(i==="*"){const l=a.indexOf("*",o+1);if(l!==-1){n(),s.push(e.jsx("em",{children:F(a.slice(o+1,l),t)},R(t))),o=l+1;continue}}else if(i==="["){const l=a.indexOf("]",o+1);if(l!==-1&&a[l+1]==="("){const d=a.indexOf(")",l+2);if(d!==-1){const p=a.slice(o+1,l),f=a.slice(l+2,d);n(),s.push(e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",children:F(p,t)},R(t))),o=d+1;continue}}}r.push(i),o++}return n(),s}function ye(a,t){const s=[],r=a.split(`
2
- `);let n=0;const o=d=>d.trim()==="",i=d=>/^#{1,6}\s+\S/.test(d.trim()),l=d=>/^(?:[-*+]|\d+[.)])\s+\S/.test(d.trim());for(;n<r.length;){const d=r[n],p=d.trim();if(o(d)){n++;continue}if(i(d)){const u=p.match(/^(#{1,6})\s+(.*)$/);if(u){const w=`h${Math.min(u[1].length,6)}`;s.push(c.createElement(w,{key:R(t)},F(u[2],t)))}n++;continue}if(l(d)){const u=/^\d+[.)]/.test(p),m=[];for(;n<r.length&&l(r[n]);){const w=r[n].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);w&&m.push(e.jsx("li",{children:F(w[1],t)},R(t))),n++}s.push(u?e.jsx("ol",{className:"sa-list",children:m},R(t)):e.jsx("ul",{className:"sa-list",children:m},R(t)));continue}const f=[];for(;n<r.length&&!o(r[n])&&!i(r[n])&&!l(r[n]);)f.push(r[n]),n++;s.push(e.jsx("p",{className:"sa-text-paragraph",children:F(f.join(" "),t)},R(t)))}return s}function je(a){const t={value:0},s=[],r=a.split("```");for(let n=0;n<r.length;n++)if(n%2===0)s.push(...ye(r[n],t));else if(r[n].trim()!==""){let o=r[n].replace(/^\r?\n/,"");o=o.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/,""),o=o.replace(/\r?\n$/,""),s.push(e.jsx("pre",{className:"sa-code-block",children:e.jsx("code",{children:o})},R(t)))}return s}function re({content:a}){return e.jsx("div",{className:"sa-text-part",children:je(a)})}function ne({content:a}){const[t,s]=c.useState(!1);return e.jsxs("div",{className:"sa-thinking-part",onClick:()=>s(!t),children:[e.jsxs("div",{className:"sa-thinking-header",children:[e.jsx("span",{className:"sa-thinking-icon",children:e.jsx(j,{name:"brain",size:14})}),e.jsx("span",{className:"sa-thinking-label",children:"思考过程"}),e.jsx("span",{className:`sa-thinking-arrow ${t?"expanded":""}`,children:e.jsx(j,{name:"chevron-right",size:12})})]}),t&&e.jsx("div",{className:"sa-thinking-content",children:a})]})}function ie({toolName:a,toolCallId:t,args:s}){const[r,n]=c.useState(!1);let o=s;try{o=JSON.stringify(JSON.parse(s),null,2)}catch{}return e.jsxs("div",{className:"sa-tool-call-part",children:[e.jsxs("div",{className:"sa-tool-call-header",onClick:()=>n(!r),children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(j,{name:"zap",size:14})}),e.jsxs("span",{className:"sa-tool-name",children:["调用工具: ",a]}),e.jsx("span",{className:`sa-thinking-arrow ${r?"expanded":""}`,children:e.jsx(j,{name:"chevron-right",size:12})})]}),r&&e.jsx("pre",{className:"sa-tool-args",children:o})]})}function Ce({html:a}){const[t,s]=c.useState(null);return c.useEffect(()=>{let r=!1;return Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs")).then(n=>{r||s(n.default.sanitize(a,{FORCE_BODY:!0}))}),()=>{r=!0}},[a]),t===null?null:e.jsx("div",{className:"sa-tool-result-html",children:e.jsx("iframe",{srcDoc:t,className:"sa-tool-result-html-iframe",sandbox:"",title:"HTML 产物"})})}function oe({toolName:a,content:t,artifacts:s,renderMode:r,html:n,artifactPreview:o}){const{openArtifactPreview:i}=B(),l=Z(s);return e.jsxs("div",{className:"sa-tool-result-part",children:[e.jsxs("div",{className:"sa-tool-result-header",children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(j,{name:"circle-check",size:14,color:"#10b981"})}),e.jsx("span",{className:"sa-tool-result-label",children:a||"工具返回"})]}),r==="html"&&n?e.jsx(Ce,{html:n}):t?e.jsx("div",{className:"sa-tool-result-content",children:t}):null,l.length>0&&e.jsx("ul",{className:"sa-artifact-file-list",role:"list",children:l.map((d,p)=>e.jsxs("li",{className:"sa-artifact-file-card",onClick:o?()=>i(d):void 0,onKeyDown:o?f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),i(d))}:void 0,tabIndex:o?0:void 0,role:o?"button":void 0,"aria-label":o?`预览 ${d.filename}`:void 0,style:o?{cursor:"pointer"}:void 0,children:[e.jsx("div",{className:"sa-artifact-file-icon",children:e.jsx("span",{className:"sa-artifact-chip-type",children:G(d.type)})}),e.jsxs("div",{className:"sa-artifact-file-info",children:[e.jsx("span",{className:"sa-artifact-file-name",children:d.filename}),d.size!=null&&e.jsx("span",{className:"sa-artifact-file-size",children:J(d.size)})]}),o&&e.jsx("button",{className:"sa-artifact-file-download",title:"下载","aria-label":`下载 ${d.filename}`,onClick:f=>{f.stopPropagation(),H(d)},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})})]},d.id||`art-${p}`))})]})}function le({content:a,onRetry:t}){return e.jsxs("div",{className:"sa-error-part",children:[e.jsxs("div",{className:"sa-error-content",children:[e.jsx("span",{className:"sa-error-icon",children:e.jsx(j,{name:"triangle-alert",size:14})}),e.jsx("span",{children:a})]}),t&&e.jsx("button",{className:"sa-error-retry",onClick:t,children:"重试"})]})}function Ne({interrupt:a,onRespond:t}){var o,i;const s=a.options,r=(typeof(s==null?void 0:s[0])=="string"?s[0]:(o=s==null?void 0:s[0])==null?void 0:o.label)||"确认",n=(typeof(s==null?void 0:s[1])=="string"?s[1]:(i=s==null?void 0:s[1])==null?void 0:i.label)||"取消";return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"circle-alert",size:16,color:"#f59e0b"}),e.jsx("span",{children:a.content})]}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",onClick:()=>t({action:"confirm"}),children:[e.jsx(j,{name:"check",size:14})," ",r]}),e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>t({action:"cancel"}),children:[e.jsx(j,{name:"x",size:14})," ",n]})]})]})}function ze({interrupt:a,onRespond:t}){var l,d,p,f;const s=a.options,r=(typeof(s==null?void 0:s[0])=="string"?s[0]:(l=s==null?void 0:s[0])==null?void 0:l.label)||"批准",n=(typeof(s==null?void 0:s[1])=="string"?s[1]:(d=s==null?void 0:s[1])==null?void 0:d.label)||"拒绝",o=(typeof(s==null?void 0:s[2])=="string"?s[2]:(p=s==null?void 0:s[2])==null?void 0:p.label)||"跳过",i=((f=a.metadata)==null?void 0:f.showSkip)!==!1;return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"circle-alert",size:16,color:"#f59e0b"}),e.jsx("span",{children:a.content})]}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",onClick:()=>t({action:"approve"}),children:[e.jsx(j,{name:"check",size:14})," ",r]}),e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-danger",onClick:()=>t({action:"reject"}),children:[e.jsx(j,{name:"x",size:14})," ",n]}),i&&e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>t({action:"skip"}),children:[e.jsx(j,{name:"chevron-right",size:14})," ",o]})]})]})}function Se(a){return typeof a=="string"?{value:a,label:a}:a}function Ie({interrupt:a,onRespond:t}){const s=(a.options??[]).map(Se);return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"list",size:16,color:"#6366f1"}),e.jsx("span",{children:a.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:s.map(r=>e.jsxs("button",{className:`sa-interrupt-option ${r.danger?"sa-interrupt-option-danger":""}`,onClick:()=>t({action:"select",value:r.value}),children:[r.icon&&e.jsx(j,{name:r.icon,size:14}),e.jsx("span",{children:r.label}),r.description&&e.jsx("span",{className:"sa-interrupt-option-desc",children:r.description})]},r.value))})]})}function Te(a){return typeof a=="string"?{value:a,label:a}:a}function Me({interrupt:a,onRespond:t}){const s=(a.options??[]).map(Te),[r,n]=c.useState(new Set),o=i=>{n(l=>{const d=new Set(l);return d.has(i)?d.delete(i):d.add(i),d})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"list-checks",size:16,color:"#6366f1"}),e.jsx("span",{children:a.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:s.map(i=>e.jsxs("button",{className:`sa-interrupt-option ${r.has(i.value)?"sa-interrupt-option-selected":""}`,onClick:()=>o(i.value),children:[e.jsx(j,{name:r.has(i.value)?"square-check":"square",size:14}),e.jsx("span",{children:i.label})]},i.value))}),e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:r.size===0,onClick:()=>t({action:"submit",value:Array.from(r)}),children:[e.jsx(j,{name:"check",size:14})," 确认 (",r.size,")"]})})]})}function Ee({interrupt:a,onRespond:t}){const[s,r]=c.useState(""),n=a.inputType??"text",o=n==="textarea",i=()=>{a.required&&!s.trim()||t({action:"submit",value:s.trim()})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"text-cursor-input",size:16,color:"#6366f1"}),e.jsx("span",{children:a.content})]}),e.jsx("div",{className:"sa-interrupt-input-area",children:o?e.jsx("textarea",{className:"sa-interrupt-textarea",value:s,onChange:l=>r(l.target.value),placeholder:a.placeholder,maxLength:a.maxLength,rows:3}):e.jsx("input",{className:"sa-interrupt-input",type:n,value:s,onChange:l=>r(l.target.value),placeholder:a.placeholder,maxLength:a.maxLength,onKeyDown:l=>l.key==="Enter"&&i()})}),e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:a.required?!s.trim():!1,onClick:i,children:[e.jsx(j,{name:"check",size:14})," 提交"]})})]})}function Le({interrupt:a,onRespond:t}){const s=a.fields??[],[r,n]=c.useState(()=>{const d={};for(const p of s)d[p.name]=p.defaultValue??"";return d}),o=(d,p)=>{n(f=>({...f,[d]:p}))},i=s.every(d=>!d.required||r[d.name]),l=()=>{i&&t({action:"submit",value:r})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(j,{name:"file-text",size:16,color:"#6366f1"}),e.jsx("span",{children:a.content})]}),e.jsx("div",{className:"sa-interrupt-form",children:s.map(d=>e.jsxs("div",{className:"sa-interrupt-form-field",children:[e.jsxs("label",{className:"sa-interrupt-form-label",children:[d.label,d.required&&e.jsx("span",{className:"sa-interrupt-form-required",children:"*"})]}),De(d,r[d.name],p=>o(d.name,p))]},d.name))}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:!i,onClick:l,children:[e.jsx(j,{name:"check",size:14})," 提交"]}),e.jsx("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>t({action:"cancel"}),children:"取消"})]})]})}function De(a,t,s){switch(a.type){case"textarea":return e.jsx("textarea",{className:"sa-interrupt-textarea",value:t,onChange:r=>s(r.target.value),placeholder:a.placeholder,rows:3});case"select":return e.jsxs("select",{className:"sa-interrupt-select",value:t,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"请选择"}),(a.options??[]).map(r=>e.jsx("option",{value:r,children:r},r))]});default:return e.jsx("input",{className:"sa-interrupt-input",type:a.type,value:t,onChange:r=>s(r.target.value),placeholder:a.placeholder})}}function ce({interrupt:a,resolved:t,response:s,onRespond:r}){if(t)return e.jsxs("div",{className:"sa-interrupt-resolved",children:[e.jsx(j,{name:"circle-check",size:14,color:"#10b981"}),e.jsx("span",{children:Ae(a.interruptType,s)})]});switch(a.interruptType){case"confirm":return e.jsx(Ne,{interrupt:a,onRespond:r});case"approve":return e.jsx(ze,{interrupt:a,onRespond:r});case"select":return e.jsx(Ie,{interrupt:a,onRespond:r});case"multiSelect":return e.jsx(Me,{interrupt:a,onRespond:r});case"input":return e.jsx(Ee,{interrupt:a,onRespond:r});case"form":return e.jsx(Le,{interrupt:a,onRespond:r});default:return e.jsxs("div",{className:"sa-interrupt-unknown",children:["未知的交互类型: ",a.interruptType]})}}function Ae(a,t){if(!t)return"已完成";switch(t.action){case"confirm":return"已确认";case"cancel":return"已取消";case"select":return`已选择: ${t.value}`;case"submit":return"已提交";case"approve":return"已批准";case"reject":return"已拒绝";case"skip":return"已跳过";default:return"已完成"}}const Pe=[{value:1,label:"事实错误"},{value:2,label:"逻辑问题"},{value:3,label:"不相关"},{value:4,label:"信息过时"},{value:5,label:"冗长啰嗦"},{value:6,label:"难以理解"}];function de({message:a,onCopy:t,onRegenerate:s}){const{status:r,feedback:n,cancelFeedback:o}=B(),[i,l]=c.useState(null),[d,p]=c.useState(!1),[f,u]=c.useState(!1),m=c.useRef(null);if(r!=="ready"&&r!=="error")return null;const w=c.useCallback(()=>{t(),p(!0),setTimeout(()=>p(!1),2e3)},[t]),y=c.useCallback(()=>{i==="like"?(l(null),o(a.id)):(l("like"),u(!1),n(a.id,"like"))},[i,a.id,n,o]),g=c.useCallback(()=>{i==="dislike"?(l(null),u(!1),o(a.id)):u(!0)},[i,a.id,o]),v=c.useCallback((h,C)=>{l("dislike"),u(!1),n(a.id,"dislike",{reason:h,remark:(C==null?void 0:C.trim())||void 0})},[a.id,n]),x=c.useCallback(()=>{u(!1)},[]);return c.useEffect(()=>{if(!f)return;const h=z=>{m.current&&!m.current.contains(z.target)&&u(!1)},C=z=>{z.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",h),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",C)}},[f]),e.jsxs("div",{className:"sa-action-bar",children:[e.jsxs("button",{className:"sa-action-btn",onClick:w,title:"复制",children:[e.jsx(j,{name:d?"circle-check":"copy",size:14})," ",d?"已复制":"复制"]}),e.jsxs("button",{className:"sa-action-btn",onClick:s,title:"重新生成",children:[e.jsx(j,{name:"refresh-cw",size:14})," 重新生成"]}),e.jsx("span",{className:"sa-action-divider"}),e.jsx("button",{className:`sa-action-btn ${i==="like"?"sa-action-btn-active":""}`,onClick:y,title:"有用","aria-label":"点赞",children:e.jsx(j,{name:"thumbs-up",size:14})}),e.jsx("button",{className:`sa-action-btn ${i==="dislike"?"sa-action-btn-active":""}`,onClick:g,title:"无用","aria-label":"踩","aria-expanded":f,"aria-haspopup":"dialog",children:e.jsx(j,{name:"thumbs-down",size:14})}),f&&e.jsx("div",{ref:m,children:e.jsx($e,{onSubmit:v,onCancel:x})})]})}function $e({onSubmit:a,onCancel:t}){const[s,r]=c.useState(void 0),[n,o]=c.useState("");return e.jsxs("div",{className:"sa-dislike-panel",children:[e.jsx("div",{className:"sa-dislike-panel-title",children:"请选择不满意的原因(可选)"}),e.jsx("div",{className:"sa-dislike-reasons",children:Pe.map(i=>e.jsx("button",{className:`sa-dislike-reason-btn ${s===i.value?"active":""}`,onClick:()=>r(s===i.value?void 0:i.value),children:i.label},i.value))}),e.jsx("textarea",{className:"sa-dislike-remark",placeholder:"补充描述(选填,≤500 字)",maxLength:500,value:n,onChange:i=>o(i.target.value),rows:2}),e.jsxs("div",{className:"sa-dislike-actions",children:[e.jsx("button",{className:"sa-dislike-submit",onClick:()=>a(s,n||void 0),children:"提交"}),e.jsx("button",{className:"sa-dislike-cancel",onClick:t,children:"取消"})]})]})}function V({src:a,role:t}){const s=t==="assistant"?"A":"U";return a?a.startsWith("http")||a.startsWith("/")||a.startsWith("data:")?e.jsx("div",{className:`sa-avatar sa-avatar-${t}`,children:e.jsx("img",{src:a,alt:t,style:{width:"100%",height:"100%",borderRadius:"inherit",objectFit:"cover"}})}):e.jsx("div",{className:`sa-avatar sa-avatar-${t}`,children:a}):e.jsx("div",{className:`sa-avatar sa-avatar-${t}`,children:s})}function pe({message:a,isStreaming:t,isLast:s,slots:r,avatar:n,artifactPreview:o}){const{regenerate:i,feedback:l,respondToInterrupt:d}=B(),p=c.useCallback(()=>{var C;const h=a.parts.filter(z=>z.type==="text").map(z=>z.content).join(`
3
- `);(C=navigator.clipboard)==null||C.writeText(h).catch(()=>{})},[a]),f=a.role==="user",u=r.Message;if(u)return e.jsx(u,{message:a,isStreaming:t,isLast:s,avatar:n,slots:r,onCopy:p,onRegenerate:i,onFeedback:l});const m=r.TextPart??re,w=r.ThinkingPart??ne,y=r.ToolCallPart??ie,g=r.ToolResultPart??oe,v=r.ErrorPart??le,x=r.ActionBar??de;return e.jsxs("div",{className:`sa-message ${f?"sa-message-user":"sa-message-assistant"}`,children:[!f&&e.jsx(V,{src:n==null?void 0:n.assistant,role:"assistant"}),e.jsxs("div",{className:"sa-message-body",children:[a.parts.map((h,C)=>{switch(h.type){case"text":return e.jsx(m,{content:h.content},C);case"thinking":return e.jsx(w,{content:h.content},C);case"tool_call":return e.jsx(y,{toolName:h.toolName,toolCallId:h.toolCallId,args:h.args},C);case"tool_result":return e.jsx(g,{toolName:h.toolName,toolCallId:h.toolCallId,content:h.content,artifacts:h.artifacts,renderMode:h.renderMode,html:h.html,artifactPreview:o},C);case"error":return e.jsx(v,{content:h.content,onRetry:i},C);case"interrupt":return e.jsx(ce,{interrupt:h.interrupt,resolved:h.resolved??!1,response:h.response,onRespond:z=>d(h.interrupt.interruptId,z)},C);default:return null}}),t&&s&&!f&&e.jsx("span",{className:"sa-streaming-cursor",children:"|"}),!f&&!t&&a.parts.length>0&&e.jsx(x,{message:a,onCopy:p,onRegenerate:i,onFeedback:l})]}),f&&e.jsx(V,{src:n==null?void 0:n.user,role:"user"})]})}function fe({message:a,suggestedPrompts:t,onPromptClick:s}){return e.jsxs("div",{className:"sa-welcome",children:[e.jsx("div",{className:"sa-welcome-icon",children:e.jsx(j,{name:"sparkles",size:40})}),e.jsx("p",{className:"sa-welcome-message",children:a||"你好!有什么可以帮你的?"}),t&&t.length>0&&e.jsx("div",{className:"sa-welcome-prompts",children:t.map((r,n)=>e.jsx("button",{className:"sa-welcome-prompt",onClick:()=>s(r),children:r},n))})]})}function q({slots:a,welcomeMessage:t,suggestedPrompts:s,avatar:r,artifactPreview:n}){const{messages:o,status:i,sendMessage:l}=B(),{containerRef:d}=se([o]),p=i==="streaming",f=a.WelcomeScreen??fe;return o.length===0?e.jsx("div",{className:"sa-thread",ref:d,children:e.jsx(f,{message:t,suggestedPrompts:s,onPromptClick:l})}):e.jsx("div",{className:"sa-thread",ref:d,children:o.map((u,m)=>e.jsx(pe,{message:u,isStreaming:p,isLast:m===o.length-1,slots:a,avatar:r,artifactPreview:n},u.id))})}function Y(){const{status:a,sendMessage:t,stop:s}=B(),[r,n]=c.useState(""),o=c.useRef(null),i=a==="streaming"||a==="submitted",l=c.useCallback(()=>{const f=r.trim();!f||i||(t(f),n(""),o.current&&(o.current.style.height="auto"))},[r,i,t]),d=c.useCallback(f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),l())},[l]),p=c.useCallback(f=>{n(f.target.value);const u=f.target;u.style.height="auto",u.style.height=Math.min(u.scrollHeight,120)+"px"},[]);return e.jsxs("div",{className:"sa-composer",children:[e.jsx("textarea",{ref:o,className:"sa-composer-input",value:r,onChange:p,onKeyDown:d,placeholder:"输入消息...",rows:1,disabled:a==="submitted"}),i?e.jsx("button",{className:"sa-composer-stop",onClick:s,title:"停止",children:e.jsx(j,{name:"circle-stop",size:16,color:"#fff"})}):e.jsx("button",{className:"sa-composer-send",onClick:l,disabled:!r.trim(),title:"发送",children:e.jsx(j,{name:"arrow-up",size:16,color:"#fff"})})]})}function Re({artifact:a}){const[t,s]=c.useState(null),[r,n]=c.useState(!0),[o,i]=c.useState(null);return c.useEffect(()=>{let l=!1;n(!0),i(null),s(null);async function d(){try{if(a.type==="pdf"){l||n(!1);return}if(a.type==="html"){const p=await fetch(a.url);if(!p.ok)throw new Error(`HTTP ${p.status}`);const f=await p.text(),u=(await Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs"))).default;l||(s(u.sanitize(f,{FORCE_BODY:!0})),n(!1));return}if(a.type==="docx"){const p=await fetch(a.url);if(!p.ok)throw new Error(`HTTP ${p.status}`);const f=await p.arrayBuffer(),m=await(await Promise.resolve().then(()=>require("./mammoth.browser-DiAPPO3x.cjs")).then(y=>y.mammoth_browser)).convertToHtml({arrayBuffer:f}),w=(await Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs"))).default;l||(s(w.sanitize(m.value,{FORCE_BODY:!0})),n(!1));return}l||(n(!1),i(`不支持预览「${a.type}」类型`))}catch(p){l||(n(!1),i(p instanceof Error?p.message:"加载失败"))}}return d(),()=>{l=!0}},[a]),r?e.jsx("div",{className:"sa-drawer-preview-loading",children:"加载中"}):o?e.jsxs("div",{className:"sa-drawer-preview-error",children:[o,e.jsx("button",{className:"sa-drawer-btn-sm",onClick:()=>void H(a),children:"下载查看"})]}):a.type==="pdf"?e.jsx("iframe",{src:a.url,title:a.filename,className:"sa-drawer-preview-iframe",sandbox:"allow-scripts"}):t!==null?e.jsx("iframe",{srcDoc:t,title:a.filename,className:"sa-drawer-preview-iframe",sandbox:"allow-same-origin"}):null}function ue({artifacts:a,initialArtifact:t,onClose:s}){const[r,n]=c.useState(t?{mode:"preview",artifact:t}:{mode:"list"}),[o,i]=c.useState(!1),l=c.useRef(null),[d,p]=c.useState(340),f=c.useRef(null);c.useEffect(()=>{t&&(l.current&&(clearTimeout(l.current),l.current=null,i(!1)),n({mode:"preview",artifact:t}))},[t]);const u=c.useCallback(()=>{i(!0),l.current=setTimeout(()=>{l.current=null,s()},240)},[s]);c.useEffect(()=>()=>{var g;l.current&&clearTimeout(l.current),(g=f.current)==null||g.call(f)},[]);const m=c.useCallback(g=>{n({mode:"preview",artifact:g})},[]),w=c.useCallback(()=>{n({mode:"list"})},[]);c.useEffect(()=>{const g=v=>{v.key==="Escape"&&u()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[u]);const y=c.useCallback(g=>{g.preventDefault();const v=g.clientX,x=d,h=z=>{const I=v-z.clientX;p(Math.max(240,Math.min(window.innerWidth*.7,x+I)))},C=()=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",C),document.body.style.cursor="",document.body.style.userSelect="",f.current=null};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",C),f.current=C},[d]);return e.jsxs("div",{className:`sa-artifact-drawer ${o?"sa-drawer-closing":""}`,style:{width:d},children:[e.jsx("div",{className:"sa-drawer-resize-handle",onMouseDown:y}),e.jsxs("div",{className:"sa-artifact-drawer-header",children:[r.mode==="preview"?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"sa-drawer-btn",onClick:w,title:"返回列表","aria-label":"返回列表",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M15 18l-6-6 6-6"})})}),e.jsx("span",{className:"sa-artifact-drawer-title",children:r.artifact.filename})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0},children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"sa-artifact-drawer-title",children:"会话产物"})]}),e.jsx("div",{style:{flex:1}}),r.mode==="preview"&&e.jsx("button",{className:"sa-drawer-btn",onClick:()=>void H(r.artifact),title:"下载","aria-label":"下载",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})}),e.jsx("button",{className:"sa-drawer-btn",onClick:u,title:"关闭","aria-label":"关闭",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsx("div",{className:"sa-artifact-drawer-body",children:r.mode==="list"?a.length===0?e.jsx("div",{className:"sa-drawer-empty",children:"暂无产物"}):e.jsx("ul",{className:"sa-drawer-file-list",role:"list",children:a.map((g,v)=>e.jsxs("li",{className:"sa-drawer-file-card",onClick:()=>m(g),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),m(g))},tabIndex:0,role:"button","aria-label":`预览 ${g.filename}`,children:[e.jsx("div",{className:"sa-drawer-file-icon",children:e.jsx("span",{className:"sa-artifact-chip-type",children:G(g.type)})}),e.jsxs("div",{className:"sa-drawer-file-info",children:[e.jsx("span",{className:"sa-drawer-file-name",children:g.filename}),e.jsx("span",{className:"sa-drawer-file-size",children:J(g.size)})]}),e.jsx("button",{className:"sa-drawer-btn",title:"下载","aria-label":`下载 ${g.filename}`,onClick:x=>{x.stopPropagation(),H(g)},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})})]},g.id||`artifact-${v}`))}):e.jsx("div",{className:"sa-drawer-view-enter",children:e.jsx(Re,{artifact:r.artifact})})})]})}function Oe({isOpen:a,onClose:t,title:s,slots:r,welcomeMessage:n,suggestedPrompts:o,avatar:i,artifactPreview:l}){const{status:d,sendMessage:p,stop:f,toggleThreadList:u,toggleArtifactDrawer:m,conversations:w,activeConversationId:y,switchConversation:g,newConversation:v,deleteConversation:x,renameConversation:h,isThreadListOpen:C,isArtifactDrawerOpen:z,allArtifacts:I,activePreviewArtifact:A}=B();if(!a)return null;const k=r.Header,T=r.Composer,D=r.ThreadList;return e.jsxs("div",{className:"sa-panel",children:[k?e.jsx(k,{title:s,onClose:t,onToggleThreadList:u}):e.jsx(ae,{title:s,onClose:t,onToggleThreadList:u,artifactCount:l?I.length:0,onToggleArtifactDrawer:l?m:void 0}),D&&C?e.jsx(D,{conversations:w,activeSessionId:y,onSwitch:g,onNew:v,onDelete:x,onRename:h}):e.jsx(te,{}),e.jsxs("div",{className:"sa-panel-content",children:[e.jsx(q,{slots:r,welcomeMessage:n,suggestedPrompts:o,avatar:i,artifactPreview:l}),l&&z&&e.jsx(ue,{artifacts:I,initialArtifact:A,onClose:m})]}),T?e.jsx(T,{status:d,onSend:p,onStop:f}):e.jsx(Y,{})]})}function Be({conversations:a,activeSessionId:t,onSwitch:s,onNew:r,onDelete:n,isCollapsed:o,onToggleCollapse:i}){const[l,d]=c.useState(null),[p,f]=c.useState(null),u=c.useCallback((w,y)=>{y.stopPropagation(),p===w?(n(w),f(null)):(f(w),setTimeout(()=>f(null),3e3))},[p,n]),m=(()=>{const w=Date.now(),y=[],g=[],v=[];for(const h of a){const C=w-new Date(h.updateTime).getTime();C<864e5?y.push(h):C<6048e5?g.push(h):v.push(h)}const x=[];return y.length&&x.push({label:"今天",items:y}),g.length&&x.push({label:"最近 7 天",items:g}),v.length&&x.push({label:"更早",items:v}),x})();return o?e.jsxs("div",{className:"sa-fp-sidebar sa-fp-sidebar-collapsed",children:[e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:i,title:"展开",children:e.jsx(j,{name:"panel-left",size:18})}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:r,title:"新会话",style:{marginTop:4},children:e.jsx(j,{name:"plus",size:18})})]}):e.jsxs("div",{className:"sa-fp-sidebar",children:[e.jsxs("div",{className:"sa-fp-sidebar-header",children:[e.jsxs("button",{className:"sa-fp-sidebar-new",onClick:r,children:[e.jsx(j,{name:"plus",size:15})," ",e.jsx("span",{children:"新会话"})]}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:i,title:"收起侧边栏",children:e.jsx(j,{name:"panel-left-close",size:18})})]}),e.jsxs("div",{className:"sa-fp-sidebar-list",children:[a.length===0&&e.jsx("div",{className:"sa-fp-sidebar-empty",children:"开始你的第一个对话"}),m.map(w=>e.jsxs("div",{children:[e.jsx("div",{className:"sa-fp-sidebar-group",children:w.label}),w.items.map(y=>{const g=y.sessionId===t,v=l===y.sessionId,x=p===y.sessionId;return e.jsxs("div",{className:`sa-fp-sidebar-item ${g?"active":""}`,onClick:()=>s(y.sessionId),onMouseEnter:()=>d(y.sessionId),onMouseLeave:()=>d(null),children:[e.jsx("span",{className:"sa-fp-sidebar-item-title",children:y.title||"新会话"}),v&&e.jsx("button",{className:`sa-fp-sidebar-item-action ${x?"danger":""}`,onClick:h=>u(y.sessionId,h),title:x?"确认删除":"删除",children:e.jsx(j,{name:x?"x":"trash2",size:14})})]},y.sessionId)})]},w.label))]})]})}function xe({title:a,slots:t,welcomeMessage:s,suggestedPrompts:r,sidebarDefaultOpen:n=!0,onClose:o,avatar:i,artifactPreview:l}){const{status:d,sendMessage:p,stop:f,conversations:u,activeConversationId:m,switchConversation:w,newConversation:y,deleteConversation:g,renameConversation:v,toggleArtifactDrawer:x,isArtifactDrawerOpen:h,allArtifacts:C,activePreviewArtifact:z}=B(),[I,A]=c.useState(n),k=c.useCallback(()=>A(S=>!S),[]),T=t.ThreadList,D=t.Composer;return e.jsxs("div",{className:"sa-fullpage",children:[T?e.jsx("div",{className:`sa-fp-sidebar-wrapper ${I?"":"sa-fp-sidebar-wrapper-collapsed"}`,children:e.jsx(T,{conversations:u,activeSessionId:m,onSwitch:w,onNew:y,onDelete:g,onRename:v})}):e.jsx(Be,{conversations:u,activeSessionId:m,onSwitch:w,onNew:y,onDelete:g,onRename:v,isCollapsed:!I,onToggleCollapse:k}),e.jsxs("div",{className:"sa-fp-main",children:[e.jsxs("div",{className:"sa-fp-header",children:[!I&&!T&&e.jsx("button",{className:"sa-fp-header-btn",onClick:k,title:"展开侧边栏",children:e.jsx(j,{name:"panel-left",size:18})}),e.jsx("div",{className:"sa-fp-header-title",children:a}),e.jsxs("div",{className:"sa-fp-header-actions",children:[l&&C.length>0&&e.jsxs("button",{className:"sa-fp-header-btn sa-header-btn-artifact",onClick:x,title:"会话产物",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{children:"产物"})]}),o&&e.jsx("button",{className:"sa-fp-header-btn",onClick:o,title:"关闭",children:e.jsx(j,{name:"x",size:18})})]})]}),e.jsxs("div",{className:"sa-fp-content-row",children:[e.jsx(q,{slots:t,welcomeMessage:s,suggestedPrompts:r,avatar:i,artifactPreview:l}),l&&h&&e.jsx(ue,{artifacts:C,initialArtifact:z,onClose:x})]}),D?e.jsx(D,{status:d,onSend:p,onStop:f}):e.jsx(Y,{})]})]})}function me(a){const{sdk:t,mode:s="floating",slots:r={},hooks:n={},welcomeMessage:o,suggestedPrompts:i,title:l="AI Assistant",initialOpen:d=!1,onOpenChange:p,sidebarDefaultOpen:f,avatar:u,artifactPreview:m}=a,[w,y]=c.useState(d);c.useEffect(()=>{y(d)},[d]);const g=c.useCallback(()=>{var C,z;const h=!w;y(h),p==null||p(h),h?(C=n.onOpen)==null||C.call(n):(z=n.onClose)==null||z.call(n)},[w,n,p]),v=c.useCallback(()=>{var h;y(!1),p==null||p(!1),(h=n.onClose)==null||h.call(n)},[n,p]),x=r.Trigger??ee;return s==="fullpage"?w?e.jsx(W,{sdk:t,hooks:n,children:e.jsx(xe,{title:l,slots:r,welcomeMessage:o,suggestedPrompts:i,sidebarDefaultOpen:f,onClose:v,avatar:u,artifactPreview:m})}):null:e.jsxs(W,{sdk:t,hooks:n,children:[e.jsx(x,{isOpen:w,onClick:g}),e.jsx(Oe,{isOpen:w,onClose:v,title:l,slots:r,welcomeMessage:o,suggestedPrompts:i,avatar:u,artifactPreview:m})]})}const he=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),Me=require("react-dom/client"),e=require("react/jsx-runtime");function te(t){const{sdk:a,sessionId:r,onSessionCreated:n,onStreamStart:s,onStreamEnd:i,onError:l,onMessageSend:c}=t,[d,p]=o.useState([]),[u,m]=o.useState("ready"),[w,f]=o.useState(null),x=o.useRef(null),v=o.useRef(!1),z=o.useRef(null),S=o.useRef(r),E=o.useRef(!0);S.current=r,E.current=d.length===0;const g=o.useCallback(j=>{if(v.current)return;v.current=!0,c==null||c(j);const D={id:`user_${Date.now()}`,role:"user",parts:[{type:"text",content:j}],timestamp:Date.now()},y=`assistant_${Date.now()}`,h={id:y,role:"assistant",parts:[],timestamp:Date.now()},$=E.current;p(k=>[...k,D,h]),m("submitted"),f(null);const M=k=>{let R="",b="",A=[],P=!1;const H=()=>{const T=[...A];if(R){const O=T.findIndex(B=>B.type==="thinking");O>=0?T[O]={type:"thinking",content:R}:T.unshift({type:"thinking",content:R})}if(b){const O=T[T.length-1];(O==null?void 0:O.type)==="text"?T[T.length-1]={type:"text",content:b}:T.push({type:"text",content:b})}p(O=>O.map(B=>B.id===y?{...B,parts:T}:B))};x.current=a.chat({sessionId:k,message:j,stream:!0,onMessage:T=>{switch(P||(P=!0,m("streaming")),T.type){case"thinking":R+=T.content;break;case"ai":b+=T.content;break;case"tool_call":b&&(A.push({type:"text",content:b}),b=""),A.push({type:"tool_call",toolName:T.toolName,toolCallId:T.toolCallId,args:T.args??"{}"});break;case"tool_result":b&&(A.push({type:"text",content:b}),b=""),A.push({type:"tool_result",toolName:T.toolName??"",toolCallId:T.toolCallId,content:T.content,artifacts:T.artifacts,renderMode:T.renderMode,html:T.html});break;case"interrupt":b&&(A.push({type:"text",content:b}),b=""),T.interrupt&&A.push({type:"interrupt",interrupt:T.interrupt,resolved:!1});break;case"stop":T.content&&(b=T.content),H();return}H()},onDone:T=>{(b||A.length>0||R)&&H(),T.sessionId&&T.sessionId!==S.current&&(n==null||n(T.sessionId));const O=()=>{z.current&&(clearTimeout(z.current),z.current=null),i==null||i(T.sessionId||k),m("ready"),v.current=!1,x.current=null};if($){const B=j.slice(0,30),Te=T.sessionId||k;a.renameConversation(Te,B).catch(()=>{}).finally(O)}else O()},onError:T=>{A.push({type:"error",content:T.message}),H(),z.current&&(clearTimeout(z.current),z.current=null),f(T),m("error"),l==null||l(T),v.current=!1,x.current=null}}),s==null||s(k)};S.current?M(S.current):a.createSession().then(k=>{S.current=k,n==null||n(k),M(k)}).catch(k=>{f(k instanceof Error?k:new Error(String(k))),m("error"),l==null||l(k instanceof Error?k:new Error(String(k))),v.current=!1})},[a,n,s,i,l,c]),C=o.useCallback(()=>{const j=S.current;j&&(z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{var D;z.current=null,(D=x.current)==null||D.abort(),x.current=null,v.current=!1,m("ready")},8e3),a.stopGeneration(j).catch(()=>{}))},[a]),I=o.useCallback(()=>{if(v.current)return;const j=d.findLastIndex(y=>y.role==="user");if(j<0)return;const D=d[j].parts.filter(y=>y.type==="text").map(y=>y.content).join("");p(y=>y.slice(0,j)),g(D)},[d,g]),L=o.useCallback((j,D)=>{p(b=>b.map(A=>({...A,parts:A.parts.map(P=>P.type==="interrupt"&&P.interrupt.interruptId===j?{...P,resolved:!0,response:D}:P)})));const y=S.current;if(!y)return;let h=0;p(b=>b.length>0&&b[b.length-1].role==="assistant"?(h=b[b.length-1].parts.length,b):(h=0,[...b,{id:`assistant_${Date.now()}`,role:"assistant",parts:[],timestamp:Date.now()}])),m("streaming");let $="",M="",k=[];const R=()=>{const b=[...k];if($){const A=b.findIndex(P=>P.type==="thinking");A>=0?b[A]={type:"thinking",content:$}:b.unshift({type:"thinking",content:$})}if(M){const A=b[b.length-1];(A==null?void 0:A.type)==="text"?b[b.length-1]={type:"text",content:M}:b.push({type:"text",content:M})}p(A=>{const P=A.findLastIndex(H=>H.role==="assistant");return P<0?A:A.map((H,T)=>T===P?{...H,parts:[...H.parts.slice(0,h),...b]}:H)})};a.respondInterrupt(j,y,D,b=>{switch(b.type){case"thinking":$+=b.content;break;case"ai":M+=b.content;break;case"tool_call":M&&(k.push({type:"text",content:M}),M=""),k.push({type:"tool_call",toolName:b.toolName,toolCallId:b.toolCallId,args:b.args??"{}"});break;case"tool_result":M&&(k.push({type:"text",content:M}),M=""),k.push({type:"tool_result",toolName:b.toolName??"",toolCallId:b.toolCallId,content:b.content,artifacts:b.artifacts,renderMode:b.renderMode,html:b.html});break;case"interrupt":M&&(k.push({type:"text",content:M}),M=""),b.interrupt&&k.push({type:"interrupt",interrupt:b.interrupt,resolved:!1});break;case"done":i==null||i(y),m("ready");break}R()},b=>{k.push({type:"error",content:b.message}),R(),f(b),m("error"),l==null||l(b)}).catch(b=>{l==null||l(b instanceof Error?b:new Error(String(b))),m("error")})},[a,l,i]);return{messages:d,status:u,error:w,sendMessage:g,stop:C,regenerate:I,setMessages:p,respondToInterrupt:L}}const ae="sa_active_conversation",Y=20;function G(t){try{return localStorage.getItem(`${ae}_${t}`)}catch{return null}}function $e(t,a){try{const r=`${ae}_${t}`;a?localStorage.setItem(r,a):localStorage.removeItem(r)}catch{}}function se(t){const{sdk:a,onConversationChange:r}=t,n=a.botId,[s,i]=o.useState([]),[l,c]=o.useState(()=>G(n)),[d,p]=o.useState(!1),[u,m]=o.useState(!0),w=o.useRef(!0),f=o.useRef(1),x=o.useRef(!1);o.useEffect(()=>()=>{w.current=!1},[]);const v=o.useCallback(j=>{c(j),$e(n,j),j&&(r==null||r(j))},[n,r]),z=o.useCallback(async()=>{if(!x.current){x.current=!0,p(!0);try{f.current=1;const j=await a.listConversations({page:1,size:Y});if(!w.current)return;i(j.items),m(j.items.length<j.total);const D=G(n);D&&!j.items.find(y=>y.sessionId===D)&&v(null)}catch{}finally{x.current=!1,w.current&&p(!1)}}},[a,v]),S=o.useCallback(async()=>{if(!(x.current||!u)){x.current=!0,p(!0);try{const j=f.current+1,D=await a.listConversations({page:j,size:Y});if(!w.current)return;f.current=j,i(h=>{const $=new Set(h.map(k=>k.sessionId)),M=D.items.filter(k=>!$.has(k.sessionId));return[...h,...M]});const y=f.current*Y;m(y<D.total)}catch{}finally{x.current=!1,w.current&&p(!1)}}},[a,u]),E=o.useCallback(async j=>(v(j),await a.getMessages(j)),[a,v]),g=o.useCallback(async()=>{try{const j=await a.createSession(),D=new Date().toISOString();i(y=>[{sessionId:j,botId:0,title:"新对话",createTime:D,updateTime:D},...y]),v(j)}catch{v(null)}},[a,v]),C=o.useCallback(async j=>{i(D=>D.filter(y=>y.sessionId!==j)),l===j&&v(null);try{await a.deleteConversation(j)}catch{}},[a,l,v]),I=o.useCallback(async(j,D)=>{await a.renameConversation(j,D),i(y=>y.map(h=>h.sessionId===j?{...h,title:D}:h))},[a]),{enabled:L=!0}=t;return o.useEffect(()=>{L&&z()},[L,z]),{conversations:s,activeConversationId:l,loading:d,hasMore:u,loadConversations:z,loadMore:S,switchConversation:E,newConversation:g,deleteConversation:C,renameConversation:I,setActiveConversationId:v}}function re(t){return!t&&t!==0?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ne(t){return t==="pdf"?"PDF":t==="docx"?"DOC":t==="html"?"HTM":t.slice(0,3).toUpperCase()||"FILE"}function ie(t){if(!t)return[];const a=[];for(const r of t)r.type==="file"&&r.data&&a.push({id:r.data.id??"",type:r.data.fileType??r.data.type??"",filename:r.data.name??r.data.filename??"",url:r.data.url??"",mime:r.data.mime,size:r.data.size,summary:r.data.summary});return a}async function K(t){try{const a=await fetch(t.url);if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.blob(),n=URL.createObjectURL(r),s=document.createElement("a");s.href=n,s.download=t.filename,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(n),4e3)}catch{const a=document.createElement("a");a.href=t.url,a.download=t.filename,a.target="_blank",document.body.appendChild(a),a.click(),a.remove()}}const oe=o.createContext(null);function _(){const t=o.useContext(oe);if(!t)throw new Error("useChatContext must be used within ChatProvider");return t}function U({sdk:t,hooks:a,children:r}){const[n,s]=o.useState(!1),[i,l]=o.useState(!1),[c,d]=o.useState(null),[p,u]=o.useState(!1),[m,w]=o.useState(!1);o.useEffect(()=>{t.getToken().then(()=>{u(!0)}).catch(()=>{u(!0)})},[t]);const f=se({sdk:t,onConversationChange:a==null?void 0:a.onConversationChange,enabled:p}),x=te({sdk:t,sessionId:f.activeConversationId,onSessionCreated:h=>{f.setActiveConversationId(h)},onStreamStart:a==null?void 0:a.onStreamStart,onStreamEnd:h=>{var $;($=a==null?void 0:a.onStreamEnd)==null||$.call(a,h),f.loadConversations()},onError:a==null?void 0:a.onError,onMessageSend:a==null?void 0:a.onMessageSend}),v=o.useCallback(async h=>{w(!0);try{const $=await f.switchConversation(h);x.setMessages($),s(!1)}finally{w(!1)}},[f,x]),z=o.useCallback(async()=>{x.setMessages([]),s(!1),await f.newConversation()},[f,x]),S=o.useCallback(async h=>{f.activeConversationId===h&&x.setMessages([]),await f.deleteConversation(h)},[f,x]);o.useEffect(()=>{f.activeConversationId&&x.messages.length===0&&(w(!0),t.getMessages(f.activeConversationId).then(h=>{x.setMessages(h)}).catch(()=>{}).finally(()=>w(!1)))},[]);const E=o.useCallback(()=>{s(h=>!h)},[]),g=o.useCallback(()=>{l(h=>!h),d(h=>null)},[]),C=o.useCallback(h=>{d(h),l(!0)},[]),I=o.useMemo(()=>{const h=new Set,$=[];for(const M of x.messages)for(const k of M.parts)if(k.type==="tool_result"&&k.artifacts)for(const R of ie(k.artifacts)){const b=R.id||`${R.url}:${R.filename}`;h.has(b)||(h.add(b),$.push(R))}return $},[x.messages]),L=o.useCallback(async()=>{const h=f.activeConversationId;if(!h)return null;try{const $=await t.getMessages(h);x.setMessages($);const M=$.findLast(k=>k.role==="assistant");return(M==null?void 0:M.id)??null}catch{return null}},[t,f.activeConversationId,x]),j=o.useCallback((h,$,M)=>{if(/^\d+$/.test(h)){t.feedback(h,$,M).catch(()=>{});return}L().then(k=>{k&&t.feedback(k,$,M).catch(()=>{})})},[t,L]),D=o.useCallback(h=>{if(/^\d+$/.test(h)){t.cancelFeedback(h).catch(()=>{});return}L().then($=>{$&&t.cancelFeedback($).catch(()=>{})})},[t,L]),y=o.useMemo(()=>({sdk:t,status:x.status,error:x.error,messages:x.messages,conversations:f.conversations,activeConversationId:f.activeConversationId,isThreadListOpen:n,isArtifactDrawerOpen:i,allArtifacts:I,activePreviewArtifact:c,hasMore:f.hasMore,conversationsLoading:f.loading,messagesLoading:m,sendMessage:x.sendMessage,stop:x.stop,regenerate:x.regenerate,switchConversation:v,newConversation:z,deleteConversation:S,renameConversation:f.renameConversation,loadMoreConversations:f.loadMore,toggleThreadList:E,toggleArtifactDrawer:g,openArtifactPreview:C,feedback:j,cancelFeedback:D,respondToInterrupt:x.respondToInterrupt}),[t,x.status,x.error,x.messages,x.sendMessage,x.stop,x.regenerate,x.respondToInterrupt,f.conversations,f.activeConversationId,f.renameConversation,f.hasMore,f.loadMore,f.loading,n,i,I,c,m,v,z,S,E,g,C,j,D]);return e.jsx(oe.Provider,{value:y,children:r})}const Ee="https://at.alicdn.com/t/c/font_5210396_pffyg5g21kn.js";let J=!1;function le(t=Ee){if(J||typeof document>"u")return;J=!0;const a=t.split("?")[0].split("/").pop();if(a&&document.querySelector(`script[src*="${a}"]`))return;const r=document.createElement("script");r.src=t,document.head.appendChild(r)}le();function N({name:t,size:a=16,color:r="currentColor",className:n,style:s}){return e.jsx("svg",{className:n,style:{width:a,height:a,fill:r,verticalAlign:"middle",...s},"aria-hidden":"true",children:e.jsx("use",{href:`#icon-${t}`})})}function ce({isOpen:t,onClick:a}){return e.jsx("button",{className:`sa-trigger ${t?"sa-trigger-open":""}`,onClick:a,children:t?e.jsx(N,{name:"x",size:24,color:"#fff"}):e.jsx(N,{name:"message-square",size:24,color:"#fff"})})}function de({title:t,onClose:a,onToggleThreadList:r,showClose:n=!0,artifactCount:s=0,onToggleArtifactDrawer:i}){return e.jsxs("div",{className:"sa-header",children:[e.jsxs("div",{className:"sa-header-left",children:[e.jsx("div",{className:"sa-header-avatar",children:"A"}),e.jsxs("div",{className:"sa-header-info",children:[e.jsx("div",{className:"sa-header-title",children:t}),e.jsx("div",{className:"sa-header-status",children:"● Online"})]})]}),e.jsxs("div",{className:"sa-header-actions",children:[s>0&&i&&e.jsxs("button",{className:"sa-header-btn sa-header-btn-artifact",onClick:i,title:"会话产物",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{children:"产物"})]}),e.jsx("button",{className:"sa-header-btn",onClick:r,title:"会话列表",children:e.jsx(N,{name:"menu",size:16})}),n&&e.jsx("button",{className:"sa-header-btn",onClick:a,title:"关闭",children:e.jsx(N,{name:"x",size:16})})]})]})}const q=t=>String(t).padStart(2,"0");function pe(t){if(!t)return"";const a=new Date(t);return isNaN(a.getTime())?"":`${a.getFullYear()}-${q(a.getMonth()+1)}-${q(a.getDate())} ${q(a.getHours())}:${q(a.getMinutes())}:${q(a.getSeconds())}`}function De(t){const a=new Date,r=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),n=r-6*864e5,s=[],i=[],l=[];for(const d of t){const p=new Date(d.updateTime).getTime();p>=r?s.push(d):p>=n?i.push(d):l.push(d)}const c=[];return s.length&&c.push({label:"今天",items:s}),i.length&&c.push({label:"最近 7 天",items:i}),l.length&&c.push({label:"更早",items:l}),c}function ue(){const{conversations:t,activeConversationId:a,switchConversation:r,newConversation:n,deleteConversation:s,renameConversation:i,isThreadListOpen:l,toggleThreadList:c,hasMore:d,loadMoreConversations:p,conversationsLoading:u}=_(),[m,w]=o.useState(null),[f,x]=o.useState(""),v=o.useRef(null),z=o.useCallback((C,I)=>{w(C),x(I??"")},[]),S=o.useCallback(C=>{f.trim()&&i(C,f.trim()),w(null)},[f,i]),E=o.useCallback(()=>{const C=v.current;!C||!d||C.scrollHeight-C.scrollTop-C.clientHeight<50&&p()},[d,p]),g=o.useMemo(()=>De(t),[t]);return l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-thread-list-overlay",onClick:c}),e.jsxs("div",{className:"sa-thread-list",children:[e.jsxs("div",{className:"sa-thread-list-header",children:[e.jsx("span",{className:"sa-thread-list-title",children:"会话记录"}),e.jsxs("button",{className:"sa-thread-list-new",onClick:n,children:[e.jsx(N,{name:"plus",size:14})," 新会话"]})]}),e.jsxs("div",{className:"sa-thread-list-items",ref:v,onScroll:E,children:[u&&t.length===0&&e.jsx("div",{className:"sa-thread-list-loading",children:"加载中..."}),!u&&t.length===0&&e.jsx("div",{className:"sa-thread-list-empty",children:"暂无会话"}),g.map(C=>e.jsxs("div",{className:"sa-thread-group",children:[e.jsx("div",{className:"sa-thread-group-label",children:C.label}),C.items.map(I=>e.jsxs("div",{className:`sa-thread-item ${I.sessionId===a?"active":""}`,onClick:()=>{m!==I.sessionId&&r(I.sessionId)},children:[m===I.sessionId?e.jsx("input",{className:"sa-thread-item-edit",value:f,onChange:L=>x(L.target.value),onBlur:()=>S(I.sessionId),onKeyDown:L=>{L.key==="Enter"&&S(I.sessionId),L.key==="Escape"&&w(null)},onClick:L=>L.stopPropagation(),autoFocus:!0}):e.jsxs("div",{className:"sa-thread-item-info",children:[e.jsx("span",{className:"sa-thread-item-title",children:I.title||"新会话"}),e.jsx("span",{className:"sa-thread-item-time",children:pe(I.updateTime)})]}),e.jsxs("div",{className:"sa-thread-item-actions",children:[e.jsx("button",{className:"sa-thread-item-action-btn",onClick:L=>{L.stopPropagation(),z(I.sessionId,I.title)},title:"重命名",children:e.jsx(N,{name:"pen",size:13})}),e.jsx("button",{className:"sa-thread-item-action-btn",onClick:L=>{L.stopPropagation(),s(I.sessionId)},title:"删除",children:e.jsx(N,{name:"trash2",size:13})})]})]},I.sessionId))]},C.label)),u&&t.length>0&&e.jsx("div",{className:"sa-thread-list-loading",children:d?"加载更多...":"加载中..."}),!u&&d&&e.jsx("div",{className:"sa-thread-list-hint",children:"向下滚动加载更多"})]})]})]}):null}function fe(t){const a=o.useRef(null),r=o.useRef(!1),n=o.useRef(0),s=o.useCallback(()=>{const l=a.current;if(!l)return;const{scrollTop:c,scrollHeight:d,clientHeight:p}=l,u=d-c-p<40;c<n.current&&!u&&(r.current=!0),u&&(r.current=!1),n.current=c},[]);o.useEffect(()=>{const l=a.current;if(l)return l.addEventListener("scroll",s,{passive:!0}),()=>l.removeEventListener("scroll",s)},[s]),o.useEffect(()=>{if(r.current)return;const l=a.current;l&&requestAnimationFrame(()=>{l.scrollTop=l.scrollHeight})},t);const i=o.useCallback(()=>{r.current=!1;const l=a.current;l&&(l.scrollTop=l.scrollHeight)},[]);return{containerRef:a,scrollToBottom:i}}function F(t){return t.value++}function W(t,a){const r=[],n=[],s=()=>{n.length>0&&(r.push(n.join("")),n.length=0)};let i=0;for(;i<t.length;){const l=t[i];if(l==="`"){const c=t.indexOf("`",i+1);if(c!==-1){s(),r.push(e.jsx("code",{className:"sa-inline-code",children:t.slice(i+1,c)},F(a))),i=c+1;continue}}else if(l==="*"&&t[i+1]==="*"){const c=t.indexOf("**",i+2);if(c!==-1){s(),r.push(e.jsx("strong",{children:W(t.slice(i+2,c),a)},F(a))),i=c+2;continue}}else if(l==="*"){const c=t.indexOf("*",i+1);if(c!==-1){s(),r.push(e.jsx("em",{children:W(t.slice(i+1,c),a)},F(a))),i=c+1;continue}}else if(l==="["){const c=t.indexOf("]",i+1);if(c!==-1&&t[c+1]==="("){const d=t.indexOf(")",c+2);if(d!==-1){const p=t.slice(i+1,c),u=t.slice(c+2,d);s(),r.push(e.jsx("a",{href:u,target:"_blank",rel:"noreferrer",children:W(p,a)},F(a))),i=d+1;continue}}}n.push(l),i++}return s(),r}function Re(t,a){const r=[],n=t.split(`
2
+ `);let s=0;const i=d=>d.trim()==="",l=d=>/^#{1,6}\s+\S/.test(d.trim()),c=d=>/^(?:[-*+]|\d+[.)])\s+\S/.test(d.trim());for(;s<n.length;){const d=n[s],p=d.trim();if(i(d)){s++;continue}if(l(d)){const m=p.match(/^(#{1,6})\s+(.*)$/);if(m){const f=`h${Math.min(m[1].length,6)}`;r.push(o.createElement(f,{key:F(a)},W(m[2],a)))}s++;continue}if(c(d)){const m=/^\d+[.)]/.test(p),w=[];for(;s<n.length&&c(n[s]);){const f=n[s].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);f&&w.push(e.jsx("li",{children:W(f[1],a)},F(a))),s++}r.push(m?e.jsx("ol",{className:"sa-list",children:w},F(a)):e.jsx("ul",{className:"sa-list",children:w},F(a)));continue}const u=[];for(;s<n.length&&!i(n[s])&&!l(n[s])&&!c(n[s]);)u.push(n[s]),s++;r.push(e.jsx("p",{className:"sa-text-paragraph",children:W(u.join(" "),a)},F(a)))}return r}function Le(t){const a={value:0},r=[],n=t.split("```");for(let s=0;s<n.length;s++)if(s%2===0)r.push(...Re(n[s],a));else if(n[s].trim()!==""){let i=n[s].replace(/^\r?\n/,"");i=i.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/,""),i=i.replace(/\r?\n$/,""),r.push(e.jsx("pre",{className:"sa-code-block",children:e.jsx("code",{children:i})},F(a)))}return r}function xe({content:t}){return e.jsx("div",{className:"sa-text-part",children:Le(t)})}function me({content:t}){const[a,r]=o.useState(!1);return e.jsxs("div",{className:"sa-thinking-part",onClick:()=>r(!a),children:[e.jsxs("div",{className:"sa-thinking-header",children:[e.jsx("span",{className:"sa-thinking-icon",children:e.jsx(N,{name:"brain",size:14})}),e.jsx("span",{className:"sa-thinking-label",children:"思考过程"}),e.jsx("span",{className:`sa-thinking-arrow ${a?"expanded":""}`,children:e.jsx(N,{name:"chevron-right",size:12})})]}),a&&e.jsx("div",{className:"sa-thinking-content",children:t})]})}function he({toolName:t,toolCallId:a,args:r}){const[n,s]=o.useState(!1),[i,l]=o.useState(!1);let c=r;try{c=JSON.stringify(JSON.parse(r),null,2)}catch{}const d=o.useCallback(()=>{var p;(p=navigator.clipboard)==null||p.writeText(c).then(()=>{l(!0),setTimeout(()=>l(!1),2e3)}).catch(()=>{})},[c]);return e.jsxs("div",{className:"sa-tool-call-part",children:[e.jsxs("div",{className:"sa-tool-call-header",onClick:()=>s(!n),children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(N,{name:"zap",size:14})}),e.jsxs("span",{className:"sa-tool-name",children:["调用工具: ",t]}),e.jsx("span",{className:`sa-thinking-arrow ${n?"expanded":""}`,children:e.jsx(N,{name:"chevron-right",size:12})})]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"sa-tool-args",children:c}),e.jsx("div",{className:"sa-tool-result-actions",children:e.jsxs("button",{className:"sa-action-btn",onClick:d,title:"复制",children:[e.jsx(N,{name:i?"circle-check":"copy",size:14})," ",i?"已复制":"复制"]})})]})]})}function Z({text:t}){const[a,r]=o.useState(!1),n=()=>{var s;(s=navigator.clipboard)==null||s.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)}).catch(()=>{})};return e.jsxs("button",{className:"sa-action-btn",onClick:n,title:"复制",children:[e.jsx(N,{name:a?"circle-check":"copy",size:14})," ",a?"已复制":"复制"]})}function Ae({html:t}){const[a,r]=o.useState(null);return o.useEffect(()=>{let n=!1;return Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs")).then(s=>{n||r(s.default.sanitize(t,{FORCE_BODY:!0,ADD_ATTR:["target"]}))}),()=>{n=!0}},[t]),a===null?null:e.jsx("div",{className:"sa-tool-result-html-scroll",children:e.jsx("div",{className:"sa-tool-result-html sa-text-part",dangerouslySetInnerHTML:{__html:a}})})}function ge({toolName:t,content:a,artifacts:r,renderMode:n,html:s,artifactPreview:i}){const{openArtifactPreview:l}=_(),c=ie(r);return e.jsxs("div",{className:"sa-tool-result-part",children:[e.jsxs("div",{className:"sa-tool-result-header",children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(N,{name:"circle-check",size:14,color:"#10b981"})}),e.jsx("span",{className:"sa-tool-result-label",children:t||"工具返回"})]}),n==="html"&&s?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{html:s}),e.jsx("div",{className:"sa-tool-result-actions",children:e.jsx(Z,{text:s})})]}):a?e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"sa-tool-result-content",children:a}),e.jsx("div",{className:"sa-tool-result-actions",children:e.jsx(Z,{text:a})})]}):e.jsx("pre",{className:"sa-tool-result-content",children:"—"}),c.length>0&&e.jsx("ul",{className:"sa-artifact-file-list",role:"list",children:c.map((d,p)=>e.jsxs("li",{className:"sa-artifact-file-card",onClick:i?()=>l(d):void 0,onKeyDown:i?u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),l(d))}:void 0,tabIndex:i?0:void 0,role:i?"button":void 0,"aria-label":i?`预览 ${d.filename}`:void 0,style:i?{cursor:"pointer"}:void 0,children:[e.jsx("div",{className:"sa-artifact-file-icon",children:e.jsx("span",{className:"sa-artifact-chip-type",children:ne(d.type)})}),e.jsxs("div",{className:"sa-artifact-file-info",children:[e.jsx("span",{className:"sa-artifact-file-name",children:d.filename}),d.size!=null&&e.jsx("span",{className:"sa-artifact-file-size",children:re(d.size)})]}),i&&e.jsx("button",{className:"sa-artifact-file-download",title:"下载","aria-label":`下载 ${d.filename}`,onClick:u=>{u.stopPropagation(),K(d)},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})})]},d.id||`art-${p}`))})]})}function be({content:t,onRetry:a}){return e.jsxs("div",{className:"sa-error-part",children:[e.jsxs("div",{className:"sa-error-content",children:[e.jsx("span",{className:"sa-error-icon",children:e.jsx(N,{name:"triangle-alert",size:14})}),e.jsx("span",{children:t})]}),a&&e.jsx("button",{className:"sa-error-retry",onClick:a,children:"重试"})]})}function Pe({interrupt:t,onRespond:a,disabled:r,answeredAction:n}){var c,d;const s=t.options,i=(typeof(s==null?void 0:s[0])=="string"?s[0]:(c=s==null?void 0:s[0])==null?void 0:c.label)||"确认",l=(typeof(s==null?void 0:s[1])=="string"?s[1]:(d=s==null?void 0:s[1])==null?void 0:d.label)||"取消";return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"circle-alert",size:16,color:"#f59e0b"}),e.jsx("span",{children:t.content})]}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:`sa-interrupt-btn sa-interrupt-btn-primary ${n==="confirm"?"sa-interrupt-btn-answered":""}`,disabled:r,onClick:()=>a({action:"confirm"}),children:[e.jsx(N,{name:"check",size:14})," ",i]}),e.jsxs("button",{className:`sa-interrupt-btn sa-interrupt-btn-secondary ${n==="cancel"?"sa-interrupt-btn-answered":""}`,disabled:r,onClick:()=>a({action:"cancel"}),children:[e.jsx(N,{name:"x",size:14})," ",l]})]}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function Oe({interrupt:t,onRespond:a,disabled:r,answeredAction:n}){var p,u,m,w;const s=t.options,i=(typeof(s==null?void 0:s[0])=="string"?s[0]:(p=s==null?void 0:s[0])==null?void 0:p.label)||"批准",l=(typeof(s==null?void 0:s[1])=="string"?s[1]:(u=s==null?void 0:s[1])==null?void 0:u.label)||"拒绝",c=(typeof(s==null?void 0:s[2])=="string"?s[2]:(m=s==null?void 0:s[2])==null?void 0:m.label)||"跳过",d=((w=t.metadata)==null?void 0:w.showSkip)!==!1;return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"circle-alert",size:16,color:"#f59e0b"}),e.jsx("span",{children:t.content})]}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:`sa-interrupt-btn sa-interrupt-btn-primary ${n==="approve"?"sa-interrupt-btn-answered":""}`,disabled:r,onClick:()=>a({action:"approve"}),children:[e.jsx(N,{name:"check",size:14})," ",i]}),e.jsxs("button",{className:`sa-interrupt-btn sa-interrupt-btn-danger ${n==="reject"?"sa-interrupt-btn-answered":""}`,disabled:r,onClick:()=>a({action:"reject"}),children:[e.jsx(N,{name:"x",size:14})," ",l]}),d&&e.jsxs("button",{className:`sa-interrupt-btn sa-interrupt-btn-secondary ${n==="skip"?"sa-interrupt-btn-answered":""}`,disabled:r,onClick:()=>a({action:"skip"}),children:[e.jsx(N,{name:"chevron-right",size:14})," ",c]})]}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function He(t){return typeof t=="string"?{value:t,label:t}:t}function Fe({interrupt:t,onRespond:a,disabled:r,initialValue:n}){const s=(t.options??[]).map(He);return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"list",size:16,color:"#6366f1"}),e.jsx("span",{children:t.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:s.map(i=>{const l=n===i.value;return e.jsxs("button",{className:`sa-interrupt-option ${i.danger?"sa-interrupt-option-danger":""} ${l?"sa-interrupt-option-selected":""}`,disabled:r,onClick:()=>a({action:"select",value:i.value}),children:[e.jsx(N,{name:l?"circle-check":"circle",size:14}),i.icon&&e.jsx(N,{name:i.icon,size:14}),e.jsx("span",{children:i.label}),i.description&&e.jsx("span",{className:"sa-interrupt-option-desc",children:i.description})]},i.value)})}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function _e(t){return typeof t=="string"?{value:t,label:t}:t}function Be({interrupt:t,onRespond:a,disabled:r,initialValue:n}){const s=(t.options??[]).map(_e),[i,l]=o.useState(()=>new Set(Array.isArray(n)?n:[])),c=d=>{r||l(p=>{const u=new Set(p);return u.has(d)?u.delete(d):u.add(d),u})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"list-checks",size:16,color:"#6366f1"}),e.jsx("span",{children:t.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:s.map(d=>e.jsxs("button",{className:`sa-interrupt-option ${i.has(d.value)?"sa-interrupt-option-selected":""}`,disabled:r,onClick:()=>c(d.value),children:[e.jsx(N,{name:i.has(d.value)?"square-check":"square",size:14}),e.jsx("span",{children:d.label})]},d.value))}),!r&&e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:i.size===0,onClick:()=>a({action:"submit",value:Array.from(i)}),children:[e.jsx(N,{name:"check",size:14})," 确认 (",i.size,")"]})}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function We({interrupt:t,onRespond:a,disabled:r,initialValue:n}){const[s,i]=o.useState(n??""),l=t.inputType??"text",c=l==="textarea",d=()=>{r||t.required&&!s.trim()||a({action:"submit",value:s.trim()})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"text-cursor-input",size:16,color:"#6366f1"}),e.jsx("span",{children:t.content})]}),e.jsx("div",{className:"sa-interrupt-input-area",children:c?e.jsx("textarea",{className:"sa-interrupt-textarea",value:s,onChange:p=>i(p.target.value),placeholder:t.placeholder,maxLength:t.maxLength,rows:3,disabled:r}):e.jsx("input",{className:"sa-interrupt-input",type:l,value:s,onChange:p=>i(p.target.value),placeholder:t.placeholder,maxLength:t.maxLength,onKeyDown:p=>p.key==="Enter"&&d(),disabled:r})}),!r&&e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:t.required?!s.trim():!1,onClick:d,children:[e.jsx(N,{name:"check",size:14})," 提交"]})}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function qe({interrupt:t,onRespond:a,disabled:r,initialValue:n}){const s=t.fields??[],[i,l]=o.useState(()=>{const u={};for(const m of s)u[m.name]=(n==null?void 0:n[m.name])??m.defaultValue??"";return u}),c=(u,m)=>{r||l(w=>({...w,[u]:m}))},d=!r&&s.every(u=>!u.required||i[u.name]),p=()=>{d&&a({action:"submit",value:i})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(N,{name:"file-text",size:16,color:"#6366f1"}),e.jsx("span",{children:t.content})]}),e.jsx("div",{className:"sa-interrupt-form",children:s.map(u=>e.jsxs("div",{className:"sa-interrupt-form-field",children:[e.jsxs("label",{className:"sa-interrupt-form-label",children:[u.label,u.required&&e.jsx("span",{className:"sa-interrupt-form-required",children:"*"})]}),Ke(u,i[u.name],m=>c(u.name,m),r)]},u.name))}),!r&&e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:!d,onClick:p,children:[e.jsx(N,{name:"check",size:14})," 提交"]}),e.jsx("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>a({action:"cancel"}),children:"取消"})]}),r&&e.jsx("div",{className:"sa-interrupt-submitted",children:"已提交"})]})}function Q(t){return typeof t=="string"?{value:t,label:t}:t}function Ke(t,a,r,n){switch(t.type){case"textarea":return e.jsx("textarea",{className:"sa-interrupt-textarea",value:a,onChange:s=>r(s.target.value),placeholder:t.placeholder,rows:3,disabled:n});case"select":{const s=(t.options??[]).map(Q);return e.jsxs("select",{className:"sa-interrupt-select",value:a,onChange:i=>r(i.target.value),disabled:n,children:[e.jsx("option",{value:"",children:"请选择"}),s.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))]})}case"multiSelect":{const s=(t.options??[]).map(Q),i=Array.isArray(a)?a:[],l=c=>{n||r(i.includes(c)?i.filter(d=>d!==c):[...i,c])};return e.jsx("div",{className:"sa-interrupt-options",children:s.map(c=>e.jsx("button",{type:"button",className:`sa-interrupt-option ${i.includes(c.value)?"sa-interrupt-option-selected":""}`,disabled:n,onClick:()=>l(c.value),children:c.label},c.value))})}case"password":return e.jsx("input",{className:"sa-interrupt-input",type:"password",value:a,onChange:s=>r(s.target.value),placeholder:t.placeholder,disabled:n});default:return e.jsx("input",{className:"sa-interrupt-input",type:t.type==="number"?"number":t.type==="date"?"date":"text",value:a,onChange:s=>r(s.target.value),placeholder:t.placeholder,disabled:n})}}function ve({interrupt:t,resolved:a,response:r,onRespond:n}){const s=a,i=r==null?void 0:r.value;switch(t.interruptType){case"confirm":return e.jsx(Pe,{interrupt:t,onRespond:n,disabled:s,answeredAction:r==null?void 0:r.action});case"approve":return e.jsx(Oe,{interrupt:t,onRespond:n,disabled:s,answeredAction:r==null?void 0:r.action});case"select":return e.jsx(Fe,{interrupt:t,onRespond:n,disabled:s,initialValue:i});case"multiSelect":return e.jsx(Be,{interrupt:t,onRespond:n,disabled:s,initialValue:i});case"input":return e.jsx(We,{interrupt:t,onRespond:n,disabled:s,initialValue:i});case"form":return e.jsx(qe,{interrupt:t,onRespond:n,disabled:s,initialValue:i});default:return e.jsxs("div",{className:"sa-interrupt-unknown",children:["未知的交互类型: ",t.interruptType]})}}const Ye=[{value:1,label:"事实错误"},{value:2,label:"逻辑问题"},{value:3,label:"不相关"},{value:4,label:"信息过时"},{value:5,label:"冗长啰嗦"},{value:6,label:"难以理解"}];function we({message:t,onCopy:a,onRegenerate:r,onFeedback:n}){const{status:s,cancelFeedback:i}=_(),[l,c]=o.useState(null),[d,p]=o.useState(!1),[u,m]=o.useState(!1),w=o.useRef(null),f=o.useCallback(()=>{a(),p(!0),setTimeout(()=>p(!1),2e3)},[a]),x=o.useCallback(()=>{l==="like"?(c(null),i(t.id)):(c("like"),m(!1),n==null||n(t.id,"like"))},[l,t.id,n,i]),v=o.useCallback(()=>{l==="dislike"?(c(null),m(!1),i(t.id)):m(!0)},[l,t.id,i]),z=o.useCallback((E,g)=>{c("dislike"),m(!1),n==null||n(t.id,"dislike",{reason:E,remark:(g==null?void 0:g.trim())||void 0})},[t.id,n]),S=o.useCallback(()=>{m(!1)},[]);return o.useEffect(()=>{if(!u)return;const E=C=>{w.current&&!w.current.contains(C.target)&&m(!1)},g=C=>{C.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",g)}},[u]),s!=="ready"&&s!=="error"?null:e.jsxs("div",{className:"sa-action-bar",children:[e.jsxs("button",{className:"sa-action-btn",onClick:f,title:"复制",children:[e.jsx(N,{name:d?"circle-check":"copy",size:14})," ",d?"已复制":"复制"]}),r&&e.jsxs("button",{className:"sa-action-btn",onClick:r,title:"重新生成",children:[e.jsx(N,{name:"refresh-cw",size:14})," 重新生成"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sa-action-divider"}),e.jsx("button",{className:`sa-action-btn ${l==="like"?"sa-action-btn-active":""}`,onClick:x,title:"有用","aria-label":"点赞",children:e.jsx(N,{name:"thumbs-up",size:14})}),e.jsx("button",{className:`sa-action-btn ${l==="dislike"?"sa-action-btn-active":""}`,onClick:v,title:"无用","aria-label":"踩","aria-expanded":u,"aria-haspopup":"dialog",children:e.jsx(N,{name:"thumbs-down",size:14})})]}),u&&e.jsx("div",{ref:w,children:e.jsx(Ue,{onSubmit:z,onCancel:S})})]})}function Ue({onSubmit:t,onCancel:a}){const[r,n]=o.useState(void 0),[s,i]=o.useState("");return e.jsxs("div",{className:"sa-dislike-panel",children:[e.jsx("div",{className:"sa-dislike-panel-title",children:"请选择不满意的原因(可选)"}),e.jsx("div",{className:"sa-dislike-reasons",children:Ye.map(l=>e.jsx("button",{className:`sa-dislike-reason-btn ${r===l.value?"active":""}`,onClick:()=>n(r===l.value?void 0:l.value),children:l.label},l.value))}),e.jsx("textarea",{className:"sa-dislike-remark",placeholder:"补充描述(选填,≤500 字)",maxLength:500,value:s,onChange:l=>i(l.target.value),rows:2}),e.jsxs("div",{className:"sa-dislike-actions",children:[e.jsx("button",{className:"sa-dislike-submit",onClick:()=>t(r,s||void 0),children:"提交"}),e.jsx("button",{className:"sa-dislike-cancel",onClick:a,children:"取消"})]})]})}function ee({src:t,role:a}){const r=a==="assistant"?"A":"U";return t?t.startsWith("http")||t.startsWith("/")||t.startsWith("data:")?e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:e.jsx("img",{src:t,alt:a,style:{width:"100%",height:"100%",borderRadius:"inherit",objectFit:"cover"}})}):e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:t}):e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:r})}function ye({message:t,isStreaming:a,isLast:r,slots:n,avatar:s,artifactPreview:i}){const{regenerate:l,feedback:c,respondToInterrupt:d}=_(),p=o.useCallback(()=>{var C;const g=t.parts.filter(I=>I.type==="text").map(I=>I.content).join(`
3
+ `);(C=navigator.clipboard)==null||C.writeText(g).catch(()=>{})},[t]),u=t.role==="user",m=n.Message;if(m)return e.jsx(m,{message:t,isStreaming:a,isLast:r,avatar:s,slots:n,onCopy:p,onRegenerate:l,onFeedback:c});const w=n.TextPart??xe,f=n.ThinkingPart??me,x=n.ToolCallPart??he,v=n.ToolResultPart??ge,z=n.ErrorPart??be,S=n.ActionBar??we,E=!u&&t.parts.some(g=>g.type==="text"&&g.content);return e.jsxs("div",{className:`sa-message ${u?"sa-message-user":"sa-message-assistant"}`,children:[!u&&e.jsx(ee,{src:s==null?void 0:s.assistant,role:"assistant"}),e.jsxs("div",{className:"sa-message-content",children:[e.jsx("span",{className:`sa-message-time ${u?"sa-message-time-right":""}`,children:pe(t.timestamp)}),e.jsxs("div",{className:"sa-message-body",children:[t.parts.map((g,C)=>{switch(g.type){case"text":return e.jsx(w,{content:g.content},C);case"thinking":return e.jsx(f,{content:g.content},C);case"tool_call":return e.jsx(x,{toolName:g.toolName,toolCallId:g.toolCallId,args:g.args},C);case"tool_result":return e.jsx(v,{toolName:g.toolName,toolCallId:g.toolCallId,content:g.content,artifacts:g.artifacts,renderMode:g.renderMode,html:g.html,artifactPreview:i},C);case"error":return e.jsx(z,{content:g.content,onRetry:l},C);case"interrupt":return e.jsx(ve,{interrupt:g.interrupt,resolved:g.resolved??!1,response:g.response,onRespond:I=>d(g.interrupt.interruptId,I)},C);default:return null}}),a&&r&&!u&&e.jsx("span",{className:"sa-streaming-cursor",children:"|"}),!u&&!a&&E&&e.jsx(S,{message:t,onCopy:p,onRegenerate:r?l:void 0,onFeedback:c})]})]}),u&&e.jsx(ee,{src:s==null?void 0:s.user,role:"user"})]})}function ke({message:t,suggestedPrompts:a,onPromptClick:r}){return e.jsxs("div",{className:"sa-welcome",children:[e.jsx("div",{className:"sa-welcome-icon",children:e.jsx(N,{name:"sparkles",size:40})}),e.jsx("p",{className:"sa-welcome-message",children:t||"你好!有什么可以帮你的?"}),a&&a.length>0&&e.jsx("div",{className:"sa-welcome-prompts",children:a.map((n,s)=>e.jsx("button",{className:"sa-welcome-prompt",onClick:()=>r(n),children:n},s))})]})}function V({slots:t,welcomeMessage:a,suggestedPrompts:r,avatar:n,artifactPreview:s}){const{messages:i,status:l,sendMessage:c}=_(),{containerRef:d}=fe([i]),p=l==="streaming",u=t.WelcomeScreen??ke;return i.length===0?e.jsx("div",{className:"sa-thread",ref:d,children:e.jsx(u,{message:a,suggestedPrompts:r,onPromptClick:c})}):e.jsx("div",{className:"sa-thread",ref:d,children:i.map((m,w)=>e.jsx(ye,{message:m,isStreaming:p,isLast:w===i.length-1,slots:t,avatar:n,artifactPreview:s},m.id))})}function Ve({items:t,activeIndex:a,onSelect:r}){const n=o.useRef(null);return o.useEffect(()=>{var i;const s=(i=n.current)==null?void 0:i.children[a];s==null||s.scrollIntoView({block:"nearest"})},[a]),t.length===0?e.jsx("div",{className:"sa-slash-menu",children:e.jsx("div",{className:"sa-slash-menu-empty",children:"没有匹配的技能"})}):e.jsx("div",{className:"sa-slash-menu",ref:n,children:t.map((s,i)=>e.jsxs("div",{className:`sa-slash-menu-item${i===a?" sa-slash-menu-item--active":""}`,onMouseDown:l=>{l.preventDefault(),r(s)},children:[e.jsxs("span",{className:"sa-slash-menu-item-name",children:["/",s.name]}),(s.displayName||s.description)&&e.jsx("span",{className:"sa-slash-menu-item-desc",children:s.displayName||s.description})]},s.code))})}function Xe({sdk:t,input:a,onSelect:r}){const[n,s]=o.useState([]),[i,l]=o.useState(!1),[c,d]=o.useState(0),p=o.useRef(!1);o.useEffect(()=>{p.current||(p.current=!0,t.listSkills().then(s).catch(()=>s([])))},[t]);const u=/^\/\S*$/.test(a);o.useEffect(()=>{l(u)},[u]),o.useEffect(()=>{u&&d(0)},[a,u]);const m=a.startsWith("/")?a.slice(1).toLowerCase():"",w=o.useMemo(()=>n.filter(g=>!m||g.code.toLowerCase().includes(m)||g.name.toLowerCase().includes(m)||g.displayName&&g.displayName.toLowerCase().includes(m)),[n,m]),f=o.useRef(i),x=o.useRef(w),v=o.useRef(c),z=o.useRef(r);f.current=i,x.current=w,v.current=c,z.current=r;const S=o.useCallback(g=>{if(!f.current||x.current.length===0)return!1;switch(g.key){case"ArrowDown":return g.preventDefault(),d(C=>(C+1)%x.current.length),!0;case"ArrowUp":return g.preventDefault(),d(C=>(C-1+x.current.length)%x.current.length),!0;case"Enter":case"Tab":return g.preventDefault(),z.current(x.current[v.current]),l(!1),!0;case"Escape":return g.preventDefault(),l(!1),!0;default:return!1}},[]),E=o.useCallback(()=>l(!1),[]);return{isOpen:i,items:w,activeIndex:c,handleKeyDown:S,close:E}}function X(){const{status:t,sendMessage:a,stop:r,sdk:n}=_(),[s,i]=o.useState(""),l=o.useRef(null),c=t==="streaming"||t==="submitted",d=o.useCallback(f=>{i(`/${f.name} `),setTimeout(()=>{const x=l.current;x&&(x.focus(),x.selectionStart=x.selectionEnd=x.value.length)},0)},[]),p=Xe({sdk:n,input:s,onSelect:d}),u=o.useCallback(()=>{const f=s.trim();!f||c||(a(f),i(""),l.current&&(l.current.style.height="auto"))},[s,c,a]),m=o.useCallback(f=>{p.handleKeyDown(f)||f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),u())},[u,p.handleKeyDown]),w=o.useCallback(f=>{i(f.target.value);const x=f.target;x.style.height="auto",x.style.height=Math.min(x.scrollHeight,120)+"px"},[]);return e.jsxs("div",{className:"sa-composer",children:[p.isOpen&&e.jsx(Ve,{items:p.items,activeIndex:p.activeIndex,onSelect:d}),e.jsx("textarea",{ref:l,className:"sa-composer-input",value:s,onChange:w,onKeyDown:m,placeholder:c?"回答生成中...":"输入消息,按 / 选择技能...",rows:1,disabled:c}),c?e.jsx("button",{className:"sa-composer-stop",onClick:r,title:"停止",children:e.jsx(N,{name:"circle-stop",size:16,color:"#fff"})}):e.jsx("button",{className:"sa-composer-send",onClick:u,disabled:!s.trim(),title:"发送",children:e.jsx(N,{name:"arrow-up",size:16,color:"#fff"})})]})}function Ge({artifact:t}){const[a,r]=o.useState(null),[n,s]=o.useState(!0),[i,l]=o.useState(null);return o.useEffect(()=>{let c=!1;s(!0),l(null),r(null);async function d(){try{if(t.type==="pdf"){c||s(!1);return}if(t.type==="html"){const p=await fetch(t.url);if(!p.ok)throw new Error(`HTTP ${p.status}`);const u=await p.text(),m=(await Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs"))).default;c||(r(m.sanitize(u,{FORCE_BODY:!0,ADD_ATTR:["target"]})),s(!1));return}if(t.type==="docx"){const p=await fetch(t.url);if(!p.ok)throw new Error(`HTTP ${p.status}`);const u=await p.arrayBuffer(),w=await(await Promise.resolve().then(()=>require("./mammoth.browser-DiAPPO3x.cjs")).then(x=>x.mammoth_browser)).convertToHtml({arrayBuffer:u}),f=(await Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs"))).default;c||(r(f.sanitize(w.value,{FORCE_BODY:!0,ADD_ATTR:["target"]})),s(!1));return}c||(s(!1),l(`不支持预览「${t.type}」类型`))}catch(p){c||(s(!1),l(p instanceof Error?p.message:"加载失败"))}}return d(),()=>{c=!0}},[t]),n?e.jsx("div",{className:"sa-drawer-preview-loading",children:"加载中"}):i?e.jsxs("div",{className:"sa-drawer-preview-error",children:[i,e.jsx("button",{className:"sa-drawer-btn-sm",onClick:()=>void K(t),children:"下载查看"})]}):t.type==="pdf"?e.jsx("iframe",{src:t.url,title:t.filename,className:"sa-drawer-preview-iframe",sandbox:"allow-scripts"}):a!==null?e.jsx("iframe",{srcDoc:a,title:t.filename,className:"sa-drawer-preview-iframe",sandbox:"allow-same-origin"}):null}function je({artifacts:t,initialArtifact:a,onClose:r}){const[n,s]=o.useState(a?{mode:"preview",artifact:a}:{mode:"list"}),[i,l]=o.useState(!1),c=o.useRef(null),[d,p]=o.useState(340),u=o.useRef(null);o.useEffect(()=>{a&&(c.current&&(clearTimeout(c.current),c.current=null,l(!1)),s({mode:"preview",artifact:a}))},[a]);const m=o.useCallback(()=>{l(!0),c.current=setTimeout(()=>{c.current=null,r()},240)},[r]);o.useEffect(()=>()=>{var v;c.current&&clearTimeout(c.current),(v=u.current)==null||v.call(u)},[]);const w=o.useCallback(v=>{s({mode:"preview",artifact:v})},[]),f=o.useCallback(()=>{s({mode:"list"})},[]);o.useEffect(()=>{const v=z=>{z.key==="Escape"&&m()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[m]);const x=o.useCallback(v=>{v.preventDefault();const z=v.clientX,S=d,E=C=>{const I=z-C.clientX;p(Math.max(240,Math.min(window.innerWidth*.7,S+I)))},g=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",g),document.body.style.cursor="",document.body.style.userSelect="",u.current=null};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",E),document.addEventListener("mouseup",g),u.current=g},[d]);return e.jsxs("div",{className:`sa-artifact-drawer ${i?"sa-drawer-closing":""}`,style:{width:d},children:[e.jsx("div",{className:"sa-drawer-resize-handle",onMouseDown:x}),e.jsxs("div",{className:"sa-artifact-drawer-header",children:[n.mode==="preview"?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"sa-drawer-btn",onClick:f,title:"返回列表","aria-label":"返回列表",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M15 18l-6-6 6-6"})})}),e.jsx("span",{className:"sa-artifact-drawer-title",children:n.artifact.filename})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0},children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"sa-artifact-drawer-title",children:"会话产物"})]}),e.jsx("div",{style:{flex:1}}),n.mode==="preview"&&e.jsx("button",{className:"sa-drawer-btn",onClick:()=>void K(n.artifact),title:"下载","aria-label":"下载",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})}),e.jsx("button",{className:"sa-drawer-btn",onClick:m,title:"关闭","aria-label":"关闭",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsx("div",{className:"sa-artifact-drawer-body",children:n.mode==="list"?t.length===0?e.jsx("div",{className:"sa-drawer-empty",children:"暂无产物"}):e.jsx("ul",{className:"sa-drawer-file-list",role:"list",children:t.map((v,z)=>e.jsxs("li",{className:"sa-drawer-file-card",onClick:()=>w(v),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),w(v))},tabIndex:0,role:"button","aria-label":`预览 ${v.filename}`,children:[e.jsx("div",{className:"sa-drawer-file-icon",children:e.jsx("span",{className:"sa-artifact-chip-type",children:ne(v.type)})}),e.jsxs("div",{className:"sa-drawer-file-info",children:[e.jsx("span",{className:"sa-drawer-file-name",children:v.filename}),e.jsx("span",{className:"sa-drawer-file-size",children:re(v.size)})]}),e.jsx("button",{className:"sa-drawer-btn",title:"下载","aria-label":`下载 ${v.filename}`,onClick:S=>{S.stopPropagation(),K(v)},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"})})})]},v.id||`artifact-${z}`))}):e.jsx("div",{className:"sa-drawer-view-enter",children:e.jsx(Ge,{artifact:n.artifact})})})]})}function Je({isOpen:t,onClose:a,title:r,slots:n,welcomeMessage:s,suggestedPrompts:i,avatar:l,artifactPreview:c}){const{status:d,sendMessage:p,stop:u,toggleThreadList:m,toggleArtifactDrawer:w,conversations:f,activeConversationId:x,switchConversation:v,newConversation:z,deleteConversation:S,renameConversation:E,isThreadListOpen:g,isArtifactDrawerOpen:C,allArtifacts:I,activePreviewArtifact:L,messagesLoading:j}=_();if(!t)return null;const D=n.Header,y=n.Composer,h=n.ThreadList;return e.jsxs("div",{className:"sa-panel",children:[D?e.jsx(D,{title:r,onClose:a,onToggleThreadList:m}):e.jsx(de,{title:r,onClose:a,onToggleThreadList:m,artifactCount:c?I.length:0,onToggleArtifactDrawer:c?w:void 0}),h&&g?e.jsx(h,{conversations:f,activeSessionId:x,onSwitch:v,onNew:z,onDelete:S,onRename:E}):e.jsx(ue,{}),e.jsxs("div",{className:"sa-panel-content",children:[j?e.jsxs("div",{className:"sa-messages-loading",children:[e.jsx("span",{className:"sa-loading-spinner"}),"加载对话..."]}):e.jsx(V,{slots:n,welcomeMessage:s,suggestedPrompts:i,avatar:l,artifactPreview:c}),c&&C&&e.jsx(je,{artifacts:I,initialArtifact:L,onClose:w})]}),y?e.jsx(y,{status:d,onSend:p,onStop:u}):e.jsx(X,{})]})}function Ze({conversations:t,activeSessionId:a,onSwitch:r,onNew:n,onDelete:s,onRename:i,isCollapsed:l,onToggleCollapse:c,hasMore:d,onLoadMore:p,conversationsLoading:u}){const[m,w]=o.useState(null),[f,x]=o.useState(null),[v,z]=o.useState(null),[S,E]=o.useState(""),g=o.useCallback((y,h)=>{h.stopPropagation(),f===y?(s(y),x(null)):(x(y),setTimeout(()=>x(null),3e3))},[f,s]),C=o.useCallback((y,h,$)=>{$.stopPropagation(),z(y),E(h??"")},[]),I=o.useCallback(y=>{S.trim()&&i(y,S.trim()),z(null)},[S,i]),L=o.useRef(null),j=o.useCallback(()=>{const y=L.current;!y||!d||!p||y.scrollHeight-y.scrollTop-y.clientHeight<50&&p()},[d,p]),D=(()=>{const y=Date.now(),h=[],$=[],M=[];for(const R of t){const b=y-new Date(R.updateTime).getTime();b<864e5?h.push(R):b<6048e5?$.push(R):M.push(R)}const k=[];return h.length&&k.push({label:"今天",items:h}),$.length&&k.push({label:"最近 7 天",items:$}),M.length&&k.push({label:"更早",items:M}),k})();return l?e.jsxs("div",{className:"sa-fp-sidebar sa-fp-sidebar-collapsed",children:[e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:c,title:"展开",children:e.jsx(N,{name:"panel-left",size:18})}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:()=>{n(),c()},title:"新会话",style:{marginTop:4},children:e.jsx(N,{name:"plus",size:18})})]}):e.jsxs("div",{className:"sa-fp-sidebar",children:[e.jsxs("div",{className:"sa-fp-sidebar-header",children:[e.jsxs("button",{className:"sa-fp-sidebar-new",onClick:n,children:[e.jsx(N,{name:"plus",size:15})," ",e.jsx("span",{children:"新会话"})]}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:c,title:"收起侧边栏",children:e.jsx(N,{name:"panel-left-close",size:18})})]}),e.jsxs("div",{className:"sa-fp-sidebar-list",ref:L,onScroll:j,children:[u&&t.length===0&&e.jsx("div",{className:"sa-thread-list-loading",children:"加载中..."}),!u&&t.length===0&&e.jsx("div",{className:"sa-fp-sidebar-empty",children:"开始你的第一个对话"}),D.map(y=>e.jsxs("div",{children:[e.jsx("div",{className:"sa-fp-sidebar-group",children:y.label}),y.items.map(h=>{const $=h.sessionId===a,M=m===h.sessionId,k=f===h.sessionId;return e.jsxs("div",{className:`sa-fp-sidebar-item ${$?"active":""}`,onClick:()=>{v!==h.sessionId&&r(h.sessionId)},onMouseEnter:()=>w(h.sessionId),onMouseLeave:()=>w(null),children:[v===h.sessionId?e.jsx("input",{className:"sa-fp-sidebar-item-edit",value:S,onChange:R=>E(R.target.value),onBlur:()=>I(h.sessionId),onKeyDown:R=>{R.key==="Enter"&&I(h.sessionId),R.key==="Escape"&&z(null)},onClick:R=>R.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"sa-fp-sidebar-item-title",children:h.title||"新会话"}),e.jsxs("div",{className:`sa-fp-sidebar-item-actions ${M&&v!==h.sessionId?"visible":""}`,children:[e.jsx("button",{className:"sa-fp-sidebar-item-action",onClick:R=>C(h.sessionId,h.title,R),title:"重命名",children:e.jsx(N,{name:"pen",size:14})}),e.jsx("button",{className:`sa-fp-sidebar-item-action ${k?"danger":""}`,onClick:R=>g(h.sessionId,R),title:k?"确认删除":"删除",children:e.jsx(N,{name:k?"x":"trash2",size:14})})]})]},h.sessionId)})]},y.label)),d&&e.jsx("div",{className:"sa-thread-list-loading",children:"加载更多..."})]})]})}function Ce({title:t,slots:a,welcomeMessage:r,suggestedPrompts:n,sidebarDefaultOpen:s=!0,onClose:i,avatar:l,artifactPreview:c}){const{status:d,sendMessage:p,stop:u,conversations:m,activeConversationId:w,switchConversation:f,newConversation:x,deleteConversation:v,renameConversation:z,toggleArtifactDrawer:S,isArtifactDrawerOpen:E,allArtifacts:g,activePreviewArtifact:C,hasMore:I,loadMoreConversations:L,conversationsLoading:j,messagesLoading:D}=_(),[y,h]=o.useState(s),$=o.useCallback(()=>h(R=>!R),[]),M=a.ThreadList,k=a.Composer;return e.jsxs("div",{className:"sa-fullpage",children:[M?e.jsx("div",{className:`sa-fp-sidebar-wrapper ${y?"":"sa-fp-sidebar-wrapper-collapsed"}`,children:e.jsx(M,{conversations:m,activeSessionId:w,onSwitch:f,onNew:x,onDelete:v,onRename:z,hasMore:I,onLoadMore:L})}):e.jsx(Ze,{conversations:m,activeSessionId:w,onSwitch:f,onNew:x,onDelete:v,onRename:z,isCollapsed:!y,onToggleCollapse:$,hasMore:I,onLoadMore:L,conversationsLoading:j}),e.jsxs("div",{className:"sa-fp-main",children:[e.jsxs("div",{className:"sa-fp-header",children:[!y&&!M&&e.jsx("button",{className:"sa-fp-header-btn",onClick:$,title:"展开侧边栏",children:e.jsx(N,{name:"panel-left",size:18})}),e.jsx("div",{className:"sa-fp-header-title",children:t}),e.jsxs("div",{className:"sa-fp-header-actions",children:[c&&g.length>0&&e.jsxs("button",{className:"sa-fp-header-btn sa-header-btn-artifact",onClick:S,title:"会话产物",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{children:"产物"})]}),i&&e.jsx("button",{className:"sa-fp-header-btn",onClick:i,title:"关闭",children:e.jsx(N,{name:"x",size:18})})]})]}),e.jsxs("div",{className:"sa-fp-content-row",children:[D?e.jsxs("div",{className:"sa-messages-loading",children:[e.jsx("span",{className:"sa-loading-spinner"}),"加载对话..."]}):e.jsx(V,{slots:a,welcomeMessage:r,suggestedPrompts:n,avatar:l,artifactPreview:c}),c&&E&&e.jsx(je,{artifacts:g,initialArtifact:C,onClose:S})]}),k?e.jsx(k,{status:d,onSend:p,onStop:u}):e.jsx(X,{})]})]})}function Ne(t){const{sdk:a,mode:r="floating",slots:n={},hooks:s={},welcomeMessage:i,suggestedPrompts:l,title:c="AI Assistant",initialOpen:d=!1,onOpenChange:p,sidebarDefaultOpen:u,avatar:m,artifactPreview:w}=t,[f,x]=o.useState(d);o.useEffect(()=>{x(d)},[d]);const v=o.useCallback(()=>{var g,C;const E=!f;x(E),p==null||p(E),E?(g=s.onOpen)==null||g.call(s):(C=s.onClose)==null||C.call(s)},[f,s,p]),z=o.useCallback(()=>{var E;x(!1),p==null||p(!1),(E=s.onClose)==null||E.call(s)},[s,p]),S=n.Trigger??ce;return r==="fullpage"?f?e.jsx(U,{sdk:a,hooks:s,children:e.jsx(Ce,{title:c,slots:n,welcomeMessage:i,suggestedPrompts:l,sidebarDefaultOpen:u,onClose:z,avatar:m,artifactPreview:w})}):null:e.jsxs(U,{sdk:a,hooks:s,children:[e.jsx(S,{isOpen:f,onClick:v}),e.jsx(Je,{isOpen:f,onClose:z,title:c,slots:n,welcomeMessage:i,suggestedPrompts:l,avatar:m,artifactPreview:w})]})}const ze=`
4
4
  [data-super-agent-widget] {
5
5
  --sa-primary-dark: color-mix(in srgb, var(--sa-primary) 82%, #000);
6
6
  --sa-primary-light: color-mix(in srgb, var(--sa-primary) 10%, #fff);
7
7
  --sa-text: #1f2937;
8
8
  --sa-text-muted: #6b7280;
9
+ --sa-text-light: #9ca3af;
9
10
  --sa-border: #e5e7eb;
10
11
  --sa-surface: #f9fafb;
12
+ --sa-hover: #f3f4f6;
11
13
 
12
14
  font-family: var(--sa-font);
13
15
  color: var(--sa-text);
@@ -195,13 +197,19 @@
195
197
  justify-content: flex-end;
196
198
  }
197
199
 
198
- .sa-message-body {
200
+ .sa-message-content {
199
201
  max-width: 78%;
200
202
  display: flex;
201
203
  flex-direction: column;
202
204
  gap: 4px;
203
205
  }
204
206
 
207
+ .sa-message-body {
208
+ display: flex;
209
+ flex-direction: column;
210
+ gap: 4px;
211
+ }
212
+
205
213
  .sa-message-user .sa-message-body {
206
214
  padding: 10px 14px;
207
215
  border-radius: 16px;
@@ -225,6 +233,16 @@
225
233
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
226
234
  }
227
235
 
236
+ .sa-message-time {
237
+ font-size: 11px;
238
+ color: var(--sa-text-muted);
239
+ opacity: 0.7;
240
+ }
241
+
242
+ .sa-message-time-right {
243
+ text-align: right;
244
+ }
245
+
228
246
  .sa-avatar {
229
247
  width: 28px;
230
248
  height: 28px;
@@ -470,12 +488,24 @@
470
488
  }
471
489
 
472
490
  .sa-tool-result-content {
491
+ max-height: 256px;
492
+ overflow: auto;
493
+ margin: 8px 0 0;
473
494
  padding: 10px 12px;
474
495
  color: #4b5563;
475
496
  font-size: 13px;
476
497
  line-height: 1.55;
477
498
  white-space: pre-wrap;
478
499
  word-break: break-word;
500
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
501
+ background: #f9fafb;
502
+ border-radius: 8px;
503
+ }
504
+
505
+ .sa-tool-result-actions {
506
+ display: flex;
507
+ gap: 8px;
508
+ margin: 4px 0;
479
509
  }
480
510
 
481
511
  /* ── Error part ──────────────────────────────────────────── */
@@ -522,12 +552,21 @@
522
552
 
523
553
  .sa-action-bar {
524
554
  display: flex;
555
+ align-items: center;
556
+ flex-wrap: wrap;
525
557
  gap: 6px;
526
558
  margin-top: 6px;
527
559
  position: relative;
528
560
  }
529
561
 
530
562
  .sa-action-btn {
563
+ display: inline-flex;
564
+ align-items: center;
565
+ justify-content: center;
566
+ gap: 4px;
567
+ flex: none;
568
+ white-space: nowrap;
569
+ line-height: 1;
531
570
  padding: 4px 10px;
532
571
  border: none;
533
572
  border-radius: 6px;
@@ -538,6 +577,11 @@
538
577
  transition: color 0.15s ease, background 0.15s ease;
539
578
  }
540
579
 
580
+ .sa-action-btn svg {
581
+ display: block;
582
+ flex: none;
583
+ }
584
+
541
585
  .sa-action-btn:hover {
542
586
  color: var(--sa-text);
543
587
  background: rgba(0, 0, 0, 0.05);
@@ -597,6 +641,7 @@
597
641
  /* ── Composer ────────────────────────────────────────────── */
598
642
 
599
643
  .sa-composer {
644
+ position: relative;
600
645
  display: flex;
601
646
  align-items: flex-end;
602
647
  gap: 10px;
@@ -672,6 +717,62 @@
672
717
  transform: scale(1.05);
673
718
  }
674
719
 
720
+ /* ── Slash Menu ─────────────────────────────────────────── */
721
+
722
+ .sa-slash-menu {
723
+ position: absolute;
724
+ bottom: 100%;
725
+ left: 14px;
726
+ right: 14px;
727
+ max-width: 400px;
728
+ max-height: 200px;
729
+ overflow-y: auto;
730
+ background: var(--sa-surface);
731
+ border: 1px solid var(--sa-border);
732
+ border-radius: 8px;
733
+ box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
734
+ margin-bottom: 4px;
735
+ z-index: 10;
736
+ }
737
+
738
+ .sa-slash-menu-empty {
739
+ padding: 12px 14px;
740
+ color: #9ca3af;
741
+ font-size: 13px;
742
+ text-align: center;
743
+ }
744
+
745
+ .sa-slash-menu-item {
746
+ display: flex;
747
+ align-items: center;
748
+ gap: 8px;
749
+ padding: 8px 14px;
750
+ cursor: pointer;
751
+ transition: background 0.15s ease;
752
+ }
753
+
754
+ .sa-slash-menu-item:hover,
755
+ .sa-slash-menu-item--active {
756
+ background: var(--sa-hover);
757
+ }
758
+
759
+ .sa-slash-menu-item-name {
760
+ font-size: 13px;
761
+ font-weight: 500;
762
+ color: var(--sa-text);
763
+ white-space: nowrap;
764
+ }
765
+
766
+ .sa-slash-menu-item-desc {
767
+ font-size: 12px;
768
+ color: #9ca3af;
769
+ overflow: hidden;
770
+ text-overflow: ellipsis;
771
+ white-space: nowrap;
772
+ flex: 1;
773
+ min-width: 0;
774
+ }
775
+
675
776
  /* ── Thread list ─────────────────────────────────────────── */
676
777
 
677
778
  .sa-thread-list-overlay {
@@ -742,6 +843,45 @@
742
843
  font-size: 14px;
743
844
  }
744
845
 
846
+ .sa-thread-list-loading {
847
+ padding: 12px 16px;
848
+ text-align: center;
849
+ color: #9ca3af;
850
+ font-size: 13px;
851
+ }
852
+
853
+ .sa-thread-list-hint {
854
+ padding: 8px 16px 12px;
855
+ text-align: center;
856
+ color: #d1d5db;
857
+ font-size: 12px;
858
+ }
859
+
860
+ /* 消息区加载态 */
861
+ .sa-messages-loading {
862
+ flex: 1;
863
+ display: flex;
864
+ align-items: center;
865
+ justify-content: center;
866
+ gap: 8px;
867
+ color: #9ca3af;
868
+ font-size: 14px;
869
+ }
870
+
871
+ .sa-loading-spinner {
872
+ width: 16px;
873
+ height: 16px;
874
+ border: 2px solid var(--sa-border, #e5e7eb);
875
+ border-top-color: var(--sa-primary, #6366f1);
876
+ border-radius: 50%;
877
+ animation: sa-spin 0.8s linear infinite;
878
+ flex-shrink: 0;
879
+ }
880
+
881
+ @keyframes sa-spin {
882
+ to { transform: rotate(360deg); }
883
+ }
884
+
745
885
  .sa-thread-group-label {
746
886
  padding: 16px 8px 6px;
747
887
  font-size: 12px;
@@ -773,13 +913,26 @@
773
913
  font-weight: 500;
774
914
  }
775
915
 
776
- .sa-thread-item-title {
916
+ .sa-thread-item-info {
777
917
  flex: 1;
918
+ overflow: hidden;
919
+ display: flex;
920
+ flex-direction: column;
921
+ gap: 2px;
922
+ }
923
+
924
+ .sa-thread-item-title {
778
925
  overflow: hidden;
779
926
  white-space: nowrap;
780
927
  text-overflow: ellipsis;
781
928
  }
782
929
 
930
+ .sa-thread-item-time {
931
+ font-size: 11px;
932
+ color: var(--sa-text-light);
933
+ white-space: nowrap;
934
+ }
935
+
783
936
  .sa-thread-item-edit {
784
937
  width: 100%;
785
938
  padding: 4px 8px;
@@ -791,22 +944,33 @@
791
944
  color: var(--sa-text);
792
945
  }
793
946
 
794
- .sa-thread-item-delete {
947
+ /* 操作按钮组:始终占位(visibility 控制),hover 时显示,高度不变 */
948
+ .sa-thread-item-actions {
949
+ display: flex;
950
+ gap: 2px;
951
+ flex-shrink: 0;
952
+ visibility: hidden;
953
+ }
954
+
955
+ .sa-thread-item:hover .sa-thread-item-actions {
956
+ visibility: visible;
957
+ }
958
+
959
+ .sa-thread-item-action-btn {
795
960
  border: none;
796
961
  background: transparent;
797
962
  color: var(--sa-text-muted);
798
- font-size: 14px;
799
963
  cursor: pointer;
800
- opacity: 0;
801
- transition: opacity 0.15s ease, color 0.15s ease;
802
- }
803
-
804
- .sa-thread-item:hover .sa-thread-item-delete {
805
- opacity: 1;
964
+ padding: 2px;
965
+ border-radius: 4px;
966
+ display: inline-flex;
967
+ align-items: center;
968
+ transition: color 0.15s ease, background 0.15s ease;
806
969
  }
807
970
 
808
- .sa-thread-item-delete:hover {
809
- color: #ef4444;
971
+ .sa-thread-item-action-btn:hover {
972
+ color: var(--sa-primary);
973
+ background: rgba(99,102,241,0.08);
810
974
  }
811
975
 
812
976
  /* ── Welcome ─────────────────────────────────────────────── */
@@ -1042,16 +1206,34 @@
1042
1206
  margin-left: 2px;
1043
1207
  }
1044
1208
 
1045
- .sa-interrupt-resolved {
1046
- display: flex;
1047
- align-items: center;
1048
- gap: 6px;
1049
- padding: 8px 12px;
1050
- border-radius: 8px;
1051
- background: #ecfdf5;
1052
- color: #065f46;
1053
- font-size: 13px;
1054
- margin: 6px 0;
1209
+ .sa-interrupt-submitted {
1210
+ margin-top: 8px;
1211
+ font-size: 12px;
1212
+ color: #9ca3af;
1213
+ }
1214
+
1215
+ .sa-interrupt-btn-answered {
1216
+ background: var(--sa-primary) !important;
1217
+ color: #fff !important;
1218
+ opacity: 0.7;
1219
+ }
1220
+
1221
+ .sa-interrupt-btn:disabled {
1222
+ opacity: 0.5;
1223
+ cursor: not-allowed;
1224
+ }
1225
+
1226
+ .sa-interrupt-option:disabled {
1227
+ opacity: 0.6;
1228
+ cursor: not-allowed;
1229
+ }
1230
+
1231
+ .sa-interrupt-input:disabled,
1232
+ .sa-interrupt-textarea:disabled,
1233
+ .sa-interrupt-select:disabled {
1234
+ opacity: 0.6;
1235
+ cursor: not-allowed;
1236
+ background: #f9fafb;
1055
1237
  }
1056
1238
 
1057
1239
  .sa-interrupt-unknown {
@@ -1100,13 +1282,11 @@
1100
1282
  /* ── Fullpage Layout (DeepSeek-style) ────────────────────────── */
1101
1283
 
1102
1284
  .sa-fullpage {
1103
- position: fixed;
1104
- inset: 0;
1105
- width: 100vw;
1106
- height: 100vh;
1285
+ position: relative;
1286
+ width: 100%;
1287
+ height: 100%;
1107
1288
  display: flex;
1108
- background: #f7f7f8;
1109
- z-index: var(--sa-z-index, 9999);
1289
+ background: var(--sa-bg, #ffffff);
1110
1290
  }
1111
1291
 
1112
1292
  /* Sidebar */
@@ -1114,7 +1294,7 @@
1114
1294
  width: 260px;
1115
1295
  display: flex;
1116
1296
  flex-direction: column;
1117
- background: #f2f2f3;
1297
+ background: var(--sa-surface, #ffffff);
1118
1298
  flex-shrink: 0;
1119
1299
  transition: width 0.2s cubic-bezier(0.16,1,0.3,1);
1120
1300
  overflow: hidden;
@@ -1240,6 +1420,29 @@
1240
1420
  text-overflow: ellipsis;
1241
1421
  }
1242
1422
 
1423
+ .sa-fp-sidebar-item-edit {
1424
+ flex: 1;
1425
+ min-width: 0;
1426
+ padding: 2px 6px;
1427
+ border: 1px solid var(--sa-primary, #6366f1);
1428
+ border-radius: 4px;
1429
+ font-size: 13px;
1430
+ color: #27272a;
1431
+ background: #fff;
1432
+ outline: none;
1433
+ }
1434
+
1435
+ .sa-fp-sidebar-item-actions {
1436
+ display: flex;
1437
+ gap: 2px;
1438
+ flex-shrink: 0;
1439
+ visibility: hidden;
1440
+ }
1441
+
1442
+ .sa-fp-sidebar-item-actions.visible {
1443
+ visibility: visible;
1444
+ }
1445
+
1243
1446
  .sa-fp-sidebar-item-action {
1244
1447
  width: 24px;
1245
1448
  height: 24px;
@@ -1399,8 +1602,9 @@
1399
1602
  .sa-artifact-file-download:active { transform: scale(0.9); }
1400
1603
 
1401
1604
  /* ── Inline HTML rendering (render_mode=html) ── */
1402
- .sa-tool-result-html { margin-top: 8px; border: 1px solid var(--sa-border); border-radius: 8px; overflow: hidden; }
1403
- .sa-tool-result-html-iframe { width: 100%; min-height: 120px; max-height: 400px; border: none; background: #fff; }
1605
+ /* HTML 工具结果:外层滚动容器 + 内层内容层(与 Playground 一致,无 iframe) */
1606
+ .sa-tool-result-html-scroll { margin-top: 8px; max-height: 60vh; overflow: auto; border: 1px solid var(--sa-border); border-radius: 8px; }
1607
+ .sa-tool-result-html { padding: 12px; background: #fff; min-width: 100%; width: max-content; }
1404
1608
 
1405
1609
  /* ── Header artifact button ── */
1406
1610
  .sa-header-btn-artifact {
@@ -1529,4 +1733,4 @@
1529
1733
  from { opacity: 0; transform: translateX(12px); }
1530
1734
  to { opacity: 1; transform: translateX(0); }
1531
1735
  }
1532
- `,ge={primaryColor:"#6366f1",backgroundColor:"#ffffff",fontFamily:"system-ui, -apple-system, sans-serif",borderRadius:16,panelWidth:380,panelHeight:520,zIndex:9999};function be(a){const t={...ge,...a};return[`--sa-primary: ${t.primaryColor}`,`--sa-bg: ${t.backgroundColor}`,`--sa-font: ${t.fontFamily}`,`--sa-radius: ${t.borderRadius}px`,`--sa-panel-width: ${t.panelWidth}px`,`--sa-panel-height: ${t.panelHeight}px`,`--sa-z-index: ${t.zIndex}`].join("; ")}function Fe(a,t){const s=typeof a=="string"?document.querySelector(a):a;if(!s)throw new Error(`Target element not found: ${a}`);const r=document.createElement("div");r.setAttribute("data-super-agent-widget","");const n=be(t.theme??{});if(r.setAttribute("style",n),s.appendChild(r),!document.getElementById("sa-widget-styles")){const d=document.createElement("style");d.id="sa-widget-styles",d.textContent=he,document.head.appendChild(d)}let o=ve.createRoot(r),i=!1;const l=d=>{o&&o.render(c.createElement(me,{...t,initialOpen:d??i,onOpenChange:p=>{i=p}}))};return l(!1),{open(){i=!0,l(!0)},close(){i=!1,l(!1)},destroy(){o&&(o.unmount(),o=null),r.remove()}}}exports.ActionBar=de;exports.ChatProvider=W;exports.ChatWidget=me;exports.Composer=Y;exports.ErrorPart=le;exports.FullpageLayout=xe;exports.Header=ae;exports.Icon=j;exports.InterruptCard=ce;exports.Message=pe;exports.TextPart=re;exports.ThinkingPart=ne;exports.Thread=q;exports.ThreadList=te;exports.ToolCallPart=ie;exports.ToolResultPart=oe;exports.Trigger=ee;exports.WelcomeScreen=fe;exports.defaultTheme=ge;exports.mount=Fe;exports.themeToCSSVars=be;exports.useAutoScroll=se;exports.useChat=U;exports.useChatContext=B;exports.useConversations=X;exports.widgetStyles=he;
1736
+ `,Se={primaryColor:"#6366f1",backgroundColor:"#ffffff",fontFamily:"system-ui, -apple-system, sans-serif",borderRadius:16,panelWidth:380,panelHeight:520,zIndex:9999};function Qe(t,a){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),s=parseInt(t.slice(5,7),16),i=1-a;return`#${Math.round(r*i).toString(16).padStart(2,"0")}${Math.round(n*i).toString(16).padStart(2,"0")}${Math.round(s*i).toString(16).padStart(2,"0")}`}function et(t,a){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),s=parseInt(t.slice(5,7),16);return`#${Math.round(r+(255-r)*a).toString(16).padStart(2,"0")}${Math.round(n+(255-n)*a).toString(16).padStart(2,"0")}${Math.round(s+(255-s)*a).toString(16).padStart(2,"0")}`}function Ie(t){const a={...Se,...t},r=a.primaryColor,n=a.backgroundColor;return[`--sa-primary: ${r}`,`--sa-bg: ${n}`,`--sa-font: ${a.fontFamily}`,`--sa-radius: ${a.borderRadius}px`,`--sa-panel-width: ${a.panelWidth}px`,`--sa-panel-height: ${a.panelHeight}px`,`--sa-z-index: ${a.zIndex}`,`--sa-primary-dark: ${Qe(r,.15)}`,`--sa-primary-light: ${et(r,.9)}`,`--sa-surface: ${n}`,"--sa-border: #e5e7eb","--sa-hover: #f4f4f5","--sa-text: #374151","--sa-text-muted: #9ca3af","--sa-text-light: #6b7280"].join("; ")}function tt(t,a){const r=typeof t=="string"?document.querySelector(t):t;if(!r)throw new Error(`Target element not found: ${t}`);const n=document.createElement("div");n.setAttribute("data-super-agent-widget","");const s=Ie(a.theme??{});if(n.setAttribute("style",`${s}; height: 100%;`),r.appendChild(n),!document.getElementById("sa-widget-styles")){const d=document.createElement("style");d.id="sa-widget-styles",d.textContent=ze,document.head.appendChild(d)}let i=Me.createRoot(n),l=!1;const c=d=>{i&&i.render(o.createElement(Ne,{...a,initialOpen:d??l,onOpenChange:p=>{l=p}}))};return c(!1),{open(){l=!0,c(!0)},close(){l=!1,c(!1)},destroy(){i&&(i.unmount(),i=null),n.remove()}}}exports.ActionBar=we;exports.ChatProvider=U;exports.ChatWidget=Ne;exports.Composer=X;exports.ErrorPart=be;exports.FullpageLayout=Ce;exports.Header=de;exports.Icon=N;exports.InterruptCard=ve;exports.Message=ye;exports.TextPart=xe;exports.ThinkingPart=me;exports.Thread=V;exports.ThreadList=ue;exports.ToolCallPart=he;exports.ToolResultPart=ge;exports.Trigger=ce;exports.WelcomeScreen=ke;exports.defaultTheme=Se;exports.ensureIconFont=le;exports.mount=tt;exports.themeToCSSVars=Ie;exports.useAutoScroll=fe;exports.useChat=te;exports.useChatContext=_;exports.useConversations=se;exports.widgetStyles=ze;