@@ -90,16 +90,16 @@ public StreamEvent mergeToolUseEvents(StreamEvent previousEvent, StreamEvent eve
9090 ContentBlockToolUse cbToolUse = (ContentBlockToolUse ) contentBlockStart .contentBlock ();
9191
9292 return eventAggregator .withIndex (contentBlockStart .index ())
93- .withId (cbToolUse .id ())
94- .withName (cbToolUse .name ())
95- .appendPartialJson ("" ); // CB START always has empty JSON.
93+ .withId (cbToolUse .id ())
94+ .withName (cbToolUse .name ())
95+ .appendPartialJson ("" ); // CB START always has empty JSON.
9696 }
9797 }
9898 else if (event .type () == EventType .CONTENT_BLOCK_DELTA ) {
9999 ContentBlockDeltaEvent contentBlockDelta = (ContentBlockDeltaEvent ) event ;
100100 if (ContentBlock .Type .INPUT_JSON_DELTA .getValue ().equals (contentBlockDelta .delta ().type ())) {
101101 return eventAggregator
102- .appendPartialJson (((ContentBlockDeltaJson ) contentBlockDelta .delta ()).partialJson ());
102+ .appendPartialJson (((ContentBlockDeltaJson ) contentBlockDelta .delta ()).partialJson ());
103103 }
104104 }
105105 else if (event .type () == EventType .CONTENT_BLOCK_STOP ) {
@@ -121,7 +121,7 @@ else if (event.type() == EventType.CONTENT_BLOCK_STOP) {
121121 * @return A ChatCompletionResponse representing the processed chunk.
122122 */
123123 public ChatCompletionResponse eventToChatCompletionResponse (StreamEvent event ,
124- AtomicReference <ChatCompletionResponseBuilder > contentBlockReference ) {
124+ AtomicReference <ChatCompletionResponseBuilder > contentBlockReference ) {
125125
126126 // https://docs.anthropic.com/claude/reference/messages-streaming
127127
@@ -131,22 +131,22 @@ public ChatCompletionResponse eventToChatCompletionResponse(StreamEvent event,
131131 MessageStartEvent messageStartEvent = (MessageStartEvent ) event ;
132132
133133 contentBlockReference .get ()
134- .withType (event .type ().name ())
135- .withId (messageStartEvent .message ().id ())
136- .withRole (messageStartEvent .message ().role ())
137- .withModel (messageStartEvent .message ().model ())
138- .withUsage (messageStartEvent .message ().usage ())
139- .withContent (new ArrayList <>());
134+ .withType (event .type ().name ())
135+ .withId (messageStartEvent .message ().id ())
136+ .withRole (messageStartEvent .message ().role ())
137+ .withModel (messageStartEvent .message ().model ())
138+ .withUsage (messageStartEvent .message ().usage ())
139+ .withContent (new ArrayList <>());
140140 }
141141 else if (event .type ().equals (EventType .TOOL_USE_AGGREGATE )) {
142142 ToolUseAggregationEvent eventToolUseBuilder = (ToolUseAggregationEvent ) event ;
143143
144144 if (!CollectionUtils .isEmpty (eventToolUseBuilder .getToolContentBlocks ())) {
145145
146146 List <ContentBlock > content = eventToolUseBuilder .getToolContentBlocks ()
147- .stream ()
148- .map (tooToUse -> new ContentBlock (Type .TOOL_USE , tooToUse .id (), tooToUse .name (), tooToUse .input ()))
149- .toList ();
147+ .stream ()
148+ .map (tooToUse -> new ContentBlock (Type .TOOL_USE , tooToUse .id (), tooToUse .name (), tooToUse .input ()))
149+ .toList ();
150150 contentBlockReference .get ().withContent (content );
151151 }
152152 }
@@ -159,7 +159,7 @@ else if (event.type().equals(EventType.CONTENT_BLOCK_START)) {
159159 }
160160 else if (contentBlockStartEvent .contentBlock () instanceof ContentBlockThinking thinkingBlock ) {
161161 ContentBlock cb = new ContentBlock (Type .THINKING , null , null , contentBlockStartEvent .index (), null ,
162- null , null , null , null , null , thinkingBlock .thinking (), null );
162+ null , null , null , null , null , null , thinkingBlock .thinking (), null );
163163 contentBlockReference .get ().withType (event .type ().name ()).withContent (List .of (cb ));
164164 }
165165 else {
@@ -176,12 +176,12 @@ else if (event.type().equals(EventType.CONTENT_BLOCK_DELTA)) {
176176 }
177177 else if (contentBlockDeltaEvent .delta () instanceof ContentBlockDeltaThinking thinking ) {
178178 ContentBlock cb = new ContentBlock (Type .THINKING_DELTA , null , null , contentBlockDeltaEvent .index (),
179- null , null , null , null , null , null , thinking .thinking (), null );
179+ null , null , null , null , null , null , null , thinking .thinking (), null );
180180 contentBlockReference .get ().withType (event .type ().name ()).withContent (List .of (cb ));
181181 }
182182 else if (contentBlockDeltaEvent .delta () instanceof ContentBlockDeltaSignature sig ) {
183183 ContentBlock cb = new ContentBlock (Type .SIGNATURE_DELTA , null , null , contentBlockDeltaEvent .index (),
184- null , null , null , null , null , sig .signature (), null , null );
184+ null , null , null , null , null , null , sig .signature (), null , null );
185185 contentBlockReference .get ().withType (event .type ().name ()).withContent (List .of (cb ));
186186 }
187187 else {
@@ -204,8 +204,10 @@ else if (event.type().equals(EventType.MESSAGE_DELTA)) {
204204 }
205205
206206 if (messageDeltaEvent .usage () != null ) {
207- Usage totalUsage = new Usage (contentBlockReference .get ().usage .inputTokens (),
208- messageDeltaEvent .usage ().outputTokens ());
207+ var totalUsage = new Usage (contentBlockReference .get ().usage .inputTokens (),
208+ messageDeltaEvent .usage ().outputTokens (),
209+ contentBlockReference .get ().usage .cacheCreationInputTokens (),
210+ contentBlockReference .get ().usage .cacheReadInputTokens ());
209211 contentBlockReference .get ().withUsage (totalUsage );
210212 }
211213 }
@@ -214,10 +216,10 @@ else if (event.type().equals(EventType.MESSAGE_STOP)) {
214216 // with an updated event type and general information like: model, message
215217 // type, id and usage
216218 contentBlockReference .get ()
217- .withType (event .type ().name ())
218- .withContent (List .of ())
219- .withStopReason (null )
220- .withStopSequence (null );
219+ .withType (event .type ().name ())
220+ .withContent (List .of ())
221+ .withStopReason (null )
222+ .withStopSequence (null );
221223 }
222224 else {
223225 // Any other event types that should propagate upwards without content
0 commit comments