@wix/himalaya-cli 0.1929.0 → 0.1930.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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +7 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/chat-web/src/index.d.ts +12 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-chat-web.mjs +19 -9
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{95a3ae045bad903e458ea7a5800e60e1044f0f754a65d7127de66ba62e897068.bin → 7656e5effbeaee2ab20810b9903e7e785d9dffb0a0563f25c2746011cf4e23e9.bin} +1 -1
- package/dist/browser-plane/sw.js +10 -10
- package/dist/cli.mjs +254 -70
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-index.md +1 -1
- package/guides/component-reference.json +1 -1
- package/guides/component-reference.md +7 -0
- package/guides/sdk-reference.json +2 -2
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon-owner/dev/index.ts +169 -139
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/branded-lite/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/brandy/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club-owner/dev/index.ts +167 -132
- package/templates/community-club-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/community-club-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/community-club-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/community-club-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/conference/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups-owner/dev/index.ts +165 -125
- package/templates/events-meetups-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/events-meetups-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness-owner/dev/index.ts +169 -139
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/gym-fitness-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/himi-chat/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/medical-services/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause-owner/dev/index.ts +167 -132
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/nonprofit-cause-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/owner-lite/dev/index.ts +171 -141
- package/templates/owner-lite/himalaya.content.json +1 -1
- package/templates/owner-lite/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/owner-lite/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/owner-lite/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/owner-lite/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/owner-lite/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/owner-lite/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator-owner/dev/index.ts +167 -132
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/portfolio-creative-owner/dev/index.ts +169 -139
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/portfolio-creative-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant-owner/dev/index.ts +169 -139
- package/templates/restaurant-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/restaurant-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/restaurant-owner/tier5-src/wix-owner-booking/index.ts +4 -1
- package/templates/retail-store/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/retail-store-owner/dev/index.ts +167 -132
- package/templates/retail-store-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/retail-store-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-order/index.ts +4 -1
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/wholesale-store/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio-owner/dev/index.ts +167 -132
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-load-error.ts +1 -1
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +12 -2
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-tab.ts +81 -5
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-selected-site.ts +15 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-widget-reads.ts +7 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-home/index.ts +30 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox/index.ts +47 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +12 -5
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +132 -39
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +10 -8
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-record/index.ts +7 -1
- package/templates/yoga-studio-owner/tier5-src/wix-owner-booking/index.ts +4 -1
|
@@ -21,3 +21,10 @@ export function isSectionUnavailable(e: unknown): boolean {
|
|
|
21
21
|
const text = String((e as Error)?.message ?? e);
|
|
22
22
|
return /^HTTP (?:403|404|428)\b/.test(text) || /^HTTP \d{3} \[(?:FAILED_PRECONDITION|PERMISSION_DENIED)\]/.test(text);
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
/** The business has not set this area up: its app is not installed on the site, which Wix
|
|
26
|
+
* answers with 428. Narrower than `isSectionUnavailable`: a 403 or a 404 may be a mistake
|
|
27
|
+
* worth showing, while this one is simply "nothing here". Read from the leading status only. */
|
|
28
|
+
export function isNotInstalled(e: unknown): boolean {
|
|
29
|
+
return /^HTTP 428\b/.test(String((e as Error)?.message ?? e));
|
|
30
|
+
}
|
|
@@ -19,10 +19,11 @@ import { getSiteAnalytics, getSiteTimeZone, localDateRange, localDateOf, localMi
|
|
|
19
19
|
// `text(...)` and never matched on — the RAW reason is kept beside it in
|
|
20
20
|
// `<part>Reason` for anything that needs it — so the display-only reduction is
|
|
21
21
|
// both safe here and the reason a 428 reason code stopped reaching the owner.
|
|
22
|
-
import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback } from "../_shared/owner-load-error.js";
|
|
22
|
+
import { ownerDisplayError, isOwnerPreviewDemo, ownerDemoFallback, SITE_CONTEXT_CODES } from "../_shared/owner-load-error.js";
|
|
23
|
+
import { isNotInstalled } from "../_shared/owner-widget-reads.js";
|
|
23
24
|
import { DEMO_DASHBOARD, DEMO_NOTE, DEMO_TODAY } from "../_shared/owner-preview-demo.js";
|
|
24
25
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
25
|
-
import { fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
|
|
26
|
+
import { currentBusinessId, fallbackNameFrom, selectedSiteName } from "../_shared/owner-selected-site.js";
|
|
26
27
|
import { settleBusinessSwitch } from "../_shared/owner-site-pick.js";
|
|
27
28
|
import { formatCurrency } from "../_shared/engine-intl.js";
|
|
28
29
|
import {
|
|
@@ -566,6 +567,14 @@ async function loadSourcePart(source: HomeSourceId, part: SourcePart): Promise<S
|
|
|
566
567
|
}
|
|
567
568
|
}
|
|
568
569
|
|
|
570
|
+
/** Wix refusing a read because the call names no business the session may read: a 403, or one
|
|
571
|
+
* of the "no site in this request" codes. Read from the leading status only. */
|
|
572
|
+
function isSiteRefusal(reason: unknown): boolean {
|
|
573
|
+
const text = String((reason as Error)?.message ?? reason);
|
|
574
|
+
const coded = /^HTTP \d{3} \[([A-Z0-9_]+)\]/.exec(text);
|
|
575
|
+
return /^HTTP 403\b/.test(text) || (!!coded && SITE_CONTEXT_CODES.includes(coded[1]));
|
|
576
|
+
}
|
|
577
|
+
|
|
569
578
|
async function loadSource(source: HomeSourceId, parts = sourceParts(source)): Promise<SourceResult> {
|
|
570
579
|
const settled = await Promise.allSettled(parts.map(async (part) => ({ part, payload: await loadSourcePart(source, part) })));
|
|
571
580
|
const result: SourceResult = {};
|
|
@@ -662,20 +671,24 @@ function composeState(): HomeState {
|
|
|
662
671
|
const now = Date.now();
|
|
663
672
|
const sourceStates: SourceState[] = activeSources.map((id) => {
|
|
664
673
|
const result = sourceResults.get(id);
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
674
|
+
// An area the business has not set up (Wix answers 428: its app is not on the site) has
|
|
675
|
+
// nothing to show and nothing to retry. It reads as empty, not as a failed card: a Space
|
|
676
|
+
// website with no store, events, reviews or reservations used to open on four red cards.
|
|
677
|
+
const absent = (part: SourcePart): boolean => result?.[`${part}Reason`] !== undefined && isNotInstalled(result[`${part}Reason`]);
|
|
678
|
+
const primaryError = absent("primary") ? "" : result?.primaryError ?? "";
|
|
679
|
+
const activityError = absent("activity") ? "" : result?.activityError ?? "";
|
|
680
|
+
const metricsError = absent("metrics") ? "" : result?.metricsError ?? "";
|
|
668
681
|
const status: SourceStatus = primaryError ? "unavailable" : result?.primary
|
|
669
682
|
? (sourceIsEmpty(id, result) ? "empty" : "ready")
|
|
670
|
-
: "loading";
|
|
683
|
+
: absent("primary") ? "empty" : "loading";
|
|
671
684
|
const activityStatus: SourceState["activityStatus"] = !ACTIVITY_SOURCES.has(id) ? "not_applicable"
|
|
672
685
|
: activityError ? "unavailable"
|
|
673
686
|
: result?.activity ? (rowsFor(id, result.activity).length ? "ready" : "empty")
|
|
674
|
-
: "loading";
|
|
687
|
+
: absent("activity") ? "empty" : "loading";
|
|
675
688
|
const metricsStatus: SourceState["metricsStatus"] = id !== "orders" ? "not_applicable"
|
|
676
689
|
: metricsError ? "unavailable"
|
|
677
690
|
: result?.metrics ? (rowsFor(id, result.metrics).length ? "ready" : "empty")
|
|
678
|
-
: "loading";
|
|
691
|
+
: absent("metrics") ? "empty" : "loading";
|
|
679
692
|
const failedParts = [primaryError && "primary", metricsError && "metrics", activityError && "activity"].filter(Boolean);
|
|
680
693
|
const retryLabel = failedParts.length === 1 && failedParts[0] !== "primary"
|
|
681
694
|
? `Retry ${SOURCE_LABELS[id]} ${failedParts[0]}`
|
|
@@ -802,6 +815,15 @@ async function loadDashboard(s: HomeState, sources: HomeSourceId[]): Promise<Hom
|
|
|
802
815
|
for (const result of results) sourceResults.set(result.source, result.value);
|
|
803
816
|
const successfulParts = results.flatMap(({ value }) => [value.primary, value.metrics, value.activity]).filter(Boolean);
|
|
804
817
|
const failedReasons = results.flatMap(({ value }) => [value.primaryReason, value.metricsReason, value.activityReason]).filter((reason) => reason !== undefined);
|
|
818
|
+
// No business was ever picked, and Wix refused every read of one (the account's own site
|
|
819
|
+
// count aside): the session is at the account, not at a business. One line saying so replaces
|
|
820
|
+
// a card per area, each blaming a business (named after the app's own provisioning) that the
|
|
821
|
+
// owner never chose. A host that reads a business without naming one is left alone.
|
|
822
|
+
const readABusiness = results.some(({ source, value }) => source !== "sites" && (value.primary || value.metrics || value.activity));
|
|
823
|
+
if (!currentBusinessId() && !readABusiness && failedReasons.length > 0 && failedReasons.every(isSiteRefusal)) {
|
|
824
|
+
currentBusinessName = copyParam("ownerHome.noBusiness", "No business chosen");
|
|
825
|
+
return shape({ status: "error", error: copyParam("ownerHome.chooseBusiness", "Choose a business to see its day here. Tap Switch business.") });
|
|
826
|
+
}
|
|
805
827
|
if (successfulParts.length === 0) {
|
|
806
828
|
if (failedReasons.length > 0 && failedReasons.every((reason) => ownerDemoFallback(reason))) {
|
|
807
829
|
return demoDashboard(shape({ ...s, sourceStates: [], sourceFailures: [] }));
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { defineService, type PollDirective } from "@himalaya/state";
|
|
25
25
|
import { listChatrooms, archiveChatroom, markChatroomUnread, type Chatroom } from "@himalaya/wix-chat-web";
|
|
26
|
+
import { currentBusinessId, readSelectedSite } from "../_shared/owner-selected-site.js";
|
|
26
27
|
import { formatMonthDay } from "../_shared/engine-intl.js";
|
|
27
28
|
import { ownerLoadError, ownerWriteError } from "../_shared/owner-load-error.js";
|
|
28
29
|
import { stashCopy, copyParam } from "../_shared/himi-copy.js";
|
|
@@ -93,13 +94,38 @@ function relTime(ms?: number): string {
|
|
|
93
94
|
return formatMonthDay(d);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
/** The business a conversation belongs to, as the owner knows it ("" when Wix does not say). */
|
|
98
|
+
const businessOf = (c: Chatroom): string => (c.businessContext?.name || "").trim();
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether each row must say which business it belongs to.
|
|
102
|
+
*
|
|
103
|
+
* Wix answers an owner with ONE inbox for the whole account: the same conversations whichever
|
|
104
|
+
* business the call names (measured live 2026-11-28, the calls addressed to two different
|
|
105
|
+
* businesses, the rows identical; each row carries its own `businessContext`). A row's business
|
|
106
|
+
* is not a site id, so the list cannot be cut down to the picked business. Without a label the
|
|
107
|
+
* owner reads another business's conversations as this one's. Rows are labelled when they come
|
|
108
|
+
* from more than one business, or from one that is not the business on screen. When the name of
|
|
109
|
+
* the business on screen is not known (a host that scoped it without a pick), there is nothing
|
|
110
|
+
* to compare with, so a business Wix names is always shown.
|
|
111
|
+
*/
|
|
112
|
+
export function labelsBusiness(rooms: Chatroom[], pickedName: string): boolean {
|
|
113
|
+
const names = new Set(rooms.map(businessOf).filter(Boolean));
|
|
114
|
+
if (names.size > 1) return true;
|
|
115
|
+
const [only] = [...names];
|
|
116
|
+
if (!only) return false;
|
|
117
|
+
return !pickedName.trim() || only.toLowerCase() !== pickedName.trim().toLowerCase();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function rowOf(c: Chatroom, withBusiness = false): InboxRow {
|
|
97
121
|
const fallback = copyParam("ownerInbox.untitled", "Conversation");
|
|
98
122
|
const display = (c.displayData?.name || c.lastMessage?.senderDisplayData?.name || "").trim() || fallback;
|
|
99
123
|
const image = c.displayData?.image?.url || c.lastMessage?.senderDisplayData?.image?.url || "";
|
|
100
124
|
const unread = Math.max(0, c.unreadCount ?? 0);
|
|
101
125
|
const unreadText = unread > 0 ? (unread > 99 ? "99+" : String(unread)) : "";
|
|
102
|
-
const
|
|
126
|
+
const preview = (c.lastMessage?.summary || "").trim().slice(0, 120);
|
|
127
|
+
const business = withBusiness ? businessOf(c) : "";
|
|
128
|
+
const subtitle = [business, preview].filter(Boolean).join(" · ");
|
|
103
129
|
const unreadLabel = unread === 0 ? "" : unread === 1
|
|
104
130
|
? copyParam("ownerInbox.oneUnread", "1 unread message")
|
|
105
131
|
: `${unreadText} ${copyParam("ownerInbox.manyUnread", "unread messages")}`;
|
|
@@ -209,6 +235,8 @@ const archivedAt = new Map<string, number>();
|
|
|
209
235
|
const unreadAt = new Map<string, { at: number; until: number }>();
|
|
210
236
|
const UNREAD_GRACE_MS = 3000;
|
|
211
237
|
let readGeneration = 0;
|
|
238
|
+
/** The business the last read was for. */
|
|
239
|
+
let readSite = "";
|
|
212
240
|
/** The newest read whose answer reached the screen. Reads are not ordered — a `load` on
|
|
213
241
|
* return can start a read while a poll tick's is still in flight — so an OLDER read that
|
|
214
242
|
* finishes after a newer one is dropped instead of painting the past over it. */
|
|
@@ -222,8 +250,19 @@ let appliedGeneration = 0;
|
|
|
222
250
|
*/
|
|
223
251
|
async function read(): Promise<InboxState> {
|
|
224
252
|
const generation = ++readGeneration;
|
|
253
|
+
// Every call names the business: this tab is kept alive across a business switch, and its
|
|
254
|
+
// Wix connection stays on the business it was opened for. A switch also ends what was
|
|
255
|
+
// learnt about the last business's rows.
|
|
256
|
+
const site = currentBusinessId();
|
|
257
|
+
if (site !== readSite) {
|
|
258
|
+
readSite = site;
|
|
259
|
+
archivedAt.clear();
|
|
260
|
+
unreadAt.clear();
|
|
261
|
+
}
|
|
225
262
|
try {
|
|
226
|
-
const rooms = await listChatrooms(PAGE_SIZE);
|
|
263
|
+
const rooms = await listChatrooms(PAGE_SIZE, { siteId: site });
|
|
264
|
+
// The owner switched business while this was read: its rows are the last business's.
|
|
265
|
+
if (site !== currentBusinessId()) return liveState();
|
|
227
266
|
// Stale first: a read older than one already painted changes nothing — not the screen,
|
|
228
267
|
// and not the fences either.
|
|
229
268
|
if (generation < appliedGeneration) return liveState();
|
|
@@ -231,9 +270,9 @@ async function read(): Promise<InboxState> {
|
|
|
231
270
|
for (const [id, at] of archivedAt) if (at < generation && !rooms.some((c) => c?.id === id)) archivedAt.delete(id);
|
|
232
271
|
const clock = Date.now();
|
|
233
272
|
for (const [id, fence] of unreadAt) if (fence.at < generation && clock >= fence.until) unreadAt.delete(id);
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
273
|
+
const listed = rooms.filter((c) => c?.id && !c.isArchived && !archivedAt.has(c.id));
|
|
274
|
+
const withBusiness = labelsBusiness(listed, readSelectedSite()?.name ?? "");
|
|
275
|
+
const all = listed.map((c) => rowOf(unreadAt.has(c.id) ? { ...c, unreadCount: Math.max(1, c.unreadCount ?? 0) } : c, withBusiness));
|
|
237
276
|
const now = liveState();
|
|
238
277
|
return shape({ status: "ready", all, filter: now.filter, query: now.query });
|
|
239
278
|
} catch (e) {
|
|
@@ -274,7 +313,7 @@ const svc = defineService<InboxState, {
|
|
|
274
313
|
const id = idOf(arg);
|
|
275
314
|
if (!id) return s;
|
|
276
315
|
try {
|
|
277
|
-
await archiveChatroom(id, true);
|
|
316
|
+
await archiveChatroom(id, true, { siteId: currentBusinessId() });
|
|
278
317
|
} catch (e) {
|
|
279
318
|
return { ...liveState(), actionError: ownerWriteError(e) };
|
|
280
319
|
}
|
|
@@ -287,7 +326,7 @@ const svc = defineService<InboxState, {
|
|
|
287
326
|
const id = idOf(arg);
|
|
288
327
|
if (!id) return s;
|
|
289
328
|
try {
|
|
290
|
-
await markChatroomUnread(id);
|
|
329
|
+
await markChatroomUnread(id, undefined, { siteId: currentBusinessId() });
|
|
291
330
|
} catch (e) {
|
|
292
331
|
return { ...liveState(), actionError: ownerWriteError(e) };
|
|
293
332
|
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { defineService, navigate, type NavDirective, type PollDirective, type StreamDirective } from "@himalaya/state";
|
|
22
22
|
import { getMessages, sendChatMessage, listChatrooms, markChatroomRead, getChatToken, type ChatMessage } from "@himalaya/wix-chat-web";
|
|
23
|
+
import { currentBusinessId } from "../_shared/owner-selected-site.js";
|
|
23
24
|
import { formatMonthDayTime } from "../_shared/engine-intl.js";
|
|
24
25
|
import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
25
26
|
import { isOfflineFailure, ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
|
|
@@ -106,7 +107,7 @@ function headerOf(msgs: ChatMessage[], fallback: string): string {
|
|
|
106
107
|
|
|
107
108
|
/** The conversation a contact is in, or "" when the owner's recent conversations have none. */
|
|
108
109
|
async function chatroomForContact(contactId: string): Promise<{ id: string; name: string }> {
|
|
109
|
-
const rooms = await listChatrooms(LOOKUP_SIZE);
|
|
110
|
+
const rooms = await listChatrooms(LOOKUP_SIZE, { siteId: threadSite });
|
|
110
111
|
const room = rooms.find((r) => r?.id && r.participantId === contactId);
|
|
111
112
|
return room ? { id: room.id, name: (room.displayData?.name || "").trim() } : { id: "", name: "" };
|
|
112
113
|
}
|
|
@@ -114,15 +115,20 @@ async function chatroomForContact(contactId: string): Promise<{ id: string; name
|
|
|
114
115
|
// The conversation the gate re-reads. Module state, not worker state: a re-read must use
|
|
115
116
|
// the conversation this screen opened even if an older state object is in flight.
|
|
116
117
|
let current = "";
|
|
118
|
+
// The business this thread was opened in. Read once per open, with the visit token: a thread
|
|
119
|
+
// belongs to one business, and a switch while it is on screen must not send its calls (or a
|
|
120
|
+
// token minted for the first business) to the other one.
|
|
121
|
+
let threadSite = "";
|
|
117
122
|
let realtime: ChatRealtimeConfig | null = null;
|
|
118
123
|
|
|
119
124
|
// ONE chatToken per visit (`_shared/chat-live.ts`): a 4 s re-read would otherwise mint a
|
|
120
125
|
// token every 4 s on top of its GET. Reset on every open.
|
|
121
|
-
|
|
126
|
+
// Every call names the business the thread was opened in (`threadSite`), as the Inbox list names its own.
|
|
127
|
+
const visitToken = createVisitToken(() => getChatToken({ siteId: threadSite }).then((t) => t.chatToken));
|
|
122
128
|
async function readThread(): Promise<ChatMessage[]> {
|
|
123
129
|
const token = visitToken.get();
|
|
124
130
|
try {
|
|
125
|
-
return await getMessages(current, PAGE_SIZE, { chatToken: await token });
|
|
131
|
+
return await getMessages(current, PAGE_SIZE, { chatToken: await token, siteId: threadSite });
|
|
126
132
|
} catch (e) {
|
|
127
133
|
visitToken.drop(token);
|
|
128
134
|
throw e;
|
|
@@ -135,7 +141,7 @@ const intents = createSendIntents();
|
|
|
135
141
|
/** Post once per intent: a retried tap of the same text reuses its message id. */
|
|
136
142
|
async function postOnce(chatroomId: string, text: string): Promise<void> {
|
|
137
143
|
const messageId = intents.idFor(chatroomId, text);
|
|
138
|
-
await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId }));
|
|
144
|
+
await postWithVisitToken(visitToken, (chatToken) => sendChatMessage(chatroomId, text, { chatToken, messageId, siteId: threadSite }));
|
|
139
145
|
intents.settle(chatroomId, text);
|
|
140
146
|
}
|
|
141
147
|
|
|
@@ -154,7 +160,7 @@ function markRead(chatroomId: string, msgs: ChatMessage[]): void {
|
|
|
154
160
|
if (seq === undefined || seq <= (markedUpTo.get(chatroomId) ?? -1)) return;
|
|
155
161
|
markedUpTo.set(chatroomId, seq);
|
|
156
162
|
void visitToken.get()
|
|
157
|
-
.then((t) => markChatroomRead(chatroomId, seq, { chatToken: t }))
|
|
163
|
+
.then((t) => markChatroomRead(chatroomId, seq, { chatToken: t, siteId: threadSite }))
|
|
158
164
|
.catch(() => {
|
|
159
165
|
if (markedUpTo.get(chatroomId) === seq) markedUpTo.delete(chatroomId);
|
|
160
166
|
});
|
|
@@ -229,6 +235,7 @@ const svc = defineService<ThreadState, {
|
|
|
229
235
|
const { id, kind } = input();
|
|
230
236
|
if (!id) return { ...s, ...presence("missing"), status: "ready", phase: "ready", messages: [], hideEmpty: true, live: "off" };
|
|
231
237
|
visitToken.reset();
|
|
238
|
+
threadSite = currentBusinessId();
|
|
232
239
|
|
|
233
240
|
let chatroomId = id;
|
|
234
241
|
let headerName = s.headerName;
|
|
@@ -29,8 +29,9 @@ import { defineService } from "@himalaya/state";
|
|
|
29
29
|
import { get as appInfo } from "@himalaya/app-info";
|
|
30
30
|
import { deviceTimeZone } from "../_shared/engine-intl.js";
|
|
31
31
|
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
32
|
-
import {
|
|
32
|
+
import { currentBusinessId } from "../_shared/owner-selected-site.js";
|
|
33
33
|
import { forSymphonyAccount, hostCannotRunMaestro, maestroAvailability, type HostCannotRunMaestro } from "../_shared/owner-maestro-availability.js";
|
|
34
|
+
import { clearAskRequest, isAskMaestroKind, pendingAskRequest, type AskMaestroKind } from "../_shared/owner-maestro-tab.js";
|
|
34
35
|
import {
|
|
35
36
|
chatDecisions, chatMessages, decisionIdsOf, linkCardOf, replyText, sendVerdict,
|
|
36
37
|
type Decision, type LinkCard, type Verdict,
|
|
@@ -49,18 +50,15 @@ interface WixApi { call: (method: string, path: string, body?: unknown, headers?
|
|
|
49
50
|
interface Host { wixApi?: WixApi; input?: Record<string, unknown> }
|
|
50
51
|
const host = (): Host => (globalThis as { himalaya?: Host }).himalaya ?? {};
|
|
51
52
|
|
|
52
|
-
/** The business the owner is looking at
|
|
53
|
-
*
|
|
54
|
-
* session never does). It is only ever an address: Symphony honours it for the account's own
|
|
53
|
+
/** The business the owner is looking at (`currentBusinessId`: the one picked on Sites, else the
|
|
54
|
+
* one the host scoped). It is only ever an address: Symphony honours it for the account's own
|
|
55
55
|
* sites and nothing else. */
|
|
56
56
|
function activeSiteId(): string {
|
|
57
|
-
|
|
58
|
-
const scoped = typeof v === "string" ? v.trim() : "";
|
|
59
|
-
return scoped || readSelectedSite()?.id || "";
|
|
57
|
+
return currentBusinessId();
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
|
|
63
|
-
/** One transcript row: the owner's turn, Maestro's reply, the thinking line, or a card. The
|
|
61
|
+
/** One transcript row: the owner's turn, Maestro's reply, the thinking line, a note, or a card. The
|
|
64
62
|
* `*Hidden` flags pick which part of the one row template shows. */
|
|
65
63
|
export interface Bubble {
|
|
66
64
|
id: string;
|
|
@@ -68,6 +66,8 @@ export interface Bubble {
|
|
|
68
66
|
userHidden: string;
|
|
69
67
|
assistantHidden: string;
|
|
70
68
|
thinkingHidden: string;
|
|
69
|
+
/** A line about the chat itself, such as "Stopped". Not something Maestro said. */
|
|
70
|
+
noteHidden: string;
|
|
71
71
|
cardHidden: string;
|
|
72
72
|
cardTitle: string;
|
|
73
73
|
cardText: string;
|
|
@@ -85,12 +85,14 @@ export interface Bubble {
|
|
|
85
85
|
planVersion: string;
|
|
86
86
|
}
|
|
87
87
|
const NO_CARD = {
|
|
88
|
-
cardHidden: "true", cardTitle: "", cardText: "", cardStatus: "", primaryLabel: "", primaryHidden: "true",
|
|
88
|
+
noteHidden: "true", cardHidden: "true", cardTitle: "", cardText: "", cardStatus: "", primaryLabel: "", primaryHidden: "true",
|
|
89
89
|
secondaryLabel: "", secondaryHidden: "true", url: "", decisionId: "", verdictId: "", planVersion: "",
|
|
90
90
|
} as const;
|
|
91
91
|
const userBubble = (id: string, content: string): Bubble => ({ ...NO_CARD, id, content, userHidden: "false", assistantHidden: "true", thinkingHidden: "true" });
|
|
92
92
|
const assistantBubble = (id: string, content: string): Bubble => ({ ...NO_CARD, id, content, userHidden: "true", assistantHidden: "false", thinkingHidden: "true" });
|
|
93
|
-
|
|
93
|
+
/** The one line that says Maestro is working. It names the step Maestro is on once it reports one. */
|
|
94
|
+
const thinkingBubble = (step = ""): Bubble => ({ ...NO_CARD, id: THINKING_ID, content: step || copy.thinking(), userHidden: "true", assistantHidden: "true", thinkingHidden: "false" });
|
|
95
|
+
const noteBubble = (id: string, content: string): Bubble => ({ ...NO_CARD, id, content, userHidden: "true", assistantHidden: "true", thinkingHidden: "true", noteHidden: "false" });
|
|
94
96
|
const cardBubble = (id: string, card: Partial<Bubble>): Bubble =>
|
|
95
97
|
({ ...NO_CARD, id, content: "", userHidden: "true", assistantHidden: "true", thinkingHidden: "true", cardHidden: "false", ...card });
|
|
96
98
|
|
|
@@ -175,10 +177,12 @@ export interface MaestroState {
|
|
|
175
177
|
noInput: boolean;
|
|
176
178
|
busy: boolean;
|
|
177
179
|
idle: boolean;
|
|
178
|
-
/**
|
|
180
|
+
/** The step Maestro is on once its reply has started ("" collapses the line). Before that the
|
|
181
|
+
* thinking row says it, so the two never show together. */
|
|
179
182
|
statusText: string;
|
|
180
|
-
/** The item this chat was opened about
|
|
183
|
+
/** The item this chat was opened about, and whether that line shows. */
|
|
181
184
|
contextLabel: string;
|
|
185
|
+
contextHidden: string;
|
|
182
186
|
error: string;
|
|
183
187
|
/** Changes on every send: the host's transcript scroll follows the new turn. */
|
|
184
188
|
scrollSend: string;
|
|
@@ -206,7 +210,8 @@ export interface MaestroState {
|
|
|
206
210
|
|
|
207
211
|
const copy = {
|
|
208
212
|
greeting: () => copyParam("ownerMaestro.greeting", "Hi, I'm Maestro. Ask me to check on your business or to get something done."),
|
|
209
|
-
thinking: () => copyParam("ownerMaestro.
|
|
213
|
+
thinking: () => copyParam("ownerMaestro.working", "Working on it…"),
|
|
214
|
+
stopped: () => copyParam("ownerMaestro.stopped", "You stopped waiting for this reply. Maestro may still finish the work."),
|
|
210
215
|
failed: () => copyParam("ownerMaestro.failed", "Maestro couldn't answer. Try again in a moment."),
|
|
211
216
|
historyFailed: () => copyParam("ownerMaestro.historyFailed", "That conversation couldn't be opened. Try again in a moment."),
|
|
212
217
|
connectTitle: (name: string) => copyParam("ownerMaestro.connect.title", "Connect {name}").replace("{name}", name),
|
|
@@ -265,7 +270,31 @@ const copy = {
|
|
|
265
270
|
},
|
|
266
271
|
};
|
|
267
272
|
|
|
268
|
-
|
|
273
|
+
type AskKind = AskMaestroKind;
|
|
274
|
+
|
|
275
|
+
/** The prompt cards of an empty chat: about the business, or about the item the chat was opened on. */
|
|
276
|
+
function prompts(kind: AskKind | "" = ""): Prompt[] {
|
|
277
|
+
if (kind === "order") {
|
|
278
|
+
return [
|
|
279
|
+
{ id: "p1", title: copyParam("ownerMaestro.order.p1.title", "Summarize this order"), text: copyParam("ownerMaestro.order.p1.text", "Summarize this order for me.") },
|
|
280
|
+
{ id: "p2", title: copyParam("ownerMaestro.order.p2.title", "What does it still need?"), text: copyParam("ownerMaestro.order.p2.text", "What does this order still need from me?") },
|
|
281
|
+
{ id: "p3", title: copyParam("ownerMaestro.order.p3.title", "Draft a message to the customer"), text: copyParam("ownerMaestro.order.p3.text", "Draft a message to this order's customer and show it to me before sending.") },
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
if (kind === "booking") {
|
|
285
|
+
return [
|
|
286
|
+
{ id: "p1", title: copyParam("ownerMaestro.booking.p1.title", "Summarize this booking"), text: copyParam("ownerMaestro.booking.p1.text", "Summarize this booking for me.") },
|
|
287
|
+
{ id: "p2", title: copyParam("ownerMaestro.booking.p2.title", "What does it still need?"), text: copyParam("ownerMaestro.booking.p2.text", "What does this booking still need from me?") },
|
|
288
|
+
{ id: "p3", title: copyParam("ownerMaestro.booking.p3.title", "Draft a reminder"), text: copyParam("ownerMaestro.booking.p3.text", "Draft a reminder for this booking's customer and show it to me before sending.") },
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
if (kind === "contact") {
|
|
292
|
+
return [
|
|
293
|
+
{ id: "p1", title: copyParam("ownerMaestro.contact.p1.title", "Summarize this contact"), text: copyParam("ownerMaestro.contact.p1.text", "Summarize what you know about this contact.") },
|
|
294
|
+
{ id: "p2", title: copyParam("ownerMaestro.contact.p2.title", "What have they bought or booked?"), text: copyParam("ownerMaestro.contact.p2.text", "What has this contact bought or booked with my business?") },
|
|
295
|
+
{ id: "p3", title: copyParam("ownerMaestro.contact.p3.title", "Draft a message to them"), text: copyParam("ownerMaestro.contact.p3.text", "Draft a message to this contact and show it to me before sending.") },
|
|
296
|
+
];
|
|
297
|
+
}
|
|
269
298
|
return [
|
|
270
299
|
{ 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.") },
|
|
271
300
|
{ id: "p2", title: copyParam("ownerMaestro.p2.title", "What needs me today?"), text: copyParam("ownerMaestro.p2.text", "What needs my attention today?") },
|
|
@@ -277,7 +306,7 @@ const initial: MaestroState = {
|
|
|
277
306
|
phase: "checking", checkingHidden: "false", chatHidden: "true", unavailableHidden: "true",
|
|
278
307
|
unavailableTitle: "", unavailableText: "",
|
|
279
308
|
messages: [], emptyHidden: "false", prompts: [], quickReplies: [], quickRepliesHidden: "true",
|
|
280
|
-
input: "", hasInput: false, noInput: true, busy: false, idle: true, statusText: "", contextLabel: "", error: "", scrollSend: "", scrollAnchor: "", ok: false,
|
|
309
|
+
input: "", hasInput: false, noInput: true, busy: false, idle: true, statusText: "", contextLabel: "", contextHidden: "true", error: "", scrollSend: "", scrollAnchor: "", ok: false,
|
|
281
310
|
_site: "", _account: "", _convId: "", _role: "", _openId: "", _openRaw: "", _turn: 0, _context: "", _decisionIds: [], _resumedId: "", _askKey: "",
|
|
282
311
|
};
|
|
283
312
|
|
|
@@ -286,18 +315,55 @@ const inputString = (key: string): string => {
|
|
|
286
315
|
return typeof v === "string" ? v.trim() : "";
|
|
287
316
|
};
|
|
288
317
|
|
|
318
|
+
/** The kind of item an ask key names ("" for none): the key starts with it. */
|
|
319
|
+
const askKindOf = (key: string): AskKind | "" => {
|
|
320
|
+
const kind = key.split(":")[0];
|
|
321
|
+
return isAskMaestroKind(kind) ? kind : "";
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
interface Ask { key: string; kind: AskKind; id: string; subject: string }
|
|
325
|
+
|
|
289
326
|
/** The item a detail screen opened this chat about. Only an order, a booking or a contact, and
|
|
290
|
-
* only with an id: the id is what Maestro looks the item up by.
|
|
291
|
-
|
|
327
|
+
* only with an id: the id is what Maestro looks the item up by. It arrives in the screen's own
|
|
328
|
+
* params (a pushed Maestro screen), or as a request the detail screen left before it switched
|
|
329
|
+
* to the Maestro tab; each request has its own stamp, so asking again about the same item is a
|
|
330
|
+
* new ask. */
|
|
331
|
+
function askedAbout(): Ask | null {
|
|
292
332
|
const kind = inputString("kind");
|
|
293
333
|
const id = inputString("id");
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
334
|
+
if (id && isAskMaestroKind(kind)) {
|
|
335
|
+
return { key: `${kind}:${id}`, kind, id, subject: inputString("subject").slice(0, 80) };
|
|
336
|
+
}
|
|
337
|
+
const request = pendingAskRequest(Date.now(), activeSiteId());
|
|
338
|
+
return request ? { key: `${request.kind}:${request.id}#${request.n}`, kind: request.kind, id: request.id, subject: request.subject.slice(0, 80) } : null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Drop the request a chat was opened from, by the stamp its key carries (`kind:id#stamp`). A
|
|
342
|
+
* chat opened from screen params has no stamp and left no request. */
|
|
343
|
+
function dropAskRequest(askKey: string): void {
|
|
344
|
+
const stamp = Number(askKey.split("#")[1]);
|
|
345
|
+
if (askKey.includes("#") && Number.isFinite(stamp)) clearAskRequest(stamp);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const askLabel = (ask: Ask, subject: string): string => copy.about(ask.kind, subject);
|
|
349
|
+
const askContext = (ask: Ask, subject: string): string =>
|
|
350
|
+
`The owner opened this chat from the Owner app's ${ask.kind} screen. It is about the ${ask.kind} with id ${ask.id}${subject ? ` ("${subject}")` : ""}. Unless they say otherwise, their questions are about that ${ask.kind}.`;
|
|
351
|
+
|
|
352
|
+
/** A contact's name, for a chat opened about one. A detail screen never passes it: on the web
|
|
353
|
+
* host a screen's params are part of the address. Read here instead, from the business on
|
|
354
|
+
* screen. `read: false` when it could not be read: the chat then names the contact by what it
|
|
355
|
+
* is, and Maestro is given its id only. */
|
|
356
|
+
async function contactName(api: WixApi, id: string, site: string): Promise<{ read: boolean; name: string }> {
|
|
357
|
+
let res: { contact?: { info?: { name?: { first?: string; last?: string } }; primaryInfo?: { email?: string } } } | null;
|
|
358
|
+
try {
|
|
359
|
+
// The business is named: this tab's own connection may still be on another one.
|
|
360
|
+
res = (await api.call("GET", `https://www.wixapis.com/contacts/v4/contacts/${encodeURIComponent(id)}`, undefined, site ? { "wix-site-id": site } : undefined)) as typeof res;
|
|
361
|
+
} catch {
|
|
362
|
+
return { read: false, name: "" };
|
|
363
|
+
}
|
|
364
|
+
const name = res?.contact?.info?.name;
|
|
365
|
+
const full = [name?.first, name?.last].filter((part): part is string => typeof part === "string" && !!part.trim()).map((part) => part.trim()).join(" ");
|
|
366
|
+
return { read: true, name: (full || res?.contact?.primaryInfo?.email || "").slice(0, 80) };
|
|
301
367
|
}
|
|
302
368
|
|
|
303
369
|
// What the owner left with New chat. A screen pushed from history or from an item keeps its
|
|
@@ -382,9 +448,9 @@ let draft = "";
|
|
|
382
448
|
let chatSeq = 0;
|
|
383
449
|
|
|
384
450
|
const freshChat = (s: MaestroState, input = ""): MaestroState => ({
|
|
385
|
-
...s, messages: [], emptyHidden: "false", quickReplies: [], quickRepliesHidden: "true",
|
|
451
|
+
...s, messages: [], emptyHidden: "false", prompts: prompts(), quickReplies: [], quickRepliesHidden: "true",
|
|
386
452
|
input, hasInput: input.trim().length > 0, noInput: input.trim().length === 0,
|
|
387
|
-
busy: false, idle: true, statusText: "", contextLabel: "", error: "", scrollSend: "", scrollAnchor: "",
|
|
453
|
+
busy: false, idle: true, statusText: "", contextLabel: "", contextHidden: "true", error: "", scrollSend: "", scrollAnchor: "",
|
|
388
454
|
_convId: "", _role: "", _openId: "", _openRaw: "", _context: "", _decisionIds: [], _resumedId: "", _askKey: "",
|
|
389
455
|
});
|
|
390
456
|
|
|
@@ -409,13 +475,15 @@ async function send(s: MaestroState, raw: string, choice?: { askId: string; opti
|
|
|
409
475
|
if (!convId) return { ...s, ...typed, error: copy.failed() };
|
|
410
476
|
}
|
|
411
477
|
const typedMeanwhile = draftSeq !== draftAtSend;
|
|
478
|
+
// The chat a detail screen asked for is in use: the request has done its work.
|
|
479
|
+
dropAskRequest(s._askKey);
|
|
412
480
|
const turn = s._turn + 1;
|
|
413
481
|
const next: MaestroState = {
|
|
414
482
|
...s, _convId: convId, _turn: turn, _role: "", _openId: "", _openRaw: "", _decisionIds: [],
|
|
415
483
|
messages: [...settled(s.messages), userBubble(`u${turn}`, text), thinkingBubble()],
|
|
416
484
|
emptyHidden: "true", quickReplies: [], quickRepliesHidden: "true",
|
|
417
485
|
input: "", hasInput: false, noInput: true, busy: true, idle: false,
|
|
418
|
-
statusText:
|
|
486
|
+
statusText: "", error: "", scrollSend: `turn-${turn}`, scrollAnchor: `${SCREEN}.message_u${turn}`, ok: false,
|
|
419
487
|
};
|
|
420
488
|
const kept: MaestroState = typedMeanwhile
|
|
421
489
|
? { ...next, input: draft, hasInput: draft.trim().length > 0, noInput: draft.trim().length === 0 }
|
|
@@ -460,6 +528,14 @@ async function endTurn(s: MaestroState, error = ""): Promise<MaestroState> {
|
|
|
460
528
|
return { ...next, messages: withCards(next.messages, cards) };
|
|
461
529
|
}
|
|
462
530
|
|
|
531
|
+
/** The step Maestro reports it is on. While the thinking row shows, the row says it; once the
|
|
532
|
+
* reply has started there is no such row, and the status line under the transcript says it. */
|
|
533
|
+
function withStep(s: MaestroState, line: string): MaestroState {
|
|
534
|
+
if (!line) return s;
|
|
535
|
+
if (!s.messages.some((b) => b.id === THINKING_ID)) return { ...s, statusText: line };
|
|
536
|
+
return { ...s, statusText: "", messages: s.messages.map((b) => (b.id === THINKING_ID ? thinkingBubble(line) : b)) };
|
|
537
|
+
}
|
|
538
|
+
|
|
463
539
|
/** The cards one event names: a link is drawn at once, a decision is noted for the turn's end. */
|
|
464
540
|
function withEventCards(s: MaestroState, data: Record<string, unknown>): MaestroState {
|
|
465
541
|
const link = linkCardOf(data);
|
|
@@ -483,7 +559,11 @@ async function resume(api: WixApi, s: MaestroState, conversationId: string): Pro
|
|
|
483
559
|
for (const id of m.decisionIds) if (!decisionIds.includes(id)) decisionIds.push(id);
|
|
484
560
|
}
|
|
485
561
|
messages = withCards(messages, await decisionCards(api, conversationId, decisionIds));
|
|
486
|
-
|
|
562
|
+
// A past chat opens on its latest message: a new token with no row to pin follows the end.
|
|
563
|
+
return {
|
|
564
|
+
...freshChat(s), _convId: conversationId, messages, emptyHidden: messages.length ? "true" : "false",
|
|
565
|
+
scrollSend: messages.length ? `open-${conversationId}-${messages.length}` : "", scrollAnchor: "",
|
|
566
|
+
};
|
|
487
567
|
}
|
|
488
568
|
|
|
489
569
|
/** Answer a decision card. Refused while a turn streams: the card's result is built from the
|
|
@@ -565,7 +645,7 @@ const svc = defineService<MaestroState, {
|
|
|
565
645
|
// A chat saved by a build without cards has rows with no card fields, and a missing
|
|
566
646
|
// "hidden" reads as shown: each row is completed so no empty card is drawn.
|
|
567
647
|
const rows = (s.busy ? s.messages : settled(s.messages)).map((b) => ({ ...NO_CARD, ...b }));
|
|
568
|
-
ready = { ...s, prompts: prompts(), messages: rows };
|
|
648
|
+
ready = { ...s, prompts: prompts(askKindOf(s._askKey)), messages: rows, contextHidden: s.contextLabel ? "false" : "true" };
|
|
569
649
|
} else {
|
|
570
650
|
// The host could not say. A chat already open is kept (above); a new one is not opened.
|
|
571
651
|
if (reads === "unknown") return unavailable(fresh, "unreachable");
|
|
@@ -602,7 +682,20 @@ const svc = defineService<MaestroState, {
|
|
|
602
682
|
}
|
|
603
683
|
const ask = past ? null : askedAbout();
|
|
604
684
|
if (ask && ask.key !== leftAsk && ask.key !== ready._askKey) {
|
|
605
|
-
|
|
685
|
+
let subject = ask.subject;
|
|
686
|
+
if (!subject && ask.kind === "contact" && api) {
|
|
687
|
+
const chatAtStart = chatSeq;
|
|
688
|
+
const draftAtStart = draftSeq;
|
|
689
|
+
// As for a past chat: no send starts while the name is read, since this result would overwrite it.
|
|
690
|
+
reading += 1;
|
|
691
|
+
try { subject = (await contactName(api, ask.id, site)).name; } finally { reading -= 1; }
|
|
692
|
+
if (chatSeq !== chatAtStart) return freshChat(ready, draft);
|
|
693
|
+
ready = withDraftSince(ready, draftAtStart);
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
...freshChat(ready, ready.input), prompts: prompts(ask.kind),
|
|
697
|
+
contextLabel: askLabel(ask, subject), contextHidden: "false", _context: askContext(ask, subject), _askKey: ask.key,
|
|
698
|
+
};
|
|
606
699
|
}
|
|
607
700
|
return ready;
|
|
608
701
|
},
|
|
@@ -627,7 +720,11 @@ const svc = defineService<MaestroState, {
|
|
|
627
720
|
},
|
|
628
721
|
// Local only, as in the Symphony iOS app: the turn keeps running on the server, and what it
|
|
629
722
|
// still streams is dropped because nothing is in flight here any more.
|
|
630
|
-
|
|
723
|
+
// The transcript says so, since nothing else would: without the note a stopped turn looks
|
|
724
|
+
// like a message Maestro ignored.
|
|
725
|
+
stop: async (s) => (s.busy
|
|
726
|
+
? endTurn({ ...s, messages: [...settled(s.messages), noteBubble(`stopped_${s._turn}`, copy.stopped())] })
|
|
727
|
+
: s),
|
|
631
728
|
newChat: async (s) => {
|
|
632
729
|
if (s.phase !== "ready") return s;
|
|
633
730
|
chatSeq += 1;
|
|
@@ -635,6 +732,8 @@ const svc = defineService<MaestroState, {
|
|
|
635
732
|
draft = "";
|
|
636
733
|
leftPastChat = s._resumedId || leftPastChat;
|
|
637
734
|
leftAsk = s._askKey || leftAsk;
|
|
735
|
+
// The chat a detail screen asked for was left: a worker started later must not reopen it.
|
|
736
|
+
dropAskRequest(s._askKey);
|
|
638
737
|
return freshChat(s);
|
|
639
738
|
},
|
|
640
739
|
// A card's one or two buttons. What they do depends on the card.
|
|
@@ -656,10 +755,7 @@ const svc = defineService<MaestroState, {
|
|
|
656
755
|
if (ev?.type === "metadata") {
|
|
657
756
|
return typeof data.conversationId === "string" && data.conversationId ? { ...s, _convId: data.conversationId } : s;
|
|
658
757
|
}
|
|
659
|
-
if (ev?.type === "thinking")
|
|
660
|
-
const line = (data.text ?? "").trim().split("\n").pop() ?? "";
|
|
661
|
-
return line ? { ...s, statusText: line } : s;
|
|
662
|
-
}
|
|
758
|
+
if (ev?.type === "thinking") return withStep(s, (data.text ?? "").trim().split("\n").pop() ?? "");
|
|
663
759
|
if (ev?.type === "messageStart") {
|
|
664
760
|
return { ...s, _role: typeof data.role === "string" ? data.role : "", _openId: "" };
|
|
665
761
|
}
|
|
@@ -667,10 +763,7 @@ const svc = defineService<MaestroState, {
|
|
|
667
763
|
const delta = typeof data.deltaText === "string" ? data.deltaText : "";
|
|
668
764
|
if (!delta) return s;
|
|
669
765
|
// Only the reply itself becomes a bubble; a step or a thought is the status line.
|
|
670
|
-
if (s._role && s._role !== "ASSISTANT")
|
|
671
|
-
const line = delta.trim().split("\n").pop() ?? "";
|
|
672
|
-
return line ? { ...s, statusText: line } : s;
|
|
673
|
-
}
|
|
766
|
+
if (s._role && s._role !== "ASSISTANT") return withStep(s, delta.trim().split("\n").pop() ?? "");
|
|
674
767
|
const messages = settled(s.messages);
|
|
675
768
|
const open = messages.findIndex((b) => b.id === s._openId);
|
|
676
769
|
if (open >= 0) {
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
// messages itself. Nothing is cached here: storage is shared by everyone who signs in on the
|
|
6
6
|
// device, and a business id is not an account.
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { formatClock, formatMonthDayTime } from "../_shared/engine-intl.js";
|
|
9
9
|
import { defineService } from "@himalaya/state";
|
|
10
10
|
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
11
|
-
import {
|
|
11
|
+
import { currentBusinessId } from "../_shared/owner-selected-site.js";
|
|
12
12
|
import { symphonyAccount, type MaestroWixApi } from "../_shared/owner-maestro-availability.js";
|
|
13
13
|
import { pastChats, type PastChat } from "../_shared/owner-maestro-chat.js";
|
|
14
14
|
|
|
@@ -17,9 +17,7 @@ const host = (): Host => (globalThis as { himalaya?: Host }).himalaya ?? {};
|
|
|
17
17
|
|
|
18
18
|
/** The same business the Maestro screen talks about. */
|
|
19
19
|
function activeSiteId(): string {
|
|
20
|
-
|
|
21
|
-
const scoped = typeof v === "string" ? v.trim() : "";
|
|
22
|
-
return scoped || readSelectedSite()?.id || "";
|
|
20
|
+
return currentBusinessId();
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
/** `stamp` marks the list a row was shown in, so opening the same chat from a later list is a new request. */
|
|
@@ -53,10 +51,14 @@ function bucketOf(updated: string, now: number): string {
|
|
|
53
51
|
return copyParam("ownerMaestroHistory.older", "Older");
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
/** When a chat was last active: the time for one from today, whose rows would otherwise all
|
|
55
|
+
* read the same date; the date and the time for an older one. */
|
|
56
|
+
function whenLabel(updated: string, now: number): string {
|
|
57
57
|
const at = Date.parse(updated);
|
|
58
58
|
if (Number.isNaN(at)) return "";
|
|
59
|
-
|
|
59
|
+
const midnight = new Date(now);
|
|
60
|
+
midnight.setHours(0, 0, 0, 0);
|
|
61
|
+
return at >= midnight.getTime() ? formatClock(new Date(at)) : formatMonthDayTime(new Date(at));
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/** Rows in the order given, with the bucket named on the first row of each bucket only. */
|
|
@@ -66,7 +68,7 @@ function rowsOf(chats: PastChat[], now: number): HistoryRow[] {
|
|
|
66
68
|
const bucket = bucketOf(c.updated, now);
|
|
67
69
|
const section = bucket === last ? "" : bucket;
|
|
68
70
|
last = bucket;
|
|
69
|
-
return { id: c.id, title: c.title || copyParam("ownerMaestroHistory.untitled", "Untitled conversation"), subtitle:
|
|
71
|
+
return { id: c.id, title: c.title || copyParam("ownerMaestroHistory.untitled", "Untitled conversation"), subtitle: whenLabel(c.updated, now), section, stamp: String(now) };
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
74
|
|