@sevenfold/setto-client 0.40.0 → 0.41.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/modules/chat/SettoChat.d.ts +48 -1
- package/dist/setto-client.js +228 -17
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,28 @@ 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
|
+
/** `@Name` as a whole word, any case, as setto-server reads it. */
|
|
71
|
+
export declare function mentionsName(content: string, name: string): boolean;
|
|
72
|
+
/** The handles a turn asks for: every named person @-mentioned, and every face tapped. */
|
|
73
|
+
export declare function mentionedHandles(content: string, humans: NearbyHuman[], tapped: ReadonlySet<string>): string[];
|
|
74
|
+
/** An `@` being typed just before the caret, and what follows it so far. */
|
|
75
|
+
export declare function mentionQuery(value: string, caret: number): {
|
|
76
|
+
start: number;
|
|
77
|
+
query: string;
|
|
78
|
+
} | null;
|
|
79
|
+
/** Puts `@Name ` where the `@` was typed, or at the end; returns the caret after it. */
|
|
80
|
+
export declare function insertMention(value: string, name: string, at: {
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
} | null): {
|
|
84
|
+
value: string;
|
|
85
|
+
caret: number;
|
|
86
|
+
};
|
|
50
87
|
/**
|
|
51
88
|
* «Translated from English · Show original» under a translated message, in
|
|
52
89
|
* the visitor's language. The toggle is a real button; the line is left out
|
|
@@ -79,6 +116,16 @@ export declare function SiteChatMarkdown({ content, reveal }: {
|
|
|
79
116
|
content: string;
|
|
80
117
|
reveal?: boolean;
|
|
81
118
|
}): import("react/jsx-runtime").JSX.Element;
|
|
119
|
+
/** Someone the @ list offers: the assistant, or a person near the chat. */
|
|
120
|
+
export type Mentionable = {
|
|
121
|
+
key: string;
|
|
122
|
+
name: string;
|
|
123
|
+
/** «AI-assistent», «Tilgjengelig nå» … */
|
|
124
|
+
detail: string;
|
|
125
|
+
avatar: ReactNode;
|
|
126
|
+
/** People only: green when online now. */
|
|
127
|
+
online?: boolean;
|
|
128
|
+
};
|
|
82
129
|
/** Responsive visitor conversation. Its drawer only contains this browser's site chats. */
|
|
83
130
|
export declare function SettoChat(): import("react/jsx-runtime").JSX.Element | null;
|
|
84
131
|
export {};
|
package/dist/setto-client.js
CHANGED
|
@@ -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,
|
|
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,36 @@ 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 escapeRegExp$1(value) {
|
|
35513
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35514
|
+
}
|
|
35515
|
+
function mentionsName(content2, name2) {
|
|
35516
|
+
return new RegExp(`(^|[^\\p{L}\\p{N}_@])@${escapeRegExp$1(name2)}(?![\\p{L}\\p{N}_])`, "iu").test(content2);
|
|
35517
|
+
}
|
|
35518
|
+
function mentionedHandles(content2, humans, tapped) {
|
|
35519
|
+
return humans.filter((human) => tapped.has(human.handle) || human.name !== null && mentionsName(content2, human.name)).map((human) => human.handle).slice(0, 3);
|
|
35520
|
+
}
|
|
35521
|
+
function mentionQuery(value, caret) {
|
|
35522
|
+
const match = value.slice(0, caret).match(/(^|[^\p{L}\p{N}_@])@([\p{L}\p{N}_-]{0,30})$/u);
|
|
35523
|
+
if (!match) return null;
|
|
35524
|
+
return { start: caret - match[2].length - 1, query: match[2] };
|
|
35525
|
+
}
|
|
35526
|
+
function insertMention(value, name2, at2) {
|
|
35527
|
+
const mention = `@${name2} `;
|
|
35528
|
+
if (at2) {
|
|
35529
|
+
const next = value.slice(0, at2.start) + mention + value.slice(at2.end).replace(/^ /, "");
|
|
35530
|
+
return { value: next, caret: at2.start + mention.length };
|
|
35531
|
+
}
|
|
35532
|
+
if (mentionsName(value, name2)) return { value, caret: value.length };
|
|
35533
|
+
const before = value && !/\s$/.test(value) ? `${value} ` : value;
|
|
35534
|
+
return { value: before + mention, caret: before.length + mention.length };
|
|
35535
|
+
}
|
|
35506
35536
|
function MenuIcon() {
|
|
35507
35537
|
return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "22", height: "22", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
|
|
35508
35538
|
"path",
|
|
@@ -35678,6 +35708,9 @@ function SiteChatMarkdown({ content: content2, reveal = false }) {
|
|
|
35678
35708
|
function SiteChatComposer({
|
|
35679
35709
|
value,
|
|
35680
35710
|
onChange,
|
|
35711
|
+
mentionables,
|
|
35712
|
+
mentionLabel,
|
|
35713
|
+
focusRequest,
|
|
35681
35714
|
onSubmit,
|
|
35682
35715
|
onBlur,
|
|
35683
35716
|
busy,
|
|
@@ -35693,6 +35726,44 @@ function SiteChatComposer({
|
|
|
35693
35726
|
}) {
|
|
35694
35727
|
const textareaRef = useRef(null);
|
|
35695
35728
|
const fileRef = useRef(null);
|
|
35729
|
+
const [mention, setMention] = useState(null);
|
|
35730
|
+
const [active, setActive] = useState(0);
|
|
35731
|
+
const caretRef = useRef(null);
|
|
35732
|
+
const listId = useId();
|
|
35733
|
+
const options = mention ? mentionables.filter((option) => option.name.toLocaleLowerCase().startsWith(mention.query.toLocaleLowerCase())) : [];
|
|
35734
|
+
const open = options.length > 0;
|
|
35735
|
+
function track(textarea) {
|
|
35736
|
+
setMention(mentionQuery(textarea.value, textarea.selectionStart ?? textarea.value.length));
|
|
35737
|
+
}
|
|
35738
|
+
function choose(option) {
|
|
35739
|
+
const textarea = textareaRef.current;
|
|
35740
|
+
if (!mention || !textarea) return;
|
|
35741
|
+
const next = insertMention(value, option.name, {
|
|
35742
|
+
start: mention.start,
|
|
35743
|
+
end: textarea.selectionStart ?? value.length
|
|
35744
|
+
});
|
|
35745
|
+
caretRef.current = next.caret;
|
|
35746
|
+
onChange(next.value);
|
|
35747
|
+
setMention(null);
|
|
35748
|
+
}
|
|
35749
|
+
useLayoutEffect(() => {
|
|
35750
|
+
const caret = caretRef.current;
|
|
35751
|
+
const textarea = textareaRef.current;
|
|
35752
|
+
if (caret === null || !textarea) return;
|
|
35753
|
+
caretRef.current = null;
|
|
35754
|
+
textarea.focus({ preventScroll: true });
|
|
35755
|
+
textarea.setSelectionRange(caret, caret);
|
|
35756
|
+
}, [value]);
|
|
35757
|
+
useEffect(() => {
|
|
35758
|
+
if (!focusRequest) return;
|
|
35759
|
+
const textarea = textareaRef.current;
|
|
35760
|
+
if (!textarea) return;
|
|
35761
|
+
const frame = window.requestAnimationFrame(() => {
|
|
35762
|
+
textarea.focus({ preventScroll: true });
|
|
35763
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
35764
|
+
});
|
|
35765
|
+
return () => window.cancelAnimationFrame(frame);
|
|
35766
|
+
}, [focusRequest]);
|
|
35696
35767
|
useEffect(() => {
|
|
35697
35768
|
const textarea = textareaRef.current;
|
|
35698
35769
|
if (!textarea) return;
|
|
@@ -35719,6 +35790,25 @@ function SiteChatComposer({
|
|
|
35719
35790
|
send();
|
|
35720
35791
|
}
|
|
35721
35792
|
function handleKeyDown(event) {
|
|
35793
|
+
if (open) {
|
|
35794
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
35795
|
+
event.preventDefault();
|
|
35796
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
35797
|
+
setActive((current) => (current + step + options.length) % options.length);
|
|
35798
|
+
return;
|
|
35799
|
+
}
|
|
35800
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
35801
|
+
event.preventDefault();
|
|
35802
|
+
choose(options[Math.min(active, options.length - 1)]);
|
|
35803
|
+
return;
|
|
35804
|
+
}
|
|
35805
|
+
if (event.key === "Escape") {
|
|
35806
|
+
event.preventDefault();
|
|
35807
|
+
event.stopPropagation();
|
|
35808
|
+
setMention(null);
|
|
35809
|
+
return;
|
|
35810
|
+
}
|
|
35811
|
+
}
|
|
35722
35812
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
35723
35813
|
event.preventDefault();
|
|
35724
35814
|
send();
|
|
@@ -35748,6 +35838,27 @@ function SiteChatComposer({
|
|
|
35748
35838
|
}
|
|
35749
35839
|
)
|
|
35750
35840
|
] }, `${attachment.file.name}-${attachment.preview}`)) }) : null,
|
|
35841
|
+
open ? /* @__PURE__ */ jsx("ul", { className: "setto-chat__mentions", role: "listbox", id: listId, "aria-label": mentionLabel, children: options.map((option, index2) => /* @__PURE__ */ jsxs(
|
|
35842
|
+
"li",
|
|
35843
|
+
{
|
|
35844
|
+
id: `${listId}-${index2}`,
|
|
35845
|
+
role: "option",
|
|
35846
|
+
"aria-selected": index2 === active,
|
|
35847
|
+
className: index2 === active ? "is-active" : void 0,
|
|
35848
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
35849
|
+
onMouseEnter: () => setActive(index2),
|
|
35850
|
+
onClick: () => choose(option),
|
|
35851
|
+
children: [
|
|
35852
|
+
/* @__PURE__ */ jsxs("span", { className: "setto-chat__face", children: [
|
|
35853
|
+
option.avatar,
|
|
35854
|
+
option.online !== void 0 ? /* @__PURE__ */ jsx("i", { className: `setto-chat__presence${option.online ? " is-online" : ""}`, "aria-hidden": "true" }) : null
|
|
35855
|
+
] }),
|
|
35856
|
+
/* @__PURE__ */ jsx("span", { className: "setto-chat__mention-name", children: option.name }),
|
|
35857
|
+
/* @__PURE__ */ jsx("span", { className: "setto-chat__mention-detail", children: option.detail })
|
|
35858
|
+
]
|
|
35859
|
+
},
|
|
35860
|
+
option.key
|
|
35861
|
+
)) }) : null,
|
|
35751
35862
|
/* @__PURE__ */ jsx(
|
|
35752
35863
|
"textarea",
|
|
35753
35864
|
{
|
|
@@ -35755,9 +35866,21 @@ function SiteChatComposer({
|
|
|
35755
35866
|
lang: norwegian(locale) ? "nb" : "en",
|
|
35756
35867
|
spellCheck: true,
|
|
35757
35868
|
value,
|
|
35758
|
-
|
|
35869
|
+
"aria-autocomplete": mentionables.length ? "list" : void 0,
|
|
35870
|
+
"aria-controls": open ? listId : void 0,
|
|
35871
|
+
"aria-expanded": mentionables.length ? open : void 0,
|
|
35872
|
+
"aria-activedescendant": open ? `${listId}-${Math.min(active, options.length - 1)}` : void 0,
|
|
35873
|
+
onChange: (event) => {
|
|
35874
|
+
onChange(event.target.value);
|
|
35875
|
+
track(event.target);
|
|
35876
|
+
setActive(0);
|
|
35877
|
+
},
|
|
35878
|
+
onSelect: (event) => track(event.currentTarget),
|
|
35759
35879
|
onKeyDown: handleKeyDown,
|
|
35760
|
-
onBlur: () =>
|
|
35880
|
+
onBlur: () => {
|
|
35881
|
+
setMention(null);
|
|
35882
|
+
onBlur?.();
|
|
35883
|
+
},
|
|
35761
35884
|
placeholder,
|
|
35762
35885
|
rows: 1,
|
|
35763
35886
|
maxLength: 1500
|
|
@@ -36129,6 +36252,8 @@ function SettoChat() {
|
|
|
36129
36252
|
humanAvailable: false,
|
|
36130
36253
|
avatarUrl: null
|
|
36131
36254
|
});
|
|
36255
|
+
const [tapped, setTapped] = useState(() => /* @__PURE__ */ new Set());
|
|
36256
|
+
const [focusRequest, setFocusRequest] = useState(0);
|
|
36132
36257
|
const conversationId = useRef(storedActiveConversation(config.siteId));
|
|
36133
36258
|
const visitor = useRef(null);
|
|
36134
36259
|
const chatRef = useRef(null);
|
|
@@ -36195,6 +36320,8 @@ function SettoChat() {
|
|
|
36195
36320
|
const siteName = settings?.displayName?.trim() || config.displayName?.trim() || null;
|
|
36196
36321
|
const agentName = settings?.agentName?.trim() || "Barista";
|
|
36197
36322
|
const agentAvatarUrl = settings?.agentAvatarUrl ?? null;
|
|
36323
|
+
const nearby = availability.humans ?? [];
|
|
36324
|
+
const greeter = availability.humanAvailable ? nearby.find((human) => human.online && human.name) ?? null : null;
|
|
36198
36325
|
const labels = isNo ? {
|
|
36199
36326
|
open: siteName ? `Åpne chat med ${siteName}` : "Åpne chat",
|
|
36200
36327
|
close: "Lukk chatten",
|
|
@@ -36203,7 +36330,14 @@ function SettoChat() {
|
|
|
36203
36330
|
chats: "Chats",
|
|
36204
36331
|
newChat: "Ny chat",
|
|
36205
36332
|
placeholder: "Hva vil du spørre om?",
|
|
36206
|
-
humanPlaceholder: `Skriv til teamet · bruk
|
|
36333
|
+
humanPlaceholder: `Skriv til teamet · bruk @${agentName} for ${agentName}`,
|
|
36334
|
+
teamPlaceholder: `Spør ${agentName}, eller skriv @ for å nå teamet`,
|
|
36335
|
+
teamRow: "Snakk med et menneske",
|
|
36336
|
+
mentions: "Hvem vil du spørre?",
|
|
36337
|
+
online: "Tilgjengelig nå",
|
|
36338
|
+
nearby: "I nærheten",
|
|
36339
|
+
askFor: (name2, online) => `Spør etter ${name2} (${online ? "tilgjengelig nå" : "i nærheten"})`,
|
|
36340
|
+
someone: "Teamet",
|
|
36207
36341
|
send: "Send melding",
|
|
36208
36342
|
sending: "Svarer …",
|
|
36209
36343
|
attach: "Legg ved bilde",
|
|
@@ -36221,7 +36355,14 @@ function SettoChat() {
|
|
|
36221
36355
|
chats: "Chats",
|
|
36222
36356
|
newChat: "New chat",
|
|
36223
36357
|
placeholder: "What would you like to ask?",
|
|
36224
|
-
humanPlaceholder: `Message the team · use
|
|
36358
|
+
humanPlaceholder: `Message the team · use @${agentName} for ${agentName}`,
|
|
36359
|
+
teamPlaceholder: `Ask ${agentName}, or type @ to reach the team`,
|
|
36360
|
+
teamRow: "Talk to a person",
|
|
36361
|
+
mentions: "Who would you like to ask?",
|
|
36362
|
+
online: "Available now",
|
|
36363
|
+
nearby: "Nearby",
|
|
36364
|
+
askFor: (name2, online) => `Ask for ${name2} (${online ? "available now" : "nearby"})`,
|
|
36365
|
+
someone: "The team",
|
|
36225
36366
|
send: "Send message",
|
|
36226
36367
|
sending: "Replying …",
|
|
36227
36368
|
attach: "Attach image",
|
|
@@ -36235,6 +36376,27 @@ function SettoChat() {
|
|
|
36235
36376
|
function ensureVisitor() {
|
|
36236
36377
|
return visitor.current ??= visitorId();
|
|
36237
36378
|
}
|
|
36379
|
+
function welcomeMessage() {
|
|
36380
|
+
if (greeter) {
|
|
36381
|
+
return {
|
|
36382
|
+
role: "human",
|
|
36383
|
+
content: humanIntro(locale, greeter, agentName),
|
|
36384
|
+
authorName: greeter.name,
|
|
36385
|
+
avatarUrl: greeter.avatarUrl
|
|
36386
|
+
};
|
|
36387
|
+
}
|
|
36388
|
+
const own2 = (norwegian(locale) ? settings?.welcome?.no : settings?.welcome?.en)?.trim();
|
|
36389
|
+
return { role: "assistant", content: own2 || intro(locale, settings?.displayName ?? void 0, agentName) };
|
|
36390
|
+
}
|
|
36391
|
+
function pickHuman(human) {
|
|
36392
|
+
setTapped((current) => new Set(current).add(human.handle));
|
|
36393
|
+
if (human.name) {
|
|
36394
|
+
const next = insertMention(draft, human.name, null).value;
|
|
36395
|
+
setDraft(next);
|
|
36396
|
+
typingSender().update(next);
|
|
36397
|
+
}
|
|
36398
|
+
setFocusRequest((current) => current + 1);
|
|
36399
|
+
}
|
|
36238
36400
|
function rememberConversation(id) {
|
|
36239
36401
|
conversationId.current = id;
|
|
36240
36402
|
try {
|
|
@@ -36375,19 +36537,20 @@ function SettoChat() {
|
|
|
36375
36537
|
cancelled = true;
|
|
36376
36538
|
window.clearInterval(timer);
|
|
36377
36539
|
};
|
|
36378
|
-
}, [apiUrl, config.siteId, settings]);
|
|
36540
|
+
}, [apiUrl, config.siteId, settings, mounted]);
|
|
36541
|
+
const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
|
|
36379
36542
|
useEffect(() => {
|
|
36380
36543
|
if (!mounted || !settings || conversationId.current) return;
|
|
36381
|
-
const
|
|
36382
|
-
const welcome = own2 || intro(locale, settings.displayName ?? void 0, settings.agentName?.trim() || void 0);
|
|
36544
|
+
const welcome = welcomeMessage();
|
|
36383
36545
|
setMessages((current) => {
|
|
36384
|
-
if (current.length === 0) return [
|
|
36385
|
-
|
|
36386
|
-
|
|
36546
|
+
if (current.length === 0) return [welcome];
|
|
36547
|
+
const only = current[0];
|
|
36548
|
+
if (current.length === 1 && only && !only.id && (only.role === "assistant" || only.role === "human")) {
|
|
36549
|
+
return only.role === welcome.role && only.content === welcome.content && only.avatarUrl === welcome.avatarUrl ? current : [welcome];
|
|
36387
36550
|
}
|
|
36388
36551
|
return current;
|
|
36389
36552
|
});
|
|
36390
|
-
}, [mounted, settings, locale]);
|
|
36553
|
+
}, [mounted, settings, locale, greeterKey]);
|
|
36391
36554
|
useEffect(() => {
|
|
36392
36555
|
filesRef.current = files;
|
|
36393
36556
|
}, [files]);
|
|
@@ -36524,8 +36687,9 @@ function SettoChat() {
|
|
|
36524
36687
|
setRealtime(null);
|
|
36525
36688
|
setTeamTypingUntil(null);
|
|
36526
36689
|
setHumanJoined(false);
|
|
36527
|
-
setMessages([
|
|
36690
|
+
setMessages([welcomeMessage()]);
|
|
36528
36691
|
setDraft("");
|
|
36692
|
+
setTapped(/* @__PURE__ */ new Set());
|
|
36529
36693
|
setQueued(false);
|
|
36530
36694
|
setDrawer(false);
|
|
36531
36695
|
clearPendingFiles();
|
|
@@ -36557,12 +36721,14 @@ function SettoChat() {
|
|
|
36557
36721
|
const content2 = draft.trim();
|
|
36558
36722
|
const turnFiles = files;
|
|
36559
36723
|
if (!content2 && turnFiles.length === 0) return;
|
|
36724
|
+
const mentions = mentionedHandles(content2, nearby, tapped);
|
|
36560
36725
|
turnRef.current.busy = true;
|
|
36561
36726
|
turnRef.current.generation += 1;
|
|
36562
36727
|
typingSender().stop();
|
|
36563
36728
|
pinToBottomRef.current = true;
|
|
36564
36729
|
setDraft("");
|
|
36565
36730
|
setFiles([]);
|
|
36731
|
+
setTapped(/* @__PURE__ */ new Set());
|
|
36566
36732
|
setSending(true);
|
|
36567
36733
|
const visitorIdValue = ensureVisitor();
|
|
36568
36734
|
let revealer = null;
|
|
@@ -36608,7 +36774,8 @@ function SettoChat() {
|
|
|
36608
36774
|
language: browserLanguage(),
|
|
36609
36775
|
page: window.location.href,
|
|
36610
36776
|
message: content2 || void 0,
|
|
36611
|
-
attachmentIds: uploaded.map((attachment) => attachment.id)
|
|
36777
|
+
attachmentIds: uploaded.map((attachment) => attachment.id),
|
|
36778
|
+
...mentions.length ? { mentions } : {}
|
|
36612
36779
|
})
|
|
36613
36780
|
}
|
|
36614
36781
|
);
|
|
@@ -36619,6 +36786,7 @@ function SettoChat() {
|
|
|
36619
36786
|
const body = await response.json();
|
|
36620
36787
|
if (body.conversationId) rememberConversation(body.conversationId);
|
|
36621
36788
|
if (body.humanJoined) setHumanJoined(true);
|
|
36789
|
+
if (body.requested) pendingRefreshRef.current = true;
|
|
36622
36790
|
if (body.silent) {
|
|
36623
36791
|
revealer.cancel();
|
|
36624
36792
|
setMessages((previous2) => removeLastEmptyAssistant(previous2));
|
|
@@ -36759,7 +36927,7 @@ function SettoChat() {
|
|
|
36759
36927
|
"aria-busy": loadingConversation,
|
|
36760
36928
|
children: /* @__PURE__ */ jsxs("div", { className: "setto-chat__message-list", children: [
|
|
36761
36929
|
messages.map((item, index2) => {
|
|
36762
|
-
if (item.role === "system" && item.kind === "agent_joined") {
|
|
36930
|
+
if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested")) {
|
|
36763
36931
|
return /* @__PURE__ */ jsx(
|
|
36764
36932
|
AgentJoinedEvent,
|
|
36765
36933
|
{
|
|
@@ -36826,6 +36994,28 @@ function SettoChat() {
|
|
|
36826
36994
|
}
|
|
36827
36995
|
),
|
|
36828
36996
|
/* @__PURE__ */ jsxs("div", { className: "setto-chat__composer-shell", ref: composerShellRef, children: [
|
|
36997
|
+
nearby.length ? /* @__PURE__ */ jsxs("div", { className: "setto-chat__team", children: [
|
|
36998
|
+
/* @__PURE__ */ jsx("span", { className: "setto-chat__team-label", children: labels.teamRow }),
|
|
36999
|
+
nearby.map((human) => /* @__PURE__ */ jsxs(
|
|
37000
|
+
"button",
|
|
37001
|
+
{
|
|
37002
|
+
type: "button",
|
|
37003
|
+
className: `setto-chat__person${tapped.has(human.handle) ? " is-picked" : ""}`,
|
|
37004
|
+
onClick: () => pickHuman(human),
|
|
37005
|
+
"aria-label": labels.askFor(human.name ?? labels.someone, human.online),
|
|
37006
|
+
"aria-pressed": tapped.has(human.handle),
|
|
37007
|
+
title: labels.askFor(human.name ?? labels.someone, human.online),
|
|
37008
|
+
children: [
|
|
37009
|
+
/* @__PURE__ */ jsxs("span", { className: "setto-chat__face", children: [
|
|
37010
|
+
human.avatarUrl ? /* @__PURE__ */ jsx("img", { src: human.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx(PersonIcon, {}),
|
|
37011
|
+
/* @__PURE__ */ jsx("i", { className: `setto-chat__presence${human.online ? " is-online" : ""}`, "aria-hidden": "true" })
|
|
37012
|
+
] }),
|
|
37013
|
+
/* @__PURE__ */ jsx("span", { children: human.name ?? labels.someone })
|
|
37014
|
+
]
|
|
37015
|
+
},
|
|
37016
|
+
human.handle
|
|
37017
|
+
))
|
|
37018
|
+
] }) : null,
|
|
36829
37019
|
/* @__PURE__ */ jsx(
|
|
36830
37020
|
SiteChatComposer,
|
|
36831
37021
|
{
|
|
@@ -36834,11 +37024,28 @@ function SettoChat() {
|
|
|
36834
37024
|
setDraft(value);
|
|
36835
37025
|
typingSender().update(value);
|
|
36836
37026
|
},
|
|
37027
|
+
mentionables: [
|
|
37028
|
+
{
|
|
37029
|
+
key: "agent",
|
|
37030
|
+
name: agentName,
|
|
37031
|
+
detail: labels.ai,
|
|
37032
|
+
avatar: /* @__PURE__ */ jsx("span", { className: "setto-chat__face-agent", children: /* @__PURE__ */ jsx(AgentAvatar, { url: agentAvatarUrl }) })
|
|
37033
|
+
},
|
|
37034
|
+
...nearby.filter((human) => human.name).map((human) => ({
|
|
37035
|
+
key: human.handle,
|
|
37036
|
+
name: human.name,
|
|
37037
|
+
detail: human.online ? labels.online : labels.nearby,
|
|
37038
|
+
avatar: human.avatarUrl ? /* @__PURE__ */ jsx("img", { src: human.avatarUrl, alt: "" }) : /* @__PURE__ */ jsx(PersonIcon, {}),
|
|
37039
|
+
online: human.online
|
|
37040
|
+
}))
|
|
37041
|
+
],
|
|
37042
|
+
mentionLabel: labels.mentions,
|
|
37043
|
+
focusRequest,
|
|
36837
37044
|
onSubmit: queueOrSend,
|
|
36838
37045
|
onBlur: () => typingSender().stop(),
|
|
36839
37046
|
busy: sending,
|
|
36840
37047
|
queued,
|
|
36841
|
-
placeholder: humanJoined ? labels.humanPlaceholder : labels.placeholder,
|
|
37048
|
+
placeholder: humanJoined ? labels.humanPlaceholder : nearby.some((human) => human.name) ? labels.teamPlaceholder : labels.placeholder,
|
|
36842
37049
|
attachLabel: labels.attach,
|
|
36843
37050
|
sendLabel: labels.send,
|
|
36844
37051
|
removeLabel: labels.remove,
|
|
@@ -36863,7 +37070,10 @@ function SettoChat() {
|
|
|
36863
37070
|
onClick: show,
|
|
36864
37071
|
"aria-label": labels.open,
|
|
36865
37072
|
title: labels.open,
|
|
36866
|
-
children: availability.humanAvailable && availability.avatarUrl ? /* @__PURE__ */
|
|
37073
|
+
children: availability.humanAvailable && availability.avatarUrl ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
37074
|
+
/* @__PURE__ */ jsx("img", { src: availability.avatarUrl, alt: "" }),
|
|
37075
|
+
/* @__PURE__ */ jsx("i", { className: "setto-chat__presence is-online", "aria-hidden": "true" })
|
|
37076
|
+
] }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx(AgentAvatar, { url: agentAvatarUrl }) })
|
|
36867
37077
|
}
|
|
36868
37078
|
) : null
|
|
36869
37079
|
]
|
|
@@ -36905,6 +37115,7 @@ function useChatStyles() {
|
|
|
36905
37115
|
.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
37116
|
.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
37117
|
.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}}
|
|
37118
|
+
.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{margin-right:.15rem;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
37119
|
@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
37120
|
`;
|
|
36910
37121
|
style.textContent += "@media(prefers-reduced-motion:reduce){.setto-chat__markdown.is-revealing .setto-chat__word{opacity:1;transform:none;filter:none;animation:none}}";
|