Refactor input message and chat panel components
This commit is contained in:
parent
3e2ea595d8
commit
f920f79869
@ -188,15 +188,6 @@ const InputMessage = observer((props: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
input.fetchContextMenus().then();
|
|
||||||
input.fetchCommandMenus().then();
|
|
||||||
input.fetchModelMenus().then();
|
|
||||||
messageUtil.registerHandler(
|
|
||||||
"regCommandList",
|
|
||||||
(message: { result: object[] }) => {
|
|
||||||
input.updateCommands(message.result);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
messageUtil.registerHandler(
|
messageUtil.registerHandler(
|
||||||
"chatWithDevChat",
|
"chatWithDevChat",
|
||||||
(message: { command: string; message: string }) => {
|
(message: { command: string; message: string }) => {
|
||||||
|
@ -44,6 +44,9 @@ const chatPanel = observer(() => {
|
|||||||
key1: "devchat",
|
key1: "devchat",
|
||||||
key2: "defaultModel",
|
key2: "defaultModel",
|
||||||
});
|
});
|
||||||
|
messageUtil.sendMessage({
|
||||||
|
command: "getUserAccessKey",
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFeatureToggles = () => {
|
const getFeatureToggles = () => {
|
||||||
@ -78,18 +81,25 @@ const chatPanel = observer(() => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSettings();
|
// Fetch the command menus, before history records are obtained,
|
||||||
getFeatureToggles();
|
// because the display information in the history record requires adjustment
|
||||||
messageUtil.registerHandler("getUserAccessKey", (message: any) => {
|
input.fetchCommandMenus().then(()=>{
|
||||||
chat.setKey(message.accessKey);
|
messageUtil.registerHandler("reloadMessage", (message: any) => {
|
||||||
// The history records need to be obtained after setting the key,
|
chat.reloadMessage(message);
|
||||||
// as the display information in the history record requires adjustment
|
});
|
||||||
// based on whether the key is present.
|
// The history records need to be obtained after setting the key,
|
||||||
chat.fetchHistoryMessages({ pageIndex: 0 }).then();
|
// as the display information in the history record requires adjustment
|
||||||
});
|
// based on whether the key is present.
|
||||||
messageUtil.registerHandler("reloadMessage", (message: any) => {
|
messageUtil.registerHandler("getUserAccessKey", (message: any) => {
|
||||||
chat.reloadMessage(message);
|
chat.setKey(message.accessKey);
|
||||||
|
chat.fetchHistoryMessages({ pageIndex: 0 }).then();
|
||||||
|
});
|
||||||
|
// The history records need to be obtained after setting the key,
|
||||||
|
input.fetchContextMenus().then();
|
||||||
|
input.fetchModelMenus().then();
|
||||||
|
getFeatureToggles();
|
||||||
|
getSettings();
|
||||||
});
|
});
|
||||||
messageUtil.registerHandler(
|
messageUtil.registerHandler(
|
||||||
"receiveMessagePartial",
|
"receiveMessagePartial",
|
||||||
|
@ -33,6 +33,19 @@ const regModelMenus = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const regCommandMenus = async () => {
|
||||||
|
return new Promise<Item[]>((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
messageUtil.sendMessage({ command: 'regCommandList' });
|
||||||
|
messageUtil.registerHandler("regCommandList",(message: { result: Item[] }) => {
|
||||||
|
resolve(message.result);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const ChatContext = types.model({
|
export const ChatContext = types.model({
|
||||||
file: types.maybe(types.string),
|
file: types.maybe(types.string),
|
||||||
path: types.maybe(types.string),
|
path: types.maybe(types.string),
|
||||||
@ -88,11 +101,6 @@ export const InputStore = types
|
|||||||
setCurrentMenuIndex(index: number) {
|
setCurrentMenuIndex(index: number) {
|
||||||
self.currentMenuIndex = index;
|
self.currentMenuIndex = index;
|
||||||
},
|
},
|
||||||
updateCommands(items) {
|
|
||||||
self.commandMenus.clear();
|
|
||||||
self.commandMenus.push(...items);
|
|
||||||
self.commandMenus.push({ name: 'help', description: 'View the DevChat documentation.', pattern: 'help' });
|
|
||||||
},
|
|
||||||
fetchContextMenus: flow(function* () {
|
fetchContextMenus: flow(function* () {
|
||||||
try {
|
try {
|
||||||
const items = yield regContextMenus();
|
const items = yield regContextMenus();
|
||||||
@ -110,18 +118,11 @@ export const InputStore = types
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
fetchCommandMenus: flow(function* () {
|
fetchCommandMenus: flow(function* () {
|
||||||
const regCommandMenus = async () => {
|
|
||||||
return new Promise<Item[]>((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
messageUtil.sendMessage({ command: 'regCommandList' });
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield regCommandMenus();
|
const items = yield regCommandMenus();
|
||||||
|
self.commandMenus.clear();
|
||||||
|
self.commandMenus.push(...items);
|
||||||
|
self.commandMenus.push({ name: 'help', description: 'View the DevChat documentation.', pattern: 'help' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch command menus", error);
|
console.error("Failed to fetch command menus", error);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user