@aiscene/shared 1.6.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.
Files changed (212) hide show
  1. package/README.md +9 -0
  2. package/dist/es/baseDB.mjs +109 -0
  3. package/dist/es/build/copy-static.mjs +31 -0
  4. package/dist/es/build/rspack-config.mjs +4 -0
  5. package/dist/es/cli/cli-runner.mjs +140 -0
  6. package/dist/es/cli/index.mjs +2 -0
  7. package/dist/es/common.mjs +37 -0
  8. package/dist/es/constants/example-code.mjs +223 -0
  9. package/dist/es/constants/index.mjs +23 -0
  10. package/dist/es/env/basic.mjs +6 -0
  11. package/dist/es/env/constants.mjs +70 -0
  12. package/dist/es/env/global-config-manager.mjs +94 -0
  13. package/dist/es/env/helper.mjs +43 -0
  14. package/dist/es/env/index.mjs +5 -0
  15. package/dist/es/env/init-debug.mjs +18 -0
  16. package/dist/es/env/model-config-manager.mjs +79 -0
  17. package/dist/es/env/parse-model-config.mjs +132 -0
  18. package/dist/es/env/types.mjs +211 -0
  19. package/dist/es/env/utils.mjs +26 -0
  20. package/dist/es/extractor/constants.mjs +2 -0
  21. package/dist/es/extractor/debug.mjs +6 -0
  22. package/dist/es/extractor/dom-util.mjs +92 -0
  23. package/dist/es/extractor/index.mjs +5 -0
  24. package/dist/es/extractor/locator.mjs +250 -0
  25. package/dist/es/extractor/tree.mjs +78 -0
  26. package/dist/es/extractor/util.mjs +245 -0
  27. package/dist/es/extractor/web-extractor.mjs +303 -0
  28. package/dist/es/img/box-select.mjs +824 -0
  29. package/dist/es/img/canvas-fallback.mjs +238 -0
  30. package/dist/es/img/get-photon.mjs +45 -0
  31. package/dist/es/img/get-sharp.mjs +11 -0
  32. package/dist/es/img/index.mjs +4 -0
  33. package/dist/es/img/info.mjs +29 -0
  34. package/dist/es/img/transform.mjs +275 -0
  35. package/dist/es/index.mjs +4 -0
  36. package/dist/es/logger.mjs +70 -0
  37. package/dist/es/mcp/base-server.mjs +281 -0
  38. package/dist/es/mcp/base-tools.mjs +91 -0
  39. package/dist/es/mcp/chrome-path.mjs +35 -0
  40. package/dist/es/mcp/index.mjs +7 -0
  41. package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
  42. package/dist/es/mcp/launcher-helper.mjs +52 -0
  43. package/dist/es/mcp/tool-generator.mjs +297 -0
  44. package/dist/es/mcp/types.mjs +3 -0
  45. package/dist/es/node/fs.mjs +44 -0
  46. package/dist/es/node/index.mjs +2 -0
  47. package/dist/es/node/port.mjs +24 -0
  48. package/dist/es/polyfills/async-hooks.mjs +2 -0
  49. package/dist/es/polyfills/index.mjs +1 -0
  50. package/dist/es/types/index.mjs +3 -0
  51. package/dist/es/us-keyboard-layout.mjs +1414 -0
  52. package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
  53. package/dist/es/utils.mjs +77 -0
  54. package/dist/es/zod-schema-utils.mjs +54 -0
  55. package/dist/lib/baseDB.js +149 -0
  56. package/dist/lib/build/copy-static.js +79 -0
  57. package/dist/lib/build/rspack-config.js +38 -0
  58. package/dist/lib/cli/cli-runner.js +196 -0
  59. package/dist/lib/cli/index.js +48 -0
  60. package/dist/lib/common.js +93 -0
  61. package/dist/lib/constants/example-code.js +260 -0
  62. package/dist/lib/constants/index.js +96 -0
  63. package/dist/lib/env/basic.js +40 -0
  64. package/dist/lib/env/constants.js +113 -0
  65. package/dist/lib/env/global-config-manager.js +128 -0
  66. package/dist/lib/env/helper.js +80 -0
  67. package/dist/lib/env/index.js +90 -0
  68. package/dist/lib/env/init-debug.js +52 -0
  69. package/dist/lib/env/model-config-manager.js +113 -0
  70. package/dist/lib/env/parse-model-config.js +178 -0
  71. package/dist/lib/env/types.js +518 -0
  72. package/dist/lib/env/utils.js +72 -0
  73. package/dist/lib/extractor/constants.js +42 -0
  74. package/dist/lib/extractor/debug.js +12 -0
  75. package/dist/lib/extractor/dom-util.js +153 -0
  76. package/dist/lib/extractor/index.js +81 -0
  77. package/dist/lib/extractor/locator.js +296 -0
  78. package/dist/lib/extractor/tree.js +124 -0
  79. package/dist/lib/extractor/util.js +336 -0
  80. package/dist/lib/extractor/web-extractor.js +349 -0
  81. package/dist/lib/img/box-select.js +875 -0
  82. package/dist/lib/img/canvas-fallback.js +305 -0
  83. package/dist/lib/img/get-photon.js +82 -0
  84. package/dist/lib/img/get-sharp.js +45 -0
  85. package/dist/lib/img/index.js +92 -0
  86. package/dist/lib/img/info.js +83 -0
  87. package/dist/lib/img/transform.js +364 -0
  88. package/dist/lib/index.js +47 -0
  89. package/dist/lib/logger.js +123 -0
  90. package/dist/lib/mcp/base-server.js +331 -0
  91. package/dist/lib/mcp/base-tools.js +125 -0
  92. package/dist/lib/mcp/chrome-path.js +72 -0
  93. package/dist/lib/mcp/index.js +100 -0
  94. package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
  95. package/dist/lib/mcp/launcher-helper.js +86 -0
  96. package/dist/lib/mcp/tool-generator.js +334 -0
  97. package/dist/lib/mcp/types.js +40 -0
  98. package/dist/lib/node/fs.js +97 -0
  99. package/dist/lib/node/index.js +65 -0
  100. package/dist/lib/node/port.js +61 -0
  101. package/dist/lib/polyfills/async-hooks.js +36 -0
  102. package/dist/lib/polyfills/index.js +58 -0
  103. package/dist/lib/types/index.js +37 -0
  104. package/dist/lib/us-keyboard-layout.js +1457 -0
  105. package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
  106. package/dist/lib/utils.js +156 -0
  107. package/dist/lib/zod-schema-utils.js +97 -0
  108. package/dist/types/baseDB.d.ts +25 -0
  109. package/dist/types/build/copy-static.d.ts +31 -0
  110. package/dist/types/build/rspack-config.d.ts +8 -0
  111. package/dist/types/cli/cli-runner.d.ts +14 -0
  112. package/dist/types/cli/index.d.ts +2 -0
  113. package/dist/types/common.d.ts +12 -0
  114. package/dist/types/constants/example-code.d.ts +2 -0
  115. package/dist/types/constants/index.d.ts +21 -0
  116. package/dist/types/env/basic.d.ts +6 -0
  117. package/dist/types/env/constants.d.ts +40 -0
  118. package/dist/types/env/global-config-manager.d.ts +32 -0
  119. package/dist/types/env/helper.d.ts +4 -0
  120. package/dist/types/env/index.d.ts +4 -0
  121. package/dist/types/env/init-debug.d.ts +1 -0
  122. package/dist/types/env/model-config-manager.d.ts +25 -0
  123. package/dist/types/env/parse-model-config.d.ts +31 -0
  124. package/dist/types/env/types.d.ts +309 -0
  125. package/dist/types/env/utils.d.ts +38 -0
  126. package/dist/types/extractor/constants.d.ts +1 -0
  127. package/dist/types/extractor/debug.d.ts +1 -0
  128. package/dist/types/extractor/dom-util.d.ts +56 -0
  129. package/dist/types/extractor/index.d.ts +32 -0
  130. package/dist/types/extractor/locator.d.ts +9 -0
  131. package/dist/types/extractor/tree.d.ts +6 -0
  132. package/dist/types/extractor/util.d.ts +47 -0
  133. package/dist/types/extractor/web-extractor.d.ts +19 -0
  134. package/dist/types/img/box-select.d.ts +26 -0
  135. package/dist/types/img/canvas-fallback.d.ts +105 -0
  136. package/dist/types/img/get-photon.d.ts +19 -0
  137. package/dist/types/img/get-sharp.d.ts +3 -0
  138. package/dist/types/img/index.d.ts +3 -0
  139. package/dist/types/img/info.d.ts +29 -0
  140. package/dist/types/img/transform.d.ts +98 -0
  141. package/dist/types/index.d.ts +4 -0
  142. package/dist/types/logger.d.ts +6 -0
  143. package/dist/types/mcp/base-server.d.ts +93 -0
  144. package/dist/types/mcp/base-tools.d.ts +79 -0
  145. package/dist/types/mcp/chrome-path.d.ts +2 -0
  146. package/dist/types/mcp/index.d.ts +7 -0
  147. package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
  148. package/dist/types/mcp/launcher-helper.d.ts +94 -0
  149. package/dist/types/mcp/tool-generator.d.ts +10 -0
  150. package/dist/types/mcp/types.d.ts +103 -0
  151. package/dist/types/node/fs.d.ts +15 -0
  152. package/dist/types/node/index.d.ts +2 -0
  153. package/dist/types/node/port.d.ts +8 -0
  154. package/dist/types/polyfills/async-hooks.d.ts +6 -0
  155. package/dist/types/polyfills/index.d.ts +4 -0
  156. package/dist/types/types/index.d.ts +34 -0
  157. package/dist/types/us-keyboard-layout.d.ts +32 -0
  158. package/dist/types/utils.d.ts +37 -0
  159. package/dist/types/zod-schema-utils.d.ts +23 -0
  160. package/package.json +121 -0
  161. package/src/baseDB.ts +158 -0
  162. package/src/build/copy-static.ts +68 -0
  163. package/src/build/rspack-config.ts +12 -0
  164. package/src/cli/cli-runner.ts +224 -0
  165. package/src/cli/index.ts +8 -0
  166. package/src/common.ts +67 -0
  167. package/src/constants/example-code.ts +223 -0
  168. package/src/constants/index.ts +29 -0
  169. package/src/env/basic.ts +12 -0
  170. package/src/env/constants.ts +234 -0
  171. package/src/env/global-config-manager.ts +191 -0
  172. package/src/env/helper.ts +58 -0
  173. package/src/env/index.ts +4 -0
  174. package/src/env/init-debug.ts +34 -0
  175. package/src/env/model-config-manager.ts +149 -0
  176. package/src/env/parse-model-config.ts +294 -0
  177. package/src/env/types.ts +533 -0
  178. package/src/env/utils.ts +89 -0
  179. package/src/extractor/constants.ts +5 -0
  180. package/src/extractor/debug.ts +10 -0
  181. package/src/extractor/dom-util.ts +226 -0
  182. package/src/extractor/index.ts +48 -0
  183. package/src/extractor/locator.ts +469 -0
  184. package/src/extractor/tree.ts +179 -0
  185. package/src/extractor/util.ts +482 -0
  186. package/src/extractor/web-extractor.ts +481 -0
  187. package/src/img/box-select.ts +588 -0
  188. package/src/img/canvas-fallback.ts +393 -0
  189. package/src/img/get-photon.ts +108 -0
  190. package/src/img/get-sharp.ts +18 -0
  191. package/src/img/index.ts +25 -0
  192. package/src/img/info.ts +75 -0
  193. package/src/img/transform.ts +553 -0
  194. package/src/index.ts +8 -0
  195. package/src/logger.ts +107 -0
  196. package/src/mcp/base-server.ts +502 -0
  197. package/src/mcp/base-tools.ts +185 -0
  198. package/src/mcp/chrome-path.ts +48 -0
  199. package/src/mcp/index.ts +7 -0
  200. package/src/mcp/inject-report-html-plugin.ts +119 -0
  201. package/src/mcp/launcher-helper.ts +200 -0
  202. package/src/mcp/tool-generator.ts +429 -0
  203. package/src/mcp/types.ts +112 -0
  204. package/src/node/fs.ts +84 -0
  205. package/src/node/index.ts +2 -0
  206. package/src/node/port.ts +37 -0
  207. package/src/polyfills/async-hooks.ts +6 -0
  208. package/src/polyfills/index.ts +4 -0
  209. package/src/types/index.ts +52 -0
  210. package/src/us-keyboard-layout.ts +723 -0
  211. package/src/utils.ts +166 -0
  212. package/src/zod-schema-utils.ts +133 -0
