@topthink/chat 1.1.30 → 1.1.32

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
@@ -613,7 +613,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
613
613
  &::before {
614
614
  transform: scale(1.4)
615
615
  }
616
- `;function yt(r){let{tool:n}=r;const[i,o]=M(!1),{logLevel:s="none"}=ce(),a="response"in n;return e(S,{children:["stats"==s&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:a?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&a?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:n.title}),t("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",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(kt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>o(a),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:a?"已使用":"正在使用"}),t("span",{children:n.title}),a&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),n.content&&t(ht,{value:n.content})]})}const kt=n.div`
616
+ `;function yt(r){let{tool:n,loading:i}=r;const[o,s]=M(!1),{logLevel:a="none"}=ce(),l="response"in n,c=!l&&!i;return e(S,{children:["stats"==a&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[c?t("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),t("span",{children:n.title})]})}),"all"==a&&t("div",{className:"mb-2",children:e("div",o&&l?{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:[n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:n.title}),t("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",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:n.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(kt,{className:"border-top p-2 overflow-hidden",children:n.response||"None"})]})]})]}:{onClick:()=>s(l),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[c?t("i",{className:"bi bi-dash-circle-fill text-muted"}):l?n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:c?"已取消":l?"已使用":"正在使用"}),t("span",{children:n.title}),l&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),n.content&&t(ht,{value:n.content})]})}const kt=n.div`
617
617
  white-space: pre-wrap;
618
618
  `;function wt(r){let{node:n}=r;const[i,o]=M(!1),{nodeIconResolver:s}=ce(),a=!("latency"in n),l=a?t(D,{animation:"border",variant:"primary",size:"sm"}):n.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"shadow-sm rounded bg-white fs-7",children:[e(Et,{onClick:()=>o((e=>!e)),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[t("i",{className:"bi bi-chevron-down text-muted"}),s?.(n.type),t(jt,{className:"me-2 text-truncate",children:n.title}),t("span",{className:"me-auto"}),!a&&t("span",{className:"text-nowrap text-muted",children:Nt(n.latency)}),t("span",{children:l})]}),i&&e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输入"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.input?JSON.stringify(n.input,null,4):"None"})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输出"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:n.output?JSON.stringify(n.output,null,4):"None"})]})]})]})}const Nt=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`,Et=n.div`
619
619
  svg {
@@ -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:[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},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.30",
3
+ "version": "1.1.32",
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": "bf6f04e2890d5d1759eacf2ac6629a160b1b8f5c"
70
+ "gitHead": "a36b175671225f66b1f237b5ddc36ef8285e8eb6"
71
71
  }
@@ -3,7 +3,7 @@ import { Conversation, LogLevel, Message } from '../../types';
3
3
  import { Updater } from '@topthink/components/types/hooks/use-immer';
4
4
  import { RequestInstance } from '@topthink/components';
5
5
  interface ContextType {
6
- bot: {
6
+ bot?: {
7
7
  name: string;
8
8
  avatar: string;
9
9
  };
@@ -5,7 +5,7 @@ import MessageItem, { MessageActions, MessageItemProps } from './message-item';
5
5
  import { Components } from 'react-markdown';
6
6
  export interface MessageBoxProps {
7
7
  className?: string;
8
- bot: {
8
+ bot?: {
9
9
  name: string;
10
10
  avatar: string;
11
11
  };
@@ -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;
@@ -1,6 +1,7 @@
1
1
  import { ToolMessage } from '../../types';
2
2
  interface Props {
3
3
  tool: ToolMessage;
4
+ loading?: boolean;
4
5
  }
5
- export default function Tool({ tool }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function Tool({ tool, loading }: Props): import("react/jsx-runtime").JSX.Element;
6
7
  export {};