@midscene/shared 1.12.6 → 1.12.7-beta-20260911033547.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.
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { getKeyAliases } from "../key-alias-utils.mjs";
3
+ import { getZodTypeName } from "../zod-schema-utils.mjs";
3
4
  import { CLIError } from "./cli-error.mjs";
4
5
  function parseValue(raw) {
5
6
  if (raw.startsWith('{') || raw.startsWith('[')) try {
@@ -8,20 +9,30 @@ function parseValue(raw) {
8
9
  if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
9
10
  return raw;
10
11
  }
11
- function walkCliArgs(args, setArgValue) {
12
+ function walkCliArgs(args, setArgValue, def) {
12
13
  for(let i = 0; i < args.length; i++){
13
14
  const arg = args[i];
14
15
  if (!arg.startsWith('--')) continue;
15
16
  const body = arg.slice(2);
16
17
  const eqIdx = body.indexOf('=');
17
- if (eqIdx >= 0) setArgValue(body.slice(0, eqIdx), parseValue(body.slice(eqIdx + 1)));
18
- else if (args[i + 1] && !args[i + 1].startsWith('--')) {
18
+ if (eqIdx >= 0) {
19
+ const key = body.slice(0, eqIdx);
20
+ setArgValue(key, parseValueForCliField(body.slice(eqIdx + 1), key, def));
21
+ } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
19
22
  i++;
20
- setArgValue(body, parseValue(args[i]));
23
+ setArgValue(body, parseValueForCliField(args[i], body, def));
21
24
  } else setArgValue(body, true);
22
25
  }
23
26
  }
24
- function parseCliArgs(args) {
27
+ function findCliSchemaField(def, cliKey) {
28
+ for (const [schemaKey, field] of Object.entries(def.schema))if (getAcceptedCliOptionNames(schemaKey, def.cli?.options?.[schemaKey]).includes(cliKey)) return field;
29
+ }
30
+ function parseValueForCliField(raw, cliKey, def) {
31
+ const field = def ? findCliSchemaField(def, cliKey) : void 0;
32
+ if (field && 'string' === getZodTypeName(field)) return raw;
33
+ return parseValue(raw);
34
+ }
35
+ function parseCliArgs(args, def) {
25
36
  const result = {};
26
37
  walkCliArgs(args, (key, value)=>{
27
38
  const existing = result[key];
@@ -38,7 +49,7 @@ function parseCliArgs(args) {
38
49
  existing,
39
50
  value
40
51
  ];
41
- });
52
+ }, def);
42
53
  return result;
43
54
  }
44
55
  function formatCliOptionName(name) {
@@ -155,7 +155,7 @@ async function runToolsCLI(tools, scriptName, options) {
155
155
  }
156
156
  const parsedArgs = {
157
157
  ...positionalArgs,
158
- ...parseCliArgs(restArgs.slice(optionStartIndex))
158
+ ...parseCliArgs(restArgs.slice(optionStartIndex), match.def)
159
159
  };
160
160
  if (true === parsedArgs.help) {
161
161
  debug('showing command help for: %s', match.name);
@@ -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.12.6";
8
+ const getCurrentVersion = ()=>"1.12.7-beta-20260911033547.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,
@@ -32,6 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  });
33
33
  const external_zod_namespaceObject = require("zod");
34
34
  const external_key_alias_utils_js_namespaceObject = require("../key-alias-utils.js");
35
+ const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
35
36
  const external_cli_error_js_namespaceObject = require("./cli-error.js");
36
37
  function parseValue(raw) {
37
38
  if (raw.startsWith('{') || raw.startsWith('[')) try {
@@ -40,20 +41,30 @@ function parseValue(raw) {
40
41
  if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
41
42
  return raw;
42
43
  }
43
- function walkCliArgs(args, setArgValue) {
44
+ function walkCliArgs(args, setArgValue, def) {
44
45
  for(let i = 0; i < args.length; i++){
45
46
  const arg = args[i];
46
47
  if (!arg.startsWith('--')) continue;
47
48
  const body = arg.slice(2);
48
49
  const eqIdx = body.indexOf('=');
49
- if (eqIdx >= 0) setArgValue(body.slice(0, eqIdx), parseValue(body.slice(eqIdx + 1)));
50
- else if (args[i + 1] && !args[i + 1].startsWith('--')) {
50
+ if (eqIdx >= 0) {
51
+ const key = body.slice(0, eqIdx);
52
+ setArgValue(key, parseValueForCliField(body.slice(eqIdx + 1), key, def));
53
+ } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
51
54
  i++;
52
- setArgValue(body, parseValue(args[i]));
55
+ setArgValue(body, parseValueForCliField(args[i], body, def));
53
56
  } else setArgValue(body, true);
54
57
  }
55
58
  }
56
- function parseCliArgs(args) {
59
+ function findCliSchemaField(def, cliKey) {
60
+ for (const [schemaKey, field] of Object.entries(def.schema))if (getAcceptedCliOptionNames(schemaKey, def.cli?.options?.[schemaKey]).includes(cliKey)) return field;
61
+ }
62
+ function parseValueForCliField(raw, cliKey, def) {
63
+ const field = def ? findCliSchemaField(def, cliKey) : void 0;
64
+ if (field && 'string' === (0, external_zod_schema_utils_js_namespaceObject.getZodTypeName)(field)) return raw;
65
+ return parseValue(raw);
66
+ }
67
+ function parseCliArgs(args, def) {
57
68
  const result = {};
58
69
  walkCliArgs(args, (key, value)=>{
59
70
  const existing = result[key];
@@ -70,7 +81,7 @@ function parseCliArgs(args) {
70
81
  existing,
71
82
  value
72
83
  ];
73
- });
84
+ }, def);
74
85
  return result;
75
86
  }
76
87
  function formatCliOptionName(name) {
@@ -198,7 +198,7 @@ async function runToolsCLI(tools, scriptName, options) {
198
198
  }
199
199
  const parsedArgs = {
200
200
  ...positionalArgs,
201
- ...(0, external_cli_args_js_namespaceObject.parseCliArgs)(restArgs.slice(optionStartIndex))
201
+ ...(0, external_cli_args_js_namespaceObject.parseCliArgs)(restArgs.slice(optionStartIndex), match.def)
202
202
  };
203
203
  if (true === parsedArgs.help) {
204
204
  debug('showing command help for: %s', match.name);
@@ -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.12.6";
40
+ const getCurrentVersion = ()=>"1.12.7-beta-20260911033547.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,
@@ -1,6 +1,6 @@
1
1
  import type { ToolCliOption, ToolDefinition } from '../agent-tools/types';
2
2
  export declare function parseValue(raw: string): unknown;
3
- export declare function parseCliArgs(args: string[]): Record<string, unknown>;
3
+ export declare function parseCliArgs(args: string[], def?: ToolDefinition): Record<string, unknown>;
4
4
  export declare function getCliOptionDisplay(key: string, cliOption?: ToolCliOption): {
5
5
  label: string;
6
6
  aliases: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.12.6",
3
+ "version": "1.12.7-beta-20260911033547.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",
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { ToolCliOption, ToolDefinition } from '../agent-tools/types';
3
3
  import { getKeyAliases } from '../key-alias-utils';
4
+ import { getZodTypeName } from '../zod-schema-utils';
4
5
  import { CLIError } from './cli-error';
5
6
 
6
7
  export function parseValue(raw: string): unknown {
@@ -22,6 +23,7 @@ export function parseValue(raw: string): unknown {
22
23
  function walkCliArgs(
23
24
  args: string[],
24
25
  setArgValue: (key: string, value: unknown) => void,
26
+ def?: ToolDefinition,
25
27
  ): void {
26
28
  for (let i = 0; i < args.length; i++) {
27
29
  const arg = args[i];
@@ -31,34 +33,73 @@ function walkCliArgs(
31
33
  const eqIdx = body.indexOf('=');
32
34
 
33
35
  if (eqIdx >= 0) {
34
- setArgValue(body.slice(0, eqIdx), parseValue(body.slice(eqIdx + 1)));
36
+ const key = body.slice(0, eqIdx);
37
+ setArgValue(key, parseValueForCliField(body.slice(eqIdx + 1), key, def));
35
38
  } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
36
39
  i++;
37
- setArgValue(body, parseValue(args[i]));
40
+ setArgValue(body, parseValueForCliField(args[i], body, def));
38
41
  } else {
39
42
  setArgValue(body, true);
40
43
  }
41
44
  }
42
45
  }
43
46
 
44
- export function parseCliArgs(args: string[]): Record<string, unknown> {
47
+ function findCliSchemaField(
48
+ def: ToolDefinition,
49
+ cliKey: string,
50
+ ): z.ZodTypeAny | undefined {
51
+ for (const [schemaKey, field] of Object.entries(def.schema)) {
52
+ if (
53
+ getAcceptedCliOptionNames(
54
+ schemaKey,
55
+ def.cli?.options?.[schemaKey],
56
+ ).includes(cliKey)
57
+ ) {
58
+ return field;
59
+ }
60
+ }
61
+
62
+ return undefined;
63
+ }
64
+
65
+ function parseValueForCliField(
66
+ raw: string,
67
+ cliKey: string,
68
+ def?: ToolDefinition,
69
+ ): unknown {
70
+ const field = def ? findCliSchemaField(def, cliKey) : undefined;
71
+ if (field && getZodTypeName(field) === 'string') {
72
+ return raw;
73
+ }
74
+
75
+ return parseValue(raw);
76
+ }
77
+
78
+ export function parseCliArgs(
79
+ args: string[],
80
+ def?: ToolDefinition,
81
+ ): Record<string, unknown> {
45
82
  const result: Record<string, unknown> = {};
46
83
 
47
- walkCliArgs(args, (key, value) => {
48
- const existing = result[key];
49
- if (existing === undefined) {
50
- result[key] = value;
51
- return;
52
- }
84
+ walkCliArgs(
85
+ args,
86
+ (key, value) => {
87
+ const existing = result[key];
88
+ if (existing === undefined) {
89
+ result[key] = value;
90
+ return;
91
+ }
53
92
 
54
- if (Array.isArray(existing)) {
55
- existing.push(value);
56
- result[key] = existing;
57
- return;
58
- }
93
+ if (Array.isArray(existing)) {
94
+ existing.push(value);
95
+ result[key] = existing;
96
+ return;
97
+ }
59
98
 
60
- result[key] = [existing, value];
61
- });
99
+ result[key] = [existing, value];
100
+ },
101
+ def,
102
+ );
62
103
 
63
104
  return result;
64
105
  }
@@ -295,7 +295,7 @@ export async function runToolsCLI(
295
295
  }
296
296
  const parsedArgs = {
297
297
  ...positionalArgs,
298
- ...parseCliArgs(restArgs.slice(optionStartIndex)),
298
+ ...parseCliArgs(restArgs.slice(optionStartIndex), match.def),
299
299
  };
300
300
  if (parsedArgs.help === true) {
301
301
  debug('showing command help for: %s', match.name);