@getsupervisor/agents-studio-sdk 1.1.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/CHANGELOG.md +19 -0
- package/dist/index.cjs +518 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1007 -127
- package/dist/index.d.ts +1007 -127
- package/dist/index.js +509 -56
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -27,6 +27,36 @@ var NetworkError = class extends Error {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
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
|
+
}
|
|
30
60
|
function sleep(ms) {
|
|
31
61
|
return new Promise((r) => setTimeout(r, ms));
|
|
32
62
|
}
|
|
@@ -101,25 +131,31 @@ function createHttp(cfg) {
|
|
|
101
131
|
};
|
|
102
132
|
};
|
|
103
133
|
async function doFetch(url, init = {}) {
|
|
134
|
+
const { query, ...requestInit } = init;
|
|
135
|
+
const targetUrl = appendQuery(url, query);
|
|
104
136
|
const ab = new AbortController();
|
|
105
137
|
const req = async () => {
|
|
106
138
|
try {
|
|
107
|
-
const finalHeaders = buildHeaders(
|
|
139
|
+
const finalHeaders = buildHeaders(requestInit.headers);
|
|
108
140
|
const res = await withTimeout(
|
|
109
|
-
fx(
|
|
141
|
+
fx(targetUrl, {
|
|
142
|
+
...requestInit,
|
|
143
|
+
headers: finalHeaders,
|
|
144
|
+
signal: ab.signal
|
|
145
|
+
}),
|
|
110
146
|
timeout,
|
|
111
147
|
ab,
|
|
112
|
-
|
|
148
|
+
targetUrl
|
|
113
149
|
);
|
|
114
150
|
if (!res.ok) {
|
|
115
151
|
const body = await res.clone().json().catch(() => void 0);
|
|
116
|
-
throw new HttpError(res.status, res.statusText, body,
|
|
152
|
+
throw new HttpError(res.status, res.statusText, body, targetUrl);
|
|
117
153
|
}
|
|
118
154
|
return res;
|
|
119
155
|
} catch (e) {
|
|
120
|
-
if (e.name === "AbortError") throw new TimeoutError(timeout,
|
|
156
|
+
if (e.name === "AbortError") throw new TimeoutError(timeout, targetUrl);
|
|
121
157
|
if (e instanceof HttpError) throw e;
|
|
122
|
-
throw new NetworkError(e,
|
|
158
|
+
throw new NetworkError(e, targetUrl);
|
|
123
159
|
}
|
|
124
160
|
};
|
|
125
161
|
return withRetry(req, retry);
|
|
@@ -135,20 +171,157 @@ function createHttp(cfg) {
|
|
|
135
171
|
};
|
|
136
172
|
}
|
|
137
173
|
|
|
138
|
-
// src/
|
|
139
|
-
function
|
|
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) {
|
|
140
287
|
const { base, doFetch } = createHttp(cfg);
|
|
288
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
141
289
|
return {
|
|
142
|
-
async
|
|
143
|
-
const
|
|
144
|
-
|
|
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
|
|
145
296
|
});
|
|
146
297
|
return res.json();
|
|
147
298
|
},
|
|
148
|
-
async
|
|
149
|
-
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
150
|
-
method: "
|
|
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)
|
|
151
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
|
+
);
|
|
152
325
|
}
|
|
153
326
|
};
|
|
154
327
|
}
|
|
@@ -169,20 +342,24 @@ function createAgentKnowledgeApi(cfg) {
|
|
|
169
342
|
);
|
|
170
343
|
return res.json();
|
|
171
344
|
},
|
|
172
|
-
async listBases(agentId) {
|
|
345
|
+
async listBases(agentId, opts = {}) {
|
|
346
|
+
const query = serializeListOptions(opts);
|
|
173
347
|
const res = await doFetch(
|
|
174
348
|
`${base}/v1/agents/${agentId}/knowledge/bases`,
|
|
175
349
|
{
|
|
176
|
-
method: "GET"
|
|
350
|
+
method: "GET",
|
|
351
|
+
query
|
|
177
352
|
}
|
|
178
353
|
);
|
|
179
354
|
return res.json();
|
|
180
355
|
},
|
|
181
|
-
async listUploads(agentId) {
|
|
356
|
+
async listUploads(agentId, opts = {}) {
|
|
357
|
+
const query = serializeListOptions(opts);
|
|
182
358
|
const res = await doFetch(
|
|
183
359
|
`${base}/v1/agents/${agentId}/knowledge/uploads`,
|
|
184
360
|
{
|
|
185
|
-
method: "GET"
|
|
361
|
+
method: "GET",
|
|
362
|
+
query
|
|
186
363
|
}
|
|
187
364
|
);
|
|
188
365
|
return res.json();
|
|
@@ -190,75 +367,254 @@ function createAgentKnowledgeApi(cfg) {
|
|
|
190
367
|
};
|
|
191
368
|
}
|
|
192
369
|
|
|
193
|
-
// src/api/agent-
|
|
194
|
-
function
|
|
370
|
+
// src/api/agent-phones.ts
|
|
371
|
+
function createAgentPhonesApi(cfg) {
|
|
195
372
|
const { base, doFetch } = createHttp(cfg);
|
|
196
373
|
const jsonHeaders = { "content-type": "application/json" };
|
|
197
374
|
return {
|
|
198
|
-
async
|
|
199
|
-
const
|
|
200
|
-
const res = await doFetch(
|
|
201
|
-
`${base}/v1/agents/${agentId}/instructions${search}`,
|
|
202
|
-
{
|
|
203
|
-
method: "GET"
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
return res.json();
|
|
207
|
-
},
|
|
208
|
-
async create(agentId, payload) {
|
|
209
|
-
const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
|
|
375
|
+
async connect(agentId, payload) {
|
|
376
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/phones`, {
|
|
210
377
|
method: "POST",
|
|
211
378
|
headers: jsonHeaders,
|
|
212
379
|
body: JSON.stringify(payload)
|
|
213
380
|
});
|
|
214
381
|
return res.json();
|
|
382
|
+
},
|
|
383
|
+
async disconnect(agentId, phoneId) {
|
|
384
|
+
await doFetch(`${base}/v1/agents/${agentId}/phones/${phoneId}`, {
|
|
385
|
+
method: "DELETE"
|
|
386
|
+
});
|
|
215
387
|
}
|
|
216
388
|
};
|
|
217
389
|
}
|
|
218
390
|
|
|
219
|
-
// src/api/agent-
|
|
220
|
-
function
|
|
391
|
+
// src/api/agent-schedule.ts
|
|
392
|
+
function createAgentScheduleApi(cfg) {
|
|
221
393
|
const { base, doFetch } = createHttp(cfg);
|
|
222
394
|
const jsonHeaders = { "content-type": "application/json" };
|
|
223
395
|
return {
|
|
224
|
-
async
|
|
225
|
-
const res = await doFetch(`${base}/v1/agents/${agentId}/
|
|
226
|
-
method: "
|
|
227
|
-
headers: jsonHeaders,
|
|
228
|
-
body: JSON.stringify(payload)
|
|
396
|
+
async get(agentId) {
|
|
397
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/schedule`, {
|
|
398
|
+
method: "GET"
|
|
229
399
|
});
|
|
230
400
|
return res.json();
|
|
231
401
|
},
|
|
232
|
-
async
|
|
233
|
-
await doFetch(`${base}/v1/agents/${agentId}/
|
|
234
|
-
method: "
|
|
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)
|
|
235
407
|
});
|
|
408
|
+
return res.json();
|
|
236
409
|
}
|
|
237
410
|
};
|
|
238
411
|
}
|
|
239
412
|
|
|
240
|
-
// src/api/
|
|
241
|
-
function
|
|
413
|
+
// src/api/agent-versions.ts
|
|
414
|
+
function createAgentVersionsApi(cfg) {
|
|
242
415
|
const { base, doFetch } = createHttp(cfg);
|
|
243
416
|
const jsonHeaders = { "content-type": "application/json" };
|
|
244
417
|
return {
|
|
245
|
-
async
|
|
246
|
-
const
|
|
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) {
|
|
247
428
|
const res = await doFetch(
|
|
248
|
-
`${base}/v1/
|
|
429
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}`,
|
|
249
430
|
{
|
|
250
431
|
method: "GET"
|
|
251
432
|
}
|
|
252
433
|
);
|
|
253
434
|
return res.json();
|
|
254
435
|
},
|
|
255
|
-
async
|
|
256
|
-
const res = await doFetch(`${base}/v1/
|
|
436
|
+
async create(agentId, payload) {
|
|
437
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
|
|
257
438
|
method: "POST",
|
|
258
439
|
headers: jsonHeaders,
|
|
259
440
|
body: JSON.stringify(payload)
|
|
260
441
|
});
|
|
261
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
|
+
|
|
537
|
+
// src/api/agents.ts
|
|
538
|
+
function createAgentsApi(cfg, relatedApis) {
|
|
539
|
+
const { base, doFetch } = createHttp(cfg);
|
|
540
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
541
|
+
const listAgents = async (options = {}) => {
|
|
542
|
+
const query = serializeListOptions(options);
|
|
543
|
+
const res = await doFetch(`${base}/v1/agents`, {
|
|
544
|
+
method: "GET",
|
|
545
|
+
query
|
|
546
|
+
});
|
|
547
|
+
return res.json();
|
|
548
|
+
};
|
|
549
|
+
const getAgentDetail = async (agentId) => {
|
|
550
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
551
|
+
method: "GET"
|
|
552
|
+
});
|
|
553
|
+
return res.json();
|
|
554
|
+
};
|
|
555
|
+
const createAgent = async (payload) => {
|
|
556
|
+
const res = await doFetch(`${base}/v1/agents`, {
|
|
557
|
+
method: "POST",
|
|
558
|
+
body: JSON.stringify(payload),
|
|
559
|
+
headers: jsonHeaders
|
|
560
|
+
});
|
|
561
|
+
return res.json();
|
|
562
|
+
};
|
|
563
|
+
const updateAgent = async (agentId, payload) => {
|
|
564
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
565
|
+
method: "PATCH",
|
|
566
|
+
body: JSON.stringify(payload),
|
|
567
|
+
headers: jsonHeaders
|
|
568
|
+
});
|
|
569
|
+
return res.json();
|
|
570
|
+
};
|
|
571
|
+
const deleteAgent = async (agentId) => {
|
|
572
|
+
await doFetch(`${base}/v1/agents/${agentId}`, {
|
|
573
|
+
method: "DELETE"
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
const baseApi = {
|
|
577
|
+
list: listAgents,
|
|
578
|
+
get: getAgentDetail,
|
|
579
|
+
create: createAgent,
|
|
580
|
+
update: updateAgent,
|
|
581
|
+
delete: deleteAgent
|
|
582
|
+
};
|
|
583
|
+
if (!relatedApis) {
|
|
584
|
+
return baseApi;
|
|
585
|
+
}
|
|
586
|
+
const wrapAgent = (detail) => createAgentEntity(detail, {
|
|
587
|
+
instructionsApi: relatedApis.instructionsApi,
|
|
588
|
+
knowledgeApi: relatedApis.knowledgeApi,
|
|
589
|
+
phonesApi: relatedApis.phonesApi,
|
|
590
|
+
scheduleApi: relatedApis.scheduleApi,
|
|
591
|
+
versionsApi: relatedApis.versionsApi,
|
|
592
|
+
reload: async (agentId) => {
|
|
593
|
+
const latest = await getAgentDetail(agentId);
|
|
594
|
+
return wrapAgent(latest);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
return {
|
|
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
|
+
},
|
|
607
|
+
async get(agentId) {
|
|
608
|
+
const detail = await getAgentDetail(agentId);
|
|
609
|
+
return wrapAgent(detail);
|
|
610
|
+
},
|
|
611
|
+
async create(payload) {
|
|
612
|
+
const detail = await createAgent(payload);
|
|
613
|
+
return wrapAgent(detail);
|
|
614
|
+
},
|
|
615
|
+
async update(agentId, payload) {
|
|
616
|
+
const detail = await updateAgent(agentId, payload);
|
|
617
|
+
return wrapAgent(detail);
|
|
262
618
|
}
|
|
263
619
|
};
|
|
264
620
|
}
|
|
@@ -268,9 +624,11 @@ function createToolsApi(cfg) {
|
|
|
268
624
|
const { base, doFetch } = createHttp(cfg);
|
|
269
625
|
const jsonHeaders = { "content-type": "application/json" };
|
|
270
626
|
return {
|
|
271
|
-
async list() {
|
|
627
|
+
async list(options = {}) {
|
|
628
|
+
const query = serializeListOptions(options);
|
|
272
629
|
const res = await doFetch(`${base}/v1/tools`, {
|
|
273
|
-
method: "GET"
|
|
630
|
+
method: "GET",
|
|
631
|
+
query
|
|
274
632
|
});
|
|
275
633
|
return res.json();
|
|
276
634
|
},
|
|
@@ -285,6 +643,76 @@ function createToolsApi(cfg) {
|
|
|
285
643
|
};
|
|
286
644
|
}
|
|
287
645
|
|
|
646
|
+
// src/api/voices.ts
|
|
647
|
+
function createVoicesApi(cfg) {
|
|
648
|
+
const { base, doFetch } = createHttp(cfg);
|
|
649
|
+
return {
|
|
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
|
|
673
|
+
});
|
|
674
|
+
return res.json();
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/api/workspaces.ts
|
|
680
|
+
function createWorkspacesApi(cfg) {
|
|
681
|
+
const { base, doFetch } = createHttp(cfg);
|
|
682
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
683
|
+
return {
|
|
684
|
+
async listPhones(workspaceId, opts = {}) {
|
|
685
|
+
const { channel } = opts;
|
|
686
|
+
const query = serializeListOptions(
|
|
687
|
+
{
|
|
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 }
|
|
698
|
+
);
|
|
699
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
|
|
700
|
+
method: "GET",
|
|
701
|
+
query
|
|
702
|
+
});
|
|
703
|
+
return res.json();
|
|
704
|
+
},
|
|
705
|
+
async enable(workspaceId, payload) {
|
|
706
|
+
const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
|
|
707
|
+
method: "POST",
|
|
708
|
+
headers: jsonHeaders,
|
|
709
|
+
body: JSON.stringify(payload)
|
|
710
|
+
});
|
|
711
|
+
return res.json();
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
|
|
288
716
|
// src/client.ts
|
|
289
717
|
function createClient(initialCfg) {
|
|
290
718
|
const runtimeCfg = {
|
|
@@ -297,15 +725,31 @@ function createClient(initialCfg) {
|
|
|
297
725
|
const setWorkspaceGetter = (getter) => {
|
|
298
726
|
runtimeCfg.getWorkspaceId = getter;
|
|
299
727
|
};
|
|
728
|
+
const instructionsApi = createAgentInstructionsApi(runtimeCfg);
|
|
729
|
+
const knowledgeApi = createAgentKnowledgeApi(runtimeCfg);
|
|
730
|
+
const phonesApi = createAgentPhonesApi(runtimeCfg);
|
|
731
|
+
const scheduleApi = createAgentScheduleApi(runtimeCfg);
|
|
732
|
+
const versionsApi = createAgentVersionsApi(runtimeCfg);
|
|
733
|
+
const voicesApi = createVoicesApi(runtimeCfg);
|
|
734
|
+
const agentsApi = createAgentsApi(runtimeCfg, {
|
|
735
|
+
instructionsApi,
|
|
736
|
+
knowledgeApi,
|
|
737
|
+
phonesApi,
|
|
738
|
+
scheduleApi,
|
|
739
|
+
versionsApi
|
|
740
|
+
});
|
|
300
741
|
const apis = {
|
|
301
742
|
agents: {
|
|
302
|
-
...
|
|
303
|
-
knowledge:
|
|
304
|
-
instructions:
|
|
305
|
-
phones:
|
|
743
|
+
...agentsApi,
|
|
744
|
+
knowledge: knowledgeApi,
|
|
745
|
+
instructions: instructionsApi,
|
|
746
|
+
phones: phonesApi,
|
|
747
|
+
schedule: scheduleApi,
|
|
748
|
+
versions: versionsApi
|
|
306
749
|
},
|
|
307
750
|
workspaces: createWorkspacesApi(runtimeCfg),
|
|
308
|
-
tools: createToolsApi(runtimeCfg)
|
|
751
|
+
tools: createToolsApi(runtimeCfg),
|
|
752
|
+
voices: voicesApi
|
|
309
753
|
};
|
|
310
754
|
return {
|
|
311
755
|
...apis,
|
|
@@ -336,13 +780,22 @@ export {
|
|
|
336
780
|
HttpError,
|
|
337
781
|
NetworkError,
|
|
338
782
|
TimeoutError,
|
|
783
|
+
bindAgentInstructions,
|
|
784
|
+
bindAgentKnowledge,
|
|
785
|
+
bindAgentPhones,
|
|
786
|
+
bindAgentSchedule,
|
|
787
|
+
bindAgentVersions,
|
|
788
|
+
createAgentEntity,
|
|
339
789
|
createAgentInstructionsApi,
|
|
340
790
|
createAgentKnowledgeApi,
|
|
341
791
|
createAgentPhonesApi,
|
|
792
|
+
createAgentScheduleApi,
|
|
793
|
+
createAgentVersionsApi,
|
|
342
794
|
createAgentsApi,
|
|
343
795
|
createClient,
|
|
344
796
|
createHttp,
|
|
345
797
|
createToolsApi,
|
|
798
|
+
createVoicesApi,
|
|
346
799
|
createWorkspacesApi
|
|
347
800
|
};
|
|
348
801
|
//# sourceMappingURL=index.js.map
|