Skip to content

Commit 7205bef

Browse files
committed
fix: add signature field and signature_delta event to Anthropic thinking blocks
1 parent 2f535ca commit 7205bef

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/bedrock.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function buildBedrockTextResponse(
269269
): object {
270270
const contentBlocks: object[] = [];
271271
if (reasoning) {
272-
contentBlocks.push({ type: "thinking", thinking: reasoning });
272+
contentBlocks.push({ type: "thinking", thinking: reasoning, signature: "" });
273273
}
274274
contentBlocks.push({ type: "text", text: content });
275275

@@ -683,7 +683,7 @@ export function buildBedrockStreamTextEvents(
683683
payload: {
684684
type: "content_block_start",
685685
index: blockIndex,
686-
content_block: { type: "thinking", thinking: "" },
686+
content_block: { type: "thinking", thinking: "", signature: "" },
687687
},
688688
});
689689

@@ -699,6 +699,15 @@ export function buildBedrockStreamTextEvents(
699699
});
700700
}
701701

702+
events.push({
703+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
704+
payload: {
705+
type: "content_block_delta",
706+
index: blockIndex,
707+
delta: { type: "signature_delta", signature: "" },
708+
},
709+
});
710+
702711
events.push({
703712
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
704713
payload: { type: "content_block_stop", index: blockIndex },
@@ -764,7 +773,7 @@ export function buildBedrockStreamContentWithToolCallsEvents(
764773
payload: {
765774
type: "content_block_start",
766775
index: blockIndex,
767-
content_block: { type: "thinking", thinking: "" },
776+
content_block: { type: "thinking", thinking: "", signature: "" },
768777
},
769778
});
770779
for (let i = 0; i < reasoning.length; i += chunkSize) {
@@ -778,6 +787,14 @@ export function buildBedrockStreamContentWithToolCallsEvents(
778787
},
779788
});
780789
}
790+
events.push({
791+
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
792+
payload: {
793+
type: "content_block_delta",
794+
index: blockIndex,
795+
delta: { type: "signature_delta", signature: "" },
796+
},
797+
});
781798
events.push({
782799
eventType: BEDROCK_INVOKE_STREAM_EVENT_TYPE,
783800
payload: { type: "content_block_stop", index: blockIndex },

src/messages.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function buildClaudeTextStreamEvents(
251251
events.push({
252252
type: "content_block_start",
253253
index: blockIndex,
254-
content_block: { type: "thinking", thinking: "" },
254+
content_block: { type: "thinking", thinking: "", signature: "" },
255255
});
256256

257257
for (let i = 0; i < reasoning.length; i += chunkSize) {
@@ -263,6 +263,12 @@ function buildClaudeTextStreamEvents(
263263
});
264264
}
265265

266+
events.push({
267+
type: "content_block_delta",
268+
index: blockIndex,
269+
delta: { type: "signature_delta", signature: "" },
270+
});
271+
266272
events.push({
267273
type: "content_block_stop",
268274
index: blockIndex,
@@ -408,7 +414,7 @@ function buildClaudeTextResponse(
408414
const contentBlocks: object[] = [];
409415

410416
if (reasoning) {
411-
contentBlocks.push({ type: "thinking", thinking: reasoning });
417+
contentBlocks.push({ type: "thinking", thinking: reasoning, signature: "" });
412418
}
413419

414420
contentBlocks.push({ type: "text", text: content });
@@ -494,7 +500,7 @@ function buildClaudeContentWithToolCallsStreamEvents(
494500
events.push({
495501
type: "content_block_start",
496502
index: blockIndex,
497-
content_block: { type: "thinking", thinking: "" },
503+
content_block: { type: "thinking", thinking: "", signature: "" },
498504
});
499505

500506
for (let i = 0; i < reasoning.length; i += chunkSize) {
@@ -506,6 +512,12 @@ function buildClaudeContentWithToolCallsStreamEvents(
506512
});
507513
}
508514

515+
events.push({
516+
type: "content_block_delta",
517+
index: blockIndex,
518+
delta: { type: "signature_delta", signature: "" },
519+
});
520+
509521
events.push({
510522
type: "content_block_stop",
511523
index: blockIndex,
@@ -607,7 +619,7 @@ function buildClaudeContentWithToolCallsResponse(
607619
const contentBlocks: object[] = [];
608620

609621
if (reasoning) {
610-
contentBlocks.push({ type: "thinking", thinking: reasoning });
622+
contentBlocks.push({ type: "thinking", thinking: reasoning, signature: "" });
611623
}
612624

613625
contentBlocks.push({ type: "text", text: content });

0 commit comments

Comments
 (0)