@midscene/visualizer 0.28.4-beta-20250910153230.0 → 0.28.4

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.
Files changed (134) hide show
  1. package/dist/es/component/{blackboard.mjs → blackboard/index.mjs} +3 -3
  2. package/dist/es/component/{playground/ConfigSelector.mjs → config-selector/index.mjs} +2 -3
  3. package/dist/es/component/{playground/ContextPreview.mjs → context-preview/index.mjs} +3 -4
  4. package/dist/es/component/{env-config.mjs → env-config/index.mjs} +1 -1
  5. package/dist/es/component/{github-star.mjs → github-star/index.mjs} +1 -1
  6. package/dist/es/component/history-selector/index.css +132 -0
  7. package/dist/es/component/{playground/HistorySelector.mjs → history-selector/index.mjs} +1 -1
  8. package/dist/es/component/index.mjs +1 -0
  9. package/dist/es/component/{logo.mjs → logo/index.mjs} +1 -1
  10. package/dist/es/component/{misc.mjs → misc/index.mjs} +42 -2
  11. package/dist/es/component/{player.mjs → player/index.mjs} +8 -8
  12. package/dist/es/component/playground/index.css +35 -161
  13. package/dist/es/component/playground/index.mjs +8 -0
  14. package/dist/es/component/playground-result/index.css +35 -0
  15. package/dist/es/component/{playground/PlaygroundResult.mjs → playground-result/index.mjs} +7 -5
  16. package/dist/es/component/prompt-input/index.css +330 -0
  17. package/dist/es/component/{playground/PromptInput.mjs → prompt-input/index.mjs} +9 -9
  18. package/dist/es/component/{playground/ServiceModeControl.mjs → service-mode-control/index.mjs} +4 -5
  19. package/dist/es/component/{shiny-text.mjs → shiny-text/index.mjs} +1 -1
  20. package/dist/es/component/universal-playground/index.css +341 -0
  21. package/dist/es/component/universal-playground/index.mjs +273 -0
  22. package/dist/es/component/universal-playground/providers/context-provider.mjs +52 -0
  23. package/dist/es/component/universal-playground/providers/storage-provider.mjs +107 -0
  24. package/dist/es/hooks/usePlaygroundExecution.mjs +168 -0
  25. package/dist/es/hooks/usePlaygroundState.mjs +176 -0
  26. package/dist/es/icons/avatar.mjs +28 -0
  27. package/dist/es/index.mjs +22 -18
  28. package/dist/es/{component/playground/playground-constants.mjs → utils/constants.mjs} +23 -43
  29. package/dist/es/{component/playground → utils}/playground-utils.mjs +1 -1
  30. package/dist/es/{component → utils}/replay-scripts.mjs +1 -2
  31. package/dist/lib/component/{blackboard.js → blackboard/index.js} +5 -5
  32. package/dist/lib/component/{playground/ConfigSelector.js → config-selector/index.js} +6 -7
  33. package/dist/lib/component/{playground/ContextPreview.js → context-preview/index.js} +8 -9
  34. package/dist/lib/component/{env-config.js → env-config/index.js} +1 -1
  35. package/dist/lib/component/{github-star.js → github-star/index.js} +1 -1
  36. package/dist/lib/component/history-selector/index.css +132 -0
  37. package/dist/lib/component/{playground/HistorySelector.js → history-selector/index.js} +1 -1
  38. package/dist/lib/component/index.js +60 -0
  39. package/dist/lib/component/{logo.js → logo/index.js} +1 -1
  40. package/dist/lib/component/{misc.js → misc/index.js} +60 -1
  41. package/dist/lib/component/{player.js → player/index.js} +23 -23
  42. package/dist/lib/component/playground/index.css +35 -161
  43. package/dist/lib/component/playground/index.js +113 -0
  44. package/dist/lib/component/playground-result/index.css +35 -0
  45. package/dist/lib/component/{playground/PlaygroundResult.js → playground-result/index.js} +12 -10
  46. package/dist/lib/component/prompt-input/index.css +330 -0
  47. package/dist/lib/component/{playground/PromptInput.js → prompt-input/index.js} +37 -37
  48. package/dist/lib/component/{playground/ServiceModeControl.js → service-mode-control/index.js} +8 -9
  49. package/dist/lib/component/{shiny-text.js → shiny-text/index.js} +1 -1
  50. package/dist/lib/component/universal-playground/index.css +341 -0
  51. package/dist/lib/component/universal-playground/index.js +321 -0
  52. package/dist/lib/component/universal-playground/providers/context-provider.js +95 -0
  53. package/dist/lib/component/universal-playground/providers/storage-provider.js +147 -0
  54. package/dist/lib/hooks/usePlaygroundExecution.js +202 -0
  55. package/dist/lib/hooks/usePlaygroundState.js +210 -0
  56. package/dist/lib/icons/avatar.js +62 -0
  57. package/dist/lib/index.js +66 -34
  58. package/dist/lib/{component/playground/playground-constants.js → utils/constants.js} +31 -64
  59. package/dist/lib/{component/playground → utils}/playground-utils.js +1 -1
  60. package/dist/lib/{component → utils}/replay-scripts.js +3 -4
  61. package/dist/types/component/{blackboard.d.ts → blackboard/index.d.ts} +2 -2
  62. package/dist/types/component/{playground/ConfigSelector.d.ts → config-selector/index.d.ts} +0 -1
  63. package/dist/types/component/{playground/ContextPreview.d.ts → context-preview/index.d.ts} +0 -1
  64. package/dist/types/component/{github-star.d.ts → github-star/index.d.ts} +1 -1
  65. package/dist/types/component/{playground/HistorySelector.d.ts → history-selector/index.d.ts} +1 -1
  66. package/dist/types/component/index.d.ts +1 -0
  67. package/dist/types/component/{logo.d.ts → logo/index.d.ts} +1 -1
  68. package/dist/types/component/misc/index.d.ts +6 -0
  69. package/dist/types/component/{player.d.ts → player/index.d.ts} +2 -2
  70. package/dist/types/component/playground/index.d.ts +7 -0
  71. package/dist/types/component/{playground/PlaygroundResult.d.ts → playground-result/index.d.ts} +3 -4
  72. package/dist/types/component/{playground/PromptInput.d.ts → prompt-input/index.d.ts} +3 -2
  73. package/dist/types/component/{playground/ServiceModeControl.d.ts → service-mode-control/index.d.ts} +0 -1
  74. package/dist/types/component/{shiny-text.d.ts → shiny-text/index.d.ts} +1 -1
  75. package/dist/types/component/universal-playground/index.d.ts +4 -0
  76. package/dist/types/component/universal-playground/providers/context-provider.d.ts +37 -0
  77. package/dist/types/component/universal-playground/providers/storage-provider.d.ts +33 -0
  78. package/dist/types/hooks/usePlaygroundExecution.d.ts +10 -0
  79. package/dist/types/hooks/usePlaygroundState.d.ts +26 -0
  80. package/dist/types/index.d.ts +15 -10
  81. package/dist/types/types.d.ts +164 -0
  82. package/dist/types/{component/playground/playground-constants.d.ts → utils/constants.d.ts} +3 -5
  83. package/dist/types/{component → utils}/replay-scripts.d.ts +0 -1
  84. package/package.json +5 -5
  85. package/dist/es/blank_polyfill.mjs +0 -2
  86. package/dist/es/component/describer.css +0 -25
  87. package/dist/es/component/playground/playground-types.mjs +0 -0
  88. package/dist/es/init.mjs +0 -10
  89. package/dist/lib/blank_polyfill.js +0 -36
  90. package/dist/lib/component/describer.css +0 -25
  91. package/dist/lib/component/playground/playground-types.js +0 -18
  92. package/dist/lib/init.js +0 -44
  93. package/dist/types/blank_polyfill.d.ts +0 -2
  94. package/dist/types/component/misc.d.ts +0 -2
  95. package/dist/types/component/playground/playground-types.d.ts +0 -19
  96. package/dist/types/component/playground/types.d.ts +0 -72
  97. package/dist/types/init.d.ts +0 -1
  98. /package/dist/es/component/{blackboard.css → blackboard/index.css} +0 -0
  99. /package/dist/es/component/{playground/FormField.mjs → form-field/index.mjs} +0 -0
  100. /package/dist/es/component/{github-star.css → github-star/index.css} +0 -0
  101. /package/dist/es/component/{logo.css → logo/index.css} +0 -0
  102. /package/dist/es/component/{player.css → player/index.css} +0 -0
  103. /package/dist/es/component/{playground-demo-ui-context.json → playground/playground-demo-ui-context.json} +0 -0
  104. /package/dist/es/component/{shiny-text.css → shiny-text/index.css} +0 -0
  105. /package/dist/es/{component/playground → hooks}/useServerValid.mjs +0 -0
  106. /package/dist/es/{component/store → store}/history.mjs +0 -0
  107. /package/dist/es/{component/store → store}/store.mjs +0 -0
  108. /package/dist/es/{component/playground/types.mjs → types.mjs} +0 -0
  109. /package/dist/es/{component → utils}/color.mjs +0 -0
  110. /package/dist/es/{utils.mjs → utils/index.mjs} +0 -0
  111. /package/dist/es/{component → utils}/pixi-loader.mjs +0 -0
  112. /package/dist/lib/component/{blackboard.css → blackboard/index.css} +0 -0
  113. /package/dist/lib/component/{playground/FormField.js → form-field/index.js} +0 -0
  114. /package/dist/lib/component/{github-star.css → github-star/index.css} +0 -0
  115. /package/dist/lib/component/{logo.css → logo/index.css} +0 -0
  116. /package/dist/lib/component/{player.css → player/index.css} +0 -0
  117. /package/dist/lib/component/{playground-demo-ui-context.json → playground/playground-demo-ui-context.json} +0 -0
  118. /package/dist/lib/component/{shiny-text.css → shiny-text/index.css} +0 -0
  119. /package/dist/lib/{component/playground → hooks}/useServerValid.js +0 -0
  120. /package/dist/lib/{component/store → store}/history.js +0 -0
  121. /package/dist/lib/{component/store → store}/store.js +0 -0
  122. /package/dist/lib/{component/playground/types.js → types.js} +0 -0
  123. /package/dist/lib/{component → utils}/color.js +0 -0
  124. /package/dist/lib/{utils.js → utils/index.js} +0 -0
  125. /package/dist/lib/{component → utils}/pixi-loader.js +0 -0
  126. /package/dist/types/component/{env-config.d.ts → env-config/index.d.ts} +0 -0
  127. /package/dist/types/component/{playground/FormField.d.ts → form-field/index.d.ts} +0 -0
  128. /package/dist/types/{component/playground → hooks}/useServerValid.d.ts +0 -0
  129. /package/dist/types/{component/store → store}/history.d.ts +0 -0
  130. /package/dist/types/{component/store → store}/store.d.ts +0 -0
  131. /package/dist/types/{component → utils}/color.d.ts +0 -0
  132. /package/dist/types/{utils.d.ts → utils/index.d.ts} +0 -0
  133. /package/dist/types/{component → utils}/pixi-loader.d.ts +0 -0
  134. /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,168 @@
