feat: 补齐 HWLAB 手动调度能力
This commit is contained in:
@@ -6,6 +6,8 @@ export interface BackendAdapterOptions {
|
||||
codexCommand?: string;
|
||||
codexArgs?: string[];
|
||||
codexHome?: string;
|
||||
workspacePath?: string;
|
||||
abortSignal?: AbortSignal;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
@@ -18,16 +20,18 @@ export async function runBackendTurn(run: RunRecord, command: CommandRecord, opt
|
||||
const turnOptions: CodexStdioTurnOptions = {
|
||||
backendProfile: run.backendProfile,
|
||||
prompt,
|
||||
cwd: typeof run.workspaceRef.path === "string" ? run.workspaceRef.path : process.cwd(),
|
||||
cwd: options.workspacePath ?? (typeof run.workspaceRef.path === "string" ? run.workspaceRef.path : process.cwd()),
|
||||
approvalPolicy: run.executionPolicy.approval,
|
||||
sandbox: run.executionPolicy.sandbox,
|
||||
timeoutMs: run.executionPolicy.timeoutMs,
|
||||
};
|
||||
if (typeof command.payload.model === "string") turnOptions.model = command.payload.model;
|
||||
if (typeof command.payload.threadId === "string") turnOptions.threadId = command.payload.threadId;
|
||||
else if (typeof run.sessionRef?.threadId === "string") turnOptions.threadId = run.sessionRef.threadId;
|
||||
if (options.codexCommand) turnOptions.command = options.codexCommand;
|
||||
if (options.codexArgs) turnOptions.args = options.codexArgs;
|
||||
if (options.env) turnOptions.env = options.env;
|
||||
if (options.codexHome) turnOptions.codexHome = options.codexHome;
|
||||
if (options.abortSignal) turnOptions.abortSignal = options.abortSignal;
|
||||
return runCodexStdioTurn(turnOptions);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ export interface CodexStdioTurnOptions {
|
||||
args?: string[];
|
||||
env?: NodeJS.ProcessEnv;
|
||||
codexHome?: string;
|
||||
abortSignal?: AbortSignal;
|
||||
}
|
||||
|
||||
interface PendingRequest {
|
||||
@@ -273,6 +274,12 @@ export async function runCodexStdioTurn(options: CodexStdioTurnOptions): Promise
|
||||
runtime: runtimeSummary(options, env, codexHome),
|
||||
},
|
||||
}];
|
||||
if (options.abortSignal?.aborted) {
|
||||
const cancelled = { status: "cancelled" as const, failureKind: "cancelled" as const, message: "cancel requested" };
|
||||
events.push({ type: "backend_status", payload: { phase: "turn-cancelled", failureKind: "cancelled" } });
|
||||
events.push({ type: "terminal_status", payload: { terminalStatus: cancelled.status, failureKind: cancelled.failureKind, message: cancelled.message } });
|
||||
return { terminalStatus: cancelled.status, failureKind: cancelled.failureKind, failureMessage: cancelled.message, events: events.map((event) => ({ ...event, payload: redactJson(event.payload) })) };
|
||||
}
|
||||
let assistantText = "";
|
||||
let threadId: string | undefined = options.threadId;
|
||||
let turnId: string | undefined;
|
||||
@@ -281,6 +288,14 @@ export async function runCodexStdioTurn(options: CodexStdioTurnOptions): Promise
|
||||
const terminalPromise = new Promise<void>((resolve) => { terminalResolve = resolve; });
|
||||
let client: CodexStdioClient | null = null;
|
||||
const requestTimeoutMs = Math.min(positiveTimeout(options.timeoutMs), requestTimeoutCapMs);
|
||||
const abortTurn = (): void => {
|
||||
if (terminal) return;
|
||||
terminal = { status: "cancelled", failureKind: "cancelled", message: "cancel requested" };
|
||||
events.push({ type: "backend_status", payload: { phase: "turn-cancelled", failureKind: "cancelled" } });
|
||||
client?.stop();
|
||||
terminalResolve();
|
||||
};
|
||||
options.abortSignal?.addEventListener("abort", abortTurn, { once: true });
|
||||
const timeout = setTimeout(() => {
|
||||
if (terminal) return;
|
||||
terminal = { status: "failed", failureKind: "backend-timeout", message: `codex stdio turn timed out after ${options.timeoutMs}ms` };
|
||||
@@ -340,6 +355,7 @@ export async function runCodexStdioTurn(options: CodexStdioTurnOptions): Promise
|
||||
events.push({ type: "error", payload: { failureKind: failure.failureKind, message: failure.message, phase: failure.phase, details: failure.details } });
|
||||
}
|
||||
} finally {
|
||||
options.abortSignal?.removeEventListener("abort", abortTurn);
|
||||
clearTimeout(timeout);
|
||||
if (client) {
|
||||
client.stop();
|
||||
|
||||
Reference in New Issue
Block a user