@midscene/visualizer 0.28.2-beta-20250909133629.0 → 0.28.2-beta-20250910021445.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.
Files changed (133) hide show
  1. package/dist/es/component/{blackboard/index.mjs → blackboard.mjs} +3 -3
  2. package/dist/es/component/describer.css +25 -0
  3. package/dist/es/component/{env-config/index.mjs → env-config.mjs} +1 -1
  4. package/dist/es/component/{github-star/index.mjs → github-star.mjs} +1 -1
  5. package/dist/es/component/{logo/index.mjs → logo.mjs} +1 -1
  6. package/dist/es/component/{misc/index.mjs → misc.mjs} +2 -42
  7. package/dist/es/component/{player/index.mjs → player.mjs} +8 -8
  8. package/dist/es/component/{config-selector/index.mjs → playground/ConfigSelector.mjs} +3 -2
  9. package/dist/es/component/{context-preview/index.mjs → playground/ContextPreview.mjs} +4 -3
  10. package/dist/es/component/{history-selector/index.mjs → playground/HistorySelector.mjs} +1 -1
  11. package/dist/es/component/{playground-result/index.mjs → playground/PlaygroundResult.mjs} +4 -3
  12. package/dist/es/component/{prompt-input/index.mjs → playground/PromptInput.mjs} +9 -9
  13. package/dist/es/component/{service-mode-control/index.mjs → playground/ServiceModeControl.mjs} +5 -4
  14. package/dist/es/component/playground/index.css +161 -29
  15. package/dist/es/{utils/constants.mjs → component/playground/playground-constants.mjs} +2 -1
  16. package/dist/es/component/playground/playground-types.mjs +0 -0
  17. package/dist/es/{utils → component/playground}/playground-utils.mjs +1 -1
  18. package/dist/es/{types.mjs → component/playground/types.mjs} +1 -23
  19. package/dist/es/{utils → component}/replay-scripts.mjs +2 -1
  20. package/dist/es/component/{shiny-text/index.mjs → shiny-text.mjs} +1 -1
  21. package/dist/es/index.mjs +18 -22
  22. package/dist/es/init.mjs +10 -0
  23. package/dist/lib/component/{blackboard/index.js → blackboard.js} +5 -5
  24. package/dist/lib/component/describer.css +25 -0
  25. package/dist/lib/component/{env-config/index.js → env-config.js} +1 -1
  26. package/dist/lib/component/{github-star/index.js → github-star.js} +1 -1
  27. package/dist/lib/component/{logo/index.js → logo.js} +1 -1
  28. package/dist/lib/component/{misc/index.js → misc.js} +1 -60
  29. package/dist/lib/component/{player/index.js → player.js} +23 -23
  30. package/dist/lib/component/{config-selector/index.js → playground/ConfigSelector.js} +7 -6
  31. package/dist/lib/component/{context-preview/index.js → playground/ContextPreview.js} +9 -8
  32. package/dist/lib/component/{history-selector/index.js → playground/HistorySelector.js} +1 -1
  33. package/dist/lib/component/{playground-result/index.js → playground/PlaygroundResult.js} +9 -8
  34. package/dist/lib/component/{prompt-input/index.js → playground/PromptInput.js} +37 -37
  35. package/dist/lib/component/{service-mode-control/index.js → playground/ServiceModeControl.js} +9 -8
  36. package/dist/lib/component/playground/index.css +161 -29
  37. package/dist/lib/{utils/constants.js → component/playground/playground-constants.js} +4 -3
  38. package/dist/lib/component/playground/playground-types.js +18 -0
  39. package/dist/lib/{utils → component/playground}/playground-utils.js +1 -1
  40. package/dist/lib/{types.js → component/playground/types.js} +0 -28
  41. package/dist/lib/{utils → component}/replay-scripts.js +4 -3
  42. package/dist/lib/component/{shiny-text/index.js → shiny-text.js} +1 -1
  43. package/dist/lib/index.js +34 -66
  44. package/dist/lib/{icons/avatar.js → init.js} +12 -16
  45. package/dist/types/component/{blackboard/index.d.ts → blackboard.d.ts} +2 -2
  46. package/dist/types/component/{github-star/index.d.ts → github-star.d.ts} +1 -1
  47. package/dist/types/component/{logo/index.d.ts → logo.d.ts} +1 -1
  48. package/dist/types/component/misc.d.ts +2 -0
  49. package/dist/types/component/{player/index.d.ts → player.d.ts} +2 -2
  50. package/dist/types/component/{config-selector/index.d.ts → playground/ConfigSelector.d.ts} +1 -0
  51. package/dist/types/component/{context-preview/index.d.ts → playground/ContextPreview.d.ts} +1 -0
  52. package/dist/types/component/{history-selector/index.d.ts → playground/HistorySelector.d.ts} +1 -1
  53. package/dist/types/component/{playground-result/index.d.ts → playground/PlaygroundResult.d.ts} +4 -3
  54. package/dist/types/component/{prompt-input/index.d.ts → playground/PromptInput.d.ts} +2 -3
  55. package/dist/types/component/{service-mode-control/index.d.ts → playground/ServiceModeControl.d.ts} +1 -0
  56. package/dist/types/{utils/constants.d.ts → component/playground/playground-constants.d.ts} +1 -0
  57. package/dist/types/component/playground/playground-types.d.ts +19 -0
  58. package/dist/types/component/playground/types.d.ts +72 -0
  59. package/dist/types/{utils → component}/replay-scripts.d.ts +1 -0
  60. package/dist/types/component/{shiny-text/index.d.ts → shiny-text.d.ts} +1 -1
  61. package/dist/types/index.d.ts +10 -15
  62. package/dist/types/init.d.ts +1 -0
  63. package/package.json +5 -10
  64. package/dist/es/browser.mjs +0 -18
  65. package/dist/es/component/history-selector/index.css +0 -132
  66. package/dist/es/component/index.mjs +0 -1
  67. package/dist/es/component/playground/index.mjs +0 -8
  68. package/dist/es/component/playground-result/index.css +0 -29
  69. package/dist/es/component/prompt-input/index.css +0 -330
  70. package/dist/es/component/universal-playground/index.css +0 -341
  71. package/dist/es/component/universal-playground/index.mjs +0 -273
  72. package/dist/es/component/universal-playground/providers/context-provider.mjs +0 -52
  73. package/dist/es/component/universal-playground/providers/storage-provider.mjs +0 -107
  74. package/dist/es/hooks/usePlaygroundExecution.mjs +0 -170
  75. package/dist/es/hooks/usePlaygroundState.mjs +0 -173
  76. package/dist/es/icons/avatar.mjs +0 -14
  77. package/dist/lib/browser.js +0 -132
  78. package/dist/lib/component/history-selector/index.css +0 -132
  79. package/dist/lib/component/index.js +0 -60
  80. package/dist/lib/component/playground/index.js +0 -113
  81. package/dist/lib/component/playground-result/index.css +0 -29
  82. package/dist/lib/component/prompt-input/index.css +0 -330
  83. package/dist/lib/component/universal-playground/index.css +0 -341
  84. package/dist/lib/component/universal-playground/index.js +0 -321
  85. package/dist/lib/component/universal-playground/providers/context-provider.js +0 -95
  86. package/dist/lib/component/universal-playground/providers/storage-provider.js +0 -147
  87. package/dist/lib/hooks/usePlaygroundExecution.js +0 -204
  88. package/dist/lib/hooks/usePlaygroundState.js +0 -207
  89. package/dist/types/browser.d.ts +0 -19
  90. package/dist/types/component/index.d.ts +0 -1
  91. package/dist/types/component/misc/index.d.ts +0 -6
  92. package/dist/types/component/playground/index.d.ts +0 -7
  93. package/dist/types/component/universal-playground/index.d.ts +0 -4
  94. package/dist/types/component/universal-playground/providers/context-provider.d.ts +0 -37
  95. package/dist/types/component/universal-playground/providers/storage-provider.d.ts +0 -33
  96. package/dist/types/hooks/usePlaygroundExecution.d.ts +0 -10
  97. package/dist/types/hooks/usePlaygroundState.d.ts +0 -26
  98. package/dist/types/types.d.ts +0 -166
  99. /package/dist/es/component/{blackboard/index.css → blackboard.css} +0 -0
  100. /package/dist/es/{utils → component}/color.mjs +0 -0
  101. /package/dist/es/component/{github-star/index.css → github-star.css} +0 -0
  102. /package/dist/es/component/{logo/index.css → logo.css} +0 -0
  103. /package/dist/es/{utils → component}/pixi-loader.mjs +0 -0
  104. /package/dist/es/component/{player/index.css → player.css} +0 -0
  105. /package/dist/es/component/{form-field/index.mjs → playground/FormField.mjs} +0 -0
  106. /package/dist/es/{hooks → component/playground}/useServerValid.mjs +0 -0
  107. /package/dist/es/component/{playground/playground-demo-ui-context.json → playground-demo-ui-context.json} +0 -0
  108. /package/dist/es/component/{shiny-text/index.css → shiny-text.css} +0 -0
  109. /package/dist/es/{store → component/store}/history.mjs +0 -0
  110. /package/dist/es/{store → component/store}/store.mjs +0 -0
  111. /package/dist/es/{utils/index.mjs → utils.mjs} +0 -0
  112. /package/dist/lib/component/{blackboard/index.css → blackboard.css} +0 -0
  113. /package/dist/lib/{utils → component}/color.js +0 -0
  114. /package/dist/lib/component/{github-star/index.css → github-star.css} +0 -0
  115. /package/dist/lib/component/{logo/index.css → logo.css} +0 -0
  116. /package/dist/lib/{utils → component}/pixi-loader.js +0 -0
  117. /package/dist/lib/component/{player/index.css → player.css} +0 -0
  118. /package/dist/lib/component/{form-field/index.js → playground/FormField.js} +0 -0
  119. /package/dist/lib/{hooks → component/playground}/useServerValid.js +0 -0
  120. /package/dist/lib/component/{playground/playground-demo-ui-context.json → playground-demo-ui-context.json} +0 -0
  121. /package/dist/lib/component/{shiny-text/index.css → shiny-text.css} +0 -0
  122. /package/dist/lib/{store → component/store}/history.js +0 -0
  123. /package/dist/lib/{store → component/store}/store.js +0 -0
  124. /package/dist/lib/{utils/index.js → utils.js} +0 -0
  125. /package/dist/types/{utils → component}/color.d.ts +0 -0
  126. /package/dist/types/component/{env-config/index.d.ts → env-config.d.ts} +0 -0
  127. /package/dist/types/{utils → component}/pixi-loader.d.ts +0 -0
  128. /package/dist/types/component/{form-field/index.d.ts → playground/FormField.d.ts} +0 -0
  129. /package/dist/types/{utils → component/playground}/playground-utils.d.ts +0 -0
  130. /package/dist/types/{hooks → component/playground}/useServerValid.d.ts +0 -0
  131. /package/dist/types/{store → component/store}/history.d.ts +0 -0
  132. /package/dist/types/{store → component/store}/store.d.ts +0 -0
  133. /package/dist/types/{utils/index.d.ts → utils.d.ts} +0 -0
@@ -1,273 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import icons, { ArrowDownOutlined, ClearOutlined, LoadingOutlined } from "@ant-design/icons";
3
- import { Button, Form, List, Tooltip, Typography, message } from "antd";
4
- import { useCallback, useEffect } from "react";
5
- import { usePlaygroundExecution } from "../../hooks/usePlaygroundExecution.mjs";
6
- import { usePlaygroundState } from "../../hooks/usePlaygroundState.mjs";
7
- import { useEnvConfig } from "../../store/store.mjs";
8
- import { ContextPreview } from "../context-preview/index.mjs";
9
- import { PlaygroundResultView } from "../playground-result/index.mjs";
10
- import "./index.css";
11
- import avatar from "../../icons/avatar.mjs";
12
- import { PromptInput } from "../prompt-input/index.mjs";
13
- const { Text } = Typography;
14
- function ErrorMessage(param) {
15
- let { error } = param;
16
- if (!error) return null;
17
- return /*#__PURE__*/ jsxs(Tooltip, {
18
- title: /*#__PURE__*/ jsx("span", {
19
- style: {
20
- whiteSpace: 'pre-wrap',
21
- wordBreak: 'break-all'
22
- },
23
- children: error
24
- }),
25
- overlayStyle: {
26
- maxWidth: '100vw'
27
- },
28
- children: [
29
- "Error: ",
30
- error.split('\n')[0]
31
- ]
32
- });
33
- }
34
- function UniversalPlayground(param) {
35
- let { playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true } = param;
36
- const [form] = Form.useForm();
37
- const { deepThink, screenshotIncluded, domIncluded, config } = useEnvConfig();
38
- const { loading, setLoading, infoList, setInfoList, actionSpace, actionSpaceLoading, uiContextPreview, setUiContextPreview, showScrollToBottomButton, verticalMode, replayCounter, setReplayCounter, infoListRef, currentRunningIdRef, interruptedFlagRef, clearInfoList, refreshContext, handleScrollToBottom } = usePlaygroundState(playgroundSDK, storage, contextProvider);
39
- const { handleRun: executeAction, handleStop, canStop } = usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, setLoading, infoList, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef);
40
- useEffect(()=>{
41
- const completeConfig = {
42
- ...config,
43
- deepThink,
44
- screenshotIncluded,
45
- domIncluded
46
- };
47
- if (playgroundSDK.overrideConfig) playgroundSDK.overrideConfig(completeConfig).catch((error)=>{
48
- console.error('Failed to override SDK config:', error);
49
- });
50
- }, [
51
- playgroundSDK,
52
- config,
53
- deepThink,
54
- screenshotIncluded,
55
- domIncluded
56
- ]);
57
- const handleFormRun = useCallback(async ()=>{
58
- try {
59
- const value = form.getFieldsValue();
60
- await executeAction(value);
61
- } catch (error) {
62
- message.error((null == error ? void 0 : error.message) || 'Execution failed');
63
- }
64
- }, [
65
- form,
66
- executeAction
67
- ]);
68
- const runButtonEnabled = !dryMode && !actionSpaceLoading;
69
- const selectedType = Form.useWatch('type', form);
70
- const finalShowContextPreview = showContextPreview && false !== componentConfig.showContextPreview;
71
- const enablePersistence = false !== componentConfig.enablePersistence;
72
- const layout = componentConfig.layout || 'vertical';
73
- const showVersionInfo = false !== componentConfig.showVersionInfo;
74
- return /*#__PURE__*/ jsx("div", {
75
- className: `playground-container ${layout}-mode ${className}`.trim(),
76
- children: /*#__PURE__*/ jsxs(Form, {
77
- form: form,
78
- onFinish: handleFormRun,
79
- className: "command-form",
80
- children: [
81
- finalShowContextPreview && /*#__PURE__*/ jsx("div", {
82
- className: "context-preview-section",
83
- children: /*#__PURE__*/ jsx(ContextPreview, {
84
- uiContextPreview: uiContextPreview,
85
- setUiContextPreview: setUiContextPreview,
86
- showContextPreview: finalShowContextPreview
87
- })
88
- }),
89
- /*#__PURE__*/ jsxs("div", {
90
- className: "middle-dialog-area",
91
- children: [
92
- infoList.length > 1 && enablePersistence && /*#__PURE__*/ jsx("div", {
93
- className: "clear-button-container",
94
- children: /*#__PURE__*/ jsx(Button, {
95
- size: "small",
96
- icon: /*#__PURE__*/ jsx(ClearOutlined, {}),
97
- onClick: clearInfoList,
98
- type: "text",
99
- className: "clear-button"
100
- })
101
- }),
102
- /*#__PURE__*/ jsx("div", {
103
- ref: infoListRef,
104
- className: "info-list-container",
105
- children: /*#__PURE__*/ jsx(List, {
106
- itemLayout: "vertical",
107
- dataSource: infoList,
108
- renderItem: (item)=>{
109
- var _item_result;
110
- return /*#__PURE__*/ jsx(List.Item, {
111
- className: "list-item",
112
- children: 'user' === item.type ? /*#__PURE__*/ jsx("div", {
113
- className: "user-message-container",
114
- children: /*#__PURE__*/ jsx("div", {
115
- className: "user-message-bubble",
116
- children: item.content
117
- })
118
- }) : 'progress' === item.type ? /*#__PURE__*/ jsx("div", {
119
- children: (()=>{
120
- var _parts_, _item_result, _item_result1, _item_result2;
121
- const parts = item.content.split(' - ');
122
- const action = null == (_parts_ = parts[0]) ? void 0 : _parts_.trim();
123
- const description = parts.slice(1).join(' - ').trim();
124
- const currentIndex = infoList.findIndex((listItem)=>listItem.id === item.id);
125
- const laterProgressExists = infoList.slice(currentIndex + 1).some((listItem)=>'progress' === listItem.type);
126
- const isLatestProgress = !laterProgressExists;
127
- const shouldShowLoading = loading && isLatestProgress;
128
- return /*#__PURE__*/ jsxs(Fragment, {
129
- children: [
130
- action && /*#__PURE__*/ jsxs("span", {
131
- className: "progress-action-item",
132
- children: [
133
- action,
134
- /*#__PURE__*/ jsx("span", {
135
- className: `progress-status-icon ${shouldShowLoading ? 'loading' : (null == (_item_result = item.result) ? void 0 : _item_result.error) ? 'error' : 'completed'}`,
136
- children: shouldShowLoading ? /*#__PURE__*/ jsx(LoadingOutlined, {
137
- spin: true
138
- }) : (null == (_item_result1 = item.result) ? void 0 : _item_result1.error) ? "\u2717" : "\u2713"
139
- })
140
- ]
141
- }),
142
- description && /*#__PURE__*/ jsx("div", {
143
- children: /*#__PURE__*/ jsx("span", {
144
- className: "progress-description",
145
- children: description
146
- })
147
- }),
148
- (null == (_item_result2 = item.result) ? void 0 : _item_result2.error) && /*#__PURE__*/ jsx(ErrorMessage, {
149
- error: item.result.error
150
- })
151
- ]
152
- });
153
- })()
154
- }) : 'separator' === item.type ? /*#__PURE__*/ jsxs("div", {
155
- className: "new-conversation-separator",
156
- children: [
157
- /*#__PURE__*/ jsx("div", {
158
- className: "separator-line"
159
- }),
160
- /*#__PURE__*/ jsx("div", {
161
- className: "separator-text-container",
162
- children: /*#__PURE__*/ jsx(Text, {
163
- type: "secondary",
164
- className: "separator-text",
165
- children: item.content
166
- })
167
- })
168
- ]
169
- }) : /*#__PURE__*/ jsxs("div", {
170
- className: "system-message-container",
171
- children: [
172
- /*#__PURE__*/ jsxs("div", {
173
- className: "system-message-header",
174
- children: [
175
- /*#__PURE__*/ jsx(icons, {
176
- component: branding.icon || avatar,
177
- style: {
178
- fontSize: 20
179
- }
180
- }),
181
- /*#__PURE__*/ jsx("span", {
182
- className: "system-message-title",
183
- children: branding.title || 'Playground'
184
- })
185
- ]
186
- }),
187
- (item.content || item.result) && /*#__PURE__*/ jsxs("div", {
188
- className: "system-message-content",
189
- children: [
190
- 'result' === item.type && (null == (_item_result = item.result) ? void 0 : _item_result.error) && /*#__PURE__*/ jsxs("div", {
191
- className: "error-message",
192
- children: [
193
- /*#__PURE__*/ jsx("div", {
194
- className: "divider"
195
- }),
196
- /*#__PURE__*/ jsx(ErrorMessage, {
197
- error: item.result.error
198
- })
199
- ]
200
- }),
201
- 'result' === item.type ? /*#__PURE__*/ jsx(PlaygroundResultView, {
202
- result: item.result || null,
203
- loading: item.loading || false,
204
- serverValid: true,
205
- serviceMode: 'Server',
206
- replayScriptsInfo: item.replayScriptsInfo || null,
207
- replayCounter: item.replayCounter || 0,
208
- loadingProgressText: item.loadingProgressText || '',
209
- verticalMode: item.verticalMode || false,
210
- fitMode: "width"
211
- }) : /*#__PURE__*/ jsxs(Fragment, {
212
- children: [
213
- /*#__PURE__*/ jsx("div", {
214
- className: "system-message-text",
215
- children: item.content
216
- }),
217
- item.loading && item.loadingProgressText && /*#__PURE__*/ jsx("div", {
218
- className: "loading-progress-text",
219
- children: /*#__PURE__*/ jsx("span", {
220
- children: item.loadingProgressText
221
- })
222
- })
223
- ]
224
- })
225
- ]
226
- })
227
- ]
228
- })
229
- }, item.id);
230
- }
231
- })
232
- }),
233
- showScrollToBottomButton && false !== componentConfig.enableScrollToBottom && /*#__PURE__*/ jsx(Button, {
234
- className: "scroll-to-bottom-button",
235
- type: "primary",
236
- shape: "circle",
237
- icon: /*#__PURE__*/ jsx(ArrowDownOutlined, {}),
238
- onClick: handleScrollToBottom,
239
- size: "large"
240
- })
241
- ]
242
- }),
243
- /*#__PURE__*/ jsx("div", {
244
- className: "bottom-input-section",
245
- children: /*#__PURE__*/ jsx(PromptInput, {
246
- runButtonEnabled: runButtonEnabled,
247
- form: form,
248
- serviceMode: 'Server',
249
- selectedType: selectedType,
250
- dryMode: dryMode,
251
- stoppable: canStop,
252
- loading: loading,
253
- onRun: handleFormRun,
254
- onStop: handleStop,
255
- actionSpace: actionSpace
256
- })
257
- }),
258
- showVersionInfo && branding.version && /*#__PURE__*/ jsx("div", {
259
- className: "version-info-section",
260
- children: /*#__PURE__*/ jsxs("span", {
261
- className: "version-text",
262
- children: [
263
- "Midscene.js version: ",
264
- branding.version
265
- ]
266
- })
267
- })
268
- ]
269
- })
270
- });
271
- }
272
- const universal_playground = UniversalPlayground;
273
- export { UniversalPlayground, universal_playground as default };
@@ -1,52 +0,0 @@
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 BaseContextProvider {
12
- async refreshContext() {
13
- this.cachedContext = void 0;
14
- return await this.getUIContext();
15
- }
16
- constructor(){
17
- _define_property(this, "cachedContext", void 0);
18
- }
19
- }
20
- class AgentContextProvider extends BaseContextProvider {
21
- async getUIContext() {
22
- if (this.cachedContext) return this.cachedContext;
23
- const agent = this.getAgent();
24
- if (!(null == agent ? void 0 : agent.getUIContext)) throw new Error('Agent does not support getUIContext');
25
- const context = await agent.getUIContext();
26
- this.cachedContext = context;
27
- return context;
28
- }
29
- constructor(getAgent, options){
30
- super(), _define_property(this, "getAgent", void 0), _define_property(this, "options", void 0), this.getAgent = getAgent, this.options = options;
31
- }
32
- }
33
- class StaticContextProvider extends BaseContextProvider {
34
- async getUIContext() {
35
- return this.context;
36
- }
37
- async refreshContext() {
38
- return this.context;
39
- }
40
- constructor(context){
41
- super(), _define_property(this, "context", void 0), this.context = context;
42
- }
43
- }
44
- class NoOpContextProvider {
45
- async getUIContext() {
46
- throw new Error('Context preview is disabled');
47
- }
48
- async refreshContext() {
49
- throw new Error('Context preview is disabled');
50
- }
51
- }
52
- export { AgentContextProvider, BaseContextProvider, NoOpContextProvider, StaticContextProvider };
@@ -1,107 +0,0 @@
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 };
@@ -1,170 +0,0 @@
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 };