@fayz-ai/plugin-conversations 0.24.9 → 0.26.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.
@@ -1,7 +1,7 @@
1
- import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, providersApi } from './chunk-3IQOSA3Y.js';
1
+ import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, providersApi, mediaPreviewKind } from './chunk-6EZLUC62.js';
2
2
  import * as React9 from 'react';
3
3
  import React9__default from 'react';
4
- import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Inbox, CheckCheck, ChevronLeft, Archive, PanelRight, Send, X, MapPin, Tag, StickyNote, Link2, CheckCircle2, MoreVertical, Loader2, AlertTriangle, Check, Clock, Snowflake, Sun, Flame, Building2, ExternalLink, UserRound, Copy, FileText, Download } from 'lucide-react';
4
+ import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Inbox, CheckCheck, ChevronLeft, Archive, PanelRight, Send, X, MapPin, Tag, StickyNote, Link2, CheckCircle2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, Snowflake, Sun, Flame, Building2, Ban, BarChart3, UserRound, Copy, FileText, Download } from 'lucide-react';
5
5
  import { PageHeaderActions, cn, Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Textarea, ModalFooter, Input, FilterChip, Skeleton, toast } from '@fayz-ai/ui';
6
6
  import { useRightRailStore, PageActions, useLimitGuard, ContactPicker, invalidateLimit, useConnectors, adminNavigateTo } from '@fayz-ai/admin';
7
7
  import { currentAppPath, appHref, useTranslation, useActiveTenantId, errorMessage, tl, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
@@ -292,7 +292,7 @@ function ConversationList({ className }) {
292
292
  ] })
293
293
  ] }),
294
294
  /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [
295
- /* @__PURE__ */ jsx("span", { className: cn("truncate text-xs", unread ? "text-foreground" : "text-muted-foreground"), children: c.lastMessagePreview }),
295
+ /* @__PURE__ */ jsx("span", { className: cn("truncate text-xs", unread ? "text-foreground" : "text-muted-foreground"), children: /* @__PURE__ */ jsx(MessagePreview, { text: c.lastMessagePreview }) }),
296
296
  unread && /* @__PURE__ */ jsx("span", { className: "flex h-[18px] min-w-[18px] shrink-0 items-center justify-center rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground", children: c.unreadCount > 0 ? c.unreadCount : "\xB7" })
297
297
  ] })
298
298
  ] })
@@ -571,7 +571,7 @@ function MediaBubble({ m, outbound }) {
571
571
  const tipo = String(m.messageType);
572
572
  const p = m.payload ?? {};
573
573
  const legenda = p.caption ?? null;
574
- const rotulo = /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: m.body });
574
+ const rotulo = mediaPreviewKind(m.body) ? /* @__PURE__ */ jsx("p", { className: "opacity-80", children: /* @__PURE__ */ jsx(MessagePreview, { text: m.body, suffix: duracao(p.seconds) || void 0 }) }) : /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: m.body });
575
575
  if (erro) {
576
576
  return /* @__PURE__ */ jsxs("div", { ref, className: "space-y-1", children: [
577
577
  rotulo,
@@ -607,10 +607,7 @@ function MediaBubble({ m, outbound }) {
607
607
  if (tipo === "audio") {
608
608
  return /* @__PURE__ */ jsxs("div", { ref, className: "space-y-1", children: [
609
609
  /* @__PURE__ */ jsx("audio", { src: url, controls: true, preload: "metadata", className: "h-9 w-64 max-w-full" }),
610
- /* @__PURE__ */ jsxs("p", { className: "text-xs opacity-60", children: [
611
- p.ptt ? "Mensagem de voz" : "\xC1udio",
612
- duracao(p.seconds) ? ` \xB7 ${duracao(p.seconds)}` : ""
613
- ] })
610
+ /* @__PURE__ */ jsx("p", { className: "text-xs opacity-60", children: /* @__PURE__ */ jsx(MessagePreview, { text: "[\xE1udio]", suffix: duracao(p.seconds) || void 0 }) })
614
611
  ] });
615
612
  }
616
613
  const nome = p.fileName ?? "Documento";
@@ -636,6 +633,171 @@ function MediaBubble({ m, outbound }) {
636
633
  legenda ? /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: legenda }) : null
637
634
  ] });
638
635
  }
