@midscene/visualizer 0.28.1-beta-20250909063633.0 → 0.28.2-beta-20250909133629.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/browser.mjs +18 -0
- package/dist/es/component/{blackboard.mjs → blackboard/index.mjs} +3 -3
- package/dist/es/component/{playground/ConfigSelector.mjs → config-selector/index.mjs} +2 -3
- package/dist/es/component/{playground/ContextPreview.mjs → context-preview/index.mjs} +3 -4
- package/dist/es/component/{env-config.mjs → env-config/index.mjs} +1 -1
- package/dist/es/component/{github-star.mjs → github-star/index.mjs} +1 -1
- package/dist/es/component/history-selector/index.css +132 -0
- package/dist/es/component/{playground/HistorySelector.mjs → history-selector/index.mjs} +1 -1
- package/dist/es/component/index.mjs +1 -0
- package/dist/es/component/{logo.mjs → logo/index.mjs} +1 -1
- package/dist/es/component/{misc.mjs → misc/index.mjs} +42 -2
- package/dist/es/component/{player.mjs → player/index.mjs} +8 -8
- package/dist/es/component/playground/index.css +29 -161
- package/dist/es/component/playground/index.mjs +8 -0
- package/dist/es/component/playground-result/index.css +29 -0
- package/dist/es/component/{playground/PlaygroundResult.mjs → playground-result/index.mjs} +3 -4
- package/dist/es/component/prompt-input/index.css +330 -0
- package/dist/es/component/{playground/PromptInput.mjs → prompt-input/index.mjs} +9 -9
- package/dist/es/component/{playground/ServiceModeControl.mjs → service-mode-control/index.mjs} +4 -5
- package/dist/es/component/{shiny-text.mjs → shiny-text/index.mjs} +1 -1
- package/dist/es/component/universal-playground/index.css +341 -0
- package/dist/es/component/universal-playground/index.mjs +273 -0
- package/dist/es/component/universal-playground/providers/context-provider.mjs +52 -0
- package/dist/es/component/universal-playground/providers/storage-provider.mjs +107 -0
- package/dist/es/hooks/usePlaygroundExecution.mjs +170 -0
- package/dist/es/hooks/usePlaygroundState.mjs +173 -0
- package/dist/es/icons/avatar.mjs +14 -0
- package/dist/es/index.mjs +22 -18
- package/dist/es/{component/playground/types.mjs → types.mjs} +23 -1
- package/dist/es/{component/playground/playground-constants.mjs → utils/constants.mjs} +1 -2
- package/dist/es/{component/playground → utils}/playground-utils.mjs +1 -1
- package/dist/es/{component → utils}/replay-scripts.mjs +1 -2
- package/dist/lib/browser.js +132 -0
- package/dist/lib/component/{blackboard.js → blackboard/index.js} +5 -5
- package/dist/lib/component/{playground/ConfigSelector.js → config-selector/index.js} +6 -7
- package/dist/lib/component/{playground/ContextPreview.js → context-preview/index.js} +8 -9
- package/dist/lib/component/{env-config.js → env-config/index.js} +1 -1
- package/dist/lib/component/{github-star.js → github-star/index.js} +1 -1
- package/dist/lib/component/history-selector/index.css +132 -0
- package/dist/lib/component/{playground/HistorySelector.js → history-selector/index.js} +1 -1
- package/dist/lib/component/index.js +60 -0
- package/dist/lib/component/{logo.js → logo/index.js} +1 -1
- package/dist/lib/component/{misc.js → misc/index.js} +60 -1
- package/dist/lib/component/{player.js → player/index.js} +23 -23
- package/dist/lib/component/playground/index.css +29 -161
- package/dist/lib/component/playground/index.js +113 -0
- package/dist/lib/component/playground-result/index.css +29 -0
- package/dist/lib/component/{playground/PlaygroundResult.js → playground-result/index.js} +8 -9
- package/dist/lib/component/prompt-input/index.css +330 -0
- package/dist/lib/component/{playground/PromptInput.js → prompt-input/index.js} +37 -37
- package/dist/lib/component/{playground/ServiceModeControl.js → service-mode-control/index.js} +8 -9
- package/dist/lib/component/{shiny-text.js → shiny-text/index.js} +1 -1
- package/dist/lib/component/universal-playground/index.css +341 -0
- package/dist/lib/component/universal-playground/index.js +321 -0
- package/dist/lib/component/universal-playground/providers/context-provider.js +95 -0
- package/dist/lib/component/universal-playground/providers/storage-provider.js +147 -0
- package/dist/lib/hooks/usePlaygroundExecution.js +204 -0
- package/dist/lib/hooks/usePlaygroundState.js +207 -0
- package/dist/lib/{init.js → icons/avatar.js} +16 -12
- package/dist/lib/index.js +66 -34
- package/dist/lib/{component/playground/types.js → types.js} +28 -0
- package/dist/lib/{component/playground/playground-constants.js → utils/constants.js} +3 -4
- package/dist/lib/{component/playground → utils}/playground-utils.js +1 -1
- package/dist/lib/{component → utils}/replay-scripts.js +3 -4
- package/dist/types/browser.d.ts +19 -0
- package/dist/types/component/{blackboard.d.ts → blackboard/index.d.ts} +2 -2
- package/dist/types/component/{playground/ConfigSelector.d.ts → config-selector/index.d.ts} +0 -1
- package/dist/types/component/{playground/ContextPreview.d.ts → context-preview/index.d.ts} +0 -1
- package/dist/types/component/{github-star.d.ts → github-star/index.d.ts} +1 -1
- package/dist/types/component/{playground/HistorySelector.d.ts → history-selector/index.d.ts} +1 -1
- package/dist/types/component/index.d.ts +1 -0
- package/dist/types/component/{logo.d.ts → logo/index.d.ts} +1 -1
- package/dist/types/component/misc/index.d.ts +6 -0
- package/dist/types/component/{player.d.ts → player/index.d.ts} +2 -2
- package/dist/types/component/playground/index.d.ts +7 -0
- package/dist/types/component/{playground/PlaygroundResult.d.ts → playground-result/index.d.ts} +3 -4
- package/dist/types/component/{playground/PromptInput.d.ts → prompt-input/index.d.ts} +3 -2
- package/dist/types/component/{playground/ServiceModeControl.d.ts → service-mode-control/index.d.ts} +0 -1
- package/dist/types/component/{shiny-text.d.ts → shiny-text/index.d.ts} +1 -1
- 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/storage-provider.d.ts +33 -0
- package/dist/types/hooks/usePlaygroundExecution.d.ts +10 -0
- package/dist/types/hooks/usePlaygroundState.d.ts +26 -0
- package/dist/types/index.d.ts +15 -10
- package/dist/types/types.d.ts +166 -0
- package/dist/types/{component/playground/playground-constants.d.ts → utils/constants.d.ts} +0 -1
- package/dist/types/{component → utils}/replay-scripts.d.ts +0 -1
- package/package.json +10 -5
- package/dist/es/component/describer.css +0 -25
- package/dist/es/component/playground/playground-types.mjs +0 -0
- package/dist/es/init.mjs +0 -10
- package/dist/lib/component/describer.css +0 -25
- package/dist/lib/component/playground/playground-types.js +0 -18
- package/dist/types/component/misc.d.ts +0 -2
- package/dist/types/component/playground/playground-types.d.ts +0 -19
- package/dist/types/component/playground/types.d.ts +0 -72
- package/dist/types/init.d.ts +0 -1
- /package/dist/es/component/{blackboard.css → blackboard/index.css} +0 -0
- /package/dist/es/component/{playground/FormField.mjs → form-field/index.mjs} +0 -0
- /package/dist/es/component/{github-star.css → github-star/index.css} +0 -0
- /package/dist/es/component/{logo.css → logo/index.css} +0 -0
- /package/dist/es/component/{player.css → player/index.css} +0 -0
- /package/dist/es/component/{playground-demo-ui-context.json → playground/playground-demo-ui-context.json} +0 -0
- /package/dist/es/component/{shiny-text.css → shiny-text/index.css} +0 -0
- /package/dist/es/{component/playground → hooks}/useServerValid.mjs +0 -0
- /package/dist/es/{component/store → store}/history.mjs +0 -0
- /package/dist/es/{component/store → store}/store.mjs +0 -0
- /package/dist/es/{component → utils}/color.mjs +0 -0
- /package/dist/es/{utils.mjs → utils/index.mjs} +0 -0
- /package/dist/es/{component → utils}/pixi-loader.mjs +0 -0
- /package/dist/lib/component/{blackboard.css → blackboard/index.css} +0 -0
- /package/dist/lib/component/{playground/FormField.js → form-field/index.js} +0 -0
- /package/dist/lib/component/{github-star.css → github-star/index.css} +0 -0
- /package/dist/lib/component/{logo.css → logo/index.css} +0 -0
- /package/dist/lib/component/{player.css → player/index.css} +0 -0
- /package/dist/lib/component/{playground-demo-ui-context.json → playground/playground-demo-ui-context.json} +0 -0
- /package/dist/lib/component/{shiny-text.css → shiny-text/index.css} +0 -0
- /package/dist/lib/{component/playground → hooks}/useServerValid.js +0 -0
- /package/dist/lib/{component/store → store}/history.js +0 -0
- /package/dist/lib/{component/store → store}/store.js +0 -0
- /package/dist/lib/{component → utils}/color.js +0 -0
- /package/dist/lib/{utils.js → utils/index.js} +0 -0
- /package/dist/lib/{component → utils}/pixi-loader.js +0 -0
- /package/dist/types/component/{env-config.d.ts → env-config/index.d.ts} +0 -0
- /package/dist/types/component/{playground/FormField.d.ts → form-field/index.d.ts} +0 -0
- /package/dist/types/{component/playground → hooks}/useServerValid.d.ts +0 -0
- /package/dist/types/{component/store → store}/history.d.ts +0 -0
- /package/dist/types/{component/store → store}/store.d.ts +0 -0
- /package/dist/types/{component → utils}/color.d.ts +0 -0
- /package/dist/types/{utils.d.ts → utils/index.d.ts} +0 -0
- /package/dist/types/{component → utils}/pixi-loader.d.ts +0 -0
- /package/dist/types/{component/playground → utils}/playground-utils.d.ts +0 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
+
value: value,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
});
|
|
8
|
+
else obj[key] = value;
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
class LocalStorageProvider {
|
|
12
|
+
async saveMessages(messages) {
|
|
13
|
+
try {
|
|
14
|
+
const lightMessages = messages.map((msg)=>({
|
|
15
|
+
...msg,
|
|
16
|
+
result: void 0
|
|
17
|
+
}));
|
|
18
|
+
localStorage.setItem(this.messagesKey, JSON.stringify(lightMessages));
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error('Failed to save messages to localStorage:', error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async loadMessages() {
|
|
24
|
+
try {
|
|
25
|
+
const stored = localStorage.getItem(this.messagesKey);
|
|
26
|
+
if (!stored) return [];
|
|
27
|
+
const messages = JSON.parse(stored);
|
|
28
|
+
const restoredMessages = await Promise.all(messages.map(async (msg)=>{
|
|
29
|
+
if ('result' === msg.type && msg.id) {
|
|
30
|
+
const resultKey = `${this.resultsKey}-${msg.id}`;
|
|
31
|
+
const storedResult = localStorage.getItem(resultKey);
|
|
32
|
+
if (storedResult) try {
|
|
33
|
+
const resultItem = JSON.parse(storedResult);
|
|
34
|
+
return {
|
|
35
|
+
...msg,
|
|
36
|
+
...resultItem
|
|
37
|
+
};
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn('Failed to parse stored result:', e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return msg;
|
|
43
|
+
}));
|
|
44
|
+
return restoredMessages;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Failed to load messages from localStorage:', error);
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async clearMessages() {
|
|
51
|
+
try {
|
|
52
|
+
localStorage.removeItem(this.messagesKey);
|
|
53
|
+
const keys = Object.keys(localStorage);
|
|
54
|
+
keys.forEach((key)=>{
|
|
55
|
+
if (key.startsWith(this.resultsKey)) localStorage.removeItem(key);
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('Failed to clear messages from localStorage:', error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async saveResult(id, result) {
|
|
62
|
+
try {
|
|
63
|
+
const resultKey = `${this.resultsKey}-${id}`;
|
|
64
|
+
localStorage.setItem(resultKey, JSON.stringify(result));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Failed to save result to localStorage:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
constructor(namespace = 'playground'){
|
|
70
|
+
_define_property(this, "messagesKey", void 0);
|
|
71
|
+
_define_property(this, "resultsKey", void 0);
|
|
72
|
+
this.messagesKey = `${namespace}-messages`;
|
|
73
|
+
this.resultsKey = `${namespace}-results`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class MemoryStorageProvider {
|
|
77
|
+
async saveMessages(messages) {
|
|
78
|
+
this.messages = [
|
|
79
|
+
...messages
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
async loadMessages() {
|
|
83
|
+
return [
|
|
84
|
+
...this.messages
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
async clearMessages() {
|
|
88
|
+
this.messages = [];
|
|
89
|
+
this.results.clear();
|
|
90
|
+
}
|
|
91
|
+
async saveResult(id, result) {
|
|
92
|
+
this.results.set(id, result);
|
|
93
|
+
}
|
|
94
|
+
constructor(){
|
|
95
|
+
_define_property(this, "messages", []);
|
|
96
|
+
_define_property(this, "results", new Map());
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class NoOpStorageProvider {
|
|
100
|
+
async saveMessages(_messages) {}
|
|
101
|
+
async loadMessages() {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
async clearMessages() {}
|
|
105
|
+
async saveResult(_id, _result) {}
|
|
106
|
+
}
|
|
107
|
+
export { LocalStorageProvider, MemoryStorageProvider, NoOpStorageProvider };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { BLANK_RESULT } from "../types.mjs";
|
|
3
|
+
import { allScriptsFromDump } from "../utils/replay-scripts.mjs";
|
|
4
|
+
const noReplayAPIs = [
|
|
5
|
+
'aiQuery',
|
|
6
|
+
'aiAssert'
|
|
7
|
+
];
|
|
8
|
+
function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, setLoading, infoList, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef) {
|
|
9
|
+
const handleRun = useCallback(async (value)=>{
|
|
10
|
+
Date.now();
|
|
11
|
+
null == actionSpace || actionSpace.find((a)=>a.interfaceAlias === value.type || a.name === value.type);
|
|
12
|
+
const thisRunningId = Date.now();
|
|
13
|
+
const actionType = value.type;
|
|
14
|
+
const displayContent = `${value.type}: ${value.prompt || JSON.stringify(value.params)}`;
|
|
15
|
+
const userItem = {
|
|
16
|
+
id: `user-${Date.now()}`,
|
|
17
|
+
type: 'user',
|
|
18
|
+
content: displayContent,
|
|
19
|
+
timestamp: new Date()
|
|
20
|
+
};
|
|
21
|
+
setInfoList((prev)=>[
|
|
22
|
+
...prev,
|
|
23
|
+
userItem
|
|
24
|
+
]);
|
|
25
|
+
setLoading(true);
|
|
26
|
+
const result = {
|
|
27
|
+
...BLANK_RESULT
|
|
28
|
+
};
|
|
29
|
+
const systemItem = {
|
|
30
|
+
id: `system-${thisRunningId}`,
|
|
31
|
+
type: 'system',
|
|
32
|
+
content: '',
|
|
33
|
+
timestamp: new Date(),
|
|
34
|
+
loading: true,
|
|
35
|
+
loadingProgressText: ''
|
|
36
|
+
};
|
|
37
|
+
setInfoList((prev)=>[
|
|
38
|
+
...prev,
|
|
39
|
+
systemItem
|
|
40
|
+
]);
|
|
41
|
+
try {
|
|
42
|
+
currentRunningIdRef.current = thisRunningId;
|
|
43
|
+
interruptedFlagRef.current[thisRunningId] = false;
|
|
44
|
+
if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate((tip)=>{
|
|
45
|
+
if (interruptedFlagRef.current[thisRunningId]) return;
|
|
46
|
+
const progressItem = {
|
|
47
|
+
id: `progress-${thisRunningId}-${Date.now()}`,
|
|
48
|
+
type: 'progress',
|
|
49
|
+
content: tip,
|
|
50
|
+
timestamp: new Date()
|
|
51
|
+
};
|
|
52
|
+
setInfoList((prev)=>[
|
|
53
|
+
...prev,
|
|
54
|
+
progressItem
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
result.result = await playgroundSDK.executeAction(actionType, value, {
|
|
58
|
+
requestId: thisRunningId.toString()
|
|
59
|
+
});
|
|
60
|
+
if ('object' == typeof result.result && null !== result.result) {
|
|
61
|
+
const resultObj = result.result;
|
|
62
|
+
if (resultObj.dump) result.dump = resultObj.dump;
|
|
63
|
+
if (resultObj.reportHTML) result.reportHTML = resultObj.reportHTML;
|
|
64
|
+
if (resultObj.error) result.error = resultObj.error;
|
|
65
|
+
if (void 0 !== resultObj.result) result.result = resultObj.result;
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
result.error = (null == e ? void 0 : e.message) || String(e);
|
|
69
|
+
console.error('Playground execution error:', e);
|
|
70
|
+
}
|
|
71
|
+
if (interruptedFlagRef.current[thisRunningId]) return;
|
|
72
|
+
setLoading(false);
|
|
73
|
+
currentRunningIdRef.current = null;
|
|
74
|
+
let replayInfo = null;
|
|
75
|
+
let counter = replayCounter;
|
|
76
|
+
if ((null == result ? void 0 : result.dump) && !noReplayAPIs.includes(actionType)) {
|
|
77
|
+
const info = allScriptsFromDump(result.dump);
|
|
78
|
+
setReplayCounter((c)=>c + 1);
|
|
79
|
+
replayInfo = info;
|
|
80
|
+
counter = replayCounter + 1;
|
|
81
|
+
}
|
|
82
|
+
setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? {
|
|
83
|
+
...item,
|
|
84
|
+
content: '',
|
|
85
|
+
loading: false,
|
|
86
|
+
loadingProgressText: ''
|
|
87
|
+
} : item));
|
|
88
|
+
const resultItem = {
|
|
89
|
+
id: `result-${thisRunningId}`,
|
|
90
|
+
type: 'result',
|
|
91
|
+
content: 'Execution result',
|
|
92
|
+
timestamp: new Date(),
|
|
93
|
+
result: result,
|
|
94
|
+
loading: false,
|
|
95
|
+
replayScriptsInfo: replayInfo,
|
|
96
|
+
replayCounter: counter,
|
|
97
|
+
loadingProgressText: '',
|
|
98
|
+
verticalMode: verticalMode
|
|
99
|
+
};
|
|
100
|
+
setInfoList((prev)=>[
|
|
101
|
+
...prev,
|
|
102
|
+
resultItem
|
|
103
|
+
]);
|
|
104
|
+
if (null == storage ? void 0 : storage.saveResult) try {
|
|
105
|
+
await storage.saveResult(resultItem.id, resultItem);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Failed to save result:', error);
|
|
108
|
+
}
|
|
109
|
+
const separatorItem = {
|
|
110
|
+
id: `separator-${thisRunningId}`,
|
|
111
|
+
type: 'separator',
|
|
112
|
+
content: 'New Session',
|
|
113
|
+
timestamp: new Date()
|
|
114
|
+
};
|
|
115
|
+
setInfoList((prev)=>[
|
|
116
|
+
...prev,
|
|
117
|
+
separatorItem
|
|
118
|
+
]);
|
|
119
|
+
}, [
|
|
120
|
+
playgroundSDK,
|
|
121
|
+
storage,
|
|
122
|
+
actionSpace,
|
|
123
|
+
setLoading,
|
|
124
|
+
setInfoList,
|
|
125
|
+
replayCounter,
|
|
126
|
+
setReplayCounter,
|
|
127
|
+
verticalMode,
|
|
128
|
+
currentRunningIdRef,
|
|
129
|
+
interruptedFlagRef
|
|
130
|
+
]);
|
|
131
|
+
const handleStop = useCallback(async ()=>{
|
|
132
|
+
const thisRunningId = currentRunningIdRef.current;
|
|
133
|
+
if (thisRunningId && playgroundSDK.cancelExecution) try {
|
|
134
|
+
await playgroundSDK.cancelExecution(thisRunningId.toString());
|
|
135
|
+
interruptedFlagRef.current[thisRunningId] = true;
|
|
136
|
+
setLoading(false);
|
|
137
|
+
setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` && item.loading ? {
|
|
138
|
+
...item,
|
|
139
|
+
content: 'Operation stopped',
|
|
140
|
+
loading: false,
|
|
141
|
+
loadingProgressText: ''
|
|
142
|
+
} : item));
|
|
143
|
+
const separatorItem = {
|
|
144
|
+
id: `separator-${thisRunningId}`,
|
|
145
|
+
type: 'separator',
|
|
146
|
+
content: 'New Session',
|
|
147
|
+
timestamp: new Date()
|
|
148
|
+
};
|
|
149
|
+
setInfoList((prev)=>[
|
|
150
|
+
...prev,
|
|
151
|
+
separatorItem
|
|
152
|
+
]);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error('Failed to stop execution:', error);
|
|
155
|
+
}
|
|
156
|
+
}, [
|
|
157
|
+
playgroundSDK,
|
|
158
|
+
currentRunningIdRef,
|
|
159
|
+
interruptedFlagRef,
|
|
160
|
+
setLoading,
|
|
161
|
+
setInfoList
|
|
162
|
+
]);
|
|
163
|
+
const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK.cancelExecution;
|
|
164
|
+
return {
|
|
165
|
+
handleRun,
|
|
166
|
+
handleStop,
|
|
167
|
+
canStop
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export { usePlaygroundExecution };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { WELCOME_MESSAGE_TEMPLATE } from "../types.mjs";
|
|
3
|
+
function usePlaygroundState(playgroundSDK, storage, contextProvider) {
|
|
4
|
+
const [loading, setLoading] = useState(false);
|
|
5
|
+
const [infoList, setInfoList] = useState([]);
|
|
6
|
+
const [actionSpace, setActionSpace] = useState([]);
|
|
7
|
+
const [actionSpaceLoading, setActionSpaceLoading] = useState(true);
|
|
8
|
+
const [uiContextPreview, setUiContextPreview] = useState();
|
|
9
|
+
const [showScrollToBottomButton, setShowScrollToBottomButton] = useState(false);
|
|
10
|
+
const [verticalMode, setVerticalMode] = useState(false);
|
|
11
|
+
const [replayCounter, setReplayCounter] = useState(0);
|
|
12
|
+
const infoListRef = useRef(null);
|
|
13
|
+
const currentRunningIdRef = useRef(null);
|
|
14
|
+
const interruptedFlagRef = useRef({});
|
|
15
|
+
const welcomeMessage = {
|
|
16
|
+
...WELCOME_MESSAGE_TEMPLATE,
|
|
17
|
+
id: 'welcome',
|
|
18
|
+
timestamp: new Date()
|
|
19
|
+
};
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
const initializeMessages = async ()=>{
|
|
22
|
+
if (null == storage ? void 0 : storage.loadMessages) try {
|
|
23
|
+
const storedMessages = await storage.loadMessages();
|
|
24
|
+
setInfoList([
|
|
25
|
+
welcomeMessage,
|
|
26
|
+
...storedMessages
|
|
27
|
+
]);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Failed to load messages:', error);
|
|
30
|
+
setInfoList([
|
|
31
|
+
welcomeMessage
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
else setInfoList([
|
|
35
|
+
welcomeMessage
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
initializeMessages();
|
|
39
|
+
}, [
|
|
40
|
+
storage
|
|
41
|
+
]);
|
|
42
|
+
useEffect(()=>{
|
|
43
|
+
if ((null == storage ? void 0 : storage.saveMessages) && infoList.length > 1) storage.saveMessages(infoList).catch((error)=>{
|
|
44
|
+
console.error('Failed to save messages:', error);
|
|
45
|
+
});
|
|
46
|
+
}, [
|
|
47
|
+
infoList,
|
|
48
|
+
storage
|
|
49
|
+
]);
|
|
50
|
+
useEffect(()=>{
|
|
51
|
+
if (!(null == contextProvider ? void 0 : contextProvider.getUIContext) || uiContextPreview) return;
|
|
52
|
+
contextProvider.getUIContext().then((context)=>setUiContextPreview(context)).catch((error)=>{
|
|
53
|
+
console.error('Failed to get UI context:', error);
|
|
54
|
+
});
|
|
55
|
+
}, [
|
|
56
|
+
contextProvider,
|
|
57
|
+
uiContextPreview
|
|
58
|
+
]);
|
|
59
|
+
useEffect(()=>{
|
|
60
|
+
const loadActionSpace = async ()=>{
|
|
61
|
+
setActionSpaceLoading(true);
|
|
62
|
+
try {
|
|
63
|
+
var _contextProvider_getUIContext;
|
|
64
|
+
const context = uiContextPreview || await (null == contextProvider ? void 0 : null == (_contextProvider_getUIContext = contextProvider.getUIContext) ? void 0 : _contextProvider_getUIContext.call(contextProvider));
|
|
65
|
+
const space = await playgroundSDK.getActionSpace(context);
|
|
66
|
+
setActionSpace(space || []);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Failed to load action space:', error);
|
|
69
|
+
setActionSpace([]);
|
|
70
|
+
} finally{
|
|
71
|
+
setActionSpaceLoading(false);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
loadActionSpace();
|
|
75
|
+
}, [
|
|
76
|
+
playgroundSDK,
|
|
77
|
+
uiContextPreview,
|
|
78
|
+
contextProvider
|
|
79
|
+
]);
|
|
80
|
+
useEffect(()=>{
|
|
81
|
+
const sizeThreshold = 750;
|
|
82
|
+
setVerticalMode(window.innerWidth < sizeThreshold);
|
|
83
|
+
const handleResize = ()=>{
|
|
84
|
+
setVerticalMode(window.innerWidth < sizeThreshold);
|
|
85
|
+
};
|
|
86
|
+
window.addEventListener('resize', handleResize);
|
|
87
|
+
return ()=>window.removeEventListener('resize', handleResize);
|
|
88
|
+
}, []);
|
|
89
|
+
const scrollToBottom = useCallback(()=>{
|
|
90
|
+
setTimeout(()=>{
|
|
91
|
+
if (infoListRef.current) infoListRef.current.scrollTop = infoListRef.current.scrollHeight;
|
|
92
|
+
}, 100);
|
|
93
|
+
}, []);
|
|
94
|
+
const checkIfScrolledToBottom = useCallback(()=>{
|
|
95
|
+
if (infoListRef.current) {
|
|
96
|
+
const { scrollTop, scrollHeight, clientHeight } = infoListRef.current;
|
|
97
|
+
const isAtBottom = scrollTop + clientHeight >= scrollHeight - 10;
|
|
98
|
+
setShowScrollToBottomButton(!isAtBottom);
|
|
99
|
+
}
|
|
100
|
+
}, []);
|
|
101
|
+
const handleScrollToBottom = useCallback(()=>{
|
|
102
|
+
if (infoListRef.current) {
|
|
103
|
+
infoListRef.current.scrollTo({
|
|
104
|
+
top: infoListRef.current.scrollHeight,
|
|
105
|
+
behavior: 'smooth'
|
|
106
|
+
});
|
|
107
|
+
setShowScrollToBottomButton(false);
|
|
108
|
+
}
|
|
109
|
+
}, []);
|
|
110
|
+
useEffect(()=>{
|
|
111
|
+
if (infoList.length > 0) scrollToBottom();
|
|
112
|
+
}, [
|
|
113
|
+
infoList,
|
|
114
|
+
scrollToBottom
|
|
115
|
+
]);
|
|
116
|
+
useEffect(()=>{
|
|
117
|
+
const container = infoListRef.current;
|
|
118
|
+
if (container) {
|
|
119
|
+
container.addEventListener('scroll', checkIfScrolledToBottom);
|
|
120
|
+
checkIfScrolledToBottom();
|
|
121
|
+
return ()=>{
|
|
122
|
+
container.removeEventListener('scroll', checkIfScrolledToBottom);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, [
|
|
126
|
+
checkIfScrolledToBottom
|
|
127
|
+
]);
|
|
128
|
+
const clearInfoList = useCallback(async ()=>{
|
|
129
|
+
setInfoList([
|
|
130
|
+
welcomeMessage
|
|
131
|
+
]);
|
|
132
|
+
if (null == storage ? void 0 : storage.clearMessages) try {
|
|
133
|
+
await storage.clearMessages();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('Failed to clear stored messages:', error);
|
|
136
|
+
}
|
|
137
|
+
}, [
|
|
138
|
+
storage,
|
|
139
|
+
welcomeMessage
|
|
140
|
+
]);
|
|
141
|
+
const refreshContext = useCallback(async ()=>{
|
|
142
|
+
if (null == contextProvider ? void 0 : contextProvider.refreshContext) try {
|
|
143
|
+
const newContext = await contextProvider.refreshContext();
|
|
144
|
+
setUiContextPreview(newContext);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('Failed to refresh context:', error);
|
|
147
|
+
}
|
|
148
|
+
}, [
|
|
149
|
+
contextProvider
|
|
150
|
+
]);
|
|
151
|
+
return {
|
|
152
|
+
loading,
|
|
153
|
+
setLoading,
|
|
154
|
+
infoList,
|
|
155
|
+
setInfoList,
|
|
156
|
+
actionSpace,
|
|
157
|
+
actionSpaceLoading,
|
|
158
|
+
uiContextPreview,
|
|
159
|
+
setUiContextPreview,
|
|
160
|
+
showScrollToBottomButton,
|
|
161
|
+
verticalMode,
|
|
162
|
+
replayCounter,
|
|
163
|
+
setReplayCounter,
|
|
164
|
+
infoListRef,
|
|
165
|
+
currentRunningIdRef,
|
|
166
|
+
interruptedFlagRef,
|
|
167
|
+
clearInfoList,
|
|
168
|
+
refreshContext,
|
|
169
|
+
handleScrollToBottom,
|
|
170
|
+
scrollToBottom
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export { usePlaygroundState };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
const SvgAvatar = (props)=>/*#__PURE__*/ jsx("svg", {
|
|
4
|
+
width: 20,
|
|
5
|
+
height: 20,
|
|
6
|
+
fill: "currentColor",
|
|
7
|
+
viewBox: "0 0 24 24",
|
|
8
|
+
...props,
|
|
9
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
10
|
+
d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
const avatar = SvgAvatar;
|
|
14
|
+
export { avatar as default };
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import "./component/playground/index.css";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
|
|
2
|
+
import "./component/universal-playground/index.css";
|
|
3
|
+
import { allScriptsFromDump, generateAnimationScripts } from "./utils/replay-scripts.mjs";
|
|
4
|
+
import { useEnvConfig } from "./store/store.mjs";
|
|
5
|
+
import { colorForName, globalThemeConfig, highlightColorForType } from "./utils/color.mjs";
|
|
6
|
+
import { EnvConfig } from "./component/env-config/index.mjs";
|
|
7
|
+
import { Logo } from "./component/logo/index.mjs";
|
|
8
|
+
import { iconForStatus, timeCostStrElement } from "./component/misc/index.mjs";
|
|
9
|
+
import { useServerValid } from "./hooks/useServerValid.mjs";
|
|
10
|
+
import { PlaygroundResultView } from "./component/playground-result/index.mjs";
|
|
11
|
+
import { ServiceModeControl } from "./component/service-mode-control/index.mjs";
|
|
12
|
+
import { ContextPreview } from "./component/context-preview/index.mjs";
|
|
13
|
+
import { PromptInput } from "./component/prompt-input/index.mjs";
|
|
14
|
+
import { Player } from "./component/player/index.mjs";
|
|
15
|
+
import { Blackboard } from "./component/blackboard/index.mjs";
|
|
16
|
+
import { GithubStar } from "./component/github-star/index.mjs";
|
|
17
|
+
import { actionNameForType, getPlaceholderForType, staticAgentFromContext } from "./utils/playground-utils.mjs";
|
|
18
|
+
import { filterBase64Value, timeStr } from "./utils/index.mjs";
|
|
19
|
+
import shiny_text from "./component/shiny-text/index.mjs";
|
|
20
|
+
import universal_playground, { UniversalPlayground } from "./component/universal-playground/index.mjs";
|
|
21
|
+
import { LocalStorageProvider, MemoryStorageProvider, NoOpStorageProvider } from "./component/universal-playground/providers/storage-provider.mjs";
|
|
22
|
+
import { AgentContextProvider, BaseContextProvider, NoOpContextProvider, StaticContextProvider } from "./component/universal-playground/providers/context-provider.mjs";
|
|
23
|
+
export { AgentContextProvider, BaseContextProvider, Blackboard, ContextPreview, EnvConfig, GithubStar, LocalStorageProvider, Logo, MemoryStorageProvider, NoOpContextProvider, NoOpStorageProvider, Player, PlaygroundResultView, PromptInput, ServiceModeControl, shiny_text as ShinyText, StaticContextProvider, UniversalPlayground, universal_playground as UniversalPlaygroundDefault, actionNameForType, allScriptsFromDump, colorForName, filterBase64Value, generateAnimationScripts, getPlaceholderForType, globalThemeConfig, highlightColorForType, iconForStatus, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useServerValid };
|
|
@@ -67,4 +67,26 @@ const extractDefaultValue = (field)=>{
|
|
|
67
67
|
currentField = currentField._def.innerType;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
const WELCOME_MESSAGE_TEMPLATE = {
|
|
71
|
+
type: 'system',
|
|
72
|
+
content: `
|
|
73
|
+
Welcome to Midscene.js Playground!
|
|
74
|
+
|
|
75
|
+
This is a panel for experimenting and testing Midscene.js features. You can use natural language instructions to operate the web page, such as clicking buttons, filling in forms, querying information, etc.
|
|
76
|
+
|
|
77
|
+
Please enter your instructions in the input box below to start experiencing.
|
|
78
|
+
`,
|
|
79
|
+
loading: false,
|
|
80
|
+
result: void 0,
|
|
81
|
+
replayScriptsInfo: null,
|
|
82
|
+
replayCounter: 0,
|
|
83
|
+
loadingProgressText: '',
|
|
84
|
+
verticalMode: false
|
|
85
|
+
};
|
|
86
|
+
const BLANK_RESULT = {
|
|
87
|
+
result: void 0,
|
|
88
|
+
dump: null,
|
|
89
|
+
reportHTML: null,
|
|
90
|
+
error: null
|
|
91
|
+
};
|
|
92
|
+
export { BLANK_RESULT, VALIDATION_CONSTANTS, WELCOME_MESSAGE_TEMPLATE, extractDefaultValue, isLocateField, isZodObjectSchema, unwrapZodType };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Alert } from "antd";
|
|
3
|
-
import shiny_text from "../shiny-text.mjs";
|
|
4
|
-
import "./index.css";
|
|
3
|
+
import shiny_text from "../component/shiny-text/index.mjs";
|
|
5
4
|
const errorMessageServerNotReady = /*#__PURE__*/ jsxs("span", {
|
|
6
5
|
children: [
|
|
7
6
|
"Don't worry, just one more step to launch the playground server.",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticPage, StaticPageAgent } from "@midscene/web/static";
|
|
2
|
-
import { isZodObjectSchema, unwrapZodType } from "
|
|
2
|
+
import { isZodObjectSchema, unwrapZodType } from "../types.mjs";
|
|
3
3
|
const actionNameForType = (type)=>{
|
|
4
4
|
const typeWithoutAi = type.startsWith('ai') ? type.slice(2) : type;
|
|
5
5
|
const fullName = typeWithoutAi.replace(/([A-Z])/g, ' $1').trim();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import "./
|
|
3
|
-
import { mousePointer } from "../utils.mjs";
|
|
2
|
+
import { mousePointer } from "./index.mjs";
|
|
4
3
|
import { paramStr, typeStr } from "@midscene/core/agent";
|
|
5
4
|
import { treeToList } from "@midscene/shared/extractor";
|
|
6
5
|
const stillDuration = 900;
|