This commit is contained in:
Timothy Jaeryang Baek
2026-07-26 21:12:14 -04:00
parent f867825bf3
commit 71c4da8c06
8 changed files with 65 additions and 40 deletions
+5 -4
View File
@@ -66,6 +66,7 @@
displayFileHandler
} from '$lib/utils';
import { AudioQueue } from '$lib/utils/audio';
import { createTemporaryChatId, isTemporaryChatId } from '$lib/utils/chatId';
import { getOutputText } from './Messages/structuredOutput';
import {
@@ -451,7 +452,7 @@
const saveChatVariables = async (values) => {
chatVariables = { ...chatVariables, ...values };
if ($chatId && !$temporaryChatEnabled && !$chatId.startsWith('local:')) {
if ($chatId && !$temporaryChatEnabled && !isTemporaryChatId($chatId)) {
const res = await updateChatById(localStorage.token, $chatId, {}, chatVariables).catch(
(err) => {
console.error('[chat variables save]', err);
@@ -2845,7 +2846,7 @@
chatFiles = mergeFiles(chatFiles, createdChat?.chat?.files ?? []);
await onSelectEmbeddedChat?.(_chatId);
} else if ($temporaryChatEnabled) {
_chatId = `local:${$socket?.id}`;
_chatId = createTemporaryChatId($socket?.id);
await chatId.set(_chatId);
}
await tick();
@@ -3098,7 +3099,7 @@
// Only send terminal_id if the model has terminal capability enabled
const terminalEnabled = model.info?.meta?.capabilities?.terminal ?? true;
const useChatVariablesFallback =
!_chatId || $temporaryChatEnabled || _chatId.startsWith('local:');
!_chatId || $temporaryChatEnabled || isTemporaryChatId(_chatId);
const res = await generateOpenAIChatCompletion(
localStorage.token,
@@ -3503,7 +3504,7 @@
selectedFolder.set(null);
} else {
_chatId = `local:${$socket?.id}`; // Use socket id for temporary chat
_chatId = createTemporaryChatId($socket?.id);
await chatId.set(_chatId);
}
await tick();
+2 -1
View File
@@ -35,6 +35,7 @@
import ChatPlus from '../icons/ChatPlus.svelte';
import ChatCheck from '../icons/ChatCheck.svelte';
import Knobs from '../icons/Knobs.svelte';
import { isTemporaryChatId } from '$lib/utils/chatId';
const i18n = getContext('i18n');
@@ -247,7 +248,7 @@
</div>
</div>
{#if $temporaryChatEnabled && ($chatId ?? '').startsWith('local:')}
{#if $temporaryChatEnabled && isTemporaryChatId($chatId)}
<div class=" w-full z-30 text-center">
<div class="text-xs text-gray-500">{$i18n.t('Temporary Chat')}</div>
</div>
+10
View File
@@ -0,0 +1,10 @@
const TEMPORARY_CHAT_ID_PREFIX = 'temporary:';
const LEGACY_TEMPORARY_CHAT_ID_PREFIX = 'local:'; // Legacy temporary chat prefix.
export const createTemporaryChatId = (sessionId: string | undefined) =>
`${TEMPORARY_CHAT_ID_PREFIX}${sessionId}`;
export const isTemporaryChatId = (chatId: string | null | undefined) =>
!!chatId &&
(chatId.startsWith(TEMPORARY_CHAT_ID_PREFIX) ||
chatId.startsWith(LEGACY_TEMPORARY_CHAT_ID_PREFIX));
+2 -1
View File
@@ -54,6 +54,7 @@
import { getSessionUser, updateUserTimezone, userSignOut } from '$lib/apis/auths';
import { getAllTags } from '$lib/apis/chats';
import { chatCompletion } from '$lib/apis/openai';
import { isTemporaryChatId } from '$lib/utils/chatId';
import {
addOpenAIConnection,
removeOpenAIConnection,
@@ -497,7 +498,7 @@
// Skip events from temporary chats that are not the current chat.
// This prevents notifications from being sent to other tabs/devices
// for privacy, since temporary chats are not meant to be persisted or visible elsewhere.
const isTemporaryChat = event.chat_id?.startsWith('local:');
const isTemporaryChat = isTemporaryChatId(event.chat_id);
if (isTemporaryChat && event.chat_id !== $chatId) {
return;
}