mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-21 21:32:15 +00:00
encapulated the audit logic into a service to reuse it
This commit is contained in:
parent
3fe8300daa
commit
b6a174929a
@ -21,7 +21,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
|
|||||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
private AssistantAuditAgent AuditAgent { get; init; } = null!;
|
private AssistantPluginAuditService AssistantPluginAuditService { get; init; } = null!;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
private IDialogService DialogService { get; init; } = null!;
|
private IDialogService DialogService { get; init; } = null!;
|
||||||
@ -96,22 +96,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await this.AuditAgent.AuditAsync(this.plugin);
|
this.audit = await this.AssistantPluginAuditService.RunAuditAsync(this.plugin);
|
||||||
this.audit = new PluginAssistantAudit
|
|
||||||
{
|
|
||||||
PluginId = this.plugin.Id,
|
|
||||||
PluginHash = this.plugin.ComputeAuditHash(),
|
|
||||||
AuditedAtUtc = DateTimeOffset.UtcNow,
|
|
||||||
AuditProviderId = this.CurrentProvider.Id,
|
|
||||||
AuditProviderName = this.CurrentProvider == AIStudio.Settings.Provider.NONE
|
|
||||||
? string.Empty
|
|
||||||
: this.CurrentProvider.InstanceName,
|
|
||||||
Level = AssistantAuditLevelExtensions.Parse(result.Level),
|
|
||||||
Summary = result.Summary,
|
|
||||||
Confidence = result.Confidence,
|
|
||||||
PromptPreview = this.promptPreview,
|
|
||||||
Findings = result.Findings,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1030,10 +1030,6 @@ Use `LAYOUT_ACCORDION` as the outer wrapper and put the actual content into one
|
|||||||
- [Bitwise Operations Library](https://www.lua.org/manual/5.2/manual.html#6.7)
|
- [Bitwise Operations Library](https://www.lua.org/manual/5.2/manual.html#6.7)
|
||||||
---
|
---
|
||||||
|
|
||||||
> **Warning:** some common lua functions might not be available in this lua environment. Examples are:
|
|
||||||
> 1. `tostring()`
|
|
||||||
> 2. `pairs()`\\`ipairs()`
|
|
||||||
|
|
||||||
### Logging helpers
|
### Logging helpers
|
||||||
The assistant runtime exposes basic logging helpers to Lua. Use them to debug custom prompt building.
|
The assistant runtime exposes basic logging helpers to Lua. Use them to debug custom prompt building.
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,32 @@
|
|||||||
|
using AIStudio.Agents.AssistantAudit;
|
||||||
|
|
||||||
|
namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs an assistant security audit and maps the agent result to the persisted audit model.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AssistantPluginAuditService(AssistantAuditAgent auditAgent)
|
||||||
|
{
|
||||||
|
public async Task<PluginAssistantAudit> RunAuditAsync(PluginAssistants plugin, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var result = await auditAgent.AuditAsync(plugin, token);
|
||||||
|
var provider = auditAgent.ProviderSettings;
|
||||||
|
var promptPreview = await plugin.BuildAuditPromptPreviewAsync(token);
|
||||||
|
|
||||||
|
return new PluginAssistantAudit
|
||||||
|
{
|
||||||
|
PluginId = plugin.Id,
|
||||||
|
PluginHash = plugin.ComputeAuditHash(),
|
||||||
|
AuditedAtUtc = DateTimeOffset.UtcNow,
|
||||||
|
AuditProviderId = provider.Id,
|
||||||
|
AuditProviderName = provider == AIStudio.Settings.Provider.NONE
|
||||||
|
? string.Empty
|
||||||
|
: provider.InstanceName,
|
||||||
|
Level = AssistantAuditLevelExtensions.Parse(result.Level),
|
||||||
|
Summary = result.Summary,
|
||||||
|
Confidence = result.Confidence,
|
||||||
|
PromptPreview = promptPreview,
|
||||||
|
Findings = result.Findings,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -73,7 +73,7 @@ public static class PluginAssistantSecurityResolver
|
|||||||
var auditSettings = settingsManager.ConfigurationData.AssistantPluginAudit;
|
var auditSettings = settingsManager.ConfigurationData.AssistantPluginAudit;
|
||||||
var currentHash = plugin.ComputeAuditHash();
|
var currentHash = plugin.ComputeAuditHash();
|
||||||
var audit = settingsManager.ConfigurationData.AssistantPluginAudits.FirstOrDefault(x => x.PluginId == plugin.Id);
|
var audit = settingsManager.ConfigurationData.AssistantPluginAudits.FirstOrDefault(x => x.PluginId == plugin.Id);
|
||||||
var hasAudit = audit is not null;
|
var hasAudit = audit is not null && audit.Level is not AssistantAuditLevel.UNKNOWN;
|
||||||
var hashMatches = hasAudit && string.Equals(audit!.PluginHash, currentHash, StringComparison.Ordinal);
|
var hashMatches = hasAudit && string.Equals(audit!.PluginHash, currentHash, StringComparison.Ordinal);
|
||||||
var hasHashMismatch = hasAudit && !hashMatches;
|
var hasHashMismatch = hasAudit && !hashMatches;
|
||||||
var isBelowMinimum = hashMatches && audit is not null && audit.Level < auditSettings.MinimumLevel;
|
var isBelowMinimum = hashMatches && audit is not null && audit.Level < auditSettings.MinimumLevel;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user