@wix/himalaya-cli 0.1929.0 → 0.1931.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.
Files changed (187) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +2 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/icon-catalog.generated.d.ts +1 -1
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +7 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/chat-web/src/index.d.ts +12 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +77 -1
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +6 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-chat-web.mjs +19 -9
  8. package/dist/browser-plane/assets.json +5 -5
  9. package/dist/browser-plane/preview-deferred/{95a3ae045bad903e458ea7a5800e60e1044f0f754a65d7127de66ba62e897068.bin → eff56fd2ab5972c0c1053a214225f9d2858768f8e24845a6b99e17a2bf244fd4.bin} +1 -1
  10. package/dist/browser-plane/sw.js +9 -9
  11. package/dist/cli.mjs +332 -73
  12. package/dist/preview-assets.generated.bin +0 -0
  13. package/guides/component-index.md +1 -1
  14. package/guides/component-reference.json +1 -1
  15. package/guides/component-reference.md +7 -0
  16. package/guides/headless-loop.md +1 -1
  17. package/guides/sdk-reference.json +2 -2
  18. package/package.json +2 -2
  19. package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +1 -1
  20. package/templates/beauty-salon/tier5-src/_shared/owner-load-error.ts +1 -1
  21. package/templates/beauty-salon-owner/dev/index.ts +169 -139
  22. package/templates/beauty-salon-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  23. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  24. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  25. package/templates/beauty-salon-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  26. package/templates/beauty-salon-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  27. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  28. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  29. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  30. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  31. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  32. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  33. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  34. package/templates/beauty-salon-owner/tier5-src/wix-owner-booking/index.ts +4 -1
  35. package/templates/branded-lite/tier5-src/_shared/owner-load-error.ts +1 -1
  36. package/templates/brandy/tier5-src/_shared/owner-load-error.ts +1 -1
  37. package/templates/community-club/tier5-src/_shared/owner-load-error.ts +1 -1
  38. package/templates/community-club-owner/dev/index.ts +167 -132
  39. package/templates/community-club-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  40. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  41. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  42. package/templates/community-club-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  43. package/templates/community-club-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  44. package/templates/community-club-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  45. package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  46. package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  47. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  48. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  49. package/templates/community-club-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  50. package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  51. package/templates/conference/tier5-src/_shared/owner-load-error.ts +1 -1
  52. package/templates/events-meetups/tier5-src/_shared/owner-load-error.ts +1 -1
  53. package/templates/events-meetups-owner/dev/index.ts +165 -125
  54. package/templates/events-meetups-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  55. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  56. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  57. package/templates/events-meetups-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  58. package/templates/events-meetups-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  59. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  60. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  61. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  62. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  63. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  64. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  65. package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +1 -1
  66. package/templates/gym-fitness/tier5-src/_shared/owner-load-error.ts +1 -1
  67. package/templates/gym-fitness-owner/dev/index.ts +169 -139
  68. package/templates/gym-fitness-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  69. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  70. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  71. package/templates/gym-fitness-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  72. package/templates/gym-fitness-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  73. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  74. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  75. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  76. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  77. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  78. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  79. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  80. package/templates/gym-fitness-owner/tier5-src/wix-owner-booking/index.ts +4 -1
  81. package/templates/himi-chat/tier5-src/_shared/owner-load-error.ts +1 -1
  82. package/templates/medical-services/tier5-src/_shared/owner-load-error.ts +1 -1
  83. package/templates/nonprofit-cause/tier5-src/_shared/owner-load-error.ts +1 -1
  84. package/templates/nonprofit-cause-owner/dev/index.ts +167 -132
  85. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  86. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  87. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  88. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  89. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  90. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  91. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  92. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  93. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  94. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  95. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  96. package/templates/nonprofit-cause-owner/tier5-src/wix-owner-booking/index.ts +4 -1
  97. package/templates/owner-lite/dev/index.ts +171 -141
  98. package/templates/owner-lite/himalaya.content.json +1 -1
  99. package/templates/owner-lite/tier5-src/_shared/owner-load-error.ts +1 -1
  100. package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  101. package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  102. package/templates/owner-lite/tier5-src/_shared/owner-selected-site.ts +15 -0
  103. package/templates/owner-lite/tier5-src/_shared/owner-widget-reads.ts +7 -0
  104. package/templates/owner-lite/tier5-src/himi-owner-lite-home/index.ts +30 -8
  105. package/templates/owner-lite/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  106. package/templates/owner-lite/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  107. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  108. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  109. package/templates/owner-lite/tier5-src/himi-owner-lite-order/index.ts +4 -1
  110. package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +7 -1
  111. package/templates/owner-lite/tier5-src/wix-owner-booking/index.ts +4 -1
  112. package/templates/personal-fitness-trainer/tier5-src/_shared/owner-load-error.ts +1 -1
  113. package/templates/podcast-creator/tier5-src/_shared/owner-load-error.ts +1 -1
  114. package/templates/podcast-creator-owner/dev/index.ts +167 -132
  115. package/templates/podcast-creator-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  116. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  117. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  118. package/templates/podcast-creator-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  119. package/templates/podcast-creator-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  120. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  121. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  122. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  123. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  124. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  125. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  126. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  127. package/templates/portfolio-creative/tier5-src/_shared/owner-load-error.ts +1 -1
  128. package/templates/portfolio-creative-owner/dev/index.ts +169 -139
  129. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  130. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  131. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  132. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  133. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  134. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  135. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  136. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  137. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  138. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  139. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  140. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  141. package/templates/portfolio-creative-owner/tier5-src/wix-owner-booking/index.ts +4 -1
  142. package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +1 -1
  143. package/templates/restaurant/tier5-src/_shared/owner-load-error.ts +1 -1
  144. package/templates/restaurant-owner/dev/index.ts +169 -139
  145. package/templates/restaurant-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  146. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  147. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  148. package/templates/restaurant-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  149. package/templates/restaurant-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  150. package/templates/restaurant-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  151. package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  152. package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  153. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  154. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  155. package/templates/restaurant-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  156. package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  157. package/templates/restaurant-owner/tier5-src/wix-owner-booking/index.ts +4 -1
  158. package/templates/retail-store/tier5-src/_shared/owner-load-error.ts +1 -1
  159. package/templates/retail-store-owner/dev/index.ts +167 -132
  160. package/templates/retail-store-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  161. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  162. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  163. package/templates/retail-store-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  164. package/templates/retail-store-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  165. package/templates/retail-store-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  166. package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  167. package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  168. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  169. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  170. package/templates/retail-store-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
  171. package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  172. package/templates/salon-spa/tier5-src/_shared/owner-load-error.ts +1 -1
  173. package/templates/wholesale-store/tier5-src/_shared/owner-load-error.ts +1 -1
  174. package/templates/yoga-studio/tier5-src/_shared/owner-load-error.ts +1 -1
  175. package/templates/yoga-studio-owner/dev/index.ts +167 -132
  176. package/templates/yoga-studio-owner/tier5-src/_shared/owner-load-error.ts +1 -1
  177. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
  178. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
  179. package/templates/yoga-studio-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
  180. package/templates/yoga-studio-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
  181. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
  182. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
  183. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
  184. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
  185. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
  186. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
  187. package/templates/yoga-studio-owner/tier5-src/wix-owner-booking/index.ts +4 -1
