bi-sdk-react 0.0.18 → 0.0.19
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
|
@@ -377,7 +377,7 @@ import*as e from"react";import t,{css as l}from"styled-components";import{AlignC
|
|
|
377
377
|
.conversation-list li small {
|
|
378
378
|
white-space: nowrap;
|
|
379
379
|
}
|
|
380
|
-
`,t$=[],tF="bi-design",tY=e=>{let t,l,n,r,a,i,o,{agentList:s=t$,headExtra:d,style:u={},onEffect:p}=e,{pageId:x,
|
|
380
|
+
`,t$=[],tF="bi-design",tY=e=>{let t,l,n,r,a,i,o,{agentList:s=t$,headExtra:d,style:u={},onEffect:p}=e,{pageId:x,schema:m,fetch:h,atItems:g,onRemoveAtItem:v}=(0,eO.useContext)(tu);if(!h)return null;let[j,b]=(0,eO.useState)(null),[w,C]=(0,eO.useState)([]),[S,z]=(0,eO.useState)([]),k=eO.default.useRef(null),I=()=>{setTimeout(()=>{k.current&&k.current.scrollToBottom()},100)},N=()=>{b(null),z([])},O=async e=>{q.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=h.ai)?void 0:t.removeConversation(tF,x,e)),C(t=>t.filter(t=>t.id!==e)),z(t=>t.filter(t=>t.conversationId!==e)),j===e&&N()}})},T=async e=>{var t;b(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),z(await (null==(t=h.ai)?void 0:t.messageList(tF,x,e))||[])},E=async e=>{var t;let l={id:ex(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:g,sending:!0};z(e=>[...e,l]),I();let n=!j,{id:r,answer:a,createdAt:i,conversation:o}=await (null==(t=h.ai)?void 0:t.chat(tF,x,j,{...e,page:m,pageItems:g}));b((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)),z(e=>[...e]),I()},A=async e=>{var t;await (null==(t=h.ai)?void 0:t.removeMessage(tF,x,e)),z(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(tF,x));C(l||[]);let n=null==l?void 0:l.find(e=>e.isActived);if(n){b(n.id);let e=await (null==(t=h.ai)?void 0:t.messageList(tF,x,n.id));z(e||[])}}catch(e){console.error(e)}};return(0,eO.useEffect)(()=>{B()},[h]),(0,eO.useEffect)(()=>{I()},[]),(0,eN.jsxs)(tM,{style:u,children:[(0,eN.jsx)(tP,{title:"智能助理",extra:(0,eN.jsxs)(en,{children:[(0,eN.jsx)(es,{title:"新对话",placement:"topRight",children:(0,eN.jsx)("a",{onClick:N,children:(0,eN.jsx)(tS,{type:"icon-chat-plus"})})}),(0,eN.jsx)(W,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,eN.jsx)(tW,{children:D.map(e=>(0,eN.jsxs)("div",{className:"group",children:[(0,eN.jsx)("div",{className:"group-title",children:e.title}),(0,eN.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,eN.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,eN.jsx)("a",{onClick:()=>T(e.id),children:e.name}),(0,eN.jsx)("small",{children:(0,eN.jsx)("a",{onClick:()=>O(e.id),children:(0,eN.jsx)(c,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,eN.jsx)("a",{children:(0,eN.jsx)(f,{})})}),d]}),style:{width:"initial"}}),(0,eN.jsxs)("div",{className:"body",children:[(0,eN.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:S.length?(0,eN.jsx)(tJ,{ref:k,list:S,onDeleteMessage:A}):(0,eN.jsx)(tG,{})}),0===S.length&&w.length>0&&(0,eN.jsx)(P,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,eN.jsx)("ul",{className:"conversation-list",children:w.slice(0,3).map(e=>(0,eN.jsxs)("li",{children:[(0,eN.jsxs)("a",{children:[(0,eN.jsx)(y,{}),e.name]}),(0,eN.jsx)("small",{children:tN(e.createdAt)})]},e.id))})}),(0,eN.jsx)(tL,{agentList:s,style:{padding:12},atItems:g,onUploading:null==h?void 0:h.upload,onSubmit:E,onRemoveAtItem:v})]})]})},tH=t.div`
|
|
381
381
|
flex: 1 1 auto;
|
|
382
382
|
display: flex;
|
|
383
383
|
align-items: center;
|
|
@@ -377,7 +377,7 @@
|
|
|
377
377
|
.conversation-list li small {
|
|
378
378
|
white-space: nowrap;
|
|
379
379
|
}
|
|
380
|
-
`,e$=[],eY="bi-design",e_=e=>{let t,l,n,r,a,i,o,{agentList:s=e$,headExtra:c,style:u={},onEffect:x}=e,{pageId:h,
|
|
380
|
+
`,e$=[],eY="bi-design",e_=e=>{let t,l,n,r,a,i,o,{agentList:s=e$,headExtra:c,style:u={},onEffect:x}=e,{pageId:h,schema:f,fetch:g,atItems:v,onRemoveAtItem:y}=(0,p.useContext)(eo);if(!g)return null;let[j,b]=(0,p.useState)(null),[w,C]=(0,p.useState)([]),[S,I]=(0,p.useState)([]),z=m().useRef(null),k=()=>{setTimeout(()=>{z.current&&z.current.scrollToBottom()},100)},O=()=>{b(null),I([])},N=async e=>{ej.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=g.ai)?void 0:t.removeConversation(eY,h,e)),C(t=>t.filter(t=>t.id!==e)),I(t=>t.filter(t=>t.conversationId!==e)),j===e&&O()}})},T=async e=>{var t;b(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),I(await (null==(t=g.ai)?void 0:t.messageList(eY,h,e))||[])},R=async e=>{var t;let l={id:ek(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:v,sending:!0};I(e=>[...e,l]),k();let n=!j,{id:r,answer:a,createdAt:i,conversation:o}=await (null==(t=g.ai)?void 0:t.chat(eY,h,j,{...e,page:f,pageItems:v}));b((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==x||x(a.effect)),I(e=>[...e]),k()},F=async e=>{var t;await (null==(t=g.ai)?void 0:t.removeMessage(eY,h,e)),I(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)),A=async()=>{try{var e,t;let l=await (null==(e=g.ai)?void 0:e.conversationList(eY,h));C(l||[]);let n=null==l?void 0:l.find(e=>e.isActived);if(n){b(n.id);let e=await (null==(t=g.ai)?void 0:t.messageList(eY,h,n.id));I(e||[])}}catch(e){console.error(e)}};return(0,p.useEffect)(()=>{A()},[g]),(0,p.useEffect)(()=>{k()},[]),(0,d.jsxs)(eP,{style:u,children:[(0,d.jsx)(eM,{title:"智能助理",extra:(0,d.jsxs)(ej.Space,{children:[(0,d.jsx)(ej.Tooltip,{title:"新对话",placement:"topRight",children:(0,d.jsx)("a",{onClick:O,children:(0,d.jsx)(ew,{type:"icon-chat-plus"})})}),(0,d.jsx)(ej.Dropdown,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,d.jsx)(eG,{children:D.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:()=>T(e.id),children:e.name}),(0,d.jsx)("small",{children:(0,d.jsx)("a",{onClick:()=>N(e.id),children:(0,d.jsx)(ey.DeleteOutlined,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,d.jsx)("a",{children:(0,d.jsx)(ey.HistoryOutlined,{})})}),c]}),style:{width:"initial"}}),(0,d.jsxs)("div",{className:"body",children:[(0,d.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:S.length?(0,d.jsx)(eK,{ref:z,list:S,onDeleteMessage:F}):(0,d.jsx)(eq,{})}),0===S.length&&w.length>0&&(0,d.jsx)(ej.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:w.slice(0,3).map(e=>(0,d.jsxs)("li",{children:[(0,d.jsxs)("a",{children:[(0,d.jsx)(ey.MessageOutlined,{}),e.name]}),(0,d.jsx)("small",{children:eO(e.createdAt)})]},e.id))})}),(0,d.jsx)(eB,{agentList:s,style:{padding:12},atItems:v,onUploading:null==g?void 0:g.upload,onSubmit:R,onRemoveAtItem:y})]})]})},eH=h().div`
|
|
381
381
|
flex: 1 1 auto;
|
|
382
382
|
display: flex;
|
|
383
383
|
align-items: center;
|
package/package.json
CHANGED
|
@@ -95,7 +95,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
95
95
|
style = {},
|
|
96
96
|
onEffect,
|
|
97
97
|
}) => {
|
|
98
|
-
const { pageId, fetch, atItems, onRemoveAtItem } = useContext(PageContext);
|
|
98
|
+
const { pageId, schema, fetch, atItems, onRemoveAtItem } = useContext(PageContext);
|
|
99
99
|
if (!fetch) return null;
|
|
100
100
|
const [conversationId, setConversationId] = useState<string | null>(null);
|
|
101
101
|
const [conversationList, setConversationList] = useState<
|
|
@@ -166,6 +166,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
166
166
|
conversationId,
|
|
167
167
|
{
|
|
168
168
|
...data,
|
|
169
|
+
page: schema,
|
|
169
170
|
pageItems: atItems,
|
|
170
171
|
}
|
|
171
172
|
)!;
|