mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add experimental agents support (#22290)
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>
This commit is contained in:
co-authored by
Cian Johnston
Danielle Maywood
Jeremy Ruppel
Claude Sonnet 4.6
parent
67da4e8b56
commit
edee917d88
@@ -0,0 +1,46 @@
|
||||
package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
func ChatEventChannel(ownerID uuid.UUID) string {
|
||||
return fmt.Sprintf("chat:owner:%s", ownerID)
|
||||
}
|
||||
|
||||
func HandleChatEvent(cb func(ctx context.Context, payload ChatEvent, err error)) func(ctx context.Context, message []byte, err error) {
|
||||
return func(ctx context.Context, message []byte, err error) {
|
||||
if err != nil {
|
||||
cb(ctx, ChatEvent{}, xerrors.Errorf("chat event pubsub: %w", err))
|
||||
return
|
||||
}
|
||||
var payload ChatEvent
|
||||
if err := json.Unmarshal(message, &payload); err != nil {
|
||||
cb(ctx, ChatEvent{}, xerrors.Errorf("unmarshal chat event"))
|
||||
return
|
||||
}
|
||||
|
||||
cb(ctx, payload, err)
|
||||
}
|
||||
}
|
||||
|
||||
type ChatEvent struct {
|
||||
Kind ChatEventKind `json:"kind"`
|
||||
Chat codersdk.Chat `json:"chat"`
|
||||
}
|
||||
|
||||
type ChatEventKind string
|
||||
|
||||
const (
|
||||
ChatEventKindStatusChange ChatEventKind = "status_change"
|
||||
ChatEventKindTitleChange ChatEventKind = "title_change"
|
||||
ChatEventKindCreated ChatEventKind = "created"
|
||||
ChatEventKindDeleted ChatEventKind = "deleted"
|
||||
)
|
||||
@@ -0,0 +1,37 @@
|
||||
package pubsub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ChatStreamNotifyChannel returns the pubsub channel for per-chat
|
||||
// stream notifications. Subscribers receive lightweight notifications
|
||||
// and read actual content from the database.
|
||||
func ChatStreamNotifyChannel(chatID uuid.UUID) string {
|
||||
return fmt.Sprintf("chat:stream:%s", chatID)
|
||||
}
|
||||
|
||||
// ChatStreamNotifyMessage is the payload published on the per-chat
|
||||
// stream notification channel. The actual message content is read
|
||||
// from the database by subscribers.
|
||||
type ChatStreamNotifyMessage struct {
|
||||
// AfterMessageID tells subscribers to query messages after this
|
||||
// ID. Set when a new message is persisted.
|
||||
AfterMessageID int64 `json:"after_message_id,omitempty"`
|
||||
|
||||
// Status is set when the chat status changes. Subscribers use
|
||||
// this to update clients and to manage relay lifecycle.
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// WorkerID identifies which replica is running the chat. Used
|
||||
// by enterprise relay to know where to connect.
|
||||
WorkerID string `json:"worker_id,omitempty"`
|
||||
|
||||
// Error is set when a processing error occurs.
|
||||
Error string `json:"error,omitempty"`
|
||||
|
||||
// QueueUpdate is set when the queued messages change.
|
||||
QueueUpdate bool `json:"queue_update,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user