@midscene/shared 1.0.1-beta-20251208031823.0 → 1.0.1-beta-20251208031856.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/mcp/base-server.mjs +241 -0
- package/dist/es/mcp/base-tools.mjs +84 -0
- package/dist/es/mcp/index.mjs +4 -0
- package/dist/es/mcp/tool-generator.mjs +215 -0
- package/dist/es/mcp/types.mjs +3 -0
- package/dist/es/node/fs.mjs +1 -1
- package/dist/lib/baseDB.js +2 -2
- package/dist/lib/build/copy-static.js +2 -2
- package/dist/lib/build/rspack-config.js +2 -2
- package/dist/lib/common.js +2 -2
- package/dist/lib/constants/example-code.js +2 -2
- package/dist/lib/constants/index.js +2 -2
- package/dist/lib/env/basic.js +2 -2
- package/dist/lib/env/constants.js +2 -2
- package/dist/lib/env/global-config-manager.js +2 -2
- package/dist/lib/env/helper.js +2 -2
- package/dist/lib/env/index.js +6 -6
- package/dist/lib/env/init-debug.js +2 -2
- package/dist/lib/env/model-config-manager.js +2 -2
- package/dist/lib/env/parse-model-config.js +2 -2
- package/dist/lib/env/types.js +2 -2
- package/dist/lib/env/utils.js +2 -2
- package/dist/lib/extractor/constants.js +2 -2
- package/dist/lib/extractor/debug.js +1 -1
- package/dist/lib/extractor/dom-util.js +2 -2
- package/dist/lib/extractor/index.js +2 -2
- package/dist/lib/extractor/locator.js +2 -2
- package/dist/lib/extractor/tree.js +2 -2
- package/dist/lib/extractor/util.js +2 -2
- package/dist/lib/extractor/web-extractor.js +2 -2
- package/dist/lib/img/box-select.js +2 -2
- package/dist/lib/img/draw-box.js +2 -2
- package/dist/lib/img/get-jimp.js +2 -2
- package/dist/lib/img/get-photon.js +2 -2
- package/dist/lib/img/get-sharp.js +2 -2
- package/dist/lib/img/index.js +2 -2
- package/dist/lib/img/info.js +2 -2
- package/dist/lib/img/transform.js +2 -2
- package/dist/lib/index.js +2 -2
- package/dist/lib/logger.js +2 -2
- package/dist/lib/mcp/base-server.js +281 -0
- package/dist/lib/mcp/base-tools.js +118 -0
- package/dist/lib/mcp/index.js +79 -0
- package/dist/lib/mcp/tool-generator.js +252 -0
- package/dist/lib/mcp/types.js +40 -0
- package/dist/lib/node/fs.js +3 -3
- package/dist/lib/node/index.js +2 -2
- package/dist/lib/polyfills/async-hooks.js +2 -2
- package/dist/lib/polyfills/index.js +2 -2
- package/dist/lib/types/index.js +2 -2
- package/dist/lib/us-keyboard-layout.js +2 -2
- package/dist/lib/utils.js +2 -2
- package/dist/types/mcp/base-server.d.ts +77 -0
- package/dist/types/mcp/base-tools.d.ts +51 -0
- package/dist/types/mcp/index.d.ts +4 -0
- package/dist/types/mcp/tool-generator.d.ts +11 -0
- package/dist/types/mcp/types.d.ts +98 -0
- package/package.json +17 -3
- package/src/mcp/base-server.ts +419 -0
- package/src/mcp/base-tools.ts +190 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/tool-generator.ts +311 -0
- package/src/mcp/types.ts +106 -0
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
BaseMidsceneTools: ()=>BaseMidsceneTools
|
|
28
|
+
});
|
|
29
|
+
const img_namespaceObject = require("@midscene/shared/img");
|
|
30
|
+
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
31
|
+
const external_tool_generator_js_namespaceObject = require("./tool-generator.js");
|
|
32
|
+
function _define_property(obj, key, value) {
|
|
33
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
else obj[key] = value;
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
const debug = (0, logger_namespaceObject.getDebug)('mcp:base-tools');
|
|
43
|
+
class BaseMidsceneTools {
|
|
44
|
+
preparePlatformTools() {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
async initTools() {
|
|
48
|
+
this.toolDefinitions = [];
|
|
49
|
+
const platformTools = this.preparePlatformTools();
|
|
50
|
+
this.toolDefinitions.push(...platformTools);
|
|
51
|
+
let actionSpace;
|
|
52
|
+
try {
|
|
53
|
+
const agent = await this.ensureAgent();
|
|
54
|
+
actionSpace = await agent.getActionSpace();
|
|
55
|
+
debug('Action space from connected agent:', actionSpace.map((a)=>a.name).join(', '));
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
58
|
+
errorMessage.includes('requires a URL') || errorMessage.includes('web_connect') ? debug('Bridge mode detected - agent will be initialized on first web_connect call') : debug('Agent not available yet, using temporary device for action space');
|
|
59
|
+
const tempDevice = this.createTemporaryDevice();
|
|
60
|
+
actionSpace = tempDevice.actionSpace();
|
|
61
|
+
debug('Action space from temporary device:', actionSpace.map((a)=>a.name).join(', '));
|
|
62
|
+
await tempDevice.destroy?.();
|
|
63
|
+
}
|
|
64
|
+
const actionTools = (0, external_tool_generator_js_namespaceObject.generateToolsFromActionSpace)(actionSpace, ()=>this.ensureAgent());
|
|
65
|
+
const commonTools = (0, external_tool_generator_js_namespaceObject.generateCommonTools)(()=>this.ensureAgent());
|
|
66
|
+
this.toolDefinitions.push(...actionTools, ...commonTools);
|
|
67
|
+
debug('Total tools prepared:', this.toolDefinitions.length);
|
|
68
|
+
}
|
|
69
|
+
attachToServer(server) {
|
|
70
|
+
this.mcpServer = server;
|
|
71
|
+
if (0 === this.toolDefinitions.length) debug('Warning: No tools to register. Tools may be initialized lazily.');
|
|
72
|
+
for (const toolDef of this.toolDefinitions)if (toolDef.autoDestroy) this.toolWithAutoDestroy(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
73
|
+
else this.mcpServer.tool(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
74
|
+
debug('Registered', this.toolDefinitions.length, 'tools');
|
|
75
|
+
}
|
|
76
|
+
toolWithAutoDestroy(name, description, schema, handler) {
|
|
77
|
+
if (!this.mcpServer) throw new Error('MCP server not attached');
|
|
78
|
+
this.mcpServer.tool(name, description, schema, async (...args)=>{
|
|
79
|
+
try {
|
|
80
|
+
return await handler(...args);
|
|
81
|
+
} finally{
|
|
82
|
+
if (!process.env.MIDSCENE_MCP_DISABLE_AGENT_AUTO_DESTROY) {
|
|
83
|
+
try {
|
|
84
|
+
await this.agent?.destroy?.();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
debug('Failed to destroy agent during cleanup:', error);
|
|
87
|
+
}
|
|
88
|
+
this.agent = void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async closeBrowser() {
|
|
94
|
+
await this.agent?.destroy?.();
|
|
95
|
+
}
|
|
96
|
+
buildScreenshotContent(screenshot) {
|
|
97
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
98
|
+
return [
|
|
99
|
+
{
|
|
100
|
+
type: 'image',
|
|
101
|
+
data: body,
|
|
102
|
+
mimeType
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
constructor(){
|
|
107
|
+
_define_property(this, "mcpServer", void 0);
|
|
108
|
+
_define_property(this, "agent", void 0);
|
|
109
|
+
_define_property(this, "toolDefinitions", []);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.BaseMidsceneTools = __webpack_exports__.BaseMidsceneTools;
|
|
113
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
114
|
+
"BaseMidsceneTools"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./base-server" (module) {
|
|
4
|
+
module.exports = require("./base-server.js");
|
|
5
|
+
},
|
|
6
|
+
"./base-tools" (module) {
|
|
7
|
+
module.exports = require("./base-tools.js");
|
|
8
|
+
},
|
|
9
|
+
"./tool-generator" (module) {
|
|
10
|
+
module.exports = require("./tool-generator.js");
|
|
11
|
+
},
|
|
12
|
+
"./types" (module) {
|
|
13
|
+
module.exports = require("./types.js");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __webpack_module_cache__ = {};
|
|
17
|
+
function __webpack_require__(moduleId) {
|
|
18
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
19
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
20
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
21
|
+
exports: {}
|
|
22
|
+
};
|
|
23
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
24
|
+
return module.exports;
|
|
25
|
+
}
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.n = (module)=>{
|
|
28
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
29
|
+
__webpack_require__.d(getter, {
|
|
30
|
+
a: getter
|
|
31
|
+
});
|
|
32
|
+
return getter;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
(()=>{
|
|
36
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
37
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: definition[key]
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
(()=>{
|
|
44
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
45
|
+
})();
|
|
46
|
+
(()=>{
|
|
47
|
+
__webpack_require__.r = (exports1)=>{
|
|
48
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
49
|
+
value: 'Module'
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
52
|
+
value: true
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
var __webpack_exports__ = {};
|
|
57
|
+
(()=>{
|
|
58
|
+
__webpack_require__.r(__webpack_exports__);
|
|
59
|
+
var _base_server__rspack_import_0 = __webpack_require__("./base-server");
|
|
60
|
+
var __rspack_reexport = {};
|
|
61
|
+
for(const __rspack_import_key in _base_server__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_base_server__rspack_import_0[__rspack_import_key];
|
|
62
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
63
|
+
var _base_tools__rspack_import_1 = __webpack_require__("./base-tools");
|
|
64
|
+
var __rspack_reexport = {};
|
|
65
|
+
for(const __rspack_import_key in _base_tools__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_base_tools__rspack_import_1[__rspack_import_key];
|
|
66
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
67
|
+
var _tool_generator__rspack_import_2 = __webpack_require__("./tool-generator");
|
|
68
|
+
var __rspack_reexport = {};
|
|
69
|
+
for(const __rspack_import_key in _tool_generator__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tool_generator__rspack_import_2[__rspack_import_key];
|
|
70
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
71
|
+
var _types__rspack_import_3 = __webpack_require__("./types");
|
|
72
|
+
var __rspack_reexport = {};
|
|
73
|
+
for(const __rspack_import_key in _types__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_3[__rspack_import_key];
|
|
74
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
75
|
+
})();
|
|
76
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
77
|
+
Object.defineProperty(exports, '__esModule', {
|
|
78
|
+
value: true
|
|
79
|
+
});
|
|
@@ -0,0 +1,252 @@
|
|
|
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
|
+
generateToolsFromActionSpace: ()=>generateToolsFromActionSpace,
|
|
28
|
+
generateCommonTools: ()=>generateCommonTools
|
|
29
|
+
});
|
|
30
|
+
const img_namespaceObject = require("@midscene/shared/img");
|
|
31
|
+
const external_zod_namespaceObject = require("zod");
|
|
32
|
+
function getErrorMessage(error) {
|
|
33
|
+
return error instanceof Error ? error.message : String(error);
|
|
34
|
+
}
|
|
35
|
+
function isZodOptional(value) {
|
|
36
|
+
return '_def' in value && value._def?.typeName === 'ZodOptional';
|
|
37
|
+
}
|
|
38
|
+
function isZodObject(value) {
|
|
39
|
+
return '_def' in value && value._def?.typeName === 'ZodObject' && 'shape' in value;
|
|
40
|
+
}
|
|
41
|
+
function unwrapOptional(value) {
|
|
42
|
+
if (isZodOptional(value)) return {
|
|
43
|
+
innerValue: value._def.innerType,
|
|
44
|
+
isOptional: true
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
innerValue: value,
|
|
48
|
+
isOptional: false
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function isLocateField(value) {
|
|
52
|
+
if (!isZodObject(value)) return false;
|
|
53
|
+
return 'prompt' in value.shape;
|
|
54
|
+
}
|
|
55
|
+
function makePromptOptional(value, wrapInOptional) {
|
|
56
|
+
const newShape = {
|
|
57
|
+
...value.shape
|
|
58
|
+
};
|
|
59
|
+
newShape.prompt = value.shape.prompt.optional();
|
|
60
|
+
let newSchema = external_zod_namespaceObject.z.object(newShape).passthrough();
|
|
61
|
+
if (wrapInOptional) newSchema = newSchema.optional();
|
|
62
|
+
return newSchema;
|
|
63
|
+
}
|
|
64
|
+
function transformSchemaField(key, value) {
|
|
65
|
+
const { innerValue, isOptional } = unwrapOptional(value);
|
|
66
|
+
if (isZodObject(innerValue) && isLocateField(innerValue)) return [
|
|
67
|
+
key,
|
|
68
|
+
makePromptOptional(innerValue, isOptional)
|
|
69
|
+
];
|
|
70
|
+
return [
|
|
71
|
+
key,
|
|
72
|
+
value
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
function extractActionSchema(paramSchema) {
|
|
76
|
+
if (!paramSchema) return {};
|
|
77
|
+
const schema = paramSchema;
|
|
78
|
+
if (!isZodObject(schema)) return schema;
|
|
79
|
+
return Object.fromEntries(Object.entries(schema.shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
80
|
+
}
|
|
81
|
+
function serializeArgsToDescription(args) {
|
|
82
|
+
try {
|
|
83
|
+
return Object.entries(args).map(([key, value])=>{
|
|
84
|
+
if ('object' == typeof value && null !== value) try {
|
|
85
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
86
|
+
} catch {
|
|
87
|
+
return `${key}: [object]`;
|
|
88
|
+
}
|
|
89
|
+
return `${key}: "${value}"`;
|
|
90
|
+
}).join(', ');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
const errorMessage = getErrorMessage(error);
|
|
93
|
+
console.error('Error serializing args:', errorMessage);
|
|
94
|
+
return `[args serialization failed: ${errorMessage}]`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function buildActionInstruction(actionName, args) {
|
|
98
|
+
const argsDescription = serializeArgsToDescription(args);
|
|
99
|
+
return argsDescription ? `Use the action "${actionName}" with ${argsDescription}` : `Use the action "${actionName}"`;
|
|
100
|
+
}
|
|
101
|
+
async function captureScreenshotResult(agent, actionName) {
|
|
102
|
+
try {
|
|
103
|
+
const screenshot = await agent.page?.screenshotBase64();
|
|
104
|
+
if (!screenshot) return {
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: `Action "${actionName}" completed.`
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
113
|
+
return {
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: 'text',
|
|
117
|
+
text: `Action "${actionName}" completed.`
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: 'image',
|
|
121
|
+
data: body,
|
|
122
|
+
mimeType
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const errorMessage = getErrorMessage(error);
|
|
128
|
+
console.error('Error capturing screenshot:', errorMessage);
|
|
129
|
+
return {
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: 'text',
|
|
133
|
+
text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function createErrorResult(message) {
|
|
140
|
+
return {
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: 'text',
|
|
144
|
+
text: message
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
isError: true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function generateToolsFromActionSpace(actionSpace, getAgent) {
|
|
151
|
+
return actionSpace.map((action)=>{
|
|
152
|
+
const schema = extractActionSchema(action.paramSchema);
|
|
153
|
+
return {
|
|
154
|
+
name: action.name,
|
|
155
|
+
description: action.description || `Execute ${action.name} action`,
|
|
156
|
+
schema,
|
|
157
|
+
handler: async (args)=>{
|
|
158
|
+
try {
|
|
159
|
+
const agent = await getAgent();
|
|
160
|
+
if (agent.aiAction) {
|
|
161
|
+
const instruction = buildActionInstruction(action.name, args);
|
|
162
|
+
try {
|
|
163
|
+
await agent.aiAction(instruction);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const errorMessage = getErrorMessage(error);
|
|
166
|
+
console.error(`Error executing action "${action.name}":`, errorMessage);
|
|
167
|
+
return createErrorResult(`Failed to execute action "${action.name}": ${errorMessage}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return await captureScreenshotResult(agent, action.name);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
const errorMessage = getErrorMessage(error);
|
|
173
|
+
console.error(`Error in handler for "${action.name}":`, errorMessage);
|
|
174
|
+
return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
autoDestroy: true
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function generateCommonTools(getAgent) {
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
name: 'take_screenshot',
|
|
185
|
+
description: 'Capture screenshot of current page/screen',
|
|
186
|
+
schema: {},
|
|
187
|
+
handler: async ()=>{
|
|
188
|
+
try {
|
|
189
|
+
const agent = await getAgent();
|
|
190
|
+
const screenshot = await agent.page?.screenshotBase64();
|
|
191
|
+
if (!screenshot) return createErrorResult('Screenshot not available');
|
|
192
|
+
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
193
|
+
return {
|
|
194
|
+
content: [
|
|
195
|
+
{
|
|
196
|
+
type: 'image',
|
|
197
|
+
data: body,
|
|
198
|
+
mimeType
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
};
|
|
202
|
+
} catch (error) {
|
|
203
|
+
const errorMessage = getErrorMessage(error);
|
|
204
|
+
console.error('Error taking screenshot:', errorMessage);
|
|
205
|
+
return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
autoDestroy: true
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: 'wait_for',
|
|
212
|
+
description: 'Wait until condition becomes true',
|
|
213
|
+
schema: {
|
|
214
|
+
assertion: external_zod_namespaceObject.z.string().describe('Condition to wait for'),
|
|
215
|
+
timeoutMs: external_zod_namespaceObject.z.number().optional().default(15000),
|
|
216
|
+
checkIntervalMs: external_zod_namespaceObject.z.number().optional().default(3000)
|
|
217
|
+
},
|
|
218
|
+
handler: async (args)=>{
|
|
219
|
+
try {
|
|
220
|
+
const agent = await getAgent();
|
|
221
|
+
const { assertion, timeoutMs, checkIntervalMs } = args;
|
|
222
|
+
if (agent.aiWaitFor) await agent.aiWaitFor(assertion, {
|
|
223
|
+
timeoutMs,
|
|
224
|
+
checkIntervalMs
|
|
225
|
+
});
|
|
226
|
+
return {
|
|
227
|
+
content: [
|
|
228
|
+
{
|
|
229
|
+
type: 'text',
|
|
230
|
+
text: `Condition met: "${assertion}"`
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
};
|
|
234
|
+
} catch (error) {
|
|
235
|
+
const errorMessage = getErrorMessage(error);
|
|
236
|
+
console.error('Error in wait_for:', errorMessage);
|
|
237
|
+
return createErrorResult(`Wait condition failed: ${errorMessage}`);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
autoDestroy: true
|
|
241
|
+
}
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
exports.generateCommonTools = __webpack_exports__.generateCommonTools;
|
|
245
|
+
exports.generateToolsFromActionSpace = __webpack_exports__.generateToolsFromActionSpace;
|
|
246
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
247
|
+
"generateCommonTools",
|
|
248
|
+
"generateToolsFromActionSpace"
|
|
249
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
250
|
+
Object.defineProperty(exports, '__esModule', {
|
|
251
|
+
value: true
|
|
252
|
+
});
|
|
@@ -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 ('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
|
+
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
|
+
});
|