@seclai/sdk 1.6.0 → 1.7.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
@@ -58,10 +58,16 @@ var SeclaiApiVersion = {
58
58
  V2026_09_28: "2026-09-28",
59
59
  V2026_09_30: "2026-09-30",
60
60
  V2026_10_03: "2026-10-03",
61
+ V2026_10_05: "2026-10-05",
62
+ V2026_10_13: "2026-10-13",
63
+ V2026_10_16: "2026-10-16",
64
+ V2026_10_18: "2026-10-18",
65
+ V2026_10_19: "2026-10-19",
66
+ V2026_10_21: "2026-10-21",
61
67
  /** Baseline applied to an unpinned, header-less caller. */
62
68
  Default: "2026-07-01",
63
69
  /** Newest version known to this SDK release. May lag the server. */
64
- Latest: "2026-10-03"
70
+ Latest: "2026-10-21"
65
71
  };
66
72
  var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
67
73
 
@@ -423,11 +429,46 @@ function buildURL(baseUrl, path, query) {
423
429
  }
424
430
  function listItems(res) {
425
431
  if (Array.isArray(res)) return res;
426
- return res?.data ?? [];
432
+ if (res !== null && typeof res === "object" && "data" in res) {
433
+ const data = res.data;
434
+ if (Array.isArray(data)) return data;
435
+ if (data === null) return [];
436
+ }
437
+ throw notAList();
438
+ }
439
+ function notAList() {
440
+ return new SeclaiError(
441
+ "Expected a list response: an array, or an object carrying the items under `data` or the endpoint's own key."
442
+ );
443
+ }
444
+ function keyedList(res, key, flat = []) {
445
+ if (Array.isArray(res)) return { [key]: res };
446
+ if (res === null || typeof res !== "object") throw notAList();
447
+ const body = { ...res };
448
+ if (Array.isArray(body.data)) body[key] = body.data;
449
+ else if ("data" in body && body.data === null) body[key] = [];
450
+ else if (!Array.isArray(body[key])) throw notAList();
451
+ const pagination = body.pagination;
452
+ for (const field of flat) {
453
+ if (body[field] === void 0 && pagination?.[field] !== void 0) body[field] = pagination[field];
454
+ }
455
+ return body;
456
+ }
457
+ var PAGE_COUNTERS = ["total", "page", "limit"];
458
+ function mergeHeaders(...layers) {
459
+ const byName = /* @__PURE__ */ new Map();
460
+ for (const layer of layers) {
461
+ for (const [name, value] of Object.entries(layer ?? {})) {
462
+ if (value === void 0 || value === null) continue;
463
+ const lower = name.toLowerCase();
464
+ byName.delete(lower);
465
+ byName.set(lower, [name, value]);
466
+ }
467
+ }
468
+ return Object.fromEntries(byName.values());
427
469
  }
