@@ -271,7 +271,7 @@ def _redact_text(
271
271
return text_encryptor .obfuscate (text , snippet )
272
272
273
273
async def process (
274
- self , reques : Any , context : PipelineContext
274
+ self , request : Any , context : PipelineContext
275
275
) -> PipelineResult :
276
276
"""
277
277
Process the request to find and protect secrets in all messages.
@@ -498,33 +498,30 @@ async def process_chunk(
498
498
)
499
499
500
500
# Check if this is the first chunk (delta role will be present, others will not)
501
- for _ in itertools .takewhile (lambda x : x [0 ] == 1 , enumerate (chunk .get_content ())):
502
- redacted_count = input_context .metadata ["redacted_secrets_count" ]
503
- secret_text = "secret" if redacted_count == 1 else "secrets"
504
- # Create notification chunk
505
- if tool_name in ["cline" , "kodu" ]:
506
- # NOTE: Original code was ensuring that role was
507
- # "assistant" here, we might have to do that as well,
508
- # but I believe it was defensive programming or
509
- # leftover of some refactoring.
510
- notification_chunk = self ._create_chunk (
511
- chunk ,
512
- f"<thinking>\n 🛡️ [CodeGate prevented { redacted_count } { secret_text } ]"
513
- f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
514
- f"by redacting them.</thinking>\n \n " ,
515
- )
516
- else :
517
- notification_chunk = self ._create_chunk (
518
- chunk ,
519
- f"\n 🛡️ [CodeGate prevented { redacted_count } { secret_text } ]"
520
- f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
521
- f"by redacting them.\n \n " ,
522
- )
523
-
524
- # Reset the counter
525
- input_context .metadata ["redacted_secrets_count" ] = 0
501
+ redacted_count = input_context .metadata ["redacted_secrets_count" ]
502
+ secret_text = "secret" if redacted_count == 1 else "secrets"
503
+ # Create notification chunk
504
+ if tool_name in ["cline" , "kodu" ]:
505
+ # NOTE: Original code was ensuring that role was
506
+ # "assistant" here, we might have to do that as well,
507
+ # but I believe it was defensive programming or
508
+ # leftover of some refactoring.
509
+ notification_chunk = self ._create_chunk (
510
+ chunk ,
511
+ f"<thinking>\n 🛡️ [CodeGate prevented { redacted_count } { secret_text } ]"
512
+ f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
513
+ f"by redacting them.</thinking>\n \n " ,
514
+ )
515
+ else :
516
+ notification_chunk = self ._create_chunk (
517
+ chunk ,
518
+ f"\n 🛡️ [CodeGate prevented { redacted_count } { secret_text } ]"
519
+ f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
520
+ f"by redacting them.\n \n " ,
521
+ )
526
522
527
- # Return both the notification and original chunk
528
- return [ notification_chunk , chunk ]
523
+ # Reset the counter
524
+ input_context . metadata [ "redacted_secrets_count" ] = 0
529
525
530
- return [chunk ]
526
+ # Return both the notification and original chunk
527
+ return [notification_chunk , chunk ]
0 commit comments