@getsupervisor/agents-studio-sdk 1.41.0 → 1.41.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/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 +175 -6
- package/dist/index.d.ts +175 -6
- package/dist/index.js +120 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -50,7 +51,9 @@ __export(index_exports, {
|
|
|
50
51
|
createToolsApi: () => createToolsApi,
|
|
51
52
|
createVoicesApi: () => createVoicesApi,
|
|
52
53
|
createWebhooksApi: () => createWebhooksApi,
|
|
53
|
-
createWorkspacesApi: () => createWorkspacesApi
|
|
54
|
+
createWorkspacesApi: () => createWorkspacesApi,
|
|
55
|
+
isApiErrorBody: () => isApiErrorBody,
|
|
56
|
+
isApiHttpError: () => isApiHttpError
|
|
54
57
|
});
|
|
55
58
|
module.exports = __toCommonJS(index_exports);
|
|
56
59
|
|
|
@@ -65,6 +68,14 @@ var HttpError = class extends Error {
|
|
|
65
68
|
this.name = "HttpError";
|
|
66
69
|
}
|
|
67
70
|
};
|
|
71
|
+
function isApiErrorBody(body) {
|
|
72
|
+
if (!body || typeof body !== "object") return false;
|
|
73
|
+
const candidate = body;
|
|
74
|
+
return typeof candidate.code === "string" && typeof candidate.message === "string";
|
|
75
|
+
}
|
|
76
|
+
function isApiHttpError(err) {
|
|
77
|
+
return err instanceof HttpError && isApiErrorBody(err.body);
|
|
78
|
+
}
|
|
68
79
|
var TimeoutError = class extends Error {
|
|
69
80
|
constructor(ms, url) {
|
|
70
81
|
super(`Timeout after ${ms}ms`);
|
|
@@ -81,6 +92,12 @@ var NetworkError = class extends Error {
|
|
|
81
92
|
this.name = "NetworkError";
|
|
82
93
|
}
|
|
83
94
|
};
|
|
95
|
+
var WorkspaceNotSelectedError = class extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super("Workspace is not selected");
|
|
98
|
+
this.name = "WorkspaceNotSelectedError";
|
|
99
|
+
}
|
|
100
|
+
};
|
|
84
101
|
|
|
85
102
|
// src/http.ts
|
|
86
103
|
function toQueryString(query) {
|
|
@@ -1144,9 +1161,21 @@ var createAgentEntity = (dto, options) => {
|
|
|
1144
1161
|
|
|
1145
1162
|
// src/api/agents.ts
|
|
1146
1163
|
function createAgentsApi(cfg, relatedApis) {
|
|
1147
|
-
const { base, doFetch } = createHttp(cfg);
|
|
1164
|
+
const { base, doFetch, resolveWorkspaceId, resolveApiKey } = createHttp(cfg);
|
|
1165
|
+
const requireWorkspace = () => {
|
|
1166
|
+
const workspaceId = resolveWorkspaceId();
|
|
1167
|
+
if (typeof workspaceId === "string" && workspaceId.trim().length > 0) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
const apiKey = resolveApiKey();
|
|
1171
|
+
if (typeof apiKey === "string" && apiKey.trim().length > 0) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
throw new WorkspaceNotSelectedError();
|
|
1175
|
+
};
|
|
1148
1176
|
const jsonHeaders = { "content-type": "application/json" };
|
|
1149
1177
|
const fetchAgentsPage = async (options = {}) => {
|
|
1178
|
+
requireWorkspace();
|
|
1150
1179
|
const sanitizedOptions = {
|
|
1151
1180
|
page: options.page,
|
|
1152
1181
|
limit: options.limit,
|
|
@@ -1165,12 +1194,14 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1165
1194
|
return attachPaginator(response, fetchAgentsPage, normalizedOptions);
|
|
1166
1195
|
};
|
|
1167
1196
|
const getAgentDetail = async (agentId) => {
|
|
1197
|
+
requireWorkspace();
|
|
1168
1198
|
const res = await doFetch(`${base}/agents/${agentId}`, {
|
|
1169
1199
|
method: "GET"
|
|
1170
1200
|
});
|
|
1171
1201
|
return res.json();
|
|
1172
1202
|
};
|
|
1173
1203
|
const createAgent = async (payload) => {
|
|
1204
|
+
requireWorkspace();
|
|
1174
1205
|
const res = await doFetch(`${base}/agents`, {
|
|
1175
1206
|
method: "POST",
|
|
1176
1207
|
body: JSON.stringify(payload),
|
|
@@ -1179,6 +1210,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1179
1210
|
return res.json();
|
|
1180
1211
|
};
|
|
1181
1212
|
const forkAgentFromTemplate = async (payload) => {
|
|
1213
|
+
requireWorkspace();
|
|
1182
1214
|
const res = await doFetch(`${base}/agents/from-template`, {
|
|
1183
1215
|
method: "POST",
|
|
1184
1216
|
body: JSON.stringify(payload),
|
|
@@ -1187,6 +1219,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1187
1219
|
return res.json();
|
|
1188
1220
|
};
|
|
1189
1221
|
const updateAgent = async (agentId, payload) => {
|
|
1222
|
+
requireWorkspace();
|
|
1190
1223
|
const res = await doFetch(`${base}/agents/${agentId}`, {
|
|
1191
1224
|
method: "PATCH",
|
|
1192
1225
|
body: JSON.stringify(payload),
|
|
@@ -1198,6 +1231,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
1198
1231
|
return typeof agent === "string" ? agent : agent.agentId;
|
|
1199
1232
|
};
|
|
1200
1233
|
const deleteAgent = async (agent) => {
|
|
1234
|
+
requireWorkspace();
|
|
1201
1235
|
const agentId = resolveAgentId(agent);
|
|
1202
1236
|
await doFetch(`${base}/agents/${agentId}`, {
|
|
1203
1237
|
method: "DELETE"
|
|
@@ -1520,7 +1554,15 @@ function createToolsApi(cfg) {
|
|
|
1520
1554
|
});
|
|
1521
1555
|
return res.json();
|
|
1522
1556
|
};
|
|
1523
|
-
|
|
1557
|
+
const fetchToolConnectionsPage = async (options = {}) => {
|
|
1558
|
+
const query = serializeListOptions(options ?? {});
|
|
1559
|
+
const res = await doFetch(`${base}/tools/connections`, {
|
|
1560
|
+
method: "GET",
|
|
1561
|
+
query
|
|
1562
|
+
});
|
|
1563
|
+
return res.json();
|
|
1564
|
+
};
|
|
1565
|
+
const api = {
|
|
1524
1566
|
async list(options = {}) {
|
|
1525
1567
|
const normalizedOptions = { ...options ?? {} };
|
|
1526
1568
|
const response = await fetchToolsPage(normalizedOptions);
|
|
@@ -1534,6 +1576,17 @@ function createToolsApi(cfg) {
|
|
|
1534
1576
|
const response = await fetchPage(normalizedOptions);
|
|
1535
1577
|
return attachPaginator(response, fetchPage, normalizedOptions);
|
|
1536
1578
|
},
|
|
1579
|
+
async listConnections(options = {}) {
|
|
1580
|
+
const normalizedOptions = {
|
|
1581
|
+
...options ?? {}
|
|
1582
|
+
};
|
|
1583
|
+
const response = await fetchToolConnectionsPage(normalizedOptions);
|
|
1584
|
+
return attachPaginator(
|
|
1585
|
+
response,
|
|
1586
|
+
fetchToolConnectionsPage,
|
|
1587
|
+
normalizedOptions
|
|
1588
|
+
);
|
|
1589
|
+
},
|
|
1537
1590
|
async uploadResource(toolId, payload) {
|
|
1538
1591
|
const formData = toFormData(payload);
|
|
1539
1592
|
const res = await doFetch(`${base}/tools/${toolId}/resources`, {
|
|
@@ -1579,8 +1632,47 @@ function createToolsApi(cfg) {
|
|
|
1579
1632
|
body: JSON.stringify(payload)
|
|
1580
1633
|
});
|
|
1581
1634
|
return res.json();
|
|
1635
|
+
},
|
|
1636
|
+
async createConnection(payload, options = {}) {
|
|
1637
|
+
const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
|
|
1638
|
+
const res = await doFetch(`${base}/tools/connections`, {
|
|
1639
|
+
method: "POST",
|
|
1640
|
+
headers: {
|
|
1641
|
+
...jsonHeaders,
|
|
1642
|
+
[IDEMPOTENCY_HEADER]: idempotencyKey
|
|
1643
|
+
},
|
|
1644
|
+
body: JSON.stringify(payload)
|
|
1645
|
+
});
|
|
1646
|
+
return res.json();
|
|
1647
|
+
},
|
|
1648
|
+
async executeConnection(toolAgentConnectionId, payload, options = {}) {
|
|
1649
|
+
const idempotencyKey = generateIdempotencyKey(options.idempotencyKey);
|
|
1650
|
+
const res = await doFetch(
|
|
1651
|
+
`${base}/tools/connections/${toolAgentConnectionId}/execute`,
|
|
1652
|
+
{
|
|
1653
|
+
method: "POST",
|
|
1654
|
+
headers: {
|
|
1655
|
+
...jsonHeaders,
|
|
1656
|
+
[IDEMPOTENCY_HEADER]: idempotencyKey
|
|
1657
|
+
},
|
|
1658
|
+
body: JSON.stringify(payload)
|
|
1659
|
+
}
|
|
1660
|
+
);
|
|
1661
|
+
return res.json();
|
|
1582
1662
|
}
|
|
1583
1663
|
};
|
|
1664
|
+
const connections = {
|
|
1665
|
+
connect: api.connect,
|
|
1666
|
+
create: api.createConnection,
|
|
1667
|
+
execute: api.executeConnection,
|
|
1668
|
+
list: api.listConnections,
|
|
1669
|
+
createConnection: api.createConnection,
|
|
1670
|
+
executeConnection: api.executeConnection
|
|
1671
|
+
};
|
|
1672
|
+
return {
|
|
1673
|
+
...api,
|
|
1674
|
+
connections
|
|
1675
|
+
};
|
|
1584
1676
|
}
|
|
1585
1677
|
|
|
1586
1678
|
// src/utils/catalog-voices.ts
|
|
@@ -1887,6 +1979,26 @@ function createWebhooksApi(cfg) {
|
|
|
1887
1979
|
function createWorkspacesApi(cfg) {
|
|
1888
1980
|
const { base, doFetch } = createHttp(cfg);
|
|
1889
1981
|
const jsonHeaders = { "content-type": "application/json" };
|
|
1982
|
+
const fetchWorkspacesPage = async (options = {}) => {
|
|
1983
|
+
const normalized = { ...options ?? {} };
|
|
1984
|
+
const query = serializeListOptions({
|
|
1985
|
+
page: normalized.page,
|
|
1986
|
+
limit: normalized.limit,
|
|
1987
|
+
sort: normalized.sort,
|
|
1988
|
+
fields: normalized.fields,
|
|
1989
|
+
include: normalized.include,
|
|
1990
|
+
search: normalized.search,
|
|
1991
|
+
filter: normalized.filter,
|
|
1992
|
+
or: normalized.or
|
|
1993
|
+
});
|
|
1994
|
+
const headers = normalized.refreshCache ? { "X-Cache-Refresh": "true" } : void 0;
|
|
1995
|
+
const res = await doFetch(`${base}/workspaces`, {
|
|
1996
|
+
method: "GET",
|
|
1997
|
+
query,
|
|
1998
|
+
headers
|
|
1999
|
+
});
|
|
2000
|
+
return res.json();
|
|
2001
|
+
};
|
|
1890
2002
|
const fetchPhonesPage = async (workspaceId, opts = {}) => {
|
|
1891
2003
|
const { channel } = opts ?? {};
|
|
1892
2004
|
const query = serializeListOptions(
|
|
@@ -1909,6 +2021,11 @@ function createWorkspacesApi(cfg) {
|
|
|
1909
2021
|
return res.json();
|
|
1910
2022
|
};
|
|
1911
2023
|
return {
|
|
2024
|
+
async list(options = {}) {
|
|
2025
|
+
const normalizedOptions = { ...options ?? {} };
|
|
2026
|
+
const response = await fetchWorkspacesPage(normalizedOptions);
|
|
2027
|
+
return attachPaginator(response, fetchWorkspacesPage, normalizedOptions);
|
|
2028
|
+
},
|
|
1912
2029
|
async listPhones(workspaceId, opts = {}) {
|
|
1913
2030
|
const normalizedOptions = {
|
|
1914
2031
|
...opts ?? {}
|
|
@@ -2097,6 +2214,7 @@ function createClient(initialCfg) {
|
|
|
2097
2214
|
HttpError,
|
|
2098
2215
|
NetworkError,
|
|
2099
2216
|
TimeoutError,
|
|
2217
|
+
WorkspaceNotSelectedError,
|
|
2100
2218
|
bindAgentBlueprints,
|
|
2101
2219
|
bindAgentPhones,
|
|
2102
2220
|
bindAgentSchedule,
|
|
@@ -2125,6 +2243,8 @@ function createClient(initialCfg) {
|
|
|
2125
2243
|
createToolsApi,
|
|
2126
2244
|
createVoicesApi,
|
|
2127
2245
|
createWebhooksApi,
|
|
2128
|
-
createWorkspacesApi
|
|
2246
|
+
createWorkspacesApi,
|
|
2247
|
+
isApiErrorBody,
|
|
2248
|
+
isApiHttpError
|
|
2129
2249
|
});
|
|
2130
2250
|
//# sourceMappingURL=index.cjs.map
|