- 全局替换 ApiKey → APIKey(类型、字段、方法、变量) - 修复所有 initialism 命名(API, SMTP, HTML, URL 等) - 添加所有缺失的包注释 - 修复导出符号的注释格式 主要修改: - ApiKey → APIKey(所有出现的地方) - ApiKeyID → APIKeyID - ApiKeyIDs → APIKeyIDs - TestSmtpConnection → TestSMTPConnection - HtmlURL → HTMLURL - 添加 20+ 个包注释 - 修复 10+ 个导出符号注释格式 验证结果: - ✓ golangci-lint: 0 issues - ✓ 单元测试: 通过 - ✓ 集成测试: 通过
50 lines
2.9 KiB
Go
50 lines
2.9 KiB
Go
// Package geminicli provides helpers for interacting with Gemini CLI tools.
|
|
package geminicli
|
|
|
|
import "time"
|
|
|
|
const (
|
|
AIStudioBaseURL = "https://generativelanguage.googleapis.com"
|
|
GeminiCliBaseURL = "https://cloudcode-pa.googleapis.com"
|
|
|
|
AuthorizeURL = "https://accounts.google.com/o/oauth2/v2/auth"
|
|
TokenURL = "https://oauth2.googleapis.com/token"
|
|
|
|
// AIStudioOAuthRedirectURI is the default redirect URI used for AI Studio OAuth.
|
|
// This matches the "copy/paste callback URL" flow used by OpenAI OAuth in this project.
|
|
// Note: You still need to register this redirect URI in your Google OAuth client
|
|
// unless you use an OAuth client type that permits localhost redirect URIs.
|
|
AIStudioOAuthRedirectURI = "http://localhost:1455/auth/callback"
|
|
|
|
// DefaultScopes for Code Assist (includes cloud-platform for API access plus userinfo scopes)
|
|
// Required by Google's Code Assist API.
|
|
DefaultCodeAssistScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
|
|
|
|
// DefaultScopes for AI Studio (uses generativelanguage API with OAuth)
|
|
// Reference: https://ai.google.dev/gemini-api/docs/oauth
|
|
// For regular Google accounts, supports API calls to generativelanguage.googleapis.com
|
|
// Note: Google Auth platform currently documents the OAuth scope as
|
|
// https://www.googleapis.com/auth/generative-language.retriever (often with cloud-platform).
|
|
DefaultAIStudioScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/generative-language.retriever"
|
|
|
|
// DefaultScopes for Google One (personal Google accounts with Gemini access)
|
|
// Only used when a custom OAuth client is configured. When using the built-in Gemini CLI client,
|
|
// Google One uses DefaultCodeAssistScopes (same as code_assist) because the built-in client
|
|
// cannot request restricted scopes like generative-language.retriever or drive.readonly.
|
|
DefaultGoogleOneScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/generative-language.retriever https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
|
|
|
|
// GeminiCLIRedirectURI is the redirect URI used by Gemini CLI for Code Assist OAuth.
|
|
GeminiCLIRedirectURI = "https://codeassist.google.com/authcode"
|
|
|
|
// GeminiCLIOAuthClientID/Secret are the public OAuth client credentials used by Google Gemini CLI.
|
|
// They enable the "login without creating your own OAuth client" experience, but Google may
|
|
// restrict which scopes are allowed for this client.
|
|
GeminiCLIOAuthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
|
|
GeminiCLIOAuthClientSecret = "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"
|
|
|
|
SessionTTL = 30 * time.Minute
|
|
|
|
// GeminiCLIUserAgent mimics Gemini CLI to maximize compatibility with internal endpoints.
|
|
GeminiCLIUserAgent = "GeminiCLI/0.1.5 (Windows; AMD64)"
|
|
)
|