@topthink/chat 1.1.9 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js CHANGED
@@ -1,4 +1,242 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox as n,styled as i,Clipboard as o,css as a,formatSize as s,Tooltip as l,useAsync as c,isImageUrl as d,isRequestError as h,Form as u,Toast as m,InfiniteScroller as p,Offcanvas as g,dayjs as f,RequestButton as b,useImmer as v,request as x}from"@topthink/components";import*as y from"react";import{memo as w,useMemo as k,useRef as E,createContext as j,useContext as N,useState as C,Fragment as M,forwardRef as q,useEffect as z,useCallback as $,useImperativeHandle as S}from"react";import A from"react-markdown";import"katex/dist/katex.min.css";import F from"remark-math";import R from"remark-breaks";import D from"remark-gfm";import I from"rehype-katex";import T from"rehype-highlight";import{codes as P,types as L}from"micromark-util-symbol";import{markdownLineEnding as B}from"micromark-util-character";import O from"lodash/isEqual";import{Spinner as _,OverlayTrigger as U,Popover as H,Badge as K,CloseButton as Q}from"react-bootstrap";import*as W from"path";import X from"path";import J from"eventemitter3";import{createPortal as V}from"react-dom";import Y from"react-textarea-autosize";import G from"use-resize-observer";const Z=function(e,t,r){function n(t){return t!==P.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(L.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===P.rightSquareBracket?(e.exit(L.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==P.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):B(n)||n===P.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==P.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},ee=function(){const e=this.data();e.micromarkExtensions.push({text:{[P.leftSquareBracket]:{tokenize:Z}}}),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}}})},te=n.Image,re={pre:r=>{let{children:n}=r;const i=E(null);return t(se,{ref:i,children:[e(ae,{tooltip:!1,content:()=>{const e=i.current?.getElementsByTagName("code");return e?.[0]?.innerText||""}}),n]})},a:t=>{let{node:r,href:n,...i}=t;const o=n?.startsWith("http")?"_blank":"_self";return e("a",{...i,href:n,target:o})},img:t=>{let{node:r,...n}=t;return e(te,{...n})}},ne=[[F,{singleDollarTextMath:!1}],D,R],ie=[I,[T,{detect:!1,ignoreMissing:!0}]],oe=w((t=>{let{content:r,components:n,cite:i}=t;r=r.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=k((()=>{const e={...re,...n};return i&&(e.cite=i),e}),[n,i]),a=k((()=>i?[...ne,ee]:ne),[i]);return e(le,{remarkPlugins:a,rehypePlugins:ie,components:o,children:r})}),O),ae=i(o)`
1
+ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as u,dayjs as m,RequestButton as p,useImmer as g,Lightbox as f,Clipboard as b,isImageUrl as v,request as x}from"@topthink/components";import*as y from"react";import{createContext as w,useContext as k,useRef as E,useCallback as j,useState as N,useEffect as C,forwardRef as M,useMemo as q,useImperativeHandle as z,Fragment as $,memo as S}from"react";import A from"react-textarea-autosize";import*as F from"path";import R from"path";import{Spinner as D,Badge as I,CloseButton as T,OverlayTrigger as L,Popover as P}from"react-bootstrap";import B from"eventemitter3";import O from"lodash/isEqual";import _ from"react-markdown";import"katex/dist/katex.min.css";import U from"remark-math";import H from"remark-breaks";import K from"remark-gfm";import Q from"rehype-katex";import W from"rehype-highlight";import{codes as X,types as J}from"micromark-util-symbol";import{markdownLineEnding as V}from"micromark-util-character";import{createPortal as Y}from"react-dom";import G from"use-resize-observer";const Z=function(e){let{ext:r}=e;const{result:n}=a((async e=>(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-nWXnlyT_.js");case"../../images/file/jpg.svg":return import("./jpg-6tBxSzWk.js");case"../../images/file/md.svg":return import("./md-GZ3HJPcw.js");case"../../images/file/pdf.svg":return import("./pdf-pVX1_E6T.js");case"../../images/file/png.svg":return import("./png-u0o1NMqQ.js");case"../../images/file/pptx.svg":return import("./pptx-Hprz0cON.js");case"../../images/file/txt.svg":return import("./txt-eHeCpvNO.js");case"../../images/file/xlsx.svg":return import("./xlsx-uOft-SV2.js");default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`../../images/file/${e}.svg`)).default),[r]);return n?t("img",{width:30,height:30,src:n}):null};function ee(r){let{className:n,name:i,size:a,loading:l,error:c,onRemove:d}=r;const h=R.extname(i).substring(1),u=e(ie,{className:n,$error:!!c,children:[e(ne,{children:[t(Z,{ext:h}),l&&t(D,{variant:"primary"})]}),e(re,{children:[t("h4",{children:i}),t("p",{children:o(a,1)})]}),d&&t(te,{onClick:e=>{e.preventDefault(),d()},children:t("i",{className:"bi bi-trash3"})})]});return c?t(s,{placement:"top",tooltip:c,children:u}):u}const te=n.div`
2
+ width: 1.75rem;
3
+ height: 1.75rem;
4
+ align-items: center;
5
+ justify-content: center;
6
+ border-radius: .375rem;
7
+ cursor: pointer;
8
+ font-size: 0.9rem;
9
+ color: var(--bs-secondary);
10
+ display: flex;
11
+
12
+ &:hover {
13
+ color: var(--bs-danger);
14
+ background-color: var(--bs-danger-bg-subtle);
15
+ }
16
+ `,re=n.div`
17
+ flex: 1;
18
+ overflow: hidden;
19
+
20
+ h4 {
21
+ font-weight: 500;
22
+ font-size: 12px;
23
+ color: #253044;
24
+ line-height: 20px;
25
+ overflow: hidden;
26
+ white-space: nowrap;
27
+ text-overflow: ellipsis;
28
+ margin-bottom: 0;
29
+ }
30
+
31
+ p {
32
+ font-size: 12px;
33
+ color: rgba(37, 48, 68, .52);
34
+ line-height: 20px;
35
+ margin-bottom: 0;
36
+ }
37
+ `,ne=n.div`
38
+ position: relative;
39
+ width: 3rem;
40
+ height: 3rem;
41
+ display: flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+ background: var(--bs-gray-200);
45
+ border-radius: 6px;
46
+
47
+ .spinner-border {
48
+ position: absolute;
49
+ }
50
+
51
+ `,ie=n.div`
52
+ display: flex;
53
+ gap: .5rem;
54
+ padding: .5rem;
55
+ border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
56
+ border-radius: var(--bs-border-radius-lg);
57
+ align-items: center;
58
+ background: #FFF;
59
+
60
+ &:hover {
61
+ border-color: var(--bs-primary);
62
+ }
63
+
64
+ ${e=>e.$error&&i`
65
+ border-color: var(--bs-danger) !important;
66
+ `}
67
+ `,oe=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],se=w(null);function ae(){const e=k(se);if(!e)throw new Error("useContext must be used within a Provider");return e}function le(e){let{children:r,...n}=e;return t(se.Provider,{value:n,children:r})}function ce(e){let{variables:r,values:n,onSubmit:i,onChange:o,children:s}=e;const a={},l=[],d={};return r.forEach((e=>{a[e.key]={type:"string",title:e.label},"textarea"===e.type?d[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(a[e.key].enum=e.options,a[e.key].enumNames=e.options,e.options.length>0&&(a[e.key].default=e.options[0])),e.required&&l.push(e.key)})),t(c,{schema:{type:"object",properties:a,required:l},formData:n,omitExtraData:!0,uiSchema:d,submitText:"开始对话",onSubmit:i,onChange:o,children:s})}const de=n.button`
68
+ color: var(--bs-secondary);
69
+ cursor: pointer;
70
+ display: flex;
71
+ align-items: center;
72
+ justify-content: center;
73
+ width: 1.8rem;
74
+ height: 1.8rem;
75
+ border-radius: .5rem;
76
+ outline: none;
77
+ border: none;
78
+ background: transparent;
79
+ font-size: 1.2rem;
80
+ position: relative;
81
+
82
+ &:disabled {
83
+ color: var(--bs-gray-400) !important;
84
+ }
85
+
86
+ &:hover&:not(:disabled) {
87
+ background-color: var(--bs-gray-200);
88
+ }
89
+
90
+ `;let he=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)}},ue=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 me=M(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=ae(),l=q((()=>{if("builtin"!==o)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",o);return(await a({url:"/transcriptions",method:"post",data:t})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:u}=function(e){let{onResult:t,loader:r}=e;const n=E(),[i,o]=N(!1),[s,a]=N(!1);return C((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:s,start:async()=>{n.current||(n.current=r?new ue(r):new he,n.current.onRecording(o),n.current.onTranscribing(a),n.current.onResult(t)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:l});return z(n,(()=>({start:c,stop:d})),[c,d]),t(s,{tooltip:h?"停止":"语音输入",placement:"top",children:e(de,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&t(pe,{animation:"border",variant:"primary",size:"sm"}),t("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),pe=n(D)`
91
+ position: absolute;
92
+ --bs-spinner-width: .75rem;
93
+ --bs-spinner-height: .75rem;
94
+ --bs-spinner-border-width: 0.1em;
95
+ `,ge=M(((e,r)=>{let{className:n,children:i,size:o,tooltip:a,placement:l,onClick:c,onMouseDown:d}=e;const h=t(fe,{ref:r,className:n,onClick:c,onMouseDown:d,$size:o,children:i});return a?t(s,{tooltip:a,placement:l,children:h}):h})),fe=n.div`
96
+ width: 2rem;
97
+ height: 2rem;
98
+ align-items: center;
99
+ justify-content: center;
100
+ border-radius: .375rem;
101
+ cursor: pointer;
102
+ font-size: 1.2rem;
103
+ color: var(--bs-secondary);
104
+ display: flex;
105
+
106
+ svg {
107
+ font-size: 1.5rem;
108
+ }
109
+
110
+ ${e=>{let{$size:t}=e;return"sm"===t&&i`
111
+ width: 1.5rem;
112
+ height: 1.5rem;
113
+ font-size: 1rem;
114
+ `}};
115
+
116
+ &:hover {
117
+ background-color: var(--bs-secondary-bg-subtle);
118
+ }
119
+ `;function be(){const{request:n,reset:i,conversationId:o}=ae(),[a,l]=N(!1);return e(r,{children:[t(ge,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:t("i",{className:"bi bi-clock-history"})}),t(u,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:ve,children:a&&t(Ee,{children:t(ke,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:r=>{let{data:a,loading:c,setData:d}=r;return a.length||c?a.map(((r,a)=>{const c=r.messages?.reduce(((e,t)=>e+t.chunks.reduce(((e,t)=>e+(t.content||"")),"")),"");return e($,{children:[a>0&&t("hr",{className:"mx-2 my-2"}),e(we,{onClick:()=>{i(r),l(!1)},children:[e(ye,{children:[o===r.id&&t(I,{bg:"secondary",children:"当前"}),t("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),t("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:m(r.update_time).fromNow()})]}),e(xe,{children:[t("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),t("span",{className:"ms-3",children:o!==r.id&&t(s,{tooltip:"删除",children:t(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const t=e.findIndex((e=>e.id===r.id));-1!==t&&e.splice(t,1)}))},children:t("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)})):t("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const ve=n.div`
120
+ padding: 0;
121
+ overflow: hidden;
122
+ `,xe=n.div`
123
+ color: var(--bs-gray-600);
124
+ font-weight: 400;
125
+ line-height: 22px;
126
+ display: flex;
127
+ align-items: center;
128
+
129
+ & :last-child {
130
+ display: none;
131
+ }
132
+ `,ye=n.div`
133
+ display: flex;
134
+ align-items: center;
135
+ gap: .25rem;
136
+ `,we=n.div`
137
+ gap: .5rem;
138
+ display: flex;
139
+ flex-direction: column;
140
+ cursor: pointer;
141
+ padding: .5rem;
142
+ border-radius: var(--bs-border-radius-lg);
143
+
144
+ &:hover {
145
+ background-color: var(--bs-gray-200);
146
+
147
+
148
+ &:hover {
149
+ ${xe} :last-child {
150
+ display: initial;
151
+ }
152
+ }
153
+ }
154
+ `,ke=n(h)`
155
+ display: flex;
156
+ flex-direction: column;
157
+ padding: .5rem;
158
+ `,Ee=n.div`
159
+ height: 100%;
160
+ overflow-y: auto;
161
+ `;var je;function Ne(){return Ne=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ne.apply(this,arguments)}const Ce=e=>y.createElement("svg",Ne({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),je||(je=y.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function Me(){const{reset:e}=ae();return t(ge,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(Ce,{})})}function qe(r){let{children:n}=r;return e($e,{children:[n,e(ze,{children:[t(be,{}),t(Me,{})]})]})}const ze=n.div`
162
+ display: flex;
163
+ gap: .25rem;
164
+ margin-left: auto;
165
+ `,$e=n.div`
166
+ margin-bottom: .5rem;
167
+ display: flex;
168
+ padding: 0 .125rem;
169
+ `;var Se=M((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:c,variables:h,minRows:u,toolbar:m,disabled:p,autoFocus:f,placeholder:b="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const v=E(null),x=E(null),y=E(null),[w,k]=N(""),[M,q]=N(""),[$,S]=g([]),[R,D]=N(!1),I=o&&o.length>0?o:oe,{messages:L,loading:P,request:B}=ae(),{send:O}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:s,setConversationId:a,request:c}=ae(),d=E(null),h=j((async()=>{d.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:s},signal:d.current.signal};const t=await c(e);i(t)}catch{}finally{d.current=null}}),[s,c]),u=j((async function(e){if("string"==typeof e){for(var u=arguments.length,m=new Array(u>1?u-1:0),p=1;p<u;p++)m[p-1]=arguments[p];e={query:e,...m}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){d.current&&d.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:s},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?a(t.conversation):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",reasoning:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.reasoning?r.chunks[e].reasoning+=t.chunks.reasoning:t.chunks.content&&(r.chunks[e].content+=t.chunks.content)}else t.stats&&(r.stats=t.stats)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await c(e),t&&h()}catch(e){let t="未知错误";l(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[s,c]);return{send:u}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{v.current?.focus()}))}}),[_,U]=N();C((()=>{const e=L.filter((e=>!!e.query));U(e.at(-1)?.variables)}),[L]),C((()=>{!o&&$.length>0&&S([])}),[o]),C((()=>{const e=c.current;if(e&&O){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};h&&(t.variables={..._,...h.values}),O(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[h,_]);const H=j((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!I.includes(F.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-$.length);S((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await B({method:"POST",url:"/upload",data:t});S((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=l(t)?t.message:"unknown error";S((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[$,I]),K=$.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),Q=j((()=>{if(w||K.length>0){const e={query:w,files:K};h&&(e.variables={..._,...h.values}),M&&(e.quote=M),O(e),k(""),q(""),S([]),y.current?.stop(!0)}}),[w,K,h,_,M]);if(z(n,(()=>({setQuery:k,setQuote:q,send:O,focus(){v.current?.focus()}}))),h){const e=h.config.filter((e=>!(e.key in(h.values||{})))),r=function(t){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!t&&e.every((e=>{const n=!e.required||t?.[e.key];return!n&&r&&d.error("请完善必填信息"),n}))};if(e.length>0&&!r(_))return t(Fe,{children:t(Ae,{children:t(ce,{values:_,variables:e,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return U(t),!0}})})})}return e(Pe,{children:[m&&t(qe,{children:m}),e(Le,{$focused:R&&!P,children:[$.length>0&&t(De,{children:$.map(((e,r)=>{let{file:n,error:i,path:o}=e;const s=void 0===i&&void 0===o;return t(Re,{name:n.name,size:n.size,error:i,loading:s,onRemove:()=>{S((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!M&&e(Te,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:M}),t(T,{onClick:()=>q("")})]}),e(Ie,{children:[t(A,{disabled:P||p,ref:v,placeholder:b,minRows:u,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),Q())},autoFocus:f,onFocus:()=>D(!0),onBlur:()=>D(!1)}),o&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(de,{disabled:$.length>=6,onClick:()=>x.current?.click(),children:[t("input",{onChange:H,multiple:!0,accept:I.join(","),ref:x,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&t(me,{ref:y,model:a.model,onResult:e=>{v.current?.focus(),k((t=>t+e+" "))}}),t(de,{className:"text-primary",disabled:!w&&0===K.length,onClick:e=>{e.preventDefault(),Q()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})}));const Ae=n.div`
170
+ border-radius: var(--bs-border-radius-lg);
171
+ box-shadow: var(--bs-box-shadow-sm);
172
+ margin: 1rem;
173
+ padding: 1rem;
174
+ width: 100%;
175
+ max-width: 500px;
176
+ `,Fe=n.div`
177
+ position: absolute;
178
+ left: 0;
179
+ right: 0;
180
+ top: 0;
181
+ bottom: 0;
182
+ background: #FFF;
183
+ display: flex;
184
+ justify-content: center;
185
+ align-items: center;
186
+ `,Re=n(ee)`
187
+ width: calc((100% - .75rem) / 2);
188
+ `,De=n.div`
189
+ display: flex;
190
+ flex-wrap: wrap;
191
+ padding: .75rem;
192
+ gap: .75rem;
193
+ border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
194
+ `,Ie=n.div`
195
+ display: flex;
196
+ padding: .5rem .5rem .5rem 1rem;
197
+ gap: .25rem;
198
+ align-items: end;
199
+
200
+ textarea {
201
+ border: none;
202
+ outline: none;
203
+ flex: 1;
204
+ resize: none;
205
+ background: transparent;
206
+
207
+ &::placeholder {
208
+ color: rgba(54, 54, 54, .3);
209
+ }
210
+ }
211
+ `,Te=n.div`
212
+ margin: .75rem .75rem 0 .75rem;
213
+ padding: 4px 8px;
214
+ display: flex;
215
+ align-items: center;
216
+ gap: 6px;
217
+ color: var(--bs-secondary);
218
+ border-radius: 4px;
219
+ background: rgb(243, 243, 243);
220
+
221
+ p {
222
+ margin-bottom: 0;
223
+ min-width: 0;
224
+ flex: 1;
225
+ overflow: hidden;
226
+ text-overflow: ellipsis;
227
+ word-break: break-all;
228
+ -webkit-line-clamp: 1;
229
+ -webkit-box-orient: vertical;
230
+ display: -webkit-box;
231
+ }
232
+ `,Le=n.div`
233
+ background: #FFF;
234
+ border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
235
+ border-radius: var(--bs-border-radius-lg);
236
+ box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
237
+ `,Pe=n.div`
238
+ margin: 0 1rem 1rem;
239
+ `;function Be(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",error:r,tools:n=[],reasoning:i}=e;return{content:t,reasoning:i,error:r,tools:n}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}function Oe(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}const _e=function(e,t,r){function n(t){return t!==X.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(J.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===X.rightSquareBracket?(e.exit(J.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==X.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):V(n)||n===X.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==X.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},Ue=function(){const e=this.data();e.micromarkExtensions.push({text:{[X.leftSquareBracket]:{tokenize:_e}}}),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}}})},He=f.Image,Ke={pre:r=>{let{children:n}=r;const i=E(null);return e(Ve,{ref:i,children:[t(Je,{tooltip:!1,content:()=>{const e=i.current?.getElementsByTagName("code");return e?.[0]?.innerText||""}}),n]})},a:e=>{let{node:r,href:n,...i}=e;const o=n?.startsWith("http")?"_blank":"_self";return t("a",{...i,href:n,target:o})},img:e=>{let{node:r,...n}=e;return t(He,{...n})}},Qe=[[U,{singleDollarTextMath:!1}],K,H],We=[Q,[W,{detect:!1,ignoreMissing:!0}]],Xe=S((e=>{let{content:r,components:n,cite:i}=e;r=r.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=q((()=>{const e={...Ke,...n};return i&&(e.cite=i),e}),[n,i]),s=q((()=>i?[...Qe,Ue]:Qe),[i]);return t(Ye,{remarkPlugins:s,rehypePlugins:We,components:o,children:r})}),O),Je=n(b)`
2
240
  position: absolute;
