Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions strands-ts/src/models/__tests__/bedrock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,76 @@ describe('BedrockModel', () => {
expect(events).toContainEqual({ stopReason: 'endTurn', type: 'modelMessageStopEvent' })
})

it('handles citation delta key as alias for citationsContent', async () => {
// Bedrock Converse API sends "citation" key in stream deltas,
// not "citationsContent". Both must be handled. See #910.
const bedrockCitationsData = {
citations: [
{
location: { documentChar: { documentIndex: 0, start: 0, end: 20 } },
sourceContent: [{ text: 'source' }],
source: 'doc-0',
title: 'Citation Key Test',
},
],
content: [{ text: 'cited text' }],
}

const mockSend = vi.fn(async () => {
if (stream) {
return {
stream: (async function* (): AsyncGenerator<unknown> {
yield { messageStart: { role: 'assistant' } }
yield { contentBlockStart: {} }
yield {
contentBlockDelta: {
delta: { citation: bedrockCitationsData },
},
}
yield { contentBlockStop: {} }
yield { messageStop: { stopReason: 'end_turn' } }
yield {
metadata: { usage: { inputTokens: 10, outputTokens: 5, totalTokens: 15 }, metrics: { latencyMs: 100 } },
}
})(),
}
} else {
return {
output: {
message: {
role: 'assistant',
content: [{ citation: bedrockCitationsData }],
},
},
stopReason: 'end_turn',
usage: { inputTokens: 10, outputTokens: 5, totalTokens: 15 },
metrics: { latencyMs: 100 },
}
}
})
mockBedrockClientImplementation({ send: mockSend })

const provider = new BedrockModel({ stream })
const messages = [new Message({ role: 'user', content: [new TextBlock('Cite this.')] })]
const events = await collectIterator(provider.stream(messages))

expect(events).toContainEqual({
type: 'modelContentBlockDeltaEvent',
delta: {
type: 'citationsDelta',
citations: [
{
location: { type: 'documentChar', documentIndex: 0, start: 0, end: 20 },
sourceContent: [{ text: 'source' }],
source: 'doc-0',
title: 'Citation Key Test',
},
],
content: [{ text: 'cited text' }],
},
})
})

describe('error handling', async () => {
it.each([
{
Expand Down
23 changes: 23 additions & 0 deletions strands-ts/src/models/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,19 @@ export class BedrockModel extends Model<BedrockModelConfig> {
if (!block) return
events.push({ type: 'modelContentBlockStartEvent' })

const mapped = this._mapBedrockCitationsData(block)
const delta: CitationsDelta = {
type: 'citationsDelta',
citations: mapped.citations,
content: mapped.content,
}
events.push({ type: 'modelContentBlockDeltaEvent', delta })
events.push({ type: 'modelContentBlockStopEvent' })
},
citation: (block: BedrockCitationsContentBlock): void => {
if (!block) return
events.push({ type: 'modelContentBlockStartEvent' })

const mapped = this._mapBedrockCitationsData(block)
const delta: CitationsDelta = {
type: 'citationsDelta',
Expand Down Expand Up @@ -1300,6 +1313,16 @@ export class BedrockModel extends Model<BedrockModelConfig> {
}
events.push({ type: 'modelContentBlockDeltaEvent', delta })
},
citation: (block: BedrockCitationsContentBlock): void => {
if (!block) return
const mapped = this._mapBedrockCitationsData(block)
const delta: CitationsDelta = {
type: 'citationsDelta',
citations: mapped.citations,
content: mapped.content,
}
events.push({ type: 'modelContentBlockDeltaEvent', delta })
},
}

for (const key in delta) {
Expand Down
Loading