primeorbit 0.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.
@@ -0,0 +1,697 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ EventQueue: () => EventQueue,
34
+ PrimeOrbitClient: () => PrimeOrbitClient,
35
+ getLogLevel: () => getLogLevel,
36
+ getPrimeOrbitApiUrl: () => getPrimeOrbitApiUrl,
37
+ logger: () => logger,
38
+ record_star_rating: () => record_star_rating,
39
+ record_thumbs_feedback: () => record_thumbs_feedback,
40
+ setLogLevel: () => setLogLevel,
41
+ setPrimeOrbitApiUrl: () => setPrimeOrbitApiUrl,
42
+ wrapAsyncToRecordLatency: () => wrapAsyncToRecordLatency,
43
+ wrapSyncToRecordLatency: () => wrapSyncToRecordLatency,
44
+ wrapToRecordLatency: () => wrapToRecordLatency
45
+ });
46
+ module.exports = __toCommonJS(index_exports);
47
+
48
+ // src/api_utils.ts
49
+ async function recordData(endpoint, payload, headers = { "Content-Type": "application/json" }) {
50
+ const res = await fetch(endpoint, {
51
+ method: "POST",
52
+ headers,
53
+ body: JSON.stringify(payload)
54
+ });
55
+ const text = await res.text();
56
+ let responseBody;
57
+ try {
58
+ responseBody = text ? JSON.parse(text) : null;
59
+ } catch {
60
+ responseBody = text;
61
+ }
62
+ if (!res.ok) {
63
+ throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`);
64
+ }
65
+ return responseBody;
66
+ }
67
+
68
+ // src/routes.ts
69
+ var routes = {
70
+ latencies: "/system-metrics/latencies",
71
+ "star-ratings": "/user-metrics/star-ratings",
72
+ "thumbs-feedbacks": "/user-metrics/thumbs-feedbacks",
73
+ "raw-events": "/user-metrics/raw-events",
74
+ "raw-events-batch": "/user-metrics/raw-events/batch"
75
+ };
76
+
77
+ // src/logger.ts
78
+ var LOG_LEVELS = {
79
+ debug: 0,
80
+ info: 1,
81
+ warn: 2,
82
+ error: 3,
83
+ silent: 4
84
+ };
85
+ var currentLogLevel = "info";
86
+ function setLogLevel(level) {
87
+ currentLogLevel = level;
88
+ }
89
+ function getLogLevel() {
90
+ return currentLogLevel;
91
+ }
92
+ function shouldLog(level) {
93
+ return LOG_LEVELS[level] >= LOG_LEVELS[currentLogLevel];
94
+ }
95
+ function formatMessage(level, message) {
96
+ return `[PrimeOrbit ${level.toUpperCase()}] ${message}`;
97
+ }
98
+ var logger = {
99
+ /**
100
+ * Log a debug message. Only shown when log level is 'debug'.
101
+ */
102
+ debug(message, ...args) {
103
+ if (shouldLog("debug")) {
104
+ console.debug(formatMessage("debug", message), ...args);
105
+ }
106
+ },
107
+ /**
108
+ * Log an informational message.
109
+ */
110
+ info(message, ...args) {
111
+ if (shouldLog("info")) {
112
+ console.info(formatMessage("info", message), ...args);
113
+ }
114
+ },
115
+ /**
116
+ * Log a warning message.
117
+ */
118
+ warn(message, ...args) {
119
+ if (shouldLog("warn")) {
120
+ console.warn(formatMessage("warn", message), ...args);
121
+ }
122
+ },
123
+ /**
124
+ * Log an error message.
125
+ */
126
+ error(message, ...args) {
127
+ if (shouldLog("error")) {
128
+ console.error(formatMessage("error", message), ...args);
129
+ }
130
+ }
131
+ };
132
+
133
+ // src/system_metrics/measure_latency.ts
134
+ function recordLatency(startTime, agentId, actionId, actionFailed) {
135
+ const endTime = performance.now();
136
+ const latency = Math.floor(endTime - startTime);
137
+ recordData(routes["latencies"], {
138
+ agent_id: agentId,
139
+ latency,
140
+ action_id: actionId,
141
+ action_failed: actionFailed
142
+ }).catch((err) => {
143
+ const message = err instanceof Error ? err.message : String(err);
144
+ logger.error(`Failed to record latency: ${message}`);
145
+ });
146
+ }
147
+ function isPromise(value) {
148
+ if (value === null || typeof value !== "object") {
149
+ return false;
150
+ }
151
+ const obj = value;
152
+ return "then" in obj && typeof obj["then"] === "function";
153
+ }
154
+ function wrapSyncToRecordLatency(fn, agentId, actionId) {
155
+ const resolvedActionId = actionId ?? fn.name;
156
+ return function(...args) {
157
+ const start = performance.now();
158
+ let failed = true;
159
+ try {
160
+ const result = fn.apply(this, args);
161
+ failed = false;
162
+ recordLatency(start, agentId, resolvedActionId, failed);
163
+ return result;
164
+ } catch (err) {
165
+ recordLatency(start, agentId, resolvedActionId, failed);
166
+ throw err;
167
+ }
168
+ };
169
+ }
170
+ function wrapAsyncToRecordLatency(fn, agentId, actionId) {
171
+ const resolvedActionId = actionId ?? fn.name;
172
+ return async function(...args) {
173
+ const start = performance.now();
174
+ let failed = true;
175
+ try {
176
+ const result = await fn.apply(this, args);
177
+ failed = false;
178
+ recordLatency(start, agentId, resolvedActionId, failed);
179
+ return result;
180
+ } catch (err) {
181
+ recordLatency(start, agentId, resolvedActionId, failed);
182
+ throw err;
183
+ }
184
+ };
185
+ }
186
+ function wrapToRecordLatency(fn, agentId, actionId) {
187
+ const resolvedActionId = actionId ?? fn.name;
188
+ return function(...args) {
189
+ const start = performance.now();
190
+ let failed = true;
191
+ try {
192
+ const result = fn.apply(this, args);
193
+ if (isPromise(result)) {
194
+ return result.then((res) => {
195
+ failed = false;
196
+ recordLatency(start, agentId, resolvedActionId, failed);
197
+ return res;
198
+ }).catch((err) => {
199
+ recordLatency(start, agentId, resolvedActionId, failed);
200
+ throw err;
201
+ });
202
+ }
203
+ failed = false;
204
+ recordLatency(start, agentId, resolvedActionId, failed);
205
+ return result;
206
+ } catch (err) {
207
+ recordLatency(start, agentId, resolvedActionId, failed);
208
+ throw err;
209
+ }
210
+ };
211
+ }
212
+
213
+ // src/config.ts
214
+ var baseApiUrl;
215
+ function setPrimeOrbitApiUrl(url) {
216
+ baseApiUrl = url;
217
+ }
218
+ function getPrimeOrbitApiUrl() {
219
+ if (!baseApiUrl) {
220
+ throw new Error(
221
+ `PrimeOrbit API URL is not set. Please call 'setPrimeOrbitApiUrl(<url>)' before using the SDK.`
222
+ );
223
+ }
224
+ return baseApiUrl;
225
+ }
226
+
227
+ // src/user_metrics/record_star_rating.ts
228
+ async function record_star_rating(agentId, rating, taskName, userId = "") {
229
+ try {
230
+ const payload = {
231
+ agent_id: agentId,
232
+ rating,
233
+ task_name: taskName
234
+ };
235
+ if (userId) {
236
+ payload["user_id"] = userId;
237
+ }
238
+ await recordData(routes["star-ratings"], payload);
239
+ } catch (err) {
240
+ const message = err instanceof Error ? err.message : String(err);
241
+ logger.error(`recordData failed: ${message}`);
242
+ }
243
+ }
244
+
245
+ // src/user_metrics/record_thumbs_feedback.ts
246
+ async function record_thumbs_feedback(agentId, isThumbsUp, taskName, userId = "") {
247
+ try {
248
+ const payload = {
249
+ agent_id: agentId,
250
+ is_thumbs_up: isThumbsUp,
251
+ task_name: taskName
252
+ };
253
+ if (userId) {
254
+ payload["user_id"] = userId;
255
+ }
256
+ await recordData(routes["thumbs-feedbacks"], payload);
257
+ } catch (err) {
258
+ const message = err instanceof Error ? err.message : String(err);
259
+ logger.error(`Failed to record thumbs feedback: ${message}`);
260
+ }
261
+ }
262
+
263
+ // src/event_queue.ts
264
+ var EventQueue = class {
265
+ queue = [];
266
+ batchSize;
267
+ flushIntervalMs;
268
+ maxConcurrentRequests;
269
+ maxRetries;
270
+ retryBaseDelayMs;
271
+ maxQueueSize;
272
+ onEventDropped;
273
+ onBatchFailed;
274
+ onBatchSuccess;
275
+ flushTimer = null;
276
+ activeBatches = [];
277
+ isShuttingDown = false;
278
+ isFlushing = false;
279
+ endpoint;
280
+ headers;
281
+ sendBatch;
282
+ constructor(endpoint, headers, options = {}) {
283
+ this.endpoint = endpoint;
284
+ this.headers = headers;
285
+ this.batchSize = options.batchSize ?? 100;
286
+ this.flushIntervalMs = options.flushIntervalMs ?? 5e3;
287
+ this.maxConcurrentRequests = options.maxConcurrentRequests ?? 5;
288
+ this.maxRetries = options.maxRetries ?? 3;
289
+ this.retryBaseDelayMs = options.retryBaseDelayMs ?? 1e3;
290
+ this.maxQueueSize = options.maxQueueSize ?? 1e5;
291
+ this.onEventDropped = options.onEventDropped;
292
+ this.onBatchFailed = options.onBatchFailed;
293
+ this.onBatchSuccess = options.onBatchSuccess;
294
+ this.sendBatch = this.createBatchSender();
295
+ this.startFlushTimer();
296
+ }
297
+ /**
298
+ * Add an event to the queue. Events are batched and sent automatically.
299
+ */
300
+ enqueue(payload) {
301
+ if (this.isShuttingDown) {
302
+ logger.warn("Cannot enqueue events after shutdown has started");
303
+ return false;
304
+ }
305
+ if (this.queue.length >= this.maxQueueSize) {
306
+ const droppedEvent = {
307
+ payload,
308
+ timestamp: Date.now(),
309
+ retryCount: 0
310
+ };
311
+ this.onEventDropped?.(droppedEvent, "Queue is full");
312
+ logger.warn(
313
+ `Event dropped: queue is full (max ${this.maxQueueSize} events)`
314
+ );
315
+ return false;
316
+ }
317
+ const event = {
318
+ payload,
319
+ timestamp: Date.now(),
320
+ retryCount: 0
321
+ };
322
+ this.queue.push(event);
323
+ if (this.queue.length >= this.batchSize) {
324
+ void this.flush();
325
+ }
326
+ return true;
327
+ }
328
+ /**
329
+ * Flush all pending events. Call this before your application exits.
330
+ */
331
+ async flush() {
332
+ if (this.isFlushing) {
333
+ await Promise.all(this.activeBatches.map((b) => b.promise));
334
+ return;
335
+ }
336
+ this.isFlushing = true;
337
+ try {
338
+ while (this.queue.length > 0) {
339
+ while (this.activeBatches.length >= this.maxConcurrentRequests) {
340
+ await Promise.race(this.activeBatches.map((b) => b.promise));
341
+ this.cleanupCompletedBatches();
342
+ }
343
+ const batch = this.queue.splice(0, this.batchSize);
344
+ if (batch.length > 0) {
345
+ const batchPromise = this.processBatch(batch);
346
+ const pendingBatch = {
347
+ events: batch,
348
+ promise: batchPromise
349
+ };
350
+ this.activeBatches.push(pendingBatch);
351
+ }
352
+ }
353
+ await Promise.all(this.activeBatches.map((b) => b.promise));
354
+ this.cleanupCompletedBatches();
355
+ } finally {
356
+ this.isFlushing = false;
357
+ }
358
+ }
359
+ /**
360
+ * Shutdown the queue gracefully. Flushes all pending events and stops the timer.
361
+ */
362
+ async shutdown() {
363
+ this.isShuttingDown = true;
364
+ this.stopFlushTimer();
365
+ await this.flush();
366
+ }
367
+ /**
368
+ * Get current queue statistics.
369
+ */
370
+ getStats() {
371
+ return {
372
+ queuedEvents: this.queue.length,
373
+ activeBatches: this.activeBatches.length,
374
+ isShuttingDown: this.isShuttingDown
375
+ };
376
+ }
377
+ startFlushTimer() {
378
+ if (this.flushTimer) return;
379
+ this.flushTimer = setInterval(() => {
380
+ if (this.queue.length > 0 && !this.isFlushing) {
381
+ void this.flush();
382
+ }
383
+ }, this.flushIntervalMs);
384
+ if (this.flushTimer.unref) {
385
+ this.flushTimer.unref();
386
+ }
387
+ }
388
+ stopFlushTimer() {
389
+ if (this.flushTimer) {
390
+ clearInterval(this.flushTimer);
391
+ this.flushTimer = null;
392
+ }
393
+ }
394
+ cleanupCompletedBatches() {
395
+ this.activeBatches = [];
396
+ }
397
+ async processBatch(events) {
398
+ let lastError = null;
399
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
400
+ try {
401
+ const response = await this.sendBatch(events);
402
+ this.onBatchSuccess?.(events, response);
403
+ return;
404
+ } catch (error) {
405
+ lastError = error instanceof Error ? error : new Error(String(error));
406
+ if (attempt < this.maxRetries) {
407
+ const delay = this.retryBaseDelayMs * Math.pow(2, attempt) + Math.random() * 1e3;
408
+ await this.sleep(delay);
409
+ }
410
+ }
411
+ }
412
+ if (lastError) {
413
+ this.onBatchFailed?.(events, lastError);
414
+ logger.error(
415
+ `Batch of ${events.length} events failed after ${this.maxRetries + 1} attempts: ${lastError.message}`
416
+ );
417
+ }
418
+ }
419
+ createBatchSender() {
420
+ return async (events) => {
421
+ const payloads = events.map((e) => e.payload);
422
+ const response = await fetch(this.endpoint, {
423
+ method: "POST",
424
+ headers: this.headers,
425
+ body: JSON.stringify({ events: payloads })
426
+ });
427
+ const text = await response.text();
428
+ let responseBody;
429
+ try {
430
+ responseBody = text ? JSON.parse(text) : null;
431
+ } catch {
432
+ responseBody = text;
433
+ }
434
+ if (!response.ok) {
435
+ throw new Error(`HTTP ${response.status} ${response.statusText}: ${text}`);
436
+ }
437
+ return responseBody;
438
+ };
439
+ }
440
+ sleep(ms) {
441
+ return new Promise((resolve) => setTimeout(resolve, ms));
442
+ }
443
+ };
444
+
445
+ // src/user_metrics/record_user_event.ts
446
+ var dotenv = __toESM(require("dotenv"), 1);
447
+ dotenv.config();
448
+ var PrimeOrbitClient = class {
449
+ apiKey;
450
+ baseUrl;
451
+ baseProperties = {};
452
+ verbose = false;
453
+ enableBatching = false;
454
+ eventQueue = null;
455
+ constructor(apiKeyOrOptions, endpoint) {
456
+ let apiKey;
457
+ let endpointUrl;
458
+ let options = {};
459
+ if (typeof apiKeyOrOptions === "object" && apiKeyOrOptions !== null) {
460
+ options = apiKeyOrOptions;
461
+ apiKey = options.apiKey;
462
+ endpointUrl = options.endpoint;
463
+ this.verbose = options.verbose ?? false;
464
+ this.enableBatching = options.enableBatching ?? false;
465
+ } else {
466
+ apiKey = apiKeyOrOptions;
467
+ endpointUrl = endpoint;
468
+ }
469
+ const envApiKey = process.env["PRIMEORBIT_API_KEY"];
470
+ const envEndpoint = process.env["PRIMEORBIT_ENDPOINT"];
471
+ if (apiKey) {
472
+ this.apiKey = apiKey;
473
+ } else if (envApiKey) {
474
+ this.apiKey = envApiKey;
475
+ } else {
476
+ throw new Error(
477
+ "API key not provided. Set the 'apiKey' parameter or the 'PRIMEORBIT_API_KEY' environment variable."
478
+ );
479
+ }
480
+ if (endpointUrl) {
481
+ this.baseUrl = endpointUrl;
482
+ } else if (envEndpoint) {
483
+ this.baseUrl = envEndpoint;
484
+ } else {
485
+ this.baseUrl = "https://sdk-dev.primeorbit.ai";
486
+ }
487
+ this.baseProperties = {};
488
+ if (this.enableBatching) {
489
+ this.initializeEventQueue(options.queueOptions);
490
+ }
491
+ }
492
+ initializeEventQueue(queueOptions) {
493
+ const batchEndpoint = `${this.baseUrl}${routes["raw-events-batch"]}`;
494
+ this.eventQueue = new EventQueue(batchEndpoint, this._headers(), {
495
+ batchSize: 100,
496
+ flushIntervalMs: 5e3,
497
+ maxConcurrentRequests: 5,
498
+ maxRetries: 3,
499
+ retryBaseDelayMs: 1e3,
500
+ maxQueueSize: 1e5,
501
+ ...queueOptions
502
+ });
503
+ }
504
+ add_properties(props) {
505
+ this.baseProperties = {
506
+ ...this.baseProperties,
507
+ ...props
508
+ };
509
+ }
510
+ _headers() {
511
+ return {
512
+ Authorization: `Bearer ${this.apiKey}`,
513
+ "Content-Type": "application/json"
514
+ };
515
+ }
516
+ /**
517
+ * Enable or disable event batching at runtime.
518
+ * When enabled, events are queued and sent in batches.
519
+ * When disabled, events are sent immediately (original behavior).
520
+ *
521
+ * @param enable - Whether to enable batching
522
+ * @param queueOptions - Optional queue configuration (only used when enabling)
523
+ */
524
+ setBatching(enable, queueOptions) {
525
+ if (enable && !this.eventQueue) {
526
+ this.enableBatching = true;
527
+ this.initializeEventQueue(queueOptions);
528
+ } else if (!enable && this.eventQueue) {
529
+ void this.eventQueue.flush().then(() => {
530
+ this.enableBatching = false;
531
+ this.eventQueue = null;
532
+ });
533
+ }
534
+ }
535
+ /**
536
+ * Flush all queued events immediately.
537
+ * Call this before your application exits to ensure all events are sent.
538
+ * Only applicable when batching is enabled.
539
+ */
540
+ async flush() {
541
+ if (this.eventQueue) {
542
+ await this.eventQueue.flush();
543
+ }
544
+ }
545
+ /**
546
+ * Shutdown the client gracefully.
547
+ * Flushes all pending events and releases resources.
548
+ * Call this when your application is shutting down.
549
+ */
550
+ async shutdown() {
551
+ if (this.eventQueue) {
552
+ await this.eventQueue.shutdown();
553
+ this.eventQueue = null;
554
+ }
555
+ }
556
+ /**
557
+ * Get queue statistics.
558
+ * Only applicable when batching is enabled.
559
+ */
560
+ getQueueStats() {
561
+ if (this.eventQueue) {
562
+ return this.eventQueue.getStats();
563
+ }
564
+ return null;
565
+ }
566
+ /**
567
+ * Records any agent interaction event such as user_message, agent_response, or user_feedback.
568
+ *
569
+ * @param eventType - Type of event. Can be:
570
+ * - 'user_message' – when the user sends a message
571
+ * - 'agent_response' – when the agent replies
572
+ * - 'user_feedback' – when the user gives feedback
573
+ *
574
+ * @param params - Object containing event details:
575
+ * - conversationId: string – Unique conversation identifier
576
+ * - agentId: string – Agent ID
577
+ * - userId: string – User ID
578
+ * - productId?: string – Optional product ID
579
+ * - content: string – Text content of the event (user message, agent reply, or feedback)
580
+ * - sessionId?: string – Optional session ID
581
+ * - messageId?: string – Optional message ID (for tracking within conversation)
582
+ * - inputMode?: string – Optional input mode (e.g., 'text', 'voice')
583
+ * - device?: string – Optional device name or model (e.g., 'iPhone 13')
584
+ * - country?: string – Optional country of the user (ISO country code, e.g., 'US')
585
+ * - platform?: string – Optional platform or OS (e.g., 'iOS', 'Android', 'Web')
586
+ * - language?: string – Optional language of the user (e.g., 'en-US')
587
+ * - Any additional properties will be captured in additional_properties
588
+ *
589
+ * @returns Promise that resolves when the event is queued (batching) or sent (non-batching).
590
+ * When batching is enabled, returns true if queued successfully, false if dropped.
591
+ */
592
+ async record_raw_event(eventType, params) {
593
+ const finalParams = {
594
+ ...this.baseProperties,
595
+ ...params
596
+ };
597
+ try {
598
+ const {
599
+ conversationId,
600
+ messageId,
601
+ agentId,
602
+ userId,
603
+ appId,
604
+ content,
605
+ sessionId,
606
+ eventId,
607
+ inputMode,
608
+ device,
609
+ country,
610
+ platform,
611
+ experimentId,
612
+ ...extraProps
613
+ } = finalParams;
614
+ const requiredFields = ["conversationId", "userId", "content"];
615
+ const missingRequired = requiredFields.filter(
616
+ (field) => !(field in finalParams) || finalParams[field] === void 0
617
+ );
618
+ if (missingRequired.length > 0) {
619
+ throw new Error(
620
+ `Missing required fields: ${missingRequired.join(", ")}`
621
+ );
622
+ }
623
+ const optionalFields = [
624
+ "agentId",
625
+ "sessionId",
626
+ "eventId",
627
+ "messageId",
628
+ "experimentId",
629
+ "inputMode",
630
+ "device",
631
+ "country",
632
+ "platform",
633
+ "appId",
634
+ "model"
635
+ ];
636
+ const missingOptionals = optionalFields.filter(
637
+ (field) => !(field in finalParams) || finalParams[field] === void 0
638
+ );
639
+ if (missingOptionals.length > 0) {
640
+ if (this.verbose) {
641
+ logger.warn(
642
+ `Missing optional fields: ${missingOptionals.join(", ")}. Analytics may be less accurate or incomplete.`
643
+ );
644
+ }
645
+ }
646
+ const payload = {
647
+ event_type: eventType,
648
+ conversation_id: conversationId,
649
+ session_id: sessionId,
650
+ user_id: userId,
651
+ agent_id: agentId,
652
+ message_id: messageId,
653
+ event_id: eventId,
654
+ app_id: appId,
655
+ content,
656
+ input_mode: inputMode,
657
+ device,
658
+ country,
659
+ platform,
660
+ experiment_id: experimentId,
661
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
662
+ additional_properties: Object.keys(extraProps).length > 0 ? extraProps : void 0
663
+ };
664
+ if (this.enableBatching && this.eventQueue) {
665
+ const queued = this.eventQueue.enqueue(payload);
666
+ return queued;
667
+ } else {
668
+ logger.debug("Recording event:", payload);
669
+ await recordData(
670
+ `${this.baseUrl}${routes["raw-events"]}`,
671
+ payload,
672
+ this._headers()
673
+ );
674
+ return void 0;
675
+ }
676
+ } catch (err) {
677
+ const message = err instanceof Error ? err.message : String(err);
678
+ logger.error(`recording_event failed: ${message}`);
679
+ return void 0;
680
+ }
681
+ }
682
+ };
683
+ // Annotate the CommonJS export names for ESM import in node:
684
+ 0 && (module.exports = {
685
+ EventQueue,
686
+ PrimeOrbitClient,
687
+ getLogLevel,
688
+ getPrimeOrbitApiUrl,
689
+ logger,
690
+ record_star_rating,
691
+ record_thumbs_feedback,
692
+ setLogLevel,
693
+ setPrimeOrbitApiUrl,
694
+ wrapAsyncToRecordLatency,
695
+ wrapSyncToRecordLatency,
696
+ wrapToRecordLatency
697
+ });