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