Skip to content

Commit 1eaafd5

Browse files
committed
feat(bedrock): send thinking blocks back with their signatures
This implements what Anthropic docs recommend. Opus 5.5, Fable 5/5.1 and Mythos 5.1 on Bedrock now keep their earlier reasoning across tool calls instead of starting over at each step. Before, Zoo sent none of the thinking blocks back to the model. Anthropic's guidance, from thinking#preserving-thinking-blocks: > Required: within a tool-use turn, pass thinking blocks back. > Recommended: across turns, pass everything back. > Allowed: outside tool use, omit prior turns' thinking. Zoo follows the recommended option and sends every stored block back, across the whole history. - Bedrock collects each reasoningContent block (text, signature, redacted content) and emits it whole at contentBlockStop as a new `thinking_block` chunk. Blocks with an empty text are kept too. - Task stores those blocks in the assistant turn in the order the model produced them, between text and tool_use blocks. It no longer stores a separate copy of the same text. - The Converse converter sends them back as reasoningContent for these models. For other models it drops them, instead of turning unknown blocks into "[Unknown Block Type]" text. - The request sets thinking.block_binding.prefix_mismatch_behavior to "drop_block" with the thinking-binding-controls-2026-08-01 beta. These models bind each block to the prefix before it (system prompt, tools, earlier messages), and Zoo edits that prefix (condensing, mode switches, environment details). Accounts created on or after 2026-08-31 would otherwise get a 400 on the first such edit. Checked live through AwsBedrockHandler (2026-09-27), with reasoning on and off: - Opus 5.5, Fable 5 and Fable 5.1: a tool round trip with the blocks sent back works, and after a system-prompt edit it still works with drop_block. Mythos 5.1 wasn't available to test; AWS says it records the binding but doesn't check it. - Opus 5.5 only: - With "error", Bedrock returns the documented 400. - Zoo's Bedrock prompt caching adds `cachePoint` markers to messages and moves them between requests. A marker added to an earlier message does not invalidate the thinking blocks after it, even with "error". Otherwise every cached request would drop the model's reasoning. Zoo can't tell which blocks were dropped, because it uses ConverseStream. The API lists them in input_transformations, which it puts in the message_start event of Anthropic's own streaming format (what InvokeModelWithResponseStream returns unchanged). AWS documents that ConverseStream returns any field requested in additionalModelResponseFieldPaths, but we observe the opposite for this field. In the live test ConverseStream only resolved paths into the final message_delta event: /delta/stop_details and /usage came back, /input_transformations and /message/input_transformations did not. Non-streaming Converse and InvokeModelWithResponseStream did return input_transformations. AWS doesn't document the message_delta behaviour; Vercel's AI SDK hit it independently (commit afe9730, "Fix bedrock ConverseStream undocumented /delta/stop_sequence"). - https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks - https://platform.claude.com/docs/en/build-with-claude/preserved-thinking - https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-thinking-block-binding.html - https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#converse-additional-model-response-field-paths - vercel/ai@afe9730 - https://repost.aws/questions/QUJqYEmLvUTSOCZ6FkRCiqjA (question we asked) See also Zoo-Code-Org#1820.
1 parent d76d4e4 commit 1eaafd5

9 files changed

Lines changed: 550 additions & 136 deletions

File tree

‎src/api/providers/__tests__/bedrock.spec.ts‎

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,12 +1862,150 @@ describe("AwsBedrockHandler", () => {
18621862
const additionalFields = commandArg.additionalModelRequestFields as
18631863
| { thinking?: unknown; anthropic_beta?: string[] }
18641864
| undefined
1865-
expect(additionalFields?.thinking).toEqual({ type: "adaptive", display: "updates" })
1865+
expect(additionalFields?.thinking).toEqual({
1866+
type: "adaptive",
1867+
display: "updates",
1868+
block_binding: { prefix_mismatch_behavior: "drop_block" },
1869+
})
18661870
expect(additionalFields?.anthropic_beta).toContain("thinking-display-updates-2026-08-18")
1871+
expect(additionalFields?.anthropic_beta).toContain("thinking-binding-controls-2026-08-01")
18671872
expect(additionalFields).not.toHaveProperty("output_config")
18681873
expect(commandArg.inferenceConfig?.temperature).toBeUndefined()
18691874
})
18701875

