bi-sdk-react 0.0.44 → 0.0.45

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.
@@ -417,7 +417,7 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
417
417
  .conversation-list li small {
418
418
  white-space: nowrap;
419
419
  }
420
- `,nM=[],nI="bi-design",nD=e=>{let t,n,r,i,a,o,s,{agentList:l=nM,headExtra:u,style:h={},onEffect:d}=e,{pageId:p,schema:f,fetch:g,atItems:v,onRemoveAtItem:y,clearAtItems:x}=(0,t_.useContext)(tb);if(!g)return null;let[b,w]=(0,t_.useState)(null),[S,C]=(0,t_.useState)([]),[k,T]=(0,t_.useState)([]),j=t_.default.useRef(null),M=()=>{setTimeout(()=>{j.current&&j.current.scrollToBottom()},100)},I=()=>{w(null),T([])},D=async e=>{$.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=g.ai)?void 0:t.removeConversation(e)),C(t=>t.filter(t=>t.id!==e)),T(t=>t.filter(t=>t.conversationId!==e)),b===e&&I()}})},O=async e=>{var t,n,r;w(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=g.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),T(await (null==(r=g.ai)?void 0:r.messageList(e))||[]),M()},A=async e=>{var t;let n={id:em(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(v),sending:!0};T(e=>[...e,n]),M();let r=!b;x();let{id:i,answer:a,createdAt:o,conversation:s}=await (null==(t=g.ai)?void 0:t.chat(nI,p,b,{...e,page:f,pageItems:v||[]}));w((null==s?void 0:s.id)||""),C(e=>[r?s||{}:null,...e].filter(e=>null!==e)),Object.assign(n,{id:i,answer:a,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),a.effect&&(null==d||d(a.effect)),T(e=>[...e]),M()},P=async e=>{var t;await (null==(t=g.ai)?void 0:t.removeMessage(e)),T(t=>t.filter(t=>t.id!==e))},z=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],S.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),L=async()=>{try{var e,t;let n=await (null==(e=g.ai)?void 0:e.conversationList(nI,p));C(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){w(r.id);let e=await (null==(t=g.ai)?void 0:t.messageList(r.id));T(e||[]),M()}}catch(e){console.error(e)}};return(0,t_.useEffect)(()=>{L()},[g]),(0,t_.useEffect)(()=>{M()},[]),(0,tx.jsxs)(nj,{style:h,children:[(0,tx.jsx)(nT,{title:"智能助理",extra:(0,tx.jsxs)(er,{children:[(0,tx.jsx)(el,{title:"新对话",placement:"topRight",children:(0,tx.jsx)("a",{onClick:I,children:(0,tx.jsx)(na,{type:"icon-chat-plus"})})}),(0,tx.jsx)(G,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,tx.jsx)(nP,{children:z.map(e=>(0,tx.jsxs)("div",{className:"group",children:[(0,tx.jsx)("div",{className:"group-title",children:e.title}),(0,tx.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,tx.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,tx.jsx)("a",{onClick:()=>O(e.id),children:e.name}),(0,tx.jsx)("small",{children:(0,tx.jsx)("a",{onClick:()=>D(e.id),children:(0,tx.jsx)(c,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,tx.jsx)("a",{children:(0,tx.jsx)(m,{})})}),u]}),style:{width:"initial"}}),(0,tx.jsxs)("div",{className:"body",children:[(0,tx.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:k.length?(0,tx.jsx)(nL,{ref:j,list:k,onDeleteMessage:P}):(0,tx.jsx)(nA,{})}),0===k.length&&S.length>0&&(0,tx.jsx)(E,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,tx.jsx)("ul",{className:"conversation-list",children:S.slice(0,3).map(e=>(0,tx.jsxs)("li",{children:[(0,tx.jsxs)("a",{children:[(0,tx.jsx)(_,{}),e.name]}),(0,tx.jsx)("small",{children:nm(e.createdAt)})]},e.id))})}),(0,tx.jsx)(nC,{agentList:l,style:{padding:12},atItems:v,onUploading:null==g?void 0:g.upload,onSubmit:A,onRemoveAtItem:y})]})]})},nO=t.div`
420
+ `,nM=[],nI="bi-design",nD=e=>{let t,n,r,i,a,o,s,{agentList:l=nM,headExtra:u,style:h={},onEffect:d}=e,{pageId:p,schema:f,fetch:g,atItems:v,onRemoveAtItem:y,clearAtItems:x}=(0,t_.useContext)(tb);if(!g)return null;let[b,w]=(0,t_.useState)(null),[S,C]=(0,t_.useState)([]),[k,T]=(0,t_.useState)([]),j=t_.default.useRef(null),M=()=>{setTimeout(()=>{j.current&&j.current.scrollToBottom()},100)},I=()=>{w(null),T([])},D=async e=>{$.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=g.ai)?void 0:t.removeConversation(e)),C(t=>t.filter(t=>t.id!==e)),T(t=>t.filter(t=>t.conversationId!==e)),b===e&&I()}})},O=async e=>{var t,n,r;w(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=g.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),T(await (null==(r=g.ai)?void 0:r.messageList(e))||[]),M()},A=async e=>{var t,n,r;let i={id:em(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(v),sending:!0};T(e=>[...e,i]),M();let a=!b;x();try{let{id:n,answer:r,createdAt:o,conversation:s}=await (null==(t=g.ai)?void 0:t.chat(nI,p,b,{...e,page:f,pageItems:v||[]}));w((null==s?void 0:s.id)||""),C(e=>[a?s||{}:null,...e].filter(e=>null!==e)),Object.assign(i,{id:n,answer:r,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),r.effect&&(null==d||d(r.effect))}catch(t){let e=(null==t||null==(r=t.response)||null==(n=r.data)?void 0:n.message)||t.message||"未知错误";console.error(e),Object.assign(i,{sending:!1,error:e})}T(e=>[...e]),M()},P=async e=>{var t;await (null==(t=g.ai)?void 0:t.removeMessage(e)),T(t=>t.filter(t=>t.id!==e))},z=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],S.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),L=async()=>{try{var e,t;let n=await (null==(e=g.ai)?void 0:e.conversationList(nI,p));C(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){w(r.id);let e=await (null==(t=g.ai)?void 0:t.messageList(r.id));T(e||[]),M()}}catch(e){console.error(e)}};return(0,t_.useEffect)(()=>{L()},[g]),(0,t_.useEffect)(()=>{M()},[]),(0,tx.jsxs)(nj,{style:h,children:[(0,tx.jsx)(nT,{title:"智能助理",extra:(0,tx.jsxs)(er,{children:[(0,tx.jsx)(el,{title:"新对话",placement:"topRight",children:(0,tx.jsx)("a",{onClick:I,children:(0,tx.jsx)(na,{type:"icon-chat-plus"})})}),(0,tx.jsx)(G,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,tx.jsx)(nP,{children:z.map(e=>(0,tx.jsxs)("div",{className:"group",children:[(0,tx.jsx)("div",{className:"group-title",children:e.title}),(0,tx.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,tx.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,tx.jsx)("a",{onClick:()=>O(e.id),children:e.name}),(0,tx.jsx)("small",{children:(0,tx.jsx)("a",{onClick:()=>D(e.id),children:(0,tx.jsx)(c,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,tx.jsx)("a",{children:(0,tx.jsx)(m,{})})}),u]}),style:{width:"initial"}}),(0,tx.jsxs)("div",{className:"body",children:[(0,tx.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:k.length?(0,tx.jsx)(nL,{ref:j,list:k,onDeleteMessage:P}):(0,tx.jsx)(nA,{})}),0===k.length&&S.length>0&&(0,tx.jsx)(E,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,tx.jsx)("ul",{className:"conversation-list",children:S.slice(0,3).map(e=>(0,tx.jsxs)("li",{children:[(0,tx.jsxs)("a",{children:[(0,tx.jsx)(_,{}),e.name]}),(0,tx.jsx)("small",{children:nm(e.createdAt)})]},e.id))})}),(0,tx.jsx)(nC,{agentList:l,style:{padding:12},atItems:v,onUploading:null==g?void 0:g.upload,onSubmit:A,onRemoveAtItem:y})]})]})},nO=t.div`
421
421
  flex: 1 1 auto;
