@ai-sdk/anthropic 4.0.60 → 4.0.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.60",
3
+ "version": "4.0.61",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.17",
39
- "@ai-sdk/provider-utils": "5.0.45"
38
+ "@ai-sdk/provider": "4.0.18",
39
+ "@ai-sdk/provider-utils": "5.0.46"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.1",
@@ -804,7 +804,7 @@ export const anthropicResponseSchema = lazySchema(() =>
804
804
  }),
805
805
  z.object({
806
806
  type: z.literal('compaction'),
807
- content: z.string(),
807
+ content: z.string().nullish(),
808
808
  }),
809
809
  z.object({
810
810
  type: z.literal('tool_use'),
@@ -799,6 +799,10 @@ function convertAnthropicBatchResponse(
799
799
  });
800
800
  break;
801
801
  case 'compaction':
802
+ if (!part.content) {
803
+ break;
804
+ }
805
+
802
806
  content.push({
803
807
  type: 'text',
804
808
  text: part.content,
@@ -1261,6 +1261,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1261
1261
  break;
1262
1262
  }
1263
1263
  case 'compaction': {
1264
+ if (!part.content) {
1265
+ break;
1266
+ }
1267
+
1264
1268
  content.push({
1265
1269
  type: 'text',
1266
1270
  text: part.content,
@@ -715,6 +715,10 @@ export async function convertToAnthropicPrompt({
715
715
  | undefined;
716
716
 
717
717
  if (textMetadata?.type === 'compaction') {
718
+ if (part.text === '') {
719
+ break;
720
+ }
721
+
718
722
  anthropicContent.push({
719
723
  type: 'compaction',
720
724
  content: part.text,
@@ -1386,10 +1390,12 @@ export async function convertToAnthropicPrompt({
1386
1390
  }
1387
1391
  }
1388
1392
 
1389
- messages.push({
1390
- role: 'assistant',
1391
- content: moveToolUseBlocksToEnd(anthropicContent),
1392
- });
1393
+ if (anthropicContent.length > 0) {
1394
+ messages.push({
1395
+ role: 'assistant',
1396
+ content: moveToolUseBlocksToEnd(anthropicContent),
1397
+ });
1398
+ }
1393
1399
 
1394
1400
  break;
1395
1401
  }