@xiuchang-midscene/shared 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/oss/index.mjs +1 -1
- package/dist/lib/oss/index.js +1 -1
- package/package.json +1 -1
- package/src/oss/index.ts +1 -1
- package/dist/es/baseDB.mjs.bak +0 -109
- package/dist/es/build/copy-static.mjs.bak +0 -31
- package/dist/es/build/rspack-config.mjs.bak +0 -4
- package/dist/es/cli/cli-runner.mjs.bak +0 -140
- package/dist/es/cli/index.mjs.bak +0 -2
- package/dist/es/common.mjs.bak +0 -37
- package/dist/es/constants/example-code.mjs.bak +0 -223
- package/dist/es/constants/index.mjs.bak +0 -23
- package/dist/es/env/basic.mjs.bak +0 -6
- package/dist/es/env/constants.mjs.bak +0 -70
- package/dist/es/env/global-config-manager.mjs.bak +0 -94
- package/dist/es/env/helper.mjs.bak +0 -43
- package/dist/es/env/index.mjs.bak +0 -5
- package/dist/es/env/init-debug.mjs.bak +0 -18
- package/dist/es/env/model-config-manager.mjs.bak +0 -79
- package/dist/es/env/parse-model-config.mjs.bak +0 -132
- package/dist/es/env/types.mjs.bak +0 -220
- package/dist/es/env/utils.mjs.bak +0 -26
- package/dist/es/extractor/constants.mjs.bak +0 -2
- package/dist/es/extractor/debug.mjs.bak +0 -6
- package/dist/es/extractor/dom-util.mjs.bak +0 -92
- package/dist/es/extractor/index.mjs.bak +0 -5
- package/dist/es/extractor/locator.mjs.bak +0 -250
- package/dist/es/extractor/tree.mjs.bak +0 -78
- package/dist/es/extractor/util.mjs.bak +0 -245
- package/dist/es/extractor/web-extractor.mjs.bak +0 -303
- package/dist/es/img/box-select.mjs.bak +0 -824
- package/dist/es/img/canvas-fallback.mjs.bak +0 -238
- package/dist/es/img/get-photon.mjs.bak +0 -45
- package/dist/es/img/get-sharp.mjs.bak +0 -11
- package/dist/es/img/index.mjs.bak +0 -4
- package/dist/es/img/info.mjs.bak +0 -29
- package/dist/es/img/transform.mjs.bak +0 -295
- package/dist/es/index.mjs.bak +0 -4
- package/dist/es/logger.mjs.bak +0 -64
- package/dist/es/mcp/base-server.mjs.bak +0 -281
- package/dist/es/mcp/base-tools.mjs.bak +0 -91
- package/dist/es/mcp/chrome-path.mjs.bak +0 -35
- package/dist/es/mcp/index.mjs.bak +0 -7
- package/dist/es/mcp/inject-report-html-plugin.mjs.bak +0 -53
- package/dist/es/mcp/launcher-helper.mjs.bak +0 -52
- package/dist/es/mcp/tool-generator.mjs.bak +0 -297
- package/dist/es/mcp/types.mjs.bak +0 -3
- package/dist/es/node/fs.mjs.bak +0 -44
- package/dist/es/node/index.mjs.bak +0 -2
- package/dist/es/node/port.mjs.bak +0 -24
- package/dist/es/oss/demo.mjs.bak +0 -30
- package/dist/es/oss/index.mjs.bak +0 -90
- package/dist/es/polyfills/async-hooks.mjs.bak +0 -2
- package/dist/es/polyfills/index.mjs.bak +0 -1
- package/dist/es/types/index.mjs.bak +0 -3
- package/dist/es/us-keyboard-layout.mjs.bak +0 -1414
- package/dist/es/utils.mjs.bak +0 -72
- package/dist/es/zod-schema-utils.mjs.bak +0 -54
- package/dist/lib/baseDB.js.bak +0 -149
- package/dist/lib/build/copy-static.js.bak +0 -79
- package/dist/lib/build/rspack-config.js.bak +0 -38
- package/dist/lib/cli/cli-runner.js.bak +0 -196
- package/dist/lib/cli/index.js.bak +0 -48
- package/dist/lib/common.js.bak +0 -93
- package/dist/lib/constants/example-code.js.bak +0 -260
- package/dist/lib/constants/index.js.bak +0 -96
- package/dist/lib/env/basic.js.bak +0 -40
- package/dist/lib/env/constants.js.bak +0 -113
- package/dist/lib/env/global-config-manager.js.bak +0 -128
- package/dist/lib/env/helper.js.bak +0 -80
- package/dist/lib/env/index.js.bak +0 -90
- package/dist/lib/env/init-debug.js.bak +0 -52
- package/dist/lib/env/model-config-manager.js.bak +0 -113
- package/dist/lib/env/parse-model-config.js.bak +0 -178
- package/dist/lib/env/types.js.bak +0 -554
- package/dist/lib/env/utils.js.bak +0 -72
- package/dist/lib/extractor/constants.js.bak +0 -42
- package/dist/lib/extractor/debug.js.bak +0 -12
- package/dist/lib/extractor/dom-util.js.bak +0 -153
- package/dist/lib/extractor/index.js.bak +0 -81
- package/dist/lib/extractor/locator.js.bak +0 -296
- package/dist/lib/extractor/tree.js.bak +0 -124
- package/dist/lib/extractor/util.js.bak +0 -336
- package/dist/lib/extractor/web-extractor.js.bak +0 -349
- package/dist/lib/img/box-select.js.bak +0 -875
- package/dist/lib/img/canvas-fallback.js.bak +0 -305
- package/dist/lib/img/get-photon.js.bak +0 -82
- package/dist/lib/img/get-sharp.js.bak +0 -45
- package/dist/lib/img/index.js.bak +0 -95
- package/dist/lib/img/info.js.bak +0 -83
- package/dist/lib/img/transform.js.bak +0 -387
- package/dist/lib/index.js.bak +0 -47
- package/dist/lib/logger.js.bak +0 -114
- package/dist/lib/mcp/base-server.js.bak +0 -331
- package/dist/lib/mcp/base-tools.js.bak +0 -125
- package/dist/lib/mcp/chrome-path.js.bak +0 -72
- package/dist/lib/mcp/index.js.bak +0 -100
- package/dist/lib/mcp/inject-report-html-plugin.js.bak +0 -98
- package/dist/lib/mcp/launcher-helper.js.bak +0 -86
- package/dist/lib/mcp/tool-generator.js.bak +0 -334
- package/dist/lib/mcp/types.js.bak +0 -40
- package/dist/lib/node/fs.js.bak +0 -97
- package/dist/lib/node/index.js.bak +0 -65
- package/dist/lib/node/port.js.bak +0 -61
- package/dist/lib/oss/demo.js.bak +0 -36
- package/dist/lib/oss/index.js.bak +0 -138
- package/dist/lib/polyfills/async-hooks.js.bak +0 -36
- package/dist/lib/polyfills/index.js.bak +0 -58
- package/dist/lib/types/index.js.bak +0 -37
- package/dist/lib/us-keyboard-layout.js.bak +0 -1457
- package/dist/lib/utils.js.bak +0 -148
- package/dist/lib/zod-schema-utils.js.bak +0 -97
- package/dist/types/baseDB.d.ts.bak +0 -25
- package/dist/types/build/copy-static.d.ts.bak +0 -31
- package/dist/types/build/rspack-config.d.ts.bak +0 -8
- package/dist/types/cli/cli-runner.d.ts.bak +0 -14
- package/dist/types/cli/index.d.ts.bak +0 -2
- package/dist/types/common.d.ts.bak +0 -12
- package/dist/types/constants/example-code.d.ts.bak +0 -2
- package/dist/types/constants/index.d.ts.bak +0 -21
- package/dist/types/env/basic.d.ts.bak +0 -6
- package/dist/types/env/constants.d.ts.bak +0 -40
- package/dist/types/env/global-config-manager.d.ts.bak +0 -32
- package/dist/types/env/helper.d.ts.bak +0 -4
- package/dist/types/env/index.d.ts.bak +0 -4
- package/dist/types/env/init-debug.d.ts.bak +0 -1
- package/dist/types/env/model-config-manager.d.ts.bak +0 -25
- package/dist/types/env/parse-model-config.d.ts.bak +0 -31
- package/dist/types/env/types.d.ts.bak +0 -318
- package/dist/types/env/utils.d.ts.bak +0 -38
- package/dist/types/extractor/constants.d.ts.bak +0 -1
- package/dist/types/extractor/debug.d.ts.bak +0 -1
- package/dist/types/extractor/dom-util.d.ts.bak +0 -56
- package/dist/types/extractor/index.d.ts.bak +0 -32
- package/dist/types/extractor/locator.d.ts.bak +0 -9
- package/dist/types/extractor/tree.d.ts.bak +0 -6
- package/dist/types/extractor/util.d.ts.bak +0 -47
- package/dist/types/extractor/web-extractor.d.ts.bak +0 -19
- package/dist/types/img/box-select.d.ts.bak +0 -26
- package/dist/types/img/canvas-fallback.d.ts.bak +0 -105
- package/dist/types/img/get-photon.d.ts.bak +0 -19
- package/dist/types/img/get-sharp.d.ts.bak +0 -3
- package/dist/types/img/index.d.ts.bak +0 -3
- package/dist/types/img/info.d.ts.bak +0 -29
- package/dist/types/img/transform.d.ts.bak +0 -107
- package/dist/types/index.d.ts.bak +0 -4
- package/dist/types/logger.d.ts.bak +0 -5
- package/dist/types/mcp/base-server.d.ts.bak +0 -93
- package/dist/types/mcp/base-tools.d.ts.bak +0 -79
- package/dist/types/mcp/chrome-path.d.ts.bak +0 -2
- package/dist/types/mcp/index.d.ts.bak +0 -7
- package/dist/types/mcp/inject-report-html-plugin.d.ts.bak +0 -18
- package/dist/types/mcp/launcher-helper.d.ts.bak +0 -94
- package/dist/types/mcp/tool-generator.d.ts.bak +0 -10
- package/dist/types/mcp/types.d.ts.bak +0 -103
- package/dist/types/node/fs.d.ts.bak +0 -15
- package/dist/types/node/index.d.ts.bak +0 -2
- package/dist/types/node/port.d.ts.bak +0 -8
- package/dist/types/oss/demo.d.ts.bak +0 -1
- package/dist/types/oss/index.d.ts.bak +0 -34
- package/dist/types/polyfills/async-hooks.d.ts.bak +0 -6
- package/dist/types/polyfills/index.d.ts.bak +0 -4
- package/dist/types/types/index.d.ts.bak +0 -34
- package/dist/types/us-keyboard-layout.d.ts.bak +0 -32
- package/dist/types/utils.d.ts.bak +0 -34
- package/dist/types/zod-schema-utils.d.ts.bak +0 -23
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canvas-based fallback for image processing when Photon WASM fails to load.
|
|
3
|
-
* Provides a compatible API with Photon for browser environments.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Canvas-based image class that mimics PhotonImage API
|
|
7
|
-
*/
|
|
8
|
-
export declare class CanvasImage {
|
|
9
|
-
private canvas;
|
|
10
|
-
private ctx;
|
|
11
|
-
private _width;
|
|
12
|
-
private _height;
|
|
13
|
-
constructor(canvas: HTMLCanvasElement);
|
|
14
|
-
get_width(): number;
|
|
15
|
-
get_height(): number;
|
|
16
|
-
get_raw_pixels(): Uint8Array;
|
|
17
|
-
get_bytes_jpeg(quality: number): Uint8Array;
|
|
18
|
-
free(): void;
|
|
19
|
-
_getCanvas(): HTMLCanvasElement;
|
|
20
|
-
_getContext(): CanvasRenderingContext2D;
|
|
21
|
-
/**
|
|
22
|
-
* Create a CanvasImage from a base64 string
|
|
23
|
-
*/
|
|
24
|
-
static new_from_base64(base64Body: string): Promise<CanvasImage>;
|
|
25
|
-
/**
|
|
26
|
-
* Create a CanvasImage from a byte array (async version)
|
|
27
|
-
*/
|
|
28
|
-
static new_from_byteslice(bytes: Uint8Array): Promise<CanvasImage>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sampling filter enum (compatible with Photon)
|
|
32
|
-
*/
|
|
33
|
-
export declare const CanvasSamplingFilter: {
|
|
34
|
-
readonly Nearest: "nearest";
|
|
35
|
-
readonly Triangle: "triangle";
|
|
36
|
-
readonly CatmullRom: "catmullrom";
|
|
37
|
-
readonly Gaussian: "gaussian";
|
|
38
|
-
readonly Lanczos3: "lanczos3";
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* RGBA color class (compatible with Photon)
|
|
42
|
-
*/
|
|
43
|
-
export declare class CanvasRgba {
|
|
44
|
-
r: number;
|
|
45
|
-
g: number;
|
|
46
|
-
b: number;
|
|
47
|
-
a: number;
|
|
48
|
-
constructor(r: number, g: number, b: number, a: number);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Resize an image
|
|
52
|
-
*/
|
|
53
|
-
export declare function canvasResize(image: CanvasImage, newWidth: number, newHeight: number, _filter: string): CanvasImage;
|
|
54
|
-
/**
|
|
55
|
-
* Crop an image
|
|
56
|
-
*/
|
|
57
|
-
export declare function canvasCrop(image: CanvasImage, x1: number, y1: number, x2: number, y2: number): CanvasImage;
|
|
58
|
-
/**
|
|
59
|
-
* Add padding to the right of an image
|
|
60
|
-
*/
|
|
61
|
-
export declare function canvasPaddingRight(image: CanvasImage, padding: number, color: CanvasRgba): CanvasImage;
|
|
62
|
-
/**
|
|
63
|
-
* Add padding to the bottom of an image
|
|
64
|
-
*/
|
|
65
|
-
export declare function canvasPaddingBottom(image: CanvasImage, padding: number, color: CanvasRgba): CanvasImage;
|
|
66
|
-
/**
|
|
67
|
-
* Add uniform padding to an image
|
|
68
|
-
*/
|
|
69
|
-
export declare function canvasPaddingUniform(image: CanvasImage, padding: number, color: CanvasRgba): CanvasImage;
|
|
70
|
-
/**
|
|
71
|
-
* Add padding to the left of an image
|
|
72
|
-
*/
|
|
73
|
-
export declare function canvasPaddingLeft(image: CanvasImage, padding: number, color: CanvasRgba): CanvasImage;
|
|
74
|
-
/**
|
|
75
|
-
* Add padding to the top of an image
|
|
76
|
-
*/
|
|
77
|
-
export declare function canvasPaddingTop(image: CanvasImage, padding: number, color: CanvasRgba): CanvasImage;
|
|
78
|
-
/**
|
|
79
|
-
* Watermark an image (overlay one image on another)
|
|
80
|
-
*/
|
|
81
|
-
export declare function canvasWatermark(base: CanvasImage, overlay: CanvasImage, x: number, y: number): CanvasImage;
|
|
82
|
-
/**
|
|
83
|
-
* Create and return the canvas fallback module with Photon-compatible API
|
|
84
|
-
*/
|
|
85
|
-
export declare function createCanvasFallbackModule(): {
|
|
86
|
-
PhotonImage: typeof CanvasImage;
|
|
87
|
-
SamplingFilter: {
|
|
88
|
-
readonly Nearest: "nearest";
|
|
89
|
-
readonly Triangle: "triangle";
|
|
90
|
-
readonly CatmullRom: "catmullrom";
|
|
91
|
-
readonly Gaussian: "gaussian";
|
|
92
|
-
readonly Lanczos3: "lanczos3";
|
|
93
|
-
};
|
|
94
|
-
resize: typeof canvasResize;
|
|
95
|
-
crop: typeof canvasCrop;
|
|
96
|
-
open_image: () => never;
|
|
97
|
-
base64_to_image: typeof CanvasImage.new_from_base64;
|
|
98
|
-
padding_uniform: typeof canvasPaddingUniform;
|
|
99
|
-
padding_left: typeof canvasPaddingLeft;
|
|
100
|
-
padding_right: typeof canvasPaddingRight;
|
|
101
|
-
padding_top: typeof canvasPaddingTop;
|
|
102
|
-
padding_bottom: typeof canvasPaddingBottom;
|
|
103
|
-
watermark: typeof canvasWatermark;
|
|
104
|
-
Rgba: typeof CanvasRgba;
|
|
105
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default function getPhoton(): Promise<{
|
|
2
|
-
PhotonImage: typeof import('@silvia-odwyer/photon-node').PhotonImage;
|
|
3
|
-
SamplingFilter: typeof import('@silvia-odwyer/photon-node').SamplingFilter;
|
|
4
|
-
resize: typeof import('@silvia-odwyer/photon-node').resize;
|
|
5
|
-
crop: typeof import('@silvia-odwyer/photon-node').crop;
|
|
6
|
-
open_image: typeof import('@silvia-odwyer/photon-node').open_image;
|
|
7
|
-
base64_to_image: typeof import('@silvia-odwyer/photon-node').base64_to_image;
|
|
8
|
-
padding_uniform: typeof import('@silvia-odwyer/photon-node').padding_uniform;
|
|
9
|
-
padding_left: typeof import('@silvia-odwyer/photon-node').padding_left;
|
|
10
|
-
padding_right: typeof import('@silvia-odwyer/photon-node').padding_right;
|
|
11
|
-
padding_top: typeof import('@silvia-odwyer/photon-node').padding_top;
|
|
12
|
-
padding_bottom: typeof import('@silvia-odwyer/photon-node').padding_bottom;
|
|
13
|
-
watermark: typeof import('@silvia-odwyer/photon-node').watermark;
|
|
14
|
-
Rgba: typeof import('@silvia-odwyer/photon-node').Rgba;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* Check if we're using the Canvas fallback instead of Photon
|
|
18
|
-
*/
|
|
19
|
-
export declare function isUsingCanvasFallback(): boolean;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { imageInfoOfBase64, isValidPNGImageBuffer, isValidJPEGImageBuffer, isValidImageBuffer, } from './info';
|
|
2
|
-
export { resizeAndConvertImgBuffer, resizeImgBase64, convertToJpegBase64, zoomForGPT4o, saveBase64Image, paddingToMatchBlockByBase64, cropByRect, scaleImage, localImg2Base64, httpImg2Base64, preProcessImageUrl, parseBase64, createImgBase64ByFormat, } from './transform';
|
|
3
|
-
export { processImageElementInfo, compositeElementInfoImg, annotateRects, } from './box-select';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Size } from '../types';
|
|
2
|
-
export interface ImageInfo extends Size {
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Retrieves the dimensions of an image from a base64-encoded string
|
|
6
|
-
*
|
|
7
|
-
* @param imageBase64 - The base64-encoded image data
|
|
8
|
-
* @returns A Promise that resolves to an object containing the width and height of the image
|
|
9
|
-
* @throws Error if the image data is invalid
|
|
10
|
-
*/
|
|
11
|
-
export declare function imageInfoOfBase64(imageBase64: string): Promise<ImageInfo>;
|
|
12
|
-
/**
|
|
13
|
-
* Check if the Buffer is a valid PNG image
|
|
14
|
-
* @param buffer The Buffer to check
|
|
15
|
-
* @returns true if the Buffer is a valid PNG image, otherwise false
|
|
16
|
-
*/
|
|
17
|
-
export declare function isValidPNGImageBuffer(buffer: Buffer): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Check if the Buffer is a valid JPEG image
|
|
20
|
-
* @param buffer The Buffer to check
|
|
21
|
-
* @returns true if the Buffer is a valid JPEG image, otherwise false
|
|
22
|
-
*/
|
|
23
|
-
export declare function isValidJPEGImageBuffer(buffer: Buffer): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Check if the Buffer is a valid image (PNG or JPEG)
|
|
26
|
-
* @param buffer The Buffer to check
|
|
27
|
-
* @returns true if the Buffer is a valid PNG or JPEG image, otherwise false
|
|
28
|
-
*/
|
|
29
|
-
export declare function isValidImageBuffer(buffer: Buffer): boolean;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import type { PhotonImage as PhotonImageType } from '@silvia-odwyer/photon-node';
|
|
3
|
-
import type { Rect } from '../types';
|
|
4
|
-
/**
|
|
5
|
-
* Saves a Base64-encoded image to a file
|
|
6
|
-
*
|
|
7
|
-
* @param options - An object containing the Base64-encoded image data and the output file path
|
|
8
|
-
* @param options.base64Data - The Base64-encoded image data
|
|
9
|
-
* @param options.outputPath - The path where the image will be saved
|
|
10
|
-
* @throws Error if there is an error during the saving process
|
|
11
|
-
*/
|
|
12
|
-
export declare function saveBase64Image(options: {
|
|
13
|
-
base64Data: string;
|
|
14
|
-
outputPath: string;
|
|
15
|
-
}): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Resizes an image from Buffer, maybe return a new format
|
|
18
|
-
* - If the image is Resized, the returned format will be jpg.
|
|
19
|
-
* - If the image is not Resized, it will return to its original format.
|
|
20
|
-
* @returns { buffer: resized buffer, format: the new format}
|
|
21
|
-
*/
|
|
22
|
-
export declare function resizeAndConvertImgBuffer(inputFormat: string, inputData: Buffer, newSize: {
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
}): Promise<{
|
|
26
|
-
buffer: Buffer;
|
|
27
|
-
format: string;
|
|
28
|
-
}>;
|
|
29
|
-
export declare const createImgBase64ByFormat: (format: string, body: string) => string;
|
|
30
|
-
export declare function resizeImgBase64(inputBase64: string, newSize: {
|
|
31
|
-
width: number;
|
|
32
|
-
height: number;
|
|
33
|
-
}): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* Calculates new dimensions for an image while maintaining its aspect ratio.
|
|
36
|
-
*
|
|
37
|
-
* This function is designed to resize an image to fit within a specified maximum width and height
|
|
38
|
-
* while maintaining the original aspect ratio. If the original width or height exceeds the maximum
|
|
39
|
-
* dimensions, the image will be scaled down to fit.
|
|
40
|
-
*
|
|
41
|
-
* @param {number} originalWidth - The original width of the image.
|
|
42
|
-
* @param {number} originalHeight - The original height of the image.
|
|
43
|
-
* @returns {Object} An object containing the new width and height.
|
|
44
|
-
* @throws {Error} Throws an error if the width or height is not a positive number.
|
|
45
|
-
*/
|
|
46
|
-
export declare function zoomForGPT4o(originalWidth: number, originalHeight: number): {
|
|
47
|
-
width: number;
|
|
48
|
-
height: number;
|
|
49
|
-
};
|
|
50
|
-
export declare function photonFromBase64(base64: string): Promise<PhotonImageType>;
|
|
51
|
-
export declare function paddingToMatchBlock(image: PhotonImageType, blockSize?: number): Promise<{
|
|
52
|
-
width: number;
|
|
53
|
-
height: number;
|
|
54
|
-
image: PhotonImageType;
|
|
55
|
-
}>;
|
|
56
|
-
export declare function paddingToMatchBlockByBase64(imageBase64: string, blockSize?: number): Promise<{
|
|
57
|
-
width: number;
|
|
58
|
-
height: number;
|
|
59
|
-
imageBase64: string;
|
|
60
|
-
}>;
|
|
61
|
-
export declare function cropByRect(imageBase64: string, rect: Rect, paddingImage: boolean): Promise<{
|
|
62
|
-
width: number;
|
|
63
|
-
height: number;
|
|
64
|
-
imageBase64: string;
|
|
65
|
-
}>;
|
|
66
|
-
export declare function photonToBase64(image: PhotonImageType, quality?: number): Promise<string>;
|
|
67
|
-
export declare const httpImg2Base64: (url: string) => Promise<string>;
|
|
68
|
-
/**
|
|
69
|
-
* Convert image file to base64 string
|
|
70
|
-
* Because this method is synchronous, the npm package `sharp` cannot be used to detect the file type.
|
|
71
|
-
* TODO: convert to webp to reduce base64 size.
|
|
72
|
-
*/
|
|
73
|
-
export declare const localImg2Base64: (imgPath: string, withoutHeader?: boolean) => string;
|
|
74
|
-
/**
|
|
75
|
-
* PreProcess image url to ensure image is accessible to LLM.
|
|
76
|
-
* @param url - The url of the image, it can be a http url or a base64 string or a file path
|
|
77
|
-
* @param convertHttpImage2Base64 - Whether to convert http image to base64, if true, the http image will be converted to base64, otherwise, the http image will be returned as is
|
|
78
|
-
* @returns The base64 string of the image (when convertHttpImage2Base64 is true or url is a file path) or the http image url
|
|
79
|
-
*/
|
|
80
|
-
export declare const preProcessImageUrl: (url: string, convertHttpImage2Base64: boolean) => Promise<string>;
|
|
81
|
-
/**
|
|
82
|
-
* parse base64 string to get mimeType and body
|
|
83
|
-
*/
|
|
84
|
-
export declare const parseBase64: (fullBase64String: string) => {
|
|
85
|
-
mimeType: string;
|
|
86
|
-
body: string;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Convert a base64 image to JPEG with specified quality (no resize).
|
|
90
|
-
* If the image is already JPEG, re-encodes at the given quality.
|
|
91
|
-
*
|
|
92
|
-
* @param inputBase64 - Full data-URI base64 string (e.g. "data:image/png;base64,...")
|
|
93
|
-
* @param quality - JPEG quality 1-100
|
|
94
|
-
* @returns JPEG data-URI base64 string
|
|
95
|
-
*/
|
|
96
|
-
export declare function convertToJpegBase64(inputBase64: string, quality: number): Promise<string>;
|
|
97
|
-
/**
|
|
98
|
-
* Scales an image by a specified factor using Sharp or Photon
|
|
99
|
-
* @param imageBase64 - Base64 encoded image
|
|
100
|
-
* @param scale - Scale factor (e.g., 2 for 2x, 1.5 for 1.5x)
|
|
101
|
-
* @returns Scaled image with new dimensions
|
|
102
|
-
*/
|
|
103
|
-
export declare function scaleImage(imageBase64: string, scale: number): Promise<{
|
|
104
|
-
width: number;
|
|
105
|
-
height: number;
|
|
106
|
-
imageBase64: string;
|
|
107
|
-
}>;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { ParseArgsConfig } from 'node:util';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import type { IMidsceneTools } from './types';
|
|
4
|
-
export interface BaseMCPServerConfig {
|
|
5
|
-
name: string;
|
|
6
|
-
version: string;
|
|
7
|
-
description: string;
|
|
8
|
-
}
|
|
9
|
-
export interface HttpLaunchOptions {
|
|
10
|
-
port: number;
|
|
11
|
-
host?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface LaunchMCPServerResult {
|
|
14
|
-
/**
|
|
15
|
-
* The MCP server port (for HTTP mode)
|
|
16
|
-
*/
|
|
17
|
-
port?: number;
|
|
18
|
-
/**
|
|
19
|
-
* The server host (for HTTP mode)
|
|
20
|
-
*/
|
|
21
|
-
host?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Function to gracefully shutdown the MCP server
|
|
24
|
-
*/
|
|
25
|
-
close: () => Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* CLI argument configuration for MCP servers
|
|
29
|
-
*/
|
|
30
|
-
export declare const CLI_ARGS_CONFIG: ParseArgsConfig['options'];
|
|
31
|
-
export interface CLIArgs {
|
|
32
|
-
mode?: string;
|
|
33
|
-
port?: string;
|
|
34
|
-
host?: string;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Launch an MCP server based on CLI arguments
|
|
38
|
-
* Shared helper to reduce duplication across platform CLI entry points
|
|
39
|
-
*/
|
|
40
|
-
export declare function launchMCPServer(server: BaseMCPServer, args: CLIArgs): Promise<LaunchMCPServerResult>;
|
|
41
|
-
/**
|
|
42
|
-
* Base MCP Server class with programmatic launch() API
|
|
43
|
-
* Each platform extends this to provide their own tools manager
|
|
44
|
-
*/
|
|
45
|
-
export declare abstract class BaseMCPServer {
|
|
46
|
-
protected mcpServer: McpServer;
|
|
47
|
-
protected toolsManager?: IMidsceneTools;
|
|
48
|
-
protected config: BaseMCPServerConfig;
|
|
49
|
-
protected providedToolsManager?: IMidsceneTools;
|
|
50
|
-
constructor(config: BaseMCPServerConfig, toolsManager?: IMidsceneTools);
|
|
51
|
-
/**
|
|
52
|
-
* Platform-specific: create tools manager instance
|
|
53
|
-
* This is only called if no tools manager was provided in constructor
|
|
54
|
-
*/
|
|
55
|
-
protected abstract createToolsManager(): IMidsceneTools;
|
|
56
|
-
/**
|
|
57
|
-
* Initialize tools manager and attach to MCP server
|
|
58
|
-
*/
|
|
59
|
-
private initializeToolsManager;
|
|
60
|
-
/**
|
|
61
|
-
* Perform cleanup on shutdown
|
|
62
|
-
*/
|
|
63
|
-
private performCleanup;
|
|
64
|
-
/**
|
|
65
|
-
* Initialize and launch the MCP server with stdio transport
|
|
66
|
-
*/
|
|
67
|
-
launch(): Promise<LaunchMCPServerResult>;
|
|
68
|
-
/**
|
|
69
|
-
* Launch MCP server with HTTP transport
|
|
70
|
-
* Supports stateful sessions for web applications and service integration
|
|
71
|
-
*/
|
|
72
|
-
launchHttp(options: HttpLaunchOptions): Promise<LaunchMCPServerResult>;
|
|
73
|
-
/**
|
|
74
|
-
* Create a new HTTP session with transport
|
|
75
|
-
*/
|
|
76
|
-
private createHttpSession;
|
|
77
|
-
/**
|
|
78
|
-
* Start periodic session cleanup for inactive sessions
|
|
79
|
-
*/
|
|
80
|
-
private startSessionCleanup;
|
|
81
|
-
/**
|
|
82
|
-
* Setup shutdown handlers for HTTP server
|
|
83
|
-
*/
|
|
84
|
-
private setupHttpShutdownHandlers;
|
|
85
|
-
/**
|
|
86
|
-
* Get the underlying MCP server instance
|
|
87
|
-
*/
|
|
88
|
-
getServer(): McpServer;
|
|
89
|
-
/**
|
|
90
|
-
* Get the tools manager instance
|
|
91
|
-
*/
|
|
92
|
-
getToolsManager(): IMidsceneTools | undefined;
|
|
93
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { BaseAgent, BaseDevice, IMidsceneTools, ToolDefinition } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Base class for platform-specific MCP tools
|
|
5
|
-
* Generic type TAgent allows subclasses to use their specific agent types
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent> implements IMidsceneTools {
|
|
8
|
-
protected mcpServer?: McpServer;
|
|
9
|
-
protected agent?: TAgent;
|
|
10
|
-
protected toolDefinitions: ToolDefinition[];
|
|
11
|
-
/**
|
|
12
|
-
* Ensure agent is initialized and ready for use.
|
|
13
|
-
* Must be implemented by subclasses to create platform-specific agent.
|
|
14
|
-
* @param initParam Optional initialization parameter (platform-specific, e.g., URL, device ID)
|
|
15
|
-
* @returns Promise resolving to initialized agent instance
|
|
16
|
-
* @throws Error if agent initialization fails
|
|
17
|
-
*/
|
|
18
|
-
protected abstract ensureAgent(initParam?: string): Promise<TAgent>;
|
|
19
|
-
/**
|
|
20
|
-
* Optional: prepare platform-specific tools (e.g., device connection)
|
|
21
|
-
*/
|
|
22
|
-
protected preparePlatformTools(): ToolDefinition[];
|
|
23
|
-
/**
|
|
24
|
-
* Must be implemented by subclasses to create a temporary device instance
|
|
25
|
-
* This allows getting real actionSpace without connecting to device
|
|
26
|
-
*/
|
|
27
|
-
protected abstract createTemporaryDevice(): BaseDevice;
|
|
28
|
-
/**
|
|
29
|
-
* Initialize all tools by querying actionSpace
|
|
30
|
-
* Uses two-layer fallback strategy:
|
|
31
|
-
* 1. Try to get actionSpace from connected agent (if available)
|
|
32
|
-
* 2. Create temporary device instance to read actionSpace (always succeeds)
|
|
33
|
-
*/
|
|
34
|
-
initTools(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Attach to MCP server and register all tools
|
|
37
|
-
*/
|
|
38
|
-
attachToServer(server: McpServer): void;
|
|
39
|
-
/**
|
|
40
|
-
* Cleanup method - destroy agent and release resources
|
|
41
|
-
*/
|
|
42
|
-
destroy(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Get tool definitions
|
|
45
|
-
*/
|
|
46
|
-
getToolDefinitions(): ToolDefinition[];
|
|
47
|
-
/**
|
|
48
|
-
* Set agent for the tools manager
|
|
49
|
-
*/
|
|
50
|
-
setAgent(agent: TAgent): void;
|
|
51
|
-
/**
|
|
52
|
-
* Helper: Convert base64 screenshot to image content array
|
|
53
|
-
*/
|
|
54
|
-
protected buildScreenshotContent(screenshot: string): {
|
|
55
|
-
type: "image";
|
|
56
|
-
data: string;
|
|
57
|
-
mimeType: string;
|
|
58
|
-
}[];
|
|
59
|
-
/**
|
|
60
|
-
* Helper: Build a simple text result for tool responses
|
|
61
|
-
*/
|
|
62
|
-
protected buildTextResult(text: string): {
|
|
63
|
-
content: {
|
|
64
|
-
type: "text";
|
|
65
|
-
text: string;
|
|
66
|
-
}[];
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Create a disconnect handler for releasing platform resources
|
|
70
|
-
* @param platformName Human-readable platform name for the response message
|
|
71
|
-
* @returns Handler function that destroys the agent and returns appropriate response
|
|
72
|
-
*/
|
|
73
|
-
protected createDisconnectHandler(platformName: string): () => Promise<{
|
|
74
|
-
content: {
|
|
75
|
-
type: "text";
|
|
76
|
-
text: string;
|
|
77
|
-
}[];
|
|
78
|
-
}>;
|
|
79
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface RslibPluginApi {
|
|
2
|
-
onAfterBuild: (callback: () => void) => void;
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Rslib plugin to inject report HTML from @midscene/core dist into MCP bundle.
|
|
6
|
-
* This runs after build and reads the already-injected HTML from core.
|
|
7
|
-
*
|
|
8
|
-
* Prerequisites:
|
|
9
|
-
* - @midscene/report must be in devDependencies to ensure correct build order
|
|
10
|
-
* - @midscene/core dist must exist with injected HTML
|
|
11
|
-
*
|
|
12
|
-
* @param packageDir - The directory of the MCP package (use __dirname)
|
|
13
|
-
*/
|
|
14
|
-
export declare function injectReportHtmlFromCore(packageDir: string): {
|
|
15
|
-
name: string;
|
|
16
|
-
setup(api: RslibPluginApi): void;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { BaseMCPServer } from './base-server';
|
|
2
|
-
import type { HttpLaunchOptions, LaunchMCPServerResult } from './base-server';
|
|
3
|
-
import type { IMidsceneTools } from './types';
|
|
4
|
-
export interface LaunchMCPServerOptions extends HttpLaunchOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Whether to show server logs
|
|
7
|
-
* @default true
|
|
8
|
-
*/
|
|
9
|
-
verbose?: boolean;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Generic agent type (avoid importing from @midscene/core to prevent circular deps)
|
|
13
|
-
*/
|
|
14
|
-
export interface GenericAgent<TDevice = any> {
|
|
15
|
-
interface: TDevice;
|
|
16
|
-
constructor: {
|
|
17
|
-
name: string;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Additional information for logging server startup
|
|
22
|
-
*/
|
|
23
|
-
export interface StartupInfo {
|
|
24
|
-
port?: number;
|
|
25
|
-
host?: string;
|
|
26
|
-
}
|
|
27
|
-
export interface MCPServerLauncherConfig<AgentType extends GenericAgent = GenericAgent, ToolsManagerType extends IMidsceneTools = IMidsceneTools> {
|
|
28
|
-
agent: AgentType;
|
|
29
|
-
platformName: string;
|
|
30
|
-
ToolsManagerClass: new (...args: any[]) => ToolsManagerType;
|
|
31
|
-
MCPServerClass: new (toolsManager?: ToolsManagerType) => BaseMCPServer;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create a generic MCP server launcher for a given agent, tools manager, and MCP server.
|
|
35
|
-
*
|
|
36
|
-
* This helper centralizes the common wiring logic used by platform-specific launchers:
|
|
37
|
-
* it constructs a tools manager, attaches the provided `agent` to it, then instantiates
|
|
38
|
-
* the `MCPServerClass` and exposes convenience methods to start the server over stdio
|
|
39
|
-
* (`launch`) or HTTP (`launchHttp`).
|
|
40
|
-
*
|
|
41
|
-
* Use this helper when adding a new platform-specific launcher or when you want to
|
|
42
|
-
* avoid duplicating boilerplate code for starting an MCP server. Typically, callers
|
|
43
|
-
* provide:
|
|
44
|
-
* - an `agent` instance that contains the underlying device on its `interface` property
|
|
45
|
-
* - a `ToolsManagerClass` that knows how to expose tools for that agent
|
|
46
|
-
* - an `MCPServerClass` that implements the MCP protocol and supports `launch` and
|
|
47
|
-
* `launchHttp` methods.
|
|
48
|
-
*
|
|
49
|
-
* The returned object has two methods:
|
|
50
|
-
* - `launch(options?)` to start the server using stdio transport
|
|
51
|
-
* - `launchHttp(options)` to start the server using HTTP transport
|
|
52
|
-
* Both methods accept a `verbose` flag to control console logging.
|
|
53
|
-
*
|
|
54
|
-
* @param config Configuration describing the agent, platform name (for logging),
|
|
55
|
-
* tools manager implementation, and MCP server implementation.
|
|
56
|
-
*
|
|
57
|
-
* @returns An object with `launch` and `launchHttp` methods to start the MCP server.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* import { createMCPServerLauncher } from '@midscene/shared/mcp';
|
|
62
|
-
* import { Agent } from '@midscene/core/agent';
|
|
63
|
-
* import { WebMidsceneTools } from './web-tools';
|
|
64
|
-
* import { WebMCPServer } from './server';
|
|
65
|
-
*
|
|
66
|
-
* const agent = new Agent();
|
|
67
|
-
* const launcher = createMCPServerLauncher({
|
|
68
|
-
* agent,
|
|
69
|
-
* platformName: 'Web',
|
|
70
|
-
* ToolsManagerClass: WebMidsceneTools,
|
|
71
|
-
* MCPServerClass: WebMCPServer,
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* // Start with stdio
|
|
75
|
-
* await launcher.launch({ verbose: true });
|
|
76
|
-
*
|
|
77
|
-
* // Or start with HTTP
|
|
78
|
-
* await launcher.launchHttp({ port: 3000, host: 'localhost' });
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
83
|
-
export declare function createMCPServerLauncher<AgentType extends GenericAgent, ToolsManagerType extends IMidsceneTools>(config: MCPServerLauncherConfig<AgentType, ToolsManagerType>): {
|
|
84
|
-
/**
|
|
85
|
-
* Launch the MCP server with stdio transport
|
|
86
|
-
*/
|
|
87
|
-
launch(options?: {
|
|
88
|
-
verbose?: boolean;
|
|
89
|
-
}): Promise<LaunchMCPServerResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Launch the MCP server with HTTP transport
|
|
92
|
-
*/
|
|
93
|
-
launchHttp(options: LaunchMCPServerOptions): Promise<LaunchMCPServerResult>;
|
|
94
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ActionSpaceItem, BaseAgent, ToolDefinition } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Converts DeviceAction from actionSpace into MCP ToolDefinition
|
|
4
|
-
* This is the core logic that removes need for hardcoded tool definitions
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateToolsFromActionSpace(actionSpace: ActionSpaceItem[], getAgent: () => Promise<BaseAgent>): ToolDefinition[];
|
|
7
|
-
/**
|
|
8
|
-
* Generate common tools (screenshot, act)
|
|
9
|
-
*/
|
|
10
|
-
export declare function generateCommonTools(getAgent: () => Promise<BaseAgent>): ToolDefinition[];
|