@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
35 lines • 1.54 kB
JavaScript
/**
* A fully in-memory {@link AgentPricingStore} for unit tests and the offline demo. Keyed by
* `modelId`, so an `upsert` supersedes the model's prior price (the same "one current row per model"
* invariant the SQL adapter enforces). Omit a model to leave it unpriced — the loop then reports
* `costUsd: null` for it (never a fabricated `0`).
*/
export class InMemoryPricingStore {
prices = new Map();
async upsertModelPrice(input) {
// A new current row, like the SQL adapter's supersede: written (and last changed) now.
const now = new Date();
this.prices.set(input.modelId, {
modelId: input.modelId,
inputPricePer1m: input.inputPricePer1m,
outputPricePer1m: input.outputPricePer1m,
effectiveFrom: now.toISOString(),
createdAt: new Date(now),
updatedAt: new Date(now),
...(input.cacheWritePricePer1m !== undefined
? { cacheWritePricePer1m: input.cacheWritePricePer1m }
: {}),
...(input.cacheReadPricePer1m !== undefined
? { cacheReadPricePer1m: input.cacheReadPricePer1m }
: {}),
});
}
async listCurrentPrices() {
return [...this.prices.values()].map((price) => ({
...price,
...(price.createdAt ? { createdAt: new Date(price.createdAt) } : {}),
...(price.updatedAt ? { updatedAt: new Date(price.updatedAt) } : {}),
}));
}
}
//# sourceMappingURL=in-memory-pricing.js.map