@seclai/sdk 1.8.0 → 1.10.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
@@ -65,10 +65,16 @@ var SeclaiApiVersion = {
65
65
  V2026_10_19: "2026-10-19",
66
66
  V2026_10_21: "2026-10-21",
67
67
  V2026_10_28: "2026-10-28",
68
+ V2026_11_02: "2026-11-02",
69
+ V2026_11_04: "2026-11-04",
70
+ V2026_11_08: "2026-11-08",
71
+ V2026_11_09: "2026-11-09",
72
+ V2026_11_14: "2026-11-14",
73
+ V2026_11_19: "2026-11-19",
68
74
  /** Baseline applied to an unpinned, header-less caller. */
69
75
  Default: "2026-07-01",
70
76
  /** Newest version known to this SDK release. May lag the server. */
71
- Latest: "2026-10-28"
77
+ Latest: "2026-11-19"
72
78
  };
73
79
  var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
74
80
 
@@ -94,6 +100,14 @@ var SeclaiAPIStatusError = class extends SeclaiError {
94
100
  url;
95
101
  /** Best-effort response body text (if available). */
96
102
  responseText;
103
+ /**
104
+ * Headers of the error response, such as `Retry-After` on a 503, or
105
+ * `Content-Range` on a 416 from a ranged `downloadAgentRunAttachment()`, whose
106
+ * value ends in `/<size>`, the file's size in bytes. Empty when the response
107
+ * headers are unknown. In a browser, only the headers the server's CORS policy
108
+ * exposes are present.
109
+ */
110
+ headers;
97
111
  constructor(opts) {
98
112
  super(opts.message);
99
113
  this.name = "SeclaiAPIStatusError";
@@ -101,6 +115,7 @@ var SeclaiAPIStatusError = class extends SeclaiError {
101
115
  this.method = opts.method;
102
116
  this.url = opts.url;
103
117
  this.responseText = opts.responseText;
118
+ this.headers = opts.headers ?? new Headers();
104
119
  }
105
120
  };
106
121
  var SeclaiAPIValidationError = class extends SeclaiAPIStatusError {
@@ -115,10 +130,17 @@ var SeclaiAPIValidationError = class extends SeclaiAPIStatusError {
115
130
  var SeclaiStreamingError = class extends SeclaiError {
116
131
  /** The run ID associated with the failed stream, when available. */
117
132
  runId;
118
- constructor(message, runId) {
133
+ /**
134
+ * Set by `runStreamingAgentAndWait()` and `runAgentAndPoll()` to the latest
135
+ * run they had, if any (when it has `result_reported_at` set, its `output`
136
+ * is the answer). The run may still be in progress, and can still fail.
137
+ */
138
+ run;
139
+ constructor(message, runId, run) {
119
140
  super(message);
120
141
  this.name = "SeclaiStreamingError";
121
142
  this.runId = runId;
143
+ this.run = run;
122
144
  }
123
145
  };
124
146
 
@@ -471,6 +493,34 @@ function mergeHeaders(...layers) {
471
493
  function headerKey(headers, name) {
472
494
  return Object.keys(headers ?? {}).filter((key) => key.toLowerCase() === name).pop();
473
495
  }
496
+ function byteRangeHeader(start, end, suffix) {
497
+ const hasStart = start !== void 0 && start !== null;
498
+ const hasEnd = end !== void 0 && end !== null;
499
+ const hasSuffix = suffix !== void 0 && suffix !== null;
500
+ if (!hasStart && !hasEnd && !hasSuffix) return void 0;
501
+ const fail = (why) => {
502
+ throw new SeclaiConfigurationError(`Invalid byte range: ${why}`);
503
+ };
504
+ if (hasSuffix) {
505
+ if (hasStart || hasEnd) fail("rangeSuffix cannot be combined with rangeStart or rangeEnd.");
506
+ if (!Number.isSafeInteger(suffix) || suffix < 1) {
507
+ fail(`rangeSuffix must be a whole number of at least 1, got ${String(suffix)}.`);
508
+ }
509
+ return `bytes=-${suffix}`;
510
+ }
511
+ if (!hasStart) fail("rangeEnd requires rangeStart; use rangeSuffix for the last bytes of the file.");
512
+ if (!Number.isSafeInteger(start) || start < 0) {
513
+ fail(`rangeStart must be a whole number of at least 0, got ${String(start)}.`);
514
+ }
515
+ if (!hasEnd) return `bytes=${start}-`;
516
+ if (!Number.isSafeInteger(end) || end < 0) {
517
+ fail(`rangeEnd must be a whole number of at least 0, got ${String(end)}.`);
518
+ }
519
+ if (end < start) {
520
+ fail(`rangeEnd (${end}) must not be less than rangeStart (${start}).`);
521
+ }
522
+ return `bytes=${start}-${end}`;
523
+ }
474
524
  async function safeText(response) {
475
525
  try {
476
526
  return await response.clone().text();
@@ -737,6 +787,7 @@ var Seclai = class {
737
787
  method,
738
788
  url: url.toString(),
739
789
  responseText,
790
+ headers: new Headers(response.headers),
740
791
  validationError: validation
741
792
  });
742
793
  }
@@ -745,7 +796,8 @@ var Seclai = class {
745
796
  statusCode: response.status,
746
797
  method,
747
798
  url: url.toString(),
748
- responseText
799
+ responseText,
800
+ headers: new Headers(response.headers)
749
801
  });
750
802
  }
751
803
  if (!response.body) return null;
@@ -792,6 +844,7 @@ var Seclai = class {
792
844
  method,
793
845
  url: url.toString(),
794
846
  responseText,
847
+ headers: new Headers(response.headers),
795
848
  validationError: validation
796
849
  });
797
850
  }
@@ -800,7 +853,8 @@ var Seclai = class {
800
853
  statusCode: response.status,
801
854
  method,
802
855
  url: url.toString(),
803
- responseText
856
+ responseText,
857
+ headers: new Headers(response.headers)
804
858
  });
