From da97410f48a1e94d7e1fe019c69a7c847fe67ddf Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期三, 12 八月 2026 17:42:02 +0800
Subject: [PATCH] 修复LLM工具无法点击的问题
---
src/Moli.Desktop/Llm/LlmGatewayService.cs | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/src/Moli.Desktop/Llm/LlmGatewayService.cs b/src/Moli.Desktop/Llm/LlmGatewayService.cs
index 472ecda..e068be6 100644
--- a/src/Moli.Desktop/Llm/LlmGatewayService.cs
+++ b/src/Moli.Desktop/Llm/LlmGatewayService.cs
@@ -20,6 +20,7 @@
private readonly IDiagnosticsService _diagnostics;
private readonly IAiChatClient? _aiChatClient;
private readonly ConcurrentDictionary<string, CancellationTokenSource> _activeRequests = new(StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, string> _requestPlugins = new(StringComparer.OrdinalIgnoreCase);
public LlmGatewayService(
ILlmModelRegistry registry,
@@ -196,6 +197,7 @@
var timeoutMs = request.Options.TimeoutMs ?? model.RequestDefaults.TimeoutMs;
linkedCts.CancelAfter(TimeSpan.FromMilliseconds(timeoutMs));
_activeRequests[request.RequestId] = linkedCts;
+ _requestPlugins[request.RequestId] = request.PluginId;
var secret = await _credentialStore.ResolveSecretAsync(model.AuthRef, linkedCts.Token).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(model.AuthRef) && string.IsNullOrWhiteSpace(secret))
@@ -227,6 +229,7 @@
if (!await enumerator.MoveNextAsync().ConfigureAwait(false))
{
_activeRequests.TryRemove(request.RequestId, out _);
+ _requestPlugins.TryRemove(request.RequestId, out _);
linkedCts.Dispose();
yield break;
}
@@ -275,6 +278,7 @@
if (nextEvent is LlmCompletedEvent or LlmErrorEvent)
{
_activeRequests.TryRemove(request.RequestId, out _);
+ _requestPlugins.TryRemove(request.RequestId, out _);
linkedCts.Dispose();
}
}
@@ -297,6 +301,7 @@
cancellationToken.ThrowIfCancellationRequested();
if (_activeRequests.TryRemove(requestId, out var cts))
{
+ _requestPlugins.TryRemove(requestId, out _);
cts.Cancel();
cts.Dispose();
}
@@ -304,6 +309,27 @@
return Task.CompletedTask;
}
+ public Task CancelPluginRequestsAsync(string pluginId, CancellationToken cancellationToken = default)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ var matchingIds = _requestPlugins
+ .Where(kvp => string.Equals(kvp.Value, pluginId, StringComparison.OrdinalIgnoreCase))
+ .Select(kvp => kvp.Key)
+ .ToList();
+
+ foreach (var requestId in matchingIds)
+ {
+ if (_activeRequests.TryRemove(requestId, out var cts))
+ {
+ _requestPlugins.TryRemove(requestId, out _);
+ cts.Cancel();
+ cts.Dispose();
+ }
+ }
+
+ return Task.CompletedTask;
+ }
+
private static bool IsValidRequest(LlmChatRequest request, out string error)
{
if (string.IsNullOrWhiteSpace(request.RequestId) ||
--
Gitblit v1.9.1