@blueharford/scrypted-spatial-awareness 0.5.6 → 0.5.8
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/main.nodejs.js +1 -1
- package/dist/main.nodejs.js.map +1 -1
- package/dist/plugin.zip +0 -0
- package/out/main.nodejs.js +49 -51
- package/out/main.nodejs.js.map +1 -1
- package/out/plugin.zip +0 -0
- package/package.json +1 -1
- package/src/core/spatial-reasoning.ts +43 -18
package/out/plugin.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -84,40 +84,65 @@ export interface ImageData {
|
|
|
84
84
|
*/
|
|
85
85
|
export async function mediaObjectToBase64(mediaObject: MediaObject): Promise<ImageData | null> {
|
|
86
86
|
try {
|
|
87
|
-
|
|
87
|
+
const mimeType = mediaObject?.mimeType || 'image/jpeg';
|
|
88
|
+
console.log(`[Image] Converting MediaObject, mimeType=${mimeType}`);
|
|
88
89
|
|
|
89
|
-
//
|
|
90
|
-
|
|
90
|
+
// Use createMediaObject to ensure we have a proper MediaObject with mimeType
|
|
91
|
+
// Then convert to buffer - this should handle the conversion internally
|
|
92
|
+
let buffer: Buffer;
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
try {
|
|
95
|
+
// Try direct conversion with the source mime type
|
|
96
|
+
buffer = await mediaManager.convertMediaObjectToBuffer(mediaObject, mimeType);
|
|
97
|
+
} catch (convErr) {
|
|
98
|
+
console.warn(`[Image] Direct conversion failed, trying with explicit JPEG:`, convErr);
|
|
99
|
+
|
|
100
|
+
// Try creating a new MediaObject with explicit mimeType
|
|
101
|
+
try {
|
|
102
|
+
// Get raw data if available
|
|
103
|
+
const anyMedia = mediaObject as any;
|
|
104
|
+
if (typeof anyMedia.getData === 'function') {
|
|
105
|
+
const rawData = await anyMedia.getData();
|
|
106
|
+
if (rawData && Buffer.isBuffer(rawData) && rawData.length > 1000) {
|
|
107
|
+
console.log(`[Image] Got raw data: ${rawData.length} bytes`);
|
|
108
|
+
buffer = rawData;
|
|
109
|
+
} else {
|
|
110
|
+
console.warn(`[Image] getData returned invalid data`);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
console.warn('[Image] No getData method available');
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
} catch (dataErr) {
|
|
118
|
+
console.warn('[Image] Alternate data fetch failed:', dataErr);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
95
121
|
}
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
// Check if we got an actual Buffer (not a proxy)
|
|
124
|
+
const isRealBuffer = Buffer.isBuffer(buffer);
|
|
125
|
+
const bufferLength = isRealBuffer ? buffer.length : 0;
|
|
126
|
+
|
|
127
|
+
console.log(`[Image] Buffer: isBuffer=${isRealBuffer}, length=${bufferLength}`);
|
|
98
128
|
|
|
99
|
-
if (
|
|
100
|
-
console.warn('[Image]
|
|
129
|
+
if (!isRealBuffer || bufferLength === 0) {
|
|
130
|
+
console.warn('[Image] Did not receive a valid Buffer');
|
|
101
131
|
return null;
|
|
102
132
|
}
|
|
103
133
|
|
|
104
134
|
// Check if buffer is too small to be a valid image (< 1KB is suspicious)
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
const bufferContent = buffer.toString('utf8').substring(0, 100);
|
|
108
|
-
console.warn(`[Image] Buffer too small (${buffer.length} bytes), content: ${bufferContent}`);
|
|
135
|
+
if (bufferLength < 1000) {
|
|
136
|
+
console.warn(`[Image] Buffer too small: ${bufferLength} bytes`);
|
|
109
137
|
return null;
|
|
110
138
|
}
|
|
111
139
|
|
|
112
140
|
// Convert buffer to base64 (raw, no data URL prefix)
|
|
113
141
|
const base64 = buffer.toString('base64');
|
|
114
142
|
|
|
115
|
-
|
|
116
|
-
const mediaType = mediaObject.mimeType?.split(';')[0] || 'image/jpeg';
|
|
117
|
-
|
|
118
|
-
console.log(`[Image] Converted to base64: ${base64.length} chars, type=${mediaType}`);
|
|
143
|
+
console.log(`[Image] Converted to base64: ${base64.length} chars`);
|
|
119
144
|
|
|
120
|
-
return { base64, mediaType };
|
|
145
|
+
return { base64, mediaType: 'image/jpeg' };
|
|
121
146
|
} catch (e) {
|
|
122
147
|
console.warn('[Image] Failed to convert MediaObject to base64:', e);
|
|
123
148
|
return null;
|