@midscene/core 0.0.1 → 0.1.1
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/ai-model.js +4218 -9
- package/dist/es/image.js +28 -14
- package/dist/es/index.js +4364 -151
- package/dist/es/utils.js +20 -11
- package/dist/lib/ai-model.js +4231 -42
- package/dist/lib/image.js +35 -21
- package/dist/lib/index.js +4348 -155
- package/dist/lib/utils.js +21 -11
- package/dist/types/ai-model.d.ts +1 -1
- package/dist/types/image.d.ts +3 -4
- package/dist/types/index.d.ts +15 -5
- package/dist/types/utils.d.ts +9 -3
- package/package.json +5 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -9
- package/CONTRIBUTING.md +0 -5
- package/demo_data/demo.actions.json +0 -160
- package/demo_data/demo.insight.json +0 -3571
- package/demo_data/index.d.ts +0 -1
- package/demo_data/index.js +0 -6
- package/modern.config.ts +0 -18
- package/third-party-licenses.txt +0 -415
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -20
package/dist/lib/utils.js
CHANGED
|
@@ -32,6 +32,7 @@ var utils_exports = {};
|
|
|
32
32
|
__export(utils_exports, {
|
|
33
33
|
commonScreenshotParam: () => commonScreenshotParam,
|
|
34
34
|
getDumpDir: () => getDumpDir,
|
|
35
|
+
getDumpDirPath: () => getDumpDirPath,
|
|
35
36
|
getPkgInfo: () => getPkgInfo,
|
|
36
37
|
getTmpDir: () => getTmpDir,
|
|
37
38
|
getTmpFile: () => getTmpFile,
|
|
@@ -80,13 +81,18 @@ function getDumpDir() {
|
|
|
80
81
|
function setDumpDir(dir) {
|
|
81
82
|
logDir = dir;
|
|
82
83
|
}
|
|
83
|
-
function
|
|
84
|
+
function getDumpDirPath(type) {
|
|
85
|
+
return (0, import_path.join)(getDumpDir(), type);
|
|
86
|
+
}
|
|
87
|
+
function writeDumpFile(opts) {
|
|
88
|
+
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
89
|
+
const targetDir = getDumpDirPath(type);
|
|
90
|
+
if (!(0, import_fs.existsSync)(targetDir)) {
|
|
91
|
+
(0, import_fs.mkdirSync)(targetDir, { recursive: true });
|
|
92
|
+
}
|
|
84
93
|
if (!logEnvReady) {
|
|
85
|
-
(0, import_assert.default)(
|
|
86
|
-
|
|
87
|
-
(0, import_fs.mkdirSync)(logDir, { recursive: true });
|
|
88
|
-
}
|
|
89
|
-
const gitIgnorePath = (0, import_path.join)(logDir, "../.gitignore");
|
|
94
|
+
(0, import_assert.default)(targetDir, "logDir should be set before writing dump file");
|
|
95
|
+
const gitIgnorePath = (0, import_path.join)(targetDir, "../../.gitignore");
|
|
90
96
|
let gitIgnoreContent = "";
|
|
91
97
|
if ((0, import_fs.existsSync)(gitIgnorePath)) {
|
|
92
98
|
gitIgnoreContent = (0, import_fs.readFileSync)(gitIgnorePath, "utf-8");
|
|
@@ -97,16 +103,19 @@ function writeDumpFile(fileName, fileExt, fileContent) {
|
|
|
97
103
|
gitIgnorePath,
|
|
98
104
|
`${gitIgnoreContent}
|
|
99
105
|
# MidScene.js dump files
|
|
100
|
-
${logDirName}/
|
|
106
|
+
${logDirName}/midscene-report
|
|
107
|
+
${logDirName}/dump-logger
|
|
101
108
|
`,
|
|
102
109
|
"utf-8"
|
|
103
110
|
);
|
|
104
111
|
}
|
|
105
112
|
logEnvReady = true;
|
|
106
113
|
}
|
|
107
|
-
const filePath = (0, import_path.join)(
|
|
114
|
+
const filePath = (0, import_path.join)(targetDir, `${fileName}.${fileExt}`);
|
|
108
115
|
(0, import_fs.writeFileSync)(filePath, fileContent);
|
|
109
|
-
|
|
116
|
+
if (type === "dump") {
|
|
117
|
+
(0, import_fs.copyFileSync)(filePath, (0, import_path.join)(targetDir, `latest.${fileExt}`));
|
|
118
|
+
}
|
|
110
119
|
return filePath;
|
|
111
120
|
}
|
|
112
121
|
function getTmpDir() {
|
|
@@ -114,8 +123,8 @@ function getTmpDir() {
|
|
|
114
123
|
(0, import_fs.mkdirSync)(path, { recursive: true });
|
|
115
124
|
return path;
|
|
116
125
|
}
|
|
117
|
-
function getTmpFile(
|
|
118
|
-
const filename = `${(0, import_crypto.randomUUID)()}.${
|
|
126
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
127
|
+
const filename = `${(0, import_crypto.randomUUID)()}.${fileExtWithoutDot}`;
|
|
119
128
|
return (0, import_path.join)(getTmpDir(), filename);
|
|
120
129
|
}
|
|
121
130
|
function overlapped(container, target) {
|
|
@@ -129,6 +138,7 @@ var commonScreenshotParam = { type: "jpeg", quality: 75 };
|
|
|
129
138
|
0 && (module.exports = {
|
|
130
139
|
commonScreenshotParam,
|
|
131
140
|
getDumpDir,
|
|
141
|
+
getDumpDirPath,
|
|
132
142
|
getPkgInfo,
|
|
133
143
|
getTmpDir,
|
|
134
144
|
getTmpFile,
|
package/dist/types/ai-model.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare function AiInspectElement<ElementType extends BaseElement = BaseElement>
|
|
|
9
9
|
context: UIContext<ElementType>;
|
|
10
10
|
multi: boolean;
|
|
11
11
|
findElementDescription: string;
|
|
12
|
-
callAI?: typeof callToGetJSONObject
|
|
12
|
+
callAI?: typeof callToGetJSONObject<AIElementParseResponse>;
|
|
13
13
|
}): Promise<{
|
|
14
14
|
parseResult: AIElementParseResponse;
|
|
15
15
|
elementById: (id: string) => ElementType;
|
package/dist/types/image.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { S as Size, R as Rect, g as UISection, U as UIContext, t as Color } from './types-1f7912d5.js';
|
|
3
|
-
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
4
3
|
import 'openai/resources';
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -79,7 +78,7 @@ declare function calculateNewDimensions(originalWidth: number, originalHeight: n
|
|
|
79
78
|
* @param image - The image to be trimmed. This can be a file path or a Buffer object containing the image data
|
|
80
79
|
* @returns A Promise that resolves to an object containing the trimming information. If the image does not need to be trimmed, this object will be null
|
|
81
80
|
*/
|
|
82
|
-
declare function trimImage(image: string | Buffer
|
|
81
|
+
declare function trimImage(image: string | Buffer): Promise<{
|
|
83
82
|
trimOffsetLeft: number;
|
|
84
83
|
trimOffsetTop: number;
|
|
85
84
|
width: number;
|
|
@@ -101,7 +100,7 @@ declare function trimImage(image: string | Buffer$1): Promise<{
|
|
|
101
100
|
* @returns A Promise that resolves to a rectangle object representing the aligned coordinates
|
|
102
101
|
* @throws Error if there is an error during image processing
|
|
103
102
|
*/
|
|
104
|
-
declare function alignCoordByTrim(image: string | Buffer
|
|
103
|
+
declare function alignCoordByTrim(image: string | Buffer, centerRect: Rect): Promise<Rect>;
|
|
105
104
|
|
|
106
105
|
/**
|
|
107
106
|
* Composes a section diagram based on the given sections and context
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,19 +4,26 @@ export { e as AIElementParseResponse, A as AIResponseFormat, f as AISectionParse
|
|
|
4
4
|
export { setDumpDir } from './utils.js';
|
|
5
5
|
import 'openai/resources';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
interface LocateOpts {
|
|
8
|
+
multi?: boolean;
|
|
9
|
+
callAI?: typeof callToGetJSONObject<AIElementParseResponse>;
|
|
10
|
+
}
|
|
11
|
+
declare class Insight<ElementType extends BaseElement = BaseElement, ContextType extends UIContext<ElementType> = UIContext<ElementType>> {
|
|
12
|
+
contextRetrieverFn: () => Promise<ContextType> | ContextType;
|
|
9
13
|
aiVendorFn: typeof callToGetJSONObject;
|
|
10
14
|
onceDumpUpdatedFn?: DumpSubscriber;
|
|
11
15
|
taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
|
|
12
|
-
constructor(context:
|
|
13
|
-
locate(queryPrompt: string
|
|
16
|
+
constructor(context: ContextType | (() => Promise<ContextType> | ContextType), opt?: InsightOptions);
|
|
17
|
+
locate(queryPrompt: string, opt?: {
|
|
18
|
+
callAI: LocateOpts['callAI'];
|
|
19
|
+
}): Promise<ElementType | null>;
|
|
14
20
|
locate(queryPrompt: string, opt: {
|
|
15
21
|
multi: true;
|
|
16
22
|
}): Promise<ElementType[]>;
|
|
17
23
|
extract<T = any>(input: string): Promise<T>;
|
|
18
24
|
extract<T extends Record<string, string>>(input: T): Promise<Record<keyof T, any>>;
|
|
19
25
|
extract<T extends object>(input: Record<keyof T, string>): Promise<T>;
|
|
26
|
+
setAiVendorFn<T>(aiVendorFn: typeof callToGetJSONObject<T>): () => void;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
declare class Executor {
|
|
@@ -36,7 +43,10 @@ declare class Executor {
|
|
|
36
43
|
declare const getElement: typeof retrieveElement;
|
|
37
44
|
declare const getSection: typeof retrieveSection;
|
|
38
45
|
|
|
39
|
-
declare function plan(
|
|
46
|
+
declare function plan(userPrompt: string, opts: {
|
|
47
|
+
context: UIContext;
|
|
48
|
+
callAI?: typeof callToGetJSONObject<PlanningAIResponse>;
|
|
49
|
+
}): Promise<{
|
|
40
50
|
plans: PlanningAction[];
|
|
41
51
|
}>;
|
|
42
52
|
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -10,11 +10,17 @@ declare const insightDumpFileExt = "insight-dump.json";
|
|
|
10
10
|
declare const groupedActionDumpFileExt = "web-dump.json";
|
|
11
11
|
declare function getDumpDir(): string;
|
|
12
12
|
declare function setDumpDir(dir: string): void;
|
|
13
|
-
declare function
|
|
13
|
+
declare function getDumpDirPath(type: 'dump' | 'cache'): string;
|
|
14
|
+
declare function writeDumpFile(opts: {
|
|
15
|
+
fileName: string;
|
|
16
|
+
fileExt: string;
|
|
17
|
+
fileContent: string;
|
|
18
|
+
type?: 'dump' | 'cache';
|
|
19
|
+
}): string;
|
|
14
20
|
declare function getTmpDir(): string;
|
|
15
|
-
declare function getTmpFile(
|
|
21
|
+
declare function getTmpFile(fileExtWithoutDot: string): string;
|
|
16
22
|
declare function overlapped(container: Rect, target: Rect): boolean;
|
|
17
23
|
declare function sleep(ms: number): Promise<unknown>;
|
|
18
24
|
declare const commonScreenshotParam: any;
|
|
19
25
|
|
|
20
|
-
export { commonScreenshotParam, getDumpDir, getPkgInfo, getTmpDir, getTmpFile, groupedActionDumpFileExt, insightDumpFileExt, overlapped, setDumpDir, sleep, writeDumpFile };
|
|
26
|
+
export { commonScreenshotParam, getDumpDir, getDumpDirPath, getPkgInfo, getTmpDir, getTmpFile, groupedActionDumpFileExt, insightDumpFileExt, overlapped, setDumpDir, sleep, writeDumpFile };
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Hello, It's MidScene",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"jsnext:source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/lib/index.js",
|
|
7
7
|
"module": "./dist/es/index.js",
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
15
|
"types": "./dist/types/index.d.ts",
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED