@hiper2d/ai-agents 0.9.0 → 0.11.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
@@ -537,8 +537,11 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
537
537
  * not on the shared scale and means "don't reason", which an agent expresses by omitting the
538
538
  * field, so the exported slice starts at minimal. Only "high" is documented to return the
539
539
  * thinking chunk; the intermediate levels are accepted but unverified.
540
- * Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax, Kimi and
541
- * Grok expose no effort parameter.
540
+ * - xAI Grok 4.7 (docs.x.ai/developers/model-capabilities/text/reasoning, 2026-09-22):
541
+ * low|medium|high|xhigh, default high, sent on the Responses API as `reasoning: {effort}`.
542
+ * Chat Completions has no equivalent. Grok 4.6 and earlier had no knob at all.
543
+ * Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax and Kimi
544
+ * expose no effort parameter.
542
545
  */
543
546
  type OpenAIReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
544
547
  type AnthropicReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
@@ -548,6 +551,7 @@ type DeepSeekReasoningEffort = 'low' | 'high' | 'max';
548
551
  type FuguReasoningEffort = 'high' | 'xhigh' | 'max';
549
552
  type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
550
553
  type MistralReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
554
+ type XaiReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh';
551
555
  /** The shared scale, lowest first. */
552
556
  declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
553
557
  declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
@@ -558,6 +562,7 @@ declare const DEEPSEEK_REASONING_EFFORTS: readonly DeepSeekReasoningEffort[];
558
562
  declare const FUGU_REASONING_EFFORTS: readonly FuguReasoningEffort[];
559
563
  declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
560
564
  declare const MISTRAL_REASONING_EFFORTS: readonly MistralReasoningEffort[];
565
+ declare const XAI_REASONING_EFFORTS: readonly XaiReasoningEffort[];
561
566
  /** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
562
567
  declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
563
568
  declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
@@ -568,6 +573,7 @@ declare const toDeepSeekEffort: (effort: ReasoningEffort) => DeepSeekReasoningEf
568
573
  declare const toMetaEffort: (effort: ReasoningEffort) => MetaReasoningEffort;
569
574
  declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
570
575
  declare const toMistralEffort: (effort: ReasoningEffort) => MistralReasoningEffort;
576
+ declare const toXaiEffort: (effort: ReasoningEffort) => XaiReasoningEffort;
571
577
 
572
578
  /**
573
579
  * Unified token usage utilities for all AI providers
@@ -1535,6 +1541,14 @@ declare class GrokAgent extends AbstractAgent {
1535
1541
  * Reasoning extraction and token accounting are identical to askWithZodSchema.
1536
1542
  */
1537
1543
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1544
+ /**
1545
+ * A stable key per (game, bot) so xAI routes this conversation's requests to the same
1546
+ * server. Without it a request often lands on a cache-cold machine and the whole prompt
1547
+ * bills at full input price — xAI calls this out as the most common caching mistake.
1548
+ * Falls back to the bot name alone outside a game (story generation, tests), which is
1549
+ * still stabler than sending nothing.
1550
+ */
1551
+ private get promptCacheKey();
1538
1552
  private createResponse;
1539
1553
  /**
1540
1554
  * Converts game history to Responses API input items. The system instruction is
@@ -1722,4 +1736,4 @@ declare class MiniMaxAgent extends AbstractAgent {
1722
1736
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1723
1737
  }
1724
1738
 
1725
- 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, 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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, 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, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
1739
+ 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, 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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, 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, 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, buildGoogleTtsPrompt, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
package/dist/index.d.ts CHANGED
@@ -537,8 +537,11 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
537
537
  * not on the shared scale and means "don't reason", which an agent expresses by omitting the
538
538
  * field, so the exported slice starts at minimal. Only "high" is documented to return the
539
539
  * thinking chunk; the intermediate levels are accepted but unverified.
540
- * Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax, Kimi and
541
- * Grok expose no effort parameter.
540
+ * - xAI Grok 4.7 (docs.x.ai/developers/model-capabilities/text/reasoning, 2026-09-22):
541
+ * low|medium|high|xhigh, default high, sent on the Responses API as `reasoning: {effort}`.
542
+ * Chat Completions has no equivalent. Grok 4.6 and earlier had no knob at all.
543
+ * Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax and Kimi
544
+ * expose no effort parameter.
542
545
  */
543
546
  type OpenAIReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
544
547
  type AnthropicReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
@@ -548,6 +551,7 @@ type DeepSeekReasoningEffort = 'low' | 'high' | 'max';
548
551
  type FuguReasoningEffort = 'high' | 'xhigh' | 'max';
549
552
  type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
550
553
  type MistralReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
554
+ type XaiReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh';
551
555
  /** The shared scale, lowest first. */
552
556
  declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
553
557
  declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
@@ -558,6 +562,7 @@ declare const DEEPSEEK_REASONING_EFFORTS: readonly DeepSeekReasoningEffort[];
558
562
  declare const FUGU_REASONING_EFFORTS: readonly FuguReasoningEffort[];
