@zero-library/chat-copilot 3.1.27 → 3.1.29

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
@@ -1190,19 +1190,9 @@ function createChatStore() {
1190
1190
  const agent = valtio.proxy({
1191
1191
  /** 当前智能体 */
1192
1192
  agentInfo: {},
1193
- model: {
1194
- modelName: "",
1195
- providerName: "",
1196
- reasoning: true
1197
- },
1198
1193
  /** 智能体加载状态 */
1199
1194
  loading: false
1200
1195
  });
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);
1205
- };
1206
1196
  const getUserInput = async (agentId) => {
1207
1197
  agent.loading = true;
1208
1198
  try {
@@ -1224,24 +1214,19 @@ function createChatStore() {
1224
1214
  try {
1225
1215
  const { data } = await config.services.request.fetchAgentInfo(id || "");
1226
1216
  agent.agentInfo = data;
1227
- config.hooks?.onAfterSwitchAgent?.(agent.agentInfo);
1228
1217
  } finally {
1229
1218
  config.loading = false;
1230
1219
  }
1231
1220
  };
1232
1221
  const setAgent = async (agentInfo) => {
1233
- if (!agent.agentInfo.id || agent.agentInfo.id !== agentInfo.id) {
1222
+ if (!agent.agentInfo.id && !agentInfo.updatedAt || agent.agentInfo.id && agent.agentInfo.id !== agentInfo.id) {
1234
1223
  await getAgentInfo(agentInfo.id);
1235
1224
  }
1236
1225
  agent.agentInfo = { ...agent.agentInfo, ...agentInfo };
1237
- if (agentInfo.agentType === 2 /* AUTONOMOUS */) {
1238
- setAgentModel({
1239
- modelName: agent.agentInfo.spec?.model?.modelName || "",
1240
- providerName: agent.agentInfo.spec?.model?.providerName || ""
1241
- });
1242
- } else if (config.layout.userInput) {
1226
+ if (config.layout.userInput) {
1243
1227
  await getUserInput(agent.agentInfo.id);
1244
1228
  }
1229
+ config.hooks?.onAfterSwitchAgent?.(agent.agentInfo);
1245
1230
  };
1246
1231
  const conversations = valtio.proxy({
1247
1232
  /** 会话列表数据 */
@@ -2074,7 +2059,11 @@ function createChatStore() {
2074
2059
  files,
2075
2060
  spec: {
2076
2061
  ...conversation.active.spec,
2077
- model: agent.model
2062
+ model: {
2063
+ providerName: agent.agentInfo.spec?.model?.providerName || "",
2064
+ modelName: agent.agentInfo.spec?.model?.modelName || "",
2065
+ reasoning: agent.agentInfo.spec?.model?.reasoning ?? false
2066
+ }
2078
2067
  },
2079
2068
  stream: true,
2080
2069
  responseMode: 2
@@ -2143,8 +2132,6 @@ function createChatStore() {
2143
2132
  setServices,
2144
2133
  /** 智能体状态 */
2145
2134
  agent,
2146
- /** 设置智能体模型 */
2147
- setAgentModel,
2148
2135
  /** 设置文件预览 */
2149
2136
  setPreview,
2150
2137
  /** 设置参数 */
@@ -6022,6 +6009,23 @@ var ModelSelect_default = ({}) => {
6022
6009
  const chatStore = useChatStore();
6023
6010
  const agentState = valtio.useSnapshot(chatStore.agent);
6024
6011
  const [models, setModels] = React10.useState([]);
6012
+ const currentModel = agentState.agentInfo.spec?.model;
6013
+ const updateAgentModel = React10.useCallback(
6014
+ (model) => {
6015
+ const nextAgentInfo = {
6016
+ ...agentState.agentInfo,
6017
+ spec: {
6018
+ ...agentState.agentInfo.spec,
6019
+ model: {
6020
+ ...agentState.agentInfo.spec?.model,
6021
+ ...model
6022
+ }
6023
+ }
6024
+ };
6025
+ chatStore.setAgent(nextAgentInfo);
6026
+ },
6027
+ [agentState.agentInfo, chatStore]
6028
+ );
6025
6029
  const modelOptions = models.map((item) => ({
6026
6030
  label: item.providerLabel || item.providerName,
6027
6031
  title: item.providerLabel || item.providerName,
@@ -6035,24 +6039,10 @@ var ModelSelect_default = ({}) => {
6035
6039
  icon: model.icon
6036
6040
  }))
6037
6041
  }));
6038
- const hasSelectedModelConfig = Boolean(agentState.model.providerName && agentState.model.modelName);
6039
- const selectedProvider = hasSelectedModelConfig ? modelOptions.find((item) => item.value === agentState.model.providerName) : void 0;
6040
- const selectedModel = selectedProvider?.options.find((item) => item.modelName === agentState.model.modelName);
6041
- const selectedModelValue = selectedModel?.value;
6042
- React10.useEffect(() => {
6043
- const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
6044
- if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
6045
- const firstProvider = models[0];
6046
- const firstModel = firstProvider.models[0];
6047
- chatStore.setAgentModel({
6048
- modelName: firstModel.modelName,
6049
- providerName: firstProvider.providerName
6050
- });
6051
- }
6052
- }, [hasSelectedModelConfig, selectedModel, models, chatStore]);
6042
+ const selectedModelValue = currentModel?.providerName && currentModel?.modelName ? `${currentModel.providerName}:${currentModel.modelName}` : void 0;
6053
6043
  const handleModelChange = (_, option) => {
6054
6044
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
6055
- chatStore.setAgentModel({
6045
+ updateAgentModel({
6056
6046
  modelName: option.modelName,
6057
6047
  providerName: option.providerName
6058
6048
  });
@@ -6094,22 +6084,27 @@ var ModelSelect_default = ({}) => {
6094
6084
  }
6095
6085
  );
6096
6086
  };
6097
- var ReasonBtn_default = ({}) => {
6087
+ var ReasonBtn_default = () => {
6098
6088
  const chatStore = useChatStore();
6099
6089
  const agentState = valtio.useSnapshot(chatStore.agent);
6100
- return /* @__PURE__ */ jsxRuntime.jsxs(
6101
- "div",
6102
- {
6103
- className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: agentState.model.reasoning }),
6104
- onClick: () => chatStore.setAgentModel((prevModel) => ({
6105
- reasoning: !prevModel.reasoning
6106
- })),
6107
- children: [
6108
- /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-reason" }),
6109
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
6110
- ]
6111
- }
6112
- );
6090
+ const currentModel = agentState.agentInfo.spec?.model;
6091
+ const toggleReasoning = () => {
6092
+ const nextAgentInfo = {
6093
+ ...agentState.agentInfo,
6094
+ spec: {
6095
+ ...agentState.agentInfo.spec,
6096
+ model: {
6097
+ ...agentState.agentInfo.spec?.model,
6098
+ reasoning: !currentModel?.reasoning
6099
+ }
6100
+ }
6101
+ };
6102
+ chatStore.setAgent(nextAgentInfo);
6103
+ };
6104
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: currentModel?.reasoning }), onClick: toggleReasoning, children: [
6105
+ /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-reason" }),
6106
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
6107
+ ] });
6113
6108
  };
6114
6109
  var { Text: Text7 } = antd.Typography;
6115
6110
  var SkillBtn_default = ({}) => {