@meistrari/chat-nuxt 4.6.0-rc.5 → 4.6.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../message-reasoning.js";
|
|
9
9
|
import {
|
|
10
10
|
beginAssistantMessageRetry,
|
|
11
|
+
createOptimisticMessagePair,
|
|
11
12
|
markPendingAssistantMessagesFailed,
|
|
12
13
|
markPendingAssistantMessagesInterrupted,
|
|
13
14
|
restoreAssistantMessageAfterRetryFailure,
|
|
@@ -531,36 +532,14 @@ export function useChat(options = {}, adapter = {}) {
|
|
|
531
532
|
const conversationId = currentConversation.value?.id ?? "";
|
|
532
533
|
const existingOptimisticUserMessage = queuedSend ? messages.value.find((message) => message.id === queuedSend.optimisticIds.user) : void 0;
|
|
533
534
|
const existingOptimisticAssistantMessage = queuedSend ? messages.value.find((message) => message.id === queuedSend.optimisticIds.assistant) : void 0;
|
|
534
|
-
const
|
|
535
|
-
id: crypto.randomUUID(),
|
|
535
|
+
const optimisticPair = createOptimisticMessagePair({
|
|
536
536
|
conversationId,
|
|
537
|
-
role: "user",
|
|
538
537
|
content,
|
|
539
|
-
status: "completed",
|
|
540
|
-
reasoningData: null,
|
|
541
538
|
files: filesWithSource,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
generationStartedAt: null,
|
|
547
|
-
updatedAt: null
|
|
548
|
-
};
|
|
549
|
-
const optimisticAssistantMessage = existingOptimisticAssistantMessage ?? {
|
|
550
|
-
id: crypto.randomUUID(),
|
|
551
|
-
conversationId,
|
|
552
|
-
role: "assistant",
|
|
553
|
-
content: "",
|
|
554
|
-
status: "pending",
|
|
555
|
-
reasoningData: null,
|
|
556
|
-
files: null,
|
|
557
|
-
externalUuid: null,
|
|
558
|
-
ttft: null,
|
|
559
|
-
createdBy: null,
|
|
560
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
561
|
-
generationStartedAt: /* @__PURE__ */ new Date(),
|
|
562
|
-
updatedAt: null
|
|
563
|
-
};
|
|
539
|
+
createdBy: authUser.value?.email ?? null
|
|
540
|
+
});
|
|
541
|
+
const optimisticUserMessage = existingOptimisticUserMessage ?? optimisticPair.user;
|
|
542
|
+
const optimisticAssistantMessage = existingOptimisticAssistantMessage ?? optimisticPair.assistant;
|
|
564
543
|
streamingMessageId.value = optimisticAssistantMessage.id;
|
|
565
544
|
directStream.beginMessage();
|
|
566
545
|
if (!queuedSend)
|
|
@@ -8,6 +8,7 @@ import { applyLightweightPart, createLightweightTurn } from "../../types/schemas
|
|
|
8
8
|
import { applyMessagePartsEvent as applyLightweightEvent, createMessagePartsAccumulator as createLightweightAccumulator } from "../../lightweight/messages/composables/use-direct-stream.js";
|
|
9
9
|
import { resolveReasoningDisplayMessages } from "../message-reasoning.js";
|
|
10
10
|
import { overlayStreamedMessage } from "../stream-overlay.js";
|
|
11
|
+
import { createOptimisticMessagePair } from "../message-state.js";
|
|
11
12
|
export const EMPTY_CHAT_DEBUG_PLAYBACK_STATE = {
|
|
12
13
|
messages: [],
|
|
13
14
|
loading: false,
|
|
@@ -589,6 +590,17 @@ export function createChatDebugScenarios(baseTime = Date.now()) {
|
|
|
589
590
|
role: "assistant",
|
|
590
591
|
status: "pending"
|
|
591
592
|
});
|
|
593
|
+
const optimisticSendIds = ["ffffffff-0000-4000-8000-000000000001", "00000000-0000-4000-8000-000000000002"];
|
|
594
|
+
const optimisticSend = createOptimisticMessagePair({
|
|
595
|
+
conversationId: "debug-conversation",
|
|
596
|
+
content: "Resuma o parecer jur\xEDdico anexado em tr\xEAs pontos.",
|
|
597
|
+
files: null,
|
|
598
|
+
createdBy: "debugger@tela.com",
|
|
599
|
+
now: new Date(baseTime),
|
|
600
|
+
createId: () => optimisticSendIds.shift()
|
|
601
|
+
});
|
|
602
|
+
const acknowledgedSendAt = new Date(baseTime + 40);
|
|
603
|
+
const acknowledgedAssistantAt = new Date(acknowledgedSendAt.getTime() + 1);
|
|
592
604
|
const allToolsReasoning = allToolTypeReasoning();
|
|
593
605
|
const allToolsIntro = allToolsReasoning[0];
|
|
594
606
|
const allToolGroups = allToolsReasoning.slice(1);
|
|
@@ -762,6 +774,99 @@ export function createChatDebugScenarios(baseTime = Date.now()) {
|
|
|
762
774
|
})
|
|
763
775
|
]
|
|
764
776
|
},
|
|
777
|
+
{
|
|
778
|
+
id: "optimistic-send-order",
|
|
779
|
+
name: "Optimistic send order",
|
|
780
|
+
intent: 'A fresh send renders prompt then "Trabalhando" from the first frame, and keeps that order when the server swaps in persisted ids.',
|
|
781
|
+
durationMs: 5500,
|
|
782
|
+
events: [
|
|
783
|
+
event({
|
|
784
|
+
id: "optimistic-send-user",
|
|
785
|
+
atMs: 0,
|
|
786
|
+
label: "Optimistic user message",
|
|
787
|
+
tone: "user",
|
|
788
|
+
type: "message.upsert",
|
|
789
|
+
message: optimisticSend.user
|
|
790
|
+
}),
|
|
791
|
+
event({
|
|
792
|
+
id: "optimistic-send-assistant",
|
|
793
|
+
atMs: 0,
|
|
794
|
+
label: "Optimistic assistant",
|
|
795
|
+
tone: "assistant",
|
|
796
|
+
type: "message.upsert",
|
|
797
|
+
message: optimisticSend.assistant
|
|
798
|
+
}),
|
|
799
|
+
event({
|
|
800
|
+
id: "optimistic-send-stream",
|
|
801
|
+
atMs: 0,
|
|
802
|
+
label: "Stream target",
|
|
803
|
+
tone: "neutral",
|
|
804
|
+
type: "playback.patch",
|
|
805
|
+
patch: { streamingActiveMessageId: optimisticSend.assistant.id }
|
|
806
|
+
}),
|
|
807
|
+
event({
|
|
808
|
+
id: "optimistic-send-ack-user",
|
|
809
|
+
atMs: 2500,
|
|
810
|
+
label: "Server persists user",
|
|
811
|
+
tone: "user",
|
|
812
|
+
type: "message.patch",
|
|
813
|
+
messageId: optimisticSend.user.id,
|
|
814
|
+
patch: { id: "optimistic-send-user", createdAt: acknowledgedSendAt }
|
|
815
|
+
}),
|
|
816
|
+
event({
|
|
817
|
+
id: "optimistic-send-ack-assistant",
|
|
818
|
+
atMs: 2500,
|
|
819
|
+
label: "Server persists assistant",
|
|
820
|
+
tone: "assistant",
|
|
821
|
+
type: "message.patch",
|
|
822
|
+
messageId: optimisticSend.assistant.id,
|
|
823
|
+
patch: { id: "optimistic-send-assistant", createdAt: acknowledgedAssistantAt, generationStartedAt: acknowledgedAssistantAt }
|
|
824
|
+
}),
|
|
825
|
+
event({
|
|
826
|
+
id: "optimistic-send-ack-stream",
|
|
827
|
+
atMs: 2500,
|
|
828
|
+
label: "Stream target persisted",
|
|
829
|
+
tone: "neutral",
|
|
830
|
+
type: "playback.patch",
|
|
831
|
+
patch: { streamingActiveMessageId: "optimistic-send-assistant" }
|
|
832
|
+
}),
|
|
833
|
+
event({
|
|
834
|
+
id: "optimistic-send-reasoning",
|
|
835
|
+
atMs: 3300,
|
|
836
|
+
label: "Reasoning starts",
|
|
837
|
+
tone: "reasoning",
|
|
838
|
+
type: "message.patch",
|
|
839
|
+
messageId: "optimistic-send-assistant",
|
|
840
|
+
patch: { reasoningData: ["Lendo o parecer anexado"] }
|
|
841
|
+
}),
|
|
842
|
+
event({
|
|
843
|
+
id: "optimistic-send-answer",
|
|
844
|
+
atMs: 4300,
|
|
845
|
+
label: "Answer",
|
|
846
|
+
tone: "assistant",
|
|
847
|
+
type: "message.patch",
|
|
848
|
+
messageId: "optimistic-send-assistant",
|
|
849
|
+
patch: { content: "1. O contrato \xE9 v\xE1lido.\n2. A cl\xE1usula penal \xE9 abusiva.\n3. Cabe renegocia\xE7\xE3o." }
|
|
850
|
+
}),
|
|
851
|
+
event({
|
|
852
|
+
id: "optimistic-send-complete",
|
|
853
|
+
atMs: 5e3,
|
|
854
|
+
label: "Message completed",
|
|
855
|
+
tone: "assistant",
|
|
856
|
+
type: "message.patch",
|
|
857
|
+
messageId: "optimistic-send-assistant",
|
|
858
|
+
patch: { status: "completed", updatedAt: new Date(baseTime + 5e3) }
|
|
859
|
+
}),
|
|
860
|
+
event({
|
|
861
|
+
id: "optimistic-send-close",
|
|
862
|
+
atMs: 5e3,
|
|
863
|
+
label: "Stream closes",
|
|
864
|
+
tone: "neutral",
|
|
865
|
+
type: "playback.patch",
|
|
866
|
+
patch: { streamingActiveMessageId: null }
|
|
867
|
+
})
|
|
868
|
+
]
|
|
869
|
+
},
|
|
765
870
|
{
|
|
766
871
|
id: "lightweight-stream",
|
|
767
872
|
name: "Lightweight stream",
|
|
@@ -2,6 +2,17 @@ import type { Message } from '../types/schemas/chat/conversations.js';
|
|
|
2
2
|
export declare const INTERRUPTED_GENERATION_TEXT = "_Gera\u00E7\u00E3o interrompida pelo usu\u00E1rio_";
|
|
3
3
|
export declare const GENERATION_FAILED_TEXT = "Erro: N\u00E3o foi poss\u00EDvel concluir a resposta";
|
|
4
4
|
export declare const CANCELLATION_FAILED_TEXT = "Erro: N\u00E3o foi poss\u00EDvel cancelar a mensagem";
|
|
5
|
+
export declare function createOptimisticMessagePair(input: {
|
|
6
|
+
conversationId: string;
|
|
7
|
+
content: string;
|
|
8
|
+
files: Message['files'];
|
|
9
|
+
createdBy: string | null;
|
|
10
|
+
now?: Date;
|
|
11
|
+
createId?: () => string;
|
|
12
|
+
}): {
|
|
13
|
+
user: Message;
|
|
14
|
+
assistant: Message;
|
|
15
|
+
};
|
|
5
16
|
export declare function markPendingAssistantMessagesInterrupted(messages: Message[]): Message[];
|
|
6
17
|
export declare function markPendingAssistantMessagesFailed(messages: Message[], content?: string): Message[];
|
|
7
18
|
export declare function beginAssistantMessageRetry(messages: Message[], messageId: string): {
|
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
export const INTERRUPTED_GENERATION_TEXT = "_Gera\xE7\xE3o interrompida pelo usu\xE1rio_";
|
|
2
2
|
export const GENERATION_FAILED_TEXT = "Erro: N\xE3o foi poss\xEDvel concluir a resposta";
|
|
3
3
|
export const CANCELLATION_FAILED_TEXT = "Erro: N\xE3o foi poss\xEDvel cancelar a mensagem";
|
|
4
|
+
export function createOptimisticMessagePair(input) {
|
|
5
|
+
const createId = input.createId ?? (() => crypto.randomUUID());
|
|
6
|
+
const userCreatedAt = input.now ?? /* @__PURE__ */ new Date();
|
|
7
|
+
const assistantCreatedAt = new Date(userCreatedAt.getTime() + 1);
|
|
8
|
+
return {
|
|
9
|
+
user: {
|
|
10
|
+
id: createId(),
|
|
11
|
+
conversationId: input.conversationId,
|
|
12
|
+
role: "user",
|
|
13
|
+
content: input.content,
|
|
14
|
+
status: "completed",
|
|
15
|
+
reasoningData: null,
|
|
16
|
+
files: input.files,
|
|
17
|
+
externalUuid: null,
|
|
18
|
+
ttft: null,
|
|
19
|
+
createdBy: input.createdBy,
|
|
20
|
+
createdAt: userCreatedAt,
|
|
21
|
+
generationStartedAt: null,
|
|
22
|
+
updatedAt: null
|
|
23
|
+
},
|
|
24
|
+
assistant: {
|
|
25
|
+
id: createId(),
|
|
26
|
+
conversationId: input.conversationId,
|
|
27
|
+
role: "assistant",
|
|
28
|
+
content: "",
|
|
29
|
+
status: "pending",
|
|
30
|
+
reasoningData: null,
|
|
31
|
+
files: null,
|
|
32
|
+
externalUuid: null,
|
|
33
|
+
ttft: null,
|
|
34
|
+
createdBy: null,
|
|
35
|
+
createdAt: assistantCreatedAt,
|
|
36
|
+
generationStartedAt: assistantCreatedAt,
|
|
37
|
+
updatedAt: null
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
4
41
|
export function markPendingAssistantMessagesInterrupted(messages) {
|
|
5
42
|
return messages.map((message) => {
|
|
6
43
|
if (message.role !== "assistant" || message.status !== "pending")
|