super-agent-sdk 1.0.4 → 1.0.6
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 +43 -36
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +38 -8
- package/dist/index.mjs +196 -167
- 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 +214 -5
- package/dist/widget.d.ts +62 -14
- package/dist/widget.mjs +1355 -692
- package/package.json +10 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});/*! @license DOMPurify 3.4.14 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.14/LICENSE */function We(r,i){(i==null||i>r.length)&&(i=r.length);for(var s=0,c=Array(i);s<i;s++)c[s]=r[s];return c}function Fn(r){if(Array.isArray(r))return r}function zn(r,i){var s=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(s!=null){var c,f,d,y,st=[],N=!0,lt=!1;try{if(d=(s=s.call(r)).next,i!==0)for(;!(N=(c=d.call(s)).done)&&(st.push(c.value),st.length!==i);N=!0);}catch(xt){lt=!0,f=xt}finally{try{if(!N&&s.return!=null&&(y=s.return(),Object(y)!==y))return}finally{if(lt)throw f}}return st}}function Hn(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Gn(r,i){return Fn(r)||zn(r,i)||Wn(r,i)||Hn()}function Wn(r,i){if(r){if(typeof r=="string")return We(r,i);var s={}.toString.call(r).slice(8,-1);return s==="Object"&&r.constructor&&(s=r.constructor.name),s==="Map"||s==="Set"?Array.from(r):s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s)?We(r,i):void 0}}const on=Object.entries,Be=Object.setPrototypeOf,Bn=Object.isFrozen,Yn=Object.getPrototypeOf,jn=Object.getOwnPropertyDescriptor;let S=Object.freeze,b=Object.seal,it=Object.create,rn=typeof Reflect<"u"&&Reflect,se=rn.apply,le=rn.construct;S||(S=function(i){return i});b||(b=function(i){return i});se||(se=function(i,s){for(var c=arguments.length,f=new Array(c>2?c-2:0),d=2;d<c;d++)f[d-2]=arguments[d];return i.apply(s,f)});le||(le=function(i){for(var s=arguments.length,c=new Array(s>1?s-1:0),f=1;f<s;f++)c[f-1]=arguments[f];return new i(...c)});const V=A(Array.prototype.forEach),$n=A(Array.prototype.lastIndexOf),Ye=A(Array.prototype.pop),dt=A(Array.prototype.push),Xn=A(Array.prototype.splice),at=Array.isArray,_t=A(String.prototype.toLowerCase),ee=A(String.prototype.toString),je=A(String.prototype.match),Tt=A(String.prototype.replace),$e=A(String.prototype.indexOf),Vn=A(String.prototype.trim),qn=A(Number.prototype.toString),Kn=A(Boolean.prototype.toString),Xe=typeof BigInt>"u"?null:A(BigInt.prototype.toString),Ve=typeof Symbol>"u"?null:A(Symbol.prototype.toString),I=A(Object.prototype.hasOwnProperty),ht=A(Object.prototype.toString),O=A(RegExp.prototype.test),X=Zn(TypeError);function A(r){return function(i){i instanceof RegExp&&(i.lastIndex=0);for(var s=arguments.length,c=new Array(s>1?s-1:0),f=1;f<s;f++)c[f-1]=arguments[f];return se(r,i,c)}}function Zn(r){return function(){for(var i=arguments.length,s=new Array(i),c=0;c<i;c++)s[c]=arguments[c];return le(r,s)}}function p(r,i){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:_t;if(Be&&Be(r,null),!at(i))return r;let c=i.length;for(;c--;){let f=i[c];if(typeof f=="string"){const d=s(f);d!==f&&(Bn(i)||(i[c]=d),f=d)}r[f]=!0}return r}function Jn(r){for(let i=0;i<r.length;i++)I(r,i)||(r[i]=null);return r}function C(r){const i=it(null);for(const c of on(r)){var s=Gn(c,2);const f=s[0],d=s[1];I(r,f)&&(at(d)?i[f]=Jn(d):d&&typeof d=="object"&&d.constructor===Object?i[f]=C(d):i[f]=d)}return i}function Qn(r){switch(typeof r){case"string":return r;case"number":return qn(r);case"boolean":return Kn(r);case"bigint":return Xe?Xe(r):"0";case"symbol":return Ve?Ve(r):"Symbol()";case"undefined":return ht(r);case"function":case"object":{if(r===null)return ht(r);const i=r,s=P(i,"toString");if(typeof s=="function"){const c=s(i);return typeof c=="string"?c:ht(c)}return ht(r)}default:return ht(r)}}function P(r,i){for(;r!==null;){const c=jn(r,i);if(c){if(c.get)return A(c.get);if(typeof c.value=="function")return A(c.value)}r=Yn(r)}function s(){return null}return s}function to(r){try{return O(r,""),!0}catch{return!1}}const qe=S(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),ne=S(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),oe=S(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),eo=S(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),re=S(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),no=S(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Ke=S(["#text"]),Ze=S(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),ie=S(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","vector-effect","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Je=S(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Pt=S(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),oo=b(/{{[\w\W]*|^[\w\W]*}}/g),ro=b(/<%[\w\W]*|^[\w\W]*%>/g),io=b(/\${[\w\W]*/g),ao=b(/^data-[\-\w.\u00B7-\uFFFF]+$/),so=b(/^aria-[\-\w]+$/),Qe=b(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),lo=b(/^(?:\w+script|data):/i),co=b(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),uo=b(/^html$/i),fo=b(/^[a-z][.\w]*(-[.\w]+)+$/i),tn=b(/<[/\w!]/g),en=b(/<[/\w]/g),po=b(/<\/no(script|embed|frames)/i),mo=b(/\/>/i),M={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},an=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],To=S(p({},an)),ho=function(){const r={};return V(an,i=>{r[i]=b(new RegExp("</"+i+"(?=[\\t\\n\\f\\r />])","i"))}),S(r)}(),_o=function(){return typeof window>"u"?null:window},go=function(i,s){if(typeof i!="object"||typeof i.createPolicy!="function")return null;let c=null;const f="data-tt-policy-suffix";s&&s.hasAttribute(f)&&(c=s.getAttribute(f));const d="dompurify"+(c?"#"+c:"");try{return i.createPolicy(d,{createHTML(y){return y},createScriptURL(y){return y}})}catch{return console.warn("TrustedTypes policy "+d+" could not be created."),null}},nn=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},H=function(i,s,c,f){return I(i,s)&&at(i[s])?p(f.base?C(f.base):{},i[s],f.transform):c},ae=function(i,s,c){const f=I(i,s)?i[s]:void 0;return f&&typeof f=="object"?C(f):c()};function sn(){let r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:_o();const i=o=>sn(o);if(i.version="3.4.14",i.removed=[],!r||!r.document||r.document.nodeType!==M.document||!r.Element)return i.isSupported=!1,i;let s=r.document;const c=s,f=c.currentScript;r.DocumentFragment;const d=r.HTMLTemplateElement,y=r.Node,st=r.Element,N=r.NodeFilter,lt=r.NamedNodeMap;lt===void 0&&(r.NamedNodeMap||r.MozNamedAttrMap),r.HTMLFormElement;const xt=r.DOMParser,gt=r.trustedTypes,G=st.prototype,ln=P(G,"cloneNode"),vt=P(G,"remove"),cn=P(G,"nextSibling"),q=P(G,"childNodes"),K=P(G,"parentNode"),ce=P(G,"shadowRoot"),kt=P(G,"attributes"),W=y&&y.prototype?P(y.prototype,"nodeType"):null,Z=y&&y.prototype?P(y.prototype,"nodeName"):null,Et=y&&y.prototype?P(y.prototype,"ownerDocument"):null,ct=function(t){return W?W(t):t.nodeType},Ut=function(t){return Z?Z(t):t.nodeName};if(typeof d=="function"){const o=s.createElement("template");o.content&&o.content.ownerDocument&&(s=o.content.ownerDocument)}let L,B="",Ft,ue=!1,ut=0;const fe=function(){if(ut>0)throw X('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},J=function(t){fe(),ut++;try{return L.createHTML(t)}finally{ut--}},un=function(t){fe(),ut++;try{return L.createScriptURL(t)}finally{ut--}},fn=function(){return ue||(Ft=go(gt,f),ue=!0),Ft},At=s,zt=At.implementation,pe=At.createNodeIterator,pn=At.createDocumentFragment,mn=At.getElementsByTagName,dn=c.importNode;let T=nn();i.isSupported=typeof on=="function"&&typeof K=="function"&&zt&&zt.createHTMLDocument!==void 0;const Tn=oo,hn=ro,_n=io,gn=ao,En=so,An=lo,me=co,yn=fo;let de=Qe,h=null;const Ht=p({},[...qe,...ne,...oe,...re,...Ke]);let _=null;const Gt=p({},[...Ze,...ie,...Je,...Pt]);let x=Object.seal(it(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ft=null,Te=null;const U=Object.seal(it(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let he=!0,Wt=!0,_e=!1,ge=!0,F=!1,Y=!0,j=!1,Bt=!1,yt=null,St=null,Yt=!1,Q=!1,bt=!1,Ot=!1,Ee=!0,Ae=!1;const ye="user-content-";let jt=!0,$t=!1,tt={},et=null;const Se=p({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let be=null;const Oe=p({},["audio","video","img","source","image","track"]);let Re=null;const Le=p({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Rt="http://www.w3.org/1998/Math/MathML",Lt="http://www.w3.org/2000/svg",v="http://www.w3.org/1999/xhtml";let nt=v,Xt=!1,Vt=null;const Sn=p({},[Rt,Lt,v],ee),De=S(["mi","mo","mn","ms","mtext"]);let qt=p({},De);const we=S(["annotation-xml"]);let Kt=p({},we);const bn=p({},["title","style","font","a","script"]);let pt=null;const On=["application/xhtml+xml","text/html"],Rn="text/html";let E=null,ot=null;const Ln=s.createElement("form"),Ie=function(t){return t instanceof RegExp||t instanceof Function},Zt=function(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(ot&&ot===t)return;(!t||typeof t!="object")&&(t={}),t=C(t),pt=On.indexOf(t.PARSER_MEDIA_TYPE)===-1?Rn:t.PARSER_MEDIA_TYPE,E=pt==="application/xhtml+xml"?ee:_t,h=H(t,"ALLOWED_TAGS",Ht,{transform:E}),_=H(t,"ALLOWED_ATTR",Gt,{transform:E}),Vt=H(t,"ALLOWED_NAMESPACES",Sn,{transform:ee}),Re=H(t,"ADD_URI_SAFE_ATTR",Le,{transform:E,base:Le}),be=H(t,"ADD_DATA_URI_TAGS",Oe,{transform:E,base:Oe}),et=H(t,"FORBID_CONTENTS",Se,{transform:E}),ft=H(t,"FORBID_TAGS",C({}),{transform:E}),Te=H(t,"FORBID_ATTR",C({}),{transform:E}),tt=I(t,"USE_PROFILES")?t.USE_PROFILES&&typeof t.USE_PROFILES=="object"?C(t.USE_PROFILES):t.USE_PROFILES:!1,he=t.ALLOW_ARIA_ATTR!==!1,Wt=t.ALLOW_DATA_ATTR!==!1,_e=t.ALLOW_UNKNOWN_PROTOCOLS||!1,ge=t.ALLOW_SELF_CLOSE_IN_ATTR!==!1,F=t.SAFE_FOR_TEMPLATES||!1,Y=t.SAFE_FOR_XML!==!1,j=t.WHOLE_DOCUMENT||!1,Q=t.RETURN_DOM||!1,bt=t.RETURN_DOM_FRAGMENT||!1,Ot=t.RETURN_TRUSTED_TYPE||!1,Yt=t.FORCE_BODY||!1,Ee=t.SANITIZE_DOM!==!1,Ae=t.SANITIZE_NAMED_PROPS||!1,jt=t.KEEP_CONTENT!==!1,$t=t.IN_PLACE||!1,de=to(t.ALLOWED_URI_REGEXP)?t.ALLOWED_URI_REGEXP:Qe,nt=typeof t.NAMESPACE=="string"?t.NAMESPACE:v,qt=ae(t,"MATHML_TEXT_INTEGRATION_POINTS",()=>p({},De)),Kt=ae(t,"HTML_INTEGRATION_POINTS",()=>p({},we));const e=ae(t,"CUSTOM_ELEMENT_HANDLING",()=>it(null));if(x=it(null),I(e,"tagNameCheck")&&Ie(e.tagNameCheck)&&(x.tagNameCheck=e.tagNameCheck),I(e,"attributeNameCheck")&&Ie(e.attributeNameCheck)&&(x.attributeNameCheck=e.attributeNameCheck),I(e,"allowCustomizedBuiltInElements")&&typeof e.allowCustomizedBuiltInElements=="boolean"&&(x.allowCustomizedBuiltInElements=e.allowCustomizedBuiltInElements),b(x),F&&(Wt=!1),bt&&(Q=!0),tt&&(h=p({},Ke),_=it(null),tt.html===!0&&(p(h,qe),p(_,Ze)),tt.svg===!0&&(p(h,ne),p(_,ie),p(_,Pt)),tt.svgFilters===!0&&(p(h,oe),p(_,ie),p(_,Pt)),tt.mathMl===!0&&(p(h,re),p(_,Je),p(_,Pt))),U.tagCheck=null,U.attributeCheck=null,I(t,"ADD_TAGS")&&(typeof t.ADD_TAGS=="function"?U.tagCheck=t.ADD_TAGS:at(t.ADD_TAGS)&&(h===Ht&&(h=C(h)),p(h,t.ADD_TAGS,E))),I(t,"ADD_ATTR")&&(typeof t.ADD_ATTR=="function"?U.attributeCheck=t.ADD_ATTR:at(t.ADD_ATTR)&&(_===Gt&&(_=C(_)),p(_,t.ADD_ATTR,E))),I(t,"ADD_FORBID_CONTENTS")&&at(t.ADD_FORBID_CONTENTS)&&(et===Se&&(et=C(et)),p(et,t.ADD_FORBID_CONTENTS,E)),jt&&(h["#text"]=!0),j&&p(h,["html","head","body"]),h.table&&(p(h,["tbody"]),delete ft.tbody),t.TRUSTED_TYPES_POLICY){if(typeof t.TRUSTED_TYPES_POLICY.createHTML!="function")throw X('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof t.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw X('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const n=L;L=t.TRUSTED_TYPES_POLICY;try{B=J("")}catch(a){throw L=n,a}}else t.TRUSTED_TYPES_POLICY===null?(L=void 0,B=""):(L===void 0&&(L=fn()),L&&typeof B=="string"&&(B=J("")));S&&S(t),ot=t},Ne=p({},[...ne,...oe,...eo]),Me=p({},[...re,...no]),Dn=function(t,e,n){return e.namespaceURI===v?t==="svg":e.namespaceURI===Rt?t==="svg"&&(n==="annotation-xml"||qt[n]):!!Ne[t]},wn=function(t,e,n){return e.namespaceURI===v?t==="math":e.namespaceURI===Lt?t==="math"&&Kt[n]:!!Me[t]},In=function(t,e,n){return e.namespaceURI===Lt&&!Kt[n]||e.namespaceURI===Rt&&!qt[n]?!1:!Me[t]&&(bn[t]||!Ne[t])},Nn=function(t){let e=K(t);(!e||!e.tagName)&&(e={namespaceURI:nt,tagName:"template"});const n=_t(t.tagName),a=_t(e.tagName);return Vt[t.namespaceURI]?t.namespaceURI===Lt?Dn(n,e,a):t.namespaceURI===Rt?wn(n,e,a):t.namespaceURI===v?In(n,e,a):!!(pt==="application/xhtml+xml"&&Vt[t.namespaceURI]):!1},z=function(t){dt(i.removed,{element:t});try{K(t).removeChild(t)}catch{if(vt(t),!K(t))throw X("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Ce=function(t,e,n){try{t.removeAttributeNode(e)}catch{try{t.removeAttribute(n)}catch{}}},Dt=function(t){wt(t);const e=q(t);if(e){const a=[];V(e,l=>{dt(a,l)}),V(a,l=>{try{vt(l)}catch{}})}const n=kt(t);if(n)for(let a=n.length-1;a>=0;--a){const l=n[a],u=l&&l.name;typeof u=="string"&&Ce(t,l,u)}},$=function(t,e,n){if(!n)try{n=e.getAttributeNode(t)}catch{n=null}dt(i.removed,{attribute:n||null,from:e});try{n?e.removeAttributeNode(n):e.removeAttribute(t)}catch{try{e.removeAttribute(t)}catch{}}if(t==="is")if(Q||bt)try{z(e)}catch{}else try{e.setAttribute(t,"")}catch{}},Mn=function(t){const e=kt(t);if(e)for(let n=e.length-1;n>=0;--n){const a=e[n],l=a&&a.name;typeof l!="string"||_[E(l)]||Ce(t,a,l)}},wt=function(t){const e=[t];for(;e.length>0;){const n=e.pop();ct(n)===M.element&&Mn(n);const l=q(n);if(l)for(let u=l.length-1;u>=0;--u)e.push(l[u])}},Pe=function(t,e){return Y?t==="patchsrc"?!0:t==="for"&&e!=="label"&&e!=="output":!1},Cn=function(t){if(!Y)return;const e=[t];for(;e.length>0;){const n=e.pop(),a=ct(n);if(a===M.processingInstruction||a===M.comment&&O(en,n.data)){try{vt(n)}catch{}continue}if(a===M.element){const u=n,m=E(Ut(n));try{u.hasAttribute&&u.hasAttribute("patchsrc")&&u.removeAttribute("patchsrc"),u.hasAttribute&&u.hasAttribute("for")&&Pe("for",m)&&u.removeAttribute("for")}catch{}}const l=q(n);if(l)for(let u=l.length-1;u>=0;--u)e.push(l[u])}},xe=function(t){let e=null,n=null;if(Yt)t="<remove></remove>"+t;else{const u=je(t,/^[\r\n\t ]+/);n=u&&u[0]}pt==="application/xhtml+xml"&&nt===v&&(t='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+t+"</body></html>");const a=L?J(t):t;if(nt===v)try{e=new xt().parseFromString(a,pt)}catch{}if(!e||!e.documentElement){e=zt.createDocument(nt,"template",null);try{e.documentElement.innerHTML=Xt?B:a}catch{}}const l=e.body||e.documentElement;return t&&n&&l.insertBefore(s.createTextNode(n),l.childNodes[0]||null),nt===v?mn.call(e,j?"html":"body")[0]:j?e.documentElement:l},ve=function(t){const e=Et?Et(t):t.ownerDocument;return pe.call(e||t,t,N.SHOW_ELEMENT|N.SHOW_COMMENT|N.SHOW_TEXT|N.SHOW_PROCESSING_INSTRUCTION|N.SHOW_CDATA_SECTION,null)},It=function(t){return t=Tt(t,Tn," "),t=Tt(t,hn," "),t=Tt(t,_n," "),t},Jt=function(t){var e;t.normalize();const n=Et?Et(t):t.ownerDocument,a=pe.call(n||t,t,N.SHOW_TEXT|N.SHOW_COMMENT|N.SHOW_CDATA_SECTION|N.SHOW_PROCESSING_INSTRUCTION,null);let l=a.nextNode();for(;l;)l.data=It(l.data),l=a.nextNode();const u=(e=t.querySelectorAll)===null||e===void 0?void 0:e.call(t,"template");u&&V(u,m=>{rt(m.content)&&Jt(m.content)})},Nt=function(t){const e=Z?Z(t):null;return typeof e!="string"||E(e)!=="form"?!1:typeof t.nodeName!="string"||typeof t.textContent!="string"||typeof t.removeChild!="function"||t.attributes!==kt(t)||typeof t.removeAttribute!="function"||typeof t.setAttribute!="function"||typeof t.namespaceURI!="string"||typeof t.insertBefore!="function"||typeof t.hasChildNodes!="function"||t.nodeType!==W(t)||t.childNodes!==q(t)},rt=function(t){if(!W||typeof t!="object"||t===null)return!1;try{return W(t)===M.documentFragment}catch{return!1}},mt=function(t){if(!W||typeof t!="object"||t===null)return!1;try{return typeof W(t)=="number"}catch{return!1}};function k(o,t,e){o.length!==0&&V(o,n=>{n.call(i,t,e,ot)})}const Pn=function(t,e){return!!(Y&&t.hasChildNodes()&&!mt(t.firstElementChild)&&O(tn,t.textContent)&&O(tn,t.innerHTML)||Y&&t.namespaceURI===v&&To[e]&&(mt(t.firstElementChild)||typeof t.textContent=="string"&&O(ho[e],t.textContent))||t.nodeType===M.processingInstruction||Y&&t.nodeType===M.comment&&O(en,t.data))},Mt=function(t,e){if(t instanceof RegExp)return O(t,e);if(t instanceof Function){for(var n=arguments.length,a=new Array(n>2?n-2:0),l=2;l<n;l++)a[l-2]=arguments[l];return!!t(e,...a)}return!1},xn=function(t,e,n){if(!ft[e]&&He(e)&&Mt(x.tagNameCheck,e))return!1;if(jt&&!et[e]){const a=K(t),l=q(t);if(l&&a){const u=l.length;for(let m=u-1;m>=0;--m){const g=t===n?ln(l[m],!0):l[m];a.insertBefore(g,cn(t))}}}return z(t),!0},ke=function(t,e,n,a){return t.length===0?e:e===n||e===a?C(e):e},Ue=function(t,e){return t===e||K(t)!==null?!1:($t&&wt(t),!0)},Fe=function(t,e){if(k(T.beforeSanitizeElements,t,null),Ue(t,e))return!0;if(Nt(t))return z(t),!0;const n=E(Ut(t));if(h=ke(T.uponSanitizeElement,h,Ht,yt),k(T.uponSanitizeElement,t,{tagName:n,allowedTags:h}),Ue(t,e))return!0;if(Pn(t,n))return z(t),!0;if(ft[n]||!(U.tagCheck instanceof Function&&U.tagCheck(n))&&!h[n]){const l=xn(t,n,e);return l===!1&&k(T.afterSanitizeElements,t,null),l}if(ct(t)===M.element&&!Nn(t)||(n==="noscript"||n==="noembed"||n==="noframes")&&O(po,t.innerHTML))return z(t),!0;if(F&&t.nodeType===M.text){const l=It(t.textContent);t.textContent!==l&&(dt(i.removed,{element:t.cloneNode()}),t.textContent=l)}return k(T.afterSanitizeElements,t,null),!1},ze=function(t,e,n){if(Te[e]||Pe(e,t)||Ee&&(e==="id"||e==="name")&&(n in s||n in Ln))return!1;const a=_[e]||U.attributeCheck instanceof Function&&U.attributeCheck(e,t);return Wt&&O(gn,e)||he&&O(En,e)?!0:a?Re[e]||O(de,Tt(n,me,""))||(e==="src"||e==="xlink:href"||e==="href")&&t!=="script"&&$e(n,"data:")===0&&be[t]||_e&&!O(An,Tt(n,me,""))?!0:!n:He(t)&&Mt(x.tagNameCheck,t)&&Mt(x.attributeNameCheck,e,t)||e==="is"&&x.allowCustomizedBuiltInElements&&Mt(x.tagNameCheck,n)},vn=p({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),He=function(t){return!vn[_t(t)]&&O(yn,t)},kn=function(t,e,n,a){if(L&&typeof gt=="object"&&typeof gt.getAttributeType=="function"&&!n)switch(gt.getAttributeType(t,e)){case"TrustedHTML":return J(a);case"TrustedScriptURL":return un(a)}return a},Un=function(t,e,n,a){try{n?t.setAttributeNS(n,e,a):t.setAttribute(e,a),Nt(t)?z(t):Ye(i.removed)}catch{$(e,t)}},Ge=function(t){k(T.beforeSanitizeAttributes,t,null);const e=t.attributes;if(!e||Nt(t))return;_=ke(T.uponSanitizeAttribute,_,Gt,St);const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:_,forceKeepAttr:void 0};let a=e.length;const l=E(t.nodeName);for(;a--;){const u=e[a],m=u.name,g=u.namespaceURI,D=u.value,w=E(m),te=D;let R=m==="value"?te:Vn(te);if(n.attrName=w,n.attrValue=R,n.keepAttr=!0,n.forceKeepAttr=void 0,k(T.uponSanitizeAttribute,t,n),R=n.attrValue,Ae&&(w==="id"||w==="name")&&$e(R,ye)!==0&&($(m,t,u),R=ye+R),Y&&O(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,R)){$(m,t,u);continue}if(w==="attributename"&&je(R,"href")){$(m,t,u);continue}if(!n.forceKeepAttr){if(!n.keepAttr){$(m,t,u);continue}if(!ge&&O(mo,R)){$(m,t,u);continue}if(F&&(R=It(R)),!ze(l,w,R)){$(m,t,u);continue}R=kn(l,w,g,R),R!==te&&Un(t,m,g,R)}}k(T.afterSanitizeAttributes,t,null)},Ct=function(t){let e=null;const n=ve(t);for(k(T.beforeSanitizeShadowDOM,t,null);e=n.nextNode();)if(k(T.uponSanitizeShadowNode,e,null),Fe(e,t),Ge(e),rt(e.content)&&Ct(e.content),ct(e)===M.element){const a=ce(e);rt(a)&&(Qt(a),Ct(a))}k(T.afterSanitizeShadowDOM,t,null)},Qt=function(t){const e=[{node:t,shadow:null}];for(;e.length>0;){const n=e.pop();if(n.shadow){Ct(n.shadow);continue}const a=n.node,u=ct(a)===M.element,m=q(a);if(m)for(let g=m.length-1;g>=0;--g)e.push({node:m[g],shadow:null});if(u){const g=Z?Z(a):null;if(typeof g=="string"&&E(g)==="template"){const D=a.content;rt(D)&&e.push({node:D,shadow:null})}}if(u){const g=ce(a);rt(g)&&e.push({node:null,shadow:g},{node:g,shadow:null})}}};return i.sanitize=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},e=null,n=null,a=null,l=null;if(Xt=!o,Xt&&(o="<!-->"),typeof o!="string"&&!mt(o)&&(o=Qn(o),typeof o!="string"))throw X("dirty is not a string, aborting");if(!i.isSupported)return o;Bt?(h=yt,_=St):Zt(t),(T.uponSanitizeElement.length>0||T.uponSanitizeAttribute.length>0)&&(h=C(h)),T.uponSanitizeAttribute.length>0&&(_=C(_)),i.removed=[];const u=$t&&typeof o!="string"&&mt(o);if(u){Cn(o);const D=Ut(o);if(typeof D=="string"){const w=E(D);if(!h[w]||ft[w])throw Dt(o),X("root node is forbidden and cannot be sanitized in-place")}if(Nt(o))throw Dt(o),X("root node is clobbered and cannot be sanitized in-place");try{Qt(o)}catch(w){throw Dt(o),w}}else if(mt(o))e=xe("<!---->"),n=e.ownerDocument.importNode(o,!0),n.nodeType===M.element&&n.nodeName==="BODY"||n.nodeName==="HTML"?e=n:e.appendChild(n),Qt(n);else{if(!Q&&!F&&!j&&o.indexOf("<")===-1)return L&&Ot?J(o):o;if(e=xe(o),!e)return Q?null:Ot?B:""}e&&Yt&&z(e.firstChild);const m=u?o:e;try{const D=ve(m);for(;a=D.nextNode();)Fe(a,m),Ge(a),rt(a.content)&&Ct(a.content)}catch(D){throw u&&(Dt(o),V(i.removed,w=>{w.element&&wt(w.element)})),D}if(u)return V(i.removed,D=>{D.element&&wt(D.element)}),F&&Jt(o),o;if(Q){if(F&&Jt(e),bt)for(l=pn.call(e.ownerDocument);e.firstChild;)l.appendChild(e.firstChild);else l=e;return(_.shadowroot||_.shadowrootmode)&&(l=dn.call(c,l,!0)),l}let g=j?e.outerHTML:e.innerHTML;return j&&h["!doctype"]&&e.ownerDocument&&e.ownerDocument.doctype&&e.ownerDocument.doctype.name&&O(uo,e.ownerDocument.doctype.name)&&(g="<!DOCTYPE "+e.ownerDocument.doctype.name+`>
|
|
3
|
+
`+g),F&&(g=It(g)),L&&Ot?J(g):g},i.setConfig=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Zt(o),Bt=!0,yt=h,St=_},i.clearConfig=function(){ot=null,Bt=!1,yt=null,St=null,L=Ft,B=""},i.isValidAttribute=function(o,t,e){ot||Zt({});const n=E(o),a=E(t);return ze(n,a,e)},i.addHook=function(o,t){typeof t=="function"&&I(T,o)&&dt(T[o],t)},i.removeHook=function(o,t){if(I(T,o)){if(t!==void 0){const e=$n(T[o],t);return e===-1?void 0:Xn(T[o],e,1)[0]}return Ye(T[o])}},i.removeHooks=function(o){I(T,o)&&(T[o]=[])},i.removeAllHooks=function(){T=nn()},i}var Eo=sn();exports.default=Eo;
|
package/dist/widget.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),xe=require("react-dom/client"),e=require("react/jsx-runtime");function U(s){const{sdk:a,sessionId:n,onSessionCreated:t,onStreamStart:r,onStreamEnd:c,onError:o,onMessageSend:l}=s,[i,u]=d.useState([]),[f,m]=d.useState("ready"),[y,v]=d.useState(null),x=d.useRef(null),h=d.useRef(!1),b=d.useRef(n);b.current=n;const p=d.useCallback(N=>{if(h.current)return;h.current=!0,l==null||l(N);const $={id:`user_${Date.now()}`,role:"user",parts:[{type:"text",content:N}],timestamp:Date.now()},z=`assistant_${Date.now()}`,M={id:z,role:"assistant",parts:[],timestamp:Date.now()};u(C=>[...C,$,M]),m("submitted"),v(null);const D=C=>{let O="",I="",L=[],W=!1;const H=()=>{const k=[...L];if(O){const R=k.findIndex(P=>P.type==="thinking");R>=0?k[R]={type:"thinking",content:O}:k.unshift({type:"thinking",content:O})}if(I){const R=k.findLastIndex(P=>P.type==="text");R>=0?k[R]={type:"text",content:I}:k.push({type:"text",content:I})}u(R=>R.map(P=>P.id===z?{...P,parts:k}:P))};x.current=a.chat({sessionId:C,message:N,stream:!0,onMessage:k=>{switch(W||(W=!0,m("streaming")),k.type){case"thinking":O+=k.content;break;case"ai":I+=k.content;break;case"tool_call":L.push({type:"tool_call",toolName:k.toolName,toolCallId:k.toolCallId,args:k.args??"{}"});break;case"tool_result":L.push({type:"tool_result",toolName:k.toolName??"",toolCallId:k.toolCallId,content:k.content}),I&&(L.push({type:"text",content:I}),I="");break;case"interrupt":k.interrupt&&L.push({type:"interrupt",interrupt:k.interrupt,resolved:!1});break}H()},onDone:k=>{(I||L.length>0||O)&&H(),k.sessionId&&k.sessionId!==b.current&&(t==null||t(k.sessionId)),c==null||c(k.sessionId||C),m("ready"),h.current=!1,x.current=null},onError:k=>{L.push({type:"error",content:k.message}),H(),v(k),m("error"),o==null||o(k),h.current=!1,x.current=null}}),r==null||r(C)};b.current?D(b.current):a.createSession().then(C=>{b.current=C,t==null||t(C),D(C)}).catch(C=>{v(C instanceof Error?C:new Error(String(C))),m("error"),o==null||o(C instanceof Error?C:new Error(String(C))),h.current=!1})},[a,t,r,c,o,l]),j=d.useCallback(()=>{var N;(N=x.current)==null||N.abort(),x.current=null,m("ready"),h.current=!1},[]),w=d.useCallback(()=>{if(h.current)return;const N=i.findLastIndex(z=>z.role==="user");if(N<0)return;const $=i[N].parts.filter(z=>z.type==="text").map(z=>z.content).join("");u(z=>z.slice(0,N)),p($)},[i,p]),S=d.useCallback((N,$)=>{u(M=>M.map(D=>({...D,parts:D.parts.map(C=>C.type==="interrupt"&&C.interrupt.interruptId===N?{...C,resolved:!0,response:$}:C)})));const z=b.current;z&&a.respondInterrupt(N,z,$).catch(M=>{o==null||o(M instanceof Error?M:new Error(String(M)))})},[a,o]);return{messages:i,status:f,error:y,sendMessage:p,stop:j,regenerate:w,setMessages:u,respondToInterrupt:S}}const q="sa_active_conversation";function K(){try{return localStorage.getItem(q)}catch{return null}}function me(s){try{s?localStorage.setItem(q,s):localStorage.removeItem(q)}catch{}}function Y(s){const{sdk:a,onConversationChange:n}=s,[t,r]=d.useState([]),[c,o]=d.useState(()=>K()),[l,i]=d.useState(!1),u=d.useRef(!0);d.useEffect(()=>()=>{u.current=!1},[]);const f=d.useCallback(p=>{o(p),me(p),p&&(n==null||n(p))},[n]),m=d.useCallback(async()=>{i(!0);try{const p=await a.listConversations({page:1,size:100});if(!u.current)return;r(p.items);const j=K();j&&!p.items.find(w=>w.sessionId===j)&&f(null)}catch{}finally{u.current&&i(!1)}},[a,f]),y=d.useCallback(async p=>(f(p),await a.getMessages(p)),[a,f]),v=d.useCallback(()=>{f(null)},[f]),x=d.useCallback(async p=>{await a.deleteConversation(p),r(j=>j.filter(w=>w.sessionId!==p)),c===p&&f(null)},[a,c,f]),h=d.useCallback(async(p,j)=>{await a.renameConversation(p,j),r(w=>w.map(S=>S.sessionId===p?{...S,title:j}:S))},[a]),{enabled:b=!0}=s;return d.useEffect(()=>{b&&m()},[b,m]),{conversations:t,activeConversationId:c,loading:l,loadConversations:m,switchConversation:y,newConversation:v,deleteConversation:x,renameConversation:h,setActiveConversationId:f}}const J=d.createContext(null);function E(){const s=d.useContext(J);if(!s)throw new Error("useChatContext must be used within ChatProvider");return s}function B({sdk:s,hooks:a,children:n}){const[t,r]=d.useState(!1),[c,o]=d.useState(!1);d.useEffect(()=>{s.getToken().then(()=>{o(!0)}).catch(()=>{o(!0)})},[s]);const l=Y({sdk:s,onConversationChange:a==null?void 0:a.onConversationChange,enabled:c}),i=U({sdk:s,sessionId:l.activeConversationId,onSessionCreated:x=>{l.setActiveConversationId(x),l.loadConversations()},onStreamStart:a==null?void 0:a.onStreamStart,onStreamEnd:x=>{var h;(h=a==null?void 0:a.onStreamEnd)==null||h.call(a,x),l.loadConversations()},onError:a==null?void 0:a.onError,onMessageSend:a==null?void 0:a.onMessageSend}),u=d.useCallback(async x=>{const h=await l.switchConversation(x);i.setMessages(h),r(!1)},[l,i]),f=d.useCallback(()=>{l.newConversation(),i.setMessages([]),r(!1)},[l,i]),m=d.useCallback(async x=>{await l.deleteConversation(x),l.activeConversationId===x&&i.setMessages([])},[l,i]);d.useEffect(()=>{l.activeConversationId&&i.messages.length===0&&s.getMessages(l.activeConversationId).then(x=>{i.setMessages(x)}).catch(()=>{})},[]);const y=d.useCallback(()=>{r(x=>!x)},[]),v={status:i.status,error:i.error,messages:i.messages,conversations:l.conversations,activeConversationId:l.activeConversationId,isThreadListOpen:t,sendMessage:i.sendMessage,stop:i.stop,regenerate:i.regenerate,switchConversation:u,newConversation:f,deleteConversation:m,renameConversation:l.renameConversation,toggleThreadList:y,feedback:(x,h)=>{s.feedback(x,h)},respondToInterrupt:i.respondToInterrupt};return e.jsx(J.Provider,{value:v,children:n})}function g({name:s,size:a=16,color:n="currentColor",className:t,style:r}){return e.jsx("svg",{className:t,style:{width:a,height:a,fill:n,verticalAlign:"middle",...r},"aria-hidden":"true",children:e.jsx("use",{href:`#icon-${s}`})})}function X({isOpen:s,onClick:a}){return e.jsx("button",{className:`sa-trigger ${s?"sa-trigger-open":""}`,onClick:a,children:s?e.jsx(g,{name:"x",size:24,color:"#fff"}):e.jsx(g,{name:"message-square",size:24,color:"#fff"})})}function G({title:s,onClose:a,onToggleThreadList:n,showClose:t=!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:s}),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:n,title:"会话列表",children:e.jsx(g,{name:"menu",size:16})}),t&&e.jsx("button",{className:"sa-header-btn",onClick:a,title:"关闭",children:e.jsx(g,{name:"x",size:16})})]})]})}function he(s){const a=new Date,n=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),t=n-6*864e5,r=[],c=[],o=[];for(const i of s){const u=new Date(i.updateTime).getTime();u>=n?r.push(i):u>=t?c.push(i):o.push(i)}const l=[];return r.length&&l.push({label:"今天",items:r}),c.length&&l.push({label:"最近 7 天",items:c}),o.length&&l.push({label:"更早",items:o}),l}function Z(){const{conversations:s,activeConversationId:a,switchConversation:n,newConversation:t,deleteConversation:r,renameConversation:c,isThreadListOpen:o,toggleThreadList:l}=E(),[i,u]=d.useState(null),[f,m]=d.useState(""),y=d.useCallback((h,b)=>{u(h),m(b??"")},[]),v=d.useCallback(h=>{f.trim()&&c(h,f.trim()),u(null)},[f,c]),x=d.useMemo(()=>he(s),[s]);return o?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:t,children:[e.jsx(g,{name:"plus",size:14})," 新会话"]})]}),e.jsxs("div",{className:"sa-thread-list-items",children:[s.length===0&&e.jsx("div",{className:"sa-thread-list-empty",children:"暂无会话"}),x.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===a?"active":""}`,onClick:()=>n(b.sessionId),children:[i===b.sessionId?e.jsx("input",{className:"sa-thread-item-edit",value:f,onChange:p=>m(p.target.value),onBlur:()=>v(b.sessionId),onKeyDown:p=>{p.key==="Enter"&&v(b.sessionId),p.key==="Escape"&&u(null)},onClick:p=>p.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"sa-thread-item-title",onDoubleClick:p=>{p.stopPropagation(),y(b.sessionId,b.title)},children:b.title||"新会话"}),e.jsx("button",{className:"sa-thread-item-delete",onClick:p=>{p.stopPropagation(),r(b.sessionId)},title:"删除",children:e.jsx(g,{name:"trash2",size:14})})]},b.sessionId))]},h.label))]})]})]}):null}function Q(s){const a=d.useRef(null),n=d.useRef(!1),t=d.useRef(0),r=d.useCallback(()=>{const o=a.current;if(!o)return;const{scrollTop:l,scrollHeight:i,clientHeight:u}=o,f=i-l-u<40;l<t.current&&!f&&(n.current=!0),f&&(n.current=!1),t.current=l},[]);d.useEffect(()=>{const o=a.current;if(o)return o.addEventListener("scroll",r,{passive:!0}),()=>o.removeEventListener("scroll",r)},[r]),d.useEffect(()=>{if(n.current)return;const o=a.current;o&&requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight})},s);const c=d.useCallback(()=>{n.current=!1;const o=a.current;o&&(o.scrollTop=o.scrollHeight)},[]);return{containerRef:a,scrollToBottom:c}}function T(s){return s.value++}function A(s,a){const n=[],t=[],r=()=>{t.length>0&&(n.push(t.join("")),t.length=0)};let c=0;for(;c<s.length;){const o=s[c];if(o==="`"){const l=s.indexOf("`",c+1);if(l!==-1){r(),n.push(e.jsx("code",{className:"sa-inline-code",children:s.slice(c+1,l)},T(a))),c=l+1;continue}}else if(o==="*"&&s[c+1]==="*"){const l=s.indexOf("**",c+2);if(l!==-1){r(),n.push(e.jsx("strong",{children:A(s.slice(c+2,l),a)},T(a))),c=l+2;continue}}else if(o==="*"){const l=s.indexOf("*",c+1);if(l!==-1){r(),n.push(e.jsx("em",{children:A(s.slice(c+1,l),a)},T(a))),c=l+1;continue}}else if(o==="["){const l=s.indexOf("]",c+1);if(l!==-1&&s[l+1]==="("){const i=s.indexOf(")",l+2);if(i!==-1){const u=s.slice(c+1,l),f=s.slice(l+2,i);r(),n.push(e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",children:A(u,a)},T(a))),c=i+1;continue}}}t.push(o),c++}return r(),n}function ge(s,a){const n=[],t=s.split(`
|
|
2
|
-
`);let r=0;const c=i=>i.trim()==="",o=i=>/^#{1,6}\s+\S/.test(i.trim()),l=i=>/^(?:[-*+]|\d+[.)])\s+\S/.test(i.trim());for(;r<t.length;){const i=t[r],u=i.trim();if(c(i)){r++;continue}if(o(i)){const m=u.match(/^(#{1,6})\s+(.*)$/);if(m){const v=`h${Math.min(m[1].length,6)}`;n.push(d.createElement(v,{key:T(a)},A(m[2],a)))}r++;continue}if(l(i)){const m=/^\d+[.)]/.test(u),y=[];for(;r<t.length&&l(t[r]);){const v=t[r].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);v&&y.push(e.jsx("li",{children:A(v[1],a)},T(a))),r++}n.push(m?e.jsx("ol",{className:"sa-list",children:y},T(a)):e.jsx("ul",{className:"sa-list",children:y},T(a)));continue}const f=[];for(;r<t.length&&!c(t[r])&&!o(t[r])&&!l(t[r]);)f.push(t[r]),r++;n.push(e.jsx("p",{className:"sa-text-paragraph",children:A(f.join(" "),a)},T(a)))}return n}function be(s){const a={value:0},n=[],t=s.split("```");for(let r=0;r<t.length;r++)if(r%2===0)n.push(...ge(t[r],a));else if(t[r].trim()!==""){let c=t[r].replace(/^\r?\n/,"");c=c.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/,""),c=c.replace(/\r?\n$/,""),n.push(e.jsx("pre",{className:"sa-code-block",children:e.jsx("code",{children:c})},T(a)))}return n}function ee({content:s}){return e.jsx("div",{className:"sa-text-part",children:be(s)})}function se({content:s}){const[a,n]=d.useState(!1);return e.jsxs("div",{className:"sa-thinking-part",onClick:()=>n(!a),children:[e.jsxs("div",{className:"sa-thinking-header",children:[e.jsx("span",{className:"sa-thinking-icon",children:e.jsx(g,{name:"brain",size:14})}),e.jsx("span",{className:"sa-thinking-label",children:"思考过程"}),e.jsx("span",{className:`sa-thinking-arrow ${a?"expanded":""}`,children:e.jsx(g,{name:"chevron-right",size:12})})]}),a&&e.jsx("div",{className:"sa-thinking-content",children:s})]})}function ae({toolName:s,toolCallId:a,args:n}){const[t,r]=d.useState(!1);let c=n;try{c=JSON.stringify(JSON.parse(n),null,2)}catch{}return e.jsxs("div",{className:"sa-tool-call-part",children:[e.jsxs("div",{className:"sa-tool-call-header",onClick:()=>r(!t),children:[e.jsx("span",{className:"sa-tool-icon",children:e.jsx(g,{name:"zap",size:14})}),e.jsxs("span",{className:"sa-tool-name",children:["调用工具: ",s]}),e.jsx("span",{className:`sa-thinking-arrow ${t?"expanded":""}`,children:e.jsx(g,{name:"chevron-right",size:12})})]}),t&&e.jsx("pre",{className:"sa-tool-args",children:c})]})}function te({toolName:s,toolCallId:a,content:n}){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(g,{name:"circle-check",size:14,color:"#10b981"})}),e.jsx("span",{className:"sa-tool-result-label",children:s||"工具返回"})]}),e.jsx("div",{className:"sa-tool-result-content",children:n})]})}function re({content:s,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(g,{name:"triangle-alert",size:14})}),e.jsx("span",{children:s})]}),a&&e.jsx("button",{className:"sa-error-retry",onClick:a,children:"重试"})]})}function ve({interrupt:s,onRespond:a}){var c,o;const n=s.options,t=(typeof(n==null?void 0:n[0])=="string"?n[0]:(c=n==null?void 0:n[0])==null?void 0:c.label)||"确认",r=(typeof(n==null?void 0:n[1])=="string"?n[1]:(o=n==null?void 0:n[1])==null?void 0:o.label)||"取消";return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(g,{name:"circle-alert",size:16,color:"#f59e0b"}),e.jsx("span",{children:s.content})]}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",onClick:()=>a({action:"confirm"}),children:[e.jsx(g,{name:"check",size:14})," ",t]}),e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>a({action:"cancel"}),children:[e.jsx(g,{name:"x",size:14})," ",r]})]})]})}function je(s){return typeof s=="string"?{value:s,label:s}:s}function ye({interrupt:s,onRespond:a}){const n=(s.options??[]).map(je);return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(g,{name:"list",size:16,color:"#6366f1"}),e.jsx("span",{children:s.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:n.map(t=>e.jsxs("button",{className:`sa-interrupt-option ${t.danger?"sa-interrupt-option-danger":""}`,onClick:()=>a({action:"select",value:t.value}),children:[t.icon&&e.jsx(g,{name:t.icon,size:14}),e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"sa-interrupt-option-desc",children:t.description})]},t.value))})]})}function ke(s){return typeof s=="string"?{value:s,label:s}:s}function we({interrupt:s,onRespond:a}){const n=(s.options??[]).map(ke),[t,r]=d.useState(new Set),c=o=>{r(l=>{const i=new Set(l);return i.has(o)?i.delete(o):i.add(o),i})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(g,{name:"list-checks",size:16,color:"#6366f1"}),e.jsx("span",{children:s.content})]}),e.jsx("div",{className:"sa-interrupt-options",children:n.map(o=>e.jsxs("button",{className:`sa-interrupt-option ${t.has(o.value)?"sa-interrupt-option-selected":""}`,onClick:()=>c(o.value),children:[e.jsx(g,{name:t.has(o.value)?"square-check":"square",size:14}),e.jsx("span",{children:o.label})]},o.value))}),e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:t.size===0,onClick:()=>a({action:"submit",value:Array.from(t)}),children:[e.jsx(g,{name:"check",size:14})," 确认 (",t.size,")"]})})]})}function Ce({interrupt:s,onRespond:a}){const[n,t]=d.useState(""),r=s.inputType??"text",c=r==="textarea",o=()=>{s.required&&!n.trim()||a({action:"submit",value:n.trim()})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(g,{name:"text-cursor-input",size:16,color:"#6366f1"}),e.jsx("span",{children:s.content})]}),e.jsx("div",{className:"sa-interrupt-input-area",children:c?e.jsx("textarea",{className:"sa-interrupt-textarea",value:n,onChange:l=>t(l.target.value),placeholder:s.placeholder,maxLength:s.maxLength,rows:3}):e.jsx("input",{className:"sa-interrupt-input",type:r,value:n,onChange:l=>t(l.target.value),placeholder:s.placeholder,maxLength:s.maxLength,onKeyDown:l=>l.key==="Enter"&&o()})}),e.jsx("div",{className:"sa-interrupt-actions",children:e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:s.required?!n.trim():!1,onClick:o,children:[e.jsx(g,{name:"check",size:14})," 提交"]})})]})}function Ne({interrupt:s,onRespond:a}){const n=s.fields??[],[t,r]=d.useState(()=>{const i={};for(const u of n)i[u.name]=u.defaultValue??"";return i}),c=(i,u)=>{r(f=>({...f,[i]:u}))},o=n.every(i=>!i.required||t[i.name]),l=()=>{o&&a({action:"submit",value:t})};return e.jsxs("div",{className:"sa-interrupt-card",children:[e.jsxs("div",{className:"sa-interrupt-content",children:[e.jsx(g,{name:"file-text",size:16,color:"#6366f1"}),e.jsx("span",{children:s.content})]}),e.jsx("div",{className:"sa-interrupt-form",children:n.map(i=>e.jsxs("div",{className:"sa-interrupt-form-field",children:[e.jsxs("label",{className:"sa-interrupt-form-label",children:[i.label,i.required&&e.jsx("span",{className:"sa-interrupt-form-required",children:"*"})]}),ze(i,t[i.name],u=>c(i.name,u))]},i.name))}),e.jsxs("div",{className:"sa-interrupt-actions",children:[e.jsxs("button",{className:"sa-interrupt-btn sa-interrupt-btn-primary",disabled:!o,onClick:l,children:[e.jsx(g,{name:"check",size:14})," 提交"]}),e.jsx("button",{className:"sa-interrupt-btn sa-interrupt-btn-secondary",onClick:()=>a({action:"cancel"}),children:"取消"})]})]})}function ze(s,a,n){switch(s.type){case"textarea":return e.jsx("textarea",{className:"sa-interrupt-textarea",value:a,onChange:t=>n(t.target.value),placeholder:s.placeholder,rows:3});case"select":return e.jsxs("select",{className:"sa-interrupt-select",value:a,onChange:t=>n(t.target.value),children:[e.jsx("option",{value:"",children:"请选择"}),(s.options??[]).map(t=>e.jsx("option",{value:t,children:t},t))]});default:return e.jsx("input",{className:"sa-interrupt-input",type:s.type,value:a,onChange:t=>n(t.target.value),placeholder:s.placeholder})}}function ne({interrupt:s,resolved:a,response:n,onRespond:t}){if(a)return e.jsxs("div",{className:"sa-interrupt-resolved",children:[e.jsx(g,{name:"circle-check",size:14,color:"#10b981"}),e.jsx("span",{children:Se(s.interruptType,n)})]});switch(s.interruptType){case"confirm":return e.jsx(ve,{interrupt:s,onRespond:t});case"select":return e.jsx(ye,{interrupt:s,onRespond:t});case"multiSelect":return e.jsx(we,{interrupt:s,onRespond:t});case"input":return e.jsx(Ce,{interrupt:s,onRespond:t});case"form":return e.jsx(Ne,{interrupt:s,onRespond:t});default:return e.jsxs("div",{className:"sa-interrupt-unknown",children:["未知的交互类型: ",s.interruptType]})}}function Se(s,a){if(!a)return"已完成";switch(a.action){case"confirm":return"已确认";case"cancel":return"已取消";case"select":return`已选择: ${a.value}`;case"submit":return"已提交";case"reject":return"已拒绝";default:return"已完成"}}function ie({message:s,onCopy:a,onRegenerate:n,onFeedback:t}){const{status:r}=E(),[c,o]=d.useState(null),[l,i]=d.useState(!1);if(r!=="ready"&&r!=="error")return null;const u=d.useCallback(()=>{a(),i(!0),setTimeout(()=>i(!1),2e3)},[a]),f=d.useCallback(m=>{const y=c===m?null:m;o(y),y&&(t==null||t(s.id,y))},[c,s.id,t]);return e.jsxs("div",{className:"sa-action-bar",children:[e.jsxs("button",{className:"sa-action-btn",onClick:u,title:"复制",children:[e.jsx(g,{name:l?"circle-check":"copy",size:14})," ",l?"已复制":"复制"]}),e.jsxs("button",{className:"sa-action-btn",onClick:n,title:"重新生成",children:[e.jsx(g,{name:"refresh-cw",size:14})," 重新生成"]}),e.jsx("span",{className:"sa-action-divider"}),e.jsx("button",{className:`sa-action-btn ${c==="like"?"sa-action-btn-active":""}`,onClick:()=>f("like"),title:"有用",children:e.jsx(g,{name:"thumbs-up",size:14})}),e.jsx("button",{className:`sa-action-btn ${c==="dislike"?"sa-action-btn-active":""}`,onClick:()=>f("dislike"),title:"无用",children:e.jsx(g,{name:"thumbs-down",size:14})})]})}function V({src:s,role:a}){const n=a==="assistant"?"A":"U";return s?s.startsWith("http")||s.startsWith("/")||s.startsWith("data:")?e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:e.jsx("img",{src:s,alt:a,style:{width:"100%",height:"100%",borderRadius:"inherit",objectFit:"cover"}})}):e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:s}):e.jsx("div",{className:`sa-avatar sa-avatar-${a}`,children:n})}function oe({message:s,isStreaming:a,isLast:n,slots:t,avatar:r}){const{regenerate:c,feedback:o,respondToInterrupt:l}=E(),i=d.useCallback(()=>{var j;const p=s.parts.filter(w=>w.type==="text").map(w=>w.content).join(`
|
|
3
|
-
`);(j=navigator.clipboard)==null||j.writeText(p).catch(()=>{})},[s]),u=s.role==="user",f=t.Message;if(f)return e.jsx(f,{message:s,isStreaming:a,isLast:n,avatar:r,slots:t,onCopy:i,onRegenerate:c,onFeedback:o});const m=t.TextPart??ee,y=t.ThinkingPart??se,v=t.ToolCallPart??ae,x=t.ToolResultPart??te,h=t.ErrorPart??re,b=t.ActionBar??ie;return e.jsxs("div",{className:`sa-message ${u?"sa-message-user":"sa-message-assistant"}`,children:[!u&&e.jsx(V,{src:r==null?void 0:r.assistant,role:"assistant"}),e.jsxs("div",{className:"sa-message-body",children:[s.parts.map((p,j)=>{switch(p.type){case"text":return e.jsx(m,{content:p.content},j);case"thinking":return e.jsx(y,{content:p.content},j);case"tool_call":return e.jsx(v,{toolName:p.toolName,toolCallId:p.toolCallId,args:p.args},j);case"tool_result":return e.jsx(x,{toolName:p.toolName,toolCallId:p.toolCallId,content:p.content},j);case"error":return e.jsx(h,{content:p.content,onRetry:c},j);case"interrupt":return e.jsx(ne,{interrupt:p.interrupt,resolved:p.resolved??!1,response:p.response,onRespond:w=>l(p.interrupt.interruptId,w)},j);default:return null}}),a&&n&&!u&&e.jsx("span",{className:"sa-streaming-cursor",children:"|"}),!u&&!a&&s.parts.length>0&&e.jsx(b,{message:s,onCopy:i,onRegenerate:c,onFeedback:o})]}),u&&e.jsx(V,{src:r==null?void 0:r.user,role:"user"})]})}function le({message:s,suggestedPrompts:a,onPromptClick:n}){return e.jsxs("div",{className:"sa-welcome",children:[e.jsx("div",{className:"sa-welcome-icon",children:e.jsx(g,{name:"sparkles",size:40})}),e.jsx("p",{className:"sa-welcome-message",children:s||"你好!有什么可以帮你的?"}),a&&a.length>0&&e.jsx("div",{className:"sa-welcome-prompts",children:a.map((t,r)=>e.jsx("button",{className:"sa-welcome-prompt",onClick:()=>n(t),children:t},r))})]})}function F({slots:s,welcomeMessage:a,suggestedPrompts:n,avatar:t}){const{messages:r,status:c,sendMessage:o}=E(),{containerRef:l}=Q([r]),i=c==="streaming",u=s.WelcomeScreen??le;return r.length===0?e.jsx("div",{className:"sa-thread",ref:l,children:e.jsx(u,{message:a,suggestedPrompts:n,onPromptClick:o})}):e.jsx("div",{className:"sa-thread",ref:l,children:r.map((f,m)=>e.jsx(oe,{message:f,isStreaming:i,isLast:m===r.length-1,slots:s,avatar:t},f.id))})}function _(){const{status:s,sendMessage:a,stop:n}=E(),[t,r]=d.useState(""),c=d.useRef(null),o=s==="streaming"||s==="submitted",l=d.useCallback(()=>{const f=t.trim();!f||o||(a(f),r(""),c.current&&(c.current.style.height="auto"))},[t,o,a]),i=d.useCallback(f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),l())},[l]),u=d.useCallback(f=>{r(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:c,className:"sa-composer-input",value:t,onChange:u,onKeyDown:i,placeholder:"输入消息...",rows:1,disabled:s==="submitted"}),o?e.jsx("button",{className:"sa-composer-stop",onClick:n,title:"停止",children:e.jsx(g,{name:"circle-stop",size:16,color:"#fff"})}):e.jsx("button",{className:"sa-composer-send",onClick:l,disabled:!t.trim(),title:"发送",children:e.jsx(g,{name:"arrow-up",size:16,color:"#fff"})})]})}function Te({isOpen:s,onClose:a,title:n,slots:t,welcomeMessage:r,suggestedPrompts:c,avatar:o}){const{status:l,sendMessage:i,stop:u,toggleThreadList:f,conversations:m,activeConversationId:y,switchConversation:v,newConversation:x,deleteConversation:h,renameConversation:b,isThreadListOpen:p}=E();if(!s)return null;const j=t.Header,w=t.Composer,S=t.ThreadList;return e.jsxs("div",{className:"sa-panel",children:[j?e.jsx(j,{title:n,onClose:a,onToggleThreadList:f}):e.jsx(G,{title:n,onClose:a,onToggleThreadList:f}),S&&p?e.jsx(S,{conversations:m,activeSessionId:y,onSwitch:v,onNew:x,onDelete:h,onRename:b}):e.jsx(Z,{}),e.jsx(F,{slots:t,welcomeMessage:r,suggestedPrompts:c,avatar:o}),w?e.jsx(w,{status:l,onSend:i,onStop:u}):e.jsx(_,{})]})}function Ie({conversations:s,activeSessionId:a,onSwitch:n,onNew:t,onDelete:r,isCollapsed:c,onToggleCollapse:o}){const[l,i]=d.useState(null),[u,f]=d.useState(null),m=d.useCallback((v,x)=>{x.stopPropagation(),u===v?(r(v),f(null)):(f(v),setTimeout(()=>f(null),3e3))},[u,r]),y=(()=>{const v=Date.now(),x=[],h=[],b=[];for(const j of s){const w=v-new Date(j.updateTime).getTime();w<864e5?x.push(j):w<6048e5?h.push(j):b.push(j)}const p=[];return x.length&&p.push({label:"今天",items:x}),h.length&&p.push({label:"最近 7 天",items:h}),b.length&&p.push({label:"更早",items:b}),p})();return c?e.jsxs("div",{className:"sa-fp-sidebar sa-fp-sidebar-collapsed",children:[e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:o,title:"展开",children:e.jsx(g,{name:"panel-left",size:18})}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:t,title:"新会话",style:{marginTop:4},children:e.jsx(g,{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:t,children:[e.jsx(g,{name:"plus",size:15})," ",e.jsx("span",{children:"新会话"})]}),e.jsx("button",{className:"sa-fp-sidebar-toggle",onClick:o,title:"收起侧边栏",children:e.jsx(g,{name:"panel-left-close",size:18})})]}),e.jsxs("div",{className:"sa-fp-sidebar-list",children:[s.length===0&&e.jsx("div",{className:"sa-fp-sidebar-empty",children:"开始你的第一个对话"}),y.map(v=>e.jsxs("div",{children:[e.jsx("div",{className:"sa-fp-sidebar-group",children:v.label}),v.items.map(x=>{const h=x.sessionId===a,b=l===x.sessionId,p=u===x.sessionId;return e.jsxs("div",{className:`sa-fp-sidebar-item ${h?"active":""}`,onClick:()=>n(x.sessionId),onMouseEnter:()=>i(x.sessionId),onMouseLeave:()=>i(null),children:[e.jsx("span",{className:"sa-fp-sidebar-item-title",children:x.title||"新会话"}),b&&e.jsx("button",{className:`sa-fp-sidebar-item-action ${p?"danger":""}`,onClick:j=>m(x.sessionId,j),title:p?"确认删除":"删除",children:e.jsx(g,{name:p?"x":"trash2",size:14})})]},x.sessionId)})]},v.label))]})]})}function ce({title:s,slots:a,welcomeMessage:n,suggestedPrompts:t,sidebarDefaultOpen:r=!0,onClose:c,avatar:o}){const{status:l,sendMessage:i,stop:u,conversations:f,activeConversationId:m,switchConversation:y,newConversation:v,deleteConversation:x,renameConversation:h}=E(),[b,p]=d.useState(r),j=d.useCallback(()=>p(N=>!N),[]),w=a.ThreadList,S=a.Composer;return e.jsxs("div",{className:"sa-fullpage",children:[w?e.jsx("div",{className:`sa-fp-sidebar-wrapper ${b?"":"sa-fp-sidebar-wrapper-collapsed"}`,children:e.jsx(w,{conversations:f,activeSessionId:m,onSwitch:y,onNew:v,onDelete:x,onRename:h})}):e.jsx(Ie,{conversations:f,activeSessionId:m,onSwitch:y,onNew:v,onDelete:x,onRename:h,isCollapsed:!b,onToggleCollapse:j}),e.jsxs("div",{className:"sa-fp-main",children:[e.jsxs("div",{className:"sa-fp-header",children:[!b&&!w&&e.jsx("button",{className:"sa-fp-header-btn",onClick:j,title:"展开侧边栏",children:e.jsx(g,{name:"panel-left",size:18})}),e.jsx("div",{className:"sa-fp-header-title",children:s}),e.jsx("div",{className:"sa-fp-header-actions",children:c&&e.jsx("button",{className:"sa-fp-header-btn",onClick:c,title:"关闭",children:e.jsx(g,{name:"x",size:18})})})]}),e.jsx(F,{slots:a,welcomeMessage:n,suggestedPrompts:t,avatar:o}),S?e.jsx(S,{status:l,onSend:i,onStop:u}):e.jsx(_,{})]})]})}function de(s){const{sdk:a,mode:n="floating",slots:t={},hooks:r={},welcomeMessage:c,suggestedPrompts:o,title:l="AI Assistant",initialOpen:i=!1,onOpenChange:u,sidebarDefaultOpen:f,avatar:m}=s,[y,v]=d.useState(i);d.useEffect(()=>{v(i)},[i]);const x=d.useCallback(()=>{var j,w;const p=!y;v(p),u==null||u(p),p?(j=r.onOpen)==null||j.call(r):(w=r.onClose)==null||w.call(r)},[y,r,u]),h=d.useCallback(()=>{var p;v(!1),u==null||u(!1),(p=r.onClose)==null||p.call(r)},[r,u]),b=t.Trigger??X;return n==="fullpage"?y?e.jsx(B,{sdk:a,hooks:r,children:e.jsx(ce,{title:l,slots:t,welcomeMessage:c,suggestedPrompts:o,sidebarDefaultOpen:f,onClose:h,avatar:m})}):null:e.jsxs(B,{sdk:a,hooks:r,children:[e.jsx(b,{isOpen:y,onClick:x}),e.jsx(Te,{isOpen:y,onClose:h,title:l,slots:t,welcomeMessage:c,suggestedPrompts:o,avatar:m})]})}const pe=`
|
|
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=`
|
|
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; top: 100%; left: 0; right: 0;
|
|
562
|
+
margin-top: 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 {
|
|
@@ -892,6 +931,15 @@
|
|
|
892
931
|
background: #e5e7eb;
|
|
893
932
|
}
|
|
894
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
|
+
|
|
895
943
|
.sa-interrupt-options {
|
|
896
944
|
display: flex;
|
|
897
945
|
flex-direction: column;
|
|
@@ -1276,7 +1324,7 @@
|
|
|
1276
1324
|
}
|
|
1277
1325
|
|
|
1278
1326
|
.sa-fp-header-btn {
|
|
1279
|
-
width: 34px;
|
|
1327
|
+
min-width: 34px;
|
|
1280
1328
|
height: 34px;
|
|
1281
1329
|
border: none;
|
|
1282
1330
|
border-radius: 8px;
|
|
@@ -1320,4 +1368,165 @@
|
|
|
1320
1368
|
border-color: #d4d4d8;
|
|
1321
1369
|
box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
|
|
1322
1370
|
}
|
|
1323
|
-
|
|
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 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;
|