Refresh config pages in realtime

This commit is contained in:
kris
2026-04-07 18:26:17 +08:00
parent 0c01627d67
commit 07ecce3d0d
10 changed files with 447 additions and 12 deletions

View File

@@ -4322,7 +4322,7 @@ export async function updateProjectAgentControls(
throw new Error("MASTER_AGENT_TAKEOVER_SCOPE_RESTRICTED");
}
return mutateStateIfChanged((state) => {
const result = await mutateStateIfChanged((state) => {
const project = state.projects.find((item) => item.id === projectId);
if (!project) throw new Error("PROJECT_NOT_FOUND");
@@ -4429,6 +4429,10 @@ export async function updateProjectAgentControls(
changed: true,
};
});
if (projectId === "master-agent") {
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
}
return result;
}
function projectOrchestrationRequestedBackendId(project: Project): OrchestrationBackendId {
@@ -4529,7 +4533,7 @@ export async function getAttachmentStorageConfig(account: string) {
}
export async function upsertAttachmentStorageConfig(config: UserAttachmentStorageConfig) {
return mutateState((state) => {
const result = await mutateState((state) => {
const index = state.userAttachmentStorageConfigs.findIndex(
(item) => item.account === config.account,
);
@@ -4540,6 +4544,8 @@ export async function upsertAttachmentStorageConfig(config: UserAttachmentStorag
}
return config;
});
publishBossEvent("storage.updated");
return result;
}
export async function getMasterAgentPromptPolicy() {
@@ -4556,7 +4562,7 @@ export async function updateMasterAgentPromptPolicy(input: {
throw new Error("MASTER_AGENT_PROMPT_REQUIRED");
}
return mutateState((state) => {
const result = await mutateState((state) => {
const policy: MasterAgentPromptPolicy = {
globalPrompt,
updatedBy: input.updatedBy?.trim() || undefined,
@@ -4565,6 +4571,8 @@ export async function updateMasterAgentPromptPolicy(input: {
state.masterAgentPromptPolicy = policy;
return policy;
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function getUserMasterPrompt(account: string) {
@@ -4578,7 +4586,7 @@ export async function updateUserMasterPrompt(account: string, content: string) {
throw new Error("USER_MASTER_PROMPT_REQUIRED");
}
return mutateState((state) => {
const result = await mutateState((state) => {
const next: UserMasterPrompt = {
account,
content: trimmedContent,
@@ -4592,14 +4600,18 @@ export async function updateUserMasterPrompt(account: string, content: string) {
}
return next;
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function clearUserMasterPrompt(account: string) {
return mutateState((state) => {
const result = await mutateState((state) => {
const before = state.userMasterPrompts.length;
state.userMasterPrompts = state.userMasterPrompts.filter((item) => item.account !== account);
return { cleared: before !== state.userMasterPrompts.length };
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function listUserMasterMemories(
@@ -4647,7 +4659,7 @@ export async function createUserMasterMemory(input: {
throw new Error("USER_MASTER_MEMORY_PROJECT_ID_REQUIRED");
}
return mutateState((state) => {
const result = await mutateState((state) => {
const now = nowIso();
const memory: MasterAgentMemory = {
memoryId: randomToken("memory"),
@@ -4667,6 +4679,8 @@ export async function createUserMasterMemory(input: {
state.masterAgentMemories.unshift(memory);
return memory;
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function updateUserMasterMemory(
@@ -4679,7 +4693,7 @@ export async function updateUserMasterMemory(
>
>,
) {
return mutateState((state) => {
const result = await mutateState((state) => {
const memory = state.masterAgentMemories.find(
(item) => item.memoryId === memoryId && item.account === account,
);
@@ -4721,10 +4735,12 @@ export async function updateUserMasterMemory(
memory.updatedAt = nowIso();
return memory;
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function archiveUserMasterMemory(memoryId: string, account: string) {
return mutateState((state) => {
const result = await mutateState((state) => {
const memory = state.masterAgentMemories.find(
(item) => item.memoryId === memoryId && item.account === account,
);
@@ -4736,6 +4752,8 @@ export async function archiveUserMasterMemory(memoryId: string, account: string)
memory.updatedAt = nowIso();
return memory;
});
publishBossEvent("master_agent.settings.updated", { projectId: "master-agent" });
return result;
}
export async function touchUserMasterMemories(memoryIds: string[], account: string) {
@@ -5509,7 +5527,7 @@ export async function saveAiAccount(payload: {
setActive?: boolean;
loginStatusNote?: string;
}) {
return mutateState((state) => {
const result = await mutateState((state) => {
const existing = payload.accountId
? state.aiAccounts.find((item) => item.accountId === payload.accountId)
: null;
@@ -5580,13 +5598,15 @@ export async function saveAiAccount(payload: {
return buildAiAccountSummary(next);
});
publishBossEvent("ai_accounts.updated");
return result;
}
export async function deleteAiAccount(accountId: string) {
if (accountId === ENV_OPENAI_ACCOUNT_ID) {
throw new Error("ENV_AI_ACCOUNT_READ_ONLY");
}
return mutateState((state) => {
const result = await mutateState((state) => {
const target = state.aiAccounts.find((item) => item.accountId === accountId);
if (!target) {
throw new Error("AI_ACCOUNT_NOT_FOUND");
@@ -5600,12 +5620,14 @@ export async function deleteAiAccount(accountId: string) {
}
return true;
});
publishBossEvent("ai_accounts.updated");
return result;
}
export async function activateAiAccount(accountId: string, reason: string) {
if (accountId === ENV_OPENAI_ACCOUNT_ID) {
const state = await readState();
return {
const result = {
activeIdentity: {
...getMasterIdentitySummaryFromState(state),
accountId: ENV_OPENAI_ACCOUNT_ID,
@@ -5617,13 +5639,17 @@ export async function activateAiAccount(accountId: string, reason: string) {
isEnvironmentFallback: true,
},
};
publishBossEvent("ai_accounts.updated");
return result;
}
return mutateState((state) => {
const result = await mutateState((state) => {
setActiveAiAccountInState(state, accountId, reason);
return {
activeIdentity: getMasterIdentitySummaryFromState(state),
};
});
publishBossEvent("ai_accounts.updated");
return result;
}
export async function updateAiAccountHealth(params: {
@@ -5661,6 +5687,7 @@ export async function updateAiAccountHealth(params: {
);
}
});
publishBossEvent("ai_accounts.updated");
}
export async function getMasterAgentRuntimeAccount() {