@aigne/anthropic 0.14.16-beta.5 → 0.14.16-beta.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.14.16-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/anthropic-v0.14.16-beta.5...anthropic-v0.14.16-beta.6) (2025-12-25)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **models:** support cache the last message for anthropic chat model ([#853](https://github.com/AIGNE-io/aigne-framework/issues/853)) ([bd08e44](https://github.com/AIGNE-io/aigne-framework/commit/bd08e44b28c46ac9a85234f0100d6dd144703c9d))
9
+
3
10
  ## [0.14.16-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/anthropic-v0.14.16-beta.4...anthropic-v0.14.16-beta.5) (2025-12-25)
4
11
 
5
12
 
@@ -287,7 +287,8 @@ async function convertMessages({ messages, responseFormat, tools, modelOptions,
287
287
  const systemBlocks = [];
288
288
  const msgs = [];
289
289
  // Extract cache configuration with defaults
290
- const { shouldCache, ttl, strategy, autoBreakpoints } = parseCacheConfig(modelOptions);
290
+ const { shouldCache, strategy, autoBreakpoints, ...cacheConfig } = parseCacheConfig(modelOptions);
291
+ const ttl = cacheConfig.ttl === "1h" ? "1h" : undefined;
291
292
  for (const msg of messages) {
292
293
  if (msg.role === "system") {
293
294
  if (typeof msg.content !== "string")
@@ -348,12 +349,29 @@ async function convertMessages({ messages, responseFormat, tools, modelOptions,
348
349
  });
349
350
  }
350
351
  // Apply cache_control to the last system block if auto strategy is enabled
351
- if (shouldCache && strategy === "auto" && autoBreakpoints.system && systemBlocks.length > 0) {
352
- const lastBlock = systemBlocks[systemBlocks.length - 1];
353
- if (lastBlock) {
354
- lastBlock.cache_control = { type: "ephemeral" };
355
- if (ttl === "1h") {
356
- lastBlock.cache_control = { type: "ephemeral", ttl: "1h" };
352
+ if (shouldCache && strategy === "auto") {
353
+ if (autoBreakpoints.system && systemBlocks.length > 0) {
354
+ const lastBlock = systemBlocks[systemBlocks.length - 1];
355
+ if (lastBlock) {
356
+ lastBlock.cache_control = { type: "ephemeral", ttl };
357
+ }
358
+ }
359
+ if (autoBreakpoints.lastMessage) {
360
+ const lastMsg = msgs[msgs.length - 1];
361
+ if (lastMsg) {
362
+ if (typeof lastMsg.content === "string") {
363
+ lastMsg.content = [
364
+ { type: "text", text: lastMsg.content, cache_control: { type: "ephemeral", ttl } },
365
+ ];
366
+ }
367
+ else if (Array.isArray(lastMsg.content)) {
368
+ const lastBlock = lastMsg.content[lastMsg.content.length - 1];
369
+ if (lastBlock &&
370
+ lastBlock.type !== "thinking" &&
371
+ lastBlock.type !== "redacted_thinking") {
372
+ lastBlock.cache_control = { type: "ephemeral", ttl };
373
+ }
374
+ }
357
375
  }
358
376
  }
359
377
  }
@@ -280,7 +280,8 @@ async function convertMessages({ messages, responseFormat, tools, modelOptions,
280
280
  const systemBlocks = [];
281
281
  const msgs = [];
282
282
  // Extract cache configuration with defaults
283
- const { shouldCache, ttl, strategy, autoBreakpoints } = parseCacheConfig(modelOptions);
283
+ const { shouldCache, strategy, autoBreakpoints, ...cacheConfig } = parseCacheConfig(modelOptions);
284
+ const ttl = cacheConfig.ttl === "1h" ? "1h" : undefined;
284
285
  for (const msg of messages) {
285
286
  if (msg.role === "system") {
286
287
  if (typeof msg.content !== "string")
@@ -341,12 +342,29 @@ async function convertMessages({ messages, responseFormat, tools, modelOptions,
341
342
  });
342
343
  }
343
344
  // Apply cache_control to the last system block if auto strategy is enabled
344
- if (shouldCache && strategy === "auto" && autoBreakpoints.system && systemBlocks.length > 0) {
345
- const lastBlock = systemBlocks[systemBlocks.length - 1];
346
- if (lastBlock) {
347
- lastBlock.cache_control = { type: "ephemeral" };
348
- if (ttl === "1h") {
349
- lastBlock.cache_control = { type: "ephemeral", ttl: "1h" };
345
+ if (shouldCache && strategy === "auto") {
346
+ if (autoBreakpoints.system && systemBlocks.length > 0) {
347
+ const lastBlock = systemBlocks[systemBlocks.length - 1];
348
+ if (lastBlock) {
349
+ lastBlock.cache_control = { type: "ephemeral", ttl };
350
+ }
351
+ }
352
+ if (autoBreakpoints.lastMessage) {
353
+ const lastMsg = msgs[msgs.length - 1];
354
+ if (lastMsg) {
355
+ if (typeof lastMsg.content === "string") {
356
+ lastMsg.content = [
357
+ { type: "text", text: lastMsg.content, cache_control: { type: "ephemeral", ttl } },
358
+ ];
359
+ }
360
+ else if (Array.isArray(lastMsg.content)) {
361
+ const lastBlock = lastMsg.content[lastMsg.content.length - 1];
362
+ if (lastBlock &&
363
+ lastBlock.type !== "thinking" &&
364
+ lastBlock.type !== "redacted_thinking") {
365
+ lastBlock.cache_control = { type: "ephemeral", ttl };
366
+ }
367
+ }
350
368
  }
351
369
  }
352
370
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/anthropic",
3
- "version": "0.14.16-beta.5",
3
+ "version": "0.14.16-beta.6",
4
4
  "description": "AIGNE Anthropic SDK for integrating with Claude AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"