Files
coder/coderd/database/queries/skills.sql
T
c4d76a4009 feat: add skill action and automatic-use settings (#30882)
Adds two per-skill settings that the project skills UI will expose next:

- `action` marks a project skill to show as an action button above
project chat composers. A `skills_action_project_only` check keeps it to
project skills; the personal and organization routes reject `action`
with 400.
- `model_invocable` (default true, every stored source) controls
automatic use. When it's false the skill is left out of
`<available-skills>` and `read_skill` reports it as not found, but a
structured skill invocation (a chip from the `/` menu or an action)
still loads it, as long as the skill is enabled and the chat owner can
read it. Workspace skills always count as model-invocable.

Migration 000625 adds both columns with defaults, so existing skills
keep today's behavior. The list, get, insert and update queries,
`codersdk.SkillMetadata` and the create/update requests carry both
fields, and the audit table tracks them.
`coderd/x/chatd/ARCHITECTURE.md` gets TODO notes for the author.

**NOTE**: the migration adds two columns with constant defaults and a
CHECK constraint to `skills`.

Stack (merge top to bottom):
- #30826
- #30827
- #30838
- #30840
- #30854
- #30855
- #30856
- #30861
- #30880
- #30881
- #30882 👈
- #30884
- #31122
- #31126

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Nick Vigilante <nickvigilante@users.noreply.github.com>
2026-10-23 19:32:08 +07:00

123 lines
4.3 KiB
SQL

-- name: InsertUserSkill :one
INSERT INTO skills (id, user_id, name, description, content, model_invocable)
VALUES (@id::uuid, @user_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('model_invocable')::boolean, true))
RETURNING *;
-- name: GetUserSkillByUserIDAndName :one
SELECT *
FROM skills
WHERE user_id = @user_id::uuid AND name = @name;
-- name: ListUserSkillMetadataByUserID :many
SELECT
id, user_id, name, description, enabled, action, model_invocable, created_at, updated_at
FROM skills
WHERE user_id = @user_id::uuid
ORDER BY name ASC;
-- name: UpdateUserSkillByUserIDAndName :one
UPDATE skills
SET
description = COALESCE(sqlc.narg('description')::text, description),
content = COALESCE(sqlc.narg('content')::text, content),
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable),
updated_at = now()
WHERE user_id = @user_id::uuid AND name = @name
RETURNING *;
-- name: DeleteUserSkillByUserIDAndName :one
DELETE FROM skills
WHERE user_id = @user_id::uuid AND name = @name
RETURNING *;
-- name: InsertOrganizationSkill :one
INSERT INTO skills (id, organization_id, name, description, content, model_invocable, group_acl, user_acl)
VALUES (@id::uuid, @organization_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('model_invocable')::boolean, true), @group_acl, @user_acl)
RETURNING *;
-- name: GetOrganizationSkillByOrganizationIDAndName :one
SELECT *
FROM skills
WHERE organization_id = @organization_id::uuid AND name = @name;
-- name: ListOrganizationSkillMetadataByOrganizationID :many
SELECT
id, organization_id, name, description, enabled, action, model_invocable, created_at, updated_at
FROM skills
WHERE organization_id = @organization_id::uuid
-- Authorize Filter clause will be injected below in GetAuthorizedOrganizationSkillMetadata
-- @authorize_filter
ORDER BY name ASC;
-- name: UpdateOrganizationSkillByOrganizationIDAndName :one
UPDATE skills
SET
description = COALESCE(sqlc.narg('description')::text, description),
content = COALESCE(sqlc.narg('content')::text, content),
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable),
updated_at = now()
WHERE organization_id = @organization_id::uuid AND name = @name
RETURNING *;
-- name: DeleteOrganizationSkillByOrganizationIDAndName :one
DELETE FROM skills
WHERE organization_id = @organization_id::uuid AND name = @name
RETURNING *;
-- name: GetOrganizationSkillByIDForUpdate :one
SELECT *
FROM skills
WHERE id = @id::uuid AND organization_id IS NOT NULL
FOR UPDATE;
-- name: UpdateOrganizationSkillACLByID :one
UPDATE skills
SET
group_acl = @group_acl,
user_acl = @user_acl,
updated_at = now()
WHERE id = @id::uuid AND organization_id IS NOT NULL
RETURNING *;
-- name: InsertProjectSkill :one
INSERT INTO skills (id, project_id, name, description, content, action, model_invocable)
VALUES (@id::uuid, @project_id::uuid, @name::text, @description::text, @content::text, COALESCE(sqlc.narg('action')::boolean, false), COALESCE(sqlc.narg('model_invocable')::boolean, true))
RETURNING *;
-- name: GetProjectSkillByProjectIDAndName :one
SELECT *
FROM skills
WHERE project_id = @project_id::uuid AND name = @name;
-- name: ListProjectSkillMetadataByProjectID :many
SELECT
id, project_id, name, description, enabled, action, model_invocable, created_at, updated_at
FROM skills
WHERE project_id = @project_id::uuid
ORDER BY name ASC;
-- name: UpdateProjectSkillByProjectIDAndName :one
UPDATE skills
SET
description = COALESCE(sqlc.narg('description')::text, description),
content = COALESCE(sqlc.narg('content')::text, content),
enabled = COALESCE(sqlc.narg('enabled')::boolean, enabled),
model_invocable = COALESCE(sqlc.narg('model_invocable')::boolean, model_invocable),
action = COALESCE(sqlc.narg('action')::boolean, action),
updated_at = now()
WHERE project_id = @project_id::uuid AND name = @name
RETURNING *;
-- name: DeleteProjectSkillByProjectIDAndName :one
DELETE FROM skills
WHERE project_id = @project_id::uuid AND name = @name
RETURNING *;
-- name: GetProjectSkillByIDForUpdate :one
SELECT *
FROM skills
WHERE id = @id::uuid AND project_id IS NOT NULL
FOR UPDATE;