@posthog/ai 5.1.0 → 5.2.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/CHANGELOG.md +3 -1
- package/lib/anthropic/index.cjs +4 -4
- package/lib/anthropic/index.cjs.map +1 -1
- package/lib/anthropic/index.mjs +4 -4
- package/lib/anthropic/index.mjs.map +1 -1
- package/lib/gemini/index.cjs +364 -0
- package/lib/gemini/index.cjs.map +1 -0
- package/lib/gemini/index.d.ts +60 -0
- package/lib/gemini/index.mjs +357 -0
- package/lib/gemini/index.mjs.map +1 -0
- package/lib/index.cjs +33 -33
- package/lib/index.cjs.map +1 -1
- package/lib/index.mjs +33 -33
- package/lib/index.mjs.map +1 -1
- package/lib/openai/index.cjs +10 -10
- package/lib/openai/index.cjs.map +1 -1
- package/lib/openai/index.mjs +10 -10
- package/lib/openai/index.mjs.map +1 -1
- package/lib/vercel/index.cjs +5 -5
- package/lib/vercel/index.cjs.map +1 -1
- package/lib/vercel/index.mjs +5 -5
- package/lib/vercel/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/anthropic/index.ts +4 -4
- package/src/gemini/index.ts +4 -4
- package/src/openai/azure.ts +10 -10
- package/src/openai/index.ts +10 -10
- package/src/vercel/middleware.ts +7 -7
- package/tests/gemini.test.ts +31 -0
- package/tests/openai.test.ts +31 -0
package/lib/index.cjs
CHANGED
|
@@ -272,7 +272,7 @@ class WrappedCompletions$1 extends OpenAIOrignal__default["default"].Chat.Comple
|
|
|
272
272
|
const latency = (Date.now() - startTime) / 1000;
|
|
273
273
|
await sendEventToPosthog({
|
|
274
274
|
client: this.phClient,
|
|
275
|
-
distinctId: posthogDistinctId
|
|
275
|
+
distinctId: posthogDistinctId,
|
|
276
276
|
traceId,
|
|
277
277
|
model: openAIParams.model,
|
|
278
278
|
provider: 'openai',
|
|
@@ -291,7 +291,7 @@ class WrappedCompletions$1 extends OpenAIOrignal__default["default"].Chat.Comple
|
|
|
291
291
|
} catch (error) {
|
|
292
292
|
await sendEventToPosthog({
|
|
293
293
|
client: this.phClient,
|
|
294
|
-
distinctId: posthogDistinctId
|
|
294
|
+
distinctId: posthogDistinctId,
|
|
295
295
|
traceId,
|
|
296
296
|
model: openAIParams.model,
|
|
297
297
|
provider: 'openai',
|
|
@@ -322,7 +322,7 @@ class WrappedCompletions$1 extends OpenAIOrignal__default["default"].Chat.Comple
|
|
|
322
322
|
const latency = (Date.now() - startTime) / 1000;
|
|
323
323
|
await sendEventToPosthog({
|
|
324
324
|
client: this.phClient,
|
|
325
|
-
distinctId: posthogDistinctId
|
|
325
|
+
distinctId: posthogDistinctId,
|
|
326
326
|
traceId,
|
|
327
327
|
model: openAIParams.model,
|
|
328
328
|
provider: 'openai',
|
|
@@ -345,7 +345,7 @@ class WrappedCompletions$1 extends OpenAIOrignal__default["default"].Chat.Comple
|
|
|
345
345
|
}, async error => {
|
|
346
346
|
await sendEventToPosthog({
|
|
347
347
|
client: this.phClient,
|
|
348
|
-
distinctId: posthogDistinctId
|
|
348
|
+
distinctId: posthogDistinctId,
|
|
349
349
|
traceId,
|
|
350
350
|
model: openAIParams.model,
|
|
351
351
|
provider: 'openai',
|
|
@@ -416,7 +416,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
416
416
|
const latency = (Date.now() - startTime) / 1000;
|
|
417
417
|
await sendEventToPosthog({
|
|
418
418
|
client: this.phClient,
|
|
419
|
-
distinctId: posthogDistinctId
|
|
419
|
+
distinctId: posthogDistinctId,
|
|
420
420
|
traceId,
|
|
421
421
|
model: openAIParams.model,
|
|
422
422
|
provider: 'openai',
|
|
@@ -432,7 +432,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
432
432
|
} catch (error) {
|
|
433
433
|
await sendEventToPosthog({
|
|
434
434
|
client: this.phClient,
|
|
435
|
-
distinctId: posthogDistinctId
|
|
435
|
+
distinctId: posthogDistinctId,
|
|
436
436
|
traceId,
|
|
437
437
|
model: openAIParams.model,
|
|
438
438
|
provider: 'openai',
|
|
@@ -462,7 +462,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
462
462
|
const latency = (Date.now() - startTime) / 1000;
|
|
463
463
|
await sendEventToPosthog({
|
|
464
464
|
client: this.phClient,
|
|
465
|
-
distinctId: posthogDistinctId
|
|
465
|
+
distinctId: posthogDistinctId,
|
|
466
466
|
traceId,
|
|
467
467
|
model: openAIParams.model,
|
|
468
468
|
provider: 'openai',
|
|
@@ -485,7 +485,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
485
485
|
}, async error => {
|
|
486
486
|
await sendEventToPosthog({
|
|
487
487
|
client: this.phClient,
|
|
488
|
-
distinctId: posthogDistinctId
|
|
488
|
+
distinctId: posthogDistinctId,
|
|
489
489
|
traceId,
|
|
490
490
|
model: openAIParams.model,
|
|
491
491
|
provider: 'openai',
|
|
@@ -532,7 +532,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
532
532
|
const latency = (Date.now() - startTime) / 1000;
|
|
533
533
|
await sendEventToPosthog({
|
|
534
534
|
client: this.phClient,
|
|
535
|
-
distinctId: posthogDistinctId
|
|
535
|
+
distinctId: posthogDistinctId,
|
|
536
536
|
traceId,
|
|
537
537
|
model: openAIParams.model,
|
|
538
538
|
provider: 'openai',
|
|
@@ -554,7 +554,7 @@ class WrappedResponses$1 extends OpenAIOrignal__default["default"].Responses {
|
|
|
554
554
|
}, async error => {
|
|
555
555
|
await sendEventToPosthog({
|
|
556
556
|
client: this.phClient,
|
|
557
|
-
distinctId: posthogDistinctId
|
|
557
|
+
distinctId: posthogDistinctId,
|
|
558
558
|
traceId,
|
|
559
559
|
model: openAIParams.model,
|
|
560
560
|
provider: 'openai',
|
|
@@ -645,7 +645,7 @@ class WrappedCompletions extends OpenAIOrignal.AzureOpenAI.Chat.Completions {
|
|
|
645
645
|
const latency = (Date.now() - startTime) / 1000;
|
|
646
646
|
await sendEventToPosthog({
|
|
647
647
|
client: this.phClient,
|
|
648
|
-
distinctId: posthogDistinctId
|
|
648
|
+
distinctId: posthogDistinctId,
|
|
649
649
|
traceId,
|
|
650
650
|
model: openAIParams.model,
|
|
651
651
|
provider: 'azure',
|
|
@@ -664,7 +664,7 @@ class WrappedCompletions extends OpenAIOrignal.AzureOpenAI.Chat.Completions {
|
|
|
664
664
|
} catch (error) {
|
|
665
665
|
await sendEventToPosthog({
|
|
666
666
|
client: this.phClient,
|
|
667
|
-
distinctId: posthogDistinctId
|
|
667
|
+
distinctId: posthogDistinctId,
|
|
668
668
|
traceId,
|
|
669
669
|
model: openAIParams.model,
|
|
670
670
|
provider: 'azure',
|
|
@@ -695,7 +695,7 @@ class WrappedCompletions extends OpenAIOrignal.AzureOpenAI.Chat.Completions {
|
|
|
695
695
|
const latency = (Date.now() - startTime) / 1000;
|
|
696
696
|
await sendEventToPosthog({
|
|
697
697
|
client: this.phClient,
|
|
698
|
-
distinctId: posthogDistinctId
|
|
698
|
+
distinctId: posthogDistinctId,
|
|
699
699
|
traceId,
|
|
700
700
|
model: openAIParams.model,
|
|
701
701
|
provider: 'azure',
|
|
@@ -718,7 +718,7 @@ class WrappedCompletions extends OpenAIOrignal.AzureOpenAI.Chat.Completions {
|
|
|
718
718
|
}, async error => {
|
|
719
719
|
await sendEventToPosthog({
|
|
720
720
|
client: this.phClient,
|
|
721
|
-
distinctId: posthogDistinctId
|
|
721
|
+
distinctId: posthogDistinctId,
|
|
722
722
|
traceId,
|
|
723
723
|
model: openAIParams.model,
|
|
724
724
|
provider: 'azure',
|
|
@@ -789,7 +789,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
789
789
|
const latency = (Date.now() - startTime) / 1000;
|
|
790
790
|
await sendEventToPosthog({
|
|
791
791
|
client: this.phClient,
|
|
792
|
-
distinctId: posthogDistinctId
|
|
792
|
+
distinctId: posthogDistinctId,
|
|
793
793
|
traceId,
|
|
794
794
|
model: openAIParams.model,
|
|
795
795
|
provider: 'azure',
|
|
@@ -805,7 +805,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
805
805
|
} catch (error) {
|
|
806
806
|
await sendEventToPosthog({
|
|
807
807
|
client: this.phClient,
|
|
808
|
-
distinctId: posthogDistinctId
|
|
808
|
+
distinctId: posthogDistinctId,
|
|
809
809
|
traceId,
|
|
810
810
|
model: openAIParams.model,
|
|
811
811
|
provider: 'azure',
|
|
@@ -835,7 +835,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
835
835
|
const latency = (Date.now() - startTime) / 1000;
|
|
836
836
|
await sendEventToPosthog({
|
|
837
837
|
client: this.phClient,
|
|
838
|
-
distinctId: posthogDistinctId
|
|
838
|
+
distinctId: posthogDistinctId,
|
|
839
839
|
traceId,
|
|
840
840
|
model: openAIParams.model,
|
|
841
841
|
provider: 'azure',
|
|
@@ -858,7 +858,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
858
858
|
}, async error => {
|
|
859
859
|
await sendEventToPosthog({
|
|
860
860
|
client: this.phClient,
|
|
861
|
-
distinctId: posthogDistinctId
|
|
861
|
+
distinctId: posthogDistinctId,
|
|
862
862
|
traceId,
|
|
863
863
|
model: openAIParams.model,
|
|
864
864
|
provider: 'azure',
|
|
@@ -899,7 +899,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
899
899
|
const latency = (Date.now() - startTime) / 1000;
|
|
900
900
|
await sendEventToPosthog({
|
|
901
901
|
client: this.phClient,
|
|
902
|
-
distinctId: posthogDistinctId
|
|
902
|
+
distinctId: posthogDistinctId,
|
|
903
903
|
traceId,
|
|
904
904
|
model: openAIParams.model,
|
|
905
905
|
provider: 'azure',
|
|
@@ -921,7 +921,7 @@ class WrappedResponses extends OpenAIOrignal.AzureOpenAI.Responses {
|
|
|
921
921
|
}, async error => {
|
|
922
922
|
await sendEventToPosthog({
|
|
923
923
|
client: this.phClient,
|
|
924
|
-
distinctId: posthogDistinctId
|
|
924
|
+
distinctId: posthogDistinctId,
|
|
925
925
|
traceId,
|
|
926
926
|
model: openAIParams.model,
|
|
927
927
|
provider: 'azure',
|
|
@@ -1154,7 +1154,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1154
1154
|
await sendEventToPosthog({
|
|
1155
1155
|
client: phClient,
|
|
1156
1156
|
distinctId: options.posthogDistinctId,
|
|
1157
|
-
traceId: options.posthogTraceId,
|
|
1157
|
+
traceId: options.posthogTraceId ?? uuid.v4(),
|
|
1158
1158
|
model: modelId,
|
|
1159
1159
|
provider: provider,
|
|
1160
1160
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1179,7 +1179,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1179
1179
|
await sendEventToPosthog({
|
|
1180
1180
|
client: phClient,
|
|
1181
1181
|
distinctId: options.posthogDistinctId,
|
|
1182
|
-
traceId: options.posthogTraceId,
|
|
1182
|
+
traceId: options.posthogTraceId ?? uuid.v4(),
|
|
1183
1183
|
model: modelId,
|
|
1184
1184
|
provider: model.provider,
|
|
1185
1185
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1248,7 +1248,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1248
1248
|
await sendEventToPosthog({
|
|
1249
1249
|
client: phClient,
|
|
1250
1250
|
distinctId: options.posthogDistinctId,
|
|
1251
|
-
traceId: options.posthogTraceId,
|
|
1251
|
+
traceId: options.posthogTraceId ?? uuid.v4(),
|
|
1252
1252
|
model: modelId,
|
|
1253
1253
|
provider: provider,
|
|
1254
1254
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1273,7 +1273,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1273
1273
|
await sendEventToPosthog({
|
|
1274
1274
|
client: phClient,
|
|
1275
1275
|
distinctId: options.posthogDistinctId,
|
|
1276
|
-
traceId: options.posthogTraceId,
|
|
1276
|
+
traceId: options.posthogTraceId ?? uuid.v4(),
|
|
1277
1277
|
model: modelId,
|
|
1278
1278
|
provider: provider,
|
|
1279
1279
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1301,7 +1301,7 @@ const wrapVercelLanguageModel = (model, phClient, options) => {
|
|
|
1301
1301
|
const middleware = createInstrumentationMiddleware(phClient, model, {
|
|
1302
1302
|
...options,
|
|
1303
1303
|
posthogTraceId: traceId,
|
|
1304
|
-
posthogDistinctId: options.posthogDistinctId
|
|
1304
|
+
posthogDistinctId: options.posthogDistinctId
|
|
1305
1305
|
});
|
|
1306
1306
|
const wrappedModel = ai.experimental_wrapLanguageModel({
|
|
1307
1307
|
model,
|
|
@@ -1372,7 +1372,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
|
|
|
1372
1372
|
const latency = (Date.now() - startTime) / 1000;
|
|
1373
1373
|
await sendEventToPosthog({
|
|
1374
1374
|
client: this.phClient,
|
|
1375
|
-
distinctId: posthogDistinctId
|
|
1375
|
+
distinctId: posthogDistinctId,
|
|
1376
1376
|
traceId,
|
|
1377
1377
|
model: anthropicParams.model,
|
|
1378
1378
|
provider: 'anthropic',
|
|
@@ -1392,7 +1392,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
|
|
|
1392
1392
|
// error handling
|
|
1393
1393
|
await sendEventToPosthog({
|
|
1394
1394
|
client: this.phClient,
|
|
1395
|
-
distinctId: posthogDistinctId
|
|
1395
|
+
distinctId: posthogDistinctId,
|
|
1396
1396
|
traceId,
|
|
1397
1397
|
model: anthropicParams.model,
|
|
1398
1398
|
provider: 'anthropic',
|
|
@@ -1423,7 +1423,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
|
|
|
1423
1423
|
const latency = (Date.now() - startTime) / 1000;
|
|
1424
1424
|
await sendEventToPosthog({
|
|
1425
1425
|
client: this.phClient,
|
|
1426
|
-
distinctId: posthogDistinctId
|
|
1426
|
+
distinctId: posthogDistinctId,
|
|
1427
1427
|
traceId,
|
|
1428
1428
|
model: anthropicParams.model,
|
|
1429
1429
|
provider: 'anthropic',
|
|
@@ -1446,7 +1446,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
|
|
|
1446
1446
|
}, async error => {
|
|
1447
1447
|
await sendEventToPosthog({
|
|
1448
1448
|
client: this.phClient,
|
|
1449
|
-
distinctId: posthogDistinctId
|
|
1449
|
+
distinctId: posthogDistinctId,
|
|
1450
1450
|
traceId,
|
|
1451
1451
|
model: anthropicParams.model,
|
|
1452
1452
|
provider: 'anthropic',
|
|
@@ -1503,7 +1503,7 @@ class WrappedModels {
|
|
|
1503
1503
|
const latency = (Date.now() - startTime) / 1000;
|
|
1504
1504
|
await sendEventToPosthog({
|
|
1505
1505
|
client: this.phClient,
|
|
1506
|
-
distinctId: posthogDistinctId
|
|
1506
|
+
distinctId: posthogDistinctId,
|
|
1507
1507
|
traceId,
|
|
1508
1508
|
model: geminiParams.model,
|
|
1509
1509
|
provider: 'gemini',
|
|
@@ -1524,7 +1524,7 @@ class WrappedModels {
|
|
|
1524
1524
|
const latency = (Date.now() - startTime) / 1000;
|
|
1525
1525
|
await sendEventToPosthog({
|
|
1526
1526
|
client: this.phClient,
|
|
1527
|
-
distinctId: posthogDistinctId
|
|
1527
|
+
distinctId: posthogDistinctId,
|
|
1528
1528
|
traceId,
|
|
1529
1529
|
model: geminiParams.model,
|
|
1530
1530
|
provider: 'gemini',
|
|
@@ -1578,7 +1578,7 @@ class WrappedModels {
|
|
|
1578
1578
|
const latency = (Date.now() - startTime) / 1000;
|
|
1579
1579
|
await sendEventToPosthog({
|
|
1580
1580
|
client: this.phClient,
|
|
1581
|
-
distinctId: posthogDistinctId
|
|
1581
|
+
distinctId: posthogDistinctId,
|
|
1582
1582
|
traceId,
|
|
1583
1583
|
model: geminiParams.model,
|
|
1584
1584
|
provider: 'gemini',
|
|
@@ -1598,7 +1598,7 @@ class WrappedModels {
|
|
|
1598
1598
|
const latency = (Date.now() - startTime) / 1000;
|
|
1599
1599
|
await sendEventToPosthog({
|
|
1600
1600
|
client: this.phClient,
|
|
1601
|
-
distinctId: posthogDistinctId
|
|
1601
|
+
distinctId: posthogDistinctId,
|
|
1602
1602
|
traceId,
|
|
1603
1603
|
model: geminiParams.model,
|
|
1604
1604
|
provider: 'gemini',
|