diff --git a/coderd/chatd/chatd.go b/coderd/chatd/chatd.go index f2a4db6ab9..7cf8ca1dfa 100644 --- a/coderd/chatd/chatd.go +++ b/coderd/chatd/chatd.go @@ -133,7 +133,6 @@ var ( type CreateOptions struct { OwnerID uuid.UUID WorkspaceID uuid.NullUUID - WorkspaceAgentID uuid.NullUUID ParentChatID uuid.NullUUID RootChatID uuid.NullUUID Title string @@ -212,7 +211,6 @@ func (p *Server) CreateChat(ctx context.Context, opts CreateOptions) (database.C insertedChat, err := tx.InsertChat(ctx, database.InsertChatParams{ OwnerID: opts.OwnerID, WorkspaceID: opts.WorkspaceID, - WorkspaceAgentID: opts.WorkspaceAgentID, ParentChatID: opts.ParentChatID, RootChatID: opts.RootChatID, LastModelConfigID: opts.ModelConfigID, @@ -1421,10 +1419,6 @@ func (p *Server) publishChatPubsubEvent(chat database.Chat, kind coderdpubsub.Ch if chat.WorkspaceID.Valid { sdkChat.WorkspaceID = &chat.WorkspaceID.UUID } - if chat.WorkspaceAgentID.Valid { - sdkChat.WorkspaceAgentID = &chat.WorkspaceAgentID.UUID - } - event := coderdpubsub.ChatEvent{ Kind: kind, Chat: sdkChat, @@ -1825,13 +1819,6 @@ func (p *Server) runChat( }() currentChat := chat - loadChatSnapshot := func( - loadCtx context.Context, - chatID uuid.UUID, - ) (database.Chat, error) { - //nolint:gocritic // System context required to load chat snapshots for the stream. - return p.db.GetChatByID(dbauthz.AsSystemRestricted(loadCtx), chatID) - } var ( chatStateMu sync.Mutex workspaceMu sync.Mutex @@ -1860,28 +1847,20 @@ func (p *Server) runChat( return nil, xerrors.New("workspace agent connector is not configured") } - if !chatSnapshot.WorkspaceAgentID.Valid { - refreshedChat, refreshErr := refreshChatWorkspaceSnapshot( - ctx, - chatSnapshot, - loadChatSnapshot, - ) - if refreshErr != nil { - return nil, refreshErr - } - if refreshedChat.WorkspaceAgentID.Valid { - chatStateMu.Lock() - currentChat = refreshedChat - chatSnapshot = refreshedChat - chatStateMu.Unlock() - } + if !chatSnapshot.WorkspaceID.Valid { + return nil, xerrors.New("chat has no workspace") } - if !chatSnapshot.WorkspaceAgentID.Valid { + //nolint:gocritic // System context needed to look up workspace agents. + agents, err := p.db.GetWorkspaceAgentsInLatestBuildByWorkspaceID( + dbauthz.AsSystemRestricted(ctx), + chatSnapshot.WorkspaceID.UUID, + ) + if err != nil || len(agents) == 0 { return nil, xerrors.New("chat has no workspace agent") } - agentConn, agentRelease, err := p.agentConnFn(ctx, chatSnapshot.WorkspaceAgentID.UUID) + agentConn, agentRelease, err := p.agentConnFn(ctx, agents[0].ID) if err != nil { return nil, xerrors.Errorf("connect to workspace agent: %w", err) } @@ -2376,23 +2355,6 @@ func usageNullInt64(value int64, valid bool) sql.NullInt64 { } } -func refreshChatWorkspaceSnapshot( - ctx context.Context, - chat database.Chat, - loadChat func(context.Context, uuid.UUID) (database.Chat, error), -) (database.Chat, error) { - if chat.WorkspaceAgentID.Valid || loadChat == nil { - return chat, nil - } - - refreshedChat, err := loadChat(ctx, chat.ID) - if err != nil { - return chat, xerrors.Errorf("reload chat workspace state: %w", err) - } - - return refreshedChat, nil -} - // resolveInstructions returns the combined system instructions for the // workspace agent. It reads the home-level (~/.coder/AGENTS.md) and // working-directory-level (/AGENTS.md) instruction files, combines @@ -2402,10 +2364,19 @@ func (p *Server) resolveInstructions( chat database.Chat, getWorkspaceConn func(context.Context) (workspacesdk.AgentConn, error), ) string { - if !chat.WorkspaceAgentID.Valid { + if !chat.WorkspaceID.Valid { return "" } - agentID := chat.WorkspaceAgentID.UUID + + //nolint:gocritic // System context needed to look up workspace agents. + agents, agentsErr := p.db.GetWorkspaceAgentsInLatestBuildByWorkspaceID( + dbauthz.AsSystemRestricted(ctx), + chat.WorkspaceID.UUID, + ) + if agentsErr != nil || len(agents) == 0 { + return "" + } + agentID := agents[0].ID p.instructionCacheMu.Lock() cached, ok := p.instructionCache[agentID] diff --git a/coderd/chatd/chattool/createworkspace.go b/coderd/chatd/chattool/createworkspace.go index d86d6cd49f..752aa22c19 100644 --- a/coderd/chatd/chattool/createworkspace.go +++ b/coderd/chatd/chattool/createworkspace.go @@ -191,10 +191,6 @@ func CreateWorkspace(options CreateWorkspaceOptions) fantasy.AgentTool { UUID: workspace.ID, Valid: true, }, - WorkspaceAgentID: uuid.NullUUID{ - UUID: workspaceAgentID, - Valid: workspaceAgentID != uuid.Nil, - }, }) } @@ -281,14 +277,15 @@ func checkExistingWorkspace( case database.ProvisionerJobStatusSucceeded: // Build succeeded — check if agent is reachable. - if chat.WorkspaceAgentID.Valid && agentConnFn != nil { + agents, agentsErr := db.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, ws.ID) + if agentsErr == nil && len(agents) > 0 && agentConnFn != nil { pingCtx, cancel := context.WithTimeout( ctx, agentPingTimeout, ) defer cancel() conn, release, connErr := agentConnFn( - pingCtx, chat.WorkspaceAgentID.UUID, + pingCtx, agents[0].ID, ) if connErr == nil { release() diff --git a/coderd/chatd/subagent.go b/coderd/chatd/subagent.go index bb41d1d47f..ad2991fd09 100644 --- a/coderd/chatd/subagent.go +++ b/coderd/chatd/subagent.go @@ -240,9 +240,8 @@ func (p *Server) createChildSubagentChat( } child, err := p.CreateChat(ctx, CreateOptions{ - OwnerID: parent.OwnerID, - WorkspaceID: parent.WorkspaceID, - WorkspaceAgentID: parent.WorkspaceAgentID, + OwnerID: parent.OwnerID, + WorkspaceID: parent.WorkspaceID, ParentChatID: uuid.NullUUID{ UUID: parent.ID, Valid: true, diff --git a/coderd/chats.go b/coderd/chats.go index c741300d63..1d176fce1e 100644 --- a/coderd/chats.go +++ b/coderd/chats.go @@ -258,7 +258,6 @@ func (api *API) postChats(rw http.ResponseWriter, r *http.Request) { chat, err := api.chatDaemon.CreateChat(ctx, chatd.CreateOptions{ OwnerID: apiKey.UserID, WorkspaceID: workspaceSelection.WorkspaceID, - WorkspaceAgentID: workspaceSelection.WorkspaceAgentID, Title: title, ModelConfigID: modelConfigID, SystemPrompt: defaultChatSystemPrompt(), @@ -1854,8 +1853,7 @@ func parseGitHubPullRequestURL(raw string) (githubPullRequestRef, bool) { } type createChatWorkspaceSelection struct { - WorkspaceID uuid.NullUUID - WorkspaceAgentID uuid.NullUUID + WorkspaceID uuid.NullUUID } func (api *API) validateCreateChatWorkspaceSelection( @@ -1888,23 +1886,6 @@ func (api *API) validateCreateChatWorkspaceSelection( Valid: true, } - workspaceAgents, err := api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID( - ctx, - workspace.ID, - ) - if err != nil { - return selection, http.StatusInternalServerError, &codersdk.Response{ - Message: "Failed to get workspace agents.", - Detail: err.Error(), - } - } - if len(workspaceAgents) > 0 { - selection.WorkspaceAgentID = uuid.NullUUID{ - UUID: workspaceAgents[0].ID, - Valid: true, - } - } - return selection, 0, nil } @@ -2081,9 +2062,6 @@ func convertChat(c database.Chat, diffStatus *database.ChatDiffStatus) codersdk. if c.WorkspaceID.Valid { chat.WorkspaceID = &c.WorkspaceID.UUID } - if c.WorkspaceAgentID.Valid { - chat.WorkspaceAgentID = &c.WorkspaceAgentID.UUID - } if diffStatus != nil { convertedDiffStatus := convertChatDiffStatus(c.ID, diffStatus) chat.DiffStatus = &convertedDiffStatus diff --git a/coderd/chats_test.go b/coderd/chats_test.go index 4ad12787ad..ffac2eb42e 100644 --- a/coderd/chats_test.go +++ b/coderd/chats_test.go @@ -77,7 +77,6 @@ func TestPostChats(t *testing.T) { require.NotZero(t, chat.CreatedAt) require.NotZero(t, chat.UpdatedAt) require.Nil(t, chat.WorkspaceID) - require.Nil(t, chat.WorkspaceAgentID) require.NotNil(t, chat.RootChatID) require.Equal(t, chat.ID, *chat.RootChatID) @@ -206,8 +205,6 @@ func TestPostChats(t *testing.T) { require.NoError(t, err) require.NotNil(t, chat.WorkspaceID) require.Equal(t, workspaceBuild.Workspace.ID, *chat.WorkspaceID) - require.NotNil(t, chat.WorkspaceAgentID) - require.Equal(t, workspaceBuild.Agents[0].ID, *chat.WorkspaceAgentID) require.Equal(t, modelConfig.ID, chat.LastModelConfigID) }) @@ -342,7 +339,6 @@ func TestListChats(t *testing.T) { require.NotZero(t, chat.UpdatedAt) require.Nil(t, chat.ParentChatID) require.Nil(t, chat.WorkspaceID) - require.Nil(t, chat.WorkspaceAgentID) require.NotNil(t, chat.RootChatID) require.Equal(t, chat.ID, *chat.RootChatID) require.NotNil(t, chat.DiffStatus) diff --git a/coderd/database/dbauthz/dbauthz_test.go b/coderd/database/dbauthz/dbauthz_test.go index 8e8bd0d2fe..78a3ae008c 100644 --- a/coderd/database/dbauthz/dbauthz_test.go +++ b/coderd/database/dbauthz/dbauthz_test.go @@ -694,9 +694,8 @@ func (s *MethodTestSuite) TestChats() { s.Run("UpdateChatWorkspace", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { chat := testutil.Fake(s.T(), faker, database.Chat{}) arg := database.UpdateChatWorkspaceParams{ - ID: chat.ID, - WorkspaceID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, - WorkspaceAgentID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, + ID: chat.ID, + WorkspaceID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, } updatedChat := testutil.Fake(s.T(), faker, database.Chat{ID: chat.ID}) dbm.EXPECT().GetChatByID(gomock.Any(), chat.ID).Return(chat, nil).AnyTimes() diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 2a9802b253..b90da8adbf 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -1263,7 +1263,6 @@ CREATE TABLE chats ( id uuid DEFAULT gen_random_uuid() NOT NULL, owner_id uuid NOT NULL, workspace_id uuid, - workspace_agent_id uuid, title text DEFAULT 'New Chat'::text NOT NULL, status chat_status DEFAULT 'waiting'::chat_status NOT NULL, worker_id uuid, @@ -3790,9 +3789,6 @@ ALTER TABLE ONLY chats ALTER TABLE ONLY chats ADD CONSTRAINT chats_root_chat_id_fkey FOREIGN KEY (root_chat_id) REFERENCES chats(id) ON DELETE SET NULL; -ALTER TABLE ONLY chats - ADD CONSTRAINT chats_workspace_agent_id_fkey FOREIGN KEY (workspace_agent_id) REFERENCES workspace_agents(id) ON DELETE SET NULL; - ALTER TABLE ONLY chats ADD CONSTRAINT chats_workspace_id_fkey FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE SET NULL; diff --git a/coderd/database/foreign_key_constraint.go b/coderd/database/foreign_key_constraint.go index fa712737e4..8c8797c2a8 100644 --- a/coderd/database/foreign_key_constraint.go +++ b/coderd/database/foreign_key_constraint.go @@ -21,7 +21,6 @@ const ( ForeignKeyChatsOwnerID ForeignKeyConstraint = "chats_owner_id_fkey" // ALTER TABLE ONLY chats ADD CONSTRAINT chats_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE; ForeignKeyChatsParentChatID ForeignKeyConstraint = "chats_parent_chat_id_fkey" // ALTER TABLE ONLY chats ADD CONSTRAINT chats_parent_chat_id_fkey FOREIGN KEY (parent_chat_id) REFERENCES chats(id) ON DELETE SET NULL; ForeignKeyChatsRootChatID ForeignKeyConstraint = "chats_root_chat_id_fkey" // ALTER TABLE ONLY chats ADD CONSTRAINT chats_root_chat_id_fkey FOREIGN KEY (root_chat_id) REFERENCES chats(id) ON DELETE SET NULL; - ForeignKeyChatsWorkspaceAgentID ForeignKeyConstraint = "chats_workspace_agent_id_fkey" // ALTER TABLE ONLY chats ADD CONSTRAINT chats_workspace_agent_id_fkey FOREIGN KEY (workspace_agent_id) REFERENCES workspace_agents(id) ON DELETE SET NULL; ForeignKeyChatsWorkspaceID ForeignKeyConstraint = "chats_workspace_id_fkey" // ALTER TABLE ONLY chats ADD CONSTRAINT chats_workspace_id_fkey FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE SET NULL; ForeignKeyConnectionLogsOrganizationID ForeignKeyConstraint = "connection_logs_organization_id_fkey" // ALTER TABLE ONLY connection_logs ADD CONSTRAINT connection_logs_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE; ForeignKeyConnectionLogsWorkspaceID ForeignKeyConstraint = "connection_logs_workspace_id_fkey" // ALTER TABLE ONLY connection_logs ADD CONSTRAINT connection_logs_workspace_id_fkey FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE; diff --git a/coderd/database/migrations/000425_remove_chat_workspace_agent_id.down.sql b/coderd/database/migrations/000425_remove_chat_workspace_agent_id.down.sql new file mode 100644 index 0000000000..3c0c556256 --- /dev/null +++ b/coderd/database/migrations/000425_remove_chat_workspace_agent_id.down.sql @@ -0,0 +1 @@ +ALTER TABLE chats ADD COLUMN workspace_agent_id UUID REFERENCES workspace_agents(id) ON DELETE SET NULL; diff --git a/coderd/database/migrations/000425_remove_chat_workspace_agent_id.up.sql b/coderd/database/migrations/000425_remove_chat_workspace_agent_id.up.sql new file mode 100644 index 0000000000..3134dcd071 --- /dev/null +++ b/coderd/database/migrations/000425_remove_chat_workspace_agent_id.up.sql @@ -0,0 +1 @@ +ALTER TABLE chats DROP COLUMN workspace_agent_id; diff --git a/coderd/database/models.go b/coderd/database/models.go index 45db1db2ab..f51f61d329 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -3889,7 +3889,6 @@ type Chat struct { ID uuid.UUID `db:"id" json:"id"` OwnerID uuid.UUID `db:"owner_id" json:"owner_id"` WorkspaceID uuid.NullUUID `db:"workspace_id" json:"workspace_id"` - WorkspaceAgentID uuid.NullUUID `db:"workspace_agent_id" json:"workspace_agent_id"` Title string `db:"title" json:"title"` Status ChatStatus `db:"status" json:"status"` WorkerID uuid.NullUUID `db:"worker_id" json:"worker_id"` diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 15c37c8391..f43d198ffb 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -2842,7 +2842,7 @@ WHERE 1 ) RETURNING - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error ` type AcquireChatParams struct { @@ -2859,7 +2859,6 @@ func (q *sqlQuerier) AcquireChat(ctx context.Context, arg AcquireChatParams) (Ch &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -2940,7 +2939,7 @@ func (q *sqlQuerier) DeleteChatQueuedMessage(ctx context.Context, arg DeleteChat const getChatByID = `-- name: GetChatByID :one SELECT - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE @@ -2954,7 +2953,6 @@ func (q *sqlQuerier) GetChatByID(ctx context.Context, id uuid.UUID) (Chat, error &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -2972,7 +2970,7 @@ func (q *sqlQuerier) GetChatByID(ctx context.Context, id uuid.UUID) (Chat, error } const getChatByIDForUpdate = `-- name: GetChatByIDForUpdate :one -SELECT id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE id = $1::uuid FOR UPDATE +SELECT id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE id = $1::uuid FOR UPDATE ` func (q *sqlQuerier) GetChatByIDForUpdate(ctx context.Context, id uuid.UUID) (Chat, error) { @@ -2982,7 +2980,6 @@ func (q *sqlQuerier) GetChatByIDForUpdate(ctx context.Context, id uuid.UUID) (Ch &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3291,7 +3288,7 @@ func (q *sqlQuerier) GetChatQueuedMessages(ctx context.Context, chatID uuid.UUID const getChatsByOwnerID = `-- name: GetChatsByOwnerID :many SELECT - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE @@ -3314,7 +3311,6 @@ func (q *sqlQuerier) GetChatsByOwnerID(ctx context.Context, ownerID uuid.UUID) ( &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3343,7 +3339,7 @@ func (q *sqlQuerier) GetChatsByOwnerID(ctx context.Context, ownerID uuid.UUID) ( const getStaleChats = `-- name: GetStaleChats :many SELECT - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE @@ -3366,7 +3362,6 @@ func (q *sqlQuerier) GetStaleChats(ctx context.Context, staleThreshold time.Time &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3397,7 +3392,6 @@ const insertChat = `-- name: InsertChat :one INSERT INTO chats ( owner_id, workspace_id, - workspace_agent_id, parent_chat_id, root_chat_id, last_model_config_id, @@ -3408,17 +3402,15 @@ INSERT INTO chats ( $3::uuid, $4::uuid, $5::uuid, - $6::uuid, - $7::text + $6::text ) RETURNING - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error ` type InsertChatParams struct { OwnerID uuid.UUID `db:"owner_id" json:"owner_id"` WorkspaceID uuid.NullUUID `db:"workspace_id" json:"workspace_id"` - WorkspaceAgentID uuid.NullUUID `db:"workspace_agent_id" json:"workspace_agent_id"` ParentChatID uuid.NullUUID `db:"parent_chat_id" json:"parent_chat_id"` RootChatID uuid.NullUUID `db:"root_chat_id" json:"root_chat_id"` LastModelConfigID uuid.UUID `db:"last_model_config_id" json:"last_model_config_id"` @@ -3429,7 +3421,6 @@ func (q *sqlQuerier) InsertChat(ctx context.Context, arg InsertChatParams) (Chat row := q.db.QueryRowContext(ctx, insertChat, arg.OwnerID, arg.WorkspaceID, - arg.WorkspaceAgentID, arg.ParentChatID, arg.RootChatID, arg.LastModelConfigID, @@ -3440,7 +3431,6 @@ func (q *sqlQuerier) InsertChat(ctx context.Context, arg InsertChatParams) (Chat &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3578,7 +3568,7 @@ func (q *sqlQuerier) InsertChatQueuedMessage(ctx context.Context, arg InsertChat const listChatsByRootID = `-- name: ListChatsByRootID :many SELECT - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE @@ -3600,7 +3590,6 @@ func (q *sqlQuerier) ListChatsByRootID(ctx context.Context, rootChatID uuid.UUID &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3629,7 +3618,7 @@ func (q *sqlQuerier) ListChatsByRootID(ctx context.Context, rootChatID uuid.UUID const listChildChatsByParentID = `-- name: ListChildChatsByParentID :many SELECT - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error FROM chats WHERE @@ -3651,7 +3640,6 @@ func (q *sqlQuerier) ListChildChatsByParentID(ctx context.Context, parentChatID &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3719,7 +3707,7 @@ SET WHERE id = $2::uuid RETURNING - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error ` type UpdateChatByIDParams struct { @@ -3734,7 +3722,6 @@ func (q *sqlQuerier) UpdateChatByID(ctx context.Context, arg UpdateChatByIDParam &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3831,7 +3818,7 @@ SET WHERE id = $6::uuid RETURNING - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error ` type UpdateChatStatusParams struct { @@ -3857,7 +3844,6 @@ func (q *sqlQuerier) UpdateChatStatus(ctx context.Context, arg UpdateChatStatusP &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, @@ -3879,28 +3865,25 @@ UPDATE chats SET workspace_id = $1::uuid, - workspace_agent_id = $2::uuid, updated_at = NOW() WHERE - id = $3::uuid + id = $2::uuid RETURNING - id, owner_id, workspace_id, workspace_agent_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error + id, owner_id, workspace_id, title, status, worker_id, started_at, heartbeat_at, created_at, updated_at, parent_chat_id, root_chat_id, last_model_config_id, archived, last_error ` type UpdateChatWorkspaceParams struct { - WorkspaceID uuid.NullUUID `db:"workspace_id" json:"workspace_id"` - WorkspaceAgentID uuid.NullUUID `db:"workspace_agent_id" json:"workspace_agent_id"` - ID uuid.UUID `db:"id" json:"id"` + WorkspaceID uuid.NullUUID `db:"workspace_id" json:"workspace_id"` + ID uuid.UUID `db:"id" json:"id"` } func (q *sqlQuerier) UpdateChatWorkspace(ctx context.Context, arg UpdateChatWorkspaceParams) (Chat, error) { - row := q.db.QueryRowContext(ctx, updateChatWorkspace, arg.WorkspaceID, arg.WorkspaceAgentID, arg.ID) + row := q.db.QueryRowContext(ctx, updateChatWorkspace, arg.WorkspaceID, arg.ID) var i Chat err := row.Scan( &i.ID, &i.OwnerID, &i.WorkspaceID, - &i.WorkspaceAgentID, &i.Title, &i.Status, &i.WorkerID, diff --git a/coderd/database/queries/chats.sql b/coderd/database/queries/chats.sql index ce1cc12db0..26a4b5aff5 100644 --- a/coderd/database/queries/chats.sql +++ b/coderd/database/queries/chats.sql @@ -136,7 +136,6 @@ ORDER BY INSERT INTO chats ( owner_id, workspace_id, - workspace_agent_id, parent_chat_id, root_chat_id, last_model_config_id, @@ -144,7 +143,6 @@ INSERT INTO chats ( ) VALUES ( @owner_id::uuid, sqlc.narg('workspace_id')::uuid, - sqlc.narg('workspace_agent_id')::uuid, sqlc.narg('parent_chat_id')::uuid, sqlc.narg('root_chat_id')::uuid, @last_model_config_id::uuid, @@ -222,7 +220,6 @@ UPDATE chats SET workspace_id = sqlc.narg('workspace_id')::uuid, - workspace_agent_id = sqlc.narg('workspace_agent_id')::uuid, updated_at = NOW() WHERE id = @id::uuid diff --git a/coderd/httpmw/chatparam_test.go b/coderd/httpmw/chatparam_test.go index 10bc8e5844..3eb0e6bf7e 100644 --- a/coderd/httpmw/chatparam_test.go +++ b/coderd/httpmw/chatparam_test.go @@ -64,7 +64,6 @@ func TestChatParam(t *testing.T) { chat, err := db.InsertChat(context.Background(), database.InsertChatParams{ OwnerID: ownerID, WorkspaceID: uuid.NullUUID{}, - WorkspaceAgentID: uuid.NullUUID{}, ParentChatID: uuid.NullUUID{}, RootChatID: uuid.NullUUID{}, LastModelConfigID: modelConfig.ID, diff --git a/codersdk/chats.go b/codersdk/chats.go index e6a141b8d8..c3edeed6c1 100644 --- a/codersdk/chats.go +++ b/codersdk/chats.go @@ -32,7 +32,6 @@ type Chat struct { ID uuid.UUID `json:"id" format:"uuid"` OwnerID uuid.UUID `json:"owner_id" format:"uuid"` WorkspaceID *uuid.UUID `json:"workspace_id,omitempty" format:"uuid"` - WorkspaceAgentID *uuid.UUID `json:"workspace_agent_id,omitempty" format:"uuid"` ParentChatID *uuid.UUID `json:"parent_chat_id,omitempty" format:"uuid"` RootChatID *uuid.UUID `json:"root_chat_id,omitempty" format:"uuid"` LastModelConfigID uuid.UUID `json:"last_model_config_id" format:"uuid"` diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index d881a91a8f..894bacf359 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1054,7 +1054,6 @@ export interface Chat { readonly id: string; readonly owner_id: string; readonly workspace_id?: string; - readonly workspace_agent_id?: string; readonly parent_chat_id?: string; readonly root_chat_id?: string; readonly last_model_config_id: string; diff --git a/site/src/pages/AgentsPage/AgentDetail.stories.tsx b/site/src/pages/AgentsPage/AgentDetail.stories.tsx index dfe5bf96b1..16b68563dc 100644 --- a/site/src/pages/AgentsPage/AgentDetail.stories.tsx +++ b/site/src/pages/AgentsPage/AgentDetail.stories.tsx @@ -117,7 +117,6 @@ const mockModelCatalog: TypesGen.ChatModelsResponse = { const baseChatFields = { owner_id: "owner-id", workspace_id: mockWorkspace.id, - workspace_agent_id: mockWorkspaceAgent.id, last_model_config_id: "model-config-1", created_at: "2026-02-18T00:00:00.000Z", updated_at: "2026-02-18T00:00:00.000Z", diff --git a/site/src/pages/AgentsPage/AgentDetail.tsx b/site/src/pages/AgentsPage/AgentDetail.tsx index 5d8801bf12..dcdb3e47aa 100644 --- a/site/src/pages/AgentsPage/AgentDetail.tsx +++ b/site/src/pages/AgentsPage/AgentDetail.tsx @@ -494,7 +494,6 @@ const AgentDetail: FC = () => { }); const chatsQuery = useQuery(chats()); const workspaceId = chatQuery.data?.chat?.workspace_id; - const workspaceAgentId = chatQuery.data?.chat?.workspace_agent_id; const workspaceQuery = useQuery({ ...workspaceById(workspaceId ?? ""), enabled: Boolean(workspaceId), @@ -507,7 +506,7 @@ const AgentDetail: FC = () => { const chatModelConfigsQuery = useQuery(chatModelConfigs()); const hasDiffStatus = Boolean(diffStatusQuery.data?.url); const workspace = workspaceQuery.data; - const workspaceAgent = getWorkspaceAgent(workspace, workspaceAgentId); + const workspaceAgent = getWorkspaceAgent(workspace, undefined); const chatData = chatQuery.data; const chatRecord = chatData?.chat; const chatMessages = chatData?.messages;