@sevenfold/setto-client 0.22.3 → 0.23.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.
@@ -22094,6 +22094,34 @@ function SettoChat() {
22094
22094
  useEffect(() => {
22095
22095
  if (open) logRef.current?.scrollTo({ top: logRef.current.scrollHeight });
22096
22096
  }, [messages, open]);
22097
+ useEffect(() => {
22098
+ if (!open || !conversationId.current || !visitor.current || sending) return;
22099
+ let cancelled = false;
22100
+ const refresh = async () => {
22101
+ try {
22102
+ const query = new URLSearchParams({ visitorId: visitor.current });
22103
+ const response = await fetch(
22104
+ `${apiUrl}/sites/${encodeURIComponent(config.siteId)}/chat/conversations/${encodeURIComponent(conversationId.current)}/public?${query}`,
22105
+ { headers: { Accept: "application/json" } }
22106
+ );
22107
+ if (!response.ok) return;
22108
+ const next = await response.json();
22109
+ if (cancelled) return;
22110
+ const serverMessages = next.messages.map(({ role, content }) => ({ role, content }));
22111
+ setMessages((previous) => {
22112
+ const greeting = previous[0]?.role === "assistant" && !serverMessages.some((message) => message.content === previous[0]?.content) ? [previous[0]] : [];
22113
+ return [...greeting, ...serverMessages];
22114
+ });
22115
+ } catch {
22116
+ }
22117
+ };
22118
+ void refresh();
22119
+ const timer = window.setInterval(() => void refresh(), 5e3);
22120
+ return () => {
22121
+ cancelled = true;
22122
+ window.clearInterval(timer);
22123
+ };
22124
+ }, [apiUrl, config.siteId, open, sending]);
22097
22125
  if (!settings || window.location.pathname.startsWith("/setto")) return null;
22098
22126
  const locale = i18n.language || "no";
22099
22127
  const siteName = settings.displayName?.trim() || null;
@@ -22231,7 +22259,10 @@ function SettoChat() {
22231
22259
  ] }),
22232
22260
  /* @__PURE__ */ jsx("button", { className: "setto-chat__close", type: "button", onClick: () => setOpen(false), "aria-label": labels.close, children: "×" })
22233
22261
  ] }),
22234
- /* @__PURE__ */ jsx("div", { className: "setto-chat__log", ref: logRef, "aria-live": "polite", children: messages.map((item, index) => /* @__PURE__ */ jsx("div", { className: `setto-chat__message setto-chat__message--${item.role}`, children: item.content || /* @__PURE__ */ jsx("span", { className: "setto-chat__typing", children: "···" }) }, `${item.role}-${index}`)) }),
22262
+ /* @__PURE__ */ jsx("div", { className: "setto-chat__log", ref: logRef, "aria-live": "polite", children: messages.map((item, index) => /* @__PURE__ */ jsxs("div", { className: `setto-chat__message setto-chat__message--${item.role}`, children: [
22263
+ item.role === "human" ? /* @__PURE__ */ jsx("span", { className: "setto-chat__speaker", children: "Teamet" }) : null,
22264
+ item.content || /* @__PURE__ */ jsx("span", { className: "setto-chat__typing", children: "···" })
22265
+ ] }, `${item.role}-${index}`)) }),
22235
22266
  /* @__PURE__ */ jsxs("div", { className: "setto-chat__contact", children: [
22236
22267
  /* @__PURE__ */ jsxs("button", { type: "button", onClick: contactTeam, children: [
22237
22268
  labels.contact,
@@ -22334,6 +22365,9 @@ function useChatStyles() {
22334
22365
  .setto-chat__message { max-width: 88%; padding: 11px 13px; border-radius: 14px; font-size: 14px; line-height: 1.48; white-space: pre-wrap; overflow-wrap: anywhere; }
22335
22366
  .setto-chat__message--assistant { align-self: flex-start; background: #efe7da; color: #302820; border-bottom-left-radius: 3px; }
22336
22367
  .setto-chat__message--visitor { align-self: flex-end; background: #2b221b; color: #fffaf1; border-bottom-right-radius: 3px; }
22368
+ .setto-chat__message--human { align-self: flex-start; background: #f5d3c7; color: #48261d; border-bottom-left-radius: 3px; }
22369
+ .setto-chat__message--system { align-self: center; max-width: 100%; padding: 2px 8px; background: transparent; color: #817568; font-size: 11px; text-align: center; }
22370
+ .setto-chat__speaker { display: block; margin-bottom: 3px; color: #a13e24; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
22337
22371
  .setto-chat__typing { display: inline-block; min-width: 24px; animation: setto-chat-pulse 1.1s ease-in-out infinite; letter-spacing: 2px; }
22338
22372
  @keyframes setto-chat-pulse { 50% { opacity: .3; } }
22339
22373
  .setto-chat__contact { padding: 0 18px 12px; display: flex; gap: 14px; flex-wrap: wrap; }