UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

47 lines • 1.75 kB
function asReceipt(output) { if (typeof output !== 'object' || output === null) { return null; } const candidate = output; if (candidate.detached !== true || candidate.status !== 'started' || typeof candidate.agent !== 'string' || typeof candidate.runId !== 'string') { return null; } return { detached: true, status: 'started', agent: candidate.agent, runId: candidate.runId }; } /** * Every sub-agent this thread started in the background, and whether each has reported back. * * Derived from the transcript rather than tracked in session state, so it survives a reload and a * second tab: the receipt is a persisted tool result, and the answer is a persisted message stamped * with the run that wrote it. Nothing here needs a live connection to be true. */ export function backgroundRunsFromThread(messages) { const byRun = new Map(); for (const message of messages) { for (const result of message.toolResults ?? []) { const receipt = asReceipt(result.output); if (receipt === null || byRun.has(receipt.runId)) { continue; } byRun.set(receipt.runId, { runId: receipt.runId, agent: receipt.agent, toolCallId: result.id, toolName: result.name, status: 'running', }); } } for (const message of messages) { const run = message.runId === undefined ? undefined : byRun.get(message.runId); if (run !== undefined) { run.status = 'delivered'; run.message = message; } } return [...byRun.values()]; } //# sourceMappingURL=background-runs.js.map