From 8dfbdb02b6e35d7b59dd18392bf713eae487bef0 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Mon, 16 Oct 2023 00:10:46 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E8=AF=AD=E6=B3=95=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E7=95=8C=E9=9D=A2=20=E8=AF=AD=E6=B3=95=E7=83=AD?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/Pages/Editor.razor | 78 ++++++++++++++++++- Frontend/Pages/Editor.razor.css | 12 ++- Frontend/Pages/Index.razor | 17 ---- Frontend/Shared/MainLayout.razor | 8 +- Frontend/wwwroot/css/site.css | 3 +- Katheryne/ServiceCollectionExtensions.cs | 2 +- .../Services/KatheryneChatRobotFactory.cs | 3 + 7 files changed, 100 insertions(+), 23 deletions(-) diff --git a/Frontend/Pages/Editor.razor b/Frontend/Pages/Editor.razor index 18d233f..9e2862a 100644 --- a/Frontend/Pages/Editor.razor +++ b/Frontend/Pages/Editor.razor @@ -1,19 +1,93 @@ @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" + 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(); + } + } \ No newline at end of file diff --git a/Frontend/Pages/Editor.razor.css b/Frontend/Pages/Editor.razor.css index 9c7bb11..d357ec7 100644 --- a/Frontend/Pages/Editor.razor.css +++ b/Frontend/Pages/Editor.razor.css @@ -1,3 +1,13 @@ .editor-zone { - min-height: calc(100vh - 64px); + height: calc(100vh - 64px); +} + +.control-zone { + height: 5%; + padding: 2px; +} + +.logging-zone { + height: 15%; + overflow-y: auto; } \ No newline at end of file diff --git a/Frontend/Pages/Index.razor b/Frontend/Pages/Index.razor index 6c398df..a502275 100644 --- a/Frontend/Pages/Index.razor +++ b/Frontend/Pages/Index.razor @@ -51,23 +51,6 @@ protected override void OnInitialized() { - ChatRobotFactory.SetGrammar(@" - robotName: 凯瑟琳 - stages: - - name: start - answer: 向着星辰和深渊!欢迎来到冒险家协会。 - transformers: - - pattern: .*? - nextStageName: running - - - name: running - answer: 对不起,做不到。 - transformers: - - pattern: .*? - nextStageName: running - beginStageName: start - "); - Chat chat = GetInitChat(); _chatDictionary.Add(chat.Guid, chat); _currentGuid = chat.Guid; diff --git a/Frontend/Shared/MainLayout.razor b/Frontend/Shared/MainLayout.razor index 44f3ae0..a4efa78 100644 --- a/Frontend/Shared/MainLayout.razor +++ b/Frontend/Shared/MainLayout.razor @@ -9,12 +9,18 @@ 试作自律型可重编程客服机器人

- +

a.k.a 凯瑟琳

+ + +
+ 维护界面 +
+
diff --git a/Frontend/wwwroot/css/site.css b/Frontend/wwwroot/css/site.css index 53dbdcb..95ba2b0 100644 --- a/Frontend/wwwroot/css/site.css +++ b/Frontend/wwwroot/css/site.css @@ -32,5 +32,6 @@ body { } .monaco-editor-container { - min-height: 100%; + min-height: 80%; + margin: 5px; } diff --git a/Katheryne/ServiceCollectionExtensions.cs b/Katheryne/ServiceCollectionExtensions.cs index d97bbe8..e4bbd1c 100644 --- a/Katheryne/ServiceCollectionExtensions.cs +++ b/Katheryne/ServiceCollectionExtensions.cs @@ -9,6 +9,6 @@ public static class ServiceCollectionExtensions { collection.AddSingleton(); collection.AddSingleton(); - collection.AddScoped(); + collection.AddSingleton(); } } \ No newline at end of file diff --git a/Katheryne/Services/KatheryneChatRobotFactory.cs b/Katheryne/Services/KatheryneChatRobotFactory.cs index dcfedd3..2d31c87 100644 --- a/Katheryne/Services/KatheryneChatRobotFactory.cs +++ b/Katheryne/Services/KatheryneChatRobotFactory.cs @@ -14,6 +14,8 @@ public class KatheryneChatRobotFactory private Grammar? _grammar; + public string GrammarText { get; private set; } = string.Empty; + public KatheryneChatRobotFactory(YamlDeserializerFactory deserializerFactory, ILogger factoryLogger, ILogger robotLogger, @@ -28,6 +30,7 @@ public class KatheryneChatRobotFactory public void SetGrammar(string grammarText) { _factoryLogger.LogInformation("Receive new grammar: {}.", grammarText); + GrammarText = grammarText; IDeserializer deserializer = _deserializerFactory.GetDeserializer(); LexicalModel model = deserializer.Deserialize(grammarText);