@hiper2d/ai-agents 0.10.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.mjs CHANGED
@@ -1530,6 +1530,7 @@ var DEEPSEEK_REASONING_EFFORTS = ["low", "high", "max"];
1530
1530
  var FUGU_REASONING_EFFORTS = ["high", "xhigh", "max"];
1531
1531
  var META_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh", "max"];
1532
1532
  var MISTRAL_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh"];
1533
+ var XAI_REASONING_EFFORTS = ["low", "medium", "high", "xhigh"];
1533
1534
  function clampReasoningEffort(effort, allowed) {
1534
1535
  const rank = REASONING_EFFORT_SCALE.indexOf(effort);
1535
1536
  let best = allowed[0];
@@ -1551,6 +1552,7 @@ var toDeepSeekEffort = (effort) => clampReasoningEffort(effort, DEEPSEEK_REASONI
1551
1552
  var toMetaEffort = (effort) => clampReasoningEffort(effort, META_REASONING_EFFORTS);
1552
1553
  var toFuguEffort = (effort) => clampReasoningEffort(effort, FUGU_REASONING_EFFORTS);
1553
1554
  var toMistralEffort = (effort) => clampReasoningEffort(effort, MISTRAL_REASONING_EFFORTS);
1555
+ var toXaiEffort = (effort) => clampReasoningEffort(effort, XAI_REASONING_EFFORTS);
1554
1556
 
1555
1557
  // src/pricing/token-usage-utils.ts
1556
1558
  function extractTokenUsage(response) {
@@ -3788,6 +3790,16 @@ ${schemaDescription}`;
3788
3790
  throw new Error(this.errorMessages.apiError(error));
3789
3791
  }
3790
3792
  }
3793
+ /**
3794
+ * A stable key per (game, bot) so xAI routes this conversation's requests to the same
3795
+ * server. Without it a request often lands on a cache-cold machine and the whole prompt
3796
+ * bills at full input price — xAI calls this out as the most common caching mistake.
3797
+ * Falls back to the bot name alone outside a game (story generation, tests), which is
3798
+ * still stabler than sending nothing.
3799
+ */
3800
+ get promptCacheKey() {
3801
+ return this.gameId ? `${this.gameId}:${this.name}` : this.name;
3802
+ }
3791
3803
  createResponse(input, jsonMode) {
3792
3804
  return this.client.responses.create({
3793
3805
  model: this.model,
@@ -3798,9 +3810,16 @@ ${schemaDescription}`;
3798
3810
  // ever starts truncating — measured turns peak far below the shared default.
3799
3811
  max_output_tokens: this.maxOutputTokens,
3800
3812
  // We manage conversation state ourselves; encrypted reasoning is only
3801
- // returned for unstored responses.
3813
+ // returned for unstored responses. Grok 4.7 returns reasoning.encrypted_content
3814
+ // on the Responses API whether or not `include` asks for it; we keep asking so
3815
+ // the behaviour is identical if the model is ever pointed back at 4.6.
3802
3816
  store: false,
3803
3817
  include: ["reasoning.encrypted_content"],
3818
+ prompt_cache_key: this.promptCacheKey,
3819
+ // Grok 4.7 is the first Grok with an effort knob (4.6 had none) and defaults to
3820
+ // "high". Only send it when the catalog asks for a level, so an unset entry keeps
3821
+ // the provider default rather than us silently picking one.
3822
+ ...this.reasoningEffort ? { reasoning: { effort: toXaiEffort(this.reasoningEffort) } } : {},
3804
3823
  ...jsonMode ? { text: { format: { type: "json_object" } } } : {}
3805
3824
  });
3806
3825
  }
@@ -5213,6 +5232,7 @@ export {
5213
5232
  VOICE_MODEL_PRICING,
5214
5233
  VOICE_PROVIDER_API_KEY,
5215
5234
  VoiceAgentFactory,
5235
+ XAI_REASONING_EFFORTS,
5216
5236
  ZodSchemaConverter,
5217
5237
  applySpend,
5218
5238
  buildGoogleTtsPrompt,
@@ -5293,6 +5313,7 @@ export {
5293
5313
  toMetaEffort,
5294
5314
  toMistralEffort,
5295
5315
  toOpenAIEffort,
5316
+ toXaiEffort,
5296
5317
  transcribeWithGemini,
5297
5318
  transcribeWithOpenAi,
5298
5319
  validateResponse