@topthink/chat 1.3.29 → 1.3.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js CHANGED
@@ -704,27 +704,27 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
704
704
  button {
705
705
  padding: .25rem 1.5rem;
706
706
  }
707
- `;class Gt extends T{state={hasError:!1};hasReported=!1;static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.hasReported||(this.hasReported=!0,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,isLast:c}=function(){const e=S(Ft);if(!e)throw new Error("useContext must be used within a Provider");return e}(),d=a?.response||o.node?.output,u=r||!!o.error||!l||!c,m=F(e=>{u||"(Empty)"!==d||n.current?.resume({chunk:i,tool:s,payload:e})},[i,s,u,d]),h=F(()=>{m({error:"Failed to render the interactive component. The generated form parameters may be invalid. Please check the parameters and try regenerating."})},[m]),p=I(()=>{switch(t.type){case"select":return e(Ot,{...t.select});case"form":return e(Ht,{...t.form});case"confirm":return e(Wt,{...t.confirm})}},[t]);return e(Pt,{resume:m,disabled:u,response:"(Empty)"===d?void 0:d,children:e(Gt,{onRenderError:h,children:p})})}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,showIcon:m,defaultExpanded:h}=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,showIcon:e.showIcon??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,showIcon:!0,defaultExpanded:!1}},[r,o]),[p,g]=z(h),f="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:p,children:[t("div",{onClick:()=>g(f&&!p),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[m&&(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,f&&e("i",p?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),p&&l]})}),d]})}const or=n.div`
707
+ `;class Gt extends T{state={hasError:!1};hasReported=!1;static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.hasReported||(this.hasReported=!0,this.props.onRenderError(e))}render(){return this.state.hasError?null:this.props.children}}function Zt({suspend:t,renderSuspend:n,response:i,disabled:o,resume:s}){const a=n?.({suspend:t,response:i,disabled:o,resume:s});if(void 0!==a)return e(r,{children:a});switch(t.type){case"select":return e(Ot,{...t.select});case"form":return e(Ht,{...t.form});case"confirm":return e(Wt,{...t.confirm});default:return null}}function er({suspend:t}){const{readonly:r,inputRef:n,renderSuspend:i}=Re(),{chunkIndex:o,chunk:s,toolIndex:a,tool:l,isLastMessage:c,isLast:d}=function(){const e=S(Ft);if(!e)throw new Error("useContext must be used within a Provider");return e}(),u=l?.response||s.node?.output,m=r||!!s.error||!c||!d,h=F(e=>{m||"(Empty)"!==u||n.current?.resume({chunk:o,tool:a,payload:e})},[o,a,m,u]),p=F(()=>{h({error:"Failed to render the interactive component. The generated form parameters may be invalid. Please check the parameters and try regenerating."})},[h]);return e(Pt,{resume:h,disabled:m,response:"(Empty)"===u?void 0:u,children:e(Gt,{onRenderError:p,children:e(Zt,{suspend:t,renderSuspend:i,response:"(Empty)"===u?void 0:u,disabled:m,resume:h})})})}function tr({value:t,cite:n}){const i=t=>"string"==typeof t?e(Nt,{content:t,cite:n}):"image"===t.type?e(At,{src:t.image}):"suspend"===t.type?e(er,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(D,{children:i(t)},r))}):i(t)}const rr=({reasoning:r,loading:n})=>{const[i,o]=z(!1);return q(()=>{n||o(!1)},[n]),e(D,{children:e("div",{className:"mb-2",children:t("div",i?{className:"border rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:e("div",{className:"border rounded bg-light p-2",children:e(Nt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},nr=P(t=>{const{renderReasoning:r}=Re();return r?r({Component:rr,props:t}):e(rr,{...t})}),ir=e=>null==e?"None":"object"==typeof e?JSON.stringify(e,null,2):e;function or({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=Re(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:u,showIcon:m,defaultExpanded:h}=I(()=>{const i=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),a=e("span",{className:"text-truncate",children:r.title}),l=t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"参数"})}),e(ar,{className:"border-top p-2",children:r.arguments})]}),s&&t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"响应"})}),e(ar,{className:"border-top p-2",children:ir(r.response)})]})]}),c=r.content&&e(tr,{value:r.content});if(o){const e=o({tool:r,args:i,loading:n});if(e)return{title:null===e.title?null:e.title??a,response:null===e.response?null:e.response??l,content:null===e.content?null:e.content??c,showStatus:e.showStatus??!0,showIcon:e.showIcon??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:a,response:l,content:c,showStatus:!0,showIcon:!0,defaultExpanded:!1}},[r,o]),[p,g]=z(h),f="all"==i&&null!==l;return t(D,{children:[c&&e("div",{className:"mb-2",children:t(sr,{className:"border rounded bg-white fs-7",$open:p,children:[t("div",{onClick:()=>g(f&&!p),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[m&&(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,f&&e("i",p?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),p&&l]})}),d]})}const sr=n.div`
708
708
  width: ${e=>e.$open?"auto":"fit-content"};
