super-agent-sdk 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -65
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +83 -10
- package/dist/index.mjs +260 -202
- package/dist/mammoth.browser-COPV53yV.js +14917 -0
- package/dist/mammoth.browser-DiAPPO3x.cjs +230 -0
- package/dist/purify.es-C-6FFqDW.js +898 -0
- package/dist/purify.es-Dsdnkgrg.cjs +3 -0
- package/dist/widget.cjs +399 -5
- package/dist/widget.d.ts +119 -16
- package/dist/widget.mjs +1729 -637
- package/package.json +8 -3
package/dist/widget.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),fe=require("react-dom/client"),e=require("react/jsx-runtime");function K(a){const{sdk:s,sessionId:l,onSessionCreated:r,onStreamStart:t,onStreamEnd:i,onError:c,onMessageSend:n}=a,[o,u]=d.useState([]),[f,m]=d.useState("ready"),[v,b]=d.useState(null),x=d.useRef(null),g=d.useRef(!1),h=d.useRef(l);h.current=l;const p=d.useCallback(C=>{if(g.current)return;g.current=!0,n==null||n(C);const L={id:`user_${Date.now()}`,role:"user",parts:[{type:"text",content:C}],timestamp:Date.now()},z=`assistant_${Date.now()}`,pe={id:z,role:"assistant",parts:[],timestamp:Date.now()};u(N=>[...N,L,pe]),m("submitted"),b(null);const _=N=>{let A="",T="",R=[],F=!1;const $=()=>{const y=[...R];if(A){const E=y.findIndex(M=>M.type==="thinking");E>=0?y[E]={type:"thinking",content:A}:y.unshift({type:"thinking",content:A})}if(T){const E=y.findLastIndex(M=>M.type==="text");E>=0?y[E]={type:"text",content:T}:y.push({type:"text",content:T})}u(E=>E.map(M=>M.id===z?{...M,parts:y}:M))};x.current=s.chat({sessionId:N,message:C,stream:!0,onMessage:y=>{switch(F||(F=!0,m("streaming")),y.type){case"thinking":A+=y.content;break;case"ai":T+=y.content;break;case"tool_call":R.push({type:"tool_call",toolName:y.toolName,toolCallId:y.toolCallId,args:y.args??"{}"});break;case"tool_result":R.push({type:"tool_result",toolName:y.toolName??"",toolCallId:y.toolCallId,content:y.content}),T&&(R.push({type:"text",content:T}),T="");break}$()},onDone:y=>{(T||R.length>0||A)&&$(),y.sessionId&&y.sessionId!==h.current&&(r==null||r(y.sessionId)),i==null||i(y.sessionId||N),m("ready"),g.current=!1,x.current=null},onError:y=>{R.push({type:"error",content:y.message}),$(),b(y),m("error"),c==null||c(y),g.current=!1,x.current=null}}),t==null||t(N)};h.current?_(h.current):s.createSession().then(N=>{h.current=N,r==null||r(N),_(N)}).catch(N=>{b(N instanceof Error?N:new Error(String(N))),m("error"),c==null||c(N instanceof Error?N:new Error(String(N))),g.current=!1})},[s,r,t,i,c,n]),w=d.useCallback(()=>{var C;(C=x.current)==null||C.abort(),x.current=null,m("ready"),g.current=!1},[]),j=d.useCallback(()=>{if(g.current)return;const C=o.findLastIndex(z=>z.role==="user");if(C<0)return;const L=o[C].parts.filter(z=>z.type==="text").map(z=>z.content).join("");u(z=>z.slice(0,C)),p(L)},[o,p]);return{messages:o,status:f,error:v,sendMessage:p,stop:w,regenerate:j,setMessages:u}}const D="sa_active_conversation";function W(){try{return localStorage.getItem(D)}catch{return null}}function ue(a){try{a?localStorage.setItem(D,a):localStorage.removeItem(D)}catch{}}function U(a){const{sdk:s,onConversationChange:l}=a,[r,t]=d.useState([]),[i,c]=d.useState(()=>W()),[n,o]=d.useState(!1),u=d.useRef(!0);d.useEffect(()=>()=>{u.current=!1},[]);const f=d.useCallback(p=>{c(p),ue(p),p&&(l==null||l(p))},[l]),m=d.useCallback(async()=>{o(!0);try{const p=await s.listConversations({page:1,size:100});if(!u.current)return;t(p.items);const w=W();w&&!p.items.find(j=>j.sessionId===w)&&f(null)}catch{}finally{u.current&&o(!1)}},[s,f]),v=d.useCallback(async p=>(f(p),await s.getMessages(p)),[s,f]),b=d.useCallback(()=>{f(null)},[f]),x=d.useCallback(async p=>{await s.deleteConversation(p),t(w=>w.filter(j=>j.sessionId!==p)),i===p&&f(null)},[s,i,f]),g=d.useCallback(async(p,w)=>{await s.renameConversation(p,w),t(j=>j.map(C=>C.sessionId===p?{...C,title:w}:C))},[s]),{enabled:h=!0}=a;return d.useEffect(()=>{h&&m()},[h,m]),{conversations:r,activeConversationId:i,loading:n,loadConversations:m,switchConversation:v,newConversation:b,deleteConversation:x,renameConversation:g,setActiveConversationId:f}}const V=d.createContext(null);function I(){const a=d.useContext(V);if(!a)throw new Error("useChatContext must be used within ChatProvider");return a}function O({sdk:a,hooks:s,children:l}){const[r,t]=d.useState(!1),[i,c]=d.useState(!1);d.useEffect(()=>{a.getToken().then(()=>{c(!0)}).catch(()=>{c(!0)})},[a]);const n=U({sdk:a,onConversationChange:s==null?void 0:s.onConversationChange,enabled:i}),o=K({sdk:a,sessionId:n.activeConversationId,onSessionCreated:x=>{n.setActiveConversationId(x),n.loadConversations()},onStreamStart:s==null?void 0:s.onStreamStart,onStreamEnd:x=>{var g;(g=s==null?void 0:s.onStreamEnd)==null||g.call(s,x),n.loadConversations()},onError:s==null?void 0:s.onError,onMessageSend:s==null?void 0:s.onMessageSend}),u=d.useCallback(async x=>{const g=await n.switchConversation(x);o.setMessages(g),t(!1)},[n,o]),f=d.useCallback(()=>{n.newConversation(),o.setMessages([]),t(!1)},[n,o]),m=d.useCallback(async x=>{await n.deleteConversation(x),n.activeConversationId===x&&o.setMessages([])},[n,o]);d.useEffect(()=>{n.activeConversationId&&o.messages.length===0&&a.getMessages(n.activeConversationId).then(x=>{o.setMessages(x)}).catch(()=>{})},[]);const v=d.useCallback(()=>{t(x=>!x)},[]),b={status:o.status,error:o.error,messages:o.messages,conversations:n.conversations,activeConversationId:n.activeConversationId,isThreadListOpen:r,sendMessage:o.sendMessage,stop:o.stop,regenerate:o.regenerate,switchConversation:u,newConversation:f,deleteConversation:m,renameConversation:n.renameConversation,toggleThreadList:v,feedback:(x,g)=>{a.feedback(x,g)}};return e.jsx(V.Provider,{value:b,children:l})}function k({name:a,size:s=16,color:l="currentColor",className:r,style:t}){return e.jsx("svg",{className:r,style:{width:s,height:s,fill:l,verticalAlign:"middle",...t},"aria-hidden":"true",children:e.jsx("use",{href:`#icon-${a}`})})}function Y({isOpen:a,onClick:s}){return e.jsx("button",{className:`sa-trigger ${a?"sa-trigger-open":""}`,onClick:s,children:a?e.jsx(k,{name:"x",size:24,color:"#fff"}):e.jsx(k,{name:"message-square",size:24,color:"#fff"})})}function J({title:a,onClose:s,onToggleThreadList:l,showClose:r=!0}){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:[e.jsx("button",{className:"sa-header-btn",onClick:l,title:"会话列表",children:e.jsx(k,{name:"menu",size:16})}),r&&e.jsx("button",{className:"sa-header-btn",onClick:s,title:"关闭",children:e.jsx(k,{name:"x",size:16})})]})]})}function xe(a){const s=new Date,l=new Date(s.getFullYear(),s.getMonth(),s.getDate()).getTime(),r=l-6*864e5,t=[],i=[],c=[];for(const o of a){const u=new Date(o.updateTime).getTime();u>=l?t.push(o):u>=r?i.push(o):c.push(o)}const n=[];return t.length&&n.push({label:"今天",items:t}),i.length&&n.push({label:"最近 7 天",items:i}),c.length&&n.push({label:"更早",items:c}),n}function X(){const{conversations:a,activeConversationId:s,switchConversation:l,newConversation:r,deleteConversation:t,renameConversation:i,isThreadListOpen:c,toggleThreadList:n}=I(),[o,u]=d.useState(null),[f,m]=d.useState(""),v=d.useCallback((g,h)=>{u(g),m(h??"")},[]),b=d.useCallback(g=>{f.trim()&&i(g,f.trim()),u(null)},[f,i]),x=d.useMemo(()=>xe(a),[a]);return c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-thread-list-overlay",onClick:n}),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(k,{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:"暂无会话"}),x.map(g=>e.jsxs("div",{className:"sa-thread-group",children:[e.jsx("div",{className:"sa-thread-group-label",children:g.label}),g.items.map(h=>e.jsxs("div",{className:`sa-thread-item ${h.sessionId===s?"active":""}`,onClick:()=>l(h.sessionId),children:[o===h.sessionId?e.jsx("input",{className:"sa-thread-item-edit",value:f,onChange:p=>m(p.target.value),onBlur:()=>b(h.sessionId),onKeyDown:p=>{p.key==="Enter"&&b(h.sessionId),p.key==="Escape"&&u(null)},onClick:p=>p.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"sa-thread-item-title",onDoubleClick:p=>{p.stopPropagation(),v(h.sessionId,h.title)},children:h.title||"新会话"}),e.jsx("button",{className:"sa-thread-item-delete",onClick:p=>{p.stopPropagation(),t(h.sessionId)},title:"删除",children:e.jsx(k,{name:"trash2",size:14})})]},h.sessionId))]},g.label))]})]})]}):null}function G(a){const s=d.useRef(null),l=d.useRef(!1),r=d.useRef(0),t=d.useCallback(()=>{const c=s.current;if(!c)return;const{scrollTop:n,scrollHeight:o,clientHeight:u}=c,f=o-n-u<40;n<r.current&&!f&&(l.current=!0),f&&(l.current=!1),r.current=n},[]);d.useEffect(()=>{const c=s.current;if(c)return c.addEventListener("scroll",t,{passive:!0}),()=>c.removeEventListener("scroll",t)},[t]),d.useEffect(()=>{if(l.current)return;const c=s.current;c&&requestAnimationFrame(()=>{c.scrollTop=c.scrollHeight})},a);const i=d.useCallback(()=>{l.current=!1;const c=s.current;c&&(c.scrollTop=c.scrollHeight)},[]);return{containerRef:s,scrollToBottom:i}}function S(a){return a.value++}function P(a,s){const l=[],r=[],t=()=>{r.length>0&&(l.push(r.join("")),r.length=0)};let i=0;for(;i<a.length;){const c=a[i];if(c==="`"){const n=a.indexOf("`",i+1);if(n!==-1){t(),l.push(e.jsx("code",{className:"sa-inline-code",children:a.slice(i+1,n)},S(s))),i=n+1;continue}}else if(c==="*"&&a[i+1]==="*"){const n=a.indexOf("**",i+2);if(n!==-1){t(),l.push(e.jsx("strong",{children:P(a.slice(i+2,n),s)},S(s))),i=n+2;continue}}else if(c==="*"){const n=a.indexOf("*",i+1);if(n!==-1){t(),l.push(e.jsx("em",{children:P(a.slice(i+1,n),s)},S(s))),i=n+1;continue}}else if(c==="["){const n=a.indexOf("]",i+1);if(n!==-1&&a[n+1]==="("){const o=a.indexOf(")",n+2);if(o!==-1){const u=a.slice(i+1,n),f=a.slice(n+2,o);t(),l.push(e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",children:P(u,s)},S(s))),i=o+1;continue}}}r.push(c),i++}return t(),l}function he(a,s){const l=[],r=a.split(`
|
|
2
|
-
`);let t=0;const i=o=>o.trim()==="",c=o=>/^#{1,6}\s+\S/.test(o.trim()),n=o=>/^(?:[-*+]|\d+[.)])\s+\S/.test(o.trim());for(;t<r.length;){const o=r[t],u=o.trim();if(i(o)){t++;continue}if(c(o)){const m=u.match(/^(#{1,6})\s+(.*)$/);if(m){const b=`h${Math.min(m[1].length,6)}`;l.push(d.createElement(b,{key:S(s)},P(m[2],s)))}t++;continue}if(n(o)){const m=/^\d+[.)]/.test(u),v=[];for(;t<r.length&&n(r[t]);){const b=r[t].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);b&&v.push(e.jsx("li",{children:P(b[1],s)},S(s))),t++}l.push(m?e.jsx("ol",{className:"sa-list",children:v},S(s)):e.jsx("ul",{className:"sa-list",children:v},S(s)));continue}const f=[];for(;t<r.length&&!i(r[t])&&!c(r[t])&&!n(r[t]);)f.push(r[t]),t++;l.push(e.jsx("p",{className:"sa-text-paragraph",children:P(f.join(" "),s)},S(s)))}return l}function me(a){const s={value:0},l=[],r=a.split("```");for(let t=0;t<r.length;t++)if(t%2===0)l.push(...he(r[t],s));else if(r[t].trim()!==""){let i=r[t].replace(/^\r?\n/,"");i=i.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/,""),i=i.replace(/\r?\n$/,""),l.push(e.jsx("pre",{className:"sa-code-block",children:e.jsx("code",{children:i})},S(s)))}return l}function Z({content:a}){return e.jsx("div",{className:"sa-text-part",children:me(a)})}function Q({content:a}){const[s,l]=d.useState(!1);return e.jsxs("div",{className:"sa-thinking-part",onClick:()=>l(!s),children:[e.jsxs("div",{className:"sa-thinking-header",children:[e.jsx("span",{className:"sa-thinking-icon",children:e.jsx(k,{name:"brain",size:14})}),e.jsx("span",{className:"sa-thinking-label",children:"思考过程"}),e.jsx("span",{className:`sa-thinking-arrow ${s?"expanded":""}`,children:e.jsx(k,{name:"chevron-right",size:12})})]}),s&&e.jsx("div",{className:"sa-thinking-content",children:a})]})}function ee({toolName:a,toolCallId:s,args:l}){const[r,t]=d.useState(!1);let i=l;try{i=JSON.stringify(JSON.parse(l),null,2)}catch{}return e.jsxs("div",{className:"sa-tool-call-part",children:[e.jsxs("div",{className:"sa-tool-call-header",onClick:()=>t(!r),children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(k,{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(k,{name:"chevron-right",size:12})})]}),r&&e.jsx("pre",{className:"sa-tool-args",children:i})]})}function se({toolName:a,toolCallId:s,content:l}){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(k,{name:"circle-check",size:14,color:"#10b981"})}),e.jsx("span",{className:"sa-tool-result-label",children:a||"工具返回"})]}),e.jsx("div",{className:"sa-tool-result-content",children:l})]})}function ae({content:a,onRetry:s}){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(k,{name:"triangle-alert",size:14})}),e.jsx("span",{children:a})]}),s&&e.jsx("button",{className:"sa-error-retry",onClick:s,children:"重试"})]})}function te({message:a,onCopy:s,onRegenerate:l,onFeedback:r}){const{status:t}=I(),[i,c]=d.useState(null),[n,o]=d.useState(!1);if(t!=="ready"&&t!=="error")return null;const u=d.useCallback(()=>{s(),o(!0),setTimeout(()=>o(!1),2e3)},[s]),f=d.useCallback(m=>{const v=i===m?null:m;c(v),v&&(r==null||r(a.id,v))},[i,a.id,r]);return e.jsxs("div",{className:"sa-action-bar",children:[e.jsxs("button",{className:"sa-action-btn",onClick:u,title:"复制",children:[e.jsx(k,{name:n?"circle-check":"copy",size:14})," ",n?"已复制":"复制"]}),e.jsxs("button",{className:"sa-action-btn",onClick:l,title:"重新生成",children:[e.jsx(k,{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:()=>f("like"),title:"有用",children:e.jsx(k,{name:"thumbs-up",size:14})}),e.jsx("button",{className:`sa-action-btn ${i==="dislike"?"sa-action-btn-active":""}`,onClick:()=>f("dislike"),title:"无用",children:e.jsx(k,{name:"thumbs-down",size:14})})]})}function q({src:a,role:s}){const l=s==="assistant"?"A":"U";return a?a.startsWith("http")||a.startsWith("/")||a.startsWith("data:")?e.jsx("div",{className:`sa-avatar sa-avatar-${s}`,children:e.jsx("img",{src:a,alt:s,style:{width:"100%",height:"100%",borderRadius:"inherit",objectFit:"cover"}})}):e.jsx("div",{className:`sa-avatar sa-avatar-${s}`,children:a}):e.jsx("div",{className:`sa-avatar sa-avatar-${s}`,children:l})}function re({message:a,isStreaming:s,isLast:l,slots:r,avatar:t}){const{regenerate:i,feedback:c}=I(),n=d.useCallback(()=>{var p;const h=a.parts.filter(w=>w.type==="text").map(w=>w.content).join(`
|
|
3
|
-
`);(p=navigator.clipboard)==null||p.writeText(h).catch(()=>{})},[a]),o=a.role==="user",u=r.Message;if(u)return e.jsx(u,{message:a,isStreaming:s,isLast:l,avatar:t,slots:r,onCopy:n,onRegenerate:i,onFeedback:c});const f=r.TextPart??Z,m=r.ThinkingPart??Q,v=r.ToolCallPart??ee,b=r.ToolResultPart??se,x=r.ErrorPart??ae,g=r.ActionBar??te;return e.jsxs("div",{className:`sa-message ${o?"sa-message-user":"sa-message-assistant"}`,children:[!o&&e.jsx(q,{src:t==null?void 0:t.assistant,role:"assistant"}),e.jsxs("div",{className:"sa-message-body",children:[a.parts.map((h,p)=>{switch(h.type){case"text":return e.jsx(f,{content:h.content},p);case"thinking":return e.jsx(m,{content:h.content},p);case"tool_call":return e.jsx(v,{toolName:h.toolName,toolCallId:h.toolCallId,args:h.args},p);case"tool_result":return e.jsx(b,{toolName:h.toolName,toolCallId:h.toolCallId,content:h.content},p);case"error":return e.jsx(x,{content:h.content,onRetry:i},p);default:return null}}),s&&l&&!o&&e.jsx("span",{className:"sa-streaming-cursor",children:"|"}),!o&&!s&&a.parts.length>0&&e.jsx(g,{message:a,onCopy:n,onRegenerate:i,onFeedback:c})]}),o&&e.jsx(q,{src:t==null?void 0:t.user,role:"user"})]})}function ne({message:a,suggestedPrompts:s,onPromptClick:l}){return e.jsxs("div",{className:"sa-welcome",children:[e.jsx("div",{className:"sa-welcome-icon",children:e.jsx(k,{name:"sparkles",size:40})}),e.jsx("p",{className:"sa-welcome-message",children:a||"你好!有什么可以帮你的?"}),s&&s.length>0&&e.jsx("div",{className:"sa-welcome-prompts",children:s.map((r,t)=>e.jsx("button",{className:"sa-welcome-prompt",onClick:()=>l(r),children:r},t))})]})}function H({slots:a,welcomeMessage:s,suggestedPrompts:l,avatar:r}){const{messages:t,status:i,sendMessage:c}=I(),{containerRef:n}=G([t]),o=i==="streaming",u=a.WelcomeScreen??ne;return t.length===0?e.jsx("div",{className:"sa-thread",ref:n,children:e.jsx(u,{message:s,suggestedPrompts:l,onPromptClick:c})}):e.jsx("div",{className:"sa-thread",ref:n,children:t.map((f,m)=>e.jsx(re,{message:f,isStreaming:o,isLast:m===t.length-1,slots:a,avatar:r},f.id))})}function B(){const{status:a,sendMessage:s,stop:l}=I(),[r,t]=d.useState(""),i=d.useRef(null),c=a==="streaming"||a==="submitted",n=d.useCallback(()=>{const f=r.trim();!f||c||(s(f),t(""),i.current&&(i.current.style.height="auto"))},[r,c,s]),o=d.useCallback(f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),n())},[n]),u=d.useCallback(f=>{t(f.target.value);const m=f.target;m.style.height="auto",m.style.height=Math.min(m.scrollHeight,120)+"px"},[]);return e.jsxs("div",{className:"sa-composer",children:[e.jsx("textarea",{ref:i,className:"sa-composer-input",value:r,onChange:u,onKeyDown:o,placeholder:"输入消息...",rows:1,disabled:a==="submitted"}),c?e.jsx("button",{className:"sa-composer-stop",onClick:l,title:"停止",children:e.jsx(k,{name:"circle-stop",size:16,color:"#fff"})}):e.jsx("button",{className:"sa-composer-send",onClick:n,disabled:!r.trim(),title:"发送",children:e.jsx(k,{name:"arrow-up",size:16,color:"#fff"})})]})}function ge({isOpen:a,onClose:s,title:l,slots:r,welcomeMessage:t,suggestedPrompts:i,avatar:c}){const{status:n,sendMessage:o,stop:u,toggleThreadList:f,conversations:m,activeConversationId:v,switchConversation:b,newConversation:x,deleteConversation:g,renameConversation:h,isThreadListOpen:p}=I();if(!a)return null;const w=r.Header,j=r.Composer,C=r.ThreadList;return e.jsxs("div",{className:"sa-panel",children:[w?e.jsx(w,{title:l,onClose:s,onToggleThreadList:f}):e.jsx(J,{title:l,onClose:s,onToggleThreadList:f}),C&&p?e.jsx(C,{conversations:m,activeSessionId:v,onSwitch:b,onNew:x,onDelete:g,onRename:h}):e.jsx(X,{}),e.jsx(H,{slots:r,welcomeMessage:t,suggestedPrompts:i,avatar:c}),j?e.jsx(j,{status:n,onSend:o,onStop:u}):e.jsx(B,{})]})}function be({conversations:a,activeSessionId:s,onSwitch:l,onNew:r,onDelete:t,isCollapsed:i,onToggleCollapse:c}){const[n,o]=d.useState(null),[u,f]=d.useState(null),m=d.useCallback((b,x)=>{x.stopPropagation(),u===b?(t(b),f(null)):(f(b),setTimeout(()=>f(null),3e3))},[u,t]),v=(()=>{const b=Date.now(),x=[],g=[],h=[];for(const w of a){const j=b-new Date(w.updateTime).getTime();j<864e5?x.push(w):j<6048e5?g.push(w):h.push(w)}const p=[];return x.length&&p.push({label:"今天",items:x}),g.length&&p.push({label:"最近 7 天",items:g}),h.length&&p.push({label:"更早",items:h}),p})();return i?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(k,{name:"panel-left",size:18})}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:r,title:"新会话",style:{marginTop:4},children:e.jsx(k,{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(k,{name:"plus",size:15})," ",e.jsx("span",{children:"新会话"})]}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:c,title:"收起侧边栏",children:e.jsx(k,{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:"开始你的第一个对话"}),v.map(b=>e.jsxs("div",{children:[e.jsx("div",{className:"sa-fp-sidebar-group",children:b.label}),b.items.map(x=>{const g=x.sessionId===s,h=n===x.sessionId,p=u===x.sessionId;return e.jsxs("div",{className:`sa-fp-sidebar-item ${g?"active":""}`,onClick:()=>l(x.sessionId),onMouseEnter:()=>o(x.sessionId),onMouseLeave:()=>o(null),children:[e.jsx("span",{className:"sa-fp-sidebar-item-title",children:x.title||"新会话"}),h&&e.jsx("button",{className:`sa-fp-sidebar-item-action ${p?"danger":""}`,onClick:w=>m(x.sessionId,w),title:p?"确认删除":"删除",children:e.jsx(k,{name:p?"x":"trash2",size:14})})]},x.sessionId)})]},b.label))]})]})}function ie({title:a,slots:s,welcomeMessage:l,suggestedPrompts:r,sidebarDefaultOpen:t=!0,onClose:i,avatar:c}){const{status:n,sendMessage:o,stop:u,conversations:f,activeConversationId:m,switchConversation:v,newConversation:b,deleteConversation:x,renameConversation:g}=I(),[h,p]=d.useState(t),w=d.useCallback(()=>p(L=>!L),[]),j=s.ThreadList,C=s.Composer;return e.jsxs("div",{className:"sa-fullpage",children:[j?e.jsx("div",{className:`sa-fp-sidebar-wrapper ${h?"":"sa-fp-sidebar-wrapper-collapsed"}`,children:e.jsx(j,{conversations:f,activeSessionId:m,onSwitch:v,onNew:b,onDelete:x,onRename:g})}):e.jsx(be,{conversations:f,activeSessionId:m,onSwitch:v,onNew:b,onDelete:x,onRename:g,isCollapsed:!h,onToggleCollapse:w}),e.jsxs("div",{className:"sa-fp-main",children:[e.jsxs("div",{className:"sa-fp-header",children:[!h&&!j&&e.jsx("button",{className:"sa-fp-header-btn",onClick:w,title:"展开侧边栏",children:e.jsx(k,{name:"panel-left",size:18})}),e.jsx("div",{className:"sa-fp-header-title",children:a}),e.jsx("div",{className:"sa-fp-header-actions",children:i&&e.jsx("button",{className:"sa-fp-header-btn",onClick:i,title:"关闭",children:e.jsx(k,{name:"x",size:18})})})]}),e.jsx(H,{slots:s,welcomeMessage:l,suggestedPrompts:r,avatar:c}),C?e.jsx(C,{status:n,onSend:o,onStop:u}):e.jsx(B,{})]})]})}function oe(a){const{sdk:s,mode:l="floating",slots:r={},hooks:t={},welcomeMessage:i,suggestedPrompts:c,title:n="AI Assistant",initialOpen:o=!1,onOpenChange:u,sidebarDefaultOpen:f,avatar:m}=a,[v,b]=d.useState(o);d.useEffect(()=>{b(o)},[o]);const x=d.useCallback(()=>{var w,j;const p=!v;b(p),u==null||u(p),p?(w=t.onOpen)==null||w.call(t):(j=t.onClose)==null||j.call(t)},[v,t,u]),g=d.useCallback(()=>{var p;b(!1),u==null||u(!1),(p=t.onClose)==null||p.call(t)},[t,u]),h=r.Trigger??Y;return l==="fullpage"?v?e.jsx(O,{sdk:s,hooks:t,children:e.jsx(ie,{title:n,slots:r,welcomeMessage:i,suggestedPrompts:c,sidebarDefaultOpen:f,onClose:g,avatar:m})}):null:e.jsxs(O,{sdk:s,hooks:t,children:[e.jsx(h,{isOpen:v,onClick:x}),e.jsx(ge,{isOpen:v,onClose:g,title:n,slots:r,welcomeMessage:i,suggestedPrompts:c,avatar:m})]})}const le=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),ve=require("react-dom/client"),e=require("react/jsx-runtime");function U(a){const{sdk:t,sessionId:r,onSessionCreated:s,onStreamStart:n,onStreamEnd:o,onError:i,onMessageSend:l}=a,[c,p]=d.useState([]),[f,u]=d.useState("ready"),[m,v]=d.useState(null),y=d.useRef(null),h=d.useRef(!1),b=d.useRef(r);b.current=r;const x=d.useCallback(S=>{if(h.current)return;h.current=!0,l==null||l(S);const A={id:`user_${Date.now()}`,role:"user",parts:[{type:"text",content:S}],timestamp:Date.now()},k=`assistant_${Date.now()}`,I={id:k,role:"assistant",parts:[],timestamp:Date.now()};p(z=>[...z,A,I]),u("submitted"),v(null);const D=z=>{let M="",E="",P=[],C=!1;const L=()=>{const w=[...P];if(M){const O=w.findIndex($=>$.type==="thinking");O>=0?w[O]={type:"thinking",content:M}:w.unshift({type:"thinking",content:M})}if(E){const O=w.findLastIndex($=>$.type==="text");O>=0?w[O]={type:"text",content:E}:w.push({type:"text",content:E})}p(O=>O.map($=>$.id===k?{...$,parts:w}:$))};y.current=t.chat({sessionId:z,message:S,stream:!0,onMessage:w=>{switch(C||(C=!0,u("streaming")),w.type){case"thinking":M+=w.content;break;case"ai":E+=w.content;break;case"tool_call":P.push({type:"tool_call",toolName:w.toolName,toolCallId:w.toolCallId,args:w.args??"{}"});break;case"tool_result":P.push({type:"tool_result",toolName:w.toolName??"",toolCallId:w.toolCallId,content:w.content,artifacts:w.artifacts,renderMode:w.renderMode,html:w.html}),E&&(P.push({type:"text",content:E}),E="");break;case"interrupt":w.interrupt&&P.push({type:"interrupt",interrupt:w.interrupt,resolved:!1});break}L()},onDone:w=>{(E||P.length>0||M)&&L(),w.messageId&&p(O=>O.map($=>$.id===k?{...$,id:w.messageId}:$)),w.sessionId&&w.sessionId!==b.current&&(s==null||s(w.sessionId)),o==null||o(w.sessionId||z),u("ready"),h.current=!1,y.current=null},onError:w=>{P.push({type:"error",content:w.message}),L(),v(w),u("error"),i==null||i(w),h.current=!1,y.current=null}}),n==null||n(z)};b.current?D(b.current):t.createSession().then(z=>{b.current=z,s==null||s(z),D(z)}).catch(z=>{v(z instanceof Error?z:new Error(String(z))),u("error"),i==null||i(z instanceof Error?z:new Error(String(z))),h.current=!1})},[t,s,n,o,i,l]),g=d.useCallback(()=>{var S;(S=y.current)==null||S.abort(),y.current=null,u("ready"),h.current=!1},[]),N=d.useCallback(()=>{if(h.current)return;const S=c.findLastIndex(k=>k.role==="user");if(S<0)return;const A=c[S].parts.filter(k=>k.type==="text").map(k=>k.content).join("");p(k=>k.slice(0,S)),x(A)},[c,x]),T=d.useCallback((S,A)=>{p(C=>C.map(L=>({...L,parts:L.parts.map(w=>w.type==="interrupt"&&w.interrupt.interruptId===S?{...w,resolved:!0,response:A}:w)})));const k=b.current;if(!k)return;const I=`assistant_${Date.now()}`,D={id:I,role:"assistant",parts:[],timestamp:Date.now()};p(C=>[...C,D]),u("streaming");let z="",M="",E=[];const P=()=>{const C=[...E];if(z){const L=C.findIndex(w=>w.type==="thinking");L>=0?C[L]={type:"thinking",content:z}:C.unshift({type:"thinking",content:z})}if(M){const L=C.findLastIndex(w=>w.type==="text");L>=0?C[L]={type:"text",content:M}:C.push({type:"text",content:M})}p(L=>L.map(w=>w.id===I?{...w,parts:C}:w))};t.respondInterrupt(S,k,A,C=>{switch(C.type){case"thinking":z+=C.content;break;case"ai":M+=C.content;break;case"tool_call":E.push({type:"tool_call",toolName:C.toolName,toolCallId:C.toolCallId,args:C.args??"{}"});break;case"tool_result":E.push({type:"tool_result",toolName:C.toolName??"",toolCallId:C.toolCallId,content:C.content,artifacts:C.artifacts,renderMode:C.renderMode,html:C.html}),M&&(E.push({type:"text",content:M}),M="");break;case"interrupt":C.interrupt&&E.push({type:"interrupt",interrupt:C.interrupt,resolved:!1});break;case"done":u("ready");break}P()},C=>{E.push({type:"error",content:C.message}),P(),v(C),u("error"),i==null||i(C)}).catch(C=>{i==null||i(C instanceof Error?C:new Error(String(C))),u("error")})},[t,i]);return{messages:c,status:f,error:m,sendMessage:x,stop:g,regenerate:N,setMessages:p,respondToInterrupt:T}}const F="sa_active_conversation";function V(){try{return localStorage.getItem(F)}catch{return null}}function we(a){try{a?localStorage.setItem(F,a):localStorage.removeItem(F)}catch{}}function X(a){const{sdk:t,onConversationChange:r}=a,[s,n]=d.useState([]),[o,i]=d.useState(()=>V()),[l,c]=d.useState(!1),p=d.useRef(!0);d.useEffect(()=>()=>{p.current=!1},[]);const f=d.useCallback(x=>{i(x),we(x),x&&(r==null||r(x))},[r]),u=d.useCallback(async()=>{c(!0);try{const x=await t.listConversations({page:1,size:100});if(!p.current)return;n(x.items);const g=V();g&&!x.items.find(N=>N.sessionId===g)&&f(null)}catch{}finally{p.current&&c(!1)}},[t,f]),m=d.useCallback(async x=>(f(x),await t.getMessages(x)),[t,f]),v=d.useCallback(()=>{f(null)},[f]),y=d.useCallback(async x=>{await t.deleteConversation(x),n(g=>g.filter(N=>N.sessionId!==x)),o===x&&f(null)},[t,o,f]),h=d.useCallback(async(x,g)=>{await t.renameConversation(x,g),n(N=>N.map(T=>T.sessionId===x?{...T,title:g}:T))},[t]),{enabled:b=!0}=a;return d.useEffect(()=>{b&&u()},[b,u]),{conversations:s,activeConversationId:o,loading:l,loadConversations:u,switchConversation:m,newConversation:v,deleteConversation:y,renameConversation:h,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 r of a)r.type==="file"&&r.data&&t.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 t}async function _(a){try{const t=await fetch(a.url);if(!t.ok)throw new Error(`HTTP ${t.status}`);const r=await t.blob(),s=URL.createObjectURL(r),n=document.createElement("a");n.href=s,n.download=a.filename,document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(s),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=d.createContext(null);function B(){const a=d.useContext(Q);if(!a)throw new Error("useChatContext must be used within ChatProvider");return a}function W({sdk:a,hooks:t,children:r}){const[s,n]=d.useState(!1),[o,i]=d.useState(!1),[l,c]=d.useState(null),[p,f]=d.useState(!1);d.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 I;(I=t==null?void 0:t.onStreamEnd)==null||I.call(t,k),u.loadConversations()},onError:t==null?void 0:t.onError,onMessageSend:t==null?void 0:t.onMessageSend}),v=d.useCallback(async k=>{const I=await u.switchConversation(k);m.setMessages(I),n(!1)},[u,m]),y=d.useCallback(()=>{u.newConversation(),m.setMessages([]),n(!1)},[u,m]),h=d.useCallback(async k=>{await u.deleteConversation(k),u.activeConversationId===k&&m.setMessages([])},[u,m]);d.useEffect(()=>{u.activeConversationId&&m.messages.length===0&&a.getMessages(u.activeConversationId).then(k=>{m.setMessages(k)}).catch(()=>{})},[]);const b=d.useCallback(()=>{n(k=>!k)},[]),x=d.useCallback(()=>{i(k=>!k),c(k=>null)},[]),g=d.useCallback(k=>{c(k),i(!0)},[]),N=d.useMemo(()=>{const k=new Set,I=[];for(const D of m.messages)for(const z of D.parts)if(z.type==="tool_result"&&z.artifacts)for(const M of Z(z.artifacts)){const E=M.id||`${M.url}:${M.filename}`;k.has(E)||(k.add(E),I.push(M))}return I},[m.messages]),T=d.useCallback((k,I,D)=>{a.feedback(k,I,D).catch(()=>{})},[a]),S=d.useCallback(k=>{a.cancelFeedback(k).catch(()=>{})},[a]),A=d.useMemo(()=>({status:m.status,error:m.error,messages:m.messages,conversations:u.conversations,activeConversationId:u.activeConversationId,isThreadListOpen:s,isArtifactDrawerOpen:o,allArtifacts:N,activePreviewArtifact:l,sendMessage:m.sendMessage,stop:m.stop,regenerate:m.regenerate,switchConversation:v,newConversation:y,deleteConversation:h,renameConversation:u.renameConversation,toggleThreadList:b,toggleArtifactDrawer:x,openArtifactPreview:g,feedback:T,cancelFeedback:S,respondToInterrupt:m.respondToInterrupt}),[m.status,m.error,m.messages,m.sendMessage,m.stop,m.regenerate,m.respondToInterrupt,u.conversations,u.activeConversationId,u.renameConversation,s,o,N,l,v,y,h,b,x,g,T,S]);return e.jsx(Q.Provider,{value:A,children:r})}function j({name:a,size:t=16,color:r="currentColor",className:s,style:n}){return e.jsx("svg",{className:s,style:{width:t,height:t,fill:r,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:r,showClose:s=!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:r,title:"会话列表",children:e.jsx(j,{name:"menu",size:16})}),s&&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,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),s=r-6*864e5,n=[],o=[],i=[];for(const c of a){const p=new Date(c.updateTime).getTime();p>=r?n.push(c):p>=s?o.push(c):i.push(c)}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:r,newConversation:s,deleteConversation:n,renameConversation:o,isThreadListOpen:i,toggleThreadList:l}=B(),[c,p]=d.useState(null),[f,u]=d.useState(""),m=d.useCallback((h,b)=>{p(h),u(b??"")},[]),v=d.useCallback(h=>{f.trim()&&o(h,f.trim()),p(null)},[f,o]),y=d.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:s,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(h=>e.jsxs("div",{className:"sa-thread-group",children:[e.jsx("div",{className:"sa-thread-group-label",children:h.label}),h.items.map(b=>e.jsxs("div",{className:`sa-thread-item ${b.sessionId===t?"active":""}`,onClick:()=>r(b.sessionId),children:[c===b.sessionId?e.jsx("input",{className:"sa-thread-item-edit",value:f,onChange:x=>u(x.target.value),onBlur:()=>v(b.sessionId),onKeyDown:x=>{x.key==="Enter"&&v(b.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(b.sessionId,b.title)},children:b.title||"新会话"}),e.jsx("button",{className:"sa-thread-item-delete",onClick:x=>{x.stopPropagation(),n(b.sessionId)},title:"删除",children:e.jsx(j,{name:"trash2",size:14})})]},b.sessionId))]},h.label))]})]})]}):null}function se(a){const t=d.useRef(null),r=d.useRef(!1),s=d.useRef(0),n=d.useCallback(()=>{const i=t.current;if(!i)return;const{scrollTop:l,scrollHeight:c,clientHeight:p}=i,f=c-l-p<40;l<s.current&&!f&&(r.current=!0),f&&(r.current=!1),s.current=l},[]);d.useEffect(()=>{const i=t.current;if(i)return i.addEventListener("scroll",n,{passive:!0}),()=>i.removeEventListener("scroll",n)},[n]),d.useEffect(()=>{if(r.current)return;const i=t.current;i&&requestAnimationFrame(()=>{i.scrollTop=i.scrollHeight})},a);const o=d.useCallback(()=>{r.current=!1;const i=t.current;i&&(i.scrollTop=i.scrollHeight)},[]);return{containerRef:t,scrollToBottom:o}}function R(a){return a.value++}function H(a,t){const r=[],s=[],n=()=>{s.length>0&&(r.push(s.join("")),s.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(),r.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(),r.push(e.jsx("strong",{children:H(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(),r.push(e.jsx("em",{children:H(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 c=a.indexOf(")",l+2);if(c!==-1){const p=a.slice(o+1,l),f=a.slice(l+2,c);n(),r.push(e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",children:H(p,t)},R(t))),o=c+1;continue}}}s.push(i),o++}return n(),r}function ye(a,t){const r=[],s=a.split(`
|
|
2
|
+
`);let n=0;const o=c=>c.trim()==="",i=c=>/^#{1,6}\s+\S/.test(c.trim()),l=c=>/^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());for(;n<s.length;){const c=s[n],p=c.trim();if(o(c)){n++;continue}if(i(c)){const u=p.match(/^(#{1,6})\s+(.*)$/);if(u){const v=`h${Math.min(u[1].length,6)}`;r.push(d.createElement(v,{key:R(t)},H(u[2],t)))}n++;continue}if(l(c)){const u=/^\d+[.)]/.test(p),m=[];for(;n<s.length&&l(s[n]);){const v=s[n].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);v&&m.push(e.jsx("li",{children:H(v[1],t)},R(t))),n++}r.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<s.length&&!o(s[n])&&!i(s[n])&&!l(s[n]);)f.push(s[n]),n++;r.push(e.jsx("p",{className:"sa-text-paragraph",children:H(f.join(" "),t)},R(t)))}return r}function je(a){const t={value:0},r=[],s=a.split("```");for(let n=0;n<s.length;n++)if(n%2===0)r.push(...ye(s[n],t));else if(s[n].trim()!==""){let o=s[n].replace(/^\r?\n/,"");o=o.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/,""),o=o.replace(/\r?\n$/,""),r.push(e.jsx("pre",{className:"sa-code-block",children:e.jsx("code",{children:o})},R(t)))}return r}function re({content:a}){return e.jsx("div",{className:"sa-text-part",children:je(a)})}function ne({content:a}){const[t,r]=d.useState(!1);return e.jsxs("div",{className:"sa-thinking-part",onClick:()=>r(!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:r}){const[s,n]=d.useState(!1);let o=r;try{o=JSON.stringify(JSON.parse(r),null,2)}catch{}return e.jsxs("div",{className:"sa-tool-call-part",children:[e.jsxs("div",{className:"sa-tool-call-header",onClick:()=>n(!s),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 ${s?"expanded":""}`,children:e.jsx(j,{name:"chevron-right",size:12})})]}),s&&e.jsx("pre",{className:"sa-tool-args",children:o})]})}function Ce({html:a}){const[t,r]=d.useState(null);return d.useEffect(()=>{let s=!1;return Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs")).then(n=>{s||r(n.default.sanitize(a,{FORCE_BODY:!0}))}),()=>{s=!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:r,renderMode:s,html:n,artifactPreview:o}){const{openArtifactPreview:i}=B(),l=Z(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(j,{name:"circle-check",size:14,color:"#10b981"})}),e.jsx("span",{className:"sa-tool-result-label",children:a||"工具返回"})]}),s==="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((c,p)=>e.jsxs("li",{className:"sa-artifact-file-card",onClick:o?()=>i(c):void 0,onKeyDown:o?f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),i(c))}:void 0,tabIndex:o?0:void 0,role:o?"button":void 0,"aria-label":o?`预览 ${c.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(c.type)})}),e.jsxs("div",{className:"sa-artifact-file-info",children:[e.jsx("span",{className:"sa-artifact-file-name",children:c.filename}),c.size!=null&&e.jsx("span",{className:"sa-artifact-file-size",children:J(c.size)})]}),o&&e.jsx("button",{className:"sa-artifact-file-download",title:"下载","aria-label":`下载 ${c.filename}`,onClick:f=>{f.stopPropagation(),_(c)},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"})})})]},c.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 r=a.options,s=(typeof(r==null?void 0:r[0])=="string"?r[0]:(o=r==null?void 0:r[0])==null?void 0:o.label)||"确认",n=(typeof(r==null?void 0:r[1])=="string"?r[1]:(i=r==null?void 0:r[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})," ",s]}),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,c,p,f;const r=a.options,s=(typeof(r==null?void 0:r[0])=="string"?r[0]:(l=r==null?void 0:r[0])==null?void 0:l.label)||"批准",n=(typeof(r==null?void 0:r[1])=="string"?r[1]:(c=r==null?void 0:r[1])==null?void 0:c.label)||"拒绝",o=(typeof(r==null?void 0:r[2])=="string"?r[2]:(p=r==null?void 0:r[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})," ",s]}),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 Te({interrupt:a,onRespond:t}){const r=(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:r.map(s=>e.jsxs("button",{className:`sa-interrupt-option ${s.danger?"sa-interrupt-option-danger":""}`,onClick:()=>t({action:"select",value:s.value}),children:[s.icon&&e.jsx(j,{name:s.icon,size:14}),e.jsx("span",{children:s.label}),s.description&&e.jsx("span",{className:"sa-interrupt-option-desc",children:s.description})]},s.value))})]})}function Ie(a){return typeof a=="string"?{value:a,label:a}:a}function Me({interrupt:a,onRespond:t}){const r=(a.options??[]).map(Ie),[s,n]=d.useState(new Set),o=i=>{n(l=>{const c=new Set(l);return c.has(i)?c.delete(i):c.add(i),c})};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:r.map(i=>e.jsxs("button",{className:`sa-interrupt-option ${s.has(i.value)?"sa-interrupt-option-selected":""}`,onClick:()=>o(i.value),children:[e.jsx(j,{name:s.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:s.size===0,onClick:()=>t({action:"submit",value:Array.from(s)}),children:[e.jsx(j,{name:"check",size:14})," 确认 (",s.size,")"]})})]})}function Ee({interrupt:a,onRespond:t}){const[r,s]=d.useState(""),n=a.inputType??"text",o=n==="textarea",i=()=>{a.required&&!r.trim()||t({action:"submit",value:r.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:r,onChange:l=>s(l.target.value),placeholder:a.placeholder,maxLength:a.maxLength,rows:3}):e.jsx("input",{className:"sa-interrupt-input",type:n,value:r,onChange:l=>s(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?!r.trim():!1,onClick:i,children:[e.jsx(j,{name:"check",size:14})," 提交"]})})]})}function De({interrupt:a,onRespond:t}){const r=a.fields??[],[s,n]=d.useState(()=>{const c={};for(const p of r)c[p.name]=p.defaultValue??"";return c}),o=(c,p)=>{n(f=>({...f,[c]:p}))},i=r.every(c=>!c.required||s[c.name]),l=()=>{i&&t({action:"submit",value:s})};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:r.map(c=>e.jsxs("div",{className:"sa-interrupt-form-field",children:[e.jsxs("label",{className:"sa-interrupt-form-label",children:[c.label,c.required&&e.jsx("span",{className:"sa-interrupt-form-required",children:"*"})]}),Le(c,s[c.name],p=>o(c.name,p))]},c.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 Le(a,t,r){switch(a.type){case"textarea":return e.jsx("textarea",{className:"sa-interrupt-textarea",value:t,onChange:s=>r(s.target.value),placeholder:a.placeholder,rows:3});case"select":return e.jsxs("select",{className:"sa-interrupt-select",value:t,onChange:s=>r(s.target.value),children:[e.jsx("option",{value:"",children:"请选择"}),(a.options??[]).map(s=>e.jsx("option",{value:s,children:s},s))]});default:return e.jsx("input",{className:"sa-interrupt-input",type:a.type,value:t,onChange:s=>r(s.target.value),placeholder:a.placeholder})}}function ce({interrupt:a,resolved:t,response:r,onRespond:s}){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,r)})]});switch(a.interruptType){case"confirm":return e.jsx(Ne,{interrupt:a,onRespond:s});case"approve":return e.jsx(ze,{interrupt:a,onRespond:s});case"select":return e.jsx(Te,{interrupt:a,onRespond:s});case"multiSelect":return e.jsx(Me,{interrupt:a,onRespond:s});case"input":return e.jsx(Ee,{interrupt:a,onRespond:s});case"form":return e.jsx(De,{interrupt:a,onRespond:s});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 $e=[{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:r,onFeedback:s}){const{status:n,feedback:o,cancelFeedback:i}=B(),[l,c]=d.useState(null),[p,f]=d.useState(!1),[u,m]=d.useState(!1);if(n!=="ready"&&n!=="error")return null;const v=d.useCallback(()=>{t(),f(!0),setTimeout(()=>f(!1),2e3)},[t]),y=d.useCallback(()=>{l==="like"?(c(null),i(a.id)):(c("like"),m(!1),o(a.id,"like"),s==null||s(a.id,"like"))},[l,a.id,o,i,s]),h=d.useCallback(()=>{l==="dislike"?(c(null),m(!1),i(a.id)):m(!0)},[l,a.id,i]),b=d.useCallback((x,g)=>{c("dislike"),m(!1),o(a.id,"dislike",{reason:x,remark:g}),s==null||s(a.id,"dislike")},[a.id,o,s]);return e.jsxs("div",{className:"sa-action-bar",children:[e.jsxs("button",{className:"sa-action-btn",onClick:v,title:"复制",children:[e.jsx(j,{name:p?"circle-check":"copy",size:14})," ",p?"已复制":"复制"]}),e.jsxs("button",{className:"sa-action-btn",onClick:r,title:"重新生成",children:[e.jsx(j,{name:"refresh-cw",size:14})," 重新生成"]}),e.jsx("span",{className:"sa-action-divider"}),e.jsx("button",{className:`sa-action-btn ${l==="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 ${l==="dislike"?"sa-action-btn-active":""}`,onClick:h,title:"无用","aria-label":"踩",children:e.jsx(j,{name:"thumbs-down",size:14})}),u&&e.jsx(Pe,{onSubmit:b,onCancel:()=>m(!1)})]})}function Pe({onSubmit:a,onCancel:t}){const[r,s]=d.useState(void 0),[n,o]=d.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:$e.map(i=>e.jsx("button",{className:`sa-dislike-reason-btn ${r===i.value?"active":""}`,onClick:()=>s(r===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(r,n||void 0),children:"提交"}),e.jsx("button",{className:"sa-dislike-cancel",onClick:t,children:"取消"})]})]})}function K({src:a,role:t}){const r=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:r})}function pe({message:a,isStreaming:t,isLast:r,slots:s,avatar:n,artifactPreview:o}){const{regenerate:i,feedback:l,respondToInterrupt:c}=B(),p=d.useCallback(()=>{var N;const g=a.parts.filter(T=>T.type==="text").map(T=>T.content).join(`
|
|
3
|
+
`);(N=navigator.clipboard)==null||N.writeText(g).catch(()=>{})},[a]),f=a.role==="user",u=s.Message;if(u)return e.jsx(u,{message:a,isStreaming:t,isLast:r,avatar:n,slots:s,onCopy:p,onRegenerate:i,onFeedback:l});const m=s.TextPart??re,v=s.ThinkingPart??ne,y=s.ToolCallPart??ie,h=s.ToolResultPart??oe,b=s.ErrorPart??le,x=s.ActionBar??de;return e.jsxs("div",{className:`sa-message ${f?"sa-message-user":"sa-message-assistant"}`,children:[!f&&e.jsx(K,{src:n==null?void 0:n.assistant,role:"assistant"}),e.jsxs("div",{className:"sa-message-body",children:[a.parts.map((g,N)=>{switch(g.type){case"text":return e.jsx(m,{content:g.content},N);case"thinking":return e.jsx(v,{content:g.content},N);case"tool_call":return e.jsx(y,{toolName:g.toolName,toolCallId:g.toolCallId,args:g.args},N);case"tool_result":return e.jsx(h,{toolName:g.toolName,toolCallId:g.toolCallId,content:g.content,artifacts:g.artifacts,renderMode:g.renderMode,html:g.html,artifactPreview:o},N);case"error":return e.jsx(b,{content:g.content,onRetry:i},N);case"interrupt":return e.jsx(ce,{interrupt:g.interrupt,resolved:g.resolved??!1,response:g.response,onRespond:T=>c(g.interrupt.interruptId,T)},N);default:return null}}),t&&r&&!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(K,{src:n==null?void 0:n.user,role:"user"})]})}function fe({message:a,suggestedPrompts:t,onPromptClick:r}){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((s,n)=>e.jsx("button",{className:"sa-welcome-prompt",onClick:()=>r(s),children:s},n))})]})}function q({slots:a,welcomeMessage:t,suggestedPrompts:r,avatar:s,artifactPreview:n}){const{messages:o,status:i,sendMessage:l}=B(),{containerRef:c}=se([o]),p=i==="streaming",f=a.WelcomeScreen??fe;return o.length===0?e.jsx("div",{className:"sa-thread",ref:c,children:e.jsx(f,{message:t,suggestedPrompts:r,onPromptClick:l})}):e.jsx("div",{className:"sa-thread",ref:c,children:o.map((u,m)=>e.jsx(pe,{message:u,isStreaming:p,isLast:m===o.length-1,slots:a,avatar:s,artifactPreview:n},u.id))})}function Y(){const{status:a,sendMessage:t,stop:r}=B(),[s,n]=d.useState(""),o=d.useRef(null),i=a==="streaming"||a==="submitted",l=d.useCallback(()=>{const f=s.trim();!f||i||(t(f),n(""),o.current&&(o.current.style.height="auto"))},[s,i,t]),c=d.useCallback(f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),l())},[l]),p=d.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:s,onChange:p,onKeyDown:c,placeholder:"输入消息...",rows:1,disabled:a==="submitted"}),i?e.jsx("button",{className:"sa-composer-stop",onClick:r,title:"停止",children:e.jsx(j,{name:"circle-stop",size:16,color:"#fff"})}):e.jsx("button",{className:"sa-composer-send",onClick:l,disabled:!s.trim(),title:"发送",children:e.jsx(j,{name:"arrow-up",size:16,color:"#fff"})})]})}function Re({artifact:a}){const[t,r]=d.useState(null),[s,n]=d.useState(!0),[o,i]=d.useState(null);return d.useEffect(()=>{let l=!1;n(!0),i(null),r(null);async function c(){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||(r(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}),v=(await Promise.resolve().then(()=>require("./purify.es-Dsdnkgrg.cjs"))).default;l||(r(v.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 c(),()=>{l=!0}},[a]),s?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 _(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:r}){const[s,n]=d.useState(t?{mode:"preview",artifact:t}:{mode:"list"}),[o,i]=d.useState(!1),l=d.useRef(null),[c,p]=d.useState(340),f=d.useRef(null);d.useEffect(()=>{t&&(l.current&&(clearTimeout(l.current),l.current=null,i(!1)),n({mode:"preview",artifact:t}))},[t]);const u=d.useCallback(()=>{i(!0),l.current=setTimeout(()=>{l.current=null,r()},240)},[r]);d.useEffect(()=>()=>{var h;l.current&&clearTimeout(l.current),(h=f.current)==null||h.call(f)},[]);const m=d.useCallback(h=>{n({mode:"preview",artifact:h})},[]),v=d.useCallback(()=>{n({mode:"list"})},[]);d.useEffect(()=>{const h=b=>{b.key==="Escape"&&u()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[u]);const y=d.useCallback(h=>{h.preventDefault();const b=h.clientX,x=c,g=T=>{const S=b-T.clientX;p(Math.max(240,Math.min(window.innerWidth*.7,x+S)))},N=()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",N),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",g),document.addEventListener("mouseup",N),f.current=N},[c]);return e.jsxs("div",{className:`sa-artifact-drawer ${o?"sa-drawer-closing":""}`,style:{width:c},children:[e.jsx("div",{className:"sa-drawer-resize-handle",onMouseDown:y}),e.jsxs("div",{className:"sa-artifact-drawer-header",children:[s.mode==="preview"?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"sa-drawer-btn",onClick:v,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:s.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}}),s.mode==="preview"&&e.jsx("button",{className:"sa-drawer-btn",onClick:()=>void _(s.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:s.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((h,b)=>e.jsxs("li",{className:"sa-drawer-file-card",onClick:()=>m(h),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),m(h))},tabIndex:0,role:"button","aria-label":`预览 ${h.filename}`,children:[e.jsx("div",{className:"sa-drawer-file-icon",children:e.jsx("span",{className:"sa-artifact-chip-type",children:G(h.type)})}),e.jsxs("div",{className:"sa-drawer-file-info",children:[e.jsx("span",{className:"sa-drawer-file-name",children:h.filename}),e.jsx("span",{className:"sa-drawer-file-size",children:J(h.size)})]}),e.jsx("button",{className:"sa-drawer-btn",title:"下载","aria-label":`下载 ${h.filename}`,onClick:x=>{x.stopPropagation(),_(h)},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"})})})]},h.id||`artifact-${b}`))}):e.jsx("div",{className:"sa-drawer-view-enter",children:e.jsx(Re,{artifact:s.artifact})})})]})}function Oe({isOpen:a,onClose:t,title:r,slots:s,welcomeMessage:n,suggestedPrompts:o,avatar:i,artifactPreview:l}){const{status:c,sendMessage:p,stop:f,toggleThreadList:u,toggleArtifactDrawer:m,conversations:v,activeConversationId:y,switchConversation:h,newConversation:b,deleteConversation:x,renameConversation:g,isThreadListOpen:N,isArtifactDrawerOpen:T,allArtifacts:S,activePreviewArtifact:A}=B();if(!a)return null;const k=s.Header,I=s.Composer,D=s.ThreadList;return e.jsxs("div",{className:"sa-panel",children:[k?e.jsx(k,{title:r,onClose:t,onToggleThreadList:u}):e.jsx(ae,{title:r,onClose:t,onToggleThreadList:u,artifactCount:l?S.length:0,onToggleArtifactDrawer:l?m:void 0}),D&&N?e.jsx(D,{conversations:v,activeSessionId:y,onSwitch:h,onNew:b,onDelete:x,onRename:g}):e.jsx(te,{}),e.jsxs("div",{className:"sa-panel-content",children:[e.jsx(q,{slots:s,welcomeMessage:n,suggestedPrompts:o,avatar:i,artifactPreview:l}),l&&T&&e.jsx(ue,{artifacts:S,initialArtifact:A,onClose:m})]}),I?e.jsx(I,{status:c,onSend:p,onStop:f}):e.jsx(Y,{})]})}function Be({conversations:a,activeSessionId:t,onSwitch:r,onNew:s,onDelete:n,isCollapsed:o,onToggleCollapse:i}){const[l,c]=d.useState(null),[p,f]=d.useState(null),u=d.useCallback((v,y)=>{y.stopPropagation(),p===v?(n(v),f(null)):(f(v),setTimeout(()=>f(null),3e3))},[p,n]),m=(()=>{const v=Date.now(),y=[],h=[],b=[];for(const g of a){const N=v-new Date(g.updateTime).getTime();N<864e5?y.push(g):N<6048e5?h.push(g):b.push(g)}const x=[];return y.length&&x.push({label:"今天",items:y}),h.length&&x.push({label:"最近 7 天",items:h}),b.length&&x.push({label:"更早",items:b}),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:s,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:s,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(v=>e.jsxs("div",{children:[e.jsx("div",{className:"sa-fp-sidebar-group",children:v.label}),v.items.map(y=>{const h=y.sessionId===t,b=l===y.sessionId,x=p===y.sessionId;return e.jsxs("div",{className:`sa-fp-sidebar-item ${h?"active":""}`,onClick:()=>r(y.sessionId),onMouseEnter:()=>c(y.sessionId),onMouseLeave:()=>c(null),children:[e.jsx("span",{className:"sa-fp-sidebar-item-title",children:y.title||"新会话"}),b&&e.jsx("button",{className:`sa-fp-sidebar-item-action ${x?"danger":""}`,onClick:g=>u(y.sessionId,g),title:x?"确认删除":"删除",children:e.jsx(j,{name:x?"x":"trash2",size:14})})]},y.sessionId)})]},v.label))]})]})}function xe({title:a,slots:t,welcomeMessage:r,suggestedPrompts:s,sidebarDefaultOpen:n=!0,onClose:o,avatar:i,artifactPreview:l}){const{status:c,sendMessage:p,stop:f,conversations:u,activeConversationId:m,switchConversation:v,newConversation:y,deleteConversation:h,renameConversation:b,toggleArtifactDrawer:x,isArtifactDrawerOpen:g,allArtifacts:N,activePreviewArtifact:T}=B(),[S,A]=d.useState(n),k=d.useCallback(()=>A(z=>!z),[]),I=t.ThreadList,D=t.Composer;return e.jsxs("div",{className:"sa-fullpage",children:[I?e.jsx("div",{className:`sa-fp-sidebar-wrapper ${S?"":"sa-fp-sidebar-wrapper-collapsed"}`,children:e.jsx(I,{conversations:u,activeSessionId:m,onSwitch:v,onNew:y,onDelete:h,onRename:b})}):e.jsx(Be,{conversations:u,activeSessionId:m,onSwitch:v,onNew:y,onDelete:h,onRename:b,isCollapsed:!S,onToggleCollapse:k}),e.jsxs("div",{className:"sa-fp-main",children:[e.jsxs("div",{className:"sa-fp-header",children:[!S&&!I&&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&&N.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:r,suggestedPrompts:s,avatar:i,artifactPreview:l}),l&&g&&e.jsx(ue,{artifacts:N,initialArtifact:T,onClose:x})]}),D?e.jsx(D,{status:c,onSend:p,onStop:f}):e.jsx(Y,{})]})]})}function me(a){const{sdk:t,mode:r="floating",slots:s={},hooks:n={},welcomeMessage:o,suggestedPrompts:i,title:l="AI Assistant",initialOpen:c=!1,onOpenChange:p,sidebarDefaultOpen:f,avatar:u,artifactPreview:m}=a,[v,y]=d.useState(c);d.useEffect(()=>{y(c)},[c]);const h=d.useCallback(()=>{var N,T;const g=!v;y(g),p==null||p(g),g?(N=n.onOpen)==null||N.call(n):(T=n.onClose)==null||T.call(n)},[v,n,p]),b=d.useCallback(()=>{var g;y(!1),p==null||p(!1),(g=n.onClose)==null||g.call(n)},[n,p]),x=s.Trigger??ee;return r==="fullpage"?v?e.jsx(W,{sdk:t,hooks:n,children:e.jsx(xe,{title:l,slots:s,welcomeMessage:o,suggestedPrompts:i,sidebarDefaultOpen:f,onClose:b,avatar:u,artifactPreview:m})}):null:e.jsxs(W,{sdk:t,hooks:n,children:[e.jsx(x,{isOpen:v,onClick:h}),e.jsx(Oe,{isOpen:v,onClose:b,title:l,slots:s,welcomeMessage:o,suggestedPrompts:i,avatar:u,artifactPreview:m})]})}const he=`
|
|
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);
|
|
@@ -524,6 +524,7 @@
|
|
|
524
524
|
display: flex;
|
|
525
525
|
gap: 6px;
|
|
526
526
|
margin-top: 6px;
|
|
527
|
+
position: relative;
|
|
527
528
|
}
|
|
528
529
|
|
|
529
530
|
.sa-action-btn {
|
|
@@ -555,6 +556,44 @@
|
|
|
555
556
|
align-self: center;
|
|
556
557
|
}
|
|
557
558
|
|
|
559
|
+
/* ── Dislike Panel ── */
|
|
560
|
+
.sa-dislike-panel {
|
|
561
|
+
position: absolute; bottom: 100%; left: 0; right: 0;
|
|
562
|
+
margin-bottom: 6px; padding: 12px;
|
|
563
|
+
background: #fff; border: 1px solid var(--sa-border); border-radius: 10px;
|
|
564
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.08);
|
|
565
|
+
animation: sa-fade-in-up 0.2s cubic-bezier(0.16,1,0.3,1) both;
|
|
566
|
+
z-index: 10;
|
|
567
|
+
}
|
|
568
|
+
.sa-dislike-panel-title { font-size: 13px; font-weight: 500; color: var(--sa-text); margin-bottom: 8px; }
|
|
569
|
+
.sa-dislike-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
|
|
570
|
+
.sa-dislike-reason-btn {
|
|
571
|
+
padding: 4px 10px; border: 1px solid var(--sa-border); border-radius: 6px;
|
|
572
|
+
background: #fff; color: var(--sa-text); font-size: 12px; cursor: pointer;
|
|
573
|
+
transition: border-color 0.15s, background 0.15s, color 0.15s;
|
|
574
|
+
}
|
|
575
|
+
.sa-dislike-reason-btn:hover { border-color: var(--sa-primary); color: var(--sa-primary); }
|
|
576
|
+
.sa-dislike-reason-btn.active { background: var(--sa-primary); color: #fff; border-color: var(--sa-primary); }
|
|
577
|
+
.sa-dislike-remark {
|
|
578
|
+
width: 100%; padding: 8px 10px; border: 1px solid var(--sa-border); border-radius: 8px;
|
|
579
|
+
font-size: 13px; color: var(--sa-text); resize: none; outline: none;
|
|
580
|
+
transition: border-color 0.15s;
|
|
581
|
+
}
|
|
582
|
+
.sa-dislike-remark:focus { border-color: var(--sa-primary); }
|
|
583
|
+
.sa-dislike-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
|
|
584
|
+
.sa-dislike-submit {
|
|
585
|
+
padding: 5px 14px; border: none; border-radius: 6px;
|
|
586
|
+
background: var(--sa-primary); color: #fff; font-size: 13px; font-weight: 500; cursor: pointer;
|
|
587
|
+
transition: opacity 0.15s;
|
|
588
|
+
}
|
|
589
|
+
.sa-dislike-submit:hover { opacity: 0.9; }
|
|
590
|
+
.sa-dislike-cancel {
|
|
591
|
+
padding: 5px 14px; border: 1px solid var(--sa-border); border-radius: 6px;
|
|
592
|
+
background: #fff; color: var(--sa-text-muted); font-size: 13px; cursor: pointer;
|
|
593
|
+
transition: background 0.15s;
|
|
594
|
+
}
|
|
595
|
+
.sa-dislike-cancel:hover { background: var(--sa-surface); }
|
|
596
|
+
|
|
558
597
|
/* ── Composer ────────────────────────────────────────────── */
|
|
559
598
|
|
|
560
599
|
.sa-composer {
|
|
@@ -830,6 +869,200 @@
|
|
|
830
869
|
animation: sa-blink 1s steps(2, start) infinite;
|
|
831
870
|
}
|
|
832
871
|
|
|
872
|
+
/* ── Interrupt cards ──────────────────────────────────────── */
|
|
873
|
+
|
|
874
|
+
.sa-interrupt-card {
|
|
875
|
+
margin: 8px 0;
|
|
876
|
+
padding: 14px;
|
|
877
|
+
border: 1px solid #e0e7ff;
|
|
878
|
+
border-radius: 10px;
|
|
879
|
+
background: #f8faff;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
.sa-interrupt-content {
|
|
883
|
+
display: flex;
|
|
884
|
+
align-items: flex-start;
|
|
885
|
+
gap: 8px;
|
|
886
|
+
font-size: 13px;
|
|
887
|
+
line-height: 1.6;
|
|
888
|
+
color: var(--sa-text);
|
|
889
|
+
margin-bottom: 12px;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
.sa-interrupt-actions {
|
|
893
|
+
display: flex;
|
|
894
|
+
gap: 8px;
|
|
895
|
+
margin-top: 10px;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
.sa-interrupt-btn {
|
|
899
|
+
display: inline-flex;
|
|
900
|
+
align-items: center;
|
|
901
|
+
gap: 5px;
|
|
902
|
+
padding: 6px 14px;
|
|
903
|
+
border: none;
|
|
904
|
+
border-radius: 8px;
|
|
905
|
+
font-size: 13px;
|
|
906
|
+
font-weight: 500;
|
|
907
|
+
cursor: pointer;
|
|
908
|
+
transition: background 0.15s, opacity 0.15s;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
.sa-interrupt-btn:disabled {
|
|
912
|
+
opacity: 0.5;
|
|
913
|
+
cursor: not-allowed;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
.sa-interrupt-btn-primary {
|
|
917
|
+
background: var(--sa-primary);
|
|
918
|
+
color: #fff;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
.sa-interrupt-btn-primary:hover:not(:disabled) {
|
|
922
|
+
opacity: 0.9;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
.sa-interrupt-btn-secondary {
|
|
926
|
+
background: #f3f4f6;
|
|
927
|
+
color: #374151;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
.sa-interrupt-btn-secondary:hover:not(:disabled) {
|
|
931
|
+
background: #e5e7eb;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
.sa-interrupt-btn-danger {
|
|
935
|
+
background: #fef2f2;
|
|
936
|
+
color: #dc2626;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.sa-interrupt-btn-danger:hover:not(:disabled) {
|
|
940
|
+
background: #fee2e2;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
.sa-interrupt-options {
|
|
944
|
+
display: flex;
|
|
945
|
+
flex-direction: column;
|
|
946
|
+
gap: 6px;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
.sa-interrupt-option {
|
|
950
|
+
display: flex;
|
|
951
|
+
align-items: center;
|
|
952
|
+
gap: 8px;
|
|
953
|
+
padding: 8px 12px;
|
|
954
|
+
border: 1px solid var(--sa-border);
|
|
955
|
+
border-radius: 8px;
|
|
956
|
+
background: #fff;
|
|
957
|
+
color: var(--sa-text);
|
|
958
|
+
font-size: 13px;
|
|
959
|
+
cursor: pointer;
|
|
960
|
+
text-align: left;
|
|
961
|
+
transition: border-color 0.12s, background 0.12s;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
.sa-interrupt-option:hover {
|
|
965
|
+
border-color: var(--sa-primary);
|
|
966
|
+
background: #f5f3ff;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
.sa-interrupt-option-selected {
|
|
970
|
+
border-color: var(--sa-primary);
|
|
971
|
+
background: #ede9fe;
|
|
972
|
+
color: var(--sa-primary);
|
|
973
|
+
font-weight: 500;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
.sa-interrupt-option-danger {
|
|
977
|
+
color: #ef4444;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
.sa-interrupt-option-danger:hover {
|
|
981
|
+
border-color: #ef4444;
|
|
982
|
+
background: #fef2f2;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
.sa-interrupt-option-desc {
|
|
986
|
+
font-size: 11px;
|
|
987
|
+
color: var(--sa-text-muted);
|
|
988
|
+
margin-left: auto;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
.sa-interrupt-input-area {
|
|
992
|
+
margin-top: 4px;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
.sa-interrupt-input,
|
|
996
|
+
.sa-interrupt-textarea,
|
|
997
|
+
.sa-interrupt-select {
|
|
998
|
+
width: 100%;
|
|
999
|
+
padding: 8px 12px;
|
|
1000
|
+
border: 1px solid var(--sa-border);
|
|
1001
|
+
border-radius: 8px;
|
|
1002
|
+
background: #fff;
|
|
1003
|
+
color: var(--sa-text);
|
|
1004
|
+
font-size: 13px;
|
|
1005
|
+
font-family: inherit;
|
|
1006
|
+
outline: none;
|
|
1007
|
+
transition: border-color 0.15s;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
.sa-interrupt-input:focus,
|
|
1011
|
+
.sa-interrupt-textarea:focus,
|
|
1012
|
+
.sa-interrupt-select:focus {
|
|
1013
|
+
border-color: var(--sa-primary);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
.sa-interrupt-textarea {
|
|
1017
|
+
resize: vertical;
|
|
1018
|
+
min-height: 60px;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
.sa-interrupt-form {
|
|
1022
|
+
display: flex;
|
|
1023
|
+
flex-direction: column;
|
|
1024
|
+
gap: 10px;
|
|
1025
|
+
margin-top: 4px;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
.sa-interrupt-form-field {
|
|
1029
|
+
display: flex;
|
|
1030
|
+
flex-direction: column;
|
|
1031
|
+
gap: 4px;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
.sa-interrupt-form-label {
|
|
1035
|
+
font-size: 12px;
|
|
1036
|
+
font-weight: 500;
|
|
1037
|
+
color: var(--sa-text);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
.sa-interrupt-form-required {
|
|
1041
|
+
color: #ef4444;
|
|
1042
|
+
margin-left: 2px;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
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;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
.sa-interrupt-unknown {
|
|
1058
|
+
padding: 8px 12px;
|
|
1059
|
+
border-radius: 8px;
|
|
1060
|
+
background: #fef3c7;
|
|
1061
|
+
color: #92400e;
|
|
1062
|
+
font-size: 13px;
|
|
1063
|
+
margin: 6px 0;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
833
1066
|
/* ── Animations ──────────────────────────────────────────── */
|
|
834
1067
|
|
|
835
1068
|
@keyframes sa-slide-up {
|
|
@@ -1091,7 +1324,7 @@
|
|
|
1091
1324
|
}
|
|
1092
1325
|
|
|
1093
1326
|
.sa-fp-header-btn {
|
|
1094
|
-
width: 34px;
|
|
1327
|
+
min-width: 34px;
|
|
1095
1328
|
height: 34px;
|
|
1096
1329
|
border: none;
|
|
1097
1330
|
border-radius: 8px;
|
|
@@ -1135,4 +1368,165 @@
|
|
|
1135
1368
|
border-color: #d4d4d8;
|
|
1136
1369
|
box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
|
|
1137
1370
|
}
|
|
1138
|
-
|
|
1371
|
+
|
|
1372
|
+
/* ── Artifact file cards (in ToolResultPart) ── */
|
|
1373
|
+
.sa-artifact-file-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
|
|
1374
|
+
.sa-artifact-file-card {
|
|
1375
|
+
display: flex; align-items: center; gap: 10px; padding: 8px 10px;
|
|
1376
|
+
border: 1px solid var(--sa-border); border-radius: 10px; background: var(--sa-surface);
|
|
1377
|
+
font-size: 13px; color: var(--sa-text);
|
|
1378
|
+
transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
|
|
1379
|
+
animation: sa-fade-in-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1380
|
+
}
|
|
1381
|
+
.sa-artifact-file-card:hover { border-color: var(--sa-primary); background: #fff; box-shadow: 0 2px 8px rgba(99,102,241,0.1); transform: translateY(-1px); }
|
|
1382
|
+
.sa-artifact-file-card:active { transform: translateY(0) scale(0.99); }
|
|
1383
|
+
.sa-artifact-file-icon { flex-shrink: 0; }
|
|
1384
|
+
.sa-artifact-chip-type {
|
|
1385
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
1386
|
+
min-width: 36px; padding: 2px 6px; border-radius: 5px;
|
|
1387
|
+
background: var(--sa-primary); color: #fff;
|
|
1388
|
+
font-size: 10px; font-weight: 700; letter-spacing: 0.3px; line-height: 1.4;
|
|
1389
|
+
}
|
|
1390
|
+
.sa-artifact-file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
1391
|
+
.sa-artifact-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
|
|
1392
|
+
.sa-artifact-file-size { color: var(--sa-text-muted); font-size: 12px; }
|
|
1393
|
+
.sa-artifact-file-download {
|
|
1394
|
+
border: none; background: none; cursor: pointer; color: var(--sa-text-muted);
|
|
1395
|
+
padding: 6px; border-radius: 6px; display: inline-flex;
|
|
1396
|
+
transition: color 0.15s ease, background 0.15s ease, transform 0.1s ease;
|
|
1397
|
+
}
|
|
1398
|
+
.sa-artifact-file-download:hover { color: var(--sa-primary); background: rgba(99,102,241,0.08); }
|
|
1399
|
+
.sa-artifact-file-download:active { transform: scale(0.9); }
|
|
1400
|
+
|
|
1401
|
+
/* ── 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; }
|
|
1404
|
+
|
|
1405
|
+
/* ── Header artifact button ── */
|
|
1406
|
+
.sa-header-btn-artifact {
|
|
1407
|
+
display: inline-flex; align-items: center; gap: 4px;
|
|
1408
|
+
padding: 4px 12px !important; border-radius: 8px;
|
|
1409
|
+
background: var(--sa-primary) !important; color: #fff !important;
|
|
1410
|
+
font-size: 12px; font-weight: 600;
|
|
1411
|
+
transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease;
|
|
1412
|
+
box-shadow: 0 1px 4px rgba(99,102,241,0.25);
|
|
1413
|
+
}
|
|
1414
|
+
.sa-header-btn-artifact:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(99,102,241,0.3); }
|
|
1415
|
+
.sa-header-btn-artifact:active { transform: translateY(0) scale(0.97); }
|
|
1416
|
+
.sa-header-btn-artifact svg { stroke: #fff; }
|
|
1417
|
+
.sa-header-btn-artifact.sa-artifact-pulse { animation: sa-artifact-pulse 2s ease-in-out 3; }
|
|
1418
|
+
|
|
1419
|
+
/* ── Artifact drawer (right side panel) ── */
|
|
1420
|
+
.sa-artifact-drawer {
|
|
1421
|
+
display: flex; flex-direction: column; min-width: 240px; max-width: 70%;
|
|
1422
|
+
border-left: 1px solid var(--sa-border); background: #fff; flex-shrink: 0; overflow: hidden;
|
|
1423
|
+
animation: sa-slide-in-right 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1424
|
+
position: relative;
|
|
1425
|
+
}
|
|
1426
|
+
.sa-artifact-drawer.sa-drawer-closing {
|
|
1427
|
+
animation: sa-slide-out-right 0.25s cubic-bezier(0.4, 0, 1, 1) both;
|
|
1428
|
+
}
|
|
1429
|
+
.sa-drawer-resize-handle {
|
|
1430
|
+
position: absolute; left: -3px; top: 0; bottom: 0; width: 6px;
|
|
1431
|
+
cursor: col-resize; z-index: 2;
|
|
1432
|
+
transition: background 0.15s ease;
|
|
1433
|
+
}
|
|
1434
|
+
.sa-drawer-resize-handle:hover, .sa-drawer-resize-handle:active {
|
|
1435
|
+
background: var(--sa-primary); opacity: 0.3; border-radius: 3px;
|
|
1436
|
+
}
|
|
1437
|
+
.sa-artifact-drawer-header {
|
|
1438
|
+
display: flex; align-items: center; gap: 8px; padding: 12px 14px;
|
|
1439
|
+
border-bottom: 1px solid var(--sa-border); font-weight: 600; font-size: 15px; color: var(--sa-text);
|
|
1440
|
+
background: var(--sa-surface);
|
|
1441
|
+
}
|
|
1442
|
+
.sa-artifact-drawer-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1443
|
+
.sa-drawer-btn {
|
|
1444
|
+
border: none; background: none; cursor: pointer; color: var(--sa-text-muted);
|
|
1445
|
+
padding: 6px; border-radius: 6px; display: inline-flex; align-items: center;
|
|
1446
|
+
transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
|
|
1447
|
+
}
|
|
1448
|
+
.sa-drawer-btn:hover { background: var(--sa-border); color: var(--sa-text); }
|
|
1449
|
+
.sa-drawer-btn:active { transform: scale(0.92); }
|
|
1450
|
+
.sa-drawer-btn-sm {
|
|
1451
|
+
border: 1px solid var(--sa-border); background: #fff; cursor: pointer; color: var(--sa-primary);
|
|
1452
|
+
padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
|
|
1453
|
+
transition: background 0.15s ease, border-color 0.15s ease;
|
|
1454
|
+
}
|
|
1455
|
+
.sa-drawer-btn-sm:hover { background: var(--sa-surface); border-color: var(--sa-primary); }
|
|
1456
|
+
.sa-artifact-drawer-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
|
|
1457
|
+
.sa-drawer-empty { padding: 48px 24px; text-align: center; color: var(--sa-text-muted); font-size: 14px; }
|
|
1458
|
+
.sa-drawer-file-list { list-style: none; margin: 0; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
|
|
1459
|
+
.sa-drawer-file-card {
|
|
1460
|
+
display: flex; align-items: center; gap: 10px; padding: 12px 14px;
|
|
1461
|
+
border: 1px solid var(--sa-border); border-radius: 10px; cursor: pointer; background: #fff;
|
|
1462
|
+
transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
|
|
1463
|
+
animation: sa-fade-in-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1464
|
+
}
|
|
1465
|
+
.sa-drawer-file-card:nth-child(1) { animation-delay: 0s; }
|
|
1466
|
+
.sa-drawer-file-card:nth-child(2) { animation-delay: 0.04s; }
|
|
1467
|
+
.sa-drawer-file-card:nth-child(3) { animation-delay: 0.08s; }
|
|
1468
|
+
.sa-drawer-file-card:nth-child(4) { animation-delay: 0.12s; }
|
|
1469
|
+
.sa-drawer-file-card:nth-child(5) { animation-delay: 0.16s; }
|
|
1470
|
+
.sa-drawer-file-card:hover { border-color: var(--sa-primary); background: var(--sa-surface); box-shadow: 0 2px 8px rgba(99,102,241,0.08); transform: translateY(-1px); }
|
|
1471
|
+
.sa-drawer-file-card:active { transform: translateY(0) scale(0.98); }
|
|
1472
|
+
.sa-drawer-file-icon { flex-shrink: 0; }
|
|
1473
|
+
.sa-drawer-file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
|
|
1474
|
+
.sa-drawer-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 14px; color: var(--sa-text); }
|
|
1475
|
+
.sa-drawer-file-size { color: var(--sa-text-muted); font-size: 12px; }
|
|
1476
|
+
|
|
1477
|
+
/* ── Drawer preview ── */
|
|
1478
|
+
.sa-drawer-preview-iframe { width: 100%; height: 100%; border: none; background: #fff; animation: sa-fade-in 0.3s ease both; }
|
|
1479
|
+
.sa-drawer-preview-loading {
|
|
1480
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
1481
|
+
height: 100%; gap: 12px; color: var(--sa-text-muted); font-size: 14px;
|
|
1482
|
+
}
|
|
1483
|
+
.sa-drawer-preview-loading::before {
|
|
1484
|
+
content: ''; width: 28px; height: 28px; border-radius: 50%;
|
|
1485
|
+
border: 3px solid var(--sa-border); border-top-color: var(--sa-primary);
|
|
1486
|
+
animation: sa-spinner 0.7s linear infinite;
|
|
1487
|
+
}
|
|
1488
|
+
.sa-drawer-preview-error {
|
|
1489
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
1490
|
+
gap: 14px; height: 100%; color: var(--sa-text-muted); font-size: 14px;
|
|
1491
|
+
animation: sa-fade-in 0.2s ease both;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/* ── Drawer view transition ── */
|
|
1495
|
+
.sa-drawer-view-enter { animation: sa-drawer-view-in 0.25s cubic-bezier(0.16, 1, 0.3, 1) both; }
|
|
1496
|
+
|
|
1497
|
+
/* ── Layout helpers for drawer alongside thread ── */
|
|
1498
|
+
.sa-panel-content { display: flex; flex: 1; min-height: 0; overflow: hidden; }
|
|
1499
|
+
.sa-panel-content .sa-thread { flex: 1; min-width: 120px; transition: flex 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
|
|
1500
|
+
.sa-panel-content .sa-artifact-drawer { max-width: 60%; }
|
|
1501
|
+
.sa-fp-content-row { display: flex; flex: 1; min-height: 0; overflow: hidden; }
|
|
1502
|
+
.sa-fp-content-row .sa-thread { flex: 1; min-width: 0; transition: flex 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
|
|
1503
|
+
|
|
1504
|
+
/* ── Artifact keyframes ── */
|
|
1505
|
+
@keyframes sa-slide-in-right {
|
|
1506
|
+
from { opacity: 0; transform: translateX(100%); }
|
|
1507
|
+
to { opacity: 1; transform: translateX(0); }
|
|
1508
|
+
}
|
|
1509
|
+
@keyframes sa-slide-out-right {
|
|
1510
|
+
from { opacity: 1; transform: translateX(0); }
|
|
1511
|
+
to { opacity: 0; transform: translateX(100%); }
|
|
1512
|
+
}
|
|
1513
|
+
@keyframes sa-fade-in-up {
|
|
1514
|
+
from { opacity: 0; transform: translateY(8px); }
|
|
1515
|
+
to { opacity: 1; transform: translateY(0); }
|
|
1516
|
+
}
|
|
1517
|
+
@keyframes sa-fade-in {
|
|
1518
|
+
from { opacity: 0; }
|
|
1519
|
+
to { opacity: 1; }
|
|
1520
|
+
}
|
|
1521
|
+
@keyframes sa-spinner {
|
|
1522
|
+
to { transform: rotate(360deg); }
|
|
1523
|
+
}
|
|
1524
|
+
@keyframes sa-artifact-pulse {
|
|
1525
|
+
0%, 100% { box-shadow: 0 1px 4px rgba(99,102,241,0.25); }
|
|
1526
|
+
50% { box-shadow: 0 2px 12px rgba(99,102,241,0.5); }
|
|
1527
|
+
}
|
|
1528
|
+
@keyframes sa-drawer-view-in {
|
|
1529
|
+
from { opacity: 0; transform: translateX(12px); }
|
|
1530
|
+
to { opacity: 1; transform: translateX(0); }
|
|
1531
|
+
}
|
|
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 He(a,t){const r=typeof a=="string"?document.querySelector(a):a;if(!r)throw new Error(`Target element not found: ${a}`);const s=document.createElement("div");s.setAttribute("data-super-agent-widget","");const n=be(t.theme??{});if(s.setAttribute("style",n),r.appendChild(s),!document.getElementById("sa-widget-styles")){const c=document.createElement("style");c.id="sa-widget-styles",c.textContent=he,document.head.appendChild(c)}let o=ve.createRoot(s),i=!1;const l=c=>{o&&o.render(d.createElement(me,{...t,initialOpen:c??i,onOpenChange:p=>{i=p}}))};return l(!1),{open(){i=!0,l(!0)},close(){i=!1,l(!1)},destroy(){o&&(o.unmount(),o=null),s.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=He;exports.themeToCSSVars=be;exports.useAutoScroll=se;exports.useChat=U;exports.useChatContext=B;exports.useConversations=X;exports.widgetStyles=he;
|