@hiper2d/ai-agents 0.36.0 → 0.37.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
@@ -382,8 +382,9 @@ declare const API_KEY_CONSTANTS: {
382
382
  * Providers whose API ENFORCES a JSON schema on the answer (askWithZodSchema sends the
383
383
  * schema natively and the provider constrains the output to it). The rest only get the
384
384
  * schema described in the prompt: Grok, GLM and Fugu run in "JSON object" mode (valid JSON,
385
- * any shape), DeepSeek and MiniMax have no JSON mode on these calls at all. Meta is listed
386
- * although its json_schema runs with strict: false (the shape is guided, not guaranteed).
385
+ * any shape), DeepSeek and MiniMax have no JSON mode on these calls at all, and Meta's
386
+ * json_schema runs with strict: false (the shape is guided, not guaranteed; a 2026-11-12
387
+ * probe also read 0% of a repeated prompt from cache there, so there is nothing to gain).
387
388
  * Hosts use this to decide where a schema can replace a plain-text ask: on most enforcing
388
389
  * providers the prompt cache is keyed on the output format, so a host that mixes text and
389
390
  * schema calls loses the cache between them (measured 2026-11-12 on OpenAI, Mistral and
@@ -1467,6 +1468,15 @@ declare class ClaudeAgent extends AbstractAgent {
1467
1468
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
1468
1469
  */
1469
1470
  cacheTtl: ClaudeCacheMode;
1471
+ /**
1472
+ * Which message carries the message breakpoint (see applyCacheBreakpoint).
1473
+ * 'previous' (default): the second-to-last message, for hosts whose final message carries
1474
+ * content they never send again (an unsaved reminder) - a breakpoint there would only pay
1475
+ * the write. 'last': the final message, for hosts that replay every request in full on the
1476
+ * next one (Werewolf since 2026-11-15 stores its turn tail and replays it), so the whole
1477
+ * request is written and the next call reads all of it.
1478
+ */
1479
+ cacheAnchor: 'previous' | 'last';
1470
1480
  /** The cache_control to attach to a breakpoint, or none when caching is off. */
1471
1481
  private get cacheControl();
1472
1482
  private get defaultParams();
@@ -1496,6 +1506,9 @@ declare class ClaudeAgent extends AbstractAgent {
1496
1506
  * reply, or an earlier flushed block) reappears verbatim next turn, where the moved-
1497
1507
  * forward breakpoint finds it via the 20-block lookback.
1498
1508
  *
1509
+ * With `cacheAnchor = 'last'` the host says its final message IS replayed, and the
1510
+ * breakpoint goes on the last message instead.
1511
+ *
1499
1512
  * NOT the top-level auto-caching mode: that mode targets the LAST cacheable block,
1500
1513
  * which for us is exactly the never-repeated tail — every entry it wrote would be dead.
1501
1514
  */
package/dist/index.d.ts CHANGED
@@ -382,8 +382,9 @@ declare const API_KEY_CONSTANTS: {
382
382
  * Providers whose API ENFORCES a JSON schema on the answer (askWithZodSchema sends the
383
383
  * schema natively and the provider constrains the output to it). The rest only get the
384
384
  * schema described in the prompt: Grok, GLM and Fugu run in "JSON object" mode (valid JSON,
385
- * any shape), DeepSeek and MiniMax have no JSON mode on these calls at all. Meta is listed
386
- * although its json_schema runs with strict: false (the shape is guided, not guaranteed).
385
+ * any shape), DeepSeek and MiniMax have no JSON mode on these calls at all, and Meta's
386
+ * json_schema runs with strict: false (the shape is guided, not guaranteed; a 2026-11-12
387
+ * probe also read 0% of a repeated prompt from cache there, so there is nothing to gain).
387
388
  * Hosts use this to decide where a schema can replace a plain-text ask: on most enforcing
388
389
  * providers the prompt cache is keyed on the output format, so a host that mixes text and
389
390
  * schema calls loses the cache between them (measured 2026-11-12 on OpenAI, Mistral and
@@ -1467,6 +1468,15 @@ declare class ClaudeAgent extends AbstractAgent {
1467
1468
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
1468
1469
  */
1469
1470
  cacheTtl: ClaudeCacheMode;
1471
+ /**
1472
+ * Which message carries the message breakpoint (see applyCacheBreakpoint).
1473
+ * 'previous' (default): the second-to-last message, for hosts whose final message carries
1474
+ * content they never send again (an unsaved reminder) - a breakpoint there would only pay
1475
+ * the write. 'last': the final message, for hosts that replay every request in full on the
1476
+ * next one (Werewolf since 2026-11-15 stores its turn tail and replays it), so the whole
1477
+ * request is written and the next call reads all of it.
1478
+ */
1479
+ cacheAnchor: 'previous' | 'last';
1470
1480
  /** The cache_control to attach to a breakpoint, or none when caching is off. */
1471
1481
  private get cacheControl();
1472
1482
  private get defaultParams();
@@ -1496,6 +1506,9 @@ declare class ClaudeAgent extends AbstractAgent {
1496
1506
  * reply, or an earlier flushed block) reappears verbatim next turn, where the moved-
1497
1507
  * forward breakpoint finds it via the 20-block lookback.
1498
1508
  *
1509
+ * With `cacheAnchor = 'last'` the host says its final message IS replayed, and the
1510
+ * breakpoint goes on the last message instead.
1511
+ *
1499
1512
  * NOT the top-level auto-caching mode: that mode targets the LAST cacheable block,
1500
1513
  * which for us is exactly the never-repeated tail — every entry it wrote would be dead.
1501
1514
  */
package/dist/index.js CHANGED
@@ -996,8 +996,7 @@ var SCHEMA_ENFORCING_API_KEYS = /* @__PURE__ */ new Set([
996
996
  API_KEY_CONSTANTS.GOOGLE,
997
997
  API_KEY_CONSTANTS.MISTRAL,
998
998
  API_KEY_CONSTANTS.QWEN,
999
- API_KEY_CONSTANTS.MOONSHOT,
1000
- API_KEY_CONSTANTS.META
999
+ API_KEY_CONSTANTS.MOONSHOT
1001
1000
  ]);
1002
1001
  var SupportedAiKeyNames = {
1003
1002
  [API_KEY_CONSTANTS.OPENAI]: "OpenAI",
@@ -3102,6 +3101,15 @@ var ClaudeAgent = class extends AbstractAgent {
3102
3101
  * requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
3103
3102
  */
3104
3103
  cacheTtl = "1h";
3104
+ /**
3105
+ * Which message carries the message breakpoint (see applyCacheBreakpoint).
3106
+ * 'previous' (default): the second-to-last message, for hosts whose final message carries
3107
+ * content they never send again (an unsaved reminder) - a breakpoint there would only pay
3108
+ * the write. 'last': the final message, for hosts that replay every request in full on the
3109
+ * next one (Werewolf since 2026-11-15 stores its turn tail and replays it), so the whole
3110
+ * request is written and the next call reads all of it.
3111
+ */
3112
+ cacheAnchor = "previous";
3105
3113
  /** The cache_control to attach to a breakpoint, or none when caching is off. */
3106
3114
  get cacheControl() {
3107
3115
  return this.cacheTtl === "off" ? {} : { cache_control: { type: "ephemeral", ttl: this.cacheTtl } };
@@ -3216,6 +3224,9 @@ var ClaudeAgent = class extends AbstractAgent {
3216
3224
  * reply, or an earlier flushed block) reappears verbatim next turn, where the moved-
3217
3225
  * forward breakpoint finds it via the 20-block lookback.
3218
3226
  *
3227
+ * With `cacheAnchor = 'last'` the host says its final message IS replayed, and the
3228
+ * breakpoint goes on the last message instead.
3229
+ *
3219
3230
  * NOT the top-level auto-caching mode: that mode targets the LAST cacheable block,
3220
3231
  * which for us is exactly the never-repeated tail — every entry it wrote would be dead.
3221
3232
  */
@@ -3223,10 +3234,11 @@ var ClaudeAgent = class extends AbstractAgent {
3223
3234
  if (this.cacheTtl === "off") {
3224
3235
  return;
3225
3236
  }
3226
- if (messages.length < 2) {
3237
+ const back = this.cacheAnchor === "last" ? 1 : 2;
3238
+ if (messages.length < back) {
3227
3239
  return;
3228
3240
  }
3229
- const anchor = messages[messages.length - 2];
3241
+ const anchor = messages[messages.length - back];
3230
3242
  if (typeof anchor.content === "string") {
3231
3243
  if (anchor.content.length > 0) {
3232
3244
  anchor.content = [{ type: "text", text: anchor.content, cache_control: { type: "ephemeral", ttl: this.cacheTtl } }];