@topthink/chat 1.3.20 → 1.3.22
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,7 +1,7 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as n,useAsync as i,css as o,formatSize as s,Tooltip as a,isCancel as l,isRequestError as c,Form as d,Toast as u,InfiniteScroller as m,useDebounce as h,Offcanvas as p,ModalForm as g,RequestButton as f,Loader as b,useImmer as v,getAbsoluteUrl as y,Lightbox as x,Clipboard as w,Button as k,isImageUrl as E,
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as n,useAsync as i,css as o,formatSize as s,Tooltip as a,isCancel as l,isRequestError as c,Form as d,Toast as u,InfiniteScroller as m,useDebounce as h,Offcanvas as p,ModalForm as g,RequestButton as f,Loader as b,useImmer as v,getAbsoluteUrl as y,Lightbox as x,Clipboard as w,Button as k,isImageUrl as E,formatLongNumber as N,request as C,SimpleBar as j}from"@topthink/components";import*as $ from"react";import{createContext as R,useContext as S,useRef as M,useCallback as F,useEffect as q,useState as z,forwardRef as A,useMemo as I,useImperativeHandle as L,Fragment as D,memo as P,Component as T}from"react";import*as O from"path";import B from"path";import{Spinner as U,Badge as _,Dropdown as H,FormControl as J,CloseButton as Q,OverlayTrigger as K,Popover as W}from"react-bootstrap";import X from"eventemitter3";import V from"react-textarea-autosize";import Y from"lodash/isEqual";import{toString as G}from"hast-util-to-string";import Z from"react-markdown";import"katex/dist/katex.min.css";import ee from"rehype-highlight";import te from"rehype-katex";import re from"rehype-raw";import ne from"remark-breaks";import ie from"remark-gfm";import oe from"remark-math";import{codes as se,types as ae}from"micromark-util-symbol";import{markdownLineEnding as le}from"micromark-util-character";import{createPortal as ce}from"react-dom";import de from"use-resize-observer";import{unified as ue}from"unified";import me from"rehype-stringify";import he from"remark-parse";import pe from"remark-rehype";function ge(e,t){return e.name===t}function fe({name:t,className:r}){const n=B.extname(t).substring(1),{result:o}=i(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}},[n]);return o?e(be,{src:o,className:r}):null}const be=n.img`
|
|
2
2
|
width: 30px;
|
|
3
3
|
height: 30px;
|
|
4
|
-
`;function
|
|
4
|
+
`;function ve({className:r,name:n,size:i=0,loading:o,error:l,onRemove:c,onClick:d}){const u=t(ke,{className:r,$error:!!l,onClick:d,children:[t(we,{children:[e(fe,{name:n}),o&&e(U,{variant:"primary"})]}),t(xe,{children:[e("h4",{children:n}),i>0&&e("p",{children:s(i,1)})]}),c&&e(ye,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(a,{placement:"top",tooltip:l,children:u}):u}const ye=n.div`
|
|
5
5
|
width: 1.75rem;
|
|
6
6
|
height: 1.75rem;
|
|
7
7
|
align-items: center;
|
|
@@ -16,7 +16,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
16
16
|
color: var(--bs-danger);
|
|
17
17
|
background-color: var(--bs-danger-bg-subtle);
|
|
18
18
|
}
|
|
19
|
-
`,
|
|
19
|
+
`,xe=n.div`
|
|
20
20
|
flex: 1;
|
|
21
21
|
overflow: hidden;
|
|
22
22
|
|
|
@@ -37,7 +37,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
37
37
|
line-height: 20px;
|
|
38
38
|
margin-bottom: 0;
|
|
39
39
|
}
|
|
40
|
-
`,
|
|
40
|
+
`,we=n.div`
|
|
41
41
|
position: relative;
|
|
42
42
|
width: 3rem;
|
|
43
43
|
height: 3rem;
|
|
@@ -51,7 +51,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
51
51
|
position: absolute;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
`,
|
|
54
|
+
`,ke=n.div`
|
|
55
55
|
display: flex;
|
|
56
56
|
gap: .5rem;
|
|
57
57
|
padding: .5rem;
|
|
@@ -68,7 +68,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
68
68
|
${e=>e.$error&&o`
|
|
69
69
|
border-color: var(--bs-danger) !important;
|
|
70
70
|
`}
|
|
71
|
-
`,
|
|
71
|
+
`,Ee=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],Ne=R(null),Ce=R(null);function je(){const e=S(Ne);if(!e)throw new Error("useChatContext must be used within a ChatProvider");return e}function $e(){return S(Ce)}function Re(){const e=S(Ne),t=S(Ce);if(!e||!t)throw new Error("useContext must be used within a Provider");return{...e,...t}}function Se({children:t,...r}){return e(Ne.Provider,{value:r,children:t})}function Me({children:t,...r}){const{request:n,loading:i,setLoading:o,inputRef:s,...a}=r;return e(Ne.Provider,{value:{request:n,loading:i,setLoading:o,inputRef:s},children:e(Ce.Provider,{value:a,children:t})})}function Fe({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&a.push(e.key)}),e(d,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const qe=n.button`
|
|
72
72
|
color: var(--bs-secondary);
|
|
73
73
|
cursor: pointer;
|
|
74
74
|
display: flex;
|
|
@@ -99,12 +99,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
99
99
|
}
|
|
100
100
|
`};
|
|
101
101
|
|
|
102
|
-
`;let
|
|
102
|
+
`;let ze=class{#e;#t;constructor(){this.#t=new X}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void u.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),u.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},Ae=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new X}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){u.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach(e=>e.stop()),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const Ie=A(({onResult:r,model:n="builtin"},i)=>{const{request:o}=je(),s=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:u}=function({onResult:e,loader:t}){const r=M(),[n,i]=z(!1),[o,s]=z(!1);return q(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new Ae(t):new ze,r.current.onRecording(i),r.current.onTranscribing(s),r.current.onResult(e)),r.current.start()},stop:()=>{r.current&&r.current.stop()}}}({onResult:r,loader:s});return L(i,()=>({start:l,stop:c}),[l,c]),e(a,{tooltip:d?"停止":"语音输入",placement:"top",children:t(qe,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[u&&e(Le,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Le=n(U)`
|
|
103
103
|
position: absolute;
|
|
104
104
|
--bs-spinner-width: .75rem;
|
|
105
105
|
--bs-spinner-height: .75rem;
|
|
106
106
|
--bs-spinner-border-width: 0.1em;
|
|
107
|
-
`,
|
|
107
|
+
`,De=A(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:s,onMouseDown:l},c)=>{const d=e(Pe,{ref:c,className:t,onClick:s,onMouseDown:l,$size:n,children:r});return i?e(a,{tooltip:i,placement:o,children:d}):d}),Pe=n.div`
|
|
108
108
|
width: 2rem;
|
|
109
109
|
height: 2rem;
|
|
110
110
|
align-items: center;
|
|
@@ -128,10 +128,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
128
128
|
&:hover {
|
|
129
129
|
background-color: var(--bs-secondary-bg-subtle);
|
|
130
130
|
}
|
|
131
|
-
`;function
|
|
131
|
+
`;function Te(){const{request:n,reset:i,conversationId:o}=Re(),[s,a]=z(!1),[l,c]=z(""),[d,u]=z(""),m=h(e=>{u(e)},500);return q(()=>{m(l)},[l]),t(r,{children:[e(De,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:e("i",{className:"bi bi-clock-history"})}),e(p,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:He,header:t(r,{children:[e("span",{children:"聊天历史记录"}),e(Je,{children:e(J,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:Oe,children:s&&e(_e,{children:e(Ue,{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)=>{const d=o===s.id;return t(D,{children:[l>0&&e("hr",{className:"mx-2 my-2"}),t(Be,{children:[d&&e(_,{bg:"secondary",children:"当前"}),e("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),t(H,{align:"end",children:[e(H.Toggle,{size:"sm",className:"no-caret",as:De,children:e("i",{className:"bi bi-three-dots-vertical"})}),t(H.Menu,{children:[e(g,{buttonProps:{as:H.Item},text:t(r,{children:[e("i",{className:"bi bi-pencil me-2"}),"重命名"]}),modalProps:{header:"编辑对话名称"},schema:{type:"object",properties:{title:{type:"string"}}},uiSchema:{title:{"ui:label":!1,"ui:autofocus":!0}},formData:{title:s.title},onRequest:e=>n({url:`/conversation/${s.id}`,method:"PUT",data:e}),onSuccess:(e,t)=>{c(e=>{const r=e.findIndex(e=>e.id===s.id);-1!==r&&Object.assign(e[r],t)})}}),t(f,{as:H.Item,confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${s.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===s.id);-1!==t&&e.splice(t,1)}),d&&i()},children:[e("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)}),l&&e(b,{wrap:!0})]}):e("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const Oe=n.div`
|
|
132
132
|
padding: 0;
|
|
133
133
|
overflow: hidden;
|
|
134
|
-
`,
|
|
134
|
+
`,Be=n.div`
|
|
135
135
|
gap: .5rem;
|
|
136
136
|
display: flex;
|
|
137
137
|
cursor: pointer;
|
|
@@ -150,33 +150,33 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
150
150
|
display: block;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
`,
|
|
153
|
+
`,Ue=n(m)`
|
|
154
154
|
display: flex;
|
|
155
155
|
flex-direction: column;
|
|
156
156
|
padding: .5rem;
|
|
157
|
-
`,
|
|
157
|
+
`,_e=n.div`
|
|
158
158
|
height: 100%;
|
|
159
159
|
overflow-y: auto;
|
|
160
|
-
`,
|
|
160
|
+
`,He=n.div`
|
|
161
161
|
display: flex;
|
|
162
162
|
align-items: center;
|
|
163
163
|
justify-content: space-between;
|
|
164
164
|
gap: 0.5rem;
|
|
165
165
|
flex: 1;
|
|
166
166
|
margin-right: .5rem;
|
|
167
|
-
`,
|
|
167
|
+
`,Je=n.div`
|
|
168
168
|
display: flex;
|
|
169
169
|
align-items: center;
|
|
170
170
|
gap: 0.5rem;
|
|
171
|
-
`;var
|
|
171
|
+
`;var Qe;function Ke(){return Ke=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},Ke.apply(null,arguments)}const We=e=>$.createElement("svg",Ke({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Qe||(Qe=$.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 Xe({onClick:t}){const{reset:r}=Re();return e(De,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:()=>t?.()??r(),children:e(We,{})})}function Ve({children:n,actions:i}){const o=t(r,{children:[e(Te,{}),e(Xe,{})]}),s="function"==typeof i?i({History:Te,Reset:Xe}):t(r,{children:[i,o]});return t(Ge,{children:[n,e(Ye,{children:s})]})}const Ye=n.div`
|
|
172
172
|
display: flex;
|
|
173
173
|
gap: .25rem;
|
|
174
174
|
margin-left: auto;
|
|
175
|
-
`,
|
|
175
|
+
`,Ge=n.div`
|
|
176
176
|
margin-bottom: .5rem;
|
|
177
177
|
display: flex;
|
|
178
178
|
padding: 0 .125rem;
|
|
179
|
-
`;var
|
|
179
|
+
`;var Ze=A(function({readonly:t,autoFocus:r,placeholder:n,minRows:i,maxRows:o,onSubmit:s,onFocusedChange:a,onQueryChange:l,onPaste:c},d){const u=M(null),[m,h]=z(""),p=F(()=>{const e=u.current;if(!e)return;e.focus();const t=e.value.length;e.setSelectionRange(t,t)},[]),g=F(e=>{const t="string"==typeof e?e:e(m);h(t),l?.(t.trim()),requestAnimationFrame(()=>{p()})},[m,l,p]);return L(d,()=>({setContent:g,focus(){p()}}),[g,p]),e(et,{ref:u,value:m,minRows:i,maxRows:o,readOnly:t,autoFocus:r,placeholder:n,onFocus:()=>a?.(!0),onBlur:()=>a?.(!1),onChange:e=>{h(e.target.value),l?.(e.target.value.trim())},onPaste:e=>{c?.(e.nativeEvent)},onKeyDown:e=>{e.nativeEvent.isComposing||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),e.stopPropagation(),s?.())}})});const et=n(V)`
|
|
180
180
|
min-height: calc(1.5em + 1rem);
|
|
181
181
|
width: 100%;
|
|
182
182
|
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
|
@@ -185,14 +185,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
185
185
|
resize: none;
|
|
186
186
|
line-height: 1.5;
|
|
187
187
|
background: transparent;
|
|
188
|
-
`;var
|
|
188
|
+
`;var tt=A(function({className:r,fileTypes:n,speech:i,scrollRef:o,variables:s,minRows:d=1,maxRows:m=5,toolbar:h,toolbarActions:p,disabled:g,autoFocus:f,tools:b,renderEditableInput:y,placeholder:x="请输入你的问题, Enter+Shift换行, Enter发送",supportStop:w=!1,onEvent:k,onNewConversation:E},N){const C=M(null),j=M(null),$=M(null),[R,S]=z(""),[A,D]=z(""),[P,T]=v([]),[B,U]=z(!1),_=n&&n.length>0?n:Ee,H=F(()=>{requestAnimationFrame(()=>{$.current?.focus()})},[]),{send:J,resume:K,stop:W}=function(e){const{setLoading:t,request:r}=je(),n=$e(),i=n?.setMessages,o=n?.setConversationId,s=n?.conversationId,a=n?.messages,d=!0===e?.supportStop,{onEvent:u,onNewConversation:m,onComplete:h}=e??{},p=M(null),g=M(),f=M(s),b=()=>(p.current&&p.current.abort(),p.current=new AbortController,p.current.signal),v=F(e=>{const t=(e,r)=>{Object.entries(r).forEach(([r,n])=>{if("string"!=typeof n)if(!n||"object"!=typeof n||Array.isArray(n))e[r]=n;else if("index"in n){const{index:i,...o}=n;Array.isArray(e[r])||(e[r]=[]),e[r][i]||(e[r][i]={}),t(e[r][i],o)}else e[r]=n;else e[r]="string"==typeof e[r]?e[r]+n:n})};if(e.data)if("[DONE]"!=e.data)try{const r=JSON.parse(e.data);r.conversation?(f.current=r.conversation,o?.(r.conversation)):r.event?u?.(r.event):i?.(e=>{const n=e[e.length-1];if(r.chunks){if(n.chunks){const e=r.chunks.index;if(!r.chunks.init&&n.chunks[e]||(n.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)n.chunks[e].error=r.chunks.error;else if(r.chunks.tools){n.chunks[e].tools||(n.chunks[e].tools=[]);const{index:i,...o}=r.chunks.tools;n.chunks[e].tools[i]||(n.chunks[e].tools[i]={name:"",title:"",arguments:""}),t(n.chunks[e].tools[i],o)}else if(r.chunks.reasoning)n.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(n.chunks[e].content)||(n.chunks[e].content=[]);const t=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(n.chunks[e].content[t]||(n.chunks[e].content[t]=""),n.chunks[e].content[t]+=i):n.chunks[e].content[t]=i}else n.chunks[e].content+=r.chunks.content;else r.chunks.node&&(n.chunks[e].node={...n.chunks[e].node,...r.chunks.node})}}else r.stats?n.stats=r.stats:r.id&&(n.id=r.id)})}catch(e){console.error(e)}else i?.(e=>{e[e.length-1].loading=!1})},[u]),y=F(e=>{if(l(e))i?.(e=>{const t=e[e.length-1];t&&(t.loading=!1)});else{let t="未知错误";c(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),i?.(e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{error:t}]:r.chunks[r.chunks.length-1].error=t),r.loading=!1})}},[]),x=F(async e=>{g.current=e;try{const n=b();t(!0),i?.(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let o={url:"message",method:"get",params:{id:e},onMessage:v,signal:n};await r(o)}catch(e){y(e)}finally{p.current=null,g.current=void 0}t(!1),h?.()},[r,u,m,h]),w=F(async(e,...o)=>{"string"==typeof e&&(e={query:e,...o});const{query:s,files:a=[],variables:l={},extra:c={},quote:d}=e;let u=null,g=null;if(s||a.length>0){const e=b();t(!0),n?.setSuggestions?.([]),i?.(e=>{e.push({query:s,quote:d,files:a,variables:l,chunks:[],loading:!0})});try{let t={method:"post",data:{query:s,quote:d,files:a,variables:l,extra:c,conversation:f.current},onMessage:v,signal:e};const n=await r(t);u=n.message??null,g=n.conversation??null}catch(e){y(e)}finally{p.current=null}if(u){let e=!1;g&&!f.current&&(e=m?.(g)??!1),e||await x(u.id)}else t(!1),h?.()}},[r,u,m,h]),k=F(async e=>{let n=null;try{const o=b();t(!0),i?.(e=>{e[e.length-1].loading=!0});let s={url:"resume",method:"post",data:{conversation:f.current,chunk:e.chunk,tool:e.tool,payload:e.payload},onMessage:v,signal:o};n=(await r(s)).message??null}catch(e){y(e)}finally{p.current=null}n?await x(n.id):(t(!1),h?.())},[r,u,m,h]),E=F(async()=>{if(d)if(g.current)try{await r({url:"stop",method:"post",data:{id:g.current}})}catch{}else p.current?.abort()},[r,d]),N=()=>{const e=a?.[a.length-1];e&&e.id&&2===e.status&&x(e.id)};return q(()=>(N(),()=>{p.current&&p.current.abort()}),[]),q(()=>{s!=f.current&&(f.current=s,p.current&&p.current.abort(),N())},[s]),{send:w,resume:k,stop:E}}({supportStop:w,onEvent:k,onNewConversation:E,onComplete:H}),{loading:X,request:V,inputRef:Y}=je(),G=$e(),[Z,ee]=z(),[te,re]=v({});q(()=>{const e=(G?.messages||[]).filter(e=>!!e.query);ee(e.at(-1)?.variables)},[G?.messages]),q(()=>{!n&&P.length>0&&T([])},[n]),q(()=>{const e=o?.current;if(e){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};s&&(t.variables={...Z,...s.values}),J(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[s,Z]);const ne=F(e=>{const t=e.map((e,t)=>{if(e.name)return e;const r=e.type.split("/")[1]||"png";return new File([e],`screenshot-${Date.now()}-${t}.${r}`,{type:e.type})}).filter(e=>!(!_.includes("*")&&!_.includes(O.extname(e.name)))&&!(e.size>20971520)).slice(0,6-P.length);return 0!==t.length&&(T(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await V({method:"POST",url:"/upload",data:t});T(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=c(t)?t.message:"unknown error";T(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}}),!0)},[P.length,_,V,T]),ie=F(({target:e})=>{e.files&&ne(Array.from(e.files)),e.value=""},[ne]),oe=F(e=>{const t=Array.from(e.clipboardData?.files||[]),r=Array.from(e.clipboardData?.items||[]).filter(e=>"file"===e.kind).map(e=>e.getAsFile()).filter(e=>!!e),n=t.length>0?t:r;0!==n.length&&ne(n)&&e.preventDefault()},[ne]),se=P.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),ae=F(()=>{if(R||se.length>0){const e={query:R,files:se,extra:te};s&&(e.variables={...Z,...s.values}),A&&(e.quote=A),J(e),$.current?.setContent(""),D(""),T([]),j.current?.stop(!0)}},[R,se,s,Z,te,A]),le=I(()=>{const e={setQuery(e){$.current?.setContent(e)},setQuote:D,setExtra:re,send:J,resume:K,focus(){$.current?.focus()}};return Y.current=e,e},[D,re,J,K]);if(L(N,()=>le,[le]),s){const t=s.config.filter(e=>!(e.key in(s.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&u.error("请完善必填信息"),n});if(t.length>0&&!r(Z))return e(nt,{children:e(rt,{children:e(Fe,{values:Z,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return ee(e),!0}})})})}return t("div",{className:r,children:[h&&e(Ve,{actions:p,children:h}),t(ct,{$focused:B&&!X,children:[P.length>0&&e(ot,{children:P.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(it,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{T(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!A&&t(lt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:A}),e(Q,{onClick:()=>D("")})]}),t(st,{$minRows:d,children:[y?.({Component:Ze,props:{ref:$,readonly:X||g,autoFocus:f,placeholder:x,minRows:d,maxRows:m,onSubmit:ae,onFocusedChange:U,onQueryChange:S,onPaste:oe}})||e(Ze,{ref:$,readonly:X||g,autoFocus:f,placeholder:x,minRows:d,maxRows:m,onSubmit:ae,onFocusedChange:U,onQueryChange:S,onPaste:oe}),t(at,{children:[b,n&&e(a,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(qe,{disabled:P.length>=6,onClick:()=>C.current?.click(),children:[e("input",{onChange:ie,multiple:!0,accept:_.join(","),ref:C,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e(Ie,{ref:j,model:i.model,onResult:e=>{$.current?.setContent(t=>t+e+" ")}}),e(qe,{$fill:X&&w,className:X&&w?"text-danger":"text-primary",disabled:!R&&0===se.length&&!X||X&&!w,onClick:e=>{e.preventDefault(),X&&w?W():ae()},children:e("i",X&&w?{className:"bi bi-square-fill fs-7"}:{className:"bi bi-send-fill"})})]})]})]})]})});const rt=n.div`
|
|
189
189
|
border-radius: var(--bs-border-radius-lg);
|
|
190
190
|
box-shadow: var(--bs-box-shadow-sm);
|
|
191
191
|
margin: 1rem;
|
|
192
192
|
padding: 1rem;
|
|
193
193
|
width: 100%;
|
|
194
194
|
max-width: 500px;
|
|
195
|
-
`,
|
|
195
|
+
`,nt=n.div`
|
|
196
196
|
position: absolute;
|
|
197
197
|
left: 0;
|
|
198
198
|
right: 0;
|
|
@@ -202,26 +202,26 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
202
202
|
display: flex;
|
|
203
203
|
justify-content: center;
|
|
204
204
|
align-items: center;
|
|
205
|
-
`,
|
|
205
|
+
`,it=n(ve)`
|
|
206
206
|
width: calc((100% - 0.75rem) / 2);
|
|
207
|
-
`,
|
|
207
|
+
`,ot=n.div`
|
|
208
208
|
display: flex;
|
|
209
209
|
flex-wrap: wrap;
|
|
210
210
|
padding: 0.75rem;
|
|
211
211
|
gap: 0.75rem;
|
|
212
212
|
border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
|
|
213
|
-
`,
|
|
213
|
+
`,st=n.div`
|
|
214
214
|
display: flex;
|
|
215
215
|
gap: 0.2rem;
|
|
216
216
|
align-items: ${e=>e.$minRows&&e.$minRows>1?"stretch":"end"};
|
|
217
217
|
flex-direction: ${e=>e.$minRows&&e.$minRows>1?"column":"row"};
|
|
218
|
-
`,
|
|
218
|
+
`,at=n.div`
|
|
219
219
|
display: flex;
|
|
220
220
|
flex-direction: row;
|
|
221
221
|
justify-content: end;
|
|
222
222
|
gap: 0.25rem;
|
|
223
223
|
padding: 0.375rem 0.5rem 0.375rem 0.5rem;
|
|
224
|
-
`,
|
|
224
|
+
`,lt=n.div`
|
|
225
225
|
margin: 0.75rem 0.75rem 0 0.75rem;
|
|
226
226
|
padding: 4px 8px;
|
|
227
227
|
display: flex;
|
|
@@ -242,12 +242,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
242
242
|
-webkit-box-orient: vertical;
|
|
243
243
|
display: -webkit-box;
|
|
244
244
|
}
|
|
245
|
-
`,
|
|
245
|
+
`,ct=n.div`
|
|
246
246
|
background: #fff;
|
|
247
247
|
border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
|
|
248
248
|
border-radius: var(--bs-border-radius-lg);
|
|
249
249
|
box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
|
|
250
|
-
`;function
|
|
250
|
+
`;function dt(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,context:e.context,latency:e.latency},status:e.status??1}))}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 mt,ht,pt;function gt(){return gt=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},gt.apply(null,arguments)}const ft=e=>$.createElement("svg",gt({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),mt||(mt=$.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},$.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),$.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),ht||(ht=$.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},$.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),$.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),pt||(pt=$.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},$.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),$.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function bt(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`})`}return""}const vt=function(e,t,r){function n(t){return t!==se.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(ae.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===se.rightSquareBracket?(e.exit(ae.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==se.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):le(n)||n===se.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==se.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},yt=function(){const e=this.data();e.micromarkExtensions.push({text:{[se.leftSquareBracket]:{tokenize:vt}}}),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}}})},xt=x.Image,wt={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=z(!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]);q(()=>{s&&o(s)},[s]);const a=I(()=>G(n),[n]);return t($t,{children:[t(jt,{children:[!i&&e(w,{tooltip:!1,as:Ct,content:a}),s&&i&&e(Ct,{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(Ct,{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(xt,{...r,lazy:!1})},kt=[[oe,{singleDollarTextMath:!1}],ie,ne],Et=[[re,{tagfilter:!0}],te,[ee,{detect:!1,ignoreMissing:!0}]],Nt=P(A(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=I(()=>{const e={...wt,...r};return n&&(e.cite=n),e},[r,n]),s=I(()=>n?[...kt,yt]:kt,[n]);return e(Rt,{ref:i,children:e(Z,{remarkPlugins:s,rehypePlugins:Et,components:o,children:t})})}),Y),Ct=n.div`
|
|
251
251
|
cursor: pointer;
|
|
252
252
|
padding: 2px 10px;
|
|
253
253
|
background-color: #303030;
|
|
@@ -271,7 +271,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
271
271
|
&:hover {
|
|
272
272
|
opacity: 1;
|
|
273
273
|
}
|
|
274
|
-
|
|
274
|
+
`,$t=n.div`
|
|
275
275
|
position: relative;
|
|
276
276
|
|
|
277
277
|
&:hover {
|
|
@@ -281,7 +281,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
281
281
|
opacity: 0.7;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
`,Rt=n.div`
|
|
285
285
|
-ms-text-size-adjust: 100%;
|
|
286
286
|
-webkit-text-size-adjust: 100%;
|
|
287
287
|
line-height: 1.8;
|
|
@@ -551,7 +551,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
551
551
|
.hljs-strong {
|
|
552
552
|
font-weight: 700;
|
|
553
553
|
}
|
|
554
|
-
`;var
|
|
554
|
+
`;var St=A(function({children:t,tooltip:r,onClick:n,disabled:i,...o},s){i&&(n=void 0);const l=e(Mt,{ref:s,onClick:n,$disabled:i,...o,children:t});return r?e(a,{tooltip:r,placement:"top",children:l}):l});const Mt=n.div`
|
|
555
555
|
align-items: center;
|
|
556
556
|
justify-content: center;
|
|
557
557
|
border-radius: .375rem;
|
|
@@ -584,7 +584,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
584
584
|
`}
|
|
585
585
|
|
|
586
586
|
}
|
|
587
|
-
`,
|
|
587
|
+
`,Ft=R(null);var qt=Ft.Provider;const zt=x.Image;function At({src:t,...r}){const{imageResolver:n}=Re();return n&&t&&(t=n(t)),e(It,{children:e(zt,{src:t,...r})},t)}const It=n.div`
|
|
588
588
|
margin-bottom: .5rem;
|
|
589
589
|
margin-top: .5rem;
|
|
590
590
|
border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
|
|
@@ -609,7 +609,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
609
609
|
max-height: 100%;
|
|
610
610
|
max-width: 100%;
|
|
611
611
|
}
|
|
612
|
-
`,
|
|
612
|
+
`,Lt=R(null);function Dt(){const e=S(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 Tt(e){const[t,r]=z(e);return q(()=>{r(e)},[e]),[t,r]}function Ot({description:r,options:n}){const{resume:i,disabled:o,response:s}=Dt(),[a,l]=Tt(s?.result),c=o||void 0!==a;return t(Bt,{children:[r&&e(Ut,{children:r}),n.map((t,r)=>e(_t,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const Bt=n.div`
|
|
613
613
|
display: flex;
|
|
614
614
|
flex-direction: column;
|
|
615
615
|
gap: 0.5rem;
|
|
@@ -622,10 +622,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
622
622
|
&:last-child {
|
|
623
623
|
margin-bottom: 0;
|
|
624
624
|
}
|
|
625
|
-
`,
|
|
625
|
+
`,Ut=n.div`
|
|
626
626
|
color: var(--bs-secondary);
|
|
627
627
|
line-height: 1.5;
|
|
628
|
-
`,
|
|
628
|
+
`,_t=n.div`
|
|
629
629
|
padding: 0.375rem 0.75rem;
|
|
630
630
|
background-color: ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.1)":"#FFFFFF"};
|
|
631
631
|
border: 1px solid ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.3)":"var(--bs-border-color)"};
|
|
@@ -644,7 +644,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
644
644
|
&:active {
|
|
645
645
|
transform: ${e=>e.$disabled?"none":"scale(0.98)"};
|
|
646
646
|
}
|
|
647
|
-
`;function
|
|
647
|
+
`;function Ht({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Dt(),[a,l]=Tt(void 0!==s),c=o||a,{schema:u,uiSchema:m}=I(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"string",title:i.label,default:i.default},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"number"===i.type?(e[i.name].type="number",void 0!==i.default&&(e[i.name].default=Number(i.default))):"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},"string"==typeof i.default&&(e[i.name].default=i.default.split(",")),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(Kt,{children:r}),e(d,{schema:u,uiSchema:m,formData:s,onSubmit:({formData:e})=>{c||(l(!0),i(e))},disabled:c,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Jt,{children:t})})]})}const Jt=n.div`
|
|
648
648
|
display: flex;
|
|
649
649
|
justify-content: flex-end;
|
|
650
650
|
border-top: 1px solid var(--bs-border-color);
|
|
@@ -653,7 +653,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
653
653
|
button {
|
|
654
654
|
padding: .25rem;
|
|
655
655
|
}
|
|
656
|
-
`,
|
|
656
|
+
`,Qt=n.div`
|
|
657
657
|
display: flex;
|
|
658
658
|
flex-direction: column;
|
|
659
659
|
gap: 0.5rem;
|
|
@@ -671,10 +671,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
671
671
|
&:last-child {
|
|
672
672
|
margin-bottom: 0;
|
|
673
673
|
}
|
|
674
|
-
`,
|
|
674
|
+
`,Kt=n.div`
|
|
675
675
|
color: var(--bs-secondary);
|
|
676
676
|
line-height: 1.5;
|
|
677
|
-
`;function
|
|
677
|
+
`;function Wt({content:r}){const{resume:n,disabled:i,response:o}=Dt(),[s,a]=Tt(void 0!==o),l=i||s;return t(Xt,{className:"rounded bg-white shadow-sm",children:[r&&e(Vt,{children:e(Nt,{content:r})}),e(Yt,{children:e(k,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Xt=n.div`
|
|
678
678
|
display: flex;
|
|
679
679
|
flex-direction: column;
|
|
680
680
|
gap: .5rem;
|
|
@@ -688,10 +688,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
688
688
|
&:last-child {
|
|
689
689
|
margin-bottom: 0;
|
|
690
690
|
}
|
|
691
|
-
`,
|
|
691
|
+
`,Vt=n.div`
|
|
692
692
|
line-height: 1.6;
|
|
693
693
|
color: var(--bs-body-color);
|
|
694
|
-
`,
|
|
694
|
+
`,Yt=n.div`
|
|
695
695
|
display: flex;
|
|
696
696
|
justify-content: flex-end;
|
|
697
697
|
border-top: 1px solid var(--bs-border-color);
|
|
@@ -700,27 +700,41 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
700
700
|
button {
|
|
701
701
|
padding: .25rem 1.5rem;
|
|
702
702
|
}
|
|
703
|
-
`;function
|
|
703
|
+
`;function Gt(e){return e instanceof Error&&e.message||String(e)}class Zt extends T{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onRenderError(e)}render(){return this.state.hasError?null:this.props.children}}function er({suspend:t}){const{readonly:r,inputRef:n}=Re(),{chunkIndex:i,chunk:o,toolIndex:s,tool:a,isLastMessage:l}=function(){const e=S(Ft);if(!e)throw new Error("useContext must be used within a Provider");return e}(),c=F(e=>{n.current?.resume({chunk:i,tool:s,payload:e})},[i,s]),d=F(e=>{c({error:Gt(e)})},[c]);let u=null;switch(t.type){case"select":u=e(Ot,{...t.select});break;case"form":u=e(Ht,{...t.form});break;case"confirm":u=e(Wt,{...t.confirm})}const m=a?.response||o.node?.output;return e(Pt,{resume:c,disabled:r||!!o.error||!l,response:"(Empty)"===m?void 0:m,children:e(Zt,{onRenderError:d,children:u})})}function tr({value:t,cite:n}){const i=t=>"string"==typeof t?e(Nt,{content:t,cite:n}):"image"===t.type?e(At,{src:t.image}):"suspend"===t.type?e(er,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(D,{children:i(t)},r))}):i(t)}const rr=({reasoning:r,loading:n})=>{const[i,o]=z(!1);return q(()=>{n||o(!1)},[n]),e(D,{children:e("div",{className:"mb-2",children:t("div",i?{className:"border 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(U,{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(Nt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(U,{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"})]})})})},nr=P(t=>{const{renderReasoning:r}=Re();return r?r({Component:rr,props:t}):e(rr,{...t})}),ir=e=>null==e?"None":"object"==typeof e?JSON.stringify(e,null,2):e;function or({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=Re(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:u,defaultExpanded:m}=I(()=>{const i=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),a=e("span",{className:"text-truncate",children:r.title}),l=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(ar,{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(ar,{className:"border-top p-2",children:ir(r.response)})]})]}),c=r.content&&e(tr,{value:r.content});if(o){const e=o({tool:r,args:i,loading:n});if(e)return{title:null===e.title?null:e.title??a,response:null===e.response?null:e.response??l,content:null===e.content?null:e.content??c,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=z(m),g="all"==i&&null!==l;return t(D,{children:[c&&e("div",{className:"mb-2",children:t(sr,{className:"border 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(U,{animation:"border",variant:"primary",size:"sm"}),u&&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 sr=n.div`
|
|
704
704
|
width: ${e=>e.$open?"auto":"fit-content"};
|
|
705
705
|
max-width: 100%;
|
|
706
706
|
overflow: hidden;
|
|
707
|
-
`,
|
|
707
|
+
`,ar=n.div`
|
|
708
708
|
white-space: pre-wrap;
|
|
709
709
|
overflow-y: auto;
|
|
710
710
|
overflow-x: hidden;
|
|
711
711
|
max-height: 150px;
|
|
712
|
-
`;function
|
|
712
|
+
`;function lr({node:r}){const[n,i]=z(!1),{nodeIconResolver:o}=Re(),s=!("latency"in r),a=s?e(U,{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(dr,{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(ur,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:cr(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 cr=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`,dr=n.div`
|
|
713
713
|
svg {
|
|
714
714
|
flex-shrink: 0;
|
|
715
715
|
}
|
|
716
|
-
`,
|
|
716
|
+
`,ur=n.span`
|
|
717
717
|
display: inline-block;
|
|
718
|
-
`;function
|
|
718
|
+
`;function mr({nodes:r,loading:n}){const[i,o]=z(!1),s=r.some(e=>"error"in e),a=n?e(U,{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:"border 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(lr,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border 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 hr=P(A(({chunks:r,loading:n,cite:i,isLast:o=!1,deleted:s=!1},a)=>{const{logLevel:l="none",showChunkOnCollapse:c,collapsible:d=!0}=Re(),u=I(()=>r.flatMap(e=>e.node?[e.node]:[]),[r]),{hiddenChunks:m,operationCount:h}=I(()=>{const e=new Set;let t=0;return r.forEach((r,n)=>{(c?c(r,n):0===(r.tools||[]).length)||(e.add(n),t+=(r.tools||[]).length)}),{hiddenChunks:e,operationCount:t}},[r,c]),p=d&&h>0,[g,f]=z(!1);return q(()=>{p&&f(!n)},[n,p]),t(pr,{ref:a,$deleted:s,children:[p&&!n&&e("div",{className:"mb-2",children:t(gr,{onClick:()=>f(!g),role:"button",className:"d-inline-flex align-items-center fs-7 gap-1",children:[t("span",{children:["完成了 ",h," 个操作"]}),e("i",g?{className:"bi bi-caret-down-fill"}:{className:"bi bi-caret-up-fill"})]})}),!g&&"all"===l&&u.length>0&&e(mr,{loading:n,nodes:u}),r.map((r,s)=>g&&m.has(s)?null:t(D,{children:[r.reasoning&&["stats","all"].includes(l)&&e(nr,{reasoning:r.reasoning,loading:n&&!r.content&&0===(r.tools||[]).length}),r.content&&e(qt,{value:{chunkIndex:s,chunk:r,isLastMessage:o},children:e(tr,{cite:i,value:r.content})}),(r.tools||[]).map((t,i)=>e(qt,{value:{chunkIndex:s,chunk:r,toolIndex:i,tool:t,isLastMessage:o},children:e(or,{tool:t,loading:n})},i)),r.error&&e(Nt,{content:`[${r.error}]`})]},s))]})})),pr=n.div`
|
|
719
719
|
${e=>e.$deleted&&o`
|
|
720
720
|
text-decoration-line: line-through;
|
|
721
721
|
color: var(--bs-secondary);
|
|
722
722
|
`}
|
|
723
|
-
|
|
723
|
+
`,gr=n.div`
|
|
724
|
+
color: var(--bs-gray-500);
|
|
725
|
+
opacity: .75;
|
|
726
|
+
transition: opacity .15s ease;
|
|
727
|
+
|
|
728
|
+
&:hover {
|
|
729
|
+
opacity: 1;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
.spinner-border {
|
|
733
|
+
width: .75rem;
|
|
734
|
+
height: .75rem;
|
|
735
|
+
border-width: .1em;
|
|
736
|
+
}
|
|
737
|
+
`;class fr{#t;#o=[];#s=0;constructor(){this.#t=new X}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 br=new Map;class vr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new X}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?(br.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),br.delete(this)}start(e,t=!1){br.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=br.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function yr({text:e,loading:t,loader:r}){const n=M(),[i,o]=z(!1),[s,a]=z(!1),l=M(t),c=async(i=!1)=>{n.current||(n.current=r?new vr(r):new fr,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 q(()=>{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]),q(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function xr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=Re(),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:u,start:m,stop:h}=yr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=ce(e(wr,{children:e(U,{size:"sm",variant:"light"})}),a.current)),d&&(p=ce(e(wr,{children:e(kr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(St,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?e(kr,{className:"bi bi-volume-down-fill"}):u?e(U,{size:"sm",variant:"primary"}):e(kr,{className:"bi bi-volume-down"}),p]})}const wr=n.div`
|
|
724
738
|
position: absolute;
|
|
725
739
|
top: 0;
|
|
726
740
|
left: 0;
|
|
@@ -730,12 +744,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
730
744
|
align-items: center;
|
|
731
745
|
justify-content: center;
|
|
732
746
|
background-color: rgba(0, 0, 0, .3);
|
|
733
|
-
`,
|
|
747
|
+
`,kr=n.i`
|
|
734
748
|
|
|
735
749
|
&::before {
|
|
736
750
|
transform: scale(1.4)
|
|
737
751
|
}
|
|
738
|
-
`,
|
|
752
|
+
`,Er=P(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:u=[],chunks:m,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v,renderFileItem:y}=Re(),x=I(()=>m?m.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=bt(t);return r?e+r+"\n":e},""):bt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=bt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[m]),k=M(null),C=M(null),j=M(null),$=c||u.length>0;return t(r,{children:[$&&t(zr,{$reverse:!0,children:[g&&t(r,{children:[e(Mr,{children:e("img",{src:g.avatar})}),e(Fr,{})]}),t(qr,{ref:k,children:[c&&e(Nt,{content:c}),d&&e(K,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:e(Nr,{body:!0,children:d}),children:e(jr,{children:e(Cr,{children:d})})}),u.length>0&&u.map(({name:t,size:r,path:n},i)=>{if(E(n))return e(At,{src:`/uploads/${n}`},i);const o={name:t,url:`/uploads/${n}`,size:r};return e($r,{children:y?y({Component:ve,props:o}):e(ve,{...o})},i)})]})]}),m&&t(zr,{children:[f&&t(r,{children:[e(Mr,{ref:C,children:e("img",{src:f.avatar})}),e(Fr,{})]}),t(qr,{children:[$&&!1!==i&&t(Rr,{children:[e(w,{placement:"top",content:x,as:St,tooltip:!0}),a&&e(xr,{loading:n.loading,avatarRef:C,contentRef:j,...a}),i?.({Component:St,message:n,content:x,setMessage:o,messages:v})]}),e(Sr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 ",N(n.stats.usage)," Credits"]})]})}),e(hr,{ref:j,chunks:m,loading:p,isLast:l,cite:s,deleted:!!h}),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(Nt,{content:h.answer})]}),n.loading&&e(ft,{})]})]})]})}),Nr=n(W)`
|
|
739
753
|
max-width: calc(100% - .875rem * 2);
|
|
740
754
|
width: calc(100% - .875rem * 2);
|
|
741
755
|
font-size: 1rem;
|
|
@@ -744,20 +758,20 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
744
758
|
.popover-body {
|
|
745
759
|
padding: .5rem .75rem;
|
|
746
760
|
}
|
|
747
|
-
`,
|
|
761
|
+
`,Cr=n.div`
|
|
748
762
|
overflow: hidden;
|
|
749
763
|
text-overflow: ellipsis;
|
|
750
764
|
word-break: break-all;
|
|
751
765
|
-webkit-line-clamp: 2;
|
|
752
766
|
-webkit-box-orient: vertical;
|
|
753
767
|
display: -webkit-box;
|
|
754
|
-
`,
|
|
768
|
+
`,jr=n.div`
|
|
755
769
|
padding: .5rem .75rem;
|
|
756
770
|
color: var(--bs-secondary);
|
|
757
771
|
border-radius: var(--bs-border-radius-lg);
|
|
758
772
|
background: #FFFFFF;
|
|
759
773
|
cursor: pointer;
|
|
760
|
-
|
|
774
|
+
`,$r=n.div`
|
|
761
775
|
width: 100%;
|
|
762
776
|
margin-bottom: .5rem;
|
|
763
777
|
margin-top: .5rem;
|
|
@@ -769,7 +783,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
769
783
|
&:last-child {
|
|
770
784
|
margin-bottom: 0;
|
|
771
785
|
}
|
|
772
|
-
`,
|
|
786
|
+
`,Rr=n.div`
|
|
773
787
|
position: absolute;
|
|
774
788
|
top: -1.1rem;
|
|
775
789
|
right: 0;
|
|
@@ -777,7 +791,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
777
791
|
gap: .5rem;
|
|
778
792
|
opacity: 0;
|
|
779
793
|
z-index: 1;
|
|
780
|
-
|
|
794
|
+
`,Sr=n.div`
|
|
781
795
|
position: absolute;
|
|
782
796
|
bottom: -1.4rem;
|
|
783
797
|
left: 0;
|
|
@@ -790,7 +804,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
790
804
|
display: flex;
|
|
791
805
|
opacity: 0;
|
|
792
806
|
z-index: 1;
|
|
793
|
-
`,
|
|
807
|
+
`,Mr=n.div`
|
|
794
808
|
width: 35px;
|
|
795
809
|
height: 35px;
|
|
796
810
|
border-radius: 50%;
|
|
@@ -801,14 +815,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
801
815
|
width: 100%;
|
|
802
816
|
height: 100%;
|
|
803
817
|
}
|
|
804
|
-
`,
|
|
818
|
+
`,Fr=n.div`
|
|
805
819
|
width: 0;
|
|
806
820
|
height: 0;
|
|
807
821
|
content: "";
|
|
808
822
|
border: 5px solid transparent;
|
|
809
823
|
border-right-color: #f3f3f3;
|
|
810
824
|
transform: translateY(10px);
|
|
811
|
-
`,
|
|
825
|
+
`,qr=n.div`
|
|
812
826
|
padding: .875rem;
|
|
813
827
|
background-color: rgb(243, 243, 243);
|
|
814
828
|
border-radius: var(--bs-border-radius-lg);
|
|
@@ -816,32 +830,32 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
816
830
|
position: relative;
|
|
817
831
|
|
|
818
832
|
&:hover {
|
|
819
|
-
${
|
|
833
|
+
${Sr}, ${Rr} {
|
|
820
834
|
opacity: 1;
|
|
821
835
|
}
|
|
822
836
|
}
|
|
823
|
-
`,
|
|
837
|
+
`,zr=n.div`
|
|
824
838
|
display: flex;
|
|
825
839
|
justify-content: flex-start;
|
|
826
840
|
padding: 1rem 0 1rem 0;
|
|
827
841
|
${e=>e.$reverse&&o`
|
|
828
842
|
flex-direction: row-reverse;
|
|
829
843
|
|
|
830
|
-
${
|
|
844
|
+
${Fr} {
|
|
831
845
|
border-left-color: rgba(var(--bs-primary-rgb), 0.1);
|
|
832
846
|
border-right-color: transparent;
|
|
833
847
|
}
|
|
834
848
|
|
|
835
|
-
${
|
|
849
|
+
${qr} {
|
|
836
850
|
background: rgba(var(--bs-primary-rgb), 0.1);
|
|
837
851
|
}
|
|
838
852
|
`};
|
|
839
|
-
`;function
|
|
853
|
+
`;function Ar(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:u,suggestions:m,conversationId:p}=Re(),g=M(r.loaded),f=M(!0),b=M(!1);q(()=>{const e=l.current;if(!e)return;const t=()=>{b.current=!0},r=()=>{if(!b.current)return;const t=e.scrollHeight-e.scrollTop-e.clientHeight<50;f.current=t,t&&(b.current=!1)};return e.addEventListener("wheel",t,{passive:!0}),e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("scroll",r,{passive:!0}),()=>{e.removeEventListener("wheel",t),e.removeEventListener("touchstart",t),e.removeEventListener("scroll",r)}},[l]);const v=h(()=>{if(!f.current)return;const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},200),y=M(null),{height:x}=de({ref:y});q(()=>{(u||!g.current)&&c.length>0&&(u&&(g.current=!0),v())},[x,u,g,c]),q(()=>{m.length>0&&v()},[m]),q(()=>{g.current=r.loaded},[p]),q(()=>{const e=y.current;if(e){const t=()=>{g.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[y]);const w=c.slice(-30);return t(Ir,{ref:y,children:[0===w.length&&n,w.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===w.length-1};return a?e(D,{children:a({Component:Er,props:n})},r):e(Er,{...n},r)}),m.length>0&&e(Lr,{children:m.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Ir=n.div`
|
|
840
854
|
display: flex;
|
|
841
855
|
flex-direction: column;
|
|
842
856
|
flex: 1;
|
|
843
857
|
margin-bottom: .5rem;
|
|
844
|
-
`,
|
|
858
|
+
`,Lr=n.div`
|
|
845
859
|
display: flex;
|
|
846
860
|
flex-direction: column;
|
|
847
861
|
align-items: flex-start;
|
|
@@ -858,7 +872,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
858
872
|
background: var(--bs-secondary-bg-subtle);
|
|
859
873
|
}
|
|
860
874
|
}
|
|
861
|
-
`,
|
|
875
|
+
`,Dr=P(A(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:u,conversation:m,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:b,renderReasoning:y,showChunkOnCollapse:w,collapsible:k=!0,messages:E,request:N,onReset:j,transformMessages:$=dt},R)=>{const S=F(e=>{const t=[];if(u&&!1!==u.enable){const e=ut(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat($(e.messages||[])):E?t.concat($(E)):t},[u]),[q,A]=z(m?.id),D=M(),[P,T]=v(()=>S(m)),O=I(()=>N?"string"==typeof N?C.create({baseURL:N}):N:C,[N]),[B,U]=z(!1),_=M(),[H,J]=z("0px"),[Q,K]=z([]),W=F(e=>{"suggestion"==e.type&&K(e.data),o?.onEvent?.(e)},[o?.onEvent]),X=F(e=>{A(e?.id),T(S(e)),K([]),U(!1),j?.(e)},[B,S,j]);return L(R,()=>({reset:X}),[X]),e(Me,{request:O,bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:q,setConversationId:A,inputRef:D,messages:P,setMessages:T,suggestions:Q,setSuggestions:K,loading:B,setLoading:U,renderFileItem:f,reset:X,readonly:!o,renderToolContent:b,renderReasoning:y,showChunkOnCollapse:w,collapsible:k,children:e(x,{children:e(Or,{className:r,scrollableNodeProps:{ref:F(e=>{_.current=e;const t=e?.firstElementChild;t&&requestAnimationFrame(()=>{const e=window.getComputedStyle(t);J(e.paddingBottom)})},[])},children:t(Tr,{children:[e(Ar,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:_}),o&&e(Pr,{$bottom:H,...o,onEvent:W,scrollRef:_})]})})})})}),Y),Pr=n(tt)`
|
|
862
876
|
position: sticky;
|
|
863
877
|
bottom: 0;
|
|
864
878
|
z-index: 1;
|
|
@@ -866,7 +880,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
866
880
|
padding-top: .5rem;
|
|
867
881
|
margin-bottom: -${e=>e.$bottom};
|
|
868
882
|
padding-bottom: calc(1rem + ${e=>e.$bottom});
|
|
869
|
-
`,
|
|
883
|
+
`,Tr=n.div`
|
|
870
884
|
display: flex;
|
|
871
885
|
flex-direction: column;
|
|
872
886
|
width: 100%;
|
|
@@ -875,10 +889,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
875
889
|
max-width: calc(810px + 2rem);
|
|
876
890
|
padding: 0 1rem;
|
|
877
891
|
flex: 1;
|
|
878
|
-
`,
|
|
892
|
+
`,Or=n(j)`
|
|
879
893
|
.simplebar-content {
|
|
880
894
|
min-height: 100%;
|
|
881
895
|
display: flex;
|
|
882
896
|
flex-direction: column;
|
|
883
897
|
}
|
|
884
|
-
`,
|
|
898
|
+
`,Br=P(A(({className:t,request:r,disabled:n,supportStop:i,fileTypes:o,speech:s,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,autoFocus:m,renderEditableInput:h,placeholder:p,variables:g,onEvent:f,onNewConversation:b},v)=>{const[y,x]=z(!1),w=M(),k=I(()=>r?"string"==typeof r?C.create({baseURL:r}):r:C,[r]);return e(Se,{request:k,loading:y,setLoading:x,inputRef:w,children:e(tt,{ref:v,className:t,fileTypes:o,speech:s,variables:g,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,disabled:n,autoFocus:m,renderEditableInput:h,placeholder:p,supportStop:i,onEvent:f,onNewConversation:b})})}),Y);async function Ur(e){const t=await ue().use(he).use(ne).use(ie).use(oe).use(pe).use(me).process(e);return String(t)}export{De as ActionButton,Br as ChatInput,hr as Chunks,Ze as EditableInput,fe as FileIcon,ve as FileItem,qe as InputButton,Nt as Markdown,Dr as MessageBox,Fe as VariableForm,ge as isToolMessage,Ur as md2html,ut as pickQuestions,je as useChatContext,Re as useMessageContext,yr as useSynthesis};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.22",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prebuild": "rimraf es types",
|
|
6
6
|
"build": "rollup -c --environment NODE_ENV:production",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
},
|
|
72
72
|
"author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
|
|
73
73
|
"license": "MIT",
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "73de7625ce6e879df62ff7863146ca360e39b206"
|
|
75
75
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, FC, MutableRefObject, PropsWithChildren, ReactElement, ReactNode, SetStateAction } from 'react';
|
|
2
|
-
import { Conversation, Input, LogLevel, Message, ToolMessage } from '../../types';
|
|
2
|
+
import { Conversation, Chunk, Input, LogLevel, Message, ToolMessage } from '../../types';
|
|
3
3
|
import { Updater } from '@topthink/components/types/hooks/use-immer';
|
|
4
4
|
import { RequestInstance } from '@topthink/components';
|
|
5
5
|
import { FileItemProps } from './file-item';
|
|
@@ -58,6 +58,10 @@ interface DisplayContextType {
|
|
|
58
58
|
}) => ReactElement;
|
|
59
59
|
/** 自定义工具渲染函数 */
|
|
60
60
|
renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
|
|
61
|
+
/** 判断某个 chunk 是否在折叠时显示,默认无工具调用(tools)时显示 */
|
|
62
|
+
showChunkOnCollapse?: (chunk: Chunk, index: number) => boolean;
|
|
63
|
+
/** 是否启用整体折叠功能,默认开启 */
|
|
64
|
+
collapsible?: boolean;
|
|
61
65
|
}
|
|
62
66
|
interface ContextType extends ChatContextType, DisplayContextType {
|
|
63
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestInstance } from '@topthink/components';
|
|
2
2
|
import { ComponentType, MutableRefObject, ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { Conversation, ConversationMessage, Input, LogLevel, Message, MessageBoxType, Variable } from '../../types';
|
|
3
|
+
import { Conversation, ConversationMessage, Chunk, Input, LogLevel, Message, MessageBoxType, Variable } from '../../types';
|
|
4
4
|
import { MessageActions, MessageItemProps } from './message-item';
|
|
5
5
|
import type { RenderEditableInput } from './input-box';
|
|
6
6
|
import type { ToolbarActions } from './input-box/toolbar';
|
|
@@ -77,6 +77,10 @@ export interface MessageBoxProps {
|
|
|
77
77
|
}) => ReactElement;
|
|
78
78
|
/** 自定义工具渲染函数,用于定制工具调用的显示样式 */
|
|
79
79
|
renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
|
|
80
|
+
/** 判断某个 chunk 是否在折叠时显示,默认无工具调用(tools)时显示 */
|
|
81
|
+
showChunkOnCollapse?: (chunk: Chunk, index: number) => boolean;
|
|
82
|
+
/** 是否启用整体折叠功能,默认开启 */
|
|
83
|
+
collapsible?: boolean;
|
|
80
84
|
transformMessages?: (messages: any[]) => Message[];
|
|
81
85
|
onReset?: (conversation?: Conversation) => void;
|
|
82
86
|
}
|