636
+ var URL_RE = /(https?:\/\/[^\s<]+[^\s<.,;:!?)\]'"])/gu;
637
+ function RichText({ text, outbound }) {
638
+ const linkCls = outbound ? "underline text-white" : "text-[hsl(var(--info))] underline";
639
+ const parts = [];
640
+ const blocks = String(text ?? "").split(/```([\s\S]*?)```/gu);
641
+ blocks.forEach((block, bi) => {
642
+ if (bi % 2 === 1) {
643
+ parts.push(/* @__PURE__ */ jsx("code", { className: "rounded bg-black/10 px-1 font-mono text-[12px]", children: block }, `m${bi}`));
644
+ return;
645
+ }
646
+ block.split(URL_RE).forEach((chunk, ci) => {
647
+ if (ci % 2 === 1) {
648
+ parts.push(/* @__PURE__ */ jsx("a", { href: chunk, target: "_blank", rel: "noreferrer", className: cn("break-all", linkCls), children: chunk }, `u${bi}-${ci}`));
649
+ return;
650
+ }
651
+ parts.push(...inline(chunk, `t${bi}-${ci}`));
652
+ });
653
+ });
654
+ return /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: parts });
655
+ }
656
+ function inline(text, key) {
657
+ const re = /(\*[^\s*][^*\n]*?\*|_[^\s_][^_\n]*?_|~[^\s~][^~\n]*?~|`[^`\n]+`)/gu;
658
+ return text.split(re).map((chunk, i) => {
659
+ if (i % 2 === 0) return chunk;
660
+ const inner = chunk.slice(1, -1);
661
+ const k = `${key}-${i}`;
662
+ switch (chunk[0]) {
663
+ case "*":
664
+ return /* @__PURE__ */ jsx("strong", { children: inner }, k);
665
+ case "_":
666
+ return /* @__PURE__ */ jsx("em", { children: inner }, k);
667
+ case "~":
668
+ return /* @__PURE__ */ jsx("s", { children: inner }, k);
669
+ default:
670
+ return /* @__PURE__ */ jsx("code", { className: "rounded bg-black/10 px-1 font-mono text-[12px]", children: inner }, k);
671
+ }
672
+ });
673
+ }
674
+ function ForwardedLabel({ m }) {
675
+ const t = useTranslation();
676
+ const f = m.payload?.forwarded;
677
+ if (!f) return null;
678
+ return /* @__PURE__ */ jsxs("p", { className: "mb-0.5 flex items-center gap-1 text-[11px] italic opacity-70", children: [
679
+ /* @__PURE__ */ jsx(Forward, { className: "h-3 w-3" }),
680
+ t(f === "many" ? "conversations.bubble.forwardedMany" : "conversations.bubble.forwarded")
681
+ ] });
682
+ }
683
+ function QuotedBlock({ m, outbound, onJump }) {
684
+ const q = m.payload?.quoted;
685
+ if (!q) return null;
686
+ return /* @__PURE__ */ jsx(
687
+ Button,
688
+ {
689
+ variant: "bare",
690
+ size: "bare",
691
+ type: "button",
692
+ onClick: () => onJump?.(q.id),
693
+ className: cn(
694
+ "mb-1 block w-full whitespace-normal rounded-md border-l-4 px-2 py-1 text-left text-xs font-normal",
695
+ outbound ? "border-white/70 bg-white/15" : "border-primary/60 bg-muted"
696
+ ),
697
+ children: /* @__PURE__ */ jsx("span", { className: "line-clamp-3 whitespace-pre-wrap opacity-80", children: q.body || "\u2026" })
698
+ }
699
+ );
700
+ }
701
+ function LinkPreview({ m, outbound }) {
702
+ const l = m.payload?.link;
703
+ if (!l || !l.title && !l.description) return null;
704
+ const body = /* @__PURE__ */ jsxs("span", { className: cn("mb-1 flex gap-2 overflow-hidden rounded-md", outbound ? "bg-white/15" : "bg-muted"), children: [
705
+ l.thumbnail && /* @__PURE__ */ jsx("img", { src: `data:image/jpeg;base64,${l.thumbnail}`, alt: "", className: "h-16 w-16 shrink-0 object-cover" }),
706
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 py-1.5 pr-2 pl-2", children: [
707
+ l.title && /* @__PURE__ */ jsx("span", { className: "line-clamp-1 block text-xs font-semibold", children: l.title }),
708
+ l.description && /* @__PURE__ */ jsx("span", { className: "line-clamp-2 block text-[11px] opacity-75", children: l.description })
709
+ ] })
710
+ ] });
711
+ return l.url ? /* @__PURE__ */ jsx("a", { href: l.url, target: "_blank", rel: "noreferrer", className: "block", children: body }) : body;
712
+ }
713
+ function ButtonRows({ m, outbound }) {
714
+ const buttons = m.payload?.buttons ?? [];
715
+ if (buttons.length === 0) return null;
716
+ const cls = cn(
717
+ "flex w-full items-center justify-center gap-1.5 border-t py-2 text-[13px] font-medium",
718
+ outbound ? "border-white/25 text-white" : "border-border text-[hsl(var(--info))]"
719
+ );
720
+ return /* @__PURE__ */ jsx("div", { className: "-mx-3.5 -mb-2 mt-1.5", children: buttons.map((b, i) => {
721
+ const label = b.text || b.url || b.phone || "\u2014";
722
+ if (b.url) {
723
+ return /* @__PURE__ */ jsxs("a", { href: b.url, target: "_blank", rel: "noreferrer", className: cls, children: [
724
+ /* @__PURE__ */ jsx(ExternalLink, { className: "h-3.5 w-3.5" }),
725
+ label
726
+ ] }, i);
727
+ }
728
+ if (b.phone) {
729
+ return /* @__PURE__ */ jsxs("a", { href: `tel:${b.phone}`, className: cls, children: [
730
+ /* @__PURE__ */ jsx(Phone, { className: "h-3.5 w-3.5" }),
731
+ label
732
+ ] }, i);
733
+ }
734
+ return /* @__PURE__ */ jsxs("span", { className: cls, children: [
735
+ /* @__PURE__ */ jsx(Reply, { className: "h-3.5 w-3.5" }),
736
+ label
737
+ ] }, i);
738
+ }) });
739
+ }
740
+ function PollCard({ m, outbound }) {
741
+ const t = useTranslation();
742
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
743
+ /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 font-medium", children: [
744
+ /* @__PURE__ */ jsx(BarChart3, { className: "h-4 w-4 shrink-0" }),
745
+ m.body
746
+ ] }),
747
+ (m.payload?.options ?? []).map((o, i) => /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2 rounded-md px-2 py-1.5 text-[13px]", outbound ? "bg-white/15" : "bg-muted"), children: [
748
+ /* @__PURE__ */ jsx("span", { className: cn("h-3.5 w-3.5 shrink-0 rounded-full border", outbound ? "border-white/70" : "border-muted-foreground/60") }),
749
+ o
750
+ ] }, i)),
751
+ /* @__PURE__ */ jsx("p", { className: "text-[11px] opacity-60", children: t("conversations.bubble.poll") })
752
+ ] });
753
+ }
754
+ function LocationCard({ m, outbound }) {
755
+ const t = useTranslation();
756
+ const p = m.payload ?? {};
757
+ const href = p.latitude != null && p.longitude != null ? `https://www.google.com/maps/search/?api=1&query=${p.latitude},${p.longitude}` : null;
758
+ return /* @__PURE__ */ jsxs(
759
+ "a",
760
+ {
761
+ href: href ?? void 0,
762
+ target: "_blank",
763
+ rel: "noreferrer",
764
+ className: cn("flex items-start gap-2.5 rounded-xl px-2.5 py-2", outbound ? "bg-white/15" : "bg-muted", href && "hover:opacity-90"),
765
+ children: [
766
+ /* @__PURE__ */ jsx(MapPin, { className: "mt-0.5 h-4 w-4 shrink-0" }),
767
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0", children: [
768
+ /* @__PURE__ */ jsx("span", { className: "block font-medium", children: p.name || t("conversations.preview.location") }),
769
+ p.address && /* @__PURE__ */ jsx("span", { className: "block text-xs opacity-75", children: p.address }),
770
+ href && /* @__PURE__ */ jsx("span", { className: "mt-0.5 block text-[11px] underline opacity-80", children: t("conversations.bubble.openMap") })
771
+ ] })
772
+ ]
773
+ }
774
+ );
775
+ }
776
+ function DeletedBody() {
777
+ const t = useTranslation();
778
+ return /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 italic opacity-70", children: [
779
+ /* @__PURE__ */ jsx(Ban, { className: "h-3.5 w-3.5" }),
780
+ " ",
781
+ t("conversations.bubble.deleted")
782
+ ] });
783
+ }
784
+ function Reactions({ m, outbound }) {
785
+ const r = m.payload?.reactions;
786
+ const list = [r?.contact, r?.me].filter(Boolean);
787
+ if (list.length === 0) return null;
788
+ return /* @__PURE__ */ jsx("span", { className: cn(
789
+ "absolute -bottom-3 flex items-center gap-0.5 rounded-full border border-border bg-card px-1.5 py-0.5 text-xs shadow-sm",
790
+ outbound ? "right-2" : "left-2"
791
+ ), children: list.map((e, i) => /* @__PURE__ */ jsx("span", { children: e }, i)) });
792
+ }
793
+ function EditedMark({ m }) {
794
+ const t = useTranslation();
795
+ if (!m.payload?.edited || m.payload?.deleted) return null;
796
+ return /* @__PURE__ */ jsx("span", { className: "italic", children: t("conversations.bubble.edited") });
797
+ }
798
+ function isFoldedRow(m) {
799
+ return m.messageType === "reaction" || m.messageType === "edit" || m.messageType === "revoke";
800
+ }
639
801
  function ContactCard({ contacts, outbound }) {
640
802
  const [copied, setCopied] = React9__default.useState(null);
641
803
  const copy = (value) => {
@@ -679,10 +841,14 @@ function ContactCard({ contacts, outbound }) {
679
841
  )) });
