@hiper2d/ai-agents 0.31.1 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -25,6 +25,7 @@ interface TokenUsage$1 {
25
25
  costUSD: number;
26
26
  reasoningTokens?: number;
27
27
  cachedInputTokens?: number;
28
+ cacheWriteTokens?: number;
28
29
  durationMs?: number;
29
30
  }
30
31
  interface ApiKeyMap {
@@ -1435,19 +1436,25 @@ declare class AgentFactory {
1435
1436
  }
1436
1437
 
1437
1438
  type CacheTtl = '5m' | '1h';
1439
+ /** Prompt-cache setting for a ClaudeAgent: a TTL for every breakpoint, or 'off' for none. */
1440
+ type ClaudeCacheMode = CacheTtl | 'off';
1438
1441
  declare class ClaudeAgent extends AbstractAgent {
1439
1442
  private readonly client;
1440
1443
  /**
1441
- * TTL for every breakpoint this agent places (system tiers and the message anchor).
1442
- * Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads at 0.1x, and a read
1443
- * refreshes the timer on either TTL. Default '1h' because the main consumer runs at human
1444
- * pace: consecutive calls for one agent measured 12-78 minutes apart, so 5m entries
1445
- * expired before they were ever read (0-16% hit rate over 30 days, hits only on gaps
1446
- * under five minutes). Set '5m' for continuous traffic where every call lands inside the
1447
- * window; there the cheaper write wins. One knob for all breakpoints on purpose: Anthropic
1444
+ * TTL for every breakpoint this agent places (system tiers and the message anchor), or
1445
+ * 'off' to place none. Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads
1446
+ * at 0.1x, and a read refreshes the timer on either TTL; with no breakpoint every token is
1447
+ * plain 1x input (Claude has no implicit caching). Caching pays only when enough of what
1448
+ * is written gets read back: break-even is ~22% of the prompt read at 5m and ~53% at 1h.
1449
+ * Measured on Werewolf (human-paced, consecutive calls for one bot 12-78 minutes apart):
1450
+ * 5m read 0-16% back, 1h 42-43% over 30 days of production bot turns (2026-11-06) — both
1451
+ * cost more than no cache, so that host sets 'off'. Default '1h' for continuous traffic
1452
+ * where calls land inside the window. One knob for all breakpoints on purpose: Anthropic
1448
1453
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
1449
1454
  */
1450
- cacheTtl: CacheTtl;
1455
+ cacheTtl: ClaudeCacheMode;
1456
+ /** The cache_control to attach to a breakpoint, or none when caching is off. */
1457
+ private get cacheControl();
1451
1458
  private get defaultParams();
1452
1459
  private readonly logTemplates;
1453
1460
  private readonly errorMessages;
@@ -1483,9 +1490,11 @@ declare class ClaudeAgent extends AbstractAgent {
1483
1490
  * Builds TokenUsage from the response. Anthropic's input_tokens EXCLUDES cached tokens
1484
1491
  * (total prompt = input_tokens + cache_read + cache_creation), unlike the OpenAI-shaped
1485
1492
  * providers whose prompt_tokens include them — so reconstruct the full prompt size here
1486
- * before pricing. Cache reads bill at the cacheHitPrice (~0.1x); cache writes bill at
1487
- * 1.25x input, which MODEL_PRICING doesn't model, so written tokens are priced at the
1488
- * plain input rate (~20% undercount on the written span only).
1493
+ * before pricing. Cache reads bill at the cacheHitPrice (~0.1x). Cache writes bill at a
1494
+ * multiple of input by TTL (1.25x for 5m, 2x for 1h); MODEL_PRICING has no write rate, so
1495
+ * the premium is added on top at the call's effective input rate (which keeps any
1496
+ * long-context tier). Until 0.33.0 writes were priced at plain input, under-reporting
1497
+ * every 1h write by half.
1489
1498
  */
1490
1499
  private buildTokenUsage;
1491
1500
  private convertRole;
@@ -1911,4 +1920,4 @@ declare class MiniMaxAgent extends AbstractAgent {
1911
1920
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1912
1921
  }
1913
1922
 
1914
- export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, type RetryHook, type RetrySettledFn, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, setRetryHook, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
1923
+ export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type ClaudeCacheMode, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, type RetryHook, type RetrySettledFn, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, setRetryHook, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ interface TokenUsage$1 {
25
25
  costUSD: number;
26
26
  reasoningTokens?: number;
27
27
  cachedInputTokens?: number;
28
+ cacheWriteTokens?: number;
28
29
  durationMs?: number;
29
30
  }
30
31
  interface ApiKeyMap {
@@ -1435,19 +1436,25 @@ declare class AgentFactory {
1435
1436
  }
1436
1437
 
1437
1438
  type CacheTtl = '5m' | '1h';
1439
+ /** Prompt-cache setting for a ClaudeAgent: a TTL for every breakpoint, or 'off' for none. */
1440
+ type ClaudeCacheMode = CacheTtl | 'off';
1438
1441
  declare class ClaudeAgent extends AbstractAgent {
1439
1442
  private readonly client;
1440
1443
  /**
1441
- * TTL for every breakpoint this agent places (system tiers and the message anchor).
1442
- * Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads at 0.1x, and a read
1443
- * refreshes the timer on either TTL. Default '1h' because the main consumer runs at human
1444
- * pace: consecutive calls for one agent measured 12-78 minutes apart, so 5m entries
1445
- * expired before they were ever read (0-16% hit rate over 30 days, hits only on gaps
1446
- * under five minutes). Set '5m' for continuous traffic where every call lands inside the
1447
- * window; there the cheaper write wins. One knob for all breakpoints on purpose: Anthropic
1444
+ * TTL for every breakpoint this agent places (system tiers and the message anchor), or
1445
+ * 'off' to place none. Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads
1446
+ * at 0.1x, and a read refreshes the timer on either TTL; with no breakpoint every token is
1447
+ * plain 1x input (Claude has no implicit caching). Caching pays only when enough of what
1448
+ * is written gets read back: break-even is ~22% of the prompt read at 5m and ~53% at 1h.
1449
+ * Measured on Werewolf (human-paced, consecutive calls for one bot 12-78 minutes apart):
1450
+ * 5m read 0-16% back, 1h 42-43% over 30 days of production bot turns (2026-11-06) — both
1451
+ * cost more than no cache, so that host sets 'off'. Default '1h' for continuous traffic
1452
+ * where calls land inside the window. One knob for all breakpoints on purpose: Anthropic
1448
1453
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
1449
1454
  */
1450
- cacheTtl: CacheTtl;
1455
+ cacheTtl: ClaudeCacheMode;
1456
+ /** The cache_control to attach to a breakpoint, or none when caching is off. */
1457
+ private get cacheControl();
1451
1458
  private get defaultParams();
1452
1459
  private readonly logTemplates;
1453
1460
  private readonly errorMessages;
@@ -1483,9 +1490,11 @@ declare class ClaudeAgent extends AbstractAgent {
1483
1490
  * Builds TokenUsage from the response. Anthropic's input_tokens EXCLUDES cached tokens
1484
1491
  * (total prompt = input_tokens + cache_read + cache_creation), unlike the OpenAI-shaped
1485
1492
  * providers whose prompt_tokens include them — so reconstruct the full prompt size here
1486
- * before pricing. Cache reads bill at the cacheHitPrice (~0.1x); cache writes bill at
1487
- * 1.25x input, which MODEL_PRICING doesn't model, so written tokens are priced at the
1488
- * plain input rate (~20% undercount on the written span only).
1493
+ * before pricing. Cache reads bill at the cacheHitPrice (~0.1x). Cache writes bill at a
1494
+ * multiple of input by TTL (1.25x for 5m, 2x for 1h); MODEL_PRICING has no write rate, so
1495
+ * the premium is added on top at the call's effective input rate (which keeps any
1496
+ * long-context tier). Until 0.33.0 writes were priced at plain input, under-reporting
1497
+ * every 1h write by half.
1489
1498
  */
1490
1499
  private buildTokenUsage;
1491
1500
  private convertRole;
@@ -1911,4 +1920,4 @@ declare class MiniMaxAgent extends AbstractAgent {
1911
1920
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1912
1921
  }
1913
1922
 
1914
- export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, type RetryHook, type RetrySettledFn, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, setRetryHook, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
1923
+ export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type ClaudeCacheMode, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, type RetryHook, type RetrySettledFn, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, setRetryHook, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
package/dist/index.js CHANGED
@@ -1083,7 +1083,7 @@ var SupportedAiModels = {
1083
1083
  apiKeyName: API_KEY_CONSTANTS.ANTHROPIC,
1084
1084
  hasThinking: true,
1085
1085
  reasoningEffort: "high",
1086
- tags: ["expensive"]
1086
+ tags: ["fast", "expensive"]
1087
1087
  },
1088
1088
  // Haiku moved 4.5 → 5.5 on 2026-10-08 (`claude-haiku-5-5`, verified live with the platform
1089
1089
  // key). 10x cheaper ($0.10/$0.50 up to 100K-token prompts), 1M context / 128K output.
@@ -1097,7 +1097,7 @@ var SupportedAiModels = {
1097
1097
  apiKeyName: API_KEY_CONSTANTS.ANTHROPIC,
1098
1098
  hasThinking: true,
1099
1099
  reasoningEffort: "high",
1100
- tags: ["cheap"]
1100
+ tags: ["fast", "cheap"]
1101
1101
  },
1102
1102
  // DeepSeek V4 models — thinking-only entries (non-thinking variants retired 2026-08-05).
1103
1103
  // reasoningEffort pinned to 'low' 2026-08-30: at the provider default ('high', no budget
@@ -1114,7 +1114,7 @@ var SupportedAiModels = {
1114
1114
  reasoningEffort: "low",
1115
1115
  // Reasoning tokens share the output budget, so leave room for both CoT and answer.
1116
1116
  maxOutputTokens: 65536,
1117
- tags: ["cheap"]
1117
+ tags: ["very-fast", "cheap"]
1118
1118
  },
1119
1119
  [LLM_CONSTANTS.DEEPSEEK_PRO]: {
1120
1120
  displayName: "DeepSeek V4 Pro",
@@ -1233,8 +1233,7 @@ var SupportedAiModels = {
1233
1233
  modelApiName: "gemini-3.8-flash",
1234
1234
  apiKeyName: API_KEY_CONSTANTS.GOOGLE,
1235
1235
  hasThinking: true,
1236
- reasoningEffort: "medium",
1237
- tags: ["fast"]
1236
+ reasoningEffort: "medium"
1238
1237
  },
1239
1238
  [LLM_CONSTANTS.GEMINI_LITE]: {
1240
1239
  displayName: "Gemini 3.5 Flash Lite",
@@ -1244,7 +1243,7 @@ var SupportedAiModels = {
1244
1243
  reasoningEffort: "minimal",
1245
1244
  // Pre-3.6, same as Pro: keeps the 0.2 it always had.
1246
1245
  temperature: 0.2,
1247
- tags: ["fast", "cheap"]
1246
+ tags: ["very-fast", "cheap"]
1248
1247
  },
1249
1248
  // Always-on reasoning — no non-thinking sibling. Bumped 4.6 → 4.7 on 2026-09-22 (id verified
1250
1249
  // against GET /v1/models). Same price, same 200K extended-context boundary; the context
@@ -1299,7 +1298,7 @@ var SupportedAiModels = {
1299
1298
  // model reasons when the field is omitted. The API now takes low|medium|high on Large 4
1300
1299
  // (the 400 for `none` lists exactly those; Small still takes only high|none); the level
1301
1300
  // barely moved latency or trace size (4-12k chars at every level), so it stays on the
1302
- // documented 'high' default. Model list: 1M context. Tagged `slow`: the 15-25s band.
1301
+ // documented 'high' default. Model list: 1M context. Tagged `slow`: prod p90 27.8s (2026-11-03).
1303
1302
  [LLM_CONSTANTS.MISTRAL_LARGE]: {
1304
1303
  displayName: "Mistral Large 4",
1305
1304
  // `mistral-large-latest` still points at Large 3 (no reasoning); use the explicit id.
@@ -1316,7 +1315,7 @@ var SupportedAiModels = {
1316
1315
  apiKeyName: API_KEY_CONSTANTS.MISTRAL,
1317
1316
  hasThinking: true,
1318
1317
  reasoningEffort: "high",
1319
- tags: ["very-fast", "cheap"]
1318
+ tags: ["fast", "cheap"]
1320
1319
  },
1321
1320
  // Kimi models. Always-reasoning entries: K3-series models reason by default and the only way
1322
1321
  // to stop it is the undocumented K2-era `thinking: disabled` toggle, which we no longer rely on.
@@ -1327,7 +1326,7 @@ var SupportedAiModels = {
1327
1326
  // 15-character story pipeline) to Kimi K3.1 Pro ($2/$10, 1M context, same low|high|max
1328
1327
  // effort levels, default max). Live at high effort 2026-10-23: 3-sentence schema ask
1329
1328
  // 4.2-4.5s, 8-character scene (476-845 output tokens) 9.7-14.9s = 49-57 tok/s — the same
1330
- // output speed as K3, so a full bot turn still lands in the 15-25s `slow` band.
1329
+ // output speed as K3. Prod 2026-11-03: p90 34.1s, so `very-slow`.
1331
1330
  // Consumer policy (werewolf): 1 bot per free game (opt-in) until 100 turns are measured.
1332
1331
  [LLM_CONSTANTS.KIMI]: {
1333
1332
  displayName: "Kimi K3.1 Pro",
@@ -1338,7 +1337,7 @@ var SupportedAiModels = {
1338
1337
  // Pinned 'high' 2026-09-22, down from Moonshot's 'max' default: K3 had no levels at
1339
1338
  // launch and the agent hardcoded max, so this is the first time the knob exists.
1340
1339
  reasoningEffort: "high",
1341
- tags: ["slow", "expensive"]
1340
+ tags: ["very-slow", "expensive"]
1342
1341
  },
1343
1342
  // Same model, Moonshot's high-speed serving tier ("roughly two to three times faster",
1344
1343
  // platform.kimi.ai K3.1 Pro quickstart, read 2026-10-23) at 2x the price ($4/$20 — Opus 5.5
@@ -1368,8 +1367,7 @@ var SupportedAiModels = {
1368
1367
  reasoningEffort: "high",
1369
1368
  // Headroom for the shared reasoning+answer budget (like the DeepSeek entries), sized
1370
1369
  // at 2x default rather than DeepSeek's 65536 to bound worst-case latency on a slow model.
1371
- maxOutputTokens: 16384,
1372
- tags: ["slow"]
1370
+ maxOutputTokens: 16384
1373
1371
  },
1374
1372
  // GLM-5.3-Flash (added 2026-08-30): the cheap sibling. Same API contract as GLM-5.3 —
1375
1373
  // thinking cannot be disabled and reasoning_effort takes low|high|max only
@@ -1450,7 +1448,7 @@ var SupportedAiModels = {
1450
1448
  // the 3.7 models (verified live) — add it to their entries if they ever need taming.
1451
1449
  thinkingBudgetTokens: 1024,
1452
1450
  // Capped it measures 25-26s → the >25s tier.
1453
- tags: ["very-slow"]
1451
+ tags: ["slow"]
1454
1452
  },
1455
1453
  // qwen3.8-flash replaced qwen3.7-flash on 2026-08-30 (same 1M context, 128k max output);
1456
1454
  // qwen3.7-plus was retired the same day — persisted 'qwen-plus' ids resolve to this entry
@@ -1478,8 +1476,8 @@ var SupportedAiModels = {
1478
1476
  // 1.7s and the 8-character scene (363 output tokens) in 2.4s — ~150 tok/s, the fastest
1479
1477
  // provider in the sweep that day (Kimi Highspeed's scene takes 8s); a 3.2k-token game
1480
1478
  // prompt with a two-sentence JSON reply took 1.9-2.1s at every effort level vs 3.5s for M3.
1481
- // Tagged `fast` rather than `very-fast`: the sweep straddles the 3s line and production
1482
- // turns carry 10k+ tokens of context. Launched 2026-09-27 as Token-Plan-only (the
1479
+ // Production 2026-11-03 (1,271 bot turns): p50 4.8s but p90 16.0s, so no speed tag (see
1480
+ // the grading above; it was `fast` on the sweep). Launched 2026-09-27 as Token-Plan-only (the
1483
1481
  // 2026-10-02 probe got `unknown model` on the pay-as-you-go key); on the key since at
1484
1482
  // least 2026-10-27.
1485
1483
  [LLM_CONSTANTS.MINIMAX]: {
@@ -1488,7 +1486,7 @@ var SupportedAiModels = {
1488
1486
  apiKeyName: API_KEY_CONSTANTS.MINIMAX,
1489
1487
  hasThinking: true,
1490
1488
  reasoningEffort: "medium",
1491
- tags: ["fast", "cheap"]
1489
+ tags: ["cheap"]
1492
1490
  },
1493
1491
  // Meta Muse Spark 1.3 (added 2026-09-12) on Meta's own Model API — Standard tier, i.e.
1494
1492
  // the private model id (the `-contributor` id is a quarter of the price but Meta trains
@@ -1498,8 +1496,8 @@ var SupportedAiModels = {
1498
1496
  // game default: turns are short and every reasoning token bills as output.
1499
1497
  // Temperature: Meta documents the model as tuned to its 1.0 default.
1500
1498
  // Speed: measured 2026-09-12 at medium effort — 9.6s on a full-context day-2 vote, 4-8s on
1501
- // short turns (reasoning ≈ 90% of output tokens). That is the untagged middle band by the
1502
- // grading above; tagged 'slow' anyway by decision so players expect a wait. Price-wise it
1499
+ // short turns (reasoning ≈ 90% of output tokens). Prod 2026-11-03: p50 10.5s, p90 24.6s,
1500
+ // which is `slow` by the grading above. Price-wise it
1503
1501
  // is neither cheap nor expensive.
1504
1502
  [LLM_CONSTANTS.MUSE_SPARK]: {
1505
1503
  displayName: "Muse Spark 1.3",
@@ -3055,22 +3053,29 @@ ${instruction}`);
3055
3053
 
3056
3054
  // src/agents/anthropic-agent.ts
3057
3055
  var import_sdk = require("@anthropic-ai/sdk");
3056
+ var CACHE_WRITE_MULTIPLIER = { "5m": 1.25, "1h": 2 };
3058
3057
  var rejectsDisabledThinking = (model) => model.includes("fable") || model.includes("opus-5-5");
3059
3058
  var usesBetweenToolsForOff = (model) => model.includes("sonnet-5-5");
3060
3059
  var usesAdaptiveThinking = (model) => !model.includes("haiku-4");
3061
3060
  var ClaudeAgent = class extends AbstractAgent {
3062
3061
  client;
3063
3062
  /**
3064
- * TTL for every breakpoint this agent places (system tiers and the message anchor).
3065
- * Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads at 0.1x, and a read
3066
- * refreshes the timer on either TTL. Default '1h' because the main consumer runs at human
3067
- * pace: consecutive calls for one agent measured 12-78 minutes apart, so 5m entries
3068
- * expired before they were ever read (0-16% hit rate over 30 days, hits only on gaps
3069
- * under five minutes). Set '5m' for continuous traffic where every call lands inside the
3070
- * window; there the cheaper write wins. One knob for all breakpoints on purpose: Anthropic
3063
+ * TTL for every breakpoint this agent places (system tiers and the message anchor), or
3064
+ * 'off' to place none. Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads
3065
+ * at 0.1x, and a read refreshes the timer on either TTL; with no breakpoint every token is
3066
+ * plain 1x input (Claude has no implicit caching). Caching pays only when enough of what
3067
+ * is written gets read back: break-even is ~22% of the prompt read at 5m and ~53% at 1h.
3068
+ * Measured on Werewolf (human-paced, consecutive calls for one bot 12-78 minutes apart):
3069
+ * 5m read 0-16% back, 1h 42-43% over 30 days of production bot turns (2026-11-06) — both
3070
+ * cost more than no cache, so that host sets 'off'. Default '1h' for continuous traffic
3071
+ * where calls land inside the window. One knob for all breakpoints on purpose: Anthropic
3071
3072
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
3072
3073
  */
3073
3074
  cacheTtl = "1h";
3075
+ /** The cache_control to attach to a breakpoint, or none when caching is off. */
3076
+ get cacheControl() {
3077
+ return this.cacheTtl === "off" ? {} : { cache_control: { type: "ephemeral", ttl: this.cacheTtl } };
3078
+ }
3074
3079
  // System-prompt breakpoints, one per cache tier (see CACHE_TIER_MARKER):
3075
3080
  // block 1 - shared static rules, byte-identical across all bots and games with the
3076
3081
  // same rule set. Caches are scoped per model, so one entry serves every bot
@@ -3086,7 +3091,7 @@ var ClaudeAgent = class extends AbstractAgent {
3086
3091
  get defaultParams() {
3087
3092
  return {
3088
3093
  max_tokens: this.maxOutputTokens,
3089
- system: this.instructionParts.map((part) => ({ type: "text", text: part, cache_control: { type: "ephemeral", ttl: this.cacheTtl } })),
3094
+ system: this.instructionParts.map((part) => ({ type: "text", text: part, ...this.cacheControl })),
3090
3095
  model: this.model
3091
3096
  };
3092
3097
  }
@@ -3185,6 +3190,9 @@ var ClaudeAgent = class extends AbstractAgent {
3185
3190
  * which for us is exactly the never-repeated tail — every entry it wrote would be dead.
3186
3191
  */
3187
3192
  applyCacheBreakpoint(messages) {
3193
+ if (this.cacheTtl === "off") {
3194
+ return;
3195
+ }
3188
3196
  if (messages.length < 2) {
3189
3197
  return;
3190
3198
  }
@@ -3207,9 +3215,11 @@ var ClaudeAgent = class extends AbstractAgent {
3207
3215
  * Builds TokenUsage from the response. Anthropic's input_tokens EXCLUDES cached tokens
3208
3216
  * (total prompt = input_tokens + cache_read + cache_creation), unlike the OpenAI-shaped
3209
3217
  * providers whose prompt_tokens include them — so reconstruct the full prompt size here
3210
- * before pricing. Cache reads bill at the cacheHitPrice (~0.1x); cache writes bill at
3211
- * 1.25x input, which MODEL_PRICING doesn't model, so written tokens are priced at the
3212
- * plain input rate (~20% undercount on the written span only).
3218
+ * before pricing. Cache reads bill at the cacheHitPrice (~0.1x). Cache writes bill at a
3219
+ * multiple of input by TTL (1.25x for 5m, 2x for 1h); MODEL_PRICING has no write rate, so
3220
+ * the premium is added on top at the call's effective input rate (which keeps any
3221
+ * long-context tier). Until 0.33.0 writes were priced at plain input, under-reporting
3222
+ * every 1h write by half.
3213
3223
  */
3214
3224
  buildTokenUsage(usage) {
3215
3225
  const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
@@ -3217,7 +3227,14 @@ var ClaudeAgent = class extends AbstractAgent {
3217
3227
  const uncachedInputTokens = usage.input_tokens || 0;
3218
3228
  const inputTokens = uncachedInputTokens + cacheReadTokens + cacheWriteTokens;
3219
3229
  const outputTokens = usage.output_tokens || 0;
3220
- const cost = calculateAnthropicCost(this.model, inputTokens, outputTokens, cacheReadTokens);
3230
+ let cost = calculateAnthropicCost(this.model, inputTokens, outputTokens, cacheReadTokens);
3231
+ if (cacheWriteTokens > 0) {
3232
+ const byTtl = usage.cache_creation;
3233
+ const written1h = byTtl ? byTtl.ephemeral_1h_input_tokens ?? 0 : this.cacheTtl === "1h" ? cacheWriteTokens : 0;
3234
+ const written5m = byTtl ? byTtl.ephemeral_5m_input_tokens ?? 0 : cacheWriteTokens - written1h;
3235
+ const inputRate = inputTokens > 0 ? calculateAnthropicCost(this.model, inputTokens, 0, 0) / inputTokens : 0;
3236
+ cost += inputRate * (written1h * (CACHE_WRITE_MULTIPLIER["1h"] - 1) + written5m * (CACHE_WRITE_MULTIPLIER["5m"] - 1));
3237
+ }
3221
3238
  if (cacheReadTokens > 0 || cacheWriteTokens > 0) {
3222
3239
  this.logger(`\u{1F4BE} Prompt cache: ${cacheReadTokens} read, ${cacheWriteTokens} written, ${uncachedInputTokens} uncached`);
3223
3240
  }
@@ -3226,8 +3243,9 @@ var ClaudeAgent = class extends AbstractAgent {
3226
3243
  outputTokens,
3227
3244
  totalTokens: inputTokens + outputTokens,
3228
3245
  costUSD: cost,
3229
- // Cache reads only — writes are a billing premium, not reuse of prior context.
3230
- ...cacheReadTokens > 0 ? { cachedInputTokens: cacheReadTokens } : {}
3246
+ // Breakdowns of inputTokens, omitted when zero (Firestore rejects undefined).
3247
+ ...cacheReadTokens > 0 ? { cachedInputTokens: cacheReadTokens } : {},
3248
+ ...cacheWriteTokens > 0 ? { cacheWriteTokens } : {}
3231
3249
  };
3232
3250
  }
3233
3251
  convertRole(role) {