mirror of
https://github.com/unslothai/unsloth.git
synced 2026-04-28 03:19:57 +00:00
fix chat delete sync
This commit is contained in:
parent
f4f780b3b7
commit
74ab98ec38
3 changed files with 24 additions and 8 deletions
|
|
@ -644,11 +644,18 @@ export function ChatSettingsPanel({
|
|||
const builtinPreset = BUILTIN_PRESETS.find(
|
||||
(preset) => preset.name === name,
|
||||
);
|
||||
if (!builtinPreset) {
|
||||
setActivePreset("Default");
|
||||
const fallbackPreset =
|
||||
builtinPreset ??
|
||||
BUILTIN_PRESETS.find((preset) => preset.name === "Default");
|
||||
if (fallbackPreset) {
|
||||
onParamsChange({
|
||||
...fallbackPreset.params,
|
||||
checkpoint: params.checkpoint,
|
||||
});
|
||||
setActivePreset(fallbackPreset.name);
|
||||
if (canUseStorage()) {
|
||||
try {
|
||||
localStorage.setItem(CHAT_ACTIVE_PRESET_KEY, "Default");
|
||||
localStorage.setItem(CHAT_ACTIVE_PRESET_KEY, fallbackPreset.name);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
|||
|
|
@ -331,6 +331,9 @@ function fallbackTitleFromUserText(userText: string): string {
|
|||
}
|
||||
|
||||
function cloneContent(content: ThreadMessage["content"]): ThreadMessage["content"] {
|
||||
if (typeof content === "string") {
|
||||
return content;
|
||||
}
|
||||
return Array.isArray(content)
|
||||
? JSON.parse(JSON.stringify(content))
|
||||
: [];
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import { db } from "@/features/chat/db";
|
|||
import type { MessageRecord } from "@/features/chat/types";
|
||||
|
||||
function cloneContent(content: ThreadMessage["content"]): ThreadMessage["content"] {
|
||||
if (typeof content === "string") {
|
||||
return content;
|
||||
}
|
||||
return Array.isArray(content) ? JSON.parse(JSON.stringify(content)) : [];
|
||||
}
|
||||
|
||||
|
|
@ -76,12 +79,15 @@ async function syncExportedRepositoryToDexie(
|
|||
await db.transaction("rw", db.messages, async () => {
|
||||
const keepIds = new Set(exp.messages.map((x) => x.message.id));
|
||||
const existing = await db.messages.where("threadId").equals(remoteId).toArray();
|
||||
await Promise.all(
|
||||
existing.filter((m) => !keepIds.has(m.id)).map((m) => db.messages.delete(m.id)),
|
||||
);
|
||||
await Promise.all(
|
||||
const idsToDelete = existing
|
||||
.filter((m) => !keepIds.has(m.id))
|
||||
.map((m) => m.id);
|
||||
if (idsToDelete.length > 0) {
|
||||
await db.messages.bulkDelete(idsToDelete);
|
||||
}
|
||||
await db.messages.bulkPut(
|
||||
exp.messages.map(({ message, parentId }) =>
|
||||
db.messages.put(exportedItemToRecord(remoteId, parentId, message)),
|
||||
exportedItemToRecord(remoteId, parentId, message),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue