@topthink/chat 1.1.17 → 1.1.18-alpha.0

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.
Files changed (2) hide show
  1. package/es/index.js +15 -15
  2. package/package.json +2 -2
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as m,dayjs as u,RequestButton as p,useImmer as g,Lightbox as f,Clipboard as b,isImageUrl as v,request as x}from"@topthink/components";import*as y from"react";import{createContext as w,useContext as k,useRef as N,useCallback as E,useState as j,useEffect as C,forwardRef as M,useMemo as z,useImperativeHandle as $,Fragment as q,memo as S}from"react";import R from"react-textarea-autosize";import*as F from"path";import A from"path";import{Spinner as I,Badge as D,CloseButton as T,OverlayTrigger as L,Popover as P}from"react-bootstrap";import O from"eventemitter3";import B from"lodash/isEqual";import _ from"react-markdown";import"katex/dist/katex.min.css";import U from"remark-math";import H from"remark-breaks";import J from"remark-gfm";import K from"rehype-katex";import Q from"rehype-highlight";import{codes as W,types as X}from"micromark-util-symbol";import{markdownLineEnding as V}from"micromark-util-character";import{createPortal as Y}from"react-dom";import G from"use-resize-observer";const Z=function(e){let{ext:r}=e;const{result:n}=a((async e=>(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-nWXnlyT_.js");case"../../images/file/jpg.svg":return import("./jpg-6tBxSzWk.js");case"../../images/file/md.svg":return import("./md-GZ3HJPcw.js");case"../../images/file/pdf.svg":return import("./pdf-pVX1_E6T.js");case"../../images/file/png.svg":return import("./png-u0o1NMqQ.js");case"../../images/file/pptx.svg":return import("./pptx-Hprz0cON.js");case"../../images/file/txt.svg":return import("./txt-eHeCpvNO.js");case"../../images/file/xlsx.svg":return import("./xlsx-uOft-SV2.js");default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`../../images/file/${e}.svg`)).default),[r]);return n?t("img",{width:30,height:30,src:n}):null};function ee(r){let{className:n,name:i,size:a,loading:l,error:c,onRemove:d}=r;const h=A.extname(i).substring(1),m=e(ie,{className:n,$error:!!c,children:[e(ne,{children:[t(Z,{ext:h}),l&&t(I,{variant:"primary"})]}),e(re,{children:[t("h4",{children:i}),t("p",{children:o(a,1)})]}),d&&t(te,{onClick:e=>{e.preventDefault(),d()},children:t("i",{className:"bi bi-trash3"})})]});return c?t(s,{placement:"top",tooltip:c,children:m}):m}const te=n.div`
1
+ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as m,dayjs as u,RequestButton as p,useImmer as g,Lightbox as f,Clipboard as b,isImageUrl as v,request as x}from"@topthink/components";import*as y from"react";import{createContext as w,useContext as k,useRef as N,useCallback as E,useState as j,useEffect as C,forwardRef as M,useMemo as q,useImperativeHandle as z,Fragment as $,memo as S}from"react";import R from"react-textarea-autosize";import*as F from"path";import A from"path";import{Spinner as I,Badge as D,CloseButton as T,OverlayTrigger as L,Popover as P}from"react-bootstrap";import O from"eventemitter3";import B from"lodash/isEqual";import _ from"react-markdown";import"katex/dist/katex.min.css";import U from"remark-math";import H from"remark-breaks";import J from"remark-gfm";import K from"rehype-katex";import Q from"rehype-highlight";import{codes as W,types as X}from"micromark-util-symbol";import{markdownLineEnding as V}from"micromark-util-character";import{createPortal as Y}from"react-dom";import G from"use-resize-observer";const Z=function(e){let{ext:r}=e;const{result:n}=a((async e=>(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-nWXnlyT_.js");case"../../images/file/jpg.svg":return import("./jpg-6tBxSzWk.js");case"../../images/file/md.svg":return import("./md-GZ3HJPcw.js");case"../../images/file/pdf.svg":return import("./pdf-pVX1_E6T.js");case"../../images/file/png.svg":return import("./png-u0o1NMqQ.js");case"../../images/file/pptx.svg":return import("./pptx-Hprz0cON.js");case"../../images/file/txt.svg":return import("./txt-eHeCpvNO.js");case"../../images/file/xlsx.svg":return import("./xlsx-uOft-SV2.js");default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`../../images/file/${e}.svg`)).default),[r]);return n?t("img",{width:30,height:30,src:n}):null};function ee(r){let{className:n,name:i,size:a,loading:l,error:c,onRemove:d}=r;const h=A.extname(i).substring(1),m=e(ie,{className:n,$error:!!c,children:[e(ne,{children:[t(Z,{ext:h}),l&&t(I,{variant:"primary"})]}),e(re,{children:[t("h4",{children:i}),t("p",{children:o(a,1)})]}),d&&t(te,{onClick:e=>{e.preventDefault(),d()},children:t("i",{className:"bi bi-trash3"})})]});return c?t(s,{placement:"top",tooltip:c,children:m}):m}const te=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -87,7 +87,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
87
87
  background-color: var(--bs-gray-200);
88
88
  }
89
89
 
90
- `;let he=class{#e;#t;constructor(){this.#t=new O}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},me=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new O}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach((e=>e.stop())),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const ue=M(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=ae(),l=z((()=>{if("builtin"!==o)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",o);return(await a({url:"/transcriptions",method:"post",data:t})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:m}=function(e){let{onResult:t,loader:r}=e;const n=N(),[i,o]=j(!1),[s,a]=j(!1);return C((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:s,start:async()=>{n.current||(n.current=r?new me(r):new he,n.current.onRecording(o),n.current.onTranscribing(a),n.current.onResult(t)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:l});return $(n,(()=>({start:c,stop:d})),[c,d]),t(s,{tooltip:h?"停止":"语音输入",placement:"top",children:e(de,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[m&&t(pe,{animation:"border",variant:"primary",size:"sm"}),t("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),pe=n(I)`
90
+ `;let he=class{#e;#t;constructor(){this.#t=new O}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},me=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new O}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach((e=>e.stop())),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const ue=M(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=ae(),l=q((()=>{if("builtin"!==o)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",o);return(await a({url:"/transcriptions",method:"post",data:t})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:m}=function(e){let{onResult:t,loader:r}=e;const n=N(),[i,o]=j(!1),[s,a]=j(!1);return C((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:s,start:async()=>{n.current||(n.current=r?new me(r):new he,n.current.onRecording(o),n.current.onTranscribing(a),n.current.onResult(t)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:l});return z(n,(()=>({start:c,stop:d})),[c,d]),t(s,{tooltip:h?"停止":"语音输入",placement:"top",children:e(de,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[m&&t(pe,{animation:"border",variant:"primary",size:"sm"}),t("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),pe=n(I)`
91
91
  position: absolute;
92
92
  --bs-spinner-width: .75rem;
93
93
  --bs-spinner-height: .75rem;
@@ -116,7 +116,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
116
116
  &:hover {
117
117
  background-color: var(--bs-secondary-bg-subtle);
118
118
  }
119
- `;function be(){const{request:n,reset:i,conversationId:o}=ae(),[a,l]=j(!1);return e(r,{children:[t(ge,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:t("i",{className:"bi bi-clock-history"})}),t(m,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:ve,children:a&&t(Ne,{children:t(ke,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:r=>{let{data:a,loading:c,setData:d}=r;return a.length||c?a.map(((r,a)=>{const c=r.messages?.reduce(((e,t)=>e+t.chunks.reduce(((e,t)=>e+(t.content||"")),"")),"");return e(q,{children:[a>0&&t("hr",{className:"mx-2 my-2"}),e(we,{onClick:()=>{i(r),l(!1)},children:[e(ye,{children:[o===r.id&&t(D,{bg:"secondary",children:"当前"}),t("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),t("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:u(r.update_time).fromNow()})]}),e(xe,{children:[t("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),t("span",{className:"ms-3",children:o!==r.id&&t(s,{tooltip:"删除",children:t(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const t=e.findIndex((e=>e.id===r.id));-1!==t&&e.splice(t,1)}))},children:t("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)})):t("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const ve=n.div`
119
+ `;function be(){const{request:n,reset:i,conversationId:o}=ae(),[a,l]=j(!1);return e(r,{children:[t(ge,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:t("i",{className:"bi bi-clock-history"})}),t(m,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:ve,children:a&&t(Ne,{children:t(ke,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:r=>{let{data:a,loading:c,setData:d}=r;return a.length||c?a.map(((r,a)=>{const c=r.messages?.reduce(((e,t)=>e+t.chunks.reduce(((e,t)=>e+(t.content||"")),"")),"");return e($,{children:[a>0&&t("hr",{className:"mx-2 my-2"}),e(we,{onClick:()=>{i(r),l(!1)},children:[e(ye,{children:[o===r.id&&t(D,{bg:"secondary",children:"当前"}),t("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),t("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:u(r.update_time).fromNow()})]}),e(xe,{children:[t("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),t("span",{className:"ms-3",children:o!==r.id&&t(s,{tooltip:"删除",children:t(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const t=e.findIndex((e=>e.id===r.id));-1!==t&&e.splice(t,1)}))},children:t("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)})):t("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const ve=n.div`
120
120
  padding: 0;
121
121
  overflow: hidden;
122
122
  `,xe=n.div`
@@ -158,15 +158,15 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
158
158
  `,Ne=n.div`
159
159
  height: 100%;
160
160
  overflow-y: auto;
161
- `;var Ee;function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},je.apply(this,arguments)}const Ce=e=>y.createElement("svg",je({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ee||(Ee=y.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function Me(){const{reset:e}=ae();return t(ge,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(Ce,{})})}function ze(r){let{children:n}=r;return e(qe,{children:[n,e($e,{children:[t(be,{}),t(Me,{})]})]})}const $e=n.div`
161
+ `;var Ee;function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},je.apply(this,arguments)}const Ce=e=>y.createElement("svg",je({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ee||(Ee=y.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function Me(){const{reset:e}=ae();return t(ge,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(Ce,{})})}function qe(r){let{children:n}=r;return e($e,{children:[n,e(ze,{children:[t(be,{}),t(Me,{})]})]})}const ze=n.div`
162
162
  display: flex;
163
163
  gap: .25rem;
164
164
  margin-left: auto;
165
- `,qe=n.div`
165
+ `,$e=n.div`
166
166
  margin-bottom: .5rem;
167
167
  display: flex;
168
168
  padding: 0 .125rem;
169
- `;var Se=M((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:c,variables:h,minRows:m,toolbar:u,disabled:p,autoFocus:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const v=N(null),x=N(null),y=N(null),[w,k]=j(""),[M,z]=j(""),[q,S]=g([]),[A,I]=j(!1),D=o&&o.length>0?o:oe,{messages:L,loading:P,request:O}=ae(),{send:B}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:s,setConversationId:a,request:c}=ae(),d=N(null),h=E((async()=>{d.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:s},signal:d.current.signal};const t=await c(e);i(t)}catch{}finally{d.current=null}}),[s,c]),m=E((async function(e){if("string"==typeof e){for(var m=arguments.length,u=new Array(m>1?m-1:0),p=1;p<m;p++)u[p-1]=arguments[p];e={query:e,...u}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){d.current&&d.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:s},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?a(t.conversation):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",reasoning:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.reasoning?r.chunks[e].reasoning+=t.chunks.reasoning:t.chunks.content?r.chunks[e].content+=t.chunks.content:t.chunks.node&&(r.chunks[e].node={...r.chunks[e].node,...t.chunks.node})}else t.stats?r.stats=t.stats:t.id&&(r.id=t.id)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await c(e),t&&h()}catch(e){let t="未知错误";l(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[s,c]);return{send:m}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{v.current?.focus()}))}}),[_,U]=j();C((()=>{const e=L.filter((e=>!!e.query));U(e.at(-1)?.variables)}),[L]),C((()=>{!o&&q.length>0&&S([])}),[o]),C((()=>{const e=c.current;if(e&&B){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};h&&(t.variables={..._,...h.values}),B(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[h,_]);const H=E((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!D.includes(F.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-q.length);S((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await O({method:"POST",url:"/upload",data:t});S((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=l(t)?t.message:"unknown error";S((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[q,D]),J=q.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),K=E((()=>{if(w||J.length>0){const e={query:w,files:J};h&&(e.variables={..._,...h.values}),M&&(e.quote=M),B(e),k(""),z(""),S([]),y.current?.stop(!0)}}),[w,J,h,_,M]);if($(n,(()=>({setQuery:k,setQuote:z,send:B,focus(){v.current?.focus()}}))),h){const e=h.config.filter((e=>!(e.key in(h.values||{})))),r=function(t){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!t&&e.every((e=>{const n=!e.required||t?.[e.key];return!n&&r&&d.error("请完善必填信息"),n}))};if(e.length>0&&!r(_))return t(Fe,{children:t(Re,{children:t(ce,{values:_,variables:e,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return U(t),!0}})})})}return e(Pe,{children:[u&&t(ze,{children:u}),e(Le,{$focused:A&&!P,children:[q.length>0&&t(Ie,{children:q.map(((e,r)=>{let{file:n,error:i,path:o}=e;const s=void 0===i&&void 0===o;return t(Ae,{name:n.name,size:n.size,error:i,loading:s,onRemove:()=>{S((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!M&&e(Te,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:M}),t(T,{onClick:()=>z("")})]}),e(De,{children:[t(R,{disabled:P||p,ref:v,placeholder:b,minRows:m,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())},autoFocus:f,onFocus:()=>I(!0),onBlur:()=>I(!1)}),o&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(de,{disabled:q.length>=6,onClick:()=>x.current?.click(),children:[t("input",{onChange:H,multiple:!0,accept:D.join(","),ref:x,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&t(ue,{ref:y,model:a.model,onResult:e=>{v.current?.focus(),k((t=>t+e+" "))}}),t(de,{className:"text-primary",disabled:!w&&0===J.length,onClick:e=>{e.preventDefault(),K()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})}));const Re=n.div`
169
+ `;var Se=M((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:c,variables:h,minRows:m,toolbar:u,disabled:p,autoFocus:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const v=N(null),x=N(null),y=N(null),[w,k]=j(""),[M,q]=j(""),[$,S]=g([]),[A,I]=j(!1),D=o&&o.length>0?o:oe,{messages:L,loading:P,request:O}=ae(),{send:B}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:s,setConversationId:a,request:c}=ae(),d=N(null),h=N(s),m=E((async()=>{d.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:h.current},signal:d.current.signal};const t=await c(e);i(t)}catch{}finally{d.current=null}}),[c]),u=E((async function(e){if("string"==typeof e){for(var s=arguments.length,u=new Array(s>1?s-1:0),p=1;p<s;p++)u[p-1]=arguments[p];e={query:e,...u}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){d.current&&d.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:h.current},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?(h.current=t.conversation,a(t.conversation)):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",reasoning:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.reasoning?r.chunks[e].reasoning+=t.chunks.reasoning:t.chunks.content?r.chunks[e].content+=t.chunks.content:t.chunks.node&&(r.chunks[e].node={...r.chunks[e].node,...t.chunks.node})}else t.stats?r.stats=t.stats:t.id&&(r.id=t.id)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await c(e),t&&requestAnimationFrame(m)}catch(e){let t="未知错误";l(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[c]);return{send:u}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{v.current?.focus()}))}}),[_,U]=j();C((()=>{const e=L.filter((e=>!!e.query));U(e.at(-1)?.variables)}),[L]),C((()=>{!o&&$.length>0&&S([])}),[o]),C((()=>{const e=c.current;if(e&&B){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};h&&(t.variables={..._,...h.values}),B(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[h,_]);const H=E((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!D.includes(F.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-$.length);S((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await O({method:"POST",url:"/upload",data:t});S((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=l(t)?t.message:"unknown error";S((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[$,D]),J=$.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),K=E((()=>{if(w||J.length>0){const e={query:w,files:J};h&&(e.variables={..._,...h.values}),M&&(e.quote=M),B(e),k(""),q(""),S([]),y.current?.stop(!0)}}),[w,J,h,_,M]);if(z(n,(()=>({setQuery:k,setQuote:q,send:B,focus(){v.current?.focus()}}))),h){const e=h.config.filter((e=>!(e.key in(h.values||{})))),r=function(t){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!t&&e.every((e=>{const n=!e.required||t?.[e.key];return!n&&r&&d.error("请完善必填信息"),n}))};if(e.length>0&&!r(_))return t(Fe,{children:t(Re,{children:t(ce,{values:_,variables:e,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return U(t),!0}})})})}return e(Pe,{children:[u&&t(qe,{children:u}),e(Le,{$focused:A&&!P,children:[$.length>0&&t(Ie,{children:$.map(((e,r)=>{let{file:n,error:i,path:o}=e;const s=void 0===i&&void 0===o;return t(Ae,{name:n.name,size:n.size,error:i,loading:s,onRemove:()=>{S((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!M&&e(Te,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:M}),t(T,{onClick:()=>q("")})]}),e(De,{children:[t(R,{disabled:P||p,ref:v,placeholder:b,minRows:m,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())},autoFocus:f,onFocus:()=>I(!0),onBlur:()=>I(!1)}),o&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(de,{disabled:$.length>=6,onClick:()=>x.current?.click(),children:[t("input",{onChange:H,multiple:!0,accept:D.join(","),ref:x,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&t(ue,{ref:y,model:a.model,onResult:e=>{v.current?.focus(),k((t=>t+e+" "))}}),t(de,{className:"text-primary",disabled:!w&&0===J.length,onClick:e=>{e.preventDefault(),K()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})}));const Re=n.div`
170
170
  border-radius: var(--bs-border-radius-lg);
171
171
  box-shadow: var(--bs-box-shadow-sm);
172
172
  margin: 1rem;
@@ -236,7 +236,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
236
236
  box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
237
237
  `,Pe=n.div`
238
238
  margin: 0 1rem 1rem;
239
- `;function Oe(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",node:r,error:n,tools:i=[],reasoning:o}=e;return{content:t,reasoning:o,error:n,tools:i,node:r}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}function Be(e){if((e=e.filter((e=>!!e.trim()))).length>3){const t=[...e];let r=e.length-3;for(;r--;){let e=Math.floor(Math.random()*t.length);t.splice(e,1)}e=t}return e}var _e,Ue,He;function Je(){return Je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Je.apply(this,arguments)}const Ke=e=>y.createElement("svg",Je({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),_e||(_e=y.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),Ue||(Ue=y.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),He||(He=y.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"})))),Qe=function(e,t,r){function n(t){return t!==W.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(X.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===W.rightSquareBracket?(e.exit(X.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==W.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):V(n)||n===W.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==W.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},We=function(){const e=this.data();e.micromarkExtensions.push({text:{[W.leftSquareBracket]:{tokenize:Qe}}}),e.fromMarkdownExtensions.push({enter:{cite:function(e){this.enter({type:"cite",data:{hName:"cite",hChildren:[{type:"text",value:""}]}},e)},citeData:function(){this.buffer()}},exit:{cite:function(e){this.exit(e)},citeData:function(){const e=this.resume();this.stack[this.stack.length-1].data.hChildren[0].value=e}}})},Xe=f.Image,Ve={pre:r=>{let{children:n}=r;const i=N(null);return e(tt,{ref:i,children:[t(et,{tooltip:!1,content:()=>{const e=i.current?.getElementsByTagName("code");return e?.[0]?.innerText||""}}),n]})},a:e=>{let{node:r,href:n,...i}=e;const o=n?.startsWith("http")?"_blank":"_self";return t("a",{...i,href:n,target:o})},img:e=>{let{node:r,...n}=e;return t(Xe,{...n})}},Ye=[[U,{singleDollarTextMath:!1}],J,H],Ge=[K,[Q,{detect:!1,ignoreMissing:!0}]],Ze=S((e=>{let{content:r,components:n,cite:i}=e;r=r.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=z((()=>{const e={...Ve,...n};return i&&(e.cite=i),e}),[n,i]),s=z((()=>i?[...Ye,We]:Ye),[i]);return t(rt,{remarkPlugins:s,rehypePlugins:Ge,components:o,children:r})}),B),et=n(b)`
239
+ `;function Oe(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",node:r,error:n,tools:i=[],reasoning:o}=e;return{content:t,reasoning:o,error:n,tools:i,node:r}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}function Be(e){if((e=e.filter((e=>!!e.trim()))).length>3){const t=[...e];let r=e.length-3;for(;r--;){let e=Math.floor(Math.random()*t.length);t.splice(e,1)}e=t}return e}var _e,Ue,He;function Je(){return Je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Je.apply(this,arguments)}const Ke=e=>y.createElement("svg",Je({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),_e||(_e=y.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),Ue||(Ue=y.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),He||(He=y.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"})))),Qe=function(e,t,r){function n(t){return t!==W.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(X.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===W.rightSquareBracket?(e.exit(X.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==W.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):V(n)||n===W.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==W.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},We=function(){const e=this.data();e.micromarkExtensions.push({text:{[W.leftSquareBracket]:{tokenize:Qe}}}),e.fromMarkdownExtensions.push({enter:{cite:function(e){this.enter({type:"cite",data:{hName:"cite",hChildren:[{type:"text",value:""}]}},e)},citeData:function(){this.buffer()}},exit:{cite:function(e){this.exit(e)},citeData:function(){const e=this.resume();this.stack[this.stack.length-1].data.hChildren[0].value=e}}})},Xe=f.Image,Ve={pre:r=>{let{children:n}=r;const i=N(null);return e(tt,{ref:i,children:[t(et,{tooltip:!1,content:()=>{const e=i.current?.getElementsByTagName("code");return e?.[0]?.innerText||""}}),n]})},a:e=>{let{node:r,href:n,...i}=e;const o=n?.startsWith("http")?"_blank":"_self";return t("a",{...i,href:n,target:o})},img:e=>{let{node:r,...n}=e;return t(Xe,{...n})}},Ye=[[U,{singleDollarTextMath:!1}],J,H],Ge=[K,[Q,{detect:!1,ignoreMissing:!0}]],Ze=S((e=>{let{content:r,components:n,cite:i}=e;r=r.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=q((()=>{const e={...Ve,...n};return i&&(e.cite=i),e}),[n,i]),s=q((()=>i?[...Ye,We]:Ye),[i]);return t(rt,{remarkPlugins:s,rehypePlugins:Ge,components:o,children:r})}),B),et=n(b)`
240
240
  position: absolute;
241
241
  right: 10px;
242
242
  top: 1em;
@@ -594,7 +594,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
594
594
  max-height: 100%;
595
595
  max-width: 100%;
596
596
  }
597
- `,lt=S((r=>{let{reasoning:n,loading:i}=r;const[o,s]=j(i);return C((()=>{i||s(!1)}),[i]),t(q,{children:t("div",{className:"mb-2",children:e("div",o||i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(i),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:t("div",{className:"border rounded bg-light p-2",children:t(Ze,{content:n})})})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})}));class ct{#t;#o=[];#s=0;constructor(){this.#t=new O}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const dt=new Map;class ht{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new O}createLoader(e){const t=new Promise((async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}}));return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(dt.set(this,t),t.onpause=async()=>{t.ended?(this.#s++,this.#s<this.#o.length?await this.playAudio(this.#s):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#t.emit("playing",!1),this.#t.emit("speaking",!1),dt.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];dt.forEach(((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)})),this.#o=Array.isArray(e)?e:[e],t||(this.#s=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=dt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function mt(e){let{text:t,loading:r,loader:n}=e;const i=N(),[o,s]=j(!1),[a,l]=j(!1),c=N(r),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new ht(n):new ct,i.current.onSpeaking(s),i.current.onPlaying(l));let o="";"string"==typeof t?o=t:t.current&&(o=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap((e=>e.textContent?[e.textContent]:[]))}(t.current),r&&o.pop()),o&&0!==o.length&&i.current.start(o,e)};return C((()=>{if(c.current&&"string"!=typeof t&&t.current){if(r){const e={childList:!0,subtree:!0},r=new MutationObserver((function(){d(!0)}));return r.observe(t.current,e),d(),()=>{r.disconnect()}}d(!0)}}),[r]),C((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:a,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function ut(r){let{model:n="builtin",voice:i,loading:o,autoplay:s,contentRef:a,avatarRef:l}=r;const{request:c}=ae(),d=z((()=>{if("builtin"!==n)return async e=>(await c({url:"/speech",method:"post",data:{model:n,voice:i,input:e}})).audio}),[n,i]),{playing:h,speaking:m,start:u,stop:p}=mt({loader:d,text:a,loading:s&&o});let g=null;return l.current&&(m&&(g=Y(t(pt,{children:t(I,{size:"sm",variant:"light"})}),l.current)),h&&(g=Y(t(pt,{children:t(gt,{className:"bi bi-volume-down-fill text-light"})}),l.current))),e(nt,{disabled:o&&!h,onClick:()=>{h?p():u()},children:[h?t(gt,{className:"bi bi-volume-down-fill"}):m?t(I,{size:"sm",variant:"primary"}):t(gt,{className:"bi bi-volume-down"}),g]})}const pt=n.div`
597
+ `,lt=S((r=>{let{reasoning:n,loading:i}=r;const[o,s]=j(i);return C((()=>{i||s(!1)}),[i]),t($,{children:t("div",{className:"mb-2",children:e("div",o||i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(i),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:t("div",{className:"border rounded bg-light p-2",children:t(Ze,{content:n})})})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})}));class ct{#t;#o=[];#s=0;constructor(){this.#t=new O}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const dt=new Map;class ht{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new O}createLoader(e){const t=new Promise((async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}}));return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(dt.set(this,t),t.onpause=async()=>{t.ended?(this.#s++,this.#s<this.#o.length?await this.playAudio(this.#s):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#t.emit("playing",!1),this.#t.emit("speaking",!1),dt.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];dt.forEach(((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)})),this.#o=Array.isArray(e)?e:[e],t||(this.#s=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=dt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function mt(e){let{text:t,loading:r,loader:n}=e;const i=N(),[o,s]=j(!1),[a,l]=j(!1),c=N(r),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new ht(n):new ct,i.current.onSpeaking(s),i.current.onPlaying(l));let o="";"string"==typeof t?o=t:t.current&&(o=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap((e=>e.textContent?[e.textContent]:[]))}(t.current),r&&o.pop()),o&&0!==o.length&&i.current.start(o,e)};return C((()=>{if(c.current&&"string"!=typeof t&&t.current){if(r){const e={childList:!0,subtree:!0},r=new MutationObserver((function(){d(!0)}));return r.observe(t.current,e),d(),()=>{r.disconnect()}}d(!0)}}),[r]),C((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:a,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function ut(r){let{model:n="builtin",voice:i,loading:o,autoplay:s,contentRef:a,avatarRef:l}=r;const{request:c}=ae(),d=q((()=>{if("builtin"!==n)return async e=>(await c({url:"/speech",method:"post",data:{model:n,voice:i,input:e}})).audio}),[n,i]),{playing:h,speaking:m,start:u,stop:p}=mt({loader:d,text:a,loading:s&&o});let g=null;return l.current&&(m&&(g=Y(t(pt,{children:t(I,{size:"sm",variant:"light"})}),l.current)),h&&(g=Y(t(pt,{children:t(gt,{className:"bi bi-volume-down-fill text-light"})}),l.current))),e(nt,{disabled:o&&!h,onClick:()=>{h?p():u()},children:[h?t(gt,{className:"bi bi-volume-down-fill"}):m?t(I,{size:"sm",variant:"primary"}):t(gt,{className:"bi bi-volume-down"}),g]})}const pt=n.div`
598
598
  position: absolute;
599
599
  top: 0;
600
600
  left: 0;
@@ -609,7 +609,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
609
609
  &::before {
610
610
  transform: scale(1.4)
611
611
  }
612
- `;function ft(r){let{tool:n}=r;const[i,o]=j(!1),{logLevel:s="none"}=ae();let a=null;n.content&&("string"==typeof n.content?a=t(Ze,{content:n.content}):"image"===n.content.type&&(a=t(st,{src:n.content.image})));const l="response"in n;return e(q,{children:["stats"==s&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&l?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:n.title}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(bt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title}),l&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),a]})}const bt=n.div`
612
+ `;function ft(r){let{tool:n}=r;const[i,o]=j(!1),{logLevel:s="none"}=ae();let a=null;n.content&&("string"==typeof n.content?a=t(Ze,{content:n.content}):"image"===n.content.type&&(a=t(st,{src:n.content.image})));const l="response"in n;return e($,{children:["stats"==s&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&l?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:n.title}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(bt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title}),l&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),a]})}const bt=n.div`
613
613
  white-space: pre-wrap;
614
614
  `;function vt(r){let{node:n}=r;const[i,o]=j(!1),{nodeIconResolver:s}=ae(),a=!("latency"in n),l=a?t(I,{animation:"border",variant:"primary",size:"sm"}):n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"shadow-sm rounded bg-white fs-7",children:[e(yt,{onClick:()=>o((e=>!e)),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[t("i",{className:"bi bi-chevron-down text-muted"}),s?.(n.type),t(wt,{className:"me-2 text-truncate",children:n.title}),t("span",{className:"me-auto"}),!a&&t("span",{className:"text-nowrap text-muted",children:xt(n.latency)}),t("span",{children:l})]}),i&&e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输入"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.input?JSON.stringify(n.input,null,4):"None"})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输出"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.output?JSON.stringify(n.output,null,4):"None"})]})]})]})}const xt=e=>e<1?`${(1e3*e).toFixed(3)} ms`:e>60?`${parseInt(Math.round(e/60).toString())} m ${(e%60).toFixed(3)} s`:`${e.toFixed(3)} s`,yt=n.div`
615
615
  svg {
@@ -617,7 +617,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
617
617
  }
618
618
  `,wt=n.span`
619
619
  display: inline-block;
620
- `;function kt(r){let{nodes:n,loading:i}=r;const[o,s]=j(!1),a=n.some((e=>"error"in e)),l=i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",a?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,r)=>t(vt,{node:e},r)))})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Nt=S((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l}=n;const{query:c,quote:d,files:h=[],chunks:m,annotation:u,loading:p}=i,{user:g,bot:f,logLevel:x="none",messages:y}=ae(),w=z((()=>m?m.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>t.content&&"string"==typeof t.content?e+t.content+"\n":e),"")}),""):""),[m]),k=N(null),E=N(null),j=N(null),C=z((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]);return e(r,{children:[(c||h.length>0)&&e(At,{$reverse:!0,children:[g&&t(St,{children:t("img",{src:g.avatar})}),t(Rt,{}),e(Ft,{ref:k,children:[c&&t(Ze,{content:c}),d&&t(L,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:t(Et,{body:!0,children:d}),children:t(Ct,{children:t(jt,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return v(o)?t(st,{src:`/uploads/${o}`},r):t(zt,{children:t(ee,{name:n,size:i})},r)}))]})]}),m&&e(At,{children:[t(St,{ref:E,children:t("img",{src:f.avatar})}),t(Rt,{}),e(Ft,{children:[(c||h.length>0)&&!1!==o&&e($t,{children:[t(b,{placement:"top",content:w,as:nt,tooltip:!0}),l&&t(ut,{loading:i.loading,avatarRef:E,contentRef:j,...l}),o?.({Component:nt,message:i,content:w,setMessage:s,messages:y})]}),t(qt,{children:["stats","all"].includes(x)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(Mt,{ref:j,$deleted:!!u,children:["all"===x&&C.length>0&&t(kt,{loading:p,nodes:C}),m.length>0&&m.map(((r,n)=>e(q,{children:[r.reasoning&&["stats","all"].includes(x)&&t(lt,{reasoning:r.reasoning,loading:!r.content}),r.content&&t(Ze,{cite:a,content:r.content}),r.tools.map(((e,r)=>t(ft,{tool:e},r))),r.error&&t(Ze,{content:`[${r.error}]`})]},n)))]}),u&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(Ze,{content:u.answer})]}),i.loading&&t(Ke,{})]})]})]})})),Et=n(P)`
620
+ `;function kt(r){let{nodes:n,loading:i}=r;const[o,s]=j(!1),a=n.some((e=>"error"in e)),l=i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",a?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,r)=>t(vt,{node:e},r)))})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Nt=S((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l}=n;const{query:c,quote:d,files:h=[],chunks:m,annotation:u,loading:p}=i,{user:g,bot:f,logLevel:x="none",messages:y}=ae(),w=q((()=>m?m.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>t.content&&"string"==typeof t.content?e+t.content+"\n":e),"")}),""):""),[m]),k=N(null),E=N(null),j=N(null),C=q((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]);return e(r,{children:[(c||h.length>0)&&e(At,{$reverse:!0,children:[g&&t(St,{children:t("img",{src:g.avatar})}),t(Rt,{}),e(Ft,{ref:k,children:[c&&t(Ze,{content:c}),d&&t(L,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:t(Et,{body:!0,children:d}),children:t(Ct,{children:t(jt,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return v(o)?t(st,{src:`/uploads/${o}`},r):t(qt,{children:t(ee,{name:n,size:i})},r)}))]})]}),m&&e(At,{children:[t(St,{ref:E,children:t("img",{src:f.avatar})}),t(Rt,{}),e(Ft,{children:[(c||h.length>0)&&!1!==o&&e(zt,{children:[t(b,{placement:"top",content:w,as:nt,tooltip:!0}),l&&t(ut,{loading:i.loading,avatarRef:E,contentRef:j,...l}),o?.({Component:nt,message:i,content:w,setMessage:s,messages:y})]}),t($t,{children:["stats","all"].includes(x)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(Mt,{ref:j,$deleted:!!u,children:["all"===x&&C.length>0&&t(kt,{loading:p,nodes:C}),m.length>0&&m.map(((r,n)=>e($,{children:[r.reasoning&&["stats","all"].includes(x)&&t(lt,{reasoning:r.reasoning,loading:!r.content}),r.content&&t(Ze,{cite:a,content:r.content}),r.tools.map(((e,r)=>t(ft,{tool:e},r))),r.error&&t(Ze,{content:`[${r.error}]`})]},n)))]}),u&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(Ze,{content:u.answer})]}),i.loading&&t(Ke,{})]})]})]})})),Et=n(P)`
621
621
  max-width: calc(100% - .875rem * 2);
622
622
  width: calc(100% - .875rem * 2);
623
623
  font-size: 1rem;
@@ -644,7 +644,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
644
644
  text-decoration-line: line-through;
645
645
  color: var(--bs-secondary);
646
646
  `}
647
- `,zt=n.div`
647
+ `,qt=n.div`
648
648
  width: 100%;
649
649
  margin-bottom: .5rem;
650
650
  margin-top: .5rem;
@@ -656,7 +656,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
656
656
  &:last-child {
657
657
  margin-bottom: 0;
658
658
  }
659
- `,$t=n.div`
659
+ `,zt=n.div`
660
660
  position: absolute;
661
661
  top: -1.1rem;
662
662
  right: 0;
@@ -664,7 +664,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
664
664
  gap: .5rem;
665
665
  opacity: 0;
666
666
  z-index: 1;
667
- `,qt=n.div`
667
+ `,$t=n.div`
668
668
  position: absolute;
669
669
  bottom: -1.4rem;
670
670
  left: 0;
@@ -703,7 +703,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
703
703
  position: relative;
704
704
 
705
705
  &:hover {
706
- ${qt}, ${$t} {
706
+ ${$t}, ${zt} {
707
707
  opacity: 1;
708
708
  }
709
709
  }
@@ -744,7 +744,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
744
744
  background: var(--bs-secondary-bg-subtle);
745
745
  }
746
746
  }
747
- `,Lt=S(M(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:m,onboarding:u,conversation:p,cite:b,speech:v,renderItem:y,messages:w,request:k}=r;const M=E((e=>{const t=[];if(u&&!1!==u.enable){const e=Be(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(Oe(e.messages||[])):w?t.concat(Oe(w)):t}),[u]),[q,S]=j(p?.id),[R,F]=g([]);C((()=>{F(M(p))}),[u]);const[A,I]=j(!1),D=N(null),[T,L]=j([]),P=E((e=>{A||(S(e?.id),F(M(e)),L([]))}),[A,M]);return $(n,(()=>({reset:P})),[P]),t(le,{request:z((()=>k?"string"==typeof k?x.create({baseURL:k}):k:x),[k]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:q,setConversationId:S,messages:R,setMessages:F,suggestions:T,setSuggestions:L,loading:A,setLoading:I,reset:P,children:t(Ot,{className:i,children:e(f,{children:[t(Pt,{ref:D,children:t(It,{placeholder:h,cite:b,actions:m,loaded:!a,speech:v,renderItem:y,scrollRef:D})}),a&&t(Se,{...a,scrollRef:D})]})})})})),B),Pt=n.div`
747
+ `,Lt=S(M(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:m,onboarding:u,conversation:p,cite:b,speech:v,renderItem:y,messages:w,request:k}=r;const M=E((e=>{const t=[];if(u&&!1!==u.enable){const e=Be(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(Oe(e.messages||[])):w?t.concat(Oe(w)):t}),[u]),[$,S]=j(p?.id),[R,F]=g([]);C((()=>{F(M(p))}),[u]);const[A,I]=j(!1),D=N(null),[T,L]=j([]),P=E((e=>{A||(S(e?.id),F(M(e)),L([]))}),[A,M]);return z(n,(()=>({reset:P})),[P]),t(le,{request:q((()=>k?"string"==typeof k?x.create({baseURL:k}):k:x),[k]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:$,setConversationId:S,messages:R,setMessages:F,suggestions:T,setSuggestions:L,loading:A,setLoading:I,reset:P,children:t(Ot,{className:i,children:e(f,{children:[t(Pt,{ref:D,children:t(It,{placeholder:h,cite:b,actions:m,loaded:!a,speech:v,renderItem:y,scrollRef:D})}),a&&t(Se,{...a,scrollRef:D})]})})})})),B),Pt=n.div`
748
748
  display: flex;
749
749
  flex-direction: column;
750
750
  flex: 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.1.17",
3
+ "version": "1.1.18-alpha.0+a276eae",
4
4
  "scripts": {
5
5
  "prebuild": "rimraf es types",
6
6
  "build": "rollup -c --environment NODE_ENV:production",
@@ -65,5 +65,5 @@
65
65
  },
66
66
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
67
67
  "license": "MIT",
68
- "gitHead": "c4906ef48d106ccac39c60c58a99f6ccbc86c384"
68
+ "gitHead": "a276eaec69a091f6d42a0e5b7d26c231d49d3556"
69
69
  }