@godscene/playground-electron 1.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/dist/es/DeviceInteractionLayer.mjs +383 -0
  4. package/dist/es/PlaygroundApp.css +207 -0
  5. package/dist/es/PlaygroundApp.mjs +776 -0
  6. package/dist/es/PlaygroundPreview.mjs +29 -0
  7. package/dist/es/PlaygroundThemeProvider.mjs +10 -0
  8. package/dist/es/PreviewRenderer.mjs +270 -0
  9. package/dist/es/ScrcpyPanel.mjs +390 -0
  10. package/dist/es/SessionSetupPanel.css +299 -0
  11. package/dist/es/SessionSetupPanel.mjs +169 -0
  12. package/dist/es/components/Header/index.css +19 -0
  13. package/dist/es/components/Header/index.mjs +37 -0
  14. package/dist/es/components/Nav/index.css +15 -0
  15. package/dist/es/components/Nav/index.mjs +93 -0
  16. package/dist/es/components/WinControlTool/index.css +5 -0
  17. package/dist/es/components/WinControlTool/index.mjs +76 -0
  18. package/dist/es/controller/ai-config.mjs +40 -0
  19. package/dist/es/controller/auto-create.mjs +19 -0
  20. package/dist/es/controller/selectors.mjs +78 -0
  21. package/dist/es/controller/single-flight.mjs +13 -0
  22. package/dist/es/controller/types.mjs +0 -0
  23. package/dist/es/controller/usePlaygroundController.mjs +400 -0
  24. package/dist/es/icons/dropdown-chevron.mjs +61 -0
  25. package/dist/es/icons/midscene-logo.mjs +247 -0
  26. package/dist/es/icons/server-offline-background.mjs +102 -0
  27. package/dist/es/icons/server-offline-foreground.mjs +200 -0
  28. package/dist/es/index.mjs +7 -0
  29. package/dist/es/manual-interaction.mjs +56 -0
  30. package/dist/es/panels/PlaygroundConversationPanel.css +20 -0
  31. package/dist/es/panels/PlaygroundConversationPanel.mjs +140 -0
  32. package/dist/es/runtime-info.mjs +128 -0
  33. package/dist/es/scrcpy-preview.mjs +30 -0
  34. package/dist/es/scrcpy-stream.mjs +53 -0
  35. package/dist/es/session-setup.mjs +13 -0
  36. package/dist/es/session-state.mjs +32 -0
  37. package/dist/es/useServerStatus.mjs +120 -0
  38. package/dist/lib/DeviceInteractionLayer.js +434 -0
  39. package/dist/lib/PlaygroundApp.css +207 -0
  40. package/dist/lib/PlaygroundApp.js +821 -0
  41. package/dist/lib/PlaygroundPreview.js +63 -0
  42. package/dist/lib/PlaygroundThemeProvider.js +44 -0
  43. package/dist/lib/PreviewRenderer.js +304 -0
  44. package/dist/lib/ScrcpyPanel.js +424 -0
  45. package/dist/lib/SessionSetupPanel.css +299 -0
  46. package/dist/lib/SessionSetupPanel.js +217 -0
  47. package/dist/lib/components/Header/index.css +19 -0
  48. package/dist/lib/components/Header/index.js +81 -0
  49. package/dist/lib/components/Nav/index.css +15 -0
  50. package/dist/lib/components/Nav/index.js +127 -0
  51. package/dist/lib/components/WinControlTool/index.css +5 -0
  52. package/dist/lib/components/WinControlTool/index.js +110 -0
  53. package/dist/lib/controller/ai-config.js +80 -0
  54. package/dist/lib/controller/auto-create.js +59 -0
  55. package/dist/lib/controller/selectors.js +115 -0
  56. package/dist/lib/controller/single-flight.js +47 -0
  57. package/dist/lib/controller/types.js +18 -0
  58. package/dist/lib/controller/usePlaygroundController.js +434 -0
  59. package/dist/lib/icons/dropdown-chevron.js +95 -0
  60. package/dist/lib/icons/midscene-logo.js +281 -0
  61. package/dist/lib/icons/server-offline-background.js +136 -0
  62. package/dist/lib/icons/server-offline-foreground.js +234 -0
  63. package/dist/lib/index.js +56 -0
  64. package/dist/lib/manual-interaction.js +90 -0
  65. package/dist/lib/panels/PlaygroundConversationPanel.css +20 -0
  66. package/dist/lib/panels/PlaygroundConversationPanel.js +174 -0
  67. package/dist/lib/runtime-info.js +174 -0
  68. package/dist/lib/scrcpy-preview.js +79 -0
  69. package/dist/lib/scrcpy-stream.js +87 -0
  70. package/dist/lib/session-setup.js +47 -0
  71. package/dist/lib/session-state.js +69 -0
  72. package/dist/lib/useServerStatus.js +154 -0
  73. package/dist/types/DeviceInteractionLayer.d.ts +50 -0
  74. package/dist/types/PlaygroundApp.d.ts +14 -0
  75. package/dist/types/PlaygroundPreview.d.ts +22 -0
  76. package/dist/types/PlaygroundThemeProvider.d.ts +2 -0
  77. package/dist/types/PreviewRenderer.d.ts +27 -0
  78. package/dist/types/ScrcpyPanel.d.ts +21 -0
  79. package/dist/types/SessionSetupPanel.d.ts +16 -0
  80. package/dist/types/components/Header/index.d.ts +3 -0
  81. package/dist/types/components/Nav/index.d.ts +3 -0
  82. package/dist/types/components/WinControlTool/index.d.ts +3 -0
  83. package/dist/types/controller/ai-config.d.ts +5 -0
  84. package/dist/types/controller/auto-create.d.ts +15 -0
  85. package/dist/types/controller/selectors.d.ts +5 -0
  86. package/dist/types/controller/single-flight.d.ts +3 -0
  87. package/dist/types/controller/types.d.ts +36 -0
  88. package/dist/types/controller/usePlaygroundController.d.ts +16 -0
  89. package/dist/types/index.d.ts +13 -0
  90. package/dist/types/manual-interaction.d.ts +21 -0
  91. package/dist/types/panels/PlaygroundConversationPanel.d.ts +25 -0
  92. package/dist/types/runtime-info.d.ts +22 -0
  93. package/dist/types/scrcpy-preview.d.ts +11 -0
  94. package/dist/types/scrcpy-stream.d.ts +16 -0
  95. package/dist/types/session-setup.d.ts +2 -0
  96. package/dist/types/session-state.d.ts +9 -0
  97. package/dist/types/useServerStatus.d.ts +12 -0
  98. package/package.json +69 -0
