refactor: cleanup auto-rename code

This commit is contained in:
Zoe
2026-02-25 20:38:55 +00:00
parent e4536cbb8c
commit c3370c27a7
6 changed files with 71 additions and 40 deletions
+14 -7
View File
@@ -412,10 +412,6 @@ export const useChat = (agentId: string) => {
return Err(AutoRenameError.NoModelSelected);
}
await triplit.update('topics', topicId, {
renaming: true
});
const modelResult = await attempt(triplit.fetchOne(triplit.query('models').Where('id', '=', settings.value.systemAssistants.rename.modelId).Include('provider')));
if (modelResult.ok === false) {
@@ -453,19 +449,30 @@ export const useChat = (agentId: string) => {
}
}
await triplit.update('topics', topicId, {
renaming: true
});
try {
const res = await $fetch(`/api/topic/auto-rename`, {
const res = await $fetch(`/api/auto-rename/${topicId}`, {
method: 'POST',
body: JSON.stringify({
modelId: model.id,
topicId,
prompt,
providerApiKey,
}),
});
}) as { ok: true, renameId: string } | { ok: false, code: string };
if (!res.ok) {
console.error('Failed to auto-rename:', res.code);
return Err(AutoRenameError.FailedToGenerate);
}
return Ok(res.renameId);
} catch (error) {
triplit.update('topics', topicId, {
renaming: false,
});
console.error('Failed to auto-rename:', error);
return Err(AutoRenameError.FailedToGenerate);
}