From ed46acd4d3e42a67cf7f3097043579cc1f4827fd Mon Sep 17 00:00:00 2001 From: chenchen Date: Thu, 4 Jun 2026 22:29:40 +0800 Subject: [PATCH] docs(agent): fix stale runtime comments about token injection amStartTemplateAgent no longer claims OPENAI_API_KEY is uninjected or that access_token is left empty for a future V2 path: the handler now mints + injects both OPENAI_API_KEY and the per-agent AGENT_ACCESS_TOKEN (forwarded as-is), and HM returns its own access_token to the client. Co-Authored-By: Claude Opus 4.8 --- heicode/controller/agent_template_runtime.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/heicode/controller/agent_template_runtime.go b/heicode/controller/agent_template_runtime.go index 4ace5ec0..5bf1cc99 100644 --- a/heicode/controller/agent_template_runtime.go +++ b/heicode/controller/agent_template_runtime.go @@ -160,9 +160,9 @@ func amStartTemplateAgent(ctx context.Context, args amStartArgs) (amStartResult, } env["MODEL_NAME"] = modelName env["OPENAI_BASE_URL"] = publicV1BaseURL() - // NOTE: OPENAI_API_KEY is intentionally NOT injected here — the desktop - // client passes its own api_key per A2A request (CODING_A2A §7). A future - // V2-decrypt path may hand the agent a scoped key instead. + // NOTE: OPENAI_API_KEY and AGENT_ACCESS_TOKEN are already in args.Env (the + // handler mints + injects them before calling us) and are forwarded as-is by + // the copy loop above. We don't add model/auth keys here. // env may carry plaintext secrets (db password, blob key…) — warn on http. base := agentRuntimeClientConfigForMode(agentRuntimeModeAgent).BaseURL @@ -188,8 +188,10 @@ func amStartTemplateAgent(ctx context.Context, args amStartArgs) (amStartResult, return amStartResult{}, err } // AM exposes the agent via access_info.{domain,external_ip}; the instance id - // is name/namespace. access_token is not issued by AM (auth = per-request - // api_key); left empty until the V2-decrypt path lands. + // is name/namespace. AM's access_token (if any) is ignored — HM mints its own + // per-agent access token (AGENT_ACCESS_TOKEN) and returns that to the client; + // AM authorizes callers by comparing the X-Agent-Access-Token header to its + // env AGENT_ACCESS_TOKEN locally. subdomain := stringFromMap(data, "subdomain", "address", "url") if subdomain == "" { if ai, ok := data["access_info"].(map[string]any); ok {