3
241
  right: 10px;
4
242
  top: 1em;
@@ -18,17 +256,17 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
18
256
  &:hover {
19
257
  opacity: 1;
20
258
  }
21
- `,se=i.pre`
259
+ `,Ve=n.pre`
22
260
  position: relative;
23
261
 
24
262
  &:hover {
25
- ${ae} {
263
+ ${Je} {
26
264
  pointer-events: all;
27
265
  transform: translateX(0px);
28
266
  opacity: 0.5;
29
267
  }
30
268
  }
31
- `,le=i(A)`
269
+ `,Ye=n(_)`
32
270
  -ms-text-size-adjust: 100%;
33
271
  -webkit-text-size-adjust: 100%;
34
272
  line-height: 1.8;
@@ -298,7 +536,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
298
536
  .hljs-strong {
299
537
  font-weight: 700;
300
538
  }
301
- `,ce=j(null);function de(){const e=N(ce);if(!e)throw new Error("useContext must be used within a Provider");return e}function he(t){let{children:r,...n}=t;return e(ce.Provider,{value:n,children:r})}const ue=n.Image;function me(t){let{src:r,...n}=t;const{imageResolver:i}=de();return i&&r&&(r=i(r)),e(pe,{children:e(ue,{src:r,...n})})}const pe=i.div`
539
+ `,Ge=f.Image;function Ze(e){let{src:r,...n}=e;const{imageResolver:i}=ae();return i&&r&&(r=i(r)),t(et,{children:t(Ge,{src:r,...n})})}const et=n.div`
302
540
  margin-bottom: .5rem;
303
541
  margin-top: .5rem;
304
542
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -323,75 +561,9 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
323
561
  max-height: 100%;
324
562
  max-width: 100%;
325
563
  }
