@midscene/shared 1.10.6-beta-20260717061640.0 → 1.10.6
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.
|
@@ -5,7 +5,7 @@ import { assert } from "../utils.mjs";
|
|
|
5
5
|
import { maskConfig, parseJson } from "./helper.mjs";
|
|
6
6
|
import { initDebugConfig } from "./init-debug.mjs";
|
|
7
7
|
const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
|
|
8
|
-
const getCurrentVersion = ()=>"1.10.6
|
|
8
|
+
const getCurrentVersion = ()=>"1.10.6";
|
|
9
9
|
const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
|
|
10
10
|
const KEYS_MAP = {
|
|
11
11
|
insight: INSIGHT_MODEL_CONFIG_KEYS,
|
package/dist/es/img/info.mjs
CHANGED
|
@@ -45,9 +45,24 @@ async function imageInfoOfBase64(imageBase64) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function isValidPNGImageBuffer(buffer) {
|
|
48
|
-
if (!buffer || buffer.length <
|
|
48
|
+
if (!buffer || buffer.length < 20) return false;
|
|
49
49
|
const isPNG = 0x89 === buffer[0] && 0x50 === buffer[1] && 0x4e === buffer[2] && 0x47 === buffer[3] && 0x0d === buffer[4] && 0x0a === buffer[5] && 0x1a === buffer[6] && 0x0a === buffer[7];
|
|
50
|
-
return
|
|
50
|
+
if (!isPNG) return false;
|
|
51
|
+
const pngIendChunk = Buffer.from([
|
|
52
|
+
0x00,
|
|
53
|
+
0x00,
|
|
54
|
+
0x00,
|
|
55
|
+
0x00,
|
|
56
|
+
0x49,
|
|
57
|
+
0x45,
|
|
58
|
+
0x4e,
|
|
59
|
+
0x44,
|
|
60
|
+
0xae,
|
|
61
|
+
0x42,
|
|
62
|
+
0x60,
|
|
63
|
+
0x82
|
|
64
|
+
]);
|
|
65
|
+
return buffer.subarray(buffer.length - pngIendChunk.length).equals(pngIendChunk);
|
|
51
66
|
}
|
|
52
67
|
function isValidJPEGImageBuffer(buffer) {
|
|
53
68
|
if (!buffer || buffer.length < 3) return false;
|
|
@@ -37,7 +37,7 @@ const external_utils_js_namespaceObject = require("../utils.js");
|
|
|
37
37
|
const external_helper_js_namespaceObject = require("./helper.js");
|
|
38
38
|
const external_init_debug_js_namespaceObject = require("./init-debug.js");
|
|
39
39
|
const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
|
|
40
|
-
const getCurrentVersion = ()=>"1.10.6
|
|
40
|
+
const getCurrentVersion = ()=>"1.10.6";
|
|
41
41
|
const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${external_types_js_namespaceObject.MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
|
|
42
42
|
const KEYS_MAP = {
|
|
43
43
|
insight: external_constants_js_namespaceObject.INSIGHT_MODEL_CONFIG_KEYS,
|
package/dist/lib/img/info.js
CHANGED
|
@@ -89,9 +89,24 @@ async function imageInfoOfBase64(imageBase64) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
function isValidPNGImageBuffer(buffer) {
|
|
92
|
-
if (!buffer || buffer.length <
|
|
92
|
+
if (!buffer || buffer.length < 20) return false;
|
|
93
93
|
const isPNG = 0x89 === buffer[0] && 0x50 === buffer[1] && 0x4e === buffer[2] && 0x47 === buffer[3] && 0x0d === buffer[4] && 0x0a === buffer[5] && 0x1a === buffer[6] && 0x0a === buffer[7];
|
|
94
|
-
return
|
|
94
|
+
if (!isPNG) return false;
|
|
95
|
+
const pngIendChunk = external_node_buffer_namespaceObject.Buffer.from([
|
|
96
|
+
0x00,
|
|
97
|
+
0x00,
|
|
98
|
+
0x00,
|
|
99
|
+
0x00,
|
|
100
|
+
0x49,
|
|
101
|
+
0x45,
|
|
102
|
+
0x4e,
|
|
103
|
+
0x44,
|
|
104
|
+
0xae,
|
|
105
|
+
0x42,
|
|
106
|
+
0x60,
|
|
107
|
+
0x82
|
|
108
|
+
]);
|
|
109
|
+
return buffer.subarray(buffer.length - pngIendChunk.length).equals(pngIendChunk);
|
|
95
110
|
}
|
|
96
111
|
function isValidJPEGImageBuffer(buffer) {
|
|
97
112
|
if (!buffer || buffer.length < 3) return false;
|
package/package.json
CHANGED
package/src/img/info.ts
CHANGED
|
@@ -70,7 +70,10 @@ export async function imageInfoOfBase64(
|
|
|
70
70
|
* @returns true if the Buffer is a valid PNG image, otherwise false
|
|
71
71
|
*/
|
|
72
72
|
export function isValidPNGImageBuffer(buffer: Buffer): boolean {
|
|
73
|
-
|
|
73
|
+
// A PNG consists of the 8-byte signature followed by chunks and must end
|
|
74
|
+
// with the 12-byte IEND chunk. Checking only the signature lets truncated
|
|
75
|
+
// screenshots through, which then fail when sent to an image model.
|
|
76
|
+
if (!buffer || buffer.length < 20) {
|
|
74
77
|
return false;
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -86,7 +89,18 @@ export function isValidPNGImageBuffer(buffer: Buffer): boolean {
|
|
|
86
89
|
buffer[6] === 0x1a &&
|
|
87
90
|
buffer[7] === 0x0a;
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
if (!isPNG) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// IEND has a zero-length payload and a fixed CRC (AE 42 60 82). It must be
|
|
97
|
+
// the final chunk in a conforming PNG.
|
|
98
|
+
const pngIendChunk = Buffer.from([
|
|
99
|
+
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
|
100
|
+
]);
|
|
101
|
+
return buffer
|
|
102
|
+
.subarray(buffer.length - pngIendChunk.length)
|
|
103
|
+
.equals(pngIendChunk);
|
|
90
104
|
}
|
|
91
105
|
|
|
92
106
|
/**
|