@sevenfold/setto-client 0.42.0 → 0.44.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/chrome.d.ts CHANGED
@@ -71,6 +71,8 @@ export interface SettoChromeHandshake {
71
71
  } | null;
72
72
  sitesLoaded: boolean;
73
73
  editMode: boolean;
74
+ /** May edit, whether or not editing now (0.44). The chrome loads the editor for it. */
75
+ canEdit?: boolean;
74
76
  /** A signed-out visitor trying the editor on setto.no. */
75
77
  guestEdit: boolean;
76
78
  authLoading: boolean;
@@ -0,0 +1,12 @@
1
+ import type { Session } from '@supabase/supabase-js';
2
+ /**
3
+ * Whether this session is the site's support account: the member a Setto admin
4
+ * signs in as with «Rediger» in the admin. setto-server makes the account and
5
+ * names its one site in `app_metadata.setto_support_site`, which only the
6
+ * service role can write (`src/lib/support-account.ts` there).
7
+ *
8
+ * Read from the session rather than asked of the server, so the editor is
9
+ * there on the first render. It only opens the editor's furniture; every
10
+ * write is still the server's to allow or refuse.
11
+ */
12
+ export declare function isSupportSession(session: Session | null, siteId: string): boolean;
@@ -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. */
@@ -20,7 +20,7 @@ export interface SettoContextValue {
20
20
  editMode: boolean;
21
21
  /**
22
22
  * True when this person may edit this site: signed in, a member, the site is
23
- * paid for, and this is not `/setto`. The Setto menu is drawn whenever this
23
+ * paid for (or this is the site's support account), and this is not `/setto`. The Setto menu is drawn whenever this
24
24
  * is; outside `editMode` it shows the site as a visitor sees it.
25
25
  * Absent on a client older than 0.33, where `editMode` meant this.
26
26
  */
@@ -22014,6 +22014,10 @@ function useSiteAccess(supabase, session, siteId) {
22014
22014
  }, [supabase, session, siteId]);
22015
22015
  return state;
22016
22016
  }
22017
+ function isSupportSession(session, siteId) {
22018
+ const site = session?.user?.app_metadata?.setto_support_site;
22019
+ return typeof site === "string" && site === siteId;
22020
+ }
22017
22021
  const CHROME_CONTRACT = 1;
22018
22022
  function chromeUrl(apiUrl) {
22019
22023
  return `${apiUrl.replace(/\/$/, "")}/chrome/v${CHROME_CONTRACT}.js`;
@@ -22081,6 +22085,7 @@ function SettoChrome() {
22081
22085
  currentSite: null,
22082
22086
  sitesLoaded: false,
22083
22087
  editMode: false,
22088
+ canEdit: false,
22084
22089
  guestEdit: false,
22085
22090
  authLoading: true
22086
22091
  }));
@@ -22094,6 +22099,7 @@ function SettoChrome() {
22094
22099
  } : null,
22095
22100
  sitesLoaded: setto.sites !== null,
22096
22101
  editMode: setto.editMode,
22102
+ canEdit: setto.canEdit,
22097
22103
  guestEdit: setto.guestEdit,
22098
22104
  authLoading: setto.authLoading
22099
22105
  });
@@ -35503,11 +35509,20 @@ function norwegian(locale) {
35503
35509
  function intro(locale, name2, agent = "Barista") {
35504
35510
  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
35511
  }
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.`;
35512
+ function ownGreeting(locale, human) {
35513
+ return (norwegian(locale) ? human.greeting?.no : human.greeting?.en)?.trim() || null;
35514
+ }
35515
+ function presenceLine(locale, name2) {
35516
+ 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.`;
35517
+ }
35518
+ function isOpeningOnly(messages) {
35519
+ return messages.length > 0 && messages.length <= 2 && messages.every((message) => !message.id && message.role !== "visitor" && message.content);
35520
+ }
35521
+ function sameOpening(a, b) {
35522
+ return a.length === b.length && a.every((message, index2) => {
35523
+ const other = b[index2];
35524
+ return message.role === other.role && message.kind === other.kind && message.content === other.content && message.avatarUrl === other.avatarUrl;
35525
+ });
35511
35526
  }
