sub2api/backend/internal/service/identity_service_antigravity.go
win d6df41feaa chore(claude): bump CLI fingerprint to 2.1.88 and accept claude-code/ UA
- Centralize Claude CLI fingerprint constants (UA, x-stainless-*) in
  pkg/claude with BuildCLI/CodeUserAgent helpers
- Reuse constants in DefaultHeaders, identity_service defaults, and
  antigravity identity defaults to keep all callers in sync
- Extend ClaudeCodeValidator to accept both claude-cli/ and claude-code/
  UA prefixes (transport/helper requests use the latter)
- Update related tests to cover the new UA prefix and version
2026-04-28 22:35:24 +08:00

42 lines
1.6 KiB
Go

package service
import "github.com/Wei-Shaw/sub2api/internal/pkg/claude"
// ==============================================================
// antigravity — identity_service 扩展
//
// 此文件包含 Antigravity fork 对 IdentityService 的扩展,
// 新增了实例级隔离盐值和指纹默认值覆盖功能。
//
// 对上游文件 identity_service.go 的最小化改动:
// - defaultFingerprint 版本号更新
// - IdentityService struct 新增 instanceSalt 字段
// ==============================================================
// ApplyDefaultFingerprintOverrides 用配置覆盖 identity_service 的默认指纹
// 允许不同部署实例设置不同的 CLI/SDK 版本号,避免所有实例指纹相同
func ApplyDefaultFingerprintOverrides(cliVersion, pkgVersion, runtimeVersion, os_, arch string) {
if cliVersion != "" {
defaultFingerprint.UserAgent = claude.BuildCLIUserAgent(cliVersion, "", "")
}
if pkgVersion != "" {
defaultFingerprint.StainlessPackageVersion = pkgVersion
}
if runtimeVersion != "" {
defaultFingerprint.StainlessRuntimeVersion = runtimeVersion
}
if os_ != "" {
defaultFingerprint.StainlessOS = os_
}
if arch != "" {
defaultFingerprint.StainlessArch = arch
}
}
// NewIdentityServiceWithSalt 创建带实例盐值的 IdentityService
// 实例盐值用于 user_id 重写时的 session hash 混淆,
// 使不同 sub2api 实例对相同输入产生不同的 hash 输出,增加隔离性
func NewIdentityServiceWithSalt(cache IdentityCache, salt string) *IdentityService {
return &IdentityService{cache: cache, instanceSalt: salt}
}