@getsupervisor/agents-studio-sdk 1.22.1 → 1.23.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 CHANGED
@@ -509,6 +509,69 @@ function createAgentPhonesApi(cfg) {
509
509
  };
510
510
  }
511
511
 
512
+ // src/api/agent-schedule-exceptions.ts
513
+ function createAgentScheduleExceptionsApi(cfg) {
514
+ const { base, doFetch } = createHttp(cfg);
515
+ const jsonHeaders = { "content-type": "application/json" };
516
+ const fetchExceptionsPage = async (agentId, options = {}) => {
517
+ const query = serializeListOptions(options ?? {});
518
+ const res = await doFetch(`${base}/agents/${agentId}/schedule/exceptions`, {
519
+ method: "GET",
520
+ query
521
+ });
522
+ return res.json();
523
+ };
524
+ return {
525
+ async list(agentId, options = {}) {
526
+ const normalizedOptions = {
527
+ ...options ?? {}
528
+ };
529
+ const fetchPage = (pageOptions) => fetchExceptionsPage(agentId, pageOptions);
530
+ const response = await fetchPage(normalizedOptions);
531
+ return attachPaginator(response, fetchPage, normalizedOptions);
532
+ },
533
+ async get(agentId, exceptionId) {
534
+ const res = await doFetch(
535
+ `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
536
+ {
537
+ method: "GET"
538
+ }
539
+ );
540
+ return res.json();
541
+ },
542
+ async create(agentId, payload) {
543
+ const res = await doFetch(
544
+ `${base}/agents/${agentId}/schedule/exceptions`,
545
+ {
546
+ method: "POST",
547
+ headers: jsonHeaders,
548
+ body: JSON.stringify(payload)
549
+ }
550
+ );
551
+ return res.json();
552
+ },
553
+ async update(agentId, exceptionId, payload) {
554
+ const res = await doFetch(
555
+ `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
556
+ {
557
+ method: "PATCH",
558
+ headers: jsonHeaders,
559
+ body: JSON.stringify(payload)
560
+ }
561
+ );
562
+ return res.json();
563
+ },
564
+ async delete(agentId, exceptionId) {
565
+ await doFetch(
566
+ `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
567
+ {
568
+ method: "DELETE"
569
+ }
570
+ );
571
+ }
572
+ };
573
+ }
574
+
512
575
  // src/api/agent-schedule.ts
513
576
  function createAgentScheduleApi(cfg) {
514
577
  const { base, doFetch } = createHttp(cfg);
@@ -539,39 +602,52 @@ function createAgentScheduleApi(cfg) {
539
602
  };
540
603
  }
541
604
 
542
- // src/api/agent-schedule-exceptions.ts
543
- function createAgentScheduleExceptionsApi(cfg) {
605
+ // src/api/agent-stage-triggers.ts
606
+ function createAgentStageTriggersApi(cfg) {
544
607
  const { base, doFetch } = createHttp(cfg);
545
608
  const jsonHeaders = { "content-type": "application/json" };
546
- const fetchExceptionsPage = async (agentId, options = {}) => {
547
- const query = serializeListOptions(options ?? {});
548
- const res = await doFetch(`${base}/agents/${agentId}/schedule/exceptions`, {
549
- method: "GET",
550
- query
551
- });
609
+ const fetchTriggerPage = async (agentId, stageId, options = {}) => {
610
+ const normalizedOptions = {
611
+ page: options.page,
612
+ limit: options.limit,
613
+ sort: options.sort,
614
+ fields: options.fields,
615
+ include: options.include,
616
+ filter: options.filter,
617
+ search: options.search,
618
+ or: options.or
619
+ };
620
+ const query = serializeListOptions(normalizedOptions);
621
+ const res = await doFetch(
622
+ `${base}/agents/${agentId}/stages/${stageId}/triggers`,
623
+ {
624
+ method: "GET",
625
+ query
626
+ }
627
+ );
552
628
  return res.json();
553
629
  };
554
630
  return {
555
- async list(agentId, options = {}) {
556
- const normalizedOptions = {
631
+ async list(agentId, stageId, options = {}) {
632
+ const normalized = {
557
633
  ...options ?? {}
558
634
  };
559
- const fetchPage = (pageOptions) => fetchExceptionsPage(agentId, pageOptions);
560
- const response = await fetchPage(normalizedOptions);
561
- return attachPaginator(response, fetchPage, normalizedOptions);
635
+ const fetchPage = (opts) => fetchTriggerPage(agentId, stageId, opts);
636
+ const response = await fetchPage(normalized);
637
+ return attachPaginator(response, fetchPage, normalized);
562
638
  },
563
- async get(agentId, exceptionId) {
639
+ async get(agentId, stageId, triggerId) {
564
640
  const res = await doFetch(
565
- `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
641
+ `${base}/agents/${agentId}/stages/${stageId}/triggers/${triggerId}`,
566
642
  {
567
643
  method: "GET"
568
644
  }
569
645
  );
570
646
  return res.json();
571
647
  },
572
- async create(agentId, payload) {
648
+ async create(agentId, stageId, payload) {
573
649
  const res = await doFetch(
574
- `${base}/agents/${agentId}/schedule/exceptions`,
650
+ `${base}/agents/${agentId}/stages/${stageId}/triggers`,
575
651
  {
576
652
  method: "POST",
577
653
  headers: jsonHeaders,
@@ -580,9 +656,9 @@ function createAgentScheduleExceptionsApi(cfg) {
580
656
  );
581
657
  return res.json();
582
658
  },
583
- async update(agentId, exceptionId, payload) {
659
+ async update(agentId, stageId, triggerId, payload) {
584
660
  const res = await doFetch(
585
- `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
661
+ `${base}/agents/${agentId}/stages/${stageId}/triggers/${triggerId}`,
586
662
  {
587
663
  method: "PATCH",
588
664
  headers: jsonHeaders,
@@ -591,9 +667,9 @@ function createAgentScheduleExceptionsApi(cfg) {
591
667
  );
592
668
  return res.json();
593
669
  },
594
- async delete(agentId, exceptionId) {
670
+ async delete(agentId, stageId, triggerId) {
595
671
  await doFetch(
596
- `${base}/agents/${agentId}/schedule/exceptions/${exceptionId}`,
672
+ `${base}/agents/${agentId}/stages/${stageId}/triggers/${triggerId}`,
597
673
  {
598
674
  method: "DELETE"
599
675
  }
@@ -602,6 +678,70 @@ function createAgentScheduleExceptionsApi(cfg) {
602
678
  };
603
679
  }
604
680
 
681
+ // src/api/agent-stages.ts
682
+ function createAgentStagesApi(cfg) {
683
+ const { base, doFetch } = createHttp(cfg);
684
+ const jsonHeaders = { "content-type": "application/json" };
685
+ const fetchStagePage = async (agentId, options = {}) => {
686
+ const normalizedOptions = {
687
+ page: options.page,
688
+ limit: options.limit,
689
+ sort: options.sort,
690
+ filter: options.filter,
691
+ search: options.search
692
+ };
693
+ const query = serializeListOptions(normalizedOptions);
694
+ const res = await doFetch(`${base}/agents/${agentId}/stages`, {
695
+ method: "GET",
696
+ query
697
+ });
698
+ return res.json();
699
+ };
700
+ return {
701
+ async list(agentId, options = {}) {
702
+ const normalized = { ...options ?? {} };
703
+ const fetchPage = (opts) => fetchStagePage(agentId, opts);
704
+ const response = await fetchPage(normalized);
705
+ return attachPaginator(response, fetchPage, normalized);
706
+ },
707
+ async get(agentId, stageId) {
708
+ const res = await doFetch(`${base}/agents/${agentId}/stages/${stageId}`, {
709
+ method: "GET"
710
+ });
711
+ return res.json();
712
+ },
713
+ async create(agentId, payload) {
714
+ const res = await doFetch(`${base}/agents/${agentId}/stages`, {
715
+ method: "POST",
716
+ headers: jsonHeaders,
717
+ body: JSON.stringify(payload)
718
+ });
719
+ return res.json();
720
+ },
721
+ async update(agentId, stageId, payload) {
722
+ const res = await doFetch(`${base}/agents/${agentId}/stages/${stageId}`, {
723
+ method: "PATCH",
724
+ headers: jsonHeaders,
725
+ body: JSON.stringify(payload)
726
+ });
727
+ return res.json();
728
+ },
729
+ async delete(agentId, stageId) {
730
+ await doFetch(`${base}/agents/${agentId}/stages/${stageId}`, {
731
+ method: "DELETE"
732
+ });
733
+ },
734
+ async reorder(agentId, payload) {
735
+ const res = await doFetch(`${base}/agents/${agentId}/stages:reorder`, {
736
+ method: "POST",
737
+ headers: jsonHeaders,
738
+ body: JSON.stringify(payload)
739
+ });
740
+ return res.json();
741
+ }
742
+ };
743
+ }
744
+
605
745
  // src/api/agent-tags.ts
606
746
  function createAgentTagsApi(cfg) {
607
747
  const { base, doFetch } = createHttp(cfg);
@@ -754,6 +894,46 @@ var bindAgentInstructions = (api, agentId) => ({
754
894
  return api.delete(agentId, instructionId);
755
895
  }
756
896
  });
897
+ var bindAgentStageTriggers = (api, agentId, stageId) => ({
898
+ list(opts) {
899
+ return api.list(agentId, stageId, opts);
900
+ },
901
+ get(triggerId) {
902
+ return api.get(agentId, stageId, triggerId);
903
+ },
904
+ create(payload) {
905
+ return api.create(agentId, stageId, payload);
906
+ },
907
+ update(triggerId, payload) {
908
+ return api.update(agentId, stageId, triggerId, payload);
909
+ },
910
+ delete(triggerId) {
911
+ return api.delete(agentId, stageId, triggerId);
912
+ }
913
+ });
914
+ var bindAgentStages = (stagesApi, triggersApi, agentId) => ({
915
+ list(opts) {
916
+ return stagesApi.list(agentId, opts);
917
+ },
918
+ get(stageId) {
919
+ return stagesApi.get(agentId, stageId);
920
+ },
921
+ create(payload) {
922
+ return stagesApi.create(agentId, payload);
923
+ },
924
+ update(stageId, payload) {
925
+ return stagesApi.update(agentId, stageId, payload);
926
+ },
927
+ delete(stageId) {
928
+ return stagesApi.delete(agentId, stageId);
929
+ },
930
+ reorder(payload) {
931
+ return stagesApi.reorder(agentId, payload);
932
+ },
933
+ triggers(stageId) {
934
+ return bindAgentStageTriggers(triggersApi, agentId, stageId);
935
+ }
936
+ });
757
937
  var bindAgentTags = (api, agentId) => ({
758
938
  add(tagId) {
759
939
  return api.add(agentId, { tagId });
@@ -867,6 +1047,8 @@ var createAgentEntity = (dto, options) => {
867
1047
  scheduleExceptionsApi,
868
1048
  versionsApi,
869
1049
  blueprintsApi,
1050
+ stagesApi,
1051
+ stageTriggersApi,
870
1052
  reload,
871
1053
  updateAgent,
872
1054
  deleteAgent
@@ -883,6 +1065,7 @@ var createAgentEntity = (dto, options) => {
883
1065
  ),
884
1066
  versions: bindAgentVersions(versionsApi, dto.agentId),
885
1067
  blueprints: bindAgentBlueprints(blueprintsApi, dto.agentId),
1068
+ stages: bindAgentStages(stagesApi, stageTriggersApi, dto.agentId),
886
1069
  async save(patch) {
887
1070
  return updateAgent(dto.agentId, patch);
888
1071
  },
@@ -967,6 +1150,8 @@ function createAgentsApi(cfg, relatedApis) {
967
1150
  scheduleExceptionsApi: relatedApis.scheduleExceptionsApi,
968
1151
  versionsApi: relatedApis.versionsApi,
969
1152
  blueprintsApi: relatedApis.blueprintsApi,
1153
+ stagesApi: relatedApis.stagesApi,
1154
+ stageTriggersApi: relatedApis.stageTriggersApi,
970
1155
  reload: async (agentId) => {
971
1156
  const latest = await getAgentDetail(agentId);
972
1157
  return wrapAgent(latest);
@@ -1217,21 +1402,167 @@ function createToolsApi(cfg) {
1217
1402
  };
1218
1403
  }
1219
1404
 
1405
+ // src/utils/catalog-voices.ts
1406
+ var FALLBACK_LOCALE = "und";
1407
+ var FALLBACK_PROVIDER = "catalog";
1408
+ function catalogItemToVoice(item) {
1409
+ const metadata = normalizeVoiceMetadata(item.metadata);
1410
+ const locale = metadata.locale ?? metadata.language ?? FALLBACK_LOCALE;
1411
+ return {
1412
+ id: item.id,
1413
+ providerVoiceId: metadata.providerVoiceId ?? item.systemIdentifier,
1414
+ name: item.name,
1415
+ gender: metadata.gender,
1416
+ locale,
1417
+ tags: metadata.tags ?? [],
1418
+ previewUrl: metadata.previewUrl ?? void 0,
1419
+ provider: metadata.provider ?? FALLBACK_PROVIDER
1420
+ };
1421
+ }
1422
+ function normalizeVoiceMetadata(metadata) {
1423
+ if (!metadata || typeof metadata !== "object") {
1424
+ return {};
1425
+ }
1426
+ const raw = metadata;
1427
+ return {
1428
+ language: pickString(raw.language),
1429
+ locale: pickString(raw.locale, true),
1430
+ gender: pickGender(raw.gender),
1431
+ provider: pickString(raw.provider, true),
1432
+ previewUrl: pickString(raw.previewUrl, true),
1433
+ tags: pickStringArray(raw.tags),
1434
+ providerVoiceId: pickString(raw.providerVoiceId)
1435
+ };
1436
+ }
1437
+ function pickString(value, allowNull = false) {
1438
+ if (typeof value === "string") {
1439
+ return value;
1440
+ }
1441
+ if (allowNull && value === null) {
1442
+ return null;
1443
+ }
1444
+ return void 0;
1445
+ }
1446
+ function pickStringArray(value) {
1447
+ if (!Array.isArray(value)) {
1448
+ return void 0;
1449
+ }
1450
+ const items = value.filter(
1451
+ (item) => typeof item === "string"
1452
+ );
1453
+ return items.length > 0 ? items : void 0;
1454
+ }
1455
+ function pickGender(value) {
1456
+ if (value === "female" || value === "male" || value === "neutral") {
1457
+ return value;
1458
+ }
1459
+ return void 0;
1460
+ }
1461
+
1462
+ // src/utils/catalog-filter.ts
1463
+ import { Query } from "@getsupervisor/api-query-builder";
1464
+ function createCatalogTypeQuery(type) {
1465
+ return new Query((qb) => qb.eq("type", type));
1466
+ }
1467
+ function ensureCatalogTypeFilter(filter, type) {
1468
+ const requiredQuery = createCatalogTypeQuery(type);
1469
+ const requiredExpression = requiredQuery.build();
1470
+ if (filter === void 0 || filter === null) {
1471
+ return requiredQuery;
1472
+ }
1473
+ if (typeof filter === "string") {
1474
+ return ensureTypeForString(filter, requiredQuery, requiredExpression);
1475
+ }
1476
+ if (isQueryBuilderLike(filter)) {
1477
+ return ensureTypeForBuilder(filter, requiredQuery, requiredExpression);
1478
+ }
1479
+ if (isPlainObject2(filter)) {
1480
+ return ensureTypeForObject(filter, type);
1481
+ }
1482
+ return filter;
1483
+ }
1484
+ function ensureTypeForString(value, requiredQuery, requiredExpression) {
1485
+ const normalized = value.trim();
1486
+ if (!normalized.length) {
1487
+ return requiredQuery;
1488
+ }
1489
+ return containsTypePredicate(normalized, requiredExpression) ? normalized : `and(${requiredExpression},${normalized})`;
1490
+ }
1491
+ function ensureTypeForBuilder(builder, requiredQuery, requiredExpression) {
1492
+ const normalized = builder.build().trim();
1493
+ if (!normalized.length) {
1494
+ return requiredQuery;
1495
+ }
1496
+ if (containsTypePredicate(normalized, requiredExpression)) {
1497
+ return builder;
1498
+ }
1499
+ const combined = `and(${requiredExpression},${normalized})`;
1500
+ return {
1501
+ build: () => combined
1502
+ };
1503
+ }
1504
+ function ensureTypeForObject(candidate, type) {
1505
+ if (hasTypeEquality(candidate, type)) {
1506
+ return candidate;
1507
+ }
1508
+ const typeConfig = candidate.type;
1509
+ const normalizedType = isPlainObject2(typeConfig) ? { ...typeConfig, eq: type } : { eq: type };
1510
+ return {
1511
+ ...candidate,
1512
+ type: normalizedType
1513
+ };
1514
+ }
1515
+ function hasTypeEquality(candidate, type) {
1516
+ const typeConfig = candidate.type;
1517
+ if (typeof typeConfig === "string") {
1518
+ return typeConfig === type;
1519
+ }
1520
+ if (!isPlainObject2(typeConfig)) {
1521
+ return false;
1522
+ }
1523
+ return typeConfig.eq === type;
1524
+ }
1525
+ function containsTypePredicate(expression, required) {
1526
+ const normalizedExpression = expression.replace(/\s+/g, "").toLowerCase();
1527
+ const normalizedRequired = required.replace(/\s+/g, "").toLowerCase();
1528
+ return normalizedExpression.includes(normalizedRequired);
1529
+ }
1530
+ function isQueryBuilderLike(candidate) {
1531
+ return !!candidate && typeof candidate === "object" && typeof candidate.build === "function";
1532
+ }
1533
+ function isPlainObject2(value) {
1534
+ if (value === null || typeof value !== "object") {
1535
+ return false;
1536
+ }
1537
+ const proto = Object.getPrototypeOf(value);
1538
+ return proto === Object.prototype || proto === null;
1539
+ }
1540
+
1220
1541
  // src/api/voices.ts
1542
+ function mapCatalogResponseToVoiceList(response) {
1543
+ return {
1544
+ data: response.data.filter((item) => item.type === "voice").map(catalogItemToVoice),
1545
+ meta: response.meta
1546
+ };
1547
+ }
1221
1548
  function createVoicesApi(cfg) {
1222
1549
  const { base, doFetch } = createHttp(cfg);
1223
1550
  const fetchVoicesPage = async (options = {}) => {
1224
- const { agentId, agentVersionId, gender, locale } = options;
1551
+ const normalizedOptions = {
1552
+ ...options,
1553
+ filter: ensureCatalogTypeFilter(options.filter, "voice")
1554
+ };
1555
+ const { agentId, agentVersionId, gender, locale } = normalizedOptions;
1225
1556
  const query = serializeListOptions(
1226
1557
  {
1227
- page: options.page,
1228
- limit: options.limit ?? options.pageSize,
1229
- sort: options.sort,
1230
- fields: options.fields,
1231
- include: options.include,
1232
- search: options.search,
1233
- filter: options.filter,
1234
- or: options.or
1558
+ page: normalizedOptions.page,
1559
+ limit: normalizedOptions.limit ?? normalizedOptions.pageSize,
1560
+ sort: normalizedOptions.sort,
1561
+ fields: normalizedOptions.fields,
1562
+ include: normalizedOptions.include,
1563
+ search: normalizedOptions.search,
1564
+ filter: normalizedOptions.filter,
1565
+ or: normalizedOptions.or
1235
1566
  },
1236
1567
  {
1237
1568
  agentId,
@@ -1240,11 +1571,12 @@ function createVoicesApi(cfg) {
1240
1571
  locale
1241
1572
  }
1242
1573
  );
1243
- const res = await doFetch(`${base}/voices`, {
1574
+ const res = await doFetch(`${base}/catalogs/items`, {
1244
1575
  method: "GET",
1245
1576
  query
1246
1577
  });
1247
- return res.json();
1578
+ const raw = await res.json();
1579
+ return mapCatalogResponseToVoiceList(raw);
1248
1580
  };
1249
1581
  return {
1250
1582
  async list(options = {}) {
@@ -1441,6 +1773,8 @@ function createClient(initialCfg) {
1441
1773
  const scheduleExceptionsApi = createAgentScheduleExceptionsApi(runtimeCfg);
1442
1774
  const versionsApi = createAgentVersionsApi(runtimeCfg);
1443
1775
  const blueprintsApi = createAgentBlueprintsApi(runtimeCfg);
1776
+ const stageTriggersApi = createAgentStageTriggersApi(runtimeCfg);
1777
+ const stagesApi = createAgentStagesApi(runtimeCfg);
1444
1778
  const voicesApi = createVoicesApi(runtimeCfg);
1445
1779
  const apiKeysApi = createApiKeysApi(runtimeCfg);
1446
1780
  const catalogsApi = createCatalogsApi(runtimeCfg);
@@ -1452,7 +1786,9 @@ function createClient(initialCfg) {
1452
1786
  scheduleApi,
1453
1787
  scheduleExceptionsApi,
1454
1788
  versionsApi,
1455
- blueprintsApi
1789
+ blueprintsApi,
1790
+ stagesApi,
1791
+ stageTriggersApi
1456
1792
  });
1457
1793
  const instructionsNamespace = Object.assign(
1458
1794
  (agentId) => bindAgentInstructions(instructionsApi, agentId),
@@ -1485,6 +1821,17 @@ function createClient(initialCfg) {
1485
1821
  (agentId) => bindAgentBlueprints(blueprintsApi, agentId),
1486
1822
  blueprintsApi
1487
1823
  );
1824
+ const stageTriggersNamespace = Object.assign(
1825
+ (agentId, stageId) => bindAgentStageTriggers(stageTriggersApi, agentId, stageId),
1826
+ stageTriggersApi
1827
+ );
1828
+ const stagesNamespace = Object.assign(
1829
+ (agentId) => bindAgentStages(stagesApi, stageTriggersApi, agentId),
1830
+ {
1831
+ ...stagesApi,
1832
+ triggers: stageTriggersNamespace
1833
+ }
1834
+ );
1488
1835
  const apis = {
1489
1836
  agents: {
1490
1837
  ...agentsApi,
@@ -1493,7 +1840,8 @@ function createClient(initialCfg) {
1493
1840
  phones: phonesNamespace,
1494
1841
  schedule: scheduleNamespace,
1495
1842
  versions: versionsNamespace,
1496
- blueprints: blueprintsNamespace
1843
+ blueprints: blueprintsNamespace,
1844
+ stages: stagesNamespace
1497
1845
  },
1498
1846
  workspaces: createWorkspacesApi(runtimeCfg),
1499
1847
  tools: createToolsApi(runtimeCfg),
@@ -1566,6 +1914,8 @@ export {
1566
1914
  bindAgentPhones,
1567
1915
  bindAgentSchedule,
1568
1916
  bindAgentScheduleExceptions,
1917
+ bindAgentStageTriggers,
1918
+ bindAgentStages,
1569
1919
  bindAgentTags,
1570
1920
  bindAgentVersions,
1571
1921
  createAgentBlueprintsApi,
@@ -1574,6 +1924,8 @@ export {
1574
1924
  createAgentPhonesApi,
1575
1925
  createAgentScheduleApi,
1576
1926
  createAgentScheduleExceptionsApi,
1927
+ createAgentStageTriggersApi,
1928
+ createAgentStagesApi,
1577
1929
  createAgentTagsApi,
1578
1930
  createAgentVersionsApi,
1579
1931
  createAgentsApi,