@seclai/sdk 1.4.0 → 1.5.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,14 @@
1
+ // src/versions.ts
2
+ var SeclaiApiVersion = {
3
+ V2026_07_01: "2026-07-01",
4
+ V2026_07_27: "2026-07-27",
5
+ /** Baseline applied to an unpinned, header-less caller. */
6
+ Default: "2026-07-01",
7
+ /** Newest version known to this SDK release. May lag the server. */
8
+ Latest: "2026-07-27"
9
+ };
10
+ var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
11
+
1
12
  // src/errors.ts
2
13
  var SeclaiError = class extends Error {
3
14
  constructor(message) {
@@ -495,7 +506,23 @@ var Seclai = class {
495
506
  );
496
507
  }
497
508
  this.baseUrl = opts.baseUrl ?? getEnv2("SECLAI_API_URL") ?? SECLAI_API_URL;
498
- this.defaultHeaders = { ...opts.defaultHeaders ?? {} };
509
+ const merged = opts.apiVersion ? { "Seclai-Version": opts.apiVersion } : {};
510
+ let versionKey = opts.apiVersion ? "Seclai-Version" : void 0;
511
+ for (const [key, value] of Object.entries(opts.defaultHeaders ?? {})) {
512
+ for (const existing of Object.keys(merged)) {
513
+ if (existing.toLowerCase() === key.toLowerCase()) delete merged[existing];
514
+ }
515
+ merged[key] = value;
516
+ if (key.toLowerCase() === "seclai-version") versionKey = key;
517
+ }
518
+ const effectiveVersion = versionKey ? merged[versionKey] : void 0;
519
+ if (effectiveVersion && !opts.allowUnknownApiVersion && !KNOWN_API_VERSIONS.includes(effectiveVersion)) {
520
+ const via = versionKey === "Seclai-Version" && merged[versionKey] === opts.apiVersion ? "apiVersion" : `defaultHeaders['${versionKey}']`;
521
+ throw new SeclaiConfigurationError(
522
+ `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.`
523
+ );
524
+ }
525
+ this.defaultHeaders = merged;
499
526
  this.fetcher = fetcher;
500
527
  const accessTokenProvider = typeof opts.accessToken === "function" ? opts.accessToken : void 0;
501
528
  const accessTokenStatic = typeof opts.accessToken === "string" ? opts.accessToken : void 0;
@@ -713,6 +740,34 @@ var Seclai = class {
713
740
  return await this.request("GET", "/me");
714
741
  }
715
742
  // ═══════════════════════════════════════════════════════════════════════════
743
+ // API Version
744
+ // ═══════════════════════════════════════════════════════════════════════════
745
+ /**
746
+ * Read the API version this request resolved to, and the versions available.
747
+ *
748
+ * Resolution order is the `Seclai-Version` header, then the account pin, then
749
+ * the default — so `effective_version` reflects the client's `apiVersion`
750
+ * option when that is set.
751
+ *
752
+ * @returns The pinned, effective, default and latest versions.
753
+ */
754
+ async getApiVersion() {
755
+ return await this.request("GET", "/version");
756
+ }
757
+ /**
758
+ * Pin the account to a dated API version, or clear the pin.
759
+ *
760
+ * Owner/admin only. The pin applies to later header-less requests; a
761
+ * `Seclai-Version` header still overrides it, so `effective_version` in the
762
+ * response describes this request rather than the pin just written.
763
+ *
764
+ * @param version - A `YYYY-MM-DD` date to pin to, or `null` to clear the pin.
765
+ * @returns The updated version state.
766
+ */
767
+ async updateApiVersion(version) {
768
+ return await this.request("PUT", "/version", { json: { version } });
769
+ }
770
+ // ═══════════════════════════════════════════════════════════════════════════
716
771
  // Agents — CRUD
717
772
  // ═══════════════════════════════════════════════════════════════════════════
718
773
  /**
@@ -909,21 +964,29 @@ var Seclai = class {
909
964
  } : void 0);
910
965
  }
911
966
  /**
912
- * Delete an agent run.
967
+ * Cancel an agent run.
968
+ *
969
+ * @deprecated This never deleted anything — the endpoint it calls is documented
970
+ * as "Cancel an agent run", and the API has no delete-a-run operation. It also
971
+ * discards the returned run state. Use {@link cancelAgentRun} instead.
913
972
  *
914
973
  * @param runId - Run identifier.
915
974
  */
916
975
  async deleteAgentRun(runId) {
917
- await this.request("DELETE", `/agents/runs/${runId}`);
976
+ await this.cancelAgentRun(runId);
918
977
  }
919
978
  /**
920
979
  * Cancel a running agent run.
921
980
  *
981
+ * Cancellation is `DELETE` on the run resource — the API exposes no
982
+ * `POST .../cancel` route, and no operation that deletes a run. Rejected when
983
+ * the run has already reached a terminal state.
984
+ *
922
985
  * @param runId - Run identifier.
923
986
  * @returns Updated run (with cancelled status).
924
987
  */
925
988
  async cancelAgentRun(runId) {
926
- return await this.request("POST", `/agents/runs/${runId}/cancel`);
989
+ return await this.request("DELETE", `/agents/runs/${runId}`);
927
990
  }
928
991
  // ═══════════════════════════════════════════════════════════════════════════
929
992
  // Agent Runs — Streaming
@@ -1189,9 +1252,10 @@ var Seclai = class {
1189
1252
  * @returns Paginated list of evaluation results.
1190
1253
  */
1191
1254
  async listRunEvaluationResults(agentId, runId, opts = {}) {
1192
- return await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1255
+ const res = await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1193
1256
  query: { page: opts.page, limit: opts.limit }
1194
1257
  });
1258
+ return Array.isArray(res) ? { data: res } : res;
1195
1259
  }