709
709
  max-width: 100%;
710
710
  overflow: hidden;
711
- `,sr=n.div`
711
+ `,ar=n.div`
712
712
  white-space: pre-wrap;
713
713
  overflow-y: auto;
714
714
  overflow-x: hidden;
715
715
  max-height: 150px;
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`
716
+ `;function lr({node:r}){const[n,i]=z(!1),{nodeIconResolver:o}=Re(),s=!("latency"in r),a=s?e(U,{animation:"border",variant:"primary",size:"sm"}):r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"shadow-sm rounded bg-white fs-7",children:[t(dr,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[e("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),e(ur,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:cr(r.latency)}),e("span",{children:a})]}),n&&t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输入"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输出"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const cr=e=>e<1?`${(1e3*e).toFixed(3)} ms`:e>60?`${parseInt(Math.round(e/60).toString())} m ${(e%60).toFixed(3)} s`:`${e.toFixed(3)} s`,dr=n.div`
717
717
  svg {
718
718
  flex-shrink: 0;
719
719
  }
720
- `,dr=n.span`
720
+ `,ur=n.span`
721
721
  display: inline-block;
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((s,a)=>{if(g&&m.has(a))return null;const c=a===r.length-1;return t(D,{children:[s.reasoning&&["stats","all"].includes(l)&&e(rr,{reasoning:s.reasoning,loading:n&&!s.content&&0===(s.tools||[]).length}),s.content&&e(qt,{value:{chunkIndex:a,chunk:s,isLastMessage:o,isLast:c},children:e(er,{cite:i,value:s.content})}),(s.tools||[]).map((t,r)=>e(qt,{value:{chunkIndex:a,chunk:s,toolIndex:r,tool:t,isLastMessage:o,isLast:c},children:e(ir,{tool:t,loading:n})},r)),s.error&&e(Nt,{content:`[${s.error}]`})]},a)})]})})),hr=n.div`
722
+ `;function mr({nodes:r,loading:n}){const[i,o]=z(!1),s=r.some(e=>"error"in e),a=n?e(U,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"border rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(lr,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center border rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const hr=P(A(({chunks:r,loading:n,cite:i,isLast:o=!1,deleted:s=!1},a)=>{const{logLevel:l="none",showChunkOnCollapse:c,collapsible:d=!0}=Re(),u=I(()=>r.flatMap(e=>e.node?[e.node]:[]),[r]),{hiddenChunks:m,operationCount:h}=I(()=>{const e=new Set;let t=0;return 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(pr,{ref:a,$deleted:s,children:[p&&!n&&e("div",{className:"mb-2",children:t(gr,{onClick:()=>f(!g),role:"button",className:"d-inline-flex align-items-center fs-7 gap-1",children:[t("span",{children:["完成了 ",h," 个操作"]}),e("i",g?{className:"bi bi-caret-down-fill"}:{className:"bi bi-caret-up-fill"})]})}),!g&&"all"===l&&u.length>0&&e(mr,{loading:n,nodes:u}),r.map((s,a)=>{if(g&&m.has(a))return null;const c=a===r.length-1;return t(D,{children:[s.reasoning&&["stats","all"].includes(l)&&e(nr,{reasoning:s.reasoning,loading:n&&!s.content&&0===(s.tools||[]).length}),s.content&&e(qt,{value:{chunkIndex:a,chunk:s,isLastMessage:o,isLast:c},children:e(tr,{cite:i,value:s.content})}),(s.tools||[]).map((t,r)=>e(qt,{value:{chunkIndex:a,chunk:s,toolIndex:r,tool:t,isLastMessage:o,isLast:c},children:e(or,{tool:t,loading:n})},r)),s.error&&e(Nt,{content:`[${s.error}]`})]},a)})]})})),pr=n.div`
723
723
  ${e=>e.$deleted&&o`
724
724
  text-decoration-line: line-through;
725
725
  color: var(--bs-secondary);
726
726
  `}
727
- `,pr=n.div`
727
+ `,gr=n.div`
728
728
  color: var(--bs-gray-500);
729
729
  opacity: .75;
730
730
  transition: opacity .15s ease;
@@ -738,7 +738,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
738
738
  height: .75rem;
739
739
  border-width: .1em;
740
740
  }
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`
741
+ `;class fr{#t;#o=[];#s=0;constructor(){this.#t=new X}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e,t=!1){this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const br=new Map;class vr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new X}createLoader(e){const t=new Promise(async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}});return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(br.set(this,t),t.onpause=async()=>{t.ended?(this.#s++,this.#s<this.#o.length?await this.playAudio(this.#s):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#t.emit("playing",!1),this.#t.emit("speaking",!1),br.delete(this)}start(e,t=!1){br.forEach((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)}),this.#o=Array.isArray(e)?e:[e],t||(this.#s=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=br.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function yr({text:e,loading:t,loader:r}){const n=M(),[i,o]=z(!1),[s,a]=z(!1),l=M(t),c=async(i=!1)=>{n.current||(n.current=r?new vr(r):new fr,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap(e=>e.textContent?[e.textContent]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return q(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),q(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function xr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=Re(),c=I(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:u,start:m,stop:h}=yr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(u&&(p=ce(e(wr,{children:e(U,{size:"sm",variant:"light"})}),a.current)),d&&(p=ce(e(wr,{children:e(kr,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(St,{disabled:i&&!d,onClick:()=>{d?h():m()},children:[d?e(kr,{className:"bi bi-volume-down-fill"}):u?e(U,{size:"sm",variant:"primary"}):e(kr,{className:"bi bi-volume-down"}),p]})}const wr=n.div`
742
742
  position: absolute;
743
743
  top: 0;
744
744
  left: 0;
@@ -748,12 +748,12 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
748
748
  align-items: center;
749
749
  justify-content: center;
750
750
  background-color: rgba(0, 0, 0, .3);
751
- `,wr=n.i`
751
+ `,kr=n.i`
752
752
 
753
753
  &::before {
754
754
  transform: scale(1.4)
755
755
  }
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)`
756
+ `,Er=P(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:u=[],chunks:m,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v,renderFileItem:y}=Re(),x=I(()=>m?m.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=bt(t);return r?e+r+"\n":e},""):bt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=bt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[m]),k=M(null),C=M(null),j=M(null),$=c||u.length>0;return t(r,{children:[$&&t(zr,{$reverse:!0,children:[g&&t(r,{children:[e(Mr,{children:e("img",{src:g.avatar})}),e(Fr,{})]}),t(qr,{ref:k,children:[c&&e(Nt,{content:c}),d&&e(K,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:e(Nr,{body:!0,children:d}),children:e(jr,{children:e(Cr,{children:d})})}),u.length>0&&u.map(({name:t,size:r,path:n},i)=>{if(E(n))return e(At,{src:`/uploads/${n}`},i);const o={name:t,url:`/uploads/${n}`,size:r};return e($r,{children:y?y({Component:ve,props:o}):e(ve,{...o})},i)})]})]}),m&&t(zr,{children:[f&&t(r,{children:[e(Mr,{ref:C,children:e("img",{src:f.avatar})}),e(Fr,{})]}),t(qr,{children:[$&&!1!==i&&t(Rr,{children:[e(w,{placement:"top",content:x,as:St,tooltip:!0}),a&&e(xr,{loading:n.loading,avatarRef:C,contentRef:j,...a}),i?.({Component:St,message:n,content:x,setMessage:o,messages:v})]}),e(Sr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 ",N(n.stats.usage)," Credits"]})]})}),e(hr,{ref:j,chunks:m,loading:p,isLast:l,cite:s,deleted:!!h}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(Nt,{content:h.answer})]}),n.loading&&e(ft,{})]})]})]})}),Nr=n(W)`
757
757
  max-width: calc(100% - .875rem * 2);
758
758
  width: calc(100% - .875rem * 2);
759
759
  font-size: 1rem;
@@ -762,20 +762,20 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
762
762
  .popover-body {
763
763
  padding: .5rem .75rem;
764
764
  }
765
- `,Nr=n.div`
765
+ `,Cr=n.div`
766
766
  overflow: hidden;
767
767
  text-overflow: ellipsis;
768
768
  word-break: break-all;
769
769
  -webkit-line-clamp: 2;
770
770
  -webkit-box-orient: vertical;
771
771
  display: -webkit-box;
772
- `,Cr=n.div`
772
+ `,jr=n.div`
773
773
  padding: .5rem .75rem;
774
774
  color: var(--bs-secondary);
775
775
  border-radius: var(--bs-border-radius-lg);
776
776
  background: #FFFFFF;
777
777
  cursor: pointer;
778
- `,jr=n.div`
778
+ `,$r=n.div`
779
779
  width: 100%;
780
780
  margin-bottom: .5rem;
781
781
  margin-top: .5rem;
@@ -787,7 +787,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
787
787
  &:last-child {
788
788
  margin-bottom: 0;
789
789
  }
790
- `,$r=n.div`
790
+ `,Rr=n.div`
791
791
  position: absolute;
792
792
  top: -1.1rem;
793
793
  right: 0;
@@ -795,7 +795,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
795
795
  gap: .5rem;
796
796
  opacity: 0;
797
797
  z-index: 1;
798
- `,Rr=n.div`
798
+ `,Sr=n.div`
799
799
  position: absolute;
800
800
  bottom: -1.4rem;
801
801
  left: 0;
@@ -808,7 +808,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
808
808
  display: flex;
809
809
  opacity: 0;
810
810
  z-index: 1;
811
- `,Sr=n.div`
811
+ `,Mr=n.div`
812
812
  width: 35px;
813
813
  height: 35px;
814
814
  border-radius: 50%;
@@ -819,14 +819,14 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
819
819
  width: 100%;
820
820
  height: 100%;
821
821
  }
822
- `,Mr=n.div`
822
+ `,Fr=n.div`
823
823
  width: 0;
824
824
  height: 0;
825
825
  content: "";
826
826
  border: 5px solid transparent;
827
827
  border-right-color: #f3f3f3;
828
828
  transform: translateY(10px);
829
- `,Fr=n.div`
829
+ `,qr=n.div`
830
830
  padding: .875rem;
831
831
  background-color: rgb(243, 243, 243);
832
832
  border-radius: var(--bs-border-radius-lg);
@@ -834,32 +834,32 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
834
834
  position: relative;
835
835
 
836
836
  &:hover {
837
- ${Rr}, ${$r} {
837
+ ${Sr}, ${Rr} {
838
838
  opacity: 1;
839
839
  }
840
840
  }
841
- `,qr=n.div`
841
+ `,zr=n.div`
842
842
  display: flex;
843
843
  justify-content: flex-start;
844
844
  padding: 1rem 0 1rem 0;
845
845
  ${e=>e.$reverse&&o`
846
846
  flex-direction: row-reverse;
847
847
 
848
- ${Mr} {
848
+ ${Fr} {
849
849
  border-left-color: rgba(var(--bs-primary-rgb), 0.1);
850
850
  border-right-color: transparent;
851
851
  }
852
852
 
853
- ${Fr} {
853
+ ${qr} {
854
854
  background: rgba(var(--bs-primary-rgb), 0.1);
855
855
  }
856
856
  `};
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`
857
+ `;function Ar(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:u,suggestions:m,conversationId:p}=Re(),g=M(r.loaded),f=M(!0),b=M(!1);q(()=>{const e=l.current;if(!e)return;const t=()=>{b.current=!0},r=()=>{if(!b.current)return;const t=e.scrollHeight-e.scrollTop-e.clientHeight<50;f.current=t,t&&(b.current=!1)};return e.addEventListener("wheel",t,{passive:!0}),e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("scroll",r,{passive:!0}),()=>{e.removeEventListener("wheel",t),e.removeEventListener("touchstart",t),e.removeEventListener("scroll",r)}},[l]);const v=h(()=>{if(!f.current)return;const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},200),y=M(null),{height:x}=de({ref:y});q(()=>{(u||!g.current)&&c.length>0&&(u&&(g.current=!0),v())},[x,u,g,c]),q(()=>{m.length>0&&v()},[m]),q(()=>{g.current=r.loaded},[p]),q(()=>{const e=y.current;if(e){const t=()=>{g.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[y]);const w=c.slice(-30);return t(Ir,{ref:y,children:[0===w.length&&n,w.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===w.length-1};return a?e(D,{children:a({Component:Er,props:n})},r):e(Er,{...n},r)}),m.length>0&&e(Lr,{children:m.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Ir=n.div`
858
858
  display: flex;
859
859
  flex-direction: column;
860
860
  flex: 1;
861
861
  margin-bottom: .5rem;
862
- `,Ir=n.div`
862
+ `,Lr=n.div`
863
863
  display: flex;
864
864
  flex-direction: column;
865
865
  align-items: flex-start;
@@ -876,7 +876,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
876
876
  background: var(--bs-secondary-bg-subtle);
877
877
  }
878
878
  }
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)`
879
+ `,Dr=P(A(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:u,conversation:m,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:b,renderSuspend:y,renderReasoning:w,showChunkOnCollapse:k,collapsible:E=!0,messages:N,request:j,onReset:$,transformMessages:R=dt},S)=>{const q=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(R(e.messages||[])):N?t.concat(R(N)):t},[u]),[A,D]=z(m?.id),P=M(),[T,O]=v(()=>q(m)),B=I(()=>j?"string"==typeof j?C.create({baseURL:j}):j:C,[j]),[U,_]=z(!1),H=M(),[J,Q]=z("0px"),[K,W]=z([]),X=F(e=>{"suggestion"==e.type&&W(e.data),o?.onEvent?.(e)},[o?.onEvent]),V=F(e=>{D(e?.id),O(q(e)),W([]),_(!1),$?.(e)},[U,q,$]);return L(S,()=>({reset:V}),[V]),e(Me,{request:B,bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:A,setConversationId:D,inputRef:P,messages:T,setMessages:O,suggestions:K,setSuggestions:W,loading:U,setLoading:_,renderFileItem:f,reset:V,readonly:!o,renderToolContent:b,renderSuspend:y,renderReasoning:w,showChunkOnCollapse:k,collapsible:E,children:e(x,{children:e(Or,{className:r,scrollableNodeProps:{ref:F(e=>{H.current=e;const t=e?.firstElementChild;t&&requestAnimationFrame(()=>{const e=window.getComputedStyle(t);Q(e.paddingBottom)})},[])},children:t(Tr,{children:[e(Ar,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:H}),o&&e(Pr,{$bottom:J,...o,onEvent:X,scrollRef:H})]})})})})}),Y),Pr=n(tt)`
880
880
  position: sticky;
881
881
  bottom: 0;
882
882
  z-index: 1;
@@ -884,7 +884,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
884
884
  padding-top: .5rem;
885
885
  margin-bottom: -${e=>e.$bottom};
886
886
  padding-bottom: calc(1rem + ${e=>e.$bottom});
887
- `,Pr=n.div`
887
+ `,Tr=n.div`
888
888
  display: flex;
889
889
  flex-direction: column;
890
890
  width: 100%;
@@ -893,10 +893,10 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
893
893
  max-width: calc(810px + 2rem);
894
894
  padding: 0 1rem;
895
895
  flex: 1;
896
- `,Tr=n(j)`
896
+ `,Or=n(j)`
897
897
  .simplebar-content {
898
898
  min-height: 100%;
899
899
  display: flex;
900
900
  flex-direction: column;
901
901
  }
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};
902
+ `,Br=P(A(({className:t,request:r,disabled:n,supportStop:i,fileTypes:o,speech:s,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,autoFocus:m,renderEditableInput:h,placeholder:p,variables:g,onEvent:f,onNewConversation:b},v)=>{const[y,x]=z(!1),w=M(),k=I(()=>r?"string"==typeof r?C.create({baseURL:r}):r:C,[r]);return e(Se,{request:k,loading:y,setLoading:x,inputRef:w,children:e(tt,{ref:v,className:t,fileTypes:o,speech:s,variables:g,minRows:a,maxRows:l,toolbar:c,toolbarActions:d,tools:u,disabled:n,autoFocus:m,renderEditableInput:h,placeholder:p,supportStop:i,onEvent:f,onNewConversation:b})})}),Y);async function Ur(e){const t=await ue().use(he).use(ne).use(ie).use(oe).use(pe).use(me).process(e);return String(t)}export{De as ActionButton,Br as ChatInput,hr as Chunks,Ze as EditableInput,fe as FileIcon,ve as FileItem,qe as InputButton,Nt as Markdown,Dr as MessageBox,Fe as VariableForm,ge as isToolMessage,Ur as md2html,ut as pickQuestions,je as useChatContext,Re as useMessageContext,yr as useSynthesis};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.3.29",
3
+ "version": "1.3.30",
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": "4a92d71c029c4360c7fc7a0b63c114d2ad2be71e"
74
+ "gitHead": "99a94f8e26740a744333dfb53e0b9b201b2a3225"
75
75
  }
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, FC, MutableRefObject, PropsWithChildren, ReactElement, ReactNode, SetStateAction } from 'react';
2
- import { Chunk, Conversation, Input, LogLevel, Message, ToolMessage } from '../../types';
2
+ import { Chunk, Conversation, Input, LogLevel, Message, SuspendType, ToolMessage } from '../../types';
3
3
  import { Updater } from '@topthink/components/types/hooks/use-immer';
4
4
  import { RequestInstance } from '@topthink/components';
5
5
  import { FileItemProps } from './file-item';
@@ -23,6 +23,17 @@ export interface ToolRenderResult {
23
23
  /** 是否默认展开详情 */
24
24
  defaultExpanded?: boolean;
25
25
  }
26
+ export interface SuspendRenderOptions {
27
+ /** 挂起项原始数据 */
28
+ suspend: SuspendType;
29
+ /** 已提交的响应数据 */
30
+ response?: any;
31
+ /** 当前挂起项是否禁止交互 */
32
+ disabled: boolean;
33
+ /** 提交响应并恢复对话 */
34
+ resume: (payload: any) => void;
35
+ }
36
+ export type SuspendRender = (options: SuspendRenderOptions) => ReactNode | undefined;
26
37
  interface ChatContextType {
27
38
  request: RequestInstance;
28
39
  loading: boolean;
@@ -59,6 +70,8 @@ interface DisplayContextType {
59
70
  }) => ReactElement;
60
71
  /** 自定义工具渲染函数 */
61
72
  renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
73
+ /** 自定义挂起项渲染函数,返回 undefined 时使用内置渲染 */
74
+ renderSuspend?: SuspendRender;
62
75
  /** 判断某个 chunk 是否在折叠时显示,默认无工具调用(tools)时显示 */
63
76
  showChunkOnCollapse?: (chunk: Chunk, index: number) => boolean;
64
77
  /** 是否启用整体折叠功能,默认开启 */
@@ -4,7 +4,7 @@ import { Conversation, ConversationMessage, Chunk, Input, LogLevel, Message, Mes
4
4
  import { MessageActions, MessageItemProps } from './message-item';
5
5
  import type { RenderEditableInput } from './input-box';
6
6
  import type { ToolbarActions } from './input-box/toolbar';
7
- import { ToolRenderOptions, ToolRenderResult } from './context';
7
+ import { SuspendRender, ToolRenderOptions, ToolRenderResult } from './context';
8
8
  import { Components } from 'react-markdown';
9
9
  import { FileItemProps } from './file-item';
10
10
  import { ReasoningProps } from './reasoning';
@@ -77,6 +77,8 @@ export interface MessageBoxProps {
77
77
  }) => ReactElement;
78
78
  /** 自定义工具渲染函数,用于定制工具调用的显示样式 */
79
79
  renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
80
+ /** 自定义挂起项渲染函数,返回 undefined 时使用内置渲染 */
81
+ renderSuspend?: SuspendRender;
80
82
  /** 判断某个 chunk 是否在折叠时显示,默认无工具调用(tools)时显示 */
81
83
  showChunkOnCollapse?: (chunk: Chunk, index: number) => boolean;
82
84
  /** 是否启用整体折叠功能,默认开启 */
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './types';
2
2
  export { default as MessageBox, MessageBoxProps } from './components/message-box';
3
3
  export { default as ChatInput, ChatInputProps } from './components/chat-input';
4
4
  export { default as Chunks, ChunksProps } from './components/message-box/chunks';
5
- export { useContext as useMessageContext, useChatContext, ToolRenderOptions, ToolRenderResult, } from './components/message-box/context';
5
+ export { useContext as useMessageContext, useChatContext, ToolRenderOptions, ToolRenderResult, SuspendRenderOptions, SuspendRender, } from './components/message-box/context';
6
6
  export { default as EditableInput } from './components/message-box/input-box/editable-input';
7
7
  export type { EditableInputProps, EditableInputRef } from './components/message-box/input-box/editable-input';
8
8
  export type { EditableInputComponent, RenderEditableInput } from './components/message-box/input-box';
package/types/types.d.ts CHANGED
@@ -8,7 +8,18 @@ export interface FormField {
8
8
  options?: string[];
9
9
  default?: string;
10
10
  }
11
- export type SuspendType = {
11
+ /**
12
+ * 自定义 suspend 类型配置。
13
+ * 默认为空,可通过 declare module '@topthink/chat' 扩展。
14
+ *
15
+ * 示例:
16
+ * interface SuspendTypeConfig {
17
+ * rating: { description: string; max: number };
18
+ * }
19
+ */
20
+ export interface SuspendTypeConfig {
21
+ }
22
+ type BuiltinSuspendType = {
12
23
  type: 'select';
13
24
  select: {
14
25
  description: string;
@@ -26,6 +37,14 @@ export type SuspendType = {
26
37
  content: string;
27
38
  };
28
39
  };
40
+ type ConfiguredSuspendType = {
41
+ [K in keyof SuspendTypeConfig]: {
42
+ type: K & string;
43
+ } & {
44
+ [P in K]: SuspendTypeConfig[P];
45
+ };
46
+ }[keyof SuspendTypeConfig];
47
+ export type SuspendType = BuiltinSuspendType | ConfiguredSuspendType;
29
48
  export type ContentType = string | {
30
49
  type: 'image';
31
50
  image: string;