@topthink/chat 1.1.36 → 1.1.37

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 +62 -133
  2. package/package.json +3 -3
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as a,useAsync as s,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as u,dayjs as m,RequestButton as p,useImmer as g,getAbsoluteUrl as b,Lightbox as f,Clipboard as v,isImageUrl as x,request as y}from"@topthink/components";import*as k from"react";import{createContext as w,useContext as E,useEffect as $,useState as N,useRef as j,useCallback as C,forwardRef as M,useMemo as F,useImperativeHandle as z,Fragment as q,memo as S}from"react";import R from"react-textarea-autosize";import*as A from"path";import I from"path";import{Spinner as L,Badge as D,CloseButton as P,OverlayTrigger as O,Popover as T}from"react-bootstrap";import B from"eventemitter3";import _ from"lodash/isEqual";import{toString as U}from"hast-util-to-string";import H from"react-markdown";import"katex/dist/katex.min.css";import J from"rehype-highlight";import K from"rehype-katex";import Q from"remark-breaks";import W from"remark-gfm";import X from"remark-math";import{codes as V,types as Y}from"micromark-util-symbol";import{markdownLineEnding as G}from"micromark-util-character";import{createPortal as Z}from"react-dom";import ee from"use-resize-observer";const re=function(e){let{ext:t}=e;const{result:n}=s((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(r,t){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(t.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`../../images/file/${e}.svg`)).default),[t]);return n?r("img",{width:30,height:30,src:n}):null};function te(t){let{className:n,name:i,size:s,loading:l,error:c,onRemove:d}=t;const h=I.extname(i).substring(1),u=e(ae,{className:n,$error:!!c,children:[e(oe,{children:[r(re,{ext:h}),l&&r(L,{variant:"primary"})]}),e(ie,{children:[r("h4",{children:i}),r("p",{children:o(s,1)})]}),d&&r(ne,{onClick:e=>{e.preventDefault(),d()},children:r("i",{className:"bi bi-trash3"})})]});return c?r(a,{placement:"top",tooltip:c,children:u}):u}const ne=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 u,dayjs as m,RequestButton as p,useImmer as g,getAbsoluteUrl as f,Lightbox as b,Clipboard as v,isImageUrl as x,request as y}from"@topthink/components";import*as k from"react";import{createContext as w,useContext as N,useEffect as E,useState as j,useRef as $,useCallback as C,forwardRef as M,useMemo as q,useImperativeHandle as z,Fragment as S,memo as F}from"react";import R from"react-textarea-autosize";import*as A from"path";import I from"path";import{Spinner as D,Badge as L,CloseButton as P,OverlayTrigger as T,Popover as O}from"react-bootstrap";import B from"eventemitter3";import _ from"lodash/isEqual";import{toString as U}from"hast-util-to-string";import H from"react-markdown";import"katex/dist/katex.min.css";import J from"rehype-highlight";import K from"rehype-katex";import Q from"remark-breaks";import W from"remark-gfm";import X from"remark-math";import{codes as V,types as Y}from"micromark-util-symbol";import{markdownLineEnding as G}from"micromark-util-character";import{createPortal as Z}from"react-dom";import ee from"use-resize-observer";const te=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 re(r){let{className:n,name:i,size:a,loading:l,error:c,onRemove:d}=r;const h=I.extname(i).substring(1),u=e(se,{className:n,$error:!!c,children:[e(oe,{children:[t(te,{ext:h}),l&&t(D,{variant:"primary"})]}),e(ie,{children:[t("h4",{children:i}),t("p",{children:o(a,1)})]}),d&&t(ne,{onClick:e=>{e.preventDefault(),d()},children:t("i",{className:"bi bi-trash3"})})]});return c?t(s,{placement:"top",tooltip:c,children:u}):u}const ne=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -48,7 +48,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
48
48
  position: absolute;
49
49
  }
50
50
 
51
- `,ae=n.div`
51
+ `,se=n.div`
52
52
  display: flex;
53
53
  gap: .5rem;
54
54
  padding: .5rem;
@@ -64,7 +64,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
64
64
  ${e=>e.$error&&i`
65
65
  border-color: var(--bs-danger) !important;
66
66
  `}
67
- `,se=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],le=w(null);function ce(e){const r=E(le);if(!r)throw new Error("useContext must be used within a Provider");const{setHandles:t}=r;return $((()=>{if(e)return t(e),()=>{t({})}}),[e]),r}function de(e){let{children:t,...n}=e;const[i,o]=N({});return r(le.Provider,{value:{...n,handles:i,setHandles:o},children:t})}function he(){const{setMessages:e,setSuggestions:r,setLoading:t,conversationId:n,setConversationId:i,request:o,handles:a}=ce(),s=j(null),c=j(!1),d=j(n);$((()=>{d.current=n}),[n]);const{onSuccess:h,onComplete:u}=a,m=C((r=>{if(r.data)if("[DONE]"!=r.data)try{const t=JSON.parse(r.data);t.conversation?(d.current=t.conversation,i(t.conversation)):e((e=>{const r=e[e.length-1];if(t.chunks){if(r.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){r.chunks[e].tools||(r.chunks[e].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 if(t.chunks.reasoning)r.chunks[e].reasoning+=t.chunks.reasoning;else if(t.chunks.content)if("object"==typeof t.chunks.content){Array.isArray(r.chunks[e].content)||(r.chunks[e].content=[]);const n=t.chunks.content.index,i=t.chunks.content.value;"string"==typeof i?(r.chunks[e].content[n]||(r.chunks[e].content[n]=""),r.chunks[e].content[n]+=i):r.chunks[e].content[n]=i}else r.chunks[e].content+=t.chunks.content;else 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:t.suspend&&(c.current=!0)}))}catch(e){console.error(e)}else e((e=>{e[e.length-1].loading=!1}))}),[]),p=C((r=>{let t="未知错误";l(r)&&(t=401==r.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof r.errors?r.errors:Object.values(r.errors).join("\n")),e((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{error:t}]:r.chunks[r.chunks.length-1].error=t),r.loading=!1}))}),[]),g=C((async function(n){if("string"==typeof n){for(var i=arguments.length,a=new Array(i>1?i-1:0),l=1;l<i;l++)a[l-1]=arguments[l];n={query:n,...a}}const{query:g,files:b=[],variables:f={},quote:v}=n;if(g||b.length>0){s.current&&s.current.abort(),c.current=!1,t(!0),r([]),e((e=>{e.push({query:g,quote:v,files:b,variables:f,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:b,variables:f,conversation:d.current},onMessage:m};await o(e),c.current||h?.()}catch(e){p(e)}t(!1),u?.()}}),[o,a]);return{send:g,resume:C((async r=>{try{s.current&&s.current.abort(),c.current=!1,t(!0),e((e=>{e[e.length-1].loading=!0}));let n={url:"resume",method:"post",data:{conversation:d.current,chunk:r.chunk,payload:r.payload},onMessage:m};await o(n),c.current||h?.()}catch(e){p(e)}t(!1),u?.()}),[o,a]),suggest:C((async()=>{s.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:d.current},signal:s.current.signal};const t=await o(e);r(t)}catch{}finally{s.current=null}}),[o])}}function ue(e){let{variables:t,values:n,onSubmit:i,onChange:o,children:a}=e;const s={},l=[],d={};return t.forEach((e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?d[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&l.push(e.key)})),r(c,{schema:{type:"object",properties:s,required:l},formData:n,omitExtraData:!0,uiSchema:d,submitText:"开始对话",onSubmit:i,onChange:o,children:a})}const me=n.button`
67
+ `,ae=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],le=w(null);function ce(e){const t=N(le);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return E((()=>{if(e)return r(e),()=>{r({})}}),[e]),t}function de(e){let{children:r,...n}=e;const[i,o]=j({});return t(le.Provider,{value:{...n,handles:i,setHandles:o},children:r})}function he(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s}=ce(),a=$(null),c=$(!1),d=$(n);E((()=>{d.current=n}),[n]);const{onSuccess:h,onComplete:u}=s,m=C((t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(d.current=r.conversation,i(r.conversation)):r.suspend?c.current=!0:e((e=>{const t=e[e.length-1];if(r.chunks){if(t.chunks){const e=r.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)t.chunks[e].error=r.chunks.error;else if(r.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const n=r.chunks.tools.index;"response"in r.chunks.tools?(t.chunks[e].tools[n].response=r.chunks.tools.response,t.chunks[e].tools[n].error=r.chunks.tools.error,t.chunks[e].tools[n].content=r.chunks.tools.content):t.chunks[e].tools[n]={name:r.chunks.tools.name,title:r.chunks.tools.title,arguments:r.chunks.tools.arguments}}else if(r.chunks.reasoning)t.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const n=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(t.chunks[e].content[n]||(t.chunks[e].content[n]=""),t.chunks[e].content[n]+=i):t.chunks[e].content[n]=i}else t.chunks[e].content+=r.chunks.content;else r.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...r.chunks.node})}}else r.stats?t.stats=r.stats:r.id&&(t.id=r.id)}))}catch(e){console.error(e)}else e((e=>{e[e.length-1].loading=!1}))}),[]),p=C((t=>{let r="未知错误";l(t)&&(r=401==t.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof t.errors?t.errors:Object.values(t.errors).join("\n")),e((e=>{const t=e[e.length-1];t.chunks&&(0===t.chunks.length?t.chunks=[{error:r}]:t.chunks[t.chunks.length-1].error=r),t.loading=!1}))}),[]),g=C((async function(n){if("string"==typeof n){for(var i=arguments.length,s=new Array(i>1?i-1:0),l=1;l<i;l++)s[l-1]=arguments[l];n={query:n,...s}}const{query:g,files:f=[],variables:b={},quote:v}=n;if(g||f.length>0){a.current&&a.current.abort(),c.current=!1,r(!0),t([]),e((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:d.current},onMessage:m};await o(e),c.current||h?.()}catch(e){p(e)}r(!1),u?.()}}),[o,s]);return{send:g,resume:C((async t=>{try{a.current&&a.current.abort(),c.current=!1,r(!0),e((e=>{e[e.length-1].loading=!0}));let n={url:"resume",method:"post",data:{conversation:d.current,chunk:t.chunk,payload:t.payload},onMessage:m};await o(n),c.current||h?.()}catch(e){p(e)}r(!1),u?.()}),[o,s]),suggest:C((async()=>{a.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:d.current},signal:a.current.signal};const r=await o(e);t(r)}catch{}finally{a.current=null}}),[o])}}function ue(e){let{variables:r,values:n,onSubmit:i,onChange:o,children:s}=e;const a={},l=[],d={};return r.forEach((e=>{a[e.key]={type:"string",title:e.label},"textarea"===e.type?d[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(a[e.key].enum=e.options,a[e.key].enumNames=e.options,e.options.length>0&&(a[e.key].default=e.options[0])),e.required&&l.push(e.key)})),t(c,{schema:{type:"object",properties:a,required:l},formData:n,omitExtraData:!0,uiSchema:d,submitText:"开始对话",onSubmit:i,onChange:o,children:s})}const me=n.button`
68
68
  color: var(--bs-secondary);