680
842
  }
681
843
  function MessageBody({ m, outbound }) {
844
+ if (m.payload?.deleted) return /* @__PURE__ */ jsx(DeletedBody, {});
845
+ if (m.messageType === "poll") return /* @__PURE__ */ jsx(PollCard, { m, outbound });
846
+ if (m.messageType === "location") return /* @__PURE__ */ jsx(LocationCard, { m, outbound });
682
847
  const contacts = m.messageType === "contact" ? m.payload?.contacts ?? [] : [];
683
848
  if (contacts.length > 0) return /* @__PURE__ */ jsx(ContactCard, { contacts, outbound });
684
849
  if (temArquivo(m)) return /* @__PURE__ */ jsx(MediaBubble, { m, outbound });
685
- return /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: m.body });
850
+ if (mediaPreviewKind(m.body)) return /* @__PURE__ */ jsx("p", { className: "opacity-80", children: /* @__PURE__ */ jsx(MessagePreview, { text: m.body }) });
851
+ return /* @__PURE__ */ jsx(RichText, { text: m.body, outbound });
686
852
  }
687
853
  function buildRows(messages) {
688
854
  const rows = [];
@@ -740,7 +906,14 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
740
906
  await send(body);
741
907
  }
742
908
  const accent = CHANNEL_ACCENT[selected.channel];
