@posthog/ai 7.1.0 → 7.1.1
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/LICENSE +56 -2
- package/dist/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/gemini/index.cjs +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/index.cjs +18 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +18 -10
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +18 -10
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +18 -10
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1 -1
- package/dist/openai/index.mjs +1 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +5 -4
package/LICENSE
CHANGED
|
@@ -219,7 +219,7 @@ limitations under the License.
|
|
|
219
219
|
|
|
220
220
|
---
|
|
221
221
|
|
|
222
|
-
Some files in this codebase contain code from getsentry/sentry-javascript by Software, Inc. dba Sentry.
|
|
222
|
+
Some files in this codebase contain code from getsentry/sentry-javascript or getsentry/sentry-react-native by Software, Inc. dba Sentry.
|
|
223
223
|
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
224
224
|
|
|
225
225
|
MIT License
|
|
@@ -242,4 +242,58 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
242
242
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
243
243
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
244
244
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
245
|
-
SOFTWARE.
|
|
245
|
+
SOFTWARE.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
|
|
250
|
+
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
251
|
+
|
|
252
|
+
MIT License
|
|
253
|
+
|
|
254
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
255
|
+
|
|
256
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
257
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
258
|
+
in the Software without restriction, including without limitation the rights
|
|
259
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
260
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
261
|
+
furnished to do so, subject to the following conditions:
|
|
262
|
+
|
|
263
|
+
The above copyright notice and this permission notice shall be included in all
|
|
264
|
+
copies or substantial portions of the Software.
|
|
265
|
+
|
|
266
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
267
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
268
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
269
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
270
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
271
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
272
|
+
SOFTWARE.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
|
|
277
|
+
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
278
|
+
|
|
279
|
+
The MIT License (MIT)
|
|
280
|
+
|
|
281
|
+
Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
|
|
282
|
+
|
|
283
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
284
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
285
|
+
in the Software without restriction, including without limitation the rights
|
|
286
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
287
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
288
|
+
furnished to do so, subject to the following conditions:
|
|
289
|
+
|
|
290
|
+
The above copyright notice and this permission notice shall be included in all
|
|
291
|
+
copies or substantial portions of the Software.
|
|
292
|
+
|
|
293
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
294
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
295
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
296
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
297
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
298
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
299
|
+
SOFTWARE.
|
package/dist/anthropic/index.cjs
CHANGED
package/dist/anthropic/index.mjs
CHANGED
package/dist/gemini/index.cjs
CHANGED
package/dist/gemini/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
26
|
|
|
27
27
|
var uuid__namespace = /*#__PURE__*/_interopNamespaceDefault(uuid);
|
|
28
28
|
|
|
29
|
-
var version = "7.1.
|
|
29
|
+
var version = "7.1.1";
|
|
30
30
|
|
|
31
31
|
// Type guards for safer type checking
|
|
32
32
|
const isString = value => {
|
|
@@ -3731,7 +3731,7 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
3731
3731
|
eventProperties['$ai_is_error'] = true;
|
|
3732
3732
|
} else {
|
|
3733
3733
|
// Handle token usage
|
|
3734
|
-
const [inputTokens, outputTokens, additionalTokenData] = this.parseUsage(output);
|
|
3734
|
+
const [inputTokens, outputTokens, additionalTokenData] = this.parseUsage(output, run.provider, run.model);
|
|
3735
3735
|
eventProperties['$ai_input_tokens'] = inputTokens;
|
|
3736
3736
|
eventProperties['$ai_output_tokens'] = outputTokens;
|
|
3737
3737
|
// Add additional token data to properties
|
|
@@ -3878,7 +3878,7 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
3878
3878
|
// Sanitize the message content to redact base64 images
|
|
3879
3879
|
return sanitizeLangChain(messageDict);
|
|
3880
3880
|
}
|
|
3881
|
-
_parseUsageModel(usage) {
|
|
3881
|
+
_parseUsageModel(usage, provider, model) {
|
|
3882
3882
|
const conversionList = [['promptTokens', 'input'], ['completionTokens', 'output'], ['input_tokens', 'input'], ['output_tokens', 'output'], ['prompt_token_count', 'input'], ['candidates_token_count', 'output'], ['inputTokenCount', 'input'], ['outputTokenCount', 'output'], ['input_token_count', 'input'], ['generated_token_count', 'output']];
|
|
3883
3883
|
const parsedUsage = conversionList.reduce((acc, [modelKey, typeKey]) => {
|
|
3884
3884
|
const value = usage[modelKey];
|
|
@@ -3945,20 +3945,28 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
3945
3945
|
if (webSearchCount !== undefined) {
|
|
3946
3946
|
additionalTokenData.webSearchCount = webSearchCount;
|
|
3947
3947
|
}
|
|
3948
|
-
//
|
|
3949
|
-
// Our cost calculation expects them to be separate
|
|
3950
|
-
|
|
3948
|
+
// For Anthropic providers, LangChain reports input_tokens as the sum of input and cache read tokens.
|
|
3949
|
+
// Our cost calculation expects them to be separate for Anthropic, so we subtract cache tokens.
|
|
3950
|
+
// For other providers (OpenAI, etc.), input_tokens already excludes cache tokens as expected.
|
|
3951
|
+
// Match logic consistent with plugin-server: exact match on provider OR substring match on model
|
|
3952
|
+
let isAnthropic = false;
|
|
3953
|
+
if (provider && provider.toLowerCase() === 'anthropic') {
|
|
3954
|
+
isAnthropic = true;
|
|
3955
|
+
} else if (model && model.toLowerCase().includes('anthropic')) {
|
|
3956
|
+
isAnthropic = true;
|
|
3957
|
+
}
|
|
3958
|
+
if (isAnthropic && parsedUsage.input && additionalTokenData.cacheReadInputTokens) {
|
|
3951
3959
|
parsedUsage.input = Math.max(parsedUsage.input - additionalTokenData.cacheReadInputTokens, 0);
|
|
3952
3960
|
}
|
|
3953
3961
|
return [parsedUsage.input, parsedUsage.output, additionalTokenData];
|
|
3954
3962
|
}
|
|
3955
|
-
parseUsage(response) {
|
|
3963
|
+
parseUsage(response, provider, model) {
|
|
3956
3964
|
let llmUsage = [0, 0, {}];
|
|
3957
3965
|
const llmUsageKeys = ['token_usage', 'usage', 'tokenUsage'];
|
|
3958
3966
|
if (response.llmOutput != null) {
|
|
3959
3967
|
const key = llmUsageKeys.find(k => response.llmOutput?.[k] != null);
|
|
3960
3968
|
if (key) {
|
|
3961
|
-
llmUsage = this._parseUsageModel(response.llmOutput[key]);
|
|
3969
|
+
llmUsage = this._parseUsageModel(response.llmOutput[key], provider, model);
|
|
3962
3970
|
}
|
|
3963
3971
|
}
|
|
3964
3972
|
// If top-level usage info was not found, try checking the generations.
|
|
@@ -3967,14 +3975,14 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
3967
3975
|
for (const genChunk of generation) {
|
|
3968
3976
|
// Check other paths for usage information
|
|
3969
3977
|
if (genChunk.generationInfo?.usage_metadata) {
|
|
3970
|
-
llmUsage = this._parseUsageModel(genChunk.generationInfo.usage_metadata);
|
|
3978
|
+
llmUsage = this._parseUsageModel(genChunk.generationInfo.usage_metadata, provider, model);
|
|
3971
3979
|
return llmUsage;
|
|
3972
3980
|
}
|
|
3973
3981
|
const messageChunk = genChunk.generationInfo ?? {};
|
|
3974
3982
|
const responseMetadata = messageChunk.response_metadata ?? {};
|
|
3975
3983
|
const chunkUsage = responseMetadata['usage'] ?? responseMetadata['amazon-bedrock-invocationMetrics'] ?? messageChunk.usage_metadata;
|
|
3976
3984
|
if (chunkUsage) {
|
|
3977
|
-
llmUsage = this._parseUsageModel(chunkUsage);
|
|
3985
|
+
llmUsage = this._parseUsageModel(chunkUsage, provider, model);
|
|
3978
3986
|
return llmUsage;
|
|
3979
3987
|
}
|
|
3980
3988
|
}
|