@@ -59,16 +59,16 @@ func NewStreamingInterceptor(
5959 }}
6060}
6161
62- func (s * StreamingInterception ) Setup (logger slog.Logger , recorder recorder.Recorder , mcpProxy mcp.ServerProxier ) {
63- s .interceptionBase .Setup (logger .Named ("streaming" ), recorder , mcpProxy )
62+ func (i * StreamingInterception ) Setup (logger slog.Logger , recorder recorder.Recorder , mcpProxy mcp.ServerProxier ) {
63+ i .interceptionBase .Setup (logger .Named ("streaming" ), recorder , mcpProxy )
6464}
6565
66- func (s * StreamingInterception ) Streaming () bool {
66+ func (* StreamingInterception ) Streaming () bool {
6767 return true
6868}
6969
70- func (s * StreamingInterception ) TraceAttributes (r * http.Request ) []attribute.KeyValue {
71- return s .interceptionBase .baseTraceAttributes (r , true )
70+ func (i * StreamingInterception ) TraceAttributes (r * http.Request ) []attribute.KeyValue {
71+ return i .interceptionBase .baseTraceAttributes (r , true )
7272}
7373
7474// ProcessRequest handles a request to /v1/messages.
@@ -534,8 +534,8 @@ newStream:
534534 return interceptionErr
535535}
536536
537- func (s * StreamingInterception ) marshalEvent (event anthropic.MessageStreamEventUnion ) ([]byte , error ) {
538- sj , err := sjson .Set (event .RawJSON (), "message.id" , s .ID ().String ())
537+ func (i * StreamingInterception ) marshalEvent (event anthropic.MessageStreamEventUnion ) ([]byte , error ) {
538+ sj , err := sjson .Set (event .RawJSON (), "message.id" , i .ID ().String ())
539539 if err != nil {
540540 return nil , xerrors .Errorf ("marshal event id failed: %w" , err )
541541 }
@@ -545,10 +545,10 @@ func (s *StreamingInterception) marshalEvent(event anthropic.MessageStreamEventU
545545 return nil , xerrors .Errorf ("marshal event usage failed: %w" , err )
546546 }
547547
548- return s .encodeForStream ([]byte (sj ), event .Type ), nil
548+ return i .encodeForStream ([]byte (sj ), event .Type ), nil
549549}
550550
551- func (s * StreamingInterception ) marshal (payload any ) ([]byte , error ) {
551+ func (i * StreamingInterception ) marshal (payload any ) ([]byte , error ) {
552552 data , err := json .Marshal (payload )
553553 if err != nil {
554554 return nil , xerrors .Errorf ("marshal payload: %w" , err )
@@ -564,15 +564,15 @@ func (s *StreamingInterception) marshal(payload any) ([]byte, error) {
564564 return nil , xerrors .Errorf ("could not determine type from payload %q" , data )
565565 }
566566
567- return s .encodeForStream (data , eventType ), nil
567+ return i .encodeForStream (data , eventType ), nil
568568}
569569
570570// https://docs.anthropic.com/en/docs/build-with-claude/streaming#basic-streaming-request
571- func (s * StreamingInterception ) pingPayload () []byte {
572- return s .encodeForStream ([]byte (`{"type": "ping"}` ), "ping" )
571+ func (i * StreamingInterception ) pingPayload () []byte {
572+ return i .encodeForStream ([]byte (`{"type": "ping"}` ), "ping" )
573573}
574574
575- func (s * StreamingInterception ) encodeForStream (payload []byte , typ string ) []byte {
575+ func (* StreamingInterception ) encodeForStream (payload []byte , typ string ) []byte {
576576 var buf bytes.Buffer
577577 buf .WriteString ("event: " )
578578 buf .WriteString (typ )
@@ -584,9 +584,9 @@ func (s *StreamingInterception) encodeForStream(payload []byte, typ string) []by
584584}
585585
586586// newStream traces svc.NewStreaming() call.
587- func (s * StreamingInterception ) newStream (ctx context.Context , svc anthropic.MessageService ) * ssestream.Stream [anthropic.MessageStreamEventUnion ] {
588- _ , span := s .tracer .Start (ctx , "Intercept.ProcessRequest.Upstream" , trace .WithAttributes (tracing .InterceptionAttributesFromContext (ctx )... ))
587+ func (i * StreamingInterception ) newStream (ctx context.Context , svc anthropic.MessageService ) * ssestream.Stream [anthropic.MessageStreamEventUnion ] {
588+ _ , span := i .tracer .Start (ctx , "Intercept.ProcessRequest.Upstream" , trace .WithAttributes (tracing .InterceptionAttributesFromContext (ctx )... ))
589589 defer span .End ()
590590
591- return svc .NewStreaming (ctx , anthropic.MessageNewParams {}, s .withBody ())
591+ return svc .NewStreaming (ctx , anthropic.MessageNewParams {}, i .withBody ())
592592}
0 commit comments