Enable automatic web search by default; improve toggle behavior and search planning.
This commit is contained in:
@@ -125,13 +125,18 @@ export function createPersonaController({
|
||||
}
|
||||
|
||||
function renderPersonaSection() {
|
||||
updateActivePersonaStatus(state.userPersonas, state.activeUserPersonaId, activeUserPersonaStatus, "No default user persona set.", "Default user persona");
|
||||
if (chatDrawerPersonaValue) {
|
||||
const active = state.userPersonas.find((persona) => persona.id === state.activeUserPersonaId);
|
||||
chatDrawerPersonaValue.textContent = active ? active.name : "None";
|
||||
if (headerPersonaName) headerPersonaName.textContent = active ? active.name : "None";
|
||||
const activeChat = state.chatSessions.find((chat) => chat.id === state.activeChatId);
|
||||
const chatPersona = state.userPersonas.find((persona) => persona.id === activeChat?.user_persona_id);
|
||||
if (activeUserPersonaStatus) {
|
||||
activeUserPersonaStatus.textContent = activeChat
|
||||
? `Using in this chat: ${chatPersona?.name || "yourself"}. Default: ${getPersonaName(state.activeUserPersonaId, state.userPersonas) || "yourself"}.`
|
||||
: `Default user persona: ${getPersonaName(state.activeUserPersonaId, state.userPersonas) || "yourself"}.`;
|
||||
}
|
||||
if (clearUserPersonaBtn) clearUserPersonaBtn.disabled = !state.activeUserPersonaId;
|
||||
if (chatDrawerPersonaValue) {
|
||||
chatDrawerPersonaValue.textContent = chatPersona?.name || "Yourself";
|
||||
if (headerPersonaName) headerPersonaName.textContent = chatPersona?.name || "Yourself";
|
||||
}
|
||||
if (clearUserPersonaBtn) clearUserPersonaBtn.disabled = !activeChat?.user_persona_id;
|
||||
}
|
||||
|
||||
function maybeShowPersonaNudge() {
|
||||
@@ -142,12 +147,6 @@ export function createPersonaController({
|
||||
setNotice("Want to personalize responses? Try personas in Tools.", "success");
|
||||
}
|
||||
|
||||
function updateActivePersonaStatus(items, activeId, statusEl, emptyText, prefix) {
|
||||
if (!statusEl) return;
|
||||
const active = items.find((persona) => persona.id === activeId);
|
||||
statusEl.textContent = active ? `${prefix}: ${active.name}` : emptyText;
|
||||
}
|
||||
|
||||
function openPersonaForm(persona = null, personaType = "assistant") {
|
||||
closeChatDrawer();
|
||||
closePopup(false);
|
||||
@@ -263,13 +262,17 @@ export function createPersonaController({
|
||||
renderPersonaSection();
|
||||
return;
|
||||
}
|
||||
const selectedId = personaType === "user"
|
||||
? state.chatSessions.find((chat) => chat.id === state.activeChatId)?.user_persona_id ?? null
|
||||
: activeId;
|
||||
items.forEach((persona) => {
|
||||
const item = document.createElement("div"), titleRow = document.createElement("div"), title = document.createElement("h4");
|
||||
const tag = document.createElement("span"), meta = document.createElement("p"), actions = document.createElement("div");
|
||||
item.className = `persona-item${personaType === "user" && persona.id === activeId ? " active" : ""}`; titleRow.className = "persona-title-row"; actions.className = "persona-item-actions";
|
||||
item.className = `persona-item${personaType === "user" && persona.id === selectedId ? " active" : ""}`; titleRow.className = "persona-title-row"; actions.className = "persona-item-actions";
|
||||
tag.className = `persona-role-tag ${personaType === "user" ? "user" : "ai"}`; tag.textContent = personaType === "user" ? "You" : "AI";
|
||||
title.textContent = persona.name; meta.textContent = persona.pronouns ? `Pronouns: ${persona.pronouns}` : "Pronouns: n/a";
|
||||
[[personaType === "assistant" ? "Start roleplay" : "Set default", () => equipPersona(persona.id, personaType), personaType === "user" && persona.id === activeId],
|
||||
[[personaType === "assistant" ? "Start roleplay" : "Use in this chat", () => personaType === "user" ? setChatUserPersona(persona.id) : equipPersona(persona.id, personaType), personaType === "user" && persona.id === selectedId],
|
||||
...(personaType === "user" ? [["Set default", () => equipPersona(persona.id, personaType), persona.id === state.activeUserPersonaId]] : []),
|
||||
["Edit", () => openPersonaForm(persona), false],
|
||||
[state.publishedPersonaIds.has(persona.id) ? "Update listing" : "Publish", () => publishPersona(persona.id), false],
|
||||
["Delete", () => deletePersona(persona.id), false]]
|
||||
@@ -309,13 +312,24 @@ export function createPersonaController({
|
||||
setNotice("User persona updated.", "success");
|
||||
}
|
||||
|
||||
async function clearPersona(type) {
|
||||
if (type !== "user") return;
|
||||
const res = await post("/personas/user/clear", {});
|
||||
async function setChatUserPersona(id) {
|
||||
if (!state.activeChatId) return setNotice("Open a chat before choosing a user persona.", "error");
|
||||
const res = await put(`/chats/${state.activeChatId}/user-persona`, {userPersonaId: id});
|
||||
if (res.error) return setNotice(res.error, "error");
|
||||
state.activeUserPersonaId = null;
|
||||
renderPersonaList(state.userPersonas, state.activeUserPersonaId, userPersonaList, "user");
|
||||
setNotice("Persona cleared.", "success");
|
||||
const chat = state.chatSessions.find((item) => item.id === state.activeChatId);
|
||||
if (chat) Object.assign(chat, res.chat);
|
||||
renderPersonaList(state.userPersonas, res.chat.user_persona_id, userPersonaList, "user");
|
||||
setNotice("User persona switched for this chat.", "success");
|
||||
}
|
||||
|
||||
async function clearChatUserPersona() {
|
||||
if (!state.activeChatId) return;
|
||||
const res = await put(`/chats/${state.activeChatId}/user-persona`, {userPersonaId: null});
|
||||
if (res.error) return setNotice(res.error, "error");
|
||||
const chat = state.chatSessions.find((item) => item.id === state.activeChatId);
|
||||
if (chat) Object.assign(chat, res.chat);
|
||||
renderPersonaList(state.userPersonas, null, userPersonaList, "user");
|
||||
setNotice("This chat will use yourself.", "success");
|
||||
}
|
||||
|
||||
async function savePersona() {
|
||||
@@ -406,6 +420,7 @@ export function createPersonaController({
|
||||
}
|
||||
|
||||
return {
|
||||
renderPersonaSection,
|
||||
updateRoleplaySuggestions,
|
||||
setRoleplayStarterNotice,
|
||||
renderRoleplayStarterStep,
|
||||
@@ -415,7 +430,7 @@ export function createPersonaController({
|
||||
openRoleplayStarter,
|
||||
closeRoleplayStarter,
|
||||
loadPersonas,
|
||||
clearPersona,
|
||||
clearChatUserPersona,
|
||||
savePersona,
|
||||
startRoleplay
|
||||
};
|
||||
|
||||
+4
-2
@@ -151,7 +151,8 @@ const {
|
||||
openRoleplayStarter,
|
||||
closeRoleplayStarter,
|
||||
loadPersonas,
|
||||
clearPersona,
|
||||
clearChatUserPersona,
|
||||
renderPersonaSection,
|
||||
savePersona,
|
||||
startRoleplay
|
||||
} = createPersonaController({
|
||||
@@ -448,6 +449,7 @@ function updateWorkspaceCopy() {
|
||||
}
|
||||
|
||||
renderDrawerSummary();
|
||||
renderPersonaSection();
|
||||
updateComposerPlaceholder();
|
||||
}
|
||||
|
||||
@@ -986,7 +988,7 @@ saveGenerationSettingsBtn.addEventListener("click", () => { void saveGenerationS
|
||||
roleplayNewPersonaBtn.addEventListener("click", () => { closeRoleplayStarter(); openPersonaForm(null, "assistant"); });
|
||||
clearUserPersonaBtn.addEventListener("click", () => {
|
||||
closeChatDrawer();
|
||||
void clearPersona("user");
|
||||
void clearChatUserPersona();
|
||||
});
|
||||
personaForm.addEventListener("submit", (event) => { event.preventDefault(); void savePersona(); }); personaCloseBtn.addEventListener("click", closePersonaForm);
|
||||
personaTypeSelect.addEventListener("change", () => {
|
||||
|
||||
Reference in New Issue
Block a user