@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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.0] - 2026-07-27
4
+
5
+ ### Changed
6
+
7
+ - Return typed results from the 20 methods that previously declared `unknown` — alerts, alert configs, model alerts and recommendations, playground experiments, search and the AI assistant acknowledgements. Narrowing `unknown` to a concrete type is source compatible, so no façade is needed here
8
+ - Stop sending `severity` from `listAlerts()`. `GET /alerts` declares no such filter, so it never filtered, and it becomes a 422 once `apiVersion` is `2026-07-27` or later. The option is still accepted and ignored
9
+ - Accept either wire shape from `listEvaluationCriteria()`. The endpoint is moving from a bare array to a paginated envelope, so the client now reads both and keeps returning `EvaluationCriteriaResponse[]`
10
+ - Sync the bundled OpenAPI spec with the API fixes found while updating the SDKs: `agent_id` is now declared on the non-manual evaluation summary, and `page`/`limit` on the evaluation and alert-config listings
11
+ - Deprecate `deleteAgentRun()`. It never deleted anything — the endpoint it calls is documented as "Cancel an agent run", and the API has no delete-a-run operation. Use `cancelAgentRun()`
12
+
13
+ ### Added
14
+
15
+ - Add the `SeclaiApiVersion` constants and the `ApiVersion` type. An `apiVersion` this release was not built against throws at construction, since a newer version can reshape responses this client would mis-decode; set `allowUnknownApiVersion` to override
16
+ - Add 20 response type exports covering those endpoints, including `AlertResponse`, `AlertDetailResponse`, `AlertConfigResponse`, `ModelAlertResponse`, `ExperimentDetailResponse`, `SearchResponse` and `OkResponse`
17
+ - Add `listEvaluationCriteriaPage()` for the canonical `{data, pagination}` envelope, which the endpoint emits once `apiVersion` is `2026-07-27` or later
18
+ - Add an `apiVersion` client option, sent as the `Seclai-Version` header, opting into dated API changes released on or before that date. Omitted by default, so upgrading the SDK alone never changes response shapes
19
+ - Add `getApiVersion()` and `updateApiVersion()` to read the version a request resolves to and to pin or clear the account's version
20
+ - Add the `ApiVersionResponse` type export
21
+ - Add the `EvaluationCriteriaListResponse` type export
22
+
23
+ ### Fixed
24
+
25
+ - Validate the merged `Seclai-Version` rather than the first match in `defaultHeaders`. The merge lets the last entry win, so two spellings of the header meant the guard could approve one value and the client send another
26
+ - Validate a `Seclai-Version` supplied through `defaultHeaders`, not just the `apiVersion` option. `defaultHeaders` is applied last so it wins, which left the unknown-version guard one header away from being bypassed; a differently-cased key also emitted two wire headers
27
+ - Throw from `getAgentAiConversationHistory()` when `opts.stepType` is missing. It was optional and dropped by `buildURL`, so a call without it still 422'd — the failure this method was changed to prevent
28
+ - Decode either wire shape in `listRunEvaluationResults()`. The endpoint answers with a bare array, which the declared envelope type could not read, so the method returned nothing; it now also reads the canonical `{data, pagination}` envelope. `listAgentEvaluationResults()` is genuinely flat and is unaffected
29
+ - Paginate `listModelAlerts()` with the `offset` the endpoint declares instead of `page`, which it does not accept — every page after the first returned page 1
30
+ - Send `step_type` from `getAgentAiConversationHistory()`, along with `stepId`, `limit` and `offset`. The API marks `step_type` required and the method had no way to supply it, so every call answered 422
31
+ - Request `GET /sources` rather than `GET /sources/`. The trailing-slash form is no longer declared by the API
32
+ - Point `cancelAgentRun()` at `DELETE /agents/runs/{run_id}`. It posted to `/agents/runs/{run_id}/cancel`, a path the API has never exposed, so cancelling a run always failed
33
+
3
34
  ## [1.4.0] - 2026-07-25
4
35
 
5
36
  ### Changed
@@ -154,6 +185,7 @@ _Stable release. No functional changes since 0.0.1._
154
185
 