559
563
  declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
560
564
  declare const MISTRAL_REASONING_EFFORTS: readonly MistralReasoningEffort[];
565
+ declare const XAI_REASONING_EFFORTS: readonly XaiReasoningEffort[];
561
566
  /** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
562
567
  declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
563
568
  declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
@@ -568,6 +573,7 @@ declare const toDeepSeekEffort: (effort: ReasoningEffort) => DeepSeekReasoningEf
568
573
  declare const toMetaEffort: (effort: ReasoningEffort) => MetaReasoningEffort;
569
574
  declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
570
575
  declare const toMistralEffort: (effort: ReasoningEffort) => MistralReasoningEffort;
576
+ declare const toXaiEffort: (effort: ReasoningEffort) => XaiReasoningEffort;
571
577
 
572
578
  /**
573
579
  * Unified token usage utilities for all AI providers
@@ -1535,6 +1541,14 @@ declare class GrokAgent extends AbstractAgent {
1535
1541
  * Reasoning extraction and token accounting are identical to askWithZodSchema.
1536
1542
  */
1537
1543
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1544
+ /**
1545
+ * A stable key per (game, bot) so xAI routes this conversation's requests to the same
1546
+ * server. Without it a request often lands on a cache-cold machine and the whole prompt
1547
+ * bills at full input price — xAI calls this out as the most common caching mistake.
1548
+ * Falls back to the bot name alone outside a game (story generation, tests), which is
1549
+ * still stabler than sending nothing.
1550
+ */
1551
+ private get promptCacheKey();
1538
1552
  private createResponse;
