@wix/himalaya-cli 0.1937.0 → 0.1938.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 (124) hide show
  1. package/dist/cli.mjs +1 -0
  2. package/package.json +2 -2
  3. package/templates/beauty-salon-owner/config.ts +12 -2
  4. package/templates/beauty-salon-owner/dev/index.ts +1200 -69
  5. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  6. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  7. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  8. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  9. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  10. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  11. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  12. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  13. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  14. package/templates/community-club-owner/config.ts +12 -2
  15. package/templates/community-club-owner/dev/index.ts +1200 -69
  16. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  17. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  18. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  19. package/templates/community-club-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  20. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  21. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  22. package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  23. package/templates/community-club-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  24. package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  25. package/templates/events-meetups-owner/config.ts +12 -2
  26. package/templates/events-meetups-owner/dev/index.ts +1178 -69
  27. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  28. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  29. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  30. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  31. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  32. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  33. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  34. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  35. package/templates/gym-fitness-owner/config.ts +12 -2
  36. package/templates/gym-fitness-owner/dev/index.ts +1222 -69
  37. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  38. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  39. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  40. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  41. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  42. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  43. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  44. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  45. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  46. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  47. package/templates/nonprofit-cause-owner/config.ts +12 -2
  48. package/templates/nonprofit-cause-owner/dev/index.ts +1200 -69
  49. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  50. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  51. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  52. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  53. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  54. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  55. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  56. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  57. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  58. package/templates/owner-lite/config.ts +12 -2
  59. package/templates/owner-lite/dev/index.ts +1222 -69
  60. package/templates/owner-lite/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  61. package/templates/owner-lite/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  62. package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  63. package/templates/owner-lite/tier5-src/himi-owner-lite-event/index.ts +12 -1
  64. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  65. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  66. package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +12 -1
  67. package/templates/owner-lite/tier5-src/himi-owner-lite-product/index.ts +12 -1
  68. package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +3 -3
  69. package/templates/owner-lite/tier5-src/himi-owner-lite-service/index.ts +12 -1
  70. package/templates/podcast-creator-owner/config.ts +12 -2
  71. package/templates/podcast-creator-owner/dev/index.ts +1200 -69
  72. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  73. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  74. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  75. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  76. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  77. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  78. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  79. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  80. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  81. package/templates/portfolio-creative-owner/config.ts +12 -2
  82. package/templates/portfolio-creative-owner/dev/index.ts +1200 -69
  83. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  84. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  85. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  86. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  87. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  88. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  89. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  90. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  91. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  92. package/templates/restaurant-owner/config.ts +12 -2
  93. package/templates/restaurant-owner/dev/index.ts +1222 -69
  94. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  95. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  96. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  97. package/templates/restaurant-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  98. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  99. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  100. package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  101. package/templates/restaurant-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  102. package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  103. package/templates/restaurant-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  104. package/templates/retail-store-owner/config.ts +12 -2
  105. package/templates/retail-store-owner/dev/index.ts +1178 -69
  106. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  107. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  108. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  109. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  110. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  111. package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  112. package/templates/retail-store-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  113. package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  114. package/templates/yoga-studio-owner/config.ts +12 -2
  115. package/templates/yoga-studio-owner/dev/index.ts +1200 -69
  116. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  117. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  118. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  119. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  120. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  121. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  122. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  123. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  124. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
@@ -9,8 +9,9 @@ import { formatClock, formatMonthDayTime } from "../_shared/engine-intl.js";
9
9
  import { defineService } from "@himalaya/state";
10
10
  import { copyParam, stashCopy } from "../_shared/himi-copy.js";
11
11
  import { currentBusinessId } from "../_shared/owner-selected-site.js";
12
+ import { noteDeletedChat } from "../_shared/owner-maestro-tab.js";
12
13
  import { symphonyAccount, type MaestroWixApi } from "../_shared/owner-maestro-availability.js";
13
- import { pastChats, type PastChat } from "../_shared/owner-maestro-chat.js";
14
+ import { deleteChat, pastChats, pinChat, renameChat, type PastChat } from "../_shared/owner-maestro-chat.js";
14
15
 
15
16
  interface Host { wixApi?: MaestroWixApi; input?: Record<string, unknown> }
