返回 DeepSeek-Reasonix
subagent_model_ref.go
根目录 / internal / boot / subagent_model_ref.go
1 package boot
2
3 import (
4 "fmt"
5 "strings"
6
7 "reasonix/internal/config"
8 "reasonix/internal/provider"
9 )
10
11 // subagentModelSelection resolves a child's model override to the entry that
12 // prices it and the reference the resolver builds it from.
13 func subagentModelSelection(cfg *config.Config, resolver provider.Resolver, parent *config.ProviderEntry, modelRef string) (config.ProviderEntry, string, error) {
14 if strings.TrimSpace(modelRef) == "" {
15 return *parent, modelRefFromEntry(parent), nil
16 }
17 modelRef = childModelRef(cfg, parent, modelRef)
18 if resolved, ok := cfg.ResolveModel(modelRef); ok {
19 return *resolved, modelRefFromEntry(resolved), nil
20 }
21 if resolver != nil {
22 return *syntheticEntryFromResolver(resolver, modelRef), modelRef, nil
23 }
24 return config.ProviderEntry{}, "", fmt.Errorf("unknown model %q", modelRef)
25 }
26
27 // childModelRef qualifies a bare model name with the parent's provider when
28 // that provider serves it. Config resolves a bare name to the first provider
29 // listing it, which would move a child onto a provider the user never picked.
30 func childModelRef(cfg *config.Config, parent *config.ProviderEntry, ref string) string {
31 ref = strings.TrimSpace(ref)
32 if cfg == nil || parent == nil || ref == "" || strings.Contains(ref, "/") || !parent.HasModel(ref) {
33 return ref
34 }
35 if _, isProvider := cfg.Provider(ref); isProvider {
36 return ref
37 }
38 return parent.Name + "/" + ref
39 }
40
40 lines GO