@midscene/shared 1.12.7-beta-20260911063016.0 → 1.12.7

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,16 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { getKeyAliases } from "../key-alias-utils.mjs";
3
- import { getZodValueKinds } from "../zod-schema-utils.mjs";
4
3
  import { CLIError } from "./cli-error.mjs";
5
- const cliNumberPattern = /^-?\d+(\.\d+)?$/;
6
- function parseValue(raw) {
7
- if (raw.startsWith('{') || raw.startsWith('[')) try {
8
- return JSON.parse(raw);
9
- } catch {}
10
- if (cliNumberPattern.test(raw)) return Number(raw);
11
- return raw;
12
- }
13
- function walkCliArgs(args, setArgValue, fieldByCliName) {
4
+ import { parseCliValue, parseValue } from "./cli-value.mjs";
5
+ function walkCliArgs(args, setArgValue) {
14
6
  for(let i = 0; i < args.length; i++){
15
7
  const arg = args[i];
16
8
  if (!arg.startsWith('--')) continue;
@@ -18,10 +10,10 @@ function walkCliArgs(args, setArgValue, fieldByCliName) {
18
10
  const eqIdx = body.indexOf('=');
19
11
  if (eqIdx >= 0) {
20
12
  const key = body.slice(0, eqIdx);
21
- setArgValue(key, parseCliValue(body.slice(eqIdx + 1), fieldByCliName?.get(key)));
13
+ setArgValue(key, body.slice(eqIdx + 1));
22
14
  } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
23
15
  i++;
24
- setArgValue(body, parseCliValue(args[i], fieldByCliName?.get(body)));
16
+ setArgValue(body, args[i]);
25
17
  } else setArgValue(body, true);
26
18
  }
27
19
  }
@@ -30,48 +22,29 @@ function buildCliFieldIndex(def) {
30
22
  for (const [schemaKey, field] of Object.entries(def.schema))for (const cliName of getAcceptedCliOptionNames(schemaKey, def.cli?.options?.[schemaKey]))fieldByCliName.set(cliName, field);
31
23
  return fieldByCliName;
32
24
  }
33
- function parseJsonValue(raw) {
34
- if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
35
- try {
36
- return JSON.parse(raw);
37
- } catch {
38
- return raw;
39
- }
40
- }
41
- function parseCliValue(raw, field) {
42
- if (!field) return parseValue(raw);
43
- const kinds = getZodValueKinds(field);
44
- if (kinds.has('object') || kinds.has('array')) {
45
- const parsedJson = parseJsonValue(raw);
46
- if (parsedJson !== raw) return parsedJson;
47
- }
48
- if (kinds.has('string')) return raw;
49
- if (kinds.has('number') && cliNumberPattern.test(raw)) return Number(raw);
50
- if (kinds.has('boolean')) {
51
- if ('true' === raw) return true;
52
- if ('false' === raw) return false;
53
- }
54
- return kinds.has('unknown') ? parseValue(raw) : raw;
55
- }
56
25
  function parseCliArgs(args, def) {
57
- const result = {};
58
26
  const fieldByCliName = def ? buildCliFieldIndex(def) : void 0;
59
- walkCliArgs(args, (key, value)=>{
60
- const existing = result[key];
61
- if (void 0 === existing) {
62
- result[key] = value;
63
- return;
64
- }
65
- if (Array.isArray(existing)) {
66
- existing.push(value);
67
- result[key] = existing;
68
- return;
27
+ const tokensByName = new Map();
28
+ walkCliArgs(args, (key, raw)=>{
29
+ const tokens = tokensByName.get(key) ?? [];
30
+ tokens.push(raw);
31
+ tokensByName.set(key, tokens);
32
+ });
33
+ const result = {};
34
+ for (const [key, tokens] of tokensByName){
35
+ let elementIndex = 0;
36
+ for (const raw of tokens){
37
+ const existing = result[key];
38
+ const value = true === raw ? true : parseCliValue(raw, fieldByCliName?.get(key), tokens.length > 1 ? elementIndex : void 0);
39
+ if (void 0 === existing) result[key] = value;
40
+ else if (Array.isArray(existing)) existing.push(value);
41
+ else result[key] = [
42
+ existing,
43
+ value
44
+ ];
45
+ elementIndex = Array.isArray(result[key]) ? result[key].length : 1;
69
46
  }
70
- result[key] = [
71
- existing,
72
- value
73
- ];
74
- }, fieldByCliName);
47
+ }
75
48
  return result;
76
49
  }
77
50
  function formatCliOptionName(name) {
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ import { unwrapZodField } from "../zod-schema-utils.mjs";
3
+ const cliNumberPattern = /^-?\d+(\.\d+)?$/;
4
+ function getFieldDef(field) {
5
+ return field._def;
6
+ }
7
+ function getFieldKind(field) {
8
+ return getFieldDef(field).typeName;
9
+ }
10
+ function parseJsonValue(raw) {
11
+ if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
12
+ try {
13
+ return JSON.parse(raw);
14
+ } catch {
15
+ return raw;
16
+ }
17
+ }
18
+ function parseValue(raw) {
19
+ const parsed = parseJsonValue(raw);
20
+ if (parsed !== raw) return parsed;
21
+ return cliNumberPattern.test(raw) ? Number(raw) : raw;
22
+ }
23
+ function getInputFields(field) {
24
+ const input = unwrapZodField(field);
25
+ const inputDef = getFieldDef(input);
26
+ if (inputDef.typeName === z.ZodFirstPartyTypeKind.ZodUnion) return (inputDef.options ?? []).flatMap(getInputFields);
27
+ return [
28
+ input
29
+ ];
30
+ }
31
+ function getRepeatedInputFields(fields, index) {
32
+ const collections = fields.filter((field)=>{
33
+ const kind = getFieldKind(field);
34
+ return kind === z.ZodFirstPartyTypeKind.ZodArray || kind === z.ZodFirstPartyTypeKind.ZodTuple;
35
+ });
36
+ if (0 === collections.length) return fields;
37
+ return collections.flatMap((field)=>{
38
+ const fieldDef = getFieldDef(field);
39
+ const item = fieldDef.typeName === z.ZodFirstPartyTypeKind.ZodArray ? fieldDef.type : fieldDef.items?.[index] ?? fieldDef.rest;
40
+ return item ? getInputFields(item) : [];
41
+ });
42
+ }
43
+ function acceptsValue(field, value) {
44
+ switch(getFieldKind(field)){
45
+ case z.ZodFirstPartyTypeKind.ZodString:
46
+ return 'string' == typeof value && field.safeParse(value).success;
47
+ case z.ZodFirstPartyTypeKind.ZodNumber:
48
+ return 'number' == typeof value && field.safeParse(value).success;
49
+ case z.ZodFirstPartyTypeKind.ZodBoolean:
50
+ return 'boolean' == typeof value;
51
+ case z.ZodFirstPartyTypeKind.ZodEnum:
52
+ case z.ZodFirstPartyTypeKind.ZodNativeEnum:
53
+ case z.ZodFirstPartyTypeKind.ZodLiteral:
54
+ return field.safeParse(value).success;
55
+ case z.ZodFirstPartyTypeKind.ZodArray:
56
+ case z.ZodFirstPartyTypeKind.ZodTuple:
57
+ return Array.isArray(value);
58
+ case z.ZodFirstPartyTypeKind.ZodObject:
59
+ case z.ZodFirstPartyTypeKind.ZodRecord:
60
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
61
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
62
+ default:
63
+ return;
64
+ }
65
+ }
66
+ function usesLegacyInference(field) {
67
+ const kind = getFieldKind(field);
68
+ return kind === z.ZodFirstPartyTypeKind.ZodAny || kind === z.ZodFirstPartyTypeKind.ZodUnknown;
69
+ }
70
+ function parseCliValue(raw, field, index) {
71
+ if (!field) return parseValue(raw);
72
+ const json = parseJsonValue(raw);
73
+ const wholeFields = getInputFields(field);
74
+ if (json !== raw && wholeFields.some((input)=>acceptsValue(input, json))) return json;
75
+ const fields = void 0 === index ? wholeFields : getRepeatedInputFields(wholeFields, index);
76
+ const candidates = json !== raw ? [
77
+ json,
78
+ raw
79
+ ] : [
80
+ raw
81
+ ];
82
+ if (cliNumberPattern.test(raw)) candidates.push(Number(raw));
83
+ if ('true' === raw || 'false' === raw) candidates.push('true' === raw);
84
+ for (const candidate of candidates)if (fields.some((input)=>acceptsValue(input, candidate))) return candidate;
85
+ return fields.some(usesLegacyInference) ? parseValue(raw) : raw;
86
+ }
87
+ export { parseCliValue, parseValue };
@@ -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.7-beta-20260911063016.0";
8
+ const getCurrentVersion = ()=>"1.12.7";
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,
@@ -8,60 +8,6 @@ function unwrapZodField(field) {
8
8
  }
9
9
  return f;
10
10
  }
11
- function getLiteralValueKind(value) {
12
- if ('string' == typeof value) return 'string';
13
- if ('number' == typeof value) return 'number';
14
- if ('boolean' == typeof value) return 'boolean';
15
- return 'unknown';
16
- }
17
- function getNativeEnumValueKinds(values) {
18
- const enumValues = Object.entries(values ?? {}).filter(([key])=>Number.isNaN(Number(key))).map(([, value])=>value);
19
- return new Set(enumValues.map(getLiteralValueKind));
20
- }
21
- function getZodValueKinds(field) {
22
- const actualField = unwrapZodField(field);
23
- const definition = actualField._def;
24
- switch(definition?.typeName){
25
- case 'ZodString':
26
- case 'ZodEnum':
27
- return new Set([
28
- 'string'
29
- ]);
30
- case 'ZodNumber':
31
- return new Set([
32
- 'number'
33
- ]);
34
- case 'ZodBoolean':
35
- return new Set([
36
- 'boolean'
37
- ]);
38
- case 'ZodArray':
39
- case 'ZodTuple':
40
- return new Set([
41
- 'array'
42
- ]);
43
- case 'ZodObject':
44
- case 'ZodRecord':
45
- case 'ZodDiscriminatedUnion':
46
- return new Set([
47
- 'object'
48
- ]);
49
- case 'ZodLiteral':
50
- return new Set([
51
- getLiteralValueKind(definition.value)
52
- ]);
53
- case 'ZodNativeEnum':
54
- return getNativeEnumValueKinds(definition.values);
55
- case 'ZodUnion':
56
- return new Set((definition.options ?? []).flatMap((option)=>[
57
- ...getZodValueKinds(option)
58
- ]));
59
- default:
60
- return new Set([
61
- 'unknown'
62
- ]);
63
- }
64
- }
65
11
  function isMidsceneLocatorField(field) {
66
12
  const actualField = unwrapZodField(field);
67
13
  if (actualField._def?.typeName === 'ZodObject') {
@@ -101,4 +47,4 @@ function getZodDescription(field) {
101
47
  if (isMidsceneLocatorField(actualField)) return 'Location information for the target element';
102
48
  return null;
103
49
  }
104
- export { getZodDescription, getZodTypeName, getZodValueKinds, isMidsceneLocatorField, unwrapZodField };
50
+ export { getZodDescription, getZodTypeName, isMidsceneLocatorField, unwrapZodField };
@@ -27,22 +27,14 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  canonicalizeCliArgKeys: ()=>canonicalizeCliArgKeys,
28
28
  parseCliArgs: ()=>parseCliArgs,
29
29
  formatCliValidationError: ()=>formatCliValidationError,
30
- parseValue: ()=>parseValue,
30
+ parseValue: ()=>external_cli_value_js_namespaceObject.parseValue,
31
31
  getCliOptionDisplay: ()=>getCliOptionDisplay
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");
36
35
  const external_cli_error_js_namespaceObject = require("./cli-error.js");
37
- const cliNumberPattern = /^-?\d+(\.\d+)?$/;
38
- function parseValue(raw) {
39
- if (raw.startsWith('{') || raw.startsWith('[')) try {
40
- return JSON.parse(raw);
41
- } catch {}
42
- if (cliNumberPattern.test(raw)) return Number(raw);
43
- return raw;
44
- }
45
- function walkCliArgs(args, setArgValue, fieldByCliName) {
36
+ const external_cli_value_js_namespaceObject = require("./cli-value.js");
37
+ function walkCliArgs(args, setArgValue) {
46
38
  for(let i = 0; i < args.length; i++){
47
39
  const arg = args[i];
48
40
  if (!arg.startsWith('--')) continue;
@@ -50,10 +42,10 @@ function walkCliArgs(args, setArgValue, fieldByCliName) {
50
42
  const eqIdx = body.indexOf('=');
51
43
  if (eqIdx >= 0) {
52
44
  const key = body.slice(0, eqIdx);
53
- setArgValue(key, parseCliValue(body.slice(eqIdx + 1), fieldByCliName?.get(key)));
45
+ setArgValue(key, body.slice(eqIdx + 1));
54
46
  } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
55
47
  i++;
56
- setArgValue(body, parseCliValue(args[i], fieldByCliName?.get(body)));
48
+ setArgValue(body, args[i]);
57
49
  } else setArgValue(body, true);
58
50
  }
59
51
  }
@@ -62,48 +54,29 @@ function buildCliFieldIndex(def) {
62
54
  for (const [schemaKey, field] of Object.entries(def.schema))for (const cliName of getAcceptedCliOptionNames(schemaKey, def.cli?.options?.[schemaKey]))fieldByCliName.set(cliName, field);
63
55
  return fieldByCliName;
64
56
  }
65
- function parseJsonValue(raw) {
66
- if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
67
- try {
68
- return JSON.parse(raw);
69
- } catch {
70
- return raw;
71
- }
72
- }
73
- function parseCliValue(raw, field) {
74
- if (!field) return parseValue(raw);
75
- const kinds = (0, external_zod_schema_utils_js_namespaceObject.getZodValueKinds)(field);
76
- if (kinds.has('object') || kinds.has('array')) {
77
- const parsedJson = parseJsonValue(raw);
78
- if (parsedJson !== raw) return parsedJson;
79
- }
80
- if (kinds.has('string')) return raw;
81
- if (kinds.has('number') && cliNumberPattern.test(raw)) return Number(raw);
82
- if (kinds.has('boolean')) {
83
- if ('true' === raw) return true;
84
- if ('false' === raw) return false;
85
- }
86
- return kinds.has('unknown') ? parseValue(raw) : raw;
87
- }
88
57
  function parseCliArgs(args, def) {
89
- const result = {};
90
58
  const fieldByCliName = def ? buildCliFieldIndex(def) : void 0;
91
- walkCliArgs(args, (key, value)=>{
92
- const existing = result[key];
93
- if (void 0 === existing) {
94
- result[key] = value;
95
- return;
96
- }
97
- if (Array.isArray(existing)) {
98
- existing.push(value);
99
- result[key] = existing;
100
- return;
59
+ const tokensByName = new Map();
60
+ walkCliArgs(args, (key, raw)=>{
61
+ const tokens = tokensByName.get(key) ?? [];
62
+ tokens.push(raw);
63
+ tokensByName.set(key, tokens);
64
+ });
65
+ const result = {};
66
+ for (const [key, tokens] of tokensByName){
67
+ let elementIndex = 0;
68
+ for (const raw of tokens){
69
+ const existing = result[key];
70
+ const value = true === raw ? true : (0, external_cli_value_js_namespaceObject.parseCliValue)(raw, fieldByCliName?.get(key), tokens.length > 1 ? elementIndex : void 0);
71
+ if (void 0 === existing) result[key] = value;
72
+ else if (Array.isArray(existing)) existing.push(value);
73
+ else result[key] = [
74
+ existing,
75
+ value
76
+ ];
77
+ elementIndex = Array.isArray(result[key]) ? result[key].length : 1;
101
78
  }
102
- result[key] = [
103
- existing,
104
- value
105
- ];
106
- }, fieldByCliName);
79
+ }
107
80
  return result;
108
81
  }
109
82
  function formatCliOptionName(name) {
@@ -0,0 +1,124 @@
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
+ parseValue: ()=>parseValue,
28
+ parseCliValue: ()=>parseCliValue
29
+ });
30
+ const external_zod_namespaceObject = require("zod");
31
+ const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
32
+ const cliNumberPattern = /^-?\d+(\.\d+)?$/;
33
+ function getFieldDef(field) {
34
+ return field._def;
35
+ }
36
+ function getFieldKind(field) {
37
+ return getFieldDef(field).typeName;
38
+ }
39
+ function parseJsonValue(raw) {
40
+ if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
41
+ try {
42
+ return JSON.parse(raw);
43
+ } catch {
44
+ return raw;
45
+ }
46
+ }
47
+ function parseValue(raw) {
48
+ const parsed = parseJsonValue(raw);
49
+ if (parsed !== raw) return parsed;
50
+ return cliNumberPattern.test(raw) ? Number(raw) : raw;
51
+ }
52
+ function getInputFields(field) {
53
+ const input = (0, external_zod_schema_utils_js_namespaceObject.unwrapZodField)(field);
54
+ const inputDef = getFieldDef(input);
55
+ if (inputDef.typeName === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodUnion) return (inputDef.options ?? []).flatMap(getInputFields);
56
+ return [
57
+ input
58
+ ];
59
+ }
60
+ function getRepeatedInputFields(fields, index) {
61
+ const collections = fields.filter((field)=>{
62
+ const kind = getFieldKind(field);
63
+ return kind === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodArray || kind === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodTuple;
64
+ });
65
+ if (0 === collections.length) return fields;
66
+ return collections.flatMap((field)=>{
67
+ const fieldDef = getFieldDef(field);
68
+ const item = fieldDef.typeName === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodArray ? fieldDef.type : fieldDef.items?.[index] ?? fieldDef.rest;
69
+ return item ? getInputFields(item) : [];
70
+ });
71
+ }
72
+ function acceptsValue(field, value) {
73
+ switch(getFieldKind(field)){
74
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodString:
75
+ return 'string' == typeof value && field.safeParse(value).success;
76
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodNumber:
77
+ return 'number' == typeof value && field.safeParse(value).success;
78
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodBoolean:
79
+ return 'boolean' == typeof value;
80
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodEnum:
81
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodNativeEnum:
82
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodLiteral:
83
+ return field.safeParse(value).success;
84
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodArray:
85
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodTuple:
86
+ return Array.isArray(value);
87
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodObject:
88
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodRecord:
89
+ case external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
90
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
91
+ default:
92
+ return;
93
+ }
94
+ }
95
+ function usesLegacyInference(field) {
96
+ const kind = getFieldKind(field);
97
+ return kind === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodAny || kind === external_zod_namespaceObject.z.ZodFirstPartyTypeKind.ZodUnknown;
98
+ }
99
+ function parseCliValue(raw, field, index) {
100
+ if (!field) return parseValue(raw);
101
+ const json = parseJsonValue(raw);
102
+ const wholeFields = getInputFields(field);
103
+ if (json !== raw && wholeFields.some((input)=>acceptsValue(input, json))) return json;
104
+ const fields = void 0 === index ? wholeFields : getRepeatedInputFields(wholeFields, index);
105
+ const candidates = json !== raw ? [
106
+ json,
107
+ raw
108
+ ] : [
109
+ raw
110
+ ];
111
+ if (cliNumberPattern.test(raw)) candidates.push(Number(raw));
112
+ if ('true' === raw || 'false' === raw) candidates.push('true' === raw);
113
+ for (const candidate of candidates)if (fields.some((input)=>acceptsValue(input, candidate))) return candidate;
114
+ return fields.some(usesLegacyInference) ? parseValue(raw) : raw;
115
+ }
116
+ exports.parseCliValue = __webpack_exports__.parseCliValue;
117
+ exports.parseValue = __webpack_exports__.parseValue;
118
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
119
+ "parseCliValue",
120
+ "parseValue"
121
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
122
+ Object.defineProperty(exports, '__esModule', {
123
+ value: true
124
+ });
@@ -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.7-beta-20260911063016.0";
40
+ const getCurrentVersion = ()=>"1.12.7";
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,
@@ -26,7 +26,6 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  getZodDescription: ()=>getZodDescription,
28
28
  getZodTypeName: ()=>getZodTypeName,
29
- getZodValueKinds: ()=>getZodValueKinds,
30
29
  isMidsceneLocatorField: ()=>isMidsceneLocatorField,
31
30
  unwrapZodField: ()=>unwrapZodField
32
31
  });
@@ -40,60 +39,6 @@ function unwrapZodField(field) {
40
39
  }
41
40
  return f;
42
41
  }
43
- function getLiteralValueKind(value) {
44
- if ('string' == typeof value) return 'string';
45
- if ('number' == typeof value) return 'number';
46
- if ('boolean' == typeof value) return 'boolean';
47
- return 'unknown';
48
- }
49
- function getNativeEnumValueKinds(values) {
50
- const enumValues = Object.entries(values ?? {}).filter(([key])=>Number.isNaN(Number(key))).map(([, value])=>value);
51
- return new Set(enumValues.map(getLiteralValueKind));
52
- }
53
- function getZodValueKinds(field) {
54
- const actualField = unwrapZodField(field);
55
- const definition = actualField._def;
56
- switch(definition?.typeName){
57
- case 'ZodString':
58
- case 'ZodEnum':
59
- return new Set([
60
- 'string'
61
- ]);
62
- case 'ZodNumber':
63
- return new Set([
64
- 'number'
65
- ]);
66
- case 'ZodBoolean':
67
- return new Set([
68
- 'boolean'
69
- ]);
70
- case 'ZodArray':
71
- case 'ZodTuple':
72
- return new Set([
73
- 'array'
74
- ]);
75
- case 'ZodObject':
76
- case 'ZodRecord':
77
- case 'ZodDiscriminatedUnion':
78
- return new Set([
79
- 'object'
80
- ]);
81
- case 'ZodLiteral':
82
- return new Set([
83
- getLiteralValueKind(definition.value)
84
- ]);
85
- case 'ZodNativeEnum':
86
- return getNativeEnumValueKinds(definition.values);
87
- case 'ZodUnion':
88
- return new Set((definition.options ?? []).flatMap((option)=>[
89
- ...getZodValueKinds(option)
90
- ]));
91
- default:
92
- return new Set([
93
- 'unknown'
94
- ]);
95
- }
96
- }
97
42
  function isMidsceneLocatorField(field) {
98
43
  const actualField = unwrapZodField(field);
99
44
  if (actualField._def?.typeName === 'ZodObject') {
@@ -135,13 +80,11 @@ function getZodDescription(field) {
135
80
  }
136
81
  exports.getZodDescription = __webpack_exports__.getZodDescription;
137
82
  exports.getZodTypeName = __webpack_exports__.getZodTypeName;
138
- exports.getZodValueKinds = __webpack_exports__.getZodValueKinds;
139
83
  exports.isMidsceneLocatorField = __webpack_exports__.isMidsceneLocatorField;
140
84
  exports.unwrapZodField = __webpack_exports__.unwrapZodField;
141
85
  for(var __rspack_i in __webpack_exports__)if (-1 === [
142
86
  "getZodDescription",
143
87
  "getZodTypeName",
144
- "getZodValueKinds",
145
88
  "isMidsceneLocatorField",
146
89
  "unwrapZodField"
147
90
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -1,5 +1,5 @@
1
1
  import type { ToolCliOption, ToolDefinition } from '../agent-tools/types';
2
- export declare function parseValue(raw: string): unknown;
2
+ export { parseValue } from './cli-value';
3
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;
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ export declare function parseValue(raw: string): unknown;
3
+ /** Decode one CLI token; index is supplied only for repeated options. */
4
+ export declare function parseCliValue(raw: string, field?: z.ZodTypeAny, index?: number): unknown;
@@ -1,16 +1,9 @@
1
1
  import type { z } from 'zod';
2
- export type ZodValueKind = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'unknown';
3
2
  /**
4
3
  * Recursively unwrap optional, nullable, default, and effects wrapper types
5
4
  * to get the actual inner Zod type
6
5
  */
7
6
  export declare function unwrapZodField(field: unknown): unknown;
8
- /**
9
- * Return every top-level value kind accepted by a Zod field. Unlike
10
- * `getZodTypeName`, this normalizes enums, literals, and unions so consumers
11
- * can make type-directed decisions without parsing its display label.
12
- */
13
- export declare function getZodValueKinds(field: unknown): Set<ZodValueKind>;
14
7
  /**
15
8
  * Check if a field is a Midscene locator field
16
9
  * Locator input schemas are identified by their prompt field.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.12.7-beta-20260911063016.0",
3
+ "version": "1.12.7",
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,31 +1,13 @@
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 { getZodValueKinds } from '../zod-schema-utils';
5
4
  import { CLIError } from './cli-error';
6
-
7
- const cliNumberPattern = /^-?\d+(\.\d+)?$/;
8
-
9
- export function parseValue(raw: string): unknown {
10
- if (raw.startsWith('{') || raw.startsWith('[')) {
11
- try {
12
- return JSON.parse(raw);
13
- } catch {
14
- // Not valid JSON, treat as string below
15
- }
16
- }
17
-
18
- if (cliNumberPattern.test(raw)) {
19
- return Number(raw);
20
- }
21
-
22
- return raw;
23
- }
5
+ import { parseCliValue } from './cli-value';
6
+ export { parseValue } from './cli-value';
24
7
 
25
8
  function walkCliArgs(
26
9
  args: string[],
27
- setArgValue: (key: string, value: unknown) => void,
28
- fieldByCliName?: ReadonlyMap<string, z.ZodTypeAny>,
10
+ setArgValue: (key: string, value: string | true) => void,
29
11
  ): void {
30
12
  for (let i = 0; i < args.length; i++) {
31
13
  const arg = args[i];
@@ -36,13 +18,10 @@ function walkCliArgs(
36
18
 
37
19
  if (eqIdx >= 0) {
38
20
  const key = body.slice(0, eqIdx);
39
- setArgValue(
40
- key,
41
- parseCliValue(body.slice(eqIdx + 1), fieldByCliName?.get(key)),
42
- );
21
+ setArgValue(key, body.slice(eqIdx + 1));
43
22
  } else if (args[i + 1] && !args[i + 1].startsWith('--')) {
44
23
  i++;
45
- setArgValue(body, parseCliValue(args[i], fieldByCliName?.get(body)));
24
+ setArgValue(body, args[i]);
46
25
  } else {
47
26
  setArgValue(body, true);
48
27
  }
@@ -66,67 +45,41 @@ function buildCliFieldIndex(
66
45
  return fieldByCliName;
67
46
  }
68
47
 
69
- function parseJsonValue(raw: string): unknown {
70
- if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
71
-
72
- try {
73
- return JSON.parse(raw);
74
- } catch {
75
- return raw;
76
- }
77
- }
78
-
79
- function parseCliValue(raw: string, field?: z.ZodTypeAny): unknown {
80
- if (!field) return parseValue(raw);
81
-
82
- const kinds = getZodValueKinds(field);
83
- if (kinds.has('object') || kinds.has('array')) {
84
- const parsedJson = parseJsonValue(raw);
85
- if (parsedJson !== raw) return parsedJson;
86
- }
87
-
88
- // CLI input cannot distinguish a numeric-looking identifier from a number.
89
- // Prefer the lossless representation whenever the schema accepts strings.
90
- if (kinds.has('string')) return raw;
91
-
92
- if (kinds.has('number') && cliNumberPattern.test(raw)) {
93
- return Number(raw);
94
- }
95
-
96
- if (kinds.has('boolean')) {
97
- if (raw === 'true') return true;
98
- if (raw === 'false') return false;
99
- }
100
-
101
- return kinds.has('unknown') ? parseValue(raw) : raw;
102
- }
103
-
104
48
  export function parseCliArgs(
105
49
  args: string[],
106
50
  def?: ToolDefinition,
107
51
  ): Record<string, unknown> {
108
- const result: Record<string, unknown> = {};
109
52
  const fieldByCliName = def ? buildCliFieldIndex(def) : undefined;
53
+ const tokensByName = new Map<string, Array<string | true>>();
54
+ walkCliArgs(args, (key, raw) => {
55
+ const tokens = tokensByName.get(key) ?? [];
56
+ tokens.push(raw);
57
+ tokensByName.set(key, tokens);
58
+ });
110
59
 
111
- walkCliArgs(
112
- args,
113
- (key, value) => {
60
+ const result: Record<string, unknown> = {};
61
+ for (const [key, tokens] of tokensByName) {
62
+ let elementIndex = 0;
63
+ for (const raw of tokens) {
114
64
  const existing = result[key];
65
+ const value =
66
+ raw === true
67
+ ? true
68
+ : parseCliValue(
69
+ raw,
70
+ fieldByCliName?.get(key),
71
+ tokens.length > 1 ? elementIndex : undefined,
72
+ );
115
73
  if (existing === undefined) {
116
74
  result[key] = value;
117
- return;
118
- }
119
-
120
- if (Array.isArray(existing)) {
75
+ } else if (Array.isArray(existing)) {
121
76
  existing.push(value);
122
- result[key] = existing;
123
- return;
77
+ } else {
78
+ result[key] = [existing, value];
124
79
  }
125
-
126
- result[key] = [existing, value];
127
- },
128
- fieldByCliName,
129
- );
80
+ elementIndex = Array.isArray(result[key]) ? result[key].length : 1;
81
+ }
82
+ }
130
83
 
131
84
  return result;
132
85
  }
@@ -0,0 +1,137 @@
1
+ import { z } from 'zod';
2
+ import { unwrapZodField } from '../zod-schema-utils';
3
+
4
+ const cliNumberPattern = /^-?\d+(\.\d+)?$/;
5
+
6
+ interface CliZodDef {
7
+ typeName?: z.ZodFirstPartyTypeKind;
8
+ options?: z.ZodTypeAny[];
9
+ type?: z.ZodTypeAny;
10
+ items?: z.ZodTypeAny[];
11
+ rest?: z.ZodTypeAny | null;
12
+ }
13
+
14
+ function getFieldDef(field: z.ZodTypeAny): CliZodDef {
15
+ return (field as z.ZodTypeAny & { _def: CliZodDef })._def;
16
+ }
17
+
18
+ function getFieldKind(
19
+ field: z.ZodTypeAny,
20
+ ): z.ZodFirstPartyTypeKind | undefined {
21
+ return getFieldDef(field).typeName;
22
+ }
23
+
24
+ function parseJsonValue(raw: string): unknown {
25
+ if (!raw.startsWith('{') && !raw.startsWith('[')) return raw;
26
+ try {
27
+ return JSON.parse(raw);
28
+ } catch {
29
+ // Preserve text for string inputs or the later schema validation error.
30
+ return raw;
31
+ }
32
+ }
33
+
34
+ export function parseValue(raw: string): unknown {
35
+ const parsed = parseJsonValue(raw);
36
+ if (parsed !== raw) return parsed;
37
+ return cliNumberPattern.test(raw) ? Number(raw) : raw;
38
+ }
39
+
40
+ // Keep the actual alternatives: a string literal is not an arbitrary string,
41
+ // and a repeated tuple argument must retain its position-specific schema.
42
+ function getInputFields(field: z.ZodTypeAny): z.ZodTypeAny[] {
43
+ const input = unwrapZodField(field) as z.ZodTypeAny;
44
+ const inputDef = getFieldDef(input);
45
+ if (inputDef.typeName === z.ZodFirstPartyTypeKind.ZodUnion) {
46
+ return (inputDef.options ?? []).flatMap(getInputFields);
47
+ }
48
+ return [input];
49
+ }
50
+
51
+ function getRepeatedInputFields(
52
+ fields: z.ZodTypeAny[],
53
+ index: number,
54
+ ): z.ZodTypeAny[] {
55
+ const collections = fields.filter((field) => {
56
+ const kind = getFieldKind(field);
57
+ return (
58
+ kind === z.ZodFirstPartyTypeKind.ZodArray ||
59
+ kind === z.ZodFirstPartyTypeKind.ZodTuple
60
+ );
61
+ });
62
+ if (collections.length === 0) return fields;
63
+ return collections.flatMap((field) => {
64
+ const fieldDef = getFieldDef(field);
65
+ const item =
66
+ fieldDef.typeName === z.ZodFirstPartyTypeKind.ZodArray
67
+ ? fieldDef.type
68
+ : (fieldDef.items?.[index] ?? fieldDef.rest);
69
+ return item ? getInputFields(item) : [];
70
+ });
71
+ }
72
+
73
+ // Only inspect scalar constraints here. Effects have been unwrapped, and
74
+ // collection children are left to the existing full validation step.
75
+ function acceptsValue(
76
+ field: z.ZodTypeAny,
77
+ value: unknown,
78
+ ): boolean | undefined {
79
+ switch (getFieldKind(field)) {
80
+ case z.ZodFirstPartyTypeKind.ZodString:
81
+ return typeof value === 'string' && field.safeParse(value).success;
82
+ case z.ZodFirstPartyTypeKind.ZodNumber:
83
+ return typeof value === 'number' && field.safeParse(value).success;
84
+ case z.ZodFirstPartyTypeKind.ZodBoolean:
85
+ return typeof value === 'boolean';
86
+ case z.ZodFirstPartyTypeKind.ZodEnum:
87
+ case z.ZodFirstPartyTypeKind.ZodNativeEnum:
88
+ case z.ZodFirstPartyTypeKind.ZodLiteral:
89
+ return field.safeParse(value).success;
90
+ case z.ZodFirstPartyTypeKind.ZodArray:
91
+ case z.ZodFirstPartyTypeKind.ZodTuple:
92
+ return Array.isArray(value);
93
+ case z.ZodFirstPartyTypeKind.ZodObject:
94
+ case z.ZodFirstPartyTypeKind.ZodRecord:
95
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
96
+ return (
97
+ typeof value === 'object' && value !== null && !Array.isArray(value)
98
+ );
99
+ default:
100
+ return undefined;
101
+ }
102
+ }
103
+
104
+ function usesLegacyInference(field: z.ZodTypeAny): boolean {
105
+ const kind = getFieldKind(field);
106
+ return (
107
+ kind === z.ZodFirstPartyTypeKind.ZodAny ||
108
+ kind === z.ZodFirstPartyTypeKind.ZodUnknown
109
+ );
110
+ }
111
+
112
+ /** Decode one CLI token; index is supplied only for repeated options. */
113
+ export function parseCliValue(
114
+ raw: string,
115
+ field?: z.ZodTypeAny,
116
+ index?: number,
117
+ ): unknown {
118
+ if (!field) return parseValue(raw);
119
+ const json = parseJsonValue(raw);
120
+ const wholeFields = getInputFields(field);
121
+ if (json !== raw && wholeFields.some((input) => acceptsValue(input, json))) {
122
+ return json;
123
+ }
124
+
125
+ const fields =
126
+ index === undefined
127
+ ? wholeFields
128
+ : getRepeatedInputFields(wholeFields, index);
129
+ const candidates: unknown[] = json !== raw ? [json, raw] : [raw];
130
+ if (cliNumberPattern.test(raw)) candidates.push(Number(raw));
131
+ if (raw === 'true' || raw === 'false') candidates.push(raw === 'true');
132
+ for (const candidate of candidates) {
133
+ if (fields.some((input) => acceptsValue(input, candidate)))
134
+ return candidate;
135
+ }
136
+ return fields.some(usesLegacyInference) ? parseValue(raw) : raw;
137
+ }
@@ -1,13 +1,5 @@
1
1
  import type { z } from 'zod';
2
2
 
3
- export type ZodValueKind =
4
- | 'string'
5
- | 'number'
6
- | 'boolean'
7
- | 'array'
8
- | 'object'
9
- | 'unknown';
10
-
11
3
  /**
12
4
  * Recursively unwrap optional, nullable, default, and effects wrapper types
13
5
  * to get the actual inner Zod type
@@ -39,68 +31,6 @@ export function unwrapZodField(field: unknown): unknown {
39
31
  return f;
40
32
  }
41
33
 
42
- function getLiteralValueKind(value: unknown): ZodValueKind {
43
- if (typeof value === 'string') return 'string';
44
- if (typeof value === 'number') return 'number';
45
- if (typeof value === 'boolean') return 'boolean';
46
- return 'unknown';
47
- }
48
-
49
- function getNativeEnumValueKinds(
50
- values: Record<string, unknown> | undefined,
51
- ): Set<ZodValueKind> {
52
- const enumValues = Object.entries(values ?? {})
53
- .filter(([key]) => Number.isNaN(Number(key)))
54
- .map(([, value]) => value);
55
- return new Set(enumValues.map(getLiteralValueKind));
56
- }
57
-
58
- /**
59
- * Return every top-level value kind accepted by a Zod field. Unlike
60
- * `getZodTypeName`, this normalizes enums, literals, and unions so consumers
61
- * can make type-directed decisions without parsing its display label.
62
- */
63
- export function getZodValueKinds(field: unknown): Set<ZodValueKind> {
64
- const actualField = unwrapZodField(field) as {
65
- _def?: {
66
- typeName?: string;
67
- options?: unknown[];
68
- value?: unknown;
69
- values?: Record<string, unknown>;
70
- };
71
- };
72
- const definition = actualField._def;
73
-
74
- switch (definition?.typeName) {
75
- case 'ZodString':
76
- case 'ZodEnum':
77
- return new Set(['string']);
78
- case 'ZodNumber':
79
- return new Set(['number']);
80
- case 'ZodBoolean':
81
- return new Set(['boolean']);
82
- case 'ZodArray':
83
- case 'ZodTuple':
84
- return new Set(['array']);
85
- case 'ZodObject':
86
- case 'ZodRecord':
87
- case 'ZodDiscriminatedUnion':
88
- return new Set(['object']);
89
- case 'ZodLiteral':
90
- return new Set([getLiteralValueKind(definition.value)]);
91
- case 'ZodNativeEnum':
92
- return getNativeEnumValueKinds(definition.values);
93
- case 'ZodUnion':
94
- return new Set(
95
- (definition.options ?? []).flatMap((option) => [
96
- ...getZodValueKinds(option),
97
- ]),
98
- );
99
- default:
100
- return new Set(['unknown']);
101
- }
102
- }
103
-
104
34
  /**
105
35
  * Check if a field is a Midscene locator field
106
36
  * Locator input schemas are identified by their prompt field.