@fayz-ai/plugin-support 0.3.0-canary.20261028142749 → 0.3.0
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-QY534ASZ.js → HelpdeskConsole-EATEBVLN.js} +10 -7
- package/dist/HelpdeskConsole-EATEBVLN.js.map +1 -0
- package/dist/{LiveChatAgentWatcher-J6PNLYWT.js → LiveChatAgentWatcher-WEUHRRLC.js} +17 -23
- package/dist/LiveChatAgentWatcher-WEUHRRLC.js.map +1 -0
- 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-JBBBJTKU.js → SupportCenter-HGQL4PBX.js} +12 -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-3WPESEK2.js +136 -0
- package/dist/chunk-3WPESEK2.js.map +1 -0
- package/dist/chunk-5MGCM5C4.js +181 -0
- package/dist/chunk-5MGCM5C4.js.map +1 -0
- package/dist/{chunk-PIMV3VRT.js → chunk-DTO5R6GN.js} +26 -126
- package/dist/chunk-DTO5R6GN.js.map +1 -0
- package/dist/chunk-E5242OSS.js +88 -0
- package/dist/chunk-E5242OSS.js.map +1 -0
- package/dist/{chunk-M4LUNCKI.js → chunk-E5EXC7QW.js} +57 -16
- package/dist/chunk-E5EXC7QW.js.map +1 -0
- package/dist/chunk-JOS2QQML.js +17 -0
- package/dist/chunk-JOS2QQML.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-37ZZRVI7.js → chunk-P4VNMWIT.js} +79 -186
- 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-MQXGB4IO.js → chunk-S766CRAY.js} +42 -239
- package/dist/chunk-S766CRAY.js.map +1 -0
- package/dist/chunk-WHEJ63CM.js +156 -0
- package/dist/chunk-WHEJ63CM.js.map +1 -0
- package/dist/chunk-Y673XGDK.js +261 -0
- 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 +12 -0
- package/dist/data/provider.d.ts.map +1 -1
- package/dist/host.d.ts +21 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +24 -10
- package/dist/host.js.map +1 -1
- package/dist/in-chat-install-2BTKBF2Z.js +11 -0
- package/dist/in-chat-install-2BTKBF2Z.js.map +1 -0
- package/dist/index.js +18 -191
- package/dist/index.js.map +1 -1
- package/dist/lib/imported.d.ts +27 -0
- package/dist/lib/imported.d.ts.map +1 -0
- package/dist/lib/report-tool.d.ts +54 -9
- package/dist/lib/report-tool.d.ts.map +1 -1
- package/dist/lib/vocabulary.d.ts.map +1 -1
- package/dist/livechat/LiveChatAgentWatcher.d.ts +3 -2
- package/dist/livechat/LiveChatAgentWatcher.d.ts.map +1 -1
- package/dist/livechat/in-chat-install.d.ts +19 -0
- package/dist/livechat/in-chat-install.d.ts.map +1 -0
- package/dist/livechat/in-chat-link.d.ts +10 -0
- package/dist/livechat/in-chat-link.d.ts.map +1 -0
- package/dist/livechat/in-chat-machine.d.ts +99 -0
- package/dist/livechat/in-chat-machine.d.ts.map +1 -0
- 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 +39 -0
- package/dist/livechat/in-chat-widgets.d.ts.map +1 -0
- package/dist/livechat/in-chat.d.ts +119 -0
- package/dist/livechat/in-chat.d.ts.map +1 -0
- 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/realtime-HQVWBTML.js +3 -0
- package/dist/realtime-HQVWBTML.js.map +1 -0
- 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/SupportRequestsPanel.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-QY534ASZ.js.map +0 -1
- package/dist/LiveChatAgentWatcher-J6PNLYWT.js.map +0 -1
- package/dist/SupportCenter-JBBBJTKU.js.map +0 -1
- package/dist/chunk-37ZZRVI7.js.map +0 -1
- package/dist/chunk-CWCN5PDE.js.map +0 -1
- package/dist/chunk-JT4ZPWH7.js +0 -61
- package/dist/chunk-JT4ZPWH7.js.map +0 -1
- package/dist/chunk-M4LUNCKI.js.map +0 -1
- package/dist/chunk-MQXGB4IO.js.map +0 -1
- package/dist/chunk-PIMV3VRT.js.map +0 -1
- package/dist/chunk-STEDUFNR.js +0 -42
- package/dist/chunk-STEDUFNR.js.map +0 -1
- package/dist/chunk-WOZTA5LS.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { consoleDetail } from './chunk-
|
|
2
|
-
import { FILTER_STATUSES, TEAM_ONLY_EVENTS, deriveSubject } from './chunk-
|
|
1
|
+
import { consoleDetail } from './chunk-PHIPTZSD.js';
|
|
2
|
+
import { FILTER_STATUSES, TEAM_ONLY_EVENTS, deriveSubject } from './chunk-L2HGTGW4.js';
|
|
3
3
|
import { getActiveUnitId, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
|
|
4
|
-
import React from 'react';
|
|
5
4
|
|
|
6
5
|
// src/types.ts
|
|
7
6
|
var MAX_ATTACHMENTS = 8;
|
|
@@ -35,10 +34,10 @@ async function chatAvailability() {
|
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
38
|
-
function originFields(originConversationId,
|
|
37
|
+
function originFields(originConversationId, snapshot = {}) {
|
|
39
38
|
const id = originConversationId?.trim() || null;
|
|
40
|
-
if (!id) return { origin: null, snapshot
|
|
41
|
-
return UUID_RE.test(id) ? { origin: id, snapshot
|
|
39
|
+
if (!id) return { origin: null, snapshot };
|
|
40
|
+
return UUID_RE.test(id) ? { origin: id, snapshot } : { origin: null, snapshot: { ...snapshot, assistant_conversation_id: id } };
|
|
42
41
|
}
|
|
43
42
|
async function openChat(input = {}) {
|
|
44
43
|
const o = originFields(input.originConversationId, input.screenSnapshot ?? {});
|
|
@@ -141,135 +140,6 @@ function wakeV1Bridge(delayMs = 400) {
|
|
|
141
140
|
}
|
|
142
141
|
}, delayMs);
|
|
143
142
|
}
|
|
144
|
-
var REGISTRY = /* @__PURE__ */ Symbol.for("fayz.conversa-ao-vivo");
|
|
145
|
-
var EVENTS = ["message", "changed", "typing", "chat"];
|
|
146
|
-
function registry() {
|
|
147
|
-
const g = globalThis;
|
|
148
|
-
return g[REGISTRY] ?? (g[REGISTRY] = /* @__PURE__ */ new Map());
|
|
149
|
-
}
|
|
150
|
-
function client2() {
|
|
151
|
-
return getSupabaseClientOptional();
|
|
152
|
-
}
|
|
153
|
-
function listenTopic(topic, listener) {
|
|
154
|
-
const supabase = client2();
|
|
155
|
-
if (!supabase?.channel || !topic) return () => {
|
|
156
|
-
};
|
|
157
|
-
const reg = registry();
|
|
158
|
-
let entry = reg.get(topic);
|
|
159
|
-
if (!entry) {
|
|
160
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
161
|
-
let channel = supabase.channel(topic, { config: { broadcast: { self: false } } });
|
|
162
|
-
for (const ev of EVENTS) {
|
|
163
|
-
channel = channel.on("broadcast", { event: ev }, (msg) => {
|
|
164
|
-
const e = { event: ev, payload: msg?.payload ?? {} };
|
|
165
|
-
for (const f of [...listeners]) {
|
|
166
|
-
try {
|
|
167
|
-
f(e);
|
|
168
|
-
} catch {
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
channel.subscribe();
|
|
174
|
-
entry = { channel, listeners };
|
|
175
|
-
reg.set(topic, entry);
|
|
176
|
-
}
|
|
177
|
-
entry.listeners.add(listener);
|
|
178
|
-
return () => {
|
|
179
|
-
const e = reg.get(topic);
|
|
180
|
-
if (!e) return;
|
|
181
|
-
e.listeners.delete(listener);
|
|
182
|
-
if (e.listeners.size === 0) {
|
|
183
|
-
reg.delete(topic);
|
|
184
|
-
void client2()?.removeChannel?.(e.channel);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
var conversationTopic = (conversationId) => `conversa:${conversationId}`;
|
|
189
|
-
var queueTopic = (centralId) => `suporte:fila:${centralId}`;
|
|
190
|
-
var presenceTopic = (centralId) => `suporte:presenca:${centralId}`;
|
|
191
|
-
function sendTyping(conversationId, from) {
|
|
192
|
-
const e = registry().get(conversationTopic(conversationId));
|
|
193
|
-
if (!e) return;
|
|
194
|
-
try {
|
|
195
|
-
void e.channel.send({ type: "broadcast", event: "typing", payload: { from } });
|
|
196
|
-
} catch {
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
var PRESENCE = /* @__PURE__ */ Symbol.for("fayz.suporte-presenca");
|
|
200
|
-
function presences() {
|
|
201
|
-
const g = globalThis;
|
|
202
|
-
return g[PRESENCE] ?? (g[PRESENCE] = /* @__PURE__ */ new Map());
|
|
203
|
-
}
|
|
204
|
-
function countOnline(state) {
|
|
205
|
-
return Object.values(state ?? {}).filter((metas) => (metas ?? []).some((m) => m?.agent === true && (m.status ?? "online") === "online")).length;
|
|
206
|
-
}
|
|
207
|
-
function presenceEntry(centralId, key) {
|
|
208
|
-
const supabase = client2();
|
|
209
|
-
if (!supabase?.channel || !centralId) return null;
|
|
210
|
-
const map = presences();
|
|
211
|
-
let entry = map.get(centralId);
|
|
212
|
-
if (!entry) {
|
|
213
|
-
const created = { channel: null, observers: /* @__PURE__ */ new Set(), mine: null, subscribed: false, trackers: 0 };
|
|
214
|
-
const channel = supabase.channel(presenceTopic(centralId), { config: { presence: { key } } });
|
|
215
|
-
channel.on("presence", { event: "sync" }, () => {
|
|
216
|
-
const n = countOnline(channel.presenceState?.() ?? {});
|
|
217
|
-
for (const f of [...created.observers]) {
|
|
218
|
-
try {
|
|
219
|
-
f(n);
|
|
220
|
-
} catch {
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
channel.subscribe((status) => {
|
|
225
|
-
if (status !== "SUBSCRIBED") return;
|
|
226
|
-
created.subscribed = true;
|
|
227
|
-
if (created.mine) void channel.track({ agent: true, status: created.mine });
|
|
228
|
-
});
|
|
229
|
-
created.channel = channel;
|
|
230
|
-
entry = created;
|
|
231
|
-
map.set(centralId, entry);
|
|
232
|
-
}
|
|
233
|
-
return entry;
|
|
234
|
-
}
|
|
235
|
-
function release(centralId) {
|
|
236
|
-
const map = presences();
|
|
237
|
-
const e = map.get(centralId);
|
|
238
|
-
if (!e || e.observers.size > 0 || e.trackers > 0) return;
|
|
239
|
-
map.delete(centralId);
|
|
240
|
-
void client2()?.removeChannel?.(e.channel);
|
|
241
|
-
}
|
|
242
|
-
function observeAgentsOnline(centralId, onCount) {
|
|
243
|
-
const key = `obs-${Math.random().toString(36).slice(2)}`;
|
|
244
|
-
const e = presenceEntry(centralId, key);
|
|
245
|
-
if (!e) return () => {
|
|
246
|
-
};
|
|
247
|
-
e.observers.add(onCount);
|
|
248
|
-
if (e.subscribed) onCount(countOnline(e.channel.presenceState?.() ?? {}));
|
|
249
|
-
return () => {
|
|
250
|
-
e.observers.delete(onCount);
|
|
251
|
-
release(centralId);
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
function announceAgent(centralId, userId2, status) {
|
|
255
|
-
const e = presenceEntry(centralId, userId2);
|
|
256
|
-
if (!e) return () => {
|
|
257
|
-
};
|
|
258
|
-
e.trackers += 1;
|
|
259
|
-
e.mine = status;
|
|
260
|
-
if (e.subscribed) void e.channel.track({ agent: true, status });
|
|
261
|
-
return () => {
|
|
262
|
-
e.trackers -= 1;
|
|
263
|
-
if (e.trackers <= 0) {
|
|
264
|
-
e.mine = null;
|
|
265
|
-
try {
|
|
266
|
-
void e.channel.untrack();
|
|
267
|
-
} catch {
|
|
268
|
-
}
|
|
269
|
-
release(centralId);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
143
|
|
|
274
144
|
// src/livechat/rules.ts
|
|
275
145
|
var PRESENCE_WAIT_MS = 4e3;
|
|
@@ -314,87 +184,7 @@ function chatSubject(messages) {
|
|
|
314
184
|
const short = first.replace(/\s+/g, " ");
|
|
315
185
|
return `Conversa: ${short.length > 80 ? short.slice(0, 80).trimEnd() + "\u2026" : short}`;
|
|
316
186
|
}
|
|
317
|
-
|
|
318
|
-
var subscribers = /* @__PURE__ */ new Set();
|
|
319
|
-
function read() {
|
|
320
|
-
try {
|
|
321
|
-
return localStorage.getItem(KEY) !== "0";
|
|
322
|
-
} catch {
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
function setAgentAvailable(on) {
|
|
327
|
-
try {
|
|
328
|
-
localStorage.setItem(KEY, on ? "1" : "0");
|
|
329
|
-
} catch {
|
|
330
|
-
}
|
|
331
|
-
memo = on;
|
|
332
|
-
for (const f of [...subscribers]) f();
|
|
333
|
-
}
|
|
334
|
-
var memo = null;
|
|
335
|
-
function snapshot() {
|
|
336
|
-
return memo ?? (memo = read());
|
|
337
|
-
}
|
|
338
|
-
function useAgentAvailable() {
|
|
339
|
-
const value = React.useSyncExternalStore(
|
|
340
|
-
(cb) => {
|
|
341
|
-
subscribers.add(cb);
|
|
342
|
-
return () => {
|
|
343
|
-
subscribers.delete(cb);
|
|
344
|
-
};
|
|
345
|
-
},
|
|
346
|
-
snapshot,
|
|
347
|
-
() => true
|
|
348
|
-
);
|
|
349
|
-
return [value, setAgentAvailable];
|
|
350
|
-
}
|
|
351
|
-
function useAgentsOnline(centralId) {
|
|
352
|
-
const [n, setN] = React.useState(null);
|
|
353
|
-
React.useEffect(() => {
|
|
354
|
-
setN(null);
|
|
355
|
-
if (!centralId) return;
|
|
356
|
-
return observeAgentsOnline(centralId, setN);
|
|
357
|
-
}, [centralId]);
|
|
358
|
-
return n;
|
|
359
|
-
}
|
|
360
|
-
function useConversationBell(conversationId, onEvent) {
|
|
361
|
-
const ref = React.useRef(onEvent);
|
|
362
|
-
ref.current = onEvent;
|
|
363
|
-
React.useEffect(() => {
|
|
364
|
-
if (!conversationId) return;
|
|
365
|
-
return listenTopic(conversationTopic(conversationId), (e) => ref.current(e));
|
|
366
|
-
}, [conversationId]);
|
|
367
|
-
}
|
|
368
|
-
function useTyping(conversationId, me) {
|
|
369
|
-
const [otherTyping, setOtherTyping] = React.useState(false);
|
|
370
|
-
const last = React.useRef(0);
|
|
371
|
-
const timer = React.useRef(null);
|
|
372
|
-
useConversationBell(conversationId, (e) => {
|
|
373
|
-
if (e.event === "typing") {
|
|
374
|
-
if (e.payload.from === me) return;
|
|
375
|
-
setOtherTyping(true);
|
|
376
|
-
if (timer.current) clearTimeout(timer.current);
|
|
377
|
-
timer.current = setTimeout(() => setOtherTyping(false), TYPING_SHOW_MS);
|
|
378
|
-
} else if (e.event === "message" && e.payload.direction === (me === "customer" ? "outbound" : "inbound")) {
|
|
379
|
-
setOtherTyping(false);
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
React.useEffect(() => () => {
|
|
383
|
-
if (timer.current) clearTimeout(timer.current);
|
|
384
|
-
}, []);
|
|
385
|
-
React.useEffect(() => {
|
|
386
|
-
setOtherTyping(false);
|
|
387
|
-
}, [conversationId]);
|
|
388
|
-
const notifyTyping = React.useCallback(() => {
|
|
389
|
-
if (!conversationId) return;
|
|
390
|
-
const now = Date.now();
|
|
391
|
-
if (now - last.current < TYPING_EVERY_MS) return;
|
|
392
|
-
last.current = now;
|
|
393
|
-
sendTyping(conversationId, me);
|
|
394
|
-
}, [conversationId, me]);
|
|
395
|
-
return { otherTyping, notifyTyping };
|
|
396
|
-
}
|
|
397
|
-
function client3() {
|
|
187
|
+
function client2() {
|
|
398
188
|
const c = getSupabaseClientOptional();
|
|
399
189
|
if (!c) throw new Error("Supabase client not available");
|
|
400
190
|
return c;
|
|
@@ -402,7 +192,7 @@ function client3() {
|
|
|
402
192
|
var cachedUserId = null;
|
|
403
193
|
async function userId() {
|
|
404
194
|
if (cachedUserId) return cachedUserId;
|
|
405
|
-
const { data } = await
|
|
195
|
+
const { data } = await client2().auth.getUser();
|
|
406
196
|
cachedUserId = data?.user?.id ?? null;
|
|
407
197
|
return cachedUserId;
|
|
408
198
|
}
|
|
@@ -465,16 +255,16 @@ var toThreadMessage = (requestId) => (r) => ({
|
|
|
465
255
|
legacy: r.legacy === true
|
|
466
256
|
});
|
|
467
257
|
async function threadMessages(requestId) {
|
|
468
|
-
const { data, error } = await
|
|
258
|
+
const { data, error } = await client2().rpc("support_request_thread", { p_request_id: requestId });
|
|
469
259
|
if (error) {
|
|
470
260
|
if (!missingRpc(error)) throw error;
|
|
471
|
-
const legacy = await
|
|
261
|
+
const legacy = await client2().from("plg_support_request_messages").select("*").eq("request_id", requestId).order("created_at", { ascending: true });
|
|
472
262
|
return (legacy.data ?? []).map(toMessage);
|
|
473
263
|
}
|
|
474
264
|
return (data?.messages ?? []).map(toThreadMessage(requestId));
|
|
475
265
|
}
|
|
476
266
|
async function listRequests(scope, filter) {
|
|
477
|
-
let q =
|
|
267
|
+
let q = client2().from("plg_support_requests").select("*").order("number", { ascending: false });
|
|
478
268
|
if (scope === "mine") {
|
|
479
269
|
const uid = await userId();
|
|
480
270
|
if (uid) q = q.eq("created_by", uid);
|
|
@@ -488,13 +278,13 @@ async function listRequests(scope, filter) {
|
|
|
488
278
|
return (data ?? []).map(toRequest);
|
|
489
279
|
}
|
|
490
280
|
async function getRequestDetail(id) {
|
|
491
|
-
const { data: req, error } = await
|
|
281
|
+
const { data: req, error } = await client2().from("plg_support_requests").select("*").eq("id", id).maybeSingle();
|
|
492
282
|
if (error) throw error;
|
|
493
283
|
if (!req) return null;
|
|
494
284
|
const [messages, events, attachments] = await Promise.all([
|
|
495
285
|
threadMessages(id),
|
|
496
|
-
|
|
497
|
-
|
|
286
|
+
client2().from("plg_support_request_events").select("*").eq("request_id", id).order("created_at", { ascending: true }),
|
|
287
|
+
client2().from("plg_support_request_attachments").select("*").eq("request_id", id).order("created_at", { ascending: true })
|
|
498
288
|
]);
|
|
499
289
|
return {
|
|
500
290
|
...toRequest(req),
|
|
@@ -508,7 +298,7 @@ async function getRequestDetail(id) {
|
|
|
508
298
|
async function unreadCount() {
|
|
509
299
|
const uid = await userId();
|
|
510
300
|
if (!uid) return 0;
|
|
511
|
-
const { count, error } = await
|
|
301
|
+
const { count, error } = await client2().from("plg_support_notifications").select("id", { count: "exact", head: true }).eq("user_id", uid).is("read_at", null);
|
|
512
302
|
if (error) return 0;
|
|
513
303
|
return count ?? 0;
|
|
514
304
|
}
|
|
@@ -528,9 +318,9 @@ async function createRequest(input) {
|
|
|
528
318
|
area: input.area ?? null,
|
|
529
319
|
status: "received"
|
|
530
320
|
};
|
|
531
|
-
const { data, error } = await
|
|
321
|
+
const { data, error } = await client2().from("plg_support_requests").insert(row).select("id, number").single();
|
|
532
322
|
if (error) throw error;
|
|
533
|
-
await
|
|
323
|
+
await client2().from("plg_support_request_events").insert({
|
|
534
324
|
tenant_id: tenantId,
|
|
535
325
|
request_id: data.id,
|
|
536
326
|
type: "opened",
|
|
@@ -543,12 +333,12 @@ async function uploadAttachment(requestId, pending) {
|
|
|
543
333
|
if (!tenantId) throw new Error("Sem conta ativa");
|
|
544
334
|
const safeName = pending.name.replace(/[^\w.\-]+/g, "_");
|
|
545
335
|
const path = `${tenantId}/${requestId}/${crypto.randomUUID()}/${safeName}`;
|
|
546
|
-
const up = await
|
|
336
|
+
const up = await client2().storage.from(SUPPORT_BUCKET).upload(path, pending.file, {
|
|
547
337
|
contentType: pending.contentType,
|
|
548
338
|
upsert: false
|
|
549
339
|
});
|
|
550
340
|
if (up.error) throw up.error;
|
|
551
|
-
const { data, error } = await
|
|
341
|
+
const { data, error } = await client2().from("plg_support_request_attachments").insert({
|
|
552
342
|
tenant_id: tenantId,
|
|
553
343
|
request_id: requestId,
|
|
554
344
|
storage_path: path,
|
|
@@ -562,10 +352,10 @@ async function uploadAttachment(requestId, pending) {
|
|
|
562
352
|
async function addMessage(requestId, body) {
|
|
563
353
|
const tenantId = getActiveTenantId();
|
|
564
354
|
if (!tenantId) throw new Error("Sem conta ativa");
|
|
565
|
-
const sent = await
|
|
355
|
+
const sent = await client2().rpc("support_request_send", { p_request_id: requestId, p_body: body.trim() });
|
|
566
356
|
if (!sent.error) return;
|
|
567
357
|
if (!missingRpc(sent.error)) throw sent.error;
|
|
568
|
-
const { error } = await
|
|
358
|
+
const { error } = await client2().from("plg_support_request_messages").insert({
|
|
569
359
|
tenant_id: tenantId,
|
|
570
360
|
request_id: requestId,
|
|
571
361
|
author_kind: "user",
|
|
@@ -576,22 +366,35 @@ async function addMessage(requestId, body) {
|
|
|
576
366
|
async function cancelRequest(requestId) {
|
|
577
367
|
const tenantId = getActiveTenantId();
|
|
578
368
|
if (!tenantId) throw new Error("Sem conta ativa");
|
|
579
|
-
const { error } = await
|
|
369
|
+
const { error } = await client2().from("plg_support_requests").update({ status: "cancelled" }).eq("id", requestId);
|
|
580
370
|
if (error) throw error;
|
|
581
|
-
await
|
|
371
|
+
await client2().from("plg_support_request_events").insert({
|
|
582
372
|
tenant_id: tenantId,
|
|
583
373
|
request_id: requestId,
|
|
584
374
|
type: "cancelled",
|
|
585
375
|
note: null
|
|
586
376
|
});
|
|
587
377
|
}
|
|
378
|
+
async function endChat(requestId) {
|
|
379
|
+
const tenantId = getActiveTenantId();
|
|
380
|
+
if (!tenantId) throw new Error("Sem conta ativa");
|
|
381
|
+
const { data, error } = await client2().from("plg_support_requests").update({ status: "closed" }).eq("id", requestId).eq("kind", "chat").select("id");
|
|
382
|
+
if (error) throw error;
|
|
383
|
+
if (!data?.length) throw new Error("N\xE3o deu para encerrar por aqui.");
|
|
384
|
+
await client2().from("plg_support_request_events").insert({
|
|
385
|
+
tenant_id: tenantId,
|
|
386
|
+
request_id: requestId,
|
|
387
|
+
type: "status_changed",
|
|
388
|
+
note: "closed"
|
|
389
|
+
});
|
|
390
|
+
}
|
|
588
391
|
async function validateRequest(requestId, ok, reason) {
|
|
589
392
|
const tenantId = getActiveTenantId();
|
|
590
393
|
if (!tenantId) throw new Error("Sem conta ativa");
|
|
591
394
|
const nextStatus = ok ? "closed" : "received";
|
|
592
|
-
const { error } = await
|
|
395
|
+
const { error } = await client2().from("plg_support_requests").update({ status: nextStatus }).eq("id", requestId);
|
|
593
396
|
if (error) throw error;
|
|
594
|
-
await
|
|
397
|
+
await client2().from("plg_support_request_events").insert({
|
|
595
398
|
tenant_id: tenantId,
|
|
596
399
|
request_id: requestId,
|
|
597
400
|
type: ok ? "validated_ok" : "reopened",
|
|
@@ -601,14 +404,14 @@ async function validateRequest(requestId, ok, reason) {
|
|
|
601
404
|
async function markNotificationsRead(requestId) {
|
|
602
405
|
const uid = await userId();
|
|
603
406
|
if (!uid) return;
|
|
604
|
-
await
|
|
407
|
+
await client2().from("plg_support_notifications").update({ read_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("request_id", requestId).eq("user_id", uid).is("read_at", null);
|
|
605
408
|
}
|
|
606
409
|
async function signedUrl(storagePath, expiresIn = 300) {
|
|
607
|
-
const { data, error } = await
|
|
410
|
+
const { data, error } = await client2().storage.from(SUPPORT_BUCKET).createSignedUrl(storagePath, expiresIn);
|
|
608
411
|
if (error) return null;
|
|
609
412
|
return data?.signedUrl ?? null;
|
|
610
413
|
}
|
|
611
414
|
|
|
612
|
-
export { MAX_ATTACHMENTS, MAX_ATTACHMENT_BYTES, PRESENCE_WAIT_MS, SUPPORT_BUCKET, acceptChat, addMessage,
|
|
613
|
-
//# sourceMappingURL=chunk-
|
|
614
|
-
//# sourceMappingURL=chunk-
|
|
415
|
+
export { MAX_ATTACHMENTS, MAX_ATTACHMENT_BYTES, PRESENCE_WAIT_MS, SUPPORT_BUCKET, TYPING_EVERY_MS, TYPING_SHOW_MS, acceptChat, addMessage, atChatLimit, buildTranscript, cancelRequest, chatAvailability, chatHeartbeat, chatQueue, chatState, chatSubject, chatThread, closeChat, createRequest, customerPhase, endChat, getRequestDetail, isActiveChatStatus, limitLine, listRequests, liveChatError, markNotificationsRead, openChat, queueLine, signedUrl, unreadCount, uploadAttachment, validateRequest, waitingFor, wakeV1Bridge };
|
|
416
|
+
//# sourceMappingURL=chunk-S766CRAY.js.map
|
|
417
|
+
//# sourceMappingURL=chunk-S766CRAY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/livechat/api.ts","../src/livechat/rules.ts","../src/data/api.ts"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,MAAM,KAAA;AACjB,EAAA,MAAMA,OAAAA,EAAO,CAAE,IAAA,CAAK,4BAA4B,EAAE,MAAA,CAAO;AAAA,IACvD,SAAA,EAAW,QAAA;AAAA,IAAU,UAAA,EAAY,SAAA;AAAA,IACjC,IAAA,EAAM,KAAK,cAAA,GAAiB,UAAA;AAAA,IAAY,IAAA,EAAM,EAAA,GAAK,IAAA,GAAQ,MAAA,IAAU;AAAA,GACtE,CAAA;AACH;AAEA,eAAsB,sBAAsB,SAAA,EAAkC;AAC5E,EAAA,MAAM,GAAA,GAAM,MAAM,MAAA,EAAO;AACzB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,MAAMA,OAAAA,EAAO,CAAE,IAAA,CAAK,2BAA2B,CAAA,CAC5C,OAAO,EAAE,OAAA,EAAA,iBAAS,IAAI,IAAA,EAAK,EAAE,WAAA,IAAe,CAAA,CAC5C,EAAA,CAAG,YAAA,EAAc,SAAS,CAAA,CAAE,EAAA,CAAG,SAAA,EAAW,GAAG,CAAA,CAAE,EAAA,CAAG,SAAA,EAAW,IAAI,CAAA;AACtE;AAEA,eAAsB,SAAA,CAAU,WAAA,EAAqB,SAAA,GAAY,GAAA,EAA6B;AAC5F,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,EAAM,GAAI,MAAMA,OAAAA,EAAO,CAAE,OAAA,CAAQ,IAAA,CAAK,cAAc,CAAA,CAAE,eAAA,CAAgB,aAAa,SAAS,CAAA;AAC1G,EAAA,IAAI,OAAO,OAAO,IAAA;AAClB,EAAA,OAAO,MAAM,SAAA,IAAa,IAAA;AAC5B","file":"chunk-S766CRAY.js","sourcesContent":["// Domain types for the support/solicitações plugin. Mirrors the V1 support_*\n// family, narrowed to what this wave ships (the client/requester side).\n\n/**\n * The V1 kinds (support_tickets.kind). 'question' (Dúvida) and 'chat' (Conversa\n * com atendente) arrive from the V1 houses over the bridge (support 011); the\n * V2 requester's own doors stay problem / improvement / other.\n */\nexport type SupportKind = 'question' | 'problem' | 'improvement' | 'other' | 'chat'\n\nexport type SupportPriority = 'low' | 'normal' | 'high' | 'urgent'\n\nexport type SupportStatus =\n | 'received'\n /** \"Em triagem\" (support 005): a equipe já olhou; o cliente ainda lê \"Recebida\". */\n | 'triage'\n | 'in_service'\n | 'waiting_you'\n | 'in_development'\n | 'resolved_check'\n | 'closed'\n | 'cancelled'\n\nexport type SupportEventType =\n | 'opened'\n | 'status_changed'\n | 'validated_ok'\n | 'reopened'\n | 'cancelled'\n | 'closed_no_reply'\n | 'merged'\n // support 005 — team-side history (never shown to the requester).\n | 'assigned'\n | 'priority_changed'\n | 'marked_duplicate'\n // support 011 — a reply/status the V1 refused (team-only).\n | 'bridge_refused'\n // support 024 — the operator started the conversation in the open helpdesk (team-only).\n | 'thread_started'\n // support 040 — the V1 ticket came by the migration, not the bridge (team-only).\n | 'imported'\n\nexport type SupportMessageAuthor = 'user' | 'team'\n\nexport interface SupportRequest {\n id: string\n tenantId: string\n number: number\n kind: SupportKind\n subject: string | null\n description: string\n status: SupportStatus\n route: string | null\n unitId: string | null\n screenSnapshot: Record<string, unknown>\n originConversationId: string | null\n /** The inbox thread (plugin-conversations) where this ticket's conversation\n * happens since support 004. Null before the first message / without an inbox. */\n conversationId: string | null\n area: string | null\n createdBy: string\n createdAt: string\n updatedAt: string\n resolvedAt: string | null\n metadata: Record<string, unknown>\n}\n\nexport interface SupportMessage {\n id: string\n requestId: string\n authorKind: SupportMessageAuthor\n authorId: string | null\n body: string\n createdAt: string\n /** A message from before the unification (plg_support_request_messages):\n * read-only, kept where it was. New messages live in the inbox thread. */\n legacy?: boolean\n}\n\nexport interface SupportEvent {\n id: string\n requestId: string\n type: SupportEventType\n note: string | null\n createdAt: string\n}\n\nexport interface SupportAttachment {\n id: string\n requestId: string\n storagePath: string\n name: string\n sizeBytes: number | null\n contentType: string | null\n createdAt: string\n /** A ready link to the file (a host hands it with the detail); absent = sign on demand. */\n url?: string | null\n /** support 040: where the file is — 'v1' = it stayed in the V1 (only the name came over). */\n location?: 'v1' | 'v2' | null\n /** support 040: the V1 attachment id of an imported one. */\n externalId?: string | null\n}\n\nexport interface SupportRequestDetail extends SupportRequest {\n messages: SupportMessage[]\n events: SupportEvent[]\n attachments: SupportAttachment[]\n}\n\n/** What the form collects before an attachment upload. */\nexport interface CreateSupportRequestInput {\n kind: SupportKind\n description: string\n subject?: string | null\n route?: string | null\n unitId?: string | null\n screenSnapshot?: Record<string, unknown>\n originConversationId?: string | null\n area?: string | null\n}\n\n/** A file staged in the form, before it is uploaded to the bucket. */\nexport interface PendingAttachment {\n id: string\n file: Blob\n name: string\n contentType: string\n sizeBytes: number\n /** Object URL for a local thumbnail; revoke on unmount. */\n previewUrl?: string\n}\n\nexport type SupportScope = 'mine' | 'all'\n\nexport type SupportFilter = 'waiting' | 'in_progress' | 'closed' | 'all'\n\nexport const MAX_ATTACHMENTS = 8\nexport const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024\nexport const SUPPORT_BUCKET = 'support-attachments'\n","import { getSupabaseClientOptional, getActiveUnitId } from '@fayz-ai/core'\nimport type { SupportStatus } from '../types'\nimport type { SupportBusinessHours } from '../lib/support-settings'\nimport type { ConsoleDetail } from '../data/console'\nimport { consoleDetail } from '../data/console'\n\n// The live chat's data layer (support 020). Every call is a SECURITY DEFINER\n// RPC: the customer's side checks the ticket is in one of the caller's\n// accounts; the agent's side runs the console guard and the agent registry.\n\nfunction client(): any {\n const c = getSupabaseClientOptional()\n if (!c) throw new Error('Supabase client not available')\n return c\n}\n\nconst isMissingFn = (e: any) => e?.code === 'PGRST202' || e?.code === '42883'\n\n/** A friendlier line for what the server refuses (the RPCs already speak pt-BR). */\nexport function liveChatError(e: unknown): string {\n const msg = (e as any)?.message as string | undefined\n if (isMissingFn(e)) return 'O atendimento ao vivo ainda não está ligado neste ambiente.'\n return msg && !/^[a-z_ ]+$/.test(msg) ? msg : 'Não consegui falar com o atendimento agora. Tente de novo.'\n}\n\n// ── customer ──────────────────────────────────────────────────────────────\n\nexport interface ChatAvailability {\n /** The central whose presence decides; null = no live chat for this account. */\n homeId: string | null\n enabled: boolean\n offlineMessage: string | null\n businessHours: SupportBusinessHours\n timezone: string\n activeChat: { id: string; number: number } | null\n /**\n * Agents available now, counted by the server (their clock-in, support 021).\n * Set only where the page has no Realtime of this pool to watch the presence\n * (a host, `@fayz-ai/plugin-support/host`); undefined = watch the presence.\n */\n online?: number\n}\n\nexport async function chatAvailability(): Promise<ChatAvailability | null> {\n const { data, error } = await client().rpc('support_chat_availability')\n if (error) { if (isMissingFn(error)) return null; throw error }\n const d = (data ?? {}) as any\n return {\n homeId: d.home_id ?? null,\n enabled: d.enabled === true,\n offlineMessage: d.offline_message ?? null,\n businessHours: (d.business_hours ?? {}) as SupportBusinessHours,\n timezone: d.timezone ?? 'America/Sao_Paulo',\n activeChat: d.active_chat ? { id: d.active_chat.id, number: d.active_chat.number } : null,\n }\n}\n\nexport interface OpenChatInput {\n subject?: string | null\n description?: string | null\n route?: string | null\n originConversationId?: string | null\n screenSnapshot?: Record<string, unknown>\n}\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/**\n * `origin_conversation_id` is a uuid column (V1: the Suportino conversation).\n * The V2 assistant's ids are not uuids (the agent's own ids): those travel in\n * the screen snapshot instead, so the ticket still says which conversation it\n * came from and the agent's greeting still says \"Já li a sua conversa…\".\n */\nexport function originFields(originConversationId: string | null | undefined, snapshot: Record<string, unknown> = {}) {\n const id = originConversationId?.trim() || null\n if (!id) return { origin: null, snapshot }\n return UUID_RE.test(id) ? { origin: id, snapshot } : { origin: null, snapshot: { ...snapshot, assistant_conversation_id: id } }\n}\n\nexport async function openChat(input: OpenChatInput = {}): Promise<{ id: string; number: number; conversationId: string | null; reused: boolean }> {\n const o = originFields(input.originConversationId, input.screenSnapshot ?? {})\n const { data, error } = await client().rpc('support_chat_open', {\n p_subject: input.subject ?? null,\n p_description: input.description ?? null,\n p_route: input.route ?? null,\n p_unit_id: getActiveUnitId() ?? null,\n p_origin_conversation_id: o.origin,\n p_screen_snapshot: o.snapshot,\n })\n if (error) throw error\n const d = data as any\n return { id: d.id, number: d.number, conversationId: d.conversation_id ?? null, reused: d.reused === true }\n}\n\nexport interface ChatState {\n id: string\n number: number\n status: SupportStatus\n waiting: boolean\n position: number | null\n teamReplied: boolean\n agentName: string | null\n conversationId: string | null\n homeId: string | null\n}\n\nexport async function chatState(requestId: string): Promise<ChatState> {\n const { data, error } = await client().rpc('support_chat_state', { p_request_id: requestId })\n if (error) throw error\n const d = data as any\n return {\n id: d.id, number: d.number, status: d.status, waiting: d.waiting === true,\n position: typeof d.position === 'number' ? d.position : null,\n teamReplied: d.team_replied === true, agentName: d.agent_name ?? null,\n conversationId: d.conversation_id ?? null, homeId: d.home_id ?? null,\n }\n}\n\n/** The live chat's messages with who wrote them (support 020 support_chat_thread). */\nexport async function chatThread(requestId: string): Promise<Array<{ id: string; mine: boolean; author: string | null; body: string; at: string }>> {\n const { data, error } = await client().rpc('support_chat_thread', { p_request_id: requestId })\n if (error) throw error\n return (((data as any)?.messages ?? []) as any[]).map((m) => ({\n id: m.id, mine: m.author_kind !== 'team', author: m.author ?? null, body: m.body ?? '', at: m.created_at,\n }))\n}\n\n// ── agent ─────────────────────────────────────────────────────────────────\n\nexport interface QueueChat {\n id: string\n number: number\n /** 'v1' = a V1 house's chat (support 021): typing does not cross, messages ride the bridge. */\n origin: 'v1' | 'v2'\n subject: string | null\n createdAt: string\n tenantId: string\n tenantName: string | null\n createdByName: string | null\n conversationId: string | null\n}\n\nexport interface ChatAgentMe {\n agent: boolean\n displayName: string\n maxChats: number\n activeChats: number\n}\n\nexport interface ChatQueue { chats: QueueChat[]; me: ChatAgentMe }\n\n/** null = the pool predates support 020 (no live chat on the board). */\nexport async function chatQueue(): Promise<ChatQueue | null> {\n const { data, error } = await client().rpc('support_chat_queue')\n if (error) { if (isMissingFn(error)) return null; throw error }\n const d = (data ?? {}) as any\n return {\n chats: ((d.chats ?? []) as any[]).map((c) => ({\n id: c.id, number: c.number, origin: c.origin === 'v1' ? 'v1' : 'v2', subject: c.subject ?? null, createdAt: c.created_at,\n tenantId: c.tenant_id, tenantName: c.tenant_name ?? null, createdByName: c.created_by_name ?? null,\n conversationId: c.conversation_id ?? null,\n })),\n me: {\n agent: d.me?.agent === true,\n displayName: d.me?.display_name ?? 'Suporte',\n maxChats: Number(d.me?.max_chats ?? 0),\n activeChats: Number(d.me?.active_chats ?? 0),\n },\n }\n}\n\nexport async function acceptChat(requestId: string): Promise<ConsoleDetail | null> {\n const { error } = await client().rpc('support_chat_accept', { p_request_id: requestId })\n if (error) throw error\n return consoleDetail(requestId)\n}\n\n/** \"Encerrar conversa\" — Resolvida; the customer confirms or reopens. */\nexport async function closeChat(requestId: string): Promise<ConsoleDetail | null> {\n const { error } = await client().rpc('support_chat_close', { p_request_id: requestId })\n if (error) throw error\n return consoleDetail(requestId)\n}\n\n// ── the bridge to the V1 (support 021) ───────────────────────────────────\n\n/**\n * The agent's clock-in for the V1 (every 30 s while the app is open). The\n * browser presence never leaves this Realtime; this is what the bridge counts\n * and tells the V1 (support.availability). null = a pool without support 021.\n */\nexport async function chatHeartbeat(status: 'online' | 'away'): Promise<{ agent: boolean; changed: boolean; bridge: boolean } | null> {\n const { data, error } = await client().rpc('support_chat_heartbeat', { p_status: status })\n if (error) { if (isMissingFn(error)) return null; throw error }\n const d = (data ?? {}) as any\n return { agent: d.agent === true, changed: d.changed === true, bridge: d.bridge === true }\n}\n\n/** The edge that delivers the queued V1 commands (customer-success functions/v1-bridge-commands-push). */\nexport const V1_BRIDGE_PUSH_FUNCTION = 'v1-bridge-commands-push'\nlet wakeTimer: ReturnType<typeof setTimeout> | null = null\n\n/**\n * Deliver NOW what is queued for the V1 (an accept, a reply, an \"Encerrar\") and\n * tell it who is available, instead of waiting for the clock (≤ 60 s). The edge\n * only delivers what is due, so any signed-in user may wake it. Debounced and\n * fire-and-forget: a failure just leaves it to the clock.\n */\nexport function wakeV1Bridge(delayMs = 400): void {\n if (wakeTimer) clearTimeout(wakeTimer)\n wakeTimer = setTimeout(() => {\n wakeTimer = null\n try {\n const c = getSupabaseClientOptional() as any\n void c?.functions?.invoke?.(V1_BRIDGE_PUSH_FUNCTION, { body: {} })?.catch?.(() => {})\n } catch { /* the clock delivers it */ }\n }, delayMs)\n}\n","import type { SupportStatus } from '../types'\n\n// The live chat's rules, pure (V1 src/lib/support/liveChat.ts + useLiveChat.ts).\n\n/** Presence takes a moment to sync; after this, \"nobody\" means nobody (V1 ConnectToAgent). */\nexport const PRESENCE_WAIT_MS = 4000\n/** \"Digitando…\" shows for 4 s after the last signal, and is sent at most every 2 s (V1 useTyping). */\nexport const TYPING_SHOW_MS = 4000\nexport const TYPING_EVERY_MS = 2000\n\nconst FINAL: SupportStatus[] = ['resolved_check', 'closed', 'cancelled']\n\n/** A chat still running (V1: Nova/Em triagem/Em atendimento/Aguardando). */\nexport function isActiveChatStatus(status: SupportStatus): boolean {\n return !FINAL.includes(status)\n}\n\n/** What the customer's chat panel shows, from the ticket's state. */\nexport type CustomerChatPhase = 'waiting' | 'chatting' | 'resolved' | 'closed'\n\nexport function customerPhase(s: { status: SupportStatus; waiting: boolean; teamReplied: boolean }): CustomerChatPhase {\n if (s.status === 'resolved_check') return 'resolved'\n if (s.status === 'closed' || s.status === 'cancelled') return 'closed'\n // Answered from /conversations without \"Aceitar\": somebody is talking — not waiting.\n if (s.waiting && !s.teamReplied) return 'waiting'\n return 'chatting'\n}\n\n/** \"Você é o 1º da fila\" — ordinal in pt-BR, short. */\nexport function queueLine(position: number | null): string | null {\n if (!position || position < 1) return null\n return position === 1 ? 'Você é o próximo a ser atendido.' : `Você é o ${position}º da fila.`\n}\n\n/** V1 activeChatsOf/noLimite: at the limit when active ≥ max (0 = never accepts). */\nexport function atChatLimit(me: { maxChats: number; activeChats: number } | null): boolean {\n return !!me && me.activeChats >= me.maxChats\n}\n\nexport function limitLine(max: number): string {\n return `Você está no limite de ${max} ${max === 1 ? 'conversa' : 'conversas'} ao mesmo tempo.`\n}\n\n/** \"esperando há 35 min\" — the queue row's age (V1 idade). */\nexport function waitingFor(iso: string, now: number = Date.now()): string {\n const min = Math.max(0, Math.floor((now - Date.parse(iso)) / 60_000))\n if (min < 60) return `${min} min`\n const h = Math.floor(min / 60)\n if (h < 24) return `${h} h`\n return `${Math.floor(h / 24)} d`\n}\n\nexport interface TranscriptMessage { role: 'user' | 'assistant'; content: string }\n\n/** V1 buildTranscript: the assistant conversation so far, newest weighs more (cut from the start). */\nexport function buildTranscript(messages: TranscriptMessage[], maxChars = 6000): string {\n const lines = messages\n .filter((m) => m.content?.trim())\n .map((m) => `${m.role === 'user' ? 'Cliente' : 'Atendimento automático'}: ${m.content.trim()}`)\n let text = lines.join('\\n\\n')\n if (text.length > maxChars) text = '…\\n' + text.slice(text.length - maxChars + 2)\n return text\n}\n\n/** V1 chatSubject: the person's first question, or the generic one. */\nexport function chatSubject(messages: TranscriptMessage[]): string {\n const first = messages.find((m) => m.role === 'user' && m.content?.trim())?.content.trim()\n if (!first) return 'Conversa com atendente'\n const short = first.replace(/\\s+/g, ' ')\n return `Conversa: ${short.length > 80 ? short.slice(0, 80).trimEnd() + '…' : short}`\n}\n","import { getSupabaseClientOptional, getActiveTenantId, getActiveUnitId } from '@fayz-ai/core'\nimport {\n type SupportRequest, type SupportRequestDetail, type SupportMessage,\n type SupportEvent, type SupportAttachment, type CreateSupportRequestInput,\n type PendingAttachment, type SupportScope, type SupportFilter, type SupportStatus,\n SUPPORT_BUCKET,\n} from '../types'\nimport { FILTER_STATUSES, TEAM_ONLY_EVENTS, deriveSubject } from '../lib/vocabulary'\n\n// The data provider is PostgREST + RLS, not an RPC layer: a user only reads and\n// writes rows their tenant policy allows, and `created_by` defaults to auth.uid()\n// in the schema so it cannot be spoofed from here. The \"Minhas vs Toda a empresa\"\n// split is a query filter (scope), gated in the UI by the support.all feature.\n\ntype AnyClient = any // supabase-js client; typed loosely as the other plugins do\n\nfunction client(): AnyClient {\n const c = getSupabaseClientOptional()\n if (!c) throw new Error('Supabase client not available')\n return c as AnyClient\n}\n\nlet cachedUserId: string | null = null\nasync function userId(): Promise<string | null> {\n if (cachedUserId) return cachedUserId\n const { data } = await client().auth.getUser()\n cachedUserId = data?.user?.id ?? null\n return cachedUserId\n}\n\n// ── row mappers ───────────────────────────────────────────────────────────\n\nfunction toRequest(r: any): SupportRequest {\n return {\n id: r.id,\n tenantId: r.tenant_id,\n number: r.number,\n kind: r.kind,\n subject: r.subject ?? null,\n description: r.description,\n status: r.status,\n route: r.route ?? null,\n unitId: r.unit_id ?? null,\n screenSnapshot: r.screen_snapshot ?? {},\n originConversationId: r.origin_conversation_id ?? null,\n conversationId: r.conversation_id ?? null,\n area: r.area ?? null,\n createdBy: r.created_by,\n createdAt: r.created_at,\n updatedAt: r.updated_at,\n resolvedAt: r.resolved_at ?? null,\n metadata: r.metadata ?? {},\n }\n}\n\nconst toMessage = (r: any): SupportMessage => ({\n id: r.id, requestId: r.request_id, authorKind: r.author_kind,\n authorId: r.author_id ?? null, body: r.body, createdAt: r.created_at,\n})\n\nconst toEvent = (r: any): SupportEvent => ({\n id: r.id, requestId: r.request_id, type: r.type, note: r.note ?? null, createdAt: r.created_at,\n})\n\nconst toAttachment = (r: any): SupportAttachment => ({\n id: r.id, requestId: r.request_id, storagePath: r.storage_path, name: r.name,\n sizeBytes: r.size_bytes ?? null, contentType: r.content_type ?? null, createdAt: r.created_at,\n})\n\n/** PostgREST's \"no such function\": the pool predates support 004. The panel\n * keeps working on the old message table until the migration lands. */\nfunction missingRpc(error: any): boolean {\n return error?.code === 'PGRST202' || error?.code === '42883'\n}\n\nconst toThreadMessage = (requestId: string) => (r: any): SupportMessage => ({\n id: r.id, requestId, authorKind: r.author_kind === 'team' ? 'team' : 'user',\n authorId: null, body: r.body ?? '', createdAt: r.created_at, legacy: r.legacy === true,\n})\n\n/** The ticket's conversation: the old messages (read-only) and, since 004, the\n * inbox thread — one list, oldest first. Through a SECURITY DEFINER RPC\n * because the thread lives in the helpdesk's account, not this one. */\nasync function threadMessages(requestId: string): Promise<SupportMessage[]> {\n const { data, error } = await client().rpc('support_request_thread', { p_request_id: requestId })\n if (error) {\n if (!missingRpc(error)) throw error\n const legacy = await client().from('plg_support_request_messages').select('*').eq('request_id', requestId).order('created_at', { ascending: true })\n return (legacy.data ?? []).map(toMessage)\n }\n return ((data as any)?.messages ?? []).map(toThreadMessage(requestId))\n}\n\n// ── reads ─────────────────────────────────────────────────────────────────\n\nexport async function listRequests(scope: SupportScope, filter: SupportFilter): Promise<SupportRequest[]> {\n let q = client().from('plg_support_requests').select('*').order('number', { ascending: false })\n if (scope === 'mine') {\n const uid = await userId()\n if (uid) q = q.eq('created_by', uid)\n }\n if (filter !== 'all') {\n const statuses = FILTER_STATUSES[filter]\n q = q.in('status', statuses)\n }\n const { data, error } = await q\n if (error) throw error\n return (data ?? []).map(toRequest)\n}\n\nexport async function getRequestDetail(id: string): Promise<SupportRequestDetail | null> {\n const { data: req, error } = await client().from('plg_support_requests').select('*').eq('id', id).maybeSingle()\n if (error) throw error\n if (!req) return null\n const [messages, events, attachments] = await Promise.all([\n threadMessages(id),\n client().from('plg_support_request_events').select('*').eq('request_id', id).order('created_at', { ascending: true }),\n client().from('plg_support_request_attachments').select('*').eq('request_id', id).order('created_at', { ascending: true }),\n ])\n return {\n ...toRequest(req),\n messages,\n // The team's own history (atribuída, prioridade, duplicata) stays with the\n // team — the requester reads the V1 client vocabulary only (support 005).\n events: (events.data ?? []).map(toEvent).filter((e: SupportEvent) => !TEAM_ONLY_EVENTS.has(e.type)),\n attachments: (attachments.data ?? []).map(toAttachment),\n }\n}\n\nexport async function unreadCount(): Promise<number> {\n const uid = await userId()\n if (!uid) return 0\n const { count, error } = await client()\n .from('plg_support_notifications')\n .select('id', { count: 'exact', head: true })\n .eq('user_id', uid)\n .is('read_at', null)\n if (error) return 0\n return count ?? 0\n}\n\n// ── writes ──────────────────────────────────────────────────────────────\n\nexport async function createRequest(input: CreateSupportRequestInput): Promise<{ id: string; number: number }> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const subject = (input.subject && input.subject.trim()) || deriveSubject(input.description)\n const row = {\n tenant_id: tenantId,\n kind: input.kind,\n subject,\n description: input.description.trim(),\n route: input.route ?? null,\n unit_id: input.unitId ?? getActiveUnitId() ?? null,\n screen_snapshot: input.screenSnapshot ?? {},\n origin_conversation_id: input.originConversationId ?? null,\n area: input.area ?? null,\n status: 'received' as SupportStatus,\n }\n const { data, error } = await client().from('plg_support_requests').insert(row).select('id, number').single()\n if (error) throw error\n await client().from('plg_support_request_events').insert({\n tenant_id: tenantId, request_id: data.id, type: 'opened', note: null,\n })\n return { id: data.id, number: data.number }\n}\n\nexport async function uploadAttachment(requestId: string, pending: PendingAttachment): Promise<SupportAttachment> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const safeName = pending.name.replace(/[^\\w.\\-]+/g, '_')\n const path = `${tenantId}/${requestId}/${crypto.randomUUID()}/${safeName}`\n const up = await client().storage.from(SUPPORT_BUCKET).upload(path, pending.file, {\n contentType: pending.contentType, upsert: false,\n })\n if (up.error) throw up.error\n const { data, error } = await client().from('plg_support_request_attachments').insert({\n tenant_id: tenantId, request_id: requestId, storage_path: path,\n name: pending.name, size_bytes: pending.sizeBytes, content_type: pending.contentType,\n }).select('*').single()\n if (error) throw error\n return toAttachment(data)\n}\n\n/** The requester answers. Since 004 the message goes to the ticket's inbox\n * thread (the team sees it in /conversations and in the ticket); the RPC\n * falls back to the old table only where there is no inbox to unify with. */\nexport async function addMessage(requestId: string, body: string): Promise<void> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const sent = await client().rpc('support_request_send', { p_request_id: requestId, p_body: body.trim() })\n if (!sent.error) return\n if (!missingRpc(sent.error)) throw sent.error\n const { error } = await client().from('plg_support_request_messages').insert({\n tenant_id: tenantId, request_id: requestId, author_kind: 'user', body: body.trim(),\n })\n if (error) throw error\n}\n\nexport async function cancelRequest(requestId: string): Promise<void> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const { error } = await client().from('plg_support_requests')\n .update({ status: 'cancelled' as SupportStatus }).eq('id', requestId)\n if (error) throw error\n await client().from('plg_support_request_events').insert({\n tenant_id: tenantId, request_id: requestId, type: 'cancelled', note: null,\n })\n}\n\n/**\n * \"Encerrar\" by the person who asked: the live chat is over from their side,\n * taken or not (the requester's own row — same direct write as cancel/validate).\n */\nexport async function endChat(requestId: string): Promise<void> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const { data, error } = await client().from('plg_support_requests')\n .update({ status: 'closed' as SupportStatus }).eq('id', requestId).eq('kind', 'chat').select('id')\n if (error) throw error\n // Nothing written (not this person's row, or not a chat): say so, the caller tells the team instead.\n if (!data?.length) throw new Error('Não deu para encerrar por aqui.')\n await client().from('plg_support_request_events').insert({\n tenant_id: tenantId, request_id: requestId, type: 'status_changed', note: 'closed',\n })\n}\n\nexport async function validateRequest(requestId: string, ok: boolean, reason?: string): Promise<void> {\n const tenantId = getActiveTenantId()\n if (!tenantId) throw new Error('Sem conta ativa')\n const nextStatus: SupportStatus = ok ? 'closed' : 'received'\n const { error } = await client().from('plg_support_requests')\n .update({ status: nextStatus }).eq('id', requestId)\n if (error) throw error\n await client().from('plg_support_request_events').insert({\n tenant_id: tenantId, request_id: requestId,\n type: ok ? 'validated_ok' : 'reopened', note: ok ? null : (reason ?? null),\n })\n}\n\nexport async function markNotificationsRead(requestId: string): Promise<void> {\n const uid = await userId()\n if (!uid) return\n await client().from('plg_support_notifications')\n .update({ read_at: new Date().toISOString() })\n .eq('request_id', requestId).eq('user_id', uid).is('read_at', null)\n}\n\nexport async function signedUrl(storagePath: string, expiresIn = 300): Promise<string | null> {\n const { data, error } = await client().storage.from(SUPPORT_BUCKET).createSignedUrl(storagePath, expiresIn)\n if (error) return null\n return data?.signedUrl ?? null\n}\n"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { chatThread, chatState, openChat, chatAvailability, markNotificationsRead, validateRequest, endChat, cancelRequest, addMessage, unreadCount, getRequestDetail, listRequests, signedUrl, uploadAttachment, createRequest } from './chunk-S766CRAY.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { create } from 'zustand';
|
|
4
|
+
|
|
5
|
+
// src/data/provider.ts
|
|
6
|
+
var platformSupportProvider = {
|
|
7
|
+
listRequests,
|
|
8
|
+
getRequestDetail,
|
|
9
|
+
unreadCount,
|
|
10
|
+
async createRequest(input, attachments) {
|
|
11
|
+
const res = await createRequest(input);
|
|
12
|
+
for (const pending of attachments.slice(0, 8)) {
|
|
13
|
+
try {
|
|
14
|
+
await uploadAttachment(res.id, pending);
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return res;
|
|
19
|
+
},
|
|
20
|
+
addMessage,
|
|
21
|
+
async addAttachments(requestId, attachments) {
|
|
22
|
+
let landed = 0;
|
|
23
|
+
for (const pending of attachments.slice(0, 8)) {
|
|
24
|
+
try {
|
|
25
|
+
await uploadAttachment(requestId, pending);
|
|
26
|
+
landed += 1;
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return landed;
|
|
31
|
+
},
|
|
32
|
+
cancelRequest,
|
|
33
|
+
endChat,
|
|
34
|
+
validateRequest,
|
|
35
|
+
markNotificationsRead,
|
|
36
|
+
attachmentUrl: (att) => signedUrl(att.storagePath),
|
|
37
|
+
chatAvailability,
|
|
38
|
+
openChat,
|
|
39
|
+
chatState,
|
|
40
|
+
chatThread,
|
|
41
|
+
realtime: true
|
|
42
|
+
};
|
|
43
|
+
var active = null;
|
|
44
|
+
function setSupportDataProvider(provider) {
|
|
45
|
+
active = provider;
|
|
46
|
+
}
|
|
47
|
+
function supportData() {
|
|
48
|
+
return active ?? platformSupportProvider;
|
|
49
|
+
}
|
|
50
|
+
function supportRealtime() {
|
|
51
|
+
return supportData().realtime !== false;
|
|
52
|
+
}
|
|
53
|
+
var useSupportStore = create((set, get) => ({
|
|
54
|
+
requests: [],
|
|
55
|
+
loadingList: false,
|
|
56
|
+
scope: "mine",
|
|
57
|
+
filter: "all",
|
|
58
|
+
selectedId: null,
|
|
59
|
+
detail: null,
|
|
60
|
+
loadingDetail: false,
|
|
61
|
+
unread: 0,
|
|
62
|
+
setScope: (scope) => {
|
|
63
|
+
set({ scope });
|
|
64
|
+
void get().loadList();
|
|
65
|
+
},
|
|
66
|
+
setFilter: (filter) => {
|
|
67
|
+
set({ filter });
|
|
68
|
+
void get().loadList();
|
|
69
|
+
},
|
|
70
|
+
loadList: async () => {
|
|
71
|
+
set({ loadingList: true });
|
|
72
|
+
try {
|
|
73
|
+
const requests = await supportData().listRequests(get().scope, get().filter);
|
|
74
|
+
set({ requests });
|
|
75
|
+
} finally {
|
|
76
|
+
set({ loadingList: false });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
select: async (id) => {
|
|
80
|
+
set({ selectedId: id, detail: null });
|
|
81
|
+
if (!id) return;
|
|
82
|
+
set({ loadingDetail: true });
|
|
83
|
+
try {
|
|
84
|
+
const detail = await supportData().getRequestDetail(id);
|
|
85
|
+
set({ detail });
|
|
86
|
+
await supportData().markNotificationsRead(id);
|
|
87
|
+
void get().refreshUnread();
|
|
88
|
+
} finally {
|
|
89
|
+
set({ loadingDetail: false });
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
refreshDetail: async () => {
|
|
93
|
+
const id = get().selectedId;
|
|
94
|
+
if (!id) return;
|
|
95
|
+
const detail = await supportData().getRequestDetail(id);
|
|
96
|
+
set({ detail });
|
|
97
|
+
},
|
|
98
|
+
refreshUnread: async () => {
|
|
99
|
+
set({ unread: await supportData().unreadCount() });
|
|
100
|
+
},
|
|
101
|
+
create: async (input, attachments) => {
|
|
102
|
+
const res = await supportData().createRequest(input, attachments);
|
|
103
|
+
await get().loadList();
|
|
104
|
+
return res;
|
|
105
|
+
},
|
|
106
|
+
sendMessage: async (body) => {
|
|
107
|
+
const id = get().selectedId;
|
|
108
|
+
if (!id || !body.trim()) return;
|
|
109
|
+
await supportData().addMessage(id, body);
|
|
110
|
+
await get().refreshDetail();
|
|
111
|
+
},
|
|
112
|
+
cancel: async () => {
|
|
113
|
+
const id = get().selectedId;
|
|
114
|
+
if (!id) return;
|
|
115
|
+
await supportData().cancelRequest(id);
|
|
116
|
+
await Promise.all([get().refreshDetail(), get().loadList()]);
|
|
117
|
+
},
|
|
118
|
+
validate: async (ok, reason) => {
|
|
119
|
+
const id = get().selectedId;
|
|
120
|
+
if (!id) return;
|
|
121
|
+
await supportData().validateRequest(id, ok, reason);
|
|
122
|
+
await Promise.all([get().refreshDetail(), get().loadList()]);
|
|
123
|
+
},
|
|
124
|
+
reset: () => set({ requests: [], loadingList: false, scope: "mine", filter: "all", selectedId: null, detail: null, loadingDetail: false, unread: 0 })
|
|
125
|
+
}));
|
|
126
|
+
function useLiveRequestDetail(id) {
|
|
127
|
+
const refresh = useSupportStore((s) => s.refreshDetail);
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
if (!id || typeof document === "undefined") return;
|
|
130
|
+
let timer = null;
|
|
131
|
+
const every = supportData().pollMs?.detail ?? 15e3;
|
|
132
|
+
const start = () => {
|
|
133
|
+
if (!timer) timer = setInterval(() => {
|
|
134
|
+
void refresh().catch(() => {
|
|
135
|
+
});
|
|
136
|
+
}, every);
|
|
137
|
+
};
|
|
138
|
+
const stop = () => {
|
|
139
|
+
if (timer) {
|
|
140
|
+
clearInterval(timer);
|
|
141
|
+
timer = null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const onVis = () => document.visibilityState === "visible" ? start() : stop();
|
|
145
|
+
onVis();
|
|
146
|
+
document.addEventListener("visibilitychange", onVis);
|
|
147
|
+
return () => {
|
|
148
|
+
stop();
|
|
149
|
+
document.removeEventListener("visibilitychange", onVis);
|
|
150
|
+
};
|
|
151
|
+
}, [id, refresh]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { setSupportDataProvider, supportData, supportRealtime, useLiveRequestDetail, useSupportStore };
|
|
155
|
+
//# sourceMappingURL=chunk-WHEJ63CM.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-WHEJ63CM.js.map
|