@sema-agent/core
Version:
Stateless, task-oriented AI agent core
39 lines (38 loc) • 3.26 kB
TypeScript
/**
* How many of a reply's output tokens the provider spent reasoning, read ONE way for every reader of a provider's usage in
* this tree: the three wire adapters and the failover lane's copy of a message's usage.
*
* `Usage.reasoning` is a SUBSET of `Usage.output`: it is never added to the totals and never priced (output already counts it).
* It is also absent, not zero, when the provider said nothing — a measured zero and "not reported" are different statements.
*
* The wire spellings stay each adapter's own (the member is read where its provider names it, in the shape judge that
* adapter already uses); what lives here is the part that must be the same everywhere:
* - priority — the first spelling that stated anything is the provider's statement, later ones are not consulted. A spelling that
* stated something in no count shape (a string, an object, `null` here, a container that could not hold it) STATES: it is the
* statement, and it is unreadable — it is never skipped for the next spelling's count, so the gates hand a statement on as it
* came and only an ABSENT spelling is `undefined`;
* - the count's own law — a whole number from zero that a number states exactly (no more than 2^53 - 1: past it the wire's
* digits were rounded on the way in, so the value read is not the value sent, and "equal to the output" proves nothing);
* - the subset law — a count larger than the output it is a part of cannot be that part.
* A count that breaks either law is not clamped (that would book a number the provider never said) and not kept (the usage
* would contradict itself): the member is left absent and the reading says `unreadable`, which each caller turns into the
* usage-unknown mark it already uses for a usage member in no shape.
*/
/** The reading of one usage's reasoning count. */
export interface ReasoningReading {
/** The count to record: set only when a spelling carried a count that is exact and fits within the output. */
readonly reasoning?: number;
/** A spelling carried a count that cannot be recorded: not an exact whole number from zero, or larger than the output it is a part of. */
readonly unreadable: boolean;
}
/** A whole number from zero that a number states exactly: the one count law of every token member a usage reading records. */
export declare const isExactCount: (v: unknown) => v is number;
/**
* @param output the usage's output count (an absent output reads as 0 — a reasoning count with no output beside it is unreadable)
* @param spellings what the provider's spellings carried, highest priority first; `undefined` = that spelling absent (a wire gate
* reads an absent member and a `null` as `undefined` and hands every other value on as it came). Anything
* but an exact count (a string, `null`, an object, a fraction, a negative, a number past 2^53 - 1) is unreadable: the count's own
* law is judged here whatever shape judge the caller ran first, so a caller whose reader is looser (the wire readers accept any
* whole number) or has none (the lane copy) is held to the same law.
*/
export declare function reasoningTokensOf(output: number | undefined, ...spellings: readonly unknown[]): ReasoningReading;