16
17
  const host = (): Host => (globalThis as { himalaya?: Host }).himalaya ?? {};
@@ -20,20 +21,45 @@ function activeSiteId(): string {
20
21
  return currentBusinessId();
21
22
  }
22
23
 
23
- /** `stamp` marks the list a row was shown in, so opening the same chat from a later list is a new request. */
24
- export interface HistoryRow { id: string; title: string; subtitle: string; section: string; stamp: string }
24
+ /** One chat. `stamp` marks the list a row was shown in, so opening the same chat from a later
25
+ * list is a new request. The `*Hidden` flags pick which strip shows under the row: its
26
+ * actions, the delete question, or nothing. */
27
+ export interface HistoryRow {
28
+ id: string; title: string; subtitle: string; section: string; stamp: string;
29
+ pinnedHidden: string; pinLabel: string; menuHidden: string; confirmHidden: string;
30
+ }
25
31
 
26
32
  export interface MaestroHistoryState {
27
33
  items: HistoryRow[];
28
34
  itemsHidden: string;
29
- /** Says the owner has no past chats ("" collapses the line). */
35
+ /** Says the owner has no past chats, or that none match the search ("" collapses the line). */
30
36
  emptyText: string;
31
37
  /** Says the list could not be read, which is not the same as having none. */
32
38
  error: string;
33
39
  errorHidden: string;
40
+ /** Search over the chats' names, and whether the field shows (only with chats to search). */
41
+ query: string;
42
+ searchHidden: string;
43
+ /** A change Symphony did not take ("" collapses the line). */
44
+ actionError: string;
45
+ /** Renaming one chat: whether the form shows, and the name being typed. */
46
+ renameHidden: string;
47
+ renameText: string;
48
+ /** Every chat of this business as read, before the search narrows it. */
49
+ _chats: PastChat[];
50
+ /** The row whose actions show, the one being asked "delete?", and the one being renamed. */
51
+ _open: string;
52
+ _confirm: string;
53
+ _rename: string;
34
54
  }
35
55
 
36
- const initial: MaestroHistoryState = { items: [], itemsHidden: "true", emptyText: "", error: "", errorHidden: "true" };
56
+ const initial: MaestroHistoryState = {
57
+ items: [], itemsHidden: "true", emptyText: "", error: "", errorHidden: "true",
58
+ query: "", searchHidden: "true", actionError: "", renameHidden: "true", renameText: "",
59
+ _chats: [], _open: "", _confirm: "", _rename: "",
60
+ };
61
+
62
+ const EVERY_FIELD = Object.keys(initial) as Array<keyof MaestroHistoryState>;
37
63
 
38
64
  const DAY = 24 * 60 * 60 * 1000;
39
65
 
@@ -61,31 +87,93 @@ function whenLabel(updated: string, now: number): string {
61
87
  return at >= midnight.getTime() ? formatClock(new Date(at)) : formatMonthDayTime(new Date(at));
62
88
  }
63
89
 
