import type { HostedToolResult } from "smoltalk"; import type { DecisionLog, EventEnvelope } from "./wireTypes.js"; /** Thin accessor layer over the wire format. Every place that reads * `ev.data.foo` directly is a leak of the wire format into consumer * code; if the runtime renames `usage.inputTokens` → `usage.promptTokens` * tomorrow (provider libraries do this constantly), we don't want to * chase the rename through every helper. Confine wire-format * knowledge to this one module. * * Rule for `lib/eval/`: no helper reads `ev.data.foo` directly — add * an accessor here first, then use it. Enforce in code review. */ /** Group events by their `data.type`. One pass; produces a plain * object (per AGENTS.md: prefer objects over Maps). */ export declare function groupByType(events: EventEnvelope[]): Record; /** Convenience: filter to one event type. Prefer `groupByType` when * you need multiple types in one pass. */ export declare function byType(events: EventEnvelope[], type: string): EventEnvelope[]; /** Epoch milliseconds for an event's timestamp. */ export declare function timestampMs(ev: EventEnvelope): number; /** Thread id stamped on a promptCompletion / toolCall / toolCallStart * by Task 0. Null for legacy traces (pre-prereq). */ export declare function threadIdOf(ev: EventEnvelope): string | null; export declare function threadIdentityOf(event: EventEnvelope): string | null; export declare function threadLabelOf(event: EventEnvelope): string | null; /** The usage kind on a promptStart / promptCompletion: "completion" for a * text model, "decision" for a decision model. Null on logs from before * the field was recorded. */ export declare function usageKindOf(ev: EventEnvelope): string | null; /** The decision a promptCompletion records, when its call went to a * decision model. Undefined on a text call, on older logs, and on a * record whose parts do not have the shape a reader uses: a log can be * cut off mid-write or come from another version, and a viewer must * degrade, not throw. */ export declare function decisionOf(ev: EventEnvelope): DecisionLog | undefined; /** Tool name on a toolCall / toolCallStart. */ export declare function toolNameOf(ev: EventEnvelope): string; /** Whether the event records token usage, including a recorded zero. */ export declare function hasTokenUsage(ev: EventEnvelope): boolean; /** Fresh input tokens: what the model was sent that did not come from * the prompt cache. See `contextTokens` for the full input. */ export declare function tokensIn(ev: EventEnvelope): number; export declare function tokensOut(ev: EventEnvelope): number; /** Input tokens served from the provider's prompt cache. They are absent * from `inputTokens`, and they still occupy the context window. */ export declare function tokensCached(ev: EventEnvelope): number; /** Input tokens written to the prompt cache on this call. The model read * them fresh, so screens count them with `tokensIn`. */ export declare function tokensCacheWrite(ev: EventEnvelope): number; /** Everything the model was sent: fresh, cached and cache-write input. * This is the number to compare against a context window. */ export declare function contextTokens(ev: EventEnvelope): number; /** USD cost on a promptCompletion. Reads `cost.totalCost` (TokenCost * shape from lib/statelogClient.ts). */ export declare function cost(ev: EventEnvelope): number; /** Model name on a promptCompletion. Strips wrapping quotes — call * sites in `lib/runtime/prompt.ts` pass `JSON.stringify(modelName)`, * which surrounds the string with quotes. */ export declare function modelOf(ev: EventEnvelope): string; /** The company that ran the model on a promptCompletion, when the call * went through a router such as OpenRouter. */ export declare function servedByOf(ev: EventEnvelope): string | undefined; /** The model's unsigned reasoning text on a promptCompletion. */ export declare function reasoningOf(ev: EventEnvelope): string | undefined; /** The tools the provider ran during a promptCompletion, such as OpenAI's * or Anthropic's built-in web search. An entry without a tool name is * dropped. */ export declare function hostedToolResultsOf(ev: EventEnvelope): HostedToolResult[]; /** Tools array advertised to the LLM on a promptCompletion. */ export declare function toolsOf(ev: EventEnvelope): string[]; /** Last user-role message content from a promptCompletion's * `data.messages` array. Returns null if no user message exists. * The "user message" is appended to the message thread after any * system prompt(s), so the LAST user-role entry in the first-turn * messages is the prompt the user just typed. */ export declare function userMessageOf(promptCompletion: EventEnvelope): string | null; /** Assistant's reply text on a promptCompletion. Returns null when * the completion is empty or absent. */ export declare function completionOf(promptCompletion: EventEnvelope): string | null; export type ToolCallRequest = { id?: string; name?: string; arguments?: unknown; }; export type WireMessage = { role: string; content: unknown; name?: string; toolCalls?: ToolCallRequest[]; toolCallId?: string; }; /** The complete message list sent with a completion. */ export declare function messagesOf(event: EventEnvelope): unknown[]; export declare function normalizeMessage(value: unknown): WireMessage; /** Display text only; message equality must compare the full content. */ export declare function contentText(content: unknown): string; /** Full model message represented by a recorded completion, including requests. */ export declare function completionMessageOf(event: EventEnvelope): WireMessage | undefined; /** The uncapped reply value produced by one successful tool call. A later * exact message comparison still checks caps, attachments and formatting. */ export declare function toolReplyContent(event: EventEnvelope): unknown;