@seclai/sdk 1.4.0 → 1.6.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,3 +1,19 @@
1
+ // src/versions.ts
2
+ var SeclaiApiVersion = {
3
+ V2026_07_01: "2026-07-01",
4
+ V2026_07_27: "2026-07-27",
5
+ V2026_08_03: "2026-08-03",
6
+ V2026_08_21: "2026-08-21",
7
+ V2026_09_28: "2026-09-28",
8
+ V2026_09_30: "2026-09-30",
9
+ V2026_10_03: "2026-10-03",
10
+ /** Baseline applied to an unpinned, header-less caller. */
11
+ Default: "2026-07-01",
12
+ /** Newest version known to this SDK release. May lag the server. */
13
+ Latest: "2026-10-03"
14
+ };
15
+ var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
16
+
1
17
  // src/errors.ts
2
18
  var SeclaiError = class extends Error {
3
19
  constructor(message) {
@@ -345,11 +361,23 @@ function buildURL(baseUrl, path, query) {
345
361
  if (query) {
346
362
  for (const [key, value] of Object.entries(query)) {
347
363
  if (value === void 0 || value === null) continue;
364
+ if (Array.isArray(value)) {
365
+ for (const item of value) url.searchParams.append(key, String(item));
366
+ continue;
367
+ }
348
368
  url.searchParams.set(key, String(value));
349
369
  }
350
370
  }
351
371
  return url;
352
372
  }
373
+ function listItems(res) {
374
+ if (Array.isArray(res)) return res;
375
+ return res?.data ?? [];
376
+ }
377
+ function withModels(res) {
378
+ const body = res;
379
+ return Array.isArray(body.models) || !Array.isArray(body.data) ? body : { ...body, models: body.data };
380
+ }
353
381
  async function safeText(response) {
354
382
  try {
355
383
  return await response.clone().text();
@@ -495,7 +523,23 @@ var Seclai = class {
495
523
  );
496
524
  }
497
525
  this.baseUrl = opts.baseUrl ?? getEnv2("SECLAI_API_URL") ?? SECLAI_API_URL;
498
- this.defaultHeaders = { ...opts.defaultHeaders ?? {} };
526
+ const merged = opts.apiVersion ? { "Seclai-Version": opts.apiVersion } : {};
527
+ let versionKey = opts.apiVersion ? "Seclai-Version" : void 0;
528
+ for (const [key, value] of Object.entries(opts.defaultHeaders ?? {})) {
529
+ for (const existing of Object.keys(merged)) {
530
+ if (existing.toLowerCase() === key.toLowerCase()) delete merged[existing];
531
+ }
532
+ merged[key] = value;
533
+ if (key.toLowerCase() === "seclai-version") versionKey = key;
534
+ }
535
+ const effectiveVersion = versionKey ? merged[versionKey] : void 0;
536
+ if (effectiveVersion && !opts.allowUnknownApiVersion && !KNOWN_API_VERSIONS.includes(effectiveVersion)) {
537
+ const via = versionKey === "Seclai-Version" && merged[versionKey] === opts.apiVersion ? "apiVersion" : `defaultHeaders['${versionKey}']`;
538
+ throw new SeclaiConfigurationError(
539
+ `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.`
540
+ );
541
+ }
542
+ this.defaultHeaders = merged;
499
543
  this.fetcher = fetcher;
500
544
  const accessTokenProvider = typeof opts.accessToken === "function" ? opts.accessToken : void 0;
501
545
  const accessTokenStatic = typeof opts.accessToken === "string" ? opts.accessToken : void 0;
@@ -713,6 +757,34 @@ var Seclai = class {
713
757
  return await this.request("GET", "/me");
714
758
  }
715
759
  // ═══════════════════════════════════════════════════════════════════════════
760
+ // API Version
761
+ // ═══════════════════════════════════════════════════════════════════════════
762
+ /**
763
+ * Read the API version this request resolved to, and the versions available.
764
+ *
765
+ * Resolution order is the `Seclai-Version` header, then the account pin, then
766
+ * the default — so `effective_version` reflects the client's `apiVersion`
767
+ * option when that is set.
768
+ *
769
+ * @returns The pinned, effective, default and latest versions.
770
+ */
771
+ async getApiVersion() {
772
+ return await this.request("GET", "/version");
773
+ }
774
+ /**
775
+ * Pin the account to a dated API version, or clear the pin.
776
+ *
777
+ * Owner/admin only. The pin applies to later header-less requests; a
778
+ * `Seclai-Version` header still overrides it, so `effective_version` in the
779
+ * response describes this request rather than the pin just written.
780
+ *
781
+ * @param version - A `YYYY-MM-DD` date to pin to, or `null` to clear the pin.
782
+ * @returns The updated version state.
783
+ */
784
+ async updateApiVersion(version) {
785
+ return await this.request("PUT", "/version", { json: { version } });
786
+ }
787
+ // ═══════════════════════════════════════════════════════════════════════════
716
788
  // Agents — CRUD
717
789
  // ═══════════════════════════════════════════════════════════════════════════
718
790
  /**
@@ -909,21 +981,29 @@ var Seclai = class {
909
981
  } : void 0);
910
982
  }
911
983
  /**
912
- * Delete an agent run.
984
+ * Cancel an agent run.
985
+ *
986
+ * @deprecated This never deleted anything — the endpoint it calls is documented
987
+ * as "Cancel an agent run", and the API has no delete-a-run operation. It also
988
+ * discards the returned run state. Use {@link cancelAgentRun} instead.
913
989
  *
914
990
  * @param runId - Run identifier.
915
991
  */
916
992
  async deleteAgentRun(runId) {
917
- await this.request("DELETE", `/agents/runs/${runId}`);
993
+ await this.cancelAgentRun(runId);
918
994
  }
919
995
  /**
920
996
  * Cancel a running agent run.
921
997
  *
998
+ * Cancellation is `DELETE` on the run resource — the API exposes no
999
+ * `POST .../cancel` route, and no operation that deletes a run. Rejected when
1000
+ * the run has already reached a terminal state.
1001
+ *
922
1002
  * @param runId - Run identifier.
923
1003
  * @returns Updated run (with cancelled status).
924
1004
  */
925
1005
  async cancelAgentRun(runId) {
926
- return await this.request("POST", `/agents/runs/${runId}/cancel`);
1006
+ return await this.request("DELETE", `/agents/runs/${runId}`);
927
1007
  }
928
1008
  // ═══════════════════════════════════════════════════════════════════════════
929
1009
  // Agent Runs — Streaming
@@ -1189,9 +1269,10 @@ var Seclai = class {
1189
1269
  * @returns Paginated list of evaluation results.
1190
1270
  */
1191
1271
  async listRunEvaluationResults(agentId, runId, opts = {}) {
1192
- return await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1272
+ const res = await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1193
1273
  query: { page: opts.page, limit: opts.limit }
1194
1274
  });
1275
+ return Array.isArray(res) ? { data: res } : res;
1195
1276
  }
1196
1277
  // ═══════════════════════════════════════════════════════════════════════════
1197
1278
  // Agent Input Uploads
@@ -1279,8 +1360,20 @@ var Seclai = class {
1279
1360
  * @param agentId - Agent identifier.
1280
1361
  * @returns Conversation history.
1281
1362
  */
1282
- async getAgentAiConversationHistory(agentId) {
1283
- return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`);
1363
+ async getAgentAiConversationHistory(agentId, opts = {}) {
1364
+ if (!opts.stepType) {
1365
+ throw new SeclaiConfigurationError(
1366
+ 'getAgentAiConversationHistory requires opts.stepType; the API rejects the request without it. Pass e.g. { stepType: "llm" }.'
1367
+ );
1368
+ }
1369
+ return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`, {
1370
+ query: {
1371
+ step_type: opts.stepType,
1372
+ step_id: opts.stepId,
1373
+ limit: opts.limit,
1374
+ offset: opts.offset
1375
+ }
1376
+ });
1284
1377
  }
1285
1378
  /**
1286
1379
  * Mark an AI suggestion as accepted or rejected.
@@ -1302,9 +1395,25 @@ var Seclai = class {
1302
1395
  * @param opts - Pagination options.
1303
1396
  */
1304
1397
  async listEvaluationCriteria(agentId, opts = {}) {
1305
- return await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1398
+ return (await this.listEvaluationCriteriaPage(agentId, opts)).data ?? [];
1399
+ }
1400
+ /**
1401
+ * List evaluation criteria for an agent, with pagination metadata.
1402
+ *
1403
+ * Accepts either wire shape. The endpoint answered with a bare array before
1404
+ * 2026-07 and with a paginated envelope after, so a client that decodes only
1405
+ * one breaks the day the other ships. `total`, `page` and `limit` are absent
1406
+ * when the endpoint answers with a bare array.
1407
+ *
1408
+ * @param agentId - Agent identifier.
1409
+ * @param opts - Pagination options.
1410
+ * @returns The criteria under `data`, plus the page metadata when present.
1411
+ */
1412
+ async listEvaluationCriteriaPage(agentId, opts = {}) {
1413
+ const res = await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1306
1414
  query: { page: opts.page, limit: opts.limit }
1307
1415
  });
1416
+ return Array.isArray(res) ? { data: res } : res;
1308
1417
  }
