@getsupervisor/agents-studio-sdk 1.2.0 → 1.4.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 CHANGED
@@ -25,59 +25,114 @@ __export(index_exports, {
25
25
  bindAgentInstructions: () => bindAgentInstructions,
26
26
  bindAgentKnowledge: () => bindAgentKnowledge,
27
27
  bindAgentPhones: () => bindAgentPhones,
28
+ bindAgentSchedule: () => bindAgentSchedule,
29
+ bindAgentVersions: () => bindAgentVersions,
28
30
  createAgentEntity: () => createAgentEntity,
29
31
  createAgentInstructionsApi: () => createAgentInstructionsApi,
30
32
  createAgentKnowledgeApi: () => createAgentKnowledgeApi,
31
33
  createAgentPhonesApi: () => createAgentPhonesApi,
34
+ createAgentScheduleApi: () => createAgentScheduleApi,
35
+ createAgentVersionsApi: () => createAgentVersionsApi,
32
36
  createAgentsApi: () => createAgentsApi,
33
37
  createClient: () => createClient,
34
38
  createHttp: () => createHttp,
35
39
  createToolsApi: () => createToolsApi,
40
+ createVoicesApi: () => createVoicesApi,
36
41
  createWorkspacesApi: () => createWorkspacesApi
37
42
  });
38
43
  module.exports = __toCommonJS(index_exports);
39
44
 
