@wix/himalaya-cli 0.1937.0 → 0.1939.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 (133) 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/schema.d.ts +6 -0
  3. package/dist/browser-plane/assets.json +5 -5
  4. package/dist/browser-plane/preview-deferred/{e5837d5c411f8725fbfe259349eee3e04e53eb313ff505c35d46a14d80cfb484.bin → 5b3d097922a41f4f7e9ad5d9701a5025ae5d293b3ee4927ad9eb21730bf6bf5c.bin} +1 -1
  5. package/dist/browser-plane/sw.js +9 -9
  6. package/dist/cli.mjs +49 -44
  7. package/dist/preview-assets.generated.bin +0 -0
  8. package/guides/component-index.md +1 -1
  9. package/guides/component-reference.json +1 -1
  10. package/guides/component-reference.md +6 -0
  11. package/package.json +2 -2
  12. package/templates/beauty-salon-owner/config.ts +12 -2
  13. package/templates/beauty-salon-owner/dev/index.ts +1200 -69
  14. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  15. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  16. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  17. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  18. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  19. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  20. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  21. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  22. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  23. package/templates/community-club-owner/config.ts +12 -2
  24. package/templates/community-club-owner/dev/index.ts +1200 -69
  25. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  26. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  27. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  28. package/templates/community-club-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  29. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  30. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  31. package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  32. package/templates/community-club-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  33. package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  34. package/templates/events-meetups-owner/config.ts +12 -2
  35. package/templates/events-meetups-owner/dev/index.ts +1178 -69
  36. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  37. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  38. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  39. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  40. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  41. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  42. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  43. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  44. package/templates/gym-fitness-owner/config.ts +12 -2
  45. package/templates/gym-fitness-owner/dev/index.ts +1222 -69
  46. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  47. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  48. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  49. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  50. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  51. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  52. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  53. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  54. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  55. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  56. package/templates/nonprofit-cause-owner/config.ts +12 -2
  57. package/templates/nonprofit-cause-owner/dev/index.ts +1200 -69
  58. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  59. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  60. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  61. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  62. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  63. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  64. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  65. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  66. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  67. package/templates/owner-lite/config.ts +12 -2
  68. package/templates/owner-lite/dev/index.ts +1222 -69
  69. package/templates/owner-lite/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  70. package/templates/owner-lite/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  71. package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  72. package/templates/owner-lite/tier5-src/himi-owner-lite-event/index.ts +12 -1
  73. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  74. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  75. package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +12 -1
  76. package/templates/owner-lite/tier5-src/himi-owner-lite-product/index.ts +12 -1
  77. package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +3 -3
  78. package/templates/owner-lite/tier5-src/himi-owner-lite-service/index.ts +12 -1
  79. package/templates/podcast-creator-owner/config.ts +12 -2
  80. package/templates/podcast-creator-owner/dev/index.ts +1200 -69
  81. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  82. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  83. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  84. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  85. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  86. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  87. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  88. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  89. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  90. package/templates/portfolio-creative-owner/config.ts +12 -2
  91. package/templates/portfolio-creative-owner/dev/index.ts +1200 -69
  92. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  93. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  94. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  95. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  96. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  97. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  98. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  99. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  100. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  101. package/templates/restaurant-owner/config.ts +12 -2
  102. package/templates/restaurant-owner/dev/index.ts +1222 -69
  103. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  104. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  105. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  106. package/templates/restaurant-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  107. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  108. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  109. package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  110. package/templates/restaurant-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  111. package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  112. package/templates/restaurant-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
  113. package/templates/retail-store-owner/config.ts +12 -2
  114. package/templates/retail-store-owner/dev/index.ts +1178 -69
  115. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  116. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  117. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  118. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  119. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  120. package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  121. package/templates/retail-store-owner/tier5-src/himi-owner-lite-product/index.ts +12 -1
  122. package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  123. package/templates/yoga-studio-owner/config.ts +12 -2
  124. package/templates/yoga-studio-owner/dev/index.ts +1200 -69
  125. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-chat.ts +168 -16
  126. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-kinds.ts +28 -0
  127. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +47 -4
  128. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event/index.ts +12 -1
  129. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +529 -70
  130. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +147 -17
  131. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +12 -1
  132. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +3 -3
  133. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-service/index.ts +12 -1
