@wix/himalaya-cli 0.1868.0 → 0.1869.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 (86) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/state/src/index.d.ts +7 -1
  2. package/dist/browser-plane/assets.json +5 -5
  3. package/dist/browser-plane/preview-deferred/{606c83075130fbcd609b5aabaa1e6bac0bfb27bd362d1ce8eb5cbcb266e1f682.bin → fb2b059338baac28265ef57c60a2934572de24f5f84471859dd358f474ca6d4a.bin} +1 -1
  4. package/dist/browser-plane/sw.js +7 -7
  5. package/dist/cli.mjs +4868 -3182
  6. package/dist/preview-assets.generated.bin +0 -0
  7. package/guides/himi-json-output.md +27 -0
  8. package/guides/one-app-to-himi-app.md +62 -0
  9. package/guides/release-notes.md +12 -0
  10. package/guides/sdk-reference.json +1 -1
  11. package/package.json +2 -2
  12. package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +9 -0
  13. package/templates/beauty-salon/tier5-src/_shared/engine-intl.ts +9 -0
  14. package/templates/beauty-salon-owner/config.ts +7 -0
  15. package/templates/beauty-salon-owner/dev/index.ts +618 -0
  16. package/templates/beauty-salon-owner/himalaya.content.json +3 -0
  17. package/templates/beauty-salon-owner/tier5-src/_shared/engine-intl.ts +9 -0
  18. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  19. package/templates/branded-lite/tier5-src/_shared/engine-intl.ts +9 -0
  20. package/templates/branded-lite/tier5-src/_shared/one-app-widget-gate.ts +65 -0
  21. package/templates/brandy/tier5-src/_shared/engine-intl.ts +9 -0
  22. package/templates/community-club/tier5-src/_shared/engine-intl.ts +9 -0
  23. package/templates/community-club-owner/config.ts +7 -0
  24. package/templates/community-club-owner/dev/index.ts +618 -0
  25. package/templates/community-club-owner/himalaya.content.json +3 -0
  26. package/templates/community-club-owner/tier5-src/_shared/engine-intl.ts +9 -0
  27. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  28. package/templates/conference/tier5-src/_shared/engine-intl.ts +9 -0
  29. package/templates/events-meetups/tier5-src/_shared/engine-intl.ts +9 -0
  30. package/templates/events-meetups-owner/config.ts +7 -0
  31. package/templates/events-meetups-owner/dev/index.ts +618 -0
  32. package/templates/events-meetups-owner/himalaya.content.json +3 -0
  33. package/templates/events-meetups-owner/tier5-src/_shared/engine-intl.ts +9 -0
  34. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  35. package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +9 -0
  36. package/templates/gym-fitness/tier5-src/_shared/engine-intl.ts +9 -0
  37. package/templates/gym-fitness-owner/config.ts +7 -0
  38. package/templates/gym-fitness-owner/dev/index.ts +618 -0
  39. package/templates/gym-fitness-owner/himalaya.content.json +3 -0
  40. package/templates/gym-fitness-owner/tier5-src/_shared/engine-intl.ts +9 -0
  41. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  42. package/templates/medical-services/tier5-src/_shared/engine-intl.ts +9 -0
  43. package/templates/nonprofit-cause/tier5-src/_shared/engine-intl.ts +9 -0
  44. package/templates/nonprofit-cause-owner/config.ts +7 -0
  45. package/templates/nonprofit-cause-owner/dev/index.ts +618 -0
  46. package/templates/nonprofit-cause-owner/himalaya.content.json +3 -0
  47. package/templates/nonprofit-cause-owner/tier5-src/_shared/engine-intl.ts +9 -0
  48. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  49. package/templates/owner-lite/config.ts +7 -0
  50. package/templates/owner-lite/dev/index.ts +618 -0
  51. package/templates/owner-lite/himalaya.content.json +3 -0
  52. package/templates/owner-lite/tier5-src/_shared/engine-intl.ts +9 -0
  53. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  54. package/templates/personal-fitness-trainer/tier5-src/_shared/engine-intl.ts +9 -0
  55. package/templates/podcast-creator/tier5-src/_shared/engine-intl.ts +9 -0
  56. package/templates/podcast-creator-owner/config.ts +7 -0
  57. package/templates/podcast-creator-owner/dev/index.ts +618 -0
  58. package/templates/podcast-creator-owner/himalaya.content.json +3 -0
  59. package/templates/podcast-creator-owner/tier5-src/_shared/engine-intl.ts +9 -0
  60. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  61. package/templates/portfolio-creative/tier5-src/_shared/engine-intl.ts +9 -0
  62. package/templates/portfolio-creative-owner/config.ts +7 -0
  63. package/templates/portfolio-creative-owner/dev/index.ts +618 -0
  64. package/templates/portfolio-creative-owner/himalaya.content.json +3 -0
  65. package/templates/portfolio-creative-owner/tier5-src/_shared/engine-intl.ts +9 -0
  66. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  67. package/templates/restaurant/tier5-src/_shared/engine-intl.ts +9 -0
  68. package/templates/restaurant-owner/config.ts +7 -0
  69. package/templates/restaurant-owner/dev/index.ts +618 -0
  70. package/templates/restaurant-owner/himalaya.content.json +3 -0
  71. package/templates/restaurant-owner/tier5-src/_shared/engine-intl.ts +9 -0
  72. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  73. package/templates/retail-store/tier5-src/_shared/engine-intl.ts +9 -0
  74. package/templates/retail-store-owner/config.ts +7 -0
  75. package/templates/retail-store-owner/dev/index.ts +618 -0
  76. package/templates/retail-store-owner/himalaya.content.json +3 -0
  77. package/templates/retail-store-owner/tier5-src/_shared/engine-intl.ts +9 -0
  78. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
  79. package/templates/salon-spa/tier5-src/_shared/engine-intl.ts +9 -0
  80. package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +9 -0
  81. package/templates/yoga-studio/tier5-src/_shared/engine-intl.ts +9 -0
  82. package/templates/yoga-studio-owner/config.ts +7 -0
  83. package/templates/yoga-studio-owner/dev/index.ts +618 -0
  84. package/templates/yoga-studio-owner/himalaya.content.json +3 -0
  85. package/templates/yoga-studio-owner/tier5-src/_shared/engine-intl.ts +9 -0
  86. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +399 -0