422
422
  display: flex;
423
423
  align-items: center;
@@ -574,6 +574,11 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
574
574
  font-size: 13px;
575
575
  line-height: 1.6;
576
576
  white-space: pre-wrap;
577
+
578
+ &.error {
579
+ color: var(--ant-color-error-text);
580
+ padding: 10px 0;
581
+ }
577
582
  }
578
583
  .msg-meta {
579
584
  display: flex;
@@ -632,7 +637,7 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
632
637
  }
633
638
  }
634
639
  }
635
- `,nL=(0,t_.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,t_.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,t_.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,tx.jsx)(nz,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,h,d;return(0,tx.jsxs)("div",{className:"msg",children:[(0,tx.jsxs)("div",{className:"user-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsx)("span",{children:nm(e.createdAt)})}),(0,tx.jsxs)("div",{className:"msg-section",children:[(0,tx.jsxs)(er,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,tx.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,tx.jsx)(Z,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,tx.jsx)(el,{title:"删除",children:(0,tx.jsx)(R,{type:"link",size:"small",icon:(0,tx.jsx)(c,{})})})})]}),(0,tx.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,tx.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,tx.jsxs)(eo,{color:"processing",children:[(0,tx.jsx)(na,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,tx.jsxs)("div",{className:"assistant-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsxs)("span",{className:"msg-title",children:[(0,tx.jsx)(T,{})," 智能助理"]})}),(0,tx.jsx)("div",{className:"msg-section",children:e.sending?(0,tx.jsx)(en,{active:!0}):(0,tx.jsxs)(tx.Fragment,{children:[(0,tx.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,tx.jsx)(el,{title:e.description,children:(0,tx.jsx)(eo,{color:"blue",children:e.name})},t))})]}),!!(null==(d=e.answer)||null==(h=d.extra)?void 0:h.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,tx.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,tx.jsx)(eo,{color:"gold",children:e.element}),(0,tx.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),nN=t.div`
640
+ `,nL=(0,t_.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,t_.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,t_.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,tx.jsx)(nz,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,h,d;return(0,tx.jsxs)("div",{className:"msg",children:[(0,tx.jsxs)("div",{className:"user-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsx)("span",{children:nm(e.createdAt)})}),(0,tx.jsxs)("div",{className:"msg-section",children:[(0,tx.jsxs)(er,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,tx.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,tx.jsx)(Z,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,tx.jsx)(el,{title:"删除",children:(0,tx.jsx)(R,{type:"link",size:"small",icon:(0,tx.jsx)(c,{})})})})]}),(0,tx.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,tx.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,tx.jsxs)(eo,{color:"processing",children:[(0,tx.jsx)(na,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,tx.jsxs)("div",{className:"assistant-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsxs)("span",{className:"msg-title",children:[(0,tx.jsx)(T,{})," 智能助理"]})}),(0,tx.jsx)("div",{className:"msg-section",children:e.sending?(0,tx.jsx)(en,{active:!0}):(0,tx.jsxs)(tx.Fragment,{children:[e.error?(0,tx.jsxs)("div",{className:"msg-content error",children:["执行失败:",e.error]}):(0,tx.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,tx.jsx)(el,{title:e.description,children:(0,tx.jsx)(eo,{color:"blue",children:e.name})},t))})]}),!!(null==(d=e.answer)||null==(h=d.extra)?void 0:h.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,tx.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,tx.jsx)(eo,{color:"gold",children:e.element}),(0,tx.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),nN=t.div`
636
641
  display: flex;
