@wix/himalaya-cli 0.1880.0 → 0.1882.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 (50) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/app-info/src/index.d.ts +4 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/app-info.mjs +1 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +1 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +48 -33
  5. package/dist/cli.mjs +345 -263
  6. package/package.json +2 -2
  7. package/templates/beauty-salon-owner/config.ts +22 -4
  8. package/templates/beauty-salon-owner/dev/index.ts +2 -1
  9. package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  10. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  11. package/templates/community-club-owner/config.ts +22 -4
  12. package/templates/community-club-owner/dev/index.ts +2 -1
  13. package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  14. package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  15. package/templates/events-meetups-owner/config.ts +22 -4
  16. package/templates/events-meetups-owner/dev/index.ts +2 -1
  17. package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  18. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  19. package/templates/gym-fitness-owner/config.ts +22 -4
  20. package/templates/gym-fitness-owner/dev/index.ts +2 -1
  21. package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  22. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  23. package/templates/nonprofit-cause-owner/config.ts +22 -4
  24. package/templates/nonprofit-cause-owner/dev/index.ts +2 -1
  25. package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  26. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  27. package/templates/owner-lite/config.ts +22 -4
  28. package/templates/owner-lite/dev/index.ts +2 -1
  29. package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  30. package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  31. package/templates/podcast-creator-owner/config.ts +22 -4
  32. package/templates/podcast-creator-owner/dev/index.ts +2 -1
  33. package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  34. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  35. package/templates/portfolio-creative-owner/config.ts +22 -4
  36. package/templates/portfolio-creative-owner/dev/index.ts +2 -1
  37. package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  38. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  39. package/templates/restaurant-owner/config.ts +22 -4
  40. package/templates/restaurant-owner/dev/index.ts +2 -1
  41. package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  42. package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  43. package/templates/retail-store-owner/config.ts +22 -4
  44. package/templates/retail-store-owner/dev/index.ts +2 -1
  45. package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  46. package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
  47. package/templates/yoga-studio-owner/config.ts +22 -4
  48. package/templates/yoga-studio-owner/dev/index.ts +2 -1
  49. package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +48 -0
  50. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +33 -31