@@ -27,12 +27,12 @@ export function replyText(src: string): string {
27
27
  return t.trim();
28
28
  }
29
29
 
30
- export interface PastChat { id: string; title: string; updated: string }
30
+ export interface PastChat { id: string; title: string; updated: string; pinned: boolean }
31
31
 
32
32
  interface ConversationEntity {
33
33
  id?: string; name?: string; source?: string; active?: boolean;
34
- createdDate?: string; updatedDate?: string;
35
- metadata?: { wixSiteId?: string } | null;
34
+ createdDate?: string; updatedDate?: string; pinned?: boolean;
35
+ metadata?: { wixSiteId?: string; pinned?: boolean } | null;
36
36
  }
37
37
 
38
38
  /** The owner's Maestro chats about one business, newest first. Symphony's list cannot be asked
@@ -45,12 +45,34 @@ export async function pastChats(api: MaestroWixApi, site: string): Promise<PastC
45
45
  if (typeof c?.id !== "string" || !c.id) continue;
46
46
  if (c.source !== "SCHEDULER" || c.active === false) continue;
47
47
  if (!site || c.metadata?.wixSiteId !== site) continue;
48
- rows.push({ id: c.id, title: (c.name ?? "").trim(), updated: c.updatedDate ?? c.createdDate ?? "" });
48
+ rows.push({ id: c.id, title: (c.name ?? "").trim(), updated: c.updatedDate ?? c.createdDate ?? "", pinned: c.pinned === true || c.metadata?.pinned === true });
49
49
  }
50
50
  return rows.sort((a, b) => (a.updated < b.updated ? 1 : a.updated > b.updated ? -1 : 0));
51
51
  }
52
52
 
53
- export interface PastMessage { id: string; role: "USER" | "ASSISTANT"; text: string; decisionIds: string[]; link: LinkCard | null }
53
+ /** Rename a chat. Resolves the name Symphony kept. Throws when it was not renamed. */
54
+ export async function renameChat(api: MaestroWixApi, conversationId: string, name: string): Promise<string> {
55
+ const res = (await api.call("POST", NATIVE_DATA, { action: "conversation-rename", conversationId, conversationName: name })) as { renamed?: boolean; name?: string } | null;
56
+ if (res?.renamed !== true) throw new Error("conversation was not renamed");
57
+ return typeof res.name === "string" && res.name.trim() ? res.name.trim() : name;
58
+ }
59
+
60
+ /** Pin or unpin a chat. Throws when Symphony did not take it. */
61
+ export async function pinChat(api: MaestroWixApi, conversationId: string, pinned: boolean): Promise<void> {
62
+ const res = (await api.call("POST", NATIVE_DATA, { action: "conversation-pin", conversationId, pinned })) as { pinned?: boolean } | null;
63
+ if (res?.pinned !== pinned) throw new Error("conversation pin was not changed");
64
+ }
65
+
66
+ /** Delete a chat. Symphony takes it off the owner's list; it does not destroy it. Throws when
67
+ * it was not deleted. */
68
+ export async function deleteChat(api: MaestroWixApi, conversationId: string): Promise<void> {
69
+ const res = (await api.call("POST", NATIVE_DATA, { action: "conversation-delete", conversationId })) as { deleted?: boolean } | null;
70
+ if (res?.deleted !== true) throw new Error("conversation was not deleted");
71
+ }
72
+
73
+ export interface PastMessage {
74
+ id: string; role: "USER" | "ASSISTANT" | "STOPPED"; text: string; decisionIds: string[]; link: LinkCard | null;
75
+ }
54
76
 