637
642
  flex-direction: column;
638
643
  height: 100%;
@@ -417,7 +417,7 @@
417
417
  .conversation-list li small {
418
418
  white-space: nowrap;
419
419
  }
420
- `,tO=[],tA="bi-design",tP=e=>{let t,n,r,i,a,o,s,{agentList:l=tO,headExtra:u,style:c={},onEffect:h}=e,{pageId:d,schema:p,fetch:f,atItems:g,onRemoveAtItem:m,clearAtItems:v}=(0,ed.useContext)(em);if(!f)return null;let[y,x]=(0,ed.useState)(null),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),C=ep().useRef(null),T=()=>{setTimeout(()=>{C.current&&C.current.scrollToBottom()},100)},k=()=>{x(null),S([])},I=async e=>{tn.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=f.ai)?void 0:t.removeConversation(e)),b(t=>t.filter(t=>t.id!==e)),S(t=>t.filter(t=>t.conversationId!==e)),y===e&&k()}})},j=async e=>{var t,n,r;x(e),b(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=f.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),S(await (null==(r=f.ai)?void 0:r.messageList(e))||[]),T()},M=async e=>{var t;let n={id:ty(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(g),sending:!0};S(e=>[...e,n]),T();let r=!y;v();let{id:i,answer:a,createdAt:o,conversation:s}=await (null==(t=f.ai)?void 0:t.chat(tA,d,y,{...e,page:p,pageItems:g||[]}));x((null==s?void 0:s.id)||""),b(e=>[r?s||{}:null,...e].filter(e=>null!==e)),Object.assign(n,{id:i,answer:a,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),a.effect&&(null==h||h(a.effect)),S(e=>[...e]),T()},D=async e=>{var t;await (null==(t=f.ai)?void 0:t.removeMessage(e)),S(t=>t.filter(t=>t.id!==e))},O=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],_.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),A=async()=>{try{var e,t;let n=await (null==(e=f.ai)?void 0:e.conversationList(tA,d));b(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){x(r.id);let e=await (null==(t=f.ai)?void 0:t.messageList(r.id));S(e||[]),T()}}catch(e){console.error(e)}};return(0,ed.useEffect)(()=>{A()},[f]),(0,ed.useEffect)(()=>{T()},[]),(0,eh.jsxs)(tD,{style:c,children:[(0,eh.jsx)(tM,{title:"智能助理",extra:(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Tooltip,{title:"新对话",placement:"topRight",children:(0,eh.jsx)("a",{onClick:k,children:(0,eh.jsx)(tt,{type:"icon-chat-plus"})})}),(0,eh.jsx)(tn.Dropdown,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,eh.jsx)(tN,{children:O.map(e=>(0,eh.jsxs)("div",{className:"group",children:[(0,eh.jsx)("div",{className:"group-title",children:e.title}),(0,eh.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,eh.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,eh.jsx)("a",{onClick:()=>j(e.id),children:e.name}),(0,eh.jsx)("small",{children:(0,eh.jsx)("a",{onClick:()=>I(e.id),children:(0,eh.jsx)(e7.DeleteOutlined,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,eh.jsx)("a",{children:(0,eh.jsx)(e7.HistoryOutlined,{})})}),u]}),style:{width:"initial"}}),(0,eh.jsxs)("div",{className:"body",children:[(0,eh.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:w.length?(0,eh.jsx)(tF,{ref:C,list:w,onDeleteMessage:D}):(0,eh.jsx)(tz,{})}),0===w.length&&_.length>0&&(0,eh.jsx)(tn.Card,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,eh.jsx)("ul",{className:"conversation-list",children:_.slice(0,3).map(e=>(0,eh.jsxs)("li",{children:[(0,eh.jsxs)("a",{children:[(0,eh.jsx)(e7.MessageOutlined,{}),e.name]}),(0,eh.jsx)("small",{children:tx(e.createdAt)})]},e.id))})}),(0,eh.jsx)(tI,{agentList:l,style:{padding:12},atItems:g,onUploading:null==f?void 0:f.upload,onSubmit:M,onRemoveAtItem:m})]})]})},tR=eg().div`
420
+ `,tO=[],tA="bi-design",tP=e=>{let t,n,r,i,a,o,s,{agentList:l=tO,headExtra:u,style:c={},onEffect:h}=e,{pageId:d,schema:p,fetch:f,atItems:g,onRemoveAtItem:m,clearAtItems:v}=(0,ed.useContext)(em);if(!f)return null;let[y,x]=(0,ed.useState)(null),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),C=ep().useRef(null),T=()=>{setTimeout(()=>{C.current&&C.current.scrollToBottom()},100)},k=()=>{x(null),S([])},I=async e=>{tn.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=f.ai)?void 0:t.removeConversation(e)),b(t=>t.filter(t=>t.id!==e)),S(t=>t.filter(t=>t.conversationId!==e)),y===e&&k()}})},j=async e=>{var t,n,r;x(e),b(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=f.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),S(await (null==(r=f.ai)?void 0:r.messageList(e))||[]),T()},M=async e=>{var t,n,r;let i={id:ty(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(g),sending:!0};S(e=>[...e,i]),T();let a=!y;v();try{let{id:n,answer:r,createdAt:o,conversation:s}=await (null==(t=f.ai)?void 0:t.chat(tA,d,y,{...e,page:p,pageItems:g||[]}));x((null==s?void 0:s.id)||""),b(e=>[a?s||{}:null,...e].filter(e=>null!==e)),Object.assign(i,{id:n,answer:r,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),r.effect&&(null==h||h(r.effect))}catch(t){let e=(null==t||null==(r=t.response)||null==(n=r.data)?void 0:n.message)||t.message||"未知错误";console.error(e),Object.assign(i,{sending:!1,error:e})}S(e=>[...e]),T()},D=async e=>{var t;await (null==(t=f.ai)?void 0:t.removeMessage(e)),S(t=>t.filter(t=>t.id!==e))},O=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],_.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),A=async()=>{try{var e,t;let n=await (null==(e=f.ai)?void 0:e.conversationList(tA,d));b(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){x(r.id);let e=await (null==(t=f.ai)?void 0:t.messageList(r.id));S(e||[]),T()}}catch(e){console.error(e)}};return(0,ed.useEffect)(()=>{A()},[f]),(0,ed.useEffect)(()=>{T()},[]),(0,eh.jsxs)(tD,{style:c,children:[(0,eh.jsx)(tM,{title:"智能助理",extra:(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Tooltip,{title:"新对话",placement:"topRight",children:(0,eh.jsx)("a",{onClick:k,children:(0,eh.jsx)(tt,{type:"icon-chat-plus"})})}),(0,eh.jsx)(tn.Dropdown,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,eh.jsx)(tN,{children:O.map(e=>(0,eh.jsxs)("div",{className:"group",children:[(0,eh.jsx)("div",{className:"group-title",children:e.title}),(0,eh.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,eh.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,eh.jsx)("a",{onClick:()=>j(e.id),children:e.name}),(0,eh.jsx)("small",{children:(0,eh.jsx)("a",{onClick:()=>I(e.id),children:(0,eh.jsx)(e7.DeleteOutlined,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,eh.jsx)("a",{children:(0,eh.jsx)(e7.HistoryOutlined,{})})}),u]}),style:{width:"initial"}}),(0,eh.jsxs)("div",{className:"body",children:[(0,eh.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:w.length?(0,eh.jsx)(tF,{ref:C,list:w,onDeleteMessage:D}):(0,eh.jsx)(tz,{})}),0===w.length&&_.length>0&&(0,eh.jsx)(tn.Card,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,eh.jsx)("ul",{className:"conversation-list",children:_.slice(0,3).map(e=>(0,eh.jsxs)("li",{children:[(0,eh.jsxs)("a",{children:[(0,eh.jsx)(e7.MessageOutlined,{}),e.name]}),(0,eh.jsx)("small",{children:tx(e.createdAt)})]},e.id))})}),(0,eh.jsx)(tI,{agentList:l,style:{padding:12},atItems:g,onUploading:null==f?void 0:f.upload,onSubmit:M,onRemoveAtItem:m})]})]})},tR=eg().div`
421
421
  flex: 1 1 auto;