326
- `;function ge(r){let{tool:n}=r;const[i,o]=C(!1),{logLevel:a="none"}=de();let s=null;n.content&&("string"==typeof n.content?s=e(oe,{content:n.content}):"image"===n.content.type&&(s=e(me,{src:n.content.image})));const l="response"in n;return t(M,{children:["stats"==a&&e("div",{className:"mb-2",children:t("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(_,{animation:"border",variant:"primary",size:"sm"}),e("span",{className:"text-muted",children:l?"已使用":"正在使用"}),e("span",{children:n.title})]})}),"all"==a&&e("div",{className:"mb-2",children:t("div",i&&l?{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.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:"已使用"}),e("span",{children:n.title}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",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",children:n.arguments})]}),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(fe,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(_,{animation:"border",variant:"primary",size:"sm"}),e("span",{className:"text-muted",children:l?"已使用":"正在使用"}),e("span",{children:n.title}),l&&e("i",{className:"bi bi-caret-down-fill text-muted"})]})}),s]})}const fe=i.div`
564
+ `;function tt(r){let{tool:n}=r;const[i,o]=N(!1),{logLevel:s="none"}=ae();let a=null;n.content&&("string"==typeof n.content?a=t(Xe,{content:n.content}):"image"===n.content.type&&(a=t(Ze,{src:n.content.image})));const l="response"in n;return e($,{children:["stats"==s&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&l?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:n.title}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(rt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已使用":"正在使用"}),t("span",{children:n.title}),l&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),a]})}const rt=n.div`
327
565
  white-space: pre-wrap;
328
- `;var be,ve,xe;function ye(){return ye=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ye.apply(this,arguments)}const we=e=>y.createElement("svg",ye({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),be||(be=y.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),ve||(ve=y.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),xe||(xe=y.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));const ke=function(t){let{ext:r}=t;const{result:n}=c((async e=>(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-nWXnlyT_.js");case"../../images/file/jpg.svg":return import("./jpg-6tBxSzWk.js");case"../../images/file/md.svg":return import("./md-GZ3HJPcw.js");case"../../images/file/pdf.svg":return import("./pdf-pVX1_E6T.js");case"../../images/file/png.svg":return import("./png-u0o1NMqQ.js");case"../../images/file/pptx.svg":return import("./pptx-Hprz0cON.js");case"../../images/file/txt.svg":return import("./txt-eHeCpvNO.js");case"../../images/file/xlsx.svg":return import("./xlsx-uOft-SV2.js");default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`../../images/file/${e}.svg`)).default),[r]);return n?e("img",{width:30,height:30,src:n}):null};function Ee(r){let{className:n,name:i,size:o,loading:a,error:c,onRemove:d}=r;const h=X.extname(i).substring(1),u=t(Me,{className:n,$error:!!c,children:[t(Ce,{children:[e(ke,{ext:h}),a&&e(_,{variant:"primary"})]}),t(Ne,{children:[e("h4",{children:i}),e("p",{children:s(o,1)})]}),d&&e(je,{onClick:e=>{e.preventDefault(),d()},children:e("i",{className:"bi bi-trash3"})})]});return c?e(l,{placement:"top",tooltip:c,children:u}):u}const je=i.div`
329
- width: 1.75rem;
330
- height: 1.75rem;
331
- align-items: center;
332
- justify-content: center;
333
- border-radius: .375rem;
334
- cursor: pointer;
335
- font-size: 0.9rem;
336
- color: var(--bs-secondary);
337
- display: flex;
338
-
339
- &:hover {
340
- color: var(--bs-danger);
341
- background-color: var(--bs-danger-bg-subtle);
342
- }
343
- `,Ne=i.div`
344
- flex: 1;
345
- overflow: hidden;
346
-
347
- h4 {
348
- font-weight: 500;
349
- font-size: 12px;
350
- color: #253044;
351
- line-height: 20px;
352
- overflow: hidden;
353
- white-space: nowrap;
354
- text-overflow: ellipsis;
355
- margin-bottom: 0;
356
- }
357
-
358
- p {
359
- font-size: 12px;
360
- color: rgba(37, 48, 68, .52);
361
- line-height: 20px;
362
- margin-bottom: 0;
363
- }
364
- `,Ce=i.div`
365
- position: relative;
366
- width: 3rem;
367
- height: 3rem;
368
- display: flex;
369
- align-items: center;
370
- justify-content: center;
371
- background: var(--bs-gray-200);
372
- border-radius: 6px;
373
-
374
- .spinner-border {
375
- position: absolute;
376
- }
377
-
378
- `,Me=i.div`
379
- display: flex;
380
- gap: .5rem;
381
- padding: .5rem;
382
- border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
383
- border-radius: var(--bs-border-radius-lg);
384
- align-items: center;
385
- background: #FFF;
386
-
387
- &:hover {
388
- border-color: var(--bs-primary);
389
- }
390
-
391
- ${e=>e.$error&&a`
392
- border-color: var(--bs-danger) !important;
393
- `}
394
- `;var qe=q((function(t,r){let{children:n,tooltip:i,onClick:o,disabled:a,...s}=t;a&&(o=void 0);const c=e(ze,{ref:r,onClick:o,$disabled:a,...s,children:n});return i?e(l,{tooltip:i,placement:"top",children:c}):c}));const ze=i.div`
566
+ `;var nt,it,ot;function st(){return st=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},st.apply(this,arguments)}const at=e=>y.createElement("svg",st({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),nt||(nt=y.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),it||(it=y.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),ot||(ot=y.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},y.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),y.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));var lt=M((function(e,r){let{children:n,tooltip:i,onClick:o,disabled:a,...l}=e;a&&(o=void 0);const c=t(ct,{ref:r,onClick:o,$disabled:a,...l,children:n});return i?t(s,{tooltip:i,placement:"top",children:c}):c}));const ct=n.div`
395
567
  align-items: center;
