mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
edee917d88
feat: add AI chat system with agent tools and chat UI Introduce the chatd subsystem and Agents UI for AI-powered chat within Coder workspaces. - Add chatd package with chat loop, message compaction, prompt management, and LLM provider integration (OpenAI, Anthropic) - Add agent tools: create workspace, list/read templates, read/write/ edit files, execute commands - Add chat API endpoints with streaming, message editing, and durable reconnection - Add database schema and migrations for chats, chat messages, chat providers, and chat model configs - Add RBAC policies and dbauthz enforcement for chat resources - Add Agents UI pages with conversation timeline, queued messages list, diff viewer, and model configuration panel - Add comprehensive test coverage including coderd integration tests, chatd unit tests, and Storybook stories - Gate feature behind experiments flag --------- Co-authored-by: Cian Johnston <cian@coder.com> Co-authored-by: Danielle Maywood <danielle@themaywoods.com> Co-authored-by: Jeremy Ruppel <jeremy@coder.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
130 lines
2.4 KiB
SQL
130 lines
2.4 KiB
SQL
-- name: GetChatModelConfigByID :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
chat_model_configs
|
|
WHERE
|
|
id = @id::uuid
|
|
AND deleted = FALSE;
|
|
|
|
-- name: GetDefaultChatModelConfig :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
chat_model_configs
|
|
WHERE
|
|
is_default = TRUE
|
|
AND deleted = FALSE;
|
|
|
|
-- name: GetChatModelConfigByProviderAndModel :one
|
|
SELECT
|
|
*
|
|
FROM
|
|
chat_model_configs
|
|
WHERE
|
|
provider = @provider::text
|
|
AND model = @model::text
|
|
AND deleted = FALSE
|
|
ORDER BY
|
|
updated_at DESC,
|
|
created_at DESC,
|
|
id DESC
|
|
LIMIT 1;
|
|
|
|
-- name: GetChatModelConfigs :many
|
|
SELECT
|
|
*
|
|
FROM
|
|
chat_model_configs
|
|
WHERE
|
|
deleted = FALSE
|
|
ORDER BY
|
|
provider ASC,
|
|
model ASC,
|
|
updated_at DESC,
|
|
id DESC;
|
|
|
|
-- name: GetEnabledChatModelConfigs :many
|
|
SELECT
|
|
cmc.*
|
|
FROM
|
|
chat_model_configs cmc
|
|
JOIN
|
|
chat_providers cp ON cp.provider = cmc.provider
|
|
WHERE
|
|
cmc.enabled = TRUE
|
|
AND cmc.deleted = FALSE
|
|
AND cp.enabled = TRUE
|
|
ORDER BY
|
|
cmc.provider ASC,
|
|
cmc.model ASC,
|
|
cmc.updated_at DESC,
|
|
cmc.id DESC;
|
|
|
|
-- name: InsertChatModelConfig :one
|
|
INSERT INTO chat_model_configs (
|
|
provider,
|
|
model,
|
|
display_name,
|
|
created_by,
|
|
updated_by,
|
|
enabled,
|
|
is_default,
|
|
context_limit,
|
|
compression_threshold,
|
|
options
|
|
) VALUES (
|
|
@provider::text,
|
|
@model::text,
|
|
@display_name::text,
|
|
sqlc.narg('created_by')::uuid,
|
|
sqlc.narg('updated_by')::uuid,
|
|
@enabled::boolean,
|
|
@is_default::boolean,
|
|
@context_limit::bigint,
|
|
@compression_threshold::integer,
|
|
@options::jsonb
|
|
)
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: UpdateChatModelConfig :one
|
|
UPDATE
|
|
chat_model_configs
|
|
SET
|
|
provider = @provider::text,
|
|
model = @model::text,
|
|
display_name = @display_name::text,
|
|
updated_by = sqlc.narg('updated_by')::uuid,
|
|
enabled = @enabled::boolean,
|
|
is_default = @is_default::boolean,
|
|
context_limit = @context_limit::bigint,
|
|
compression_threshold = @compression_threshold::integer,
|
|
options = @options::jsonb,
|
|
updated_at = NOW()
|
|
WHERE
|
|
id = @id::uuid
|
|
AND deleted = FALSE
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: UnsetDefaultChatModelConfigs :exec
|
|
UPDATE
|
|
chat_model_configs
|
|
SET
|
|
is_default = FALSE,
|
|
updated_at = NOW()
|
|
WHERE
|
|
is_default = TRUE
|
|
AND deleted = FALSE;
|
|
|
|
-- name: DeleteChatModelConfigByID :exec
|
|
UPDATE
|
|
chat_model_configs
|
|
SET
|
|
deleted = TRUE,
|
|
deleted_at = NOW(),
|
|
updated_at = NOW()
|
|
WHERE
|
|
id = @id::uuid;
|