@meistrari/chat-nuxt 4.6.0-rc.4 → 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 +1 -1
- package/dist/runtime/embed/components/mobile/chat-mobile-shell.d.vue.ts +2 -2
- package/dist/runtime/embed/components/mobile/chat-mobile-shell.vue.d.ts +2 -2
- package/dist/runtime/messages/components/reasoning/chat-reasoning-message.vue +23 -7
- package/dist/runtime/messages/components/reasoning/chat-reasoning-thought.vue +3 -0
- package/dist/runtime/messages/composables/chat.js +6 -27
- package/dist/runtime/messages/debug/chat-debug-scenarios.js +105 -0
- package/dist/runtime/messages/message-reasoning.d.ts +0 -1
- package/dist/runtime/messages/message-reasoning.js +21 -10
- package/dist/runtime/messages/message-state.d.ts +11 -0
- package/dist/runtime/messages/message-state.js +37 -0
- package/dist/runtime/messages/reasoning-step-key.js +2 -0
- package/dist/runtime/messages/reasoning.d.ts +5 -1
- package/dist/runtime/types/schemas/integrations/lightweight.js +2 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -67,8 +67,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
67
67
|
copyLink: () => any;
|
|
68
68
|
debug: () => any;
|
|
69
69
|
selectConversation: (id: string) => any;
|
|
70
|
-
send: (content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any;
|
|
71
70
|
settings: () => any;
|
|
71
|
+
send: (content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any;
|
|
72
72
|
tabChange: (tab: TopbarTab) => any;
|
|
73
73
|
newConversation: (groupId?: string | null | undefined) => any;
|
|
74
74
|
switchWorkspace: () => any;
|
|
@@ -88,8 +88,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
88
88
|
onCopyLink?: (() => any) | undefined;
|
|
89
89
|
onDebug?: (() => any) | undefined;
|
|
90
90
|
onSelectConversation?: ((id: string) => any) | undefined;
|
|
91
|
-
onSend?: ((content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any) | undefined;
|
|
92
91
|
onSettings?: (() => any) | undefined;
|
|
92
|
+
onSend?: ((content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any) | undefined;
|
|
93
93
|
"onUpdate:selectedModel"?: ((value: string | null) => any) | undefined;
|
|
94
94
|
"onUpdate:selectedReasoningEffort"?: ((value: any) => any) | undefined;
|
|
95
95
|
onTabChange?: ((tab: TopbarTab) => any) | undefined;
|
|
@@ -67,8 +67,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
67
67
|
copyLink: () => any;
|
|
68
68
|
debug: () => any;
|
|
69
69
|
selectConversation: (id: string) => any;
|
|
70
|
-
send: (content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any;
|
|
71
70
|
settings: () => any;
|
|
71
|
+
send: (content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any;
|
|
72
72
|
tabChange: (tab: TopbarTab) => any;
|
|
73
73
|
newConversation: (groupId?: string | null | undefined) => any;
|
|
74
74
|
switchWorkspace: () => any;
|
|
@@ -88,8 +88,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
88
88
|
onCopyLink?: (() => any) | undefined;
|
|
89
89
|
onDebug?: (() => any) | undefined;
|
|
90
90
|
onSelectConversation?: ((id: string) => any) | undefined;
|
|
91
|
-
onSend?: ((content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any) | undefined;
|
|
92
91
|
onSettings?: (() => any) | undefined;
|
|
92
|
+
onSend?: ((content: string, files: FileUploadInput[], agentInputs?: TelaAgentExecutionInput[] | undefined) => any) | undefined;
|
|
93
93
|
"onUpdate:selectedModel"?: ((value: string | null) => any) | undefined;
|
|
94
94
|
"onUpdate:selectedReasoningEffort"?: ((value: any) => any) | undefined;
|
|
95
95
|
onTabChange?: ((tab: TopbarTab) => any) | undefined;
|
|
@@ -27,24 +27,25 @@ const TOOL_WIDGETS = {
|
|
|
27
27
|
"grep": ChatGrepWidget,
|
|
28
28
|
"generic": ChatGenericToolWidget
|
|
29
29
|
};
|
|
30
|
-
const
|
|
30
|
+
const toolGroup = computed(() => typeof props.step !== "string" && props.step.type === "tool_group" ? props.step : null);
|
|
31
|
+
const displayToolUse = computed(() => toolGroup.value ? withReportedToolInput(toolGroup.value.toolUse, toolGroup.value.toolResult) : null);
|
|
31
32
|
const toolDisplay = computed(() => {
|
|
32
|
-
if (
|
|
33
|
+
if (!toolGroup.value)
|
|
33
34
|
return null;
|
|
34
|
-
return resolveToolDisplay(
|
|
35
|
+
return resolveToolDisplay(toolGroup.value.toolUse);
|
|
35
36
|
});
|
|
36
37
|
const stepWasExecuted = computed(
|
|
37
|
-
() =>
|
|
38
|
+
() => toolGroup.value?.toolResult !== void 0 && !props.isActive
|
|
38
39
|
);
|
|
39
40
|
const stepMeta = computed(() => {
|
|
40
|
-
if (
|
|
41
|
+
if (!toolGroup.value)
|
|
41
42
|
return null;
|
|
42
43
|
return resolveToolMeta(displayToolUse.value);
|
|
43
44
|
});
|
|
44
45
|
const stepTitle = computed(() => {
|
|
45
|
-
if (
|
|
46
|
+
if (!toolGroup.value)
|
|
46
47
|
return "";
|
|
47
|
-
return resolveToolTitle(
|
|
48
|
+
return resolveToolTitle(toolGroup.value.toolUse, stepWasExecuted.value);
|
|
48
49
|
});
|
|
49
50
|
</script>
|
|
50
51
|
|
|
@@ -61,6 +62,21 @@ const stepTitle = computed(() => {
|
|
|
61
62
|
/>
|
|
62
63
|
</div>
|
|
63
64
|
|
|
65
|
+
<div v-else-if="step.type === 'thinking'" class="chat-reasoning-step">
|
|
66
|
+
<ChatReasoningToolRow
|
|
67
|
+
:title="isActive && !completed ? 'Pensando' : 'Pensou'"
|
|
68
|
+
has-result
|
|
69
|
+
:is-active="isActive && !completed"
|
|
70
|
+
>
|
|
71
|
+
<ChatThinkingWidget
|
|
72
|
+
class="chat-reasoning-thinking-detail"
|
|
73
|
+
:content="step.text"
|
|
74
|
+
:is-active="isActive"
|
|
75
|
+
:completed="completed"
|
|
76
|
+
/>
|
|
77
|
+
</ChatReasoningToolRow>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
64
80
|
<div v-else class="chat-reasoning-step">
|
|
65
81
|
<ChatReasoningToolRow
|
|
66
82
|
:title="stepTitle"
|
|
@@ -34,6 +34,9 @@ const currentStepName = computed(() => {
|
|
|
34
34
|
if (step && typeof step !== "string" && step.type === "tool_group") {
|
|
35
35
|
return resolveToolTitle(step.toolUse, false);
|
|
36
36
|
}
|
|
37
|
+
if (step && typeof step !== "string" && step.type === "thinking") {
|
|
38
|
+
return "Pensando";
|
|
39
|
+
}
|
|
37
40
|
if (step && typeof step === "string") {
|
|
38
41
|
const truncated = step.length > TEXT_TRUNCATE_LENGTH ? `${step.slice(0, TEXT_TRUNCATE_LENGTH)}...` : step;
|
|
39
42
|
return truncated;
|
|
@@ -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,7 +2,6 @@ import type { Message } from '../types/schemas/chat/conversations.js';
|
|
|
2
2
|
import type { ReasoningStep } from './reasoning.js';
|
|
3
3
|
type ParsedReasoning = {
|
|
4
4
|
steps: ReasoningStep[];
|
|
5
|
-
thinkingTexts: Set<string>;
|
|
6
5
|
currentAnswerParts: string[];
|
|
7
6
|
currentAnswerStepTexts: Set<string>;
|
|
8
7
|
};
|
|
@@ -7,6 +7,8 @@ export function createReasoningCache() {
|
|
|
7
7
|
function getReasoningStepKey(step) {
|
|
8
8
|
if (typeof step === "string")
|
|
9
9
|
return `text:${step.slice(0, 100)}`;
|
|
10
|
+
if (step.type === "thinking")
|
|
11
|
+
return `thinking:${step.text.slice(0, 100)}`;
|
|
10
12
|
return `tool:${step.toolUse.id}`;
|
|
11
13
|
}
|
|
12
14
|
function groupReasoningSteps(parsedSteps) {
|
|
@@ -15,6 +17,14 @@ function groupReasoningSteps(parsedSteps) {
|
|
|
15
17
|
for (const step of parsedSteps) {
|
|
16
18
|
if (typeof step === "string") {
|
|
17
19
|
grouped.push(step);
|
|
20
|
+
} else if ("type" in step) {
|
|
21
|
+
const previous = grouped.at(-1);
|
|
22
|
+
if (typeof previous === "object" && previous.type === "thinking")
|
|
23
|
+
grouped[grouped.length - 1] = { type: "thinking", text: `${previous.text}
|
|
24
|
+
|
|
25
|
+
${step.text}` };
|
|
26
|
+
else
|
|
27
|
+
grouped.push(step);
|
|
18
28
|
} else if ("name" in step && "input" in step) {
|
|
19
29
|
pendingToolUses.set(step.id, step);
|
|
20
30
|
grouped.push({
|
|
@@ -77,7 +87,7 @@ function parseReasoningFromPolling(reasoning) {
|
|
|
77
87
|
const allSteps = [];
|
|
78
88
|
const seenContentIds = /* @__PURE__ */ new Set();
|
|
79
89
|
const seenTexts = /* @__PURE__ */ new Set();
|
|
80
|
-
const
|
|
90
|
+
const seenThoughts = /* @__PURE__ */ new Set();
|
|
81
91
|
let currentAnswerParts = [];
|
|
82
92
|
let currentAnswerStepTexts = /* @__PURE__ */ new Set();
|
|
83
93
|
for (const item of reasoning) {
|
|
@@ -117,17 +127,18 @@ function parseReasoningFromPolling(reasoning) {
|
|
|
117
127
|
if (!contentPart || typeof contentPart !== "object")
|
|
118
128
|
continue;
|
|
119
129
|
const part = contentPart;
|
|
120
|
-
if (
|
|
121
|
-
if (part.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
if (part.type === "thinking" && typeof part.text === "string") {
|
|
131
|
+
if (seenThoughts.has(part.text))
|
|
132
|
+
continue;
|
|
133
|
+
seenThoughts.add(part.text);
|
|
134
|
+
allSteps.push({ type: "thinking", text: part.text });
|
|
135
|
+
} else if (part.type === "text" && typeof part.text === "string") {
|
|
136
|
+
answerParts.push(part.text);
|
|
125
137
|
if (seenTexts.has(part.text))
|
|
126
138
|
continue;
|
|
127
139
|
seenTexts.add(part.text);
|
|
128
140
|
allSteps.push(part.text);
|
|
129
|
-
|
|
130
|
-
answerStepTexts.add(part.text);
|
|
141
|
+
answerStepTexts.add(part.text);
|
|
131
142
|
} else if (part.type === "tool_use" && part.id && part.name) {
|
|
132
143
|
const toolId = part.id;
|
|
133
144
|
if (seenContentIds.has(`tool_use:${toolId}`))
|
|
@@ -183,7 +194,7 @@ function parseReasoningFromPolling(reasoning) {
|
|
|
183
194
|
});
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
|
-
return { steps: groupReasoningSteps(allSteps),
|
|
197
|
+
return { steps: groupReasoningSteps(allSteps), currentAnswerParts, currentAnswerStepTexts };
|
|
187
198
|
}
|
|
188
199
|
export function resolveReasoningDisplayMessages(messages, cache = createReasoningCache()) {
|
|
189
200
|
pruneReasoningCache(cache, messages);
|
|
@@ -198,7 +209,7 @@ export function resolveReasoningDisplayMessages(messages, cache = createReasonin
|
|
|
198
209
|
const key = getReasoningStepKey(step);
|
|
199
210
|
if (renderedSteps.has(key))
|
|
200
211
|
continue;
|
|
201
|
-
if (typeof step === "string" && currentAnswerMatches && parsed.currentAnswerStepTexts.has(step)
|
|
212
|
+
if (typeof step === "string" && currentAnswerMatches && parsed.currentAnswerStepTexts.has(step)) {
|
|
202
213
|
continue;
|
|
203
214
|
}
|
|
204
215
|
renderedSteps.add(key);
|
|
@@ -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")
|
|
@@ -14,7 +14,11 @@ export type ToolGroup = {
|
|
|
14
14
|
toolUse: ToolUse;
|
|
15
15
|
toolResult?: ToolResult;
|
|
16
16
|
};
|
|
17
|
-
export type
|
|
17
|
+
export type ThinkingStep = {
|
|
18
|
+
type: 'thinking';
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
export type ReasoningStep = string | ToolGroup | ThinkingStep;
|
|
18
22
|
/**
|
|
19
23
|
* A turn that is still working towards its first output has no reasoning of its
|
|
20
24
|
* own yet, so the preparing steps stand in. That makes the wait read as an agent
|
|
@@ -99,7 +99,7 @@ export function applyLightweightPart(state, part, sequence, timestamp) {
|
|
|
99
99
|
const id = `${state.runId}:thinking:${typeof part.id === 'string' ? part.id : 'default'}`;
|
|
100
100
|
const existing = state.reasoning.find(item => item.uuid === id)?.message.content[0];
|
|
101
101
|
const text = existing && 'text' in existing && typeof existing.text === 'string' ? existing.text : '';
|
|
102
|
-
upsertReasoning(state, reasoningItem(state.sessionId, id, { type: '
|
|
102
|
+
upsertReasoning(state, reasoningItem(state.sessionId, id, { type: 'thinking', text: text + delta }, timestamp));
|
|
103
103
|
return true;
|
|
104
104
|
}
|
|
105
105
|
if (part.type === 'tool-call' && typeof part.toolCallId === 'string') {
|
|
@@ -134,7 +134,7 @@ export function lightweightThreadReasoning(sessionId, runId, events) {
|
|
|
134
134
|
for (const [index, event] of events.entries()) {
|
|
135
135
|
const timestamp = typeof event.timestamp === 'number' ? event.timestamp : 0;
|
|
136
136
|
if ((event.type === 'thinking' || event.type === 'text') && typeof event.text === 'string') {
|
|
137
|
-
upsertReasoning(state, reasoningItem(sessionId, `${runId}:${event.type}:${event.sequenceIndex ?? index}`, { type: 'text', text: event.text }, timestamp));
|
|
137
|
+
upsertReasoning(state, reasoningItem(sessionId, `${runId}:${event.type}:${event.sequenceIndex ?? index}`, { type: event.type === 'thinking' ? 'thinking' : 'text', text: event.text }, timestamp));
|
|
138
138
|
}
|
|
139
139
|
else if (event.type === 'tool_call') {
|
|
140
140
|
applyLightweightPart(state, { type: 'tool-call', toolCallId: event.callId, toolName: event.toolName, input: event.arguments }, index, timestamp);
|