@@ -0,0 +1,533 @@
1
+ // config keys
2
+ export const MIDSCENE_MODEL_INIT_CONFIG_JSON =
3
+ 'MIDSCENE_MODEL_INIT_CONFIG_JSON';
4
+ export const MIDSCENE_MODEL_EXTRA_BODY_JSON = 'MIDSCENE_MODEL_EXTRA_BODY_JSON';
5
+ export const MIDSCENE_MODEL_NAME = 'MIDSCENE_MODEL_NAME';
6
+ export const MIDSCENE_DEBUG_MODEL_PROFILE = 'MIDSCENE_DEBUG_MODEL_PROFILE';
7
+ export const MIDSCENE_DEBUG_MODEL_RESPONSE = 'MIDSCENE_DEBUG_MODEL_RESPONSE';
8
+ export const MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG =
9
+ 'MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG';
10
+ export const MIDSCENE_DEBUG_MODE = 'MIDSCENE_DEBUG_MODE';
11
+ export const MIDSCENE_MCP_USE_PUPPETEER_MODE =
12
+ 'MIDSCENE_MCP_USE_PUPPETEER_MODE';
13
+ export const MIDSCENE_MCP_CHROME_PATH = 'MIDSCENE_MCP_CHROME_PATH';
14
+ export const MIDSCENE_MCP_ANDROID_MODE = 'MIDSCENE_MCP_ANDROID_MODE';
15
+ export const DOCKER_CONTAINER = 'DOCKER_CONTAINER';
16
+
17
+ // Observability
18
+ export const MIDSCENE_LANGSMITH_DEBUG = 'MIDSCENE_LANGSMITH_DEBUG';
19
+ export const MIDSCENE_LANGFUSE_DEBUG = 'MIDSCENE_LANGFUSE_DEBUG';
20
+
21
+ export const MIDSCENE_MODEL_SOCKS_PROXY = 'MIDSCENE_MODEL_SOCKS_PROXY';
22
+ export const MIDSCENE_MODEL_HTTP_PROXY = 'MIDSCENE_MODEL_HTTP_PROXY';
23
+
24
+ // New primary names for public API
25
+ export const MIDSCENE_MODEL_API_KEY = 'MIDSCENE_MODEL_API_KEY';
26
+ export const MIDSCENE_MODEL_BASE_URL = 'MIDSCENE_MODEL_BASE_URL';
27
+ export const MIDSCENE_MODEL_MAX_TOKENS = 'MIDSCENE_MODEL_MAX_TOKENS';
28
+ export const MIDSCENE_MODEL_TIMEOUT = 'MIDSCENE_MODEL_TIMEOUT';
29
+ export const MIDSCENE_MODEL_TEMPERATURE = 'MIDSCENE_MODEL_TEMPERATURE';
30
+ export const MIDSCENE_MODEL_RETRY_COUNT = 'MIDSCENE_MODEL_RETRY_COUNT';
31
+ export const MIDSCENE_MODEL_RETRY_INTERVAL = 'MIDSCENE_MODEL_RETRY_INTERVAL';
32
+ export const MIDSCENE_MODEL_REASONING_EFFORT =
33
+ 'MIDSCENE_MODEL_REASONING_EFFORT';
34
+ export const MIDSCENE_MODEL_REASONING_ENABLED =
35
+ 'MIDSCENE_MODEL_REASONING_ENABLED';
36
+ export const MIDSCENE_MODEL_REASONING_BUDGET =
37
+ 'MIDSCENE_MODEL_REASONING_BUDGET';
38
+
39
+ /**
40
+ * @deprecated Use MIDSCENE_MODEL_API_KEY instead. This is kept for backward compatibility.
41
+ */
42
+ export const OPENAI_API_KEY = 'OPENAI_API_KEY';
43
+ /**
44
+ * @deprecated Use MIDSCENE_MODEL_BASE_URL instead. This is kept for backward compatibility.
45
+ */
46
+ export const OPENAI_BASE_URL = 'OPENAI_BASE_URL';
47
+ /**
48
+ * @deprecated Use MIDSCENE_MODEL_INIT_CONFIG_JSON instead. This is kept for backward compatibility.
49
+ */
50
+ export const MIDSCENE_OPENAI_INIT_CONFIG_JSON =
51
+ 'MIDSCENE_OPENAI_INIT_CONFIG_JSON';
52
+ /**
53
+ * @deprecated Use MIDSCENE_MODEL_HTTP_PROXY instead. This is kept for backward compatibility.
54
+ */
55
+ export const MIDSCENE_OPENAI_HTTP_PROXY = 'MIDSCENE_OPENAI_HTTP_PROXY';
56
+ /**
57
+ * @deprecated Use MIDSCENE_MODEL_SOCKS_PROXY instead. This is kept for backward compatibility.
58
+ */
59
+ export const MIDSCENE_OPENAI_SOCKS_PROXY = 'MIDSCENE_OPENAI_SOCKS_PROXY';
60
+ /**
61
+ * @deprecated Use MIDSCENE_MODEL_MAX_TOKENS instead. This is kept for backward compatibility.
62
+ */
63
+ export const OPENAI_MAX_TOKENS = 'OPENAI_MAX_TOKENS';
64
+
65
+ export const MIDSCENE_ADB_PATH = 'MIDSCENE_ADB_PATH';
66
+ export const MIDSCENE_ADB_REMOTE_HOST = 'MIDSCENE_ADB_REMOTE_HOST';
67
+ export const MIDSCENE_ADB_REMOTE_PORT = 'MIDSCENE_ADB_REMOTE_PORT';
68
+ export const MIDSCENE_ANDROID_IME_STRATEGY = 'MIDSCENE_ANDROID_IME_STRATEGY';
69
+
70
+ export const MIDSCENE_IOS_DEVICE_UDID = 'MIDSCENE_IOS_DEVICE_UDID';
71
+ export const MIDSCENE_IOS_SIMULATOR_UDID = 'MIDSCENE_IOS_SIMULATOR_UDID';
72
+
73
+ export const MIDSCENE_CACHE = 'MIDSCENE_CACHE';
74
+ export const MIDSCENE_USE_VLM_UI_TARS = 'MIDSCENE_USE_VLM_UI_TARS';
75
+ export const MIDSCENE_USE_QWEN_VL = 'MIDSCENE_USE_QWEN_VL';
76
+ export const MIDSCENE_USE_QWEN3_VL = 'MIDSCENE_USE_QWEN3_VL';
77
+ export const MIDSCENE_USE_DOUBAO_VISION = 'MIDSCENE_USE_DOUBAO_VISION';
78
+ export const MIDSCENE_USE_GEMINI = 'MIDSCENE_USE_GEMINI';
79
+ export const MIDSCENE_USE_VL_MODEL = 'MIDSCENE_USE_VL_MODEL';
80
+ export const MATCH_BY_POSITION = 'MATCH_BY_POSITION';
81
+ export const MIDSCENE_REPORT_TAG_NAME = 'MIDSCENE_REPORT_TAG_NAME';
82
+ export const MIDSCENE_REPORT_QUIET = 'MIDSCENE_REPORT_QUIET';
83
+
84
+ export const MIDSCENE_PREFERRED_LANGUAGE = 'MIDSCENE_PREFERRED_LANGUAGE';
85
+
86
+ export const MIDSCENE_CACHE_MAX_FILENAME_LENGTH =
87
+ 'MIDSCENE_CACHE_MAX_FILENAME_LENGTH';
88
+
89
+ export const MIDSCENE_REPLANNING_CYCLE_LIMIT =
90
+ 'MIDSCENE_REPLANNING_CYCLE_LIMIT';
91
+
92
+ export const MIDSCENE_RUN_DIR = 'MIDSCENE_RUN_DIR';
93
+
94
+ // INSIGHT (unified VQA and Grounding)
95
+ export const MIDSCENE_INSIGHT_MODEL_NAME = 'MIDSCENE_INSIGHT_MODEL_NAME';
96
+ export const MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY =
97
+ 'MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY';
98
+ export const MIDSCENE_INSIGHT_MODEL_HTTP_PROXY =
99
+ 'MIDSCENE_INSIGHT_MODEL_HTTP_PROXY';
100
+ export const MIDSCENE_INSIGHT_MODEL_BASE_URL =
101
+ 'MIDSCENE_INSIGHT_MODEL_BASE_URL';
102
+ export const MIDSCENE_INSIGHT_MODEL_API_KEY = 'MIDSCENE_INSIGHT_MODEL_API_KEY';
103
+ export const MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON =
104
+ 'MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON';
105
+ export const MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON =
106
+ 'MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON';
107
+ export const MIDSCENE_INSIGHT_MODEL_TIMEOUT = 'MIDSCENE_INSIGHT_MODEL_TIMEOUT';
108
+ export const MIDSCENE_INSIGHT_MODEL_TEMPERATURE =
109
+ 'MIDSCENE_INSIGHT_MODEL_TEMPERATURE';
110
+ export const MIDSCENE_INSIGHT_MODEL_RETRY_COUNT =
111
+ 'MIDSCENE_INSIGHT_MODEL_RETRY_COUNT';
112
+ export const MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL =
113
+ 'MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL';
114
+ export const MIDSCENE_INSIGHT_MODEL_FAMILY = 'MIDSCENE_INSIGHT_MODEL_FAMILY';
115
+ export const MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT =
116
+ 'MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT';
117
+ export const MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED =
118
+ 'MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED';
119
+ export const MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET =
120
+ 'MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET';
121
+
122
+ // PLANNING
123
+ export const MIDSCENE_PLANNING_MODEL_NAME = 'MIDSCENE_PLANNING_MODEL_NAME';
124
+ export const MIDSCENE_PLANNING_MODEL_SOCKS_PROXY =
125
+ 'MIDSCENE_PLANNING_MODEL_SOCKS_PROXY';
126
+ export const MIDSCENE_PLANNING_MODEL_HTTP_PROXY =
127
+ 'MIDSCENE_PLANNING_MODEL_HTTP_PROXY';
128
+ export const MIDSCENE_PLANNING_MODEL_BASE_URL =
129
+ 'MIDSCENE_PLANNING_MODEL_BASE_URL';
130
+ export const MIDSCENE_PLANNING_MODEL_API_KEY =
131
+ 'MIDSCENE_PLANNING_MODEL_API_KEY';
132
+ export const MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON =
133
+ 'MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON';
134
+ export const MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON =
135
+ 'MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON';
136
+ export const MIDSCENE_PLANNING_MODEL_TIMEOUT =
137
+ 'MIDSCENE_PLANNING_MODEL_TIMEOUT';
138
+ export const MIDSCENE_PLANNING_MODEL_TEMPERATURE =
139
+ 'MIDSCENE_PLANNING_MODEL_TEMPERATURE';
140
+ export const MIDSCENE_PLANNING_MODEL_RETRY_COUNT =
141
+ 'MIDSCENE_PLANNING_MODEL_RETRY_COUNT';
142
+ export const MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL =
143
+ 'MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL';
144
+ export const MIDSCENE_PLANNING_MODEL_FAMILY = 'MIDSCENE_PLANNING_MODEL_FAMILY';
145
+ export const MIDSCENE_PLANNING_MODEL_REASONING_EFFORT =
146
+ 'MIDSCENE_PLANNING_MODEL_REASONING_EFFORT';
147
+ export const MIDSCENE_PLANNING_MODEL_REASONING_ENABLED =
148
+ 'MIDSCENE_PLANNING_MODEL_REASONING_ENABLED';
149
+ export const MIDSCENE_PLANNING_MODEL_REASONING_BUDGET =
150
+ 'MIDSCENE_PLANNING_MODEL_REASONING_BUDGET';
151
+ export const MIDSCENE_MODEL_FAMILY = 'MIDSCENE_MODEL_FAMILY';
152
+
153
+ /**
154
+ * env keys declared but unused
155
+ */
156
+ export const UNUSED_ENV_KEYS = [MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG];
157
+
158
+ /**
159
+ * env keys for debug or basic run
160
+ * can not be override by overrideAIConfig
161
+ */
162
+ export const BASIC_ENV_KEYS = [
163
+ MIDSCENE_DEBUG_MODE,
164
+ MIDSCENE_DEBUG_MODEL_PROFILE,
165
+ MIDSCENE_DEBUG_MODEL_RESPONSE,
166
+ MIDSCENE_RUN_DIR,
167
+ ] as const;
168
+
169
+ export const BOOLEAN_ENV_KEYS = [
170
+ MIDSCENE_CACHE,
171
+ MIDSCENE_MCP_USE_PUPPETEER_MODE,
172
+ MIDSCENE_MCP_ANDROID_MODE,
173
+ MIDSCENE_LANGSMITH_DEBUG,
174
+ MIDSCENE_LANGFUSE_DEBUG,
175
+ MIDSCENE_REPORT_QUIET,
176
+ ] as const;
177
+
178
+ export const NUMBER_ENV_KEYS = [
179
+ MIDSCENE_MODEL_MAX_TOKENS,
180
+ MIDSCENE_CACHE_MAX_FILENAME_LENGTH,
181
+ MIDSCENE_REPLANNING_CYCLE_LIMIT,
182
+ ] as const;
183
+
184
+ export const STRING_ENV_KEYS = [
185
+ MIDSCENE_MODEL_MAX_TOKENS,
186
+ OPENAI_MAX_TOKENS,
187
+ MIDSCENE_ADB_PATH,
188
+ MIDSCENE_ADB_REMOTE_HOST,
189
+ MIDSCENE_ADB_REMOTE_PORT,
190
+ MIDSCENE_ANDROID_IME_STRATEGY,
191
+ MIDSCENE_IOS_DEVICE_UDID,
192
+ MIDSCENE_IOS_SIMULATOR_UDID,
193
+ MIDSCENE_REPORT_TAG_NAME,
194
+ MIDSCENE_PREFERRED_LANGUAGE,
195
+ MATCH_BY_POSITION,
196
+ MIDSCENE_MCP_CHROME_PATH,
197
+ DOCKER_CONTAINER,
198
+ ] as const;
199
+
200
+ /**
201
+ * Non model related env keys, used for globally controlling the behavior of midscene
202
+ * Can not be override by agent.modelConfig but can be override by overrideAIConfig
203
+ * Can be access at any time
204
+ */
205
+ export const GLOBAL_ENV_KEYS = [
206
+ ...BOOLEAN_ENV_KEYS,
207
+ ...NUMBER_ENV_KEYS,
208
+ ...STRING_ENV_KEYS,
209
+ ] as const;
210
+
211
+ /**
212
+ * Model related eve keys, used for declare which model to use.
213
+ * Can be override by both agent.modelConfig and overrideAIConfig
214
+ * Can only be access after agent.constructor
215
+ */
216
+ export const MODEL_ENV_KEYS = [
217
+ // model default
218
+ MIDSCENE_MODEL_NAME,
219
+ MIDSCENE_MODEL_INIT_CONFIG_JSON,
220
+ MIDSCENE_MODEL_EXTRA_BODY_JSON,
221
+ MIDSCENE_MODEL_API_KEY,
222
+ MIDSCENE_MODEL_BASE_URL,
223
+ MIDSCENE_MODEL_SOCKS_PROXY,
224
+ MIDSCENE_MODEL_HTTP_PROXY,
225
+ MIDSCENE_MODEL_TIMEOUT,
226
+ MIDSCENE_MODEL_TEMPERATURE,
227
+ MIDSCENE_MODEL_RETRY_COUNT,
228
+ MIDSCENE_MODEL_RETRY_INTERVAL,
229
+ MIDSCENE_MODEL_REASONING_EFFORT,
230
+ MIDSCENE_MODEL_REASONING_ENABLED,
231
+ MIDSCENE_MODEL_REASONING_BUDGET,
232
+ MIDSCENE_USE_VLM_UI_TARS,
233
+ MIDSCENE_USE_QWEN_VL,
234
+ MIDSCENE_USE_QWEN3_VL,
235
+ MIDSCENE_USE_DOUBAO_VISION,
236
+ MIDSCENE_USE_GEMINI,
237
+ MIDSCENE_USE_VL_MODEL,
238
+ // model default legacy
239
+ OPENAI_API_KEY,
240
+ OPENAI_BASE_URL,
241
+ MIDSCENE_OPENAI_INIT_CONFIG_JSON,
242
+ MIDSCENE_OPENAI_HTTP_PROXY,
243
+ MIDSCENE_OPENAI_SOCKS_PROXY,
244
+ // INSIGHT (unified VQA and Grounding)
245
+ MIDSCENE_INSIGHT_MODEL_NAME,
246
+ MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY,
247
+ MIDSCENE_INSIGHT_MODEL_HTTP_PROXY,
248
+ MIDSCENE_INSIGHT_MODEL_BASE_URL,
249
+ MIDSCENE_INSIGHT_MODEL_API_KEY,
250
+ MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON,
251
+ MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON,
252
+ MIDSCENE_INSIGHT_MODEL_TIMEOUT,
253
+ MIDSCENE_INSIGHT_MODEL_TEMPERATURE,
254
+ MIDSCENE_INSIGHT_MODEL_RETRY_COUNT,
255
+ MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL,
256
+ MIDSCENE_INSIGHT_MODEL_FAMILY,
257
+ MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT,
258
+ MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED,
259
+ MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET,
260
+ // PLANNING
261
+ MIDSCENE_PLANNING_MODEL_NAME,
262
+ MIDSCENE_PLANNING_MODEL_SOCKS_PROXY,
263
+ MIDSCENE_PLANNING_MODEL_HTTP_PROXY,
264
+ MIDSCENE_PLANNING_MODEL_BASE_URL,
265
+ MIDSCENE_PLANNING_MODEL_API_KEY,
266
+ MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON,
267
+ MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON,
268
+ MIDSCENE_PLANNING_MODEL_TIMEOUT,
269
+ MIDSCENE_PLANNING_MODEL_TEMPERATURE,
270
+ MIDSCENE_PLANNING_MODEL_RETRY_COUNT,
271
+ MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL,
272
+ MIDSCENE_PLANNING_MODEL_FAMILY,
273
+ MIDSCENE_PLANNING_MODEL_REASONING_EFFORT,
274
+ MIDSCENE_PLANNING_MODEL_REASONING_ENABLED,
275
+ MIDSCENE_PLANNING_MODEL_REASONING_BUDGET,
276
+ MIDSCENE_MODEL_FAMILY,
277
+ ] as const;
278
+
279
+ export const ALL_ENV_KEYS = [
280
+ ...UNUSED_ENV_KEYS,
281
+ ...BASIC_ENV_KEYS,
282
+ ...GLOBAL_ENV_KEYS,
283
+ ...MODEL_ENV_KEYS,
284
+ ] as const;
285
+
286
+ export type TEnvKeys = (typeof ALL_ENV_KEYS)[number];
287
+ export type TGlobalConfig = Record<TEnvKeys, string | undefined>;
288
+
289
+ /**
290
+ * valid Model family types
291
+ */
292
+ export type TModelFamily =
293
+ | 'qwen2.5-vl'
294
+ | 'qwen3-vl'
295
+ | 'qwen3.5'
296
+ | 'doubao-vision'
297
+ | 'doubao-seed'
298
+ | 'gemini'
299
+ | 'vlm-ui-tars'
300
+ | 'vlm-ui-tars-doubao'
301
+ | 'vlm-ui-tars-doubao-1.5'
302
+ | 'glm-v'
303
+ | 'auto-glm'
304
+ | 'auto-glm-multilingual'
305
+ | 'gpt-5';
306
+
307
+ export const MODEL_FAMILY_VALUES: TModelFamily[] = [
308
+ 'doubao-vision',
309
+ 'doubao-seed',
310
+ 'gemini',
311
+ 'qwen2.5-vl',
312
+ 'qwen3-vl',
313
+ 'qwen3.5',
314
+ 'vlm-ui-tars',
315
+ 'vlm-ui-tars-doubao',
316
+ 'vlm-ui-tars-doubao-1.5',
317
+ 'glm-v',
318
+ 'auto-glm',
319
+ 'auto-glm-multilingual',
320
+ 'gpt-5',
321
+ ];
322
+
323
+ export interface IModelConfigForInsight {
324
+ // model name
325
+ [MIDSCENE_INSIGHT_MODEL_NAME]: string;
326
+ // proxy
327
+ [MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY]?: string;
328
+ [MIDSCENE_INSIGHT_MODEL_HTTP_PROXY]?: string;
329
+ // OpenAI
330
+ [MIDSCENE_INSIGHT_MODEL_BASE_URL]?: string;
331
+ [MIDSCENE_INSIGHT_MODEL_API_KEY]?: string;
332
+ [MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON]?: string;
333
+ [MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON]?: string;
334
+ // timeout
335
+ [MIDSCENE_INSIGHT_MODEL_TIMEOUT]?: string;
336
+ // temperature
337
+ [MIDSCENE_INSIGHT_MODEL_TEMPERATURE]?: string;
338
+ // model family
339
+ [MIDSCENE_INSIGHT_MODEL_FAMILY]?: TModelFamily;
340
+ }
341
+
342
+ export interface IModelConfigForPlanning {
343
+ // model name
344
+ [MIDSCENE_PLANNING_MODEL_NAME]: string;
345
+ // proxy
346
+ [MIDSCENE_PLANNING_MODEL_SOCKS_PROXY]?: string;
347
+ [MIDSCENE_PLANNING_MODEL_HTTP_PROXY]?: string;
348
+ // OpenAI
349
+ [MIDSCENE_PLANNING_MODEL_BASE_URL]?: string;
350
+ [MIDSCENE_PLANNING_MODEL_API_KEY]?: string;
351
+ [MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON]?: string;
352
+ [MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON]?: string;
353
+ // timeout
354
+ [MIDSCENE_PLANNING_MODEL_TIMEOUT]?: string;
355
+ // temperature
356
+ [MIDSCENE_PLANNING_MODEL_TEMPERATURE]?: string;
357
+ // model family
358
+ [MIDSCENE_PLANNING_MODEL_FAMILY]?: TModelFamily;
359
+ }
360
+
361
+ /**
362
+ * Model configuration for Planning intent.
363
+ *
364
+ * IMPORTANT: Planning MUST use a vision language model (VL mode).
365
+ * DOM-based planning is not supported.
366
+ *
367
+ * Required: MIDSCENE_MODEL_FAMILY must be set to one of 「TModelFamily」
368
+ */
369
+ export interface IModelConfigForDefault {
370
+ // model name
371
+ [MIDSCENE_MODEL_NAME]: string;
372
+ // proxy
373
+ [MIDSCENE_MODEL_SOCKS_PROXY]?: string;
374
+ [MIDSCENE_MODEL_HTTP_PROXY]?: string;
375
+ // OpenAI
376
+ [MIDSCENE_MODEL_BASE_URL]?: string;
377
+ [MIDSCENE_MODEL_API_KEY]?: string;
378
+ [MIDSCENE_MODEL_INIT_CONFIG_JSON]?: string;
379
+ [MIDSCENE_MODEL_EXTRA_BODY_JSON]?: string;
380
+ // extra
381
+ [MIDSCENE_MODEL_FAMILY]?: TModelFamily;
382
+ // temperature
383
+ [MIDSCENE_MODEL_TEMPERATURE]?: string;
384
+ // reasoning effort
385
+ [MIDSCENE_MODEL_REASONING_EFFORT]?: string;
386
+ // enable reasoning (boolean as string)
387
+ [MIDSCENE_MODEL_REASONING_ENABLED]?: string;
388
+ // reasoning budget (number as string)
389
+ [MIDSCENE_MODEL_REASONING_BUDGET]?: string;
390
+ }
391
+
392
+ export interface IModelConfigForDefaultLegacy {
393
+ // model name
394
+ [MIDSCENE_MODEL_NAME]: string;
395
+ // proxy
396
+ [MIDSCENE_OPENAI_SOCKS_PROXY]?: string;
397
+ [MIDSCENE_OPENAI_HTTP_PROXY]?: string;
398
+ // OpenAI
399
+ [OPENAI_BASE_URL]?: string;
400
+ [OPENAI_API_KEY]?: string;
401
+ [MIDSCENE_OPENAI_INIT_CONFIG_JSON]?: string;
402
+ }
403
+
404
+ /**
405
+ * - insight: Visual Question Answering and Visual Grounding (unified)
406
+ * - planning: planning
407
+ * - default: all except insight、planning
408
+ */
409
+ export type TIntent = 'insight' | 'planning' | 'default';
410
+
411
+ /**
412
+ * Env-style model configuration map supplied directly to the agent.
413
+ * Numbers are allowed so callers can pass numeric env values (e.g. limits) without casting.
414
+ */
415
+ export type TModelConfig = Record<string, string | number>;
416
+
417
+ export enum UITarsModelVersion {
418
+ V1_0 = '1.0',
419
+ V1_5 = '1.5',
420
+ DOUBAO_1_5_15B = 'doubao-1.5-15B',
421
+ DOUBAO_1_5_20B = 'doubao-1.5-20B',
422
+ }
423
+
424
+ /**
425
+ * Callback to create custom OpenAI client instance
426
+ * @param config - Resolved model configuration including apiKey, baseURL, modelName, intent, etc.
427
+ * @returns OpenAI client instance (can be wrapped with langsmith, langfuse, etc.)
428
+ *
429
+ * Note: Wrapper functions like langsmith's wrapOpenAI() return the same OpenAI instance
430
+ * with enhanced behavior, so the return type remains compatible with OpenAI.
431
+ *
432
+ * Note: The return type is `any` in the shared package to avoid requiring openai as a dependency.
433
+ * The actual implementation should return an OpenAI instance.
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * import OpenAI from 'openai';
438
+ * import { wrapOpenAI } from 'langsmith/wrappers';
439
+ *
440
+ * createOpenAIClient: async (openai, opts) => {
441
+ * // Wrap with langsmith for planning tasks
442
+ * if (opts.baseURL?.includes('planning')) {
443
+ * return wrapOpenAI(openai, { metadata: { task: 'planning' } });
444
+ * }
445
+ *
446
+ * return openai;
447
+ * }
448
+ * ```
449
+ */
450
+ export type CreateOpenAIClientFn = (
451
+ openAIInstance: any,
452
+ options: Record<string, unknown>,
453
+ ) => Promise<any>; // OpenAI instance, but typed as `any` to avoid dependency
454
+
455
+ export interface IModelConfig {
456
+ /**
457
+ * proxy
458
+ */
459
+ socksProxy?: string;
460
+ httpProxy?: string;
461
+ /**
462
+ * model
463
+ */
464
+ modelName: string;
465
+ /**
466
+ * OpenAI
467
+ */
468
+ openaiBaseURL?: string;
469
+ openaiApiKey?: string;
470
+ openaiExtraConfig?: Record<string, unknown>;
471
+ /**
472
+ * Extra body parameters merged into each chat completion request body.
473
+ * Unlike openaiExtraConfig (which configures the OpenAI client instance),
474
+ * this is spread directly into the completion.create() call body.
475
+ * Example: { "chat_template_kwargs": { "enable_thinking": true } }
476
+ */
477
+ extraBody?: Record<string, unknown>;
478
+ /**
479
+ * Timeout for API calls in milliseconds.
480
+ * If not set, uses OpenAI SDK default (10 minutes).
481
+ */
482
+ timeout?: number;
483
+ /**
484
+ * Temperature for model sampling.
485
+ */
486
+ temperature?: number;
487
+ /**
488
+ * Number of retries when AI call fails.
489
+ * Default is 1 (retry once after failure).
490
+ */
491
+ retryCount?: number;
492
+ /**
493
+ * Interval between retries in milliseconds.
494
+ * Default is 2000.
495
+ */
496
+ retryInterval?: number;
497
+ /**
498
+ * Reasoning effort level for the model.
499
+ * Passed through to model-family-specific parameters (e.g., reasoning_effort for doubao, reasoning.effort for gpt-5).
500
+ */
501
+ reasoningEffort?: string;
502
+ /**
503
+ * Enable/disable reasoning for the model.
504
+ * Passed through to model-family-specific parameters (e.g., enable_thinking for qwen, thinking.type for doubao/glm-v).
505
+ */
506
+ reasoningEnabled?: boolean;
507
+ /**
508
+ * Reasoning token budget for the model.
509
+ * Passed through to model-family-specific parameters (e.g., thinking_budget for qwen).
510
+ */
511
+ reasoningBudget?: number;
512
+ /**
513
+ * Model family - unified model configuration
514
+ * Maps directly to model families like 'qwen2.5-vl', 'qwen3-vl', 'doubao-vision', 'doubao-seed', etc.
515
+ */
516
+ modelFamily?: TModelFamily;
517
+ uiTarsModelVersion?: UITarsModelVersion;
518
+ modelDescription: string;
519
+ /**
520
+ * original intent from the config
521
+ */
522
+ intent: TIntent;
523
+ /**
524
+ * Custom OpenAI client factory function
525
+ *
526
+ * If provided, this function will be called to create OpenAI client instances
527
+ * for each AI call, allowing you to:
528
+ * - Wrap clients with observability tools (langsmith, langfuse)
529
+ * - Use custom OpenAI-compatible clients
530
+ * - Apply different configurations based on intent
531
+ */
532
+ createOpenAIClient?: CreateOpenAIClientFn;
533
+ }
@@ -0,0 +1,89 @@
1
+ import { GlobalConfigManager } from './global-config-manager';
2
+ import { ModelConfigManager } from './model-config-manager';
3
+ import {
4
+ type GLOBAL_ENV_KEYS,
5
+ MIDSCENE_PREFERRED_LANGUAGE,
6
+ type MODEL_ENV_KEYS,
7
+ } from './types';
8
+
9
+ export const globalModelConfigManager = new ModelConfigManager();
10
+
11
+ export const globalConfigManager = new GlobalConfigManager();
12
+
13
+ globalConfigManager.registerModelConfigManager(globalModelConfigManager);
14
+ globalModelConfigManager.registerGlobalConfigManager(globalConfigManager);
15
+
16
+ /**
17
+ * Interface for devices that support getTimestamp method.
18
+ * This is a minimal interface to avoid circular dependencies with @midscene/core.
19
+ */
20
+ export interface DeviceWithTimestamp {
21
+ getTimestamp?: () => Promise<number>;
22
+ }
23
+
24
+ /**
25
+ * Get the current timestamp, optionally from the target device.
26
+ *
27
+ * When useDeviceTimestamp is enabled and a device with getTimestamp is provided,
28
+ * this function will return the device's time. Otherwise, it returns the system time.
29
+ *
30
+ * This is useful when:
31
+ * - Testing on devices with different time zones
32
+ * - Debugging time-sensitive features
33
+ * - The system clock and device clock are not synchronized
34
+ *
35
+ * @param device Optional device interface that supports getTimestamp
36
+ * @param useDeviceTimestamp Whether to use device timestamp (from agent config)
37
+ * @returns Timestamp in milliseconds
38
+ *
39
+ * @example
40
+ * // Without device - always returns system time
41
+ * const systemTime = await getCurrentTime();
42
+ *
43
+ * @example
44
+ * // With device and config enabled - returns device time
45
+ * const deviceTime = await getCurrentTime(androidDevice, true);
46
+ */
47
+ export async function getCurrentTime(
48
+ device?: DeviceWithTimestamp,
49
+ useDeviceTimestamp?: boolean,
50
+ ): Promise<number> {
51
+ if (useDeviceTimestamp && device?.getTimestamp) {
52
+ try {
53
+ return await device.getTimestamp();
54
+ } catch (error) {
55
+ // Fall back to system time if device time retrieval fails
56
+ console.warn(
57
+ `Failed to get device time, falling back to system time: ${error}`,
58
+ );
59
+ return Date.now();
60
+ }
61
+ }
62
+
63
+ return Date.now();
64
+ }
65
+
66
+ export const getPreferredLanguage = () => {
67
+ const prefer = globalConfigManager.getEnvConfigValue(
68
+ MIDSCENE_PREFERRED_LANGUAGE,
69
+ );
70
+ if (prefer) {
71
+ return prefer;
72
+ }
73
+
74
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
75
+ const isChina = timeZone === 'Asia/Shanghai';
76
+ return isChina ? 'Chinese' : 'English';
77
+ };
78
+
79
+ export const overrideAIConfig = (
80
+ newConfig: Partial<
81
+ Record<
82
+ (typeof GLOBAL_ENV_KEYS)[number] | (typeof MODEL_ENV_KEYS)[number],
83
+ string
84
+ >
85
+ >,
86
+ extendMode = false, // true: merge with global config, false: override global config
87
+ ) => {
88
+ globalConfigManager.overrideAIConfig(newConfig, extendMode);
89
+ };
@@ -0,0 +1,5 @@
1
+ export {
2
+ NodeType,
3
+ TEXT_MAX_SIZE,
4
+ TEXT_SIZE_THRESHOLD,
5
+ } from '../constants/index';
@@ -0,0 +1,10 @@
1
+ import { webExtractTextWithPosition } from '.';
2
+ import {
3
+ setExtractTextWithPositionOnWindow,
4
+ setMidsceneVisibleRectOnWindow,
5
+ } from './util';
6
+
7
+ console.log(webExtractTextWithPosition(document.body, true));
8
+ console.log(JSON.stringify(webExtractTextWithPosition(document.body, true)));
9
+ setExtractTextWithPositionOnWindow();
10
+ setMidsceneVisibleRectOnWindow();