@page "/editor" @using Katheryne.Services @using Katheryne.Exceptions @inject NavigationManager Navigation @inject KatheryneChatRobotFactory RobotFactory

@context

@code { private StandaloneCodeEditor _editor = null!; private AntList _logList = null!; private readonly List _logs = new(); protected override async Task OnInitializedAsync() { Log("编辑器加载完成"); await base.OnInitializedAsync(); } private StandaloneEditorConstructionOptions GetEditorConstructionOptions(StandaloneCodeEditor editor) { string grammarText; if (!string.IsNullOrEmpty(RobotFactory.GrammarText)) { Log("加载文法..."); grammarText = RobotFactory.GrammarText; } else { Log("未设置文法"); grammarText = string.Empty; } return new StandaloneEditorConstructionOptions { Language = "yaml", Value = grammarText }; } private async Task CompileGrammarClicked() { string grammarText = await _editor.GetValue(); try { Log("编译文法..."); RobotFactory.SetGrammar(grammarText); Log("编译成功!"); } catch (GrammarException e) { Log($"编译文法遇到错误:{e.Message}"); } } private void Log(string message) { _logs.Add($"{DateTime.Now:HH:mm:ss} {message}"); StateHasChanged(); } }