fix: 为 AgentRun 短连接注入 device-pod env

This commit is contained in:
Codex
2026-06-01 18:20:56 +08:00
parent c92b0fbebf
commit 10f4e00851
2 changed files with 41 additions and 7 deletions
+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(); });