55
77
  export interface LinkCard { name: string; url: string }
56
78
 
@@ -77,21 +99,28 @@ export function linkCardOf(bag: Record<string, unknown> | null | undefined): Lin
77
99
 
78
100
  /** An https address with a plain host. A worker has no `URL` on every host (JavaScriptCore has
79
101
  * none), so the shape is checked here; the host still decides whether to open it. */
80
- function isHttpsUrl(value: string): boolean {
102
+ export function isHttpsUrl(value: string): boolean {
81
103
  return /^https:\/\/[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:\d+)?([/?#]\S*)?$/i.test(value);
82
104
  }
83
105
 
84
- /** One chat's messages, oldest first: the owner's turns and Maestro's replies. Steps and
85
- * thoughts are left out, as they are while a turn streams. Throws when it could not be read. */
86
- export async function chatMessages(api: MaestroWixApi, conversationId: string): Promise<PastMessage[]> {
106
+ /** One page of a chat's messages, oldest first: the owner's turns and Maestro's replies. Steps
107
+ * and thoughts are left out, as they are while a turn streams. Without `cursor` it is the
108
+ * latest page; `older` is the cursor of the page before it, "" when there is none.
109
+ * Throws when it could not be read. */
110
+ export async function chatPage(api: MaestroWixApi, conversationId: string, cursor = ""): Promise<{ messages: PastMessage[]; older: string }> {
87
111
  const res = (await api.call("POST", NATIVE_DATA, {
88
- action: "conversation-message-window", conversationId, requestId: requestId(), limit: 40,
89
- })) as { conversationMessages?: MessageRow[] } | null;
112
+ action: "conversation-message-window", conversationId, requestId: requestId(), limit: 40, ...(cursor ? { cursor } : {}),
113
+ })) as { conversationMessages?: MessageRow[]; nextCursor?: string | null } | null;
90
114
  const rows = (res?.conversationMessages ?? []).filter((m) => typeof m?.id === "string" && !!m.id);
91
115
  // The order of the answer is not part of the contract: the two Symphony clients disagree on it.
92
116
  rows.sort((a, b) => ((a.createdDate ?? "") < (b.createdDate ?? "") ? -1 : (a.createdDate ?? "") > (b.createdDate ?? "") ? 1 : 0));
93
117
  const out: PastMessage[] = [];
94
118
  for (const m of rows) {
119
+ // The marker Symphony writes when a turn was stopped: the owner did that, so the chat says so.
120
+ if (m.role === "SYSTEM" && m.metadata?.stopMessage === true) {
121
+ out.push({ id: m.id as string, role: "STOPPED", text: "", decisionIds: [], link: null });
122
+ continue;
123
+ }
95
124
  if (m.role !== "USER" && m.role !== "ASSISTANT") continue;
96
125
  const text = typeof m.content === "string" ? m.content : "";
97
126
  const decisionIds = decisionIdsOf(m.metadata);
@@ -99,7 +128,27 @@ export async function chatMessages(api: MaestroWixApi, conversationId: string):
99
128
  if (!text.trim() && !decisionIds.length && !link) continue;
100
129
  out.push({ id: m.id as string, role: m.role, text, decisionIds, link });
101
130
  }
102
- return out;
131
+ return { messages: out, older: typeof res?.nextCursor === "string" ? res.nextCursor : "" };
132
+ }
133
+
134
+ /** The latest page of a chat's messages. */
135
+ export async function chatMessages(api: MaestroWixApi, conversationId: string): Promise<PastMessage[]> {
136
+ return (await chatPage(api, conversationId)).messages;
137
+ }
138
+
139
+ const ACTIVITY = "https://manage.wix.com/_api/symphony-bff/v1/symphony/chats/activity";
140
+
141
+ /** Whether Maestro is working on a chat right now: a turn the owner left before it ended keeps
142
+ * running on Symphony's side. False when Symphony says it is idle, does not know, or could not
143
+ * be asked: "still working" is only said when Symphony says so. */
144
+ export async function chatIsRunning(api: MaestroWixApi, account: string, conversationId: string): Promise<boolean> {
145
+ if (!account || !conversationId) return false;
146
+ try {
147
+ const res = (await api.call("POST", ACTIVITY, { conversationId }, { "wix-site-id": account, "Content-Type": "application/json" })) as { state?: string } | null;
148
+ return res?.state === "RUNNING";
149
+ } catch {
150
+ return false;
151
+ }
103
152
  }
104
153
 
105
154
  /** Unique per request: Symphony uses it to drop a repeated read. It must be a UUID. Any other
@@ -117,29 +166,55 @@ export interface Decision {
117
166
  open: boolean;
118
167
  /** How it was settled: `ACCEPTED`, `REFUSED` or "". */
119
168
  resolution: string;
169
+ /** What kind of answer it wants: `APPROVE` and `CONFIRM` take yes or no, `CHOOSE` one of
170
+ * `options`, `ANSWER` the owner's own words. "" when Symphony did not say, which reads as
171
+ * yes or no unless it has options. */
172
+ kind: string;
173
+ /** The options of a `CHOOSE`, each with the id an answer names. Empty for every other kind. */
174
+ options: DecisionOption[];
120
175
  /** A decision that asks the owner to pick one of several options cannot be answered with
121
176
  * yes or no. */
122
177
  hasOptions: boolean;
178
+ /** The option the owner chose, as Symphony stores it (an option id), or their words. */
179
+ chosen: string;
123
180
  planVersion: string;
124
181
  }
