@getsupervisor/agents-studio-sdk 1.3.0 → 1.4.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.cjs +255 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -39
- package/dist/index.d.ts +67 -39
- package/dist/index.js +255 -89
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
1
|
+
// src/utils/pagination.ts
|
|
2
|
+
var toNumber = (value) => {
|
|
3
|
+
return typeof value === "number" ? value : void 0;
|
|
4
|
+
};
|
|
5
|
+
var toBoolean = (value) => {
|
|
6
|
+
return typeof value === "boolean" ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
function cloneOptions(options, overrides) {
|
|
9
|
+
return {
|
|
10
|
+
...options ?? {},
|
|
11
|
+
...overrides ?? {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function normalizeMeta(meta) {
|
|
15
|
+
if (!meta) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
const metaRecord = meta;
|
|
19
|
+
return {
|
|
20
|
+
...metaRecord,
|
|
21
|
+
page: toNumber(metaRecord.page),
|
|
22
|
+
limit: toNumber(metaRecord.limit) ?? toNumber(metaRecord.pageSize),
|
|
23
|
+
total: toNumber(metaRecord.total) ?? toNumber(metaRecord.totalItems),
|
|
24
|
+
hasNext: toBoolean(metaRecord.hasNext),
|
|
25
|
+
hasPrevious: toBoolean(metaRecord.hasPrevious),
|
|
26
|
+
totalPages: toNumber(metaRecord.totalPages)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function resolveHasNext(meta, limit) {
|
|
30
|
+
if (typeof meta?.hasNext === "boolean") {
|
|
31
|
+
return meta.hasNext;
|
|
32
|
+
}
|
|
33
|
+
if (typeof meta?.total === "number" && typeof meta?.page === "number" && typeof limit === "number") {
|
|
34
|
+
return meta.page * limit < meta.total;
|
|
35
|
+
}
|
|
36
|
+
if (typeof meta?.totalPages === "number" && typeof meta?.page === "number") {
|
|
37
|
+
return meta.page < meta.totalPages;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function resolveHasPrevious(meta) {
|
|
42
|
+
if (typeof meta?.hasPrevious === "boolean") {
|
|
43
|
+
return meta.hasPrevious;
|
|
44
|
+
}
|
|
45
|
+
if (typeof meta?.page === "number") {
|
|
46
|
+
return meta.page > 1;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function attachPaginator(response, fetchPage, options) {
|
|
51
|
+
const baseOptions = options ?? {};
|
|
52
|
+
const meta = normalizeMeta(response.meta);
|
|
53
|
+
const currentPage = typeof meta?.page === "number" ? meta.page : typeof baseOptions.page === "number" ? baseOptions.page : 1;
|
|
54
|
+
const currentLimit = typeof meta?.limit === "number" ? meta.limit : typeof baseOptions.limit === "number" ? baseOptions.limit : void 0;
|
|
55
|
+
const getNextResponse = async (page, overrides) => {
|
|
56
|
+
const nextOptions = cloneOptions(baseOptions, {
|
|
57
|
+
...overrides,
|
|
58
|
+
page
|
|
59
|
+
});
|
|
60
|
+
const nextResponse = await fetchPage(nextOptions);
|
|
61
|
+
return attachPaginator(nextResponse, fetchPage, nextOptions);
|
|
62
|
+
};
|
|
63
|
+
return Object.assign(response, {
|
|
64
|
+
async next() {
|
|
65
|
+
if (!resolveHasNext(meta, currentLimit)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return getNextResponse(currentPage + 1);
|
|
69
|
+
},
|
|
70
|
+
async prev() {
|
|
71
|
+
if (!resolveHasPrevious(meta)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return getNextResponse(Math.max(1, currentPage - 1));
|
|
75
|
+
},
|
|
76
|
+
async page(pageNumber) {
|
|
77
|
+
if (typeof pageNumber !== "number" || Number.isNaN(pageNumber)) {
|
|
78
|
+
throw new TypeError("page(pageNumber) requires a numeric value.");
|
|
79
|
+
}
|
|
80
|
+
if (pageNumber < 1) {
|
|
81
|
+
throw new RangeError(
|
|
82
|
+
"Page numbers must be greater than or equal to 1."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return getNextResponse(pageNumber);
|
|
86
|
+
},
|
|
87
|
+
async reload() {
|
|
88
|
+
return getNextResponse(currentPage);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
1
93
|
// src/errors.ts
|
|
2
94
|
var HttpError = class extends Error {
|
|
3
95
|
constructor(status, statusText, body, url) {
|
|
@@ -286,15 +378,23 @@ function getQueryBuilderString(value) {
|
|
|
286
378
|
function createAgentInstructionsApi(cfg) {
|
|
287
379
|
const { base, doFetch } = createHttp(cfg);
|
|
288
380
|
const jsonHeaders = { "content-type": "application/json" };
|
|
381
|
+
const fetchInstructionPage = async (agentId, opts = {}) => {
|
|
382
|
+
const { versionId, ...queryOptions } = opts ?? {};
|
|
383
|
+
const query = serializeListOptions(queryOptions, { versionId });
|
|
384
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
385
|
+
method: "GET",
|
|
386
|
+
query
|
|
387
|
+
});
|
|
388
|
+
return res.json();
|
|
389
|
+
};
|
|
289
390
|
return {
|
|
290
391
|
async list(agentId, opts = {}) {
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return res.json();
|
|
392
|
+
const normalizedOptions = {
|
|
393
|
+
...opts ?? {}
|
|
394
|
+
};
|
|
395
|
+
const fetchPage = (options) => fetchInstructionPage(agentId, options);
|
|
396
|
+
const response = await fetchPage(normalizedOptions);
|
|
397
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
298
398
|
},
|
|
299
399
|
async create(agentId, payload) {
|
|
300
400
|
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
@@ -330,6 +430,25 @@ function createAgentInstructionsApi(cfg) {
|
|
|
330
430
|
function createAgentKnowledgeApi(cfg) {
|
|
331
431
|
const { base, doFetch } = createHttp(cfg);
|
|
332
432
|
const jsonHeaders = { "content-type": "application/json" };
|
|
433
|
+
const fetchBasesPage = async (agentId, opts = {}) => {
|
|
434
|
+
const query = serializeListOptions(opts);
|
|
435
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/knowledge/bases`, {
|
|
436
|
+
method: "GET",
|
|
437
|
+
query
|
|
438
|
+
});
|
|
439
|
+
return res.json();
|
|
440
|
+
};
|
|
441
|
+
const fetchUploadsPage = async (agentId, opts = {}) => {
|
|
442
|
+
const query = serializeListOptions(opts);
|
|
443
|
+
const res = await doFetch(
|
|
444
|
+
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
445
|
+
{
|
|
446
|
+
method: "GET",
|
|
447
|
+
query
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
return res.json();
|
|
451
|
+
};
|
|
333
452
|
return {
|
|
334
453
|
async upload(agentId, payload) {
|
|
335
454
|
const res = await doFetch(
|
|
@@ -343,26 +462,20 @@ function createAgentKnowledgeApi(cfg) {
|
|
|
343
462
|
return res.json();
|
|
344
463
|
},
|
|
345
464
|
async listBases(agentId, opts = {}) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
);
|
|
354
|
-
return res.json();
|
|
465
|
+
const normalizedOptions = {
|
|
466
|
+
...opts ?? {}
|
|
467
|
+
};
|
|
468
|
+
const fetchPage = (options) => fetchBasesPage(agentId, options);
|
|
469
|
+
const response = await fetchPage(normalizedOptions);
|
|
470
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
355
471
|
},
|
|
356
472
|
async listUploads(agentId, opts = {}) {
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
return res.json();
|
|
473
|
+
const normalizedOptions = {
|
|
474
|
+
...opts ?? {}
|
|
475
|
+
};
|
|
476
|
+
const fetchPage = (options) => fetchUploadsPage(agentId, options);
|
|
477
|
+
const response = await fetchPage(normalizedOptions);
|
|
478
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
366
479
|
}
|
|
367
480
|
};
|
|
368
481
|
}
|
|
@@ -414,15 +527,21 @@ function createAgentScheduleApi(cfg) {
|
|
|
414
527
|
function createAgentVersionsApi(cfg) {
|
|
415
528
|
const { base, doFetch } = createHttp(cfg);
|
|
416
529
|
const jsonHeaders = { "content-type": "application/json" };
|
|
530
|
+
const fetchVersionsPage = async (agentId, opts = {}) => {
|
|
531
|
+
const { status, ...queryOptions } = opts ?? {};
|
|
532
|
+
const query = serializeListOptions(queryOptions, { status });
|
|
533
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
534
|
+
method: "GET",
|
|
535
|
+
query
|
|
536
|
+
});
|
|
537
|
+
return res.json();
|
|
538
|
+
};
|
|
417
539
|
return {
|
|
418
540
|
async list(agentId, opts = {}) {
|
|
419
|
-
const {
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
query
|
|
424
|
-
});
|
|
425
|
-
return res.json();
|
|
541
|
+
const normalizedOptions = { ...opts ?? {} };
|
|
542
|
+
const fetchPage = (options) => fetchVersionsPage(agentId, options);
|
|
543
|
+
const response = await fetchPage(normalizedOptions);
|
|
544
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
426
545
|
},
|
|
427
546
|
async get(agentId, versionId) {
|
|
428
547
|
const res = await doFetch(
|
|
@@ -518,7 +637,9 @@ var createAgentEntity = (dto, options) => {
|
|
|
518
637
|
phonesApi,
|
|
519
638
|
scheduleApi,
|
|
520
639
|
versionsApi,
|
|
521
|
-
reload
|
|
640
|
+
reload,
|
|
641
|
+
updateAgent,
|
|
642
|
+
deleteAgent
|
|
522
643
|
} = options;
|
|
523
644
|
const entity = {
|
|
524
645
|
...dto,
|
|
@@ -527,6 +648,12 @@ var createAgentEntity = (dto, options) => {
|
|
|
527
648
|
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
528
649
|
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
529
650
|
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
651
|
+
async save(patch) {
|
|
652
|
+
return updateAgent(dto.agentId, patch);
|
|
653
|
+
},
|
|
654
|
+
async delete() {
|
|
655
|
+
await deleteAgent(dto.agentId);
|
|
656
|
+
},
|
|
530
657
|
async refresh() {
|
|
531
658
|
return reload(dto.agentId);
|
|
532
659
|
}
|
|
@@ -538,7 +665,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
538
665
|
function createAgentsApi(cfg, relatedApis) {
|
|
539
666
|
const { base, doFetch } = createHttp(cfg);
|
|
540
667
|
const jsonHeaders = { "content-type": "application/json" };
|
|
541
|
-
const
|
|
668
|
+
const fetchAgentsPage = async (options = {}) => {
|
|
542
669
|
const query = serializeListOptions(options);
|
|
543
670
|
const res = await doFetch(`${base}/v1/agents`, {
|
|
544
671
|
method: "GET",
|
|
@@ -546,6 +673,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
546
673
|
});
|
|
547
674
|
return res.json();
|
|
548
675
|
};
|
|
676
|
+
const listAgents = async (options = {}) => {
|
|
677
|
+
const normalizedOptions = { ...options ?? {} };
|
|
678
|
+
const response = await fetchAgentsPage(normalizedOptions);
|
|
679
|
+
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
680
|
+
};
|
|
549
681
|
const getAgentDetail = async (agentId) => {
|
|
550
682
|
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
551
683
|
method: "GET"
|
|
@@ -568,7 +700,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
568
700
|
});
|
|
569
701
|
return res.json();
|
|
570
702
|
};
|
|
571
|
-
const
|
|
703
|
+
const resolveAgentId = (agent) => {
|
|
704
|
+
return typeof agent === "string" ? agent : agent.agentId;
|
|
705
|
+
};
|
|
706
|
+
const deleteAgent = async (agent) => {
|
|
707
|
+
const agentId = resolveAgentId(agent);
|
|
572
708
|
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
573
709
|
method: "DELETE"
|
|
574
710
|
});
|
|
@@ -592,17 +728,29 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
592
728
|
reload: async (agentId) => {
|
|
593
729
|
const latest = await getAgentDetail(agentId);
|
|
594
730
|
return wrapAgent(latest);
|
|
731
|
+
},
|
|
732
|
+
updateAgent: async (agentId, payload) => {
|
|
733
|
+
const updated = await updateAgent(agentId, payload);
|
|
734
|
+
return wrapAgent(updated);
|
|
735
|
+
},
|
|
736
|
+
deleteAgent: async (agentId) => {
|
|
737
|
+
await deleteAgent(agentId);
|
|
595
738
|
}
|
|
596
739
|
});
|
|
597
740
|
return {
|
|
598
741
|
...baseApi,
|
|
599
742
|
async list(options = {}) {
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
743
|
+
const normalizedOptions = { ...options ?? {} };
|
|
744
|
+
const applyWrap = async (opts) => {
|
|
745
|
+
const result = await fetchAgentsPage(opts);
|
|
746
|
+
const items = Array.isArray(result.data) ? result.data : [];
|
|
747
|
+
return {
|
|
748
|
+
...result,
|
|
749
|
+
data: items.map((summary) => wrapAgent(summary))
|
|
750
|
+
};
|
|
605
751
|
};
|
|
752
|
+
const initial = await applyWrap(normalizedOptions);
|
|
753
|
+
return attachPaginator(initial, applyWrap, normalizedOptions);
|
|
606
754
|
},
|
|
607
755
|
async get(agentId) {
|
|
608
756
|
const detail = await getAgentDetail(agentId);
|
|
@@ -623,14 +771,19 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
623
771
|
function createToolsApi(cfg) {
|
|
624
772
|
const { base, doFetch } = createHttp(cfg);
|
|
625
773
|
const jsonHeaders = { "content-type": "application/json" };
|
|
774
|
+
const fetchToolsPage = async (options = {}) => {
|
|
775
|
+
const query = serializeListOptions(options);
|
|
776
|
+
const res = await doFetch(`${base}/v1/tools`, {
|
|
777
|
+
method: "GET",
|
|
778
|
+
query
|
|
779
|
+
});
|
|
780
|
+
return res.json();
|
|
781
|
+
};
|
|
626
782
|
return {
|
|
627
783
|
async list(options = {}) {
|
|
628
|
-
const
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
query
|
|
632
|
-
});
|
|
633
|
-
return res.json();
|
|
784
|
+
const normalizedOptions = { ...options ?? {} };
|
|
785
|
+
const response = await fetchToolsPage(normalizedOptions);
|
|
786
|
+
return attachPaginator(response, fetchToolsPage, normalizedOptions);
|
|
634
787
|
},
|
|
635
788
|
async execute(toolId, payload) {
|
|
636
789
|
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
@@ -646,32 +799,37 @@ function createToolsApi(cfg) {
|
|
|
646
799
|
// src/api/voices.ts
|
|
647
800
|
function createVoicesApi(cfg) {
|
|
648
801
|
const { base, doFetch } = createHttp(cfg);
|
|
802
|
+
const fetchVoicesPage = async (options = {}) => {
|
|
803
|
+
const { agentId, agentVersionId, gender, locale } = options;
|
|
804
|
+
const query = serializeListOptions(
|
|
805
|
+
{
|
|
806
|
+
page: options.page,
|
|
807
|
+
limit: options.limit ?? options.pageSize,
|
|
808
|
+
sort: options.sort,
|
|
809
|
+
fields: options.fields,
|
|
810
|
+
include: options.include,
|
|
811
|
+
search: options.search,
|
|
812
|
+
filter: options.filter,
|
|
813
|
+
or: options.or
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
agentId,
|
|
817
|
+
agentVersionId,
|
|
818
|
+
gender,
|
|
819
|
+
locale
|
|
820
|
+
}
|
|
821
|
+
);
|
|
822
|
+
const res = await doFetch(`${base}/v1/voices`, {
|
|
823
|
+
method: "GET",
|
|
824
|
+
query
|
|
825
|
+
});
|
|
826
|
+
return res.json();
|
|
827
|
+
};
|
|
649
828
|
return {
|
|
650
829
|
async list(options = {}) {
|
|
651
|
-
const
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
page: options.page,
|
|
655
|
-
limit: options.limit ?? options.pageSize,
|
|
656
|
-
sort: options.sort,
|
|
657
|
-
fields: options.fields,
|
|
658
|
-
include: options.include,
|
|
659
|
-
search: options.search,
|
|
660
|
-
filter: options.filter,
|
|
661
|
-
or: options.or
|
|
662
|
-
},
|
|
663
|
-
{
|
|
664
|
-
agentId,
|
|
665
|
-
agentVersionId,
|
|
666
|
-
gender,
|
|
667
|
-
locale
|
|
668
|
-
}
|
|
669
|
-
);
|
|
670
|
-
const res = await doFetch(`${base}/v1/voices`, {
|
|
671
|
-
method: "GET",
|
|
672
|
-
query
|
|
673
|
-
});
|
|
674
|
-
return res.json();
|
|
830
|
+
const normalizedOptions = { ...options ?? {} };
|
|
831
|
+
const response = await fetchVoicesPage(normalizedOptions);
|
|
832
|
+
return attachPaginator(response, fetchVoicesPage, normalizedOptions);
|
|
675
833
|
}
|
|
676
834
|
};
|
|
677
835
|
}
|
|
@@ -680,27 +838,35 @@ function createVoicesApi(cfg) {
|
|
|
680
838
|
function createWorkspacesApi(cfg) {
|
|
681
839
|
const { base, doFetch } = createHttp(cfg);
|
|
682
840
|
const jsonHeaders = { "content-type": "application/json" };
|
|
841
|
+
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
842
|
+
const { channel } = opts ?? {};
|
|
843
|
+
const query = serializeListOptions(
|
|
844
|
+
{
|
|
845
|
+
page: opts.page,
|
|
846
|
+
limit: opts.limit,
|
|
847
|
+
sort: opts.sort,
|
|
848
|
+
fields: opts.fields,
|
|
849
|
+
include: opts.include,
|
|
850
|
+
search: opts.search,
|
|
851
|
+
filter: opts.filter,
|
|
852
|
+
or: opts.or
|
|
853
|
+
},
|
|
854
|
+
{ channel }
|
|
855
|
+
);
|
|
856
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
857
|
+
method: "GET",
|
|
858
|
+
query
|
|
859
|
+
});
|
|
860
|
+
return res.json();
|
|
861
|
+
};
|
|
683
862
|
return {
|
|
684
863
|
async listPhones(workspaceId, opts = {}) {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
fields: opts.fields,
|
|
692
|
-
include: opts.include,
|
|
693
|
-
search: opts.search,
|
|
694
|
-
filter: opts.filter,
|
|
695
|
-
or: opts.or
|
|
696
|
-
},
|
|
697
|
-
{ channel }
|
|
698
|
-
);
|
|
699
|
-
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
700
|
-
method: "GET",
|
|
701
|
-
query
|
|
702
|
-
});
|
|
703
|
-
return res.json();
|
|
864
|
+
const normalizedOptions = {
|
|
865
|
+
...opts ?? {}
|
|
866
|
+
};
|
|
867
|
+
const response = await fetchPhonesPage(workspaceId, normalizedOptions);
|
|
868
|
+
const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
|
|
869
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
704
870
|
},
|
|
705
871
|
async enable(workspaceId, payload) {
|
|
706
872
|
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
|