69
69
  cursor: pointer;
70
70
  display: flex;
@@ -87,12 +87,12 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
87
87
  background-color: var(--bs-gray-200);
88
88
  }
89
89
 
90
- `;let pe=class{#e;#r;constructor(){this.#r=new B}onResult(e){this.#r.on("result",e)}onRecording(e){this.#r.on("recording",e)}onTranscribing(e){this.#r.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const r=new e;r.continuous=!0,r.lang=navigator.language,r.onresult=e=>{const r=Array.from(e.results).at(-1)?.item(0).transcript;r&&this.#r.emit("result",r)},r.onspeechend=()=>{this.#r.emit("recording",!1)},r.onerror=e=>{this.#r.emit("recording",!1),d.error(e.error)},this.#e=r}this.#r.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#r.emit("recording",!1)}},ge=class{#r;#t;#n;#i;constructor(e){this.#t=e,this.#r=new B}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 r=[],t=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,a=e.inputBuffer.getChannelData(0);let s=!0;for(let e=0;e<a.length;e++)if(Math.abs(a[e])>n){s=!1;break}if(s){const e=o-t;e>i&&(r.length>1&&(this.save(r),r=[]),e>10&&this.stop())}else r.push(new Float32Array(a)),t=o},this.#r.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const r=new Float32Array(e),t=new Int16Array(e.length);for(let e=0;e<r.length;e++){const n=Math.max(-1,Math.min(1,r[e]));t[e]=n<0?32768*n:32767*n}return t}async encodeMP3(e){const{Mp3Encoder:r}=await import("@breezystack/lamejs"),t=new r(1,44100,128),n=[];for(const r of e){const e=this.convertBuffer(r),i=1152;let o=e.length;for(let r=0;o>=0;r+=i){const a=e.subarray(r,r+i),s=t.encodeBuffer(a);n.push(new Int8Array(s)),o-=i}}return n.push(t.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const r=await this.encodeMP3(e);try{this.#r.emit("transcribing",!0);const e=await this.#t(r);e&&this.#r.emit("result",e)}catch(e){}finally{this.#r.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.#r.emit("recording",!1)}onResult(e){this.#r.on("result",e)}onRecording(e){this.#r.on("recording",e)}onTranscribing(e){this.#r.on("transcribing",e)}};const be=M(((t,n)=>{let{onResult:i,model:o="builtin"}=t;const{request:s}=ce(),l=F((()=>{if("builtin"!==o)return async e=>{const r=new FormData;r.append("file",e,"audio.mp3"),r.append("model",o);return(await s({url:"/transcriptions",method:"post",data:r})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:u}=function(e){let{onResult:r,loader:t}=e;const n=j(),[i,o]=N(!1),[a,s]=N(!1);return $((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:a,start:async()=>{n.current||(n.current=t?new ge(t):new pe,n.current.onRecording(o),n.current.onTranscribing(s),n.current.onResult(r)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:l});return z(n,(()=>({start:c,stop:d})),[c,d]),r(a,{tooltip:h?"停止":"语音输入",placement:"top",children:e(me,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&r(fe,{animation:"border",variant:"primary",size:"sm"}),r("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),fe=n(L)`
90
+ `;let pe=class{#e;#t;constructor(){this.#t=new B}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)}},ge=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new B}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 fe=M(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=ce(),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:u}=function(e){let{onResult:t,loader:r}=e;const n=$(),[i,o]=j(!1),[s,a]=j(!1);return E((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:s,start:async()=>{n.current||(n.current=r?new ge(r):new pe,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(me,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&t(be,{animation:"border",variant:"primary",size:"sm"}),t("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),be=n(D)`
91
91
  position: absolute;
92
92
  --bs-spinner-width: .75rem;
93
93
  --bs-spinner-height: .75rem;
94
94
  --bs-spinner-border-width: 0.1em;
95
- `,ve=M(((e,t)=>{let{className:n,children:i,size:o,tooltip:s,placement:l,onClick:c,onMouseDown:d}=e;const h=r(xe,{ref:t,className:n,onClick:c,onMouseDown:d,$size:o,children:i});return s?r(a,{tooltip:s,placement:l,children:h}):h})),xe=n.div`
95
+ `,ve=M(((e,r)=>{let{className:n,children:i,size:o,tooltip:a,placement:l,onClick:c,onMouseDown:d}=e;const h=t(xe,{ref:r,className:n,onClick:c,onMouseDown:d,$size:o,children:i});return a?t(s,{tooltip:a,placement:l,children:h}):h})),xe=n.div`
96
96
  width: 2rem;
97
97
  height: 2rem;
98
98
  align-items: center;
@@ -107,7 +107,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
107
107
  font-size: 1.5rem;
108
108
  }
109
109
 
110
- ${e=>{let{$size:r}=e;return"sm"===r&&i`
110
+ ${e=>{let{$size:t}=e;return"sm"===t&&i`
111
111
  width: 1.5rem;
112
112
  height: 1.5rem;
113
113
  font-size: 1rem;
@@ -116,7 +116,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
116
116
  &:hover {
117
117
  background-color: var(--bs-secondary-bg-subtle);
118
118
  }
119
- `;function ye(){const{request:n,reset:i,conversationId:o}=ce(),[s,l]=N(!1);return e(t,{children:[r(ve,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:r("i",{className:"bi bi-clock-history"})}),r(u,{show:s,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:ke,children:s&&r(je,{children:r(Ne,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:t=>{let{data:s,loading:c,setData:d}=t;return s.length||c?s.map(((t,s)=>{const c=t.messages?.reduce(((e,r)=>e+r.chunks.reduce(((e,r)=>e+(r.content||"")),"")),"");return e(q,{children:[s>0&&r("hr",{className:"mx-2 my-2"}),e($e,{onClick:()=>{i(t),l(!1)},children:[e(Ee,{children:[o===t.id&&r(D,{bg:"secondary",children:"当前"}),r("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:t.title||"未命名对话"}),r("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:m(t.update_time).fromNow()})]}),e(we,{children:[r("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),r("span",{className:"ms-3",children:o!==t.id&&r(a,{tooltip:"删除",children:r(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${t.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const r=e.findIndex((e=>e.id===t.id));-1!==r&&e.splice(r,1)}))},children:r("i",{className:"bi bi-trash3"})})})})]})]})]},t.id)})):r("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const ke=n.div`
119
+ `;function ye(){const{request:n,reset:i,conversationId:o}=ce(),[a,l]=j(!1);return e(r,{children:[t(ve,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:t("i",{className:"bi bi-clock-history"})}),t(u,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:ke,children:a&&t($e,{children:t(je,{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(S,{children:[a>0&&t("hr",{className:"mx-2 my-2"}),e(Ee,{onClick:()=>{i(r),l(!1)},children:[e(Ne,{children:[o===r.id&&t(L,{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:m(r.update_time).fromNow()})]}),e(we,{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 ke=n.div`
120
120
  padding: 0;
121
121
  overflow: hidden;
122
122
  `,we=n.div`
@@ -129,11 +129,11 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
129
129
  & :last-child {
130
130
  display: none;
131
131
  }
132
- `,Ee=n.div`
132
+ `,Ne=n.div`
133
133
  display: flex;
134
134
  align-items: center;
135
135
  gap: .25rem;
136
- `,$e=n.div`
136
+ `,Ee=n.div`
137
137
  gap: .5rem;
138
138
  display: flex;
139
139
  flex-direction: column;
@@ -151,14 +151,14 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
151
151
  }
152
152
  }
153
153
  }
154
- `,Ne=n(h)`
154
+ `,je=n(h)`
155
155
  display: flex;