805
859
  }
806
860
  return response;
@@ -831,6 +885,7 @@ var Seclai = class {
831
885
  method: "POST",
832
886
  url: url.toString(),
833
887
  responseText,
888
+ headers: new Headers(response.headers),
834
889
  validationError: validation
835
890
  });
836
891
  }
@@ -839,7 +894,8 @@ var Seclai = class {
839
894
  statusCode: response.status,
840
895
  method: "POST",
841
896
  url: url.toString(),
842
- responseText
897
+ responseText,
898
+ headers: new Headers(response.headers)
843
899
  });
844
900
  }
845
901
  return await response.json();
@@ -905,6 +961,10 @@ var Seclai = class {
905
961
  /**
906
962
  * List the agent gallery: example agents to start from.
907
963
  *
964
+ * From `apiVersion` `2026-11-09`, `query` describes what the agent should do
965
+ * and entries come back ranked by how well they match it, best first. Before
966
+ * it, only entries containing every word of `query` are returned.
967
+ *
908
968
  * Pass an entry's `key` as `agent_template` to {@link createAgent}, with
909
969
  * `resource_bindings` for the resources it needs.
910
970
  *
@@ -1058,6 +1118,11 @@ var Seclai = class {
1058
1118
  /**
1059
1119
  * Start an agent run.
1060
1120
  *
1121
+ * From `apiVersion` `2026-11-14`, an agent whose definition fails to validate
1122
+ * is refused with HTTP 409 ({@link SeclaiAPIStatusError}) and no run is
1123
+ * created; earlier versions return the run, already failed with the
1124
+ * validation error as its cause.
1125
+ *
1061
1126
  * @param agentId - Agent identifier.
1062
1127
  * @param body - Run request payload (`input`, `metadata`, `priority`, etc.).
1063
1128
  * @returns The created agent run.
@@ -1111,14 +1176,17 @@ var Seclai = class {
1111
1176
  await this.cancelAgentRun(runId);
1112
1177
  }
1113
1178
  /**
1114
- * Cancel a running agent run.
1179
+ * Cancel an agent run that has not ended: `queued`, `pending`, `processing`,
1180
+ * `waiting_human` or `waiting_scheduled`.
1115
1181
  *
1116
1182
  * Cancellation is `DELETE` on the run resource — the API exposes no
1117
1183
  * `POST .../cancel` route, and no operation that deletes a run. Rejected when
1118
- * the run has already reached a terminal state.
1184
+ * the run has already ended (`completed`, `failed` or `cancelled`). From
1185
+ * `apiVersion` `2026-11-08` the cancelled run ends with status `cancelled`;
1186
+ * on earlier versions it ends `failed`.
1119
1187
  *
1120
1188
  * @param runId - Run identifier.
1121
- * @returns Updated run (with cancelled status).
1189
+ * @returns The updated run.
1122
1190
  */
1123
1191
  async cancelAgentRun(runId) {
1124
1192
  return await this.request("DELETE", `/agents/runs/${runId}`);
@@ -1131,17 +1199,58 @@ var Seclai = class {
1131
1199
  *
1132
1200
  * Consumes the entire SSE stream and returns only the terminal `done` payload.
1133
1201
  * For real-time event access, use {@link runStreamingAgent} instead. The body
1134
- * takes no `include_reasoning`, and one passed anyway is not sent: this method
1135
- * returns no `stream_reasoning` events.
1202
+ * takes no `include_reasoning` or `include_commentary`, and one passed anyway
1203
+ * is not sent: this method returns no `stream_reasoning` or
1204
+ * `stream_commentary` events.
1205
+ *
1206
+ * A `result` event carries the run's answer in `output` once
1207
+ * `result_reported_at` is set, and can arrive while later steps still run.
1208
+ * Pass `returnOnResult: true` to return that `result` snapshot as soon as it
1209
+ * arrives, without waiting for `done`. Such a run may still be in progress:
1210
+ * its `status` is not terminal and the run can still fail, so check
1211
+ * `result_reported_at`, not `status`.
1212
+ *
1213
+ * If `timeoutMs` elapses, this throws {@link SeclaiStreamingError} with the
1214
+ * latest snapshot in `run`: the `result` snapshot if one arrived, else the
1215
+ * `init` snapshot. An abort from `signal` rethrows the abort error.
1216
+ *
1217
+ * By default, a stream that ends before `done` returns the latest snapshot
1218
+ * when its status is not `pending`, so the run returned may not have
1219
+ * finished: check `status` and `result_reported_at`. A stream that breaks
1220
+ * throws the fetch error. Pass `throwOnIncomplete: true` to throw
1221
+ * {@link SeclaiStreamingError} with the snapshot in `run` in both cases
1222
+ * instead; it is recommended, and becomes the default in the next major
1223
+ * version.
1136
1224
  *
1137
1225
  * @param agentId - Agent identifier.
1138
- * @param body - Streaming run request payload, without `include_reasoning`.
1139
- * @param opts - Timeout and abort signal options.
1140
- * @returns Final agent run payload from the `done` event.
1141
- * @throws {@link SeclaiStreamingError} If the stream ends before a `done` event.
1226
+ * @param body - Streaming run request payload, without `include_reasoning`
1227
+ * or `include_commentary`.
1228
+ * @param opts - Timeout, abort signal and `returnOnResult` options.
1229
+ * @returns The run from the `done` event; with `returnOnResult`, the
1230
+ * `result` snapshot; without `throwOnIncomplete`, possibly an unfinished
1231
+ * snapshot (see above).
1232
+ * @throws {@link SeclaiStreamingError} If `timeoutMs` elapses, or, with
1233
+ * `throwOnIncomplete`, the stream ends or breaks, before the run finished.
1234
+ * Its `run` holds the latest snapshot.
1235
+ *
1236
+ * @example
1237
+ * ```ts
1238
+ * try {
1239
+ * const run = await client.runStreamingAgentAndWait("agent-id", { input: "Hello" }, { throwOnIncomplete: true });
1240
+ * console.log(run.output);
1241
+ * } catch (err) {
1242
+ * if (err instanceof SeclaiStreamingError && err.run?.result_reported_at) {
1243
+ * console.log("Answer (run not finished):", err.run.output);
1244
+ * } else throw err;
1245
+ * }
1246
+ * ```
1142
1247
  */
1143
1248
  async runStreamingAgentAndWait(agentId, body, opts) {
1144
- const { include_reasoning: _ignored, ...runBody } = body;
1249
+ const {
1250
+ include_reasoning: _reasoning,
1251
+ include_commentary: _commentary,
1252
+ ...runBody
1253
+ } = body;
1145
1254
  const url = buildURL(this.baseUrl, `/agents/${agentId}/runs/stream`);
1146
1255
  const authHdrs = await this.authHeaders();
1147
1256
  const headers = this.requestHeaders([
@@ -1158,6 +1267,7 @@ var Seclai = class {
1158
1267
  }, timeoutMs);
1159
1268
  const signal = anySignal([opts?.signal, timeoutController.signal]);
1160
1269
  let lastSeen;
1270
+ let reported;
1161
1271
  try {
1162
1272
  const init = { method: "POST", headers, body: JSON.stringify(runBody) };
1163
1273
  if (signal) init.signal = signal;
@@ -1174,6 +1284,7 @@ var Seclai = class {
1174
1284
  method: "POST",
1175
1285
  url: url.toString(),
1176
1286
  responseText,
1287
+ headers: new Headers(response.headers),
1177
1288
  validationError: validation
1178
1289
  });
1179
1290
  }
@@ -1182,11 +1293,19 @@ var Seclai = class {
1182
1293
  statusCode: response.status,
1183
1294
  method: "POST",
1184
1295
  url: url.toString(),
1185
- responseText
1296
+ responseText,
1297
+ headers: new Headers(response.headers)
1186
1298
  });
1187
1299
  }
1188
1300
  if (isJson) {
1189
- return await response.json();
1301
+ const run2 = await response.json();
1302
+ const status = run2.status;
1303
+ const finished = status === "completed" || status === "failed" || status === "cancelled" || Boolean(opts?.returnOnResult && run2.result_reported_at);
1304
+ if (opts?.throwOnIncomplete && !finished) {
1305
+ const state2 = run2.result_reported_at ? "A result had been reported; see `run`." : "No result had been reported.";
1306
+ throw new SeclaiStreamingError(`The server answered with JSON for a run that has not finished. ${state2}`, run2.run_id, run2);
1307
+ }
1308
+ return run2;
1190
1309
  }
1191
1310
  if (!response.body) {
1192
1311
  throw new SeclaiConfigurationError(
@@ -1198,31 +1317,48 @@ var Seclai = class {
1198
1317
  let final;
1199
1318
  const parser = createSseParser((msg) => {
1200
1319
  if (!msg.data) return;
1201
- if (msg.event === "init" || msg.event === "done") {
1320
+ if (msg.event === "init" || msg.event === "result" || msg.event === "done") {
1202
1321
  try {
1203
1322
  const parsed = JSON.parse(msg.data);
1204
1323
  lastSeen = parsed;
1324
+ if (msg.event === "result") reported = parsed;
1205
1325
  if (msg.event === "done") final = parsed;
1206
1326
  } catch {
1207
1327
  }
1208
1328
  }
1209
1329
  });
1210
- while (!final) {
1211
- const { value, done } = await reader.read();
1212
- if (done) break;
1213
- if (value) parser.feed(decoder.decode(value, { stream: true }));
1330
+ let readFailure;
1331
+ try {
1332
+ while (!final && !(opts?.returnOnResult && reported)) {
1333
+ const { value, done } = await reader.read();
1334
+ if (done) break;
1335
+ if (value) parser.feed(decoder.decode(value, { stream: true }));
1336
+ }
1337
+ } catch (err) {
1338
+ if (opts?.signal?.aborted || !opts?.throwOnIncomplete && !timedOut) throw err;
1339
+ readFailure = err instanceof Error ? err.message : String(err);
1214
1340
  }
1341
+ parser.feed(decoder.decode());
1215
1342
  parser.end();
1216
1343
  if (final) return final;
1217
- if (lastSeen && lastSeen.status && lastSeen.status !== "pending") {
1344
+ if (opts?.returnOnResult && reported) {
1345
+ reader.cancel().catch(() => {
1346
+ });
1347
+ return reported;
1348
+ }
1349
+ if (!opts?.throwOnIncomplete && !timedOut && lastSeen?.status && lastSeen.status !== "pending") {
1218
1350
  return lastSeen;
1219
1351
  }
1220
- throw new SeclaiStreamingError("Stream ended before receiving a 'done' event.", lastSeen?.run_id);
1352
+ const run = reported ?? lastSeen;
1353
+ const state = reported ? "A result had been reported; see `run`." : "No result had been reported.";
1354
+ const reason = timedOut ? `Timed out after ${timeoutMs}ms before the streaming agent run finished.` : readFailure !== void 0 ? `Stream failed before the run finished: ${readFailure}.` : "Stream ended before receiving a 'done' event.";
1355
+ throw new SeclaiStreamingError(`${reason} ${state}`, run?.run_id, run);
1221
1356
  } catch (err) {
1222
- if (timedOut) {
1357
+ if (timedOut && !opts?.signal?.aborted && !(err instanceof SeclaiStreamingError)) {
1223
1358
  throw new SeclaiStreamingError(
1224
1359
  `Timed out after ${timeoutMs}ms waiting for streaming agent run to complete.`,
1225
- lastSeen?.run_id
1360
+ lastSeen?.run_id,
1361
+ reported ?? lastSeen
1226
1362
  );
1227
1363
  }
1228
1364
  throw err;
@@ -1234,7 +1370,13 @@ var Seclai = class {
1234
1370
  * Run an agent in streaming mode and yield each SSE event as it arrives.
1235
1371
  *
1236
1372
  * This is an `AsyncGenerator` suitable for real-time UIs that want to render
1237
- * step progress as it happens.
1373
+ * step progress as it happens. Set `include_reasoning` or
1374
+ * `include_commentary` in `body` to also receive `stream_reasoning` or
1375
+ * `stream_commentary` events.
1376
+ *
1377
+ * From `apiVersion` `2026-11-14`, an agent whose definition fails to validate
1378
+ * is refused with HTTP 409 ({@link SeclaiAPIStatusError}) before any event,
1379
+ * and no run is created.
1238
1380
  *
1239
1381
  * @param agentId - Agent identifier.
1240
1382
  * @param body - Streaming run request payload.
@@ -1244,6 +1386,10 @@ var Seclai = class {
1244
1386
  * @example
1245
1387
  * ```ts
1246
1388
  * for await (const event of client.runStreamingAgent("agent-id", { input: "Hello!" })) {
1389
+ * // `result` carries the answer in `output`, possibly before later steps finish.
1390
+ * if (event.event === "result") {
1391
+ * console.log("Answer:", (event.data as AgentRunResponse).output);
1392
+ * }
1247
1393
  * if (event.event === "done") {
1248
1394
  * console.log("Final:", event.data);
1249
1395
  * }
@@ -1282,6 +1428,7 @@ var Seclai = class {
1282
1428
  method: "POST",
1283
1429
  url: url.toString(),
1284
1430
  responseText,
1431
+ headers: new Headers(response.headers),
1285
1432
  validationError: validation
1286
1433
  });
1287
1434
  }
@@ -1290,7 +1437,8 @@ var Seclai = class {
1290
1437
  statusCode: response.status,
1291
1438
  method: "POST",
1292
1439
  url: url.toString(),
1293
- responseText
1440
+ responseText,
1441
+ headers: new Headers(response.headers)
1294
1442
  });
1295
1443
  }
1296
1444
  if (isJson) {
@@ -1347,11 +1495,38 @@ var Seclai = class {
1347
1495
  *
1348
1496
  * This is useful in environments where SSE streaming is unavailable.
1349
1497
  *
1498
+ * A run's answer can be ready before its last step finishes: once
1499
+ * `result_reported_at` is set, `output` holds the answer. Pass
1500
+ * `returnOnResult: true` to return as soon as a run has it set, the run
1501
+ * `runAgent()` returns included. With `includeStepOutputs`, when that run
1502
+ * would end the poll and `signal` is not aborted, it is fetched again at
1503
+ * once for its step outputs.
1504
+ * Such a run may still be in progress: its `status` is not terminal and the
1505
+ * run can still fail, so check `result_reported_at`, not `status`.
1506
+ *
1507
+ * When `timeoutMs` elapses first, this throws {@link SeclaiStreamingError}
1508
+ * with the latest run it has (the `runAgent()` response if no poll ran) in
1509
+ * `run`. If that run has `result_reported_at`
1510
+ * set, its `output` is the answer.
1511
+ *
1512
+ * `signal` is checked at the top of each poll, after the check for a run
1513
+ * that ends the poll. A run that has ended the poll by then, whether the
1514
+ * start run or a polled one, is returned even after an abort; the start run
1515
+ * then comes back without step outputs, even when `includeStepOutputs` is
1516
+ * set. Otherwise an abort throws `SeclaiError("Polling aborted.")`, which is
1517
+ * not an `AbortError` and does not carry `signal.reason`.
1518
+ *
1350
1519
  * @param agentId - Agent identifier.
1351
1520
  * @param body - Run request payload.
1352
1521
  * @param opts - Polling configuration and abort signal.
1353
- * @returns The terminal agent run.
1354
- * @throws {@link SeclaiStreamingError} On timeout.
1522
+ * @returns The terminal agent run, or, with `returnOnResult`, the first run
1523
+ * with `result_reported_at` set.
1524
+ * @throws {@link SeclaiStreamingError} If `timeoutMs` elapses before the run
1525
+ * finished. Its `run` holds the latest run it has (the `runAgent()`
1526
+ * response if no poll ran).
1527
+ * @throws {@link SeclaiError} `"Polling aborted."` If `signal` is aborted and,
1528
+ * at the next poll's check, the run has not ended the poll. It is not an
1529
+ * `AbortError` and does not carry `signal.reason`.
1355
1530
  */
1356
1531
  async runAgentAndPoll(agentId, body, opts) {
1357
1532
  const pollInterval = opts?.pollIntervalMs ?? 2e3;
@@ -1360,20 +1535,29 @@ var Seclai = class {
1360
1535
  const run = await this.runAgent(agentId, body);
1361
1536
  const runId = run.id ?? run.run_id;
1362
1537
  if (!runId) throw new SeclaiError("Agent run response did not contain an id.");
1538
+ let current = run;
1539
+ if (opts?.includeStepOutputs) {
1540
+ const status = run.status;
1541
+ if (status === "completed" || status === "failed" || status === "cancelled" || opts.returnOnResult && run.result_reported_at) {
1542
+ if (!opts.signal?.aborted) current = await this.getAgentRun(runId, { includeStepOutputs: true });
1543
+ }
1544
+ }
1363
1545
  while (true) {
1546
+ const status = current.status;
1547
+ if (status === "completed" || status === "failed" || status === "cancelled") {
1548
+ return current;
1549
+ }
1550
+ if (opts?.returnOnResult && current.result_reported_at) return current;
1364
1551
  if (opts?.signal?.aborted) throw new SeclaiError("Polling aborted.");
1365
1552
  if (Date.now() - startTime > timeout) {
1366
- throw new SeclaiStreamingError(`Polling timed out after ${timeout}ms.`, runId);
1553
+ const state = current.result_reported_at ? "A result had been reported; see `run`." : "No result had been reported.";
1554
+ throw new SeclaiStreamingError(`Polling timed out after ${timeout}ms. ${state}`, runId, current);
1367
1555
  }
1368
1556
  await new Promise((r) => setTimeout(r, pollInterval));
1369
- const current = await this.getAgentRun(
1557
+ current = await this.getAgentRun(
1370
1558
  runId,
1371
1559
  opts?.includeStepOutputs ? { includeStepOutputs: true } : void 0
1372
1560
  );
1373
- const status = current.status;
1374
- if (status === "completed" || status === "failed" || status === "cancelled") {
1375
- return current;
1376
- }
1377
1561
  }
1378
1562
  }
1379
1563
  // ═══════════════════════════════════════════════════════════════════════════
@@ -1442,22 +1626,50 @@ var Seclai = class {
1442
1626
  return await this.request("GET", `/agents/${agentId}/attachment-references`);
1443
1627
  }
1444
1628
  /**
1445
- * Download a file attachment emitted by a step in an agent run.
1629
+ * Download a file of an agent run (one a step emitted or one the run started
1630
+ * with), or one byte range of it.
1446
1631
  *
1447
1632
  * Returns the raw `Response` so you can stream or save the binary data.
1448
1633
  *
1634
+ * To fetch part of the file, set a byte range. Offsets are zero-based and
1635
+ * `rangeEnd` is inclusive:
1636
+ *
1637
+ * - `rangeStart` alone sends `Range: bytes=<rangeStart>-`, from that byte to the end.
1638
+ * - `rangeStart` and `rangeEnd` send `Range: bytes=<rangeStart>-<rangeEnd>`.
1639
+ * - `rangeSuffix` alone sends `Range: bytes=-<rangeSuffix>`, the last that many bytes.
1640
+ *
1641
+ * With none of them set, the SDK adds no `Range` header. The server answers a range
1642
+ * with status 206 and a `Content-Range` header, so check `resp.status` before
1643
+ * treating the body as the whole file. A range of an empty file is answered with
1644
+ * 200 and the whole (empty) file. A range that starts at or past the end of a
1645
+ * non-empty file throws {@link SeclaiAPIStatusError} with `statusCode` 416,
1646
+ * and its `headers.get("content-range")` ends in `/<size>`, the file's size in
1647
+ * bytes.
1648
+ *
1449
1649
  * @param runId - Run identifier.
1450
- * @param attachmentId - URL-safe-base64-encoded `storage_key` of the attachment
1451
- * (as surfaced in run output manifests and webhook/email payloads).
1650
+ * @param attachmentId - The `id` of an entry in the run's or a step's
1651
+ * `attachments`, or the URL-safe-base64-encoded storage key that webhook and
1652
+ * email links carry.
1452
1653
  * @param opts - Optional `downloadName` filename hint for the download
1453
- * disposition, and `signal`, which cancels the request; with a standard `fetch` this
1654
+ * disposition; `rangeStart`, `rangeEnd` and `rangeSuffix`, the byte range
1655
+ * described above; and `signal`, which cancels the request; with a standard `fetch` this
1454
1656
  * includes reading the body, so `AbortSignal.timeout(ms)` bounds the whole
1455
1657
  * transfer.
1456
- * @returns Raw response with the attachment bytes.
1658
+ * @returns Raw response with the attachment bytes: status 200 with the whole
1659
+ * file, or 206 with the requested range.
1660
+ * @throws {@link SeclaiConfigurationError} Before any request, when the range
1661
+ * options are not one of the three forms above: `rangeEnd` without
1662
+ * `rangeStart`, `rangeSuffix` with either of them, `rangeEnd` less than
1663
+ * `rangeStart`, a negative `rangeStart` or `rangeEnd`, a `rangeSuffix` below
1664
+ * 1, or a value that is not a safe integer (`Number.isSafeInteger`).
1665
+ * @throws {@link SeclaiAPIStatusError} On a non-2xx response, including 416
1666
+ * when the range cannot be satisfied.
1457
1667
  */
1458
1668
  async downloadAgentRunAttachment(runId, attachmentId, opts = {}) {
1669
+ const range = byteRangeHeader(opts.rangeStart, opts.rangeEnd, opts.rangeSuffix);
1459
1670
  return await this.requestRaw("GET", `/v2/agent-runs/${runId}/attachments/${attachmentId}`, {
1460
1671
  query: { download_name: opts.downloadName },
1672
+ ...range === void 0 ? {} : { headers: { Range: range } },
1461
1673
  signal: opts.signal
1462
1674
  });
1463
1675
  }
@@ -1735,8 +1947,9 @@ var Seclai = class {
1735
1947
  * Configure an agent's `SLACK_COMMAND` trigger, which people run from Slack
1736
1948
  * with `/seclai` or the message shortcut.
1737
1949
  *
1738
- * Sets the Slack connection, form, channels, reply visibility and conversation
1739
- * settings. Omitted fields are left unchanged.
1950
+ * Sets the Slack connection, `alias` (the name people type after `/seclai`),
1951
+ * form, channels, reply visibility and conversation settings. Omitted fields
1952
+ * are left unchanged. `input` is deprecated and ignored by the API.
1740
1953
  *
1741
1954
  * @param agentId - Agent identifier.
1742
1955
  * @param triggerId - Trigger identifier.
@@ -1766,6 +1979,40 @@ var Seclai = class {
1766
1979
  json: body
1767
1980
  });
1768
1981
  }
1982
+ /**
1983
+ * Get the run metadata keys a trigger declares.
1984
+ *
1985
+ * Steps may reference a declared key as `{{metadata.<key>}}`. The response
1986
+ * also lists the system and source keys the trigger's type can declare.
1987
+ *
1988
+ * @param agentId - Agent identifier.
1989
+ * @param triggerId - Trigger identifier, as `getAgent()` returns it.
1990
+ * @returns The trigger's declared and declarable metadata keys.
1991
+ */
1992
+ async getMetadataKeys(agentId, triggerId) {
1993
+ return await this.request(
1994
+ "GET",
1995
+ `/agents/${agentId}/triggers/${triggerId}/metadata-keys`
1996
+ );
1997
+ }
1998
+ /**
1999
+ * Replace the run metadata keys a trigger declares.
2000
+ *
2001
+ * The body is the whole declaration and replaces the current one. The API
2002
+ * answers 400 when the agent references a key that no trigger of its branch
2003
+ * declares.
2004
+ *
2005
+ * @param agentId - Agent identifier.
2006
+ * @param triggerId - Trigger identifier, as `getAgent()` returns it.
2007
+ * @param body - The full declaration; each key's `required` defaults to `false`.
2008
+ * @returns The trigger's metadata keys, with `warnings` naming agents whose
2009
+ * `call_agent` mapping no longer fits.
2010
+ */
2011
+ async setMetadataKeys(agentId, triggerId, body) {
2012
+ return await this.request("PUT", `/agents/${agentId}/triggers/${triggerId}/metadata-keys`, {
2013
+ json: body
2014
+ });
2015
+ }
1769
2016
  // ═══════════════════════════════════════════════════════════════════════════
1770
2017
  // Agent Email Governance
1771
2018
  // ═══════════════════════════════════════════════════════════════════════════
@@ -1875,11 +2122,12 @@ var Seclai = class {
1875
2122
  return await this.request("GET", "/agents/inbound-email-status");
1876
2123
  }
1877
2124
  /**
1878
- * Fail all of the account's QUEUED (over-quota parked) inbound-email runs at
1879
- * once.
2125
+ * Cancel all of the account's QUEUED (over-quota parked) inbound-email runs
2126
+ * at once.
1880
2127
  *
1881
- * A queued run consumed no quota or credits at queue time, so this merely
1882
- * fails them. Requires an account owner/admin.
2128
+ * A queued run consumed no quota or credits at queue time. Each ends
2129
+ * `cancelled`, or `failed` with an `apiVersion` before `2026-11-08`.
2130
+ * Requires an account owner/admin.
1883
2131
  *
1884
2132
  * @returns The count cancelled.
1885
2133
  */
@@ -1932,6 +2180,21 @@ var Seclai = class {
1932
2180
  async getKnowledgeBase(knowledgeBaseId) {
1933
2181
  return await this.request("GET", `/knowledge_bases/${knowledgeBaseId}`);
1934
2182
  }
2183
+ /**
2184
+ * Get the item-metadata keys seen in a knowledge base's content.
2185
+ *
2186
+ * Reports, for all time and the last 30 and 7 days, each key's item count,
2187
+ * number of distinct values and five most frequent values.
2188
+ *
2189
+ * @param knowledgeBaseId - Knowledge base identifier.
2190
+ * @returns The key statistics per window.
2191
+ */
2192
+ async getKnowledgeBaseMetadataKeyStats(knowledgeBaseId) {
2193
+ return await this.request(
2194
+ "GET",
2195
+ `/knowledge_bases/${knowledgeBaseId}/metadata-key-stats`
2196
+ );
2197
+ }
1935
2198
  /**
1936
2199
  * Update a knowledge base.
1937
2200
  *