29
29
from rich .text import Text
30
30
import sys
31
31
import time
32
- from typing import Any , Iterator , Optional , cast
32
+ from typing import Any , Iterator , Optional , Sequence , cast
33
33
34
34
from parlant .client import ParlantClient
35
35
from parlant .client .core import ApiError
@@ -848,9 +848,7 @@ def delete_tag(ctx: click.Context, tag_id: str) -> None:
848
848
client .tags .delete (tag_id = tag_id )
849
849
850
850
@staticmethod
851
- def stream_logs (
852
- ctx : click .Context , filters : list [str ], operator : str
853
- ) -> Iterator [dict [str , Any ]]:
851
+ def stream_logs (ctx : click .Context , filters : list [str ]) -> Iterator [dict [str , Any ]]:
854
852
try :
855
853
context = zmq .Context .instance ()
856
854
sub_socket = context .socket (zmq .SUB )
@@ -863,7 +861,7 @@ def stream_logs(
863
861
while True :
864
862
try :
865
863
message = cast (dict [str , Any ], sub_socket .recv_json (flags = zmq .NOBLOCK ))
866
- if Actions ._log_matches_filters (message , filters , operator ):
864
+ if Actions ._log_matches_filters (message , filters ):
867
865
yield message
868
866
except zmq .Again :
869
867
time .sleep (0.01 )
@@ -873,19 +871,14 @@ def stream_logs(
873
871
sub_socket .close ()
874
872
875
873
@staticmethod
876
- def _log_matches_filters (log_entry : dict [str , Any ], filters : list [str ], operator : str ) -> bool :
874
+ def _log_matches_filters (log_entry : dict [str , Any ], filters : list [str ]) -> bool :
877
875
message = log_entry .get ("message" , "" )
878
876
matches_filters = []
879
877
880
878
for filter_item in filters :
881
879
matches_filters .append (filter_item in message )
882
880
883
- if operator == "AND" :
884
- filter_match = all (matches_filters )
885
- else :
886
- filter_match = any (matches_filters )
887
-
888
- return filter_match
881
+ return any (matches_filters ) if matches_filters else True
889
882
890
883
891
884
def raise_for_status_with_detail (response : requests .Response ) -> None :
@@ -2011,10 +2004,9 @@ def delete_tag(ctx: click.Context, tag_id: str) -> None:
2011
2004
def stream_logs (
2012
2005
ctx : click .Context ,
2013
2006
filters : list [str ],
2014
- operator : str ,
2015
2007
) -> None :
2016
2008
try :
2017
- for log in Actions .stream_logs (ctx , filters , operator ):
2009
+ for log in Actions .stream_logs (ctx , filters ):
2018
2010
level = log .get ("level" , "" )
2019
2011
message = log .get ("message" , "" )
2020
2012
correlation_id = log .get ("correlation_id" , "" )
@@ -3120,23 +3112,14 @@ def tag_delete(ctx: click.Context, id: str) -> None:
3120
3112
is_flag = True ,
3121
3113
help = "Filter logs by [MessageEventGenerator]" ,
3122
3114
)
3123
- @click .option (
3124
- "--operator" ,
3125
- "-o" ,
3126
- type = click .Choice (["AND" , "OR" ], case_sensitive = False ),
3127
- default = "OR" ,
3128
- show_default = True ,
3129
- help = "Logical operator to combine filters" ,
3130
- )
3131
- @click .argument ("pattern" , required = False )
3115
+ @click .argument ("patterns" , nargs = - 1 , required = False )
3132
3116
@click .pass_context
3133
3117
def log_view (
3134
3118
ctx : click .Context ,
3135
3119
guideline_proposer : bool ,
3136
3120
tool_caller : bool ,
3137
3121
message_event_generator : bool ,
3138
- operator : str ,
3139
- pattern : Optional [str ],
3122
+ patterns : Optional [Sequence [str ]],
3140
3123
) -> None :
3141
3124
filters = []
3142
3125
if guideline_proposer :
@@ -3145,10 +3128,10 @@ def log_view(
3145
3128
filters .append ("[ToolCaller]" )
3146
3129
if message_event_generator :
3147
3130
filters .append ("[MessageEventGenerator]" )
3148
- if pattern :
3149
- filters .append ( pattern )
3131
+ if patterns :
3132
+ filters .extend ( patterns )
3150
3133
3151
- Interface .stream_logs (ctx , filters , operator )
3134
+ Interface .stream_logs (ctx , filters )
3152
3135
3153
3136
@cli .command (
3154
3137
"help" ,
0 commit comments