@@ -71,7 +71,7 @@ private function logRequest(
7171 RequestContext $ context ,
7272 ): void {
7373 // Determine effective privacy level
74- $ privacyLevel = $ this ->resolvePrivacyLevel ($ configuration );
74+ $ privacyLevel = $ this ->resolvePrivacyLevel ($ configuration, $ request );
7575 if ($ privacyLevel === PrivacyLevel::None) {
7676 return ;
7777 }
@@ -165,23 +165,28 @@ private function logRequest(
165165 }
166166
167167 /**
168- * Resolve the effective privacy level from the provider config and user TSconfig.
169- * The stricter of the two wins.
168+ * Resolve the effective privacy level from provider config, user TSconfig,
169+ * and any per-request override carried on the request. The strictest of
170+ * the three wins — an override can only escalate, never relax.
170171 */
171- private function resolvePrivacyLevel (ProviderConfiguration $ configuration ): PrivacyLevel
172+ private function resolvePrivacyLevel (ProviderConfiguration $ configuration, AiRequestInterface $ request ): PrivacyLevel
172173 {
173- $ configLevel = PrivacyLevel::fromString ($ configuration ->privacyLevel );
174+ $ level = PrivacyLevel::fromString ($ configuration ->privacyLevel );
174175
175176 $ user = $ this ->getBackendUser ();
176- if ($ user === null || !method_exists ($ user , 'getTSConfig ' )) {
177- return $ configLevel ;
177+ if ($ user !== null && method_exists ($ user , 'getTSConfig ' )) {
178+ $ userLevel = PrivacyLevel::fromString (
179+ (string )($ user ->getTSConfig ()['aim. ' ]['privacyLevel ' ] ?? 'standard ' )
180+ );
181+ $ level = $ level ->strictest ($ userLevel );
178182 }
179183
180- $ userLevel = PrivacyLevel::fromString (
181- (string )($ user ->getTSConfig ()['aim. ' ]['privacyLevel ' ] ?? 'standard ' )
182- );
184+ $ requestOverride = $ request ->getPrivacyLevelOverride ();
185+ if ($ requestOverride !== null ) {
186+ $ level = $ level ->strictest ($ requestOverride );
187+ }
183188
184- return $ configLevel -> strictest ( $ userLevel ) ;
189+ return $ level ;
185190 }
186191
187192 private function extractMetadata (AiRequestInterface $ request ): array
0 commit comments