Skip to content

[Bug]: Antigravity (agy) Gemini 协议下 Base URL 未做路径归一化/校验,且前端占位符易误导导致请求 404 #1040

Open

Description

@Bugaoxingxx

Component / host

Platform — web / API

Edition

Platform

LoopForge version

v0.4.0 (e89cda9)

What happened?

在「个人配置 → Antigravity」中选择默认的 「Gemini 官方 API」(protocol = "gemini")协议时,存在前端引导误导与后端 Base URL 处理不一致的问题,容易导致 agy CLI 拼接出非法的请求路径并返回 Error 404, Message: , Status: 404 Not Found:

  1. 前端占位符误导:
    web/app/workbench.js 中 agentCli.agy 的 Base URL 输入框在选择「Gemini 官方 API」协议时依然展示 placeholder="https://gateway.example.com/v1"(带 /v1 路径后缀),没有提示 Gemini 协议仅接收域名根地址(或留空直连官方服务),用户很容易将带路径的端点(例如 https://generativelanguage.googleapis.com/v1beta 或 Google AI Studio 示例中的 https://generativelanguage.googleapis.com/v1beta/interactions)填入 Base URL。

  2. 探测接口与运行时对 Base URL 的路径处理不一致:

    • 模型探测接口 discoverGeminiModels(internal/httpapi/cli_models_probe.go:171)对 baseURL 做了后缀剥离:
      baseURL = strings.TrimSuffix(strings.TrimRight(baseURL, "/"), "/v1beta")
    • 但实际运行 agy 的 ApplyAgentCLICredential(internal/runtime/agent_cli.go:430-433)未做任何路径归一化或校验,直接将原始 baseURL 注入 GOOGLE_GEMINI_BASE_URL / GEMINI_BASE_URL。
    • agy CLI 底层 SDK(google.golang.org/genai)将 GOOGLE_GEMINI_BASE_URL 视为服务根地址并自动追加 /v1beta/models/<model>:streamGenerateContent?alt=sse。
    • 结果:
      • 若填入 https://generativelanguage.googleapis.com/v1beta,「获取可用模型」能够成功返回模型列表,但实际发起对话时请求变成 .../v1beta/v1beta/models/...,直接 404。
      • 若填入 https://generativelanguage.googleapis.com/v1beta/interactions,请求变成 .../v1beta/interactions/v1beta/models/...,Google 前端返回空响应体的 HTML 404,导致 agy 报 Error 404, Message: , Status: 404 Not Found, Details: [],前端仅提示笼统的生成失败。

期望行为:

  1. 前端在「个人配置 → Antigravity」切换为「Gemini 官方 API」协议时,更新 Base URL 的 placeholder / 提示文案(例如 https://generativelanguage.googleapis.com,说明留空默认直连官方服务,填写反向代理时不要包含 /v1beta 等接口路径)。
  2. 后端在 protocol == "gemini" 时统一归一化或校验 Base URL(例如剥离尾部的 /v1beta 保持与 discoverGeminiModels 一致,并对包含 /v1beta/... 子路径如 /v1beta/interactions 的非法根地址给出明确的配置校验错误或归一化处理)。

Reproduction

  1. 打开「个人配置 → Antigravity」,协议保持「Gemini 官方 API」。
  2. 填写有效的 Gemini API Key,并将 Base URL 填为 https://generativelanguage.googleapis.com/v1beta(此时点击「获取可用模型」可成功拉取)或 https://generativelanguage.googleapis.com/v1beta/interactions,点击保存。
  3. 在 AI 对话中选择 Antigravity 模型发送任意消息。
  4. 观察对话失败,诊断日志中出现 Error 404, Message: , Status: 404 Not Found。

Sanitized diagnostics

# agy 实际发出的请求路径变成二次拼接:
POST https://generativelanguage.googleapis.com/v1beta/interactions/v1beta/models/<model>:streamGenerateContent?alt=sse

# CLI 报错输出(已脱敏):
agent executor error: generating and executing: Error 404, Message: , Status: 404 Not Found, Details: []; stderr=error: agent executor error: generating and executing: Error 404, Message: , Status: 404 Not Found, Details: [] | AGY_ERROR: {"short_error":"agent executor error: generating and executing: Error 404, Message: , Status: 404 Not Found, Details: []","status":"NOT_FOUND","error_code":404,"code_kind":"http","retryable":false}

Safety checks

  • I removed credentials, private endpoints, internal identifiers, and personal data.
  • I searched existing issues for duplicates.

Activity

  1. cocofhu00 commented on Nov 18, 2026

    @cocofhu00
    Contributor

    感谢反馈!理解你的意思是:Antigravity 使用 Gemini 协议时,Base URL 的占位符容易让人带上 /v1beta 这类路径;探测接口会去掉后缀,实际运行却原样使用,于是请求路径被拼重并返回 404。

    已经看到,会按现有 Issue 排期查看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions