using Avalonia.Controls; using Avalonia.Threading; using Avalonia.VisualTree; using OpenCvSharp; using Prism.Dialogs; using SopHelper.Engine.Sop; using SopHelper.Engine.SopAgent; using SopHelper.Engine.Recipes; using SopHelper.SopVideo; using SopHelper.VVMs.RecipeEditor; using Window = Avalonia.Controls.Window; internal static class AgentDraftGenerationChecks { public static void Run(string root) { var store = new RecipeWorkspace(root); Directory.CreateDirectory(root); var video = Path.Combine(root, "agent-generation.avi"); using (var writer = new VideoWriter(video, FourCC.MJPG, 10, new OpenCvSharp.Size(64, 48))) { Check(writer.IsOpened(), "Agent generation test video opens"); for (var i = 0; i < 20; i++) { using var image = new Mat(48, 64, MatType.CV_8UC3, new Scalar(20, 50, 100)); writer.Write(image); } } var config = new SopConfig(); config.Sop.Name = "代理草稿生成"; config.Sop.Parts = []; ReferenceEvidenceChecks.Run(video); config.Sop.Regions["work"] = new() { X2 = 64, Y2 = 48 }; config.Sop.Steps = [new() { Id = 1, Name = "保留人工步骤", Description = "人工要求" }]; Directory.CreateDirectory(Path.Combine(root,"workspace")); File.WriteAllText(Path.Combine(root,"workspace","sop-agent.json"),"{\"endpoint\":\"http://127.0.0.1:1/v1\",\"model\":\"unit-test\",\"autoVerify\":true}"); var model = new RecipeEditorViewModel(); var client = new ProbeClient(); model.AgentClient = client; model.OnDialogOpened(new DialogParameters { { "directory", store.RecipesDirectory }, { "config", config }, { "new", true } }); model.SaveCommand.Execute(); var path = store.ConfigPath(config.Sop.Name); var before = File.ReadAllBytes(path); model.AgentVideoPath = video; model.AgentEndpoint = "http://127.0.0.1:1/v1"; model.AgentModel = "unit-test"; model.AgentSequenceEnableThinking = false; model.AgentEnableThinking = false; using (var saved = System.Text.Json.JsonDocument.Parse(File.ReadAllText(Path.Combine(root, "workspace", "sop-agent.json")))) Check(!saved.RootElement.GetProperty("sequenceEnableThinking").GetBoolean() && !saved.RootElement.GetProperty("enableThinking").GetBoolean(), "Agent与时序思考设置须可持久化,便于复现实测参数"); var view = new RecipeEditor { DataContext = model }; var window = new Window { Width = 1040, Height = 900, Content = view }; window.Show(); window.UpdateLayout(); var tabs = view.GetVisualDescendants().OfType().Single(); tabs.SelectedItem = tabs.Items.OfType().Single(t => t.Header?.ToString() == "Agent助手"); window.UpdateLayout(); Check(view.FindControl