@topthink/chat 1.1.18-alpha.0 → 1.1.19
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 +28 -28
- package/package.json +3 -3
- package/types/components/message-box/content.d.ts +8 -0
- package/types/types.d.ts +9 -8
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as
|
|
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 k,useContext as w,useRef as N,useEffect as E,useCallback as j,useState 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 R from"path";import F from"path";import{Spinner as I,Badge as D,CloseButton as T,OverlayTrigger as L,Popover as P}from"react-bootstrap";import O from"eventemitter3";import B from"lodash/isEqual";import _ from"react-markdown";import"katex/dist/katex.min.css";import U from"remark-math";import H from"remark-breaks";import J from"remark-gfm";import K from"rehype-katex";import Q from"rehype-highlight";import{codes as W,types as X}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=F.extname(i).substring(1),u=e(ie,{className:n,$error:!!c,children:[e(ne,{children:[t(Z,{ext:h}),l&&t(I,{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
2
|
width: 1.75rem;
|
|
3
3
|
height: 1.75rem;
|
|
4
4
|
align-items: center;
|
|
@@ -64,7 +64,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
64
64
|
${e=>e.$error&&i`
|
|
65
65
|
border-color: var(--bs-danger) !important;
|
|
66
66
|
`}
|
|
67
|
-
`,oe=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],se=
|
|
67
|
+
`,oe=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],se=k(null);function ae(){const e=w(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
68
|
color: var(--bs-secondary);
|
|
69
69
|
cursor: pointer;
|
|
70
70
|
display: flex;
|
|
@@ -87,7 +87,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
87
87
|
background-color: var(--bs-gray-200);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
`;let he=class{#e;#t;constructor(){this.#t=new O}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)}},
|
|
90
|
+
`;let he=class{#e;#t;constructor(){this.#t=new O}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 O}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=N(),[i,o]=C(!1),[s,a]=C(!1);return E((()=>()=>{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(I)`
|
|
91
91
|
position: absolute;
|
|
92
92
|
--bs-spinner-width: .75rem;
|
|
93
93
|
--bs-spinner-height: .75rem;
|
|
@@ -116,7 +116,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
116
116
|
&:hover {
|
|
117
117
|
background-color: var(--bs-secondary-bg-subtle);
|
|
118
118
|
}
|
|
119
|
-
`;function be(){const{request:n,reset:i,conversationId:o}=ae(),[a,l]=
|
|
119
|
+
`;function be(){const{request:n,reset:i,conversationId:o}=ae(),[a,l]=C(!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(Ne,{children:t(we,{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(ke,{onClick:()=>{i(r),l(!1)},children:[e(ye,{children:[o===r.id&&t(D,{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
120
|
padding: 0;
|
|
121
121
|
overflow: hidden;
|
|
122
122
|
`,xe=n.div`
|
|
@@ -133,7 +133,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
133
133
|
display: flex;
|
|
134
134
|
align-items: center;
|
|
135
135
|
gap: .25rem;
|
|
136
|
-
`,
|
|
136
|
+
`,ke=n.div`
|
|
137
137
|
gap: .5rem;
|
|
138
138
|
display: flex;
|
|
139
139
|
flex-direction: column;
|
|
@@ -151,7 +151,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
`,
|
|
154
|
+
`,we=n(h)`
|
|
155
155
|
display: flex;
|
|
156
156
|
flex-direction: column;
|
|
157
157
|
padding: .5rem;
|
|
@@ -166,14 +166,14 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
166
166
|
margin-bottom: .5rem;
|
|
167
167
|
display: flex;
|
|
168
168
|
padding: 0 .125rem;
|
|
169
|
-
`;var Se=M((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:c,variables:h,minRows:
|
|
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=N(null),x=N(null),y=N(null),[k,w]=C(""),[M,q]=C(""),[$,S]=g([]),[F,I]=C(!1),D=o&&o.length>0?o:oe,{messages:L,loading:P,request:O}=ae(),{send:B}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:s,setConversationId:a,request:c}=ae(),d=N(null),h=N(s);E((()=>{h.current=s}),[s]);const u=j((async()=>{d.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:h.current},signal:d.current.signal};const t=await c(e);i(t)}catch{}finally{d.current=null}}),[c]),m=j((async function(e){if("string"==typeof e){for(var s=arguments.length,m=new Array(s>1?s-1:0),p=1;p<s;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:h.current},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?(h.current=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 if(t.chunks.reasoning)r.chunks[e].reasoning+=t.chunks.reasoning;else if(t.chunks.content)if("object"==typeof t.chunks.content){Array.isArray(r.chunks[e].content)||(r.chunks[e].content=[]);const n=t.chunks.content.index,i=t.chunks.content.value;"string"==typeof i?(r.chunks[e].content[n]||(r.chunks[e].content[n]=""),r.chunks[e].content[n]+=i):r.chunks[e].content[n]=i}else r.chunks[e].content+=t.chunks.content;else t.chunks.node&&(r.chunks[e].node={...r.chunks[e].node,...t.chunks.node})}else t.stats?r.stats=t.stats:t.id&&(r.id=t.id)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await c(e),t&&requestAnimationFrame(u)}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?.()}}),[c]);return{send:m}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{v.current?.focus()}))}}),[_,U]=C();E((()=>{const e=L.filter((e=>!!e.query));U(e.at(-1)?.variables)}),[L]),E((()=>{!o&&$.length>0&&S([])}),[o]),E((()=>{const e=c.current;if(e&&B){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}),B(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=>!!D.includes(R.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 O({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=""}),[$,D]),J=$.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),K=j((()=>{if(k||J.length>0){const e={query:k,files:J};h&&(e.variables={..._,...h.values}),M&&(e.quote=M),B(e),w(""),q(""),S([]),y.current?.stop(!0)}}),[k,J,h,_,M]);if(z(n,(()=>({setQuery:w,setQuote:q,send:B,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(Re,{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:F&&!P,children:[$.length>0&&t(Ie,{children:$.map(((e,r)=>{let{file:n,error:i,path:o}=e;const s=void 0===i&&void 0===o;return t(Fe,{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(De,{children:[t(A,{disabled:P||p,ref:v,placeholder:b,minRows:u,maxRows:5,value:k,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())},autoFocus:f,onFocus:()=>I(!0),onBlur:()=>I(!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:D.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(),w((t=>t+e+" "))}}),t(de,{className:"text-primary",disabled:!k&&0===J.length,onClick:e=>{e.preventDefault(),K()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})}));const Ae=n.div`
|
|
170
170
|
border-radius: var(--bs-border-radius-lg);
|
|
171
171
|
box-shadow: var(--bs-box-shadow-sm);
|
|
172
172
|
margin: 1rem;
|
|
173
173
|
padding: 1rem;
|
|
174
174
|
width: 100%;
|
|
175
175
|
max-width: 500px;
|
|
176
|
-
`,
|
|
176
|
+
`,Re=n.div`
|
|
177
177
|
position: absolute;
|
|
178
178
|
left: 0;
|
|
179
179
|
right: 0;
|
|
@@ -183,7 +183,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
183
183
|
display: flex;
|
|
184
184
|
justify-content: center;
|
|
185
185
|
align-items: center;
|
|
186
|
-
`,
|
|
186
|
+
`,Fe=n(ee)`
|
|
187
187
|
width: calc((100% - .75rem) / 2);
|
|
188
188
|
`,Ie=n.div`
|
|
189
189
|
display: flex;
|
|
@@ -594,7 +594,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
594
594
|
max-height: 100%;
|
|
595
595
|
max-width: 100%;
|
|
596
596
|
}
|
|
597
|
-
|
|
597
|
+
`;function lt(e){let{value:n,cite:i}=e;const o=e=>"string"==typeof e?t(Ze,{content:e,cite:i}):"image"===e.type?t(st,{src:e.image}):null;return Array.isArray(n)?t(r,{children:n.map(((e,r)=>t($,{children:o(e)},r)))}):o(n)}const ct=S((r=>{let{reasoning:n,loading:i}=r;const[o,s]=C(i);return E((()=>{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(I,{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(Ze,{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(I,{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"})]})})})}));class dt{#t;#o=[];#s=0;constructor(){this.#t=new O}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 O}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=N(),[o,s]=C(!1),[a,l]=C(!1),c=N(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 E((()=>{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]),E((()=>()=>{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(I,{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(nt,{disabled:o&&!h,onClick:()=>{h?p():m()},children:[h?t(ft,{className:"bi bi-volume-down-fill"}):u?t(I,{size:"sm",variant:"primary"}):t(ft,{className:"bi bi-volume-down"}),g]})}const gt=n.div`
|
|
598
598
|
position: absolute;
|
|
599
599
|
top: 0;
|
|
600
600
|
left: 0;
|
|
@@ -604,20 +604,20 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
604
604
|
align-items: center;
|
|
605
605
|
justify-content: center;
|
|
606
606
|
background-color: rgba(0, 0, 0, .3);
|
|
607
|
-
`,
|
|
607
|
+
`,ft=n.i`
|
|
608
608
|
|
|
609
609
|
&::before {
|
|
610
610
|
transform: scale(1.4)
|
|
611
611
|
}
|
|
612
|
-
`;function
|
|
612
|
+
`;function bt(r){let{tool:n}=r;const[i,o]=C(!1),{logLevel:s="none"}=ae(),a="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:[a?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:a?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&a?{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(vt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(a),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(I,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:a?"已使用":"正在使用"}),t("span",{children:n.title}),a&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),n.content&&t(lt,{value:n.content})]})}const vt=n.div`
|
|
613
613
|
white-space: pre-wrap;
|
|
614
|
-
`;function
|
|
614
|
+
`;function xt(r){let{node:n}=r;const[i,o]=C(!1),{nodeIconResolver:s}=ae(),a=!("latency"in n),l=a?t(I,{animation:"border",variant:"primary",size:"sm"}):n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"shadow-sm rounded bg-white fs-7",children:[e(kt,{onClick:()=>o((e=>!e)),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[t("i",{className:"bi bi-chevron-down text-muted"}),s?.(n.type),t(wt,{className:"me-2 text-truncate",children:n.title}),t("span",{className:"me-auto"}),!a&&t("span",{className:"text-nowrap text-muted",children:yt(n.latency)}),t("span",{children:l})]}),i&&e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输入"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.input?JSON.stringify(n.input,null,4):"None"})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输出"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.output?JSON.stringify(n.output,null,4):"None"})]})]})]})}const yt=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`,kt=n.div`
|
|
615
615
|
svg {
|
|
616
616
|
flex-shrink: 0;
|
|
617
617
|
}
|
|
618
618
|
`,wt=n.span`
|
|
619
619
|
display: inline-block;
|
|
620
|
-
`;function
|
|
620
|
+
`;function Nt(r){let{nodes:n,loading:i}=r;const[o,s]=C(!1),a=n.some((e=>"error"in e)),l=i?t(I,{animation:"border",variant:"primary",size:"sm"}):t("i",a?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,r)=>t(xt,{node:e},r)))})]}:{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:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Et=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,loading:p}=i,{user:g,bot:f,logLevel:x="none",messages:y}=ae(),k=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=N(null),E=N(null),j=N(null),C=q((()=>u?.flatMap((e=>e.node?[e.node]:[]))||[]),[u]);return console.log(u),e(r,{children:[(c||h.length>0)&&e(It,{$reverse:!0,children:[g&&t(At,{children:t("img",{src:g.avatar})}),t(Rt,{}),e(Ft,{ref:w,children:[c&&t(Ze,{content:c}),d&&t(L,{trigger:"click",container:w,rootClose:!0,placement:"bottom",overlay:t(jt,{body:!0,children:d}),children:t(Mt,{children:t(Ct,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return v(o)?t(st,{src:`/uploads/${o}`},r):t(zt,{children:t(ee,{name:n,size:i})},r)}))]})]}),u&&e(It,{children:[t(At,{ref:E,children:t("img",{src:f.avatar})}),t(Rt,{}),e(Ft,{children:[(c||h.length>0)&&!1!==o&&e($t,{children:[t(b,{placement:"top",content:k,as:nt,tooltip:!0}),l&&t(pt,{loading:i.loading,avatarRef:E,contentRef:j,...l}),o?.({Component:nt,message:i,content:k,setMessage:s,messages:y})]}),t(St,{children:["stats","all"].includes(x)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(qt,{ref:j,$deleted:!!m,children:["all"===x&&C.length>0&&t(Nt,{loading:p,nodes:C}),u.length>0&&u.map(((r,n)=>e($,{children:[r.reasoning&&["stats","all"].includes(x)&&t(ct,{reasoning:r.reasoning,loading:!r.content}),r.content&&t(lt,{cite:a,value:r.content}),r.tools.map(((e,r)=>t(bt,{tool:e},r))),r.error&&t(Ze,{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(Ze,{content:m.answer})]}),i.loading&&t(Ke,{})]})]})]})})),jt=n(P)`
|
|
621
621
|
max-width: calc(100% - .875rem * 2);
|
|
622
622
|
width: calc(100% - .875rem * 2);
|
|
623
623
|
font-size: 1rem;
|
|
@@ -626,25 +626,25 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
626
626
|
.popover-body {
|
|
627
627
|
padding: .5rem .75rem;
|
|
628
628
|
}
|
|
629
|
-
`,
|
|
629
|
+
`,Ct=n.div`
|
|
630
630
|
overflow: hidden;
|
|
631
631
|
text-overflow: ellipsis;
|
|
632
632
|
word-break: break-all;
|
|
633
633
|
-webkit-line-clamp: 2;
|
|
634
634
|
-webkit-box-orient: vertical;
|
|
635
635
|
display: -webkit-box;
|
|
636
|
-
`,
|
|
636
|
+
`,Mt=n.div`
|
|
637
637
|
padding: .5rem .75rem;
|
|
638
638
|
color: var(--bs-secondary);
|
|
639
639
|
border-radius: var(--bs-border-radius-lg);
|
|
640
640
|
background: #FFFFFF;
|
|
641
641
|
cursor: pointer;
|
|
642
|
-
`,
|
|
642
|
+
`,qt=n.div`
|
|
643
643
|
${e=>e.$deleted&&i`
|
|
644
644
|
text-decoration-line: line-through;
|
|
645
645
|
color: var(--bs-secondary);
|
|
646
646
|
`}
|
|
647
|
-
`,
|
|
647
|
+
`,zt=n.div`
|
|
648
648
|
width: 100%;
|
|
649
649
|
margin-bottom: .5rem;
|
|
650
650
|
margin-top: .5rem;
|
|
@@ -656,7 +656,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
656
656
|
&:last-child {
|
|
657
657
|
margin-bottom: 0;
|
|
658
658
|
}
|
|
659
|
-
|
|
659
|
+
`,$t=n.div`
|
|
660
660
|
position: absolute;
|
|
661
661
|
top: -1.1rem;
|
|
662
662
|
right: 0;
|
|
@@ -664,7 +664,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
664
664
|
gap: .5rem;
|
|
665
665
|
opacity: 0;
|
|
666
666
|
z-index: 1;
|
|
667
|
-
|
|
667
|
+
`,St=n.div`
|
|
668
668
|
position: absolute;
|
|
669
669
|
bottom: -1.4rem;
|
|
670
670
|
left: 0;
|
|
@@ -677,7 +677,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
677
677
|
display: flex;
|
|
678
678
|
opacity: 0;
|
|
679
679
|
z-index: 1;
|
|
680
|
-
`,
|
|
680
|
+
`,At=n.div`
|
|
681
681
|
width: 35px;
|
|
682
682
|
height: 35px;
|
|
683
683
|
border-radius: 50%;
|
|
@@ -703,11 +703,11 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
703
703
|
position: relative;
|
|
704
704
|
|
|
705
705
|
&:hover {
|
|
706
|
-
${
|
|
706
|
+
${St}, ${$t} {
|
|
707
707
|
opacity: 1;
|
|
708
708
|
}
|
|
709
709
|
}
|
|
710
|
-
`,
|
|
710
|
+
`,It=n.div`
|
|
711
711
|
display: flex;
|
|
712
712
|
justify-content: flex-start;
|
|
713
713
|
padding: 1rem 0 1rem 0;
|
|
@@ -723,11 +723,11 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
723
723
|
background: rgba(var(--bs-primary-rgb), 0.1);
|
|
724
724
|
}
|
|
725
725
|
`};
|
|
726
|
-
`;function
|
|
726
|
+
`;function Dt(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:h,suggestions:u,conversationId:m}=ae(),p=N(r.loaded),g=j((()=>{const e=l.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),f=N(null),{height:b}=G({ref:f});return E((()=>{(h||!p.current)&&c.length>0&&(h&&(p.current=!0),g())}),[b,h,p,c]),E((()=>{u.length>0&&g()}),[u]),E((()=>{p.current=r.loaded}),[m]),E((()=>{const e=f.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[f]),e(Tt,{ref:f,children:[0===c.length&&n,c.slice(-30).map(((e,r)=>{const n={actions:i,cite:o,speech:s,message:e,setMessage:t=>{d((r=>{const n=r.findIndex((t=>t.id===e.id));-1!==n&&t(r[n])}))}};return a?a({Component:Et,props:n},r):t(Et,{...n},r)})),u.length>0&&t(Lt,{children:u.map(((e,r)=>t("a",{href:"#!question",children:e},r)))})]})}const Tt=n.div`
|
|
727
727
|
display: flex;
|
|
728
728
|
flex-direction: column;
|
|
729
729
|
flex: 1;
|
|
730
|
-
`,
|
|
730
|
+
`,Lt=n.div`
|
|
731
731
|
display: flex;
|
|
732
732
|
flex-direction: column;
|
|
733
733
|
align-items: flex-start;
|
|
@@ -744,16 +744,16 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
744
744
|
background: var(--bs-secondary-bg-subtle);
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
|
-
`,
|
|
747
|
+
`,Pt=S(M(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:u,onboarding:m,conversation:p,cite:b,speech:v,renderItem:y,messages:k,request:w}=r;const M=j((e=>{const t=[];if(m&&!1!==m.enable){const e=Be(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(Oe(e.messages||[])):k?t.concat(Oe(k)):t}),[m]),[$,S]=C(p?.id),[A,R]=g([]);E((()=>{R(M(p))}),[m]);const[F,I]=C(!1),D=N(null),[T,L]=C([]),P=j((e=>{F||(S(e?.id),R(M(e)),L([]))}),[F,M]);return z(n,(()=>({reset:P})),[P]),t(le,{request:q((()=>w?"string"==typeof w?x.create({baseURL:w}):w:x),[w]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:$,setConversationId:S,messages:A,setMessages:R,suggestions:T,setSuggestions:L,loading:F,setLoading:I,reset:P,children:t(Bt,{className:i,children:e(f,{children:[t(Ot,{ref:D,children:t(Dt,{placeholder:h,cite:b,actions:u,loaded:!a,speech:v,renderItem:y,scrollRef:D})}),a&&t(Se,{...a,scrollRef:D})]})})})})),B),Ot=n.div`
|
|
748
748
|
display: flex;
|
|
749
749
|
flex-direction: column;
|
|
750
750
|
flex: 1;
|
|
751
751
|
overflow-y: auto;
|
|
752
752
|
padding: 0 1rem;
|
|
753
753
|
margin-bottom: .5rem;
|
|
754
|
-
`,
|
|
754
|
+
`,Bt=n.div`
|
|
755
755
|
display: flex;
|
|
756
756
|
flex-direction: column;
|
|
757
757
|
height: 100%;
|
|
758
758
|
position: relative;
|
|
759
|
-
`;export{ge as ActionButton,Ze as Markdown,
|
|
759
|
+
`;export{ge as ActionButton,Ze as Markdown,Pt as MessageBox,ce as VariableForm,Be as pickQuestions,mt as useSynthesis};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.19",
|
|
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.
|
|
21
|
+
"@topthink/components": "^1.1.13",
|
|
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": "
|
|
68
|
+
"gitHead": "a2e1d94433fd41c04c5185137951c34150d06adb"
|
|
69
69
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Components } from 'react-markdown';
|
|
2
|
+
import { ContentType } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
value: ContentType | ContentType[];
|
|
5
|
+
cite?: Components['cite'];
|
|
6
|
+
}
|
|
7
|
+
export default function Content({ value, cite }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
8
|
+
export {};
|
package/types/types.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
export type ContentType = string | {
|
|
2
|
+
type: 'image';
|
|
3
|
+
image: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'chart';
|
|
6
|
+
chart: string;
|
|
7
|
+
};
|
|
1
8
|
export interface ToolMessage {
|
|
2
9
|
name: string;
|
|
3
10
|
title: string;
|
|
4
11
|
arguments: string;
|
|
5
12
|
response?: string;
|
|
6
13
|
error?: boolean;
|
|
7
|
-
content?:
|
|
8
|
-
type: 'image';
|
|
9
|
-
image: string;
|
|
10
|
-
} | {
|
|
11
|
-
type: 'chart';
|
|
12
|
-
chart: string;
|
|
13
|
-
};
|
|
14
|
+
content?: ContentType;
|
|
14
15
|
}
|
|
15
16
|
export type LogLevel = 'stats' | 'all' | 'none';
|
|
16
17
|
export interface Node {
|
|
@@ -32,7 +33,7 @@ export interface Message {
|
|
|
32
33
|
}[];
|
|
33
34
|
variables?: Record<string, string>;
|
|
34
35
|
chunks?: {
|
|
35
|
-
content: string;
|
|
36
|
+
content: string | ContentType[];
|
|
36
37
|
reasoning?: string;
|
|
37
38
|
tools: ToolMessage[];
|
|
38
39
|
error?: string;
|