@posthog/ai 8.6.4 → 8.6.6
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 +19 -7
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +19 -7
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +22 -10
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +22 -10
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +38 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +38 -32
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +16 -6
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +16 -6
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +402 -51
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.ts +13 -1
- package/dist/openai/index.mjs +402 -51
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +10 -2
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +10 -2
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.cjs +15 -5
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +15 -5
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +38 -32
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +38 -32
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/anthropic/index.cjs
CHANGED
|
@@ -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
|
|
138
|
-
const
|
|
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.
|
|
313
|
+
var version = "8.6.6";
|
|
304
314
|
|
|
305
315
|
const DEFAULT_MAX_DEPTH = 3;
|
|
306
316
|
const MAX_STACK_LINES = 20;
|
|
@@ -498,7 +508,9 @@ const captureAiGeneration = async (client, options) => {
|
|
|
498
508
|
$ai_output_tokens: usage.outputTokens
|
|
499
509
|
} : {}),
|
|
500
510
|
...additionalTokenValues,
|
|
501
|
-
|
|
511
|
+
...(options.latency !== undefined ? {
|
|
512
|
+
$ai_latency: options.latency
|
|
513
|
+
} : {}),
|
|
502
514
|
...(options.timeToFirstToken !== undefined ? {
|
|
503
515
|
$ai_time_to_first_token: options.timeToFirstToken
|
|
504
516
|
} : {}),
|