@sevenfold/setto-client 0.40.0 → 0.41.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.
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from 'react';
1
2
  import { type MessageTranslation } from './translation-caption.js';
2
3
  type Attachment = {
3
4
  id: string;
@@ -14,7 +15,7 @@ type Message = {
14
15
  avatarUrl?: string | null;
15
16
  authorName?: string | null;
16
17
  attachments?: Attachment[];
17
- kind?: 'message' | 'navigation' | 'agent_joined';
18
+ kind?: 'message' | 'navigation' | 'agent_joined' | 'agent_requested';
18
19
  action?: {
19
20
  type: 'navigate';
20
21
  url: string;
@@ -26,6 +27,20 @@ type Message = {
26
27
  */
27
28
  translation?: MessageTranslation | null;
28
29
  };
30
+ /**
31
+ * Someone from the team near the chat: checked in, and in Setto recently.
32
+ * `online` means right now. The handle is opaque; it is what a tap sends.
33
+ */
34
+ export type NearbyHuman = {
35
+ handle: string;
36
+ name: string | null;
37
+ avatarUrl: string | null;
38
+ online: boolean;
39
+ greeting?: {
40
+ no?: string | null;
41
+ en?: string | null;
42
+ } | null;
43
+ };
29
44
  /** The browser's language for the server's translation, within its 35-character limit. */
30
45
  export declare function browserLanguage(): string | undefined;
31
46
  export type ShownMessage = {
@@ -47,6 +62,33 @@ export declare function nextWordBoundary(content: string, visibleLength: number)
47
62
  export declare function sineOut(progress: number): number;
48
63
  export declare function isAtChatBottom(scrollHeight: number, scrollTop: number, clientHeight: number): boolean;
49
64
  export declare function chatComposerSpace(height: number): number;
65
+ /**
66
+ * The opening line from the teammate whose face is on the chat button: their
67
+ * own, or this. Mirrors setto-server's back office (`defaultGreeting`).
68
+ */
69
+ export declare function humanIntro(locale: string, human: Pick<NearbyHuman, 'name' | 'greeting'>, agent?: string): string;
70
+ /**
71
+ * Whether the team row needs «Snakk med et menneske» above the faces. Not for
72
+ * one person who is online: their greeting already says to tap their picture.
73
+ */
74
+ export declare function teamRowLabelled(humans: readonly Pick<NearbyHuman, 'online'>[]): boolean;
75
+ /** `@Name` as a whole word, any case, as setto-server reads it. */
76
+ export declare function mentionsName(content: string, name: string): boolean;
77
+ /** The handles a turn asks for: every named person @-mentioned, and every face tapped. */
78
+ export declare function mentionedHandles(content: string, humans: NearbyHuman[], tapped: ReadonlySet<string>): string[];
79
+ /** An `@` being typed just before the caret, and what follows it so far. */
80
+ export declare function mentionQuery(value: string, caret: number): {
81
+ start: number;
82
+ query: string;
83
+ } | null;
84
+ /** Puts `@Name ` where the `@` was typed, or at the end; returns the caret after it. */
85
+ export declare function insertMention(value: string, name: string, at: {
86
+ start: number;
87
+ end: number;
88
+ } | null): {
89
+ value: string;
90
+ caret: number;
91
+ };
50
92
  /**
51
93
  * «Translated from English · Show original» under a translated message, in
52
94
  * the visitor's language. The toggle is a real button; the line is left out
@@ -57,10 +99,13 @@ export declare function TranslationNote({ translation, showingOriginal, onToggle
57
99
  showingOriginal: boolean;
58
100
  onToggle: () => void;
59
101
  }): import("react/jsx-runtime").JSX.Element;
60
- export declare function AgentJoinedEvent({ message, originals, onToggleOriginal, }: {
102
+ /**
103
+ * «Kari har blitt med i samtalen.» and «Kari har fått beskjed.»: shown in the
104
+ * visitor's language, without «Show original». A notice is Setto's own line,
105
+ * not something a person wrote, so there is no original worth reading.
106
+ */
107
+ export declare function AgentJoinedEvent({ message }: {
61
108
  message: Message;
62
- originals?: ReadonlySet<string>;
63
- onToggleOriginal?: (id: string) => void;
64
109
  }): import("react/jsx-runtime").JSX.Element;
65
110
  /**
66
111
  * A teammate is composing. The row opts out of the transcript's polite live
@@ -79,6 +124,16 @@ export declare function SiteChatMarkdown({ content, reveal }: {
79
124
  content: string;
80
125
  reveal?: boolean;
81
126
  }): import("react/jsx-runtime").JSX.Element;
127
+ /** Someone the @ list offers: the assistant, or a person near the chat. */
128
+ export type Mentionable = {
129
+ key: string;
130
+ name: string;
131
+ /** «AI-assistent», «Tilgjengelig nå» … */
132
+ detail: string;
133
+ avatar: ReactNode;
134
+ /** People only: green when online now. */
135
+ online?: boolean;
136
+ };
82
137
  /** Responsive visitor conversation. Its drawer only contains this browser's site chats. */
83
138
  export declare function SettoChat(): import("react/jsx-runtime").JSX.Element | null;
84
139
  export {};
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { useState, useRef, useEffect, useMemo, useId, useInsertionEffect, Children, createContext, useContext, useCallback, useLayoutEffect, useSyncExternalStore, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import { useState, useRef, useEffect, useMemo, useId, useInsertionEffect, useLayoutEffect, Children, createContext, useContext, useCallback, useSyncExternalStore, forwardRef, Fragment as Fragment$1 } from "react";
4
4
  import { useTranslation } from "react-i18next";
5
5
  import * as ReactDOM from "react-dom";
6
6
  import { createPortal } from "react-dom";
@@ -35503,6 +35503,39 @@ function norwegian(locale) {
35503
35503
  function intro(locale, name2, agent = "Barista") {
35504
35504
  return norwegian(locale) ? `Hei! Jeg er ${agent}, ${name2 ? `${name2}s` : "nettstedets"} AI-assistent. Jeg svarer ut fra det teamet har delt her, og hjelper deg videre til dem når det trengs.` : `Hello! I’m ${agent}, the AI assistant for ${name2 ?? "this website"}. I answer from what the team has shared here and help you reach them when needed.`;
35505
35505
  }
35506
+ function humanIntro(locale, human, agent = "Barista") {
35507
+ const own2 = (norwegian(locale) ? human.greeting?.no : human.greeting?.en)?.trim();
35508
+ if (own2) return own2;
35509
+ const name2 = human.name ?? "";
35510
+ return norwegian(locale) ? `Hei, jeg heter ${name2}! ${agent} svarer deg med en gang, og vil du heller snakke med meg, skriver du @${name2} eller trykker på bildet mitt.` : `Hi, my name is ${name2}! ${agent} will answer you right away. If you would rather talk to me, type @${name2} or tap my picture.`;
35511
+ }
35512
+ function teamRowLabelled(humans) {
35513
+ return !(humans.length === 1 && humans[0].online);
35514
+ }
35515
+ function escapeRegExp$1(value) {
35516
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
35517
+ }
35518
+ function mentionsName(content2, name2) {
35519
+ return new RegExp(`(^|[^\\p{L}\\p{N}_@])@${escapeRegExp$1(name2)}(?![\\p{L}\\p{N}_])`, "iu").test(content2);
35520
+ }
35521
+ function mentionedHandles(content2, humans, tapped) {
35522
+ return humans.filter((human) => tapped.has(human.handle) || human.name !== null && mentionsName(content2, human.name)).map((human) => human.handle).slice(0, 3);
35523
+ }
35524
+ function mentionQuery(value, caret) {
35525
+ const match = value.slice(0, caret).match(/(^|[^\p{L}\p{N}_@])@([\p{L}\p{N}_-]{0,30})$/u);
35526
+ if (!match) return null;
35527
+ return { start: caret - match[2].length - 1, query: match[2] };
35528
+ }
35529
+ function insertMention(value, name2, at2) {
35530
+ const mention = `@${name2} `;
35531
+ if (at2) {
35532
+ const next = value.slice(0, at2.start) + mention + value.slice(at2.end).replace(/^ /, "");
35533
+ return { value: next, caret: at2.start + mention.length };
35534
+ }
35535
+ if (mentionsName(value, name2)) return { value, caret: value.length };
35536
+ const before = value && !/\s$/.test(value) ? `${value} ` : value;
35537
+ return { value: before + mention, caret: before.length + mention.length };
35538
+ }
35506
35539
  function MenuIcon() {
35507
35540
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "22", height: "22", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
35508
35541
  "path",
@@ -35591,12 +35624,8 @@ function TranslationNote({
35591
35624
  ] });
35592
35625
  }
35593
35626
  const NO_ORIGINALS = /* @__PURE__ */ new Set();
35594
- function AgentJoinedEvent({
35595
- message,
35596
- originals = NO_ORIGINALS,
35597
- onToggleOriginal
35598
- }) {
35599
- const shown = shownMessage(message, originals);
35627
+ function AgentJoinedEvent({ message }) {
35628
+ const shown = shownMessage(message, NO_ORIGINALS);
35600
35629
  return /* @__PURE__ */ jsxs("div", { className: "setto-chat__message setto-chat__message--system setto-chat__message--agent-joined", children: [
35601
35630
  /* @__PURE__ */ jsx(
35602
35631
  "span",
@@ -35606,17 +35635,7 @@ function AgentJoinedEvent({
35606
35635
  children: message.avatarUrl ? /* @__PURE__ */ jsx("img", { src: message.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx(PersonIcon, {})
35607
35636
  }
35608
35637
  ),
35609
- /* @__PURE__ */ jsxs("div", { className: "setto-chat__message-stack", children: [
35610
- /* @__PURE__ */ jsx("div", { className: "setto-chat__message-bubble", children: /* @__PURE__ */ jsx("span", { className: "setto-chat__message-copy", lang: shown.lang, children: shown.content }) }),
35611
- shown.translation && message.id && onToggleOriginal ? /* @__PURE__ */ jsx(
35612
- TranslationNote,
35613
- {
35614
- translation: shown.translation,
35615
- showingOriginal: shown.showingOriginal,
35616
- onToggle: () => onToggleOriginal(message.id)
35617
- }
35618
- ) : null
35619
- ] })
35638
+ /* @__PURE__ */ jsx("div", { className: "setto-chat__message-stack", children: /* @__PURE__ */ jsx("div", { className: "setto-chat__message-bubble", children: /* @__PURE__ */ jsx("span", { className: "setto-chat__message-copy", lang: shown.lang, children: shown.content }) }) })
35620
35639
  ] });
35621
35640
  }
35622
35641
  function TeamTypingRow({ label, avatarUrl }) {
@@ -35678,6 +35697,9 @@ function SiteChatMarkdown({ content: content2, reveal = false }) {
35678
35697
  function SiteChatComposer({
35679
35698
  value,
35680
35699
  onChange,
35700
+ mentionables,
35701
+ mentionLabel,
35702
+ focusRequest,
35681
35703
  onSubmit,
35682
35704
  onBlur,
35683
35705
  busy,
@@ -35693,6 +35715,44 @@ function SiteChatComposer({
35693
35715
  }) {
35694
35716
  const textareaRef = useRef(null);
35695
35717
  const fileRef = useRef(null);
35718
+ const [mention, setMention] = useState(null);
35719
+ const [active, setActive] = useState(0);
35720
+ const caretRef = useRef(null);
35721
+ const listId = useId();
35722
+ const options = mention ? mentionables.filter((option) => option.name.toLocaleLowerCase().startsWith(mention.query.toLocaleLowerCase())) : [];
35723
+ const open = options.length > 0;
35724
+ function track(textarea) {
35725
+ setMention(mentionQuery(textarea.value, textarea.selectionStart ?? textarea.value.length));
35726
+ }
35727
+ function choose(option) {
35728
+ const textarea = textareaRef.current;
35729
+ if (!mention || !textarea) return;
35730
+ const next = insertMention(value, option.name, {
35731
+ start: mention.start,
35732
+ end: textarea.selectionStart ?? value.length
35733
+ });
35734
+ caretRef.current = next.caret;
35735
+ onChange(next.value);
35736
+ setMention(null);
35737
+ }
35738
+ useLayoutEffect(() => {
35739
+ const caret = caretRef.current;
35740
+ const textarea = textareaRef.current;
35741
+ if (caret === null || !textarea) return;
35742
+ caretRef.current = null;
35743
+ textarea.focus({ preventScroll: true });
35744
+ textarea.setSelectionRange(caret, caret);
35745
+ }, [value]);
35746
+ useEffect(() => {
35747
+ if (!focusRequest) return;
35748
+ const textarea = textareaRef.current;
35749
+ if (!textarea) return;
35750
+ const frame = window.requestAnimationFrame(() => {
35751
+ textarea.focus({ preventScroll: true });
35752
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
35753
+ });
35754
+ return () => window.cancelAnimationFrame(frame);
35755
+ }, [focusRequest]);
35696
35756
  useEffect(() => {
35697
35757
  const textarea = textareaRef.current;
35698
35758
  if (!textarea) return;
@@ -35719,6 +35779,25 @@ function SiteChatComposer({
35719
35779
  send();
35720
35780
  }
35721
35781
  function handleKeyDown(event) {
35782
+ if (open) {
35783
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
35784
+ event.preventDefault();
35785
+ const step = event.key === "ArrowDown" ? 1 : -1;
35786
+ setActive((current) => (current + step + options.length) % options.length);
35787
+ return;
35788
+ }
35789
+ if (event.key === "Enter" || event.key === "Tab") {
35790
+ event.preventDefault();
35791
+ choose(options[Math.min(active, options.length - 1)]);
35792
+ return;
35793
+ }
35794
+ if (event.key === "Escape") {
35795
+ event.preventDefault();
35796
+ event.stopPropagation();
35797
+ setMention(null);
35798
+ return;
35799
+ }
35800
+ }
35722
35801
  if (event.key === "Enter" && !event.shiftKey) {
35723
35802
  event.preventDefault();
35724
35803
  send();
@@ -35748,6 +35827,27 @@ function SiteChatComposer({
35748
35827
  }
35749
35828
  )
35750
35829
  ] }, `${attachment.file.name}-${attachment.preview}`)) }) : null,
35830
+ open ? /* @__PURE__ */ jsx("ul", { className: "setto-chat__mentions", role: "listbox", id: listId, "aria-label": mentionLabel, children: options.map((option, index2) => /* @__PURE__ */ jsxs(
35831
+ "li",
35832
+ {
35833
+ id: `${listId}-${index2}`,
35834
+ role: "option",
35835
+ "aria-selected": index2 === active,
35836
+ className: index2 === active ? "is-active" : void 0,
35837
+ onMouseDown: (event) => event.preventDefault(),
35838
+ onMouseEnter: () => setActive(index2),
35839
+ onClick: () => choose(option),
35840
+ children: [
35841
+ /* @__PURE__ */ jsxs("span", { className: "setto-chat__face", children: [
35842
+ option.avatar,
35843
+ option.online !== void 0 ? /* @__PURE__ */ jsx("i", { className: `setto-chat__presence${option.online ? " is-online" : ""}`, "aria-hidden": "true" }) : null
35844
+ ] }),
35845
+ /* @__PURE__ */ jsx("span", { className: "setto-chat__mention-name", children: option.name }),
35846
+ /* @__PURE__ */ jsx("span", { className: "setto-chat__mention-detail", children: option.detail })
35847
+ ]
35848
+ },
35849
+ option.key
35850
+ )) }) : null,
35751
35851
  /* @__PURE__ */ jsx(
35752
35852
  "textarea",
35753
35853
  {
@@ -35755,9 +35855,21 @@ function SiteChatComposer({
35755
35855
  lang: norwegian(locale) ? "nb" : "en",
35756
35856
  spellCheck: true,
35757
35857
  value,
35758
- onChange: (event) => onChange(event.target.value),
35858
+ "aria-autocomplete": mentionables.length ? "list" : void 0,
35859
+ "aria-controls": open ? listId : void 0,
35860
+ "aria-expanded": mentionables.length ? open : void 0,
35861
+ "aria-activedescendant": open ? `${listId}-${Math.min(active, options.length - 1)}` : void 0,
35862
+ onChange: (event) => {
35863
+ onChange(event.target.value);
35864
+ track(event.target);
35865
+ setActive(0);
35866
+ },
35867
+ onSelect: (event) => track(event.currentTarget),
35759
35868
  onKeyDown: handleKeyDown,
35760
- onBlur: () => onBlur?.(),
35869
+ onBlur: () => {
35870
+ setMention(null);
35871
+ onBlur?.();
35872
+ },
35761
35873
  placeholder,
35762
35874
  rows: 1,
35763
35875
  maxLength: 1500
@@ -36129,6 +36241,8 @@ function SettoChat() {
36129
36241
  humanAvailable: false,
36130
36242
  avatarUrl: null
36131
36243
  });
36244
+ const [tapped, setTapped] = useState(() => /* @__PURE__ */ new Set());
36245
+ const [focusRequest, setFocusRequest] = useState(0);
36132
36246
  const conversationId = useRef(storedActiveConversation(config.siteId));
36133
36247
  const visitor = useRef(null);
36134
36248
  const chatRef = useRef(null);
@@ -36195,6 +36309,8 @@ function SettoChat() {
36195
36309
  const siteName = settings?.displayName?.trim() || config.displayName?.trim() || null;
36196
36310
  const agentName = settings?.agentName?.trim() || "Barista";
36197
36311
  const agentAvatarUrl = settings?.agentAvatarUrl ?? null;
36312
+ const nearby = availability.humans ?? [];
36313
+ const greeter = availability.humanAvailable ? nearby.find((human) => human.online && human.name) ?? null : null;
36198
36314
  const labels = isNo ? {
36199
36315
  open: siteName ? `Åpne chat med ${siteName}` : "Åpne chat",
36200
36316
  close: "Lukk chatten",
@@ -36203,7 +36319,14 @@ function SettoChat() {
36203
36319
  chats: "Chats",
36204
36320
  newChat: "Ny chat",
36205
36321
  placeholder: "Hva vil du spørre om?",
36206
- humanPlaceholder: `Skriv til teamet · bruk @barista for ${agentName}`,
36322
+ humanPlaceholder: `Skriv til teamet · bruk @${agentName} for ${agentName}`,
36323
+ teamPlaceholder: `Spør ${agentName}, eller skriv @ for å nå teamet`,
36324
+ teamRow: "Snakk med et menneske",
36325
+ mentions: "Hvem vil du spørre?",
36326
+ online: "Tilgjengelig nå",
36327
+ nearby: "I nærheten",
36328
+ askFor: (name2, online) => `Spør etter ${name2} (${online ? "tilgjengelig nå" : "i nærheten"})`,
36329
+ someone: "Teamet",
36207
36330
  send: "Send melding",
36208
36331
  sending: "Svarer …",
36209
36332
  attach: "Legg ved bilde",
@@ -36221,7 +36344,14 @@ function SettoChat() {
36221
36344
  chats: "Chats",
36222
36345
  newChat: "New chat",
36223
36346
  placeholder: "What would you like to ask?",
36224
- humanPlaceholder: `Message the team · use @barista for ${agentName}`,
36347
+ humanPlaceholder: `Message the team · use @${agentName} for ${agentName}`,
36348
+ teamPlaceholder: `Ask ${agentName}, or type @ to reach the team`,
36349
+ teamRow: "Talk to a person",
36350
+ mentions: "Who would you like to ask?",
36351
+ online: "Available now",
36352
+ nearby: "Nearby",
36353
+ askFor: (name2, online) => `Ask for ${name2} (${online ? "available now" : "nearby"})`,
36354
+ someone: "The team",
36225
36355
  send: "Send message",
36226
36356
  sending: "Replying …",
36227
36357
  attach: "Attach image",
@@ -36235,6 +36365,27 @@ function SettoChat() {
36235
36365
  function ensureVisitor() {
36236
36366
  return visitor.current ??= visitorId();
36237
36367
  }
36368
+ function welcomeMessage() {
36369
+ if (greeter) {
36370
+ return {
36371
+ role: "human",
36372
+ content: humanIntro(locale, greeter, agentName),
36373
+ authorName: greeter.name,
36374
+ avatarUrl: greeter.avatarUrl
36375
+ };
36376
+ }
36377
+ const own2 = (norwegian(locale) ? settings?.welcome?.no : settings?.welcome?.en)?.trim();
36378
+ return { role: "assistant", content: own2 || intro(locale, settings?.displayName ?? void 0, agentName) };
36379
+ }
36380
+ function pickHuman(human) {
36381
+ setTapped((current) => new Set(current).add(human.handle));
36382
+ if (human.name) {
36383
+ const next = insertMention(draft, human.name, null).value;
36384
+ setDraft(next);
36385
+ typingSender().update(next);
36386
+ }
36387
+ setFocusRequest((current) => current + 1);
36388
+ }
36238
36389
  function rememberConversation(id) {
36239
36390
  conversationId.current = id;
36240
36391
  try {
@@ -36375,19 +36526,20 @@ function SettoChat() {
36375
36526
  cancelled = true;
36376
36527
  window.clearInterval(timer);
36377
36528
  };
36378
- }, [apiUrl, config.siteId, settings]);
36529
+ }, [apiUrl, config.siteId, settings, mounted]);
36530
+ const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
36379
36531
  useEffect(() => {
36380
36532
  if (!mounted || !settings || conversationId.current) return;
36381
- const own2 = (norwegian(locale) ? settings.welcome?.no : settings.welcome?.en)?.trim();
36382
- const welcome = own2 || intro(locale, settings.displayName ?? void 0, settings.agentName?.trim() || void 0);
36533
+ const welcome = welcomeMessage();
36383
36534
  setMessages((current) => {
36384
- if (current.length === 0) return [{ role: "assistant", content: welcome }];
36385
- if (current.length === 1 && current[0]?.role === "assistant" && !current[0].id) {
36386
- return current[0].content === welcome ? current : [{ role: "assistant", content: welcome }];
36535
+ if (current.length === 0) return [welcome];
36536
+ const only = current[0];
36537
+ if (current.length === 1 && only && !only.id && (only.role === "assistant" || only.role === "human")) {
36538
+ return only.role === welcome.role && only.content === welcome.content && only.avatarUrl === welcome.avatarUrl ? current : [welcome];
36387
36539
  }
36388
36540
  return current;
36389
36541
  });
36390
- }, [mounted, settings, locale]);
36542
+ }, [mounted, settings, locale, greeterKey]);
36391
36543
  useEffect(() => {
36392
36544
  filesRef.current = files;
36393
36545
  }, [files]);
@@ -36524,8 +36676,9 @@ function SettoChat() {
36524
36676
  setRealtime(null);
36525
36677
  setTeamTypingUntil(null);
36526
36678
  setHumanJoined(false);
36527
- setMessages([{ role: "assistant", content: intro(locale, settings?.displayName ?? void 0, agentName) }]);
36679
+ setMessages([welcomeMessage()]);
36528
36680
  setDraft("");
36681
+ setTapped(/* @__PURE__ */ new Set());
36529
36682
  setQueued(false);
36530
36683
  setDrawer(false);
36531
36684
  clearPendingFiles();
@@ -36557,12 +36710,14 @@ function SettoChat() {
36557
36710
  const content2 = draft.trim();
36558
36711
  const turnFiles = files;
36559
36712
  if (!content2 && turnFiles.length === 0) return;
36713
+ const mentions = mentionedHandles(content2, nearby, tapped);
36560
36714
  turnRef.current.busy = true;
36561
36715
  turnRef.current.generation += 1;
36562
36716
  typingSender().stop();
36563
36717
  pinToBottomRef.current = true;
36564
36718
  setDraft("");
36565
36719
  setFiles([]);
36720
+ setTapped(/* @__PURE__ */ new Set());
36566
36721
  setSending(true);
36567
36722
  const visitorIdValue = ensureVisitor();
36568
36723
  let revealer = null;
@@ -36608,7 +36763,8 @@ function SettoChat() {
36608
36763
  language: browserLanguage(),
36609
36764
  page: window.location.href,
36610
36765
  message: content2 || void 0,
36611
- attachmentIds: uploaded.map((attachment) => attachment.id)
36766
+ attachmentIds: uploaded.map((attachment) => attachment.id),
36767
+ ...mentions.length ? { mentions } : {}
36612
36768
  })
36613
36769
  }
36614
36770
  );
@@ -36619,6 +36775,7 @@ function SettoChat() {
36619
36775
  const body = await response.json();
36620
36776
  if (body.conversationId) rememberConversation(body.conversationId);
36621
36777
  if (body.humanJoined) setHumanJoined(true);
36778
+ if (body.requested) pendingRefreshRef.current = true;
36622
36779
  if (body.silent) {
36623
36780
  revealer.cancel();
36624
36781
  setMessages((previous2) => removeLastEmptyAssistant(previous2));
@@ -36759,13 +36916,11 @@ function SettoChat() {
36759
36916
  "aria-busy": loadingConversation,
36760
36917
  children: /* @__PURE__ */ jsxs("div", { className: "setto-chat__message-list", children: [
36761
36918
  messages.map((item, index2) => {
36762
- if (item.role === "system" && item.kind === "agent_joined") {
36919
+ if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested")) {
36763
36920
  return /* @__PURE__ */ jsx(
36764
36921
  AgentJoinedEvent,
36765
36922
  {
36766
- message: item,
36767
- originals,
36768
- onToggleOriginal: toggleOriginal
36923
+ message: item
36769
36924
  },
36770
36925
  item.id ?? `agent-joined-${index2}`
36771
36926
  );
@@ -36826,6 +36981,28 @@ function SettoChat() {
36826
36981
  }
36827
36982
  ),
36828
36983
  /* @__PURE__ */ jsxs("div", { className: "setto-chat__composer-shell", ref: composerShellRef, children: [
36984
+ nearby.length ? /* @__PURE__ */ jsxs("div", { className: "setto-chat__team", children: [
36985
+ teamRowLabelled(nearby) ? /* @__PURE__ */ jsx("span", { className: "setto-chat__team-label", children: labels.teamRow }) : null,
36986
+ nearby.map((human) => /* @__PURE__ */ jsxs(
36987
+ "button",
36988
+ {
36989
+ type: "button",
36990
+ className: `setto-chat__person${tapped.has(human.handle) ? " is-picked" : ""}`,
36991
+ onClick: () => pickHuman(human),
36992
+ "aria-label": labels.askFor(human.name ?? labels.someone, human.online),
36993
+ "aria-pressed": tapped.has(human.handle),
36994
+ title: labels.askFor(human.name ?? labels.someone, human.online),
36995
+ children: [
36996
+ /* @__PURE__ */ jsxs("span", { className: "setto-chat__face", children: [
36997
+ human.avatarUrl ? /* @__PURE__ */ jsx("img", { src: human.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx(PersonIcon, {}),
36998
+ /* @__PURE__ */ jsx("i", { className: `setto-chat__presence${human.online ? " is-online" : ""}`, "aria-hidden": "true" })
36999
+ ] }),
37000
+ /* @__PURE__ */ jsx("span", { children: human.name ?? labels.someone })
37001
+ ]
37002
+ },
37003
+ human.handle
37004
+ ))
37005
+ ] }) : null,
36829
37006
  /* @__PURE__ */ jsx(
36830
37007
  SiteChatComposer,
36831
37008
  {
@@ -36834,11 +37011,28 @@ function SettoChat() {
36834
37011
  setDraft(value);
36835
37012
  typingSender().update(value);
36836
37013
  },
37014
+ mentionables: [
37015
+ {
37016
+ key: "agent",
37017
+ name: agentName,
37018
+ detail: labels.ai,
37019
+ avatar: /* @__PURE__ */ jsx("span", { className: "setto-chat__face-agent", children: /* @__PURE__ */ jsx(AgentAvatar, { url: agentAvatarUrl }) })
37020
+ },
37021
+ ...nearby.filter((human) => human.name).map((human) => ({
37022
+ key: human.handle,
37023
+ name: human.name,
37024
+ detail: human.online ? labels.online : labels.nearby,
37025
+ avatar: human.avatarUrl ? /* @__PURE__ */ jsx("img", { src: human.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx(PersonIcon, {}),
37026
+ online: human.online
37027
+ }))
37028
+ ],
37029
+ mentionLabel: labels.mentions,
37030
+ focusRequest,
36837
37031
  onSubmit: queueOrSend,
36838
37032
  onBlur: () => typingSender().stop(),
36839
37033
  busy: sending,
36840
37034
  queued,
36841
- placeholder: humanJoined ? labels.humanPlaceholder : labels.placeholder,
37035
+ placeholder: humanJoined ? labels.humanPlaceholder : nearby.some((human) => human.name) ? labels.teamPlaceholder : labels.placeholder,
36842
37036
  attachLabel: labels.attach,
36843
37037
  sendLabel: labels.send,
36844
37038
  removeLabel: labels.remove,
@@ -36863,7 +37057,10 @@ function SettoChat() {
36863
37057
  onClick: show,
36864
37058
  "aria-label": labels.open,
36865
37059
  title: labels.open,
36866
- children: availability.humanAvailable && availability.avatarUrl ? /* @__PURE__ */ jsx("img", { src: availability.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx(AgentAvatar, { url: agentAvatarUrl }) })
37060
+ children: availability.humanAvailable && availability.avatarUrl ? /* @__PURE__ */ jsxs(Fragment, { children: [
37061
+ /* @__PURE__ */ jsx("img", { src: availability.avatarUrl, alt: "" }),
37062
+ /* @__PURE__ */ jsx("i", { className: "setto-chat__presence is-online", "aria-hidden": "true" })
37063
+ ] }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx(AgentAvatar, { url: agentAvatarUrl }) })
36867
37064
  }
36868
37065
  ) : null
36869
37066
  ]
@@ -36905,6 +37102,7 @@ function useChatStyles() {
36905
37102
  .setto-chat__receipt{display:block;margin:.26rem .45rem 0 0;color:color-mix(in srgb,var(--setto-chat-ink) 52%,transparent);font-size:.69rem;font-weight:500;line-height:1.2}.setto-chat__translation{display:flex;flex-wrap:wrap;align-items:baseline;gap:0 .3rem;margin:.3rem .4rem 0;color:color-mix(in srgb,var(--setto-chat-ink) 52%,transparent);font-size:.69rem;font-weight:500;line-height:1.3}.setto-chat__translation button{padding:0;border:0;border-radius:2px;background:transparent;color:inherit;font:inherit;line-height:inherit;text-decoration:underline;text-decoration-color:color-mix(in srgb,var(--setto-chat-ink) 30%,transparent);text-underline-offset:2px;cursor:pointer;transition:color 140ms ease}.setto-chat__translation button:hover{color:var(--setto-chat-ink);text-decoration-color:currentColor}.setto-chat__translation button:focus-visible{outline:2px solid var(--setto-chat-accent);outline-offset:2px}.setto-chat__message--system .setto-chat__translation{justify-content:center}.setto-chat__message--typing{animation:setto-chat-typing-in 180ms cubic-bezier(.2,.8,.2,1) both}.setto-chat__message--typing .setto-chat__message-bubble{min-width:3.25rem;text-align:center}.setto-chat__message--typing .setto-chat__typing{font-weight:700;letter-spacing:.06em}@keyframes setto-chat-typing-in{from{opacity:0;transform:translateY(4px)}}@media(prefers-reduced-motion:reduce){.setto-chat__message--typing{animation:none}}
36906
37103
  .setto-chat__composer-shell{position:absolute;left:0;right:0;bottom:0;z-index:25;display:grid;grid-template-columns:minmax(0,1fr);padding:1.5rem .75rem 0;background:transparent;isolation:isolate}.setto-chat__composer-shell::before{content:"";position:absolute;inset:0;pointer-events:none;background:linear-gradient(to bottom,transparent 0%,color-mix(in srgb,var(--setto-chat-canvas) 82%,transparent) 46%,var(--setto-chat-canvas) 66%);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);-webkit-mask-image:linear-gradient(to bottom,rgba(0,0,0,0) 0%,rgba(0,0,0,.4) 34%,rgba(0,0,0,1) 66%);mask-image:linear-gradient(to bottom,rgba(0,0,0,0) 0%,rgba(0,0,0,.4) 34%,rgba(0,0,0,1) 66%)}.setto-chat__composer{position:relative;z-index:1;display:flex;flex-direction:column;gap:.15rem;width:100%;min-width:0;margin:0;padding:.35rem .4rem;border:2px solid color-mix(in srgb,var(--setto-chat-ink) 10%,transparent);border-radius:24px;background:var(--setto-chat-canvas);box-shadow:0 8px 24px -16px color-mix(in srgb,var(--setto-chat-ink) 28%,transparent);transition:border-color 200ms ease,box-shadow 360ms cubic-bezier(.16,1,.3,1)}.setto-chat__composer:focus-within{border-color:var(--setto-chat-accent)}.setto-chat__composer textarea,.setto-chat__composer textarea:hover,.setto-chat__composer textarea:focus,.setto-chat__composer textarea:focus-visible{width:100%;min-height:36px;max-height:${MAX_COMPOSER_HEIGHT}px;overflow-y:auto;padding:.45rem .25rem;resize:none;-webkit-appearance:none!important;appearance:none!important;border:0!important;border-radius:0!important;outline:0!important;box-shadow:none!important;background:transparent!important;color:var(--setto-chat-ink);font-family:"Archivo Variable",Archivo,system-ui,sans-serif;font-size:16px;line-height:1.35}.setto-chat__composer textarea::placeholder{color:color-mix(in srgb,var(--setto-chat-ink) 52%,transparent)}.setto-chat__composer textarea::-webkit-scrollbar{width:6px}.setto-chat__composer textarea::-webkit-scrollbar-track{background:transparent}.setto-chat__composer textarea::-webkit-scrollbar-thumb{border-radius:999px;background:color-mix(in srgb,var(--setto-chat-ink) 24%,transparent)}.setto-chat__composer textarea::-webkit-scrollbar-button{display:none;height:0}@supports not selector(::-webkit-scrollbar){.setto-chat__composer textarea{scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--setto-chat-ink) 24%,transparent) transparent}}.setto-chat__composer-tools{display:flex;align-items:center;gap:.4rem;width:100%;min-width:0}.setto-chat__attach{flex:none;width:34px;height:34px;padding:0;border:0;border-radius:50%;background:transparent;color:color-mix(in srgb,var(--setto-chat-ink) 58%,transparent);display:inline-flex;align-items:center;justify-content:center;cursor:pointer;transition:background 160ms ease,color 160ms ease}.setto-chat__attach:hover:not(:disabled){background:color-mix(in srgb,var(--setto-chat-ink) 6%,transparent);color:var(--setto-chat-ink)}.setto-chat__attach:disabled{opacity:.4;cursor:default}.setto-chat__send{flex:none;width:36px;height:36px;margin-left:auto;padding:0;border:0;border-radius:50%;background:var(--setto-chat-accent);color:var(--setto-chat-on-accent);display:inline-flex;align-items:center;justify-content:center;cursor:pointer;transition:transform 360ms cubic-bezier(.16,1,.3,1),box-shadow 360ms cubic-bezier(.16,1,.3,1),background 200ms ease,opacity 200ms ease}.setto-chat__send:hover:not(:disabled){transform:translateY(-2px);box-shadow:0 12px 24px -12px color-mix(in srgb,var(--setto-chat-ink) 45%,transparent)}.setto-chat__send:active:not(:disabled){transform:translateY(0);box-shadow:0 4px 10px -8px color-mix(in srgb,var(--setto-chat-ink) 40%,transparent);transition-duration:90ms}.setto-chat__send:disabled{opacity:.35;cursor:default}.setto-chat__send.is-queued{animation:setto-chat-queued 1.1s ease-in-out infinite}.setto-chat__attachments{display:flex;flex-wrap:wrap;gap:.4rem;list-style:none;margin:0;padding:.15rem .15rem 0}.setto-chat__attachments li{position:relative;width:56px;height:56px;border-radius:10px;overflow:hidden;border:1px solid color-mix(in srgb,var(--setto-chat-ink) 12%,transparent);background:var(--setto-chat-crema)}.setto-chat__attachments img{display:block;width:100%;height:100%;object-fit:cover}.setto-chat__attachments button{position:absolute;top:2px;right:2px;width:18px;height:18px;padding:0;border:0;border-radius:50%;background:color-mix(in srgb,var(--setto-chat-ink) 72%,transparent);color:var(--setto-chat-canvas);display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.setto-chat__composer-floor{position:relative;z-index:1;width:calc(100% + 1.5rem);height:max(var(--setto-chat-edge),env(safe-area-inset-bottom));margin-left:-.75rem;background:var(--setto-chat-canvas)}
36907
37104
  .setto-chat__launcher{width:58px;height:58px;padding:3px;border:1px solid color-mix(in srgb,var(--setto-chat-canvas) 54%,transparent);border-radius:50%;background:color-mix(in srgb,var(--setto-chat-raised) 35%,transparent);box-shadow:0 10px 30px color-mix(in srgb,var(--setto-chat-ink) 24%,transparent),inset 0 0 0 1px color-mix(in srgb,var(--setto-chat-ink) 9%,transparent);backdrop-filter:blur(14px) saturate(115%);-webkit-backdrop-filter:blur(14px) saturate(115%);color:var(--setto-chat-ink);display:grid;place-items:center;cursor:pointer;transition:transform 180ms ease,box-shadow 180ms ease}.setto-chat__launcher:hover{transform:translateY(-2px);box-shadow:0 15px 35px color-mix(in srgb,var(--setto-chat-ink) 28%,transparent),inset 0 0 0 1px color-mix(in srgb,var(--setto-chat-ink) 9%,transparent)}.setto-chat__launcher span{width:46px;height:46px;border-radius:50%;display:grid;place-items:center;background:var(--setto-chat-accent);color:var(--setto-chat-on-accent)}.setto-chat__launcher img{display:block;width:50px;height:50px;border-radius:50%;object-fit:cover}.setto-chat__launcher span{overflow:hidden}.setto-chat__launcher span img{width:100%;height:100%}.setto-chat__launcher:focus-visible,.setto-chat button:focus-visible,.setto-chat input:focus-visible{outline:2px solid var(--setto-chat-accent);outline-offset:2px}@keyframes setto-chat-pulse{50%{opacity:.35}}@keyframes setto-chat-queued{50%{opacity:.55}}
37105
+ .setto-chat__team{position:relative;z-index:1;display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;margin:0 0 .55rem;padding:0 .2rem}.setto-chat__team-label{flex:0 0 100%;margin:0 0 -.05rem .3rem;color:color-mix(in srgb,var(--setto-chat-ink) 56%,transparent);font-size:.74rem;font-weight:600}.setto-chat__person{display:inline-flex;align-items:center;gap:.4rem;min-height:34px;padding:.18rem .7rem .18rem .2rem;border:1px solid color-mix(in srgb,var(--setto-chat-ink) 12%,transparent);border-radius:999px;background:var(--setto-chat-canvas);color:var(--setto-chat-ink);font-size:.82rem;font-weight:600;line-height:1;cursor:pointer;transition:background 160ms ease,border-color 160ms ease}.setto-chat__person:hover{border-color:var(--setto-chat-accent)}.setto-chat__person.is-picked{border-color:var(--setto-chat-accent);background:color-mix(in srgb,var(--setto-chat-accent) 12%,var(--setto-chat-canvas))}.setto-chat__face{position:relative;display:grid;place-items:center;flex:0 0 28px;width:28px;height:28px;border-radius:50%;background:var(--setto-chat-crema);color:var(--setto-chat-ink)}.setto-chat__face>img,.setto-chat__face-agent{display:grid;place-items:center;width:100%;height:100%;overflow:hidden;border-radius:50%;object-fit:cover}.setto-chat__face svg{width:16px;height:16px}.setto-chat__face-agent{background:var(--setto-chat-accent);color:var(--setto-chat-on-accent)}.setto-chat__face-agent img{width:100%;height:100%;object-fit:cover}.setto-chat__presence{position:absolute;right:-1px;bottom:-1px;width:10px;height:10px;border:2px solid var(--setto-chat-canvas);border-radius:50%;background:color-mix(in srgb,var(--setto-chat-ink) 32%,var(--setto-chat-canvas))}.setto-chat__presence.is-online{background:#2f9e5a}.setto-chat__launcher{position:relative}.setto-chat__launcher>.setto-chat__presence{right:4px;bottom:4px;width:15px;height:15px;border-width:2.5px}.setto-chat__mentions{position:absolute;left:0;right:0;bottom:calc(100% + 8px);z-index:3;max-height:240px;margin:0;padding:6px;overflow:auto;overscroll-behavior:contain;list-style:none;border:1px solid color-mix(in srgb,var(--setto-chat-ink) 12%,transparent);border-radius:16px;background:var(--setto-chat-canvas);box-shadow:0 16px 36px -18px color-mix(in srgb,var(--setto-chat-ink) 40%,transparent)}.setto-chat__mentions li{display:flex;align-items:center;gap:.6rem;padding:.42rem .55rem;border-radius:10px;cursor:pointer}.setto-chat__mentions li.is-active{background:color-mix(in srgb,var(--setto-chat-ink) 7%,transparent)}.setto-chat__mention-name{font-weight:600;font-size:.92rem}.setto-chat__mention-detail{margin-left:auto;color:color-mix(in srgb,var(--setto-chat-ink) 55%,transparent);font-size:.76rem}
36908
37106
  @media(max-width:700px){.setto-chat__chats{position:absolute;inset:0 auto 0 0;transform:translateX(-100%);transition:transform 260ms cubic-bezier(.16,1,.3,1);box-shadow:14px 0 35px color-mix(in srgb,var(--setto-chat-ink) 16%,transparent)}.setto-chat__chats--open{transform:none}.setto-chat__main{width:100%;max-width:none;margin:0}.setto-chat__log{padding-left:.75rem;padding-right:.75rem}}@media(min-width:701px){.setto-chat{--setto-chat-edge:.9rem}.setto-chat--mounted{top:auto;right:max(18px,env(safe-area-inset-right));bottom:max(18px,env(safe-area-inset-bottom));left:auto;width:min(440px,calc(100vw - 36px));height:min(720px,calc(100dvh - 36px));overflow:visible;background:transparent}.setto-chat__shell{position:relative;top:auto;left:auto;width:100%;height:100%;border:1px solid color-mix(in srgb,var(--setto-chat-ink) 14%,transparent);border-radius:26px;background:var(--setto-chat-canvas);box-shadow:0 28px 80px -24px color-mix(in srgb,var(--setto-chat-ink) 42%,transparent),0 8px 24px -12px color-mix(in srgb,var(--setto-chat-ink) 24%,transparent);transform:translateY(16px) scale(.975);transform-origin:right bottom}.setto-chat--visible .setto-chat__shell{transform:none}.setto-chat__chats{position:absolute;inset:0 auto 0 0;width:min(82%,280px);height:100%;transform:translateX(-100%);transition:transform 260ms cubic-bezier(.16,1,.3,1);box-shadow:14px 0 35px color-mix(in srgb,var(--setto-chat-ink) 16%,transparent)}.setto-chat__chats--open{transform:none}.setto-chat__main{width:100%;max-width:none;margin:0}.setto-chat__header,.setto-chat__log{padding-left:.9rem;padding-right:.9rem}.setto-chat__composer-shell{padding-left:.9rem;padding-right:.9rem}.setto-chat__composer-floor{width:calc(100% + 1.8rem);height:var(--setto-chat-edge);margin-left:-.9rem}.setto-chat__message{font-size:15.5px}.setto-chat__message-stack{max-width:82%}}@media(prefers-reduced-motion:reduce){.setto-chat,.setto-chat__shell,.setto-chat__chats,.setto-chat__launcher,.setto-chat__composer,.setto-chat__composer textarea,.setto-chat__send{transition:none!important}.setto-chat__typing,.setto-chat__send.is-queued{animation:none}}
36909
37107
  `;
36910
37108
  style.textContent += "@media(prefers-reduced-motion:reduce){.setto-chat__markdown.is-revealing .setto-chat__word{opacity:1;transform:none;filter:none;animation:none}}";