@godscene/shared 1.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +122 -0
- package/dist/es/cli/index.mjs +4 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +227 -0
- package/dist/es/constants/index.mjs +124 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +110 -0
- package/dist/es/env/global-config-manager.mjs +94 -0
- package/dist/es/env/helper.mjs +43 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +79 -0
- package/dist/es/env/parse-model-config.mjs +165 -0
- package/dist/es/env/types.mjs +232 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +641 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +96 -0
- package/dist/es/extractor/index.mjs +5 -0
- package/dist/es/extractor/locator.mjs +250 -0
- package/dist/es/extractor/tree.mjs +78 -0
- package/dist/es/extractor/util.mjs +245 -0
- package/dist/es/extractor/web-extractor.mjs +393 -0
- package/dist/es/img/box-select.mjs +824 -0
- package/dist/es/img/canvas-fallback.mjs +238 -0
- package/dist/es/img/get-photon.mjs +45 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +4 -0
- package/dist/es/img/info.mjs +35 -0
- package/dist/es/img/transform.mjs +275 -0
- package/dist/es/index.mjs +2 -0
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/logger.mjs +64 -0
- package/dist/es/mcp/base-server.mjs +282 -0
- package/dist/es/mcp/base-tools.mjs +159 -0
- package/dist/es/mcp/chrome-path.mjs +35 -0
- 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 +9 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
- package/dist/es/mcp/launcher-helper.mjs +52 -0
- package/dist/es/mcp/tool-generator.mjs +419 -0
- package/dist/es/mcp/types.mjs +3 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +2 -0
- package/dist/es/node/port.mjs +24 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +72 -0
- package/dist/es/zod-schema-utils.mjs +54 -0
- package/dist/lib/baseDB.js +149 -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 +181 -0
- package/dist/lib/cli/index.js +53 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +264 -0
- package/dist/lib/constants/index.js +221 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +153 -0
- package/dist/lib/env/global-config-manager.js +128 -0
- package/dist/lib/env/helper.js +80 -0
- package/dist/lib/env/index.js +90 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +113 -0
- package/dist/lib/env/parse-model-config.js +211 -0
- package/dist/lib/env/types.js +572 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +693 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +157 -0
- package/dist/lib/extractor/index.js +87 -0
- package/dist/lib/extractor/locator.js +296 -0
- package/dist/lib/extractor/tree.js +124 -0
- package/dist/lib/extractor/util.js +336 -0
- package/dist/lib/extractor/web-extractor.js +442 -0
- package/dist/lib/img/box-select.js +875 -0
- package/dist/lib/img/canvas-fallback.js +305 -0
- package/dist/lib/img/get-photon.js +82 -0
- package/dist/lib/img/get-sharp.js +45 -0
- package/dist/lib/img/index.js +95 -0
- package/dist/lib/img/info.js +92 -0
- package/dist/lib/img/transform.js +364 -0
- package/dist/lib/index.js +36 -0
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/mcp/base-server.js +332 -0
- package/dist/lib/mcp/base-tools.js +193 -0
- package/dist/lib/mcp/chrome-path.js +72 -0
- 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 +114 -0
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
- package/dist/lib/mcp/launcher-helper.js +86 -0
- package/dist/lib/mcp/tool-generator.js +456 -0
- package/dist/lib/mcp/types.js +40 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +65 -0
- package/dist/lib/node/port.js +61 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +58 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +148 -0
- package/dist/lib/zod-schema-utils.js +97 -0
- package/dist/types/baseDB.d.ts +25 -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 +19 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +61 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +50 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +4 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +25 -0
- package/dist/types/env/parse-model-config.d.ts +31 -0
- package/dist/types/env/types.d.ts +339 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +57 -0
- package/dist/types/extractor/index.d.ts +33 -0
- package/dist/types/extractor/locator.d.ts +9 -0
- package/dist/types/extractor/tree.d.ts +6 -0
- package/dist/types/extractor/util.d.ts +47 -0
- package/dist/types/extractor/web-extractor.d.ts +24 -0
- package/dist/types/img/box-select.d.ts +26 -0
- package/dist/types/img/canvas-fallback.d.ts +105 -0
- package/dist/types/img/get-photon.d.ts +19 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +3 -0
- package/dist/types/img/info.d.ts +34 -0
- package/dist/types/img/transform.d.ts +98 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/logger.d.ts +5 -0
- package/dist/types/mcp/base-server.d.ts +93 -0
- package/dist/types/mcp/base-tools.d.ts +148 -0
- package/dist/types/mcp/chrome-path.d.ts +2 -0
- 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 +9 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/launcher-helper.d.ts +94 -0
- package/dist/types/mcp/tool-generator.d.ts +10 -0
- package/dist/types/mcp/types.d.ts +113 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +2 -0
- package/dist/types/node/port.d.ts +8 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +36 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +34 -0
- package/dist/types/zod-schema-utils.d.ts +23 -0
- package/package.json +125 -0
- package/src/baseDB.ts +158 -0
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +230 -0
- package/src/cli/index.ts +4 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +227 -0
- package/src/constants/index.ts +139 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +303 -0
- package/src/env/global-config-manager.ts +191 -0
- package/src/env/helper.ts +58 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +34 -0
- package/src/env/model-config-manager.ts +149 -0
- package/src/env/parse-model-config.ts +357 -0
- package/src/env/types.ts +583 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +136 -0
- package/src/extractor/customLocator.ts +1245 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +231 -0
- package/src/extractor/index.ts +50 -0
- package/src/extractor/locator.ts +469 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +482 -0
- package/src/extractor/web-extractor.ts +617 -0
- package/src/img/box-select.ts +588 -0
- package/src/img/canvas-fallback.ts +393 -0
- package/src/img/get-photon.ts +108 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +27 -0
- package/src/img/info.ts +102 -0
- package/src/img/transform.ts +553 -0
- package/src/index.ts +1 -0
- package/src/key-alias-utils.ts +23 -0
- package/src/logger.ts +96 -0
- package/src/mcp/base-server.ts +500 -0
- package/src/mcp/base-tools.ts +391 -0
- package/src/mcp/chrome-path.ts +48 -0
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +119 -0
- package/src/mcp/launcher-helper.ts +200 -0
- package/src/mcp/tool-generator.ts +658 -0
- package/src/mcp/types.ts +131 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +2 -0
- package/src/node/port.ts +37 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +54 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +149 -0
- package/src/zod-schema-utils.ts +133 -0
|
@@ -0,0 +1,105 @@
|
|
|
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: BlobPart): 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
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { imageInfoOfBase64, isValidPNGImageBuffer, isValidJPEGImageBuffer, isValidImageBuffer, validateScreenshotBuffer, type ValidateScreenshotBufferOptions, } from './info';
|
|
2
|
+
export { resizeAndConvertImgBuffer, resizeImgBase64, zoomForGPT4o, saveBase64Image, paddingToMatchBlockByBase64, cropByRect, scaleImage, localImg2Base64, httpImg2Base64, preProcessImageUrl, parseBase64, createImgBase64ByFormat, } from './transform';
|
|
3
|
+
export { processImageElementInfo, compositeElementInfoImg, annotateRects, } from './box-select';
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
30
|
+
export interface ValidateScreenshotBufferOptions {
|
|
31
|
+
label: string;
|
|
32
|
+
minBufferSize?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function validateScreenshotBuffer(screenshotBuffer: Buffer | undefined, { label, minBufferSize }: ValidateScreenshotBufferOptions): asserts screenshotBuffer is Buffer;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
* Scales an image by a specified factor using Sharp or Photon
|
|
90
|
+
* @param imageBase64 - Base64 encoded image
|
|
91
|
+
* @param scale - Scale factor (e.g., 2 for 2x, 1.5 for 1.5x)
|
|
92
|
+
* @returns Scaled image with new dimensions
|
|
93
|
+
*/
|
|
94
|
+
export declare function scaleImage(imageBase64: string, scale: number): Promise<{
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
imageBase64: string;
|
|
98
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal-only helpers for CLI/MCP argument key aliasing.
|
|
3
|
+
* Not re-exported from the package entry point — keep consumers within
|
|
4
|
+
* `cli/` and `mcp/`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function kebabToCamel(str: string): string;
|
|
7
|
+
export declare function camelToKebab(str: string): string;
|
|
8
|
+
export declare function getKeyAliases(key: string): string[];
|
|
9
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import { type CliReportSession } from './cli-report-session';
|
|
4
|
+
import type { BaseAgent, BaseDevice, IMidsceneTools, ToolCliMetadata, ToolDefinition, ToolSchema } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Declarative description of a platform's agent init args.
|
|
7
|
+
* Collapses the `extractAgentInitParam` / `sanitizeToolArgs` /
|
|
8
|
+
* `getAgentInitArgSchema` trio into a single data declaration.
|
|
9
|
+
*/
|
|
10
|
+
export interface InitArgSpec<TInitParam> {
|
|
11
|
+
/** Arg namespace, e.g. `android`, `ios`. */
|
|
12
|
+
namespace: string;
|
|
13
|
+
/** Zod shape describing the init args. Field names drive the MCP schema. */
|
|
14
|
+
shape: Record<string, z.ZodTypeAny>;
|
|
15
|
+
/**
|
|
16
|
+
* Optional CLI presentation hints. These affect `--help` output for
|
|
17
|
+
* single-platform CLIs but do not alter MCP/YAML protocol keys.
|
|
18
|
+
*/
|
|
19
|
+
cli?: {
|
|
20
|
+
/** Prefer bare `--device-id`-style options in platform CLI help output. */
|
|
21
|
+
preferBareKeys?: boolean;
|
|
22
|
+
/** Override the displayed option name for specific init arg fields. */
|
|
23
|
+
preferredNames?: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Adapt extracted namespaced args into the concrete `TInitParam` passed to
|
|
27
|
+
* `ensureAgent`. Defaults to returning the raw extracted record.
|
|
28
|
+
*/
|
|
29
|
+
adapt?: (extracted: Record<string, unknown> | undefined) => TInitParam | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Base class for platform-specific MCP tools.
|
|
33
|
+
* @typeParam TAgent - Platform-specific agent type.
|
|
34
|
+
* @typeParam TInitParam - Platform-specific init parameter consumed by
|
|
35
|
+
* `ensureAgent`. Defaults to `undefined` for platforms that take no args.
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent, TInitParam = unknown> implements IMidsceneTools {
|
|
38
|
+
protected mcpServer?: McpServer;
|
|
39
|
+
protected agent?: TAgent;
|
|
40
|
+
protected toolDefinitions: ToolDefinition[];
|
|
41
|
+
/**
|
|
42
|
+
* Declarative init-arg spec. Subclasses that accept CLI/MCP init args should
|
|
43
|
+
* set this once and get `extractAgentInitParam` / `sanitizeToolArgs` /
|
|
44
|
+
* `getAgentInitArgSchema` auto-implemented.
|
|
45
|
+
*
|
|
46
|
+
* Declared with `declare` so that TS doesn't emit an `Object.defineProperty`
|
|
47
|
+
* for this field on the base constructor, which would otherwise overwrite
|
|
48
|
+
* a subclass field initializer under `useDefineForClassFields`.
|
|
49
|
+
*/
|
|
50
|
+
protected readonly initArgSpec?: InitArgSpec<TInitParam>;
|
|
51
|
+
/**
|
|
52
|
+
* Ensure agent is initialized and ready for use.
|
|
53
|
+
* Must be implemented by subclasses to create platform-specific agent.
|
|
54
|
+
* @param initParam Optional initialization parameter (platform-specific, e.g., URL, device ID)
|
|
55
|
+
* @returns Promise resolving to initialized agent instance
|
|
56
|
+
* @throws Error if agent initialization fails
|
|
57
|
+
*/
|
|
58
|
+
protected abstract ensureAgent(initParam?: TInitParam): Promise<TAgent>;
|
|
59
|
+
private getInitArgKeys;
|
|
60
|
+
/**
|
|
61
|
+
* Extract a platform-specific agent init parameter from CLI/MCP tool args.
|
|
62
|
+
*/
|
|
63
|
+
protected extractAgentInitParam(args: Record<string, unknown>): TInitParam | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Remove platform-specific init args before dispatching a tool payload to the action itself.
|
|
66
|
+
*/
|
|
67
|
+
protected sanitizeToolArgs(args: Record<string, unknown>): Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Expose platform-specific init args on action/common tool schemas.
|
|
70
|
+
*/
|
|
71
|
+
protected getAgentInitArgSchema(): ToolSchema;
|
|
72
|
+
/**
|
|
73
|
+
* Expose CLI-only metadata for platform init args so single-platform help can
|
|
74
|
+
* show ergonomic bare flags while the underlying schema stays namespaced.
|
|
75
|
+
* When `preferBareKeys` is enabled, single-platform CLIs only accept the
|
|
76
|
+
* bare spellings; namespaced dotted spellings remain available through the
|
|
77
|
+
* MCP/YAML schema instead of the platform CLI surface.
|
|
78
|
+
*/
|
|
79
|
+
protected getAgentInitArgCliMetadata(): ToolCliMetadata | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Optional: prepare platform-specific tools (e.g., device connection)
|
|
82
|
+
*/
|
|
83
|
+
protected preparePlatformTools(): ToolDefinition[];
|
|
84
|
+
protected getCliReportSessionName(): string | undefined;
|
|
85
|
+
protected createNewCliReportSession(targetIdentity?: string): CliReportSession | undefined;
|
|
86
|
+
protected commitCliReportSession(session?: CliReportSession): void;
|
|
87
|
+
protected readCliReportFileName(): string | undefined;
|
|
88
|
+
protected readCliReportAgentOptions(): {
|
|
89
|
+
reportFileName: string;
|
|
90
|
+
reportAttributes: Record<string, string>;
|
|
91
|
+
} | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Must be implemented by subclasses to create a temporary device instance
|
|
94
|
+
* This allows getting real actionSpace without connecting to device
|
|
95
|
+
*/
|
|
96
|
+
protected abstract createTemporaryDevice(): BaseDevice;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize all tools by querying actionSpace
|
|
99
|
+
* Uses two-layer fallback strategy:
|
|
100
|
+
* 1. Try to get actionSpace from connected agent (if available)
|
|
101
|
+
* 2. Create temporary device instance to read actionSpace (always succeeds)
|
|
102
|
+
*/
|
|
103
|
+
initTools(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Attach to MCP server and register all tools
|
|
106
|
+
*/
|
|
107
|
+
attachToServer(server: McpServer): void;
|
|
108
|
+
/**
|
|
109
|
+
* Cleanup method - destroy agent and release resources
|
|
110
|
+
*/
|
|
111
|
+
destroy(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Get tool definitions
|
|
114
|
+
*/
|
|
115
|
+
getToolDefinitions(): ToolDefinition[];
|
|
116
|
+
/**
|
|
117
|
+
* Set agent for the tools manager
|
|
118
|
+
*/
|
|
119
|
+
setAgent(agent: TAgent): void;
|
|
120
|
+
/**
|
|
121
|
+
* Helper: Convert base64 screenshot to image content array
|
|
122
|
+
*/
|
|
123
|
+
protected buildScreenshotContent(screenshot: string): {
|
|
124
|
+
type: "image";
|
|
125
|
+
data: string;
|
|
126
|
+
mimeType: string;
|
|
127
|
+
}[];
|
|
128
|
+
/**
|
|
129
|
+
* Helper: Build a simple text result for tool responses
|
|
130
|
+
*/
|
|
131
|
+
protected buildTextResult(text: string): {
|
|
132
|
+
content: {
|
|
133
|
+
type: "text";
|
|
134
|
+
text: string;
|
|
135
|
+
}[];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Create a disconnect handler for releasing platform resources
|
|
139
|
+
* @param platformName Human-readable platform name for the response message
|
|
140
|
+
* @returns Handler function that destroys the agent and returns appropriate response
|
|
141
|
+
*/
|
|
142
|
+
protected createDisconnectHandler(platformName: string): () => Promise<{
|
|
143
|
+
content: {
|
|
144
|
+
type: "text";
|
|
145
|
+
text: string;
|
|
146
|
+
}[];
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CliReportSession {
|
|
2
|
+
version: 1;
|
|
3
|
+
sessionName: string;
|
|
4
|
+
targetIdentity?: string;
|
|
5
|
+
reportFileName: string;
|
|
6
|
+
reportPath: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function generateCliReportSession(sessionName: string, targetIdentity?: string): CliReportSession;
|
|
10
|
+
export declare function writeCliReportSession(session: CliReportSession): void;
|
|
11
|
+
export declare function createCliReportSession(sessionName: string, targetIdentity?: string): CliReportSession;
|
|
12
|
+
export declare function readCliReportSession(sessionName: string): CliReportSession | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract a human-readable message from an unknown thrown value.
|
|
3
|
+
*
|
|
4
|
+
* Many SDK/transport layers reject with structured objects (e.g.
|
|
5
|
+
* `{ code, message }`, `{ error: { message } }`, `{ cause: { message } }`)
|
|
6
|
+
* rather than `Error` instances. `String(obj)` collapses those to
|
|
7
|
+
* `"[object Object]"`, which is useless for diagnostics. This helper walks
|
|
8
|
+
* the common shapes, falls back to `JSON.stringify`, and finally to
|
|
9
|
+
* `Object.prototype.toString.call` so that callers always get something
|
|
10
|
+
* actionable in logs and surfaced tool results.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './base-server';
|
|
2
|
+
export * from './base-tools';
|
|
3
|
+
export * from './init-arg-utils';
|
|
4
|
+
export * from './error-formatter';
|
|
5
|
+
export * from './tool-generator';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './inject-report-html-plugin';
|
|
8
|
+
export * from './launcher-helper';
|
|
9
|
+
export * from './chrome-path';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ToolSchema } from './types';
|
|
3
|
+
export declare function extractNamespacedArgs<TFieldName extends string, TArgs extends Record<string, unknown> = Record<string, unknown>>(args: Record<string, unknown>, namespace: string, keys: readonly TFieldName[]): TArgs | undefined;
|
|
4
|
+
export declare function sanitizeNamespacedArgs(args: Record<string, unknown>, namespace: string, keys: readonly string[]): Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Build a flat MCP tool schema whose keys are dotted `"<namespace>.<field>"`.
|
|
7
|
+
*
|
|
8
|
+
* We intentionally stay flat (rather than `{ namespace: z.object({...}) }`) so
|
|
9
|
+
* that CLI (`--android.device-id`), MCP clients, and `--help` output all share
|
|
10
|
+
* the same spelling. `readNamespacedArg` understands all three input shapes:
|
|
11
|
+
* nested namespace object, dotted flat key, and bare key fallback.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createNamespacedInitArgSchema(namespace: string, shape: Record<string, z.ZodTypeAny>): ToolSchema;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface RslibPluginApi {
|
|
2
|
+
onAfterBuild: (callback: () => void) => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Rslib plugin to inject report HTML from @godscene/core dist into MCP bundle.
|
|
6
|
+
* This runs after build and reads the already-injected HTML from core.
|
|
7
|
+
*
|
|
8
|
+
* Prerequisites:
|
|
9
|
+
* - @godscene/report must be in devDependencies to ensure correct build order
|
|
10
|
+
* - @godscene/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 {};
|