1309
1418
  /**
1310
1419
  * Create evaluation criteria for an agent.
@@ -1758,7 +1867,7 @@ var Seclai = class {
1758
1867
  * @returns Paginated list of sources.
1759
1868
  */
1760
1869
  async listSources(opts = {}) {
1761
- return await this.request("GET", "/sources/", {
1870
+ return await this.request("GET", "/sources", {
1762
1871
  query: {
1763
1872
  page: opts.page,
1764
1873
  limit: opts.limit,
@@ -1827,6 +1936,55 @@ var Seclai = class {
1827
1936
  async uploadInlineTextToSource(sourceId, body) {
1828
1937
  return await this.request("POST", `/sources/${sourceId}`, { json: body });
1829
1938
  }
1939
+ /**
1940
+ * List a source's content items and their indexing status.
1941
+ *
1942
+ * @param sourceId - Source connection identifier.
1943
+ * @param opts - Pagination, sorting, and filters. Pass the `content_version_id`
1944
+ * values the upload methods return as `contentVersionIds` to poll a batch of
1945
+ * uploads in one request — about 100 at a time, since the ids travel in the
1946
+ * query string and a URL over 8,192 bytes is rejected with a 414. An empty
1947
+ * `contentVersionIds` matches nothing, so it returns an empty page without
1948
+ * sending a request.
1949
+ * @returns The items under `data` with `pagination`, on every API version.
1950
+ */
1951
+ async listSourceContents(sourceId, opts = {}) {
1952
+ if (opts.contentVersionIds?.length === 0) {
1953
+ return {
1954
+ data: [],
1955
+ pagination: {
1956
+ page: opts.page ?? 1,
1957
+ limit: opts.limit ?? 20,
1958
+ total: 0,
1959
+ pages: 0,
1960
+ has_next: false,
1961
+ has_prev: false
1962
+ }
1963
+ };
1964
+ }
1965
+ return await this.request("GET", `/sources/${sourceId}/contents`, {
1966
+ query: {
1967
+ page: opts.page,
1968
+ limit: opts.limit,
1969
+ sort: opts.sort,
1970
+ order: opts.order,
1971
+ status: opts.status,
1972
+ content_version_id: opts.contentVersionIds
1973
+ }
1974
+ });
1975
+ }
1976
+ /**
1977
+ * Get one content item's indexing status.
1978
+ *
1979
+ * @param sourceId - Source connection identifier.
1980
+ * @param contentVersionId - The `content_version_id` an upload returned.
1981
+ */
1982
+ async getSourceContentStatus(sourceId, contentVersionId) {
1983
+ return await this.request(
1984
+ "GET",
1985
+ `/sources/${sourceId}/contents/${contentVersionId}`
1986
+ );
1987
+ }
1830
1988
  // ─── Source Exports ────────────────────────────────────────────────────────
1831
1989
  /**
1832
1990
  * List exports for a source.
@@ -2221,7 +2379,7 @@ var Seclai = class {
2221
2379
  */
2222
2380
  async listAlerts(opts = {}) {
2223
2381
  return await this.request("GET", "/alerts", {
2224
- query: { page: opts.page, limit: opts.limit, status: opts.status, severity: opts.severity }
2382
+ query: { page: opts.page, limit: opts.limit, status: opts.status }
2225
2383
  });
2226
2384
  }
2227
2385
  /**
@@ -2274,6 +2432,12 @@ var Seclai = class {
2274
2432
  * @param opts - Pagination options.
2275
2433
  * @returns Paginated list of alert configs.
2276
2434
  */
2435
+ /**
2436
+ * The configurations arrive under `configs` alongside `total` by default.
2437
+ * Once the caller opts in with `apiVersion` 2026-07-27 or later the endpoint
2438
+ * returns the canonical `{data, pagination}` envelope instead, so the
2439
+ * top-level key changes.
2440
+ */
2277
2441
  async listAlertConfigs(opts = {}) {
2278
2442
  return await this.request("GET", "/alerts/configs", {
2279
2443
  query: { page: opts.page, limit: opts.limit }
@@ -2345,8 +2509,10 @@ var Seclai = class {
2345
2509
  * @param opts - Pagination options.
2346
2510
  */
2347
2511
  async listModelAlerts(opts = {}) {
2512
+ const limit = opts.limit ?? 50;
2513
+ const offset = opts.page && opts.page > 1 ? (opts.page - 1) * limit : void 0;
2348
2514
  return await this.request("GET", "/models/alerts", {
2349
- query: { page: opts.page, limit: opts.limit }
2515
+ query: { offset, limit: opts.limit }
2350
2516
  });
2351
2517
  }
2352
2518
  /**
@@ -2415,6 +2581,31 @@ var Seclai = class {
2415
2581
  async getGenerationTiers() {
2416
2582
  return await this.request("GET", "/models/generation-tiers");
2417
2583
  }
2584
+ /**
2585
+ * List the embedding models a source can index with, and their pricing.
2586
+ *
2587
+ * The endpoint lists the embedders under `models` by default and under `data`
2588
+ * once the caller opts in with `apiVersion` 2026-07-27 or later; `models` is
2589
+ * populated on either, with the defaults and pricing beside it.
2590
+ *
2591
+ * @param opts.supportsInputMedia - Keep only embedders that can index this
2592
+ * input modality — a coarse kind (text, image, video, audio) or a full MIME.
2593
+ */
2594
+ async listEmbeddingModels(opts = {}) {
2595
+ return withModels(
2596
+ await this.request("GET", "/models/embedders", {
2597
+ query: { supports_input_media: opts.supportsInputMedia }
2598
+ })
2599
+ );
2600
+ }
2601
+ /**
2602
+ * List the reranker models a knowledge base can use, and their pricing.
2603
+ *
2604
+ * `models` is populated on either wire shape, as for {@link Seclai.listEmbeddingModels}.
2605
+ */
2606
+ async listRerankerModels() {
2607
+ return withModels(await this.request("GET", "/models/rerankers"));
2608
+ }
2418
2609
  // ═══════════════════════════════════════════════════════════════════════════
2419
2610
  // Model Playground Experiments
2420
2611
  // ═══════════════════════════════════════════════════════════════════════════
@@ -2464,6 +2655,88 @@ var Seclai = class {
2464
2655
  await this.request("DELETE", `/models/playground/experiments/${experimentId}`);
2465
2656
  }
2466
2657
  // ═══════════════════════════════════════════════════════════════════════════
2658
+ // Cloud Drives
2659
+ // ═══════════════════════════════════════════════════════════════════════════
2660
+ /**
2661
+ * List the cloud-drive providers this deployment has configured.
2662
+ *
2663
+ * @returns The providers, read from either wire shape.
2664
+ */
2665
+ async listCloudDriveProviders() {
2666
+ return listItems(await this.request("GET", "/cloud-drives/providers"));
2667
+ }
2668
+ /**
2669
+ * List the account's cloud-drive connections.
2670
+ *
2671
+ * @returns The connections, read from either wire shape.
2672
+ */
2673
+ async listCloudDrives() {
2674
+ return listItems(await this.request("GET", "/cloud-drives"));
2675
+ }
2676
+ /**
2677
+ * Get a cloud-drive connection.
2678
+ *
2679
+ * @param connectionId - Cloud-drive connection identifier.
2680
+ */
2681
+ async getCloudDrive(connectionId) {
2682
+ return await this.request("GET", `/cloud-drives/${connectionId}`);
2683
+ }
2684
+ /**
2685
+ * Update a cloud-drive connection.
2686
+ *
2687
+ * @param connectionId - Cloud-drive connection identifier.
2688
+ * @param body - Fields to change — `name` and/or `folder_path`.
2689
+ * @returns The updated connection.
2690
+ */
2691
+ async updateCloudDrive(connectionId, body) {
2692
+ return await this.request("PATCH", `/cloud-drives/${connectionId}`, { json: body });
2693
+ }
2694
+ /**
2695
+ * Disconnect a cloud-drive connection, keeping the connection itself.
2696
+ *
2697
+ * @param connectionId - Cloud-drive connection identifier.
2698
+ * @returns The connection in its disconnected state.
2699
+ */
2700
+ async disconnectCloudDrive(connectionId) {
2701
+ return await this.request("POST", `/cloud-drives/${connectionId}/disconnect`);
2702
+ }
2703
+ /**
2704
+ * Delete a cloud-drive connection.
2705
+ *
2706
+ * @param connectionId - Cloud-drive connection identifier.
2707
+ */
2708
+ async deleteCloudDrive(connectionId) {
2709
+ await this.request("DELETE", `/cloud-drives/${connectionId}`);
2710
+ }
2711
+ /**
2712
+ * List the agents that use a cloud-drive connection.
2713
+ *
2714
+ * @param connectionId - Cloud-drive connection identifier.
2715
+ * @returns The agents, read from either wire shape.
2716
+ */
2717
+ async getAgentsUsingCloudDrive(connectionId) {
2718
+ return listItems(
2719
+ await this.request("GET", `/cloud-drives/${connectionId}/agents`)
2720
+ );
2721
+ }
2722
+ /**
2723
+ * List the files a cloud-drive connection skipped, newest first.
2724
+ *
2725
+ * A skipped file fires no trigger, so this is where to look when an agent
2726
+ * did not run for a file.
2727
+ *
2728
+ * @param connectionId - Cloud-drive connection identifier.
2729
+ * @param opts.limit - Maximum number of rejections (1-200, default 50).
2730
+ * @returns The rejections with their reasons, read from either wire shape.
2731
+ */
2732
+ async listCloudDriveRejections(connectionId, opts = {}) {
2733
+ return listItems(
2734
+ await this.request("GET", `/cloud-drives/${connectionId}/rejections`, {
2735
+ query: { limit: opts.limit }
2736
+ })
2737
+ );
2738
+ }
2739
+ // ═══════════════════════════════════════════════════════════════════════════
2467
2740
  // Search
2468
2741
  // ═══════════════════════════════════════════════════════════════════════════
2469
2742
  /**
@@ -2702,18 +2975,20 @@ var Seclai = class {
2702
2975
  /**
2703
2976
  * Auto-paginate through a list endpoint.
2704
2977
  *
2705
- * Yields individual items from each page, automatically fetching the next page
2706
- * until all items have been returned.
2978
+ * Yields individual items from each page, fetching the next page until the
2979
+ * response reports there is none. A fetcher that answers with a bare array has
2980
+ * no further pages, so its items are yielded once.
2707
2981
  *
2708
2982
  * @param fetchPage - A function that fetches a single page given `{ page, limit }`.
2709
2983
  * @param opts - Page size (default: 50).
2984
+ * @throws {@link SeclaiError} When a page carries its items under neither `data` nor `items`.
2710
2985
  *
2711
2986
  * @example
2712
2987
  * ```ts
2713
2988
  * for await (const agent of client.paginate(
2714
2989
  * (opts) => client.listAgents(opts),
2715
2990
  * )) {
2716
- * console.log(agent);
2991
+ * console.log(agent.name);
2717
2992
  * }
2718
2993
  * ```
2719
2994
  */
@@ -2722,11 +2997,29 @@ var Seclai = class {
2722
2997
  let page = 1;
2723
2998
  while (true) {
2724
2999
  const result = await fetchPage({ page, limit });
2725
- for (const item of result.items) {
2726
- yield item;
3000
+ if (Array.isArray(result)) {
3001
+ yield* result;
3002
+ return;
3003
+ }
3004
+ const body = result ?? {};
3005
+ const items = "data" in body ? body.data ?? [] : body.items;
3006
+ if (!Array.isArray(items)) {
3007
+ throw new SeclaiError(
3008
+ "paginate() could not find the page's items: expected an array, or an object with a `data` or `items` array."
3009
+ );
2727
3010
  }
2728
- if (!result.pagination || result.items.length < limit || page >= result.pagination.total_pages) {
2729
- break;
3011
+ yield* items;
3012
+ const pagination = body.pagination;
3013
+ if (items.length === 0) return;
3014
+ if (!pagination) {
3015
+ if (typeof body.total !== "number") return;
3016
+ const pageSize = typeof body.limit === "number" && body.limit > 0 ? body.limit : limit;
3017
+ if (page * pageSize >= body.total) return;
3018
+ } else if (typeof pagination.has_next === "boolean") {
3019
+ if (!pagination.has_next) return;
3020
+ } else {
3021
+ const pages = pagination.pages ?? pagination.total_pages;
3022
+ if (items.length < limit || pages === void 0 || page >= pages) return;
2730
3023
  }
2731
3024
  page++;
2732
3025
  }
@@ -2740,6 +3033,7 @@ export {
2740
3033
  Seclai,
2741
3034
  SeclaiAPIStatusError,
2742
3035
  SeclaiAPIValidationError,
3036
+ SeclaiApiVersion,
2743
3037
  SeclaiConfigurationError,
2744
3038
  SeclaiError,
2745
3039
  SeclaiStreamingError,