@topthink/chat 1.3.23 → 1.3.24
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 +32 -28
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -390,6 +390,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
390
390
|
line-height: 1.8;
|
|
391
391
|
border-spacing: 0;
|
|
392
392
|
|
|
393
|
+
thead th {
|
|
394
|
+
background-color: #f5f5f5;
|
|
395
|
+
}
|
|
396
|
+
|
|
393
397
|
th {
|
|
394
398
|
text-align: left;
|
|
395
399
|
|
|
@@ -644,7 +648,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
644
648
|
&:active {
|
|
645
649
|
transform: ${e=>e.$disabled?"none":"scale(0.98)"};
|
|
646
650
|
}
|
|
647
|
-
`;function Ht({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Dt(),[a,l]=Tt(void 0!==s),c=o||a,{schema:u,uiSchema:m}=I(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"string",title:i.label,default:i.default},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"number"===i.type?(e[i.name].type="number",void 0!==i.default&&(e[i.name].default=Number(i.default))):"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},"string"==typeof i.default&&(e[i.name].default=i.default.split(",")),r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Qt,{className:"rounded bg-white shadow-sm",children:[r&&e(Kt,{children:r}),e(d,{schema:u,uiSchema:m,formData:s,onSubmit:({formData:e})=>{c||(l(!0),i(e))},disabled:c,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Jt,{children:t})})]})}const Jt=n.div`
|
|
651
|
+
`;function Ht({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Dt(),[a,l]=Tt(void 0!==s),c=o||a,{schema:u,uiSchema:m}=I(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"string",title:i.label,default:i.default},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"number"===i.type?(e[i.name].type="number",void 0!==i.default&&(e[i.name].default=Number(i.default))):"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},"string"==typeof i.default&&(e[i.name].default=i.default.split(",").map(e=>e.trim()).filter(e=>i.options?.includes(e))),r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Qt,{className:"rounded bg-white shadow-sm",children:[r&&e(Kt,{children:r}),e(d,{schema:u,uiSchema:m,formData:s,onSubmit:({formData:e})=>{c||(l(!0),i(e))},disabled:c,validate:!0,onError:e=>console.error(e),showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Jt,{children:t})})]})}const Jt=n.div`
|
|
648
652
|
display: flex;
|
|
649
653
|
justify-content: flex-end;
|
|
650
654
|
border-top: 1px solid var(--bs-border-color);
|
|
@@ -700,27 +704,27 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
700
704
|
button {
|
|
701
705
|
padding: .25rem 1.5rem;
|
|
702
706
|
}
|
|
703
|
-
`;
|
|
707
|
+
`;class Gt extends T{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onRenderError(e)}render(){return this.state.hasError?null:this.props.children}}function Zt({suspend:t}){const{readonly:r,inputRef:n}=Re(),{chunkIndex:i,chunk:o,toolIndex:s,tool:a,isLastMessage:l}=function(){const e=S(Ft);if(!e)throw new Error("useContext must be used within a Provider");return e}(),c=F(e=>{n.current?.resume({chunk:i,tool:s,payload:e})},[i,s]),d=F(()=>{c({error:"Failed to render the interactive component. The generated form parameters may be invalid. Please check the parameters and try regenerating."})},[c]);let u=null;switch(t.type){case"select":u=e(Ot,{...t.select});break;case"form":u=e(Ht,{...t.form});break;case"confirm":u=e(Wt,{...t.confirm})}const m=a?.response||o.node?.output;return e(Pt,{resume:c,disabled:r||!!o.error||!l,response:"(Empty)"===m?void 0:m,children:e(Gt,{onRenderError:d,children:u})})}function er({value:t,cite:n}){const i=t=>"string"==typeof t?e(Nt,{content:t,cite:n}):"image"===t.type?e(At,{src:t.image}):"suspend"===t.type?e(Zt,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(D,{children:i(t)},r))}):i(t)}const tr=({reasoning:r,loading:n})=>{const[i,o]=z(!1);return q(()=>{n||o(!1)},[n]),e(D,{children:e("div",{className:"mb-2",children:t("div",i?{className:"border rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:e("div",{className:"border rounded bg-light p-2",children:e(Nt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},rr=P(t=>{const{renderReasoning:r}=Re();return r?r({Component:tr,props:t}):e(tr,{...t})}),nr=e=>null==e?"None":"object"==typeof e?JSON.stringify(e,null,2):e;function ir({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=Re(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:u,defaultExpanded:m}=I(()=>{const i=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),a=e("span",{className:"text-truncate",children:r.title}),l=t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"参数"})}),e(sr,{className:"border-top p-2",children:r.arguments})]}),s&&t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"响应"})}),e(sr,{className:"border-top p-2",children:nr(r.response)})]})]}),c=r.content&&e(er,{value:r.content});if(o){const e=o({tool:r,args:i,loading:n});if(e)return{title:null===e.title?null:e.title??a,response:null===e.response?null:e.response??l,content:null===e.content?null:e.content??c,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=z(m),g="all"==i&&null!==l;return t(D,{children:[c&&e("div",{className:"mb-2",children:t(or,{className:"border rounded bg-white fs-7",$open:h,children:[t("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?e("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(U,{animation:"border",variant:"primary",size:"sm"}),u&&e("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&e("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const or=n.div`
|
|
704
708
|
width: ${e=>e.$open?"auto":"fit-content"};
|
|
705
709
|
max-width: 100%;
|
|
706
710
|
overflow: hidden;
|
|
707
|
-
`,
|
|
711
|
+
`,sr=n.div`
|
|
708
712
|
white-space: pre-wrap;
|
|
709
713
|
overflow-y: auto;
|
|
710
714
|
overflow-x: hidden;
|
|
711
715
|
max-height: 150px;
|
|
712
|
-
`;function
|
|
716
|
+
`;function ar({node:r}){const[n,i]=z(!1),{nodeIconResolver:o}=Re(),s=!("latency"in r),a=s?e(U,{animation:"border",variant:"primary",size:"sm"}):r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"shadow-sm rounded bg-white fs-7",children:[t(cr,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[e("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),e(dr,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:lr(r.latency)}),e("span",{children:a})]}),n&&t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输入"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输出"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const lr=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`,cr=n.div`
|
|
713
717
|
svg {
|
|
714
718
|
flex-shrink: 0;
|
|
715
719
|
}
|
|
716
|
-
`,
|
|
720
|
+
`,dr=n.span`
|
|
717
721
|
display: inline-block;
|
|
718
|
-
`;function
|
|
722
|
+
`;function ur({nodes:r,loading:n}){const[i,o]=z(!1),s=r.some(e=>"error"in e),a=n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"border rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(ar,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const mr=P(A(({chunks:r,loading:n,cite:i,isLast:o=!1,deleted:s=!1},a)=>{const{logLevel:l="none",showChunkOnCollapse:c,collapsible:d=!0}=Re(),u=I(()=>r.flatMap(e=>e.node?[e.node]:[]),[r]),{hiddenChunks:m,operationCount:h}=I(()=>{const e=new Set;let t=0;return n||r.forEach((r,n)=>{(c?c(r,n):0===(r.tools||[]).length)||(e.add(n),t+=(r.tools||[]).length)}),{hiddenChunks:e,operationCount:t}},[r,c,n]),p=d&&h>0,[g,f]=z(!1);return q(()=>{p&&f(!n)},[n,p]),t(hr,{ref:a,$deleted:s,children:[p&&!n&&e("div",{className:"mb-2",children:t(pr,{onClick:()=>f(!g),role:"button",className:"d-inline-flex align-items-center fs-7 gap-1",children:[t("span",{children:["完成了 ",h," 个操作"]}),e("i",g?{className:"bi bi-caret-down-fill"}:{className:"bi bi-caret-up-fill"})]})}),!g&&"all"===l&&u.length>0&&e(ur,{loading:n,nodes:u}),r.map((r,s)=>g&&m.has(s)?null:t(D,{children:[r.reasoning&&["stats","all"].includes(l)&&e(rr,{reasoning:r.reasoning,loading:n&&!r.content&&0===(r.tools||[]).length}),r.content&&e(qt,{value:{chunkIndex:s,chunk:r,isLastMessage:o},children:e(er,{cite:i,value:r.content})}),(r.tools||[]).map((t,i)=>e(qt,{value:{chunkIndex:s,chunk:r,toolIndex:i,tool:t,isLastMessage:o},children:e(ir,{tool:t,loading:n})},i)),r.error&&e(Nt,{content:`[${r.error}]`})]},s))]})})),hr=n.div`
|
|
719
723
|
${e=>e.$deleted&&o`
|
|
720
724
|
text-decoration-line: line-through;
|
|
721
725
|
color: var(--bs-secondary);
|
|
722
726
|
`}
|
|
723
|
-
`,
|
|
727
|
+
`,pr=n.div`
|
|
724
728
|
color: var(--bs-gray-500);
|
|
725
729
|
opacity: .75;
|
|
726
730
|
transition: opacity .15s ease;
|
|
@@ -734,7 +738,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
734
738
|
height: .75rem;
|
|
735
739
|
border-width: .1em;
|
|
736
740
|
}
|
|
737
|
-
`;class
|
|
741
|
+
`;class gr{#t;#o=[];#s=0;constructor(){this.#t=new X}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e,t=!1){this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const fr=new Map;class br{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new X}createLoader(e){const t=new Promise(async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}});return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(fr.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),fr.delete(this)}start(e,t=!1){fr.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=fr.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function vr({text:e,loading:t,loader:r}){const n=M(),[i,o]=z(!1),[s,a]=z(!1),l=M(t),c=async(i=!1)=>{n.current||(n.current=r?new br(r):new gr,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap(e=>e.textContent?[e.textContent]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return q(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),q(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function yr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=Re(),c=I(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:u,start:m,stop:h}=vr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=ce(e(xr,{children:e(U,{size:"sm",variant:"light"})}),a.current)),d&&(p=ce(e(xr,{children:e(wr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(St,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?e(wr,{className:"bi bi-volume-down-fill"}):u?e(U,{size:"sm",variant:"primary"}):e(wr,{className:"bi bi-volume-down"}),p]})}const xr=n.div`
|
|
738
742
|
position: absolute;
|
|
739
743
|
top: 0;
|
|
740
744
|
left: 0;
|
|
@@ -744,12 +748,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
744
748
|
align-items: center;
|
|
745
749
|
justify-content: center;
|
|
746
750
|
background-color: rgba(0, 0, 0, .3);
|
|
747
|
-
`,
|
|
751
|
+
`,wr=n.i`
|
|
748
752
|
|
|
749
753
|
&::before {
|
|
750
754
|
transform: scale(1.4)
|
|
751
755
|
}
|
|
752
|
-
`,
|
|
756
|
+
`,kr=P(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:u=[],chunks:m,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v,renderFileItem:y}=Re(),x=I(()=>m?m.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=bt(t);return r?e+r+"\n":e},""):bt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=bt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[m]),k=M(null),C=M(null),j=M(null),$=c||u.length>0;return t(r,{children:[$&&t(qr,{$reverse:!0,children:[g&&t(r,{children:[e(Sr,{children:e("img",{src:g.avatar})}),e(Mr,{})]}),t(Fr,{ref:k,children:[c&&e(Nt,{content:c}),d&&e(K,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:e(Er,{body:!0,children:d}),children:e(Cr,{children:e(Nr,{children:d})})}),u.length>0&&u.map(({name:t,size:r,path:n},i)=>{if(E(n))return e(At,{src:`/uploads/${n}`},i);const o={name:t,url:`/uploads/${n}`,size:r};return e(jr,{children:y?y({Component:ve,props:o}):e(ve,{...o})},i)})]})]}),m&&t(qr,{children:[f&&t(r,{children:[e(Sr,{ref:C,children:e("img",{src:f.avatar})}),e(Mr,{})]}),t(Fr,{children:[$&&!1!==i&&t($r,{children:[e(w,{placement:"top",content:x,as:St,tooltip:!0}),a&&e(yr,{loading:n.loading,avatarRef:C,contentRef:j,...a}),i?.({Component:St,message:n,content:x,setMessage:o,messages:v})]}),e(Rr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 ",N(n.stats.usage)," Credits"]})]})}),e(mr,{ref:j,chunks:m,loading:p,isLast:l,cite:s,deleted:!!h}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(Nt,{content:h.answer})]}),n.loading&&e(ft,{})]})]})]})}),Er=n(W)`
|
|
753
757
|
max-width: calc(100% - .875rem * 2);
|
|
754
758
|
width: calc(100% - .875rem * 2);
|
|
755
759
|
font-size: 1rem;
|
|
@@ -758,20 +762,20 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
758
762
|
.popover-body {
|
|
759
763
|
padding: .5rem .75rem;
|
|
760
764
|
}
|
|
761
|
-
`,
|
|
765
|
+
`,Nr=n.div`
|
|
762
766
|
overflow: hidden;
|
|
763
767
|
text-overflow: ellipsis;
|
|
764
768
|
word-break: break-all;
|
|
765
769
|
-webkit-line-clamp: 2;
|
|
766
770
|
-webkit-box-orient: vertical;
|
|
767
771
|
display: -webkit-box;
|
|
768
|
-
`,
|
|
772
|
+
`,Cr=n.div`
|
|
769
773
|
padding: .5rem .75rem;
|
|
770
774
|
color: var(--bs-secondary);
|
|
771
775
|
border-radius: var(--bs-border-radius-lg);
|
|
772
776
|
background: #FFFFFF;
|
|
773
777
|
cursor: pointer;
|
|
774
|
-
|
|
778
|
+
`,jr=n.div`
|
|
775
779
|
width: 100%;
|
|
776
780
|
margin-bottom: .5rem;
|
|
777
781
|
margin-top: .5rem;
|
|
@@ -783,7 +787,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
783
787
|
&:last-child {
|
|
784
788
|
margin-bottom: 0;
|
|
785
789
|
}
|
|
786
|
-
|
|
790
|
+
`,$r=n.div`
|
|
787
791
|
position: absolute;
|
|
788
792
|
top: -1.1rem;
|
|
789
793
|
right: 0;
|
|
@@ -791,7 +795,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
791
795
|
gap: .5rem;
|
|
792
796
|
opacity: 0;
|
|
793
797
|
z-index: 1;
|
|
794
|
-
`,
|
|
798
|
+
`,Rr=n.div`
|
|
795
799
|
position: absolute;
|
|
796
800
|
bottom: -1.4rem;
|
|
797
801
|
left: 0;
|
|
@@ -804,7 +808,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
804
808
|
display: flex;
|
|
805
809
|
opacity: 0;
|
|
806
810
|
z-index: 1;
|
|
807
|
-
`,
|
|
811
|
+
`,Sr=n.div`
|
|
808
812
|
width: 35px;
|
|
809
813
|
height: 35px;
|
|
810
814
|
border-radius: 50%;
|
|
@@ -815,14 +819,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
815
819
|
width: 100%;
|
|
816
820
|
height: 100%;
|
|
817
821
|
}
|
|
818
|
-
`,
|
|
822
|
+
`,Mr=n.div`
|
|
819
823
|
width: 0;
|
|
820
824
|
height: 0;
|
|
821
825
|
content: "";
|
|
822
826
|
border: 5px solid transparent;
|
|
823
827
|
border-right-color: #f3f3f3;
|
|
824
828
|
transform: translateY(10px);
|
|
825
|
-
`,
|
|
829
|
+
`,Fr=n.div`
|
|
826
830
|
padding: .875rem;
|
|
827
831
|
background-color: rgb(243, 243, 243);
|
|
828
832
|
border-radius: var(--bs-border-radius-lg);
|
|
@@ -830,32 +834,32 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
830
834
|
position: relative;
|
|
831
835
|
|
|
832
836
|
&:hover {
|
|
833
|
-
${
|
|
837
|
+
${Rr}, ${$r} {
|
|
834
838
|
opacity: 1;
|
|
835
839
|
}
|
|
836
840
|
}
|
|
837
|
-
`,
|
|
841
|
+
`,qr=n.div`
|
|
838
842
|
display: flex;
|
|
839
843
|
justify-content: flex-start;
|
|
840
844
|
padding: 1rem 0 1rem 0;
|
|
841
845
|
${e=>e.$reverse&&o`
|
|
842
846
|
flex-direction: row-reverse;
|
|
843
847
|
|
|
844
|
-
${
|
|
848
|
+
${Mr} {
|
|
845
849
|
border-left-color: rgba(var(--bs-primary-rgb), 0.1);
|
|
846
850
|
border-right-color: transparent;
|
|
847
851
|
}
|
|
848
852
|
|
|
849
|
-
${
|
|
853
|
+
${Fr} {
|
|
850
854
|
background: rgba(var(--bs-primary-rgb), 0.1);
|
|
851
855
|
}
|
|
852
856
|
`};
|
|
853
|
-
`;function
|
|
857
|
+
`;function zr(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:u,suggestions:m,conversationId:p}=Re(),g=M(r.loaded),f=M(!0),b=M(!1);q(()=>{const e=l.current;if(!e)return;const t=()=>{b.current=!0},r=()=>{if(!b.current)return;const t=e.scrollHeight-e.scrollTop-e.clientHeight<50;f.current=t,t&&(b.current=!1)};return e.addEventListener("wheel",t,{passive:!0}),e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("scroll",r,{passive:!0}),()=>{e.removeEventListener("wheel",t),e.removeEventListener("touchstart",t),e.removeEventListener("scroll",r)}},[l]);const v=h(()=>{if(!f.current)return;const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},200),y=M(null),{height:x}=de({ref:y});q(()=>{(u||!g.current)&&c.length>0&&(u&&(g.current=!0),v())},[x,u,g,c]),q(()=>{m.length>0&&v()},[m]),q(()=>{g.current=r.loaded},[p]),q(()=>{const e=y.current;if(e){const t=()=>{g.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[y]);const w=c.slice(-30);return t(Ar,{ref:y,children:[0===w.length&&n,w.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===w.length-1};return a?e(D,{children:a({Component:kr,props:n})},r):e(kr,{...n},r)}),m.length>0&&e(Ir,{children:m.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Ar=n.div`
|
|
854
858
|
display: flex;
|
|
855
859
|
flex-direction: column;
|
|
856
860
|
flex: 1;
|
|
857
861
|
margin-bottom: .5rem;
|
|
858
|
-
`,
|
|
862
|
+
`,Ir=n.div`
|
|
859
863
|
display: flex;
|
|
860
864
|
flex-direction: column;
|
|
861
865
|
align-items: flex-start;
|
|
@@ -872,7 +876,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
872
876
|
background: var(--bs-secondary-bg-subtle);
|
|
873
877
|
}
|
|
874
878
|
}
|
|
875
|
-
`,
|
|
879
|
+
`,Lr=P(A(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:u,conversation:m,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:b,renderReasoning:y,showChunkOnCollapse:w,collapsible:k=!0,messages:E,request:N,onReset:j,transformMessages:$=dt},R)=>{const S=F(e=>{const t=[];if(u&&!1!==u.enable){const e=ut(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat($(e.messages||[])):E?t.concat($(E)):t},[u]),[q,A]=z(m?.id),D=M(),[P,T]=v(()=>S(m)),O=I(()=>N?"string"==typeof N?C.create({baseURL:N}):N:C,[N]),[B,U]=z(!1),_=M(),[H,J]=z("0px"),[Q,K]=z([]),W=F(e=>{"suggestion"==e.type&&K(e.data),o?.onEvent?.(e)},[o?.onEvent]),X=F(e=>{A(e?.id),T(S(e)),K([]),U(!1),j?.(e)},[B,S,j]);return L(R,()=>({reset:X}),[X]),e(Me,{request:O,bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:q,setConversationId:A,inputRef:D,messages:P,setMessages:T,suggestions:Q,setSuggestions:K,loading:B,setLoading:U,renderFileItem:f,reset:X,readonly:!o,renderToolContent:b,renderReasoning:y,showChunkOnCollapse:w,collapsible:k,children:e(x,{children:e(Tr,{className:r,scrollableNodeProps:{ref:F(e=>{_.current=e;const t=e?.firstElementChild;t&&requestAnimationFrame(()=>{const e=window.getComputedStyle(t);J(e.paddingBottom)})},[])},children:t(Pr,{children:[e(zr,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:_}),o&&e(Dr,{$bottom:H,...o,onEvent:W,scrollRef:_})]})})})})}),Y),Dr=n(tt)`
|
|
876
880
|
position: sticky;
|
|
877
881
|
bottom: 0;
|
|
878
882
|
z-index: 1;
|
|
@@ -880,7 +884,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
880
884
|
padding-top: .5rem;
|
|
881
885
|
margin-bottom: -${e=>e.$bottom};
|
|
882
886
|
padding-bottom: calc(1rem + ${e=>e.$bottom});
|
|
883
|
-
`,
|
|
887
|
+
`,Pr=n.div`
|
|
884
888
|
display: flex;
|
|
885
889
|
flex-direction: column;
|
|
886
890
|
width: 100%;
|
|
@@ -889,10 +893,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
889
893
|
max-width: calc(810px + 2rem);
|
|
890
894
|
padding: 0 1rem;
|
|
891
895
|
flex: 1;
|
|
892
|
-
`,
|
|
896
|
+
`,Tr=n(j)`
|
|
893
897
|
.simplebar-content {
|
|
894
898
|
min-height: 100%;
|
|
895
899
|
display: flex;
|
|
896
900
|
flex-direction: column;
|
|
897
901
|
}
|
|
898
|
-
`,
|
|
902
|
+
`,Or=P(A(({className:t,request:r,disabled:n,supportStop:i,fileTypes:o,speech:s,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,autoFocus:m,renderEditableInput:h,placeholder:p,variables:g,onEvent:f,onNewConversation:b},v)=>{const[y,x]=z(!1),w=M(),k=I(()=>r?"string"==typeof r?C.create({baseURL:r}):r:C,[r]);return e(Se,{request:k,loading:y,setLoading:x,inputRef:w,children:e(tt,{ref:v,className:t,fileTypes:o,speech:s,variables:g,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,disabled:n,autoFocus:m,renderEditableInput:h,placeholder:p,supportStop:i,onEvent:f,onNewConversation:b})})}),Y);async function Br(e){const t=await ue().use(he).use(ne).use(ie).use(oe).use(pe).use(me).process(e);return String(t)}export{De as ActionButton,Or as ChatInput,mr as Chunks,Ze as EditableInput,fe as FileIcon,ve as FileItem,qe as InputButton,Nt as Markdown,Lr as MessageBox,Fe as VariableForm,ge as isToolMessage,Br as md2html,ut as pickQuestions,je as useChatContext,Re as useMessageContext,vr as useSynthesis};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.24",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prebuild": "rimraf es types",
|
|
6
6
|
"build": "rollup -c --environment NODE_ENV:production",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
},
|
|
72
72
|
"author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
|
|
73
73
|
"license": "MIT",
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "d7258615194b30be96cd958d6c7ebf86366205be"
|
|
75
75
|
}
|