@godscene/visualizer 1.7.11
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/es/component/blackboard/highlights.mjs +47 -0
- package/dist/es/component/blackboard/index.css +118 -0
- package/dist/es/component/blackboard/index.mjs +122 -0
- package/dist/es/component/config-selector/index.mjs +251 -0
- package/dist/es/component/context-preview/index.mjs +37 -0
- package/dist/es/component/env-config/index.mjs +237 -0
- package/dist/es/component/env-config-reminder/index.css +30 -0
- package/dist/es/component/env-config-reminder/index.mjs +27 -0
- package/dist/es/component/form-field/index.mjs +158 -0
- package/dist/es/component/history-selector/index.css +237 -0
- package/dist/es/component/history-selector/index.mjs +197 -0
- package/dist/es/component/index.mjs +1 -0
- package/dist/es/component/logo/index.css +19 -0
- package/dist/es/component/logo/index.mjs +20 -0
- package/dist/es/component/logo/logo.mjs +2 -0
- package/dist/es/component/misc/index.mjs +96 -0
- package/dist/es/component/nav-actions/index.mjs +14 -0
- package/dist/es/component/nav-actions/style.css +35 -0
- package/dist/es/component/player/index.css +296 -0
- package/dist/es/component/player/index.mjs +702 -0
- package/dist/es/component/player/playback-controls.mjs +4 -0
- package/dist/es/component/player/report-download.mjs +61 -0
- package/dist/es/component/player/scenes/StepScene.mjs +194 -0
- package/dist/es/component/player/scenes/derive-frame-state.mjs +229 -0
- package/dist/es/component/player/scenes/export-branded-video.mjs +360 -0
- package/dist/es/component/player/scenes/frame-calculator.mjs +149 -0
- package/dist/es/component/player/scenes/playback-frame.mjs +6 -0
- package/dist/es/component/player/scenes/playback-layout.mjs +12 -0
- package/dist/es/component/player/scenes/pointer-layout.mjs +36 -0
- package/dist/es/component/player/use-frame-player.mjs +87 -0
- package/dist/es/component/playground/index.css +930 -0
- package/dist/es/component/playground/playground-demo-ui-context.json +290 -0
- package/dist/es/component/playground-result/index.css +92 -0
- package/dist/es/component/playground-result/index.mjs +232 -0
- package/dist/es/component/prompt-input/index.css +832 -0
- package/dist/es/component/prompt-input/index.mjs +959 -0
- package/dist/es/component/screenshot-viewer/index.css +237 -0
- package/dist/es/component/screenshot-viewer/index.mjs +319 -0
- package/dist/es/component/service-mode-control/index.mjs +107 -0
- package/dist/es/component/shiny-text/index.css +107 -0
- package/dist/es/component/shiny-text/index.mjs +15 -0
- package/dist/es/component/universal-playground/empty-state.mjs +5 -0
- package/dist/es/component/universal-playground/index.css +619 -0
- package/dist/es/component/universal-playground/index.mjs +558 -0
- package/dist/es/component/universal-playground/providers/context-provider.mjs +90 -0
- package/dist/es/component/universal-playground/providers/indexeddb-storage-provider.mjs +280 -0
- package/dist/es/component/universal-playground/providers/storage-provider.mjs +279 -0
- package/dist/es/component/universal-playground/universal-playground-electron.mjs +668 -0
- package/dist/es/hooks/useMinimalTypeGate.mjs +47 -0
- package/dist/es/hooks/usePlaygroundExecution.mjs +435 -0
- package/dist/es/hooks/usePlaygroundState.mjs +278 -0
- package/dist/es/hooks/useSafeOverrideAIConfig.mjs +20 -0
- package/dist/es/hooks/useServerValid.mjs +55 -0
- package/dist/es/hooks/useTheme.mjs +25 -0
- package/dist/es/icons/action-chevron.mjs +61 -0
- package/dist/es/icons/avatar.mjs +70 -0
- package/dist/es/icons/close.mjs +61 -0
- package/dist/es/icons/global-perspective.mjs +58 -0
- package/dist/es/icons/history.mjs +72 -0
- package/dist/es/icons/magnifying-glass.mjs +81 -0
- package/dist/es/icons/player-setting.mjs +68 -0
- package/dist/es/icons/prompt-history.mjs +70 -0
- package/dist/es/icons/setting.mjs +62 -0
- package/dist/es/icons/show-marker.mjs +58 -0
- package/dist/es/index.mjs +26 -0
- package/dist/es/static/image/logo.png +0 -0
- package/dist/es/store/history.mjs +128 -0
- package/dist/es/store/store.mjs +277 -0
- package/dist/es/types.mjs +73 -0
- package/dist/es/utils/action-label.mjs +15 -0
- package/dist/es/utils/color.mjs +35 -0
- package/dist/es/utils/constants.mjs +99 -0
- package/dist/es/utils/device-capabilities.mjs +13 -0
- package/dist/es/utils/empty-state-scroll.mjs +8 -0
- package/dist/es/utils/highlight-element.mjs +62 -0
- package/dist/es/utils/index.mjs +13 -0
- package/dist/es/utils/playground-utils.mjs +43 -0
- package/dist/es/utils/progress-action-icon.mjs +30 -0
- package/dist/es/utils/prompt-input-utils.mjs +49 -0
- package/dist/es/utils/prompt-placeholder.mjs +19 -0
- package/dist/es/utils/replay-scripts.mjs +428 -0
- package/dist/lib/component/blackboard/highlights.js +84 -0
- package/dist/lib/component/blackboard/index.css +118 -0
- package/dist/lib/component/blackboard/index.js +169 -0
- package/dist/lib/component/config-selector/index.js +295 -0
- package/dist/lib/component/context-preview/index.js +82 -0
- package/dist/lib/component/env-config/index.js +271 -0
- package/dist/lib/component/env-config-reminder/index.css +30 -0
- package/dist/lib/component/env-config-reminder/index.js +61 -0
- package/dist/lib/component/form-field/index.js +204 -0
- package/dist/lib/component/history-selector/index.css +237 -0
- package/dist/lib/component/history-selector/index.js +243 -0
- package/dist/lib/component/index.js +58 -0
- package/dist/lib/component/logo/index.css +19 -0
- package/dist/lib/component/logo/index.js +67 -0
- package/dist/lib/component/logo/logo.js +24 -0
- package/dist/lib/component/misc/index.js +152 -0
- package/dist/lib/component/nav-actions/index.js +48 -0
- package/dist/lib/component/nav-actions/style.css +35 -0
- package/dist/lib/component/player/index.css +296 -0
- package/dist/lib/component/player/index.js +747 -0
- package/dist/lib/component/player/playback-controls.js +38 -0
- package/dist/lib/component/player/report-download.js +98 -0
- package/dist/lib/component/player/scenes/StepScene.js +228 -0
- package/dist/lib/component/player/scenes/derive-frame-state.js +266 -0
- package/dist/lib/component/player/scenes/export-branded-video.js +403 -0
- package/dist/lib/component/player/scenes/frame-calculator.js +186 -0
- package/dist/lib/component/player/scenes/playback-frame.js +40 -0
- package/dist/lib/component/player/scenes/playback-layout.js +46 -0
- package/dist/lib/component/player/scenes/pointer-layout.js +88 -0
- package/dist/lib/component/player/use-frame-player.js +121 -0
- package/dist/lib/component/playground/index.css +930 -0
- package/dist/lib/component/playground/playground-demo-ui-context.json +290 -0
- package/dist/lib/component/playground-result/index.css +92 -0
- package/dist/lib/component/playground-result/index.js +276 -0
- package/dist/lib/component/prompt-input/index.css +832 -0
- package/dist/lib/component/prompt-input/index.js +1005 -0
- package/dist/lib/component/screenshot-viewer/index.css +237 -0
- package/dist/lib/component/screenshot-viewer/index.js +353 -0
- package/dist/lib/component/service-mode-control/index.js +141 -0
- package/dist/lib/component/shiny-text/index.css +107 -0
- package/dist/lib/component/shiny-text/index.js +49 -0
- package/dist/lib/component/universal-playground/empty-state.js +39 -0
- package/dist/lib/component/universal-playground/index.css +619 -0
- package/dist/lib/component/universal-playground/index.js +607 -0
- package/dist/lib/component/universal-playground/providers/context-provider.js +133 -0
- package/dist/lib/component/universal-playground/providers/indexeddb-storage-provider.js +320 -0
- package/dist/lib/component/universal-playground/providers/storage-provider.js +337 -0
- package/dist/lib/component/universal-playground/universal-playground-electron.js +717 -0
- package/dist/lib/hooks/useMinimalTypeGate.js +81 -0
- package/dist/lib/hooks/usePlaygroundExecution.js +478 -0
- package/dist/lib/hooks/usePlaygroundState.js +312 -0
- package/dist/lib/hooks/useSafeOverrideAIConfig.js +57 -0
- package/dist/lib/hooks/useServerValid.js +89 -0
- package/dist/lib/hooks/useTheme.js +59 -0
- package/dist/lib/icons/action-chevron.js +95 -0
- package/dist/lib/icons/avatar.js +104 -0
- package/dist/lib/icons/close.js +95 -0
- package/dist/lib/icons/global-perspective.js +92 -0
- package/dist/lib/icons/history.js +106 -0
- package/dist/lib/icons/magnifying-glass.js +115 -0
- package/dist/lib/icons/player-setting.js +102 -0
- package/dist/lib/icons/prompt-history.js +104 -0
- package/dist/lib/icons/setting.js +96 -0
- package/dist/lib/icons/show-marker.js +92 -0
- package/dist/lib/index.js +204 -0
- package/dist/lib/static/image/logo.png +0 -0
- package/dist/lib/store/history.js +135 -0
- package/dist/lib/store/store.js +287 -0
- package/dist/lib/types.js +119 -0
- package/dist/lib/utils/action-label.js +52 -0
- package/dist/lib/utils/color.js +75 -0
- package/dist/lib/utils/constants.js +172 -0
- package/dist/lib/utils/device-capabilities.js +50 -0
- package/dist/lib/utils/empty-state-scroll.js +42 -0
- package/dist/lib/utils/highlight-element.js +99 -0
- package/dist/lib/utils/index.js +69 -0
- package/dist/lib/utils/playground-utils.js +86 -0
- package/dist/lib/utils/progress-action-icon.js +67 -0
- package/dist/lib/utils/prompt-input-utils.js +89 -0
- package/dist/lib/utils/prompt-placeholder.js +53 -0
- package/dist/lib/utils/replay-scripts.js +474 -0
- package/dist/types/component/blackboard/highlights.d.ts +11 -0
- package/dist/types/component/blackboard/index.d.ts +10 -0
- package/dist/types/component/config-selector/index.d.ts +15 -0
- package/dist/types/component/context-preview/index.d.ts +9 -0
- package/dist/types/component/env-config/index.d.ts +8 -0
- package/dist/types/component/env-config-reminder/index.d.ts +6 -0
- package/dist/types/component/form-field/index.d.ts +17 -0
- package/dist/types/component/history-selector/index.d.ts +13 -0
- package/dist/types/component/index.d.ts +1 -0
- package/dist/types/component/logo/index.d.ts +5 -0
- package/dist/types/component/misc/index.d.ts +6 -0
- package/dist/types/component/nav-actions/index.d.ts +12 -0
- package/dist/types/component/player/index.d.ts +15 -0
- package/dist/types/component/player/playback-controls.d.ts +1 -0
- package/dist/types/component/player/report-download.d.ts +32 -0
- package/dist/types/component/player/scenes/StepScene.d.ts +9 -0
- package/dist/types/component/player/scenes/derive-frame-state.d.ts +40 -0
- package/dist/types/component/player/scenes/export-branded-video.d.ts +33 -0
- package/dist/types/component/player/scenes/frame-calculator.d.ts +40 -0
- package/dist/types/component/player/scenes/playback-frame.d.ts +3 -0
- package/dist/types/component/player/scenes/playback-layout.d.ts +7 -0
- package/dist/types/component/player/scenes/pointer-layout.d.ts +20 -0
- package/dist/types/component/player/use-frame-player.d.ts +17 -0
- package/dist/types/component/playground-result/index.d.ts +22 -0
- package/dist/types/component/prompt-input/index.d.ts +23 -0
- package/dist/types/component/screenshot-viewer/index.d.ts +23 -0
- package/dist/types/component/service-mode-control/index.d.ts +6 -0
- package/dist/types/component/shiny-text/index.d.ts +12 -0
- package/dist/types/component/universal-playground/empty-state.d.ts +3 -0
- package/dist/types/component/universal-playground/index.d.ts +4 -0
- package/dist/types/component/universal-playground/providers/context-provider.d.ts +37 -0
- package/dist/types/component/universal-playground/providers/indexeddb-storage-provider.d.ts +71 -0
- package/dist/types/component/universal-playground/providers/storage-provider.d.ts +58 -0
- package/dist/types/component/universal-playground/universal-playground-electron.d.ts +4 -0
- package/dist/types/hooks/useMinimalTypeGate.d.ts +72 -0
- package/dist/types/hooks/usePlaygroundExecution.d.ts +40 -0
- package/dist/types/hooks/usePlaygroundState.d.ts +26 -0
- package/dist/types/hooks/useSafeOverrideAIConfig.d.ts +16 -0
- package/dist/types/hooks/useServerValid.d.ts +1 -0
- package/dist/types/hooks/useTheme.d.ts +7 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/store/history.d.ts +16 -0
- package/dist/types/store/store.d.ts +57 -0
- package/dist/types/types.d.ts +278 -0
- package/dist/types/utils/action-label.d.ts +11 -0
- package/dist/types/utils/color.d.ts +4 -0
- package/dist/types/utils/constants.d.ts +80 -0
- package/dist/types/utils/device-capabilities.d.ts +9 -0
- package/dist/types/utils/empty-state-scroll.d.ts +11 -0
- package/dist/types/utils/highlight-element.d.ts +3 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/playground-utils.d.ts +11 -0
- package/dist/types/utils/progress-action-icon.d.ts +12 -0
- package/dist/types/utils/prompt-input-utils.d.ts +24 -0
- package/dist/types/utils/prompt-placeholder.d.ts +1 -0
- package/dist/types/utils/replay-scripts.d.ts +50 -0
- package/package.json +82 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
function useMinimalTypeGate(options) {
|
|
3
|
+
const { enabled, form, selectedType, onAfterReset, defaultType = 'aiAct' } = options;
|
|
4
|
+
const [hasExplicitSelection, setHasExplicitSelection] = useState(false);
|
|
5
|
+
const skipNextRestoreRef = useRef(false);
|
|
6
|
+
useEffect(()=>{
|
|
7
|
+
if (!enabled || hasExplicitSelection || !selectedType || selectedType === defaultType) return;
|
|
8
|
+
skipNextRestoreRef.current = false;
|
|
9
|
+
form.setFieldsValue({
|
|
10
|
+
type: defaultType,
|
|
11
|
+
prompt: '',
|
|
12
|
+
params: {}
|
|
13
|
+
});
|
|
14
|
+
null == onAfterReset || onAfterReset();
|
|
15
|
+
}, [
|
|
16
|
+
enabled,
|
|
17
|
+
hasExplicitSelection,
|
|
18
|
+
selectedType,
|
|
19
|
+
defaultType,
|
|
20
|
+
form,
|
|
21
|
+
onAfterReset
|
|
22
|
+
]);
|
|
23
|
+
const markExplicitSelection = useCallback(()=>{
|
|
24
|
+
if (!enabled) return;
|
|
25
|
+
setHasExplicitSelection(true);
|
|
26
|
+
}, [
|
|
27
|
+
enabled
|
|
28
|
+
]);
|
|
29
|
+
const skipNextRestore = useCallback(()=>{
|
|
30
|
+
skipNextRestoreRef.current = true;
|
|
31
|
+
}, []);
|
|
32
|
+
const shouldSkipRestoreOnce = useCallback(()=>{
|
|
33
|
+
if (!skipNextRestoreRef.current) return false;
|
|
34
|
+
skipNextRestoreRef.current = false;
|
|
35
|
+
return true;
|
|
36
|
+
}, []);
|
|
37
|
+
return useMemo(()=>({
|
|
38
|
+
markExplicitSelection,
|
|
39
|
+
skipNextRestore,
|
|
40
|
+
shouldSkipRestoreOnce
|
|
41
|
+
}), [
|
|
42
|
+
markExplicitSelection,
|
|
43
|
+
skipNextRestore,
|
|
44
|
+
shouldSkipRestoreOnce
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
export { useMinimalTypeGate };
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { paramStr, typeStr } from "@godscene/core/agent";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useEnvConfig } from "../store/store.mjs";
|
|
4
|
+
import { BLANK_RESULT } from "../utils/constants.mjs";
|
|
5
|
+
import { allScriptsFromDump } from "../utils/replay-scripts.mjs";
|
|
6
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
7
|
+
try {
|
|
8
|
+
var info = gen[key](arg);
|
|
9
|
+
var value = info.value;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
reject(error);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (info.done) resolve(value);
|
|
15
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
16
|
+
}
|
|
17
|
+
function _async_to_generator(fn) {
|
|
18
|
+
return function() {
|
|
19
|
+
var self = this, args = arguments;
|
|
20
|
+
return new Promise(function(resolve, reject) {
|
|
21
|
+
var gen = fn.apply(self, args);
|
|
22
|
+
function _next(value) {
|
|
23
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
24
|
+
}
|
|
25
|
+
function _throw(err) {
|
|
26
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
27
|
+
}
|
|
28
|
+
_next(void 0);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _define_property(obj, key, value) {
|
|
33
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
else obj[key] = value;
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
function _object_spread(target) {
|
|
43
|
+
for(var i = 1; i < arguments.length; i++){
|
|
44
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
45
|
+
var ownKeys = Object.keys(source);
|
|
46
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
47
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
48
|
+
}));
|
|
49
|
+
ownKeys.forEach(function(key) {
|
|
50
|
+
_define_property(target, key, source[key]);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
function usePlaygroundExecution_ownKeys(object, enumerableOnly) {
|
|
56
|
+
var keys = Object.keys(object);
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
59
|
+
if (enumerableOnly) symbols = symbols.filter(function(sym) {
|
|
60
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
61
|
+
});
|
|
62
|
+
keys.push.apply(keys, symbols);
|
|
63
|
+
}
|
|
64
|
+
return keys;
|
|
65
|
+
}
|
|
66
|
+
function _object_spread_props(target, source) {
|
|
67
|
+
source = null != source ? source : {};
|
|
68
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
69
|
+
else usePlaygroundExecution_ownKeys(Object(source)).forEach(function(key) {
|
|
70
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
71
|
+
});
|
|
72
|
+
return target;
|
|
73
|
+
}
|
|
74
|
+
function formatError(error) {
|
|
75
|
+
var _error_dump;
|
|
76
|
+
if (!error) return '';
|
|
77
|
+
if ('string' == typeof error) return error;
|
|
78
|
+
if (null == error ? void 0 : null == (_error_dump = error.dump) ? void 0 : _error_dump.error) return error.dump.error;
|
|
79
|
+
if (error.message) return String(error.message);
|
|
80
|
+
try {
|
|
81
|
+
return JSON.stringify(error);
|
|
82
|
+
} catch (unused) {
|
|
83
|
+
return String(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function buildProgressContent(task) {
|
|
87
|
+
const action = typeStr(task);
|
|
88
|
+
const description = paramStr(task);
|
|
89
|
+
return description ? `${action} - ${description}` : action;
|
|
90
|
+
}
|
|
91
|
+
function wrapExecutionDumpForReplay(dump, deviceType) {
|
|
92
|
+
return {
|
|
93
|
+
sdkVersion: '',
|
|
94
|
+
groupName: 'Playground Execution',
|
|
95
|
+
modelBriefs: [],
|
|
96
|
+
executions: [
|
|
97
|
+
dump
|
|
98
|
+
],
|
|
99
|
+
deviceType
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function usePlaygroundExecution(options) {
|
|
103
|
+
const { playgroundSDK, storage, actionSpace, loading, setLoading, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef, deviceType } = options;
|
|
104
|
+
const { deepLocate, deepThink, screenshotIncluded, domIncluded, imeStrategy, autoDismissKeyboard, keyboardDismissStrategy, alwaysRefreshScreenInfo } = useEnvConfig();
|
|
105
|
+
const handleRun = useCallback((value)=>_async_to_generator(function*() {
|
|
106
|
+
if (!playgroundSDK) return void console.warn('PlaygroundSDK is not available');
|
|
107
|
+
const thisRunningId = Date.now();
|
|
108
|
+
const actionType = value.type;
|
|
109
|
+
const displayContent = `${value.type}: ${value.prompt || JSON.stringify(value.params)}`;
|
|
110
|
+
const userItem = {
|
|
111
|
+
id: `user-${Date.now()}`,
|
|
112
|
+
type: 'user',
|
|
113
|
+
content: displayContent,
|
|
114
|
+
timestamp: new Date()
|
|
115
|
+
};
|
|
116
|
+
setInfoList((prev)=>[
|
|
117
|
+
...prev,
|
|
118
|
+
userItem
|
|
119
|
+
]);
|
|
120
|
+
setLoading(true);
|
|
121
|
+
const result = _object_spread({}, BLANK_RESULT);
|
|
122
|
+
const systemItem = {
|
|
123
|
+
id: `system-${thisRunningId}`,
|
|
124
|
+
type: 'system',
|
|
125
|
+
content: '',
|
|
126
|
+
timestamp: new Date(),
|
|
127
|
+
loading: true,
|
|
128
|
+
loadingProgressText: ''
|
|
129
|
+
};
|
|
130
|
+
setInfoList((prev)=>[
|
|
131
|
+
...prev,
|
|
132
|
+
systemItem
|
|
133
|
+
]);
|
|
134
|
+
try {
|
|
135
|
+
currentRunningIdRef.current = thisRunningId;
|
|
136
|
+
interruptedFlagRef.current[thisRunningId] = false;
|
|
137
|
+
if (playgroundSDK.onDumpUpdate) playgroundSDK.onDumpUpdate((_, executionDump)=>{
|
|
138
|
+
var _executionDump_tasks;
|
|
139
|
+
if (interruptedFlagRef.current[thisRunningId] || !(null == executionDump ? void 0 : null == (_executionDump_tasks = executionDump.tasks) ? void 0 : _executionDump_tasks.length)) return;
|
|
140
|
+
const progressItems = executionDump.tasks.map((task, index)=>{
|
|
141
|
+
var _task_timing;
|
|
142
|
+
return {
|
|
143
|
+
id: `progress-${thisRunningId}-task-${index}`,
|
|
144
|
+
type: 'progress',
|
|
145
|
+
content: buildProgressContent(task),
|
|
146
|
+
actionKind: typeStr(task),
|
|
147
|
+
timestamp: new Date((null == (_task_timing = task.timing) ? void 0 : _task_timing.start) || Date.now()),
|
|
148
|
+
result: task.error ? {
|
|
149
|
+
error: formatError(task.error),
|
|
150
|
+
result: null
|
|
151
|
+
} : void 0
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
setInfoList((prev)=>{
|
|
155
|
+
const systemItemIndex = prev.findIndex((item)=>item.id === `system-${thisRunningId}`);
|
|
156
|
+
if (-1 === systemItemIndex) return prev;
|
|
157
|
+
const listWithoutCurrentProgress = prev.filter((item)=>!('progress' === item.type && item.id.startsWith(`progress-${thisRunningId}-`)));
|
|
158
|
+
return [
|
|
159
|
+
...listWithoutCurrentProgress.slice(0, systemItemIndex + 1),
|
|
160
|
+
...progressItems,
|
|
161
|
+
...listWithoutCurrentProgress.slice(systemItemIndex + 1)
|
|
162
|
+
];
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
if ('aiAct' !== actionType && true === deepThink) console.warn('[Playground] Non-aiAct action will be executed without deepThink. deepThink is only forwarded for aiAct.', {
|
|
166
|
+
actionType,
|
|
167
|
+
requestId: thisRunningId.toString()
|
|
168
|
+
});
|
|
169
|
+
const resolvedDeepThink = 'unset' === deepThink ? void 0 : deepThink;
|
|
170
|
+
const executionOptions = _object_spread_props(_object_spread({
|
|
171
|
+
requestId: thisRunningId.toString(),
|
|
172
|
+
deepLocate
|
|
173
|
+
}, 'aiAct' === actionType && void 0 !== resolvedDeepThink ? {
|
|
174
|
+
deepThink: resolvedDeepThink
|
|
175
|
+
} : {}), {
|
|
176
|
+
screenshotIncluded,
|
|
177
|
+
domIncluded,
|
|
178
|
+
deviceOptions: {
|
|
179
|
+
imeStrategy,
|
|
180
|
+
autoDismissKeyboard,
|
|
181
|
+
keyboardDismissStrategy,
|
|
182
|
+
alwaysRefreshScreenInfo
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
result.result = yield playgroundSDK.executeAction(actionType, value, executionOptions);
|
|
186
|
+
if ('object' == typeof result.result && null !== result.result) {
|
|
187
|
+
const resultObj = result.result;
|
|
188
|
+
if (resultObj.dump) result.dump = resultObj.dump;
|
|
189
|
+
if (resultObj.reportHTML) result.reportHTML = resultObj.reportHTML;
|
|
190
|
+
if (resultObj.error) result.error = formatError(resultObj.error);
|
|
191
|
+
if ('result' in resultObj) result.result = resultObj.result;
|
|
192
|
+
}
|
|
193
|
+
} catch (e) {
|
|
194
|
+
result.error = formatError(e);
|
|
195
|
+
console.error('Playground execution error:', e);
|
|
196
|
+
if ('object' == typeof e && null !== e) {
|
|
197
|
+
if (e.dump) result.dump = e.dump;
|
|
198
|
+
if (e.reportHTML) result.reportHTML = e.reportHTML;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (interruptedFlagRef.current[thisRunningId]) return;
|
|
202
|
+
setLoading(false);
|
|
203
|
+
currentRunningIdRef.current = null;
|
|
204
|
+
let replayInfo = null;
|
|
205
|
+
let counter = replayCounter;
|
|
206
|
+
if (null == result ? void 0 : result.dump) {
|
|
207
|
+
if (result.dump.tasks && Array.isArray(result.dump.tasks)) {
|
|
208
|
+
const groupedDump = wrapExecutionDumpForReplay(result.dump, deviceType);
|
|
209
|
+
const info = allScriptsFromDump(groupedDump);
|
|
210
|
+
setReplayCounter((c)=>c + 1);
|
|
211
|
+
replayInfo = info;
|
|
212
|
+
counter = replayCounter + 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? _object_spread_props(_object_spread({}, item), {
|
|
216
|
+
content: '',
|
|
217
|
+
loading: false,
|
|
218
|
+
loadingProgressText: ''
|
|
219
|
+
}) : item));
|
|
220
|
+
const resultItem = {
|
|
221
|
+
id: `result-${thisRunningId}`,
|
|
222
|
+
type: 'result',
|
|
223
|
+
content: 'Execution result',
|
|
224
|
+
timestamp: new Date(),
|
|
225
|
+
result: result,
|
|
226
|
+
loading: false,
|
|
227
|
+
replayScriptsInfo: replayInfo,
|
|
228
|
+
replayCounter: counter,
|
|
229
|
+
loadingProgressText: '',
|
|
230
|
+
verticalMode: verticalMode,
|
|
231
|
+
actionType: actionType
|
|
232
|
+
};
|
|
233
|
+
setInfoList((prev)=>[
|
|
234
|
+
...prev,
|
|
235
|
+
resultItem
|
|
236
|
+
]);
|
|
237
|
+
if (null == storage ? void 0 : storage.saveResult) try {
|
|
238
|
+
yield storage.saveResult(resultItem.id, resultItem);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.error('Failed to save result:', error);
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
console.log('result----', result);
|
|
244
|
+
const { tasks, logTime } = result.dump;
|
|
245
|
+
const end = tasks.at(-1).timing.end;
|
|
246
|
+
const totalTime = end - logTime;
|
|
247
|
+
const list = tasks.map((item)=>({
|
|
248
|
+
type: item.type,
|
|
249
|
+
subType: item.subType,
|
|
250
|
+
cost: item.timing.cost
|
|
251
|
+
}));
|
|
252
|
+
console.log('总耗时:', totalTime);
|
|
253
|
+
console.table(list);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(error);
|
|
256
|
+
}
|
|
257
|
+
if (result && result.dump && result.dump.tasks) {
|
|
258
|
+
const thisRunningId = Date.now();
|
|
259
|
+
const tasks = result.dump.tasks || [];
|
|
260
|
+
const actionTasks = tasks.map((item, index)=>{
|
|
261
|
+
if ('Action Space' === item.type) {
|
|
262
|
+
var _tasks__param, _tasks_;
|
|
263
|
+
if ('DragAndDrop' === item.subType) {
|
|
264
|
+
var _tasks__param1, _tasks_1, _tasks__param2, _tasks_2;
|
|
265
|
+
const from = (null == (_tasks_1 = tasks[index - 2]) ? void 0 : null == (_tasks__param1 = _tasks_1.param) ? void 0 : _tasks__param1.prompt) || '';
|
|
266
|
+
const to = (null == (_tasks_2 = tasks[index - 1]) ? void 0 : null == (_tasks__param2 = _tasks_2.param) ? void 0 : _tasks__param2.prompt) || '';
|
|
267
|
+
return _object_spread_props(_object_spread({}, item), {
|
|
268
|
+
param: _object_spread_props(_object_spread({}, item.param), {
|
|
269
|
+
from: _object_spread_props(_object_spread({}, item.param.from), {
|
|
270
|
+
locateDescription: from
|
|
271
|
+
}),
|
|
272
|
+
to: _object_spread_props(_object_spread({}, item.param.to), {
|
|
273
|
+
locateDescription: to
|
|
274
|
+
})
|
|
275
|
+
}),
|
|
276
|
+
output: _object_spread_props(_object_spread({}, item.output), {
|
|
277
|
+
param: _object_spread_props(_object_spread({}, item.output.param), {
|
|
278
|
+
from: _object_spread_props(_object_spread({}, item.output.param.from), {
|
|
279
|
+
locateDescription: from
|
|
280
|
+
}),
|
|
281
|
+
to: _object_spread_props(_object_spread({}, item.output.param.to), {
|
|
282
|
+
locateDescription: to
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return _object_spread_props(_object_spread({}, item), {
|
|
289
|
+
locateDescription: (null == (_tasks_ = tasks[index - 1]) ? void 0 : null == (_tasks__param = _tasks_.param) ? void 0 : _tasks__param.prompt) || ''
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}).filter(Boolean);
|
|
294
|
+
const systemItem = {
|
|
295
|
+
id: `system-${thisRunningId}`,
|
|
296
|
+
type: 'system',
|
|
297
|
+
content: '',
|
|
298
|
+
timestamp: new Date(),
|
|
299
|
+
loading: false,
|
|
300
|
+
loadingProgressText: '',
|
|
301
|
+
actionTasks
|
|
302
|
+
};
|
|
303
|
+
setInfoList((prev)=>[
|
|
304
|
+
...prev,
|
|
305
|
+
systemItem
|
|
306
|
+
]);
|
|
307
|
+
}
|
|
308
|
+
const separatorItem = {
|
|
309
|
+
id: `separator-${thisRunningId}`,
|
|
310
|
+
type: 'separator',
|
|
311
|
+
content: 'New Session',
|
|
312
|
+
timestamp: new Date()
|
|
313
|
+
};
|
|
314
|
+
setInfoList((prev)=>[
|
|
315
|
+
...prev,
|
|
316
|
+
separatorItem
|
|
317
|
+
]);
|
|
318
|
+
return _object_spread_props(_object_spread({}, result), {
|
|
319
|
+
reportHTML: null
|
|
320
|
+
});
|
|
321
|
+
})(), [
|
|
322
|
+
playgroundSDK,
|
|
323
|
+
storage,
|
|
324
|
+
actionSpace,
|
|
325
|
+
setLoading,
|
|
326
|
+
setInfoList,
|
|
327
|
+
replayCounter,
|
|
328
|
+
setReplayCounter,
|
|
329
|
+
verticalMode,
|
|
330
|
+
currentRunningIdRef,
|
|
331
|
+
interruptedFlagRef,
|
|
332
|
+
deepLocate,
|
|
333
|
+
deepThink,
|
|
334
|
+
screenshotIncluded,
|
|
335
|
+
domIncluded,
|
|
336
|
+
deviceType,
|
|
337
|
+
imeStrategy,
|
|
338
|
+
autoDismissKeyboard,
|
|
339
|
+
keyboardDismissStrategy,
|
|
340
|
+
alwaysRefreshScreenInfo
|
|
341
|
+
]);
|
|
342
|
+
const handleStop = useCallback(()=>_async_to_generator(function*() {
|
|
343
|
+
const thisRunningId = currentRunningIdRef.current;
|
|
344
|
+
if (thisRunningId && playgroundSDK && playgroundSDK.cancelExecution) try {
|
|
345
|
+
const cancelResult = yield playgroundSDK.cancelExecution(thisRunningId.toString());
|
|
346
|
+
let executionData = null;
|
|
347
|
+
if (cancelResult) executionData = cancelResult;
|
|
348
|
+
else if (playgroundSDK.getCurrentExecutionData) try {
|
|
349
|
+
executionData = yield playgroundSDK.getCurrentExecutionData();
|
|
350
|
+
} catch (error) {
|
|
351
|
+
console.error('Failed to get execution data before stop:', error);
|
|
352
|
+
}
|
|
353
|
+
interruptedFlagRef.current[thisRunningId] = true;
|
|
354
|
+
setLoading(false);
|
|
355
|
+
if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate(()=>{});
|
|
356
|
+
if (playgroundSDK.onDumpUpdate) playgroundSDK.onDumpUpdate(()=>{});
|
|
357
|
+
setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? _object_spread_props(_object_spread({}, item), {
|
|
358
|
+
content: '',
|
|
359
|
+
loading: false,
|
|
360
|
+
loadingProgressText: ''
|
|
361
|
+
}) : item));
|
|
362
|
+
if (executionData && (executionData.dump || executionData.reportHTML)) {
|
|
363
|
+
var _executionData_dump;
|
|
364
|
+
let replayInfo = null;
|
|
365
|
+
let counter = replayCounter;
|
|
366
|
+
if ((null == (_executionData_dump = executionData.dump) ? void 0 : _executionData_dump.tasks) && Array.isArray(executionData.dump.tasks)) {
|
|
367
|
+
const groupedDump = wrapExecutionDumpForReplay(executionData.dump, deviceType);
|
|
368
|
+
replayInfo = allScriptsFromDump(groupedDump);
|
|
369
|
+
setReplayCounter((c)=>c + 1);
|
|
370
|
+
counter = replayCounter + 1;
|
|
371
|
+
}
|
|
372
|
+
const resultItem = {
|
|
373
|
+
id: `stop-result-${thisRunningId}`,
|
|
374
|
+
type: 'result',
|
|
375
|
+
content: 'Execution stopped by user',
|
|
376
|
+
timestamp: new Date(),
|
|
377
|
+
result: {
|
|
378
|
+
result: null,
|
|
379
|
+
dump: executionData.dump,
|
|
380
|
+
reportHTML: executionData.reportHTML,
|
|
381
|
+
error: null
|
|
382
|
+
},
|
|
383
|
+
loading: false,
|
|
384
|
+
verticalMode,
|
|
385
|
+
replayScriptsInfo: replayInfo,
|
|
386
|
+
replayCounter: counter
|
|
387
|
+
};
|
|
388
|
+
setInfoList((prev)=>[
|
|
389
|
+
...prev,
|
|
390
|
+
resultItem
|
|
391
|
+
]);
|
|
392
|
+
} else {
|
|
393
|
+
const stopItem = {
|
|
394
|
+
id: `stop-${thisRunningId}`,
|
|
395
|
+
type: 'system',
|
|
396
|
+
content: 'Operation stopped',
|
|
397
|
+
timestamp: new Date(),
|
|
398
|
+
loading: false
|
|
399
|
+
};
|
|
400
|
+
setInfoList((prev)=>[
|
|
401
|
+
...prev,
|
|
402
|
+
stopItem
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
const separatorItem = {
|
|
406
|
+
id: `separator-${thisRunningId}`,
|
|
407
|
+
type: 'separator',
|
|
408
|
+
content: 'New Session',
|
|
409
|
+
timestamp: new Date()
|
|
410
|
+
};
|
|
411
|
+
setInfoList((prev)=>[
|
|
412
|
+
...prev,
|
|
413
|
+
separatorItem
|
|
414
|
+
]);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
console.error('Failed to stop execution:', error);
|
|
417
|
+
}
|
|
418
|
+
})(), [
|
|
419
|
+
playgroundSDK,
|
|
420
|
+
currentRunningIdRef,
|
|
421
|
+
interruptedFlagRef,
|
|
422
|
+
setLoading,
|
|
423
|
+
setInfoList,
|
|
424
|
+
verticalMode,
|
|
425
|
+
replayCounter,
|
|
426
|
+
deviceType
|
|
427
|
+
]);
|
|
428
|
+
const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK && !!playgroundSDK.cancelExecution;
|
|
429
|
+
return {
|
|
430
|
+
handleRun,
|
|
431
|
+
handleStop,
|
|
432
|
+
canStop
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
export { buildProgressContent, formatError, usePlaygroundExecution, wrapExecutionDumpForReplay };
|