@modelnex/sdk 0.5.43 → 0.5.44
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/index.js +97 -24
- package/dist/index.mjs +97 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2041,7 +2041,18 @@ var import_zod2 = require("zod");
|
|
|
2041
2041
|
|
|
2042
2042
|
// src/utils/screenshot.ts
|
|
2043
2043
|
var import_html2canvas = __toESM(require("html2canvas"));
|
|
2044
|
-
|
|
2044
|
+
var SCREENSHOT_SCALE_BY_RESOLUTION = {
|
|
2045
|
+
low: 0.75,
|
|
2046
|
+
medium: 1.25,
|
|
2047
|
+
high: 2
|
|
2048
|
+
};
|
|
2049
|
+
function normalizeScreenshotResolution(resolution) {
|
|
2050
|
+
return resolution === "low" || resolution === "high" || resolution === "medium" ? resolution : "medium";
|
|
2051
|
+
}
|
|
2052
|
+
function resolveScreenshotScale(resolution) {
|
|
2053
|
+
return SCREENSHOT_SCALE_BY_RESOLUTION[normalizeScreenshotResolution(resolution)];
|
|
2054
|
+
}
|
|
2055
|
+
async function captureScreenshot(selector, resolution) {
|
|
2045
2056
|
const target = selector ? document.querySelector(selector) : document.documentElement;
|
|
2046
2057
|
if (!target || !(target instanceof HTMLElement)) {
|
|
2047
2058
|
throw new Error(`Screenshot target not found: ${selector ?? "document"}`);
|
|
@@ -2049,7 +2060,7 @@ async function captureScreenshot(selector) {
|
|
|
2049
2060
|
const canvas = await (0, import_html2canvas.default)(target, {
|
|
2050
2061
|
useCORS: true,
|
|
2051
2062
|
allowTaint: true,
|
|
2052
|
-
scale:
|
|
2063
|
+
scale: resolveScreenshotScale(resolution),
|
|
2053
2064
|
width: window.innerWidth,
|
|
2054
2065
|
height: window.innerHeight,
|
|
2055
2066
|
x: window.scrollX,
|
|
@@ -2512,14 +2523,15 @@ async function resolveWorkflowFromInput(getters, params) {
|
|
|
2512
2523
|
return { workflow: ranked[0].workflow };
|
|
2513
2524
|
}
|
|
2514
2525
|
var screenshotSchema = import_zod2.z.object({
|
|
2515
|
-
selector: import_zod2.z.string().optional().describe("Optional CSS selector to capture a specific element. Omit to capture the full viewport.")
|
|
2526
|
+
selector: import_zod2.z.string().optional().describe("Optional CSS selector to capture a specific element. Omit to capture the full viewport."),
|
|
2527
|
+
resolution: import_zod2.z.enum(["low", "medium", "high"]).optional().describe("Optional screenshot resolution. Use low for smaller/faster captures, medium for the default balance, or high for extra detail.")
|
|
2516
2528
|
});
|
|
2517
2529
|
var BUILTIN_SCREENSHOT_ACTION = {
|
|
2518
2530
|
id: "take_screenshot",
|
|
2519
2531
|
description: "Take a screenshot of the current page (or a specific element via CSS selector). Returns a base64 PNG image. Use when you need to see the current UI state, verify a visual change, or when the user asks you to look at the screen.",
|
|
2520
2532
|
schema: screenshotSchema,
|
|
2521
2533
|
execute: async (params) => {
|
|
2522
|
-
return await captureScreenshot(params.selector);
|
|
2534
|
+
return await captureScreenshot(params.selector, params.resolution);
|
|
2523
2535
|
}
|
|
2524
2536
|
};
|
|
2525
2537
|
var clickElementSchema = import_zod2.z.object({
|
|
@@ -3529,6 +3541,54 @@ function compactTourForTransport(tour) {
|
|
|
3529
3541
|
};
|
|
3530
3542
|
}
|
|
3531
3543
|
|
|
3544
|
+
// src/utils/tourSessionPersistence.ts
|
|
3545
|
+
var ACTIVE_TOUR_SESSION_STORAGE_KEY = "modelnex-active-tour-session";
|
|
3546
|
+
var ACTIVE_TOUR_SESSION_VERSION = 1;
|
|
3547
|
+
var ACTIVE_TOUR_SESSION_MAX_AGE_MS = 10 * 60 * 1e3;
|
|
3548
|
+
function canUseSessionStorage2() {
|
|
3549
|
+
return typeof window !== "undefined" && typeof window.sessionStorage !== "undefined";
|
|
3550
|
+
}
|
|
3551
|
+
function persistActiveTourSession(runId) {
|
|
3552
|
+
if (!canUseSessionStorage2() || !Number.isFinite(runId)) return;
|
|
3553
|
+
const session = {
|
|
3554
|
+
version: ACTIVE_TOUR_SESSION_VERSION,
|
|
3555
|
+
runId,
|
|
3556
|
+
savedAt: Date.now()
|
|
3557
|
+
};
|
|
3558
|
+
try {
|
|
3559
|
+
window.sessionStorage.setItem(ACTIVE_TOUR_SESSION_STORAGE_KEY, JSON.stringify(session));
|
|
3560
|
+
} catch {
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
function clearPersistedActiveTourSession() {
|
|
3564
|
+
if (!canUseSessionStorage2()) return;
|
|
3565
|
+
try {
|
|
3566
|
+
window.sessionStorage.removeItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
|
|
3567
|
+
} catch {
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
function readPersistedActiveTourSession() {
|
|
3571
|
+
if (!canUseSessionStorage2()) return null;
|
|
3572
|
+
try {
|
|
3573
|
+
const raw = window.sessionStorage.getItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
|
|
3574
|
+
if (!raw) return null;
|
|
3575
|
+
const parsed = JSON.parse(raw);
|
|
3576
|
+
const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
|
|
3577
|
+
if (!isValid) {
|
|
3578
|
+
clearPersistedActiveTourSession();
|
|
3579
|
+
return null;
|
|
3580
|
+
}
|
|
3581
|
+
if (Date.now() - parsed.savedAt > ACTIVE_TOUR_SESSION_MAX_AGE_MS) {
|
|
3582
|
+
clearPersistedActiveTourSession();
|
|
3583
|
+
return null;
|
|
3584
|
+
}
|
|
3585
|
+
return parsed;
|
|
3586
|
+
} catch {
|
|
3587
|
+
clearPersistedActiveTourSession();
|
|
3588
|
+
return null;
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3532
3592
|
// src/hooks/useTourPlayback.ts
|
|
3533
3593
|
init_editable_controls();
|
|
3534
3594
|
|
|
@@ -4143,7 +4203,8 @@ function useTourPlayback({
|
|
|
4143
4203
|
const pendingTourRef = (0, import_react12.useRef)(null);
|
|
4144
4204
|
const pendingTourOptionsRef = (0, import_react12.useRef)(null);
|
|
4145
4205
|
const showCaptionsRef = (0, import_react12.useRef)(showCaptions);
|
|
4146
|
-
const
|
|
4206
|
+
const initialPersistedTourSessionRef = (0, import_react12.useRef)(readPersistedActiveTourSession());
|
|
4207
|
+
const runIdRef = (0, import_react12.useRef)(initialPersistedTourSessionRef.current?.runId ?? null);
|
|
4147
4208
|
const turnIdRef = (0, import_react12.useRef)(null);
|
|
4148
4209
|
const startRequestedRef = (0, import_react12.useRef)(false);
|
|
4149
4210
|
const playbackOwnerIdRef = (0, import_react12.useRef)(`playback-owner-${Math.random().toString(36).slice(2, 10)}`);
|
|
@@ -4171,6 +4232,19 @@ function useTourPlayback({
|
|
|
4171
4232
|
releaseTourPlaybackOwnership(claimedKey, playbackOwnerIdRef.current);
|
|
4172
4233
|
claimedPlaybackOwnerKeyRef.current = null;
|
|
4173
4234
|
}, []);
|
|
4235
|
+
const emitTourInit = (0, import_react12.useCallback)((socket, currentWebsiteId, profile) => {
|
|
4236
|
+
if (!currentWebsiteId || !profile?.type) return;
|
|
4237
|
+
const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
|
|
4238
|
+
const payload = {
|
|
4239
|
+
websiteId: currentWebsiteId,
|
|
4240
|
+
userId: profile.userId,
|
|
4241
|
+
userType: profile.type
|
|
4242
|
+
};
|
|
4243
|
+
if (typeof persistedRunId === "number") {
|
|
4244
|
+
payload.resumeRunId = persistedRunId;
|
|
4245
|
+
}
|
|
4246
|
+
emitSocketEvent(socket, "tour:init", payload);
|
|
4247
|
+
}, []);
|
|
4174
4248
|
(0, import_react12.useEffect)(() => {
|
|
4175
4249
|
if (disabled) return;
|
|
4176
4250
|
if (typeof window === "undefined") return;
|
|
@@ -4182,9 +4256,7 @@ function useTourPlayback({
|
|
|
4182
4256
|
}, { devMode: devModeRef.current });
|
|
4183
4257
|
const profile = userProfileRef.current;
|
|
4184
4258
|
const currentWebsiteId = websiteIdRef.current;
|
|
4185
|
-
|
|
4186
|
-
emitSocketEvent(socket, "tour:init", { websiteId: currentWebsiteId, userId: profile.userId, userType: profile.type });
|
|
4187
|
-
}
|
|
4259
|
+
emitTourInit(socket, currentWebsiteId, profile);
|
|
4188
4260
|
};
|
|
4189
4261
|
const handleServerState = (payload) => {
|
|
4190
4262
|
if (typeof payload?.runId === "number") {
|
|
@@ -4193,6 +4265,11 @@ function useTourPlayback({
|
|
|
4193
4265
|
if (typeof payload?.turnId === "string" || payload?.turnId === null) {
|
|
4194
4266
|
turnIdRef.current = payload.turnId ?? null;
|
|
4195
4267
|
}
|
|
4268
|
+
if (payload?.isActive && typeof payload?.runId === "number") {
|
|
4269
|
+
persistActiveTourSession(payload.runId);
|
|
4270
|
+
} else if (payload?.isActive === false) {
|
|
4271
|
+
clearPersistedActiveTourSession();
|
|
4272
|
+
}
|
|
4196
4273
|
setServerState(payload);
|
|
4197
4274
|
};
|
|
4198
4275
|
const handleCommandCancel = (payload) => {
|
|
@@ -4456,19 +4533,9 @@ function useTourPlayback({
|
|
|
4456
4533
|
return { result: value };
|
|
4457
4534
|
}
|
|
4458
4535
|
if (action.type === "take_screenshot") {
|
|
4459
|
-
const
|
|
4460
|
-
const
|
|
4461
|
-
|
|
4462
|
-
useCORS: true,
|
|
4463
|
-
allowTaint: true,
|
|
4464
|
-
scale: Math.min(window.devicePixelRatio, 2),
|
|
4465
|
-
width: window.innerWidth,
|
|
4466
|
-
height: window.innerHeight,
|
|
4467
|
-
x: window.scrollX,
|
|
4468
|
-
y: window.scrollY,
|
|
4469
|
-
logging: false
|
|
4470
|
-
});
|
|
4471
|
-
return { result: canvas.toDataURL("image/png") };
|
|
4536
|
+
const selector = typeof action.params?.selector === "string" ? action.params.selector : void 0;
|
|
4537
|
+
const resolution = typeof action.params?.resolution === "string" ? action.params.resolution : void 0;
|
|
4538
|
+
return { result: await captureScreenshot(selector, resolution) };
|
|
4472
4539
|
}
|
|
4473
4540
|
if (action.type === "navigate_to_url") {
|
|
4474
4541
|
const nextUrl = typeof action.params?.url === "string" ? action.params.url : "";
|
|
@@ -4760,6 +4827,9 @@ function useTourPlayback({
|
|
|
4760
4827
|
const handleTourStart = async (tourData) => {
|
|
4761
4828
|
if (isActiveRef.current) return;
|
|
4762
4829
|
runIdRef.current = typeof tourData.runId === "number" ? tourData.runId : runIdRef.current;
|
|
4830
|
+
if (typeof runIdRef.current === "number") {
|
|
4831
|
+
persistActiveTourSession(runIdRef.current);
|
|
4832
|
+
}
|
|
4763
4833
|
const tour = tourData.tourContext ?? tourRef.current;
|
|
4764
4834
|
const expType = experienceTypeRef.current;
|
|
4765
4835
|
if (tour?.type && tour.type !== expType) {
|
|
@@ -4835,6 +4905,7 @@ function useTourPlayback({
|
|
|
4835
4905
|
}
|
|
4836
4906
|
};
|
|
4837
4907
|
const handleTourEndEvent = () => {
|
|
4908
|
+
clearPersistedActiveTourSession();
|
|
4838
4909
|
setServerState((prev) => prev ? { ...prev, isActive: false, phase: "completed" } : prev);
|
|
4839
4910
|
handleTourEnd();
|
|
4840
4911
|
};
|
|
@@ -4884,17 +4955,17 @@ function useTourPlayback({
|
|
|
4884
4955
|
releasePlaybackOwnership();
|
|
4885
4956
|
tourSocketPool.release(serverUrl, toClose);
|
|
4886
4957
|
};
|
|
4887
|
-
}, [serverUrl, disabled, releasePlaybackOwnership]);
|
|
4958
|
+
}, [serverUrl, disabled, emitTourInit, releasePlaybackOwnership]);
|
|
4888
4959
|
(0, import_react12.useEffect)(() => {
|
|
4889
4960
|
if (disabled) return;
|
|
4890
4961
|
const s = socketRef.current;
|
|
4891
4962
|
const profile = userProfile;
|
|
4892
4963
|
if (!websiteId || !profile?.type) return;
|
|
4893
4964
|
const timer = setTimeout(() => {
|
|
4894
|
-
|
|
4965
|
+
emitTourInit(s, websiteId, profile);
|
|
4895
4966
|
}, 150);
|
|
4896
4967
|
return () => clearTimeout(timer);
|
|
4897
|
-
}, [disabled, websiteId, userProfile?.userId, userProfile?.type]);
|
|
4968
|
+
}, [disabled, emitTourInit, websiteId, userProfile?.userId, userProfile?.type]);
|
|
4898
4969
|
(0, import_react12.useEffect)(() => {
|
|
4899
4970
|
if (!showCaptions || !isReviewMode) {
|
|
4900
4971
|
removeCaption();
|
|
@@ -5013,6 +5084,7 @@ function useTourPlayback({
|
|
|
5013
5084
|
tourRef.current = null;
|
|
5014
5085
|
setPlaybackState("idle");
|
|
5015
5086
|
setServerState(null);
|
|
5087
|
+
clearPersistedActiveTourSession();
|
|
5016
5088
|
runIdRef.current = null;
|
|
5017
5089
|
turnIdRef.current = null;
|
|
5018
5090
|
setPreviewRunId(null);
|
|
@@ -5042,6 +5114,7 @@ function useTourPlayback({
|
|
|
5042
5114
|
tourRef.current = null;
|
|
5043
5115
|
setPlaybackState("idle");
|
|
5044
5116
|
setServerState(null);
|
|
5117
|
+
clearPersistedActiveTourSession();
|
|
5045
5118
|
runIdRef.current = null;
|
|
5046
5119
|
turnIdRef.current = null;
|
|
5047
5120
|
setPreviewRunId(null);
|
package/dist/index.mjs
CHANGED
|
@@ -1667,7 +1667,18 @@ import { z as z2 } from "zod";
|
|
|
1667
1667
|
|
|
1668
1668
|
// src/utils/screenshot.ts
|
|
1669
1669
|
import html2canvas from "html2canvas";
|
|
1670
|
-
|
|
1670
|
+
var SCREENSHOT_SCALE_BY_RESOLUTION = {
|
|
1671
|
+
low: 0.75,
|
|
1672
|
+
medium: 1.25,
|
|
1673
|
+
high: 2
|
|
1674
|
+
};
|
|
1675
|
+
function normalizeScreenshotResolution(resolution) {
|
|
1676
|
+
return resolution === "low" || resolution === "high" || resolution === "medium" ? resolution : "medium";
|
|
1677
|
+
}
|
|
1678
|
+
function resolveScreenshotScale(resolution) {
|
|
1679
|
+
return SCREENSHOT_SCALE_BY_RESOLUTION[normalizeScreenshotResolution(resolution)];
|
|
1680
|
+
}
|
|
1681
|
+
async function captureScreenshot(selector, resolution) {
|
|
1671
1682
|
const target = selector ? document.querySelector(selector) : document.documentElement;
|
|
1672
1683
|
if (!target || !(target instanceof HTMLElement)) {
|
|
1673
1684
|
throw new Error(`Screenshot target not found: ${selector ?? "document"}`);
|
|
@@ -1675,7 +1686,7 @@ async function captureScreenshot(selector) {
|
|
|
1675
1686
|
const canvas = await html2canvas(target, {
|
|
1676
1687
|
useCORS: true,
|
|
1677
1688
|
allowTaint: true,
|
|
1678
|
-
scale:
|
|
1689
|
+
scale: resolveScreenshotScale(resolution),
|
|
1679
1690
|
width: window.innerWidth,
|
|
1680
1691
|
height: window.innerHeight,
|
|
1681
1692
|
x: window.scrollX,
|
|
@@ -2138,14 +2149,15 @@ async function resolveWorkflowFromInput(getters, params) {
|
|
|
2138
2149
|
return { workflow: ranked[0].workflow };
|
|
2139
2150
|
}
|
|
2140
2151
|
var screenshotSchema = z2.object({
|
|
2141
|
-
selector: z2.string().optional().describe("Optional CSS selector to capture a specific element. Omit to capture the full viewport.")
|
|
2152
|
+
selector: z2.string().optional().describe("Optional CSS selector to capture a specific element. Omit to capture the full viewport."),
|
|
2153
|
+
resolution: z2.enum(["low", "medium", "high"]).optional().describe("Optional screenshot resolution. Use low for smaller/faster captures, medium for the default balance, or high for extra detail.")
|
|
2142
2154
|
});
|
|
2143
2155
|
var BUILTIN_SCREENSHOT_ACTION = {
|
|
2144
2156
|
id: "take_screenshot",
|
|
2145
2157
|
description: "Take a screenshot of the current page (or a specific element via CSS selector). Returns a base64 PNG image. Use when you need to see the current UI state, verify a visual change, or when the user asks you to look at the screen.",
|
|
2146
2158
|
schema: screenshotSchema,
|
|
2147
2159
|
execute: async (params) => {
|
|
2148
|
-
return await captureScreenshot(params.selector);
|
|
2160
|
+
return await captureScreenshot(params.selector, params.resolution);
|
|
2149
2161
|
}
|
|
2150
2162
|
};
|
|
2151
2163
|
var clickElementSchema = z2.object({
|
|
@@ -3155,6 +3167,54 @@ function compactTourForTransport(tour) {
|
|
|
3155
3167
|
};
|
|
3156
3168
|
}
|
|
3157
3169
|
|
|
3170
|
+
// src/utils/tourSessionPersistence.ts
|
|
3171
|
+
var ACTIVE_TOUR_SESSION_STORAGE_KEY = "modelnex-active-tour-session";
|
|
3172
|
+
var ACTIVE_TOUR_SESSION_VERSION = 1;
|
|
3173
|
+
var ACTIVE_TOUR_SESSION_MAX_AGE_MS = 10 * 60 * 1e3;
|
|
3174
|
+
function canUseSessionStorage2() {
|
|
3175
|
+
return typeof window !== "undefined" && typeof window.sessionStorage !== "undefined";
|
|
3176
|
+
}
|
|
3177
|
+
function persistActiveTourSession(runId) {
|
|
3178
|
+
if (!canUseSessionStorage2() || !Number.isFinite(runId)) return;
|
|
3179
|
+
const session = {
|
|
3180
|
+
version: ACTIVE_TOUR_SESSION_VERSION,
|
|
3181
|
+
runId,
|
|
3182
|
+
savedAt: Date.now()
|
|
3183
|
+
};
|
|
3184
|
+
try {
|
|
3185
|
+
window.sessionStorage.setItem(ACTIVE_TOUR_SESSION_STORAGE_KEY, JSON.stringify(session));
|
|
3186
|
+
} catch {
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
function clearPersistedActiveTourSession() {
|
|
3190
|
+
if (!canUseSessionStorage2()) return;
|
|
3191
|
+
try {
|
|
3192
|
+
window.sessionStorage.removeItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
|
|
3193
|
+
} catch {
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
function readPersistedActiveTourSession() {
|
|
3197
|
+
if (!canUseSessionStorage2()) return null;
|
|
3198
|
+
try {
|
|
3199
|
+
const raw = window.sessionStorage.getItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
|
|
3200
|
+
if (!raw) return null;
|
|
3201
|
+
const parsed = JSON.parse(raw);
|
|
3202
|
+
const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
|
|
3203
|
+
if (!isValid) {
|
|
3204
|
+
clearPersistedActiveTourSession();
|
|
3205
|
+
return null;
|
|
3206
|
+
}
|
|
3207
|
+
if (Date.now() - parsed.savedAt > ACTIVE_TOUR_SESSION_MAX_AGE_MS) {
|
|
3208
|
+
clearPersistedActiveTourSession();
|
|
3209
|
+
return null;
|
|
3210
|
+
}
|
|
3211
|
+
return parsed;
|
|
3212
|
+
} catch {
|
|
3213
|
+
clearPersistedActiveTourSession();
|
|
3214
|
+
return null;
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3158
3218
|
// src/utils/tour-playback-guards.ts
|
|
3159
3219
|
var playbackOwners = /* @__PURE__ */ new Map();
|
|
3160
3220
|
function shouldExecuteTourCommandBatch(isPlaybackActive) {
|
|
@@ -3766,7 +3826,8 @@ function useTourPlayback({
|
|
|
3766
3826
|
const pendingTourRef = useRef8(null);
|
|
3767
3827
|
const pendingTourOptionsRef = useRef8(null);
|
|
3768
3828
|
const showCaptionsRef = useRef8(showCaptions);
|
|
3769
|
-
const
|
|
3829
|
+
const initialPersistedTourSessionRef = useRef8(readPersistedActiveTourSession());
|
|
3830
|
+
const runIdRef = useRef8(initialPersistedTourSessionRef.current?.runId ?? null);
|
|
3770
3831
|
const turnIdRef = useRef8(null);
|
|
3771
3832
|
const startRequestedRef = useRef8(false);
|
|
3772
3833
|
const playbackOwnerIdRef = useRef8(`playback-owner-${Math.random().toString(36).slice(2, 10)}`);
|
|
@@ -3794,6 +3855,19 @@ function useTourPlayback({
|
|
|
3794
3855
|
releaseTourPlaybackOwnership(claimedKey, playbackOwnerIdRef.current);
|
|
3795
3856
|
claimedPlaybackOwnerKeyRef.current = null;
|
|
3796
3857
|
}, []);
|
|
3858
|
+
const emitTourInit = useCallback7((socket, currentWebsiteId, profile) => {
|
|
3859
|
+
if (!currentWebsiteId || !profile?.type) return;
|
|
3860
|
+
const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
|
|
3861
|
+
const payload = {
|
|
3862
|
+
websiteId: currentWebsiteId,
|
|
3863
|
+
userId: profile.userId,
|
|
3864
|
+
userType: profile.type
|
|
3865
|
+
};
|
|
3866
|
+
if (typeof persistedRunId === "number") {
|
|
3867
|
+
payload.resumeRunId = persistedRunId;
|
|
3868
|
+
}
|
|
3869
|
+
emitSocketEvent(socket, "tour:init", payload);
|
|
3870
|
+
}, []);
|
|
3797
3871
|
useEffect11(() => {
|
|
3798
3872
|
if (disabled) return;
|
|
3799
3873
|
if (typeof window === "undefined") return;
|
|
@@ -3805,9 +3879,7 @@ function useTourPlayback({
|
|
|
3805
3879
|
}, { devMode: devModeRef.current });
|
|
3806
3880
|
const profile = userProfileRef.current;
|
|
3807
3881
|
const currentWebsiteId = websiteIdRef.current;
|
|
3808
|
-
|
|
3809
|
-
emitSocketEvent(socket, "tour:init", { websiteId: currentWebsiteId, userId: profile.userId, userType: profile.type });
|
|
3810
|
-
}
|
|
3882
|
+
emitTourInit(socket, currentWebsiteId, profile);
|
|
3811
3883
|
};
|
|
3812
3884
|
const handleServerState = (payload) => {
|
|
3813
3885
|
if (typeof payload?.runId === "number") {
|
|
@@ -3816,6 +3888,11 @@ function useTourPlayback({
|
|
|
3816
3888
|
if (typeof payload?.turnId === "string" || payload?.turnId === null) {
|
|
3817
3889
|
turnIdRef.current = payload.turnId ?? null;
|
|
3818
3890
|
}
|
|
3891
|
+
if (payload?.isActive && typeof payload?.runId === "number") {
|
|
3892
|
+
persistActiveTourSession(payload.runId);
|
|
3893
|
+
} else if (payload?.isActive === false) {
|
|
3894
|
+
clearPersistedActiveTourSession();
|
|
3895
|
+
}
|
|
3819
3896
|
setServerState(payload);
|
|
3820
3897
|
};
|
|
3821
3898
|
const handleCommandCancel = (payload) => {
|
|
@@ -4079,19 +4156,9 @@ function useTourPlayback({
|
|
|
4079
4156
|
return { result: value };
|
|
4080
4157
|
}
|
|
4081
4158
|
if (action.type === "take_screenshot") {
|
|
4082
|
-
const
|
|
4083
|
-
const
|
|
4084
|
-
|
|
4085
|
-
useCORS: true,
|
|
4086
|
-
allowTaint: true,
|
|
4087
|
-
scale: Math.min(window.devicePixelRatio, 2),
|
|
4088
|
-
width: window.innerWidth,
|
|
4089
|
-
height: window.innerHeight,
|
|
4090
|
-
x: window.scrollX,
|
|
4091
|
-
y: window.scrollY,
|
|
4092
|
-
logging: false
|
|
4093
|
-
});
|
|
4094
|
-
return { result: canvas.toDataURL("image/png") };
|
|
4159
|
+
const selector = typeof action.params?.selector === "string" ? action.params.selector : void 0;
|
|
4160
|
+
const resolution = typeof action.params?.resolution === "string" ? action.params.resolution : void 0;
|
|
4161
|
+
return { result: await captureScreenshot(selector, resolution) };
|
|
4095
4162
|
}
|
|
4096
4163
|
if (action.type === "navigate_to_url") {
|
|
4097
4164
|
const nextUrl = typeof action.params?.url === "string" ? action.params.url : "";
|
|
@@ -4383,6 +4450,9 @@ function useTourPlayback({
|
|
|
4383
4450
|
const handleTourStart = async (tourData) => {
|
|
4384
4451
|
if (isActiveRef.current) return;
|
|
4385
4452
|
runIdRef.current = typeof tourData.runId === "number" ? tourData.runId : runIdRef.current;
|
|
4453
|
+
if (typeof runIdRef.current === "number") {
|
|
4454
|
+
persistActiveTourSession(runIdRef.current);
|
|
4455
|
+
}
|
|
4386
4456
|
const tour = tourData.tourContext ?? tourRef.current;
|
|
4387
4457
|
const expType = experienceTypeRef.current;
|
|
4388
4458
|
if (tour?.type && tour.type !== expType) {
|
|
@@ -4458,6 +4528,7 @@ function useTourPlayback({
|
|
|
4458
4528
|
}
|
|
4459
4529
|
};
|
|
4460
4530
|
const handleTourEndEvent = () => {
|
|
4531
|
+
clearPersistedActiveTourSession();
|
|
4461
4532
|
setServerState((prev) => prev ? { ...prev, isActive: false, phase: "completed" } : prev);
|
|
4462
4533
|
handleTourEnd();
|
|
4463
4534
|
};
|
|
@@ -4507,17 +4578,17 @@ function useTourPlayback({
|
|
|
4507
4578
|
releasePlaybackOwnership();
|
|
4508
4579
|
tourSocketPool.release(serverUrl, toClose);
|
|
4509
4580
|
};
|
|
4510
|
-
}, [serverUrl, disabled, releasePlaybackOwnership]);
|
|
4581
|
+
}, [serverUrl, disabled, emitTourInit, releasePlaybackOwnership]);
|
|
4511
4582
|
useEffect11(() => {
|
|
4512
4583
|
if (disabled) return;
|
|
4513
4584
|
const s = socketRef.current;
|
|
4514
4585
|
const profile = userProfile;
|
|
4515
4586
|
if (!websiteId || !profile?.type) return;
|
|
4516
4587
|
const timer = setTimeout(() => {
|
|
4517
|
-
|
|
4588
|
+
emitTourInit(s, websiteId, profile);
|
|
4518
4589
|
}, 150);
|
|
4519
4590
|
return () => clearTimeout(timer);
|
|
4520
|
-
}, [disabled, websiteId, userProfile?.userId, userProfile?.type]);
|
|
4591
|
+
}, [disabled, emitTourInit, websiteId, userProfile?.userId, userProfile?.type]);
|
|
4521
4592
|
useEffect11(() => {
|
|
4522
4593
|
if (!showCaptions || !isReviewMode) {
|
|
4523
4594
|
removeCaption();
|
|
@@ -4636,6 +4707,7 @@ function useTourPlayback({
|
|
|
4636
4707
|
tourRef.current = null;
|
|
4637
4708
|
setPlaybackState("idle");
|
|
4638
4709
|
setServerState(null);
|
|
4710
|
+
clearPersistedActiveTourSession();
|
|
4639
4711
|
runIdRef.current = null;
|
|
4640
4712
|
turnIdRef.current = null;
|
|
4641
4713
|
setPreviewRunId(null);
|
|
@@ -4665,6 +4737,7 @@ function useTourPlayback({
|
|
|
4665
4737
|
tourRef.current = null;
|
|
4666
4738
|
setPlaybackState("idle");
|
|
4667
4739
|
setServerState(null);
|
|
4740
|
+
clearPersistedActiveTourSession();
|
|
4668
4741
|
runIdRef.current = null;
|
|
4669
4742
|
turnIdRef.current = null;
|
|
4670
4743
|
setPreviewRunId(null);
|