125
182
 
183
+ export interface DecisionOption { id: string; label: string }
184
+
126
185
  interface DecisionRow {
127
186
  decision?: {
128
187
  id?: string; question?: string; detail?: string; settledDate?: string | null; planVersion?: string;
129
- outcome?: { resolution?: string } | null; options?: unknown[];
188
+ outcome?: { resolution?: string; choice?: string; answer?: string } | null; options?: unknown[];
189
+ kind?: string; status?: string; dueBy?: string | null;
130
190
  };
131
191
  }
132
192
 
133
193
  function decisionOf(row: DecisionRow["decision"]): Decision | null {
134
194
  if (typeof row?.id !== "string" || !row.id) return null;
135
195
  const resolution = typeof row.outcome?.resolution === "string" ? row.outcome.resolution : "";
196
+ // An option without an id or a label cannot be named in an answer, so it is not offered.
197
+ const options: DecisionOption[] = [];
198
+ for (const o of Array.isArray(row.options) ? row.options : []) {
199
+ const id = typeof (o as { id?: unknown })?.id === "string" ? ((o as { id: string }).id).trim() : "";
200
+ const label = typeof (o as { label?: unknown })?.label === "string" ? ((o as { label: string }).label).trim() : "";
201
+ if (id && label) options.push({ id, label });
202
+ }
203
+ const status = typeof row.status === "string" ? row.status : "";
204
+ const due = typeof row.dueBy === "string" && row.dueBy ? Date.parse(row.dueBy) : NaN;
205
+ // Open: nothing settled it, Symphony does not call it closed, and it is not past its date.
206
+ const open = !resolution && !row.settledDate && (!status || status === "OPEN") && !(Number.isFinite(due) && due < Date.now());
207
+ const chosenId = typeof row.outcome?.choice === "string" ? row.outcome.choice : "";
136
208
  return {
137
209
  id: row.id,
138
210
  question: typeof row.question === "string" ? row.question.trim() : "",
139
211
  detail: typeof row.detail === "string" ? row.detail.trim() : "",
140
- open: !resolution && !row.settledDate,
212
+ open,
141
213
  resolution,
214
+ kind: typeof row.kind === "string" ? row.kind : "",
215
+ options,
142
216
  hasOptions: Array.isArray(row.options) && row.options.length > 0,
217
+ chosen: options.find((o) => o.id === chosenId)?.label || chosenId || (typeof row.outcome?.answer === "string" ? row.outcome.answer.trim() : ""),
143
218
  planVersion: typeof row.planVersion === "string" ? row.planVersion : "",
144
219
  };
145
220
  }
