Ship Assistent 0.10: settings panel and UserPrefs with prompt weight.
Separate About-the-user memory (global + per-persona) from craft RAG, add tabbed settings with persona export/import and craft clear APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SwarmUI.Accounts;
|
||||
|
||||
namespace Mrleo1nid.SwarmAssistent;
|
||||
|
||||
/// <summary>CRUD for About-the-user preferences (global + per-persona).</summary>
|
||||
public partial class SwarmAssistentExtension
|
||||
{
|
||||
public async Task<JObject> AssistentListUserPrefs(Session session, string scope = null, string persona = null, int limit = 200)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
if (Memory is null)
|
||||
{
|
||||
return new JObject { ["error"] = "memory not ready" };
|
||||
}
|
||||
try
|
||||
{
|
||||
string pid = AssistentConfig.SafeId(persona) ?? Config?.DefaultPersonaId() ?? "neutral";
|
||||
JArray rows = Memory.ListUserPrefs(scope, pid, limit);
|
||||
return new JObject
|
||||
{
|
||||
["success"] = true,
|
||||
["prefs"] = rows,
|
||||
["total"] = Memory.CountUserPrefs(),
|
||||
["persona"] = pid,
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JObject { ["error"] = $"user prefs list: {ex.Message}" };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<JObject> AssistentUpsertUserPref(Session session, string key, string text, string scope = "global", string persona = null, string source = "user", bool pinned = false)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
if (Memory is null)
|
||||
{
|
||||
return new JObject { ["error"] = "memory not ready" };
|
||||
}
|
||||
try
|
||||
{
|
||||
string pid = AssistentConfig.SafeId(persona) ?? Config?.DefaultPersonaId() ?? "neutral";
|
||||
JObject row = Memory.UpsertUserPref(key, text, scope, pid, source, pinned);
|
||||
return new JObject { ["success"] = true, ["pref"] = row };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JObject { ["error"] = $"user pref upsert: {ex.Message}" };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<JObject> AssistentForgetUserPref(Session session, string key, string scope = "global", string persona = null)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
if (Memory is null)
|
||||
{
|
||||
return new JObject { ["error"] = "memory not ready" };
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
return new JObject { ["error"] = "key required" };
|
||||
}
|
||||
try
|
||||
{
|
||||
string pid = AssistentConfig.SafeId(persona) ?? Config?.DefaultPersonaId() ?? "neutral";
|
||||
bool ok = Memory.ForgetUserPref(key, scope, pid);
|
||||
return new JObject { ["success"] = ok, ["key"] = key.Trim(), ["scope"] = scope };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JObject { ["error"] = $"user pref forget: {ex.Message}" };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<JObject> AssistentClearUserPrefs(Session session, string scope = "all", string persona = null)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
if (Memory is null)
|
||||
{
|
||||
return new JObject { ["error"] = "memory not ready" };
|
||||
}
|
||||
try
|
||||
{
|
||||
string pid = AssistentConfig.SafeId(persona) ?? Config?.DefaultPersonaId() ?? "neutral";
|
||||
int n = Memory.ClearUserPrefs(scope, pid);
|
||||
return new JObject { ["success"] = true, ["deleted"] = n, ["scope"] = scope ?? "all" };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JObject { ["error"] = $"user prefs clear: {ex.Message}" };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user