Add Leonid as a shelf-based example with preference_bias slider; support /persona new clone-to-overlay and UI-only delete. Co-authored-by: Cursor <cursoragent@cursor.com>
143 lines
4.8 KiB
C#
143 lines
4.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json.Linq;
|
|
using SwarmUI.Accounts;
|
|
using SwarmUI.Utils;
|
|
|
|
namespace Mrleo1nid.SwarmAssistent;
|
|
|
|
/// <summary>Persona overlay CRUD: controls Exact, clone/write shelves, UI-only delete.</summary>
|
|
public partial class SwarmAssistentExtension
|
|
{
|
|
public async Task<JObject> AssistentSaveControls(Session session, string persona = null, JObject controls = null)
|
|
{
|
|
await Task.CompletedTask;
|
|
string pid = AssistentConfig.SafeId(persona) ?? Config.DefaultPersonaId();
|
|
try
|
|
{
|
|
JObject saved = Config.SaveControlValues(pid, controls ?? new JObject());
|
|
return new JObject
|
|
{
|
|
["success"] = true,
|
|
["persona"] = pid,
|
|
["control_values"] = saved,
|
|
["controls"] = Config.LoadControlsSchema(pid),
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JObject { ["error"] = $"controls save: {ex.Message}" };
|
|
}
|
|
}
|
|
|
|
public async Task<JObject> AssistentGetPersonaShelves(Session session, string persona = null)
|
|
{
|
|
await Task.CompletedTask;
|
|
string pid = AssistentConfig.SafeId(persona) ?? Config.DefaultPersonaId();
|
|
return new JObject
|
|
{
|
|
["success"] = true,
|
|
["persona"] = pid,
|
|
["source"] = Config.PersonaSource(pid),
|
|
["shelves"] = Config.LoadIdentityParts(pid),
|
|
["controls"] = Config.LoadControlsSchema(pid),
|
|
["control_values"] = Config.LoadControlValues(pid),
|
|
["identity_summary"] = Config.RenderIdentityBlock(pid),
|
|
};
|
|
}
|
|
|
|
public async Task<JObject> AssistentClonePersona(Session session, string from = null, string to = null, string title = null, bool overwrite = false)
|
|
{
|
|
await Task.CompletedTask;
|
|
string src = AssistentConfig.SafeId(from) ?? Config.DefaultPersonaId();
|
|
string dest = AssistentConfig.SafeId(to);
|
|
if (dest is null)
|
|
{
|
|
return new JObject { ["error"] = "invalid to id" };
|
|
}
|
|
try
|
|
{
|
|
JObject meta = Config.ClonePersonaToOverlay(src, dest, title, overwrite);
|
|
return new JObject
|
|
{
|
|
["success"] = true,
|
|
["persona"] = meta,
|
|
["personas"] = new JArray(Config.ListPersonaCatalog().Select(p => new JObject
|
|
{
|
|
["id"] = p.id,
|
|
["title"] = p.title,
|
|
["accent"] = p.accent,
|
|
["source"] = p.source,
|
|
})),
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JObject { ["error"] = ex.Message };
|
|
}
|
|
}
|
|
|
|
public async Task<JObject> AssistentSavePersona(Session session, string persona = null, JObject shelves = null)
|
|
{
|
|
await Task.CompletedTask;
|
|
string pid = AssistentConfig.SafeId(persona);
|
|
if (pid is null)
|
|
{
|
|
return new JObject { ["error"] = "invalid persona id" };
|
|
}
|
|
try
|
|
{
|
|
JObject saved = Config.SavePersonaShelves(pid, shelves);
|
|
return new JObject
|
|
{
|
|
["success"] = true,
|
|
["persona"] = pid,
|
|
["source"] = Config.PersonaSource(pid),
|
|
["shelves"] = saved,
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JObject { ["error"] = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>UI-only. Never called from LLM patch actions.</summary>
|
|
public async Task<JObject> AssistentDeletePersona(Session session, string persona = null)
|
|
{
|
|
await Task.CompletedTask;
|
|
string pid = AssistentConfig.SafeId(persona);
|
|
if (pid is null)
|
|
{
|
|
return new JObject { ["error"] = "invalid persona id" };
|
|
}
|
|
if (!Config.IsOverlayPersona(pid))
|
|
{
|
|
return new JObject { ["error"] = "only overlay personas can be deleted" };
|
|
}
|
|
try
|
|
{
|
|
bool ok = Config.DeleteOverlayPersona(pid);
|
|
string next = Config.DefaultPersonaId();
|
|
return new JObject
|
|
{
|
|
["success"] = ok,
|
|
["deleted"] = pid,
|
|
["default_persona"] = next,
|
|
["personas"] = new JArray(Config.ListPersonaCatalog().Select(p => new JObject
|
|
{
|
|
["id"] = p.id,
|
|
["title"] = p.title,
|
|
["accent"] = p.accent,
|
|
["source"] = p.source,
|
|
})),
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JObject { ["error"] = ex.Message };
|
|
}
|
|
}
|
|
}
|