@midscene/visualizer 1.5.2 → 1.5.3-beta-20260305031416.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/es/component/blackboard/index.css +82 -4
- package/dist/es/component/blackboard/index.mjs +73 -301
- package/dist/es/component/player/index.css +144 -119
- package/dist/es/component/player/index.mjs +468 -830
- package/dist/es/component/player/remotion/StepScene.mjs +190 -0
- package/dist/es/component/player/remotion/derive-frame-state.mjs +207 -0
- package/dist/es/component/player/remotion/export-branded-video.mjs +210 -0
- package/dist/es/component/player/remotion/frame-calculator.mjs +149 -0
- package/dist/es/component/player/use-frame-player.mjs +88 -0
- package/dist/es/component/universal-playground/index.mjs +14 -1
- package/dist/es/hooks/usePlaygroundExecution.mjs +11 -7
- package/dist/es/index.mjs +2 -2
- package/dist/es/store/store.mjs +9 -0
- package/dist/es/utils/replay-scripts.mjs +78 -59
- package/dist/lib/component/blackboard/index.css +82 -4
- package/dist/lib/component/blackboard/index.js +73 -307
- package/dist/lib/component/player/index.css +144 -119
- package/dist/lib/component/player/index.js +466 -828
- package/dist/lib/component/player/remotion/StepScene.js +224 -0
- package/dist/lib/component/player/remotion/derive-frame-state.js +241 -0
- package/dist/lib/component/player/remotion/export-branded-video.js +244 -0
- package/dist/lib/component/player/remotion/frame-calculator.js +186 -0
- package/dist/lib/component/player/use-frame-player.js +122 -0
- package/dist/lib/component/universal-playground/index.js +14 -1
- package/dist/lib/hooks/usePlaygroundExecution.js +11 -7
- package/dist/lib/index.js +3 -0
- package/dist/lib/store/store.js +9 -0
- package/dist/lib/utils/replay-scripts.js +80 -58
- package/dist/types/component/blackboard/index.d.ts +0 -4
- package/dist/types/component/player/index.d.ts +0 -1
- package/dist/types/component/player/remotion/StepScene.d.ts +9 -0
- package/dist/types/component/player/remotion/derive-frame-state.d.ts +38 -0
- package/dist/types/component/player/remotion/export-branded-video.d.ts +2 -0
- package/dist/types/component/player/remotion/frame-calculator.d.ts +35 -0
- package/dist/types/component/player/use-frame-player.d.ts +17 -0
- package/dist/types/hooks/usePlaygroundExecution.d.ts +15 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store/store.d.ts +2 -0
- package/dist/types/utils/replay-scripts.d.ts +16 -1
- package/package.json +5 -8
- package/dist/es/utils/pixi-loader.mjs +0 -42
- package/dist/lib/utils/pixi-loader.js +0 -82
- package/dist/types/utils/pixi-loader.d.ts +0 -5
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const FPS = 30;
|
|
2
|
+
function calculateFrameMap(scripts) {
|
|
3
|
+
let baseImageWidth = 1920;
|
|
4
|
+
let baseImageHeight = 1080;
|
|
5
|
+
for (const s of scripts)if (('img' === s.type || 'insight' === s.type) && s.img) {
|
|
6
|
+
baseImageWidth = s.imageWidth || 1920;
|
|
7
|
+
baseImageHeight = s.imageHeight || 1080;
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
const scriptFrames = [];
|
|
11
|
+
let currentFrame = 0;
|
|
12
|
+
for (const script of scripts){
|
|
13
|
+
const durationMs = script.duration;
|
|
14
|
+
switch(script.type){
|
|
15
|
+
case 'sleep':
|
|
16
|
+
{
|
|
17
|
+
const frames = Math.ceil(durationMs / 1000 * FPS);
|
|
18
|
+
scriptFrames.push({
|
|
19
|
+
type: 'sleep',
|
|
20
|
+
startFrame: currentFrame,
|
|
21
|
+
durationInFrames: frames,
|
|
22
|
+
title: script.title,
|
|
23
|
+
subTitle: script.subTitle,
|
|
24
|
+
taskId: script.taskId
|
|
25
|
+
});
|
|
26
|
+
currentFrame += frames;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case 'img':
|
|
30
|
+
{
|
|
31
|
+
const frames = Math.max(Math.ceil(durationMs / 1000 * FPS), 1);
|
|
32
|
+
const camera = script.camera;
|
|
33
|
+
const iw = script.imageWidth || baseImageWidth;
|
|
34
|
+
const ih = script.imageHeight || baseImageHeight;
|
|
35
|
+
const sf = {
|
|
36
|
+
type: 'img',
|
|
37
|
+
startFrame: currentFrame,
|
|
38
|
+
durationInFrames: frames,
|
|
39
|
+
img: script.img,
|
|
40
|
+
imageWidth: iw,
|
|
41
|
+
imageHeight: ih,
|
|
42
|
+
title: script.title,
|
|
43
|
+
subTitle: script.subTitle,
|
|
44
|
+
taskId: script.taskId
|
|
45
|
+
};
|
|
46
|
+
if (camera) {
|
|
47
|
+
var _camera_pointerLeft, _camera_pointerTop;
|
|
48
|
+
sf.cameraTarget = {
|
|
49
|
+
left: camera.left,
|
|
50
|
+
top: camera.top,
|
|
51
|
+
width: camera.width,
|
|
52
|
+
pointerLeft: null != (_camera_pointerLeft = camera.pointerLeft) ? _camera_pointerLeft : Math.round(iw / 2),
|
|
53
|
+
pointerTop: null != (_camera_pointerTop = camera.pointerTop) ? _camera_pointerTop : Math.round(ih / 2)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
scriptFrames.push(sf);
|
|
57
|
+
currentFrame += frames;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'insight':
|
|
61
|
+
{
|
|
62
|
+
const insightPhaseFrames = Math.max(Math.ceil(durationMs / 1000 * FPS), 1);
|
|
63
|
+
const cameraDurationMs = script.insightCameraDuration || 0;
|
|
64
|
+
const cameraPhaseFrames = Math.ceil(cameraDurationMs / 1000 * FPS);
|
|
65
|
+
const totalFrames = insightPhaseFrames + cameraPhaseFrames;
|
|
66
|
+
const iw = script.imageWidth || baseImageWidth;
|
|
67
|
+
const ih = script.imageHeight || baseImageHeight;
|
|
68
|
+
const camera = script.camera;
|
|
69
|
+
const sf = {
|
|
70
|
+
type: 'insight',
|
|
71
|
+
startFrame: currentFrame,
|
|
72
|
+
durationInFrames: totalFrames,
|
|
73
|
+
img: script.img,
|
|
74
|
+
imageWidth: iw,
|
|
75
|
+
imageHeight: ih,
|
|
76
|
+
insightPhaseFrames,
|
|
77
|
+
cameraPhaseFrames,
|
|
78
|
+
highlightElement: script.highlightElement,
|
|
79
|
+
searchArea: script.searchArea,
|
|
80
|
+
title: script.title,
|
|
81
|
+
subTitle: script.subTitle,
|
|
82
|
+
taskId: script.taskId
|
|
83
|
+
};
|
|
84
|
+
if (camera) {
|
|
85
|
+
var _camera_pointerLeft1, _camera_pointerTop1;
|
|
86
|
+
sf.cameraTarget = {
|
|
87
|
+
left: camera.left,
|
|
88
|
+
top: camera.top,
|
|
89
|
+
width: camera.width,
|
|
90
|
+
pointerLeft: null != (_camera_pointerLeft1 = camera.pointerLeft) ? _camera_pointerLeft1 : Math.round(iw / 2),
|
|
91
|
+
pointerTop: null != (_camera_pointerTop1 = camera.pointerTop) ? _camera_pointerTop1 : Math.round(ih / 2)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
scriptFrames.push(sf);
|
|
95
|
+
currentFrame += totalFrames;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'clear-insight':
|
|
99
|
+
{
|
|
100
|
+
const frames = Math.max(Math.ceil(durationMs / 1000 * FPS), 1);
|
|
101
|
+
scriptFrames.push({
|
|
102
|
+
type: 'clear-insight',
|
|
103
|
+
startFrame: currentFrame,
|
|
104
|
+
durationInFrames: frames,
|
|
105
|
+
title: script.title,
|
|
106
|
+
subTitle: script.subTitle,
|
|
107
|
+
taskId: script.taskId
|
|
108
|
+
});
|
|
109
|
+
currentFrame += frames;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 'spinning-pointer':
|
|
113
|
+
{
|
|
114
|
+
const frames = Math.max(Math.ceil(durationMs / 1000 * FPS), 1);
|
|
115
|
+
scriptFrames.push({
|
|
116
|
+
type: 'spinning-pointer',
|
|
117
|
+
startFrame: currentFrame,
|
|
118
|
+
durationInFrames: frames,
|
|
119
|
+
title: script.title,
|
|
120
|
+
subTitle: script.subTitle,
|
|
121
|
+
taskId: script.taskId
|
|
122
|
+
});
|
|
123
|
+
currentFrame += frames;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 'pointer':
|
|
127
|
+
scriptFrames.push({
|
|
128
|
+
type: 'pointer',
|
|
129
|
+
startFrame: currentFrame,
|
|
130
|
+
durationInFrames: 0,
|
|
131
|
+
pointerImg: script.img,
|
|
132
|
+
title: script.title,
|
|
133
|
+
subTitle: script.subTitle,
|
|
134
|
+
taskId: script.taskId
|
|
135
|
+
});
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const stepsDurationInFrames = Math.max(currentFrame, 1);
|
|
140
|
+
return {
|
|
141
|
+
scriptFrames,
|
|
142
|
+
totalDurationInFrames: stepsDurationInFrames,
|
|
143
|
+
fps: FPS,
|
|
144
|
+
stepsDurationInFrames,
|
|
145
|
+
imageWidth: baseImageWidth,
|
|
146
|
+
imageHeight: baseImageHeight
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export { FPS, calculateFrameMap };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
function useFramePlayer(options) {
|
|
3
|
+
const { durationInFrames, fps, autoPlay = false, loop = false } = options;
|
|
4
|
+
const [currentFrame, setCurrentFrame] = useState(0);
|
|
5
|
+
const [playing, setPlaying] = useState(autoPlay);
|
|
6
|
+
const playingRef = useRef(playing);
|
|
7
|
+
const frameRef = useRef(currentFrame);
|
|
8
|
+
var _options_playbackRate;
|
|
9
|
+
const rateRef = useRef(null != (_options_playbackRate = options.playbackRate) ? _options_playbackRate : 1);
|
|
10
|
+
const durationRef = useRef(durationInFrames);
|
|
11
|
+
const fpsRef = useRef(fps);
|
|
12
|
+
const loopRef = useRef(loop);
|
|
13
|
+
playingRef.current = playing;
|
|
14
|
+
frameRef.current = currentFrame;
|
|
15
|
+
var _options_playbackRate1;
|
|
16
|
+
rateRef.current = null != (_options_playbackRate1 = options.playbackRate) ? _options_playbackRate1 : 1;
|
|
17
|
+
durationRef.current = durationInFrames;
|
|
18
|
+
fpsRef.current = fps;
|
|
19
|
+
loopRef.current = loop;
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
if (!playing) return;
|
|
22
|
+
let rafId;
|
|
23
|
+
let lastTime = null;
|
|
24
|
+
let accumulated = 0;
|
|
25
|
+
const tick = (now)=>{
|
|
26
|
+
if (null !== lastTime) {
|
|
27
|
+
const delta = (now - lastTime) * rateRef.current;
|
|
28
|
+
accumulated += delta;
|
|
29
|
+
const frameDuration = 1000 / fpsRef.current;
|
|
30
|
+
while(accumulated >= frameDuration){
|
|
31
|
+
accumulated -= frameDuration;
|
|
32
|
+
const next = frameRef.current + 1;
|
|
33
|
+
if (next >= durationRef.current) if (loopRef.current) {
|
|
34
|
+
frameRef.current = 0;
|
|
35
|
+
setCurrentFrame(0);
|
|
36
|
+
} else {
|
|
37
|
+
frameRef.current = durationRef.current - 1;
|
|
38
|
+
setCurrentFrame(durationRef.current - 1);
|
|
39
|
+
setPlaying(false);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
frameRef.current = next;
|
|
44
|
+
setCurrentFrame(next);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
lastTime = now;
|
|
49
|
+
rafId = requestAnimationFrame(tick);
|
|
50
|
+
};
|
|
51
|
+
rafId = requestAnimationFrame(tick);
|
|
52
|
+
return ()=>cancelAnimationFrame(rafId);
|
|
53
|
+
}, [
|
|
54
|
+
playing
|
|
55
|
+
]);
|
|
56
|
+
const play = useCallback(()=>{
|
|
57
|
+
if (frameRef.current >= durationRef.current - 1) {
|
|
58
|
+
frameRef.current = 0;
|
|
59
|
+
setCurrentFrame(0);
|
|
60
|
+
}
|
|
61
|
+
setPlaying(true);
|
|
62
|
+
}, []);
|
|
63
|
+
const pause = useCallback(()=>setPlaying(false), []);
|
|
64
|
+
const toggle = useCallback(()=>{
|
|
65
|
+
if (playingRef.current) setPlaying(false);
|
|
66
|
+
else {
|
|
67
|
+
if (frameRef.current >= durationRef.current - 1) {
|
|
68
|
+
frameRef.current = 0;
|
|
69
|
+
setCurrentFrame(0);
|
|
70
|
+
}
|
|
71
|
+
setPlaying(true);
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
const seekTo = useCallback((frame)=>{
|
|
75
|
+
const clamped = Math.max(0, Math.min(frame, durationRef.current - 1));
|
|
76
|
+
frameRef.current = clamped;
|
|
77
|
+
setCurrentFrame(clamped);
|
|
78
|
+
}, []);
|
|
79
|
+
return {
|
|
80
|
+
currentFrame,
|
|
81
|
+
playing,
|
|
82
|
+
play,
|
|
83
|
+
pause,
|
|
84
|
+
toggle,
|
|
85
|
+
seekTo
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export { useFramePlayer };
|
|
@@ -100,7 +100,20 @@ function UniversalPlayground({ playgroundSDK, storage, contextProvider, config:
|
|
|
100
100
|
playgroundSDK
|
|
101
101
|
]);
|
|
102
102
|
const { loading, setLoading, infoList, setInfoList, actionSpace, actionSpaceLoading, uiContextPreview, setUiContextPreview, showScrollToBottomButton, verticalMode, replayCounter, setReplayCounter, infoListRef, currentRunningIdRef, interruptedFlagRef, clearInfoList, handleScrollToBottom } = usePlaygroundState(playgroundSDK, effectiveStorage, contextProvider, branding.targetName);
|
|
103
|
-
const { handleRun: executeAction, handleStop, canStop } = usePlaygroundExecution(
|
|
103
|
+
const { handleRun: executeAction, handleStop, canStop } = usePlaygroundExecution({
|
|
104
|
+
playgroundSDK,
|
|
105
|
+
storage: effectiveStorage,
|
|
106
|
+
actionSpace,
|
|
107
|
+
loading,
|
|
108
|
+
setLoading,
|
|
109
|
+
setInfoList,
|
|
110
|
+
replayCounter,
|
|
111
|
+
setReplayCounter,
|
|
112
|
+
verticalMode,
|
|
113
|
+
currentRunningIdRef,
|
|
114
|
+
interruptedFlagRef,
|
|
115
|
+
deviceType: componentConfig.deviceType
|
|
116
|
+
});
|
|
104
117
|
useEffect(()=>{
|
|
105
118
|
if ((null == playgroundSDK ? void 0 : playgroundSDK.overrideConfig) && config) playgroundSDK.overrideConfig(config).catch((error)=>{
|
|
106
119
|
console.error('Failed to override SDK config:', error);
|
|
@@ -88,7 +88,7 @@ function buildProgressContent(task) {
|
|
|
88
88
|
const description = paramStr(task);
|
|
89
89
|
return description ? `${action} - ${description}` : action;
|
|
90
90
|
}
|
|
91
|
-
function wrapExecutionDumpForReplay(dump) {
|
|
91
|
+
function wrapExecutionDumpForReplay(dump, deviceType) {
|
|
92
92
|
const modelBriefsSet = new Set();
|
|
93
93
|
if ((null == dump ? void 0 : dump.tasks) && Array.isArray(dump.tasks)) dump.tasks.forEach((task)=>{
|
|
94
94
|
if (task.usage) {
|
|
@@ -106,10 +106,12 @@ function wrapExecutionDumpForReplay(dump) {
|
|
|
106
106
|
modelBriefs,
|
|
107
107
|
executions: [
|
|
108
108
|
dump
|
|
109
|
-
]
|
|
109
|
+
],
|
|
110
|
+
deviceType
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
|
-
function usePlaygroundExecution(
|
|
113
|
+
function usePlaygroundExecution(options) {
|
|
114
|
+
const { playgroundSDK, storage, actionSpace, loading, setLoading, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef, deviceType } = options;
|
|
113
115
|
const { deepLocate, deepThink, screenshotIncluded, domIncluded } = useEnvConfig();
|
|
114
116
|
const handleRun = useCallback((value)=>_async_to_generator(function*() {
|
|
115
117
|
if (!playgroundSDK) return void console.warn('PlaygroundSDK is not available');
|
|
@@ -206,7 +208,7 @@ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, se
|
|
|
206
208
|
let counter = replayCounter;
|
|
207
209
|
if (null == result ? void 0 : result.dump) {
|
|
208
210
|
if (result.dump.tasks && Array.isArray(result.dump.tasks)) {
|
|
209
|
-
const groupedDump = wrapExecutionDumpForReplay(result.dump);
|
|
211
|
+
const groupedDump = wrapExecutionDumpForReplay(result.dump, deviceType);
|
|
210
212
|
const info = allScriptsFromDump(groupedDump);
|
|
211
213
|
setReplayCounter((c)=>c + 1);
|
|
212
214
|
replayInfo = info;
|
|
@@ -264,7 +266,8 @@ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, se
|
|
|
264
266
|
deepLocate,
|
|
265
267
|
deepThink,
|
|
266
268
|
screenshotIncluded,
|
|
267
|
-
domIncluded
|
|
269
|
+
domIncluded,
|
|
270
|
+
deviceType
|
|
268
271
|
]);
|
|
269
272
|
const handleStop = useCallback(()=>_async_to_generator(function*() {
|
|
270
273
|
const thisRunningId = currentRunningIdRef.current;
|
|
@@ -291,7 +294,7 @@ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, se
|
|
|
291
294
|
let replayInfo = null;
|
|
292
295
|
let counter = replayCounter;
|
|
293
296
|
if ((null == (_executionData_dump = executionData.dump) ? void 0 : _executionData_dump.tasks) && Array.isArray(executionData.dump.tasks)) {
|
|
294
|
-
const groupedDump = wrapExecutionDumpForReplay(executionData.dump);
|
|
297
|
+
const groupedDump = wrapExecutionDumpForReplay(executionData.dump, deviceType);
|
|
295
298
|
replayInfo = allScriptsFromDump(groupedDump);
|
|
296
299
|
setReplayCounter((c)=>c + 1);
|
|
297
300
|
counter = replayCounter + 1;
|
|
@@ -349,7 +352,8 @@ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, se
|
|
|
349
352
|
setLoading,
|
|
350
353
|
setInfoList,
|
|
351
354
|
verticalMode,
|
|
352
|
-
replayCounter
|
|
355
|
+
replayCounter,
|
|
356
|
+
deviceType
|
|
353
357
|
]);
|
|
354
358
|
const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK && !!playgroundSDK.cancelExecution;
|
|
355
359
|
return {
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { allScriptsFromDump, generateAnimationScripts } from "./utils/replay-scripts.mjs";
|
|
1
|
+
import { allScriptsFromDump, extractDumpMetaInfo, generateAnimationScripts } from "./utils/replay-scripts.mjs";
|
|
2
2
|
import { useEnvConfig, useGlobalPreference } from "./store/store.mjs";
|
|
3
3
|
import { colorForName, globalThemeConfig, highlightColorForType } from "./utils/color.mjs";
|
|
4
4
|
import { EnvConfig } from "./component/env-config/index.mjs";
|
|
@@ -22,4 +22,4 @@ import shiny_text from "./component/shiny-text/index.mjs";
|
|
|
22
22
|
import universal_playground, { UniversalPlayground } from "./component/universal-playground/index.mjs";
|
|
23
23
|
import { IndexedDBStorageProvider, LocalStorageProvider, MemoryStorageProvider, NoOpStorageProvider, StorageType, createStorageProvider, detectBestStorageType } from "./component/universal-playground/providers/storage-provider.mjs";
|
|
24
24
|
import { AgentContextProvider, BaseContextProvider, NoOpContextProvider, StaticContextProvider } from "./component/universal-playground/providers/context-provider.mjs";
|
|
25
|
-
export { AgentContextProvider, BaseContextProvider, Blackboard, ContextPreview, EnvConfig, EnvConfigReminder, IndexedDBStorageProvider, LocalStorageProvider, Logo, MemoryStorageProvider, NavActions, NoOpContextProvider, NoOpStorageProvider, Player, PlaygroundResultView, PromptInput, screenshot_viewer as ScreenshotViewer, ServiceModeControl, shiny_text as ShinyText, StaticContextProvider, StorageType, UniversalPlayground, universal_playground as UniversalPlaygroundDefault, actionNameForType, allScriptsFromDump, colorForName, createStorageProvider, detectBestStorageType, filterBase64Value, generateAnimationScripts, getPlaceholderForType, globalThemeConfig, highlightColorForType, iconForStatus, safeOverrideAIConfig, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useGlobalPreference, useSafeOverrideAIConfig, useServerValid, useTheme };
|
|
25
|
+
export { AgentContextProvider, BaseContextProvider, Blackboard, ContextPreview, EnvConfig, EnvConfigReminder, IndexedDBStorageProvider, LocalStorageProvider, Logo, MemoryStorageProvider, NavActions, NoOpContextProvider, NoOpStorageProvider, Player, PlaygroundResultView, PromptInput, screenshot_viewer as ScreenshotViewer, ServiceModeControl, shiny_text as ShinyText, StaticContextProvider, StorageType, UniversalPlayground, universal_playground as UniversalPlaygroundDefault, actionNameForType, allScriptsFromDump, colorForName, createStorageProvider, detectBestStorageType, extractDumpMetaInfo, filterBase64Value, generateAnimationScripts, getPlaceholderForType, globalThemeConfig, highlightColorForType, iconForStatus, safeOverrideAIConfig, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useGlobalPreference, useSafeOverrideAIConfig, useServerValid, useTheme };
|
package/dist/es/store/store.mjs
CHANGED
|
@@ -33,6 +33,7 @@ const ELEMENTS_VISIBLE_KEY = 'midscene-elements-visible';
|
|
|
33
33
|
const MODEL_CALL_DETAILS_KEY = 'midscene-model-call-details';
|
|
34
34
|
const DARK_MODE_KEY = 'midscene-dark-mode';
|
|
35
35
|
const PLAYBACK_SPEED_KEY = 'midscene-playback-speed';
|
|
36
|
+
const SUBTITLE_ENABLED_KEY = 'midscene-subtitle-enabled';
|
|
36
37
|
const parseBooleanParam = (value)=>{
|
|
37
38
|
if (null === value) return;
|
|
38
39
|
const normalized = value.trim().toLowerCase();
|
|
@@ -62,6 +63,7 @@ const useGlobalPreference = store_create((set)=>{
|
|
|
62
63
|
const savedDarkMode = 'true' === localStorage.getItem(DARK_MODE_KEY);
|
|
63
64
|
const parsedPlaybackSpeed = Number.parseFloat(localStorage.getItem(PLAYBACK_SPEED_KEY) || '1');
|
|
64
65
|
const savedPlaybackSpeed = Number.isNaN(parsedPlaybackSpeed) ? 1 : parsedPlaybackSpeed;
|
|
66
|
+
const savedSubtitleEnabled = 'false' !== localStorage.getItem(SUBTITLE_ENABLED_KEY);
|
|
65
67
|
const autoZoomFromQuery = getQueryPreference('focusOnCursor');
|
|
66
68
|
const elementsVisibleFromQuery = getQueryPreference('showElementMarkers');
|
|
67
69
|
const darkModeFromQuery = getQueryPreference('darkMode');
|
|
@@ -114,6 +116,13 @@ const useGlobalPreference = store_create((set)=>{
|
|
|
114
116
|
playbackSpeed: speed
|
|
115
117
|
});
|
|
116
118
|
localStorage.setItem(PLAYBACK_SPEED_KEY, speed.toString());
|
|
119
|
+
},
|
|
120
|
+
subtitleEnabled: savedSubtitleEnabled,
|
|
121
|
+
setSubtitleEnabled: (enabled)=>{
|
|
122
|
+
set({
|
|
123
|
+
subtitleEnabled: enabled
|
|
124
|
+
});
|
|
125
|
+
localStorage.setItem(SUBTITLE_ENABLED_KEY, enabled.toString());
|
|
117
126
|
}
|
|
118
127
|
};
|
|
119
128
|
});
|
|
@@ -79,16 +79,9 @@ const mergeTwoCameraState = (cameraState1, cameraState2)=>{
|
|
|
79
79
|
width: newWidth
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
console.warn('[allScriptsFromDump] dump is empty');
|
|
86
|
-
return {
|
|
87
|
-
scripts: [],
|
|
88
|
-
modelBriefs: []
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const normalizedDump = Array.isArray(dump.executions) ? dump : {
|
|
82
|
+
const normalizeDump = (dump)=>{
|
|
83
|
+
if (!dump) return null;
|
|
84
|
+
return Array.isArray(dump.executions) ? dump : {
|
|
92
85
|
sdkVersion: '',
|
|
93
86
|
groupName: 'Execution',
|
|
94
87
|
modelBriefs: [],
|
|
@@ -96,7 +89,11 @@ const allScriptsFromDump = (dump)=>{
|
|
|
96
89
|
dump
|
|
97
90
|
]
|
|
98
91
|
};
|
|
99
|
-
|
|
92
|
+
};
|
|
93
|
+
const extractDumpMetaInfo = (dump)=>{
|
|
94
|
+
var _normalizedDump_executions, _normalizedDump_modelBriefs;
|
|
95
|
+
const normalizedDump = normalizeDump(dump);
|
|
96
|
+
if (!normalizedDump) return null;
|
|
100
97
|
let firstWidth;
|
|
101
98
|
let firstHeight;
|
|
102
99
|
const sdkVersion = normalizedDump.sdkVersion;
|
|
@@ -111,35 +108,17 @@ const allScriptsFromDump = (dump)=>{
|
|
|
111
108
|
firstWidth = w;
|
|
112
109
|
firstHeight = h;
|
|
113
110
|
}
|
|
114
|
-
dimensionsSet.add(`${w}x${h}`);
|
|
115
111
|
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
if (!firstWidth || !firstHeight) {
|
|
119
|
-
console.warn('width or height is missing in dump file');
|
|
120
|
-
return {
|
|
121
|
-
scripts: [],
|
|
122
|
-
sdkVersion,
|
|
123
|
-
modelBriefs: []
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const allScripts = [];
|
|
127
|
-
const executions = (null == (_normalizedDump_executions1 = normalizedDump.executions) ? void 0 : _normalizedDump_executions1.filter(Boolean)) || [];
|
|
128
|
-
for(let execIndex = 0; execIndex < executions.length; execIndex++){
|
|
129
|
-
const execution = executions[execIndex];
|
|
130
|
-
const scripts = generateAnimationScripts(execution, -1, firstWidth, firstHeight, execIndex);
|
|
131
|
-
if (scripts) allScripts.push(...scripts);
|
|
132
|
-
execution.tasks.forEach((task)=>{
|
|
133
112
|
if (task.usage) {
|
|
134
113
|
const { model_name, model_description, intent } = task.usage;
|
|
135
114
|
if (intent && model_name) modelBriefsSet.add(model_description ? `${intent}/${model_name}(${model_description})` : `${intent}/${model_name}`);
|
|
136
115
|
}
|
|
137
116
|
});
|
|
138
|
-
}
|
|
139
|
-
const allScriptsWithoutIntermediateDoneFrame = allScripts.filter((script, index)=>{
|
|
140
|
-
if (index !== allScripts.length - 1 && 'Done' === script.title) return false;
|
|
141
|
-
return true;
|
|
142
117
|
});
|
|
118
|
+
if (!firstWidth || !firstHeight) {
|
|
119
|
+
console.warn('width or height is missing in dump file');
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
143
122
|
const normalizedModelBriefs = (null == (_normalizedDump_modelBriefs = normalizedDump.modelBriefs) ? void 0 : _normalizedDump_modelBriefs.length) ? normalizedDump.modelBriefs : [];
|
|
144
123
|
const modelBriefs = (()=>{
|
|
145
124
|
var _list_;
|
|
@@ -154,11 +133,48 @@ const allScriptsFromDump = (dump)=>{
|
|
|
154
133
|
return list;
|
|
155
134
|
})();
|
|
156
135
|
return {
|
|
157
|
-
scripts: allScriptsWithoutIntermediateDoneFrame,
|
|
158
136
|
width: firstWidth,
|
|
159
137
|
height: firstHeight,
|
|
160
138
|
sdkVersion,
|
|
161
|
-
modelBriefs
|
|
139
|
+
modelBriefs,
|
|
140
|
+
deviceType: normalizedDump.deviceType
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const allScriptsFromDump = (dump)=>{
|
|
144
|
+
var _normalizedDump_executions;
|
|
145
|
+
const normalizedDump = normalizeDump(dump);
|
|
146
|
+
if (!normalizedDump) {
|
|
147
|
+
console.warn('[allScriptsFromDump] dump is empty');
|
|
148
|
+
return {
|
|
149
|
+
scripts: [],
|
|
150
|
+
modelBriefs: []
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const metaInfo = extractDumpMetaInfo(dump);
|
|
154
|
+
if (!metaInfo) return {
|
|
155
|
+
scripts: [],
|
|
156
|
+
sdkVersion: normalizedDump.sdkVersion,
|
|
157
|
+
modelBriefs: []
|
|
158
|
+
};
|
|
159
|
+
const { width: firstWidth, height: firstHeight } = metaInfo;
|
|
160
|
+
const allScripts = [];
|
|
161
|
+
const executions = (null == (_normalizedDump_executions = normalizedDump.executions) ? void 0 : _normalizedDump_executions.filter(Boolean)) || [];
|
|
162
|
+
for(let execIndex = 0; execIndex < executions.length; execIndex++){
|
|
163
|
+
const execution = executions[execIndex];
|
|
164
|
+
const scripts = generateAnimationScripts(execution, -1, firstWidth, firstHeight, execIndex);
|
|
165
|
+
if (scripts) allScripts.push(...scripts);
|
|
166
|
+
}
|
|
167
|
+
const allScriptsWithoutIntermediateDoneFrame = allScripts.filter((script, index)=>{
|
|
168
|
+
if (index !== allScripts.length - 1 && 'Done' === script.title) return false;
|
|
169
|
+
return true;
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
scripts: allScriptsWithoutIntermediateDoneFrame,
|
|
173
|
+
width: firstWidth,
|
|
174
|
+
height: firstHeight,
|
|
175
|
+
sdkVersion: metaInfo.sdkVersion,
|
|
176
|
+
modelBriefs: metaInfo.modelBriefs,
|
|
177
|
+
deviceType: metaInfo.deviceType
|
|
162
178
|
};
|
|
163
179
|
};
|
|
164
180
|
const generateAnimationScripts = (execution, task, imageWidth, imageHeight, executionIndex = 0)=>{
|
|
@@ -197,6 +213,19 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
197
213
|
subTitle,
|
|
198
214
|
taskId
|
|
199
215
|
});
|
|
216
|
+
const createScript = (base, screenshot)=>{
|
|
217
|
+
if (!screenshot) return base;
|
|
218
|
+
const script = _object_spread({}, base);
|
|
219
|
+
let cachedImg;
|
|
220
|
+
Object.defineProperty(script, 'img', {
|
|
221
|
+
get () {
|
|
222
|
+
if (void 0 === cachedImg) cachedImg = screenshot.base64;
|
|
223
|
+
return cachedImg;
|
|
224
|
+
},
|
|
225
|
+
enumerable: true
|
|
226
|
+
});
|
|
227
|
+
return script;
|
|
228
|
+
};
|
|
200
229
|
const scripts = [];
|
|
201
230
|
let insightCameraState;
|
|
202
231
|
let insightOnTop = false;
|
|
@@ -240,17 +269,16 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
240
269
|
var _context_shotSize, _context_shotSize1;
|
|
241
270
|
const width = (null == (_context_shotSize = context.shotSize) ? void 0 : _context_shotSize.width) || imageWidth;
|
|
242
271
|
const height = (null == (_context_shotSize1 = context.shotSize) ? void 0 : _context_shotSize1.height) || imageHeight;
|
|
243
|
-
const
|
|
244
|
-
scripts.push({
|
|
272
|
+
const contextScreenshot = context.screenshot;
|
|
273
|
+
scripts.push(createScript({
|
|
245
274
|
type: 'img',
|
|
246
|
-
img: screenshotData,
|
|
247
275
|
duration: stillAfterInsightDuration,
|
|
248
276
|
title,
|
|
249
277
|
subTitle,
|
|
250
278
|
imageWidth: width,
|
|
251
279
|
imageHeight: height,
|
|
252
280
|
taskId: currentTaskId
|
|
253
|
-
});
|
|
281
|
+
}, contextScreenshot));
|
|
254
282
|
locateElements.forEach((element)=>{
|
|
255
283
|
var _task_log_taskInfo, _task_log, _context_shotSize, _context_shotSize1;
|
|
256
284
|
insightCameraState = _object_spread_props(_object_spread({}, cameraStateForRect(element.rect, width, height)), {
|
|
@@ -258,9 +286,8 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
258
286
|
pointerTop: element.center[1]
|
|
259
287
|
});
|
|
260
288
|
const newCameraState = insightCameraState;
|
|
261
|
-
scripts.push({
|
|
289
|
+
scripts.push(createScript({
|
|
262
290
|
type: 'insight',
|
|
263
|
-
img: screenshotData,
|
|
264
291
|
context: context,
|
|
265
292
|
camera: newCameraState,
|
|
266
293
|
highlightElement: element,
|
|
@@ -272,7 +299,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
272
299
|
imageWidth: (null == (_context_shotSize = context.shotSize) ? void 0 : _context_shotSize.width) || imageWidth,
|
|
273
300
|
imageHeight: (null == (_context_shotSize1 = context.shotSize) ? void 0 : _context_shotSize1.height) || imageHeight,
|
|
274
301
|
taskId: currentTaskId
|
|
275
|
-
});
|
|
302
|
+
}, contextScreenshot));
|
|
276
303
|
insightOnTop = true;
|
|
277
304
|
});
|
|
278
305
|
}
|
|
@@ -280,17 +307,15 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
280
307
|
if (planningTask.recorder && planningTask.recorder.length > 0) {
|
|
281
308
|
var _planningTask_recorder_, _task_uiContext_shotSize, _task_uiContext, _task_uiContext_shotSize1, _task_uiContext1;
|
|
282
309
|
const screenshot = null == (_planningTask_recorder_ = planningTask.recorder[0]) ? void 0 : _planningTask_recorder_.screenshot;
|
|
283
|
-
|
|
284
|
-
scripts.push({
|
|
310
|
+
scripts.push(createScript({
|
|
285
311
|
type: 'img',
|
|
286
|
-
img: screenshotData,
|
|
287
312
|
duration: stillDuration,
|
|
288
313
|
title: typeStr(task),
|
|
289
314
|
subTitle: paramStr(task),
|
|
290
315
|
imageWidth: (null == (_task_uiContext = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize = _task_uiContext.shotSize) ? void 0 : _task_uiContext_shotSize.width) || imageWidth,
|
|
291
316
|
imageHeight: (null == (_task_uiContext1 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize1 = _task_uiContext1.shotSize) ? void 0 : _task_uiContext_shotSize1.height) || imageHeight,
|
|
292
317
|
taskId: currentTaskId
|
|
293
|
-
});
|
|
318
|
+
}, screenshot));
|
|
294
319
|
}
|
|
295
320
|
} else if ('Action Space' === task.type) {
|
|
296
321
|
var _task_recorder_, _task_recorder, _task_uiContext_shotSize2, _task_uiContext2, _task_uiContext_shotSize3, _task_uiContext3;
|
|
@@ -315,10 +340,8 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
315
340
|
}
|
|
316
341
|
scripts.push(setPointerScript(mousePointer, title, subTitle, currentTaskId));
|
|
317
342
|
const screenshot = null == (_task_recorder = task.recorder) ? void 0 : null == (_task_recorder_ = _task_recorder[0]) ? void 0 : _task_recorder_.screenshot;
|
|
318
|
-
|
|
319
|
-
scripts.push({
|
|
343
|
+
scripts.push(createScript({
|
|
320
344
|
type: 'img',
|
|
321
|
-
img: actionScreenshotData,
|
|
322
345
|
duration: actionDuration,
|
|
323
346
|
camera: 'Sleep' === task.subType ? fullPageCameraState : void 0,
|
|
324
347
|
title,
|
|
@@ -326,7 +349,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
326
349
|
imageWidth: (null == (_task_uiContext2 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize2 = _task_uiContext2.shotSize) ? void 0 : _task_uiContext_shotSize2.width) || imageWidth,
|
|
327
350
|
imageHeight: (null == (_task_uiContext3 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize3 = _task_uiContext3.shotSize) ? void 0 : _task_uiContext_shotSize3.height) || imageHeight,
|
|
328
351
|
taskId: currentTaskId
|
|
329
|
-
});
|
|
352
|
+
}, screenshot));
|
|
330
353
|
} else {
|
|
331
354
|
var _task_recorder_1, _task_recorder1;
|
|
332
355
|
const title = typeStr(task);
|
|
@@ -334,10 +357,8 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
334
357
|
const screenshot = null == (_task_recorder1 = task.recorder) ? void 0 : null == (_task_recorder_1 = _task_recorder1[task.recorder.length - 1]) ? void 0 : _task_recorder_1.screenshot;
|
|
335
358
|
if (screenshot) {
|
|
336
359
|
var _task_uiContext_shotSize4, _task_uiContext4, _task_uiContext_shotSize5, _task_uiContext5;
|
|
337
|
-
|
|
338
|
-
scripts.push({
|
|
360
|
+
scripts.push(createScript({
|
|
339
361
|
type: 'img',
|
|
340
|
-
img: screenshotData,
|
|
341
362
|
duration: stillDuration,
|
|
342
363
|
camera: fullPageCameraState,
|
|
343
364
|
title,
|
|
@@ -345,7 +366,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
345
366
|
imageWidth: (null == (_task_uiContext4 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize4 = _task_uiContext4.shotSize) ? void 0 : _task_uiContext_shotSize4.width) || imageWidth,
|
|
346
367
|
imageHeight: (null == (_task_uiContext5 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize5 = _task_uiContext5.shotSize) ? void 0 : _task_uiContext_shotSize5.height) || imageHeight,
|
|
347
368
|
taskId: currentTaskId
|
|
348
|
-
});
|
|
369
|
+
}, screenshot));
|
|
349
370
|
}
|
|
350
371
|
}
|
|
351
372
|
if ('finished' !== task.status) {
|
|
@@ -354,10 +375,8 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
354
375
|
const errorMsg = task.errorMessage || 'unknown error';
|
|
355
376
|
const errorSubTitle = errorMsg.indexOf('NOT_IMPLEMENTED_AS_DESIGNED') > 0 ? 'Further actions cannot be performed in the current environment' : errorMsg;
|
|
356
377
|
const screenshot = null == (_task_recorder2 = task.recorder) ? void 0 : null == (_task_recorder_2 = _task_recorder2[task.recorder.length - 1]) ? void 0 : _task_recorder_2.screenshot;
|
|
357
|
-
|
|
358
|
-
scripts.push({
|
|
378
|
+
scripts.push(createScript({
|
|
359
379
|
type: 'img',
|
|
360
|
-
img: errorScreenshotData,
|
|
361
380
|
camera: fullPageCameraState,
|
|
362
381
|
duration: stillDuration,
|
|
363
382
|
title: errorTitle,
|
|
@@ -365,7 +384,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
365
384
|
imageWidth: (null == (_task_uiContext6 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize6 = _task_uiContext6.shotSize) ? void 0 : _task_uiContext_shotSize6.width) || imageWidth,
|
|
366
385
|
imageHeight: (null == (_task_uiContext7 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize7 = _task_uiContext7.shotSize) ? void 0 : _task_uiContext_shotSize7.height) || imageHeight,
|
|
367
386
|
taskId: currentTaskId
|
|
368
|
-
});
|
|
387
|
+
}, screenshot));
|
|
369
388
|
}
|
|
370
389
|
});
|
|
371
390
|
scripts.push({
|
|
@@ -378,4 +397,4 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
|
|
|
378
397
|
});
|
|
379
398
|
return scripts;
|
|
380
399
|
};
|
|
381
|
-
export { allScriptsFromDump, cameraStateForRect, generateAnimationScripts, mergeTwoCameraState };
|
|
400
|
+
export { allScriptsFromDump, cameraStateForRect, extractDumpMetaInfo, generateAnimationScripts, mergeTwoCameraState };
|