feat: let master-agent dispatch real threads
This commit is contained in:
@@ -2,6 +2,17 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireRequestSession } from "@/lib/boss-auth";
|
||||
import { confirmDispatchPlanAndCreateExecutions } from "@/lib/boss-data";
|
||||
|
||||
function confirmFailureMessage(error?: string) {
|
||||
switch (error) {
|
||||
case "DISPATCH_TARGET_DEVICE_OFFLINE":
|
||||
return "目标线程所在设备当前不在线,请先让设备上线后再确认下发。";
|
||||
case "DISPATCH_TARGET_THREAD_BINDING_REQUIRED":
|
||||
return "目标线程还没有绑定真实 Codex 线程,请先修复群成员或重新导入线程后再试。";
|
||||
default:
|
||||
return error ?? "UNKNOWN_ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string; planId: string }> },
|
||||
@@ -36,8 +47,13 @@ export async function POST(
|
||||
collaborationGate: result.collaborationGate,
|
||||
});
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : "UNKNOWN_ERROR";
|
||||
return NextResponse.json(
|
||||
{ ok: false, message: error instanceof Error ? error.message : "UNKNOWN_ERROR" },
|
||||
{
|
||||
ok: false,
|
||||
code: reason,
|
||||
message: confirmFailureMessage(reason),
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export async function POST(
|
||||
if (!project) {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
|
||||
}
|
||||
if (!project.isGroup) {
|
||||
if (!project.isGroup && project.id !== "master-agent") {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_GROUP_CHAT" }, { status: 400 });
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
queueGroupDispatchPlan,
|
||||
queueThreadConversationReplyTask,
|
||||
replyToMasterAgentUserMessage,
|
||||
shouldRecommendMasterAgentDispatchPlan,
|
||||
} from "@/lib/boss-master-agent";
|
||||
import { evaluatePermissionPolicy } from "@/lib/execution/permission-policy";
|
||||
|
||||
@@ -19,6 +20,17 @@ function dispatchFailureNotice(error?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function threadConversationFailureMessage(error?: string) {
|
||||
switch (error) {
|
||||
case "THREAD_BINDING_REQUIRED":
|
||||
return "当前线程还没有绑定真实 Codex 线程,请先重新导入该线程后再试。";
|
||||
case "THREAD_TARGET_DEVICE_OFFLINE":
|
||||
return "当前线程所在设备不在线,请先让对应设备上线后再试。";
|
||||
default:
|
||||
return error ?? "UNKNOWN_ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string }> },
|
||||
@@ -37,8 +49,10 @@ export async function POST(
|
||||
const state = await readState();
|
||||
const project = state.projects.find((item) => item.id === projectId);
|
||||
const shouldCreateDispatchPlan =
|
||||
project?.isGroup &&
|
||||
project.id !== "master-agent" &&
|
||||
Boolean(project) &&
|
||||
((project?.isGroup && project.id !== "master-agent") ||
|
||||
(project?.id === "master-agent" &&
|
||||
shouldRecommendMasterAgentDispatchPlan(state, (body.body ?? "").trim()))) &&
|
||||
(body.kind ?? "text") === "text" &&
|
||||
(body.body ?? "").trim().length > 0;
|
||||
|
||||
@@ -195,8 +209,13 @@ export async function POST(
|
||||
collaborationGate,
|
||||
});
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : "UNKNOWN_ERROR";
|
||||
return NextResponse.json(
|
||||
{ ok: false, message: error instanceof Error ? error.message : "UNKNOWN_ERROR" },
|
||||
{
|
||||
ok: false,
|
||||
code: reason,
|
||||
message: threadConversationFailureMessage(reason),
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user