cerevox
Version:
TypeScript SDK for browser automation and secure command execution in highly available and scalable micro computer environments
83 lines • 3.26 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.compilePrompt = void 0;
const nunjucks = __importStar(require("nunjucks"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
/**
* 使用 nunjucks 编译 scisnap.prompt.tpl 模板
*
* @param options - 编译选项,包含 width 和 height 参数
* @returns 编译后的 prompt 对象,格式为 {role: 'system', content: prompt}
*
* @example
* ```typescript
* const prompt = compilePrompt({ width: 800, height: 600 });
* console.log(prompt.role); // 'system'
* console.log(prompt.content); // 编译后的模板内容
* ```
*/
const compilePrompt = (options) => {
try {
// 获取模板文件路径
const templatePath = path.join(__dirname, '../mcp/servers/prompts/scisnap.tpl.md');
// 检查模板文件是否存在
if (!fs.existsSync(templatePath)) {
throw new Error(`Template file not found: ${templatePath}`);
}
// 读取模板文件内容
const templateContent = fs.readFileSync(templatePath, 'utf-8');
// 配置 nunjucks 环境
const env = new nunjucks.Environment();
// 编译模板
const compiledContent = env.renderString(templateContent, {
width: options.width,
height: options.height,
duration: options.duration,
});
console.log(`[INFO] Prompt template compiled successfully: ${options.width}x${options.height}, length: ${compiledContent.length}`);
return {
role: 'system',
content: compiledContent,
};
}
catch (error) {
console.error('[ERROR] Failed to compile prompt template:', error);
throw new Error(`Prompt compilation failed: ${error}`);
}
};
exports.compilePrompt = compilePrompt;
//# sourceMappingURL=promot-tools.js.map