@seclai/sdk 1.9.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/CHANGELOG.md +17 -0
- package/README.md +80 -12
- package/dist/index.cjs +127 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -34
- package/dist/index.d.ts +124 -34
- package/dist/index.js +127 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,10 +16,14 @@ var SeclaiApiVersion = {
|
|
|
16
16
|
V2026_10_28: "2026-10-28",
|
|
17
17
|
V2026_11_02: "2026-11-02",
|
|
18
18
|
V2026_11_04: "2026-11-04",
|
|
19
|
+
V2026_11_08: "2026-11-08",
|
|
20
|
+
V2026_11_09: "2026-11-09",
|
|
21
|
+
V2026_11_14: "2026-11-14",
|
|
22
|
+
V2026_11_19: "2026-11-19",
|
|
19
23
|
/** Baseline applied to an unpinned, header-less caller. */
|
|
20
24
|
Default: "2026-07-01",
|
|
21
25
|
/** Newest version known to this SDK release. May lag the server. */
|
|
22
|
-
Latest: "2026-11-
|
|
26
|
+
Latest: "2026-11-19"
|
|
23
27
|
};
|
|
24
28
|
var KNOWN_API_VERSIONS = Object.entries(SeclaiApiVersion).filter(([k]) => k.startsWith("V")).map(([, v]) => v);
|
|
25
29
|
|
|
@@ -45,6 +49,14 @@ var SeclaiAPIStatusError = class extends SeclaiError {
|
|
|
45
49
|
url;
|
|
46
50
|
/** Best-effort response body text (if available). */
|
|
47
51
|
responseText;
|
|
52
|
+
/**
|
|
53
|
+
* Headers of the error response, such as `Retry-After` on a 503, or
|
|
54
|
+
* `Content-Range` on a 416 from a ranged `downloadAgentRunAttachment()`, whose
|
|
55
|
+
* value ends in `/<size>`, the file's size in bytes. Empty when the response
|
|
56
|
+
* headers are unknown. In a browser, only the headers the server's CORS policy
|
|
57
|
+
* exposes are present.
|
|
58
|
+
*/
|
|
59
|
+
headers;
|
|
48
60
|
constructor(opts) {
|
|
49
61
|
super(opts.message);
|
|
50
62
|
this.name = "SeclaiAPIStatusError";
|
|
@@ -52,6 +64,7 @@ var SeclaiAPIStatusError = class extends SeclaiError {
|
|
|
52
64
|
this.method = opts.method;
|
|
53
65
|
this.url = opts.url;
|
|
54
66
|
this.responseText = opts.responseText;
|
|
67
|
+
this.headers = opts.headers ?? new Headers();
|
|
55
68
|
}
|
|
56
69
|
};
|
|
57
70
|
var SeclaiAPIValidationError = class extends SeclaiAPIStatusError {
|
|
@@ -429,6 +442,34 @@ function mergeHeaders(...layers) {
|
|
|
429
442
|
function headerKey(headers, name) {
|
|
430
443
|
return Object.keys(headers ?? {}).filter((key) => key.toLowerCase() === name).pop();
|
|
431
444
|
}
|
|
445
|
+
function byteRangeHeader(start, end, suffix) {
|
|
446
|
+
const hasStart = start !== void 0 && start !== null;
|
|
447
|
+
const hasEnd = end !== void 0 && end !== null;
|
|
448
|
+
const hasSuffix = suffix !== void 0 && suffix !== null;
|
|
449
|
+
if (!hasStart && !hasEnd && !hasSuffix) return void 0;
|
|
450
|
+
const fail = (why) => {
|
|
451
|
+
throw new SeclaiConfigurationError(`Invalid byte range: ${why}`);
|
|
452
|
+
};
|
|
453
|
+
if (hasSuffix) {
|
|
454
|
+
if (hasStart || hasEnd) fail("rangeSuffix cannot be combined with rangeStart or rangeEnd.");
|
|
455
|
+
if (!Number.isSafeInteger(suffix) || suffix < 1) {
|
|
456
|
+
fail(`rangeSuffix must be a whole number of at least 1, got ${String(suffix)}.`);
|
|
457
|
+
}
|
|
458
|
+
return `bytes=-${suffix}`;
|
|
459
|
+
}
|
|
460
|
+
if (!hasStart) fail("rangeEnd requires rangeStart; use rangeSuffix for the last bytes of the file.");
|
|
461
|
+
if (!Number.isSafeInteger(start) || start < 0) {
|
|
462
|
+
fail(`rangeStart must be a whole number of at least 0, got ${String(start)}.`);
|
|
463
|
+
}
|
|
464
|
+
if (!hasEnd) return `bytes=${start}-`;
|
|
465
|
+
if (!Number.isSafeInteger(end) || end < 0) {
|
|
466
|
+
fail(`rangeEnd must be a whole number of at least 0, got ${String(end)}.`);
|
|
467
|
+
}
|
|
468
|
+
if (end < start) {
|
|
469
|
+
fail(`rangeEnd (${end}) must not be less than rangeStart (${start}).`);
|
|
470
|
+
}
|
|
471
|
+
return `bytes=${start}-${end}`;
|
|
472
|
+
}
|
|
432
473
|
async function safeText(response) {
|
|
433
474
|
try {
|
|
434
475
|
return await response.clone().text();
|
|
@@ -695,6 +736,7 @@ var Seclai = class {
|
|
|
695
736
|
method,
|
|
696
737
|
url: url.toString(),
|
|
697
738
|
responseText,
|
|
739
|
+
headers: new Headers(response.headers),
|
|
698
740
|
validationError: validation
|
|
699
741
|
});
|
|
700
742
|
}
|
|
@@ -703,7 +745,8 @@ var Seclai = class {
|
|
|
703
745
|
statusCode: response.status,
|
|
704
746
|
method,
|
|
705
747
|
url: url.toString(),
|
|
706
|
-
responseText
|
|
748
|
+
responseText,
|
|
749
|
+
headers: new Headers(response.headers)
|
|
707
750
|
});
|
|
708
751
|
}
|
|
709
752
|
if (!response.body) return null;
|
|
@@ -750,6 +793,7 @@ var Seclai = class {
|
|
|
750
793
|
method,
|
|
751
794
|
url: url.toString(),
|
|
752
795
|
responseText,
|
|
796
|
+
headers: new Headers(response.headers),
|
|
753
797
|
validationError: validation
|
|
754
798
|
});
|
|
755
799
|
}
|
|
@@ -758,7 +802,8 @@ var Seclai = class {
|
|
|
758
802
|
statusCode: response.status,
|
|
759
803
|
method,
|
|
760
804
|
url: url.toString(),
|
|
761
|
-
responseText
|
|
805
|
+
responseText,
|
|
806
|
+
headers: new Headers(response.headers)
|
|
762
807
|
});
|
|
763
808
|
}
|
|
764
809
|
return response;
|
|
@@ -789,6 +834,7 @@ var Seclai = class {
|
|
|
789
834
|
method: "POST",
|
|
790
835
|
url: url.toString(),
|
|
791
836
|
responseText,
|
|
837
|
+
headers: new Headers(response.headers),
|
|
792
838
|
validationError: validation
|
|
793
839
|
});
|
|
794
840
|
}
|
|
@@ -797,7 +843,8 @@ var Seclai = class {
|
|
|
797
843
|
statusCode: response.status,
|
|
798
844
|
method: "POST",
|
|
799
845
|
url: url.toString(),
|
|
800
|
-
responseText
|
|
846
|
+
responseText,
|
|
847
|
+
headers: new Headers(response.headers)
|
|
801
848
|
});
|
|
802
849
|
}
|
|
803
850
|
return await response.json();
|
|
@@ -863,6 +910,10 @@ var Seclai = class {
|
|
|
863
910
|
/**
|
|
864
911
|
* List the agent gallery: example agents to start from.
|
|
865
912
|
*
|
|
913
|
+
* From `apiVersion` `2026-11-09`, `query` describes what the agent should do
|
|
914
|
+
* and entries come back ranked by how well they match it, best first. Before
|
|
915
|
+
* it, only entries containing every word of `query` are returned.
|
|
916
|
+
*
|
|
866
917
|
* Pass an entry's `key` as `agent_template` to {@link createAgent}, with
|
|
867
918
|
* `resource_bindings` for the resources it needs.
|
|
868
919
|
*
|
|
@@ -1016,6 +1067,11 @@ var Seclai = class {
|
|
|
1016
1067
|
/**
|
|
1017
1068
|
* Start an agent run.
|
|
1018
1069
|
*
|
|
1070
|
+
* From `apiVersion` `2026-11-14`, an agent whose definition fails to validate
|
|
1071
|
+
* is refused with HTTP 409 ({@link SeclaiAPIStatusError}) and no run is
|
|
1072
|
+
* created; earlier versions return the run, already failed with the
|
|
1073
|
+
* validation error as its cause.
|
|
1074
|
+
*
|
|
1019
1075
|
* @param agentId - Agent identifier.
|
|
1020
1076
|
* @param body - Run request payload (`input`, `metadata`, `priority`, etc.).
|
|
1021
1077
|
* @returns The created agent run.
|
|
@@ -1069,14 +1125,17 @@ var Seclai = class {
|
|
|
1069
1125
|
await this.cancelAgentRun(runId);
|
|
1070
1126
|
}
|
|
1071
1127
|
/**
|
|
1072
|
-
* Cancel
|
|
1128
|
+
* Cancel an agent run that has not ended: `queued`, `pending`, `processing`,
|
|
1129
|
+
* `waiting_human` or `waiting_scheduled`.
|
|
1073
1130
|
*
|
|
1074
1131
|
* Cancellation is `DELETE` on the run resource — the API exposes no
|
|
1075
1132
|
* `POST .../cancel` route, and no operation that deletes a run. Rejected when
|
|
1076
|
-
* the run has already
|
|
1133
|
+
* the run has already ended (`completed`, `failed` or `cancelled`). From
|
|
1134
|
+
* `apiVersion` `2026-11-08` the cancelled run ends with status `cancelled`;
|
|
1135
|
+
* on earlier versions it ends `failed`.
|
|
1077
1136
|
*
|
|
1078
1137
|
* @param runId - Run identifier.
|
|
1079
|
-
* @returns
|
|
1138
|
+
* @returns The updated run.
|
|
1080
1139
|
*/
|
|
1081
1140
|
async cancelAgentRun(runId) {
|
|
1082
1141
|
return await this.request("DELETE", `/agents/runs/${runId}`);
|
|
@@ -1089,8 +1148,9 @@ var Seclai = class {
|
|
|
1089
1148
|
*
|
|
1090
1149
|
* Consumes the entire SSE stream and returns only the terminal `done` payload.
|
|
1091
1150
|
* For real-time event access, use {@link runStreamingAgent} instead. The body
|
|
1092
|
-
* takes no `include_reasoning`, and one passed anyway
|
|
1093
|
-
* returns no `stream_reasoning`
|
|
1151
|
+
* takes no `include_reasoning` or `include_commentary`, and one passed anyway
|
|
1152
|
+
* is not sent: this method returns no `stream_reasoning` or
|
|
1153
|
+
* `stream_commentary` events.
|
|
1094
1154
|
*
|
|
1095
1155
|
* A `result` event carries the run's answer in `output` once
|
|
1096
1156
|
* `result_reported_at` is set, and can arrive while later steps still run.
|
|
@@ -1112,7 +1172,8 @@ var Seclai = class {
|
|
|
1112
1172
|
* version.
|
|
1113
1173
|
*
|
|
1114
1174
|
* @param agentId - Agent identifier.
|
|
1115
|
-
* @param body - Streaming run request payload, without `include_reasoning
|
|
1175
|
+
* @param body - Streaming run request payload, without `include_reasoning`
|
|
1176
|
+
* or `include_commentary`.
|
|
1116
1177
|
* @param opts - Timeout, abort signal and `returnOnResult` options.
|
|
1117
1178
|
* @returns The run from the `done` event; with `returnOnResult`, the
|
|
1118
1179
|
* `result` snapshot; without `throwOnIncomplete`, possibly an unfinished
|
|
@@ -1134,7 +1195,11 @@ var Seclai = class {
|
|
|
1134
1195
|
* ```
|
|
1135
1196
|
*/
|
|
1136
1197
|
async runStreamingAgentAndWait(agentId, body, opts) {
|
|
1137
|
-
const {
|
|
1198
|
+
const {
|
|
1199
|
+
include_reasoning: _reasoning,
|
|
1200
|
+
include_commentary: _commentary,
|
|
1201
|
+
...runBody
|
|
1202
|
+
} = body;
|
|
1138
1203
|
const url = buildURL(this.baseUrl, `/agents/${agentId}/runs/stream`);
|
|
1139
1204
|
const authHdrs = await this.authHeaders();
|
|
1140
1205
|
const headers = this.requestHeaders([
|
|
@@ -1168,6 +1233,7 @@ var Seclai = class {
|
|
|
1168
1233
|
method: "POST",
|
|
1169
1234
|
url: url.toString(),
|
|
1170
1235
|
responseText,
|
|
1236
|
+
headers: new Headers(response.headers),
|
|
1171
1237
|
validationError: validation
|
|
1172
1238
|
});
|
|
1173
1239
|
}
|
|
@@ -1176,7 +1242,8 @@ var Seclai = class {
|
|
|
1176
1242
|
statusCode: response.status,
|
|
1177
1243
|
method: "POST",
|
|
1178
1244
|
url: url.toString(),
|
|
1179
|
-
responseText
|
|
1245
|
+
responseText,
|
|
1246
|
+
headers: new Headers(response.headers)
|
|
1180
1247
|
});
|
|
1181
1248
|
}
|
|
1182
1249
|
if (isJson) {
|
|
@@ -1252,7 +1319,13 @@ var Seclai = class {
|
|
|
1252
1319
|
* Run an agent in streaming mode and yield each SSE event as it arrives.
|
|
1253
1320
|
*
|
|
1254
1321
|
* This is an `AsyncGenerator` suitable for real-time UIs that want to render
|
|
1255
|
-
* step progress as it happens.
|
|
1322
|
+
* step progress as it happens. Set `include_reasoning` or
|
|
1323
|
+
* `include_commentary` in `body` to also receive `stream_reasoning` or
|
|
1324
|
+
* `stream_commentary` events.
|
|
1325
|
+
*
|
|
1326
|
+
* From `apiVersion` `2026-11-14`, an agent whose definition fails to validate
|
|
1327
|
+
* is refused with HTTP 409 ({@link SeclaiAPIStatusError}) before any event,
|
|
1328
|
+
* and no run is created.
|
|
1256
1329
|
*
|
|
1257
1330
|
* @param agentId - Agent identifier.
|
|
1258
1331
|
* @param body - Streaming run request payload.
|
|
@@ -1304,6 +1377,7 @@ var Seclai = class {
|
|
|
1304
1377
|
method: "POST",
|
|
1305
1378
|
url: url.toString(),
|
|
1306
1379
|
responseText,
|
|
1380
|
+
headers: new Headers(response.headers),
|
|
1307
1381
|
validationError: validation
|
|
1308
1382
|
});
|
|
1309
1383
|
}
|
|
@@ -1312,7 +1386,8 @@ var Seclai = class {
|
|
|
1312
1386
|
statusCode: response.status,
|
|
1313
1387
|
method: "POST",
|
|
1314
1388
|
url: url.toString(),
|
|
1315
|
-
responseText
|
|
1389
|
+
responseText,
|
|
1390
|
+
headers: new Headers(response.headers)
|
|
1316
1391
|
});
|
|
1317
1392
|
}
|
|
1318
1393
|
if (isJson) {
|
|
@@ -1500,22 +1575,50 @@ var Seclai = class {
|
|
|
1500
1575
|
return await this.request("GET", `/agents/${agentId}/attachment-references`);
|
|
1501
1576
|
}
|
|
1502
1577
|
/**
|
|
1503
|
-
* Download a file
|
|
1578
|
+
* Download a file of an agent run (one a step emitted or one the run started
|
|
1579
|
+
* with), or one byte range of it.
|
|
1504
1580
|
*
|
|
1505
1581
|
* Returns the raw `Response` so you can stream or save the binary data.
|
|
1506
1582
|
*
|
|
1583
|
+
* To fetch part of the file, set a byte range. Offsets are zero-based and
|
|
1584
|
+
* `rangeEnd` is inclusive:
|
|
1585
|
+
*
|
|
1586
|
+
* - `rangeStart` alone sends `Range: bytes=<rangeStart>-`, from that byte to the end.
|
|
1587
|
+
* - `rangeStart` and `rangeEnd` send `Range: bytes=<rangeStart>-<rangeEnd>`.
|
|
1588
|
+
* - `rangeSuffix` alone sends `Range: bytes=-<rangeSuffix>`, the last that many bytes.
|
|
1589
|
+
*
|
|
1590
|
+
* With none of them set, the SDK adds no `Range` header. The server answers a range
|
|
1591
|
+
* with status 206 and a `Content-Range` header, so check `resp.status` before
|
|
1592
|
+
* treating the body as the whole file. A range of an empty file is answered with
|
|
1593
|
+
* 200 and the whole (empty) file. A range that starts at or past the end of a
|
|
1594
|
+
* non-empty file throws {@link SeclaiAPIStatusError} with `statusCode` 416,
|
|
1595
|
+
* and its `headers.get("content-range")` ends in `/<size>`, the file's size in
|
|
1596
|
+
* bytes.
|
|
1597
|
+
*
|
|
1507
1598
|
* @param runId - Run identifier.
|
|
1508
|
-
* @param attachmentId -
|
|
1509
|
-
*
|
|
1599
|
+
* @param attachmentId - The `id` of an entry in the run's or a step's
|
|
1600
|
+
* `attachments`, or the URL-safe-base64-encoded storage key that webhook and
|
|
1601
|
+
* email links carry.
|
|
1510
1602
|
* @param opts - Optional `downloadName` filename hint for the download
|
|
1511
|
-
* disposition
|
|
1603
|
+
* disposition; `rangeStart`, `rangeEnd` and `rangeSuffix`, the byte range
|
|
1604
|
+
* described above; and `signal`, which cancels the request; with a standard `fetch` this
|
|
1512
1605
|
* includes reading the body, so `AbortSignal.timeout(ms)` bounds the whole
|
|
1513
1606
|
* transfer.
|
|
1514
|
-
* @returns Raw response with the attachment bytes
|
|
1607
|
+
* @returns Raw response with the attachment bytes: status 200 with the whole
|
|
1608
|
+
* file, or 206 with the requested range.
|
|
1609
|
+
* @throws {@link SeclaiConfigurationError} Before any request, when the range
|
|
1610
|
+
* options are not one of the three forms above: `rangeEnd` without
|
|
1611
|
+
* `rangeStart`, `rangeSuffix` with either of them, `rangeEnd` less than
|
|
1612
|
+
* `rangeStart`, a negative `rangeStart` or `rangeEnd`, a `rangeSuffix` below
|
|
1613
|
+
* 1, or a value that is not a safe integer (`Number.isSafeInteger`).
|
|
1614
|
+
* @throws {@link SeclaiAPIStatusError} On a non-2xx response, including 416
|
|
1615
|
+
* when the range cannot be satisfied.
|
|
1515
1616
|
*/
|
|
1516
1617
|
async downloadAgentRunAttachment(runId, attachmentId, opts = {}) {
|
|
1618
|
+
const range = byteRangeHeader(opts.rangeStart, opts.rangeEnd, opts.rangeSuffix);
|
|
1517
1619
|
return await this.requestRaw("GET", `/v2/agent-runs/${runId}/attachments/${attachmentId}`, {
|
|
1518
1620
|
query: { download_name: opts.downloadName },
|
|
1621
|
+
...range === void 0 ? {} : { headers: { Range: range } },
|
|
1519
1622
|
signal: opts.signal
|
|
1520
1623
|
});
|
|
1521
1624
|
}
|
|
@@ -1968,11 +2071,12 @@ var Seclai = class {
|
|
|
1968
2071
|
return await this.request("GET", "/agents/inbound-email-status");
|
|
1969
2072
|
}
|
|
1970
2073
|
/**
|
|
1971
|
-
*
|
|
1972
|
-
* once.
|
|
2074
|
+
* Cancel all of the account's QUEUED (over-quota parked) inbound-email runs
|
|
2075
|
+
* at once.
|
|
1973
2076
|
*
|
|
1974
|
-
* A queued run consumed no quota or credits at queue time
|
|
1975
|
-
*
|
|
2077
|
+
* A queued run consumed no quota or credits at queue time. Each ends
|
|
2078
|
+
* `cancelled`, or `failed` with an `apiVersion` before `2026-11-08`.
|
|
2079
|
+
* Requires an account owner/admin.
|
|
1976
2080
|
*
|
|
1977
2081
|
* @returns The count cancelled.
|
|
1978
2082
|
*/
|