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

Method subscribeChatControl

coderd/x/chatd/chatd.go:5802–5838  ·  view source on GitHub ↗
(
	ctx context.Context,
	chatID uuid.UUID,
	cancel context.CancelCauseFunc,
	logger slog.Logger,
)

Source from the content-addressed store, hash-verified

5800}
5801
5802func (p *Server) subscribeChatControl(
5803 ctx context.Context,
5804 chatID uuid.UUID,
5805 cancel context.CancelCauseFunc,
5806 logger slog.Logger,
5807) func() {
5808 if p.pubsub == nil {
5809 return nil
5810 }
5811
5812 listener := func(_ context.Context, message []byte, err error) {
5813 if err != nil {
5814 logger.Warn(ctx, "chat control pubsub error", slog.Error(err))
5815 return
5816 }
5817
5818 var notify coderdpubsub.ChatStreamNotifyMessage
5819 if unmarshalErr := json.Unmarshal(message, &notify); unmarshalErr != nil {
5820 logger.Warn(ctx, "failed to unmarshal chat control notify", slog.Error(unmarshalErr))
5821 return
5822 }
5823
5824 if shouldCancelChatFromControlNotification(notify, p.workerID) {
5825 cancel(chatloop.ErrInterrupted)
5826 }
5827 }
5828
5829 controlCancel, err := p.pubsub.SubscribeWithErr(
5830 coderdpubsub.ChatStreamNotifyChannel(chatID),
5831 listener,
5832 )
5833 if err != nil {
5834 logger.Warn(ctx, "failed to subscribe to chat control notifications", slog.Error(err))
5835 return nil
5836 }
5837 return controlCancel
5838}
5839
5840// Rejects oversize images on capped providers before any upstream
5841// request is issued.

Callers 1

processChatMethod · 0.95

Calls 4

SubscribeWithErrMethod · 0.65
ErrorMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected