@menuia/react 1.4.2 → 1.5.1
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/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +32 -22
- package/dist/index.mjs +32 -22
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -42,6 +42,8 @@ interface UseMenuIAReturn {
|
|
|
42
42
|
isLoading: boolean;
|
|
43
43
|
isStreaming: boolean;
|
|
44
44
|
streamingText: string;
|
|
45
|
+
/** A IA nao respondeu de proposito (atendente assumiu, modo humano, autoReply off, plano vencido). */
|
|
46
|
+
aiPaused: boolean;
|
|
45
47
|
error: string | null;
|
|
46
48
|
sendMessage: (content: string, attachments?: MessageAttachment[]) => Promise<void>;
|
|
47
49
|
clearChat: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ interface UseMenuIAReturn {
|
|
|
42
42
|
isLoading: boolean;
|
|
43
43
|
isStreaming: boolean;
|
|
44
44
|
streamingText: string;
|
|
45
|
+
/** A IA nao respondeu de proposito (atendente assumiu, modo humano, autoReply off, plano vencido). */
|
|
46
|
+
aiPaused: boolean;
|
|
45
47
|
error: string | null;
|
|
46
48
|
sendMessage: (content: string, attachments?: MessageAttachment[]) => Promise<void>;
|
|
47
49
|
clearChat: () => void;
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,12 @@ var import_react2 = __toESM(require("react"));
|
|
|
42
42
|
// src/useMenuIA.ts
|
|
43
43
|
var import_react = require("react");
|
|
44
44
|
var import_core = require("@menuia/core");
|
|
45
|
+
var normalizar = (s) => (s || "").trim().replace(/\s+/g, " ").toLowerCase();
|
|
46
|
+
function mesmaMensagem(lista, msg) {
|
|
47
|
+
const alvo = normalizar(msg.content);
|
|
48
|
+
return lista.some((m) => m.id === msg.id || !!alvo && m.role === msg.role && normalizar(m.content) === alvo);
|
|
49
|
+
}
|
|
50
|
+
var vazia = (m) => !normalizar(m.content || "") && !m.mediaUrl;
|
|
45
51
|
function useMenuIA(config) {
|
|
46
52
|
const clientRef = (0, import_react.useRef)(null);
|
|
47
53
|
const [messages, setMessages] = (0, import_react.useState)([]);
|
|
@@ -51,15 +57,14 @@ function useMenuIA(config) {
|
|
|
51
57
|
const [streamingText, setStreamingText] = (0, import_react.useState)("");
|
|
52
58
|
const [error, setError] = (0, import_react.useState)(null);
|
|
53
59
|
const [ticketId, setTicketId] = (0, import_react.useState)(null);
|
|
60
|
+
const [aiPaused, setAiPaused] = (0, import_react.useState)(false);
|
|
54
61
|
(0, import_react.useEffect)(() => {
|
|
55
62
|
const client = new import_core.MenuIAClient({
|
|
56
63
|
...config,
|
|
57
64
|
onStatusChange: (s) => setStatus(s),
|
|
58
65
|
onMessage: (msg) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return [...prev, msg];
|
|
62
|
-
});
|
|
66
|
+
if (vazia(msg)) return;
|
|
67
|
+
setMessages((prev) => mesmaMensagem(prev, msg) ? prev : [...prev, msg]);
|
|
63
68
|
},
|
|
64
69
|
onTicketCreated: (id) => setTicketId(id),
|
|
65
70
|
onError: (err) => setError(err.message)
|
|
@@ -100,17 +105,17 @@ function useMenuIA(config) {
|
|
|
100
105
|
setStreamingText(fullText);
|
|
101
106
|
}
|
|
102
107
|
);
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
108
|
+
setAiPaused(!!response?.data?.aiPaused);
|
|
109
|
+
const finalContent = (response?.data?.message || streamingText || "").trim();
|
|
110
|
+
if (finalContent && !response?.data?.aiPaused) {
|
|
111
|
+
const assistantMsg = {
|
|
112
|
+
id: `assistant_${Date.now()}`,
|
|
113
|
+
role: "assistant",
|
|
114
|
+
content: finalContent,
|
|
115
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
116
|
+
};
|
|
117
|
+
setMessages((prev) => mesmaMensagem(prev, assistantMsg) ? prev : [...prev, assistantMsg]);
|
|
118
|
+
}
|
|
114
119
|
if (response?.data?.ticketId) {
|
|
115
120
|
setTicketId(response.data.ticketId);
|
|
116
121
|
}
|
|
@@ -119,13 +124,17 @@ function useMenuIA(config) {
|
|
|
119
124
|
setIsStreaming(false);
|
|
120
125
|
setStreamingText("");
|
|
121
126
|
const response = await clientRef.current.sendMessage({ content: text, attachments });
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
setAiPaused(!!response?.data?.aiPaused);
|
|
128
|
+
const conteudoFb = (response?.data?.message || "").trim();
|
|
129
|
+
if (conteudoFb && !response?.data?.aiPaused) {
|
|
130
|
+
const fb = {
|
|
131
|
+
id: `assistant_${Date.now()}_fb`,
|
|
132
|
+
role: "assistant",
|
|
133
|
+
content: conteudoFb,
|
|
134
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
135
|
+
};
|
|
136
|
+
setMessages((prev) => mesmaMensagem(prev, fb) ? prev : [...prev, fb]);
|
|
137
|
+
}
|
|
129
138
|
} catch (fallbackErr) {
|
|
130
139
|
const errMsg = fallbackErr instanceof Error ? fallbackErr.message : "Erro ao enviar mensagem";
|
|
131
140
|
setError(errMsg);
|
|
@@ -148,6 +157,7 @@ function useMenuIA(config) {
|
|
|
148
157
|
isLoading,
|
|
149
158
|
isStreaming,
|
|
150
159
|
streamingText,
|
|
160
|
+
aiPaused,
|
|
151
161
|
error,
|
|
152
162
|
sendMessage,
|
|
153
163
|
clearChat,
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,12 @@ import React, { useState as useState2, useRef as useRef2, useEffect as useEffect
|
|
|
4
4
|
// src/useMenuIA.ts
|
|
5
5
|
import { useState, useEffect, useRef, useCallback } from "react";
|
|
6
6
|
import { MenuIAClient } from "@menuia/core";
|
|
7
|
+
var normalizar = (s) => (s || "").trim().replace(/\s+/g, " ").toLowerCase();
|
|
8
|
+
function mesmaMensagem(lista, msg) {
|
|
9
|
+
const alvo = normalizar(msg.content);
|
|
10
|
+
return lista.some((m) => m.id === msg.id || !!alvo && m.role === msg.role && normalizar(m.content) === alvo);
|
|
11
|
+
}
|
|
12
|
+
var vazia = (m) => !normalizar(m.content || "") && !m.mediaUrl;
|
|
7
13
|
function useMenuIA(config) {
|
|
8
14
|
const clientRef = useRef(null);
|
|
9
15
|
const [messages, setMessages] = useState([]);
|
|
@@ -13,15 +19,14 @@ function useMenuIA(config) {
|
|
|
13
19
|
const [streamingText, setStreamingText] = useState("");
|
|
14
20
|
const [error, setError] = useState(null);
|
|
15
21
|
const [ticketId, setTicketId] = useState(null);
|
|
22
|
+
const [aiPaused, setAiPaused] = useState(false);
|
|
16
23
|
useEffect(() => {
|
|
17
24
|
const client = new MenuIAClient({
|
|
18
25
|
...config,
|
|
19
26
|
onStatusChange: (s) => setStatus(s),
|
|
20
27
|
onMessage: (msg) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return [...prev, msg];
|
|
24
|
-
});
|
|
28
|
+
if (vazia(msg)) return;
|
|
29
|
+
setMessages((prev) => mesmaMensagem(prev, msg) ? prev : [...prev, msg]);
|
|
25
30
|
},
|
|
26
31
|
onTicketCreated: (id) => setTicketId(id),
|
|
27
32
|
onError: (err) => setError(err.message)
|
|
@@ -62,17 +67,17 @@ function useMenuIA(config) {
|
|
|
62
67
|
setStreamingText(fullText);
|
|
63
68
|
}
|
|
64
69
|
);
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
70
|
+
setAiPaused(!!response?.data?.aiPaused);
|
|
71
|
+
const finalContent = (response?.data?.message || streamingText || "").trim();
|
|
72
|
+
if (finalContent && !response?.data?.aiPaused) {
|
|
73
|
+
const assistantMsg = {
|
|
74
|
+
id: `assistant_${Date.now()}`,
|
|
75
|
+
role: "assistant",
|
|
76
|
+
content: finalContent,
|
|
77
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
78
|
+
};
|
|
79
|
+
setMessages((prev) => mesmaMensagem(prev, assistantMsg) ? prev : [...prev, assistantMsg]);
|
|
80
|
+
}
|
|
76
81
|
if (response?.data?.ticketId) {
|
|
77
82
|
setTicketId(response.data.ticketId);
|
|
78
83
|
}
|
|
@@ -81,13 +86,17 @@ function useMenuIA(config) {
|
|
|
81
86
|
setIsStreaming(false);
|
|
82
87
|
setStreamingText("");
|
|
83
88
|
const response = await clientRef.current.sendMessage({ content: text, attachments });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
setAiPaused(!!response?.data?.aiPaused);
|
|
90
|
+
const conteudoFb = (response?.data?.message || "").trim();
|
|
91
|
+
if (conteudoFb && !response?.data?.aiPaused) {
|
|
92
|
+
const fb = {
|
|
93
|
+
id: `assistant_${Date.now()}_fb`,
|
|
94
|
+
role: "assistant",
|
|
95
|
+
content: conteudoFb,
|
|
96
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
97
|
+
};
|
|
98
|
+
setMessages((prev) => mesmaMensagem(prev, fb) ? prev : [...prev, fb]);
|
|
99
|
+
}
|
|
91
100
|
} catch (fallbackErr) {
|
|
92
101
|
const errMsg = fallbackErr instanceof Error ? fallbackErr.message : "Erro ao enviar mensagem";
|
|
93
102
|
setError(errMsg);
|
|
@@ -110,6 +119,7 @@ function useMenuIA(config) {
|
|
|
110
119
|
isLoading,
|
|
111
120
|
isStreaming,
|
|
112
121
|
streamingText,
|
|
122
|
+
aiPaused,
|
|
113
123
|
error,
|
|
114
124
|
sendMessage,
|
|
115
125
|
clearChat,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@menuia/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "MenuIA Chat SDK - React Component",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"react-dom": ">=17.0.0"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@menuia/core": "^1.5.
|
|
20
|
+
"@menuia/core": "^1.5.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^18.2.0",
|