@zero-library/chat-agent 2.3.10 → 2.3.12

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
@@ -187,7 +187,7 @@ var init_MdEdit = __esm({
187
187
  setValue(data.content);
188
188
  }, [data.content]);
189
189
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles_module_default.mdEdit, children: [
190
- /* @__PURE__ */ jsxRuntime.jsx(common.MarkdownEditor, { disabled: loading, value, onChange: setValue, showToolbar: false }),
190
+ /* @__PURE__ */ jsxRuntime.jsx(common.MarkdownEditor, { disabled: loading, value, onChange: setValue, fixedToolbar: false, floatToolbar: false }),
191
191
  !loading && /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { justify: "end", className: "m-t-16", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { color: "primary", variant: "outlined", onClick: onOk, children: btnText }) })
192
192
  ] });
193
193
  };
@@ -427,11 +427,11 @@ var createChatService = (request) => {
427
427
  const labelItemDelete = (id) => {
428
428
  return request.delete("/lolr/label/item", { id });
429
429
  };
430
- const labelsQuery = (agentId, params) => {
431
- return request.get("/lolr/label", { agentId, ...params });
430
+ const labelsQuery = (params) => {
431
+ return request.get("/lolr/label", params);
432
432
  };
433
- const labelItemsQuery = (agentId, params) => {
434
- return request.get("/lolr/label/item", { ...params, agentId });
433
+ const labelItemsQuery = (params) => {
434
+ return request.get("/lolr/label/item", params);
435
435
  };
436
436
  const labelItemTop = (params) => {
437
437
  return request.put("/lolr/label/item/top", params);
@@ -2125,6 +2125,13 @@ var ChatSender_default = react.forwardRef(
2125
2125
  onSend();
2126
2126
  }
2127
2127
  };
2128
+ const isFocusedRef = react.useRef(false);
2129
+ react.useEffect(() => {
2130
+ if (!content) return;
2131
+ if (!isFocusedRef.current) {
2132
+ senderRef.current?.focus({ cursor: "end" });
2133
+ }
2134
+ }, [content]);
2128
2135
  react.useImperativeHandle(
2129
2136
  ref,
2130
2137
  () => ({
@@ -2143,7 +2150,13 @@ var ChatSender_default = react.forwardRef(
2143
2150
  header: senderHeader,
2144
2151
  onSubmit,
2145
2152
  onChange: setInputValue,
2146
- onFocus,
2153
+ onFocus: () => {
2154
+ isFocusedRef.current = true;
2155
+ onFocus?.();
2156
+ },
2157
+ onBlur: () => {
2158
+ isFocusedRef.current = false;
2159
+ },
2147
2160
  autoSize: { minRows: 2, maxRows: 6 },
2148
2161
  onCancel,
2149
2162
  footer: ({ components }) => {
@@ -2275,7 +2288,6 @@ var styles_module_default4 = {
2275
2288
  quickAskItemTitle: "styles_module_quickAskItemTitle",
2276
2289
  quickAskItemActions: "styles_module_quickAskItemActions"
2277
2290
  };
2278
- var ALL = "all";
2279
2291
  var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2280
2292
  const { message: message2 } = antd.App.useApp();
2281
2293
  const chatStore = useChatStore();
@@ -2283,39 +2295,43 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2283
2295
  const receiverState = valtio.useSnapshot(chatStore.receiver);
2284
2296
  const [searchText, setSearchText, getSearchText] = common.useRefState("");
2285
2297
  const [searchExpanded, setSearchExpanded] = react.useState(false);
2286
- const [activeTab, setActiveTab, getActiveTab] = common.useRefState({});
2298
+ const [activeTab, setActiveTab, getActiveTab] = common.useRefState("");
2287
2299
  const [categories, setCategories] = react.useState([]);
2288
2300
  const [items, setItems] = react.useState([]);
2289
2301
  const [editModalOpen, setEditModalOpen] = react.useState(false);
2290
2302
  const [editingItem, setEditingItem] = react.useState();
2291
2303
  const fetchCategories = async () => {
2292
2304
  try {
2293
- const res = await configState.services.request?.labelsQuery?.(receiverState.active?.id, { pageNo: 1, pageSize: 1e3 });
2305
+ const res = await configState.services.request?.labelsQuery?.({
2306
+ agentId: receiverState.active?.id,
2307
+ businessData: configState.params.businessData,
2308
+ pageNo: 1,
2309
+ pageSize: 1e3
2310
+ });
2294
2311
  if (res?.data) {
2295
2312
  setCategories(res.data?.items);
2313
+ if (!activeTab && res.data?.items?.length) {
2314
+ setActiveTab(res.data.items[0].id);
2315
+ }
2296
2316
  }
2297
2317
  } catch (err) {
2298
2318
  }
2299
2319
  };
2300
2320
  const tabsItems = react.useMemo(
2301
- () => [
2302
- {
2303
- key: ALL,
2304
- label: "\u5168\u90E8"
2305
- },
2306
- ...categories.map((item) => ({
2307
- key: item.id,
2308
- label: item.labelName
2309
- }))
2310
- ],
2321
+ () => categories.map((item) => ({
2322
+ key: item.id,
2323
+ label: item.labelName
2324
+ })),
2311
2325
  [categories]
2312
2326
  );
2313
2327
  const [loading, setLoading] = react.useState(false);
2314
2328
  const fetchItems = common.useDebounce(async () => {
2329
+ if (!getActiveTab()) return;
2315
2330
  try {
2316
2331
  setLoading(true);
2317
- const res = await configState.services.request?.labelItemsQuery?.(receiverState.active?.id, {
2318
- labelId: getActiveTab().id,
2332
+ const res = await configState.services.request?.labelItemsQuery?.({
2333
+ agentId: receiverState.active?.id,
2334
+ labelId: getActiveTab(),
2319
2335
  keyword: getSearchText()
2320
2336
  });
2321
2337
  if (res?.data) {
@@ -2325,10 +2341,12 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2325
2341
  setLoading(false);
2326
2342
  }
2327
2343
  });
2344
+ react.useEffect(() => {
2345
+ fetchItems();
2346
+ }, [activeTab]);
2328
2347
  react.useEffect(() => {
2329
2348
  if (receiverState.active?.id) {
2330
2349
  fetchCategories();
2331
- fetchItems();
2332
2350
  }
2333
2351
  }, [receiverState.active?.id]);
2334
2352
  const [updateLoading, setUpdateLoading] = react.useState(false);
@@ -2338,9 +2356,7 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2338
2356
  await configState.services.request?.labelItemUpdate?.(receiverState.active?.id, values);
2339
2357
  setEditModalOpen(false);
2340
2358
  message2.success("\u4FDD\u5B58\u6210\u529F");
2341
- if (!getActiveTab().id || values.labelName === getActiveTab().labelName) {
2342
- fetchItems();
2343
- }
2359
+ fetchItems();
2344
2360
  fetchCategories();
2345
2361
  } finally {
2346
2362
  setUpdateLoading(false);
@@ -2371,9 +2387,10 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2371
2387
  if (canProceed === false) {
2372
2388
  return;
2373
2389
  }
2374
- chatStore.setContent(item.content);
2390
+ chatStore.setContent(`#${item.title}# `);
2375
2391
  chatStore.setContentParams({
2376
- use_template: 1
2392
+ capacityId: item.id,
2393
+ capacityTitle: item.title
2377
2394
  });
2378
2395
  };
2379
2396
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -2391,11 +2408,10 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2391
2408
  children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: styles_module_default4.quickAskPanel, children: [
2392
2409
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 12, className: "p-16", vertical: true, children: [
2393
2410
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, children: [
2394
- !searchExpanded && /* @__PURE__ */ jsxRuntime.jsx(
2411
+ !searchExpanded ? /* @__PURE__ */ jsxRuntime.jsx(
2395
2412
  antd.Button,
2396
2413
  {
2397
2414
  type: "dashed",
2398
- block: true,
2399
2415
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
2400
2416
  className: "flex-1",
2401
2417
  onClick: () => {
@@ -2404,6 +2420,20 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2404
2420
  },
2405
2421
  children: "\u65B0\u589E\u80FD\u529B\u6A21\u677F"
2406
2422
  }
2423
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
2424
+ antd.Button,
2425
+ {
2426
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
2427
+ onClick: () => {
2428
+ if (getSearchText()) {
2429
+ setSearchText("");
2430
+ fetchItems();
2431
+ }
2432
+ setSearchExpanded(false);
2433
+ setEditingItem(null);
2434
+ setEditModalOpen(true);
2435
+ }
2436
+ }
2407
2437
  ),
2408
2438
  searchExpanded ? /* @__PURE__ */ jsxRuntime.jsx(
2409
2439
  antd.Input,
@@ -2417,25 +2447,11 @@ var QuickAskPanelDrawer_default = ({ open, onClose }) => {
2417
2447
  fetchItems();
2418
2448
  },
2419
2449
  className: "flex-1",
2420
- allowClear: true,
2421
- onBlur: () => setSearchExpanded(false)
2450
+ allowClear: true
2422
2451
  }
2423
2452
  ) : /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { icon: /* @__PURE__ */ jsxRuntime.jsx(icons.SearchOutlined, {}), onClick: () => setSearchExpanded(true) })
2424
2453
  ] }),
2425
- /* @__PURE__ */ jsxRuntime.jsx(
2426
- antd.Tabs,
2427
- {
2428
- className: styles_module_default4.tagContainer,
2429
- activeKey: activeTab.id ? activeTab.id : ALL,
2430
- onChange: (key) => {
2431
- setActiveTab(key === ALL ? {} : categories.find((c) => c.id === key));
2432
- fetchItems();
2433
- },
2434
- tabPosition: "top",
2435
- items: tabsItems,
2436
- size: "small"
2437
- }
2438
- )
2454
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Tabs, { className: styles_module_default4.tagContainer, activeKey: activeTab, onChange: setActiveTab, tabPosition: "top", items: tabsItems, size: "small" })
2439
2455
  ] }),
2440
2456
  /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, wrapperClassName: "full-spin", tip: "\u52A0\u8F7D\u4E2D...", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, gap: 8, className: "height-full scroll-fade-in p-16 p-t-0", children: items.length ? items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 4, align: "start", className: styles_module_default4.quickAskItem, onClick: () => onSelectItem(item), children: [
2441
2457
  /* @__PURE__ */ jsxRuntime.jsx(icons.FileTextOutlined, { className: styles_module_default4.quickAskItemIcon }),