refactor(updateWorkflowList): replace Local Service call with IDE Service

Update the workflow list retrieval mechanism by replacing the direct local service
invocation with a call to the IDE service. This change introduces a more structured
approach to interacting with services and sets the foundation for future service
communications within the application.
This commit is contained in:
Rankin Zheng 2024-08-28 06:50:14 +08:00
parent 56e30328be
commit 2499ff5312
2 changed files with 22 additions and 2 deletions

View File

@ -56,8 +56,8 @@ export default function App() {
compare_func(configs);
// 假设setReady是一个函数用于设置应用状态为准备就绪
setReady(true);
// 调用 Local Service 更新工作流,更新、重载命令列表
MessageUtil.sendMessage({ command: "updateWorkflowList"});
// update workflow list
config.updateWorkflowList();
}
};

View File

@ -1,4 +1,5 @@
import MessageUtil from "@/util/MessageUtil";
import IDEServiceUtil from "@/util/IDEServiceUtil";
import { types, Instance, flow } from "mobx-state-tree";
import modelsTemplate from "@/models";
import cloneDeep from "lodash.clonedeep";
@ -26,6 +27,22 @@ function deepCopy(obj) {
return copy;
}
export const doUpdateWorkflowList = async () => {
try {
// Get local service port
const port = await IDEServiceUtil.callService("get_local_service_port", {});
// Call local service to update Workflows
await axios.post(`http://localhost:${port}/workflows/update`, {});
await axios.post(`http://localhost:${port}/workflows/custom_update`, {});
// Update command list
MessageUtil.sendMessage({ command: "regCommandList" });
} catch (e) {
console.error("do update workflow and command list error:", e);
return undefined;
}
};
export const fetchServerConfigUtil = async ({ modelsUrl, devchatApiKey }) => {
try {
const response = await axios.get(`${modelsUrl}/models`, {
@ -295,6 +312,9 @@ export const ConfigStore = types
MessageUtil.handleMessage({ command: "readServerConfig", value: undefined });
}
}),
updateWorkflowList: flow(function* (){
yield doUpdateWorkflowList();
}),
checkAndSetCompletionDefaults: (newConfig) => {
const codeModels = self.modelsTemplate.filter(model => model.category === "code");
const isCustomAPIBase = self.modelsUrl.indexOf("api.devchat.ai") === -1 && self.modelsUrl.indexOf("api.devchat-ai.cn") === -1;