import { getModelId } from "../../../model-provider.js";
export function createPiUsageAccumulator() {
    return {
        inputTokens: 0,
        outputTokens: 0,
        assistantErrors: [],
    };
}
export function capturePiMessageUsage(accumulator, message) {
    if (message?.errorMessage) {
        accumulator.assistantErrors.push(message.errorMessage);
    }
    if (message?.usage) {
        accumulator.inputTokens += message.usage.input;
        accumulator.outputTokens += message.usage.output;
    }
}
export function buildPiResultMessage(options) {
    const errorText = options.error instanceof Error
        ? options.error.message
        : options.error ? JSON.stringify(options.error) : "";
    const modelId = getModelId(options.config);
    return {
        type: "result",
        subtype: errorText ? "error" : "success",
        num_turns: options.numTurns,
        usage: {
            input_tokens: options.inputTokens,
            output_tokens: options.outputTokens,
        },
        total_cost_usd: 0,
        is_error: Boolean(errorText),
        errors: errorText ? [errorText] : [],
        model: modelId,
        modelUsage: {
            [modelId]: {
                inputTokens: options.inputTokens,
                outputTokens: options.outputTokens,
                cacheReadInputTokens: 0,
                cacheCreationInputTokens: 0,
                contextWindow: options.contextWindow,
            },
        },
    };
}
//# sourceMappingURL=usage.js.map