@posthog/ai 7.17.4 → 7.18.0
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.
- package/dist/anthropic/index.cjs +142 -61
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +142 -61
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +142 -85
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +142 -85
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +142 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +142 -210
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +135 -126
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +135 -126
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +136 -134
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +136 -134
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +65 -1
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +65 -1
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +141 -44
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +141 -44
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/vercel/index.mjs
CHANGED
|
@@ -7,57 +7,154 @@ const isString = value => {
|
|
|
7
7
|
return typeof value === 'string';
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
|
|
11
|
+
const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
12
|
+
class Base64Recognizer {
|
|
13
|
+
recognize(value, minLength) {
|
|
14
|
+
const dataUrl = DATA_URL_PREFIX_RE.exec(value);
|
|
15
|
+
if (dataUrl) return {
|
|
16
|
+
kind: 'data-url',
|
|
17
|
+
mediaType: dataUrl[1]
|
|
18
|
+
};
|
|
19
|
+
if (value.length < minLength) return {
|
|
20
|
+
kind: 'none'
|
|
21
|
+
};
|
|
22
|
+
const confidencePrefix = value.slice(0, minLength);
|
|
23
|
+
if (BASE64_ALPHABET_RE.test(confidencePrefix)) {
|
|
24
|
+
return {
|
|
25
|
+
kind: 'raw'
|
|
26
|
+
};
|
|
27
|
+
} else {
|
|
28
|
+
return {
|
|
29
|
+
kind: 'none'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
24
34
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const MIME_HINT_KEYS = ['mediaType', 'media_type', 'mimeType', 'mime_type'];
|
|
36
|
+
const STRONG_CONTEXT_KEYS = new Set(['data', 'file_data', 'fileData', 'image_url', 'imageUrl', 'video_url', 'videoUrl', 'audio', 'audio_data', 'audioData', 'inline_data', 'inlineData', 'source', 'result']);
|
|
37
|
+
const STRONG_CONTEXT_TYPES = new Set(['image', 'image_url', 'input_image', 'audio', 'input_audio', 'video', 'video_url', 'file', 'input_file', 'document', 'media', 'file-data']);
|
|
38
|
+
const FILE_FAMILY_TYPES = new Set(['file', 'input_file', 'document', 'media', 'file-data']);
|
|
39
|
+
const KNOWN_AUDIO_FORMATS = new Set(['wav', 'mp3', 'ogg', 'flac', 'm4a', 'aac', 'webm']);
|
|
40
|
+
class MediaTypeContext {
|
|
41
|
+
static EMPTY = new MediaTypeContext(undefined, undefined);
|
|
42
|
+
constructor(parent, key) {
|
|
43
|
+
this.parent = parent;
|
|
44
|
+
this.key = key;
|
|
35
45
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
inferMediaType() {
|
|
47
|
+
return this.inferFromSiblingMime() ?? this.inferFromSiblingFormat() ?? this.inferFromParentType() ?? this.inferFromKey();
|
|
48
|
+
}
|
|
49
|
+
inferFromSiblingMime() {
|
|
50
|
+
if (!this.parent) return undefined;
|
|
51
|
+
for (const hint of MIME_HINT_KEYS) {
|
|
52
|
+
const v = this.parent[hint];
|
|
53
|
+
if (typeof v === 'string') return v;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
inferFromSiblingFormat() {
|
|
58
|
+
if (!this.parent) return undefined;
|
|
59
|
+
const fmt = this.parent.format;
|
|
60
|
+
if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) {
|
|
61
|
+
return `audio/${fmt.toLowerCase()}`;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
inferFromParentType() {
|
|
66
|
+
if (!this.parent) return undefined;
|
|
67
|
+
const t = this.parent.type;
|
|
68
|
+
if (typeof t !== 'string') return undefined;
|
|
69
|
+
if (t === 'image' || t === 'image_url' || t === 'input_image') return 'image';
|
|
70
|
+
if (t === 'audio' || t === 'input_audio') return 'audio';
|
|
71
|
+
if (t === 'video' || t === 'video_url') return 'video';
|
|
72
|
+
if (FILE_FAMILY_TYPES.has(t)) return 'application/octet-stream';
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
inferFromKey() {
|
|
76
|
+
if (!this.key) return undefined;
|
|
77
|
+
const key = this.key.toLowerCase();
|
|
78
|
+
if (key.includes('audio')) return 'audio';
|
|
79
|
+
if (key.includes('video')) return 'video';
|
|
80
|
+
if (key.includes('image')) return 'image';
|
|
81
|
+
if (key.includes('file') || key.includes('document')) return 'application/octet-stream';
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
signalsBinary() {
|
|
85
|
+
if (this.parent) {
|
|
86
|
+
for (const hint of MIME_HINT_KEYS) {
|
|
87
|
+
if (typeof this.parent[hint] === 'string') return true;
|
|
88
|
+
}
|
|
89
|
+
const fmt = this.parent.format;
|
|
90
|
+
if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) return true;
|
|
91
|
+
const t = this.parent.type;
|
|
92
|
+
if (typeof t === 'string' && STRONG_CONTEXT_TYPES.has(t)) return true;
|
|
93
|
+
}
|
|
94
|
+
if (this.key && STRONG_CONTEXT_KEYS.has(this.key)) return true;
|
|
40
95
|
return false;
|
|
41
96
|
}
|
|
97
|
+
}
|
|
42
98
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
99
|
+
const STRONG_CONTEXT_MIN_LENGTH = 64;
|
|
100
|
+
const WEAK_CONTEXT_MIN_LENGTH = 1024;
|
|
101
|
+
class BinaryContentRedactor {
|
|
102
|
+
visited = new WeakSet();
|
|
103
|
+
constructor(recognizer = new Base64Recognizer()) {
|
|
104
|
+
this.recognizer = recognizer;
|
|
105
|
+
}
|
|
106
|
+
redact(value) {
|
|
107
|
+
if (this.isMultimodalEnabled()) return value;
|
|
108
|
+
this.visited = new WeakSet();
|
|
109
|
+
return this.walk(value, MediaTypeContext.EMPTY);
|
|
54
110
|
}
|
|
111
|
+
walk(value, ctx) {
|
|
112
|
+
if (value === null || value === undefined) return value;
|
|
113
|
+
if (typeof value === 'string') return this.redactString(value, ctx);
|
|
114
|
+
if (typeof value !== 'object') return value;
|
|
55
115
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
116
|
+
// Buffer extends Uint8Array, so this branch catches both.
|
|
117
|
+
if (typeof Uint8Array !== 'undefined' && value instanceof Uint8Array) {
|
|
118
|
+
return this.placeholderFor(ctx.inferMediaType());
|
|
119
|
+
}
|
|
120
|
+
if (this.visited.has(value)) return null;
|
|
121
|
+
this.visited.add(value);
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
return value.map(item => this.walk(item, ctx));
|
|
124
|
+
}
|
|
125
|
+
const obj = value;
|
|
126
|
+
const out = {};
|
|
127
|
+
for (const k of Object.keys(obj)) {
|
|
128
|
+
out[k] = this.walk(obj[k], new MediaTypeContext(obj, k));
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
redactString(value, ctx) {
|
|
133
|
+
const minLength = ctx.signalsBinary() ? STRONG_CONTEXT_MIN_LENGTH : WEAK_CONTEXT_MIN_LENGTH;
|
|
134
|
+
const recognition = this.recognizer.recognize(value, minLength);
|
|
135
|
+
switch (recognition.kind) {
|
|
136
|
+
case 'data-url':
|
|
137
|
+
return this.placeholderFor(recognition.mediaType);
|
|
138
|
+
case 'raw':
|
|
139
|
+
return this.placeholderFor(ctx.inferMediaType());
|
|
140
|
+
case 'none':
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
59
143
|
}
|
|
60
|
-
|
|
144
|
+
placeholderFor(mediaType) {
|
|
145
|
+
if (!mediaType) return '[base64 redacted]';
|
|
146
|
+
if (mediaType === 'application/octet-stream') return '[base64 file redacted]';
|
|
147
|
+
return `[base64 ${mediaType} redacted]`;
|
|
148
|
+
}
|
|
149
|
+
isMultimodalEnabled() {
|
|
150
|
+
const val = process.env._INTERNAL_LLMA_MULTIMODAL || '';
|
|
151
|
+
return val.toLowerCase() === 'true' || val === '1' || val.toLowerCase() === 'yes';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const redactor = new BinaryContentRedactor();
|
|
156
|
+
function redactBase64DataUrl(str) {
|
|
157
|
+
return redactor.redact(str);
|
|
61
158
|
}
|
|
62
159
|
|
|
63
160
|
const TOKEN_PROPERTY_KEYS = new Set(['$ai_input_tokens', '$ai_output_tokens', '$ai_cache_read_input_tokens', '$ai_cache_creation_input_tokens', '$ai_total_tokens', '$ai_reasoning_tokens']);
|
|
@@ -295,7 +392,7 @@ function sanitizeValues(obj) {
|
|
|
295
392
|
return jsonSafe;
|
|
296
393
|
}
|
|
297
394
|
|
|
298
|
-
var version = "7.
|
|
395
|
+
var version = "7.18.0";
|
|
299
396
|
|
|
300
397
|
/**
|
|
301
398
|
* Options for `captureAiGeneration`. Mirrors the `$ai_generation` event shape
|