@topthink/chat 1.2.10 → 1.3.1

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{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,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 S,useState as M,useRef as F,useCallback as R,forwardRef as q,useMemo as z,useImperativeHandle as A,Fragment as I,memo as D,Component as L}from"react";import*as P from"path";import T from"path";import{Spinner as O,Badge as B,Dropdown as U,FormControl as _,CloseButton as H,OverlayTrigger as Q,Popover as J}from"react-bootstrap";import K from"eventemitter3";import W from"react-textarea-autosize";import X from"lodash/isEqual";import{toString as V}from"hast-util-to-string";import Y from"react-markdown";import"katex/dist/katex.min.css";import G from"rehype-highlight";import Z from"rehype-katex";import ee from"remark-breaks";import te from"remark-gfm";import re from"remark-math";import{codes as ne,types as ie}from"micromark-util-symbol";import{markdownLineEnding as oe}from"micromark-util-character";import{createPortal as se}from"react-dom";import ae from"use-resize-observer";import{unified as le}from"unified";import ce from"rehype-stringify";import de from"remark-parse";import ue from"remark-rehype";function me(e,t){return e.name===t}const he=function({ext:e}){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}},[e]);return r?t("img",{width:30,height:30,src:r}):null};function pe({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const u=T.extname(n).substring(1),m=e(ve,{className:r,$error:!!l,onClick:d,children:[e(be,{children:[t(he,{ext:u}),a&&t(O,{variant:"primary"})]}),e(fe,{children:[t("h4",{children:n}),i>0&&t("p",{children:o(i,1)})]}),c&&t(ge,{onClick:e=>{e.preventDefault(),c()},children:t("i",{className:"bi bi-trash3"})})]});return l?t(s,{placement:"top",tooltip:l,children:m}):m}const ge=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,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 $,useRef as M,useCallback as S,useEffect as R,useState as F,forwardRef as q,useMemo as z,useImperativeHandle as A,Fragment as I,memo as D,Component as L}from"react";import*as P from"path";import T from"path";import{Spinner as O,Badge as B,Dropdown as U,FormControl as _,CloseButton as H,OverlayTrigger as Q,Popover as J}from"react-bootstrap";import K from"eventemitter3";import W from"react-textarea-autosize";import X from"lodash/isEqual";import{toString as V}from"hast-util-to-string";import Y from"react-markdown";import"katex/dist/katex.min.css";import G from"rehype-highlight";import Z from"rehype-katex";import ee from"remark-breaks";import te from"remark-gfm";import re from"remark-math";import{codes as ne,types as ie}from"micromark-util-symbol";import{markdownLineEnding as oe}from"micromark-util-character";import{createPortal as se}from"react-dom";import ae from"use-resize-observer";import{unified as le}from"unified";import ce from"rehype-stringify";import de from"remark-parse";import ue from"remark-rehype";function me(e,t){return e.name===t}const he=function({ext:e}){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}},[e]);return r?t("img",{width:30,height:30,src:r}):null};function pe({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const u=T.extname(n).substring(1),m=e(ve,{className:r,$error:!!l,onClick:d,children:[e(be,{children:[t(he,{ext:u}),a&&t(O,{variant:"primary"})]}),e(fe,{children:[t("h4",{children:n}),i>0&&t("p",{children:o(i,1)})]}),c&&t(ge,{onClick:e=>{e.preventDefault(),c()},children:t("i",{className:"bi bi-trash3"})})]});return l?t(s,{placement:"top",tooltip:l,children:m}):m}const ge=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -65,7 +65,7 @@ import{jsxs as e,jsx 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
- `,ye=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],xe=C(null);function we(e){const t=$(xe);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return S(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function ke({children:e,...r}){const[n,i]=M({});return t(xe.Provider,{value:{...r,handles:n,setHandles:i},children:e})}function Ee({variables:e,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return e.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)}),t(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`
68
+ `,ye=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],xe=C(null);function we(){const e=$(xe);if(!e)throw new Error("useContext must be used within a Provider");return e}function ke({children:e,...r}){return t(xe.Provider,{value:r,children:e})}function Ee({variables:e,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return e.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)}),t(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;
@@ -96,12 +96,12 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
96
96
  }
97
97
  `};
98
98
 
99
- `;let je=class{#e;#t;constructor(){this.#t=new K}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 K}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=q(({onResult:r,model:n="builtin"},i)=>{const{request:o}=we(),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]=M(!1),[o,s]=M(!1);return S(()=>()=>{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 A(i,()=>({start:l,stop:c}),[l,c]),t(s,{tooltip:d?"停止":"语音输入",placement:"top",children:e(Ne,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[u&&t(Se,{animation:"border",variant:"primary",size:"sm"}),t("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Se=n(O)`
99
+ `;let je=class{#e;#t;constructor(){this.#t=new K}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 K}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=q(({onResult:r,model:n="builtin"},i)=>{const{request:o}=we(),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=M(),[n,i]=F(!1),[o,s]=F(!1);return R(()=>()=>{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 A(i,()=>({start:l,stop:c}),[l,c]),t(s,{tooltip:d?"停止":"语音输入",placement:"top",children:e(Ne,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[u&&t(Me,{animation:"border",variant:"primary",size:"sm"}),t("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Me=n(O)`
100
100
  position: absolute;
101
101
  --bs-spinner-width: .75rem;
102
102
  --bs-spinner-height: .75rem;
103
103
  --bs-spinner-border-width: 0.1em;
104
- `,Me=q(({className:e,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=t(Fe,{ref:c,className:e,onClick:a,onMouseDown:l,$size:n,children:r});return i?t(s,{tooltip:i,placement:o,children:d}):d}),Fe=n.div`
104
+ `,Se=q(({className:e,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=t(Re,{ref:c,className:e,onClick:a,onMouseDown:l,$size:n,children:r});return i?t(s,{tooltip:i,placement:o,children:d}):d}),Re=n.div`
105
105
  width: 2rem;
106
106
  height: 2rem;
107
107
  align-items: center;
@@ -125,7 +125,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
125
125
  &:hover {
126
126
  background-color: var(--bs-secondary-bg-subtle);
127
127
  }
128
- `;function Re(){const{request:n,reset:i,conversationId:o}=we(),[s,a]=M(!1),[l,c]=M(""),[d,u]=M(""),m=h(e=>{u(e)},500);return S(()=>{m(l)},[l]),e(r,{children:[t(Me,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:t("i",{className:"bi bi-clock-history"})}),t(p,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:De,header:e(r,{children:[t("span",{children:"聊天历史记录"}),t(Le,{children:t(_,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:qe,children:s&&t(Ie,{children:t(Ae,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?e(r,{children:[s.map((s,l)=>{const d=o===s.id;return e(I,{children:[l>0&&t("hr",{className:"mx-2 my-2"}),e(ze,{children:[d&&t(B,{bg:"secondary",children:"当前"}),t("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),e(U,{align:"end",children:[t(U.Toggle,{size:"sm",className:"no-caret",as:Me,children:t("i",{className:"bi bi-three-dots-vertical"})}),e(U.Menu,{children:[t(g,{buttonProps:{as:U.Item},text:e(r,{children:[t("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)})}}),e(f,{as:U.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)}),d&&i()},children:[t("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)}),l&&t(b,{wrap:!0})]}):t("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const qe=n.div`
128
+ `;function Fe(){const{request:n,reset:i,conversationId:o}=we(),[s,a]=F(!1),[l,c]=F(""),[d,u]=F(""),m=h(e=>{u(e)},500);return R(()=>{m(l)},[l]),e(r,{children:[t(Se,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:t("i",{className:"bi bi-clock-history"})}),t(p,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:De,header:e(r,{children:[t("span",{children:"聊天历史记录"}),t(Le,{children:t(_,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:qe,children:s&&t(Ie,{children:t(Ae,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?e(r,{children:[s.map((s,l)=>{const d=o===s.id;return e(I,{children:[l>0&&t("hr",{className:"mx-2 my-2"}),e(ze,{children:[d&&t(B,{bg:"secondary",children:"当前"}),t("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),e(U,{align:"end",children:[t(U.Toggle,{size:"sm",className:"no-caret",as:Se,children:t("i",{className:"bi bi-three-dots-vertical"})}),e(U.Menu,{children:[t(g,{buttonProps:{as:U.Item},text:e(r,{children:[t("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)})}}),e(f,{as:U.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)}),d&&i()},children:[t("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)}),l&&t(b,{wrap:!0})]}):t("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const qe=n.div`
129
129
  padding: 0;
130
130
  overflow: hidden;
131
131
  `,ze=n.div`
@@ -165,7 +165,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
165
165
  display: flex;
166
166
  align-items: center;
167
167
  gap: 0.5rem;
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:e}=we();return t(Me,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(Oe,{})})}function Ue({children:r,actions:n}){return e(He,{children:[r,e(_e,{children:[n,t(Re,{}),t(Be,{})]})]})}const _e=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({onClick:e}){const{reset:r}=we();return t(Se,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:()=>e?.()??r(),children:t(Oe,{})})}function Ue({children:n,actions:i}){const o=e(r,{children:[t(Fe,{}),t(Be,{})]}),s="function"==typeof i?i({History:Fe,Reset:Be}):e(r,{children:[i,o]});return e(He,{children:[n,t(_e,{children:s})]})}const _e=n.div`
169
169
  display: flex;
170
170
  gap: .25rem;
171
171
  margin-left: auto;
@@ -173,7 +173,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
173
173
  margin-bottom: .5rem;
174
174
  display: flex;
175
175
  padding: 0 .125rem;
176
- `;var Qe=q(function({readonly:e,autoFocus:r,placeholder:n,minRows:i,maxRows:o,onSubmit:s,onFocusedChange:a,onQueryChange:l,onPaste:c},d){const u=F(null),[m,h]=M(""),p=R(()=>{const e=u.current;if(!e)return;e.focus();const t=e.value.length;e.setSelectionRange(t,t)},[]),g=R(e=>{const t="string"==typeof e?e:e(m);h(t),l?.(t.trim()),requestAnimationFrame(()=>{p()})},[m,l,p]);return A(d,()=>({setContent:g,focus(){p()}}),[g,p]),t(Je,{ref:u,value:m,minRows:i,maxRows:o,readOnly:e,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(W)`
176
+ `;var Qe=q(function({readonly:e,autoFocus:r,placeholder:n,minRows:i,maxRows:o,onSubmit:s,onFocusedChange:a,onQueryChange:l,onPaste:c},d){const u=M(null),[m,h]=F(""),p=S(()=>{const e=u.current;if(!e)return;e.focus();const t=e.value.length;e.setSelectionRange(t,t)},[]),g=S(e=>{const t="string"==typeof e?e:e(m);h(t),l?.(t.trim()),requestAnimationFrame(()=>{p()})},[m,l,p]);return A(d,()=>({setContent:g,focus(){p()}}),[g,p]),t(Je,{ref:u,value:m,minRows:i,maxRows:o,readOnly:e,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(W)`
177
177
  min-height: calc(1.5em + 1rem);
178
178
  width: 100%;
179
179
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
@@ -183,7 +183,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
183
183
  flex: 1;
184
184
  line-height: 1.5;
185
185
  background: transparent;
186
- `;var Ke=q(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=F(null),N=F(null),j=F(null),[C,$]=M(""),[q,I]=M(""),[D,L]=v([]),[T,O]=M(!1),B=n&&n.length>0?n:ye,{send:U,resume:_,stop:Q,suggest:J}=function(e){const{setMessages:t,setSuggestions:r,setLoading:n,conversationId:i,setConversationId:o,request:s,handles:a,messages:d}=we(),u=!0===e?.supportStop,m=F(null),h=F(),p=F(i),g=()=>(m.current&&m.current.abort(),m.current=new AbortController,m.current.signal),{onComplete:f,onEvent:b}=a,v=R(e=>{const r=(e,t)=>{Object.entries(t).forEach(([t,n])=>{if("string"!=typeof n)if(!n||"object"!=typeof n||Array.isArray(n))e[t]=n;else if("index"in n){const{index:i,...o}=n;Array.isArray(e[t])||(e[t]=[]),e[t][i]||(e[t][i]={}),r(e[t][i],o)}else e[t]=n;else e[t]="string"==typeof e[t]?e[t]+n:n})};if(e.data)if("[DONE]"!=e.data)try{const n=JSON.parse(e.data);n.conversation?(p.current=n.conversation,o(n.conversation)):n.event?b?.(n.event):t(e=>{const t=e[e.length-1];if(n.chunks){if(t.chunks){const e=n.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),n.chunks.error)t.chunks[e].error=n.chunks.error;else if(n.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const{index:i,...o}=n.chunks.tools;t.chunks[e].tools[i]||(t.chunks[e].tools[i]={name:"",title:"",arguments:""}),r(t.chunks[e].tools[i],o)}else if(n.chunks.reasoning)t.chunks[e].reasoning+=n.chunks.reasoning;else if(n.chunks.content)if("object"==typeof n.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const r=n.chunks.content.index,i=n.chunks.content.value;"string"==typeof i?(t.chunks[e].content[r]||(t.chunks[e].content[r]=""),t.chunks[e].content[r]+=i):t.chunks[e].content[r]=i}else t.chunks[e].content+=n.chunks.content;else n.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...n.chunks.node})}}else n.stats?t.stats=n.stats:n.id&&(t.id=n.id)})}catch(e){console.error(e)}else t(e=>{e[e.length-1].loading=!1})},[a]),y=R(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=R(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=R(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=R(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=R(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=R(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 S(()=>(j(),()=>{m.current&&m.current.abort()}),[]),S(()=>{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}=we(K),[G,Z]=M();S(()=>{const e=W.filter(e=>!!e.query);Z(e.at(-1)?.variables)},[W]),S(()=>{!n&&D.length>0&&L([])},[n]),S(()=>{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=R(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(P.extname(e.name)))&&!(e.size>20971520)).slice(0,6-D.length);return 0!==t.length&&(L(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});L(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=c(t)?t.message:"unknown error";L(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}}),!0)},[D.length,B,V,L]),te=R(({target:e})=>{e.files&&ee(Array.from(e.files)),e.value=""},[ee]),re=R(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=R(()=>{if(C||ne.length>0){const e={query:C,files:ne};a&&(e.variables={...G,...a.values}),q&&(e.quote=q),U(e),j.current?.setContent(""),I(""),L([]),N.current?.stop(!0)}},[C,ne,a,G,q]),oe=z(()=>({setQuery(e){j.current?.setContent(e)},setQuote:I,send:U,resume:_,focus(){j.current?.focus()}}),[I,U,_]);if(S(()=>{Y(oe)},[oe]),A(k,()=>oe,[oe]),a){const e=a.config.filter(e=>!(e.key in(a.values||{}))),r=(t,r=!1)=>!!t&&e.every(e=>{const n=!e.required||t?.[e.key];return!n&&r&&u.error("请完善必填信息"),n});if(e.length>0&&!r(G))return t(Xe,{children:t(We,{children:t(Ee,{values:G,variables:e,onSubmit:({formData:e})=>{if(r(e,!0))return Z(e),!0}})})})}return e(rt,{children:[h&&t(Ue,{actions:p,children:h}),e(tt,{$focused:T&&!X,children:[D.length>0&&t(Ye,{children:D.map(({file:e,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return t(Ve,{name:e.name,size:e.size,error:r,loading:o,onRemove:()=>{L(t=>{const r=t.findIndex(t=>t.file===e);-1!==r&&t.splice(r,1)})}},i)})}),!!q&&e(et,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:q}),t(H,{onClick:()=>I("")})]}),e(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}})||t(Qe,{ref:j,readonly:X||g,autoFocus:f,placeholder:y,minRows:d,maxRows:m,onSubmit:ie,onFocusedChange:O,onQueryChange:$,onPaste:re}),e(Ze,{children:[n&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(Ne,{disabled:D.length>=6,onClick:()=>E.current?.click(),children:[t("input",{onChange:te,multiple:!0,accept:B.join(","),ref:E,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&t($e,{ref:N,model:i.model,onResult:e=>{j.current?.setContent(t=>t+e+" ")}}),t(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:t("i",X&&x?{className:"bi bi-square-fill fs-7"}:{className:"bi bi-send-fill"})})]})]})]})]})});const We=n.div`
186
+ `;var Ke=q(function({fileTypes:r,speech:n,scrollRef:i,variables:o,minRows:a=1,maxRows:d=5,toolbar:m,toolbarActions:h,disabled:p,autoFocus:g,renderEditableInput:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送",supportStop:y=!1,onEvent:x,onNewConversation:w},k){const E=M(null),N=M(null),j=M(null),[C,$]=F(""),[q,I]=F(""),[D,L]=v([]),[T,O]=F(!1),B=r&&r.length>0?r:ye,U=S(()=>{requestAnimationFrame(()=>{j.current?.focus()})},[]),{send:_,resume:Q,stop:J}=function(e){const{setMessages:t,setSuggestions:r,setLoading:n,conversationId:i,setConversationId:o,request:s,messages:a}=we(),d=!0===e?.supportStop,{onEvent:u,onNewConversation:m,onComplete:h}=e??{},p=M(null),g=M(),f=M(i),b=()=>(p.current&&p.current.abort(),p.current=new AbortController,p.current.signal),v=S(e=>{const r=(e,t)=>{Object.entries(t).forEach(([t,n])=>{if("string"!=typeof n)if(!n||"object"!=typeof n||Array.isArray(n))e[t]=n;else if("index"in n){const{index:i,...o}=n;Array.isArray(e[t])||(e[t]=[]),e[t][i]||(e[t][i]={}),r(e[t][i],o)}else e[t]=n;else e[t]="string"==typeof e[t]?e[t]+n:n})};if(e.data)if("[DONE]"!=e.data)try{const n=JSON.parse(e.data);n.conversation?(f.current=n.conversation,o(n.conversation)):n.event?u?.(n.event):t(e=>{const t=e[e.length-1];if(n.chunks){if(t.chunks){const e=n.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),n.chunks.error)t.chunks[e].error=n.chunks.error;else if(n.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const{index:i,...o}=n.chunks.tools;t.chunks[e].tools[i]||(t.chunks[e].tools[i]={name:"",title:"",arguments:""}),r(t.chunks[e].tools[i],o)}else if(n.chunks.reasoning)t.chunks[e].reasoning+=n.chunks.reasoning;else if(n.chunks.content)if("object"==typeof n.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const r=n.chunks.content.index,i=n.chunks.content.value;"string"==typeof i?(t.chunks[e].content[r]||(t.chunks[e].content[r]=""),t.chunks[e].content[r]+=i):t.chunks[e].content[r]=i}else t.chunks[e].content+=n.chunks.content;else n.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...n.chunks.node})}}else n.stats?t.stats=n.stats:n.id&&(t.id=n.id)})}catch(e){console.error(e)}else t(e=>{e[e.length-1].loading=!1})},[u]),y=S(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=S(async e=>{g.current=e;try{const r=b();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{p.current=null,g.current=void 0}n(!1),h?.()},[s,u,m,h]),w=S(async(e,...i)=>{"string"==typeof e&&(e={query:e,...i});const{query:o,files:a=[],variables:l={},quote:c}=e;let d=null,u=null;if(o||a.length>0){const e=b();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:f.current},onMessage:v,signal:e};const r=await s(t);d=r.message??null,u=r.conversation??null}catch(e){y(e)}finally{p.current=null}if(d){let e=!1;u&&!f.current&&(e=m?.(u)??!1),e||await x(d.id)}else n(!1),h?.()}},[s,u,m,h]),k=S(async e=>{let r=null;try{const i=b();n(!0),t(e=>{e[e.length-1].loading=!0});let o={url:"resume",method:"post",data:{conversation:f.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{p.current=null}r?await x(r.id):(n(!1),h?.())},[s,u,m,h]),E=S(async()=>{if(d)if(g.current)try{await s({url:"stop",method:"post",data:{id:g.current}})}catch{}else p.current?.abort()},[s,d]),N=()=>{const e=a[a.length-1];e&&e.id&&2===e.status&&x(e.id)};return R(()=>(N(),()=>{p.current&&p.current.abort()}),[]),R(()=>{i!=f.current&&(f.current=i,p.current&&p.current.abort(),N())},[i]),{send:w,resume:k,stop:E}}({supportStop:y,onEvent:x,onNewConversation:w,onComplete:U}),{messages:K,loading:W,request:X,setInput:V}=we(),[Y,G]=F();R(()=>{const e=K.filter(e=>!!e.query);G(e.at(-1)?.variables)},[K]),R(()=>{!r&&D.length>0&&L([])},[r]),R(()=>{const e=i.current;if(e&&_){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};o&&(t.variables={...Y,...o.values}),_(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[o,Y]);const Z=S(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(P.extname(e.name)))&&!(e.size>20971520)).slice(0,6-D.length);return 0!==t.length&&(L(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await X({method:"POST",url:"/upload",data:t});L(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=c(t)?t.message:"unknown error";L(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}}),!0)},[D.length,B,X,L]),ee=S(({target:e})=>{e.files&&Z(Array.from(e.files)),e.value=""},[Z]),te=S(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&&Z(n)&&e.preventDefault()},[Z]),re=D.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),ne=S(()=>{if(C||re.length>0){const e={query:C,files:re};o&&(e.variables={...Y,...o.values}),q&&(e.quote=q),_(e),j.current?.setContent(""),I(""),L([]),N.current?.stop(!0)}},[C,re,o,Y,q]),ie=z(()=>({setQuery(e){j.current?.setContent(e)},setQuote:I,send:_,resume:Q,focus(){j.current?.focus()}}),[I,_,Q]);if(R(()=>{V(ie)},[ie]),A(k,()=>ie,[ie]),o){const e=o.config.filter(e=>!(e.key in(o.values||{}))),r=(t,r=!1)=>!!t&&e.every(e=>{const n=!e.required||t?.[e.key];return!n&&r&&u.error("请完善必填信息"),n});if(e.length>0&&!r(Y))return t(Xe,{children:t(We,{children:t(Ee,{values:Y,variables:e,onSubmit:({formData:e})=>{if(r(e,!0))return G(e),!0}})})})}return e(rt,{children:[m&&t(Ue,{actions:h,children:m}),e(tt,{$focused:T&&!W,children:[D.length>0&&t(Ye,{children:D.map(({file:e,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return t(Ve,{name:e.name,size:e.size,error:r,loading:o,onRemove:()=>{L(t=>{const r=t.findIndex(t=>t.file===e);-1!==r&&t.splice(r,1)})}},i)})}),!!q&&e(et,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:q}),t(H,{onClick:()=>I("")})]}),e(Ge,{children:[f?.({Component:Qe,props:{ref:j,readonly:W||p,autoFocus:g,placeholder:b,minRows:a,maxRows:d,onSubmit:ne,onFocusedChange:O,onQueryChange:$,onPaste:te}})||t(Qe,{ref:j,readonly:W||p,autoFocus:g,placeholder:b,minRows:a,maxRows:d,onSubmit:ne,onFocusedChange:O,onQueryChange:$,onPaste:te}),e(Ze,{children:[r&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(Ne,{disabled:D.length>=6,onClick:()=>E.current?.click(),children:[t("input",{onChange:ee,multiple:!0,accept:B.join(","),ref:E,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),n&&t($e,{ref:N,model:n.model,onResult:e=>{j.current?.setContent(t=>t+e+" ")}}),t(Ne,{$fill:W&&y,className:W&&y?"text-danger":"text-primary",disabled:!C&&0===re.length&&!W||W&&!y,onClick:e=>{e.preventDefault(),W&&y?J():ne()},children:t("i",W&&y?{className:"bi bi-square-fill fs-7"}:{className:"bi bi-send-fill"})})]})]})]})]})});const We=n.div`
187
187
  border-radius: var(--bs-border-radius-lg);
188
188
  box-shadow: var(--bs-box-shadow-sm);
189
189
  margin: 1rem;
@@ -246,7 +246,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
246
246
  box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
247
247
  `,rt=n.div`
248
248
  margin: 0 1rem 1rem;
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!==ne.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(ie.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===ne.rightSquareBracket?(e.exit(ie.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==ne.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):oe(n)||n===ne.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==ne.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},mt=function(){const e=this.data();e.micromarkExtensions.push({text:{[ne.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]=M(!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]);S(()=>{s&&o(s)},[s]);const a=z(()=>V(n),[n]);return e(xt,{children:[e(yt,{children:[!i&&t(w,{tooltip:!1,as:vt,content:a}),s&&i&&t(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&&t(vt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?t("div",{dangerouslySetInnerHTML:{__html:a}}):t("pre",{children:r})]})},a:({node:e,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return t("a",{...n,href:r,target:i})},img:({node:e,...r})=>t(ht,{...r})},gt=[[re,{singleDollarTextMath:!1}],te,ee],ft=[Z,[G,{detect:!1,ignoreMissing:!0}]],bt=D(q(({content:e,components:r,cite:n},i)=>{e=e.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 t(wt,{ref:i,children:t(Y,{remarkPlugins:s,rehypePlugins:ft,components:o,children:e})})}),X),vt=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!==ne.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(ie.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===ne.rightSquareBracket?(e.exit(ie.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==ne.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):oe(n)||n===ne.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==ne.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},mt=function(){const e=this.data();e.micromarkExtensions.push({text:{[ne.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]=F(!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]);R(()=>{s&&o(s)},[s]);const a=z(()=>V(n),[n]);return e(xt,{children:[e(yt,{children:[!i&&t(w,{tooltip:!1,as:vt,content:a}),s&&i&&t(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&&t(vt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?t("div",{dangerouslySetInnerHTML:{__html:a}}):t("pre",{children:r})]})},a:({node:e,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return t("a",{...n,href:r,target:i})},img:({node:e,...r})=>t(ht,{...r})},gt=[[re,{singleDollarTextMath:!1}],te,ee],ft=[Z,[G,{detect:!1,ignoreMissing:!0}]],bt=D(q(({content:e,components:r,cite:n},i)=>{e=e.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 t(wt,{ref:i,children:t(Y,{remarkPlugins:s,rehypePlugins:ft,components:o,children:e})})}),X),vt=n.div`
250
250
  cursor: pointer;
251
251
  padding: 2px 10px;
252
252
  background-color: #303030;
@@ -583,7 +583,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
583
583
  `}
584
584
 
585
585
  }
586
- `,Nt=C(null);var jt=Nt.Provider;const Ct=x.Image;function $t({src:e,...r}){const{imageResolver:n}=we();return n&&e&&(e=n(e)),t(St,{children:t(Ct,{src:e,...r})},e)}const St=n.div`
586
+ `,Nt=C(null);var jt=Nt.Provider;const Ct=x.Image;function $t({src:e,...r}){const{imageResolver:n}=we();return n&&e&&(e=n(e)),t(Mt,{children:t(Ct,{src:e,...r})},e)}const Mt=n.div`
587
587
  margin-bottom: .5rem;
588
588
  margin-top: .5rem;
589
589
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -608,7 +608,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
608
608
  max-height: 100%;
609
609
  max-width: 100%;
610
610
  }
611
- `,Mt=C(null);function Ft(){const e=$(Mt);if(!e)throw new Error("useContext must be used within a Provider");return e}function Rt({children:e,...r}){return t(Mt.Provider,{value:r,children:e})}function qt(e){const[t,r]=M(e);return S(()=>{r(e)},[e]),[t,r]}function zt({description:r,options:n}){const{resume:i,disabled:o,response:s}=Ft(),[a,l]=qt(s?.result),c=o||void 0!==a;return e(At,{children:[r&&t(It,{children:r}),n.map((e,r)=>t(Dt,{$selected:a===e,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(e),children:e},r))]})}const At=n.div`
611
+ `,St=C(null);function Rt(){const e=$(St);if(!e)throw new Error("useContext must be used within a Provider");return e}function Ft({children:e,...r}){return t(St.Provider,{value:r,children:e})}function qt(e){const[t,r]=F(e);return R(()=>{r(e)},[e]),[t,r]}function zt({description:r,options:n}){const{resume:i,disabled:o,response:s}=Rt(),[a,l]=qt(s?.result),c=o||void 0!==a;return e(At,{children:[r&&t(It,{children:r}),n.map((e,r)=>t(Dt,{$selected:a===e,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(e),children:e},r))]})}const At=n.div`
612
612
  display: flex;
613
613
  flex-direction: column;
614
614
  gap: 0.5rem;
@@ -643,7 +643,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
643
643
  &:active {
644
644
  transform: ${e=>e.$disabled?"none":"scale(0.98)"};
645
645
  }
646
- `;function Lt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Ft(),[a,l]=qt(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,default:i.default},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 e(Tt,{className:"rounded bg-white shadow-sm",children:[r&&t(Ot,{children:r}),t(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:e})=>t(Pt,{children:e})})]})}const Pt=n.div`
646
+ `;function Lt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Rt(),[a,l]=qt(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,default:i.default},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 e(Tt,{className:"rounded bg-white shadow-sm",children:[r&&t(Ot,{children:r}),t(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:e})=>t(Pt,{children:e})})]})}const Pt=n.div`
647
647
  display: flex;
648
648
  justify-content: flex-end;
649
649
  border-top: 1px solid var(--bs-border-color);
@@ -673,7 +673,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
673
673
  `,Ot=n.div`
674
674
  color: var(--bs-secondary);
675
675
  line-height: 1.5;
676
- `;function Bt({content:r}){const{resume:n,disabled:i,response:o}=Ft(),[s,a]=qt(void 0!==o),l=i||s;return e(Ut,{className:"rounded bg-white shadow-sm",children:[r&&t(_t,{children:t(bt,{content:r})}),t(Ht,{children:t(k,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Ut=n.div`
676
+ `;function Bt({content:r}){const{resume:n,disabled:i,response:o}=Rt(),[s,a]=qt(void 0!==o),l=i||s;return e(Ut,{className:"rounded bg-white shadow-sm",children:[r&&t(_t,{children:t(bt,{content:r})}),t(Ht,{children:t(k,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Ut=n.div`
677
677
  display: flex;
678
678
  flex-direction: column;
679
679
  gap: .5rem;
@@ -699,7 +699,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
699
699
  button {
700
700
  padding: .25rem 1.5rem;
701
701
  }
702
- `;function Qt(e){return e instanceof Error&&e.message||String(e)}class Jt extends L{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onRenderError(e)}render(){return this.state.hasError?null:this.props.children}}function Kt({suspend:e}){const{readonly:r,input:n}=we(),{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=R(e=>{n?.resume({chunk:i,tool:s,payload:e})},[i,n,s]),d=R(e=>{c({error:Qt(e)})},[c]);let u=null;switch(e.type){case"select":u=t(zt,{...e.select});break;case"form":u=t(Lt,{...e.form});break;case"confirm":u=t(Bt,{...e.confirm})}const m=a?.response||o.node?.output;return t(Rt,{resume:c,disabled:r||!!o.error||!l,response:"(Empty)"===m?void 0:m,children:t(Jt,{onRenderError:d,children:u})})}function Wt({value:e,cite:n}){const i=e=>"string"==typeof e?t(bt,{content:e,cite:n}):"image"===e.type?t($t,{src:e.image}):"suspend"===e.type?t(Kt,{suspend:e.suspend}):null;return Array.isArray(e)?t(r,{children:e.map((e,r)=>t(I,{children:i(e)},r))}):i(e)}const Xt=({reasoning:r,loading:n})=>{const[i,o]=M(!1);return S(()=>{n||o(!1)},[n]),t(I,{children:t("div",{className:"mb-2",children:e("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),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(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?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},Vt=D(e=>{const{renderReasoning:r}=we();return r?r({Component:Xt,props:e}):t(Xt,{...e})});function Yt({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=we(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:u,defaultExpanded:m}=z(()=>{const i=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),a=t("span",{className:"text-truncate",children:r.title}),l=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(Zt,{className:"border-top p-2",children:r.arguments})]}),s&&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(Zt,{className:"border-top p-2",children:r.response||"None"})]})]}),c=r.content&&t(Wt,{value:r.content});if(o){const e=o({tool:r,args:i,loading:n});if(e)return{title:null===e.title?null:e.title??a,response:null===e.response?null:e.response??l,content:null===e.content?null:e.content??c,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=M(m),g="all"==i&&null!==l;return e(I,{children:[c&&t("div",{className:"mb-2",children:e(Gt,{className:"shadow-sm rounded bg-white fs-7",$open:h,children:[e("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?t("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(O,{animation:"border",variant:"primary",size:"sm"}),u&&t("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&t("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const Gt=n.div`
702
+ `;function Qt(e){return e instanceof Error&&e.message||String(e)}class Jt extends L{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onRenderError(e)}render(){return this.state.hasError?null:this.props.children}}function Kt({suspend:e}){const{readonly:r,input:n}=we(),{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=S(e=>{n?.resume({chunk:i,tool:s,payload:e})},[i,n,s]),d=S(e=>{c({error:Qt(e)})},[c]);let u=null;switch(e.type){case"select":u=t(zt,{...e.select});break;case"form":u=t(Lt,{...e.form});break;case"confirm":u=t(Bt,{...e.confirm})}const m=a?.response||o.node?.output;return t(Ft,{resume:c,disabled:r||!!o.error||!l,response:"(Empty)"===m?void 0:m,children:t(Jt,{onRenderError:d,children:u})})}function Wt({value:e,cite:n}){const i=e=>"string"==typeof e?t(bt,{content:e,cite:n}):"image"===e.type?t($t,{src:e.image}):"suspend"===e.type?t(Kt,{suspend:e.suspend}):null;return Array.isArray(e)?t(r,{children:e.map((e,r)=>t(I,{children:i(e)},r))}):i(e)}const Xt=({reasoning:r,loading:n})=>{const[i,o]=F(!1);return R(()=>{n||o(!1)},[n]),t(I,{children:t("div",{className:"mb-2",children:e("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),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(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?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},Vt=D(e=>{const{renderReasoning:r}=we();return r?r({Component:Xt,props:e}):t(Xt,{...e})});function Yt({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=we(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:u,defaultExpanded:m}=z(()=>{const i=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),a=t("span",{className:"text-truncate",children:r.title}),l=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(Zt,{className:"border-top p-2",children:r.arguments})]}),s&&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(Zt,{className:"border-top p-2",children:r.response||"None"})]})]}),c=r.content&&t(Wt,{value:r.content});if(o){const e=o({tool:r,args:i,loading:n});if(e)return{title:null===e.title?null:e.title??a,response:null===e.response?null:e.response??l,content:null===e.content?null:e.content??c,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=F(m),g="all"==i&&null!==l;return e(I,{children:[c&&t("div",{className:"mb-2",children:e(Gt,{className:"shadow-sm rounded bg-white fs-7",$open:h,children:[e("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?t("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(O,{animation:"border",variant:"primary",size:"sm"}),u&&t("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&t("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const Gt=n.div`
703
703
  width: ${e=>e.$open?"auto":"fit-content"};
704
704
  max-width: 100%;
705
705
  overflow:hidden;
@@ -708,18 +708,18 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
708
708
  overflow-y: auto;
709
709
  overflow-x: hidden;
710
710
  max-height: 150px;
711
- `;function er({node:r}){const[n,i]=M(!1),{nodeIconResolver:o}=we(),s=!("latency"in r),a=s?t(O,{animation:"border",variant:"primary",size:"sm"}):r.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(rr,{onClick:()=>i(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"}),o?.(r.type),t(nr,{className:"me-2 text-truncate",children:r.title}),t("span",{className:"me-auto"}),!s&&t("span",{className:"text-nowrap text-muted",children:tr(r.latency)}),t("span",{children:a})]}),n&&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:r.input?JSON.stringify(r.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:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const tr=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`,rr=n.div`
711
+ `;function er({node:r}){const[n,i]=F(!1),{nodeIconResolver:o}=we(),s=!("latency"in r),a=s?t(O,{animation:"border",variant:"primary",size:"sm"}):r.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(rr,{onClick:()=>i(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"}),o?.(r.type),t(nr,{className:"me-2 text-truncate",children:r.title}),t("span",{className:"me-auto"}),!s&&t("span",{className:"text-nowrap text-muted",children:tr(r.latency)}),t("span",{children:a})]}),n&&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:r.input?JSON.stringify(r.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:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const tr=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`,rr=n.div`
712
712
  svg {
713
713
  flex-shrink: 0;
714
714
  }
715
715
  `,nr=n.span`
716
716
  display: inline-block;
717
- `;function ir({nodes:r,loading:n}){const[i,o]=M(!1),s=r.some(e=>"error"in e),a=n?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",s?{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",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,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:r.map((e,r)=>t(er,{node:e},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,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const or=D(q(({chunks:r,loading:n,cite:i,isLast:o=!1,deleted:s=!1},a)=>{const{logLevel:l="none"}=we(),c=z(()=>r.flatMap(e=>e.node?[e.node]:[]),[r]);return e(sr,{ref:a,$deleted:s,children:["all"===l&&c.length>0&&t(ir,{loading:n,nodes:c}),r.map((r,s)=>e(I,{children:[r.reasoning&&["stats","all"].includes(l)&&t(Vt,{reasoning:r.reasoning,loading:n&&!r.content&&0===(r.tools||[]).length}),r.content&&t(jt,{value:{chunkIndex:s,chunk:r,isLastMessage:o},children:t(Wt,{cite:i,value:r.content})}),(r.tools||[]).map((e,i)=>t(jt,{value:{chunkIndex:s,chunk:r,toolIndex:i,tool:e,isLastMessage:o},children:t(Yt,{tool:e,loading:n})},i)),r.error&&t(bt,{content:`[${r.error}]`})]},s))]})})),sr=n.div`
717
+ `;function ir({nodes:r,loading:n}){const[i,o]=F(!1),s=r.some(e=>"error"in e),a=n?t(O,{animation:"border",variant:"primary",size:"sm"}):t("i",s?{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",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,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:r.map((e,r)=>t(er,{node:e},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,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const or=D(q(({chunks:r,loading:n,cite:i,isLast:o=!1,deleted:s=!1},a)=>{const{logLevel:l="none"}=we(),c=z(()=>r.flatMap(e=>e.node?[e.node]:[]),[r]);return e(sr,{ref:a,$deleted:s,children:["all"===l&&c.length>0&&t(ir,{loading:n,nodes:c}),r.map((r,s)=>e(I,{children:[r.reasoning&&["stats","all"].includes(l)&&t(Vt,{reasoning:r.reasoning,loading:n&&!r.content&&0===(r.tools||[]).length}),r.content&&t(jt,{value:{chunkIndex:s,chunk:r,isLastMessage:o},children:t(Wt,{cite:i,value:r.content})}),(r.tools||[]).map((e,i)=>t(jt,{value:{chunkIndex:s,chunk:r,toolIndex:i,tool:e,isLastMessage:o},children:t(Yt,{tool:e,loading:n})},i)),r.error&&t(bt,{content:`[${r.error}]`})]},s))]})})),sr=n.div`
718
718
  ${e=>e.$deleted&&i`
719
719
  text-decoration-line: line-through;
720
720
  color: var(--bs-secondary);
721
721
  `}
722
- `;class ar{#t;#o=[];#s=0;constructor(){this.#t=new K}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 lr=new Map;class cr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new K}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?(lr.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),lr.delete(this)}start(e,t=!1){lr.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=lr.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function dr({text:e,loading:t,loader:r}){const n=F(),[i,o]=M(!1),[s,a]=M(!1),l=F(t),c=async(i=!1)=>{n.current||(n.current=r?new cr(r):new ar,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 S(()=>{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]),S(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function ur({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=we(),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}=dr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=se(t(mr,{children:t(O,{size:"sm",variant:"light"})}),a.current)),d&&(p=se(t(mr,{children:t(hr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),e(kt,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?t(hr,{className:"bi bi-volume-down-fill"}):u?t(O,{size:"sm",variant:"primary"}):t(hr,{className:"bi bi-volume-down"}),p]})}const mr=n.div`
722
+ `;class ar{#t;#o=[];#s=0;constructor(){this.#t=new K}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 lr=new Map;class cr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new K}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?(lr.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),lr.delete(this)}start(e,t=!1){lr.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=lr.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function dr({text:e,loading:t,loader:r}){const n=M(),[i,o]=F(!1),[s,a]=F(!1),l=M(t),c=async(i=!1)=>{n.current||(n.current=r?new cr(r):new ar,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 R(()=>{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]),R(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function ur({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=we(),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}=dr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=se(t(mr,{children:t(O,{size:"sm",variant:"light"})}),a.current)),d&&(p=se(t(mr,{children:t(hr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),e(kt,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?t(hr,{className:"bi bi-volume-down-fill"}):u?t(O,{size:"sm",variant:"primary"}):t(hr,{className:"bi bi-volume-down"}),p]})}const mr=n.div`
723
723
  position: absolute;
724
724
  top: 0;
725
725
  left: 0;
@@ -734,7 +734,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
734
734
  &::before {
735
735
  transform: scale(1.4)
736
736
  }
737
- `,pr=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,renderFileItem:y}=we(),x=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]),k=F(null),N=F(null),j=F(null),C=c||u.length>0;return e(r,{children:[C&&e(Nr,{$reverse:!0,children:[g&&t(wr,{children:t("img",{src:g.avatar})}),t(kr,{}),e(Er,{ref:k,children:[c&&t(bt,{content:c}),d&&t(Q,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:t(gr,{body:!0,children:d}),children:t(br,{children:t(fr,{children:d})})}),u.length>0&&u.map(({name:e,size:r,path:n},i)=>{if(E(n))return t($t,{src:`/uploads/${n}`},i);const o={name:e,url:`/uploads/${n}`,size:r};return t(vr,{children:y?y({Component:pe,props:o}):t(pe,{...o})},i)})]})]}),m&&e(Nr,{children:[f&&t(wr,{ref:N,children:t("img",{src:f.avatar})}),t(kr,{}),e(Er,{children:[C&&!1!==i&&e(yr,{children:[t(w,{placement:"top",content:x,as:kt,tooltip:!0}),a&&t(ur,{loading:n.loading,avatarRef:N,contentRef:j,...a}),i?.({Component:kt,message:n,content:x,setMessage:o,messages:v})]}),t(xr,{children:["stats","all"].includes(b)&&n.stats&&e(r,{children:[e("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",n.stats.usage]})]})}),t(or,{ref:j,chunks:m,loading:p,isLast:l,cite:s,deleted:!!h}),h&&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(bt,{content:h.answer})]}),n.loading&&t(ct,{})]})]})]})}),gr=n(J)`
737
+ `,pr=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,renderFileItem:y}=we(),x=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]),k=M(null),N=M(null),j=M(null),C=c||u.length>0;return e(r,{children:[C&&e(Nr,{$reverse:!0,children:[g&&t(wr,{children:t("img",{src:g.avatar})}),t(kr,{}),e(Er,{ref:k,children:[c&&t(bt,{content:c}),d&&t(Q,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:t(gr,{body:!0,children:d}),children:t(br,{children:t(fr,{children:d})})}),u.length>0&&u.map(({name:e,size:r,path:n},i)=>{if(E(n))return t($t,{src:`/uploads/${n}`},i);const o={name:e,url:`/uploads/${n}`,size:r};return t(vr,{children:y?y({Component:pe,props:o}):t(pe,{...o})},i)})]})]}),m&&e(Nr,{children:[f&&t(wr,{ref:N,children:t("img",{src:f.avatar})}),t(kr,{}),e(Er,{children:[C&&!1!==i&&e(yr,{children:[t(w,{placement:"top",content:x,as:kt,tooltip:!0}),a&&t(ur,{loading:n.loading,avatarRef:N,contentRef:j,...a}),i?.({Component:kt,message:n,content:x,setMessage:o,messages:v})]}),t(xr,{children:["stats","all"].includes(b)&&n.stats&&e(r,{children:[e("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",n.stats.usage]})]})}),t(or,{ref:j,chunks:m,loading:p,isLast:l,cite:s,deleted:!!h}),h&&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(bt,{content:h.answer})]}),n.loading&&t(ct,{})]})]})]})}),gr=n(J)`
738
738
  max-width: calc(100% - .875rem * 2);
739
739
  width: calc(100% - .875rem * 2);
740
740
  font-size: 1rem;
@@ -835,7 +835,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
835
835
  background: rgba(var(--bs-primary-rgb), 0.1);
836
836
  }
837
837
  `};
838
- `;function jr(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}=we(),p=F(r.loaded),g=R(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=F(null),{height:b}=ae({ref:f});S(()=>{(u||!p.current)&&c.length>0&&(u&&(p.current=!0),g())},[b,u,p,c]),S(()=>{m.length>0&&g()},[m]),S(()=>{p.current=r.loaded},[h]),S(()=>{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(Cr,{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?t(I,{children:a({Component:pr,props:n})},r):t(pr,{...n},r)}),m.length>0&&t($r,{children:m.map((e,r)=>t("a",{href:"#!question",children:e},r))})]})}const Cr=n.div`
838
+ `;function jr(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}=we(),p=M(r.loaded),g=S(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=M(null),{height:b}=ae({ref:f});R(()=>{(u||!p.current)&&c.length>0&&(u&&(p.current=!0),g())},[b,u,p,c]),R(()=>{m.length>0&&g()},[m]),R(()=>{p.current=r.loaded},[h]),R(()=>{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(Cr,{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?t(I,{children:a({Component:pr,props:n})},r):t(pr,{...n},r)}),m.length>0&&t($r,{children:m.map((e,r)=>t("a",{href:"#!question",children:e},r))})]})}const Cr=n.div`
839
839
  display: flex;
840
840
  flex-direction: column;
841
841
  flex: 1;
@@ -856,16 +856,16 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
856
856
  background: var(--bs-secondary-bg-subtle);
857
857
  }
858
858
  }
859
- `,Sr=D(q(({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 $=R(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]),[S,q]=M(m?.id),[I,D]=M(),[L,P]=v(()=>$(m)),[T,O]=M(!1),B=F(null),[U,_]=M([]),H=R(e=>{q(e?.id),P($(e)),_([]),O(!1),E?.(e)},[T,$,E]);return A(C,()=>({reset:H}),[H]),t(ke,{request:z(()=>k?"string"==typeof k?N.create({baseURL:k}):k:N,[k]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:S,setConversationId:q,input:I,setInput:D,messages:L,setMessages:P,suggestions:U,setSuggestions:_,loading:T,setLoading:O,renderFileItem:f,reset:H,readonly:!o,renderToolContent:b,renderReasoning:y,children:t(Fr,{className:r,children:e(x,{children:[t(Mr,{ref:B,children:t(jr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&t(Ke,{...o,scrollRef:B})]})})})}),X),Mr=n.div`
859
+ `,Mr=D(q(({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 $=S(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]),[R,q]=F(m?.id),[I,D]=F(),[L,P]=v(()=>$(m)),[T,O]=F(!1),B=M(null),[U,_]=F([]),H=S(e=>{q(e?.id),P($(e)),_([]),O(!1),E?.(e)},[T,$,E]);return A(C,()=>({reset:H}),[H]),t(ke,{request:z(()=>k?"string"==typeof k?N.create({baseURL:k}):k:N,[k]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:R,setConversationId:q,input:I,setInput:D,messages:L,setMessages:P,suggestions:U,setSuggestions:_,loading:T,setLoading:O,renderFileItem:f,reset:H,readonly:!o,renderToolContent:b,renderReasoning:y,children:t(Rr,{className:r,children:e(x,{children:[t(Sr,{ref:B,children:t(jr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&t(Ke,{...o,scrollRef:B})]})})})}),X),Sr=n.div`
860
860
  display: flex;
861
861
  flex-direction: column;
862
862
  flex: 1;
863
863
  overflow-y: auto;
864
864
  padding: 0 1rem;
865
865
  margin-bottom: .5rem;
866
- `,Fr=n.div`
866
+ `,Rr=n.div`
867
867
  display: flex;
868
868
  flex-direction: column;
869
869
  height: 100%;
870
870
  position: relative;
871
- `;async function Rr(e){const t=await le().use(de).use(ee).use(te).use(re).use(ue).use(ce).process(e);return String(t)}export{Me as ActionButton,or as Chunks,Qe as EditableInput,pe as FileItem,bt as Markdown,Sr as MessageBox,Ee as VariableForm,me as isToolMessage,Rr as md2html,it as pickQuestions,we as useMessageContext,dr as useSynthesis};
871
+ `;async function Fr(e){const t=await le().use(de).use(ee).use(te).use(re).use(ue).use(ce).process(e);return String(t)}export{Se as ActionButton,or as Chunks,Qe as EditableInput,pe as FileItem,bt as Markdown,Mr as MessageBox,Ee as VariableForm,me as isToolMessage,Fr as md2html,it as pickQuestions,we as useMessageContext,dr as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.2.10",
3
+ "version": "1.3.1",
4
4
  "module": "es/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
65
65
  "license": "MIT",
66
- "gitHead": "b277f93a670c3556a28ee5ffbcb1177622c6ae59",
66
+ "gitHead": "cb20d0cac609edf3057a95a4e517ca8593e0464d",
67
67
  "scripts": {
68
68
  "prebuild": "rimraf es types",
69
69
  "build": "rollup -c --environment NODE_ENV:production",
@@ -4,14 +4,6 @@ import { Updater } from '@topthink/components/types/hooks/use-immer';
4
4
  import { RequestInstance } from '@topthink/components';
5
5
  import { FileItemProps } from './file-item';
6
6
  import { ReasoningProps } from './reasoning';
7
- interface Handles {
8
- onSuccess?: () => void;
9
- onComplete?: () => void;
10
- onEvent?: (event: {
11
- type: string;
12
- data?: any;
13
- }) => void;
14
- }
15
7
  export interface ToolRenderOptions {
16
8
  /** 工具消息原始数据 */
17
9
  tool: ToolMessage;
@@ -55,8 +47,6 @@ interface ContextType {
55
47
  setLoading: Dispatch<SetStateAction<boolean>>;
56
48
  reset: (conversation?: Conversation) => void;
57
49
  readonly: boolean;
58
- handles: Handles;
59
- setHandles: Dispatch<SetStateAction<Handles>>;
60
50
  renderFileItem?: (props: {
61
51
  Component: ComponentType<FileItemProps>;
62
52
  props: FileItemProps;
@@ -68,6 +58,6 @@ interface ContextType {
68
58
  /** 自定义工具渲染函数 */
69
59
  renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
70
60
  }
71
- export declare function useContext(handles?: Handles): ContextType;
72
- export declare function Provider({ children, ...props }: PropsWithChildren<Omit<ContextType, 'handles' | 'setHandles'>>): import("react/jsx-runtime").JSX.Element;
61
+ export declare function useContext(): ContextType;
62
+ export declare function Provider({ children, ...props }: PropsWithChildren<ContextType>): import("react/jsx-runtime").JSX.Element;
73
63
  export {};
@@ -3,6 +3,7 @@ import { ComponentType, MutableRefObject, ReactElement, ReactNode } from 'react'
3
3
  import { Conversation, ConversationMessage, Input, LogLevel, Message, MessageBoxType, Variable } from '../../types';
4
4
  import { MessageActions, MessageItemProps } from './message-item';
5
5
  import type { RenderEditableInput } from './input-box';
6
+ import type { ToolbarActions } from './input-box/toolbar';
6
7
  import { ToolRenderOptions, ToolRenderResult } from './context';
7
8
  import { Components } from 'react-markdown';
8
9
  import { FileItemProps } from './file-item';
@@ -42,9 +43,8 @@ export interface MessageBoxProps {
42
43
  model?: string;
43
44
  };
44
45
  minRows?: number;
45
- suggestion?: boolean;
46
46
  toolbar?: ReactNode;
47
- toolbarActions?: ReactNode;
47
+ toolbarActions?: ToolbarActions;
48
48
  autoFocus?: boolean;
49
49
  renderEditableInput?: RenderEditableInput;
50
50
  placeholder?: string;
@@ -56,6 +56,7 @@ export interface MessageBoxProps {
56
56
  type: string;
57
57
  data?: any;
58
58
  }) => void;
59
+ onNewConversation?: (conversation: Conversation) => boolean;
59
60
  ref?: MutableRefObject<Input | null>;
60
61
  };
61
62
  request?: RequestInstance | string;
@@ -1,5 +1,6 @@
1
1
  import { ForwardRefExoticComponent, MutableRefObject, ReactNode, RefAttributes } from 'react';
2
- import { Input, Variable } from '../../../types';
2
+ import { Conversation, Input, Variable } from '../../../types';
3
+ import { ToolbarActions } from './toolbar';
3
4
  import { EditableInputProps, EditableInputRef } from './editable-input';
4
5
  export type EditableInputComponent = ForwardRefExoticComponent<EditableInputProps & RefAttributes<EditableInputRef>>;
5
6
  export type RenderEditableInput = (options: {
@@ -7,7 +8,6 @@ export type RenderEditableInput = (options: {
7
8
  props: EditableInputProps & RefAttributes<EditableInputRef>;
8
9
  }) => ReactNode;
9
10
  export interface Props {
10
- suggestion?: boolean;
11
11
  supportStop?: boolean;
12
12
  variables?: {
13
13
  config: Variable[];
@@ -21,7 +21,7 @@ export interface Props {
21
21
  maxRows?: number;
22
22
  scrollRef: MutableRefObject<HTMLDivElement | null>;
23
23
  toolbar?: ReactNode | true;
24
- toolbarActions?: ReactNode;
24
+ toolbarActions?: ToolbarActions;
25
25
  disabled?: boolean;
26
26
  placeholder?: string;
27
27
  autoFocus?: boolean;
@@ -30,6 +30,7 @@ export interface Props {
30
30
  type: string;
31
31
  data?: any;
32
32
  }) => void;
33
+ onNewConversation?: (conversation: Conversation) => boolean;
33
34
  }
34
35
  declare const _default: ForwardRefExoticComponent<Props & RefAttributes<Input>>;
35
36
  export default _default;
@@ -1,7 +1,14 @@
1
+ import History from './history';
1
2
  import { ReactNode } from 'react';
3
+ import Reset from './reset';
4
+ export interface ToolbarActionComponents {
5
+ History: typeof History;
6
+ Reset: typeof Reset;
7
+ }
8
+ export type ToolbarActions = ReactNode | ((components: ToolbarActionComponents) => ReactNode);
2
9
  interface Props {
3
10
  children?: ReactNode;
4
- actions?: ReactNode;
11
+ actions?: ToolbarActions;
5
12
  }
6
13
  export default function Toolbar({ children, actions }: Props): import("react/jsx-runtime").JSX.Element;
7
14
  export {};
@@ -1 +1,5 @@
1
- export default function Reset(): import("react/jsx-runtime").JSX.Element;
1
+ interface ResetProps {
2
+ onClick?: () => void;
3
+ }
4
+ export default function Reset({ onClick }: ResetProps): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -1,10 +1,16 @@
1
+ import { Conversation } from '../../../types';
1
2
  interface UseChatOptions {
2
3
  supportStop?: boolean;
4
+ onEvent?: (event: {
5
+ type: string;
6
+ data?: any;
7
+ }) => void;
8
+ onNewConversation?: (conversation: Conversation) => boolean;
9
+ onComplete?: () => void;
3
10
  }
4
11
  export default function useChat(options?: UseChatOptions): {
5
12
  send: (params: string | import("../../..").SendParams, files?: import("../../..").Message["files"], variables?: import("../../..").Message["variables"]) => Promise<void>;
6
13
  resume: (params: import("../../..").ResumeParams) => Promise<void>;
7
- suggest: () => Promise<void>;
8
14
  stop: () => Promise<void>;
9
15
  };
10
16
  export {};