@getsupervisor/agents-studio-sdk 1.41.2-patch.1 → 1.41.2-patch.11

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
@@ -200,6 +200,11 @@ function createHttp(cfg) {
200
200
  }
201
201
 
202
202
  // src/utils/query.ts
203
+ function buildSearchParams(entries) {
204
+ const searchParams = new URLSearchParams();
205
+ entries.forEach(([key, value]) => appendParam(searchParams, key, value));
206
+ return searchParams;
207
+ }
203
208
  function serializeListOptions(options = {}, extra = {}) {
204
209
  const params = new URLSearchParams();
205
210
  appendParam(params, "page", options.page);
@@ -1071,7 +1076,8 @@ var createAgentEntity = (dto, options) => {
1071
1076
  stageTriggersApi,
1072
1077
  reload,
1073
1078
  updateAgent,
1074
- deleteAgent
1079
+ deleteAgent,
1080
+ cloneAgent
1075
1081
  } = options;
1076
1082
  const schedulesHelper = bindAgentSchedules(
1077
1083
  scheduleApi,
@@ -1090,6 +1096,9 @@ var createAgentEntity = (dto, options) => {
1090
1096
  async save(patch) {
1091
1097
  return updateAgent(dto.agentId, patch);
1092
1098
  },
1099
+ async clone(payload) {
1100
+ return cloneAgent(dto.agentId, payload);
1101
+ },
1093
1102
  async delete() {
1094
1103
  await deleteAgent(dto.agentId);
1095
1104
  },
@@ -1115,6 +1124,22 @@ function createAgentsApi(cfg, relatedApis) {
1115
1124
  throw new WorkspaceNotSelectedError();
1116
1125
  };
1117
1126
  const jsonHeaders = { "content-type": "application/json" };
1127
+ const normalizeCloneSelection = (selection) => {
1128
+ if (!selection) {
1129
+ return [];
1130
+ }
1131
+ if (Array.isArray(selection)) {
1132
+ return selection;
1133
+ }
1134
+ return Object.entries(selection).filter(([, enabled]) => enabled).map(([component]) => component);
1135
+ };
1136
+ const buildCloneAgentRequest = (payload) => {
1137
+ const { clone, ...rest } = payload;
1138
+ return {
1139
+ ...rest,
1140
+ clone: normalizeCloneSelection(clone)
1141
+ };
1142
+ };
1118
1143
  const fetchAgentsPage = async (options = {}) => {
1119
1144
  requireWorkspace();
1120
1145
  const sanitizedOptions = {
@@ -1159,6 +1184,16 @@ function createAgentsApi(cfg, relatedApis) {
1159
1184
  });
1160
1185
  return res.json();
1161
1186
  };
1187
+ const cloneAgent = async (agentId, payload) => {
1188
+ requireWorkspace();
1189
+ const requestPayload = buildCloneAgentRequest(payload);
1190
+ const res = await doFetch(`${base}/agents/${agentId}/clone`, {
1191
+ method: "POST",
1192
+ body: JSON.stringify(requestPayload),
1193
+ headers: jsonHeaders
1194
+ });
1195
+ return res.json();
1196
+ };
1162
1197
  const updateAgent = async (agentId, payload) => {
1163
1198
  requireWorkspace();
1164
1199
  const res = await doFetch(`${base}/agents/${agentId}`, {
@@ -1182,6 +1217,7 @@ function createAgentsApi(cfg, relatedApis) {
1182
1217
  list: listAgents,
1183
1218
  get: getAgentDetail,
1184
1219
  create: createAgent,
1220
+ clone: cloneAgent,
1185
1221
  forkFromTemplate: forkAgentFromTemplate,
1186
1222
  update: updateAgent,
1187
1223
  delete: deleteAgent
@@ -1208,6 +1244,10 @@ function createAgentsApi(cfg, relatedApis) {
1208
1244
  },
1209
1245
  deleteAgent: async (agentId) => {
1210
1246
  await deleteAgent(agentId);
1247
+ },
1248
+ cloneAgent: async (agentId, payload) => {
1249
+ const cloned = await cloneAgent(agentId, payload);
1250
+ return wrapAgent(cloned);
1211
1251
  }
1212
1252
  });
1213
1253
  return {
@@ -1233,6 +1273,10 @@ function createAgentsApi(cfg, relatedApis) {
1233
1273
  const detail = await createAgent(payload);
1234
1274
  return wrapAgent(detail);
1235
1275
  },
1276
+ async clone(agentId, payload) {
1277
+ const detail = await cloneAgent(agentId, payload);
1278
+ return wrapAgent(detail);
1279
+ },
1236
1280
  async forkFromTemplate(payload) {
1237
1281
  const detail = await forkAgentFromTemplate(payload);
1238
1282
  return wrapAgent(detail);
@@ -1275,6 +1319,82 @@ function createApiKeysApi(cfg) {
1275
1319
  };
1276
1320
  }
1277
1321
 
1322
+ // src/api/billing.ts
1323
+ function createBillingApi(cfg) {
1324
+ const { base, doFetch } = createHttp(cfg);
1325
+ return {
1326
+ async getBalance() {
1327
+ const res = await doFetch(`${base}/billing/balance`, {
1328
+ method: "GET"
1329
+ });
1330
+ return res.json();
1331
+ }
1332
+ };
1333
+ }
1334
+
1335
+ // src/api/calls.ts
1336
+ function createCallsApi(cfg) {
1337
+ const { base, doFetch } = createHttp(cfg);
1338
+ const fetchCallsPage = async (options = {}) => {
1339
+ const {
1340
+ agentBatchId,
1341
+ agentId,
1342
+ executionId,
1343
+ recordedAfter,
1344
+ recordedBefore,
1345
+ durationBucket,
1346
+ goalStatus,
1347
+ query: searchQuery,
1348
+ ...listOptions
1349
+ } = options ?? {};
1350
+ const query = serializeListOptions(listOptions, {
1351
+ agentBatchId,
1352
+ agentId,
1353
+ executionId,
1354
+ recordedAfter,
1355
+ recordedBefore,
1356
+ durationBucket,
1357
+ goalStatus,
1358
+ query: searchQuery
1359
+ });
1360
+ const res = await doFetch(`${base}/calls`, {
1361
+ method: "GET",
1362
+ query
1363
+ });
1364
+ return res.json();
1365
+ };
1366
+ return {
1367
+ async list(options = {}) {
1368
+ const normalizedOptions = { ...options ?? {} };
1369
+ const response = await fetchCallsPage(normalizedOptions);
1370
+ return attachPaginator(response, fetchCallsPage, normalizedOptions);
1371
+ },
1372
+ async stream(options) {
1373
+ const query = buildSearchParams([
1374
+ ["after", options.after],
1375
+ ["limit", options.limit],
1376
+ ["agentBatchId", options.agentBatchId],
1377
+ ["agentId", options.agentId],
1378
+ ["executionId", options.executionId],
1379
+ ["durationBucket", options.durationBucket],
1380
+ ["goalStatus", options.goalStatus],
1381
+ ["query", options.query]
1382
+ ]);
1383
+ const res = await doFetch(`${base}/calls/stream`, {
1384
+ method: "GET",
1385
+ query
1386
+ });
1387
+ return res.json();
1388
+ },
1389
+ async get(callId) {
1390
+ const res = await doFetch(`${base}/calls/${callId}`, {
1391
+ method: "GET"
1392
+ });
1393
+ return res.json();
1394
+ }
1395
+ };
1396
+ }
1397
+
1278
1398
  // src/api/campaigns.ts
1279
1399
  function createCampaignsApi(cfg) {
1280
1400
  const { base, doFetch } = createHttp(cfg);
@@ -1616,6 +1736,33 @@ function createToolsApi(cfg) {
1616
1736
  };
1617
1737
  }
1618
1738
 
1739
+ // src/api/usage.ts
1740
+ function createUsageApi(cfg) {
1741
+ const { base, doFetch } = createHttp(cfg);
1742
+ const fetchUsageAgentsPage = async (options = {}) => {
1743
+ const { resource, from, to, ...listOptions } = options ?? {};
1744
+ const query = serializeListOptions(listOptions, {
1745
+ resource,
1746
+ from,
1747
+ to
1748
+ });
1749
+ const res = await doFetch(`${base}/usage/agents`, {
1750
+ method: "GET",
1751
+ query
1752
+ });
1753
+ return res.json();
1754
+ };
1755
+ return {
1756
+ async agents(options = {}) {
1757
+ const normalizedOptions = {
1758
+ ...options ?? {}
1759
+ };
1760
+ const response = await fetchUsageAgentsPage(normalizedOptions);
1761
+ return attachPaginator(response, fetchUsageAgentsPage, normalizedOptions);
1762
+ }
1763
+ };
1764
+ }
1765
+
1619
1766
  // src/utils/catalog-voices.ts
1620
1767
  var FALLBACK_LOCALE = "und";
1621
1768
  var FALLBACK_PROVIDER = "catalog";
@@ -1912,6 +2059,35 @@ function createWebhooksApi(cfg) {
1912
2059
  `${base}/webhooks/${webhookId}/subscriptions/${subscriptionId}`,
1913
2060
  { method: "DELETE" }
1914
2061
  );
2062
+ },
2063
+ // Deliveries
2064
+ async listDeliveries(webhookId, options = {}) {
2065
+ const fetchPage = async (opts) => {
2066
+ const query = serializeListOptions({
2067
+ page: opts.page,
2068
+ limit: opts.limit,
2069
+ sort: opts.sort,
2070
+ fields: opts.fields,
2071
+ include: opts.include,
2072
+ search: opts.search,
2073
+ filter: opts.filter
2074
+ });
2075
+ const res = await doFetch(`${base}/webhooks/${webhookId}/deliveries`, {
2076
+ method: "GET",
2077
+ query
2078
+ });
2079
+ return res.json();
2080
+ };
2081
+ const normalized = { ...options ?? {} };
2082
+ const response = await fetchPage(normalized);
2083
+ return attachPaginator(response, fetchPage, normalized);
2084
+ },
2085
+ async getDelivery(webhookId, deliveryId) {
2086
+ const res = await doFetch(
2087
+ `${base}/webhooks/${webhookId}/deliveries/${deliveryId}`,
2088
+ { method: "GET" }
2089
+ );
2090
+ return res.json();
1915
2091
  }
1916
2092
  };
1917
2093
  }
@@ -1975,8 +2151,8 @@ function createWorkspacesApi(cfg) {
1975
2151
  const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
1976
2152
  return attachPaginator(response, fetchPage, normalizedOptions);
1977
2153
  },
1978
- async enable(workspaceId, payload) {
1979
- const res = await doFetch(`${base}/workspaces/${workspaceId}/enable`, {
2154
+ async enable(payload) {
2155
+ const res = await doFetch(`${base}/workspaces/enable`, {
1980
2156
  method: "POST",
1981
2157
  headers: jsonHeaders,
1982
2158
  body: JSON.stringify(payload)
@@ -2022,6 +2198,7 @@ function createClient(initialCfg) {
2022
2198
  const stagesApi = createAgentStagesApi(runtimeCfg);
2023
2199
  const voicesApi = createVoicesApi(runtimeCfg);
2024
2200
  const apiKeysApi = createApiKeysApi(runtimeCfg);
2201
+ const callsApi = createCallsApi(runtimeCfg);
2025
2202
  const catalogsApi = createCatalogsApi(runtimeCfg);
2026
2203
  const catalogTemplatesApi = createCatalogTemplatesApi(runtimeCfg);
2027
2204
  const webhooksApi = createWebhooksApi(runtimeCfg);
@@ -2093,6 +2270,9 @@ function createClient(initialCfg) {
2093
2270
  campaigns: createCampaignsApi(runtimeCfg),
2094
2271
  voices: voicesApi,
2095
2272
  apiKeys: apiKeysApi,
2273
+ billing: createBillingApi(runtimeCfg),
2274
+ calls: callsApi,
2275
+ usage: createUsageApi(runtimeCfg),
2096
2276
  webhooks: webhooksApi
2097
2277
  };
2098
2278
  return {
@@ -2175,12 +2355,15 @@ export {
2175
2355
  createAgentVersionsApi,
2176
2356
  createAgentsApi,
2177
2357
  createApiKeysApi,
2358
+ createBillingApi,
2359
+ createCallsApi,
2178
2360
  createCampaignsApi,
2179
2361
  createCatalogTemplatesApi,
2180
2362
  createCatalogsApi,
2181
2363
  createClient,
2182
2364
  createHttp,
2183
2365
  createToolsApi,
2366
+ createUsageApi,
2184
2367
  createVoicesApi,
2185
2368
  createWebhooksApi,
2186
2369
  createWorkspacesApi,