@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
60 lines • 2.93 kB
TypeScript
import type { CostSource } from '../spi/agent-store.js';
import { type AgentPricingStore, type ModelPriceInput } from '../spi/pricing-store.js';
import type { MessageUsage } from '../types.js';
import { type BootPricingLog, type PriceCatalogOptions } from './boot-pricing.js';
/**
* The cost a usage row persists: the provider's figure (`'provider'`), else the estimate off the
* model's price row (`'estimate'`), else nothing (`cost_usd` NULL). The one rule every engine
* records usage by, so the ledger, a USD quota and the message carry the same figure.
*/
export declare function resolveUsageCost(usage: MessageUsage, reportedCostUsd: number | undefined, price: ModelPriceInput | undefined): {
costUsd?: number;
costSource?: CostSource;
};
/** A model to price, as an engine knows it. */
export interface PricedModelRef {
/** The id usage is recorded under. */
modelId: string;
/** Its provider family (`amazon-bedrock`, `openai`, `openrouter`, …), when known. */
provider?: string;
/**
* Other ids the same model is known by, tried after `modelId` (e.g. the bare model id of a
* `provider/model` label, or the Bedrock id behind a gateway's alias).
*/
aliases?: readonly string[];
}
export interface ModelPriceResolverOptions {
/** The configured pricing store (`pricingStore`). Omit → prices resolve in memory only. */
pricingStore?: AgentPricingStore | undefined;
/** `priceCatalog` in `config/agent.ts`; `false` → no app prices, never fetch models.dev. */
catalog?: PriceCatalogOptions | false | undefined;
log?: BootPricingLog;
/** How long the store's current prices are reused before they are read again. Default 60s. */
cacheMs?: number;
}
/**
* The price of a model an engine only learns about at run time (OpenCode reports the model each step
* ran on), resolved the way boot pricing does it for configured models:
*
* 1. the pricing store's current row (by the id, then its normalized Bedrock candidates);
* 2. once per model and process, the boot seed (`ensureModelPricing`): the app's
* `priceCatalog.prices`, then the built-in GovCloud Bedrock table, then models.dev — written to
* the store as a row, so the dashboard and a later run read the same price;
* 3. without a pricing store, the same three sources, kept in memory.
*
* Never throws: pricing is bookkeeping, and an unpriced step is recorded without a cost.
*/
export declare class ModelPriceResolver {
private readonly options;
private rows;
private rowsAt;
private readonly seeded;
constructor(options?: ModelPriceResolverOptions);
priceFor(model: PricedModelRef): Promise<ModelPriceInput | undefined>;
private catalog;
private currentRows;
private seed;
/** No pricing store: the app's prices, the built-in Bedrock table, then models.dev. */
private inMemory;
}
//# sourceMappingURL=resolve.d.ts.map