Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 81 additions & 3 deletions coderd/apidoc/docs.go

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

80 changes: 77 additions & 3 deletions 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/chat_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (api *API) registerOrganizationChatRoutes(r chi.Router, prefix chatAPIPrefi
r.Get("/", api.getOrganizationChatModelOverrides)
r.Put("/{context}", api.putOrganizationChatModelOverride)
})
r.Get("/chats/tree", api.getChatTree)
r.Route("/chats/models", func(r chi.Router) {
r.Get("/", api.listChatModelConfigsByOrganization)
r.Post("/", api.createChatModelConfig)
Expand Down
25 changes: 25 additions & 0 deletions coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,31 @@ func ChatRowsWithChildren(
return result
}

// SetChatTreePosition records a chat's depth in its tree and its direct
// chat kind child count. A depth of 0 means the chat is not attached to
// a tree root and leaves both fields unset.
func SetChatTreePosition(chat *codersdk.Chat, depth int32, childChatCount int64) {
if depth <= 0 {
return
}
d := int(depth)
c := int(childChatCount)
chat.Depth = &d
chat.ChildChatCount = &c
}

// ChatTreeRows converts tree rows into codersdk.Chat values with Depth and
// ChildChatCount set. Rows outside the tree (depth 0) carry neither.
func ChatTreeRows(rows []database.GetChatTreeByOwnerAndOrganizationRow) []codersdk.Chat {
result := make([]codersdk.Chat, len(rows))
for i, row := range rows {
result[i] = Chat(row.Chat, nil, nil)
result[i].HasUnread = row.HasUnread
SetChatTreePosition(&result[i], row.Depth, row.ChildChatCount)
}
return result
}

// ChatDiffStatus converts a database.ChatDiffStatus to a
// codersdk.ChatDiffStatus. When status is nil an empty value
// containing only the chatID is returned.
Expand Down
8 changes: 7 additions & 1 deletion coderd/database/db2sdk/db2sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,13 @@ func TestChat_AllFieldsPopulated(t *testing.T) {
v := reflect.ValueOf(got)
typ := v.Type()
// These fields are set outside db2sdk.Chat and intentionally remain zero.
skip := map[string]bool{"HasUnread": true, "Warnings": true, "QueuedForCapacity": true}
skip := map[string]bool{
"HasUnread": true,
"Warnings": true,
"QueuedForCapacity": true,
"Depth": true,
"ChildChatCount": true,
}
for i := range typ.NumField() {
field := typ.Field(i)
if skip[field.Name] {
Expand Down
Loading
Loading