@getsupervisor/agents-studio-sdk 1.40.0 → 1.41.0-patch.2

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 CHANGED
@@ -22,6 +22,7 @@ __export(index_exports, {
22
22
  HttpError: () => HttpError,
23
23
  NetworkError: () => NetworkError,
24
24
  TimeoutError: () => TimeoutError,
25
+ WorkspaceNotSelectedError: () => WorkspaceNotSelectedError,
25
26
  bindAgentBlueprints: () => bindAgentBlueprints,
26
27
  bindAgentPhones: () => bindAgentPhones,
27
28
  bindAgentSchedule: () => bindAgentSchedule,
@@ -42,6 +43,7 @@ __export(index_exports, {
42
43
  createAgentVersionsApi: () => createAgentVersionsApi,
43
44
  createAgentsApi: () => createAgentsApi,
44
45
  createApiKeysApi: () => createApiKeysApi,
46
+ createCampaignsApi: () => createCampaignsApi,
45
47
  createCatalogTemplatesApi: () => createCatalogTemplatesApi,
46
48
  createCatalogsApi: () => createCatalogsApi,
47
49
  createClient: () => createClient,
@@ -80,6 +82,12 @@ var NetworkError = class extends Error {
80
82
  this.name = "NetworkError";
81
83
  }
82
84
  };
85
+ var WorkspaceNotSelectedError = class extends Error {
86
+ constructor() {
87
+ super("Workspace is not selected");
88
+ this.name = "WorkspaceNotSelectedError";
89
+ }
90
+ };
83
91
 
84
92
  // src/http.ts
85
93
  function toQueryString(query) {
@@ -515,6 +523,56 @@ function attachPaginator(response, fetchPage, options) {
515
523
  });
516
524
  }
517
525
 
526
+ // src/api/agent-schedule.ts
527
+ function createAgentScheduleApi(cfg) {
528
+ const { base, doFetch } = createHttp(cfg);
529
+ const jsonHeaders = { "content-type": "application/json" };
530
+ const fetchSchedulesPage = async (agentId, options = {}) => {
531
+ const query = serializeListOptions({ ...options ?? {} });
532
+ const res = await doFetch(`${base}/agents/${agentId}/schedules`, {
533
+ method: "GET",
534
+ query
535
+ });
536
+ return res.json();
537
+ };
538
+ return {
539
+ async list(agentId, options = {}) {
540
+ const normalized = { ...options ?? {} };
541
+ const fetchPage = (pageOptions) => fetchSchedulesPage(agentId, pageOptions);
542
+ const response = await fetchPage(normalized);
543
+ return attachPaginator(response, fetchPage, normalized);
544
+ },
545
+ async get(agentId, scheduleId) {
546
+ const res = await doFetch(
547
+ `${base}/agents/${agentId}/schedules/${scheduleId}`,
548
+ {
549
+ method: "GET"
550
+ }
551
+ );
552
+ return res.json();
553
+ },
554
+ async create(agentId, payload) {
555
+ const res = await doFetch(`${base}/agents/${agentId}/schedules`, {
556
+ method: "POST",
557
+ headers: jsonHeaders,
558
+ body: JSON.stringify(payload)
559
+ });
560
+ return res.json();
561
+ },
562
+ async update(agentId, scheduleId, payload) {
563
+ const res = await doFetch(
564
+ `${base}/agents/${agentId}/schedules/${scheduleId}`,
565
+ {
566
+ method: "PUT",
567
+ headers: jsonHeaders,
568
+ body: JSON.stringify(payload)
569
+ }
570
+ );
571
+ return res.json();
572
+ }
573
+ };
574
+ }
575
+
518
576
  // src/api/agent-schedule-exceptions.ts
519
577
  function createAgentScheduleExceptionsApi(cfg) {
520
578
  const { base, doFetch } = createHttp(cfg);
@@ -581,56 +639,6 @@ function createAgentScheduleExceptionsApi(cfg) {
581
639
  };
582
640
  }
583
641
 
584
- // src/api/agent-schedule.ts
585
- function createAgentScheduleApi(cfg) {
586
- const { base, doFetch } = createHttp(cfg);
587
- const jsonHeaders = { "content-type": "application/json" };
588
- const fetchSchedulesPage = async (agentId, options = {}) => {
589
- const query = serializeListOptions({ ...options ?? {} });
590
- const res = await doFetch(`${base}/agents/${agentId}/schedules`, {
591
- method: "GET",
592
- query
593
- });
594
- return res.json();
595
- };
596
- return {
597
- async list(agentId, options = {}) {
598
- const normalized = { ...options ?? {} };
599
- const fetchPage = (pageOptions) => fetchSchedulesPage(agentId, pageOptions);
600
- const response = await fetchPage(normalized);
601
- return attachPaginator(response, fetchPage, normalized);
602
- },
603
- async get(agentId, scheduleId) {
604
- const res = await doFetch(
605
- `${base}/agents/${agentId}/schedules/${scheduleId}`,
606
- {
607
- method: "GET"
608
- }
609
- );
610
- return res.json();
611
- },
612
- async create(agentId, payload) {
613
- const res = await doFetch(`${base}/agents/${agentId}/schedules`, {
614
- method: "POST",
615
- headers: jsonHeaders,
616
- body: JSON.stringify(payload)
617
- });
618
- return res.json();
619
- },
620
- async update(agentId, scheduleId, payload) {
621
- const res = await doFetch(
622
- `${base}/agents/${agentId}/schedules/${scheduleId}`,
623
- {
624
- method: "PUT",
625
- headers: jsonHeaders,
626
- body: JSON.stringify(payload)
627
- }
628
- );
629
- return res.json();
630
- }
631
- };
632
- }
633
-
634
642
  // src/api/agent-stage-triggers.ts
635
643
  function createAgentStageTriggersApi(cfg) {
636
644
  const { base, doFetch } = createHttp(cfg);
@@ -1143,9 +1151,21 @@ var createAgentEntity = (dto, options) => {
1143
1151
 
1144
1152
  // src/api/agents.ts
1145
1153
  function createAgentsApi(cfg, relatedApis) {
1146
- const { base, doFetch } = createHttp(cfg);
1154
+ const { base, doFetch, resolveWorkspaceId, resolveApiKey } = createHttp(cfg);
1155
+ const requireWorkspace = () => {
1156
+ const workspaceId = resolveWorkspaceId();
1157
+ if (typeof workspaceId === "string" && workspaceId.trim().length > 0) {
1158
+ return;
1159
+ }
1160
+ const apiKey = resolveApiKey();
1161
+ if (typeof apiKey === "string" && apiKey.trim().length > 0) {
1162
+ return;
1163
+ }
1164
+ throw new WorkspaceNotSelectedError();
1165
+ };
1147
1166
  const jsonHeaders = { "content-type": "application/json" };
1148
1167
  const fetchAgentsPage = async (options = {}) => {
1168
+ requireWorkspace();
1149
1169
  const sanitizedOptions = {
1150
1170
  page: options.page,
1151
1171
  limit: options.limit,
@@ -1164,12 +1184,14 @@ function createAgentsApi(cfg, relatedApis) {
1164
1184
  return attachPaginator(response, fetchAgentsPage, normalizedOptions);
1165
1185
  };
1166
1186
  const getAgentDetail = async (agentId) => {
1187
+ requireWorkspace();
1167
1188
  const res = await doFetch(`${base}/agents/${agentId}`, {
1168
1189
  method: "GET"
1169
1190
  });
1170
1191
  return res.json();
1171
1192
  };
1172
1193
  const createAgent = async (payload) => {
1194
+ requireWorkspace();
1173
1195
  const res = await doFetch(`${base}/agents`, {
1174
1196
  method: "POST",
1175
1197
  body: JSON.stringify(payload),
@@ -1178,6 +1200,7 @@ function createAgentsApi(cfg, relatedApis) {
1178
1200
  return res.json();
1179
1201
  };
1180
1202
  const forkAgentFromTemplate = async (payload) => {
1203
+ requireWorkspace();
1181
1204
  const res = await doFetch(`${base}/agents/from-template`, {
1182
1205
  method: "POST",
1183
1206
  body: JSON.stringify(payload),
@@ -1186,6 +1209,7 @@ function createAgentsApi(cfg, relatedApis) {
1186
1209
  return res.json();
1187
1210
  };
1188
1211
  const updateAgent = async (agentId, payload) => {
1212
+ requireWorkspace();
1189
1213
  const res = await doFetch(`${base}/agents/${agentId}`, {
1190
1214
  method: "PATCH",
1191
1215
  body: JSON.stringify(payload),
@@ -1197,6 +1221,7 @@ function createAgentsApi(cfg, relatedApis) {
1197
1221
  return typeof agent === "string" ? agent : agent.agentId;
1198
1222
  };
1199
1223
  const deleteAgent = async (agent) => {
1224
+ requireWorkspace();
1200
1225
  const agentId = resolveAgentId(agent);
1201
1226
  await doFetch(`${base}/agents/${agentId}`, {
1202
1227
  method: "DELETE"
@@ -1299,6 +1324,82 @@ function createApiKeysApi(cfg) {
1299
1324
  };
1300
1325
  }
1301
1326
 
1327
+ // src/api/campaigns.ts
1328
+ function createCampaignsApi(cfg) {
1329
+ const { base, doFetch } = createHttp(cfg);
1330
+ const isFormData2 = (value) => {
1331
+ return typeof FormData !== "undefined" && value instanceof FormData;
1332
+ };
1333
+ const fetchCampaignsPage = async (options = {}) => {
1334
+ const query = serializeListOptions(options ?? {});
1335
+ const res = await doFetch(`${base}/campaigns`, {
1336
+ method: "GET",
1337
+ query
1338
+ });
1339
+ return res.json();
1340
+ };
1341
+ const fetchExecutionsPage = async (campaignId, options = {}) => {
1342
+ const query = serializeListOptions({
1343
+ page: options.page,
1344
+ limit: options.limit
1345
+ });
1346
+ const res = await doFetch(`${base}/campaigns/${campaignId}/executions`, {
1347
+ method: "GET",
1348
+ query
1349
+ });
1350
+ return res.json();
1351
+ };
1352
+ const buildMultipart = (payload) => {
1353
+ if (isFormData2(payload)) {
1354
+ return payload;
1355
+ }
1356
+ if (typeof FormData === "undefined") {
1357
+ throw new TypeError(
1358
+ "FormData is not available in this environment. Pass a FormData instance instead."
1359
+ );
1360
+ }
1361
+ const form = new FormData();
1362
+ form.append("name", payload.name);
1363
+ if (payload.objective !== void 0 && payload.objective !== null) {
1364
+ form.append("objective", payload.objective);
1365
+ }
1366
+ form.append("file", payload.file);
1367
+ return form;
1368
+ };
1369
+ return {
1370
+ async list(options = {}) {
1371
+ const normalizedOptions = { ...options ?? {} };
1372
+ const response = await fetchCampaignsPage(normalizedOptions);
1373
+ return attachPaginator(response, fetchCampaignsPage, normalizedOptions);
1374
+ },
1375
+ async get(campaignId) {
1376
+ const res = await doFetch(`${base}/campaigns/${campaignId}`, {
1377
+ method: "GET"
1378
+ });
1379
+ return res.json();
1380
+ },
1381
+ async create(agentId, versionId, payload) {
1382
+ const body = buildMultipart(payload);
1383
+ const res = await doFetch(
1384
+ `${base}/agents/${agentId}/versions/${versionId}/campaigns`,
1385
+ {
1386
+ method: "POST",
1387
+ body
1388
+ }
1389
+ );
1390
+ return res.json();
1391
+ },
1392
+ async listExecutions(campaignId, options = {}) {
1393
+ const normalizedOptions = {
1394
+ ...options ?? {}
1395
+ };
1396
+ const response = await fetchExecutionsPage(campaignId, normalizedOptions);
1397
+ const fetchPage = (opts) => fetchExecutionsPage(campaignId, opts);
1398
+ return attachPaginator(response, fetchPage, normalizedOptions);
1399
+ }
1400
+ };
1401
+ }
1402
+
1302
1403
  // src/api/catalog-templates.ts
1303
1404
  function createCatalogTemplatesApi(cfg) {
1304
1405
  const { base, doFetch } = createHttp(cfg);
@@ -1502,6 +1603,33 @@ function createToolsApi(cfg) {
1502
1603
  body: JSON.stringify(payload)
1503
1604
  });
1504
1605
  return res.json();
1606
+ },
1607
+ async createConnection(payload, options = {}) {
1608
+ const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
1609
+ const res = await doFetch(`${base}/tools/connections`, {
1610
+ method: "POST",
1611
+ headers: {
1612
+ ...jsonHeaders,
1613
+ [IDEMPOTENCY_HEADER]: idempotencyKey
1614
+ },
1615
+ body: JSON.stringify(payload)
1616
+ });
1617
+ return res.json();
1618
+ },
1619
+ async executeConnection(toolAgentConnectionId, payload, options = {}) {
1620
+ const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
1621
+ const res = await doFetch(
1622
+ `${base}/tools/connections/${toolAgentConnectionId}/execute`,
1623
+ {
1624
+ method: "POST",
1625
+ headers: {
1626
+ ...jsonHeaders,
1627
+ [IDEMPOTENCY_HEADER]: idempotencyKey
1628
+ },
1629
+ body: JSON.stringify(payload)
1630
+ }
1631
+ );
1632
+ return res.json();
1505
1633
  }
1506
1634
  };
1507
1635
  }
@@ -1810,6 +1938,26 @@ function createWebhooksApi(cfg) {
1810
1938
  function createWorkspacesApi(cfg) {
1811
1939
  const { base, doFetch } = createHttp(cfg);
1812
1940
  const jsonHeaders = { "content-type": "application/json" };
1941
+ const fetchWorkspacesPage = async (options = {}) => {
1942
+ const normalized = { ...options ?? {} };
1943
+ const query = serializeListOptions({
1944
+ page: normalized.page,
1945
+ limit: normalized.limit,
1946
+ sort: normalized.sort,
1947
+ fields: normalized.fields,
1948
+ include: normalized.include,
1949
+ search: normalized.search,
1950
+ filter: normalized.filter,
1951
+ or: normalized.or
1952
+ });
1953
+ const headers = normalized.refreshCache ? { "X-Cache-Refresh": "true" } : void 0;
1954
+ const res = await doFetch(`${base}/workspaces`, {
1955
+ method: "GET",
1956
+ query,
1957
+ headers
1958
+ });
1959
+ return res.json();
1960
+ };
1813
1961
  const fetchPhonesPage = async (workspaceId, opts = {}) => {
1814
1962
  const { channel } = opts ?? {};
1815
1963
  const query = serializeListOptions(
@@ -1832,6 +1980,11 @@ function createWorkspacesApi(cfg) {
1832
1980
  return res.json();
1833
1981
  };
1834
1982
  return {
1983
+ async list(options = {}) {
1984
+ const normalizedOptions = { ...options ?? {} };
1985
+ const response = await fetchWorkspacesPage(normalizedOptions);
1986
+ return attachPaginator(response, fetchWorkspacesPage, normalizedOptions);
1987
+ },
1835
1988
  async listPhones(workspaceId, opts = {}) {
1836
1989
  const normalizedOptions = {
1837
1990
  ...opts ?? {}
@@ -1955,6 +2108,7 @@ function createClient(initialCfg) {
1955
2108
  ...catalogsApi,
1956
2109
  templates: catalogTemplatesApi
1957
2110
  },
2111
+ campaigns: createCampaignsApi(runtimeCfg),
1958
2112
  voices: voicesApi,
1959
2113
  apiKeys: apiKeysApi,
1960
2114
  webhooks: webhooksApi
@@ -2019,6 +2173,7 @@ function createClient(initialCfg) {
2019
2173
  HttpError,
2020
2174
  NetworkError,
2021
2175
  TimeoutError,
2176
+ WorkspaceNotSelectedError,
2022
2177
  bindAgentBlueprints,
2023
2178
  bindAgentPhones,
2024
2179
  bindAgentSchedule,
@@ -2039,6 +2194,7 @@ function createClient(initialCfg) {
2039
2194
  createAgentVersionsApi,
2040
2195
  createAgentsApi,
2041
2196
  createApiKeysApi,
2197
+ createCampaignsApi,
2042
2198
  createCatalogTemplatesApi,
2043
2199
  createCatalogsApi,
2044
2200
  createClient,