@zero-library/chat-agent 2.1.0 → 2.1.2

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() {
@@ -729,6 +739,7 @@ function createChatStore() {
729
739
  } finally {
730
740
  }
731
741
  config.hooks?.onAfterInitMessages?.(conversation.messages[conversationId].message);
742
+ config.hooks?.onAfterInit?.();
732
743
  }
733
744
  };
734
745
  const pickReceiver = () => {
@@ -1027,7 +1038,7 @@ var MessageAIRender_default = ({ message: message3, placement }) => {
1027
1038
  }
1028
1039
  ) });
1029
1040
  };
1030
- var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: true } }) => {
1041
+ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, agent: true, other: true } }) => {
1031
1042
  const chatStore = useChatStore();
1032
1043
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1033
1044
  const conversationState = valtio.useSnapshot(chatStore.conversation);
@@ -1172,8 +1183,22 @@ var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: tru
1172
1183
  };
1173
1184
  });
1174
1185
  }, [chatMessage?.message]);
1186
+ const firstMessageRecord = react.useMemo(() => {
1187
+ const isExist = common.shouldRender(firstMessage);
1188
+ return isExist ? [
1189
+ {
1190
+ key: "firstMessage",
1191
+ content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: firstMessage }),
1192
+ placement: "end"
1193
+ // avatar: { style: { visibility: 'hidden' } }
1194
+ }
1195
+ ] : [];
1196
+ }, [firstMessage]);
1175
1197
  const bubbleListItems = react.useMemo(() => {
1176
1198
  const list = [];
1199
+ if (firstMessageRecord.length > 0) {
1200
+ list.push(...firstMessageRecord);
1201
+ }
1177
1202
  if (chatRecords.length > 0) {
1178
1203
  list.push(...chatRecords, ...questionList);
1179
1204
  }
@@ -1181,7 +1206,7 @@ var BubbleListItems_default = ({ avatar = { user: false, agent: true, other: tru
1181
1206
  return list;
1182
1207
  }
1183
1208
  return [...placeholderNode];
1184
- }, [chatRecords, questionList, placeholderNode]);
1209
+ }, [chatRecords, questionList, placeholderNode, firstMessageRecord]);
1185
1210
  const listRef = react.useRef(null);
1186
1211
  const autoScrollRef = react.useRef(true);
1187
1212
  const handleScroll = (el) => {
@@ -1804,7 +1829,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1804
1829
  return;
1805
1830
  }
1806
1831
  if (config?.receiverId && config?.receiverType === 3) {
1807
- chatStore.switchAgentConversation(config.receiverId, config.conversationStrategy);
1832
+ chatStore.switchAgentConversation(String(config.receiverId), config.conversationStrategy);
1808
1833
  }
1809
1834
  }, [config]);
1810
1835
  react.useEffect(() => {
@@ -1820,6 +1845,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1820
1845
  chatStore.setHooks(hooks);
1821
1846
  }, [hooks]);
1822
1847
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1848
+ valtio.useSnapshot(chatStore.conversation);
1823
1849
  const configState = valtio.useSnapshot(chatStore.config);
1824
1850
  react.useImperativeHandle(
1825
1851
  ref,
@@ -1853,10 +1879,13 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1853
1879
  clientHeartbeat: false,
1854
1880
  reconnectInterval: 1e4
1855
1881
  });
1882
+ react.useEffect(() => {
1883
+ configState.hooks?.onBeforeInit?.();
1884
+ }, []);
1856
1885
  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
1886
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.globalHeader, DefaultComponent: ChatHeader_default }),
1858
1887
  /* @__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, {}) }),
1888
+ /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.leftPanel }),
1860
1889
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.conversationList, DefaultComponent: ConversationListPanel_default }),
1861
1890
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Splitter, { className: "flex-1", onResize: setSplitterSizes, children: [
1862
1891
  /* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, min: 600, size: sizes[0], children: hasPreView && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -1911,17 +1940,17 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1911
1940
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.chatHeader, DefaultComponent: ChatHeader_default }),
1912
1941
  /* @__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
1942
  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
1943
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
1944
+ /* @__PURE__ */ jsxRuntime.jsx(
1945
+ common.RenderWrapper,
1946
+ {
1947
+ control: configState.layout.senderHeader,
1948
+ DefaultComponent: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles_module_default4.nsChatSenderHeader, children: [
1949
+ "\u6211\u662F ",
1950
+ receiverState.active.name
1951
+ ] })
1952
+ }
1953
+ ),
1925
1954
  /* @__PURE__ */ jsxRuntime.jsx(
1926
1955
  common.RenderWrapper,
1927
1956
  {
@@ -1938,7 +1967,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1938
1967
  }
1939
1968
  )
1940
1969
  ] }),
1941
- /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.senderFooter, DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) })
1970
+ /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.senderFooter })
1942
1971
  ] }) })
1943
1972
  ] }) })
1944
1973
  ] })