1
+ import { useCallback } from "react";
2
+ import { BLANK_RESULT } from "../utils/constants.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
+ const thisRunningId = Date.now();
11
+ const actionType = value.type;
12
+ const displayContent = `${value.type}: ${value.prompt || JSON.stringify(value.params)}`;
13
+ const userItem = {
14
+ id: `user-${Date.now()}`,
15
+ type: 'user',
16
+ content: displayContent,
17
+ timestamp: new Date()
18
+ };
19
+ setInfoList((prev)=>[
20
+ ...prev,
21
+ userItem
22
+ ]);
23
+ setLoading(true);
24
+ const result = {
25
+ ...BLANK_RESULT
26
+ };
27
+ const systemItem = {
28
+ id: `system-${thisRunningId}`,
29
+ type: 'system',
30
+ content: '',
31
+ timestamp: new Date(),
32
+ loading: true,
33
+ loadingProgressText: ''
34
+ };
35
+ setInfoList((prev)=>[
36
+ ...prev,
37
+ systemItem
38
+ ]);
39
+ try {
40
+ currentRunningIdRef.current = thisRunningId;
41
+ interruptedFlagRef.current[thisRunningId] = false;
42
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate((tip)=>{
43
+ if (interruptedFlagRef.current[thisRunningId]) return;
44
+ const progressItem = {
45
+ id: `progress-${thisRunningId}-${Date.now()}`,
46
+ type: 'progress',
47
+ content: tip,
48
+ timestamp: new Date()
49
+ };
50
+ setInfoList((prev)=>[
51
+ ...prev,
52
+ progressItem
53
+ ]);
54
+ });
55
+ result.result = await playgroundSDK.executeAction(actionType, value, {
56
+ requestId: thisRunningId.toString()
57
+ });
58
+ if ('object' == typeof result.result && null !== result.result) {
59
+ const resultObj = result.result;
60
+ if (resultObj.dump) result.dump = resultObj.dump;
61
+ if (resultObj.reportHTML) result.reportHTML = resultObj.reportHTML;
62
+ if (resultObj.error) result.error = resultObj.error;
63
+ if (void 0 !== resultObj.result) result.result = resultObj.result;
64
+ }
65
+ } catch (e) {
66
+ result.error = (null == e ? void 0 : e.message) || String(e);
67
+ console.error('Playground execution error:', e);
68
+ }
69
+ if (interruptedFlagRef.current[thisRunningId]) return;
70
+ setLoading(false);
71
+ currentRunningIdRef.current = null;
72
+ let replayInfo = null;
73
+ let counter = replayCounter;
74
+ if ((null == result ? void 0 : result.dump) && !noReplayAPIs.includes(actionType)) {
75
+ const info = allScriptsFromDump(result.dump);
76
+ setReplayCounter((c)=>c + 1);
77
+ replayInfo = info;
78
+ counter = replayCounter + 1;
79
+ }
80
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? {
81
+ ...item,
82
+ content: '',
83
+ loading: false,
84
+ loadingProgressText: ''
85
+ } : item));
86
+ const resultItem = {
87
+ id: `result-${thisRunningId}`,
88
+ type: 'result',
89
+ content: 'Execution result',
90
+ timestamp: new Date(),
91
+ result: result,
92
+ loading: false,
93
+ replayScriptsInfo: replayInfo,
94
+ replayCounter: counter,
95
+ loadingProgressText: '',
96
+ verticalMode: verticalMode
97
+ };
98
+ setInfoList((prev)=>[
99
+ ...prev,
100
+ resultItem
101
+ ]);
102
+ if (null == storage ? void 0 : storage.saveResult) try {
103
+ await storage.saveResult(resultItem.id, resultItem);
104
+ } catch (error) {
105
+ console.error('Failed to save result:', error);
106
+ }
107
+ const separatorItem = {
108
+ id: `separator-${thisRunningId}`,
109
+ type: 'separator',
110
+ content: 'New Session',
111
+ timestamp: new Date()
112
+ };
113
+ setInfoList((prev)=>[
114
+ ...prev,
115
+ separatorItem
116
+ ]);
117
+ }, [
118
+ playgroundSDK,
119
+ storage,
120
+ actionSpace,
121
+ setLoading,
122
+ setInfoList,
123
+ replayCounter,
124
+ setReplayCounter,
125
+ verticalMode,
126
+ currentRunningIdRef,
127
+ interruptedFlagRef
128
+ ]);
129
+ const handleStop = useCallback(async ()=>{
130
+ const thisRunningId = currentRunningIdRef.current;
131
+ if (thisRunningId && playgroundSDK.cancelExecution) try {
132
+ await playgroundSDK.cancelExecution(thisRunningId.toString());
133
+ interruptedFlagRef.current[thisRunningId] = true;
134
+ setLoading(false);
135
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` && item.loading ? {
136
+ ...item,
137
+ content: 'Operation stopped',
138
+ loading: false,
139
+ loadingProgressText: ''
140
+ } : item));
141
+ const separatorItem = {
142
+ id: `separator-${thisRunningId}`,
143
+ type: 'separator',
144
+ content: 'New Session',
145
+ timestamp: new Date()
146
+ };
147
+ setInfoList((prev)=>[
148
+ ...prev,
149
+ separatorItem
150
+ ]);
151
+ } catch (error) {
152
+ console.error('Failed to stop execution:', error);
153
+ }
154
+ }, [
155
+ playgroundSDK,
156
+ currentRunningIdRef,
157
+ interruptedFlagRef,
158
+ setLoading,
159
+ setInfoList
160
+ ]);
161
+ const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK.cancelExecution;
162
+ return {
163
+ handleRun,
164
+ handleStop,
165
+ canStop
166
+ };
167
+ }
168
+ export { usePlaygroundExecution };
@@ -0,0 +1,176 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { WELCOME_MESSAGE_TEMPLATE } from "../utils/constants.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
+ useEffect(()=>{
16
+ const initializeMessages = async ()=>{
17
+ const welcomeMessage = {
18
+ ...WELCOME_MESSAGE_TEMPLATE,
19
+ id: 'welcome',
20
+ timestamp: new Date()
21
+ };
22
+ if (null == storage ? void 0 : storage.loadMessages) try {
23
+ const storedMessages = await storage.loadMessages();
24
+ const hasWelcomeMessage = storedMessages.some((msg)=>'welcome' === msg.id);
25
+ hasWelcomeMessage ? setInfoList(storedMessages) : setInfoList([
26
+ welcomeMessage,
27
+ ...storedMessages
28
+ ]);
29
+ } catch (error) {
30
+ console.error('Failed to load messages:', error);
31
+ setInfoList([
32
+ welcomeMessage
33
+ ]);
34
+ }
35
+ else setInfoList([
36
+ welcomeMessage
37
+ ]);
38
+ };
39
+ if (0 === infoList.length) initializeMessages();
40
+ }, []);
41
+ useEffect(()=>{
42
+ if ((null == storage ? void 0 : storage.saveMessages) && infoList.length > 1) storage.saveMessages(infoList).catch((error)=>{
43
+ console.error('Failed to save messages:', error);
44
+ });
45
+ }, [
46
+ infoList,
47
+ storage
48
+ ]);
49
+ useEffect(()=>{
50
+ if (!(null == contextProvider ? void 0 : contextProvider.getUIContext) || uiContextPreview) return;
51
+ contextProvider.getUIContext().then((context)=>setUiContextPreview(context)).catch((error)=>{
52
+ console.error('Failed to get UI context:', error);
53
+ });
54
+ }, [
55
+ contextProvider,
56
+ uiContextPreview
57
+ ]);
58
+ useEffect(()=>{
59
+ const loadActionSpace = async ()=>{
60
+ setActionSpaceLoading(true);
61
+ try {
62
+ var _contextProvider_getUIContext;
63
+ const context = uiContextPreview || await (null == contextProvider ? void 0 : null == (_contextProvider_getUIContext = contextProvider.getUIContext) ? void 0 : _contextProvider_getUIContext.call(contextProvider));
64
+ const space = await playgroundSDK.getActionSpace(context);
65
+ setActionSpace(space || []);
66
+ } catch (error) {
67
+ console.error('Failed to load action space:', error);
68
+ setActionSpace([]);
69
+ } finally{
70
+ setActionSpaceLoading(false);
71
+ }
72
+ };
73
+ loadActionSpace();
74
+ }, [
75
+ playgroundSDK,
76
+ uiContextPreview,
77
+ contextProvider
78
+ ]);
79
+ useEffect(()=>{
80
+ const sizeThreshold = 750;
81
+ setVerticalMode(window.innerWidth < sizeThreshold);
82
+ const handleResize = ()=>{
83
+ setVerticalMode(window.innerWidth < sizeThreshold);
84
+ };
85
+ window.addEventListener('resize', handleResize);
86
+ return ()=>window.removeEventListener('resize', handleResize);
87
+ }, []);
88
+ const scrollToBottom = useCallback(()=>{
89
+ setTimeout(()=>{
90
+ if (infoListRef.current) infoListRef.current.scrollTop = infoListRef.current.scrollHeight;
91
+ }, 100);
92
+ }, []);
93
+ const checkIfScrolledToBottom = useCallback(()=>{
94
+ if (infoListRef.current) {
95
+ const { scrollTop, scrollHeight, clientHeight } = infoListRef.current;
96
+ const isAtBottom = scrollTop + clientHeight >= scrollHeight - 10;
97
+ setShowScrollToBottomButton(!isAtBottom);
98
+ }
99
+ }, []);
100
+ const handleScrollToBottom = useCallback(()=>{
101
+ if (infoListRef.current) {
102
+ infoListRef.current.scrollTo({
103
+ top: infoListRef.current.scrollHeight,
104
+ behavior: 'smooth'
105
+ });
106
+ setShowScrollToBottomButton(false);
107
+ }
108
+ }, []);
109
+ useEffect(()=>{
110
+ if (infoList.length > 0) scrollToBottom();
111
+ }, [
112
+ infoList,
113
+ scrollToBottom
114
+ ]);
115
+ useEffect(()=>{
116
+ const container = infoListRef.current;
117
+ if (container) {
118
+ container.addEventListener('scroll', checkIfScrolledToBottom);
119
+ checkIfScrolledToBottom();
120
+ return ()=>{
121
+ container.removeEventListener('scroll', checkIfScrolledToBottom);
122
+ };
123
+ }
124
+ }, [
125
+ checkIfScrolledToBottom
126
+ ]);
127
+ const clearInfoList = useCallback(async ()=>{
128
+ const welcomeMessage = {
129
+ ...WELCOME_MESSAGE_TEMPLATE,
130
+ id: 'welcome',
131
+ timestamp: new Date()
132
+ };
133
+ setInfoList([
134
+ welcomeMessage
135
+ ]);
136
+ if (null == storage ? void 0 : storage.clearMessages) try {
137
+ await storage.clearMessages();
138
+ } catch (error) {
139
+ console.error('Failed to clear stored messages:', error);
140
+ }
141
+ }, [
142
+ storage
143
+ ]);
144
+ const refreshContext = useCallback(async ()=>{
145
+ if (null == contextProvider ? void 0 : contextProvider.refreshContext) try {
146
+ const newContext = await contextProvider.refreshContext();
147
+ setUiContextPreview(newContext);
148
+ } catch (error) {
149
+ console.error('Failed to refresh context:', error);
150
+ }
151
+ }, [
152
+ contextProvider
153
+ ]);
154
+ return {
155
+ loading,
156
+ setLoading,
157
+ infoList,
158
+ setInfoList,
159
+ actionSpace,
160
+ actionSpaceLoading,
161
+ uiContextPreview,
162
+ setUiContextPreview,
163
+ showScrollToBottomButton,
164
+ verticalMode,
165
+ replayCounter,
166
+ setReplayCounter,
167
+ infoListRef,
168
+ currentRunningIdRef,
169
+ interruptedFlagRef,
170
+ clearInfoList,
171
+ refreshContext,
172
+ handleScrollToBottom,
173
+ scrollToBottom
174
+ };
175
+ }
176
+ export { usePlaygroundState };
@@ -0,0 +1,28 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "react";
3
+ const SvgAvatar = (props)=>/*#__PURE__*/ jsxs("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ width: 20,
6
+ height: 20,
7
+ fill: "none",
8
+ "aria-label": "Playground",
9
+ viewBox: "0 0 20 20",
10
+ ...props,
11
+ children: [
12
+ /*#__PURE__*/ jsx("rect", {
13
+ width: 20,
14
+ height: 20,
15
+ fill: "#2B83FF",
16
+ rx: 10
17
+ }),
18
+ /*#__PURE__*/ jsx("path", {
19
+ fill: "#2B83FF",
20
+ stroke: "#fff",
21
+ strokeLinejoin: "round",
22
+ strokeWidth: 1.125,
23
+ d: "M6.866 5.882a.56.56 0 0 1 .667-.078l3.248 1.875 3.247 1.875a.563.563 0 0 1 0 .974l-3.247 1.875-3.248 1.875a.563.563 0 0 1-.784-.74l1.749-3.497-1.75-3.498a.56.56 0 0 1 .118-.661Z"
24
+ })
25
+ ]
26
+ });
27
+ const avatar = SvgAvatar;
28
+ export { avatar as default };
package/dist/es/index.mjs CHANGED
@@ -1,19 +1,23 @@
1
1
  import "./component/playground/index.css";
2
- import { allScriptsFromDump, generateAnimationScripts } from "./component/replay-scripts.mjs";
3
- import { useEnvConfig } from "./component/store/store.mjs";
4
- import { colorForName, globalThemeConfig, highlightColorForType } from "./component/color.mjs";
5
- import { EnvConfig } from "./component/env-config.mjs";
6
- import { Logo } from "./component/logo.mjs";
7
- import { iconForStatus, timeCostStrElement } from "./component/misc.mjs";
8
- import { useServerValid } from "./component/playground/useServerValid.mjs";
9
- import { PlaygroundResultView } from "./component/playground/PlaygroundResult.mjs";
10
- import { ServiceModeControl } from "./component/playground/ServiceModeControl.mjs";
11
- import { ContextPreview } from "./component/playground/ContextPreview.mjs";
12
- import { PromptInput } from "./component/playground/PromptInput.mjs";
13
- import { Player } from "./component/player.mjs";
14
- import { Blackboard } from "./component/blackboard.mjs";
15
- import { GithubStar } from "./component/github-star.mjs";
16
- import { actionNameForType, getPlaceholderForType, staticAgentFromContext } from "./component/playground/playground-utils.mjs";
17
- import { filterBase64Value, timeStr } from "./utils.mjs";
18
- import shiny_text from "./component/shiny-text.mjs";
19
- export { Blackboard, ContextPreview, EnvConfig, GithubStar, Logo, Player, PlaygroundResultView, PromptInput, ServiceModeControl, shiny_text as ShinyText, actionNameForType, allScriptsFromDump, colorForName, filterBase64Value, generateAnimationScripts, getPlaceholderForType, globalThemeConfig, highlightColorForType, iconForStatus, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useServerValid };
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 };
@@ -1,45 +1,3 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Alert } from "antd";
3
- import shiny_text from "../shiny-text.mjs";
4
- import "./index.css";
5
- const errorMessageServerNotReady = /*#__PURE__*/ jsxs("span", {
6
- children: [
7
- "Don't worry, just one more step to launch the playground server.",
8
- /*#__PURE__*/ jsx("br", {}),
9
- "Please run one of the commands under the midscene project directory:",
10
- /*#__PURE__*/ jsx("br", {}),
11
- "a. ",
12
- /*#__PURE__*/ jsx("strong", {
13
- children: "npx midscene-playground"
14
- }),
15
- /*#__PURE__*/ jsx("br", {}),
16
- "b. ",
17
- /*#__PURE__*/ jsx("strong", {
18
- children: "npx --yes @midscene/web"
19
- })
20
- ]
21
- });
22
- const serverLaunchTip = function() {
23
- let notReadyMessage = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : errorMessageServerNotReady;
24
- return /*#__PURE__*/ jsx("div", {
25
- className: "server-tip",
26
- children: /*#__PURE__*/ jsx(Alert, {
27
- message: "Playground Server Not Ready",
28
- description: notReadyMessage,
29
- type: "warning"
30
- })
31
- });
32
- };
33
- const emptyResultTip = /*#__PURE__*/ jsx("div", {
34
- className: "result-empty-tip",
35
- style: {
36
- textAlign: 'center'
37
- },
38
- children: /*#__PURE__*/ jsx(shiny_text, {
39
- disabled: true,
40
- text: "The result will be shown here"
41
- })
42
- });
43
1
  const trackingTip = 'limit popup to current tab';
44
2
  const deepThinkTip = 'deep think';
45
3
  const screenshotIncludedTip = 'include screenshot in request';
@@ -116,4 +74,26 @@ const defaultMainButtons = [
116
74
  'aiQuery',
117
75
  'aiAssert'
118
76
  ];
119
- export { apiMetadata, deepThinkTip, defaultMainButtons, domIncludedTip, emptyResultTip, errorMessageServerNotReady, screenshotIncludedTip, serverLaunchTip, trackingTip };
77
+ const WELCOME_MESSAGE_TEMPLATE = {
78
+ type: 'system',
79
+ content: `
80
+ Welcome to Midscene.js Playground!
81
+
82
+ 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.
83
+
84
+ Please enter your instructions in the input box below to start experiencing.
85
+ `,
86
+ loading: false,
87
+ result: void 0,
88
+ replayScriptsInfo: null,
89
+ replayCounter: 0,
90
+ loadingProgressText: '',
91
+ verticalMode: false
92
+ };
93
+ const BLANK_RESULT = {
94
+ result: void 0,
95
+ dump: null,
96
+ reportHTML: null,
97
+ error: null
98
+ };
99
+ export { BLANK_RESULT, WELCOME_MESSAGE_TEMPLATE, apiMetadata, deepThinkTip, defaultMainButtons, domIncludedTip, screenshotIncludedTip, trackingTip };
@@ -1,5 +1,5 @@
1
1
  import { StaticPage, StaticPageAgent } from "@midscene/web/static";
2
- import { isZodObjectSchema, unwrapZodType } from "./types.mjs";
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 "./player.css";
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;
@@ -35,17 +35,17 @@ require("pixi.js/unsafe-eval");
35
35
  const external_antd_namespaceObject = require("antd");
36
36
  const external_pixi_js_namespaceObject = require("pixi.js");
37
37
  const external_react_namespaceObject = require("react");
38
- const external_color_js_namespaceObject = require("./color.js");
39
- require("./blackboard.css");
38
+ const color_js_namespaceObject = require("../../utils/color.js");
39
+ require("./index.css");
40
40
  const extractor_namespaceObject = require("@midscene/shared/extractor");
41
41
  const external_pixi_filters_namespaceObject = require("pixi-filters");
42
- const store_js_namespaceObject = require("./store/store.js");
42
+ const store_js_namespaceObject = require("../../store/store.js");
43
43
  const itemFillAlpha = 0.4;
44
44
  const highlightAlpha = 0.4;
45
45
  const pointRadius = 10;
46
46
  const pointMarkForItem = (point, type)=>{
47
47
  const [x, y] = point;
48
- const themeColor = (0, external_color_js_namespaceObject.highlightColorForType)('element');
48
+ const themeColor = (0, color_js_namespaceObject.highlightColorForType)('element');
49
49
  const graphics = new external_pixi_js_namespaceObject.Graphics();
50
50
  graphics.beginFill(themeColor, itemFillAlpha);
51
51
  graphics.drawCircle(x, y, pointRadius);
@@ -55,7 +55,7 @@ const pointMarkForItem = (point, type)=>{
55
55
  const rectMarkForItem = (rect, name, type)=>{
56
56
  const { left, top, width, height } = rect;
57
57
  let themeColor;
58
- themeColor = 'element' === type ? (0, external_color_js_namespaceObject.colorForName)(name) : 'searchArea' === type ? (0, external_color_js_namespaceObject.highlightColorForType)('searchArea') : (0, external_color_js_namespaceObject.highlightColorForType)('element');
58
+ themeColor = 'element' === type ? (0, color_js_namespaceObject.colorForName)(name) : 'searchArea' === type ? (0, color_js_namespaceObject.highlightColorForType)('searchArea') : (0, color_js_namespaceObject.highlightColorForType)('element');
59
59
  const alpha = 'highlight' === type ? highlightAlpha : itemFillAlpha;
60
60
  const graphics = new external_pixi_js_namespaceObject.Graphics();
61
61
  graphics.beginFill(themeColor, alpha);