422
422
  display: flex;
423
423
  align-items: center;
@@ -574,6 +574,11 @@
574
574
  font-size: 13px;
575
575
  line-height: 1.6;
576
576
  white-space: pre-wrap;
577
+
578
+ &.error {
579
+ color: var(--ant-color-error-text);
580
+ padding: 10px 0;
581
+ }
577
582
  }
578
583
  .msg-meta {
579
584
  display: flex;
@@ -632,7 +637,7 @@
632
637
  }
633
638
  }
634
639
  }
635
- `,tF=(0,ed.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,ed.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,ed.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eh.jsx)(tL,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,c,h;return(0,eh.jsxs)("div",{className:"msg",children:[(0,eh.jsxs)("div",{className:"user-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsx)("span",{children:tx(e.createdAt)})}),(0,eh.jsxs)("div",{className:"msg-section",children:[(0,eh.jsxs)(tn.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eh.jsx)(tn.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eh.jsx)(tn.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,eh.jsx)(tn.Tooltip,{title:"删除",children:(0,eh.jsx)(tn.Button,{type:"link",size:"small",icon:(0,eh.jsx)(e7.DeleteOutlined,{})})})})]}),(0,eh.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,eh.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eh.jsxs)(tn.Tag,{color:"processing",children:[(0,eh.jsx)(tt,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,eh.jsxs)("div",{className:"assistant-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsxs)("span",{className:"msg-title",children:[(0,eh.jsx)(e7.RobotOutlined,{})," 智能助理"]})}),(0,eh.jsx)("div",{className:"msg-section",children:e.sending?(0,eh.jsx)(tn.Skeleton,{active:!0}):(0,eh.jsxs)(eh.Fragment,{children:[(0,eh.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,eh.jsx)(tn.Tooltip,{title:e.description,children:(0,eh.jsx)(tn.Tag,{color:"blue",children:e.name})},t))})]}),!!(null==(h=e.answer)||null==(c=h.extra)?void 0:c.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,eh.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,eh.jsx)(tn.Tag,{color:"gold",children:e.element}),(0,eh.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),tE=eg().div`
640
+ `,tF=(0,ed.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,ed.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,ed.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eh.jsx)(tL,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,c,h;return(0,eh.jsxs)("div",{className:"msg",children:[(0,eh.jsxs)("div",{className:"user-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsx)("span",{children:tx(e.createdAt)})}),(0,eh.jsxs)("div",{className:"msg-section",children:[(0,eh.jsxs)(tn.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eh.jsx)(tn.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eh.jsx)(tn.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,eh.jsx)(tn.Tooltip,{title:"删除",children:(0,eh.jsx)(tn.Button,{type:"link",size:"small",icon:(0,eh.jsx)(e7.DeleteOutlined,{})})})})]}),(0,eh.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,eh.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eh.jsxs)(tn.Tag,{color:"processing",children:[(0,eh.jsx)(tt,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,eh.jsxs)("div",{className:"assistant-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsxs)("span",{className:"msg-title",children:[(0,eh.jsx)(e7.RobotOutlined,{})," 智能助理"]})}),(0,eh.jsx)("div",{className:"msg-section",children:e.sending?(0,eh.jsx)(tn.Skeleton,{active:!0}):(0,eh.jsxs)(eh.Fragment,{children:[e.error?(0,eh.jsxs)("div",{className:"msg-content error",children:["执行失败:",e.error]}):(0,eh.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,eh.jsx)(tn.Tooltip,{title:e.description,children:(0,eh.jsx)(tn.Tag,{color:"blue",children:e.name})},t))})]}),!!(null==(h=e.answer)||null==(c=h.extra)?void 0:c.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,eh.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,eh.jsx)(tn.Tag,{color:"gold",children:e.element}),(0,eh.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),tE=eg().div`
636
641
  display: flex;
