fix(agentrun): 简化 Artificer Target 派单
This commit is contained in:
@@ -74,7 +74,23 @@ export function parseAgentRunClientConfigYaml(raw: string, sourcePath = "config/
|
||||
const role = stringFieldFromRecord(client, "role", "client");
|
||||
const transport = stringFieldFromRecord(client, "transport", "client");
|
||||
if (role !== "render-only") throw new Error(`${sourcePath}: client.role must be render-only`);
|
||||
if (transport !== "direct-http") throw new Error(`${sourcePath}: client.transport must be direct-http`);
|
||||
if (transport !== "direct-http" && transport !== "target-trans") {
|
||||
throw new Error(`${sourcePath}: client.transport must be direct-http or target-trans`);
|
||||
}
|
||||
const targetExecutionInput = record(client.targetExecution);
|
||||
const targetExecution = transport === "target-trans"
|
||||
? {
|
||||
markerEnv: environmentVariableField(
|
||||
stringFieldFromRecord(targetExecutionInput, "markerEnv", "client.targetExecution"),
|
||||
`${sourcePath}: client.targetExecution.markerEnv`,
|
||||
),
|
||||
executable: stringFieldFromRecord(targetExecutionInput, "executable", "client.targetExecution"),
|
||||
cliPath: relativePathField(
|
||||
stringFieldFromRecord(targetExecutionInput, "cliPath", "client.targetExecution"),
|
||||
`${sourcePath}: client.targetExecution.cliPath`,
|
||||
),
|
||||
}
|
||||
: null;
|
||||
const sessionPolicy = readAgentRunSessionPolicyConfig(client, sourcePath);
|
||||
const publicExposure = readAgentRunPublicExposureConfig(input.publicExposure, baseUrl.replace(/\/+$/u, "/"), sourcePath);
|
||||
return {
|
||||
@@ -92,6 +108,7 @@ export function parseAgentRunClientConfigYaml(raw: string, sourcePath = "config/
|
||||
client: {
|
||||
role,
|
||||
transport,
|
||||
targetExecution,
|
||||
sessionPolicy,
|
||||
},
|
||||
publicExposure,
|
||||
@@ -754,6 +771,18 @@ export function booleanFieldFromRecord(obj: Record<string, unknown>, key: string
|
||||
return value;
|
||||
}
|
||||
|
||||
function environmentVariableField(value: string, pathValue: string): string {
|
||||
if (!/^[A-Z_][A-Z0-9_]*$/u.test(value)) throw new Error(`${pathValue} must be an uppercase environment variable name`);
|
||||
return value;
|
||||
}
|
||||
|
||||
function relativePathField(value: string, pathValue: string): string {
|
||||
if (value.startsWith("/") || value.includes("..") || value.includes("\0")) {
|
||||
throw new Error(`${pathValue} must be a repository-relative path without ..`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function cloneJsonRecord(value: Record<string, unknown>): Record<string, unknown> {
|
||||
return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
|
||||
}
|
||||
@@ -772,7 +801,12 @@ export interface AgentRunClientConfig {
|
||||
};
|
||||
client: {
|
||||
role: string;
|
||||
transport: string;
|
||||
transport: "direct-http" | "target-trans";
|
||||
targetExecution: {
|
||||
markerEnv: string;
|
||||
executable: string;
|
||||
cliPath: string;
|
||||
} | null;
|
||||
sessionPolicy: AgentRunSessionPolicyConfig;
|
||||
};
|
||||
publicExposure: AgentRunPublicExposure | null;
|
||||
|
||||
Reference in New Issue
Block a user