@aiscene/shared 8.0.1 → 8.0.2
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/img/info.mjs +20 -11
- package/dist/es/mcp/base-server.mjs +1 -1
- package/dist/es/mcp/tool-generator.mjs +1 -1
- package/dist/lib/img/info.js +20 -11
- package/dist/lib/mcp/base-server.js +1 -1
- package/dist/lib/mcp/tool-generator.js +1 -1
- package/package.json +1 -1
- package/src/img/info.ts +45 -9
- package/src/mcp/base-server.ts +1 -1
- package/src/mcp/base-tools.ts +1 -1
- package/src/mcp/tool-generator.ts +1 -1
package/dist/es/img/info.mjs
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import node_assert from "node:assert";
|
|
2
2
|
import get_photon from "./get-photon.mjs";
|
|
3
3
|
async function imageInfoOfBase64(imageBase64) {
|
|
4
|
-
|
|
4
|
+
if (!imageBase64 || 'string' != typeof imageBase64) throw new Error('Invalid image base64: data is empty or not a string');
|
|
5
5
|
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, '');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
width
|
|
14
|
-
height
|
|
15
|
-
|
|
6
|
+
if (!base64Data || 0 === base64Data.length) throw new Error('Invalid image base64: no data after stripping prefix');
|
|
7
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64Data)) throw new Error('Invalid image base64: contains invalid characters');
|
|
8
|
+
if (base64Data.length < 4) throw new Error(`Invalid image base64: data too short (${base64Data.length} characters)`);
|
|
9
|
+
try {
|
|
10
|
+
const { PhotonImage } = await get_photon();
|
|
11
|
+
const result = PhotonImage.new_from_base64(base64Data);
|
|
12
|
+
const image = result instanceof Promise ? await result : result;
|
|
13
|
+
const width = image.get_width();
|
|
14
|
+
const height = image.get_height();
|
|
15
|
+
image.free();
|
|
16
|
+
node_assert(width && height, 'Invalid image: cannot get width or height');
|
|
17
|
+
return {
|
|
18
|
+
width,
|
|
19
|
+
height
|
|
20
|
+
};
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof Error && error.message.includes('unreachable')) throw new Error(`Failed to decode image: invalid or corrupted image data. Original error: ${error.message}`);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
16
25
|
}
|
|
17
26
|
function isValidPNGImageBuffer(buffer) {
|
|
18
27
|
if (!buffer || buffer.length < 8) return false;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { setIsMcp } from "../utils.mjs";
|
|
3
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
4
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
6
5
|
import express from "express";
|
|
6
|
+
import { setIsMcp } from "../utils.mjs";
|
|
7
7
|
function _define_property(obj, key, value) {
|
|
8
8
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
9
9
|
value: value,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parseBase64 } from "../img/index.mjs";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { parseBase64 } from "../img/index.mjs";
|
|
3
3
|
import { getZodDescription, getZodTypeName, isMidsceneLocatorField, unwrapZodField } from "../zod-schema-utils.mjs";
|
|
4
4
|
function getErrorMessage(error) {
|
|
5
5
|
return error instanceof Error ? error.message : String(error);
|
package/dist/lib/img/info.js
CHANGED
|
@@ -43,18 +43,27 @@ var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_
|
|
|
43
43
|
const external_get_photon_js_namespaceObject = require("./get-photon.js");
|
|
44
44
|
var external_get_photon_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_photon_js_namespaceObject);
|
|
45
45
|
async function imageInfoOfBase64(imageBase64) {
|
|
46
|
-
|
|
46
|
+
if (!imageBase64 || 'string' != typeof imageBase64) throw new Error('Invalid image base64: data is empty or not a string');
|
|
47
47
|
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, '');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
width
|
|
56
|
-
height
|
|
57
|
-
|
|
48
|
+
if (!base64Data || 0 === base64Data.length) throw new Error('Invalid image base64: no data after stripping prefix');
|
|
49
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64Data)) throw new Error('Invalid image base64: contains invalid characters');
|
|
50
|
+
if (base64Data.length < 4) throw new Error(`Invalid image base64: data too short (${base64Data.length} characters)`);
|
|
51
|
+
try {
|
|
52
|
+
const { PhotonImage } = await external_get_photon_js_default()();
|
|
53
|
+
const result = PhotonImage.new_from_base64(base64Data);
|
|
54
|
+
const image = result instanceof Promise ? await result : result;
|
|
55
|
+
const width = image.get_width();
|
|
56
|
+
const height = image.get_height();
|
|
57
|
+
image.free();
|
|
58
|
+
external_node_assert_default()(width && height, 'Invalid image: cannot get width or height');
|
|
59
|
+
return {
|
|
60
|
+
width,
|
|
61
|
+
height
|
|
62
|
+
};
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof Error && error.message.includes('unreachable')) throw new Error(`Failed to decode image: invalid or corrupted image data. Original error: ${error.message}`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
function isValidPNGImageBuffer(buffer) {
|
|
60
69
|
if (!buffer || buffer.length < 8) return false;
|
|
@@ -38,12 +38,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
38
38
|
BaseMCPServer: ()=>BaseMCPServer
|
|
39
39
|
});
|
|
40
40
|
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
41
|
-
const external_utils_js_namespaceObject = require("../utils.js");
|
|
42
41
|
const mcp_js_namespaceObject = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
43
42
|
const stdio_js_namespaceObject = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
44
43
|
const streamableHttp_js_namespaceObject = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
45
44
|
const external_express_namespaceObject = require("express");
|
|
46
45
|
var external_express_default = /*#__PURE__*/ __webpack_require__.n(external_express_namespaceObject);
|
|
46
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
47
47
|
function _define_property(obj, key, value) {
|
|
48
48
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
49
49
|
value: value,
|
|
@@ -27,8 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
generateToolsFromActionSpace: ()=>generateToolsFromActionSpace,
|
|
28
28
|
generateCommonTools: ()=>generateCommonTools
|
|
29
29
|
});
|
|
30
|
-
const index_js_namespaceObject = require("../img/index.js");
|
|
31
30
|
const external_zod_namespaceObject = require("zod");
|
|
31
|
+
const index_js_namespaceObject = require("../img/index.js");
|
|
32
32
|
const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
|
|
33
33
|
function getErrorMessage(error) {
|
|
34
34
|
return error instanceof Error ? error.message : String(error);
|
package/package.json
CHANGED
package/src/img/info.ts
CHANGED
|
@@ -14,16 +14,52 @@ export interface ImageInfo extends Size {}
|
|
|
14
14
|
export async function imageInfoOfBase64(
|
|
15
15
|
imageBase64: string,
|
|
16
16
|
): Promise<ImageInfo> {
|
|
17
|
-
|
|
17
|
+
// Validate input before passing to Photon
|
|
18
|
+
if (!imageBase64 || typeof imageBase64 !== 'string') {
|
|
19
|
+
throw new Error('Invalid image base64: data is empty or not a string');
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, '');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
// Check if base64 data is valid after stripping data URL prefix
|
|
25
|
+
if (!base64Data || base64Data.length === 0) {
|
|
26
|
+
throw new Error('Invalid image base64: no data after stripping prefix');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Basic validation: base64 should only contain valid characters
|
|
30
|
+
// (A-Z, a-z, 0-9, +, /, and = for padding)
|
|
31
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64Data)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Invalid image base64: contains invalid characters',
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Check minimum length for a valid image (at least a few bytes)
|
|
38
|
+
if (base64Data.length < 4) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Invalid image base64: data too short (${base64Data.length} characters)`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const { PhotonImage } = await getPhoton();
|
|
46
|
+
// Support both sync (Photon) and async (Canvas fallback) versions
|
|
47
|
+
const result = PhotonImage.new_from_base64(base64Data);
|
|
48
|
+
const image = result instanceof Promise ? await result : result;
|
|
49
|
+
const width = image.get_width();
|
|
50
|
+
const height = image.get_height();
|
|
51
|
+
image.free();
|
|
52
|
+
assert(width && height, 'Invalid image: cannot get width or height');
|
|
53
|
+
return { width, height };
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// Provide more helpful error message for Photon failures
|
|
56
|
+
if (error instanceof Error && error.message.includes('unreachable')) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Failed to decode image: invalid or corrupted image data. Original error: ${error.message}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
27
63
|
}
|
|
28
64
|
|
|
29
65
|
/**
|
package/src/mcp/base-server.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import type { ParseArgsConfig } from 'node:util';
|
|
3
|
-
import { setIsMcp } from '../utils';
|
|
4
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
5
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
@@ -9,6 +8,7 @@ import express, {
|
|
|
9
8
|
type Request,
|
|
10
9
|
type Response,
|
|
11
10
|
} from 'express';
|
|
11
|
+
import { setIsMcp } from '../utils';
|
|
12
12
|
import type { IMidsceneTools } from './types';
|
|
13
13
|
|
|
14
14
|
export interface BaseMCPServerConfig {
|
package/src/mcp/base-tools.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
1
2
|
import { parseBase64 } from '../img';
|
|
2
3
|
import { getDebug } from '../logger';
|
|
3
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
4
|
import {
|
|
5
5
|
generateCommonTools,
|
|
6
6
|
generateToolsFromActionSpace,
|