feat: 支持 v0.1 deepseek backend profile
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { BackendTurnResult, CommandRecord, RunRecord } from "../common/types.js";
|
||||
import { runCodexStdioTurn, type CodexStdioTurnOptions } from "./codex-stdio.js";
|
||||
import { backendProfileSpec } from "../common/backend-profiles.js";
|
||||
|
||||
export interface BackendAdapterOptions {
|
||||
codexCommand?: string;
|
||||
@@ -9,11 +10,13 @@ export interface BackendAdapterOptions {
|
||||
}
|
||||
|
||||
export async function runBackendTurn(run: RunRecord, command: CommandRecord, options: BackendAdapterOptions = {}): Promise<BackendTurnResult> {
|
||||
if (run.backendProfile !== "codex") {
|
||||
const spec = backendProfileSpec(run.backendProfile);
|
||||
if (!spec || spec.backendKind !== "codex-app-server-stdio") {
|
||||
return { terminalStatus: "failed", failureKind: "backend-failed", failureMessage: `unsupported backendProfile ${run.backendProfile}`, events: [{ type: "error", payload: { failureKind: "backend-failed", backendProfile: run.backendProfile } }] };
|
||||
}
|
||||
const prompt = typeof command.payload.prompt === "string" ? command.payload.prompt : JSON.stringify(command.payload);
|
||||
const turnOptions: CodexStdioTurnOptions = {
|
||||
backendProfile: run.backendProfile,
|
||||
prompt,
|
||||
cwd: typeof run.workspaceRef.path === "string" ? run.workspaceRef.path : process.cwd(),
|
||||
approvalPolicy: run.executionPolicy.approval,
|
||||
|
||||
@@ -4,8 +4,9 @@ import { accessSync, constants as fsConstants } from "node:fs";
|
||||
import { chmod, copyFile, mkdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import * as readline from "node:readline";
|
||||
import type { BackendEvent, BackendTurnResult, FailureKind, JsonRecord, JsonValue, TerminalStatus } from "../common/types.js";
|
||||
import type { BackendEvent, BackendProfile, BackendTurnResult, FailureKind, JsonRecord, JsonValue, TerminalStatus } from "../common/types.js";
|
||||
import { redactJson, redactText } from "../common/redaction.js";
|
||||
import { backendProfileSpec } from "../common/backend-profiles.js";
|
||||
|
||||
const codexProtocol = "codex-app-server-jsonrpc-stdio";
|
||||
const defaultCodexArgs = ["app-server", "--listen", "stdio://"];
|
||||
@@ -32,6 +33,7 @@ const childEnvSummaryKeys = [
|
||||
];
|
||||
|
||||
export interface CodexStdioTurnOptions {
|
||||
backendProfile?: BackendProfile;
|
||||
prompt: string;
|
||||
cwd: string;
|
||||
model?: string;
|
||||
@@ -266,6 +268,7 @@ export async function runCodexStdioTurn(options: CodexStdioTurnOptions): Promise
|
||||
type: "backend_status",
|
||||
payload: {
|
||||
phase: "codex-app-server-starting",
|
||||
...backendMetadata(options),
|
||||
protocol: codexProtocol,
|
||||
runtime: runtimeSummary(options, env, codexHome),
|
||||
},
|
||||
@@ -307,7 +310,7 @@ export async function runCodexStdioTurn(options: CodexStdioTurnOptions): Promise
|
||||
const initializeResult = requireResponseRecord(await client.request("initialize", { clientInfo: { name: "agentrun", title: "AgentRun", version: "0.1.0" }, capabilities: { experimentalApi: true } }, requestTimeoutMs), "initialize");
|
||||
validateInitializeResponse(initializeResult);
|
||||
client.notify("initialized", {});
|
||||
events.push({ type: "backend_status", payload: { phase: "initialize:completed", protocol: codexProtocol } });
|
||||
events.push({ type: "backend_status", payload: { phase: "initialize:completed", ...backendMetadata(options), protocol: codexProtocol } });
|
||||
|
||||
const threadMethod = options.threadId ? "thread/resume" : "thread/start";
|
||||
const threadParams: JsonRecord = options.threadId
|
||||
@@ -525,6 +528,17 @@ function runtimeSummary(options: CodexStdioTurnOptions, env: NodeJS.ProcessEnv,
|
||||
};
|
||||
}
|
||||
|
||||
function backendMetadata(options: CodexStdioTurnOptions): JsonRecord {
|
||||
const profile = options.backendProfile ?? "codex";
|
||||
const spec = backendProfileSpec(profile);
|
||||
return {
|
||||
backendProfile: profile,
|
||||
backendKind: spec?.backendKind ?? "codex-app-server-stdio",
|
||||
protocol: spec?.protocol ?? codexProtocol,
|
||||
transport: spec?.transport ?? "stdio",
|
||||
};
|
||||
}
|
||||
|
||||
function envSummary(env: NodeJS.ProcessEnv): JsonRecord {
|
||||
const keyState: Record<string, JsonValue> = {};
|
||||
for (const key of childEnvSummaryKeys) keyState[key] = { present: typeof env[key] === "string" && String(env[key]).length > 0 };
|
||||
|
||||
Reference in New Issue
Block a user