Skip to content

Commit 7df0b3e

Browse files
Refactored plugin settings handling for maintainability (#515)
1 parent 1b8ed28 commit 7df0b3e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

app/MindWork AI Studio/Settings/SettingsManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using System.Linq.Expressions;
23
using System.Text.Json;
34

45
using AIStudio.Provider;
@@ -347,4 +348,21 @@ public ConfidenceLevel GetConfiguredConfidenceLevel(LLMProviders llmProvider)
347348
return ConfidenceLevel.UNKNOWN;
348349
}
349350
}
351+
352+
public static string ToSettingName<T>(Expression<Func<T, object>> propertyExpression)
353+
{
354+
MemberExpression? memberExpr;
355+
356+
// Handle the case where the expression is a unary expression (e.g., when using Convert):
357+
if (propertyExpression.Body is UnaryExpression { NodeType: ExpressionType.Convert } unaryExpr)
358+
memberExpr = unaryExpr.Operand as MemberExpression;
359+
else
360+
memberExpr = propertyExpression.Body as MemberExpression;
361+
362+
if (memberExpr is null)
363+
throw new ArgumentException("Expression must be a property access", nameof(propertyExpression));
364+
365+
// Return the full name of the property, including the class name:
366+
return $"{typeof(T).Name}.{memberExpr.Member.Name}";
367+
}
350368
}

app/MindWork AI Studio/Tools/PluginSystem/PluginConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private bool TryProcessConfiguration(out string message)
4848
return false;
4949
}
5050

51-
if (settingsTable.TryGetValue("DataApp.UpdateBehavior", out var updateBehaviorValue) && updateBehaviorValue.TryRead<string>(out var updateBehaviorText) && Enum.TryParse<UpdateBehavior>(updateBehaviorText, true, out var updateBehavior))
51+
if (settingsTable.TryGetValue(SettingsManager.ToSettingName<DataApp>(x => x.UpdateBehavior), out var updateBehaviorValue) && updateBehaviorValue.TryRead<string>(out var updateBehaviorText) && Enum.TryParse<UpdateBehavior>(updateBehaviorText, true, out var updateBehavior))
5252
{
5353
SETTINGS_LOCKER.Register<DataApp>(x => x.UpdateBehavior, this.Id);
5454
SETTINGS_MANAGER.ConfigurationData.App.UpdateBehavior = updateBehavior;

app/MindWork AI Studio/wwwroot/changelog/v0.9.49.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Added a library by Nils Kruthoff (`nilskruthoff`) that allows AI Studio to read PowerPoint files. This feature is not yet available in the UI, but it will soon be available. Thanks, Nils, for that great contribution.
33
- Improved the loading of some components that require data fetching, resulting in a more responsive UI.
44
- Improved some awkward phrasings in English and German.
5+
- Improved the implementation of configuration plugins to enhance long-term maintainability.
56
- Changed the timestamp display to use the local datetime format for the chats and assistants.
67
- Fixed a bug when editing data sources that caused the selected retrieval process of an ERI data source to not load correctly.
78
- Upgraded to Rust 1.88.0.

0 commit comments

Comments
 (0)