35512
35527
  function teamRowLabelled(humans) {
35513
35528
  return !(humans.length === 1 && humans[0].online);
@@ -36379,17 +36394,23 @@ function SettoChat() {
36379
36394
  function ensureVisitor() {
36380
36395
  return visitor.current ??= visitorId();
36381
36396
  }
36382
- function welcomeMessage() {
36383
- if (greeter) {
36384
- return {
36385
- role: "human",
36386
- content: humanIntro(locale, greeter, agentName),
36397
+ function welcomeMessages() {
36398
+ const theirs = greeter ? ownGreeting(locale, greeter) : null;
36399
+ if (greeter && theirs)
36400
+ return [{ role: "human", content: theirs, authorName: greeter.name, avatarUrl: greeter.avatarUrl }];
36401
+ const own2 = (norwegian(locale) ? settings?.welcome?.no : settings?.welcome?.en)?.trim();
36402
+ const opening = { role: "assistant", content: own2 || intro(locale, settings?.displayName ?? void 0, agentName) };
36403
+ if (!greeter?.name) return [opening];
36404
+ return [
36405
+ opening,
36406
+ {
36407
+ role: "system",
36408
+ kind: "agent_present",
36409
+ content: presenceLine(locale, greeter.name),
36387
36410
  authorName: greeter.name,
36388
36411
  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) };
36412
+ }
36413
+ ];
36393
36414
  }
36394
36415
  function pickHuman(human) {
36395
36416
  setTapped((current) => new Set(current).add(human.handle));
@@ -36555,13 +36576,10 @@ function SettoChat() {
36555
36576
  const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
36556
36577
  useEffect(() => {
36557
36578
  if (!mounted || !settings || conversationId.current) return;
36558
- const welcome = welcomeMessage();
36579
+ const welcome = welcomeMessages();
36559
36580
  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
- }
36581
+ if (current.length === 0) return welcome;
36582
+ if (isOpeningOnly(current)) return sameOpening(current, welcome) ? current : welcome;
36565
36583
  return current;
36566
36584
  });
36567
36585
  }, [mounted, settings, locale, greeterKey]);
@@ -36701,7 +36719,7 @@ function SettoChat() {
36701
36719
  setRealtime(null);
36702
36720
  setTeamTypingUntil(null);
36703
36721
  setHumanJoined(false);
36704
- setMessages([welcomeMessage()]);
36722
+ setMessages(welcomeMessages());
36705
36723
  setDraft("");
36706
36724
  setTapped(/* @__PURE__ */ new Set());
36707
36725
  setQueued(false);
@@ -36941,7 +36959,7 @@ function SettoChat() {
36941
36959
  "aria-busy": loadingConversation,
36942
36960
  children: /* @__PURE__ */ jsxs("div", { className: "setto-chat__message-list", children: [
36943
36961
  messages.map((item, index2) => {
36944
- if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested")) {
36962
+ if (item.role === "system" && (item.kind === "agent_joined" || item.kind === "agent_requested" || item.kind === "agent_present")) {
36945
36963
  return /* @__PURE__ */ jsx(
36946
36964
  AgentJoinedEvent,
36947
36965
  {
@@ -37227,7 +37245,7 @@ function SettoProvider({ config, children }) {
37227
37245
  pageStoreRef.current = new PageStore(bundledManifest(config.pages));
37228
37246
  setStoreReady(true);
37229
37247
  }, [i18n, config.theme, config.pages]);
37230
- const canEdit = !!session && access.currentSite?.status === "live" && !onAdminRoute && !authLoading && !access.loading;
37248
+ const canEdit = !!session && (access.currentSite?.status === "live" || !!access.currentSite && isSupportSession(session, config.siteId)) && !onAdminRoute && !authLoading && !access.loading;
37231
37249
  const [editing, setEditingState] = useState(() => readEditing(config.siteId));
37232
37250
  const setEditing = useCallback(
37233
37251
  (on) => {