64
- /** Rows in the order given, with the bucket named on the first row of each bucket only. */
65
- function rowsOf(chats: PastChat[], now: number): HistoryRow[] {
90
+ /** Rows: pinned chats first under their own heading, then by recency, each heading named on
91
+ * its first row only. */
92
+ function rowsOf(chats: PastChat[], now: number, s: Pick<MaestroHistoryState, "_open" | "_confirm">): HistoryRow[] {
93
+ const ordered = [...chats.filter((c) => c.pinned), ...chats.filter((c) => !c.pinned)];
66
94
  let last = "";
67
- return chats.map((c) => {
68
- const bucket = bucketOf(c.updated, now);
95
+ return ordered.map((c) => {
96
+ const bucket = c.pinned ? copyParam("ownerMaestroHistory.pinned", "Pinned") : bucketOf(c.updated, now);
69
97
  const section = bucket === last ? "" : bucket;
70
98
  last = bucket;
71
- return { id: c.id, title: c.title || copyParam("ownerMaestroHistory.untitled", "Untitled conversation"), subtitle: whenLabel(c.updated, now), section, stamp: String(now) };
99
+ return {
100
+ id: c.id, title: c.title || copyParam("ownerMaestroHistory.untitled", "Untitled conversation"), subtitle: whenLabel(c.updated, now), section, stamp: String(now),
101
+ pinnedHidden: c.pinned ? "false" : "true",
102
+ pinLabel: c.pinned ? copyParam("ownerMaestroHistory.unpin", "Unpin") : copyParam("ownerMaestroHistory.pin", "Pin"),
103
+ menuHidden: s._open === c.id && s._confirm !== c.id ? "false" : "true",
104
+ confirmHidden: s._confirm === c.id ? "false" : "true",
105
+ };
72
106
  });
73
107
  }
74
108
 
75
- const none = (): MaestroHistoryState =>
76
- ({ ...initial, emptyText: copyParam("ownerMaestroHistory.empty", "No past conversations yet.") });
109
+ /** The state as the screen shows it: the chats the search keeps, and the lines that follow. */
110
+ function shown(s: MaestroHistoryState): MaestroHistoryState {
111
+ const q = s.query.trim().toLowerCase();
112
+ const kept = q ? s._chats.filter((c) => c.title.toLowerCase().includes(q)) : s._chats;
113
+ const items = rowsOf(kept, Date.now(), s);
114
+ return {
115
+ ...s, items, itemsHidden: items.length ? "false" : "true",
116
+ searchHidden: s._chats.length ? "false" : "true",
117
+ emptyText: items.length ? ""
118
+ : s._chats.length ? copyParam("ownerMaestroHistory.noMatch", "No conversations match that search.")
119
+ : copyParam("ownerMaestroHistory.empty", "No past conversations yet."),
120
+ renameHidden: s._rename ? "false" : "true",
121
+ };
122
+ }
123
+
124
+ const none = (): MaestroHistoryState => shown(initial);
77
125
  const failed = (): MaestroHistoryState =>
78
126
  ({ ...initial, error: copyParam("ownerMaestroHistory.failed", "Your conversations couldn't be loaded. Try again in a moment."), errorHidden: "false" });
127
+ const changeFailed = (): string => copyParam("ownerMaestroHistory.changeFailed", "That didn't go through. Try again in a moment.");
128
+
129
+ const idOf = (arg: unknown): string => {
130
+ const id = (arg as { id?: unknown } | undefined)?.id;
131
+ return typeof id === "string" ? id : "";
132
+ };
133
+ const textOf = (arg: unknown): string => {
134
+ if (typeof arg === "string") return arg;
135
+ for (const key of ["value", "text"] as const) {
136
+ const v = (arg as Record<string, unknown> | undefined)?.[key];
137
+ if (typeof v === "string") return v;
138
+ }
139
+ return "";
140
+ };
141
+
142
+ // One change at a time: each result is built from the state it started with.
143
+ let changing = false;
144
+
145
+ /** Make one change in Symphony, then apply it to the list read earlier. A change Symphony did
146
+ * not take leaves the list as it was and says so. */
147
+ async function change(s: MaestroHistoryState, call: (api: MaestroWixApi) => Promise<PastChat[]>): Promise<MaestroHistoryState> {
148
+ const api = host().wixApi;
149
+ if (changing || !api) return s;
150
+ changing = true;
151
+ try {
152
+ const chats = await call(api);
153
+ return shown({ ...s, _chats: chats, _open: "", _confirm: "", _rename: "", renameText: "", actionError: "" });
154
+ } catch {
155
+ return shown({ ...s, _confirm: "", actionError: changeFailed() });
156
+ } finally { changing = false; }
157
+ }
79
158
 
80
159
  const svc = defineService<MaestroHistoryState, {
81
160
  load: (s: MaestroHistoryState, arg?: unknown) => Promise<MaestroHistoryState>;
161
+ search: (s: MaestroHistoryState, arg?: unknown) => MaestroHistoryState;
162
+ more: (s: MaestroHistoryState, arg?: unknown) => MaestroHistoryState;
163
+ pin: (s: MaestroHistoryState, arg?: unknown) => Promise<MaestroHistoryState>;
164
+ askDelete: (s: MaestroHistoryState, arg?: unknown) => MaestroHistoryState;
165
+ cancel: (s: MaestroHistoryState) => MaestroHistoryState;
166
+ confirmDelete: (s: MaestroHistoryState, arg?: unknown) => Promise<MaestroHistoryState>;
167
+ rename: (s: MaestroHistoryState, arg?: unknown) => MaestroHistoryState;
168
+ setName: (s: MaestroHistoryState, arg?: unknown) => MaestroHistoryState;
169
+ saveName: (s: MaestroHistoryState) => Promise<MaestroHistoryState>;
82
170
  }>("himiOwnerLiteMaestroHistory", {
83
171
  state: initial,
84
172
  // The list is read again on every appear and is never shown from an earlier run.
85
- notPersisted: ["items", "itemsHidden", "emptyText", "error", "errorHidden"],
86
- notHydrated: ["items", "itemsHidden", "emptyText", "error", "errorHidden"],
173
+ notPersisted: EVERY_FIELD,
174
+ notHydrated: EVERY_FIELD,
87
175
  actions: {
88
- load: async (_s, arg) => {
176
+ load: async (s, arg) => {
89
177
  stashCopy(arg);
90
178
  const site = activeSiteId();
91
179
  const api = host().wixApi;
@@ -94,12 +182,54 @@ const svc = defineService<MaestroHistoryState, {
94
182
  // No Symphony account means no chats: the list call would only be refused.
95
183
  if (!(await symphonyAccount(api))) return none();
96
184
  const chats = await pastChats(api, site);
97
- if (!chats.length) return none();
98
- return { ...initial, items: rowsOf(chats, Date.now()), itemsHidden: "false" };
185
+ // The search the owner typed is kept across a re-read; what was open on a row is not.
186
+ return shown({ ...initial, _chats: chats, query: s.query ?? "" });
99
187
  } catch {
100
188
  return failed();
101
189
  }
102
190
  },
191
+ // Over the names of the chats read: Symphony's own search cannot be asked for one business.
192
+ search: (s, arg) => shown({ ...s, query: textOf(arg), _open: "", _confirm: "" }),
193
+ // A row's actions: Pin, Rename, Delete. Tapping the same row again puts them away.
194
+ more: (s, arg) => {
195
+ const id = idOf(arg);
196
+ return shown({ ...s, _open: s._open === id ? "" : id, _confirm: "", actionError: "" });
197
+ },
198
+ pin: async (s, arg) => {
199
+ const chat = s._chats.find((c) => c.id === idOf(arg));
200
+ if (!chat) return s;
201
+ return change(s, async (api) => {
202
+ await pinChat(api, chat.id, !chat.pinned);
203
+ return s._chats.map((c) => (c.id === chat.id ? { ...c, pinned: !chat.pinned } : c));
204
+ });
205
+ },
206
+ askDelete: (s, arg) => (s._chats.some((c) => c.id === idOf(arg)) ? shown({ ...s, _confirm: idOf(arg), actionError: "" }) : s),
207
+ cancel: (s) => shown({ ...s, _open: "", _confirm: "", _rename: "", renameText: "", actionError: "" }),
208
+ confirmDelete: async (s, arg) => {
209
+ const id = idOf(arg);
210
+ // Only the chat the owner was just asked about.
211
+ if (!id || s._confirm !== id) return s;
212
+ return change(s, async (api) => {
213
+ await deleteChat(api, id);
214
+ // The Maestro screen may have this chat open: it must not go on writing into it.
215
+ noteDeletedChat(id);
216
+ return s._chats.filter((c) => c.id !== id);
217
+ });
218
+ },
219
+ rename: (s, arg) => {
220
+ const chat = s._chats.find((c) => c.id === idOf(arg));
221
+ return chat ? shown({ ...s, _rename: chat.id, renameText: chat.title, _open: "", _confirm: "", actionError: "" }) : s;
222
+ },
223
+ setName: (s, arg) => ({ ...s, renameText: textOf(arg) }),
224
+ saveName: async (s) => {
225
+ const id = s._rename;
226
+ const name = s.renameText.replace(/\s+/g, " ").trim().slice(0, 120);
227
+ if (!id || !name) return s;
228
+ return change(s, async (api) => {
229
+ const kept = await renameChat(api, id, name);
230
+ return s._chats.map((c) => (c.id === id ? { ...c, title: kept } : c));
231
+ });
232
+ },
103
233
  },
104
234
  });
105
235
 
@@ -6,6 +6,7 @@ import { postCoverUrl } from "../_shared/owner-post-content.js";
6
6
  // Modeled on himi-blog-owner-post; write verbs use the wix-blog draft lifecycle.
7
7
 
8
8
  import { defineService } from "@himalaya/state";
9
+ import { askMaestroHidden, askMaestroNav } from "../_shared/owner-maestro-tab.js";
9
10
  import { getPost, getDraftPost, publishDraftPost, revertDraftPost, deleteDraftPost } from "@himalaya/wix-blog";
10
11
  import { parseRicosJson } from "@himalaya/wix-rich-content";
11
12
  import { openRichLink } from "../_shared/rich-content-link.js";
@@ -38,6 +39,8 @@ async function cacheBodyText(s: PostState): Promise<void> {
38
39
  }
39
40
 
40
41
  interface PostState {
42
+ /** "false" while the assistant tab is Maestro for this business: shows "Ask Maestro". */
43
+ askMaestroHidden: string;
41
44
  id: string;
42
45
  /** Edit-form target for the loaded entity (canonical detail descriptors bind
43
46
  * this — the id is only known at runtime under WS-C nav params). */
@@ -128,7 +131,11 @@ const FACT_KEYS = ["postStatus", "category", "published", "updated"] as const;
128
131
 
129
132
  function shape(s: Partial<PostState>): PostState {
130
133
  const out = shapeFields(s);
131
- return { ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS) };
134
+ return {
135
+ ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS),
136
+ // "Ask Maestro" shows only for a loaded record, while the assistant tab is Maestro.
137
+ askMaestroHidden: out.status === "ready" && out.id ? askMaestroHidden() : "true",
138
+ };
132
139
  }
133
140
 
134
141
  function shapeFields(s: Partial<PostState>): PostState {
@@ -139,6 +146,7 @@ function shapeFields(s: Partial<PostState>): PostState {
139
146
  const isLoading = status === "loading";
140
147
  const published = raw === "PUBLISHED" || raw === "SCHEDULED";
141
148
  return {
149
+ askMaestroHidden: "true", // `shape` decides it
142
150
  id: s.id ?? "",
143
151
  // WS-C — CANONICAL form target (the entity `id` rides as a separate nav
144
152
  // param the descriptor binds; suffixed `_form_<id>` was #570 and 404s on
@@ -340,6 +348,7 @@ const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
340
348
  const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
341
349
 
342
350
  const svc = defineService<PostState, {
351
+ askMaestro: (s: PostState) => PostState;
343
352
  load: (s: PostState, arg?: unknown) => Promise<PostState>;
344
353
  retry: (s: PostState) => Promise<PostState>;
345
354
  publish: (s: PostState) => Promise<PostState>;
@@ -355,6 +364,8 @@ const svc = defineService<PostState, {
355
364
  // perVisit: a cached embed's warm return starts this run fresh, as a cold boot does (`__resetRunState`).
356
365
  perVisit: [...DELETE_RUN_KEYS],
357
366
  actions: {
367
+ // "Ask Maestro": the chat opens on the Maestro tab, about this post.
368
+ askMaestro: (s) => askMaestroNav(s, { kind: "post", id: s.id, subject: s.title }),
358
369
  load: async (s0, arg) => {
359
370
  const s = disarm(s0);
360
371
  stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
@@ -7,6 +7,7 @@ import { openRichLink } from "../_shared/rich-content-link.js";
7
7
  // generic buildDetail descriptor ($service:himiOwnerLiteProduct.*).
8
8
 
9
9
  import { defineService } from "@himalaya/state";
10
+ import { askMaestroHidden, askMaestroNav } from "../_shared/owner-maestro-tab.js";
10
11
  import { getProduct, updateProduct, deleteProduct, type WixProduct } from "@himalaya/wix-stores";
11
12
  import { productImage, wixMediaUrl, WIX_DETAIL_IMAGE, type StoreProduct } from "../_shared/himi-store.js";
12
13
  import { ownerLoadError, isOwnerPreviewDemo, ownerDemoFallback, ownerWriteError, isNotFound } from "../_shared/owner-load-error.js";
@@ -27,6 +28,8 @@ async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTIT
27
28
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
28
29
 
29
30
  interface ProductState {
31
+ /** "false" while the assistant tab is Maestro for this business: shows "Ask Maestro". */
32
+ askMaestroHidden: string;
30
33
  id: string;
31
34
  /** Edit-form target for the loaded entity (canonical detail descriptors bind
32
35
  * this — the id is only known at runtime under WS-C nav params). */
@@ -120,7 +123,11 @@ const FACT_KEYS = ["price", "statusLabel", "sku", "inventory"] as const;
120
123
 
121
124
  function shape(s: Partial<ProductState>): ProductState {
122
125
  const out = shapeFields(s);
123
- return { ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS) };
126
+ return {
127
+ ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS),
128
+ // "Ask Maestro" shows only for a loaded record, while the assistant tab is Maestro.
129
+ askMaestroHidden: out.status === "ready" && out.id ? askMaestroHidden() : "true",
130
+ };
124
131
  }
125
132
 
126
133
  function shapeFields(s: Partial<ProductState>): ProductState {
@@ -130,6 +137,7 @@ function shapeFields(s: Partial<ProductState>): ProductState {
130
137
  const hasEntity = !!s.title && status === "ready";
131
138
  const isLoading = status === "loading";
132
139
  return {
140
+ askMaestroHidden: "true", // `shape` decides it
133
141
  id: s.id ?? "",
134
142
  // WS-C — CANONICAL form target (the entity `id` rides as a separate nav
135
143
  // param the descriptor binds; suffixed `_form_<id>` was #570 and 404s on
@@ -316,6 +324,7 @@ const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
316
324
  const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
317
325
 
318
326
  const svc = defineService<ProductState, {
327
+ askMaestro: (s: ProductState) => ProductState;
319
328
  load: (s: ProductState, arg?: unknown) => Promise<ProductState>;
320
329
  retry: (s: ProductState) => Promise<ProductState>;
321
330
  show: (s: ProductState) => Promise<ProductState>;
@@ -330,6 +339,8 @@ const svc = defineService<ProductState, {
330
339
  // perVisit: a cached embed's warm return starts this run fresh, as a cold boot does (`__resetRunState`).
331
340
  perVisit: [...DELETE_RUN_KEYS],
332
341
  actions: {
342
+ // "Ask Maestro": the chat opens on the Maestro tab, about this product.
343
+ askMaestro: (s) => askMaestroNav(s, { kind: "product", id: s.id, subject: s.title }),
333
344
  openLink: async (_state, arg): Promise<ProductState> => {
334
345
  const opened = await openRichLink(arg);
335
346
  const failed = copyParam("ownerProduct.linkOpenFailed", "This link could not be opened.");
@@ -19,10 +19,10 @@ const svc = defineService('himiOwnerRecord', {
19
19
  notLoading: false, notErrored: true, hideContent: true, handoffError: '' } as State,
20
20
  actions: {
21
21
  // "Ask Maestro": the chat opens on the Maestro tab, about this record.
22
- // The screen says what kind of record this is (only a contact's detail has the button). No
23
- // subject: a contact's title is a person's name, which the Maestro worker reads itself.
22
+ // The screen says what kind of record this is. The record's title names it, except where
23
+ // the title is a person's name (`askMaestroNav` leaves those out).
24
24
  askMaestro(state: State, arg?: unknown): State {
25
- return askMaestroNav(state, { kind: (arg as { kind?: unknown } | undefined)?.kind, id: state.id });
25
+ return askMaestroNav(state, { kind: (arg as { kind?: unknown } | undefined)?.kind, id: state.id, subject: state.title });
26
26
  },
27
27
  async load(state: State, arg?: unknown): Promise<State | undefined> {
28
28
  stashCopy(arg);
@@ -8,6 +8,7 @@ import { openRichLink } from "../_shared/rich-content-link.js";
8
8
  // generated WixServiceWrite) — this is a management read view for now.
9
9
 
10
10
  import { defineService } from "@himalaya/state";
11
+ import { askMaestroHidden, askMaestroNav } from "../_shared/owner-maestro-tab.js";
11
12
  import { getService, deleteService, type WixService } from "@himalaya/wix-bookings";
12
13
  import { ownerLoadError, isOwnerPreviewDemo, ownerDemoFallback, ownerWriteError, isNotFound } from "../_shared/owner-load-error.js";
13
14
  import { DEMO_SERVICES, DEMO_NOTE, DEMO_SAVE_NOTE } from "../_shared/owner-preview-demo.js";
@@ -29,6 +30,8 @@ async function cacheDrop(id: string): Promise<void> { try { await dbRemove(ENTIT
29
30
  async function cacheGet(id: string): Promise<DbEntity | null> { try { return await dbGet(ENTITY, id); } catch { return null; } }
30
31
 
31
32
  interface ServiceState {
33
+ /** "false" while the assistant tab is Maestro for this business: shows "Ask Maestro". */
34
+ askMaestroHidden: string;
32
35
  id: string;
33
36
  /** Edit-form target for the loaded entity (canonical detail descriptors bind
34
37
  * this — the id is only known at runtime under WS-C nav params). */
@@ -109,7 +112,11 @@ const FACT_KEYS = ["typeLabel", "category", "capacity"] as const;
109
112
 
110
113
  function shape(s: Partial<ServiceState>): ServiceState {
111
114
  const out = shapeFields(s);
112
- return { ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS) };
115
+ return {
116
+ ...out, ...blankFlags(out as unknown as Record<string, unknown>, FACT_KEYS),
117
+ // "Ask Maestro" shows only for a loaded record, while the assistant tab is Maestro.
118
+ askMaestroHidden: out.status === "ready" && out.id ? askMaestroHidden() : "true",
119
+ };
113
120
  }
114
121
 
115
122
  function shapeFields(s: Partial<ServiceState>): ServiceState {
@@ -118,6 +125,7 @@ function shapeFields(s: Partial<ServiceState>): ServiceState {
118
125
  const hasEntity = !!s.title && status === "ready";
119
126
  const isLoading = status === "loading";
120
127
  return {
128
+ askMaestroHidden: "true", // `shape` decides it
121
129
  id: s.id ?? "",
122
130
  // WS-C — CANONICAL form target (the entity `id` rides as a separate nav
123
131
  // param the descriptor binds; suffixed `_form_<id>` was #570 and 404s on
@@ -236,6 +244,7 @@ async function refresh(prev: ServiceState, id: string): Promise<ServiceState> {
236
244
  }
237
245
 
238
246
  const svc = defineService<ServiceState, {
247
+ askMaestro: (s: ServiceState) => ServiceState;
239
248
  load: (s: ServiceState, arg?: unknown) => Promise<ServiceState>;
240
249
  retry: (s: ServiceState) => Promise<ServiceState>;
241
250
  delete: (s: ServiceState) => Promise<ServiceState>;
@@ -243,6 +252,8 @@ const svc = defineService<ServiceState, {
243
252
  }>("himiOwnerLiteService", {
244
253
  state: shape({ status: "loading" }),
245
254
  actions: {
255
+ // "Ask Maestro": the chat opens on the Maestro tab, about this service.
256
+ askMaestro: (s) => askMaestroNav(s, { kind: "service", id: s.id, subject: s.title }),
246
257
  openLink: async (_state, arg): Promise<ServiceState> => {
247
258
  const opened = await openRichLink(arg);
248
259
  const failed = copyParam("ownerService.linkOpenFailed", "This link could not be opened.");
@@ -610,7 +610,12 @@ export default defineApp({
610
610
  "label": "Maestro",
611
611
  "icon": "ai",
612
612
  "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
613
- "hiddenUntilResolved": true
613
+ "hiddenUntilResolved": true,
614
+ "badge": {
615
+ "kind": "count",
616
+ "valuePath": "$service:ownerLiteNav.maestroWaiting",
617
+ "countLabel": "waiting on you"
618
+ }
614
619
  },
615
620
  {
616
621
  "id": "manage",
@@ -649,7 +654,12 @@ export default defineApp({
649
654
  "label": "Maestro",
650
655
  "icon": "ai",
651
656
  "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
652
- "hiddenUntilResolved": true
657
+ "hiddenUntilResolved": true,
658
+ "badge": {
659
+ "kind": "count",
660
+ "valuePath": "$service:ownerLiteNav.maestroWaiting",
661
+ "countLabel": "waiting on you"
662
+ }
653
663
  },
654
664
  {
655
665
  "id": "manage",