637
642
  flex-direction: column;
638
643
  height: 100%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-sdk-react",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -104,7 +104,9 @@ export const AiPanel: React.FC<AiPanelProps> = ({
104
104
  const [conversationList, setConversationList] = useState<
105
105
  ChatConversationType[]
106
106
  >([]);
107
- const [messageList, setMessageList] = useState<ChatMessageType[]>([]);
107
+ const [messageList, setMessageList] = useState<
108
+ (ChatMessageType & { error?: string | null })[]
109
+ >([]);
108
110
  const messageListRef = React.useRef<MessageListRef>(null);
109
111
 
110
112
  const scrollToBottom = () => {
@@ -159,39 +161,48 @@ export const AiPanel: React.FC<AiPanelProps> = ({
159
161
  agents: data.agents || [],
160
162
  atItems: JSON.stringify(atItems),
161
163
  sending: true,
162
- } as ChatMessageType;
164
+ } as ChatMessageType & { error?: string | null };
163
165
  setMessageList((list) => [...list, questionMessage]);
164
166
  scrollToBottom();
165
167
 
166
168
  const newConversation = !conversationId;
167
169
 
168
170
  clearAtItems();
169
- const { id, answer, createdAt, conversation } = await fetch.ai?.chat(
170
- BIZ_TYPE,
171
- pageId,
172
- conversationId,
173
- {
174
- ...data,
175
- page: schema,
176
- pageItems: atItems || [],
177
- },
178
- )!;
179
- setConversationId(conversation?.id || "");
180
- setConversationList((list) =>
181
- [
182
- newConversation ? conversation || ({} as ChatConversationType) : null,
183
- ...list,
184
- ].filter((i) => i !== null),
185
- );
186
- Object.assign(questionMessage, {
187
- id,
188
- answer,
189
- createdAt,
190
- conversationId: conversation?.id || "",
191
- sending: false,
192
- });
193
- if (answer.effect) {
194
- onEffect?.(answer.effect);
171
+ try {
172
+ const { id, answer, createdAt, conversation } = await fetch.ai?.chat(
173
+ BIZ_TYPE,
174
+ pageId,
175
+ conversationId,
176
+ {
177
+ ...data,
178
+ page: schema,
179
+ pageItems: atItems || [],
180
+ },
181
+ )!;
182
+ setConversationId(conversation?.id || "");
183
+ setConversationList((list) =>
184
+ [
185
+ newConversation ? conversation || ({} as ChatConversationType) : null,
186
+ ...list,
187
+ ].filter((i) => i !== null),
188
+ );
189
+ Object.assign(questionMessage, {
190
+ id,
191
+ answer,
192
+ createdAt,
193
+ conversationId: conversation?.id || "",
194
+ sending: false,
195
+ });
196
+ if (answer.effect) {
197
+ onEffect?.(answer.effect);
198
+ }
199
+ } catch (error: any) {
200
+ const errorMessage = error?.response?.data?.message || error.message || "未知错误";
201
+ console.error(errorMessage);
202
+ Object.assign(questionMessage, {
203
+ sending: false,
204
+ error: errorMessage,
205
+ });
195
206
  }
196
207
  setMessageList((list) => [...list]);
197
208
  scrollToBottom();
@@ -238,9 +249,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
238
249
  const active = list?.find((i) => i.isActived);
239
250
  if (active) {
240
251
  setConversationId(active.id);
241
- const messages = await fetch.ai?.messageList(
242
- active.id,
243
- );
252
+ const messages = await fetch.ai?.messageList(active.id);
244
253
  setMessageList(messages || []);
245
254
  scrollToBottom();
246
255
  }
@@ -553,6 +562,11 @@ const MessageRoot = styled.div`
553
562
  font-size: 13px;
554
563
  line-height: 1.6;
555
564
  white-space: pre-wrap;
565
+
566
+ &.error {
567
+ color: var(--ant-color-error-text);
568
+ padding: 10px 0;
569
+ }
556
570
  }
557
571
  .msg-meta {
558
572
  display: flex;
@@ -619,7 +633,7 @@ type MessageListRef = {
619
633
 
620
634
  const MessageList = forwardRef<
621
635
  MessageListRef,
622
- { list: ChatMessageType[]; onDeleteMessage: (id: string) => void }
636
+ { list: (ChatMessageType & { error?: string | null })[]; onDeleteMessage: (id: string) => void }
623
637
  >(({ list, onDeleteMessage }, forwardRef) => {
624
638
  const ref = useRef<HTMLDivElement>(null);
625
639
 
@@ -661,7 +675,9 @@ const MessageList = forwardRef<
661
675
  </div>
662
676
  <div className="msg-section">
663
677
  <Space size={4} orientation="vertical" className="msg-tools">
664
- <Typography.Text copyable={{ text: msg.question, tooltips: "复制" }} />
678
+ <Typography.Text
679
+ copyable={{ text: msg.question, tooltips: "复制" }}
680
+ />
665
681
  <Popconfirm
666
682
  title="确认删除吗?"
667
683
  okText="确认"
@@ -681,7 +697,9 @@ const MessageList = forwardRef<
681
697
  </Tooltip> */}
682
698
  </Space>
683
699
  <div className="msg-content">{msg.question}</div>
684
- {msg.files?.length || msg.agents?.length || msg.atItems?.length ? (
700
+ {msg.files?.length ||
701
+ msg.agents?.length ||
702
+ msg.atItems?.length ? (
685
703
  <div className="msg-meta">
686
704
  {msg.files?.map((f) => (
687
705
  <Tag key={f.id} color="processing">
@@ -721,7 +739,11 @@ const MessageList = forwardRef<
721
739
  <Skeleton active />
722
740
  ) : (
723
741
  <>
724
- <div className="msg-content">{msg.answer?.answer || ""}</div>
742
+ {msg.error ? (
743
+ <div className="msg-content error">执行失败:{msg.error}</div>
744
+ ) : (
745
+ <div className="msg-content">{msg.answer?.answer || ""}</div>
746
+ )}
725
747
  {!!msg.answer?.plans?.length && (
726
748
  <details className="msg-ai-meta" open>
727
749
  <summary className="msg-ai-meta-title">PLANS:</summary>