refactor: cleanup auto-rename code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user