mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: auto-archive inactive chats with audit trail (#24642)
Adds a background job in `dbpurge` that periodically archives chats inactive beyond a configurable threshold. Each archived root chat gets a background audit entry tagged `chat_auto_archive`. Disabled by default. * New `AutoArchiveInactiveChats` SQL query with LATERAL last-activity subquery and partial index on archive candidates * `site_configs`-backed `auto_archive_days` setting with admin-only PUT, any-authenticated-user GET * Cascade archive via `root_chat_id`; pinned chats and active threads exempt * Root-only audit dispatch on detached context, matching manual archive (`patchChat`) behavior * 11 subtests covering disabled no-op, boundary, deleted messages, child activity, pinned exemption, multi-owner, idempotency, and batch pagination PR #24643 adds per-owner digest notifications. PR #24704 adds the requisite UI controls. > 🤖
This commit is contained in:
@@ -796,6 +796,11 @@ type ChatDebugStep struct {
|
||||
// Zero means disabled — the template's own autostop setting applies.
|
||||
const DefaultChatWorkspaceTTL = 0
|
||||
|
||||
// DefaultChatAutoArchiveDays is the default auto-archive window, in
|
||||
// days, applied when no site config row exists. Zero disables
|
||||
// auto-archival.
|
||||
const DefaultChatAutoArchiveDays int32 = 0
|
||||
|
||||
// ChatWorkspaceTTLResponse is the response for getting the chat
|
||||
// workspace TTL setting.
|
||||
type ChatWorkspaceTTLResponse struct {
|
||||
@@ -823,6 +828,17 @@ type UpdateChatRetentionDaysRequest struct {
|
||||
RetentionDays int32 `json:"retention_days"`
|
||||
}
|
||||
|
||||
// ChatAutoArchiveDaysResponse contains the current chat auto-archive setting.
|
||||
type ChatAutoArchiveDaysResponse struct {
|
||||
AutoArchiveDays int32 `json:"auto_archive_days"`
|
||||
}
|
||||
|
||||
// UpdateChatAutoArchiveDaysRequest is a request to update the chat
|
||||
// auto-archive period.
|
||||
type UpdateChatAutoArchiveDaysRequest struct {
|
||||
AutoArchiveDays int32 `json:"auto_archive_days"`
|
||||
}
|
||||
|
||||
// ParseChatWorkspaceTTL parses a stored TTL string, returning the
|
||||
// default when the value is empty.
|
||||
func ParseChatWorkspaceTTL(s string) (time.Duration, error) {
|
||||
@@ -2183,6 +2199,33 @@ func (c *ExperimentalClient) UpdateChatRetentionDays(ctx context.Context, req Up
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetChatAutoArchiveDays returns the configured chat auto-archive period.
|
||||
func (c *ExperimentalClient) GetChatAutoArchiveDays(ctx context.Context) (ChatAutoArchiveDaysResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/experimental/chats/config/auto-archive-days", nil)
|
||||
if err != nil {
|
||||
return ChatAutoArchiveDaysResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return ChatAutoArchiveDaysResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp ChatAutoArchiveDaysResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
// UpdateChatAutoArchiveDays updates the chat auto-archive period.
|
||||
func (c *ExperimentalClient) UpdateChatAutoArchiveDays(ctx context.Context, req UpdateChatAutoArchiveDaysRequest) error {
|
||||
res, err := c.Request(ctx, http.MethodPut, "/api/experimental/chats/config/auto-archive-days", req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusNoContent {
|
||||
return ReadBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetChatTemplateAllowlist returns the deployment-wide chat template allowlist.
|
||||
func (c *ExperimentalClient) GetChatTemplateAllowlist(ctx context.Context) (ChatTemplateAllowlist, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/experimental/chats/config/template-allowlist", nil)
|
||||
|
||||
Reference in New Issue
Block a user