Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fa60a15
feat: add the Agents automations list page and chat-list automation f…
ThomasK33 Sep 30, 2026
c05cb0e
test(site/src/pages/AgentsPage): cover switching the automations org …
ThomasK33 Sep 30, 2026
f106110
fix: address list page UAT findings
ThomasK33 Sep 30, 2026
cbea559
fix(site/src): address frontend self-review findings
ThomasK33 Sep 30, 2026
8f2ee30
chore(site/src/pages/AgentsPage): drop a comment about the stored org…
ThomasK33 Sep 30, 2026
3acd9c0
Merge remote-tracking branch 'origin/tk/codagt-1215-automations-chat-…
ThomasK33 Sep 30, 2026
0fefb2a
fix: address Codex review round 1 on the automations list
ThomasK33 Sep 30, 2026
e5962d6
chore(site/src/api/queries): drop a comment on the chat list invalida…
ThomasK33 Sep 30, 2026
43fa1a5
Merge remote-tracking branch 'origin/tk/codagt-1215-automations-chat-…
ThomasK33 Sep 30, 2026
a307cbc
fix(site/src/pages/AgentsPage): address Codex review round 2
ThomasK33 Sep 30, 2026
b37e9d9
fix(site/src/pages/AgentsPage): address Codex review round 3
ThomasK33 Sep 30, 2026
ff3ae79
Merge tk/codagt-1215-automations-chat-labels (main d9c13dc06d) into t…
ThomasK33 Oct 1, 2026
529ba91
Merge tk/codagt-1215-automations-chat-labels (main 35abc22fa9) into t…
ThomasK33 Oct 1, 2026
eff3f06
fix(site/src/pages/AgentsPage): address review on the automations lis…
ThomasK33 Oct 1, 2026
d3cfdd9
Merge tk/codagt-1215-automations-chat-labels into tk/codagt-1213-auto…
ThomasK33 Oct 1, 2026
46b879b
Merge tk/codagt-1215-automations-chat-labels (main 35abc22fa9) into t…
ThomasK33 Oct 1, 2026
ddf7ab2
Merge tk/codagt-1215-automations-chat-labels (main d11809f095) into t…
ThomasK33 Oct 1, 2026
89fa9dc
Merge tk/codagt-1215-automations-chat-labels (main a328bee007) into t…
ThomasK33 Oct 1, 2026
e95b284
Merge tk/codagt-1215-automations-chat-labels (main 15382ebd5d) into t…
ThomasK33 Oct 2, 2026
991f969
Merge tk/codagt-1215-automations-chat-labels (main dc07908504) into t…
ThomasK33 Oct 2, 2026
356447f
fix: include archived chats in automation chat history
ThomasK33 Oct 2, 2026
1b6d9ff
fix(site/src/pages/AgentsPage): restore chats dialog focus and apply …
ThomasK33 Oct 2, 2026
5f9cdb3
docs(docs/ai-coder/agents): document archived:any in chat search syntax
ThomasK33 Oct 2, 2026
fe4cf27
refactor(site/src/pages/AgentsPage): tidy the automations flag doc an…
ThomasK33 Oct 2, 2026
4b2a0af
Merge tk/codagt-1215-automations-chat-labels (main dc07908504) into t…
ThomasK33 Oct 2, 2026
2b91eb8
fix(site/src/pages/AgentsPage): show used single-use webhooks as off
ThomasK33 Oct 2, 2026
52959fb
test(site/src/pages/AgentsPage): check a used webhook's switch sends …
ThomasK33 Oct 2, 2026
9b89634
Merge tk/codagt-1215-automations-chat-labels into tk/codagt-1213-auto…
ThomasK33 Oct 2, 2026
c84c1bb
Merge tk/codagt-1215-automations-chat-labels into tk/codagt-1213-auto…
ThomasK33 Oct 2, 2026
59cb625
Merge tk/codagt-1215-automations-chat-labels into tk/codagt-1213-auto…
ThomasK33 Oct 2, 2026
29a4d1c
Merge tk/codagt-1215-automations-chat-labels into tk/codagt-1213-auto…
ThomasK33 Oct 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ func (q *sqlQuerier) GetAuthorizedChats(ctx context.Context, arg GetChatsParams,
arg.RepoQuery,
arg.PrTitleQuery,
arg.Search,
arg.AutomationID,
arg.OffsetOpt,
arg.LimitOpt,
)
Expand Down
21 changes: 19 additions & 2 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions coderd/database/queries/chats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,21 @@ WHERE
)
ELSE true
END
-- Filter to chats an automation created or sent messages to. Served
-- by chats_automation_idx and chat_messages_automation_idx.
AND CASE
WHEN @automation_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN (
chats_expanded.automation_id = @automation_id::uuid
OR EXISTS (
SELECT 1
FROM chat_messages cm
WHERE cm.chat_id = chats_expanded.id
AND cm.automation_id = @automation_id::uuid
AND cm.deleted = false
)
)
ELSE true
END
-- Paginate over root chats only. Children are fetched
-- separately via GetChildChatsByParentIDs and embedded under
-- each parent. Other callers that need the full set should
Expand Down
28 changes: 27 additions & 1 deletion coderd/exp_chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,12 @@ func (api *API) chatsByWorkspace(rw http.ResponseWriter, r *http.Request) {
// @Security CoderSessionToken
// @Tags Chats
// @Produce json
// @Param q query string false "Search query. Supports `title:<substring>` (case-insensitive, quote multi-word values), `archived:bool`, `has_unread:bool`, `status:<waiting\|running\|error\|requires_action\|interrupting>` (chat status, repeated or comma-separated), `pr_status:<draft\|open\|merged\|closed\|none>` (none matches chats with no pull request) as repeated or comma-separated values, `source:<created_by_me\|shared_with_me>`, `diff_url:<url>` (quote values containing colons), `pr:<number>` (exact PR number match), `repo:<owner/repo>` (case-insensitive substring match against git remote origin or URL), `pr_title:<text>` (case-insensitive PR title substring), `search:<text>` (full-text search across chat titles, PR titles, PR numbers, and message bodies; message bodies match English word stems, e.g. `refactor` matches `refactoring`, and ignore English stopwords; titles and PR titles match whole words case-insensitively without stemming; quote multi-word values; cannot be combined with title, pr_title, or pr; a value that tokenizes to no searchable words, e.g. punctuation only, returns an empty list). Bare terms are not supported; use `title:<value>` or `search:<value>`."
// @Param q query string false "Search query. Supports `title:<substring>` (case-insensitive, quote multi-word values), `archived:bool` (`archived:any` matches archived and active chats), `has_unread:bool`, `status:<waiting\|running\|error\|requires_action\|interrupting>` (chat status, repeated or comma-separated), `pr_status:<draft\|open\|merged\|closed\|none>` (none matches chats with no pull request) as repeated or comma-separated values, `source:<created_by_me\|shared_with_me>`, `diff_url:<url>` (quote values containing colons), `pr:<number>` (exact PR number match), `repo:<owner/repo>` (case-insensitive substring match against git remote origin or URL), `pr_title:<text>` (case-insensitive PR title substring), `search:<text>` (full-text search across chat titles, PR titles, PR numbers, and message bodies; message bodies match English word stems, e.g. `refactor` matches `refactoring`, and ignore English stopwords; titles and PR titles match whole words case-insensitively without stemming; quote multi-word values; cannot be combined with title, pr_title, or pr; a value that tokenizes to no searchable words, e.g. punctuation only, returns an empty list). Bare terms are not supported; use `title:<value>` or `search:<value>`."
// @Param label query []string false "Filter by label as key:value. Repeat for multiple (AND logic)." collectionFormat(multi)
// @Param after_id query string false "After ID" format(uuid)
// @Param limit query int false "Page limit"
// @Param offset query int false "Page offset"
// @Param automation_id query string false "Filter to chats the automation created or sent messages to. Ignored unless the chat-automations experiment is enabled for the caller." format(uuid)
// @Param project_id query string false "Only chats in this project. Requires the chat-projects experiment." format(uuid)
// @Success 200 {array} codersdk.Chat
// @Router /api/v2/chats [get]
Expand Down Expand Up @@ -467,6 +468,30 @@ func (api *API) listChats(rw http.ResponseWriter, r *http.Request) {
}
}

