mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-08 21:09:23 +08:00
fix(ui): refresh agent files after external edits
This commit is contained in:
@@ -421,7 +421,17 @@ export function renderApp(state: AppViewState) {
|
||||
void state.loadCron();
|
||||
}
|
||||
},
|
||||
onLoadFiles: (agentId) => loadAgentFiles(state, agentId),
|
||||
onLoadFiles: (agentId) => {
|
||||
void (async () => {
|
||||
await loadAgentFiles(state, agentId);
|
||||
if (state.agentFileActive) {
|
||||
await loadAgentFileContent(state, agentId, state.agentFileActive, {
|
||||
force: true,
|
||||
preserveDraft: true,
|
||||
});
|
||||
}
|
||||
})();
|
||||
},
|
||||
onSelectFile: (name) => {
|
||||
state.agentFileActive = name;
|
||||
if (!resolvedAgentId) {
|
||||
|
||||
@@ -55,11 +55,16 @@ export async function loadAgentFiles(state: AgentFilesState, agentId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadAgentFileContent(state: AgentFilesState, agentId: string, name: string) {
|
||||
export async function loadAgentFileContent(
|
||||
state: AgentFilesState,
|
||||
agentId: string,
|
||||
name: string,
|
||||
opts?: { force?: boolean; preserveDraft?: boolean },
|
||||
) {
|
||||
if (!state.client || !state.connected || state.agentFilesLoading) {
|
||||
return;
|
||||
}
|
||||
if (Object.hasOwn(state.agentFileContents, name)) {
|
||||
if (!opts?.force && Object.hasOwn(state.agentFileContents, name)) {
|
||||
return;
|
||||
}
|
||||
state.agentFilesLoading = true;
|
||||
@@ -71,9 +76,16 @@ export async function loadAgentFileContent(state: AgentFilesState, agentId: stri
|
||||
});
|
||||
if (res?.file) {
|
||||
const content = res.file.content ?? "";
|
||||
const previousBase = state.agentFileContents[name] ?? "";
|
||||
const currentDraft = state.agentFileDrafts[name];
|
||||
const preserveDraft = opts?.preserveDraft ?? true;
|
||||
state.agentFilesList = mergeFileEntry(state.agentFilesList, res.file);
|
||||
state.agentFileContents = { ...state.agentFileContents, [name]: content };
|
||||
if (!Object.hasOwn(state.agentFileDrafts, name)) {
|
||||
if (
|
||||
!preserveDraft ||
|
||||
!Object.hasOwn(state.agentFileDrafts, name) ||
|
||||
currentDraft === previousBase
|
||||
) {
|
||||
state.agentFileDrafts = { ...state.agentFileDrafts, [name]: content };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user