pollax 1.0.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/dist/index.js ADDED
@@ -0,0 +1,907 @@
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
+ Agents: () => Agents,
34
+ Analytics: () => Analytics,
35
+ ApiKeys: () => ApiKeys,
36
+ AuthenticationError: () => AuthenticationError,
37
+ Calls: () => Calls,
38
+ Campaigns: () => Campaigns,
39
+ Integrations: () => Integrations,
40
+ Knowledge: () => Knowledge,
41
+ NotFoundError: () => NotFoundError,
42
+ PhoneNumbers: () => PhoneNumbers,
43
+ Pollax: () => Pollax,
44
+ PollaxError: () => PollaxError,
45
+ RateLimitError: () => RateLimitError,
46
+ ValidationError: () => ValidationError,
47
+ VoiceCloning: () => VoiceCloning,
48
+ default: () => Pollax
49
+ });
50
+ module.exports = __toCommonJS(index_exports);
51
+
52
+ // src/client.ts
53
+ var import_axios = __toESM(require("axios"));
54
+
55
+ // src/resources/agents.ts
56
+ var Agents = class {
57
+ constructor(request) {
58
+ this.request = request;
59
+ }
60
+ /**
61
+ * Create a new AI agent
62
+ *
63
+ * @example
64
+ * const agent = await pollax.agents.create({
65
+ * name: 'Customer Support Agent',
66
+ * system_prompt: 'You are a helpful customer support agent.',
67
+ * voice_id: 'alloy',
68
+ * model: 'gpt-4',
69
+ * });
70
+ */
71
+ async create(params) {
72
+ return this.request({
73
+ method: "POST",
74
+ url: "/api/v1/agents",
75
+ data: params
76
+ });
77
+ }
78
+ /**
79
+ * List all agents
80
+ *
81
+ * @example
82
+ * const agents = await pollax.agents.list({ is_active: true });
83
+ */
84
+ async list(params) {
85
+ return this.request({
86
+ method: "GET",
87
+ url: "/api/v1/agents",
88
+ params
89
+ });
90
+ }
91
+ /**
92
+ * Get a single agent by ID
93
+ *
94
+ * @example
95
+ * const agent = await pollax.agents.retrieve('agent_123');
96
+ */
97
+ async retrieve(agentId) {
98
+ return this.request({
99
+ method: "GET",
100
+ url: `/api/v1/agents/${agentId}`
101
+ });
102
+ }
103
+ /**
104
+ * Update an agent
105
+ *
106
+ * @example
107
+ * const agent = await pollax.agents.update('agent_123', {
108
+ * name: 'Updated Agent Name',
109
+ * is_active: false,
110
+ * });
111
+ */
112
+ async update(agentId, params) {
113
+ return this.request({
114
+ method: "PUT",
115
+ url: `/api/v1/agents/${agentId}`,
116
+ data: params
117
+ });
118
+ }
119
+ /**
120
+ * Delete an agent
121
+ *
122
+ * @example
123
+ * await pollax.agents.delete('agent_123');
124
+ */
125
+ async delete(agentId) {
126
+ return this.request({
127
+ method: "DELETE",
128
+ url: `/api/v1/agents/${agentId}`
129
+ });
130
+ }
131
+ /**
132
+ * Test an agent with a sample prompt
133
+ *
134
+ * @example
135
+ * const response = await pollax.agents.test('agent_123', {
136
+ * message: 'Hello, how can you help me?',
137
+ * });
138
+ */
139
+ async test(agentId, params) {
140
+ return this.request({
141
+ method: "POST",
142
+ url: `/api/v1/agents/${agentId}/test`,
143
+ data: params
144
+ });
145
+ }
146
+ };
147
+
148
+ // src/resources/calls.ts
149
+ var Calls = class {
150
+ constructor(request) {
151
+ this.request = request;
152
+ }
153
+ /**
154
+ * Create a new voice call
155
+ *
156
+ * @example
157
+ * const call = await pollax.calls.create({
158
+ * agent_id: 'agent_123',
159
+ * to_number: '+1234567890',
160
+ * });
161
+ */
162
+ async create(params) {
163
+ return this.request({
164
+ method: "POST",
165
+ url: "/api/v1/calls",
166
+ data: params
167
+ });
168
+ }
169
+ /**
170
+ * List all calls
171
+ *
172
+ * @example
173
+ * const calls = await pollax.calls.list({
174
+ * agent_id: 'agent_123',
175
+ * status: 'completed',
176
+ * });
177
+ */
178
+ async list(params) {
179
+ return this.request({
180
+ method: "GET",
181
+ url: "/api/v1/calls",
182
+ params
183
+ });
184
+ }
185
+ /**
186
+ * Get a single call by SID
187
+ *
188
+ * @example
189
+ * const call = await pollax.calls.retrieve('CA123456789');
190
+ */
191
+ async retrieve(callSid) {
192
+ return this.request({
193
+ method: "GET",
194
+ url: `/api/v1/calls/${callSid}`
195
+ });
196
+ }
197
+ /**
198
+ * End an active call
199
+ *
200
+ * @example
201
+ * await pollax.calls.end('CA123456789');
202
+ */
203
+ async end(callSid) {
204
+ return this.request({
205
+ method: "POST",
206
+ url: `/api/v1/calls/${callSid}/end`
207
+ });
208
+ }
209
+ /**
210
+ * Transfer a call to another number
211
+ *
212
+ * @example
213
+ * await pollax.calls.transfer('CA123456789', {
214
+ * to_number: '+1234567890',
215
+ * });
216
+ */
217
+ async transfer(callSid, params) {
218
+ return this.request({
219
+ method: "POST",
220
+ url: `/api/v1/calls/${callSid}/transfer`,
221
+ data: params
222
+ });
223
+ }
224
+ /**
225
+ * Get call transcript
226
+ *
227
+ * @example
228
+ * const transcript = await pollax.calls.getTranscript('CA123456789');
229
+ */
230
+ async getTranscript(callSid) {
231
+ return this.request({
232
+ method: "GET",
233
+ url: `/api/v1/calls/${callSid}/transcript`
234
+ });
235
+ }
236
+ /**
237
+ * Get call recording URL
238
+ *
239
+ * @example
240
+ * const recording = await pollax.calls.getRecording('CA123456789');
241
+ */
242
+ async getRecording(callSid) {
243
+ return this.request({
244
+ method: "GET",
245
+ url: `/api/v1/calls/${callSid}/recording`
246
+ });
247
+ }
248
+ };
249
+
250
+ // src/resources/campaigns.ts
251
+ var Campaigns = class {
252
+ constructor(request) {
253
+ this.request = request;
254
+ }
255
+ /**
256
+ * Create a new campaign
257
+ *
258
+ * @example
259
+ * const campaign = await pollax.campaigns.create({
260
+ * name: 'Q1 Outreach Campaign',
261
+ * agent_id: 'agent_123',
262
+ * contacts: [
263
+ * { name: 'John Doe', phone: '+1234567890' },
264
+ * { name: 'Jane Smith', phone: '+0987654321' },
265
+ * ],
266
+ * });
267
+ */
268
+ async create(params) {
269
+ return this.request({
270
+ method: "POST",
271
+ url: "/api/v1/campaigns",
272
+ data: params
273
+ });
274
+ }
275
+ /**
276
+ * List all campaigns
277
+ *
278
+ * @example
279
+ * const campaigns = await pollax.campaigns.list();
280
+ */
281
+ async list() {
282
+ return this.request({
283
+ method: "GET",
284
+ url: "/api/v1/campaigns"
285
+ });
286
+ }
287
+ /**
288
+ * Get a single campaign by ID
289
+ *
290
+ * @example
291
+ * const campaign = await pollax.campaigns.retrieve('campaign_123');
292
+ */
293
+ async retrieve(campaignId) {
294
+ return this.request({
295
+ method: "GET",
296
+ url: `/api/v1/campaigns/${campaignId}`
297
+ });
298
+ }
299
+ /**
300
+ * Update a campaign
301
+ *
302
+ * @example
303
+ * const campaign = await pollax.campaigns.update('campaign_123', {
304
+ * status: 'paused',
305
+ * });
306
+ */
307
+ async update(campaignId, params) {
308
+ return this.request({
309
+ method: "PUT",
310
+ url: `/api/v1/campaigns/${campaignId}`,
311
+ data: params
312
+ });
313
+ }
314
+ /**
315
+ * Delete a campaign
316
+ *
317
+ * @example
318
+ * await pollax.campaigns.delete('campaign_123');
319
+ */
320
+ async delete(campaignId) {
321
+ return this.request({
322
+ method: "DELETE",
323
+ url: `/api/v1/campaigns/${campaignId}`
324
+ });
325
+ }
326
+ /**
327
+ * Start a campaign
328
+ *
329
+ * @example
330
+ * await pollax.campaigns.start('campaign_123');
331
+ */
332
+ async start(campaignId) {
333
+ return this.request({
334
+ method: "POST",
335
+ url: `/api/v1/campaigns/${campaignId}/start`
336
+ });
337
+ }
338
+ /**
339
+ * Pause a running campaign
340
+ *
341
+ * @example
342
+ * await pollax.campaigns.pause('campaign_123');
343
+ */
344
+ async pause(campaignId) {
345
+ return this.request({
346
+ method: "POST",
347
+ url: `/api/v1/campaigns/${campaignId}/pause`
348
+ });
349
+ }
350
+ /**
351
+ * Upload contacts to a campaign via CSV
352
+ *
353
+ * @example
354
+ * const campaign = await pollax.campaigns.uploadContacts('campaign_123', csvFile);
355
+ */
356
+ async uploadContacts(campaignId, file) {
357
+ const formData = new FormData();
358
+ formData.append("file", file);
359
+ return this.request({
360
+ method: "POST",
361
+ url: `/api/v1/campaigns/${campaignId}/upload`,
362
+ data: formData,
363
+ headers: {
364
+ "Content-Type": "multipart/form-data"
365
+ }
366
+ });
367
+ }
368
+ /**
369
+ * Get campaign statistics
370
+ *
371
+ * @example
372
+ * const stats = await pollax.campaigns.getStats('campaign_123');
373
+ */
374
+ async getStats(campaignId) {
375
+ return this.request({
376
+ method: "GET",
377
+ url: `/api/v1/campaigns/${campaignId}/stats`
378
+ });
379
+ }
380
+ };
381
+
382
+ // src/resources/knowledge.ts
383
+ var Knowledge = class {
384
+ constructor(request) {
385
+ this.request = request;
386
+ }
387
+ /**
388
+ * Upload a document to the knowledge base
389
+ *
390
+ * @example
391
+ * const doc = await pollax.knowledge.upload({
392
+ * name: 'Product Manual',
393
+ * file: pdfFile,
394
+ * type: 'pdf',
395
+ * });
396
+ */
397
+ async upload(params) {
398
+ const formData = new FormData();
399
+ formData.append("name", params.name);
400
+ if (params.file) {
401
+ formData.append("file", params.file);
402
+ }
403
+ if (params.content) {
404
+ formData.append("content", params.content);
405
+ }
406
+ if (params.url) {
407
+ formData.append("url", params.url);
408
+ }
409
+ if (params.type) {
410
+ formData.append("type", params.type);
411
+ }
412
+ return this.request({
413
+ method: "POST",
414
+ url: "/api/v1/knowledge",
415
+ data: formData,
416
+ headers: {
417
+ "Content-Type": "multipart/form-data"
418
+ }
419
+ });
420
+ }
421
+ /**
422
+ * List all knowledge documents
423
+ *
424
+ * @example
425
+ * const documents = await pollax.knowledge.list();
426
+ */
427
+ async list() {
428
+ return this.request({
429
+ method: "GET",
430
+ url: "/api/v1/knowledge"
431
+ });
432
+ }
433
+ /**
434
+ * Get a single document by ID
435
+ *
436
+ * @example
437
+ * const doc = await pollax.knowledge.retrieve('doc_123');
438
+ */
439
+ async retrieve(documentId) {
440
+ return this.request({
441
+ method: "GET",
442
+ url: `/api/v1/knowledge/${documentId}`
443
+ });
444
+ }
445
+ /**
446
+ * Delete a document
447
+ *
448
+ * @example
449
+ * await pollax.knowledge.delete('doc_123');
450
+ */
451
+ async delete(documentId) {
452
+ return this.request({
453
+ method: "DELETE",
454
+ url: `/api/v1/knowledge/${documentId}`
455
+ });
456
+ }
457
+ /**
458
+ * Search the knowledge base
459
+ *
460
+ * @example
461
+ * const results = await pollax.knowledge.search({
462
+ * query: 'How do I reset my password?',
463
+ * limit: 5,
464
+ * });
465
+ */
466
+ async search(params) {
467
+ return this.request({
468
+ method: "POST",
469
+ url: "/api/v1/knowledge/search",
470
+ data: params
471
+ });
472
+ }
473
+ };
474
+
475
+ // src/resources/analytics.ts
476
+ var Analytics = class {
477
+ constructor(request) {
478
+ this.request = request;
479
+ }
480
+ /**
481
+ * Get dashboard statistics
482
+ *
483
+ * @example
484
+ * const stats = await pollax.analytics.getStats();
485
+ */
486
+ async getStats() {
487
+ return this.request({
488
+ method: "GET",
489
+ url: "/api/v1/analytics/stats"
490
+ });
491
+ }
492
+ /**
493
+ * Get call volume over time
494
+ *
495
+ * @example
496
+ * const volume = await pollax.analytics.getCallVolume({ period: '7d' });
497
+ */
498
+ async getCallVolume(params) {
499
+ return this.request({
500
+ method: "GET",
501
+ url: "/api/v1/analytics/call-volume",
502
+ params
503
+ });
504
+ }
505
+ /**
506
+ * Get agent performance metrics
507
+ *
508
+ * @example
509
+ * const performance = await pollax.analytics.getAgentPerformance('agent_123');
510
+ */
511
+ async getAgentPerformance(agentId) {
512
+ return this.request({
513
+ method: "GET",
514
+ url: `/api/v1/analytics/agents/${agentId}/performance`
515
+ });
516
+ }
517
+ /**
518
+ * Export analytics data
519
+ *
520
+ * @example
521
+ * const csvData = await pollax.analytics.export({
522
+ * start_date: '2024-01-01',
523
+ * end_date: '2024-01-31',
524
+ * format: 'csv',
525
+ * });
526
+ */
527
+ async export(params) {
528
+ return this.request({
529
+ method: "GET",
530
+ url: "/api/v1/analytics/export",
531
+ params
532
+ });
533
+ }
534
+ };
535
+
536
+ // src/resources/integrations.ts
537
+ var Integrations = class {
538
+ constructor(request) {
539
+ this.request = request;
540
+ }
541
+ /**
542
+ * Create a new integration
543
+ *
544
+ * @example
545
+ * const integration = await pollax.integrations.create({
546
+ * name: 'Salesforce CRM',
547
+ * type: 'salesforce',
548
+ * config: {
549
+ * client_id: '...',
550
+ * client_secret: '...',
551
+ * },
552
+ * });
553
+ */
554
+ async create(params) {
555
+ return this.request({
556
+ method: "POST",
557
+ url: "/api/v1/integrations",
558
+ data: params
559
+ });
560
+ }
561
+ /**
562
+ * List all integrations
563
+ *
564
+ * @example
565
+ * const integrations = await pollax.integrations.list();
566
+ */
567
+ async list() {
568
+ return this.request({
569
+ method: "GET",
570
+ url: "/api/v1/integrations"
571
+ });
572
+ }
573
+ /**
574
+ * Get a single integration by ID
575
+ *
576
+ * @example
577
+ * const integration = await pollax.integrations.retrieve('int_123');
578
+ */
579
+ async retrieve(integrationId) {
580
+ return this.request({
581
+ method: "GET",
582
+ url: `/api/v1/integrations/${integrationId}`
583
+ });
584
+ }
585
+ /**
586
+ * Delete an integration
587
+ *
588
+ * @example
589
+ * await pollax.integrations.delete('int_123');
590
+ */
591
+ async delete(integrationId) {
592
+ return this.request({
593
+ method: "DELETE",
594
+ url: `/api/v1/integrations/${integrationId}`
595
+ });
596
+ }
597
+ };
598
+
599
+ // src/resources/phone-numbers.ts
600
+ var PhoneNumbers = class {
601
+ constructor(request) {
602
+ this.request = request;
603
+ }
604
+ /**
605
+ * List all phone numbers
606
+ *
607
+ * @example
608
+ * const numbers = await pollax.phoneNumbers.list();
609
+ */
610
+ async list() {
611
+ return this.request({
612
+ method: "GET",
613
+ url: "/api/v1/phone-numbers"
614
+ });
615
+ }
616
+ /**
617
+ * Search available phone numbers
618
+ *
619
+ * @example
620
+ * const numbers = await pollax.phoneNumbers.search({
621
+ * country_code: 'US',
622
+ * area_code: '415',
623
+ * });
624
+ */
625
+ async search(params) {
626
+ return this.request({
627
+ method: "GET",
628
+ url: "/api/v1/phone-numbers/search",
629
+ params
630
+ });
631
+ }
632
+ /**
633
+ * Purchase a phone number
634
+ *
635
+ * @example
636
+ * const number = await pollax.phoneNumbers.purchase('+14155551234');
637
+ */
638
+ async purchase(phoneNumber) {
639
+ return this.request({
640
+ method: "POST",
641
+ url: "/api/v1/phone-numbers",
642
+ data: { phone_number: phoneNumber }
643
+ });
644
+ }
645
+ /**
646
+ * Release a phone number
647
+ *
648
+ * @example
649
+ * await pollax.phoneNumbers.release('num_123');
650
+ */
651
+ async release(numberId) {
652
+ return this.request({
653
+ method: "DELETE",
654
+ url: `/api/v1/phone-numbers/${numberId}`
655
+ });
656
+ }
657
+ };
658
+
659
+ // src/resources/api-keys.ts
660
+ var ApiKeys = class {
661
+ constructor(request) {
662
+ this.request = request;
663
+ }
664
+ /**
665
+ * Create a new API key
666
+ *
667
+ * @example
668
+ * const apiKey = await pollax.apiKeys.create({
669
+ * name: 'Production Key',
670
+ * permissions: ['read', 'write'],
671
+ * });
672
+ */
673
+ async create(params) {
674
+ return this.request({
675
+ method: "POST",
676
+ url: "/api/v1/api-keys",
677
+ data: params
678
+ });
679
+ }
680
+ /**
681
+ * List all API keys
682
+ *
683
+ * @example
684
+ * const keys = await pollax.apiKeys.list();
685
+ */
686
+ async list() {
687
+ return this.request({
688
+ method: "GET",
689
+ url: "/api/v1/api-keys"
690
+ });
691
+ }
692
+ /**
693
+ * Revoke an API key
694
+ *
695
+ * @example
696
+ * await pollax.apiKeys.revoke('key_123');
697
+ */
698
+ async revoke(keyId) {
699
+ return this.request({
700
+ method: "DELETE",
701
+ url: `/api/v1/api-keys/${keyId}`
702
+ });
703
+ }
704
+ };
705
+
706
+ // src/resources/voice-cloning.ts
707
+ var VoiceCloning = class {
708
+ constructor(request) {
709
+ this.request = request;
710
+ }
711
+ /**
712
+ * Create a new voice profile
713
+ *
714
+ * @example
715
+ * const voice = await pollax.voiceCloning.create({
716
+ * name: 'Custom Voice',
717
+ * description: 'My custom voice profile',
718
+ * audio_files: [audioFile1, audioFile2],
719
+ * });
720
+ */
721
+ async create(params) {
722
+ const formData = new FormData();
723
+ formData.append("name", params.name);
724
+ if (params.description) {
725
+ formData.append("description", params.description);
726
+ }
727
+ if (params.provider) {
728
+ formData.append("provider", params.provider);
729
+ }
730
+ params.audio_files.forEach((file, index) => {
731
+ formData.append("audio_files", file, `audio_${index}.wav`);
732
+ });
733
+ return this.request({
734
+ method: "POST",
735
+ url: "/api/v1/voice-cloning",
736
+ data: formData,
737
+ headers: {
738
+ "Content-Type": "multipart/form-data"
739
+ }
740
+ });
741
+ }
742
+ /**
743
+ * List all voice profiles
744
+ *
745
+ * @example
746
+ * const voices = await pollax.voiceCloning.list();
747
+ */
748
+ async list() {
749
+ return this.request({
750
+ method: "GET",
751
+ url: "/api/v1/voice-cloning"
752
+ });
753
+ }
754
+ /**
755
+ * Get a single voice profile by ID
756
+ *
757
+ * @example
758
+ * const voice = await pollax.voiceCloning.retrieve('voice_123');
759
+ */
760
+ async retrieve(voiceId) {
761
+ return this.request({
762
+ method: "GET",
763
+ url: `/api/v1/voice-cloning/${voiceId}`
764
+ });
765
+ }
766
+ /**
767
+ * Delete a voice profile
768
+ *
769
+ * @example
770
+ * await pollax.voiceCloning.delete('voice_123');
771
+ */
772
+ async delete(voiceId) {
773
+ return this.request({
774
+ method: "DELETE",
775
+ url: `/api/v1/voice-cloning/${voiceId}`
776
+ });
777
+ }
778
+ };
779
+
780
+ // src/errors.ts
781
+ var PollaxError = class _PollaxError extends Error {
782
+ constructor(message, statusCode = 0, response) {
783
+ super(message);
784
+ this.name = "PollaxError";
785
+ this.statusCode = statusCode;
786
+ this.response = response;
787
+ if (Error.captureStackTrace) {
788
+ Error.captureStackTrace(this, _PollaxError);
789
+ }
790
+ }
791
+ };
792
+ var AuthenticationError = class extends PollaxError {
793
+ constructor(message = "Authentication failed", response) {
794
+ super(message, 401, response);
795
+ this.name = "AuthenticationError";
796
+ }
797
+ };
798
+ var NotFoundError = class extends PollaxError {
799
+ constructor(message = "Resource not found", response) {
800
+ super(message, 404, response);
801
+ this.name = "NotFoundError";
802
+ }
803
+ };
804
+ var RateLimitError = class extends PollaxError {
805
+ constructor(message = "Rate limit exceeded", response) {
806
+ super(message, 429, response);
807
+ this.name = "RateLimitError";
808
+ }
809
+ };
810
+ var ValidationError = class extends PollaxError {
811
+ constructor(message = "Validation error", response) {
812
+ super(message, 400, response);
813
+ this.name = "ValidationError";
814
+ }
815
+ };
816
+
817
+ // src/client.ts
818
+ var Pollax = class {
819
+ constructor(config) {
820
+ if (!config.apiKey) {
821
+ throw new PollaxError("API key is required. Get one at https://pollax.ai/settings/api-keys");
822
+ }
823
+ this.maxRetries = config.maxRetries || 3;
824
+ const headers = {
825
+ "Authorization": `Bearer ${config.apiKey}`,
826
+ "Content-Type": "application/json",
827
+ "User-Agent": "Pollax-SDK-TypeScript/1.0.0"
828
+ };
829
+ if (config.tenantId) {
830
+ headers["X-Tenant-ID"] = config.tenantId;
831
+ }
832
+ this.client = import_axios.default.create({
833
+ baseURL: config.baseURL || "https://api.pollax.ai",
834
+ timeout: config.timeout || 3e4,
835
+ headers
836
+ });
837
+ this.client.interceptors.response.use(
838
+ (response) => response,
839
+ async (error) => {
840
+ if (error.response) {
841
+ const { status, data } = error.response;
842
+ if (status === 429 && this.maxRetries > 0) {
843
+ const retryAfter = parseInt(error.response.headers["retry-after"] || "1", 10);
844
+ await this.sleep(retryAfter * 1e3);
845
+ return this.client.request(error.config);
846
+ }
847
+ throw new PollaxError(
848
+ data.error || data.detail || "An error occurred",
849
+ status,
850
+ data
851
+ );
852
+ }
853
+ throw new PollaxError(
854
+ error.message || "Network error occurred",
855
+ 0,
856
+ error
857
+ );
858
+ }
859
+ );
860
+ this.agents = new Agents(this.request.bind(this));
861
+ this.calls = new Calls(this.request.bind(this));
862
+ this.campaigns = new Campaigns(this.request.bind(this));
863
+ this.knowledge = new Knowledge(this.request.bind(this));
864
+ this.analytics = new Analytics(this.request.bind(this));
865
+ this.integrations = new Integrations(this.request.bind(this));
866
+ this.phoneNumbers = new PhoneNumbers(this.request.bind(this));
867
+ this.apiKeys = new ApiKeys(this.request.bind(this));
868
+ this.voiceCloning = new VoiceCloning(this.request.bind(this));
869
+ }
870
+ /**
871
+ * Make an HTTP request with automatic retries
872
+ */
873
+ async request(config, retries = 0) {
874
+ try {
875
+ const response = await this.client.request(config);
876
+ return response.data;
877
+ } catch (error) {
878
+ if (retries < this.maxRetries && (error.code === "ECONNRESET" || error.code === "ETIMEDOUT" || error.response && error.response.status >= 500)) {
879
+ const delay = Math.pow(2, retries) * 1e3;
880
+ await this.sleep(delay);
881
+ return this.request(config, retries + 1);
882
+ }
883
+ throw error;
884
+ }
885
+ }
886
+ sleep(ms) {
887
+ return new Promise((resolve) => setTimeout(resolve, ms));
888
+ }
889
+ };
890
+ // Annotate the CommonJS export names for ESM import in node:
891
+ 0 && (module.exports = {
892
+ Agents,
893
+ Analytics,
894
+ ApiKeys,
895
+ AuthenticationError,
896
+ Calls,
897
+ Campaigns,
898
+ Integrations,
899
+ Knowledge,
900
+ NotFoundError,
901
+ PhoneNumbers,
902
+ Pollax,
903
+ PollaxError,
904
+ RateLimitError,
905
+ ValidationError,
906
+ VoiceCloning
907
+ });