Skip to content

feat: 添加全局 Antigravity 模型映射和请求详情增强#42

Merged
awsl233777 merged 1 commit intomainfrom
feat/global-antigravity-settings
Jan 15, 2026
Merged

feat: 添加全局 Antigravity 模型映射和请求详情增强#42
awsl233777 merged 1 commit intomainfrom
feat/global-antigravity-settings

Conversation

@Bowl42
Copy link
Collaborator

@Bowl42 Bowl42 commented Jan 15, 2026

User description

Summary

  • 添加 Antigravity 全局模型映射设置,支持通配符模式匹配
  • 添加 Copy as cURL 功能,支持一键复制请求为 cURL 命令
  • 为 ProxyUpstreamAttempt 添加 responseModel 字段,显示完整模型转换链

Changes

全局模型映射

  • 添加 Settings 页面的 Antigravity 全局模型映射配置
  • 支持通配符模式匹配 (如 claude-*gemini-2.5-pro)
  • 在 executor 中实现全局映射逻辑,优先级:Route > Provider > Global
  • 添加 ModelMappingEditor 组件用于可视化编辑映射规则
  • 添加 ModelInput 组件支持按 provider 过滤模型列表

请求详情增强

  • 添加 Copy as cURL 按钮
  • 为 ProxyUpstreamAttempt 添加 responseModel 字段
  • 显示完整的模型转换链:requestModel → mappedModel → responseModel
  • 优化 Metadata 面板布局

其他改进

  • 修复 web server 模式下 GlobalSettingsGetter 未初始化的问题
  • 添加通配符匹配单元测试
  • 数据库迁移:添加 response_model 字段

Test plan

  • 验证全局模型映射在 Settings 页面正常保存和加载
  • 验证通配符匹配规则正确工作
  • 验证 Copy as cURL 按钮生成正确的命令
  • 验证 responseModel 在请求详情中正确显示

PR Type

enhancement, bug fix


Description

  • Add global Antigravity model mapping settings

  • Enhance request details with Copy as cURL feature

  • Introduce response model tracking in ProxyUpstreamAttempt


Diagram Walkthrough

flowchart LR
  A["Add Global Antigravity Settings"] --> B["Enhance Request Details"]
  B --> C["Track Response Model in Attempts"]
Loading

File Walkthrough

Relevant files
Enhancement
11 files
model_mapping.go
Implement global model mapping rules                                         
+143/-55
executor.go
Update executor to handle model mapping                                   
+139/-6 
admin.go
Add Antigravity global settings API                                           
+99/-0   
admin.go
Handle Antigravity settings in admin                                         
+49/-0   
settings.go
Manage global settings for Antigravity                                     
+80/-0   
index.tsx
Integrate Antigravity model mapping in settings                   
+228/-2 
RequestDetailPanel.tsx
Enhance request detail panel with model info                         
+42/-14 
antigravity-provider-view.tsx
Add model mapping editor for Antigravity                                 
+90/-0   
model-mapping-editor.tsx
Create model mapping editor component                                       
+130/-0 
provider-edit-flow.tsx
Include model mapping in provider edit flow                           
+27/-1   
CopyAsCurlButton.tsx
Add Copy as cURL button functionality                                       
+89/-0   
Bug fix
1 files
proxy_upstream_attempt.go
Add response model to database schema                                       
+6/-6     
Additional files
25 files
app.go +9/-1     
bindings.go +17/-0   
main.go +15/-2   
go.mod +1/-6     
adapter.go +52/-13 
claude_streaming.go +5/-0     
database.go +16/-1   
api.go +14/-0   
model.go +10/-1   
wildcard_test.go +97/-0   
db.go +28/-0   
router.go +0/-6     
package.json.md5 +1/-1     
index.ts +15/-1   
model-input.tsx +385/-0 
index.ts +3/-0     
use-settings.ts +34/-0   
http-transport.ts +16/-0   
index.ts +1/-0     
interface.ts +4/-0     
types.ts +16/-0   
wails-transport.ts +14/-0   
RequestDetailView.tsx +2/-1     
index.ts +1/-0     
form.tsx +19/-0   

## 全局模型映射
- 添加 Antigravity 全局模型映射设置页面 (Settings)
- 支持通配符模式匹配 (如 claude-* → gemini-2.5-pro)
- 在 executor 中实现全局映射逻辑,优先级:Route > Provider > Global
- 添加 ModelMappingEditor 组件用于可视化编辑映射规则
- 添加 ModelInput 组件支持按 provider 过滤模型列表

