@aiscene/shared 8.0.2 → 8.0.4
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/agent-tools/agent-behavior-init-args.mjs +44 -0
- package/dist/es/agent-tools/base-tools.mjs +163 -0
- package/dist/es/agent-tools/chrome-path.mjs +50 -0
- package/dist/es/agent-tools/cli-report-session.mjs +78 -0
- package/dist/es/agent-tools/error-formatter.mjs +106 -0
- package/dist/es/agent-tools/index.mjs +9 -0
- package/dist/es/agent-tools/init-arg-utils.mjs +38 -0
- package/dist/es/agent-tools/observation-artifact.mjs +5 -0
- package/dist/es/agent-tools/observation-record.mjs +248 -0
- package/dist/es/agent-tools/tool-defaults.mjs +54 -0
- package/dist/es/agent-tools/tool-generator.mjs +529 -0
- package/dist/es/agent-tools/types.mjs +3 -0
- package/dist/es/agent-tools/user-prompt.mjs +66 -0
- package/dist/es/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +10 -40
- package/dist/es/cli/index.mjs +4 -2
- package/dist/es/cli/interrupt.mjs +116 -0
- package/dist/es/cli/record-command.mjs +130 -0
- package/dist/es/cli/screenshot-file.mjs +24 -0
- package/dist/es/cli/verbose-ai-act.mjs +230 -0
- package/dist/es/cli/verbose-screenshot.mjs +134 -0
- package/dist/es/cli/verbose.mjs +404 -0
- package/dist/es/constants/example-code.mjs +2 -2
- package/dist/es/constants/index.mjs +6 -1
- package/dist/es/env/model-config-manager.mjs +3 -0
- package/dist/es/env/parse-model-config.mjs +6 -1
- package/dist/es/env/types.mjs +4 -1
- package/dist/es/env/utils.mjs +1 -9
- package/dist/es/extractor/index.mjs +2 -2
- package/dist/es/img/index.mjs +2 -2
- package/dist/es/img/info.mjs +58 -17
- package/dist/es/img/photon-loader.mjs +4 -0
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/mcp/base-server.mjs +10 -9
- package/dist/es/mcp/base-tools.mjs +72 -4
- package/dist/es/mcp/cli-report-session.mjs +78 -0
- package/dist/es/mcp/error-formatter.mjs +19 -0
- package/dist/es/mcp/index.mjs +2 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +1 -1
- package/dist/es/mcp/tool-generator.mjs +65 -17
- package/dist/es/node/fs.mjs +1 -1
- package/dist/es/recorder.mjs +249 -0
- package/dist/lib/agent-tools/agent-behavior-init-args.js +87 -0
- package/dist/lib/agent-tools/base-tools.js +197 -0
- package/dist/lib/agent-tools/chrome-path.js +87 -0
- package/dist/lib/agent-tools/cli-report-session.js +121 -0
- package/dist/lib/agent-tools/error-formatter.js +149 -0
- package/dist/lib/agent-tools/index.js +114 -0
- package/dist/lib/agent-tools/init-arg-utils.js +78 -0
- package/dist/lib/agent-tools/observation-artifact.js +42 -0
- package/dist/lib/agent-tools/observation-record.js +297 -0
- package/dist/lib/agent-tools/tool-defaults.js +97 -0
- package/dist/lib/agent-tools/tool-generator.js +569 -0
- package/dist/lib/agent-tools/types.js +40 -0
- package/dist/lib/agent-tools/user-prompt.js +103 -0
- package/dist/lib/cli/cli-args.js +138 -0
- package/dist/lib/cli/cli-error.js +61 -0
- package/dist/lib/cli/cli-runner.js +19 -46
- package/dist/lib/cli/index.js +8 -3
- package/dist/lib/cli/interrupt.js +156 -0
- package/dist/lib/cli/record-command.js +164 -0
- package/dist/lib/cli/screenshot-file.js +58 -0
- package/dist/lib/cli/verbose-ai-act.js +273 -0
- package/dist/lib/cli/verbose-screenshot.js +177 -0
- package/dist/lib/cli/verbose.js +465 -0
- package/dist/lib/constants/example-code.js +2 -2
- package/dist/lib/constants/index.js +23 -3
- package/dist/lib/env/model-config-manager.js +3 -0
- package/dist/lib/env/parse-model-config.js +6 -1
- package/dist/lib/env/types.js +9 -0
- package/dist/lib/env/utils.js +0 -11
- package/dist/lib/extractor/index.js +3 -0
- package/dist/lib/img/index.js +3 -0
- package/dist/lib/img/info.js +65 -18
- package/dist/lib/img/photon-loader.js +38 -0
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/mcp/base-server.js +11 -10
- package/dist/lib/mcp/base-tools.js +74 -6
- package/dist/lib/mcp/cli-report-session.js +121 -0
- package/dist/lib/mcp/error-formatter.js +53 -0
- package/dist/lib/mcp/index.js +24 -10
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +1 -1
- package/dist/lib/mcp/tool-generator.js +74 -26
- package/dist/lib/node/fs.js +1 -1
- package/dist/lib/recorder.js +307 -0
- package/dist/types/agent-tools/agent-behavior-init-args.d.ts +17 -0
- package/dist/types/agent-tools/base-tools.d.ts +158 -0
- package/dist/types/agent-tools/chrome-path.d.ts +2 -0
- package/dist/types/agent-tools/cli-report-session.d.ts +12 -0
- package/dist/types/agent-tools/error-formatter.d.ts +30 -0
- package/dist/types/agent-tools/index.d.ts +9 -0
- package/dist/types/agent-tools/init-arg-utils.d.ts +13 -0
- package/dist/types/agent-tools/observation-artifact.d.ts +10 -0
- package/dist/types/agent-tools/observation-record.d.ts +38 -0
- package/dist/types/agent-tools/tool-defaults.d.ts +63 -0
- package/dist/types/agent-tools/tool-generator.d.ts +13 -0
- package/dist/types/agent-tools/types.d.ts +213 -0
- package/dist/types/agent-tools/user-prompt.d.ts +13 -0
- package/dist/types/cli/cli-args.d.ts +8 -0
- package/dist/types/cli/cli-error.d.ts +5 -0
- package/dist/types/cli/cli-runner.d.ts +4 -7
- package/dist/types/cli/index.d.ts +3 -1
- package/dist/types/cli/interrupt.d.ts +49 -0
- package/dist/types/cli/record-command.d.ts +3 -0
- package/dist/types/cli/screenshot-file.d.ts +10 -0
- package/dist/types/cli/verbose-ai-act.d.ts +44 -0
- package/dist/types/cli/verbose-screenshot.d.ts +10 -0
- package/dist/types/cli/verbose.d.ts +40 -0
- package/dist/types/constants/example-code.d.ts +1 -1
- package/dist/types/constants/index.d.ts +5 -0
- package/dist/types/env/types.d.ts +14 -5
- package/dist/types/env/utils.d.ts +0 -31
- package/dist/types/extractor/index.d.ts +1 -1
- package/dist/types/img/index.d.ts +1 -1
- package/dist/types/img/info.d.ts +7 -0
- package/dist/types/img/photon-loader.d.ts +2 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/mcp/base-tools.d.ts +74 -5
- package/dist/types/mcp/cli-report-session.d.ts +12 -0
- package/dist/types/mcp/error-formatter.d.ts +12 -0
- package/dist/types/mcp/index.d.ts +2 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +2 -2
- package/dist/types/mcp/launcher-helper.d.ts +3 -3
- package/dist/types/mcp/tool-generator.d.ts +3 -3
- package/dist/types/mcp/types.d.ts +10 -0
- package/dist/types/recorder.d.ts +113 -0
- package/package.json +1 -1
- package/src/agent-tools/agent-behavior-init-args.ts +109 -0
- package/src/agent-tools/base-tools.ts +399 -0
- package/src/agent-tools/chrome-path.ts +74 -0
- package/src/agent-tools/cli-report-session.ts +130 -0
- package/src/agent-tools/error-formatter.ts +177 -0
- package/src/agent-tools/index.ts +9 -0
- package/src/agent-tools/init-arg-utils.ts +105 -0
- package/src/agent-tools/observation-artifact.ts +29 -0
- package/src/agent-tools/observation-record.ts +331 -0
- package/src/agent-tools/tool-defaults.ts +119 -0
- package/src/agent-tools/tool-generator.ts +866 -0
- package/src/agent-tools/types.ts +250 -0
- package/src/agent-tools/user-prompt.ts +102 -0
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +37 -56
- package/src/cli/index.ts +3 -7
- package/src/cli/interrupt.ts +207 -0
- package/src/cli/record-command.ts +177 -0
- package/src/cli/screenshot-file.ts +61 -0
- package/src/cli/verbose-ai-act.ts +387 -0
- package/src/cli/verbose-screenshot.ts +269 -0
- package/src/cli/verbose.ts +753 -0
- package/src/constants/example-code.ts +2 -2
- package/src/constants/index.ts +10 -0
- package/src/env/model-config-manager.ts +3 -0
- package/src/env/parse-model-config.ts +19 -1
- package/src/env/types.ts +13 -2
- package/src/env/utils.ts +0 -50
- package/src/extractor/index.ts +1 -1
- package/src/img/index.ts +14 -0
- package/src/img/info.ts +97 -45
- package/src/img/photon-loader.ts +5 -0
- package/src/img/transform.ts +261 -2
- package/src/key-alias-utils.ts +23 -0
- package/src/mcp/base-server.ts +10 -12
- package/src/mcp/base-tools.ts +218 -11
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +3 -3
- package/src/mcp/launcher-helper.ts +3 -3
- package/src/mcp/tool-generator.ts +98 -20
- package/src/mcp/types.ts +18 -1
- package/src/recorder.ts +625 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { basename, dirname, isAbsolute, join, relative } from "node:path";
|
|
2
|
+
import { writeCliScreenshotFile } from "./screenshot-file.mjs";
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
function isCliVerboseScreenshotRefLike(value) {
|
|
7
|
+
return isRecord(value) && 'midscene_screenshot_ref' === value.type;
|
|
8
|
+
}
|
|
9
|
+
function toSerializableScreenshot(value) {
|
|
10
|
+
if (!value || 'object' != typeof value) return null;
|
|
11
|
+
const maybeSerializable = value;
|
|
12
|
+
if ('function' == typeof maybeSerializable.toSerializable) try {
|
|
13
|
+
const serialized = maybeSerializable.toSerializable();
|
|
14
|
+
return isCliVerboseScreenshotRefLike(serialized) ? serialized : null;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return isCliVerboseScreenshotRefLike(value) ? value : null;
|
|
19
|
+
}
|
|
20
|
+
function getStringProperty(value, key) {
|
|
21
|
+
if (!isRecord(value)) return;
|
|
22
|
+
try {
|
|
23
|
+
const property = value[key];
|
|
24
|
+
return 'string' == typeof property && property.length > 0 ? property : void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function screenshotRawBase64(value) {
|
|
30
|
+
const rawBase64 = getStringProperty(value, 'rawBase64');
|
|
31
|
+
if (rawBase64) return rawBase64;
|
|
32
|
+
const base64 = getStringProperty(value, 'base64');
|
|
33
|
+
const match = base64?.match(/^data:image\/(?:png|jpeg|jpg);base64,(.+)$/);
|
|
34
|
+
return match?.[1];
|
|
35
|
+
}
|
|
36
|
+
function inlineScreenshotCacheKey(rawBase64, serialized, directoryPath, directoryName, extension) {
|
|
37
|
+
return JSON.stringify([
|
|
38
|
+
serialized.id,
|
|
39
|
+
serialized.mimeType,
|
|
40
|
+
directoryPath,
|
|
41
|
+
directoryName,
|
|
42
|
+
extension,
|
|
43
|
+
rawBase64
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
function exportInlineScreenshotForVerbose(value, serialized, options) {
|
|
47
|
+
if ('string' == typeof serialized.path) return serialized.path;
|
|
48
|
+
const exportMode = options.exportMode ?? 'tmp';
|
|
49
|
+
if ('none' === exportMode) return;
|
|
50
|
+
const rawBase64 = screenshotRawBase64(value);
|
|
51
|
+
if (!rawBase64) return;
|
|
52
|
+
const directoryPath = 'report' === exportMode && 'string' == typeof options.reportFile && options.reportFile.length > 0 ? join(dirname(options.reportFile), 'screenshots') : void 0;
|
|
53
|
+
const directoryName = directoryPath ? void 0 : 'midscene-cli-screenshots';
|
|
54
|
+
const extension = getStringProperty(value, 'extension');
|
|
55
|
+
const cacheKey = inlineScreenshotCacheKey(rawBase64, serialized, directoryPath, directoryName, extension);
|
|
56
|
+
const cachedPath = options.cache?.get(cacheKey);
|
|
57
|
+
if (cachedPath) return cachedPath;
|
|
58
|
+
try {
|
|
59
|
+
const path = writeCliScreenshotFile(rawBase64, {
|
|
60
|
+
id: serialized.id,
|
|
61
|
+
mimeType: serialized.mimeType,
|
|
62
|
+
extension,
|
|
63
|
+
...directoryPath ? {
|
|
64
|
+
directoryPath
|
|
65
|
+
} : {
|
|
66
|
+
directoryName
|
|
67
|
+
},
|
|
68
|
+
overwrite: false
|
|
69
|
+
});
|
|
70
|
+
options.cache?.set(cacheKey, path);
|
|
71
|
+
return path;
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function collectScreenshotRefs(value, options = {}) {
|
|
77
|
+
const screenshots = [];
|
|
78
|
+
const visit = (candidate, timing)=>{
|
|
79
|
+
if (Array.isArray(candidate)) {
|
|
80
|
+
for (const item of candidate)visit(item, timing);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const serialized = toSerializableScreenshot(candidate);
|
|
84
|
+
if (serialized?.type === 'midscene_screenshot_ref') {
|
|
85
|
+
const screenshot = {
|
|
86
|
+
id: serialized.id,
|
|
87
|
+
storage: serialized.storage
|
|
88
|
+
};
|
|
89
|
+
const exportedPath = exportInlineScreenshotForVerbose(candidate, serialized, options);
|
|
90
|
+
if (exportedPath) {
|
|
91
|
+
screenshot.path = exportedPath;
|
|
92
|
+
screenshot.file = basename(exportedPath);
|
|
93
|
+
}
|
|
94
|
+
if ('string' == typeof timing) screenshot.timing = timing;
|
|
95
|
+
screenshots.push(screenshot);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!isRecord(candidate)) return;
|
|
99
|
+
const screenshotRecord = candidate.screenshot;
|
|
100
|
+
if (screenshotRecord) visit(screenshotRecord, candidate.timing);
|
|
101
|
+
if (candidate.recorder) visit(candidate.recorder);
|
|
102
|
+
if (isRecord(candidate.uiContext)) visit(candidate.uiContext.screenshot);
|
|
103
|
+
};
|
|
104
|
+
visit(value);
|
|
105
|
+
return screenshots;
|
|
106
|
+
}
|
|
107
|
+
function pathForReportScreenshot(path, reportFile) {
|
|
108
|
+
const resolvedPath = 'string' == typeof reportFile && reportFile.length > 0 && (path.startsWith('./') || path.startsWith('../')) ? join(dirname(reportFile), path) : path;
|
|
109
|
+
if (!isAbsolute(resolvedPath)) return resolvedPath;
|
|
110
|
+
const relativePath = relative(process.cwd(), resolvedPath);
|
|
111
|
+
if (relativePath && !relativePath.startsWith('..') && !isAbsolute(relativePath)) return relativePath;
|
|
112
|
+
return resolvedPath;
|
|
113
|
+
}
|
|
114
|
+
function latestScreenshotPathForAiAct(value, options = {}) {
|
|
115
|
+
const screenshot = collectScreenshotRefs(value, {
|
|
116
|
+
...options,
|
|
117
|
+
exportMode: options.exportMode ?? 'report'
|
|
118
|
+
}).slice().reverse().find((item)=>'string' == typeof item.path && item.path.length > 0);
|
|
119
|
+
const path = 'string' == typeof screenshot?.path ? screenshot.path : '';
|
|
120
|
+
return path ? pathForReportScreenshot(path, options.reportFile) : '';
|
|
121
|
+
}
|
|
122
|
+
function renderScreenshotList(screenshots) {
|
|
123
|
+
if (!Array.isArray(screenshots) || 0 === screenshots.length) return '';
|
|
124
|
+
return screenshots.map((item)=>{
|
|
125
|
+
if (!isRecord(item)) return '';
|
|
126
|
+
const path = 'string' == typeof item.path ? item.path : 'string' == typeof item.file ? item.file : 'string' == typeof item.id ? item.id : '';
|
|
127
|
+
const timing = 'string' == typeof item.timing ? item.timing : '';
|
|
128
|
+
return [
|
|
129
|
+
timing,
|
|
130
|
+
path
|
|
131
|
+
].filter(Boolean).join(' ');
|
|
132
|
+
}).filter(Boolean).join(', ');
|
|
133
|
+
}
|
|
134
|
+
export { collectScreenshotRefs, latestScreenshotPathForAiAct, pathForReportScreenshot, renderScreenshotList };
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { aiActCliProgressRenderer, cliAiActProgressScope } from "./verbose-ai-act.mjs";
|
|
2
|
+
import { collectScreenshotRefs, renderScreenshotList } from "./verbose-screenshot.mjs";
|
|
3
|
+
const cliVerboseFlag = 'verbose';
|
|
4
|
+
const progressRenderers = {
|
|
5
|
+
[cliAiActProgressScope]: aiActCliProgressRenderer
|
|
6
|
+
};
|
|
7
|
+
function progressRendererForEvent(event) {
|
|
8
|
+
if ('object' != typeof event || null === event) return;
|
|
9
|
+
const scope = event.scope;
|
|
10
|
+
if ('string' != typeof scope) return;
|
|
11
|
+
const renderer = progressRenderers[scope];
|
|
12
|
+
return renderer ? {
|
|
13
|
+
scope,
|
|
14
|
+
renderer
|
|
15
|
+
} : void 0;
|
|
16
|
+
}
|
|
17
|
+
const progressEventName = 'midscene_progress';
|
|
18
|
+
const cliVerboseContextKey = '__midscene_cli_verbose_context__';
|
|
19
|
+
const getGlobalContext = ()=>{
|
|
20
|
+
const globalWithContext = globalThis;
|
|
21
|
+
if (!globalWithContext[cliVerboseContextKey]) globalWithContext[cliVerboseContextKey] = {
|
|
22
|
+
current: {
|
|
23
|
+
enabled: false
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return globalWithContext[cliVerboseContextKey];
|
|
27
|
+
};
|
|
28
|
+
function parseVerboseFormat(rawFormat) {
|
|
29
|
+
if ('text' === rawFormat || 'jsonl' === rawFormat) return rawFormat;
|
|
30
|
+
throw new Error(`Unsupported --${cliVerboseFlag} format "${rawFormat}". Use "--${cliVerboseFlag}" or "--${cliVerboseFlag}=jsonl".`);
|
|
31
|
+
}
|
|
32
|
+
function stripVerboseFlag(argv) {
|
|
33
|
+
const rawArgs = [];
|
|
34
|
+
let verbose = false;
|
|
35
|
+
let format = 'text';
|
|
36
|
+
for (const arg of argv){
|
|
37
|
+
if (arg === `--${cliVerboseFlag}`) {
|
|
38
|
+
verbose = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (arg.startsWith(`--${cliVerboseFlag}=`)) {
|
|
42
|
+
verbose = true;
|
|
43
|
+
format = parseVerboseFormat(arg.slice(`--${cliVerboseFlag}=`.length));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
rawArgs.push(arg);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
rawArgs,
|
|
50
|
+
verbose,
|
|
51
|
+
format
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function withCliVerboseContext(context, fn) {
|
|
55
|
+
const globalContext = getGlobalContext();
|
|
56
|
+
const previous = globalContext.current;
|
|
57
|
+
globalContext.current = {
|
|
58
|
+
...context,
|
|
59
|
+
renderedLineKeys: context.renderedLineKeys ?? new Set()
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
return await fn();
|
|
63
|
+
} finally{
|
|
64
|
+
globalContext.current = previous;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getCliVerboseContext() {
|
|
68
|
+
return getGlobalContext().current;
|
|
69
|
+
}
|
|
70
|
+
function isCliVerboseEnabled() {
|
|
71
|
+
return getCliVerboseContext().enabled;
|
|
72
|
+
}
|
|
73
|
+
function emitCliVerboseEvent(event) {
|
|
74
|
+
const context = getCliVerboseContext();
|
|
75
|
+
if (!context.enabled) return;
|
|
76
|
+
const payload = {
|
|
77
|
+
type: progressEventName,
|
|
78
|
+
timestamp: new Date().toISOString(),
|
|
79
|
+
scriptName: context.scriptName,
|
|
80
|
+
command: context.commandName,
|
|
81
|
+
...event
|
|
82
|
+
};
|
|
83
|
+
if ('jsonl' === context.format) return void console.log(JSON.stringify(payload));
|
|
84
|
+
const text = renderCliVerboseEventText(payload, context);
|
|
85
|
+
if (text) console.log(text);
|
|
86
|
+
}
|
|
87
|
+
function errorMessageOf(error) {
|
|
88
|
+
return error instanceof Error ? error.message : String(error);
|
|
89
|
+
}
|
|
90
|
+
function isRecord(value) {
|
|
91
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
function compactText(value) {
|
|
94
|
+
if (null == value || '' === value) return '';
|
|
95
|
+
if ('string' == typeof value) return value.length > 180 ? `${value.slice(0, 177)}...` : value;
|
|
96
|
+
if ('number' == typeof value || 'boolean' == typeof value) return String(value);
|
|
97
|
+
try {
|
|
98
|
+
const json = JSON.stringify(value);
|
|
99
|
+
return json.length > 180 ? `${json.slice(0, 177)}...` : json;
|
|
100
|
+
} catch {
|
|
101
|
+
return String(value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function compactPrimitiveCliVerboseValue(value) {
|
|
105
|
+
if (null == value) return {
|
|
106
|
+
handled: true,
|
|
107
|
+
value
|
|
108
|
+
};
|
|
109
|
+
if ('string' == typeof value) return {
|
|
110
|
+
handled: true,
|
|
111
|
+
value: value.length > 180 ? `${value.slice(0, 177)}...` : value
|
|
112
|
+
};
|
|
113
|
+
if ('number' == typeof value || 'boolean' == typeof value) return {
|
|
114
|
+
handled: true,
|
|
115
|
+
value
|
|
116
|
+
};
|
|
117
|
+
if ('object' != typeof value) return {
|
|
118
|
+
handled: true,
|
|
119
|
+
value: String(value)
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
handled: false
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function compactStructuredCliVerboseValue(value) {
|
|
126
|
+
const primitive = compactPrimitiveCliVerboseValue(value);
|
|
127
|
+
if (primitive.handled) return primitive.value;
|
|
128
|
+
if (Array.isArray(value)) return value.slice(0, 5).map(compactStructuredCliVerboseValue);
|
|
129
|
+
if (!isRecord(value)) return String(value);
|
|
130
|
+
const entries = Object.entries(value).slice(0, 6);
|
|
131
|
+
return Object.fromEntries(entries.map(([key, entryValue])=>[
|
|
132
|
+
key,
|
|
133
|
+
compactStructuredCliVerboseValue(entryValue)
|
|
134
|
+
]));
|
|
135
|
+
}
|
|
136
|
+
function compactCliVerboseValue(value) {
|
|
137
|
+
const primitive = compactPrimitiveCliVerboseValue(value);
|
|
138
|
+
if (primitive.handled) return primitive.value;
|
|
139
|
+
if (Array.isArray(value)) return value.slice(0, 5).map(compactCliVerboseValue);
|
|
140
|
+
if (isRecord(value) && 'string' == typeof value.prompt) return compactCliVerboseValue(value.prompt);
|
|
141
|
+
if (!isRecord(value)) return String(value);
|
|
142
|
+
const entries = Object.entries(value).slice(0, 6);
|
|
143
|
+
return Object.fromEntries(entries.map(([key, entryValue])=>[
|
|
144
|
+
key,
|
|
145
|
+
compactCliVerboseValue(entryValue)
|
|
146
|
+
]));
|
|
147
|
+
}
|
|
148
|
+
function compactCliVerboseArgs(args) {
|
|
149
|
+
return Object.fromEntries(Object.entries(args).slice(0, 8).map(([key, value])=>[
|
|
150
|
+
key,
|
|
151
|
+
compactStructuredCliVerboseValue(value)
|
|
152
|
+
]));
|
|
153
|
+
}
|
|
154
|
+
function summarizeParam(param) {
|
|
155
|
+
if (!param || 'object' != typeof param) return compactCliVerboseValue(param);
|
|
156
|
+
const record = param;
|
|
157
|
+
if ('string' == typeof record.prompt) return compactCliVerboseValue(record.prompt);
|
|
158
|
+
if (record.locate && 'object' == typeof record.locate && null !== record.locate) {
|
|
159
|
+
const locate = record.locate;
|
|
160
|
+
return {
|
|
161
|
+
locate: compactCliVerboseValue(locate.prompt),
|
|
162
|
+
...Object.fromEntries(Object.entries(record).filter(([key])=>'locate' !== key).slice(0, 4).map(([key, value])=>[
|
|
163
|
+
key,
|
|
164
|
+
compactCliVerboseValue(value)
|
|
165
|
+
]))
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return compactCliVerboseValue(record);
|
|
169
|
+
}
|
|
170
|
+
function summarizeUserInstruction(value) {
|
|
171
|
+
if ('string' == typeof value) return compactText(value);
|
|
172
|
+
if (isRecord(value) && 'string' == typeof value.prompt) return compactText(value.prompt);
|
|
173
|
+
return compactText(value);
|
|
174
|
+
}
|
|
175
|
+
function summarizeTaskParamText(task) {
|
|
176
|
+
if (!isRecord(task.param)) return compactText(summarizeParam(task.param));
|
|
177
|
+
if ('Planning' === task.type && 'Locate' !== task.subType) {
|
|
178
|
+
if (task.param.userInstructionDisplay) return summarizeUserInstruction(task.param.userInstructionDisplay);
|
|
179
|
+
if (task.param.userInstruction) return summarizeUserInstruction(task.param.userInstruction);
|
|
180
|
+
}
|
|
181
|
+
if (task.param.dataDemand) return compactText(summarizeParam(task.param.dataDemand));
|
|
182
|
+
if (task.param.assertion) return compactText(summarizeParam(task.param.assertion));
|
|
183
|
+
return compactText(summarizeParam(task.param));
|
|
184
|
+
}
|
|
185
|
+
function summarizeSubGoals(value) {
|
|
186
|
+
if (!Array.isArray(value) || 0 === value.length) return '';
|
|
187
|
+
const goals = value.slice(0, 6).map((goal)=>{
|
|
188
|
+
if (!isRecord(goal)) return '';
|
|
189
|
+
const index = 'number' == typeof goal.index ? `${goal.index}. ` : '';
|
|
190
|
+
const status = 'string' == typeof goal.status ? `[${goal.status}] ` : '';
|
|
191
|
+
const description = 'string' == typeof goal.description ? goal.description : '';
|
|
192
|
+
return `${index}${status}${description}`.trim();
|
|
193
|
+
}).filter(Boolean);
|
|
194
|
+
return goals.length > 0 ? `sub-goals: ${goals.join('; ')}` : '';
|
|
195
|
+
}
|
|
196
|
+
function summarizeActions(value) {
|
|
197
|
+
if (!Array.isArray(value) || 0 === value.length) return '';
|
|
198
|
+
const actions = value.slice(0, 5).map((action)=>{
|
|
199
|
+
if (!isRecord(action)) return '';
|
|
200
|
+
const type = 'string' == typeof action.type ? action.type : 'Action';
|
|
201
|
+
const param = compactText(summarizeParam(action.param));
|
|
202
|
+
return param ? `${type}: ${param}` : type;
|
|
203
|
+
}).filter(Boolean);
|
|
204
|
+
return actions.length > 0 ? `actions: ${actions.join('; ')}` : '';
|
|
205
|
+
}
|
|
206
|
+
function summarizeTaskOutputText(task) {
|
|
207
|
+
if (!isRecord(task.output)) return compactText(task.output);
|
|
208
|
+
return summarizeSubGoals(task.output.updateSubGoals) || compactText(task.output.log) || compactText(task.output.output) || summarizeActions(task.output.actions);
|
|
209
|
+
}
|
|
210
|
+
function summarizeTaskText(task) {
|
|
211
|
+
const parts = [
|
|
212
|
+
task.type,
|
|
213
|
+
task.subType
|
|
214
|
+
].filter((part)=>'string' == typeof part && part.length > 0);
|
|
215
|
+
const label = parts.length > 0 ? parts.join('/') : 'Task';
|
|
216
|
+
const status = 'string' == typeof task.status && task.status.length > 0 ? task.status : 'unknown';
|
|
217
|
+
const param = summarizeTaskParamText(task);
|
|
218
|
+
const output = summarizeTaskOutputText(task);
|
|
219
|
+
const thought = compactText(task.thought);
|
|
220
|
+
const detail = output || thought || param;
|
|
221
|
+
return detail ? `${label} ${status}: ${detail}` : `${label} ${status}`;
|
|
222
|
+
}
|
|
223
|
+
function isCliVerboseExecutionDumpLike(value) {
|
|
224
|
+
return isRecord(value) && Array.isArray(value.tasks);
|
|
225
|
+
}
|
|
226
|
+
function summarizeDumpUpdate(executionDump, screenshotOptions = {}) {
|
|
227
|
+
if (!isCliVerboseExecutionDumpLike(executionDump)) return;
|
|
228
|
+
const tasks = executionDump.tasks;
|
|
229
|
+
const latestTask = tasks[tasks.length - 1];
|
|
230
|
+
const steps = tasks.map((task, index)=>({
|
|
231
|
+
id: task.taskId,
|
|
232
|
+
index: index + 1,
|
|
233
|
+
total: tasks.length,
|
|
234
|
+
type: task.type,
|
|
235
|
+
subType: task.subType,
|
|
236
|
+
status: task.status,
|
|
237
|
+
param: summarizeParam(task.param),
|
|
238
|
+
message: summarizeTaskText(task),
|
|
239
|
+
error: task.errorMessage,
|
|
240
|
+
durationMs: task.timing?.cost,
|
|
241
|
+
screenshots: collectScreenshotRefs(task, screenshotOptions).slice(-3)
|
|
242
|
+
}));
|
|
243
|
+
return {
|
|
244
|
+
execution: {
|
|
245
|
+
id: executionDump.id,
|
|
246
|
+
name: executionDump.name,
|
|
247
|
+
description: compactCliVerboseValue(executionDump.description),
|
|
248
|
+
taskCount: tasks.length
|
|
249
|
+
},
|
|
250
|
+
steps,
|
|
251
|
+
task: latestTask ? {
|
|
252
|
+
id: latestTask.taskId,
|
|
253
|
+
index: tasks.length,
|
|
254
|
+
total: tasks.length,
|
|
255
|
+
type: latestTask.type,
|
|
256
|
+
subType: latestTask.subType,
|
|
257
|
+
status: latestTask.status,
|
|
258
|
+
param: summarizeParam(latestTask.param),
|
|
259
|
+
message: summarizeTaskText(latestTask),
|
|
260
|
+
error: latestTask.errorMessage,
|
|
261
|
+
durationMs: latestTask.timing?.cost
|
|
262
|
+
} : void 0,
|
|
263
|
+
screenshots: collectScreenshotRefs(tasks, screenshotOptions).slice(-5)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function stringifyArgs(args) {
|
|
267
|
+
if (!isRecord(args) || 0 === Object.keys(args).length) return '';
|
|
268
|
+
return Object.entries(args).map(([key, value])=>`${key}=${compactText(value)}`).join(', ');
|
|
269
|
+
}
|
|
270
|
+
function isActVerboseEvent(command, tool) {
|
|
271
|
+
return 'act' === command || 'act' === tool;
|
|
272
|
+
}
|
|
273
|
+
function renderLinesOnce(context, lines) {
|
|
274
|
+
if (0 === lines.length) return;
|
|
275
|
+
if (!context.renderedLineKeys) context.renderedLineKeys = new Set();
|
|
276
|
+
const renderedLineKeys = context.renderedLineKeys;
|
|
277
|
+
const pendingLines = lines.filter((line)=>{
|
|
278
|
+
if (renderedLineKeys.has(line.key)) return false;
|
|
279
|
+
renderedLineKeys.add(line.key);
|
|
280
|
+
return true;
|
|
281
|
+
});
|
|
282
|
+
return pendingLines.length > 0 ? pendingLines.map((line)=>line.text).join('\n') : void 0;
|
|
283
|
+
}
|
|
284
|
+
function renderCliVerboseEventText(event, context) {
|
|
285
|
+
const command = 'string' == typeof event.command ? event.command : 'command';
|
|
286
|
+
const tool = 'string' == typeof event.tool ? event.tool : void 0;
|
|
287
|
+
switch(event.event){
|
|
288
|
+
case 'agent_progress':
|
|
289
|
+
{
|
|
290
|
+
const scope = 'string' == typeof event.scope ? event.scope : void 0;
|
|
291
|
+
const renderer = scope ? progressRenderers[scope] : void 0;
|
|
292
|
+
const progressEvent = isRecord(event.progress) ? event.progress : void 0;
|
|
293
|
+
if (!renderer || !progressEvent) return;
|
|
294
|
+
return renderLinesOnce(context, renderer.buildLines(progressEvent));
|
|
295
|
+
}
|
|
296
|
+
case 'command_start':
|
|
297
|
+
{
|
|
298
|
+
if (isActVerboseEvent(command, tool)) return;
|
|
299
|
+
const args = stringifyArgs(event.args);
|
|
300
|
+
return args ? `[Midscene] ${command} started (${args})` : `[Midscene] ${command} started`;
|
|
301
|
+
}
|
|
302
|
+
case 'agent_ready':
|
|
303
|
+
if (isActVerboseEvent(command, tool)) return;
|
|
304
|
+
return `[Midscene] ${tool ?? command} ready`;
|
|
305
|
+
case 'recording_ready':
|
|
306
|
+
return '[Midscene] Recording. Press Ctrl+C to stop and save.';
|
|
307
|
+
case 'recording_stopping':
|
|
308
|
+
if ('watchdog' === event.reason) return '[Midscene] Recording watchdog reached; finalizing and saving.';
|
|
309
|
+
if ('sigterm' === event.reason) return '[Midscene] SIGTERM received; finalizing and saving.';
|
|
310
|
+
return 'sighup' === event.reason ? '[Midscene] SIGHUP received; finalizing and saving.' : '[Midscene] Ctrl+C received; finalizing and saving. Press Ctrl+C again to force exit.';
|
|
311
|
+
case 'dump_update':
|
|
312
|
+
{
|
|
313
|
+
if (isActVerboseEvent(command, tool)) return;
|
|
314
|
+
const task = isRecord(event.task) ? event.task : void 0;
|
|
315
|
+
const steps = Array.isArray(event.steps) ? event.steps.filter(isRecord) : [];
|
|
316
|
+
const execution = isRecord(event.execution) ? event.execution : void 0;
|
|
317
|
+
const executionName = 'string' == typeof execution?.name ? execution.name : 'execution';
|
|
318
|
+
const lines = steps.length > 0 ? [
|
|
319
|
+
`[Midscene] Progress: ${executionName} (${steps.length} steps)`,
|
|
320
|
+
...steps.map((step)=>{
|
|
321
|
+
const index = 'number' == typeof step.index && 'number' == typeof step.total ? `Step ${step.index}/${step.total}` : 'Step';
|
|
322
|
+
const message = 'string' == typeof step.message ? step.message : 'string' == typeof step.status ? step.status : 'updated';
|
|
323
|
+
return `[Midscene] ${index}: ${message}`;
|
|
324
|
+
})
|
|
325
|
+
] : [
|
|
326
|
+
`[Midscene] Step: ${'string' == typeof task?.message ? task.message : 'string' == typeof task?.status ? task.status : 'updated'}`
|
|
327
|
+
];
|
|
328
|
+
const screenshots = renderScreenshotList(event.screenshots);
|
|
329
|
+
if (screenshots) lines.push(`[Midscene] Screenshot: ${screenshots}`);
|
|
330
|
+
if ('string' == typeof event.report && event.report.length > 0) lines.push(`[Midscene] Report: ${event.report}`);
|
|
331
|
+
return lines.join('\n');
|
|
332
|
+
}
|
|
333
|
+
case 'artifact':
|
|
334
|
+
{
|
|
335
|
+
if (isActVerboseEvent(command, tool)) return;
|
|
336
|
+
const kind = 'string' == typeof event.kind ? event.kind : 'artifact';
|
|
337
|
+
const path = 'string' == typeof event.path ? event.path : void 0;
|
|
338
|
+
return path ? `[Midscene] ${kind} saved: ${path}` : `[Midscene] ${kind} ready`;
|
|
339
|
+
}
|
|
340
|
+
case 'command_done':
|
|
341
|
+
{
|
|
342
|
+
if (isActVerboseEvent(command, tool)) {
|
|
343
|
+
if ('error' === event.status) {
|
|
344
|
+
const error = 'string' == typeof event.error && event.error.length > 0 ? `: ${event.error}` : '';
|
|
345
|
+
return renderLinesOnce(context, [
|
|
346
|
+
{
|
|
347
|
+
key: `aiAct:command_failed:${event.error ?? 'unknown'}`,
|
|
348
|
+
text: `[Midscene][aiAct] Failed${error}`
|
|
349
|
+
}
|
|
350
|
+
]);
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const status = 'error' === event.status ? 'failed' : 'finished';
|
|
355
|
+
const duration = 'number' == typeof event.durationMs ? ` in ${event.durationMs}ms` : '';
|
|
356
|
+
const error = 'error' === event.status && 'string' == typeof event.error ? `: ${event.error}` : '';
|
|
357
|
+
return `[Midscene] ${command} ${status}${duration}${error}`;
|
|
358
|
+
}
|
|
359
|
+
default:
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function attachCliVerboseDumpListener(agent, options) {
|
|
364
|
+
if (!isCliVerboseEnabled()) return ()=>{};
|
|
365
|
+
const isActTool = options?.toolName === 'act';
|
|
366
|
+
const screenshotExportCache = new Map();
|
|
367
|
+
if (isActTool && 'function' == typeof agent.addProgressListener) return agent.addProgressListener((event)=>{
|
|
368
|
+
const match = progressRendererForEvent(event);
|
|
369
|
+
if (!match) return;
|
|
370
|
+
const context = getCliVerboseContext();
|
|
371
|
+
const isTextMode = 'jsonl' !== context.format;
|
|
372
|
+
const progress = match.renderer.normalize(event, {
|
|
373
|
+
reportFile: agent.reportFile,
|
|
374
|
+
exportMode: isTextMode ? 'report' : 'none',
|
|
375
|
+
cache: screenshotExportCache
|
|
376
|
+
});
|
|
377
|
+
if (!progress) return;
|
|
378
|
+
emitCliVerboseEvent({
|
|
379
|
+
event: 'agent_progress',
|
|
380
|
+
tool: options?.toolName,
|
|
381
|
+
scope: match.scope,
|
|
382
|
+
progress
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
if (isActTool) return ()=>{};
|
|
386
|
+
if ('function' != typeof agent.addDumpUpdateListener) return ()=>{};
|
|
387
|
+
return agent.addDumpUpdateListener((_dump, executionDump)=>{
|
|
388
|
+
const context = getCliVerboseContext();
|
|
389
|
+
const isTextMode = 'jsonl' !== context.format;
|
|
390
|
+
const summaryExportMode = isTextMode && !isActTool ? 'tmp' : 'none';
|
|
391
|
+
const summary = summarizeDumpUpdate(executionDump, {
|
|
392
|
+
exportMode: summaryExportMode,
|
|
393
|
+
cache: screenshotExportCache
|
|
394
|
+
});
|
|
395
|
+
if (!summary) return;
|
|
396
|
+
emitCliVerboseEvent({
|
|
397
|
+
event: 'dump_update',
|
|
398
|
+
tool: options?.toolName,
|
|
399
|
+
report: agent.reportFile || void 0,
|
|
400
|
+
...summary
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
export { attachCliVerboseDumpListener, errorMessageOf as cliVerboseErrorMessage, cliVerboseFlag, compactCliVerboseArgs, compactCliVerboseValue, emitCliVerboseEvent, getCliVerboseContext, isCliVerboseEnabled, stripVerboseFlag, withCliVerboseContext };
|
|
@@ -28,8 +28,8 @@ aiQuery<T>(queryObject: Record<string, string>): Promise<T> // Extracts data fro
|
|
|
28
28
|
// The following is test code for Midscene AI, for reference
|
|
29
29
|
// The following is Playwright syntax, you can use Playwright to assist in test generation
|
|
30
30
|
import { test as base } from '@playwright/test';
|
|
31
|
-
import type { PlayWrightAiFixtureType } from '@
|
|
32
|
-
import { PlaywrightAiFixture } from '@
|
|
31
|
+
import type { PlayWrightAiFixtureType } from '@aiscene/web/playwright';
|
|
32
|
+
import { PlaywrightAiFixture } from '@aiscene/web/playwright';
|
|
33
33
|
|
|
34
34
|
const test = base.extend<PlayWrightAiFixtureType>(PlaywrightAiFixture({
|
|
35
35
|
waitForNetworkIdleTimeout: 2000, // optional, the timeout for waiting for network idle between each action, default is 2000ms
|
|
@@ -15,9 +15,14 @@ var constants_NodeType = /*#__PURE__*/ function(NodeType) {
|
|
|
15
15
|
}({});
|
|
16
16
|
const PLAYGROUND_SERVER_PORT = 5800;
|
|
17
17
|
const SCRCPY_SERVER_PORT = 5700;
|
|
18
|
+
const SCRCPY_ADB_CONNECT_TIMEOUT_MS = 10000;
|
|
19
|
+
const SCRCPY_PUSH_TIMEOUT_MS = 10000;
|
|
20
|
+
const SCRCPY_START_TIMEOUT_MS = 15000;
|
|
21
|
+
const SCRCPY_VIDEO_STREAM_TIMEOUT_MS = 15000;
|
|
22
|
+
const SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = SCRCPY_ADB_CONNECT_TIMEOUT_MS + SCRCPY_PUSH_TIMEOUT_MS + SCRCPY_START_TIMEOUT_MS + SCRCPY_VIDEO_STREAM_TIMEOUT_MS + 5000;
|
|
18
23
|
const WEBDRIVER_ELEMENT_ID_KEY = 'element-6066-11e4-a52e-4f735466cecf';
|
|
19
24
|
const DEFAULT_WDA_PORT = 8100;
|
|
20
25
|
const DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT = 5000;
|
|
21
26
|
const DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT = 2000;
|
|
22
27
|
const DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY = 2;
|
|
23
|
-
export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT, DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT, DEFAULT_WDA_PORT, constants_NodeType as NodeType, PLAYGROUND_SERVER_PORT, PLAYWRIGHT_EXAMPLE_CODE, SCRCPY_SERVER_PORT, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD, WEBDRIVER_ELEMENT_ID_KEY, YAML_EXAMPLE_CODE };
|
|
28
|
+
export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT, DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT, DEFAULT_WDA_PORT, constants_NodeType as NodeType, PLAYGROUND_SERVER_PORT, PLAYWRIGHT_EXAMPLE_CODE, SCRCPY_ADB_CONNECT_TIMEOUT_MS, SCRCPY_PREVIEW_METADATA_TIMEOUT_MS, SCRCPY_PUSH_TIMEOUT_MS, SCRCPY_SERVER_PORT, SCRCPY_START_TIMEOUT_MS, SCRCPY_VIDEO_STREAM_TIMEOUT_MS, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD, WEBDRIVER_ELEMENT_ID_KEY, YAML_EXAMPLE_CODE };
|
|
@@ -24,14 +24,17 @@ class ModelConfigManager {
|
|
|
24
24
|
this.modelConfigMap = {
|
|
25
25
|
default: {
|
|
26
26
|
...defaultConfig,
|
|
27
|
+
intent: 'default',
|
|
27
28
|
createOpenAIClient: this.createOpenAIClientFn
|
|
28
29
|
},
|
|
29
30
|
insight: {
|
|
30
31
|
...insightConfig || defaultConfig,
|
|
32
|
+
intent: 'insight',
|
|
31
33
|
createOpenAIClient: this.createOpenAIClientFn
|
|
32
34
|
},
|
|
33
35
|
planning: {
|
|
34
36
|
...planningConfig || defaultConfig,
|
|
37
|
+
intent: 'planning',
|
|
35
38
|
createOpenAIClient: this.createOpenAIClientFn
|
|
36
39
|
}
|
|
37
40
|
};
|
|
@@ -4,6 +4,9 @@ import { getDebug } from "../logger.mjs";
|
|
|
4
4
|
import { assert } from "../utils.mjs";
|
|
5
5
|
import { maskConfig, parseJson } from "./helper.mjs";
|
|
6
6
|
import { initDebugConfig } from "./init-debug.mjs";
|
|
7
|
+
const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
|
|
8
|
+
const getCurrentVersion = ()=>"8.0.4";
|
|
9
|
+
const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
|
|
7
10
|
const KEYS_MAP = {
|
|
8
11
|
insight: INSIGHT_MODEL_CONFIG_KEYS,
|
|
9
12
|
planning: PLANNING_MODEL_CONFIG_KEYS,
|
|
@@ -14,7 +17,7 @@ const getUITarsModelVersion = (modelFamily)=>{
|
|
|
14
17
|
if ('vlm-ui-tars-doubao' === modelFamily || 'vlm-ui-tars-doubao-1.5' === modelFamily) return UITarsModelVersion.DOUBAO_1_5_20B;
|
|
15
18
|
};
|
|
16
19
|
const validateModelFamily = (modelFamily)=>{
|
|
17
|
-
if (modelFamily && !MODEL_FAMILY_VALUES.includes(modelFamily)) throw new Error(
|
|
20
|
+
if (modelFamily && !MODEL_FAMILY_VALUES.includes(modelFamily)) throw new Error(getInvalidModelFamilyMessage(modelFamily));
|
|
18
21
|
};
|
|
19
22
|
const legacyConfigToModelFamily = (provider)=>{
|
|
20
23
|
const isDoubao = provider[MIDSCENE_USE_DOUBAO_VISION];
|
|
@@ -90,6 +93,7 @@ const parseOpenaiSdkConfig = ({ keys, provider, useLegacyLogic = false })=>{
|
|
|
90
93
|
modelName: modelName,
|
|
91
94
|
modelDescription,
|
|
92
95
|
intent: '-',
|
|
96
|
+
slot: '-',
|
|
93
97
|
timeout: provider[keys.timeout] ? Number(provider[keys.timeout]) : void 0,
|
|
94
98
|
temperature,
|
|
95
99
|
retryCount: (()=>{
|
|
@@ -132,6 +136,7 @@ const decideModelConfigFromIntentConfig = (intent, configMap)=>{
|
|
|
132
136
|
useLegacyLogic: 'default' === intent
|
|
133
137
|
});
|
|
134
138
|
finalResult.intent = intent;
|
|
139
|
+
finalResult.slot = intent;
|
|
135
140
|
debugLog('decideModelConfig result by agent.modelConfig() with intent', intent, maskConfig({
|
|
136
141
|
...finalResult
|
|
137
142
|
}));
|
package/dist/es/env/types.mjs
CHANGED
|
@@ -6,6 +6,7 @@ const MIDSCENE_DEBUG_MODEL_RESPONSE = 'MIDSCENE_DEBUG_MODEL_RESPONSE';
|
|
|
6
6
|
const MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = 'MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG';
|
|
7
7
|
const MIDSCENE_DEBUG_MODE = 'MIDSCENE_DEBUG_MODE';
|
|
8
8
|
const MIDSCENE_MCP_USE_PUPPETEER_MODE = 'MIDSCENE_MCP_USE_PUPPETEER_MODE';
|
|
9
|
+
const MIDSCENE_CHROME_PATH = 'MIDSCENE_CHROME_PATH';
|
|
9
10
|
const MIDSCENE_MCP_CHROME_PATH = 'MIDSCENE_MCP_CHROME_PATH';
|
|
10
11
|
const MIDSCENE_MCP_ANDROID_MODE = 'MIDSCENE_MCP_ANDROID_MODE';
|
|
11
12
|
const DOCKER_CONTAINER = 'DOCKER_CONTAINER';
|
|
@@ -35,6 +36,7 @@ const MIDSCENE_ADB_REMOTE_PORT = 'MIDSCENE_ADB_REMOTE_PORT';
|
|
|
35
36
|
const MIDSCENE_ANDROID_IME_STRATEGY = 'MIDSCENE_ANDROID_IME_STRATEGY';
|
|
36
37
|
const MIDSCENE_IOS_DEVICE_UDID = 'MIDSCENE_IOS_DEVICE_UDID';
|
|
37
38
|
const MIDSCENE_IOS_SIMULATOR_UDID = 'MIDSCENE_IOS_SIMULATOR_UDID';
|
|
39
|
+
const MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE = 'MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE';
|
|
38
40
|
const MIDSCENE_CACHE = 'MIDSCENE_CACHE';
|
|
39
41
|
const MIDSCENE_USE_VLM_UI_TARS = 'MIDSCENE_USE_VLM_UI_TARS';
|
|
40
42
|
const MIDSCENE_USE_QWEN_VL = 'MIDSCENE_USE_QWEN_VL';
|
|
@@ -114,6 +116,7 @@ const STRING_ENV_KEYS = [
|
|
|
114
116
|
MIDSCENE_REPORT_TAG_NAME,
|
|
115
117
|
MIDSCENE_PREFERRED_LANGUAGE,
|
|
116
118
|
MATCH_BY_POSITION,
|
|
119
|
+
MIDSCENE_CHROME_PATH,
|
|
117
120
|
MIDSCENE_MCP_CHROME_PATH,
|
|
118
121
|
DOCKER_CONTAINER
|
|
119
122
|
];
|
|
@@ -209,4 +212,4 @@ var types_UITarsModelVersion = /*#__PURE__*/ function(UITarsModelVersion) {
|
|
|
209
212
|
UITarsModelVersion["DOUBAO_1_5_20B"] = "doubao-1.5-20B";
|
|
210
213
|
return UITarsModelVersion;
|
|
211
214
|
}({});
|
|
212
|
-
export { ALL_ENV_KEYS, 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_CACHE, MIDSCENE_CACHE_MAX_FILENAME_LENGTH, MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG, MIDSCENE_DEBUG_MODE, MIDSCENE_DEBUG_MODEL_PROFILE, MIDSCENE_DEBUG_MODEL_RESPONSE, MIDSCENE_INSIGHT_MODEL_API_KEY, MIDSCENE_INSIGHT_MODEL_BASE_URL, MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON, MIDSCENE_INSIGHT_MODEL_FAMILY, MIDSCENE_INSIGHT_MODEL_HTTP_PROXY, MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON, MIDSCENE_INSIGHT_MODEL_NAME, MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET, MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT, MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED, MIDSCENE_INSIGHT_MODEL_RETRY_COUNT, MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL, MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY, MIDSCENE_INSIGHT_MODEL_TEMPERATURE, MIDSCENE_INSIGHT_MODEL_TIMEOUT, MIDSCENE_IOS_DEVICE_UDID, MIDSCENE_IOS_SIMULATOR_UDID, MIDSCENE_LANGFUSE_DEBUG, MIDSCENE_LANGSMITH_DEBUG, MIDSCENE_MCP_ANDROID_MODE, MIDSCENE_MCP_CHROME_PATH, MIDSCENE_MCP_USE_PUPPETEER_MODE, MIDSCENE_MODEL_API_KEY, MIDSCENE_MODEL_BASE_URL, MIDSCENE_MODEL_EXTRA_BODY_JSON, MIDSCENE_MODEL_FAMILY, MIDSCENE_MODEL_HTTP_PROXY, MIDSCENE_MODEL_INIT_CONFIG_JSON, MIDSCENE_MODEL_MAX_TOKENS, MIDSCENE_MODEL_NAME, MIDSCENE_MODEL_REASONING_BUDGET, MIDSCENE_MODEL_REASONING_EFFORT, MIDSCENE_MODEL_REASONING_ENABLED, MIDSCENE_MODEL_RETRY_COUNT, MIDSCENE_MODEL_RETRY_INTERVAL, MIDSCENE_MODEL_SOCKS_PROXY, MIDSCENE_MODEL_TEMPERATURE, MIDSCENE_MODEL_TIMEOUT, MIDSCENE_OPENAI_HTTP_PROXY, MIDSCENE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_OPENAI_SOCKS_PROXY, MIDSCENE_PLANNING_MODEL_API_KEY, MIDSCENE_PLANNING_MODEL_BASE_URL, MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON, MIDSCENE_PLANNING_MODEL_FAMILY, MIDSCENE_PLANNING_MODEL_HTTP_PROXY, MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON, MIDSCENE_PLANNING_MODEL_NAME, MIDSCENE_PLANNING_MODEL_REASONING_BUDGET, MIDSCENE_PLANNING_MODEL_REASONING_EFFORT, MIDSCENE_PLANNING_MODEL_REASONING_ENABLED, MIDSCENE_PLANNING_MODEL_RETRY_COUNT, MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL, MIDSCENE_PLANNING_MODEL_SOCKS_PROXY, MIDSCENE_PLANNING_MODEL_TEMPERATURE, MIDSCENE_PLANNING_MODEL_TIMEOUT, MIDSCENE_PREFERRED_LANGUAGE, MIDSCENE_REPLANNING_CYCLE_LIMIT, MIDSCENE_REPORT_QUIET, MIDSCENE_REPORT_TAG_NAME, MIDSCENE_RUN_DIR, MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN3_VL, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS, MIDSCENE_USE_VL_MODEL, MODEL_ENV_KEYS, MODEL_FAMILY_VALUES, NUMBER_ENV_KEYS, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MAX_TOKENS, STRING_ENV_KEYS, types_UITarsModelVersion as UITarsModelVersion, UNUSED_ENV_KEYS };
|
|
215
|
+
export { ALL_ENV_KEYS, 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_CACHE, MIDSCENE_CACHE_MAX_FILENAME_LENGTH, MIDSCENE_CHROME_PATH, MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG, MIDSCENE_DEBUG_MODE, MIDSCENE_DEBUG_MODEL_PROFILE, MIDSCENE_DEBUG_MODEL_RESPONSE, MIDSCENE_INSIGHT_MODEL_API_KEY, MIDSCENE_INSIGHT_MODEL_BASE_URL, MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON, MIDSCENE_INSIGHT_MODEL_FAMILY, MIDSCENE_INSIGHT_MODEL_HTTP_PROXY, MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON, MIDSCENE_INSIGHT_MODEL_NAME, MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET, MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT, MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED, MIDSCENE_INSIGHT_MODEL_RETRY_COUNT, MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL, MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY, MIDSCENE_INSIGHT_MODEL_TEMPERATURE, MIDSCENE_INSIGHT_MODEL_TIMEOUT, MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE, MIDSCENE_IOS_DEVICE_UDID, MIDSCENE_IOS_SIMULATOR_UDID, MIDSCENE_LANGFUSE_DEBUG, MIDSCENE_LANGSMITH_DEBUG, MIDSCENE_MCP_ANDROID_MODE, MIDSCENE_MCP_CHROME_PATH, MIDSCENE_MCP_USE_PUPPETEER_MODE, MIDSCENE_MODEL_API_KEY, MIDSCENE_MODEL_BASE_URL, MIDSCENE_MODEL_EXTRA_BODY_JSON, MIDSCENE_MODEL_FAMILY, MIDSCENE_MODEL_HTTP_PROXY, MIDSCENE_MODEL_INIT_CONFIG_JSON, MIDSCENE_MODEL_MAX_TOKENS, MIDSCENE_MODEL_NAME, MIDSCENE_MODEL_REASONING_BUDGET, MIDSCENE_MODEL_REASONING_EFFORT, MIDSCENE_MODEL_REASONING_ENABLED, MIDSCENE_MODEL_RETRY_COUNT, MIDSCENE_MODEL_RETRY_INTERVAL, MIDSCENE_MODEL_SOCKS_PROXY, MIDSCENE_MODEL_TEMPERATURE, MIDSCENE_MODEL_TIMEOUT, MIDSCENE_OPENAI_HTTP_PROXY, MIDSCENE_OPENAI_INIT_CONFIG_JSON, MIDSCENE_OPENAI_SOCKS_PROXY, MIDSCENE_PLANNING_MODEL_API_KEY, MIDSCENE_PLANNING_MODEL_BASE_URL, MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON, MIDSCENE_PLANNING_MODEL_FAMILY, MIDSCENE_PLANNING_MODEL_HTTP_PROXY, MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON, MIDSCENE_PLANNING_MODEL_NAME, MIDSCENE_PLANNING_MODEL_REASONING_BUDGET, MIDSCENE_PLANNING_MODEL_REASONING_EFFORT, MIDSCENE_PLANNING_MODEL_REASONING_ENABLED, MIDSCENE_PLANNING_MODEL_RETRY_COUNT, MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL, MIDSCENE_PLANNING_MODEL_SOCKS_PROXY, MIDSCENE_PLANNING_MODEL_TEMPERATURE, MIDSCENE_PLANNING_MODEL_TIMEOUT, MIDSCENE_PREFERRED_LANGUAGE, MIDSCENE_REPLANNING_CYCLE_LIMIT, MIDSCENE_REPORT_QUIET, MIDSCENE_REPORT_TAG_NAME, MIDSCENE_RUN_DIR, MIDSCENE_USE_DOUBAO_VISION, MIDSCENE_USE_GEMINI, MIDSCENE_USE_QWEN3_VL, MIDSCENE_USE_QWEN_VL, MIDSCENE_USE_VLM_UI_TARS, MIDSCENE_USE_VL_MODEL, MODEL_ENV_KEYS, MODEL_FAMILY_VALUES, NUMBER_ENV_KEYS, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MAX_TOKENS, STRING_ENV_KEYS, types_UITarsModelVersion as UITarsModelVersion, UNUSED_ENV_KEYS };
|