bloby-bot 0.21.1 → 0.21.2
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/package.json
CHANGED
|
@@ -37,6 +37,8 @@ export function useChat(ws: WsClient | null) {
|
|
|
37
37
|
const [streamBuffer, setStreamBuffer] = useState('');
|
|
38
38
|
const [tools, setTools] = useState<ToolActivity[]>([]);
|
|
39
39
|
const loaded = useRef(false);
|
|
40
|
+
/** Count of user messages awaiting a bot response — keeps typing indicator alive across turns */
|
|
41
|
+
const pendingMessages = useRef(0);
|
|
40
42
|
|
|
41
43
|
// Load current conversation from DB on mount
|
|
42
44
|
useEffect(() => {
|
|
@@ -128,6 +130,8 @@ export function useChat(ws: WsClient | null) {
|
|
|
128
130
|
setTools([]);
|
|
129
131
|
}),
|
|
130
132
|
ws.on('bot:token', (data: { token: string }) => {
|
|
133
|
+
// Auto-detect new turn — if tokens arrive after a response cleared streaming
|
|
134
|
+
setStreaming(true);
|
|
131
135
|
setStreamBuffer((buf) => buf + data.token);
|
|
132
136
|
}),
|
|
133
137
|
ws.on('bot:tool', (data: { name: string; input?: any; status?: string }) => {
|
|
@@ -149,13 +153,20 @@ export function useChat(ws: WsClient | null) {
|
|
|
149
153
|
},
|
|
150
154
|
]);
|
|
151
155
|
setStreamBuffer('');
|
|
152
|
-
setStreaming(false);
|
|
153
156
|
setTools([]);
|
|
157
|
+
// Only stop streaming when all pending messages have been answered
|
|
158
|
+
pendingMessages.current = Math.max(0, pendingMessages.current - 1);
|
|
159
|
+
if (pendingMessages.current === 0) {
|
|
160
|
+
setStreaming(false);
|
|
161
|
+
}
|
|
154
162
|
}),
|
|
155
163
|
ws.on('bot:error', (data: { error: string }) => {
|
|
156
164
|
setStreamBuffer('');
|
|
157
|
-
setStreaming(false);
|
|
158
165
|
setTools([]);
|
|
166
|
+
pendingMessages.current = Math.max(0, pendingMessages.current - 1);
|
|
167
|
+
if (pendingMessages.current === 0) {
|
|
168
|
+
setStreaming(false);
|
|
169
|
+
}
|
|
159
170
|
setMessages((msgs) => [
|
|
160
171
|
...msgs,
|
|
161
172
|
{
|
|
@@ -191,6 +202,7 @@ export function useChat(ws: WsClient | null) {
|
|
|
191
202
|
attachments: optimisticAttachments,
|
|
192
203
|
};
|
|
193
204
|
setMessages((msgs) => [...msgs, userMsg]);
|
|
205
|
+
pendingMessages.current += 1;
|
|
194
206
|
|
|
195
207
|
// Build WS payload
|
|
196
208
|
const payload: any = { conversationId, content };
|
|
@@ -220,6 +232,7 @@ export function useChat(ws: WsClient | null) {
|
|
|
220
232
|
setStreaming(false);
|
|
221
233
|
setStreamBuffer('');
|
|
222
234
|
setTools([]);
|
|
235
|
+
pendingMessages.current = 0;
|
|
223
236
|
}, [ws, conversationId]);
|
|
224
237
|
|
|
225
238
|
const clearContext = useCallback(() => {
|
|
@@ -228,6 +241,7 @@ export function useChat(ws: WsClient | null) {
|
|
|
228
241
|
setStreamBuffer('');
|
|
229
242
|
setStreaming(false);
|
|
230
243
|
setTools([]);
|
|
244
|
+
pendingMessages.current = 0;
|
|
231
245
|
prevConvId.current = null;
|
|
232
246
|
loaded.current = false;
|
|
233
247
|
fetch('/api/context/clear', { method: 'POST' }).catch(() => {});
|