@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
44 lines • 1.72 kB
JavaScript
import { snapshotActionProposal } from './action-proposal-transitions.js';
function snapshot(value) {
if (!value ||
typeof value.component !== 'string' ||
!/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(value.component) ||
!Number.isSafeInteger(value.version) ||
value.version < 1 ||
typeof value.fallbackText !== 'string' ||
typeof value.props !== 'object' ||
value.props === null ||
Array.isArray(value.props))
throw new TypeError('Invalid tool component presentation');
return snapshotActionProposal(value);
}
/** Presentation must never turn a completed domain write into a retryable tool failure. */
export async function presentToolResult(toolName, handler, output, ctx) {
if (handler.present === undefined)
return;
try {
const result = await handler.present(output, ctx);
if (result === undefined)
return;
const presentations = (Array.isArray(result) ? result : [result]).map(snapshot);
for (const item of presentations) {
await ctx.emitUi(item.component, item.props, {
version: item.version,
fallbackText: item.fallbackText,
});
}
}
catch (error) {
try {
if (ctx.onPresentationError !== undefined) {
await ctx.onPresentationError(error, { toolName });
return;
}
}
catch {
// A broken reporter must not cause the successful action to run again either.
}
console.warn('[agent] Tool presentation failed after successful execution', { toolName });
}
}
//# sourceMappingURL=tool-result-presentation.js.map