@midscene/shared 0.28.2 → 0.28.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/env/{model-config.mjs → decide-model-config.mjs} +52 -50
- package/dist/es/env/global-config-manager.mjs +91 -0
- package/dist/es/env/index.mjs +3 -2
- package/dist/es/env/model-config-manager.mjs +95 -0
- package/dist/es/env/parse.mjs +8 -23
- package/dist/es/env/types.mjs +16 -1
- package/dist/es/env/utils.mjs +7 -52
- package/dist/lib/env/{model-config.js → decide-model-config.js} +57 -52
- package/dist/lib/env/global-config-manager.js +125 -0
- package/dist/lib/env/index.js +17 -8
- package/dist/lib/env/model-config-manager.js +129 -0
- package/dist/lib/env/parse.js +9 -27
- package/dist/lib/env/types.js +23 -2
- package/dist/lib/env/utils.js +12 -69
- package/dist/types/env/decide-model-config.d.ts +14 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +1 -1
- package/dist/types/env/index.d.ts +2 -1
- package/dist/types/env/model-config-manager.d.ts +23 -0
- package/dist/types/env/parse.d.ts +2 -13
- package/dist/types/env/types.d.ts +52 -2
- package/dist/types/env/utils.d.ts +4 -8
- package/package.json +1 -1
- package/src/env/{model-config.ts → decide-model-config.ts} +91 -139
- package/src/env/global-config-manager.ts +174 -0
- package/src/env/helper.ts +1 -1
- package/src/env/index.ts +2 -1
- package/src/env/model-config-manager.ts +135 -0
- package/src/env/parse.ts +5 -24
- package/src/env/types.ts +61 -3
- package/src/env/utils.ts +7 -98
- package/dist/es/env/global-config.mjs +0 -192
- package/dist/lib/env/global-config.js +0 -229
- package/dist/types/env/global-config.d.ts +0 -52
- package/dist/types/env/model-config.d.ts +0 -70
- package/src/env/global-config.ts +0 -329
|
@@ -3,7 +3,7 @@ import { getDebug } from "../logger.mjs";
|
|
|
3
3
|
import { assert } from "../utils.mjs";
|
|
4
4
|
import { createAssert, maskConfig, parseJson } from "./helper.mjs";
|
|
5
5
|
import { initDebugConfig } from "./init-debug.mjs";
|
|
6
|
-
import { parseVlModeAndUiTarsFromGlobalConfig,
|
|
6
|
+
import { parseVlModeAndUiTarsFromGlobalConfig, parseVlModeAndUiTarsModelVersionFromRawValue } from "./parse.mjs";
|
|
7
7
|
const KEYS_MAP = {
|
|
8
8
|
VQA: VQA_MODEL_CONFIG_KEYS,
|
|
9
9
|
grounding: GROUNDING_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:config');
|
|
16
16
|
const socksProxy = provider[keys.socksProxy];
|
|
17
17
|
const httpProxy = provider[keys.httpProxy];
|
|
18
18
|
const vlMode = provider[keys.vlMode];
|
|
@@ -89,61 +89,62 @@ const getModelDescription = (vlMode, uiTarsVersion)=>{
|
|
|
89
89
|
else return `${vlMode} mode`;
|
|
90
90
|
return '';
|
|
91
91
|
};
|
|
92
|
-
const
|
|
92
|
+
const decideModelConfigFromIntentConfig = (intent, intentConfig)=>{
|
|
93
|
+
const debugLog = getDebug('ai:config');
|
|
94
|
+
debugLog('decideModelConfig base on agent.modelConfig()');
|
|
95
|
+
const keysForFn = KEYS_MAP[intent];
|
|
96
|
+
const candidateModelNameFromConfig = intentConfig[keysForFn.modelName];
|
|
97
|
+
debugLog('Got modelName from modelConfigFn', candidateModelNameFromConfig);
|
|
98
|
+
const chosenKeys = (()=>{
|
|
99
|
+
if (candidateModelNameFromConfig) {
|
|
100
|
+
debugLog('query modelConfig from fn by intent got corresponding modelName, will get other corresponding keys');
|
|
101
|
+
return keysForFn;
|
|
102
|
+
}
|
|
103
|
+
debugLog('query modelConfig from fn by intent got no corresponding modelName, will get other keys by default');
|
|
104
|
+
assert(intentConfig[DEFAULT_MODEL_CONFIG_KEYS.modelName], `The return value of agent.modelConfig do not have a valid value with key ${DEFAULT_MODEL_CONFIG_KEYS.modelName}.`);
|
|
105
|
+
return DEFAULT_MODEL_CONFIG_KEYS;
|
|
106
|
+
})();
|
|
107
|
+
const result = decideOpenaiSdkConfig({
|
|
108
|
+
keys: chosenKeys,
|
|
109
|
+
provider: intentConfig,
|
|
110
|
+
valueAssert: createAssert(chosenKeys.modelName, 'modelConfig', candidateModelNameFromConfig)
|
|
111
|
+
});
|
|
112
|
+
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsModelVersionFromRawValue(result.vlModeRaw);
|
|
113
|
+
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
114
|
+
const finalResult = {
|
|
115
|
+
...result,
|
|
116
|
+
modelName: intentConfig[chosenKeys.modelName],
|
|
117
|
+
vlMode,
|
|
118
|
+
uiTarsModelVersion: uiTarsVersion,
|
|
119
|
+
modelDescription,
|
|
120
|
+
from: 'modelConfig',
|
|
121
|
+
intent
|
|
122
|
+
};
|
|
123
|
+
debugLog(`decideModelConfig result by agent.modelConfig() with intent ${intent}:`, maskConfig(finalResult));
|
|
124
|
+
return finalResult;
|
|
125
|
+
};
|
|
126
|
+
const decideModelConfigFromEnv = (intent, allEnvConfig)=>{
|
|
93
127
|
initDebugConfig();
|
|
94
|
-
const debugLog = getDebug('ai:
|
|
95
|
-
if (modelConfigFromFn) {
|
|
96
|
-
debugLog('decideModelConfig base on agent.modelConfig()');
|
|
97
|
-
const keysForFn = KEYS_MAP[intent];
|
|
98
|
-
const candidateModelNameFromConfig = modelConfigFromFn[keysForFn.modelName];
|
|
99
|
-
debugLog('Got modelName from modelConfigFn', candidateModelNameFromConfig);
|
|
100
|
-
const chosenKeys = (()=>{
|
|
101
|
-
if (candidateModelNameFromConfig) {
|
|
102
|
-
debugLog('query modelConfig from fn by intent got corresponding modelName, will get other corresponding keys');
|
|
103
|
-
return keysForFn;
|
|
104
|
-
}
|
|
105
|
-
debugLog('query modelConfig from fn by intent got no corresponding modelName, will get other keys by default');
|
|
106
|
-
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}.`);
|
|
107
|
-
return DEFAULT_MODEL_CONFIG_KEYS;
|
|
108
|
-
})();
|
|
109
|
-
const result = decideOpenaiSdkConfig({
|
|
110
|
-
keys: chosenKeys,
|
|
111
|
-
provider: modelConfigFromFn,
|
|
112
|
-
valueAssert: createAssert(chosenKeys.modelName, 'modelConfig', candidateModelNameFromConfig)
|
|
113
|
-
});
|
|
114
|
-
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromRaw(result.vlModeRaw);
|
|
115
|
-
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
116
|
-
const finalResult = {
|
|
117
|
-
...result,
|
|
118
|
-
modelName: modelConfigFromFn[chosenKeys.modelName],
|
|
119
|
-
vlMode,
|
|
120
|
-
uiTarsVersion,
|
|
121
|
-
modelDescription,
|
|
122
|
-
from: 'modelConfig'
|
|
123
|
-
};
|
|
124
|
-
debugLog(`decideModelConfig result by agent.modelConfig() with intent ${intent}:`, maskConfig(finalResult));
|
|
125
|
-
return finalResult;
|
|
126
|
-
}
|
|
128
|
+
const debugLog = getDebug('ai:config');
|
|
127
129
|
const keysForEnv = 'default' === intent ? DEFAULT_MODEL_CONFIG_KEYS_LEGACY : KEYS_MAP[intent];
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if ('default' !== intent && allConfig[keysForEnv.modelName]) {
|
|
131
|
-
const modelName = allConfig[keysForEnv.modelName];
|
|
130
|
+
if ('default' !== intent && allEnvConfig[keysForEnv.modelName]) {
|
|
131
|
+
const modelName = allEnvConfig[keysForEnv.modelName];
|
|
132
132
|
debugLog(`Got intent ${intent} corresponding modelName ${modelName} by key ${keysForEnv.modelName} from globalConfig, will get other config by intent.`);
|
|
133
133
|
const result = decideOpenaiSdkConfig({
|
|
134
134
|
keys: keysForEnv,
|
|
135
|
-
provider:
|
|
135
|
+
provider: allEnvConfig,
|
|
136
136
|
valueAssert: createAssert(keysForEnv.modelName, 'process.env', modelName)
|
|
137
137
|
});
|
|
138
|
-
const { vlMode, uiTarsVersion } =
|
|
138
|
+
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsModelVersionFromRawValue(result.vlModeRaw);
|
|
139
139
|
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
140
140
|
const finalResult = {
|
|
141
141
|
...result,
|
|
142
142
|
modelName,
|
|
143
143
|
vlMode,
|
|
144
|
-
uiTarsVersion,
|
|
144
|
+
uiTarsModelVersion: uiTarsVersion,
|
|
145
145
|
modelDescription,
|
|
146
|
-
from: 'env'
|
|
146
|
+
from: 'env',
|
|
147
|
+
intent
|
|
147
148
|
};
|
|
148
149
|
debugLog(`decideModelConfig result by process.env with intent ${intent}:`, maskConfig(finalResult));
|
|
149
150
|
return finalResult;
|
|
@@ -151,20 +152,21 @@ const decideModelConfig = ({ intent, modelConfigFromFn, allConfig })=>{
|
|
|
151
152
|
debugLog(`decideModelConfig as legacy logic with intent ${intent}.`);
|
|
152
153
|
const result = decideOpenaiSdkConfig({
|
|
153
154
|
keys: DEFAULT_MODEL_CONFIG_KEYS_LEGACY,
|
|
154
|
-
provider:
|
|
155
|
+
provider: allEnvConfig,
|
|
155
156
|
valueAssert: createAssert(DEFAULT_MODEL_CONFIG_KEYS_LEGACY.modelName, 'process.env')
|
|
156
157
|
});
|
|
157
|
-
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromGlobalConfig(
|
|
158
|
+
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromGlobalConfig(allEnvConfig);
|
|
158
159
|
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
159
160
|
const finalResult = {
|
|
160
161
|
...result,
|
|
161
|
-
modelName:
|
|
162
|
+
modelName: allEnvConfig[DEFAULT_MODEL_CONFIG_KEYS_LEGACY.modelName] || 'gpt-4o',
|
|
162
163
|
vlMode,
|
|
163
|
-
uiTarsVersion,
|
|
164
|
+
uiTarsModelVersion: uiTarsVersion,
|
|
164
165
|
modelDescription,
|
|
165
|
-
from: 'legacy-env'
|
|
166
|
+
from: 'legacy-env',
|
|
167
|
+
intent
|
|
166
168
|
};
|
|
167
169
|
debugLog(`decideModelConfig result by legacy logic with intent ${intent}:`, maskConfig(finalResult));
|
|
168
170
|
return finalResult;
|
|
169
171
|
};
|
|
170
|
-
export {
|
|
172
|
+
export { decideModelConfigFromEnv, decideModelConfigFromIntentConfig, decideOpenaiSdkConfig };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { initDebugConfig } from "./init-debug.mjs";
|
|
2
|
+
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";
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
else obj[key] = value;
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
class GlobalConfigManager {
|
|
14
|
+
getAllEnvConfig() {
|
|
15
|
+
const envConfig = ALL_ENV_KEYS.reduce((p, name)=>{
|
|
16
|
+
p[name] = process.env[name];
|
|
17
|
+
return p;
|
|
18
|
+
}, Object.create(null));
|
|
19
|
+
if (!this.override) return envConfig;
|
|
20
|
+
{
|
|
21
|
+
const { newConfig, extendMode } = this.override;
|
|
22
|
+
if (extendMode) return {
|
|
23
|
+
...envConfig,
|
|
24
|
+
...newConfig
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
...newConfig
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getEnvConfigValue(key) {
|
|
32
|
+
const allConfig = this.getAllEnvConfig();
|
|
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 MIDSCENE_USE_VL_MODEL instead');
|
|
35
|
+
const value = allConfig[key];
|
|
36
|
+
this.keysHaveBeenRead[key] = true;
|
|
37
|
+
if ('string' == typeof value) return value.trim();
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
getEnvConfigInNumber(key) {
|
|
41
|
+
const allConfig = this.getAllEnvConfig();
|
|
42
|
+
if (!NUMBER_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigInNumber with key ${key} is not supported`);
|
|
43
|
+
const value = allConfig[key];
|
|
44
|
+
this.keysHaveBeenRead[key] = true;
|
|
45
|
+
return Number(value || '');
|
|
46
|
+
}
|
|
47
|
+
getEnvConfigInBoolean(key) {
|
|
48
|
+
const allConfig = this.getAllEnvConfig();
|
|
49
|
+
if (!BOOLEAN_ENV_KEYS.includes(key)) throw new Error(`getEnvConfigInBoolean with key ${key} is not supported`);
|
|
50
|
+
const value = allConfig[key];
|
|
51
|
+
this.keysHaveBeenRead[key] = true;
|
|
52
|
+
if (!value) return false;
|
|
53
|
+
if (/^(true|1)$/i.test(value)) return true;
|
|
54
|
+
if (/^(false|0)$/i.test(value)) return false;
|
|
55
|
+
return !!value.trim();
|
|
56
|
+
}
|
|
57
|
+
registerModelConfigManager(globalModelConfigManager) {
|
|
58
|
+
this.globalModelConfigManager = globalModelConfigManager;
|
|
59
|
+
}
|
|
60
|
+
overrideAIConfig(newConfig, extendMode = false) {
|
|
61
|
+
var _this_override;
|
|
62
|
+
for(const key in newConfig){
|
|
63
|
+
if (![
|
|
64
|
+
...GLOBAL_ENV_KEYS,
|
|
65
|
+
...MODEL_ENV_KEYS
|
|
66
|
+
].includes(key)) throw new Error(`Failed to override AI config, invalid key: ${key}`);
|
|
67
|
+
const value = newConfig[key];
|
|
68
|
+
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}`);
|
|
69
|
+
if (this.keysHaveBeenRead[key]) console.warn(`Warning: try to override AI config with key ${key} ,but it has been read.`);
|
|
70
|
+
}
|
|
71
|
+
const savedNewConfig = extendMode ? {
|
|
72
|
+
...null == (_this_override = this.override) ? void 0 : _this_override.newConfig,
|
|
73
|
+
...newConfig
|
|
74
|
+
} : newConfig;
|
|
75
|
+
this.override = {
|
|
76
|
+
newConfig: {
|
|
77
|
+
...savedNewConfig
|
|
78
|
+
},
|
|
79
|
+
extendMode
|
|
80
|
+
};
|
|
81
|
+
if (!this.globalModelConfigManager) throw new Error('globalModelConfigManager is not registered, which should not happen');
|
|
82
|
+
this.globalModelConfigManager.clearModelConfigMap();
|
|
83
|
+
}
|
|
84
|
+
constructor(){
|
|
85
|
+
_define_property(this, "override", void 0);
|
|
86
|
+
_define_property(this, "keysHaveBeenRead", {});
|
|
87
|
+
_define_property(this, "globalModelConfigManager", void 0);
|
|
88
|
+
initDebugConfig();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export { GlobalConfigManager };
|
package/dist/es/env/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModelConfigManager } from "./model-config-manager.mjs";
|
|
2
|
+
import { GlobalConfigManager } from "./global-config-manager.mjs";
|
|
2
3
|
export * from "./utils.mjs";
|
|
3
4
|
export * from "./types.mjs";
|
|
4
|
-
export {
|
|
5
|
+
export { GlobalConfigManager, ModelConfigManager };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { decideModelConfigFromEnv, decideModelConfigFromIntentConfig } from "./decide-model-config.mjs";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
const ALL_INTENTS = [
|
|
13
|
+
'VQA',
|
|
14
|
+
'default',
|
|
15
|
+
'grounding',
|
|
16
|
+
'planning'
|
|
17
|
+
];
|
|
18
|
+
class ModelConfigManager {
|
|
19
|
+
calcIntentConfigMap(modelConfigFn) {
|
|
20
|
+
const intentConfigMap = {
|
|
21
|
+
VQA: void 0,
|
|
22
|
+
default: void 0,
|
|
23
|
+
grounding: void 0,
|
|
24
|
+
planning: void 0
|
|
25
|
+
};
|
|
26
|
+
for (const i of ALL_INTENTS){
|
|
27
|
+
const result = modelConfigFn({
|
|
28
|
+
intent: i
|
|
29
|
+
});
|
|
30
|
+
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.`);
|
|
31
|
+
intentConfigMap[i] = result;
|
|
32
|
+
}
|
|
33
|
+
return intentConfigMap;
|
|
34
|
+
}
|
|
35
|
+
calcModelConfigMapBaseOnIntent(intentConfigMap) {
|
|
36
|
+
const modelConfigMap = {
|
|
37
|
+
VQA: void 0,
|
|
38
|
+
default: void 0,
|
|
39
|
+
grounding: void 0,
|
|
40
|
+
planning: void 0
|
|
41
|
+
};
|
|
42
|
+
for (const i of ALL_INTENTS){
|
|
43
|
+
const result = decideModelConfigFromIntentConfig(i, intentConfigMap[i]);
|
|
44
|
+
modelConfigMap[i] = result;
|
|
45
|
+
}
|
|
46
|
+
return modelConfigMap;
|
|
47
|
+
}
|
|
48
|
+
calcModelConfigMapBaseOnEnv(allEnvConfig) {
|
|
49
|
+
const modelConfigMap = {
|
|
50
|
+
VQA: void 0,
|
|
51
|
+
default: void 0,
|
|
52
|
+
grounding: void 0,
|
|
53
|
+
planning: void 0
|
|
54
|
+
};
|
|
55
|
+
for (const i of ALL_INTENTS){
|
|
56
|
+
const result = decideModelConfigFromEnv(i, allEnvConfig);
|
|
57
|
+
modelConfigMap[i] = result;
|
|
58
|
+
}
|
|
59
|
+
return modelConfigMap;
|
|
60
|
+
}
|
|
61
|
+
clearModelConfigMap() {
|
|
62
|
+
if (this.isolatedMode) throw new Error('ModelConfigManager work in isolated mode, so clearModelConfigMap should not be called');
|
|
63
|
+
this.modelConfigMap = void 0;
|
|
64
|
+
}
|
|
65
|
+
getModelConfig(intent) {
|
|
66
|
+
if (this.isolatedMode) {
|
|
67
|
+
if (!this.modelConfigMap) throw new Error('modelConfigMap is not initialized in isolated mode, which should not happen');
|
|
68
|
+
return this.modelConfigMap[intent];
|
|
69
|
+
}
|
|
70
|
+
if (!this.modelConfigMap) {
|
|
71
|
+
if (!this.globalConfigManager) throw new Error('globalConfigManager is not registered, which should not happen');
|
|
72
|
+
this.modelConfigMap = this.calcModelConfigMapBaseOnEnv(this.globalConfigManager.getAllEnvConfig());
|
|
73
|
+
}
|
|
74
|
+
return this.modelConfigMap[intent];
|
|
75
|
+
}
|
|
76
|
+
getUploadTestServerUrl() {
|
|
77
|
+
const { openaiExtraConfig } = this.getModelConfig('default');
|
|
78
|
+
const serverUrl = null == openaiExtraConfig ? void 0 : openaiExtraConfig.REPORT_SERVER_URL;
|
|
79
|
+
return serverUrl;
|
|
80
|
+
}
|
|
81
|
+
registerGlobalConfigManager(globalConfigManager) {
|
|
82
|
+
this.globalConfigManager = globalConfigManager;
|
|
83
|
+
}
|
|
84
|
+
constructor(modelConfigFn){
|
|
85
|
+
_define_property(this, "modelConfigMap", void 0);
|
|
86
|
+
_define_property(this, "isolatedMode", false);
|
|
87
|
+
_define_property(this, "globalConfigManager", void 0);
|
|
88
|
+
if (modelConfigFn) {
|
|
89
|
+
this.isolatedMode = true;
|
|
90
|
+
const intentConfigMap = this.calcIntentConfigMap(modelConfigFn);
|
|
91
|
+
this.modelConfigMap = this.calcModelConfigMapBaseOnIntent(intentConfigMap);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export { ModelConfigManager };
|
package/dist/es/env/parse.mjs
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
|
-
import { MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS } from "./types.mjs";
|
|
2
|
-
|
|
3
|
-
UITarsModelVersion["V1_0"] = "1.0";
|
|
4
|
-
UITarsModelVersion["V1_5"] = "1.5";
|
|
5
|
-
UITarsModelVersion["DOUBAO_1_5_15B"] = "doubao-1.5-15B";
|
|
6
|
-
UITarsModelVersion["DOUBAO_1_5_20B"] = "doubao-1.5-20B";
|
|
7
|
-
return UITarsModelVersion;
|
|
8
|
-
}({});
|
|
9
|
-
const vlModeRawValidValues = [
|
|
10
|
-
'doubao-vision',
|
|
11
|
-
'gemini',
|
|
12
|
-
'qwen-vl',
|
|
13
|
-
'vlm-ui-tars',
|
|
14
|
-
'vlm-ui-tars-doubao',
|
|
15
|
-
'vlm-ui-tars-doubao-1.5'
|
|
16
|
-
];
|
|
17
|
-
const parseVlModeAndUiTarsFromRaw = (vlModeRaw)=>{
|
|
1
|
+
import { MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS, UITarsModelVersion, VL_MODE_RAW_VALID_VALUES } from "./types.mjs";
|
|
2
|
+
const parseVlModeAndUiTarsModelVersionFromRawValue = (vlModeRaw)=>{
|
|
18
3
|
if (!vlModeRaw) return {
|
|
19
4
|
vlMode: void 0,
|
|
20
5
|
uiTarsVersion: void 0
|
|
21
6
|
};
|
|
22
|
-
if (!
|
|
7
|
+
if (!VL_MODE_RAW_VALID_VALUES.includes(vlModeRaw)) throw new Error(`the value ${vlModeRaw} is not a valid VL_MODE value, must be one of ${VL_MODE_RAW_VALID_VALUES}`);
|
|
23
8
|
const raw = vlModeRaw;
|
|
24
9
|
if ('vlm-ui-tars' === raw) return {
|
|
25
10
|
vlMode: 'vlm-ui-tars',
|
|
26
|
-
uiTarsVersion:
|
|
11
|
+
uiTarsVersion: UITarsModelVersion.V1_0
|
|
27
12
|
};
|
|
28
13
|
if ('vlm-ui-tars-doubao' === raw || 'vlm-ui-tars-doubao-1.5' === raw) return {
|
|
29
14
|
vlMode: 'vlm-ui-tars',
|
|
30
|
-
uiTarsVersion:
|
|
15
|
+
uiTarsVersion: UITarsModelVersion.DOUBAO_1_5_20B
|
|
31
16
|
};
|
|
32
17
|
return {
|
|
33
18
|
vlMode: raw,
|
|
@@ -60,11 +45,11 @@ const parseVlModeAndUiTarsFromGlobalConfig = (provider)=>{
|
|
|
60
45
|
};
|
|
61
46
|
if (isUiTars) if ('1' === isUiTars) return {
|
|
62
47
|
vlMode: 'vlm-ui-tars',
|
|
63
|
-
uiTarsVersion:
|
|
48
|
+
uiTarsVersion: UITarsModelVersion.V1_0
|
|
64
49
|
};
|
|
65
50
|
else if ('DOUBAO' === isUiTars || 'DOUBAO-1.5' === isUiTars) return {
|
|
66
51
|
vlMode: 'vlm-ui-tars',
|
|
67
|
-
uiTarsVersion:
|
|
52
|
+
uiTarsVersion: UITarsModelVersion.DOUBAO_1_5_20B
|
|
68
53
|
};
|
|
69
54
|
else return {
|
|
70
55
|
vlMode: 'vlm-ui-tars',
|
|
@@ -75,4 +60,4 @@ const parseVlModeAndUiTarsFromGlobalConfig = (provider)=>{
|
|
|
75
60
|
uiTarsVersion: void 0
|
|
76
61
|
};
|
|
77
62
|
};
|
|
78
|
-
export {
|
|
63
|
+
export { parseVlModeAndUiTarsFromGlobalConfig, parseVlModeAndUiTarsModelVersionFromRawValue };
|
package/dist/es/env/types.mjs
CHANGED
|
@@ -228,4 +228,19 @@ const ALL_ENV_KEYS = [
|
|
|
228
228
|
...GLOBAL_ENV_KEYS,
|
|
229
229
|
...MODEL_ENV_KEYS
|
|
230
230
|
];
|
|
231
|
-
|
|
231
|
+
var types_UITarsModelVersion = /*#__PURE__*/ function(UITarsModelVersion) {
|
|
232
|
+
UITarsModelVersion["V1_0"] = "1.0";
|
|
233
|
+
UITarsModelVersion["V1_5"] = "1.5";
|
|
234
|
+
UITarsModelVersion["DOUBAO_1_5_15B"] = "doubao-1.5-15B";
|
|
235
|
+
UITarsModelVersion["DOUBAO_1_5_20B"] = "doubao-1.5-20B";
|
|
236
|
+
return UITarsModelVersion;
|
|
237
|
+
}({});
|
|
238
|
+
const VL_MODE_RAW_VALID_VALUES = [
|
|
239
|
+
'doubao-vision',
|
|
240
|
+
'gemini',
|
|
241
|
+
'qwen-vl',
|
|
242
|
+
'vlm-ui-tars',
|
|
243
|
+
'vlm-ui-tars-doubao',
|
|
244
|
+
'vlm-ui-tars-doubao-1.5'
|
|
245
|
+
];
|
|
246
|
+
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, types_UITarsModelVersion as UITarsModelVersion, UNUSED_ENV_KEYS, VL_MODE_RAW_VALID_VALUES };
|
package/dist/es/env/utils.mjs
CHANGED
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GlobalConfigManager } from "./global-config-manager.mjs";
|
|
2
|
+
import { ModelConfigManager } from "./model-config-manager.mjs";
|
|
2
3
|
import { MIDSCENE_PREFERRED_LANGUAGE } from "./types.mjs";
|
|
4
|
+
const globalModelConfigManager = new ModelConfigManager();
|
|
3
5
|
const globalConfigManager = new GlobalConfigManager();
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const vlLocateMode = (modelPreferences)=>{
|
|
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
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const getIsUseQwenVl = (modelPreferences)=>{
|
|
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
|
-
}
|
|
33
|
-
};
|
|
34
|
-
function getModelName(modelPreferences) {
|
|
35
|
-
try {
|
|
36
|
-
const result = globalConfigManager.getModelConfigByIntent(modelPreferences.intent);
|
|
37
|
-
return null == result ? void 0 : result.modelName;
|
|
38
|
-
} catch (e) {
|
|
39
|
-
if (null == e ? void 0 : e[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG]) return void console.warn("Call getModelName before globalConfig init, will return undefined. This warning should only appear in midscene's own unit tests.");
|
|
40
|
-
throw e;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
6
|
+
globalConfigManager.registerModelConfigManager(globalModelConfigManager);
|
|
7
|
+
globalModelConfigManager.registerGlobalConfigManager(globalConfigManager);
|
|
43
8
|
const getPreferredLanguage = ()=>{
|
|
44
9
|
const prefer = globalConfigManager.getEnvConfigValue(MIDSCENE_PREFERRED_LANGUAGE);
|
|
45
10
|
if (prefer) return prefer;
|
|
@@ -47,17 +12,7 @@ const getPreferredLanguage = ()=>{
|
|
|
47
12
|
const isChina = 'Asia/Shanghai' === timeZone;
|
|
48
13
|
return isChina ? 'Chinese' : 'English';
|
|
49
14
|
};
|
|
50
|
-
const getUploadTestServerUrl = ()=>{
|
|
51
|
-
try {
|
|
52
|
-
const { openaiExtraConfig } = globalConfigManager.getModelConfigByIntent('default');
|
|
53
|
-
const serverUrl = null == openaiExtraConfig ? void 0 : openaiExtraConfig.REPORT_SERVER_URL;
|
|
54
|
-
return serverUrl;
|
|
55
|
-
} catch (e) {
|
|
56
|
-
if (null == e ? void 0 : e[GLOBAL_CONFIG_MANAGER_UNINITIALIZED_FLAG]) return void console.warn("Call getUploadTestServerUrl before globalConfig init, will return undefined. This warning should only appear in midscene's own unit tests.");
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
15
|
const overrideAIConfig = (newConfig, extendMode = false)=>{
|
|
61
|
-
globalConfigManager.
|
|
16
|
+
globalConfigManager.overrideAIConfig(newConfig, extendMode);
|
|
62
17
|
};
|
|
63
|
-
export {
|
|
18
|
+
export { getPreferredLanguage, globalConfigManager, globalModelConfigManager, overrideAIConfig };
|