feat: refine mobile master agent sync and chat rendering
This commit is contained in:
@@ -9,6 +9,7 @@ let replyToMasterAgentUserMessage: (typeof import("../src/lib/boss-master-agent"
|
||||
let saveAiAccount: (typeof import("../src/lib/boss-data"))["saveAiAccount"];
|
||||
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
||||
let updateAiAccountHealth: (typeof import("../src/lib/boss-data"))["updateAiAccountHealth"];
|
||||
let updateProjectAgentControls: (typeof import("../src/lib/boss-data"))["updateProjectAgentControls"];
|
||||
|
||||
async function setup() {
|
||||
if (runtimeRoot) return;
|
||||
@@ -26,6 +27,18 @@ async function setup() {
|
||||
saveAiAccount = data.saveAiAccount;
|
||||
readState = data.readState;
|
||||
updateAiAccountHealth = data.updateAiAccountHealth;
|
||||
updateProjectAgentControls = data.updateProjectAgentControls;
|
||||
}
|
||||
|
||||
async function waitFor(predicate: () => Promise<boolean>, timeoutMs = 5_000) {
|
||||
const startedAt = Date.now();
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
if (await predicate()) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
throw new Error("waitFor timed out");
|
||||
}
|
||||
|
||||
test.after(async () => {
|
||||
@@ -322,6 +335,74 @@ test("replyToMasterAgentUserMessage retries the next ready API backup when the f
|
||||
}
|
||||
});
|
||||
|
||||
test("replyToMasterAgentUserMessage 在快速反应模式遇到复杂请求时会自动切到深度思考模型并排队执行", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "openai-primary-smart-upgrade",
|
||||
label: "OpenAI 主控",
|
||||
role: "primary",
|
||||
provider: "openai_api",
|
||||
displayName: "OpenAI 主账号",
|
||||
model: "gpt-5.4",
|
||||
apiKey: "sk-openai-smart-upgrade",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "主 OpenAI 账号。",
|
||||
});
|
||||
|
||||
await updateProjectAgentControls("master-agent", {
|
||||
modelOverride: "gpt-4.1",
|
||||
reasoningEffortOverride: "low",
|
||||
fastModelOverride: "gpt-4.1",
|
||||
deepModelOverride: "gpt-5.4",
|
||||
});
|
||||
|
||||
const fetchCalls: Array<{ url: string; body: unknown }> = [];
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = (async (input, init) => {
|
||||
const body = typeof init?.body === "string" ? JSON.parse(init.body) : init?.body ?? null;
|
||||
fetchCalls.push({ url: String(input), body });
|
||||
return new Response(JSON.stringify({ output_text: "已经自动切到深度思考模型。" }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"x-request-id": "req-master-smart-upgrade",
|
||||
},
|
||||
});
|
||||
}) as typeof fetch;
|
||||
|
||||
try {
|
||||
const result = await replyToMasterAgentUserMessage({
|
||||
requestMessageId: "msg-master-smart-upgrade",
|
||||
requestText: "请深入分析当前主 Agent 架构,并给出分阶段实现方案、风险和回归测试建议。",
|
||||
requestedBy: "Boss 超级管理员",
|
||||
requestedByAccount: "17600003315",
|
||||
mode: "smart",
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.accountId, "openai-primary-smart-upgrade");
|
||||
assert.equal(result.masterReplyState, "queued");
|
||||
assert.equal(result.autoEscalated, true);
|
||||
assert.ok(result.taskId, "expected a queued task after smart deep-upgrade");
|
||||
|
||||
await waitFor(async () => {
|
||||
const state = await readState();
|
||||
const task = state.masterAgentTasks.find((item) => item.taskId === result.taskId);
|
||||
return task?.status === "completed";
|
||||
});
|
||||
|
||||
assert.equal(fetchCalls.length, 1);
|
||||
const requestBody = fetchCalls[0]?.body as {
|
||||
model?: string;
|
||||
reasoning?: { effort?: string };
|
||||
};
|
||||
assert.equal(requestBody?.model, "gpt-5.4");
|
||||
assert.equal(requestBody?.reasoning?.effort, "high");
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("replyToMasterAgentUserMessage falls back to a ready backup master node account when API backends are unavailable", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "master-codex-primary-offline",
|
||||
|
||||
Reference in New Issue
Block a user