@midscene/visualizer 0.27.7-beta-20250905094830.0 → 0.27.7-beta-20250908085836.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/component/playground/FormField.mjs +41 -2
- package/dist/es/component/playground/PromptInput.mjs +38 -21
- package/dist/es/component/playground/ServiceModeControl.mjs +7 -2
- package/dist/es/component/playground/playground-utils.mjs +2 -94
- package/dist/es/component/playground/types.mjs +8 -7
- package/dist/es/component/playground/useServerValid.mjs +5 -2
- package/dist/es/index.mjs +2 -3
- package/dist/lib/component/playground/FormField.js +44 -2
- package/dist/lib/component/playground/PromptInput.js +37 -20
- package/dist/lib/component/playground/ServiceModeControl.js +7 -2
- package/dist/lib/component/playground/playground-utils.js +5 -124
- package/dist/lib/component/playground/types.js +8 -7
- package/dist/lib/component/playground/useServerValid.js +5 -2
- package/dist/lib/index.js +10 -41
- package/dist/types/component/playground/FormField.d.ts +1 -0
- package/dist/types/component/playground/playground-utils.d.ts +2 -22
- package/dist/types/component/playground/types.d.ts +15 -1
- package/dist/types/index.d.ts +1 -2
- package/package.json +5 -4
- package/dist/es/component/playground/playground-execution.mjs +0 -112
- package/dist/lib/component/playground/playground-execution.js +0 -152
- package/dist/types/component/playground/playground-execution.d.ts +0 -5
|
@@ -20,6 +20,7 @@ const TextField = (param)=>{
|
|
|
20
20
|
style: {
|
|
21
21
|
marginBottom
|
|
22
22
|
},
|
|
23
|
+
colon: false,
|
|
23
24
|
children: /*#__PURE__*/ jsx(Input, {
|
|
24
25
|
placeholder: placeholder
|
|
25
26
|
})
|
|
@@ -43,6 +44,7 @@ const LocateField = (param)=>{
|
|
|
43
44
|
style: {
|
|
44
45
|
marginBottom
|
|
45
46
|
},
|
|
47
|
+
colon: false,
|
|
46
48
|
children: /*#__PURE__*/ jsx(TextArea, {
|
|
47
49
|
rows: 2,
|
|
48
50
|
placeholder: placeholder
|
|
@@ -51,7 +53,8 @@ const LocateField = (param)=>{
|
|
|
51
53
|
};
|
|
52
54
|
const EnumField = (param)=>{
|
|
53
55
|
let { name, label, fieldSchema, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
54
|
-
|
|
56
|
+
var _fieldSchema__def;
|
|
57
|
+
const enumValues = (null == (_fieldSchema__def = fieldSchema._def) ? void 0 : _fieldSchema__def.values) || [];
|
|
55
58
|
const selectOptions = enumValues.map((value)=>({
|
|
56
59
|
value,
|
|
57
60
|
label: value.charAt(0).toUpperCase() + value.slice(1)
|
|
@@ -71,6 +74,7 @@ const EnumField = (param)=>{
|
|
|
71
74
|
style: {
|
|
72
75
|
marginBottom
|
|
73
76
|
},
|
|
77
|
+
colon: false,
|
|
74
78
|
children: /*#__PURE__*/ jsx(Select, {
|
|
75
79
|
placeholder: customPlaceholder || `Select ${name}`,
|
|
76
80
|
options: selectOptions
|
|
@@ -110,6 +114,7 @@ const NumberField = (param)=>{
|
|
|
110
114
|
flex: 'distance' === name ? 1 : void 0,
|
|
111
115
|
marginBottom
|
|
112
116
|
},
|
|
117
|
+
colon: false,
|
|
113
118
|
children: /*#__PURE__*/ jsx(InputNumber, {
|
|
114
119
|
placeholder: placeholderValue.toString(),
|
|
115
120
|
min: min,
|
|
@@ -121,4 +126,38 @@ const NumberField = (param)=>{
|
|
|
121
126
|
})
|
|
122
127
|
}, name);
|
|
123
128
|
};
|
|
124
|
-
|
|
129
|
+
const BooleanField = (param)=>{
|
|
130
|
+
let { name, label, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
131
|
+
const selectOptions = [
|
|
132
|
+
{
|
|
133
|
+
value: true,
|
|
134
|
+
label: 'True'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value: false,
|
|
138
|
+
label: 'False'
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
return /*#__PURE__*/ jsx(Form.Item, {
|
|
142
|
+
name: [
|
|
143
|
+
'params',
|
|
144
|
+
name
|
|
145
|
+
],
|
|
146
|
+
label: renderLabel(label, !isRequired),
|
|
147
|
+
rules: isRequired ? [
|
|
148
|
+
{
|
|
149
|
+
required: true,
|
|
150
|
+
message: `Please select ${name}`
|
|
151
|
+
}
|
|
152
|
+
] : [],
|
|
153
|
+
style: {
|
|
154
|
+
marginBottom
|
|
155
|
+
},
|
|
156
|
+
colon: false,
|
|
157
|
+
children: /*#__PURE__*/ jsx(Select, {
|
|
158
|
+
placeholder: customPlaceholder || `Select ${name}`,
|
|
159
|
+
options: selectOptions
|
|
160
|
+
})
|
|
161
|
+
}, name);
|
|
162
|
+
};
|
|
163
|
+
export { BooleanField, EnumField, LocateField, NumberField, TextField };
|
|
@@ -4,7 +4,7 @@ import { Button, Dropdown, Form, Input, Radio, Space, Tooltip } from "antd";
|
|
|
4
4
|
import react, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { useHistoryStore } from "../store/history.mjs";
|
|
6
6
|
import { ConfigSelector } from "./ConfigSelector.mjs";
|
|
7
|
-
import { EnumField, LocateField, NumberField, TextField } from "./FormField.mjs";
|
|
7
|
+
import { BooleanField, EnumField, LocateField, NumberField, TextField } from "./FormField.mjs";
|
|
8
8
|
import { HistorySelector } from "./HistorySelector.mjs";
|
|
9
9
|
import { apiMetadata, defaultMainButtons } from "./playground-constants.mjs";
|
|
10
10
|
import { actionNameForType, getPlaceholderForType, isRunButtonEnabled as external_playground_utils_mjs_isRunButtonEnabled } from "./playground-utils.mjs";
|
|
@@ -85,8 +85,9 @@ const PromptInput = (param)=>{
|
|
|
85
85
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
86
86
|
if ((null == action ? void 0 : action.paramSchema) && isZodObjectSchema(action.paramSchema)) {
|
|
87
87
|
const schema = action.paramSchema;
|
|
88
|
-
const
|
|
89
|
-
|
|
88
|
+
const shape = schema.shape || {};
|
|
89
|
+
const hasLocateField = Object.keys(shape).some((key)=>{
|
|
90
|
+
const field = shape[key];
|
|
90
91
|
const { actualField } = unwrapZodType(field);
|
|
91
92
|
return isLocateField(actualField);
|
|
92
93
|
});
|
|
@@ -239,7 +240,8 @@ const PromptInput = (param)=>{
|
|
|
239
240
|
const schema = action.paramSchema;
|
|
240
241
|
const shape = schema.shape || {};
|
|
241
242
|
Object.keys(shape).forEach((key)=>{
|
|
242
|
-
|
|
243
|
+
var _values_params;
|
|
244
|
+
const paramValue = null == (_values_params = values.params) ? void 0 : _values_params[key];
|
|
243
245
|
if (null != paramValue && '' !== paramValue) {
|
|
244
246
|
const field = shape[key];
|
|
245
247
|
const { actualField } = unwrapZodType(field);
|
|
@@ -285,12 +287,15 @@ const PromptInput = (param)=>{
|
|
|
285
287
|
e.stopPropagation();
|
|
286
288
|
} else if ('Enter' === e.key) setTimeout(()=>{
|
|
287
289
|
if (textAreaRef.current) {
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
var _textAreaRef_current_resizableTextArea;
|
|
291
|
+
const textarea = null == (_textAreaRef_current_resizableTextArea = textAreaRef.current.resizableTextArea) ? void 0 : _textAreaRef_current_resizableTextArea.textArea;
|
|
292
|
+
if (textarea) {
|
|
293
|
+
const selectionStart = textarea.selectionStart;
|
|
294
|
+
const value = textarea.value;
|
|
295
|
+
const lastNewlineIndex = value.lastIndexOf('\n');
|
|
296
|
+
const isAtLastLine = -1 === lastNewlineIndex || selectionStart > lastNewlineIndex;
|
|
297
|
+
if (isAtLastLine) textarea.scrollTop = textarea.scrollHeight;
|
|
298
|
+
}
|
|
294
299
|
}
|
|
295
300
|
}, 0);
|
|
296
301
|
}, [
|
|
@@ -321,10 +326,10 @@ const PromptInput = (param)=>{
|
|
|
321
326
|
const { actualField } = unwrapZodType(field);
|
|
322
327
|
const isLocateFieldFlag = isLocateField(actualField);
|
|
323
328
|
const placeholderText = (()=>{
|
|
324
|
-
var
|
|
325
|
-
const
|
|
326
|
-
if (null == (
|
|
327
|
-
if (
|
|
329
|
+
var _fieldWithRuntime__def;
|
|
330
|
+
const fieldWithRuntime = actualField;
|
|
331
|
+
if (null == (_fieldWithRuntime__def = fieldWithRuntime._def) ? void 0 : _fieldWithRuntime__def.description) return fieldWithRuntime._def.description;
|
|
332
|
+
if (fieldWithRuntime.description) return fieldWithRuntime.description;
|
|
328
333
|
if (actionSpace) {
|
|
329
334
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
330
335
|
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
@@ -358,19 +363,28 @@ const PromptInput = (param)=>{
|
|
|
358
363
|
});
|
|
359
364
|
}
|
|
360
365
|
const fields = [];
|
|
361
|
-
schemaKeys.
|
|
362
|
-
|
|
366
|
+
const sortedKeys = schemaKeys.sort((keyA, keyB)=>{
|
|
367
|
+
const fieldSchemaA = shape[keyA];
|
|
368
|
+
const fieldSchemaB = shape[keyB];
|
|
369
|
+
const { isOptional: isOptionalA } = unwrapZodType(fieldSchemaA);
|
|
370
|
+
const { isOptional: isOptionalB } = unwrapZodType(fieldSchemaB);
|
|
371
|
+
if (!isOptionalA && isOptionalB) return -1;
|
|
372
|
+
if (isOptionalA && !isOptionalB) return 1;
|
|
373
|
+
return 0;
|
|
374
|
+
});
|
|
375
|
+
sortedKeys.forEach((key, index)=>{
|
|
376
|
+
var _actualField__def, _actualField__def1, _actualField__def2;
|
|
363
377
|
const fieldSchema = shape[key];
|
|
364
378
|
const { actualField, isOptional } = unwrapZodType(fieldSchema);
|
|
365
379
|
const isLocateFieldFlag = isLocateField(actualField);
|
|
366
380
|
const label = key.charAt(0).toUpperCase() + key.slice(1);
|
|
367
381
|
const isRequired = !isOptional;
|
|
368
|
-
const marginBottom = index ===
|
|
382
|
+
const marginBottom = index === sortedKeys.length - 1 ? 0 : 12;
|
|
369
383
|
const placeholder = (()=>{
|
|
370
|
-
var
|
|
371
|
-
const
|
|
372
|
-
if (null == (
|
|
373
|
-
if (
|
|
384
|
+
var _fieldWithRuntime__def;
|
|
385
|
+
const fieldWithRuntime = actualField;
|
|
386
|
+
if (null == (_fieldWithRuntime__def = fieldWithRuntime._def) ? void 0 : _fieldWithRuntime__def.description) return fieldWithRuntime._def.description;
|
|
387
|
+
if (fieldWithRuntime.description) return fieldWithRuntime.description;
|
|
374
388
|
if (actionSpace) {
|
|
375
389
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
376
390
|
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
@@ -400,6 +414,9 @@ const PromptInput = (param)=>{
|
|
|
400
414
|
else if ((null == (_actualField__def1 = actualField._def) ? void 0 : _actualField__def1.typeName) === 'ZodNumber') fields.push(/*#__PURE__*/ jsx(NumberField, {
|
|
401
415
|
...fieldProps
|
|
402
416
|
}, key));
|
|
417
|
+
else if ((null == (_actualField__def2 = actualField._def) ? void 0 : _actualField__def2.typeName) === 'ZodBoolean') fields.push(/*#__PURE__*/ jsx(BooleanField, {
|
|
418
|
+
...fieldProps
|
|
419
|
+
}, key));
|
|
403
420
|
else fields.push(/*#__PURE__*/ jsx(TextField, {
|
|
404
421
|
...fieldProps
|
|
405
422
|
}, key));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PlaygroundSDK } from "@midscene/playground";
|
|
2
3
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
3
4
|
import { Button, Tooltip } from "antd";
|
|
4
5
|
import { useEffect } from "react";
|
|
5
6
|
import { EnvConfig } from "../env-config.mjs";
|
|
6
7
|
import { iconForStatus } from "../misc.mjs";
|
|
7
8
|
import { useEnvConfig } from "../store/store.mjs";
|
|
8
|
-
import { overrideServerConfig } from "./playground-utils.mjs";
|
|
9
9
|
import { useServerValid } from "./useServerValid.mjs";
|
|
10
10
|
import "./index.css";
|
|
11
11
|
const TITLE_TEXT = {
|
|
@@ -59,7 +59,12 @@ const ServiceModeControl = (param)=>{
|
|
|
59
59
|
};
|
|
60
60
|
useEffect(()=>{
|
|
61
61
|
overrideAIConfig(config);
|
|
62
|
-
if ('Server' === serviceMode)
|
|
62
|
+
if ('Server' === serviceMode) {
|
|
63
|
+
const playgroundSDK = new PlaygroundSDK({
|
|
64
|
+
type: 'remote-execution'
|
|
65
|
+
});
|
|
66
|
+
playgroundSDK.overrideConfig(config);
|
|
67
|
+
}
|
|
63
68
|
}, [
|
|
64
69
|
config,
|
|
65
70
|
serviceMode,
|
|
@@ -1,86 +1,5 @@
|
|
|
1
|
-
import { StaticPage, StaticPageAgent } from "@midscene/
|
|
2
|
-
import { PLAYGROUND_SERVER_PORT } from "@midscene/shared/constants";
|
|
1
|
+
import { StaticPage, StaticPageAgent } from "@midscene/web/static";
|
|
3
2
|
import { isZodObjectSchema, unwrapZodType } from "./types.mjs";
|
|
4
|
-
const serverBase = `http://localhost:${PLAYGROUND_SERVER_PORT}`;
|
|
5
|
-
const checkServerStatus = async ()=>{
|
|
6
|
-
try {
|
|
7
|
-
const res = await fetch(`${serverBase}/status`);
|
|
8
|
-
return 200 === res.status;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const requestPlaygroundServer = async function(context, type, prompt) {
|
|
14
|
-
let { requestId, deepThink, params, screenshotIncluded, domIncluded } = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {};
|
|
15
|
-
const payload = {
|
|
16
|
-
context,
|
|
17
|
-
type,
|
|
18
|
-
prompt
|
|
19
|
-
};
|
|
20
|
-
if (requestId) payload.requestId = requestId;
|
|
21
|
-
if (deepThink) payload.deepThink = deepThink;
|
|
22
|
-
if (void 0 !== screenshotIncluded) payload.screenshotIncluded = screenshotIncluded;
|
|
23
|
-
if (void 0 !== domIncluded) payload.domIncluded = domIncluded;
|
|
24
|
-
if (params) payload.params = params;
|
|
25
|
-
const res = await fetch(`${serverBase}/execute`, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: {
|
|
28
|
-
'Content-Type': 'application/json'
|
|
29
|
-
},
|
|
30
|
-
body: JSON.stringify(payload)
|
|
31
|
-
});
|
|
32
|
-
return res.json();
|
|
33
|
-
};
|
|
34
|
-
const overrideServerConfig = async (aiConfig)=>fetch(`${serverBase}/config`, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: {
|
|
37
|
-
'Content-Type': 'application/json'
|
|
38
|
-
},
|
|
39
|
-
body: JSON.stringify({
|
|
40
|
-
aiConfig
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
const cancelTask = async (requestId)=>{
|
|
44
|
-
try {
|
|
45
|
-
const res = await fetch(`${serverBase}/cancel/${requestId}`);
|
|
46
|
-
return res.json();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error('Failed to cancel task:', error);
|
|
49
|
-
return {
|
|
50
|
-
error: 'Failed to cancel task'
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const getTaskProgress = async (requestId)=>{
|
|
55
|
-
try {
|
|
56
|
-
const response = await fetch(`${serverBase}/task-progress/${requestId}`);
|
|
57
|
-
return await response.json();
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.error('Failed to poll task progress:', error);
|
|
60
|
-
return {
|
|
61
|
-
tip: null
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const getActionSpace = async (context)=>{
|
|
66
|
-
try {
|
|
67
|
-
if (!context) return [];
|
|
68
|
-
const response = await fetch(`${serverBase}/action-space`, {
|
|
69
|
-
method: 'POST',
|
|
70
|
-
headers: {
|
|
71
|
-
'Content-Type': 'application/json'
|
|
72
|
-
},
|
|
73
|
-
body: JSON.stringify({
|
|
74
|
-
context
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
if (response.ok) return await response.json();
|
|
78
|
-
return [];
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error('Failed to get action space:', error);
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
3
|
const actionNameForType = (type)=>{
|
|
85
4
|
const typeWithoutAi = type.startsWith('ai') ? type.slice(2) : type;
|
|
86
5
|
const fullName = typeWithoutAi.replace(/([A-Z])/g, ' $1').trim();
|
|
@@ -92,11 +11,6 @@ const staticAgentFromContext = (context)=>{
|
|
|
92
11
|
const page = new StaticPage(context);
|
|
93
12
|
return new StaticPageAgent(page);
|
|
94
13
|
};
|
|
95
|
-
const formatErrorMessage = (e)=>{
|
|
96
|
-
const errorMessage = (null == e ? void 0 : e.message) || '';
|
|
97
|
-
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
|
|
98
|
-
return errorMessage || 'Unknown error';
|
|
99
|
-
};
|
|
100
14
|
const getPlaceholderForType = (type)=>{
|
|
101
15
|
if ('aiQuery' === type) return 'What do you want to query?';
|
|
102
16
|
if ('aiAssert' === type) return 'What do you want to assert?';
|
|
@@ -115,12 +29,6 @@ const getPlaceholderForType = (type)=>{
|
|
|
115
29
|
if ('aiWaitFor' === type) return 'What condition do you want to wait for?';
|
|
116
30
|
return 'What do you want to do?';
|
|
117
31
|
};
|
|
118
|
-
const blankResult = {
|
|
119
|
-
result: null,
|
|
120
|
-
dump: null,
|
|
121
|
-
reportHTML: null,
|
|
122
|
-
error: null
|
|
123
|
-
};
|
|
124
32
|
const isRunButtonEnabled = (runButtonEnabled, needsStructuredParams, params, actionSpace, selectedType, promptValue)=>{
|
|
125
33
|
if (!runButtonEnabled) return false;
|
|
126
34
|
const needsAnyInput = (()=>{
|
|
@@ -155,4 +63,4 @@ const isRunButtonEnabled = (runButtonEnabled, needsStructuredParams, params, act
|
|
|
155
63
|
}
|
|
156
64
|
return promptValue.trim().length > 0;
|
|
157
65
|
};
|
|
158
|
-
export { actionNameForType,
|
|
66
|
+
export { actionNameForType, getPlaceholderForType, isRunButtonEnabled, staticAgentFromContext };
|
|
@@ -6,7 +6,8 @@ const VALIDATION_CONSTANTS = {
|
|
|
6
6
|
OBJECT: 'ZodObject',
|
|
7
7
|
ENUM: 'ZodEnum',
|
|
8
8
|
NUMBER: 'ZodNumber',
|
|
9
|
-
STRING: 'ZodString'
|
|
9
|
+
STRING: 'ZodString',
|
|
10
|
+
BOOLEAN: 'ZodBoolean'
|
|
10
11
|
},
|
|
11
12
|
FIELD_FLAGS: {
|
|
12
13
|
LOCATION: 'midscene_location_field_flag'
|
|
@@ -20,24 +21,24 @@ const VALIDATION_CONSTANTS = {
|
|
|
20
21
|
const isZodObjectSchema = (schema)=>'object' == typeof schema && null !== schema && ('shape' in schema || 'ZodObject' === schema.type);
|
|
21
22
|
const isLocateField = (field)=>{
|
|
22
23
|
var _field__def;
|
|
23
|
-
const
|
|
24
|
+
const fieldWithRuntime = field;
|
|
24
25
|
if ((null == (_field__def = field._def) ? void 0 : _field__def.typeName) === VALIDATION_CONSTANTS.ZOD_TYPES.OBJECT) {
|
|
25
26
|
var _field__def1;
|
|
26
27
|
let shape;
|
|
27
28
|
if (field._def.shape) shape = 'function' == typeof field._def.shape ? field._def.shape() : field._def.shape;
|
|
28
|
-
if (!shape &&
|
|
29
|
+
if (!shape && fieldWithRuntime.shape) shape = fieldWithRuntime.shape;
|
|
29
30
|
if (shape && VALIDATION_CONSTANTS.FIELD_FLAGS.LOCATION in shape) return true;
|
|
30
|
-
const description = (null == (_field__def1 = field._def) ? void 0 : _field__def1.description) ||
|
|
31
|
+
const description = (null == (_field__def1 = field._def) ? void 0 : _field__def1.description) || fieldWithRuntime.description || '';
|
|
31
32
|
if ('string' == typeof description && description.toLowerCase().includes('input field')) return true;
|
|
32
33
|
}
|
|
33
34
|
if ('object' == typeof field && null !== field) {
|
|
34
|
-
var
|
|
35
|
-
const description =
|
|
35
|
+
var _fieldWithRuntime__def;
|
|
36
|
+
const description = fieldWithRuntime.description || (null == (_fieldWithRuntime__def = fieldWithRuntime._def) ? void 0 : _fieldWithRuntime__def.description) || '';
|
|
36
37
|
if ('string' == typeof description) {
|
|
37
38
|
const desc = description.toLowerCase();
|
|
38
39
|
if (desc.includes('input field') || desc.includes('element') || desc.includes('locate')) return true;
|
|
39
40
|
}
|
|
40
|
-
if ('ZodObject' ===
|
|
41
|
+
if ('ZodObject' === fieldWithRuntime.typeName || 'ZodObject' === fieldWithRuntime.type) return 'string' == typeof description && description.toLowerCase().includes('input field');
|
|
41
42
|
}
|
|
42
43
|
return false;
|
|
43
44
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { PlaygroundSDK } from "@midscene/playground";
|
|
1
2
|
import { useEffect, useState } from "react";
|
|
2
3
|
import { useEnvConfig } from "../store/store.mjs";
|
|
3
|
-
import { checkServerStatus } from "./playground-utils.mjs";
|
|
4
4
|
const useServerValid = function() {
|
|
5
5
|
let shouldRun = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : true;
|
|
6
6
|
const [serverValid, setServerValid] = useState(true);
|
|
@@ -10,7 +10,10 @@ const useServerValid = function() {
|
|
|
10
10
|
if (!shouldRun) return;
|
|
11
11
|
Promise.resolve((async ()=>{
|
|
12
12
|
while(!interruptFlag){
|
|
13
|
-
const
|
|
13
|
+
const playgroundSDK = new PlaygroundSDK({
|
|
14
|
+
type: 'remote-execution'
|
|
15
|
+
});
|
|
16
|
+
const status = await playgroundSDK.checkStatus();
|
|
14
17
|
status ? setServerValid(true) : setServerValid(false);
|
|
15
18
|
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
16
19
|
}
|
package/dist/es/index.mjs
CHANGED
|
@@ -13,8 +13,7 @@ import { PromptInput } from "./component/playground/PromptInput.mjs";
|
|
|
13
13
|
import { Player } from "./component/player.mjs";
|
|
14
14
|
import { Blackboard } from "./component/blackboard.mjs";
|
|
15
15
|
import { GithubStar } from "./component/github-star.mjs";
|
|
16
|
-
import { actionNameForType,
|
|
17
|
-
import { executeAction, formatErrorMessage, validateStructuredParams } from "./component/playground/playground-execution.mjs";
|
|
16
|
+
import { actionNameForType, getPlaceholderForType, staticAgentFromContext } from "./component/playground/playground-utils.mjs";
|
|
18
17
|
import { filterBase64Value, timeStr } from "./utils.mjs";
|
|
19
18
|
import shiny_text from "./component/shiny-text.mjs";
|
|
20
|
-
export { Blackboard, ContextPreview, EnvConfig, GithubStar, Logo, Player, PlaygroundResultView, PromptInput, ServiceModeControl, shiny_text as ShinyText, actionNameForType, allScriptsFromDump,
|
|
19
|
+
export { Blackboard, ContextPreview, EnvConfig, GithubStar, Logo, Player, PlaygroundResultView, PromptInput, ServiceModeControl, shiny_text as ShinyText, actionNameForType, allScriptsFromDump, colorForName, filterBase64Value, generateAnimationScripts, getPlaceholderForType, globalThemeConfig, highlightColorForType, iconForStatus, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useServerValid };
|
|
@@ -24,8 +24,9 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
27
|
+
BooleanField: ()=>BooleanField,
|
|
28
28
|
NumberField: ()=>NumberField,
|
|
29
|
+
TextField: ()=>TextField,
|
|
29
30
|
LocateField: ()=>LocateField,
|
|
30
31
|
EnumField: ()=>EnumField
|
|
31
32
|
});
|
|
@@ -51,6 +52,7 @@ const TextField = (param)=>{
|
|
|
51
52
|
style: {
|
|
52
53
|
marginBottom
|
|
53
54
|
},
|
|
55
|
+
colon: false,
|
|
54
56
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Input, {
|
|
55
57
|
placeholder: placeholder
|
|
56
58
|
})
|
|
@@ -74,6 +76,7 @@ const LocateField = (param)=>{
|
|
|
74
76
|
style: {
|
|
75
77
|
marginBottom
|
|
76
78
|
},
|
|
79
|
+
colon: false,
|
|
77
80
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TextArea, {
|
|
78
81
|
rows: 2,
|
|
79
82
|
placeholder: placeholder
|
|
@@ -82,7 +85,8 @@ const LocateField = (param)=>{
|
|
|
82
85
|
};
|
|
83
86
|
const EnumField = (param)=>{
|
|
84
87
|
let { name, label, fieldSchema, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
85
|
-
|
|
88
|
+
var _fieldSchema__def;
|
|
89
|
+
const enumValues = (null == (_fieldSchema__def = fieldSchema._def) ? void 0 : _fieldSchema__def.values) || [];
|
|
86
90
|
const selectOptions = enumValues.map((value)=>({
|
|
87
91
|
value,
|
|
88
92
|
label: value.charAt(0).toUpperCase() + value.slice(1)
|
|
@@ -102,6 +106,7 @@ const EnumField = (param)=>{
|
|
|
102
106
|
style: {
|
|
103
107
|
marginBottom
|
|
104
108
|
},
|
|
109
|
+
colon: false,
|
|
105
110
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
|
|
106
111
|
placeholder: customPlaceholder || `Select ${name}`,
|
|
107
112
|
options: selectOptions
|
|
@@ -141,6 +146,7 @@ const NumberField = (param)=>{
|
|
|
141
146
|
flex: 'distance' === name ? 1 : void 0,
|
|
142
147
|
marginBottom
|
|
143
148
|
},
|
|
149
|
+
colon: false,
|
|
144
150
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.InputNumber, {
|
|
145
151
|
placeholder: placeholderValue.toString(),
|
|
146
152
|
min: min,
|
|
@@ -152,11 +158,47 @@ const NumberField = (param)=>{
|
|
|
152
158
|
})
|
|
153
159
|
}, name);
|
|
154
160
|
};
|
|
161
|
+
const BooleanField = (param)=>{
|
|
162
|
+
let { name, label, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
163
|
+
const selectOptions = [
|
|
164
|
+
{
|
|
165
|
+
value: true,
|
|
166
|
+
label: 'True'
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
value: false,
|
|
170
|
+
label: 'False'
|
|
171
|
+
}
|
|
172
|
+
];
|
|
173
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
174
|
+
name: [
|
|
175
|
+
'params',
|
|
176
|
+
name
|
|
177
|
+
],
|
|
178
|
+
label: renderLabel(label, !isRequired),
|
|
179
|
+
rules: isRequired ? [
|
|
180
|
+
{
|
|
181
|
+
required: true,
|
|
182
|
+
message: `Please select ${name}`
|
|
183
|
+
}
|
|
184
|
+
] : [],
|
|
185
|
+
style: {
|
|
186
|
+
marginBottom
|
|
187
|
+
},
|
|
188
|
+
colon: false,
|
|
189
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
|
|
190
|
+
placeholder: customPlaceholder || `Select ${name}`,
|
|
191
|
+
options: selectOptions
|
|
192
|
+
})
|
|
193
|
+
}, name);
|
|
194
|
+
};
|
|
195
|
+
exports.BooleanField = __webpack_exports__.BooleanField;
|
|
155
196
|
exports.EnumField = __webpack_exports__.EnumField;
|
|
156
197
|
exports.LocateField = __webpack_exports__.LocateField;
|
|
157
198
|
exports.NumberField = __webpack_exports__.NumberField;
|
|
158
199
|
exports.TextField = __webpack_exports__.TextField;
|
|
159
200
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
201
|
+
"BooleanField",
|
|
160
202
|
"EnumField",
|
|
161
203
|
"LocateField",
|
|
162
204
|
"NumberField",
|
|
@@ -123,8 +123,9 @@ const PromptInput = (param)=>{
|
|
|
123
123
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
124
124
|
if ((null == action ? void 0 : action.paramSchema) && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
125
125
|
const schema = action.paramSchema;
|
|
126
|
-
const
|
|
127
|
-
|
|
126
|
+
const shape = schema.shape || {};
|
|
127
|
+
const hasLocateField = Object.keys(shape).some((key)=>{
|
|
128
|
+
const field = shape[key];
|
|
128
129
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
129
130
|
return (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
130
131
|
});
|
|
@@ -277,7 +278,8 @@ const PromptInput = (param)=>{
|
|
|
277
278
|
const schema = action.paramSchema;
|
|
278
279
|
const shape = schema.shape || {};
|
|
279
280
|
Object.keys(shape).forEach((key)=>{
|
|
280
|
-
|
|
281
|
+
var _values_params;
|
|
282
|
+
const paramValue = null == (_values_params = values.params) ? void 0 : _values_params[key];
|
|
281
283
|
if (null != paramValue && '' !== paramValue) {
|
|
282
284
|
const field = shape[key];
|
|
283
285
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
@@ -323,12 +325,15 @@ const PromptInput = (param)=>{
|
|
|
323
325
|
e.stopPropagation();
|
|
324
326
|
} else if ('Enter' === e.key) setTimeout(()=>{
|
|
325
327
|
if (textAreaRef.current) {
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
var _textAreaRef_current_resizableTextArea;
|
|
329
|
+
const textarea = null == (_textAreaRef_current_resizableTextArea = textAreaRef.current.resizableTextArea) ? void 0 : _textAreaRef_current_resizableTextArea.textArea;
|
|
330
|
+
if (textarea) {
|
|
331
|
+
const selectionStart = textarea.selectionStart;
|
|
332
|
+
const value = textarea.value;
|
|
333
|
+
const lastNewlineIndex = value.lastIndexOf('\n');
|
|
334
|
+
const isAtLastLine = -1 === lastNewlineIndex || selectionStart > lastNewlineIndex;
|
|
335
|
+
if (isAtLastLine) textarea.scrollTop = textarea.scrollHeight;
|
|
336
|
+
}
|
|
332
337
|
}
|
|
333
338
|
}, 0);
|
|
334
339
|
}, [
|
|
@@ -359,10 +364,10 @@ const PromptInput = (param)=>{
|
|
|
359
364
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
360
365
|
const isLocateFieldFlag = (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
361
366
|
const placeholderText = (()=>{
|
|
362
|
-
var
|
|
363
|
-
const
|
|
364
|
-
if (null == (
|
|
365
|
-
if (
|
|
367
|
+
var _fieldWithRuntime__def;
|
|
368
|
+
const fieldWithRuntime = actualField;
|
|
369
|
+
if (null == (_fieldWithRuntime__def = fieldWithRuntime._def) ? void 0 : _fieldWithRuntime__def.description) return fieldWithRuntime._def.description;
|
|
370
|
+
if (fieldWithRuntime.description) return fieldWithRuntime.description;
|
|
366
371
|
if (actionSpace) {
|
|
367
372
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
368
373
|
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
@@ -396,19 +401,28 @@ const PromptInput = (param)=>{
|
|
|
396
401
|
});
|
|
397
402
|
}
|
|
398
403
|
const fields = [];
|
|
399
|
-
schemaKeys.
|
|
400
|
-
|
|
404
|
+
const sortedKeys = schemaKeys.sort((keyA, keyB)=>{
|
|
405
|
+
const fieldSchemaA = shape[keyA];
|
|
406
|
+
const fieldSchemaB = shape[keyB];
|
|
407
|
+
const { isOptional: isOptionalA } = (0, external_types_js_namespaceObject.unwrapZodType)(fieldSchemaA);
|
|
408
|
+
const { isOptional: isOptionalB } = (0, external_types_js_namespaceObject.unwrapZodType)(fieldSchemaB);
|
|
409
|
+
if (!isOptionalA && isOptionalB) return -1;
|
|
410
|
+
if (isOptionalA && !isOptionalB) return 1;
|
|
411
|
+
return 0;
|
|
412
|
+
});
|
|
413
|
+
sortedKeys.forEach((key, index)=>{
|
|
414
|
+
var _actualField__def, _actualField__def1, _actualField__def2;
|
|
401
415
|
const fieldSchema = shape[key];
|
|
402
416
|
const { actualField, isOptional } = (0, external_types_js_namespaceObject.unwrapZodType)(fieldSchema);
|
|
403
417
|
const isLocateFieldFlag = (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
404
418
|
const label = key.charAt(0).toUpperCase() + key.slice(1);
|
|
405
419
|
const isRequired = !isOptional;
|
|
406
|
-
const marginBottom = index ===
|
|
420
|
+
const marginBottom = index === sortedKeys.length - 1 ? 0 : 12;
|
|
407
421
|
const placeholder = (()=>{
|
|
408
|
-
var
|
|
409
|
-
const
|
|
410
|
-
if (null == (
|
|
411
|
-
if (
|
|
422
|
+
var _fieldWithRuntime__def;
|
|
423
|
+
const fieldWithRuntime = actualField;
|
|
424
|
+
if (null == (_fieldWithRuntime__def = fieldWithRuntime._def) ? void 0 : _fieldWithRuntime__def.description) return fieldWithRuntime._def.description;
|
|
425
|
+
if (fieldWithRuntime.description) return fieldWithRuntime.description;
|
|
412
426
|
if (actionSpace) {
|
|
413
427
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
414
428
|
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
@@ -438,6 +452,9 @@ const PromptInput = (param)=>{
|
|
|
438
452
|
else if ((null == (_actualField__def1 = actualField._def) ? void 0 : _actualField__def1.typeName) === 'ZodNumber') fields.push(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FormField_js_namespaceObject.NumberField, {
|
|
439
453
|
...fieldProps
|
|
440
454
|
}, key));
|
|
455
|
+
else if ((null == (_actualField__def2 = actualField._def) ? void 0 : _actualField__def2.typeName) === 'ZodBoolean') fields.push(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FormField_js_namespaceObject.BooleanField, {
|
|
456
|
+
...fieldProps
|
|
457
|
+
}, key));
|
|
441
458
|
else fields.push(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FormField_js_namespaceObject.TextField, {
|
|
442
459
|
...fieldProps
|
|
443
460
|
}, key));
|
|
@@ -27,13 +27,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
ServiceModeControl: ()=>ServiceModeControl
|
|
28
28
|
});
|
|
29
29
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
const playground_namespaceObject = require("@midscene/playground");
|
|
30
31
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
31
32
|
const external_antd_namespaceObject = require("antd");
|
|
32
33
|
const external_react_namespaceObject = require("react");
|
|
33
34
|
const external_env_config_js_namespaceObject = require("../env-config.js");
|
|
34
35
|
const external_misc_js_namespaceObject = require("../misc.js");
|
|
35
36
|
const store_js_namespaceObject = require("../store/store.js");
|
|
36
|
-
const external_playground_utils_js_namespaceObject = require("./playground-utils.js");
|
|
37
37
|
const external_useServerValid_js_namespaceObject = require("./useServerValid.js");
|
|
38
38
|
require("./index.css");
|
|
39
39
|
const TITLE_TEXT = {
|
|
@@ -87,7 +87,12 @@ const ServiceModeControl = (param)=>{
|
|
|
87
87
|
};
|
|
88
88
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
89
89
|
(0, env_namespaceObject.overrideAIConfig)(config);
|
|
90
|
-
if ('Server' === serviceMode)
|
|
90
|
+
if ('Server' === serviceMode) {
|
|
91
|
+
const playgroundSDK = new playground_namespaceObject.PlaygroundSDK({
|
|
92
|
+
type: 'remote-execution'
|
|
93
|
+
});
|
|
94
|
+
playgroundSDK.overrideConfig(config);
|
|
95
|
+
}
|
|
91
96
|
}, [
|
|
92
97
|
config,
|
|
93
98
|
serviceMode,
|