1539
1553
  /**
1540
1554
  * Converts game history to Responses API input items. The system instruction is
@@ -1722,4 +1736,4 @@ declare class MiniMaxAgent extends AbstractAgent {
1722
1736
  doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1723
1737
  }
1724
1738
 
1725
- 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, 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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, 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, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
1739
+ 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, 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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, 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, 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, buildGoogleTtsPrompt, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
package/dist/index.js CHANGED
@@ -83,6 +83,7 @@ __export(src_exports, {
83
83
  VOICE_MODEL_PRICING: () => VOICE_MODEL_PRICING,
84
84
  VOICE_PROVIDER_API_KEY: () => VOICE_PROVIDER_API_KEY,
85
85
  VoiceAgentFactory: () => VoiceAgentFactory,
86
+ XAI_REASONING_EFFORTS: () => XAI_REASONING_EFFORTS,
86
87
  ZodSchemaConverter: () => ZodSchemaConverter,
87
88
  applySpend: () => applySpend,
88
89
  buildGoogleTtsPrompt: () => buildGoogleTtsPrompt,
@@ -163,6 +164,7 @@ __export(src_exports, {
163
164
  toMetaEffort: () => toMetaEffort,
164
165
  toMistralEffort: () => toMistralEffort,
165
166
  toOpenAIEffort: () => toOpenAIEffort,
167
+ toXaiEffort: () => toXaiEffort,
166
168
  transcribeWithGemini: () => transcribeWithGemini,
167
169
  transcribeWithOpenAi: () => transcribeWithOpenAi,
168
170
  validateResponse: () => validateResponse
@@ -1129,10 +1131,15 @@ var SupportedAiModels = {
1129
1131
  reasoningEffort: "minimal",
1130
1132
  tags: ["fast", "cheap"]
1131
1133
  },
1132
- // Always-on reasoning (xAI default effort "high", cannot be disabled) — no non-thinking sibling
1134
+ // Always-on reasoning — no non-thinking sibling. Bumped 4.6 → 4.7 on 2026-09-22 (id verified
1135
+ // against GET /v1/models). Same price, same 200K extended-context boundary; the context
1136
+ // window is 500K. NOTE 4.7 newly accepts `reasoning_effort` (low | medium | high | xhigh,
1137
+ // default high) where 4.6 had no knob at all. GrokAgent still sends none, so behaviour is
1138
+ // unchanged — but Grok is the app's most expensive model per turn (94% of its output is
1139
+ // reasoning), so a lower pin is the obvious lever to measure before anything else.
1133
1140
  [LLM_CONSTANTS.GROK]: {
1134
- displayName: "Grok 4.6",
1135
- modelApiName: "grok-4.6",
1141
+ displayName: "Grok 4.7",
1142
+ modelApiName: "grok-4.7",
1136
1143
  apiKeyName: API_KEY_CONSTANTS.GROK,
1137
1144
  hasThinking: true,
1138
1145
  temperature: 0.7
@@ -1544,8 +1551,9 @@ var MODEL_PRICING = {
1544
1551
  cacheHitPrice: 0.015
1545
1552
  },
1546
1553
  // Grok models. Cached price is per-model on xAI (not a uniform ratio):
1547
- // grok-4.6 is $0.50/M cached vs $2.00/M input, and all rates double for prompts
1548
- // >= 200K tokens, per docs.x.ai/developers/models (verified 2026-08-12).
1554
+ // grok-4.7 is $0.50/M cached vs $2.00/M input, and all rates double for prompts
1555
+ // >= 200K tokens, per docs.x.ai/docs/models (re-verified 2026-09-22 for 4.7).
1556
+ // 4.7 carries over 4.6's rates unchanged — the bump is capability-only, not a reprice.
1549
1557
  [SupportedAiModels[LLM_CONSTANTS.GROK].modelApiName]: {
1550
1558
  inputPrice: 2,
1551
1559
  outputPrice: 6,
@@ -1695,6 +1703,7 @@ var DEEPSEEK_REASONING_EFFORTS = ["low", "high", "max"];
1695
1703
  var FUGU_REASONING_EFFORTS = ["high", "xhigh", "max"];
1696
1704
  var META_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh", "max"];
1697
1705
  var MISTRAL_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh"];
1706
+ var XAI_REASONING_EFFORTS = ["low", "medium", "high", "xhigh"];
1698
1707
  function clampReasoningEffort(effort, allowed) {
1699
1708
  const rank = REASONING_EFFORT_SCALE.indexOf(effort);
1700
1709
  let best = allowed[0];
@@ -1716,6 +1725,7 @@ var toDeepSeekEffort = (effort) => clampReasoningEffort(effort, DEEPSEEK_REASONI
1716
1725
  var toMetaEffort = (effort) => clampReasoningEffort(effort, META_REASONING_EFFORTS);
1717
1726
  var toFuguEffort = (effort) => clampReasoningEffort(effort, FUGU_REASONING_EFFORTS);
1718
1727
  var toMistralEffort = (effort) => clampReasoningEffort(effort, MISTRAL_REASONING_EFFORTS);
1728
+ var toXaiEffort = (effort) => clampReasoningEffort(effort, XAI_REASONING_EFFORTS);
1719
1729
 
1720
1730
  // src/pricing/token-usage-utils.ts
1721
1731
  function extractTokenUsage(response) {
@@ -3953,6 +3963,16 @@ ${schemaDescription}`;
3953
3963
  throw new Error(this.errorMessages.apiError(error));
3954
3964
  }
3955
3965
  }
3966
+ /**
3967
+ * A stable key per (game, bot) so xAI routes this conversation's requests to the same
3968
+ * server. Without it a request often lands on a cache-cold machine and the whole prompt
3969
+ * bills at full input price — xAI calls this out as the most common caching mistake.
3970
+ * Falls back to the bot name alone outside a game (story generation, tests), which is
3971
+ * still stabler than sending nothing.
3972
+ */
3973
+ get promptCacheKey() {
3974
+ return this.gameId ? `${this.gameId}:${this.name}` : this.name;
3975
+ }
3956
3976
  createResponse(input, jsonMode) {
3957
3977
  return this.client.responses.create({
3958
3978
  model: this.model,
@@ -3963,9 +3983,16 @@ ${schemaDescription}`;
3963
3983
  // ever starts truncating — measured turns peak far below the shared default.
3964
3984
  max_output_tokens: this.maxOutputTokens,
3965
3985
  // We manage conversation state ourselves; encrypted reasoning is only
3966
- // returned for unstored responses.
3986
+ // returned for unstored responses. Grok 4.7 returns reasoning.encrypted_content
3987
+ // on the Responses API whether or not `include` asks for it; we keep asking so
3988
+ // the behaviour is identical if the model is ever pointed back at 4.6.
3967
3989
  store: false,
3968
3990
  include: ["reasoning.encrypted_content"],
3991
+ prompt_cache_key: this.promptCacheKey,
3992
+ // Grok 4.7 is the first Grok with an effort knob (4.6 had none) and defaults to
3993
+ // "high". Only send it when the catalog asks for a level, so an unset entry keeps
3994
+ // the provider default rather than us silently picking one.
3995
+ ...this.reasoningEffort ? { reasoning: { effort: toXaiEffort(this.reasoningEffort) } } : {},
3969
3996
  ...jsonMode ? { text: { format: { type: "json_object" } } } : {}
3970
3997
  });
3971
3998
  }
@@ -5379,6 +5406,7 @@ var AgentFactory = class {
5379
5406
  VOICE_MODEL_PRICING,
5380
5407
  VOICE_PROVIDER_API_KEY,
5381
5408
  VoiceAgentFactory,
5409
+ XAI_REASONING_EFFORTS,
5382
5410
  ZodSchemaConverter,
5383
5411
  applySpend,
5384
5412
  buildGoogleTtsPrompt,
@@ -5459,6 +5487,7 @@ var AgentFactory = class {
5459
5487
  toMetaEffort,
5460
5488
  toMistralEffort,
5461
5489
  toOpenAIEffort,
5490
+ toXaiEffort,
5462
5491
  transcribeWithGemini,
5463
5492
  transcribeWithOpenAi,
5464
5493
  validateResponse