396
568
  justify-content: center;
397
569
  border-radius: .375rem;
@@ -406,7 +578,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
406
578
  height: 1.875rem;
407
579
  overflow: hidden;
408
580
 
409
- ${e=>e.$disabled&&a`
581
+ ${e=>e.$disabled&&i`
410
582
  color: var(--bs-gray-400) !important;
411
583
  `}
412
584
  .bi {
@@ -416,7 +588,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
416
588
  line-height: 1.75rem;
417
589
  text-align: center;
418
590
 
419
- ${e=>!e.$disabled&&a`
591
+ ${e=>!e.$disabled&&i`
420
592
  &:hover {
421
593
  color: var(--bs-dark);
422
594
  background-color: var(--bs-gray-200);
@@ -424,7 +596,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
424
596
  `}
425
597
 
426
598
  }
427
- `;let $e=class{#e;#t=[];#r=0;constructor(){this.#e=new J}speak(){for(this.#e.emit("playing",!0);this.#r<this.#t.length;){const e=this.#t[this.#r],t=new SpeechSynthesisUtterance(e),r=++this.#r;t.onend=()=>{r>=this.#t.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#e.emit("playing",!1)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#t=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#r=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#e.on("playing",e)}onSpeaking(e){this.#e.on("speaking",e)}};const Se=new Map;let Ae=class{#n;#e;#t=[];#i=new Map;#o=!1;#r=0;#a=!1;constructor(e){this.#n=e,this.#e=new J}createLoader(e){const t=new Promise((async t=>{try{const{type:r,data:n}=await this.#n(e),i=new Audio(`data:${r};base64,${n}`);this.#i.set(e,i),t(i)}catch{this.#i.delete(e),t(void 0)}}));return this.#i.set(e,t),t}async loadAudioData(){this.#a=!0,this.#e.emit("speaking",!0);let e=0;for(;e<this.#t.length;){const t=this.#t[e];!this.#i.has(t)&&this.#a&&await this.createLoader(t),e++}this.#e.emit("speaking",!1),this.#a=!1}waitForAudioLoaded(e){const t=this.#i.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.#o=!0;const t=await this.waitForAudioLoaded(this.#t[e]);this.#e.emit("playing",!0),t?(Se.set(this,t),t.onpause=async()=>{t.ended?(this.#r++,this.#r<this.#t.length?await this.playAudio(this.#r):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#o=!1,this.#a=!1,this.#e.emit("playing",!1),this.#e.emit("speaking",!1),Se.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];Se.forEach(((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)})),this.#t=Array.isArray(e)?e:[e],t||(this.#r=0),this.#a||this.loadAudioData(),this.#o||this.playAudio()}update(e){this.#t=Array.isArray(e)?e:[e]}stop(){const e=Se.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#e.on("playing",e)}onSpeaking(e){this.#e.on("speaking",e)}};function Fe(e){let{text:t,loading:r,loader:n}=e;const i=E(),[o,a]=C(!1),[s,l]=C(!1),c=E(r),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new Ae(n):new $e,i.current.onSpeaking(a),i.current.onPlaying(l));let o="";"string"==typeof t?o=t:t.current&&(o=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap((e=>e.textContent?[e.textContent]:[]))}(t.current),r&&o.pop()),o&&0!==o.length&&i.current.start(o,e)};return z((()=>{if(c.current&&"string"!=typeof t&&t.current){if(r){const e={childList:!0,subtree:!0},r=new MutationObserver((function(){d(!0)}));return r.observe(t.current,e),d(),()=>{r.disconnect()}}d(!0)}}),[r]),z((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:s,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function Re(r){let{model:n="builtin",voice:i,loading:o,autoplay:a,contentRef:s,avatarRef:l}=r;const{request:c}=de(),d=k((()=>{if("builtin"!==n)return async e=>(await c({url:"/speech",method:"post",data:{model:n,voice:i,input:e}})).audio}),[n,i]),{playing:h,speaking:u,start:m,stop:p}=Fe({loader:d,text:s,loading:a&&o});let g=null;return l.current&&(u&&(g=V(e(De,{children:e(_,{size:"sm",variant:"light"})}),l.current)),h&&(g=V(e(De,{children:e(Ie,{className:"bi bi-volume-down-fill text-light"})}),l.current))),t(qe,{disabled:o&&!h,onClick:()=>{h?p():m()},children:[h?e(Ie,{className:"bi bi-volume-down-fill"}):u?e(_,{size:"sm",variant:"primary"}):e(Ie,{className:"bi bi-volume-down"}),g]})}const De=i.div`
599
+ `;class dt{#t;#o=[];#s=0;constructor(){this.#t=new B}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const ht=new Map;class ut{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new B}createLoader(e){const t=new Promise((async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}}));return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(ht.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),ht.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];ht.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=ht.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function mt(e){let{text:t,loading:r,loader:n}=e;const i=E(),[o,s]=N(!1),[a,l]=N(!1),c=E(r),d=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];i.current||(i.current=n?new ut(n):new dt,i.current.onSpeaking(s),i.current.onPlaying(l));let o="";"string"==typeof t?o=t:t.current&&(o=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap((e=>e.textContent?[e.textContent]:[]))}(t.current),r&&o.pop()),o&&0!==o.length&&i.current.start(o,e)};return C((()=>{if(c.current&&"string"!=typeof t&&t.current){if(r){const e={childList:!0,subtree:!0},r=new MutationObserver((function(){d(!0)}));return r.observe(t.current,e),d(),()=>{r.disconnect()}}d(!0)}}),[r]),C((()=>()=>{i.current&&(i.current.stop(),i.current=void 0)}),[]),{playing:a,speaking:o,start:d,stop:()=>{i.current&&i.current.stop()}}}function pt(r){let{model:n="builtin",voice:i,loading:o,autoplay:s,contentRef:a,avatarRef:l}=r;const{request:c}=ae(),d=q((()=>{if("builtin"!==n)return async e=>(await c({url:"/speech",method:"post",data:{model:n,voice:i,input:e}})).audio}),[n,i]),{playing:h,speaking:u,start:m,stop:p}=mt({loader:d,text:a,loading:s&&o});let g=null;return l.current&&(u&&(g=Y(t(gt,{children:t(D,{size:"sm",variant:"light"})}),l.current)),h&&(g=Y(t(gt,{children:t(ft,{className:"bi bi-volume-down-fill text-light"})}),l.current))),e(lt,{disabled:o&&!h,onClick:()=>{h?p():m()},children:[h?t(ft,{className:"bi bi-volume-down-fill"}):u?t(D,{size:"sm",variant:"primary"}):t(ft,{className:"bi bi-volume-down"}),g]})}const gt=n.div`
428
600
  position: absolute;
429
601
  top: 0;
430
602
  left: 0;
@@ -434,12 +606,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
434
606
  align-items: center;
435
607
  justify-content: center;
436
608
  background-color: rgba(0, 0, 0, .3);
437
- `,Ie=i.i`
609
+ `,ft=n.i`
438
610
 
439
611
  &::before {
440
612
  transform: scale(1.4)
441
613
  }
