@@ -13,6 +13,7 @@ import type {
1313 BetaRawContentBlockStopEvent ,
1414} from "@anthropic-ai/sdk/resources/beta.js" ;
1515import type { BetaRateLimitError } from "@anthropic-ai/sdk/resources" ;
16+ import { nanoid } from "../utils/nanoid.js" ;
1617
1718type AnthropicChunk =
1819 | BetaRawContentBlockDeltaEvent
@@ -33,8 +34,8 @@ type AnthropicChunk =
3334
3435type OnlyLiteralStrings < T > = T extends string
3536 ? string extends T
36- ? never
37- : T
37+ ? never
38+ : T
3839 : never ;
3940
4041export type AnthropicModel = OnlyLiteralStrings < Anthropic . Model > ;
@@ -71,6 +72,8 @@ export class AnthropicProvider extends Provider {
7172 private content : string = "" ;
7273 /** Current model being used for the request */
7374 private currentModel : string = "" ;
75+ /** Unique execution ID for this streaming session */
76+ private executionId : string = "" ;
7477
7578 /**
7679 * Creates a new AnthropicProvider instance.
@@ -132,6 +135,7 @@ export class AnthropicProvider extends Provider {
132135 this . currentToolName = null ;
133136 this . content = "" ;
134137 this . currentModel = model ;
138+ this . executionId = nanoid ( ) ;
135139
136140 const stream = this . client . beta . messages . stream ( {
137141 model : model . replace ( "anthropic/" , "" ) as Anthropic . Model ,
@@ -236,9 +240,12 @@ export class AnthropicProvider extends Provider {
236240 protected normalizeChunk ( chunk : AnthropicChunk ) : NormalizedChunk | null {
237241 const timestamp = Date . now ( ) ;
238242
243+ console . log ( chunk ) ;
244+
239245 if ( chunk . type === "rate_limit_error" ) {
240246 return {
241247 provider : "anthropic" ,
248+ executionId : this . executionId ,
242249 timestamp,
243250 index : - 1 ,
244251 type : "error" ,
@@ -249,9 +256,10 @@ export class AnthropicProvider extends Provider {
249256
250257 const baseChunk : Pick <
251258 NormalizedChunkAnthropic ,
252- "provider" | "timestamp" | "index" | "originalChunk"
259+ "provider" | "executionId" | " timestamp" | "index" | "originalChunk"
253260 > = {
254261 provider : "anthropic" ,
262+ executionId : this . executionId ,
255263 timestamp,
256264 index : chunk . index ,
257265 originalChunk : chunk ,
0 commit comments