@posthog/ai 8.7.1 → 8.8.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 +36 -13
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +36 -13
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +36 -13
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +36 -13
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +60 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +60 -35
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +27 -13
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +27 -13
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +66 -43
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +66 -43
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +25 -4
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +25 -4
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.cjs +1 -5
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +1 -5
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +67 -35
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +67 -35
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/anthropic/index.cjs
CHANGED
|
@@ -11,6 +11,33 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
11
11
|
|
|
12
12
|
var AnthropicOriginal__default = /*#__PURE__*/_interopDefault(AnthropicOriginal);
|
|
13
13
|
|
|
14
|
+
/** @internal */
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
function isFullAiCaptureEnabled(client) {
|
|
20
|
+
return client?.enableFullAiCapture === true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
function captureAiEvent(client, event) {
|
|
25
|
+
if (isFullAiCaptureEnabled(client) && typeof client.captureAi === 'function') {
|
|
26
|
+
client.captureAi(event);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
client.capture(event);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
async function captureAiEventImmediate(client, event) {
|
|
34
|
+
if (isFullAiCaptureEnabled(client) && typeof client.captureAiImmediate === 'function') {
|
|
35
|
+
await client.captureAiImmediate(event);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await client.captureImmediate(event);
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
|
|
15
42
|
const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
16
43
|
class Base64Recognizer {
|
|
@@ -116,7 +143,6 @@ class BinaryContentRedactor {
|
|
|
116
143
|
this.recognizer = recognizer;
|
|
117
144
|
}
|
|
118
145
|
redact(value, mediaType) {
|
|
119
|
-
if (this.isMultimodalEnabled()) return value;
|
|
120
146
|
this.visited = new WeakSet();
|
|
121
147
|
return this.walk(value, mediaType ? new MediaTypeContext(undefined, undefined, mediaType) : MediaTypeContext.EMPTY);
|
|
122
148
|
}
|
|
@@ -160,14 +186,11 @@ class BinaryContentRedactor {
|
|
|
160
186
|
if (mediaType === 'application/octet-stream') return '[base64 file redacted]';
|
|
161
187
|
return `[base64 ${mediaType} redacted]`;
|
|
162
188
|
}
|
|
163
|
-
isMultimodalEnabled() {
|
|
164
|
-
const val = process.env._INTERNAL_LLMA_MULTIMODAL || '';
|
|
165
|
-
return val.toLowerCase() === 'true' || val === '1' || val.toLowerCase() === 'yes';
|
|
166
|
-
}
|
|
167
189
|
}
|
|
168
190
|
|
|
169
191
|
const redactor = new BinaryContentRedactor();
|
|
170
|
-
const
|
|
192
|
+
const sanitize = (data, client) => isFullAiCaptureEnabled(client) ? data : redactor.redact(data);
|
|
193
|
+
const sanitizeAnthropic = (data, client) => sanitize(data, client);
|
|
171
194
|
|
|
172
195
|
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']);
|
|
173
196
|
|
|
@@ -315,7 +338,7 @@ function addDefaults(params) {
|
|
|
315
338
|
};
|
|
316
339
|
}
|
|
317
340
|
|
|
318
|
-
var version = "8.
|
|
341
|
+
var version = "8.8.0";
|
|
319
342
|
|
|
320
343
|
const DEFAULT_MAX_DEPTH = 3;
|
|
321
344
|
const MAX_STACK_LINES = 20;
|
|
@@ -564,9 +587,9 @@ const captureAiGeneration = async (client, options) => {
|
|
|
564
587
|
groups: options.groups
|
|
565
588
|
};
|
|
566
589
|
if (options.captureImmediate) {
|
|
567
|
-
await client
|
|
590
|
+
await captureAiEventImmediate(client, event);
|
|
568
591
|
} else {
|
|
569
|
-
client
|
|
592
|
+
captureAiEvent(client, event);
|
|
570
593
|
}
|
|
571
594
|
} catch (error) {
|
|
572
595
|
// Telemetry failures must never affect the instrumented provider call.
|
|
@@ -1027,7 +1050,7 @@ class WrappedMessages extends AnthropicOriginal__default.default.Messages {
|
|
|
1027
1050
|
...posthogParams,
|
|
1028
1051
|
model: anthropicParams.model,
|
|
1029
1052
|
provider: 'anthropic',
|
|
1030
|
-
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams, 'anthropic')),
|
|
1053
|
+
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams, 'anthropic'), this.phClient),
|
|
1031
1054
|
output: formattedOutput,
|
|
1032
1055
|
latency,
|
|
1033
1056
|
timeToFirstToken,
|
|
@@ -1043,7 +1066,7 @@ class WrappedMessages extends AnthropicOriginal__default.default.Messages {
|
|
|
1043
1066
|
...posthogParams,
|
|
1044
1067
|
model: anthropicParams.model,
|
|
1045
1068
|
provider: 'anthropic',
|
|
1046
|
-
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams)),
|
|
1069
|
+
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams), this.phClient),
|
|
1047
1070
|
output: [],
|
|
1048
1071
|
latency: 0,
|
|
1049
1072
|
baseURL: this.baseURL,
|
|
@@ -1079,7 +1102,7 @@ class WrappedMessages extends AnthropicOriginal__default.default.Messages {
|
|
|
1079
1102
|
...posthogParams,
|
|
1080
1103
|
model: anthropicParams.model,
|
|
1081
1104
|
provider: 'anthropic',
|
|
1082
|
-
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams)),
|
|
1105
|
+
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams), this.phClient),
|
|
1083
1106
|
output: formatResponseAnthropic(result),
|
|
1084
1107
|
latency,
|
|
1085
1108
|
baseURL: this.baseURL,
|
|
@@ -1103,7 +1126,7 @@ class WrappedMessages extends AnthropicOriginal__default.default.Messages {
|
|
|
1103
1126
|
...posthogParams,
|
|
1104
1127
|
model: anthropicParams.model,
|
|
1105
1128
|
provider: 'anthropic',
|
|
1106
|
-
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams)),
|
|
1129
|
+
input: sanitizeAnthropic(mergeSystemPrompt(anthropicParams), this.phClient),
|
|
1107
1130
|
output: [],
|
|
1108
1131
|
latency: 0,
|
|
1109
1132
|
baseURL: this.baseURL,
|