fix: accept AgentRun v02 adapter mode

This commit is contained in:
root
2026-06-28 11:40:15 +08:00
parent 44f236880f
commit d72d61f71e
3 changed files with 41 additions and 2 deletions
@@ -50,6 +50,8 @@ import { agentRunResultSyncDeferred, buildAgentRunProjectionEventsFetchPlan, bui
import { codeAgentOtelTraceFields, codeAgentOtelTraceContext, emitCodeAgentOtelSpan } from "./otel-trace.ts";
const ADAPTER_ID = "agentrun-v01";
const ADAPTER_IDS = new Set([ADAPTER_ID, "agentrun-v02"]);
const ADAPTER_ALIASES = new Set(["agentrun", "agentrun-v0.1", "agentrun-v0.2"]);
const DEFAULT_TENANT_ID = "hwlab";
const DEFAULT_PROJECT_ID = "pikasTech/HWLAB";
const DEFAULT_RUNNER_NAMESPACE = "agentrun-v01";
@@ -73,7 +75,7 @@ const HWLAB_RESOURCE_PROMPT_REFS = Object.freeze([
export function codeAgentAgentRunAdapterEnabled(env = process.env) {
const value = String(env.HWLAB_CODE_AGENT_ADAPTER ?? env.HWLAB_CODE_AGENT_PROVIDER ?? "").trim().toLowerCase();
return value === ADAPTER_ID || value === "agentrun" || value === "agentrun-v0.1";
return ADAPTER_IDS.has(value) || ADAPTER_ALIASES.has(value);
}
export function describeAgentRunAdapterAvailability(env = process.env, options = {}) {
+29 -1
View File
@@ -785,10 +785,27 @@ function firstNonEmptyValue(...values) {
return null;
}
function safeOtelConfigText(value) {
const text = firstNonEmptyValue(value);
return text === null ? null : text.slice(0, 120);
}
function safeOtelUrlHost(value) {
const text = firstNonEmptyValue(value);
if (text === null) return null;
try {
return new URL(text).host.slice(0, 120);
} catch {
return null;
}
}
async function submitCodeAgentChatTurn({ params, options, traceId }) {
const traceStore = options.traceStore ?? defaultCodeAgentTraceStore;
const results = options.codeAgentChatResults ?? createCodeAgentChatResultStore();
const timestamp = new Date().toISOString();
const runtimeEnv = options.env ?? process.env;
const adapterEnabled = codeAgentAgentRunAdapterEnabled(runtimeEnv);
const acceptedPayload = {
accepted: true,
status: "running",
@@ -803,7 +820,18 @@ async function submitCodeAgentChatTurn({ params, options, traceId }) {
};
await recordCodeAgentTurnAdmission({ payload: acceptedPayload, params, options, traceId });
results.set(traceId, annotateOwner(acceptedPayload, params));
if (codeAgentAgentRunAdapterEnabled(options.env ?? process.env)) {
void emitCodeAgentOtelSpan("provider_decision", traceId, runtimeEnv, {
attributes: {
adapterEnabled,
adapter: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_ADAPTER ?? runtimeEnv.HWLAB_CODE_AGENT_PROVIDER),
provider: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_PROVIDER),
defaultProviderProfile: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_DEFAULT_PROVIDER_PROFILE),
agentRunManagerHost: safeOtelUrlHost(runtimeEnv.AGENTRUN_MGR_URL ?? runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_MGR_URL),
agentRunRunnerNamespace: safeOtelConfigText(runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_RUNNER_NAMESPACE ?? runtimeEnv.AGENTRUN_RUNTIME_NAMESPACE),
agentRunSourceCommitPresent: Boolean(firstNonEmptyValue(runtimeEnv.HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT))
}
});
if (adapterEnabled) {
const run = async () => {
let initial = null;
let executionOptions = options;
+9
View File
@@ -1101,6 +1101,15 @@ test("AgentRun adapter does not initialize repo-owned Codex stdio runtime defaul
assert.equal(env.CODEX_HOME, undefined);
assert.equal(env.HWLAB_PREINSTALLED_SKILLS_DIR, "/app/skills");
assert.equal(env.HWLAB_USER_SKILLS_DIR, "/data/user-skills");
const v02Env = {
HWLAB_CODE_AGENT_ADAPTER: "agentrun-v02"
};
ensureCodeAgentRuntimeBase(v02Env);
assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_STDIO_ENABLED, undefined);
assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_STDIO_SUPERVISOR, undefined);
assert.equal(v02Env.HWLAB_CODE_AGENT_CODEX_WORKSPACE, undefined);
assert.equal(v02Env.CODEX_HOME, undefined);
});
test("explicit Codex stdio mode keeps local runtime defaults available", () => {