Skip to content

Commit c44699d

Browse files
committed
fix: auto-save chat controls params on change
1 parent 782d2f2 commit c44699d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@
175175
let chatFiles = [];
176176
let files = [];
177177
let params = {};
178+
let oldParams = {};
179+
let paramsDebounceTimer: ReturnType<typeof setTimeout> | null = null;
180+
181+
$: if (!equal(params, oldParams)) {
182+
oldParams = structuredClone(params);
183+
if (!loading && !$temporaryChatEnabled && $chatId) {
184+
if (paramsDebounceTimer) clearTimeout(paramsDebounceTimer);
185+
paramsDebounceTimer = setTimeout(saveParamsHandler, 500);
186+
}
187+
}
178188
179189
$: if (chatIdProp) {
180190
navigateHandler();
@@ -189,6 +199,11 @@
189199
190200
loading = true;
191201
202+
if (paramsDebounceTimer) {
203+
clearTimeout(paramsDebounceTimer);
204+
paramsDebounceTimer = null;
205+
}
206+
192207
prompt = '';
193208
messageInput?.setText('');
194209
@@ -2720,6 +2735,14 @@
27202735
return _chatId;
27212736
};
27222737
2738+
const saveParamsHandler = async () => {
2739+
const _chatId = $chatId;
2740+
if (!_chatId || $temporaryChatEnabled || loading) return;
2741+
await updateChatById(localStorage.token, _chatId, {
2742+
params: params
2743+
});
2744+
};
2745+
27232746
const saveChatHandler = async (_chatId, history) => {
27242747
if ($chatId == _chatId) {
27252748
if (!$temporaryChatEnabled) {

0 commit comments

Comments
 (0)