156
156
  flex-direction: column;
157
157
  padding: .5rem;
158
- `,je=n.div`
158
+ `,$e=n.div`
159
159
  height: 100%;
160
160
  overflow-y: auto;
161
- `;var Ce;function Me(){return Me=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},Me.apply(this,arguments)}const Fe=e=>k.createElement("svg",Me({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ce||(Ce=k.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 ze(){const{reset:e}=ce();return r(ve,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:r(Fe,{})})}function qe(t){let{children:n}=t;return e(Re,{children:[n,e(Se,{children:[r(ye,{}),r(ze,{})]})]})}const Se=n.div`
161
+ `;var Ce;function Me(){return Me=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},Me.apply(this,arguments)}const qe=e=>k.createElement("svg",Me({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ce||(Ce=k.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 ze(){const{reset:e}=ce();return t(ve,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(qe,{})})}function Se(r){let{children:n}=r;return e(Re,{children:[n,e(Fe,{children:[t(ye,{}),t(ze,{})]})]})}const Fe=n.div`
162
162
  display: flex;
163
163
  gap: .25rem;
164
164
  margin-left: auto;
@@ -166,14 +166,14 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
166
166
  margin-bottom: .5rem;
167
167
  display: flex;
168
168
  padding: 0 .125rem;
169
- `;var Ae=M((function(t,n){let{suggestion:i,fileTypes:o,speech:s,scrollRef:c,variables:h,minRows:u,toolbar:m,disabled:p,autoFocus:b,placeholder:f="请输入你的问题, Enter+Shift换行, Enter发送"}=t;const v=j(null),x=j(null),y=j(null),[k,w]=N(""),[E,M]=N(""),[q,S]=g([]),[I,L]=N(!1),D=o&&o.length>0?o:se,{send:O,resume:T,suggest:B}=he(),_=F((()=>({onSuccess(){i&&B()},onComplete(){requestAnimationFrame((()=>{v.current?.focus()}))}})),[i]),{messages:U,loading:H,request:J}=ce(_),[K,Q]=N();$((()=>{const e=U.filter((e=>!!e.query));Q(e.at(-1)?.variables)}),[U]),$((()=>{!o&&q.length>0&&S([])}),[o]),$((()=>{const e=c.current;if(e&&O){const r=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const r={query:e.target.text};h&&(r.variables={...K,...h.values}),O(r)}};return e.addEventListener("click",r),()=>{e.removeEventListener("click",r)}}}),[h,K]);const W=C((e=>{let{target:r}=e;if(r.files){const e=Array.from(r.files).filter((e=>!!D.includes(A.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-q.length);S((r=>{r.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const r=new FormData;r.set("file",e);const t=await J({method:"POST",url:"/upload",data:r});S((r=>{const n=r.find((r=>r.file===e));n&&(n.path=t.path)}))}catch(r){const t=l(r)?r.message:"unknown error";S((r=>{const n=r.find((r=>r.file===e));n&&(n.error=t)}))}}))}r.value=""}),[q,D]),X=q.flatMap((e=>{let{file:r,path:t}=e;return t?[{name:r.name,size:r.size,path:t}]:[]})),V=C((()=>{if(k||X.length>0){const e={query:k,files:X};h&&(e.variables={...K,...h.values}),E&&(e.quote=E),O(e),w(""),M(""),S([]),y.current?.stop(!0)}}),[k,X,h,K,E]);if(z(n,(()=>({setQuery:w,setQuote:M,send:O,resume:T,focus(){v.current?.focus()}}))),h){const e=h.config.filter((e=>!(e.key in(h.values||{})))),t=function(r){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!r&&e.every((e=>{const n=!e.required||r?.[e.key];return!n&&t&&d.error("请完善必填信息"),n}))};if(e.length>0&&!t(K))return r(Le,{children:r(Ie,{children:r(ue,{values:K,variables:e,onSubmit:e=>{let{formData:r}=e;if(t(r,!0))return Q(r),!0}})})})}return e(_e,{children:[m&&r(qe,{children:m}),e(Be,{$focused:I&&!H,children:[q.length>0&&r(Pe,{children:q.map(((e,t)=>{let{file:n,error:i,path:o}=e;const a=void 0===i&&void 0===o;return r(De,{name:n.name,size:n.size,error:i,loading:a,onRemove:()=>{S((e=>{const r=e.findIndex((e=>e.file===n));-1!==r&&e.splice(r,1)}))}},t)}))}),!!E&&e(Te,{children:[r("i",{className:"bi bi-quote"}),r("p",{children:E}),r(P,{onClick:()=>M("")})]}),e(Oe,{children:[r(R,{disabled:H||p,ref:v,placeholder:f,minRows:u,maxRows:5,value:k,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),V())},autoFocus:b,onFocus:()=>L(!0),onBlur:()=>L(!1)}),o&&r(a,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(me,{disabled:q.length>=6,onClick:()=>x.current?.click(),children:[r("input",{onChange:W,multiple:!0,accept:D.join(","),ref:x,type:"file",hidden:!0}),r("i",{className:"bi bi-file-earmark-arrow-up"})]})}),s&&r(be,{ref:y,model:s.model,onResult:e=>{v.current?.focus(),w((r=>r+e+" "))}}),r(me,{className:"text-primary",disabled:!k&&0===X.length,onClick:e=>{e.preventDefault(),V()},children:r("i",{className:"bi bi-send-fill"})})]})]})]})}));const Ie=n.div`
169
+ `;var Ae=M((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:c,variables:h,minRows:u,toolbar:m,disabled:p,autoFocus:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const v=$(null),x=$(null),y=$(null),[k,w]=j(""),[N,M]=j(""),[S,F]=g([]),[I,D]=j(!1),L=o&&o.length>0?o:ae,{send:T,resume:O,suggest:B}=he(),_=q((()=>({onSuccess(){i&&B()},onComplete(){requestAnimationFrame((()=>{v.current?.focus()}))}})),[i]),{messages:U,loading:H,request:J}=ce(_),[K,Q]=j();E((()=>{const e=U.filter((e=>!!e.query));Q(e.at(-1)?.variables)}),[U]),E((()=>{!o&&S.length>0&&F([])}),[o]),E((()=>{const e=c.current;if(e&&T){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};h&&(t.variables={...K,...h.values}),T(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[h,K]);const W=C((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!L.includes(A.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-S.length);F((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await J({method:"POST",url:"/upload",data:t});F((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=l(t)?t.message:"unknown error";F((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[S,L]),X=S.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),V=C((()=>{if(k||X.length>0){const e={query:k,files:X};h&&(e.variables={...K,...h.values}),N&&(e.quote=N),T(e),w(""),M(""),F([]),y.current?.stop(!0)}}),[k,X,h,K,N]);if(z(n,(()=>({setQuery:w,setQuote:M,send:T,resume:O,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(K))return t(De,{children:t(Ie,{children:t(ue,{values:K,variables:e,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return Q(t),!0}})})})}return e(_e,{children:[m&&t(Se,{children:m}),e(Be,{$focused:I&&!H,children:[S.length>0&&t(Pe,{children:S.map(((e,r)=>{let{file:n,error:i,path:o}=e;const s=void 0===i&&void 0===o;return t(Le,{name:n.name,size:n.size,error:i,loading:s,onRemove:()=>{F((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!N&&e(Oe,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:N}),t(P,{onClick:()=>M("")})]}),e(Te,{children:[t(R,{disabled:H||p,ref:v,placeholder:b,minRows:u,maxRows:5,value:k,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),V())},autoFocus:f,onFocus:()=>D(!0),onBlur:()=>D(!1)}),o&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(me,{disabled:S.length>=6,onClick:()=>x.current?.click(),children:[t("input",{onChange:W,multiple:!0,accept:L.join(","),ref:x,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&t(fe,{ref:y,model:a.model,onResult:e=>{v.current?.focus(),w((t=>t+e+" "))}}),t(me,{className:"text-primary",disabled:!k&&0===X.length,onClick:e=>{e.preventDefault(),V()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})}));const Ie=n.div`
170
170
  border-radius: var(--bs-border-radius-lg);
171
171
  box-shadow: var(--bs-box-shadow-sm);
172
172
  margin: 1rem;
173
173
  padding: 1rem;
174
174
  width: 100%;
175
175
  max-width: 500px;
176
- `,Le=n.div`
176
+ `,De=n.div`
177
177
  position: absolute;
178
178
  left: 0;
179
179
  right: 0;
@@ -183,7 +183,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
183
183
  display: flex;
184
184
  justify-content: center;
185
185
  align-items: center;
186
- `,De=n(te)`
186
+ `,Le=n(re)`
187
187
  width: calc((100% - .75rem) / 2);
188
188
  `,Pe=n.div`
189
189
  display: flex;
@@ -191,7 +191,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
191
191
  padding: .75rem;
192
192
  gap: .75rem;
193
193
  border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
194
- `,Oe=n.div`
194
+ `,Te=n.div`
195
195
  display: flex;
196
196
  padding: .5rem .5rem .5rem 1rem;
197
197
  gap: .25rem;
@@ -208,7 +208,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
208
208
  color: rgba(54, 54, 54, .3);
209
209
  }
210
210
  }
211
- `,Te=n.div`
211
+ `,Oe=n.div`
212
212
  margin: .75rem .75rem 0 .75rem;