155
186
  _Initial release._
156
187
 
188
+ [1.5.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.5.0
157
189
  [1.4.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.4.0
158
190
  [1.3.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.3.0
159
191
  [1.2.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.2.0
package/README.md CHANGED
@@ -104,10 +104,58 @@ or set environment variables:
104
104
 
105
105
  Online API documentation (latest):
106
106
 
107
- https://seclai.github.io/seclai-javascript/1.4.0/
107
+ https://seclai.github.io/seclai-javascript/1.5.0/
108
108
 
109
109
  Release history is in [`CHANGELOG.md`](CHANGELOG.md).
110
110
 
111
+ ## API versioning
112
+
113
+ The API dates its backward-incompatible changes. Nothing changes for you until
114
+ you opt in, either per client or by pinning the account:
115
+
116
+ ```ts
117
+ const client = new Seclai({
118
+ apiKey: "...",
119
+ apiVersion: SeclaiApiVersion.V2026_07_27, // sent as the Seclai-Version header
120
+ });
121
+
122
+ const state = await client.getApiVersion(); // what this request resolved to
123
+ await client.updateApiVersion(SeclaiApiVersion.V2026_07_27); // pin the whole account
124
+ ```
125
+
126
+ Leave `apiVersion` unset and the header is omitted, so the account's pinned
127
+ baseline applies and responses keep their current shapes. Upgrading this package
128
+ alone never changes the wire contract.
129
+
130
+ Known versions are on `SeclaiApiVersion` (`V2026_07_01`, `V2026_07_27`, plus
131
+ `Default` and `Latest`), imported from `@seclai/sdk`. A version this release was
132
+ **not** built against throws at construction: a newer version can reshape
133
+ responses, and this client would decode them incorrectly rather than reject them.
134
+ Upgrade the package to adopt a new version, or set `allowUnknownApiVersion` if
135
+ you have to move first and accept that risk.
136
+
137
+ The guard only covers the header. An account pinned server-side can still be
138
+ newer than this release — `getApiVersion()` reports the `effective_version` the
139
+ request resolved to, and comparing it against `SeclaiApiVersion.Latest` is how
140
+ you detect the gap.
141
+
142
+ **What `2026-07-27` changes.** Undeclared query parameters become a 422 instead
143
+ of being ignored, and list endpoints move to the canonical `{data, pagination}`
144
+ envelope. The affected methods read both shapes, so they keep working either way
145
+ — but the metadata moves:
146
+
147
+ | Method | Before | From 2026-07-27 |
148
+ | --- | --- | --- |
149
+ | `listEvaluationCriteriaPage()` | bare array | `data` + `pagination` |
150
+ | `listRunEvaluationResults()` | bare array | `data` + `pagination` |
151
+ | `listAlertConfigs()` | `configs` + `total` | `data` + `pagination` |
152
+ | `listModelAlerts()` | `alerts` + `total` | `data` + `pagination` |
153
+
154
+ Prefer `pagination` over the flat `total`/`page`/`limit` properties, and read the
155
+ last two with `res.data ?? res.configs` / `res.data ?? res.alerts`. The legacy
156
+ keys will be deprecated and then removed once the canonical envelope is the
157
+ default.
158
+
111
159
  ## Resources
112
160
 
113
161
  ### Identity
@@ -302,7 +350,10 @@ await client.markAgentAiSuggestion("agent_id", "conversation_id", { accepted: tr
302
350
  ### Agent evaluations
303
351
 
304
352
  ```ts
305
- const criteria = await client.listEvaluationCriteria("agent_id");
353
+ const criteria = await client.listEvaluationCriteria("agent_id", { page: 1, limit: 50 });
354
+ // page/limit only take effect with apiVersion "2026-07-27" or later; the legacy
355
+ // response is unpaginated. listEvaluationCriteriaPage() returns the same items
356
+ // plus a `pagination` object when opted in.
306
357
  const created = await client.createEvaluationCriteria("agent_id", { name: "Accuracy", ... });
307
358
  const detail = await client.getEvaluationCriteria("criteria_id");
308
359
  await client.updateEvaluationCriteria("criteria_id", { ... });
@@ -569,6 +620,7 @@ Send and receive agent email on your own domain instead of the shared
569
620
  `agent.seclai.com`. These endpoints require a user-bound credential (an
570
621
  account-only API key is refused with 403) and, for mutations, an account owner/admin.
571
622
 
623
+ <!-- sdksync:check -->
572
624
  ```ts
573
625
  // Current domains, their DNS records, and what your plan allows
574
626
  const { domains, can_add_custom, has_custom } = await client.listEmailDomains();
package/dist/index.cjs CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  Seclai: () => Seclai,
38
38
  SeclaiAPIStatusError: () => SeclaiAPIStatusError,
39
39
  SeclaiAPIValidationError: () => SeclaiAPIValidationError,
40
+ SeclaiApiVersion: () => SeclaiApiVersion,
40
41
  SeclaiConfigurationError: () => SeclaiConfigurationError,
41
42
  SeclaiError: () => SeclaiError,
42
43
  SeclaiStreamingError: () => SeclaiStreamingError,
@@ -48,6 +49,17 @@ __export(index_exports, {
48
49
  });
49
50
  module.exports = __toCommonJS(index_exports);
50
51
 
52
+ // src/versions.ts
53
+ var SeclaiApiVersion = {
54
+ V2026_07_01: "2026-07-01",
55
+ V2026_07_27: "2026-07-27",
56
+ /** Baseline applied to an unpinned, header-less caller. */
57
+ Default: "2026-07-01",
58
+ /** Newest version known to this SDK release. May lag the server. */
59
+ Latest: "2026-07-27"
60
+ };
61
+ var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
62
+
51
63
  // src/errors.ts
52
64
  var SeclaiError = class extends Error {
53
65
  constructor(message) {
@@ -545,7 +557,23 @@ var Seclai = class {
545
557
  );
546
558
  }
547
559
  this.baseUrl = opts.baseUrl ?? getEnv2("SECLAI_API_URL") ?? SECLAI_API_URL;
548
- this.defaultHeaders = { ...opts.defaultHeaders ?? {} };
560
+ const merged = opts.apiVersion ? { "Seclai-Version": opts.apiVersion } : {};
561
+ let versionKey = opts.apiVersion ? "Seclai-Version" : void 0;
562
+ for (const [key, value] of Object.entries(opts.defaultHeaders ?? {})) {
563
+ for (const existing of Object.keys(merged)) {
564
+ if (existing.toLowerCase() === key.toLowerCase()) delete merged[existing];
565
+ }
566
+ merged[key] = value;
567
+ if (key.toLowerCase() === "seclai-version") versionKey = key;
568
+ }
569
+ const effectiveVersion = versionKey ? merged[versionKey] : void 0;
570
+ if (effectiveVersion && !opts.allowUnknownApiVersion && !KNOWN_API_VERSIONS.includes(effectiveVersion)) {
571
+ const via = versionKey === "Seclai-Version" && merged[versionKey] === opts.apiVersion ? "apiVersion" : `defaultHeaders['${versionKey}']`;
572
+ throw new SeclaiConfigurationError(
573
+ `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.`
574
+ );
575
+ }
576
+ this.defaultHeaders = merged;
549
577
  this.fetcher = fetcher;
550
578
  const accessTokenProvider = typeof opts.accessToken === "function" ? opts.accessToken : void 0;
551
579
  const accessTokenStatic = typeof opts.accessToken === "string" ? opts.accessToken : void 0;
@@ -763,6 +791,34 @@ var Seclai = class {
763
791
  return await this.request("GET", "/me");
764
792
  }
765
793
  // ═══════════════════════════════════════════════════════════════════════════
794
+ // API Version
795
+ // ═══════════════════════════════════════════════════════════════════════════
796
+ /**
797
+ * Read the API version this request resolved to, and the versions available.
798
+ *
799
+ * Resolution order is the `Seclai-Version` header, then the account pin, then
800
+ * the default — so `effective_version` reflects the client's `apiVersion`
801
+ * option when that is set.
802
+ *
803
+ * @returns The pinned, effective, default and latest versions.
804
+ */
805
+ async getApiVersion() {
806
+ return await this.request("GET", "/version");
807
+ }
808
+ /**
809
+ * Pin the account to a dated API version, or clear the pin.
810
+ *
811
+ * Owner/admin only. The pin applies to later header-less requests; a
812
+ * `Seclai-Version` header still overrides it, so `effective_version` in the
813
+ * response describes this request rather than the pin just written.
814
+ *
815
+ * @param version - A `YYYY-MM-DD` date to pin to, or `null` to clear the pin.
816
+ * @returns The updated version state.
817
+ */
818
+ async updateApiVersion(version) {
819
+ return await this.request("PUT", "/version", { json: { version } });
820
+ }
821
+ // ═══════════════════════════════════════════════════════════════════════════
766
822
  // Agents — CRUD
767
823
  // ═══════════════════════════════════════════════════════════════════════════
768
824
  /**
@@ -959,21 +1015,29 @@ var Seclai = class {
959
1015
  } : void 0);
960
1016
  }
961
1017
  /**
962
- * Delete an agent run.
1018
+ * Cancel an agent run.
1019
+ *
1020
+ * @deprecated This never deleted anything — the endpoint it calls is documented
1021
+ * as "Cancel an agent run", and the API has no delete-a-run operation. It also
1022
+ * discards the returned run state. Use {@link cancelAgentRun} instead.
963
1023
  *
964
1024
  * @param runId - Run identifier.
965
1025
  */
966
1026
  async deleteAgentRun(runId) {
967
- await this.request("DELETE", `/agents/runs/${runId}`);
1027
+ await this.cancelAgentRun(runId);
968
1028
  }
969
1029
  /**
970
1030
  * Cancel a running agent run.
971
1031
  *
1032
+ * Cancellation is `DELETE` on the run resource — the API exposes no
1033
+ * `POST .../cancel` route, and no operation that deletes a run. Rejected when
1034
+ * the run has already reached a terminal state.
1035
+ *
972
1036
  * @param runId - Run identifier.
973
1037
  * @returns Updated run (with cancelled status).
974
1038
  */
975
1039
  async cancelAgentRun(runId) {
976
- return await this.request("POST", `/agents/runs/${runId}/cancel`);
1040
+ return await this.request("DELETE", `/agents/runs/${runId}`);
977
1041
  }
978
1042
  // ═══════════════════════════════════════════════════════════════════════════
979
1043
  // Agent Runs — Streaming
@@ -1239,9 +1303,10 @@ var Seclai = class {
1239
1303
  * @returns Paginated list of evaluation results.
1240
1304
  */
1241
1305
  async listRunEvaluationResults(agentId, runId, opts = {}) {
1242
- return await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1306
+ const res = await this.request("GET", `/agents/${agentId}/runs/${runId}/evaluation-results`, {
1243
1307
  query: { page: opts.page, limit: opts.limit }
1244
1308
  });
1309
+ return Array.isArray(res) ? { data: res } : res;
1245
1310
  }
1246
1311
  // ═══════════════════════════════════════════════════════════════════════════
1247
1312
  // Agent Input Uploads
@@ -1329,8 +1394,20 @@ var Seclai = class {
1329
1394
  * @param agentId - Agent identifier.
1330
1395
  * @returns Conversation history.
1331
1396
  */
1332
- async getAgentAiConversationHistory(agentId) {
1333
- return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`);
1397
+ async getAgentAiConversationHistory(agentId, opts = {}) {
1398
+ if (!opts.stepType) {
1399
+ throw new SeclaiConfigurationError(
1400
+ 'getAgentAiConversationHistory requires opts.stepType; the API rejects the request without it. Pass e.g. { stepType: "llm" }.'
1401
+ );
1402
+ }
1403
+ return await this.request("GET", `/agents/${agentId}/ai-assistant/conversations`, {
1404
+ query: {
1405
+ step_type: opts.stepType,
1406
+ step_id: opts.stepId,
1407
+ limit: opts.limit,
1408
+ offset: opts.offset
1409
+ }
1410
+ });
1334
1411
  }
1335
1412
  /**
1336
1413
  * Mark an AI suggestion as accepted or rejected.
@@ -1352,9 +1429,25 @@ var Seclai = class {
1352
1429
  * @param opts - Pagination options.
1353
1430
  */
1354
1431
  async listEvaluationCriteria(agentId, opts = {}) {
1355
- return await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1432
+ return (await this.listEvaluationCriteriaPage(agentId, opts)).data ?? [];
1433
+ }
1434
+ /**
1435
+ * List evaluation criteria for an agent, with pagination metadata.
1436
+ *
1437
+ * Accepts either wire shape. The endpoint answered with a bare array before
1438
+ * 2026-07 and with a paginated envelope after, so a client that decodes only
1439
+ * one breaks the day the other ships. `total`, `page` and `limit` are absent
1440
+ * when the endpoint answers with a bare array.
1441
+ *
1442
+ * @param agentId - Agent identifier.
1443
+ * @param opts - Pagination options.
1444
+ * @returns The criteria under `data`, plus the page metadata when present.
1445
+ */
1446
+ async listEvaluationCriteriaPage(agentId, opts = {}) {
1447
+ const res = await this.request("GET", `/agents/${agentId}/evaluation-criteria`, {
1356
1448
  query: { page: opts.page, limit: opts.limit }
1357
1449
  });
1450
+ return Array.isArray(res) ? { data: res } : res;
1358
1451
  }
1359
1452
  /**
1360
1453
  * Create evaluation criteria for an agent.
@@ -1808,7 +1901,7 @@ var Seclai = class {
1808
1901
  * @returns Paginated list of sources.
1809
1902
  */
1810
1903
  async listSources(opts = {}) {
1811
- return await this.request("GET", "/sources/", {
1904
+ return await this.request("GET", "/sources", {
1812
1905
  query: {
1813
1906
  page: opts.page,
1814
1907
  limit: opts.limit,
@@ -2271,7 +2364,7 @@ var Seclai = class {
2271
2364
  */
2272
2365
  async listAlerts(opts = {}) {
2273
2366
  return await this.request("GET", "/alerts", {
2274
- query: { page: opts.page, limit: opts.limit, status: opts.status, severity: opts.severity }
2367
+ query: { page: opts.page, limit: opts.limit, status: opts.status }
2275
2368
  });
2276
2369
  }
2277
2370
  /**
@@ -2324,6 +2417,12 @@ var Seclai = class {
2324
2417
  * @param opts - Pagination options.
2325
2418
  * @returns Paginated list of alert configs.
2326
2419
  */
2420
+ /**
2421
+ * The configurations arrive under `configs` alongside `total` by default.
2422
+ * Once the caller opts in with `apiVersion` 2026-07-27 or later the endpoint
2423
+ * returns the canonical `{data, pagination}` envelope instead, so the
2424
+ * top-level key changes.
2425
+ */
2327
2426
  async listAlertConfigs(opts = {}) {
2328
2427
  return await this.request("GET", "/alerts/configs", {
2329
2428
  query: { page: opts.page, limit: opts.limit }
@@ -2395,8 +2494,10 @@ var Seclai = class {
2395
2494
  * @param opts - Pagination options.
2396
2495
  */
2397
2496
  async listModelAlerts(opts = {}) {
2497
+ const limit = opts.limit ?? 50;
2498
+ const offset = opts.page && opts.page > 1 ? (opts.page - 1) * limit : void 0;
2398
2499
  return await this.request("GET", "/models/alerts", {
2399
- query: { page: opts.page, limit: opts.limit }
2500
+ query: { offset, limit: opts.limit }
2400
2501
  });
2401
2502
  }
2402
2503
  /**
@@ -2791,6 +2892,7 @@ var Seclai = class {
2791
2892
  Seclai,
2792
2893
  SeclaiAPIStatusError,
2793
2894
  SeclaiAPIValidationError,
2895
+ SeclaiApiVersion,
2794
2896
  SeclaiConfigurationError,
2795
2897
  SeclaiError,
2796
2898
  SeclaiStreamingError,