@zero-library/chat-copilot 3.1.22 → 3.1.24

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
@@ -1198,9 +1198,10 @@ function createChatStore() {
1198
1198
  /** 智能体加载状态 */
1199
1199
  loading: false
1200
1200
  });
1201
- const setAgentModel = (model) => {
1202
- agent.model = { ...agent.model, ...model };
1203
- config.hooks?.onAfterSwitchModel?.(model);
1201
+ const setAgentModel = (updater) => {
1202
+ const nextPatch = typeof updater === "function" ? updater(agent.model) : updater;
1203
+ agent.model = { ...agent.model, ...nextPatch };
1204
+ config.hooks?.onAfterSwitchModel?.(agent.model);
1204
1205
  };
1205
1206
  const getUserInput = async (agentId) => {
1206
1207
  agent.loading = true;
@@ -1297,6 +1298,7 @@ function createChatStore() {
1297
1298
  };
1298
1299
  const initConversation = async (config2) => {
1299
1300
  await getConversations(config2.agent.id);
1301
+ await getConversationFavorite();
1300
1302
  if (config2?.conversationId) {
1301
1303
  switchConversation(config2.conversationId);
1302
1304
  } else {
@@ -2272,10 +2274,11 @@ window._iconfont_svg_string_5021436 = '<svg><symbol id="icon-Ollama" viewBox="0
2272
2274
  // src/components/IconFont/index.ts
2273
2275
  var IconFont = icons.createFromIconfontCN({});
2274
2276
  var IconFont_default = IconFont;
2275
- var ConversationFavoritesBtn_default = ({ icon, ...rest }) => {
2277
+ var ConversationFavoritesBtn_default = ({ icon, disabled, ...rest }) => {
2276
2278
  const chatStore = useChatStore();
2277
2279
  const conversationsState = valtio.useSnapshot(chatStore.conversations);
2278
2280
  const conversationState = valtio.useSnapshot(chatStore.conversation);
2281
+ const activeMessages = conversationState.messages[conversationState.active.id]?.message;
2279
2282
  const activeConversation = React10.useMemo(() => {
2280
2283
  return conversationsState.list.items.find((item) => item.id === conversationState.active.id);
2281
2284
  }, [conversationsState.list.items, conversationState.active.id]);
@@ -2290,17 +2293,18 @@ var ConversationFavoritesBtn_default = ({ icon, ...rest }) => {
2290
2293
  title: isFavorite ? "\u53D6\u6D88\u6536\u85CF" : "\u6536\u85CF",
2291
2294
  type: "text",
2292
2295
  size: "large",
2293
- disabled: !conversationState.active.id,
2296
+ disabled: disabled || !conversationState.active.id || !activeMessages?.length,
2294
2297
  icon: icon?.() || (isFavorite ? /* @__PURE__ */ jsxRuntime.jsx(icons.StarFilled, { className: "primary-text" }) : /* @__PURE__ */ jsxRuntime.jsx(icons.StarOutlined, {})),
2295
2298
  onClick: handleToggleFavorite,
2296
2299
  ...rest
2297
2300
  }
2298
2301
  );
2299
2302
  };
2300
- var ConversationShareBtn_default = ({ icon, ...rest }) => {
2303
+ var ConversationShareBtn_default = ({ icon, disabled, ...rest }) => {
2301
2304
  const chatStore = useChatStore();
2302
2305
  const conversationState = valtio.useSnapshot(chatStore.conversation);
2303
2306
  const configState = valtio.useSnapshot(chatStore.config);
2307
+ const activeMessages = conversationState.messages[conversationState.active.id]?.message;
2304
2308
  const handleShareConversation = async () => {
2305
2309
  const { data } = await configState.services.request.shareConversation(conversationState.active.id);
2306
2310
  if (data) {
@@ -2313,7 +2317,7 @@ var ConversationShareBtn_default = ({ icon, ...rest }) => {
2313
2317
  title: "\u5206\u4EAB",
2314
2318
  type: "text",
2315
2319
  size: "large",
2316
- disabled: !conversationState.active.id,
2320
+ disabled: disabled || !conversationState.active.id || !activeMessages?.length,
2317
2321
  icon: icon?.() || /* @__PURE__ */ jsxRuntime.jsx(icons.ShareAltOutlined, {}),
2318
2322
  ...rest,
2319
2323
  onClick: handleShareConversation
@@ -2378,17 +2382,12 @@ var ConversationTabPane = ({ items, activeKey, emptyDescription, scrollableTarge
2378
2382
  }
2379
2383
  ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles_module_default2.conversationEmpty, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Empty, { description: emptyDescription, image: antd.Empty.PRESENTED_IMAGE_SIMPLE }) }) });
2380
2384
  };
2381
- var ConversationList_default = () => {
2385
+ var ConversationList_default = ({ onClose }) => {
2382
2386
  const chatStore = useChatStore();
2383
- const agentState = valtio.useSnapshot(chatStore.agent);
2384
2387
  const conversationsState = valtio.useSnapshot(chatStore.conversations);
2385
2388
  const conversationState = valtio.useSnapshot(chatStore.conversation);
2386
2389
  const favoriteState = valtio.useSnapshot(chatStore.favorite);
2387
2390
  const [activeTabKey, setActiveTabKey] = React10.useState("history");
2388
- React10.useEffect(() => {
2389
- if (!agentState.agentInfo.id) return;
2390
- chatStore.getConversationFavorite();
2391
- }, [agentState.agentInfo.id, chatStore]);
2392
2391
  const conversationList = React10.useMemo(() => {
2393
2392
  return conversationsState.list.items.filter((item) => item.label);
2394
2393
  }, [conversationsState.list.items]);
@@ -2413,6 +2412,7 @@ var ConversationList_default = () => {
2413
2412
  itemInfo.domEvent.stopPropagation();
2414
2413
  if (itemInfo.key === "deleteChat") {
2415
2414
  chatStore.delConversation(conversation.key);
2415
+ onClose?.();
2416
2416
  } else if (itemInfo.key === "collect") {
2417
2417
  chatStore.collectConversation(conversation.id, !conversation.isFavorite);
2418
2418
  }
@@ -2434,7 +2434,7 @@ var ConversationList_default = () => {
2434
2434
  children: /* @__PURE__ */ jsxRuntime.jsx(
2435
2435
  antd.Button,
2436
2436
  {
2437
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.DeleteOutlined, {}),
2437
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.StarFilled, { className: "primary-text" }),
2438
2438
  title: "\u53D6\u6D88\u6536\u85CF",
2439
2439
  type: "text",
2440
2440
  onClick: (e) => {
@@ -2446,7 +2446,10 @@ var ConversationList_default = () => {
2446
2446
  ),
2447
2447
  items: []
2448
2448
  });
2449
- const handleConversationChange = async (id) => chatStore.switchConversation(id);
2449
+ const handleConversationChange = async (id) => {
2450
+ await chatStore.switchConversation(id);
2451
+ onClose?.();
2452
+ };
2450
2453
  return /* @__PURE__ */ jsxRuntime.jsx(
2451
2454
  antd.Tabs,
2452
2455
  {
@@ -2524,13 +2527,25 @@ var style_module_default = {
2524
2527
  footer: "style_module_footer",
2525
2528
  titleContainer: "style_module_titleContainer"};
2526
2529
  var HistoryBtn_default = ({ icon, ...rest }) => {
2530
+ const chatStore = useChatStore();
2531
+ const agentState = valtio.useSnapshot(chatStore.agent);
2532
+ const [open, setOpen] = React10.useState(false);
2533
+ const handleOpenChange = (open2) => {
2534
+ setOpen(open2);
2535
+ if (open2 && agentState.agentInfo.id) {
2536
+ chatStore.getConversations(agentState.agentInfo.id);
2537
+ chatStore.getConversationFavorite();
2538
+ }
2539
+ };
2527
2540
  return /* @__PURE__ */ jsxRuntime.jsx(
2528
2541
  antd.Popover,
2529
2542
  {
2543
+ open,
2530
2544
  getPopupContainer: (e) => e,
2545
+ onOpenChange: handleOpenChange,
2531
2546
  placement: "bottom",
2532
2547
  classNames: { container: style_module_default.popover },
2533
- content: /* @__PURE__ */ jsxRuntime.jsx(ConversationList_default, {}),
2548
+ content: /* @__PURE__ */ jsxRuntime.jsx(ConversationList_default, { onClose: () => setOpen(false) }),
2534
2549
  trigger: ["click"],
2535
2550
  children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { title: "\u5386\u53F2\u4F1A\u8BDD", size: "large", type: "text", icon: icon?.() || /* @__PURE__ */ jsxRuntime.jsx(icons.CommentOutlined, {}), ...rest })
2536
2551
  }
@@ -5190,6 +5205,34 @@ ${resultContent.text}
5190
5205
  ] });
5191
5206
  };
5192
5207
  var default_render_default = DefaultToolRender;
5208
+ var MAX_NESTING_DEPTH = 3;
5209
+ var SubAgentRender = ({ item }) => {
5210
+ const subMessages = item.subMessages || [];
5211
+ const depth = subMessages[0]?.subAgentDepth || 1;
5212
+ if (!subMessages.length) {
5213
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { type: "secondary", className: index_module_default2.emptyText, children: "\u5B50\u667A\u80FD\u4F53\u6267\u884C\u4E2D..." });
5214
+ }
5215
+ if (depth > MAX_NESTING_DEPTH) {
5216
+ return /* @__PURE__ */ jsxRuntime.jsxs(antd.Typography.Text, { type: "secondary", className: index_module_default2.emptyText, children: [
5217
+ "\u5B50\u667A\u80FD\u4F53\u6267\u884C\u5185\u5BB9\uFF08\u5D4C\u5957\u5C42\u7EA7 ",
5218
+ depth,
5219
+ "\uFF0C\u5DF2\u6298\u53E0\uFF09"
5220
+ ] });
5221
+ }
5222
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: index_module_default2.subAgentContainer, children: [
5223
+ item.subAgentName && /* @__PURE__ */ jsxRuntime.jsx("div", { className: index_module_default2.subAgentHeader, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { type: "secondary", className: index_module_default2.subAgentName, children: item.subAgentName }) }),
5224
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: index_module_default2.subAgentMessages, children: subMessages.map((msg, index) => /* @__PURE__ */ jsxRuntime.jsx(
5225
+ MessageRender_default,
5226
+ {
5227
+ role: { user: "agent", role: 2, placement: "start" },
5228
+ message: msg,
5229
+ loading: !!msg.generating
5230
+ },
5231
+ `sub-agent-${msg.messageId || index}`
5232
+ )) })
5233
+ ] });
5234
+ };
5235
+ var sub_agent_render_default = SubAgentRender;
5193
5236
  var TodoWriteRender = ({ args, result }) => {
5194
5237
  const { token } = antd.theme.useToken();
5195
5238
  const todos = Array.isArray(result) ? result : result?.todos || (Array.isArray(args) ? args : args?.todos) || [];
@@ -5221,21 +5264,30 @@ var TodoWriteRender = ({ args, result }) => {
5221
5264
  );
5222
5265
  };
