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
+4 -1
View File
@@ -66,7 +66,10 @@ const cancelAutoRename = async (topicId: string) => {
const renameId = activeAutoRenames.get(topicId);
if (!renameId) return;
await $fetch(`/api/topic/auto-rename/cancel/${renameId}`, {
await $fetch(`/api/auto-rename/cancel`, {
body: {
renameId,
},
method: 'POST',
});
+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);
}
+1 -10
View File
@@ -49,16 +49,7 @@ const handleSubmit = async (message: string, model: ModelWithProvider | null) =>
const topic = await createTopic();
if (!topic) throw new Error('Failed to create topic');
autoRename(topic.id, message).then(async res => {
if (res.ok === false) {
console.error('Failed to auto-rename:', res.error);
await triplit.update('topics', topic.id, {
renaming: false,
});
return;
}
});
autoRename(topic.id, message);
await navigateTo(`/agent/${route.params.id}/topic/${topic.id}`);
+1 -10
View File
@@ -110,16 +110,7 @@ const handleChatSubmit = async (message: string, model: ModelWithProvider | null
await navigateTo(`/agent/${agent.id}/topic/${topic.id}`);
autoRename(topic.id, message).then(async res => {
if (res.ok === false) {
console.error('Failed to auto-rename:', res.error);
await triplit.update('topics', topic.id, {
renaming: false,
});
return;
}
});
autoRename(topic.id, message);
return sendMessage(message, topic, [], agent, model.provider, model).then(async res => {
if (res.ok === false) {