UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

48 lines (47 loc) • 2.75 kB
import type { AssistantMessageDiagnostic, Model, Usage } from "../../internal/llm.js"; import { type ServedReading } from "../../brain/model-lane.js"; import { type ModelPricing } from "../pricing.js"; import type { RunnerDeps } from "../types.js"; /** One model call as the account bills it: the model it is priced at, the usage it reported, and whether that usage is a lower * bound (`usageMissing`). */ export interface Bill { readonly model: Model; readonly usage: Usage; readonly usageMissing?: true; } /** * THE bills of one answer to a request for `requested`: every request it left behind on its way, then the answer itself — each at * the model that made it ({@link servedReadingOf}: ids resolved along the requested model's own chain, never looked up by word). * An answer that lists nothing left behind is one bill, at the model that answered. `usage` absent ⇒ no bill for the answer * (the caller marks the lower bound). */ export declare function billsOf(requested: Model, msg: { readonly usage?: Usage; readonly usageMissing?: true; readonly diagnostics?: AssistantMessageDiagnostic[]; } | undefined): { readonly reading: ServedReading; readonly bills: readonly Bill[]; }; /** One bill priced by the engine: its model's price table, whether a table exists at all, and the re-priced figures. */ export interface PricedReply { readonly served: Model; readonly modelId: string; readonly price: ModelPricing; /** The call has a cost figure (`callPriced`): a price table EXISTS for the model (`priceTableOf`) and declares the tier that served * the call (`callRatesOf`), or the call billed nothing. `false` ⇒ `costMicroUsd` is a fabricated 0, or the standard rates' lower * bound for a fast-served call — unknown, not free. */ readonly priced: boolean; /** A price table exists for the model (`false` ⇒ unpriced whatever the speed; `true` with `priced: false` ⇒ fast, no fast tier). */ readonly tableExists: boolean; readonly totalInputTokens: number; readonly uncachedInputTokens: number; readonly costMicroUsd: number; } /** * THE one pricing of a model call made BESIDE the main loop — the run's side-call lanes (`recordSideCallUsage`) and * `Runner.sideQuery`'s account line both read it, so a run's reported cost and a side query's cost are the same arithmetic: the * deployment's table for the model's id, else the model's own `cost` (`priceTableOf`), at the tier that served the call, with * the model's cache family. The call's model prices independently of the main loop's telemetry state. */ export declare function priceReply(usage: Usage, model: Model, pricing: RunnerDeps["pricing"], usageMissing: boolean): PricedReply;