@@ -153,8 +153,8 @@ export default defineApp({
153
153
  "screenId": "himi_owner_lite_maestro",
154
154
  "isPublic": false,
155
155
  "paramKeys": [],
156
- "parentScreenId": "himi_owner_lite_aria",
157
- "tabId": "aria"
156
+ "parentScreenId": "",
157
+ "tabId": "maestro"
158
158
  },
159
159
  {
160
160
  "screenId": "himi_owner_lite_brief",
@@ -649,7 +649,16 @@ export default defineApp({
649
649
  "id": "aria",
650
650
  "screenId": "himi_owner_lite_aria",
651
651
  "label": "Aria",
652
- "icon": "ai"
652
+ "icon": "ai",
653
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
654
+ },
655
+ {
656
+ "id": "maestro",
657
+ "screenId": "himi_owner_lite_maestro",
658
+ "label": "Maestro",
659
+ "icon": "ai",
660
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
661
+ "hiddenUntilResolved": true
653
662
  },
654
663
  {
655
664
  "id": "manage",
@@ -679,7 +688,16 @@ export default defineApp({
679
688
  "id": "aria",
680
689
  "screenId": "himi_owner_lite_aria",
681
690
  "label": "Aria",
682
- "icon": "ai"
691
+ "icon": "ai",
692
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
693
+ },
694
+ {
695
+ "id": "maestro",
696
+ "screenId": "himi_owner_lite_maestro",
697
+ "label": "Maestro",
698
+ "icon": "ai",
699
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
700
+ "hiddenUntilResolved": true
683
701
  },
684
702
  {
685
703
  "id": "manage",
@@ -64478,7 +64478,8 @@ const SCREENS = runtimeSetting({
64478
64478
  "contentType": "application/javascript+ts-bundle",
64479
64479
  "declaredCapabilities": [
64480
64480
  "wix_api",
64481
- "stream"
64481
+ "stream",
64482
+ "app_info"
64482
64483
  ],
64483
64484
  "minBinaryVersion": "0.1.0",
64484
64485
  "bundleVersion": "0.0.1"
@@ -0,0 +1,48 @@
1
+ // Whether Maestro (Symphony's assistant) can work for one of the owner's businesses.
2
+ //
3
+ // Two things must hold: the owner has a Symphony account, and the business is the website of
4
+ // one of that account's Spaces. Both are asked over the owner's own Wix session; nothing here
5
+ // holds a credential. Shared by the Maestro screen, which needs the answer to open its chat,
6
+ // and __HIMI_APP_NAME__'s app-level worker, which uses it to choose the assistant tab.
7
+
8
+ export interface MaestroWixApi {
9
+ call: (method: string, path: string, body?: unknown, headers?: Record<string, string>) => Promise<unknown>;
10
+ }
11
+
12
+ const NATIVE_DATA = "https://manage.wix.com/_serverless/ai-scheduling-assistant-server/native-data";
13
+ const SPACES = "https://manage.wix.com/_api/symphony-bff/v1/symphony/workspaces";
14
+
15
+ /** `wix-site-id` makes the host mint the credential for THAT metasite (the Symphony account),
16
+ * instead of the business on screen. */
17
+ export const forSymphonyAccount = (metaSiteId: string): Record<string, string> =>
18
+ ({ "wix-site-id": metaSiteId, "Content-Type": "application/json" });
19
+
20
+ interface Recipient { recipient?: { metaSiteId?: string } | null }
21
+ interface Spaces { workspaces?: Array<{ website?: { metaSiteId?: string } | null }> }
22
+
23
+ /** The owner's Symphony metasite, or "" when they have no Symphony account. Throws when the
24
+ * service could not be asked. */
25
+ export async function symphonyAccount(api: MaestroWixApi): Promise<string> {
26
+ const res = (await api.call("POST", NATIVE_DATA, { action: "recipient" })) as Recipient | null;
27
+ const id = res?.recipient?.metaSiteId;
28
+ return typeof id === "string" ? id.trim() : "";
29
+ }
30
+
31
+ /** Whether `site` is the website of one of the owner's Spaces. Throws when it could not be asked. */
32
+ export async function isSpaceWebsite(api: MaestroWixApi, account: string, site: string): Promise<boolean> {
33
+ const res = (await api.call("POST", SPACES, {}, forSymphonyAccount(account))) as Spaces | null;
34
+ return (res?.workspaces ?? []).some((w) => w?.website?.metaSiteId === site);
35
+ }
36
+
37
+ export type MaestroAvailability =
38
+ | { available: true; account: string }
39
+ | { available: false; why: "no_site" | "no_account" | "not_connected" };
40
+
41
+ /** The whole answer for one business. Throws when Symphony could not be asked, which is not a
42
+ * "no": a caller decides what an unanswered question means for it. */
43
+ export async function maestroAvailability(api: MaestroWixApi, site: string): Promise<MaestroAvailability> {
44
+ if (!site) return { available: false, why: "no_site" };
45
+ const account = await symphonyAccount(api);
46
+ if (!account) return { available: false, why: "no_account" };
47
+ return (await isSpaceWebsite(api, account, site)) ? { available: true, account } : { available: false, why: "not_connected" };
48
+ }
@@ -20,15 +20,15 @@
20
20
  // Verified against the live service on 2026-11-24.
21
21
 
22
22
  import { defineService } from "@himalaya/state";
23
+ import { get as appInfo } from "@himalaya/app-info";
23
24
  import { deviceTimeZone } from "../_shared/engine-intl.js";
24
25
  import { copyParam, stashCopy } from "../_shared/himi-copy.js";
25
26
  import { readSelectedSite } from "../_shared/owner-selected-site.js";
27
+ import { forSymphonyAccount, maestroAvailability } from "../_shared/owner-maestro-availability.js";
26
28
 
27
29
  const SERVICE = "himiOwnerLiteMaestro";
28
30
  /** The screen this worker paints: message rows are stamped `<screen>.message_<id>`. */
29
31
  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
32
  const CONVERSATIONS = "https://symphony.wix.com/individuals-chat/conversation/v1/conversations";
33
33
  const SEND = "https://symphony.wix.com/_api/symphony-harness/v1/send-message-streamed-http";
34
34
  const STREAM_ID = "maestro-turn";
@@ -49,10 +49,6 @@ function activeSiteId(): string {
49
49
  }
50
50
 
51
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
52
  export interface Bubble {
57
53
  id: string;
58
54
  content: string;
@@ -68,7 +64,7 @@ export interface QuickReply { id: string; label: string; askId: string }
68
64
  export interface Prompt { id: string; title: string; text: string }
69
65
 
70
66
  /** Why Maestro cannot be used here. Each one sends the owner to Aria. */
71
- type Unavailable = "" | "no_site" | "no_account" | "not_connected" | "unreachable";
67
+ type Unavailable = "" | "no_site" | "no_account" | "not_connected" | "unreachable" | "needs_update";
72
68
 
73
69
  export interface MaestroState {
74
70
  /** `checking` until the account and the Space are known. */
@@ -124,6 +120,12 @@ const copy = {
124
120
  text: copyParam("ownerMaestro.noSite.text", "Maestro works on one business at a time. Pick one in Sites, then come back."),
125
121
  };
126
122
  }
123
+ if (why === "needs_update") {
124
+ return {
125
+ title: copyParam("ownerMaestro.needsUpdate.title", "Update the app to use Maestro"),
126
+ text: copyParam("ownerMaestro.needsUpdate.text", "This version of the app can't show Maestro's replies. Until you update, Aria can help."),
127
+ };
128
+ }
127
129
  if (why === "unreachable") {
128
130
  return {
129
131
  title: copyParam("ownerMaestro.unreachable.title", "Maestro can't be reached right now"),
@@ -153,6 +155,17 @@ const initial: MaestroState = {
153
155
  _site: "", _account: "", _convId: "", _role: "", _openId: "", _turn: 0,
154
156
  };
155
157
 
158
+ /** Whether this host can read a streamed turn. `unknown` when the host could not be asked this
159
+ * time: that is not a "no", and it is asked again on the next load. */
160
+ type ReadsTurns = "yes" | "no" | "unknown";
161
+ let readsTurns: "yes" | "no" | undefined;
162
+ async function hostReadsTurns(): Promise<ReadsTurns> {
163
+ if (readsTurns === undefined) {
164
+ try { readsTurns = (await appInfo()).ndjsonStreamAvailable === true ? "yes" : "no"; } catch { return "unknown"; }
165
+ }
166
+ return readsTurns;
167
+ }
168
+
156
169
  function unavailable(s: MaestroState, why: Unavailable): MaestroState {
157
170
  const text = copy.unavailable(why);
158
171
  return {
@@ -161,27 +174,10 @@ function unavailable(s: MaestroState, why: Unavailable): MaestroState {
161
174
  };
162
175
  }
163
176
 
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
177
  async function createConversation(api: WixApi, account: string, site: string): Promise<string> {
182
178
  const res = (await api.call("POST", CONVERSATIONS, {
183
179
  conversation: { source: "SCHEDULER", communicationChannel: "APP", name: "Owner app", metadata: { wixSiteId: site } },
184
- }, forSite(account))) as { conversation?: { id?: string } } | null;
180
+ }, forSymphonyAccount(account))) as { conversation?: { id?: string } } | null;
185
181
  const id = res?.conversation?.id;
186
182
  return typeof id === "string" ? id : "";
187
183
  }
@@ -195,7 +191,7 @@ function streamDirective(s: MaestroState, text: string, choice?: { askId: string
195
191
  // The host authorizes the request as the Symphony metasite: no token passes through here.
196
192
  authorize: true,
197
193
  format: "ndjson",
198
- headers: { ...forSite(s._account), Accept: "application/x-ndjson", "X-Time-Budget": "300000" },
194
+ headers: { ...forSymphonyAccount(s._account), Accept: "application/x-ndjson", "X-Time-Budget": "300000" },
199
195
  body: {
200
196
  conversationId: s._convId, messageText: text, role: "USER", clientCapabilities: [],
201
197
  deviceTimeZone: deviceTimeZone(), adoptsConversationId: true, communicationChannel: "APP",
@@ -308,19 +304,25 @@ const svc = defineService<MaestroState, {
308
304
  load: async (s, arg) => {
309
305
  stashCopy(arg);
310
306
  const site = activeSiteId();
307
+ const fresh: MaestroState = { ...initial, _site: site, prompts: prompts() };
308
+ // A turn arrives as a stream of JSON lines. A host built before it could read one delivers
309
+ // nothing, so every send would end in the failure message: say so instead of offering a chat.
310
+ // Asked before a stored `ready` is trusted: an old host may have saved one.
311
+ const reads = await hostReadsTurns();
312
+ if (reads === "no") return unavailable(fresh, "needs_update");
311
313
  if (s.phase === "ready" && s._site === site && site) {
312
314
  // No turn in flight means no thinking bubble: one restored from a killed run is dropped.
313
315
  return { ...s, prompts: prompts(), messages: s.busy ? s.messages : settled(s.messages) };
314
316
  }
315
- const fresh: MaestroState = { ...initial, _site: site, prompts: prompts() };
317
+ // The host could not say. A chat already open is kept (above); a new one is not opened.
318
+ if (reads === "unknown") return unavailable(fresh, "unreachable");
316
319
  if (!site) return unavailable(fresh, "no_site");
317
320
  const api = host().wixApi;
318
321
  if (!api) return unavailable(fresh, "unreachable");
319
322
  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 };
323
+ const answer = await maestroAvailability(api, site);
324
+ if (!answer.available) return unavailable(fresh, answer.why);
325
+ return { ...fresh, phase: "ready", checkingHidden: "true", chatHidden: "false", _account: answer.account };
324
326
  } catch {
325
327
  return unavailable(fresh, "unreachable");
326
328
  }
@@ -153,8 +153,8 @@ export default defineApp({
153
153
  "screenId": "himi_owner_lite_maestro",
154
154
  "isPublic": false,
155
155
  "paramKeys": [],
156
- "parentScreenId": "himi_owner_lite_aria",
157
- "tabId": "aria"
156
+ "parentScreenId": "",
157
+ "tabId": "maestro"
158
158
  },
159
159
  {
160
160
  "screenId": "himi_owner_lite_brief",
@@ -570,7 +570,16 @@ export default defineApp({
570
570
  "id": "aria",
571
571
  "screenId": "himi_owner_lite_aria",
572
572
  "label": "Aria",
573
- "icon": "ai"
573
+ "icon": "ai",
574
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
575
+ },
576
+ {
577
+ "id": "maestro",
578
+ "screenId": "himi_owner_lite_maestro",
579
+ "label": "Maestro",
580
+ "icon": "ai",
581
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
582
+ "hiddenUntilResolved": true
574
583
  },
575
584
  {
576
585
  "id": "manage",
@@ -600,7 +609,16 @@ export default defineApp({
600
609
  "id": "aria",
601
610
  "screenId": "himi_owner_lite_aria",
602
611
  "label": "Aria",
603
- "icon": "ai"
612
+ "icon": "ai",
613
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
614
+ },
615
+ {
616
+ "id": "maestro",
617
+ "screenId": "himi_owner_lite_maestro",
618
+ "label": "Maestro",
619
+ "icon": "ai",
620
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
621
+ "hiddenUntilResolved": true
604
622
  },
605
623
  {
606
624
  "id": "manage",
@@ -64405,7 +64405,8 @@ const SCREENS = runtimeSetting({
64405
64405
  "contentType": "application/javascript+ts-bundle",
64406
64406
  "declaredCapabilities": [
64407
64407
  "wix_api",
64408
- "stream"
64408
+ "stream",
64409
+ "app_info"
64409
64410
  ],
64410
64411
  "minBinaryVersion": "0.1.0",
64411
64412
  "bundleVersion": "0.0.1"
@@ -0,0 +1,48 @@
1
+ // Whether Maestro (Symphony's assistant) can work for one of the owner's businesses.
2
+ //
3
+ // Two things must hold: the owner has a Symphony account, and the business is the website of
4
+ // one of that account's Spaces. Both are asked over the owner's own Wix session; nothing here
5
+ // holds a credential. Shared by the Maestro screen, which needs the answer to open its chat,
6
+ // and __HIMI_APP_NAME__'s app-level worker, which uses it to choose the assistant tab.
7
+
8
+ export interface MaestroWixApi {
9
+ call: (method: string, path: string, body?: unknown, headers?: Record<string, string>) => Promise<unknown>;
10
+ }
11
+
12
+ const NATIVE_DATA = "https://manage.wix.com/_serverless/ai-scheduling-assistant-server/native-data";
13
+ const SPACES = "https://manage.wix.com/_api/symphony-bff/v1/symphony/workspaces";
14
+
15
+ /** `wix-site-id` makes the host mint the credential for THAT metasite (the Symphony account),
16
+ * instead of the business on screen. */
17
+ export const forSymphonyAccount = (metaSiteId: string): Record<string, string> =>
18
+ ({ "wix-site-id": metaSiteId, "Content-Type": "application/json" });
19
+
20
+ interface Recipient { recipient?: { metaSiteId?: string } | null }
21
+ interface Spaces { workspaces?: Array<{ website?: { metaSiteId?: string } | null }> }
22
+
23
+ /** The owner's Symphony metasite, or "" when they have no Symphony account. Throws when the
24
+ * service could not be asked. */
25
+ export async function symphonyAccount(api: MaestroWixApi): Promise<string> {
26
+ const res = (await api.call("POST", NATIVE_DATA, { action: "recipient" })) as Recipient | null;
27
+ const id = res?.recipient?.metaSiteId;
28
+ return typeof id === "string" ? id.trim() : "";
29
+ }
30
+
31
+ /** Whether `site` is the website of one of the owner's Spaces. Throws when it could not be asked. */
32
+ export async function isSpaceWebsite(api: MaestroWixApi, account: string, site: string): Promise<boolean> {
33
+ const res = (await api.call("POST", SPACES, {}, forSymphonyAccount(account))) as Spaces | null;
34
+ return (res?.workspaces ?? []).some((w) => w?.website?.metaSiteId === site);
35
+ }
36
+
37
+ export type MaestroAvailability =
38
+ | { available: true; account: string }
39
+ | { available: false; why: "no_site" | "no_account" | "not_connected" };
40
+
41
+ /** The whole answer for one business. Throws when Symphony could not be asked, which is not a
42
+ * "no": a caller decides what an unanswered question means for it. */
43
+ export async function maestroAvailability(api: MaestroWixApi, site: string): Promise<MaestroAvailability> {
44
+ if (!site) return { available: false, why: "no_site" };
45
+ const account = await symphonyAccount(api);
46
+ if (!account) return { available: false, why: "no_account" };
47
+ return (await isSpaceWebsite(api, account, site)) ? { available: true, account } : { available: false, why: "not_connected" };
48
+ }
@@ -20,15 +20,15 @@
20
20
  // Verified against the live service on 2026-11-24.
21
21
 
22
22
  import { defineService } from "@himalaya/state";
23
+ import { get as appInfo } from "@himalaya/app-info";
23
24
  import { deviceTimeZone } from "../_shared/engine-intl.js";
24
25
  import { copyParam, stashCopy } from "../_shared/himi-copy.js";
25
26
  import { readSelectedSite } from "../_shared/owner-selected-site.js";
27
+ import { forSymphonyAccount, maestroAvailability } from "../_shared/owner-maestro-availability.js";
26
28
 
27
29
  const SERVICE = "himiOwnerLiteMaestro";
28
30
  /** The screen this worker paints: message rows are stamped `<screen>.message_<id>`. */
29
31
  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
32
  const CONVERSATIONS = "https://symphony.wix.com/individuals-chat/conversation/v1/conversations";
33
33
  const SEND = "https://symphony.wix.com/_api/symphony-harness/v1/send-message-streamed-http";
34
34
  const STREAM_ID = "maestro-turn";
@@ -49,10 +49,6 @@ function activeSiteId(): string {
49
49
  }
50
50
 
51
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
52
  export interface Bubble {
57
53
  id: string;
58
54
  content: string;
@@ -68,7 +64,7 @@ export interface QuickReply { id: string; label: string; askId: string }
68
64
  export interface Prompt { id: string; title: string; text: string }
69
65
 
70
66
  /** Why Maestro cannot be used here. Each one sends the owner to Aria. */
71
- type Unavailable = "" | "no_site" | "no_account" | "not_connected" | "unreachable";
67
+ type Unavailable = "" | "no_site" | "no_account" | "not_connected" | "unreachable" | "needs_update";
72
68
 
73
69
  export interface MaestroState {
74
70
  /** `checking` until the account and the Space are known. */
@@ -124,6 +120,12 @@ const copy = {
124
120
  text: copyParam("ownerMaestro.noSite.text", "Maestro works on one business at a time. Pick one in Sites, then come back."),
125
121
  };
126
122
  }
123
+ if (why === "needs_update") {
124
+ return {
125
+ title: copyParam("ownerMaestro.needsUpdate.title", "Update the app to use Maestro"),
126
+ text: copyParam("ownerMaestro.needsUpdate.text", "This version of the app can't show Maestro's replies. Until you update, Aria can help."),
127
+ };
128
+ }
127
129
  if (why === "unreachable") {
128
130
  return {
129
131
  title: copyParam("ownerMaestro.unreachable.title", "Maestro can't be reached right now"),
@@ -153,6 +155,17 @@ const initial: MaestroState = {
153
155
  _site: "", _account: "", _convId: "", _role: "", _openId: "", _turn: 0,
154
156
  };
155
157
 
158
+ /** Whether this host can read a streamed turn. `unknown` when the host could not be asked this
159
+ * time: that is not a "no", and it is asked again on the next load. */
160
+ type ReadsTurns = "yes" | "no" | "unknown";
161
+ let readsTurns: "yes" | "no" | undefined;
162
+ async function hostReadsTurns(): Promise<ReadsTurns> {
163
+ if (readsTurns === undefined) {
164
+ try { readsTurns = (await appInfo()).ndjsonStreamAvailable === true ? "yes" : "no"; } catch { return "unknown"; }
165
+ }
166
+ return readsTurns;
167
+ }
168
+
156
169
  function unavailable(s: MaestroState, why: Unavailable): MaestroState {
157
170
  const text = copy.unavailable(why);
158
171
  return {
@@ -161,27 +174,10 @@ function unavailable(s: MaestroState, why: Unavailable): MaestroState {
161
174
  };
162
175
  }
163
176
 
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
177
  async function createConversation(api: WixApi, account: string, site: string): Promise<string> {
182
178
  const res = (await api.call("POST", CONVERSATIONS, {
183
179
  conversation: { source: "SCHEDULER", communicationChannel: "APP", name: "Owner app", metadata: { wixSiteId: site } },
184
- }, forSite(account))) as { conversation?: { id?: string } } | null;
180
+ }, forSymphonyAccount(account))) as { conversation?: { id?: string } } | null;
185
181
  const id = res?.conversation?.id;
186
182
  return typeof id === "string" ? id : "";
187
183
  }
@@ -195,7 +191,7 @@ function streamDirective(s: MaestroState, text: string, choice?: { askId: string
195
191
  // The host authorizes the request as the Symphony metasite: no token passes through here.
196
192
  authorize: true,
197
193
  format: "ndjson",
198
- headers: { ...forSite(s._account), Accept: "application/x-ndjson", "X-Time-Budget": "300000" },
194
+ headers: { ...forSymphonyAccount(s._account), Accept: "application/x-ndjson", "X-Time-Budget": "300000" },
199
195
  body: {
200
196
  conversationId: s._convId, messageText: text, role: "USER", clientCapabilities: [],
201
197
  deviceTimeZone: deviceTimeZone(), adoptsConversationId: true, communicationChannel: "APP",
@@ -308,19 +304,25 @@ const svc = defineService<MaestroState, {
308
304
  load: async (s, arg) => {
309
305
  stashCopy(arg);
310
306
  const site = activeSiteId();
307
+ const fresh: MaestroState = { ...initial, _site: site, prompts: prompts() };
308
+ // A turn arrives as a stream of JSON lines. A host built before it could read one delivers
309
+ // nothing, so every send would end in the failure message: say so instead of offering a chat.
310
+ // Asked before a stored `ready` is trusted: an old host may have saved one.
311
+ const reads = await hostReadsTurns();
312
+ if (reads === "no") return unavailable(fresh, "needs_update");
311
313
  if (s.phase === "ready" && s._site === site && site) {
312
314
  // No turn in flight means no thinking bubble: one restored from a killed run is dropped.
313
315
  return { ...s, prompts: prompts(), messages: s.busy ? s.messages : settled(s.messages) };
314
316
  }
315
- const fresh: MaestroState = { ...initial, _site: site, prompts: prompts() };
317
+ // The host could not say. A chat already open is kept (above); a new one is not opened.
318
+ if (reads === "unknown") return unavailable(fresh, "unreachable");
316
319
  if (!site) return unavailable(fresh, "no_site");
317
320
  const api = host().wixApi;
318
321
  if (!api) return unavailable(fresh, "unreachable");
319
322
  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 };
323
+ const answer = await maestroAvailability(api, site);
324
+ if (!answer.available) return unavailable(fresh, answer.why);
325
+ return { ...fresh, phase: "ready", checkingHidden: "true", chatHidden: "false", _account: answer.account };
324
326
  } catch {
325
327
  return unavailable(fresh, "unreachable");
326
328
  }
@@ -153,8 +153,8 @@ export default defineApp({
153
153
  "screenId": "himi_owner_lite_maestro",
154
154
  "isPublic": false,
155
155
  "paramKeys": [],
156
- "parentScreenId": "himi_owner_lite_aria",
157
- "tabId": "aria"
156
+ "parentScreenId": "",
157
+ "tabId": "maestro"
158
158
  },
159
159
  {
160
160
  "screenId": "himi_owner_lite_brief",
@@ -586,7 +586,16 @@ export default defineApp({
586
586
  "id": "aria",
587
587
  "screenId": "himi_owner_lite_aria",
588
588
  "label": "Aria",
589
- "icon": "ai"
589
+ "icon": "ai",
590
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
591
+ },
592
+ {
593
+ "id": "maestro",
594
+ "screenId": "himi_owner_lite_maestro",
595
+ "label": "Maestro",
596
+ "icon": "ai",
597
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
598
+ "hiddenUntilResolved": true
590
599
  },
591
600
  {
592
601
  "id": "manage",
@@ -616,7 +625,16 @@ export default defineApp({
616
625
  "id": "aria",
617
626
  "screenId": "himi_owner_lite_aria",
618
627
  "label": "Aria",
619
- "icon": "ai"
628
+ "icon": "ai",
629
+ "hiddenPath": "$service:ownerLiteNav.ariaTabHidden"
630
+ },
631
+ {
632
+ "id": "maestro",
633
+ "screenId": "himi_owner_lite_maestro",
634
+ "label": "Maestro",
635
+ "icon": "ai",
636
+ "hiddenPath": "$service:ownerLiteNav.maestroTabHidden",
637
+ "hiddenUntilResolved": true
620
638
  },
621
639
  {
622
640
  "id": "manage",
@@ -64405,7 +64405,8 @@ const SCREENS = runtimeSetting({
64405
64405
  "contentType": "application/javascript+ts-bundle",
64406
64406
  "declaredCapabilities": [
64407
64407
  "wix_api",
64408
- "stream"
64408
+ "stream",
64409
+ "app_info"
64409
64410
  ],
64410
64411
  "minBinaryVersion": "0.1.0",
64411
64412
  "bundleVersion": "0.0.1"
@@ -0,0 +1,48 @@
1
+ // Whether Maestro (Symphony's assistant) can work for one of the owner's businesses.
2
+ //
3
+ // Two things must hold: the owner has a Symphony account, and the business is the website of
4
+ // one of that account's Spaces. Both are asked over the owner's own Wix session; nothing here
5
+ // holds a credential. Shared by the Maestro screen, which needs the answer to open its chat,
6
+ // and __HIMI_APP_NAME__'s app-level worker, which uses it to choose the assistant tab.
7
+
8
+ export interface MaestroWixApi {
9
+ call: (method: string, path: string, body?: unknown, headers?: Record<string, string>) => Promise<unknown>;
10
+ }
11
+
12
+ const NATIVE_DATA = "https://manage.wix.com/_serverless/ai-scheduling-assistant-server/native-data";
13
+ const SPACES = "https://manage.wix.com/_api/symphony-bff/v1/symphony/workspaces";
14
+
15
+ /** `wix-site-id` makes the host mint the credential for THAT metasite (the Symphony account),
16
+ * instead of the business on screen. */
17
+ export const forSymphonyAccount = (metaSiteId: string): Record<string, string> =>
18
+ ({ "wix-site-id": metaSiteId, "Content-Type": "application/json" });
19
+
20
+ interface Recipient { recipient?: { metaSiteId?: string } | null }
21
+ interface Spaces { workspaces?: Array<{ website?: { metaSiteId?: string } | null }> }
22
+
23
+ /** The owner's Symphony metasite, or "" when they have no Symphony account. Throws when the
24
+ * service could not be asked. */
25
+ export async function symphonyAccount(api: MaestroWixApi): Promise<string> {
26
+ const res = (await api.call("POST", NATIVE_DATA, { action: "recipient" })) as Recipient | null;
27
+ const id = res?.recipient?.metaSiteId;
28
+ return typeof id === "string" ? id.trim() : "";
29
+ }
30
+
31
+ /** Whether `site` is the website of one of the owner's Spaces. Throws when it could not be asked. */
32
+ export async function isSpaceWebsite(api: MaestroWixApi, account: string, site: string): Promise<boolean> {
33
+ const res = (await api.call("POST", SPACES, {}, forSymphonyAccount(account))) as Spaces | null;
34
+ return (res?.workspaces ?? []).some((w) => w?.website?.metaSiteId === site);
35
+ }
36
+
37
+ export type MaestroAvailability =
38
+ | { available: true; account: string }
39
+ | { available: false; why: "no_site" | "no_account" | "not_connected" };
40
+
41
+ /** The whole answer for one business. Throws when Symphony could not be asked, which is not a
42
+ * "no": a caller decides what an unanswered question means for it. */
43
+ export async function maestroAvailability(api: MaestroWixApi, site: string): Promise<MaestroAvailability> {
44
+ if (!site) return { available: false, why: "no_site" };
45
+ const account = await symphonyAccount(api);
46
+ if (!account) return { available: false, why: "no_account" };
47
+ return (await isSpaceWebsite(api, account, site)) ? { available: true, account } : { available: false, why: "not_connected" };
48
+ }