@topthink/chat 1.3.24 → 1.3.26

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,7 +704,7 @@ 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};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`
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`
708
708
  width: ${e=>e.$open?"auto":"fit-content"};
709
709
  max-width: 100%;
710
710
  overflow: hidden;
@@ -719,7 +719,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as
719
719
  }
720
720
  `,dr=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((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`
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`
723
723
  ${e=>e.$deleted&&o`
724
724
  text-decoration-line: line-through;
725
725
  color: var(--bs-secondary);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.3.24",
3
+ "version": "1.3.26",
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": "d7258615194b30be96cd958d6c7ebf86366205be"
74
+ "gitHead": "2270223c5518f0fbea99dcc1ffccbd107756efd8"
75
75
  }
@@ -5,6 +5,7 @@ interface ContextType {
5
5
  toolIndex?: number;
6
6
  tool?: ToolMessage;
7
7
  isLastMessage: boolean;
8
+ isLast: boolean;
8
9
  }
9
10
  declare const _default: import("react").Provider<ContextType | null>;
10
11
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, FC, MutableRefObject, PropsWithChildren, ReactElement, ReactNode, SetStateAction } from 'react';
2
- import { Conversation, Chunk, Input, LogLevel, Message, ToolMessage } from '../../types';
2
+ import { Chunk, Conversation, Input, LogLevel, Message, 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';
@@ -19,6 +19,7 @@ export interface ToolRenderResult {
19
19
  response?: ReactNode;
20
20
  /** 是否显示状态文本(如"已使用"、"正在使用"等),默认为 true */
21
21
  showStatus?: boolean;
22
+ showIcon?: boolean;
22
23
  /** 是否默认展开详情 */
23
24
  defaultExpanded?: boolean;
24
25
  }