@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
20 lines • 853 B
JavaScript
/**
* Wraps the turn's stream writer to note when the first `text` frame goes out: the time to first
* token as the reader sees it (a frame an output gate held back counts when it was released). The
* clock is this process's, so a run resumed elsewhere measures from its resume.
*/
export function observeFirstText(writer, now = Date.now) {
let firstTextAt;
const wrapped = Object.create(writer);
wrapped.write = (frame) => {
if (firstTextAt === undefined && frame.t === 'text' && frame.v.length > 0)
firstTextAt = now();
return writer.write(frame);
};
wrapped.end = () => writer.end();
if (typeof writer.flush === 'function') {
wrapped.flush = () => writer.flush.call(writer);
}
return { writer: wrapped, firstTextAt: () => firstTextAt };
}
//# sourceMappingURL=turn-timing.js.map