@@ -166,15 +241,92 @@ export type Verdict = "ACCEPTED" | "REFUSED";
166
241
  * Throws when the outcome is unknown, and the same `verdictId` may then be sent again. */
167
242
  export async function sendVerdict(
168
243
  api: MaestroWixApi,
169
- o: { decisionId: string; verdictId: string; resolution: Verdict; planVersion: string; conversationId: string },
244
+ o: { decisionId: string; verdictId: string; resolution: Verdict; planVersion: string; conversationId: string; choice?: string; answer?: string },
170
245
  ): Promise<Decision | null> {
171
246
  const res = (await api.call("POST", NATIVE_DATA, {
172
247
  action: "decision-verdict", decisionId: o.decisionId, verdictId: o.verdictId, resolution: o.resolution,
248
+ // A `CHOOSE` names the option by its id: Symphony refuses a label. An `ANSWER` carries the words.
249
+ ...(o.choice ? { choice: o.choice } : {}),
250
+ ...(o.answer ? { answer: o.answer } : {}),
173
251
  ...(o.planVersion ? { planVersion: o.planVersion } : {}),
174
252
  ...(o.conversationId ? { answeredIn: o.conversationId } : {}),
175
253
  })) as { ok?: boolean; decision?: DecisionRow["decision"] } | null;
176
254
  if (res?.ok !== true) return null;
177
255
  return decisionOf(res.decision) ?? {
178
- id: o.decisionId, question: "", detail: "", open: false, resolution: o.resolution, hasOptions: false, planVersion: o.planVersion,
256
+ id: o.decisionId, question: "", detail: "", open: false, resolution: o.resolution, kind: "", options: [], hasOptions: false,
257
+ chosen: "", planVersion: o.planVersion,
179
258
  };
180
259
  }
