@topthink/chat 1.0.45 → 1.0.47
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 +68 -43
- package/package.json +4 -4
- package/types/components/message-box/action.d.ts +1 -0
- package/types/components/message-box/index.d.ts +7 -1
- package/types/components/message-box/message-item.d.ts +7 -1
- package/types/components/message-box/speech-action.d.ts +12 -0
- package/types/index.d.ts +1 -0
- package/types/speech/synthesis/builtin.d.ts +11 -0
- package/types/speech/synthesis/custom.d.ts +15 -0
- package/types/speech/use-synthesis.d.ts +15 -0
- package/types/types.d.ts +6 -0
- package/types/utils/get-element-content.d.ts +1 -0
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as e from"react";import{useCallback as t,useEffect as r,useState as n,useRef as i,useImperativeHandle as o,memo as a,useMemo as s,createContext as l,useContext as c,Fragment as d,forwardRef as
|
|
1
|
+
import*as e from"react";import{useCallback as t,useEffect as r,useState as n,useRef as i,useImperativeHandle as o,memo as a,useMemo as s,createContext as l,useContext as c,Fragment as d,forwardRef as h}from"react";import{useImmer as u,request as m,isRequestError as p,Lightbox as g,styled as f,Clipboard as b,css as v,formatSize as x,Tooltip as y,useAsync as w,isImageUrl as k,Form as E,Toast as j}from"@topthink/components";import{jsx as N,jsxs as M,Fragment as $}from"react/jsx-runtime";import q from"react-markdown";import"katex/dist/katex.min.css";import C from"remark-math";import S from"remark-breaks";import z from"remark-gfm";import A from"rehype-katex";import F from"rehype-highlight";import{codes as R,types as D}from"micromark-util-symbol";import{markdownLineEnding as T}from"micromark-util-character";import I from"lodash/isEqual";import{Spinner as P,OverlayTrigger as B,Popover as L,CloseButton as O}from"react-bootstrap";import*as _ from"path";import U from"path";import H from"eventemitter3";import{createPortal as K}from"react-dom";import Q from"react-textarea-autosize";import X from"use-resize-observer";function J(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}function W(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",error:r,tools:n=[]}=e;return{content:t,error:r,tools:n}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}function Y(e){let{url:a,onboarding:s,suggestion:l,onSuccess:c,ref:d,transformRequest:h,...g}=e;const f=t((e=>{const t=[];if(s&&!1!==s.enable){const e=J(s.questions||[]);t.push({chunks:[{content:[s.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:s.loading})}return e?t.concat(W(e.messages||[])):t}),[s]),[b,v]=u((()=>f(g.conversation)));r((()=>{v(f(g.conversation))}),[s]);const[x,y]=n([]),[w,k]=n(!1),E=i(g.conversation?.id),j=i(null),N=t((async()=>{j.current=new AbortController;try{let e={method:"post",url:`${a}/suggestion`,data:{conversation:E.current},signal:j.current.signal};h&&(e=h("suggestion",e));const t=await m(e);y(t)}catch{}finally{j.current=null}}),[h,a]),M=t((async function(e){if("string"==typeof e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];e={query:e,...r}}const{query:i,files:o=[],variables:s={},quote:d}=e;if(i||o.length>0){j.current&&j.current.abort(),k(!0),y([]),v((e=>{e.push({query:i,quote:d,files:o,variables:s,chunks:[],loading:!0})}));try{let e={method:"post",url:a,data:{query:i,quote:d,files:o,variables:s,conversation:E.current},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?E.current=t.conversation:v((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.content&&(r.chunks[e].content+=t.chunks.content)}else t.stats&&(r.stats=t.stats)}))}catch(e){console.error(e)}else v((e=>{e[e.length-1].loading=!1}))}};h&&(e=h("chat",e)),await m(e),l?.enable&&N()}catch(e){let t="未知错误";p(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),v((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}))}k(!1),c?.()}}),[h,a]),$=t((e=>{w||(E.current=e?.id,v(f(e)),y([]))}),[w,f]);return o(d,(()=>({reset:$,send:M}))),{messages:b,suggestions:x,loading:w,send:M,reset:$}}const G=function(e,t,r){function n(t){return t!==R.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(D.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===R.rightSquareBracket?(e.exit(D.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==R.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):T(n)||n===R.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==R.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},V=function(){const e=this.data();e.micromarkExtensions.push({text:{[R.leftSquareBracket]:{tokenize:G}}}),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}}})},Z=g.Image,ee={pre:e=>{let{children:t}=e;const r=i(null);return M(oe,{ref:r,children:[N(ie,{tooltip:!1,content:()=>{const e=r.current?.getElementsByTagName("code");return e?.[0]?.innerText||""}}),t]})},a:e=>{let{node:t,href:r,...n}=e;const i=r?.startsWith("http")?"_blank":"_self";return N("a",{...n,href:r,target:i})},img:e=>{let{node:t,...r}=e;return N(Z,{...r})}},te=[[C,{singleDollarTextMath:!1}],z,S],re=[A,[F,{detect:!1,ignoreMissing:!0}]],ne=a((e=>{let{content:t,components:r,cite:n}=e;t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const i=s((()=>{const e={...ee,...r};return n&&(e.cite=n),e}),[r,n]),o=s((()=>n?[...te,V]:te),[n]);return N(ae,{remarkPlugins:o,rehypePlugins:re,components:i,children:t})}),I),ie=f(b)`
|
|
2
2
|
position: absolute;
|
|
3
3
|
right: 10px;
|
|
4
4
|
top: 1em;
|
|
@@ -18,17 +18,17 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
18
18
|
&:hover {
|
|
19
19
|
opacity: 1;
|
|
20
20
|
}
|
|
21
|
-
`,
|
|
21
|
+
`,oe=f.pre`
|
|
22
22
|
position: relative;
|
|
23
23
|
|
|
24
24
|
&:hover {
|
|
25
|
-
${
|
|
25
|
+
${ie} {
|
|
26
26
|
pointer-events: all;
|
|
27
27
|
transform: translateX(0px);
|
|
28
28
|
opacity: 0.5;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
`,
|
|
31
|
+
`,ae=f(q)`
|
|
32
32
|
-ms-text-size-adjust: 100%;
|
|
33
33
|
-webkit-text-size-adjust: 100%;
|
|
34
34
|
line-height: 1.8;
|
|
@@ -298,7 +298,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
298
298
|
.hljs-strong {
|
|
299
299
|
font-weight: 700;
|
|
300
300
|
}
|
|
301
|
-
`,
|
|
301
|
+
`,se=l(null);function le(){const e=c(se);if(!e)throw new Error("useContext must be used within a Provider");return e}function ce(e){let{children:t,...r}=e;return N(se.Provider,{value:r,children:t})}const de=g.Image;function he(e){let{src:t,...r}=e;const{imageResolver:n}=le();return n&&t&&(t=n(t)),N(ue,{children:N(de,{src:t,...r})})}const ue=f.div`
|
|
302
302
|
margin-bottom: .5rem;
|
|
303
303
|
margin-top: .5rem;
|
|
304
304
|
border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
|
|
@@ -323,9 +323,9 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
323
323
|
max-height: 100%;
|
|
324
324
|
max-width: 100%;
|
|
325
325
|
}
|
|
326
|
-
`;function
|
|
326
|
+
`;function me(e){let{tool:t}=e;const[r,i]=n(!1),{logLevel:o="none"}=le();let a=null;t.content&&("string"==typeof t.content?a=N(ne,{content:t.content}):"image"===t.content.type&&(a=N(he,{src:t.content.image})));const s="response"in t;return M(d,{children:["stats"==o&&N("div",{className:"mb-2",children:M("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[s?t.error?N("i",{className:"bi bi-x-circle-fill text-danger"}):N("i",{className:"bi bi-check-circle-fill text-success"}):N(P,{animation:"border",variant:"primary",size:"sm"}),N("span",{className:"text-muted",children:s?"已使用":"正在使用"}),N("span",{children:t.title})]})}),"all"==o&&N("div",{className:"mb-2",children:M("div",r&&s?{className:"shadow-sm rounded bg-white fs-7",children:[M("div",{onClick:()=>i(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[t.error?N("i",{className:"bi bi-x-circle-fill text-danger"}):N("i",{className:"bi bi-check-circle-fill text-success"}),N("span",{className:"text-muted",children:"已使用"}),N("span",{children:t.title}),N("i",{className:"bi bi-caret-up-fill text-muted"})]}),M("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[M("div",{className:"border rounded bg-light",children:[N("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:N("span",{className:"text-muted",children:"参数"})}),N("div",{className:"border-top p-2 overflow-hidden",children:t.arguments})]}),M("div",{className:"border rounded bg-light",children:[N("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:N("span",{className:"text-muted",children:"响应"})}),N(pe,{className:"border-top p-2 overflow-hidden",children:t.response||"None"})]})]})]}:{onClick:()=>i(s),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[s?t.error?N("i",{className:"bi bi-x-circle-fill text-danger"}):N("i",{className:"bi bi-check-circle-fill text-success"}):N(P,{animation:"border",variant:"primary",size:"sm"}),N("span",{className:"text-muted",children:s?"已使用":"正在使用"}),N("span",{children:t.title}),s&&N("i",{className:"bi bi-caret-down-fill text-muted"})]})}),a]})}const pe=f.div`
|
|
327
327
|
white-space: pre-wrap;
|
|
328
|
-
`;var
|
|
328
|
+
`;var ge,fe,be;function ve(){return ve=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ve.apply(this,arguments)}const xe=t=>e.createElement("svg",ve({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},t),ge||(ge=e.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},e.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),e.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),fe||(fe=e.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},e.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),e.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),be||(be=e.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},e.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),e.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));const ye=function(e){let{ext:t}=e;const{result:r}=w((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),[t]);return r?N("img",{width:30,height:30,src:r}):null};function we(e){let{className:t,name:r,size:n,loading:i,error:o,onRemove:a}=e;const s=U.extname(r).substring(1),l=M(Ne,{className:t,$error:!!o,children:[M(je,{children:[N(ye,{ext:s}),i&&N(P,{variant:"primary"})]}),M(Ee,{children:[N("h4",{children:r}),N("p",{children:x(n,1)})]}),a&&N(ke,{onClick:e=>{e.preventDefault(),a()},children:N("i",{className:"bi bi-trash3"})})]});return o?N(y,{placement:"top",tooltip:o,children:l}):l}const ke=f.div`
|
|
329
329
|
width: 1.75rem;
|
|
330
330
|
height: 1.75rem;
|
|
331
331
|
align-items: center;
|
|
@@ -340,7 +340,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
340
340
|
color: var(--bs-danger);
|
|
341
341
|
background-color: var(--bs-danger-bg-subtle);
|
|
342
342
|
}
|
|
343
|
-
`,
|
|
343
|
+
`,Ee=f.div`
|
|
344
344
|
flex: 1;
|
|
345
345
|
overflow: hidden;
|
|
346
346
|
|
|
@@ -375,7 +375,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
375
375
|
position: absolute;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
`,
|
|
378
|
+
`,Ne=f.div`
|
|
379
379
|
display: flex;
|
|
380
380
|
gap: .5rem;
|
|
381
381
|
padding: .5rem;
|
|
@@ -391,7 +391,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
391
391
|
${e=>e.$error&&v`
|
|
392
392
|
border-color: var(--bs-danger) !important;
|
|
393
393
|
`}
|
|
394
|
-
`;var
|
|
394
|
+
`;var Me=h((function(e,t){let{children:r,tooltip:n,onClick:i,disabled:o,...a}=e;o&&(i=void 0);const s=N($e,{ref:t,onClick:i,$disabled:o,...a,children:r});return n?N(y,{tooltip:n,placement:"top",children:s}):s}));const $e=f.div`
|
|
395
395
|
align-items: center;
|
|
396
396
|
justify-content: center;
|
|
397
397
|
border-radius: .375rem;
|
|
@@ -402,7 +402,13 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
402
402
|
background: #FFF;
|
|
403
403
|
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
|
|
404
404
|
padding: .125rem;
|
|
405
|
+
width: 1.875rem;
|
|
406
|
+
height: 1.875rem;
|
|
407
|
+
overflow: hidden;
|
|
405
408
|
|
|
409
|
+
${e=>e.$disabled&&v`
|
|
410
|
+
color: var(--bs-gray-400) !important;
|
|
411
|
+
`}
|
|
406
412
|
.bi {
|
|
407
413
|
width: 1.75rem;
|
|
408
414
|
height: 1.75rem;
|
|
@@ -410,12 +416,30 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
410
416
|
line-height: 1.75rem;
|
|
411
417
|
text-align: center;
|
|
412
418
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
419
|
+
${e=>!e.$disabled&&v`
|
|
420
|
+
&:hover {
|
|
421
|
+
color: var(--bs-dark);
|
|
422
|
+
background-color: var(--bs-gray-200);
|
|
423
|
+
}
|
|
424
|
+
`}
|
|
425
|
+
|
|
426
|
+
}
|
|
427
|
+
`;let qe=class{#e;#t=[];#r=0;constructor(){this.#e=new H}speak(){for(this.#e.emit("playing",!0);this.#r<this.#t.length;){const e=this.#t[this.#r],t=new SpeechSynthesisUtterance(e),r=++this.#r;t.onend=()=>{r>=this.#t.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#e.emit("playing",!1)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.#t=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#r=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#e.on("playing",e)}onSpeaking(e){this.#e.on("speaking",e)}};const Ce=new Map;let Se=class{#n;#i;#o;#e;#t=[];#a=new Map;#s=!1;#r=0;#l=!1;constructor(e,t,r){this.#n=t,this.#i=e,this.#o=r,this.#e=new H}createLoader(e){const t=new Promise((async t=>{try{const r=await m({url:this.#i,method:"post",data:{model:this.#n,voice:this.#o,input:e}}),n=new Audio(`data:${r.audio.type};base64,${r.audio.data}`);this.#a.set(e,n),t(n)}catch{this.#a.delete(e),t(void 0)}}));return this.#a.set(e,t),t}async loadAudioData(){this.#l=!0,this.#e.emit("speaking",!0);let e=0;for(;e<this.#t.length;){const t=this.#t[e];!this.#a.has(t)&&this.#l&&await this.createLoader(t),e++}this.#e.emit("speaking",!1),this.#l=!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.#s=!0;const t=await this.waitForAudioLoaded(this.#t[e]);this.#e.emit("playing",!0),t?(Ce.set(this,t),t.onpause=async()=>{t.ended?(this.#r++,this.#r<this.#t.length?await this.playAudio(this.#r):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#s=!1,this.#l=!1,this.#e.emit("playing",!1),this.#e.emit("speaking",!1),Ce.delete(this)}start(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];Ce.forEach(((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)})),this.#t=Array.isArray(e)?e:[e],t||(this.#r=0),this.#l||this.loadAudioData(),this.#s||this.playAudio()}update(e){this.#t=Array.isArray(e)?e:[e]}stop(){const e=Ce.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#e.on("playing",e)}onSpeaking(e){this.#e.on("speaking",e)}};function ze(e){let{text:t,url:o,voice:a,loading:s,model:l="builtin"}=e;const c=i(),[d,h]=n(!1),[u,m]=n(!1),p=i(s),g=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];c.current||(c.current="builtin"===l?new qe:new Se(o,l,a),c.current.onSpeaking(h),c.current.onPlaying(m));let r="";"string"==typeof t?r=t:t.current&&(r=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),s&&r.pop()),r&&0!==r.length&&c.current.start(r,e)};return r((()=>{if(p.current&&"string"!=typeof t&&t.current){if(s){const e={childList:!0,subtree:!0},r=new MutationObserver((function(){g(!0)}));return r.observe(t.current,e),g(),()=>{r.disconnect()}}g(!0)}}),[s]),r((()=>()=>{c.current&&(c.current.stop(),c.current=void 0)}),[]),{playing:u,speaking:d,start:g,stop:()=>{c.current&&c.current.stop()}}}function Ae(e){let{url:t,model:r,voice:n,loading:i,autoplay:o,contentRef:a,avatarRef:s}=e;const{playing:l,speaking:c,start:d,stop:h}=ze({text:a,url:t,model:r,voice:n,loading:o&&i});let u=null;return s.current&&(c&&(u=K(N(Fe,{children:N(P,{size:"sm",variant:"light"})}),s.current)),l&&(u=K(N(Fe,{children:N(Re,{className:"bi bi-volume-down-fill text-light"})}),s.current))),M(Me,{disabled:i&&!l,onClick:()=>{l?h():d()},children:[l?N(Re,{className:"bi bi-volume-down-fill"}):c?N(P,{size:"sm",variant:"primary"}):N(Re,{className:"bi bi-volume-down"}),u]})}const Fe=f.div`
|
|
428
|
+
position: absolute;
|
|
429
|
+
top: 0;
|
|
430
|
+
left: 0;
|
|
431
|
+
width: 100%;
|
|
432
|
+
height: 100%;
|
|
433
|
+
display: flex;
|
|
434
|
+
align-items: center;
|
|
435
|
+
justify-content: center;
|
|
436
|
+
background-color: rgba(0, 0, 0, .3);
|
|
437
|
+
`,Re=f.i`
|
|
438
|
+
|
|
439
|
+
&::before {
|
|
440
|
+
transform: scale(1.4)
|
|
417
441
|
}
|
|
418
|
-
`,
|
|
442
|
+
`,De=a((e=>{let{message:t,actions:r,updater:n,cite:o,speech:a}=e;const{query:l,quote:c,files:h=[],chunks:u,annotation:m}=t,{user:p,bot:g,logLevel:f="none"}=le(),v=s((()=>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]),x=i(null),y=i(null),w=i(null);return M($,{children:[(l||h.length>0)&&M(Qe,{$reverse:!0,children:[p&&N(Ue,{children:N("img",{src:p.avatar})}),N(He,{}),M(Ke,{ref:x,children:[l&&N(ne,{content:l}),c&&N(B,{trigger:"click",container:x,rootClose:!0,placement:"bottom",overlay:N(Te,{body:!0,children:c}),children:N(Pe,{children:N(Ie,{children:c})})}),h.length>0&&h.map(((e,t)=>{let{name:r,size:n,path:i}=e;return k(i)?N(he,{src:`/uploads/${i}`},t):N(Le,{children:N(we,{name:r,size:n})},t)}))]})]}),u&&M(Qe,{children:[N(Ue,{ref:y,children:N("img",{src:g.avatar})}),N(He,{}),M(Ke,{children:[(l||h.length>0)&&M(Oe,{children:[N(b,{placement:"top",content:v,as:Me,tooltip:!0}),a&&N(Ae,{loading:t.loading,avatarRef:y,contentRef:w,...a}),r?.({Component:Me,message:t,content:v,setMessage:n})]}),N(_e,{children:["stats","all"].includes(f)&&t.stats&&M($,{children:[M("span",{children:["耗时 ",t.stats.latency/1e3," 秒"]}),M("span",{children:["花费 Token ",t.stats.usage]})]})}),N(Be,{ref:w,$deleted:!!m,children:u.length>0&&u.map(((e,t)=>M(d,{children:[e.content&&N(ne,{cite:o,content:e.content}),e.tools.map(((e,t)=>N(me,{tool:e},t))),e.error&&N(ne,{content:`[${e.error}]`})]},t)))}),m&&M("div",{children:[M("div",{className:"d-flex align-items-center",children:[N("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),N("hr",{className:"flex-fill"})]}),N(ne,{content:m.answer})]}),t.loading&&N(xe,{})]})]})]})})),Te=f(L)`
|
|
419
443
|
max-width: calc(100% - .875rem * 2);
|
|
420
444
|
width: calc(100% - .875rem * 2);
|
|
421
445
|
font-size: 1rem;
|
|
@@ -424,25 +448,25 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
424
448
|
.popover-body {
|
|
425
449
|
padding: .5rem .75rem;
|
|
426
450
|
}
|
|
427
|
-
`,
|
|
451
|
+
`,Ie=f.div`
|
|
428
452
|
overflow: hidden;
|
|
429
453
|
text-overflow: ellipsis;
|
|
430
454
|
word-break: break-all;
|
|
431
455
|
-webkit-line-clamp: 2;
|
|
432
456
|
-webkit-box-orient: vertical;
|
|
433
457
|
display: -webkit-box;
|
|
434
|
-
|
|
458
|
+
`,Pe=f.div`
|
|
435
459
|
padding: .5rem .75rem;
|
|
436
460
|
color: var(--bs-secondary);
|
|
437
461
|
border-radius: var(--bs-border-radius-lg);
|
|
438
462
|
background: #FFFFFF;
|
|
439
463
|
cursor: pointer;
|
|
440
|
-
`,
|
|
464
|
+
`,Be=f.div`
|
|
441
465
|
${e=>e.$deleted&&v`
|
|
442
466
|
text-decoration-line: line-through;
|
|
443
467
|
color: var(--bs-secondary);
|
|
444
468
|
`}
|
|
445
|
-
`,
|
|
469
|
+
`,Le=f.div`
|
|
446
470
|
width: 100%;
|
|
447
471
|
margin-bottom: .5rem;
|
|
448
472
|
margin-top: .5rem;
|
|
@@ -454,7 +478,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
454
478
|
&:last-child {
|
|
455
479
|
margin-bottom: 0;
|
|
456
480
|
}
|
|
457
|
-
`,
|
|
481
|
+
`,Oe=f.div`
|
|
458
482
|
position: absolute;
|
|
459
483
|
top: -1.1rem;
|
|
460
484
|
right: 0;
|
|
@@ -462,7 +486,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
462
486
|
gap: .5rem;
|
|
463
487
|
opacity: 0;
|
|
464
488
|
z-index: 1;
|
|
465
|
-
`,
|
|
489
|
+
`,_e=f.div`
|
|
466
490
|
position: absolute;
|
|
467
491
|
bottom: -1.4rem;
|
|
468
492
|
left: 0;
|
|
@@ -475,24 +499,25 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
475
499
|
display: flex;
|
|
476
500
|
opacity: 0;
|
|
477
501
|
z-index: 1;
|
|
478
|
-
`,
|
|
502
|
+
`,Ue=f.div`
|
|
479
503
|
width: 35px;
|
|
480
504
|
height: 35px;
|
|
481
505
|
border-radius: 50%;
|
|
482
506
|
overflow: hidden;
|
|
507
|
+
position: relative;
|
|
483
508
|
|
|
484
509
|
img, svg {
|
|
485
510
|
width: 100%;
|
|
486
511
|
height: 100%;
|
|
487
512
|
}
|
|
488
|
-
`,
|
|
513
|
+
`,He=f.div`
|
|
489
514
|
width: 0;
|
|
490
515
|
height: 0;
|
|
491
516
|
content: "";
|
|
492
517
|
border: 5px solid transparent;
|
|
493
518
|
border-right-color: #f3f3f3;
|
|
494
519
|
transform: translateY(10px);
|
|
495
|
-
`,
|
|
520
|
+
`,Ke=f.div`
|
|
496
521
|
padding: .875rem;
|
|
497
522
|
background-color: rgb(243, 243, 243);
|
|
498
523
|
border-radius: var(--bs-border-radius-lg);
|
|
@@ -500,27 +525,27 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
500
525
|
position: relative;
|
|
501
526
|
|
|
502
527
|
&:hover {
|
|
503
|
-
${
|
|
528
|
+
${_e}, ${Oe} {
|
|
504
529
|
opacity: 1;
|
|
505
530
|
}
|
|
506
531
|
}
|
|
507
|
-
`,
|
|
532
|
+
`,Qe=f.div`
|
|
508
533
|
display: flex;
|
|
509
534
|
justify-content: flex-start;
|
|
510
535
|
padding: 1rem 0 1rem 0;
|
|
511
536
|
${e=>e.$reverse&&v`
|
|
512
537
|
flex-direction: row-reverse;
|
|
513
538
|
|
|
514
|
-
${
|
|
539
|
+
${He} {
|
|
515
540
|
border-left-color: rgba(var(--bs-primary-rgb), 0.1);
|
|
516
541
|
border-right-color: transparent;
|
|
517
542
|
}
|
|
518
543
|
|
|
519
|
-
${
|
|
544
|
+
${Ke} {
|
|
520
545
|
background: rgba(var(--bs-primary-rgb), 0.1);
|
|
521
546
|
}
|
|
522
547
|
`};
|
|
523
|
-
`,
|
|
548
|
+
`,Xe=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Je(e){let{variables:t,values:r,onSubmit:n,onChange:i,children:o}=e;const a={},s=[],l={};return t.forEach((e=>{a[e.key]={type:"string",title:e.label},"textarea"===e.type?l[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&&s.push(e.key)})),N(E,{schema:{type:"object",properties:a,required:s},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const We=f.button`
|
|
524
549
|
color: var(--bs-secondary);
|
|
525
550
|
cursor: pointer;
|
|
526
551
|
display: flex;
|
|
@@ -543,19 +568,19 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
543
568
|
background-color: var(--bs-gray-200);
|
|
544
569
|
}
|
|
545
570
|
|
|
546
|
-
`;class
|
|
571
|
+
`;class Ye{#c;#e;constructor(){this.#e=new H}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}start(){if(!this.#c){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void j.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#e.emit("result",t)},t.onspeechend=()=>{this.#e.emit("recording",!1)},t.onerror=()=>{this.#e.emit("recording",!1)},this.#c=t}this.#e.emit("recording",!0),this.#c.start()}stop(){this.#c?.stop(),this.#e.emit("recording",!1)}}class Ge{#e;#i;#n;#d;#h;constructor(e,t){this.#i=e,this.#n=t,this.#e=new H}async start(){this.#d=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#h=new AudioContext;const e=this.#h.createScriptProcessor(0,1,1);this.#h.createMediaStreamSource(this.#d).connect(e),e.connect(this.#h.destination);let t=[],r=0;e.onaudioprocess=e=>{const n=e.playbackTime,i=e.inputBuffer.getChannelData(0);let o=!0;for(let e=0;e<i.length;e++)if(Math.abs(i[e])>.01){o=!1;break}if(o){const e=n-r;e>1&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(i)),r=n},this.#e.emit("recording",!0)}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const a=e.subarray(t,t+i),s=r.encodeBuffer(a);n.push(new Int8Array(s)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e),r=new FormData;r.append("file",t,"audio.mp3"),r.append("model",this.#n);try{this.#e.emit("transcribing",!0);const e=await m({url:this.#i,method:"post",data:r});e.text&&this.#e.emit("result",e.text)}catch(e){}finally{this.#e.emit("transcribing",!1)}}stop(){this.#d&&(this.#d.getTracks().forEach((e=>e.stop())),this.#d=void 0),this.#h&&(this.#h.close(),this.#h=void 0),this.#e.emit("recording",!1)}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}}const Ve=h(((e,t)=>{let{onResult:a,url:s,model:l="builtin"}=e;const{start:c,stop:d,recording:h,transcribing:u}=function(e){let{onResult:t,url:o,model:a="builtin"}=e;const s=i(),[l,c]=n(!1),[d,h]=n(!1);return r((()=>()=>{s.current&&(s.current.stop(),s.current=void 0)}),[]),{recording:l,transcribing:d,start:async()=>{s.current||(s.current="builtin"===a?new Ye:new Ge(o,a),s.current.onRecording(c),s.current.onTranscribing(h),s.current.onResult(t)),s.current.start()},stop:()=>{s.current&&s.current.stop()}}}({model:l,url:s,onResult:a});return o(t,(()=>({start:c,stop:d})),[c,d]),N(y,{tooltip:h?"停止":"语音输入",placement:"top",children:M(We,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&N(Ze,{animation:"border",variant:"primary",size:"sm"}),N("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),Ze=f(P)`
|
|
547
572
|
position: absolute;
|
|
548
573
|
--bs-spinner-width: .75rem;
|
|
549
574
|
--bs-spinner-height: .75rem;
|
|
550
575
|
--bs-spinner-border-width: 0.1em;
|
|
551
|
-
`;var
|
|
576
|
+
`;var et=h((function(e,a){let{chat:s,fileTypes:l,speech:c,scrollRef:d,onMessages:h,onSuggestions:g,variables:f,minRows:b,toolbar:v,disabled:x,onLoading:w,autoFocus:k}=e;const E=i(null),$=i(null),q=i(null),[C,S]=n(""),[z,A]=n(""),[F,R]=u([]),[D,T]=n(!1),I=l&&l.length>0?l:Xe,{loading:P,messages:B,suggestions:L,send:U,reset:H}=Y({...s,onSuccess(){requestAnimationFrame((()=>{E.current?.focus()})),s.onSuccess?.()}}),[K,X]=n((()=>{const e=B.filter((e=>!!e.query));if(e.length>0){return e[e.length-1].variables}}));r((()=>{h(B)}),[B]),r((()=>{g(L)}),[L]),r((()=>{w?.(P)}),[P]),r((()=>{!l&&F.length>0&&R([])}),[l]),r((()=>{const e=d.current;if(e&&U){const t=e=>{e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash&&(e.preventDefault(),U(e.target.text))};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[d,U]);const J=t((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!I.includes(_.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-F.length);R((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);let r={method:"POST",url:`${s.url}/upload`,data:t};s.transformRequest&&(r=s.transformRequest("upload",r));const n=await m(r);R((t=>{const r=t.find((t=>t.file===e));r&&(r.path=n.path)}))}catch(t){const r=p(t)?t.message:"unknown error";R((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[F,I]),W=F.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),G=t((()=>{if(C||W.length>0){const e={query:C,files:W};f&&(e.variables={...K,...f.values}),z&&(e.quote=z),U(e),S(""),A(""),R([]),q.current?.stop(!0)}}),[C,W,f,z]);if(o(a,(()=>({setQuery:S,setQuote:A,reset:H,send:U,focus(){E.current?.focus()}}))),f){const e=f.config.filter((e=>!(e.key in(f.values||{})))),t=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&&j.error("请完善必填信息"),n}))};if(e.length>0&&!t(K))return N(rt,{children:N(tt,{children:N(Je,{values:K,variables:e,onSubmit:e=>{let{formData:r}=e;if(t(r,!0))return X(r),!0}})})})}return M(lt,{children:[v,M(st,{$focused:D&&!P,children:[F.length>0&&N(it,{children:F.map(((e,t)=>{let{file:r,error:n,path:i}=e;const o=void 0===n&&void 0===i;return N(nt,{name:r.name,size:r.size,error:n,loading:o,onRemove:()=>{R((e=>{const t=e.findIndex((e=>e.file===r));-1!==t&&e.splice(t,1)}))}},t)}))}),!!z&&M(at,{children:[N("i",{className:"bi bi-quote"}),N("p",{children:z}),N(O,{onClick:()=>A("")})]}),M(ot,{children:[N(Q,{disabled:P||x,ref:E,placeholder:"请输入你的问题, Enter+Shift换行, Enter发送",minRows:b,maxRows:5,value:C,onChange:e=>S(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),G())},autoFocus:k,onFocus:()=>T(!0),onBlur:()=>T(!1)}),l&&N(y,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:M(We,{disabled:F.length>=6,onClick:()=>$.current?.click(),children:[N("input",{onChange:J,multiple:!0,accept:I.join(","),ref:$,type:"file",hidden:!0}),N("i",{className:"bi bi-file-earmark-arrow-up"})]})}),c&&N(Ve,{ref:q,url:`${s.url}/transcriptions`,model:c.model,onResult:e=>{E.current?.focus(),S((t=>t+e+" "))}}),N(We,{className:"text-primary",disabled:!C&&0===W.length,onClick:e=>{e.preventDefault(),G()},children:N("i",{className:"bi bi-send-fill"})})]})]})]})}));const tt=f.div`
|
|
552
577
|
border-radius: var(--bs-border-radius-lg);
|
|
553
578
|
box-shadow: var(--bs-box-shadow-sm);
|
|
554
579
|
margin: 1rem;
|
|
555
580
|
padding: 1rem;
|
|
556
581
|
width: 100%;
|
|
557
582
|
max-width: 500px;
|
|
558
|
-
`,
|
|
583
|
+
`,rt=f.div`
|
|
559
584
|
position: absolute;
|
|
560
585
|
left: 0;
|
|
561
586
|
right: 0;
|
|
@@ -565,15 +590,15 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
565
590
|
display: flex;
|
|
566
591
|
justify-content: center;
|
|
567
592
|
align-items: center;
|
|
568
|
-
`,
|
|
593
|
+
`,nt=f(we)`
|
|
569
594
|
width: calc((100% - .75rem) / 2);
|
|
570
|
-
`,
|
|
595
|
+
`,it=f.div`
|
|
571
596
|
display: flex;
|
|
572
597
|
flex-wrap: wrap;
|
|
573
598
|
padding: .75rem;
|
|
574
599
|
gap: .75rem;
|
|
575
600
|
border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
|
|
576
|
-
`,
|
|
601
|
+
`,ot=f.div`
|
|
577
602
|
display: flex;
|
|
578
603
|
padding: .5rem .5rem .5rem 1rem;
|
|
579
604
|
gap: .25rem;
|
|
@@ -590,7 +615,7 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
590
615
|
color: rgba(54, 54, 54, .3);
|
|
591
616
|
}
|
|
592
617
|
}
|
|
593
|
-
`,
|
|
618
|
+
`,at=f.div`
|
|
594
619
|
margin: .75rem .75rem 0 .75rem;
|
|
595
620
|
padding: 4px 8px;
|
|
596
621
|
display: flex;
|
|
@@ -611,14 +636,14 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
611
636
|
-webkit-box-orient: vertical;
|
|
612
637
|
display: -webkit-box;
|
|
613
638
|
}
|
|
614
|
-
`,
|
|
639
|
+
`,st=f.div`
|
|
615
640
|
background: #FFF;
|
|
616
641
|
border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
|
|
617
642
|
border-radius: var(--bs-border-radius-lg);
|
|
618
643
|
box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
|
|
619
|
-
`,
|
|
644
|
+
`,lt=f.div`
|
|
620
645
|
margin: 0 1rem 1rem;
|
|
621
|
-
`,
|
|
646
|
+
`,ct=a((e=>{let{className:o,bot:a,user:s,input:l,logLevel:c,imageResolver:d,placeholder:h,actions:m,messages:p=[],cite:f,speech:b}=e;const[v,x]=u((()=>W(p))),[y,w]=n(!1),k=i(!l),E=i(null),j=t((()=>{const e=E.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),{ref:$,height:q}=X(),[C,S]=n([]);return r((()=>{(y||!k.current)&&v.length>0&&(y&&(k.current=!0),j())}),[q,y,k,v]),r((()=>{C.length>0&&j()}),[C]),N(ce,{bot:a,user:s,logLevel:c,imageResolver:d,children:N(mt,{className:o,children:M(g,{children:[N(ht,{ref:E,children:M(ut,{ref:$,children:[0===v.length&&h,v.slice(-30).map(((e,t)=>N(De,{actions:m,cite:f,speech:b?.model&&(b?.url||l)?{url:b.url||`${l?.chat.url}/speech`,model:b.model,voice:b.voice,autoplay:b.autoplay}:void 0,message:e,updater:t=>{x((r=>{const n=r.findIndex((t=>t.id===e.id));-1!==n&&t(r[n])}))}},t))),C.length>0&&N(dt,{children:C.map(((e,t)=>N("a",{href:"#!question",children:e},t)))})]})}),l&&N(et,{...l,onMessages:x,onSuggestions:S,scrollRef:E,onLoading:w})]})})})}),I),dt=f.div`
|
|
622
647
|
display: flex;
|
|
623
648
|
flex-direction: column;
|
|
624
649
|
align-items: flex-start;
|
|
@@ -635,20 +660,20 @@ import*as e from"react";import{useCallback as t,useEffect as r,useState as n,use
|
|
|
635
660
|
background: var(--bs-secondary-bg-subtle);
|
|
636
661
|
}
|
|
637
662
|
}
|
|
638
|
-
`,
|
|
663
|
+
`,ht=f.div`
|
|
639
664
|
display: flex;
|
|
640
665
|
flex-direction: column;
|
|
641
666
|
flex: 1;
|
|
642
667
|
overflow-y: auto;
|
|
643
668
|
padding: 0 1rem;
|
|
644
669
|
margin-bottom: .5rem;
|
|
645
|
-
`,
|
|
670
|
+
`,ut=f.div`
|
|
646
671
|
display: flex;
|
|
647
672
|
flex-direction: column;
|
|
648
673
|
flex: 1;
|
|
649
|
-
`,
|
|
674
|
+
`,mt=f.div`
|
|
650
675
|
display: flex;
|
|
651
676
|
flex-direction: column;
|
|
652
677
|
height: 100%;
|
|
653
678
|
position: relative;
|
|
654
|
-
`;export{
|
|
679
|
+
`;export{ne as Markdown,ct as MessageBox,Je as VariableForm,J as pickQuestions,Y as useChat,ze as useSynthesis};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prebuild": "rimraf es types",
|
|
6
6
|
"build": "rollup -c --environment NODE_ENV:production",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime": "^7.11.2",
|
|
20
|
-
"@
|
|
20
|
+
"@breezystack/lamejs": "^1.2.7",
|
|
21
|
+
"@topthink/components": "^1.0.104",
|
|
21
22
|
"@types/mdast": "^4.0.4",
|
|
22
23
|
"eventemitter3": "^5.0.1",
|
|
23
24
|
"katex": "^0.16.9",
|
|
24
|
-
"lamejs": "github:zhuker/lamejs",
|
|
25
25
|
"mdast-util-from-markdown": "^2.0.1",
|
|
26
26
|
"micromark-util-character": "^2.1.0",
|
|
27
27
|
"micromark-util-symbol": "^2.0.0",
|
|
@@ -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": "64d14b1a75ae909fff14afbfe2b2e5e4d96a00bc"
|
|
69
69
|
}
|
|
@@ -14,6 +14,12 @@ interface Props {
|
|
|
14
14
|
avatar: string;
|
|
15
15
|
};
|
|
16
16
|
messages?: ConversationMessage[];
|
|
17
|
+
speech?: {
|
|
18
|
+
model?: string;
|
|
19
|
+
voice?: string;
|
|
20
|
+
autoplay?: boolean;
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
17
23
|
placeholder?: ReactNode;
|
|
18
24
|
logLevel?: LogLevel;
|
|
19
25
|
imageResolver?: (url: string) => string;
|
|
@@ -36,5 +42,5 @@ interface Props {
|
|
|
36
42
|
actions?: MessageActions;
|
|
37
43
|
cite?: Components['cite'];
|
|
38
44
|
}
|
|
39
|
-
declare const MessageBox: import("react").MemoExoticComponent<({ className, bot, user, input, logLevel, imageResolver, placeholder, actions, messages: initMessages, cite, }: Props) => JSX.Element>;
|
|
45
|
+
declare const MessageBox: import("react").MemoExoticComponent<({ className, bot, user, input, logLevel, imageResolver, placeholder, actions, messages: initMessages, cite, speech, }: Props) => JSX.Element>;
|
|
40
46
|
export default MessageBox;
|
|
@@ -13,6 +13,12 @@ interface Props {
|
|
|
13
13
|
actions?: MessageActions;
|
|
14
14
|
updater: (callback: (message: Message) => void) => void;
|
|
15
15
|
cite?: Components['cite'];
|
|
16
|
+
speech?: {
|
|
17
|
+
url: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
voice?: string;
|
|
20
|
+
autoplay?: boolean;
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
|
-
declare const MessageItem: import("react").MemoExoticComponent<({ message, actions, updater, cite }: Props) => JSX.Element>;
|
|
23
|
+
declare const MessageItem: import("react").MemoExoticComponent<({ message, actions, updater, cite, speech }: Props) => JSX.Element>;
|
|
18
24
|
export default MessageItem;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
interface Props {
|
|
3
|
+
url: string;
|
|
4
|
+
model?: string;
|
|
5
|
+
voice?: string;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
avatarRef: RefObject<HTMLDivElement>;
|
|
8
|
+
contentRef: RefObject<HTMLDivElement>;
|
|
9
|
+
autoplay?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export default function SpeechAction({ url, model, voice, loading, autoplay, contentRef, avatarRef }: Props): JSX.Element;
|
|
12
|
+
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { default as MessageBox } from './components/message-box';
|
|
|
4
4
|
export { default as Markdown } from './components/markdown';
|
|
5
5
|
export { default as VariableForm } from './components/variable-form';
|
|
6
6
|
export { default as pickQuestions } from './utils/pick-questions';
|
|
7
|
+
export { default as useSynthesis } from './speech/use-synthesis';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Synthesis } from '../../types';
|
|
2
|
+
export default class Builtin implements Synthesis {
|
|
3
|
+
#private;
|
|
4
|
+
constructor();
|
|
5
|
+
protected speak(): void;
|
|
6
|
+
protected clear(): void;
|
|
7
|
+
start(text: string | string[], append?: boolean): void;
|
|
8
|
+
stop(): void;
|
|
9
|
+
onPlaying(onPlaying: (playing: boolean) => void): void;
|
|
10
|
+
onSpeaking(onSpeaking: (speaking: boolean) => void): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Synthesis } from '../../types';
|
|
2
|
+
export default class Custom implements Synthesis {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(url: string, model: string, voice?: string);
|
|
5
|
+
protected createLoader(text: string): Promise<HTMLAudioElement | undefined>;
|
|
6
|
+
protected loadAudioData(): Promise<void>;
|
|
7
|
+
protected waitForAudioLoaded(text: string): Promise<HTMLAudioElement | undefined>;
|
|
8
|
+
protected playAudio(index?: number): Promise<void>;
|
|
9
|
+
protected clear(): void;
|
|
10
|
+
start(text: string | string[], append?: boolean): void;
|
|
11
|
+
update(text: string): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
onPlaying(onPlaying: (playing: boolean) => void): void;
|
|
14
|
+
onSpeaking(onSpeaking: (speaking: boolean) => void): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
interface Config {
|
|
3
|
+
text: string | RefObject<HTMLDivElement>;
|
|
4
|
+
model?: string;
|
|
5
|
+
voice?: string;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
url: string;
|
|
8
|
+
}
|
|
9
|
+
export default function useSynthesis({ text, url, voice, loading, model }: Config): {
|
|
10
|
+
playing: boolean;
|
|
11
|
+
speaking: boolean;
|
|
12
|
+
start: (append?: boolean) => Promise<void>;
|
|
13
|
+
stop: () => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
package/types/types.d.ts
CHANGED
|
@@ -93,3 +93,9 @@ export interface Recognition {
|
|
|
93
93
|
onRecording(onRecording: (recording: boolean) => void): void;
|
|
94
94
|
onTranscribing(onTranscribing: (transcribing: boolean) => void): void;
|
|
95
95
|
}
|
|
96
|
+
export interface Synthesis {
|
|
97
|
+
start(text: string | string[], append?: boolean): void;
|
|
98
|
+
stop(): void;
|
|
99
|
+
onPlaying(onPlaying: (playing: boolean) => void): void;
|
|
100
|
+
onSpeaking(onSpeaking: (speaking: boolean) => void): void;
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getElementContent(element: HTMLElement): string[];
|