@rpascene/shared 0.30.8 → 0.30.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/es/common.mjs +9 -9
- package/dist/es/constants/example-code.mjs +10 -10
- package/dist/es/constants/index.mjs +1 -1
- package/dist/es/env/constants.mjs +77 -77
- package/dist/es/env/global-config-manager.mjs +1 -1
- package/dist/es/env/init-debug.mjs +5 -5
- package/dist/es/env/model-config-manager.mjs +1 -1
- package/dist/es/env/parse.mjs +11 -11
- package/dist/es/env/types.mjs +191 -191
- package/dist/es/env/utils.mjs +2 -2
- package/dist/es/extractor/debug.mjs +2 -2
- package/dist/es/extractor/util.mjs +11 -11
- package/dist/es/extractor/web-extractor.mjs +7 -7
- package/dist/es/logger.mjs +3 -3
- package/dist/es/node/fs.mjs +6 -6
- package/dist/es/utils.mjs +2 -2
- package/dist/lib/common.js +16 -16
- package/dist/lib/constants/example-code.js +10 -10
- package/dist/lib/constants/index.js +1 -1
- package/dist/lib/env/constants.js +76 -76
- package/dist/lib/env/global-config-manager.js +1 -1
- package/dist/lib/env/init-debug.js +4 -4
- package/dist/lib/env/model-config-manager.js +1 -1
- package/dist/lib/env/parse.js +10 -10
- package/dist/lib/env/types.js +478 -478
- package/dist/lib/env/utils.js +1 -1
- package/dist/lib/extractor/debug.js +1 -1
- package/dist/lib/extractor/util.js +16 -16
- package/dist/lib/extractor/web-extractor.js +6 -6
- package/dist/lib/logger.js +2 -2
- package/dist/lib/node/fs.js +6 -6
- package/dist/lib/utils.js +2 -2
- package/dist/types/common.d.ts +5 -5
- package/dist/types/constants/example-code.d.ts +2 -2
- package/dist/types/env/types.d.ts +180 -180
- package/dist/types/extractor/util.d.ts +2 -2
- package/dist/types/node/fs.d.ts +1 -1
- package/package.json +8 -3
- package/src/common.ts +10 -10
- package/src/constants/example-code.ts +10 -10
- package/src/constants/index.ts +1 -1
- package/src/env/constants.ts +144 -144
- package/src/env/decide-model-config.ts +1 -1
- package/src/env/global-config-manager.ts +1 -1
- package/src/env/init-debug.ts +5 -5
- package/src/env/model-config-manager.ts +1 -1
- package/src/env/parse.ts +15 -15
- package/src/env/types.ts +315 -315
- package/src/env/utils.ts +2 -2
- package/src/extractor/debug.ts +2 -2
- package/src/extractor/util.ts +15 -15
- package/src/extractor/web-extractor.ts +7 -7
- package/src/logger.ts +3 -3
- package/src/node/fs.ts +5 -5
- package/src/utils.ts +2 -2
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
An AI-powered automation SDK can control the page, perform assertions, and extract data in JSON format using natural language.
|
|
4
4
|
|
|
5
|
-
See https://
|
|
5
|
+
See https://midscenejs.com/ for details.
|
|
6
6
|
|
|
7
7
|
## License
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Midscene is MIT licensed.
|
package/dist/es/common.mjs
CHANGED
|
@@ -2,16 +2,16 @@ import { existsSync, mkdirSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import node_path from "node:path";
|
|
4
4
|
import { getBasicEnvValue } from "./env/basic.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { MIDSCENE_RUN_DIR } from "./env/types.mjs";
|
|
6
6
|
import { ifInNode } from "./utils.mjs";
|
|
7
|
-
const defaultRunDirName = '
|
|
8
|
-
const
|
|
7
|
+
const defaultRunDirName = 'midscene_run';
|
|
8
|
+
const getMidsceneRunDir = ()=>{
|
|
9
9
|
if (!ifInNode) return '';
|
|
10
|
-
return getBasicEnvValue(
|
|
10
|
+
return getBasicEnvValue(MIDSCENE_RUN_DIR) || defaultRunDirName;
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const getMidsceneRunBaseDir = ()=>{
|
|
13
13
|
if (!ifInNode) return '';
|
|
14
|
-
let basePath = node_path.resolve(process.cwd(),
|
|
14
|
+
let basePath = node_path.resolve(process.cwd(), getMidsceneRunDir());
|
|
15
15
|
if (!existsSync(basePath)) try {
|
|
16
16
|
mkdirSync(basePath, {
|
|
17
17
|
recursive: true
|
|
@@ -24,9 +24,9 @@ const getRpasceneRunBaseDir = ()=>{
|
|
|
24
24
|
}
|
|
25
25
|
return basePath;
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const getMidsceneRunSubDir = (subdir)=>{
|
|
28
28
|
if (!ifInNode) return '';
|
|
29
|
-
const basePath =
|
|
29
|
+
const basePath = getMidsceneRunBaseDir();
|
|
30
30
|
const logPath = node_path.join(basePath, subdir);
|
|
31
31
|
if (!existsSync(logPath)) mkdirSync(logPath, {
|
|
32
32
|
recursive: true
|
|
@@ -34,4 +34,4 @@ const getRpasceneRunSubDir = (subdir)=>{
|
|
|
34
34
|
return logPath;
|
|
35
35
|
};
|
|
36
36
|
const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = 'NOT_IMPLEMENTED_AS_DESIGNED';
|
|
37
|
-
export { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED, defaultRunDirName,
|
|
37
|
+
export { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED, defaultRunDirName, getMidsceneRunBaseDir, getMidsceneRunDir, getMidsceneRunSubDir };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const PLAYWRIGHT_EXAMPLE_CODE = `
|
|
2
|
-
// Reference the following code to generate
|
|
3
|
-
// The following is test code for
|
|
2
|
+
// Reference the following code to generate Midscene test cases
|
|
3
|
+
// The following is test code for Midscene AI, for reference
|
|
4
4
|
// The following is Playwright syntax, you can use Playwright to assist in test generation
|
|
5
5
|
IMPORTANT: Follow these exact type signatures for AI functions:
|
|
6
6
|
|
|
@@ -17,8 +17,8 @@ aiAssert(assertion: string): Promise<void>
|
|
|
17
17
|
aiQuery<T>(queryObject: Record<string, string>): Promise<T> // Extracts data from page based on descriptions
|
|
18
18
|
|
|
19
19
|
// examples:
|
|
20
|
-
// Reference the following code to generate
|
|
21
|
-
// The following is test code for
|
|
20
|
+
// Reference the following code to generate Midscene test cases
|
|
21
|
+
// The following is test code for Midscene AI, for reference
|
|
22
22
|
// The following is Playwright syntax, you can use Playwright to assist in test generation
|
|
23
23
|
import { test as base } from '@playwright/test';
|
|
24
24
|
import type { PlayWrightAiFixtureType } from '@rpascene/web/playwright';
|
|
@@ -127,33 +127,33 @@ tasks:
|
|
|
127
127
|
# Tap an element described by a prompt.
|
|
128
128
|
- aiTap: <prompt>
|
|
129
129
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
130
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
130
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
131
131
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
132
132
|
|
|
133
133
|
# Double click an element described by a prompt.
|
|
134
134
|
- aiDoubleClick: <prompt>
|
|
135
135
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
136
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
136
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
137
137
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
138
138
|
|
|
139
139
|
# Hover over an element described by a prompt.
|
|
140
140
|
- aiHover: <prompt>
|
|
141
141
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
142
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
142
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
143
143
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
144
144
|
|
|
145
145
|
# Input text into an element described by a prompt.
|
|
146
146
|
- aiInput: <final text content of the input>
|
|
147
147
|
locate: <prompt>
|
|
148
148
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
149
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
149
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
150
150
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
151
151
|
|
|
152
152
|
# Press a key (e.g., Enter, Tab, Escape) on an element described by a prompt.
|
|
153
153
|
- aiKeyboardPress: <key>
|
|
154
154
|
locate: <prompt>
|
|
155
155
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
156
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
156
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
157
157
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
158
158
|
|
|
159
159
|
# Scroll globally or on an element described by a prompt.
|
|
@@ -163,7 +163,7 @@ tasks:
|
|
|
163
163
|
distance: <number> # Optional, the scroll distance in pixels.
|
|
164
164
|
locate: <prompt> # Optional, the element to scroll on.
|
|
165
165
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
166
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
166
|
+
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Midscene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
|
|
167
167
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
168
168
|
|
|
169
169
|
# Log the current screenshot with a description in the report file.
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { ANTHROPIC_API_KEY, AZURE_OPENAI_API_VERSION, AZURE_OPENAI_DEPLOYMENT, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_KEY,
|
|
1
|
+
import { ANTHROPIC_API_KEY, AZURE_OPENAI_API_VERSION, AZURE_OPENAI_DEPLOYMENT, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_KEY, MIDSCENE_ANTHROPIC_API_KEY, MIDSCENE_AZURE_OPENAI_API_VERSION, MIDSCENE_AZURE_OPENAI_DEPLOYMENT, MIDSCENE_AZURE_OPENAI_ENDPOINT, MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_AZURE_OPENAI_KEY, MIDSCENE_AZURE_OPENAI_SCOPE, MIDSCENE_GROUNDING_ANTHROPIC_API_KEY, MIDSCENE_GROUNDING_AZURE_OPENAI_API_VERSION, MIDSCENE_GROUNDING_AZURE_OPENAI_DEPLOYMENT, MIDSCENE_GROUNDING_AZURE_OPENAI_ENDPOINT, MIDSCENE_GROUNDING_AZURE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_GROUNDING_AZURE_OPENAI_KEY, MIDSCENE_GROUNDING_AZURE_OPENAI_SCOPE, MIDSCENE_GROUNDING_MODEL_NAME, MIDSCENE_GROUNDING_OPENAI_API_KEY, MIDSCENE_GROUNDING_OPENAI_BASE_URL, MIDSCENE_GROUNDING_OPENAI_HTTP_PROXY, MIDSCENE_GROUNDING_OPENAI_INIT_CONFIG_JSON, MIDSCENE_GROUNDING_OPENAI_SOCKS_PROXY, MIDSCENE_GROUNDING_OPENAI_USE_AZURE, MIDSCENE_GROUNDING_USE_ANTHROPIC_SDK, MIDSCENE_GROUNDING_USE_AZURE_OPENAI, MIDSCENE_GROUNDING_VL_MODE, MIDSCENE_MODEL_NAME, MIDSCENE_OPENAI_API_KEY, MIDSCENE_OPENAI_BASE_URL, MIDSCENE_OPENAI_HTTP_PROXY, MIDSCENE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_OPENAI_SOCKS_PROXY, MIDSCENE_OPENAI_USE_AZURE, MIDSCENE_PLANNING_ANTHROPIC_API_KEY, MIDSCENE_PLANNING_AZURE_OPENAI_API_VERSION, MIDSCENE_PLANNING_AZURE_OPENAI_DEPLOYMENT, MIDSCENE_PLANNING_AZURE_OPENAI_ENDPOINT, MIDSCENE_PLANNING_AZURE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_PLANNING_AZURE_OPENAI_KEY, MIDSCENE_PLANNING_AZURE_OPENAI_SCOPE, MIDSCENE_PLANNING_MODEL_NAME, MIDSCENE_PLANNING_OPENAI_API_KEY, MIDSCENE_PLANNING_OPENAI_BASE_URL, MIDSCENE_PLANNING_OPENAI_HTTP_PROXY, MIDSCENE_PLANNING_OPENAI_INIT_CONFIG_JSON, MIDSCENE_PLANNING_OPENAI_SOCKS_PROXY, MIDSCENE_PLANNING_OPENAI_USE_AZURE, MIDSCENE_PLANNING_USE_ANTHROPIC_SDK, MIDSCENE_PLANNING_USE_AZURE_OPENAI, MIDSCENE_PLANNING_VL_MODE, MIDSCENE_USE_ANTHROPIC_SDK, MIDSCENE_USE_AZURE_OPENAI, MIDSCENE_VL_MODE, MIDSCENE_VQA_ANTHROPIC_API_KEY, MIDSCENE_VQA_AZURE_OPENAI_API_VERSION, MIDSCENE_VQA_AZURE_OPENAI_DEPLOYMENT, MIDSCENE_VQA_AZURE_OPENAI_ENDPOINT, MIDSCENE_VQA_AZURE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_VQA_AZURE_OPENAI_KEY, MIDSCENE_VQA_AZURE_OPENAI_SCOPE, MIDSCENE_VQA_MODEL_NAME, MIDSCENE_VQA_OPENAI_API_KEY, MIDSCENE_VQA_OPENAI_BASE_URL, MIDSCENE_VQA_OPENAI_HTTP_PROXY, MIDSCENE_VQA_OPENAI_INIT_CONFIG_JSON, MIDSCENE_VQA_OPENAI_SOCKS_PROXY, MIDSCENE_VQA_OPENAI_USE_AZURE, MIDSCENE_VQA_USE_ANTHROPIC_SDK, MIDSCENE_VQA_USE_AZURE_OPENAI, MIDSCENE_VQA_VL_MODE, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_USE_AZURE } from "./types.mjs";
|
|
2
2
|
const VQA_MODEL_CONFIG_KEYS = {
|
|
3
|
-
modelName:
|
|
4
|
-
socksProxy:
|
|
5
|
-
httpProxy:
|
|
6
|
-
openaiBaseURL:
|
|
7
|
-
openaiApiKey:
|
|
8
|
-
openaiExtraConfig:
|
|
9
|
-
openaiUseAzureDeprecated:
|
|
10
|
-
useAzureOpenai:
|
|
11
|
-
azureOpenaiScope:
|
|
12
|
-
azureOpenaiKey:
|
|
13
|
-
azureOpenaiEndpoint:
|
|
14
|
-
azureOpenaiApiVersion:
|
|
15
|
-
azureOpenaiDeployment:
|
|
16
|
-
azureExtraConfig:
|
|
17
|
-
useAnthropicSdk:
|
|
18
|
-
anthropicApiKey:
|
|
19
|
-
vlMode:
|
|
3
|
+
modelName: MIDSCENE_VQA_MODEL_NAME,
|
|
4
|
+
socksProxy: MIDSCENE_VQA_OPENAI_SOCKS_PROXY,
|
|
5
|
+
httpProxy: MIDSCENE_VQA_OPENAI_HTTP_PROXY,
|
|
6
|
+
openaiBaseURL: MIDSCENE_VQA_OPENAI_BASE_URL,
|
|
7
|
+
openaiApiKey: MIDSCENE_VQA_OPENAI_API_KEY,
|
|
8
|
+
openaiExtraConfig: MIDSCENE_VQA_OPENAI_INIT_CONFIG_JSON,
|
|
9
|
+
openaiUseAzureDeprecated: MIDSCENE_VQA_OPENAI_USE_AZURE,
|
|
10
|
+
useAzureOpenai: MIDSCENE_VQA_USE_AZURE_OPENAI,
|
|
11
|
+
azureOpenaiScope: MIDSCENE_VQA_AZURE_OPENAI_SCOPE,
|
|
12
|
+
azureOpenaiKey: MIDSCENE_VQA_AZURE_OPENAI_KEY,
|
|
13
|
+
azureOpenaiEndpoint: MIDSCENE_VQA_AZURE_OPENAI_ENDPOINT,
|
|
14
|
+
azureOpenaiApiVersion: MIDSCENE_VQA_AZURE_OPENAI_API_VERSION,
|
|
15
|
+
azureOpenaiDeployment: MIDSCENE_VQA_AZURE_OPENAI_DEPLOYMENT,
|
|
16
|
+
azureExtraConfig: MIDSCENE_VQA_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
17
|
+
useAnthropicSdk: MIDSCENE_VQA_USE_ANTHROPIC_SDK,
|
|
18
|
+
anthropicApiKey: MIDSCENE_VQA_ANTHROPIC_API_KEY,
|
|
19
|
+
vlMode: MIDSCENE_VQA_VL_MODE
|
|
20
20
|
};
|
|
21
21
|
const GROUNDING_MODEL_CONFIG_KEYS = {
|
|
22
|
-
modelName:
|
|
23
|
-
socksProxy:
|
|
24
|
-
httpProxy:
|
|
25
|
-
openaiBaseURL:
|
|
26
|
-
openaiApiKey:
|
|
27
|
-
openaiExtraConfig:
|
|
28
|
-
openaiUseAzureDeprecated:
|
|
29
|
-
useAzureOpenai:
|
|
30
|
-
azureOpenaiScope:
|
|
31
|
-
azureOpenaiKey:
|
|
32
|
-
azureOpenaiEndpoint:
|
|
33
|
-
azureOpenaiApiVersion:
|
|
34
|
-
azureOpenaiDeployment:
|
|
35
|
-
azureExtraConfig:
|
|
36
|
-
useAnthropicSdk:
|
|
37
|
-
anthropicApiKey:
|
|
38
|
-
vlMode:
|
|
22
|
+
modelName: MIDSCENE_GROUNDING_MODEL_NAME,
|
|
23
|
+
socksProxy: MIDSCENE_GROUNDING_OPENAI_SOCKS_PROXY,
|
|
24
|
+
httpProxy: MIDSCENE_GROUNDING_OPENAI_HTTP_PROXY,
|
|
25
|
+
openaiBaseURL: MIDSCENE_GROUNDING_OPENAI_BASE_URL,
|
|
26
|
+
openaiApiKey: MIDSCENE_GROUNDING_OPENAI_API_KEY,
|
|
27
|
+
openaiExtraConfig: MIDSCENE_GROUNDING_OPENAI_INIT_CONFIG_JSON,
|
|
28
|
+
openaiUseAzureDeprecated: MIDSCENE_GROUNDING_OPENAI_USE_AZURE,
|
|
29
|
+
useAzureOpenai: MIDSCENE_GROUNDING_USE_AZURE_OPENAI,
|
|
30
|
+
azureOpenaiScope: MIDSCENE_GROUNDING_AZURE_OPENAI_SCOPE,
|
|
31
|
+
azureOpenaiKey: MIDSCENE_GROUNDING_AZURE_OPENAI_KEY,
|
|
32
|
+
azureOpenaiEndpoint: MIDSCENE_GROUNDING_AZURE_OPENAI_ENDPOINT,
|
|
33
|
+
azureOpenaiApiVersion: MIDSCENE_GROUNDING_AZURE_OPENAI_API_VERSION,
|
|
34
|
+
azureOpenaiDeployment: MIDSCENE_GROUNDING_AZURE_OPENAI_DEPLOYMENT,
|
|
35
|
+
azureExtraConfig: MIDSCENE_GROUNDING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
36
|
+
useAnthropicSdk: MIDSCENE_GROUNDING_USE_ANTHROPIC_SDK,
|
|
37
|
+
anthropicApiKey: MIDSCENE_GROUNDING_ANTHROPIC_API_KEY,
|
|
38
|
+
vlMode: MIDSCENE_GROUNDING_VL_MODE
|
|
39
39
|
};
|
|
40
40
|
const PLANNING_MODEL_CONFIG_KEYS = {
|
|
41
|
-
modelName:
|
|
42
|
-
socksProxy:
|
|
43
|
-
httpProxy:
|
|
44
|
-
openaiBaseURL:
|
|
45
|
-
openaiApiKey:
|
|
46
|
-
openaiExtraConfig:
|
|
47
|
-
openaiUseAzureDeprecated:
|
|
48
|
-
useAzureOpenai:
|
|
49
|
-
azureOpenaiScope:
|
|
50
|
-
azureOpenaiKey:
|
|
51
|
-
azureOpenaiEndpoint:
|
|
52
|
-
azureOpenaiApiVersion:
|
|
53
|
-
azureOpenaiDeployment:
|
|
54
|
-
azureExtraConfig:
|
|
55
|
-
useAnthropicSdk:
|
|
56
|
-
anthropicApiKey:
|
|
57
|
-
vlMode:
|
|
41
|
+
modelName: MIDSCENE_PLANNING_MODEL_NAME,
|
|
42
|
+
socksProxy: MIDSCENE_PLANNING_OPENAI_SOCKS_PROXY,
|
|
43
|
+
httpProxy: MIDSCENE_PLANNING_OPENAI_HTTP_PROXY,
|
|
44
|
+
openaiBaseURL: MIDSCENE_PLANNING_OPENAI_BASE_URL,
|
|
45
|
+
openaiApiKey: MIDSCENE_PLANNING_OPENAI_API_KEY,
|
|
46
|
+
openaiExtraConfig: MIDSCENE_PLANNING_OPENAI_INIT_CONFIG_JSON,
|
|
47
|
+
openaiUseAzureDeprecated: MIDSCENE_PLANNING_OPENAI_USE_AZURE,
|
|
48
|
+
useAzureOpenai: MIDSCENE_PLANNING_USE_AZURE_OPENAI,
|
|
49
|
+
azureOpenaiScope: MIDSCENE_PLANNING_AZURE_OPENAI_SCOPE,
|
|
50
|
+
azureOpenaiKey: MIDSCENE_PLANNING_AZURE_OPENAI_KEY,
|
|
51
|
+
azureOpenaiEndpoint: MIDSCENE_PLANNING_AZURE_OPENAI_ENDPOINT,
|
|
52
|
+
azureOpenaiApiVersion: MIDSCENE_PLANNING_AZURE_OPENAI_API_VERSION,
|
|
53
|
+
azureOpenaiDeployment: MIDSCENE_PLANNING_AZURE_OPENAI_DEPLOYMENT,
|
|
54
|
+
azureExtraConfig: MIDSCENE_PLANNING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
55
|
+
useAnthropicSdk: MIDSCENE_PLANNING_USE_ANTHROPIC_SDK,
|
|
56
|
+
anthropicApiKey: MIDSCENE_PLANNING_ANTHROPIC_API_KEY,
|
|
57
|
+
vlMode: MIDSCENE_PLANNING_VL_MODE
|
|
58
58
|
};
|
|
59
59
|
const DEFAULT_MODEL_CONFIG_KEYS = {
|
|
60
|
-
modelName:
|
|
61
|
-
socksProxy:
|
|
62
|
-
httpProxy:
|
|
63
|
-
openaiBaseURL:
|
|
64
|
-
openaiApiKey:
|
|
65
|
-
openaiExtraConfig:
|
|
66
|
-
openaiUseAzureDeprecated:
|
|
67
|
-
useAzureOpenai:
|
|
68
|
-
azureOpenaiScope:
|
|
69
|
-
azureOpenaiKey:
|
|
70
|
-
azureOpenaiEndpoint:
|
|
71
|
-
azureOpenaiApiVersion:
|
|
72
|
-
azureOpenaiDeployment:
|
|
73
|
-
azureExtraConfig:
|
|
74
|
-
useAnthropicSdk:
|
|
75
|
-
anthropicApiKey:
|
|
76
|
-
vlMode:
|
|
60
|
+
modelName: MIDSCENE_MODEL_NAME,
|
|
61
|
+
socksProxy: MIDSCENE_OPENAI_SOCKS_PROXY,
|
|
62
|
+
httpProxy: MIDSCENE_OPENAI_HTTP_PROXY,
|
|
63
|
+
openaiBaseURL: MIDSCENE_OPENAI_BASE_URL,
|
|
64
|
+
openaiApiKey: MIDSCENE_OPENAI_API_KEY,
|
|
65
|
+
openaiExtraConfig: MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
66
|
+
openaiUseAzureDeprecated: MIDSCENE_OPENAI_USE_AZURE,
|
|
67
|
+
useAzureOpenai: MIDSCENE_USE_AZURE_OPENAI,
|
|
68
|
+
azureOpenaiScope: MIDSCENE_AZURE_OPENAI_SCOPE,
|
|
69
|
+
azureOpenaiKey: MIDSCENE_AZURE_OPENAI_KEY,
|
|
70
|
+
azureOpenaiEndpoint: MIDSCENE_AZURE_OPENAI_ENDPOINT,
|
|
71
|
+
azureOpenaiApiVersion: MIDSCENE_AZURE_OPENAI_API_VERSION,
|
|
72
|
+
azureOpenaiDeployment: MIDSCENE_AZURE_OPENAI_DEPLOYMENT,
|
|
73
|
+
azureExtraConfig: MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
74
|
+
useAnthropicSdk: MIDSCENE_USE_ANTHROPIC_SDK,
|
|
75
|
+
anthropicApiKey: MIDSCENE_ANTHROPIC_API_KEY,
|
|
76
|
+
vlMode: MIDSCENE_VL_MODE
|
|
77
77
|
};
|
|
78
78
|
const DEFAULT_MODEL_CONFIG_KEYS_LEGACY = {
|
|
79
|
-
modelName:
|
|
80
|
-
socksProxy:
|
|
81
|
-
httpProxy:
|
|
79
|
+
modelName: MIDSCENE_MODEL_NAME,
|
|
80
|
+
socksProxy: MIDSCENE_OPENAI_SOCKS_PROXY,
|
|
81
|
+
httpProxy: MIDSCENE_OPENAI_HTTP_PROXY,
|
|
82
82
|
openaiBaseURL: OPENAI_BASE_URL,
|
|
83
83
|
openaiApiKey: OPENAI_API_KEY,
|
|
84
|
-
openaiExtraConfig:
|
|
84
|
+
openaiExtraConfig: MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
85
85
|
openaiUseAzureDeprecated: OPENAI_USE_AZURE,
|
|
86
|
-
useAzureOpenai:
|
|
87
|
-
azureOpenaiScope:
|
|
86
|
+
useAzureOpenai: MIDSCENE_USE_AZURE_OPENAI,
|
|
87
|
+
azureOpenaiScope: MIDSCENE_AZURE_OPENAI_SCOPE,
|
|
88
88
|
azureOpenaiKey: AZURE_OPENAI_KEY,
|
|
89
89
|
azureOpenaiEndpoint: AZURE_OPENAI_ENDPOINT,
|
|
90
90
|
azureOpenaiApiVersion: AZURE_OPENAI_API_VERSION,
|
|
91
91
|
azureOpenaiDeployment: AZURE_OPENAI_DEPLOYMENT,
|
|
92
|
-
azureExtraConfig:
|
|
93
|
-
useAnthropicSdk:
|
|
92
|
+
azureExtraConfig: MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
93
|
+
useAnthropicSdk: MIDSCENE_USE_ANTHROPIC_SDK,
|
|
94
94
|
anthropicApiKey: ANTHROPIC_API_KEY,
|
|
95
95
|
vlMode: 'DEFAULT_MODEL_CONFIG_KEYS has no vlMode key'
|
|
96
96
|
};
|
|
@@ -31,7 +31,7 @@ class GlobalConfigManager {
|
|
|
31
31
|
getEnvConfigValue(key) {
|
|
32
32
|
const allConfig = this.getAllEnvConfig();
|
|
33
33
|
if (!STRING_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigValue with key ${key} is not supported.`);
|
|
34
|
-
if (key === MATCH_BY_POSITION) throw new Error('MATCH_BY_POSITION is deprecated, use
|
|
34
|
+
if (key === MATCH_BY_POSITION) throw new Error('MATCH_BY_POSITION is deprecated, use MIDSCENE_USE_VL_MODEL instead');
|
|
35
35
|
const value = allConfig[key];
|
|
36
36
|
this.keysHaveBeenRead[key] = true;
|
|
37
37
|
if ('string' == typeof value) return value.trim();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { enableDebug } from "../logger.mjs";
|
|
2
2
|
import { getBasicEnvValue } from "./basic.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { MIDSCENE_DEBUG_AI_PROFILE, MIDSCENE_DEBUG_AI_RESPONSE } from "./types.mjs";
|
|
4
4
|
const initDebugConfig = ()=>{
|
|
5
|
-
const shouldPrintTiming = getBasicEnvValue(
|
|
5
|
+
const shouldPrintTiming = getBasicEnvValue(MIDSCENE_DEBUG_AI_PROFILE);
|
|
6
6
|
let debugConfig = '';
|
|
7
7
|
if (shouldPrintTiming) {
|
|
8
|
-
console.warn('
|
|
8
|
+
console.warn('MIDSCENE_DEBUG_AI_PROFILE is deprecated, use DEBUG=midscene:ai:profile instead');
|
|
9
9
|
debugConfig = 'ai:profile';
|
|
10
10
|
}
|
|
11
|
-
const shouldPrintAIResponse = getBasicEnvValue(
|
|
11
|
+
const shouldPrintAIResponse = getBasicEnvValue(MIDSCENE_DEBUG_AI_RESPONSE);
|
|
12
12
|
if (shouldPrintAIResponse) {
|
|
13
|
-
console.warn('
|
|
13
|
+
console.warn('MIDSCENE_DEBUG_AI_RESPONSE is deprecated, use DEBUG=midscene:ai:response instead');
|
|
14
14
|
debugConfig = debugConfig ? 'ai:*' : 'ai:call';
|
|
15
15
|
}
|
|
16
16
|
if (debugConfig) enableDebug(debugConfig);
|
|
@@ -83,7 +83,7 @@ class ModelConfigManager {
|
|
|
83
83
|
}
|
|
84
84
|
throwErrorIfNonVLModel(intent = 'grounding') {
|
|
85
85
|
const modelConfig = this.getModelConfig(intent);
|
|
86
|
-
if (!modelConfig.vlMode) throw new Error('No visual language model (VL model) detected for the current scenario. Element localization may be inaccurate. Please verify your model configuration. Learn more: https://
|
|
86
|
+
if (!modelConfig.vlMode) throw new Error('No visual language model (VL model) detected for the current scenario. Element localization may be inaccurate. Please verify your model configuration. Learn more: https://midscenejs.com/choose-a-model');
|
|
87
87
|
}
|
|
88
88
|
constructor(modelConfigFn){
|
|
89
89
|
_define_property(this, "modelConfigMap", void 0);
|
package/dist/es/env/parse.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN3_VL, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS, UITarsModelVersion, VL_MODE_RAW_VALID_VALUES } from "./types.mjs";
|
|
2
2
|
const parseVlModeAndUiTarsModelVersionFromRawValue = (vlModeRaw)=>{
|
|
3
3
|
if (!vlModeRaw) return {
|
|
4
4
|
vlMode: void 0,
|
|
@@ -20,17 +20,17 @@ const parseVlModeAndUiTarsModelVersionFromRawValue = (vlModeRaw)=>{
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
const parseVlModeAndUiTarsFromGlobalConfig = (provider)=>{
|
|
23
|
-
const isDoubao = provider[
|
|
24
|
-
const isQwen = provider[
|
|
25
|
-
const isQwen3 = provider[
|
|
26
|
-
const isUiTars = provider[
|
|
27
|
-
const isGemini = provider[
|
|
23
|
+
const isDoubao = provider[MIDSCENE_USE_DOUBAO_VISION];
|
|
24
|
+
const isQwen = provider[MIDSCENE_USE_QWEN_VL];
|
|
25
|
+
const isQwen3 = provider[MIDSCENE_USE_QWEN3_VL];
|
|
26
|
+
const isUiTars = provider[MIDSCENE_USE_VLM_UI_TARS];
|
|
27
|
+
const isGemini = provider[MIDSCENE_USE_GEMINI];
|
|
28
28
|
const enabledModes = [
|
|
29
|
-
isDoubao &&
|
|
30
|
-
isQwen &&
|
|
31
|
-
isQwen3 &&
|
|
32
|
-
isUiTars &&
|
|
33
|
-
isGemini &&
|
|
29
|
+
isDoubao && MIDSCENE_USE_DOUBAO_VISION,
|
|
30
|
+
isQwen && MIDSCENE_USE_QWEN_VL,
|
|
31
|
+
isQwen3 && MIDSCENE_USE_QWEN3_VL,
|
|
32
|
+
isUiTars && MIDSCENE_USE_VLM_UI_TARS,
|
|
33
|
+
isGemini && MIDSCENE_USE_GEMINI
|
|
34
34
|
].filter(Boolean);
|
|
35
35
|
if (enabledModes.length > 1) throw new Error(`Only one vision mode can be enabled at a time. Currently enabled modes: ${enabledModes.join(', ')}. Please disable all but one mode.`);
|
|
36
36
|
if (isQwen3) return {
|