closes CODAGT-1506 Project skill action chips show the skill's slug (`deploy-bot`, `security-review`), because skill names must be kebab-case. This adds an optional display name that labels the chip instead. Project skills get a `display_name` column, set through `display_name` on the create and update requests. It is limited to project skills (the same rule as `action`), trimmed, single line, and at most 64 Unicode code points. The chip, its tooltip, and the "More" menu show the display name, sort by it, and fall back to the skill name when it is empty. When a display name is set, the tooltip and the menu item also show the `/name` slash command, so actions that share a display name stay distinguishable. Clicking an action still inserts `/name`, and the `/` menu is unchanged. The project skill editor shows a **Display name** field under **Show as action** only while that switch is on. Turning the switch off hides the field but keeps its value, and saves omit `display_name` while the action is off, so the stored value stays. The display name lives in the database rather than SKILL.md frontmatter, so downloading and re-importing a skill does not carry it. To share the code-point length check with the editor, `countCharacters` and `maxCharacters` move from `ChatProjectDialog.tsx` into `site/src/utils/formUtils.ts`. <img width="637" alt="Project skill editor with the Display name field under Show as action" src="https://raw.githubusercontent.com/coder/coder/assets/pr-skill-action-display-name/pr/edit.png" /> <img width="520" alt="Action chips labeled with display names, with the tooltip open" src="https://raw.githubusercontent.com/coder/coder/assets/pr-skill-action-display-name/pr/chips.png" /> Refs CODAGT-1506
161 lines
6.1 KiB
SQL
161 lines
6.1 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, display_name)
|
|
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), COALESCE(sqlc.narg('display_name')::text, ''))
|
|
RETURNING *;
|
|
|
|
-- name: GetProjectSkillByProjectIDAndName :one
|
|
SELECT *
|
|
FROM skills
|
|
WHERE project_id = @project_id::uuid AND name = @name;
|
|
|
|
-- name: ListProjectSkillMetadataByProjectID :many
|
|
SELECT
|
|
id, project_id, name, display_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),
|
|
display_name = COALESCE(sqlc.narg('display_name')::text, display_name),
|
|
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;
|
|
|
|
-- name: GetOrganizationSkillMemberPreferences :one
|
|
-- Returns the organization's member opt-out setting and the member's stored
|
|
-- choices. Members without stored choices get the defaults.
|
|
SELECT
|
|
organizations.members_can_disable_skills,
|
|
COALESCE(s.all_skills_disabled, false)::boolean AS all_skills_disabled,
|
|
ARRAY(
|
|
SELECT skill_id
|
|
FROM organization_member_disabled_skills
|
|
WHERE organization_id = @organization_id::uuid AND user_id = @user_id::uuid
|
|
ORDER BY skill_id
|
|
)::uuid[] AS disabled_skill_ids
|
|
FROM organizations
|
|
LEFT JOIN organization_member_skill_settings s
|
|
ON s.organization_id = organizations.id AND s.user_id = @user_id::uuid
|
|
WHERE organizations.id = @organization_id::uuid;
|
|
|
|
-- name: UpsertOrganizationMemberSkillSettings :exec
|
|
INSERT INTO organization_member_skill_settings (organization_id, user_id, all_skills_disabled)
|
|
VALUES (@organization_id::uuid, @user_id::uuid, @all_skills_disabled::boolean)
|
|
ON CONFLICT (organization_id, user_id) DO UPDATE
|
|
SET all_skills_disabled = EXCLUDED.all_skills_disabled;
|
|
|
|
-- name: InsertOrganizationMemberDisabledSkill :exec
|
|
-- Stores nothing unless the skill belongs to the organization.
|
|
INSERT INTO organization_member_disabled_skills (organization_id, user_id, skill_id)
|
|
SELECT @organization_id::uuid, @user_id::uuid, skills.id
|
|
FROM skills
|
|
WHERE skills.id = @skill_id::uuid AND skills.organization_id = @organization_id::uuid
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
-- name: DeleteOrganizationMemberDisabledSkill :exec
|
|
DELETE FROM organization_member_disabled_skills
|
|
WHERE organization_id = @organization_id::uuid
|
|
AND user_id = @user_id::uuid
|
|
AND skill_id = @skill_id::uuid;
|