@databuddy/sdk 2.3.26 → 2.3.28
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/ai/vercel/index.d.mts +3 -12
- package/dist/ai/vercel/index.d.ts +3 -12
- package/dist/ai/vercel/index.mjs +2 -17
- package/dist/core/index.mjs +1 -1
- package/dist/node/index.d.mts +4 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.mjs +29 -11
- package/dist/react/index.mjs +1 -1
- package/dist/shared/@databuddy/{sdk.ClnhxS25.mjs → sdk.urY7MmVr.mjs} +1 -1
- package/dist/vue/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -124,15 +124,10 @@ interface DatabuddyLLMOptions {
|
|
|
124
124
|
*/
|
|
125
125
|
apiUrl?: string;
|
|
126
126
|
/**
|
|
127
|
-
* API key for authentication
|
|
127
|
+
* API key for authentication (determines owner - org or user)
|
|
128
128
|
* @default process.env.DATABUDDY_API_KEY
|
|
129
129
|
*/
|
|
130
130
|
apiKey?: string;
|
|
131
|
-
/**
|
|
132
|
-
* Client/Website ID for tracking
|
|
133
|
-
* @default process.env.DATABUDDY_CLIENT_ID
|
|
134
|
-
*/
|
|
135
|
-
clientId?: string;
|
|
136
131
|
/**
|
|
137
132
|
* Custom transport function to send log entries
|
|
138
133
|
* If provided, overrides default HTTP transport
|
|
@@ -175,10 +170,6 @@ interface TrackOptions {
|
|
|
175
170
|
* Trace ID to link related calls together
|
|
176
171
|
*/
|
|
177
172
|
traceId?: string;
|
|
178
|
-
/**
|
|
179
|
-
* Client ID for this specific call (overrides instance-level clientId)
|
|
180
|
-
*/
|
|
181
|
-
clientId?: string;
|
|
182
173
|
/**
|
|
183
174
|
* Whether to compute costs using TokenLens
|
|
184
175
|
* @default true
|
|
@@ -207,11 +198,11 @@ interface TrackOptions {
|
|
|
207
198
|
* import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
|
|
208
199
|
*
|
|
209
200
|
* const { track } = databuddyLLM({
|
|
210
|
-
* transport: httpTransport("https://api.example.com/ai-logs", "
|
|
201
|
+
* transport: httpTransport("https://api.example.com/ai-logs", "api-key"),
|
|
211
202
|
* });
|
|
212
203
|
* ```
|
|
213
204
|
*/
|
|
214
|
-
declare const httpTransport: (url: string,
|
|
205
|
+
declare const httpTransport: (url: string, apiKey?: string) => Transport;
|
|
215
206
|
|
|
216
207
|
/**
|
|
217
208
|
* Vercel AI SDK middleware for Databuddy
|
|
@@ -124,15 +124,10 @@ interface DatabuddyLLMOptions {
|
|
|
124
124
|
*/
|
|
125
125
|
apiUrl?: string;
|
|
126
126
|
/**
|
|
127
|
-
* API key for authentication
|
|
127
|
+
* API key for authentication (determines owner - org or user)
|
|
128
128
|
* @default process.env.DATABUDDY_API_KEY
|
|
129
129
|
*/
|
|
130
130
|
apiKey?: string;
|
|
131
|
-
/**
|
|
132
|
-
* Client/Website ID for tracking
|
|
133
|
-
* @default process.env.DATABUDDY_CLIENT_ID
|
|
134
|
-
*/
|
|
135
|
-
clientId?: string;
|
|
136
131
|
/**
|
|
137
132
|
* Custom transport function to send log entries
|
|
138
133
|
* If provided, overrides default HTTP transport
|
|
@@ -175,10 +170,6 @@ interface TrackOptions {
|
|
|
175
170
|
* Trace ID to link related calls together
|
|
176
171
|
*/
|
|
177
172
|
traceId?: string;
|
|
178
|
-
/**
|
|
179
|
-
* Client ID for this specific call (overrides instance-level clientId)
|
|
180
|
-
*/
|
|
181
|
-
clientId?: string;
|
|
182
173
|
/**
|
|
183
174
|
* Whether to compute costs using TokenLens
|
|
184
175
|
* @default true
|
|
@@ -207,11 +198,11 @@ interface TrackOptions {
|
|
|
207
198
|
* import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
|
|
208
199
|
*
|
|
209
200
|
* const { track } = databuddyLLM({
|
|
210
|
-
* transport: httpTransport("https://api.example.com/ai-logs", "
|
|
201
|
+
* transport: httpTransport("https://api.example.com/ai-logs", "api-key"),
|
|
211
202
|
* });
|
|
212
203
|
* ```
|
|
213
204
|
*/
|
|
214
|
-
declare const httpTransport: (url: string,
|
|
205
|
+
declare const httpTransport: (url: string, apiKey?: string) => Transport;
|
|
215
206
|
|
|
216
207
|
/**
|
|
217
208
|
* Vercel AI SDK middleware for Databuddy
|
package/dist/ai/vercel/index.mjs
CHANGED
|
@@ -349,7 +349,7 @@ const buildStreamOutput = (generatedText, reasoningText, toolCalls, sources = []
|
|
|
349
349
|
];
|
|
350
350
|
};
|
|
351
351
|
|
|
352
|
-
const createDefaultTransport = (apiUrl,
|
|
352
|
+
const createDefaultTransport = (apiUrl, apiKey) => {
|
|
353
353
|
return async (call) => {
|
|
354
354
|
const headers = {
|
|
355
355
|
"Content-Type": "application/json"
|
|
@@ -357,9 +357,6 @@ const createDefaultTransport = (apiUrl, clientId, apiKey) => {
|
|
|
357
357
|
if (apiKey) {
|
|
358
358
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
359
359
|
}
|
|
360
|
-
if (clientId) {
|
|
361
|
-
headers["databuddy-client-id"] = clientId;
|
|
362
|
-
}
|
|
363
360
|
const response = await fetch(apiUrl, {
|
|
364
361
|
method: "POST",
|
|
365
362
|
headers,
|
|
@@ -372,7 +369,7 @@ const createDefaultTransport = (apiUrl, clientId, apiKey) => {
|
|
|
372
369
|
}
|
|
373
370
|
};
|
|
374
371
|
};
|
|
375
|
-
const httpTransport = (url,
|
|
372
|
+
const httpTransport = (url, apiKey) => {
|
|
376
373
|
return async (call) => {
|
|
377
374
|
const headers = {
|
|
378
375
|
"Content-Type": "application/json"
|
|
@@ -380,9 +377,6 @@ const httpTransport = (url, clientId, apiKey) => {
|
|
|
380
377
|
if (apiKey) {
|
|
381
378
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
382
379
|
}
|
|
383
|
-
if (clientId) {
|
|
384
|
-
headers["databuddy-client-id"] = clientId;
|
|
385
|
-
}
|
|
386
380
|
const response = await fetch(url, {
|
|
387
381
|
method: "POST",
|
|
388
382
|
headers,
|
|
@@ -430,7 +424,6 @@ const databuddyLLM = (options = {}) => {
|
|
|
430
424
|
const {
|
|
431
425
|
apiUrl,
|
|
432
426
|
apiKey,
|
|
433
|
-
clientId,
|
|
434
427
|
transport: customTransport,
|
|
435
428
|
computeCosts: defaultComputeCosts = true,
|
|
436
429
|
privacyMode: defaultPrivacyMode = false,
|
|
@@ -440,7 +433,6 @@ const databuddyLLM = (options = {}) => {
|
|
|
440
433
|
} = options;
|
|
441
434
|
const transport = customTransport ? customTransport : createDefaultTransport(
|
|
442
435
|
apiUrl ?? process.env.DATABUDDY_API_URL ?? "https://basket.databuddy.cc/llm",
|
|
443
|
-
clientId ?? process.env.DATABUDDY_CLIENT_ID,
|
|
444
436
|
apiKey ?? process.env.DATABUDDY_API_KEY
|
|
445
437
|
);
|
|
446
438
|
const track = (model, trackOptions = {}) => {
|
|
@@ -448,13 +440,6 @@ const databuddyLLM = (options = {}) => {
|
|
|
448
440
|
if (trackOptions.transport) {
|
|
449
441
|
return trackOptions.transport;
|
|
450
442
|
}
|
|
451
|
-
if (trackOptions.clientId && trackOptions.clientId !== clientId) {
|
|
452
|
-
return createDefaultTransport(
|
|
453
|
-
apiUrl ?? process.env.DATABUDDY_API_URL ?? "https://basket.databuddy.cc/llm",
|
|
454
|
-
trackOptions.clientId,
|
|
455
|
-
apiKey ?? process.env.DATABUDDY_API_KEY
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
443
|
return transport;
|
|
459
444
|
};
|
|
460
445
|
return Object.create(model, {
|
package/dist/core/index.mjs
CHANGED
package/dist/node/index.d.mts
CHANGED
|
@@ -234,6 +234,10 @@ declare class Databuddy {
|
|
|
234
234
|
* ```
|
|
235
235
|
*/
|
|
236
236
|
track(event: CustomEventInput): Promise<EventResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
|
|
239
|
+
*/
|
|
240
|
+
private toCustomEventSpan;
|
|
237
241
|
private send;
|
|
238
242
|
private scheduleFlush;
|
|
239
243
|
/**
|
package/dist/node/index.d.ts
CHANGED
|
@@ -234,6 +234,10 @@ declare class Databuddy {
|
|
|
234
234
|
* ```
|
|
235
235
|
*/
|
|
236
236
|
track(event: CustomEventInput): Promise<EventResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
|
|
239
|
+
*/
|
|
240
|
+
private toCustomEventSpan;
|
|
237
241
|
private send;
|
|
238
242
|
private scheduleFlush;
|
|
239
243
|
/**
|
package/dist/node/index.mjs
CHANGED
|
@@ -419,20 +419,35 @@ class Databuddy {
|
|
|
419
419
|
}
|
|
420
420
|
return { success: true };
|
|
421
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
|
|
424
|
+
*/
|
|
425
|
+
toCustomEventSpan(event) {
|
|
426
|
+
const timestamp = event.timestamp ? Math.floor(event.timestamp) : Date.now();
|
|
427
|
+
return {
|
|
428
|
+
timestamp,
|
|
429
|
+
path: "",
|
|
430
|
+
eventName: event.name,
|
|
431
|
+
anonymousId: event.anonymousId ?? null,
|
|
432
|
+
sessionId: event.sessionId ?? null,
|
|
433
|
+
properties: event.properties ?? null
|
|
434
|
+
};
|
|
435
|
+
}
|
|
422
436
|
async send(event) {
|
|
423
437
|
try {
|
|
424
|
-
const url = `${this.apiUrl}
|
|
438
|
+
const url = `${this.apiUrl}/events?client_id=${encodeURIComponent(this.clientId)}`;
|
|
439
|
+
const customEventSpan = this.toCustomEventSpan(event);
|
|
425
440
|
this.logger.info("\u{1F4E4} SENDING SINGLE EVENT:", {
|
|
426
|
-
|
|
427
|
-
properties: JSON.stringify(
|
|
428
|
-
propertiesCount: Object.keys(
|
|
441
|
+
eventName: customEventSpan.eventName,
|
|
442
|
+
properties: JSON.stringify(customEventSpan.properties, null, 2),
|
|
443
|
+
propertiesCount: Object.keys(customEventSpan.properties || {}).length
|
|
429
444
|
});
|
|
430
445
|
const response = await fetch(url, {
|
|
431
446
|
method: "POST",
|
|
432
447
|
headers: {
|
|
433
448
|
"Content-Type": "application/json"
|
|
434
449
|
},
|
|
435
|
-
body: JSON.stringify(
|
|
450
|
+
body: JSON.stringify([customEventSpan])
|
|
436
451
|
});
|
|
437
452
|
if (!response.ok) {
|
|
438
453
|
const errorText = await response.text().catch(() => "Unknown error");
|
|
@@ -578,17 +593,20 @@ class Databuddy {
|
|
|
578
593
|
};
|
|
579
594
|
}
|
|
580
595
|
try {
|
|
581
|
-
const url = `${this.apiUrl}/
|
|
596
|
+
const url = `${this.apiUrl}/events?client_id=${encodeURIComponent(this.clientId)}`;
|
|
597
|
+
const customEventSpans = processedEvents.map(
|
|
598
|
+
(event) => this.toCustomEventSpan(event)
|
|
599
|
+
);
|
|
582
600
|
this.logger.info("\u{1F4E6} SENDING BATCH EVENTS:", {
|
|
583
|
-
count:
|
|
584
|
-
firstEventName:
|
|
601
|
+
count: customEventSpans.length,
|
|
602
|
+
firstEventName: customEventSpans[0]?.eventName,
|
|
585
603
|
firstEventProperties: JSON.stringify(
|
|
586
|
-
|
|
604
|
+
customEventSpans[0]?.properties,
|
|
587
605
|
null,
|
|
588
606
|
2
|
|
589
607
|
),
|
|
590
608
|
firstEventPropertiesCount: Object.keys(
|
|
591
|
-
|
|
609
|
+
customEventSpans[0]?.properties || {}
|
|
592
610
|
).length
|
|
593
611
|
});
|
|
594
612
|
const response = await fetch(url, {
|
|
@@ -596,7 +614,7 @@ class Databuddy {
|
|
|
596
614
|
headers: {
|
|
597
615
|
"Content-Type": "application/json"
|
|
598
616
|
},
|
|
599
|
-
body: JSON.stringify(
|
|
617
|
+
body: JSON.stringify(customEventSpans)
|
|
600
618
|
});
|
|
601
619
|
if (!response.ok) {
|
|
602
620
|
const errorText = await response.text().catch(() => "Unknown error");
|
package/dist/react/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { detectClientId } from '../core/index.mjs';
|
|
4
4
|
export { clear, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isTrackerAvailable, track, trackError } from '../core/index.mjs';
|
|
5
|
-
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.
|
|
5
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.urY7MmVr.mjs';
|
|
6
6
|
import React, { useRef, useMemo, useEffect, useSyncExternalStore, createContext, useContext } from 'react';
|
|
7
7
|
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.DE24-JrU.mjs';
|
|
8
8
|
import { l as logger } from '../shared/@databuddy/sdk.CALvx07o.mjs';
|
package/dist/vue/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, ref, onMounted, onUnmounted, watch, reactive, watchEffect, computed } from 'vue';
|
|
2
|
-
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.
|
|
2
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.urY7MmVr.mjs';
|
|
3
3
|
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.DE24-JrU.mjs';
|
|
4
4
|
import '../shared/@databuddy/sdk.CALvx07o.mjs';
|
|
5
5
|
|