diff --git a/tools/BootstrapBlazor.LLMsDocs.Cli/BootstrapBlazor.LLMsDocs.Cli.csproj b/tools/BootstrapBlazor.LLMsDocs.Cli/BootstrapBlazor.LLMsDocs.Cli.csproj index 2947a815..09e622c0 100644 --- a/tools/BootstrapBlazor.LLMsDocs.Cli/BootstrapBlazor.LLMsDocs.Cli.csproj +++ b/tools/BootstrapBlazor.LLMsDocs.Cli/BootstrapBlazor.LLMsDocs.Cli.csproj @@ -1,7 +1,7 @@ - 10.0.5 + 10.0.6 Exe net10.0 false diff --git a/tools/BootstrapBlazor.LLMsDocs.Cli/README.md b/tools/BootstrapBlazor.LLMsDocs.Cli/README.md index 5865e216..6a085b93 100644 --- a/tools/BootstrapBlazor.LLMsDocs.Cli/README.md +++ b/tools/BootstrapBlazor.LLMsDocs.Cli/README.md @@ -127,7 +127,7 @@ bb-llms get Button --base-url ./wwwroot/llms > 含义:官网发版后,最长 24 小时本地才会感知到文档更新(用 `--refresh` 可立即刷新)。 -索引同样缓存。新增组件或扩展服务已发布但提示索引中不存在时,使用 `bb-llms get SelectCity --refresh` 同时刷新索引及目标文档。 +索引同样缓存。`get` 在缓存索引中找不到名称时,会自动回源刷新一次索引后重试,便于发现新增组件或扩展服务;刷新后仍不存在才报错。索引已回源、指定了 `--refresh` / `--no-cache` 或使用本地目录时,不会重复刷新。已有文档内容仍遵循 24 小时缓存,可使用 `bb-llms get SelectCity --refresh` 立即刷新索引及目标文档。此自动刷新行为需要更新到包含该功能的 CLI 版本。 --- diff --git a/tools/BootstrapBlazor.LLMsDocs.Cli/Services/LlmsDocsClient.cs b/tools/BootstrapBlazor.LLMsDocs.Cli/Services/LlmsDocsClient.cs index 40e6127d..577668d1 100644 --- a/tools/BootstrapBlazor.LLMsDocs.Cli/Services/LlmsDocsClient.cs +++ b/tools/BootstrapBlazor.LLMsDocs.Cli/Services/LlmsDocsClient.cs @@ -70,8 +70,20 @@ public async Task GetComponentAsync(string name, CancellationToken ct = throw new ArgumentException("Component name is required.", nameof(name)); } - var entry = ParseIndex(await GetIndexAsync(ct)) + var index = ""; + var usedCachedIndex = _useCache && !_refresh && TryReadFreshCache("llms.txt", out index); + if (!usedCachedIndex) + { + index = await GetIndexAsync(ct); + } + + var entry = ParseIndex(index) .FirstOrDefault(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase)); + if (entry is null && usedCachedIndex) + { + entry = ParseIndex(await FetchAsync("llms.txt", ct, refresh: true)) + .FirstOrDefault(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase)); + } if (entry is null) { throw new FileNotFoundException($"Component not found in index: {name}"); @@ -112,7 +124,7 @@ public async Task> SearchAsync(string query, int l // ---- core fetch ------------------------------------------------------- - private async Task FetchAsync(string relativePath, CancellationToken ct) + private async Task FetchAsync(string relativePath, CancellationToken ct, bool refresh = false) { if (!_isRemote) { @@ -127,7 +139,7 @@ private async Task FetchAsync(string relativePath, CancellationToken ct) var url = new Uri(_baseUri!, relativePath); - if (_useCache && !_refresh && TryReadFreshCache(relativePath, out var fresh)) + if (_useCache && !_refresh && !refresh && TryReadFreshCache(relativePath, out var fresh)) { return fresh; }