From 10f4e00851b1ec956cfc36c2eb7d5ca07b89d8c2 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 1 Jun 2026 18:20:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=20AgentRun=20=E7=9F=AD?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B3=A8=E5=85=A5=20device-pod=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/cloud/server-agent-chat.test.ts | 20 +++++++++++++---- internal/cloud/server-code-agent-http.ts | 28 +++++++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/internal/cloud/server-agent-chat.test.ts b/internal/cloud/server-agent-chat.test.ts index 0b63f8ee..859bf778 100644 --- a/internal/cloud/server-agent-chat.test.ts +++ b/internal/cloud/server-agent-chat.test.ts @@ -164,7 +164,10 @@ test("cloud api /v1/agent/chat delegates v0.2 turns to AgentRun v0.1 over adapte if (request.method === "POST" && url.pathname === "/api/v1/runs/run_hwlab_adapter/runner-jobs") { assert.equal(body.commandId, "cmd_hwlab_adapter"); assert.deepEqual(body.transientEnv.map((entry) => entry.name), ["HWLAB_DEVICE_POD_API_URL", "HWLAB_CLOUD_API_URL", "HWLAB_DEVICE_POD_SESSION_TOKEN"]); - assert.equal(body.transientEnv.find((entry) => entry.name === "HWLAB_DEVICE_POD_SESSION_TOKEN").value, "test-device-pod-session-token"); + const transientEnv = Object.fromEntries(body.transientEnv.map((entry) => [entry.name, entry.value])); + assert.equal(transientEnv.HWLAB_DEVICE_POD_API_URL, "http://hwlab-cloud-api.hwlab-v02.svc.cluster.local:6667"); + assert.equal(transientEnv.HWLAB_CLOUD_API_URL, "http://hwlab-cloud-api.hwlab-v02.svc.cluster.local:6667"); + assert.equal(transientEnv.HWLAB_DEVICE_POD_SESSION_TOKEN, "test-device-pod-session-token"); return send({ action: "create-kubernetes-job", runId: "run_hwlab_adapter", @@ -218,9 +221,18 @@ test("cloud api /v1/agent/chat delegates v0.2 turns to AgentRun v0.1 over adapte HWLAB_CODE_AGENT_AGENTRUN_SOURCE_COMMIT: "0123456789abcdef0123456789abcdef01234567", HWLAB_CODE_AGENT_DEFAULT_PROVIDER_PROFILE: "deepseek", HWLAB_CODE_AGENT_DEEPSEEK_MODEL: "deepseek-chat", - HWLAB_DEVICE_POD_API_URL: "http://hwlab-cloud-web.test", - HWLAB_CLOUD_API_URL: "http://hwlab-cloud-web.test", - HWLAB_DEVICE_POD_SESSION_TOKEN: "test-device-pod-session-token" + HWLAB_ENVIRONMENT: "v02", + HWLAB_GITOPS_PROFILE: "v02", + HWLAB_CLOUD_API_PORT: "6667" + }, + accessController: { + required: false, + async authenticate() { + return { ok: true, actor: null, session: null }; + }, + async createCodeAgentDevicePodSession() { + return { token: "test-device-pod-session-token" }; + } } }); await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); diff --git a/internal/cloud/server-code-agent-http.ts b/internal/cloud/server-code-agent-http.ts index f84d176f..9694b3db 100644 --- a/internal/cloud/server-code-agent-http.ts +++ b/internal/cloud/server-code-agent-http.ts @@ -151,6 +151,7 @@ async function codeAgentDevicePodAuthEnv(options = {}, env = process.env) { env.HWLAB_CODE_AGENT_DEVICE_POD_API_URL, env.HWLAB_DEVICE_POD_API_URL, env.HWLAB_CLOUD_API_URL, + codeAgentAgentRunAdapterEnabled(env) ? internalCloudApiUrl(env) : null, env.HWLAB_PUBLIC_ENDPOINT, localCloudApiUrl(env) ); @@ -161,6 +162,25 @@ async function codeAgentDevicePodAuthEnv(options = {}, env = process.env) { }; } +function internalCloudApiUrl(env = process.env) { + const namespace = firstNonEmptyValue( + env.HWLAB_RUNTIME_NAMESPACE, + env.POD_NAMESPACE, + env.HWLAB_NAMESPACE, + defaultRuntimeNamespace(env) + ); + const serviceName = firstNonEmptyValue(env.HWLAB_CLOUD_API_SERVICE_NAME, "hwlab-cloud-api"); + const port = parsePositiveInteger(env.HWLAB_CLOUD_API_PORT, 6667); + return `http://${serviceName}.${namespace}.svc.cluster.local:${port}`; +} + +function defaultRuntimeNamespace(env = process.env) { + const profile = String(firstNonEmptyValue(env.HWLAB_GITOPS_PROFILE, env.HWLAB_ENVIRONMENT, "dev") ?? "dev").trim().toLowerCase(); + if (profile === "prod" || profile === "production") return "hwlab-prod"; + if (profile === "v02" || profile === "v0.2" || profile === "0.2") return "hwlab-v02"; + return "hwlab-dev"; +} + function localCloudApiUrl(env = process.env) { const port = parsePositiveInteger(env.HWLAB_CLOUD_API_PORT, 6667); return `http://127.0.0.1:${port}`; @@ -235,11 +255,13 @@ function submitCodeAgentChatTurn({ params, options, traceId }) { const initial = initialAgentRunChatResult({ params, options, traceId }); results.set(traceId, annotateOwner(initial, params)); const run = async () => { + let executionOptions = options; try { - const payload = await submitAgentRunChatTurn({ params, options, traceId, traceStore, results }); + executionOptions = { ...options, ...(await codeAgentChatExecutionOptions(options, params)) }; + const payload = await submitAgentRunChatTurn({ params, options: executionOptions, traceId, traceStore, results }); if (isCodeAgentResultCanceled(results.get(traceId))) return; const owned = annotateOwner(payload, params); - await recordCodeAgentSessionOwner({ payload: owned, params, options, status: "running" }); + await recordCodeAgentSessionOwner({ payload: owned, params, options: executionOptions, status: "running" }); results.set(traceId, owned); } catch (error) { if (isCodeAgentResultCanceled(results.get(traceId))) return; @@ -271,7 +293,7 @@ function submitCodeAgentChatTurn({ params, options, traceId }) { message: payload.error.message, terminal: true }); - await recordCodeAgentSessionOwner({ payload, params, options, status: "failed" }); + await recordCodeAgentSessionOwner({ payload, params, options: executionOptions, status: "failed" }); } }; setImmediate(() => { run(); });