@rpascene/shared 0.30.8
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 +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/build/copy-static.mjs +29 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +202 -0
- package/dist/es/constants/index.mjs +74 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +97 -0
- package/dist/es/env/decide-model-config.mjs +172 -0
- package/dist/es/env/global-config-manager.mjs +82 -0
- package/dist/es/env/helper.mjs +45 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +99 -0
- package/dist/es/env/parse.mjs +69 -0
- package/dist/es/env/types.mjs +265 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +646 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +92 -0
- package/dist/es/extractor/index.mjs +7 -0
- package/dist/es/extractor/locator.mjs +95 -0
- package/dist/es/extractor/tree.mjs +81 -0
- package/dist/es/extractor/util.mjs +244 -0
- package/dist/es/extractor/web-extractor.mjs +361 -0
- package/dist/es/img/box-select.mjs +184 -0
- package/dist/es/img/draw-box.mjs +42 -0
- package/dist/es/img/get-jimp.mjs +10 -0
- package/dist/es/img/get-photon.mjs +19 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +5 -0
- package/dist/es/img/info.mjs +32 -0
- package/dist/es/img/transform.mjs +192 -0
- package/dist/es/index.mjs +3 -0
- package/dist/es/logger.mjs +61 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +1 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +66 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/build/copy-static.js +77 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +239 -0
- package/dist/lib/constants/index.js +153 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +143 -0
- package/dist/lib/env/decide-model-config.js +212 -0
- package/dist/lib/env/global-config-manager.js +116 -0
- package/dist/lib/env/helper.js +85 -0
- package/dist/lib/env/index.js +94 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +133 -0
- package/dist/lib/env/parse.js +106 -0
- package/dist/lib/env/types.js +650 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +698 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +150 -0
- package/dist/lib/extractor/index.js +153 -0
- package/dist/lib/extractor/locator.js +141 -0
- package/dist/lib/extractor/tree.js +127 -0
- package/dist/lib/extractor/util.js +335 -0
- package/dist/lib/extractor/web-extractor.js +407 -0
- package/dist/lib/img/box-select.js +232 -0
- package/dist/lib/img/draw-box.js +89 -0
- package/dist/lib/img/get-jimp.js +72 -0
- package/dist/lib/img/get-photon.js +76 -0
- package/dist/lib/img/get-sharp.js +63 -0
- package/dist/lib/img/index.js +102 -0
- package/dist/lib/img/info.js +86 -0
- package/dist/lib/img/transform.js +279 -0
- package/dist/lib/index.js +43 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +60 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +60 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +136 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/build/copy-static.d.ts +31 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +23 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +40 -0
- 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 +6 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +24 -0
- package/dist/types/env/parse.d.ts +12 -0
- package/dist/types/env/types.d.ts +295 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +26 -0
- package/dist/types/extractor/index.d.ts +36 -0
- package/dist/types/extractor/locator.d.ts +7 -0
- package/dist/types/extractor/tree.d.ts +9 -0
- package/dist/types/extractor/util.d.ts +43 -0
- package/dist/types/extractor/web-extractor.d.ts +19 -0
- package/dist/types/img/box-select.d.ts +25 -0
- package/dist/types/img/draw-box.d.ts +15 -0
- package/dist/types/img/get-jimp.d.ts +2 -0
- package/dist/types/img/get-photon.d.ts +8 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +4 -0
- package/dist/types/img/info.d.ts +29 -0
- package/dist/types/img/transform.d.ts +88 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +37 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +22 -0
- package/package.json +102 -0
- package/src/baseDB.ts +158 -0
- package/src/build/copy-static.ts +62 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +202 -0
- package/src/constants/index.ts +81 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +291 -0
- package/src/env/decide-model-config.ts +319 -0
- package/src/env/global-config-manager.ts +174 -0
- package/src/env/helper.ts +80 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +29 -0
- package/src/env/model-config-manager.ts +145 -0
- package/src/env/parse.ts +131 -0
- package/src/env/types.ts +573 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +101 -0
- package/src/extractor/customLocator.ts +1138 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +141 -0
- package/src/extractor/index.ts +54 -0
- package/src/extractor/locator.ts +179 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +468 -0
- package/src/extractor/web-extractor.ts +559 -0
- package/src/img/box-select.ts +346 -0
- package/src/img/draw-box.ts +60 -0
- package/src/img/get-jimp.ts +12 -0
- package/src/img/get-photon.ts +48 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +24 -0
- package/src/img/info.ts +79 -0
- package/src/img/jimp.d.ts +4 -0
- package/src/img/transform.ts +396 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +93 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +1 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +53 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +127 -0
|
@@ -0,0 +1,172 @@
|
|
|
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";
|
|
2
|
+
import { getDebug } from "../logger.mjs";
|
|
3
|
+
import { assert } from "../utils.mjs";
|
|
4
|
+
import { createAssert, maskConfig, parseJson } from "./helper.mjs";
|
|
5
|
+
import { initDebugConfig } from "./init-debug.mjs";
|
|
6
|
+
import { parseVlModeAndUiTarsFromGlobalConfig, parseVlModeAndUiTarsModelVersionFromRawValue } from "./parse.mjs";
|
|
7
|
+
const KEYS_MAP = {
|
|
8
|
+
VQA: VQA_MODEL_CONFIG_KEYS,
|
|
9
|
+
grounding: GROUNDING_MODEL_CONFIG_KEYS,
|
|
10
|
+
planning: PLANNING_MODEL_CONFIG_KEYS,
|
|
11
|
+
default: DEFAULT_MODEL_CONFIG_KEYS
|
|
12
|
+
};
|
|
13
|
+
const decideOpenaiSdkConfig = ({ keys, provider, valueAssert })=>{
|
|
14
|
+
initDebugConfig();
|
|
15
|
+
const debugLog = getDebug('ai:config');
|
|
16
|
+
const socksProxy = provider[keys.socksProxy];
|
|
17
|
+
const httpProxy = provider[keys.httpProxy];
|
|
18
|
+
const vlMode = provider[keys.vlMode];
|
|
19
|
+
debugLog('enter decideOpenaiSdkConfig with keys:', keys);
|
|
20
|
+
if (provider[keys.openaiUseAzureDeprecated]) {
|
|
21
|
+
debugLog(`provider has ${keys.openaiUseAzureDeprecated} with value${provider[keys.openaiUseAzureDeprecated]}`);
|
|
22
|
+
const openaiBaseURL = provider[keys.openaiBaseURL];
|
|
23
|
+
const openaiApiKey = provider[keys.openaiApiKey];
|
|
24
|
+
const openaiExtraConfig = parseJson(keys.openaiExtraConfig, provider[keys.openaiExtraConfig]);
|
|
25
|
+
valueAssert(openaiApiKey, keys.openaiApiKey, keys.openaiUseAzureDeprecated);
|
|
26
|
+
return {
|
|
27
|
+
socksProxy,
|
|
28
|
+
httpProxy,
|
|
29
|
+
vlModeRaw: vlMode,
|
|
30
|
+
openaiUseAzureDeprecated: true,
|
|
31
|
+
openaiApiKey,
|
|
32
|
+
openaiBaseURL,
|
|
33
|
+
openaiExtraConfig
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (provider[keys.useAzureOpenai]) {
|
|
37
|
+
debugLog(`provider has ${keys.useAzureOpenai} with value ${provider[keys.useAzureOpenai]}`);
|
|
38
|
+
const azureOpenaiScope = provider[keys.azureOpenaiScope];
|
|
39
|
+
const azureOpenaiKey = provider[keys.azureOpenaiKey];
|
|
40
|
+
const azureOpenaiEndpoint = provider[keys.azureOpenaiEndpoint];
|
|
41
|
+
const azureOpenaiDeployment = provider[keys.azureOpenaiDeployment];
|
|
42
|
+
const azureOpenaiApiVersion = provider[keys.azureOpenaiApiVersion];
|
|
43
|
+
const azureExtraConfig = parseJson(keys.azureExtraConfig, provider[keys.azureExtraConfig]);
|
|
44
|
+
const openaiExtraConfig = parseJson(keys.openaiExtraConfig, provider[keys.openaiExtraConfig]);
|
|
45
|
+
valueAssert(azureOpenaiKey, keys.azureOpenaiKey, keys.useAzureOpenai);
|
|
46
|
+
return {
|
|
47
|
+
socksProxy,
|
|
48
|
+
httpProxy,
|
|
49
|
+
vlModeRaw: vlMode,
|
|
50
|
+
useAzureOpenai: true,
|
|
51
|
+
azureOpenaiScope,
|
|
52
|
+
azureOpenaiKey,
|
|
53
|
+
azureOpenaiEndpoint,
|
|
54
|
+
azureOpenaiDeployment,
|
|
55
|
+
azureOpenaiApiVersion,
|
|
56
|
+
azureExtraConfig,
|
|
57
|
+
openaiExtraConfig
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (provider[keys.useAnthropicSdk]) {
|
|
61
|
+
debugLog(`provider has ${keys.useAnthropicSdk} with value ${provider[keys.useAnthropicSdk]}`);
|
|
62
|
+
const anthropicApiKey = provider[keys.anthropicApiKey];
|
|
63
|
+
valueAssert(anthropicApiKey, keys.anthropicApiKey, keys.useAnthropicSdk);
|
|
64
|
+
return {
|
|
65
|
+
socksProxy,
|
|
66
|
+
httpProxy,
|
|
67
|
+
useAnthropicSdk: true,
|
|
68
|
+
anthropicApiKey
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
{
|
|
72
|
+
debugLog('provider has no specific model SDK declared');
|
|
73
|
+
const openaiBaseURL = provider[keys.openaiBaseURL];
|
|
74
|
+
const openaiApiKey = provider[keys.openaiApiKey];
|
|
75
|
+
const openaiExtraConfig = parseJson(keys.openaiExtraConfig, provider[keys.openaiExtraConfig]);
|
|
76
|
+
valueAssert(openaiApiKey, keys.openaiApiKey);
|
|
77
|
+
return {
|
|
78
|
+
socksProxy,
|
|
79
|
+
httpProxy,
|
|
80
|
+
vlModeRaw: vlMode,
|
|
81
|
+
openaiBaseURL,
|
|
82
|
+
openaiApiKey,
|
|
83
|
+
openaiExtraConfig
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const getModelDescription = (vlMode, uiTarsVersion)=>{
|
|
88
|
+
if (vlMode) if (uiTarsVersion) return `UI-TARS=${uiTarsVersion}`;
|
|
89
|
+
else return `${vlMode} mode`;
|
|
90
|
+
return '';
|
|
91
|
+
};
|
|
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)=>{
|
|
127
|
+
initDebugConfig();
|
|
128
|
+
const debugLog = getDebug('ai:config');
|
|
129
|
+
const keysForEnv = 'default' === intent ? DEFAULT_MODEL_CONFIG_KEYS_LEGACY : KEYS_MAP[intent];
|
|
130
|
+
if ('default' !== intent && allEnvConfig[keysForEnv.modelName]) {
|
|
131
|
+
const modelName = allEnvConfig[keysForEnv.modelName];
|
|
132
|
+
debugLog(`Got intent ${intent} corresponding modelName ${modelName} by key ${keysForEnv.modelName} from globalConfig, will get other config by intent.`);
|
|
133
|
+
const result = decideOpenaiSdkConfig({
|
|
134
|
+
keys: keysForEnv,
|
|
135
|
+
provider: allEnvConfig,
|
|
136
|
+
valueAssert: createAssert(keysForEnv.modelName, 'process.env', modelName)
|
|
137
|
+
});
|
|
138
|
+
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsModelVersionFromRawValue(result.vlModeRaw);
|
|
139
|
+
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
140
|
+
const finalResult = {
|
|
141
|
+
...result,
|
|
142
|
+
modelName,
|
|
143
|
+
vlMode,
|
|
144
|
+
uiTarsModelVersion: uiTarsVersion,
|
|
145
|
+
modelDescription,
|
|
146
|
+
from: 'env',
|
|
147
|
+
intent
|
|
148
|
+
};
|
|
149
|
+
debugLog(`decideModelConfig result by process.env with intent ${intent}:`, maskConfig(finalResult));
|
|
150
|
+
return finalResult;
|
|
151
|
+
}
|
|
152
|
+
debugLog(`decideModelConfig as legacy logic with intent ${intent}.`);
|
|
153
|
+
const result = decideOpenaiSdkConfig({
|
|
154
|
+
keys: DEFAULT_MODEL_CONFIG_KEYS_LEGACY,
|
|
155
|
+
provider: allEnvConfig,
|
|
156
|
+
valueAssert: createAssert(DEFAULT_MODEL_CONFIG_KEYS_LEGACY.modelName, 'process.env')
|
|
157
|
+
});
|
|
158
|
+
const { vlMode, uiTarsVersion } = parseVlModeAndUiTarsFromGlobalConfig(allEnvConfig);
|
|
159
|
+
const modelDescription = getModelDescription(vlMode, uiTarsVersion);
|
|
160
|
+
const finalResult = {
|
|
161
|
+
...result,
|
|
162
|
+
modelName: allEnvConfig[DEFAULT_MODEL_CONFIG_KEYS_LEGACY.modelName] || 'gpt-4o',
|
|
163
|
+
vlMode,
|
|
164
|
+
uiTarsModelVersion: uiTarsVersion,
|
|
165
|
+
modelDescription,
|
|
166
|
+
from: 'legacy-env',
|
|
167
|
+
intent
|
|
168
|
+
};
|
|
169
|
+
debugLog(`decideModelConfig result by legacy logic with intent ${intent}:`, maskConfig(finalResult));
|
|
170
|
+
return finalResult;
|
|
171
|
+
};
|
|
172
|
+
export { decideModelConfigFromEnv, decideModelConfigFromIntentConfig, decideOpenaiSdkConfig };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { initDebugConfig } from "./init-debug.mjs";
|
|
2
|
+
import { ALL_ENV_KEYS, BOOLEAN_ENV_KEYS, MATCH_BY_POSITION, 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 RPASCENE_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
|
+
const savedNewConfig = extendMode ? {
|
|
63
|
+
...null == (_this_override = this.override) ? void 0 : _this_override.newConfig,
|
|
64
|
+
...newConfig
|
|
65
|
+
} : newConfig;
|
|
66
|
+
this.override = {
|
|
67
|
+
newConfig: {
|
|
68
|
+
...savedNewConfig
|
|
69
|
+
},
|
|
70
|
+
extendMode
|
|
71
|
+
};
|
|
72
|
+
if (!this.globalModelConfigManager) throw new Error('globalModelConfigManager is not registered, which should not happen');
|
|
73
|
+
this.globalModelConfigManager.clearModelConfigMap();
|
|
74
|
+
}
|
|
75
|
+
constructor(){
|
|
76
|
+
_define_property(this, "override", void 0);
|
|
77
|
+
_define_property(this, "keysHaveBeenRead", {});
|
|
78
|
+
_define_property(this, "globalModelConfigManager", void 0);
|
|
79
|
+
initDebugConfig();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export { GlobalConfigManager };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "../utils.mjs";
|
|
2
|
+
const maskKey = (key, maskChar = '*')=>{
|
|
3
|
+
if ('string' != typeof key || 0 === key.length) return key;
|
|
4
|
+
const prefixLen = 3;
|
|
5
|
+
const suffixLen = 3;
|
|
6
|
+
const keepLength = prefixLen + suffixLen;
|
|
7
|
+
if (key.length <= keepLength) return key;
|
|
8
|
+
const prefix = key.substring(0, prefixLen);
|
|
9
|
+
const suffix = key.substring(key.length - suffixLen);
|
|
10
|
+
const maskLength = key.length - keepLength;
|
|
11
|
+
const mask = maskChar.repeat(maskLength);
|
|
12
|
+
return `${prefix}${mask}${suffix}`;
|
|
13
|
+
};
|
|
14
|
+
const maskConfig = (config)=>Object.fromEntries(Object.entries(config).map(([key, value])=>{
|
|
15
|
+
if ([
|
|
16
|
+
'openaiApiKey',
|
|
17
|
+
'azureOpenaiKey',
|
|
18
|
+
'anthropicApiKey'
|
|
19
|
+
].includes(key)) return [
|
|
20
|
+
key,
|
|
21
|
+
maskKey(value)
|
|
22
|
+
];
|
|
23
|
+
if ([
|
|
24
|
+
'openaiExtraConfig',
|
|
25
|
+
'azureExtraConfig'
|
|
26
|
+
].includes(key)) return [
|
|
27
|
+
key,
|
|
28
|
+
maskKey(JSON.stringify(value))
|
|
29
|
+
];
|
|
30
|
+
return [
|
|
31
|
+
key,
|
|
32
|
+
value
|
|
33
|
+
];
|
|
34
|
+
}));
|
|
35
|
+
const parseJson = (key, value)=>{
|
|
36
|
+
if (value) try {
|
|
37
|
+
return JSON.parse(value);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw new Error(`Failed to parse ${key} as a JSON. ${e.message}`, {
|
|
40
|
+
cause: e
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const createAssert = (modelNameKey, provider, modelName)=>(value, key, modelVendorFlag)=>{};
|
|
45
|
+
export { createAssert, maskConfig, parseJson };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { enableDebug } from "../logger.mjs";
|
|
2
|
+
import { getBasicEnvValue } from "./basic.mjs";
|
|
3
|
+
import { RPASCENE_DEBUG_AI_PROFILE, RPASCENE_DEBUG_AI_RESPONSE } from "./types.mjs";
|
|
4
|
+
const initDebugConfig = ()=>{
|
|
5
|
+
const shouldPrintTiming = getBasicEnvValue(RPASCENE_DEBUG_AI_PROFILE);
|
|
6
|
+
let debugConfig = '';
|
|
7
|
+
if (shouldPrintTiming) {
|
|
8
|
+
console.warn('RPASCENE_DEBUG_AI_PROFILE is deprecated, use DEBUG=rpascene:ai:profile instead');
|
|
9
|
+
debugConfig = 'ai:profile';
|
|
10
|
+
}
|
|
11
|
+
const shouldPrintAIResponse = getBasicEnvValue(RPASCENE_DEBUG_AI_RESPONSE);
|
|
12
|
+
if (shouldPrintAIResponse) {
|
|
13
|
+
console.warn('RPASCENE_DEBUG_AI_RESPONSE is deprecated, use DEBUG=rpascene:ai:response instead');
|
|
14
|
+
debugConfig = debugConfig ? 'ai:*' : 'ai:call';
|
|
15
|
+
}
|
|
16
|
+
if (debugConfig) enableDebug(debugConfig);
|
|
17
|
+
};
|
|
18
|
+
export { initDebugConfig };
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
throwErrorIfNonVLModel(intent = 'grounding') {
|
|
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://rpascenejs.com/choose-a-model');
|
|
87
|
+
}
|
|
88
|
+
constructor(modelConfigFn){
|
|
89
|
+
_define_property(this, "modelConfigMap", void 0);
|
|
90
|
+
_define_property(this, "isolatedMode", false);
|
|
91
|
+
_define_property(this, "globalConfigManager", void 0);
|
|
92
|
+
if (modelConfigFn) {
|
|
93
|
+
this.isolatedMode = true;
|
|
94
|
+
const intentConfigMap = this.calcIntentConfigMap(modelConfigFn);
|
|
95
|
+
this.modelConfigMap = this.calcModelConfigMapBaseOnIntent(intentConfigMap);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export { ModelConfigManager };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RPASCENE_USE_DOUBAO_VISION, RPASCENE_USE_GEMINI, RPASCENE_USE_QWEN3_VL, RPASCENE_USE_QWEN_VL, RPASCENE_USE_VLM_UI_TARS, UITarsModelVersion, VL_MODE_RAW_VALID_VALUES } from "./types.mjs";
|
|
2
|
+
const parseVlModeAndUiTarsModelVersionFromRawValue = (vlModeRaw)=>{
|
|
3
|
+
if (!vlModeRaw) return {
|
|
4
|
+
vlMode: void 0,
|
|
5
|
+
uiTarsVersion: void 0
|
|
6
|
+
};
|
|
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}`);
|
|
8
|
+
const raw = vlModeRaw;
|
|
9
|
+
if ('vlm-ui-tars' === raw) return {
|
|
10
|
+
vlMode: 'vlm-ui-tars',
|
|
11
|
+
uiTarsVersion: UITarsModelVersion.V1_0
|
|
12
|
+
};
|
|
13
|
+
if ('vlm-ui-tars-doubao' === raw || 'vlm-ui-tars-doubao-1.5' === raw) return {
|
|
14
|
+
vlMode: 'vlm-ui-tars',
|
|
15
|
+
uiTarsVersion: UITarsModelVersion.DOUBAO_1_5_20B
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
vlMode: raw,
|
|
19
|
+
uiTarsVersion: void 0
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const parseVlModeAndUiTarsFromGlobalConfig = (provider)=>{
|
|
23
|
+
const isDoubao = provider[RPASCENE_USE_DOUBAO_VISION];
|
|
24
|
+
const isQwen = provider[RPASCENE_USE_QWEN_VL];
|
|
25
|
+
const isQwen3 = provider[RPASCENE_USE_QWEN3_VL];
|
|
26
|
+
const isUiTars = provider[RPASCENE_USE_VLM_UI_TARS];
|
|
27
|
+
const isGemini = provider[RPASCENE_USE_GEMINI];
|
|
28
|
+
const enabledModes = [
|
|
29
|
+
isDoubao && RPASCENE_USE_DOUBAO_VISION,
|
|
30
|
+
isQwen && RPASCENE_USE_QWEN_VL,
|
|
31
|
+
isQwen3 && RPASCENE_USE_QWEN3_VL,
|
|
32
|
+
isUiTars && RPASCENE_USE_VLM_UI_TARS,
|
|
33
|
+
isGemini && RPASCENE_USE_GEMINI
|
|
34
|
+
].filter(Boolean);
|
|
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
|
+
if (isQwen3) return {
|
|
37
|
+
vlMode: 'qwen3-vl',
|
|
38
|
+
uiTarsVersion: void 0
|
|
39
|
+
};
|
|
40
|
+
if (isQwen) return {
|
|
41
|
+
vlMode: 'qwen-vl',
|
|
42
|
+
uiTarsVersion: void 0
|
|
43
|
+
};
|
|
44
|
+
if (isDoubao) return {
|
|
45
|
+
vlMode: 'doubao-vision',
|
|
46
|
+
uiTarsVersion: void 0
|
|
47
|
+
};
|
|
48
|
+
if (isGemini) return {
|
|
49
|
+
vlMode: 'gemini',
|
|
50
|
+
uiTarsVersion: void 0
|
|
51
|
+
};
|
|
52
|
+
if (isUiTars) if ('1' === isUiTars) return {
|
|
53
|
+
vlMode: 'vlm-ui-tars',
|
|
54
|
+
uiTarsVersion: UITarsModelVersion.V1_0
|
|
55
|
+
};
|
|
56
|
+
else if ('DOUBAO' === isUiTars || 'DOUBAO-1.5' === isUiTars) return {
|
|
57
|
+
vlMode: 'vlm-ui-tars',
|
|
58
|
+
uiTarsVersion: UITarsModelVersion.DOUBAO_1_5_20B
|
|
59
|
+
};
|
|
60
|
+
else return {
|
|
61
|
+
vlMode: 'vlm-ui-tars',
|
|
62
|
+
uiTarsVersion: `${isUiTars}`
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
vlMode: void 0,
|
|
66
|
+
uiTarsVersion: void 0
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export { parseVlModeAndUiTarsFromGlobalConfig, parseVlModeAndUiTarsModelVersionFromRawValue };
|