refactor: add remote runtime adapter

This commit is contained in:
kris
2026-04-03 00:24:11 +08:00
parent 8a62e72fd5
commit 70e8a13368
5 changed files with 144 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { authorizeDeviceWriteRequest } from "@/lib/boss-device-auth";
import { completeMasterAgentTask } from "@/lib/boss-data";
import { normalizeRemoteExecutionResult } from "@/lib/execution/remote-runtime-adapter";
export async function POST(
request: NextRequest,
@@ -30,17 +31,18 @@ export async function POST(
const { taskId } = await context.params;
try {
const normalized = normalizeRemoteExecutionResult(body);
const task = await completeMasterAgentTask({
taskId,
deviceId: body.deviceId.trim(),
status: body.status === "failed" ? "failed" : "completed",
replyBody: body.replyBody,
errorMessage: body.errorMessage,
requestId: body.requestId,
dispatchExecutionId: body.dispatchExecutionId,
targetProjectId: body.targetProjectId,
targetThreadId: body.targetThreadId,
rawThreadReply: body.rawThreadReply,
status: normalized.status,
replyBody: normalized.replyBody,
errorMessage: normalized.errorMessage,
requestId: normalized.requestId,
dispatchExecutionId: normalized.dispatchExecutionId,
targetProjectId: normalized.targetProjectId,
targetThreadId: normalized.targetThreadId,
rawThreadReply: normalized.rawThreadReply,
});
return NextResponse.json({ ok: true, task });
} catch (error) {

View File

@@ -0,0 +1,11 @@
import type { OrchestrationBackend } from "@/lib/execution/orchestration-backend";
export const BOSS_NATIVE_ORCHESTRATOR: OrchestrationBackend = {
backendId: "boss-native-orchestrator",
async describe() {
return {
backendId: "boss-native-orchestrator",
label: "Boss Native Orchestrator",
};
},
};

View File

@@ -0,0 +1,43 @@
export interface RemoteExecutionResultInput {
status: "completed" | "failed";
dispatchExecutionId?: string;
targetProjectId?: string;
targetThreadId?: string;
rawThreadReply?: string;
replyBody?: string;
errorMessage?: string;
requestId?: string;
}
export interface NormalizedRemoteExecutionResult {
status: "completed" | "failed";
dispatchExecutionId?: string;
targetProjectId?: string;
targetThreadId?: string;
rawThreadReply?: string;
replyBody?: string;
errorMessage?: string;
requestId?: string;
}
function trimToDefined(value: string | undefined) {
const trimmed = value?.trim();
return trimmed ? trimmed : undefined;
}
export function normalizeRemoteExecutionResult(
input: RemoteExecutionResultInput,
): NormalizedRemoteExecutionResult {
return {
status: input.status === "failed" ? "failed" : "completed",
dispatchExecutionId: trimToDefined(input.dispatchExecutionId),
targetProjectId: trimToDefined(input.targetProjectId),
targetThreadId: trimToDefined(input.targetThreadId),
rawThreadReply: trimToDefined(input.rawThreadReply),
replyBody: trimToDefined(input.replyBody),
errorMessage: trimToDefined(input.errorMessage),
requestId: trimToDefined(input.requestId),
};
}
export const normalizeRemoteExecutionResultForTesting = normalizeRemoteExecutionResult;