@midscene/shared 1.9.5 → 1.9.6-beta-20260612050456.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.
@@ -5,7 +5,7 @@ import { assert } from "../utils.mjs";
5
5
  import { maskConfig, parseJson } from "./helper.mjs";
6
6
  import { initDebugConfig } from "./init-debug.mjs";
7
7
  const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
8
- const getCurrentVersion = ()=>"1.9.5";
8
+ const getCurrentVersion = ()=>"1.9.6-beta-20260612050456.0";
9
9
  const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
10
10
  const KEYS_MAP = {
11
11
  insight: INSIGHT_MODEL_CONFIG_KEYS,
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ const agentBehaviorInitArgShape = {
3
+ aiActContext: z.string().optional().describe('Background knowledge passed to aiAct. Default: no extra context.'),
4
+ aiActionContext: z.string().optional().describe('Deprecated alias for aiActContext. Default: no extra context.'),
5
+ replanningCycleLimit: z.number().int().nonnegative().optional().describe('Maximum number of replanning cycles for aiAct. Default: model adapter default.'),
6
+ waitAfterAction: z.number().nonnegative().optional().describe('Wait time in milliseconds after each action execution. Default: 300ms.'),
7
+ screenshotShrinkFactor: z.number().min(1).optional().describe('Screenshot shrink factor before sending images to AI. Default: 1; high values may reduce recognition quality, especially on mobile.')
8
+ };
9
+ function extractAgentBehaviorInitArgs(extracted) {
10
+ if (!extracted) return;
11
+ const agentOptions = {
12
+ ...'string' == typeof extracted.aiActContext ? {
13
+ aiActContext: extracted.aiActContext
14
+ } : {},
15
+ ...'string' == typeof extracted.aiActionContext ? {
16
+ aiActionContext: extracted.aiActionContext
17
+ } : {},
18
+ ...'number' == typeof extracted.replanningCycleLimit ? {
19
+ replanningCycleLimit: extracted.replanningCycleLimit
20
+ } : {},
21
+ ...'number' == typeof extracted.waitAfterAction ? {
22
+ waitAfterAction: extracted.waitAfterAction
23
+ } : {},
24
+ ...'number' == typeof extracted.screenshotShrinkFactor ? {
25
+ screenshotShrinkFactor: extracted.screenshotShrinkFactor
26
+ } : {}
27
+ };
28
+ return Object.keys(agentOptions).length > 0 ? agentOptions : void 0;
29
+ }
30
+ function stableJsonValue(value) {
31
+ if (Array.isArray(value)) return value.map(stableJsonValue);
32
+ if (value && 'object' == typeof value) return Object.fromEntries(Object.entries(value).sort(([left], [right])=>left.localeCompare(right)).map(([key, nestedValue])=>[
33
+ key,
34
+ stableJsonValue(nestedValue)
35
+ ]));
36
+ return value;
37
+ }
38
+ function getAgentInitArgsSignature(initArgs) {
39
+ if (!initArgs || 0 === Object.keys(initArgs).length) return;
40
+ return JSON.stringify(stableJsonValue(initArgs));
41
+ }
42
+ export { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature };
@@ -1,6 +1,7 @@
1
1
  export * from "./base-server.mjs";
2
2
  export * from "./base-tools.mjs";
3
3
  export * from "./tool-defaults.mjs";
4
+ export * from "./agent-behavior-init-args.mjs";
4
5
  export * from "./init-arg-utils.mjs";
5
6
  export * from "./error-formatter.mjs";
6
7
  export * from "./tool-generator.mjs";
@@ -37,7 +37,7 @@ const external_utils_js_namespaceObject = require("../utils.js");
37
37
  const external_helper_js_namespaceObject = require("./helper.js");
38
38
  const external_init_debug_js_namespaceObject = require("./init-debug.js");
39
39
  const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
40
- const getCurrentVersion = ()=>"1.9.5";
40
+ const getCurrentVersion = ()=>"1.9.6-beta-20260612050456.0";
41
41
  const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${external_types_js_namespaceObject.MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
42
42
  const KEYS_MAP = {
43
43
  insight: external_constants_js_namespaceObject.INSIGHT_MODEL_CONFIG_KEYS,
@@ -0,0 +1,82 @@
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
+ extractAgentBehaviorInitArgs: ()=>extractAgentBehaviorInitArgs,
28
+ agentBehaviorInitArgShape: ()=>agentBehaviorInitArgShape,
29
+ getAgentInitArgsSignature: ()=>getAgentInitArgsSignature
30
+ });
31
+ const external_zod_namespaceObject = require("zod");
32
+ const agentBehaviorInitArgShape = {
33
+ aiActContext: external_zod_namespaceObject.z.string().optional().describe('Background knowledge passed to aiAct. Default: no extra context.'),
34
+ aiActionContext: external_zod_namespaceObject.z.string().optional().describe('Deprecated alias for aiActContext. Default: no extra context.'),
35
+ replanningCycleLimit: external_zod_namespaceObject.z.number().int().nonnegative().optional().describe('Maximum number of replanning cycles for aiAct. Default: model adapter default.'),
36
+ waitAfterAction: external_zod_namespaceObject.z.number().nonnegative().optional().describe('Wait time in milliseconds after each action execution. Default: 300ms.'),
37
+ screenshotShrinkFactor: external_zod_namespaceObject.z.number().min(1).optional().describe('Screenshot shrink factor before sending images to AI. Default: 1; high values may reduce recognition quality, especially on mobile.')
38
+ };
39
+ function extractAgentBehaviorInitArgs(extracted) {
40
+ if (!extracted) return;
41
+ const agentOptions = {
42
+ ...'string' == typeof extracted.aiActContext ? {
43
+ aiActContext: extracted.aiActContext
44
+ } : {},
45
+ ...'string' == typeof extracted.aiActionContext ? {
46
+ aiActionContext: extracted.aiActionContext
47
+ } : {},
48
+ ...'number' == typeof extracted.replanningCycleLimit ? {
49
+ replanningCycleLimit: extracted.replanningCycleLimit
50
+ } : {},
51
+ ...'number' == typeof extracted.waitAfterAction ? {
52
+ waitAfterAction: extracted.waitAfterAction
53
+ } : {},
54
+ ...'number' == typeof extracted.screenshotShrinkFactor ? {
55
+ screenshotShrinkFactor: extracted.screenshotShrinkFactor
56
+ } : {}
57
+ };
58
+ return Object.keys(agentOptions).length > 0 ? agentOptions : void 0;
59
+ }
60
+ function stableJsonValue(value) {
61
+ if (Array.isArray(value)) return value.map(stableJsonValue);
62
+ if (value && 'object' == typeof value) return Object.fromEntries(Object.entries(value).sort(([left], [right])=>left.localeCompare(right)).map(([key, nestedValue])=>[
63
+ key,
64
+ stableJsonValue(nestedValue)
65
+ ]));
66
+ return value;
67
+ }
68
+ function getAgentInitArgsSignature(initArgs) {
69
+ if (!initArgs || 0 === Object.keys(initArgs).length) return;
70
+ return JSON.stringify(stableJsonValue(initArgs));
71
+ }
72
+ exports.agentBehaviorInitArgShape = __webpack_exports__.agentBehaviorInitArgShape;
73
+ exports.extractAgentBehaviorInitArgs = __webpack_exports__.extractAgentBehaviorInitArgs;
74
+ exports.getAgentInitArgsSignature = __webpack_exports__.getAgentInitArgsSignature;
75
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
76
+ "agentBehaviorInitArgShape",
77
+ "extractAgentBehaviorInitArgs",
78
+ "getAgentInitArgsSignature"
79
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
80
+ Object.defineProperty(exports, '__esModule', {
81
+ value: true
82
+ });
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  var __webpack_modules__ = {
3
+ "./agent-behavior-init-args" (module) {
4
+ module.exports = require("./agent-behavior-init-args.js");
5
+ },
3
6
  "./base-server" (module) {
4
7
  module.exports = require("./base-server.js");
5
8
  },
@@ -86,33 +89,37 @@ var __webpack_exports__ = {};
86
89
  var __rspack_reexport = {};
87
90
  for(const __rspack_import_key in _tool_defaults__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tool_defaults__rspack_import_2[__rspack_import_key];
88
91
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
89
- var _init_arg_utils__rspack_import_3 = __webpack_require__("./init-arg-utils");
92
+ var _agent_behavior_init_args__rspack_import_3 = __webpack_require__("./agent-behavior-init-args");
93
+ var __rspack_reexport = {};
94
+ for(const __rspack_import_key in _agent_behavior_init_args__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_agent_behavior_init_args__rspack_import_3[__rspack_import_key];
95
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
96
+ var _init_arg_utils__rspack_import_4 = __webpack_require__("./init-arg-utils");
90
97
  var __rspack_reexport = {};
91
- for(const __rspack_import_key in _init_arg_utils__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_init_arg_utils__rspack_import_3[__rspack_import_key];
98
+ for(const __rspack_import_key in _init_arg_utils__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_init_arg_utils__rspack_import_4[__rspack_import_key];
92
99
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
93
- var _error_formatter__rspack_import_4 = __webpack_require__("./error-formatter");
100
+ var _error_formatter__rspack_import_5 = __webpack_require__("./error-formatter");
94
101
  var __rspack_reexport = {};
95
- for(const __rspack_import_key in _error_formatter__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_error_formatter__rspack_import_4[__rspack_import_key];
102
+ for(const __rspack_import_key in _error_formatter__rspack_import_5)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_error_formatter__rspack_import_5[__rspack_import_key];
96
103
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
97
- var _tool_generator__rspack_import_5 = __webpack_require__("./tool-generator");
104
+ var _tool_generator__rspack_import_6 = __webpack_require__("./tool-generator");
98
105
  var __rspack_reexport = {};
99
- for(const __rspack_import_key in _tool_generator__rspack_import_5)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tool_generator__rspack_import_5[__rspack_import_key];
106
+ for(const __rspack_import_key in _tool_generator__rspack_import_6)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tool_generator__rspack_import_6[__rspack_import_key];
100
107
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
101
- var _types__rspack_import_6 = __webpack_require__("./types");
108
+ var _types__rspack_import_7 = __webpack_require__("./types");
102
109
  var __rspack_reexport = {};
103
- for(const __rspack_import_key in _types__rspack_import_6)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_6[__rspack_import_key];
110
+ for(const __rspack_import_key in _types__rspack_import_7)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_7[__rspack_import_key];
104
111
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
105
- var _inject_report_html_plugin__rspack_import_7 = __webpack_require__("./inject-report-html-plugin");
112
+ var _inject_report_html_plugin__rspack_import_8 = __webpack_require__("./inject-report-html-plugin");
106
113
  var __rspack_reexport = {};
107
- for(const __rspack_import_key in _inject_report_html_plugin__rspack_import_7)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_inject_report_html_plugin__rspack_import_7[__rspack_import_key];
114
+ for(const __rspack_import_key in _inject_report_html_plugin__rspack_import_8)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_inject_report_html_plugin__rspack_import_8[__rspack_import_key];
108
115
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
109
- var _launcher_helper__rspack_import_8 = __webpack_require__("./launcher-helper");
116
+ var _launcher_helper__rspack_import_9 = __webpack_require__("./launcher-helper");
110
117
  var __rspack_reexport = {};
111
- for(const __rspack_import_key in _launcher_helper__rspack_import_8)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_launcher_helper__rspack_import_8[__rspack_import_key];
118
+ for(const __rspack_import_key in _launcher_helper__rspack_import_9)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_launcher_helper__rspack_import_9[__rspack_import_key];
112
119
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
113
- var _chrome_path__rspack_import_9 = __webpack_require__("./chrome-path");
120
+ var _chrome_path__rspack_import_10 = __webpack_require__("./chrome-path");
114
121
  var __rspack_reexport = {};
115
- for(const __rspack_import_key in _chrome_path__rspack_import_9)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_chrome_path__rspack_import_9[__rspack_import_key];
122
+ for(const __rspack_import_key in _chrome_path__rspack_import_10)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_chrome_path__rspack_import_10[__rspack_import_key];
116
123
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
117
124
  })();
118
125
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ export interface AgentBehaviorInitArgs {
3
+ aiActContext?: string;
4
+ aiActionContext?: string;
5
+ replanningCycleLimit?: number;
6
+ waitAfterAction?: number;
7
+ screenshotShrinkFactor?: number;
8
+ }
9
+ export declare const agentBehaviorInitArgShape: {
10
+ aiActContext: z.ZodOptional<z.ZodString>;
11
+ aiActionContext: z.ZodOptional<z.ZodString>;
12
+ replanningCycleLimit: z.ZodOptional<z.ZodNumber>;
13
+ waitAfterAction: z.ZodOptional<z.ZodNumber>;
14
+ screenshotShrinkFactor: z.ZodOptional<z.ZodNumber>;
15
+ };
16
+ export declare function extractAgentBehaviorInitArgs(extracted: Partial<AgentBehaviorInitArgs> | undefined): AgentBehaviorInitArgs | undefined;
17
+ export declare function getAgentInitArgsSignature(initArgs: object | undefined): string | undefined;
@@ -1,6 +1,7 @@
1
1
  export * from './base-server';
2
2
  export * from './base-tools';
3
3
  export * from './tool-defaults';
4
+ export * from './agent-behavior-init-args';
4
5
  export * from './init-arg-utils';
5
6
  export * from './error-formatter';
6
7
  export * from './tool-generator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.9.5",
3
+ "version": "1.9.6-beta-20260612050456.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -0,0 +1,98 @@
1
+ import { z } from 'zod';
2
+
3
+ export interface AgentBehaviorInitArgs {
4
+ aiActContext?: string;
5
+ aiActionContext?: string;
6
+ replanningCycleLimit?: number;
7
+ waitAfterAction?: number;
8
+ screenshotShrinkFactor?: number;
9
+ }
10
+
11
+ export const agentBehaviorInitArgShape = {
12
+ aiActContext: z
13
+ .string()
14
+ .optional()
15
+ .describe(
16
+ 'Background knowledge passed to aiAct. Default: no extra context.',
17
+ ),
18
+ aiActionContext: z
19
+ .string()
20
+ .optional()
21
+ .describe('Deprecated alias for aiActContext. Default: no extra context.'),
22
+ replanningCycleLimit: z
23
+ .number()
24
+ .int()
25
+ .nonnegative()
26
+ .optional()
27
+ .describe(
28
+ 'Maximum number of replanning cycles for aiAct. Default: model adapter default.',
29
+ ),
30
+ waitAfterAction: z
31
+ .number()
32
+ .nonnegative()
33
+ .optional()
34
+ .describe(
35
+ 'Wait time in milliseconds after each action execution. Default: 300ms.',
36
+ ),
37
+ screenshotShrinkFactor: z
38
+ .number()
39
+ .min(1)
40
+ .optional()
41
+ .describe(
42
+ 'Screenshot shrink factor before sending images to AI. Default: 1; high values may reduce recognition quality, especially on mobile.',
43
+ ),
44
+ } satisfies Record<keyof AgentBehaviorInitArgs, z.ZodTypeAny>;
45
+
46
+ export function extractAgentBehaviorInitArgs(
47
+ extracted: Partial<AgentBehaviorInitArgs> | undefined,
48
+ ): AgentBehaviorInitArgs | undefined {
49
+ if (!extracted) {
50
+ return undefined;
51
+ }
52
+
53
+ const agentOptions: AgentBehaviorInitArgs = {
54
+ ...(typeof extracted.aiActContext === 'string'
55
+ ? { aiActContext: extracted.aiActContext }
56
+ : {}),
57
+ ...(typeof extracted.aiActionContext === 'string'
58
+ ? { aiActionContext: extracted.aiActionContext }
59
+ : {}),
60
+ ...(typeof extracted.replanningCycleLimit === 'number'
61
+ ? { replanningCycleLimit: extracted.replanningCycleLimit }
62
+ : {}),
63
+ ...(typeof extracted.waitAfterAction === 'number'
64
+ ? { waitAfterAction: extracted.waitAfterAction }
65
+ : {}),
66
+ ...(typeof extracted.screenshotShrinkFactor === 'number'
67
+ ? { screenshotShrinkFactor: extracted.screenshotShrinkFactor }
68
+ : {}),
69
+ };
70
+
71
+ return Object.keys(agentOptions).length > 0 ? agentOptions : undefined;
72
+ }
73
+
74
+ function stableJsonValue(value: unknown): unknown {
75
+ if (Array.isArray(value)) {
76
+ return value.map(stableJsonValue);
77
+ }
78
+
79
+ if (value && typeof value === 'object') {
80
+ return Object.fromEntries(
81
+ Object.entries(value as Record<string, unknown>)
82
+ .sort(([left], [right]) => left.localeCompare(right))
83
+ .map(([key, nestedValue]) => [key, stableJsonValue(nestedValue)]),
84
+ );
85
+ }
86
+
87
+ return value;
88
+ }
89
+
90
+ export function getAgentInitArgsSignature(
91
+ initArgs: object | undefined,
92
+ ): string | undefined {
93
+ if (!initArgs || Object.keys(initArgs).length === 0) {
94
+ return undefined;
95
+ }
96
+
97
+ return JSON.stringify(stableJsonValue(initArgs));
98
+ }
package/src/mcp/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './base-server';
2
2
  export * from './base-tools';
3
3
  export * from './tool-defaults';
4
+ export * from './agent-behavior-init-args';
4
5
  export * from './init-arg-utils';
5
6
  export * from './error-formatter';
6
7
  export * from './tool-generator';