5223
5266
  var todo_write_render_default = TodoWriteRender;
5267
+
5268
+ // src/components/CustomComponents/ToolRenders/index.tsx
5224
5269
  var toolRenders = {
5225
5270
  todo_write: {
5226
5271
  component: todo_write_render_default,
5227
- defaultExpanded: false,
5272
+ defaultExpanded: true,
5228
5273
  alwaysShowContent: (args, result) => {
5229
5274
  const todos = Array.isArray(result) ? result : result?.todos || (Array.isArray(args) ? args : args?.todos) || [];
5230
- return todos && todos.length > 0;
5275
+ return Array.isArray(todos) && todos.length > 0;
5231
5276
  },
5232
5277
  hideStatus: true,
5233
5278
  disableExpandOnError: true
5234
5279
  }
5235
5280
  };
5236
- var getToolRenderConfig = (toolName) => {
5237
- if (toolName && toolRenders[toolName]) {
5238
- return toolRenders[toolName];
5281
+ var getToolRenderConfig = (item) => {
5282
+ if (item?.hasSubAgent && item?.subMessages?.length) {
5283
+ return {
5284
+ component: sub_agent_render_default,
5285
+ defaultExpanded: true,
5286
+ alwaysShowContent: true
5287
+ };
5288
+ }
5289
+ if (item?.toolName && toolRenders[item.toolName]) {
5290
+ return toolRenders[item.toolName];
5239
5291
  }
5240
5292
  return {
5241
5293
  component: default_render_default,
@@ -5974,35 +6026,37 @@ var ModelSelect_default = ({}) => {
5974
6026
  icon: item.icon,
5975
6027
  options: item.models.map((model) => ({
5976
6028
  label: model.modelLabel,
5977
- value: model.modelName,
6029
+ value: `${item.providerName}:${model.modelName}`,
6030
+ modelName: model.modelName,
5978
6031
  providerName: item.providerName,
5979
6032
  icon: model.icon
5980
6033
  }))
5981
6034
  }));
5982
- const selectedModelValue = modelOptions.find((item) => item.value === agentState.model.providerName)?.options.find((item) => item.value === agentState.model.modelName)?.value || void 0;
6035
+ const hasSelectedModelConfig = Boolean(agentState.model.providerName && agentState.model.modelName);
6036
+ const selectedProvider = hasSelectedModelConfig ? modelOptions.find((item) => item.value === agentState.model.providerName) : void 0;
6037
+ const selectedModel = selectedProvider?.options.find((item) => item.modelName === agentState.model.modelName);
6038
+ const selectedModelValue = selectedModel?.value;
5983
6039
  React10.useEffect(() => {
5984
- if (!selectedModelValue && models.length > 0 && models[0].models?.length > 0) {
6040
+ const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
6041
+ if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
5985
6042
  const firstProvider = models[0];
5986
6043
  const firstModel = firstProvider.models[0];
5987
6044
  chatStore.setAgentModel({
5988
- ...agentState.model,
5989
6045
  modelName: firstModel.modelName,
5990
6046
  providerName: firstProvider.providerName
5991
6047
  });
5992
6048
  }
5993
- }, [selectedModelValue, models, agentState.model, chatStore]);
6049
+ }, [hasSelectedModelConfig, selectedModel, models, chatStore]);
5994
6050
  const handleModelChange = (_, option) => {
5995
6051
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
5996
6052
  chatStore.setAgentModel({
5997
- ...agentState.model,
5998
- modelName: option.value,
6053
+ modelName: option.modelName,
5999
6054
  providerName: option.providerName
6000
6055
  });
6001
6056
  };
