@sema-agent/core
Version:
Stateless, task-oriented AI agent core
17 lines (16 loc) • 455 B
JavaScript
const SLOT = /\{\{(\w+)\}\}/g;
export function slotNames(text) {
return [...text.matchAll(SLOT)].map((m) => m[1]);
}
export function fillSlots(text, valueOf) {
const missing = [];
const filled = text.replace(SLOT, (whole, name) => {
const value = valueOf(name);
if (value === undefined) {
missing.push(name);
return whole;
}
return value;
});
return { text: filled, missing };
}