40
- // src/entities/agent.ts
41
- var bindAgentInstructions = (api, agentId) => ({
42
- list(opts) {
43
- return api.list(agentId, opts);
44
- },
45
- create(payload) {
46
- return api.create(agentId, payload);
45
+ // src/utils/pagination.ts
46
+ var toNumber = (value) => {
47
+ return typeof value === "number" ? value : void 0;
48
+ };
49
+ var toBoolean = (value) => {
50
+ return typeof value === "boolean" ? value : void 0;
51
+ };
52
+ function cloneOptions(options, overrides) {
53
+ return {
54
+ ...options ?? {},
55
+ ...overrides ?? {}
56
+ };
57
+ }
58
+ function normalizeMeta(meta) {
59
+ if (!meta) {
60
+ return void 0;
47
61
  }
48
- });
49
- var bindAgentKnowledge = (api, agentId) => ({
50
- upload(payload) {
51
- return api.upload(agentId, payload);
52
- },
53
- listBases() {
54
- return api.listBases(agentId);
55
- },
56
- listUploads() {
57
- return api.listUploads(agentId);
62
+ const metaRecord = meta;
63
+ return {
64
+ ...metaRecord,
65
+ page: toNumber(metaRecord.page),
66
+ limit: toNumber(metaRecord.limit) ?? toNumber(metaRecord.pageSize),
67
+ total: toNumber(metaRecord.total) ?? toNumber(metaRecord.totalItems),
68
+ hasNext: toBoolean(metaRecord.hasNext),
69
+ hasPrevious: toBoolean(metaRecord.hasPrevious),
70
+ totalPages: toNumber(metaRecord.totalPages)
71
+ };
72
+ }
73
+ function resolveHasNext(meta, limit) {
74
+ if (typeof meta?.hasNext === "boolean") {
75
+ return meta.hasNext;
58
76
  }
59
- });
60
- var bindAgentPhones = (api, agentId) => ({
61
- connect(payload) {
62
- return api.connect(agentId, payload);
63
- },
64
- disconnect(phoneId) {
65
- return api.disconnect(agentId, phoneId);
77
+ if (typeof meta?.total === "number" && typeof meta?.page === "number" && typeof limit === "number") {
78
+ return meta.page * limit < meta.total;
66
79
  }
67
- });
68
- var createAgentEntity = (dto, options) => {
69
- const { instructionsApi, knowledgeApi, phonesApi, reload } = options;
70
- const entity = {
71
- ...dto,
72
- instructions: bindAgentInstructions(instructionsApi, dto.agentId),
73
- knowledge: bindAgentKnowledge(knowledgeApi, dto.agentId),
74
- phones: bindAgentPhones(phonesApi, dto.agentId),
75
- async refresh() {
76
- return reload(dto.agentId);
77
- }
80
+ if (typeof meta?.totalPages === "number" && typeof meta?.page === "number") {
81
+ return meta.page < meta.totalPages;
82
+ }
83
+ return false;
84
+ }
85
+ function resolveHasPrevious(meta) {
86
+ if (typeof meta?.hasPrevious === "boolean") {
87
+ return meta.hasPrevious;
88
+ }
89
+ if (typeof meta?.page === "number") {
90
+ return meta.page > 1;
91
+ }
92
+ return false;
93
+ }
94
+ function attachPaginator(response, fetchPage, options) {
95
+ const baseOptions = options ?? {};
96
+ const meta = normalizeMeta(response.meta);
97
+ const currentPage = typeof meta?.page === "number" ? meta.page : typeof baseOptions.page === "number" ? baseOptions.page : 1;
98
+ const currentLimit = typeof meta?.limit === "number" ? meta.limit : typeof baseOptions.limit === "number" ? baseOptions.limit : void 0;
99
+ const getNextResponse = async (page, overrides) => {
100
+ const nextOptions = cloneOptions(baseOptions, {
101
+ ...overrides,
102
+ page
103
+ });
104
+ const nextResponse = await fetchPage(nextOptions);
105
+ return attachPaginator(nextResponse, fetchPage, nextOptions);
78
106
  };
79
- return Object.freeze(entity);
80
- };
107
+ return Object.assign(response, {
108
+ async next() {
109
+ if (!resolveHasNext(meta, currentLimit)) {
110
+ return null;
111
+ }
112
+ return getNextResponse(currentPage + 1);
113
+ },
114
+ async prev() {
115
+ if (!resolveHasPrevious(meta)) {
116
+ return null;
117
+ }
118
+ return getNextResponse(Math.max(1, currentPage - 1));
119
+ },
120
+ async page(pageNumber) {
121
+ if (typeof pageNumber !== "number" || Number.isNaN(pageNumber)) {
122
+ throw new TypeError("page(pageNumber) requires a numeric value.");
123
+ }
124
+ if (pageNumber < 1) {
125
+ throw new RangeError(
126
+ "Page numbers must be greater than or equal to 1."
127
+ );
128
+ }
129
+ return getNextResponse(pageNumber);
130
+ },
131
+ async reload() {
132
+ return getNextResponse(currentPage);
133
+ }
134
+ });
135
+ }
81
136
 
82
137
  // src/errors.ts
83
138
  var HttpError = class extends Error {
@@ -108,6 +163,36 @@ var NetworkError = class extends Error {
108
163
  };
109
164
 
110
165
  // src/http.ts
166
+ function toQueryString(query) {
167
+ if (!query) return void 0;
168
+ if (typeof query === "string") {
169
+ const normalized = query.trim().replace(/^\?/, "");
170
+ return normalized.length > 0 ? normalized : void 0;
171
+ }
172
+ if (query instanceof URLSearchParams) {
173
+ const result2 = query.toString();
174
+ return result2.length > 0 ? result2 : void 0;
175
+ }
176
+ const params = new URLSearchParams();
177
+ Object.entries(query).forEach(([key, value]) => {
178
+ if (value === null || value === void 0) return;
179
+ const values = Array.isArray(value) ? value : [value];
180
+ values.forEach((item) => {
181
+ params.append(key, String(item));
182
+ });
183
+ });
184
+ const result = params.toString();
185
+ return result.length > 0 ? result : void 0;
186
+ }
187
+ function appendQuery(url, query) {
188
+ const qs = toQueryString(query);
189
+ if (!qs) return url;
190
+ const [base, hash] = url.split("#");
191
+ const hasQuery = base.includes("?");
192
+ const needsSeparator = hasQuery ? base.endsWith("?") || base.endsWith("&") ? "" : "&" : "?";
193
+ const built = `${base}${needsSeparator}${qs}`;
194
+ return hash ? `${built}#${hash}` : built;
195
+ }
111
196
  function sleep(ms) {
112
197
  return new Promise((r) => setTimeout(r, ms));
113
198
  }
@@ -182,25 +267,31 @@ function createHttp(cfg) {
182
267
  };
183
268
  };
184
269
  async function doFetch(url, init = {}) {
270
+ const { query, ...requestInit } = init;
271
+ const targetUrl = appendQuery(url, query);
185
272
  const ab = new AbortController();
186
273
  const req = async () => {
187
274
  try {
188
- const finalHeaders = buildHeaders(init.headers);
275
+ const finalHeaders = buildHeaders(requestInit.headers);
189
276
  const res = await withTimeout(
190
- fx(url, { ...init, headers: finalHeaders, signal: ab.signal }),
277
+ fx(targetUrl, {
278
+ ...requestInit,
279
+ headers: finalHeaders,
280
+ signal: ab.signal
281
+ }),
191
282
  timeout,
192
283
  ab,
193
- url
284
+ targetUrl
194
285
  );
195
286
  if (!res.ok) {
196
287
  const body = await res.clone().json().catch(() => void 0);
197
- throw new HttpError(res.status, res.statusText, body, url);
288
+ throw new HttpError(res.status, res.statusText, body, targetUrl);
198
289
  }
199
290
  return res;
200
291
  } catch (e) {
201
- if (e.name === "AbortError") throw new TimeoutError(timeout, url);
292
+ if (e.name === "AbortError") throw new TimeoutError(timeout, targetUrl);
202
293
  if (e instanceof HttpError) throw e;
203
- throw new NetworkError(e, url);
294
+ throw new NetworkError(e, targetUrl);
204
295
  }
205
296
  };
206
297
  return withRetry(req, retry);
@@ -216,16 +307,421 @@ function createHttp(cfg) {
216
307
  };
217
308
  }
218
309
 
310
+ // src/utils/query.ts
311
+ function serializeListOptions(options = {}, extra = {}) {
312
+ const params = new URLSearchParams();
313
+ appendParam(params, "page", options.page);
314
+ appendParam(params, "limit", options.limit);
315
+ appendParam(params, "sort", options.sort);
316
+ appendParam(params, "fields", options.fields);
317
+ appendParam(params, "include", options.include);
318
+ appendParam(params, "q", options.search);
319
+ appendParam(params, "filter", mapQueryValue(options.filter));
320
+ appendParam(params, "or", mapQueryValue(options.or));
321
+ Object.entries(extra).forEach(([key, value]) => {
322
+ appendParam(params, key, value);
323
+ });
324
+ return params.toString();
325
+ }
326
+ function mapQueryValue(value) {
327
+ if (value === void 0 || value === null) {
328
+ return void 0;
329
+ }
330
+ if (isQueryBuilderSerializable(value)) {
331
+ return getQueryBuilderString(value);
332
+ }
333
+ return value;
334
+ }
335
+ function appendParam(params, key, value) {
336
+ if (value === void 0 || value === null) {
337
+ return;
338
+ }
339
+ if (value instanceof Date) {
340
+ params.set(key, value.toISOString());
341
+ return;
342
+ }
343
+ if (isQueryBuilderSerializable(value)) {
344
+ params.set(key, getQueryBuilderString(value));
345
+ return;
346
+ }
347
+ if (typeof value === "string") {
348
+ params.set(key, value);
349
+ return;
350
+ }
351
+ if (typeof value === "number" || typeof value === "boolean") {
352
+ params.set(key, String(value));
353
+ return;
354
+ }
355
+ if (typeof value === "bigint") {
356
+ params.set(key, value.toString());
357
+ return;
358
+ }
359
+ if (Array.isArray(value)) {
360
+ if (value.length === 0) {
361
+ return;
362
+ }
363
+ if (value.every(isPrimitive)) {
364
+ params.set(key, value.map((item) => String(item)).join(","));
365
+ return;
366
+ }
367
+ value.forEach((item, idx) => {
368
+ appendParam(params, `${key}[${idx}]`, item);
369
+ });
370
+ return;
371
+ }
372
+ if (isPlainObject(value)) {
373
+ Object.entries(value).forEach(([childKey, childValue]) => {
374
+ appendParam(params, `${key}[${childKey}]`, childValue);
375
+ });
376
+ return;
377
+ }
378
+ params.set(key, String(value));
379
+ }
380
+ function isPrimitive(value) {
381
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint";
382
+ }
383
+ function isPlainObject(value) {
384
+ if (value === null || typeof value !== "object") {
385
+ return false;
386
+ }
387
+ const proto = Object.getPrototypeOf(value);
388
+ return proto === Object.prototype || proto === null;
389
+ }
390
+ function isQueryBuilderSerializable(value) {
391
+ return !!value && typeof value === "object" && typeof value.build === "function";
392
+ }
393
+ function getQueryBuilderString(value) {
394
+ const build = value.build;
395
+ if (typeof build !== "function") {
396
+ throw new TypeError(
397
+ "Query builder values must expose a build() method returning a string."
398
+ );
399
+ }
400
+ if (build.length > 0) {
401
+ const stringValue = value.toString?.();
402
+ if (stringValue && stringValue !== "[object Object]") {
403
+ return stringValue;
404
+ }
405
+ throw new TypeError(
406
+ "Query builder instances passed to the SDK must expose a zero-argument build() method. Did you pass QueryBuilder instead of Query?"
407
+ );
408
+ }
409
+ const result = build.call(value);
410
+ if (typeof result === "string") {
411
+ return result;
412
+ }
413
+ if (result === void 0 || result === null) {
414
+ throw new TypeError(
415
+ "Query builder build() must return a string representation of the query."
416
+ );
417
+ }
418
+ return String(result);
419
+ }
420
+
421
+ // src/api/agent-instructions.ts
422
+ function createAgentInstructionsApi(cfg) {
423
+ const { base, doFetch } = createHttp(cfg);
424
+ const jsonHeaders = { "content-type": "application/json" };
425
+ const fetchInstructionPage = async (agentId, opts = {}) => {
426
+ const { versionId, ...queryOptions } = opts ?? {};
427
+ const query = serializeListOptions(queryOptions, { versionId });
428
+ const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
429
+ method: "GET",
430
+ query
431
+ });
432
+ return res.json();
433
+ };
434
+ return {
435
+ async list(agentId, opts = {}) {
436
+ const normalizedOptions = {
437
+ ...opts ?? {}
438
+ };
439
+ const fetchPage = (options) => fetchInstructionPage(agentId, options);
440
+ const response = await fetchPage(normalizedOptions);
441
+ return attachPaginator(response, fetchPage, normalizedOptions);
442
+ },
443
+ async create(agentId, payload) {
444
+ const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
445
+ method: "POST",
446
+ headers: jsonHeaders,
447
+ body: JSON.stringify(payload)
448
+ });
449
+ return res.json();
450
+ },
451
+ async update(agentId, instructionId, payload) {
452
+ const res = await doFetch(
453
+ `${base}/v1/agents/${agentId}/instructions/${instructionId}`,
454
+ {
455
+ method: "PATCH",
456
+ headers: jsonHeaders,
457
+ body: JSON.stringify(payload)
458
+ }
459
+ );
460
+ return res.json();
461
+ },
462
+ async delete(agentId, instructionId) {
463
+ await doFetch(
464
+ `${base}/v1/agents/${agentId}/instructions/${instructionId}`,
465
+ {
466
+ method: "DELETE"
467
+ }
468
+ );
469
+ }
470
+ };
471
+ }
472
+
473
+ // src/api/agent-knowledge.ts
474
+ function createAgentKnowledgeApi(cfg) {
475
+ const { base, doFetch } = createHttp(cfg);
476
+ const jsonHeaders = { "content-type": "application/json" };
477
+ const fetchBasesPage = async (agentId, opts = {}) => {
478
+ const query = serializeListOptions(opts);
479
+ const res = await doFetch(`${base}/v1/agents/${agentId}/knowledge/bases`, {
480
+ method: "GET",
481
+ query
482
+ });
483
+ return res.json();
484
+ };
485
+ const fetchUploadsPage = async (agentId, opts = {}) => {
486
+ const query = serializeListOptions(opts);
487
+ const res = await doFetch(
488
+ `${base}/v1/agents/${agentId}/knowledge/uploads`,
489
+ {
490
+ method: "GET",
491
+ query
492
+ }
493
+ );
494
+ return res.json();
495
+ };
496
+ return {
497
+ async upload(agentId, payload) {
498
+ const res = await doFetch(
499
+ `${base}/v1/agents/${agentId}/knowledge/upload`,
500
+ {
501
+ method: "POST",
502
+ headers: jsonHeaders,
503
+ body: JSON.stringify(payload)
504
+ }
505
+ );
506
+ return res.json();
507
+ },
508
+ async listBases(agentId, opts = {}) {
509
+ const normalizedOptions = {
510
+ ...opts ?? {}
511
+ };
512
+ const fetchPage = (options) => fetchBasesPage(agentId, options);
513
+ const response = await fetchPage(normalizedOptions);
514
+ return attachPaginator(response, fetchPage, normalizedOptions);
515
+ },
516
+ async listUploads(agentId, opts = {}) {
517
+ const normalizedOptions = {
518
+ ...opts ?? {}
519
+ };
520
+ const fetchPage = (options) => fetchUploadsPage(agentId, options);
521
+ const response = await fetchPage(normalizedOptions);
522
+ return attachPaginator(response, fetchPage, normalizedOptions);
523
+ }
524
+ };
525
+ }
526
+
527
+ // src/api/agent-phones.ts
528
+ function createAgentPhonesApi(cfg) {
529
+ const { base, doFetch } = createHttp(cfg);
530
+ const jsonHeaders = { "content-type": "application/json" };
531
+ return {
532
+ async connect(agentId, payload) {
533
+ const res = await doFetch(`${base}/v1/agents/${agentId}/phones`, {
534
+ method: "POST",
535
+ headers: jsonHeaders,
536
+ body: JSON.stringify(payload)
537
+ });
538
+ return res.json();
539
+ },
540
+ async disconnect(agentId, phoneId) {
541
+ await doFetch(`${base}/v1/agents/${agentId}/phones/${phoneId}`, {
542
+ method: "DELETE"
543
+ });
544
+ }
545
+ };
546
+ }
547
+
548
+ // src/api/agent-schedule.ts
549
+ function createAgentScheduleApi(cfg) {
550
+ const { base, doFetch } = createHttp(cfg);
551
+ const jsonHeaders = { "content-type": "application/json" };
552
+ return {
553
+ async get(agentId) {
554
+ const res = await doFetch(`${base}/v1/agents/${agentId}/schedule`, {
555
+ method: "GET"
556
+ });
557
+ return res.json();
558
+ },
559
+ async update(agentId, payload) {
560
+ const res = await doFetch(`${base}/v1/agents/${agentId}/schedule`, {
561
+ method: "PUT",
562
+ headers: jsonHeaders,
563
+ body: JSON.stringify(payload)
564
+ });
565
+ return res.json();
566
+ }
567
+ };
568
+ }
569
+
570
+ // src/api/agent-versions.ts
571
+ function createAgentVersionsApi(cfg) {
572
+ const { base, doFetch } = createHttp(cfg);
573
+ const jsonHeaders = { "content-type": "application/json" };
574
+ const fetchVersionsPage = async (agentId, opts = {}) => {
575
+ const { status, ...queryOptions } = opts ?? {};
576
+ const query = serializeListOptions(queryOptions, { status });
577
+ const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
578
+ method: "GET",
579
+ query
580
+ });
581
+ return res.json();
582
+ };
583
+ return {
584
+ async list(agentId, opts = {}) {
585
+ const normalizedOptions = { ...opts ?? {} };
586
+ const fetchPage = (options) => fetchVersionsPage(agentId, options);
587
+ const response = await fetchPage(normalizedOptions);
588
+ return attachPaginator(response, fetchPage, normalizedOptions);
589
+ },
590
+ async get(agentId, versionId) {
591
+ const res = await doFetch(
592
+ `${base}/v1/agents/${agentId}/versions/${versionId}`,
593
+ {
594
+ method: "GET"
595
+ }
596
+ );
597
+ return res.json();
598
+ },
599
+ async create(agentId, payload) {
600
+ const res = await doFetch(`${base}/v1/agents/${agentId}/versions`, {
601
+ method: "POST",
602
+ headers: jsonHeaders,
603
+ body: JSON.stringify(payload)
604
+ });
605
+ return res.json();
606
+ },
607
+ async update(agentId, versionId, payload) {
608
+ const res = await doFetch(
609
+ `${base}/v1/agents/${agentId}/versions/${versionId}`,
610
+ {
611
+ method: "PATCH",
612
+ headers: jsonHeaders,
613
+ body: JSON.stringify(payload)
614
+ }
615
+ );
616
+ return res.json();
617
+ }
618
+ };
619
+ }
620
+
621
+ // src/entities/agent.ts
622
+ var bindAgentInstructions = (api, agentId) => ({
623
+ list(opts) {
624
+ return api.list(agentId, opts);
625
+ },
626
+ create(payload) {
627
+ return api.create(agentId, payload);
628
+ },
629
+ update(instructionId, payload) {
630
+ return api.update(agentId, instructionId, payload);
631
+ },
632
+ delete(instructionId) {
633
+ return api.delete(agentId, instructionId);
634
+ }
635
+ });
636
+ var bindAgentKnowledge = (api, agentId) => ({
637
+ upload(payload) {
638
+ return api.upload(agentId, payload);
639
+ },
640
+ listBases(opts) {
641
+ return api.listBases(agentId, opts);
642
+ },
643
+ listUploads(opts) {
644
+ return api.listUploads(agentId, opts);
645
+ }
646
+ });
647
+ var bindAgentPhones = (api, agentId) => ({
648
+ connect(payload) {
649
+ return api.connect(agentId, payload);
650
+ },
651
+ disconnect(phoneId) {
652
+ return api.disconnect(agentId, phoneId);
653
+ }
654
+ });
655
+ var bindAgentSchedule = (api, agentId) => ({
656
+ get() {
657
+ return api.get(agentId);
658
+ },
659
+ update(payload) {
660
+ return api.update(agentId, payload);
661
+ }
662
+ });
663
+ var bindAgentVersions = (api, agentId) => ({
664
+ list(opts) {
665
+ return api.list(agentId, opts);
666
+ },
667
+ get(versionId) {
668
+ return api.get(agentId, versionId);
669
+ },
670
+ create(payload) {
671
+ return api.create(agentId, payload);
672
+ },
673
+ update(versionId, payload) {
674
+ return api.update(agentId, versionId, payload);
675
+ }
676
+ });
677
+ var createAgentEntity = (dto, options) => {
678
+ const {
679
+ instructionsApi,
680
+ knowledgeApi,
681
+ phonesApi,
682
+ scheduleApi,
683
+ versionsApi,
684
+ reload,
685
+ updateAgent,
686
+ deleteAgent
687
+ } = options;
688
+ const entity = {
689
+ ...dto,
690
+ instructions: bindAgentInstructions(instructionsApi, dto.agentId),
691
+ knowledge: bindAgentKnowledge(knowledgeApi, dto.agentId),
692
+ phones: bindAgentPhones(phonesApi, dto.agentId),
693
+ schedule: bindAgentSchedule(scheduleApi, dto.agentId),
694
+ versions: bindAgentVersions(versionsApi, dto.agentId),
695
+ async save(patch) {
696
+ return updateAgent(dto.agentId, patch);
697
+ },
698
+ async delete() {
699
+ await deleteAgent(dto.agentId);
700
+ },
701
+ async refresh() {
702
+ return reload(dto.agentId);
703
+ }
704
+ };
705
+ return Object.freeze(entity);
706
+ };
707
+
219
708
  // src/api/agents.ts