442
- `,Te=w((n=>{let{message:i,actions:a,updater:s,cite:l,speech:c}=n;const{query:h,quote:u,files:m=[],chunks:p,annotation:g}=i,{user:f,bot:b,logLevel:v="none"}=de(),x=k((()=>p?p.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>t.content&&"string"==typeof t.content?e+t.content+"\n":e),"")}),""):""),[p]),y=E(null),w=E(null),j=E(null);return t(r,{children:[(h||m.length>0)&&t(Xe,{$reverse:!0,children:[f&&e(Ke,{children:e("img",{src:f.avatar})}),e(Qe,{}),t(We,{ref:y,children:[h&&e(oe,{content:h}),u&&e(U,{trigger:"click",container:y,rootClose:!0,placement:"bottom",overlay:e(Pe,{body:!0,children:u}),children:e(Be,{children:e(Le,{children:u})})}),m.length>0&&m.map(((t,r)=>{let{name:n,size:i,path:o}=t;return d(o)?e(me,{src:`/uploads/${o}`},r):e(_e,{children:e(Ee,{name:n,size:i})},r)}))]})]}),p&&t(Xe,{children:[e(Ke,{ref:w,children:e("img",{src:b.avatar})}),e(Qe,{}),t(We,{children:[(h||m.length>0)&&t(Ue,{children:[e(o,{placement:"top",content:x,as:qe,tooltip:!0}),c&&e(Re,{loading:i.loading,avatarRef:w,contentRef:j,...c}),a?.({Component:qe,message:i,content:x,setMessage:s})]}),e(He,{children:["stats","all"].includes(v)&&i.stats&&t(r,{children:[t("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",i.stats.usage]})]})}),e(Oe,{ref:j,$deleted:!!g,children:p.length>0&&p.map(((r,n)=>t(M,{children:[r.content&&e(oe,{cite:l,content:r.content}),r.tools.map(((t,r)=>e(ge,{tool:t},r))),r.error&&e(oe,{content:`[${r.error}]`})]},n)))}),g&&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(oe,{content:g.answer})]}),i.loading&&e(we,{})]})]})]})})),Pe=i(H)`
614
+ `,bt=S((r=>{let{reasoning:n,loading:i}=r;const[o,s]=N(i);return C((()=>{i||s(!1)}),[i]),t($,{children:t("div",{className:"mb-2",children:e("div",o||i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(i),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[i?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:t("div",{className:"border rounded bg-light p-2",children:t(Xe,{content:n})})})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[i?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:i?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})})),vt=S((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l}=n;const{query:c,quote:d,files:h=[],chunks:u,annotation:m}=i,{user:p,bot:g,logLevel:f="none",messages:x}=ae(),y=q((()=>u?u.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>t.content&&"string"==typeof t.content?e+t.content+"\n":e),"")}),""):""),[u]),w=E(null),k=E(null),j=E(null);return e(r,{children:[(c||h.length>0)&&e(zt,{$reverse:!0,children:[p&&t(Ct,{children:t("img",{src:p.avatar})}),t(Mt,{}),e(qt,{ref:w,children:[c&&t(Xe,{content:c}),d&&t(L,{trigger:"click",container:w,rootClose:!0,placement:"bottom",overlay:t(xt,{body:!0,children:d}),children:t(wt,{children:t(yt,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return v(o)?t(Ze,{src:`/uploads/${o}`},r):t(Et,{children:t(ee,{name:n,size:i})},r)}))]})]}),u&&e(zt,{children:[t(Ct,{ref:k,children:t("img",{src:g.avatar})}),t(Mt,{}),e(qt,{children:[(c||h.length>0)&&!1!==o&&e(jt,{children:[t(b,{placement:"top",content:y,as:lt,tooltip:!0}),l&&t(pt,{loading:i.loading,avatarRef:k,contentRef:j,...l}),o?.({Component:lt,message:i,content:y,setMessage:s,messages:x})]}),t(Nt,{children:["stats","all"].includes(f)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),t(kt,{ref:j,$deleted:!!m,children:u.length>0&&u.map(((r,n)=>e($,{children:[r.reasoning&&["stats","all"].includes(f)&&t(bt,{reasoning:r.reasoning,loading:!r.content}),r.content&&t(Xe,{cite:a,content:r.content}),r.tools.map(((e,r)=>t(tt,{tool:e},r))),r.error&&t(Xe,{content:`[${r.error}]`})]},n)))}),m&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(Xe,{content:m.answer})]}),i.loading&&t(at,{})]})]})]})})),xt=n(P)`
443
615
  max-width: calc(100% - .875rem * 2);
444
616
  width: calc(100% - .875rem * 2);
445
617
  font-size: 1rem;
@@ -448,25 +620,25 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
448
620
  .popover-body {
449
621
  padding: .5rem .75rem;
450
622
  }
451
- `,Le=i.div`
623
+ `,yt=n.div`
452
624
  overflow: hidden;
453
625
  text-overflow: ellipsis;
454
626
  word-break: break-all;
455
627
  -webkit-line-clamp: 2;
456
628
  -webkit-box-orient: vertical;
457
629
  display: -webkit-box;
458
- `,Be=i.div`
630
+ `,wt=n.div`
459
631
  padding: .5rem .75rem;
460
632
  color: var(--bs-secondary);
461
633
  border-radius: var(--bs-border-radius-lg);
462
634
  background: #FFFFFF;
463
635
  cursor: pointer;
