@getsupervisor/agents-studio-sdk 1.41.2-patch.15 → 1.41.2-patch.16

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
@@ -49,6 +49,7 @@ __export(index_exports, {
49
49
  createCatalogTemplatesApi: () => createCatalogTemplatesApi,
50
50
  createCatalogsApi: () => createCatalogsApi,
51
51
  createClient: () => createClient,
52
+ createDocumentsApi: () => createDocumentsApi,
52
53
  createHttp: () => createHttp,
53
54
  createSipTrunksApi: () => createSipTrunksApi,
54
55
  createToolsApi: () => createToolsApi,
@@ -1328,6 +1329,31 @@ function createAgentsApi(cfg, relatedApis) {
1328
1329
  body: JSON.stringify(payload),
1329
1330
  headers
1330
1331
  });
1332
+ if (!res.ok) {
1333
+ const body = await res.text();
1334
+ throw new Error(`POST ${url} failed with status ${res.status}: ${body}`);
1335
+ }
1336
+ const contentType = res.headers.get("content-type") ?? "";
1337
+ if (contentType.includes("application/json")) {
1338
+ const agent = await res.json();
1339
+ callbacks.onAgentCreated?.(agent);
1340
+ return agent;
1341
+ }
1342
+ return consumeSseStream(
1343
+ res,
1344
+ buildSseHandlers(callbacks),
1345
+ "agent-created"
1346
+ );
1347
+ };
1348
+ const getWithSse = async (url, callbacks) => {
1349
+ requireWorkspace();
1350
+ const headers = buildHeaders({});
1351
+ const fx = cfg.fetchImpl ?? fetch;
1352
+ const res = await fx(url, { method: "GET", headers });
1353
+ if (!res.ok) {
1354
+ const body = await res.text();
1355
+ throw new Error(`GET ${url} failed with status ${res.status}: ${body}`);
1356
+ }
1331
1357
  const contentType = res.headers.get("content-type") ?? "";
1332
1358
  if (contentType.includes("application/json")) {
1333
1359
  const agent = await res.json();
@@ -1356,7 +1382,10 @@ function createAgentsApi(cfg, relatedApis) {
1356
1382
  const response = await fetchPage(opts);
1357
1383
  return attachPaginator(response, fetchPage, opts);
1358
1384
  },
1359
- async get(agentId) {
1385
+ async get(agentId, callbacks) {
1386
+ if (callbacks) {
1387
+ return getWithSse(`${base}/agents/${agentId}`, callbacks);
1388
+ }
1360
1389
  requireWorkspace();
1361
1390
  const res = await doFetch(`${base}/agents/${agentId}`, { method: "GET" });
1362
1391
  return res.json();
@@ -1388,9 +1417,6 @@ function createAgentsApi(cfg, relatedApis) {
1388
1417
  });
1389
1418
  return res.json();
1390
1419
  },
1391
- async presignDocuments(files) {
1392
- return postJson(`${base}/documents`, { files });
1393
- },
1394
1420
  async delete(agent) {
1395
1421
  requireWorkspace();
1396
1422
  await doFetch(`${base}/agents/${resolveAgentId(agent)}`, {
@@ -1434,8 +1460,8 @@ function withEntityWrapping(api, fetchPage, deps) {
1434
1460
  const initial = await wrapList(opts);
1435
1461
  return attachPaginator(initial, wrapList, opts);
1436
1462
  },
1437
- async get(agentId) {
1438
- return wrapAgent(await api.get(agentId));
1463
+ async get(agentId, callbacks) {
1464
+ return wrapAgent(await api.get(agentId, callbacks));
1439
1465
  },
1440
1466
  async create(payload, callbacks) {
1441
1467
  return wrapAgent(await api.create(payload, callbacks));
@@ -1711,6 +1737,34 @@ function createCatalogsApi(cfg) {
1711
1737
  };
1712
1738
  }
1713
1739
 
1740
+ // src/api/documents.ts
1741
+ function createDocumentsApi(cfg) {
1742
+ const { base, doFetch, resolveWorkspaceId, resolveApiKey } = createHttp(cfg);
1743
+ const jsonHeaders = { "content-type": "application/json" };
1744
+ const requireWorkspace = () => {
1745
+ const workspaceId = resolveWorkspaceId();
1746
+ if (typeof workspaceId === "string" && workspaceId.trim().length > 0) {
1747
+ return;
1748
+ }
1749
+ const apiKey = resolveApiKey();
1750
+ if (typeof apiKey === "string" && apiKey.trim().length > 0) {
1751
+ return;
1752
+ }
1753
+ throw new WorkspaceNotSelectedError();
1754
+ };
1755
+ return {
1756
+ async create(files) {
1757
+ requireWorkspace();
1758
+ const res = await doFetch(`${base}/documents`, {
1759
+ method: "POST",
1760
+ body: JSON.stringify({ files }),
1761
+ headers: jsonHeaders
1762
+ });
1763
+ return res.json();
1764
+ }
1765
+ };
1766
+ }
1767
+
1714
1768
  // src/api/sip-trunks.ts
1715
1769
  function createSipTrunksApi(cfg) {
1716
1770
  const { base, doFetch } = createHttp(cfg);
@@ -2508,6 +2562,7 @@ function createClient(initialCfg) {
2508
2562
  ...catalogsApi,
2509
2563
  templates: catalogTemplatesApi
2510
2564
  },
2565
+ documents: createDocumentsApi(runtimeCfg),
2511
2566
  campaigns: createCampaignsApi(runtimeCfg),
2512
2567
  voices: voicesApi,
2513
2568
  apiKeys: apiKeysApi,
@@ -2604,6 +2659,7 @@ function createClient(initialCfg) {
2604
2659
  createCatalogTemplatesApi,
2605
2660
  createCatalogsApi,
2606
2661
  createClient,
2662
+ createDocumentsApi,
2607
2663
  createHttp,
2608
2664
  createSipTrunksApi,
2609
2665
  createToolsApi,