260
+
261
+ const HARNESS = "https://symphony.wix.com/_api/symphony-harness/v1";
262
+
263
+ /** Ask Symphony to stop the turn running in a chat. The turn stops between its steps, so a step
264
+ * already under way still finishes. Resolves false when Symphony could not be told. Never throws:
265
+ * the chat has already stopped listening, and that part does not depend on this. */
266
+ export async function stopTurn(api: MaestroWixApi, account: string, conversationId: string): Promise<boolean> {
267
+ if (!account || !conversationId) return false;
268
+ try {
269
+ await api.call("POST", `${HARNESS}/stop-stream-http`, { conversationId }, { "wix-site-id": account, "Content-Type": "application/json" });
270
+ return true;
271
+ } catch {
272
+ return false;
273
+ }
274
+ }
275
+
276
+ /** Something Maestro is waiting on the owner for, with the chat it is asked in. */
277
+ export interface WaitingAsk { id: string; conversationId: string; title: string }
278
+
279
+ interface WaitingAnswer {
280
+ waitingTotal?: number; waitingQuestionsTotal?: number; waitingOutreachQuestionsTotal?: number; waitingOpenAsksTotal?: number;
281
+ waitingOpenAsks?: Array<{ id?: string; conversationId?: string; title?: string; prompt?: string; body?: string }>;
282
+ }
283
+
284
+ /** What Maestro is waiting on the owner for, across their Symphony account: how many things
285
+ * (the number Symphony's own apps show as "Action needed"), and the ones that have a chat to
286
+ * answer them in. Symphony keeps this per account, not per business. Throws when it could not
287
+ * be asked. */
288
+ export async function waitingOnOwner(api: MaestroWixApi): Promise<{ count: number; asks: WaitingAsk[] }> {
289
+ const res = (await api.call("POST", NATIVE_DATA, { action: "agent-workspace-tasks" })) as WaitingAnswer | null;
290
+ const n = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) && v > 0 ? Math.floor(v) : 0);
291
+ const count = n(res?.waitingQuestionsTotal ?? res?.waitingTotal) + n(res?.waitingOutreachQuestionsTotal) + n(res?.waitingOpenAsksTotal);
292
+ const asks: WaitingAsk[] = [];
293
+ for (const a of res?.waitingOpenAsks ?? []) {
294
+ const id = typeof a?.id === "string" ? a.id : "";
295
+ const conversationId = typeof a?.conversationId === "string" ? a.conversationId : "";
296
+ const title = [a?.title, a?.prompt, a?.body].find((t): t is string => typeof t === "string" && !!t.trim())?.replace(/\s+/g, " ").trim().slice(0, 120) ?? "";
297
+ if (id && conversationId && title) asks.push({ id, conversationId, title });
298
+ }
299
+ return { count, asks };
300
+ }
301
+
302
+ /** A file as a turn carries it. `fileName` and `mimeType` are the file's own: Symphony's upload
303
+ * may rename it, and the model is told what the owner picked. */
304
+ export interface TurnAttachment { fileName: string; mimeType: string; url: string; thumbnailUrl: string; size: number }
305
+
306
+ const UPLOAD_URL = "https://manage.wix.com/_serverless/ai-scheduling-assistant-server/media-upload-url";
307
+
308
+ /** Where to put a file's bytes, and under which name and type. The owner's Wix session answers
309
+ * it; the upload itself carries no credential. Throws when Symphony gave no address. */
310
+ export async function mintUpload(api: MaestroWixApi, file: { fileName: string; mimeType: string; size: number }): Promise<{ url: string; contentType: string }> {
311
+ const res = (await api.call("POST", UPLOAD_URL, file)) as { uploadUrl?: string; uploadFileName?: string; uploadMimeType?: string } | null;
312
+ const uploadUrl = typeof res?.uploadUrl === "string" ? res.uploadUrl : "";
313
+ const name = typeof res?.uploadFileName === "string" && res.uploadFileName ? res.uploadFileName : file.fileName;
314
+ if (!isHttpsUrl(uploadUrl)) throw new Error("no upload address");
315
+ // The upload must declare exactly the name and type Symphony minted the address for.
316
+ return {
317
+ url: `${uploadUrl}${uploadUrl.includes("?") ? "&" : "?"}filename=${encodeURIComponent(name)}`,
318
+ contentType: typeof res?.uploadMimeType === "string" && res.uploadMimeType ? res.uploadMimeType : file.mimeType,
319
+ };
320
+ }
321
+
322
+ /** What the upload host answered, as an attachment. Null when it named no usable file address. */
323
+ export function uploadedFile(body: string, file: { fileName: string; mimeType: string; size: number }): TurnAttachment | null {
324
+ interface UploadAnswer { file?: { url?: unknown; thumbnailUrl?: unknown } }
325
+ let answer: UploadAnswer = {};
326
+ try { answer = (JSON.parse(body) ?? {}) as UploadAnswer; } catch { return null; }
327
+ const url = typeof answer.file?.url === "string" ? answer.file.url : "";
328
+ if (!isHttpsUrl(url)) return null;
329
+ const rawThumb = answer.file?.thumbnailUrl;
330
+ const thumb = typeof rawThumb === "string" && isHttpsUrl(rawThumb) ? rawThumb : url;
331
+ return { fileName: file.fileName, mimeType: file.mimeType, url, thumbnailUrl: thumb, size: file.size };
332
+ }
@@ -0,0 +1,28 @@
1
+ // What __HIMI_APP_NAME__'s "Ask Maestro" can be about. No imports: the screen builders read this file
2
+ // too, and they run outside a worker.
3
+
4
+ /** What a chat can be opened about, with the words the chat uses for each ("this invoice"). */
5
+ export const ASK_MAESTRO_NOUNS = {
6
+ order: "order", booking: "booking", contact: "contact",
7
+ product: "product", service: "service", event: "event", post: "post",
8
+ coupon: "coupon", invoice: "invoice", giftCard: "gift card", member: "member", group: "group", review: "review",
9
+ plan: "plan", subscription: "subscription", program: "program", badge: "badge", reservation: "reservation",
10
+ form: "form", project: "portfolio project", campaign: "donation campaign",
11
+ } as const;
12
+ export type AskMaestroKind = keyof typeof ASK_MAESTRO_NOUNS;
13
+
14
+ /** Kinds whose title is a person's name. The name is never handed on by a screen or stored in
15
+ * the request: the chat names them by what they are, unless the Maestro worker reads the name
16
+ * itself (it does for a contact). */
17
+ // A reservation's title is the guest's name.
18
+ const PERSON_KINDS: readonly AskMaestroKind[] = ["contact", "member", "reservation"];
19
+ export const askKindIsAPerson = (kind: AskMaestroKind): boolean => PERSON_KINDS.includes(kind);
20
+
21
+ /** The kind of record each management module holds. */
22
+ const MODULE_KINDS: Readonly<Record<string, AskMaestroKind>> = {
23
+ coupons: "coupon", invoices: "invoice", giftCards: "giftCard", contacts: "contact", members: "member", groups: "group",
24
+ reviews: "review", plans: "plan", subscriptions: "subscription", programs: "program", badges: "badge",
25
+ reservations: "reservation", forms: "form", portfolio: "project", donationCampaigns: "campaign",
26
+ };
27
+ export const askKindOfModule = (module: string): AskMaestroKind | undefined =>
28
+ (Object.prototype.hasOwnProperty.call(MODULE_KINDS, module) ? MODULE_KINDS[module] : undefined);
@@ -14,6 +14,9 @@
14
14
 
