Merge pull request #648 from pikasTech/fix/v02-agentrun-short-env-injection

fix: 为 AgentRun 短连接注入 device-pod env
This commit is contained in:
Lyon
2026-06-01 18:22:33 +08:00
committed by GitHub
2 changed files with 41 additions and 7 deletions
+16 -4
View File
@@ -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));
+25 -3
View File
@@ -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(); });