@zero-library/chat-copilot 3.1.27 → 3.1.28

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,18 +1190,20 @@ 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
1196
  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);
1197
+ const prevModel = agent.agentInfo.spec?.model || {
1198
+ modelName: "",
1199
+ providerName: "",
1200
+ reasoning: true
1201
+ };
1202
+ const nextPatch = typeof updater === "function" ? updater(prevModel) : updater;
1203
+ const nextSpec = common.deepCopy(agent.agentInfo.spec || {});
1204
+ nextSpec.model = { ...prevModel, ...nextPatch };
1205
+ agent.agentInfo.spec = nextSpec;
1206
+ config.hooks?.onAfterSwitchModel?.(agent.agentInfo.spec.model);
1205
1207
  };
1206
1208
  const getUserInput = async (agentId) => {
1207
1209
  agent.loading = true;
@@ -1230,16 +1232,11 @@ function createChatStore() {
1230
1232
  }
1231
1233
  };
1232
1234
  const setAgent = async (agentInfo) => {
1233
- if (!agent.agentInfo.id || agent.agentInfo.id !== agentInfo.id) {
1235
+ if (!agent.agentInfo.id && !agentInfo.updatedAt || agent.agentInfo.id !== agentInfo.id) {
1234
1236
  await getAgentInfo(agentInfo.id);
1235
1237
  }
1236
1238
  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) {
1239
+ if (config.layout.userInput) {
1243
1240
  await getUserInput(agent.agentInfo.id);
1244
1241
  }
1245
1242
  };
@@ -2074,7 +2071,7 @@ function createChatStore() {
2074
2071
  files,
2075
2072
  spec: {
2076
2073
  ...conversation.active.spec,
2077
- model: agent.model
2074
+ model: agent.agentInfo.spec?.model
2078
2075
  },
2079
2076
  stream: true,
2080
2077
  responseMode: 2
@@ -6022,6 +6019,23 @@ var ModelSelect_default = ({}) => {
6022
6019
  const chatStore = useChatStore();
6023
6020
  const agentState = valtio.useSnapshot(chatStore.agent);
6024
6021
  const [models, setModels] = React10.useState([]);
6022
+ const currentModel = agentState.agentInfo.spec?.model;
6023
+ const updateAgentModel = React10.useCallback(
6024
+ (model) => {
6025
+ const nextAgentInfo = common.deepCopy(agentState.agentInfo || {});
6026
+ const nextSpec = common.deepCopy(agentState.agentInfo.spec || {});
6027
+ nextSpec.model = {
6028
+ modelName: "",
6029
+ providerName: "",
6030
+ reasoning: true,
6031
+ ...nextSpec.model || {},
6032
+ ...model
6033
+ };
6034
+ nextAgentInfo.spec = nextSpec;
6035
+ chatStore.setAgent(nextAgentInfo);
6036
+ },
6037
+ [agentState.agentInfo, chatStore]
6038
+ );
6025
6039
  const modelOptions = models.map((item) => ({
6026
6040
  label: item.providerLabel || item.providerName,
6027
6041
  title: item.providerLabel || item.providerName,
@@ -6035,24 +6049,10 @@ var ModelSelect_default = ({}) => {
6035
6049
  icon: model.icon
6036
6050
  }))
6037
6051
  }));
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]);
6052
+ const selectedModelValue = currentModel?.providerName && currentModel?.modelName ? `${currentModel.providerName}:${currentModel.modelName}` : void 0;
6053
6053
  const handleModelChange = (_, option) => {
6054
6054
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
6055
- chatStore.setAgentModel({
6055
+ updateAgentModel({
6056
6056
  modelName: option.modelName,
6057
6057
  providerName: option.providerName
6058
6058
  });
@@ -6097,13 +6097,25 @@ var ModelSelect_default = ({}) => {
6097
6097
  var ReasonBtn_default = ({}) => {
6098
6098
  const chatStore = useChatStore();
6099
6099
  const agentState = valtio.useSnapshot(chatStore.agent);
6100
+ const currentModel = agentState.agentInfo.spec?.model;
6101
+ const updateAgentModel = (reasoning) => {
6102
+ const nextAgentInfo = common.deepCopy(agentState.agentInfo || {});
6103
+ const nextSpec = common.deepCopy(agentState.agentInfo.spec || {});
6104
+ nextSpec.model = {
6105
+ modelName: "",
6106
+ providerName: "",
6107
+ reasoning: true,
6108
+ ...nextSpec.model || {}
6109
+ };
6110
+ nextSpec.model.reasoning = reasoning;
6111
+ nextAgentInfo.spec = nextSpec;
6112
+ chatStore.setAgent(nextAgentInfo);
6113
+ };
6100
6114
  return /* @__PURE__ */ jsxRuntime.jsxs(
6101
6115
  "div",
6102
6116
  {
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
- })),
6117
+ className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: currentModel?.reasoning }),
6118
+ onClick: () => updateAgentModel(!currentModel?.reasoning),
6107
6119
  children: [
6108
6120
  /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-reason" }),
6109
6121
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })