@wix/himalaya-cli 0.1936.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 (123) hide show
  1. package/package.json +2 -2
  2. package/templates/beauty-salon-owner/config.ts +12 -2
  3. package/templates/beauty-salon-owner/dev/index.ts +1200 -69
  4. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  5. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  6. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  7. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  8. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  9. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  10. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  11. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  12. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  13. package/templates/community-club-owner/config.ts +12 -2
  14. package/templates/community-club-owner/dev/index.ts +1200 -69
  15. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  16. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  17. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  18. package/templates/community-club-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  19. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  20. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  21. package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  22. package/templates/community-club-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  23. package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  24. package/templates/events-meetups-owner/config.ts +12 -2
  25. package/templates/events-meetups-owner/dev/index.ts +1178 -69
  26. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  27. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  28. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  29. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  30. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  31. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  32. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  33. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  34. package/templates/gym-fitness-owner/config.ts +12 -2
  35. package/templates/gym-fitness-owner/dev/index.ts +1222 -69
  36. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  37. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  38. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  39. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  40. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  41. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  42. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  43. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  44. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  45. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  46. package/templates/nonprofit-cause-owner/config.ts +12 -2
  47. package/templates/nonprofit-cause-owner/dev/index.ts +1200 -69
  48. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  49. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  50. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  51. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  52. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  53. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  54. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  55. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  56. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  57. package/templates/owner-lite/config.ts +12 -2
  58. package/templates/owner-lite/dev/index.ts +1222 -69
  59. package/templates/owner-lite/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  60. package/templates/owner-lite/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  61. package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  62. package/templates/owner-lite/tier5-src/himi-owner-lite-event/index.ts +12 -1
  63. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  64. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  65. package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +12 -1
  66. package/templates/owner-lite/tier5-src/himi-owner-lite-product/index.ts +12 -1
  67. package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +3 -3
  68. package/templates/owner-lite/tier5-src/himi-owner-lite-service/index.ts +12 -1
  69. package/templates/podcast-creator-owner/config.ts +12 -2
  70. package/templates/podcast-creator-owner/dev/index.ts +1200 -69
  71. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  72. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  73. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  74. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  75. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  76. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  77. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  78. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  79. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  80. package/templates/portfolio-creative-owner/config.ts +12 -2
  81. package/templates/portfolio-creative-owner/dev/index.ts +1200 -69
  82. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  83. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  84. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  85. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  86. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  87. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  88. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  89. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  90. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  91. package/templates/restaurant-owner/config.ts +12 -2
  92. package/templates/restaurant-owner/dev/index.ts +1222 -69
  93. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  94. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  95. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  96. package/templates/restaurant-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  97. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  98. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  99. package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  100. package/templates/restaurant-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  101. package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  102. package/templates/restaurant-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  103. package/templates/retail-store-owner/config.ts +12 -2
  104. package/templates/retail-store-owner/dev/index.ts +1178 -69
  105. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  106. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  107. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  108. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  109. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  110. package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  111. package/templates/retail-store-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  112. package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  113. package/templates/yoga-studio-owner/config.ts +12 -2
  114. package/templates/yoga-studio-owner/dev/index.ts +1200 -69
  115. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  116. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  117. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  118. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  119. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  120. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  121. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  122. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  123. 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
@@ -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);
@@ -646,7 +646,12 @@ export default defineApp({
646
646
  "label": "Maestro",
647
647
  "icon": "ai",
648
648
  "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
649
- "hiddenUntilResolved": true
649
+ "hiddenUntilResolved": true,
650
+ "badge": {
651
+ "kind": "count",
652
+ "valuePath": "$service:ownerLiteNav.maestroWaiting",
653
+ "countLabel": "waiting on you"
654
+ }
650
655
  },
651
656
  {
652
657
  "id": "manage",
@@ -685,7 +690,12 @@ export default defineApp({
685
690
  "label": "Maestro",
686
691
  "icon": "ai",
687
692
  "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
688
- "hiddenUntilResolved": true
693
+ "hiddenUntilResolved": true,
694
+ "badge": {
695
+ "kind": "count",
696
+ "valuePath": "$service:ownerLiteNav.maestroWaiting",
697
+ "countLabel": "waiting on you"
698
+ }
689
699
  },
690
700
  {
691
701
  "id": "manage",