feat: add omx orchestration backend selection
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireRequestSession } from "@/lib/boss-auth";
|
||||
import {
|
||||
getProject,
|
||||
getProjectOrchestrationBackendState,
|
||||
updateProjectOrchestrationBackend,
|
||||
} from "@/lib/boss-data";
|
||||
|
||||
function normalizeRequestedBackendId(value: unknown) {
|
||||
return value === "omx-team" ? "omx-team" : "boss-native-orchestrator";
|
||||
}
|
||||
|
||||
async function readGroupProjectOrNotFound(projectId: string) {
|
||||
const project = await getProject(projectId);
|
||||
if (!project) {
|
||||
return { ok: false as const, response: NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 }) };
|
||||
}
|
||||
if (!project.isGroup) {
|
||||
return {
|
||||
ok: false as const,
|
||||
response: NextResponse.json({ ok: false, message: "PROJECT_NOT_GROUP_CHAT" }, { status: 400 }),
|
||||
};
|
||||
}
|
||||
return { ok: true as const, project };
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string }> },
|
||||
) {
|
||||
const session = await requireRequestSession(request);
|
||||
if (!session) {
|
||||
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await context.params;
|
||||
const projectCheck = await readGroupProjectOrNotFound(projectId);
|
||||
if (!projectCheck.ok) {
|
||||
return projectCheck.response;
|
||||
}
|
||||
|
||||
const state = await getProjectOrchestrationBackendState(projectId);
|
||||
if (!state) {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
...state,
|
||||
requestedBackendId: projectCheck.project.orchestrationBackendOverride ?? null,
|
||||
requestedBackendLabel: projectCheck.project.orchestrationBackendOverride
|
||||
? state.requestedBackendLabel
|
||||
: null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string }> },
|
||||
) {
|
||||
const session = await requireRequestSession(request);
|
||||
if (!session) {
|
||||
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await context.params;
|
||||
const projectCheck = await readGroupProjectOrNotFound(projectId);
|
||||
if (!projectCheck.ok) {
|
||||
return projectCheck.response;
|
||||
}
|
||||
|
||||
const rawBody = await request.text().catch(() => "");
|
||||
let body: unknown;
|
||||
try {
|
||||
body = JSON.parse(rawBody);
|
||||
} catch {
|
||||
return NextResponse.json({ ok: false, message: "INVALID_JSON_PAYLOAD" }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
||||
return NextResponse.json({ ok: false, message: "INVALID_ORCHESTRATION_BACKEND_PAYLOAD" }, { status: 400 });
|
||||
}
|
||||
|
||||
const payload = body as {
|
||||
orchestrationBackendOverride?: unknown;
|
||||
backendId?: unknown;
|
||||
requestedBackendId?: unknown;
|
||||
};
|
||||
const hasOrchestrationBackendOverride = Object.prototype.hasOwnProperty.call(
|
||||
payload,
|
||||
"orchestrationBackendOverride",
|
||||
);
|
||||
const hasBackendId = Object.prototype.hasOwnProperty.call(payload, "backendId");
|
||||
const hasRequestedBackendId = Object.prototype.hasOwnProperty.call(payload, "requestedBackendId");
|
||||
if (!hasOrchestrationBackendOverride && !hasBackendId && !hasRequestedBackendId) {
|
||||
return NextResponse.json({ ok: false, message: "INVALID_ORCHESTRATION_BACKEND_PAYLOAD" }, { status: 400 });
|
||||
}
|
||||
|
||||
const requestedBackendId = normalizeRequestedBackendId(
|
||||
hasOrchestrationBackendOverride
|
||||
? payload.orchestrationBackendOverride
|
||||
: hasRequestedBackendId
|
||||
? payload.requestedBackendId
|
||||
: payload.backendId,
|
||||
);
|
||||
|
||||
try {
|
||||
await updateProjectOrchestrationBackend(projectId, requestedBackendId);
|
||||
const state = await getProjectOrchestrationBackendState(projectId);
|
||||
if (!state) {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true, ...state });
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, message: error instanceof Error ? error.message : "UNKNOWN_ERROR" },
|
||||
{ status: error instanceof Error && error.message === "PROJECT_NOT_FOUND" ? 404 : 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,15 @@ import {
|
||||
MasterIdentityPill,
|
||||
PageNav,
|
||||
ProjectHeaderActions,
|
||||
ProjectOrchestrationBackendCard,
|
||||
StatusBar,
|
||||
} from "@/components/app-ui";
|
||||
import { requirePageSession } from "@/lib/boss-auth";
|
||||
import { listDispatchPlansByProject, readState } from "@/lib/boss-data";
|
||||
import {
|
||||
getProjectOrchestrationBackendState,
|
||||
listDispatchPlansByProject,
|
||||
readState,
|
||||
} from "@/lib/boss-data";
|
||||
import { resolveDispatchPlanComposerState } from "@/lib/dispatch-plan-ui";
|
||||
import { formatTimestampLabel, getProjectDetailView } from "@/lib/boss-projections";
|
||||
|
||||
@@ -30,6 +35,9 @@ export default async function ProjectChatPage({
|
||||
const dispatchPlanState = detail?.project.isGroup
|
||||
? resolveDispatchPlanComposerState(await listDispatchPlansByProject(projectId))
|
||||
: resolveDispatchPlanComposerState([]);
|
||||
const orchestrationBackendState = detail?.project.isGroup
|
||||
? await getProjectOrchestrationBackendState(projectId)
|
||||
: null;
|
||||
|
||||
if (!detail) notFound();
|
||||
|
||||
@@ -76,6 +84,14 @@ export default async function ProjectChatPage({
|
||||
<div className="pt-3">
|
||||
<ProjectHeaderActions projectId={detail.project.id} />
|
||||
</div>
|
||||
{detail.project.isGroup && orchestrationBackendState ? (
|
||||
<div className="mt-3">
|
||||
<ProjectOrchestrationBackendCard
|
||||
projectId={detail.project.id}
|
||||
initialState={orchestrationBackendState}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="mt-4 space-y-3">
|
||||
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
|
||||
<div className="text-[14px] font-semibold text-[#111111]">主 Agent 调度结论</div>
|
||||
|
||||
Reference in New Issue
Block a user