@topthink/chat 1.1.31 → 1.1.33

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
@@ -621,7 +621,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
621
621
  }
622
622
  `,jt=n.span`
623
623
  display: inline-block;
624
- `;function Ct(r){let{nodes:n,loading:i}=r;const[o,s]=M(!1),a=n.some((e=>"error"in e)),l=i?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",a?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,r)=>t(wt,{node:e},r)))})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Mt=R((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l}=n;const{query:c,quote:d,files:h=[],chunks:m,annotation:u,loading:p}=i,{user:g,bot:f,logLevel:y="none",messages:k}=ce(),w=q((()=>m?m.reduce((function(e,t){return e+t.content+"\n"+t.tools.reduce(((e,t)=>{if(t.content){if("string"==typeof t.content)return e+t.content+"\n";if("image"===t.content.type){return e+`![](${v(t.content.image)})\n`}}return e}),"")}),""):""),[m]),N=E(null),j=E(null),C=E(null),M=q((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]);return e(r,{children:[(c||h.length>0)&&e(Ot,{$reverse:!0,children:[g&&t(It,{children:t("img",{src:g.avatar})}),t(Dt,{}),e(Lt,{ref:N,children:[c&&t(tt,{content:c}),d&&t(T,{trigger:"click",container:N,rootClose:!0,placement:"bottom",overlay:t($t,{body:!0,children:d}),children:t(zt,{children:t(qt,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return x(o)?t(ct,{src:`/uploads/${o}`},r):t(Rt,{children:t(re,{name:n,size:i})},r)}))]})]}),m&&e(Ot,{children:[f&&t(It,{ref:j,children:t("img",{src:f.avatar})}),t(Dt,{}),e(Lt,{children:[(c||h.length>0)&&!1!==o&&e(At,{children:[t(b,{placement:"top",content:w,as:st,tooltip:!0}),l&&t(bt,{loading:i.loading,avatarRef:j,contentRef:C,...l}),o?.({Component:st,message:i,content:w,setMessage:s,messages:k})]}),t(Ft,{children:["stats","all"].includes(y)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(St,{ref:C,$deleted:!!u,children:["all"===y&&M.length>0&&t(Ct,{loading:p,nodes:M}),m.length>0&&m.map(((r,n)=>e(S,{children:[r.reasoning&&["stats","all"].includes(y)&&t(mt,{reasoning:r.reasoning,loading:!r.content&&0===r.tools.length}),r.content&&t(ht,{cite:a,value:r.content}),r.tools.map(((e,r)=>t(yt,{tool:e,loading:p},r))),r.error&&t(tt,{content:`[${r.error}]`})]},n)))]}),u&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(tt,{content:u.answer})]}),i.loading&&t(We,{})]})]})]})})),$t=n(P)`
624
+ `;function Ct(r){let{nodes:n,loading:i}=r;const[o,s]=M(!1),a=n.some((e=>"error"in e)),l=i?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",a?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",o?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>s(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:n.map(((e,r)=>t(wt,{node:e},r)))})]}:{onClick:()=>s(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const Mt=R((n=>{let{message:i,actions:o,setMessage:s,cite:a,speech:l}=n;const{query:c,quote:d,files:h=[],chunks:m,annotation:u,loading:p}=i,{user:g,bot:f,logLevel:y="none",messages:k}=ce(),w=q((()=>m?m.reduce((function(e,t){return e+t.content+"\n"+(t.tools||[]).reduce(((e,t)=>{if(t.content){if("string"==typeof t.content)return e+t.content+"\n";if("image"===t.content.type){return e+`![](${v(t.content.image)})\n`}}return e}),"")}),""):""),[m]),N=E(null),j=E(null),C=E(null),M=q((()=>m?.flatMap((e=>e.node?[e.node]:[]))||[]),[m]);return e(r,{children:[(c||h.length>0)&&e(Ot,{$reverse:!0,children:[g&&t(It,{children:t("img",{src:g.avatar})}),t(Dt,{}),e(Lt,{ref:N,children:[c&&t(tt,{content:c}),d&&t(T,{trigger:"click",container:N,rootClose:!0,placement:"bottom",overlay:t($t,{body:!0,children:d}),children:t(zt,{children:t(qt,{children:d})})}),h.length>0&&h.map(((e,r)=>{let{name:n,size:i,path:o}=e;return x(o)?t(ct,{src:`/uploads/${o}`},r):t(Rt,{children:t(re,{name:n,size:i})},r)}))]})]}),m&&e(Ot,{children:[f&&t(It,{ref:j,children:t("img",{src:f.avatar})}),t(Dt,{}),e(Lt,{children:[(c||h.length>0)&&!1!==o&&e(At,{children:[t(b,{placement:"top",content:w,as:st,tooltip:!0}),l&&t(bt,{loading:i.loading,avatarRef:j,contentRef:C,...l}),o?.({Component:st,message:i,content:w,setMessage:s,messages:k})]}),t(Ft,{children:["stats","all"].includes(y)&&i.stats&&e(r,{children:[e("span",{children:["耗时 ",i.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",i.stats.usage]})]})}),e(St,{ref:C,$deleted:!!u,children:["all"===y&&M.length>0&&t(Ct,{loading:p,nodes:M}),m.length>0&&m.map(((r,n)=>e(S,{children:[r.reasoning&&["stats","all"].includes(y)&&t(mt,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&t(ht,{cite:a,value:r.content}),(r.tools||[]).map(((e,r)=>t(yt,{tool:e,loading:p},r))),r.error&&t(tt,{content:`[${r.error}]`})]},n)))]}),u&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(tt,{content:u.answer})]}),i.loading&&t(We,{})]})]})]})})),$t=n(P)`
625
625
  max-width: calc(100% - .875rem * 2);
