Skip to content

Commit c19bd1d

Browse files
pjcdawkinsclaudemiguelsanchez-upsun
authored
refactor(init): use API base URL for AI configuration endpoint (#41)
The /ai/generate-configuration endpoint is now served by the general Upsun API (api.upsun.com) instead of a separate AI service host (ai.upsun.com). Remove the separate ai_url config field and AIServiceURL references, using the existing API base URL instead. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: miguelsanchez-upsun <miguel.sanchez@platform.sh>
1 parent ffb380d commit c19bd1d

4 files changed

Lines changed: 11 additions & 22 deletions

File tree

‎commands/init.go‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commands
22

33
import (
44
"bytes"
5-
"cmp"
65
"context"
76
"fmt"
87
"io"
@@ -109,9 +108,6 @@ func runInitCommand(
109108

110109
cnf := config.FromContext(cmd.Context())
111110

112-
// TODO check if this is needed
113-
cnf.API.AIServiceURL = cmp.Or(os.Getenv(cnf.Application.EnvPrefix+"API_AI_URL"), cnf.API.AIServiceURL)
114-
115111
legacyCLIClient, err := auth.NewLegacyCLIClient(cmd.Context(),
116112
makeLegacyCLIWrapper(cnf, cmd.OutOrStdout(), cmd.ErrOrStderr(), cmd.InOrStdin()))
117113
if err != nil {
@@ -183,7 +179,7 @@ func runInitCommand(
183179
}
184180

185181
initOptions.HTTPClient = legacyCLIClient.HTTPClient
186-
initOptions.AIServiceURL = cnf.API.AIServiceURL
182+
initOptions.APIURL = cnf.API.BaseURL
187183
initOptions.UserAgent = cnf.UserAgent()
188184
initOptions.IsInteractive = isInteractive
189185
initOptions.Yes = viper.GetBool("yes")
@@ -233,9 +229,6 @@ func canUseAI(cnf *config.Config) (msg string, canUseAI bool) {
233229
if !cnf.API.EnableOrganizations {
234230
return "using AI requires Organizations to be enabled", false
235231
}
236-
if cnf.API.AIServiceURL == "" {
237-
return "using AI requires the service URL to be set", false
238-
}
239232
return "", true
240233
}
241234

‎internal/config/schema.go‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ type Config struct {
4848
UserAgent string `validate:"omitempty" yaml:"user_agent,omitempty"` // a template - see UserAgent method
4949
SessionID string `validate:"omitempty,ascii" yaml:"session_id,omitempty"` // the ID for the authentication session - defaults to "default"
5050

51-
OAuth2ClientID string `validate:"omitempty" yaml:"oauth2_client_id,omitempty"` // e.g. "upsun-cli"
52-
OAuth2AuthorizeURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_auth_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/authorize"
53-
OAuth2RevokeURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_revoke_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/revoke"
54-
OAuth2TokenURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_token_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/token"
55-
CertifierURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"certifier_url,omitempty"` // No longer used
56-
57-
AIServiceURL string `validate:"omitempty,url" yaml:"ai_url,omitempty"` // The AI service URL, e.g. "https://ai.upsun.com".
58-
EnableOrganizations bool `validate:"omitempty" yaml:"organizations,omitempty"` // Whether the "organizations" feature is enabled.
51+
OAuth2ClientID string `validate:"omitempty" yaml:"oauth2_client_id,omitempty"` // e.g. "upsun-cli"
52+
OAuth2AuthorizeURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_auth_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/authorize"
53+
OAuth2RevokeURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_revoke_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/revoke"
54+
OAuth2TokenURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"oauth2_token_url,omitempty"` // e.g. "https://auth.upsun.com/oauth2/token"
55+
CertifierURL string `validate:"required_without=AuthURL,omitempty,url" yaml:"certifier_url,omitempty"` // No longer used
56+
EnableOrganizations bool `validate:"omitempty" yaml:"organizations,omitempty"` // Whether the "organizations" feature is enabled.
5957
} `validate:"required"`
6058
Detection struct {
6159
GitRemoteName string `validate:"required" yaml:"git_remote_name"` // e.g. "upsun"

‎internal/config/upsun-cli.yaml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ api:
5454
auth_url: "https://auth.upsun.com"
5555
oauth2_client_id: "upsun-cli"
5656

57-
ai_url: "https://ai.upsun.com"
58-
5957
organization_types: [flexible, fixed]
6058
default_organization_type: flexible
6159

‎internal/init/command.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Options struct {
3131
ExtraContext string
3232

3333
HTTPClient *http.Client
34-
AIServiceURL string
34+
APIURL string
3535
UserAgent string
3636
RequestTimeout time.Duration // Defaults to 10 minutes
3737

@@ -53,8 +53,8 @@ func RunAIConfig(
5353
opts *Options,
5454
stdout, stderr io.Writer,
5555
) error {
56-
if opts.AIServiceURL == "" {
57-
return fmt.Errorf("no AI service URL available")
56+
if opts.APIURL == "" {
57+
return fmt.Errorf("no API URL available")
5858
}
5959
if opts.HTTPClient == nil {
6060
opts.HTTPClient = http.DefaultClient
@@ -88,7 +88,7 @@ func RunAIConfig(
8888
return err
8989
}
9090

91-
u, err := url.Parse(opts.AIServiceURL)
91+
u, err := url.Parse(opts.APIURL)
9292
if err != nil {
9393
return err
9494
}

0 commit comments

Comments
 (0)