@topthink/chat 1.1.9 → 1.1.10
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 +39 -39
- package/package.json +3 -3
- package/types/components/message-box/reasoning.d.ts +7 -0
- package/types/types.d.ts +3 -1
package/es/index.js
CHANGED
|
@@ -439,7 +439,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
439
439
|
&::before {
|
|
440
440
|
transform: scale(1.4)
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
`;function Te(r){let{reasoning:n,loading:i}=r;const[o,a]=C(i);return e(M,{children:e("div",{className:"mb-2",children:t("div",o||i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>a(i),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[i?e(_,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:i?"思考中":"已思考"}),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(oe,{content:n})})})]}:{onClick:()=>a(!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?e(_,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:i?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})}const Pe=w((n=>{let{message:i,actions:a,updater:s,cite:l,speech:c}=n;const{query:h,quote:u,files:m=[],chunks:p,annotation:g}=i,{user:f,bot:b,logLevel:v="none"}=de(),x=k((()=>p?p.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>t.content&&"string"==typeof t.content?e+t.content+"\n":e),"")}),""):""),[p]),y=E(null),w=E(null),j=E(null);return t(r,{children:[(h||m.length>0)&&t(Je,{$reverse:!0,children:[f&&e(Qe,{children:e("img",{src:f.avatar})}),e(We,{}),t(Xe,{ref:y,children:[h&&e(oe,{content:h}),u&&e(U,{trigger:"click",container:y,rootClose:!0,placement:"bottom",overlay:e(Le,{body:!0,children:u}),children:e(Oe,{children:e(Be,{children:u})})}),m.length>0&&m.map(((t,r)=>{let{name:n,size:i,path:o}=t;return d(o)?e(me,{src:`/uploads/${o}`},r):e(Ue,{children:e(Ee,{name:n,size:i})},r)}))]})]}),p&&t(Je,{children:[e(Qe,{ref:w,children:e("img",{src:b.avatar})}),e(We,{}),t(Xe,{children:[(h||m.length>0)&&t(He,{children:[e(o,{placement:"top",content:x,as:qe,tooltip:!0}),c&&e(Re,{loading:i.loading,avatarRef:w,contentRef:j,...c}),a?.({Component:qe,message:i,content:x,setMessage:s})]}),e(Ke,{children:["stats","all"].includes(v)&&i.stats&&t(r,{children:[t("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",i.stats.usage]})]})}),e(_e,{ref:j,$deleted:!!g,children:p.length>0&&p.map(((r,n)=>t(M,{children:[r.reasoning&&e(Te,{reasoning:r.reasoning,loading:!r.content}),r.content&&e(oe,{cite:l,content:r.content}),r.tools.map(((t,r)=>e(ge,{tool:t},r))),r.error&&e(oe,{content:`[${r.error}]`})]},n)))}),g&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(oe,{content:g.answer})]}),i.loading&&e(we,{})]})]})]})})),Le=i(H)`
|
|
443
443
|
max-width: calc(100% - .875rem * 2);
|
|
444
444
|
width: calc(100% - .875rem * 2);
|
|
445
445
|
font-size: 1rem;
|
|
@@ -448,25 +448,25 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
448
448
|
.popover-body {
|
|
449
449
|
padding: .5rem .75rem;
|
|
450
450
|
}
|
|
451
|
-
`,
|
|
451
|
+
`,Be=i.div`
|
|
452
452
|
overflow: hidden;
|
|
453
453
|
text-overflow: ellipsis;
|
|
454
454
|
word-break: break-all;
|
|
455
455
|
-webkit-line-clamp: 2;
|
|
456
456
|
-webkit-box-orient: vertical;
|
|
457
457
|
display: -webkit-box;
|
|
458
|
-
`,
|
|
458
|
+
`,Oe=i.div`
|
|
459
459
|
padding: .5rem .75rem;
|
|
460
460
|
color: var(--bs-secondary);
|
|
461
461
|
border-radius: var(--bs-border-radius-lg);
|
|
462
462
|
background: #FFFFFF;
|
|
463
463
|
cursor: pointer;
|
|
464
|
-
`,
|
|
464
|
+
`,_e=i.div`
|
|
465
465
|
${e=>e.$deleted&&a`
|
|
466
466
|
text-decoration-line: line-through;
|
|
467
467
|
color: var(--bs-secondary);
|
|
468
468
|
`}
|
|
469
|
-
`,
|
|
469
|
+
`,Ue=i.div`
|
|
470
470
|
width: 100%;
|
|
471
471
|
margin-bottom: .5rem;
|
|
472
472
|
margin-top: .5rem;
|
|
@@ -478,7 +478,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
478
478
|
&:last-child {
|
|
479
479
|
margin-bottom: 0;
|
|
480
480
|
}
|
|
481
|
-
`,
|
|
481
|
+
`,He=i.div`
|
|
482
482
|
position: absolute;
|
|
483
483
|
top: -1.1rem;
|
|
484
484
|
right: 0;
|
|
@@ -486,7 +486,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
486
486
|
gap: .5rem;
|
|
487
487
|
opacity: 0;
|
|
488
488
|
z-index: 1;
|
|
489
|
-
`,
|
|
489
|
+
`,Ke=i.div`
|
|
490
490
|
position: absolute;
|
|
491
491
|
bottom: -1.4rem;
|
|
492
492
|
left: 0;
|
|
@@ -499,7 +499,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
499
499
|
display: flex;
|
|
500
500
|
opacity: 0;
|
|
501
501
|
z-index: 1;
|
|
502
|
-
`,
|
|
502
|
+
`,Qe=i.div`
|
|
503
503
|
width: 35px;
|
|
504
504
|
height: 35px;
|
|
505
505
|
border-radius: 50%;
|
|
@@ -510,14 +510,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
510
510
|
width: 100%;
|
|
511
511
|
height: 100%;
|
|
512
512
|
}
|
|
513
|
-
`,
|
|
513
|
+
`,We=i.div`
|
|
514
514
|
width: 0;
|
|
515
515
|
height: 0;
|
|
516
516
|
content: "";
|
|
517
517
|
border: 5px solid transparent;
|
|
518
518
|
border-right-color: #f3f3f3;
|
|
519
519
|
transform: translateY(10px);
|
|
520
|
-
`,
|
|
520
|
+
`,Xe=i.div`
|
|
521
521
|
padding: .875rem;
|
|
522
522
|
background-color: rgb(243, 243, 243);
|
|
523
523
|
border-radius: var(--bs-border-radius-lg);
|
|
@@ -525,27 +525,27 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
525
525
|
position: relative;
|
|
526
526
|
|
|
527
527
|
&:hover {
|
|
528
|
-
${
|
|
528
|
+
${Ke}, ${He} {
|
|
529
529
|
opacity: 1;
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
-
`,
|
|
532
|
+
`,Je=i.div`
|
|
533
533
|
display: flex;
|
|
534
534
|
justify-content: flex-start;
|
|
535
535
|
padding: 1rem 0 1rem 0;
|
|
536
536
|
${e=>e.$reverse&&a`
|
|
537
537
|
flex-direction: row-reverse;
|
|
538
538
|
|
|
539
|
-
${
|
|
539
|
+
${We} {
|
|
540
540
|
border-left-color: rgba(var(--bs-primary-rgb), 0.1);
|
|
541
541
|
border-right-color: transparent;
|
|
542
542
|
}
|
|
543
543
|
|
|
544
|
-
${
|
|
544
|
+
${Xe} {
|
|
545
545
|
background: rgba(var(--bs-primary-rgb), 0.1);
|
|
546
546
|
}
|
|
547
547
|
`};
|
|
548
|
-
`,
|
|
548
|
+
`,Ve=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Ye(t){let{variables:r,values:n,onSubmit:i,onChange:o,children:a}=t;const s={},l=[],c={};return r.forEach((e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?c[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&l.push(e.key)})),e(u,{schema:{type:"object",properties:s,required:l},formData:n,omitExtraData:!0,uiSchema:c,submitText:"开始对话",onSubmit:i,onChange:o,children:a})}const Ge=i.button`
|
|
549
549
|
color: var(--bs-secondary);
|
|
550
550
|
cursor: pointer;
|
|
551
551
|
display: flex;
|
|
@@ -568,12 +568,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
568
568
|
background-color: var(--bs-gray-200);
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
-
`;class
|
|
571
|
+
`;class Ze{#s;#e;constructor(){this.#e=new J}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}start(){if(!this.#s){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void m.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#e.emit("result",t)},t.onspeechend=()=>{this.#e.emit("recording",!1)},t.onerror=e=>{this.#e.emit("recording",!1),m.error(e.error)},this.#s=t}this.#e.emit("recording",!0),this.#s.start()}stop(){this.#s?.stop(),this.#e.emit("recording",!1)}}class et{#e;#n;#l;#c;constructor(e){this.#n=e,this.#e=new J}async start(){try{this.#l=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#c=new AudioContext;const e=this.#c.createScriptProcessor(0,1,1);this.#c.createMediaStreamSource(this.#l).connect(e),e.connect(this.#c.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,a=e.inputBuffer.getChannelData(0);let s=!0;for(let e=0;e<a.length;e++)if(Math.abs(a[e])>n){s=!1;break}if(s){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(a)),r=o},this.#e.emit("recording",!0)}catch(e){m.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const a=e.subarray(t,t+i),s=r.encodeBuffer(a);n.push(new Int8Array(s)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#e.emit("transcribing",!0);const e=await this.#n(t);e&&this.#e.emit("result",e)}catch(e){}finally{this.#e.emit("transcribing",!1)}}stop(){this.#l&&(this.#l.getTracks().forEach((e=>e.stop())),this.#l=void 0),this.#c&&(this.#c.close(),this.#c=void 0),this.#e.emit("recording",!1)}onResult(e){this.#e.on("result",e)}onRecording(e){this.#e.on("recording",e)}onTranscribing(e){this.#e.on("transcribing",e)}}const tt=q(((r,n)=>{let{onResult:i,model:o="builtin"}=r;const{request:a}=de(),s=k((()=>{if("builtin"!==o)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",o);return(await a({url:"/transcriptions",method:"post",data:t})).text}}),[o]),{start:c,stop:d,recording:h,transcribing:u}=function(e){let{onResult:t,loader:r}=e;const n=E(),[i,o]=C(!1),[a,s]=C(!1);return z((()=>()=>{n.current&&(n.current.stop(),n.current=void 0)}),[]),{recording:i,transcribing:a,start:async()=>{n.current||(n.current=r?new et(r):new Ze,n.current.onRecording(o),n.current.onTranscribing(s),n.current.onResult(t)),n.current.start()},stop:()=>{n.current&&n.current.stop()}}}({onResult:i,loader:s});return S(n,(()=>({start:c,stop:d})),[c,d]),e(l,{tooltip:h?"停止":"语音输入",placement:"top",children:t(Ge,{onMouseDown:e=>{e.preventDefault(),h?d():c()},children:[u&&e(rt,{animation:"border",variant:"primary",size:"sm"}),e("i",h?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})})),rt=i(_)`
|
|
572
572
|
position: absolute;
|
|
573
573
|
--bs-spinner-width: .75rem;
|
|
574
574
|
--bs-spinner-height: .75rem;
|
|
575
575
|
--bs-spinner-border-width: 0.1em;
|
|
576
|
-
`,
|
|
576
|
+
`,nt=q(((t,r)=>{let{className:n,children:i,size:o,tooltip:a,placement:s,onClick:c,onMouseDown:d}=t;const h=e(it,{ref:r,className:n,onClick:c,onMouseDown:d,$size:o,children:i});return a?e(l,{tooltip:a,placement:s,children:h}):h})),it=i.div`
|
|
577
577
|
width: 2rem;
|
|
578
578
|
height: 2rem;
|
|
579
579
|
align-items: center;
|
|
@@ -597,10 +597,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
597
597
|
&:hover {
|
|
598
598
|
background-color: var(--bs-secondary-bg-subtle);
|
|
599
599
|
}
|
|
600
|
-
`;function
|
|
600
|
+
`;function ot(){const{request:n,reset:i,conversationId:o}=de(),[a,s]=C(!1);return t(r,{children:[e(nt,{tooltip:"历史记录",placement:"top",onClick:()=>s(!0),children:e("i",{className:"bi bi-clock-history"})}),e(g,{show:a,onHide:()=>{s(!1)},placement:"end",header:"聊天历史记录",bodyAs:at,children:a&&e(ht,{children:e(dt,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:r=>{let{data:a,loading:c,setData:d}=r;return a.length||c?a.map(((r,a)=>{const c=r.messages?.reduce(((e,t)=>e+t.chunks.reduce(((e,t)=>e+(t.content||"")),"")),"");return t(M,{children:[a>0&&e("hr",{className:"mx-2 my-2"}),t(ct,{onClick:()=>{i(r),s(!1)},children:[t(lt,{children:[o===r.id&&e(K,{bg:"secondary",children:"当前"}),e("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),e("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:f(r.update_time).fromNow()})]}),t(st,{children:[e("span",{className:"overflow-hidden text-truncate me-auto",children:c||" "}),e("span",{className:"ms-3",children:o!==r.id&&e(l,{tooltip:"删除",children:e(b,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{d((e=>{const t=e.findIndex((e=>e.id===r.id));-1!==t&&e.splice(t,1)}))},children:e("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)})):e("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})}})})})]})}const at=i.div`
|
|
601
601
|
padding: 0;
|
|
602
602
|
overflow: hidden;
|
|
603
|
-
`,
|
|
603
|
+
`,st=i.div`
|
|
604
604
|
color: var(--bs-gray-600);
|
|
605
605
|
font-weight: 400;
|
|
606
606
|
line-height: 22px;
|
|
@@ -610,11 +610,11 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
610
610
|
& :last-child {
|
|
611
611
|
display: none;
|
|
612
612
|
}
|
|
613
|
-
`,
|
|
613
|
+
`,lt=i.div`
|
|
614
614
|
display: flex;
|
|
615
615
|
align-items: center;
|
|
616
616
|
gap: .25rem;
|
|
617
|
-
`,
|
|
617
|
+
`,ct=i.div`
|
|
618
618
|
gap: .5rem;
|
|
619
619
|
display: flex;
|
|
620
620
|
flex-direction: column;
|
|
@@ -627,34 +627,34 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
627
627
|
|
|
628
628
|
|
|
629
629
|
&:hover {
|
|
630
|
-
${
|
|
630
|
+
${st} :last-child {
|
|
631
631
|
display: initial;
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
`,
|
|
635
|
+
`,dt=i(p)`
|
|
636
636
|
display: flex;
|
|
637
637
|
flex-direction: column;
|
|
638
638
|
padding: .5rem;
|
|
639
|
-
`,
|
|
639
|
+
`,ht=i.div`
|
|
640
640
|
height: 100%;
|
|
641
641
|
overflow-y: auto;
|
|
642
|
-
`;var
|
|
642
|
+
`;var ut;function mt(){return mt=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},mt.apply(this,arguments)}const pt=e=>y.createElement("svg",mt({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),ut||(ut=y.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function gt(){const{reset:t}=de();return e(nt,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(pt,{})})}function ft(r){let{children:n}=r;return t(vt,{children:[n,t(bt,{children:[e(ot,{}),e(gt,{})]})]})}const bt=i.div`
|
|
643
643
|
display: flex;
|
|
644
644
|
gap: .25rem;
|
|
645
645
|
margin-left: auto;
|
|
646
|
-
`,
|
|
646
|
+
`,vt=i.div`
|
|
647
647
|
margin-bottom: .5rem;
|
|
648
648
|
display: flex;
|
|
649
649
|
padding: 0 .125rem;
|
|
650
|
-
`;var
|
|
650
|
+
`;var xt=q((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:s,variables:c,minRows:d,toolbar:u,disabled:p,autoFocus:g,placeholder:f="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const b=E(null),x=E(null),y=E(null),[w,k]=C(""),[j,N]=C(""),[M,q]=v([]),[A,F]=C(!1),R=o&&o.length>0?o:Ve,{messages:D,loading:I,request:T}=de(),{send:P}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:a,setConversationId:s,request:l}=de(),c=E(null),d=$((async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:a},signal:c.current.signal};const t=await l(e);i(t)}catch{}finally{c.current=null}}),[a,l]),u=$((async function(e){if("string"==typeof e){for(var u=arguments.length,m=new Array(u>1?u-1:0),p=1;p<u;p++)m[p-1]=arguments[p];e={query:e,...m}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){c.current&&c.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:a},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?s(t.conversation):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",reasoning:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.reasoning?r.chunks[e].reasoning+=t.chunks.reasoning:t.chunks.content&&(r.chunks[e].content+=t.chunks.content)}else t.stats&&(r.stats=t.stats)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await l(e),t&&d()}catch(e){let t="未知错误";h(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[a,l]);return{send:u}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{b.current?.focus()}))}}),[L,B]=C();z((()=>{const e=D.filter((e=>!!e.query));B(e.at(-1)?.variables)}),[D]),z((()=>{!o&&M.length>0&&q([])}),[o]),z((()=>{const e=s.current;if(e&&P){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};c&&(t.variables={...L,...c.values}),P(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[c,L]);const O=$((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!R.includes(W.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-M.length);q((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await T({method:"POST",url:"/upload",data:t});q((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=h(t)?t.message:"unknown error";q((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[M,R]),_=M.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),U=$((()=>{if(w||_.length>0){const e={query:w,files:_};c&&(e.variables={...L,...c.values}),j&&(e.quote=j),P(e),k(""),N(""),q([]),y.current?.stop(!0)}}),[w,_,c,L,j]);if(S(n,(()=>({setQuery:k,setQuote:N,send:P,focus(){b.current?.focus()}}))),c){const t=c.config.filter((e=>!(e.key in(c.values||{})))),r=function(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!e&&t.every((t=>{const n=!t.required||e?.[t.key];return!n&&r&&m.error("请完善必填信息"),n}))};if(t.length>0&&!r(L))return e(wt,{children:e(yt,{children:e(Ye,{values:L,variables:t,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return B(t),!0}})})})}return t(Mt,{children:[u&&e(ft,{children:u}),t(Ct,{$focused:A&&!I,children:[M.length>0&&e(Et,{children:M.map(((t,r)=>{let{file:n,error:i,path:o}=t;const a=void 0===i&&void 0===o;return e(kt,{name:n.name,size:n.size,error:i,loading:a,onRemove:()=>{q((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!j&&t(Nt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:j}),e(Q,{onClick:()=>N("")})]}),t(jt,{children:[e(Y,{disabled:I||p,ref:b,placeholder:f,minRows:d,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),U())},autoFocus:g,onFocus:()=>F(!0),onBlur:()=>F(!1)}),o&&e(l,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(Ge,{disabled:M.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:O,multiple:!0,accept:R.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&e(tt,{ref:y,model:a.model,onResult:e=>{b.current?.focus(),k((t=>t+e+" "))}}),e(Ge,{className:"text-primary",disabled:!w&&0===_.length,onClick:e=>{e.preventDefault(),U()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})}));const yt=i.div`
|
|
651
651
|
border-radius: var(--bs-border-radius-lg);
|
|
652
652
|
box-shadow: var(--bs-box-shadow-sm);
|
|
653
653
|
margin: 1rem;
|
|
654
654
|
padding: 1rem;
|
|
655
655
|
width: 100%;
|
|
656
656
|
max-width: 500px;
|
|
657
|
-
`,
|
|
657
|
+
`,wt=i.div`
|
|
658
658
|
position: absolute;
|
|
659
659
|
left: 0;
|
|
660
660
|
right: 0;
|
|
@@ -664,15 +664,15 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
664
664
|
display: flex;
|
|
665
665
|
justify-content: center;
|
|
666
666
|
align-items: center;
|
|
667
|
-
`,
|
|
667
|
+
`,kt=i(Ee)`
|
|
668
668
|
width: calc((100% - .75rem) / 2);
|
|
669
|
-
`,
|
|
669
|
+
`,Et=i.div`
|
|
670
670
|
display: flex;
|
|
671
671
|
flex-wrap: wrap;
|
|
672
672
|
padding: .75rem;
|
|
673
673
|
gap: .75rem;
|
|
674
674
|
border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
|
|
675
|
-
`,
|
|
675
|
+
`,jt=i.div`
|
|
676
676
|
display: flex;
|
|
677
677
|
padding: .5rem .5rem .5rem 1rem;
|
|
678
678
|
gap: .25rem;
|
|
@@ -689,7 +689,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
689
689
|
color: rgba(54, 54, 54, .3);
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
|
-
`,
|
|
692
|
+
`,Nt=i.div`
|
|
693
693
|
margin: .75rem .75rem 0 .75rem;
|
|
694
694
|
padding: 4px 8px;
|
|
695
695
|
display: flex;
|
|
@@ -710,14 +710,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
710
710
|
-webkit-box-orient: vertical;
|
|
711
711
|
display: -webkit-box;
|
|
712
712
|
}
|
|
713
|
-
`,
|
|
713
|
+
`,Ct=i.div`
|
|
714
714
|
background: #FFF;
|
|
715
715
|
border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
|
|
716
716
|
border-radius: var(--bs-border-radius-lg);
|
|
717
717
|
box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
|
|
718
|
-
`,
|
|
718
|
+
`,Mt=i.div`
|
|
719
719
|
margin: 0 1rem 1rem;
|
|
720
|
-
`;function
|
|
720
|
+
`;function qt(e){if((e=e.filter((e=>!!e.trim()))).length>3){const t=[...e];let r=e.length-3;for(;r--;){let e=Math.floor(Math.random()*t.length);t.splice(e,1)}e=t}return e}const zt=w(q(((r,i)=>{let{className:o,bot:a,user:s,input:l,logLevel:c,imageResolver:d,placeholder:h,actions:u,onboarding:m,conversation:p,cite:g,speech:f,request:b}=r;const y=$((e=>{const t=[];if(m&&!1!==m.enable){const e=qt(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(function(e){return e.map((e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map((e=>{let{content:t="",error:r,tools:n=[],reasoning:i}=e;return{content:t,reasoning:i,error:r,tools:n}})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}})))}(e.messages||[])):t}),[m]),[w,j]=C(p?.id),[N,M]=v([]);z((()=>{M(y(p))}),[m]);const[q,A]=C(!1),F=E(!l),R=E(null),D=$((()=>{const e=R.current;e&&requestAnimationFrame((()=>{e.scrollTo({top:e.scrollHeight})}))}),[]),{ref:I,height:T}=G(),[P,L]=C([]);z((()=>{(q||!F.current)&&N.length>0&&(q&&(F.current=!0),D())}),[T,q,F,N]),z((()=>{P.length>0&&D()}),[P]);const B=$((e=>{q||(j(e?.id),M(y(e)),L([]))}),[q,y]);return S(i,(()=>({reset:B})),[B]),e(he,{request:k((()=>b?"string"==typeof b?x.create({baseURL:b}):b:x),[b]),bot:a,user:s,logLevel:c,imageResolver:d,conversationId:w,setConversationId:j,messages:N,setMessages:M,suggestions:P,setSuggestions:L,loading:q,setLoading:A,reset:B,children:e(Ft,{className:o,children:t(n,{children:[e(St,{ref:R,children:t(At,{ref:I,children:[0===N.length&&h,N.slice(-30).map(((t,r)=>e(Pe,{actions:u,cite:g,speech:f,message:t,updater:e=>{M((r=>{const n=r.findIndex((e=>e.id===t.id));-1!==n&&e(r[n])}))}},r))),P.length>0&&e($t,{children:P.map(((t,r)=>e("a",{href:"#!question",children:t},r)))})]})}),l&&e(xt,{...l,scrollRef:R})]})})})})),O),$t=i.div`
|
|
721
721
|
display: flex;
|
|
722
722
|
flex-direction: column;
|
|
723
723
|
align-items: flex-start;
|
|
@@ -734,20 +734,20 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
734
734
|
background: var(--bs-secondary-bg-subtle);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
-
|
|
737
|
+
`,St=i.div`
|
|
738
738
|
display: flex;
|
|
739
739
|
flex-direction: column;
|
|
740
740
|
flex: 1;
|
|
741
741
|
overflow-y: auto;
|
|
742
742
|
padding: 0 1rem;
|
|
743
743
|
margin-bottom: .5rem;
|
|
744
|
-
`,
|
|
744
|
+
`,At=i.div`
|
|
745
745
|
display: flex;
|
|
746
746
|
flex-direction: column;
|
|
747
747
|
flex: 1;
|
|
748
|
-
`,
|
|
748
|
+
`,Ft=i.div`
|
|
749
749
|
display: flex;
|
|
750
750
|
flex-direction: column;
|
|
751
751
|
height: 100%;
|
|
752
752
|
position: relative;
|
|
753
|
-
`;export{
|
|
753
|
+
`;export{nt as ActionButton,oe as Markdown,zt as MessageBox,Ye as VariableForm,qt as pickQuestions,Fe 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.10",
|
|
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.7",
|
|
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": "4def1cecb5375f8a315bda7443ba86d4572d49c0"
|
|
69
69
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface Message {
|
|
|
25
25
|
variables?: Record<string, string>;
|
|
26
26
|
chunks?: {
|
|
27
27
|
content: string;
|
|
28
|
+
reasoning?: string;
|
|
28
29
|
tools: ToolMessage[];
|
|
29
30
|
error?: string;
|
|
30
31
|
}[];
|
|
@@ -58,7 +59,8 @@ export interface ConversationMessage {
|
|
|
58
59
|
files?: [];
|
|
59
60
|
variables?: Record<string, string>;
|
|
60
61
|
chunks: {
|
|
61
|
-
content?:
|
|
62
|
+
content?: string;
|
|
63
|
+
reasoning?: string;
|
|
62
64
|
error?: string;
|
|
63
65
|
tools?: ToolMessage[];
|
|
64
66
|
}[];
|