@zero-library/chat-agent 2.1.0 → 2.1.1

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/index.cjs.js CHANGED
@@ -323,7 +323,7 @@ var conversationDelete = (conversationId) => {
323
323
  return common.request.delete("/agent/conversation", { conversationId });
324
324
  };
325
325
  var conversationRecentQuery = (params) => {
326
- return common.request.get("/lolr/conversation/recent", { params });
326
+ return common.request.get("/lolr/conversation/recent", params);
327
327
  };
328
328
  var conversationMessagesQuery = (params) => {
329
329
  return common.request.get("/lolr/conversation/message", params);
@@ -362,6 +362,7 @@ var defaultAgentLayout = {
362
362
  conversationList: true,
363
363
  preview: true,
364
364
  messageList: true,
365
+ firstMessage: false,
365
366
  senderHeader: false,
366
367
  sender: true,
367
368
  senderPrompts: true,
@@ -375,12 +376,21 @@ var defaultExpertLayout = {
375
376
  conversationList: false,
376
377
  preview: false,
377
378
  messageList: true,
379
+ firstMessage: false,
378
380
  senderHeader: false,
379
381
  sender: true,
380
382
  senderPrompts: false,
381
383
  senderFooter: false,
382
384
  globalHeader: false,
383
- chatHeader: false,
385
+ chatHeader: {
386
+ props: {
387
+ title: true,
388
+ closeBtn: false,
389
+ newConversationBtn: false,
390
+ agentCharacter: false,
391
+ conversationListBtn: false
392
+ }
393
+ },
384
394
  disclaimerNotice: false
385
395
  };
386
396
  function createChatStore() {
@@ -647,7 +657,7 @@ function createChatStore() {
647
657
  const resolveConversationId = async (receiverId, strategy = 2) => {
648
658
  if (strategy === 1) {
649
659
  const { data } = await conversationRecentQuery({
650
- receiverId,
660
+ receiverId: String(receiverId),
651
661
  receiverType: 3,
652
662
  businessId: config.params.businessId,
653
663
  businessType: config.params.businessType
@@ -655,7 +665,7 @@ function createChatStore() {
655
665
  return data;
656
666
  } else {
657
667
  const { data } = await conversationCreate({
658
- receiverId,
668
+ receiverId: String(receiverId),
659
669
  receiverType: 3,
660
670
  businessId: config.params.businessId,
661
671
  businessType: config.params.businessType,
@@ -1027,7 +1037,7 @@ var MessageAIRender_default = ({ message: message3, placement }) => {
1027
1037
  }
1028
1038
  ) });
1029
1039
  };
1030
- var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: true } }) => {
1040
+ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, agent: true, other: true } }) => {
1031
1041
  const chatStore = useChatStore();
1032
1042
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1033
1043
  const conversationState = valtio.useSnapshot(chatStore.conversation);
@@ -1172,8 +1182,22 @@ var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: tru
1172
1182
  };
1173
1183
  });
1174
1184
  }, [chatMessage?.message]);
1185
+ const firstMessageRecord = react.useMemo(() => {
1186
+ const isExist = common.shouldRender(firstMessage);
1187
+ return isExist ? [
1188
+ {
1189
+ key: "firstMessage",
1190
+ content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: firstMessage }),
1191
+ placement: "end"
1192
+ // avatar: { style: { visibility: 'hidden' } }
1193
+ }
1194
+ ] : [];
1195
+ }, [firstMessage]);
1175
1196
  const bubbleListItems = react.useMemo(() => {
1176
1197
  const list = [];
1198
+ if (firstMessageRecord.length > 0) {
1199
+ list.push(...firstMessageRecord);
1200
+ }
1177
1201
  if (chatRecords.length > 0) {
1178
1202
  list.push(...chatRecords, ...questionList);
1179
1203
  }
@@ -1181,7 +1205,7 @@ var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: tru
1181
1205
  return list;
1182
1206
  }
1183
1207
  return [...placeholderNode];
1184
- }, [chatRecords, questionList, placeholderNode]);
1208
+ }, [chatRecords, questionList, placeholderNode, firstMessageRecord]);
1185
1209
  const listRef = react.useRef(null);
1186
1210
  const autoScrollRef = react.useRef(true);
1187
1211
  const handleScroll = (el) => {
@@ -1820,6 +1844,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1820
1844
  chatStore.setHooks(hooks);
1821
1845
  }, [hooks]);
1822
1846
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1847
+ valtio.useSnapshot(chatStore.conversation);
1823
1848
  const configState = valtio.useSnapshot(chatStore.config);
1824
1849
  react.useImperativeHandle(
1825
1850
  ref,
@@ -1853,10 +1878,13 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1853
1878
  clientHeartbeat: false,
1854
1879
  reconnectInterval: 1e4
1855
1880
  });
1881
+ react.useEffect(() => {
1882
+ configState.hooks?.onBeforeInit?.();
1883
+ }, []);
1856
1884
  return /* @__PURE__ */ jsxRuntime.jsx(x.XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsxRuntime.jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: receiverState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames7__default.default(styles_module_default4.nsChatLayout, "height-full"), children: [
1857
1885
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.globalHeader, DefaultComponent: ChatHeader_default }),
1858
1886
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "full-scroll", children: [
1859
- /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.leftPanel, DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) }),
1887
+ /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.leftPanel }),
1860
1888
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.conversationList, DefaultComponent: ConversationListPanel_default }),
1861
1889
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Splitter, { className: "flex-1", onResize: setSplitterSizes, children: [
1862
1890
  /* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, min: 600, size: sizes[0], children: hasPreView && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -1911,17 +1939,17 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1911
1939
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.chatHeader, DefaultComponent: ChatHeader_default }),
1912
1940
  /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, className: classNames7__default.default("full-scroll"), children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "center", vertical: true, gap: 24, className: classNames7__default.default("height-full p-t-8 p-b-8", styles_module_default2.nsBodyWidth), children: [
1913
1941
  common.shouldRender(configState.layout.messageList) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.messageList, DefaultComponent: BubbleListItems_default }) }),
1914
- /* @__PURE__ */ jsxRuntime.jsx(
1915
- common.RenderWrapper,
1916
- {
1917
- control: configState.layout.senderHeader,
1918
- DefaultComponent: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles_module_default4.nsChatSenderHeader, children: [
1919
- "\u6211\u662F ",
1920
- receiverState.active.name
1921
- ] })
1922
- }
1923
- ),
1924
1942
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
1943
+ /* @__PURE__ */ jsxRuntime.jsx(
1944
+ common.RenderWrapper,
1945
+ {
1946
+ control: configState.layout.senderHeader,
1947
+ DefaultComponent: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles_module_default4.nsChatSenderHeader, children: [
1948
+ "\u6211\u662F ",
1949
+ receiverState.active.name
1950
+ ] })
1951
+ }
1952
+ ),
1925
1953
  /* @__PURE__ */ jsxRuntime.jsx(
1926
1954
  common.RenderWrapper,
1927
1955
  {
@@ -1938,7 +1966,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1938
1966
  }
1939
1967
  )
1940
1968
  ] }),
1941
- /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.senderFooter, DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) })
1969
+ /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.senderFooter })
1942
1970
  ] }) })
1943
1971
  ] }) })
1944
1972
  ] })