From 7157cc77774c33a7ec1dab0880ba773aab30de08 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 11:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BA=E5=AE=9Adlite=E5=8D=95=E5=9B=BE?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E5=B9=B6=E9=9A=94=E7=A6=BBAgent=EF=BC=8C?= =?UTF-8?q?=E6=89=A7=E8=A1=8C500=E6=AF=AB=E7=A7=92=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E5=92=8C=E6=96=B0=E5=9B=BE=E5=A4=8D=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Training/DesktopSequenceVisionClient.cs | 41 ++----------- .../Training/SopDraftReferenceVerifier.cs | 2 +- .../Training/SopDraftVideoVerifier.cs | 24 +++----- .../Training/SopVideoFlowTest.cs | 2 +- .../VVMs/RecipeEditor/EditorNodes.cs | 6 +- .../VVMs/RecipeEditor/RecipeEditor.axaml | 27 ++------- .../SopAgentVerificationViewModel.cs | 48 ++++++++++++++- .../RecipeEditor/SopVideoAgentViewModel.cs | 16 ++--- .../VVMs/SopPage/SopPageViewModel.cs | 2 +- .../Sop/LayaVisionDecisionClient.cs | 21 +++---- .../Sop/RealtimeDecisionPolicy.cs | 46 +++++++++++++++ .../Sop/SopEngine.BufferedEvidence.cs | 7 ++- .../Sop/SopEngine.ContinuousChecks.cs | 31 +++++----- .../Sop/SopEngine.cs | 7 +-- .../Sop/VisionDecision.cs | 21 ++++--- .../SopAgent/SopDraftVerification.cs | 10 ++-- .../SopAgent/SopStepDesignPrompt.cs | 33 +++++------ .../SopAgent/SopVideoAgentClient.cs | 29 ++------- .../SopAgent/SopVideoDraftClient.cs | 10 +--- .../DirectDraftVerificationChecks.cs | 8 +-- .../InspectionPolicyChecks.cs | 8 +-- .../AgentDraftVerificationChecks.cs | 9 ++- .../LiveVideoFlowChecks.cs | 7 ++- tests/VideoFlowTest.Smoke/Program.cs | 21 +++---- .../BufferedEvidenceChecks.cs | 6 +- .../ContinuousCheckTests.cs | 23 ++++---- tests/VisionDecision.Smoke/D3Checks.cs | 6 +- tests/VisionDecision.Smoke/DliteAudit.cs | 51 ++++++++++++++++ tests/VisionDecision.Smoke/LayaChecks.cs | 11 +--- tests/VisionDecision.Smoke/Program.cs | 5 +- .../RealtimeDeadlineChecks.cs | 59 +++++++++++++++++++ 31 files changed, 357 insertions(+), 240 deletions(-) create mode 100644 src/SopHelper.CrossPlatform.Engine/Sop/RealtimeDecisionPolicy.cs create mode 100644 tests/VisionDecision.Smoke/DliteAudit.cs create mode 100644 tests/VisionDecision.Smoke/RealtimeDeadlineChecks.cs diff --git a/src/SopHelper.Avalonia/Training/DesktopSequenceVisionClient.cs b/src/SopHelper.Avalonia/Training/DesktopSequenceVisionClient.cs index 96baa10..3a70134 100644 --- a/src/SopHelper.Avalonia/Training/DesktopSequenceVisionClient.cs +++ b/src/SopHelper.Avalonia/Training/DesktopSequenceVisionClient.cs @@ -1,44 +1,15 @@ -using System.Net.Http; -using System.Text.Json; +using System.Net.Http; using SopHelper.Engine.Sop; -using SopHelper.Presentation; namespace SopHelper.Training; -/// 仅明确启用时复用 Agent 连接;连接变化只作用于下一次请求。 +/// 旧配置兼容占位;Agent只负责编写步骤,禁止用作判定模型。 public sealed class DesktopSequenceVisionClient(HttpClient http) : IVisionDecisionClient { - private readonly object _gate = new(); - private long _refreshAt; - private SequenceVisionDecisionClient? _client; - private SequenceVisionDecisionClient Current + public bool SupportsSequences => false; + public Task DecideAsync(VisionDecisionRequest request, CancellationToken token) { - get - { - lock (_gate) - { - if (_client is not null && Environment.TickCount64 < _refreshAt) return _client; - _refreshAt = Environment.TickCount64 + 1000; - _client = new(http); - try - { - var path = Path.Combine(DesktopPlatform.WorkspaceRoot, "workspace", "sop-agent.json"); - if (!File.Exists(path)) return _client; - using var document = JsonDocument.Parse(File.ReadAllText(path)); - var root = document.RootElement; - if (root.TryGetProperty("useForSequence", out var enabled) && enabled.GetBoolean()) - _client = new(http, new(root.GetProperty("endpoint").GetString() ?? "", - root.GetProperty("model").GetString() ?? "", - root.TryGetProperty("apiKey", out var key) ? key.GetString() ?? "" : "", - root.TryGetProperty("sequenceEnableThinking", out var thinking) && thinking.ValueKind != JsonValueKind.Null - ? thinking.GetBoolean() : null)); - } - catch (Exception error) when (error is IOException or UnauthorizedAccessException or JsonException or InvalidOperationException or KeyNotFoundException) - { _client = new(http, new("", "")); } - return _client; - } - } + _ = http; + return Task.FromResult(RealtimeDecisionPolicy.Unsupported()); } - public bool SupportsSequences => Current.SupportsSequences; - public Task DecideAsync(VisionDecisionRequest request, CancellationToken token) => Current.DecideAsync(request, token); } diff --git a/src/SopHelper.Avalonia/Training/SopDraftReferenceVerifier.cs b/src/SopHelper.Avalonia/Training/SopDraftReferenceVerifier.cs index 1df3766..7e99a94 100644 --- a/src/SopHelper.Avalonia/Training/SopDraftReferenceVerifier.cs +++ b/src/SopHelper.Avalonia/Training/SopDraftReferenceVerifier.cs @@ -13,7 +13,7 @@ public sealed class SopDraftReferenceVerifier(IVisionDecisionClient? vision = nu SopVideoSample video, int blockedId, CancellationToken token) { var checks = new List(); - var client = vision ?? new ConfiguredVisionDecisionClient(Http, new DesktopSequenceVisionClient(Http)); + var client = vision ?? new ConfiguredVisionDecisionClient(Http); foreach (var id in new[] { blockedId, blockedId + 1 }.Where(id => id > 0 && id <= draft.Steps.Count)) { var step = config.Sop.Steps[id - 1]; var source = draft.Steps[id - 1]; diff --git a/src/SopHelper.Avalonia/Training/SopDraftVideoVerifier.cs b/src/SopHelper.Avalonia/Training/SopDraftVideoVerifier.cs index cf8fd77..a6ef439 100644 --- a/src/SopHelper.Avalonia/Training/SopDraftVideoVerifier.cs +++ b/src/SopHelper.Avalonia/Training/SopDraftVideoVerifier.cs @@ -1,4 +1,4 @@ -using Avalonia.Threading; +using Avalonia.Threading; using OpenCvSharp; using SopHelper.Engine.Sop; using SopHelper.Engine.SopAgent; @@ -29,7 +29,7 @@ public sealed class SopDraftVideoVerifier : ISopDraftVideoVerifier using var budget = CancellationTokenSource.CreateLinkedTokenSource(token); budget.CancelAfter(TimeSpan.FromSeconds(video.DurationSeconds + 210)); var images = new System.Collections.Concurrent.ConcurrentDictionary(); - var budgetHints = new System.Collections.Concurrent.ConcurrentDictionary(); + var checks = new System.Collections.Concurrent.ConcurrentQueue(); var playback = new RecordedVideoPlayback(); using var test = new SopVideoFlowTest(config); var diagnostics = new SopTriggerDiagnosticsCollector(config, draft, video.DurationSeconds); @@ -50,21 +50,15 @@ public sealed class SopDraftVideoVerifier : ISopDraftVideoVerifier }; test.DecisionEvaluated += (request, decision, accepted) => { + checks.Enqueue(new(request.StepId, request.FrameId, request.SourceSeconds, request.ImageCount, decision.ElapsedMs, decision.EffectiveStatus.ToString(), accepted)); var confirmation = request.ConfirmationEvidence; diagnostics.Evaluated(request.StepId, confirmation?.FrameId ?? request.FrameId, confirmation?.SourceSeconds ?? (fps > 0 ? (confirmation?.FrameId ?? request.FrameId) / fps : 0), accepted, decision.Reason); if (images.TryGetValue(request.StepId, out var image)) images[request.StepId] = image with { FrameId = request.FrameId, Seconds = request.SourceSeconds ?? (fps > 0 ? request.FrameId / fps : 0), - Jpeg = request.Jpeg, Confidence = decision.Confidence, Accepted = accepted, Reason = decision.Reason }; - if (decision.Reason.Contains("接口请求失败") || decision.Reason.Contains("超时或已取消")) infrastructureFailure = true; - var options = config.Sop.Steps[request.StepId - 1].AiConfirmation; - if (!accepted && decision.Reason.Contains("超时或已取消") && options is { EvidenceMode: VisionEvidenceMode.Sequence, CheckWindowMs: > 0 } - && options.CheckWindowMs < options.TimeoutSeconds * 1000L) - { - var requestMs = (int)Math.Min(int.MaxValue, options.TimeoutSeconds * 1000L); - var suggested = (int)Math.Min(60000, requestMs + (long)Math.Max(options.CheckSettleMs, options.ObservationMinMs) + 500); - if (suggested > options.CheckWindowMs) budgetHints[request.StepId] = new(request.StepId, options.CheckWindowMs, requestMs, suggested); - } + Jpeg = request.Jpeg, Confidence = decision.Confidence, Accepted = accepted, Reason = decision.Reason, ImageCount = request.ImageCount, ElapsedMs = decision.ElapsedMs, Status = decision.EffectiveStatus.ToString() }; + if (decision.EffectiveStatus == VisionDecisionStatus.TimedOut || decision.Reason.Contains("接口请求失败") || decision.Reason.Contains("超时或已取消")) infrastructureFailure = true; + }; string? lastProgress = null; test.Changed += (status, _) => @@ -104,15 +98,15 @@ public sealed class SopDraftVideoVerifier : ISopDraftVideoVerifier : "标准视频回放期间视觉服务未返回有效判定,尚未完成验收;不应据此放宽工艺要求"; return new(test.IsCompleted && !contradictory && !infrastructureFailure, summary, test.StepResults, images.Values.OrderBy(i => i.StepId).ToArray(), fingerprint, infrastructureFailure, diagnostics.Build(), references, test.IsCompleted, - images.Values.Any(i => i.Accepted == true) ? budgetHints.Values.OrderBy(h => h.StepId).ToArray() : null); + Checks: checks.ToArray()); } catch (OperationCanceledException) when (!token.IsCancellationRequested) { - return new(false, "标准视频回测超时,请检查视觉服务响应速度", test.StepResults, images.Values.ToArray(), fingerprint, true, diagnostics.Build()); + return new(false, "标准视频回测超时,请检查视觉服务响应速度", test.StepResults, images.Values.ToArray(), fingerprint, true, diagnostics.Build(), Checks: checks.ToArray()); } catch (Exception error) when (error is not OperationCanceledException) { - return new(false, "标准视频回测无法完成:" + error.Message, test.StepResults, images.Values.ToArray(), fingerprint, true, diagnostics.Build()); + return new(false, "标准视频回测无法完成:" + error.Message, test.StepResults, images.Values.ToArray(), fingerprint, true, diagnostics.Build(), Checks: checks.ToArray()); } finally { diff --git a/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs b/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs index 92837cc..cdfa118 100644 --- a/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs +++ b/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs @@ -51,7 +51,7 @@ public sealed class SopVideoFlowTest : IDisposable snapshot.Sop.Settings.AutoResetOnComplete = false; snapshot.Sop.Model = null; _stride = Math.Max(1, snapshot.Sop.Settings.FrameStride); - _engine.VisionDecisionClient = visionClient ?? new ConfiguredVisionDecisionClient(VisionHttp, new DesktopSequenceVisionClient(VisionHttp)); + _engine.VisionDecisionClient = visionClient ?? new ConfiguredVisionDecisionClient(VisionHttp); _engine.LogArrived += entry => LogObserved?.Invoke(entry); _engine.DecisionCandidatesObserved += (id, frames) => DecisionCandidatesObserved?.Invoke(id, frames); _engine.DecisionSubmitted += request => { DecisionImageCaptured?.Invoke(request.Jpeg, request.FrameId); DecisionSubmitted?.Invoke(request); }; diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index 43e0c0b..3998196 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -780,7 +780,7 @@ public class RegionNode : EditorNode /// public class StepNode : EditorNode { - private int _aiCheckWindowMs = 10000, _aiMaxChecks = 3, _aiCheckSettleMs = 350; + private int _aiCheckWindowMs = 10000, _aiMaxChecks = 20, _aiCheckSettleMs = 100; public int AiCheckWindowMs { get => _aiCheckWindowMs; set { if (SetProperty(ref _aiCheckWindowMs, value)) RaisePropertyChanged(nameof(AiContinueAfterWindow)); } } public bool AiContinueAfterWindow { get => AiCheckWindowMs > 0; set { if (value != AiContinueAfterWindow) AiCheckWindowMs = value ? 10000 : 0; } } public int AiMaxChecks { get => _aiMaxChecks; set => SetProperty(ref _aiMaxChecks, value); } @@ -788,7 +788,7 @@ public class StepNode : EditorNode private string _aiEvidenceMode = VisionEvidenceMode.SingleFrame; private int _aiObservationPreRollMs = 1000, _aiObservationMinMs = 2400, _aiObservationMaxMs = 10000, _aiObservationSampleMs = 400, _aiObservationMaxFrames = 24, _aiObservationRequestMaxFrames = 12; - public IReadOnlyList AiEvidenceModes { get; } = [VisionEvidenceMode.SingleFrame, VisionEvidenceMode.Sequence]; + public IReadOnlyList AiEvidenceModes { get; } = [VisionEvidenceMode.SingleFrame]; public string AiEvidenceMode { get => _aiEvidenceMode; set { if (SetProperty(ref _aiEvidenceMode, value)) RaisePropertyChanged(nameof(UsesSequenceEvidence)); } } public bool UsesSequenceEvidence => AiEvidenceMode == VisionEvidenceMode.Sequence; public int AiObservationPreRollMs { get => _aiObservationPreRollMs; set => SetProperty(ref _aiObservationPreRollMs, value); } @@ -812,7 +812,7 @@ public class StepNode : EditorNode public int AiHandMemoryMs { get => _aiHandMemoryMs; set => SetProperty(ref _aiHandMemoryMs, value); } private string _aiImageRegion = ""; private double _aiMinConfidence = 0.85; - private int _aiRetryDelayMs = 3000, _aiTimeoutSeconds = 30; + private int _aiRetryDelayMs = 200, _aiTimeoutSeconds = 1; public string AiImageRegion { get => _aiImageRegion; set => SetProperty(ref _aiImageRegion, value); } public double AiMinConfidence { get => _aiMinConfidence; set => SetProperty(ref _aiMinConfidence, value); } public int AiRetryDelayMs { get => _aiRetryDelayMs; set => SetProperty(ref _aiRetryDelayMs, value); } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 80a3334..f7e1fa7 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -166,21 +166,8 @@ - - - - - - - - - - - - - - - + + @@ -205,9 +192,9 @@ - + - + @@ -520,9 +507,7 @@ - - @@ -545,11 +530,11 @@