@posthog/ai 8.6.4 → 8.6.5

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.
@@ -43,14 +43,16 @@ const FILE_FAMILY_TYPES = new Set(['file', 'input_file', 'document', 'media', 'f
43
43
  const KNOWN_AUDIO_FORMATS = new Set(['wav', 'mp3', 'ogg', 'flac', 'm4a', 'aac', 'webm']);
44
44
  class MediaTypeContext {
45
45
  static EMPTY = new MediaTypeContext(undefined, undefined);
46
- constructor(parent, key) {
46
+ constructor(parent, key, explicitMediaType) {
47
47
  this.parent = parent;
48
48
  this.key = key;
49
+ this.explicitMediaType = explicitMediaType;
49
50
  }
50
51
  inferMediaType() {
51
52
  return this.inferFromSiblingMime() ?? this.inferFromSiblingFormat() ?? this.inferFromParentType() ?? this.inferFromKey();
52
53
  }
53
54
  inferFromSiblingMime() {
55
+ if (this.explicitMediaType) return this.explicitMediaType;
54
56
  if (!this.parent) return undefined;
55
57
  for (const hint of MIME_HINT_KEYS) {
56
58
  const v = this.parent[hint];
@@ -85,7 +87,13 @@ class MediaTypeContext {
85
87
  if (key.includes('file') || key.includes('document')) return 'application/octet-stream';
86
88
  return undefined;
87
89
  }
90
+ hasExplicitBinaryMediaType() {
91
+ if (!this.explicitMediaType && (!this.parent || !this.key || !STRONG_CONTEXT_KEYS.has(this.key))) return false;
92
+ const mediaType = this.inferFromSiblingMime();
93
+ return mediaType !== undefined && !mediaType.toLowerCase().startsWith('text/');
94
+ }
88
95
  signalsBinary() {
96
+ if (this.explicitMediaType) return true;
89
97
  if (this.parent) {
90
98
  for (const hint of MIME_HINT_KEYS) {
91
99
  if (typeof this.parent[hint] === 'string') return true;
@@ -107,10 +115,10 @@ class BinaryContentRedactor {
107
115
  constructor(recognizer = new Base64Recognizer()) {
108
116
  this.recognizer = recognizer;
109
117
  }
110
- redact(value) {
118
+ redact(value, mediaType) {
111
119
  if (this.isMultimodalEnabled()) return value;
112
120
  this.visited = new WeakSet();
113
- return this.walk(value, MediaTypeContext.EMPTY);
121
+ return this.walk(value, mediaType ? new MediaTypeContext(undefined, undefined, mediaType) : MediaTypeContext.EMPTY);
114
122
  }
115
123
  walk(value, ctx) {
116
124
  if (value === null || value === undefined) return value;
@@ -134,8 +142,10 @@ class BinaryContentRedactor {
134
142
  return out;
135
143
  }
136
144
  redactString(value, ctx) {
137
- const minLength = ctx.signalsBinary() ? STRONG_CONTEXT_MIN_LENGTH : WEAK_CONTEXT_MIN_LENGTH;
138
- const recognition = this.recognizer.recognize(value, minLength);
145
+ const hasExplicitBinaryMediaType = ctx.hasExplicitBinaryMediaType();
146
+ const recognitionValue = hasExplicitBinaryMediaType ? value.replace(/[\r\n]/g, '') : value;
147
+ const minLength = hasExplicitBinaryMediaType ? Math.min(recognitionValue.length, STRONG_CONTEXT_MIN_LENGTH) : ctx.signalsBinary() ? STRONG_CONTEXT_MIN_LENGTH : WEAK_CONTEXT_MIN_LENGTH;
148
+ const recognition = this.recognizer.recognize(recognitionValue, minLength);
139
149
  switch (recognition.kind) {
140
150
  case 'data-url':
141
151
  return this.placeholderFor(recognition.mediaType);
@@ -300,7 +310,7 @@ function addDefaults(params) {
300
310
  };
301
311
  }
302
312
 
303
- var version = "8.6.4";
313
+ var version = "8.6.5";
304
314
 
305
315
  const DEFAULT_MAX_DEPTH = 3;
306
316
  const MAX_STACK_LINES = 20;