@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.mjs
CHANGED
|
@@ -245,7 +245,7 @@ class WrappedCompletions$1 extends OpenAIOrignal.Chat.Completions {
|
|
|
245
245
|
const latency = (Date.now() - startTime) / 1000;
|
|
246
246
|
await sendEventToPosthog({
|
|
247
247
|
client: this.phClient,
|
|
248
|
-
distinctId: posthogDistinctId
|
|
248
|
+
distinctId: posthogDistinctId,
|
|
249
249
|
traceId,
|
|
250
250
|
model: openAIParams.model,
|
|
251
251
|
provider: 'openai',
|
|
@@ -264,7 +264,7 @@ class WrappedCompletions$1 extends OpenAIOrignal.Chat.Completions {
|
|
|
264
264
|
} catch (error) {
|
|
265
265
|
await sendEventToPosthog({
|
|
266
266
|
client: this.phClient,
|
|
267
|
-
distinctId: posthogDistinctId
|
|
267
|
+
distinctId: posthogDistinctId,
|
|
268
268
|
traceId,
|
|
269
269
|
model: openAIParams.model,
|
|
270
270
|
provider: 'openai',
|
|
@@ -295,7 +295,7 @@ class WrappedCompletions$1 extends OpenAIOrignal.Chat.Completions {
|
|
|
295
295
|
const latency = (Date.now() - startTime) / 1000;
|
|
296
296
|
await sendEventToPosthog({
|
|
297
297
|
client: this.phClient,
|
|
298
|
-
distinctId: posthogDistinctId
|
|
298
|
+
distinctId: posthogDistinctId,
|
|
299
299
|
traceId,
|
|
300
300
|
model: openAIParams.model,
|
|
301
301
|
provider: 'openai',
|
|
@@ -318,7 +318,7 @@ class WrappedCompletions$1 extends OpenAIOrignal.Chat.Completions {
|
|
|
318
318
|
}, async error => {
|
|
319
319
|
await sendEventToPosthog({
|
|
320
320
|
client: this.phClient,
|
|
321
|
-
distinctId: posthogDistinctId
|
|
321
|
+
distinctId: posthogDistinctId,
|
|
322
322
|
traceId,
|
|
323
323
|
model: openAIParams.model,
|
|
324
324
|
provider: 'openai',
|
|
@@ -389,7 +389,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
389
389
|
const latency = (Date.now() - startTime) / 1000;
|
|
390
390
|
await sendEventToPosthog({
|
|
391
391
|
client: this.phClient,
|
|
392
|
-
distinctId: posthogDistinctId
|
|
392
|
+
distinctId: posthogDistinctId,
|
|
393
393
|
traceId,
|
|
394
394
|
model: openAIParams.model,
|
|
395
395
|
provider: 'openai',
|
|
@@ -405,7 +405,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
405
405
|
} catch (error) {
|
|
406
406
|
await sendEventToPosthog({
|
|
407
407
|
client: this.phClient,
|
|
408
|
-
distinctId: posthogDistinctId
|
|
408
|
+
distinctId: posthogDistinctId,
|
|
409
409
|
traceId,
|
|
410
410
|
model: openAIParams.model,
|
|
411
411
|
provider: 'openai',
|
|
@@ -435,7 +435,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
435
435
|
const latency = (Date.now() - startTime) / 1000;
|
|
436
436
|
await sendEventToPosthog({
|
|
437
437
|
client: this.phClient,
|
|
438
|
-
distinctId: posthogDistinctId
|
|
438
|
+
distinctId: posthogDistinctId,
|
|
439
439
|
traceId,
|
|
440
440
|
model: openAIParams.model,
|
|
441
441
|
provider: 'openai',
|
|
@@ -458,7 +458,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
458
458
|
}, async error => {
|
|
459
459
|
await sendEventToPosthog({
|
|
460
460
|
client: this.phClient,
|
|
461
|
-
distinctId: posthogDistinctId
|
|
461
|
+
distinctId: posthogDistinctId,
|
|
462
462
|
traceId,
|
|
463
463
|
model: openAIParams.model,
|
|
464
464
|
provider: 'openai',
|
|
@@ -505,7 +505,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
505
505
|
const latency = (Date.now() - startTime) / 1000;
|
|
506
506
|
await sendEventToPosthog({
|
|
507
507
|
client: this.phClient,
|
|
508
|
-
distinctId: posthogDistinctId
|
|
508
|
+
distinctId: posthogDistinctId,
|
|
509
509
|
traceId,
|
|
510
510
|
model: openAIParams.model,
|
|
511
511
|
provider: 'openai',
|
|
@@ -527,7 +527,7 @@ class WrappedResponses$1 extends OpenAIOrignal.Responses {
|
|
|
527
527
|
}, async error => {
|
|
528
528
|
await sendEventToPosthog({
|
|
529
529
|
client: this.phClient,
|
|
530
|
-
distinctId: posthogDistinctId
|
|
530
|
+
distinctId: posthogDistinctId,
|
|
531
531
|
traceId,
|
|
532
532
|
model: openAIParams.model,
|
|
533
533
|
provider: 'openai',
|
|
@@ -618,7 +618,7 @@ class WrappedCompletions extends AzureOpenAI.Chat.Completions {
|
|
|
618
618
|
const latency = (Date.now() - startTime) / 1000;
|
|
619
619
|
await sendEventToPosthog({
|
|
620
620
|
client: this.phClient,
|
|
621
|
-
distinctId: posthogDistinctId
|
|
621
|
+
distinctId: posthogDistinctId,
|
|
622
622
|
traceId,
|
|
623
623
|
model: openAIParams.model,
|
|
624
624
|
provider: 'azure',
|
|
@@ -637,7 +637,7 @@ class WrappedCompletions extends AzureOpenAI.Chat.Completions {
|
|
|
637
637
|
} catch (error) {
|
|
638
638
|
await sendEventToPosthog({
|
|
639
639
|
client: this.phClient,
|
|
640
|
-
distinctId: posthogDistinctId
|
|
640
|
+
distinctId: posthogDistinctId,
|
|
641
641
|
traceId,
|
|
642
642
|
model: openAIParams.model,
|
|
643
643
|
provider: 'azure',
|
|
@@ -668,7 +668,7 @@ class WrappedCompletions extends AzureOpenAI.Chat.Completions {
|
|
|
668
668
|
const latency = (Date.now() - startTime) / 1000;
|
|
669
669
|
await sendEventToPosthog({
|
|
670
670
|
client: this.phClient,
|
|
671
|
-
distinctId: posthogDistinctId
|
|
671
|
+
distinctId: posthogDistinctId,
|
|
672
672
|
traceId,
|
|
673
673
|
model: openAIParams.model,
|
|
674
674
|
provider: 'azure',
|
|
@@ -691,7 +691,7 @@ class WrappedCompletions extends AzureOpenAI.Chat.Completions {
|
|
|
691
691
|
}, async error => {
|
|
692
692
|
await sendEventToPosthog({
|
|
693
693
|
client: this.phClient,
|
|
694
|
-
distinctId: posthogDistinctId
|
|
694
|
+
distinctId: posthogDistinctId,
|
|
695
695
|
traceId,
|
|
696
696
|
model: openAIParams.model,
|
|
697
697
|
provider: 'azure',
|
|
@@ -762,7 +762,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
762
762
|
const latency = (Date.now() - startTime) / 1000;
|
|
763
763
|
await sendEventToPosthog({
|
|
764
764
|
client: this.phClient,
|
|
765
|
-
distinctId: posthogDistinctId
|
|
765
|
+
distinctId: posthogDistinctId,
|
|
766
766
|
traceId,
|
|
767
767
|
model: openAIParams.model,
|
|
768
768
|
provider: 'azure',
|
|
@@ -778,7 +778,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
778
778
|
} catch (error) {
|
|
779
779
|
await sendEventToPosthog({
|
|
780
780
|
client: this.phClient,
|
|
781
|
-
distinctId: posthogDistinctId
|
|
781
|
+
distinctId: posthogDistinctId,
|
|
782
782
|
traceId,
|
|
783
783
|
model: openAIParams.model,
|
|
784
784
|
provider: 'azure',
|
|
@@ -808,7 +808,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
808
808
|
const latency = (Date.now() - startTime) / 1000;
|
|
809
809
|
await sendEventToPosthog({
|
|
810
810
|
client: this.phClient,
|
|
811
|
-
distinctId: posthogDistinctId
|
|
811
|
+
distinctId: posthogDistinctId,
|
|
812
812
|
traceId,
|
|
813
813
|
model: openAIParams.model,
|
|
814
814
|
provider: 'azure',
|
|
@@ -831,7 +831,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
831
831
|
}, async error => {
|
|
832
832
|
await sendEventToPosthog({
|
|
833
833
|
client: this.phClient,
|
|
834
|
-
distinctId: posthogDistinctId
|
|
834
|
+
distinctId: posthogDistinctId,
|
|
835
835
|
traceId,
|
|
836
836
|
model: openAIParams.model,
|
|
837
837
|
provider: 'azure',
|
|
@@ -872,7 +872,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
872
872
|
const latency = (Date.now() - startTime) / 1000;
|
|
873
873
|
await sendEventToPosthog({
|
|
874
874
|
client: this.phClient,
|
|
875
|
-
distinctId: posthogDistinctId
|
|
875
|
+
distinctId: posthogDistinctId,
|
|
876
876
|
traceId,
|
|
877
877
|
model: openAIParams.model,
|
|
878
878
|
provider: 'azure',
|
|
@@ -894,7 +894,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
894
894
|
}, async error => {
|
|
895
895
|
await sendEventToPosthog({
|
|
896
896
|
client: this.phClient,
|
|
897
|
-
distinctId: posthogDistinctId
|
|
897
|
+
distinctId: posthogDistinctId,
|
|
898
898
|
traceId,
|
|
899
899
|
model: openAIParams.model,
|
|
900
900
|
provider: 'azure',
|
|
@@ -1127,7 +1127,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1127
1127
|
await sendEventToPosthog({
|
|
1128
1128
|
client: phClient,
|
|
1129
1129
|
distinctId: options.posthogDistinctId,
|
|
1130
|
-
traceId: options.posthogTraceId,
|
|
1130
|
+
traceId: options.posthogTraceId ?? v4(),
|
|
1131
1131
|
model: modelId,
|
|
1132
1132
|
provider: provider,
|
|
1133
1133
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1152,7 +1152,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1152
1152
|
await sendEventToPosthog({
|
|
1153
1153
|
client: phClient,
|
|
1154
1154
|
distinctId: options.posthogDistinctId,
|
|
1155
|
-
traceId: options.posthogTraceId,
|
|
1155
|
+
traceId: options.posthogTraceId ?? v4(),
|
|
1156
1156
|
model: modelId,
|
|
1157
1157
|
provider: model.provider,
|
|
1158
1158
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1221,7 +1221,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1221
1221
|
await sendEventToPosthog({
|
|
1222
1222
|
client: phClient,
|
|
1223
1223
|
distinctId: options.posthogDistinctId,
|
|
1224
|
-
traceId: options.posthogTraceId,
|
|
1224
|
+
traceId: options.posthogTraceId ?? v4(),
|
|
1225
1225
|
model: modelId,
|
|
1226
1226
|
provider: provider,
|
|
1227
1227
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1246,7 +1246,7 @@ const createInstrumentationMiddleware = (phClient, model, options) => {
|
|
|
1246
1246
|
await sendEventToPosthog({
|
|
1247
1247
|
client: phClient,
|
|
1248
1248
|
distinctId: options.posthogDistinctId,
|
|
1249
|
-
traceId: options.posthogTraceId,
|
|
1249
|
+
traceId: options.posthogTraceId ?? v4(),
|
|
1250
1250
|
model: modelId,
|
|
1251
1251
|
provider: provider,
|
|
1252
1252
|
input: options.posthogPrivacyMode ? '' : mapVercelPrompt(params.prompt),
|
|
@@ -1274,7 +1274,7 @@ const wrapVercelLanguageModel = (model, phClient, options) => {
|
|
|
1274
1274
|
const middleware = createInstrumentationMiddleware(phClient, model, {
|
|
1275
1275
|
...options,
|
|
1276
1276
|
posthogTraceId: traceId,
|
|
1277
|
-
posthogDistinctId: options.posthogDistinctId
|
|
1277
|
+
posthogDistinctId: options.posthogDistinctId
|
|
1278
1278
|
});
|
|
1279
1279
|
const wrappedModel = experimental_wrapLanguageModel({
|
|
1280
1280
|
model,
|
|
@@ -1345,7 +1345,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1345
1345
|
const latency = (Date.now() - startTime) / 1000;
|
|
1346
1346
|
await sendEventToPosthog({
|
|
1347
1347
|
client: this.phClient,
|
|
1348
|
-
distinctId: posthogDistinctId
|
|
1348
|
+
distinctId: posthogDistinctId,
|
|
1349
1349
|
traceId,
|
|
1350
1350
|
model: anthropicParams.model,
|
|
1351
1351
|
provider: 'anthropic',
|
|
@@ -1365,7 +1365,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1365
1365
|
// error handling
|
|
1366
1366
|
await sendEventToPosthog({
|
|
1367
1367
|
client: this.phClient,
|
|
1368
|
-
distinctId: posthogDistinctId
|
|
1368
|
+
distinctId: posthogDistinctId,
|
|
1369
1369
|
traceId,
|
|
1370
1370
|
model: anthropicParams.model,
|
|
1371
1371
|
provider: 'anthropic',
|
|
@@ -1396,7 +1396,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1396
1396
|
const latency = (Date.now() - startTime) / 1000;
|
|
1397
1397
|
await sendEventToPosthog({
|
|
1398
1398
|
client: this.phClient,
|
|
1399
|
-
distinctId: posthogDistinctId
|
|
1399
|
+
distinctId: posthogDistinctId,
|
|
1400
1400
|
traceId,
|
|
1401
1401
|
model: anthropicParams.model,
|
|
1402
1402
|
provider: 'anthropic',
|
|
@@ -1419,7 +1419,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1419
1419
|
}, async error => {
|
|
1420
1420
|
await sendEventToPosthog({
|
|
1421
1421
|
client: this.phClient,
|
|
1422
|
-
distinctId: posthogDistinctId
|
|
1422
|
+
distinctId: posthogDistinctId,
|
|
1423
1423
|
traceId,
|
|
1424
1424
|
model: anthropicParams.model,
|
|
1425
1425
|
provider: 'anthropic',
|
|
@@ -1476,7 +1476,7 @@ class WrappedModels {
|
|
|
1476
1476
|
const latency = (Date.now() - startTime) / 1000;
|
|
1477
1477
|
await sendEventToPosthog({
|
|
1478
1478
|
client: this.phClient,
|
|
1479
|
-
distinctId: posthogDistinctId
|
|
1479
|
+
distinctId: posthogDistinctId,
|
|
1480
1480
|
traceId,
|
|
1481
1481
|
model: geminiParams.model,
|
|
1482
1482
|
provider: 'gemini',
|
|
@@ -1497,7 +1497,7 @@ class WrappedModels {
|
|
|
1497
1497
|
const latency = (Date.now() - startTime) / 1000;
|
|
1498
1498
|
await sendEventToPosthog({
|
|
1499
1499
|
client: this.phClient,
|
|
1500
|
-
distinctId: posthogDistinctId
|
|
1500
|
+
distinctId: posthogDistinctId,
|
|
1501
1501
|
traceId,
|
|
1502
1502
|
model: geminiParams.model,
|
|
1503
1503
|
provider: 'gemini',
|
|
@@ -1551,7 +1551,7 @@ class WrappedModels {
|
|
|
1551
1551
|
const latency = (Date.now() - startTime) / 1000;
|
|
1552
1552
|
await sendEventToPosthog({
|
|
1553
1553
|
client: this.phClient,
|
|
1554
|
-
distinctId: posthogDistinctId
|
|
1554
|
+
distinctId: posthogDistinctId,
|
|
1555
1555
|
traceId,
|
|
1556
1556
|
model: geminiParams.model,
|
|
1557
1557
|
provider: 'gemini',
|
|
@@ -1571,7 +1571,7 @@ class WrappedModels {
|
|
|
1571
1571
|
const latency = (Date.now() - startTime) / 1000;
|
|
1572
1572
|
await sendEventToPosthog({
|
|
1573
1573
|
client: this.phClient,
|
|
1574
|
-
distinctId: posthogDistinctId
|
|
1574
|
+
distinctId: posthogDistinctId,
|
|
1575
1575
|
traceId,
|
|
1576
1576
|
model: geminiParams.model,
|
|
1577
1577
|
provider: 'gemini',
|