@@ -0,0 +1,399 @@
1
+ // Tier-5 bundle: __HIMI_APP_NAME__ — Maestro, the Symphony assistant, about the business the owner is
2
+ // looking at.
3
+ //
4
+ // Maestro is not Aria. Aria is the Wix Genie chat-service, addressed with the active site's own
5
+ // signed instance. Maestro lives in the owner's SYMPHONY account, a separate hidden metasite, so
6
+ // every call here names that metasite and the host mints the credential for it: the worker never
7
+ // holds, sees or stores a token.
8
+ //
9
+ // 1. Who is this owner in Symphony? POST manage.wix.com/_serverless/ai-scheduling-assistant-
10
+ // server/native-data {action:"recipient"} — the Wix session alone answers it.
11
+ // 2. Is this business one of their Spaces? POST manage.wix.com/_api/symphony-bff/v1/symphony/
12
+ // workspaces — a Space's `website.metaSiteId` is the business it manages.
13
+ // 3. A conversation is tied to the business ONCE, at creation: `metadata.wixSiteId`.
14
+ // 4. A turn is one streamed request (a `_stream` directive with `format: "ndjson"`): the live Symphony
15
+ // send answers newline-delimited JSON, one {type, data} per line.
16
+ //
17
+ // (1) or (2) failing is not an error: it is the rule that sends the owner to Aria instead. A new
18
+ // Symphony account needs a verified phone, so it cannot be created silently from here.
19
+ //
20
+ // Verified against the live service on 2026-11-24.
21
+
22
+ import { defineService } from "@himalaya/state";
23
+ import { deviceTimeZone } from "../_shared/engine-intl.js";
24
+ import { copyParam, stashCopy } from "../_shared/himi-copy.js";
25
+ import { readSelectedSite } from "../_shared/owner-selected-site.js";
26
+
27
+ const SERVICE = "himiOwnerLiteMaestro";
28
+ /** The screen this worker paints: message rows are stamped `<screen>.message_<id>`. */
29
+ const SCREEN = "himi_owner_lite_maestro";
30
+ const NATIVE_DATA = "https://manage.wix.com/_serverless/ai-scheduling-assistant-server/native-data";
31
+ const SPACES = "https://manage.wix.com/_api/symphony-bff/v1/symphony/workspaces";
32
+ const CONVERSATIONS = "https://symphony.wix.com/individuals-chat/conversation/v1/conversations";
33
+ const SEND = "https://symphony.wix.com/_api/symphony-harness/v1/send-message-streamed-http";
34
+ const STREAM_ID = "maestro-turn";
35
+ const THINKING_ID = "__thinking__";
36
+
37
+ interface WixApi { call: (method: string, path: string, body?: unknown, headers?: Record<string, string>) => Promise<unknown>; }
38
+ interface Host { wixApi?: WixApi; input?: Record<string, unknown> }
39
+ const host = (): Host => (globalThis as { himalaya?: Host }).himalaya ?? {};
40
+
41
+ /** The business the owner is looking at: the one the host has scoped, else the one the Sites
42
+ * picker recorded (a host that has not scoped a business yet, as the web preview's sample
43
+ * session never does). It is only ever an address: Symphony honours it for the account's own
44
+ * sites and nothing else. */
45
+ function activeSiteId(): string {
46
+ const v = host().input?.__himiPreferenceBusiness;
47
+ const scoped = typeof v === "string" ? v.trim() : "";
48
+ return scoped || readSelectedSite()?.id || "";
49
+ }
50
+
51
+
52
+ /** `wix-site-id` makes the host mint the credential for THAT metasite (the Symphony account),
53
+ * instead of the business on screen. */
54
+ const forSite = (metaSiteId: string): Record<string, string> => ({ "wix-site-id": metaSiteId, "Content-Type": "application/json" });
55
+
56
+ export interface Bubble {
57
+ id: string;
58
+ content: string;
59
+ userHidden: string;
60
+ assistantHidden: string;
61
+ thinkingHidden: string;
62
+ }
63
+ const userBubble = (id: string, content: string): Bubble => ({ id, content, userHidden: "false", assistantHidden: "true", thinkingHidden: "true" });
64
+ const assistantBubble = (id: string, content: string): Bubble => ({ id, content, userHidden: "true", assistantHidden: "false", thinkingHidden: "true" });
65
+ const thinkingBubble = (): Bubble => ({ id: THINKING_ID, content: "", userHidden: "true", assistantHidden: "true", thinkingHidden: "false" });
66
+
67
+ export interface QuickReply { id: string; label: string; askId: string }
68
+ export interface Prompt { id: string; title: string; text: string }
69
+
70
+ /** Why Maestro cannot be used here. Each one sends the owner to Aria. */
71
+ type Unavailable = "" | "no_site" | "no_account" | "not_connected" | "unreachable";
72
+
73
+ export interface MaestroState {
74
+ /** `checking` until the account and the Space are known. */
75
+ phase: "checking" | "ready" | "unavailable";
76
+ checkingHidden: string;
77
+ chatHidden: string;
78
+ unavailableHidden: string;
79
+ unavailableTitle: string;
80
+ unavailableText: string;
81
+ messages: Bubble[];
82
+ /** The empty state (greeting + prompt cards) shows until the first turn. */
83
+ emptyHidden: string;
84
+ prompts: Prompt[];
85
+ quickReplies: QuickReply[];
86
+ quickRepliesHidden: string;
87
+ input: string;
88
+ hasInput: boolean;
89
+ noInput: boolean;
90
+ busy: boolean;
91
+ idle: boolean;
92
+ /** What Maestro is doing right now ("" collapses the line). */
93
+ statusText: string;
94
+ error: string;
95
+ /** Changes on every send: the host's transcript scroll follows the new turn. */
96
+ scrollSend: string;
97
+ /** The row to pin on a send: the owner's own message. */
98
+ scrollAnchor: string;
99
+ ok: boolean;
100
+ _site: string;
101
+ /** The owner's Symphony metasite: an address, not a credential. */
102
+ _account: string;
103
+ _convId: string;
104
+ /** Role of the segment currently streaming, and the bubble it appends to. */
105
+ _role: string;
106
+ _openId: string;
107
+ _turn: number;
108
+ }
109
+
110
+ const copy = {
111
+ greeting: () => copyParam("ownerMaestro.greeting", "Hi, I'm Maestro. Ask me to check on your business or to get something done."),
112
+ thinking: () => copyParam("ownerMaestro.thinking", "Maestro is working on it…"),
113
+ failed: () => copyParam("ownerMaestro.failed", "Maestro couldn't answer. Try again in a moment."),
114
+ unavailable: (why: Unavailable): { title: string; text: string } => {
115
+ if (why === "not_connected") {
116
+ return {
117
+ title: copyParam("ownerMaestro.notConnected.title", "This business isn't connected to Maestro yet"),
118
+ text: copyParam("ownerMaestro.notConnected.text", "Add it as a Space in Symphony and Maestro can work on it from here. Until then, Aria can help."),
119
+ };
120
+ }
121
+ if (why === "no_site") {
122
+ return {
123
+ title: copyParam("ownerMaestro.noSite.title", "Choose a business first"),
124
+ text: copyParam("ownerMaestro.noSite.text", "Maestro works on one business at a time. Pick one in Sites, then come back."),
125
+ };
126
+ }
127
+ if (why === "unreachable") {
128
+ return {
129
+ title: copyParam("ownerMaestro.unreachable.title", "Maestro can't be reached right now"),
130
+ text: copyParam("ownerMaestro.unreachable.text", "Check your connection and try again. Aria is available meanwhile."),
131
+ };
132
+ }
133
+ return {
134
+ title: copyParam("ownerMaestro.noAccount.title", "Set up Maestro for this business"),
135
+ text: copyParam("ownerMaestro.noAccount.text", "Maestro is part of Symphony. Create your Symphony account to use it here. Until then, Aria can help."),
136
+ };
137
+ },
138
+ };
139
+
140
+ function prompts(): Prompt[] {
141
+ return [
142
+ { id: "p1", title: copyParam("ownerMaestro.p1.title", "Catch me up"), text: copyParam("ownerMaestro.p1.text", "Catch me up on what happened in my business since yesterday.") },
143
+ { id: "p2", title: copyParam("ownerMaestro.p2.title", "What needs me today?"), text: copyParam("ownerMaestro.p2.text", "What needs my attention today?") },
144
+ { id: "p3", title: copyParam("ownerMaestro.p3.title", "Draft a promotion"), text: copyParam("ownerMaestro.p3.text", "Draft a promotion for my best-selling item and show it to me before sending.") },
145
+ ];
146
+ }
147
+
148
+ const initial: MaestroState = {
149
+ phase: "checking", checkingHidden: "false", chatHidden: "true", unavailableHidden: "true",
150
+ unavailableTitle: "", unavailableText: "",
151
+ messages: [], emptyHidden: "false", prompts: [], quickReplies: [], quickRepliesHidden: "true",
152
+ input: "", hasInput: false, noInput: true, busy: false, idle: true, statusText: "", error: "", scrollSend: "", scrollAnchor: "", ok: false,
153
+ _site: "", _account: "", _convId: "", _role: "", _openId: "", _turn: 0,
154
+ };
155
+
156
+ function unavailable(s: MaestroState, why: Unavailable): MaestroState {
157
+ const text = copy.unavailable(why);
158
+ return {
159
+ ...s, phase: "unavailable", checkingHidden: "true", chatHidden: "true", unavailableHidden: "false",
160
+ unavailableTitle: text.title, unavailableText: text.text, busy: false, idle: true, statusText: "",
161
+ };
162
+ }
163
+
164
+ interface Recipient { recipient?: { metaSiteId?: string } | null }
165
+ interface Spaces { workspaces?: Array<{ website?: { metaSiteId?: string } | null }> }
166
+
167
+ /** The owner's Symphony metasite, or "" when they have no Symphony account. Throws when the
168
+ * service could not be asked. */
169
+ async function symphonyAccount(api: WixApi): Promise<string> {
170
+ const res = (await api.call("POST", NATIVE_DATA, { action: "recipient" })) as Recipient | null;
171
+ const id = res?.recipient?.metaSiteId;
172
+ return typeof id === "string" ? id.trim() : "";
173
+ }
174
+
175
+ /** Whether `site` is the website of one of the owner's Spaces. */
176
+ async function isConnected(api: WixApi, account: string, site: string): Promise<boolean> {
177
+ const res = (await api.call("POST", SPACES, {}, forSite(account))) as Spaces | null;
178
+ return (res?.workspaces ?? []).some((w) => w?.website?.metaSiteId === site);
179
+ }
180
+
181
+ async function createConversation(api: WixApi, account: string, site: string): Promise<string> {
182
+ const res = (await api.call("POST", CONVERSATIONS, {
183
+ conversation: { source: "SCHEDULER", communicationChannel: "APP", name: "Owner app", metadata: { wixSiteId: site } },
184
+ }, forSite(account))) as { conversation?: { id?: string } } | null;
185
+ const id = res?.conversation?.id;
186
+ return typeof id === "string" ? id : "";
187
+ }
188
+
189
+ function streamDirective(s: MaestroState, text: string, choice?: { askId: string; optionId: string }): unknown {
190
+ return {
191
+ id: STREAM_ID,
192
+ request: {
193
+ method: "POST",
194
+ url: SEND,
195
+ // The host authorizes the request as the Symphony metasite: no token passes through here.
196
+ authorize: true,
197
+ format: "ndjson",
198
+ headers: { ...forSite(s._account), Accept: "application/x-ndjson", "X-Time-Budget": "300000" },
199
+ body: {
200
+ conversationId: s._convId, messageText: text, role: "USER", clientCapabilities: [],
201
+ deviceTimeZone: deviceTimeZone(), adoptsConversationId: true, communicationChannel: "APP",
202
+ ...(choice ? { choiceAnswer: choice } : {}),
203
+ },
204
+ },
205
+ onEvent: "streamEvent",
206
+ onDone: "streamDone",
207
+ onError: "streamFailed",
208
+ };
209
+ }
210
+
211
+ const settled = (messages: Bubble[]): Bubble[] => messages.filter((b) => b.id !== THINKING_ID);
212
+
213
+ // Actions are not queued: each one reads the state as it was when it was dispatched. A new chat
214
+ // awaits its conversation before `busy` can be stored, so a second send dispatched meanwhile
215
+ // would pass the `busy` guard and open a second conversation. This flag closes that window.
216
+ let opening = false;
217
+ // What the owner did while that conversation was being opened. The send's result is built from
218
+ // the state it was dispatched with, so a draft typed or a New chat tapped meanwhile would be
219
+ // overwritten by it; these let the result be rebased onto them (as Aria's `draftSeq` does).
220
+ let draftSeq = 0;
221
+ let draft = "";
222
+ let chatSeq = 0;
223
+
224
+ const freshChat = (s: MaestroState, input = ""): MaestroState => ({
225
+ ...s, messages: [], emptyHidden: "false", quickReplies: [], quickRepliesHidden: "true",
226
+ input, hasInput: input.trim().length > 0, noInput: input.trim().length === 0,
227
+ busy: false, idle: true, statusText: "", error: "", scrollSend: "", scrollAnchor: "",
228
+ _convId: "", _role: "", _openId: "",
229
+ });
230
+
231
+ async function send(s: MaestroState, raw: string, choice?: { askId: string; optionId: string }): Promise<MaestroState & { _stream?: unknown }> {
232
+ const text = (raw ?? "").trim();
233
+ if (!text || s.busy || opening || s.phase !== "ready") return s;
234
+ const api = host().wixApi;
235
+ if (!api) return { ...s, error: copy.failed() };
236
+ let convId = s._convId;
237
+ const draftAtSend = draftSeq;
238
+ const chatAtSend = chatSeq;
239
+ if (!convId) {
240
+ opening = true;
241
+ try { convId = await createConversation(api, s._account, s._site); } catch { convId = ""; } finally { opening = false; }
242
+ // New chat was tapped while this one was opening: the owner left it, so no turn starts.
243
+ if (chatSeq !== chatAtSend) return freshChat(s, draft);
244
+ const typed = draftSeq !== draftAtSend ? { input: draft, hasInput: draft.trim().length > 0, noInput: draft.trim().length === 0 } : {};
245
+ if (!convId) return { ...s, ...typed, error: copy.failed() };
246
+ }
247
+ const typedMeanwhile = draftSeq !== draftAtSend;
248
+ const turn = s._turn + 1;
249
+ const next: MaestroState = {
250
+ ...s, _convId: convId, _turn: turn, _role: "", _openId: "",
251
+ messages: [...settled(s.messages), userBubble(`u${turn}`, text), thinkingBubble()],
252
+ emptyHidden: "true", quickReplies: [], quickRepliesHidden: "true",
253
+ input: "", hasInput: false, noInput: true, busy: true, idle: false,
254
+ statusText: copy.thinking(), error: "", scrollSend: `turn-${turn}`, scrollAnchor: `${SCREEN}.message_u${turn}`, ok: false,
255
+ };
256
+ const kept: MaestroState = typedMeanwhile
257
+ ? { ...next, input: draft, hasInput: draft.trim().length > 0, noInput: draft.trim().length === 0 }
258
+ : next;
259
+ return { ...kept, _stream: streamDirective(kept, text, choice) };
260
+ }
261
+
262
+ interface StreamEvent {
263
+ type?: string;
264
+ data?: {
265
+ role?: string; deltaText?: string; text?: string; conversationId?: string;
266
+ choices?: { askId?: string; options?: Array<{ id?: string; label?: string }> };
267
+ };
268
+ }
269
+
270
+ function quickRepliesOf(data: StreamEvent["data"]): QuickReply[] {
271
+ const askId = data?.choices?.askId;
272
+ if (typeof askId !== "string" || !askId) return [];
273
+ return (data?.choices?.options ?? [])
274
+ .filter((o): o is { id: string; label: string } => typeof o?.id === "string" && typeof o?.label === "string" && !!o.label)
275
+ .map((o) => ({ id: o.id, label: o.label, askId }));
276
+ }
277
+
278
+ const finished = (s: MaestroState): MaestroState => ({
279
+ ...s, messages: settled(s.messages), busy: false, idle: true, statusText: "", _role: "", _openId: "",
280
+ });
281
+
282
+ type Arg = string | { value?: unknown; message?: string; text?: string; id?: string } | undefined;
283
+ const textOf = (arg: Arg): string => {
284
+ if (typeof arg === "string") return arg;
285
+ for (const v of [arg?.message, arg?.text, arg?.value]) if (typeof v === "string") return v;
286
+ return "";
287
+ };
288
+
289
+ const svc = defineService<MaestroState, {
290
+ load: (s: MaestroState, arg?: unknown) => Promise<MaestroState>;
291
+ setInput: (s: MaestroState, arg?: Arg) => Promise<MaestroState>;
292
+ submit: (s: MaestroState, arg?: Arg) => Promise<MaestroState>;
293
+ usePrompt: (s: MaestroState, arg?: Arg) => Promise<MaestroState>;
294
+ answer: (s: MaestroState, arg?: Arg) => Promise<MaestroState>;
295
+ stop: (s: MaestroState) => Promise<MaestroState>;
296
+ newChat: (s: MaestroState) => Promise<MaestroState>;
297
+ streamEvent: (s: MaestroState, ev?: StreamEvent) => Promise<MaestroState>;
298
+ streamDone: (s: MaestroState) => Promise<MaestroState>;
299
+ streamFailed: (s: MaestroState) => Promise<MaestroState>;
300
+ }>(SERVICE, {
301
+ state: initial,
302
+ // A turn lives only as long as its stream. Restored after an app kill, `busy` and the thinking
303
+ // bubble would describe a stream that no longer exists and the composer would refuse every send.
304
+ notHydrated: ["busy", "idle", "statusText", "error", "scrollSend", "scrollAnchor", "_role", "_openId", "quickReplies", "quickRepliesHidden"],
305
+ actions: {
306
+ // Runs on every appear. A conversation belongs to one business, so a switch starts over;
307
+ // returning to the same business keeps the transcript.
308
+ load: async (s, arg) => {
309
+ stashCopy(arg);
310
+ const site = activeSiteId();
311
+ if (s.phase === "ready" && s._site === site && site) {
312
+ // No turn in flight means no thinking bubble: one restored from a killed run is dropped.
313
+ return { ...s, prompts: prompts(), messages: s.busy ? s.messages : settled(s.messages) };
314
+ }
315
+ const fresh: MaestroState = { ...initial, _site: site, prompts: prompts() };
316
+ if (!site) return unavailable(fresh, "no_site");
317
+ const api = host().wixApi;
318
+ if (!api) return unavailable(fresh, "unreachable");
319
+ try {
320
+ const account = await symphonyAccount(api);
321
+ if (!account) return unavailable(fresh, "no_account");
322
+ if (!(await isConnected(api, account, site))) return unavailable(fresh, "not_connected");
323
+ return { ...fresh, phase: "ready", checkingHidden: "true", chatHidden: "false", _account: account };
324
+ } catch {
325
+ return unavailable(fresh, "unreachable");
326
+ }
327
+ },
328
+ setInput: async (s, arg) => {
329
+ const input = textOf(arg);
330
+ const has = input.trim().length > 0;
331
+ draftSeq += 1;
332
+ draft = input;
333
+ return { ...s, input, hasInput: has, noInput: !has };
334
+ },
335
+ submit: async (s, arg) => send(s, textOf(arg) || s.input),
336
+ usePrompt: async (s, arg) => {
337
+ const id = typeof arg === "object" ? arg?.id : "";
338
+ const prompt = s.prompts.find((p) => p.id === id);
339
+ return prompt ? send(s, prompt.text) : s;
340
+ },
341
+ // A quick reply is a normal turn that also names the question it answers.
342
+ answer: async (s, arg) => {
343
+ const id = typeof arg === "object" ? arg?.id : "";
344
+ const reply = s.quickReplies.find((q) => q.id === id);
345
+ return reply ? send(s, reply.label, { askId: reply.askId, optionId: reply.id }) : s;
346
+ },
347
+ // Local only, as in the Symphony iOS app: the turn keeps running on the server, and what it
348
+ // still streams is dropped because nothing is in flight here any more.
349
+ stop: async (s) => (s.busy ? finished(s) : s),
350
+ newChat: async (s) => {
351
+ if (s.phase !== "ready") return s;
352
+ chatSeq += 1;
353
+ draftSeq += 1;
354
+ draft = "";
355
+ return freshChat(s);
356
+ },
357
+ streamEvent: async (s, ev) => {
358
+ if (!s.busy) return s; // stopped, or a turn that already ended
359
+ const data = ev?.data ?? {};
360
+ if (ev?.type === "metadata") {
361
+ return typeof data.conversationId === "string" && data.conversationId ? { ...s, _convId: data.conversationId } : s;
362
+ }
363
+ if (ev?.type === "thinking") {
364
+ const line = (data.text ?? "").trim().split("\n").pop() ?? "";
365
+ return line ? { ...s, statusText: line } : s;
366
+ }
367
+ if (ev?.type === "messageStart") {
368
+ return { ...s, _role: typeof data.role === "string" ? data.role : "", _openId: "" };
369
+ }
370
+ if (ev?.type === "messageDelta") {
371
+ const delta = typeof data.deltaText === "string" ? data.deltaText : "";
372
+ if (!delta) return s;
373
+ // Only the reply itself becomes a bubble; a step or a thought is the status line.
374
+ if (s._role && s._role !== "ASSISTANT") {
375
+ const line = delta.trim().split("\n").pop() ?? "";
376
+ return line ? { ...s, statusText: line } : s;
377
+ }
378
+ const messages = settled(s.messages);
379
+ const open = messages.findIndex((b) => b.id === s._openId);
380
+ if (open >= 0) {
381
+ messages[open] = { ...messages[open], content: messages[open].content + delta };
382
+ return { ...s, messages, statusText: "" };
383
+ }
384
+ const id = `a${s._turn}_${messages.length}`;
385
+ return { ...s, messages: [...messages, assistantBubble(id, delta)], _openId: id, statusText: "" };
386
+ }
387
+ if (ev?.type === "messageEnd") {
388
+ const replies = quickRepliesOf(data);
389
+ return { ...s, _openId: "", quickReplies: replies, quickRepliesHidden: replies.length ? "false" : "true" };
390
+ }
391
+ return s;
392
+ },
393
+ streamDone: async (s) => (s.busy ? finished(s) : s),
394
+ streamFailed: async (s) => (s.busy ? { ...finished(s), error: copy.failed() } : s),
395
+ },
396
+ });
397
+
398
+ svc.load();
399
+ export { svc };
@@ -27,6 +27,15 @@ export function hasIntl(): boolean {
27
27
  return typeof Intl !== "undefined";
28
28
  }