1196
1260
  // ═══════════════════════════════════════════════════════════════════════════
1197
1261
  // Agent Input Uploads
@@ -1279,8 +1343,20 @@ var Seclai = class {
1279
1343
  * @param agentId - Agent identifier.
1280
1344
  * @returns Conversation history.
1281
1345
  */
1282
- async getAgentAiConversationHistory(agentId) {
1283
- return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`);
1346
+ async getAgentAiConversationHistory(agentId, opts = {}) {
1347
+ if (!opts.stepType) {
1348
+ throw new SeclaiConfigurationError(
1349
+ 'getAgentAiConversationHistory requires opts.stepType; the API rejects the request without it. Pass e.g. { stepType: "llm" }.'
1350
+ );
1351
+ }
1352
+ return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`, {
1353
+ query: {
1354
+ step_type: opts.stepType,
1355
+ step_id: opts.stepId,
1356
+ limit: opts.limit,
1357
+ offset: opts.offset
1358
+ }
1359
+ });
1284
1360
  }
1285
1361
  /**
1286
1362
  * Mark an AI suggestion as accepted or rejected.
@@ -1302,9 +1378,25 @@ var Seclai = class {
1302
1378
  * @param opts - Pagination options.
1303
1379
  */
1304
1380
  async listEvaluationCriteria(agentId, opts = {}) {
1305
- return await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1381
+ return (await this.listEvaluationCriteriaPage(agentId, opts)).data ?? [];
1382
+ }
1383
+ /**
1384
+ * List evaluation criteria for an agent, with pagination metadata.
1385
+ *
1386
+ * Accepts either wire shape. The endpoint answered with a bare array before
1387
+ * 2026-07 and with a paginated envelope after, so a client that decodes only
1388
+ * one breaks the day the other ships. `total`, `page` and `limit` are absent
1389
+ * when the endpoint answers with a bare array.
1390
+ *
1391
+ * @param agentId - Agent identifier.
1392
+ * @param opts - Pagination options.
1393
+ * @returns The criteria under `data`, plus the page metadata when present.
1394
+ */
1395
+ async listEvaluationCriteriaPage(agentId, opts = {}) {
1396
+ const res = await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1306
1397
  query: { page: opts.page, limit: opts.limit }
1307
1398
  });
1399
+ return Array.isArray(res) ? { data: res } : res;
1308
1400
  }
1309
1401
  /**
1310
1402
  * Create evaluation criteria for an agent.
@@ -1758,7 +1850,7 @@ var Seclai = class {
1758
1850
  * @returns Paginated list of sources.
1759
1851
  */
1760
1852
  async listSources(opts = {}) {
1761
- return await this.request("GET", "/sources/", {
1853
+ return await this.request("GET", "/sources", {
1762
1854
  query: {
1763
1855
  page: opts.page,
1764
1856
  limit: opts.limit,
@@ -2221,7 +2313,7 @@ var Seclai = class {
2221
2313
  */
2222
2314
  async listAlerts(opts = {}) {
2223
2315
  return await this.request("GET", "/alerts", {
2224
- query: { page: opts.page, limit: opts.limit, status: opts.status, severity: opts.severity }
2316
+ query: { page: opts.page, limit: opts.limit, status: opts.status }
2225
2317
  });
2226
2318
  }
2227
2319
  /**
@@ -2274,6 +2366,12 @@ var Seclai = class {
2274
2366
  * @param opts - Pagination options.
2275
2367
  * @returns Paginated list of alert configs.
2276
2368
  */
2369
+ /**
2370
+ * The configurations arrive under `configs` alongside `total` by default.
2371
+ * Once the caller opts in with `apiVersion` 2026-07-27 or later the endpoint
2372
+ * returns the canonical `{data, pagination}` envelope instead, so the
2373
+ * top-level key changes.
2374
+ */
2277
2375
  async listAlertConfigs(opts = {}) {
2278
2376
  return await this.request("GET", "/alerts/configs", {
2279
2377
  query: { page: opts.page, limit: opts.limit }
@@ -2345,8 +2443,10 @@ var Seclai = class {
2345
2443
  * @param opts - Pagination options.
2346
2444
  */
2347
2445
  async listModelAlerts(opts = {}) {
2446
+ const limit = opts.limit ?? 50;
2447
+ const offset = opts.page && opts.page > 1 ? (opts.page - 1) * limit : void 0;
2348
2448
  return await this.request("GET", "/models/alerts", {
2349
- query: { page: opts.page, limit: opts.limit }
2449
+ query: { offset, limit: opts.limit }
2350
2450
  });
2351
2451
  }
2352
2452
  /**
@@ -2740,6 +2840,7 @@ export {
2740
2840
  Seclai,
2741
2841
  SeclaiAPIStatusError,
2742
2842
  SeclaiAPIValidationError,
2843
+ SeclaiApiVersion,
2743
2844
  SeclaiConfigurationError,
2744
2845
  SeclaiError,
2745
2846
  SeclaiStreamingError,