@midscene/shared 0.27.3-beta-20250825120123.0 → 0.27.3
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/dist/es/common.mjs +3 -2
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/global-config.mjs +112 -61
- package/dist/es/env/helper.mjs +1 -18
- package/dist/es/env/index.mjs +1 -3
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config.mjs +12 -16
- package/dist/es/env/types.mjs +35 -14
- package/dist/es/env/utils.mjs +34 -24
- package/dist/lib/common.js +3 -2
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/global-config.js +116 -62
- package/dist/lib/env/helper.js +0 -20
- package/dist/lib/env/index.js +9 -27
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config.js +13 -17
- package/dist/lib/env/types.js +60 -18
- package/dist/lib/env/utils.js +35 -31
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/global-config.d.ts +31 -12
- package/dist/types/env/helper.d.ts +0 -1
- package/dist/types/env/index.d.ts +0 -2
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config.d.ts +6 -2
- package/dist/types/env/types.d.ts +26 -2
- package/dist/types/env/utils.d.ts +4 -5
- package/package.json +1 -1
- package/src/common.ts +5 -2
- package/src/env/basic.ts +12 -0
- package/src/env/global-config.ts +195 -70
- package/src/env/helper.ts +0 -33
- package/src/env/index.ts +0 -2
- package/src/env/init-debug.ts +29 -0
- package/src/env/model-config.ts +31 -41
- package/src/env/parse.ts +0 -1
- package/src/env/types.ts +57 -14
- package/src/env/utils.ts +67 -43
package/dist/es/common.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import node_path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { getBasicEnvValue } from "./env/basic.mjs";
|
|
5
|
+
import { MIDSCENE_RUN_DIR } from "./env/types.mjs";
|
|
5
6
|
import { ifInNode } from "./utils.mjs";
|
|
6
7
|
const defaultRunDirName = 'midscene_run';
|
|
7
8
|
const getMidsceneRunDir = ()=>{
|
|
8
9
|
if (!ifInNode) return '';
|
|
9
|
-
return
|
|
10
|
+
return getBasicEnvValue(MIDSCENE_RUN_DIR) || defaultRunDirName;
|
|
10
11
|
};
|
|
11
12
|
const getMidsceneRunBaseDir = ()=>{
|
|
12
13
|
if (!ifInNode) return '';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDebug } from "../logger.mjs";
|
|
2
|
+
import { initDebugConfig } from "./init-debug.mjs";
|
|
3
|
+
import { decideModelConfig } from "./model-config.mjs";
|
|
4
|
+
import { ALL_ENV_KEYS, BOOLEAN_ENV_KEYS, GLOBAL_ENV_KEYS, MATCH_BY_POSITION, MODEL_ENV_KEYS, NUMBER_ENV_KEYS, STRING_ENV_KEYS } from "./types.mjs";
|
|
2
5
|
function _define_property(obj, key, value) {
|
|
3
6
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
7
|
value: value,
|
|
@@ -9,13 +12,45 @@ function _define_property(obj, key, value) {
|
|
|
9
12
|
else obj[key] = value;
|
|
10
13
|
return obj;
|
|
11
14
|
}
|
|
12
|
-
const allConfigFromEnv = ()=>
|
|
15
|
+
const allConfigFromEnv = ()=>ALL_ENV_KEYS.reduce((p, name)=>({
|
|
13
16
|
...p,
|
|
14
17
|
[name]: process.env[name]
|
|
15
18
|
}), Object.create(null));
|
|
19
|
+
const GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG = 'GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG';
|
|
16
20
|
class GlobalConfigManager {
|
|
21
|
+
initAllEnvConfig() {
|
|
22
|
+
const envConfig = allConfigFromEnv();
|
|
23
|
+
this.allConfig = (()=>{
|
|
24
|
+
if (this.override) {
|
|
25
|
+
this.debugLog('initAllConfig with override from overrideAIConfig');
|
|
26
|
+
const { newConfig, extendMode } = this.override;
|
|
27
|
+
if (extendMode) {
|
|
28
|
+
this.debugLog('initAllConfig with extend mode from overrideAIConfig');
|
|
29
|
+
return {
|
|
30
|
+
...envConfig,
|
|
31
|
+
...newConfig
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
this.debugLog('initAllConfig without override mode from overrideAIConfig');
|
|
35
|
+
return {
|
|
36
|
+
...newConfig
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
this.debugLog('initAllConfig without override from overrideAIConfig');
|
|
40
|
+
return envConfig;
|
|
41
|
+
})();
|
|
42
|
+
}
|
|
43
|
+
createUninitializedError(message) {
|
|
44
|
+
const error = new Error(message);
|
|
45
|
+
error[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG] = true;
|
|
46
|
+
return error;
|
|
47
|
+
}
|
|
17
48
|
reset() {
|
|
49
|
+
console.warn('globalConfigManager.reset should only be called in Midscene owner unit test');
|
|
50
|
+
this.initialized = false;
|
|
18
51
|
this.override = void 0;
|
|
52
|
+
this.allConfig = void 0;
|
|
53
|
+
this.keysHaveBeenRead = {};
|
|
19
54
|
this.modelConfigByIntent = {
|
|
20
55
|
VQA: void 0,
|
|
21
56
|
default: void 0,
|
|
@@ -23,86 +58,102 @@ class GlobalConfigManager {
|
|
|
23
58
|
planning: void 0
|
|
24
59
|
};
|
|
25
60
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
61
|
+
init(modelConfigFn) {
|
|
62
|
+
if (this.initialized) throw new Error('GlobalConfigManager.init should be called only once');
|
|
63
|
+
const intents = [
|
|
64
|
+
'VQA',
|
|
65
|
+
'default',
|
|
66
|
+
'grounding',
|
|
67
|
+
'planning'
|
|
68
|
+
];
|
|
69
|
+
this.initAllEnvConfig();
|
|
70
|
+
const intentConfigFromFn = {
|
|
71
|
+
VQA: void 0,
|
|
72
|
+
default: void 0,
|
|
73
|
+
grounding: void 0,
|
|
74
|
+
planning: void 0
|
|
75
|
+
};
|
|
76
|
+
if (modelConfigFn) for (const i of intents){
|
|
77
|
+
const result = modelConfigFn({
|
|
78
|
+
intent: i
|
|
79
|
+
});
|
|
80
|
+
if (!result) throw new Error(`The agent has an option named modelConfig is a function, but it return ${result} when call with intent ${i}, which should be a object.`);
|
|
81
|
+
intentConfigFromFn[i] = result;
|
|
37
82
|
}
|
|
83
|
+
for (const i of intents){
|
|
84
|
+
const result = decideModelConfig({
|
|
85
|
+
intent: i,
|
|
86
|
+
allConfig: this.allConfig,
|
|
87
|
+
modelConfigFromFn: intentConfigFromFn[i]
|
|
88
|
+
});
|
|
89
|
+
this.modelConfigByIntent[i] = result;
|
|
90
|
+
}
|
|
91
|
+
this.initialized = true;
|
|
92
|
+
}
|
|
93
|
+
getModelConfigByIntent(intent) {
|
|
94
|
+
if (!this.initialized) throw this.createUninitializedError(`globalConfigManager is not initialized when call getModelConfigByIntent with intent ${intent}`);
|
|
95
|
+
return this.modelConfigByIntent[intent];
|
|
38
96
|
}
|
|
39
|
-
|
|
97
|
+
getEnvConfigValue(key) {
|
|
98
|
+
const allConfig = this.allConfig || process.env;
|
|
99
|
+
if (!STRING_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigValue with key ${key} is not supported.`);
|
|
40
100
|
if (key === MATCH_BY_POSITION) throw new Error('MATCH_BY_POSITION is deprecated, use MIDSCENE_USE_VL_MODEL instead');
|
|
41
|
-
const value =
|
|
101
|
+
const value = allConfig[key];
|
|
102
|
+
this.keysHaveBeenRead[key] = true;
|
|
42
103
|
if ('string' == typeof value) return value.trim();
|
|
43
104
|
return value;
|
|
44
105
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
106
|
+
getEnvConfigInNumber(key) {
|
|
107
|
+
const allConfig = this.allConfig || process.env;
|
|
108
|
+
if (!NUMBER_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigInNumber with key ${key} is not supported`);
|
|
109
|
+
const value = allConfig[key];
|
|
110
|
+
this.keysHaveBeenRead[key] = true;
|
|
111
|
+
return Number(value || '');
|
|
112
|
+
}
|
|
113
|
+
getEnvConfigInBoolean(key) {
|
|
114
|
+
const allConfig = this.allConfig || process.env;
|
|
115
|
+
if (!BOOLEAN_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigInBoolean with key ${key} is not supported`);
|
|
116
|
+
const value = allConfig[key];
|
|
117
|
+
this.keysHaveBeenRead[key] = true;
|
|
47
118
|
if (!value) return false;
|
|
48
119
|
if (/^(true|1)$/i.test(value)) return true;
|
|
49
120
|
if (/^(false|0)$/i.test(value)) return false;
|
|
50
121
|
return !!value.trim();
|
|
51
122
|
}
|
|
52
|
-
getConfigValueInNumber(key) {
|
|
53
|
-
const value = this.getAllConfig()[key];
|
|
54
|
-
return Number(value || '');
|
|
55
|
-
}
|
|
56
|
-
getConfigValueInJson(key) {
|
|
57
|
-
const config = this.getConfigValue(key);
|
|
58
|
-
try {
|
|
59
|
-
return config ? JSON.parse(config) : void 0;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
throw new Error(`Failed to parse json config: ${key}. ${error.message}`, {
|
|
62
|
-
cause: error
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
123
|
registerOverride(newConfig, extendMode = false) {
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
124
|
+
if (this.initialized) throw new Error('overrideAIConfig must be called before Agent.constructor');
|
|
125
|
+
for(const key in newConfig){
|
|
126
|
+
if (![
|
|
127
|
+
...GLOBAL_ENV_KEYS,
|
|
128
|
+
...MODEL_ENV_KEYS
|
|
129
|
+
].includes(key)) throw new Error(`Failed to override AI config, invalid key: ${key}`);
|
|
130
|
+
const value = newConfig[key];
|
|
131
|
+
if ('string' != typeof value) throw new Error(`Failed to override AI config, value for key ${key} must be a string, but got with type ${typeof value}`);
|
|
132
|
+
if (this.keysHaveBeenRead[key]) console.warn(`Warning: try to override AI config with key ${key} ,but it has been read.`);
|
|
133
|
+
}
|
|
72
134
|
this.override = {
|
|
73
|
-
newConfig:
|
|
135
|
+
newConfig: {
|
|
136
|
+
...newConfig
|
|
137
|
+
},
|
|
74
138
|
extendMode
|
|
75
139
|
};
|
|
76
|
-
|
|
77
|
-
getModelConfigFromFn(intent) {
|
|
78
|
-
return this.modelConfigByIntent[intent];
|
|
79
|
-
}
|
|
80
|
-
registerModelConfigFn(modelConfigFn) {
|
|
81
|
-
if ('function' != typeof modelConfigFn) throw new Error(`modelConfigFn must be a function when registerModelConfigFn, but got with type ${typeof modelConfigFn}`);
|
|
82
|
-
const intents = [
|
|
83
|
-
'VQA',
|
|
84
|
-
'default',
|
|
85
|
-
'grounding',
|
|
86
|
-
'planning'
|
|
87
|
-
];
|
|
88
|
-
for (const i of intents){
|
|
89
|
-
const result = modelConfigFn({
|
|
90
|
-
intent: i
|
|
91
|
-
});
|
|
92
|
-
if (!result) throw new Error(`The agent has an option named modelConfig is a function, but it return ${result} when call with intent ${i}, which should be a object.`);
|
|
93
|
-
this.modelConfigByIntent[i] = result;
|
|
94
|
-
}
|
|
140
|
+
this.initAllEnvConfig();
|
|
95
141
|
}
|
|
96
142
|
constructor(){
|
|
97
143
|
_define_property(this, "override", void 0);
|
|
98
|
-
_define_property(this, "
|
|
99
|
-
this
|
|
144
|
+
_define_property(this, "initialized", false);
|
|
145
|
+
_define_property(this, "debugLog", void 0);
|
|
146
|
+
_define_property(this, "modelConfigByIntent", {
|
|
100
147
|
VQA: void 0,
|
|
101
148
|
default: void 0,
|
|
102
149
|
grounding: void 0,
|
|
103
150
|
planning: void 0
|
|
104
|
-
};
|
|
151
|
+
});
|
|
152
|
+
_define_property(this, "allConfig", void 0);
|
|
153
|
+
_define_property(this, "keysHaveBeenRead", {});
|
|
154
|
+
initDebugConfig();
|
|
155
|
+
const debugLog = getDebug('ai:global-config');
|
|
156
|
+
this.debugLog = debugLog;
|
|
105
157
|
}
|
|
106
158
|
}
|
|
107
|
-
|
|
108
|
-
export { globalConfigManger };
|
|
159
|
+
export { GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG, GlobalConfigManager };
|
package/dist/es/env/helper.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { enableDebug } from "../logger.mjs";
|
|
2
1
|
import { assert } from "../utils.mjs";
|
|
3
|
-
import { globalConfigManger } from "./global-config.mjs";
|
|
4
|
-
import { MIDSCENE_DEBUG_AI_PROFILE, MIDSCENE_DEBUG_AI_RESPONSE } from "./types.mjs";
|
|
5
2
|
const maskKey = (key, maskChar = '*')=>{
|
|
6
3
|
if ('string' != typeof key || 0 === key.length) return key;
|
|
7
4
|
const prefixLen = 3;
|
|
@@ -35,20 +32,6 @@ const maskConfig = (config)=>Object.fromEntries(Object.entries(config).map(([key
|
|
|
35
32
|
value
|
|
36
33
|
];
|
|
37
34
|
}));
|
|
38
|
-
const initDebugConfig = ()=>{
|
|
39
|
-
const shouldPrintTiming = globalConfigManger.getConfigValueInBoolean(MIDSCENE_DEBUG_AI_PROFILE);
|
|
40
|
-
let debugConfig = '';
|
|
41
|
-
if (shouldPrintTiming) {
|
|
42
|
-
console.warn('MIDSCENE_DEBUG_AI_PROFILE is deprecated, use DEBUG=midscene:ai:profile instead');
|
|
43
|
-
debugConfig = 'ai:profile';
|
|
44
|
-
}
|
|
45
|
-
const shouldPrintAIResponse = globalConfigManger.getConfigValueInBoolean(MIDSCENE_DEBUG_AI_RESPONSE);
|
|
46
|
-
if (shouldPrintAIResponse) {
|
|
47
|
-
console.warn('MIDSCENE_DEBUG_AI_RESPONSE is deprecated, use DEBUG=midscene:ai:response instead');
|
|
48
|
-
debugConfig = debugConfig ? 'ai:*' : 'ai:call';
|
|
49
|
-
}
|
|
50
|
-
if (debugConfig) enableDebug(debugConfig);
|
|
51
|
-
};
|
|
52
35
|
const parseJson = (key, value)=>{
|
|
53
36
|
if (value) try {
|
|
54
37
|
return JSON.parse(value);
|
|
@@ -62,4 +45,4 @@ const createAssert = (modelNameKey, provider, modelName)=>(value, key, modelVend
|
|
|
62
45
|
if (modelName) modelVendorFlag ? assert(value, `The ${key} must be a non-empty string because of the ${modelNameKey} is declared as ${modelName} and ${modelVendorFlag} has also been specified in ${provider}, but got: ${value}. Please check your config.`) : assert(value, `The ${key} must be a non-empty string because of the ${modelNameKey} is declared as ${modelName} in ${provider}, but got: ${value}. Please check your config.`);
|
|
63
46
|
else assert(value, `The ${key} must be a non-empty string, but got: ${value}. Please check your config.`);
|
|
64
47
|
};
|
|
65
|
-
export { createAssert,
|
|
48
|
+
export { createAssert, maskConfig, parseJson };
|
package/dist/es/env/index.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { globalConfigManger } from "./global-config.mjs";
|
|
2
|
-
import { decideModelConfig } from "./model-config.mjs";
|
|
3
1
|
import { UITarsModelVersion } from "./parse.mjs";
|
|
4
2
|
export * from "./utils.mjs";
|
|
5
3
|
export * from "./types.mjs";
|
|
6
|
-
export { UITarsModelVersion
|
|
4
|
+
export { UITarsModelVersion };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { enableDebug } from "../logger.mjs";
|
|
2
|
+
import { getBasicEnvValue } from "./basic.mjs";
|
|
3
|
+
import { MIDSCENE_DEBUG_AI_PROFILE, MIDSCENE_DEBUG_AI_RESPONSE } from "./types.mjs";
|
|
4
|
+
const initDebugConfig = ()=>{
|
|
5
|
+
const shouldPrintTiming = getBasicEnvValue(MIDSCENE_DEBUG_AI_PROFILE);
|
|
6
|
+
let debugConfig = '';
|
|
7
|
+
if (shouldPrintTiming) {
|
|
8
|
+
console.warn('MIDSCENE_DEBUG_AI_PROFILE is deprecated, use DEBUG=midscene:ai:profile instead');
|
|
9
|
+
debugConfig = 'ai:profile';
|
|
10
|
+
}
|
|
11
|
+
const shouldPrintAIResponse = getBasicEnvValue(MIDSCENE_DEBUG_AI_RESPONSE);
|
|
12
|
+
if (shouldPrintAIResponse) {
|
|
13
|
+
console.warn('MIDSCENE_DEBUG_AI_RESPONSE is deprecated, use DEBUG=midscene:ai:response instead');
|
|
14
|
+
debugConfig = debugConfig ? 'ai:*' : 'ai:call';
|
|
15
|
+
}
|
|
16
|
+
if (debugConfig) enableDebug(debugConfig);
|
|
17
|
+
};
|
|
18
|
+
export { initDebugConfig };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { globalConfigManger } from "./global-config.mjs";
|
|
2
1
|
import { DEFAULT_MODEL_CONFIG_KEYS, DEFAULT_MODEL_CONFIG_KEYS_LEGACY, GROUNDING_MODEL_CONFIG_KEYS, PLANNING_MODEL_CONFIG_KEYS, VQA_MODEL_CONFIG_KEYS } from "./constants.mjs";
|
|
3
2
|
import { getDebug } from "../logger.mjs";
|
|
4
3
|
import { assert } from "../utils.mjs";
|
|
5
|
-
import { createAssert,
|
|
4
|
+
import { createAssert, maskConfig, parseJson } from "./helper.mjs";
|
|
5
|
+
import { initDebugConfig } from "./init-debug.mjs";
|
|
6
6
|
import { parseVlModeAndUiTarsFromGlobalConfig, parseVlModeAndUiTarsFromRaw } from "./parse.mjs";
|
|
7
7
|
const KEYS_MAP = {
|
|
8
8
|
VQA: VQA_MODEL_CONFIG_KEYS,
|
|
@@ -12,7 +12,7 @@ const KEYS_MAP = {
|
|
|
12
12
|
};
|
|
13
13
|
const decideOpenaiSdkConfig = ({ keys, provider, valueAssert })=>{
|
|
14
14
|
initDebugConfig();
|
|
15
|
-
const debugLog = getDebug('ai:
|
|
15
|
+
const debugLog = getDebug('ai:globalConfig');
|
|
16
16
|
const socksProxy = provider[keys.socksProxy];
|
|
17
17
|
const httpProxy = provider[keys.httpProxy];
|
|
18
18
|
const vlMode = provider[keys.vlMode];
|
|
@@ -91,12 +91,9 @@ const getModelDescription = (vlMode, uiTarsVersion)=>{
|
|
|
91
91
|
else return `${vlMode} mode`;
|
|
92
92
|
return '';
|
|
93
93
|
};
|
|
94
|
-
const decideModelConfig = (
|
|
94
|
+
const decideModelConfig = ({ intent, modelConfigFromFn, allConfig })=>{
|
|
95
95
|
initDebugConfig();
|
|
96
|
-
const debugLog = getDebug('ai:
|
|
97
|
-
debugLog('modelPreferences', modelPreferences);
|
|
98
|
-
const { intent } = modelPreferences;
|
|
99
|
-
const modelConfigFromFn = globalConfigManger.getModelConfigFromFn(intent);
|
|
96
|
+
const debugLog = getDebug('ai:globalConfig');
|
|
100
97
|
if (modelConfigFromFn) {
|
|
101
98
|
debugLog('decideModelConfig base on agent.modelConfig()');
|
|
102
99
|
const keysForFn = KEYS_MAP[intent];
|
|
@@ -108,13 +105,13 @@ const decideModelConfig = (modelPreferences, withAssert)=>{
|
|
|
108
105
|
return keysForFn;
|
|
109
106
|
}
|
|
110
107
|
debugLog('query modelConfig from fn by intent got no corresponding modelName, will get other keys by default');
|
|
111
|
-
|
|
108
|
+
assert(modelConfigFromFn[DEFAULT_MODEL_CONFIG_KEYS.modelName], `The return value of agent.modelConfig do not have a valid value with key ${DEFAULT_MODEL_CONFIG_KEYS.modelName}.`);
|
|
112
109
|
return DEFAULT_MODEL_CONFIG_KEYS;
|
|
113
110
|
})();
|
|
114
111
|
const result = decideOpenaiSdkConfig({
|
|
115
112
|
keys: chosenKeys,
|
|
116
113
|
provider: modelConfigFromFn,
|
|
117
|
-
valueAssert:
|
|
114
|
+
valueAssert: createAssert(chosenKeys.modelName, 'modelConfig', candidateModelNameFromConfig)
|
|
118
115
|
});
|
|
119
116
|
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromRaw(result.vlModeRaw);
|
|
120
117
|
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
@@ -126,10 +123,9 @@ const decideModelConfig = (modelPreferences, withAssert)=>{
|
|
|
126
123
|
modelDescription,
|
|
127
124
|
from: 'modelConfig'
|
|
128
125
|
};
|
|
129
|
-
debugLog(
|
|
126
|
+
debugLog(`decideModelConfig result by agent.modelConfig() with intent ${intent}:`, maskConfig(finalResult));
|
|
130
127
|
return finalResult;
|
|
131
128
|
}
|
|
132
|
-
const allConfig = globalConfigManger.getAllConfig();
|
|
133
129
|
const keysForEnv = 'default' === intent ? DEFAULT_MODEL_CONFIG_KEYS_LEGACY : KEYS_MAP[intent];
|
|
134
130
|
const candidateModelNameFromEnv = allConfig[keysForEnv.modelName];
|
|
135
131
|
debugLog(`Get value of ${keysForEnv.modelName} from globalConfig`, candidateModelNameFromEnv);
|
|
@@ -139,7 +135,7 @@ const decideModelConfig = (modelPreferences, withAssert)=>{
|
|
|
139
135
|
const result = decideOpenaiSdkConfig({
|
|
140
136
|
keys: keysForEnv,
|
|
141
137
|
provider: allConfig,
|
|
142
|
-
valueAssert:
|
|
138
|
+
valueAssert: createAssert(keysForEnv.modelName, 'process.env', modelName)
|
|
143
139
|
});
|
|
144
140
|
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromRaw(result.vlModeRaw);
|
|
145
141
|
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
@@ -151,14 +147,14 @@ const decideModelConfig = (modelPreferences, withAssert)=>{
|
|
|
151
147
|
modelDescription,
|
|
152
148
|
from: 'env'
|
|
153
149
|
};
|
|
154
|
-
debugLog(
|
|
150
|
+
debugLog(`decideModelConfig result by process.env with intent ${intent}:`, maskConfig(finalResult));
|
|
155
151
|
return finalResult;
|
|
156
152
|
}
|
|
157
153
|
debugLog(`decideModelConfig as legacy logic with intent ${intent}.`);
|
|
158
154
|
const result = decideOpenaiSdkConfig({
|
|
159
155
|
keys: DEFAULT_MODEL_CONFIG_KEYS_LEGACY,
|
|
160
156
|
provider: allConfig,
|
|
161
|
-
valueAssert:
|
|
157
|
+
valueAssert: createAssert(DEFAULT_MODEL_CONFIG_KEYS_LEGACY.modelName, 'process.env')
|
|
162
158
|
});
|
|
163
159
|
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromGlobalConfig(allConfig);
|
|
164
160
|
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
@@ -170,7 +166,7 @@ const decideModelConfig = (modelPreferences, withAssert)=>{
|
|
|
170
166
|
modelDescription,
|
|
171
167
|
from: 'legacy-env'
|
|
172
168
|
};
|
|
173
|
-
debugLog(
|
|
169
|
+
debugLog(`decideModelConfig result by legacy logic with intent ${intent}:`, maskConfig(finalResult));
|
|
174
170
|
return finalResult;
|
|
175
171
|
};
|
|
176
172
|
export { decideModelConfig, decideOpenaiSdkConfig };
|
package/dist/es/env/types.mjs
CHANGED
|
@@ -102,29 +102,44 @@ const MIDSCENE_GROUNDING_USE_ANTHROPIC_SDK = 'MIDSCENE_GROUNDING_USE_ANTHROPIC_S
|
|
|
102
102
|
const MIDSCENE_GROUNDING_ANTHROPIC_API_KEY = 'MIDSCENE_GROUNDING_ANTHROPIC_API_KEY';
|
|
103
103
|
const MIDSCENE_GROUNDING_VL_MODE = 'MIDSCENE_GROUNDING_VL_MODE';
|
|
104
104
|
const OPENAI_USE_AZURE = 'OPENAI_USE_AZURE';
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const UNUSED_ENV_KEYS = [
|
|
106
|
+
MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG
|
|
107
|
+
];
|
|
108
|
+
const BASIC_ENV_KEYS = [
|
|
108
109
|
MIDSCENE_DEBUG_MODE,
|
|
109
|
-
MIDSCENE_FORCE_DEEP_THINK,
|
|
110
|
-
MIDSCENE_LANGSMITH_DEBUG,
|
|
111
110
|
MIDSCENE_DEBUG_AI_PROFILE,
|
|
112
111
|
MIDSCENE_DEBUG_AI_RESPONSE,
|
|
113
|
-
|
|
112
|
+
MIDSCENE_RUN_DIR
|
|
113
|
+
];
|
|
114
|
+
const BOOLEAN_ENV_KEYS = [
|
|
115
|
+
MIDSCENE_CACHE,
|
|
116
|
+
MIDSCENE_LANGSMITH_DEBUG,
|
|
117
|
+
MIDSCENE_FORCE_DEEP_THINK,
|
|
118
|
+
MIDSCENE_MCP_USE_PUPPETEER_MODE,
|
|
119
|
+
MIDSCENE_MCP_ANDROID_MODE
|
|
120
|
+
];
|
|
121
|
+
const NUMBER_ENV_KEYS = [
|
|
114
122
|
OPENAI_MAX_TOKENS,
|
|
123
|
+
MIDSCENE_CACHE_MAX_FILENAME_LENGTH,
|
|
124
|
+
MIDSCENE_REPLANNING_CYCLE_LIMIT
|
|
125
|
+
];
|
|
126
|
+
const STRING_ENV_KEYS = [
|
|
115
127
|
MIDSCENE_ADB_PATH,
|
|
116
128
|
MIDSCENE_ADB_REMOTE_HOST,
|
|
117
129
|
MIDSCENE_ADB_REMOTE_PORT,
|
|
118
130
|
MIDSCENE_ANDROID_IME_STRATEGY,
|
|
119
|
-
MIDSCENE_CACHE,
|
|
120
|
-
MATCH_BY_POSITION,
|
|
121
131
|
MIDSCENE_REPORT_TAG_NAME,
|
|
122
|
-
MIDSCENE_MCP_USE_PUPPETEER_MODE,
|
|
123
|
-
MIDSCENE_MCP_CHROME_PATH,
|
|
124
|
-
MIDSCENE_RUN_DIR,
|
|
125
132
|
MIDSCENE_PREFERRED_LANGUAGE,
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
MATCH_BY_POSITION,
|
|
134
|
+
MIDSCENE_MCP_CHROME_PATH,
|
|
135
|
+
DOCKER_CONTAINER
|
|
136
|
+
];
|
|
137
|
+
const GLOBAL_ENV_KEYS = [
|
|
138
|
+
...BOOLEAN_ENV_KEYS,
|
|
139
|
+
...NUMBER_ENV_KEYS,
|
|
140
|
+
...STRING_ENV_KEYS
|
|
141
|
+
];
|
|
142
|
+
const MODEL_ENV_KEYS = [
|
|
128
143
|
MIDSCENE_MODEL_NAME,
|
|
129
144
|
MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
130
145
|
MIDSCENE_OPENAI_API_KEY,
|
|
@@ -207,4 +222,10 @@ const ENV_KEYS = [
|
|
|
207
222
|
MIDSCENE_GROUNDING_ANTHROPIC_API_KEY,
|
|
208
223
|
MIDSCENE_GROUNDING_VL_MODE
|
|
209
224
|
];
|
|
210
|
-
|
|
225
|
+
const ALL_ENV_KEYS = [
|
|
226
|
+
...UNUSED_ENV_KEYS,
|
|
227
|
+
...BASIC_ENV_KEYS,
|
|
228
|
+
...GLOBAL_ENV_KEYS,
|
|
229
|
+
...MODEL_ENV_KEYS
|
|
230
|
+
];
|
|
231
|
+
export { ALL_ENV_KEYS, ANTHROPIC_API_KEY, AZURE_OPENAI_API_VERSION, AZURE_OPENAI_DEPLOYMENT, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_KEY, BASIC_ENV_KEYS, BOOLEAN_ENV_KEYS, DOCKER_CONTAINER, GLOBAL_ENV_KEYS, MATCH_BY_POSITION, MIDSCENE_ADB_PATH, MIDSCENE_ADB_REMOTE_HOST, MIDSCENE_ADB_REMOTE_PORT, MIDSCENE_ANDROID_IME_STRATEGY, MIDSCENE_ANTHROPIC_API_KEY, MIDSCENE_API_TYPE, 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_CACHE, MIDSCENE_CACHE_MAX_FILENAME_LENGTH, MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG, MIDSCENE_DEBUG_AI_PROFILE, MIDSCENE_DEBUG_AI_RESPONSE, MIDSCENE_DEBUG_MODE, MIDSCENE_FORCE_DEEP_THINK, 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_LANGSMITH_DEBUG, MIDSCENE_MCP_ANDROID_MODE, MIDSCENE_MCP_CHROME_PATH, MIDSCENE_MCP_USE_PUPPETEER_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_PREFERRED_LANGUAGE, MIDSCENE_REPLANNING_CYCLE_LIMIT, MIDSCENE_REPORT_TAG_NAME, MIDSCENE_RUN_DIR, MIDSCENE_USE_ANTHROPIC_SDK, MIDSCENE_USE_AZURE_OPENAI, MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS, MIDSCENE_USE_VL_MODEL, 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, MODEL_ENV_KEYS, NUMBER_ENV_KEYS, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MAX_TOKENS, OPENAI_USE_AZURE, STRING_ENV_KEYS, UNUSED_ENV_KEYS };
|
package/dist/es/env/utils.mjs
CHANGED
|
@@ -1,43 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG, GlobalConfigManager } from "./global-config.mjs";
|
|
2
|
+
import { MIDSCENE_PREFERRED_LANGUAGE } from "./types.mjs";
|
|
3
|
+
const globalConfigManager = new GlobalConfigManager();
|
|
4
4
|
const uiTarsModelVersion = (modelPreferences)=>{
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
try {
|
|
6
|
+
const result = globalConfigManager.getModelConfigByIntent(modelPreferences.intent);
|
|
7
|
+
return result.uiTarsVersion;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
if (null == e ? void 0 : e[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG]) return void console.warn("Call uiTarsModelVersion before globalConfig init, will return undefined. This warning should only appear in midscene's own unit tests.");
|
|
10
|
+
throw e;
|
|
11
|
+
}
|
|
7
12
|
};
|
|
8
13
|
const vlLocateMode = (modelPreferences)=>{
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
try {
|
|
15
|
+
const result = globalConfigManager.getModelConfigByIntent(modelPreferences.intent);
|
|
16
|
+
return result.vlMode;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (null == e ? void 0 : e[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG]) return void console.warn("Call vlLocateMode before globalConfig init, will return undefined. This warning should only appear in midscene's own unit tests.");
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
11
21
|
};
|
|
12
22
|
const getIsUseQwenVl = (modelPreferences)=>{
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
try {
|
|
24
|
+
const result = globalConfigManager.getModelConfigByIntent(modelPreferences.intent);
|
|
25
|
+
return 'qwen-vl' === result.vlMode;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (null == e ? void 0 : e[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG]) {
|
|
28
|
+
console.warn("Call getIsUseQwenVl before globalConfig init, will return false. This warning should only appear in midscene's own unit tests.");
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
15
33
|
};
|
|
16
34
|
function getModelName(modelPreferences) {
|
|
17
|
-
const
|
|
18
|
-
return
|
|
35
|
+
const result = globalConfigManager.getModelConfigByIntent(modelPreferences.intent);
|
|
36
|
+
return null == result ? void 0 : result.modelName;
|
|
19
37
|
}
|
|
20
38
|
const getPreferredLanguage = ()=>{
|
|
21
|
-
const prefer =
|
|
39
|
+
const prefer = globalConfigManager.getEnvConfigValue(MIDSCENE_PREFERRED_LANGUAGE);
|
|
22
40
|
if (prefer) return prefer;
|
|
23
41
|
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
42
|
const isChina = 'Asia/Shanghai' === timeZone;
|
|
25
43
|
return isChina ? 'Chinese' : 'English';
|
|
26
44
|
};
|
|
27
45
|
const getUploadTestServerUrl = ()=>{
|
|
28
|
-
const
|
|
29
|
-
const serverUrl = null ==
|
|
46
|
+
const { openaiExtraConfig } = globalConfigManager.getModelConfigByIntent('default');
|
|
47
|
+
const serverUrl = null == openaiExtraConfig ? void 0 : openaiExtraConfig.REPORT_SERVER_URL;
|
|
30
48
|
return serverUrl;
|
|
31
49
|
};
|
|
32
|
-
const getAIConfig = (configKey)=>globalConfigManger.getConfigValue(configKey);
|
|
33
|
-
const getAIConfigInBoolean = (configKey)=>globalConfigManger.getConfigValueInBoolean(configKey);
|
|
34
|
-
const getAIConfigInNumber = (configKey)=>globalConfigManger.getConfigValueInNumber(configKey);
|
|
35
50
|
const overrideAIConfig = (newConfig, extendMode = false)=>{
|
|
36
|
-
|
|
37
|
-
if ('string' != typeof key) throw new Error(`Failed to override AI config, invalid key: ${key}`);
|
|
38
|
-
const value = newConfig[key];
|
|
39
|
-
if ('string' != typeof value) throw new Error(`Failed to override AI config, value for key ${key} must be a string, but got with type ${typeof value}`);
|
|
40
|
-
}
|
|
41
|
-
globalConfigManger.registerOverride(newConfig, extendMode);
|
|
51
|
+
globalConfigManager.registerOverride(newConfig, extendMode);
|
|
42
52
|
};
|
|
43
|
-
export {
|
|
53
|
+
export { getIsUseQwenVl, getModelName, getPreferredLanguage, getUploadTestServerUrl, globalConfigManager, overrideAIConfig, uiTarsModelVersion, vlLocateMode };
|
package/dist/lib/common.js
CHANGED
|
@@ -43,12 +43,13 @@ const external_node_fs_namespaceObject = require("node:fs");
|
|
|
43
43
|
const external_node_os_namespaceObject = require("node:os");
|
|
44
44
|
const external_node_path_namespaceObject = require("node:path");
|
|
45
45
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
46
|
-
const
|
|
46
|
+
const basic_js_namespaceObject = require("./env/basic.js");
|
|
47
|
+
const types_js_namespaceObject = require("./env/types.js");
|
|
47
48
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
48
49
|
const defaultRunDirName = 'midscene_run';
|
|
49
50
|
const getMidsceneRunDir = ()=>{
|
|
50
51
|
if (!external_utils_js_namespaceObject.ifInNode) return '';
|
|
51
|
-
return (0,
|
|
52
|
+
return (0, basic_js_namespaceObject.getBasicEnvValue)(types_js_namespaceObject.MIDSCENE_RUN_DIR) || defaultRunDirName;
|
|
52
53
|
};
|
|
53
54
|
const getMidsceneRunBaseDir = ()=>{
|
|
54
55
|
if (!external_utils_js_namespaceObject.ifInNode) return '';
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
getBasicEnvValue: ()=>getBasicEnvValue
|
|
28
|
+
});
|
|
29
|
+
const external_types_js_namespaceObject = require("./types.js");
|
|
30
|
+
const getBasicEnvValue = (key)=>{
|
|
31
|
+
if (!external_types_js_namespaceObject.BASIC_ENV_KEYS.includes(key)) throw new Error(`getBasicEnvValue with key ${key} is not supported.`);
|
|
32
|
+
return process.env[key];
|
|
33
|
+
};
|
|
34
|
+
exports.getBasicEnvValue = __webpack_exports__.getBasicEnvValue;
|
|
35
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
36
|
+
"getBasicEnvValue"
|
|
37
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
38
|
+
Object.defineProperty(exports, '__esModule', {
|
|
39
|
+
value: true
|
|
40
|
+
});
|