@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/src/common.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
// do not import getBasicEnvValue and
|
|
4
|
+
// do not import getBasicEnvValue and MIDSCENE_RUN_DIR directly from ./env,
|
|
5
5
|
// because it will cause circular dependency
|
|
6
6
|
import { getBasicEnvValue } from './env/basic';
|
|
7
|
-
import {
|
|
7
|
+
import { MIDSCENE_RUN_DIR } from './env/types';
|
|
8
8
|
import { ifInNode } from './utils';
|
|
9
9
|
|
|
10
|
-
export const defaultRunDirName = '
|
|
10
|
+
export const defaultRunDirName = 'midscene_run';
|
|
11
11
|
// Define locally for now to avoid import issues
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const getMidsceneRunDir = () => {
|
|
14
14
|
if (!ifInNode) {
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return getBasicEnvValue(
|
|
18
|
+
return getBasicEnvValue(MIDSCENE_RUN_DIR) || defaultRunDirName;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const getMidsceneRunBaseDir = () => {
|
|
22
22
|
if (!ifInNode) {
|
|
23
23
|
return '';
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let basePath = path.resolve(process.cwd(),
|
|
26
|
+
let basePath = path.resolve(process.cwd(), getMidsceneRunDir());
|
|
27
27
|
|
|
28
28
|
// Create a base directory
|
|
29
29
|
if (!existsSync(basePath)) {
|
|
@@ -40,13 +40,13 @@ export const getRpasceneRunBaseDir = () => {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Get the path to the
|
|
43
|
+
* Get the path to the midscene_run directory or a subdirectory within it.
|
|
44
44
|
* Creates the directory if it doesn't exist.
|
|
45
45
|
*
|
|
46
46
|
* @param subdir - Optional subdirectory name (e.g., 'log', 'report')
|
|
47
47
|
* @returns The absolute path to the requested directory
|
|
48
48
|
*/
|
|
49
|
-
export const
|
|
49
|
+
export const getMidsceneRunSubDir = (
|
|
50
50
|
subdir: 'dump' | 'cache' | 'report' | 'tmp' | 'log' | 'output',
|
|
51
51
|
): string => {
|
|
52
52
|
if (!ifInNode) {
|
|
@@ -54,7 +54,7 @@ export const getRpasceneRunSubDir = (
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Create a log directory
|
|
57
|
-
const basePath =
|
|
57
|
+
const basePath = getMidsceneRunBaseDir();
|
|
58
58
|
const logPath = path.join(basePath, subdir);
|
|
59
59
|
if (!existsSync(logPath)) {
|
|
60
60
|
mkdirSync(logPath, { recursive: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export 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';
|
|
@@ -128,33 +128,33 @@ tasks:
|
|
|
128
128
|
# Tap an element described by a prompt.
|
|
129
129
|
- aiTap: <prompt>
|
|
130
130
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
131
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
131
|
+
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.
|
|
132
132
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
133
133
|
|
|
134
134
|
# Double click an element described by a prompt.
|
|
135
135
|
- aiDoubleClick: <prompt>
|
|
136
136
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
137
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
137
|
+
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.
|
|
138
138
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
139
139
|
|
|
140
140
|
# Hover over an element described by a prompt.
|
|
141
141
|
- aiHover: <prompt>
|
|
142
142
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
143
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
143
|
+
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.
|
|
144
144
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
145
145
|
|
|
146
146
|
# Input text into an element described by a prompt.
|
|
147
147
|
- aiInput: <final text content of the input>
|
|
148
148
|
locate: <prompt>
|
|
149
149
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
150
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
150
|
+
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.
|
|
151
151
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
152
152
|
|
|
153
153
|
# Press a key (e.g., Enter, Tab, Escape) on an element described by a prompt.
|
|
154
154
|
- aiKeyboardPress: <key>
|
|
155
155
|
locate: <prompt>
|
|
156
156
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
157
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
157
|
+
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.
|
|
158
158
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
159
159
|
|
|
160
160
|
# Scroll globally or on an element described by a prompt.
|
|
@@ -164,7 +164,7 @@ tasks:
|
|
|
164
164
|
distance: <number> # Optional, the scroll distance in pixels.
|
|
165
165
|
locate: <prompt> # Optional, the element to scroll on.
|
|
166
166
|
deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
|
|
167
|
-
xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided,
|
|
167
|
+
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.
|
|
168
168
|
cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
|
|
169
169
|
|
|
170
170
|
# Log the current screenshot with a description in the report file.
|
package/src/constants/index.ts
CHANGED
package/src/env/constants.ts
CHANGED
|
@@ -4,75 +4,75 @@ import {
|
|
|
4
4
|
AZURE_OPENAI_DEPLOYMENT,
|
|
5
5
|
AZURE_OPENAI_ENDPOINT,
|
|
6
6
|
AZURE_OPENAI_KEY,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
7
|
+
MIDSCENE_ANTHROPIC_API_KEY,
|
|
8
|
+
MIDSCENE_AZURE_OPENAI_API_VERSION,
|
|
9
|
+
MIDSCENE_AZURE_OPENAI_DEPLOYMENT,
|
|
10
|
+
MIDSCENE_AZURE_OPENAI_ENDPOINT,
|
|
11
|
+
MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
12
|
+
MIDSCENE_AZURE_OPENAI_KEY,
|
|
13
|
+
MIDSCENE_AZURE_OPENAI_SCOPE,
|
|
14
|
+
MIDSCENE_GROUNDING_ANTHROPIC_API_KEY,
|
|
15
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_API_VERSION,
|
|
16
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_DEPLOYMENT,
|
|
17
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_ENDPOINT,
|
|
18
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
19
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_KEY,
|
|
20
|
+
MIDSCENE_GROUNDING_AZURE_OPENAI_SCOPE,
|
|
21
|
+
MIDSCENE_GROUNDING_MODEL_NAME,
|
|
22
|
+
MIDSCENE_GROUNDING_OPENAI_API_KEY,
|
|
23
|
+
MIDSCENE_GROUNDING_OPENAI_BASE_URL,
|
|
24
|
+
MIDSCENE_GROUNDING_OPENAI_HTTP_PROXY,
|
|
25
|
+
MIDSCENE_GROUNDING_OPENAI_INIT_CONFIG_JSON,
|
|
26
|
+
MIDSCENE_GROUNDING_OPENAI_SOCKS_PROXY,
|
|
27
|
+
MIDSCENE_GROUNDING_OPENAI_USE_AZURE,
|
|
28
|
+
MIDSCENE_GROUNDING_USE_ANTHROPIC_SDK,
|
|
29
|
+
MIDSCENE_GROUNDING_USE_AZURE_OPENAI,
|
|
30
|
+
MIDSCENE_GROUNDING_VL_MODE,
|
|
31
|
+
MIDSCENE_MODEL_NAME,
|
|
32
|
+
MIDSCENE_OPENAI_API_KEY,
|
|
33
|
+
MIDSCENE_OPENAI_BASE_URL,
|
|
34
|
+
MIDSCENE_OPENAI_HTTP_PROXY,
|
|
35
|
+
MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
36
|
+
MIDSCENE_OPENAI_SOCKS_PROXY,
|
|
37
|
+
MIDSCENE_OPENAI_USE_AZURE,
|
|
38
|
+
MIDSCENE_PLANNING_ANTHROPIC_API_KEY,
|
|
39
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_API_VERSION,
|
|
40
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_DEPLOYMENT,
|
|
41
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_ENDPOINT,
|
|
42
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
43
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_KEY,
|
|
44
|
+
MIDSCENE_PLANNING_AZURE_OPENAI_SCOPE,
|
|
45
|
+
MIDSCENE_PLANNING_MODEL_NAME,
|
|
46
|
+
MIDSCENE_PLANNING_OPENAI_API_KEY,
|
|
47
|
+
MIDSCENE_PLANNING_OPENAI_BASE_URL,
|
|
48
|
+
MIDSCENE_PLANNING_OPENAI_HTTP_PROXY,
|
|
49
|
+
MIDSCENE_PLANNING_OPENAI_INIT_CONFIG_JSON,
|
|
50
|
+
MIDSCENE_PLANNING_OPENAI_SOCKS_PROXY,
|
|
51
|
+
MIDSCENE_PLANNING_OPENAI_USE_AZURE,
|
|
52
|
+
MIDSCENE_PLANNING_USE_ANTHROPIC_SDK,
|
|
53
|
+
MIDSCENE_PLANNING_USE_AZURE_OPENAI,
|
|
54
|
+
MIDSCENE_PLANNING_VL_MODE,
|
|
55
|
+
MIDSCENE_USE_ANTHROPIC_SDK,
|
|
56
|
+
MIDSCENE_USE_AZURE_OPENAI,
|
|
57
|
+
MIDSCENE_VL_MODE,
|
|
58
|
+
MIDSCENE_VQA_ANTHROPIC_API_KEY,
|
|
59
|
+
MIDSCENE_VQA_AZURE_OPENAI_API_VERSION,
|
|
60
|
+
MIDSCENE_VQA_AZURE_OPENAI_DEPLOYMENT,
|
|
61
|
+
MIDSCENE_VQA_AZURE_OPENAI_ENDPOINT,
|
|
62
|
+
MIDSCENE_VQA_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
63
|
+
MIDSCENE_VQA_AZURE_OPENAI_KEY,
|
|
64
|
+
MIDSCENE_VQA_AZURE_OPENAI_SCOPE,
|
|
65
65
|
// VQA
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
MIDSCENE_VQA_MODEL_NAME,
|
|
67
|
+
MIDSCENE_VQA_OPENAI_API_KEY,
|
|
68
|
+
MIDSCENE_VQA_OPENAI_BASE_URL,
|
|
69
|
+
MIDSCENE_VQA_OPENAI_HTTP_PROXY,
|
|
70
|
+
MIDSCENE_VQA_OPENAI_INIT_CONFIG_JSON,
|
|
71
|
+
MIDSCENE_VQA_OPENAI_SOCKS_PROXY,
|
|
72
|
+
MIDSCENE_VQA_OPENAI_USE_AZURE,
|
|
73
|
+
MIDSCENE_VQA_USE_ANTHROPIC_SDK,
|
|
74
|
+
MIDSCENE_VQA_USE_AZURE_OPENAI,
|
|
75
|
+
MIDSCENE_VQA_VL_MODE,
|
|
76
76
|
OPENAI_API_KEY,
|
|
77
77
|
OPENAI_BASE_URL,
|
|
78
78
|
OPENAI_USE_AZURE,
|
|
@@ -114,175 +114,175 @@ interface IModelConfigKeys {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export const VQA_MODEL_CONFIG_KEYS: IModelConfigKeys = {
|
|
117
|
-
modelName:
|
|
117
|
+
modelName: MIDSCENE_VQA_MODEL_NAME,
|
|
118
118
|
/**
|
|
119
119
|
* proxy
|
|
120
120
|
*/
|
|
121
|
-
socksProxy:
|
|
122
|
-
httpProxy:
|
|
121
|
+
socksProxy: MIDSCENE_VQA_OPENAI_SOCKS_PROXY,
|
|
122
|
+
httpProxy: MIDSCENE_VQA_OPENAI_HTTP_PROXY,
|
|
123
123
|
/**
|
|
124
124
|
* OpenAI
|
|
125
125
|
*/
|
|
126
|
-
openaiBaseURL:
|
|
127
|
-
openaiApiKey:
|
|
128
|
-
openaiExtraConfig:
|
|
126
|
+
openaiBaseURL: MIDSCENE_VQA_OPENAI_BASE_URL,
|
|
127
|
+
openaiApiKey: MIDSCENE_VQA_OPENAI_API_KEY,
|
|
128
|
+
openaiExtraConfig: MIDSCENE_VQA_OPENAI_INIT_CONFIG_JSON,
|
|
129
129
|
/**
|
|
130
130
|
* Azure
|
|
131
131
|
*/
|
|
132
|
-
openaiUseAzureDeprecated:
|
|
133
|
-
useAzureOpenai:
|
|
134
|
-
azureOpenaiScope:
|
|
135
|
-
azureOpenaiKey:
|
|
136
|
-
azureOpenaiEndpoint:
|
|
137
|
-
azureOpenaiApiVersion:
|
|
138
|
-
azureOpenaiDeployment:
|
|
139
|
-
azureExtraConfig:
|
|
132
|
+
openaiUseAzureDeprecated: MIDSCENE_VQA_OPENAI_USE_AZURE,
|
|
133
|
+
useAzureOpenai: MIDSCENE_VQA_USE_AZURE_OPENAI,
|
|
134
|
+
azureOpenaiScope: MIDSCENE_VQA_AZURE_OPENAI_SCOPE,
|
|
135
|
+
azureOpenaiKey: MIDSCENE_VQA_AZURE_OPENAI_KEY,
|
|
136
|
+
azureOpenaiEndpoint: MIDSCENE_VQA_AZURE_OPENAI_ENDPOINT,
|
|
137
|
+
azureOpenaiApiVersion: MIDSCENE_VQA_AZURE_OPENAI_API_VERSION,
|
|
138
|
+
azureOpenaiDeployment: MIDSCENE_VQA_AZURE_OPENAI_DEPLOYMENT,
|
|
139
|
+
azureExtraConfig: MIDSCENE_VQA_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
140
140
|
/**
|
|
141
141
|
* Anthropic
|
|
142
142
|
*/
|
|
143
|
-
useAnthropicSdk:
|
|
144
|
-
anthropicApiKey:
|
|
143
|
+
useAnthropicSdk: MIDSCENE_VQA_USE_ANTHROPIC_SDK,
|
|
144
|
+
anthropicApiKey: MIDSCENE_VQA_ANTHROPIC_API_KEY,
|
|
145
145
|
/**
|
|
146
146
|
* Extra
|
|
147
147
|
*/
|
|
148
|
-
vlMode:
|
|
148
|
+
vlMode: MIDSCENE_VQA_VL_MODE,
|
|
149
149
|
} as const;
|
|
150
150
|
|
|
151
151
|
export const GROUNDING_MODEL_CONFIG_KEYS: IModelConfigKeys = {
|
|
152
|
-
modelName:
|
|
152
|
+
modelName: MIDSCENE_GROUNDING_MODEL_NAME,
|
|
153
153
|
/**
|
|
154
154
|
* proxy
|
|
155
155
|
*/
|
|
156
|
-
socksProxy:
|
|
157
|
-
httpProxy:
|
|
156
|
+
socksProxy: MIDSCENE_GROUNDING_OPENAI_SOCKS_PROXY,
|
|
157
|
+
httpProxy: MIDSCENE_GROUNDING_OPENAI_HTTP_PROXY,
|
|
158
158
|
/**
|
|
159
159
|
* OpenAI
|
|
160
160
|
*/
|
|
161
|
-
openaiBaseURL:
|
|
162
|
-
openaiApiKey:
|
|
163
|
-
openaiExtraConfig:
|
|
161
|
+
openaiBaseURL: MIDSCENE_GROUNDING_OPENAI_BASE_URL,
|
|
162
|
+
openaiApiKey: MIDSCENE_GROUNDING_OPENAI_API_KEY,
|
|
163
|
+
openaiExtraConfig: MIDSCENE_GROUNDING_OPENAI_INIT_CONFIG_JSON,
|
|
164
164
|
/**
|
|
165
165
|
* Azure
|
|
166
166
|
*/
|
|
167
|
-
openaiUseAzureDeprecated:
|
|
168
|
-
useAzureOpenai:
|
|
169
|
-
azureOpenaiScope:
|
|
170
|
-
azureOpenaiKey:
|
|
171
|
-
azureOpenaiEndpoint:
|
|
172
|
-
azureOpenaiApiVersion:
|
|
173
|
-
azureOpenaiDeployment:
|
|
174
|
-
azureExtraConfig:
|
|
167
|
+
openaiUseAzureDeprecated: MIDSCENE_GROUNDING_OPENAI_USE_AZURE,
|
|
168
|
+
useAzureOpenai: MIDSCENE_GROUNDING_USE_AZURE_OPENAI,
|
|
169
|
+
azureOpenaiScope: MIDSCENE_GROUNDING_AZURE_OPENAI_SCOPE,
|
|
170
|
+
azureOpenaiKey: MIDSCENE_GROUNDING_AZURE_OPENAI_KEY,
|
|
171
|
+
azureOpenaiEndpoint: MIDSCENE_GROUNDING_AZURE_OPENAI_ENDPOINT,
|
|
172
|
+
azureOpenaiApiVersion: MIDSCENE_GROUNDING_AZURE_OPENAI_API_VERSION,
|
|
173
|
+
azureOpenaiDeployment: MIDSCENE_GROUNDING_AZURE_OPENAI_DEPLOYMENT,
|
|
174
|
+
azureExtraConfig: MIDSCENE_GROUNDING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
175
175
|
/**
|
|
176
176
|
* Anthropic
|
|
177
177
|
*/
|
|
178
|
-
useAnthropicSdk:
|
|
179
|
-
anthropicApiKey:
|
|
178
|
+
useAnthropicSdk: MIDSCENE_GROUNDING_USE_ANTHROPIC_SDK,
|
|
179
|
+
anthropicApiKey: MIDSCENE_GROUNDING_ANTHROPIC_API_KEY,
|
|
180
180
|
/**
|
|
181
181
|
* Extra
|
|
182
182
|
*/
|
|
183
|
-
vlMode:
|
|
183
|
+
vlMode: MIDSCENE_GROUNDING_VL_MODE,
|
|
184
184
|
} as const;
|
|
185
185
|
|
|
186
186
|
export const PLANNING_MODEL_CONFIG_KEYS: IModelConfigKeys = {
|
|
187
|
-
modelName:
|
|
187
|
+
modelName: MIDSCENE_PLANNING_MODEL_NAME,
|
|
188
188
|
/**
|
|
189
189
|
* proxy
|
|
190
190
|
*/
|
|
191
|
-
socksProxy:
|
|
192
|
-
httpProxy:
|
|
191
|
+
socksProxy: MIDSCENE_PLANNING_OPENAI_SOCKS_PROXY,
|
|
192
|
+
httpProxy: MIDSCENE_PLANNING_OPENAI_HTTP_PROXY,
|
|
193
193
|
/**
|
|
194
194
|
* OpenAI
|
|
195
195
|
*/
|
|
196
|
-
openaiBaseURL:
|
|
197
|
-
openaiApiKey:
|
|
198
|
-
openaiExtraConfig:
|
|
196
|
+
openaiBaseURL: MIDSCENE_PLANNING_OPENAI_BASE_URL,
|
|
197
|
+
openaiApiKey: MIDSCENE_PLANNING_OPENAI_API_KEY,
|
|
198
|
+
openaiExtraConfig: MIDSCENE_PLANNING_OPENAI_INIT_CONFIG_JSON,
|
|
199
199
|
/**
|
|
200
200
|
* Azure
|
|
201
201
|
*/
|
|
202
|
-
openaiUseAzureDeprecated:
|
|
203
|
-
useAzureOpenai:
|
|
204
|
-
azureOpenaiScope:
|
|
205
|
-
azureOpenaiKey:
|
|
206
|
-
azureOpenaiEndpoint:
|
|
207
|
-
azureOpenaiApiVersion:
|
|
208
|
-
azureOpenaiDeployment:
|
|
209
|
-
azureExtraConfig:
|
|
202
|
+
openaiUseAzureDeprecated: MIDSCENE_PLANNING_OPENAI_USE_AZURE,
|
|
203
|
+
useAzureOpenai: MIDSCENE_PLANNING_USE_AZURE_OPENAI,
|
|
204
|
+
azureOpenaiScope: MIDSCENE_PLANNING_AZURE_OPENAI_SCOPE,
|
|
205
|
+
azureOpenaiKey: MIDSCENE_PLANNING_AZURE_OPENAI_KEY,
|
|
206
|
+
azureOpenaiEndpoint: MIDSCENE_PLANNING_AZURE_OPENAI_ENDPOINT,
|
|
207
|
+
azureOpenaiApiVersion: MIDSCENE_PLANNING_AZURE_OPENAI_API_VERSION,
|
|
208
|
+
azureOpenaiDeployment: MIDSCENE_PLANNING_AZURE_OPENAI_DEPLOYMENT,
|
|
209
|
+
azureExtraConfig: MIDSCENE_PLANNING_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
210
210
|
/**
|
|
211
211
|
* Anthropic
|
|
212
212
|
*/
|
|
213
|
-
useAnthropicSdk:
|
|
214
|
-
anthropicApiKey:
|
|
213
|
+
useAnthropicSdk: MIDSCENE_PLANNING_USE_ANTHROPIC_SDK,
|
|
214
|
+
anthropicApiKey: MIDSCENE_PLANNING_ANTHROPIC_API_KEY,
|
|
215
215
|
/**
|
|
216
216
|
* Extra
|
|
217
217
|
*/
|
|
218
|
-
vlMode:
|
|
218
|
+
vlMode: MIDSCENE_PLANNING_VL_MODE,
|
|
219
219
|
} as const;
|
|
220
220
|
|
|
221
221
|
// modelConfig return default
|
|
222
222
|
export const DEFAULT_MODEL_CONFIG_KEYS: IModelConfigKeys = {
|
|
223
|
-
modelName:
|
|
223
|
+
modelName: MIDSCENE_MODEL_NAME,
|
|
224
224
|
/**
|
|
225
225
|
* proxy
|
|
226
226
|
*/
|
|
227
|
-
socksProxy:
|
|
228
|
-
httpProxy:
|
|
227
|
+
socksProxy: MIDSCENE_OPENAI_SOCKS_PROXY,
|
|
228
|
+
httpProxy: MIDSCENE_OPENAI_HTTP_PROXY,
|
|
229
229
|
/**
|
|
230
230
|
* OpenAI
|
|
231
231
|
*/
|
|
232
|
-
openaiBaseURL:
|
|
233
|
-
openaiApiKey:
|
|
234
|
-
openaiExtraConfig:
|
|
232
|
+
openaiBaseURL: MIDSCENE_OPENAI_BASE_URL,
|
|
233
|
+
openaiApiKey: MIDSCENE_OPENAI_API_KEY,
|
|
234
|
+
openaiExtraConfig: MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
235
235
|
/**
|
|
236
236
|
* Azure
|
|
237
237
|
*/
|
|
238
|
-
openaiUseAzureDeprecated:
|
|
239
|
-
useAzureOpenai:
|
|
240
|
-
azureOpenaiScope:
|
|
241
|
-
azureOpenaiKey:
|
|
242
|
-
azureOpenaiEndpoint:
|
|
243
|
-
azureOpenaiApiVersion:
|
|
244
|
-
azureOpenaiDeployment:
|
|
245
|
-
azureExtraConfig:
|
|
238
|
+
openaiUseAzureDeprecated: MIDSCENE_OPENAI_USE_AZURE,
|
|
239
|
+
useAzureOpenai: MIDSCENE_USE_AZURE_OPENAI,
|
|
240
|
+
azureOpenaiScope: MIDSCENE_AZURE_OPENAI_SCOPE,
|
|
241
|
+
azureOpenaiKey: MIDSCENE_AZURE_OPENAI_KEY,
|
|
242
|
+
azureOpenaiEndpoint: MIDSCENE_AZURE_OPENAI_ENDPOINT,
|
|
243
|
+
azureOpenaiApiVersion: MIDSCENE_AZURE_OPENAI_API_VERSION,
|
|
244
|
+
azureOpenaiDeployment: MIDSCENE_AZURE_OPENAI_DEPLOYMENT,
|
|
245
|
+
azureExtraConfig: MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
246
246
|
/**
|
|
247
247
|
* Anthropic
|
|
248
248
|
*/
|
|
249
|
-
useAnthropicSdk:
|
|
250
|
-
anthropicApiKey:
|
|
249
|
+
useAnthropicSdk: MIDSCENE_USE_ANTHROPIC_SDK,
|
|
250
|
+
anthropicApiKey: MIDSCENE_ANTHROPIC_API_KEY,
|
|
251
251
|
/**
|
|
252
252
|
* Extra
|
|
253
253
|
*/
|
|
254
|
-
vlMode:
|
|
254
|
+
vlMode: MIDSCENE_VL_MODE,
|
|
255
255
|
} as const;
|
|
256
256
|
|
|
257
257
|
// read from process.env
|
|
258
258
|
export const DEFAULT_MODEL_CONFIG_KEYS_LEGACY: IModelConfigKeys = {
|
|
259
|
-
modelName:
|
|
259
|
+
modelName: MIDSCENE_MODEL_NAME,
|
|
260
260
|
/**
|
|
261
261
|
* proxy
|
|
262
262
|
*/
|
|
263
|
-
socksProxy:
|
|
264
|
-
httpProxy:
|
|
263
|
+
socksProxy: MIDSCENE_OPENAI_SOCKS_PROXY,
|
|
264
|
+
httpProxy: MIDSCENE_OPENAI_HTTP_PROXY,
|
|
265
265
|
/**
|
|
266
266
|
* OpenAI
|
|
267
267
|
*/
|
|
268
268
|
openaiBaseURL: OPENAI_BASE_URL,
|
|
269
269
|
openaiApiKey: OPENAI_API_KEY,
|
|
270
|
-
openaiExtraConfig:
|
|
270
|
+
openaiExtraConfig: MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
271
271
|
/**
|
|
272
272
|
* Azure
|
|
273
273
|
*/
|
|
274
274
|
openaiUseAzureDeprecated: OPENAI_USE_AZURE,
|
|
275
|
-
useAzureOpenai:
|
|
276
|
-
azureOpenaiScope:
|
|
275
|
+
useAzureOpenai: MIDSCENE_USE_AZURE_OPENAI,
|
|
276
|
+
azureOpenaiScope: MIDSCENE_AZURE_OPENAI_SCOPE,
|
|
277
277
|
azureOpenaiKey: AZURE_OPENAI_KEY,
|
|
278
278
|
azureOpenaiEndpoint: AZURE_OPENAI_ENDPOINT,
|
|
279
279
|
azureOpenaiApiVersion: AZURE_OPENAI_API_VERSION,
|
|
280
280
|
azureOpenaiDeployment: AZURE_OPENAI_DEPLOYMENT,
|
|
281
|
-
azureExtraConfig:
|
|
281
|
+
azureExtraConfig: MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
|
|
282
282
|
/**
|
|
283
283
|
* Anthropic
|
|
284
284
|
*/
|
|
285
|
-
useAnthropicSdk:
|
|
285
|
+
useAnthropicSdk: MIDSCENE_USE_ANTHROPIC_SDK,
|
|
286
286
|
anthropicApiKey: ANTHROPIC_API_KEY,
|
|
287
287
|
/**
|
|
288
288
|
* Extra
|
|
@@ -284,7 +284,7 @@ export const decideModelConfigFromEnv = (
|
|
|
284
284
|
|
|
285
285
|
debugLog(`decideModelConfig as legacy logic with intent ${intent}.`);
|
|
286
286
|
|
|
287
|
-
// TODO: when fallback to legacy logic, prefer to read
|
|
287
|
+
// TODO: when fallback to legacy logic, prefer to read MIDSCENE_OPENAI_API_KEY rather than OPENAI_API_KEY
|
|
288
288
|
const result = decideOpenaiSdkConfig({
|
|
289
289
|
keys: DEFAULT_MODEL_CONFIG_KEYS_LEGACY,
|
|
290
290
|
provider: allEnvConfig,
|
|
@@ -67,7 +67,7 @@ export class GlobalConfigManager {
|
|
|
67
67
|
}
|
|
68
68
|
if (key === MATCH_BY_POSITION) {
|
|
69
69
|
throw new Error(
|
|
70
|
-
'MATCH_BY_POSITION is deprecated, use
|
|
70
|
+
'MATCH_BY_POSITION is deprecated, use MIDSCENE_USE_VL_MODEL instead',
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
const value = allConfig[key];
|
package/src/env/init-debug.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { enableDebug } from '../logger';
|
|
2
2
|
import { getBasicEnvValue } from './basic';
|
|
3
|
-
import {
|
|
3
|
+
import { MIDSCENE_DEBUG_AI_PROFILE, MIDSCENE_DEBUG_AI_RESPONSE } from './types';
|
|
4
4
|
|
|
5
5
|
export const initDebugConfig = () => {
|
|
6
|
-
const shouldPrintTiming = getBasicEnvValue(
|
|
6
|
+
const shouldPrintTiming = getBasicEnvValue(MIDSCENE_DEBUG_AI_PROFILE);
|
|
7
7
|
let debugConfig = '';
|
|
8
8
|
if (shouldPrintTiming) {
|
|
9
9
|
console.warn(
|
|
10
|
-
'
|
|
10
|
+
'MIDSCENE_DEBUG_AI_PROFILE is deprecated, use DEBUG=midscene:ai:profile instead',
|
|
11
11
|
);
|
|
12
12
|
debugConfig = 'ai:profile';
|
|
13
13
|
}
|
|
14
|
-
const shouldPrintAIResponse = getBasicEnvValue(
|
|
14
|
+
const shouldPrintAIResponse = getBasicEnvValue(MIDSCENE_DEBUG_AI_RESPONSE);
|
|
15
15
|
|
|
16
16
|
if (shouldPrintAIResponse) {
|
|
17
17
|
console.warn(
|
|
18
|
-
'
|
|
18
|
+
'MIDSCENE_DEBUG_AI_RESPONSE is deprecated, use DEBUG=midscene:ai:response instead',
|
|
19
19
|
);
|
|
20
20
|
if (debugConfig) {
|
|
21
21
|
debugConfig = 'ai:*';
|
|
@@ -138,7 +138,7 @@ export class ModelConfigManager {
|
|
|
138
138
|
|
|
139
139
|
if (!modelConfig.vlMode) {
|
|
140
140
|
throw new Error(
|
|
141
|
-
'No visual language model (VL model) detected for the current scenario. Element localization may be inaccurate. Please verify your model configuration. Learn more: https://
|
|
141
|
+
'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',
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
144
|
}
|
package/src/env/parse.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
MIDSCENE_USE_DOUBAO_VISION,
|
|
3
|
+
MIDSCENE_USE_GEMINI,
|
|
4
|
+
MIDSCENE_USE_QWEN3_VL,
|
|
5
|
+
MIDSCENE_USE_QWEN_VL,
|
|
6
|
+
MIDSCENE_USE_VLM_UI_TARS,
|
|
7
7
|
type TVlModeTypes,
|
|
8
8
|
type TVlModeValues,
|
|
9
9
|
UITarsModelVersion,
|
|
@@ -57,18 +57,18 @@ export const parseVlModeAndUiTarsFromGlobalConfig = (
|
|
|
57
57
|
vlMode?: TVlModeTypes;
|
|
58
58
|
uiTarsVersion?: UITarsModelVersion;
|
|
59
59
|
} => {
|
|
60
|
-
const isDoubao = provider[
|
|
61
|
-
const isQwen = provider[
|
|
62
|
-
const isQwen3 = provider[
|
|
63
|
-
const isUiTars = provider[
|
|
64
|
-
const isGemini = provider[
|
|
60
|
+
const isDoubao = provider[MIDSCENE_USE_DOUBAO_VISION];
|
|
61
|
+
const isQwen = provider[MIDSCENE_USE_QWEN_VL];
|
|
62
|
+
const isQwen3 = provider[MIDSCENE_USE_QWEN3_VL];
|
|
63
|
+
const isUiTars = provider[MIDSCENE_USE_VLM_UI_TARS];
|
|
64
|
+
const isGemini = provider[MIDSCENE_USE_GEMINI];
|
|
65
65
|
|
|
66
66
|
const enabledModes = [
|
|
67
|
-
isDoubao &&
|
|
68
|
-
isQwen &&
|
|
69
|
-
isQwen3 &&
|
|
70
|
-
isUiTars &&
|
|
71
|
-
isGemini &&
|
|
67
|
+
isDoubao && MIDSCENE_USE_DOUBAO_VISION,
|
|
68
|
+
isQwen && MIDSCENE_USE_QWEN_VL,
|
|
69
|
+
isQwen3 && MIDSCENE_USE_QWEN3_VL,
|
|
70
|
+
isUiTars && MIDSCENE_USE_VLM_UI_TARS,
|
|
71
|
+
isGemini && MIDSCENE_USE_GEMINI,
|
|
72
72
|
].filter(Boolean);
|
|
73
73
|
|
|
74
74
|
if (enabledModes.length > 1) {
|