/**
* PersonaSettingsPanel — RPG-style character sheet for persona projects
*
* Replaces the AgentSettingsPanel when editing persona projects.
* Displays the avatar gallery, identity details, appearance settings,
* and agentic capabilities (goal, tools, agents, execution profile).
*
* Phase 2 additions:
* - Wardrobe system — generate outfit variations using stored character prompt
* - Avatar generation settings display — shows reproducibility info
* - Class badge from persona_class stored in persona_agent
*
* Designed like an MMORPG character profile card.
*/
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { X, Sparkles, User, Heart, Star, Shield, Palette, FileText, Trash2, Loader2, Camera, Zap, Wrench, Users, Server, Settings, Check, ChevronDown, ChevronUp, Shirt, Plus, Copy, Upload, RefreshCw, Package, Share2, } from 'lucide-react';
import { ImageViewer } from '../ImageViewer';
import { InventoryView } from './InventoryView';
import { OUTFIT_PRESETS, PERSONA_BLUEPRINTS } from '../personaTypes';
import { generateOutfitImages, generatePersonaImages, commitGeneratedImages } from '../personaApi';
import { commitPersonaAvatar } from '../personaPortability';
import { useAvatarCapabilities } from '../useAvatarCapabilities';
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const PROFILE_OPTIONS = [
{ value: 'fast', label: 'Swift', hint: 'Low latency, fewer tool calls', icon: '\u26A1' },
{ value: 'balanced', label: 'Balanced', hint: 'Good mix of speed and depth', icon: '\u2696\uFE0F' },
{ value: 'quality', label: 'Thorough', hint: 'Multi-step reasoning', icon: '\uD83C\uDFAF' },
];
const BUILTIN_CAPABILITIES = [
{ id: 'generate_images', label: 'Generate images' },
{ id: 'generate_videos', label: 'Generate short videos' },
{ id: 'analyze_documents', label: 'Analyze documents' },
{ id: 'automate_external', label: 'Automate external services' },
];
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function readNsfwMode() {
try {
return localStorage.getItem('homepilot_nsfw_mode') === 'true';
}
catch {
return false;
}
}
/** Build a displayable /files/ URL from a DB-stored relative path.
* Appends auth token for tags that can't set Authorization headers. */
function fileUrl(backendUrl, rel) {
if (!rel)
return null;
const clean = rel.replace(/^\/+/, '');
const tok = localStorage.getItem('homepilot_auth_token') || '';
return `${backendUrl}/files/${clean}${tok ? `?token=${encodeURIComponent(tok)}` : ''}`;
}
/** Resolve an image URL — prepend backendUrl for backend-relative paths
* like `/comfy/view/...` that come from Avatar Studio exports.
* Appends auth token for /files/ paths (needed for tags). */
function resolveImgUrl(url, backendUrl) {
if (!url)
return url;
if (url.startsWith('data:') || url.startsWith('blob:'))
return url;
let full = url;
if (!url.startsWith('http://') && !url.startsWith('https://')) {
const base = backendUrl.replace(/\/+$/, '');
const path = url.startsWith('/') ? url : `/${url}`;
full = `${base}${path}`;
}
// Append auth token for /files/ paths so tags can access them
if (full.includes('/files/')) {
const tok = localStorage.getItem('homepilot_auth_token') || '';
if (tok) {
const sep = full.includes('?') ? '&' : '?';
return `${full}${sep}token=${encodeURIComponent(tok)}`;
}
}
return full;
}
let _imgCounter = 0;
function nextImageId() {
return `pimg_${Date.now()}_${++_imgCounter}`;
}
function SectionHeader({ icon: Icon, title, badge, color = 'text-white/50', }) {
return (
{title}
{badge !== undefined && (
{badge}
)}
);
}
function StatBar({ label, value, color = 'bg-purple-500' }) {
return ();
}
function Toggle({ checked, onChange, label, }) {
return ( onChange(!checked)} className="flex items-center justify-between w-full group">
{label}
);
}
function StatusDot({ ok }) {
return ;
}
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
export function PersonaSettingsPanel({ project, backendUrl, apiKey, onClose, onSaved }) {
const pa = project.persona_agent || {};
const pap = project.persona_appearance || {};
const ag = project.agentic || {};
const isSpicy = readNsfwMode();
// Avatar model capabilities — purely informational, never blocks existing flows
const { capabilities: avatarCaps } = useAvatarCapabilities(backendUrl, apiKey);
// --- View mode: "sheet" (default character sheet) or "inventory" ---
const [viewMode, setViewMode] = useState('sheet');
// --- Persona identity state ---
const [name, setName] = useState(pa.label || project.name || '');
const [role, setRole] = useState(pa.role || project.description || '');
const [systemPrompt, setSystemPrompt] = useState(pa.system_prompt || project.instructions || '');
const [tone, setTone] = useState(pa.response_style?.tone || 'warm');
const [stylePreset, setStylePreset] = useState(pap.style_preset || 'Executive');
// --- Agentic state ---
const [goal, setGoal] = useState(ag.goal || '');
const [capabilities, setCapabilities] = useState(ag.capabilities || []);
const [profile, setProfile] = useState(ag.execution_profile || 'balanced');
const [askFirst, setAskFirst] = useState(ag.ask_before_acting !== false);
const [toolIds, setToolIds] = useState(ag.tool_ids || []);
const [agentIds, setAgentIds] = useState(ag.a2a_agent_ids || []);
const [toolSource, setToolSource] = useState(ag.tool_source || 'all');
// --- Catalog data ---
const [catalogTools, setCatalogTools] = useState([]);
const [catalogAgents, setCatalogAgents] = useState([]);
const [catalogServers, setCatalogServers] = useState([]);
const [catalogLoading, setCatalogLoading] = useState(true);
// --- Auto-pin & reconcile tools when catalog loads ---
// 1. If toolIds is empty: derive pins from tool_details or keyword matching.
// 2. If toolIds is populated but some IDs don't exist in the catalog:
// reconcile by matching tool names so checkboxes render correctly.
const autoPopulated = useRef(false);
useEffect(() => {
if (autoPopulated.current || catalogLoading || catalogTools.length === 0)
return;
autoPopulated.current = true;
const enabled = catalogTools.filter((t) => t.enabled !== false);
const catalogIdSet = new Set(enabled.map((t) => t.id));
// -- Reconcile existing pinned IDs that may not match catalog --
if (toolIds.length > 0) {
const allMatch = toolIds.every((id) => catalogIdSet.has(id));
if (allMatch)
return; // everything already matches, nothing to do
// Build lookup maps for fuzzy matching: by name and by suffix
const catalogByName = new Map(); // lowercase name → catalog id
const catalogBySuffix = new Map(); // last segment → catalog id
for (const t of enabled) {
catalogByName.set(t.name.toLowerCase(), t.id);
// e.g. "mcp-news__get-headlines" → "get-headlines"
const parts = t.id.split(/__|\/|:/);
const suffix = parts[parts.length - 1];
if (suffix && !catalogBySuffix.has(suffix))
catalogBySuffix.set(suffix, t.id);
}
// Also index tool_details by id for name lookups
const detailsMap = new Map(); // old id → name
const details = ag.tool_details;
if (Array.isArray(details)) {
for (const d of details) {
if (d.id && d.name)
detailsMap.set(d.id, d.name);
}
}
const reconciled = [];
const seen = new Set();
for (const oldId of toolIds) {
let resolved;
if (catalogIdSet.has(oldId)) {
resolved = oldId;
}
else {
// Try matching by tool name from tool_details
const name = detailsMap.get(oldId);
if (name)
resolved = catalogByName.get(name.toLowerCase());
// Try matching by suffix (last segment of the id)
if (!resolved) {
const parts = oldId.split(/__|\/|:/);
const suffix = parts[parts.length - 1];
if (suffix)
resolved = catalogBySuffix.get(suffix);
}
// Try direct name match on the old id itself
if (!resolved)
resolved = catalogByName.get(oldId.toLowerCase());
}
if (resolved && !seen.has(resolved)) {
reconciled.push(resolved);
seen.add(resolved);
}
}
if (reconciled.length > 0 && (reconciled.length !== toolIds.length || reconciled.some((id, i) => id !== toolIds[i]))) {
setToolIds(reconciled);
}
return;
}
// -- No pinned tools yet: auto-populate --
const ids = [];
// Strategy 1: use tool_details from the agentic data (set by .hpersona import)
const details = ag.tool_details;
if (Array.isArray(details) && details.length > 0) {
// Match by id first, then fall back to name
const catalogByName = new Map();
for (const t of enabled)
catalogByName.set(t.name.toLowerCase(), t.id);
for (const d of details) {
const tid = d.id || d.name || '';
let resolved;
if (tid && catalogIdSet.has(tid)) {
resolved = tid;
}
else if (d.name) {
resolved = catalogByName.get(d.name.toLowerCase());
}
else if (tid) {
resolved = catalogByName.get(tid.toLowerCase());
}
if (resolved && !ids.includes(resolved))
ids.push(resolved);
}
}
// Strategy 2: match role / system_prompt keywords against tool name prefixes
if (ids.length === 0) {
const haystack = [role, systemPrompt, goal].join(' ').toLowerCase();
// Build keyword→prefix map for profession-based matching
const KEYWORD_PREFIXES = [
[['news', 'journalist', 'reporter', 'headlines'], 'news-'],
[['teams', 'meeting', 'conference', 'calendar'], 'teams-'],
[['email', 'mail', 'gmail', 'outlook'], 'hp-email'],
[['web', 'search', 'research', 'browse'], 'hp-web'],
[['brief', 'digest', 'executive', 'summary'], 'hp-brief'],
[['decision', 'risk', 'options', 'strategy'], 'hp-decision'],
[['inventory', 'photos', 'images', 'files', 'assets'], 'hp-inventory'],
];
const matchedPrefixes = new Set();
for (const [kws, prefix] of KEYWORD_PREFIXES) {
if (kws.some((kw) => haystack.includes(kw)))
matchedPrefixes.add(prefix);
}
if (matchedPrefixes.size > 0) {
for (const t of enabled) {
for (const prefix of matchedPrefixes) {
if (t.id.startsWith(prefix) || t.name.toLowerCase().startsWith(prefix)) {
if (!ids.includes(t.id))
ids.push(t.id);
}
}
}
}
}
if (ids.length > 0)
setToolIds(ids);
}, [catalogLoading, catalogTools]); // eslint-disable-line react-hooks/exhaustive-deps
// Avatar state (sets is stateful so individual image deletions trigger re-render)
// For imported personas: sets may be empty but selected_filename exists on disk.
// Synthesize a fallback set so the portrait renders immediately.
const initialSets = (() => {
const raw = Array.isArray(pap.sets) ? pap.sets : [];
if (raw.length > 0)
return raw;
const thumb = pap.selected_thumb_filename;
const full = pap.selected_filename;
const url = fileUrl(backendUrl, thumb || full);
if (!url)
return [];
return [
{
set_id: 'set_imported_001',
images: [{ id: 'pimg_imported_001', url, set_id: 'set_imported_001' }],
},
];
})();
const [sets, setSets] = useState(initialSets);
const allImages = sets.flatMap((s) => (s.images || []).map((img) => ({ ...img, set_id: s.set_id })));
const [selectedImage, setSelectedImage] = useState(pap.selected
|| (initialSets.length > 0
? { set_id: initialSets[0].set_id, image_id: initialSets[0].images[0].id }
: null));
// Outfit / wardrobe state
const [outfits, setOutfits] = useState(pap.outfits || []);
const [generatingOutfit, setGeneratingOutfit] = useState(false);
const [outfitGenError, setOutfitGenError] = useState(null);
const [selectedOutfitPreset, setSelectedOutfitPreset] = useState('');
const [customOutfitPrompt, setCustomOutfitPrompt] = useState('');
const [customOutfitLabel, setCustomOutfitLabel] = useState('');
// Generation mode: 'standard' (default text-to-image) or 'identity' (face-preserving)
const [generationMode, setGenerationModeRaw] = useState(pap.avatar_settings?.generation_mode || 'standard');
const setGenerationMode = (mode) => {
setGenerationModeRaw(mode);
// Persist into avatar_settings so it survives save
if (avatarSettingsLocal) {
setAvatarSettingsLocal({ ...avatarSettingsLocal, generation_mode: mode });
}
markDirty();
};
// Avatar settings (stored for reproducibility)
const avatarSettings = pap.avatar_settings || null;
// Documents
const [documents, setDocuments] = useState(project.files || []);
// Shared API (publish as model)
const sa = project.shared_api || {};
const [sharedEnabled, setSharedEnabled] = useState(sa.enabled ?? false);
const [sharedAlias, setSharedAlias] = useState(sa.alias ?? '');
const [featuredSlot, setFeaturedSlot] = useState(sa.featured_slot ?? null);
// UI state
const [saving, setSaving] = useState(false);
const [dirty, setDirty] = useState(false);
const [lightbox, setLightbox] = useState(null);
const [showGallery, setShowGallery] = useState(false);
const [showTools, setShowTools] = useState(false);
const [showAgents, setShowAgents] = useState(false);
const [showWardrobe, setShowWardrobe] = useState(false);
const [showAvatarSettings, setShowAvatarSettings] = useState(false);
const [showChangePhoto, setShowChangePhoto] = useState(false);
const [uploadingPhoto, setUploadingPhoto] = useState(false);
const [generatingPhoto, setGeneratingPhoto] = useState(false);
const [changePhotoError, setChangePhotoError] = useState(null);
const [avatarSettingsLocal, setAvatarSettingsLocal] = useState(avatarSettings ?? null);
const [showEnableOutfits, setShowEnableOutfits] = useState(false);
const [enableOutfitCharDesc, setEnableOutfitCharDesc] = useState('');
// Class info
const personaClass = pa.persona_class || pa.category || 'custom';
const blueprint = PERSONA_BLUEPRINTS.find((bp) => bp.id === personaClass);
// Total image count across base portraits + all outfits (for LV badge)
const totalImageCount = allImages.length + outfits.reduce((n, o) => n + o.images.length, 0);
// Find selected image URL — must search base portraits AND outfit images.
// Resolve relative backend paths (e.g. /comfy/view/...) to full URLs.
const selectedUrl = (() => {
let raw = null;
if (selectedImage) {
// Check base portraits
for (const img of allImages) {
if (img.id === selectedImage.image_id && img.set_id === selectedImage.set_id) {
raw = img.url;
break;
}
}
// Check outfit images
if (!raw) {
for (const outfit of outfits) {
for (const img of outfit.images) {
if (img.id === selectedImage.image_id && img.set_id === selectedImage.set_id) {
raw = img.url;
break;
}
}
if (raw)
break;
}
}
}
if (raw)
return resolveImgUrl(raw, backendUrl);
// Fallback: first image in gallery, or resolve from imported filename fields
const fallback = allImages[0]?.url;
if (fallback)
return resolveImgUrl(fallback, backendUrl);
return fileUrl(backendUrl, pap.selected_thumb_filename)
|| fileUrl(backendUrl, pap.selected_filename);
})();
// --- RPG stat bars derived from persona config ---
const toneValues = {
warm: 70,
professional: 85,
playful: 50,
assertive: 90,
flirty: 40,
};
const styleValues = {
Executive: 90,
Elegant: 80,
Romantic: 60,
Casual: 40,
Seductive: 55,
Lingerie: 35,
'Pin-Up': 50,
Fantasy: 45,
};
// Track dirtiness
const markDirty = () => {
if (!dirty)
setDirty(true);
};
// --- Fetch catalog ---
useEffect(() => {
const headers = {};
if (apiKey)
headers['x-api-key'] = apiKey;
try {
if (typeof window !== 'undefined') {
const tok = window.localStorage.getItem('homepilot_auth_token') || '';
if (tok)
headers['authorization'] = `Bearer ${tok}`;
}
}
catch { /* ignore */ }
fetch(`${backendUrl}/v1/agentic/catalog`, { headers, credentials: 'include' })
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
if (data) {
setCatalogServers(Array.isArray(data.servers)
? data.servers.map((s) => ({
id: String(s.id || s.name),
name: String(s.name || s.id),
description: s.description,
enabled: s.enabled !== false,
tool_ids: Array.isArray(s.tool_ids)
? s.tool_ids
: Array.isArray(s.associated_tools)
? s.associated_tools
: [],
}))
: []);
setCatalogTools(Array.isArray(data.tools)
? data.tools.map((t) => ({
id: t.id || t.name,
name: t.name,
description: t.description,
enabled: t.enabled !== false,
}))
: []);
setCatalogAgents(Array.isArray(data.a2a_agents)
? data.a2a_agents.map((a) => ({
id: a.id || a.name,
name: a.name,
description: a.description,
enabled: a.enabled !== false,
}))
: []);
}
})
.catch(() => { })
.finally(() => setCatalogLoading(false));
}, [backendUrl, apiKey]);
// --- Derived: effective tool counts ---
const enabledCatalogTools = catalogTools.filter((t) => t.enabled !== false);
const serverToolCount = (() => {
if (!toolSource.startsWith('server:'))
return 0;
const sid = toolSource.replace('server:', '');
const s = catalogServers.find((x) => x.id === sid);
return s?.tool_ids?.length || 0;
})();
const effectiveToolCount = (() => {
if (toolSource === 'none')
return 0;
if (toolSource === 'all')
return enabledCatalogTools.length;
if (toolSource.startsWith('server:'))
return serverToolCount;
return 0;
})();
const visibleTools = (() => {
if (toolSource === 'none')
return [];
if (toolSource === 'all')
return enabledCatalogTools;
if (toolSource.startsWith('server:')) {
const sid = toolSource.replace('server:', '');
const s = catalogServers.find((x) => x.id === sid);
if (!s?.tool_ids?.length)
return [];
const ids = new Set(s.tool_ids);
return enabledCatalogTools.filter((t) => ids.has(t.id));
}
return [];
})();
// --- Toggle helpers ---
const toggleCap = (id) => {
setCapabilities((prev) => (prev.includes(id) ? prev.filter((c) => c !== id) : [...prev, id]));
markDirty();
};
const toggleTool = (id) => {
setToolIds((prev) => (prev.includes(id) ? prev.filter((t) => t !== id) : [...prev, id]));
markDirty();
};
const toggleAgent = (id) => {
setAgentIds((prev) => (prev.includes(id) ? prev.filter((a) => a !== id) : [...prev, id]));
markDirty();
};
// --- Upload a new photo ---
const handleUploadPhoto = useCallback(async (file) => {
setUploadingPhoto(true);
setChangePhotoError(null);
try {
const formData = new FormData();
formData.append('file', file);
const headers = {};
if (apiKey)
headers['x-api-key'] = apiKey;
const uploadRes = await fetch(`${backendUrl}/upload`, {
method: 'POST',
headers,
body: formData,
});
if (!uploadRes.ok)
throw new Error(`Upload failed: ${uploadRes.status}`);
const { url } = await uploadRes.json();
// Extract the bare filename from the upload URL (e.g. "abc123.png")
// The upload endpoint returns /files/.
const uploadedFilename = url.split('/files/').pop()?.split('?')[0];
// Commit the uploaded file as the project's durable avatar
const commitResult = await commitPersonaAvatar({
backendUrl,
apiKey,
projectId: project.id,
sourceFilename: uploadedFilename,
});
// Use the committed file URL for display
const committedProject = commitResult.project || {};
const committedPap = committedProject.persona_appearance || {};
const committedRel = committedPap.selected_thumb_filename || committedPap.selected_filename;
const _tok = localStorage.getItem('homepilot_auth_token') || '';
const displayUrl = committedRel
? `${backendUrl}/files/${String(committedRel).replace(/^\/+/, '')}?v=${Date.now()}${_tok ? `&token=${encodeURIComponent(_tok)}` : ''}`
: url;
// Add to gallery sets and select
const imgId = nextImageId();
const setId = `set_upload_${Date.now()}`;
const newImage = {
id: imgId,
url: displayUrl,
created_at: new Date().toISOString(),
set_id: setId,
};
setSets((prev) => [...prev, { set_id: setId, images: [newImage] }]);
setSelectedImage({ set_id: setId, image_id: imgId });
setShowChangePhoto(false);
markDirty();
}
catch (err) {
setChangePhotoError(err?.message || 'Upload failed');
}
finally {
setUploadingPhoto(false);
}
}, [backendUrl, apiKey, project.id]);
// --- Generate a new portrait photo ---
const handleGenerateNewPhoto = useCallback(async () => {
const charPrompt = avatarSettingsLocal?.character_prompt || `${name}, portrait`;
setGeneratingPhoto(true);
setChangePhotoError(null);
try {
const out = await generatePersonaImages({
backendUrl,
apiKey,
prompt: charPrompt,
imgModel: avatarSettingsLocal?.img_model,
imgBatchSize: 4,
imgAspectRatio: avatarSettingsLocal?.aspect_ratio ?? '2:3',
imgPreset: avatarSettingsLocal?.img_preset ?? 'med',
promptRefinement: true,
nsfwMode: avatarSettingsLocal?.nsfw_mode ?? false,
generationMode,
referenceImageUrl: generationMode === 'identity' ? selectedUrl ?? undefined : undefined,
});
if (out.urls.length === 0) {
setChangePhotoError('No images returned. Check your image backend (ComfyUI).');
return;
}
const setId = `set_gen_${Date.now()}`;
const newImages = out.urls.map((url, i) => ({
id: nextImageId(),
url,
created_at: new Date().toISOString(),
set_id: setId,
seed: out.seeds?.[i],
}));
// Show images immediately (comfy URLs) while commit runs
setSets((prev) => [...prev, { set_id: setId, images: newImages }]);
setSelectedImage({ set_id: setId, image_id: newImages[0].id });
// Commit-on-generate: persist to durable /files/ storage immediately
// so inventory + MCP + chat can resolve them without waiting for Save.
try {
const commitRes = await commitGeneratedImages({
backendUrl,
apiKey,
projectId: project.id,
kind: 'set',
images: newImages.map(img => ({ url: img.url, id: img.id, set_id: img.set_id })),
});
// Replace local URLs with durable /files/ URLs
if (commitRes.committed?.length) {
const urlMap = new Map(commitRes.committed.map(c => [c.id, c.url]));
setSets((prev) => prev.map(s => s.set_id === setId
? { ...s, images: s.images.map(img => ({ ...img, url: urlMap.get(img.id) || img.url })) }
: s));
}
}
catch {
// Non-fatal — images still display from ComfyUI URLs, commit on Save
}
// Also commit the selected avatar so thumbnail is durable
try {
await commitPersonaAvatar({
backendUrl,
apiKey,
projectId: project.id,
auto: true,
});
}
catch {
// Non-fatal
}
// Update avatar_settings with the generation params
const newSettings = {
character_prompt: charPrompt,
outfit_prompt: avatarSettingsLocal?.outfit_prompt || 'default outfit',
full_prompt: out.final_prompt ?? charPrompt,
style_preset: stylePreset,
gender: pap.gender ?? 'female',
img_model: out.model ?? avatarSettingsLocal?.img_model ?? 'dreamshaper_8.safetensors',
img_preset: avatarSettingsLocal?.img_preset ?? 'med',
aspect_ratio: avatarSettingsLocal?.aspect_ratio ?? '2:3',
nsfw_mode: avatarSettingsLocal?.nsfw_mode ?? false,
generation_mode: generationMode,
};
setAvatarSettingsLocal(newSettings);
setShowChangePhoto(false);
markDirty();
}
catch (err) {
setChangePhotoError(err?.message || 'Generation failed');
}
finally {
setGeneratingPhoto(false);
}
}, [avatarSettingsLocal, backendUrl, apiKey, name, stylePreset, pap.gender, generationMode, selectedUrl, project.id]);
// --- Enable outfit variations for imported personas ---
const handleEnableOutfitVariations = useCallback((charDescription) => {
if (!charDescription.trim())
return;
const style = stylePreset || 'elegant';
const newSettings = {
character_prompt: charDescription.trim(),
outfit_prompt: `${style} outfit variation`,
full_prompt: `${charDescription.trim()}, ${style} outfit, elegant lighting, realistic, sharp focus`,
style_preset: style,
gender: pap.gender ?? 'female',
img_model: pap.img_model ?? 'dreamshaper_8.safetensors',
img_preset: pap.img_preset ?? 'med',
aspect_ratio: pap.aspect_ratio ?? '2:3',
nsfw_mode: !!pap.nsfwMode,
};
setAvatarSettingsLocal(newSettings);
setShowEnableOutfits(false);
markDirty();
}, [stylePreset, pap]);
// --- Generate outfit variation ---
// Uses avatarSettingsLocal which includes both original DB settings
// and user-enabled settings (for imported personas that set it inline).
const effectiveAvatarSettings = avatarSettingsLocal ?? avatarSettings ?? null;
const handleGenerateOutfit = useCallback(async () => {
if (!effectiveAvatarSettings?.character_prompt) {
setOutfitGenError('No character description set. Enable outfit variations first.');
return;
}
const outfitPrompt = customOutfitPrompt.trim()
|| OUTFIT_PRESETS.find((p) => p.id === selectedOutfitPreset)?.prompt
|| '';
if (!outfitPrompt) {
setOutfitGenError('Select an outfit preset or enter a custom outfit description.');
return;
}
const label = customOutfitLabel.trim()
|| OUTFIT_PRESETS.find((p) => p.id === selectedOutfitPreset)?.label
|| 'Custom Outfit';
setGeneratingOutfit(true);
setOutfitGenError(null);
try {
const out = await generateOutfitImages({
backendUrl,
apiKey,
characterPrompt: effectiveAvatarSettings.character_prompt,
outfitPrompt,
imgModel: effectiveAvatarSettings.img_model,
imgPreset: effectiveAvatarSettings.img_preset,
imgAspectRatio: effectiveAvatarSettings.aspect_ratio,
nsfwMode: effectiveAvatarSettings.nsfw_mode,
generationMode,
referenceImageUrl: generationMode === 'identity' ? selectedUrl ?? undefined : undefined,
});
if (out.urls.length === 0) {
setOutfitGenError('No images returned. Check your image backend.');
return;
}
const created_at = new Date().toISOString();
const outfitId = `outfit_${Date.now()}`;
const images = out.urls.map((url, i) => ({
id: nextImageId(),
url,
created_at,
set_id: outfitId,
seed: out.seeds?.[i],
}));
const genSettings = {
...effectiveAvatarSettings,
outfit_prompt: outfitPrompt,
full_prompt: out.final_prompt ?? `${effectiveAvatarSettings.character_prompt}, ${outfitPrompt}`,
};
const newOutfit = {
id: outfitId,
label,
outfit_prompt: outfitPrompt,
images,
selected_image_id: images[0]?.id,
generation_settings: genSettings,
created_at,
};
// Show immediately in local state (comfy URLs)
// Merge into existing outfit with the same label (avoid duplicates
// like two separate "Lingerie" entries — instead combine images).
setOutfits((prev) => {
const existingIdx = prev.findIndex((o) => o.label.toLowerCase() === newOutfit.label.toLowerCase());
if (existingIdx >= 0) {
const updated = [...prev];
const existing = updated[existingIdx];
updated[existingIdx] = {
...existing,
images: [...existing.images, ...newOutfit.images],
};
return updated;
}
return [...prev, newOutfit];
});
// Commit-on-generate: persist to durable /files/ storage immediately
// so inventory + MCP + chat can resolve them without waiting for Save.
try {
const commitRes = await commitGeneratedImages({
backendUrl,
apiKey,
projectId: project.id,
kind: 'outfit',
images: images.map(img => ({ url: img.url, id: img.id, set_id: img.set_id })),
outfitId,
outfitLabel: label,
outfitPrompt,
generationSettings: genSettings,
});
// Replace local URLs with durable /files/ URLs
if (commitRes.committed?.length) {
const urlMap = new Map(commitRes.committed.map(c => [c.id, c.url]));
setOutfits((prev) => prev.map(o => {
if (o.id === outfitId || o.label.toLowerCase() === label.toLowerCase()) {
return {
...o,
images: o.images.map(img => ({ ...img, url: urlMap.get(img.id) || img.url })),
};
}
return o;
}));
}
}
catch {
// Non-fatal — images still display from ComfyUI URLs, commit on Save
}
setCustomOutfitPrompt('');
setCustomOutfitLabel('');
setSelectedOutfitPreset('');
markDirty();
}
catch (err) {
setOutfitGenError(err?.message || 'Outfit generation failed.');
}
finally {
setGeneratingOutfit(false);
}
}, [effectiveAvatarSettings, customOutfitPrompt, customOutfitLabel, selectedOutfitPreset, backendUrl, apiKey, generationMode, selectedUrl, project.id]);
// --- Delete outfit ---
const handleDeleteOutfit = (outfitId) => {
setOutfits((prev) => prev.filter((o) => o.id !== outfitId));
markDirty();
};
// --- Use outfit image as main avatar ---
const handleUseOutfitAsAvatar = (outfitImage) => {
setSelectedImage({ set_id: outfitImage.set_id, image_id: outfitImage.id });
markDirty();
};
// --- Save ---
const handleSave = useCallback(async () => {
setSaving(true);
try {
const headers = { 'Content-Type': 'application/json' };
if (apiKey)
headers['x-api-key'] = apiKey;
try {
if (typeof window !== 'undefined') {
const tok = window.localStorage.getItem('homepilot_auth_token') || '';
if (tok)
headers['authorization'] = `Bearer ${tok}`;
}
}
catch { /* ignore */ }
const prevToolDetails = {};
for (const d of ag.tool_details || []) {
if (d && typeof d === 'object' && d.id)
prevToolDetails[d.id] = d;
}
const prevAgentDetails = {};
for (const d of ag.agent_details || []) {
if (d && typeof d === 'object' && d.id)
prevAgentDetails[d.id] = d;
}
const toolDetails = toolIds.map((tid) => {
const t = catalogTools.find((x) => x.id === tid);
const prev = prevToolDetails[tid];
return {
id: tid,
name: t?.name || prev?.name || tid,
description: t?.description || prev?.description || '',
};
});
const agentDetailsList = agentIds.map((aid) => {
const a = catalogAgents.find((x) => x.id === aid);
const prev = prevAgentDetails[aid];
return {
id: aid,
name: a?.name || prev?.name || aid,
description: a?.description || prev?.description || '',
};
});
const body = {
name,
description: role,
instructions: systemPrompt,
project_type: 'persona',
persona_agent: {
...pa,
label: name,
role,
system_prompt: systemPrompt,
response_style: { ...(pa.response_style || {}), tone },
},
persona_appearance: {
...pap,
sets,
style_preset: stylePreset,
selected: selectedImage,
outfits,
...(avatarSettingsLocal ? { avatar_settings: avatarSettingsLocal } : {}),
},
agentic: {
goal,
capabilities,
tool_ids: toolIds,
a2a_agent_ids: agentIds,
tool_details: toolDetails,
agent_details: agentDetailsList,
tool_source: toolSource,
ask_before_acting: askFirst,
execution_profile: profile,
},
shared_api: {
enabled: sharedEnabled,
alias: sharedAlias,
featured_slot: featuredSlot,
},
};
const res = await fetch(`${backendUrl}/projects/${project.id}`, {
method: 'PUT',
headers,
credentials: 'include',
body: JSON.stringify(body),
});
if (res.ok) {
const data = await res.json();
// Auto-commit the currently selected avatar so the durable
// selected_filename / selected_thumb_filename stay in sync.
// This ensures the mini thumbnail in the projects list updates.
let finalProject = data.project;
try {
const commitRes = await commitPersonaAvatar({
backendUrl,
apiKey,
projectId: project.id,
auto: true,
});
if (commitRes.project) {
finalProject = commitRes.project;
}
}
catch {
// Non-fatal — avatar may already be committed or ComfyUI offline
}
setDirty(false);
onSaved(finalProject);
}
else {
alert('Failed to save persona settings');
}
}
catch {
alert('Failed to save persona settings');
}
finally {
setSaving(false);
}
}, [
name, role, systemPrompt, tone, stylePreset, selectedImage, sets, outfits,
goal, capabilities, profile, askFirst, toolIds, agentIds, toolSource,
pa, pap, ag.tool_details, ag.agent_details, backendUrl, apiKey,
project.id, onSaved, catalogTools, catalogAgents, avatarSettingsLocal,
sharedEnabled, sharedAlias, featuredSlot,
]);
// --- Document delete ---
const handleDeleteDoc = async (docName) => {
if (!confirm(`Delete document "${docName}"?`))
return;
try {
const headers = {};
if (apiKey)
headers['x-api-key'] = apiKey;
const res = await fetch(`${backendUrl}/projects/${project.id}/documents/${encodeURIComponent(docName)}`, { method: 'DELETE', headers });
if (res.ok)
setDocuments((prev) => prev.filter((d) => d.name !== docName));
}
catch {
/* silent */
}
};
// --- Available outfit presets based on NSFW mode ---
const availableOutfitPresets = OUTFIT_PRESETS.filter((p) => p.category === 'sfw' || isSpicy);
return (
e.stopPropagation()}>
{/* -- Header -- */}
Persona Profile
{blueprint && blueprint.id !== 'custom' && (
{blueprint.icon} {blueprint.label}
)}
{viewMode === 'inventory' ? 'Inventory' : 'Character Sheet'}
{
if (viewMode === 'inventory') {
setViewMode('sheet');
}
else {
// Auto-save before switching to inventory so the backend
// has fresh persona_appearance data (including newly
// generated outfits) for the inventory API to read.
if (dirty) {
await handleSave();
}
setViewMode('inventory');
}
}} className={[
'flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg transition-all border',
viewMode === 'inventory'
? 'bg-amber-500/20 border-amber-500/30 text-amber-400'
: 'bg-white/5 border-white/10 text-white/50 hover:text-white hover:bg-white/10',
].join(' ')}>
Inventory
{/* -- Content: swap between sheet and inventory -- */}
{viewMode === 'inventory' ? (
setViewMode('sheet')} activeSelection={selectedImage} draftAppearance={{ sets, outfits, selected: selectedImage }} onSetActiveLook={(sel) => {
// Wardrobe-style selection: update selectedImage state, mark dirty.
// Stay on inventory page — no auto navigation back.
setSelectedImage({ set_id: sel.set_id, image_id: sel.image_id });
markDirty();
}}/>) : (
{/* -- Top: Avatar + Stats -- */}
{/* Avatar frame */}
{selectedUrl ? (
setLightbox(selectedUrl)} className="w-40 h-52 object-cover object-top rounded-xl border-2 border-pink-500/30 shadow-lg shadow-pink-500/10 cursor-zoom-in"/>) : (
setShowChangePhoto(true)}>
Add photo
)}
{/* Change Photo button (hover) */}
setShowChangePhoto(!showChangePhoto)} className="absolute top-2 right-2 p-1.5 bg-black/60 hover:bg-black/80 rounded-lg border border-white/20 transition-all opacity-0 group-hover:opacity-100" title="Change photo">
{allImages.length > 1 && (
setShowGallery(!showGallery)} className="absolute bottom-2 right-2 p-1.5 bg-black/60 hover:bg-black/80 rounded-lg border border-white/20 transition-all opacity-0 group-hover:opacity-100">
)}
LV {totalImageCount}
{/* Change Photo panel */}
{showChangePhoto && (
{/* Upload option */}
{uploadingPhoto ? 'Uploading...' : 'Upload image'}
{
const f = e.target.files?.[0];
if (f)
handleUploadPhoto(f);
e.target.value = '';
}}/>
{/* Generate option */}
{generatingPhoto ? 'Generating...' : 'Generate new (4)'}
{generatingPhoto && }
{/* Generation mode toggle — Standard vs Same Person */}
Generation mode
setGenerationMode('standard')} className={`flex-1 px-2 py-1.5 rounded-lg border text-[10px] font-medium transition-all ${generationMode === 'standard'
? 'bg-purple-500/15 border-purple-500/30 text-purple-300'
: 'bg-white/[0.03] border-white/10 text-white/40 hover:bg-white/[0.06]'}`}>
Standard
avatarCaps.canIdentityPortrait && setGenerationMode('identity')} disabled={!avatarCaps.canIdentityPortrait} title={avatarCaps.canIdentityPortrait
? 'Keeps the same face consistent across generations'
: 'Install Avatar Models (Add-ons) to enable'} className={`flex-1 px-2 py-1.5 rounded-lg border text-[10px] font-medium transition-all ${generationMode === 'identity'
? 'bg-emerald-500/15 border-emerald-500/30 text-emerald-300'
: avatarCaps.canIdentityPortrait
? 'bg-white/[0.03] border-white/10 text-white/40 hover:bg-white/[0.06]'
: 'bg-white/[0.02] border-white/5 text-white/15 cursor-not-allowed'}`}>
Same Person
{generationMode === 'identity' && (
Face preservation active
)}
{!avatarCaps.canIdentityPortrait && generationMode === 'standard' && (
Install Avatar Models for same-person mode
)}
{changePhotoError && (
{changePhotoError}
)}
)}
{/* Stats panel */}
{/* -- Portrait Gallery (expandable) — base portraits only -- */}
{showGallery && allImages.length > 0 && (
{allImages.map((img) => {
const isSel = selectedImage?.set_id === img.set_id && selectedImage?.image_id === img.id;
return (
{
setSelectedImage({ set_id: img.set_id, image_id: img.id });
markDirty();
}} className={`relative w-full overflow-hidden rounded-lg border-2 transition-all ${isSel
? 'border-pink-500 ring-2 ring-pink-500/30 scale-[1.02]'
: 'border-white/10 hover:border-white/30 hover:scale-[1.01]'}`}>
{isSel && (
Active
)}
{/* Delete — small bin icon, top-right, appears on hover */}
{!isSel && (
{
e.stopPropagation();
setSets((prev) => prev.map((s) => ({
...s,
images: s.images.filter((i) => i.id !== img.id),
})).filter((s) => s.images.length > 0));
markDirty();
}} className="absolute top-1 right-1 p-1 bg-black/70 hover:bg-red-600/90 rounded-md border border-white/10 transition-all opacity-0 group-hover/thumb:opacity-100" title="Delete this portrait">
)}
);
})}
)}
{/* -- Detail sections -- */}
{/* --- Quest Objective --- */}
{/* --- Style & Tone --- */}
Style
{[...['Executive', 'Elegant', 'Romantic', 'Casual'], ...(isSpicy ? ['Seductive', 'Lingerie', 'Pin-Up', 'Fantasy'] : [])].map((s) => ( {
setStylePreset(s);
markDirty();
}} className={`px-3 py-1.5 rounded-full border text-xs transition-all ${stylePreset === s
? 'bg-pink-500/20 border-pink-500/40 text-pink-300'
: 'bg-white/5 border-white/10 text-white/50 hover:bg-white/10'}`}>
{s}
))}
Tone
{['warm', 'professional', 'playful', 'assertive', ...(isSpicy ? ['flirty'] : [])].map((t) => ( {
setTone(t);
markDirty();
}} className={`px-3 py-1.5 rounded-full border text-xs capitalize transition-all ${tone === t
? 'bg-purple-500/20 border-purple-500/40 text-purple-300'
: 'bg-white/5 border-white/10 text-white/50 hover:bg-white/10'}`}>
{t}
))}
{/* --- Backstory & Personality --- */}
{/* --- Wardrobe (Outfit Variations) --- */}
{/* Existing outfits */}
{outfits.length > 0 && (
{outfits.map((outfit) => (
{outfit.label}
handleDeleteOutfit(outfit.id)} className="p-1 text-white/30 hover:text-red-400 rounded hover:bg-red-500/10 transition-all">
{outfit.images.map((img) => {
const isActive = selectedImage?.set_id === img.set_id && selectedImage?.image_id === img.id;
return (
handleUseOutfitAsAvatar(img)} className={`relative w-full overflow-hidden rounded-lg border transition-all ${isActive
? 'border-amber-500 ring-1 ring-amber-500/30'
: 'border-white/10 hover:border-white/25'}`}>
{isActive && (
Active
)}
{/* Delete single image — bin icon, top-right */}
{!isActive && (
{
e.stopPropagation();
setOutfits((prev) => prev.map((o) => o.id === outfit.id
? { ...o, images: o.images.filter((i) => i.id !== img.id) }
: o).filter((o) => o.images.length > 0));
markDirty();
}} className="absolute top-0.5 right-0.5 p-0.5 bg-black/70 hover:bg-red-600/90 rounded border border-white/10 transition-all opacity-0 group-hover/oimg:opacity-100" title="Delete this image">
)}
);
})}
))}
)}
{/* Outfit generation mode selector */}
Outfit generation
setGenerationMode('standard')} className={`flex-1 px-3 py-2 rounded-lg border text-[11px] font-medium transition-all ${generationMode === 'standard'
? 'bg-amber-500/15 border-amber-500/30 text-amber-300'
: 'bg-white/[0.03] border-white/10 text-white/40 hover:bg-white/[0.06]'}`}>
Standard
Fast, flexible
(avatarCaps.canOutfits || avatarCaps.canIdentityPortrait) && setGenerationMode('identity')} disabled={!avatarCaps.canOutfits && !avatarCaps.canIdentityPortrait} title={(avatarCaps.canOutfits || avatarCaps.canIdentityPortrait)
? 'Keeps the same face consistent across outfit variations'
: 'Install Avatar Models (Add-ons) to enable'} className={`flex-1 px-3 py-2 rounded-lg border text-[11px] font-medium transition-all ${generationMode === 'identity'
? 'bg-emerald-500/15 border-emerald-500/30 text-emerald-300'
: (avatarCaps.canOutfits || avatarCaps.canIdentityPortrait)
? 'bg-white/[0.03] border-white/10 text-white/40 hover:bg-white/[0.06]'
: 'bg-white/[0.02] border-white/5 text-white/15 cursor-not-allowed'}`}>
Same Person
Face consistency
{generationMode === 'identity' && avatarCaps.canOutfits && (
Identity models ready — face preservation active for outfits
)}
{generationMode === 'identity' && avatarCaps.canIdentityPortrait && !avatarCaps.canOutfits && (
Basic identity models installed. Add PhotoMaker V2 or PuLID for best outfit results.
)}
{!avatarCaps.canOutfits && !avatarCaps.canIdentityPortrait && (
Install Avatar Models (Add-ons) to enable same-person mode
)}
{/* Generate new outfit */}
setShowWardrobe(!showWardrobe)} className="flex items-center gap-2 text-xs text-white/50 hover:text-white/80 transition-colors mb-2">
{showWardrobe ? : }
{showWardrobe ? 'Hide outfit creator' : 'Add new outfit variation'}
{showWardrobe && (
{!effectiveAvatarSettings?.character_prompt ? (
/* Enable outfit variations — inline form */
Describe your character to enable outfit variations.
This description stays constant across all outfits.
{showEnableOutfits ? (
) : (
{
// Pre-fill with name + role if available
const hint = [name, role].filter(Boolean).join(', ');
setEnableOutfitCharDesc(hint ? `${hint}, portrait` : '');
setShowEnableOutfits(true);
}} className="w-full px-4 py-2.5 bg-amber-500/20 hover:bg-amber-500/30 border border-amber-500/30 text-amber-300 text-xs font-semibold rounded-xl transition-all flex items-center justify-center gap-2">
Set up outfit variations
)}
) : (<>
{/* Character prompt (read-only display) */}
Stored character description (constant across outfits)
{effectiveAvatarSettings.character_prompt}
{/* Outfit presets */}
Outfit preset
{availableOutfitPresets.map((preset) => ( {
setSelectedOutfitPreset(preset.id);
setCustomOutfitPrompt('');
setCustomOutfitLabel(preset.label);
}} className={`px-2.5 py-1 rounded-full border text-[11px] transition-all ${selectedOutfitPreset === preset.id
? 'bg-amber-500/20 border-amber-500/40 text-amber-300'
: 'bg-white/5 border-white/10 text-white/50 hover:bg-white/10'}`}>
{preset.label}
))}
{/* Custom outfit */}
Or custom outfit description
{
setCustomOutfitPrompt(e.target.value);
if (e.target.value.trim())
setSelectedOutfitPreset('');
}} className="w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-xs text-white placeholder-white/30 focus:outline-none focus:border-amber-500/50" placeholder="e.g., medieval armor, enchanted forest setting..."/>
{/* Label */}
Outfit label
setCustomOutfitLabel(e.target.value)} className="w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-xs text-white placeholder-white/30 focus:outline-none focus:border-amber-500/50" placeholder="e.g., Medieval Knight"/>
{generatingOutfit ? (<>
Generating outfit...
>) : (<>
Generate Outfit Variation (4 images)
>)}
{outfitGenError && (
{outfitGenError}
)}
>)}
)}
{/* --- Avatar Generation Settings (expandable) --- */}
{effectiveAvatarSettings && (
setShowAvatarSettings(!showAvatarSettings)} className="flex items-center gap-2 mb-3">
Generation Settings
{showAvatarSettings ? ( ) : ( )}
{showAvatarSettings && (
Model
{effectiveAvatarSettings.img_model}
Quality
{effectiveAvatarSettings.img_preset}
Aspect ratio
{effectiveAvatarSettings.aspect_ratio}
Style
{effectiveAvatarSettings.style_preset}
{effectiveAvatarSettings.body_type && (
Body type
{effectiveAvatarSettings.body_type}
)}
Full prompt
{effectiveAvatarSettings.full_prompt}
)}
)}
{/* --- Execution Profile --- */}
{PROFILE_OPTIONS.map((opt) => (
{
setProfile(opt.value);
markDirty();
}} className={[
'relative px-3 py-3 rounded-xl border text-left transition-all',
profile === opt.value
? 'bg-cyan-500/15 border-cyan-500/40 ring-1 ring-cyan-500/20'
: 'bg-white/5 border-white/10 hover:bg-white/8 hover:border-white/15',
].join(' ')}>
{opt.icon}
{opt.label}
{opt.hint}
{profile === opt.value && (
)}
))}
{
setAskFirst(v);
markDirty();
}} label="Ask before executing actions"/>
When enabled, the persona will confirm before running tools or taking actions.
{/* --- Skills --- */}
{BUILTIN_CAPABILITIES.map((cap) => {
const active = capabilities.includes(cap.id);
return (
toggleCap(cap.id)} className={[
'flex items-center gap-2.5 px-3 py-2.5 rounded-xl border text-left transition-all',
active
? 'bg-emerald-500/15 border-emerald-500/30'
: 'bg-white/5 border-white/10 hover:bg-white/8',
].join(' ')}>
{active && }
{cap.label}
);
})}
{/* --- Equipment (Tools) --- */}
{catalogLoading ? (
Loading catalog...
) : catalogTools.length === 0 ? (
No tools registered. Start MCP servers and run the seed script to populate.
) : (
setShowTools(!showTools)} className="flex items-center gap-2 text-xs text-white/50 hover:text-white/80 transition-colors mb-2">
{showTools ? : }
{showTools ? 'Collapse' : `Browse ${effectiveToolCount} in bundle (${toolIds.length} pinned)`}
{showTools && (
{visibleTools.map((tool) => {
const bound = toolIds.includes(tool.id);
return (
toggleTool(tool.id)} className={[
'w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-all',
bound
? 'bg-orange-500/10 border border-orange-500/20'
: 'hover:bg-white/5 border border-transparent',
].join(' ')}>
{tool.name}
{tool.description && (
{tool.description}
)}
{bound && }
);
})}
)}
Tool bundle:
{
setToolSource(e.target.value);
markDirty();
}} className="bg-[#1a1a2e] border border-white/10 rounded-lg px-2 py-1 text-xs text-white focus:outline-none focus:border-pink-500/50 [&>option]:bg-[#1a1a2e] [&>option]:text-white">
All enabled tools
{catalogServers.map((s) => (
Server: {s.name}
))}
No tools
)}
{/* --- Party Members (Agents) --- */}
{catalogLoading ? (
Loading...
) : catalogAgents.length === 0 ? (No A2A agents registered.
) : (
setShowAgents(!showAgents)} className="flex items-center gap-2 text-xs text-white/50 hover:text-white/80 transition-colors mb-2">
{showAgents ? : }
{showAgents
? 'Collapse'
: `Browse ${catalogAgents.length} available (${agentIds.length} in party)`}
{showAgents && (
{catalogAgents.map((agent) => {
const bound = agentIds.includes(agent.id);
return (
toggleAgent(agent.id)} className={[
'w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-all',
bound
? 'bg-violet-500/10 border border-violet-500/20'
: 'hover:bg-white/5 border border-transparent',
].join(' ')}>
{agent.name}
{agent.description && (
{agent.description}
)}
{bound && }
);
})}
)}
)}
{/* --- Character Summary --- */}
Class
{blueprint ? `${blueprint.icon} ${blueprint.label}` : stylePreset} {role || 'Persona'}
Alignment
{tone}
Portraits
{allImages.length}
Wardrobe
{outfits.length} outfit{outfits.length !== 1 ? 's' : ''} ({outfits.reduce((n, o) => n + o.images.length, 0)} images)
Generation
{generationMode === 'identity' ? 'Same Person' : 'Standard'}
Equipment
{toolSource === 'all'
? `All tools (${effectiveToolCount})`
: toolSource === 'none'
? 'No tools'
: (() => {
const sid = toolSource.replace('server:', '');
const s = catalogServers.find((x) => x.id === sid);
return s ? `${s.name} (${effectiveToolCount})` : toolSource;
})()}
Party
{agentIds.length === 0
? 'Solo'
: agentIds
.map((id) => catalogAgents.find((a) => a.id === id)?.name || id)
.join(', ')}
Stance
{profile} / {askFirst ? 'Cautious' : 'Auto'}
Skills
{capabilities.length > 0 ? capabilities.length : 'None'}
{pap.nsfwMode && (
Mode
Spicy
)}
{/* Age in days — computed from project creation timestamp */}
{(() => {
const ts = project.created_at;
if (!ts || ts <= 0)
return null;
const createdDate = new Date(ts * 1000);
const ageDays = Math.max(0, Math.floor((Date.now() - createdDate.getTime()) / 86_400_000));
return (<>
Born
{createdDate.toLocaleDateString()}
Age
{ageDays === 0
? 'Newborn (today)'
: ageDays === 1
? '1 day'
: `${ageDays} days`}
>);
})()}
{/* --- Knowledge Base --- */}
{documents.length === 0 ? (
No documents uploaded. Upload files when using this persona project.
) : (
{documents.map((doc, i) => (
{doc.name}
{doc.size || ''}
{doc.chunks ? ` \u00b7 ${doc.chunks} chunks` : ''}
handleDeleteDoc(doc.name)} className="p-1 text-white/30 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all rounded hover:bg-red-500/10">
))}
)}
{/* --- Shared API — Publish as Model --- */}
{/* Toggle row */}
Publish as API Model
Make this persona discoverable by OllaBridge and external apps
{ setSharedEnabled(!sharedEnabled); markDirty(); }} className={`w-9 h-5 rounded-full transition-colors relative ${sharedEnabled ? 'bg-emerald-500' : 'bg-white/20'}`}>
{/* Expanded settings (when enabled) */}
{sharedEnabled && (
{/* Model alias */}
{/* Featured slot */}
Featured Slot (optional)
{
setFeaturedSlot(e.target.value ? Number(e.target.value) : null);
markDirty();
}} className="w-full bg-black/30 border border-white/10 rounded-lg px-3 py-2 text-xs text-white focus:outline-none focus:border-emerald-500/50 transition-colors">
None
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => (Slot {n} ))}
Featured slot controls display order in external apps.
{/* Generated model ID (read-only, copyable) */}
{(() => {
const aliasText = sharedAlias.trim();
const derivedName = (name || '').trim().toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
const shortId = project.id.slice(0, 8);
const modelId = aliasText
? `persona:${aliasText.toLowerCase().replace(/[^a-z0-9-]/g, '').replace(/\s+/g, '-')}--${shortId}`
: derivedName
? `persona:${derivedName}--${shortId}`
: `persona:${shortId}`;
return (
OpenAI Model ID
{modelId}
navigator.clipboard.writeText(modelId)} className="p-1 text-white/30 hover:text-emerald-400 transition-colors" title="Copy model ID">
{aliasText
? 'Use this in OllaBridge, OpenAI SDKs, or any compatible client.'
: 'Set an alias above for a custom model name, or the persona name will be used.'}
);
})()}
)}
)}
{/* -- Footer -- */}
{dirty ? 'Unsaved changes' : 'All changes saved'}
Cancel
{saving ? (
Saving...
) : ('Save Changes')}
{/* Lightbox for full-screen avatar viewing (view-only, no edit/video) */}
{lightbox ? (
setLightbox(null)}/>) : null}
);
}