464
- `,Oe=i.div`
465
- ${e=>e.$deleted&&a`
636
+ `,kt=n.div`
637
+ ${e=>e.$deleted&&i`
466
638
  text-decoration-line: line-through;
467
639
  color: var(--bs-secondary);
468
640
  `}
469
- `,_e=i.div`
641
+ `,Et=n.div`
470
642
  width: 100%;
471
643
  margin-bottom: .5rem;
472
644
  margin-top: .5rem;
@@ -478,7 +650,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
478
650
  &:last-child {
479
651
  margin-bottom: 0;
480
652
  }
481
- `,Ue=i.div`
653
+ `,jt=n.div`
482
654
  position: absolute;
483
655
  top: -1.1rem;
484
656
  right: 0;
@@ -486,7 +658,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
486
658
  gap: .5rem;
487
659
  opacity: 0;
488
660
  z-index: 1;
489
- `,He=i.div`
661
+ `,Nt=n.div`
490
662
  position: absolute;
491
663
  bottom: -1.4rem;
492
664
  left: 0;
@@ -499,7 +671,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
499
671
  display: flex;
500
672
  opacity: 0;
501
673
  z-index: 1;
502
- `,Ke=i.div`
674
+ `,Ct=n.div`
503
675
  width: 35px;
504
676
  height: 35px;
505
677
  border-radius: 50%;
@@ -510,14 +682,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
510
682
  width: 100%;
511
683
  height: 100%;
512
684
  }
513
- `,Qe=i.div`
685
+ `,Mt=n.div`
514
686
  width: 0;
515
687
  height: 0;
516
688
  content: "";
517
689
  border: 5px solid transparent;
518
690
  border-right-color: #f3f3f3;
519
691
  transform: translateY(10px);
520
- `,We=i.div`
692
+ `,qt=n.div`
521
693
  padding: .875rem;
522
694
  background-color: rgb(243, 243, 243);
523
695
  border-radius: var(--bs-border-radius-lg);
@@ -525,199 +697,38 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
525
697
  position: relative;
526
698
 
527
699
  &:hover {
528
- ${He}, ${Ue} {
700
+ ${Nt}, ${jt} {
529
701
  opacity: 1;
530
702
  }
531
703
  }
532
- `,Xe=i.div`
704
+ `,zt=n.div`
533
705
  display: flex;
534
706
  justify-content: flex-start;
535
707
  padding: 1rem 0 1rem 0;
536
- ${e=>e.$reverse&&a`
708
+ ${e=>e.$reverse&&i`
537
709
  flex-direction: row-reverse;
538
710
 
539
- ${Qe} {
711
+ ${Mt} {
540
712
  border-left-color: rgba(var(--bs-primary-rgb), 0.1);
541
713
  border-right-color: transparent;
542
714
  }
543
715
 
544
- ${We} {
716
+ ${qt} {
545
717
  background: rgba(var(--bs-primary-rgb), 0.1);
546
718
  }
547
719
  `};
548
- `,Je=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Ve(t){let{variables:r,values:n,onSubmit:i,onChange:o,children:a}=t;const s={},l=[],c={};return r.forEach((e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?c[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&l.push(e.key)})),e(u,{schema:{type:"object",properties:s,required:l},formData:n,omitExtraData:!0,uiSchema:c,submitText:"开始对话",onSubmit:i,onChange:o,children:a})}const Ye=i.button`
549
- color: var(--bs-secondary);
550
- cursor: pointer;
551
- display: flex;
552
- align-items: center;
553
- justify-content: center;
554
- width: 1.8rem;
555
- height: 1.8rem;
556
- border-radius: .5rem;
557
- outline: none;
558
- border: none;
559
- background: transparent;
560
- font-size: 1.2rem;
561
- position: relative;
562
-
563
- &:disabled {
564
- color: var(--bs-gray-400) !important;
565
- }
566
-
567
- &:hover&:not(:disabled) {
568
- background-color: var(--bs-gray-200);
569
- }
570
-
571
- `;class Ge{#s;#e;constructor(){this.#e=new J}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}start(){if(!this.#s){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void m.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.#e.emit("result",t)},t.onspeechend=()=>{this.#e.emit("recording",!1)},t.onerror=e=>{this.#e.emit("recording",!1),m.error(e.error)},this.#s=t}this.#e.emit("recording",!0),this.#s.start()}stop(){this.#s?.stop(),this.#e.emit("recording",!1)}}class Ze{#e;#n;#l;#c;constructor(e){this.#n=e,this.#e=new J}async start(){try{this.#l=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#c=new AudioContext;const e=this.#c.createScriptProcessor(0,1,1);this.#c.createMediaStreamSource(this.#l).connect(e),e.connect(this.#c.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,a=e.inputBuffer.getChannelData(0);let s=!0;for(let e=0;e<a.length;e++)if(Math.abs(a[e])>n){s=!1;break}if(s){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(a)),r=o},this.#e.emit("recording",!0)}catch(e){m.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 a=e.subarray(t,t+i),s=r.encodeBuffer(a);n.push(new Int8Array(s)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#e.emit("transcribing",!0);const e=await this.#n(t);e&&this.#e.emit("result",e)}catch(e){}finally{this.#e.emit("transcribing",!1)}}stop(){this.#l&&(this.#l.getTracks().forEach((e=>e.stop())),this.#l=void 0),this.#c&&(this.#c.close(),this.#c=void 0),this.#e.emit("recording",!1)}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}}const et=q(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=de(),s=k((()=>{if("builtin"!==o)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",o);return(await a({url:"/transcriptions",method:"post",data:t})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:u}=function(e){let{onResult:t,loader:r}=e;const n=E(),[i,o]=C(!1),[a,s]=C(!1);return z((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:a,start:async()=>{n.current||(n.current=r?new Ze(r):new Ge,n.current.onRecording(o),n.current.onTranscribing(s),n.current.onResult(t)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:s});return S(n,(()=>({start:c,stop:d})),[c,d]),e(l,{tooltip:h?"停止":"语音输入",placement:"top",children:t(Ye,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&e(tt,{animation:"border",variant:"primary",size:"sm"}),e("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),tt=i(_)`
572
- position: absolute;
573
- --bs-spinner-width: .75rem;
574
- --bs-spinner-height: .75rem;
575
- --bs-spinner-border-width: 0.1em;
576
- `,rt=q(((t,r)=>{let{className:n,children:i,size:o,tooltip:a,placement:s,onClick:c,onMouseDown:d}=t;const h=e(nt,{ref:r,className:n,onClick:c,onMouseDown:d,$size:o,children:i});return a?e(l,{tooltip:a,placement:s,children:h}):h})),nt=i.div`
577
- width: 2rem;
578
- height: 2rem;
579
- align-items: center;
580
- justify-content: center;
581
- border-radius: .375rem;
582
- cursor: pointer;
583
- font-size: 1.2rem;
584
- color: var(--bs-secondary);
585
- display: flex;
586
-
587
- svg {
588
- font-size: 1.5rem;
589
- }
590
-
591
- ${e=>{let{$size:t}=e;return"sm"===t&&a`
592
- width: 1.5rem;
593
- height: 1.5rem;
594
- font-size: 1rem;
595
- `}};
596
-
597
- &:hover {
598
- background-color: var(--bs-secondary-bg-subtle);
599
- }
600
- `;function it(){const{request:n,reset:i,conversationId:o}=de(),[a,s]=C(!1);return t(r,{children:[e(rt,{tooltip:"历史记录",placement:"top",onClick:()=>s(!0),children:e("i",{className:"bi bi-clock-history"})}),e(g,{show:a,onHide:()=>{s(!1)},placement:"end",header:"聊天历史记录",bodyAs:ot,children:a&&e(dt,{children:e(ct,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:r=>{let{data:a,loading:c,setData:d}=r;return a.length||c?a.map(((r,a)=>{const c=r.messages?.reduce(((e,t)=>e+t.chunks.reduce(((e,t)=>e+(t.content||"")),"")),"");return t(M,{children:[a>0&&e("hr",{className:"mx-2 my-2"}),t(lt,{onClick:()=>{i(r),s(!1)},children:[t(st,{children:[o===r.id&&e(K,{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:f(r.update_time).fromNow()})]}),t(at,{children:[e("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),e("span",{className:"ms-3",children:o!==r.id&&e(l,{tooltip:"删除",children:e(b,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const t=e.findIndex((e=>e.id===r.id));-1!==t&&e.splice(t,1)}))},children:e("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)})):e("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const ot=i.div`
601
- padding: 0;
602
- overflow: hidden;
603
- `,at=i.div`
604
- color: var(--bs-gray-600);
605
- font-weight: 400;
606
- line-height: 22px;
607
- display: flex;
608
- align-items: center;
609
-
610
- & :last-child {
611
- display: none;
612
- }
613
- `,st=i.div`
614
- display: flex;
615
- align-items: center;
616
- gap: .25rem;
617
- `,lt=i.div`
618
- gap: .5rem;
619
- display: flex;
620
- flex-direction: column;
621
- cursor: pointer;
622
- padding: .5rem;
623
- border-radius: var(--bs-border-radius-lg);
624
-
625
- &:hover {
626
- background-color: var(--bs-gray-200);
627
-
628
-
629
- &:hover {
630
- ${at} :last-child {
631
- display: initial;
632
- }
633
- }
634
- }
635
- `,ct=i(p)`
720
+ `;function $t(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a}=r,{messages:l,setMessages:c,loading:d,suggestions:h,conversationId:u}=ae(),m=E(r.loaded),p=E(null),g=j((()=>{const e=p.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),f=E(null),{height:b}=G({ref:f});return C((()=>{(d||!m.current)&&l.length>0&&(d&&(m.current=!0),g())}),[b,d,m,l]),C((()=>{h.length>0&&g()}),[h]),C((()=>{m.current=r.loaded}),[u]),C((()=>{const e=p.current;if(e){const t=()=>{m.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[f]),t(St,{ref:p,children:e(At,{ref:f,children:[0===l.length&&n,l.slice(-30).map(((e,r)=>{const n={actions:i,cite:o,speech:s,message:e,setMessage:t=>{c((r=>{const n=r.findIndex((t=>t.id===e.id));-1!==n&&t(r[n])}))}};return a?a({Component:vt,props:n},e.id):t(vt,{...n},r)})),h.length>0&&t(Ft,{children:h.map(((e,r)=>t("a",{href:"#!question",children:e},r)))})]})})}const St=n.div`
636
721
  display: flex;
637
722
  flex-direction: column;
638
- padding: .5rem;
639
- `,dt=i.div`
640
- height: 100%;
723
+ flex: 1;
641
724
  overflow-y: auto;
642
- `;var ht;function ut(){return ut=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ut.apply(this,arguments)}const mt=e=>y.createElement("svg",ut({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),ht||(ht=y.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function pt(){const{reset:t}=de();return e(rt,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(mt,{})})}function gt(r){let{children:n}=r;return t(bt,{children:[n,t(ft,{children:[e(it,{}),e(pt,{})]})]})}const ft=i.div`
643
- display: flex;
644
- gap: .25rem;
645
- margin-left: auto;
646
- `,bt=i.div`
725
+ padding: 0 1rem;
647
726
  margin-bottom: .5rem;
727
+ `,At=n.div`
648
728
  display: flex;
649
- padding: 0 .125rem;
650
- `;var vt=q((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:s,variables:c,minRows:d,toolbar:u,disabled:p,autoFocus:g,placeholder:f="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const b=E(null),x=E(null),y=E(null),[w,k]=C(""),[j,N]=C(""),[M,q]=v([]),[A,F]=C(!1),R=o&&o.length>0?o:Je,{messages:D,loading:I,request:T}=de(),{send:P}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:a,setConversationId:s,request:l}=de(),c=E(null),d=$((async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:a},signal:c.current.signal};const t=await l(e);i(t)}catch{}finally{c.current=null}}),[a,l]),u=$((async function(e){if("string"==typeof e){for(var u=arguments.length,m=new Array(u>1?u-1:0),p=1;p<u;p++)m[p-1]=arguments[p];e={query:e,...m}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){c.current&&c.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:a},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?s(t.conversation):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.content&&(r.chunks[e].content+=t.chunks.content)}else t.stats&&(r.stats=t.stats)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await l(e),t&&d()}catch(e){let t="未知错误";h(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[a,l]);return{send:u}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{b.current?.focus()}))}}),[L,B]=C();z((()=>{const e=D.filter((e=>!!e.query));B(e.at(-1)?.variables)}),[D]),z((()=>{!o&&M.length>0&&q([])}),[o]),z((()=>{const e=s.current;if(e&&P){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};c&&(t.variables={...L,...c.values}),P(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[c,L]);const O=$((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!R.includes(W.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-M.length);q((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await T({method:"POST",url:"/upload",data:t});q((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=h(t)?t.message:"unknown error";q((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[M,R]),_=M.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),U=$((()=>{if(w||_.length>0){const e={query:w,files:_};c&&(e.variables={...L,...c.values}),j&&(e.quote=j),P(e),k(""),N(""),q([]),y.current?.stop(!0)}}),[w,_,c,L,j]);if(S(n,(()=>({setQuery:k,setQuote:N,send:P,focus(){b.current?.focus()}}))),c){const t=c.config.filter((e=>!(e.key in(c.values||{})))),r=function(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!e&&t.every((t=>{const n=!t.required||e?.[t.key];return!n&&r&&m.error("请完善必填信息"),n}))};if(t.length>0&&!r(L))return e(yt,{children:e(xt,{children:e(Ve,{values:L,variables:t,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return B(t),!0}})})})}return t(Ct,{children:[u&&e(gt,{children:u}),t(Nt,{$focused:A&&!I,children:[M.length>0&&e(kt,{children:M.map(((t,r)=>{let{file:n,error:i,path:o}=t;const a=void 0===i&&void 0===o;return e(wt,{name:n.name,size:n.size,error:i,loading:a,onRemove:()=>{q((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!j&&t(jt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:j}),e(Q,{onClick:()=>N("")})]}),t(Et,{children:[e(Y,{disabled:I||p,ref:b,placeholder:f,minRows:d,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),U())},autoFocus:g,onFocus:()=>F(!0),onBlur:()=>F(!1)}),o&&e(l,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(Ye,{disabled:M.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:O,multiple:!0,accept:R.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&e(et,{ref:y,model:a.model,onResult:e=>{b.current?.focus(),k((t=>t+e+" "))}}),e(Ye,{className:"text-primary",disabled:!w&&0===_.length,onClick:e=>{e.preventDefault(),U()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})}));const xt=i.div`
651
- border-radius: var(--bs-border-radius-lg);
652
- box-shadow: var(--bs-box-shadow-sm);
653
- margin: 1rem;
654
- padding: 1rem;
655
- width: 100%;
656
- max-width: 500px;
657
- `,yt=i.div`
658
- position: absolute;
659
- left: 0;
660
- right: 0;
661
- top: 0;
662
- bottom: 0;
663
- background: #FFF;
664
- display: flex;
665
- justify-content: center;
666
- align-items: center;
667
- `,wt=i(Ee)`
668
- width: calc((100% - .75rem) / 2);
669
- `,kt=i.div`
670
- display: flex;
671
- flex-wrap: wrap;
672
- padding: .75rem;
673
- gap: .75rem;
674
- border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
675
- `,Et=i.div`
676
- display: flex;
677
- padding: .5rem .5rem .5rem 1rem;
678
- gap: .25rem;
679
- align-items: end;
680
-
681
- textarea {
682
- border: none;
683
- outline: none;
684
- flex: 1;
685
- resize: none;
686
- background: transparent;
687
-
688
- &::placeholder {
689
- color: rgba(54, 54, 54, .3);
690
- }
691
- }
692
- `,jt=i.div`
693
- margin: .75rem .75rem 0 .75rem;
694
- padding: 4px 8px;
695
- display: flex;
696
- align-items: center;
697
- gap: 6px;
698
- color: var(--bs-secondary);
699
- border-radius: 4px;
700
- background: rgb(243, 243, 243);
701
-
702
- p {
703
- margin-bottom: 0;
704
- min-width: 0;
705
- flex: 1;
706
- overflow: hidden;
707
- text-overflow: ellipsis;
708
- word-break: break-all;
709
- -webkit-line-clamp: 1;
710
- -webkit-box-orient: vertical;
711
- display: -webkit-box;
712
- }
713
- `,Nt=i.div`
714
- background: #FFF;
715
- border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
716
- border-radius: var(--bs-border-radius-lg);
717
- box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
718
- `,Ct=i.div`
719
- margin: 0 1rem 1rem;
720
- `;function Mt(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}const qt=w(q(((r,i)=>{let{className:o,bot:a,user:s,input:l,logLevel:c,imageResolver:d,placeholder:h,actions:u,onboarding:m,conversation:p,cite:g,speech:f,request:b}=r;const y=$((e=>{const t=[];if(m&&!1!==m.enable){const e=Mt(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(function(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",error:r,tools:n=[]}=e;return{content:t,error:r,tools:n}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}(e.messages||[])):t}),[m]),[w,j]=C(p?.id),[N,M]=v([]);z((()=>{M(y(p))}),[m]);const[q,A]=C(!1),F=E(!l),R=E(null),D=$((()=>{const e=R.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),{ref:I,height:T}=G(),[P,L]=C([]);z((()=>{(q||!F.current)&&N.length>0&&(q&&(F.current=!0),D())}),[T,q,F,N]),z((()=>{P.length>0&&D()}),[P]);const B=$((e=>{q||(j(e?.id),M(y(e)),L([]))}),[q,y]);return S(i,(()=>({reset:B})),[B]),e(he,{request:k((()=>b?"string"==typeof b?x.create({baseURL:b}):b:x),[b]),bot:a,user:s,logLevel:c,imageResolver:d,conversationId:w,setConversationId:j,messages:N,setMessages:M,suggestions:P,setSuggestions:L,loading:q,setLoading:A,reset:B,children:e(At,{className:o,children:t(n,{children:[e($t,{ref:R,children:t(St,{ref:I,children:[0===N.length&&h,N.slice(-30).map(((t,r)=>e(Te,{actions:u,cite:g,speech:f,message:t,updater:e=>{M((r=>{const n=r.findIndex((e=>e.id===t.id));-1!==n&&e(r[n])}))}},r))),P.length>0&&e(zt,{children:P.map(((t,r)=>e("a",{href:"#!question",children:t},r)))})]})}),l&&e(vt,{...l,scrollRef:R})]})})})})),O),zt=i.div`
729
+ flex-direction: column;
730
+ flex: 1;
731
+ `,Ft=n.div`
721
732
  display: flex;
722
733
  flex-direction: column;
723
734
  align-items: flex-start;
@@ -734,20 +745,9 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
734
745
  background: var(--bs-secondary-bg-subtle);
735
746
  }