15
15
  import { navigate, type NavDirective } from "@himalaya/state";
16
16
  import { currentBusinessId } from "./owner-selected-site.js";
17
+ import { ASK_MAESTRO_NOUNS, askKindIsAPerson, type AskMaestroKind } from "./owner-maestro-kinds.js";
18
+
19
+ export { ASK_MAESTRO_NOUNS, askKindIsAPerson, askKindOfModule, type AskMaestroKind } from "./owner-maestro-kinds.js";
17
20
 
18
21
  type StorageLike = { getItem(key: string): string | null; setItem(key: string, value: string): void };
19
22
  type Host = { storage?: StorageLike };
@@ -52,10 +55,10 @@ export function askMaestroHidden(): "true" | "false" {
52
55
  const ASK_KEY = "himi.ownerLite.maestroAsk.v1";
53
56
  const ASK_REQUEST_TTL_MS = 30_000;
54
57
 
55
- export type AskMaestroKind = "order" | "booking" | "contact";
56
58
  export interface AskMaestroRequest { kind: AskMaestroKind; id: string; subject: string; site: string; n: number }
57
59
 
58
- export const isAskMaestroKind = (v: unknown): v is AskMaestroKind => v === "order" || v === "booking" || v === "contact";
60
+ export const isAskMaestroKind = (v: unknown): v is AskMaestroKind =>
61
+ typeof v === "string" && Object.prototype.hasOwnProperty.call(ASK_MAESTRO_NOUNS, v);
59
62
 
60
63
  /** Leave "ask Maestro about this item" for the Maestro tab. False when it could not be left
61
64
  * (no id, no business, or a host without storage): the caller then opens the Maestro screen
@@ -67,7 +70,9 @@ export function requestAskMaestro(kind: unknown, id: unknown, subject: unknown,
67
70
  const storage = host()?.storage;
68
71
  if (!storage) return false;
69
72
  try {
70
- storage.setItem(ASK_KEY, JSON.stringify({ kind, id: item, subject: typeof subject === "string" ? subject.trim() : "", site, n: now }));
73
+ // A person's name is not written here, whatever the caller passed.
74
+ const named = !askKindIsAPerson(kind) && typeof subject === "string" ? subject.trim() : "";
75
+ storage.setItem(ASK_KEY, JSON.stringify({ kind, id: item, subject: named, site, n: now }));
71
76
  return true;
72
77
  } catch { return false; }
73
78
  }
@@ -110,9 +115,47 @@ export function askMaestroNav<S extends object>(state: S, arg: unknown): S & { _
110
115
  const a = (arg && typeof arg === "object" ? arg : {}) as { kind?: unknown; id?: unknown; subject?: unknown };
111
116
  if (requestAskMaestro(a.kind, a.id, a.subject, Date.now())) return navigate(state, { tab: "maestro", reset: true });
112
117
  const args: Record<string, string> = {};
118
+ // A person's name is not put in screen params either: on the web host they are part of the address.
119
+ const named = isAskMaestroKind(a.kind) && !askKindIsAPerson(a.kind);
113
120
  for (const key of ["kind", "id", "subject"] as const) {
114
121
  const value = a[key];
115
- if (typeof value === "string" && value) args[key] = value;
122
+ if (typeof value === "string" && value && (key !== "subject" || named)) args[key] = value;
116
123
  }
117
124
  return navigate(state, { screenId: "himi_owner_lite_maestro", args });
118
125
  }
126
+
127
+ // ── Notes between the Maestro screens and the app-level worker ──────────────────────────────
128
+ // Each is one value in the app's storage, written by the worker that knows and read by the one
129
+ // that must act. Never throws: a host without storage only loses the nicety.
130
+
131
+ const DELETED_KEY = "himi.ownerLite.maestroDeletedChat.v1";
132
+ const RECOUNT_KEY = "himi.ownerLite.maestroRecount.v1";
133
+ const put = (key: string, value: string): void => { try { host()?.storage?.setItem(key, value); } catch { /* no storage */ } };
134
+ const take = (key: string): string => { try { return host()?.storage?.getItem(key) ?? ""; } catch { return ""; } };
135
+
136
+ /** The chats History deleted, newest last. The Maestro screen reads the note only when it next
137
+ * appears, and the owner may delete many before going back: the newest two hundred are kept, more
138
+ * than one visit to History can delete by hand, and bounded because nothing ever clears the note. */
139
+ function deletedChats(): string[] {
140
+ try {
141
+ const parsed: unknown = JSON.parse(take(DELETED_KEY) || "[]");
142
+ return Array.isArray(parsed) ? parsed.filter((id): id is string => typeof id === "string" && id.length > 0) : [];
143
+ } catch { return []; }
144
+ }
145
+ const DELETED_KEPT = 200;
146
+ /** History deleted this chat: the Maestro screen must not go on writing into it. */
147
+ export function noteDeletedChat(conversationId: string): void {
148
+ if (!conversationId) return;
149
+ put(DELETED_KEY, JSON.stringify([...deletedChats().filter((id) => id !== conversationId), conversationId].slice(-DELETED_KEPT)));
150
+ }
151
+ export function wasDeleted(conversationId: string): boolean { return !!conversationId && deletedChats().includes(conversationId); }
152
+
153
+ /** The owner answered something Maestro was waiting on: the tab's badge is out of date. The
154
+ * app-level worker counts again on its next tick. */
155
+ export function askForRecount(): void { put(RECOUNT_KEY, "1"); }
156
+ /** Whether a recount was asked for; reading it clears it. */
157
+ export function recountAsked(): boolean {
158
+ if (take(RECOUNT_KEY) !== "1") return false;
159
+ put(RECOUNT_KEY, "");
160
+ return true;
161
+ }