@getsupervisor/agents-studio-sdk 1.3.0 → 1.5.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/CHANGELOG.md +51 -0
- package/README.md +31 -23
- package/dist/index.cjs +401 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +283 -937
- package/dist/index.d.ts +283 -937
- package/dist/index.js +399 -126
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,15 +23,15 @@ __export(index_exports, {
|
|
|
23
23
|
NetworkError: () => NetworkError,
|
|
24
24
|
TimeoutError: () => TimeoutError,
|
|
25
25
|
bindAgentInstructions: () => bindAgentInstructions,
|
|
26
|
-
bindAgentKnowledge: () => bindAgentKnowledge,
|
|
27
26
|
bindAgentPhones: () => bindAgentPhones,
|
|
28
27
|
bindAgentSchedule: () => bindAgentSchedule,
|
|
28
|
+
bindAgentTags: () => bindAgentTags,
|
|
29
29
|
bindAgentVersions: () => bindAgentVersions,
|
|
30
30
|
createAgentEntity: () => createAgentEntity,
|
|
31
31
|
createAgentInstructionsApi: () => createAgentInstructionsApi,
|
|
32
|
-
createAgentKnowledgeApi: () => createAgentKnowledgeApi,
|
|
33
32
|
createAgentPhonesApi: () => createAgentPhonesApi,
|
|
34
33
|
createAgentScheduleApi: () => createAgentScheduleApi,
|
|
34
|
+
createAgentTagsApi: () => createAgentTagsApi,
|
|
35
35
|
createAgentVersionsApi: () => createAgentVersionsApi,
|
|
36
36
|
createAgentsApi: () => createAgentsApi,
|
|
37
37
|
createClient: () => createClient,
|
|
@@ -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`, {
|
|
@@ -370,47 +470,6 @@ function createAgentInstructionsApi(cfg) {
|
|
|
370
470
|
};
|
|
371
471
|
}
|
|
372
472
|
|
|
373
|
-
// src/api/agent-knowledge.ts
|
|
374
|
-
function createAgentKnowledgeApi(cfg) {
|
|
375
|
-
const { base, doFetch } = createHttp(cfg);
|
|
376
|
-
const jsonHeaders = { "content-type": "application/json" };
|
|
377
|
-
return {
|
|
378
|
-
async upload(agentId, payload) {
|
|
379
|
-
const res = await doFetch(
|
|
380
|
-
`${base}/v1/agents/${agentId}/knowledge/upload`,
|
|
381
|
-
{
|
|
382
|
-
method: "POST",
|
|
383
|
-
headers: jsonHeaders,
|
|
384
|
-
body: JSON.stringify(payload)
|
|
385
|
-
}
|
|
386
|
-
);
|
|
387
|
-
return res.json();
|
|
388
|
-
},
|
|
389
|
-
async listBases(agentId, opts = {}) {
|
|
390
|
-
const query = serializeListOptions(opts);
|
|
391
|
-
const res = await doFetch(
|
|
392
|
-
`${base}/v1/agents/${agentId}/knowledge/bases`,
|
|
393
|
-
{
|
|
394
|
-
method: "GET",
|
|
395
|
-
query
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
|
-
return res.json();
|
|
399
|
-
},
|
|
400
|
-
async listUploads(agentId, opts = {}) {
|
|
401
|
-
const query = serializeListOptions(opts);
|
|
402
|
-
const res = await doFetch(
|
|
403
|
-
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
404
|
-
{
|
|
405
|
-
method: "GET",
|
|
406
|
-
query
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
return res.json();
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
473
|
// src/api/agent-phones.ts
|
|
415
474
|
function createAgentPhonesApi(cfg) {
|
|
416
475
|
const { base, doFetch } = createHttp(cfg);
|
|
@@ -454,19 +513,46 @@ function createAgentScheduleApi(cfg) {
|
|
|
454
513
|
};
|
|
455
514
|
}
|
|
456
515
|
|
|
516
|
+
// src/api/agent-tags.ts
|
|
517
|
+
function createAgentTagsApi(cfg) {
|
|
518
|
+
const { base, doFetch } = createHttp(cfg);
|
|
519
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
520
|
+
return {
|
|
521
|
+
async add(agentId, payload) {
|
|
522
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/tags`, {
|
|
523
|
+
method: "POST",
|
|
524
|
+
headers: jsonHeaders,
|
|
525
|
+
body: JSON.stringify(payload)
|
|
526
|
+
});
|
|
527
|
+
return res.json();
|
|
528
|
+
},
|
|
529
|
+
async remove(agentId, tagId) {
|
|
530
|
+
await doFetch(`${base}/v1/agents/${agentId}/tags/${tagId}`, {
|
|
531
|
+
method: "DELETE"
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
457
537
|
// src/api/agent-versions.ts
|
|
458
538
|
function createAgentVersionsApi(cfg) {
|
|
459
539
|
const { base, doFetch } = createHttp(cfg);
|
|
460
540
|
const jsonHeaders = { "content-type": "application/json" };
|
|
541
|
+
const fetchVersionsPage = async (agentId, opts = {}) => {
|
|
542
|
+
const { status, ...queryOptions } = opts ?? {};
|
|
543
|
+
const query = serializeListOptions(queryOptions, { status });
|
|
544
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
545
|
+
method: "GET",
|
|
546
|
+
query
|
|
547
|
+
});
|
|
548
|
+
return res.json();
|
|
549
|
+
};
|
|
461
550
|
return {
|
|
462
551
|
async list(agentId, opts = {}) {
|
|
463
|
-
const {
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
query
|
|
468
|
-
});
|
|
469
|
-
return res.json();
|
|
552
|
+
const normalizedOptions = { ...opts ?? {} };
|
|
553
|
+
const fetchPage = (options) => fetchVersionsPage(agentId, options);
|
|
554
|
+
const response = await fetchPage(normalizedOptions);
|
|
555
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
470
556
|
},
|
|
471
557
|
async get(agentId, versionId) {
|
|
472
558
|
const res = await doFetch(
|
|
@@ -495,6 +581,52 @@ function createAgentVersionsApi(cfg) {
|
|
|
495
581
|
}
|
|
496
582
|
);
|
|
497
583
|
return res.json();
|
|
584
|
+
},
|
|
585
|
+
async delete(agentId, versionId) {
|
|
586
|
+
await doFetch(`${base}/v1/agents/${agentId}/versions/${versionId}`, {
|
|
587
|
+
method: "DELETE"
|
|
588
|
+
});
|
|
589
|
+
},
|
|
590
|
+
async listInstructions(agentId, versionId, opts = {}) {
|
|
591
|
+
const query = serializeListOptions(opts);
|
|
592
|
+
const res = await doFetch(
|
|
593
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions`,
|
|
594
|
+
{
|
|
595
|
+
method: "GET",
|
|
596
|
+
query
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
return res.json();
|
|
600
|
+
},
|
|
601
|
+
async createInstruction(agentId, versionId, payload) {
|
|
602
|
+
const res = await doFetch(
|
|
603
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions`,
|
|
604
|
+
{
|
|
605
|
+
method: "POST",
|
|
606
|
+
headers: jsonHeaders,
|
|
607
|
+
body: JSON.stringify(payload)
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
return res.json();
|
|
611
|
+
},
|
|
612
|
+
async updateInstruction(agentId, versionId, instructionId, payload) {
|
|
613
|
+
const res = await doFetch(
|
|
614
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions/${instructionId}`,
|
|
615
|
+
{
|
|
616
|
+
method: "PATCH",
|
|
617
|
+
headers: jsonHeaders,
|
|
618
|
+
body: JSON.stringify(payload)
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
return res.json();
|
|
622
|
+
},
|
|
623
|
+
async deleteInstruction(agentId, versionId, instructionId) {
|
|
624
|
+
await doFetch(
|
|
625
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions/${instructionId}`,
|
|
626
|
+
{
|
|
627
|
+
method: "DELETE"
|
|
628
|
+
}
|
|
629
|
+
);
|
|
498
630
|
}
|
|
499
631
|
};
|
|
500
632
|
}
|
|
@@ -514,15 +646,12 @@ var bindAgentInstructions = (api, agentId) => ({
|
|
|
514
646
|
return api.delete(agentId, instructionId);
|
|
515
647
|
}
|
|
516
648
|
});
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
return api.
|
|
649
|
+
var bindAgentTags = (api, agentId) => ({
|
|
650
|
+
add(tagId) {
|
|
651
|
+
return api.add(agentId, { tagId });
|
|
520
652
|
},
|
|
521
|
-
|
|
522
|
-
return api.
|
|
523
|
-
},
|
|
524
|
-
listUploads(opts) {
|
|
525
|
-
return api.listUploads(agentId, opts);
|
|
653
|
+
remove(tagId) {
|
|
654
|
+
return api.remove(agentId, tagId);
|
|
526
655
|
}
|
|
527
656
|
});
|
|
528
657
|
var bindAgentPhones = (api, agentId) => ({
|
|
@@ -553,24 +682,56 @@ var bindAgentVersions = (api, agentId) => ({
|
|
|
553
682
|
},
|
|
554
683
|
update(versionId, payload) {
|
|
555
684
|
return api.update(agentId, versionId, payload);
|
|
685
|
+
},
|
|
686
|
+
delete(versionId) {
|
|
687
|
+
return api.delete(agentId, versionId);
|
|
688
|
+
},
|
|
689
|
+
instructions(versionId) {
|
|
690
|
+
return {
|
|
691
|
+
list(opts) {
|
|
692
|
+
return api.listInstructions(agentId, versionId, opts);
|
|
693
|
+
},
|
|
694
|
+
create(payload) {
|
|
695
|
+
return api.createInstruction(agentId, versionId, payload);
|
|
696
|
+
},
|
|
697
|
+
update(instructionId, payload) {
|
|
698
|
+
return api.updateInstruction(
|
|
699
|
+
agentId,
|
|
700
|
+
versionId,
|
|
701
|
+
instructionId,
|
|
702
|
+
payload
|
|
703
|
+
);
|
|
704
|
+
},
|
|
705
|
+
delete(instructionId) {
|
|
706
|
+
return api.deleteInstruction(agentId, versionId, instructionId);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
556
709
|
}
|
|
557
710
|
});
|
|
558
711
|
var createAgentEntity = (dto, options) => {
|
|
559
712
|
const {
|
|
560
713
|
instructionsApi,
|
|
561
|
-
|
|
714
|
+
tagsApi,
|
|
562
715
|
phonesApi,
|
|
563
716
|
scheduleApi,
|
|
564
717
|
versionsApi,
|
|
565
|
-
reload
|
|
718
|
+
reload,
|
|
719
|
+
updateAgent,
|
|
720
|
+
deleteAgent
|
|
566
721
|
} = options;
|
|
567
722
|
const entity = {
|
|
568
723
|
...dto,
|
|
569
724
|
instructions: bindAgentInstructions(instructionsApi, dto.agentId),
|
|
570
|
-
|
|
725
|
+
tagAssignments: bindAgentTags(tagsApi, dto.agentId),
|
|
571
726
|
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
572
727
|
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
573
728
|
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
729
|
+
async save(patch) {
|
|
730
|
+
return updateAgent(dto.agentId, patch);
|
|
731
|
+
},
|
|
732
|
+
async delete() {
|
|
733
|
+
await deleteAgent(dto.agentId);
|
|
734
|
+
},
|
|
574
735
|
async refresh() {
|
|
575
736
|
return reload(dto.agentId);
|
|
576
737
|
}
|
|
@@ -582,7 +743,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
582
743
|
function createAgentsApi(cfg, relatedApis) {
|
|
583
744
|
const { base, doFetch } = createHttp(cfg);
|
|
584
745
|
const jsonHeaders = { "content-type": "application/json" };
|
|
585
|
-
const
|
|
746
|
+
const fetchAgentsPage = async (options = {}) => {
|
|
586
747
|
const query = serializeListOptions(options);
|
|
587
748
|
const res = await doFetch(`${base}/v1/agents`, {
|
|
588
749
|
method: "GET",
|
|
@@ -590,6 +751,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
590
751
|
});
|
|
591
752
|
return res.json();
|
|
592
753
|
};
|
|
754
|
+
const listAgents = async (options = {}) => {
|
|
755
|
+
const normalizedOptions = { ...options ?? {} };
|
|
756
|
+
const response = await fetchAgentsPage(normalizedOptions);
|
|
757
|
+
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
758
|
+
};
|
|
593
759
|
const getAgentDetail = async (agentId) => {
|
|
594
760
|
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
595
761
|
method: "GET"
|
|
@@ -612,7 +778,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
612
778
|
});
|
|
613
779
|
return res.json();
|
|
614
780
|
};
|
|
615
|
-
const
|
|
781
|
+
const resolveAgentId = (agent) => {
|
|
782
|
+
return typeof agent === "string" ? agent : agent.agentId;
|
|
783
|
+
};
|
|
784
|
+
const deleteAgent = async (agent) => {
|
|
785
|
+
const agentId = resolveAgentId(agent);
|
|
616
786
|
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
617
787
|
method: "DELETE"
|
|
618
788
|
});
|
|
@@ -629,24 +799,36 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
629
799
|
}
|
|
630
800
|
const wrapAgent = (detail) => createAgentEntity(detail, {
|
|
631
801
|
instructionsApi: relatedApis.instructionsApi,
|
|
632
|
-
|
|
802
|
+
tagsApi: relatedApis.tagsApi,
|
|
633
803
|
phonesApi: relatedApis.phonesApi,
|
|
634
804
|
scheduleApi: relatedApis.scheduleApi,
|
|
635
805
|
versionsApi: relatedApis.versionsApi,
|
|
636
806
|
reload: async (agentId) => {
|
|
637
807
|
const latest = await getAgentDetail(agentId);
|
|
638
808
|
return wrapAgent(latest);
|
|
809
|
+
},
|
|
810
|
+
updateAgent: async (agentId, payload) => {
|
|
811
|
+
const updated = await updateAgent(agentId, payload);
|
|
812
|
+
return wrapAgent(updated);
|
|
813
|
+
},
|
|
814
|
+
deleteAgent: async (agentId) => {
|
|
815
|
+
await deleteAgent(agentId);
|
|
639
816
|
}
|
|
640
817
|
});
|
|
641
818
|
return {
|
|
642
819
|
...baseApi,
|
|
643
820
|
async list(options = {}) {
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
821
|
+
const normalizedOptions = { ...options ?? {} };
|
|
822
|
+
const applyWrap = async (opts) => {
|
|
823
|
+
const result = await fetchAgentsPage(opts);
|
|
824
|
+
const items = Array.isArray(result.data) ? result.data : [];
|
|
825
|
+
return {
|
|
826
|
+
...result,
|
|
827
|
+
data: items.map((summary) => wrapAgent(summary))
|
|
828
|
+
};
|
|
649
829
|
};
|
|
830
|
+
const initial = await applyWrap(normalizedOptions);
|
|
831
|
+
return attachPaginator(initial, applyWrap, normalizedOptions);
|
|
650
832
|
},
|
|
651
833
|
async get(agentId) {
|
|
652
834
|
const detail = await getAgentDetail(agentId);
|
|
@@ -664,18 +846,88 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
664
846
|
}
|
|
665
847
|
|
|
666
848
|
// src/api/tools.ts
|
|
849
|
+
var isFormData = (value) => {
|
|
850
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
851
|
+
};
|
|
852
|
+
var toFormData = (payload) => {
|
|
853
|
+
if (isFormData(payload)) {
|
|
854
|
+
return payload;
|
|
855
|
+
}
|
|
856
|
+
if (typeof FormData === "undefined") {
|
|
857
|
+
throw new TypeError(
|
|
858
|
+
"FormData is not available in this environment. Pass a FormData instance instead."
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
const formData = new FormData();
|
|
862
|
+
formData.append("file", payload.file);
|
|
863
|
+
if (payload.type) {
|
|
864
|
+
formData.append("type", payload.type);
|
|
865
|
+
}
|
|
866
|
+
if (payload.title) {
|
|
867
|
+
formData.append("title", payload.title);
|
|
868
|
+
}
|
|
869
|
+
if (payload.metadata) {
|
|
870
|
+
formData.append("metadata", JSON.stringify(payload.metadata));
|
|
871
|
+
}
|
|
872
|
+
return formData;
|
|
873
|
+
};
|
|
667
874
|
function createToolsApi(cfg) {
|
|
668
875
|
const { base, doFetch } = createHttp(cfg);
|
|
669
876
|
const jsonHeaders = { "content-type": "application/json" };
|
|
877
|
+
const fetchToolsPage = async (options = {}) => {
|
|
878
|
+
const { agentType, ...queryOptions } = options ?? {};
|
|
879
|
+
const query = serializeListOptions(queryOptions, { agentType });
|
|
880
|
+
const res = await doFetch(`${base}/v1/tools`, {
|
|
881
|
+
method: "GET",
|
|
882
|
+
query
|
|
883
|
+
});
|
|
884
|
+
return res.json();
|
|
885
|
+
};
|
|
886
|
+
const fetchToolResourcesPage = async (toolId, options = {}) => {
|
|
887
|
+
const { type, ...queryOptions } = options ?? {};
|
|
888
|
+
const query = serializeListOptions(queryOptions, { type });
|
|
889
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/resources`, {
|
|
890
|
+
method: "GET",
|
|
891
|
+
query
|
|
892
|
+
});
|
|
893
|
+
return res.json();
|
|
894
|
+
};
|
|
670
895
|
return {
|
|
671
896
|
async list(options = {}) {
|
|
672
|
-
const
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
|
|
897
|
+
const normalizedOptions = { ...options ?? {} };
|
|
898
|
+
const response = await fetchToolsPage(normalizedOptions);
|
|
899
|
+
return attachPaginator(response, fetchToolsPage, normalizedOptions);
|
|
900
|
+
},
|
|
901
|
+
async listResources(toolId, options = {}) {
|
|
902
|
+
const normalizedOptions = {
|
|
903
|
+
...options ?? {}
|
|
904
|
+
};
|
|
905
|
+
const fetchPage = (opts) => fetchToolResourcesPage(toolId, opts);
|
|
906
|
+
const response = await fetchPage(normalizedOptions);
|
|
907
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
908
|
+
},
|
|
909
|
+
async uploadResource(toolId, payload) {
|
|
910
|
+
const formData = toFormData(payload);
|
|
911
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/resources`, {
|
|
912
|
+
method: "POST",
|
|
913
|
+
body: formData
|
|
676
914
|
});
|
|
677
915
|
return res.json();
|
|
678
916
|
},
|
|
917
|
+
async deleteResource(toolId, resourceId) {
|
|
918
|
+
await doFetch(`${base}/v1/tools/${toolId}/resources/${resourceId}`, {
|
|
919
|
+
method: "DELETE"
|
|
920
|
+
});
|
|
921
|
+
},
|
|
922
|
+
async reloadResource(toolId, resourceId) {
|
|
923
|
+
const res = await doFetch(
|
|
924
|
+
`${base}/v1/tools/${toolId}/resources/${resourceId}/reload`,
|
|
925
|
+
{
|
|
926
|
+
method: "POST"
|
|
927
|
+
}
|
|
928
|
+
);
|
|
929
|
+
return res.json();
|
|
930
|
+
},
|
|
679
931
|
async execute(toolId, payload) {
|
|
680
932
|
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
681
933
|
method: "POST",
|
|
@@ -683,6 +935,14 @@ function createToolsApi(cfg) {
|
|
|
683
935
|
body: JSON.stringify(payload)
|
|
684
936
|
});
|
|
685
937
|
return res.json();
|
|
938
|
+
},
|
|
939
|
+
async connect(toolId, payload) {
|
|
940
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/connect`, {
|
|
941
|
+
method: "POST",
|
|
942
|
+
headers: jsonHeaders,
|
|
943
|
+
body: JSON.stringify(payload)
|
|
944
|
+
});
|
|
945
|
+
return res.json();
|
|
686
946
|
}
|
|
687
947
|
};
|
|
688
948
|
}
|
|
@@ -690,32 +950,37 @@ function createToolsApi(cfg) {
|
|
|
690
950
|
// src/api/voices.ts
|
|
691
951
|
function createVoicesApi(cfg) {
|
|
692
952
|
const { base, doFetch } = createHttp(cfg);
|
|
953
|
+
const fetchVoicesPage = async (options = {}) => {
|
|
954
|
+
const { agentId, agentVersionId, gender, locale } = options;
|
|
955
|
+
const query = serializeListOptions(
|
|
956
|
+
{
|
|
957
|
+
page: options.page,
|
|
958
|
+
limit: options.limit ?? options.pageSize,
|
|
959
|
+
sort: options.sort,
|
|
960
|
+
fields: options.fields,
|
|
961
|
+
include: options.include,
|
|
962
|
+
search: options.search,
|
|
963
|
+
filter: options.filter,
|
|
964
|
+
or: options.or
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
agentId,
|
|
968
|
+
agentVersionId,
|
|
969
|
+
gender,
|
|
970
|
+
locale
|
|
971
|
+
}
|
|
972
|
+
);
|
|
973
|
+
const res = await doFetch(`${base}/v1/voices`, {
|
|
974
|
+
method: "GET",
|
|
975
|
+
query
|
|
976
|
+
});
|
|
977
|
+
return res.json();
|
|
978
|
+
};
|
|
693
979
|
return {
|
|
694
980
|
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();
|
|
981
|
+
const normalizedOptions = { ...options ?? {} };
|
|
982
|
+
const response = await fetchVoicesPage(normalizedOptions);
|
|
983
|
+
return attachPaginator(response, fetchVoicesPage, normalizedOptions);
|
|
719
984
|
}
|
|
720
985
|
};
|
|
721
986
|
}
|
|
@@ -724,27 +989,35 @@ function createVoicesApi(cfg) {
|
|
|
724
989
|
function createWorkspacesApi(cfg) {
|
|
725
990
|
const { base, doFetch } = createHttp(cfg);
|
|
726
991
|
const jsonHeaders = { "content-type": "application/json" };
|
|
992
|
+
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
993
|
+
const { channel } = opts ?? {};
|
|
994
|
+
const query = serializeListOptions(
|
|
995
|
+
{
|
|
996
|
+
page: opts.page,
|
|
997
|
+
limit: opts.limit,
|
|
998
|
+
sort: opts.sort,
|
|
999
|
+
fields: opts.fields,
|
|
1000
|
+
include: opts.include,
|
|
1001
|
+
search: opts.search,
|
|
1002
|
+
filter: opts.filter,
|
|
1003
|
+
or: opts.or
|
|
1004
|
+
},
|
|
1005
|
+
{ channel }
|
|
1006
|
+
);
|
|
1007
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
1008
|
+
method: "GET",
|
|
1009
|
+
query
|
|
1010
|
+
});
|
|
1011
|
+
return res.json();
|
|
1012
|
+
};
|
|
727
1013
|
return {
|
|
728
1014
|
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();
|
|
1015
|
+
const normalizedOptions = {
|
|
1016
|
+
...opts ?? {}
|
|
1017
|
+
};
|
|
1018
|
+
const response = await fetchPhonesPage(workspaceId, normalizedOptions);
|
|
1019
|
+
const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
|
|
1020
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
748
1021
|
},
|
|
749
1022
|
async enable(workspaceId, payload) {
|
|
750
1023
|
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
|
|
@@ -770,14 +1043,14 @@ function createClient(initialCfg) {
|
|
|
770
1043
|
runtimeCfg.getWorkspaceId = getter;
|
|
771
1044
|
};
|
|
772
1045
|
const instructionsApi = createAgentInstructionsApi(runtimeCfg);
|
|
773
|
-
const
|
|
1046
|
+
const tagsApi = createAgentTagsApi(runtimeCfg);
|
|
774
1047
|
const phonesApi = createAgentPhonesApi(runtimeCfg);
|
|
775
1048
|
const scheduleApi = createAgentScheduleApi(runtimeCfg);
|
|
776
1049
|
const versionsApi = createAgentVersionsApi(runtimeCfg);
|
|
777
1050
|
const voicesApi = createVoicesApi(runtimeCfg);
|
|
778
1051
|
const agentsApi = createAgentsApi(runtimeCfg, {
|
|
779
1052
|
instructionsApi,
|
|
780
|
-
|
|
1053
|
+
tagsApi,
|
|
781
1054
|
phonesApi,
|
|
782
1055
|
scheduleApi,
|
|
783
1056
|
versionsApi
|
|
@@ -785,8 +1058,8 @@ function createClient(initialCfg) {
|
|
|
785
1058
|
const apis = {
|
|
786
1059
|
agents: {
|
|
787
1060
|
...agentsApi,
|
|
788
|
-
knowledge: knowledgeApi,
|
|
789
1061
|
instructions: instructionsApi,
|
|
1062
|
+
tags: tagsApi,
|
|
790
1063
|
phones: phonesApi,
|
|
791
1064
|
schedule: scheduleApi,
|
|
792
1065
|
versions: versionsApi
|
|
@@ -826,15 +1099,15 @@ function createClient(initialCfg) {
|
|
|
826
1099
|
NetworkError,
|
|
827
1100
|
TimeoutError,
|
|
828
1101
|
bindAgentInstructions,
|
|
829
|
-
bindAgentKnowledge,
|
|
830
1102
|
bindAgentPhones,
|
|
831
1103
|
bindAgentSchedule,
|
|
1104
|
+
bindAgentTags,
|
|
832
1105
|
bindAgentVersions,
|
|
833
1106
|
createAgentEntity,
|
|
834
1107
|
createAgentInstructionsApi,
|
|
835
|
-
createAgentKnowledgeApi,
|
|
836
1108
|
createAgentPhonesApi,
|
|
837
1109
|
createAgentScheduleApi,
|
|
1110
|
+
createAgentTagsApi,
|
|
838
1111
|
createAgentVersionsApi,
|
|
839
1112
|
createAgentsApi,
|
|
840
1113
|
createClient,
|