736
747
  }
737
- `,$t=i.div`
738
- display: flex;
739
- flex-direction: column;
740
- flex: 1;
741
- overflow-y: auto;
742
- padding: 0 1rem;
743
- margin-bottom: .5rem;
744
- `,St=i.div`
745
- display: flex;
746
- flex-direction: column;
747
- flex: 1;
748
- `,At=i.div`
748
+ `,Rt=S(M(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,placeholder:d,actions:h,onboarding:u,conversation:m,cite:p,speech:b,renderItem:v,messages:y,request:w}=r;const k=j((e=>{const t=[];if(u&&!1!==u.enable){const e=Oe(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(Be(e.messages||[])):y?t.concat(Be(y)):t}),[u]),[M,$]=N(m?.id),[S,A]=g([]);C((()=>{A(k(m))}),[u]);const[F,R]=N(!1),D=E(null),[I,T]=N([]),L=j((e=>{F||($(e?.id),A(k(e)),T([]))}),[F,k]);return z(n,(()=>({reset:L})),[L]),t(le,{request:q((()=>w?"string"==typeof w?x.create({baseURL:w}):w:x),[w]),bot:o,user:s,logLevel:l,imageResolver:c,conversationId:M,setConversationId:$,messages:S,setMessages:A,suggestions:I,setSuggestions:T,loading:F,setLoading:R,reset:L,children:t(Dt,{className:i,children:e(f,{children:[t($t,{placeholder:d,cite:p,actions:h,loaded:!a,speech:b,renderItem:v}),a&&t(Se,{...a,scrollRef:D})]})})})})),O),Dt=n.div`
749
749
  display: flex;
750
750
  flex-direction: column;
751
751
  height: 100%;
752
752
  position: relative;
753
- `;export{rt as ActionButton,oe as Markdown,qt as MessageBox,Ve as VariableForm,Mt as pickQuestions,Fe as useSynthesis};
753
+ `;export{ge as ActionButton,Xe as Markdown,Rt as MessageBox,ce as VariableForm,Oe as pickQuestions,mt as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "scripts": {
5
5
  "prebuild": "rimraf es types",
6
6
  "build": "rollup -c --environment NODE_ENV:production",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.11.2",
20
20
  "@breezystack/lamejs": "^1.2.7",
21
- "@topthink/components": "^1.1.6",
21
+ "@topthink/components": "^1.1.8",
22
22
  "@types/mdast": "^4.0.4",
23
23
  "eventemitter3": "^5.0.1",
24
24
  "katex": "^0.16.9",
@@ -65,5 +65,5 @@
65
65
  },
66
66
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
67
67
  "license": "MIT",
68
- "gitHead": "41fdb171970f06f951fd35926087097ee95b9283"
68
+ "gitHead": "8d8c9e127c692c2ec5319f146b70f06f921fdc06"
69
69
  }
