MCPcopy Create free account
hub / github.com/github/gh-aw / selectAIEngineAndKey

Method selectAIEngineAndKey

pkg/cli/add_interactive_engine.go:20–141  ·  view source on GitHub ↗

selectAIEngineAndKey prompts the user to select an AI engine and provide API key

()

Source from the content-addressed store, hash-verified

18
19// selectAIEngineAndKey prompts the user to select an AI engine and provide API key
20func (c *AddInteractiveConfig) selectAIEngineAndKey() error {
21 addInteractiveLog.Print("Starting coding agent selection")
22
23 // First, check which secrets already exist in the repository
24 if err := c.checkExistingSecrets(); err != nil {
25 return err
26 }
27
28 // Determine default engine based on existing secrets, workflow preference, then environment
29 // Priority order: flag override > existing secrets > workflow frontmatter > environment > default
30 defaultEngine := string(constants.DefaultEngine)
31 workflowSpecifiedEngine := ""
32
33 // Check if workflow specifies a preferred engine in frontmatter
34 if c.resolvedWorkflows != nil && len(c.resolvedWorkflows.Workflows) > 0 {
35 for _, wf := range c.resolvedWorkflows.Workflows {
36 if wf.Engine != "" {
37 workflowSpecifiedEngine = wf.Engine
38 addInteractiveLog.Printf("Workflow specifies engine in frontmatter: %s", wf.Engine)
39 break
40 }
41 }
42 }
43
44 // If engine is explicitly overridden via flag, use that
45 if c.EngineOverride != "" {
46 defaultEngine = c.EngineOverride
47 } else {
48 // Priority 1: Check existing repository secrets using EngineOptions
49 // This takes precedence over workflow preference since users should use what's already available
50 for _, opt := range constants.EngineOptions {
51 if setutil.Contains(c.existingSecrets, opt.SecretName) {
52 defaultEngine = opt.Value
53 addInteractiveLog.Printf("Found existing secret %s, recommending engine: %s", opt.SecretName, opt.Value)
54 break
55 }
56 }
57
58 // Priority 2: If no existing secret found, use workflow frontmatter preference
59 if defaultEngine == string(constants.DefaultEngine) && workflowSpecifiedEngine != "" {
60 defaultEngine = workflowSpecifiedEngine
61 }
62
63 // Priority 3: Check environment variables if no existing secret or workflow preference found
64 if defaultEngine == string(constants.DefaultEngine) && workflowSpecifiedEngine == "" {
65 for _, opt := range constants.EngineOptions {
66 envVar := opt.SecretName
67 if opt.EnvVarName != "" {
68 envVar = opt.EnvVarName
69 }
70 if os.Getenv(envVar) != "" {
71 defaultEngine = opt.Value
72 addInteractiveLog.Printf("Found env var %s, recommending engine: %s", envVar, opt.Value)
73 break
74 }
75 }
76 }
77 }

Calls 15

checkExistingSecretsMethod · 0.95
AllMethod · 0.95
ContainsFunction · 0.92
FormatInfoMessageFunction · 0.92
NewEngineCatalogFunction · 0.92
NewEngineRegistryFunction · 0.92
MapFunction · 0.92
GetEngineOptionFunction · 0.92
IsAccessibleModeFunction · 0.92
FormatSuccessMessageFunction · 0.92
PrintMethod · 0.80