@midscene/visualizer 0.27.5-beta-20250828012323.0 → 0.27.5-beta-20250828025824.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 +12 -10
- package/dist/es/component/playground/PromptInput.mjs +169 -32
- package/dist/es/component/playground/index.css +7 -0
- package/dist/es/component/playground/playground-execution.mjs +114 -0
- package/dist/es/component/playground/playground-utils.mjs +46 -8
- package/dist/es/component/playground/types.mjs +22 -3
- package/dist/es/index.mjs +3 -3
- package/dist/lib/component/playground/FormField.js +12 -10
- package/dist/lib/component/playground/PromptInput.js +169 -32
- package/dist/lib/component/playground/index.css +7 -0
- package/dist/lib/component/playground/playground-execution.js +154 -0
- package/dist/lib/component/playground/playground-utils.js +47 -6
- package/dist/lib/component/playground/types.js +22 -3
- package/dist/lib/index.js +11 -5
- package/dist/types/component/playground/FormField.d.ts +1 -0
- package/dist/types/component/playground/PromptInput.d.ts +1 -1
- package/dist/types/component/playground/playground-execution.d.ts +7 -0
- package/dist/types/component/playground/playground-utils.d.ts +3 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +4 -4
- package/dist/es/component/playground/useStaticPageAgent.mjs +0 -12
- package/dist/lib/component/playground/useStaticPageAgent.js +0 -49
- package/dist/types/component/playground/useStaticPageAgent.d.ts +0 -5
|
@@ -17,10 +17,29 @@ const VALIDATION_CONSTANTS = {
|
|
|
17
17
|
CHECK_INTERVAL_MS: 3000
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
const isZodObjectSchema = (schema)=>'object' == typeof schema && null !== schema && 'shape' in schema
|
|
20
|
+
const isZodObjectSchema = (schema)=>'object' == typeof schema && null !== schema && ('shape' in schema || 'ZodObject' === schema.type);
|
|
21
21
|
const isLocateField = (field)=>{
|
|
22
|
-
var _field__def
|
|
23
|
-
|
|
22
|
+
var _field__def;
|
|
23
|
+
const fieldAsAny = field;
|
|
24
|
+
if ((null == (_field__def = field._def) ? void 0 : _field__def.typeName) === VALIDATION_CONSTANTS.ZOD_TYPES.OBJECT) {
|
|
25
|
+
var _field__def1;
|
|
26
|
+
let shape;
|
|
27
|
+
if (field._def.shape) shape = 'function' == typeof field._def.shape ? field._def.shape() : field._def.shape;
|
|
28
|
+
if (!shape && fieldAsAny.shape) shape = fieldAsAny.shape;
|
|
29
|
+
if (shape && VALIDATION_CONSTANTS.FIELD_FLAGS.LOCATION in shape) return true;
|
|
30
|
+
const description = (null == (_field__def1 = field._def) ? void 0 : _field__def1.description) || fieldAsAny.description || '';
|
|
31
|
+
if ('string' == typeof description && description.toLowerCase().includes('input field')) return true;
|
|
32
|
+
}
|
|
33
|
+
if ('object' == typeof field && null !== field) {
|
|
34
|
+
var _fieldAsAny__def;
|
|
35
|
+
const description = fieldAsAny.description || (null == (_fieldAsAny__def = fieldAsAny._def) ? void 0 : _fieldAsAny__def.description) || '';
|
|
36
|
+
if ('string' == typeof description) {
|
|
37
|
+
const desc = description.toLowerCase();
|
|
38
|
+
if (desc.includes('input field') || desc.includes('element') || desc.includes('locate')) return true;
|
|
39
|
+
}
|
|
40
|
+
if ('ZodObject' === fieldAsAny.typeName || 'ZodObject' === fieldAsAny.type) return 'string' == typeof description && description.toLowerCase().includes('input field');
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
24
43
|
};
|
|
25
44
|
const unwrapZodType = (field)=>{
|
|
26
45
|
var _actualField__def, _actualField__def1, _actualField__def2;
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useStaticPageAgent } from "./component/playground/useStaticPageAgent.mjs";
|
|
2
1
|
import "./component/playground/index.css";
|
|
3
2
|
import { allScriptsFromDump, generateAnimationScripts } from "./component/replay-scripts.mjs";
|
|
4
3
|
import { useEnvConfig } from "./component/store/store.mjs";
|
|
@@ -14,7 +13,8 @@ import { PromptInput } from "./component/playground/PromptInput.mjs";
|
|
|
14
13
|
import { Player } from "./component/player.mjs";
|
|
15
14
|
import { Blackboard } from "./component/blackboard.mjs";
|
|
16
15
|
import { GithubStar } from "./component/github-star.mjs";
|
|
17
|
-
import { actionNameForType, blankResult, cancelTask, checkServerStatus,
|
|
16
|
+
import { actionNameForType, blankResult, cancelTask, checkServerStatus, getActionSpace, getPlaceholderForType, getTaskProgress, overrideServerConfig, requestPlaygroundServer, staticAgentFromContext } from "./component/playground/playground-utils.mjs";
|
|
17
|
+
import { executeAction, formatErrorMessage, validateStructuredParams } from "./component/playground/playground-execution.mjs";
|
|
18
18
|
import { filterBase64Value, timeStr } from "./utils.mjs";
|
|
19
19
|
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, blankResult, cancelTask, checkServerStatus, colorForName, filterBase64Value, formatErrorMessage, generateAnimationScripts, getPlaceholderForType, getTaskProgress, globalThemeConfig, highlightColorForType, iconForStatus, overrideServerConfig, requestPlaygroundServer, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useServerValid,
|
|
20
|
+
export { Blackboard, ContextPreview, EnvConfig, GithubStar, Logo, Player, PlaygroundResultView, PromptInput, ServiceModeControl, shiny_text as ShinyText, actionNameForType, allScriptsFromDump, blankResult, cancelTask, checkServerStatus, colorForName, executeAction, filterBase64Value, formatErrorMessage, generateAnimationScripts, getActionSpace, getPlaceholderForType, getTaskProgress, globalThemeConfig, highlightColorForType, iconForStatus, overrideServerConfig, requestPlaygroundServer, staticAgentFromContext, timeCostStrElement, timeStr, useEnvConfig, useServerValid, validateStructuredParams };
|
|
@@ -34,8 +34,8 @@ const external_antd_namespaceObject = require("antd");
|
|
|
34
34
|
const { TextArea } = external_antd_namespaceObject.Input;
|
|
35
35
|
const renderLabel = (label, isOptional)=>`${label}${isOptional ? ' (Optional)' : ''}`;
|
|
36
36
|
const TextField = (param)=>{
|
|
37
|
-
let { name, label, isRequired, marginBottom } = param;
|
|
38
|
-
const placeholder = `Enter ${name}`;
|
|
37
|
+
let { name, label, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
38
|
+
const placeholder = customPlaceholder || `Enter ${name}`;
|
|
39
39
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
40
40
|
name: [
|
|
41
41
|
'params',
|
|
@@ -57,7 +57,8 @@ const TextField = (param)=>{
|
|
|
57
57
|
}, name);
|
|
58
58
|
};
|
|
59
59
|
const LocateField = (param)=>{
|
|
60
|
-
let { name, label, isRequired, marginBottom } = param;
|
|
60
|
+
let { name, label, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
61
|
+
const placeholder = customPlaceholder || `Describe the ${name}, use natural language`;
|
|
61
62
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
62
63
|
name: [
|
|
63
64
|
'params',
|
|
@@ -67,7 +68,7 @@ const LocateField = (param)=>{
|
|
|
67
68
|
rules: isRequired ? [
|
|
68
69
|
{
|
|
69
70
|
required: true,
|
|
70
|
-
message: `
|
|
71
|
+
message: `The ${name} is required`
|
|
71
72
|
}
|
|
72
73
|
] : [],
|
|
73
74
|
style: {
|
|
@@ -75,12 +76,12 @@ const LocateField = (param)=>{
|
|
|
75
76
|
},
|
|
76
77
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TextArea, {
|
|
77
78
|
rows: 2,
|
|
78
|
-
placeholder:
|
|
79
|
+
placeholder: placeholder
|
|
79
80
|
})
|
|
80
81
|
}, name);
|
|
81
82
|
};
|
|
82
83
|
const EnumField = (param)=>{
|
|
83
|
-
let { name, label, fieldSchema, isRequired, marginBottom } = param;
|
|
84
|
+
let { name, label, fieldSchema, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
84
85
|
const enumValues = fieldSchema._def.values || [];
|
|
85
86
|
const selectOptions = enumValues.map((value)=>({
|
|
86
87
|
value,
|
|
@@ -102,14 +103,15 @@ const EnumField = (param)=>{
|
|
|
102
103
|
marginBottom
|
|
103
104
|
},
|
|
104
105
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
|
|
105
|
-
placeholder: `Select ${name}`,
|
|
106
|
+
placeholder: customPlaceholder || `Select ${name}`,
|
|
106
107
|
options: selectOptions
|
|
107
108
|
})
|
|
108
109
|
}, name);
|
|
109
110
|
};
|
|
110
111
|
const NumberField = (param)=>{
|
|
111
|
-
let { name, label, isRequired, marginBottom } = param;
|
|
112
|
-
const
|
|
112
|
+
let { name, label, isRequired, marginBottom, placeholder: customPlaceholder } = param;
|
|
113
|
+
const defaultPlaceholder = 'distance' === name ? 500 : 0;
|
|
114
|
+
const placeholderValue = customPlaceholder ? Number(customPlaceholder) || defaultPlaceholder : defaultPlaceholder;
|
|
113
115
|
const min = 0;
|
|
114
116
|
const max = 'distance' === name ? 10000 : void 0;
|
|
115
117
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
@@ -140,7 +142,7 @@ const NumberField = (param)=>{
|
|
|
140
142
|
marginBottom
|
|
141
143
|
},
|
|
142
144
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.InputNumber, {
|
|
143
|
-
placeholder:
|
|
145
|
+
placeholder: placeholderValue.toString(),
|
|
144
146
|
min: min,
|
|
145
147
|
max: max,
|
|
146
148
|
step: 'distance' === name ? 10 : 1,
|
|
@@ -68,13 +68,42 @@ const PromptInput = (param)=>{
|
|
|
68
68
|
const needsStructuredParams = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
69
69
|
if (actionSpace) {
|
|
70
70
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
71
|
-
|
|
71
|
+
if (!(null == action ? void 0 : action.paramSchema)) return false;
|
|
72
|
+
if ((0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
73
|
+
const schema = action.paramSchema;
|
|
74
|
+
const shape = schema.shape || {};
|
|
75
|
+
const shapeKeys = Object.keys(shape);
|
|
76
|
+
return shapeKeys.length > 0;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
72
79
|
}
|
|
73
80
|
return false;
|
|
74
81
|
}, [
|
|
75
82
|
selectedType,
|
|
76
83
|
actionSpace
|
|
77
84
|
]);
|
|
85
|
+
const needsAnyInput = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
86
|
+
if (actionSpace && actionSpace.length > 0) {
|
|
87
|
+
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
88
|
+
if (action) {
|
|
89
|
+
if (action.paramSchema && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
90
|
+
const schema = action.paramSchema;
|
|
91
|
+
const shape = schema.shape || {};
|
|
92
|
+
const hasRequiredFields = Object.keys(shape).some((key)=>{
|
|
93
|
+
const field = shape[key];
|
|
94
|
+
const { isOptional } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
95
|
+
return !isOptional;
|
|
96
|
+
});
|
|
97
|
+
return hasRequiredFields;
|
|
98
|
+
}
|
|
99
|
+
return !!action.paramSchema;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}, [
|
|
104
|
+
selectedType,
|
|
105
|
+
actionSpace
|
|
106
|
+
]);
|
|
78
107
|
const showDataExtractionOptions = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
79
108
|
const dataExtractionMethods = [
|
|
80
109
|
'aiQuery',
|
|
@@ -94,11 +123,12 @@ const PromptInput = (param)=>{
|
|
|
94
123
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
95
124
|
if ((null == action ? void 0 : action.paramSchema) && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
96
125
|
const schema = action.paramSchema;
|
|
97
|
-
|
|
126
|
+
const hasLocateField = Object.keys(schema.shape).some((key)=>{
|
|
98
127
|
const field = schema.shape[key];
|
|
99
128
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
100
129
|
return (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
101
130
|
});
|
|
131
|
+
return hasLocateField;
|
|
102
132
|
}
|
|
103
133
|
}
|
|
104
134
|
return false;
|
|
@@ -106,14 +136,43 @@ const PromptInput = (param)=>{
|
|
|
106
136
|
selectedType,
|
|
107
137
|
actionSpace
|
|
108
138
|
]);
|
|
139
|
+
const hasConfigOptions = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
140
|
+
const hasTracking = 'In-Browser-Extension' === serviceMode;
|
|
141
|
+
const hasDeepThink = showDeepThinkOption;
|
|
142
|
+
const hasDataExtraction = showDataExtractionOptions && !hideDomAndScreenshotOptions;
|
|
143
|
+
return hasTracking || hasDeepThink || hasDataExtraction;
|
|
144
|
+
}, [
|
|
145
|
+
serviceMode,
|
|
146
|
+
showDeepThinkOption,
|
|
147
|
+
showDataExtractionOptions,
|
|
148
|
+
hideDomAndScreenshotOptions
|
|
149
|
+
]);
|
|
150
|
+
const availableDropdownMethods = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
151
|
+
const metadataMethods = Object.keys(external_playground_constants_js_namespaceObject.apiMetadata);
|
|
152
|
+
if (!actionSpace || 0 === actionSpace.length) return metadataMethods;
|
|
153
|
+
const availableMethods = actionSpace.map((action)=>action.interfaceAlias || action.name);
|
|
154
|
+
const finalMethods = new Set();
|
|
155
|
+
metadataMethods.forEach((method)=>{
|
|
156
|
+
const methodInfo = external_playground_constants_js_namespaceObject.apiMetadata[method];
|
|
157
|
+
if ((null == methodInfo ? void 0 : methodInfo.group) === 'extraction' || (null == methodInfo ? void 0 : methodInfo.group) === 'validation') finalMethods.add(method);
|
|
158
|
+
else if (availableMethods.includes(method)) finalMethods.add(method);
|
|
159
|
+
});
|
|
160
|
+
availableMethods.forEach((method)=>{
|
|
161
|
+
finalMethods.add(method);
|
|
162
|
+
});
|
|
163
|
+
return Array.from(finalMethods);
|
|
164
|
+
}, [
|
|
165
|
+
actionSpace
|
|
166
|
+
]);
|
|
109
167
|
const getDefaultParams = (0, external_react_namespaceObject.useCallback)(()=>{
|
|
110
168
|
if (!needsStructuredParams || !actionSpace) return {};
|
|
111
169
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
112
170
|
if ((null == action ? void 0 : action.paramSchema) && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
113
171
|
const defaultParams = {};
|
|
114
172
|
const schema = action.paramSchema;
|
|
115
|
-
|
|
116
|
-
|
|
173
|
+
const shape = schema.shape || {};
|
|
174
|
+
Object.keys(shape).forEach((key)=>{
|
|
175
|
+
const field = shape[key];
|
|
117
176
|
const defaultValue = (0, external_types_js_namespaceObject.extractDefaultValue)(field);
|
|
118
177
|
if (void 0 !== defaultValue) defaultParams[key] = defaultValue;
|
|
119
178
|
});
|
|
@@ -190,7 +249,8 @@ const PromptInput = (param)=>{
|
|
|
190
249
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
191
250
|
if ((null == action ? void 0 : action.paramSchema) && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
192
251
|
const schema = action.paramSchema;
|
|
193
|
-
|
|
252
|
+
const shape = schema.shape || {};
|
|
253
|
+
return 1 === Object.keys(shape).length;
|
|
194
254
|
}
|
|
195
255
|
return false;
|
|
196
256
|
}, [
|
|
@@ -215,10 +275,11 @@ const PromptInput = (param)=>{
|
|
|
215
275
|
let locateValue = '';
|
|
216
276
|
const otherValues = [];
|
|
217
277
|
const schema = action.paramSchema;
|
|
218
|
-
|
|
278
|
+
const shape = schema.shape || {};
|
|
279
|
+
Object.keys(shape).forEach((key)=>{
|
|
219
280
|
const paramValue = values.params[key];
|
|
220
281
|
if (null != paramValue && '' !== paramValue) {
|
|
221
|
-
const field =
|
|
282
|
+
const field = shape[key];
|
|
222
283
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
223
284
|
if ((0, external_types_js_namespaceObject.isLocateField)(actualField)) locateValue = String(paramValue);
|
|
224
285
|
else if ('distance' === key) otherValues.push(`${paramValue}`);
|
|
@@ -290,19 +351,33 @@ const PromptInput = (param)=>{
|
|
|
290
351
|
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
291
352
|
if ((null == action ? void 0 : action.paramSchema) && (0, external_types_js_namespaceObject.isZodObjectSchema)(action.paramSchema)) {
|
|
292
353
|
const schema = action.paramSchema;
|
|
293
|
-
const
|
|
354
|
+
const shape = schema.shape || {};
|
|
355
|
+
const schemaKeys = Object.keys(shape);
|
|
294
356
|
if (1 === schemaKeys.length) {
|
|
295
357
|
const key = schemaKeys[0];
|
|
296
|
-
const field =
|
|
358
|
+
const field = shape[key];
|
|
297
359
|
const { actualField } = (0, external_types_js_namespaceObject.unwrapZodType)(field);
|
|
298
360
|
const isLocateFieldFlag = (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
if (
|
|
305
|
-
|
|
361
|
+
const placeholderText = (()=>{
|
|
362
|
+
var _fieldAsAny__def;
|
|
363
|
+
const fieldAsAny = actualField;
|
|
364
|
+
if (null == (_fieldAsAny__def = fieldAsAny._def) ? void 0 : _fieldAsAny__def.description) return fieldAsAny._def.description;
|
|
365
|
+
if (fieldAsAny.description) return fieldAsAny.description;
|
|
366
|
+
if (actionSpace) {
|
|
367
|
+
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
368
|
+
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
369
|
+
var _fieldDef__def;
|
|
370
|
+
const shape = action.paramSchema.shape || {};
|
|
371
|
+
const fieldDef = shape[key];
|
|
372
|
+
if (null == fieldDef ? void 0 : null == (_fieldDef__def = fieldDef._def) ? void 0 : _fieldDef__def.description) return fieldDef._def.description;
|
|
373
|
+
if (null == fieldDef ? void 0 : fieldDef.description) return fieldDef.description;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (isLocateFieldFlag) return 'Describe the element you want to interact with';
|
|
377
|
+
if ('keyName' === key) return 'Enter key name or text to type';
|
|
378
|
+
if ('value' === key) return 'Enter text to input';
|
|
379
|
+
return `Enter ${key}`;
|
|
380
|
+
})();
|
|
306
381
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
307
382
|
name: [
|
|
308
383
|
'params',
|
|
@@ -323,18 +398,36 @@ const PromptInput = (param)=>{
|
|
|
323
398
|
const fields = [];
|
|
324
399
|
schemaKeys.forEach((key, index)=>{
|
|
325
400
|
var _actualField__def, _actualField__def1;
|
|
326
|
-
const fieldSchema =
|
|
401
|
+
const fieldSchema = shape[key];
|
|
327
402
|
const { actualField, isOptional } = (0, external_types_js_namespaceObject.unwrapZodType)(fieldSchema);
|
|
328
403
|
const isLocateFieldFlag = (0, external_types_js_namespaceObject.isLocateField)(actualField);
|
|
329
404
|
const label = key.charAt(0).toUpperCase() + key.slice(1);
|
|
330
405
|
const isRequired = !isOptional;
|
|
331
406
|
const marginBottom = index === schemaKeys.length - 1 ? 0 : 12;
|
|
407
|
+
const placeholder = (()=>{
|
|
408
|
+
var _fieldAsAny__def;
|
|
409
|
+
const fieldAsAny = actualField;
|
|
410
|
+
if (null == (_fieldAsAny__def = fieldAsAny._def) ? void 0 : _fieldAsAny__def.description) return fieldAsAny._def.description;
|
|
411
|
+
if (fieldAsAny.description) return fieldAsAny.description;
|
|
412
|
+
if (actionSpace) {
|
|
413
|
+
const action = actionSpace.find((a)=>a.interfaceAlias === selectedType || a.name === selectedType);
|
|
414
|
+
if ((null == action ? void 0 : action.paramSchema) && 'object' == typeof action.paramSchema && 'shape' in action.paramSchema) {
|
|
415
|
+
var _fieldDef__def;
|
|
416
|
+
const shape = action.paramSchema.shape || {};
|
|
417
|
+
const fieldDef = shape[key];
|
|
418
|
+
if (null == fieldDef ? void 0 : null == (_fieldDef__def = fieldDef._def) ? void 0 : _fieldDef__def.description) return fieldDef._def.description;
|
|
419
|
+
if (null == fieldDef ? void 0 : fieldDef.description) return fieldDef.description;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (isLocateFieldFlag) return 'Describe the element you want to interact with';
|
|
423
|
+
})();
|
|
332
424
|
const fieldProps = {
|
|
333
425
|
name: key,
|
|
334
426
|
label,
|
|
335
427
|
fieldSchema: actualField,
|
|
336
428
|
isRequired,
|
|
337
|
-
marginBottom
|
|
429
|
+
marginBottom,
|
|
430
|
+
placeholder
|
|
338
431
|
};
|
|
339
432
|
if (isLocateFieldFlag) fields.push(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FormField_js_namespaceObject.LocateField, {
|
|
340
433
|
...fieldProps
|
|
@@ -457,45 +550,77 @@ const PromptInput = (param)=>{
|
|
|
457
550
|
}),
|
|
458
551
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Dropdown, {
|
|
459
552
|
menu: (()=>{
|
|
460
|
-
const hiddenAPIs =
|
|
553
|
+
const hiddenAPIs = availableDropdownMethods.filter((api)=>!external_playground_constants_js_namespaceObject.defaultMainButtons.includes(api));
|
|
461
554
|
const groupedItems = [];
|
|
462
|
-
const interactionAPIs = hiddenAPIs.filter((api)=>
|
|
555
|
+
const interactionAPIs = hiddenAPIs.filter((api)=>{
|
|
556
|
+
var _apiMetadata_api;
|
|
557
|
+
return (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.group) === 'interaction';
|
|
558
|
+
});
|
|
463
559
|
if (interactionAPIs.length > 0) groupedItems.push({
|
|
464
560
|
key: 'interaction-group',
|
|
465
561
|
type: 'group',
|
|
466
562
|
label: 'Interaction APIs',
|
|
467
|
-
children: interactionAPIs.map((api)=>
|
|
563
|
+
children: interactionAPIs.map((api)=>{
|
|
564
|
+
var _apiMetadata_api;
|
|
565
|
+
return {
|
|
468
566
|
key: api,
|
|
469
567
|
label: (0, external_playground_utils_js_namespaceObject.actionNameForType)(api),
|
|
470
|
-
title: external_playground_constants_js_namespaceObject.apiMetadata[api].title,
|
|
568
|
+
title: (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.title) || '',
|
|
471
569
|
onClick: ()=>{
|
|
472
570
|
form.setFieldValue('type', api);
|
|
473
571
|
}
|
|
474
|
-
}
|
|
572
|
+
};
|
|
573
|
+
})
|
|
574
|
+
});
|
|
575
|
+
const extractionAPIs = hiddenAPIs.filter((api)=>{
|
|
576
|
+
var _apiMetadata_api;
|
|
577
|
+
return (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.group) === 'extraction';
|
|
475
578
|
});
|
|
476
|
-
const extractionAPIs = hiddenAPIs.filter((api)=>'extraction' === external_playground_constants_js_namespaceObject.apiMetadata[api].group);
|
|
477
579
|
if (extractionAPIs.length > 0) groupedItems.push({
|
|
478
580
|
key: 'extraction-group',
|
|
479
581
|
type: 'group',
|
|
480
582
|
label: 'Data Extraction APIs',
|
|
481
|
-
children: extractionAPIs.map((api)=>
|
|
583
|
+
children: extractionAPIs.map((api)=>{
|
|
584
|
+
var _apiMetadata_api;
|
|
585
|
+
return {
|
|
482
586
|
key: api,
|
|
483
587
|
label: (0, external_playground_utils_js_namespaceObject.actionNameForType)(api),
|
|
484
|
-
title: external_playground_constants_js_namespaceObject.apiMetadata[api].title,
|
|
588
|
+
title: (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.title) || '',
|
|
485
589
|
onClick: ()=>{
|
|
486
590
|
form.setFieldValue('type', api);
|
|
487
591
|
}
|
|
488
|
-
}
|
|
592
|
+
};
|
|
593
|
+
})
|
|
594
|
+
});
|
|
595
|
+
const validationAPIs = hiddenAPIs.filter((api)=>{
|
|
596
|
+
var _apiMetadata_api;
|
|
597
|
+
return (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.group) === 'validation';
|
|
489
598
|
});
|
|
490
|
-
const validationAPIs = hiddenAPIs.filter((api)=>'validation' === external_playground_constants_js_namespaceObject.apiMetadata[api].group);
|
|
491
599
|
if (validationAPIs.length > 0) groupedItems.push({
|
|
492
600
|
key: 'validation-group',
|
|
493
601
|
type: 'group',
|
|
494
602
|
label: 'Validation APIs',
|
|
495
|
-
children: validationAPIs.map((api)=>
|
|
603
|
+
children: validationAPIs.map((api)=>{
|
|
604
|
+
var _apiMetadata_api;
|
|
605
|
+
return {
|
|
496
606
|
key: api,
|
|
497
607
|
label: (0, external_playground_utils_js_namespaceObject.actionNameForType)(api),
|
|
498
|
-
title: external_playground_constants_js_namespaceObject.apiMetadata[api].title,
|
|
608
|
+
title: (null == (_apiMetadata_api = external_playground_constants_js_namespaceObject.apiMetadata[api]) ? void 0 : _apiMetadata_api.title) || '',
|
|
609
|
+
onClick: ()=>{
|
|
610
|
+
form.setFieldValue('type', api);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
})
|
|
614
|
+
});
|
|
615
|
+
const deviceSpecificAPIs = hiddenAPIs.filter((api)=>!external_playground_constants_js_namespaceObject.apiMetadata[api]);
|
|
616
|
+
if (deviceSpecificAPIs.length > 0) groupedItems.push({
|
|
617
|
+
key: 'device-specific-group',
|
|
618
|
+
type: 'group',
|
|
619
|
+
label: 'Device-Specific APIs',
|
|
620
|
+
children: deviceSpecificAPIs.map((api)=>({
|
|
621
|
+
key: api,
|
|
622
|
+
label: (0, external_playground_utils_js_namespaceObject.actionNameForType)(api),
|
|
623
|
+
title: '',
|
|
499
624
|
onClick: ()=>{
|
|
500
625
|
form.setFieldValue('type', api);
|
|
501
626
|
}
|
|
@@ -533,7 +658,7 @@ const PromptInput = (param)=>{
|
|
|
533
658
|
history: historyForSelectedType,
|
|
534
659
|
currentType: selectedType
|
|
535
660
|
}),
|
|
536
|
-
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
661
|
+
hasConfigOptions && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
537
662
|
className: hoveringSettings ? 'settings-wrapper settings-wrapper-hover' : 'settings-wrapper',
|
|
538
663
|
onMouseEnter: handleMouseEnter,
|
|
539
664
|
onMouseLeave: handleMouseLeave,
|
|
@@ -551,7 +676,7 @@ const PromptInput = (param)=>{
|
|
|
551
676
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
552
677
|
className: `main-side-console-input ${!runButtonEnabled ? 'disabled' : ''} ${loading ? 'loading' : ''}`,
|
|
553
678
|
children: [
|
|
554
|
-
needsStructuredParams ? hasSingleStructuredParam ? renderStructuredParams() : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
679
|
+
needsAnyInput ? needsStructuredParams ? hasSingleStructuredParam ? renderStructuredParams() : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
555
680
|
className: "structured-params-container",
|
|
556
681
|
children: renderStructuredParams()
|
|
557
682
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
|
|
@@ -569,6 +694,18 @@ const PromptInput = (param)=>{
|
|
|
569
694
|
onChange: handlePromptChange,
|
|
570
695
|
ref: textAreaRef
|
|
571
696
|
})
|
|
697
|
+
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
698
|
+
className: "no-input-method",
|
|
699
|
+
style: {
|
|
700
|
+
padding: '20px',
|
|
701
|
+
textAlign: 'center',
|
|
702
|
+
color: '#666',
|
|
703
|
+
fontSize: '14px'
|
|
704
|
+
},
|
|
705
|
+
children: [
|
|
706
|
+
'Click "Run" to execute ',
|
|
707
|
+
(0, external_playground_utils_js_namespaceObject.actionNameForType)(selectedType)
|
|
708
|
+
]
|
|
572
709
|
}),
|
|
573
710
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
574
711
|
className: "form-controller-wrapper",
|
|
@@ -58,11 +58,18 @@ body {
|
|
|
58
58
|
border-radius: 11px;
|
|
59
59
|
align-items: center;
|
|
60
60
|
gap: 2px;
|
|
61
|
+
max-width: 160px;
|
|
61
62
|
padding: 0 8px;
|
|
62
63
|
font-size: 12px;
|
|
63
64
|
display: inline-flex;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
.prompt-input-wrapper .mode-radio-group-wrapper .mode-radio-group .more-apis-button .ant-btn-content {
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
white-space: nowrap;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
.prompt-input-wrapper .mode-radio-group-wrapper .mode-radio-group .more-apis-button:hover {
|
|
67
74
|
background-color: #e6e6e6;
|
|
68
75
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
formatErrorMessage: ()=>formatErrorMessage,
|
|
28
|
+
validateStructuredParams: ()=>validateStructuredParams,
|
|
29
|
+
executeAction: ()=>executeAction
|
|
30
|
+
});
|
|
31
|
+
const ai_model_namespaceObject = require("@midscene/core/ai-model");
|
|
32
|
+
const formatErrorMessage = (e)=>{
|
|
33
|
+
const errorMessage = (null == e ? void 0 : e.message) || '';
|
|
34
|
+
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';
|
|
35
|
+
return errorMessage || 'Unknown error';
|
|
36
|
+
};
|
|
37
|
+
async function parseStructuredParams(action, params) {
|
|
38
|
+
let options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
|
|
39
|
+
if (!(null == action ? void 0 : action.paramSchema) || !('shape' in action.paramSchema)) return [
|
|
40
|
+
params.prompt || '',
|
|
41
|
+
options
|
|
42
|
+
];
|
|
43
|
+
const schema = action.paramSchema;
|
|
44
|
+
const keys = Object.keys(schema.shape);
|
|
45
|
+
const paramObj = {
|
|
46
|
+
...options
|
|
47
|
+
};
|
|
48
|
+
keys.forEach((key)=>{
|
|
49
|
+
if (void 0 !== params[key] && null !== params[key] && '' !== params[key]) paramObj[key] = params[key];
|
|
50
|
+
});
|
|
51
|
+
return [
|
|
52
|
+
paramObj
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
function validateStructuredParams(value, action) {
|
|
56
|
+
if (!value.params) return {
|
|
57
|
+
valid: false,
|
|
58
|
+
errorMessage: 'Parameters are required'
|
|
59
|
+
};
|
|
60
|
+
if (!(null == action ? void 0 : action.paramSchema)) return {
|
|
61
|
+
valid: true
|
|
62
|
+
};
|
|
63
|
+
try {
|
|
64
|
+
var _action_paramSchema;
|
|
65
|
+
const paramsForValidation = {
|
|
66
|
+
...value.params
|
|
67
|
+
};
|
|
68
|
+
const schema = action.paramSchema;
|
|
69
|
+
if (schema) {
|
|
70
|
+
const locatorFieldKeys = (0, ai_model_namespaceObject.findAllMidsceneLocatorField)(schema);
|
|
71
|
+
locatorFieldKeys.forEach((key)=>{
|
|
72
|
+
if ('string' == typeof paramsForValidation[key]) paramsForValidation[key] = {
|
|
73
|
+
midscene_location_field_flag: true,
|
|
74
|
+
prompt: paramsForValidation[key],
|
|
75
|
+
center: [
|
|
76
|
+
0,
|
|
77
|
+
0
|
|
78
|
+
],
|
|
79
|
+
rect: {
|
|
80
|
+
left: 0,
|
|
81
|
+
top: 0,
|
|
82
|
+
width: 0,
|
|
83
|
+
height: 0
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
null == (_action_paramSchema = action.paramSchema) || _action_paramSchema.parse(paramsForValidation);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const zodError = error;
|
|
91
|
+
if (zodError.errors && zodError.errors.length > 0) {
|
|
92
|
+
const errorMessages = zodError.errors.filter((err)=>{
|
|
93
|
+
const path = err.path.join('.');
|
|
94
|
+
return !path.includes('center') && !path.includes('rect') && !path.includes('midscene_location_field_flag');
|
|
95
|
+
}).map((err)=>{
|
|
96
|
+
const field = err.path.join('.');
|
|
97
|
+
return `${field}: ${err.message}`;
|
|
98
|
+
});
|
|
99
|
+
if (errorMessages.length > 0) return {
|
|
100
|
+
valid: false,
|
|
101
|
+
errorMessage: `Validation error: ${errorMessages.join(', ')}`
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown validation error';
|
|
105
|
+
return {
|
|
106
|
+
valid: false,
|
|
107
|
+
errorMessage: `Parameter validation failed: ${errorMsg}`
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
valid: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function executeAction(activeAgent, actionType, actionSpace, value, deepThink) {
|
|
116
|
+
const action = null == actionSpace ? void 0 : actionSpace.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
|
|
117
|
+
if (action && 'function' == typeof activeAgent.callActionInActionSpace) if (!value.params) return await activeAgent.callActionInActionSpace(action.name, {
|
|
118
|
+
prompt: value.prompt,
|
|
119
|
+
deepThink
|
|
120
|
+
});
|
|
121
|
+
else {
|
|
122
|
+
const parsedParams = await parseStructuredParams(action, value.params, {
|
|
123
|
+
deepThink
|
|
124
|
+
});
|
|
125
|
+
return await activeAgent.callActionInActionSpace(action.name, parsedParams[0]);
|
|
126
|
+
}
|
|
127
|
+
{
|
|
128
|
+
const prompt = value.prompt;
|
|
129
|
+
if ('aiAssert' === actionType) {
|
|
130
|
+
const { pass, thought } = await (null == activeAgent ? void 0 : activeAgent.aiAssert(prompt, void 0, {
|
|
131
|
+
keepRawResponse: true
|
|
132
|
+
})) || {};
|
|
133
|
+
return {
|
|
134
|
+
pass,
|
|
135
|
+
thought
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (activeAgent && 'function' == typeof activeAgent[actionType]) return await activeAgent[actionType](prompt, {
|
|
139
|
+
deepThink
|
|
140
|
+
});
|
|
141
|
+
throw new Error(`Unknown action type: ${actionType}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.executeAction = __webpack_exports__.executeAction;
|
|
145
|
+
exports.formatErrorMessage = __webpack_exports__.formatErrorMessage;
|
|
146
|
+
exports.validateStructuredParams = __webpack_exports__.validateStructuredParams;
|
|
147
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
148
|
+
"executeAction",
|
|
149
|
+
"formatErrorMessage",
|
|
150
|
+
"validateStructuredParams"
|
|
151
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
152
|
+
Object.defineProperty(exports, '__esModule', {
|
|
153
|
+
value: true
|
|
154
|
+
});
|