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

Method UserPrompt

coderd/x/chatd/configcache.go:356–383  ·  view source on GitHub ↗
(ctx context.Context, userID uuid.UUID)

Source from the content-addressed store, hash-verified

354}
355
356func (c *chatConfigCache) UserPrompt(ctx context.Context, userID uuid.UUID) (string, error) {
357 if prompt, ok := c.cachedUserPrompt(userID); ok {
358 return prompt, nil
359 }
360
361 epoch := c.currentUserPromptEpoch()
362 prompt, err := singleflightDoChan(ctx, &c.userPromptFetches, fmt.Sprintf("%d:%s", epoch, userID), func() (string, error) {
363 if cached, ok := c.cachedUserPrompt(userID); ok {
364 return cached, nil
365 }
366
367 fetched, err := c.db.GetUserChatCustomPrompt(c.ctx, userID)
368 if err != nil {
369 if errors.Is(err, sql.ErrNoRows) {
370 c.storeUserPrompt(epoch, userID, "")
371 return "", nil
372 }
373 return "", err
374 }
375 c.storeUserPrompt(epoch, userID, fetched)
376 return fetched, nil
377 })
378 if err != nil {
379 return "", err
380 }
381
382 return prompt, nil
383}
384
385func (c *chatConfigCache) cachedUserPrompt(userID uuid.UUID) (string, bool) {
386 prompt, _, ok := c.userPrompts.Get(userID)

Calls 6

cachedUserPromptMethod · 0.95
storeUserPromptMethod · 0.95
singleflightDoChanFunction · 0.85
IsMethod · 0.45