## 请求详情增强
- 添加 Copy as cURL 按钮,支持一键复制请求为 cURL 命令
- 为 ProxyUpstreamAttempt 添加 responseModel 字段
- 显示完整的模型转换链:requestModel → mappedModel → responseModel
- 优化 Metadata 面板布局,增加 Response Model 显示

## 其他改进
- 修复 web server 模式下 GlobalSettingsGetter 未初始化的问题
- 添加通配符匹配单元测试
- 数据库迁移:添加 response_model 字段到 proxy_upstream_attempts 表
@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Complexity

The logic for matching model mapping rules is complex and may lead to unexpected behavior if not thoroughly tested. Ensure that all edge cases are covered in tests.

		return haikuTarget
	}

	// 2. Check global settings first (highest priority for user customization)
	// Rules are matched in order, first match wins
	if globalSettings := GetGlobalSettings(); globalSettings != nil {
		if len(globalSettings.ModelMappingRules) > 0 {
			if mapped := MatchRulesInOrder(cleanInput, globalSettings.ModelMappingRules); mapped != "" {
				return mapped
			}
		}
	}

	// 3. Check default rules in order
	if mapped := MatchRulesInOrder(cleanInput, defaultModelMappingRules); mapped != "" {
		return mapped
	}

	// 4. Pass-through known prefixes (gemini-, -thinking) to support dynamic suffixes
	// (like Antigravity-Manager)
	if strings.HasPrefix(cleanInput, "gemini-") || strings.Contains(cleanInput, "thinking") {
		return cleanInput
	}

	// 5. Fallback to default
	return "claude-sonnet-4-5"
}

// MatchRulesInOrder matches input against rules in order, first match wins
// Returns the target model or empty string if no match
func MatchRulesInOrder(input string, rules []ModelMappingRule) string {
	for i, rule := range rules {
		matched := MatchWildcard(rule.Pattern, input)
		log.Printf("[MatchRulesInOrder] Rule[%d]: pattern=%q, input=%q, matched=%v", i, rule.Pattern, input, matched)
		if matched {
			log.Printf("[MatchRulesInOrder] Matched! Returning target=%q", rule.Target)
			return rule.Target
		}
	}
	return ""
}
Possible Performance Issue

The addition of multiple logging statements may impact performance, especially in high-throughput scenarios. Consider using a logging level to control output.

requestURI := ctxutil.GetRequestURI(ctx)
requestHeaders := ctxutil.GetRequestHeaders(ctx)
requestBody := ctxutil.GetRequestBody(ctx)
headers := flattenHeaders(requestHeaders)
// Go stores Host separately from headers, add it explicitly
if req.Host != "" {
	if headers == nil {
		headers = make(map[string]string)
	}
	headers["Host"] = req.Host
}
proxyReq.RequestInfo = &domain.RequestInfo{
	Method:  req.Method,
	URL:     requestURI,
	Headers: headers,
	Body:    string(requestBody),
}

if err := e.proxyRequestRepo.Create(proxyReq); err != nil {
	log.Printf("[Executor] Failed to create proxy request: %v", err)
}
UI/UX Consideration

Ensure that the UI for managing model mappings is intuitive and provides clear feedback to users, especially when adding or removing rules.

<div className="space-y-6">
  <AppearanceSection />
  <ForceProjectSection />
  <AntigravityModelMappingSection />
</div>

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Clarify gemini model mapping behavior

Ensure that the comment regarding gemini- models is accurate and reflects the
intended behavior of the mapping rules. If there are specific cases where gemini-

models should not pass through, update the comment to clarify this behavior.

internal/adapter/provider/antigravity/model_mapping.go [19]

 ...
-// Note: gemini-* models pass through automatically without needing a mapping rule
+// Note: gemini-* models pass through automatically without needing a mapping rule unless specified otherwise
 var defaultModelMappingRules = []ModelMappingRule{
 ...
Suggestion importance[1-10]: 5

__

Why: The suggestion aims to ensure that the comment accurately reflects the behavior of the mapping rules, which is important for maintainability. However, it does not address a critical issue or bug, hence a moderate score.

Low

@awsl233777 awsl233777 merged commit 74185ed into main Jan 15, 2026
2 checks passed
@awsl233777 awsl233777 deleted the feat/global-antigravity-settings branch January 15, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants