@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.cjs
CHANGED
|
@@ -42,6 +42,98 @@ __export(index_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(index_exports);
|
|
44
44
|
|
|
45
|
+
// src/utils/pagination.ts
|
|
46
|
+
var toNumber = (value) => {
|
|
47
|
+
return typeof value === "number" ? value : void 0;
|
|
48
|
+
};
|
|
49
|
+
var toBoolean = (value) => {
|
|
50
|
+
return typeof value === "boolean" ? value : void 0;
|
|
51
|
+
};
|
|
52
|
+
function cloneOptions(options, overrides) {
|
|
53
|
+
return {
|
|
54
|
+
...options ?? {},
|
|
55
|
+
...overrides ?? {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function normalizeMeta(meta) {
|
|
59
|
+
if (!meta) {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
const metaRecord = meta;
|
|
63
|
+
return {
|
|
64
|
+
...metaRecord,
|
|
65
|
+
page: toNumber(metaRecord.page),
|
|
66
|
+
limit: toNumber(metaRecord.limit) ?? toNumber(metaRecord.pageSize),
|
|
67
|
+
total: toNumber(metaRecord.total) ?? toNumber(metaRecord.totalItems),
|
|
68
|
+
hasNext: toBoolean(metaRecord.hasNext),
|
|
69
|
+
hasPrevious: toBoolean(metaRecord.hasPrevious),
|
|
70
|
+
totalPages: toNumber(metaRecord.totalPages)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function resolveHasNext(meta, limit) {
|
|
74
|
+
if (typeof meta?.hasNext === "boolean") {
|
|
75
|
+
return meta.hasNext;
|
|
76
|
+
}
|
|
77
|
+
if (typeof meta?.total === "number" && typeof meta?.page === "number" && typeof limit === "number") {
|
|
78
|
+
return meta.page * limit < meta.total;
|
|
79
|
+
}
|
|
80
|
+
if (typeof meta?.totalPages === "number" && typeof meta?.page === "number") {
|
|
81
|
+
return meta.page < meta.totalPages;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
function resolveHasPrevious(meta) {
|
|
86
|
+
if (typeof meta?.hasPrevious === "boolean") {
|
|
87
|
+
return meta.hasPrevious;
|
|
88
|
+
}
|
|
89
|
+
if (typeof meta?.page === "number") {
|
|
90
|
+
return meta.page > 1;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
function attachPaginator(response, fetchPage, options) {
|
|
95
|
+
const baseOptions = options ?? {};
|
|
96
|
+
const meta = normalizeMeta(response.meta);
|
|
97
|
+
const currentPage = typeof meta?.page === "number" ? meta.page : typeof baseOptions.page === "number" ? baseOptions.page : 1;
|
|
98
|
+
const currentLimit = typeof meta?.limit === "number" ? meta.limit : typeof baseOptions.limit === "number" ? baseOptions.limit : void 0;
|
|
99
|
+
const getNextResponse = async (page, overrides) => {
|
|
100
|
+
const nextOptions = cloneOptions(baseOptions, {
|
|
101
|
+
...overrides,
|
|
102
|
+
page
|
|
103
|
+
});
|
|
104
|
+
const nextResponse = await fetchPage(nextOptions);
|
|
105
|
+
return attachPaginator(nextResponse, fetchPage, nextOptions);
|
|
106
|
+
};
|
|
107
|
+
return Object.assign(response, {
|
|
108
|
+
async next() {
|
|
109
|
+
if (!resolveHasNext(meta, currentLimit)) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return getNextResponse(currentPage + 1);
|
|
113
|
+
},
|
|
114
|
+
async prev() {
|
|
115
|
+
if (!resolveHasPrevious(meta)) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return getNextResponse(Math.max(1, currentPage - 1));
|
|
119
|
+
},
|
|
120
|
+
async page(pageNumber) {
|
|
121
|
+
if (typeof pageNumber !== "number" || Number.isNaN(pageNumber)) {
|
|
122
|
+
throw new TypeError("page(pageNumber) requires a numeric value.");
|
|
123
|
+
}
|
|
124
|
+
if (pageNumber < 1) {
|
|
125
|
+
throw new RangeError(
|
|
126
|
+
"Page numbers must be greater than or equal to 1."
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return getNextResponse(pageNumber);
|
|
130
|
+
},
|
|
131
|
+
async reload() {
|
|
132
|
+
return getNextResponse(currentPage);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
45
137
|
// src/errors.ts
|
|
46
138
|
var HttpError = class extends Error {
|
|
47
139
|
constructor(status, statusText, body, url) {
|
|
@@ -330,15 +422,23 @@ function getQueryBuilderString(value) {
|
|
|
330
422
|
function createAgentInstructionsApi(cfg) {
|
|
331
423
|
const { base, doFetch } = createHttp(cfg);
|
|
332
424
|
const jsonHeaders = { "content-type": "application/json" };
|
|
425
|
+
const fetchInstructionPage = async (agentId, opts = {}) => {
|
|
426
|
+
const { versionId, ...queryOptions } = opts ?? {};
|
|
427
|
+
const query = serializeListOptions(queryOptions, { versionId });
|
|
428
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
429
|
+
method: "GET",
|
|
430
|
+
query
|
|
431
|
+
});
|
|
432
|
+
return res.json();
|
|
433
|
+
};
|
|
333
434
|
return {
|
|
334
435
|
async list(agentId, opts = {}) {
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return res.json();
|
|
436
|
+
const normalizedOptions = {
|
|
437
|
+
...opts ?? {}
|
|
438
|
+
};
|
|
439
|
+
const fetchPage = (options) => fetchInstructionPage(agentId, options);
|
|
440
|
+
const response = await fetchPage(normalizedOptions);
|
|
441
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
342
442
|
},
|
|
343
443
|
async create(agentId, payload) {
|
|
344
444
|
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
@@ -374,6 +474,25 @@ function createAgentInstructionsApi(cfg) {
|
|
|
374
474
|
function createAgentKnowledgeApi(cfg) {
|
|
375
475
|
const { base, doFetch } = createHttp(cfg);
|
|
376
476
|
const jsonHeaders = { "content-type": "application/json" };
|
|
477
|
+
const fetchBasesPage = async (agentId, opts = {}) => {
|
|
478
|
+
const query = serializeListOptions(opts);
|
|
479
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/knowledge/bases`, {
|
|
480
|
+
method: "GET",
|
|
481
|
+
query
|
|
482
|
+
});
|
|
483
|
+
return res.json();
|
|
484
|
+
};
|
|
485
|
+
const fetchUploadsPage = async (agentId, opts = {}) => {
|
|
486
|
+
const query = serializeListOptions(opts);
|
|
487
|
+
const res = await doFetch(
|
|
488
|
+
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
489
|
+
{
|
|
490
|
+
method: "GET",
|
|
491
|
+
query
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
return res.json();
|
|
495
|
+
};
|
|
377
496
|
return {
|
|
378
497
|
async upload(agentId, payload) {
|
|
379
498
|
const res = await doFetch(
|
|
@@ -387,26 +506,20 @@ function createAgentKnowledgeApi(cfg) {
|
|
|
387
506
|
return res.json();
|
|
388
507
|
},
|
|
389
508
|
async listBases(agentId, opts = {}) {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
|
-
return res.json();
|
|
509
|
+
const normalizedOptions = {
|
|
510
|
+
...opts ?? {}
|
|
511
|
+
};
|
|
512
|
+
const fetchPage = (options) => fetchBasesPage(agentId, options);
|
|
513
|
+
const response = await fetchPage(normalizedOptions);
|
|
514
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
399
515
|
},
|
|
400
516
|
async listUploads(agentId, opts = {}) {
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
return res.json();
|
|
517
|
+
const normalizedOptions = {
|
|
518
|
+
...opts ?? {}
|
|
519
|
+
};
|
|
520
|
+
const fetchPage = (options) => fetchUploadsPage(agentId, options);
|
|
521
|
+
const response = await fetchPage(normalizedOptions);
|
|
522
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
410
523
|
}
|
|
411
524
|
};
|
|
412
525
|
}
|
|
@@ -458,15 +571,21 @@ function createAgentScheduleApi(cfg) {
|
|
|
458
571
|
function createAgentVersionsApi(cfg) {
|
|
459
572
|
const { base, doFetch } = createHttp(cfg);
|
|
460
573
|
const jsonHeaders = { "content-type": "application/json" };
|
|
574
|
+
const fetchVersionsPage = async (agentId, opts = {}) => {
|
|
575
|
+
const { status, ...queryOptions } = opts ?? {};
|
|
576
|
+
const query = serializeListOptions(queryOptions, { status });
|
|
577
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
578
|
+
method: "GET",
|
|
579
|
+
query
|
|
580
|
+
});
|
|
581
|
+
return res.json();
|
|
582
|
+
};
|
|
461
583
|
return {
|
|
462
584
|
async list(agentId, opts = {}) {
|
|
463
|
-
const {
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
query
|
|
468
|
-
});
|
|
469
|
-
return res.json();
|
|
585
|
+
const normalizedOptions = { ...opts ?? {} };
|
|
586
|
+
const fetchPage = (options) => fetchVersionsPage(agentId, options);
|
|
587
|
+
const response = await fetchPage(normalizedOptions);
|
|
588
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
470
589
|
},
|
|
471
590
|
async get(agentId, versionId) {
|
|
472
591
|
const res = await doFetch(
|
|
@@ -562,7 +681,9 @@ var createAgentEntity = (dto, options) => {
|
|
|
562
681
|
phonesApi,
|
|
563
682
|
scheduleApi,
|
|
564
683
|
versionsApi,
|
|
565
|
-
reload
|
|
684
|
+
reload,
|
|
685
|
+
updateAgent,
|
|
686
|
+
deleteAgent
|
|
566
687
|
} = options;
|
|
567
688
|
const entity = {
|
|
568
689
|
...dto,
|
|
@@ -571,6 +692,12 @@ var createAgentEntity = (dto, options) => {
|
|
|
571
692
|
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
572
693
|
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
573
694
|
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
695
|
+
async save(patch) {
|
|
696
|
+
return updateAgent(dto.agentId, patch);
|
|
697
|
+
},
|
|
698
|
+
async delete() {
|
|
699
|
+
await deleteAgent(dto.agentId);
|
|
700
|
+
},
|
|
574
701
|
async refresh() {
|
|
575
702
|
return reload(dto.agentId);
|
|
576
703
|
}
|
|
@@ -582,7 +709,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
582
709
|
function createAgentsApi(cfg, relatedApis) {
|
|
583
710
|
const { base, doFetch } = createHttp(cfg);
|
|
584
711
|
const jsonHeaders = { "content-type": "application/json" };
|
|
585
|
-
const
|
|
712
|
+
const fetchAgentsPage = async (options = {}) => {
|
|
586
713
|
const query = serializeListOptions(options);
|
|
587
714
|
const res = await doFetch(`${base}/v1/agents`, {
|
|
588
715
|
method: "GET",
|
|
@@ -590,6 +717,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
590
717
|
});
|
|
591
718
|
return res.json();
|
|
592
719
|
};
|
|
720
|
+
const listAgents = async (options = {}) => {
|
|
721
|
+
const normalizedOptions = { ...options ?? {} };
|
|
722
|
+
const response = await fetchAgentsPage(normalizedOptions);
|
|
723
|
+
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
724
|
+
};
|
|
593
725
|
const getAgentDetail = async (agentId) => {
|
|
594
726
|
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
595
727
|
method: "GET"
|
|
@@ -612,7 +744,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
612
744
|
});
|
|
613
745
|
return res.json();
|
|
614
746
|
};
|
|
615
|
-
const
|
|
747
|
+
const resolveAgentId = (agent) => {
|
|
748
|
+
return typeof agent === "string" ? agent : agent.agentId;
|
|
749
|
+
};
|
|
750
|
+
const deleteAgent = async (agent) => {
|
|
751
|
+
const agentId = resolveAgentId(agent);
|
|
616
752
|
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
617
753
|
method: "DELETE"
|
|
618
754
|
});
|
|
@@ -636,17 +772,29 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
636
772
|
reload: async (agentId) => {
|
|
637
773
|
const latest = await getAgentDetail(agentId);
|
|
638
774
|
return wrapAgent(latest);
|
|
775
|
+
},
|
|
776
|
+
updateAgent: async (agentId, payload) => {
|
|
777
|
+
const updated = await updateAgent(agentId, payload);
|
|
778
|
+
return wrapAgent(updated);
|
|
779
|
+
},
|
|
780
|
+
deleteAgent: async (agentId) => {
|
|
781
|
+
await deleteAgent(agentId);
|
|
639
782
|
}
|
|
640
783
|
});
|
|
641
784
|
return {
|
|
642
785
|
...baseApi,
|
|
643
786
|
async list(options = {}) {
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
787
|
+
const normalizedOptions = { ...options ?? {} };
|
|
788
|
+
const applyWrap = async (opts) => {
|
|
789
|
+
const result = await fetchAgentsPage(opts);
|
|
790
|
+
const items = Array.isArray(result.data) ? result.data : [];
|
|
791
|
+
return {
|
|
792
|
+
...result,
|
|
793
|
+
data: items.map((summary) => wrapAgent(summary))
|
|
794
|
+
};
|
|
649
795
|
};
|
|
796
|
+
const initial = await applyWrap(normalizedOptions);
|
|
797
|
+
return attachPaginator(initial, applyWrap, normalizedOptions);
|
|
650
798
|
},
|
|
651
799
|
async get(agentId) {
|
|
652
800
|
const detail = await getAgentDetail(agentId);
|
|
@@ -667,14 +815,19 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
667
815
|
function createToolsApi(cfg) {
|
|
668
816
|
const { base, doFetch } = createHttp(cfg);
|
|
669
817
|
const jsonHeaders = { "content-type": "application/json" };
|
|
818
|
+
const fetchToolsPage = async (options = {}) => {
|
|
819
|
+
const query = serializeListOptions(options);
|
|
820
|
+
const res = await doFetch(`${base}/v1/tools`, {
|
|
821
|
+
method: "GET",
|
|
822
|
+
query
|
|
823
|
+
});
|
|
824
|
+
return res.json();
|
|
825
|
+
};
|
|
670
826
|
return {
|
|
671
827
|
async list(options = {}) {
|
|
672
|
-
const
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
query
|
|
676
|
-
});
|
|
677
|
-
return res.json();
|
|
828
|
+
const normalizedOptions = { ...options ?? {} };
|
|
829
|
+
const response = await fetchToolsPage(normalizedOptions);
|
|
830
|
+
return attachPaginator(response, fetchToolsPage, normalizedOptions);
|
|
678
831
|
},
|
|
679
832
|
async execute(toolId, payload) {
|
|
680
833
|
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
@@ -690,32 +843,37 @@ function createToolsApi(cfg) {
|
|
|
690
843
|
// src/api/voices.ts
|
|
691
844
|
function createVoicesApi(cfg) {
|
|
692
845
|
const { base, doFetch } = createHttp(cfg);
|
|
846
|
+
const fetchVoicesPage = async (options = {}) => {
|
|
847
|
+
const { agentId, agentVersionId, gender, locale } = options;
|
|
848
|
+
const query = serializeListOptions(
|
|
849
|
+
{
|
|
850
|
+
page: options.page,
|
|
851
|
+
limit: options.limit ?? options.pageSize,
|
|
852
|
+
sort: options.sort,
|
|
853
|
+
fields: options.fields,
|
|
854
|
+
include: options.include,
|
|
855
|
+
search: options.search,
|
|
856
|
+
filter: options.filter,
|
|
857
|
+
or: options.or
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
agentId,
|
|
861
|
+
agentVersionId,
|
|
862
|
+
gender,
|
|
863
|
+
locale
|
|
864
|
+
}
|
|
865
|
+
);
|
|
866
|
+
const res = await doFetch(`${base}/v1/voices`, {
|
|
867
|
+
method: "GET",
|
|
868
|
+
query
|
|
869
|
+
});
|
|
870
|
+
return res.json();
|
|
871
|
+
};
|
|
693
872
|
return {
|
|
694
873
|
async list(options = {}) {
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
page: options.page,
|
|
699
|
-
limit: options.limit ?? options.pageSize,
|
|
700
|
-
sort: options.sort,
|
|
701
|
-
fields: options.fields,
|
|
702
|
-
include: options.include,
|
|
703
|
-
search: options.search,
|
|
704
|
-
filter: options.filter,
|
|
705
|
-
or: options.or
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
agentId,
|
|
709
|
-
agentVersionId,
|
|
710
|
-
gender,
|
|
711
|
-
locale
|
|
712
|
-
}
|
|
713
|
-
);
|
|
714
|
-
const res = await doFetch(`${base}/v1/voices`, {
|
|
715
|
-
method: "GET",
|
|
716
|
-
query
|
|
717
|
-
});
|
|
718
|
-
return res.json();
|
|
874
|
+
const normalizedOptions = { ...options ?? {} };
|
|
875
|
+
const response = await fetchVoicesPage(normalizedOptions);
|
|
876
|
+
return attachPaginator(response, fetchVoicesPage, normalizedOptions);
|
|
719
877
|
}
|
|
720
878
|
};
|
|
721
879
|
}
|
|
@@ -724,27 +882,35 @@ function createVoicesApi(cfg) {
|
|
|
724
882
|
function createWorkspacesApi(cfg) {
|
|
725
883
|
const { base, doFetch } = createHttp(cfg);
|
|
726
884
|
const jsonHeaders = { "content-type": "application/json" };
|
|
885
|
+
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
886
|
+
const { channel } = opts ?? {};
|
|
887
|
+
const query = serializeListOptions(
|
|
888
|
+
{
|
|
889
|
+
page: opts.page,
|
|
890
|
+
limit: opts.limit,
|
|
891
|
+
sort: opts.sort,
|
|
892
|
+
fields: opts.fields,
|
|
893
|
+
include: opts.include,
|
|
894
|
+
search: opts.search,
|
|
895
|
+
filter: opts.filter,
|
|
896
|
+
or: opts.or
|
|
897
|
+
},
|
|
898
|
+
{ channel }
|
|
899
|
+
);
|
|
900
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
901
|
+
method: "GET",
|
|
902
|
+
query
|
|
903
|
+
});
|
|
904
|
+
return res.json();
|
|
905
|
+
};
|
|
727
906
|
return {
|
|
728
907
|
async listPhones(workspaceId, opts = {}) {
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
fields: opts.fields,
|
|
736
|
-
include: opts.include,
|
|
737
|
-
search: opts.search,
|
|
738
|
-
filter: opts.filter,
|
|
739
|
-
or: opts.or
|
|
740
|
-
},
|
|
741
|
-
{ channel }
|
|
742
|
-
);
|
|
743
|
-
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
744
|
-
method: "GET",
|
|
745
|
-
query
|
|
746
|
-
});
|
|
747
|
-
return res.json();
|
|
908
|
+
const normalizedOptions = {
|
|
909
|
+
...opts ?? {}
|
|
910
|
+
};
|
|
911
|
+
const response = await fetchPhonesPage(workspaceId, normalizedOptions);
|
|
912
|
+
const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
|
|
913
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
748
914
|
},
|
|
749
915
|
async enable(workspaceId, payload) {
|
|
750
916
|
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
|