@fayz-ai/plugin-support 0.3.0-canary.20261028153856 → 0.3.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/{HelpdeskConsole-YCFXPFIX.js → HelpdeskConsole-EATEBVLN.js} +9 -8
- package/dist/HelpdeskConsole-EATEBVLN.js.map +1 -0
- package/dist/{LiveChatAgentWatcher-EGPPEZ4L.js → LiveChatAgentWatcher-WEUHRRLC.js} +9 -9
- package/dist/{LiveChatAgentWatcher-EGPPEZ4L.js.map → LiveChatAgentWatcher-WEUHRRLC.js.map} +1 -1
- package/dist/{OpenTicketFromConversation-KDXK7A6L.js → OpenTicketFromConversation-RC26KHN3.js} +4 -4
- package/dist/{OpenTicketFromConversation-KDXK7A6L.js.map → OpenTicketFromConversation-RC26KHN3.js.map} +1 -1
- package/dist/{SupportCenter-7UQGJGOV.js → SupportCenter-HGQL4PBX.js} +10 -9
- package/dist/SupportCenter-HGQL4PBX.js.map +1 -0
- package/dist/{SupportSettingsPage-PB6A3VCI.js → SupportSettingsPage-LIVZY2XQ.js} +3 -3
- package/dist/{SupportSettingsPage-PB6A3VCI.js.map → SupportSettingsPage-LIVZY2XQ.js.map} +1 -1
- package/dist/chunk-5MGCM5C4.js +181 -0
- package/dist/chunk-5MGCM5C4.js.map +1 -0
- package/dist/{chunk-2MHNBXOX.js → chunk-DTO5R6GN.js} +5 -5
- package/dist/{chunk-2MHNBXOX.js.map → chunk-DTO5R6GN.js.map} +1 -1
- package/dist/{chunk-UM4GEZWF.js → chunk-E5242OSS.js} +3 -3
- package/dist/{chunk-UM4GEZWF.js.map → chunk-E5242OSS.js.map} +1 -1
- package/dist/{chunk-5JJEN6KO.js → chunk-E5EXC7QW.js} +56 -17
- package/dist/chunk-E5EXC7QW.js.map +1 -0
- package/dist/{chunk-WOZTA5LS.js → chunk-L2HGTGW4.js} +6 -4
- package/dist/chunk-L2HGTGW4.js.map +1 -0
- package/dist/{chunk-BZBC2OYM.js → chunk-P4VNMWIT.js} +9 -180
- package/dist/chunk-P4VNMWIT.js.map +1 -0
- package/dist/{chunk-CWCN5PDE.js → chunk-PHIPTZSD.js} +48 -5
- package/dist/chunk-PHIPTZSD.js.map +1 -0
- package/dist/chunk-QBOQYER7.js +1603 -0
- package/dist/chunk-QBOQYER7.js.map +1 -0
- package/dist/{chunk-77VZVUK3.js → chunk-S766CRAY.js} +18 -5
- package/dist/chunk-S766CRAY.js.map +1 -0
- package/dist/{chunk-MGBQNKCH.js → chunk-WHEJ63CM.js} +4 -3
- package/dist/chunk-WHEJ63CM.js.map +1 -0
- package/dist/{chunk-5NDPMWHS.js → chunk-Y673XGDK.js} +36 -25
- package/dist/chunk-Y673XGDK.js.map +1 -0
- package/dist/data/api.d.ts +5 -0
- package/dist/data/api.d.ts.map +1 -1
- package/dist/data/console.d.ts +6 -0
- package/dist/data/console.d.ts.map +1 -1
- package/dist/data/mock-host.d.ts.map +1 -1
- package/dist/data/provider.d.ts +6 -0
- package/dist/data/provider.d.ts.map +1 -1
- package/dist/host.js +17 -14
- package/dist/host.js.map +1 -1
- package/dist/in-chat-install-2BTKBF2Z.js +11 -0
- package/dist/{in-chat-install-633DIRHJ.js.map → in-chat-install-2BTKBF2Z.js.map} +1 -1
- package/dist/index.js +16 -16
- package/dist/lib/imported.d.ts +27 -0
- package/dist/lib/imported.d.ts.map +1 -0
- package/dist/lib/report-tool.d.ts +13 -0
- package/dist/lib/report-tool.d.ts.map +1 -1
- package/dist/lib/vocabulary.d.ts.map +1 -1
- package/dist/livechat/in-chat-install.d.ts +2 -0
- package/dist/livechat/in-chat-install.d.ts.map +1 -1
- package/dist/livechat/in-chat-machine.d.ts +17 -3
- package/dist/livechat/in-chat-machine.d.ts.map +1 -1
- package/dist/livechat/in-chat-request-machine.d.ts +147 -0
- package/dist/livechat/in-chat-request-machine.d.ts.map +1 -0
- package/dist/livechat/in-chat-request.d.ts +94 -0
- package/dist/livechat/in-chat-request.d.ts.map +1 -0
- package/dist/livechat/in-chat-widgets.d.ts +13 -1
- package/dist/livechat/in-chat-widgets.d.ts.map +1 -1
- package/dist/livechat/in-chat.d.ts +20 -10
- package/dist/livechat/in-chat.d.ts.map +1 -1
- package/dist/livechat/report-intake.d.ts +45 -0
- package/dist/livechat/report-intake.d.ts.map +1 -0
- package/dist/livechat/screen-capture.d.ts +7 -0
- package/dist/livechat/screen-capture.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +3 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +1181 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/screen-capture-FRMTTRUY.js +77 -0
- package/dist/screen-capture-FRMTTRUY.js.map +1 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/views/TicketSheet.d.ts +11 -1
- package/dist/views/TicketSheet.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/HelpdeskConsole-YCFXPFIX.js.map +0 -1
- package/dist/SupportCenter-7UQGJGOV.js.map +0 -1
- package/dist/chunk-5JJEN6KO.js.map +0 -1
- package/dist/chunk-5NDPMWHS.js.map +0 -1
- package/dist/chunk-77VZVUK3.js.map +0 -1
- package/dist/chunk-BZBC2OYM.js.map +0 -1
- package/dist/chunk-CB3B4FFU.js +0 -1002
- package/dist/chunk-CB3B4FFU.js.map +0 -1
- package/dist/chunk-CWCN5PDE.js.map +0 -1
- package/dist/chunk-MGBQNKCH.js.map +0 -1
- package/dist/chunk-WOZTA5LS.js.map +0 -1
- package/dist/in-chat-install-633DIRHJ.js +0 -11
package/dist/chunk-CB3B4FFU.js
DELETED
|
@@ -1,1002 +0,0 @@
|
|
|
1
|
-
import { setSupportToolBridge, supportToolHandlers } from './chunk-5NDPMWHS.js';
|
|
2
|
-
import { setLiveChatOpener } from './chunk-JOS2QQML.js';
|
|
3
|
-
import { supportData, useSupportStore } from './chunk-MGBQNKCH.js';
|
|
4
|
-
import { customerPhase, queueLine, liveChatError, buildTranscript, chatSubject, PRESENCE_WAIT_MS, TYPING_SHOW_MS, isActiveChatStatus, MAX_ATTACHMENT_BYTES, MAX_ATTACHMENTS } from './chunk-77VZVUK3.js';
|
|
5
|
-
import { describeBusinessHours } from './chunk-ZEHBREG5.js';
|
|
6
|
-
import { observeAgentsOnline, listenTopic, conversationTopic } from './chunk-3WPESEK2.js';
|
|
7
|
-
import { KIND_LABEL, STATUS_LABEL, STATUS_TONE, canValidate, canMessage } from './chunk-WOZTA5LS.js';
|
|
8
|
-
import { currentChatContext, takeTurnReportFiles, registerChatWidget, registerChatAction, postUserLine, postAssistantLine, useChatStore, registerAIToolHandler, unregisterAIToolHandler, registerChatSupportHandler, getChatHandoff, openAssistant, postSystemLine, publishChatHandoff } from '@fayz-ai/admin';
|
|
9
|
-
import { getRecentActivity } from '@fayz-ai/core';
|
|
10
|
-
import React from 'react';
|
|
11
|
-
import { Paperclip, X, ImagePlus, Send, CheckCircle2 } from 'lucide-react';
|
|
12
|
-
import { Textarea, Button, cn, Skeleton, Badge } from '@fayz-ai/ui';
|
|
13
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
-
|
|
15
|
-
// src/livechat/in-chat-machine.ts
|
|
16
|
-
var INITIAL_IN_CHAT = {
|
|
17
|
-
phase: "idle",
|
|
18
|
-
requestId: null,
|
|
19
|
-
number: null,
|
|
20
|
-
agentName: null,
|
|
21
|
-
position: null,
|
|
22
|
-
ratingBy: null,
|
|
23
|
-
announced: null
|
|
24
|
-
};
|
|
25
|
-
var LIVE = ["waiting", "chatting", "rating", "closing"];
|
|
26
|
-
function isLivePhase(phase) {
|
|
27
|
-
return LIVE.includes(phase);
|
|
28
|
-
}
|
|
29
|
-
function ended(state, text) {
|
|
30
|
-
return { state: { ...INITIAL_IN_CHAT }, effects: [{ k: "line", text }, { k: "done" }] };
|
|
31
|
-
}
|
|
32
|
-
function endedLine(number) {
|
|
33
|
-
return number ? `Conversa com o suporte encerrada \xB7 #${number}` : "Conversa com o suporte encerrada";
|
|
34
|
-
}
|
|
35
|
-
function stepInChat(state, event) {
|
|
36
|
-
switch (event.t) {
|
|
37
|
-
case "start":
|
|
38
|
-
if (state.phase !== "idle") return { state, effects: [] };
|
|
39
|
-
return { state: { ...INITIAL_IN_CHAT, phase: "connecting" }, effects: [] };
|
|
40
|
-
case "nobody":
|
|
41
|
-
if (state.phase !== "connecting") return { state, effects: [] };
|
|
42
|
-
return { state: { ...INITIAL_IN_CHAT }, effects: [{ k: "offline" }] };
|
|
43
|
-
case "failed":
|
|
44
|
-
if (state.phase !== "connecting") return { state, effects: [] };
|
|
45
|
-
return { state: { ...INITIAL_IN_CHAT }, effects: [{ k: "done" }] };
|
|
46
|
-
case "opened": {
|
|
47
|
-
if (state.phase !== "idle" && state.phase !== "connecting") return { state, effects: [] };
|
|
48
|
-
const text = event.resumed ? `Conversa com o suporte #${event.number} retomada` : `Voc\xEA est\xE1 falando com a equipe de suporte \xB7 #${event.number}`;
|
|
49
|
-
return {
|
|
50
|
-
state: { ...INITIAL_IN_CHAT, phase: "waiting", requestId: event.id, number: event.number },
|
|
51
|
-
effects: [{ k: "line", text }]
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
case "agent": {
|
|
55
|
-
if (!isLivePhase(state.phase) || !event.name || event.name === state.announced) return { state, effects: [] };
|
|
56
|
-
return {
|
|
57
|
-
state: { ...state, agentName: event.name, announced: event.name },
|
|
58
|
-
effects: [{ k: "line", text: `${event.name} entrou na conversa` }]
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
case "state": {
|
|
62
|
-
if (!isLivePhase(state.phase)) return { state, effects: [] };
|
|
63
|
-
const s = event.snapshot;
|
|
64
|
-
const phase = customerPhase(s);
|
|
65
|
-
if (phase === "closed") return ended(state, endedLine(state.number));
|
|
66
|
-
const effects = [];
|
|
67
|
-
let next = { ...state, agentName: s.agentName ?? state.agentName, position: s.position };
|
|
68
|
-
if (s.agentName && s.agentName !== state.announced) {
|
|
69
|
-
effects.push({ k: "line", text: `${s.agentName} entrou na conversa` });
|
|
70
|
-
next = { ...next, announced: s.agentName };
|
|
71
|
-
}
|
|
72
|
-
if (phase === "resolved") {
|
|
73
|
-
if (state.phase !== "rating") {
|
|
74
|
-
effects.push({ k: "ask-rating", by: "team" });
|
|
75
|
-
next = { ...next, phase: "rating", ratingBy: "team" };
|
|
76
|
-
}
|
|
77
|
-
return { state: next, effects };
|
|
78
|
-
}
|
|
79
|
-
if (state.phase === "rating" || state.phase === "closing") return { state: next, effects };
|
|
80
|
-
next = { ...next, phase: phase === "waiting" ? "waiting" : "chatting" };
|
|
81
|
-
return { state: next, effects };
|
|
82
|
-
}
|
|
83
|
-
case "end":
|
|
84
|
-
if (state.phase === "waiting") return { state: { ...state, phase: "closing" }, effects: [{ k: "cancel" }] };
|
|
85
|
-
if (state.phase === "chatting") {
|
|
86
|
-
return { state: { ...state, phase: "rating", ratingBy: "user" }, effects: [{ k: "ask-rating", by: "user" }] };
|
|
87
|
-
}
|
|
88
|
-
return { state, effects: [] };
|
|
89
|
-
case "continue":
|
|
90
|
-
if (state.phase !== "rating" || state.ratingBy !== "user") return { state, effects: [] };
|
|
91
|
-
return { state: { ...state, phase: "chatting", ratingBy: null }, effects: [] };
|
|
92
|
-
case "rated":
|
|
93
|
-
if (state.phase !== "rating") return { state, effects: [] };
|
|
94
|
-
return ended(
|
|
95
|
-
state,
|
|
96
|
-
event.ok || !state.number ? endedLine(state.number) : `${endedLine(state.number)} \xB7 a equipe continua pela solicita\xE7\xE3o`
|
|
97
|
-
);
|
|
98
|
-
case "closed":
|
|
99
|
-
if (!isLivePhase(state.phase)) return { state, effects: [] };
|
|
100
|
-
return ended(state, endedLine(state.number));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function statusLine(state) {
|
|
104
|
-
switch (state.phase) {
|
|
105
|
-
case "connecting":
|
|
106
|
-
return { status: "Procurando um atendente dispon\xEDvel\u2026", detail: null };
|
|
107
|
-
case "waiting":
|
|
108
|
-
return { status: "Aguardando um atendente \xB7 a equipe j\xE1 recebeu sua conversa", detail: queueLine(state.position) };
|
|
109
|
-
case "chatting":
|
|
110
|
-
return { status: state.agentName ? `${state.agentName}, do suporte \xB7 online` : "Equipe de suporte \xB7 online", detail: null };
|
|
111
|
-
case "rating":
|
|
112
|
-
return { status: "Conversa terminando \xB7 conte se ficou bom", detail: null };
|
|
113
|
-
case "closing":
|
|
114
|
-
return { status: "Encerrando a conversa\u2026", detail: null };
|
|
115
|
-
default:
|
|
116
|
-
return { status: "", detail: null };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/livechat/in-chat.ts
|
|
121
|
-
var MSG_PREFIX = "support-msg-";
|
|
122
|
-
function initialsOf(name) {
|
|
123
|
-
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
124
|
-
if (!words.length) return "";
|
|
125
|
-
if (words.length === 1) return words[0].slice(0, 2).toUpperCase();
|
|
126
|
-
return (words[0][0] + words[words.length - 1][0]).toUpperCase();
|
|
127
|
-
}
|
|
128
|
-
function supportMessageId(providerId) {
|
|
129
|
-
return `${MSG_PREFIX}${providerId}`;
|
|
130
|
-
}
|
|
131
|
-
function personName(author) {
|
|
132
|
-
return String(author ?? "").replace(/\s*\(.*?\)\s*$/, "").trim() || "Equipe de suporte";
|
|
133
|
-
}
|
|
134
|
-
function toPending(file) {
|
|
135
|
-
return {
|
|
136
|
-
id: globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
|
137
|
-
file,
|
|
138
|
-
name: file.name || "anexo",
|
|
139
|
-
contentType: file.type || "application/octet-stream",
|
|
140
|
-
sizeBytes: file.size
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function attachmentKind(file) {
|
|
144
|
-
if (file.type.startsWith("image/")) return "image";
|
|
145
|
-
if (file.type === "application/pdf") return "pdf";
|
|
146
|
-
return "binary";
|
|
147
|
-
}
|
|
148
|
-
var InChatController = class {
|
|
149
|
-
constructor(deps) {
|
|
150
|
-
this.state = { ...INITIAL_IN_CHAT };
|
|
151
|
-
/** provider message id → message id in the chat (an echo keeps its own id). */
|
|
152
|
-
this.mirrored = /* @__PURE__ */ new Map();
|
|
153
|
-
/** What the person typed and is still on its way (matched to the thread by body). */
|
|
154
|
-
this.echoes = [];
|
|
155
|
-
this.conversationId = null;
|
|
156
|
-
this.timer = null;
|
|
157
|
-
this.bellOff = null;
|
|
158
|
-
this.typing = false;
|
|
159
|
-
this.typingTimer = null;
|
|
160
|
-
this.lastTypingSent = 0;
|
|
161
|
-
this.polling = null;
|
|
162
|
-
this.resumeChecked = false;
|
|
163
|
-
this.seq = 0;
|
|
164
|
-
this.surface = deps.surface;
|
|
165
|
-
this.provider = deps.provider ?? supportData;
|
|
166
|
-
this.realtime = deps.realtime ?? null;
|
|
167
|
-
}
|
|
168
|
-
get snapshot() {
|
|
169
|
-
return this.state;
|
|
170
|
-
}
|
|
171
|
-
/** "Atendente" (header), "Falar com um atendente" (chip) or the model's startLiveChat. */
|
|
172
|
-
async start(ctx) {
|
|
173
|
-
if (this.state.phase !== "idle") {
|
|
174
|
-
this.surface.openAssistant();
|
|
175
|
-
return { ok: true, number: this.state.number ?? void 0 };
|
|
176
|
-
}
|
|
177
|
-
this.dispatch({ t: "start" });
|
|
178
|
-
this.surface.openAssistant();
|
|
179
|
-
let availability;
|
|
180
|
-
try {
|
|
181
|
-
availability = await this.provider().chatAvailability();
|
|
182
|
-
} catch (error) {
|
|
183
|
-
this.dispatch({ t: "failed" });
|
|
184
|
-
this.surface.assistantLine(liveChatError(error));
|
|
185
|
-
return { ok: false, reason: "unavailable" };
|
|
186
|
-
}
|
|
187
|
-
if (availability?.activeChat) {
|
|
188
|
-
await this.resume(availability.activeChat.id, availability.activeChat.number, true);
|
|
189
|
-
return { ok: true, number: availability.activeChat.number };
|
|
190
|
-
}
|
|
191
|
-
if (!availability || !availability.enabled || !availability.homeId) {
|
|
192
|
-
this.offline(availability, ctx, "O atendimento ao vivo n\xE3o est\xE1 dispon\xEDvel nesta conta.");
|
|
193
|
-
return { ok: false, reason: "no_live_chat" };
|
|
194
|
-
}
|
|
195
|
-
const online = await this.countOnline(availability);
|
|
196
|
-
if (online <= 0) {
|
|
197
|
-
this.offline(availability, ctx);
|
|
198
|
-
return { ok: false, reason: "nobody_online" };
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
const msgs = ctx.transcript ?? [];
|
|
202
|
-
const opened = await this.provider().openChat({
|
|
203
|
-
subject: chatSubject(msgs),
|
|
204
|
-
description: msgs.length ? buildTranscript(msgs) : null,
|
|
205
|
-
route: ctx.route,
|
|
206
|
-
originConversationId: ctx.conversationId
|
|
207
|
-
});
|
|
208
|
-
this.dispatch({ t: "opened", id: opened.id, number: opened.number, resumed: opened.reused });
|
|
209
|
-
await this.poll({ baseline: !opened.reused });
|
|
210
|
-
this.startPolling();
|
|
211
|
-
this.surface.focusComposer();
|
|
212
|
-
return { ok: true, number: opened.number };
|
|
213
|
-
} catch (error) {
|
|
214
|
-
this.dispatch({ t: "failed" });
|
|
215
|
-
this.surface.assistantLine(liveChatError(error));
|
|
216
|
-
return { ok: false, reason: "open_failed" };
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/** Back to a live chat that is still open ("Voltar à conversa #N", a reload, Minhas solicitações). */
|
|
220
|
-
async resume(requestId, number, fromStart = false) {
|
|
221
|
-
if (isLivePhase(this.state.phase)) {
|
|
222
|
-
if (this.state.requestId === requestId) {
|
|
223
|
-
this.surface.openAssistant();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (!fromStart && this.state.phase === "connecting") return;
|
|
229
|
-
if (!number) {
|
|
230
|
-
try {
|
|
231
|
-
number = (await this.provider().chatState(requestId)).number;
|
|
232
|
-
} catch {
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
this.dispatch({ t: "opened", id: requestId, number, resumed: true });
|
|
236
|
-
this.surface.openAssistant();
|
|
237
|
-
await this.poll({ baseline: false });
|
|
238
|
-
this.startPolling();
|
|
239
|
-
this.surface.focusComposer();
|
|
240
|
-
}
|
|
241
|
-
/** Called when the assistant opens: an open live chat takes the conversation over. */
|
|
242
|
-
async checkResume(force = false) {
|
|
243
|
-
if (this.state.phase !== "idle") return;
|
|
244
|
-
if (this.resumeChecked && !force) return;
|
|
245
|
-
this.resumeChecked = true;
|
|
246
|
-
try {
|
|
247
|
-
const a = await this.provider().chatAvailability();
|
|
248
|
-
if (a?.activeChat && this.state.phase === "idle") await this.resume(a.activeChat.id, a.activeChat.number);
|
|
249
|
-
} catch {
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
/** "Encerrar". */
|
|
253
|
-
async end() {
|
|
254
|
-
this.dispatch({ t: "end" });
|
|
255
|
-
}
|
|
256
|
-
async send(text, files = []) {
|
|
257
|
-
const id = this.state.requestId;
|
|
258
|
-
if (!id || this.state.phase !== "waiting" && this.state.phase !== "chatting") return;
|
|
259
|
-
const body = text.trim();
|
|
260
|
-
const p = this.provider();
|
|
261
|
-
const canAttach = typeof p.addAttachments === "function";
|
|
262
|
-
const sendable = canAttach ? files : [];
|
|
263
|
-
if (!body && !sendable.length) return;
|
|
264
|
-
const echoId = `support-echo-${Date.now().toString(36)}-${(this.seq++).toString(36)}`;
|
|
265
|
-
this.surface.upsert({
|
|
266
|
-
id: echoId,
|
|
267
|
-
role: "user",
|
|
268
|
-
content: body,
|
|
269
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
270
|
-
local: true,
|
|
271
|
-
...sendable.length ? { attachments: sendable.map((f) => ({ name: f.name || "anexo", kind: attachmentKind(f) })) } : {}
|
|
272
|
-
});
|
|
273
|
-
if (body) this.echoes.push({ id: echoId, body });
|
|
274
|
-
try {
|
|
275
|
-
if (body) await p.addMessage(id, body);
|
|
276
|
-
if (sendable.length) await p.addAttachments(id, sendable.map(toPending));
|
|
277
|
-
await this.poll();
|
|
278
|
-
} catch (error) {
|
|
279
|
-
this.surface.assistantLine(`N\xE3o consegui enviar para a equipe: ${liveChatError(error)}`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/** The person is typing (platform only: the other side's "digitando…"). */
|
|
283
|
-
notifyTyping() {
|
|
284
|
-
if (!this.realtime || !this.conversationId || this.provider().realtime === false) return;
|
|
285
|
-
const now = Date.now();
|
|
286
|
-
if (now - this.lastTypingSent < 2e3) return;
|
|
287
|
-
this.lastTypingSent = now;
|
|
288
|
-
void import('./realtime-HQVWBTML.js').then((r) => r.sendTyping(this.conversationId, "customer")).catch(() => {
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
/** Reads the chat now (the poll, a bell, after a send). */
|
|
292
|
-
poll(options = {}) {
|
|
293
|
-
if (this.polling && !options.baseline) return this.polling;
|
|
294
|
-
const run = this.readOnce(options).finally(() => {
|
|
295
|
-
if (this.polling === run) this.polling = null;
|
|
296
|
-
});
|
|
297
|
-
this.polling = run;
|
|
298
|
-
return run;
|
|
299
|
-
}
|
|
300
|
-
/** Tears everything down (tests, a host disposing). */
|
|
301
|
-
dispose() {
|
|
302
|
-
this.stopPolling();
|
|
303
|
-
this.state = { ...INITIAL_IN_CHAT };
|
|
304
|
-
this.mirrored.clear();
|
|
305
|
-
this.echoes = [];
|
|
306
|
-
this.surface.publish(null);
|
|
307
|
-
}
|
|
308
|
-
// ── internals ──────────────────────────────────────────────────────────
|
|
309
|
-
async readOnce(options) {
|
|
310
|
-
const id = this.state.requestId;
|
|
311
|
-
if (!id || !isLivePhase(this.state.phase)) return;
|
|
312
|
-
const p = this.provider();
|
|
313
|
-
let state, thread;
|
|
314
|
-
try {
|
|
315
|
-
;
|
|
316
|
-
[state, thread] = await Promise.all([p.chatState(id), p.chatThread(id)]);
|
|
317
|
-
} catch {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (this.state.requestId !== id) return;
|
|
321
|
-
if (state.conversationId && state.conversationId !== this.conversationId) this.listen(state.conversationId);
|
|
322
|
-
if (this.mirrored.size && ![...this.mirrored.values()].some((mid) => this.surface.has(mid))) {
|
|
323
|
-
this.mirrored.clear();
|
|
324
|
-
this.surface.systemLine(`Voc\xEA est\xE1 falando com a equipe de suporte \xB7 #${this.state.number}`);
|
|
325
|
-
}
|
|
326
|
-
if (state.agentName) this.dispatch({ t: "agent", name: state.agentName });
|
|
327
|
-
this.mirror(thread, !!options.baseline);
|
|
328
|
-
this.dispatch({
|
|
329
|
-
t: "state",
|
|
330
|
-
snapshot: { status: state.status, waiting: state.waiting, teamReplied: state.teamReplied, agentName: state.agentName, position: state.position }
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
mirror(thread, baseline) {
|
|
334
|
-
for (const m of thread) {
|
|
335
|
-
if (this.mirrored.has(m.id)) continue;
|
|
336
|
-
const chatId = supportMessageId(m.id);
|
|
337
|
-
if (m.mine) {
|
|
338
|
-
const echo = this.echoes.findIndex((e) => e.body === m.body.trim());
|
|
339
|
-
if (echo >= 0) {
|
|
340
|
-
this.mirrored.set(m.id, this.echoes[echo].id);
|
|
341
|
-
this.echoes.splice(echo, 1);
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
this.mirrored.set(m.id, chatId);
|
|
345
|
-
if (baseline || this.surface.has(chatId)) continue;
|
|
346
|
-
this.surface.upsert({ id: chatId, role: "user", content: m.body, timestamp: m.at, local: true });
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
this.mirrored.set(m.id, chatId);
|
|
350
|
-
if (this.surface.has(chatId)) continue;
|
|
351
|
-
const name = personName(m.author);
|
|
352
|
-
this.surface.upsert({
|
|
353
|
-
id: chatId,
|
|
354
|
-
role: "assistant",
|
|
355
|
-
content: m.body,
|
|
356
|
-
timestamp: m.at,
|
|
357
|
-
local: true,
|
|
358
|
-
author: { name, initials: initialsOf(name), human: true }
|
|
359
|
-
});
|
|
360
|
-
this.typing = false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
dispatch(event) {
|
|
364
|
-
const { state, effects } = stepInChat(this.state, event);
|
|
365
|
-
const prev = this.state;
|
|
366
|
-
this.state = state;
|
|
367
|
-
for (const effect of effects) this.apply(effect, prev);
|
|
368
|
-
this.publish();
|
|
369
|
-
}
|
|
370
|
-
apply(effect, prev) {
|
|
371
|
-
switch (effect.k) {
|
|
372
|
-
case "line":
|
|
373
|
-
this.surface.systemLine(effect.text);
|
|
374
|
-
return;
|
|
375
|
-
case "ask-rating": {
|
|
376
|
-
const actions = [
|
|
377
|
-
{ id: "ok", label: "Ficou bom", icon: "Check", primary: true, run: () => {
|
|
378
|
-
this.surface.userLine("Ficou bom");
|
|
379
|
-
return this.rate(true);
|
|
380
|
-
} },
|
|
381
|
-
{ id: "no", label: "Ainda n\xE3o resolveu", run: () => {
|
|
382
|
-
this.surface.userLine("Ainda n\xE3o resolveu");
|
|
383
|
-
return this.rate(false);
|
|
384
|
-
} },
|
|
385
|
-
...effect.by === "user" ? [{ id: "continue", label: "Continuar conversando", run: () => {
|
|
386
|
-
this.surface.userLine("Continuar conversando");
|
|
387
|
-
this.dispatch({ t: "continue" });
|
|
388
|
-
} }] : []
|
|
389
|
-
];
|
|
390
|
-
this.surface.assistantLine(
|
|
391
|
-
effect.by === "team" ? "A equipe marcou a conversa como resolvida. Ficou bom?" : "Antes de encerrar: ficou bom?",
|
|
392
|
-
{ id: `support-rating-${this.state.requestId}-${Date.now().toString(36)}`, actions }
|
|
393
|
-
);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
case "cancel": {
|
|
397
|
-
const id = prev.requestId;
|
|
398
|
-
if (!id) return;
|
|
399
|
-
void this.provider().cancelRequest(id).catch(() => {
|
|
400
|
-
}).finally(() => this.dispatch({ t: "closed" }));
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
case "offline":
|
|
404
|
-
return;
|
|
405
|
-
// posted by offline() with the central's own words
|
|
406
|
-
case "done":
|
|
407
|
-
this.stopPolling();
|
|
408
|
-
this.mirrored.clear();
|
|
409
|
-
this.echoes = [];
|
|
410
|
-
this.typing = false;
|
|
411
|
-
this.surface.showSuggestions();
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async rate(ok) {
|
|
416
|
-
const id = this.state.requestId;
|
|
417
|
-
const number = this.state.number;
|
|
418
|
-
if (!id) return;
|
|
419
|
-
try {
|
|
420
|
-
await this.provider().validateRequest(id, ok, ok ? void 0 : "Ainda n\xE3o resolveu (conversa no assistente)");
|
|
421
|
-
} catch (error) {
|
|
422
|
-
this.surface.assistantLine(liveChatError(error));
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
this.dispatch({ t: "rated", ok });
|
|
426
|
-
this.surface.assistantLine(
|
|
427
|
-
ok ? "Que bom! Se precisar de mais alguma coisa, \xE9 s\xF3 chamar." : `Certo. A equipe segue pela solicita\xE7\xE3o #${number} e responde por aqui e por e-mail.`
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
offline(a, ctx, why) {
|
|
431
|
-
this.dispatch({ t: "nobody" });
|
|
432
|
-
const hours = a ? describeBusinessHours({ businessHours: a.businessHours }) : "";
|
|
433
|
-
const parts = [
|
|
434
|
-
why ?? "Ningu\xE9m da equipe est\xE1 online agora.",
|
|
435
|
-
a?.offlineMessage ?? "Deixe um recado: a equipe responde por aqui e por e-mail.",
|
|
436
|
-
hours ? `Hor\xE1rio de atendimento: ${hours}.` : ""
|
|
437
|
-
].filter(Boolean);
|
|
438
|
-
this.surface.assistantLine(parts.join(" "), {
|
|
439
|
-
actions: [{
|
|
440
|
-
id: "leave-message",
|
|
441
|
-
label: "Deixar recado para a equipe",
|
|
442
|
-
icon: "MessageSquare",
|
|
443
|
-
primary: true,
|
|
444
|
-
run: () => {
|
|
445
|
-
openRequestForm(this.surface, "other", { transcript: ctx.transcript, echo: "Deixar recado para a equipe" });
|
|
446
|
-
}
|
|
447
|
-
}]
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
async countOnline(a) {
|
|
451
|
-
if (typeof a.online === "number") return a.online;
|
|
452
|
-
if (!this.realtime || !a.homeId) return 0;
|
|
453
|
-
return new Promise((resolve) => {
|
|
454
|
-
let settled = false;
|
|
455
|
-
let off = null;
|
|
456
|
-
const finish = (n) => {
|
|
457
|
-
if (settled) return;
|
|
458
|
-
settled = true;
|
|
459
|
-
off?.();
|
|
460
|
-
resolve(n);
|
|
461
|
-
};
|
|
462
|
-
const t = setTimeout(() => finish(0), PRESENCE_WAIT_MS);
|
|
463
|
-
off = this.realtime.observeOnline(a.homeId, (n) => {
|
|
464
|
-
if (n && n > 0) {
|
|
465
|
-
clearTimeout(t);
|
|
466
|
-
finish(n);
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
listen(conversationId) {
|
|
472
|
-
this.bellOff?.();
|
|
473
|
-
this.bellOff = null;
|
|
474
|
-
this.conversationId = conversationId;
|
|
475
|
-
if (!this.realtime || this.provider().realtime === false) return;
|
|
476
|
-
this.bellOff = this.realtime.listen(conversationId, (e) => {
|
|
477
|
-
if (e.event === "typing") {
|
|
478
|
-
if (e.payload.from === "customer") return;
|
|
479
|
-
this.typing = true;
|
|
480
|
-
if (this.typingTimer) clearTimeout(this.typingTimer);
|
|
481
|
-
this.typingTimer = setTimeout(() => {
|
|
482
|
-
this.typing = false;
|
|
483
|
-
this.publish();
|
|
484
|
-
}, TYPING_SHOW_MS);
|
|
485
|
-
this.publish();
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
void this.poll();
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
startPolling() {
|
|
492
|
-
if (this.timer) return;
|
|
493
|
-
const p = this.provider();
|
|
494
|
-
const every = p.pollMs?.chat ?? (p.realtime === false ? 4e3 : 15e3);
|
|
495
|
-
this.timer = setInterval(() => {
|
|
496
|
-
void this.poll();
|
|
497
|
-
}, every);
|
|
498
|
-
}
|
|
499
|
-
stopPolling() {
|
|
500
|
-
if (this.timer) {
|
|
501
|
-
clearInterval(this.timer);
|
|
502
|
-
this.timer = null;
|
|
503
|
-
}
|
|
504
|
-
this.bellOff?.();
|
|
505
|
-
this.bellOff = null;
|
|
506
|
-
this.conversationId = null;
|
|
507
|
-
if (this.typingTimer) {
|
|
508
|
-
clearTimeout(this.typingTimer);
|
|
509
|
-
this.typingTimer = null;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
publish() {
|
|
513
|
-
const s = this.state;
|
|
514
|
-
if (s.phase === "idle") {
|
|
515
|
-
this.surface.publish(null);
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const { status, detail } = statusLine(s);
|
|
519
|
-
const person = s.phase !== "connecting" && s.phase !== "waiting" && s.agentName ? personName(s.agentName) : null;
|
|
520
|
-
const canAttach = typeof this.provider().addAttachments === "function";
|
|
521
|
-
this.surface.publish({
|
|
522
|
-
id: s.requestId ?? "support-connecting",
|
|
523
|
-
responder: person ? { name: person, initials: initialsOf(person) } : { name: "Atendente" },
|
|
524
|
-
presence: s.phase === "chatting" || s.phase === "rating" ? "online" : "waiting",
|
|
525
|
-
status,
|
|
526
|
-
detail,
|
|
527
|
-
typing: this.typing,
|
|
528
|
-
attachments: canAttach,
|
|
529
|
-
placeholder: s.phase === "chatting" && person ? `Escreva para ${person.split(" ")[0]}\u2026` : "Escreva para a equipe\u2026",
|
|
530
|
-
composerDisabled: s.phase === "connecting" || s.phase === "rating" || s.phase === "closing",
|
|
531
|
-
send: (text, files) => this.send(text, files),
|
|
532
|
-
onTyping: () => this.notifyTyping(),
|
|
533
|
-
...s.phase === "waiting" || s.phase === "chatting" ? { end: { label: "Encerrar", run: () => this.end() } } : {}
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
var REQUEST_FORM_WIDGET = "support.request-form";
|
|
538
|
-
var REQUEST_RESULT_WIDGET = "support.request-result";
|
|
539
|
-
var REQUESTS_LIST_WIDGET = "support.requests-list";
|
|
540
|
-
var REQUEST_THREAD_WIDGET = "support.request-thread";
|
|
541
|
-
var FORM_INTRO = {
|
|
542
|
-
problem: "Me conte o que aconteceu: o que voc\xEA fazia, o que esperava e o que apareceu. Se tiver um print, anexe.",
|
|
543
|
-
improvement: "Conte a sua ideia: o que voc\xEA gostaria que o sistema fizesse e para qu\xEA.",
|
|
544
|
-
other: "Escreva o que voc\xEA precisa (treinamento, acesso, dados, comercial). A equipe responde por aqui e por e-mail."
|
|
545
|
-
};
|
|
546
|
-
function openRequestForm(surface2, kind, options = {}) {
|
|
547
|
-
if (options.echo) surface2.userLine(options.echo);
|
|
548
|
-
return surface2.assistantLine(FORM_INTRO[kind], {
|
|
549
|
-
widget: {
|
|
550
|
-
type: REQUEST_FORM_WIDGET,
|
|
551
|
-
props: {
|
|
552
|
-
kind,
|
|
553
|
-
...options.transcript?.length ? { transcript: buildTranscript(options.transcript, 3e3) } : {}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
function requestSnapshot(extra = {}) {
|
|
559
|
-
let activity = [];
|
|
560
|
-
try {
|
|
561
|
-
activity = getRecentActivity(10);
|
|
562
|
-
} catch {
|
|
563
|
-
}
|
|
564
|
-
return { activity, origin: "assistant", ...extra };
|
|
565
|
-
}
|
|
566
|
-
var cardHost = null;
|
|
567
|
-
function setInChatCardHost(host) {
|
|
568
|
-
cardHost = host;
|
|
569
|
-
}
|
|
570
|
-
function currentRoute() {
|
|
571
|
-
if (typeof location === "undefined") return null;
|
|
572
|
-
return location.hash || location.pathname || null;
|
|
573
|
-
}
|
|
574
|
-
function toPending2(file) {
|
|
575
|
-
return {
|
|
576
|
-
id: globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
|
577
|
-
file,
|
|
578
|
-
name: file.name || "anexo",
|
|
579
|
-
contentType: file.type || "application/octet-stream",
|
|
580
|
-
sizeBytes: file.size
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
var CARD = "rounded-2xl border border-border bg-card p-3 text-sm shadow-sm";
|
|
584
|
-
function RequestFormCard({ messageId, props }) {
|
|
585
|
-
const kind = ["problem", "improvement", "other"].includes(String(props.kind)) ? props.kind : "problem";
|
|
586
|
-
const [text, setText] = React.useState("");
|
|
587
|
-
const [files, setFiles] = React.useState([]);
|
|
588
|
-
const [busy, setBusy] = React.useState(false);
|
|
589
|
-
const [error, setError] = React.useState(null);
|
|
590
|
-
const input = React.useRef(null);
|
|
591
|
-
const add = (list) => {
|
|
592
|
-
const ok = list.filter((f) => f.size <= MAX_ATTACHMENT_BYTES);
|
|
593
|
-
setFiles((prev) => [...prev, ...ok].slice(0, MAX_ATTACHMENTS));
|
|
594
|
-
if (ok.length < list.length) setError("Arquivo acima de 20 MB fica de fora.");
|
|
595
|
-
};
|
|
596
|
-
async function submit() {
|
|
597
|
-
const description = text.trim();
|
|
598
|
-
if (description.length < 5) {
|
|
599
|
-
setError("Escreva pelo menos uma frase.");
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
setBusy(true);
|
|
603
|
-
setError(null);
|
|
604
|
-
try {
|
|
605
|
-
const res = await supportData().createRequest({
|
|
606
|
-
kind,
|
|
607
|
-
description,
|
|
608
|
-
subject: null,
|
|
609
|
-
route: currentRoute(),
|
|
610
|
-
screenSnapshot: requestSnapshot(typeof props.transcript === "string" ? { assistant_transcript: props.transcript } : {})
|
|
611
|
-
}, files.map(toPending2));
|
|
612
|
-
try {
|
|
613
|
-
void useSupportStore.getState().loadList();
|
|
614
|
-
} catch {
|
|
615
|
-
}
|
|
616
|
-
cardHost?.patchMessage(messageId, {
|
|
617
|
-
content: "Pronto, registrei.",
|
|
618
|
-
widget: { type: "support.request-result", props: { id: res.id, number: res.number, kind, attachments: files.length } }
|
|
619
|
-
});
|
|
620
|
-
cardHost?.showSuggestions();
|
|
621
|
-
} catch (e) {
|
|
622
|
-
setError(liveChatError(e));
|
|
623
|
-
setBusy(false);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return /* @__PURE__ */ jsxs("div", { className: CARD, "data-testid": "support-request-form", children: [
|
|
627
|
-
/* @__PURE__ */ jsx("p", { className: "pb-2 text-xs font-medium text-muted-foreground", children: KIND_LABEL[kind] }),
|
|
628
|
-
/* @__PURE__ */ jsx(
|
|
629
|
-
Textarea,
|
|
630
|
-
{
|
|
631
|
-
autoFocus: true,
|
|
632
|
-
rows: 3,
|
|
633
|
-
value: text,
|
|
634
|
-
disabled: busy,
|
|
635
|
-
onChange: (e) => setText(e.target.value),
|
|
636
|
-
onPaste: (e) => {
|
|
637
|
-
const pasted = Array.from(e.clipboardData?.files ?? []).filter((f) => f.type.startsWith("image/"));
|
|
638
|
-
if (pasted.length) {
|
|
639
|
-
e.preventDefault();
|
|
640
|
-
add(pasted);
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
placeholder: kind === "improvement" ? "Seria bom se\u2026" : "O que aconteceu?",
|
|
644
|
-
"aria-label": "Descri\xE7\xE3o da solicita\xE7\xE3o",
|
|
645
|
-
className: "min-h-[72px] resize-none text-sm"
|
|
646
|
-
}
|
|
647
|
-
),
|
|
648
|
-
files.length > 0 && /* @__PURE__ */ jsx("ul", { className: "flex flex-wrap gap-1.5 pt-2", children: files.map((f, i) => /* @__PURE__ */ jsxs("li", { className: "inline-flex max-w-full items-center gap-1 rounded-lg border border-border bg-muted/50 px-2 py-0.5 text-[11px] text-muted-foreground", children: [
|
|
649
|
-
/* @__PURE__ */ jsx(Paperclip, { className: "h-3 w-3 shrink-0" }),
|
|
650
|
-
/* @__PURE__ */ jsx("span", { className: "max-w-[12rem] truncate", children: f.name }),
|
|
651
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": `Tirar ${f.name}`, className: "rounded p-0.5 hover:bg-muted", onClick: () => setFiles((p) => p.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" }) })
|
|
652
|
-
] }, `${f.name}-${i}`)) }),
|
|
653
|
-
error && /* @__PURE__ */ jsx("p", { className: "pt-2 text-xs text-destructive", role: "alert", children: error }),
|
|
654
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 pt-2", children: [
|
|
655
|
-
/* @__PURE__ */ jsxs(Button, { type: "button", variant: "ghost", size: "sm", className: "h-8 gap-1.5 px-2 text-xs", disabled: busy, onClick: () => input.current?.click(), children: [
|
|
656
|
-
/* @__PURE__ */ jsx(ImagePlus, { className: "h-3.5 w-3.5" }),
|
|
657
|
-
" Anexar print"
|
|
658
|
-
] }),
|
|
659
|
-
/* @__PURE__ */ jsx(
|
|
660
|
-
"input",
|
|
661
|
-
{
|
|
662
|
-
ref: input,
|
|
663
|
-
type: "file",
|
|
664
|
-
multiple: true,
|
|
665
|
-
accept: "image/*,application/pdf",
|
|
666
|
-
className: "hidden",
|
|
667
|
-
tabIndex: -1,
|
|
668
|
-
onChange: (e) => {
|
|
669
|
-
add(Array.from(e.target.files ?? []));
|
|
670
|
-
e.target.value = "";
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
),
|
|
674
|
-
/* @__PURE__ */ jsx("span", { className: "flex-1" }),
|
|
675
|
-
/* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", className: "h-8 gap-1.5", disabled: busy || text.trim().length < 5, onClick: () => void submit(), "data-testid": "support-request-submit", children: [
|
|
676
|
-
/* @__PURE__ */ jsx(Send, { className: "h-3.5 w-3.5" }),
|
|
677
|
-
" ",
|
|
678
|
-
busy ? "Enviando\u2026" : "Enviar"
|
|
679
|
-
] })
|
|
680
|
-
] })
|
|
681
|
-
] });
|
|
682
|
-
}
|
|
683
|
-
function RequestResultCard({ props }) {
|
|
684
|
-
const number = Number(props.number);
|
|
685
|
-
const id = String(props.id ?? "");
|
|
686
|
-
const kind = props.kind ?? "problem";
|
|
687
|
-
const attachments = Number(props.attachments ?? 0);
|
|
688
|
-
return /* @__PURE__ */ jsxs("div", { className: cn(CARD, "flex items-start gap-2.5"), "data-testid": "support-request-result", children: [
|
|
689
|
-
/* @__PURE__ */ jsx(CheckCircle2, { className: "mt-0.5 h-5 w-5 shrink-0 text-success" }),
|
|
690
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
691
|
-
/* @__PURE__ */ jsxs("p", { className: "font-semibold text-foreground", children: [
|
|
692
|
-
"Solicita\xE7\xE3o #",
|
|
693
|
-
number,
|
|
694
|
-
" registrada"
|
|
695
|
-
] }),
|
|
696
|
-
/* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
697
|
-
KIND_LABEL[kind] ?? "Solicita\xE7\xE3o",
|
|
698
|
-
attachments ? ` \xB7 ${attachments} anexo${attachments > 1 ? "s" : ""}` : "",
|
|
699
|
-
" \xB7 a equipe acompanha e responde por aqui e por e-mail."
|
|
700
|
-
] }),
|
|
701
|
-
id && /* @__PURE__ */ jsx(
|
|
702
|
-
Button,
|
|
703
|
-
{
|
|
704
|
-
type: "button",
|
|
705
|
-
variant: "link",
|
|
706
|
-
size: "sm",
|
|
707
|
-
className: "h-auto px-0 pt-1 text-xs",
|
|
708
|
-
onClick: () => cardHost?.assistantLine(`Solicita\xE7\xE3o #${number}`, { widget: { type: "support.request-thread", props: { id } } }),
|
|
709
|
-
children: "Acompanhar aqui"
|
|
710
|
-
}
|
|
711
|
-
)
|
|
712
|
-
] })
|
|
713
|
-
] });
|
|
714
|
-
}
|
|
715
|
-
function toItem(r) {
|
|
716
|
-
return { id: r.id, number: r.number, kind: r.kind, subject: r.subject || r.description.slice(0, 80), status: r.status };
|
|
717
|
-
}
|
|
718
|
-
function RequestsListCard({ props }) {
|
|
719
|
-
const given = Array.isArray(props.items) ? props.items : null;
|
|
720
|
-
const [items, setItems] = React.useState(given);
|
|
721
|
-
const [error, setError] = React.useState(null);
|
|
722
|
-
React.useEffect(() => {
|
|
723
|
-
if (given) return;
|
|
724
|
-
let alive = true;
|
|
725
|
-
supportData().listRequests("mine", "all").then((rows) => {
|
|
726
|
-
if (alive) setItems(rows.map(toItem).slice(0, 8));
|
|
727
|
-
}).catch((e) => {
|
|
728
|
-
if (alive) setError(liveChatError(e));
|
|
729
|
-
});
|
|
730
|
-
return () => {
|
|
731
|
-
alive = false;
|
|
732
|
-
};
|
|
733
|
-
}, []);
|
|
734
|
-
if (error) return /* @__PURE__ */ jsx("div", { className: CARD, children: /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error }) });
|
|
735
|
-
if (!items) {
|
|
736
|
-
return /* @__PURE__ */ jsx("div", { className: cn(CARD, "space-y-2"), "data-testid": "support-requests-skeleton", children: [0, 1, 2].map((i) => /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full" }, i)) });
|
|
737
|
-
}
|
|
738
|
-
if (!items.length) {
|
|
739
|
-
return /* @__PURE__ */ jsx("div", { className: CARD, children: /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Voc\xEA ainda n\xE3o tem solicita\xE7\xF5es. Use as sugest\xF5es acima para abrir uma." }) });
|
|
740
|
-
}
|
|
741
|
-
return /* @__PURE__ */ jsx("ul", { className: cn(CARD, "divide-y divide-border p-0"), "data-testid": "support-requests-list", children: items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
742
|
-
"button",
|
|
743
|
-
{
|
|
744
|
-
type: "button",
|
|
745
|
-
className: "flex w-full items-start gap-2 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
746
|
-
onClick: () => {
|
|
747
|
-
if (item.kind === "chat" && isActiveChatStatus(item.status)) cardHost?.resumeChat(item.id, item.number);
|
|
748
|
-
else cardHost?.assistantLine(`Solicita\xE7\xE3o #${item.number}`, { widget: { type: "support.request-thread", props: { id: item.id } } });
|
|
749
|
-
},
|
|
750
|
-
children: [
|
|
751
|
-
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
752
|
-
/* @__PURE__ */ jsxs("span", { className: "block truncate text-sm text-foreground", children: [
|
|
753
|
-
"#",
|
|
754
|
-
item.number,
|
|
755
|
-
" \xB7 ",
|
|
756
|
-
item.subject
|
|
757
|
-
] }),
|
|
758
|
-
/* @__PURE__ */ jsx("span", { className: "block text-[11px] text-muted-foreground", children: KIND_LABEL[item.kind] ?? "" })
|
|
759
|
-
] }),
|
|
760
|
-
/* @__PURE__ */ jsx(Badge, { variant: STATUS_TONE[item.status], className: "shrink-0", children: STATUS_LABEL[item.status] })
|
|
761
|
-
]
|
|
762
|
-
}
|
|
763
|
-
) }, item.id)) });
|
|
764
|
-
}
|
|
765
|
-
function RequestThreadCard({ props }) {
|
|
766
|
-
const id = String(props.id ?? "");
|
|
767
|
-
const [detail, setDetail] = React.useState(void 0);
|
|
768
|
-
const [draft, setDraft] = React.useState("");
|
|
769
|
-
const [busy, setBusy] = React.useState(false);
|
|
770
|
-
const [error, setError] = React.useState(null);
|
|
771
|
-
const reload = React.useCallback(async () => {
|
|
772
|
-
try {
|
|
773
|
-
setDetail(await supportData().getRequestDetail(id));
|
|
774
|
-
setError(null);
|
|
775
|
-
} catch (e) {
|
|
776
|
-
setError(liveChatError(e));
|
|
777
|
-
}
|
|
778
|
-
}, [id]);
|
|
779
|
-
React.useEffect(() => {
|
|
780
|
-
void reload();
|
|
781
|
-
const t = setInterval(() => {
|
|
782
|
-
void reload();
|
|
783
|
-
}, supportData().pollMs?.detail ?? 15e3);
|
|
784
|
-
return () => clearInterval(t);
|
|
785
|
-
}, [reload]);
|
|
786
|
-
if (detail === void 0) {
|
|
787
|
-
return /* @__PURE__ */ jsxs("div", { className: cn(CARD, "space-y-2"), children: [
|
|
788
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-40" }),
|
|
789
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-14 w-full" }),
|
|
790
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-9 w-full" })
|
|
791
|
-
] });
|
|
792
|
-
}
|
|
793
|
-
if (!detail) return /* @__PURE__ */ jsx("div", { className: CARD, children: /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: error ?? "Solicita\xE7\xE3o n\xE3o encontrada." }) });
|
|
794
|
-
async function reply() {
|
|
795
|
-
const body = draft.trim();
|
|
796
|
-
if (!body) return;
|
|
797
|
-
setBusy(true);
|
|
798
|
-
try {
|
|
799
|
-
await supportData().addMessage(id, body);
|
|
800
|
-
setDraft("");
|
|
801
|
-
await reload();
|
|
802
|
-
} catch (e) {
|
|
803
|
-
setError(liveChatError(e));
|
|
804
|
-
} finally {
|
|
805
|
-
setBusy(false);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
async function validate(ok) {
|
|
809
|
-
setBusy(true);
|
|
810
|
-
try {
|
|
811
|
-
await supportData().validateRequest(id, ok, ok ? void 0 : "Ainda n\xE3o resolveu (assistente)");
|
|
812
|
-
await reload();
|
|
813
|
-
} catch (e) {
|
|
814
|
-
setError(liveChatError(e));
|
|
815
|
-
} finally {
|
|
816
|
-
setBusy(false);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return /* @__PURE__ */ jsxs("div", { className: CARD, "data-testid": "support-request-thread", children: [
|
|
820
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
821
|
-
/* @__PURE__ */ jsxs("p", { className: "min-w-0 flex-1 truncate font-semibold text-foreground", children: [
|
|
822
|
-
"#",
|
|
823
|
-
detail.number,
|
|
824
|
-
" \xB7 ",
|
|
825
|
-
detail.subject || detail.description.slice(0, 60)
|
|
826
|
-
] }),
|
|
827
|
-
/* @__PURE__ */ jsx(Badge, { variant: STATUS_TONE[detail.status], className: "shrink-0", children: STATUS_LABEL[detail.status] })
|
|
828
|
-
] }),
|
|
829
|
-
/* @__PURE__ */ jsx("p", { className: "pt-1 text-xs text-muted-foreground line-clamp-3", children: detail.description }),
|
|
830
|
-
detail.messages.length > 0 && /* @__PURE__ */ jsx("ul", { className: "mt-2 space-y-1.5 border-t border-border pt-2", children: detail.messages.slice(-6).map((m) => /* @__PURE__ */ jsxs("li", { className: cn("rounded-lg px-2.5 py-1.5 text-xs", m.authorKind === "team" ? "bg-muted text-foreground" : "bg-foreground/5 text-foreground"), children: [
|
|
831
|
-
/* @__PURE__ */ jsx("span", { className: "block text-[10px] text-muted-foreground", children: m.authorKind === "team" ? "Equipe de suporte" : "Voc\xEA" }),
|
|
832
|
-
/* @__PURE__ */ jsx("span", { className: "whitespace-pre-wrap", children: m.body })
|
|
833
|
-
] }, m.id)) }),
|
|
834
|
-
error && /* @__PURE__ */ jsx("p", { className: "pt-2 text-xs text-destructive", role: "alert", children: error }),
|
|
835
|
-
canValidate(detail.status) ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5 pt-2", children: [
|
|
836
|
-
/* @__PURE__ */ jsx("span", { className: "w-full text-xs text-foreground", children: "A equipe marcou como resolvida. Ficou bom?" }),
|
|
837
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", className: "h-7 text-xs", disabled: busy, onClick: () => void validate(true), children: "Ficou bom" }),
|
|
838
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", className: "h-7 text-xs", disabled: busy, onClick: () => void validate(false), children: "Ainda n\xE3o resolveu" })
|
|
839
|
-
] }) : canMessage(detail.status) ? /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-1.5 pt-2", children: [
|
|
840
|
-
/* @__PURE__ */ jsx(
|
|
841
|
-
Textarea,
|
|
842
|
-
{
|
|
843
|
-
rows: 1,
|
|
844
|
-
value: draft,
|
|
845
|
-
disabled: busy,
|
|
846
|
-
onChange: (e) => setDraft(e.target.value),
|
|
847
|
-
onKeyDown: (e) => {
|
|
848
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
849
|
-
e.preventDefault();
|
|
850
|
-
void reply();
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
placeholder: "Responder \xE0 equipe\u2026",
|
|
854
|
-
"aria-label": `Responder \xE0 solicita\xE7\xE3o #${detail.number}`,
|
|
855
|
-
className: "min-h-[36px] flex-1 resize-none text-xs"
|
|
856
|
-
}
|
|
857
|
-
),
|
|
858
|
-
/* @__PURE__ */ jsx(Button, { size: "icon", className: "h-9 w-9", disabled: busy || !draft.trim(), onClick: () => void reply(), "aria-label": "Enviar resposta", children: /* @__PURE__ */ jsx(Send, { className: "h-3.5 w-3.5" }) })
|
|
859
|
-
] }) : /* @__PURE__ */ jsx("p", { className: "pt-2 text-[11px] text-muted-foreground", children: "Solicita\xE7\xE3o encerrada." })
|
|
860
|
-
] });
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// src/livechat/in-chat-install.tsx
|
|
864
|
-
var surface = {
|
|
865
|
-
publish: (session) => publishChatHandoff(session),
|
|
866
|
-
systemLine: (text) => {
|
|
867
|
-
postSystemLine(text);
|
|
868
|
-
},
|
|
869
|
-
assistantLine: (content, options) => postAssistantLine(content, options),
|
|
870
|
-
userLine: (text) => {
|
|
871
|
-
postUserLine(text);
|
|
872
|
-
},
|
|
873
|
-
upsert: (message) => useChatStore.getState().upsertMessage(message),
|
|
874
|
-
has: (id) => useChatStore.getState().messages.some((m) => m.id === id),
|
|
875
|
-
focusComposer: () => useChatStore.getState().requestComposerFocus(),
|
|
876
|
-
openAssistant: () => openAssistant(),
|
|
877
|
-
showSuggestions: () => useChatStore.getState().setSuggestionsOpen(true)
|
|
878
|
-
};
|
|
879
|
-
var controller = null;
|
|
880
|
-
function getInChatController() {
|
|
881
|
-
controller ?? (controller = new InChatController({
|
|
882
|
-
surface,
|
|
883
|
-
provider: supportData,
|
|
884
|
-
realtime: {
|
|
885
|
-
listen: (conversationId, onEvent) => listenTopic(conversationTopic(conversationId), (e) => onEvent(e)),
|
|
886
|
-
observeOnline: (homeId, onCount) => observeAgentsOnline(homeId, onCount)
|
|
887
|
-
}
|
|
888
|
-
}));
|
|
889
|
-
return controller;
|
|
890
|
-
}
|
|
891
|
-
var KIND_OF = {
|
|
892
|
-
"support.report.problem": "problem",
|
|
893
|
-
"support.report.improvement": "improvement",
|
|
894
|
-
"support.report.other": "other"
|
|
895
|
-
};
|
|
896
|
-
var installs = 0;
|
|
897
|
-
var teardown = null;
|
|
898
|
-
function installSupportInChat() {
|
|
899
|
-
installs += 1;
|
|
900
|
-
if (installs === 1) teardown = doInstall();
|
|
901
|
-
let done = false;
|
|
902
|
-
return () => {
|
|
903
|
-
if (done) return;
|
|
904
|
-
done = true;
|
|
905
|
-
installs -= 1;
|
|
906
|
-
if (installs === 0) {
|
|
907
|
-
teardown?.();
|
|
908
|
-
teardown = null;
|
|
909
|
-
}
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
function doInstall() {
|
|
913
|
-
const c = getInChatController();
|
|
914
|
-
const offs = [];
|
|
915
|
-
setInChatCardHost({
|
|
916
|
-
patchMessage: (id, patch) => useChatStore.getState().patchMessage(id, patch),
|
|
917
|
-
assistantLine: (content, options) => postAssistantLine(content, options),
|
|
918
|
-
resumeChat: (id, number) => {
|
|
919
|
-
void c.resume(id, number);
|
|
920
|
-
},
|
|
921
|
-
showSuggestions: () => useChatStore.getState().setSuggestionsOpen(true)
|
|
922
|
-
});
|
|
923
|
-
setSupportToolBridge({
|
|
924
|
-
takeTurnFiles: () => takeTurnReportFiles(),
|
|
925
|
-
startLiveChat: () => c.start(toStart(currentChatContext())),
|
|
926
|
-
resumeChat: (id, number) => {
|
|
927
|
-
void c.resume(id, number);
|
|
928
|
-
}
|
|
929
|
-
});
|
|
930
|
-
setLiveChatOpener(({ id, number }) => {
|
|
931
|
-
if (id) void c.resume(id, number ?? 0);
|
|
932
|
-
else void c.start(toStart(currentChatContext()));
|
|
933
|
-
});
|
|
934
|
-
offs.push(() => setLiveChatOpener(null));
|
|
935
|
-
offs.push(registerChatWidget(REQUEST_FORM_WIDGET, RequestFormCard));
|
|
936
|
-
offs.push(registerChatWidget(REQUEST_RESULT_WIDGET, RequestResultCard));
|
|
937
|
-
offs.push(registerChatWidget(REQUESTS_LIST_WIDGET, RequestsListCard));
|
|
938
|
-
offs.push(registerChatWidget(REQUEST_THREAD_WIDGET, RequestThreadCard));
|
|
939
|
-
offs.push(registerChatAction("support.question", (ctx) => {
|
|
940
|
-
postUserLine(ctx.label || "Tenho uma d\xFAvida");
|
|
941
|
-
postAssistantLine("Pode perguntar: escreva a sua d\xFAvida aqui embaixo que eu respondo.");
|
|
942
|
-
useChatStore.getState().requestComposerFocus();
|
|
943
|
-
}));
|
|
944
|
-
offs.push(registerChatAction("support.live-chat", (ctx) => {
|
|
945
|
-
postUserLine(ctx.label || "Falar com um atendente");
|
|
946
|
-
void c.start(toStart(ctx));
|
|
947
|
-
}));
|
|
948
|
-
for (const [action, kind] of Object.entries(KIND_OF)) {
|
|
949
|
-
offs.push(registerChatAction(action, (ctx) => {
|
|
950
|
-
openRequestForm(surface, kind, { echo: ctx.label, transcript: ctx.transcript });
|
|
951
|
-
}));
|
|
952
|
-
}
|
|
953
|
-
offs.push(registerChatAction("support.my-requests", (ctx) => {
|
|
954
|
-
postUserLine(ctx.label || "Minhas solicita\xE7\xF5es");
|
|
955
|
-
postAssistantLine("Estas s\xE3o as suas solicita\xE7\xF5es. Toque numa para ver a conversa.", { widget: { type: REQUESTS_LIST_WIDGET } });
|
|
956
|
-
}));
|
|
957
|
-
for (const [name, run] of Object.entries(supportToolHandlers)) {
|
|
958
|
-
registerAIToolHandler(name, (args) => run(args));
|
|
959
|
-
offs.push(() => unregisterAIToolHandler(name));
|
|
960
|
-
}
|
|
961
|
-
offs.push(useChatStore.subscribe((s, prev) => {
|
|
962
|
-
if (s.isOpen && !prev.isOpen) void c.checkResume(true);
|
|
963
|
-
}));
|
|
964
|
-
return () => {
|
|
965
|
-
for (const off of offs.reverse()) off();
|
|
966
|
-
offHandler?.();
|
|
967
|
-
offHandler = null;
|
|
968
|
-
setInChatCardHost(null);
|
|
969
|
-
setSupportToolBridge(null);
|
|
970
|
-
c.dispose();
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
function toStart(ctx) {
|
|
974
|
-
return { transcript: ctx.transcript, conversationId: ctx.conversationId, route: ctx.route };
|
|
975
|
-
}
|
|
976
|
-
var offHandler = null;
|
|
977
|
-
async function refreshSupportHandler() {
|
|
978
|
-
let enabled = false;
|
|
979
|
-
try {
|
|
980
|
-
const a = await supportData().chatAvailability();
|
|
981
|
-
enabled = !!a?.enabled;
|
|
982
|
-
} catch {
|
|
983
|
-
enabled = false;
|
|
984
|
-
}
|
|
985
|
-
if (enabled && !offHandler) {
|
|
986
|
-
const c = getInChatController();
|
|
987
|
-
offHandler = registerChatSupportHandler((ctx) => {
|
|
988
|
-
void c.start(toStart(ctx));
|
|
989
|
-
});
|
|
990
|
-
} else if (!enabled && offHandler) {
|
|
991
|
-
offHandler();
|
|
992
|
-
offHandler = null;
|
|
993
|
-
}
|
|
994
|
-
return enabled;
|
|
995
|
-
}
|
|
996
|
-
function supportInChatActive() {
|
|
997
|
-
return getChatHandoff() !== null;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
export { INITIAL_IN_CHAT, getInChatController, installSupportInChat, refreshSupportHandler, statusLine, stepInChat, supportInChatActive };
|
|
1001
|
-
//# sourceMappingURL=chunk-CB3B4FFU.js.map
|
|
1002
|
-
//# sourceMappingURL=chunk-CB3B4FFU.js.map
|