返回 DeepSeek-Reasonix
deepseek_chat_default_upgrade.go
根目录 / internal / config / deepseek_chat_default_upgrade.go
1 package config
2
3 const deepSeekChatDefaultConfigVersion = 8
4 const deepSeekOfficialChatUpgradeConfigVersion = 9
5
6 // Official endpoint identity, rather than the editable display name, owns this
7 // one-time migration. Nonstandard paths and gateways remain user-owned.
8 func isOfficialDeepSeekChatUpgrade(p *ProviderEntry) bool {
9 if p == nil || (p.Kind != "anthropic" && p.Kind != "responses" && p.Kind != "openai") {
10 return false
11 }
12 for _, endpoint := range []string{p.BaseURL, p.RequestURL, p.ChatURL} {
13 if endpoint == "" {
14 continue
15 }
16 path, ok := deepSeekOpenAIEndpointPath(endpoint)
17 if !ok {
18 return false
19 }
20 switch path {
21 case "", "/v1", "/anthropic", "/anthropic/v1", "/anthropic/v1/messages", "/responses", "/v1/responses", "/chat/completions", "/v1/chat/completions":
22 default:
23 return false
24 }
25 }
26 return p.BaseURL != ""
27 }
28
29 func migrateOfficialDeepSeekChat(c *Config) {
30 for i := range c.Providers {
31 p := &c.Providers[i]
32 if !isOfficialDeepSeekChatUpgrade(p) {
33 continue
34 }
35 p.Kind, p.BaseURL = "openai", "https://api.deepseek.com"
36 // Drop the standard override instead of pinning the canonical URL: the
37 // derived endpoint is identical, and a non-empty override hides the
38 // account from IsOfficialDeepSeekSearchEndpoint (independent search).
39 p.RequestURL, p.ChatURL = "", ""
40 }
41 }
42
43 // Only the historical built-in Messages routes are defaults to restore.
44 // Explicit alternate presets, custom models and transport settings remain owned
45 // by the user. Model selection, effort, pricing and the search switch survive.
46 func isLegacyDeepSeekMessagesDefault(p *ProviderEntry) bool {
47 if p == nil || p.Kind != "anthropic" || !IsOfficialDeepSeekSearchEndpoint(p) ||
48 p.PresetID != "" || len(p.Headers) != 0 || len(p.ExtraBody) != 0 || p.AuthHeader ||
49 (p.ReasoningProtocol != "" && p.ReasoningProtocol != ReasoningProtocolDeepSeek) {
50 return false
51 }
52 copy := *p
53 copy.Kind = "openai"
54 copy.BaseURL = "https://api.deepseek.com"
55 if !CanUpgradeDeepSeekProviderProtocol(&copy) {
56 return false
57 }
58 for _, override := range p.ModelOverrides {
59 if override.ReasoningProtocol != "" && override.ReasoningProtocol != ReasoningProtocolDeepSeek {
60 return false
61 }
62 }
63 return true
64 }
65
66 func restoreDeepSeekChatDefaults(c *Config) {
67 for i := range c.Providers {
68 p := &c.Providers[i]
69 if isLegacyDeepSeekMessagesDefault(p) {
70 p.Kind = "openai"
71 p.BaseURL = "https://api.deepseek.com"
72 }
73 }
74 }
75
75 lines GO