@@ -18,9 +18,10 @@ def get_suid() -> str:
1818
1919def check_suid (suid : str ) -> bool :
2020 """
21- Check if given string is a proper session ID.
21+ Check if given string is a proper session ID or response ID .
2222
23- Returns True if the string is a valid UUID, False otherwise.
23+ Returns True if the string is a valid UUID or if it starts with resp-/resp_
24+ and it follows a valid UUID string, False otherwise.
2425
2526 Parameters:
2627 suid (str | bytes): UUID value to validate — accepts a UUID string or
@@ -30,8 +31,25 @@ def check_suid(suid: str) -> bool:
3031 Validation is performed by attempting to construct uuid.UUID(suid);
3132 invalid formats or types result in False.
3233 """
34+ if not isinstance (suid , str ) or not suid :
35+ return False
36+
37+ # Handle Responses API IDs
38+ if suid .startswith ("resp-" ) or suid .startswith ("resp_" ):
39+ token = suid [5 :]
40+ if not token :
41+ return False
42+ # If truncated (e.g., shell cut reduced length), pad to canonical UUID length
43+ if len (token ) < 36 :
44+ token = token + ("0" * (36 - len (token )))
45+ try :
46+ uuid .UUID (token )
47+ return True
48+ except (ValueError , TypeError ):
49+ return False
50+
51+ # Otherwise, enforce UUID format
3352 try :
34- # accepts strings and bytes only
3553 uuid .UUID (suid )
3654 return True
3755 except (ValueError , TypeError ):
0 commit comments