Relates to AIGOV-824 Stacked on #32650. `GET /api/v2/ai-gateway/providers` was added in #28966, in September, and first shipped in v2.38.0. It was a fix for the provider filter on the AI Gateway sessions page. That filter called `GET /api/v2/ai/providers`, which only owners could read, so the dropdown was empty for auditors. Rather than open up the provider config, #28966 added a second route that returns just the `name`, `type`, `display_name` and `icon` of every provider, deleted ones included, to anyone who can read sessions, i.e. owners and auditors. Now that `GET /api/v2/ai/providers` answers every signed-in user with those same fields (#32650), the second route has no caller that it alone can serve. Jake, who added it, and I agree that we should remove it rather than keep two routes that list providers, so this PR does that. The one thing only the old route did was return deleted providers, so that sessions and spend recorded under a provider that has since been deleted keep their label. So, `GET /api/v2/ai/providers` gains an `include_deleted` query parameter. A deleted provider can share its name with a live one, so each name appears once, as its live provider if there is one, otherwise the most recently updated deleted one. Unlike the old route, any caller can pass it, so members can now see the names of deleted providers. A deleted provider comes back without its configuration, for owners too. The sessions provider filter and the Spend page now call `GET /api/v2/ai/providers?include_deleted=true`, and show the same thing as before. `codersdk.AIBridgeProvider`, `Client.AIBridgeListProviders` and the `GetAIProviderFilterOptions` query go with the route. ## For changelog - `GET /api/v2/ai-gateway/providers` has been removed (#32651) > `GET /api/v2/ai-gateway/providers` has been removed, along with `codersdk.AIBridgeProvider` and `Client.AIBridgeListProviders` in the Go SDK. It listed providers only for users who can read AI Gateway sessions, i.e. owners and auditors. `GET /api/v2/ai/providers` replaces it, and now answers every signed-in user. Owners still get each provider's full configuration from it, and everyone else gets the same list with an empty `base_url`, an empty `api_keys` array, `null` `settings` and no `status`. > > Migration: Call `GET /api/v2/ai/providers?include_deleted=true` instead. Each provider keeps its `name`, `type`, `display_name` and `icon` fields, and `display_name` now holds the provider name when no display name is set. In the Go SDK, `Client.AIProviders` now takes a `codersdk.AIProvidersFilter`. Set its `IncludeDeleted` field to list deleted providers too. An API token with an allow list needs `ai_provider` in that list to call `GET /api/v2/ai/providers`, where the removed route needed `aibridge_interception`.
129 lines
2.6 KiB
SQL
129 lines
2.6 KiB
SQL
-- name: GetAIProviderByID :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
ai_providers
|
|
WHERE
|
|
id = @id::uuid AND deleted = FALSE;
|
|
|
|
-- name: GetAIProviderByIDForReferenceLock :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
ai_providers
|
|
WHERE
|
|
id = @id::uuid AND deleted = FALSE
|
|
-- Lock the provider row until the model-config write completes. The
|
|
-- transaction alone does not stop a concurrent soft-delete or disable
|
|
-- between validation and writing the model config reference.
|
|
FOR SHARE;
|
|
|
|
-- name: GetAIProviderByName :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
ai_providers
|
|
WHERE
|
|
name = @name::text AND deleted = FALSE;
|
|
|
|
-- name: GetAIProviders :many
|
|
-- Returns AI provider rows. Soft-deleted and disabled rows are excluded
|
|
-- unless include_deleted or include_disabled is set.
|
|
SELECT
|
|
*
|
|
FROM
|
|
ai_providers
|
|
WHERE
|
|
(@include_deleted::boolean OR NOT deleted)
|
|
AND (@include_disabled::boolean OR enabled)
|
|
ORDER BY
|
|
name ASC;
|
|
|
|
-- name: GetAIProviderSummaries :many
|
|
SELECT DISTINCT ON (name)
|
|
id,
|
|
type,
|
|
name,
|
|
display_name,
|
|
icon,
|
|
enabled,
|
|
deleted,
|
|
created_at,
|
|
updated_at
|
|
FROM
|
|
ai_providers
|
|
WHERE
|
|
@include_deleted::boolean OR NOT deleted
|
|
ORDER BY
|
|
name ASC,
|
|
deleted ASC,
|
|
updated_at DESC;
|
|
|
|
-- name: InsertAIProvider :one
|
|
INSERT INTO ai_providers (
|
|
id,
|
|
type,
|
|
name,
|
|
display_name,
|
|
icon,
|
|
enabled,
|
|
base_url,
|
|
settings,
|
|
settings_key_id
|
|
) VALUES (
|
|
@id::uuid,
|
|
@type::ai_provider_type,
|
|
@name::text,
|
|
sqlc.narg('display_name')::text,
|
|
@icon::text,
|
|
@enabled::boolean,
|
|
@base_url::text,
|
|
sqlc.narg('settings')::text,
|
|
sqlc.narg('settings_key_id')::text
|
|
)
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: UpdateAIProvider :one
|
|
UPDATE
|
|
ai_providers
|
|
SET
|
|
type = @type::ai_provider_type,
|
|
display_name = sqlc.narg('display_name')::text,
|
|
icon = @icon::text,
|
|
enabled = @enabled::boolean,
|
|
base_url = @base_url::text,
|
|
settings = sqlc.narg('settings')::text,
|
|
settings_key_id = sqlc.narg('settings_key_id')::text,
|
|
updated_at = NOW()
|
|
WHERE
|
|
id = @id::uuid AND deleted = FALSE
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: DeleteAIProviderByID :exec
|
|
UPDATE
|
|
ai_providers
|
|
SET
|
|
deleted = TRUE,
|
|
enabled = FALSE,
|
|
updated_at = NOW()
|
|
WHERE
|
|
id = @id::uuid AND deleted = FALSE;
|
|
|
|
-- name: UpdateEncryptedAIProviderSettings :one
|
|
-- Updates only the encrypted columns (settings, settings_key_id) and
|
|
-- the updated_at timestamp on a row, regardless of its deleted flag.
|
|
-- Used by the dbcrypt key rotation utility to re-encrypt or decrypt
|
|
-- rows in place.
|
|
UPDATE
|
|
ai_providers
|
|
SET
|
|
settings = sqlc.narg('settings')::text,
|
|
settings_key_id = sqlc.narg('settings_key_id')::text,
|
|
updated_at = NOW()
|
|
WHERE
|
|
id = @id::uuid
|
|
RETURNING
|
|
*;
|