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
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@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);