@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
30 lines • 1.35 kB
JavaScript
/**
* The `actor_ref` usage nobody in particular pays for is recorded under — platform cost: a nightly
* embedding job, a moderation pass over every upload. `actor_ref` stays NOT NULL (every quota and
* spend-by-actor query keys on it), so platform cost is one more actor, spelled so no real one can
* collide with it. It never counts against any actor's quota.
*/
export const PLATFORM_ACTOR_REF = '@platform';
/** {@link UsageTotals} over usage rows: the one summing rule every store shares. */
export function sumUsage(rows) {
let usedTokens = 0;
let costUsd = 0;
let estimatedCostUsd = 0;
for (const row of rows) {
usedTokens += row.inputTokens + row.outputTokens;
const cost = row.costUsd === null || row.costUsd === undefined ? 0 : Number(row.costUsd);
costUsd += cost;
if (row.costSource === 'estimate')
estimatedCostUsd += cost;
}
return { usedTokens, costUsd, estimatedCostUsd };
}
/** Clear `threadId`'s active run if it is still `runId` (see {@link AgentStore.clearActiveStream}). */
export async function clearActiveRun(store, threadId, runId) {
if (store.clearActiveStream !== undefined) {
await store.clearActiveStream(threadId, runId);
return;
}
await store.setActiveStream(threadId, null);
}
//# sourceMappingURL=agent-store.js.map