@topthink/chat 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsx as e,jsxs 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,isCancel as l,isRequestError as c,Form as d,Toast as u,InfiniteScroller as m,useDebounce as h,Offcanvas as p,ModalForm as g,RequestButton as f,Loader as b,useImmer as v,getAbsoluteUrl as y,Lightbox as x,Clipboard as w,Button as k,isImageUrl as E,request as N}from"@topthink/components";import*as j from"react";import{createContext as C,useContext as $,useEffect as M,useState as S,useRef as F,useCallback as q,forwardRef as R,useMemo as z,useImperativeHandle as I,Fragment as A,memo as D}from"react";import*as L from"path";import P from"path";import{Spinner as T,Badge as O,Dropdown as B,FormControl as U,CloseButton as _,OverlayTrigger as H,Popover as Q}from"react-bootstrap";import J from"eventemitter3";import K from"react-textarea-autosize";import W from"lodash/isEqual";import{toString as X}from"hast-util-to-string";import V from"react-markdown";import"katex/dist/katex.min.css";import Y from"rehype-highlight";import G from"rehype-katex";import Z from"remark-breaks";import ee from"remark-gfm";import te from"remark-math";import{codes as re,types as ne}from"micromark-util-symbol";import{markdownLineEnding as ie}from"micromark-util-character";import{createPortal as oe}from"react-dom";import se from"use-resize-observer";import{unified as ae}from"unified";import le from"rehype-stringify";import ce from"remark-parse";import de from"remark-rehype";function ue(e,t){return e.name===t}const me=C(null);function he(e){const t=$(me);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return M(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function pe({children:t,...r}){const[n,i]=S({});return e(me.Provider,{value:{...r,handles:n,setHandles:i},children:t})}const ge=function({ext:t}){const{result:r}=a(async e=>{try{return(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/html.svg":return import("./html-BSKTzJZQ.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/mp3.svg":return import("./mp3-HhP1Gk4B.js");case"../../images/file/mp4.svg":return import("./mp4-CWxSyjdn.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/py.svg":return import("./py-D30pRTJN.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/unknown.svg":return import("./unknown-DW8znerP.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.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}catch{return(await import("./unknown-DW8znerP.js")).default}},[t]);return r?e("img",{width:30,height:30,src:r}):null},fe=function({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const u=P.extname(n).substring(1),m=t(we,{className:r,$error:!!l,onClick:d,children:[t(xe,{children:[e(ge,{ext:u}),a&&e(T,{variant:"primary"})]}),t(ye,{children:[e("h4",{children:n}),i>0&&e("p",{children:o(i,1)})]}),c&&e(ve,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(s,{placement:"top",tooltip:l,children:m}):m};function be(t){const{renderFileItem:r}=he();return r?r({Component:fe,props:t}):e(fe,{...t})}const ve=n.div`
1
+ import{jsx as e,jsxs 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,isCancel as l,isRequestError as c,Form as d,Toast as u,InfiniteScroller as m,useDebounce as h,Offcanvas as p,ModalForm as g,RequestButton as f,Loader as b,useImmer as v,getAbsoluteUrl as y,Lightbox as x,Clipboard as w,Button as k,isImageUrl as E,request as N}from"@topthink/components";import*as j from"react";import{createContext as C,useContext as $,useEffect as M,useState as S,useRef as q,useCallback as F,forwardRef as R,useMemo as z,useImperativeHandle as I,Fragment as A,memo as D}from"react";import*as L from"path";import P from"path";import{Spinner as T,Badge as O,Dropdown as B,FormControl as U,CloseButton as _,OverlayTrigger as H,Popover as Q}from"react-bootstrap";import J from"eventemitter3";import K from"react-textarea-autosize";import W from"lodash/isEqual";import{toString as X}from"hast-util-to-string";import V from"react-markdown";import"katex/dist/katex.min.css";import Y from"rehype-highlight";import G from"rehype-katex";import Z from"remark-breaks";import ee from"remark-gfm";import te from"remark-math";import{codes as re,types as ne}from"micromark-util-symbol";import{markdownLineEnding as ie}from"micromark-util-character";import{createPortal as oe}from"react-dom";import se from"use-resize-observer";import{unified as ae}from"unified";import le from"rehype-stringify";import ce from"remark-parse";import de from"remark-rehype";function ue(e,t){return e.name===t}const me=C(null);function he(e){const t=$(me);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return M(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function pe({children:t,...r}){const[n,i]=S({});return e(me.Provider,{value:{...r,handles:n,setHandles:i},children:t})}const ge=function({ext:t}){const{result:r}=a(async e=>{try{return(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/html.svg":return import("./html-BSKTzJZQ.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/mp3.svg":return import("./mp3-HhP1Gk4B.js");case"../../images/file/mp4.svg":return import("./mp4-CWxSyjdn.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/py.svg":return import("./py-D30pRTJN.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/unknown.svg":return import("./unknown-DW8znerP.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.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}catch{return(await import("./unknown-DW8znerP.js")).default}},[t]);return r?e("img",{width:30,height:30,src:r}):null},fe=function({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const u=P.extname(n).substring(1),m=t(we,{className:r,$error:!!l,onClick:d,children:[t(xe,{children:[e(ge,{ext:u}),a&&e(T,{variant:"primary"})]}),t(ye,{children:[e("h4",{children:n}),i>0&&e("p",{children:o(i,1)})]}),c&&e(ve,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(s,{placement:"top",tooltip:l,children:m}):m};function be(t){const{renderFileItem:r}=he();return r?r({Component:fe,props:t}):e(fe,{...t})}const ve=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -65,15 +65,15 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
65
65
  ${e=>e.$error&&i`
66
66
  border-color: var(--bs-danger) !important;
67
67
  `}
68
- `,ke=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Ee(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s,messages:a}=he(),d=F(null),u=F(n),m=()=>(d.current&&d.current.abort(),d.current=new AbortController,d.current.signal),{onComplete:h,onEvent:p}=s,g=q(t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(u.current=r.conversation,i(r.conversation)):r.event?p?.(r.event):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;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}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})},[s]),f=q(t=>{if(l(t))e(e=>{const t=e[e.length-1];t&&(t.loading=!1)});else{let r="未知错误";c(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})}},[]),b=q(async t=>{try{const n=m();r(!0),e(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let i={url:"message",method:"get",params:{id:t},onMessage:g,signal:n};await o(i)}catch(e){f(e)}finally{d.current=null}r(!1),h?.()},[o,s]),v=q(async(n,...i)=>{"string"==typeof n&&(n={query:n,...i});const{query:s,files:a=[],variables:l={},quote:c}=n;let p=null;if(s||a.length>0){const n=m();r(!0),t([]),e(e=>{e.push({query:s,quote:c,files:a,variables:l,chunks:[],loading:!0})});try{let e={method:"post",data:{query:s,quote:c,files:a,variables:l,conversation:u.current},onMessage:g,signal:n};p=(await o(e)).message??null}catch(e){f(e)}finally{d.current=null}p?await b(p.id):(r(!1),h?.())}},[o,s]),y=q(async t=>{try{const n=m();r(!0),e(e=>{e[e.length-1].loading=!0});let i={url:"resume",method:"post",data:{conversation:u.current,chunk:t.chunk,tool:t.tool,payload:t.payload},onMessage:g,signal:n};await o(i)}catch(e){f(e)}finally{d.current=null}r(!1),h?.()},[o,s]),x=q(async()=>{try{const e=m();let r={method:"post",url:"/suggestion",data:{conversation:u.current},signal:e};const n=await o(r);t(n)}catch{}finally{d.current=null}},[o]);return M(()=>{const e=a[a.length-1];return e&&0==e.chunks?.length&&!e.loading&&b(e.id),()=>{d.current&&d.current.abort()}},[]),M(()=>{if(n!=u.current){u.current=n,d.current&&d.current.abort();const e=a[a.length-1];e&&0==e.chunks?.length&&!e.loading&&b(e.id)}},[n]),{send:v,resume:y,suggest:x}}function Ne({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[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&&a.push(e.key)}),e(d,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const je=n.button`
68
+ `,ke=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Ee({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[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&&a.push(e.key)}),e(d,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const Ne=n.button`
69
69
  color: var(--bs-secondary);
70
70
  cursor: pointer;
71
71
  display: flex;
72
72
  align-items: center;
73
73
  justify-content: center;
74
- width: 1.5rem;
75
- height: 1.5rem;
76
- border-radius: .5rem;
74
+ width: 1.75rem;
75
+ height: 1.75rem;
76
+ border-radius: .25rem;
77
77
  outline: none;
78
78
  border: none;
79
79
  background: transparent;
@@ -84,16 +84,24 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
84
84
  color: var(--bs-gray-400) !important;
85
85
  }
86
86
 
87
- &:hover&:not(:disabled) {
87
+ &:hover:not(:disabled) {
88
88
  background-color: var(--bs-gray-200);
89
89
  }
90
90
 
91
- `;let Ce=class{#e;#t;constructor(){this.#t=new J}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 u.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),u.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},$e=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new J}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){u.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 Me=R(({onResult:r,model:n="builtin"},i)=>{const{request:o}=he(),a=z(()=>{if("builtin"!==n)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",n);return(await o({url:"/transcriptions",method:"post",data:t})).text}},[n]),{start:l,stop:c,recording:d,transcribing:u}=function({onResult:e,loader:t}){const r=F(),[n,i]=S(!1),[o,s]=S(!1);return M(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new $e(t):new Ce,r.current.onRecording(i),r.current.onTranscribing(s),r.current.onResult(e)),r.current.start()},stop:()=>{r.current&&r.current.stop()}}}({onResult:r,loader:a});return I(i,()=>({start:l,stop:c}),[l,c]),e(s,{tooltip:d?"停止":"语音输入",placement:"top",children:t(je,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[u&&e(Se,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Se=n(T)`
91
+ ${({$fill:e})=>e&&i`
92
+ background-color: var(--bs-gray-200);
93
+
94
+ &:hover:not(:disabled) {
95
+ background-color: var(--bs-gray-300);
96
+ }
97
+ `};
98
+
99
+ `;let je=class{#e;#t;constructor(){this.#t=new J}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 u.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),u.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},Ce=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new J}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){u.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 $e=R(({onResult:r,model:n="builtin"},i)=>{const{request:o}=he(),a=z(()=>{if("builtin"!==n)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",n);return(await o({url:"/transcriptions",method:"post",data:t})).text}},[n]),{start:l,stop:c,recording:d,transcribing:u}=function({onResult:e,loader:t}){const r=q(),[n,i]=S(!1),[o,s]=S(!1);return M(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new Ce(t):new je,r.current.onRecording(i),r.current.onTranscribing(s),r.current.onResult(e)),r.current.start()},stop:()=>{r.current&&r.current.stop()}}}({onResult:r,loader:a});return I(i,()=>({start:l,stop:c}),[l,c]),e(s,{tooltip:d?"停止":"语音输入",placement:"top",children:t(Ne,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[u&&e(Me,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Me=n(T)`
92
100
  position: absolute;
93
101
  --bs-spinner-width: .75rem;
94
102
  --bs-spinner-height: .75rem;
95
103
  --bs-spinner-border-width: 0.1em;
96
- `,Fe=R(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=e(qe,{ref:c,className:t,onClick:a,onMouseDown:l,$size:n,children:r});return i?e(s,{tooltip:i,placement:o,children:d}):d}),qe=n.div`
104
+ `,Se=R(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=e(qe,{ref:c,className:t,onClick:a,onMouseDown:l,$size:n,children:r});return i?e(s,{tooltip:i,placement:o,children:d}):d}),qe=n.div`
97
105
  width: 2rem;
98
106
  height: 2rem;
99
107
  align-items: center;
@@ -117,10 +125,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
117
125
  &:hover {
118
126
  background-color: var(--bs-secondary-bg-subtle);
119
127
  }
120
- `;function Re(){const{request:n,reset:i,conversationId:o}=he(),[s,a]=S(!1),[l,c]=S(""),[d,u]=S(""),m=h(e=>{u(e)},500);return M(()=>{m(l)},[l]),t(r,{children:[e(Fe,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:e("i",{className:"bi bi-clock-history"})}),e(p,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:Le,header:t(r,{children:[e("span",{children:"聊天历史记录"}),e(Pe,{children:e(U,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:ze,children:s&&e(De,{children:e(Ae,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?t(r,{children:[s.map((s,l)=>t(A,{children:[l>0&&e("hr",{className:"mx-2 my-2"}),t(Ie,{children:[o===s.id&&e(O,{bg:"secondary",children:"当前"}),e("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),t(B,{align:"end",children:[e(B.Toggle,{size:"sm",className:"no-caret",as:Fe,children:e("i",{className:"bi bi-three-dots-vertical"})}),t(B.Menu,{children:[e(g,{buttonProps:{as:B.Item},text:t(r,{children:[e("i",{className:"bi bi-pencil me-2"}),"重命名"]}),modalProps:{header:"编辑对话名称"},schema:{type:"object",properties:{title:{type:"string"}}},uiSchema:{title:{"ui:label":!1,"ui:autofocus":!0}},formData:{title:s.title},onRequest:e=>n({url:`/conversation/${s.id}`,method:"PUT",data:e}),onSuccess:(e,t)=>{c(e=>{const r=e.findIndex(e=>e.id===s.id);-1!==r&&Object.assign(e[r],t)})}}),t(f,{as:B.Item,confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${s.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===s.id);-1!==t&&e.splice(t,1)})},children:[e("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)),l&&e(b,{wrap:!0})]}):e("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const ze=n.div`
128
+ `;function Fe(){const{request:n,reset:i,conversationId:o}=he(),[s,a]=S(!1),[l,c]=S(""),[d,u]=S(""),m=h(e=>{u(e)},500);return M(()=>{m(l)},[l]),t(r,{children:[e(Se,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:e("i",{className:"bi bi-clock-history"})}),e(p,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:De,header:t(r,{children:[e("span",{children:"聊天历史记录"}),e(Le,{children:e(U,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:Re,children:s&&e(Ae,{children:e(Ie,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?t(r,{children:[s.map((s,l)=>t(A,{children:[l>0&&e("hr",{className:"mx-2 my-2"}),t(ze,{children:[o===s.id&&e(O,{bg:"secondary",children:"当前"}),e("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),t(B,{align:"end",children:[e(B.Toggle,{size:"sm",className:"no-caret",as:Se,children:e("i",{className:"bi bi-three-dots-vertical"})}),t(B.Menu,{children:[e(g,{buttonProps:{as:B.Item},text:t(r,{children:[e("i",{className:"bi bi-pencil me-2"}),"重命名"]}),modalProps:{header:"编辑对话名称"},schema:{type:"object",properties:{title:{type:"string"}}},uiSchema:{title:{"ui:label":!1,"ui:autofocus":!0}},formData:{title:s.title},onRequest:e=>n({url:`/conversation/${s.id}`,method:"PUT",data:e}),onSuccess:(e,t)=>{c(e=>{const r=e.findIndex(e=>e.id===s.id);-1!==r&&Object.assign(e[r],t)})}}),t(f,{as:B.Item,confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${s.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===s.id);-1!==t&&e.splice(t,1)})},children:[e("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)),l&&e(b,{wrap:!0})]}):e("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const Re=n.div`
121
129
  padding: 0;
122
130
  overflow: hidden;
123
- `,Ie=n.div`
131
+ `,ze=n.div`
124
132
  gap: .5rem;
125
133
  display: flex;
126
134
  cursor: pointer;
@@ -139,33 +147,33 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
139
147
  display: block;
140
148
  }
141
149
  }
142
- `,Ae=n(m)`
150
+ `,Ie=n(m)`
143
151
  display: flex;
144
152
  flex-direction: column;
145
153
  padding: .5rem;
146
- `,De=n.div`
154
+ `,Ae=n.div`
147
155
  height: 100%;
148
156
  overflow-y: auto;
149
- `,Le=n.div`
157
+ `,De=n.div`
150
158
  display: flex;
151
159
  align-items: center;
152
160
  justify-content: space-between;
153
161
  gap: 0.5rem;
154
162
  flex: 1;
155
163
  margin-right: .5rem;
156
- `,Pe=n.div`
164
+ `,Le=n.div`
157
165
  display: flex;
158
166
  align-items: center;
159
167
  gap: 0.5rem;
160
- `;var Te;function Oe(){return Oe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Oe.apply(null,arguments)}const Be=e=>j.createElement("svg",Oe({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Te||(Te=j.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 Ue(){const{reset:t}=he();return e(Fe,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(Be,{})})}function _e({children:r,actions:n}){return t(Qe,{children:[r,t(He,{children:[n,e(Re,{}),e(Ue,{})]})]})}const He=n.div`
168
+ `;var Pe;function Te(){return Te=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Te.apply(null,arguments)}const Oe=e=>j.createElement("svg",Te({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Pe||(Pe=j.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 Be(){const{reset:t}=he();return e(Se,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(Oe,{})})}function Ue({children:r,actions:n}){return t(He,{children:[r,t(_e,{children:[n,e(Fe,{}),e(Be,{})]})]})}const _e=n.div`
161
169
  display: flex;
162
170
  gap: .25rem;
163
171
  margin-left: auto;
164
- `,Qe=n.div`
172
+ `,He=n.div`
165
173
  margin-bottom: .5rem;
166
174
  display: flex;
167
175
  padding: 0 .125rem;
168
- `;var Je=R(function({readonly:t,autoFocus:r,placeholder:n,minRows:i,maxRows:o,onSubmit:s,onFocusedChange:a,onQueryChange:l,onPaste:c},d){const u=F(null),[m,h]=S(""),p=q(()=>{const e=u.current;if(!e)return;e.focus();const t=e.value.length;e.setSelectionRange(t,t)},[]),g=q(e=>{const t="string"==typeof e?e:e(m);h(t),l?.(t.trim()),requestAnimationFrame(()=>{p()})},[m,l,p]);return I(d,()=>({setContent:g,focus(){p()}}),[g,p]),e(Ke,{ref:u,value:m,minRows:i,maxRows:o,readOnly:t,autoFocus:r,placeholder:n,onFocus:()=>a?.(!0),onBlur:()=>a?.(!1),onChange:e=>{h(e.target.value),l?.(e.target.value.trim())},onPaste:e=>{c?.(e.nativeEvent)},onKeyDown:e=>{e.nativeEvent.isComposing||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),e.stopPropagation(),s?.())}})});const Ke=n(K)`
176
+ `;var Qe=R(function({readonly:t,autoFocus:r,placeholder:n,minRows:i,maxRows:o,onSubmit:s,onFocusedChange:a,onQueryChange:l,onPaste:c},d){const u=q(null),[m,h]=S(""),p=F(()=>{const e=u.current;if(!e)return;e.focus();const t=e.value.length;e.setSelectionRange(t,t)},[]),g=F(e=>{const t="string"==typeof e?e:e(m);h(t),l?.(t.trim()),requestAnimationFrame(()=>{p()})},[m,l,p]);return I(d,()=>({setContent:g,focus(){p()}}),[g,p]),e(Je,{ref:u,value:m,minRows:i,maxRows:o,readOnly:t,autoFocus:r,placeholder:n,onFocus:()=>a?.(!0),onBlur:()=>a?.(!1),onChange:e=>{h(e.target.value),l?.(e.target.value.trim())},onPaste:e=>{c?.(e.nativeEvent)},onKeyDown:e=>{e.nativeEvent.isComposing||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),e.stopPropagation(),s?.())}})});const Je=n(K)`
169
177
  min-height: calc(1.5em + 1rem);
170
178
  width: 100%;
171
179
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
@@ -175,14 +183,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
175
183
  flex: 1;
176
184
  line-height: 1.5;
177
185
  background: transparent;
178
- `;var We=R(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:l=1,maxRows:d=5,toolbar:m,toolbarActions:h,disabled:p,autoFocus:g,renderEditableInput:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送",onEvent:y},x){const w=F(null),k=F(null),E=F(null),[N,j]=S(""),[C,$]=S(""),[R,A]=v([]),[D,P]=S(!1),T=n&&n.length>0?n:ke,{send:O,resume:B,suggest:U}=Ee(),H=z(()=>({onSuccess(){r&&U()},onComplete(){requestAnimationFrame(()=>{E.current?.focus()})},onEvent:y}),[r,y]),{messages:Q,loading:J,request:K,setInput:W}=he(H),[X,V]=S();M(()=>{const e=Q.filter(e=>!!e.query);V(e.at(-1)?.variables)},[Q]),M(()=>{!n&&R.length>0&&A([])},[n]),M(()=>{const e=o.current;if(e&&O){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...X,...a.values}),O(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,X]);const Y=q(e=>{const t=e.map((e,t)=>{if(e.name)return e;const r=e.type.split("/")[1]||"png";return new File([e],`screenshot-${Date.now()}-${t}.${r}`,{type:e.type})}).filter(e=>!(!T.includes("*")&&!T.includes(L.extname(e.name)))&&!(e.size>20971520)).slice(0,6-R.length);return 0!==t.length&&(A(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await K({method:"POST",url:"/upload",data:t});A(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=c(t)?t.message:"unknown error";A(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}}),!0)},[R.length,T,K,A]),G=q(({target:e})=>{e.files&&Y(Array.from(e.files)),e.value=""},[Y]),Z=q(e=>{const t=Array.from(e.clipboardData?.files||[]),r=Array.from(e.clipboardData?.items||[]).filter(e=>"file"===e.kind).map(e=>e.getAsFile()).filter(e=>!!e),n=t.length>0?t:r;0!==n.length&&Y(n)&&e.preventDefault()},[Y]),ee=R.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),te=q(()=>{if(N||ee.length>0){const e={query:N,files:ee};a&&(e.variables={...X,...a.values}),C&&(e.quote=C),O(e),E.current?.setContent(""),$(""),A([]),k.current?.stop(!0)}},[N,ee,a,X,C]),re=z(()=>({setQuery(e){E.current?.setContent(e)},setQuote:$,send:O,resume:B,focus(){E.current?.focus()}}),[$,O,B]);if(M(()=>{W(re)},[re]),I(x,()=>re,[re]),a){const t=a.config.filter(e=>!(e.key in(a.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&u.error("请完善必填信息"),n});if(t.length>0&&!r(X))return e(Ve,{children:e(Xe,{children:e(Ne,{values:X,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return V(e),!0}})})})}return t(nt,{children:[m&&e(_e,{actions:h,children:m}),t(rt,{$focused:D&&!J,children:[R.length>0&&e(Ge,{children:R.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(Ye,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{A(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!C&&t(tt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:C}),e(_,{onClick:()=>$("")})]}),t(Ze,{children:[f?.({Component:Je,props:{ref:E,readonly:J||p,autoFocus:g,placeholder:b,minRows:l,maxRows:d,onSubmit:te,onFocusedChange:P,onQueryChange:j,onPaste:Z}})||e(Je,{ref:E,readonly:J||p,autoFocus:g,placeholder:b,minRows:l,maxRows:d,onSubmit:te,onFocusedChange:P,onQueryChange:j,onPaste:Z}),t(et,{children:[n&&e(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(je,{disabled:R.length>=6,onClick:()=>w.current?.click(),children:[e("input",{onChange:G,multiple:!0,accept:T.join(","),ref:w,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e(Me,{ref:k,model:i.model,onResult:e=>{E.current?.setContent(t=>t+e+" ")}}),e(je,{className:"text-primary",disabled:!N&&0===ee.length,onClick:e=>{e.preventDefault(),te()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})]})});const Xe=n.div`
186
+ `;var Ke=R(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:d=1,maxRows:m=5,toolbar:h,toolbarActions:p,disabled:g,autoFocus:f,renderEditableInput:b,placeholder:y="请输入你的问题, Enter+Shift换行, Enter发送",supportStop:x=!1,onEvent:w},k){const E=q(null),N=q(null),j=q(null),[C,$]=S(""),[R,A]=S(""),[D,P]=v([]),[T,O]=S(!1),B=n&&n.length>0?n:ke,{send:U,resume:H,stop:Q,suggest:J}=function(e){const{setMessages:t,setSuggestions:r,setLoading:n,conversationId:i,setConversationId:o,request:s,handles:a,messages:d}=he(),u=!0===e?.supportStop,m=q(null),h=q(),p=q(i),g=()=>(m.current&&m.current.abort(),m.current=new AbortController,m.current.signal),{onComplete:f,onEvent:b}=a,v=F(e=>{if(e.data)if("[DONE]"!=e.data)try{const r=JSON.parse(e.data);r.conversation?(p.current=r.conversation,o(r.conversation)):r.event?b?.(r.event):t(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;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}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 t(e=>{e[e.length-1].loading=!1})},[a]),y=F(e=>{if(l(e))t(e=>{const t=e[e.length-1];t&&(t.loading=!1)});else{let r="未知错误";c(e)&&(r=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),t(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})}},[]),x=F(async e=>{h.current=e;try{const r=g();n(!0),t(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let i={url:"message",method:"get",params:{id:e},onMessage:v,signal:r};await s(i)}catch(e){y(e)}finally{m.current=null,h.current=void 0}n(!1),f?.()},[s,a]),w=F(async(e,...i)=>{"string"==typeof e&&(e={query:e,...i});const{query:o,files:a=[],variables:l={},quote:c}=e;let d=null;if(o||a.length>0){const e=g();n(!0),r([]),t(e=>{e.push({query:o,quote:c,files:a,variables:l,chunks:[],loading:!0})});try{let t={method:"post",data:{query:o,quote:c,files:a,variables:l,conversation:p.current},onMessage:v,signal:e};d=(await s(t)).message??null}catch(e){y(e)}finally{m.current=null}d?await x(d.id):(n(!1),f?.())}},[s,a]),k=F(async e=>{let r=null;try{const i=g();n(!0),t(e=>{e[e.length-1].loading=!0});let o={url:"resume",method:"post",data:{conversation:p.current,chunk:e.chunk,tool:e.tool,payload:e.payload},onMessage:v,signal:i};r=(await s(o)).message??null}catch(e){y(e)}finally{m.current=null}r?await x(r.id):(n(!1),f?.())},[s,a]),E=F(async()=>{try{const e=g();let t={method:"post",url:"/suggestion",data:{conversation:p.current},signal:e};const n=await s(t);r(n)}catch{}finally{m.current=null}},[s]),N=F(async()=>{if(u)if(h.current)try{await s({url:"stop",method:"post",data:{id:h.current}})}catch{}else m.current?.abort()},[s,u]),j=()=>{const e=d[d.length-1];e&&e.id&&2===e.status&&x(e.id)};return M(()=>(j(),()=>{m.current&&m.current.abort()}),[]),M(()=>{i!=p.current&&(p.current=i,m.current&&m.current.abort(),j())},[i]),{send:w,resume:k,suggest:E,stop:N}}({supportStop:x}),K=z(()=>({onSuccess(){r&&J()},onComplete(){requestAnimationFrame(()=>{j.current?.focus()})},onEvent:w}),[r,w]),{messages:W,loading:X,request:V,setInput:Y}=he(K),[G,Z]=S();M(()=>{const e=W.filter(e=>!!e.query);Z(e.at(-1)?.variables)},[W]),M(()=>{!n&&D.length>0&&P([])},[n]),M(()=>{const e=o.current;if(e&&U){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...G,...a.values}),U(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,G]);const ee=F(e=>{const t=e.map((e,t)=>{if(e.name)return e;const r=e.type.split("/")[1]||"png";return new File([e],`screenshot-${Date.now()}-${t}.${r}`,{type:e.type})}).filter(e=>!(!B.includes("*")&&!B.includes(L.extname(e.name)))&&!(e.size>20971520)).slice(0,6-D.length);return 0!==t.length&&(P(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await V({method:"POST",url:"/upload",data:t});P(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=c(t)?t.message:"unknown error";P(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}}),!0)},[D.length,B,V,P]),te=F(({target:e})=>{e.files&&ee(Array.from(e.files)),e.value=""},[ee]),re=F(e=>{const t=Array.from(e.clipboardData?.files||[]),r=Array.from(e.clipboardData?.items||[]).filter(e=>"file"===e.kind).map(e=>e.getAsFile()).filter(e=>!!e),n=t.length>0?t:r;0!==n.length&&ee(n)&&e.preventDefault()},[ee]),ne=D.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),ie=F(()=>{if(C||ne.length>0){const e={query:C,files:ne};a&&(e.variables={...G,...a.values}),R&&(e.quote=R),U(e),j.current?.setContent(""),A(""),P([]),N.current?.stop(!0)}},[C,ne,a,G,R]),oe=z(()=>({setQuery(e){j.current?.setContent(e)},setQuote:A,send:U,resume:H,focus(){j.current?.focus()}}),[A,U,H]);if(M(()=>{Y(oe)},[oe]),I(k,()=>oe,[oe]),a){const t=a.config.filter(e=>!(e.key in(a.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&u.error("请完善必填信息"),n});if(t.length>0&&!r(G))return e(Xe,{children:e(We,{children:e(Ee,{values:G,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return Z(e),!0}})})})}return t(rt,{children:[h&&e(Ue,{actions:p,children:h}),t(tt,{$focused:T&&!X,children:[D.length>0&&e(Ye,{children:D.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(Ve,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{P(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!R&&t(et,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:R}),e(_,{onClick:()=>A("")})]}),t(Ge,{children:[b?.({Component:Qe,props:{ref:j,readonly:X||g,autoFocus:f,placeholder:y,minRows:d,maxRows:m,onSubmit:ie,onFocusedChange:O,onQueryChange:$,onPaste:re}})||e(Qe,{ref:j,readonly:X||g,autoFocus:f,placeholder:y,minRows:d,maxRows:m,onSubmit:ie,onFocusedChange:O,onQueryChange:$,onPaste:re}),t(Ze,{children:[n&&e(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(Ne,{disabled:D.length>=6,onClick:()=>E.current?.click(),children:[e("input",{onChange:te,multiple:!0,accept:B.join(","),ref:E,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e($e,{ref:N,model:i.model,onResult:e=>{j.current?.setContent(t=>t+e+" ")}}),e(Ne,{$fill:X&&x,className:X&&x?"text-danger":"text-primary",disabled:!C&&0===ne.length&&!X||X&&!x,onClick:e=>{e.preventDefault(),X&&x?Q():ie()},children:e("i",X&&x?{className:"bi bi-square-fill fs-7"}:{className:"bi bi-send-fill"})})]})]})]})]})});const We=n.div`
179
187
  border-radius: var(--bs-border-radius-lg);
180
188
  box-shadow: var(--bs-box-shadow-sm);
181
189
  margin: 1rem;
182
190
  padding: 1rem;
183
191
  width: 100%;
184
192
  max-width: 500px;
185
- `,Ve=n.div`
193
+ `,Xe=n.div`
186
194
  position: absolute;
187
195
  left: 0;
188
196
  right: 0;
@@ -192,25 +200,25 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
192
200
  display: flex;
193
201
  justify-content: center;
194
202
  align-items: center;
195
- `,Ye=n(be)`
203
+ `,Ve=n(be)`
196
204
  width: calc((100% - 0.75rem) / 2);
197
- `,Ge=n.div`
205
+ `,Ye=n.div`
198
206
  display: flex;
199
207
  flex-wrap: wrap;
200
208
  padding: 0.75rem;
201
209
  gap: 0.75rem;
202
210
  border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
203
- `,Ze=n.div`
211
+ `,Ge=n.div`
204
212
  display: flex;
205
213
  gap: 0.25rem;
206
214
  align-items: end;
207
215
  flex-direction: row;
208
- `,et=n.div`
216
+ `,Ze=n.div`
209
217
  display: flex;
210
218
  flex-direction: row;
211
219
  gap: 0.25rem;
212
- padding: 0.5rem 0.5rem 0.5rem 0.5rem;
213
- `,tt=n.div`
220
+ padding: 0.375rem 0.5rem 0.375rem 0.5rem;
221
+ `,et=n.div`
214
222
  margin: 0.75rem 0.75rem 0 0.75rem;
215
223
  padding: 4px 8px;
216
224
  display: flex;
@@ -231,14 +239,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
231
239
  -webkit-box-orient: vertical;
232
240
  display: -webkit-box;
233
241
  }
234
- `,rt=n.div`
242
+ `,tt=n.div`
235
243
  background: #fff;
236
244
  border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
237
245
  border-radius: var(--bs-border-radius-lg);
238
246
  box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
239
- `,nt=n.div`
247
+ `,rt=n.div`
240
248
  margin: 0 1rem 1rem;
241
- `;function it(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(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}}))}function ot(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 st,at,lt;function ct(){return ct=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ct.apply(null,arguments)}const dt=e=>j.createElement("svg",ct({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),st||(st=j.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),at||(at=j.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),lt||(lt=j.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function ut(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${y(e.image)})`}return""}const mt=function(e,t,r){function n(t){return t!==re.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(ne.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===re.rightSquareBracket?(e.exit(ne.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==re.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):ie(n)||n===re.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==re.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},ht=function(){const e=this.data();e.micromarkExtensions.push({text:{[re.leftSquareBracket]:{tokenize:mt}}}),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}}})},pt=x.Image,gt={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=S(!1),s=z(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);M(()=>{s&&o(s)},[s]);const a=z(()=>X(n),[n]);return t(wt,{children:[t(xt,{children:[!i&&e(w,{tooltip:!1,as:yt,content:a}),s&&i&&e(yt,{onClick:()=>{const e=new Blob([a],{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:"下载"}),s&&e(yt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?e("div",{dangerouslySetInnerHTML:{__html:a}}):e("pre",{children:r})]})},a:({node:t,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return e("a",{...n,href:r,target:i})},img:({node:t,...r})=>e(pt,{...r})},ft=[[te,{singleDollarTextMath:!1}],ee,Z],bt=[G,[Y,{detect:!1,ignoreMissing:!0}]],vt=D(R(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=z(()=>{const e={...gt,...r};return n&&(e.cite=n),e},[r,n]),s=z(()=>n?[...ft,ht]:ft,[n]);return e(kt,{ref:i,children:e(V,{remarkPlugins:s,rehypePlugins:bt,components:o,children:t})})}),W),yt=n.div`
249
+ `;function nt(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(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency},status:e.status??1}))}function it(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 ot,st,at;function lt(){return lt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},lt.apply(null,arguments)}const ct=e=>j.createElement("svg",lt({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),ot||(ot=j.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),st||(st=j.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),at||(at=j.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function dt(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${y(e.image)})`}return""}const ut=function(e,t,r){function n(t){return t!==re.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(ne.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===re.rightSquareBracket?(e.exit(ne.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==re.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):ie(n)||n===re.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==re.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},mt=function(){const e=this.data();e.micromarkExtensions.push({text:{[re.leftSquareBracket]:{tokenize:ut}}}),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}}})},ht=x.Image,pt={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=S(!1),s=z(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);M(()=>{s&&o(s)},[s]);const a=z(()=>X(n),[n]);return t(xt,{children:[t(yt,{children:[!i&&e(w,{tooltip:!1,as:vt,content:a}),s&&i&&e(vt,{onClick:()=>{const e=new Blob([a],{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:"下载"}),s&&e(vt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?e("div",{dangerouslySetInnerHTML:{__html:a}}):e("pre",{children:r})]})},a:({node:t,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return e("a",{...n,href:r,target:i})},img:({node:t,...r})=>e(ht,{...r})},gt=[[te,{singleDollarTextMath:!1}],ee,Z],ft=[G,[Y,{detect:!1,ignoreMissing:!0}]],bt=D(R(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=z(()=>{const e={...pt,...r};return n&&(e.cite=n),e},[r,n]),s=z(()=>n?[...gt,mt]:gt,[n]);return e(wt,{ref:i,children:e(V,{remarkPlugins:s,rehypePlugins:ft,components:o,children:t})})}),W),vt=n.div`
242
250
  cursor: pointer;
243
251
  padding: 2px 10px;
244
252
  background-color: #303030;
@@ -248,7 +256,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
248
256
  font-size: 12px;
249
257
  font-family: initial;
250
258
  user-select: none;
251
- `,xt=n.div`
259
+ `,yt=n.div`
252
260
  position: absolute;
253
261
  right: 10px;
254
262
  top: 1em;
@@ -262,17 +270,17 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
262
270
  &:hover {
263
271
  opacity: 1;
264
272
  }
265
- `,wt=n.div`
273
+ `,xt=n.div`
266
274
  position: relative;
267
275
 
268
276
  &:hover {
269
- ${xt} {
277
+ ${yt} {
270
278
  pointer-events: all;
271
279
  transform: translateX(0px);
272
280
  opacity: 0.7;
273
281
  }
274
282
  }
275
- `,kt=n.div`
283
+ `,wt=n.div`
276
284
  -ms-text-size-adjust: 100%;
277
285
  -webkit-text-size-adjust: 100%;
278
286
  line-height: 1.8;
@@ -542,7 +550,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
542
550
  .hljs-strong {
543
551
  font-weight: 700;
544
552
  }
545
- `;var Et=R(function({children:t,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=e(Nt,{ref:a,onClick:n,$disabled:i,...o,children:t});return r?e(s,{tooltip:r,placement:"top",children:l}):l});const Nt=n.div`
553
+ `;var kt=R(function({children:t,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=e(Et,{ref:a,onClick:n,$disabled:i,...o,children:t});return r?e(s,{tooltip:r,placement:"top",children:l}):l});const Et=n.div`
546
554
  align-items: center;
547
555
  justify-content: center;
548
556
  border-radius: .375rem;
@@ -575,7 +583,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
575
583
  `}
576
584
 
577
585
  }
578
- `,jt=C(null);var Ct=jt.Provider;const $t=x.Image;function Mt({src:t,...r}){const{imageResolver:n}=he();return n&&t&&(t=n(t)),e(St,{children:e($t,{src:t,...r})},t)}const St=n.div`
586
+ `,Nt=C(null);var jt=Nt.Provider;const Ct=x.Image;function $t({src:t,...r}){const{imageResolver:n}=he();return n&&t&&(t=n(t)),e(Mt,{children:e(Ct,{src:t,...r})},t)}const Mt=n.div`
579
587
  margin-bottom: .5rem;
580
588
  margin-top: .5rem;
581
589
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -600,7 +608,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
600
608
  max-height: 100%;
601
609
  max-width: 100%;
602
610
  }
603
- `,Ft=C(null);function qt(){const e=$(Ft);if(!e)throw new Error("useContext must be used within a Provider");return e}function Rt({children:t,...r}){return e(Ft.Provider,{value:r,children:t})}function zt({description:r,options:n}){const{resume:i,disabled:o,response:s}=qt(),[a,l]=S(s?.result),c=o||void 0!==a;return t(It,{children:[r&&e(At,{children:r}),n.map((t,r)=>e(Dt,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const It=n.div`
611
+ `,St=C(null);function qt(){const e=$(St);if(!e)throw new Error("useContext must be used within a Provider");return e}function Ft({children:t,...r}){return e(St.Provider,{value:r,children:t})}function Rt(e){const[t,r]=S(e);return M(()=>{r(e)},[e]),[t,r]}function zt({description:r,options:n}){const{resume:i,disabled:o,response:s}=qt(),[a,l]=Rt(s?.result),c=o||void 0!==a;return t(It,{children:[r&&e(At,{children:r}),n.map((t,r)=>e(Dt,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const It=n.div`
604
612
  display: flex;
605
613
  flex-direction: column;
606
614
  gap: 0.5rem;
@@ -635,7 +643,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
635
643
  &:active {
636
644
  transform: ${e=>e.$disabled?"none":"scale(0.98)"};
637
645
  }
638
- `;function Lt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=qt(),[a,l]=S(void 0!==s),c=o||a,{schema:u,uiSchema:m}=z(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Tt,{className:"rounded bg-white shadow-sm",children:[r&&e(Ot,{children:r}),e(d,{schema:u,uiSchema:m,formData:s,onSubmit:({formData:e})=>{c||(l(!0),i(e))},disabled:c,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Pt,{children:t})})]})}const Pt=n.div`
646
+ `;function Lt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=qt(),[a,l]=Rt(void 0!==s),c=o||a,{schema:u,uiSchema:m}=z(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Tt,{className:"rounded bg-white shadow-sm",children:[r&&e(Ot,{children:r}),e(d,{schema:u,uiSchema:m,formData:s,onSubmit:({formData:e})=>{c||(l(!0),i(e))},disabled:c,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Pt,{children:t})})]})}const Pt=n.div`
639
647
  display: flex;
640
648
  justify-content: flex-end;
641
649
  border-top: 1px solid var(--bs-border-color);
@@ -664,7 +672,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
664
672
  `,Ot=n.div`
665
673
  color: var(--bs-secondary);
666
674
  line-height: 1.5;
667
- `;function Bt({content:r}){const{resume:n,disabled:i,response:o}=qt(),[s,a]=S(void 0!==o),l=i||s;return t(Ut,{className:"rounded bg-white shadow-sm",children:[r&&e(_t,{children:e(vt,{content:r})}),e(Ht,{children:e(k,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Ut=n.div`
675
+ `;function Bt({content:r}){const{resume:n,disabled:i,response:o}=qt(),[s,a]=Rt(void 0!==o),l=i||s;return t(Ut,{className:"rounded bg-white shadow-sm",children:[r&&e(_t,{children:e(bt,{content:r})}),e(Ht,{children:e(k,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Ut=n.div`
668
676
  display: flex;
669
677
  flex-direction: column;
670
678
  gap: .5rem;
@@ -690,7 +698,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
690
698
  button {
691
699
  padding: .25rem 1.5rem;
692
700
  }
693
- `;function Qt({suspend:t}){const{readonly:r}=he(),{chunkIndex:n,chunk:i,toolIndex:o,tool:s,isLastMessage:a}=function(){const e=$(jt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:l}=Ee(),c=q(e=>{l({chunk:n,tool:o,payload:e})},[]);let d=null;switch(t.type){case"select":d=e(zt,{...t.select});break;case"form":d=e(Lt,{...t.form});break;case"confirm":d=e(Bt,{...t.confirm})}const u=s?.response||i.node?.output;return e(Rt,{resume:c,disabled:r||!!i.error||!a,response:"(Empty)"===u?void 0:u,children:d})}function Jt({value:t,cite:n}){const i=t=>"string"==typeof t?e(vt,{content:t,cite:n}):"image"===t.type?e(Mt,{src:t.image}):"suspend"===t.type?e(Qt,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(A,{children:i(t)},r))}):i(t)}const Kt=({reasoning:r,loading:n})=>{const[i,o]=S(!1);return M(()=>{n||o(!1)},[n]),e(A,{children:e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("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 p-2",children:e(vt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},Wt=D(t=>{const{renderReasoning:r}=he();return r?r({Component:Kt,props:t}):e(Kt,{...t})});class Xt{#t;#o=[];#s=0;constructor(){this.#t=new J}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,t=!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 Vt=new Map;class Yt{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new J}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(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(Vt.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),Vt.delete(this)}start(e,t=!1){Vt.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=Vt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function Gt({text:e,loading:t,loader:r}){const n=F(),[i,o]=S(!1),[s,a]=S(!1),l=F(t),c=async(i=!1)=>{n.current||(n.current=r?new Yt(r):new Xt,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=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]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return M(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),M(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function Zt({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=he(),c=z(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:u,start:m,stop:h}=Gt({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=oe(e(er,{children:e(T,{size:"sm",variant:"light"})}),a.current)),d&&(p=oe(e(er,{children:e(tr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(Et,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?e(tr,{className:"bi bi-volume-down-fill"}):u?e(T,{size:"sm",variant:"primary"}):e(tr,{className:"bi bi-volume-down"}),p]})}const er=n.div`
701
+ `;function Qt({suspend:t}){const{readonly:r,input:n}=he(),{chunkIndex:i,chunk:o,toolIndex:s,tool:a,isLastMessage:l}=function(){const e=$(Nt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),c=F(e=>{n?.resume({chunk:i,tool:s,payload:e})},[n]);let d=null;switch(t.type){case"select":d=e(zt,{...t.select});break;case"form":d=e(Lt,{...t.form});break;case"confirm":d=e(Bt,{...t.confirm})}const u=a?.response||o.node?.output;return e(Ft,{resume:c,disabled:r||!!o.error||!l,response:"(Empty)"===u?void 0:u,children:d})}function Jt({value:t,cite:n}){const i=t=>"string"==typeof t?e(bt,{content:t,cite:n}):"image"===t.type?e($t,{src:t.image}):"suspend"===t.type?e(Qt,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(A,{children:i(t)},r))}):i(t)}const Kt=({reasoning:r,loading:n})=>{const[i,o]=S(!1);return M(()=>{n||o(!1)},[n]),e(A,{children:e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("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 p-2",children:e(bt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},Wt=D(t=>{const{renderReasoning:r}=he();return r?r({Component:Kt,props:t}):e(Kt,{...t})});class Xt{#t;#o=[];#s=0;constructor(){this.#t=new J}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,t=!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 Vt=new Map;class Yt{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new J}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(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(Vt.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),Vt.delete(this)}start(e,t=!1){Vt.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=Vt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function Gt({text:e,loading:t,loader:r}){const n=q(),[i,o]=S(!1),[s,a]=S(!1),l=q(t),c=async(i=!1)=>{n.current||(n.current=r?new Yt(r):new Xt,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=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]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return M(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),M(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function Zt({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=he(),c=z(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:u,start:m,stop:h}=Gt({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=oe(e(er,{children:e(T,{size:"sm",variant:"light"})}),a.current)),d&&(p=oe(e(er,{children:e(tr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(kt,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?e(tr,{className:"bi bi-volume-down-fill"}):u?e(T,{size:"sm",variant:"primary"}):e(tr,{className:"bi bi-volume-down"}),p]})}const er=n.div`
694
702
  position: absolute;
695
703
  top: 0;
696
704
  left: 0;
@@ -720,7 +728,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
720
728
  }
721
729
  `,lr=n.span`
722
730
  display: inline-block;
723
- `;function cr({nodes:r,loading:n}){const[i,o]=S(!1),s=r.some(e=>"error"in e),a=n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(or,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const dr=D(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:u=[],chunks:m,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v}=he(),y=z(()=>m?m.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=ut(t);return r?e+r+"\n":e},""):ut(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=ut(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[m]),x=F(null),k=F(null),N=F(null),j=z(()=>m?.flatMap(e=>e.node?[e.node]:[])||[],[m]),C=c||u.length>0;return t(r,{children:[C&&t(wr,{$reverse:!0,children:[g&&e(vr,{children:e("img",{src:g.avatar})}),e(yr,{}),t(xr,{ref:x,children:[c&&e(vt,{content:c}),d&&e(H,{trigger:"click",container:x,rootClose:!0,placement:"bottom",overlay:e(ur,{body:!0,children:d}),children:e(hr,{children:e(mr,{children:d})})}),u.length>0&&u.map(({name:t,size:r,path:n},i)=>E(n)?e(Mt,{src:`/uploads/${n}`},i):e(gr,{children:e(be,{name:t,url:`/uploads/${n}`,size:r})},i))]})]}),m&&t(wr,{children:[f&&e(vr,{ref:k,children:e("img",{src:f.avatar})}),e(yr,{}),t(xr,{children:[C&&!1!==i&&t(fr,{children:[e(w,{placement:"top",content:y,as:Et,tooltip:!0}),a&&e(Zt,{loading:n.loading,avatarRef:k,contentRef:N,...a}),i?.({Component:Et,message:n,content:y,setMessage:o,messages:v})]}),e(br,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",n.stats.usage]})]})}),t(pr,{ref:N,$deleted:!!h,children:["all"===b&&j.length>0&&e(cr,{loading:p,nodes:j}),m.map((r,n)=>t(A,{children:[r.reasoning&&["stats","all"].includes(b)&&e(Wt,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&e(Ct,{value:{chunkIndex:n,chunk:r,isLastMessage:l},children:e(Jt,{cite:s,value:r.content})}),(r.tools||[]).map((t,i)=>e(Ct,{value:{chunkIndex:n,chunk:r,toolIndex:i,tool:t,isLastMessage:l},children:e(rr,{tool:t,loading:p})},i)),r.error&&e(vt,{content:`[${r.error}]`})]},n))]}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(vt,{content:h.answer})]}),n.loading&&e(dt,{})]})]})]})}),ur=n(Q)`
731
+ `;function cr({nodes:r,loading:n}){const[i,o]=S(!1),s=r.some(e=>"error"in e),a=n?e(T,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(or,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const dr=D(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:u=[],chunks:m,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v}=he(),y=z(()=>m?m.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=dt(t);return r?e+r+"\n":e},""):dt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=dt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[m]),x=q(null),k=q(null),N=q(null),j=z(()=>m?.flatMap(e=>e.node?[e.node]:[])||[],[m]),C=c||u.length>0;return t(r,{children:[C&&t(wr,{$reverse:!0,children:[g&&e(vr,{children:e("img",{src:g.avatar})}),e(yr,{}),t(xr,{ref:x,children:[c&&e(bt,{content:c}),d&&e(H,{trigger:"click",container:x,rootClose:!0,placement:"bottom",overlay:e(ur,{body:!0,children:d}),children:e(hr,{children:e(mr,{children:d})})}),u.length>0&&u.map(({name:t,size:r,path:n},i)=>E(n)?e($t,{src:`/uploads/${n}`},i):e(gr,{children:e(be,{name:t,url:`/uploads/${n}`,size:r})},i))]})]}),m&&t(wr,{children:[f&&e(vr,{ref:k,children:e("img",{src:f.avatar})}),e(yr,{}),t(xr,{children:[C&&!1!==i&&t(fr,{children:[e(w,{placement:"top",content:y,as:kt,tooltip:!0}),a&&e(Zt,{loading:n.loading,avatarRef:k,contentRef:N,...a}),i?.({Component:kt,message:n,content:y,setMessage:o,messages:v})]}),e(br,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",n.stats.usage]})]})}),t(pr,{ref:N,$deleted:!!h,children:["all"===b&&j.length>0&&e(cr,{loading:p,nodes:j}),m.map((r,n)=>t(A,{children:[r.reasoning&&["stats","all"].includes(b)&&e(Wt,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&e(jt,{value:{chunkIndex:n,chunk:r,isLastMessage:l},children:e(Jt,{cite:s,value:r.content})}),(r.tools||[]).map((t,i)=>e(jt,{value:{chunkIndex:n,chunk:r,toolIndex:i,tool:t,isLastMessage:l},children:e(rr,{tool:t,loading:p})},i)),r.error&&e(bt,{content:`[${r.error}]`})]},n))]}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(bt,{content:h.answer})]}),n.loading&&e(ct,{})]})]})]})}),ur=n(Q)`
724
732
  max-width: calc(100% - .875rem * 2);
725
733
  width: calc(100% - .875rem * 2);
726
734
  font-size: 1rem;
@@ -826,7 +834,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
826
834
  background: rgba(var(--bs-primary-rgb), 0.1);
827
835
  }
828
836
  `};
829
- `;function kr(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:u,suggestions:m,conversationId:h}=he(),p=F(r.loaded),g=q(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=F(null),{height:b}=se({ref:f});M(()=>{(u||!p.current)&&c.length>0&&(u&&(p.current=!0),g())},[b,u,p,c]),M(()=>{m.length>0&&g()},[m]),M(()=>{p.current=r.loaded},[h]),M(()=>{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 t(Er,{ref:f,children:[0===v.length&&n,v.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===v.length-1};return a?a({Component:dr,props:n},r):e(dr,{...n},r)}),m.length>0&&e(Nr,{children:m.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Er=n.div`
837
+ `;function kr(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:u,suggestions:m,conversationId:h}=he(),p=q(r.loaded),g=F(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=q(null),{height:b}=se({ref:f});M(()=>{(u||!p.current)&&c.length>0&&(u&&(p.current=!0),g())},[b,u,p,c]),M(()=>{m.length>0&&g()},[m]),M(()=>{p.current=r.loaded},[h]),M(()=>{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 t(Er,{ref:f,children:[0===v.length&&n,v.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===v.length-1};return a?e(A,{children:a({Component:dr,props:n})},r):e(dr,{...n},r)}),m.length>0&&e(Nr,{children:m.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Er=n.div`
830
838
  display: flex;
831
839
  flex-direction: column;
832
840
  flex: 1;
@@ -847,7 +855,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
847
855
  background: var(--bs-secondary-bg-subtle);
848
856
  }
849
857
  }
850
- `,jr=D(R(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:u,conversation:m,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:b,renderReasoning:y,messages:w,request:k,onReset:E,transformMessages:j=it},C)=>{const $=q(e=>{const t=[];if(u&&!1!==u.enable){const e=ot(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(j(e.messages||[])):w?t.concat(j(w)):t},[u]),[M,R]=S(m?.id),[A,D]=S(),[L,P]=v(()=>$(m)),[T,O]=S(!1),B=F(null),[U,_]=S([]),H=q(e=>{R(e?.id),P($(e)),_([]),O(!1),E?.(e)},[T,$,E]);return I(C,()=>({reset:H}),[H]),e(pe,{request:z(()=>k?"string"==typeof k?N.create({baseURL:k}):k:N,[k]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:M,setConversationId:R,input:A,setInput:D,messages:L,setMessages:P,suggestions:U,setSuggestions:_,loading:T,setLoading:O,renderFileItem:f,reset:H,readonly:!o,renderToolContent:b,renderReasoning:y,children:e($r,{className:r,children:t(x,{children:[e(Cr,{ref:B,children:e(kr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&e(We,{...o,scrollRef:B})]})})})}),W),Cr=n.div`
858
+ `,jr=D(R(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:u,conversation:m,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:b,renderReasoning:y,messages:w,request:k,onReset:E,transformMessages:j=nt},C)=>{const $=F(e=>{const t=[];if(u&&!1!==u.enable){const e=it(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(j(e.messages||[])):w?t.concat(j(w)):t},[u]),[M,R]=S(m?.id),[A,D]=S(),[L,P]=v(()=>$(m)),[T,O]=S(!1),B=q(null),[U,_]=S([]),H=F(e=>{R(e?.id),P($(e)),_([]),O(!1),E?.(e)},[T,$,E]);return I(C,()=>({reset:H}),[H]),e(pe,{request:z(()=>k?"string"==typeof k?N.create({baseURL:k}):k:N,[k]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:M,setConversationId:R,input:A,setInput:D,messages:L,setMessages:P,suggestions:U,setSuggestions:_,loading:T,setLoading:O,renderFileItem:f,reset:H,readonly:!o,renderToolContent:b,renderReasoning:y,children:e($r,{className:r,children:t(x,{children:[e(Cr,{ref:B,children:e(kr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&e(Ke,{...o,scrollRef:B})]})})})}),W),Cr=n.div`
851
859
  display: flex;
852
860
  flex-direction: column;
853
861
  flex: 1;
@@ -859,4 +867,4 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
859
867
  flex-direction: column;
860
868
  height: 100%;
861
869
  position: relative;
862
- `;async function Mr(e){const t=await ae().use(ce).use(Z).use(ee).use(te).use(de).use(le).process(e);return String(t)}export{Fe as ActionButton,Je as EditableInput,be as FileItem,vt as Markdown,jr as MessageBox,Ne as VariableForm,ue as isToolMessage,Mr as md2html,ot as pickQuestions,he as useMessageContext,Gt as useSynthesis};
870
+ `;async function Mr(e){const t=await ae().use(ce).use(Z).use(ee).use(te).use(de).use(le).process(e);return String(t)}export{Se as ActionButton,Qe as EditableInput,be as FileItem,bt as Markdown,jr as MessageBox,Ee as VariableForm,ue as isToolMessage,Mr as md2html,it as pickQuestions,he as useMessageContext,Gt as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "module": "es/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@babel/runtime": "^7.11.2",
13
13
  "@breezystack/lamejs": "^1.2.7",
14
- "@topthink/components": "1.2.4",
14
+ "@topthink/components": "1.2.5",
15
15
  "@types/hast": "^3.0.4",
16
16
  "@types/mdast": "^4.0.4",
17
17
  "eventemitter3": "^5.0.1",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
65
65
  "license": "MIT",
66
- "gitHead": "5b926446ee583f2265247e1b937fc2fac53519a5",
66
+ "gitHead": "aba026d4f1183c1633629b4c54f684b2093a2754",
67
67
  "scripts": {
68
68
  "prebuild": "rimraf es types",
69
69
  "build": "rollup -c --environment NODE_ENV:production",
@@ -36,6 +36,7 @@ export interface MessageBoxProps {
36
36
  nodeIconResolver?: (type: string) => ReactNode;
37
37
  input?: {
38
38
  disabled?: boolean;
39
+ supportStop?: boolean;
39
40
  fileTypes?: string[];
40
41
  speech?: {
41
42
  model?: string;
@@ -63,7 +64,7 @@ export interface MessageBoxProps {
63
64
  renderItem?: (props: {
64
65
  Component: ComponentType<MessageItemProps>;
65
66
  props: MessageItemProps;
66
- }, index: number) => ReactNode;
67
+ }) => ReactNode;
67
68
  renderFileItem?: (props: {
68
69
  Component: ComponentType<FileItemProps>;
69
70
  props: FileItemProps;
@@ -1,4 +1,4 @@
1
- import { ForwardRefExoticComponent, MutableRefObject, RefAttributes, ReactNode } from 'react';
1
+ import { ForwardRefExoticComponent, MutableRefObject, ReactNode, RefAttributes } from 'react';
2
2
  import { Input, Variable } from '../../../types';
3
3
  import { EditableInputProps, EditableInputRef } from './editable-input';
4
4
  export type EditableInputComponent = ForwardRefExoticComponent<EditableInputProps & RefAttributes<EditableInputRef>>;
@@ -8,6 +8,7 @@ export type RenderEditableInput = (options: {
8
8
  }) => ReactNode;
9
9
  export interface Props {
10
10
  suggestion?: boolean;
11
+ supportStop?: boolean;
11
12
  variables?: {
12
13
  config: Variable[];
13
14
  values?: Record<string, string>;
@@ -1,3 +1,6 @@
1
1
  import { ButtonHTMLAttributes, ComponentType, DetailedHTMLProps } from 'react';
2
- declare const InputButton: ComponentType<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>>;
2
+ type InputButtonProps = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> & {
3
+ $fill?: boolean;
4
+ };
5
+ declare const InputButton: ComponentType<InputButtonProps>;
3
6
  export default InputButton;
@@ -1,6 +1,10 @@
1
- import { Message } from '../../../types';
2
- export default function useChat(): {
3
- send: (params: string | import("../../..").SendParams, files?: Message["files"], variables?: Message["variables"]) => Promise<void>;
1
+ interface UseChatOptions {
2
+ supportStop?: boolean;
3
+ }
4
+ export default function useChat(options?: UseChatOptions): {
5
+ send: (params: string | import("../../..").SendParams, files?: import("../../..").Message["files"], variables?: import("../../..").Message["variables"]) => Promise<void>;
4
6
  resume: (params: import("../../..").ResumeParams) => Promise<void>;
5
7
  suggest: () => Promise<void>;
8
+ stop: () => Promise<void>;
6
9
  };
10
+ export {};
@@ -14,7 +14,7 @@ interface Props {
14
14
  renderItem?: (props: {
15
15
  Component: typeof MessageItem;
16
16
  props: MessageItemProps;
17
- }, index: number) => ReactNode;
17
+ }) => ReactNode;
18
18
  scrollRef: MutableRefObject<HTMLDivElement | null>;
19
19
  }
20
20
  export default function List(props: Props): import("react/jsx-runtime").JSX.Element;
@@ -6,4 +6,5 @@ interface ContextType {
6
6
  }
7
7
  export declare function useSuspend(): ContextType;
8
8
  export declare function Provider({ children, ...props }: PropsWithChildren<ContextType>): import("react/jsx-runtime").JSX.Element;
9
+ export declare function useSyncedState<T>(value: T): readonly [T, import("react").Dispatch<import("react").SetStateAction<T>>];
9
10
  export {};
package/types/types.d.ts CHANGED
@@ -98,6 +98,7 @@ export interface Message {
98
98
  question: string;
99
99
  answer: string;
100
100
  };
101
+ status?: number;
101
102
  }
102
103
  export interface Variable {
103
104
  key: string;
@@ -131,6 +132,7 @@ export interface ConversationMessage {
131
132
  question: string;
132
133
  answer: string;
133
134
  };
135
+ status?: number;
134
136
  [key: string]: any;
135
137
  }
136
138
  export interface SendParams {