flowdit-chatbot-library 1.0.0
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/LICENSE +21 -0
- package/README.md +218 -0
- package/dist/assets/data/types/index.d.ts +2 -0
- package/dist/assets/data/types/index.d.ts.map +1 -0
- package/dist/assets/data/types/index.js +2 -0
- package/dist/assets/data/types/index.js.map +1 -0
- package/dist/assets/data/types/redux/action.d.ts +8 -0
- package/dist/assets/data/types/redux/action.d.ts.map +1 -0
- package/dist/assets/data/types/redux/action.js +9 -0
- package/dist/assets/data/types/redux/action.js.map +1 -0
- package/dist/assets/data/types/redux/index.d.ts +2 -0
- package/dist/assets/data/types/redux/index.d.ts.map +1 -0
- package/dist/assets/data/types/redux/index.js +2 -0
- package/dist/assets/data/types/redux/index.js.map +1 -0
- package/dist/assets/data/types/vm/chatbot.d.ts +5 -0
- package/dist/assets/data/types/vm/chatbot.d.ts.map +1 -0
- package/dist/assets/data/types/vm/chatbot.js +8 -0
- package/dist/assets/data/types/vm/chatbot.js.map +1 -0
- package/dist/assets/data/types/vm/index.d.ts +2 -0
- package/dist/assets/data/types/vm/index.d.ts.map +1 -0
- package/dist/assets/data/types/vm/index.js +2 -0
- package/dist/assets/data/types/vm/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/redux/Provider.d.ts +11 -0
- package/dist/redux/Provider.d.ts.map +1 -0
- package/dist/redux/Provider.js +12 -0
- package/dist/redux/Provider.js.map +1 -0
- package/dist/redux/actions/index.d.ts +8 -0
- package/dist/redux/actions/index.d.ts.map +1 -0
- package/dist/redux/actions/index.js +73 -0
- package/dist/redux/actions/index.js.map +1 -0
- package/dist/redux/hooks.d.ts +6 -0
- package/dist/redux/hooks.d.ts.map +1 -0
- package/dist/redux/hooks.js +27 -0
- package/dist/redux/hooks.js.map +1 -0
- package/dist/redux/reducers/actions/general.d.ts +7 -0
- package/dist/redux/reducers/actions/general.d.ts.map +1 -0
- package/dist/redux/reducers/actions/general.js +16 -0
- package/dist/redux/reducers/actions/general.js.map +1 -0
- package/dist/redux/reducers/actions/index.d.ts +5 -0
- package/dist/redux/reducers/actions/index.d.ts.map +1 -0
- package/dist/redux/reducers/actions/index.js +8 -0
- package/dist/redux/reducers/actions/index.js.map +1 -0
- package/dist/redux/reducers/index.d.ts +4 -0
- package/dist/redux/reducers/index.d.ts.map +1 -0
- package/dist/redux/reducers/index.js +15 -0
- package/dist/redux/reducers/index.js.map +1 -0
- package/dist/redux/store.d.ts +11 -0
- package/dist/redux/store.d.ts.map +1 -0
- package/dist/redux/store.js +20 -0
- package/dist/redux/store.js.map +1 -0
- package/dist/styles.css +434 -0
- package/dist/utilities/API.d.ts +17 -0
- package/dist/utilities/API.d.ts.map +1 -0
- package/dist/utilities/API.js +71 -0
- package/dist/utilities/API.js.map +1 -0
- package/dist/utilities/external-tools.d.ts +19 -0
- package/dist/utilities/external-tools.d.ts.map +1 -0
- package/dist/utilities/external-tools.js +27 -0
- package/dist/utilities/external-tools.js.map +1 -0
- package/dist/views/fullscreen/index.d.ts +20 -0
- package/dist/views/fullscreen/index.d.ts.map +1 -0
- package/dist/views/fullscreen/index.functions.d.ts +38 -0
- package/dist/views/fullscreen/index.functions.d.ts.map +1 -0
- package/dist/views/fullscreen/index.functions.js +484 -0
- package/dist/views/fullscreen/index.functions.js.map +1 -0
- package/dist/views/fullscreen/index.js +569 -0
- package/dist/views/fullscreen/index.js.map +1 -0
- package/dist/views/tools/ChecklistPreview.d.ts +4 -0
- package/dist/views/tools/ChecklistPreview.d.ts.map +1 -0
- package/dist/views/tools/ChecklistPreview.js +29 -0
- package/dist/views/tools/ChecklistPreview.js.map +1 -0
- package/dist/views/tools/index.d.ts +6 -0
- package/dist/views/tools/index.d.ts.map +1 -0
- package/dist/views/tools/index.js +8 -0
- package/dist/views/tools/index.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ChatMessage } from ".";
|
|
3
|
+
/**
|
|
4
|
+
* Handles the logic for sending a user message to the AI and streaming the response.
|
|
5
|
+
*
|
|
6
|
+
* @param params - Object containing all necessary state setters and refs from the component.
|
|
7
|
+
*/
|
|
8
|
+
export declare const sendMessage: ({ input, setInput, isStreaming, setIsStreaming, setMessages, controllerRef, conversationIdRef, charBufferRef, setAnimatingMessageId, animatingMessageId, setDisplayedChars, setStreamingComplete, textFromInput, resetAnimationState }: {
|
|
9
|
+
input: string;
|
|
10
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
11
|
+
isStreaming: boolean;
|
|
12
|
+
setIsStreaming: React.Dispatch<React.SetStateAction<boolean>>;
|
|
13
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
14
|
+
controllerRef: React.MutableRefObject<AbortController | null>;
|
|
15
|
+
conversationIdRef: React.MutableRefObject<string>;
|
|
16
|
+
charBufferRef: React.MutableRefObject<string>;
|
|
17
|
+
setAnimatingMessageId: React.Dispatch<React.SetStateAction<string | null>>;
|
|
18
|
+
animatingMessageId: string | null;
|
|
19
|
+
setDisplayedChars: React.Dispatch<React.SetStateAction<string>>;
|
|
20
|
+
setStreamingComplete: React.Dispatch<React.SetStateAction<boolean>>;
|
|
21
|
+
textFromInput?: string;
|
|
22
|
+
resetAnimationState?: () => void;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Stops the active stream explicitly.
|
|
26
|
+
* Used when the user clicks the "Stop" button.
|
|
27
|
+
*/
|
|
28
|
+
export declare const stopStreaming: ({ controllerRef, setIsStreaming, animatingMessageId, charBufferRef, setMessages, setAnimatingMessageId, setDisplayedChars, setStreamingComplete }: {
|
|
29
|
+
controllerRef: React.MutableRefObject<AbortController | null>;
|
|
30
|
+
setIsStreaming: React.Dispatch<React.SetStateAction<boolean>>;
|
|
31
|
+
animatingMessageId: string | null;
|
|
32
|
+
charBufferRef: React.MutableRefObject<string>;
|
|
33
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
34
|
+
setAnimatingMessageId: React.Dispatch<React.SetStateAction<string | null>>;
|
|
35
|
+
setDisplayedChars: React.Dispatch<React.SetStateAction<string>>;
|
|
36
|
+
setStreamingComplete: React.Dispatch<React.SetStateAction<boolean>>;
|
|
37
|
+
}) => void;
|
|
38
|
+
//# sourceMappingURL=index.functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.functions.d.ts","sourceRoot":"","sources":["../../../views/fullscreen/index.functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAA;AAK/B;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAU,wOAe/B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACjE,aAAa,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAC9D,iBAAiB,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,aAAa,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC9C,qBAAqB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IAC3E,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iBAAiB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAA;CACjC,kBAkeA,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,mJAS3B;IACD,aAAa,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAC9D,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,aAAa,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC9C,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACjE,qBAAqB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IAC3E,iBAAiB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;CACpE,SA2BA,CAAA"}
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { _connectWithStreaming, _sendMessage } from "../../redux/actions";
|
|
3
|
+
import { getAPI } from "../../utilities/API";
|
|
4
|
+
/**
|
|
5
|
+
* Handles the logic for sending a user message to the AI and streaming the response.
|
|
6
|
+
*
|
|
7
|
+
* @param params - Object containing all necessary state setters and refs from the component.
|
|
8
|
+
*/
|
|
9
|
+
export const sendMessage = async ({ input, setInput, isStreaming, setIsStreaming, setMessages, controllerRef, conversationIdRef, charBufferRef, setAnimatingMessageId, animatingMessageId, setDisplayedChars, setStreamingComplete, textFromInput, resetAnimationState }) => {
|
|
10
|
+
const prompt = (textFromInput ?? input).trim();
|
|
11
|
+
if (!prompt || isStreaming)
|
|
12
|
+
return;
|
|
13
|
+
// 1. Reset component-level animation refs if provided
|
|
14
|
+
if (resetAnimationState) {
|
|
15
|
+
resetAnimationState();
|
|
16
|
+
}
|
|
17
|
+
let latestBuffer = "";
|
|
18
|
+
// 2. Prepare Messages
|
|
19
|
+
const userMessage = {
|
|
20
|
+
id: uuidv4(),
|
|
21
|
+
role: "user",
|
|
22
|
+
content: prompt
|
|
23
|
+
};
|
|
24
|
+
const assistantMessageId = uuidv4();
|
|
25
|
+
const assistantMessage = {
|
|
26
|
+
id: assistantMessageId,
|
|
27
|
+
role: "assistant", // "assistant" role triggers the markdown rendering in UI
|
|
28
|
+
content: "", // Starts empty, will be filled by animation
|
|
29
|
+
isStreaming: true // Mark as streaming until done
|
|
30
|
+
};
|
|
31
|
+
// 3. Update UI instantly with user message and empty assistant bubble
|
|
32
|
+
setMessages((prev) => [...prev, userMessage, assistantMessage]);
|
|
33
|
+
setInput("");
|
|
34
|
+
setIsStreaming(true);
|
|
35
|
+
// 4. Initialize animation state
|
|
36
|
+
charBufferRef.current = ""; // Direct synchronous reset
|
|
37
|
+
setDisplayedChars("");
|
|
38
|
+
setStreamingComplete(false);
|
|
39
|
+
setAnimatingMessageId(assistantMessageId); // Triggers the animation loop in the component
|
|
40
|
+
// 5. Setup AbortController for cancellation
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
controllerRef.current = controller;
|
|
43
|
+
// Track job finished state (accessible in finally block)
|
|
44
|
+
const jobFinishedRef = { current: false };
|
|
45
|
+
try {
|
|
46
|
+
const API = getAPI();
|
|
47
|
+
const apiBase = API.defaults.baseURL || "";
|
|
48
|
+
console.log("Starting stream to API:", `${apiBase}/chat/stream`);
|
|
49
|
+
console.log("Sending prompt:", prompt);
|
|
50
|
+
const createJobResponse = await _sendMessage(prompt, conversationIdRef.current);
|
|
51
|
+
const createJobData = createJobResponse?.data;
|
|
52
|
+
console.log('----------------------', createJobResponse);
|
|
53
|
+
const response = await _connectWithStreaming(createJobData.job_id, controller.signal);
|
|
54
|
+
if (!response.ok || !response.body || typeof response.body.getReader !== "function") {
|
|
55
|
+
throw new Error("Network error");
|
|
56
|
+
}
|
|
57
|
+
const reader = response.body.getReader();
|
|
58
|
+
const decoder = new TextDecoder("utf-8");
|
|
59
|
+
const responseBody = response.body; // Store for cancellation
|
|
60
|
+
let buffer = "";
|
|
61
|
+
let completeText = ""; // Local source of truth for the accumulation
|
|
62
|
+
let doneReading = false;
|
|
63
|
+
let lastEventId = null; // Track Last-Event-ID for reconnection support
|
|
64
|
+
let jobFinished = false; // Flag to break out of reading loop when job completes/fails
|
|
65
|
+
// Helper to close the connection
|
|
66
|
+
const closeConnection = async () => {
|
|
67
|
+
try {
|
|
68
|
+
// Cancel the response body stream to close the connection
|
|
69
|
+
if (responseBody && typeof responseBody.cancel === 'function') {
|
|
70
|
+
await responseBody.cancel();
|
|
71
|
+
console.log("✅ SSE connection cancelled");
|
|
72
|
+
}
|
|
73
|
+
// Release the reader lock
|
|
74
|
+
if (reader) {
|
|
75
|
+
reader.releaseLock();
|
|
76
|
+
console.log("✅ SSE reader released");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.warn("Error closing SSE connection:", err);
|
|
81
|
+
// Still try to release the reader lock
|
|
82
|
+
try {
|
|
83
|
+
if (reader) {
|
|
84
|
+
reader.releaseLock();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (releaseErr) {
|
|
88
|
+
// Ignore release errors
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// Track tool calls during streaming
|
|
93
|
+
const toolCallsMap = new Map();
|
|
94
|
+
/**
|
|
95
|
+
* Appends a delta chunk to the local buffer and updates the shared state.
|
|
96
|
+
*/
|
|
97
|
+
const applyDelta = (deltaText) => {
|
|
98
|
+
// Accumulate locally
|
|
99
|
+
completeText += deltaText;
|
|
100
|
+
// Update state directly from local source
|
|
101
|
+
// NOTE: We check aborted signal to prevent updating state after user cancelled
|
|
102
|
+
if (!controller.signal.aborted) {
|
|
103
|
+
charBufferRef.current = completeText; // Direct synchronous update to ref
|
|
104
|
+
latestBuffer = completeText; // Keep track for finally block
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Processes SSE events in the new format:
|
|
109
|
+
* id: {seq}
|
|
110
|
+
* event: {event_type}
|
|
111
|
+
* data: {json}
|
|
112
|
+
*/
|
|
113
|
+
const processSSEEvent = (eventId, eventType, dataStr) => {
|
|
114
|
+
if (!dataStr || dataStr.trim() === "")
|
|
115
|
+
return;
|
|
116
|
+
// Track Last-Event-ID
|
|
117
|
+
if (eventId) {
|
|
118
|
+
const seq = parseInt(eventId, 10);
|
|
119
|
+
if (!isNaN(seq)) {
|
|
120
|
+
lastEventId = seq;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let payload;
|
|
124
|
+
try {
|
|
125
|
+
payload = JSON.parse(dataStr);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
console.warn("Failed to parse SSE data:", dataStr);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
console.log(`📨 SSE Event: id=${eventId}, event=${eventType}`, payload);
|
|
132
|
+
// Handle different event types from backend
|
|
133
|
+
if (eventType === "agent.delta") {
|
|
134
|
+
// Backend format: payload = {"text": "..."}
|
|
135
|
+
const deltaText = payload.text || "";
|
|
136
|
+
if (deltaText) {
|
|
137
|
+
applyDelta(deltaText);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (eventType === "agent.message") {
|
|
141
|
+
// Backend format: payload = {"role": "assistant", "content": "..."}
|
|
142
|
+
// This is the complete message - use it if we don't have deltas
|
|
143
|
+
const content = payload.content || "";
|
|
144
|
+
if (content && !completeText) {
|
|
145
|
+
// If we haven't received deltas, use the complete message
|
|
146
|
+
completeText = content;
|
|
147
|
+
if (!controller.signal.aborted) {
|
|
148
|
+
charBufferRef.current = completeText;
|
|
149
|
+
latestBuffer = completeText;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (eventType === "tool.requested") {
|
|
154
|
+
// Backend format: payload = {"name": "...", "arguments": {...}, "call_id": "..."}
|
|
155
|
+
const toolName = payload.name || "tool";
|
|
156
|
+
const callId = payload.call_id || uuidv4();
|
|
157
|
+
const statusMsg = `Using ${toolName}...`;
|
|
158
|
+
// Track this tool call
|
|
159
|
+
toolCallsMap.set(callId, {
|
|
160
|
+
tool: toolName,
|
|
161
|
+
call_id: callId,
|
|
162
|
+
status: "executing",
|
|
163
|
+
data: undefined
|
|
164
|
+
});
|
|
165
|
+
// Update message with status and pending tool call
|
|
166
|
+
setMessages(prev => prev.map(m => {
|
|
167
|
+
if (m.id === assistantMessageId) {
|
|
168
|
+
const pendingToolCalls = Array.from(toolCallsMap.values())
|
|
169
|
+
.filter(tc => !tc.data) // Only pending (not completed)
|
|
170
|
+
.map(tc => ({
|
|
171
|
+
tool: tc.tool,
|
|
172
|
+
status: tc.status,
|
|
173
|
+
data: tc.data
|
|
174
|
+
}));
|
|
175
|
+
return {
|
|
176
|
+
...m,
|
|
177
|
+
status: statusMsg,
|
|
178
|
+
pendingToolCalls: pendingToolCalls.length > 0 ? pendingToolCalls : undefined
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return m;
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
else if (eventType === "tool.completed") {
|
|
185
|
+
// Backend format: payload = {"call_id": "...", "result": {...}, "tool_name": "..."}
|
|
186
|
+
const callId = payload.call_id;
|
|
187
|
+
const toolResult = payload.result || {};
|
|
188
|
+
const toolName = payload.tool_name || null;
|
|
189
|
+
if (callId && toolCallsMap.has(callId)) {
|
|
190
|
+
// Update existing tool call with result
|
|
191
|
+
const toolCall = toolCallsMap.get(callId);
|
|
192
|
+
toolCall.status = "completed";
|
|
193
|
+
toolCall.data = toolResult;
|
|
194
|
+
// Update tool name if provided
|
|
195
|
+
if (toolName) {
|
|
196
|
+
toolCall.tool = toolName;
|
|
197
|
+
}
|
|
198
|
+
toolCallsMap.set(callId, toolCall);
|
|
199
|
+
}
|
|
200
|
+
else if (callId) {
|
|
201
|
+
// Tool call not tracked (tool.requested was missed or async tool)
|
|
202
|
+
// Use tool_name from payload, or infer from result structure
|
|
203
|
+
let finalToolName = toolName || "unknown";
|
|
204
|
+
if (!toolName && toolResult && typeof toolResult === 'object') {
|
|
205
|
+
// Infer tool name from result structure as fallback
|
|
206
|
+
if (toolResult.title || toolResult.items) {
|
|
207
|
+
finalToolName = "generate_checklist";
|
|
208
|
+
}
|
|
209
|
+
else if (toolResult.translated_text) {
|
|
210
|
+
finalToolName = "translate_text";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
toolCallsMap.set(callId, {
|
|
214
|
+
tool: finalToolName,
|
|
215
|
+
call_id: callId,
|
|
216
|
+
status: "completed",
|
|
217
|
+
data: toolResult
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
// Update message: clear status, update pending/completed tool calls
|
|
221
|
+
setMessages(prev => prev.map(m => {
|
|
222
|
+
if (m.id === assistantMessageId) {
|
|
223
|
+
const pendingToolCalls = Array.from(toolCallsMap.values())
|
|
224
|
+
.filter(tc => !tc.data) // Only pending (not completed)
|
|
225
|
+
.map(tc => ({
|
|
226
|
+
tool: tc.tool,
|
|
227
|
+
status: tc.status,
|
|
228
|
+
data: tc.data
|
|
229
|
+
}));
|
|
230
|
+
const completedToolCalls = Array.from(toolCallsMap.values())
|
|
231
|
+
.filter(tc => tc.data) // Only completed (has data)
|
|
232
|
+
.map(tc => ({
|
|
233
|
+
tool: tc.tool,
|
|
234
|
+
status: tc.status,
|
|
235
|
+
data: tc.data
|
|
236
|
+
}));
|
|
237
|
+
console.log("🔧 tool.completed event - updating message:", {
|
|
238
|
+
callId,
|
|
239
|
+
toolName,
|
|
240
|
+
toolResult,
|
|
241
|
+
completedToolCallsCount: completedToolCalls.length,
|
|
242
|
+
completedToolCalls,
|
|
243
|
+
toolCallsMapSize: toolCallsMap.size,
|
|
244
|
+
toolCallsMapEntries: Array.from(toolCallsMap.entries()),
|
|
245
|
+
currentAnimationComplete: m.animationComplete,
|
|
246
|
+
animatingMessageId
|
|
247
|
+
});
|
|
248
|
+
// Don't set animationComplete here - it should only be set when animation actually finishes
|
|
249
|
+
// The useEffect watching animatingMessageId will set it when animation completes
|
|
250
|
+
return {
|
|
251
|
+
...m,
|
|
252
|
+
status: pendingToolCalls.length > 0 ? `Using ${pendingToolCalls[0].tool}...` : undefined,
|
|
253
|
+
pendingToolCalls: pendingToolCalls.length > 0 ? pendingToolCalls : undefined,
|
|
254
|
+
toolCalls: completedToolCalls.length > 0 ? completedToolCalls : (m.toolCalls || undefined) // Preserve existing toolCalls if no new ones
|
|
255
|
+
// animationComplete is only set by the useEffect when animatingMessageId becomes null
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return m;
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
else if (eventType === "job.paused") {
|
|
262
|
+
// Backend format: payload = {"reason": "..."}
|
|
263
|
+
const reason = payload.reason || "Paused for tool execution";
|
|
264
|
+
setMessages(prev => prev.map(m => {
|
|
265
|
+
if (m.id === assistantMessageId) {
|
|
266
|
+
return { ...m, status: reason };
|
|
267
|
+
}
|
|
268
|
+
return m;
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
else if (eventType === "job.resumed") {
|
|
272
|
+
// Backend format: payload = {"reason": "..."}
|
|
273
|
+
const reason = payload.reason || "Resuming...";
|
|
274
|
+
setMessages(prev => prev.map(m => {
|
|
275
|
+
if (m.id === assistantMessageId) {
|
|
276
|
+
// Clear status or show resuming message briefly
|
|
277
|
+
return { ...m, status: undefined };
|
|
278
|
+
}
|
|
279
|
+
return m;
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
else if (eventType === "job.completed") {
|
|
283
|
+
console.log("✅ Job completed. Total content:", completeText);
|
|
284
|
+
// Mark job as finished - will break out of reading loop
|
|
285
|
+
jobFinished = true;
|
|
286
|
+
jobFinishedRef.current = true;
|
|
287
|
+
// Mark message as no longer streaming
|
|
288
|
+
// Move all pending tool calls to completed tool calls
|
|
289
|
+
// Set animationComplete if we have tool calls and message is not currently animating
|
|
290
|
+
setMessages(prev => prev.map(m => {
|
|
291
|
+
if (m.id === assistantMessageId) {
|
|
292
|
+
const allToolCalls = Array.from(toolCallsMap.values())
|
|
293
|
+
.filter(tc => tc.data) // Only completed tool calls
|
|
294
|
+
.map(tc => ({
|
|
295
|
+
tool: tc.tool,
|
|
296
|
+
status: tc.status,
|
|
297
|
+
data: tc.data
|
|
298
|
+
}));
|
|
299
|
+
console.log("✅ job.completed - updating message with toolCalls:", {
|
|
300
|
+
allToolCallsCount: allToolCalls.length,
|
|
301
|
+
allToolCalls,
|
|
302
|
+
existingToolCalls: m.toolCalls,
|
|
303
|
+
toolCallsMapSize: toolCallsMap.size,
|
|
304
|
+
toolCallsMapEntries: Array.from(toolCallsMap.entries()),
|
|
305
|
+
currentAnimationComplete: m.animationComplete,
|
|
306
|
+
animatingMessageId
|
|
307
|
+
});
|
|
308
|
+
// Don't set animationComplete here - it should only be set when animation actually finishes
|
|
309
|
+
// The useEffect watching animatingMessageId will set it when animation completes
|
|
310
|
+
const finalToolCalls = allToolCalls.length > 0 ? allToolCalls : (m.toolCalls || undefined);
|
|
311
|
+
return {
|
|
312
|
+
...m,
|
|
313
|
+
isStreaming: false,
|
|
314
|
+
status: undefined, // Clear any status
|
|
315
|
+
toolCalls: finalToolCalls,
|
|
316
|
+
pendingToolCalls: undefined // Clear pending
|
|
317
|
+
// animationComplete is only set by the useEffect when animatingMessageId becomes null
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return m;
|
|
321
|
+
}));
|
|
322
|
+
// Set streaming state to false to hide stop button
|
|
323
|
+
setIsStreaming(false);
|
|
324
|
+
setStreamingComplete(true);
|
|
325
|
+
}
|
|
326
|
+
else if (eventType === "job.failed") {
|
|
327
|
+
console.error("❌ Job failed:", payload);
|
|
328
|
+
// Mark job as finished - will break out of reading loop
|
|
329
|
+
jobFinished = true;
|
|
330
|
+
jobFinishedRef.current = true;
|
|
331
|
+
const errorMsg = payload.error?.message || "Job failed";
|
|
332
|
+
setMessages(prev => prev.map(m => {
|
|
333
|
+
if (m.id === assistantMessageId) {
|
|
334
|
+
return { ...m, content: completeText || errorMsg, isStreaming: false };
|
|
335
|
+
}
|
|
336
|
+
return m;
|
|
337
|
+
}));
|
|
338
|
+
setIsStreaming(false);
|
|
339
|
+
setStreamingComplete(true);
|
|
340
|
+
}
|
|
341
|
+
else if (eventType === "job.started") {
|
|
342
|
+
console.log("🚀 Job started");
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// Unknown event type - log for debugging
|
|
346
|
+
console.log(`⚠️ Unknown event type: ${eventType}`, payload);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Parses SSE format and processes events.
|
|
351
|
+
* SSE format:
|
|
352
|
+
* id: {seq}
|
|
353
|
+
* event: {event_type}
|
|
354
|
+
* data: {json}
|
|
355
|
+
*
|
|
356
|
+
* (empty line separates events)
|
|
357
|
+
*/
|
|
358
|
+
const parseSSE = (text) => {
|
|
359
|
+
const lines = text.split("\n");
|
|
360
|
+
let currentEvent = {
|
|
361
|
+
id: null,
|
|
362
|
+
event: null,
|
|
363
|
+
data: []
|
|
364
|
+
};
|
|
365
|
+
for (const line of lines) {
|
|
366
|
+
const trimmed = line.trim();
|
|
367
|
+
if (!trimmed) {
|
|
368
|
+
// Empty line = end of event, process it
|
|
369
|
+
if (currentEvent.data.length > 0) {
|
|
370
|
+
processSSEEvent(currentEvent.id, currentEvent.event, currentEvent.data.join("\n"));
|
|
371
|
+
}
|
|
372
|
+
// Reset for next event
|
|
373
|
+
currentEvent = { id: null, event: null, data: [] };
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
// Parse SSE fields
|
|
377
|
+
if (trimmed.startsWith("id:")) {
|
|
378
|
+
currentEvent.id = trimmed.slice(3).trim();
|
|
379
|
+
}
|
|
380
|
+
else if (trimmed.startsWith("event:")) {
|
|
381
|
+
currentEvent.event = trimmed.slice(6).trim();
|
|
382
|
+
}
|
|
383
|
+
else if (trimmed.startsWith("data:")) {
|
|
384
|
+
currentEvent.data.push(trimmed.slice(5).trim());
|
|
385
|
+
}
|
|
386
|
+
else if (trimmed.startsWith(":")) {
|
|
387
|
+
// Comment/control line (e.g., ": connected", ": ping")
|
|
388
|
+
if (trimmed.includes("connected")) {
|
|
389
|
+
console.log("✅ SSE connection established");
|
|
390
|
+
}
|
|
391
|
+
else if (trimmed.includes("ping")) {
|
|
392
|
+
// Heartbeat - no action needed
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// Process any remaining event in buffer
|
|
397
|
+
if (currentEvent.data.length > 0) {
|
|
398
|
+
processSSEEvent(currentEvent.id, currentEvent.event, currentEvent.data.join("\n"));
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
// 6. Stream Reading Loop
|
|
402
|
+
while (!doneReading && !jobFinished) {
|
|
403
|
+
const { done, value } = await reader.read();
|
|
404
|
+
doneReading = done;
|
|
405
|
+
const chunk = decoder.decode(value || new Uint8Array(), { stream: !done });
|
|
406
|
+
buffer += chunk;
|
|
407
|
+
// Process complete SSE events (separated by double newlines)
|
|
408
|
+
// But also handle single newlines for line-by-line processing
|
|
409
|
+
let doubleNewlineIndex = buffer.indexOf("\n\n");
|
|
410
|
+
while (doubleNewlineIndex !== -1 && !jobFinished) {
|
|
411
|
+
const eventText = buffer.slice(0, doubleNewlineIndex);
|
|
412
|
+
parseSSE(eventText);
|
|
413
|
+
buffer = buffer.slice(doubleNewlineIndex + 2);
|
|
414
|
+
doubleNewlineIndex = buffer.indexOf("\n\n");
|
|
415
|
+
}
|
|
416
|
+
// Also handle single newlines for partial events
|
|
417
|
+
if (done && buffer.trim() && !jobFinished) {
|
|
418
|
+
parseSSE(buffer);
|
|
419
|
+
buffer = "";
|
|
420
|
+
}
|
|
421
|
+
// Break out of loop if job finished (job.completed or job.failed received)
|
|
422
|
+
if (jobFinished) {
|
|
423
|
+
console.log("🛑 Job finished, closing SSE connection");
|
|
424
|
+
await closeConnection();
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// If loop ended normally (doneReading), still close the connection
|
|
429
|
+
if (!jobFinished) {
|
|
430
|
+
await closeConnection();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
if (controller.signal.aborted) {
|
|
435
|
+
console.log("Stream aborted by user");
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
console.error("Streaming error:", err);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
// 7. Cleanup
|
|
443
|
+
if (!controller.signal.aborted) {
|
|
444
|
+
// Only update if not aborted to avoid overwriting state
|
|
445
|
+
charBufferRef.current = latestBuffer;
|
|
446
|
+
setIsStreaming(false);
|
|
447
|
+
setStreamingComplete(true); // Signals animation loop to finish up
|
|
448
|
+
// Don't set animationComplete here - it should only be set when animation actually finishes
|
|
449
|
+
// The useEffect watching animatingMessageId will set it when animation completes
|
|
450
|
+
}
|
|
451
|
+
if (controllerRef.current === controller) {
|
|
452
|
+
controllerRef.current = null;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Stops the active stream explicitly.
|
|
458
|
+
* Used when the user clicks the "Stop" button.
|
|
459
|
+
*/
|
|
460
|
+
export const stopStreaming = ({ controllerRef, setIsStreaming, animatingMessageId, charBufferRef, setMessages, setAnimatingMessageId, setDisplayedChars, setStreamingComplete }) => {
|
|
461
|
+
if (controllerRef.current) {
|
|
462
|
+
controllerRef.current.abort();
|
|
463
|
+
controllerRef.current = null;
|
|
464
|
+
}
|
|
465
|
+
setIsStreaming(false);
|
|
466
|
+
const finalContent = charBufferRef.current;
|
|
467
|
+
// Force-complete the animation: show all buffered content immediately
|
|
468
|
+
if (animatingMessageId) {
|
|
469
|
+
setMessages((msgs) => {
|
|
470
|
+
return msgs.map((m) => {
|
|
471
|
+
if (m.id === animatingMessageId) {
|
|
472
|
+
return { ...m, content: finalContent };
|
|
473
|
+
}
|
|
474
|
+
return m;
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
setAnimatingMessageId(null);
|
|
478
|
+
setDisplayedChars(finalContent);
|
|
479
|
+
// Explicitly clear ref
|
|
480
|
+
charBufferRef.current = "";
|
|
481
|
+
setStreamingComplete(false);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
//# sourceMappingURL=index.functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.functions.js","sourceRoot":"","sources":["../../../views/fullscreen/index.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAGnC,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAG5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,EAChC,KAAK,EACL,QAAQ,EACR,WAAW,EACX,cAAc,EACd,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB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