@getsupervisor/agents-studio-sdk 1.2.0 → 1.3.0
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 +492 -143
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +677 -44
- package/dist/index.d.ts +677 -44
- package/dist/index.js +487 -143
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,45 +1,3 @@
|
|
|
1
|
-
// src/entities/agent.ts
|
|
2
|
-
var bindAgentInstructions = (api, agentId) => ({
|
|
3
|
-
list(opts) {
|
|
4
|
-
return api.list(agentId, opts);
|
|
5
|
-
},
|
|
6
|
-
create(payload) {
|
|
7
|
-
return api.create(agentId, payload);
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
var bindAgentKnowledge = (api, agentId) => ({
|
|
11
|
-
upload(payload) {
|
|
12
|
-
return api.upload(agentId, payload);
|
|
13
|
-
},
|
|
14
|
-
listBases() {
|
|
15
|
-
return api.listBases(agentId);
|
|
16
|
-
},
|
|
17
|
-
listUploads() {
|
|
18
|
-
return api.listUploads(agentId);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
var bindAgentPhones = (api, agentId) => ({
|
|
22
|
-
connect(payload) {
|
|
23
|
-
return api.connect(agentId, payload);
|
|
24
|
-
},
|
|
25
|
-
disconnect(phoneId) {
|
|
26
|
-
return api.disconnect(agentId, phoneId);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
var createAgentEntity = (dto, options) => {
|
|
30
|
-
const { instructionsApi, knowledgeApi, phonesApi, reload } = options;
|
|
31
|
-
const entity = {
|
|
32
|
-
...dto,
|
|
33
|
-
instructions: bindAgentInstructions(instructionsApi, dto.agentId),
|
|
34
|
-
knowledge: bindAgentKnowledge(knowledgeApi, dto.agentId),
|
|
35
|
-
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
36
|
-
async refresh() {
|
|
37
|
-
return reload(dto.agentId);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return Object.freeze(entity);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
1
|
// src/errors.ts
|
|
44
2
|
var HttpError = class extends Error {
|
|
45
3
|
constructor(status, statusText, body, url) {
|
|
@@ -69,6 +27,36 @@ var NetworkError = class extends Error {
|
|
|
69
27
|
};
|
|
70
28
|
|
|
71
29
|
// src/http.ts
|
|
30
|
+
function toQueryString(query) {
|
|
31
|
+
if (!query) return void 0;
|
|
32
|
+
if (typeof query === "string") {
|
|
33
|
+
const normalized = query.trim().replace(/^\?/, "");
|
|
34
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
35
|
+
}
|
|
36
|
+
if (query instanceof URLSearchParams) {
|
|
37
|
+
const result2 = query.toString();
|
|
38
|
+
return result2.length > 0 ? result2 : void 0;
|
|
39
|
+
}
|
|
40
|
+
const params = new URLSearchParams();
|
|
41
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
42
|
+
if (value === null || value === void 0) return;
|
|
43
|
+
const values = Array.isArray(value) ? value : [value];
|
|
44
|
+
values.forEach((item) => {
|
|
45
|
+
params.append(key, String(item));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const result = params.toString();
|
|
49
|
+
return result.length > 0 ? result : void 0;
|
|
50
|
+
}
|
|
51
|
+
function appendQuery(url, query) {
|
|
52
|
+
const qs = toQueryString(query);
|
|
53
|
+
if (!qs) return url;
|
|
54
|
+
const [base, hash] = url.split("#");
|
|
55
|
+
const hasQuery = base.includes("?");
|
|
56
|
+
const needsSeparator = hasQuery ? base.endsWith("?") || base.endsWith("&") ? "" : "&" : "?";
|
|
57
|
+
const built = `${base}${needsSeparator}${qs}`;
|
|
58
|
+
return hash ? `${built}#${hash}` : built;
|
|
59
|
+
}
|
|
72
60
|
function sleep(ms) {
|
|
73
61
|
return new Promise((r) => setTimeout(r, ms));
|
|
74
62
|
}
|
|
@@ -143,25 +131,31 @@ function createHttp(cfg) {
|
|
|
143
131
|
};
|
|
144
132
|
};
|
|
145
133
|
async function doFetch(url, init = {}) {
|
|
134
|
+
const { query, ...requestInit } = init;
|
|
135
|
+
const targetUrl = appendQuery(url, query);
|
|
146
136
|
const ab = new AbortController();
|
|
147
137
|
const req = async () => {
|
|
148
138
|
try {
|
|
149
|
-
const finalHeaders = buildHeaders(
|
|
139
|
+
const finalHeaders = buildHeaders(requestInit.headers);
|
|
150
140
|
const res = await withTimeout(
|
|
151
|
-
fx(
|
|
141
|
+
fx(targetUrl, {
|
|
142
|
+
...requestInit,
|
|
143
|
+
headers: finalHeaders,
|
|
144
|
+
signal: ab.signal
|
|
145
|
+
}),
|
|
152
146
|
timeout,
|
|
153
147
|
ab,
|
|
154
|
-
|
|
148
|
+
targetUrl
|
|
155
149
|
);
|
|
156
150
|
if (!res.ok) {
|
|
157
151
|
const body = await res.clone().json().catch(() => void 0);
|
|
158
|
-
throw new HttpError(res.status, res.statusText, body,
|
|
152
|
+
throw new HttpError(res.status, res.statusText, body, targetUrl);
|
|
159
153
|
}
|
|
160
154
|
return res;
|
|
161
155
|
} catch (e) {
|
|
162
|
-
if (e.name === "AbortError") throw new TimeoutError(timeout,
|
|
156
|
+
if (e.name === "AbortError") throw new TimeoutError(timeout, targetUrl);
|
|
163
157
|
if (e instanceof HttpError) throw e;
|
|
164
|
-
throw new NetworkError(e,
|
|
158
|
+
throw new NetworkError(e, targetUrl);
|
|
165
159
|
}
|
|
166
160
|
};
|
|
167
161
|
return withRetry(req, retry);
|
|
@@ -177,13 +171,378 @@ function createHttp(cfg) {
|
|
|
177
171
|
};
|
|
178
172
|
}
|
|
179
173
|
|
|
174
|
+
// src/utils/query.ts
|
|
175
|
+
function serializeListOptions(options = {}, extra = {}) {
|
|
176
|
+
const params = new URLSearchParams();
|
|
177
|
+
appendParam(params, "page", options.page);
|
|
178
|
+
appendParam(params, "limit", options.limit);
|
|
179
|
+
appendParam(params, "sort", options.sort);
|
|
180
|
+
appendParam(params, "fields", options.fields);
|
|
181
|
+
appendParam(params, "include", options.include);
|
|
182
|
+
appendParam(params, "q", options.search);
|
|
183
|
+
appendParam(params, "filter", mapQueryValue(options.filter));
|
|
184
|
+
appendParam(params, "or", mapQueryValue(options.or));
|
|
185
|
+
Object.entries(extra).forEach(([key, value]) => {
|
|
186
|
+
appendParam(params, key, value);
|
|
187
|
+
});
|
|
188
|
+
return params.toString();
|
|
189
|
+
}
|
|
190
|
+
function mapQueryValue(value) {
|
|
191
|
+
if (value === void 0 || value === null) {
|
|
192
|
+
return void 0;
|
|
193
|
+
}
|
|
194
|
+
if (isQueryBuilderSerializable(value)) {
|
|
195
|
+
return getQueryBuilderString(value);
|
|
196
|
+
}
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
function appendParam(params, key, value) {
|
|
200
|
+
if (value === void 0 || value === null) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (value instanceof Date) {
|
|
204
|
+
params.set(key, value.toISOString());
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (isQueryBuilderSerializable(value)) {
|
|
208
|
+
params.set(key, getQueryBuilderString(value));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (typeof value === "string") {
|
|
212
|
+
params.set(key, value);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
216
|
+
params.set(key, String(value));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (typeof value === "bigint") {
|
|
220
|
+
params.set(key, value.toString());
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(value)) {
|
|
224
|
+
if (value.length === 0) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (value.every(isPrimitive)) {
|
|
228
|
+
params.set(key, value.map((item) => String(item)).join(","));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
value.forEach((item, idx) => {
|
|
232
|
+
appendParam(params, `${key}[${idx}]`, item);
|
|
233
|
+
});
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (isPlainObject(value)) {
|
|
237
|
+
Object.entries(value).forEach(([childKey, childValue]) => {
|
|
238
|
+
appendParam(params, `${key}[${childKey}]`, childValue);
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
params.set(key, String(value));
|
|
243
|
+
}
|
|
244
|
+
function isPrimitive(value) {
|
|
245
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint";
|
|
246
|
+
}
|
|
247
|
+
function isPlainObject(value) {
|
|
248
|
+
if (value === null || typeof value !== "object") {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
const proto = Object.getPrototypeOf(value);
|
|
252
|
+
return proto === Object.prototype || proto === null;
|
|
253
|
+
}
|
|
254
|
+
function isQueryBuilderSerializable(value) {
|
|
255
|
+
return !!value && typeof value === "object" && typeof value.build === "function";
|
|
256
|
+
}
|
|
257
|
+
function getQueryBuilderString(value) {
|
|
258
|
+
const build = value.build;
|
|
259
|
+
if (typeof build !== "function") {
|
|
260
|
+
throw new TypeError(
|
|
261
|
+
"Query builder values must expose a build() method returning a string."
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (build.length > 0) {
|
|
265
|
+
const stringValue = value.toString?.();
|
|
266
|
+
if (stringValue && stringValue !== "[object Object]") {
|
|
267
|
+
return stringValue;
|
|
268
|
+
}
|
|
269
|
+
throw new TypeError(
|
|
270
|
+
"Query builder instances passed to the SDK must expose a zero-argument build() method. Did you pass QueryBuilder instead of Query?"
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const result = build.call(value);
|
|
274
|
+
if (typeof result === "string") {
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
if (result === void 0 || result === null) {
|
|
278
|
+
throw new TypeError(
|
|
279
|
+
"Query builder build() must return a string representation of the query."
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return String(result);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/api/agent-instructions.ts
|
|
286
|
+
function createAgentInstructionsApi(cfg) {
|
|
287
|
+
const { base, doFetch } = createHttp(cfg);
|
|
288
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
289
|
+
return {
|
|
290
|
+
async list(agentId, opts = {}) {
|
|
291
|
+
const { versionId, ...queryOptions } = opts;
|
|
292
|
+
const query = serializeListOptions(queryOptions, { versionId });
|
|
293
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
294
|
+
method: "GET",
|
|
295
|
+
query
|
|
296
|
+
});
|
|
297
|
+
return res.json();
|
|
298
|
+
},
|
|
299
|
+
async create(agentId, payload) {
|
|
300
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: jsonHeaders,
|
|
303
|
+
body: JSON.stringify(payload)
|
|
304
|
+
});
|
|
305
|
+
return res.json();
|
|
306
|
+
},
|
|
307
|
+
async update(agentId, instructionId, payload) {
|
|
308
|
+
const res = await doFetch(
|
|
309
|
+
`${base}/v1/agents/${agentId}/instructions/${instructionId}`,
|
|
310
|
+
{
|
|
311
|
+
method: "PATCH",
|
|
312
|
+
headers: jsonHeaders,
|
|
313
|
+
body: JSON.stringify(payload)
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
return res.json();
|
|
317
|
+
},
|
|
318
|
+
async delete(agentId, instructionId) {
|
|
319
|
+
await doFetch(
|
|
320
|
+
`${base}/v1/agents/${agentId}/instructions/${instructionId}`,
|
|
321
|
+
{
|
|
322
|
+
method: "DELETE"
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/api/agent-knowledge.ts
|
|
330
|
+
function createAgentKnowledgeApi(cfg) {
|
|
331
|
+
const { base, doFetch } = createHttp(cfg);
|
|
332
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
333
|
+
return {
|
|
334
|
+
async upload(agentId, payload) {
|
|
335
|
+
const res = await doFetch(
|
|
336
|
+
`${base}/v1/agents/${agentId}/knowledge/upload`,
|
|
337
|
+
{
|
|
338
|
+
method: "POST",
|
|
339
|
+
headers: jsonHeaders,
|
|
340
|
+
body: JSON.stringify(payload)
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
return res.json();
|
|
344
|
+
},
|
|
345
|
+
async listBases(agentId, opts = {}) {
|
|
346
|
+
const query = serializeListOptions(opts);
|
|
347
|
+
const res = await doFetch(
|
|
348
|
+
`${base}/v1/agents/${agentId}/knowledge/bases`,
|
|
349
|
+
{
|
|
350
|
+
method: "GET",
|
|
351
|
+
query
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
return res.json();
|
|
355
|
+
},
|
|
356
|
+
async listUploads(agentId, opts = {}) {
|
|
357
|
+
const query = serializeListOptions(opts);
|
|
358
|
+
const res = await doFetch(
|
|
359
|
+
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
360
|
+
{
|
|
361
|
+
method: "GET",
|
|
362
|
+
query
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
return res.json();
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/api/agent-phones.ts
|
|
371
|
+
function createAgentPhonesApi(cfg) {
|
|
372
|
+
const { base, doFetch } = createHttp(cfg);
|
|
373
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
374
|
+
return {
|
|
375
|
+
async connect(agentId, payload) {
|
|
376
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/phones`, {
|
|
377
|
+
method: "POST",
|
|
378
|
+
headers: jsonHeaders,
|
|
379
|
+
body: JSON.stringify(payload)
|
|
380
|
+
});
|
|
381
|
+
return res.json();
|
|
382
|
+
},
|
|
383
|
+
async disconnect(agentId, phoneId) {
|
|
384
|
+
await doFetch(`${base}/v1/agents/${agentId}/phones/${phoneId}`, {
|
|
385
|
+
method: "DELETE"
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/api/agent-schedule.ts
|
|
392
|
+
function createAgentScheduleApi(cfg) {
|
|
393
|
+
const { base, doFetch } = createHttp(cfg);
|
|
394
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
395
|
+
return {
|
|
396
|
+
async get(agentId) {
|
|
397
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/schedule`, {
|
|
398
|
+
method: "GET"
|
|
399
|
+
});
|
|
400
|
+
return res.json();
|
|
401
|
+
},
|
|
402
|
+
async update(agentId, payload) {
|
|
403
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/schedule`, {
|
|
404
|
+
method: "PUT",
|
|
405
|
+
headers: jsonHeaders,
|
|
406
|
+
body: JSON.stringify(payload)
|
|
407
|
+
});
|
|
408
|
+
return res.json();
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/api/agent-versions.ts
|
|
414
|
+
function createAgentVersionsApi(cfg) {
|
|
415
|
+
const { base, doFetch } = createHttp(cfg);
|
|
416
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
417
|
+
return {
|
|
418
|
+
async list(agentId, opts = {}) {
|
|
419
|
+
const { status, ...queryOptions } = opts;
|
|
420
|
+
const query = serializeListOptions(queryOptions, { status });
|
|
421
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
422
|
+
method: "GET",
|
|
423
|
+
query
|
|
424
|
+
});
|
|
425
|
+
return res.json();
|
|
426
|
+
},
|
|
427
|
+
async get(agentId, versionId) {
|
|
428
|
+
const res = await doFetch(
|
|
429
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}`,
|
|
430
|
+
{
|
|
431
|
+
method: "GET"
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
return res.json();
|
|
435
|
+
},
|
|
436
|
+
async create(agentId, payload) {
|
|
437
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
438
|
+
method: "POST",
|
|
439
|
+
headers: jsonHeaders,
|
|
440
|
+
body: JSON.stringify(payload)
|
|
441
|
+
});
|
|
442
|
+
return res.json();
|
|
443
|
+
},
|
|
444
|
+
async update(agentId, versionId, payload) {
|
|
445
|
+
const res = await doFetch(
|
|
446
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}`,
|
|
447
|
+
{
|
|
448
|
+
method: "PATCH",
|
|
449
|
+
headers: jsonHeaders,
|
|
450
|
+
body: JSON.stringify(payload)
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
return res.json();
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/entities/agent.ts
|
|
459
|
+
var bindAgentInstructions = (api, agentId) => ({
|
|
460
|
+
list(opts) {
|
|
461
|
+
return api.list(agentId, opts);
|
|
462
|
+
},
|
|
463
|
+
create(payload) {
|
|
464
|
+
return api.create(agentId, payload);
|
|
465
|
+
},
|
|
466
|
+
update(instructionId, payload) {
|
|
467
|
+
return api.update(agentId, instructionId, payload);
|
|
468
|
+
},
|
|
469
|
+
delete(instructionId) {
|
|
470
|
+
return api.delete(agentId, instructionId);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
var bindAgentKnowledge = (api, agentId) => ({
|
|
474
|
+
upload(payload) {
|
|
475
|
+
return api.upload(agentId, payload);
|
|
476
|
+
},
|
|
477
|
+
listBases(opts) {
|
|
478
|
+
return api.listBases(agentId, opts);
|
|
479
|
+
},
|
|
480
|
+
listUploads(opts) {
|
|
481
|
+
return api.listUploads(agentId, opts);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
var bindAgentPhones = (api, agentId) => ({
|
|
485
|
+
connect(payload) {
|
|
486
|
+
return api.connect(agentId, payload);
|
|
487
|
+
},
|
|
488
|
+
disconnect(phoneId) {
|
|
489
|
+
return api.disconnect(agentId, phoneId);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
var bindAgentSchedule = (api, agentId) => ({
|
|
493
|
+
get() {
|
|
494
|
+
return api.get(agentId);
|
|
495
|
+
},
|
|
496
|
+
update(payload) {
|
|
497
|
+
return api.update(agentId, payload);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
var bindAgentVersions = (api, agentId) => ({
|
|
501
|
+
list(opts) {
|
|
502
|
+
return api.list(agentId, opts);
|
|
503
|
+
},
|
|
504
|
+
get(versionId) {
|
|
505
|
+
return api.get(agentId, versionId);
|
|
506
|
+
},
|
|
507
|
+
create(payload) {
|
|
508
|
+
return api.create(agentId, payload);
|
|
509
|
+
},
|
|
510
|
+
update(versionId, payload) {
|
|
511
|
+
return api.update(agentId, versionId, payload);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
var createAgentEntity = (dto, options) => {
|
|
515
|
+
const {
|
|
516
|
+
instructionsApi,
|
|
517
|
+
knowledgeApi,
|
|
518
|
+
phonesApi,
|
|
519
|
+
scheduleApi,
|
|
520
|
+
versionsApi,
|
|
521
|
+
reload
|
|
522
|
+
} = options;
|
|
523
|
+
const entity = {
|
|
524
|
+
...dto,
|
|
525
|
+
instructions: bindAgentInstructions(instructionsApi, dto.agentId),
|
|
526
|
+
knowledge: bindAgentKnowledge(knowledgeApi, dto.agentId),
|
|
527
|
+
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
528
|
+
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
529
|
+
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
530
|
+
async refresh() {
|
|
531
|
+
return reload(dto.agentId);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
return Object.freeze(entity);
|
|
535
|
+
};
|
|
536
|
+
|
|
180
537
|
// src/api/agents.ts
|
|
181
538
|
function createAgentsApi(cfg, relatedApis) {
|
|
182
539
|
const { base, doFetch } = createHttp(cfg);
|
|
183
540
|
const jsonHeaders = { "content-type": "application/json" };
|
|
184
|
-
const listAgents = async () => {
|
|
541
|
+
const listAgents = async (options = {}) => {
|
|
542
|
+
const query = serializeListOptions(options);
|
|
185
543
|
const res = await doFetch(`${base}/v1/agents`, {
|
|
186
|
-
method: "GET"
|
|
544
|
+
method: "GET",
|
|
545
|
+
query
|
|
187
546
|
});
|
|
188
547
|
return res.json();
|
|
189
548
|
};
|
|
@@ -228,6 +587,8 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
228
587
|
instructionsApi: relatedApis.instructionsApi,
|
|
229
588
|
knowledgeApi: relatedApis.knowledgeApi,
|
|
230
589
|
phonesApi: relatedApis.phonesApi,
|
|
590
|
+
scheduleApi: relatedApis.scheduleApi,
|
|
591
|
+
versionsApi: relatedApis.versionsApi,
|
|
231
592
|
reload: async (agentId) => {
|
|
232
593
|
const latest = await getAgentDetail(agentId);
|
|
233
594
|
return wrapAgent(latest);
|
|
@@ -235,6 +596,14 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
235
596
|
});
|
|
236
597
|
return {
|
|
237
598
|
...baseApi,
|
|
599
|
+
async list(options = {}) {
|
|
600
|
+
const response = await listAgents(options);
|
|
601
|
+
const items = Array.isArray(response.data) ? response.data : [];
|
|
602
|
+
return {
|
|
603
|
+
...response,
|
|
604
|
+
data: items.map((summary) => wrapAgent(summary))
|
|
605
|
+
};
|
|
606
|
+
},
|
|
238
607
|
async get(agentId) {
|
|
239
608
|
const detail = await getAgentDetail(agentId);
|
|
240
609
|
return wrapAgent(detail);
|
|
@@ -250,60 +619,21 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
250
619
|
};
|
|
251
620
|
}
|
|
252
621
|
|
|
253
|
-
// src/api/
|
|
254
|
-
function
|
|
255
|
-
const { base, doFetch } = createHttp(cfg);
|
|
256
|
-
const jsonHeaders = { "content-type": "application/json" };
|
|
257
|
-
return {
|
|
258
|
-
async upload(agentId, payload) {
|
|
259
|
-
const res = await doFetch(
|
|
260
|
-
`${base}/v1/agents/${agentId}/knowledge/upload`,
|
|
261
|
-
{
|
|
262
|
-
method: "POST",
|
|
263
|
-
headers: jsonHeaders,
|
|
264
|
-
body: JSON.stringify(payload)
|
|
265
|
-
}
|
|
266
|
-
);
|
|
267
|
-
return res.json();
|
|
268
|
-
},
|
|
269
|
-
async listBases(agentId) {
|
|
270
|
-
const res = await doFetch(
|
|
271
|
-
`${base}/v1/agents/${agentId}/knowledge/bases`,
|
|
272
|
-
{
|
|
273
|
-
method: "GET"
|
|
274
|
-
}
|
|
275
|
-
);
|
|
276
|
-
return res.json();
|
|
277
|
-
},
|
|
278
|
-
async listUploads(agentId) {
|
|
279
|
-
const res = await doFetch(
|
|
280
|
-
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
281
|
-
{
|
|
282
|
-
method: "GET"
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
return res.json();
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// src/api/agent-instructions.ts
|
|
291
|
-
function createAgentInstructionsApi(cfg) {
|
|
622
|
+
// src/api/tools.ts
|
|
623
|
+
function createToolsApi(cfg) {
|
|
292
624
|
const { base, doFetch } = createHttp(cfg);
|
|
293
625
|
const jsonHeaders = { "content-type": "application/json" };
|
|
294
626
|
return {
|
|
295
|
-
async list(
|
|
296
|
-
const
|
|
297
|
-
const res = await doFetch(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
);
|
|
627
|
+
async list(options = {}) {
|
|
628
|
+
const query = serializeListOptions(options);
|
|
629
|
+
const res = await doFetch(`${base}/v1/tools`, {
|
|
630
|
+
method: "GET",
|
|
631
|
+
query
|
|
632
|
+
});
|
|
303
633
|
return res.json();
|
|
304
634
|
},
|
|
305
|
-
async
|
|
306
|
-
const res = await doFetch(`${base}/v1/
|
|
635
|
+
async execute(toolId, payload) {
|
|
636
|
+
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
307
637
|
method: "POST",
|
|
308
638
|
headers: jsonHeaders,
|
|
309
639
|
body: JSON.stringify(payload)
|
|
@@ -313,23 +643,35 @@ function createAgentInstructionsApi(cfg) {
|
|
|
313
643
|
};
|
|
314
644
|
}
|
|
315
645
|
|
|
316
|
-
// src/api/
|
|
317
|
-
function
|
|
646
|
+
// src/api/voices.ts
|
|
647
|
+
function createVoicesApi(cfg) {
|
|
318
648
|
const { base, doFetch } = createHttp(cfg);
|
|
319
|
-
const jsonHeaders = { "content-type": "application/json" };
|
|
320
649
|
return {
|
|
321
|
-
async
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
650
|
+
async list(options = {}) {
|
|
651
|
+
const { agentId, agentVersionId, gender, locale } = options;
|
|
652
|
+
const query = serializeListOptions(
|
|
653
|
+
{
|
|
654
|
+
page: options.page,
|
|
655
|
+
limit: options.limit ?? options.pageSize,
|
|
656
|
+
sort: options.sort,
|
|
657
|
+
fields: options.fields,
|
|
658
|
+
include: options.include,
|
|
659
|
+
search: options.search,
|
|
660
|
+
filter: options.filter,
|
|
661
|
+
or: options.or
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
agentId,
|
|
665
|
+
agentVersionId,
|
|
666
|
+
gender,
|
|
667
|
+
locale
|
|
668
|
+
}
|
|
669
|
+
);
|
|
670
|
+
const res = await doFetch(`${base}/v1/voices`, {
|
|
671
|
+
method: "GET",
|
|
672
|
+
query
|
|
326
673
|
});
|
|
327
674
|
return res.json();
|
|
328
|
-
},
|
|
329
|
-
async disconnect(agentId, phoneId) {
|
|
330
|
-
await doFetch(`${base}/v1/agents/${agentId}/phones/${phoneId}`, {
|
|
331
|
-
method: "DELETE"
|
|
332
|
-
});
|
|
333
675
|
}
|
|
334
676
|
};
|
|
335
677
|
}
|
|
@@ -339,14 +681,25 @@ function createWorkspacesApi(cfg) {
|
|
|
339
681
|
const { base, doFetch } = createHttp(cfg);
|
|
340
682
|
const jsonHeaders = { "content-type": "application/json" };
|
|
341
683
|
return {
|
|
342
|
-
async listPhones(workspaceId, opts) {
|
|
343
|
-
const
|
|
344
|
-
const
|
|
345
|
-
`${base}/v1/workspaces/${workspaceId}/phones${search}`,
|
|
684
|
+
async listPhones(workspaceId, opts = {}) {
|
|
685
|
+
const { channel } = opts;
|
|
686
|
+
const query = serializeListOptions(
|
|
346
687
|
{
|
|
347
|
-
|
|
348
|
-
|
|
688
|
+
page: opts.page,
|
|
689
|
+
limit: opts.limit,
|
|
690
|
+
sort: opts.sort,
|
|
691
|
+
fields: opts.fields,
|
|
692
|
+
include: opts.include,
|
|
693
|
+
search: opts.search,
|
|
694
|
+
filter: opts.filter,
|
|
695
|
+
or: opts.or
|
|
696
|
+
},
|
|
697
|
+
{ channel }
|
|
349
698
|
);
|
|
699
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
700
|
+
method: "GET",
|
|
701
|
+
query
|
|
702
|
+
});
|
|
350
703
|
return res.json();
|
|
351
704
|
},
|
|
352
705
|
async enable(workspaceId, payload) {
|
|
@@ -360,28 +713,6 @@ function createWorkspacesApi(cfg) {
|
|
|
360
713
|
};
|
|
361
714
|
}
|
|
362
715
|
|
|
363
|
-
// src/api/tools.ts
|
|
364
|
-
function createToolsApi(cfg) {
|
|
365
|
-
const { base, doFetch } = createHttp(cfg);
|
|
366
|
-
const jsonHeaders = { "content-type": "application/json" };
|
|
367
|
-
return {
|
|
368
|
-
async list() {
|
|
369
|
-
const res = await doFetch(`${base}/v1/tools`, {
|
|
370
|
-
method: "GET"
|
|
371
|
-
});
|
|
372
|
-
return res.json();
|
|
373
|
-
},
|
|
374
|
-
async execute(toolId, payload) {
|
|
375
|
-
const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
|
|
376
|
-
method: "POST",
|
|
377
|
-
headers: jsonHeaders,
|
|
378
|
-
body: JSON.stringify(payload)
|
|
379
|
-
});
|
|
380
|
-
return res.json();
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
716
|
// src/client.ts
|
|
386
717
|
function createClient(initialCfg) {
|
|
387
718
|
const runtimeCfg = {
|
|
@@ -397,20 +728,28 @@ function createClient(initialCfg) {
|
|
|
397
728
|
const instructionsApi = createAgentInstructionsApi(runtimeCfg);
|
|
398
729
|
const knowledgeApi = createAgentKnowledgeApi(runtimeCfg);
|
|
399
730
|
const phonesApi = createAgentPhonesApi(runtimeCfg);
|
|
731
|
+
const scheduleApi = createAgentScheduleApi(runtimeCfg);
|
|
732
|
+
const versionsApi = createAgentVersionsApi(runtimeCfg);
|
|
733
|
+
const voicesApi = createVoicesApi(runtimeCfg);
|
|
400
734
|
const agentsApi = createAgentsApi(runtimeCfg, {
|
|
401
735
|
instructionsApi,
|
|
402
736
|
knowledgeApi,
|
|
403
|
-
phonesApi
|
|
737
|
+
phonesApi,
|
|
738
|
+
scheduleApi,
|
|
739
|
+
versionsApi
|
|
404
740
|
});
|
|
405
741
|
const apis = {
|
|
406
742
|
agents: {
|
|
407
743
|
...agentsApi,
|
|
408
744
|
knowledge: knowledgeApi,
|
|
409
745
|
instructions: instructionsApi,
|
|
410
|
-
phones: phonesApi
|
|
746
|
+
phones: phonesApi,
|
|
747
|
+
schedule: scheduleApi,
|
|
748
|
+
versions: versionsApi
|
|
411
749
|
},
|
|
412
750
|
workspaces: createWorkspacesApi(runtimeCfg),
|
|
413
|
-
tools: createToolsApi(runtimeCfg)
|
|
751
|
+
tools: createToolsApi(runtimeCfg),
|
|
752
|
+
voices: voicesApi
|
|
414
753
|
};
|
|
415
754
|
return {
|
|
416
755
|
...apis,
|
|
@@ -444,14 +783,19 @@ export {
|
|
|
444
783
|
bindAgentInstructions,
|
|
445
784
|
bindAgentKnowledge,
|
|
446
785
|
bindAgentPhones,
|
|
786
|
+
bindAgentSchedule,
|
|
787
|
+
bindAgentVersions,
|
|
447
788
|
createAgentEntity,
|
|
448
789
|
createAgentInstructionsApi,
|
|
449
790
|
createAgentKnowledgeApi,
|
|
450
791
|
createAgentPhonesApi,
|
|
792
|
+
createAgentScheduleApi,
|
|
793
|
+
createAgentVersionsApi,
|
|
451
794
|
createAgentsApi,
|
|
452
795
|
createClient,
|
|
453
796
|
createHttp,
|
|
454
797
|
createToolsApi,
|
|
798
|
+
createVoicesApi,
|
|
455
799
|
createWorkspacesApi
|
|
456
800
|
};
|
|
457
801
|
//# sourceMappingURL=index.js.map
|