@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
32 lines • 1.05 kB
JavaScript
const MAX_SLOTS = 2_000;
/** String leaves of a JSON value (tool arguments, structured results). */
export function jsonSlots(root, source, fresh, replaceRoot) {
const out = [];
const walk = (value, set, depth) => {
if (out.length >= MAX_SLOTS || depth > 10)
return;
if (typeof value === 'string') {
if (value)
out.push({ segment: { text: value, source, fresh }, set });
return;
}
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
walk(value[i], (t) => {
value[i] = t;
}, depth + 1);
}
return;
}
if (value && typeof value === 'object') {
const o = value;
for (const k of Object.keys(o))
walk(o[k], (t) => {
o[k] = t;
}, depth + 1);
}
};
walk(root, replaceRoot ?? (() => undefined), 0);
return out;
}
//# sourceMappingURL=segments.js.map