@menuia/core 1.0.0 → 1.1.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 +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +14 -6
- package/dist/index.mjs +14 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
interface MenuIAConfig {
|
|
2
|
-
|
|
2
|
+
/** Widget ID (from /dashboard/channels) - preferred */
|
|
3
|
+
widgetId?: string;
|
|
4
|
+
/** Agent ID (from /dashboard/agents) - fallback if no widgetId */
|
|
5
|
+
agentId?: string;
|
|
3
6
|
apiUrl?: string;
|
|
4
7
|
sessionId?: string;
|
|
5
8
|
customFields?: Record<string, string>;
|
|
@@ -59,7 +62,10 @@ declare class MenuIAClient {
|
|
|
59
62
|
private status;
|
|
60
63
|
private pollInterval;
|
|
61
64
|
private lastMessageCount;
|
|
65
|
+
private resolvedAgentId;
|
|
62
66
|
constructor(config: MenuIAConfig);
|
|
67
|
+
/** Get the effective ID (widgetId preferred, falls back to agentId) */
|
|
68
|
+
private getWidgetId;
|
|
63
69
|
/** Send a message to the AI agent */
|
|
64
70
|
sendMessage(options: SendMessageOptions): Promise<ChatResponse>;
|
|
65
71
|
/** Send a message and receive streaming response */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
interface MenuIAConfig {
|
|
2
|
-
|
|
2
|
+
/** Widget ID (from /dashboard/channels) - preferred */
|
|
3
|
+
widgetId?: string;
|
|
4
|
+
/** Agent ID (from /dashboard/agents) - fallback if no widgetId */
|
|
5
|
+
agentId?: string;
|
|
3
6
|
apiUrl?: string;
|
|
4
7
|
sessionId?: string;
|
|
5
8
|
customFields?: Record<string, string>;
|
|
@@ -59,7 +62,10 @@ declare class MenuIAClient {
|
|
|
59
62
|
private status;
|
|
60
63
|
private pollInterval;
|
|
61
64
|
private lastMessageCount;
|
|
65
|
+
private resolvedAgentId;
|
|
62
66
|
constructor(config: MenuIAConfig);
|
|
67
|
+
/** Get the effective ID (widgetId preferred, falls back to agentId) */
|
|
68
|
+
private getWidgetId;
|
|
63
69
|
/** Send a message to the AI agent */
|
|
64
70
|
sendMessage(options: SendMessageOptions): Promise<ChatResponse>;
|
|
65
71
|
/** Send a message and receive streaming response */
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,10 @@ var MenuIAClient = class {
|
|
|
32
32
|
this.status = "disconnected";
|
|
33
33
|
this.pollInterval = null;
|
|
34
34
|
this.lastMessageCount = 0;
|
|
35
|
+
this.resolvedAgentId = null;
|
|
36
|
+
if (!config.widgetId && !config.agentId) {
|
|
37
|
+
throw new Error("[MenuIA] widgetId ou agentId e obrigatorio");
|
|
38
|
+
}
|
|
35
39
|
this.config = {
|
|
36
40
|
...config,
|
|
37
41
|
apiUrl: config.apiUrl || DEFAULT_API_URL,
|
|
@@ -39,6 +43,10 @@ var MenuIAClient = class {
|
|
|
39
43
|
};
|
|
40
44
|
this.session = this.loadSession();
|
|
41
45
|
}
|
|
46
|
+
/** Get the effective ID (widgetId preferred, falls back to agentId) */
|
|
47
|
+
getWidgetId() {
|
|
48
|
+
return this.config.widgetId || this.config.agentId || "";
|
|
49
|
+
}
|
|
42
50
|
// =====================
|
|
43
51
|
// PUBLIC API
|
|
44
52
|
// =====================
|
|
@@ -47,13 +55,13 @@ var MenuIAClient = class {
|
|
|
47
55
|
this.setStatus("connecting");
|
|
48
56
|
try {
|
|
49
57
|
const body = {
|
|
50
|
-
agentId: this.
|
|
58
|
+
agentId: this.getWidgetId(),
|
|
51
59
|
message: options.content,
|
|
52
60
|
channel: this.config.channel,
|
|
53
61
|
sessionId: this.session.sessionId,
|
|
54
62
|
metadata: {
|
|
55
63
|
...this.config.metadata,
|
|
56
|
-
widgetId: this.
|
|
64
|
+
widgetId: this.getWidgetId(),
|
|
57
65
|
customData: this.config.customFields
|
|
58
66
|
}
|
|
59
67
|
};
|
|
@@ -109,13 +117,13 @@ var MenuIAClient = class {
|
|
|
109
117
|
this.setStatus("connecting");
|
|
110
118
|
try {
|
|
111
119
|
const body = {
|
|
112
|
-
agentId: this.
|
|
120
|
+
agentId: this.getWidgetId(),
|
|
113
121
|
message: options.content,
|
|
114
122
|
channel: this.config.channel,
|
|
115
123
|
sessionId: this.session.sessionId,
|
|
116
124
|
metadata: {
|
|
117
125
|
...this.config.metadata,
|
|
118
|
-
widgetId: this.
|
|
126
|
+
widgetId: this.getWidgetId(),
|
|
119
127
|
customData: this.config.customFields
|
|
120
128
|
}
|
|
121
129
|
};
|
|
@@ -204,7 +212,7 @@ var MenuIAClient = class {
|
|
|
204
212
|
if (!this.session.conversationId) return [];
|
|
205
213
|
try {
|
|
206
214
|
const response = await fetch(
|
|
207
|
-
`${this.config.apiUrl}/widget/history/${this.session.sessionId}?agentId=${this.
|
|
215
|
+
`${this.config.apiUrl}/widget/history/${this.session.sessionId}?agentId=${this.getWidgetId()}`
|
|
208
216
|
);
|
|
209
217
|
if (!response.ok) return this.session.messages;
|
|
210
218
|
const data = await response.json();
|
|
@@ -285,7 +293,7 @@ var MenuIAClient = class {
|
|
|
285
293
|
}
|
|
286
294
|
}
|
|
287
295
|
getSessionKey() {
|
|
288
|
-
return `${SESSION_KEY_PREFIX}${this.
|
|
296
|
+
return `${SESSION_KEY_PREFIX}${this.getWidgetId()}`;
|
|
289
297
|
}
|
|
290
298
|
loadSession() {
|
|
291
299
|
if (this.config.sessionId) {
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,10 @@ var MenuIAClient = class {
|
|
|
6
6
|
this.status = "disconnected";
|
|
7
7
|
this.pollInterval = null;
|
|
8
8
|
this.lastMessageCount = 0;
|
|
9
|
+
this.resolvedAgentId = null;
|
|
10
|
+
if (!config.widgetId && !config.agentId) {
|
|
11
|
+
throw new Error("[MenuIA] widgetId ou agentId e obrigatorio");
|
|
12
|
+
}
|
|
9
13
|
this.config = {
|
|
10
14
|
...config,
|
|
11
15
|
apiUrl: config.apiUrl || DEFAULT_API_URL,
|
|
@@ -13,6 +17,10 @@ var MenuIAClient = class {
|
|
|
13
17
|
};
|
|
14
18
|
this.session = this.loadSession();
|
|
15
19
|
}
|
|
20
|
+
/** Get the effective ID (widgetId preferred, falls back to agentId) */
|
|
21
|
+
getWidgetId() {
|
|
22
|
+
return this.config.widgetId || this.config.agentId || "";
|
|
23
|
+
}
|
|
16
24
|
// =====================
|
|
17
25
|
// PUBLIC API
|
|
18
26
|
// =====================
|
|
@@ -21,13 +29,13 @@ var MenuIAClient = class {
|
|
|
21
29
|
this.setStatus("connecting");
|
|
22
30
|
try {
|
|
23
31
|
const body = {
|
|
24
|
-
agentId: this.
|
|
32
|
+
agentId: this.getWidgetId(),
|
|
25
33
|
message: options.content,
|
|
26
34
|
channel: this.config.channel,
|
|
27
35
|
sessionId: this.session.sessionId,
|
|
28
36
|
metadata: {
|
|
29
37
|
...this.config.metadata,
|
|
30
|
-
widgetId: this.
|
|
38
|
+
widgetId: this.getWidgetId(),
|
|
31
39
|
customData: this.config.customFields
|
|
32
40
|
}
|
|
33
41
|
};
|
|
@@ -83,13 +91,13 @@ var MenuIAClient = class {
|
|
|
83
91
|
this.setStatus("connecting");
|
|
84
92
|
try {
|
|
85
93
|
const body = {
|
|
86
|
-
agentId: this.
|
|
94
|
+
agentId: this.getWidgetId(),
|
|
87
95
|
message: options.content,
|
|
88
96
|
channel: this.config.channel,
|
|
89
97
|
sessionId: this.session.sessionId,
|
|
90
98
|
metadata: {
|
|
91
99
|
...this.config.metadata,
|
|
92
|
-
widgetId: this.
|
|
100
|
+
widgetId: this.getWidgetId(),
|
|
93
101
|
customData: this.config.customFields
|
|
94
102
|
}
|
|
95
103
|
};
|
|
@@ -178,7 +186,7 @@ var MenuIAClient = class {
|
|
|
178
186
|
if (!this.session.conversationId) return [];
|
|
179
187
|
try {
|
|
180
188
|
const response = await fetch(
|
|
181
|
-
`${this.config.apiUrl}/widget/history/${this.session.sessionId}?agentId=${this.
|
|
189
|
+
`${this.config.apiUrl}/widget/history/${this.session.sessionId}?agentId=${this.getWidgetId()}`
|
|
182
190
|
);
|
|
183
191
|
if (!response.ok) return this.session.messages;
|
|
184
192
|
const data = await response.json();
|
|
@@ -259,7 +267,7 @@ var MenuIAClient = class {
|
|
|
259
267
|
}
|
|
260
268
|
}
|
|
261
269
|
getSessionKey() {
|
|
262
|
-
return `${SESSION_KEY_PREFIX}${this.
|
|
270
|
+
return `${SESSION_KEY_PREFIX}${this.getWidgetId()}`;
|
|
263
271
|
}
|
|
264
272
|
loadSession() {
|
|
265
273
|
if (this.config.sessionId) {
|