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

Struct Server

coderd/x/chatd/chatd.go:211–277  ·  view source on GitHub ↗

Server handles background processing of pending chats.

Source from the content-addressed store, hash-verified

209
210// Server handles background processing of pending chats.
211type Server struct {
212 cancel context.CancelFunc
213 ctx context.Context
214 wg sync.WaitGroup
215 inflight sync.WaitGroup
216 inflightMu sync.Mutex
217
218 db database.Store
219 workerID uuid.UUID
220 logger slog.Logger
221
222 subscribeFn SubscribeFn
223
224 agentConnFn AgentConnFunc
225 agentInactiveDisconnectTimeout time.Duration
226 dialTimeout time.Duration
227 instructionLookupTimeout time.Duration
228 createWorkspaceFn chattool.CreateWorkspaceFn
229 startWorkspaceFn chattool.StartWorkspaceFn
230 stopWorkspaceFn chattool.StopWorkspaceFn
231 pubsub pubsub.Pubsub
232 webpushDispatcher webpush.Dispatcher
233 providerAPIKeys chatprovider.ProviderAPIKeys
234 allowBYOK bool
235 oidcTokenSource mcpclient.UserOIDCTokenSource
236 debugSvc *chatdebug.Service
237 debugSvcFactory func() *chatdebug.Service
238 debugSvcReady atomic.Bool
239 debugSvcInit sync.Once
240 configCache *chatConfigCache
241 configCacheUnsubscribe func()
242
243 // chatStreams stores per-chat stream state. Using sync.Map
244 // gives each chat independent locking — concurrent chats
245 // never contend with each other.
246 chatStreams sync.Map // uuid.UUID -> *chatStreamState
247
248 // workspaceMCPToolsCache caches workspace MCP tool definitions
249 // per chat to avoid re-fetching on every turn. The cache is
250 // keyed by chat ID and invalidated when the agent changes.
251 workspaceMCPToolsCache sync.Map // uuid.UUID -> *cachedWorkspaceMCPTools
252
253 usageTracker *workspacestats.UsageTracker
254 clock quartz.Clock
255 metrics *chatloop.Metrics
256 recordingSem chan struct{}
257
258 aibridgeTransportFactory *atomic.Pointer[aibridge.TransportFactory]
259 aiGatewayRoutingEnabled bool
260
261 // Configuration
262 pendingChatAcquireInterval time.Duration
263 maxChatsPerAcquire int32
264 inFlightChatStaleAfter time.Duration
265 chatHeartbeatInterval time.Duration
266
267 // heartbeatMu guards heartbeatRegistry.
268 heartbeatMu sync.Mutex

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected