make some overall QoL improvements
This commit is contained in:
+32
-7
@@ -120,6 +120,7 @@ let workspaceMode = localStorage.getItem("krishd-workspace-mode") || "basic";
|
||||
let onboardingStep = 1, onboardingIntent = "ask";
|
||||
let chatLoadingDepth = 0;
|
||||
let chatActivityDepth = 0;
|
||||
let noticeTimer = null;
|
||||
|
||||
let availableModelsById = new Map();
|
||||
const personalitySelect = document.getElementById("personalitySelect");
|
||||
@@ -234,7 +235,15 @@ const branchExplorer = createBranchExplorer({state: conversation, setActiveChat,
|
||||
|
||||
function setNotice(message = "", state = "") {
|
||||
const notice = document.getElementById("workspaceNotice");
|
||||
if (notice) { notice.textContent = state === "error" ? message : ""; notice.classList.toggle("hidden", state !== "error"); }
|
||||
clearTimeout(noticeTimer);
|
||||
if (notice) {
|
||||
const visible = state === "error" || state === "success";
|
||||
notice.textContent = visible ? message : "";
|
||||
notice.classList.toggle("hidden", !visible);
|
||||
notice.classList.toggle("error", state === "error");
|
||||
notice.classList.toggle("success", state === "success");
|
||||
if (state === "success") noticeTimer = setTimeout(() => setNotice(), 3500);
|
||||
}
|
||||
return { message, state };
|
||||
}
|
||||
|
||||
@@ -603,6 +612,18 @@ function openModelSettings() {
|
||||
requestAnimationFrame(() => modelSelect?.focus());
|
||||
}
|
||||
|
||||
function formatChatActivity(value) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value.includes("T") ? value : `${value.replace(" ", "T")}Z`);
|
||||
if (Number.isNaN(date.getTime())) return "";
|
||||
const today = new Date();
|
||||
const sameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
||||
if (sameDay(date, today)) return new Intl.DateTimeFormat(undefined, {hour: "numeric", minute: "2-digit"}).format(date);
|
||||
const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1);
|
||||
if (sameDay(date, yesterday)) return "Yesterday";
|
||||
return new Intl.DateTimeFormat(undefined, {month: "short", day: "numeric", ...(date.getFullYear() === today.getFullYear() ? {} : {year: "numeric"})}).format(date);
|
||||
}
|
||||
|
||||
function renderChatList() {
|
||||
const query = chatSearchInput.value.trim().toLowerCase();
|
||||
const source = query ? (conversation.chatSearchResults ?? []) : conversation.chatSessions;
|
||||
@@ -657,7 +678,8 @@ function renderChatList() {
|
||||
const chatType = chat.assistant_persona_id
|
||||
? `Roleplay${chat.user_persona_name ? ` · ${chat.user_persona_name}` : ""}`
|
||||
: "Assistant chat";
|
||||
meta.textContent = chat.source_chat_id ? `Branch · ${chatType}` : chatType;
|
||||
const activity = formatChatActivity(chat.updated_at);
|
||||
meta.textContent = [chat.source_chat_id ? `Branch · ${chatType}` : chatType, activity].filter(Boolean).join(" · ");
|
||||
remove.type = "button";
|
||||
remove.className = "chat-item-delete";
|
||||
remove.textContent = "Delete";
|
||||
@@ -668,10 +690,11 @@ function renderChatList() {
|
||||
await deleteChat(chat.id);
|
||||
});
|
||||
content.append(title, meta);
|
||||
if (query && chat.matched_content) {
|
||||
const preview = query && chat.matched_content ? chat.matched_content : chat.last_message_preview;
|
||||
if (preview) {
|
||||
const excerpt = document.createElement("small");
|
||||
const normalized = chat.matched_content.replace(/\s+/g, " ");
|
||||
const matchAt = normalized.toLowerCase().indexOf(query);
|
||||
const normalized = preview.replace(/\s+/g, " ").trim();
|
||||
const matchAt = query ? normalized.toLowerCase().indexOf(query) : -1;
|
||||
const start = Math.max(0, matchAt - 35);
|
||||
excerpt.className = "chat-item-excerpt";
|
||||
excerpt.textContent = `${start ? "…" : ""}${normalized.slice(start, start + 110)}${normalized.length > start + 110 ? "…" : ""}`;
|
||||
@@ -778,7 +801,7 @@ async function updateChatOrganization(id, changes) {
|
||||
const res = await put(`/chats/${id}/organization`, payload);
|
||||
if (res.error) return setNotice(res.error, "error");
|
||||
const index = conversation.chatSessions.findIndex((item) => item.id === id);
|
||||
if (index >= 0) conversation.chatSessions[index] = res.chat;
|
||||
if (index >= 0) conversation.chatSessions[index] = {...conversation.chatSessions[index], ...res.chat};
|
||||
updateWorkspaceCopy();
|
||||
renderChatList();
|
||||
updateChatActionState();
|
||||
@@ -799,7 +822,9 @@ async function clearChat(id) {
|
||||
if (res.error) return setNotice(res.error, "error");
|
||||
conversation.messageRetryState = new Map();
|
||||
conversation.historyPage = null;
|
||||
conversation.currentMessages = []; renderMessages(); await loadSummary(); setNotice("Chat cleared.", "success");
|
||||
chat.last_message_preview = null;
|
||||
chat.updated_at = new Date().toISOString();
|
||||
conversation.currentMessages = []; renderMessages(); renderChatList(); await loadSummary(); setNotice("Chat cleared.", "success");
|
||||
}
|
||||
|
||||
const personaStateFields = [
|
||||
|
||||
Reference in New Issue
Block a user