@topthink/chat 1.2.0 → 1.2.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.
Files changed (2) hide show
  1. package/es/index.js +82 -84
  2. package/package.json +3 -3
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as m,Offcanvas as u,dayjs as h,RequestButton as p,useImmer as g,createGlobalStyle as f,getAbsoluteUrl as b,Lightbox as v,Clipboard as x,Button as y,isImageUrl as k,request as w}from"@topthink/components";import*as E from"react";import{createContext as N,useContext as j,useEffect as $,useState as C,useRef as M,useCallback as S,forwardRef as q,useMemo as R,useImperativeHandle as z,Fragment as F,memo as I}from"react";import*as A from"path";import D from"path";import{Spinner as L,Badge as T,CloseButton as P,OverlayTrigger as O,Popover as _}from"react-bootstrap";import B from"eventemitter3";import{Editor as U,Delta as H,SKILL_KEY as J,VARS_KEY as Q,SEL_VALUE_KEY as W,SEL_KEY as X,EditableInputPlugin as G,SelectorInputPlugin as K,SkillInputPlugin as V,BlockKit as Y,Editable as Z,VARS_VALUE_KEY as ee}from"@block-kit/variable";import"@block-kit/variable/dist/style/index.css";import te from"lodash/isEqual";import{toString as re}from"hast-util-to-string";import ne from"react-markdown";import"katex/dist/katex.min.css";import ie from"rehype-highlight";import oe from"rehype-katex";import se from"remark-breaks";import ae from"remark-gfm";import le from"remark-math";import{codes as ce,types as de}from"micromark-util-symbol";import{markdownLineEnding as me}from"micromark-util-character";import{createPortal as ue}from"react-dom";import he from"use-resize-observer";import{unified as pe}from"unified";import ge from"rehype-stringify";import fe from"remark-parse";import be from"remark-rehype";function ve(e,t){return e.name===t}const xe=N(null);function ye(e){const t=j(xe);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return $(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function ke({children:t,...r}){const[n,i]=C({});return e(xe.Provider,{value:{...r,handles:n,setHandles:i},children:t})}const we=function({ext:t}){const{result:r}=a(async e=>{try{return(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/html.svg":return import("./html-BSKTzJZQ.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/mp3.svg":return import("./mp3-HhP1Gk4B.js");case"../../images/file/mp4.svg":return import("./mp4-CWxSyjdn.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/py.svg":return import("./py-D30pRTJN.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/unknown.svg":return import("./unknown-DW8znerP.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.js");default:return new Promise(function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))})}}(`../../images/file/${e}.svg`)).default}catch{return(await import("./unknown-DW8znerP.js")).default}},[t]);return r?e("img",{width:30,height:30,src:r}):null},Ee=function({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const m=D.extname(n).substring(1),u=t(Me,{className:r,$error:!!l,onClick:d,children:[t(Ce,{children:[e(we,{ext:m}),a&&e(L,{variant:"primary"})]}),t($e,{children:[e("h4",{children:n}),i>0&&e("p",{children:o(i,1)})]}),c&&e(je,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(s,{placement:"top",tooltip:l,children:u}):u};function Ne(t){const{renderFileItem:r}=ye();return r?r({Component:Ee,props:t}):e(Ee,{...t})}const je=n.div`
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as m,useDebounce as u,Offcanvas as h,ModalForm as p,RequestButton as g,Loader as f,useImmer as b,createGlobalStyle as v,getAbsoluteUrl as x,Lightbox as y,Clipboard as k,Button as w,isImageUrl as E,request as N}from"@topthink/components";import*as j from"react";import{createContext as $,useContext as C,useEffect as M,useState as S,useRef as q,useCallback as R,forwardRef as z,useMemo as I,useImperativeHandle as F,Fragment as A,memo as D}from"react";import*as L from"path";import T from"path";import{Spinner as P,Badge as O,Dropdown as _,FormControl as B,CloseButton as U,OverlayTrigger as H,Popover as J}from"react-bootstrap";import Q from"eventemitter3";import{Editor as W,Delta as X,SKILL_KEY as G,VARS_KEY as K,SEL_VALUE_KEY as V,SEL_KEY as Y,EditableInputPlugin as Z,SelectorInputPlugin as ee,SkillInputPlugin as te,BlockKit as re,Editable as ne,VARS_VALUE_KEY as ie}from"@block-kit/variable";import"@block-kit/variable/dist/style/index.css";import oe from"lodash/isEqual";import{toString as se}from"hast-util-to-string";import ae from"react-markdown";import"katex/dist/katex.min.css";import le from"rehype-highlight";import ce from"rehype-katex";import de from"remark-breaks";import me from"remark-gfm";import ue from"remark-math";import{codes as he,types as pe}from"micromark-util-symbol";import{markdownLineEnding as ge}from"micromark-util-character";import{createPortal as fe}from"react-dom";import be from"use-resize-observer";import{unified as ve}from"unified";import xe from"rehype-stringify";import ye from"remark-parse";import ke from"remark-rehype";function we(e,t){return e.name===t}const Ee=$(null);function Ne(e){const t=C(Ee);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return M(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function je({children:t,...r}){const[n,i]=S({});return e(Ee.Provider,{value:{...r,handles:n,setHandles:i},children:t})}const $e=function({ext:t}){const{result:r}=a(async e=>{try{return(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/html.svg":return import("./html-BSKTzJZQ.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/mp3.svg":return import("./mp3-HhP1Gk4B.js");case"../../images/file/mp4.svg":return import("./mp4-CWxSyjdn.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/py.svg":return import("./py-D30pRTJN.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/unknown.svg":return import("./unknown-DW8znerP.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.js");default:return new Promise(function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))})}}(`../../images/file/${e}.svg`)).default}catch{return(await import("./unknown-DW8znerP.js")).default}},[t]);return r?e("img",{width:30,height:30,src:r}):null},Ce=function({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const m=T.extname(n).substring(1),u=t(ze,{className:r,$error:!!l,onClick:d,children:[t(Re,{children:[e($e,{ext:m}),a&&e(P,{variant:"primary"})]}),t(qe,{children:[e("h4",{children:n}),i>0&&e("p",{children:o(i,1)})]}),c&&e(Se,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(s,{placement:"top",tooltip:l,children:u}):u};function Me(t){const{renderFileItem:r}=Ne();return r?r({Component:Ce,props:t}):e(Ce,{...t})}const Se=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -13,7 +13,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
13
13
  color: var(--bs-danger);
14
14
  background-color: var(--bs-danger-bg-subtle);
15
15
  }
16
- `,$e=n.div`
16
+ `,qe=n.div`
17
17
  flex: 1;
18
18
  overflow: hidden;
19
19
 
@@ -34,7 +34,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
34
34
  line-height: 20px;
35
35
  margin-bottom: 0;
36
36
  }
37
- `,Ce=n.div`
37
+ `,Re=n.div`
38
38
  position: relative;
39
39
  width: 3rem;
40
40
  height: 3rem;
@@ -48,7 +48,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
48
48
  position: absolute;
49
49
  }
50
50
 
51
- `,Me=n.div`
51
+ `,ze=n.div`
52
52
  display: flex;
53
53
  gap: .5rem;
54
54
  padding: .5rem;
@@ -65,7 +65,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
65
65
  ${e=>e.$error&&i`
66
66
  border-color: var(--bs-danger) !important;
67
67
  `}
68
- `,Se=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function qe(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s,messages:a}=ye(),c=M(null),d=M(!1),m=M(n),{onSuccess:u,onComplete:h,onEvent:p}=s,g=S(t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(m.current=r.conversation,i(r.conversation)):r.suspend?d.current=!0:r.event?p?.(r.event):e(e=>{const t=e[e.length-1];if(r.chunks){if(t.chunks){const e=r.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)t.chunks[e].error=r.chunks.error;else if(r.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const n=r.chunks.tools.index;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}else if(r.chunks.reasoning)t.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const n=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(t.chunks[e].content[n]||(t.chunks[e].content[n]=""),t.chunks[e].content[n]+=i):t.chunks[e].content[n]=i}else t.chunks[e].content+=r.chunks.content;else r.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...r.chunks.node})}}else r.stats?t.stats=r.stats:r.id&&(t.id=r.id)})}catch(e){console.error(e)}else e(e=>{e[e.length-1].loading=!1})},[s]),f=S(t=>{let r="未知错误";l(t)&&(r=401==t.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof t.errors?t.errors:Object.values(t.errors).join("\n")),e(e=>{const t=e[e.length-1];t.chunks&&(0===t.chunks.length?t.chunks=[{error:r}]:t.chunks[t.chunks.length-1].error=r),t.loading=!1})},[]),b=S(async()=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let t={url:"message",method:"get",params:{conversation:m.current},onMessage:g};await o(t),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[]);$(()=>{m.current=n;const e=a[a.length-1];e&&0==e.chunks?.length&&!e.loading&&b()},[n]);const v=S(async(n,...i)=>{"string"==typeof n&&(n={query:n,...i});const{query:s,files:a=[],variables:l={},quote:p}=n;if(s||a.length>0){c.current&&c.current.abort(),d.current=!1,r(!0),t([]),e(e=>{e.push({query:s,quote:p,files:a,variables:l,chunks:[],loading:!0})});try{let e={method:"post",data:{query:s,quote:p,files:a,variables:l,conversation:m.current},onMessage:g};await o(e),d.current||u?.()}catch(e){f(e)}r(!1),h?.()}},[o,s]),x=S(async t=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0});let n={url:"resume",method:"post",data:{conversation:m.current,chunk:t.chunk,tool:t.tool,payload:t.payload},onMessage:g};await o(n),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[o,s]);return{send:v,resume:x,suggest:S(async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:m.current},signal:c.current.signal};const r=await o(e);t(r)}catch{}finally{c.current=null}},[o])}}function Re({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&a.push(e.key)}),e(c,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const ze=n.button`
68
+ `,Ie=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Fe(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s,messages:a}=Ne(),c=q(null),d=q(!1),m=q(n),{onSuccess:u,onComplete:h,onEvent:p}=s,g=R(t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(m.current=r.conversation,i(r.conversation)):r.suspend?d.current=!0:r.event?p?.(r.event):e(e=>{const t=e[e.length-1];if(r.chunks){if(t.chunks){const e=r.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)t.chunks[e].error=r.chunks.error;else if(r.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const n=r.chunks.tools.index;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}else if(r.chunks.reasoning)t.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const n=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(t.chunks[e].content[n]||(t.chunks[e].content[n]=""),t.chunks[e].content[n]+=i):t.chunks[e].content[n]=i}else t.chunks[e].content+=r.chunks.content;else r.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...r.chunks.node})}}else r.stats?t.stats=r.stats:r.id&&(t.id=r.id)})}catch(e){console.error(e)}else e(e=>{e[e.length-1].loading=!1})},[s]),f=R(t=>{let r="未知错误";l(t)&&(r=401==t.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof t.errors?t.errors:Object.values(t.errors).join("\n")),e(e=>{const t=e[e.length-1];t.chunks&&(0===t.chunks.length?t.chunks=[{error:r}]:t.chunks[t.chunks.length-1].error=r),t.loading=!1})},[]),b=R(async()=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let t={url:"message",method:"get",params:{conversation:m.current},onMessage:g};await o(t),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[]);M(()=>{m.current=n;const e=a[a.length-1];e&&0==e.chunks?.length&&!e.loading&&b()},[n]);const v=R(async(n,...i)=>{"string"==typeof n&&(n={query:n,...i});const{query:s,files:a=[],variables:l={},quote:p}=n;if(s||a.length>0){c.current&&c.current.abort(),d.current=!1,r(!0),t([]),e(e=>{e.push({query:s,quote:p,files:a,variables:l,chunks:[],loading:!0})});try{let e={method:"post",data:{query:s,quote:p,files:a,variables:l,conversation:m.current},onMessage:g};await o(e),d.current||u?.()}catch(e){f(e)}r(!1),h?.()}},[o,s]),x=R(async t=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0});let n={url:"resume",method:"post",data:{conversation:m.current,chunk:t.chunk,tool:t.tool,payload:t.payload},onMessage:g};await o(n),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[o,s]);return{send:v,resume:x,suggest:R(async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:m.current},signal:c.current.signal};const r=await o(e);t(r)}catch{}finally{c.current=null}},[o])}}function Ae({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&a.push(e.key)}),e(c,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const De=n.button`
69
69
  color: var(--bs-secondary);
70
70
  cursor: pointer;
71
71
  display: flex;
@@ -88,12 +88,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
88
88
  background-color: var(--bs-gray-200);
89
89
  }
90
90
 
91
- `;let Fe=class{#e;#t;constructor(){this.#t=new B}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},Ie=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new B}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach(e=>e.stop()),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const Ae=q(({onResult:r,model:n="builtin"},i)=>{const{request:o}=ye(),a=R(()=>{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:m}=function({onResult:e,loader:t}){const r=M(),[n,i]=C(!1),[o,s]=C(!1);return $(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new Ie(t):new Fe,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 z(i,()=>({start:l,stop:c}),[l,c]),e(s,{tooltip:d?"停止":"语音输入",placement:"top",children:t(ze,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[m&&e(De,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),De=n(L)`
91
+ `;let Le=class{#e;#t;constructor(){this.#t=new Q}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},Te=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new Q}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach(e=>e.stop()),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const Pe=z(({onResult:r,model:n="builtin"},i)=>{const{request:o}=Ne(),a=I(()=>{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:m}=function({onResult:e,loader:t}){const r=q(),[n,i]=S(!1),[o,s]=S(!1);return M(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new Te(t):new Le,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 F(i,()=>({start:l,stop:c}),[l,c]),e(s,{tooltip:d?"停止":"语音输入",placement:"top",children:t(De,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[m&&e(Oe,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Oe=n(P)`
92
92
  position: absolute;
93
93
  --bs-spinner-width: .75rem;
94
94
  --bs-spinner-height: .75rem;
95
95
  --bs-spinner-border-width: 0.1em;
96
- `,Le=q(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=e(Te,{ref:c,className:t,onClick:a,onMouseDown:l,$size:n,children:r});return i?e(s,{tooltip:i,placement:o,children:d}):d}),Te=n.div`
96
+ `,_e=z(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=e(Be,{ref:c,className:t,onClick:a,onMouseDown:l,$size:n,children:r});return i?e(s,{tooltip:i,placement:o,children:d}):d}),Be=n.div`
97
97
  width: 2rem;
98
98
  height: 2rem;
99
99
  align-items: center;
@@ -117,64 +117,62 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
117
117
  &:hover {
118
118
  background-color: var(--bs-secondary-bg-subtle);
119
119
  }
120
- `;function Pe(){const{request:n,reset:i,conversationId:o}=ye(),[a,l]=C(!1);return t(r,{children:[e(Le,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:e("i",{className:"bi bi-clock-history"})}),e(u,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:Oe,children:a&&e(Je,{children:e(He,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:({data:r,loading:a,setData:c})=>r.length||a?r.map((r,a)=>{const d=r.messages?.reduce((e,t)=>e+t.chunks.reduce((e,t)=>e+(t.content||""),""),"");return t(F,{children:[a>0&&e("hr",{className:"mx-2 my-2"}),t(Ue,{onClick:()=>{i(r),l(!1)},children:[t(Be,{children:[o===r.id&&e(T,{bg:"secondary",children:"当前"}),e("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),e("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:h(r.update_time).fromNow()})]}),t(_e,{children:[e("span",{className:"overflow-hidden text-truncate me-auto",children:d||" "}),e("span",{className:"ms-3",children:o!==r.id&&e(s,{tooltip:"删除",children:e(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===r.id);-1!==t&&e.splice(t,1)})},children:e("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)}):e("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})})})})]})}const Oe=n.div`
120
+ `;function Ue(){const{request:n,reset:i,conversationId:o}=Ne(),[s,a]=S(!1),[l,c]=S(""),[d,m]=S(""),b=u(e=>{m(e)},500);return M(()=>{b(l)},[l]),t(r,{children:[e(_e,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:e("i",{className:"bi bi-clock-history"})}),e(h,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:Xe,header:t(r,{children:[e("span",{children:"聊天历史记录"}),e(Ge,{children:e(B,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:He,children:s&&e(We,{children:e(Qe,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?t(r,{children:[s.map((s,l)=>t(A,{children:[l>0&&e("hr",{className:"mx-2 my-2"}),t(Je,{children:[o===s.id&&e(O,{bg:"secondary",children:"当前"}),e("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),t(_,{align:"end",children:[e(_.Toggle,{size:"sm",className:"no-caret",as:_e,children:e("i",{className:"bi bi-three-dots-vertical"})}),t(_.Menu,{children:[e(p,{buttonProps:{as:_.Item},text:t(r,{children:[e("i",{className:"bi bi-pencil me-2"}),"重命名"]}),modalProps:{header:"编辑对话名称"},schema:{type:"object",properties:{title:{type:"string"}}},uiSchema:{title:{"ui:label":!1,"ui:autofocus":!0}},formData:{title:s.title},onRequest:e=>n({url:`/conversation/${s.id}`,method:"PUT",data:e}),onSuccess:(e,t)=>{c(e=>{const r=e.findIndex(e=>e.id===s.id);-1!==r&&Object.assign(e[r],t)})}}),t(g,{as:_.Item,confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${s.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===s.id);-1!==t&&e.splice(t,1)})},children:[e("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)),l&&e(f,{wrap:!0})]}):e("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const He=n.div`
121
121
  padding: 0;
122
122
  overflow: hidden;
123
- `,_e=n.div`
124
- color: var(--bs-gray-600);
125
- font-weight: 400;
126
- line-height: 22px;
127
- display: flex;
128
- align-items: center;
129
-
130
- & :last-child {
131
- display: none;
132
- }
133
- `,Be=n.div`
134
- display: flex;
135
- align-items: center;
136
- gap: .25rem;
137
- `,Ue=n.div`
123
+ `,Je=n.div`
138
124
  gap: .5rem;
139
125
  display: flex;
140
- flex-direction: column;
141
126
  cursor: pointer;
142
127
  padding: .5rem;
128
+ align-items: center;
143
129
  border-radius: var(--bs-border-radius-lg);
144
130
 
131
+ & > .dropdown {
132
+ display: none;
133
+ }
134
+
145
135
  &:hover {
146
136
  background-color: var(--bs-gray-200);
147
137
 
148
-
149
- &:hover {
150
- ${_e} :last-child {
151
- display: initial;
152
- }
138
+ & > .dropdown {
139
+ display: block;
153
140
  }
154
141
  }
155
- `,He=n(m)`
142
+ `,Qe=n(m)`
156
143
  display: flex;
157
144
  flex-direction: column;
158
145
  padding: .5rem;
159
- `,Je=n.div`
146
+ `,We=n.div`
160
147
  height: 100%;
161
148
  overflow-y: auto;
162
- `;var Qe;function We(){return We=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},We.apply(null,arguments)}const Xe=e=>E.createElement("svg",We({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Qe||(Qe=E.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 Ge(){const{reset:t}=ye();return e(Le,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(Xe,{})})}function Ke({children:r}){return t(Ye,{children:[r,t(Ve,{children:[e(Pe,{}),e(Ge,{})]})]})}const Ve=n.div`
149
+ `,Xe=n.div`
150
+ display: flex;
151
+ align-items: center;
152
+ justify-content: space-between;
153
+ gap: 0.5rem;
154
+ flex: 1;
155
+ margin-right: .5rem;
156
+ `,Ge=n.div`
157
+ display: flex;
158
+ align-items: center;
159
+ gap: 0.5rem;
160
+ `;var Ke;function Ve(){return Ve=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},Ve.apply(null,arguments)}const Ye=e=>j.createElement("svg",Ve({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ke||(Ke=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 Ze(){const{reset:t}=Ne();return e(_e,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(Ye,{})})}function et({children:r}){return t(rt,{children:[r,t(tt,{children:[e(Ue,{}),e(Ze,{})]})]})}const tt=n.div`
163
161
  display: flex;
164
162
  gap: .25rem;
165
163
  margin-left: auto;
166
- `,Ye=n.div`
164
+ `,rt=n.div`
167
165
  margin-bottom: .5rem;
168
166
  display: flex;
169
167
  padding: 0 .125rem;
170
- `,Ze=function(e){return e.ops.map(e=>e.attributes?.[ee]||e.attributes?.[W]||e.insert||"").join("")};var et=q(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:c=1,maxRows:m=5,toolbar:u,disabled:h,autoFocus:p,placeholder:f="请输入你的问题, Enter+Shift换行, Enter发送",onEvent:b},v){const x=M(null),y=M(null),k=M(),[w,E]=C(""),[N,j]=C(""),[q,F]=g([]),[I,D]=C(!1),L=n&&n.length>0?n:Se,{send:T,resume:O,suggest:_}=qe(),B=R(()=>{const e=new U({schema:{[Q]:{void:!0,inline:!0},[X]:{void:!0,inline:!0},[J]:{void:!0,inline:!0}}});return e.event.on("focus_capture",()=>D(!0)),e.event.on("blur_capture",()=>D(!1)),e.event.on("keydown_capture",t=>{if("Escape"===t.key){const{ops:t}=e.state.toBlock();t.some(e=>"skill-key"in(e.attributes||{}))&&e.state.setContent(new H)}else"Enter"!==t.key||t.shiftKey||(t.preventDefault(),t.stopPropagation(),k.current?.())}),e.event.on("CONTENT_CHANGE",e=>{E(Ze(e.current).trim())}),e},[]),Z=R(()=>({onSuccess(){r&&_()},onComplete(){requestAnimationFrame(()=>{B.selection.focus()})},onEvent:b}),[r,b]),{messages:ee,loading:te,request:re,setInput:ne}=ye(Z),[ie,oe]=C();$(()=>{const e=ee.filter(e=>!!e.query);oe(e.at(-1)?.variables)},[ee]),$(()=>{!n&&q.length>0&&F([])},[n]),$(()=>{const e=o.current;if(e&&T){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...ie,...a.values}),T(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,ie]);const se=S(({target:e})=>{if(e.files){const t=Array.from(e.files).filter(e=>!!L.includes(A.extname(e.name))&&(!(e.size>20971520)&&e)).slice(0,6-q.length);F(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await re({method:"POST",url:"/upload",data:t});F(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=l(t)?t.message:"unknown error";F(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}})}e.value=""},[q,L]),ae=q.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),le=S(()=>{if(w||ae.length>0){const e={query:w,files:ae};a&&(e.variables={...ie,...a.values}),N&&(e.quote=N),T(e),de(""),j(""),F([]),y.current?.stop(!0)}},[w,ae,a,ie,N]);$(()=>{k.current=le},[le]);const ce=S(e=>{const t={},r={},n=new H;let i=1,o=1,s=0;const a=/\(([^)]+)\)|\[([^\]]+)\]|\{([^}]+)\}/g;let l;for(;null!==(l=a.exec(e));){if(l.index>s){const t=e.substring(s,l.index);t&&n.insert(t)}if(l[1])n.insert(" ",{[J]:l[1].trim()});else if(l[2]){const e=`var-${i}`;t[e]=l[0],n.insert(" ",{[Q]:e}),i++}else if(l[3]){const e=l[3].split("|").map(e=>e.trim()),t=`sel-${o}`;r[t]=e,n.insert(" ",{[X]:t,[W]:e[0]}),o++}s=a.lastIndex}if(s<e.length){const t=e.substring(s);t&&n.insert(t)}return{delta:n,placeholders:t,selector:r}},[]),de=S(e=>{let t;t="string"==typeof e?e:e(Ze(B.state.block.toDelta()));const{delta:r,placeholders:n,selector:i}=ce(t);B.plugin.register([new G({placeholders:n}),new K({selector:i}),new V]),B.state.setContent(r),requestAnimationFrame(()=>{B.selection.focus()})},[B,ce]),me=R(()=>({setQuery:de,setQuote:j,send:T,resume:O,editor:B,focus(){B.selection.focus()}}),[de,j,T,O,B]);if($(()=>{ne(me)},[me]),z(v,()=>me,[me]),a){const t=a.config.filter(e=>!(e.key in(a.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&d.error("请完善必填信息"),n});if(t.length>0&&!r(ie))return e(rt,{children:e(tt,{children:e(Re,{values:ie,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return oe(e),!0}})})})}return t(dt,{children:[e(it,{}),u&&e(Ke,{children:u}),t(ct,{$focused:I&&!te,children:[q.length>0&&e(st,{children:q.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(nt,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{F(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!N&&t(lt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:N}),e(P,{onClick:()=>j("")})]}),t(at,{children:[e(Y,{editor:B,readonly:te||h,children:e(ot,{className:"block-kit-editable",autoFocus:p,placeholder:f,$minRows:c,$maxRows:m})}),n&&e(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(ze,{disabled:q.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:se,multiple:!0,accept:L.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e(Ae,{ref:y,model:i.model,onResult:e=>{de(t=>t+e+" ")}}),e(ze,{className:"text-primary",disabled:!w&&0===ae.length,onClick:e=>{e.preventDefault(),le()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})});const tt=n.div`
168
+ `,nt=function(e){return e.ops.map(e=>e.attributes?.[ie]||e.attributes?.[V]||e.insert||"").join("")};var it=z(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:c=1,maxRows:m=5,toolbar:u,disabled:h,autoFocus:p,placeholder:g="请输入你的问题, Enter+Shift换行, Enter发送",onEvent:f},v){const x=q(null),y=q(null),k=q(),[w,E]=S(""),[N,j]=S(""),[$,C]=b([]),[z,A]=S(!1),D=n&&n.length>0?n:Ie,{send:T,resume:P,suggest:O}=Fe(),_=I(()=>{const e=new W({schema:{[K]:{void:!0,inline:!0},[Y]:{void:!0,inline:!0},[G]:{void:!0,inline:!0}}});return e.event.on("focus_capture",()=>A(!0)),e.event.on("blur_capture",()=>A(!1)),e.event.on("keydown_capture",t=>{if("Escape"===t.key){const{ops:t}=e.state.toBlock();t.some(e=>"skill-key"in(e.attributes||{}))&&e.state.setContent(new X)}else"Enter"!==t.key||t.shiftKey||(t.preventDefault(),t.stopPropagation(),k.current?.())}),e.event.on("CONTENT_CHANGE",e=>{E(nt(e.current).trim())}),e},[]),B=I(()=>({onSuccess(){r&&O()},onComplete(){requestAnimationFrame(()=>{_.selection.focus()})},onEvent:f}),[r,f]),{messages:H,loading:J,request:Q,setInput:ne}=Ne(B),[ie,oe]=S();M(()=>{const e=H.filter(e=>!!e.query);oe(e.at(-1)?.variables)},[H]),M(()=>{!n&&$.length>0&&C([])},[n]),M(()=>{const e=o.current;if(e&&T){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...ie,...a.values}),T(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,ie]);const se=R(({target:e})=>{if(e.files){const t=Array.from(e.files).filter(e=>!!D.includes(L.extname(e.name))&&(!(e.size>20971520)&&e)).slice(0,6-$.length);C(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await Q({method:"POST",url:"/upload",data:t});C(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=l(t)?t.message:"unknown error";C(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}})}e.value=""},[$,D]),ae=$.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),le=R(()=>{if(w||ae.length>0){const e={query:w,files:ae};a&&(e.variables={...ie,...a.values}),N&&(e.quote=N),T(e),de(""),j(""),C([]),y.current?.stop(!0)}},[w,ae,a,ie,N]);M(()=>{k.current=le},[le]);const ce=R(e=>{const t={},r={},n=new X;let i=1,o=1,s=0;const a=/\(([^)]+)\)|\[([^\]]+)\]|\{([^}]+)\}/g;let l;for(;null!==(l=a.exec(e));){if(l.index>s){const t=e.substring(s,l.index);t&&n.insert(t)}if(l[1])n.insert(" ",{[G]:l[1].trim()});else if(l[2]){const e=`var-${i}`;t[e]=l[0],n.insert(" ",{[K]:e}),i++}else if(l[3]){const e=l[3].split("|").map(e=>e.trim()),t=`sel-${o}`;r[t]=e,n.insert(" ",{[Y]:t,[V]:e[0]}),o++}s=a.lastIndex}if(s<e.length){const t=e.substring(s);t&&n.insert(t)}return{delta:n,placeholders:t,selector:r}},[]),de=R(e=>{let t;t="string"==typeof e?e:e(nt(_.state.block.toDelta()));const{delta:r,placeholders:n,selector:i}=ce(t);_.plugin.register([new Z({placeholders:n}),new ee({selector:i}),new te]),_.state.setContent(r),requestAnimationFrame(()=>{_.selection.focus()})},[_,ce]),me=I(()=>({setQuery:de,setQuote:j,send:T,resume:P,editor:_,focus(){_.selection.focus()}}),[de,j,T,P,_]);if(M(()=>{ne(me)},[me]),F(v,()=>me,[me]),a){const t=a.config.filter(e=>!(e.key in(a.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&d.error("请完善必填信息"),n});if(t.length>0&&!r(ie))return e(st,{children:e(ot,{children:e(Ae,{values:ie,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return oe(e),!0}})})})}return t(pt,{children:[e(lt,{}),u&&e(et,{children:u}),t(ht,{$focused:z&&!J,children:[$.length>0&&e(dt,{children:$.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(at,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{C(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!N&&t(ut,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:N}),e(U,{onClick:()=>j("")})]}),t(mt,{children:[e(re,{editor:_,readonly:J||h,children:e(ct,{className:"block-kit-editable",autoFocus:p,placeholder:g,$minRows:c,$maxRows:m})}),n&&e(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(De,{disabled:$.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:se,multiple:!0,accept:D.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e(Pe,{ref:y,model:i.model,onResult:e=>{de(t=>t+e+" ")}}),e(De,{className:"text-primary",disabled:!w&&0===ae.length,onClick:e=>{e.preventDefault(),le()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})});const ot=n.div`
171
169
  border-radius: var(--bs-border-radius-lg);
172
170
  box-shadow: var(--bs-box-shadow-sm);
173
171
  margin: 1rem;
174
172
  padding: 1rem;
175
173
  width: 100%;
176
174
  max-width: 500px;
177
- `,rt=n.div`
175
+ `,st=n.div`
178
176
  position: absolute;
179
177
  left: 0;
180
178
  right: 0;
@@ -184,9 +182,9 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
184
182
  display: flex;
185
183
  justify-content: center;
186
184
  align-items: center;
187
- `,nt=n(Ne)`
185
+ `,at=n(Me)`
188
186
  width: calc((100% - 0.75rem) / 2);
189
- `,it=f`
187
+ `,lt=v`
190
188
  .editable-selector-options {
191
189
  border-radius: var(--bs-border-radius) !important;
192
190
  border: none !important;
@@ -205,7 +203,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
205
203
  }
206
204
  }
207
205
  }
208
- `,ot=n(Z)`
206
+ `,ct=n(ne)`
209
207
  min-height: calc(${e=>1.5*e.$minRows}em + 1rem);
210
208
  max-height: calc(${e=>1.5*e.$maxRows}em + 1rem);
211
209
  overflow-y: auto;
@@ -230,18 +228,18 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
230
228
  .editable-selector {
231
229
  color: var(--bs-primary);
232
230
  }
233
- `,st=n.div`
231
+ `,dt=n.div`
234
232
  display: flex;
235
233
  flex-wrap: wrap;
236
234
  padding: 0.75rem;
237
235
  gap: 0.75rem;
238
236
  border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
239
- `,at=n.div`
237
+ `,mt=n.div`
240
238
  display: flex;
241
239
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
242
240
  gap: 0.25rem;
243
241
  align-items: end;
244
- `,lt=n.div`
242
+ `,ut=n.div`
245
243
  margin: 0.75rem 0.75rem 0 0.75rem;
246
244
  padding: 4px 8px;
247
245
  display: flex;
@@ -262,14 +260,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
262
260
  -webkit-box-orient: vertical;
263
261
  display: -webkit-box;
264
262
  }
265
- `,ct=n.div`
263
+ `,ht=n.div`
266
264
  background: #fff;
267
265
  border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
268
266
  border-radius: var(--bs-border-radius-lg);
269
267
  box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
270
- `,dt=n.div`
268
+ `,pt=n.div`
271
269
  margin: 0 1rem 1rem;
272
- `;function mt(e){return e.map(e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}}))}function ut(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 ht,pt,gt;function ft(){return ft=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},ft.apply(null,arguments)}const bt=e=>E.createElement("svg",ft({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),ht||(ht=E.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},E.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),E.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),pt||(pt=E.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},E.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),E.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),gt||(gt=E.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},E.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),E.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function vt(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${b(e.image)})`}return""}const xt=function(e,t,r){function n(t){return t!==ce.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(de.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===ce.rightSquareBracket?(e.exit(de.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==ce.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):me(n)||n===ce.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==ce.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},yt=function(){const e=this.data();e.micromarkExtensions.push({text:{[ce.leftSquareBracket]:{tokenize:xt}}}),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}}})},kt=v.Image,wt={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=C(!1),s=R(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);$(()=>{s&&o(s)},[s]);const a=R(()=>re(n),[n]);return t(Mt,{children:[t(Ct,{children:[!i&&e(x,{tooltip:!1,as:$t,content:a}),s&&i&&e($t,{onClick:()=>{const e=new Blob([a],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="image.svg",r.click(),URL.revokeObjectURL(t)},children:"下载"}),s&&e($t,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?e("div",{dangerouslySetInnerHTML:{__html:a}}):e("pre",{children:r})]})},a:({node:t,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return e("a",{...n,href:r,target:i})},img:({node:t,...r})=>e(kt,{...r})},Et=[[le,{singleDollarTextMath:!1}],ae,se],Nt=[oe,[ie,{detect:!1,ignoreMissing:!0}]],jt=I(q(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=R(()=>{const e={...wt,...r};return n&&(e.cite=n),e},[r,n]),s=R(()=>n?[...Et,yt]:Et,[n]);return e(St,{ref:i,children:e(ne,{remarkPlugins:s,rehypePlugins:Nt,components:o,children:t})})}),te),$t=n.div`
270
+ `;function gt(e){return e.map(e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}}))}function ft(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 bt,vt,xt;function yt(){return yt=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},yt.apply(null,arguments)}const kt=e=>j.createElement("svg",yt({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),bt||(bt=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"}))),vt||(vt=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"}))),xt||(xt=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 wt(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${x(e.image)})`}return""}const Et=function(e,t,r){function n(t){return t!==he.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(pe.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===he.rightSquareBracket?(e.exit(pe.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==he.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):ge(n)||n===he.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==he.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},Nt=function(){const e=this.data();e.micromarkExtensions.push({text:{[he.leftSquareBracket]:{tokenize:Et}}}),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}}})},jt=y.Image,$t={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=S(!1),s=I(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);M(()=>{s&&o(s)},[s]);const a=I(()=>se(n),[n]);return t(zt,{children:[t(Rt,{children:[!i&&e(k,{tooltip:!1,as:qt,content:a}),s&&i&&e(qt,{onClick:()=>{const e=new Blob([a],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="image.svg",r.click(),URL.revokeObjectURL(t)},children:"下载"}),s&&e(qt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?e("div",{dangerouslySetInnerHTML:{__html:a}}):e("pre",{children:r})]})},a:({node:t,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return e("a",{...n,href:r,target:i})},img:({node:t,...r})=>e(jt,{...r})},Ct=[[ue,{singleDollarTextMath:!1}],me,de],Mt=[ce,[le,{detect:!1,ignoreMissing:!0}]],St=D(z(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=I(()=>{const e={...$t,...r};return n&&(e.cite=n),e},[r,n]),s=I(()=>n?[...Ct,Nt]:Ct,[n]);return e(It,{ref:i,children:e(ae,{remarkPlugins:s,rehypePlugins:Mt,components:o,children:t})})}),oe),qt=n.div`
273
271
  cursor: pointer;
274
272
  padding: 2px 10px;
275
273
  background-color: #303030;
@@ -279,7 +277,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
279
277
  font-size: 12px;
280
278
  font-family: initial;
281
279
  user-select: none;
282
- `,Ct=n.div`
280
+ `,Rt=n.div`
283
281
  position: absolute;
284
282
  right: 10px;
285
283
  top: 1em;
@@ -293,17 +291,17 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
293
291
  &:hover {
294
292
  opacity: 1;
295
293
  }
296
- `,Mt=n.div`
294
+ `,zt=n.div`
297
295
  position: relative;
298
296
 
299
297
  &:hover {
300
- ${Ct} {
298
+ ${Rt} {
301
299
  pointer-events: all;
302
300
  transform: translateX(0px);
303
301
  opacity: 0.7;
304
302
  }
305
303
  }
306
- `,St=n.div`
304
+ `,It=n.div`
307
305
  -ms-text-size-adjust: 100%;
308
306
  -webkit-text-size-adjust: 100%;
309
307
  line-height: 1.8;
@@ -573,7 +571,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
573
571
  .hljs-strong {
574
572
  font-weight: 700;
575
573
  }
576
- `;var qt=q(function({children:t,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=e(Rt,{ref:a,onClick:n,$disabled:i,...o,children:t});return r?e(s,{tooltip:r,placement:"top",children:l}):l});const Rt=n.div`
574
+ `;var Ft=z(function({children:t,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=e(At,{ref:a,onClick:n,$disabled:i,...o,children:t});return r?e(s,{tooltip:r,placement:"top",children:l}):l});const At=n.div`
577
575
  align-items: center;
578
576
  justify-content: center;
579
577
  border-radius: .375rem;
@@ -606,7 +604,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
606
604
  `}
607
605
 
608
606
  }
609
- `,zt=N(null);var Ft=zt.Provider;const It=v.Image;function At({src:t,...r}){const{imageResolver:n}=ye();return n&&t&&(t=n(t)),e(Dt,{children:e(It,{src:t,...r})})}const Dt=n.div`
607
+ `,Dt=$(null);var Lt=Dt.Provider;const Tt=y.Image;function Pt({src:t,...r}){const{imageResolver:n}=Ne();return n&&t&&(t=n(t)),e(Ot,{children:e(Tt,{src:t,...r})})}const Ot=n.div`
610
608
  margin-bottom: .5rem;
611
609
  margin-top: .5rem;
612
610
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -631,7 +629,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
631
629
  max-height: 100%;
632
630
  max-width: 100%;
633
631
  }
634
- `,Lt=N(null);function Tt(){const e=j(Lt);if(!e)throw new Error("useContext must be used within a Provider");return e}function Pt({children:t,...r}){return e(Lt.Provider,{value:r,children:t})}function Ot({description:r,options:n}){const{resume:i,disabled:o,response:s}=Tt(),[a,l]=C(s?.result),c=o||void 0!==a;return t(_t,{children:[r&&e(Bt,{children:r}),n.map((t,r)=>e(Ut,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const _t=n.div`
632
+ `,_t=$(null);function Bt(){const e=C(_t);if(!e)throw new Error("useContext must be used within a Provider");return e}function Ut({children:t,...r}){return e(_t.Provider,{value:r,children:t})}function Ht({description:r,options:n}){const{resume:i,disabled:o,response:s}=Bt(),[a,l]=S(s?.result),c=o||void 0!==a;return t(Jt,{children:[r&&e(Qt,{children:r}),n.map((t,r)=>e(Wt,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const Jt=n.div`
635
633
  display: flex;
636
634
  flex-direction: column;
637
635
  gap: 0.5rem;
@@ -644,10 +642,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
644
642
  &:last-child {
645
643
  margin-bottom: 0;
646
644
  }
647
- `,Bt=n.div`
645
+ `,Qt=n.div`
648
646
  color: var(--bs-secondary);
649
647
  line-height: 1.5;
650
- `,Ut=n.div`
648
+ `,Wt=n.div`
651
649
  padding: 0.375rem 0.75rem;
652
650
  background-color: ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.1)":"#FFFFFF"};
653
651
  border: 1px solid ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.3)":"var(--bs-border-color)"};
@@ -666,7 +664,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
666
664
  &:active {
667
665
  transform: ${e=>e.$disabled?"none":"scale(0.98)"};
668
666
  }
669
- `;function Ht({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Tt(),[a,l]=C(void 0!==s),d=o||a,{schema:m,uiSchema:u}=R(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Qt,{className:"rounded bg-white shadow-sm",children:[r&&e(Wt,{children:r}),e(c,{schema:m,uiSchema:u,formData:s,onSubmit:({formData:e})=>{d||(l(!0),i(e))},disabled:d,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Jt,{children:t})})]})}const Jt=n.div`
667
+ `;function Xt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Bt(),[a,l]=S(void 0!==s),d=o||a,{schema:m,uiSchema:u}=I(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Kt,{className:"rounded bg-white shadow-sm",children:[r&&e(Vt,{children:r}),e(c,{schema:m,uiSchema:u,formData:s,onSubmit:({formData:e})=>{d||(l(!0),i(e))},disabled:d,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Gt,{children:t})})]})}const Gt=n.div`
670
668
  display: flex;
671
669
  justify-content: flex-end;
672
670
  border-top: 1px solid var(--bs-border-color);
@@ -674,7 +672,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
674
672
  button {
675
673
  padding: .25rem;
676
674
  }
677
- `,Qt=n.div`
675
+ `,Kt=n.div`
678
676
  display: flex;
679
677
  flex-direction: column;
680
678
  gap: 0.5rem;
@@ -692,10 +690,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
692
690
  &:last-child {
693
691
  margin-bottom: 0;
694
692
  }
695
- `,Wt=n.div`
693
+ `,Vt=n.div`
696
694
  color: var(--bs-secondary);
697
695
  line-height: 1.5;
698
- `;function Xt({content:r}){const{resume:n,disabled:i,response:o}=Tt(),[s,a]=C(void 0!==o),l=i||s;return t(Gt,{className:"rounded bg-white shadow-sm",children:[r&&e(Kt,{children:e(jt,{content:r})}),e(Vt,{children:e(y,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Gt=n.div`
696
+ `;function Yt({content:r}){const{resume:n,disabled:i,response:o}=Bt(),[s,a]=S(void 0!==o),l=i||s;return t(Zt,{className:"rounded bg-white shadow-sm",children:[r&&e(er,{children:e(St,{content:r})}),e(tr,{children:e(w,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Zt=n.div`
699
697
  display: flex;
700
698
  flex-direction: column;
701
699
  gap: .5rem;
@@ -709,10 +707,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
709
707
  &:last-child {
710
708
  margin-bottom: 0;
711
709
  }
712
- `,Kt=n.div`
710
+ `,er=n.div`
713
711
  line-height: 1.6;
714
712
  color: var(--bs-body-color);
715
- `,Vt=n.div`
713
+ `,tr=n.div`
716
714
  display: flex;
717
715
  justify-content: flex-end;
718
716
  border-top: 1px solid var(--bs-border-color);
@@ -721,7 +719,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
721
719
  button {
722
720
  padding: .25rem 1.5rem;
723
721
  }
724
- `;function Yt({suspend:t}){const{readonly:r}=ye(),{chunkIndex:n,chunk:i,toolIndex:o,tool:s,isLastMessage:a}=function(){const e=j(zt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:l}=qe(),c=S(e=>{l({chunk:n,tool:o,payload:e})},[]);let d=null;switch(t.type){case"select":d=e(Ot,{...t.select});break;case"form":d=e(Ht,{...t.form});break;case"confirm":d=e(Xt,{...t.confirm})}const m=s?.response||i.node?.output;return e(Pt,{resume:c,disabled:r||!!i.error||!a,response:"(Empty)"===m?void 0:m,children:d})}function Zt({value:t,cite:n}){const i=t=>"string"==typeof t?e(jt,{content:t,cite:n}):"image"===t.type?e(At,{src:t.image}):"suspend"===t.type?e(Yt,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(F,{children:i(t)},r))}):i(t)}const er=({reasoning:r,loading:n})=>{const[i,o]=C(!1);return $(()=>{n||o(!1)},[n]),e(F,{children:e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(L,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:e("div",{className:"border rounded bg-light p-2",children:e(jt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(L,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},tr=I(t=>{const{renderReasoning:r}=ye();return r?r({Component:er,props:t}):e(er,{...t})});class rr{#t;#o=[];#s=0;constructor(){this.#t=new B}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e,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 nr=new Map;class ir{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new B}createLoader(e){const t=new Promise(async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}});return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(nr.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),nr.delete(this)}start(e,t=!1){nr.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=nr.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function or({text:e,loading:t,loader:r}){const n=M(),[i,o]=C(!1),[s,a]=C(!1),l=M(t),c=async(i=!1)=>{n.current||(n.current=r?new ir(r):new rr,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 $(()=>{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]),$(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function sr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=ye(),c=R(()=>{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:m,start:u,stop:h}=or({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(m&&(p=ue(e(ar,{children:e(L,{size:"sm",variant:"light"})}),a.current)),d&&(p=ue(e(ar,{children:e(lr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(qt,{disabled:i&&!d,onClick:()=>{d?h():u()},children:[d?e(lr,{className:"bi bi-volume-down-fill"}):m?e(L,{size:"sm",variant:"primary"}):e(lr,{className:"bi bi-volume-down"}),p]})}const ar=n.div`
722
+ `;function rr({suspend:t}){const{readonly:r}=Ne(),{chunkIndex:n,chunk:i,toolIndex:o,tool:s,isLastMessage:a}=function(){const e=C(Dt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:l}=Fe(),c=R(e=>{l({chunk:n,tool:o,payload:e})},[]);let d=null;switch(t.type){case"select":d=e(Ht,{...t.select});break;case"form":d=e(Xt,{...t.form});break;case"confirm":d=e(Yt,{...t.confirm})}const m=s?.response||i.node?.output;return e(Ut,{resume:c,disabled:r||!!i.error||!a,response:"(Empty)"===m?void 0:m,children:d})}function nr({value:t,cite:n}){const i=t=>"string"==typeof t?e(St,{content:t,cite:n}):"image"===t.type?e(Pt,{src:t.image}):"suspend"===t.type?e(rr,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(A,{children:i(t)},r))}):i(t)}const ir=({reasoning:r,loading:n})=>{const[i,o]=S(!1);return M(()=>{n||o(!1)},[n]),e(A,{children:e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:e("div",{className:"border rounded bg-light p-2",children:e(St,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},or=D(t=>{const{renderReasoning:r}=Ne();return r?r({Component:ir,props:t}):e(ir,{...t})});class sr{#t;#o=[];#s=0;constructor(){this.#t=new Q}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 ar=new Map;class lr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new Q}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?(ar.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),ar.delete(this)}start(e,t=!1){ar.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=ar.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function cr({text:e,loading:t,loader:r}){const n=q(),[i,o]=S(!1),[s,a]=S(!1),l=q(t),c=async(i=!1)=>{n.current||(n.current=r?new lr(r):new sr,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap(e=>e.textContent?[e.textContent]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return M(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),M(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function dr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=Ne(),c=I(()=>{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:m,start:u,stop:h}=cr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(m&&(p=fe(e(mr,{children:e(P,{size:"sm",variant:"light"})}),a.current)),d&&(p=fe(e(mr,{children:e(ur,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(Ft,{disabled:i&&!d,onClick:()=>{d?h():u()},children:[d?e(ur,{className:"bi bi-volume-down-fill"}):m?e(P,{size:"sm",variant:"primary"}):e(ur,{className:"bi bi-volume-down"}),p]})}const mr=n.div`
725
723
  position: absolute;
726
724
  top: 0;
727
725
  left: 0;
@@ -731,27 +729,27 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
731
729
  align-items: center;
732
730
  justify-content: center;
733
731
  background-color: rgba(0, 0, 0, .3);
734
- `,lr=n.i`
732
+ `,ur=n.i`
735
733
 
736
734
  &::before {
737
735
  transform: scale(1.4)
738
736
  }
739
- `;function cr({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=ye(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:m,defaultExpanded:u}=R(()=>{const n=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),i=e("span",{className:"text-truncate",children:r.title}),a=t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"参数"})}),e(mr,{className:"border-top p-2",children:r.arguments})]}),s&&t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"响应"})}),e(mr,{className:"border-top p-2",children:r.response||"None"})]})]}),l=r.content&&e(Zt,{value:r.content});if(o){const e=o({tool:r,args:n});if(e)return{title:null===e.title?null:e.title??i,response:null===e.response?null:e.response??a,content:null===e.content?null:e.content??l,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:i,response:a,content:l,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=C(u),g="all"==i&&null!==l;return t(F,{children:[c&&e("div",{className:"mb-2",children:t(dr,{className:"shadow-sm rounded bg-white fs-7",$open:h,children:[t("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?e("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(L,{animation:"border",variant:"primary",size:"sm"}),m&&e("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&e("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const dr=n.div`
737
+ `;function hr({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=Ne(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:m,defaultExpanded:u}=I(()=>{const n=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),i=e("span",{className:"text-truncate",children:r.title}),a=t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"参数"})}),e(gr,{className:"border-top p-2",children:r.arguments})]}),s&&t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"响应"})}),e(gr,{className:"border-top p-2",children:r.response||"None"})]})]}),l=r.content&&e(nr,{value:r.content});if(o){const e=o({tool:r,args:n});if(e)return{title:null===e.title?null:e.title??i,response:null===e.response?null:e.response??a,content:null===e.content?null:e.content??l,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:i,response:a,content:l,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=S(u),g="all"==i&&null!==l;return t(A,{children:[c&&e("div",{className:"mb-2",children:t(pr,{className:"shadow-sm rounded bg-white fs-7",$open:h,children:[t("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?e("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(P,{animation:"border",variant:"primary",size:"sm"}),m&&e("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&e("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const pr=n.div`
740
738
  width: ${e=>e.$open?"auto":"fit-content"};
741
739
  max-width: 100%;
742
740
  overflow:hidden;
743
- `,mr=n.div`
741
+ `,gr=n.div`
744
742
  white-space: pre-wrap;
745
743
  overflow-y: auto;
746
744
  overflow-x: hidden;
747
745
  max-height: 150px;
748
- `;function ur({node:r}){const[n,i]=C(!1),{nodeIconResolver:o}=ye(),s=!("latency"in r),a=s?e(L,{animation:"border",variant:"primary",size:"sm"}):r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"shadow-sm rounded bg-white fs-7",children:[t(pr,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[e("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),e(gr,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:hr(r.latency)}),e("span",{children:a})]}),n&&t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输入"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输出"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const hr=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`,pr=n.div`
746
+ `;function fr({node:r}){const[n,i]=S(!1),{nodeIconResolver:o}=Ne(),s=!("latency"in r),a=s?e(P,{animation:"border",variant:"primary",size:"sm"}):r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"shadow-sm rounded bg-white fs-7",children:[t(vr,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[e("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),e(xr,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:br(r.latency)}),e("span",{children:a})]}),n&&t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输入"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输出"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const br=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`,vr=n.div`
749
747
  svg {
750
748
  flex-shrink: 0;
751
749
  }
752
- `,gr=n.span`
750
+ `,xr=n.span`
753
751
  display: inline-block;
754
- `;function fr({nodes:r,loading:n}){const[i,o]=C(!1),s=r.some(e=>"error"in e),a=n?e(L,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(ur,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const br=I(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:m=[],chunks:u,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v}=ye(),y=R(()=>u?u.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=vt(t);return r?e+r+"\n":e},""):vt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=vt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[u]),w=M(null),E=M(null),N=M(null),j=R(()=>u?.flatMap(e=>e.node?[e.node]:[])||[],[u]),$=c||m.length>0;return t(r,{children:[$&&t(Mr,{$reverse:!0,children:[g&&e(jr,{children:e("img",{src:g.avatar})}),e($r,{}),t(Cr,{ref:w,children:[c&&e(jt,{content:c}),d&&e(O,{trigger:"click",container:w,rootClose:!0,placement:"bottom",overlay:e(vr,{body:!0,children:d}),children:e(yr,{children:e(xr,{children:d})})}),m.length>0&&m.map(({name:t,size:r,path:n},i)=>k(n)?e(At,{src:`/uploads/${n}`},i):e(wr,{children:e(Ne,{name:t,url:`/uploads/${n}`,size:r})},i))]})]}),u&&t(Mr,{children:[f&&e(jr,{ref:E,children:e("img",{src:f.avatar})}),e($r,{}),t(Cr,{children:[$&&!1!==i&&t(Er,{children:[e(x,{placement:"top",content:y,as:qt,tooltip:!0}),a&&e(sr,{loading:n.loading,avatarRef:E,contentRef:N,...a}),i?.({Component:qt,message:n,content:y,setMessage:o,messages:v})]}),e(Nr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",n.stats.usage]})]})}),t(kr,{ref:N,$deleted:!!h,children:["all"===b&&j.length>0&&e(fr,{loading:p,nodes:j}),u.map((r,n)=>t(F,{children:[r.reasoning&&["stats","all"].includes(b)&&e(tr,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&e(Ft,{value:{chunkIndex:n,chunk:r,isLastMessage:l},children:e(Zt,{cite:s,value:r.content})}),(r.tools||[]).map((t,i)=>e(Ft,{value:{chunkIndex:n,chunk:r,toolIndex:i,tool:t,isLastMessage:l},children:e(cr,{tool:t,loading:p})},i)),r.error&&e(jt,{content:`[${r.error}]`})]},n))]}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(jt,{content:h.answer})]}),n.loading&&e(bt,{})]})]})]})}),vr=n(_)`
752
+ `;function yr({nodes:r,loading:n}){const[i,o]=S(!1),s=r.some(e=>"error"in e),a=n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(fr,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const kr=D(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:m=[],chunks:u,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v}=Ne(),x=I(()=>u?u.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=wt(t);return r?e+r+"\n":e},""):wt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=wt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[u]),y=q(null),w=q(null),N=q(null),j=I(()=>u?.flatMap(e=>e.node?[e.node]:[])||[],[u]),$=c||m.length>0;return t(r,{children:[$&&t(zr,{$reverse:!0,children:[g&&e(Sr,{children:e("img",{src:g.avatar})}),e(qr,{}),t(Rr,{ref:y,children:[c&&e(St,{content:c}),d&&e(H,{trigger:"click",container:y,rootClose:!0,placement:"bottom",overlay:e(wr,{body:!0,children:d}),children:e(Nr,{children:e(Er,{children:d})})}),m.length>0&&m.map(({name:t,size:r,path:n},i)=>E(n)?e(Pt,{src:`/uploads/${n}`},i):e($r,{children:e(Me,{name:t,url:`/uploads/${n}`,size:r})},i))]})]}),u&&t(zr,{children:[f&&e(Sr,{ref:w,children:e("img",{src:f.avatar})}),e(qr,{}),t(Rr,{children:[$&&!1!==i&&t(Cr,{children:[e(k,{placement:"top",content:x,as:Ft,tooltip:!0}),a&&e(dr,{loading:n.loading,avatarRef:w,contentRef:N,...a}),i?.({Component:Ft,message:n,content:x,setMessage:o,messages:v})]}),e(Mr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",n.stats.usage]})]})}),t(jr,{ref:N,$deleted:!!h,children:["all"===b&&j.length>0&&e(yr,{loading:p,nodes:j}),u.map((r,n)=>t(A,{children:[r.reasoning&&["stats","all"].includes(b)&&e(or,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&e(Lt,{value:{chunkIndex:n,chunk:r,isLastMessage:l},children:e(nr,{cite:s,value:r.content})}),(r.tools||[]).map((t,i)=>e(Lt,{value:{chunkIndex:n,chunk:r,toolIndex:i,tool:t,isLastMessage:l},children:e(hr,{tool:t,loading:p})},i)),r.error&&e(St,{content:`[${r.error}]`})]},n))]}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(St,{content:h.answer})]}),n.loading&&e(kt,{})]})]})]})}),wr=n(J)`
755
753
  max-width: calc(100% - .875rem * 2);
756
754
  width: calc(100% - .875rem * 2);
757
755
  font-size: 1rem;
@@ -760,25 +758,25 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
760
758
  .popover-body {
761
759
  padding: .5rem .75rem;
762
760
  }
763
- `,xr=n.div`
761
+ `,Er=n.div`
764
762
  overflow: hidden;
765
763
  text-overflow: ellipsis;
766
764
  word-break: break-all;
767
765
  -webkit-line-clamp: 2;
768
766
  -webkit-box-orient: vertical;
769
767
  display: -webkit-box;
770
- `,yr=n.div`
768
+ `,Nr=n.div`
771
769
  padding: .5rem .75rem;
772
770
  color: var(--bs-secondary);
773
771
  border-radius: var(--bs-border-radius-lg);
774
772
  background: #FFFFFF;
775
773
  cursor: pointer;
776
- `,kr=n.div`
774
+ `,jr=n.div`
777
775
  ${e=>e.$deleted&&i`
778
776
  text-decoration-line: line-through;
779
777
  color: var(--bs-secondary);
780
778
  `}
781
- `,wr=n.div`
779
+ `,$r=n.div`
782
780
  width: 100%;
783
781
  margin-bottom: .5rem;
784
782
  margin-top: .5rem;
@@ -790,7 +788,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
790
788
  &:last-child {
791
789
  margin-bottom: 0;
792
790
  }
793
- `,Er=n.div`
791
+ `,Cr=n.div`
794
792
  position: absolute;
795
793
  top: -1.1rem;
796
794
  right: 0;
@@ -798,7 +796,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
798
796
  gap: .5rem;
799
797
  opacity: 0;
800
798
  z-index: 1;
801
- `,Nr=n.div`
799
+ `,Mr=n.div`
802
800
  position: absolute;
803
801
  bottom: -1.4rem;
804
802
  left: 0;
@@ -811,7 +809,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
811
809
  display: flex;
812
810
  opacity: 0;
813
811
  z-index: 1;
814
- `,jr=n.div`
812
+ `,Sr=n.div`
815
813
  width: 35px;
816
814
  height: 35px;
817
815
  border-radius: 50%;
@@ -822,14 +820,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
822
820
  width: 100%;
823
821
  height: 100%;
824
822
  }
825
- `,$r=n.div`
823
+ `,qr=n.div`
826
824
  width: 0;
827
825
  height: 0;
828
826
  content: "";
829
827
  border: 5px solid transparent;
830
828
  border-right-color: #f3f3f3;
831
829
  transform: translateY(10px);
832
- `,Cr=n.div`
830
+ `,Rr=n.div`
833
831
  padding: .875rem;
834
832
  background-color: rgb(243, 243, 243);
835
833
  border-radius: var(--bs-border-radius-lg);
@@ -837,31 +835,31 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
837
835
  position: relative;
838
836
 
839
837
  &:hover {
840
- ${Nr}, ${Er} {
838
+ ${Mr}, ${Cr} {
841
839
  opacity: 1;
842
840
  }
843
841
  }
844
- `,Mr=n.div`
842
+ `,zr=n.div`
845
843
  display: flex;
846
844
  justify-content: flex-start;
847
845
  padding: 1rem 0 1rem 0;
848
846
  ${e=>e.$reverse&&i`
849
847
  flex-direction: row-reverse;
850
848
 
851
- ${$r} {
849
+ ${qr} {
852
850
  border-left-color: rgba(var(--bs-primary-rgb), 0.1);
853
851
  border-right-color: transparent;
854
852
  }
855
853
 
856
- ${Cr} {
854
+ ${Rr} {
857
855
  background: rgba(var(--bs-primary-rgb), 0.1);
858
856
  }
859
857
  `};
860
- `;function Sr(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:m,suggestions:u,conversationId:h}=ye(),p=M(r.loaded),g=S(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=M(null),{height:b}=he({ref:f});$(()=>{(m||!p.current)&&c.length>0&&(m&&(p.current=!0),g())},[b,m,p,c]),$(()=>{u.length>0&&g()},[u]),$(()=>{p.current=r.loaded},[h]),$(()=>{const e=f.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[f]);const v=c.slice(-30);return t(qr,{ref:f,children:[0===v.length&&n,v.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===v.length-1};return a?a({Component:br,props:n},r):e(br,{...n},r)}),u.length>0&&e(Rr,{children:u.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const qr=n.div`
858
+ `;function Ir(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:m,suggestions:u,conversationId:h}=Ne(),p=q(r.loaded),g=R(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=q(null),{height:b}=be({ref:f});M(()=>{(m||!p.current)&&c.length>0&&(m&&(p.current=!0),g())},[b,m,p,c]),M(()=>{u.length>0&&g()},[u]),M(()=>{p.current=r.loaded},[h]),M(()=>{const e=f.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[f]);const v=c.slice(-30);return t(Fr,{ref:f,children:[0===v.length&&n,v.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===v.length-1};return a?a({Component:kr,props:n},r):e(kr,{...n},r)}),u.length>0&&e(Ar,{children:u.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Fr=n.div`
861
859
  display: flex;
862
860
  flex-direction: column;
863
861
  flex: 1;
864
- `,Rr=n.div`
862
+ `,Ar=n.div`
865
863
  display: flex;
866
864
  flex-direction: column;
867
865
  align-items: flex-start;
@@ -878,16 +876,16 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
878
876
  background: var(--bs-secondary-bg-subtle);
879
877
  }
880
878
  }
881
- `,zr=I(q(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:m,conversation:u,cite:h,speech:p,renderItem:f,renderFileItem:b,renderToolContent:x,renderReasoning:y,messages:k,request:E,onReset:N,transformMessages:j=mt},q)=>{const F=S(e=>{const t=[];if(m&&!1!==m.enable){const e=ut(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(j(e.messages||[])):k?t.concat(j(k)):t},[m]),[I,A]=C(u?.id),[D,L]=C(),[T,P]=g([]);$(()=>{P(F(u))},[m]);const[O,_]=C(!1),B=M(null),[U,H]=C([]),J=S(e=>{A(e?.id),P(F(e)),H([]),_(!1),N?.(e)},[O,F,N]);return z(q,()=>({reset:J}),[J]),e(ke,{request:R(()=>E?"string"==typeof E?w.create({baseURL:E}):E:w,[E]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:I,setConversationId:A,input:D,setInput:L,messages:T,setMessages:P,suggestions:U,setSuggestions:H,loading:O,setLoading:_,renderFileItem:b,reset:J,readonly:!o,renderToolContent:x,renderReasoning:y,children:e(Ir,{className:r,children:t(v,{children:[e(Fr,{ref:B,children:e(Sr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:f,scrollRef:B})}),o&&e(et,{...o,scrollRef:B})]})})})}),te),Fr=n.div`
879
+ `,Dr=D(z(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:m,conversation:u,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:v,renderReasoning:x,messages:k,request:w,onReset:E,transformMessages:j=gt},$)=>{const C=R(e=>{const t=[];if(m&&!1!==m.enable){const e=ft(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(j(e.messages||[])):k?t.concat(j(k)):t},[m]),[z,A]=S(u?.id),[D,L]=S(),[T,P]=b([]);M(()=>{P(C(u))},[m]);const[O,_]=S(!1),B=q(null),[U,H]=S([]),J=R(e=>{A(e?.id),P(C(e)),H([]),_(!1),E?.(e)},[O,C,E]);return F($,()=>({reset:J}),[J]),e(je,{request:I(()=>w?"string"==typeof w?N.create({baseURL:w}):w:N,[w]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:z,setConversationId:A,input:D,setInput:L,messages:T,setMessages:P,suggestions:U,setSuggestions:H,loading:O,setLoading:_,renderFileItem:f,reset:J,readonly:!o,renderToolContent:v,renderReasoning:x,children:e(Tr,{className:r,children:t(y,{children:[e(Lr,{ref:B,children:e(Ir,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&e(it,{...o,scrollRef:B})]})})})}),oe),Lr=n.div`
882
880
  display: flex;
883
881
  flex-direction: column;
884
882
  flex: 1;
885
883
  overflow-y: auto;
886
884
  padding: 0 1rem;
887
885
  margin-bottom: .5rem;
888
- `,Ir=n.div`
886
+ `,Tr=n.div`
889
887
  display: flex;
890
888
  flex-direction: column;
891
889
  height: 100%;
892
890
  position: relative;
893
- `;async function Ar(e){const t=await pe().use(fe).use(se).use(ae).use(le).use(be).use(ge).process(e);return String(t)}export{Le as ActionButton,Ne as FileItem,jt as Markdown,zr as MessageBox,Re as VariableForm,ve as isToolMessage,Ar as md2html,ut as pickQuestions,ye as useMessageContext,or as useSynthesis};
891
+ `;async function Pr(e){const t=await ve().use(ye).use(de).use(me).use(ue).use(ke).use(xe).process(e);return String(t)}export{_e as ActionButton,Me as FileItem,St as Markdown,Dr as MessageBox,Ae as VariableForm,we as isToolMessage,Pr as md2html,ft as pickQuestions,Ne as useMessageContext,cr as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "module": "es/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "@block-kit/core": "^1.0.22",
14
14
  "@block-kit/variable": "^1.0.21",
15
15
  "@breezystack/lamejs": "^1.2.7",
16
- "@topthink/components": "1.2.0",
16
+ "@topthink/components": "1.2.1",
17
17
  "@types/hast": "^3.0.4",
18
18
  "@types/mdast": "^4.0.4",
19
19
  "eventemitter3": "^5.0.1",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
66
66
  "license": "MIT",
67
- "gitHead": "4253c979c79485d87650d73049657e2889f36fe1",
67
+ "gitHead": "bf97bae04cbf072837f3dc02bf3223a71483026d",
68
68
  "scripts": {
69
69
  "prebuild": "rimraf es types",
70
70
  "build": "rollup -c --environment NODE_ENV:production",