Merge pull request #2780 from pikasTech/fix/workbench-native-projection-state-20260723
Pipelines as Code CI / hwlab-nc01-v03-ci-poll-d0174c25bbb9d744fe5a9b555174684af0146089 Success
Pipelines as Code CI / hwlab-nc01-v03-ci-poll-d0174c25bbb9d744fe5a9b555174684af0146089 Success
修正 Workbench 原生投影诊断状态
This commit is contained in:
@@ -178,15 +178,29 @@ async function nativeTurn(options: { snapshot?: () => Promise<any>; mode?: Workb
|
||||
const turn = state.turns[traceId];
|
||||
const projected = options.mode === "agentrun-native" ? options.kafkaEventBridge?.workbenchTurnSnapshot?.(traceId) : null;
|
||||
if (!turn && !projected?.turn) return json(404, { ok: false, error: { code: "turn_not_found", message: "native turn was not found" } });
|
||||
const projectedAgentRun = projected?.turn ? nativeProjectedAgentRun(turn?.agentRun, projected.turn) : turn?.agentRun;
|
||||
return json(200, {
|
||||
ok: true,
|
||||
...(turn ?? {}),
|
||||
...(projected?.turn ?? {}),
|
||||
agentRun: projectedAgentRun ?? null,
|
||||
projectionStatus: projected?.turn?.projectionStatus ?? (projected?.ok === false ? "degraded" : turn?.terminal === true ? "caught-up" : "projecting"),
|
||||
projectionWarning: projected?.warning ?? null,
|
||||
mode: options.mode ?? "native-test"
|
||||
});
|
||||
}
|
||||
function nativeProjectedAgentRun(admission: any, turn: any) {
|
||||
return {
|
||||
adapter: text(admission?.adapter) || "agentrun-v02",
|
||||
runId: text(turn?.sourceRunId) || text(admission?.runId) || null,
|
||||
commandId: text(turn?.sourceCommandId) || text(admission?.commandId) || null,
|
||||
namespace: text(admission?.namespace) || null,
|
||||
backendProfile: text(admission?.backendProfile) || null,
|
||||
status: text(turn?.status) || "running",
|
||||
terminalStatus: turn?.terminal === true ? text(turn?.status) || null : null,
|
||||
valuesPrinted: false
|
||||
};
|
||||
}
|
||||
function nativeTrace(options: { mode?: WorkbenchMode; kafkaEventBridge?: any }, traceId: string) {
|
||||
const projected = options.mode === "agentrun-native" ? options.kafkaEventBridge?.workbenchTraceSnapshot?.(traceId) : null;
|
||||
if (!projected?.trace) {
|
||||
|
||||
@@ -245,7 +245,15 @@ describe("Workbench native HTTP adapter", () => {
|
||||
async snapshot() {
|
||||
return {
|
||||
sessions: {},
|
||||
turns: { [traceId]: { traceId, sessionId: "ses_native_projection", status: "running", terminal: false } }
|
||||
turns: {
|
||||
[traceId]: {
|
||||
traceId,
|
||||
sessionId: "ses_native_projection",
|
||||
status: "running",
|
||||
terminal: false,
|
||||
agentRun: { adapter: "agentrun-v01", runId: "run_projection", commandId: "cmd_projection", runStatus: "pending", commandState: "pending" }
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
kafkaEventBridge: {
|
||||
@@ -272,7 +280,10 @@ describe("Workbench native HTTP adapter", () => {
|
||||
for (const pathname of [`/v1/workbench/turns/${traceId}`, `/v1/agent/turns/${traceId}`, `/v1/agent/chat/result/${traceId}`]) {
|
||||
const response = await app.fetch(new Request(`http://native.test${pathname}`));
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toMatchObject(projectedTurn);
|
||||
const body = await response.json();
|
||||
expect(body).toMatchObject({ ...projectedTurn, agentRun: { runId: "run_projection", commandId: "cmd_projection", status: "completed", terminalStatus: "completed" } });
|
||||
expect(body.agentRun.runStatus).toBeUndefined();
|
||||
expect(body.agentRun.commandState).toBeUndefined();
|
||||
}
|
||||
const traceResponse = await app.fetch(new Request(`http://native.test/v1/agent/traces/${traceId}`));
|
||||
expect(traceResponse.status).toBe(200);
|
||||
|
||||
Reference in New Issue
Block a user