refreshModelCache fetches available models for the current provider in background and caches them for autocomplete suggestions.
(ctx context.Context)
| 486 | // refreshModelCache fetches available models for the current provider in background |
| 487 | // and caches them for autocomplete suggestions. |
| 488 | func (cli *ChatCLI) refreshModelCache(ctx context.Context) { |
| 489 | go func() { |
| 490 | // The warmer must outlive the triggering request; detach |
| 491 | // cancellation while inheriting context values. |
| 492 | ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 15*time.Second) |
| 493 | defer cancel() |
| 494 | |
| 495 | models, err := cli.manager.ListModelsForProvider(ctx, cli.Provider) |
| 496 | if err != nil { |
| 497 | cli.logger.Debug("Failed to refresh model cache", zap.String("provider", cli.Provider), zap.Error(err)) |
| 498 | return |
| 499 | } |
| 500 | |
| 501 | cli.cachedModelsMu.Lock() |
| 502 | cli.cachedModels = models |
| 503 | cli.cachedModelsMu.Unlock() |
| 504 | |
| 505 | cli.logger.Debug("Model cache refreshed", zap.String("provider", cli.Provider), zap.Int("count", len(models))) |
| 506 | }() |
| 507 | } |
| 508 | |
| 509 | // getCachedModels returns the cached model list (thread-safe). |
| 510 | func (cli *ChatCLI) getCachedModels() []client.ModelInfo { |
no test coverage detected