@midscene/cli 1.10.2 → 1.10.4-beta-20260707113337.0
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/index.mjs +193 -17
- package/dist/es/index.mjs.map +1 -1
- package/dist/lib/index.js +195 -17
- package/dist/lib/index.js.map +1 -1
- package/package.json +8 -8
package/dist/lib/index.js
CHANGED
|
@@ -4706,16 +4706,12 @@ defineYamlBatchTest(test, testOptions);
|
|
|
4706
4706
|
},
|
|
4707
4707
|
"./src/index.ts" (__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
|
|
4708
4708
|
"use strict";
|
|
4709
|
+
var core_ = __webpack_require__("@midscene/core");
|
|
4710
|
+
const cli_namespaceObject = require("@midscene/shared/cli");
|
|
4711
|
+
var package_namespaceObject = JSON.parse('{"rE":"1.10.4-beta-20260707113337.0"}');
|
|
4709
4712
|
var external_node_fs_ = __webpack_require__("node:fs");
|
|
4710
4713
|
var external_node_fs_namespaceObject = /*#__PURE__*/ __webpack_require__.t(external_node_fs_, 2);
|
|
4711
4714
|
var external_node_path_ = __webpack_require__("node:path");
|
|
4712
|
-
var core_ = __webpack_require__("@midscene/core");
|
|
4713
|
-
const cli_namespaceObject = require("@midscene/shared/cli");
|
|
4714
|
-
var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js");
|
|
4715
|
-
var main_default = /*#__PURE__*/ __webpack_require__.n(main);
|
|
4716
|
-
var package_namespaceObject = {
|
|
4717
|
-
rE: "1.10.2"
|
|
4718
|
-
};
|
|
4719
4715
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
4720
4716
|
var brace_expansion = __webpack_require__("../../node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js");
|
|
4721
4717
|
const MAX_PATTERN_LENGTH = 65536;
|
|
@@ -12587,7 +12583,7 @@ Usage:
|
|
|
12587
12583
|
type: 'boolean',
|
|
12588
12584
|
description: `Turn on logging to help debug why certain keys or values are not being set as you expect, default is ${config_factory_defaultConfig.dotenvDebug}`
|
|
12589
12585
|
}
|
|
12590
|
-
}).version('version', 'Show version number', "1.10.
|
|
12586
|
+
}).version('version', 'Show version number', "1.10.4-beta-20260707113337.0").help().epilogue(`For complete list of configuration options, please visit:
|
|
12591
12587
|
• Web options: https://midscenejs.com/automate-with-scripts-in-yaml#the-web-part
|
|
12592
12588
|
• Android options: https://midscenejs.com/automate-with-scripts-in-yaml#the-android-part
|
|
12593
12589
|
• iOS options: https://midscenejs.com/automate-with-scripts-in-yaml#the-ios-part
|
|
@@ -12635,7 +12631,188 @@ Examples:
|
|
|
12635
12631
|
});
|
|
12636
12632
|
return files.filter((file)=>file.endsWith('.yml') || file.endsWith('.yaml')).sort();
|
|
12637
12633
|
}
|
|
12634
|
+
var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js");
|
|
12635
|
+
var main_default = /*#__PURE__*/ __webpack_require__.n(main);
|
|
12636
|
+
function loadDotenvConfig(options = {}) {
|
|
12637
|
+
const dotEnvConfigFile = (0, external_node_path_.join)(options.cwd ?? process.cwd(), '.env');
|
|
12638
|
+
if (!(0, external_node_fs_.existsSync)(dotEnvConfigFile)) return;
|
|
12639
|
+
options.log?.(` Env file: ${dotEnvConfigFile}`);
|
|
12640
|
+
main_default().config({
|
|
12641
|
+
path: dotEnvConfigFile,
|
|
12642
|
+
debug: options.dotenvDebug,
|
|
12643
|
+
override: options.dotenvOverride
|
|
12644
|
+
});
|
|
12645
|
+
}
|
|
12638
12646
|
var framework = __webpack_require__("./src/framework/index.ts");
|
|
12647
|
+
const env_namespaceObject = require("@midscene/shared/env");
|
|
12648
|
+
var chalk_source = __webpack_require__("../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js");
|
|
12649
|
+
var source_default = /*#__PURE__*/ __webpack_require__.n(chalk_source);
|
|
12650
|
+
const DEFAULT_OPENAI_BASE_URL = 'https://api.openai.com/v1';
|
|
12651
|
+
const MODEL_VERIFY_SEPARATOR = '────────────────────────────────────────';
|
|
12652
|
+
const MODEL_COMMAND_USAGE = `Usage:
|
|
12653
|
+
midscene model verify
|
|
12654
|
+
midscene model eval
|
|
12655
|
+
`;
|
|
12656
|
+
function assertNoModelVerifyOptions(args) {
|
|
12657
|
+
for (const arg of args)throw new Error(`Unknown option for midscene model verify: ${arg}`);
|
|
12658
|
+
}
|
|
12659
|
+
function shellSingleQuote(value) {
|
|
12660
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
12661
|
+
}
|
|
12662
|
+
function buildChatCompletionsUrl(baseURL) {
|
|
12663
|
+
const normalizedBaseURL = (baseURL || DEFAULT_OPENAI_BASE_URL).replace(/\/+$/, '');
|
|
12664
|
+
if (normalizedBaseURL.endsWith('/chat/completions')) return normalizedBaseURL;
|
|
12665
|
+
return `${normalizedBaseURL}/chat/completions`;
|
|
12666
|
+
}
|
|
12667
|
+
function buildCurlCommand(modelConfig) {
|
|
12668
|
+
const payload = {
|
|
12669
|
+
model: modelConfig.modelName,
|
|
12670
|
+
messages: [
|
|
12671
|
+
{
|
|
12672
|
+
role: 'user',
|
|
12673
|
+
content: 'What is 1+1?'
|
|
12674
|
+
}
|
|
12675
|
+
]
|
|
12676
|
+
};
|
|
12677
|
+
return [
|
|
12678
|
+
`curl -X POST ${shellSingleQuote(buildChatCompletionsUrl(modelConfig.openaiBaseURL))} \\`,
|
|
12679
|
+
` -H ${shellSingleQuote(`Authorization: Bearer ${modelConfig.openaiApiKey || ''}`)} \\`,
|
|
12680
|
+
` -H ${shellSingleQuote('Content-Type: application/json')} \\`,
|
|
12681
|
+
` -d ${shellSingleQuote(JSON.stringify(payload, null, 2))}`
|
|
12682
|
+
].join('\n');
|
|
12683
|
+
}
|
|
12684
|
+
function buildCurlDedupKey(modelConfig) {
|
|
12685
|
+
return JSON.stringify({
|
|
12686
|
+
baseURL: modelConfig.openaiBaseURL || DEFAULT_OPENAI_BASE_URL,
|
|
12687
|
+
apiKey: modelConfig.openaiApiKey || '',
|
|
12688
|
+
modelName: modelConfig.modelName
|
|
12689
|
+
});
|
|
12690
|
+
}
|
|
12691
|
+
function buildModelVerifyCurlCommands(configs) {
|
|
12692
|
+
const commandMap = new Map();
|
|
12693
|
+
for (const item of configs){
|
|
12694
|
+
const key = buildCurlDedupKey(item.modelConfig);
|
|
12695
|
+
const existing = commandMap.get(key);
|
|
12696
|
+
if (existing) {
|
|
12697
|
+
existing.intents.push(item.intent);
|
|
12698
|
+
continue;
|
|
12699
|
+
}
|
|
12700
|
+
commandMap.set(key, {
|
|
12701
|
+
intents: [
|
|
12702
|
+
item.intent
|
|
12703
|
+
],
|
|
12704
|
+
curl: buildCurlCommand(item.modelConfig),
|
|
12705
|
+
usesDefaultBaseURL: !item.modelConfig.openaiBaseURL
|
|
12706
|
+
});
|
|
12707
|
+
}
|
|
12708
|
+
return [
|
|
12709
|
+
...commandMap.values()
|
|
12710
|
+
];
|
|
12711
|
+
}
|
|
12712
|
+
function formatModelVerifyFailureOutput(message, curlCommands) {
|
|
12713
|
+
const details = message?.trim() || 'No failure details were generated.';
|
|
12714
|
+
const curlSection = curlCommands.map((item)=>{
|
|
12715
|
+
const baseUrlNote = item.usesDefaultBaseURL ? ' (base URL not configured; using OpenAI SDK default)' : '';
|
|
12716
|
+
return source_default().gray(`# ${item.intents.join(', ')}${baseUrlNote}\n${item.curl}`);
|
|
12717
|
+
}).join('\n\n');
|
|
12718
|
+
return [
|
|
12719
|
+
source_default().red.bold('❌ Model verify failed with messages:'),
|
|
12720
|
+
MODEL_VERIFY_SEPARATOR,
|
|
12721
|
+
'',
|
|
12722
|
+
details,
|
|
12723
|
+
'',
|
|
12724
|
+
MODEL_VERIFY_SEPARATOR,
|
|
12725
|
+
'Generated curl requests for basic API connectivity:',
|
|
12726
|
+
'If the error is a basic connectivity issue, use these requests to test the base URL, API key, and model name directly.',
|
|
12727
|
+
'These commands contain your API key. Do not share them publicly.',
|
|
12728
|
+
'',
|
|
12729
|
+
curlSection
|
|
12730
|
+
].join('\n');
|
|
12731
|
+
}
|
|
12732
|
+
function getDefaultDeps(io) {
|
|
12733
|
+
return {
|
|
12734
|
+
loadDotenv: ()=>{
|
|
12735
|
+
loadDotenvConfig({
|
|
12736
|
+
dotenvDebug: true,
|
|
12737
|
+
dotenvOverride: true,
|
|
12738
|
+
log: io.stdout
|
|
12739
|
+
});
|
|
12740
|
+
},
|
|
12741
|
+
getModelConfig: (intent)=>env_namespaceObject.globalModelConfigManager.getModelConfig(intent),
|
|
12742
|
+
verifyModel: core_.runConnectivityTest
|
|
12743
|
+
};
|
|
12744
|
+
}
|
|
12745
|
+
async function runModelVerifyCommand(args, deps, io) {
|
|
12746
|
+
try {
|
|
12747
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
12748
|
+
io.stdout(MODEL_COMMAND_USAGE);
|
|
12749
|
+
return 0;
|
|
12750
|
+
}
|
|
12751
|
+
assertNoModelVerifyOptions(args);
|
|
12752
|
+
io.stdout('Model verify started. This usually takes about 5 seconds.\n');
|
|
12753
|
+
deps.loadDotenv();
|
|
12754
|
+
io.stdout('');
|
|
12755
|
+
const defaultModelConfig = deps.getModelConfig('default');
|
|
12756
|
+
const planningModelConfig = deps.getModelConfig('planning');
|
|
12757
|
+
const insightModelConfig = deps.getModelConfig('insight');
|
|
12758
|
+
const curlCommands = buildModelVerifyCurlCommands([
|
|
12759
|
+
{
|
|
12760
|
+
intent: 'default',
|
|
12761
|
+
modelConfig: defaultModelConfig
|
|
12762
|
+
},
|
|
12763
|
+
{
|
|
12764
|
+
intent: 'planning',
|
|
12765
|
+
modelConfig: planningModelConfig
|
|
12766
|
+
},
|
|
12767
|
+
{
|
|
12768
|
+
intent: 'insight',
|
|
12769
|
+
modelConfig: insightModelConfig
|
|
12770
|
+
}
|
|
12771
|
+
]);
|
|
12772
|
+
const result = await deps.verifyModel({
|
|
12773
|
+
defaultModelConfig,
|
|
12774
|
+
planningModelConfig,
|
|
12775
|
+
insightModelConfig
|
|
12776
|
+
});
|
|
12777
|
+
if (result.passed) {
|
|
12778
|
+
io.stdout('✅ Model verify passed.');
|
|
12779
|
+
return 0;
|
|
12780
|
+
}
|
|
12781
|
+
io.stderr(formatModelVerifyFailureOutput(result.message, curlCommands));
|
|
12782
|
+
return 1;
|
|
12783
|
+
} catch (error) {
|
|
12784
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12785
|
+
io.stderr([
|
|
12786
|
+
MODEL_VERIFY_SEPARATOR,
|
|
12787
|
+
'❌ Model verify failed with messages:',
|
|
12788
|
+
'',
|
|
12789
|
+
message,
|
|
12790
|
+
MODEL_VERIFY_SEPARATOR
|
|
12791
|
+
].join('\n'));
|
|
12792
|
+
return 1;
|
|
12793
|
+
}
|
|
12794
|
+
}
|
|
12795
|
+
async function runModelCommand(rawArgs, deps, io = {
|
|
12796
|
+
stdout: console.log,
|
|
12797
|
+
stderr: console.error
|
|
12798
|
+
}) {
|
|
12799
|
+
const [, action, ...restArgs] = rawArgs;
|
|
12800
|
+
const mergedDeps = {
|
|
12801
|
+
...getDefaultDeps(io),
|
|
12802
|
+
...deps
|
|
12803
|
+
};
|
|
12804
|
+
if (!action || '--help' === action || '-h' === action) {
|
|
12805
|
+
io.stdout(MODEL_COMMAND_USAGE);
|
|
12806
|
+
return 0;
|
|
12807
|
+
}
|
|
12808
|
+
if ('verify' === action) return runModelVerifyCommand(restArgs, mergedDeps, io);
|
|
12809
|
+
if ('eval' === action) {
|
|
12810
|
+
io.stderr('midscene model eval is not implemented yet. It is reserved for future model evaluation suites.');
|
|
12811
|
+
return 1;
|
|
12812
|
+
}
|
|
12813
|
+
io.stderr(`Unknown midscene model command: ${action}\n\n${MODEL_COMMAND_USAGE}`);
|
|
12814
|
+
return 1;
|
|
12815
|
+
}
|
|
12639
12816
|
Promise.resolve((async ()=>{
|
|
12640
12817
|
const rawArgs = process.argv.slice(2);
|
|
12641
12818
|
const [firstArg] = rawArgs;
|
|
@@ -12648,6 +12825,11 @@ Examples:
|
|
|
12648
12825
|
version: package_namespaceObject.rE,
|
|
12649
12826
|
extraCommands: (0, core_.createReportCliCommands)()
|
|
12650
12827
|
});
|
|
12828
|
+
if ('model' === firstArg) {
|
|
12829
|
+
const exitCode = await runModelCommand(rawArgs);
|
|
12830
|
+
process.exit(exitCode);
|
|
12831
|
+
return;
|
|
12832
|
+
}
|
|
12651
12833
|
const { options, path, files: cmdFiles } = await parseProcessArgs();
|
|
12652
12834
|
const welcome = `\nWelcome to @midscene/cli v${package_namespaceObject.rE}\n`;
|
|
12653
12835
|
console.log(welcome);
|
|
@@ -12696,15 +12878,11 @@ Examples:
|
|
|
12696
12878
|
console.error('Could not create a valid configuration.');
|
|
12697
12879
|
process.exit(1);
|
|
12698
12880
|
}
|
|
12699
|
-
|
|
12700
|
-
|
|
12701
|
-
|
|
12702
|
-
|
|
12703
|
-
|
|
12704
|
-
debug: config.dotenvDebug,
|
|
12705
|
-
override: config.dotenvOverride
|
|
12706
|
-
});
|
|
12707
|
-
}
|
|
12881
|
+
loadDotenvConfig({
|
|
12882
|
+
dotenvDebug: config.dotenvDebug,
|
|
12883
|
+
dotenvOverride: config.dotenvOverride,
|
|
12884
|
+
log: console.log
|
|
12885
|
+
});
|
|
12708
12886
|
const exitCode = await (0, framework.runFrameworkTestConfig)(config);
|
|
12709
12887
|
if (config.keepWindow) setInterval(()=>{
|
|
12710
12888
|
console.log('browser is still running, use ctrl+c to stop it');
|