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