MCPcopy Index your code
hub / github.com/coder/coder / publishChatPubsubEvent

Method publishChatPubsubEvent

coderd/x/chatd/chatd.go:5518–5549  ·  view source on GitHub ↗

publishChatPubsubEvent broadcasts a chat lifecycle event via PostgreSQL pubsub so that all replicas can push updates to watching clients.

(chat database.Chat, kind codersdk.ChatWatchEventKind, diffStatus *codersdk.ChatDiffStatus)

Source from the content-addressed store, hash-verified

5516// publishChatPubsubEvent broadcasts a chat lifecycle event via PostgreSQL
5517// pubsub so that all replicas can push updates to watching clients.
5518func (p *Server) publishChatPubsubEvent(chat database.Chat, kind codersdk.ChatWatchEventKind, diffStatus *codersdk.ChatDiffStatus) {
5519 if p.pubsub == nil {
5520 return
5521 }
5522 // diffStatus is applied below. File metadata is intentionally
5523 // omitted from pubsub events to avoid an extra DB query per
5524 // publish. Clients must merge pubsub updates, not replace
5525 // cached file metadata.
5526 sdkChat := db2sdk.Chat(chat, nil, nil)
5527 if diffStatus != nil {
5528 sdkChat.DiffStatus = diffStatus
5529 }
5530 event := codersdk.ChatWatchEvent{
5531 Kind: kind,
5532 Chat: sdkChat,
5533 }
5534 payload, err := json.Marshal(event)
5535 if err != nil {
5536 p.logger.Error(context.Background(), "failed to marshal chat pubsub event",
5537 slog.F("chat_id", chat.ID),
5538 slog.Error(err),
5539 )
5540 return
5541 }
5542 if err := p.pubsub.Publish(coderdpubsub.ChatWatchEventChannel(chat.OwnerID), payload); err != nil {
5543 p.logger.Error(context.Background(), "failed to publish chat pubsub event",
5544 slog.F("chat_id", chat.ID),
5545 slog.F("kind", kind),
5546 slog.Error(err),
5547 )
5548 }
5549}
5550
5551// pendingToStreamToolCalls converts a slice of chatloop pending
5552// tool calls into the SDK streaming representation.

Callers 15

CreateChatMethod · 0.95
SendMessageMethod · 0.95
EditMessageMethod · 0.95
ArchiveChatMethod · 0.95
PromoteQueuedMethod · 0.95
PublishTitleChangeMethod · 0.95
setChatWaitingMethod · 0.95
processChatMethod · 0.95

Calls 4

ChatFunction · 0.92
PublishMethod · 0.65
MarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected