Add thread execution conflict guards to chat flows
This commit is contained in:
@@ -2,10 +2,12 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireRequestSession } from "@/lib/boss-auth";
|
||||
import { appendProjectMessage, buildCollaborationGate, readState } from "@/lib/boss-data";
|
||||
import {
|
||||
getThreadConversationExecutionConflict,
|
||||
queueGroupDispatchPlan,
|
||||
queueThreadConversationReplyTask,
|
||||
replyToMasterAgentUserMessage,
|
||||
shouldRecommendMasterAgentDispatchPlan,
|
||||
ThreadConversationExecutionConflictError,
|
||||
} from "@/lib/boss-master-agent";
|
||||
import { evaluatePermissionPolicy } from "@/lib/execution/permission-policy";
|
||||
|
||||
@@ -26,6 +28,8 @@ function threadConversationFailureMessage(error?: string) {
|
||||
return "当前线程还没有绑定真实 Codex 线程,请先重新导入该线程后再试。";
|
||||
case "THREAD_TARGET_DEVICE_OFFLINE":
|
||||
return "当前线程所在设备不在线,请先让对应设备上线后再试。";
|
||||
case "THREAD_EXECUTION_CONFLICT":
|
||||
return "当前线程命中了 GUI / CLI 冲突保护,请先确认本项目是否放行后再继续发送。";
|
||||
default:
|
||||
return error ?? "UNKNOWN_ERROR";
|
||||
}
|
||||
@@ -80,6 +84,27 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
|
||||
const singleThreadExecutionConflict =
|
||||
project &&
|
||||
projectId !== "master-agent" &&
|
||||
!project.isGroup &&
|
||||
(body.kind ?? "text") === "text" &&
|
||||
(body.body ?? "").trim().length > 0
|
||||
? await getThreadConversationExecutionConflict(projectId)
|
||||
: null;
|
||||
|
||||
if (singleThreadExecutionConflict) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
code: "THREAD_EXECUTION_CONFLICT",
|
||||
message: threadConversationFailureMessage("THREAD_EXECUTION_CONFLICT"),
|
||||
executionConflict: singleThreadExecutionConflict,
|
||||
},
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
const message = await appendProjectMessage({
|
||||
projectId,
|
||||
senderLabel: session.displayName || "你",
|
||||
@@ -209,6 +234,17 @@ export async function POST(
|
||||
collaborationGate,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof ThreadConversationExecutionConflictError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
code: error.message,
|
||||
message: threadConversationFailureMessage(error.message),
|
||||
executionConflict: error.conflict,
|
||||
},
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
const reason = error instanceof Error ? error.message : "UNKNOWN_ERROR";
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user