@godscene/shared 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.
- package/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +122 -0
- package/dist/es/cli/index.mjs +4 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +227 -0
- package/dist/es/constants/index.mjs +124 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +110 -0
- package/dist/es/env/global-config-manager.mjs +94 -0
- package/dist/es/env/helper.mjs +43 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +79 -0
- package/dist/es/env/parse-model-config.mjs +165 -0
- package/dist/es/env/types.mjs +232 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +641 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +96 -0
- package/dist/es/extractor/index.mjs +5 -0
- package/dist/es/extractor/locator.mjs +250 -0
- package/dist/es/extractor/tree.mjs +78 -0
- package/dist/es/extractor/util.mjs +245 -0
- package/dist/es/extractor/web-extractor.mjs +393 -0
- package/dist/es/img/box-select.mjs +824 -0
- package/dist/es/img/canvas-fallback.mjs +238 -0
- package/dist/es/img/get-photon.mjs +45 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +4 -0
- package/dist/es/img/info.mjs +35 -0
- package/dist/es/img/transform.mjs +275 -0
- package/dist/es/index.mjs +2 -0
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/logger.mjs +64 -0
- package/dist/es/mcp/base-server.mjs +282 -0
- package/dist/es/mcp/base-tools.mjs +159 -0
- package/dist/es/mcp/chrome-path.mjs +35 -0
- package/dist/es/mcp/cli-report-session.mjs +78 -0
- package/dist/es/mcp/error-formatter.mjs +19 -0
- package/dist/es/mcp/index.mjs +9 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
- package/dist/es/mcp/launcher-helper.mjs +52 -0
- package/dist/es/mcp/tool-generator.mjs +419 -0
- package/dist/es/mcp/types.mjs +3 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +2 -0
- package/dist/es/node/port.mjs +24 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +72 -0
- package/dist/es/zod-schema-utils.mjs +54 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/cli/cli-args.js +138 -0
- package/dist/lib/cli/cli-error.js +61 -0
- package/dist/lib/cli/cli-runner.js +181 -0
- package/dist/lib/cli/index.js +53 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +264 -0
- package/dist/lib/constants/index.js +221 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +153 -0
- package/dist/lib/env/global-config-manager.js +128 -0
- package/dist/lib/env/helper.js +80 -0
- package/dist/lib/env/index.js +90 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +113 -0
- package/dist/lib/env/parse-model-config.js +211 -0
- package/dist/lib/env/types.js +572 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +693 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +157 -0
- package/dist/lib/extractor/index.js +87 -0
- package/dist/lib/extractor/locator.js +296 -0
- package/dist/lib/extractor/tree.js +124 -0
- package/dist/lib/extractor/util.js +336 -0
- package/dist/lib/extractor/web-extractor.js +442 -0
- package/dist/lib/img/box-select.js +875 -0
- package/dist/lib/img/canvas-fallback.js +305 -0
- package/dist/lib/img/get-photon.js +82 -0
- package/dist/lib/img/get-sharp.js +45 -0
- package/dist/lib/img/index.js +95 -0
- package/dist/lib/img/info.js +92 -0
- package/dist/lib/img/transform.js +364 -0
- package/dist/lib/index.js +36 -0
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/mcp/base-server.js +332 -0
- package/dist/lib/mcp/base-tools.js +193 -0
- package/dist/lib/mcp/chrome-path.js +72 -0
- package/dist/lib/mcp/cli-report-session.js +121 -0
- package/dist/lib/mcp/error-formatter.js +53 -0
- package/dist/lib/mcp/index.js +114 -0
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
- package/dist/lib/mcp/launcher-helper.js +86 -0
- package/dist/lib/mcp/tool-generator.js +456 -0
- package/dist/lib/mcp/types.js +40 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +65 -0
- package/dist/lib/node/port.js +61 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +58 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +148 -0
- package/dist/lib/zod-schema-utils.js +97 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/cli/cli-args.d.ts +8 -0
- package/dist/types/cli/cli-error.d.ts +5 -0
- package/dist/types/cli/cli-runner.d.ts +19 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +61 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +50 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +4 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +25 -0
- package/dist/types/env/parse-model-config.d.ts +31 -0
- package/dist/types/env/types.d.ts +339 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +57 -0
- package/dist/types/extractor/index.d.ts +33 -0
- package/dist/types/extractor/locator.d.ts +9 -0
- package/dist/types/extractor/tree.d.ts +6 -0
- package/dist/types/extractor/util.d.ts +47 -0
- package/dist/types/extractor/web-extractor.d.ts +24 -0
- package/dist/types/img/box-select.d.ts +26 -0
- package/dist/types/img/canvas-fallback.d.ts +105 -0
- package/dist/types/img/get-photon.d.ts +19 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +3 -0
- package/dist/types/img/info.d.ts +34 -0
- package/dist/types/img/transform.d.ts +98 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/logger.d.ts +5 -0
- package/dist/types/mcp/base-server.d.ts +93 -0
- package/dist/types/mcp/base-tools.d.ts +148 -0
- package/dist/types/mcp/chrome-path.d.ts +2 -0
- package/dist/types/mcp/cli-report-session.d.ts +12 -0
- package/dist/types/mcp/error-formatter.d.ts +12 -0
- package/dist/types/mcp/index.d.ts +9 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/launcher-helper.d.ts +94 -0
- package/dist/types/mcp/tool-generator.d.ts +10 -0
- package/dist/types/mcp/types.d.ts +113 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +2 -0
- package/dist/types/node/port.d.ts +8 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +36 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +34 -0
- package/dist/types/zod-schema-utils.d.ts +23 -0
- package/package.json +125 -0
- package/src/baseDB.ts +158 -0
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +230 -0
- package/src/cli/index.ts +4 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +227 -0
- package/src/constants/index.ts +139 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +303 -0
- package/src/env/global-config-manager.ts +191 -0
- package/src/env/helper.ts +58 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +34 -0
- package/src/env/model-config-manager.ts +149 -0
- package/src/env/parse-model-config.ts +357 -0
- package/src/env/types.ts +583 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +136 -0
- package/src/extractor/customLocator.ts +1245 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +231 -0
- package/src/extractor/index.ts +50 -0
- package/src/extractor/locator.ts +469 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +482 -0
- package/src/extractor/web-extractor.ts +617 -0
- package/src/img/box-select.ts +588 -0
- package/src/img/canvas-fallback.ts +393 -0
- package/src/img/get-photon.ts +108 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +27 -0
- package/src/img/info.ts +102 -0
- package/src/img/transform.ts +553 -0
- package/src/index.ts +1 -0
- package/src/key-alias-utils.ts +23 -0
- package/src/logger.ts +96 -0
- package/src/mcp/base-server.ts +500 -0
- package/src/mcp/base-tools.ts +391 -0
- package/src/mcp/chrome-path.ts +48 -0
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +119 -0
- package/src/mcp/launcher-helper.ts +200 -0
- package/src/mcp/tool-generator.ts +658 -0
- package/src/mcp/types.ts +131 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +2 -0
- package/src/node/port.ts +37 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +54 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +149 -0
- package/src/zod-schema-utils.ts +133 -0
|
@@ -0,0 +1,456 @@
|
|
|
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 ("u" > 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
|
+
generateToolsFromActionSpace: ()=>generateToolsFromActionSpace,
|
|
28
|
+
generateCommonTools: ()=>generateCommonTools
|
|
29
|
+
});
|
|
30
|
+
const img_namespaceObject = require("@godscene/shared/img");
|
|
31
|
+
const external_zod_namespaceObject = require("zod");
|
|
32
|
+
const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
|
|
33
|
+
const external_error_formatter_js_namespaceObject = require("./error-formatter.js");
|
|
34
|
+
function describeActionForMCP(action) {
|
|
35
|
+
const actionDesc = action.description || `Execute ${action.name} action`;
|
|
36
|
+
if (!action.paramSchema) return `${action.name} action, ${actionDesc}`;
|
|
37
|
+
const shape = getZodObjectShape(action.paramSchema);
|
|
38
|
+
if (!shape) {
|
|
39
|
+
const typeName = (0, external_zod_schema_utils_js_namespaceObject.getZodTypeName)(action.paramSchema);
|
|
40
|
+
const description = (0, external_zod_schema_utils_js_namespaceObject.getZodDescription)(action.paramSchema);
|
|
41
|
+
const paramDesc = description ? `${typeName} - ${description}` : typeName;
|
|
42
|
+
return `${action.name} action, ${actionDesc}. Parameter: ${paramDesc}`;
|
|
43
|
+
}
|
|
44
|
+
const paramDescriptions = [];
|
|
45
|
+
for (const [key, field] of Object.entries(shape))if (field && 'object' == typeof field) {
|
|
46
|
+
const isFieldOptional = 'function' == typeof field.isOptional && field.isOptional();
|
|
47
|
+
const typeName = (0, external_zod_schema_utils_js_namespaceObject.getZodTypeName)(field);
|
|
48
|
+
const description = (0, external_zod_schema_utils_js_namespaceObject.getZodDescription)(field);
|
|
49
|
+
let paramStr = `${key}${isFieldOptional ? '?' : ''} (${typeName})`;
|
|
50
|
+
if (description) paramStr += ` - ${description}`;
|
|
51
|
+
paramDescriptions.push(paramStr);
|
|
52
|
+
}
|
|
53
|
+
if (0 === paramDescriptions.length) return `${action.name} action, ${actionDesc}`;
|
|
54
|
+
return `${action.name} action, ${actionDesc}. Parameters: ${paramDescriptions.join('; ')}`;
|
|
55
|
+
}
|
|
56
|
+
function isZodOptional(value) {
|
|
57
|
+
return '_def' in value && value._def?.typeName === 'ZodOptional';
|
|
58
|
+
}
|
|
59
|
+
function unwrapOptional(value) {
|
|
60
|
+
if (isZodOptional(value)) return {
|
|
61
|
+
innerValue: value._def.innerType,
|
|
62
|
+
isOptional: true
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
innerValue: value,
|
|
66
|
+
isOptional: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function getZodObjectShape(value) {
|
|
70
|
+
if (!value) return;
|
|
71
|
+
const actualValue = (0, external_zod_schema_utils_js_namespaceObject.unwrapZodField)(value);
|
|
72
|
+
if (actualValue._def?.typeName !== 'ZodObject') return;
|
|
73
|
+
if ('function' == typeof actualValue._def.shape) return actualValue._def.shape();
|
|
74
|
+
return actualValue.shape;
|
|
75
|
+
}
|
|
76
|
+
function isRecord(value) {
|
|
77
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
78
|
+
}
|
|
79
|
+
function makePromptOptional(shape, wrapInOptional) {
|
|
80
|
+
const newShape = {
|
|
81
|
+
...shape
|
|
82
|
+
};
|
|
83
|
+
newShape.prompt = shape.prompt.optional();
|
|
84
|
+
let newSchema = external_zod_namespaceObject.z.object(newShape).passthrough();
|
|
85
|
+
if (wrapInOptional) newSchema = newSchema.optional();
|
|
86
|
+
return newSchema;
|
|
87
|
+
}
|
|
88
|
+
function transformSchemaField(key, value) {
|
|
89
|
+
const { innerValue, isOptional } = unwrapOptional(value);
|
|
90
|
+
const shape = getZodObjectShape(innerValue);
|
|
91
|
+
if (shape && (0, external_zod_schema_utils_js_namespaceObject.isMidsceneLocatorField)(innerValue)) return [
|
|
92
|
+
key,
|
|
93
|
+
makePromptOptional(shape, isOptional)
|
|
94
|
+
];
|
|
95
|
+
return [
|
|
96
|
+
key,
|
|
97
|
+
value
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
function extractActionSchema(paramSchema, actionName) {
|
|
101
|
+
if (!paramSchema) return {};
|
|
102
|
+
const shape = getZodObjectShape(paramSchema);
|
|
103
|
+
if (!shape) {
|
|
104
|
+
const typeName = paramSchema?._def?.typeName ?? 'unknown';
|
|
105
|
+
throw new Error(`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI and MCP tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`);
|
|
106
|
+
}
|
|
107
|
+
return Object.fromEntries(Object.entries(shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
108
|
+
}
|
|
109
|
+
function getPromptText(prompt) {
|
|
110
|
+
if ('string' == typeof prompt) return prompt;
|
|
111
|
+
if (isRecord(prompt) && 'string' == typeof prompt.prompt) return prompt.prompt;
|
|
112
|
+
}
|
|
113
|
+
function moveLocateExtrasIntoPrompt(value, locateFieldKeys) {
|
|
114
|
+
const promptText = getPromptText(value.prompt);
|
|
115
|
+
if (!promptText) return value;
|
|
116
|
+
const normalizedPrompt = isRecord(value.prompt) ? {
|
|
117
|
+
...value.prompt
|
|
118
|
+
} : {
|
|
119
|
+
prompt: promptText
|
|
120
|
+
};
|
|
121
|
+
const normalizedLocate = {};
|
|
122
|
+
let movedExtraField = false;
|
|
123
|
+
for (const [key, fieldValue] of Object.entries(value))if ('prompt' !== key) {
|
|
124
|
+
if (locateFieldKeys.has(key)) {
|
|
125
|
+
normalizedLocate[key] = fieldValue;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
movedExtraField = true;
|
|
129
|
+
if (!(key in normalizedPrompt)) normalizedPrompt[key] = fieldValue;
|
|
130
|
+
}
|
|
131
|
+
if (!movedExtraField) return value;
|
|
132
|
+
return {
|
|
133
|
+
...normalizedLocate,
|
|
134
|
+
prompt: normalizedPrompt
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function normalizeLocateLikeArg(value, fieldSchema) {
|
|
138
|
+
if ('string' == typeof value) return {
|
|
139
|
+
prompt: value
|
|
140
|
+
};
|
|
141
|
+
if (!isRecord(value)) return value;
|
|
142
|
+
const shape = getZodObjectShape(fieldSchema);
|
|
143
|
+
if (!shape) return value;
|
|
144
|
+
return moveLocateExtrasIntoPrompt(value, new Set(Object.keys(shape)));
|
|
145
|
+
}
|
|
146
|
+
function normalizeActionArgs(args, paramSchema) {
|
|
147
|
+
if (!paramSchema) return args;
|
|
148
|
+
const shape = getZodObjectShape(paramSchema);
|
|
149
|
+
if (!shape) return args;
|
|
150
|
+
return Object.fromEntries(Object.entries(args).map(([key, value])=>{
|
|
151
|
+
const fieldSchema = shape[key];
|
|
152
|
+
if (!fieldSchema) return [
|
|
153
|
+
key,
|
|
154
|
+
value
|
|
155
|
+
];
|
|
156
|
+
if ((0, external_zod_schema_utils_js_namespaceObject.isMidsceneLocatorField)(fieldSchema)) return [
|
|
157
|
+
key,
|
|
158
|
+
normalizeLocateLikeArg(value, fieldSchema)
|
|
159
|
+
];
|
|
160
|
+
return [
|
|
161
|
+
key,
|
|
162
|
+
value
|
|
163
|
+
];
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function serializeArgsToDescription(args) {
|
|
167
|
+
try {
|
|
168
|
+
return Object.entries(args).map(([key, value])=>{
|
|
169
|
+
if ('object' == typeof value && null !== value) try {
|
|
170
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
171
|
+
} catch {
|
|
172
|
+
return `${key}: [object]`;
|
|
173
|
+
}
|
|
174
|
+
return `${key}: "${value}"`;
|
|
175
|
+
}).join(', ');
|
|
176
|
+
} catch (error) {
|
|
177
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
178
|
+
console.error('Error serializing args:', errorMessage);
|
|
179
|
+
return `[args serialization failed: ${errorMessage}]`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function buildActionInstruction(actionName, args) {
|
|
183
|
+
const locatePrompt = isRecord(args.locate) ? getPromptText(args.locate.prompt) : void 0;
|
|
184
|
+
switch(actionName){
|
|
185
|
+
case 'Tap':
|
|
186
|
+
return locatePrompt ? `Tap on "${locatePrompt}"` : 'Tap';
|
|
187
|
+
case 'Input':
|
|
188
|
+
{
|
|
189
|
+
const value = args.value ?? args.content ?? '';
|
|
190
|
+
return locatePrompt ? `Input "${value}" into "${locatePrompt}"` : `Input "${value}"`;
|
|
191
|
+
}
|
|
192
|
+
case 'Scroll':
|
|
193
|
+
{
|
|
194
|
+
const direction = args.direction ?? 'down';
|
|
195
|
+
return locatePrompt ? `Scroll ${direction} on "${locatePrompt}"` : `Scroll ${direction}`;
|
|
196
|
+
}
|
|
197
|
+
case 'Hover':
|
|
198
|
+
return locatePrompt ? `Hover over "${locatePrompt}"` : 'Hover';
|
|
199
|
+
case 'KeyboardPress':
|
|
200
|
+
{
|
|
201
|
+
const key = args.value ?? args.key ?? '';
|
|
202
|
+
return `Press key "${key}"`;
|
|
203
|
+
}
|
|
204
|
+
default:
|
|
205
|
+
{
|
|
206
|
+
const argsDescription = serializeArgsToDescription(args);
|
|
207
|
+
return argsDescription ? `${actionName}: ${argsDescription}` : actionName;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function executeAction(agent, actionName, args) {
|
|
212
|
+
if (agent.callActionInActionSpace) return agent.callActionInActionSpace(actionName, args);
|
|
213
|
+
if (agent.aiAction) {
|
|
214
|
+
const instruction = buildActionInstruction(actionName, args);
|
|
215
|
+
return agent.aiAction(instruction);
|
|
216
|
+
}
|
|
217
|
+
throw new Error(`Action "${actionName}" is not supported by this agent`);
|
|
218
|
+
}
|
|
219
|
+
async function captureScreenshotResult(agent, actionName, actionResult) {
|
|
220
|
+
const content = [
|
|
221
|
+
{
|
|
222
|
+
type: 'text',
|
|
223
|
+
text: `Action "${actionName}" completed.`
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
if (void 0 !== actionResult) content.push({
|
|
227
|
+
type: 'text',
|
|
228
|
+
text: `Result: ${serializeActionResult(actionResult)}`
|
|
229
|
+
});
|
|
230
|
+
try {
|
|
231
|
+
const screenshot = await agent.page?.screenshotBase64();
|
|
232
|
+
if (!screenshot) return {
|
|
233
|
+
content
|
|
234
|
+
};
|
|
235
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
236
|
+
content.push({
|
|
237
|
+
type: 'image',
|
|
238
|
+
data: body,
|
|
239
|
+
mimeType
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
content
|
|
243
|
+
};
|
|
244
|
+
} catch (error) {
|
|
245
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
246
|
+
console.error('Error capturing screenshot:', errorMessage);
|
|
247
|
+
content[0] = {
|
|
248
|
+
type: 'text',
|
|
249
|
+
text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
content
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function serializeActionResult(actionResult) {
|
|
257
|
+
if ('string' == typeof actionResult) return actionResult;
|
|
258
|
+
try {
|
|
259
|
+
return JSON.stringify(actionResult);
|
|
260
|
+
} catch {
|
|
261
|
+
return String(actionResult);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function createErrorResult(message) {
|
|
265
|
+
return {
|
|
266
|
+
content: [
|
|
267
|
+
{
|
|
268
|
+
type: 'text',
|
|
269
|
+
text: message
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
isError: true
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function captureFailureResult(agent, actionName, errorMessage) {
|
|
276
|
+
const warningText = `Warning: Action "${actionName}" failed: ${errorMessage}. Check the screenshot below for the current page state and decide how to proceed.`;
|
|
277
|
+
try {
|
|
278
|
+
const screenshot = await agent.page?.screenshotBase64();
|
|
279
|
+
if (!screenshot) return {
|
|
280
|
+
content: [
|
|
281
|
+
{
|
|
282
|
+
type: 'text',
|
|
283
|
+
text: warningText
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
};
|
|
287
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
288
|
+
return {
|
|
289
|
+
content: [
|
|
290
|
+
{
|
|
291
|
+
type: 'text',
|
|
292
|
+
text: warningText
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
type: 'image',
|
|
296
|
+
data: body,
|
|
297
|
+
mimeType
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
};
|
|
301
|
+
} catch {
|
|
302
|
+
return {
|
|
303
|
+
content: [
|
|
304
|
+
{
|
|
305
|
+
type: 'text',
|
|
306
|
+
text: warningText
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function mergeToolCliMetadata(base, extra) {
|
|
313
|
+
const options = {
|
|
314
|
+
...base?.options ?? {},
|
|
315
|
+
...extra?.options ?? {}
|
|
316
|
+
};
|
|
317
|
+
return Object.keys(options).length > 0 ? {
|
|
318
|
+
options
|
|
319
|
+
} : void 0;
|
|
320
|
+
}
|
|
321
|
+
function generateToolsFromActionSpace(actionSpace, getAgent, sanitizeArgs = (args)=>args, initArgSchema = {}, initArgCliMetadata) {
|
|
322
|
+
return actionSpace.map((action)=>{
|
|
323
|
+
const schema = {
|
|
324
|
+
...extractActionSchema(action.paramSchema, action.name),
|
|
325
|
+
...initArgSchema
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
name: action.name,
|
|
329
|
+
description: describeActionForMCP(action),
|
|
330
|
+
schema,
|
|
331
|
+
cli: initArgCliMetadata,
|
|
332
|
+
handler: async (args)=>{
|
|
333
|
+
try {
|
|
334
|
+
const agent = await getAgent(args);
|
|
335
|
+
const normalizedArgs = normalizeActionArgs(sanitizeArgs(args), action.paramSchema);
|
|
336
|
+
let actionResult;
|
|
337
|
+
try {
|
|
338
|
+
actionResult = await executeAction(agent, action.name, normalizedArgs);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
341
|
+
console.error(`Error executing action "${action.name}":`, errorMessage);
|
|
342
|
+
return await captureFailureResult(agent, action.name, errorMessage);
|
|
343
|
+
}
|
|
344
|
+
return await captureScreenshotResult(agent, action.name, actionResult);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
347
|
+
console.error(`Error in handler for "${action.name}":`, errorMessage);
|
|
348
|
+
return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function generateCommonTools(getAgent, initArgSchema = {}, initArgCliMetadata) {
|
|
355
|
+
return [
|
|
356
|
+
{
|
|
357
|
+
name: 'take_screenshot',
|
|
358
|
+
description: 'Capture screenshot of current page/screen',
|
|
359
|
+
schema: {
|
|
360
|
+
...initArgSchema
|
|
361
|
+
},
|
|
362
|
+
cli: initArgCliMetadata,
|
|
363
|
+
handler: async (args = {})=>{
|
|
364
|
+
try {
|
|
365
|
+
const agent = await getAgent(args);
|
|
366
|
+
const screenshot = await agent.page?.screenshotBase64();
|
|
367
|
+
if (!screenshot) return createErrorResult('Screenshot not available');
|
|
368
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
369
|
+
return {
|
|
370
|
+
content: [
|
|
371
|
+
{
|
|
372
|
+
type: 'image',
|
|
373
|
+
data: body,
|
|
374
|
+
mimeType
|
|
375
|
+
}
|
|
376
|
+
]
|
|
377
|
+
};
|
|
378
|
+
} catch (error) {
|
|
379
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
380
|
+
console.error('Error taking screenshot:', errorMessage);
|
|
381
|
+
return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: 'act',
|
|
387
|
+
description: 'Execute a natural language action. The AI will plan and perform multi-step operations in a single invocation, useful for transient UI interactions (e.g., Spotlight, dropdown menus) that disappear between separate commands.',
|
|
388
|
+
schema: {
|
|
389
|
+
prompt: external_zod_namespaceObject.z.string().describe('Natural language description of the action to perform, e.g. "press Command+Space, type Safari, press Enter"'),
|
|
390
|
+
...initArgSchema
|
|
391
|
+
},
|
|
392
|
+
cli: mergeToolCliMetadata(void 0, initArgCliMetadata),
|
|
393
|
+
handler: async (args = {})=>{
|
|
394
|
+
const prompt = args.prompt;
|
|
395
|
+
try {
|
|
396
|
+
const agent = await getAgent(args);
|
|
397
|
+
if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
|
|
398
|
+
const result = await agent.aiAction(prompt, {
|
|
399
|
+
deepThink: false
|
|
400
|
+
});
|
|
401
|
+
const screenshotResult = await captureScreenshotResult(agent, 'act');
|
|
402
|
+
if (result) {
|
|
403
|
+
const message = 'string' == typeof result ? result : JSON.stringify(result);
|
|
404
|
+
screenshotResult.content.unshift({
|
|
405
|
+
type: 'text',
|
|
406
|
+
text: `Task finished, message: ${message}`
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return screenshotResult;
|
|
410
|
+
} catch (error) {
|
|
411
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
412
|
+
console.error('Error executing act:', errorMessage);
|
|
413
|
+
return createErrorResult(`Failed to execute act: ${errorMessage}`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
name: 'assert',
|
|
419
|
+
description: 'Assert a natural language statement against the current page/screen.',
|
|
420
|
+
schema: {
|
|
421
|
+
prompt: external_zod_namespaceObject.z.string().describe('Natural language assertion to verify, e.g. "there is a login button visible"'),
|
|
422
|
+
...initArgSchema
|
|
423
|
+
},
|
|
424
|
+
cli: mergeToolCliMetadata(void 0, initArgCliMetadata),
|
|
425
|
+
handler: async (args = {})=>{
|
|
426
|
+
const prompt = args.prompt;
|
|
427
|
+
try {
|
|
428
|
+
const agent = await getAgent(args);
|
|
429
|
+
if (!agent.aiAssert) return createErrorResult('assert is not supported by this agent');
|
|
430
|
+
await agent.aiAssert(prompt);
|
|
431
|
+
return {
|
|
432
|
+
content: [
|
|
433
|
+
{
|
|
434
|
+
type: 'text',
|
|
435
|
+
text: 'Assertion passed.'
|
|
436
|
+
}
|
|
437
|
+
]
|
|
438
|
+
};
|
|
439
|
+
} catch (error) {
|
|
440
|
+
const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
441
|
+
console.error('Error executing assert:', errorMessage);
|
|
442
|
+
return createErrorResult(`Failed to execute assert: ${errorMessage}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
exports.generateCommonTools = __webpack_exports__.generateCommonTools;
|
|
449
|
+
exports.generateToolsFromActionSpace = __webpack_exports__.generateToolsFromActionSpace;
|
|
450
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
451
|
+
"generateCommonTools",
|
|
452
|
+
"generateToolsFromActionSpace"
|
|
453
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
454
|
+
Object.defineProperty(exports, '__esModule', {
|
|
455
|
+
value: true
|
|
456
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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 ("u" > 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
|
+
defaultAppLoadingCheckIntervalMs: ()=>defaultAppLoadingCheckIntervalMs,
|
|
28
|
+
defaultAppLoadingTimeoutMs: ()=>defaultAppLoadingTimeoutMs
|
|
29
|
+
});
|
|
30
|
+
const defaultAppLoadingTimeoutMs = 10000;
|
|
31
|
+
const defaultAppLoadingCheckIntervalMs = 2000;
|
|
32
|
+
exports.defaultAppLoadingCheckIntervalMs = __webpack_exports__.defaultAppLoadingCheckIntervalMs;
|
|
33
|
+
exports.defaultAppLoadingTimeoutMs = __webpack_exports__.defaultAppLoadingTimeoutMs;
|
|
34
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
35
|
+
"defaultAppLoadingCheckIntervalMs",
|
|
36
|
+
"defaultAppLoadingTimeoutMs"
|
|
37
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
38
|
+
Object.defineProperty(exports, '__esModule', {
|
|
39
|
+
value: true
|
|
40
|
+
});
|