启动步骤生成或优化时清空助手日志和会话
This commit is contained in:
parent
71419847c0
commit
32bc36b723
@ -26,7 +26,7 @@ public partial class RecipeEditorViewModel
|
||||
/// <summary>保留原说明并生成九条同义候选,使用相同送检图逐条测试;仅当配方快照仍一致时批量回写。</summary>
|
||||
private async Task OptimizeStepsAsync()
|
||||
{
|
||||
if (IsAgentBusy || IsTestingStep || IsCapturing || _agentClosed) return;
|
||||
if (!CanStartAgentStepTask()) return;
|
||||
var recipe = Recipe;
|
||||
var recipeName = recipe.Name;
|
||||
var config = recipe.ToConfig();
|
||||
@ -51,7 +51,7 @@ public partial class RecipeEditorViewModel
|
||||
_agentCancellation = cancellation;
|
||||
var token = cancellation.Token;
|
||||
IsAgentBusy = true;
|
||||
ClearOptimizationReports();
|
||||
ResetAgentStepTaskHistory();
|
||||
var results = new List<(StepNode Node, string Description)>();
|
||||
var unchanged = 0;
|
||||
try
|
||||
|
||||
@ -102,8 +102,8 @@ public partial class RecipeEditorViewModel
|
||||
|
||||
private void InitializeAgentCommands()
|
||||
{
|
||||
OptimizeStepsCommand = new DelegateCommand(() => _agentTask = OptimizeStepsAsync(), () => !IsAgentBusy && !IsTestingStep && !IsCapturing && !_agentClosed);
|
||||
GenerateStepsCommand = new DelegateCommand(() => _agentTask = AnalyzeVideoAsync(), () => !IsAgentBusy && !IsCapturing);
|
||||
OptimizeStepsCommand = new DelegateCommand(() => _agentTask = OptimizeStepsAsync(), CanStartAgentStepTask);
|
||||
GenerateStepsCommand = new DelegateCommand(() => _agentTask = AnalyzeVideoAsync(), CanStartAgentStepTask);
|
||||
SendAgentChatCommand = new DelegateCommand(() => _agentTask = AnalyzeVideoAsync(AgentChatInput.Trim()),
|
||||
() => !IsAgentBusy && !IsCapturing && !string.IsNullOrWhiteSpace(AgentChatInput));
|
||||
ClearAgentChatCommand = new DelegateCommand(ClearAgentConversation, () => !IsAgentBusy);
|
||||
@ -234,7 +234,7 @@ public partial class RecipeEditorViewModel
|
||||
/// <summary>以当前配方和视频构造 Agent 请求,维护聊天及草稿状态,并支持取消。</summary>
|
||||
private async Task AnalyzeVideoAsync(string? userMessage = null)
|
||||
{
|
||||
if (IsAgentBusy || IsCapturing) return;
|
||||
if (IsAgentBusy || IsCapturing || _agentClosed || (userMessage is null && IsTestingStep)) return;
|
||||
if (SopRecording?.IsRecording == true) { AgentStatus = "请先停止并保存 SOP 录像,再开始分析。"; return; }
|
||||
if (!File.Exists(AgentVideoPath)) { AgentStatus = "请先录制标准 SOP 视频,或选择已有视频。"; return; }
|
||||
if (!Uri.TryCreate(AgentEndpoint.Trim(), UriKind.Absolute, out var endpoint) || endpoint.Scheme is not ("http" or "https")
|
||||
@ -252,6 +252,7 @@ public partial class RecipeEditorViewModel
|
||||
_agentCancellation = new CancellationTokenSource();
|
||||
var token = _agentCancellation.Token;
|
||||
IsAgentBusy = true;
|
||||
if (userMessage is null) ResetAgentStepTaskHistory();
|
||||
AgentStatus = "正在读取标准 SOP 视频…";
|
||||
var activeAnalysis = _agentCancellation;
|
||||
SopAgentRunLog? runLog = null;
|
||||
@ -325,7 +326,7 @@ public partial class RecipeEditorViewModel
|
||||
}
|
||||
else AgentStatus = "";
|
||||
_agentSample = sample;
|
||||
if (userMessage is null) { _agentConversation.Clear(); _agentConversation.Add(new("assistant", reply)); }
|
||||
if (userMessage is null) _agentConversation.Add(new("assistant", reply));
|
||||
AgentChatMessages.Add(new("Agent", reply));
|
||||
}
|
||||
catch (OperationCanceledException error)
|
||||
@ -467,6 +468,18 @@ public partial class RecipeEditorViewModel
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>等待单步测试结束后再启动,避免旧测试把结果追加到清空后的日志。</summary>
|
||||
private bool CanStartAgentStepTask() => !IsAgentBusy && !IsTestingStep && !IsCapturing && !_agentClosed;
|
||||
|
||||
/// <summary>新任务通过校验后清空旧对话、界面判定日志及优化报告,后续聊天使用本次上下文。</summary>
|
||||
private void ResetAgentStepTaskHistory()
|
||||
{
|
||||
ClearAgentConversation();
|
||||
StepDecisionLog = "";
|
||||
ClearOptimizationReports();
|
||||
}
|
||||
|
||||
/// <summary>清空对话上下文和显示记录,使已排队的旧提示词回调失效。</summary>
|
||||
private void ClearAgentConversation() { _agentPromptSession = null; _agentConversation.Clear(); AgentChatMessages.Clear(); }
|
||||
|
||||
private void ClearAgentDraft(bool clearConversation = true, bool forgetApplied = true)
|
||||
|
||||
@ -21,6 +21,7 @@ public partial class RecipeEditorViewModel
|
||||
if (SetProperty(ref _isTestingStep, value))
|
||||
{
|
||||
TestStepDecisionCommand.RaiseCanExecuteChanged();
|
||||
GenerateStepsCommand?.RaiseCanExecuteChanged();
|
||||
OptimizeStepsCommand?.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,11 +70,19 @@ internal static class AgentDraftGenerationChecks
|
||||
&& !logText.Contains("verification_start") && logText.Contains("session_end"), "Generation logs finish without starting local verification");
|
||||
Check(Directory.GetFiles(Path.ChangeExtension(savedLog, null) + "-images", "*.jpg").Length == 1,
|
||||
"Actual model image evidence is saved beside the analysis log");
|
||||
// 单步测试的缺关键帧提示会写入界面日志,用于验证聊天和重新生成的清理边界。
|
||||
model.Recipe.SelectedStep = model.Recipe.Steps.Single();
|
||||
model.TestStepDecisionCommand.Execute();
|
||||
var previousDecisionLog = model.StepDecisionLog;
|
||||
model.AgentChatInput="保留当前工艺要求,润色说明";model.SendAgentChatCommand.Execute();Until(()=>!model.IsAgentBusy);
|
||||
Check(!client.SawVerification&&client.SawCurrentDraft&&!client.SawDirectVerification&&model.ApplyAgentDraftCommand.CanExecute(),"Ordinary chat edits the current draft without running verification");
|
||||
Check(previousDecisionLog.Length > 0 && model.StepDecisionLog == previousDecisionLog
|
||||
&& model.AgentChatMessages.Any(m => m.Text.Contains(savedLog)), "继续聊天保留本轮对话及判定日志");
|
||||
model.AgentApiKey = "never-show-secret";
|
||||
client.Failure = new System.Net.Http.HttpRequestException("连接重置 Bearer never-show-secret data:image/jpeg;base64,AAAA");
|
||||
model.GenerateStepsCommand.Execute(); Until(() => !model.IsAgentBusy);
|
||||
Check(model.StepDecisionLog.Length == 0 && model.AgentChatMessages.All(m => m.Speaker != "我" && !m.Text.Contains(savedLog))
|
||||
&& model.AgentChatMessages.Count(m => m.Speaker == "分析日志") == 1, "重新生成从空日志和空对话开始,保留本次诊断");
|
||||
Check(model.AgentStatus.Contains("模型接口连接失败") && model.AgentStatus.Contains("连接重置")
|
||||
&& !model.AgentStatus.Contains("never-show-secret") && !model.AgentStatus.Contains("AAAA"), "Actual network cause is visible while credentials and image bytes are hidden");
|
||||
var diagnostics = Directory.GetFiles(Path.Combine(root, "workspace", "agent-diagnostics"), "error-*.json").Select(File.ReadAllText).ToArray();
|
||||
|
||||
@ -10,6 +10,9 @@ internal static class OptimizeStepsChecks
|
||||
public static void Run()
|
||||
{
|
||||
CheckRewriteProtocolAsync().GetAwaiter().GetResult();
|
||||
// 独立运行优化测试时,在临时工作区建立有权设置模型的账号。
|
||||
var access = SopHelper.Models.UserAccess.Current;
|
||||
if (access.NeedsSetup) access.Setup("optimization-smoke-admin", "OptimizationSmokePassword123");
|
||||
var model = new RecipeEditorViewModel { AgentEndpoint = "http://127.0.0.1:1/v1", AgentModel = "test" };
|
||||
model.OptimizeStepsCommand.Execute();
|
||||
Check(model.AgentStatus.Contains("没有"), "空配方不优化");
|
||||
@ -59,6 +62,9 @@ internal static class OptimizeStepsChecks
|
||||
decisions = new Decisions { Invalid = true }; model.StepTestDecisionClient = decisions;
|
||||
var retained = first.Description;
|
||||
model.OptimizeStepsCommand.Execute(); Until(() => !model.IsAgentBusy);
|
||||
// 两轮判定返回不同原因,检查第二轮只展示自己的日志和候选。
|
||||
Check(model.StepDecisionLog.Contains("异常") && !model.StepDecisionLog.Contains("测试结果")
|
||||
&& model.AgentChatMessages.Count(m => m.Text.Contains("10 · 同义改写")) == 2, "重新优化清空上一轮的判定日志和对话记录");
|
||||
Check(first.Description == retained && decisions.Requests.Count == 20, "所有测试无效保留原说明");
|
||||
Check(model.OptimizationReports.Count == 2 && model.OptimizationReports.All(r => r.Text.Contains("无有效分数")
|
||||
&& !r.Text.Contains("★")), "异常结果公开且不标记为选中");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user