626
626
  width: calc(100% - .875rem * 2);
627
627
  font-size: 1rem;
@@ -748,7 +748,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
748
748
  background: var(--bs-secondary-bg-subtle);
749
749
  }
750
750
  }
751
- `,_t=R($(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:m,onboarding:u,conversation:p,cite:b,speech:v,renderItem:x,messages:k,request:w}=r;const N=C((e=>{const t=[];if(u&&!1!==u.enable){const e=Ue(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(_e(e.messages||[])):k?t.concat(_e(k)):t}),[u]),[$,S]=M(p?.id),[R,A]=g([]);j((()=>{A(N(p))}),[u]);const[F,I]=M(!1),D=E(null),[L,O]=M([]),T=C((e=>{F||(S(e?.id),A(N(e)),O([]))}),[F,N]);return z(n,(()=>({reset:T})),[T]),t(de,{request:q((()=>w?"string"==typeof w?y.create({baseURL:w}):w:y),[w]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:$,setConversationId:S,messages:R,setMessages:A,suggestions:L,setSuggestions:O,loading:F,setLoading:I,reset:T,children:t(Ht,{className:i,children:e(f,{children:[t(Ut,{ref:D,children:t(Tt,{placeholder:h,cite:b,actions:m,loaded:!a,speech:v,renderItem:x,scrollRef:D})}),a&&t(Ae,{...a,scrollRef:D})]})})})})),_),Ut=n.div`
751
+ `,_t=R($(((r,n)=>{let{className:i,bot:o,user:s,input:a,logLevel:l,imageResolver:c,nodeIconResolver:d,placeholder:h,actions:m,onboarding:u,conversation:p,cite:b,speech:v,renderItem:x,messages:k,request:w,transformMessages:N=_e}=r;const $=C((e=>{const t=[];if(u&&!1!==u.enable){const e=Ue(u.questions||[]);t.push({chunks:[{content:[u.prologue,...e.map((e=>`[${e}](#!question)`))].join("\n"),tools:[]}],loading:u.loading})}return e?t.concat(N(e.messages||[])):k?t.concat(N(k)):t}),[u]),[S,R]=M(p?.id),[A,F]=g([]);j((()=>{F($(p))}),[u]);const[I,D]=M(!1),L=E(null),[O,T]=M([]),P=C((e=>{I||(R(e?.id),F($(e)),T([]))}),[I,$]);return z(n,(()=>({reset:P})),[P]),t(de,{request:q((()=>w?"string"==typeof w?y.create({baseURL:w}):w:y),[w]),bot:o,user:s,logLevel:l,imageResolver:c,nodeIconResolver:d,conversationId:S,setConversationId:R,messages:A,setMessages:F,suggestions:O,setSuggestions:T,loading:I,setLoading:D,reset:P,children:t(Ht,{className:i,children:e(f,{children:[t(Ut,{ref:L,children:t(Tt,{placeholder:h,cite:b,actions:m,loaded:!a,speech:v,renderItem:x,scrollRef:L})}),a&&t(Ae,{...a,scrollRef:L})]})})})})),_),Ut=n.div`
752
752
  display: flex;
753
753
  flex-direction: column;
754
754
  flex: 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
4
4
  "scripts": {
5
5
  "prebuild": "rimraf es types",
6
6
  "build": "rollup -c --environment NODE_ENV:production",
@@ -67,5 +67,5 @@
67
67
  },
68
68
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
69
69
  "license": "MIT",
70
- "gitHead": "b77f45210035b69ad360f769ab5a00abf431137a"
70
+ "gitHead": "07be160c68a62ce444c41ce638500a5b8619713a"
71
71
  }
@@ -54,6 +54,7 @@ export interface MessageBoxProps {
54
54
  Component: typeof MessageItem;
55
55
  props: MessageItemProps;
56
56
  }, index: number) => ReactNode;
57
+ transformMessages?: (messages: any[]) => Message[];
57
58
  }
58
59
  declare const MessageBox: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<MessageBoxProps & import("react").RefAttributes<MessageBoxType>>>;
59
60
  export default MessageBox;
package/types/types.d.ts CHANGED
@@ -35,7 +35,7 @@ export interface Message {
35
35
  chunks?: {
36
36
  content: string | ContentType[];
37
37
  reasoning?: string;
38
- tools: ToolMessage[];
38
+ tools?: ToolMessage[];
39
39
  error?: string;
40
40
  node?: Node;
41
41
  }[];