@posthog/ai 8.6.0 → 8.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { AzureOpenAI, OpenAI } from 'openai';
2
2
  import { v4 } from 'uuid';
3
- import { uuidv7 } from '@posthog/core';
3
+ import { toJsonSafeValue, uuidv7 } from '@posthog/core';
4
4
 
5
5
  // Type guards for safer type checking
6
6
 
@@ -533,7 +533,7 @@ function formatOpenAIResponsesInput(input, instructions) {
533
533
  return messages;
534
534
  }
535
535
 
536
- var version = "8.6.0";
536
+ var version = "8.6.2";
537
537
 
538
538
  const DEFAULT_MAX_DEPTH = 3;
539
539
  const MAX_STACK_LINES = 20;
@@ -652,8 +652,13 @@ const captureAiGeneration$1 = async (client, options) => {
652
652
  const eventType = options.eventType ?? AIEvent.Generation;
653
653
  const privacyMode = options.privacyMode ?? false;
654
654
  const usage = options.usage ?? {};
655
- const safeInput = sanitizeValues(options.input);
656
- const safeOutput = sanitizeValues(options.output);
655
+
656
+ // Check privacy before reading or traversing input/output. Besides avoiding
657
+ // needless work, this ensures hostile getters/proxies cannot observe a value
658
+ // that the caller explicitly requested us to redact.
659
+ const shouldRedact = withPrivacyMode(client, privacyMode, false) === null;
660
+ const safeInput = shouldRedact ? null : toJsonSafeValue(options.input);
661
+ const safeOutput = shouldRedact ? null : toJsonSafeValue(options.output);
657
662
  let httpStatus = options.httpStatus;
658
663
  let errorData = {};
659
664
  if (options.error) {
@@ -714,8 +719,8 @@ const captureAiGeneration$1 = async (client, options) => {
714
719
  $ai_provider: options.providerOverride ?? options.provider,
715
720
  $ai_model: options.modelOverride ?? options.model,
716
721
  $ai_model_parameters: options.modelParameters ?? {},
717
- $ai_input: withPrivacyMode(client, privacyMode, safeInput),
718
- $ai_output_choices: withPrivacyMode(client, privacyMode, safeOutput),
722
+ $ai_input: safeInput,
723
+ $ai_output_choices: safeOutput,
719
724
  $ai_http_status: httpStatus,
720
725
  $ai_input_tokens: usage.inputTokens ?? 0,
721
726
  ...(usage.outputTokens !== undefined ? {