@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.esm.js CHANGED
@@ -1160,19 +1160,9 @@ function createChatStore() {
1160
1160
  const agent = proxy({
1161
1161
  /** 当前智能体 */
1162
1162
  agentInfo: {},
1163
- model: {
1164
- modelName: "",
1165
- providerName: "",
1166
- reasoning: true
1167
- },
1168
1163
  /** 智能体加载状态 */
1169
1164
  loading: false
1170
1165
  });
1171
- const setAgentModel = (updater) => {
1172
- const nextPatch = typeof updater === "function" ? updater(agent.model) : updater;
1173
- agent.model = { ...agent.model, ...nextPatch };
1174
- config.hooks?.onAfterSwitchModel?.(agent.model);
1175
- };
1176
1166
  const getUserInput = async (agentId) => {
1177
1167
  agent.loading = true;
1178
1168
  try {
@@ -1194,24 +1184,19 @@ function createChatStore() {
1194
1184
  try {
1195
1185
  const { data } = await config.services.request.fetchAgentInfo(id || "");
1196
1186
  agent.agentInfo = data;
1197
- config.hooks?.onAfterSwitchAgent?.(agent.agentInfo);
1198
1187
  } finally {
1199
1188
  config.loading = false;
1200
1189
  }
1201
1190
  };
1202
1191
  const setAgent = async (agentInfo) => {
1203
- if (!agent.agentInfo.id || agent.agentInfo.id !== agentInfo.id) {
1192
+ if (!agent.agentInfo.id && !agentInfo.updatedAt || agent.agentInfo.id && agent.agentInfo.id !== agentInfo.id) {
1204
1193
  await getAgentInfo(agentInfo.id);
1205
1194
  }
1206
1195
  agent.agentInfo = { ...agent.agentInfo, ...agentInfo };
1207
- if (agentInfo.agentType === 2 /* AUTONOMOUS */) {
1208
- setAgentModel({
1209
- modelName: agent.agentInfo.spec?.model?.modelName || "",
1210
- providerName: agent.agentInfo.spec?.model?.providerName || ""
1211
- });
1212
- } else if (config.layout.userInput) {
1196
+ if (config.layout.userInput) {
1213
1197
  await getUserInput(agent.agentInfo.id);
1214
1198
  }
1199
+ config.hooks?.onAfterSwitchAgent?.(agent.agentInfo);
1215
1200
  };
1216
1201
  const conversations = proxy({
1217
1202
  /** 会话列表数据 */
@@ -2044,7 +2029,11 @@ function createChatStore() {
2044
2029
  files,
2045
2030
  spec: {
2046
2031
  ...conversation.active.spec,
2047
- model: agent.model
2032
+ model: {
2033
+ providerName: agent.agentInfo.spec?.model?.providerName || "",
2034
+ modelName: agent.agentInfo.spec?.model?.modelName || "",
2035
+ reasoning: agent.agentInfo.spec?.model?.reasoning ?? false
2036
+ }
2048
2037
  },
2049
2038
  stream: true,
2050
2039
  responseMode: 2
@@ -2113,8 +2102,6 @@ function createChatStore() {
2113
2102
  setServices,
2114
2103
  /** 智能体状态 */
2115
2104
  agent,
2116
- /** 设置智能体模型 */
2117
- setAgentModel,
2118
2105
  /** 设置文件预览 */
2119
2106
  setPreview,
2120
2107
  /** 设置参数 */
@@ -5992,6 +5979,23 @@ var ModelSelect_default = ({}) => {
5992
5979
  const chatStore = useChatStore();
5993
5980
  const agentState = useSnapshot(chatStore.agent);
5994
5981
  const [models, setModels] = useState([]);
5982
+ const currentModel = agentState.agentInfo.spec?.model;
5983
+ const updateAgentModel = useCallback(
5984
+ (model) => {
5985
+ const nextAgentInfo = {
5986
+ ...agentState.agentInfo,
5987
+ spec: {
5988
+ ...agentState.agentInfo.spec,
5989
+ model: {
5990
+ ...agentState.agentInfo.spec?.model,
5991
+ ...model
5992
+ }
5993
+ }
5994
+ };
5995
+ chatStore.setAgent(nextAgentInfo);
5996
+ },
5997
+ [agentState.agentInfo, chatStore]
5998
+ );
5995
5999
  const modelOptions = models.map((item) => ({
5996
6000
  label: item.providerLabel || item.providerName,
5997
6001
  title: item.providerLabel || item.providerName,
@@ -6005,24 +6009,10 @@ var ModelSelect_default = ({}) => {
6005
6009
  icon: model.icon
6006
6010
  }))
6007
6011
  }));
6008
- const hasSelectedModelConfig = Boolean(agentState.model.providerName && agentState.model.modelName);
6009
- const selectedProvider = hasSelectedModelConfig ? modelOptions.find((item) => item.value === agentState.model.providerName) : void 0;
6010
- const selectedModel = selectedProvider?.options.find((item) => item.modelName === agentState.model.modelName);
6011
- const selectedModelValue = selectedModel?.value;
6012
- useEffect(() => {
6013
- const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
6014
- if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
6015
- const firstProvider = models[0];
6016
- const firstModel = firstProvider.models[0];
6017
- chatStore.setAgentModel({
6018
- modelName: firstModel.modelName,
6019
- providerName: firstProvider.providerName
6020
- });
6021
- }
6022
- }, [hasSelectedModelConfig, selectedModel, models, chatStore]);
6012
+ const selectedModelValue = currentModel?.providerName && currentModel?.modelName ? `${currentModel.providerName}:${currentModel.modelName}` : void 0;
6023
6013
  const handleModelChange = (_, option) => {
6024
6014
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
6025
- chatStore.setAgentModel({
6015
+ updateAgentModel({
6026
6016
  modelName: option.modelName,
6027
6017
  providerName: option.providerName
6028
6018
  });
@@ -6064,22 +6054,27 @@ var ModelSelect_default = ({}) => {
6064
6054
  }
6065
6055
  );
6066
6056
  };
6067
- var ReasonBtn_default = ({}) => {
6057
+ var ReasonBtn_default = () => {
6068
6058
  const chatStore = useChatStore();
6069
6059
  const agentState = useSnapshot(chatStore.agent);
6070
- return /* @__PURE__ */ jsxs(
6071
- "div",
6072
- {
6073
- className: classNames2(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: agentState.model.reasoning }),
6074
- onClick: () => chatStore.setAgentModel((prevModel) => ({
6075
- reasoning: !prevModel.reasoning
6076
- })),
6077
- children: [
6078
- /* @__PURE__ */ jsx(IconFont_default, { type: "icon-reason" }),
6079
- /* @__PURE__ */ jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
6080
- ]
6081
- }
6082
- );
6060
+ const currentModel = agentState.agentInfo.spec?.model;
6061
+ const toggleReasoning = () => {
6062
+ const nextAgentInfo = {
6063
+ ...agentState.agentInfo,
6064
+ spec: {
6065
+ ...agentState.agentInfo.spec,
6066
+ model: {
6067
+ ...agentState.agentInfo.spec?.model,
6068
+ reasoning: !currentModel?.reasoning
6069
+ }
6070
+ }
6071
+ };
6072
+ chatStore.setAgent(nextAgentInfo);
6073
+ };
6074
+ return /* @__PURE__ */ jsxs("div", { className: classNames2(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: currentModel?.reasoning }), onClick: toggleReasoning, children: [
6075
+ /* @__PURE__ */ jsx(IconFont_default, { type: "icon-reason" }),
6076
+ /* @__PURE__ */ jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
6077
+ ] });
6083
6078
  };
6084
6079
  var { Text: Text7 } = Typography;
6085
6080
  var SkillBtn_default = ({}) => {