@controleonline/ui-crm 1.0.60 → 1.0.61
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.61",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.61-rc.1",
|
|
5
|
+
"baseMaster": "f74060050bf143d4436051cd70d688618bd01dc5",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
1335
|
|
8
8
|
],
|
|
9
9
|
"frozen": true,
|
|
10
10
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-crm": "
|
|
11
|
+
"ControleOnline/ui-crm": "54cacf3c5bc086cbd32a13b8b14b889df261e729"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -28,6 +28,8 @@ const PROVIDER_LABELS = {
|
|
|
28
28
|
export default function McpPage() {
|
|
29
29
|
const {showError, showSuccess} = useToastMessage();
|
|
30
30
|
const peopleStore = useStore('people');
|
|
31
|
+
const websocketStore = useStore('websocket');
|
|
32
|
+
const wsMessages = websocketStore?.getters?.messages || [];
|
|
31
33
|
const company =
|
|
32
34
|
peopleStore?.getters?.currentCompany ||
|
|
33
35
|
peopleStore?.getters?.mainCompany ||
|
|
@@ -44,6 +46,8 @@ export default function McpPage() {
|
|
|
44
46
|
const [loadingChat, setLoadingChat] = useState(false);
|
|
45
47
|
const [sending, setSending] = useState(false);
|
|
46
48
|
const listRef = useRef(null);
|
|
49
|
+
const pendingByTaskRef = useRef({}); // taskId -> userInteractionId
|
|
50
|
+
const handledWsRef = useRef(new Set());
|
|
47
51
|
|
|
48
52
|
const companyQuery = useMemo(
|
|
49
53
|
() => (companyId ? {company_id: Number(companyId)} : {}),
|
|
@@ -131,27 +135,45 @@ export default function McpPage() {
|
|
|
131
135
|
setDraft('');
|
|
132
136
|
};
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
await loadMessages(taskId);
|
|
140
|
-
if (interactionId) {
|
|
141
|
-
const detail = await api.fetch(`/task_interations/${interactionId}`);
|
|
142
|
-
const st = detail?.status || detail?.['status'];
|
|
143
|
-
if (st === 'done' || st === 'error') {
|
|
144
|
-
return st;
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
return 'done';
|
|
148
|
-
}
|
|
149
|
-
} catch {
|
|
150
|
-
// keep polling
|
|
151
|
-
}
|
|
138
|
+
// Realtime: apply mcp_chat_reply from websocket store (no HTTP poll)
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!Array.isArray(wsMessages) || wsMessages.length === 0) {
|
|
141
|
+
return;
|
|
152
142
|
}
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
const latest = wsMessages[wsMessages.length - 1];
|
|
144
|
+
const candidates = Array.isArray(latest) ? latest : [latest];
|
|
145
|
+
candidates.forEach(evt => {
|
|
146
|
+
if (!evt || typeof evt !== 'object') {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const eventName = String(evt.event || evt.action || '');
|
|
150
|
+
if (eventName !== 'mcp_chat_reply') {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const taskId = Number(evt.task_id || evt.taskId || 0);
|
|
154
|
+
const interactionId = Number(evt.interaction_id || evt.interactionId || 0);
|
|
155
|
+
const key = `${taskId}:${interactionId}:${evt.status || ''}:${String(evt.body || '').slice(0, 40)}`;
|
|
156
|
+
if (handledWsRef.current.has(key)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
handledWsRef.current.add(key);
|
|
160
|
+
|
|
161
|
+
if (taskId && Number(activeTaskId) === taskId) {
|
|
162
|
+
// Refresh only the open chat once when reply arrives
|
|
163
|
+
loadMessages(taskId);
|
|
164
|
+
} else if (taskId && !activeTaskId) {
|
|
165
|
+
setActiveTaskId(taskId);
|
|
166
|
+
}
|
|
167
|
+
if (taskId) {
|
|
168
|
+
delete pendingByTaskRef.current[taskId];
|
|
169
|
+
loadTasks();
|
|
170
|
+
}
|
|
171
|
+
if (String(evt.status || '') === 'error') {
|
|
172
|
+
showError(evt.body || 'A IA retornou erro ao processar a mensagem');
|
|
173
|
+
}
|
|
174
|
+
setSending(false);
|
|
175
|
+
});
|
|
176
|
+
}, [wsMessages, activeTaskId, loadMessages, loadTasks, showError]);
|
|
155
177
|
|
|
156
178
|
const sendMessage = async () => {
|
|
157
179
|
const text = draft.trim();
|
|
@@ -168,30 +190,38 @@ export default function McpPage() {
|
|
|
168
190
|
...(activeTaskId ? {task_id: activeTaskId} : {}),
|
|
169
191
|
...(companyId ? {company_id: Number(companyId)} : {}),
|
|
170
192
|
};
|
|
193
|
+
// Optimistic local bubble while queue processes
|
|
194
|
+
setMessages(prev => [
|
|
195
|
+
...prev,
|
|
196
|
+
{
|
|
197
|
+
id: `local-${Date.now()}`,
|
|
198
|
+
body: text,
|
|
199
|
+
status: 'pending',
|
|
200
|
+
registeredBy: {id: companyId ? Number(companyId) + 1 : 0},
|
|
201
|
+
},
|
|
202
|
+
]);
|
|
203
|
+
setDraft('');
|
|
171
204
|
const res = await api.post('/mcp/chat', body);
|
|
172
205
|
const newTaskId = res?.task_id || res?.task?.id;
|
|
173
206
|
const interactionId = res?.interaction_id;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
207
|
+
if (newTaskId) {
|
|
208
|
+
pendingByTaskRef.current[Number(newTaskId)] = interactionId;
|
|
209
|
+
if (Number(newTaskId) !== Number(activeTaskId)) {
|
|
210
|
+
setActiveTaskId(Number(newTaskId));
|
|
211
|
+
loadTasks();
|
|
212
|
+
}
|
|
213
|
+
// Single reload after persist (user message on server) — no poll loop
|
|
214
|
+
await loadMessages(Number(newTaskId));
|
|
178
215
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (finalStatus === 'error') {
|
|
185
|
-
showError('A IA retornou erro ao processar a mensagem');
|
|
186
|
-
} else if (finalStatus === 'timeout') {
|
|
187
|
-
showError('Ainda processando… atualize o chat em instantes');
|
|
216
|
+
// sending stays true until websocket reply (or error toast)
|
|
217
|
+
if (!(res?.async || res?.status === 'pending')) {
|
|
218
|
+
setSending(false);
|
|
219
|
+
if (res?.message) {
|
|
220
|
+
await loadMessages(newTaskId || activeTaskId);
|
|
188
221
|
}
|
|
189
|
-
} else if (res?.message) {
|
|
190
|
-
await loadMessages(newTaskId || activeTaskId);
|
|
191
222
|
}
|
|
192
223
|
} catch (e) {
|
|
193
224
|
showError(e?.message || e?.error || 'Falha ao enviar mensagem');
|
|
194
|
-
} finally {
|
|
195
225
|
setSending(false);
|
|
196
226
|
}
|
|
197
227
|
};
|