bi-sdk-react 0.0.27 → 0.0.28
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/dist/es/js/bi-sdk.es.js
CHANGED
|
@@ -417,7 +417,7 @@ import*as e from"react";import t,{css as l}from"styled-components";import{AlignC
|
|
|
417
417
|
.conversation-list li small {
|
|
418
418
|
white-space: nowrap;
|
|
419
419
|
}
|
|
420
|
-
`,tM=[],t_="bi-design",t$=e=>{let t,l,n,r,a,i,o,{agentList:s=tM,headExtra:d,style:u={},onEffect:p}=e,{pageId:x,schema:m,fetch:h,atItems:g,onRemoveAtItem:v}=(0,eE.useContext)(eT);if(!h)return null;let[j,y]=(0,eE.useState)(null),[w,C]=(0,eE.useState)([]),[S,k]=(0,eE.useState)([]),z=eE.default.useRef(null),I=()=>{setTimeout(()=>{z.current&&z.current.scrollToBottom()},100)},N=()=>{y(null),k([])},O=async e=>{q.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=h.ai)?void 0:t.removeConversation(
|
|
420
|
+
`,tM=[],t_="bi-design",t$=e=>{let t,l,n,r,a,i,o,{agentList:s=tM,headExtra:d,style:u={},onEffect:p}=e,{pageId:x,schema:m,fetch:h,atItems:g,onRemoveAtItem:v}=(0,eE.useContext)(eT);if(!h)return null;let[j,y]=(0,eE.useState)(null),[w,C]=(0,eE.useState)([]),[S,k]=(0,eE.useState)([]),z=eE.default.useRef(null),I=()=>{setTimeout(()=>{z.current&&z.current.scrollToBottom()},100)},N=()=>{y(null),k([])},O=async e=>{q.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=h.ai)?void 0:t.removeConversation(e)),C(t=>t.filter(t=>t.id!==e)),k(t=>t.filter(t=>t.conversationId!==e)),j===e&&N()}})},E=async e=>{var t;y(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),k(await (null==(t=h.ai)?void 0:t.messageList(e))||[]),I()},T=async e=>{var t;let l={id:ef(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:g,sending:!0};k(e=>[...e,l]),I();let n=!j,{id:r,answer:a,createdAt:i,conversation:o}=await (null==(t=h.ai)?void 0:t.chat(t_,x,j,{...e,page:JSON.stringify(m),pageItems:JSON.stringify(g||[])}));y((null==o?void 0:o.id)||""),C(e=>[n?o||{}:null,...e].filter(e=>null!==e)),Object.assign(l,{id:r,answer:a,createdAt:i,conversationId:(null==o?void 0:o.id)||"",sending:!1}),a.effect&&(null==p||p(a.effect)),k(e=>[...e]),I()},A=async e=>{var t;await (null==(t=h.ai)?void 0:t.removeMessage(e)),k(t=>t.filter(t=>t.id!==e))},D=(t=new Date,l=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(n=new Date(t)).setDate(t.getDate()-1),r=[],a=[],i=[],o=[],w.forEach(e=>{let s=new Date(e.createdAt);if(l(s,t))r.push(e);else if(l(s,n))a.push(e);else s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()?i.push(e):o.push(e)}),[{title:"今天",items:r},{title:"昨天",items:a},{title:"本月内",items:i},{title:"很久以前",items:o}].filter(e=>e.items.length>0)),B=async()=>{try{var e,t;let l=await (null==(e=h.ai)?void 0:e.conversationList(t_,x));C(l||[]);let n=null==l?void 0:l.find(e=>e.isActived);if(n){y(n.id);let e=await (null==(t=h.ai)?void 0:t.messageList(n.id));k(e||[]),I()}}catch(e){console.error(e)}};return(0,eE.useEffect)(()=>{B()},[h]),(0,eE.useEffect)(()=>{I()},[]),(0,eO.jsxs)(tP,{style:u,children:[(0,eO.jsx)(tL,{title:"智能助理",extra:(0,eO.jsxs)(en,{children:[(0,eO.jsx)(es,{title:"新对话",placement:"topRight",children:(0,eO.jsx)("a",{onClick:N,children:(0,eO.jsx)(th,{type:"icon-chat-plus"})})}),(0,eO.jsx)(J,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,eO.jsx)(tH,{children:D.map(e=>(0,eO.jsxs)("div",{className:"group",children:[(0,eO.jsx)("div",{className:"group-title",children:e.title}),(0,eO.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,eO.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,eO.jsx)("a",{onClick:()=>E(e.id),children:e.name}),(0,eO.jsx)("small",{children:(0,eO.jsx)("a",{onClick:()=>O(e.id),children:(0,eO.jsx)(c,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,eO.jsx)("a",{children:(0,eO.jsx)(f,{})})}),d]}),style:{width:"initial"}}),(0,eO.jsxs)("div",{className:"body",children:[(0,eO.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:S.length?(0,eO.jsx)(tJ,{ref:z,list:S,onDeleteMessage:A}):(0,eO.jsx)(tY,{})}),0===S.length&&w.length>0&&(0,eO.jsx)(M,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,eO.jsx)("ul",{className:"conversation-list",children:w.slice(0,3).map(e=>(0,eO.jsxs)("li",{children:[(0,eO.jsxs)("a",{children:[(0,eO.jsx)(b,{}),e.name]}),(0,eO.jsx)("small",{children:tz(e.createdAt)})]},e.id))})}),(0,eO.jsx)(tB,{agentList:s,style:{padding:12},atItems:g,onUploading:null==h?void 0:h.upload,onSubmit:T,onRemoveAtItem:v})]})]})},tF=t.div`
|
|
421
421
|
flex: 1 1 auto;
|
|
422
422
|
display: flex;
|
|
423
423
|
align-items: center;
|
|
@@ -632,7 +632,7 @@ import*as e from"react";import t,{css as l}from"styled-components";import{AlignC
|
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
`,tJ=(0,eE.forwardRef)((e,t)=>{let{list:l,onDeleteMessage:n}=e,r=(0,eE.useRef)(null),a=()=>{setTimeout(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},100)};return(0,eE.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eO.jsx)(tG,{className:"message-list beautified_scrollbar",ref:r,children:l.map(e=>{var t,l,r,a,i,o,s,d,u,p;return(0,eO.jsxs)("div",{className:"msg",children:[(0,eO.jsxs)("div",{className:"user-message",children:[(0,eO.jsx)("div",{className:"msg-header",children:(0,eO.jsx)("span",{children:tz(e.createdAt)})}),(0,eO.jsxs)("div",{className:"msg-section",children:[(0,eO.jsxs)(en,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eO.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eO.jsx)(V,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>n(e.id),children:(0,eO.jsx)(es,{title:"删除",children:(0,eO.jsx)(P,{type:"link",size:"small",icon:(0,eO.jsx)(c,{})})})})]}),(0,eO.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(l=e.agents)?void 0:l.length)||(null==(r=e.atItems)?void 0:r.length)?(0,eO.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eO.jsxs)(ei,{color:"processing",children:[(0,eO.jsx)(th,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(i=e.agents)?void 0:i.map(e=>(0,eO.jsxs)(ei,{color:"blue",children:[(0,eO.jsx)(th,{type:"icon-at"})," ",e.name]},e.id)),JSON.parse(e
|
|
635
|
+
`,tJ=(0,eE.forwardRef)((e,t)=>{let{list:l,onDeleteMessage:n}=e,r=(0,eE.useRef)(null),a=()=>{setTimeout(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},100)};return(0,eE.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eO.jsx)(tG,{className:"message-list beautified_scrollbar",ref:r,children:l.map(e=>{var t,l,r,a,i,o,s,d,u,p;return(0,eO.jsxs)("div",{className:"msg",children:[(0,eO.jsxs)("div",{className:"user-message",children:[(0,eO.jsx)("div",{className:"msg-header",children:(0,eO.jsx)("span",{children:tz(e.createdAt)})}),(0,eO.jsxs)("div",{className:"msg-section",children:[(0,eO.jsxs)(en,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eO.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eO.jsx)(V,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>n(e.id),children:(0,eO.jsx)(es,{title:"删除",children:(0,eO.jsx)(P,{type:"link",size:"small",icon:(0,eO.jsx)(c,{})})})})]}),(0,eO.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(l=e.agents)?void 0:l.length)||(null==(r=e.atItems)?void 0:r.length)?(0,eO.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eO.jsxs)(ei,{color:"processing",children:[(0,eO.jsx)(th,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(i=e.agents)?void 0:i.map(e=>(0,eO.jsxs)(ei,{color:"blue",children:[(0,eO.jsx)(th,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{return JSON.parse(e||"[]")}catch(e){return[]}})(e.atItems).map(e=>(0,eO.jsxs)(ei,{color:"blue",children:[(0,eO.jsx)(th,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,eO.jsxs)("div",{className:"assistant-message",children:[(0,eO.jsx)("div",{className:"msg-header",children:(0,eO.jsxs)("span",{className:"msg-title",children:[(0,eO.jsx)(z,{})," 智能助理"]})}),(0,eO.jsx)("div",{className:"msg-section",children:e.sending?(0,eO.jsx)(el,{active:!0}):(0,eO.jsxs)(eO.Fragment,{children:[(0,eO.jsx)("div",{className:"msg-content",children:(null==(o=e.answer)?void 0:o.answer)||""}),!!(null==(d=e.answer)||null==(s=d.plans)?void 0:s.length)&&(0,eO.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eO.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,eO.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,eO.jsx)(es,{title:e.description,children:(0,eO.jsx)(ei,{color:"blue",children:e.name})},t))})]}),!!(null==(p=e.answer)||null==(u=p.extra)?void 0:u.length)&&(0,eO.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eO.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,eO.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,eO.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,eO.jsx)(ei,{color:"gold",children:e.element}),(0,eO.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),tK=t.div`
|
|
636
636
|
display: flex;
|
|
637
637
|
flex-direction: column;
|
|
638
638
|
height: 100%;
|
|
@@ -77,9 +77,9 @@ export type FetchType = {
|
|
|
77
77
|
ai?: {
|
|
78
78
|
chat: (bizType: string, bizId: string, conversationId: string | null, request: ChatRequestType) => Promise<ChatResponseType>;
|
|
79
79
|
conversationList: (bizType: string, bizId: string) => Promise<ChatConversationType[]>;
|
|
80
|
-
messageList: (
|
|
81
|
-
removeConversation: (
|
|
82
|
-
removeMessage: (
|
|
80
|
+
messageList: (conversationId: string, prevId?: string) => Promise<ChatMessageType[]>;
|
|
81
|
+
removeConversation: (conversationId: string) => Promise<boolean>;
|
|
82
|
+
removeMessage: (messageId: string) => Promise<boolean>;
|
|
83
83
|
};
|
|
84
84
|
dataset?: (dataSetId: string, params: Record<string, any>) => Promise<any>;
|
|
85
85
|
};
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
.conversation-list li small {
|
|
418
418
|
white-space: nowrap;
|
|
419
419
|
}
|
|
420
|
-
`,eY=[],e_="bi-design",eq=e=>{let t,l,n,r,a,i,o,{agentList:s=eY,headExtra:u,style:p={},onEffect:x}=e,{pageId:h,schema:g,fetch:v,atItems:j,onRemoveAtItem:b}=(0,c.useContext)(f);if(!v)return null;let[y,w]=(0,c.useState)(null),[C,S]=(0,c.useState)([]),[I,k]=(0,c.useState)([]),z=m().useRef(null),O=()=>{setTimeout(()=>{z.current&&z.current.scrollToBottom()},100)},N=()=>{w(null),k([])},T=async e=>{ep.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=v.ai)?void 0:t.removeConversation(
|
|
420
|
+
`,eY=[],e_="bi-design",eq=e=>{let t,l,n,r,a,i,o,{agentList:s=eY,headExtra:u,style:p={},onEffect:x}=e,{pageId:h,schema:g,fetch:v,atItems:j,onRemoveAtItem:b}=(0,c.useContext)(f);if(!v)return null;let[y,w]=(0,c.useState)(null),[C,S]=(0,c.useState)([]),[I,k]=(0,c.useState)([]),z=m().useRef(null),O=()=>{setTimeout(()=>{z.current&&z.current.scrollToBottom()},100)},N=()=>{w(null),k([])},T=async e=>{ep.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=v.ai)?void 0:t.removeConversation(e)),S(t=>t.filter(t=>t.id!==e)),k(t=>t.filter(t=>t.conversationId!==e)),y===e&&N()}})},R=async e=>{var t;w(e),S(t=>t.map(t=>({...t,isActived:t.id===e}))),k(await (null==(t=v.ai)?void 0:t.messageList(e))||[]),O()},F=async e=>{var t;let l={id:eO(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:j,sending:!0};k(e=>[...e,l]),O();let n=!y,{id:r,answer:a,createdAt:i,conversation:o}=await (null==(t=v.ai)?void 0:t.chat(e_,h,y,{...e,page:JSON.stringify(g),pageItems:JSON.stringify(j||[])}));w((null==o?void 0:o.id)||""),S(e=>[n?o||{}:null,...e].filter(e=>null!==e)),Object.assign(l,{id:r,answer:a,createdAt:i,conversationId:(null==o?void 0:o.id)||"",sending:!1}),a.effect&&(null==x||x(a.effect)),k(e=>[...e]),O()},D=async e=>{var t;await (null==(t=v.ai)?void 0:t.removeMessage(e)),k(t=>t.filter(t=>t.id!==e))},E=(t=new Date,l=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(n=new Date(t)).setDate(t.getDate()-1),r=[],a=[],i=[],o=[],C.forEach(e=>{let s=new Date(e.createdAt);if(l(s,t))r.push(e);else if(l(s,n))a.push(e);else s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()?i.push(e):o.push(e)}),[{title:"今天",items:r},{title:"昨天",items:a},{title:"本月内",items:i},{title:"很久以前",items:o}].filter(e=>e.items.length>0)),A=async()=>{try{var e,t;let l=await (null==(e=v.ai)?void 0:e.conversationList(e_,h));S(l||[]);let n=null==l?void 0:l.find(e=>e.isActived);if(n){w(n.id);let e=await (null==(t=v.ai)?void 0:t.messageList(n.id));k(e||[]),O()}}catch(e){console.error(e)}};return(0,c.useEffect)(()=>{A()},[v]),(0,c.useEffect)(()=>{O()},[]),(0,d.jsxs)(e$,{style:p,children:[(0,d.jsx)(eL,{title:"智能助理",extra:(0,d.jsxs)(ep.Space,{children:[(0,d.jsx)(ep.Tooltip,{title:"新对话",placement:"topRight",children:(0,d.jsx)("a",{onClick:N,children:(0,d.jsx)(eu,{type:"icon-chat-plus"})})}),(0,d.jsx)(ep.Dropdown,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,d.jsx)(eU,{children:E.map(e=>(0,d.jsxs)("div",{className:"group",children:[(0,d.jsx)("div",{className:"group-title",children:e.title}),(0,d.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,d.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,d.jsx)("a",{onClick:()=>R(e.id),children:e.name}),(0,d.jsx)("small",{children:(0,d.jsx)("a",{onClick:()=>T(e.id),children:(0,d.jsx)(ed.DeleteOutlined,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,d.jsx)("a",{children:(0,d.jsx)(ed.HistoryOutlined,{})})}),u]}),style:{width:"initial"}}),(0,d.jsxs)("div",{className:"body",children:[(0,d.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:I.length?(0,d.jsx)(eK,{ref:z,list:I,onDeleteMessage:D}):(0,d.jsx)(eG,{})}),0===I.length&&C.length>0&&(0,d.jsx)(ep.Card,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,d.jsx)("ul",{className:"conversation-list",children:C.slice(0,3).map(e=>(0,d.jsxs)("li",{children:[(0,d.jsxs)("a",{children:[(0,d.jsx)(ed.MessageOutlined,{}),e.name]}),(0,d.jsx)("small",{children:eN(e.createdAt)})]},e.id))})}),(0,d.jsx)(eM,{agentList:s,style:{padding:12},atItems:j,onUploading:null==v?void 0:v.upload,onSubmit:F,onRemoveAtItem:b})]})]})},eH=h().div`
|
|
421
421
|
flex: 1 1 auto;
|
|
422
422
|
display: flex;
|
|
423
423
|
align-items: center;
|
|
@@ -632,7 +632,7 @@
|
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
`,eK=(0,c.forwardRef)((e,t)=>{let{list:l,onDeleteMessage:n}=e,r=(0,c.useRef)(null),a=()=>{setTimeout(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},100)};return(0,c.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,d.jsx)(eJ,{className:"message-list beautified_scrollbar",ref:r,children:l.map(e=>{var t,l,r,a,i,o,s,c,u,p;return(0,d.jsxs)("div",{className:"msg",children:[(0,d.jsxs)("div",{className:"user-message",children:[(0,d.jsx)("div",{className:"msg-header",children:(0,d.jsx)("span",{children:eN(e.createdAt)})}),(0,d.jsxs)("div",{className:"msg-section",children:[(0,d.jsxs)(ep.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,d.jsx)(ep.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,d.jsx)(ep.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>n(e.id),children:(0,d.jsx)(ep.Tooltip,{title:"删除",children:(0,d.jsx)(ep.Button,{type:"link",size:"small",icon:(0,d.jsx)(ed.DeleteOutlined,{})})})})]}),(0,d.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(l=e.agents)?void 0:l.length)||(null==(r=e.atItems)?void 0:r.length)?(0,d.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,d.jsxs)(ep.Tag,{color:"processing",children:[(0,d.jsx)(eu,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(i=e.agents)?void 0:i.map(e=>(0,d.jsxs)(ep.Tag,{color:"blue",children:[(0,d.jsx)(eu,{type:"icon-at"})," ",e.name]},e.id)),JSON.parse(e
|
|
635
|
+
`,eK=(0,c.forwardRef)((e,t)=>{let{list:l,onDeleteMessage:n}=e,r=(0,c.useRef)(null),a=()=>{setTimeout(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},100)};return(0,c.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,d.jsx)(eJ,{className:"message-list beautified_scrollbar",ref:r,children:l.map(e=>{var t,l,r,a,i,o,s,c,u,p;return(0,d.jsxs)("div",{className:"msg",children:[(0,d.jsxs)("div",{className:"user-message",children:[(0,d.jsx)("div",{className:"msg-header",children:(0,d.jsx)("span",{children:eN(e.createdAt)})}),(0,d.jsxs)("div",{className:"msg-section",children:[(0,d.jsxs)(ep.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,d.jsx)(ep.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,d.jsx)(ep.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>n(e.id),children:(0,d.jsx)(ep.Tooltip,{title:"删除",children:(0,d.jsx)(ep.Button,{type:"link",size:"small",icon:(0,d.jsx)(ed.DeleteOutlined,{})})})})]}),(0,d.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(l=e.agents)?void 0:l.length)||(null==(r=e.atItems)?void 0:r.length)?(0,d.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,d.jsxs)(ep.Tag,{color:"processing",children:[(0,d.jsx)(eu,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(i=e.agents)?void 0:i.map(e=>(0,d.jsxs)(ep.Tag,{color:"blue",children:[(0,d.jsx)(eu,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{return JSON.parse(e||"[]")}catch(e){return[]}})(e.atItems).map(e=>(0,d.jsxs)(ep.Tag,{color:"blue",children:[(0,d.jsx)(eu,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,d.jsxs)("div",{className:"assistant-message",children:[(0,d.jsx)("div",{className:"msg-header",children:(0,d.jsxs)("span",{className:"msg-title",children:[(0,d.jsx)(ed.RobotOutlined,{})," 智能助理"]})}),(0,d.jsx)("div",{className:"msg-section",children:e.sending?(0,d.jsx)(ep.Skeleton,{active:!0}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"msg-content",children:(null==(o=e.answer)?void 0:o.answer)||""}),!!(null==(c=e.answer)||null==(s=c.plans)?void 0:s.length)&&(0,d.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,d.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,d.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,d.jsx)(ep.Tooltip,{title:e.description,children:(0,d.jsx)(ep.Tag,{color:"blue",children:e.name})},t))})]}),!!(null==(p=e.answer)||null==(u=p.extra)?void 0:u.length)&&(0,d.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,d.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,d.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,d.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,d.jsx)(ep.Tag,{color:"gold",children:e.element}),(0,d.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),eW=h().div`
|
|
636
636
|
display: flex;
|
|
637
637
|
flex-direction: column;
|
|
638
638
|
height: 100%;
|
package/package.json
CHANGED
|
@@ -125,7 +125,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
125
125
|
okText: "确认",
|
|
126
126
|
cancelText: "取消",
|
|
127
127
|
onOk: async () => {
|
|
128
|
-
await fetch.ai?.removeConversation(
|
|
128
|
+
await fetch.ai?.removeConversation(id);
|
|
129
129
|
setConversationList((list) => list.filter((i) => i.id !== id));
|
|
130
130
|
setMessageList((list) => list.filter((m) => m.conversationId !== id));
|
|
131
131
|
if (conversationId === id) {
|
|
@@ -140,7 +140,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
140
140
|
setConversationList((list) =>
|
|
141
141
|
list.map((i) => ({ ...i, isActived: i.id === id })),
|
|
142
142
|
);
|
|
143
|
-
const messages = await fetch.ai?.messageList(
|
|
143
|
+
const messages = await fetch.ai?.messageList(id);
|
|
144
144
|
setMessageList(messages || []);
|
|
145
145
|
scrollToBottom();
|
|
146
146
|
};
|
|
@@ -196,7 +196,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
const handleDeleteMessage = async (id: string) => {
|
|
199
|
-
await fetch.ai?.removeMessage(
|
|
199
|
+
await fetch.ai?.removeMessage(id);
|
|
200
200
|
setMessageList((list) => list.filter((i) => i.id !== id));
|
|
201
201
|
};
|
|
202
202
|
|
|
@@ -237,8 +237,6 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
237
237
|
if (active) {
|
|
238
238
|
setConversationId(active.id);
|
|
239
239
|
const messages = await fetch.ai?.messageList(
|
|
240
|
-
BIZ_TYPE,
|
|
241
|
-
pageId,
|
|
242
240
|
active.id,
|
|
243
241
|
);
|
|
244
242
|
setMessageList(messages || []);
|
|
@@ -635,6 +633,14 @@ const MessageList = forwardRef<
|
|
|
635
633
|
scrollToBottom,
|
|
636
634
|
}));
|
|
637
635
|
|
|
636
|
+
const parseAtItems = (atItems?: string | null) => {
|
|
637
|
+
try {
|
|
638
|
+
return JSON.parse(atItems || "[]");
|
|
639
|
+
} catch (error) {
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
638
644
|
return (
|
|
639
645
|
<MessageRoot className="message-list beautified_scrollbar" ref={ref}>
|
|
640
646
|
{list.map((msg) => (
|
|
@@ -678,7 +684,7 @@ const MessageList = forwardRef<
|
|
|
678
684
|
<IconFont type="icon-at" /> {a.name}
|
|
679
685
|
</Tag>
|
|
680
686
|
))}
|
|
681
|
-
{
|
|
687
|
+
{parseAtItems(msg.atItems).map((a: SchemaItemType) => (
|
|
682
688
|
<Tag key={a.id} color="blue">
|
|
683
689
|
<IconFont type="icon-number" /> {a.name}
|
|
684
690
|
</Tag>
|
package/src/components/typing.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type PageItemEffectType = {
|
|
|
13
13
|
position: "before" | "after" | "replace" | "insert";
|
|
14
14
|
insertSlot?: string | null;
|
|
15
15
|
pageItem: PageSchema;
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
export type ChatResponseAnswerEffectType = {
|
|
19
19
|
datasets?: DataSetType[] | null;
|
|
@@ -68,27 +68,15 @@ export type FetchType = {
|
|
|
68
68
|
bizType: string,
|
|
69
69
|
bizId: string,
|
|
70
70
|
conversationId: string | null,
|
|
71
|
-
request: ChatRequestType
|
|
71
|
+
request: ChatRequestType,
|
|
72
72
|
) => Promise<ChatResponseType>;
|
|
73
73
|
conversationList: (
|
|
74
|
-
bizType: string,
|
|
75
|
-
bizId: string
|
|
76
|
-
) => Promise<ChatConversationType[]>;
|
|
77
|
-
messageList: (
|
|
78
74
|
bizType: string,
|
|
79
75
|
bizId: string,
|
|
80
|
-
|
|
81
|
-
) => Promise<ChatMessageType[]>;
|
|
82
|
-
removeConversation: (
|
|
83
|
-
|
|
84
|
-
bizId: string,
|
|
85
|
-
conversationId: string
|
|
86
|
-
) => Promise<boolean>;
|
|
87
|
-
removeMessage: (
|
|
88
|
-
bizType: string,
|
|
89
|
-
bizId: string,
|
|
90
|
-
messageId: string
|
|
91
|
-
) => Promise<boolean>;
|
|
76
|
+
) => Promise<ChatConversationType[]>;
|
|
77
|
+
messageList: (conversationId: string, prevId?: string) => Promise<ChatMessageType[]>;
|
|
78
|
+
removeConversation: (conversationId: string) => Promise<boolean>;
|
|
79
|
+
removeMessage: (messageId: string) => Promise<boolean>;
|
|
92
80
|
};
|
|
93
81
|
dataset?: (dataSetId: string, params: Record<string, any>) => Promise<any>;
|
|
94
82
|
};
|
|
@@ -196,15 +184,22 @@ export type EnvType = {
|
|
|
196
184
|
local: Record<string, Record<string, any>>;
|
|
197
185
|
};
|
|
198
186
|
|
|
199
|
-
export type CallbackType = (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
187
|
+
export type CallbackType = (
|
|
188
|
+
refresh?: boolean,
|
|
189
|
+
args?: any,
|
|
190
|
+
) =>
|
|
191
|
+
| {
|
|
192
|
+
target: Omit<SchemaItemType, "children">;
|
|
193
|
+
data: any;
|
|
194
|
+
}
|
|
195
|
+
| null
|
|
196
|
+
| undefined
|
|
197
|
+
| void;
|
|
203
198
|
|
|
204
199
|
export type CallbacksType = Record<string, CallbackType>;
|
|
205
200
|
|
|
206
201
|
export type DatasetSelectorFunction = (
|
|
207
|
-
onSelect: (dataset: DataSetType) => void
|
|
202
|
+
onSelect: (dataset: DataSetType) => void,
|
|
208
203
|
) => React.ReactNode;
|
|
209
204
|
|
|
210
205
|
export type DatasetAddFunction = (
|
package/src/example.tsx
CHANGED
|
@@ -185,15 +185,15 @@ export const Example: React.FC = () => {
|
|
|
185
185
|
}),
|
|
186
186
|
conversationList: async (bizType, bizId) =>
|
|
187
187
|
Promise.resolve(example.conversationList),
|
|
188
|
-
messageList: async (
|
|
188
|
+
messageList: async (conversationId, prevId) =>
|
|
189
189
|
Promise.resolve(
|
|
190
190
|
example.messageList.filter(
|
|
191
191
|
(m) => m.conversationId === conversationId,
|
|
192
192
|
),
|
|
193
193
|
),
|
|
194
|
-
removeConversation: async (
|
|
194
|
+
removeConversation: async (conversationId) =>
|
|
195
195
|
Promise.resolve(true),
|
|
196
|
-
removeMessage: async (
|
|
196
|
+
removeMessage: async (messageId) =>
|
|
197
197
|
Promise.resolve(true),
|
|
198
198
|
},
|
|
199
199
|
upload: async (file) =>
|