|
@@ -126,9 +126,11 @@ export function useChat() {
|
|
|
const numId = Number(strId);
|
|
const numId = Number(strId);
|
|
|
if (!numId) return;
|
|
if (!numId) return;
|
|
|
const data = await getConversationMessages(numId);
|
|
const data = await getConversationMessages(numId);
|
|
|
|
|
+ if (activeConversationId.value !== strId) return;
|
|
|
const normalized = normalizeApiMessages(data?.items);
|
|
const normalized = normalizeApiMessages(data?.items);
|
|
|
messages.value = normalized.length ? normalized : [...defaultMessages];
|
|
messages.value = normalized.length ? normalized : [...defaultMessages];
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
|
|
+ if (activeConversationId.value !== strId) return;
|
|
|
messages.value = [...defaultMessages];
|
|
messages.value = [...defaultMessages];
|
|
|
if (err?.message !== "session_expired") {
|
|
if (err?.message !== "session_expired") {
|
|
|
conversationsError.value = "Erro ao carregar mensagens da conversa.";
|
|
conversationsError.value = "Erro ao carregar mensagens da conversa.";
|
|
@@ -178,16 +180,23 @@ export function useChat() {
|
|
|
async function exportConversation(id) {
|
|
async function exportConversation(id) {
|
|
|
const numId = Number(String(id ?? "").trim());
|
|
const numId = Number(String(id ?? "").trim());
|
|
|
if (!numId) return;
|
|
if (!numId) return;
|
|
|
- const data = await exportConversationAPI(numId);
|
|
|
|
|
- const conv = conversations.value.find((c) => c.id === String(id));
|
|
|
|
|
- const filename = `conversa-${conv?.title?.slice(0, 40).replace(/[^a-zA-Z0-9À-ÿ\s]/g, "").trim().replace(/\s+/g, "-") || numId}.md`;
|
|
|
|
|
- const blob = new Blob([data.markdown ?? ""], { type: "text/markdown" });
|
|
|
|
|
- const url = URL.createObjectURL(blob);
|
|
|
|
|
- const a = document.createElement("a");
|
|
|
|
|
- a.href = url;
|
|
|
|
|
- a.download = filename;
|
|
|
|
|
- a.click();
|
|
|
|
|
- URL.revokeObjectURL(url);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = await exportConversationAPI(numId);
|
|
|
|
|
+ const conv = conversations.value.find((c) => c.id === String(id));
|
|
|
|
|
+ const filename = `conversa-${conv?.title?.slice(0, 40).replace(/[^a-zA-Z0-9À-ÿ\s]/g, "").trim().replace(/\s+/g, "-") || numId}.md`;
|
|
|
|
|
+ const blob = new Blob([data.markdown ?? ""], { type: "text/markdown" });
|
|
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
|
|
+ const a = document.createElement("a");
|
|
|
|
|
+ a.href = url;
|
|
|
|
|
+ a.download = filename;
|
|
|
|
|
+ a.click();
|
|
|
|
|
+ URL.revokeObjectURL(url);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ if (err?.message !== "session_expired") {
|
|
|
|
|
+ toast.erro("Não foi possível exportar a conversa.");
|
|
|
|
|
+ console.warn("[useChat] exportConversation:", err);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function searchConversations(query) {
|
|
function searchConversations(query) {
|
|
@@ -232,6 +241,9 @@ export function useChat() {
|
|
|
try {
|
|
try {
|
|
|
const title = trimmed.slice(0, 60);
|
|
const title = trimmed.slice(0, 60);
|
|
|
const conv = await createConversation(title);
|
|
const conv = await createConversation(title);
|
|
|
|
|
+ if (_streamAbort !== abortController) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
convId = conv.id;
|
|
convId = conv.id;
|
|
|
activeConversationId.value = String(convId);
|
|
activeConversationId.value = String(convId);
|
|
|
const now = Date.now();
|
|
const now = Date.now();
|