// The chat list is not experiment-gated, so the automation filter is
// ignored, not rejected, when the experiment is off for the caller.
// The evaluator reads the database, so it runs only when the filter
// is requested.
automationID := uuid.Nil
if r.URL.Query().Has("automation_id") && chatd.AutomationsEnabled(ctx, api.ExperimentEvaluator, apiKey.UserID) {
parser := httpapi.NewQueryParamParser()
automationID = parser.UUID(r.URL.Query(), uuid.Nil, "automation_id")
Comment thread
ThomasK33 marked this conversation as resolved.
Resolved
// The query treats the nil UUID as "no filter".
if len(parser.Errors) == 0 && automationID == uuid.Nil {
parser.Errors = append(parser.Errors, codersdk.ValidationError{
Field: "automation_id",
Detail: "Query param \"automation_id\" must not be the nil UUID.",
})
}
if len(parser.Errors) > 0 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Query parameters have invalid values.",
Validations: parser.Errors,
})
return
}
}

var sharedWithGroupIDs []string
if searchParams.SharedOnly {
groups, err := api.Database.GetGroups(ctx, database.GetGroupsParams{HasMemberID: apiKey.UserID})
Expand Down Expand Up @@ -517,6 +542,7 @@ func (api *API) listChats(rw http.ResponseWriter, r *http.Request) {
RepoQuery: searchParams.RepoQuery,
PrTitleQuery: searchParams.PrTitleQuery,
Search: searchParams.Search,
AutomationID: automationID,
ProjectID: projectID,
// #nosec G115 - Pagination offsets are small and fit in int32
OffsetOpt: int32(paginationParams.Offset),
Expand Down
89 changes: 89 additions & 0 deletions coderd/exp_chats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,95 @@ func TestListChats(t *testing.T) {
require.Equal(t, archivedWithPR.ID, chats[0].ID)
})
})

