@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.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`, {
|
|
@@ -326,47 +426,6 @@ function createAgentInstructionsApi(cfg) {
|
|
|
326
426
|
};
|
|
327
427
|
}
|
|
328
428
|
|
|
329
|
-
// src/api/agent-knowledge.ts
|
|
330
|
-
function createAgentKnowledgeApi(cfg) {
|
|
331
|
-
const { base, doFetch } = createHttp(cfg);
|
|
332
|
-
const jsonHeaders = { "content-type": "application/json" };
|
|
333
|
-
return {
|
|
334
|
-
async upload(agentId, payload) {
|
|
335
|
-
const res = await doFetch(
|
|
336
|
-
`${base}/v1/agents/${agentId}/knowledge/upload`,
|
|
337
|
-
{
|
|
338
|
-
method: "POST",
|
|
339
|
-
headers: jsonHeaders,
|
|
340
|
-
body: JSON.stringify(payload)
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
return res.json();
|
|
344
|
-
},
|
|
345
|
-
async listBases(agentId, opts = {}) {
|
|
346
|
-
const query = serializeListOptions(opts);
|
|
347
|
-
const res = await doFetch(
|
|
348
|
-
`${base}/v1/agents/${agentId}/knowledge/bases`,
|
|
349
|
-
{
|
|
350
|
-
method: "GET",
|
|
351
|
-
query
|
|
352
|
-
}
|
|
353
|
-
);
|
|
354
|
-
return res.json();
|
|
355
|
-
},
|
|
356
|
-
async listUploads(agentId, opts = {}) {
|
|
357
|
-
const query = serializeListOptions(opts);
|
|
358
|
-
const res = await doFetch(
|
|
359
|
-
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
360
|
-
{
|
|
361
|
-
method: "GET",
|
|
362
|
-
query
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
return res.json();
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
429
|
// src/api/agent-phones.ts
|
|
371
430
|
function createAgentPhonesApi(cfg) {
|
|
372
431
|
const { base, doFetch } = createHttp(cfg);
|
|
@@ -410,19 +469,46 @@ function createAgentScheduleApi(cfg) {
|
|
|
410
469
|
};
|
|
411
470
|
}
|
|
412
471
|
|
|
472
|
+
// src/api/agent-tags.ts
|
|
473
|
+
function createAgentTagsApi(cfg) {
|
|
474
|
+
const { base, doFetch } = createHttp(cfg);
|
|
475
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
476
|
+
return {
|
|
477
|
+
async add(agentId, payload) {
|
|
478
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/tags`, {
|
|
479
|
+
method: "POST",
|
|
480
|
+
headers: jsonHeaders,
|
|
481
|
+
body: JSON.stringify(payload)
|
|
482
|
+
});
|
|
483
|
+
return res.json();
|
|
484
|
+
},
|
|
485
|
+
async remove(agentId, tagId) {
|
|
486
|
+
await doFetch(`${base}/v1/agents/${agentId}/tags/${tagId}`, {
|
|
487
|
+
method: "DELETE"
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
413
493
|
// src/api/agent-versions.ts
|
|
414
494
|
function createAgentVersionsApi(cfg) {
|
|
415
495
|
const { base, doFetch } = createHttp(cfg);
|
|
416
496
|
const jsonHeaders = { "content-type": "application/json" };
|
|
497
|
+
const fetchVersionsPage = async (agentId, opts = {}) => {
|
|
498
|
+
const { status, ...queryOptions } = opts ?? {};
|
|
499
|
+
const query = serializeListOptions(queryOptions, { status });
|
|
500
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
501
|
+
method: "GET",
|
|
502
|
+
query
|
|
503
|
+
});
|
|
504
|
+
return res.json();
|
|
505
|
+
};
|
|
417
506
|
return {
|
|
418
507
|
async list(agentId, opts = {}) {
|
|
419
|
-
const {
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
query
|
|
424
|
-
});
|
|
425
|
-
return res.json();
|
|
508
|
+
const normalizedOptions = { ...opts ?? {} };
|
|
509
|
+
const fetchPage = (options) => fetchVersionsPage(agentId, options);
|
|
510
|
+
const response = await fetchPage(normalizedOptions);
|
|
511
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
426
512
|
},
|
|
427
513
|
async get(agentId, versionId) {
|
|
428
514
|
const res = await doFetch(
|
|
@@ -451,6 +537,52 @@ function createAgentVersionsApi(cfg) {
|
|
|
451
537
|
}
|
|
452
538
|
);
|
|
453
539
|
return res.json();
|
|
540
|
+
},
|
|
541
|
+
async delete(agentId, versionId) {
|
|
542
|
+
await doFetch(`${base}/v1/agents/${agentId}/versions/${versionId}`, {
|
|
543
|
+
method: "DELETE"
|
|
544
|
+
});
|
|
545
|
+
},
|
|
546
|
+
async listInstructions(agentId, versionId, opts = {}) {
|
|
547
|
+
const query = serializeListOptions(opts);
|
|
548
|
+
const res = await doFetch(
|
|
549
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions`,
|
|
550
|
+
{
|
|
551
|
+
method: "GET",
|
|
552
|
+
query
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
return res.json();
|
|
556
|
+
},
|
|
557
|
+
async createInstruction(agentId, versionId, payload) {
|
|
558
|
+
const res = await doFetch(
|
|
559
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions`,
|
|
560
|
+
{
|
|
561
|
+
method: "POST",
|
|
562
|
+
headers: jsonHeaders,
|
|
563
|
+
body: JSON.stringify(payload)
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
return res.json();
|
|
567
|
+
},
|
|
568
|
+
async updateInstruction(agentId, versionId, instructionId, payload) {
|
|
569
|
+
const res = await doFetch(
|
|
570
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions/${instructionId}`,
|
|
571
|
+
{
|
|
572
|
+
method: "PATCH",
|
|
573
|
+
headers: jsonHeaders,
|
|
574
|
+
body: JSON.stringify(payload)
|
|
575
|
+
}
|
|
576
|
+
);
|
|
577
|
+
return res.json();
|
|
578
|
+
},
|
|
579
|
+
async deleteInstruction(agentId, versionId, instructionId) {
|
|
580
|
+
await doFetch(
|
|
581
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/instructions/${instructionId}`,
|
|
582
|
+
{
|
|
583
|
+
method: "DELETE"
|
|
584
|
+
}
|
|
585
|
+
);
|
|
454
586
|
}
|
|
455
587
|
};
|
|
456
588
|
}
|
|
@@ -470,15 +602,12 @@ var bindAgentInstructions = (api, agentId) => ({
|
|
|
470
602
|
return api.delete(agentId, instructionId);
|
|
471
603
|
}
|
|
472
604
|
});
|
|
473
|
-
var
|
|
474
|
-
|
|
475
|
-
return api.
|
|
605
|
+
var bindAgentTags = (api, agentId) => ({
|
|
606
|
+
add(tagId) {
|
|
607
|
+
return api.add(agentId, { tagId });
|
|
476
608
|
},
|
|
477
|
-
|
|
478
|
-
return api.
|
|
479
|
-
},
|
|
480
|
-
listUploads(opts) {
|
|
481
|
-
return api.listUploads(agentId, opts);
|
|
609
|
+
remove(tagId) {
|
|
610
|
+
return api.remove(agentId, tagId);
|
|
482
611
|
}
|
|
483
612
|
});
|
|
484
613
|
var bindAgentPhones = (api, agentId) => ({
|
|
@@ -509,24 +638,56 @@ var bindAgentVersions = (api, agentId) => ({
|
|
|
509
638
|
},
|
|
510
639
|
update(versionId, payload) {
|
|
511
640
|
return api.update(agentId, versionId, payload);
|
|
641
|
+
},
|
|
642
|
+
delete(versionId) {
|
|
643
|
+
return api.delete(agentId, versionId);
|
|
644
|
+
},
|
|
645
|
+
instructions(versionId) {
|
|
646
|
+
return {
|
|
647
|
+
list(opts) {
|
|
648
|
+
return api.listInstructions(agentId, versionId, opts);
|
|
649
|
+
},
|
|
650
|
+
create(payload) {
|
|
651
|
+
return api.createInstruction(agentId, versionId, payload);
|
|
652
|
+
},
|
|
653
|
+
update(instructionId, payload) {
|
|
654
|
+
return api.updateInstruction(
|
|
655
|
+
agentId,
|
|
656
|
+
versionId,
|
|
657
|
+
instructionId,
|
|
658
|
+
payload
|
|
659
|
+
);
|
|
660
|
+
},
|
|
661
|
+
delete(instructionId) {
|
|
662
|
+
return api.deleteInstruction(agentId, versionId, instructionId);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
512
665
|
}
|
|
513
666
|
});
|
|
514
667
|
var createAgentEntity = (dto, options) => {
|
|
515
668
|
const {
|
|
516
669
|
instructionsApi,
|
|
517
|
-
|
|
670
|
+
tagsApi,
|
|
518
671
|
phonesApi,
|
|
519
672
|
scheduleApi,
|
|
520
673
|
versionsApi,
|
|
521
|
-
reload
|
|
674
|
+
reload,
|
|
675
|
+
updateAgent,
|
|
676
|
+
deleteAgent
|
|
522
677
|
} = options;
|
|
523
678
|
const entity = {
|
|
524
679
|
...dto,
|
|
525
680
|
instructions: bindAgentInstructions(instructionsApi, dto.agentId),
|
|
526
|
-
|
|
681
|
+
tagAssignments: bindAgentTags(tagsApi, dto.agentId),
|
|
527
682
|
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
528
683
|
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
529
684
|
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
685
|
+
async save(patch) {
|
|
686
|
+
return updateAgent(dto.agentId, patch);
|
|
687
|
+
},
|
|
688
|
+
async delete() {
|
|
689
|
+
await deleteAgent(dto.agentId);
|
|
690
|
+
},
|
|
530
691
|
async refresh() {
|
|
531
692
|
return reload(dto.agentId);
|
|
532
693
|
}
|
|
@@ -538,7 +699,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
538
699
|
function createAgentsApi(cfg, relatedApis) {
|
|
539
700
|
const { base, doFetch } = createHttp(cfg);
|
|
540
701
|
const jsonHeaders = { "content-type": "application/json" };
|
|
541
|
-
const
|
|
702
|
+
const fetchAgentsPage = async (options = {}) => {
|
|
542
703
|
const query = serializeListOptions(options);
|
|
543
704
|
const res = await doFetch(`${base}/v1/agents`, {
|
|
544
705
|
method: "GET",
|
|
@@ -546,6 +707,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
546
707
|
});
|
|
547
708
|
return res.json();
|
|
548
709
|
};
|
|
710
|
+
const listAgents = async (options = {}) => {
|
|
711
|
+
const normalizedOptions = { ...options ?? {} };
|
|
712
|
+
const response = await fetchAgentsPage(normalizedOptions);
|
|
713
|
+
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
714
|
+
};
|
|
549
715
|
const getAgentDetail = async (agentId) => {
|
|
550
716
|
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
551
717
|
method: "GET"
|
|
@@ -568,7 +734,11 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
568
734
|
});
|
|
569
735
|
return res.json();
|
|
570
736
|
};
|
|
571
|
-
const
|
|
737
|
+
const resolveAgentId = (agent) => {
|
|
738
|
+
return typeof agent === "string" ? agent : agent.agentId;
|
|
739
|
+
};
|
|
740
|
+
const deleteAgent = async (agent) => {
|
|
741
|
+
const agentId = resolveAgentId(agent);
|
|
572
742
|
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
573
743
|
method: "DELETE"
|
|
574
744
|
});
|
|
@@ -585,24 +755,36 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
585
755
|
}
|
|
586
756
|
const wrapAgent = (detail) => createAgentEntity(detail, {
|
|
587
757
|
instructionsApi: relatedApis.instructionsApi,
|
|
588
|
-
|
|
758
|
+
tagsApi: relatedApis.tagsApi,
|
|
589
759
|
phonesApi: relatedApis.phonesApi,
|
|
590
760
|
scheduleApi: relatedApis.scheduleApi,
|
|
591
761
|
versionsApi: relatedApis.versionsApi,
|
|
592
762
|
reload: async (agentId) => {
|
|
593
763
|
const latest = await getAgentDetail(agentId);
|
|
594
764
|
return wrapAgent(latest);
|
|
765
|
+
},
|
|
766
|
+
updateAgent: async (agentId, payload) => {
|
|
767
|
+
const updated = await updateAgent(agentId, payload);
|
|
768
|
+
return wrapAgent(updated);
|
|
769
|
+
},
|
|
770
|
+
deleteAgent: async (agentId) => {
|
|
771
|
+
await deleteAgent(agentId);
|
|
595
772
|
}
|
|
596
773
|
});
|
|
597
774
|
return {
|
|
598
775
|
...baseApi,
|
|
599
776
|
async list(options = {}) {
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
777
|
+
const normalizedOptions = { ...options ?? {} };
|
|
778
|
+
const applyWrap = async (opts) => {
|
|
779
|
+
const result = await fetchAgentsPage(opts);
|
|
780
|
+
const items = Array.isArray(result.data) ? result.data : [];
|
|
781
|
+
return {
|
|
782
|
+
...result,
|
|
783
|
+
data: items.map((summary) => wrapAgent(summary))
|
|
784
|
+
};
|
|
605
785
|
};
|
|
786
|
+
const initial = await applyWrap(normalizedOptions);
|
|
787
|
+
return attachPaginator(initial, applyWrap, normalizedOptions);
|
|
606
788
|
},
|
|
607
789
|
async get(agentId) {
|
|
608
790
|
const detail = await getAgentDetail(agentId);
|
|
@@ -620,18 +802,88 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
620
802
|
}
|
|
621
803
|
|
|
622
804
|
// src/api/tools.ts
|
|
805
|
+
var isFormData = (value) => {
|
|
806
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
807
|
+
};
|
|
808
|
+
var toFormData = (payload) => {
|
|
809
|
+
if (isFormData(payload)) {
|
|
810
|
+
return payload;
|
|
811
|
+
}
|
|
812
|
+
if (typeof FormData === "undefined") {
|
|
813
|
+
throw new TypeError(
|
|
814
|
+
"FormData is not available in this environment. Pass a FormData instance instead."
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const formData = new FormData();
|
|
818
|
+
formData.append("file", payload.file);
|
|
819
|
+
if (payload.type) {
|
|
820
|
+
formData.append("type", payload.type);
|
|
821
|
+
}
|
|
822
|
+
if (payload.title) {
|
|
823
|
+
formData.append("title", payload.title);
|
|
824
|
+
}
|
|
825
|
+
if (payload.metadata) {
|
|
826
|
+
formData.append("metadata", JSON.stringify(payload.metadata));
|
|
827
|
+
}
|
|
828
|
+
return formData;
|
|
829
|
+
};
|
|
623
830
|
function createToolsApi(cfg) {
|
|
624
831
|
const { base, doFetch } = createHttp(cfg);
|
|
625
832
|
const jsonHeaders = { "content-type": "application/json" };
|
|
833
|
+
const fetchToolsPage = async (options = {}) => {
|
|
834
|
+
const { agentType, ...queryOptions } = options ?? {};
|
|
835
|
+
const query = serializeListOptions(queryOptions, { agentType });
|
|
836
|
+
const res = await doFetch(`${base}/v1/tools`, {
|
|
837
|
+
method: "GET",
|
|
838
|
+
query
|
|
839
|
+
});
|
|
840
|
+
return res.json();
|
|
841
|
+
};
|
|
842
|
+
const fetchToolResourcesPage = async (toolId, options = {}) => {
|
|
843
|
+
const { type, ...queryOptions } = options ?? {};
|
|
844
|
+
const query = serializeListOptions(queryOptions, { type });
|
|
845
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/resources`, {
|
|
846
|
+
method: "GET",
|
|
847
|
+
query
|
|
848
|
+
});
|
|
849
|
+
return res.json();
|
|
850
|
+
};
|
|
626
851
|
return {
|
|
627
852
|
async list(options = {}) {
|
|
628
|
-
const
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
853
|
+
const normalizedOptions = { ...options ?? {} };
|
|
854
|
+
const response = await fetchToolsPage(normalizedOptions);
|
|
855
|
+
return attachPaginator(response, fetchToolsPage, normalizedOptions);
|
|
856
|
+
},
|
|
857
|
+
async listResources(toolId, options = {}) {
|
|
858
|
+
const normalizedOptions = {
|
|
859
|
+
...options ?? {}
|
|
860
|
+
};
|
|
861
|
+
const fetchPage = (opts) => fetchToolResourcesPage(toolId, opts);
|
|
862
|
+
const response = await fetchPage(normalizedOptions);
|
|
863
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
864
|
+
},
|
|
865
|
+
async uploadResource(toolId, payload) {
|
|
866
|
+
const formData = toFormData(payload);
|
|
867
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/resources`, {
|
|
868
|
+
method: "POST",
|
|
869
|
+
body: formData
|
|
632
870
|
});
|
|
633
871
|
return res.json();
|
|
634
872
|
},
|
|
873
|
+
async deleteResource(toolId, resourceId) {
|
|
874
|
+
await doFetch(`${base}/v1/tools/${toolId}/resources/${resourceId}`, {
|
|
875
|
+
method: "DELETE"
|
|
876
|
+
});
|
|
877
|
+
},
|
|
878
|
+
async reloadResource(toolId, resourceId) {
|
|
879
|
+
const res = await doFetch(
|
|
880
|
+
`${base}/v1/tools/${toolId}/resources/${resourceId}/reload`,
|
|
881
|
+
{
|
|
882
|
+
method: "POST"
|
|
883
|
+
}
|
|
884
|
+
);
|
|
885
|
+
return res.json();
|
|
886
|
+
},
|
|
635
887
|
async execute(toolId, payload) {
|
|
636
888
|
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
637
889
|
method: "POST",
|
|
@@ -639,6 +891,14 @@ function createToolsApi(cfg) {
|
|
|
639
891
|
body: JSON.stringify(payload)
|
|
640
892
|
});
|
|
641
893
|
return res.json();
|
|
894
|
+
},
|
|
895
|
+
async connect(toolId, payload) {
|
|
896
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/connect`, {
|
|
897
|
+
method: "POST",
|
|
898
|
+
headers: jsonHeaders,
|
|
899
|
+
body: JSON.stringify(payload)
|
|
900
|
+
});
|
|
901
|
+
return res.json();
|
|
642
902
|
}
|
|
643
903
|
};
|
|
644
904
|
}
|
|
@@ -646,32 +906,37 @@ function createToolsApi(cfg) {
|
|
|
646
906
|
// src/api/voices.ts
|
|
647
907
|
function createVoicesApi(cfg) {
|
|
648
908
|
const { base, doFetch } = createHttp(cfg);
|
|
909
|
+
const fetchVoicesPage = async (options = {}) => {
|
|
910
|
+
const { agentId, agentVersionId, gender, locale } = options;
|
|
911
|
+
const query = serializeListOptions(
|
|
912
|
+
{
|
|
913
|
+
page: options.page,
|
|
914
|
+
limit: options.limit ?? options.pageSize,
|
|
915
|
+
sort: options.sort,
|
|
916
|
+
fields: options.fields,
|
|
917
|
+
include: options.include,
|
|
918
|
+
search: options.search,
|
|
919
|
+
filter: options.filter,
|
|
920
|
+
or: options.or
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
agentId,
|
|
924
|
+
agentVersionId,
|
|
925
|
+
gender,
|
|
926
|
+
locale
|
|
927
|
+
}
|
|
928
|
+
);
|
|
929
|
+
const res = await doFetch(`${base}/v1/voices`, {
|
|
930
|
+
method: "GET",
|
|
931
|
+
query
|
|
932
|
+
});
|
|
933
|
+
return res.json();
|
|
934
|
+
};
|
|
649
935
|
return {
|
|
650
936
|
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();
|
|
937
|
+
const normalizedOptions = { ...options ?? {} };
|
|
938
|
+
const response = await fetchVoicesPage(normalizedOptions);
|
|
939
|
+
return attachPaginator(response, fetchVoicesPage, normalizedOptions);
|
|
675
940
|
}
|
|
676
941
|
};
|
|
677
942
|
}
|
|
@@ -680,27 +945,35 @@ function createVoicesApi(cfg) {
|
|
|
680
945
|
function createWorkspacesApi(cfg) {
|
|
681
946
|
const { base, doFetch } = createHttp(cfg);
|
|
682
947
|
const jsonHeaders = { "content-type": "application/json" };
|
|
948
|
+
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
949
|
+
const { channel } = opts ?? {};
|
|
950
|
+
const query = serializeListOptions(
|
|
951
|
+
{
|
|
952
|
+
page: opts.page,
|
|
953
|
+
limit: opts.limit,
|
|
954
|
+
sort: opts.sort,
|
|
955
|
+
fields: opts.fields,
|
|
956
|
+
include: opts.include,
|
|
957
|
+
search: opts.search,
|
|
958
|
+
filter: opts.filter,
|
|
959
|
+
or: opts.or
|
|
960
|
+
},
|
|
961
|
+
{ channel }
|
|
962
|
+
);
|
|
963
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
964
|
+
method: "GET",
|
|
965
|
+
query
|
|
966
|
+
});
|
|
967
|
+
return res.json();
|
|
968
|
+
};
|
|
683
969
|
return {
|
|
684
970
|
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();
|
|
971
|
+
const normalizedOptions = {
|
|
972
|
+
...opts ?? {}
|
|
973
|
+
};
|
|
974
|
+
const response = await fetchPhonesPage(workspaceId, normalizedOptions);
|
|
975
|
+
const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
|
|
976
|
+
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
704
977
|
},
|
|
705
978
|
async enable(workspaceId, payload) {
|
|
706
979
|
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
|
|
@@ -726,14 +999,14 @@ function createClient(initialCfg) {
|
|
|
726
999
|
runtimeCfg.getWorkspaceId = getter;
|
|
727
1000
|
};
|
|
728
1001
|
const instructionsApi = createAgentInstructionsApi(runtimeCfg);
|
|
729
|
-
const
|
|
1002
|
+
const tagsApi = createAgentTagsApi(runtimeCfg);
|
|
730
1003
|
const phonesApi = createAgentPhonesApi(runtimeCfg);
|
|
731
1004
|
const scheduleApi = createAgentScheduleApi(runtimeCfg);
|
|
732
1005
|
const versionsApi = createAgentVersionsApi(runtimeCfg);
|
|
733
1006
|
const voicesApi = createVoicesApi(runtimeCfg);
|
|
734
1007
|
const agentsApi = createAgentsApi(runtimeCfg, {
|
|
735
1008
|
instructionsApi,
|
|
736
|
-
|
|
1009
|
+
tagsApi,
|
|
737
1010
|
phonesApi,
|
|
738
1011
|
scheduleApi,
|
|
739
1012
|
versionsApi
|
|
@@ -741,8 +1014,8 @@ function createClient(initialCfg) {
|
|
|
741
1014
|
const apis = {
|
|
742
1015
|
agents: {
|
|
743
1016
|
...agentsApi,
|
|
744
|
-
knowledge: knowledgeApi,
|
|
745
1017
|
instructions: instructionsApi,
|
|
1018
|
+
tags: tagsApi,
|
|
746
1019
|
phones: phonesApi,
|
|
747
1020
|
schedule: scheduleApi,
|
|
748
1021
|
versions: versionsApi
|
|
@@ -781,15 +1054,15 @@ export {
|
|
|
781
1054
|
NetworkError,
|
|
782
1055
|
TimeoutError,
|
|
783
1056
|
bindAgentInstructions,
|
|
784
|
-
bindAgentKnowledge,
|
|
785
1057
|
bindAgentPhones,
|
|
786
1058
|
bindAgentSchedule,
|
|
1059
|
+
bindAgentTags,
|
|
787
1060
|
bindAgentVersions,
|
|
788
1061
|
createAgentEntity,
|
|
789
1062
|
createAgentInstructionsApi,
|
|
790
|
-
createAgentKnowledgeApi,
|
|
791
1063
|
createAgentPhonesApi,
|
|
792
1064
|
createAgentScheduleApi,
|
|
1065
|
+
createAgentTagsApi,
|
|
793
1066
|
createAgentVersionsApi,
|
|
794
1067
|
createAgentsApi,
|
|
795
1068
|
createClient,
|