mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
Add an endpoint to fetch AI task prompts for multiple workspace builds at the same time. A prompt is the value of the "AI Prompt" workspace build parameter. On main, the only way our API allows fetching workspace build parameters is by using the `/workspacebuilds/$build_id/parameters` endpoint, requiring a separate API call for every build. The Tasks dashboard fetches Task workspaces in order to show them in a list, and then needs to fetch the value of the `AI Prompt` parameter for every task workspace (using its latest build id), requiring an additional API call for each list item. This endpoint will allow the dashboard to make just 2 calls to render the list: one to fetch task workspaces, the other to fetch prompts. <img width="1512" alt="Screenshot 2025-06-20 at 11 33 11" src="https://github.com/user-attachments/assets/92899999-e922-44c5-8325-b4b23a0d2bff" /> Related to https://github.com/coder/internal/issues/660.
59 lines
1.6 KiB
SQL
59 lines
1.6 KiB
SQL
-- name: InsertWorkspaceBuildParameters :exec
|
|
INSERT INTO
|
|
workspace_build_parameters (workspace_build_id, name, value)
|
|
SELECT
|
|
@workspace_build_id :: uuid AS workspace_build_id,
|
|
unnest(@name :: text[]) AS name,
|
|
unnest(@value :: text[]) AS value
|
|
RETURNING *;
|
|
|
|
-- name: GetWorkspaceBuildParameters :many
|
|
SELECT
|
|
*
|
|
FROM
|
|
workspace_build_parameters
|
|
WHERE
|
|
workspace_build_id = $1;
|
|
|
|
-- name: GetUserWorkspaceBuildParameters :many
|
|
SELECT name, value
|
|
FROM (
|
|
SELECT DISTINCT ON (tvp.name)
|
|
tvp.name,
|
|
wbp.value,
|
|
wb.created_at
|
|
FROM
|
|
workspace_build_parameters wbp
|
|
JOIN
|
|
workspace_builds wb ON wb.id = wbp.workspace_build_id
|
|
JOIN
|
|
workspaces w ON w.id = wb.workspace_id
|
|
JOIN
|
|
template_version_parameters tvp ON tvp.template_version_id = wb.template_version_id
|
|
WHERE
|
|
w.owner_id = $1
|
|
AND wb.transition = 'start'
|
|
AND w.template_id = $2
|
|
AND tvp.ephemeral = false
|
|
AND tvp.name = wbp.name
|
|
ORDER BY
|
|
tvp.name, wb.created_at DESC
|
|
) q1
|
|
ORDER BY created_at DESC, name
|
|
LIMIT 100;
|
|
|
|
-- name: GetWorkspaceBuildParametersByBuildIDs :many
|
|
SELECT
|
|
workspace_build_parameters.*
|
|
FROM
|
|
workspace_build_parameters
|
|
JOIN
|
|
workspace_builds ON workspace_builds.id = workspace_build_parameters.workspace_build_id
|
|
JOIN
|
|
workspaces ON workspaces.id = workspace_builds.workspace_id
|
|
WHERE
|
|
workspace_build_parameters.workspace_build_id = ANY(@workspace_build_ids :: uuid[])
|
|
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaceBuildParametersByBuildIDs
|
|
-- @authorize_filter
|
|
;
|