29
29
 
30
+ /** The device's IANA time zone, or "UTC" where this engine has no ECMA-402 or no zone data. */
31
+ export function deviceTimeZone(): string {
32
+ try {
33
+ const zone = typeof Intl !== "undefined" && Intl.DateTimeFormat().resolvedOptions().timeZone;
34
+ if (typeof zone === "string" && zone) return zone;
35
+ } catch { /* an engine with Intl but no zone data */ }
36
+ return "UTC";
37
+ }
38
+
30
39
  const MONTHS_SHORT = [
31
40
  "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
32
41
  ] as const;
@@ -27,6 +27,15 @@ export function hasIntl(): boolean {
27
27
  return typeof Intl !== "undefined";
28
28
  }
29
29
 
30
+ /** The device's IANA time zone, or "UTC" where this engine has no ECMA-402 or no zone data. */
31
+ export function deviceTimeZone(): string {
32
+ try {
33
+ const zone = typeof Intl !== "undefined" && Intl.DateTimeFormat().resolvedOptions().timeZone;
34
+ if (typeof zone === "string" && zone) return zone;
35
+ } catch { /* an engine with Intl but no zone data */ }
36
+ return "UTC";
37
+ }
38
+
30
39
  const MONTHS_SHORT = [
31
40
  "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
32
41
  ] as const;
@@ -149,6 +149,13 @@ export default defineApp({
149
149
  "parentScreenId": "himi_owner_lite_aria",
150
150
  "tabId": "aria"
151
151
  },
152
+ {
153
+ "screenId": "himi_owner_lite_maestro",
154
+ "isPublic": false,
155
+ "paramKeys": [],
156
+ "parentScreenId": "himi_owner_lite_aria",
157
+ "tabId": "aria"
158
+ },
152
159
  {
153
160
  "screenId": "himi_owner_lite_brief",
154
161
  "isPublic": false,