@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "fmt"
5+ "net/url"
56 "os"
67
78 "github.com/AlecAivazis/survey/v2"
@@ -26,8 +27,14 @@ var getCmd = &cobra.Command{
2627 fmt .Println ("Error getting model:" , err )
2728 os .Exit (1 )
2829 }
30+ endpoint , err := config .GetEndpoint ()
31+ if err != nil {
32+ fmt .Println ("Error getting endpoint:" , err )
33+ os .Exit (1 )
34+ }
2935 fmt .Printf ("Active Provider: %s\n " , provider )
3036 fmt .Printf ("Model: %s\n " , model )
37+ fmt .Printf ("Endpoint: %s\n " , endpoint )
3138 },
3239}
3340
@@ -39,13 +46,40 @@ var setCmd = &cobra.Command{
3946 },
4047}
4148
49+ func validateEndpointURL (val interface {}) error {
50+ endpoint , ok := val .(string )
51+ if ! ok {
52+ return fmt .Errorf ("endpoint must be a string" )
53+ }
54+
55+ // Empty string is valid (uses default)
56+ if endpoint == "" {
57+ return nil
58+ }
59+
60+ parsedURL , err := url .Parse (endpoint )
61+ if err != nil {
62+ return fmt .Errorf ("invalid URL format: %w" , err )
63+ }
64+
65+ if parsedURL .Scheme != "http" && parsedURL .Scheme != "https" {
66+ return fmt .Errorf ("endpoint must use http or https protocol" )
67+ }
68+
69+ if parsedURL .Host == "" {
70+ return fmt .Errorf ("endpoint must have a valid host" )
71+ }
72+
73+ return nil
74+ }
75+
4276func runInteractiveConfig () {
4377 currentProvider := config .GetProvider ()
4478 currentModel , _ := config .GetModel ()
4579
4680 providerPrompt := & survey.Select {
4781 Message : "Choose a provider:" ,
48- Options : []string {"openai" , "openrouter" , " copilot" },
82+ Options : []string {"openai" , "copilot" },
4983 Default : currentProvider ,
5084 }
5185 var selectedProvider string
@@ -87,9 +121,8 @@ func runInteractiveConfig() {
87121
88122 // Dynamically generate available models for OpenAI
89123 availableModels := map [string ][]string {
90- "openai" : {},
91- "openrouter" : {},
92- "copilot" : {"gpt-4o" }, // TODO: update if copilot models are dynamic
124+ "openai" : {},
125+ "copilot" : {"gpt-4o" }, // TODO: update if copilot models are dynamic
93126 }
94127
95128 modelDisplayToID := map [string ]string {}
@@ -99,12 +132,6 @@ func runInteractiveConfig() {
99132 availableModels ["openai" ] = append (availableModels ["openai" ], display )
100133 modelDisplayToID [display ] = string (id )
101134 }
102- } else if selectedProvider == "openrouter" {
103- for id , m := range models .OpenRouterModels {
104- display := fmt .Sprintf ("%s (%s)" , m .Name , string (id ))
105- availableModels ["openrouter" ] = append (availableModels ["openrouter" ], display )
106- modelDisplayToID [display ] = string (id )
107- }
108135 }
109136
110137 modelPrompt := & survey.Select {
@@ -115,7 +142,7 @@ func runInteractiveConfig() {
115142 // Try to set the default to the current model if possible
116143 isValidDefault := false
117144 currentDisplay := ""
118- if selectedProvider == "openai" || selectedProvider == "openrouter" {
145+ if selectedProvider == "openai" {
119146 for display , id := range modelDisplayToID {
120147 if id == currentModel || display == currentModel {
121148 isValidDefault = true
@@ -144,7 +171,7 @@ func runInteractiveConfig() {
144171 }
145172
146173 selectedModel := selectedDisplay
147- if selectedProvider == "openai" || selectedProvider == "openrouter" {
174+ if selectedProvider == "openai" {
148175 selectedModel = modelDisplayToID [selectedDisplay ]
149176 }
150177
@@ -156,6 +183,33 @@ func runInteractiveConfig() {
156183 }
157184 fmt .Printf ("Model set to: %s\n " , selectedModel )
158185 }
186+
187+ // Get current endpoint
188+ currentEndpoint , _ := config .GetEndpoint ()
189+
190+ // Endpoint configuration prompt
191+ endpointPrompt := & survey.Input {
192+ Message : "Enter custom endpoint URL (leave empty for default):" ,
193+ Default : currentEndpoint ,
194+ }
195+ var endpoint string
196+ err = survey .AskOne (endpointPrompt , & endpoint , survey .WithValidator (validateEndpointURL ))
197+ if err != nil {
198+ fmt .Println (err .Error ())
199+ return
200+ }
201+
202+ // Only set endpoint if it's different from current
203+ if endpoint != currentEndpoint && endpoint != "" {
204+ err := config .SetEndpoint (selectedProvider , endpoint )
205+ if err != nil {
206+ fmt .Printf ("Error setting endpoint: %v\n " , err )
207+ return
208+ }
209+ fmt .Printf ("Endpoint set to: %s\n " , endpoint )
210+ } else if endpoint == "" {
211+ fmt .Println ("Using default endpoint for provider" )
212+ }
159213}
160214
161215func init () {
0 commit comments