refactor: keep only OpenAI and Anthropic model protocols
Retain OpenAI Responses and Chat Completions with streaming and fallback. Use native Anthropic Messages with tools, thinking and streaming support. Remove other model providers and SDKs while preserving speech services. Update configuration and docs; verify all Go tests, vet, lint and Linux build.
This commit is contained in:
1 parent
3029f22e01
commit
a8804df0ed
85 files changed
+506
-16321
No files matched your search
+9
-50
@@ -23,8 +23,8 @@ import (
|
||||
type OAuthProviderConfig struct {
|
||||
Issuer string
|
||||
ClientID string
|
||||
ClientSecret string // Required for Google OAuth (confidential client)
|
||||
TokenURL string // Override token endpoint (Google uses a different URL than issuer)
|
||||
ClientSecret string // Optional confidential-client secret
|
||||
TokenURL string // Optional override for the token endpoint
|
||||
Scopes string
|
||||
Originator string
|
||||
Port int
|
||||
@@ -49,32 +49,6 @@ func OpenAIOAuthConfig() OAuthProviderConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// GoogleAntigravityOAuthConfig returns the OAuth configuration for Google Cloud Code Assist (Antigravity).
|
||||
// Client credentials are the same ones used by OpenCode/pi-ai for Cloud Code Assist access.
|
||||
func GoogleAntigravityOAuthConfig() OAuthProviderConfig {
|
||||
// These are the same client credentials used by the OpenCode antigravity plugin.
|
||||
clientID := decodeBase64(
|
||||
"MTA3MTAwNjA2MDU5MS10bWhzc2luMmgyMWxjcmUyMzV2dG9sb2poNGc0MDNlcC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbQ==",
|
||||
)
|
||||
clientSecret := decodeBase64("R09DU1BYLUs1OEZXUjQ4NkxkTEoxbUxCOHNYQzR6NnFEQWY=")
|
||||
return OAuthProviderConfig{
|
||||
Issuer: "https://accounts.google.com/o/oauth2/v2",
|
||||
TokenURL: "https://oauth2.googleapis.com/token",
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
Scopes: "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/cclog https://www.googleapis.com/auth/experimentsandconfigs",
|
||||
Port: 51121,
|
||||
}
|
||||
}
|
||||
|
||||
func decodeBase64(s string) string {
|
||||
data, err := base64.StdEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// GenerateState generates a random state string for OAuth CSRF protection.
|
||||
func GenerateState() (string, error) {
|
||||
buf := make([]byte, 32)
|
||||
@@ -503,27 +477,15 @@ func buildAuthorizeURL(cfg OAuthProviderConfig, pkce PKCECodes, state, redirectU
|
||||
"state": {state},
|
||||
}
|
||||
|
||||
isGoogle := strings.Contains(strings.ToLower(cfg.Issuer), "accounts.google.com")
|
||||
if isGoogle {
|
||||
// Google OAuth requires these for refresh token support
|
||||
params.Set("access_type", "offline")
|
||||
params.Set("prompt", "consent")
|
||||
} else {
|
||||
// OpenAI-specific parameters
|
||||
params.Set("id_token_add_organizations", "true")
|
||||
params.Set("codex_cli_simplified_flow", "true")
|
||||
if strings.Contains(strings.ToLower(cfg.Issuer), "auth.openai.com") {
|
||||
params.Set("originator", "picoclaw")
|
||||
}
|
||||
if cfg.Originator != "" {
|
||||
params.Set("originator", cfg.Originator)
|
||||
}
|
||||
params.Set("id_token_add_organizations", "true")
|
||||
params.Set("codex_cli_simplified_flow", "true")
|
||||
if strings.Contains(strings.ToLower(cfg.Issuer), "auth.openai.com") {
|
||||
params.Set("originator", "picoclaw")
|
||||
}
|
||||
if cfg.Originator != "" {
|
||||
params.Set("originator", cfg.Originator)
|
||||
}
|
||||
|
||||
// Google uses /auth path, OpenAI uses /oauth/authorize
|
||||
if isGoogle {
|
||||
return cfg.Issuer + "/auth?" + params.Encode()
|
||||
}
|
||||
return cfg.Issuer + "/oauth/authorize?" + params.Encode()
|
||||
}
|
||||
|
||||
@@ -547,9 +509,6 @@ func ExchangeCodeForTokens(cfg OAuthProviderConfig, code, codeVerifier, redirect
|
||||
|
||||
// Determine provider name from config
|
||||
provider := "openai"
|
||||
if cfg.TokenURL != "" && strings.Contains(cfg.TokenURL, "googleapis.com") {
|
||||
provider = "google-antigravity"
|
||||
}
|
||||
|
||||
resp, err := http.PostForm(tokenURL, data)
|
||||
if err != nil {
|
||||
|
||||
+1
-12
@@ -26,11 +26,6 @@ type AuthStore struct {
|
||||
Credentials map[string]*AuthCredential `json:"credentials"`
|
||||
}
|
||||
|
||||
const (
|
||||
providerGoogleAntigravity = "google-antigravity"
|
||||
providerAntigravityAlias = "antigravity"
|
||||
)
|
||||
|
||||
func (c *AuthCredential) IsExpired() bool {
|
||||
if c.ExpiresAt.IsZero() {
|
||||
return false
|
||||
@@ -50,13 +45,7 @@ func authFilePath() string {
|
||||
}
|
||||
|
||||
func canonicalProvider(provider string) string {
|
||||
normalized := strings.ToLower(strings.TrimSpace(provider))
|
||||
switch normalized {
|
||||
case providerAntigravityAlias:
|
||||
return providerGoogleAntigravity
|
||||
default:
|
||||
return normalized
|
||||
}
|
||||
return strings.ToLower(strings.TrimSpace(provider))
|
||||
}
|
||||
|
||||
func cloneCredential(cred *AuthCredential) *AuthCredential {
|
||||
|
||||
+9
-282
@@ -1,7 +1,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -188,286 +187,14 @@ func TestLoadStoreEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCredentialCanonicalizesLegacyAntigravityProvider(t *testing.T) {
|
||||
tmpDir := setTestAuthHome(t)
|
||||
|
||||
expiresAt := time.Date(2026, 4, 16, 10, 0, 0, 0, time.UTC)
|
||||
store := map[string]any{
|
||||
"credentials": map[string]any{
|
||||
"antigravity": map[string]any{
|
||||
"access_token": "legacy-token",
|
||||
"expires_at": expiresAt.Format(time.RFC3339),
|
||||
"provider": "antigravity",
|
||||
"auth_method": "oauth",
|
||||
"project_id": "project-1",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(store)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error: %v", err)
|
||||
}
|
||||
path := filepath.Join(tmpDir, ".picoclaw", "auth.json")
|
||||
err = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
if err != nil {
|
||||
t.Fatalf("MkdirAll() error: %v", err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile() error: %v", err)
|
||||
}
|
||||
|
||||
cred, err := GetCredential("google-antigravity")
|
||||
if err != nil {
|
||||
t.Fatalf("GetCredential() error: %v", err)
|
||||
}
|
||||
if cred == nil {
|
||||
t.Fatal("GetCredential() returned nil")
|
||||
}
|
||||
if cred.Provider != "google-antigravity" {
|
||||
t.Fatalf("Provider = %q, want %q", cred.Provider, "google-antigravity")
|
||||
}
|
||||
if !cred.ExpiresAt.Equal(expiresAt) {
|
||||
t.Fatalf("ExpiresAt = %v, want %v", cred.ExpiresAt, expiresAt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadStoreMergesAntigravityAliasesPreferringNewerExpiry(t *testing.T) {
|
||||
tmpDir := setTestAuthHome(t)
|
||||
|
||||
legacyExpiry := time.Date(2026, 4, 16, 10, 0, 0, 0, time.UTC)
|
||||
refreshedExpiry := time.Date(2026, 4, 16, 12, 0, 0, 0, time.UTC)
|
||||
store := map[string]any{
|
||||
"credentials": map[string]any{
|
||||
"antigravity": map[string]any{
|
||||
"access_token": "legacy-token",
|
||||
"refresh_token": "legacy-refresh",
|
||||
"expires_at": legacyExpiry.Format(time.RFC3339),
|
||||
"provider": "antigravity",
|
||||
"auth_method": "oauth",
|
||||
"email": "legacy@example.com",
|
||||
},
|
||||
"google-antigravity": map[string]any{
|
||||
"access_token": "fresh-token",
|
||||
"expires_at": refreshedExpiry.Format(time.RFC3339),
|
||||
"provider": "google-antigravity",
|
||||
"auth_method": "oauth",
|
||||
"project_id": "project-2",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(store)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error: %v", err)
|
||||
}
|
||||
path := filepath.Join(tmpDir, ".picoclaw", "auth.json")
|
||||
err = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
if err != nil {
|
||||
t.Fatalf("MkdirAll() error: %v", err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile() error: %v", err)
|
||||
}
|
||||
|
||||
loaded, err := LoadStore()
|
||||
if err != nil {
|
||||
t.Fatalf("LoadStore() error: %v", err)
|
||||
}
|
||||
if len(loaded.Credentials) != 1 {
|
||||
t.Fatalf("credential count = %d, want 1", len(loaded.Credentials))
|
||||
}
|
||||
|
||||
cred := loaded.Credentials["google-antigravity"]
|
||||
if cred == nil {
|
||||
t.Fatal("google-antigravity credential missing")
|
||||
}
|
||||
if cred.AccessToken != "fresh-token" {
|
||||
t.Fatalf("AccessToken = %q, want %q", cred.AccessToken, "fresh-token")
|
||||
}
|
||||
if cred.RefreshToken != "legacy-refresh" {
|
||||
t.Fatalf("RefreshToken = %q, want %q", cred.RefreshToken, "legacy-refresh")
|
||||
}
|
||||
if cred.Email != "legacy@example.com" {
|
||||
t.Fatalf("Email = %q, want %q", cred.Email, "legacy@example.com")
|
||||
}
|
||||
if cred.ProjectID != "project-2" {
|
||||
t.Fatalf("ProjectID = %q, want %q", cred.ProjectID, "project-2")
|
||||
}
|
||||
if !cred.ExpiresAt.Equal(refreshedExpiry) {
|
||||
t.Fatalf("ExpiresAt = %v, want %v", cred.ExpiresAt, refreshedExpiry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadStorePrefersCanonicalKeyWhenExpiryMatchesAlias(t *testing.T) {
|
||||
tmpDir := setTestAuthHome(t)
|
||||
|
||||
expiresAt := time.Date(2026, 4, 16, 12, 0, 0, 0, time.UTC)
|
||||
store := map[string]any{
|
||||
"credentials": map[string]any{
|
||||
"antigravity": map[string]any{
|
||||
"access_token": "legacy-token",
|
||||
"refresh_token": "legacy-refresh",
|
||||
"expires_at": expiresAt.Format(time.RFC3339),
|
||||
"provider": "antigravity",
|
||||
"auth_method": "oauth",
|
||||
"email": "legacy@example.com",
|
||||
},
|
||||
" Google-Antigravity ": map[string]any{
|
||||
"access_token": "fresh-token",
|
||||
"expires_at": expiresAt.Format(time.RFC3339),
|
||||
"provider": " Google-Antigravity ",
|
||||
"auth_method": "oauth",
|
||||
"project_id": "project-2",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(store)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error: %v", err)
|
||||
}
|
||||
path := filepath.Join(tmpDir, ".picoclaw", "auth.json")
|
||||
err = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
if err != nil {
|
||||
t.Fatalf("MkdirAll() error: %v", err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile() error: %v", err)
|
||||
}
|
||||
|
||||
loaded, err := LoadStore()
|
||||
if err != nil {
|
||||
t.Fatalf("LoadStore() error: %v", err)
|
||||
}
|
||||
if len(loaded.Credentials) != 1 {
|
||||
t.Fatalf("credential count = %d, want 1", len(loaded.Credentials))
|
||||
}
|
||||
|
||||
cred := loaded.Credentials["google-antigravity"]
|
||||
if cred == nil {
|
||||
t.Fatal("google-antigravity credential missing")
|
||||
}
|
||||
if cred.AccessToken != "fresh-token" {
|
||||
t.Fatalf("AccessToken = %q, want %q", cred.AccessToken, "fresh-token")
|
||||
}
|
||||
if cred.RefreshToken != "legacy-refresh" {
|
||||
t.Fatalf("RefreshToken = %q, want %q", cred.RefreshToken, "legacy-refresh")
|
||||
}
|
||||
if cred.Email != "legacy@example.com" {
|
||||
t.Fatalf("Email = %q, want %q", cred.Email, "legacy@example.com")
|
||||
}
|
||||
if cred.ProjectID != "project-2" {
|
||||
t.Fatalf("ProjectID = %q, want %q", cred.ProjectID, "project-2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCredentialReplacesLegacyAntigravityEntry(t *testing.T) {
|
||||
tmpDir := setTestAuthHome(t)
|
||||
|
||||
legacyStore := map[string]any{
|
||||
"credentials": map[string]any{
|
||||
"antigravity": map[string]any{
|
||||
"access_token": "legacy-token",
|
||||
"expires_at": time.Date(2026, 4, 16, 10, 0, 0, 0, time.UTC).Format(time.RFC3339),
|
||||
"provider": "antigravity",
|
||||
"auth_method": "oauth",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(legacyStore)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error: %v", err)
|
||||
}
|
||||
path := filepath.Join(tmpDir, ".picoclaw", "auth.json")
|
||||
err = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
if err != nil {
|
||||
t.Fatalf("MkdirAll() error: %v", err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile() error: %v", err)
|
||||
}
|
||||
|
||||
refreshedExpiry := time.Date(2026, 4, 16, 12, 30, 0, 0, time.UTC)
|
||||
err = SetCredential("google-antigravity", &AuthCredential{
|
||||
AccessToken: "fresh-token",
|
||||
ExpiresAt: refreshedExpiry,
|
||||
Provider: "google-antigravity",
|
||||
AuthMethod: "oauth",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SetCredential() error: %v", err)
|
||||
}
|
||||
|
||||
loaded, err := LoadStore()
|
||||
if err != nil {
|
||||
t.Fatalf("LoadStore() error: %v", err)
|
||||
}
|
||||
if len(loaded.Credentials) != 1 {
|
||||
t.Fatalf("credential count = %d, want 1", len(loaded.Credentials))
|
||||
}
|
||||
|
||||
cred := loaded.Credentials["google-antigravity"]
|
||||
if cred == nil {
|
||||
t.Fatal("google-antigravity credential missing")
|
||||
}
|
||||
if cred.AccessToken != "fresh-token" {
|
||||
t.Fatalf("AccessToken = %q, want %q", cred.AccessToken, "fresh-token")
|
||||
}
|
||||
if !cred.ExpiresAt.Equal(refreshedExpiry) {
|
||||
t.Fatalf("ExpiresAt = %v, want %v", cred.ExpiresAt, refreshedExpiry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteCredentialRemovesLegacyAntigravityAlias(t *testing.T) {
|
||||
tmpDir := setTestAuthHome(t)
|
||||
|
||||
legacyStore := map[string]any{
|
||||
"credentials": map[string]any{
|
||||
"antigravity": map[string]any{
|
||||
"access_token": "legacy-token",
|
||||
"provider": "antigravity",
|
||||
"auth_method": "oauth",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(legacyStore)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error: %v", err)
|
||||
}
|
||||
path := filepath.Join(tmpDir, ".picoclaw", "auth.json")
|
||||
err = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
if err != nil {
|
||||
t.Fatalf("MkdirAll() error: %v", err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile() error: %v", err)
|
||||
}
|
||||
|
||||
err = DeleteCredential(" google-antigravity ")
|
||||
if err != nil {
|
||||
t.Fatalf("DeleteCredential() error: %v", err)
|
||||
}
|
||||
|
||||
loaded, err := LoadStore()
|
||||
if err != nil {
|
||||
t.Fatalf("LoadStore() error: %v", err)
|
||||
}
|
||||
if len(loaded.Credentials) != 0 {
|
||||
t.Fatalf("credential count = %d, want 0", len(loaded.Credentials))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCredentialCanonicalizesTrimmedMixedCaseProvider(t *testing.T) {
|
||||
setTestAuthHome(t)
|
||||
|
||||
expiresAt := time.Date(2026, 4, 16, 13, 0, 0, 0, time.UTC)
|
||||
if err := SetCredential(" AnTiGrAvItY ", &AuthCredential{
|
||||
if err := SetCredential(" OpEnAi ", &AuthCredential{
|
||||
AccessToken: "fresh-token",
|
||||
ExpiresAt: expiresAt,
|
||||
Provider: " AnTiGrAvItY ",
|
||||
Provider: " OpEnAi ",
|
||||
AuthMethod: "oauth",
|
||||
}); err != nil {
|
||||
t.Fatalf("SetCredential() error: %v", err)
|
||||
@@ -481,25 +208,25 @@ func TestSetCredentialCanonicalizesTrimmedMixedCaseProvider(t *testing.T) {
|
||||
t.Fatalf("credential count = %d, want 1", len(loaded.Credentials))
|
||||
}
|
||||
|
||||
cred := loaded.Credentials["google-antigravity"]
|
||||
cred := loaded.Credentials["openai"]
|
||||
if cred == nil {
|
||||
t.Fatal("google-antigravity credential missing")
|
||||
t.Fatal("openai credential missing")
|
||||
}
|
||||
if cred.Provider != "google-antigravity" {
|
||||
t.Fatalf("Provider = %q, want %q", cred.Provider, "google-antigravity")
|
||||
if cred.Provider != "openai" {
|
||||
t.Fatalf("Provider = %q, want %q", cred.Provider, "openai")
|
||||
}
|
||||
if !cred.ExpiresAt.Equal(expiresAt) {
|
||||
t.Fatalf("ExpiresAt = %v, want %v", cred.ExpiresAt, expiresAt)
|
||||
}
|
||||
|
||||
got, err := GetCredential(" GoOgLe-AnTiGrAvItY ")
|
||||
got, err := GetCredential(" OpEnAi ")
|
||||
if err != nil {
|
||||
t.Fatalf("GetCredential() error: %v", err)
|
||||
}
|
||||
if got == nil {
|
||||
t.Fatal("GetCredential() returned nil")
|
||||
}
|
||||
if got.Provider != "google-antigravity" {
|
||||
t.Fatalf("GetCredential provider = %q, want %q", got.Provider, "google-antigravity")
|
||||
if got.Provider != "openai" {
|
||||
t.Fatalf("GetCredential provider = %q, want %q", got.Provider, "openai")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user