428
- function withModels(res) {
429
- const body = res;
430
- return Array.isArray(body.models) || !Array.isArray(body.data) ? body : { ...body, models: body.data };
470
+ function headerKey(headers, name) {
471
+ return Object.keys(headers ?? {}).filter((key) => key.toLowerCase() === name).pop();
431
472
  }
432
473
  async function safeText(response) {
433
474
  try {
@@ -544,6 +585,7 @@ function inferMimeType(fileName) {
544
585
  var Seclai = class {
545
586
  baseUrl;
546
587
  defaultHeaders;
588
+ allowUnknownApiVersion;
547
589
  fetcher;
548
590
  _authState = null;
549
591
  _authInitPromise = null;
@@ -574,22 +616,13 @@ var Seclai = class {
574
616
  );
575
617
  }
576
618
  this.baseUrl = opts.baseUrl ?? getEnv2("SECLAI_API_URL") ?? SECLAI_API_URL;
577
- const merged = opts.apiVersion ? { "Seclai-Version": opts.apiVersion } : {};
578
- let versionKey = opts.apiVersion ? "Seclai-Version" : void 0;
579
- for (const [key, value] of Object.entries(opts.defaultHeaders ?? {})) {
580
- for (const existing of Object.keys(merged)) {
581
- if (existing.toLowerCase() === key.toLowerCase()) delete merged[existing];
582
- }
583
- merged[key] = value;
584
- if (key.toLowerCase() === "seclai-version") versionKey = key;
585
- }
586
- const effectiveVersion = versionKey ? merged[versionKey] : void 0;
587
- if (effectiveVersion && !opts.allowUnknownApiVersion && !KNOWN_API_VERSIONS.includes(effectiveVersion)) {
588
- const via = versionKey === "Seclai-Version" && merged[versionKey] === opts.apiVersion ? "apiVersion" : `defaultHeaders['${versionKey}']`;
589
- throw new SeclaiConfigurationError(
590
- `Unknown API version '${effectiveVersion}' (via ${via}). This release was built against ${KNOWN_API_VERSIONS.join(", ")}. A newer API version can change response shapes, which this client would decode incorrectly rather than reject. Upgrade the package, or set allowUnknownApiVersion to proceed anyway.`
591
- );
592
- }
619
+ this.allowUnknownApiVersion = opts.allowUnknownApiVersion ?? false;
620
+ const merged = mergeHeaders(
621
+ opts.apiVersion ? { "Seclai-Version": opts.apiVersion } : void 0,
622
+ opts.defaultHeaders
623
+ );
624
+ const defaultKey = headerKey(opts.defaultHeaders, "seclai-version");
625
+ this.assertKnownApiVersion(merged, defaultKey ? `defaultHeaders['${defaultKey}']` : "apiVersion");
593
626
  this.defaultHeaders = merged;
594
627
  this.fetcher = fetcher;
595
628
  const accessTokenProvider = typeof opts.accessToken === "function" ? opts.accessToken : void 0;
@@ -628,6 +661,26 @@ var Seclai = class {
628
661
  }
629
662
  return this._authState;
630
663
  }
664
+ /** Throw unless the `Seclai-Version` in `headers` is one this release was built against. */
665
+ assertKnownApiVersion(headers, via) {
666
+ const key = headerKey(headers, "seclai-version");
667
+ if (key === void 0 || this.allowUnknownApiVersion) return;
668
+ const version = headers[key] ?? "";
669
+ if (KNOWN_API_VERSIONS.includes(version)) return;
670
+ throw new SeclaiConfigurationError(
671
+ `Unknown API version '${version}' (via ${via}). This release was built against ${KNOWN_API_VERSIONS.join(", ")}. A newer API version can change response shapes, which this client would decode incorrectly rather than reject. Upgrade the package, or set allowUnknownApiVersion to proceed anyway.`
672
+ );
673
+ }
674
+ /**
675
+ * The headers one request sends: `layers` merged in order, later winning,
676
+ * with the resulting `Seclai-Version` checked against the known versions.
677
+ */
678
+ requestHeaders(layers, perRequest) {
679
+ const headers = mergeHeaders(...layers);
680
+ const requestKey = headerKey(perRequest, "seclai-version");
681
+ this.assertKnownApiVersion(headers, requestKey ? `headers['${requestKey}']` : "defaultHeaders");
682
+ return headers;
683
+ }
631
684
  /** Resolve auth headers for the current request. */
632
685
  async authHeaders() {
633
686
  const state = await this.ensureAuth();
@@ -651,16 +704,17 @@ var Seclai = class {
651
704
  async request(method, path, opts) {
652
705
  const url = buildURL(this.baseUrl, path, opts?.query);
653
706
  const authHeaders = await this.authHeaders();
654
- const headers = {
655
- ...this.defaultHeaders,
656
- ...opts?.headers ?? {},
657
- ...authHeaders
658
- };
659
707
  let body;
660
- if (opts?.json !== void 0) {
661
- headers["content-type"] = headers["content-type"] ?? "application/json";
662
- body = JSON.stringify(opts.json);
663
- }
708
+ if (opts?.json !== void 0) body = JSON.stringify(opts.json);
709
+ const headers = this.requestHeaders(
710
+ [
711
+ body === void 0 ? void 0 : { "content-type": "application/json" },
712
+ this.defaultHeaders,
713
+ opts?.headers,
714
+ authHeaders
715
+ ],
716
+ opts?.headers
717
+ );
664
718
  const init = { method, headers };
665
719
  if (body !== void 0) {
666
720
  init.body = body;
@@ -712,16 +766,17 @@ var Seclai = class {
712
766
  async requestRaw(method, path, opts) {
713
767
  const url = buildURL(this.baseUrl, path, opts?.query);
714
768
  const authHeaders = await this.authHeaders();
715
- const headers = {
716
- ...this.defaultHeaders,
717
- ...opts?.headers ?? {},
718
- ...authHeaders
719
- };
720
769
  let body;
721
- if (opts?.json !== void 0) {
722
- headers["content-type"] = headers["content-type"] ?? "application/json";
723
- body = JSON.stringify(opts.json);
724
- }
770
+ if (opts?.json !== void 0) body = JSON.stringify(opts.json);
771
+ const headers = this.requestHeaders(
772
+ [
773
+ body === void 0 ? void 0 : { "content-type": "application/json" },
774
+ this.defaultHeaders,
775
+ opts?.headers,
776
+ authHeaders
777
+ ],
778
+ opts?.headers
779
+ );
725
780
  const init = { method, headers };
726
781
  if (body !== void 0) init.body = body;
727
782
  if (opts?.signal) init.signal = opts.signal;
@@ -753,12 +808,9 @@ var Seclai = class {
753
808
  async uploadFile(path, opts) {
754
809
  const url = buildURL(this.baseUrl, path);
755
810
  const authHeaders = await this.authHeaders();
756
- const headers = {
757
- ...this.defaultHeaders,
758
- ...authHeaders
759
- };
760
- delete headers["content-type"];
761
- delete headers["Content-Type"];
811
+ const headers = this.requestHeaders([this.defaultHeaders, authHeaders]);
812
+ const contentType = headerKey(headers, "content-type");
813
+ if (contentType !== void 0) delete headers[contentType];
762
814
  const form = new FormData();
763
815
  const mimeType = opts.mimeType ?? inferMimeType(opts.fileName);
764
816
  const blob = toBlob(opts.file, mimeType);
@@ -925,7 +977,7 @@ var Seclai = class {
925
977
  * @returns The calling agents.
926
978
  */
927
979
  async getAgentCallers(agentId) {
928
- return await this.request("GET", `/agents/${agentId}/callers`);
980
+ return listItems(await this.request("GET", `/agents/${agentId}/callers`));
929
981
  }
930
982
  // ═══════════════════════════════════════════════════════════════════════════
931
983
  // Agent Export / Import
@@ -1063,23 +1115,25 @@ var Seclai = class {
1063
1115
  * Run an agent in streaming mode (SSE) and wait for the final result.
1064
1116
  *
1065
1117
  * Consumes the entire SSE stream and returns only the terminal `done` payload.
1066
- * For real-time event access, use {@link runStreamingAgent} instead.
1118
+ * For real-time event access, use {@link runStreamingAgent} instead. The body
1119
+ * takes no `include_reasoning`, and one passed anyway is not sent: this method
1120
+ * returns no `stream_reasoning` events.
1067
1121
  *
1068
1122
  * @param agentId - Agent identifier.
1069
- * @param body - Streaming run request payload.
1123
+ * @param body - Streaming run request payload, without `include_reasoning`.
1070
1124
  * @param opts - Timeout and abort signal options.
1071
1125
  * @returns Final agent run payload from the `done` event.
1072
1126
  * @throws {@link SeclaiStreamingError} If the stream ends before a `done` event.
1073
1127
  */
1074
1128
  async runStreamingAgentAndWait(agentId, body, opts) {
1129
+ const { include_reasoning: _ignored, ...runBody } = body;
1075
1130
  const url = buildURL(this.baseUrl, `/agents/${agentId}/runs/stream`);
1076
1131
  const authHdrs = await this.authHeaders();
1077
- const headers = {
1078
- ...this.defaultHeaders,
1079
- ...authHdrs,
1080
- accept: "text/event-stream",
1081
- "content-type": "application/json"
1082
- };
1132
+ const headers = this.requestHeaders([
1133
+ this.defaultHeaders,
1134
+ authHdrs,
1135
+ { accept: "text/event-stream", "content-type": "application/json" }
1136
+ ]);
1083
1137
  const timeoutMs = opts?.timeoutMs ?? 6e4;
1084
1138
  const timeoutController = new AbortController();
1085
1139
  let timedOut = false;
@@ -1090,7 +1144,7 @@ var Seclai = class {
1090
1144
  const signal = anySignal([opts?.signal, timeoutController.signal]);
1091
1145
  let lastSeen;
1092
1146
  try {
1093
- const init = { method: "POST", headers, body: JSON.stringify(body) };
1147
+ const init = { method: "POST", headers, body: JSON.stringify(runBody) };
1094
1148
  if (signal) init.signal = signal;
1095
1149
  const response = await this.fetcher(url, init);
1096
1150
  const contentType = response.headers.get("content-type") ?? "";
@@ -1184,12 +1238,11 @@ var Seclai = class {
1184
1238
  async *runStreamingAgent(agentId, body, opts) {
1185
1239
  const url = buildURL(this.baseUrl, `/agents/${agentId}/runs/stream`);
1186
1240
  const authHdrs = await this.authHeaders();
1187
- const headers = {
1188
- ...this.defaultHeaders,
1189
- ...authHdrs,
1190
- accept: "text/event-stream",
1191
- "content-type": "application/json"
1192
- };
1241
+ const headers = this.requestHeaders([
1242
+ this.defaultHeaders,
1243
+ authHdrs,
1244
+ { accept: "text/event-stream", "content-type": "application/json" }
1245
+ ]);
1193
1246
  const timeoutMs = opts?.timeoutMs ?? 6e4;
1194
1247
  const timeoutController = new AbortController();
1195
1248
  let timedOut = false;
@@ -1320,19 +1373,26 @@ var Seclai = class {
1320
1373
  * @returns Paginated list of evaluation results.
1321
1374
  */
1322
1375
  async listRunEvaluationResults(agentId, runId, opts = {}) {
1323
- const res = await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1324
- query: { page: opts.page, limit: opts.limit }
1325
- });
1326
- return Array.isArray(res) ? { data: res } : res;
1376
+ return keyedList(
1377
+ await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1378
+ query: { page: opts.page, limit: opts.limit }
1379
+ }),
1380
+ "data",
1381
+ PAGE_COUNTERS
1382
+ );
1327
1383
  }
1328
1384
  // ═══════════════════════════════════════════════════════════════════════════
1329
1385
  // Agent Input Uploads
1330
1386
  // ═══════════════════════════════════════════════════════════════════════════
1331
1387
  /**
1332
- * Upload a file to use as input for a `dynamic_input` agent run.
1388
+ * Upload a file to use as input for a `dynamic_input` agent run. Any other
1389
+ * agent rejects the upload with HTTP 400. Files are limited to 200 MB.
1333
1390
  *
1334
- * After uploading, poll {@link getAgentInputUploadStatus} until `status` is `ready`,
1335
- * then pass `input_upload_id` to {@link runAgent}.
1391
+ * From API version `2026-10-16` a file of any type is accepted and is `ready`
1392
+ * at once: pass its `id` as `input_upload_id` to {@link runAgent}.
1393
+ * Earlier versions accept only a fixed list of extensions and write each
1394
+ * file's extracted text into the run's `input`, so poll
1395
+ * {@link getAgentInputUploadStatus} until `status` is `ready` before running.
1336
1396
  *
1337
1397
  * @param agentId - Agent identifier.
1338
1398
  * @param opts - File payload and optional metadata.
@@ -1374,12 +1434,16 @@ var Seclai = class {
1374
1434
  * @param runId - Run identifier.
1375
1435
  * @param attachmentId - URL-safe-base64-encoded `storage_key` of the attachment
1376
1436
  * (as surfaced in run output manifests and webhook/email payloads).
1377
- * @param opts - Optional `downloadName` filename hint for the download disposition.
1437
+ * @param opts - Optional `downloadName` filename hint for the download
1438
+ * disposition, and `signal`, which cancels the request; with a standard `fetch` this
1439
+ * includes reading the body, so `AbortSignal.timeout(ms)` bounds the whole
1440
+ * transfer.
1378
1441
  * @returns Raw response with the attachment bytes.
1379
1442
  */
1380
1443
  async downloadAgentRunAttachment(runId, attachmentId, opts = {}) {
1381
1444
  return await this.requestRaw("GET", `/v2/agent-runs/${runId}/attachments/${attachmentId}`, {
1382
- query: { download_name: opts.downloadName }
1445
+ query: { download_name: opts.downloadName },
1446
+ signal: opts.signal
1383
1447
  });
1384
1448
  }
1385
1449
  // ═══════════════════════════════════════════════════════════════════════════
@@ -1451,20 +1515,21 @@ var Seclai = class {
1451
1515
  /**
1452
1516
  * List evaluation criteria for an agent, with pagination metadata.
1453
1517
  *
1454
- * Accepts either wire shape. The endpoint answered with a bare array before
1455
- * 2026-07 and with a paginated envelope after, so a client that decodes only
1456
- * one breaks the day the other ships. `total`, `page` and `limit` are absent
1457
- * when the endpoint answers with a bare array.
1518
+ * The endpoint answers with a bare array by default and with `{data,
1519
+ * pagination}` once `apiVersion` is 2026-07-27 or later; `pagination` is
1520
+ * absent on the bare array.
1458
1521
  *
1459
1522
  * @param agentId - Agent identifier.
1460
1523
  * @param opts - Pagination options.
1461
1524
  * @returns The criteria under `data`, plus the page metadata when present.
1462
1525
  */
1463
1526
  async listEvaluationCriteriaPage(agentId, opts = {}) {
1464
- const res = await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1465
- query: { page: opts.page, limit: opts.limit }
1466
- });
1467
- return Array.isArray(res) ? { data: res } : res;
1527
+ return keyedList(
1528
+ await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1529
+ query: { page: opts.page, limit: opts.limit }
1530
+ }),
1531
+ "data"
1532
+ );
1468
1533
  }
1469
1534
  /**
1470
1535
  * Create evaluation criteria for an agent.
@@ -1519,9 +1584,13 @@ var Seclai = class {
1519
1584
  * @param opts - Pagination options.
1520
1585
  */
1521
1586
  async listEvaluationResults(criteriaId, opts = {}) {
1522
- return await this.request("GET", `/agents/evaluation-criteria/${criteriaId}/results`, {
1523
- query: { page: opts.page, limit: opts.limit }
1524
- });
1587
+ return keyedList(
1588
+ await this.request("GET", `/agents/evaluation-criteria/${criteriaId}/results`, {
1589
+ query: { page: opts.page, limit: opts.limit }
1590
+ }),
1591
+ "data",
1592
+ PAGE_COUNTERS
1593
+ );
1525
1594
  }
1526
1595
  /**
1527
1596
  * Create a manual evaluation result for a criteria.
@@ -1540,9 +1609,13 @@ var Seclai = class {
1540
1609
  * @param opts - Pagination options.
1541
1610
  */
1542
1611
  async listCompatibleRuns(criteriaId, opts = {}) {
1543
- return await this.request("GET", `/agents/evaluation-criteria/${criteriaId}/compatible-runs`, {
1544
- query: { page: opts.page, limit: opts.limit }
1545
- });
1612
+ return keyedList(
1613
+ await this.request("GET", `/agents/evaluation-criteria/${criteriaId}/compatible-runs`, {
1614
+ query: { page: opts.page, limit: opts.limit }
1615
+ }),
1616
+ "data",
1617
+ PAGE_COUNTERS
1618
+ );
1546
1619
  }
1547
1620
  /**
1548
1621
  * Test a draft evaluation criteria without persisting it.
@@ -1561,9 +1634,13 @@ var Seclai = class {
1561
1634
  * @param opts - Pagination options.
1562
1635
  */
1563
1636
  async listAgentEvaluationResults(agentId, opts = {}) {
1564
- return await this.request("GET", `/agents/${agentId}/evaluation-results`, {
1565
- query: { page: opts.page, limit: opts.limit }
1566
- });
1637
+ return keyedList(
1638
+ await this.request("GET", `/agents/${agentId}/evaluation-results`, {
1639
+ query: { page: opts.page, limit: opts.limit }
1640
+ }),
1641
+ "data",
1642
+ PAGE_COUNTERS
1643
+ );
1567
1644
  }
1568
1645
  /**
1569
1646
  * List evaluation run summaries for an agent.
@@ -1572,9 +1649,13 @@ var Seclai = class {
1572
1649
  * @param opts - Pagination options.
1573
1650
  */
1574
1651
  async listEvaluationRuns(agentId, opts = {}) {
1575
- return await this.request("GET", `/agents/${agentId}/evaluation-runs`, {
1576
- query: { page: opts.page, limit: opts.limit }
1577
- });
1652
+ return keyedList(
1653
+ await this.request("GET", `/agents/${agentId}/evaluation-runs`, {
1654
+ query: { page: opts.page, limit: opts.limit }
1655
+ }),
1656
+ "data",
1657
+ PAGE_COUNTERS
1658
+ );
1578
1659
  }
1579
1660
  /**
1580
1661
  * Get a summary of non-manual evaluations across an agent's runs.
@@ -1607,6 +1688,24 @@ var Seclai = class {
1607
1688
  json: body
1608
1689
  });
1609
1690
  }
1691
+ /**
1692
+ * Replace the input attachments a trigger accepts.
1693
+ *
1694
+ * A run's files are each assigned to one declared attachment before any step
1695
+ * runs, and steps reference one as `{{agent.attachments.<name>}}`. The API
1696
+ * answers 400 when the agent references an attachment the new declaration
1697
+ * leaves out.
1698
+ *
1699
+ * @param agentId - Agent identifier.
1700
+ * @param triggerId - Trigger identifier, as `getAgent()` returns it.
1701
+ * @param body - The full list of accepted attachments; a slot's `min` defaults to 0.
1702
+ * @returns The trigger's accepted attachments.
1703
+ */
1704
+ async setAcceptedAttachments(agentId, triggerId, body) {
1705
+ return await this.request("PUT", `/agents/${agentId}/triggers/${triggerId}/accepted-attachments`, {
1706
+ json: body
1707
+ });
1708
+ }
1610
1709
  // ═══════════════════════════════════════════════════════════════════════════
1611
1710
  // Agent Email Governance
1612
1711
  // ═══════════════════════════════════════════════════════════════════════════
@@ -1620,9 +1719,13 @@ var Seclai = class {
1620
1719
  * @returns The page of opt-outs plus the total count.
1621
1720
  */
1622
1721
  async listAgentEmailOptOuts(opts = {}) {
1623
- return await this.request("GET", "/agents/agent-email-optouts", {
1624
- query: { agent_id: opts.agentId, limit: opts.limit, offset: opts.offset }
1625
- });
1722
+ return keyedList(
1723
+ await this.request("GET", "/agents/agent-email-optouts", {
1724
+ query: { agent_id: opts.agentId, limit: opts.limit, offset: opts.offset }
1725
+ }),
1726
+ "items",
1727
+ ["total"]
1728
+ );
1626
1729
  }
1627
1730
  /**
1628
1731
  * Revoke an opt-out, opting the recipient back in to agent emails.
@@ -1641,9 +1744,13 @@ var Seclai = class {
1641
1744
  * @param opts.offset - Rows to skip (default 0).
1642
1745
  */
1643
1746
  async listBlockedEmailSenders(opts = {}) {
1644
- return await this.request("GET", "/agents/blocked-email-senders", {
1645
- query: { limit: opts.limit, offset: opts.offset }
1646
- });
1747
+ return keyedList(
1748
+ await this.request("GET", "/agents/blocked-email-senders", {
1749
+ query: { limit: opts.limit, offset: opts.offset }
1750
+ }),
1751
+ "items",
1752
+ ["total"]
1753
+ );
1647
1754
  }
1648
1755
  /**
1649
1756
  * Add a sender address or a whole domain to the account blocklist.
@@ -1678,9 +1785,11 @@ var Seclai = class {
1678
1785
  * @returns The updated blocked-sender list.
1679
1786
  */
1680
1787
  async setAutoBlockMode(body) {
1681
- return await this.request("PUT", "/agents/blocked-email-senders/mode", {
1682
- json: body
1683
- });
1788
+ return keyedList(
1789
+ await this.request("PUT", "/agents/blocked-email-senders/mode", { json: body }),
1790
+ "items",
1791
+ ["total"]
1792
+ );
1684
1793
  }
1685
1794
  /**
1686
1795
  * List recent inbound emails that were quietly discarded before running an
@@ -1691,9 +1800,11 @@ var Seclai = class {
1691
1800
  * @param opts.limit - Maximum results (1-200, default 50).
1692
1801
  */
1693
1802
  async listInboundEmailRejections(opts = {}) {
1694
- return await this.request("GET", "/agents/inbound-email-rejections", {
1695
- query: { agent_id: opts.agentId, limit: opts.limit }
1696
- });
1803
+ return listItems(
1804
+ await this.request("GET", "/agents/inbound-email-rejections", {
1805
+ query: { agent_id: opts.agentId, limit: opts.limit }
1806
+ })
1807
+ );
1697
1808
  }
1698
1809
  /**
1699
1810
  * Get the account's inbound-email overload status — whether the circuit
@@ -1735,9 +1846,13 @@ var Seclai = class {
1735
1846
  * @returns Paginated list of knowledge bases.
1736
1847
  */
1737
1848
  async listKnowledgeBases(opts = {}) {
1738
- return await this.request("GET", "/knowledge_bases", {
1739
- query: { page: opts.page, limit: opts.limit, sort: opts.sort, order: opts.order }
1740
- });
1849
+ return keyedList(
1850
+ await this.request("GET", "/knowledge_bases", {
1851
+ query: { page: opts.page, limit: opts.limit, sort: opts.sort, order: opts.order }
1852
+ }),
1853
+ "knowledge_bases",
1854
+ PAGE_COUNTERS
1855
+ );
1741
1856
  }
1742
1857
  /**
1743
1858
  * Create a new knowledge base.
@@ -1785,9 +1900,13 @@ var Seclai = class {
1785
1900
  * @returns Paginated list of memory banks.
1786
1901
  */
1787
1902
  async listMemoryBanks(opts = {}) {
1788
- return await this.request("GET", "/memory_banks", {
1789
- query: { page: opts.page, limit: opts.limit, sort: opts.sort, order: opts.order }
1790
- });
1903
+ return keyedList(
1904
+ await this.request("GET", "/memory_banks", {
1905
+ query: { page: opts.page, limit: opts.limit, sort: opts.sort, order: opts.order }
1906
+ }),
1907
+ "memory_banks",
1908
+ PAGE_COUNTERS
1909
+ );
1791
1910
  }
1792
1911
  /**
1793
1912
  * Create a new memory bank.
@@ -1834,7 +1953,7 @@ var Seclai = class {
1834
1953
  * @param memoryBankId - Memory bank identifier.
1835
1954
  */
1836
1955
  async getAgentsUsingMemoryBank(memoryBankId) {
1837
- return await this.request("GET", `/memory_banks/${memoryBankId}/agents`);
1956
+ return listItems(await this.request("GET", `/memory_banks/${memoryBankId}/agents`));
1838
1957
  }
1839
1958
  /**
1840
1959
  * Get stats for a memory bank.
@@ -1881,7 +2000,7 @@ var Seclai = class {
1881
2000
  * List available memory bank templates.
1882
2001
  */
1883
2002
  async listMemoryBankTemplates() {
1884
- return await this.request("GET", "/memory_banks/templates");
2003
+ return listItems(await this.request("GET", "/memory_banks/templates"));
1885
2004
  }
1886
2005
  // ─── Memory Bank AI Assistant ──────────────────────────────────────────────
1887
2006
  /**
@@ -2036,6 +2155,24 @@ var Seclai = class {
2036
2155
  `/sources/${sourceId}/contents/${contentVersionId}`
2037
2156
  );
2038
2157
  }
2158
+ /**
2159
+ * List mail an email content source refused, newest first.
2160
+ *
2161
+ * Each entry says who sent the message and why it was refused, never its
2162
+ * subject or body. To accept a refused sender, add its `from_address` or that
2163
+ * address's domain to the source's `email_allowed_senders` — which only helps
2164
+ * when `authenticated` is true. Requires an account owner or administrator;
2165
+ * the API answers 404 for a source that is not an email source.
2166
+ *
2167
+ * @param sourceId - Source connection identifier.
2168
+ * @param opts - Pagination options (`limit` 1-100).
2169
+ * @returns The rejections under `data` with `pagination`.
2170
+ */
2171
+ async listEmailSourceRejections(sourceId, opts = {}) {
2172
+ return await this.request("GET", `/sources/${sourceId}/email-rejections`, {
2173
+ query: { page: opts.page, limit: opts.limit }
2174
+ });
2175
+ }
2039
2176
  // ─── Source Exports ────────────────────────────────────────────────────────
2040
2177
  /**
2041
2178
  * List exports for a source.
@@ -2085,10 +2222,15 @@ var Seclai = class {
2085
2222
  *
2086
2223
  * @param sourceId - Source connection identifier.
2087
2224
  * @param exportId - Export identifier.
2225
+ * @param opts - Optional `signal`, which cancels the request; with a standard `fetch` this
2226
+ * includes reading the body, so `AbortSignal.timeout(ms)` bounds the whole
2227
+ * transfer.
2088
2228
  * @returns Raw response with the export file.
2089
2229
  */
2090
- async downloadSourceExport(sourceId, exportId) {
2091
- return await this.requestRaw("GET", `/sources/${sourceId}/exports/${exportId}/download`);
2230
+ async downloadSourceExport(sourceId, exportId, opts = {}) {
2231
+ return await this.requestRaw("GET", `/sources/${sourceId}/exports/${exportId}/download`, {
2232
+ signal: opts.signal
2233
+ });
2092
2234
  }
2093
2235
  /**
2094
2236
  * Estimate a source export.
@@ -2182,6 +2324,79 @@ var Seclai = class {
2182
2324
  query: { page: opts.page ?? 1, limit: opts.limit ?? 20 }
2183
2325
  });
2184
2326
  }
2327
+ /**
2328
+ * List the files attached to a content item.
2329
+ *
2330
+ * Files arrive from an agent's `write_content_attachment` step, with an email
2331
+ * message, from an RSS feed's `feed_attachments`, from a web page's media, or
2332
+ * as the images inside a document. Each entry says whether it is indexed for
2333
+ * search and, when indexing failed, why.
2334
+ *
2335
+ * @param contentVersionId - Content version identifier.
2336
+ * @param opts - Pagination options.
2337
+ * @returns The attachments under `data` with `pagination`.
2338
+ */
2339
+ async listContentAttachments(contentVersionId, opts = {}) {
2340
+ return await this.request("GET", `/contents/${contentVersionId}/attachments`, {
2341
+ query: { page: opts.page, limit: opts.limit }
2342
+ });
2343
+ }
2344
+ /**
2345
+ * Get one file attached to a content item: its indexing status and reason,
2346
+ * its metadata, and the text it is indexed by.
2347
+ *
2348
+ * @param contentVersionId - Content version identifier.
2349
+ * @param attachmentId - The `id` of an entry from {@link listContentAttachments}.
2350
+ * @param opts - `start` and `end` character offsets for paging through long text
2351
+ * (server defaults 0 and 5000). Both are sent as given, so `end: 0` asks for
2352
+ * the metadata without any text. A file that was not indexed has no text.
2353
+ * @returns The attachment with the requested range of its text.
2354
+ * @throws {SeclaiAPIStatusError} 402 when the account has no credits left
2355
+ * (`error.code` `insufficient_credits`).
2356
+ */
2357
+ async getContentAttachment(contentVersionId, attachmentId, opts = {}) {
2358
+ return await this.request("GET", `/contents/${contentVersionId}/attachments/${attachmentId}`, {
2359
+ query: { start: opts.start, end: opts.end }
2360
+ });
2361
+ }
2362
+ /**
2363
+ * List the embeddings (chunk vectors) a content attachment is indexed by.
2364
+ * The list is empty for a file that has no completed index.
2365
+ *
2366
+ * @param contentVersionId - Content version identifier.
2367
+ * @param attachmentId - Attachment identifier.
2368
+ * @param opts - Pagination options (`limit` 1-100).
2369
+ * @returns Paginated list of embeddings.
2370
+ * @throws {SeclaiAPIStatusError} 402 when the account has no credits left
2371
+ * (`error.code` `insufficient_credits`).
2372
+ */
2373
+ async listContentAttachmentEmbeddings(contentVersionId, attachmentId, opts = {}) {
2374
+ return await this.request("GET", `/contents/${contentVersionId}/attachments/${attachmentId}/embeddings`, {
2375
+ query: { page: opts.page, limit: opts.limit }
2376
+ });
2377
+ }
2378
+ /**
2379
+ * Download a content attachment's bytes.
2380
+ *
2381
+ * Returns the raw `Response` so you can stream or save the binary data. The
2382
+ * API answers 403 when the file is withheld — blocked or redacted by a
2383
+ * governance policy, or still being indexed after arriving from outside; the
2384
+ * attachment's `file_withheld` field says which before you ask.
2385
+ *
2386
+ * @param contentVersionId - Content version identifier.
2387
+ * @param attachmentId - Attachment identifier.
2388
+ * @param opts - Optional `signal`, which cancels the request; with a standard `fetch` this
2389
+ * includes reading the body, so `AbortSignal.timeout(ms)` bounds the whole
2390
+ * transfer.
2391
+ * @returns Raw response with the attachment bytes.
2392
+ * @throws {SeclaiAPIStatusError} 403 when the file is withheld, and 402 when
2393
+ * the account has no credits left (`error.code` `insufficient_credits`).
2394
+ */
2395
+ async downloadContentAttachment(contentVersionId, attachmentId, opts = {}) {
2396
+ return await this.requestRaw("GET", `/contents/${contentVersionId}/attachments/${attachmentId}/file`, {
2397
+ signal: opts.signal
2398
+ });
2399
+ }
2185
2400
  /**
2186
2401
  * Upload a file to replace content for an existing content version.
2187
2402
  *
@@ -2311,7 +2526,9 @@ var Seclai = class {
2311
2526
  * @returns List of conversations.
2312
2527
  */
2313
2528
  async listSolutionConversations(solutionId) {
2314
- return await this.request("GET", `/solutions/${solutionId}/conversations`);
2529
+ return listItems(
2530
+ await this.request("GET", `/solutions/${solutionId}/conversations`)
2531
+ );
2315
2532
  }
2316
2533
  /**
2317
2534
  * Add a conversation turn to a solution.
@@ -2400,7 +2617,9 @@ var Seclai = class {
2400
2617
  * List governance AI conversations.
2401
2618
  */
2402
2619
  async listGovernanceAiConversations() {
2403
- return await this.request("GET", "/governance/ai-assistant/conversations");
2620
+ return listItems(
2621
+ await this.request("GET", "/governance/ai-assistant/conversations")
2622
+ );
2404
2623
  }
2405
2624
  /**
2406
2625
  * Accept a governance AI plan.
@@ -2484,15 +2703,15 @@ var Seclai = class {
2484
2703
  * @returns Paginated list of alert configs.
2485
2704
  */
2486
2705
  /**
2487
- * The configurations arrive under `configs` alongside `total` by default.
2488
- * Once the caller opts in with `apiVersion` 2026-07-27 or later the endpoint
2489
- * returns the canonical `{data, pagination}` envelope instead, so the
2490
- * top-level key changes.
2706
+ * `configs` and `total` are populated on every API version; `data` and
2707
+ * `pagination` are also present once `apiVersion` is 2026-07-27 or later.
2491
2708
  */
2492
2709
  async listAlertConfigs(opts = {}) {
2493
- return await this.request("GET", "/alerts/configs", {
2494
- query: { page: opts.page, limit: opts.limit }
2495
- });
2710
+ return keyedList(
2711
+ await this.request("GET", "/alerts/configs", { query: { page: opts.page, limit: opts.limit } }),
2712
+ "configs",
2713
+ ["total"]
2714
+ );
2496
2715
  }
2497
2716
  /**
2498
2717
  * Create an alert configuration.
@@ -2535,7 +2754,11 @@ var Seclai = class {
2535
2754
  * List organization alert preferences.
2536
2755
  */
2537
2756
  async listOrganizationAlertPreferences() {
2538
- return await this.request("GET", "/alerts/organization-preferences/list");
2757
+ return keyedList(
2758
+ await this.request("GET", "/alerts/organization-preferences/list"),
2759
+ "preferences",
2760
+ ["total"]
2761
+ );
2539
2762
  }
2540
2763
  /**
2541
2764
  * Update an organization alert preference.
@@ -2562,9 +2785,11 @@ var Seclai = class {
2562
2785
  async listModelAlerts(opts = {}) {
2563
2786
  const limit = opts.limit ?? 50;
2564
2787
  const offset = opts.page && opts.page > 1 ? (opts.page - 1) * limit : void 0;
2565
- return await this.request("GET", "/models/alerts", {
2566
- query: { offset, limit: opts.limit }
2567
- });
2788
+ return keyedList(
2789
+ await this.request("GET", "/models/alerts", { query: { offset, limit: opts.limit } }),
2790
+ "alerts",
2791
+ ["total"]
2792
+ );
2568
2793
  }
2569
2794
  /**
2570
2795
  * Mark all model alerts as read.
@@ -2600,7 +2825,7 @@ var Seclai = class {
2600
2825
  * @param opts - Optional filters.
2601
2826
  */
2602
2827
  async listModels(opts = {}) {
2603
- return await this.request("GET", "/models", {
2828
+ return listItems(await this.request("GET", "/models", {
2604
2829
  query: {
2605
2830
  provider: opts.provider,
2606
2831
  supports_tool_use: opts.supportsToolUse,
@@ -2608,7 +2833,7 @@ var Seclai = class {
2608
2833
  supports_input_media: opts.supportsInputMedia,
2609
2834
  supports_output_media: opts.supportsOutputMedia
2610
2835
  }
2611
- });
2836
+ }));
2612
2837
  }
2613
2838
  /**
2614
2839
  * Get full details for a specific model.
@@ -2630,7 +2855,7 @@ var Seclai = class {
2630
2855
  * Global routing/pricing (the same for every account); read-only.
2631
2856
  */
2632
2857
  async getGenerationTiers() {
2633
- return await this.request("GET", "/models/generation-tiers");
2858
+ return keyedList(await this.request("GET", "/models/generation-tiers"), "tiers");
2634
2859
  }
2635
2860
  /**
2636
2861
  * List the embedding models a source can index with, and their pricing.
@@ -2643,10 +2868,11 @@ var Seclai = class {
2643
2868
  * input modality — a coarse kind (text, image, video, audio) or a full MIME.
2644
2869
  */
2645
2870
  async listEmbeddingModels(opts = {}) {
2646
- return withModels(
2871
+ return keyedList(
2647
2872
  await this.request("GET", "/models/embedders", {
2648
2873
  query: { supports_input_media: opts.supportsInputMedia }
2649
- })
2874
+ }),
2875
+ "models"
2650
2876
  );
2651
2877
  }
2652
2878
  /**
@@ -2655,7 +2881,7 @@ var Seclai = class {
2655
2881
  * `models` is populated on either wire shape, as for {@link Seclai.listEmbeddingModels}.
2656
2882
  */
2657
2883
  async listRerankerModels() {
2658
- return withModels(await this.request("GET", "/models/rerankers"));
2884
+ return keyedList(await this.request("GET", "/models/rerankers"), "models");
2659
2885
  }
2660
2886
  // ═══════════════════════════════════════════════════════════════════════════
2661
2887
  // Model Playground Experiments
@@ -2666,9 +2892,13 @@ var Seclai = class {
2666
2892
  * @param opts - Optional filters and pagination.
2667
2893
  */
2668
2894
  async listExperiments(opts = {}) {
2669
- return await this.request("GET", "/models/playground/experiments", {
2670
- query: { days: opts.days, start_date: opts.startDate, end_date: opts.endDate, limit: opts.limit, offset: opts.offset }
2671
- });
2895
+ return keyedList(
2896
+ await this.request("GET", "/models/playground/experiments", {
2897
+ query: { days: opts.days, start_date: opts.startDate, end_date: opts.endDate, limit: opts.limit, offset: opts.offset }
2898
+ }),
2899
+ "experiments",
2900
+ ["total"]
2901
+ );
2672
2902
  }
2673
2903
  /**
2674
2904
  * Create a model playground experiment.
@@ -2845,7 +3075,7 @@ var Seclai = class {
2845
3075
  * Requires a user-bound credential; an account-only API key is refused with 403.
2846
3076
  */
2847
3077
  async listEmailDomains() {
2848
- return await this.request("GET", "/email-domains");
3078
+ return keyedList(await this.request("GET", "/email-domains"), "domains");
2849
3079
  }
2850
3080
  /**
2851
3081
  * Add and provision a new agent-email domain.