1876+
it.each(["global.anthropic.claude-opus-5-5", "anthropic.claude-fable-5", "anthropic.claude-fable-5-1"])(
1877+
"sends drop_block with its beta when reasoning is enabled on %s",
1878+
async (apiModelId) => {
1879+
const provider = new AwsBedrockHandler({
1880+
apiModelId,
1881+
enableReasoningEffort: true,
1882+
modelMaxTokens: 32_000,
1883+
})
1884+
await collectStream(provider.createMessage("System prompt", messages))
1885+
1886+
const additionalFields = mockConverseStreamCommand.mock.calls[0][0].additionalModelRequestFields as
1887+
| { thinking?: unknown; anthropic_beta?: string[] }
1888+
| undefined
1889+
expect(additionalFields?.thinking).toMatchObject({
1890+
display: "summarized",
1891+
block_binding: { prefix_mismatch_behavior: "drop_block" },
1892+
})
1893+
expect(additionalFields?.anthropic_beta).toContain("thinking-binding-controls-2026-08-01")
1894+
},
1895+
)
1896+
1897+
it.each(["anthropic.claude-opus-4-8", "anthropic.claude-opus-5"])(
1898+
"leaves block_binding out for %s, which does not bind thinking to the prefix",
1899+
async (apiModelId) => {
1900+
const provider = new AwsBedrockHandler({
1901+
apiModelId,
1902+
enableReasoningEffort: true,
1903+
modelMaxTokens: 32_000,
1904+
})
1905+
await collectStream(provider.createMessage("System prompt", messages))
1906+
1907+
const additionalFields = mockConverseStreamCommand.mock.calls[0][0].additionalModelRequestFields as
1908+
| { thinking?: unknown; anthropic_beta?: string[] }
1909+
| undefined
1910+
expect(additionalFields?.thinking).not.toHaveProperty("block_binding")
1911+
expect(additionalFields?.anthropic_beta ?? []).not.toContain("thinking-binding-controls-2026-08-01")
1912+
},
1913+
)
1914+
1915+
it("emits each reasoning block whole at contentBlockStop, with its signature", async () => {
1916+
const provider = new AwsBedrockHandler({
1917+
apiModelId: "global.anthropic.claude-opus-5-5",
1918+
enableReasoningEffort: true,
1919+
modelMaxTokens: 32_000,
1920+
})
1921+
provider["client"].send = vi.fn().mockResolvedValue({
1922+
stream: asyncStreamFrom([
1923+
{ contentBlockDelta: { contentBlockIndex: 0, delta: { reasoningContent: { text: "Let me " } } } },
1924+
{ contentBlockDelta: { contentBlockIndex: 0, delta: { reasoningContent: { text: "check." } } } },
1925+
{
1926+
contentBlockDelta: {
1927+
contentBlockIndex: 0,
1928+
delta: { reasoningContent: { signature: "sig-a" } },
1929+
},
1930+
},
1931+
{ contentBlockStop: { contentBlockIndex: 0 } },
1932+
// An omitted block: no text, only a signature, still sent back.
1933+
{
1934+
contentBlockDelta: {
1935+
contentBlockIndex: 1,
1936+
delta: { reasoningContent: { signature: "sig-b" } },
1937+
},
1938+
},
1939+
{ contentBlockStop: { contentBlockIndex: 1 } },
1940+
{
1941+
contentBlockDelta: {
1942+
contentBlockIndex: 2,
1943+
delta: { reasoningContent: { redactedContent: new Uint8Array([1, 2, 3]) } },
1944+
},
1945+
},
1946+
{ contentBlockStop: { contentBlockIndex: 2 } },
1947+
{ contentBlockDelta: { contentBlockIndex: 3, delta: { text: "Done." } } },
1948+
{ contentBlockStop: { contentBlockIndex: 3 } },
1949+
{ messageStop: { stopReason: "end_turn" } },
1950+
]),
1951+
})
1952+
1953+
const chunks = await collectStream(provider.createMessage("System prompt", messages))
1954+
1955+
expect(chunks.filter((chunk) => chunk.type === "thinking_block")).toEqual([
1956+
{ type: "thinking_block", block: { type: "thinking", thinking: "Let me check.", signature: "sig-a" } },
1957+
{ type: "thinking_block", block: { type: "thinking", thinking: "", signature: "sig-b" } },
1958+
{ type: "thinking_block", block: { type: "redacted_thinking", data: "AQID" } },
1959+
])
1960+
})
1961+
1962+
it("does not collect reasoning blocks for models that don't round-trip them", async () => {
1963+
const provider = new AwsBedrockHandler({
1964+
apiModelId: "anthropic.claude-opus-4-8",
1965+
enableReasoningEffort: true,
1966+
modelMaxTokens: 32_000,
1967+
})
1968+
provider["client"].send = vi.fn().mockResolvedValue({
1969+
stream: asyncStreamFrom([
1970+
{ contentBlockDelta: { contentBlockIndex: 0, delta: { reasoningContent: { text: "Hmm." } } } },
1971+
{ contentBlockDelta: { contentBlockIndex: 0, delta: { reasoningContent: { signature: "sig" } } } },
1972+
{ contentBlockStop: { contentBlockIndex: 0 } },
1973+
{ messageStop: { stopReason: "end_turn" } },
1974+
]),
1975+
})
1976+
1977+
const chunks = await collectStream(provider.createMessage("System prompt", messages))
1978+
1979+
expect(chunks.some((chunk) => chunk.type === "thinking_block")).toBe(false)
1980+
})
1981+
1982+
it("sends stored thinking blocks back as reasoningContent in their original position", async () => {
1983+
const provider = new AwsBedrockHandler({
1984+
apiModelId: "global.anthropic.claude-opus-5-5",
1985+
enableReasoningEffort: true,
1986+
modelMaxTokens: 32_000,
1987+
awsUsePromptCache: false,
1988+
})
1989+
const history: Anthropic.Messages.MessageParam[] = [
1990+
{ role: "user", content: "Fix it." },
1991+
{
1992+
role: "assistant",
1993+
content: [
1994+
{ type: "thinking", thinking: "Plan.", signature: "sig-a" },
1995+
{ type: "tool_use", id: "t1", name: "read_file", input: { path: "a.ts" } },
1996+
],
1997+
},
1998+
{ role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: "..." }] },
1999+
]
2000+
await collectStream(provider.createMessage("System prompt", history))
2001+
2002+
const sent = mockConverseStreamCommand.mock.calls[0][0].messages
2003+
expect(sent?.[1].content).toEqual([
2004+
{ reasoningContent: { reasoningText: { text: "Plan.", signature: "sig-a" } } },
2005+
{ toolUse: { toolUseId: "t1", name: "read_file", input: { path: "a.ts" } } },
2006+
])
2007+
})
2008+
18712009
it.each([
18722010
[false, "progress_update"],
18732011
[true, "reasoning"],

‎src/api/providers/bedrock.ts‎

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ interface BedrockInferenceConfig {
7373
* (for example `reasoning_extraction`). Bedrock reports such refusals only as `content_filtered` otherwise.
7474
* See #1820.
7575
*
76-
* ConverseStream resolves these pointers against the native streaming `message_delta` event,
77-
* where the field sits under `delta`, not against the non-streaming message.
76+
* ConverseStream resolves these pointers against the final `message_delta` event of Anthropic's
77+
* streaming format, where the field sits under `delta`, not against the non-streaming message.
78+
* AWS doesn't document this; Vercel's AI SDK found the same for `/delta/stop_sequence`.
7879
* Verified live on 2026-09-27: `/stop_details` came back as nothing,
7980
* while `/delta/stop_details` returned `{"delta":{"stop_details":null}}` in
8081
* `messageStop.additionalModelResponseFields` on an ordinary turn.
8182
* A valid pointer the model doesn't return is ignored.
8283
*
8384
* - https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#what-a-refusal-looks-like
8485
* - https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#converse-additional-model-response-field-paths
86+
* - https://github.com/vercel/ai/commit/afe9730ab7e1d187b5b18b829636046ef5b8eb06
8587
*/
8688
const ANTHROPIC_RESPONSE_FIELD_PATHS = ["/delta/stop_details"]
8789

@@ -119,6 +121,49 @@ const PROGRESS_UPDATE_MODEL_PATTERNS = [
119121
] as const
120122
const THINKING_DISPLAY_UPDATES_BETA = "thinking-display-updates-2026-08-18"
121123

124+
/**
125+
* Thinking blocks are sent back to these models with their signatures, across the whole history,
126+
* so the model keeps its earlier reasoning instead of starting over at each step.
127+
* Anthropic's guidance (thinking#preserving-thinking-blocks):
128+
*
129+
* > Required: within a tool-use turn, pass thinking blocks back.
130+
* > Recommended: across turns, pass everything back.
131+
* > Allowed: outside tool use, omit prior turns' thinking.
132+
*
133+
* Bedrock accepted round-tripped `reasoningContent` blocks for Opus 5.5, Fable 5 and Fable 5.1
134+
* in a live test (2026-09-27). Mythos 5.1 wasn't available to test.
135+
*
136+
* Opus 5.5 and Fable 5.1 bind each block to the conversation prefix before it:
137+
* an edited system prompt, tool list or earlier message makes the block invalid.
138+
* Zoo edits the prefix (condensing, mode switches, environment details),
139+
* so `drop_block` asks the API to drop invalid blocks rather than reject the request,
140+
* which it does by default for accounts created on or after 2026-08-31.
141+
* It's sent to every model here, not only those two:
142+
* AWS says Mythos 5.1 "records the same signature but doesn't run" the check,
143+
* and doesn't mention Fable 5, so sending it keeps them safe if that changes.
144+
* The same live test accepted it on Opus 5.5, Fable 5 and Fable 5.1, including after a system-prompt edit.
145+
*
146+
* Zoo can't tell which blocks were dropped, because it uses ConverseStream.
147+
* The API lists them in `input_transformations`, which it puts in the `message_start` event
148+
* of Anthropic's own streaming format (what InvokeModelWithResponseStream returns unchanged).
149+
* AWS documents that ConverseStream returns any field requested in `additionalModelResponseFieldPaths`,
150+
* but we observe the opposite for this field (live test, 2026-09-27):
151+
* ConverseStream only resolved paths into the final `message_delta` event
152+
* (the same behaviour noted at `ANTHROPIC_RESPONSE_FIELD_PATHS`, which Vercel's AI SDK also found).
153+
* `/delta/stop_details` and `/usage` came back; `/input_transformations` and
154+
* `/message/input_transformations` did not.
155+
* Non-streaming Converse and InvokeModelWithResponseStream did return `input_transformations`.
156+
*
157+
* - https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks
158+
* - https://platform.claude.com/docs/en/build-with-claude/preserved-thinking
159+
* - https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-thinking-block-binding.html
160+
* - https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#converse-additional-model-response-field-paths
161+
* - https://repost.aws/questions/QUJqYEmLvUTSOCZ6FkRCiqjA (question we asked)
162+
*/
163+
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01"
164+
165+
type ThinkingBlockBinding = { prefix_mismatch_behavior: "error" | "drop_block" }
166+
122167
// Define interface for Bedrock additional model request fields
123168
// This includes thinking configuration, 1M context beta, and other model-specific parameters
124169
interface BedrockAdditionalModelFields {
@@ -132,6 +177,7 @@ interface BedrockAdditionalModelFields {
132177
type: "adaptive"
133178
// "updates" returns only progress-update text, "summarized" also reasoning summaries.
134179
display?: "summarized" | "updates" | "omitted"
180+
block_binding?: ThinkingBlockBinding
135181
}
136182
| { type: "disabled" }
137183
output_config?: {
@@ -201,6 +247,8 @@ interface ContentBlockDeltaEvent {
201247
// AWS SDK structure for reasoning content deltas
202248
reasoningContent?: {
203249
text?: string
250+
signature?: string
251+
redactedContent?: Uint8Array
204252
}
205253
// Tool use input delta
206254
toolUse?: {
@@ -228,6 +276,7 @@ export interface StreamEvent {
228276
}
229277
contentBlockStart?: ContentBlockStartEvent
230278
contentBlockDelta?: ContentBlockDeltaEvent
279+
contentBlockStop?: { contentBlockIndex?: number }
231280
// Exception events that arrive in-band rather than being thrown
232281
internalServerException?: BedrockStreamException
233282
modelStreamErrorException?: BedrockStreamException
@@ -421,6 +470,11 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
421470
return PROGRESS_UPDATE_MODEL_PATTERNS.some((pattern) => baseModelId.includes(pattern))
422471
}
423472

473+
/** Models whose thinking blocks are round-tripped; see THINKING_BINDING_CONTROLS_BETA. */
474+
private roundTripsThinking(modelId: string): boolean {
475+
return this.writesProgressUpdates(modelId)
476+
}
477+
424478
private isAdaptiveThinkingModel(modelId: string): boolean {
425479
const baseModelId = this.getCapabilityModelId(modelId)
426480
return (
@@ -518,12 +572,14 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
518572
}`
519573
: "default_conversation"
520574

575+
const keepThinking = this.roundTripsThinking(modelConfig.id)
521576
const formatted = this.convertToBedrockConverseMessages(
522577
messages,
523578
systemPrompt,
524579
usePromptCache,
525580
modelConfig.info,
526581
conversationId,
582+
keepThinking,
527583
)
528584

529585
let additionalModelRequestFields: BedrockAdditionalModelFields | undefined
@@ -639,6 +695,13 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
639695
const thinkingTextChunk = (text: string): ApiStreamChunk =>
640696
thinkingTextIsProgressUpdate ? { type: "progress_update", text } : { type: "reasoning", text }
641697

698+
if (keepThinking && thinkingDisplay?.type === "adaptive") {
699+
thinkingDisplay.block_binding = { prefix_mismatch_behavior: "drop_block" }
700+
anthropicBetas.push(THINKING_BINDING_CONTROLS_BETA)
701+
}
702+
// Reasoning blocks of this response by content-block index, emitted whole at contentBlockStop.
703+
const thinkingBlocks = new Map<number, { text: string; signature: string; redacted?: Uint8Array }>()
704+
642705
// Apply anthropic_beta to additionalModelRequestFields if any betas are needed
643706
if (anthropicBetas.length > 0) {
644707
if (!additionalModelRequestFields) {
@@ -883,9 +946,21 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
883946
// - delta.text: standard text content
884947
// - delta.toolUse.input: tool input arguments
885948
if (delta) {
949+
const reasoning = delta.reasoningContent
950+
if (keepThinking && reasoning) {
951+
const index = cbDelta.contentBlockIndex ?? 0
952+
const block = thinkingBlocks.get(index) ?? { text: "", signature: "" }
953+
block.text += reasoning.text ?? ""
954+
block.signature += reasoning.signature ?? ""
955+
if (reasoning.redactedContent) {
956+
block.redacted = reasoning.redactedContent
957+
}
958+
thinkingBlocks.set(index, block)
959+
}
960+
886961
// Check for reasoningContent property (AWS SDK structure)
887-
if (delta.reasoningContent?.text) {
888-
yield thinkingTextChunk(delta.reasoningContent.text)
962+
if (reasoning?.text) {
963+
yield thinkingTextChunk(reasoning.text)
889964
continue
890965
}
891966

@@ -913,6 +988,23 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
913988
}
914989
continue
915990
}
991+
if (streamEvent.contentBlockStop) {
992+
const index = streamEvent.contentBlockStop.contentBlockIndex ?? 0
993+
const block = thinkingBlocks.get(index)
994+
thinkingBlocks.delete(index)
995+
if (block?.redacted) {
996+
yield {
997+
type: "thinking_block",
998+
block: { type: "redacted_thinking", data: Buffer.from(block.redacted).toString("base64") },
999+
}
1000+
} else if (block?.signature) {
1001+
yield {
1002+
type: "thinking_block",
1003+
block: { type: "thinking", thinking: block.text, signature: block.signature },
1004+
}
1005+
}
1006+
continue
1007+
}
9161008
// Handle message stop
9171009
if (streamEvent.messageStop) {
9181010
outputLimitReached = streamEvent.messageStop.stopReason === "max_tokens"
@@ -1118,9 +1210,12 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
11181210
usePromptCache: boolean = false,
11191211
modelInfo?: any,
11201212
conversationId?: string, // Optional conversation ID to track cache points across messages
1213+
keepThinking = false,
11211214
): { system: SystemContentBlock[]; messages: Message[] } {
11221215
// First convert messages using shared converter for proper image handling
1123-
const convertedMessages = sharedConverter(anthropicMessages as Anthropic.Messages.MessageParam[])
1216+
const convertedMessages = sharedConverter(anthropicMessages as Anthropic.Messages.MessageParam[], {
1217+
keepThinking,
1218+
})
11241219

11251220
// If prompt caching is disabled, return the converted messages directly
11261221
if (!usePromptCache) {

‎src/api/transform/__tests__/bedrock-converse-format.spec.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,49 @@ import { Anthropic } from "@anthropic-ai/sdk"
55
import { ContentBlock, ToolResultContentBlock } from "@aws-sdk/client-bedrock-runtime"
66
import { OPENAI_CALL_ID_MAX_LENGTH } from "../../../utils/tool-id"
77

8+
describe("convertToBedrockConverseMessages thinking blocks", () => {
9+
const turn: Anthropic.Messages.MessageParam = {
10+
role: "assistant",
11+
content: [
12+
{ type: "thinking", thinking: "Plan.", signature: "sig-a" },
13+
{ type: "thinking", thinking: "", signature: "sig-b" },
14+
{ type: "redacted_thinking", data: "AQID" },
15+
{ type: "text", text: "Reading it." },
16+
{ type: "tool_use", id: "t1", name: "read_file", input: { path: "a.ts" } },
17+
],
18+
}
19+
20+
it("drops them unless asked to keep them, so other models never see them", () => {
21+
const [message] = convertToBedrockConverseMessages([turn])
22+
23+
expect(message.content).toEqual([
24+
{ text: "Reading it." },
25+
{ toolUse: { toolUseId: "t1", name: "read_file", input: { path: "a.ts" } } },
26+
])
27+
})
28+
29+
it("sends them back as reasoningContent in their original order, empty ones included", () => {
30+
const [message] = convertToBedrockConverseMessages([turn], { keepThinking: true })
31+
32+
expect(message.content).toEqual([
33+
{ reasoningContent: { reasoningText: { text: "Plan.", signature: "sig-a" } } },
34+
{ reasoningContent: { reasoningText: { text: "", signature: "sig-b" } } },
35+
{ reasoningContent: { redactedContent: new Uint8Array([1, 2, 3]) } },
36+
{ text: "Reading it." },
37+
{ toolUse: { toolUseId: "t1", name: "read_file", input: { path: "a.ts" } } },
38+
])
39+
})
40+
41+
it("leaves out a thinking block without a signature, which the API would reject", () => {
42+
const [message] = convertToBedrockConverseMessages(
43+
[{ role: "assistant", content: [{ type: "thinking", thinking: "Plan.", signature: "" }] }],
44+
{ keepThinking: true },
45+
)
46+
47+
expect(message.content).toEqual([])
48+
})
49+
})
50+
851
describe("convertToBedrockConverseMessages", () => {
952
it("converts simple text messages correctly", () => {
1053
const messages: Anthropic.Messages.MessageParam[] = [

0 commit comments

Comments
 (0)