MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Build

Method Build

sdk/cliproxy/builder.go:183–297  ·  view source on GitHub ↗

Build validates inputs, applies defaults, and returns a ready-to-run service.

()

Source from the content-addressed store, hash-verified

181
182// Build validates inputs, applies defaults, and returns a ready-to-run service.
183func (b *Builder) Build() (*Service, error) {
184 if b.cfg == nil {
185 return nil, fmt.Errorf("cliproxy: configuration is required")
186 }
187 if b.configPath == "" {
188 return nil, fmt.Errorf("cliproxy: configuration path is required")
189 }
190
191 tokenProvider := b.tokenProvider
192 if tokenProvider == nil {
193 tokenProvider = NewFileTokenClientProvider()
194 }
195
196 apiKeyProvider := b.apiKeyProvider
197 if apiKeyProvider == nil {
198 apiKeyProvider = NewAPIKeyClientProvider()
199 }
200
201 watcherFactory := b.watcherFactory
202 if watcherFactory == nil {
203 watcherFactory = defaultWatcherFactory
204 }
205
206 authManager := b.authManager
207 if authManager == nil {
208 authManager = newDefaultAuthManager()
209 }
210
211 accessManager := b.accessManager
212 if accessManager == nil {
213 accessManager = sdkaccess.NewManager()
214 }
215
216 configaccess.Register(&b.cfg.SDKConfig)
217 pluginHost := b.pluginHost
218 if pluginHost == nil {
219 pluginHost = pluginhost.New()
220 }
221 if b.cfg != nil {
222 pluginHost.ApplyConfig(context.Background(), b.cfg)
223 pluginHost.RegisterFrontendAuthProviders()
224 }
225 accessManager.SetProviders(sdkaccess.RegisteredProviders())
226
227 coreManager := b.coreManager
228 if coreManager == nil {
229 tokenStore := sdkAuth.GetTokenStore()
230 if dirSetter, ok := tokenStore.(interface{ SetBaseDir(string) }); ok && b.cfg != nil {
231 dirSetter.SetBaseDir(b.cfg.AuthDir)
232 }
233
234 strategy := ""
235 sessionAffinity := false
236 sessionAffinityTTL := time.Hour
237 if b.cfg != nil {
238 strategy = strings.ToLower(strings.TrimSpace(b.cfg.Routing.Strategy))
239 // Support both legacy ClaudeCodeSessionAffinity and new universal SessionAffinity
240 sessionAffinity = b.cfg.Routing.SessionAffinity

Callers 4

mainFunction · 0.80

Calls 15

runtimeAuthSyncHookMethod · 0.95
NewFunction · 0.92
WithPostAuthHookFunction · 0.92
WithPostAuthPersistHookFunction · 0.92
WithPluginHostFunction · 0.92
WithConfigReloadHookFunction · 0.92
NewAPIKeyClientProviderFunction · 0.85
newDefaultAuthManagerFunction · 0.85