From 23208e74cd9ea5c7035cd9a2b9caab16a5e57d84 Mon Sep 17 00:00:00 2001 From: miqui Date: Thu, 19 Nov 2026 09:28:02 -0500 Subject: [PATCH] Add read-only commands for the model catalog and providers `models list`, `models providers`, and `models discover ID` map to the Platform model-gateway read routes. Provider writes stay in the dashboard for now. Co-Authored-By: Claude Opus 5.5 --- docs/api-coverage.md | 10 +++++-- docs/cli-reference.md | 32 +++++++++++++++++++++ skills/adapt/SKILL.md | 13 +++++++++ src/cli.rs | 18 ++++++++++++ src/commands.rs | 5 ++++ tests/cli.rs | 1 + tests/models/mod.rs | 67 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 tests/models/mod.rs diff --git a/docs/api-coverage.md b/docs/api-coverage.md index 722684b..21dacc4 100644 --- a/docs/api-coverage.md +++ b/docs/api-coverage.md @@ -3,9 +3,10 @@ Based on the resource OpenAPI document from `../platform` at `f20ded3`, plus its dashboard auth integrations. The `query` filter on `GET /v1/sandboxes` and the `name` and `status` filters on `GET /v1/images` come from platform `2396647`. `GET /v1/sandboxes/{id}/usage` -comes from platform `d3b6c77`. -Every resource operation has a named command. `adapt api METHOD PATH` -also exposes same-origin JSON requests for less common account operations. +comes from platform `d3b6c77`. The model routes come from platform `8747699`. +Every resource operation has a named command, except model provider writes (`POST`, `PUT`, +and `DELETE` on `/v1/model-gateway/providers`); configure providers in the Platform dashboard. +`adapt api METHOD PATH` also exposes same-origin JSON requests for less common account operations. `{id}` denotes the corresponding resource ID. Writes requiring an idempotency key receive one from the CLI, or reuse the UUID supplied with `--idempotency-key`. @@ -60,6 +61,9 @@ one from the CLI, or reuse the UUID supplied with `--idempotency-key`. | `GET /v1/environment-variable-sets/{id}` | `env get ID` | | `PUT /v1/environment-variable-sets/{id}` | `env update ID --data JSON` | | `DELETE /v1/environment-variable-sets/{id}` | `env delete ID` | +| `GET /v1/models` | `models list` | +| `GET /v1/model-gateway/providers` | `models providers` | +| `GET /v1/model-gateway/providers/{id}/models` | `models discover ID` | | `POST /v1/gateway/connections` | `connections create --data JSON` | | `GET /v1/gateway/connections` | `connections list` | | `GET /v1/gateway/connections/{id}` | `connections get ID` | diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 13c946a..dbf8aa9 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -10,6 +10,7 @@ Replace example names such as `SANDBOX_ID` and `EXEC_ID` with your resource IDs. - [Files](#files) - [Hosted applications](#hosted-applications) - [Images and environment variables](#images-and-environment-variables) +- [Models](#models) - [Resource IDs](#resource-ids) - [JSON requests](#json-requests) - [Lists and filters](#lists-and-filters) @@ -42,6 +43,7 @@ For example, use `adapt org members ls` or `adapt sandbox ls --all`. | `env` | `list`, `get`, `create`, `update`, `delete` | | `registry` | `list`, `create`, `update`, `delete` | | `connections` | `list`, `get`, `create`, `update`, `delete`, `refresh`, `grant`, `oauth`, `oauth-complete`, `calls`, `principals`, `search`, `describe`, `call` | +| `models` | `list`, `providers`, `discover` | | `keys` | `list`, `create`, `delete` | | `sessions` | `list`, `revoke`, `revoke-others` | | `mcp` | `list`, `revoke`, `tools` | @@ -390,6 +392,35 @@ Create a sandbox with the image and variable set: adapt sandbox create --image-id IMAGE_ID --variable-set VARIABLE_SET_ID --wait ``` +## Models + +List the models enabled in your organization: + +```sh +adapt models list +``` + +Model IDs include the provider prefix, such as `openai/gpt-5`. +This command requires the `modelGateway` `use` permission. +Owners and admins have it; an API key has it only if its permissions grant it. + +List the configured model providers: + +```sh +adapt models providers +``` + +The output never includes provider API keys. +To configure providers, use the Platform dashboard. + +To list every model that a provider offers, including disabled models, run: + +```sh +adapt models discover PROVIDER_ID +``` + +`discover` requires a browser login as an organization owner or admin. + ## Resource IDs These resources accept full UUIDs or unique ID prefixes: @@ -398,6 +429,7 @@ These resources accept full UUIDs or unique ID prefixes: - Images and registry credentials. - Volumes and endpoints. - Environment variable sets and tool connections. +- Model providers. This also applies to references such as `--image-id`, `--credential`, and both IDs in an endpoint binding. diff --git a/skills/adapt/SKILL.md b/skills/adapt/SKILL.md index 1bfc05d..236add0 100644 --- a/skills/adapt/SKILL.md +++ b/skills/adapt/SKILL.md @@ -122,6 +122,19 @@ describe the message-posting tool and use that channel ID. Listing channels is a separate action from sending a message. Inspect tool results for reported errors as well as the CLI exit status. +## Models + +```sh +adapt models list --json +adapt models providers --json +``` + +`models list` returns the organization's enabled models; IDs include the +provider prefix, such as `openai/gpt-5`. It needs `modelGateway` `use` +permission, which an API key has only if granted. `models providers` lists configured +providers without their keys. `models discover PROVIDER_ID` lists every model a +provider offers and requires browser sign-in as an owner or admin. + ## Platform MCP server ```sh diff --git a/src/cli.rs b/src/cli.rs index 61b7597..766a270 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -75,6 +75,9 @@ pub enum Command { /// Manage upstream MCP connections and call tools #[command(subcommand)] Connections(ConnectionCommand), + /// Inspect model providers and the enabled model catalog + #[command(subcommand, visible_alias = "model")] + Models(ModelCommand), /// Manage organization API keys #[command(subcommand)] Keys(KeyCommand), @@ -725,6 +728,21 @@ pub enum SessionCommand { RevokeOthers, } +#[derive(Subcommand)] +pub enum ModelCommand { + /// List the organization's enabled models, as provider/model IDs + #[command(visible_alias = "ls")] + List, + /// List configured model providers (API keys are never returned) + Providers, + /// List every model a provider offers, including disabled models + #[command(after_help = "Requires browser sign-in as an organization owner or admin.")] + Discover { + /// Full provider UUID or an unambiguous ID prefix + id: ResourceRef, + }, +} + #[derive(Subcommand)] pub enum McpCommand { /// List MCP clients you have authorized diff --git a/src/commands.rs b/src/commands.rs index 4b3f66b..1969a0e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -193,6 +193,11 @@ pub async fn run(cli: Cli) -> Result { RegistryCommand::Delete { id } => delete(&api, &format!("/v1/registry-credentials/{id}")).await?, }, Command::Connections(command) => connections(&api, command).await?, + Command::Models(command) => match command { + ModelCommand::List => api.get("/v1/models").await?, + ModelCommand::Providers => api.get("/v1/model-gateway/providers").await?, + ModelCommand::Discover { id } => api.get(&format!("/v1/model-gateway/providers/{id}/models")).await?, + }, Command::Keys(command) => keys(&api, command).await?, Command::Sessions(command) => match command { SessionCommand::List => api.get("/v1/auth/sessions").await?, diff --git a/tests/cli.rs b/tests/cli.rs index b573335..cabd707 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -6,6 +6,7 @@ use support::*; mod endpoint_request; mod image_list; mod mcp_tools; +mod models; mod resource_prefixes; mod retries; mod sandbox_list; diff --git a/tests/models/mod.rs b/tests/models/mod.rs new file mode 100644 index 0000000..a104bd7 --- /dev/null +++ b/tests/models/mod.rs @@ -0,0 +1,67 @@ +use crate::support::*; +use serde_json::json; + +#[test] +fn model_commands_request_their_paths_and_pass_json_through() { + let catalog = json!({"object":"list","data":[ + {"id":"openai/gpt-5","object":"model","created":1762800000,"owned_by":"openai"} + ]}); + let providers = json!({"providers":[{ + "id":ID,"provider":"openai","name":"OpenAI","disabledModels":["gpt-4o"],"enabled":true, + "version":2,"createdAt":"2026-11-11T00:00:00Z","updatedAt":"2026-11-12T00:00:00Z" + }],"adaptProviders":["anthropic"]}); + let discovered = json!({"version":2,"models":[ + {"id":"gpt-5","name":"GPT-5"},{"id":"gpt-4o","name":"GPT-4o"} + ]}); + let server = Server::start(vec![ + step("GET", "/v1/models".into(), None, catalog.clone()), + step( + "GET", + "/v1/model-gateway/providers".into(), + None, + providers.clone(), + ), + step( + "GET", + "/v1/model-gateway/providers/11111111/models".into(), + None, + discovered.clone(), + ), + ]); + let dir = tempfile::tempdir().unwrap(); + assert_eq!( + success(&run(dir.path(), &server.url, &["models", "list"])), + catalog + ); + assert_eq!( + success(&run(dir.path(), &server.url, &["models", "providers"])), + providers + ); + assert_eq!( + success(&run( + dir.path(), + &server.url, + &["models", "discover", "11111111"] + )), + discovered + ); + server.finish(); +} + +#[test] +fn discover_reports_the_api_error() { + let server = Server::start(vec![Box::new(|_| { + Reply::json( + 403, + json!({"error":{"code":"FORBIDDEN","message":"Sign in as an owner or admin to manage provider keys."}}), + ) + })]); + let dir = tempfile::tempdir().unwrap(); + let output = run(dir.path(), &server.url, &["models", "discover", ID]); + assert!(!output.status.success()); + assert!( + String::from_utf8_lossy(&output.stderr) + .contains("403 FORBIDDEN: Sign in as an owner or admin to manage provider keys.") + ); + server.finish(); +}