6002
6057
  const labelRender = (props) => {
6003
6058
  const currentVal = props.value;
6004
- const option = modelOptions.find((item) => item.options.some((model2) => model2.value === currentVal));
6005
- const model = option?.options.find((model2) => model2.value === currentVal);
6059
+ const model = modelOptions.flatMap((item) => item.options).find((model2) => model2.value === currentVal);
6006
6060
  if (!model) {
6007
6061
  return currentVal;
6008
6062
  }
@@ -6044,7 +6098,9 @@ var ReasonBtn_default = ({}) => {
6044
6098
  "div",
6045
6099
  {
6046
6100
  className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: agentState.model.reasoning }),
6047
- onClick: () => chatStore.setAgentModel({ ...agentState.model, reasoning: !agentState.model.reasoning }),
6101
+ onClick: () => chatStore.setAgentModel((prevModel) => ({
6102
+ reasoning: !prevModel.reasoning
6103
+ })),
6048
6104
  children: [
6049
6105
  /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-reason" }),
6050
6106
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
@@ -6057,7 +6113,25 @@ var SkillBtn_default = ({}) => {
6057
6113
  const chatStore = useChatStore();
6058
6114
  const conversationState = valtio.useSnapshot(chatStore.conversation);
6059
6115
  const [modalOpen, setModalOpen] = React10.useState(false);
6060
- const skillsCount = conversationState.active.spec?.skills?.items?.length ?? 0;
6116
+ const [skillsCount, setSkillsCount] = React10.useState(0);
6117
+ React10.useEffect(() => {
6118
+ let canceled = false;
6119
+ const syncSkillsCount = async () => {
6120
+ const initialItems = conversationState.active.spec?.skills?.items;
6121
+ if (!initialItems?.length) {
6122
+ setSkillsCount(0);
6123
+ return;
6124
+ }
6125
+ const { data } = await chatStore.config.services.request.listSkills();
6126
+ if (canceled) return;
6127
+ const validIds = new Set((data || []).map((item) => item.id));
6128
+ setSkillsCount(initialItems.map((item) => item.id).filter((id) => validIds.has(id)).length);
6129
+ };
6130
+ syncSkillsCount();
6131
+ return () => {
6132
+ canceled = true;
6133
+ };
6134
+ }, [chatStore, conversationState.active.spec?.skills?.items]);
6061
6135
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6062
6136
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: style_module_default.resourceBtn, onClick: () => setModalOpen(true), children: [
6063
6137
  /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-skill" }),