220
709
  function createAgentsApi(cfg, relatedApis) {
221
710
  const { base, doFetch } = createHttp(cfg);
222
711
  const jsonHeaders = { "content-type": "application/json" };
223
- const listAgents = async () => {
712
+ const fetchAgentsPage = async (options = {}) => {
713
+ const query = serializeListOptions(options);
224
714
  const res = await doFetch(`${base}/v1/agents`, {
225
- method: "GET"
715
+ method: "GET",
716
+ query
226
717
  });
227
718
  return res.json();
228
719
  };
720
+ const listAgents = async (options = {}) => {
721
+ const normalizedOptions = { ...options ?? {} };
722
+ const response = await fetchAgentsPage(normalizedOptions);
723
+ return attachPaginator(response, fetchAgentsPage, normalizedOptions);
724
+ };
229
725
  const getAgentDetail = async (agentId) => {
230
726
  const res = await doFetch(`${base}/v1/agents/${agentId}`, {
231
727
  method: "GET"
@@ -248,7 +744,11 @@ function createAgentsApi(cfg, relatedApis) {
248
744
  });
249
745
  return res.json();
250
746
  };
251
- const deleteAgent = async (agentId) => {
747
+ const resolveAgentId = (agent) => {
748
+ return typeof agent === "string" ? agent : agent.agentId;
749
+ };
750
+ const deleteAgent = async (agent) => {
751
+ const agentId = resolveAgentId(agent);
252
752
  await doFetch(`${base}/v1/agents/${agentId}`, {
253
753
  method: "DELETE"
254
754
  });
@@ -267,13 +767,35 @@ function createAgentsApi(cfg, relatedApis) {
267
767
  instructionsApi: relatedApis.instructionsApi,
268
768
  knowledgeApi: relatedApis.knowledgeApi,
269
769
  phonesApi: relatedApis.phonesApi,
770
+ scheduleApi: relatedApis.scheduleApi,
771
+ versionsApi: relatedApis.versionsApi,
270
772
  reload: async (agentId) => {
271
773
  const latest = await getAgentDetail(agentId);
272
774
  return wrapAgent(latest);
775
+ },
776
+ updateAgent: async (agentId, payload) => {
777
+ const updated = await updateAgent(agentId, payload);
778
+ return wrapAgent(updated);
779
+ },
780
+ deleteAgent: async (agentId) => {
781
+ await deleteAgent(agentId);
273
782
  }
274
783
  });
275
784
  return {
276
785
  ...baseApi,
786
+ async list(options = {}) {
787
+ const normalizedOptions = { ...options ?? {} };
788
+ const applyWrap = async (opts) => {
789
+ const result = await fetchAgentsPage(opts);
790
+ const items = Array.isArray(result.data) ? result.data : [];
791
+ return {
792
+ ...result,
793
+ data: items.map((summary) => wrapAgent(summary))
794
+ };
795
+ };
796
+ const initial = await applyWrap(normalizedOptions);
797
+ return attachPaginator(initial, applyWrap, normalizedOptions);
798
+ },
277
799
  async get(agentId) {
278
800
  const detail = await getAgentDetail(agentId);
279
801
  return wrapAgent(detail);
@@ -289,60 +811,26 @@ function createAgentsApi(cfg, relatedApis) {
289
811
  };
290
812
  }
291
813
 
292
- // src/api/agent-knowledge.ts
293
- function createAgentKnowledgeApi(cfg) {
814
+ // src/api/tools.ts
815
+ function createToolsApi(cfg) {
294
816
  const { base, doFetch } = createHttp(cfg);
295
817
  const jsonHeaders = { "content-type": "application/json" };
296
- return {
297
- async upload(agentId, payload) {
298
- const res = await doFetch(
299
- `${base}/v1/agents/${agentId}/knowledge/upload`,
300
- {
301
- method: "POST",
302
- headers: jsonHeaders,
303
- body: JSON.stringify(payload)
304
- }
305
- );
306
- return res.json();
307
- },
308
- async listBases(agentId) {
309
- const res = await doFetch(
310
- `${base}/v1/agents/${agentId}/knowledge/bases`,
311
- {
312
- method: "GET"
313
- }
314
- );
315
- return res.json();
316
- },
317
- async listUploads(agentId) {
318
- const res = await doFetch(
319
- `${base}/v1/agents/${agentId}/knowledge/uploads`,
320
- {
321
- method: "GET"
322
- }
323
- );
324
- return res.json();
325
- }
818
+ const fetchToolsPage = async (options = {}) => {
819
+ const query = serializeListOptions(options);
820
+ const res = await doFetch(`${base}/v1/tools`, {
821
+ method: "GET",
822
+ query
823
+ });
824
+ return res.json();
326
825
  };
327
- }
328
-
329
- // src/api/agent-instructions.ts
330
- function createAgentInstructionsApi(cfg) {
331
- const { base, doFetch } = createHttp(cfg);
332
- const jsonHeaders = { "content-type": "application/json" };
333
826
  return {
334
- async list(agentId, opts) {
335
- const search = opts?.versionId ? `?versionId=${encodeURIComponent(opts.versionId)}` : "";
336
- const res = await doFetch(
337
- `${base}/v1/agents/${agentId}/instructions${search}`,
338
- {
339
- method: "GET"
340
- }
341
- );
342
- return res.json();
827
+ async list(options = {}) {
828
+ const normalizedOptions = { ...options ?? {} };
829
+ const response = await fetchToolsPage(normalizedOptions);
830
+ return attachPaginator(response, fetchToolsPage, normalizedOptions);
343
831
  },
344
- async create(agentId, payload) {
345
- const res = await doFetch(`${base}/v1/agents/${agentId}/instructions`, {
832
+ async execute(toolId, payload) {
833
+ const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
346
834
  method: "POST",
347
835
  headers: jsonHeaders,
348
836
  body: JSON.stringify(payload)
@@ -352,23 +840,40 @@ function createAgentInstructionsApi(cfg) {
352
840
  };
353
841
  }
354
842
 
355
- // src/api/agent-phones.ts
356
- function createAgentPhonesApi(cfg) {
843
+ // src/api/voices.ts
844
+ function createVoicesApi(cfg) {
357
845
  const { base, doFetch } = createHttp(cfg);
358
- const jsonHeaders = { "content-type": "application/json" };
846
+ const fetchVoicesPage = async (options = {}) => {
847
+ const { agentId, agentVersionId, gender, locale } = options;
848
+ const query = serializeListOptions(
849
+ {
850
+ page: options.page,
851
+ limit: options.limit ?? options.pageSize,
852
+ sort: options.sort,
853
+ fields: options.fields,
854
+ include: options.include,
855
+ search: options.search,
856
+ filter: options.filter,
857
+ or: options.or
858
+ },
859
+ {
860
+ agentId,
861
+ agentVersionId,
862
+ gender,
863
+ locale
864
+ }
865
+ );
866
+ const res = await doFetch(`${base}/v1/voices`, {
867
+ method: "GET",
868
+ query
869
+ });
870
+ return res.json();
871
+ };
359
872
  return {
360
- async connect(agentId, payload) {
361
- const res = await doFetch(`${base}/v1/agents/${agentId}/phones`, {
362
- method: "POST",
363
- headers: jsonHeaders,
364
- body: JSON.stringify(payload)
365
- });
366
- return res.json();
367
- },
368
- async disconnect(agentId, phoneId) {
369
- await doFetch(`${base}/v1/agents/${agentId}/phones/${phoneId}`, {
370
- method: "DELETE"
371
- });
873
+ async list(options = {}) {
874
+ const normalizedOptions = { ...options ?? {} };
875
+ const response = await fetchVoicesPage(normalizedOptions);
876
+ return attachPaginator(response, fetchVoicesPage, normalizedOptions);
372
877
  }
373
878
  };
374
879
  }
@@ -377,16 +882,35 @@ function createAgentPhonesApi(cfg) {
377
882
  function createWorkspacesApi(cfg) {
378
883
  const { base, doFetch } = createHttp(cfg);
379
884
  const jsonHeaders = { "content-type": "application/json" };
885
+ const fetchPhonesPage = async (workspaceId, opts = {}) => {
886
+ const { channel } = opts ?? {};
887
+ const query = serializeListOptions(
888
+ {
889
+ page: opts.page,
890
+ limit: opts.limit,
891
+ sort: opts.sort,
892
+ fields: opts.fields,
893
+ include: opts.include,
894
+ search: opts.search,
895
+ filter: opts.filter,
896
+ or: opts.or
897
+ },
898
+ { channel }
899
+ );
900
+ const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/phones`, {
901
+ method: "GET",
902
+ query
903
+ });
904
+ return res.json();
905
+ };
380
906
  return {
381
- async listPhones(workspaceId, opts) {
382
- const search = opts?.channel ? `?channel=${opts.channel}` : "";
383
- const res = await doFetch(
384
- `${base}/v1/workspaces/${workspaceId}/phones${search}`,
385
- {
386
- method: "GET"
387
- }
388
- );
389
- return res.json();
907
+ async listPhones(workspaceId, opts = {}) {
908
+ const normalizedOptions = {
909
+ ...opts ?? {}
910
+ };
911
+ const response = await fetchPhonesPage(workspaceId, normalizedOptions);
912
+ const fetchPage = (options) => fetchPhonesPage(workspaceId, options);
913
+ return attachPaginator(response, fetchPage, normalizedOptions);
390
914
  },
391
915
  async enable(workspaceId, payload) {
392
916
  const res = await doFetch(`${base}/v1/workspaces/${workspaceId}/enable`, {
@@ -399,28 +923,6 @@ function createWorkspacesApi(cfg) {
399
923
  };
400
924
  }
401
925
 
402
- // src/api/tools.ts
403
- function createToolsApi(cfg) {
404
- const { base, doFetch } = createHttp(cfg);
405
- const jsonHeaders = { "content-type": "application/json" };
406
- return {
407
- async list() {
408
- const res = await doFetch(`${base}/v1/tools`, {
409
- method: "GET"
410
- });
411
- return res.json();
412
- },
413
- async execute(toolId, payload) {
414
- const res = await doFetch(`${base}/v1/tools/${toolId}/execute`, {
415
- method: "POST",
416
- headers: jsonHeaders,
417
- body: JSON.stringify(payload)
418
- });
419
- return res.json();
420
- }
421
- };
422
- }
423
-
424
926
  // src/client.ts
425
927
  function createClient(initialCfg) {
426
928
  const runtimeCfg = {
@@ -436,20 +938,28 @@ function createClient(initialCfg) {
436
938
  const instructionsApi = createAgentInstructionsApi(runtimeCfg);
437
939
  const knowledgeApi = createAgentKnowledgeApi(runtimeCfg);
438
940
  const phonesApi = createAgentPhonesApi(runtimeCfg);
941
+ const scheduleApi = createAgentScheduleApi(runtimeCfg);
942
+ const versionsApi = createAgentVersionsApi(runtimeCfg);
943
+ const voicesApi = createVoicesApi(runtimeCfg);
439
944
  const agentsApi = createAgentsApi(runtimeCfg, {
440
945
  instructionsApi,
441
946
  knowledgeApi,
442
- phonesApi
947
+ phonesApi,
948
+ scheduleApi,
949
+ versionsApi
443
950
  });
444
951
  const apis = {
445
952
  agents: {
446
953
  ...agentsApi,
447
954
  knowledge: knowledgeApi,
448
955
  instructions: instructionsApi,
449
- phones: phonesApi
956
+ phones: phonesApi,
957
+ schedule: scheduleApi,
958
+ versions: versionsApi
450
959
  },
451
960
  workspaces: createWorkspacesApi(runtimeCfg),
452
- tools: createToolsApi(runtimeCfg)
961
+ tools: createToolsApi(runtimeCfg),
962
+ voices: voicesApi
453
963
  };
454
964
  return {
455
965
  ...apis,
@@ -484,14 +994,19 @@ function createClient(initialCfg) {
484
994
  bindAgentInstructions,
485
995
  bindAgentKnowledge,
486
996
  bindAgentPhones,
997
+ bindAgentSchedule,
998
+ bindAgentVersions,
487
999
  createAgentEntity,
488
1000
  createAgentInstructionsApi,
489
1001
  createAgentKnowledgeApi,
490
1002
  createAgentPhonesApi,
1003
+ createAgentScheduleApi,
1004
+ createAgentVersionsApi,
491
1005
  createAgentsApi,
492
1006
  createClient,
493
1007
  createHttp,
494
1008
  createToolsApi,
1009
+ createVoicesApi,
495
1010
  createWorkspacesApi
496
1011
  });
497
1012
  //# sourceMappingURL=index.cjs.map