@@ -0,0 +1,776 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Logo, NavActions } from "@godscene/visualizer";
3
+ import { Layout, Modal, message as external_antd_message } from "antd";
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
6
+ import { PlaygroundThemeProvider } from "./PlaygroundThemeProvider.mjs";
7
+ import { usePlaygroundController } from "./controller/usePlaygroundController.mjs";
8
+ import server_offline_background from "./icons/server-offline-background.mjs";
9
+ import server_offline_foreground from "./icons/server-offline-foreground.mjs";
10
+ import { PlaygroundConversationPanel } from "./panels/PlaygroundConversationPanel.mjs";
11
+ import { Header } from "./components/Header/index.mjs";
12
+ import { Nav } from "./components/Nav/index.mjs";
13
+ import { commandMap, rpasceneCommand, rpastudioCommand } from "@godscene/shared/constants";
14
+ import "./PlaygroundApp.css";
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
16
+ try {
17
+ var info = gen[key](arg);
18
+ var value = info.value;
19
+ } catch (error) {
20
+ reject(error);
21
+ return;
22
+ }
23
+ if (info.done) resolve(value);
24
+ else Promise.resolve(value).then(_next, _throw);
25
+ }
26
+ function _async_to_generator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(void 0);
38
+ });
39
+ };
40
+ }
41
+ function _define_property(obj, key, value) {
42
+ if (key in obj) Object.defineProperty(obj, key, {
43
+ value: value,
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true
47
+ });
48
+ else obj[key] = value;
49
+ return obj;
50
+ }
51
+ function _object_spread(target) {
52
+ for(var i = 1; i < arguments.length; i++){
53
+ var source = null != arguments[i] ? arguments[i] : {};
54
+ var ownKeys = Object.keys(source);
55
+ if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
56
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
57
+ }));
58
+ ownKeys.forEach(function(key) {
59
+ _define_property(target, key, source[key]);
60
+ });
61
+ }
62
+ return target;
63
+ }
64
+ function PlaygroundApp_ownKeys(object, enumerableOnly) {
65
+ var keys = Object.keys(object);
66
+ if (Object.getOwnPropertySymbols) {
67
+ var symbols = Object.getOwnPropertySymbols(object);
68
+ if (enumerableOnly) symbols = symbols.filter(function(sym) {
69
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
70
+ });
71
+ keys.push.apply(keys, symbols);
72
+ }
73
+ return keys;
74
+ }
75
+ function _object_spread_props(target, source) {
76
+ source = null != source ? source : {};
77
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
78
+ else PlaygroundApp_ownKeys(Object(source)).forEach(function(key) {
79
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
80
+ });
81
+ return target;
82
+ }
83
+ const { Content } = Layout;
84
+ function PlaygroundApp({ serverUrl, appVersion, title = 'Playground', defaultDeviceType = 'web', branding, playgroundConfig, offlineTitle = 'Midscene Playground', offlineStatusText = 'Server offline...', pollIntervalMs = 5000 }) {
85
+ var _playgroundConfig_executionUx;
86
+ const [isNarrowScreen, setIsNarrowScreen] = useState(false);
87
+ const controller = usePlaygroundController({
88
+ serverUrl,
89
+ defaultDeviceType,
90
+ countdownSeconds: null == playgroundConfig ? void 0 : null == (_playgroundConfig_executionUx = playgroundConfig.executionUx) ? void 0 : _playgroundConfig_executionUx.countdownSeconds,
91
+ pollIntervalMs
92
+ });
93
+ useEffect(()=>{
94
+ const handleResize = ()=>{
95
+ setIsNarrowScreen(window.innerWidth <= 1024);
96
+ };
97
+ handleResize();
98
+ window.addEventListener('resize', handleResize);
99
+ return ()=>window.removeEventListener('resize', handleResize);
100
+ }, []);
101
+ const rightRef = useRef(null);
102
+ const viewRef = useRef(null);
103
+ const actionRef = useRef(null);
104
+ const [agentReady, setAgentReady] = useState(false);
105
+ const [dialogInfo, setDialogInfo] = useState(null);
106
+ useEffect(()=>{
107
+ var _window_electron;
108
+ null == (_window_electron = window.electron) || _window_electron.ipcRenderer.on('agent:ready', (event, value)=>{
109
+ if (!value) Modal.warning({
110
+ title: '初始化失败',
111
+ content: '请确认是否购买了token',
112
+ getContainer: ()=>rightRef.current,
113
+ mask: false,
114
+ className: "insert-modal",
115
+ wrapClassName: 'insert-modal-wrap',
116
+ zIndex: 99999
117
+ });
118
+ setAgentReady(value);
119
+ });
120
+ }, []);
121
+ useEffect(()=>{
122
+ actionRef.current = {
123
+ receiveMsg (msgData) {
124
+ return _async_to_generator(function*() {
125
+ const { message } = msgData;
126
+ const { pageName, actionName, data } = message;
127
+ console.log('/////////////receive-msg/////////', message);
128
+ if ('initialize' === actionName) setDialogInfo(_object_spread({
129
+ pageName
130
+ }, data));
131
+ else if ('insertScriptCommandResult' === actionName) {
132
+ const { success, message } = data;
133
+ switch(success){
134
+ case true:
135
+ Modal.success({
136
+ title: '使用命令成功',
137
+ content: '已为您生成命令,请在设计器主页查看命令详情',
138
+ getContainer: ()=>rightRef.current,
139
+ mask: false,
140
+ className: "insert-modal",
141
+ wrapClassName: 'insert-modal-wrap',
142
+ zIndex: 99999
143
+ });
144
+ break;
145
+ case false:
146
+ Modal.warning({
147
+ title: '使用命令失败',
148
+ content: message || '使用命令失败,请稍后再试',
149
+ getContainer: ()=>rightRef.current,
150
+ mask: false,
151
+ className: "insert-modal",
152
+ wrapClassName: 'insert-modal-wrap',
153
+ zIndex: 99999
154
+ });
155
+ break;
156
+ default:
157
+ break;
158
+ }
159
+ }
160
+ })();
161
+ }
162
+ };
163
+ }, []);
164
+ useEffect(()=>{
165
+ console.log(!!viewRef.current, 'viewRef.current');
166
+ const resizeObserver = new ResizeObserver((entries)=>{
167
+ for (let entry of entries){
168
+ var _window_electron;
169
+ console.log(entry.contentRect.width, entry.contentRect.height, 'entry.contentRect.width, entry.contentRect.height');
170
+ null == (_window_electron = window.electron) || _window_electron.ipcRenderer.send('playgroundViewer:resize', entry.contentRect.width, entry.contentRect.height);
171
+ }
172
+ });
173
+ if (viewRef.current) {
174
+ var _window_electron;
175
+ console.log(viewRef.current.clientWidth, viewRef.current.clientHeight, 'viewRef.current.clientWidth, viewRef.current.clientHeight');
176
+ null == (_window_electron = window.electron) || _window_electron.ipcRenderer.send('playgroundViewer:resize', viewRef.current.clientWidth, viewRef.current.clientHeight);
177
+ resizeObserver.observe(viewRef.current);
178
+ }
179
+ return ()=>{
180
+ if (viewRef.current) resizeObserver.unobserve(viewRef.current);
181
+ resizeObserver.disconnect();
182
+ };
183
+ }, [
184
+ viewRef,
185
+ agentReady,
186
+ controller.state.serverOnline
187
+ ]);
188
+ const handler = useCallback((msgData)=>{
189
+ var _actionRef_current;
190
+ null == (_actionRef_current = actionRef.current) || _actionRef_current.receiveMsg(msgData);
191
+ }, [
192
+ actionRef
193
+ ]);
194
+ useEffect(()=>{
195
+ var _window___Window;
196
+ if (null == (_window___Window = window.__Window) ? void 0 : _window___Window.receiveMessage) window.__Window.receiveMessage(handler);
197
+ }, [
198
+ handler
199
+ ]);
200
+ const onHumanUse = useCallback((recommendResult)=>{
201
+ if (!(null == recommendResult ? void 0 : recommendResult.length)) return external_antd_message.warning('暂无可使用的命令');
202
+ console.log(recommendResult, 'recommendResult');
203
+ try {
204
+ const data = recommendResult.map((item)=>{
205
+ var _commandMap_item_subType, _commandMap_item_subType1;
206
+ let res = {
207
+ CommandName: null == (_commandMap_item_subType = commandMap[item.subType]) ? void 0 : _commandMap_item_subType.CommandName,
208
+ DisplayName: null == (_commandMap_item_subType1 = commandMap[item.subType]) ? void 0 : _commandMap_item_subType1.DisplayName,
209
+ Parameters: {}
210
+ };
211
+ switch(item.subType){
212
+ case rpasceneCommand.Scroll:
213
+ {
214
+ const { scrollType, direction, distance } = item.param || {};
215
+ if ("untilBottom" === scrollType) res.Parameters = {
216
+ ScrollPosition: {
217
+ Key: "ScrollPosition",
218
+ Name: "滚动位置",
219
+ Value: "Bottom"
220
+ }
221
+ };
222
+ else if ("untilTop" === scrollType) res.Parameters = {
223
+ ScrollPosition: {
224
+ Key: "ScrollPosition",
225
+ Name: "滚动位置",
226
+ Value: "Top"
227
+ }
228
+ };
229
+ else if ('untilRight' === scrollType) res.Parameters = {
230
+ ScrollPosition: {
231
+ Key: "ScrollPosition",
232
+ Name: "滚动位置",
233
+ Value: "Position"
234
+ },
235
+ ScrollWidth: {
236
+ Key: "ScrollWidth",
237
+ Name: "滚动到横坐标位置",
238
+ Value: 999999
239
+ }
240
+ };
241
+ else if ('untilLeft' === scrollType) res.Parameters = {
242
+ ScrollPosition: {
243
+ Key: "ScrollPosition",
244
+ Name: "滚动位置",
245
+ Value: "Position"
246
+ },
247
+ ScrollWidth: {
248
+ Key: "ScrollWidth",
249
+ Name: "滚动到横坐标位置",
250
+ Value: -999999
251
+ }
252
+ };
253
+ else if ('once' === scrollType) {
254
+ if ('left' === direction || 'right' === direction) res.Parameters = {
255
+ ScrollPosition: {
256
+ Key: "ScrollPosition",
257
+ Name: "滚动位置",
258
+ Value: "Position"
259
+ },
260
+ ScrollWidth: {
261
+ Key: "ScrollWidth",
262
+ Name: "滚动到横坐标位置",
263
+ Value: distance
264
+ }
265
+ };
266
+ if ('up' === direction || 'down' === direction) res.Parameters = {
267
+ ScrollPosition: {
268
+ Key: "ScrollPosition",
269
+ Name: "滚动位置",
270
+ Value: "Position"
271
+ },
272
+ ScrollHeight: {
273
+ Key: "ScrollWidth",
274
+ Name: "滚动到纵坐标位置",
275
+ Value: distance
276
+ }
277
+ };
278
+ }
279
+ if (item.param.locate) {
280
+ var _item_param_locate_allPaths_, _item_param_locate_allPaths, _item_param_locate, _item_param_locate1;
281
+ res.CommandName = rpastudioCommand.SeleniumElementScrollCommand;
282
+ res.Parameters = _object_spread_props(_object_spread({}, res.Parameters), {
283
+ SearchParameter: {
284
+ Key: "SearchParameter",
285
+ Value: null == (_item_param_locate = item.param.locate) ? void 0 : null == (_item_param_locate_allPaths = _item_param_locate.allPaths) ? void 0 : null == (_item_param_locate_allPaths_ = _item_param_locate_allPaths[0]) ? void 0 : _item_param_locate_allPaths_.value
286
+ },
287
+ ElementName: {
288
+ Key: "ElementName",
289
+ Name: "元素名称",
290
+ Value: item.locateDescription
291
+ },
292
+ ContainerXpath: {
293
+ Key: "ContainerXpath",
294
+ Name: "父级Xpath",
295
+ Value: JSON.stringify((null == (_item_param_locate1 = item.param.locate) ? void 0 : _item_param_locate1.containerPaths) || [])
296
+ },
297
+ ElementIndex: {
298
+ Key: "ElementIndex",
299
+ Value: 1
300
+ }
301
+ });
302
+ } else res.CommandName = rpastudioCommand.SeleniumWindowScrollCommand;
303
+ break;
304
+ }
305
+ case rpasceneCommand.KeyboardPress:
306
+ {
307
+ var _item_param;
308
+ let keyName = (null == (_item_param = item.param) ? void 0 : _item_param.keyName) || '';
309
+ let useSeleniumElementSendKeysCommand = false;
310
+ if (useSeleniumElementSendKeysCommand && item.param.locate) {
311
+ var _item_param_locate2, _item_param1, _item_param_locate_allPaths_1, _item_param_locate_allPaths1, _item_param_locate3, _item_param2;
312
+ const keyValue = keyName.split('+').map((item)=>{
313
+ const key = item.trim();
314
+ switch(key.toLowerCase()){
315
+ case 'backspace':
316
+ return '{BACKSPACE}';
317
+ case 'capslock':
318
+ return '{CAPSLOCK}';
319
+ case 'delete':
320
+ return '{DELETE}';
321
+ case 'arrowdown':
322
+ return '{DOWN}';
323
+ case 'end':
324
+ return '{END}';
325
+ case 'enter':
326
+ return '{ENTER}';
327
+ case 'escape':
328
+ return '{ESC}';
329
+ case 'help':
330
+ return '{HELP}';
331
+ case 'home':
332
+ return '{HOME}';
333
+ case 'insert':
334
+ return '{Insert}';
335
+ case 'arrowleft':
336
+ return '{LEFT}';
337
+ case 'numlock':
338
+ return 'NUMLOCK';
339
+ case 'pagedown':
340
+ return '{PGDN}';
341
+ case 'pageup':
342
+ return '{PGUP}';
343
+ case 'printscreen':
344
+ return '{PRTSC}';
345
+ case 'arrowright':
346
+ return '{RIGHT}';
347
+ case 'scrolllock':
348
+ return '{SCROLLLOCK}';
349
+ case 'tab':
350
+ return '{TAB}';
351
+ case 'arrowup':
352
+ return '{UP}';
353
+ case 'f1':
354
+ return '{F1}';
355
+ case 'f2':
356
+ return '{F2}';
357
+ case 'f3':
358
+ return '{F3}';
359
+ case 'f4':
360
+ return '{F4}';
361
+ case 'f5':
362
+ return '{F5}';
363
+ case 'f6':
364
+ return '{F6}';
365
+ case 'f7':
366
+ return '{F7}';
367
+ case 'f8':
368
+ return '{F8}';
369
+ case 'f9':
370
+ return '{F9}';
371
+ case 'f10':
372
+ return '{F10}';
373
+ case 'f11':
374
+ return '{F11}';
375
+ case 'f12':
376
+ return '{F12}';
377
+ case 'numpadadd':
378
+ return '{ADD}';
379
+ case 'numpadsubtract':
380
+ return '{SUBTRACT}';
381
+ case 'numpadmultiply':
382
+ return '{MULTIPLY}';
383
+ case 'numpaddivide':
384
+ return '{DIVIDE}';
385
+ case 'shift':
386
+ return '+';
387
+ case 'control':
388
+ return '^';
389
+ case 'alt':
390
+ return '%';
391
+ default:
392
+ return key;
393
+ }
394
+ }).filter(Boolean).join('');
395
+ res.CommandName = rpastudioCommand.SeleniumElementSendKeysCommand;
396
+ res.Parameters = {
397
+ ContainerXpath: {
398
+ Key: "ContainerXpath",
399
+ Name: "父级Xpath",
400
+ Value: JSON.stringify((null == (_item_param1 = item.param) ? void 0 : null == (_item_param_locate2 = _item_param1.locate) ? void 0 : _item_param_locate2.containerPaths) || [])
401
+ },
402
+ ElementName: {
403
+ Key: "ElementName",
404
+ Name: "元素名称",
405
+ Value: item.locateDescription || ''
406
+ },
407
+ SearchParameter: {
408
+ Key: "SearchParameter",
409
+ Name: "元素搜索参数",
410
+ Value: (null == (_item_param2 = item.param) ? void 0 : null == (_item_param_locate3 = _item_param2.locate) ? void 0 : null == (_item_param_locate_allPaths1 = _item_param_locate3.allPaths) ? void 0 : null == (_item_param_locate_allPaths_1 = _item_param_locate_allPaths1[0]) ? void 0 : _item_param_locate_allPaths_1.value) || ''
411
+ },
412
+ SearchType: {
413
+ Key: "SearchType",
414
+ Name: "元素搜索方式",
415
+ Value: "Find Element By XPath"
416
+ },
417
+ Value: {
418
+ Key: "Value",
419
+ Name: "文本内容",
420
+ Value: keyValue
421
+ }
422
+ };
423
+ } else {
424
+ const keyValue = keyName.split('+').map((item)=>{
425
+ const key = item.trim();
426
+ switch(key.toLowerCase()){
427
+ case 'backspace':
428
+ return 'BACKSPACE';
429
+ case 'delete':
430
+ return 'DELETE';
431
+ case 'arrowdown':
432
+ return 'DOWN';
433
+ case 'end':
434
+ return 'END';
435
+ case 'enter':
436
+ return 'ENTER';
437
+ case 'escape':
438
+ return 'ESC';
439
+ case 'help':
440
+ return 'HELP';
441
+ case 'home':
442
+ return 'HOME';
443
+ case 'insert':
444
+ return 'INSERT';
445
+ case 'arrowleft':
446
+ return 'LEFT';
447
+ case 'pagedown':
448
+ return 'PGDN';
449
+ case 'pageup':
450
+ return 'PGUP';
451
+ case 'arrowright':
452
+ return 'RIGHT';
453
+ case 'tab':
454
+ return 'TAB';
455
+ case 'arrowup':
456
+ return 'UP';
457
+ case 'f1':
458
+ return 'F1';
459
+ case 'f2':
460
+ return 'F2';
461
+ case 'f3':
462
+ return 'F3';
463
+ case 'f4':
464
+ return 'F4';
465
+ case 'f5':
466
+ return 'F5';
467
+ case 'f6':
468
+ return 'F6';
469
+ case 'f7':
470
+ return 'F7';
471
+ case 'f8':
472
+ return 'F8';
473
+ case 'f9':
474
+ return 'F9';
475
+ case 'f10':
476
+ return 'F10';
477
+ case 'f11':
478
+ return 'F11';
479
+ case 'f12':
480
+ return 'F12';
481
+ case 'numpadadd':
482
+ return 'ADD';
483
+ case 'numpadsubtract':
484
+ return 'SUBTRACT';
485
+ case 'numpadmultiply':
486
+ return 'MULTIPLY';
487
+ case 'numpaddivide':
488
+ return 'DIVIDE';
489
+ case 'shift':
490
+ return 'SHIFT';
491
+ case 'control':
492
+ return 'CTRL';
493
+ case 'alt':
494
+ return 'ALT';
495
+ case 'capslock':
496
+ return 'CAPSLOCK';
497
+ case 'numlock':
498
+ return 'NUMLOCK';
499
+ case 'printscreen':
500
+ return 'PRTSC';
501
+ case 'scrolllock':
502
+ return 'SCROLLLOCK';
503
+ default:
504
+ return key;
505
+ }
506
+ }).filter(Boolean).join('');
507
+ res.CommandName = rpastudioCommand.SeleniumSendKeysCommand;
508
+ res.Parameters = {
509
+ TextToSend: {
510
+ Key: "TextToSend",
511
+ Name: "请输入要发送的文本",
512
+ Value: keyValue
513
+ }
514
+ };
515
+ }
516
+ break;
517
+ }
518
+ case rpasceneCommand.Tap:
519
+ case rpasceneCommand.RightClick:
520
+ case rpasceneCommand.DoubleClick:
521
+ case rpasceneCommand.Hover:
522
+ case rpasceneCommand.ClearInput:
523
+ var _item_param_locate_allPaths_2, _item_param_locate_allPaths2, _item_param_locate4, _item_param3, _item_param_locate5, _item_param4;
524
+ res.Parameters = {
525
+ SearchParameter: {
526
+ Key: "SearchParameter",
527
+ Value: (null == (_item_param3 = item.param) ? void 0 : null == (_item_param_locate4 = _item_param3.locate) ? void 0 : null == (_item_param_locate_allPaths2 = _item_param_locate4.allPaths) ? void 0 : null == (_item_param_locate_allPaths_2 = _item_param_locate_allPaths2[0]) ? void 0 : _item_param_locate_allPaths_2.value) || ''
528
+ },
529
+ ElementName: {
530
+ Key: "ElementName",
531
+ Name: "元素名称",
532
+ Value: item.locateDescription || ''
533
+ },
534
+ ContainerXpath: {
535
+ Key: "ContainerXpath",
536
+ Name: "父级Xpath",
537
+ Value: JSON.stringify((null == (_item_param4 = item.param) ? void 0 : null == (_item_param_locate5 = _item_param4.locate) ? void 0 : _item_param_locate5.containerPaths) || [])
538
+ },
539
+ ElementIndex: {
540
+ Key: "ElementIndex",
541
+ Value: 1
542
+ }
543
+ };
544
+ break;
545
+ case rpasceneCommand.Input:
546
+ var _item_param_locate_allPaths_3, _item_param_locate_allPaths3, _item_param_locate6, _item_param5, _item_param_locate7, _item_param6, _item_param7, _item_param8;
547
+ res.Parameters = {
548
+ SearchParameter: {
549
+ Key: "SearchParameter",
550
+ Name: "元素搜索参数",
551
+ Value: (null == (_item_param5 = item.param) ? void 0 : null == (_item_param_locate6 = _item_param5.locate) ? void 0 : null == (_item_param_locate_allPaths3 = _item_param_locate6.allPaths) ? void 0 : null == (_item_param_locate_allPaths_3 = _item_param_locate_allPaths3[0]) ? void 0 : _item_param_locate_allPaths_3.value) || ''
552
+ },
553
+ ContainerXpath: {
554
+ Key: "ContainerXpath",
555
+ Name: "父级Xpath",
556
+ Value: JSON.stringify((null == (_item_param6 = item.param) ? void 0 : null == (_item_param_locate7 = _item_param6.locate) ? void 0 : _item_param_locate7.containerPaths) || [])
557
+ },
558
+ ElementName: {
559
+ Key: "ElementName",
560
+ Name: "元素名称",
561
+ Value: item.locateDescription || ''
562
+ },
563
+ Value: {
564
+ Key: "Value",
565
+ Name: '文本内容',
566
+ Value: (null == (_item_param7 = item.param) ? void 0 : _item_param7.value) || ''
567
+ },
568
+ ClearBeforeInput: {
569
+ Key: "ClearBeforeInput",
570
+ Name: "输入前是否清空",
571
+ Value: (null == (_item_param8 = item.param) ? void 0 : _item_param8.mode) !== "append"
572
+ }
573
+ };
574
+ break;
575
+ case rpasceneCommand.Sleep:
576
+ var _ref;
577
+ var _item_param9;
578
+ res.Parameters = {
579
+ PauseLength: {
580
+ Key: "PauseLength",
581
+ Name: "暂停时间(毫秒)",
582
+ Value: null != (_ref = null == (_item_param9 = item.param) ? void 0 : _item_param9.timeMs) ? _ref : 0
583
+ }
584
+ };
585
+ break;
586
+ case rpasceneCommand.DragAndDrop:
587
+ var _item_param_from, _item_param10, _item_param_from1, _item_param11, _item_param_from_allPaths_, _item_param_from_allPaths, _item_param_from2, _item_param12, _item_param_to, _item_param13, _item_param_to_allPaths_, _item_param_to_allPaths, _item_param_to1, _item_param14;
588
+ res.Parameters = {
589
+ ContainerXpath: {
590
+ Key: "ContainerXpath",
591
+ Name: "拖动元素父级Xpath",
592
+ Value: JSON.stringify((null == (_item_param10 = item.param) ? void 0 : null == (_item_param_from = _item_param10.from) ? void 0 : _item_param_from.containerPaths) || [])
593
+ },
594
+ ElementName: {
595
+ Key: "ElementName",
596
+ Name: "拖动元素名称",
597
+ Value: (null == (_item_param11 = item.param) ? void 0 : null == (_item_param_from1 = _item_param11.from) ? void 0 : _item_param_from1.locateDescription) || ''
598
+ },
599
+ SearchParameter: {
600
+ Key: "SearchParameter",
601
+ Name: "拖动元素搜索参数",
602
+ Value: (null == (_item_param12 = item.param) ? void 0 : null == (_item_param_from2 = _item_param12.from) ? void 0 : null == (_item_param_from_allPaths = _item_param_from2.allPaths) ? void 0 : null == (_item_param_from_allPaths_ = _item_param_from_allPaths[0]) ? void 0 : _item_param_from_allPaths_.value) || ''
603
+ },
604
+ SearchType: {
605
+ Key: "SearchType",
606
+ Name: "拖动元素搜索方式",
607
+ Value: "Find Element By XPath"
608
+ },
609
+ TargetContainerXpath: {
610
+ Key: "TargetContainerXpath",
611
+ Name: "目标元素父级Xpath",
612
+ Value: JSON.stringify((null == (_item_param13 = item.param) ? void 0 : null == (_item_param_to = _item_param13.to) ? void 0 : _item_param_to.containerPaths) || [])
613
+ },
614
+ TargetSearchParameter: {
615
+ Key: "TargetSearchParameter",
616
+ Name: "目标元素搜索参数",
617
+ Value: (null == (_item_param14 = item.param) ? void 0 : null == (_item_param_to1 = _item_param14.to) ? void 0 : null == (_item_param_to_allPaths = _item_param_to1.allPaths) ? void 0 : null == (_item_param_to_allPaths_ = _item_param_to_allPaths[0]) ? void 0 : _item_param_to_allPaths_.value) || ''
618
+ },
619
+ TargetSearchType: {
620
+ Key: "TargetSearchType",
621
+ Name: "目标元素搜索方式",
622
+ Value: "Find Element By XPath"
623
+ }
624
+ };
625
+ break;
626
+ case rpasceneCommand.Reload:
627
+ case rpasceneCommand.GoBack:
628
+ res.Parameters = {};
629
+ break;
630
+ case rpasceneCommand.Navigate:
631
+ var _item_param15;
632
+ res.Parameters = {
633
+ URL: {
634
+ Key: "URL",
635
+ Name: "网址",
636
+ Value: (null == (_item_param15 = item.param) ? void 0 : _item_param15.url) || ''
637
+ }
638
+ };
639
+ break;
640
+ default:
641
+ res = null;
642
+ }
643
+ return res;
644
+ }).filter(Boolean);
645
+ console.log(data, '生成的命令data------------------------');
646
+ (null == dialogInfo ? void 0 : dialogInfo.parentToken) && window.__Window.sendMessage({
647
+ from: dialogInfo.token,
648
+ to: dialogInfo.parentToken,
649
+ token: `${Math.random()}`,
650
+ message: {
651
+ pageName: 'aiGenerateScript',
652
+ actionName: 'insertScriptCommand',
653
+ data
654
+ }
655
+ });
656
+ } catch (error) {
657
+ console.error(error, 'error');
658
+ }
659
+ }, [
660
+ null == dialogInfo ? void 0 : dialogInfo.token,
661
+ null == dialogInfo ? void 0 : dialogInfo.parentToken
662
+ ]);
663
+ if (!controller.state.serverOnline) return /*#__PURE__*/ jsx(PlaygroundThemeProvider, {
664
+ children: /*#__PURE__*/ jsx("div", {
665
+ className: "server-offline-container",
666
+ children: /*#__PURE__*/ jsxs("div", {
667
+ className: "server-offline-message",
668
+ children: [
669
+ /*#__PURE__*/ jsx(Logo, {}),
670
+ /*#__PURE__*/ jsxs("div", {
671
+ className: "server-offline-content",
672
+ children: [
673
+ /*#__PURE__*/ jsxs("div", {
674
+ className: "server-offline-icon",
675
+ children: [
676
+ /*#__PURE__*/ jsx(server_offline_background, {
677
+ className: "icon-background"
678
+ }),
679
+ /*#__PURE__*/ jsx(server_offline_foreground, {
680
+ className: "icon-foreground"
681
+ })
682
+ ]
683
+ }),
684
+ /*#__PURE__*/ jsx("h1", {
685
+ children: offlineTitle
686
+ }),
687
+ /*#__PURE__*/ jsx("p", {
688
+ className: "connection-status",
689
+ children: offlineStatusText
690
+ })
691
+ ]
692
+ })
693
+ ]
694
+ })
695
+ })
696
+ });
697
+ return /*#__PURE__*/ jsx(PlaygroundThemeProvider, {
698
+ children: /*#__PURE__*/ jsxs(Layout, {
699
+ className: "app-container playground-container",
700
+ children: [
701
+ /*#__PURE__*/ jsx(Header, _object_spread({}, dialogInfo || {})),
702
+ /*#__PURE__*/ jsx(Content, {
703
+ className: "app-content",
704
+ children: /*#__PURE__*/ jsxs(PanelGroup, {
705
+ autoSaveId: "playground-layout",
706
+ direction: isNarrowScreen ? 'vertical' : 'horizontal',
707
+ children: [
708
+ /*#__PURE__*/ jsx(Panel, {
709
+ defaultSize: isNarrowScreen ? 33 : 68,
710
+ minSize: isNarrowScreen ? 15 : 40,
711
+ className: "app-panel right-panel",
712
+ children: /*#__PURE__*/ jsxs("div", {
713
+ className: "panel-content right-panel-content",
714
+ children: [
715
+ /*#__PURE__*/ jsx(Nav, {}),
716
+ /*#__PURE__*/ jsx("div", {
717
+ className: "screenshot-viewer offline",
718
+ ref: viewRef,
719
+ children: /*#__PURE__*/ jsx("div", {
720
+ className: "screenshot-placeholder",
721
+ children: /*#__PURE__*/ jsx("h3", {
722
+ children: "Screen Preview"
723
+ })
724
+ })
725
+ })
726
+ ]
727
+ })
728
+ }),
729
+ /*#__PURE__*/ jsx(PanelResizeHandle, {
730
+ className: "panel-resize-handle"
731
+ }),
732
+ /*#__PURE__*/ jsx(Panel, {
733
+ defaultSize: isNarrowScreen ? 67 : 32,
734
+ maxSize: isNarrowScreen ? 85 : 60,
735
+ minSize: isNarrowScreen ? 67 : 25,
736
+ className: "app-panel left-panel",
737
+ children: /*#__PURE__*/ jsxs("div", {
738
+ className: "panel-content left-panel-content",
739
+ ref: rightRef,
740
+ children: [
741
+ /*#__PURE__*/ jsx("div", {
742
+ className: "playground-panel-header",
743
+ children: /*#__PURE__*/ jsxs("div", {
744
+ className: "header-row",
745
+ children: [
746
+ /*#__PURE__*/ jsx(Logo, {}),
747
+ /*#__PURE__*/ jsx(NavActions, {
748
+ showTooltipWhenEmpty: false,
749
+ showModelName: false,
750
+ playgroundSDK: controller.state.playgroundSDK
751
+ })
752
+ ]
753
+ })
754
+ }),
755
+ /*#__PURE__*/ jsx("div", {
756
+ className: "playground-panel-playground",
757
+ children: /*#__PURE__*/ jsx(PlaygroundConversationPanel, {
758
+ controller: controller,
759
+ appVersion: appVersion,
760
+ branding: branding,
761
+ playgroundConfig: playgroundConfig,
762
+ title: title,
763
+ onHumanUse: onHumanUse
764
+ })
765
+ })
766
+ ]
767
+ })
768
+ })
769
+ ]
770
+ })
771
+ })
772
+ ]
773
+ })
774
+ });
775
+ }
776
+ export { PlaygroundApp };