Skip to content

Commit 44551f9

Browse files
committed
refactor: remove summaryIndex from ResponsesStreamState and related handlers
1 parent 9477b45 commit 44551f9

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

src/routes/messages/responses-stream-translation.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface ResponsesStreamState {
1515
initialInputTokens?: number
1616
functionCallStateByOutputIndex: Map<number, FunctionCallStreamState>
1717
functionCallOutputIndexByItemId: Map<string, number>
18-
summryIndex: number
1918
}
2019

2120
type FunctionCallStreamState = {
@@ -33,7 +32,6 @@ export const createResponsesStreamState = (): ResponsesStreamState => ({
3332
blockHasDelta: new Set(),
3433
functionCallStateByOutputIndex: new Map(),
3534
functionCallOutputIndexByItemId: new Map(),
36-
summryIndex: 0,
3735
})
3836

3937
export const translateResponsesStreamEvent = (
@@ -172,13 +170,8 @@ const handleOutputItemDone = (
172170
}
173171

174172
const outputIndex = toNumber(rawEvent.output_index)
175-
const contentIndex = state.summryIndex
176173

177-
const blockIndex = openThinkingBlockIfNeeded(state, {
178-
outputIndex,
179-
contentIndex,
180-
events,
181-
})
174+
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events)
182175

183176
const signature =
184177
typeof item.encrypted_content === "string" ? item.encrypted_content : ""
@@ -321,18 +314,13 @@ const handleReasoningSummaryTextDelta = (
321314
const events = ensureMessageStart(state)
322315

323316
const outputIndex = toNumber(rawEvent.output_index)
324-
const contentIndex = toNumber(rawEvent.summary_index)
325317
const deltaText = typeof rawEvent.delta === "string" ? rawEvent.delta : ""
326318

327319
if (!deltaText) {
328320
return events
329321
}
330322

331-
const blockIndex = openThinkingBlockIfNeeded(state, {
332-
outputIndex,
333-
contentIndex,
334-
events,
335-
})
323+
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events)
336324

337325
events.push({
338326
type: "content_block_delta",
@@ -354,16 +342,10 @@ const handleReasoningSummaryPartDone = (
354342
const events = ensureMessageStart(state)
355343

356344
const outputIndex = toNumber(rawEvent.output_index)
357-
const contentIndex = toNumber(rawEvent.summary_index)
358-
state.summryIndex = contentIndex
359345
const part = isRecord(rawEvent.part) ? rawEvent.part : undefined
360346
const text = part && typeof part.text === "string" ? part.text : ""
361347

362-
const blockIndex = openThinkingBlockIfNeeded(state, {
363-
outputIndex,
364-
contentIndex,
365-
events,
366-
})
348+
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events)
367349

368350
if (text && !state.blockHasDelta.has(blockIndex)) {
369351
events.push({
@@ -554,13 +536,10 @@ const openTextBlockIfNeeded = (
554536

555537
const openThinkingBlockIfNeeded = (
556538
state: ResponsesStreamState,
557-
params: {
558-
outputIndex: number
559-
contentIndex: number
560-
events: Array<AnthropicStreamEventData>
561-
},
539+
outputIndex: number,
540+
events: Array<AnthropicStreamEventData>,
562541
): number => {
563-
const { outputIndex, contentIndex, events } = params
542+
const contentIndex = 0
564543
const key = getBlockKey(outputIndex, contentIndex)
565544
let blockIndex = state.blockIndexByKey.get(key)
566545

0 commit comments

Comments
 (0)