@sevenfold/setto-client 0.42.0 → 0.43.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.
@@ -15,7 +15,8 @@ type Message = {
15
15
  avatarUrl?: string | null;
16
16
  authorName?: string | null;
17
17
  attachments?: Attachment[];
18
- kind?: 'message' | 'navigation' | 'agent_joined' | 'agent_requested';
18
+ /** `agent_present` is the widget's own: the person on the chat button, under the opening line. */
19
+ kind?: 'message' | 'navigation' | 'agent_joined' | 'agent_requested' | 'agent_present';
19
20
  action?: {
20
21
  type: 'navigate';
21
22
  url: string;
@@ -62,14 +63,21 @@ export declare function nextWordBoundary(content: string, visibleLength: number)
62
63
  export declare function sineOut(progress: number): number;
63
64
  export declare function isAtChatBottom(scrollHeight: number, scrollTop: number, clientHeight: number): boolean;
64
65
  export declare function chatComposerSpace(height: number): number;
66
+ /** The greeting the teammate on the chat button wrote themselves, in the widget's language, if any. */
67
+ export declare function ownGreeting(locale: string, human: Pick<NearbyHuman, 'greeting'>): string | null;
65
68
  /**
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`).
69
+ * The line under the assistant's opening when someone is on the chat button
70
+ * and has not written a greeting of their own. Until 0.43.0 the opening was
71
+ * a canned «Hei, jeg heter Simon! Pixel svarer deg …» in their name, which
72
+ * read as if they had typed it and then handed over to an AI (Simon,
73
+ * 2026-10-14). The assistant opens now, and this notice shows the person.
68
74
  */
69
- export declare function humanIntro(locale: string, human: Pick<NearbyHuman, 'name' | 'greeting'>, agent?: string): string;
75
+ export declare function presenceLine(locale: string, name: string): string;
76
+ /** Messages that are only the widget's opening: local, and none of them the visitor's. */
77
+ export declare function isOpeningOnly(messages: readonly Message[]): boolean;
70
78
  /**
71
79
  * 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.
80
+ * one person who is online: the notice under the opening already shows them.
73
81
  */
74
82
  export declare function teamRowLabelled(humans: readonly Pick<NearbyHuman, 'online'>[]): boolean;
75
83
  /** `@Name` as a whole word, any case, as setto-server reads it. */
@@ -35503,11 +35503,20 @@ 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.`;
35506
+ function ownGreeting(locale, human) {
35507
+ return (norwegian(locale) ? human.greeting?.no : human.greeting?.en)?.trim() || null;
35508
+ }
35509
+ function presenceLine(locale, name2) {
35510
+ return norwegian(locale) ? `${name2} er her også. Trykk på bildet eller skriv @${name2} for å snakke med et menneske.` : `${name2} is here too. Tap the photo or type @${name2} to talk to a person.`;
35511
+ }
35512
+ function isOpeningOnly(messages) {
35513
+ return messages.length > 0 && messages.length <= 2 && messages.every((message) => !message.id && message.role !== "visitor" && message.content);
35514
+ }
35515
+ function sameOpening(a, b) {
35516
+ return a.length === b.length && a.every((message, index2) => {
35517
+ const other = b[index2];
35518
+ return message.role === other.role && message.kind === other.kind && message.content === other.content && message.avatarUrl === other.avatarUrl;
35519
+ });
35511
35520
  }
35512
35521
  function teamRowLabelled(humans) {
35513
35522
  return !(humans.length === 1 && humans[0].online);
@@ -36379,17 +36388,23 @@ function SettoChat() {
36379
36388
  function ensureVisitor() {
36380
36389
  return visitor.current ??= visitorId();
36381
36390
  }
36382
- function welcomeMessage() {
36383
- if (greeter) {
36384
- return {
36385
- role: "human",
36386
- content: humanIntro(locale, greeter, agentName),
36391
+ function welcomeMessages() {
36392
+ const theirs = greeter ? ownGreeting(locale, greeter) : null;
36393
+ if (greeter && theirs)
36394
+ return [{ role: "human", content: theirs, authorName: greeter.name, avatarUrl: greeter.avatarUrl }];
36395
+ const own2 = (norwegian(locale) ? settings?.welcome?.no : settings?.welcome?.en)?.trim();
36396
+ const opening = { role: "assistant", content: own2 || intro(locale, settings?.displayName ?? void 0, agentName) };
36397
+ if (!greeter?.name) return [opening];
36398
+ return [
36399
+ opening,
36400
+ {
36401
+ role: "system",
36402
+ kind: "agent_present",
36403
+ content: presenceLine(locale, greeter.name),
36387
36404
  authorName: greeter.name,
36388
36405
  avatarUrl: greeter.avatarUrl
36389
- };
36390
- }
36391
- const own2 = (norwegian(locale) ? settings?.welcome?.no : settings?.welcome?.en)?.trim();
36392
- return { role: "assistant", content: own2 || intro(locale, settings?.displayName ?? void 0, agentName) };
36406
+ }
36407
+ ];
36393
36408
  }
36394
36409
  function pickHuman(human) {
36395
36410
  setTapped((current) => new Set(current).add(human.handle));
@@ -36555,13 +36570,10 @@ function SettoChat() {
36555
36570
  const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
36556
36571
  useEffect(() => {
36557
36572
  if (!mounted || !settings || conversationId.current) return;
36558
- const welcome = welcomeMessage();
36573
+ const welcome = welcomeMessages();
36559
36574
  setMessages((current) => {
36560
- if (current.length === 0) return [welcome];
36561
- const only = current[0];
36562
- if (current.length === 1 && only && !only.id && (only.role === "assistant" || only.role === "human")) {
36563
- return only.role === welcome.role && only.content === welcome.content && only.avatarUrl === welcome.avatarUrl ? current : [welcome];
36564
- }
36575
+ if (current.length === 0) return welcome;
36576
+ if (isOpeningOnly(current)) return sameOpening(current, welcome) ? current : welcome;
36565
36577
  return current;
36566
36578
  });
36567
36579
  }, [mounted, settings, locale, greeterKey]);
@@ -36701,7 +36713,7 @@ function SettoChat() {
36701
36713
  setRealtime(null);
36702
36714
  setTeamTypingUntil(null);
36703
36715
  setHumanJoined(false);
36704
- setMessages([welcomeMessage()]);
36716
+ setMessages(welcomeMessages());
36705
36717
  setDraft("");
36706
36718
  setTapped(/* @__PURE__ */ new Set());
36707
36719
  setQueued(false);
@@ -36941,7 +36953,7 @@ function SettoChat() {
36941
36953
  "aria-busy": loadingConversation,
36942
36954
  children: /* @__PURE__ */ jsxs("div", { className: "setto-chat__message-list", children: [
36943
36955
  messages.map((item, index2) => {
36944
- if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested")) {
36956
+ if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested" || item.kind === "agent_present")) {
36945
36957
  return /* @__PURE__ */ jsx(
36946
36958
  AgentJoinedEvent,
36947
36959
  {