返回 DeepSeek-Reasonix
authentication.go
根目录 / internal / boot / authentication.go
1 package boot
2
3 import (
4 "strings"
5
6 "reasonix/internal/config"
7 "reasonix/internal/control"
8 "reasonix/internal/provider"
9 )
10
11 func authenticationStateForModelEntry(entry *config.ProviderEntry, modelRef string) control.AuthenticationState {
12 if entry == nil || !entry.RequiresAPIKey() || entry.APIKey() != "" {
13 return control.AuthenticationState{Status: control.AuthenticationReady}
14 }
15 status := control.AuthenticationMissingCredential
16 code := "missing_credential"
17 switch config.CredentialStoreRevision() {
18 case "unavailable", "unreadable":
19 status = control.AuthenticationCredentialStoreUnavailable
20 code = "credential_store_unavailable"
21 }
22 return control.AuthenticationState{
23 Status: status,
24 ProviderName: entry.Name,
25 ModelRef: modelRef,
26 KeyEnv: entry.APIKeyEnv,
27 Code: code,
28 }
29 }
30
31 // Capture absence as well as presence once. A request must never reread keys
32 // changed by another process in the middle of the runtime's current turn.
33 func authenticationReader(cfg *config.Config, external provider.Resolver) func(string) control.AuthenticationState {
34 states := map[string]control.AuthenticationState{}
35 if external == nil {
36 for i := range cfg.Providers {
37 entry := &cfg.Providers[i]
38 states[entry.Name] = authenticationStateForModelEntry(entry, "")
39 }
40 }
41 return func(ref string) control.AuthenticationState {
42 name, _, _ := strings.Cut(ref, "/")
43 state := states[name]
44 if state.Status == "" {
45 state.Status = control.AuthenticationReady
46 }
47 state.ModelRef = ref
48 return state
49 }
50 }
51
52 func runtimeImageEnabled(p provider.Provider, fallback bool) bool {
53 if info, ok := p.(provider.ModelInfoProvider); ok {
54 return info.ModelInfo().SupportsInput(provider.ModalityImage)
55 }
56 return fallback
57 }
58
58 lines GO