743
- const rows = React9__default.useMemo(() => buildRows(messages), [messages]);
909
+ const rows = React9__default.useMemo(() => buildRows(messages.filter((m) => !isFoldedRow(m))), [messages]);
910
+ const jumpTo = React9__default.useCallback((providerId) => {
911
+ const el = threadRef.current?.querySelector(`[data-provider-id="${CSS.escape(providerId)}"]`);
912
+ if (!el) return;
913
+ el.scrollIntoView({ behavior: "smooth", block: "center" });
914
+ el.classList.add("ring-2", "ring-primary");
915
+ window.setTimeout(() => el.classList.remove("ring-2", "ring-primary"), 1200);
916
+ }, []);
744
917
  return /* @__PURE__ */ jsxs("section", { className: cn("flex min-w-0 flex-1 flex-col bg-muted/20", className), children: [
745
918
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-border bg-card px-3 py-2.5 md:px-5", children: [
746
919
  /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2 md:gap-3", children: [
@@ -789,8 +962,10 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
789
962
  /* @__PURE__ */ jsxs(
790
963
  "div",
791
964
  {
965
+ "data-provider-id": m.providerMessageId ?? void 0,
792
966
  className: cn(
793
- "max-w-[68%] px-3.5 py-2 text-sm shadow-sm",
967
+ "relative max-w-[68%] px-3.5 py-2 text-sm shadow-sm transition-shadow",
968
+ (m.payload?.reactions?.contact || m.payload?.reactions?.me) && "mb-3",
794
969
  outbound ? "rounded-2xl text-white" : "rounded-2xl bg-card text-foreground",
795
970
  // Tail only on the last bubble of a run, on the sender's side.
796
971
  outbound && row.endsRun && "rounded-br-sm",
@@ -802,11 +977,17 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
802
977
  ),
803
978
  style: outbound ? { backgroundColor: failed ? "hsl(var(--destructive))" : accent.color } : void 0,
804
979
  children: [
980
+ /* @__PURE__ */ jsx(ForwardedLabel, { m }),
981
+ /* @__PURE__ */ jsx(QuotedBlock, { m, outbound, onJump: jumpTo }),
982
+ !m.payload?.deleted && /* @__PURE__ */ jsx(LinkPreview, { m, outbound }),
805
983
  /* @__PURE__ */ jsx(MessageBody, { m, outbound }),
806
984
  /* @__PURE__ */ jsxs("div", { className: cn("mt-0.5 flex items-center justify-end gap-1 text-[10px]", outbound ? "text-white/70" : "text-muted-foreground"), children: [
985
+ /* @__PURE__ */ jsx(EditedMark, { m }),
807
986
  new Date(m.at).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
808
987
  /* @__PURE__ */ jsx(DeliveryMark, { m })
809
- ] })
988
+ ] }),
989
+ !m.payload?.deleted && /* @__PURE__ */ jsx(ButtonRows, { m, outbound }),
990
+ /* @__PURE__ */ jsx(Reactions, { m, outbound })
810
991
  ]
811
992
  }
812
993
  ),
@@ -1269,5 +1450,5 @@ function ConversationsPage({ store, config }) {
1269
1450
  }
1270
1451
 
1271
1452
  export { ConversationsPage };
1272
- //# sourceMappingURL=ConversationsPage-I47C36I5.js.map
1273
- //# sourceMappingURL=ConversationsPage-I47C36I5.js.map
1453
+ //# sourceMappingURL=ConversationsPage-7W7LDH2H.js.map
1454
+ //# sourceMappingURL=ConversationsPage-7W7LDH2H.js.map