返回 DeepSeek-Reasonix
resolver.go
根目录 / internal / provider / resolver.go
1 package provider
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8 // Descriptor is the non-sensitive provider/model metadata shared across
9 // process boundaries. It intentionally contains no endpoint, credential,
10 // header, proxy, or environment-variable information.
11 type Descriptor struct {
12 Ref string `json:"ref"`
13 DisplayName string `json:"displayName,omitempty"`
14 Model string `json:"model,omitempty"`
15 ContextWindow int `json:"contextWindow,omitempty"`
16 PricingCurrency string `json:"pricingCurrency,omitempty"`
17 CacheHitPerMillion float64 `json:"cacheHitPerMillion,omitempty"`
18 InputPerMillion float64 `json:"inputPerMillion,omitempty"`
19 OutputPerMillion float64 `json:"outputPerMillion,omitempty"`
20 Vision bool `json:"vision,omitempty"`
21 InputModalities []ModelModality `json:"inputModalities,omitempty"`
22 Tools bool `json:"tools,omitempty"`
23 Reasoning bool `json:"reasoning,omitempty"`
24 ReasoningUnknown bool `json:"reasoningUnknown,omitempty"`
25 Efforts []string `json:"efforts,omitempty"`
26 DefaultEffort string `json:"defaultEffort,omitempty"`
27 ToolCallReasoning bool `json:"toolCallReasoning,omitempty"`
28 ReasoningRoundTrip bool `json:"reasoningRoundTrip,omitempty"`
29 WarnOnMissingToolCallReasoning bool `json:"warnOnMissingToolCallReasoning,omitempty"`
30 }
31
32 // Selection identifies a catalog provider and an optional session-local
33 // effort override.
34 type Selection struct {
35 Ref string `json:"ref"`
36 Effort *string `json:"effort,omitempty"`
37 }
38
39 // Resolver creates providers without exposing credential material to callers.
40 // Remote runtimes use a Broker-backed resolver; ordinary boots keep using the
41 // local config-backed resolver.
42 type Resolver interface {
43 Catalog() []Descriptor
44 Resolve(Selection) (Provider, error)
45 }
46
47 // StaticResolver is a small deterministic test double.
48 type StaticResolver struct {
49 Descriptors []Descriptor
50 Providers map[string]Provider
51 }
52
53 func (r *StaticResolver) Catalog() []Descriptor {
54 if r == nil {
55 return nil
56 }
57 out := make([]Descriptor, len(r.Descriptors))
58 copy(out, r.Descriptors)
59 return out
60 }
61
62 func (r *StaticResolver) Resolve(selection Selection) (Provider, error) {
63 if r == nil {
64 return nil, fmt.Errorf("provider resolver is nil")
65 }
66 ref := strings.TrimSpace(selection.Ref)
67 if ref == "" {
68 return nil, fmt.Errorf("provider selection ref is required")
69 }
70 if p, ok := r.Providers[ref]; ok {
71 return p, nil
72 }
73 for key, p := range r.Providers {
74 if strings.HasPrefix(key, ref+"/") || strings.HasSuffix(key, "/"+ref) {
75 return p, nil
76 }
77 }
78 return nil, fmt.Errorf("unknown provider ref %q", ref)
79 }
80
80 lines GO