opencode: support vertex-ai auth#214
Conversation
There was a problem hiding this comment.
Code Review
This pull request enables Vertex AI authentication for the OpenCode harness by updating its capabilities and implementing auth resolution logic. Key changes include refactoring command argument construction, adding a resolveVertexAI helper function, and updating the ResolveAuth method to support both explicit and auto-detected Vertex AI configurations. Feedback was provided to improve the clarity and consistency of the error message when no valid authentication method is found by explicitly listing the required environment variables.
9609b7d to
d0dfe9e
Compare
PR Review: opencode: support vertex-ai authPR: #214 Executive SummaryMedium risk — request changes. Enables Vertex AI as an auth method for the OpenCode harness by flipping the capability flag, adding a Files Changed (1 file, +34 / -9)
Critical / Blocking Issues1. Auto-detect priority puts Vertex AI ahead of API keys — silent behavior regressionFile: // Auto-detect preference order: VertexAi → AnthropicAPIKey → OpenAIAPIKey → OpenCodeAuthFile → error
if auth.GoogleCloudProject != "" && auth.GoogleCloudRegion != "" {
return o.resolveVertexAI(auth), nil
}
if auth.AnthropicAPIKey != "" { ... }Compare with the Claude Code harness, which intentionally puts Vertex last in the auto-detect chain:
Many GCP users have Suggested fix: Move the Vertex AI block to after the auth-file block, matching the Claude Code precedence. Update the comment accordingly. 2. Auto-detect doesn't gate on actual credentials being presentFile: if auth.GoogleCloudProject != "" && auth.GoogleCloudRegion != "" {
return o.resolveVertexAI(auth), nil
}
Compare with hasVertexCreds := auth.GoogleAppCredentials != "" || auth.GCPMetadataMode == "assign"
if hasVertexCreds && auth.GoogleCloudProject != "" && auth.GoogleCloudRegion != "" {
return c.resolveVertexAI(auth), nil
}Suggested fix: Add the same 3. Env vars likely won't activate Vertex in opencodeFile: EnvVars: map[string]string{
"VERTEX_LOCATION": auth.GoogleCloudRegion,
"GOOGLE_CLOUD_REGION": auth.GoogleCloudRegion,
"GOOGLE_CLOUD_PROJECT": auth.GoogleCloudProject,
},Two concerns: (a) opencode is built on the Vercel AI SDK. Its {
"$schema": "https://opencode.ai/config.json",
"theme": "matrix"
}No provider block, no model selection. Without (b) Suggested fix: Smoke-test end-to-end with a real opencode + Vertex run. Verify which env vars opencode actually reads and/or add a provider block to the embedded Observations4. No test coverage for the new path
Tests to add:
5. Bundled, unrelated
|
|
@ptone This was an early pass on this and noticed auto-detection picks the first auth it finds, which is why I put the vertex first. I have since added a parameter/flag to disable host-level credential passthrough and only use configured auth. I was unable to get vertex to work with anthropic creds on my host if we only change the order above. Thoughts? (did I see some PR/changeset to disable host auth passthrough go by?) In agreement with the other PR feedback. I can pull out the code that disables host-auth passthrough and open a separate PR. Should that come first? |
|
sorry for slow reply. given opencode has auth libraries this should be just a matter of detecting the cloud settings are available vertex-ai should autodetect if: (GOOGLE_CLOUD_REGION OR GOOGLE_CLOUD_LOCATION OR && (GOOGLE_CLOUD_PROJECT OR && gcp service account != BLOCK final keys in env should be: that quasi spec may be all a coding agent needs. |
|
i used the above quasi spec to generate main...ptone:scion/opencode-vertex-auth but have not really run it through any test yet. i've also been working on some UX to launch harness with "no-auth" and then capture the auth details in initial interactive mode and then use those captured credentials for subsequent agents of that type. |
opencodefor vertex-ai auth, tested "in production"--promptflag when no task consuming next arg from baseArgs as prompt, i.e. if no task, should not even supply the flag