dist / preprocess.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.preprocess = void 0;
exports.parseImageCommands = parseImageCommands;
const images_1 = require("./images");
const node_path_1 = require("node:path");
function parseImageCommands(text) {
const paths = [];
const lines = [];
for (const line of text.split(/\r?\n/)) {
if (!/^@strata-image(?:\s|$)/.test(line)) {
lines.push(line);
continue;
}
const match = /^@strata-image\s+"([^"]+)"\s*$/.exec(line);
if (!match || !(0, node_path_1.isAbsolute)(match[1]))
throw new Error('Use @strata-image "C:\\absolute\\path.png" on its own line.');
paths.push(match[1]);
}
return { text: lines.join("\n").trim(), paths };
}
// An explicit file command provides an alternative when LM Studio disables image upload
// for generator plugins. The prepared attachment is retained in the conversation.
const preprocess = async (ctl, original) => {
if (!original.isUserMessage())
return original;
const parsed = parseImageCommands(original.getText());
if (!parsed.paths.length)
return original;
const message = original.asMutableCopy();
let total = 0;
for (const path of parsed.paths) {
const bytes = await (0, images_1.readImage)(path, ctl.abortSignal);
total += bytes.length;
if (total > images_1.TOTAL_IMAGE_LIMIT)
throw new Error("Image commands exceed 64 MiB.");
message.appendFile(await ctl.client.files.prepareImageBase64((0, node_path_1.basename)(path), bytes.toString("base64")));
}
message.replaceText(parsed.text || "Describe the attached images.");
return message;
};
exports.preprocess = preprocess;
dist / preprocess.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.preprocess = void 0;
exports.parseImageCommands = parseImageCommands;
const images_1 = require("./images");
const node_path_1 = require("node:path");
function parseImageCommands(text) {
const paths = [];
const lines = [];
for (const line of text.split(/\r?\n/)) {
if (!/^@strata-image(?:\s|$)/.test(line)) {
lines.push(line);
continue;
}
const match = /^@strata-image\s+"([^"]+)"\s*$/.exec(line);
if (!match || !(0, node_path_1.isAbsolute)(match[1]))
throw new Error('Use @strata-image "C:\\absolute\\path.png" on its own line.');
paths.push(match[1]);
}
return { text: lines.join("\n").trim(), paths };
}
// An explicit file command provides an alternative when LM Studio disables image upload
// for generator plugins. The prepared attachment is retained in the conversation.
const preprocess = async (ctl, original) => {
if (!original.isUserMessage())
return original;
const parsed = parseImageCommands(original.getText());
if (!parsed.paths.length)
return original;
const message = original.asMutableCopy();
let total = 0;
for (const path of parsed.paths) {
const bytes = await (0, images_1.readImage)(path, ctl.abortSignal);
total += bytes.length;
if (total > images_1.TOTAL_IMAGE_LIMIT)
throw new Error("Image commands exceed 64 MiB.");
message.appendFile(await ctl.client.files.prepareImageBase64((0, node_path_1.basename)(path), bytes.toString("base64")));
}
message.replaceText(parsed.text || "Describe the attached images.");
return message;
};
exports.preprocess = preprocess;