213
213
  padding: 4px 8px;
214
214
  display: flex;
@@ -236,7 +236,7 @@ import{jsxs as e,jsx as r,Fragment as t}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
  `,_e=n.div`
238
238
  margin: 0 1rem 1rem;
239
- `;function Ue(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:r="",node:t,error:n,tools:i=[],reasoning:o}=e;return{content:r,reasoning:o,error:n,tools:i,node:t}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}function He(e){if((e=e.filter((e=>!!e.trim()))).length>3){const r=[...e];let t=e.length-3;for(;t--;){let e=Math.floor(Math.random()*r.length);r.splice(e,1)}e=r}return e}var Je,Ke,Qe;function We(){return We=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},We.apply(this,arguments)}const Xe=e=>k.createElement("svg",We({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),Je||(Je=k.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),Ke||(Ke=k.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),Qe||(Qe=k.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function Ve(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${b(e.image)})`}return""}const Ye=function(e,r,t){function n(r){return r!==V.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(Y.chunkString,{contentType:"string"}),i(r)):(e.consume(r),n)}function i(n){return n===V.rightSquareBracket?(e.exit(Y.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==V.rightSquareBracket)return t(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),r(n)}(n)):G(n)||n===V.eof||n>57||n<48?t(n):(e.consume(n),i)}return function(r){return r!==V.leftSquareBracket?t(r):(e.enter("cite"),e.enter("citeMarker"),n(r))}},Ge=function(){const e=this.data();e.micromarkExtensions.push({text:{[V.leftSquareBracket]:{tokenize:Ye}}}),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}}})},Ze=f.Image,er={pre:t=>{let{children:n,node:i}=t;const[o,a]=N(!1),s=F((()=>{const e=i.children[0];return"element"===(r=e).type&&"code"===r.tagName&&!!e.properties?.className?.includes("language-svg");var r}),[i]);$((()=>{s&&a(s)}),[s]);const l=F((()=>U(i)),[i]);return e(ar,{children:[e(or,{children:[!o&&r(v,{tooltip:!1,as:ir,content:l}),s&&o&&r(ir,{onClick:()=>{const e=new Blob([l],{type:"image/svg+xml"}),r=URL.createObjectURL(e),t=document.createElement("a");t.href=r,t.download="image.svg",t.click(),URL.revokeObjectURL(r)},children:"下载"}),s&&r(ir,{onClick:()=>a(!o),children:o?"源码":"预览"})]}),s&&o?r("div",{dangerouslySetInnerHTML:{__html:l}}):r("pre",{children:n})]})},a:e=>{let{node:t,href:n,...i}=e;const o=n?.startsWith("http")?"_blank":"_self";return r("a",{...i,href:n,target:o})},img:e=>{let{node:t,...n}=e;return r(Ze,{...n})}},rr=[[X,{singleDollarTextMath:!1}],W,Q],tr=[K,[J,{detect:!1,ignoreMissing:!0}]],nr=S((e=>{let{content:t,components:n,cite:i}=e;t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=F((()=>{const e={...er,...n};return i&&(e.cite=i),e}),[n,i]),a=F((()=>i?[...rr,Ge]:rr),[i]);return r(sr,{remarkPlugins:a,rehypePlugins:tr,components:o,children:t})}),_),ir=n.div`
239
+ `;function Ue(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 He(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 Je,Ke,Qe;function We(){return We=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},We.apply(this,arguments)}const Xe=e=>k.createElement("svg",We({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),Je||(Je=k.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),Ke||(Ke=k.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),Qe||(Qe=k.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},k.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),k.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function Ve(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${f(e.image)})`}return""}const Ye=function(e,t,r){function n(t){return t!==V.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(Y.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===V.rightSquareBracket?(e.exit(Y.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==V.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):G(n)||n===V.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==V.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},Ge=function(){const e=this.data();e.micromarkExtensions.push({text:{[V.leftSquareBracket]:{tokenize:Ye}}}),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}}})},Ze=b.Image,et={pre:r=>{let{children:n,node:i}=r;const[o,s]=j(!1),a=q((()=>{const e=i.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t}),[i]);E((()=>{a&&s(a)}),[a]);const l=q((()=>U(i)),[i]);return e(st,{children:[e(ot,{children:[!o&&t(v,{tooltip:!1,as:it,content:l}),a&&o&&t(it,{onClick:()=>{const e=new Blob([l],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="image.svg",r.click(),URL.revokeObjectURL(t)},children:"下载"}),a&&t(it,{onClick:()=>s(!o),children:o?"源码":"预览"})]}),a&&o?t("div",{dangerouslySetInnerHTML:{__html:l}}):t("pre",{children: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(Ze,{...n})}},tt=[[X,{singleDollarTextMath:!1}],W,Q],rt=[K,[J,{detect:!1,ignoreMissing:!0}]],nt=F((e=>{let{content:r,components:n,cite:i}=e;r=r.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=q((()=>{const e={...et,...n};return i&&(e.cite=i),e}),[n,i]),s=q((()=>i?[...tt,Ge]:tt),[i]);return t(at,{remarkPlugins:s,rehypePlugins:rt,components:o,children:r})}),_),it=n.div`
240
240
  cursor: pointer;
241
241
  padding: 2px 10px;
242
242
  background-color: #303030;
@@ -246,7 +246,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
246
246
  font-size: 12px;
247
247
  font-family: initial;
248
248
  user-select: none;
249
- `,or=n.div`
249
+ `,ot=n.div`
250
250
  position: absolute;
251
251
  right: 10px;
252
252
  top: 1em;
@@ -260,17 +260,17 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
260
260
  &:hover {
261
261
  opacity: 1;
262
262
  }
263
- `,ar=n.div`
263
+ `,st=n.div`
264
264
  position: relative;
265
265
 
266
266
  &:hover {
267
- ${or} {
267
+ ${ot} {
268
268
  pointer-events: all;
269
269
  transform: translateX(0px);
270
270
  opacity: 0.7;
271
271
  }
272
272
  }
273
- `,sr=n(H)`
273
+ `,at=n(H)`
274
274
  -ms-text-size-adjust: 100%;
275
275
  -webkit-text-size-adjust: 100%;
276
276
  line-height: 1.8;
@@ -540,7 +540,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
540
540
  .hljs-strong {
541
541
  font-weight: 700;
542
542
  }
543
- `;var lr=M((function(e,t){let{children:n,tooltip:i,onClick:o,disabled:s,...l}=e;s&&(o=void 0);const c=r(cr,{ref:t,onClick:o,$disabled:s,...l,children:n});return i?r(a,{tooltip:i,placement:"top",children:c}):c}));const cr=n.div`
543
+ `;var lt=M((function(e,r){let{children:n,tooltip:i,onClick:o,disabled:a,...l}=e;a&&(o=void 0);const c=t(ct,{ref:r,onClick:o,$disabled:a,...l,children:n});return i?t(s,{tooltip:i,placement:"top",children:c}):c}));const ct=n.div`
544
544
  align-items: center;
545
545
  justify-content: center;
546
546
  border-radius: .375rem;
@@ -573,7 +573,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
573
573
  `}
574
574
 
575
575
  }
576
- `,dr=w(null);var hr=dr.Provider;const ur=f.Image;function mr(e){let{src:t,...n}=e;const{imageResolver:i}=ce();return i&&t&&(t=i(t)),r(pr,{children:r(ur,{src:t,...n})})}const pr=n.div`
576
+ `,dt=w(null);var ht=dt.Provider;const ut=b.Image;function mt(e){let{src:r,...n}=e;const{imageResolver:i}=ce();return i&&r&&(r=i(r)),t(pt,{children:t(ut,{src:r,...n})})}const pt=n.div`
577
577
  margin-bottom: .5rem;
578
578
  margin-top: .5rem;
579
579
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -598,11 +598,11 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
598
598
  max-height: 100%;
599
599
  max-width: 100%;
600
600
  }
601
- `,gr=w(null);function br(){const e=E(gr);if(!e)throw new Error("useContext must be used within a Provider");return e}function fr(e){let{children:t,...n}=e;return r(gr.Provider,{value:n,children:t})}function vr(t){let{description:n,options:i}=t;const{resume:o,disabled:a,output:s}=br(),[l,c]=N(s?.result),d=a||void 0!==l;return e(xr,{children:[n&&r(yr,{children:n}),i.map(((e,t)=>r(kr,{$selected:l===e,$disabled:d,onClick:()=>(e=>{d||(c(e),o(e))})(e),children:e},t)))]})}const xr=n.div`
601
+ `,gt=w(null);function ft(){const e=N(gt);if(!e)throw new Error("useContext must be used within a Provider");return e}function bt(e){let{children:r,...n}=e;return t(gt.Provider,{value:n,children:r})}function vt(r){let{description:n,options:i}=r;const{resume:o,disabled:s,output:a}=ft(),[l,c]=j(a?.result),d=s||void 0!==l;return e(xt,{children:[n&&t(yt,{children:n}),i.map(((e,r)=>t(kt,{$selected:l===e,$disabled:d,onClick:()=>(e=>{d||(c(e),o(e))})(e),children:e},r)))]})}const xt=n.div`
602
602
  display: flex;
603
603
  flex-direction: column;
604
- gap: 0.25rem;
605
- margin: 0.5rem 0;
604
+ gap: 0.5rem;
605
+ margin: 1rem 0;
606
606
 
607
607
  &:first-child {
608
608
  margin-top: 0;
@@ -611,15 +611,14 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
611
611
  &:last-child {
612
612
  margin-bottom: 0;
613
613
  }
614
- `,yr=n.div`
614
+ `,yt=n.div`
615
615
  color: var(--bs-secondary);
616
- font-size: 0.9rem;
617
616
  line-height: 1.5;
618
- `,kr=n.div`
619
- padding: 0.25rem .75rem;
617
+ `,kt=n.div`
618
+ padding: 0.375rem 0.75rem;
620
619
  background-color: ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.1)":"#FFFFFF"};
621
620
  border: 1px solid ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.3)":"var(--bs-border-color)"};
622
- border-radius: var(--bs-border-radius-lg);
621
+ border-radius: var(--bs-border-radius);
623
622
  cursor: ${e=>e.$disabled?"not-allowed":"pointer"};
624
623
  transition: all 0.2s ease;
625
624
  color: ${e=>e.$selected?"var(--bs-primary)":"inherit"};
@@ -634,11 +633,15 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
634
633
  &:active {
635
634
  transform: ${e=>e.$disabled?"none":"scale(0.98)"};
636
635
  }
637
- `;function wr(t){let{description:n,fields:i}=t;const{resume:o,disabled:a,output:s}=br(),[l,c]=N(s||{}),[d,h]=N({}),u=void 0!==s,m=a||u,p=(e,r)=>{m||(c((t=>({...t,[e]:r}))),d[e]&&h((r=>{const t={...r};return delete t[e],t})))};return e(Er,{children:[n&&r($r,{children:n}),r(Nr,{children:i.map((t=>{const n=l[t.name]||"",i=d[t.name];return e(jr,{children:[e(Cr,{children:[t.label,t.required&&r(Mr,{children:"*"})]}),"textarea"===t.type?r(qr,{value:n,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder,disabled:m,$hasError:!!i}):"select"===t.type?e(Sr,{value:n,onChange:e=>p(t.name,e.target.value),disabled:m,$hasError:!!i,children:[r("option",{value:"",children:t.placeholder||"请选择"}),t.options?.map(((e,t)=>r("option",{value:e,children:e},t)))]}):r(zr,{type:t.type,value:n,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder,disabled:m,$hasError:!!i}),i&&r(Rr,{children:i})]},t.name)}))}),r(Ar,{onClick:()=>{if(!m&&(()=>{const e={};for(const r of i){const t=l[r.name];if(!r.required||t&&""!==t.toString().trim()){if(t&&t.toString().trim())switch(r.type){case"email":/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)||(e[r.name]="请输入有效的邮箱地址");break;case"tel":/^[0-9\-\+\(\)\s]+$/.test(t)||(e[r.name]="请输入有效的电话号码");break;case"number":isNaN(Number(t))&&(e[r.name]="请输入有效的数字")}}else e[r.name]=`${r.label}为必填项`}return h(e),0===Object.keys(e).length})()){const e={...l};for(const r of i)"number"===r.type&&e[r.name]&&(e[r.name]=Number(e[r.name]));c(e),o(e)}},disabled:m,$submitted:u,children:u?"已提交":"提交"})]})}const Er=n.div`
636
+ `;function wt(r){let{description:n,fields:i}=r;const{resume:o,disabled:s,output:a}=ft(),[l,d]=j(void 0!==a),h=s||l,{schema:u,uiSchema:m}=q((()=>{const e={},t=[],r={};for(const n of i)e[n.name]={type:"number"===n.type?"number":"string",title:n.label},n.placeholder&&(r[n.name]={"ui:placeholder":n.placeholder}),"textarea"===n.type?r[n.name]={...r[n.name],"ui:widget":"textarea"}:"select"===n.type&&n.options?(e[n.name].enum=n.options,e[n.name].enumNames=n.options):"email"===n.type?e[n.name].format="email":"date"===n.type?e[n.name].format="date":"tel"===n.type&&(r[n.name]={...r[n.name],"ui:options":{inputType:"tel"}}),n.required&&t.push(n.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}}),[i]);return e(Nt,{children:[n&&t(Et,{children:n}),t(c,{schema:u,uiSchema:m,formData:a,onSubmit:e=>{let{formData:t}=e;h||(d(!0),o(t))},disabled:h,validate:!0,showErrorList:!1,submitText:l?"已提交":"提交",omitExtraData:!0})]})}const Nt=n.div`
638
637
  display: flex;
639
638
  flex-direction: column;
640
639
  gap: 0.5rem;
641
- margin: 0.5rem 0;
640
+ margin: 1rem 0;
641
+
642
+ .g-3 {
643
+ --bs-gutter-y: .5rem !important;
644
+ }
642
645
 
643
646
  &:first-child {
644
647
  margin-top: 0;
@@ -647,84 +650,10 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
647
650
  &:last-child {
648
651
  margin-bottom: 0;
649
652
  }
650
- `,$r=n.div`
653
+ `,Et=n.div`
651
654
  color: var(--bs-secondary);
652
- font-size: 0.9rem;
653
655
  line-height: 1.5;
654
- `,Nr=n.div`
655
- display: flex;
656
- flex-direction: column;
657
- gap: 0.5rem;
658
- `,jr=n.div`
659
- display: flex;
660
- flex-direction: column;
661
- gap: 0.375rem;
662
- `,Cr=n.label`
663
- font-size: 0.875rem;
664
- font-weight: 500;
665
- color: var(--bs-body-color);
666
- display: flex;
667
- align-items: center;
668
- gap: 0.25rem;
669
- `,Mr=n.span`
670
- color: var(--bs-danger);
671
- `,Fr="\n padding: 0.5rem 0.75rem;\n border: 1px solid var(--bs-border-color);\n border-radius: var(--bs-border-radius);\n font-size: 0.875rem;\n color: var(--bs-body-color);\n background-color: #FFFFFF;\n transition: all 0.2s ease;\n outline: none;\n\n &::placeholder {\n color: var(--bs-secondary);\n opacity: 0.6;\n }\n\n &:focus {\n border-color: var(--bs-primary);\n box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.15);\n }\n\n &:disabled {\n background-color: var(--bs-secondary-bg);\n opacity: 0.65;\n cursor: not-allowed;\n }\n",zr=n.input`
672
- ${Fr};
673
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-border-color)"};
674
-
675
- &:focus {
676
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-primary)"};
677
- box-shadow: 0 0 0 0.2rem ${e=>e.$hasError?"rgba(var(--bs-danger-rgb), 0.15)":"rgba(var(--bs-primary-rgb), 0.15)"};
678
- }
679
- `,qr=n.textarea`
680
- ${Fr};
681
- min-height: 5rem;
682
- resize: vertical;
683
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-border-color)"};
684
-
685
- &:focus {
686
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-primary)"};
687
- box-shadow: 0 0 0 0.2rem ${e=>e.$hasError?"rgba(var(--bs-danger-rgb), 0.15)":"rgba(var(--bs-primary-rgb), 0.15)"};
688
- }
689
- `,Sr=n.select`
690
- ${Fr};
691
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-border-color)"};
692
- cursor: pointer;
693
-
694
- &:focus {
695
- border-color: ${e=>e.$hasError?"var(--bs-danger)":"var(--bs-primary)"};
696
- box-shadow: 0 0 0 0.2rem ${e=>e.$hasError?"rgba(var(--bs-danger-rgb), 0.15)":"rgba(var(--bs-primary-rgb), 0.15)"};
697
- }
698
-
699
- &:disabled {
700
- cursor: not-allowed;
701
- }
702
- `,Rr=n.div`
703
- font-size: 0.75rem;
704
- color: var(--bs-danger);
705
- margin-top: -0.125rem;
706
- `,Ar=n.button`
707
- padding: 0.5rem 1rem;
708
- background-color: ${e=>e.$submitted?"rgba(var(--bs-success-rgb), 0.1)":"var(--bs-primary)"};
709
- color: ${e=>e.$submitted?"var(--bs-success)":"#FFFFFF"};
710
- border: 1px solid ${e=>e.$submitted?"rgba(var(--bs-success-rgb), 0.3)":"var(--bs-primary)"};
711
- border-radius: var(--bs-border-radius-lg);
712
- font-size: 0.875rem;
713
- font-weight: 500;
714
- cursor: ${e=>e.disabled?"not-allowed":"pointer"};
715
- transition: all 0.2s ease;
716
- opacity: ${e=>e.disabled&&!e.$submitted?.65:1};
717
-
718
- &:hover {
719
- background-color: ${e=>e.disabled?e.$submitted?"rgba(var(--bs-success-rgb), 0.1)":"var(--bs-primary)":e.$submitted?"rgba(var(--bs-success-rgb), 0.15)":"var(--bs-primary-hover, var(--bs-primary))"};
720
- border-color: ${e=>e.disabled?e.$submitted?"rgba(var(--bs-success-rgb), 0.3)":"var(--bs-primary)":e.$submitted?"rgba(var(--bs-success-rgb), 0.4)":"var(--bs-primary-hover, var(--bs-primary))"};
721
- filter: ${e=>e.disabled?"none":"brightness(0.95)"};
722
- }
723
-
724
- &:active {
725
- transform: ${e=>e.disabled?"none":"scale(0.98)"};
726
- }
727
- `;function Ir(e){let{suspend:t}=e;const{readonly:n}=ce(),{index:i,chunk:o,isLastMessage:a}=function(){const e=E(dr);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:s}=he(),l=C((e=>{s({chunk:i,payload:e})}),[]);let c=null;switch(t.type){case"select":c=r(vr,{...t.select});break;case"form":c=r(wr,{...t.form})}return r(fr,{resume:l,disabled:n||!!o.error||!a,output:o.node?.output,children:c})}function Lr(e){let{value:n,cite:i}=e;const o=e=>"string"==typeof e?r(nr,{content:e,cite:i}):"image"===e.type?r(mr,{src:e.image}):"suspend"===e.type?r(Ir,{suspend:e.suspend}):null;return Array.isArray(n)?r(t,{children:n.map(((e,t)=>r(q,{children:o(e)},t)))}):o(n)}const Dr=S((t=>{let{reasoning:n,loading:i}=t;const[o,a]=N(i);return $((()=>{i||a(!1)}),[i]),r(q,{children:r("div",{className:"mb-2",children:e("div",o||i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>a(i),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[i?r(L,{animation:"border",variant:"primary",size:"sm"}):r("i",{className:"bi bi-check-circle-fill text-success"}),r("span",{className:"text-muted",children:i?"思考中":"已思考"}),r("i",{className:"bi bi-caret-up-fill text-muted"})]}),r("div",{className:"border-top p-2 d-flex flex-column gap-2",children:r("div",{className:"border rounded bg-light p-2",children:r(nr,{content:n})})})]}:{onClick:()=>a(!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?r(L,{animation:"border",variant:"primary",size:"sm"}):r("i",{className:"bi bi-check-circle-fill text-success"}),r("span",{className:"text-muted",children:i?"思考中":"已思考"}),r("i",{className:"bi bi-caret-down-fill text-muted"})]})})})}));class Pr{#r;#o=[];#a=0;constructor(){this.#r=new B}speak(){for(this.#r.emit("playing",!0);this.#a<this.#o.length;){const e=this.#o[this.#a],r=new SpeechSynthesisUtterance(e),t=++this.#a;r.onend=()=>{t>=this.#o.length&&this.clear()},r.onerror=()=>{this.clear()},window.speechSynthesis.speak(r)}}clear(){this.#r.emit("playing",!1)}start(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#o=Array.isArray(e)?e:[e],r||(window.speechSynthesis.cancel(),this.#a=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#r.on("playing",e)}onSpeaking(e){this.#r.on("speaking",e)}}const Or=new Map;class Tr{#t;#r;#o=[];#s=new Map;#l=!1;#a=0;#c=!1;constructor(e){this.#t=e,this.#r=new B}createLoader(e){const r=new Promise((async r=>{try{const{type:t,data:n}=await this.#t(e),i=new Audio(`data:${t};base64,${n}`);this.#s.set(e,i),r(i)}catch{this.#s.delete(e),r(void 0)}}));return this.#s.set(e,r),r}async loadAudioData(){this.#c=!0,this.#r.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const r=this.#o[e];!this.#s.has(r)&&this.#c&&await this.createLoader(r),e++}this.#r.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const r=this.#s.get(e);return r instanceof Promise?r:Promise.resolve(r)}async playAudio(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.#l=!0;const r=await this.waitForAudioLoaded(this.#o[e]);this.#r.emit("playing",!0),r?(Or.set(this,r),r.onpause=async()=>{r.ended?(this.#a++,this.#a<this.#o.length?await this.playAudio(this.#a):this.clear()):this.clear()},await r.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#r.emit("playing",!1),this.#r.emit("speaking",!1),Or.delete(this)}start(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];Or.forEach(((e,r)=>{r!==this&&(e.pause(),e.currentTime=0)})),this.#o=Array.isArray(e)?e:[e],r||(this.#a=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=Or.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#r.on("playing",e)}onSpeaking(e){this.#r.on("speaking",e)}}function Br(e){let{text:r,loading:t,loader:n}=e;const i=j(),[o,a]=N(!1),[s,l]=N(!1),c=j(t),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new Tr(n):new Pr,i.current.onSpeaking(a),i.current.onPlaying(l));let o="";"string"==typeof r?o=r:r.current&&(o=function(e){const r=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(r).flatMap((e=>e.textContent?[e.textContent]:[]))}(r.current),t&&o.pop()),o&&0!==o.length&&i.current.start(o,e)};return $((()=>{if(c.current&&"string"!=typeof r&&r.current){if(t){const e={childList:!0,subtree:!0},t=new MutationObserver((function(){d(!0)}));return t.observe(r.current,e),d(),()=>{t.disconnect()}}d(!0)}}),[t]),$((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:s,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function _r(t){let{model:n="builtin",voice:i,loading:o,autoplay:a,contentRef:s,avatarRef:l}=t;const{request:c}=ce(),d=F((()=>{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:u,start:m,stop:p}=Br({loader:d,text:s,loading:a&&o});let g=null;return l.current&&(u&&(g=Z(r(Ur,{children:r(L,{size:"sm",variant:"light"})}),l.current)),h&&(g=Z(r(Ur,{children:r(Hr,{className:"bi bi-volume-down-fill text-light"})}),l.current))),e(lr,{disabled:o&&!h,onClick:()=>{h?p():m()},children:[h?r(Hr,{className:"bi bi-volume-down-fill"}):u?r(L,{size:"sm",variant:"primary"}):r(Hr,{className:"bi bi-volume-down"}),g]})}const Ur=n.div`
656
+ `;function jt(e){let{suspend:r}=e;const{readonly:n}=ce(),{index:i,chunk:o,isLastMessage:s}=function(){const e=N(dt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:a}=he(),l=C((e=>{a({chunk:i,payload:e})}),[]);let c=null;switch(r.type){case"select":c=t(vt,{...r.select});break;case"form":c=t(wt,{...r.form})}return t(bt,{resume:l,disabled:n||!!o.error||!s,output:o.node?.output,children:c})}function $t(e){let{value:n,cite:i}=e;const o=e=>"string"==typeof e?t(nt,{content:e,cite:i}):"image"===e.type?t(mt,{src:e.image}):"suspend"===e.type?t(jt,{suspend:e.suspend}):null;return Array.isArray(n)?t(r,{children:n.map(((e,r)=>t(S,{children:o(e)},r)))}):o(n)}const Ct=F((r=>{let{reasoning:n,loading:i}=r;const[o,s]=j(i);return E((()=>{i||s(!1)}),[i]),t(S,{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(D,{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(nt,{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(D,{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 Mt{#t;#o=[];#s=0;constructor(){this.#t=new B}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 qt=new Map;class zt{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new B}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?(qt.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),qt.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];qt.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=qt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function St(e){let{text:t,loading:r,loader:n}=e;const i=$(),[o,s]=j(!1),[a,l]=j(!1),c=$(r),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new zt(n):new Mt,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 E((()=>{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]),E((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:a,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function Ft(r){let{model:n="builtin",voice:i,loading:o,autoplay:s,contentRef:a,avatarRef:l}=r;const{request:c}=ce(),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:u,start:m,stop:p}=St({loader:d,text:a,loading:s&&o});let g=null;return l.current&&(u&&(g=Z(t(Rt,{children:t(D,{size:"sm",variant:"light"})}),l.current)),h&&(g=Z(t(Rt,{children:t(At,{className:"bi bi-volume-down-fill text-light"})}),l.current))),e(lt,{disabled:o&&!h,onClick:()=>{h?p():m()},children:[h?t(At,{className:"bi bi-volume-down-fill"}):u?t(D,{size:"sm",variant:"primary"}):t(At,{className:"bi bi-volume-down"}),g]})}const Rt=n.div`
728
657
  position: absolute;
729
658
  top: 0;
730
659
  left: 0;
@@ -734,20 +663,20 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
734
663
  align-items: center;
735
664
  justify-content: center;
736
665
  background-color: rgba(0, 0, 0, .3);
737
- `,Hr=n.i`
666
+ `,At=n.i`
738
667
 
739
668
  &::before {
740
669
  transform: scale(1.4)
741
670
  }
742
- `;function Jr(t){let{tool:n,loading:i}=t;const[o,a]=N(!1),{logLevel:s="none"}=ce(),l="response"in n,c=!l&&!i;return e(q,{children:["stats"==s&&r("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:[c?r("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?r("i",{className:"bi bi-x-circle-fill text-danger"}):r("i",{className:"bi bi-check-circle-fill text-success"}):r(L,{animation:"border",variant:"primary",size:"sm"}),r("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),r("span",{children:n.title})]})}),"all"==s&&r("div",{className:"mb-2",children:e("div",o&&l?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>a(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n.error?r("i",{className:"bi bi-x-circle-fill text-danger"}):r("i",{className:"bi bi-check-circle-fill text-success"}),r("span",{className:"text-muted",children:"已使用"}),r("span",{children:n.title}),r("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:[r("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:r("span",{className:"text-muted",children:"参数"})}),r("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[r("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:r("span",{className:"text-muted",children:"响应"})}),r(Kr,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>a(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[c?r("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?r("i",{className:"bi bi-x-circle-fill text-danger"}):r("i",{className:"bi bi-check-circle-fill text-success"}):r(L,{animation:"border",variant:"primary",size:"sm"}),r("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),r("span",{children:n.title}),l&&r("i",{className:"bi bi-caret-down-fill text-muted"})]})}),n.content&&r(Lr,{value:n.content})]})}const Kr=n.div`
671
+ `;function It(r){let{tool:n,loading:i}=r;const[o,s]=j(!1),{logLevel:a="none"}=ce(),l="response"in n,c=!l&&!i;return e(S,{children:["stats"==a&&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:[c?t("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==a&&t("div",{className:"mb-2",children:e("div",o&&l?{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:[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(Dt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>s(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[c?t("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),t("span",{children:n.title}),l&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),n.content&&t($t,{value:n.content})]})}const Dt=n.div`
743
672
  white-space: pre-wrap;
744
- `;function Qr(t){let{node:n}=t;const[i,o]=N(!1),{nodeIconResolver:a}=ce(),s=!("latency"in n),l=s?r(L,{animation:"border",variant:"primary",size:"sm"}):n.error?r("i",{className:"bi bi-x-circle-fill text-danger"}):r("i",{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"shadow-sm rounded bg-white fs-7",children:[e(Xr,{onClick:()=>o((e=>!e)),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[r("i",{className:"bi bi-chevron-down text-muted"}),a?.(n.type),r(Vr,{className:"me-2 text-truncate",children:n.title}),r("span",{className:"me-auto"}),!s&&r("span",{className:"text-nowrap text-muted",children:Wr(n.latency)}),r("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:[r("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:r("span",{className:"text-muted",children:"输入"})}),r("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:[r("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:r("span",{className:"text-muted",children:"输出"})}),r("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.output?JSON.stringify(n.output,null,4):"None"})]})]})]})}const Wr=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`,Xr=n.div`
673
+ `;function Lt(r){let{node:n}=r;const[i,o]=j(!1),{nodeIconResolver:s}=ce(),a=!("latency"in n),l=a?t(D,{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(Tt,{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(Ot,{className:"me-2 text-truncate",children:n.title}),t("span",{className:"me-auto"}),!a&&t("span",{className:"text-nowrap text-muted",children:Pt(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 Pt=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`,Tt=n.div`
745
674
  svg {
746
675
  flex-shrink: 0;
747
676
  }
748
- `,Vr=n.span`
677
+ `,Ot=n.span`
749
678
  display: inline-block;
750
- `;function Yr(t){let{nodes:n,loading:i}=t;const[o,a]=N(!1),s=n.some((e=>"error"in e)),l=i?r(L,{animation:"border",variant:"primary",size:"sm"}):r("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return r("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>a(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,r("span",{children:"工作流"}),r("i",{className:"bi bi-caret-up-fill text-muted"})]}),r("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,t)=>r(Qr,{node:e},t)))})]}:{onClick:()=>a(!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,r("span",{children:"工作流"}),r("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Gr=S((n=>{let{message:i,actions:o,setMessage:a,cite:s,speech:l,isLast:c}=n;const{query:d,quote:h,files:u=[],chunks:m,annotation:p,loading:g}=i,{user:b,bot:f,logLevel:y="none",messages:k}=ce(),w=F((()=>m?m.reduce((function(e,r){const t=Array.isArray(r.content)?r.content.reduce(((e,r)=>{const t=Ve(r);return t?e+t+"\n":e}),""):Ve(r.content);return e+t+"\n"+(r.tools||[]).reduce(((e,r)=>{if(r.content){const t=Ve(r.content);if(t)return e+t+"\n"}return e}),"")}),""):""),[m]),E=j(null),$=j(null),N=j(null),C=F((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]),M=d||u.length>0;return e(t,{children:[M&&e(ct,{$reverse:!0,children:[b&&r(at,{children:r("img",{src:b.avatar})}),r(st,{}),e(lt,{ref:E,children:[d&&r(nr,{content:d}),h&&r(O,{trigger:"click",container:E,rootClose:!0,placement:"bottom",overlay:r(Zr,{body:!0,children:h}),children:r(rt,{children:r(et,{children:h})})}),u.length>0&&u.map(((e,t)=>{let{name:n,size:i,path:o}=e;return x(o)?r(mr,{src:`/uploads/${o}`},t):r(nt,{children:r(te,{name:n,size:i})},t)}))]})]}),m&&e(ct,{children:[f&&r(at,{ref:$,children:r("img",{src:f.avatar})}),r(st,{}),e(lt,{children:[M&&!1!==o&&e(it,{children:[r(v,{placement:"top",content:w,as:lr,tooltip:!0}),l&&r(_r,{loading:i.loading,avatarRef:$,contentRef:N,...l}),o?.({Component:lr,message:i,content:w,setMessage:a,messages:k})]}),r(ot,{children:["stats","all"].includes(y)&&i.stats&&e(t,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(tt,{ref:N,$deleted:!!p,children:["all"===y&&C.length>0&&r(Yr,{loading:g,nodes:C}),m.map(((t,n)=>e(hr,{value:{index:n,chunk:t,isLastMessage:c},children:[t.reasoning&&["stats","all"].includes(y)&&r(Dr,{reasoning:t.reasoning,loading:!t.content&&0===(t.tools||[]).length}),t.content&&r(Lr,{cite:s,value:t.content}),(t.tools||[]).map(((e,t)=>r(Jr,{tool:e,loading:g},t))),t.error&&r(nr,{content:`[${t.error}]`})]},n)))]}),p&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[r("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),r("hr",{className:"flex-fill"})]}),r(nr,{content:p.answer})]}),i.loading&&r(Xe,{})]})]})]})})),Zr=n(T)`
679
+ `;function Bt(r){let{nodes:n,loading:i}=r;const[o,s]=j(!1),a=n.some((e=>"error"in e)),l=i?t(D,{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(Lt,{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 _t=F((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l,isLast:c}=n;const{query:d,quote:h,files:u=[],chunks:m,annotation:p,loading:g}=i,{user:f,bot:b,logLevel:y="none",messages:k}=ce(),w=q((()=>m?m.reduce((function(e,t){const r=Array.isArray(t.content)?t.content.reduce(((e,t)=>{const r=Ve(t);return r?e+r+"\n":e}),""):Ve(t.content);return e+r+"\n"+(t.tools||[]).reduce(((e,t)=>{if(t.content){const r=Ve(t.content);if(r)return e+r+"\n"}return e}),"")}),""):""),[m]),N=$(null),E=$(null),j=$(null),C=q((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]),M=d||u.length>0;return e(r,{children:[M&&e(Zt,{$reverse:!0,children:[f&&t(Vt,{children:t("img",{src:f.avatar})}),t(Yt,{}),e(Gt,{ref:N,children:[d&&t(nt,{content:d}),h&&t(T,{trigger:"click",container:N,rootClose:!0,placement:"bottom",overlay:t(Ut,{body:!0,children:h}),children:t(Jt,{children:t(Ht,{children:h})})}),u.length>0&&u.map(((e,r)=>{let{name:n,size:i,path:o}=e;return x(o)?t(mt,{src:`/uploads/${o}`},r):t(Qt,{children:t(re,{name:n,size:i})},r)}))]})]}),m&&e(Zt,{children:[b&&t(Vt,{ref:E,children:t("img",{src:b.avatar})}),t(Yt,{}),e(Gt,{children:[M&&!1!==o&&e(Wt,{children:[t(v,{placement:"top",content:w,as:lt,tooltip:!0}),l&&t(Ft,{loading:i.loading,avatarRef:E,contentRef:j,...l}),o?.({Component:lt,message:i,content:w,setMessage:s,messages:k})]}),t(Xt,{children:["stats","all"].includes(y)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(Kt,{ref:j,$deleted:!!p,children:["all"===y&&C.length>0&&t(Bt,{loading:g,nodes:C}),m.map(((r,n)=>e(ht,{value:{index:n,chunk:r,isLastMessage:c},children:[r.reasoning&&["stats","all"].includes(y)&&t(Ct,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&t($t,{cite:a,value:r.content}),(r.tools||[]).map(((e,r)=>t(It,{tool:e,loading:g},r))),r.error&&t(nt,{content:`[${r.error}]`})]},n)))]}),p&&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(nt,{content:p.answer})]}),i.loading&&t(Xe,{})]})]})]})})),Ut=n(O)`
751
680
  max-width: calc(100% - .875rem * 2);
752
681
  width: calc(100% - .875rem * 2);
753
682
  font-size: 1rem;
@@ -756,25 +685,25 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
756
685
  .popover-body {
757
686
  padding: .5rem .75rem;
758
687
  }
759
- `,et=n.div`
688
+ `,Ht=n.div`
760
689
  overflow: hidden;
761
690
  text-overflow: ellipsis;
762
691
  word-break: break-all;
763
692
  -webkit-line-clamp: 2;
764
693
  -webkit-box-orient: vertical;
765
694
  display: -webkit-box;
766
- `,rt=n.div`
695
+ `,Jt=n.div`
767
696
  padding: .5rem .75rem;
768
697
  color: var(--bs-secondary);
769
698
  border-radius: var(--bs-border-radius-lg);
770
699
  background: #FFFFFF;
771
700
  cursor: pointer;
772
- `,tt=n.div`
701
+ `,Kt=n.div`
773
702
  ${e=>e.$deleted&&i`
774
703
  text-decoration-line: line-through;
775
704
  color: var(--bs-secondary);
776
705
  `}
777
- `,nt=n.div`
706
+ `,Qt=n.div`
778
707
  width: 100%;
779
708
  margin-bottom: .5rem;
780
709
  margin-top: .5rem;
@@ -786,7 +715,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
786
715
  &:last-child {
787
716
  margin-bottom: 0;
788
717
  }
789
- `,it=n.div`
718
+ `,Wt=n.div`
790
719
  position: absolute;
791
720
  top: -1.1rem;
792
721
  right: 0;
@@ -794,7 +723,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
794
723
  gap: .5rem;
795
724
  opacity: 0;
796
725
  z-index: 1;
797
- `,ot=n.div`
726
+ `,Xt=n.div`
798
727
  position: absolute;
799
728
  bottom: -1.4rem;
800
729
  left: 0;
@@ -807,7 +736,7 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
807
736
  display: flex;
808
737
  opacity: 0;
809
738
  z-index: 1;
810
- `,at=n.div`
739
+ `,Vt=n.div`
811
740
  width: 35px;
812
741
  height: 35px;
813
742
  border-radius: 50%;
@@ -818,14 +747,14 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
818
747
  width: 100%;
819
748
  height: 100%;
820
749
  }
821
- `,st=n.div`
750
+ `,Yt=n.div`
822
751
  width: 0;
823
752
  height: 0;
824
753
  content: "";
825
754
  border: 5px solid transparent;
826
755
  border-right-color: #f3f3f3;
827
756
  transform: translateY(10px);
828
- `,lt=n.div`
757
+ `,Gt=n.div`
829
758
  padding: .875rem;
830
759
  background-color: rgb(243, 243, 243);
831
760
  border-radius: var(--bs-border-radius-lg);
@@ -833,31 +762,31 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
833
762
  position: relative;
834
763
 
835
764
  &:hover {
836
- ${ot}, ${it} {
765
+ ${Xt}, ${Wt} {
837
766
  opacity: 1;
838
767
  }
839
768
  }
840
- `,ct=n.div`
769
+ `,Zt=n.div`
841
770
  display: flex;
842
771
  justify-content: flex-start;
843
772
  padding: 1rem 0 1rem 0;
844
773
  ${e=>e.$reverse&&i`
845
774
  flex-direction: row-reverse;
846
775
 
847
- ${st} {
776
+ ${Yt} {
848
777
  border-left-color: rgba(var(--bs-primary-rgb), 0.1);
849
778
  border-right-color: transparent;
850
779
  }
851
780
 
852
- ${lt} {
781
+ ${Gt} {
853
782
  background: rgba(var(--bs-primary-rgb), 0.1);
854
783
  }
855
784
  `};
856
- `;function dt(t){const{placeholder:n,actions:i,cite:o,speech:a,renderItem:s,scrollRef:l}=t,{messages:c,setMessages:d,loading:h,suggestions:u,conversationId:m}=ce(),p=j(t.loaded),g=C((()=>{const e=l.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),b=j(null),{height:f}=ee({ref:b});$((()=>{(h||!p.current)&&c.length>0&&(h&&(p.current=!0),g())}),[f,h,p,c]),$((()=>{u.length>0&&g()}),[u]),$((()=>{p.current=t.loaded}),[m]),$((()=>{const e=b.current;if(e){const r=()=>{p.current=!0};return e.addEventListener("click",r),()=>{e.removeEventListener("click",r)}}}),[b]);const v=c.slice(-30);return e(ht,{ref:b,children:[0===v.length&&n,v.map(((e,t)=>{const n={actions:i,cite:o,speech:a,message:e,setMessage:r=>{d((t=>{const n=t.findIndex((r=>r.id===e.id));-1!==n&&r(t[n])}))},isLast:t===v.length-1};return s?s({Component:Gr,props:n},t):r(Gr,{...n},t)})),u.length>0&&r(ut,{children:u.map(((e,t)=>r("a",{href:"#!question",children:e},t)))})]})}const ht=n.div`
785
+ `;function er(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:h,suggestions:u,conversationId:m}=ce(),p=$(r.loaded),g=C((()=>{const e=l.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),f=$(null),{height:b}=ee({ref:f});E((()=>{(h||!p.current)&&c.length>0&&(h&&(p.current=!0),g())}),[b,h,p,c]),E((()=>{u.length>0&&g()}),[u]),E((()=>{p.current=r.loaded}),[m]),E((()=>{const e=f.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[f]);const v=c.slice(-30);return e(tr,{ref:f,children:[0===v.length&&n,v.map(((e,r)=>{const n={actions:i,cite:o,speech:s,message:e,setMessage:t=>{d((r=>{const n=r.findIndex((t=>t.id===e.id));-1!==n&&t(r[n])}))},isLast:r===v.length-1};return a?a({Component:_t,props:n},r):t(_t,{...n},r)})),u.length>0&&t(rr,{children:u.map(((e,r)=>t("a",{href:"#!question",children:e},r)))})]})}const tr=n.div`
857
786
  display: flex;
858
787
  flex-direction: column;
859
788
  flex: 1;
860
- `,ut=n.div`
789
+ `,rr=n.div`
861
790
  display: flex;
862
791
  flex-direction: column;
863
792
  align-items: flex-start;
@@ -874,16 +803,16 @@ import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{styled as
874
803
  background: var(--bs-secondary-bg-subtle);
875
804
  }
876
805
  }
877
- `,mt=S(M(((t,n)=>{let{className:i,bot:o,user:a,input:s,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:u,onboarding:m,conversation:p,cite:b,speech:v,renderItem:x,messages:k,request:w,transformMessages:E=Ue}=t;const M=C((e=>{const r=[];if(m&&!1!==m.enable){const e=He(m.questions||[]);r.push({chunks:[{content:[m.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:m.loading})}return e?r.concat(E(e.messages||[])):k?r.concat(E(k)):r}),[m]),[q,S]=N(p?.id),[R,A]=g([]);$((()=>{A(M(p))}),[m]);const[I,L]=N(!1),D=j(null),[P,O]=N([]),T=C((e=>{I||(S(e?.id),A(M(e)),O([]))}),[I,M]);return z(n,(()=>({reset:T})),[T]),r(de,{request:F((()=>w?"string"==typeof w?y.create({baseURL:w}):w:y),[w]),bot:o,user:a,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:q,setConversationId:S,messages:R,setMessages:A,suggestions:P,setSuggestions:O,loading:I,setLoading:L,reset:T,readonly:!s,children:r(gt,{className:i,children:e(f,{children:[r(pt,{ref:D,children:r(dt,{placeholder:h,cite:b,actions:u,loaded:!s,speech:v,renderItem:x,scrollRef:D})}),s&&r(Ae,{...s,scrollRef:D})]})})})})),_),pt=n.div`
806
+ `,nr=F(M(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:u,onboarding:m,conversation:p,cite:f,speech:v,renderItem:x,messages:k,request:w,transformMessages:N=Ue}=r;const M=C((e=>{const t=[];if(m&&!1!==m.enable){const e=He(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(N(e.messages||[])):k?t.concat(N(k)):t}),[m]),[S,F]=j(p?.id),[R,A]=g([]);E((()=>{A(M(p))}),[m]);const[I,D]=j(!1),L=$(null),[P,T]=j([]),O=C((e=>{I||(F(e?.id),A(M(e)),T([]))}),[I,M]);return z(n,(()=>({reset:O})),[O]),t(de,{request:q((()=>w?"string"==typeof w?y.create({baseURL:w}):w:y),[w]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:S,setConversationId:F,messages:R,setMessages:A,suggestions:P,setSuggestions:T,loading:I,setLoading:D,reset:O,readonly:!a,children:t(or,{className:i,children:e(b,{children:[t(ir,{ref:L,children:t(er,{placeholder:h,cite:f,actions:u,loaded:!a,speech:v,renderItem:x,scrollRef:L})}),a&&t(Ae,{...a,scrollRef:L})]})})})})),_),ir=n.div`
878
807
  display: flex;
879
808
  flex-direction: column;
880
809
  flex: 1;
881
810
  overflow-y: auto;
882
811
  padding: 0 1rem;
883
812
  margin-bottom: .5rem;
884
- `,gt=n.div`
813
+ `,or=n.div`
885
814
  display: flex;
886
815
  flex-direction: column;
887
816
  height: 100%;
888
817
  position: relative;
889
- `;export{ve as ActionButton,nr as Markdown,mt as MessageBox,ue as VariableForm,He as pickQuestions,Br as useSynthesis};
818
+ `;export{ve as ActionButton,nt as Markdown,nr as MessageBox,ue as VariableForm,He as pickQuestions,St as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.1.36",
3
+ "version": "1.1.37",
4
4
  "scripts": {
5
5
  "prebuild": "rimraf es types",
6
6
  "build": "rollup -c --environment NODE_ENV:production",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.11.2",
20
20
  "@breezystack/lamejs": "^1.2.7",
21
- "@topthink/components": "^1.1.22",
21
+ "@topthink/components": "^1.1.23",
22
22
  "@types/hast": "^2.0.0",
23
23
  "@types/mdast": "^4.0.4",
24
24
  "eventemitter3": "^5.0.1",
@@ -67,5 +67,5 @@
67
67
  },
68
68
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
69
69
  "license": "MIT",
70
- "gitHead": "8c15e5e12e16b56e3bee47322959f3e5364e54ba"
70
+ "gitHead": "a3b55b29586394f73a1a16982d2f1c13901d5061"
71
71
  }