@@ -12,10 +12,11 @@
12
12
  // when the record changes while it stays on screen, so the button can lag one visit behind the tab.
13
13
  // Shown too long, it opens the Maestro screen, which says so itself when Maestro is unavailable.
14
14
 
15
- import { readSelectedSite } from "./owner-selected-site.js";
15
+ import { navigate, type NavDirective } from "@himalaya/state";
16
+ import { currentBusinessId } from "./owner-selected-site.js";
16
17
 
17
18
  type StorageLike = { getItem(key: string): string | null; setItem(key: string, value: string): void };
18
- type Host = { storage?: StorageLike; input?: Record<string, unknown> };
19
+ type Host = { storage?: StorageLike };
19
20
  const host = (): Host | undefined => (globalThis as { himalaya?: Host }).himalaya;
20
21
 
21
22
  const KEY = "himi.ownerLite.maestroTab.v1";
@@ -36,7 +37,82 @@ export function maestroTabIsFor(site: string): boolean {
36
37
  * Maestro for the business on screen. The business is the one the host scoped, else the one
37
38
  * picked on Sites, as the Maestro screen reads it. */
38
39
  export function askMaestroHidden(): "true" | "false" {
39
- const scoped = host()?.input?.__himiPreferenceBusiness;
40
- const site = (typeof scoped === "string" ? scoped.trim() : "") || readSelectedSite()?.id || "";
41
- return maestroTabIsFor(site) ? "false" : "true";
40
+ return maestroTabIsFor(currentBusinessId()) ? "false" : "true";
41
+ }
42
+ // ── "Ask Maestro" from a detail screen ─────────────────────────────────────────────────────
43
+ // The detail screen's worker leaves the item here and switches to the Maestro tab; the Maestro
44
+ // screen's worker reads it when the tab appears. A screen param cannot carry it: a tab switch
45
+ // takes none. The request names the business it was left for, and is good for half a minute:
46
+ // the Maestro worker acts on each stamp once, for that business only, and a request the tab
47
+ // never picked up (the switch was dropped, or a turn was streaming there) is then ignored.
48
+ // It is dropped as soon as its chat is used (a first turn) or left (New chat), and when the
49
+ // owner changes. Not on the read itself: the Maestro screen loads twice as it opens, and both
50
+ // loads must find it.
51
+
52
+ const ASK_KEY = "himi.ownerLite.maestroAsk.v1";
53
+ const ASK_REQUEST_TTL_MS = 30_000;
54
+
55
+ export type AskMaestroKind = "order" | "booking" | "contact";
56
+ export interface AskMaestroRequest { kind: AskMaestroKind; id: string; subject: string; site: string; n: number }
57
+
58
+ export const isAskMaestroKind = (v: unknown): v is AskMaestroKind => v === "order" || v === "booking" || v === "contact";
59
+
60
+ /** Leave "ask Maestro about this item" for the Maestro tab. False when it could not be left
61
+ * (no id, no business, or a host without storage): the caller then opens the Maestro screen
62
+ * with params. */
63
+ export function requestAskMaestro(kind: unknown, id: unknown, subject: unknown, now: number): boolean {
64
+ const item = typeof id === "string" ? id.trim() : "";
65
+ const site = currentBusinessId();
66
+ if (!isAskMaestroKind(kind) || !item || !site) return false;
67
+ const storage = host()?.storage;
68
+ if (!storage) return false;
69
+ try {
70
+ storage.setItem(ASK_KEY, JSON.stringify({ kind, id: item, subject: typeof subject === "string" ? subject.trim() : "", site, n: now }));
71
+ return true;
72
+ } catch { return false; }
73
+ }
74
+
75
+ /** The request a detail screen left for `site`, while it is recent. */
76
+ export function pendingAskRequest(now: number, site: string): AskMaestroRequest | null {
77
+ try {
78
+ const raw = host()?.storage?.getItem(ASK_KEY);
79
+ if (!raw) return null;
80
+ const v = JSON.parse(raw) as Partial<AskMaestroRequest> | null;
81
+ if (!v || !isAskMaestroKind(v.kind) || typeof v.id !== "string" || !v.id || typeof v.n !== "number") return null;
82
+ // An item of another business is never asked about here: the owner switched in between.
83
+ if (!site || v.site !== site) return null;
84
+ if (now < v.n || now - v.n > ASK_REQUEST_TTL_MS) return null;
85
+ return { kind: v.kind, id: v.id, subject: typeof v.subject === "string" ? v.subject : "", site, n: v.n };
86
+ } catch { return null; }
87
+ }
88
+
89
+ /** Drop the request: its chat was used or left (`stamp`: only the request with that stamp, so a
90
+ * newer one a detail screen left meanwhile stays), or the owner changed (no stamp: whatever is
91
+ * there). Never throws. */
92
+ export function clearAskRequest(stamp?: number): void {
93
+ try {
94
+ const storage = host()?.storage;
95
+ if (!storage) return;
96
+ if (stamp !== undefined) {
97
+ const raw = storage.getItem(ASK_KEY);
98
+ if (!raw || (JSON.parse(raw) as { n?: unknown } | null)?.n !== stamp) return;
99
+ }
100
+ storage.setItem(ASK_KEY, "");
101
+ } catch { /* no storage on this host, or nothing readable there: nothing to drop */ }
102
+ }
103
+
104
+ /** A detail worker's `askMaestro` action: leave the item, then switch to the Maestro tab at its
105
+ * root: a tab left on History or on a past chat would otherwise show that, and the root is
106
+ * what reads the request. Every binary that can show the Maestro tab knows `{ tab, reset }`:
107
+ * the form shipped on 2026-10-27, and the tab needs the NDJSON stream of 2026-11-25.
108
+ * On a host where the item cannot be left, open the Maestro screen about it instead. */
109
+ export function askMaestroNav<S extends object>(state: S, arg: unknown): S & { _nav: NavDirective } {
110
+ const a = (arg && typeof arg === "object" ? arg : {}) as { kind?: unknown; id?: unknown; subject?: unknown };
111
+ if (requestAskMaestro(a.kind, a.id, a.subject, Date.now())) return navigate(state, { tab: "maestro", reset: true });
112
+ const args: Record<string, string> = {};
113
+ for (const key of ["kind", "id", "subject"] as const) {
114
+ const value = a[key];
115
+ if (typeof value === "string" && value) args[key] = value;
116
+ }
117
+ return navigate(state, { screenId: "himi_owner_lite_maestro", args });
42
118
  }
@@ -107,3 +107,18 @@ export function fallbackNameFrom(arg: unknown, current = ""): string {
107
107
  const v = (arg as { businessName?: unknown } | undefined)?.businessName;
108
108
  return typeof v === "string" && v.trim() ? v.trim() : current;
109
109
  }
110
+
111
+ /**
112
+ * The business the owner is working in, as an id for a call that must name it ("" = none known).
113
+ *
114
+ * The picked one first: the Sites pick records it at the moment of the switch, for every worker.
115
+ * The host's own scope (`__himiPreferenceBusiness`) is the fallback, not the first choice: a tab
116
+ * kept alive across a switch keeps the scope it was opened with (measured live 2026-11-28: after
117
+ * a switch the Inbox tab went on reading the first business, while Home read the new one).
118
+ */
119
+ export function currentBusinessId(): string {
120
+ const picked = readSelectedSite()?.id?.trim();
121
+ if (picked) return picked;
122
+ const scoped = (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input?.__himiPreferenceBusiness;
123
+ return typeof scoped === "string" ? scoped.trim() : "";
124
+ }
@@ -21,3 +21,10 @@ export function isSectionUnavailable(e: unknown): boolean {
21
21
  const text = String((e as Error)?.message ?? e);
22
22
  return /^HTTP (?:403|404|428)\b/.test(text) || /^HTTP \d{3} \[(?:FAILED_PRECONDITION|PERMISSION_DENIED)\]/.test(text);
23
23
  }
24
+
25
+ /** The business has not set this area up: its app is not installed on the site, which Wix
26
+ * answers with 428. Narrower than `isSectionUnavailable`: a 403 or a 404 may be a mistake
27
+ * worth showing, while this one is simply "nothing here". Read from the leading status only. */
28
+ export function isNotInstalled(e: unknown): boolean {
29
+ return /^HTTP 428\b/.test(String((e as Error)?.message ?? e));
30
+ }
@@ -19,10 +19,11 @@ import { getSiteAnalytics, getSiteTimeZone, localDateRange, localDateOf, localMi
19
19
  // `text(...)` and never matched on — the RAW reason is kept beside it in
20
20
  // `<part>Reason` for anything that needs it — so the display-only reduction is
21
21
  // both safe here and the reason a 428 reason code stopped reaching the owner.
22
- import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback } from "../_shared/owner-load-error.js";
22
+ import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback, SITE_CONTEXT_CODES } from "../_shared/owner-load-error.js";
23
+ import { isNotInstalled } from "../_shared/owner-widget-reads.js";
23
24
  import { DEMO_DASHBOARD, DEMO_NOTE, DEMO_TODAY } from "../_shared/owner-preview-demo.js";
24
25
  import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
25
- import { fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
26
+ import { currentBusinessId, fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
26
27
  import { settleBusinessSwitch } from "../_shared/owner-site-pick.js";
27
28
  import { formatCurrency } from "../_shared/engine-intl.js";
28
29
  import {
@@ -566,6 +567,14 @@ async function loadSourcePart(source: HomeSourceId, part: SourcePart): Promise<S
566
567
  }
567
568
  }
568
569
 
570
+ /** Wix refusing a read because the call names no business the session may read: a 403, or one
571
+ * of the "no site in this request" codes. Read from the leading status only. */
572
+ function isSiteRefusal(reason: unknown): boolean {
573
+ const text = String((reason as Error)?.message ?? reason);
574
+ const coded = /^HTTP \d{3} \[([A-Z0-9_]+)\]/.exec(text);
575
+ return /^HTTP 403\b/.test(text) || (!!coded && SITE_CONTEXT_CODES.includes(coded[1]));
576
+ }
577
+
569
578
  async function loadSource(source: HomeSourceId, parts = sourceParts(source)): Promise<SourceResult> {
570
579
  const settled = await Promise.allSettled(parts.map(async (part) => ({ part, payload: await loadSourcePart(source, part) })));
571
580
  const result: SourceResult = {};
@@ -662,20 +671,24 @@ function composeState(): HomeState {
662
671
  const now = Date.now();
663
672
  const sourceStates: SourceState[] = activeSources.map((id) => {
664
673
  const result = sourceResults.get(id);
665
- const primaryError = result?.primaryError ?? "";
666
- const activityError = result?.activityError ?? "";
667
- const metricsError = result?.metricsError ?? "";
674
+ // An area the business has not set up (Wix answers 428: its app is not on the site) has
675
+ // nothing to show and nothing to retry. It reads as empty, not as a failed card: a Space
676
+ // website with no store, events, reviews or reservations used to open on four red cards.
677
+ const absent = (part: SourcePart): boolean => result?.[`${part}Reason`] !== undefined && isNotInstalled(result[`${part}Reason`]);
678
+ const primaryError = absent("primary") ? "" : result?.primaryError ?? "";
679
+ const activityError = absent("activity") ? "" : result?.activityError ?? "";
680
+ const metricsError = absent("metrics") ? "" : result?.metricsError ?? "";
668
681
  const status: SourceStatus = primaryError ? "unavailable" : result?.primary
669
682
  ? (sourceIsEmpty(id, result) ? "empty" : "ready")
670
- : "loading";
683
+ : absent("primary") ? "empty" : "loading";
671
684
  const activityStatus: SourceState["activityStatus"] = !ACTIVITY_SOURCES.has(id) ? "not_applicable"
672
685
  : activityError ? "unavailable"
673
686
  : result?.activity ? (rowsFor(id, result.activity).length ? "ready" : "empty")
674
- : "loading";
687
+ : absent("activity") ? "empty" : "loading";
675
688
  const metricsStatus: SourceState["metricsStatus"] = id !== "orders" ? "not_applicable"
676
689
  : metricsError ? "unavailable"
677
690
  : result?.metrics ? (rowsFor(id, result.metrics).length ? "ready" : "empty")
678
- : "loading";
691
+ : absent("metrics") ? "empty" : "loading";
679
692
  const failedParts = [primaryError && "primary", metricsError && "metrics", activityError && "activity"].filter(Boolean);
680
693
  const retryLabel = failedParts.length === 1 && failedParts[0] !== "primary"
681
694
  ? `Retry ${SOURCE_LABELS[id]} ${failedParts[0]}`
@@ -802,6 +815,15 @@ async function loadDashboard(s: HomeState, sources: HomeSourceId[]): Promise<Hom
802
815
  for (const result of results) sourceResults.set(result.source, result.value);
803
816
  const successfulParts = results.flatMap(({ value }) => [value.primary, value.metrics, value.activity]).filter(Boolean);
804
817
  const failedReasons = results.flatMap(({ value }) => [value.primaryReason, value.metricsReason, value.activityReason]).filter((reason) => reason !== undefined);
818
+ // No business was ever picked, and Wix refused every read of one (the account's own site
819
+ // count aside): the session is at the account, not at a business. One line saying so replaces
820
+ // a card per area, each blaming a business (named after the app's own provisioning) that the
821
+ // owner never chose. A host that reads a business without naming one is left alone.
822
+ const readABusiness = results.some(({ source, value }) => source !== "sites" && (value.primary || value.metrics || value.activity));
823
+ if (!currentBusinessId() && !readABusiness && failedReasons.length > 0 && failedReasons.every(isSiteRefusal)) {
824
+ currentBusinessName = copyParam("ownerHome.noBusiness", "No business chosen");
825
+ return shape({ status: "error", error: copyParam("ownerHome.chooseBusiness", "Choose a business to see its day here. Tap Switch business.") });
826
+ }
805
827
  if (successfulParts.length === 0) {
806
828
  if (failedReasons.length > 0 && failedReasons.every((reason) => ownerDemoFallback(reason))) {
807
829
  return demoDashboard(shape({ ...s, sourceStates: [], sourceFailures: [] }));
@@ -23,6 +23,7 @@
23
23
 
24
24
  import { defineService, type PollDirective } from "@himalaya/state";
25
25
  import { listChatrooms, archiveChatroom, markChatroomUnread, type Chatroom } from "@himalaya/wix-chat-web";
26
+ import { currentBusinessId, readSelectedSite } from "../_shared/owner-selected-site.js";
26
27
  import { formatMonthDay } from "../_shared/engine-intl.js";
27
28
  import { ownerLoadError, ownerWriteError } from "../_shared/owner-load-error.js";
28
29
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
@@ -93,13 +94,38 @@ function relTime(ms?: number): string {
93
94
  return formatMonthDay(d);
94
95
  }
95
96
 
96
- export function rowOf(c: Chatroom): InboxRow {
97
+ /** The business a conversation belongs to, as the owner knows it ("" when Wix does not say). */
98
+ const businessOf = (c: Chatroom): string => (c.businessContext?.name || "").trim();
99
+
100
+ /**
101
+ * Whether each row must say which business it belongs to.
102
+ *
103
+ * Wix answers an owner with ONE inbox for the whole account: the same conversations whichever
104
+ * business the call names (measured live 2026-11-28, the calls addressed to two different
105
+ * businesses, the rows identical; each row carries its own `businessContext`). A row's business
106
+ * is not a site id, so the list cannot be cut down to the picked business. Without a label the
107
+ * owner reads another business's conversations as this one's. Rows are labelled when they come
108
+ * from more than one business, or from one that is not the business on screen. When the name of
109
+ * the business on screen is not known (a host that scoped it without a pick), there is nothing
110
+ * to compare with, so a business Wix names is always shown.
111
+ */
112
+ export function labelsBusiness(rooms: Chatroom[], pickedName: string): boolean {
113
+ const names = new Set(rooms.map(businessOf).filter(Boolean));
114
+ if (names.size > 1) return true;
115
+ const [only] = [...names];
116
+ if (!only) return false;
117
+ return !pickedName.trim() || only.toLowerCase() !== pickedName.trim().toLowerCase();
118
+ }
119
+
120
+ export function rowOf(c: Chatroom, withBusiness = false): InboxRow {
97
121
  const fallback = copyParam("ownerInbox.untitled", "Conversation");
98
122
  const display = (c.displayData?.name || c.lastMessage?.senderDisplayData?.name || "").trim() || fallback;
99
123
  const image = c.displayData?.image?.url || c.lastMessage?.senderDisplayData?.image?.url || "";
100
124
  const unread = Math.max(0, c.unreadCount ?? 0);
101
125
  const unreadText = unread > 0 ? (unread > 99 ? "99+" : String(unread)) : "";
102
- const subtitle = (c.lastMessage?.summary || "").trim().slice(0, 120);
126
+ const preview = (c.lastMessage?.summary || "").trim().slice(0, 120);
127
+ const business = withBusiness ? businessOf(c) : "";
128
+ const subtitle = [business, preview].filter(Boolean).join(" · ");
103
129
  const unreadLabel = unread === 0 ? "" : unread === 1
104
130
  ? copyParam("ownerInbox.oneUnread", "1 unread message")
105
131
  : `${unreadText} ${copyParam("ownerInbox.manyUnread", "unread messages")}`;
@@ -209,6 +235,8 @@ const archivedAt = new Map<string, number>();
209
235
  const unreadAt = new Map<string, { at: number; until: number }>();
210
236
  const UNREAD_GRACE_MS = 3000;
211
237
  let readGeneration = 0;
238
+ /** The business the last read was for. */
239
+ let readSite = "";
212
240
  /** The newest read whose answer reached the screen. Reads are not ordered — a `load` on
213
241
  * return can start a read while a poll tick's is still in flight — so an OLDER read that
214
242
  * finishes after a newer one is dropped instead of painting the past over it. */
@@ -222,8 +250,19 @@ let appliedGeneration = 0;
222
250
  */
223
251
  async function read(): Promise<InboxState> {
224
252
  const generation = ++readGeneration;
253
+ // Every call names the business: this tab is kept alive across a business switch, and its
254
+ // Wix connection stays on the business it was opened for. A switch also ends what was
255
+ // learnt about the last business's rows.
256
+ const site = currentBusinessId();
257
+ if (site !== readSite) {
258
+ readSite = site;
259
+ archivedAt.clear();
260
+ unreadAt.clear();
261
+ }
225
262
  try {
226
- const rooms = await listChatrooms(PAGE_SIZE);
263
+ const rooms = await listChatrooms(PAGE_SIZE, { siteId: site });
264
+ // The owner switched business while this was read: its rows are the last business's.
265
+ if (site !== currentBusinessId()) return liveState();
227
266
  // Stale first: a read older than one already painted changes nothing — not the screen,
228
267
  // and not the fences either.
229
268
  if (generation < appliedGeneration) return liveState();
@@ -231,9 +270,9 @@ async function read(): Promise<InboxState> {
231
270
  for (const [id, at] of archivedAt) if (at < generation && !rooms.some((c) => c?.id === id)) archivedAt.delete(id);
232
271
  const clock = Date.now();
233
272
  for (const [id, fence] of unreadAt) if (fence.at < generation && clock >= fence.until) unreadAt.delete(id);
234
- const all = rooms
235
- .filter((c) => c?.id && !c.isArchived && !archivedAt.has(c.id))
236
- .map((c) => rowOf(unreadAt.has(c.id) ? { ...c, unreadCount: Math.max(1, c.unreadCount ?? 0) } : c));
273
+ const listed = rooms.filter((c) => c?.id && !c.isArchived && !archivedAt.has(c.id));
274
+ const withBusiness = labelsBusiness(listed, readSelectedSite()?.name ?? "");
275
+ const all = listed.map((c) => rowOf(unreadAt.has(c.id) ? { ...c, unreadCount: Math.max(1, c.unreadCount ?? 0) } : c, withBusiness));
237
276
  const now = liveState();
238
277
  return shape({ status: "ready", all, filter: now.filter, query: now.query });
239
278
  } catch (e) {
@@ -274,7 +313,7 @@ const svc = defineService<InboxState, {
274
313
  const id = idOf(arg);
275
314
  if (!id) return s;
276
315
  try {
277
- await archiveChatroom(id, true);
316
+ await archiveChatroom(id, true, { siteId: currentBusinessId() });
278
317
  } catch (e) {
279
318
  return { ...liveState(), actionError: ownerWriteError(e) };
280
319
  }
@@ -287,7 +326,7 @@ const svc = defineService<InboxState, {
287
326
  const id = idOf(arg);
288
327
  if (!id) return s;
289
328
  try {
290
- await markChatroomUnread(id);
329
+ await markChatroomUnread(id, undefined, { siteId: currentBusinessId() });
291
330
  } catch (e) {
292
331
  return { ...liveState(), actionError: ownerWriteError(e) };
293
332
  }
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { defineService, navigate, type NavDirective, type PollDirective, type StreamDirective } from "@himalaya/state";
22
22
  import { getMessages, sendChatMessage, listChatrooms, markChatroomRead, getChatToken, type ChatMessage } from "@himalaya/wix-chat-web";
23
+ import { currentBusinessId } from "../_shared/owner-selected-site.js";
23
24
  import { formatMonthDayTime } from "../_shared/engine-intl.js";
24
25
  import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
25
26
  import { isOfflineFailure, ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
@@ -106,7 +107,7 @@ function headerOf(msgs: ChatMessage[], fallback: string): string {
106
107
 
107
108
  /** The conversation a contact is in, or "" when the owner's recent conversations have none. */
108
109
  async function chatroomForContact(contactId: string): Promise<{ id: string; name: string }> {
109
- const rooms = await listChatrooms(LOOKUP_SIZE);
110
+ const rooms = await listChatrooms(LOOKUP_SIZE, { siteId: threadSite });
110
111
  const room = rooms.find((r) => r?.id && r.participantId === contactId);
111
112
  return room ? { id: room.id, name: (room.displayData?.name || "").trim() } : { id: "", name: "" };
112
113
  }
@@ -114,15 +115,20 @@ async function chatroomForContact(contactId: string): Promise<{ id: string; name
114
115
  // The conversation the gate re-reads. Module state, not worker state: a re-read must use
115
116
  // the conversation this screen opened even if an older state object is in flight.
116
117
  let current = "";
118
+ // The business this thread was opened in. Read once per open, with the visit token: a thread
119
+ // belongs to one business, and a switch while it is on screen must not send its calls (or a
120
+ // token minted for the first business) to the other one.
121
+ let threadSite = "";
117
122
  let realtime: ChatRealtimeConfig | null = null;
118
123
 
119
124
  // ONE chatToken per visit (`_shared/chat-live.ts`): a 4 s re-read would otherwise mint a
120
125
  // token every 4 s on top of its GET. Reset on every open.
121
- const visitToken = createVisitToken(() => getChatToken().then((t) => t.chatToken));
126
+ // Every call names the business the thread was opened in (`threadSite`), as the Inbox list names its own.
127
+ const visitToken = createVisitToken(() => getChatToken({ siteId: threadSite }).then((t) => t.chatToken));
122
128
  async function readThread(): Promise<ChatMessage[]> {
123
129
  const token = visitToken.get();
124
130
  try {
125
- return await getMessages(current, PAGE_SIZE, { chatToken: await token });
131
+ return await getMessages(current, PAGE_SIZE, { chatToken: await token, siteId: threadSite });
126
132
  } catch (e) {
127
133
  visitToken.drop(token);
128
134
  throw e;
@@ -135,7 +141,7 @@ const intents = createSendIntents();
135
141
  /** Post once per intent: a retried tap of the same text reuses its message id. */
136
142
  async function postOnce(chatroomId: string, text: string): Promise<void> {
137
143
  const messageId = intents.idFor(chatroomId, text);
138
- await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId }));
144
+ await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId, siteId: threadSite }));
139
145
  intents.settle(chatroomId, text);
140
146
  }
141
147
 
@@ -154,7 +160,7 @@ function markRead(chatroomId: string, msgs: ChatMessage[]): void {
154
160
  if (seq === undefined || seq <= (markedUpTo.get(chatroomId) ?? -1)) return;
155
161
  markedUpTo.set(chatroomId, seq);
156
162
  void visitToken.get()
157
- .then((t) => markChatroomRead(chatroomId, seq, { chatToken: t }))
163
+ .then((t) => markChatroomRead(chatroomId, seq, { chatToken: t, siteId: threadSite }))
158
164
  .catch(() => {
159
165
  if (markedUpTo.get(chatroomId) === seq) markedUpTo.delete(chatroomId);
160
166
  });
@@ -229,6 +235,7 @@ const svc = defineService<ThreadState, {
229
235
  const { id, kind } = input();
230
236
  if (!id) return { ...s, ...presence("missing"), status: "ready", phase: "ready", messages: [], hideEmpty: true, live: "off" };
231
237
  visitToken.reset();
238
+ threadSite = currentBusinessId();
232
239
 
233
240
  let chatroomId = id;
234
241
  let headerName = s.headerName;