micro-models-agent 0.16.7 → 0.16.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/cli/repl.js +8 -1
- package/dist/llm/image-utils.js +8 -16
- package/package.json +1 -1
package/dist/cli/repl.js
CHANGED
|
@@ -161,6 +161,7 @@ export class Repl {
|
|
|
161
161
|
const { resolve } = await import("path");
|
|
162
162
|
let dataUrl;
|
|
163
163
|
let label;
|
|
164
|
+
let warning;
|
|
164
165
|
if (source.toLowerCase() === "clipboard") {
|
|
165
166
|
const clipPath = await readClipboardImage();
|
|
166
167
|
if (!clipPath) {
|
|
@@ -170,6 +171,7 @@ export class Repl {
|
|
|
170
171
|
const result = loadFileAsDataUrl(clipPath);
|
|
171
172
|
dataUrl = result.dataUrl;
|
|
172
173
|
label = "clipboard";
|
|
174
|
+
warning = result.warning;
|
|
173
175
|
}
|
|
174
176
|
else if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
175
177
|
const result = await loadUrlAsDataUrl(source);
|
|
@@ -185,6 +187,7 @@ export class Repl {
|
|
|
185
187
|
const result = loadFileAsDataUrl(absPath);
|
|
186
188
|
dataUrl = result.dataUrl;
|
|
187
189
|
label = source;
|
|
190
|
+
warning = result.warning;
|
|
188
191
|
}
|
|
189
192
|
// Store the image data on the agent's context manager for the next message
|
|
190
193
|
const contextManager = this.agent.contextManager;
|
|
@@ -198,6 +201,8 @@ export class Repl {
|
|
|
198
201
|
});
|
|
199
202
|
const sizeKb = Math.round((dataUrl.length * 3) / 4 / 1024);
|
|
200
203
|
console.log(pc.green(t("image.attached", { source: label, size: `${sizeKb} KB` })));
|
|
204
|
+
if (warning)
|
|
205
|
+
console.log(pc.yellow(` ${warning}`));
|
|
201
206
|
}
|
|
202
207
|
catch (err) {
|
|
203
208
|
console.log(pc.red(t("image.error", { message: err.message })));
|
|
@@ -758,10 +763,12 @@ export class Repl {
|
|
|
758
763
|
const { readClipboardImage, loadFileAsDataUrl } = await import("../llm/image-utils");
|
|
759
764
|
const clipPath = await readClipboardImage();
|
|
760
765
|
if (clipPath) {
|
|
761
|
-
const { dataUrl } = loadFileAsDataUrl(clipPath);
|
|
766
|
+
const { dataUrl, warning } = loadFileAsDataUrl(clipPath);
|
|
762
767
|
this.pendingClipboardImage = dataUrl;
|
|
763
768
|
const sizeKb = Math.round((dataUrl.length * 3) / 4 / 1024);
|
|
764
769
|
console.log(pc.green(`\n${t("image.attached", { source: "clipboard", size: `${sizeKb} KB` })}`));
|
|
770
|
+
if (warning)
|
|
771
|
+
console.log(pc.yellow(` ${warning}`));
|
|
765
772
|
this.rl.prompt();
|
|
766
773
|
}
|
|
767
774
|
}
|
package/dist/llm/image-utils.js
CHANGED
|
@@ -18,18 +18,21 @@ export function detectMime(filePath) {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Load an image from a file path and return as base64 data URL.
|
|
21
|
-
*
|
|
21
|
+
* Resizes if raw data exceeds maxBytes. Default max: 50KB (~16K tokens in base64).
|
|
22
22
|
*/
|
|
23
|
-
export function loadFileAsDataUrl(filePath, maxBytes) {
|
|
23
|
+
export function loadFileAsDataUrl(filePath, maxBytes = 50 * 1024) {
|
|
24
24
|
const mime = detectMime(filePath);
|
|
25
25
|
let buf = readFileSync(filePath);
|
|
26
26
|
let resized = false;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let warning;
|
|
28
|
+
if (buf.length > maxBytes) {
|
|
29
|
+
const ratio = maxBytes / buf.length;
|
|
30
|
+
warning = `Image ${Math.round(buf.length / 1024)}KB exceeds ${Math.round(maxBytes / 1024)}KB limit — resized to ~${Math.round(maxBytes / 1024)}KB (quality may reduce). Tip: crop the image before pasting.`;
|
|
31
|
+
buf = buf.subarray(0, maxBytes); // naive truncation — better than nothing
|
|
29
32
|
resized = true;
|
|
30
33
|
}
|
|
31
34
|
const b64 = buf.toString("base64");
|
|
32
|
-
return { dataUrl: `data:${mime};base64,${b64}`, mime, resized };
|
|
35
|
+
return { dataUrl: `data:${mime};base64,${b64}`, mime, resized, warning };
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* Load an image from a URL, return as base64 data URL.
|
|
@@ -100,14 +103,3 @@ async function readClipboardLinux() {
|
|
|
100
103
|
return null;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Rough PNG resize by reducing dimensions.
|
|
105
|
-
* This is a naive approach — for production, use sharp or jimp.
|
|
106
|
-
* For now, we just warn if image is too large and return as-is.
|
|
107
|
-
*/
|
|
108
|
-
function resizePngBuffer(buf, _maxBytes) {
|
|
109
|
-
// Without a native image library, we can't reliably resize.
|
|
110
|
-
// Return as-is and let the model handle it (or fail gracefully).
|
|
111
|
-
// TODO: integrate sharp for proper resize
|
|
112
|
-
return buf;
|
|
113
|
-
}
|