接入限时复检界面并区分跳过与整轮合格状态
This commit is contained in:
parent
11eaca66c6
commit
70c04d9e94
@ -28,14 +28,15 @@ public sealed class SopVideoFlowTest : IDisposable
|
||||
public event Action<VisionDecisionRequest, VisionDecisionResult, bool>? DecisionEvaluated;
|
||||
public IReadOnlyList<SopHelper.Engine.SopAgent.SopDraftVerificationStep> StepResults
|
||||
{
|
||||
get { lock (_gate) return _steps.Values.OrderBy(s => s.StepId).Select(s => new SopHelper.Engine.SopAgent.SopDraftVerificationStep(s.StepId, s.Name, s.IsMet, s.Message)).ToArray(); }
|
||||
get { lock (_gate) return _steps.Values.OrderBy(s => s.StepId).Select(s => new SopHelper.Engine.SopAgent.SopDraftVerificationStep(s.StepId, s.Name, s.IsMet, s.Message, s.IsSkipped)).ToArray(); }
|
||||
}
|
||||
public bool IsCompleted => _engine.State == EngineState.Completed;
|
||||
public bool IsCompleted => _engine.RoundPassed;
|
||||
public bool IsFinished => _engine.State == EngineState.Completed;
|
||||
public IReadOnlyDictionary<string, RegionDef> Regions => _engine.Config.Sop.Regions;
|
||||
public string Details
|
||||
{
|
||||
get { lock (_gate) return string.Join(Environment.NewLine, _steps.Values.OrderBy(s => s.StepId)
|
||||
.Select(s => $"{(s.IsMet ? "✓" : s.IsCurrent ? "▶" : "○")} {s.StepId} {s.Name}:{s.Message}"
|
||||
.Select(s => $"{(s.IsMet ? "✓" : s.IsSkipped ? "✕" : s.IsCurrent ? "▶" : "○")} {s.StepId} {s.Name}:{s.Message}"
|
||||
+ (!s.IsMet && _lastAiFailures.TryGetValue(s.StepId, out var failure) && failure != s.Message ? $"(最近判定:{failure})" : ""))); }
|
||||
}
|
||||
public string Progress { get { lock (_gate) return $"已完成 {_steps.Values.Count(s => s.IsMet)}/{_steps.Count} 步"; } }
|
||||
@ -55,12 +56,13 @@ public sealed class SopVideoFlowTest : IDisposable
|
||||
_engine.DecisionEvaluated += (request, result, accepted) => DecisionEvaluated?.Invoke(request, result, accepted);
|
||||
_engine.StepSnapshotChanged += step =>
|
||||
{
|
||||
if (_steps.TryGetValue(step.StepId, out var previous) && previous.IsMet && !step.IsMet) return;
|
||||
if (_steps.TryGetValue(step.StepId, out var previous) && (previous.IsMet || previous.IsSkipped) && !step.IsMet && !step.IsSkipped) return;
|
||||
_steps[step.StepId] = step;
|
||||
if (step.Message.StartsWith("AI 未确认完成")) _lastAiFailures[step.StepId] = step.Message;
|
||||
Changed?.Invoke(IsCompleted ? $"流程检测通过,{Progress}" : $"正在测试流程,{Progress}", Details);
|
||||
};
|
||||
_engine.Completed += () => Changed?.Invoke($"流程检测通过,{Progress}", Details);
|
||||
_engine.RoundStarted += () => { _steps.Clear(); _lastAiFailures.Clear(); };
|
||||
_engine.RoundFinished += passed => Changed?.Invoke(passed ? $"流程检测通过,{Progress}" : $"本轮结束,有步骤未通过并跳过,{Progress}", Details);
|
||||
_engine.Load(snapshot);
|
||||
}
|
||||
|
||||
@ -124,6 +126,7 @@ public sealed class SopVideoFlowTest : IDisposable
|
||||
{
|
||||
lock (_gate) return IsCompleted
|
||||
? $"{reason};流程检测通过,{Progress}"
|
||||
: IsFinished ? $"{reason};本轮结束,有步骤未通过并跳过,{Progress}"
|
||||
: $"{reason};流程未完成,{Progress},停在步骤 {_engine.CurrentStep?.Id}「{_engine.CurrentStep?.Name}」";
|
||||
}
|
||||
|
||||
|
||||
@ -424,6 +424,7 @@ public class RecipeNode : EditorNode
|
||||
AiConfirmation = step.AiConfirmation is null ? null : new AiConfirmation
|
||||
{
|
||||
MinConfidence = step.AiConfirmation.MinConfidence,
|
||||
CheckWindowMs = step.AiConfirmation.CheckWindowMs, MaxChecks = step.AiConfirmation.MaxChecks, CheckSettleMs = step.AiConfirmation.CheckSettleMs,
|
||||
EvidenceMode = step.AiConfirmation.EvidenceMode,
|
||||
ObservationPreRollMs = step.AiConfirmation.ObservationPreRollMs, ObservationMinMs = step.AiConfirmation.ObservationMinMs,
|
||||
ObservationMaxMs = step.AiConfirmation.ObservationMaxMs, ObservationSampleMs = step.AiConfirmation.ObservationSampleMs,
|
||||
@ -492,6 +493,7 @@ public class RecipeNode : EditorNode
|
||||
AiConfirmation = new AiConfirmation
|
||||
{
|
||||
MinConfidence = step.AiMinConfidence,
|
||||
CheckWindowMs = step.AiCheckWindowMs, MaxChecks = step.AiMaxChecks, CheckSettleMs = step.AiCheckSettleMs,
|
||||
EvidenceMode = step.AiEvidenceMode, ObservationPreRollMs = step.AiObservationPreRollMs,
|
||||
ObservationMinMs = step.AiObservationMinMs, ObservationMaxMs = step.AiObservationMaxMs,
|
||||
ObservationSampleMs = step.AiObservationSampleMs, ObservationMaxFrames = step.AiObservationMaxFrames,
|
||||
@ -778,6 +780,11 @@ public class RegionNode : EditorNode
|
||||
/// </summary>
|
||||
public class StepNode : EditorNode
|
||||
{
|
||||
private int _aiCheckWindowMs, _aiMaxChecks = 3, _aiCheckSettleMs = 350;
|
||||
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); }
|
||||
public int AiCheckSettleMs { get => _aiCheckSettleMs; set => SetProperty(ref _aiCheckSettleMs, value); }
|
||||
private string _aiEvidenceMode = VisionEvidenceMode.SingleFrame;
|
||||
private int _aiObservationPreRollMs = 1000, _aiObservationMinMs = 2400, _aiObservationMaxMs = 10000,
|
||||
_aiObservationSampleMs = 400, _aiObservationMaxFrames = 24;
|
||||
@ -815,6 +822,7 @@ public class StepNode : EditorNode
|
||||
{
|
||||
if (value is null) return;
|
||||
AiMinConfidence = value.MinConfidence;
|
||||
AiCheckWindowMs = value.CheckWindowMs; AiMaxChecks = value.MaxChecks; AiCheckSettleMs = value.CheckSettleMs;
|
||||
AiEvidenceMode = value.EvidenceMode; AiObservationPreRollMs = value.ObservationPreRollMs;
|
||||
AiObservationMinMs = value.ObservationMinMs; AiObservationMaxMs = value.ObservationMaxMs;
|
||||
AiObservationSampleMs = value.ObservationSampleMs; AiObservationMaxFrames = value.ObservationMaxFrames;
|
||||
|
||||
@ -150,6 +150,15 @@
|
||||
</Grid>
|
||||
<TextBlock Text="AI 完成确认" Classes="Title" Margin="0,10,0,4" />
|
||||
<StackPanel Spacing="6">
|
||||
<CheckBox Content="限时复检,到期未通过则跳过并继续后续步骤" IsChecked="{Binding AiContinueAfterWindow, Mode=TwoWay}" />
|
||||
<StackPanel IsVisible="{Binding AiContinueAfterWindow}" Spacing="6">
|
||||
<TextBlock Text="操作事件开启窗口;优先在手部停稳或离开后检查,窗口内用新画面重试。跳过记录为未通过。" TextWrapping="Wrap" />
|
||||
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto,Auto">
|
||||
<TextBlock Text="检查窗口(毫秒)" /><NumericUpDown Grid.Column="1" Value="{Binding AiCheckWindowMs, Mode=TwoWay}" Minimum="0" Maximum="60000" Increment="500" />
|
||||
<TextBlock Grid.Row="1" Text="最多检查次数" /><NumericUpDown Grid.Row="1" Grid.Column="1" Value="{Binding AiMaxChecks, Mode=TwoWay}" Minimum="1" Maximum="20" />
|
||||
<TextBlock Grid.Row="2" Text="停稳等待(毫秒)" /><NumericUpDown Grid.Row="2" Grid.Column="1" Value="{Binding AiCheckSettleMs, Mode=TwoWay}" Minimum="100" Maximum="3000" Increment="50" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<TextBlock Text="判定依据" />
|
||||
<ComboBox ItemsSource="{Binding AiEvidenceModes}" SelectedItem="{Binding AiEvidenceMode, Mode=TwoWay, Converter={StaticResource SelectionConverter}}">
|
||||
<ComboBox.ItemTemplate><DataTemplate><TextBlock Text="{Binding Converter={x:Static ed:VisionEvidenceModeLabels.Converter}}" /></DataTemplate></ComboBox.ItemTemplate>
|
||||
|
||||
@ -418,7 +418,8 @@ public partial class RecipeEditorViewModel
|
||||
var existing = index < _agentAppliedNodes.Count ? _agentAppliedNodes[index] : null;
|
||||
return new SopAgentImageScope(index + 1, existing?.AiImageMode ?? VisionImageMode.FixedRegion,
|
||||
existing?.AiImageRegion ?? (row.Step.Method == ConditionMethod.HandMove ? row.Step.ToRegion : row.Step.Region),
|
||||
existing?.AiHandPadding ?? 160, existing?.AiHandMinSize ?? 320, existing?.AiHandMemoryMs ?? 3000, existing?.AiEvidenceMode ?? VisionEvidenceMode.SingleFrame);
|
||||
existing?.AiHandPadding ?? 160, existing?.AiHandMinSize ?? 320, existing?.AiHandMemoryMs ?? 3000, existing?.AiEvidenceMode ?? VisionEvidenceMode.SingleFrame,
|
||||
existing?.AiCheckWindowMs ?? 0, existing?.AiMaxChecks ?? 3, existing?.AiCheckSettleMs ?? 350);
|
||||
}).ToArray();
|
||||
|
||||
private void ClearAgentConversation() { _agentPromptSession = null; _agentConversation.Clear(); AgentChatMessages.Clear(); }
|
||||
|
||||
@ -124,6 +124,7 @@
|
||||
<TextBlock Width="28" FontWeight="Bold" Foreground="{StaticResource FgDim}" Text="{Binding StepId, StringFormat={}{0}.}" />
|
||||
<TextBlock Width="140" Text="{Binding Name}" />
|
||||
<TextBlock Text="{Binding Message}" Foreground="{StaticResource FgDim}" TextTrimming="CharacterEllipsis" />
|
||||
<TextBlock Text="已跳过/未通过" Foreground="#D97706" IsVisible="{Binding IsSkipped}" Margin="8,0,0,0" />
|
||||
<Rectangle x:Name="dot" Width="8" Height="8" Margin="8,0,0,0" VerticalAlignment="Center" Fill="{StaticResource Ok}" Classes.state4="{Binding IsMet}" IsVisible="False" />
|
||||
</StackPanel>
|
||||
<TextBlock Text="{Binding ElapsedText, StringFormat=用时:{0}}" Foreground="{StaticResource FgDim}" FontSize="12" Margin="28,3,0,0" />
|
||||
|
||||
@ -128,7 +128,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
_engine.ViolationRaised += violation => _dispatcher.BeginInvoke(() => AppendViolation(violation));
|
||||
_engine.StepSnapshotChanged += OnStepSnapshot;
|
||||
_engine.RoundStarted += OnRoundStarted;
|
||||
_engine.Completed += OnCompleted;
|
||||
_engine.RoundFinished += OnRoundFinished;
|
||||
|
||||
LoadRecipes();
|
||||
|
||||
@ -441,7 +441,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
{
|
||||
_statisticsTimer.Stop();
|
||||
_engine.Stop();
|
||||
_engine.Completed -= OnCompleted;
|
||||
_engine.RoundFinished -= OnRoundFinished;
|
||||
_camera.FrameArrived -= OnCameraFrame;
|
||||
_pipeline.ResultFrameArrived -= OnResultFrame;
|
||||
_engine.StepSnapshotChanged -= OnStepSnapshot;
|
||||
@ -871,7 +871,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
else _dispatcher.BeginInvoke(() => { if (!_destroyed) { ClearProcessImages(); RefreshStatistics(); } });
|
||||
}
|
||||
|
||||
private void OnCompleted() => _dispatcher.BeginInvoke(() => { if (!_destroyed) { StatusText = "本轮完成"; RefreshStatistics(); } });
|
||||
private void OnRoundFinished(bool passed) => _dispatcher.BeginInvoke(() => { if (!_destroyed) { StatusText = passed ? "本轮完成,全部通过" : "本轮结束,有步骤未通过并跳过"; RefreshStatistics(); } });
|
||||
|
||||
private void RefreshStatistics()
|
||||
{
|
||||
@ -977,6 +977,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
|
||||
card.IsCurrent = snapshot.IsCurrent;
|
||||
card.IsMet = snapshot.IsMet;
|
||||
card.IsSkipped = snapshot.IsSkipped;
|
||||
card.Message = snapshot.Message;
|
||||
if (snapshot.Elapsed is { } elapsed) card.ElapsedText = FormatDuration(elapsed);
|
||||
using var aiEvidence = snapshot.IsMet && snapshot.EvidenceJpeg is { } jpeg
|
||||
@ -1079,7 +1080,8 @@ public class StepCard : ViewModelBase
|
||||
public bool IsWaitingForImage => !HasCompletionImage;
|
||||
|
||||
private bool _isCurrent;
|
||||
private bool _isMet;
|
||||
private bool _isMet, _isSkipped;
|
||||
public bool IsSkipped { get => _isSkipped; set => SetProperty(ref _isSkipped, value); }
|
||||
private string _message = "";
|
||||
|
||||
/// <summary>步骤 Id</summary>
|
||||
|
||||
@ -17,8 +17,8 @@ public partial class SopEngine
|
||||
ObservationMaxMs = Math.Max(step.AiConfirmation.ObservationMaxMs, step.AiConfirmation.CheckWindowMs),
|
||||
ObservationMaxFrames = step.AiConfirmation.ObservationMaxFrames,
|
||||
});
|
||||
public bool Triggered;
|
||||
public long LastFrame = -1, StartedAt, LastSubmittedAt, FinishedAt;
|
||||
public bool Triggered, SawQuiet;
|
||||
public long LastFrame = -1, SentFrame = -1, StartedAt, LastSubmittedAt, FinishedAt;
|
||||
public double TriggerSeconds, LatestSeconds, LastMotionSeconds;
|
||||
public int Attempts, SentVersion;
|
||||
public Dictionary<HandType, (double X, double Y)> Anchors = [];
|
||||
@ -39,6 +39,7 @@ public partial class SopEngine
|
||||
Func<byte[]>? capture, Func<RegionDef?, byte[]>? crop)
|
||||
{
|
||||
if (capture is null && crop is null || state.LastFrame == frame.FrameId) return;
|
||||
var firstObservation = state.LastFrame == -1;
|
||||
state.LastFrame = frame.FrameId;
|
||||
var seconds = frame.SourceSeconds ?? (frame.Timestamp - DateTime.UnixEpoch).TotalSeconds;
|
||||
state.LatestSeconds = seconds;
|
||||
@ -49,11 +50,20 @@ public partial class SopEngine
|
||||
_ => true,
|
||||
}).GroupBy(h => h.HandType).ToDictionary(g => g.Key, g => ((double)g.First().Center.Cx, (double)g.First().Center.Cy));
|
||||
var movement = Math.Max(1, Math.Sqrt((double)frame.Size.W * frame.Size.W + (double)frame.Size.H * frame.Size.H) * .01);
|
||||
if (selected.Count != state.Anchors.Count || selected.Any(h => !state.Anchors.TryGetValue(h.Key, out var prior)
|
||||
|| Math.Sqrt(Math.Pow(h.Value.Item1 - prior.X, 2) + Math.Pow(h.Value.Item2 - prior.Y, 2)) > movement))
|
||||
var moved = selected.Count != state.Anchors.Count || selected.Any(h => !state.Anchors.TryGetValue(h.Key, out var prior)
|
||||
|| Math.Sqrt(Math.Pow(h.Value.Item1 - prior.X, 2) + Math.Pow(h.Value.Item2 - prior.Y, 2)) > movement);
|
||||
if (!state.Triggered && state.Gate.RequireRelease && state.SawQuiet && moved && selected.Count > 0)
|
||||
{
|
||||
// 连续工序可以始终位于同一操作区;“停稳后重新运动”也是新动作边界。
|
||||
state.Gate.RequireRelease = false; state.Gate.Evaluator.Reset();
|
||||
Log("info", $"步骤 {state.Step.Id} 检测到停稳后的新运动,重新启用区域触发");
|
||||
}
|
||||
if (firstObservation || moved)
|
||||
{
|
||||
state.LastMotionSeconds = seconds; state.Anchors = selected;
|
||||
}
|
||||
else if ((seconds - state.LastMotionSeconds) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs)
|
||||
state.SawQuiet = true;
|
||||
var trigger = EvaluateCaptureGate(state.Step, frame, state.Gate, "continuous");
|
||||
if (!state.Triggered && trigger.IsMet)
|
||||
{
|
||||
@ -122,7 +132,15 @@ public partial class SopEngine
|
||||
var timeToCheck = state.Attempts == 0 ? quiet || sinceRequest >= interval : sinceRequest >= interval;
|
||||
var frames = state.Window.Frames.Where(f => !_acceptedEvidenceTimes.TryGetValue(_index - 1, out var prior)
|
||||
|| ObservationEvidenceWindow.Time(f) >= prior).ToArray();
|
||||
if (!timeToCheck || state.Window.Version <= state.SentVersion || frames.Length == 0
|
||||
if (!timeToCheck) return new() { Message = $"等待下一次检查时机(已送检 {state.Attempts}/{options.MaxChecks} 次)" };
|
||||
if (options.EvidenceMode == VisionEvidenceMode.SingleFrame && (capture is not null || crop is not null))
|
||||
{
|
||||
// 停稳事件可能处于抽样间隔之间;单帧检查必须取该事件当下的图。
|
||||
var current = CaptureDecision(step, frame, state.Gate.HandRegion, capture, crop, out _, notify: false);
|
||||
if (current is not null) frames = [new(frame.FrameId, frame.Timestamp, current.Request.Jpeg, frame.SourceSeconds)];
|
||||
}
|
||||
if (frames.Length == 0 || frames[^1].FrameId == state.SentFrame
|
||||
|| options.EvidenceMode == VisionEvidenceMode.Sequence && state.Window.Version <= state.SentVersion
|
||||
|| options.EvidenceMode == VisionEvidenceMode.Sequence && (frames.Length < 3 || !state.Window.Ready))
|
||||
return new() { Message = $"窗口内观察,优先在手部停稳或离开后检查(已送检 {state.Attempts}/{options.MaxChecks} 次)" };
|
||||
var last = frames[^1];
|
||||
@ -131,7 +149,7 @@ public partial class SopEngine
|
||||
options.EvidenceMode == VisionEvidenceMode.Sequence ? frames : null, last.SourceSeconds);
|
||||
var remaining = Math.Max(1, options.CheckWindowMs - state.ElapsedMs);
|
||||
var cancellation = new CancellationTokenSource(TimeSpan.FromMilliseconds(Math.Min(options.TimeoutSeconds * 1000d, remaining)));
|
||||
state.Attempts++; state.SentVersion = state.Window.Version; state.LastSubmittedAt = Environment.TickCount64;
|
||||
state.Attempts++; state.SentVersion = state.Window.Version; state.SentFrame = last.FrameId; state.LastSubmittedAt = Environment.TickCount64;
|
||||
state.FinishedAt = long.MaxValue;
|
||||
async Task<VisionDecisionResult> CheckAsync()
|
||||
{
|
||||
|
||||
@ -33,9 +33,11 @@ public static class VisionEvidenceMode
|
||||
public const string SingleFrame = "single_frame", Sequence = "sequence";
|
||||
public static bool IsCheckPolicyValid(AiConfirmation options) => options.CheckWindowMs == 0
|
||||
|| options.CheckWindowMs is >= 500 and <= 60000 && options.MaxChecks is >= 1 and <= 20
|
||||
&& options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs;
|
||||
&& options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs
|
||||
&& IsObservationValid(options);
|
||||
public static bool IsValid(AiConfirmation options) => options.EvidenceMode == SingleFrame
|
||||
|| options.EvidenceMode == Sequence && options.ObservationPreRollMs is >= 0 and <= 5000
|
||||
|| options.EvidenceMode == Sequence && IsObservationValid(options);
|
||||
private static bool IsObservationValid(AiConfirmation options) => options.ObservationPreRollMs is >= 0 and <= 5000
|
||||
&& options.ObservationMinMs is >= 200 and <= 30000 && options.ObservationMaxMs >= options.ObservationMinMs
|
||||
&& options.ObservationMaxMs <= 60000 && options.ObservationSampleMs is >= 100 and <= 2000
|
||||
&& options.ObservationMaxFrames is >= 3 and <= 32;
|
||||
|
||||
@ -5,7 +5,7 @@ using SopHelper.Engine.Sop;
|
||||
|
||||
namespace SopHelper.Engine.SopAgent;
|
||||
|
||||
public sealed record SopDraftVerificationStep(int Id, string Name, bool Completed, string Message);
|
||||
public sealed record SopDraftVerificationStep(int Id, string Name, bool Completed, string Message, bool Skipped = false);
|
||||
public sealed record SopDraftVerificationImage(int StepId, long FrameId, double Seconds, string Scope,
|
||||
double? Confidence, bool? Accepted, string Reason, [property: JsonIgnore] byte[] Jpeg,
|
||||
string EvidenceMode = VisionEvidenceMode.SingleFrame,
|
||||
|
||||
@ -15,6 +15,7 @@ public static class SopStepDesignPrompt
|
||||
- 相邻步骤应有可区分的可见变化,前一步结果不应直接满足后一步判据。
|
||||
|
||||
触发与取图:
|
||||
- step_image_context 的 CheckWindowMs>0 表示连续操作限时复检:事件开启窗口,优先在手停稳/离开后检查,失败使用新画面重试,到期未确认会记录未通过并跳过继续。跳过不等于完成;不能通过放宽判据来掩盖跳过,也不能要求操作员等待模型返回。手部触发区应对应本步实际操作,不宜扩大到无关动作区域。
|
||||
- method 只决定取图时机,不证明完成。选择结果已形成且关键部位尽量无遮挡的时机,不机械地统一规则。
|
||||
- hand_in_region:指定手中心在主区域内达到稳定帧数,停留时仍可重试;不能把进入区域当作完成证据。
|
||||
- hand_leave_region:先检测指定手接触主区域,再等区域内不再检测到匹配手。
|
||||
|
||||
@ -20,7 +20,7 @@ public sealed record SopVideoAnalysisRequest(string Recipe, string Instructions,
|
||||
public sealed record SopAgentPrompt(int Round, long EstimatedTokens, int ContextLength, string Compression, string Text);
|
||||
public sealed record SopAgentTrace(string Kind, int Round, string Text, IReadOnlyList<SopAgentTraceImage>? Images = null);
|
||||
public sealed record SopAgentTraceImage(string Name, byte[] Jpeg);
|
||||
public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame);
|
||||
public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int MaxChecks = 3, int CheckSettleMs = 350);
|
||||
public sealed record SopAgentChatTurn(string Role, string Text);
|
||||
public sealed record SopAgentChatResult(string Reply, SopVideoDraft? Draft, IReadOnlyList<SopVideoFrame> ObservedFrames);
|
||||
public sealed class SopVideoDraft
|
||||
|
||||
@ -49,12 +49,17 @@ internal static class Program
|
||||
{
|
||||
var config = new SopConfig();
|
||||
config.Sop.Steps.Add(new() { Id = 1, Description = "状态变化", AiConfirmation = new()
|
||||
{ EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationSampleMs = 300 } });
|
||||
{ EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationSampleMs = 300,
|
||||
CheckWindowMs = 7000, MaxChecks = 4, CheckSettleMs = 450 } });
|
||||
var editor = RecipeNode.From(config, "试验.yaml", false);
|
||||
Check(editor.Steps[0].UsesSequenceEvidence, "编辑器须识别过程时序模式");
|
||||
var restored = SopConfigLoader.Parse(SopConfigLoader.ToYaml(editor.ToConfig())).Sop.Steps[0].AiConfirmation!;
|
||||
Check(restored.EvidenceMode == VisionEvidenceMode.Sequence && restored.ObservationMinMs == 1800
|
||||
&& restored.ObservationMaxFrames == 13 && restored.ObservationSampleMs == 300, "编辑保存不得丢失时序模式与窗口参数");
|
||||
Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000 && restored.MaxChecks == 4
|
||||
&& restored.CheckSettleMs == 450, "编辑保存须保留连续操作限时复检参数");
|
||||
editor.Steps[0].AiContinueAfterWindow = false;
|
||||
Check(editor.ToConfig().Sop.Steps[0].AiConfirmation!.CheckWindowMs == 0, "关闭限时复检须恢复原等待策略");
|
||||
Console.WriteLine("PASS: 编辑器过程时序模式及观察参数往返保留");
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,8 @@ internal static class SequenceTrialChecks
|
||||
File.WriteAllText(Path.Combine(reportPath, "result.json"), JsonSerializer.Serialize(new
|
||||
{
|
||||
Config = configPath, Video = videoPath, StopSeconds = double.IsFinite(stopSeconds) ? (double?)stopSeconds : null,
|
||||
Completed = test.IsCompleted, Summary = summary, test.Details, Observed = observed, LatestSeconds = latestSeconds,
|
||||
Completed = test.IsCompleted, Finished = test.IsFinished, Steps = test.StepResults,
|
||||
Summary = summary, test.Details, Observed = observed, LatestSeconds = latestSeconds,
|
||||
WallSeconds = watch.Elapsed.TotalSeconds, Requests = requests, Verdicts = verdicts, Triggers = triggers,
|
||||
ConfigUnchanged = original.SequenceEqual(File.ReadAllBytes(configPath))
|
||||
}, new JsonSerializerOptions { WriteIndented = true }));
|
||||
|
||||
@ -77,6 +77,16 @@ internal static class ContinuousCheckTests
|
||||
timed.ProcessFrame(Frame(5, 2.1, 120)); await Until(() => slow.Calls.Count == 2);
|
||||
Check(timed.CurrentStep?.Id == 2 && timed.SkippedSteps.Contains(1), "已跳过步骤的迟到结果不能放行后续步骤");
|
||||
timed.Stop(); Check(!timed.HasPendingDecision, "停止必须取消限时检查和未来步骤缓存");
|
||||
var sameRegion = Config(); sameRegion.Sop.Steps[1].Detection!.Region = "r0";
|
||||
var same = new SopEngine { VisionDecisionClient = new Client() }; same.Load(sameRegion); same.Start();
|
||||
var secondTriggered = false;
|
||||
same.TriggerEvaluated += (id, _, result, _) => { if (id == 2 && result.IsMet) secondTriggered = true; };
|
||||
void SameFeed(int id, double seconds, int x) => same.ProcessFrame(Frame(id, seconds, x), () => [(byte)id]);
|
||||
SameFeed(1, 0, 10); SameFeed(2, .1, 10); SameFeed(3, .3, 10);
|
||||
Check(!secondTriggered, "同区域持续停留不得直接触发下一步");
|
||||
SameFeed(4, .5, 35);
|
||||
Check(secondTriggered, "同区域停稳后开始新运动,应能触发下一步,不能强求手离开操作区");
|
||||
same.Stop();
|
||||
Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user