@topthink/chat 1.3.25 → 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};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,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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.3.25",
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": "0d6e57578bb7b559e0b12fdae7ba6d2ff9736d9b"
74
+ "gitHead": "2270223c5518f0fbea99dcc1ffccbd107756efd8"
75
75
  }
@@ -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
  }