-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObsidianLethePlugin.cs
More file actions
55 lines (50 loc) · 2.13 KB
/
Copy pathObsidianLethePlugin.cs
File metadata and controls
55 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using LetheAISharp.Agent;
using LetheAISharp.LLM;
using Microsoft.Extensions.Logging;
using ObsidianToolset.Files;
using System.Reflection;
namespace ObsidianToolset
{
public sealed class ObsidianLethePlugin : IPluginEntry
{
public static ObsidianSettings Settings { get; private set; } = new();
public void Register()
{
LLMEngine.Logger?.LogInformation("w(ai)fu Plugin: entry point invoked.");
// get the plugin directory (the directory where the DLL is located)
var pluginDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (pluginDir == null)
{
LLMEngine.Logger?.LogError("Failed to determine plugin directory for ObsidianLethePlugin.");
return;
}
// check if settings file exists in the plugin directory
var settingsPath = Path.Combine(pluginDir, "ObsidianToolset.json");
if (!File.Exists(settingsPath))
{
LLMEngine.Logger?.LogError("ObsidianToolset.json file not found for ObsidianLethePlugin. File created, but you need to edit it to specify your Obsidian vault path.");
// create file
var defaultSettings = new ObsidianSettings()
{
VaultPath = string.Empty
};
File.WriteAllText(settingsPath, System.Text.Json.JsonSerializer.Serialize(defaultSettings, new System.Text.Json.JsonSerializerOptions() { WriteIndented = true }));
return;
}
// read settings
var settingsJson = File.ReadAllText(settingsPath);
try
{
var settings = System.Text.Json.JsonSerializer.Deserialize<ObsidianSettings>(settingsJson);
if (settings != null)
{
Settings = settings;
}
}
catch (Exception ex)
{
LLMEngine.Logger?.LogError("Failed to deserialize ObsidianToolset.json for ObsidianLethePlugin. Exception: {mess}", ex.Message);
}
}
}
}