Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions components/ambient-cli/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
module github.com/ambient-code/platform/components/ambient-cli

go 1.24
go 1.24.0

toolchain go1.24.4

require (
github.com/ambient-code/platform/components/ambient-sdk/go-sdk v0.0.0
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/spf13/cobra v1.9.1
golang.org/x/term v0.28.0
golang.org/x/term v0.38.0
)

require (
github.com/ambient-code/platform/components/ambient-api-server v0.0.0-20260304211549-047314a7664b // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.32.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/grpc v1.79.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)

replace github.com/ambient-code/platform/components/ambient-sdk/go-sdk => ../ambient-sdk/go-sdk
46 changes: 42 additions & 4 deletions components/ambient-cli/go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
github.com/ambient-code/platform/components/ambient-api-server v0.0.0-20260304211549-047314a7664b h1:nmYJWbkCDU+NiZUQT/kdpW6WUTlDrNstWXr0JOFBR4c=
github.com/ambient-code/platform/components/ambient-api-server v0.0.0-20260304211549-047314a7664b/go.mod h1:r4ZByb4gVckDNzRU/EdyFY+UwSKn6M+lv04Z4YvOPNQ=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g=
go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g=
go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc=
go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18=
go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE=
go.opentelemetry.io/otel/sdk/metric v1.40.0 h1:mtmdVqgQkeRxHgRv4qhyJduP3fYJRMX4AtAlbuWdCYw=
go.opentelemetry.io/otel/sdk/metric v1.40.0/go.mod h1:4Z2bGMf0KSK3uRjlczMOeMhKU2rhUqdWNoKcYrtcBPg=
go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw=
go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY=
google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Binary file added components/ambient-sdk/bin/ambient-sdk-generator
Binary file not shown.
Binary file modified components/ambient-sdk/generator/ambient-sdk-generator
Binary file not shown.
1 change: 1 addition & 0 deletions components/ambient-sdk/generator/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Field struct {
}

type Spec struct {
BasePath string
Resources []Resource
}

Expand Down
36 changes: 32 additions & 4 deletions components/ambient-sdk/generator/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ type openAPIDoc struct {
} `yaml:"components"`
}

func extractBasePath(paths map[string]interface{}) string {
for path := range paths {
parts := strings.SplitN(path, "/", -1)
// Expect paths like /api/ambient/v1/resource or /api/ambient-api-server/v1/resource
// Find the common prefix by looking for the version segment (v\d+)
for i, part := range parts {
if len(part) > 1 && part[0] == 'v' && len(part) > 1 {
allDigits := true
for _, c := range part[1:] {
if c < '0' || c > '9' {
allDigits = false
break
}
}
if allDigits {
return strings.Join(parts[:i+1], "/")
}
}
}
}
return "/api/ambient/v1"
}

type subSpecDoc struct {
Paths map[string]interface{} `yaml:"paths"`
Components struct {
Expand Down Expand Up @@ -76,7 +99,9 @@ func parseSpec(specPath string) (*Spec, error) {
return resources[i].Name < resources[j].Name
})

return &Spec{Resources: resources}, nil
basePath := extractBasePath(mainDoc.Paths)

return &Spec{BasePath: basePath, Resources: resources}, nil
}

func extractResource(name, pathSegment string, doc *subSpecDoc) (*Resource, error) {
Expand Down Expand Up @@ -313,7 +338,8 @@ func extractPatchFields(schemaMap map[string]interface{}) ([]Field, []string, er
}

func checkHasPatch(paths map[string]interface{}, pathSegment string) bool {
idPath := fmt.Sprintf("/api/ambient-api-server/v1/%s/{id}", pathSegment)
basePath := extractBasePath(paths)
idPath := fmt.Sprintf("%s/%s/{id}", basePath, pathSegment)
pathVal, ok := paths[idPath]
if !ok {
return false
Expand All @@ -329,7 +355,8 @@ func checkHasPatch(paths map[string]interface{}, pathSegment string) bool {
}

func checkHasDelete(paths map[string]interface{}, pathSegment string) bool {
idPath := fmt.Sprintf("/api/ambient-api-server/v1/%s/{id}", pathSegment)
basePath := extractBasePath(paths)
idPath := fmt.Sprintf("%s/%s/{id}", basePath, pathSegment)
pathVal, ok := paths[idPath]
if !ok {
return false
Expand All @@ -345,10 +372,11 @@ func checkHasDelete(paths map[string]interface{}, pathSegment string) bool {
}

func detectActions(paths map[string]interface{}, pathSegment string) []string {
basePath := extractBasePath(paths)
knownActions := []string{"start", "stop"}
var found []string
for _, action := range knownActions {
actionPath := fmt.Sprintf("/api/ambient-api-server/v1/%s/{id}/%s", pathSegment, action)
actionPath := fmt.Sprintf("%s/%s/{id}/%s", basePath, pathSegment, action)
pathVal, ok := paths[actionPath]
if !ok {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewClientFromEnv(opts ...ClientOption) (*Client, error) {
}

func (c *Client) do(ctx context.Context, method, path string, body []byte, expectedStatus int, result interface{}) error {
url := c.baseURL + "/api/ambient-api-server/v1" + path
url := c.baseURL + "{{.Spec.BasePath}}" + path

req, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if TYPE_CHECKING:
class AmbientClient:
"""HTTP client for the Ambient Platform API."""

_base_path = "/api/ambient-api-server/v1"
_base_path = "{{.Spec.BasePath}}"

def __init__(
self,
Expand Down Expand Up @@ -110,7 +110,7 @@ class AmbientClient:
expect_json: bool = True,
) -> Any:
"""Make HTTP request to the API."""
url = self._base_url + "/api/ambient-api-server/v1" + path
url = self._base_url + "{{.Spec.BasePath}}" + path

headers = {
"Authorization": f"Bearer {self._token}",
Expand Down
2 changes: 1 addition & 1 deletion components/ambient-sdk/generator/templates/ts/base.ts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function ambientFetch<T>(
body?: unknown,
requestOpts?: RequestOptions,
): Promise<T> {
const url = `${config.baseUrl}/api/ambient-api-server/v1${path}`;
const url = `${config.baseUrl}{{.Spec.BasePath}}${path}`;
const headers: Record<string, string> = {
'Authorization': `Bearer ${config.token}`,
'X-Ambient-Project': config.project,
Expand Down
26 changes: 11 additions & 15 deletions components/ambient-sdk/go-sdk/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/ambient-sdk/go-sdk/client/iterator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/ambient-sdk/go-sdk/client/project_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions components/ambient-sdk/go-sdk/client/project_settings_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions components/ambient-sdk/go-sdk/client/session_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading