@rpascene/visualizer 0.30.16 → 0.30.18

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.
@@ -12,7 +12,7 @@ import { BooleanField, EnumField, LocateField, NumberField, TextField } from "..
12
12
  import { HistorySelector } from "../history-selector/index.mjs";
13
13
  const { TextArea } = Input;
14
14
  const PromptInput = (param)=>{
15
- let { runButtonEnabled, form, serviceMode, selectedType, dryMode, stoppable, loading, onRun, onStop, clearPromptAfterRun = true, actionSpace, hideDomAndScreenshotOptions = false } = param;
15
+ let { runButtonEnabled, form, serviceMode, selectedType, dryMode, stoppable, loading, onRun, onStop, clearPromptAfterRun = true, actionSpace, hideDomAndScreenshotOptions = false, defaultSelectedType } = param;
16
16
  const [hoveringSettings, setHoveringSettings] = useState(false);
17
17
  const [promptValue, setPromptValue] = useState('');
18
18
  const placeholder = getPlaceholderForType(selectedType);
@@ -149,9 +149,13 @@ const PromptInput = (param)=>{
149
149
  actionSpace
150
150
  ]);
151
151
  useEffect(()=>{
152
- if (!form.getFieldValue('type') && lastSelectedType) form.setFieldValue('type', lastSelectedType);
152
+ if (!form.getFieldValue('type')) {
153
+ if (defaultSelectedType) form.setFieldValue('type', defaultSelectedType);
154
+ else if (lastSelectedType) form.setFieldValue('type', lastSelectedType);
155
+ }
153
156
  }, [
154
157
  form,
158
+ defaultSelectedType,
155
159
  lastSelectedType
156
160
  ]);
157
161
  useEffect(()=>{
@@ -183,28 +187,15 @@ const PromptInput = (param)=>{
183
187
  }
184
188
  }, []);
185
189
  useEffect(()=>{
186
- const lastHistory = historyForSelectedType[0];
187
- if (lastHistory && lastHistoryRef.current && lastHistory.timestamp === lastHistoryRef.current.timestamp) return;
188
- if (lastHistory) {
189
- form.setFieldsValue({
190
- type: lastHistory.type,
191
- prompt: lastHistory.prompt || '',
192
- params: lastHistory.params
193
- });
194
- setPromptValue(lastHistory.prompt || '');
195
- lastHistoryRef.current = lastHistory;
196
- } else {
197
- const defaultParams = getDefaultParams();
198
- form.setFieldsValue({
199
- prompt: '',
200
- params: defaultParams
201
- });
202
- setPromptValue('');
203
- lastHistoryRef.current = null;
204
- }
190
+ const defaultParams = getDefaultParams();
191
+ form.setFieldsValue({
192
+ prompt: '',
193
+ params: defaultParams
194
+ });
195
+ setPromptValue('');
205
196
  }, [
206
197
  selectedType,
207
- historyForSelectedType,
198
+ setPromptValue,
208
199
  form,
209
200
  getDefaultParams
210
201
  ]);
@@ -42,7 +42,7 @@ function ErrorMessage(param) {
42
42
  });
43
43
  }
44
44
  function UniversalPlayground(param) {
45
- let { playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true, showPromptInput = true, onHumanUse = ()=>{}, showHumanUse = false } = param;
45
+ let { playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true, showPromptInput = true, onHumanUse = ()=>{}, showHumanUse = false, defaultSelectedType } = param;
46
46
  const [form] = Form.useForm();
47
47
  const { config } = useEnvConfig();
48
48
  const [sdkReady, setSdkReady] = useState(false);
@@ -85,11 +85,6 @@ function UniversalPlayground(param) {
85
85
  playgroundSDK,
86
86
  config
87
87
  ]);
88
- useEffect(()=>{
89
- form.setFieldValue('type', 'aiTap');
90
- }, [
91
- form
92
- ]);
93
88
  const handleFormRun = useCallback(async ()=>{
94
89
  try {
95
90
  const value = form.getFieldsValue();
@@ -144,6 +139,12 @@ function UniversalPlayground(param) {
144
139
  canStop,
145
140
  handleStop
146
141
  ]);
142
+ useEffect(()=>{
143
+ if (defaultSelectedType && !showPromptInput) form.setFieldValue('type', defaultSelectedType);
144
+ }, [
145
+ defaultSelectedType,
146
+ showPromptInput
147
+ ]);
147
148
  return /*#__PURE__*/ jsx("div", {
148
149
  id: "playground-container",
149
150
  className: `playground-container ${layout}-mode ${className}`.trim(),
@@ -152,9 +153,6 @@ function UniversalPlayground(param) {
152
153
  form: form,
153
154
  onFinish: handleFormRun,
154
155
  className: "command-form",
155
- initialValues: {
156
- type: 'aiTap'
157
- },
158
156
  children: [
159
157
  finalShowContextPreview && /*#__PURE__*/ jsx("div", {
160
158
  className: "context-preview-section",
@@ -413,7 +411,7 @@ function UniversalPlayground(param) {
413
411
  ]
414
412
  }),
415
413
  /*#__PURE__*/ jsx("div", {
416
- className: "bottom-input-section aaa",
414
+ className: "bottom-input-section",
417
415
  children: showPromptInput && /*#__PURE__*/ jsx(PromptInput, {
418
416
  runButtonEnabled: runButtonEnabled,
419
417
  form: form,
@@ -424,7 +422,8 @@ function UniversalPlayground(param) {
424
422
  loading: loading,
425
423
  onRun: handleFormRun,
426
424
  onStop: handleStop,
427
- actionSpace: actionSpace
425
+ actionSpace: actionSpace,
426
+ defaultSelectedType: defaultSelectedType
428
427
  })
429
428
  }),
430
429
  showVersionInfo && branding.version && /*#__PURE__*/ jsx("div", {
@@ -0,0 +1,327 @@
1
+ import { useCallback, useRef } from "react";
2
+ import { useEnvConfig } from "../store/store.mjs";
3
+ import { noReplayAPIs } from "@rpascene/playground";
4
+ import { BLANK_RESULT } from "../utils/constants.mjs";
5
+ import { allScriptsFromDump } from "../utils/replay-scripts.mjs";
6
+ function _define_property(obj, key, value) {
7
+ if (key in obj) Object.defineProperty(obj, key, {
8
+ value: value,
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true
12
+ });
13
+ else obj[key] = value;
14
+ return obj;
15
+ }
16
+ class TaskNode {
17
+ constructor(taskId, prompt, next = null){
18
+ _define_property(this, "taskId", void 0);
19
+ _define_property(this, "prompt", void 0);
20
+ _define_property(this, "next", void 0);
21
+ _define_property(this, "result", void 0);
22
+ _define_property(this, "status", void 0);
23
+ this.taskId = taskId;
24
+ this.prompt = prompt;
25
+ this.next = next;
26
+ this.result = null;
27
+ this.status = 'pending';
28
+ }
29
+ }
30
+ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, setLoading, infoList, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef, showHumanUse) {
31
+ const toBeUsedRef = useRef([]);
32
+ const isCancelledRef = useRef(false);
33
+ const currentNodeRef = useRef();
34
+ const { deepThink, screenshotIncluded, domIncluded } = useEnvConfig();
35
+ const setUsedInfoList = ()=>{
36
+ if (toBeUsedRef.current.length > 0) {
37
+ const thisRunningId = Date.now();
38
+ const systemItem = {
39
+ id: `system-${thisRunningId}`,
40
+ type: 'system',
41
+ content: '',
42
+ timestamp: new Date(),
43
+ loading: false,
44
+ loadingProgressText: '',
45
+ actionTasks: toBeUsedRef.current
46
+ };
47
+ setInfoList((prev)=>[
48
+ ...prev,
49
+ systemItem
50
+ ]);
51
+ toBeUsedRef.current = [];
52
+ }
53
+ };
54
+ const handleRun = useCallback(async (value)=>{
55
+ console.log(value, "\u5728\u8FD9\u91CC\u5206\u5272value\uFF0C\u4E32\u884C\u6267\u884C\uFF0Cvalue-----------------------");
56
+ if (!playgroundSDK) return void console.warn('PlaygroundSDK is not available');
57
+ const executeTask = async (value)=>{
58
+ var _result_dump_executions_, _result_dump_executions;
59
+ const thisRunningId = Date.now();
60
+ const actionType = value.type;
61
+ const sub = value.prompt || value.params ? value.prompt || JSON.stringify(value.params) : '';
62
+ const displayContent = sub ? `${value.type}: ${sub}` : value.type;
63
+ const userItem = {
64
+ id: `user-${Date.now()}`,
65
+ type: 'user',
66
+ content: displayContent,
67
+ timestamp: new Date()
68
+ };
69
+ setInfoList((prev)=>[
70
+ ...prev,
71
+ userItem
72
+ ]);
73
+ setLoading(true);
74
+ const result = {
75
+ ...BLANK_RESULT
76
+ };
77
+ const systemItem = {
78
+ id: `system-${thisRunningId}`,
79
+ type: 'system',
80
+ content: '',
81
+ timestamp: new Date(),
82
+ loading: true,
83
+ loadingProgressText: ''
84
+ };
85
+ setInfoList((prev)=>[
86
+ ...prev,
87
+ systemItem
88
+ ]);
89
+ try {
90
+ currentRunningIdRef.current = thisRunningId;
91
+ interruptedFlagRef.current[thisRunningId] = false;
92
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate(()=>{});
93
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate((tip)=>{
94
+ if (interruptedFlagRef.current[thisRunningId]) return;
95
+ setInfoList((prev)=>{
96
+ const lastItem = prev[prev.length - 1];
97
+ if (lastItem && 'progress' === lastItem.type && lastItem.content === tip) return prev;
98
+ const progressItem = {
99
+ id: `progress-${thisRunningId}-${Date.now()}`,
100
+ type: 'progress',
101
+ content: tip,
102
+ timestamp: new Date()
103
+ };
104
+ return [
105
+ ...prev,
106
+ progressItem
107
+ ];
108
+ });
109
+ });
110
+ result.result = await playgroundSDK.executeAction(actionType, value, {
111
+ requestId: thisRunningId.toString(),
112
+ deepThink,
113
+ screenshotIncluded,
114
+ domIncluded
115
+ });
116
+ if ('object' == typeof result.result && null !== result.result) {
117
+ const resultObj = result.result;
118
+ if (resultObj.dump) result.dump = resultObj.dump;
119
+ if (resultObj.reportHTML) result.reportHTML = resultObj.reportHTML;
120
+ if (resultObj.error) result.error = resultObj.error;
121
+ if (void 0 !== resultObj.result) result.result = resultObj.result;
122
+ }
123
+ } catch (e) {
124
+ result.error = (null == e ? void 0 : e.message) || String(e);
125
+ console.error('Playground execution error:', result);
126
+ }
127
+ if (interruptedFlagRef.current[thisRunningId]) return;
128
+ setLoading(false);
129
+ currentRunningIdRef.current = null;
130
+ let replayInfo = null;
131
+ let counter = replayCounter;
132
+ if ((null == result ? void 0 : result.dump) && !noReplayAPIs.includes(actionType)) {
133
+ const info = allScriptsFromDump(result.dump);
134
+ setReplayCounter((c)=>c + 1);
135
+ replayInfo = info;
136
+ counter = replayCounter + 1;
137
+ }
138
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? {
139
+ ...item,
140
+ content: '',
141
+ loading: false,
142
+ loadingProgressText: ''
143
+ } : item));
144
+ const resultItem = {
145
+ id: `result-${thisRunningId}`,
146
+ type: 'result',
147
+ content: 'Execution result',
148
+ timestamp: new Date(),
149
+ result: result,
150
+ loading: false,
151
+ replayScriptsInfo: replayInfo,
152
+ replayCounter: counter,
153
+ loadingProgressText: '',
154
+ verticalMode: verticalMode
155
+ };
156
+ setInfoList((prev)=>[
157
+ ...prev,
158
+ resultItem
159
+ ]);
160
+ if (null == storage ? void 0 : storage.saveResult) try {
161
+ await storage.saveResult(resultItem.id, resultItem);
162
+ } catch (error) {
163
+ console.error('Failed to save result:', error);
164
+ }
165
+ if (showHumanUse && result && result.dump && (null == (_result_dump_executions = result.dump.executions) ? void 0 : null == (_result_dump_executions_ = _result_dump_executions[0]) ? void 0 : _result_dump_executions_.tasks)) {
166
+ var _result_dump_executions_1, _result_dump_executions1, _result_dump;
167
+ const tasks = (null == result ? void 0 : null == (_result_dump = result.dump) ? void 0 : null == (_result_dump_executions1 = _result_dump.executions) ? void 0 : null == (_result_dump_executions_1 = _result_dump_executions1[0]) ? void 0 : _result_dump_executions_1.tasks) || [];
168
+ const actionTasks = tasks.map((item, index)=>{
169
+ if ('Action' === item.type) {
170
+ var _tasks__param, _tasks_;
171
+ if ('DragAndDrop' === item.subType) {
172
+ var _tasks__param1, _tasks_1, _tasks__param2, _tasks_2;
173
+ const from = (null == (_tasks_1 = tasks[index - 2]) ? void 0 : null == (_tasks__param1 = _tasks_1.param) ? void 0 : _tasks__param1.prompt) || '';
174
+ const to = (null == (_tasks_2 = tasks[index - 1]) ? void 0 : null == (_tasks__param2 = _tasks_2.param) ? void 0 : _tasks__param2.prompt) || '';
175
+ return {
176
+ ...item,
177
+ param: {
178
+ ...item.param,
179
+ from: {
180
+ ...item.param.from,
181
+ locateDescription: from
182
+ },
183
+ to: {
184
+ ...item.param.to,
185
+ locateDescription: to
186
+ }
187
+ },
188
+ output: {
189
+ ...item.output,
190
+ param: {
191
+ ...item.output.param,
192
+ from: {
193
+ ...item.output.param.from,
194
+ locateDescription: from
195
+ },
196
+ to: {
197
+ ...item.output.param.to,
198
+ locateDescription: to
199
+ }
200
+ }
201
+ }
202
+ };
203
+ }
204
+ return {
205
+ ...item,
206
+ locateDescription: (null == (_tasks_ = tasks[index - 1]) ? void 0 : null == (_tasks__param = _tasks_.param) ? void 0 : _tasks__param.prompt) || ''
207
+ };
208
+ }
209
+ return item;
210
+ });
211
+ toBeUsedRef.current = toBeUsedRef.current.concat(actionTasks.filter((item)=>'Action' === item.type));
212
+ }
213
+ const separatorItem = {
214
+ id: `separator-${thisRunningId}`,
215
+ type: 'separator',
216
+ content: 'New Session',
217
+ timestamp: new Date()
218
+ };
219
+ setInfoList((prev)=>[
220
+ ...prev,
221
+ separatorItem
222
+ ]);
223
+ return {
224
+ ...result,
225
+ reportHTML: null
226
+ };
227
+ };
228
+ if ('aiAction' !== value.type) return await executeTask(value);
229
+ {
230
+ var _value_prompt;
231
+ toBeUsedRef.current = [];
232
+ isCancelledRef.current = false;
233
+ currentNodeRef.current = null;
234
+ const prompts = (null == (_value_prompt = value.prompt) ? void 0 : _value_prompt.split("\n").map((item)=>item.trim()).filter(Boolean)) || [];
235
+ const createTaskList = function() {
236
+ let prompts = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
237
+ let head = null;
238
+ let current = null;
239
+ for (let prompt of prompts){
240
+ const taskNode = new TaskNode(Date.now(), prompt, null);
241
+ if (!head) head = taskNode;
242
+ if (current) current.next = taskNode;
243
+ current = taskNode;
244
+ }
245
+ return head;
246
+ };
247
+ const executeTaskList = async (task)=>{
248
+ let current = task;
249
+ while(current && !isCancelledRef.current)try {
250
+ current.status = 'running';
251
+ const value = {
252
+ type: 'aiAction',
253
+ prompt: current.prompt
254
+ };
255
+ const result = await executeTask(value);
256
+ current.result = result;
257
+ current.status = 'completed';
258
+ currentNodeRef.current = current = current.next;
259
+ } catch (error) {
260
+ if (current) current.status = 'error';
261
+ break;
262
+ }
263
+ };
264
+ const task = createTaskList(prompts);
265
+ await executeTaskList(task);
266
+ setUsedInfoList();
267
+ }
268
+ }, [
269
+ playgroundSDK,
270
+ storage,
271
+ actionSpace,
272
+ setLoading,
273
+ setInfoList,
274
+ replayCounter,
275
+ setReplayCounter,
276
+ verticalMode,
277
+ currentRunningIdRef,
278
+ interruptedFlagRef,
279
+ deepThink,
280
+ screenshotIncluded,
281
+ domIncluded,
282
+ showHumanUse
283
+ ]);
284
+ const handleStop = useCallback(async ()=>{
285
+ const thisRunningId = currentRunningIdRef.current;
286
+ if (thisRunningId && playgroundSDK && playgroundSDK.cancelExecution) try {
287
+ isCancelledRef.current = true;
288
+ await playgroundSDK.cancelExecution(thisRunningId.toString());
289
+ interruptedFlagRef.current[thisRunningId] = true;
290
+ if (currentNodeRef.current) currentNodeRef.current.status = 'cancelled';
291
+ setLoading(false);
292
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate(()=>{});
293
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` && item.loading ? {
294
+ ...item,
295
+ content: 'Operation stopped',
296
+ loading: false,
297
+ loadingProgressText: ''
298
+ } : item));
299
+ const separatorItem = {
300
+ id: `separator-${thisRunningId}`,
301
+ type: 'separator',
302
+ content: 'New Session',
303
+ timestamp: new Date()
304
+ };
305
+ setInfoList((prev)=>[
306
+ ...prev,
307
+ separatorItem
308
+ ]);
309
+ setUsedInfoList();
310
+ } catch (error) {
311
+ console.error('Failed to stop execution:', error);
312
+ }
313
+ }, [
314
+ playgroundSDK,
315
+ currentRunningIdRef,
316
+ interruptedFlagRef,
317
+ setLoading,
318
+ setInfoList
319
+ ]);
320
+ const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK && !!playgroundSDK.cancelExecution;
321
+ return {
322
+ handleRun,
323
+ handleStop,
324
+ canStop
325
+ };
326
+ }
327
+ export { usePlaygroundExecution };
@@ -50,7 +50,7 @@ const external_form_field_index_js_namespaceObject = require("../form-field/inde
50
50
  const external_history_selector_index_js_namespaceObject = require("../history-selector/index.js");
51
51
  const { TextArea } = external_antd_namespaceObject.Input;
52
52
  const PromptInput = (param)=>{
53
- let { runButtonEnabled, form, serviceMode, selectedType, dryMode, stoppable, loading, onRun, onStop, clearPromptAfterRun = true, actionSpace, hideDomAndScreenshotOptions = false } = param;
53
+ let { runButtonEnabled, form, serviceMode, selectedType, dryMode, stoppable, loading, onRun, onStop, clearPromptAfterRun = true, actionSpace, hideDomAndScreenshotOptions = false, defaultSelectedType } = param;
54
54
  const [hoveringSettings, setHoveringSettings] = (0, external_react_namespaceObject.useState)(false);
55
55
  const [promptValue, setPromptValue] = (0, external_react_namespaceObject.useState)('');
56
56
  const placeholder = (0, playground_utils_js_namespaceObject.getPlaceholderForType)(selectedType);
@@ -187,9 +187,13 @@ const PromptInput = (param)=>{
187
187
  actionSpace
188
188
  ]);
189
189
  (0, external_react_namespaceObject.useEffect)(()=>{
190
- if (!form.getFieldValue('type') && lastSelectedType) form.setFieldValue('type', lastSelectedType);
190
+ if (!form.getFieldValue('type')) {
191
+ if (defaultSelectedType) form.setFieldValue('type', defaultSelectedType);
192
+ else if (lastSelectedType) form.setFieldValue('type', lastSelectedType);
193
+ }
191
194
  }, [
192
195
  form,
196
+ defaultSelectedType,
193
197
  lastSelectedType
194
198
  ]);
195
199
  (0, external_react_namespaceObject.useEffect)(()=>{
@@ -221,28 +225,15 @@ const PromptInput = (param)=>{
221
225
  }
222
226
  }, []);
223
227
  (0, external_react_namespaceObject.useEffect)(()=>{
224
- const lastHistory = historyForSelectedType[0];
225
- if (lastHistory && lastHistoryRef.current && lastHistory.timestamp === lastHistoryRef.current.timestamp) return;
226
- if (lastHistory) {
227
- form.setFieldsValue({
228
- type: lastHistory.type,
229
- prompt: lastHistory.prompt || '',
230
- params: lastHistory.params
231
- });
232
- setPromptValue(lastHistory.prompt || '');
233
- lastHistoryRef.current = lastHistory;
234
- } else {
235
- const defaultParams = getDefaultParams();
236
- form.setFieldsValue({
237
- prompt: '',
238
- params: defaultParams
239
- });
240
- setPromptValue('');
241
- lastHistoryRef.current = null;
242
- }
228
+ const defaultParams = getDefaultParams();
229
+ form.setFieldsValue({
230
+ prompt: '',
231
+ params: defaultParams
232
+ });
233
+ setPromptValue('');
243
234
  }, [
244
235
  selectedType,
245
- historyForSelectedType,
236
+ setPromptValue,
246
237
  form,
247
238
  getDefaultParams
248
239
  ]);
@@ -82,7 +82,7 @@ function ErrorMessage(param) {
82
82
  });
83
83
  }
84
84
  function UniversalPlayground(param) {
85
- let { playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true, showPromptInput = true, onHumanUse = ()=>{}, showHumanUse = false } = param;
85
+ let { playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true, showPromptInput = true, onHumanUse = ()=>{}, showHumanUse = false, defaultSelectedType } = param;
86
86
  const [form] = external_antd_namespaceObject.Form.useForm();
87
87
  const { config } = (0, store_js_namespaceObject.useEnvConfig)();
88
88
  const [sdkReady, setSdkReady] = (0, external_react_namespaceObject.useState)(false);
@@ -125,11 +125,6 @@ function UniversalPlayground(param) {
125
125
  playgroundSDK,
126
126
  config
127
127
  ]);
128
- (0, external_react_namespaceObject.useEffect)(()=>{
129
- form.setFieldValue('type', 'aiTap');
130
- }, [
131
- form
132
- ]);
133
128
  const handleFormRun = (0, external_react_namespaceObject.useCallback)(async ()=>{
134
129
  try {
135
130
  const value = form.getFieldsValue();
@@ -184,6 +179,12 @@ function UniversalPlayground(param) {
184
179
  canStop,
185
180
  handleStop
186
181
  ]);
182
+ (0, external_react_namespaceObject.useEffect)(()=>{
183
+ if (defaultSelectedType && !showPromptInput) form.setFieldValue('type', defaultSelectedType);
184
+ }, [
185
+ defaultSelectedType,
186
+ showPromptInput
187
+ ]);
187
188
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
188
189
  id: "playground-container",
189
190
  className: `playground-container ${layout}-mode ${className}`.trim(),
@@ -192,9 +193,6 @@ function UniversalPlayground(param) {
192
193
  form: form,
193
194
  onFinish: handleFormRun,
194
195
  className: "command-form",
195
- initialValues: {
196
- type: 'aiTap'
197
- },
198
196
  children: [
199
197
  finalShowContextPreview && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
200
198
  className: "context-preview-section",
@@ -453,7 +451,7 @@ function UniversalPlayground(param) {
453
451
  ]
454
452
  }),
455
453
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
456
- className: "bottom-input-section aaa",
454
+ className: "bottom-input-section",
457
455
  children: showPromptInput && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_prompt_input_index_js_namespaceObject.PromptInput, {
458
456
  runButtonEnabled: runButtonEnabled,
459
457
  form: form,
@@ -464,7 +462,8 @@ function UniversalPlayground(param) {
464
462
  loading: loading,
465
463
  onRun: handleFormRun,
466
464
  onStop: handleStop,
467
- actionSpace: actionSpace
465
+ actionSpace: actionSpace,
466
+ defaultSelectedType: defaultSelectedType
468
467
  })
469
468
  }),
470
469
  showVersionInfo && branding.version && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ usePlaygroundExecution: ()=>usePlaygroundExecution
28
+ });
29
+ const external_react_namespaceObject = require("react");
30
+ const store_js_namespaceObject = require("../store/store.js");
31
+ const playground_namespaceObject = require("@rpascene/playground");
32
+ const constants_js_namespaceObject = require("../utils/constants.js");
33
+ const replay_scripts_js_namespaceObject = require("../utils/replay-scripts.js");
34
+ function _define_property(obj, key, value) {
35
+ if (key in obj) Object.defineProperty(obj, key, {
36
+ value: value,
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true
40
+ });
41
+ else obj[key] = value;
42
+ return obj;
43
+ }
44
+ class TaskNode {
45
+ constructor(taskId, prompt, next = null){
46
+ _define_property(this, "taskId", void 0);
47
+ _define_property(this, "prompt", void 0);
48
+ _define_property(this, "next", void 0);
49
+ _define_property(this, "result", void 0);
50
+ _define_property(this, "status", void 0);
51
+ this.taskId = taskId;
52
+ this.prompt = prompt;
53
+ this.next = next;
54
+ this.result = null;
55
+ this.status = 'pending';
56
+ }
57
+ }
58
+ function usePlaygroundExecution(playgroundSDK, storage, actionSpace, loading, setLoading, infoList, setInfoList, replayCounter, setReplayCounter, verticalMode, currentRunningIdRef, interruptedFlagRef, showHumanUse) {
59
+ const toBeUsedRef = (0, external_react_namespaceObject.useRef)([]);
60
+ const isCancelledRef = (0, external_react_namespaceObject.useRef)(false);
61
+ const currentNodeRef = (0, external_react_namespaceObject.useRef)();
62
+ const { deepThink, screenshotIncluded, domIncluded } = (0, store_js_namespaceObject.useEnvConfig)();
63
+ const setUsedInfoList = ()=>{
64
+ if (toBeUsedRef.current.length > 0) {
65
+ const thisRunningId = Date.now();
66
+ const systemItem = {
67
+ id: `system-${thisRunningId}`,
68
+ type: 'system',
69
+ content: '',
70
+ timestamp: new Date(),
71
+ loading: false,
72
+ loadingProgressText: '',
73
+ actionTasks: toBeUsedRef.current
74
+ };
75
+ setInfoList((prev)=>[
76
+ ...prev,
77
+ systemItem
78
+ ]);
79
+ toBeUsedRef.current = [];
80
+ }
81
+ };
82
+ const handleRun = (0, external_react_namespaceObject.useCallback)(async (value)=>{
83
+ console.log(value, "\u5728\u8FD9\u91CC\u5206\u5272value\uFF0C\u4E32\u884C\u6267\u884C\uFF0Cvalue-----------------------");
84
+ if (!playgroundSDK) return void console.warn('PlaygroundSDK is not available');
85
+ const executeTask = async (value)=>{
86
+ var _result_dump_executions_, _result_dump_executions;
87
+ const thisRunningId = Date.now();
88
+ const actionType = value.type;
89
+ const sub = value.prompt || value.params ? value.prompt || JSON.stringify(value.params) : '';
90
+ const displayContent = sub ? `${value.type}: ${sub}` : value.type;
91
+ const userItem = {
92
+ id: `user-${Date.now()}`,
93
+ type: 'user',
94
+ content: displayContent,
95
+ timestamp: new Date()
96
+ };
97
+ setInfoList((prev)=>[
98
+ ...prev,
99
+ userItem
100
+ ]);
101
+ setLoading(true);
102
+ const result = {
103
+ ...constants_js_namespaceObject.BLANK_RESULT
104
+ };
105
+ const systemItem = {
106
+ id: `system-${thisRunningId}`,
107
+ type: 'system',
108
+ content: '',
109
+ timestamp: new Date(),
110
+ loading: true,
111
+ loadingProgressText: ''
112
+ };
113
+ setInfoList((prev)=>[
114
+ ...prev,
115
+ systemItem
116
+ ]);
117
+ try {
118
+ currentRunningIdRef.current = thisRunningId;
119
+ interruptedFlagRef.current[thisRunningId] = false;
120
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate(()=>{});
121
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate((tip)=>{
122
+ if (interruptedFlagRef.current[thisRunningId]) return;
123
+ setInfoList((prev)=>{
124
+ const lastItem = prev[prev.length - 1];
125
+ if (lastItem && 'progress' === lastItem.type && lastItem.content === tip) return prev;
126
+ const progressItem = {
127
+ id: `progress-${thisRunningId}-${Date.now()}`,
128
+ type: 'progress',
129
+ content: tip,
130
+ timestamp: new Date()
131
+ };
132
+ return [
133
+ ...prev,
134
+ progressItem
135
+ ];
136
+ });
137
+ });
138
+ result.result = await playgroundSDK.executeAction(actionType, value, {
139
+ requestId: thisRunningId.toString(),
140
+ deepThink,
141
+ screenshotIncluded,
142
+ domIncluded
143
+ });
144
+ if ('object' == typeof result.result && null !== result.result) {
145
+ const resultObj = result.result;
146
+ if (resultObj.dump) result.dump = resultObj.dump;
147
+ if (resultObj.reportHTML) result.reportHTML = resultObj.reportHTML;
148
+ if (resultObj.error) result.error = resultObj.error;
149
+ if (void 0 !== resultObj.result) result.result = resultObj.result;
150
+ }
151
+ } catch (e) {
152
+ result.error = (null == e ? void 0 : e.message) || String(e);
153
+ console.error('Playground execution error:', result);
154
+ }
155
+ if (interruptedFlagRef.current[thisRunningId]) return;
156
+ setLoading(false);
157
+ currentRunningIdRef.current = null;
158
+ let replayInfo = null;
159
+ let counter = replayCounter;
160
+ if ((null == result ? void 0 : result.dump) && !playground_namespaceObject.noReplayAPIs.includes(actionType)) {
161
+ const info = (0, replay_scripts_js_namespaceObject.allScriptsFromDump)(result.dump);
162
+ setReplayCounter((c)=>c + 1);
163
+ replayInfo = info;
164
+ counter = replayCounter + 1;
165
+ }
166
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` ? {
167
+ ...item,
168
+ content: '',
169
+ loading: false,
170
+ loadingProgressText: ''
171
+ } : item));
172
+ const resultItem = {
173
+ id: `result-${thisRunningId}`,
174
+ type: 'result',
175
+ content: 'Execution result',
176
+ timestamp: new Date(),
177
+ result: result,
178
+ loading: false,
179
+ replayScriptsInfo: replayInfo,
180
+ replayCounter: counter,
181
+ loadingProgressText: '',
182
+ verticalMode: verticalMode
183
+ };
184
+ setInfoList((prev)=>[
185
+ ...prev,
186
+ resultItem
187
+ ]);
188
+ if (null == storage ? void 0 : storage.saveResult) try {
189
+ await storage.saveResult(resultItem.id, resultItem);
190
+ } catch (error) {
191
+ console.error('Failed to save result:', error);
192
+ }
193
+ if (showHumanUse && result && result.dump && (null == (_result_dump_executions = result.dump.executions) ? void 0 : null == (_result_dump_executions_ = _result_dump_executions[0]) ? void 0 : _result_dump_executions_.tasks)) {
194
+ var _result_dump_executions_1, _result_dump_executions1, _result_dump;
195
+ const tasks = (null == result ? void 0 : null == (_result_dump = result.dump) ? void 0 : null == (_result_dump_executions1 = _result_dump.executions) ? void 0 : null == (_result_dump_executions_1 = _result_dump_executions1[0]) ? void 0 : _result_dump_executions_1.tasks) || [];
196
+ const actionTasks = tasks.map((item, index)=>{
197
+ if ('Action' === item.type) {
198
+ var _tasks__param, _tasks_;
199
+ if ('DragAndDrop' === item.subType) {
200
+ var _tasks__param1, _tasks_1, _tasks__param2, _tasks_2;
201
+ const from = (null == (_tasks_1 = tasks[index - 2]) ? void 0 : null == (_tasks__param1 = _tasks_1.param) ? void 0 : _tasks__param1.prompt) || '';
202
+ const to = (null == (_tasks_2 = tasks[index - 1]) ? void 0 : null == (_tasks__param2 = _tasks_2.param) ? void 0 : _tasks__param2.prompt) || '';
203
+ return {
204
+ ...item,
205
+ param: {
206
+ ...item.param,
207
+ from: {
208
+ ...item.param.from,
209
+ locateDescription: from
210
+ },
211
+ to: {
212
+ ...item.param.to,
213
+ locateDescription: to
214
+ }
215
+ },
216
+ output: {
217
+ ...item.output,
218
+ param: {
219
+ ...item.output.param,
220
+ from: {
221
+ ...item.output.param.from,
222
+ locateDescription: from
223
+ },
224
+ to: {
225
+ ...item.output.param.to,
226
+ locateDescription: to
227
+ }
228
+ }
229
+ }
230
+ };
231
+ }
232
+ return {
233
+ ...item,
234
+ locateDescription: (null == (_tasks_ = tasks[index - 1]) ? void 0 : null == (_tasks__param = _tasks_.param) ? void 0 : _tasks__param.prompt) || ''
235
+ };
236
+ }
237
+ return item;
238
+ });
239
+ toBeUsedRef.current = toBeUsedRef.current.concat(actionTasks.filter((item)=>'Action' === item.type));
240
+ }
241
+ const separatorItem = {
242
+ id: `separator-${thisRunningId}`,
243
+ type: 'separator',
244
+ content: 'New Session',
245
+ timestamp: new Date()
246
+ };
247
+ setInfoList((prev)=>[
248
+ ...prev,
249
+ separatorItem
250
+ ]);
251
+ return {
252
+ ...result,
253
+ reportHTML: null
254
+ };
255
+ };
256
+ if ('aiAction' !== value.type) return await executeTask(value);
257
+ {
258
+ var _value_prompt;
259
+ toBeUsedRef.current = [];
260
+ isCancelledRef.current = false;
261
+ currentNodeRef.current = null;
262
+ const prompts = (null == (_value_prompt = value.prompt) ? void 0 : _value_prompt.split("\n").map((item)=>item.trim()).filter(Boolean)) || [];
263
+ const createTaskList = function() {
264
+ let prompts = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
265
+ let head = null;
266
+ let current = null;
267
+ for (let prompt of prompts){
268
+ const taskNode = new TaskNode(Date.now(), prompt, null);
269
+ if (!head) head = taskNode;
270
+ if (current) current.next = taskNode;
271
+ current = taskNode;
272
+ }
273
+ return head;
274
+ };
275
+ const executeTaskList = async (task)=>{
276
+ let current = task;
277
+ while(current && !isCancelledRef.current)try {
278
+ current.status = 'running';
279
+ const value = {
280
+ type: 'aiAction',
281
+ prompt: current.prompt
282
+ };
283
+ const result = await executeTask(value);
284
+ current.result = result;
285
+ current.status = 'completed';
286
+ currentNodeRef.current = current = current.next;
287
+ } catch (error) {
288
+ if (current) current.status = 'error';
289
+ break;
290
+ }
291
+ };
292
+ const task = createTaskList(prompts);
293
+ await executeTaskList(task);
294
+ setUsedInfoList();
295
+ }
296
+ }, [
297
+ playgroundSDK,
298
+ storage,
299
+ actionSpace,
300
+ setLoading,
301
+ setInfoList,
302
+ replayCounter,
303
+ setReplayCounter,
304
+ verticalMode,
305
+ currentRunningIdRef,
306
+ interruptedFlagRef,
307
+ deepThink,
308
+ screenshotIncluded,
309
+ domIncluded,
310
+ showHumanUse
311
+ ]);
312
+ const handleStop = (0, external_react_namespaceObject.useCallback)(async ()=>{
313
+ const thisRunningId = currentRunningIdRef.current;
314
+ if (thisRunningId && playgroundSDK && playgroundSDK.cancelExecution) try {
315
+ isCancelledRef.current = true;
316
+ await playgroundSDK.cancelExecution(thisRunningId.toString());
317
+ interruptedFlagRef.current[thisRunningId] = true;
318
+ if (currentNodeRef.current) currentNodeRef.current.status = 'cancelled';
319
+ setLoading(false);
320
+ if (playgroundSDK.onProgressUpdate) playgroundSDK.onProgressUpdate(()=>{});
321
+ setInfoList((prev)=>prev.map((item)=>item.id === `system-${thisRunningId}` && item.loading ? {
322
+ ...item,
323
+ content: 'Operation stopped',
324
+ loading: false,
325
+ loadingProgressText: ''
326
+ } : item));
327
+ const separatorItem = {
328
+ id: `separator-${thisRunningId}`,
329
+ type: 'separator',
330
+ content: 'New Session',
331
+ timestamp: new Date()
332
+ };
333
+ setInfoList((prev)=>[
334
+ ...prev,
335
+ separatorItem
336
+ ]);
337
+ setUsedInfoList();
338
+ } catch (error) {
339
+ console.error('Failed to stop execution:', error);
340
+ }
341
+ }, [
342
+ playgroundSDK,
343
+ currentRunningIdRef,
344
+ interruptedFlagRef,
345
+ setLoading,
346
+ setInfoList
347
+ ]);
348
+ const canStop = loading && !!currentRunningIdRef.current && !!playgroundSDK && !!playgroundSDK.cancelExecution;
349
+ return {
350
+ handleRun,
351
+ handleStop,
352
+ canStop
353
+ };
354
+ }
355
+ exports.usePlaygroundExecution = __webpack_exports__.usePlaygroundExecution;
356
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
357
+ "usePlaygroundExecution"
358
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
359
+ Object.defineProperty(exports, '__esModule', {
360
+ value: true
361
+ });
@@ -17,6 +17,7 @@ interface PromptInputProps {
17
17
  clearPromptAfterRun?: boolean;
18
18
  hideDomAndScreenshotOptions?: boolean;
19
19
  actionSpace: DeviceAction<any>[];
20
+ defaultSelectedType?: string;
20
21
  }
21
22
  export declare const PromptInput: React.FC<PromptInputProps>;
22
23
  export {};
@@ -1,4 +1,4 @@
1
1
  import type { UniversalPlaygroundProps } from '../../types';
2
2
  import './index.less';
3
- export declare function UniversalPlayground({ playgroundSDK, storage, contextProvider, config: componentConfig, branding, className, dryMode, showContextPreview, showPromptInput, onHumanUse, showHumanUse }: UniversalPlaygroundProps): import("react").JSX.Element;
3
+ export declare function UniversalPlayground({ playgroundSDK, storage, contextProvider, config: componentConfig, branding, className, dryMode, showContextPreview, showPromptInput, onHumanUse, showHumanUse, defaultSelectedType }: UniversalPlaygroundProps): import("react").JSX.Element;
4
4
  export default UniversalPlayground;
@@ -0,0 +1,15 @@
1
+ import type { DeviceAction } from '@rpascene/core';
2
+ import type { FormValue, InfoListItem, PlaygroundSDKLike, StorageProvider } from '../types';
3
+ /**
4
+ * Hook for handling playground execution logic
5
+ */
6
+ export declare function usePlaygroundExecution(playgroundSDK: PlaygroundSDKLike | null, storage: StorageProvider | undefined | null, actionSpace: DeviceAction<unknown>[], loading: boolean, setLoading: (loading: boolean) => void, infoList: InfoListItem[], setInfoList: React.Dispatch<React.SetStateAction<InfoListItem[]>>, replayCounter: number, setReplayCounter: React.Dispatch<React.SetStateAction<number>>, verticalMode: boolean, currentRunningIdRef: React.MutableRefObject<number | null>, interruptedFlagRef: React.MutableRefObject<Record<number, boolean>>, showHumanUse: boolean): {
7
+ handleRun: (value: FormValue) => Promise<{
8
+ reportHTML: null;
9
+ result: any;
10
+ dump?: import("@rpascene/core").GroupedActionDump | null;
11
+ error: string | null;
12
+ } | undefined>;
13
+ handleStop: () => Promise<void>;
14
+ canStop: boolean;
15
+ };
@@ -162,4 +162,5 @@ export interface UniversalPlaygroundProps {
162
162
  showPromptInput?: boolean;
163
163
  onHumanUse?: (commands?: any) => void;
164
164
  showHumanUse?: boolean;
165
+ defaultSelectedType?: string;
165
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpascene/visualizer",
3
- "version": "0.30.16",
3
+ "version": "0.30.18",
4
4
  "description": "RPA visualizer",
5
5
  "repository": "",
6
6
  "homepage": "",
@@ -72,10 +72,10 @@
72
72
  "antd": "^5.21.6",
73
73
  "buffer": "6.0.3",
74
74
  "dayjs": "^1.11.11",
75
- "@rpascene/playground": "0.30.16",
76
- "@rpascene/web": "0.30.16",
77
- "@rpascene/shared": "0.30.16",
78
- "@rpascene/core": "0.30.16"
75
+ "@rpascene/core": "0.30.18",
76
+ "@rpascene/playground": "0.30.18",
77
+ "@rpascene/web": "0.30.18",
78
+ "@rpascene/shared": "0.30.18"
79
79
  },
80
80
  "license": "MIT",
81
81
  "scripts": {