Files
KrisHD_AI/public/js/personalities.js
T
Fretux 2275ddfb90
CI / check (22) (push) Failing after 15m50s
CI / check (24) (push) Failing after 15m50s
Update CSP to allow external fonts, scripts, and add corresponding test coverage
2026-10-08 00:00:30 +02:00

64 lines
3.6 KiB
JavaScript

import {get} from "./api.js";
const grid = document.getElementById("personalityGrid");
const iconPaths = {
spark: '<path d="M12 2.8 14.5 9.5 21.2 12l-6.7 2.5L12 21.2l-2.5-6.7L2.8 12l6.7-2.5L12 2.8Z"/><path d="m19 2 .8 2.2L22 5l-2.2.8L19 8l-.8-2.2L16 5l2.2-.8L19 2Z"/>',
quill: '<path d="M20.8 3.2c-6.3-.4-11 2.3-13.2 7.1-1 2.1-.9 4.1-.5 5.7 1.6.4 3.6.5 5.7-.5 4.8-2.2 7.5-6.9 7.1-13.2Z"/><path d="M3 21c3.5-5.1 7.8-8.8 13-11.4M7.2 16.4l-3.4-.3M10.2 13.1l-.1-3.4"/>',
code: '<path d="m8 7-5 5 5 5M16 7l5 5-5 5M14 4l-4 16"/>',
flask: '<path d="M9 3h6M10 3v6l-5.8 9.5A2.3 2.3 0 0 0 6.2 22h11.6a2.3 2.3 0 0 0 2-3.5L14 9V3M7.5 16h9"/>',
"book-open": '<path d="M12 7.2C9.8 5.4 6.5 5 3 5.8v13c3.5-.8 6.8-.4 9 1.4m0-13c2.2-1.8 5.5-2.2 9-1.4v13c-3.5-.8-6.8-.4-9 1.4m0-13v13"/>',
logic: '<circle cx="6" cy="6" r="2"/><circle cx="18" cy="6" r="2"/><circle cx="12" cy="18" r="2"/><path d="M8 7.2 10.8 16M16 7.2 13.2 16M8 6h8"/>'
};
const result = await get("/personalities");
if (result.error) {
grid.textContent = result.error;
} else {
for (const item of result.personalities || []) {
const card = document.createElement("article");
card.className = "personality-card";
card.style.setProperty("--personality-accent", item.accentColor);
const icon = document.createElement("span");
icon.className = "personality-icon";
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.setAttribute("viewBox", "0 0 24 24");
svg.setAttribute("fill", "none");
svg.setAttribute("stroke", "currentColor");
svg.setAttribute("stroke-width", "1.65");
svg.setAttribute("stroke-linecap", "round");
svg.setAttribute("stroke-linejoin", "round");
svg.setAttribute("aria-hidden", "true");
svg.innerHTML = iconPaths[item.icon] || iconPaths.spark;
icon.append(svg);
icon.title = item.name;
icon.setAttribute("aria-hidden", "true");
const specialization = document.createElement("p");
specialization.className = "personality-specialization";
specialization.textContent = `${item.specialization}${item.isDefault ? " · Default" : ""}`;
const name = document.createElement("h2");
name.textContent = item.name;
const description = document.createElement("p");
description.className = "personality-description";
description.textContent = item.description;
const details = document.createElement("details");
details.className = "personality-details";
const summary = document.createElement("summary");
summary.textContent = "Learn more";
const longDescription = document.createElement("p");
longDescription.textContent = item.longDescription;
const inspiration = document.createElement("p");
inspiration.className = "personality-inspiration";
inspiration.textContent = `Thematic inspiration: ${item.historicalInspiration}`;
details.append(summary, longDescription, inspiration);
const action = document.createElement("a");
action.className = "primary-action";
action.innerHTML = '<span>Start a chat</span><span aria-hidden="true">→</span>';
action.setAttribute("aria-label", `Start a chat with ${item.name}, ${item.specialization}`);
action.href = `/app/chats/new?personality=${encodeURIComponent(item.id)}`;
const identity = document.createElement("div");
identity.className = "personality-identity";
identity.append(specialization, name);
card.append(icon, identity, description, details, action);
grid.append(card);
}
}