@hiper2d/ai-agents 0.36.1 → 0.38.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 +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2486,8 +2486,20 @@ var AbstractAgent = class {
|
|
|
2486
2486
|
* invalidResponseRetries policy. Subclasses implement doAskWithZodSchema/doAskText and
|
|
2487
2487
|
* must NOT override these.
|
|
2488
2488
|
*/
|
|
2489
|
-
|
|
2490
|
-
|
|
2489
|
+
/**
|
|
2490
|
+
* `reject` is the host's own check on a schema-valid answer: return why it is unusable
|
|
2491
|
+
* (a required field left as an empty string, say) and the answer is treated exactly like
|
|
2492
|
+
* a malformed one: a ModelInvalidResponseError, re-sent under invalidResponseRetries.
|
|
2493
|
+
* It exists because a check written into the zod schema would change the JSON schema
|
|
2494
|
+
* the provider sees.
|
|
2495
|
+
*/
|
|
2496
|
+
async askWithZodSchema(zodSchema, messages, reject) {
|
|
2497
|
+
return this.askWithRetries(async () => {
|
|
2498
|
+
const result = await this.doAskWithZodSchema(zodSchema, messages);
|
|
2499
|
+
const reason = reject?.(result[0]);
|
|
2500
|
+
if (reason) throw new ModelInvalidResponseError(this.model, reason);
|
|
2501
|
+
return result;
|
|
2502
|
+
});
|
|
2491
2503
|
}
|
|
2492
2504
|
async askText(messages) {
|
|
2493
2505
|
return this.askWithRetries(() => this.doAskText(messages));
|
|
@@ -2918,6 +2930,15 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
2918
2930
|
* requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
|
|
2919
2931
|
*/
|
|
2920
2932
|
cacheTtl = "1h";
|
|
2933
|
+
/**
|
|
2934
|
+
* Which message carries the message breakpoint (see applyCacheBreakpoint).
|
|
2935
|
+
* 'previous' (default): the second-to-last message, for hosts whose final message carries
|
|
2936
|
+
* content they never send again (an unsaved reminder) - a breakpoint there would only pay
|
|
2937
|
+
* the write. 'last': the final message, for hosts that replay every request in full on the
|
|
2938
|
+
* next one (Werewolf since 2026-11-15 stores its turn tail and replays it), so the whole
|
|
2939
|
+
* request is written and the next call reads all of it.
|
|
2940
|
+
*/
|
|
2941
|
+
cacheAnchor = "previous";
|
|
2921
2942
|
/** The cache_control to attach to a breakpoint, or none when caching is off. */
|
|
2922
2943
|
get cacheControl() {
|
|
2923
2944
|
return this.cacheTtl === "off" ? {} : { cache_control: { type: "ephemeral", ttl: this.cacheTtl } };
|
|
@@ -3032,6 +3053,9 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3032
3053
|
* reply, or an earlier flushed block) reappears verbatim next turn, where the moved-
|
|
3033
3054
|
* forward breakpoint finds it via the 20-block lookback.
|
|
3034
3055
|
*
|
|
3056
|
+
* With `cacheAnchor = 'last'` the host says its final message IS replayed, and the
|
|
3057
|
+
* breakpoint goes on the last message instead.
|
|
3058
|
+
*
|
|
3035
3059
|
* NOT the top-level auto-caching mode: that mode targets the LAST cacheable block,
|
|
3036
3060
|
* which for us is exactly the never-repeated tail — every entry it wrote would be dead.
|
|
3037
3061
|
*/
|
|
@@ -3039,10 +3063,11 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3039
3063
|
if (this.cacheTtl === "off") {
|
|
3040
3064
|
return;
|
|
3041
3065
|
}
|
|
3042
|
-
|
|
3066
|
+
const back = this.cacheAnchor === "last" ? 1 : 2;
|
|
3067
|
+
if (messages.length < back) {
|
|
3043
3068
|
return;
|
|
3044
3069
|
}
|
|
3045
|
-
const anchor = messages[messages.length -
|
|
3070
|
+
const anchor = messages[messages.length - back];
|
|
3046
3071
|
if (typeof anchor.content === "string") {
|
|
3047
3072
|
if (anchor.content.length > 0) {
|
|
3048
3073
|
anchor.content = [{ type: "text", text: anchor.content, cache_control: { type: "ephemeral", ttl: this.cacheTtl } }];
|