@getsupervisor/agents-studio-sdk 1.41.0 → 1.41.1
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 +103 -89
- package/README.md +20 -0
- package/dist/index.cjs +124 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -6
- package/dist/index.d.ts +131 -6
- package/dist/index.js +120 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,6 +9,14 @@ var HttpError = class extends Error {
|
|
|
9
9
|
this.name = "HttpError";
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
+
function isApiErrorBody(body) {
|
|
13
|
+
if (!body || typeof body !== "object") return false;
|
|
14
|
+
const candidate = body;
|
|
15
|
+
return typeof candidate.code === "string" && typeof candidate.message === "string";
|
|
16
|
+
}
|
|
17
|
+
function isApiHttpError(err) {
|
|
18
|
+
return err instanceof HttpError && isApiErrorBody(err.body);
|
|
19
|
+
}
|
|
12
20
|
var TimeoutError = class extends Error {
|
|
13
21
|
constructor(ms, url) {
|
|
14
22
|
super(`Timeout after ${ms}ms`);
|
|
@@ -25,6 +33,12 @@ var NetworkError = class extends Error {
|
|
|
25
33
|
this.name = "NetworkError";
|
|
26
34
|
}
|
|
27
35
|
};
|
|
36
|
+
var WorkspaceNotSelectedError = class extends Error {
|
|
37
|
+
constructor() {
|
|
38
|
+
super("Workspace is not selected");
|
|
39
|
+
this.name = "WorkspaceNotSelectedError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
28
42
|
|
|
29
43
|
// src/http.ts
|
|
30
44
|
function toQueryString(query) {
|
|
@@ -1088,9 +1102,21 @@ var createAgentEntity = (dto, options) => {
|
|
|
1088
1102
|
|
|
1089
1103
|
// src/api/agents.ts
|
|
1090
1104
|
function createAgentsApi(cfg, relatedApis) {
|
|
1091
|
-
const { base, doFetch } = createHttp(cfg);
|
|
1105
|
+
const { base, doFetch, resolveWorkspaceId, resolveApiKey } = createHttp(cfg);
|
|
1106
|
+
const requireWorkspace = () => {
|
|
1107
|
+
const workspaceId = resolveWorkspaceId();
|
|
1108
|
+
if (typeof workspaceId === "string" && workspaceId.trim().length > 0) {
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
const apiKey = resolveApiKey();
|
|
1112
|
+
if (typeof apiKey === "string" && apiKey.trim().length > 0) {
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
throw new WorkspaceNotSelectedError();
|
|
1116
|
+
};
|
|
1092
1117
|
const jsonHeaders = { "content-type": "application/json" };
|
|
1093
1118
|
const fetchAgentsPage = async (options = {}) => {
|
|
1119
|
+
requireWorkspace();
|
|
1094
1120
|
const sanitizedOptions = {
|
|
1095
1121
|
page: options.page,
|
|
1096
1122
|
limit: options.limit,
|
|
@@ -1109,12 +1135,14 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1109
1135
|
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
1110
1136
|
};
|
|
1111
1137
|
const getAgentDetail = async (agentId) => {
|
|
1138
|
+
requireWorkspace();
|
|
1112
1139
|
const res = await doFetch(`${base}/agents/${agentId}`, {
|
|
1113
1140
|
method: "GET"
|
|
1114
1141
|
});
|
|
1115
1142
|
return res.json();
|
|
1116
1143
|
};
|
|
1117
1144
|
const createAgent = async (payload) => {
|
|
1145
|
+
requireWorkspace();
|
|
1118
1146
|
const res = await doFetch(`${base}/agents`, {
|
|
1119
1147
|
method: "POST",
|
|
1120
1148
|
body: JSON.stringify(payload),
|
|
@@ -1123,6 +1151,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1123
1151
|
return res.json();
|
|
1124
1152
|
};
|
|
1125
1153
|
const forkAgentFromTemplate = async (payload) => {
|
|
1154
|
+
requireWorkspace();
|
|
1126
1155
|
const res = await doFetch(`${base}/agents/from-template`, {
|
|
1127
1156
|
method: "POST",
|
|
1128
1157
|
body: JSON.stringify(payload),
|
|
@@ -1131,6 +1160,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1131
1160
|
return res.json();
|
|
1132
1161
|
};
|
|
1133
1162
|
const updateAgent = async (agentId, payload) => {
|
|
1163
|
+
requireWorkspace();
|
|
1134
1164
|
const res = await doFetch(`${base}/agents/${agentId}`, {
|
|
1135
1165
|
method: "PATCH",
|
|
1136
1166
|
body: JSON.stringify(payload),
|
|
@@ -1142,6 +1172,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1142
1172
|
return typeof agent === "string" ? agent : agent.agentId;
|
|
1143
1173
|
};
|
|
1144
1174
|
const deleteAgent = async (agent) => {
|
|
1175
|
+
requireWorkspace();
|
|
1145
1176
|
const agentId = resolveAgentId(agent);
|
|
1146
1177
|
await doFetch(`${base}/agents/${agentId}`, {
|
|
1147
1178
|
method: "DELETE"
|
|
@@ -1464,7 +1495,15 @@ function createToolsApi(cfg) {
|
|
|
1464
1495
|
});
|
|
1465
1496
|
return res.json();
|
|
1466
1497
|
};
|
|
1467
|
-
|
|
1498
|
+
const fetchToolConnectionsPage = async (options = {}) => {
|
|
1499
|
+
const query = serializeListOptions(options ?? {});
|
|
1500
|
+
const res = await doFetch(`${base}/tools/connections`, {
|
|
1501
|
+
method: "GET",
|
|
1502
|
+
query
|
|
1503
|
+
});
|
|
1504
|
+
return res.json();
|
|
1505
|
+
};
|
|
1506
|
+
const api = {
|
|
1468
1507
|
async list(options = {}) {
|
|
1469
1508
|
const normalizedOptions = { ...options ?? {} };
|
|
1470
1509
|
const response = await fetchToolsPage(normalizedOptions);
|
|
@@ -1478,6 +1517,17 @@ function createToolsApi(cfg) {
|
|
|
1478
1517
|
const response = await fetchPage(normalizedOptions);
|
|
1479
1518
|
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
1480
1519
|
},
|
|
1520
|
+
async listConnections(options = {}) {
|
|
1521
|
+
const normalizedOptions = {
|
|
1522
|
+
...options ?? {}
|
|
1523
|
+
};
|
|
1524
|
+
const response = await fetchToolConnectionsPage(normalizedOptions);
|
|
1525
|
+
return attachPaginator(
|
|
1526
|
+
response,
|
|
1527
|
+
fetchToolConnectionsPage,
|
|
1528
|
+
normalizedOptions
|
|
1529
|
+
);
|
|
1530
|
+
},
|
|
1481
1531
|
async uploadResource(toolId, payload) {
|
|
1482
1532
|
const formData = toFormData(payload);
|
|
1483
1533
|
const res = await doFetch(`${base}/tools/${toolId}/resources`, {
|
|
@@ -1523,8 +1573,47 @@ function createToolsApi(cfg) {
|
|
|
1523
1573
|
body: JSON.stringify(payload)
|
|
1524
1574
|
});
|
|
1525
1575
|
return res.json();
|
|
1576
|
+
},
|
|
1577
|
+
async createConnection(payload, options = {}) {
|
|
1578
|
+
const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
|
|
1579
|
+
const res = await doFetch(`${base}/tools/connections`, {
|
|
1580
|
+
method: "POST",
|
|
1581
|
+
headers: {
|
|
1582
|
+
...jsonHeaders,
|
|
1583
|
+
[IDEMPOTENCY_HEADER]: idempotencyKey
|
|
1584
|
+
},
|
|
1585
|
+
body: JSON.stringify(payload)
|
|
1586
|
+
});
|
|
1587
|
+
return res.json();
|
|
1588
|
+
},
|
|
1589
|
+
async executeConnection(toolAgentConnectionId, payload, options = {}) {
|
|
1590
|
+
const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
|
|
1591
|
+
const res = await doFetch(
|
|
1592
|
+
`${base}/tools/connections/${toolAgentConnectionId}/execute`,
|
|
1593
|
+
{
|
|
1594
|
+
method: "POST",
|
|
1595
|
+
headers: {
|
|
1596
|
+
...jsonHeaders,
|
|
1597
|
+
[IDEMPOTENCY_HEADER]: idempotencyKey
|
|
1598
|
+
},
|
|
1599
|
+
body: JSON.stringify(payload)
|
|
1600
|
+
}
|
|
1601
|
+
);
|
|
1602
|
+
return res.json();
|
|
1526
1603
|
}
|
|
1527
1604
|
};
|
|
1605
|
+
const connections = {
|
|
1606
|
+
connect: api.connect,
|
|
1607
|
+
create: api.createConnection,
|
|
1608
|
+
execute: api.executeConnection,
|
|
1609
|
+
list: api.listConnections,
|
|
1610
|
+
createConnection: api.createConnection,
|
|
1611
|
+
executeConnection: api.executeConnection
|
|
1612
|
+
};
|
|
1613
|
+
return {
|
|
1614
|
+
...api,
|
|
1615
|
+
connections
|
|
1616
|
+
};
|
|
1528
1617
|
}
|
|
1529
1618
|
|
|
1530
1619
|
// src/utils/catalog-voices.ts
|
|
@@ -1831,6 +1920,26 @@ function createWebhooksApi(cfg) {
|
|
|
1831
1920
|
function createWorkspacesApi(cfg) {
|
|
1832
1921
|
const { base, doFetch } = createHttp(cfg);
|
|
1833
1922
|
const jsonHeaders = { "content-type": "application/json" };
|
|
1923
|
+
const fetchWorkspacesPage = async (options = {}) => {
|
|
1924
|
+
const normalized = { ...options ?? {} };
|
|
1925
|
+
const query = serializeListOptions({
|
|
1926
|
+
page: normalized.page,
|
|
1927
|
+
limit: normalized.limit,
|
|
1928
|
+
sort: normalized.sort,
|
|
1929
|
+
fields: normalized.fields,
|
|
1930
|
+
include: normalized.include,
|
|
1931
|
+
search: normalized.search,
|
|
1932
|
+
filter: normalized.filter,
|
|
1933
|
+
or: normalized.or
|
|
1934
|
+
});
|
|
1935
|
+
const headers = normalized.refreshCache ? { "X-Cache-Refresh": "true" } : void 0;
|
|
1936
|
+
const res = await doFetch(`${base}/workspaces`, {
|
|
1937
|
+
method: "GET",
|
|
1938
|
+
query,
|
|
1939
|
+
headers
|
|
1940
|
+
});
|
|
1941
|
+
return res.json();
|
|
1942
|
+
};
|
|
1834
1943
|
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
1835
1944
|
const { channel } = opts ?? {};
|
|
1836
1945
|
const query = serializeListOptions(
|
|
@@ -1853,6 +1962,11 @@ function createWorkspacesApi(cfg) {
|
|
|
1853
1962
|
return res.json();
|
|
1854
1963
|
};
|
|
1855
1964
|
return {
|
|
1965
|
+
async list(options = {}) {
|
|
1966
|
+
const normalizedOptions = { ...options ?? {} };
|
|
1967
|
+
const response = await fetchWorkspacesPage(normalizedOptions);
|
|
1968
|
+
return attachPaginator(response, fetchWorkspacesPage, normalizedOptions);
|
|
1969
|
+
},
|
|
1856
1970
|
async listPhones(workspaceId, opts = {}) {
|
|
1857
1971
|
const normalizedOptions = {
|
|
1858
1972
|
...opts ?? {}
|
|
@@ -2040,6 +2154,7 @@ export {
|
|
|
2040
2154
|
HttpError,
|
|
2041
2155
|
NetworkError,
|
|
2042
2156
|
TimeoutError,
|
|
2157
|
+
WorkspaceNotSelectedError,
|
|
2043
2158
|
bindAgentBlueprints,
|
|
2044
2159
|
bindAgentPhones,
|
|
2045
2160
|
bindAgentSchedule,
|
|
@@ -2068,6 +2183,8 @@ export {
|
|
|
2068
2183
|
createToolsApi,
|
|
2069
2184
|
createVoicesApi,
|
|
2070
2185
|
createWebhooksApi,
|
|
2071
|
-
createWorkspacesApi
|
|
2186
|
+
createWorkspacesApi,
|
|
2187
|
+
isApiErrorBody,
|
|
2188
|
+
isApiHttpError
|
|
2072
2189
|
};
|
|
2073
2190
|
//# sourceMappingURL=index.js.map
|