@seclai/sdk 1.5.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
@@ -2,10 +2,15 @@
2
2
  var SeclaiApiVersion = {
3
3
  V2026_07_01: "2026-07-01",
4
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",
5
10
  /** Baseline applied to an unpinned, header-less caller. */
6
11
  Default: "2026-07-01",
7
12
  /** Newest version known to this SDK release. May lag the server. */
8
- Latest: "2026-07-27"
13
+ Latest: "2026-10-03"
9
14
  };
10
15
  var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
11
16
 
@@ -356,11 +361,23 @@ function buildURL(baseUrl, path, query) {
356
361
  if (query) {
357
362
  for (const [key, value] of Object.entries(query)) {
358
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
+ }
359
368
  url.searchParams.set(key, String(value));
360
369
  }
361
370
  }
362
371
  return url;
363
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
+ }
364
381
  async function safeText(response) {
365
382
  try {
366
383
  return await response.clone().text();
@@ -1919,6 +1936,55 @@ var Seclai = class {
1919
1936
  async uploadInlineTextToSource(sourceId, body) {
1920
1937
  return await this.request("POST", `/sources/${sourceId}`, { json: body });
1921
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
+ }
1922
1988
  // ─── Source Exports ────────────────────────────────────────────────────────
1923
1989
  /**
1924
1990
  * List exports for a source.
@@ -2515,6 +2581,31 @@ var Seclai = class {
2515
2581
  async getGenerationTiers() {
2516
2582
  return await this.request("GET", "/models/generation-tiers");
2517
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
+ }
2518
2609
  // ═══════════════════════════════════════════════════════════════════════════
2519
2610
  // Model Playground Experiments
2520
2611
  // ═══════════════════════════════════════════════════════════════════════════
@@ -2564,6 +2655,88 @@ var Seclai = class {
2564
2655
  await this.request("DELETE", `/models/playground/experiments/${experimentId}`);
2565
2656
  }
2566
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
+ // ═══════════════════════════════════════════════════════════════════════════
2567
2740
  // Search
2568
2741
  // ═══════════════════════════════════════════════════════════════════════════
2569
2742
  /**
@@ -2802,18 +2975,20 @@ var Seclai = class {
2802
2975
  /**
2803
2976
  * Auto-paginate through a list endpoint.
2804
2977
  *
2805
- * Yields individual items from each page, automatically fetching the next page
2806
- * 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.
2807
2981
  *
2808
2982
  * @param fetchPage - A function that fetches a single page given `{ page, limit }`.
2809
2983
  * @param opts - Page size (default: 50).
2984
+ * @throws {@link SeclaiError} When a page carries its items under neither `data` nor `items`.
2810
2985
  *
2811
2986
  * @example
2812
2987
  * ```ts
2813
2988
  * for await (const agent of client.paginate(
2814
2989
  * (opts) => client.listAgents(opts),
2815
2990
  * )) {
2816
- * console.log(agent);
2991
+ * console.log(agent.name);
2817
2992
  * }
2818
2993
  * ```
2819
2994
  */
@@ -2822,11 +2997,29 @@ var Seclai = class {
2822
2997
  let page = 1;
2823
2998
  while (true) {
2824
2999
  const result = await fetchPage({ page, limit });
2825
- for (const item of result.items) {
2826
- 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
+ );
2827
3010
  }
2828
- if (!result.pagination || result.items.length < limit || page >= result.pagination.total_pages) {
2829
- 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;
2830
3023
  }
2831
3024
  page++;
2832
3025
  }