t.Run("AutomationFilter", func(t *testing.T) {
t.Parallel()

env := newChatAutomationTestEnv(t, nil, nil)
ctx := testutil.Context(t, testutil.WaitLong)
automationID := uuid.New()
markCreatedBy := func(chat database.Chat) {
t.Helper()
rows, err := env.db.UpdateChatAutomationIDByID(dbauthz.AsSystemRestricted(ctx), database.UpdateChatAutomationIDByIDParams{
ID: chat.ID,
AutomationID: automationID,
})
require.NoError(t, err)
require.EqualValues(t, 1, rows)
}
newMemberChat := func() database.Chat {
return dbgen.Chat(t, env.db, database.Chat{
OrganizationID: env.orgID,
OwnerID: env.memberID,
LastModelConfigID: env.modelConfig.ID,
})
}

created := newMemberChat()
markCreatedBy(created)
// Archived chats stay in the automation's history when the
// caller asks for archived:any.
archivedCreated := newMemberChat()
markCreatedBy(archivedCreated)
require.NoError(t, env.member.UpdateChat(ctx, archivedCreated.ID, codersdk.UpdateChatRequest{Archived: ptr.Ref(true)}))
// The automation only sent a message to this existing chat.
writtenTo := env.memberChat
dbgen.ChatMessage(t, env.db, database.ChatMessage{
ChatID: writtenTo.ID,
AutomationID: uuid.NullUUID{UUID: automationID, Valid: true},
})
unrelated := newMemberChat()
// A deleted automation message no longer counts as writing to
// the chat.
deletedMessageChat := newMemberChat()
deletedMessage := dbgen.ChatMessage(t, env.db, database.ChatMessage{
ChatID: deletedMessageChat.ID,
AutomationID: uuid.NullUUID{UUID: automationID, Valid: true},
})
require.NoError(t, env.db.SoftDeleteChatMessageByID(dbauthz.AsSystemRestricted(ctx), deletedMessage.ID))
// Another user's chat that the member may not read.
owner, err := env.owner.User(ctx, codersdk.Me)
require.NoError(t, err)
markCreatedBy(dbgen.Chat(t, env.db, database.Chat{
OrganizationID: env.orgID,
OwnerID: owner.ID,
LastModelConfigID: env.modelConfig.ID,
}))

chatIDs := func(opts *codersdk.ListChatsOptions) []uuid.UUID {
t.Helper()
chats, err := env.member.ListChats(ctx, opts)
require.NoError(t, err)
ids := make([]uuid.UUID, 0, len(chats))
for _, chat := range chats {
ids = append(ids, chat.ID)
}
return ids
}

require.ElementsMatch(t, []uuid.UUID{created.ID, writtenTo.ID}, chatIDs(&codersdk.ListChatsOptions{AutomationID: automationID}))
require.ElementsMatch(t, []uuid.UUID{created.ID, archivedCreated.ID, writtenTo.ID}, chatIDs(&codersdk.ListChatsOptions{AutomationID: automationID, Query: "archived:any"}))
require.Equal(t, []uuid.UUID{archivedCreated.ID}, chatIDs(&codersdk.ListChatsOptions{AutomationID: automationID, Query: "archived:true"}))
require.Empty(t, chatIDs(&codersdk.ListChatsOptions{AutomationID: uuid.New()}))

for _, value := range []string{"not-a-uuid", uuid.Nil.String()} {
status, body := rawGet(t, env.member, "/api/v2/chats?automation_id="+value)
require.Equal(t, http.StatusBadRequest, status, body)
require.Contains(t, body, "automation_id")
}

// With the experiment off for the member, the filter is ignored.
member, err := env.member.User(ctx, codersdk.Me)
require.NoError(t, err)
_, err = env.owner.PutExperimentRule(ctx, codersdk.ExperimentChatAutomations, codersdk.PutExperimentRuleRequest{
Mode: codersdk.ExperimentRuleModeCondition,
Condition: fmt.Sprintf("user.username != %q", member.Username),
})
require.NoError(t, err)
require.ElementsMatch(t, []uuid.UUID{created.ID, writtenTo.ID, unrelated.ID, deletedMessageChat.ID}, chatIDs(&codersdk.ListChatsOptions{AutomationID: automationID}))
status, body := rawGet(t, env.member, "/api/v2/chats?automation_id=not-a-uuid")
require.Equal(t, http.StatusOK, status, body)
})
}

func TestListChatModels(t *testing.T) {
Expand Down
Loading
Loading