@@ -6,5 +6,5 @@ interface Props {
6
6
  components?: Components;
7
7
  cite?: Components['cite'];
8
8
  }
9
- export declare const Markdown: import("react").MemoExoticComponent<({ content, components: userComponents, cite }: Props) => JSX.Element>;
9
+ declare const Markdown: import("react").MemoExoticComponent<({ content, components: userComponents, cite }: Props) => import("react/jsx-runtime").JSX.Element>;
10
10
  export default Markdown;
@@ -25,5 +25,5 @@ interface ContextType {
25
25
  reset: (conversation?: Conversation) => void;
26
26
  }
27
27
  export declare function useContext(): ContextType;
28
- export declare function Provider({ children, ...props }: PropsWithChildren<ContextType>): JSX.Element;
28
+ export declare function Provider({ children, ...props }: PropsWithChildren<ContextType>): import("react/jsx-runtime").JSX.Element;
29
29
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  interface Props {
3
2
  className?: string;
4
3
  name: string;
@@ -7,5 +6,5 @@ interface Props {
7
6
  error?: string;
8
7
  onRemove?: () => void;
9
8
  }
10
- export default function FileItem({ className, name, size, loading, error, onRemove }: Props): JSX.Element;
9
+ export default function FileItem({ className, name, size, loading, error, onRemove }: Props): import("react/jsx-runtime").JSX.Element;
11
10
  export {};
@@ -1,2 +1,2 @@
1
1
  import { ImgHTMLAttributes } from 'react';
2
- export default function ImageItem({ src, ...props }: ImgHTMLAttributes<HTMLImageElement>): JSX.Element;
2
+ export default function ImageItem({ src, ...props }: ImgHTMLAttributes<HTMLImageElement>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import { RequestInstance } from '@topthink/components';
2
2
  import { MutableRefObject, ReactNode } from 'react';
3
- import { Conversation, ConversationMessage, Input, LogLevel, MessageBoxType, Variable } from '../../types';
4
- import { MessageActions } from './message-item';
3
+ import { Conversation, ConversationMessage, Input, LogLevel, Message, MessageBoxType, Variable } from '../../types';
4
+ import MessageItem, { MessageActions, MessageItemProps } from './message-item';
5
5
  import { Components } from 'react-markdown';
6
- interface Props {
6
+ export interface MessageBoxProps {
7
7
  className?: string;
8
8
  bot: {
9
9
  name: string;
@@ -13,7 +13,7 @@ interface Props {
13
13
  name: string;
14
14
  avatar: string;
15
15
  };
16
- messages?: ConversationMessage[];
16
+ messages?: ConversationMessage[] | Message[];
17
17
  conversation?: Conversation;
18
18
  speech?: {
19
19
  model?: string;
@@ -49,6 +49,10 @@ interface Props {
49
49
  request?: RequestInstance | string;
50
50
  actions?: MessageActions;
51
51
  cite?: Components['cite'];
52
+ renderItem?: (props: {
53
+ Component: typeof MessageItem;
54
+ props: MessageItemProps;
55
+ }, id?: string) => ReactNode;
52
56
  }
53
- declare const MessageBox: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<MessageBoxType>>>;
57
+ declare const MessageBox: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<MessageBoxProps & import("react").RefAttributes<MessageBoxType>>>;
54
58
  export default MessageBox;
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function History(): JSX.Element;
1
+ export default function History(): import("react/jsx-runtime").JSX.Element;
@@ -2,5 +2,5 @@ import { ReactNode } from 'react';
2
2
  interface Props {
3
3
  children?: ReactNode;
4
4
  }
5
- export default function Toolbar({ children }: Props): JSX.Element;
5
+ export default function Toolbar({ children }: Props): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function Reset(): JSX.Element;
1
+ export default function Reset(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import MessageItem, { MessageActions, MessageItemProps } from './message-item';
2
+ import { ReactNode } from 'react';
3
+ import { Components } from 'react-markdown';
4
+ interface Props {
5
+ placeholder: ReactNode;
6
+ loaded?: boolean;
7
+ actions?: MessageActions;
8
+ cite?: Components['cite'];
9
+ speech?: {
10
+ model?: string;
11
+ voice?: string;
12
+ autoplay?: boolean;
13
+ };
14
+ renderItem?: (props: {
15
+ Component: typeof MessageItem;
16
+ props: MessageItemProps;
17
+ }, id?: string) => ReactNode;
18
+ }
19
+ export default function List(props: Props): import("react/jsx-runtime").JSX.Element;
20
+ export {};
@@ -2,16 +2,17 @@ import { ReactNode } from 'react';
2
2
  import { Message } from '../../types';
3
3
  import Action from './action';
4
4
  import { Components } from 'react-markdown';
5
- export type MessageActions = (props: {
5
+ export type MessageActions = ((props: {
6
6
  Component: typeof Action;
7
7
  message: Message;
8
8
  content: string;
9
9
  setMessage: (callback: (message: Message) => void) => void;
10
- }) => ReactNode;
11
- interface Props {
10
+ messages: Message[];
11
+ }) => ReactNode) | false;
12
+ export interface MessageItemProps {
12
13
  message: Message;
13
14
  actions?: MessageActions;
14
- updater: (callback: (message: Message) => void) => void;
15
+ setMessage: (callback: (message: Message) => void) => void;
15
16
  cite?: Components['cite'];
16
17
  speech?: {
17
18
  model?: string;
@@ -19,5 +20,5 @@ interface Props {
19
20
  autoplay?: boolean;
20
21
  };
21
22
  }
22
- declare const MessageItem: import("react").MemoExoticComponent<({ message, actions, updater, cite, speech }: Props) => JSX.Element>;
23
+ declare const MessageItem: import("react").MemoExoticComponent<({ message, actions, setMessage, cite, speech }: MessageItemProps) => import("react/jsx-runtime").JSX.Element>;
23
24
  export default MessageItem;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ reasoning: string;
4
+ loading?: boolean;
5
+ }
6
+ declare const Reasoning: import("react").MemoExoticComponent<({ reasoning, loading }: Props) => import("react/jsx-runtime").JSX.Element>;
7
+ export default Reasoning;
@@ -7,5 +7,5 @@ interface Props {
7
7
  contentRef: RefObject<HTMLDivElement>;
8
8
  autoplay?: boolean;
9
9
  }
10
- export default function SpeechAction({ model, voice, loading, autoplay, contentRef, avatarRef }: Props): JSX.Element;
10
+ export default function SpeechAction({ model, voice, loading, autoplay, contentRef, avatarRef }: Props): import("react/jsx-runtime").JSX.Element;
11
11
  export {};
@@ -1,7 +1,6 @@
1
- /// <reference types="react" />
2
1
  import { ToolMessage } from '../../types';
3
2
  interface Props {
4
3
  tool: ToolMessage;
5
4
  }
6
- export default function Tool({ tool }: Props): JSX.Element;
5
+ export default function Tool({ tool }: Props): import("react/jsx-runtime").JSX.Element;
7
6
  export {};
@@ -8,5 +8,5 @@ interface Props {
8
8
  onChange?: FormProps['onChange'];
9
9
  children?: ReactNode;
10
10
  }
11
- export default function VariableForm({ variables, values, onSubmit, onChange, children }: Props): JSX.Element;
11
+ export default function VariableForm({ variables, values, onSubmit, onChange, children }: Props): import("react/jsx-runtime").JSX.Element;
12
12
  export {};
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './types';
2
- export { default as MessageBox } from './components/message-box';
2
+ export { default as MessageBox, MessageBoxProps } from './components/message-box';
3
3
  export { default as ActionButton } from './components/action-button';
4
4
  export { default as Markdown } from './components/markdown';
5
5
  export { default as VariableForm } from './components/variable-form';
package/types/types.d.ts CHANGED
@@ -25,6 +25,7 @@ export interface Message {
25
25
  variables?: Record<string, string>;
26
26
  chunks?: {
27
27
  content: string;
28
+ reasoning?: string;
28
29
  tools: ToolMessage[];
29
30
  error?: string;
30
31
  }[];
@@ -58,7 +59,8 @@ export interface ConversationMessage {
58
59
  files?: [];
59
60
  variables?: Record<string, string>;
60
61
  chunks: {
61
- content?: '';
62
+ content?: string;
63
+ reasoning?: string;
62
64
  error?: string;
63
65
  tools?: ToolMessage[];
64
66
  }[];