@seclai/sdk 1.9.0 → 1.11.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 +43 -0
- package/README.md +109 -25
- package/dist/index.cjs +416 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +202 -66
- package/dist/index.d.ts +202 -66
- package/dist/index.js +416 -209
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.11.0] - 2026-11-27
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **Breaking:** Return `GenerationTierListResponse` from `getGenerationTiers()` in place of `Record<string, unknown>`, so a tier's `aspect_ratios` and other fields are typed. An `as` cast from the old type to an unrelated one, or an assignment that relied on `Record<string, unknown>`, may no longer compile
|
|
8
|
+
- Make an abort through `signal` in `runAgentAndPoll()` throw `signal.reason`, as `signal.throwIfAborted()` does (an `AbortError` unless the caller aborted with a reason of its own, and for a signal that has no `reason`, such as a polyfill's), instead of `SeclaiError("Polling aborted.")`. `signal` now also reaches the start request, each poll and the wait between polls: an already-aborted signal starts no run, an abort during the wait stops it without sending another poll, and with a `fetch` that honours `signal`, an abort during the start request throws, where a start run that had already ended the poll was returned. A run that has ended the poll is still returned after an abort, and with `includeStepOutputs` and a `fetch` that honours `signal`, an abort during the fetch for its step outputs returns the start run without them. `runAgentAndPoll()` now sends its requests itself and no longer calls `runAgent()` or `getAgentRun()`
|
|
9
|
+
- Return the `result` snapshot from `runStreamingAgentAndWait()` with `returnOnResult` when a `result` event and the `done` event arrive in one chunk, where the `done` run was returned
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Add the type exports `GenerationTierListResponse` and `GenerationTierResponse`
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Throw the caller's abort reason from `runStreamingAgent()` and `runStreamingAgentAndWait()` when `signal` is aborted with one (`controller.abort(reason)`) and the `fetch` rejects with the signal's reason, as the standard `fetch` does, where a generic `AbortError` was thrown. An abort without a reason still throws an `AbortError`
|
|
18
|
+
- Throw `SeclaiStreamingError` from `runStreamingAgentAndWait()` when the server sends an `error` event, with the server's error text in the message, or a `timeout` event, each with the latest snapshot in `run`, with or without `throwOnIncomplete`. Both were read as the stream ending early: without `throwOnIncomplete`, the latest snapshot was returned when its status was not `pending`, so a run that failed on the server came back looking like an unfinished success, without the server's message; with it, the error said only that `done` never arrived
|
|
19
|
+
- Parse a final SSE line that has no trailing newline, in `runStreamingAgent()` and `runStreamingAgentAndWait()`, where it was dropped
|
|
20
|
+
- Close the response body on every way out of `runStreamingAgentAndWait()`, after `done` included, and when a caller leaves a `runStreamingAgent()` loop early
|
|
21
|
+
- Remove the abort listeners `runStreamingAgent()` and `runStreamingAgentAndWait()` add to the caller's `signal` when the call ends, so a signal reused across calls no longer collects one per call
|
|
22
|
+
- Throw one `SeclaiStreamingError` from `runStreamingAgentAndWait()` whether `timeoutMs` elapses during the request or during the read: `Timed out after <n>ms waiting for streaming agent run to complete.`, then whether a result had been reported, with the latest snapshot in `run` and, when the request or read was cut off, the error it ended with as its `cause`. A timeout during the read said `Timed out after <n>ms before the streaming agent run finished.`
|
|
23
|
+
- Keep an event whose lines were read in full before a stream broke or timed out, unless the caller aborted `signal`: `runStreamingAgent()` yields it before throwing, and `runStreamingAgentAndWait()` returns a `done` event read so, or with `returnOnResult` a `result` event, where without `throwOnIncomplete` it threw the fetch error
|
|
24
|
+
- Stop waiting for a run in `runAgentAndPoll()` at the deadline: a wait between polls that reaches it ends the call with the timeout `SeclaiStreamingError`, and with a `fetch` that honours `signal`, a poll still in flight then is aborted and the call throws the same error, with the latest run in `run`. `timeoutMs` could overshoot by up to one `pollIntervalMs`, and a poll the server never answered kept the call waiting without limit, whether or not a `signal` was passed. No poll is sent at or after the deadline, so a run that ends during the last interval now times out, and a `timeoutMs` no greater than `pollIntervalMs` sends no poll. Any other error a poll ends with once the deadline has passed, the abort of a poll in flight included, is the timeout's `cause`, except a caller abort, which throws `signal.reason`, and an HTTP error status a poll gets after the deadline, such as a 500, is thrown as itself. `timeoutMs` does not cut off the start request, since the server may already have created the run, nor the fetch for an ended start run's step outputs; only `signal` does. A request is not cut off while more than 2^31-1 ms remain ([#25](https://github.com/seclai/seclai-javascript/issues/25))
|
|
25
|
+
- Wait out a `pollIntervalMs` over 2^31-1 ms in `runAgentAndPoll()`, which polled in a tight loop because `setTimeout` fires at once for a longer delay
|
|
26
|
+
- Throw an HTTP error status that `runStreamingAgent()` or `runStreamingAgentAndWait()` gets as `timeoutMs` elapses (for example, a 401 whose body is still being read) as `SeclaiAPIStatusError`, as `runAgentAndPoll()` does, where it was thrown as the timeout `SeclaiStreamingError`
|
|
27
|
+
|
|
28
|
+
## [1.10.0] - 2026-11-27
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Sync the bundled OpenAPI spec and regenerate the types. `PendingProcessingCompletedFailedStatus`, the `status` of `AgentRunResponse`, `AgentRunStepResponse` and `AgentRunAttemptResponse`, gains `cancelled`. The run status union can gain values in a minor release, so an exhaustive `switch` or a `Record` keyed by it should handle values it does not know. A tier `getGenerationTiers()` returns can now carry `aspect_ratios`, the aspect ratios an image tier's model can be asked for
|
|
33
|
+
- Move `SeclaiApiVersion.Latest` to `2026-11-19`. Nothing is sent unless `apiVersion` is set, so a client that passes `SeclaiApiVersion.Latest` now opts into the four versions added below: from `2026-11-08`, a run cancelled with `cancelAgentRun()` or `cancelQueuedEmailRuns()` ends with `status` `cancelled` instead of `failed`; from `2026-11-09`, `listAgentExamples()` reads `query` as a description of what the agent should do and returns entries ranked by how well they match it, best first, where older versions return only entries containing every word; from `2026-11-14`, `runAgent()`, `runStreamingAgent()` and the helpers built on them are refused with a 409, and no run is created, for an agent whose definition fails to validate, where older versions return the run already failed with the validation error as its cause; and from `2026-11-19`, `createAlertConfig()` accepts the agent alert type `step_failure_continued`
|
|
34
|
+
- Note API changes that apply on every API version, whatever `apiVersion` is set: `cancelAgentRun()` also cancels a `pending`, `waiting_human` or `waiting_scheduled` run, and cancelling a run started by another agent's `call_agent` step that is still waiting for it ends the outermost calling run, and every run below it that has not reported its result
|
|
35
|
+
- Describe a run's answer as the output of the step carrying `run_result`, as the API reference now does, in place of a `streaming_result` or `display_result` step: from `2026-11-04` the `step_id` of a criterion passed to `createEvaluationCriteria()` or `updateEvaluationCriteria()` must name the step carrying `run_result`
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- Add the `rangeStart`, `rangeEnd` and `rangeSuffix` options to `downloadAgentRunAttachment()`, to download one byte range of an attachment: `rangeStart` alone reads to the end of the file, with `rangeEnd` (inclusive) it reads that span, and `rangeSuffix` alone reads the last that many bytes. The server answers with status 206 and `Content-Range`, or 200 and the whole file when the file is empty, and a range starting at or past the end of a non-empty file throws `SeclaiAPIStatusError` with `statusCode` 416. Any other combination, a `rangeEnd` below `rangeStart`, a negative `rangeStart` or `rangeEnd`, a `rangeSuffix` below 1, or a value that is not a safe integer (`Number.isSafeInteger`), throws `SeclaiConfigurationError` before a request is sent. With none set, the request is unchanged and the SDK adds no `Range` header
|
|
40
|
+
- Add `headers` to `SeclaiAPIStatusError` and `SeclaiAPIValidationError`: the error response's headers as a `Headers` object, such as `Retry-After` on a 503, or on a 416 from a ranged `downloadAgentRunAttachment()` a `Content-Range` ending in `/<size>`, the file's size in bytes. It is set on every request path, including uploads, raw downloads and streaming runs, and is an empty `Headers` when the error is constructed without them. In a browser, only the headers the server's CORS policy exposes are present
|
|
41
|
+
- Add `include_commentary` to the `runStreamingAgent()` request, to receive `stream_commentary` events carrying the text a model on OpenAI's Responses API writes outside its final answer, for a `prompt_call` step whose `run_result` enables `show_commentary`. `runStreamingAgentAndWait()`, which returns no such events, does not take it and does not send one passed anyway
|
|
42
|
+
- Add the `SeclaiApiVersion.V2026_11_08`, `SeclaiApiVersion.V2026_11_09`, `SeclaiApiVersion.V2026_11_14` and `SeclaiApiVersion.V2026_11_19` constants, so those versions are accepted as `apiVersion`
|
|
43
|
+
|
|
3
44
|
## [1.9.0] - 2026-11-05
|
|
4
45
|
|
|
5
46
|
### Changed
|
|
@@ -292,6 +333,8 @@ _Stable release. No functional changes since 0.0.1._
|
|
|
292
333
|
|
|
293
334
|
_Initial release._
|
|
294
335
|
|
|
336
|
+
[1.11.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.11.0
|
|
337
|
+
[1.10.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.10.0
|
|
295
338
|
[1.9.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.9.0
|
|
296
339
|
[1.8.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.8.0
|
|
297
340
|
[1.7.0]: https://github.com/seclai/seclai-javascript/releases/tag/1.7.0
|
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ or set environment variables:
|
|
|
104
104
|
|
|
105
105
|
Online API documentation (latest):
|
|
106
106
|
|
|
107
|
-
https://seclai.github.io/seclai-javascript/1.
|
|
107
|
+
https://seclai.github.io/seclai-javascript/1.11.0/
|
|
108
108
|
|
|
109
109
|
Release history is in [`CHANGELOG.md`](CHANGELOG.md).
|
|
110
110
|
|
|
@@ -127,7 +127,7 @@ Leave `apiVersion` unset and the header is omitted, so the account's pinned
|
|
|
127
127
|
baseline applies and responses keep their current shapes. Upgrading this package
|
|
128
128
|
alone never changes the wire contract.
|
|
129
129
|
|
|
130
|
-
Known versions are on `SeclaiApiVersion` (`V2026_07_01` through `
|
|
130
|
+
Known versions are on `SeclaiApiVersion` (`V2026_07_01` through `V2026_11_19`,
|
|
131
131
|
plus `Default` and `Latest`), imported from `@seclai/sdk`. A version this release was
|
|
132
132
|
**not** built against throws at construction: a newer version can reshape
|
|
133
133
|
responses, and this client would decode them incorrectly rather than reject them.
|
|
@@ -193,6 +193,15 @@ a request that used to succeed, or (from `2026-10-21`) which fields can be
|
|
|
193
193
|
- `2026-11-02` refuses an agent write that references a metadata key no trigger
|
|
194
194
|
declares, where older versions declare the key for you.
|
|
195
195
|
- `2026-11-04` rejects with a 400 evaluation settings that were accepted before.
|
|
196
|
+
- `2026-11-08` changes a value you may branch on: a cancelled agent run reports
|
|
197
|
+
`status` `cancelled` instead of `failed`.
|
|
198
|
+
- `2026-11-09` changes which gallery entries `listAgentExamples()` returns for a
|
|
199
|
+
`query`, and their order.
|
|
200
|
+
- `2026-11-14` refuses with a 409, and no run, a run of an agent whose
|
|
201
|
+
definition fails to validate, where older versions return a run that has
|
|
202
|
+
already failed.
|
|
203
|
+
- `2026-11-19` accepts a new agent alert type, `step_failure_continued`, in
|
|
204
|
+
`createAlertConfig()`.
|
|
196
205
|
|
|
197
206
|
| Version | What it changes |
|
|
198
207
|
| --- | --- |
|
|
@@ -209,7 +218,11 @@ a request that used to succeed, or (from `2026-10-21`) which fields can be
|
|
|
209
218
|
| `2026-10-21` | An evaluation result whose evaluator returned no verdict (`error`) is left out of `failed` and of `pass_rate` / `failure_rate` in `getNonManualEvaluationSummary()`, and `getEvaluationCriteriaSummary()` averages `average_score` over passed and failed results only. `testDraftEvaluation()` returns `score` and `passed` as `null` for an `error` result. Below it the summary counts `error` results in `failed` and the rates, `average_score` includes their stored scores, and the test draft returns `score` 0.5 and `passed: false`. The summary's `error` count is returned on every version |
|
|
210
219
|
| `2026-10-28` | An `if_else` or `switch` step's `output` is the result of the arm it took, or its input when that arm is empty or it took none. Below it the `output` is a `{"branch": ...}` marker naming the arm, with no `attachments`. The step's `decision` names the arm on every version |
|
|
211
220
|
| `2026-11-02` | `updateAgentDefinition()`, and `updateAgent()` when it sets `sampling_config`, refuse a definition or sampling rule that references a metadata key no trigger declares, with a 400 and a 422 respectively. Declare the key first with `setMetadataKeys()`. An `agent_definition` import through `createAgent()` or `updateAgent()` is not refused and still declares the keys it reads. Below it each such key is declared on the trigger as optional |
|
|
212
|
-
| `2026-11-04` | `createEvaluationResult()` rejects `retry_triggered: true` and `updateAgent()` rejects `evaluation_mode` `eval_and_retry` with a 400: evaluations never retry a step. `createEvaluationCriteria()`, and `updateEvaluationCriteria()` when it changes `step_id`, reject a `step_id` that does not name
|
|
221
|
+
| `2026-11-04` | `createEvaluationResult()` rejects `retry_triggered: true` and `updateAgent()` rejects `evaluation_mode` `eval_and_retry` with a 400: evaluations never retry a step. `createEvaluationCriteria()`, and `updateEvaluationCriteria()` when it changes `step_id`, reject a `step_id` that does not name the step carrying `run_result` with a 400. Below it `eval_and_retry` is stored as `sample_and_flag` |
|
|
222
|
+
| `2026-11-08` | An agent run cancelled with `cancelAgentRun()` or `cancelQueuedEmailRuns()` ends with `status` `cancelled`. Below it the run ends `failed`. `runAgentAndPoll()` and `runStreamingAgentAndWait()` treat both as the end of the run |
|
|
223
|
+
| `2026-11-09` | `listAgentExamples()` reads `query` as a description of what the agent should do and returns entries ranked by how well they match it, in words and meaning, best first; a query of several words that are all filler ("create an agent") counts as no query. Below it only entries containing every word of `query` are returned |
|
|
224
|
+
| `2026-11-14` | `runAgent()`, `runStreamingAgent()` and the helpers built on them are refused with a 409, and no run is created, for an agent whose definition fails to validate. Below it the run is returned, already failed with the validation error as its cause |
|
|
225
|
+
| `2026-11-19` | `createAlertConfig()` accepts the agent alert type `step_failure_continued` |
|
|
213
226
|
|
|
214
227
|
**`Latest` moves with the SDK.** `SeclaiApiVersion.Latest` is the newest version
|
|
215
228
|
the installed release knows, so upgrading the package can opt a client that
|
|
@@ -218,9 +231,12 @@ passes it into every version added since — `1.6.0` moved it from `2026-07-27`
|
|
|
218
231
|
`2026-10-21`, across the `2026-10-05` status change, the `2026-10-13` and
|
|
219
232
|
`2026-10-19` source-setting rejections, the `2026-10-16` input change and the
|
|
220
233
|
`2026-10-21` evaluation change, `1.8.0` moves it to `2026-10-28`,
|
|
221
|
-
across the `if_else` / `switch` step-output change,
|
|
234
|
+
across the `if_else` / `switch` step-output change, `1.9.0` moves it to
|
|
222
235
|
`2026-11-04`, across the `2026-11-02` undeclared-metadata-key refusal and the
|
|
223
|
-
`2026-11-04` evaluation-setting rejections.
|
|
236
|
+
`2026-11-04` evaluation-setting rejections, and `1.10.0` moves it to
|
|
237
|
+
`2026-11-19`, across the `2026-11-08` `cancelled` run status, the `2026-11-09`
|
|
238
|
+
gallery ranking, the `2026-11-14` refusal of an agent that fails to
|
|
239
|
+
validate and the `2026-11-19` `step_failure_continued` alert type. Pass a
|
|
224
240
|
dated constant such as `SeclaiApiVersion.V2026_07_27` to keep behaviour fixed
|
|
225
241
|
across upgrades.
|
|
226
242
|
|
|
@@ -361,14 +377,19 @@ await client.deleteAgentRun("run_id");
|
|
|
361
377
|
|
|
362
378
|
The SDK provides two streaming patterns over the SSE `/runs/stream` endpoint:
|
|
363
379
|
|
|
364
|
-
**Block until done** — returns the run from the `done` event.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
380
|
+
**Block until done** — returns the run from the `done` event. When the server
|
|
381
|
+
sends an `error` event (the run's stream failed on the server) it throws
|
|
382
|
+
`SeclaiStreamingError` with the server's error text in its message, and when the
|
|
383
|
+
server sends a `timeout` event, or `timeoutMs` elapses first, it throws
|
|
384
|
+
`SeclaiStreamingError` too. Its `run` holds the latest snapshot: the `result`
|
|
385
|
+
snapshot if one arrived, else the `init` snapshot. An HTTP error status that
|
|
386
|
+
arrives as `timeoutMs` elapses is thrown as itself, as `SeclaiAPIStatusError`.
|
|
387
|
+
An abort through `signal` rethrows the abort error.
|
|
368
388
|
|
|
369
389
|
By default, a stream that ends before `done` returns the latest snapshot when
|
|
370
|
-
its status is not `pending`, so the run returned may not have finished: check
|
|
371
|
-
|
|
390
|
+
its status is not `pending`, so the run returned may not have finished: check `status` and `result_reported_at`. A stream that breaks
|
|
391
|
+
throws the fetch error, unless a `done` event, or with `returnOnResult` a `result`
|
|
392
|
+
event, was read in full before it broke.
|
|
372
393
|
Pass `throwOnIncomplete: true` to throw `SeclaiStreamingError`, with the snapshot
|
|
373
394
|
in `run`, in both cases instead, and also when the server answers with plain
|
|
374
395
|
JSON for a run that has not finished. It is recommended, and becomes the default in
|
|
@@ -397,7 +418,9 @@ for await (const event of client.runStreamingAgent(
|
|
|
397
418
|
```
|
|
398
419
|
|
|
399
420
|
When the server answers with plain JSON instead of an SSE stream,
|
|
400
|
-
`runStreamingAgent` yields only a `done` event, so read the answer from it.
|
|
421
|
+
`runStreamingAgent` yields only a `done` event, so read the answer from it. The
|
|
422
|
+
iterator yields the server's `error` and `timeout` events like any other, and
|
|
423
|
+
leaving the loop early closes the response body.
|
|
401
424
|
|
|
402
425
|
A `result` event carries the run's answer in `output` once `result_reported_at`
|
|
403
426
|
is set. It comes before `done`, and for an agent that reports its result early it
|
|
@@ -431,23 +454,30 @@ try {
|
|
|
431
454
|
```
|
|
432
455
|
|
|
433
456
|
Pass `include_reasoning: true` to also receive `stream_reasoning` events carrying
|
|
434
|
-
the model's reasoning while it thinks
|
|
435
|
-
`
|
|
436
|
-
|
|
457
|
+
the model's reasoning while it thinks, and `include_commentary: true` to receive
|
|
458
|
+
`stream_commentary` events carrying the text a model on OpenAI's Responses API
|
|
459
|
+
writes outside its final answer, with its `phase` and `message` number. They are
|
|
460
|
+
sent only for a `prompt_call` step whose `run_result` enables `show_reasoning`
|
|
461
|
+
or `show_commentary` respectively, never when a governance policy redacts that
|
|
462
|
+
step, and neither is part of `output`. `runStreamingAgentAndWait()` returns no
|
|
463
|
+
such events and does not send either key:
|
|
437
464
|
|
|
438
465
|
<!-- sdksync:check -->
|
|
439
466
|
```ts
|
|
440
467
|
for await (const event of client.runStreamingAgent("agent_id", {
|
|
441
468
|
input: "Hello",
|
|
442
469
|
include_reasoning: true,
|
|
470
|
+
include_commentary: true,
|
|
443
471
|
})) {
|
|
444
472
|
if (event.event === "stream_reasoning") console.log(event.data);
|
|
473
|
+
if (event.event === "stream_commentary") console.log(event.data);
|
|
445
474
|
}
|
|
446
475
|
```
|
|
447
476
|
|
|
448
477
|
### Polling
|
|
449
478
|
|
|
450
|
-
For environments where SSE is not practical, poll
|
|
479
|
+
For environments where SSE is not practical, poll until the run ends with
|
|
480
|
+
`status` `completed`, `failed` or `cancelled`:
|
|
451
481
|
|
|
452
482
|
```ts
|
|
453
483
|
const result = await client.runAgentAndPoll(
|
|
@@ -461,12 +491,21 @@ A run's answer can be ready before its last step finishes: once
|
|
|
461
491
|
`result_reported_at` is set on `getAgentRun()`, `output` holds the answer. Pass
|
|
462
492
|
`returnOnResult: true` to return as soon as a run has it set, the one
|
|
463
493
|
`runAgent()` returns included. With `includeStepOutputs`, when that run would end
|
|
464
|
-
the poll
|
|
465
|
-
|
|
466
|
-
without step outputs. Such a run may still be in
|
|
467
|
-
is not terminal and the run can still fail, so check
|
|
468
|
-
`status`. If `timeoutMs` elapses first, it throws
|
|
469
|
-
latest run it has (the `runAgent()` response if
|
|
494
|
+
the poll, it is fetched again at once, because the `runAgent()` response carries
|
|
495
|
+
no step outputs; when `signal` aborts before that fetch answers (with a `fetch`
|
|
496
|
+
that honours `signal`), the run comes back without step outputs. Such a run may still be in
|
|
497
|
+
progress: its `status` is not terminal and the run can still fail, so check
|
|
498
|
+
`result_reported_at`, not `status`. If `timeoutMs` elapses first, it throws
|
|
499
|
+
`SeclaiStreamingError` with the latest run it has (the `runAgent()` response if
|
|
500
|
+
no poll answered) in `run`. No poll is sent at or after the deadline: a wait
|
|
501
|
+
that reaches it ends the call, so a `timeoutMs` no greater than `pollIntervalMs`
|
|
502
|
+
sends no poll, and with a `fetch` that honours `signal` a poll in flight at the
|
|
503
|
+
deadline is aborted. `timeoutMs` does not cut off the start request (the server
|
|
504
|
+
may already have created the run) or the step-outputs fetch; only `signal` does.
|
|
505
|
+
A request is not cut off while more than 2^31-1 ms remain.
|
|
506
|
+
`signal` is passed to every request and to the wait between polls, and an abort
|
|
507
|
+
throws `signal.reason`, as `signal.throwIfAborted()` does (an `AbortError` for a
|
|
508
|
+
signal that has no `reason`), unless a run has already ended the poll.
|
|
470
509
|
|
|
471
510
|
<!-- sdksync:check -->
|
|
472
511
|
```ts
|
|
@@ -506,12 +545,57 @@ Only a `dynamic_input` agent takes uploads; any other agent rejects one with a
|
|
|
506
545
|
|
|
507
546
|
<!-- sdksync:check -->
|
|
508
547
|
```ts
|
|
509
|
-
// Download a file
|
|
510
|
-
// URL-safe-base64
|
|
548
|
+
// Download a file of an agent run. attachment_id is the `id` of an entry in the
|
|
549
|
+
// run's or a step's `attachments`, or the URL-safe-base64 storage key that
|
|
550
|
+
// webhook and email links carry.
|
|
511
551
|
const resp = await client.downloadAgentRunAttachment("run_id", "attachment_id");
|
|
512
552
|
const blob = await resp.blob(); // raw Response — stream or save the bytes
|
|
513
553
|
```
|
|
514
554
|
|
|
555
|
+
To fetch part of a file, set a byte range. Offsets are zero-based and
|
|
556
|
+
`rangeEnd` is inclusive: `rangeStart` alone reads to the end of the file,
|
|
557
|
+
`rangeStart` with `rangeEnd` reads that span, and `rangeSuffix` alone reads the
|
|
558
|
+
last that many bytes. The server answers a range with status 206 and a
|
|
559
|
+
`Content-Range` header, and a range of an empty file with 200 and the whole
|
|
560
|
+
(empty) file, so check `status` before treating the body as the whole file.
|
|
561
|
+
|
|
562
|
+
<!-- sdksync:check -->
|
|
563
|
+
```ts
|
|
564
|
+
const part = await client.downloadAgentRunAttachment("run_id", "attachment_id", {
|
|
565
|
+
rangeStart: 0,
|
|
566
|
+
rangeEnd: 1023, // the first 1 KiB
|
|
567
|
+
});
|
|
568
|
+
if (part.status === 206) {
|
|
569
|
+
console.log(part.headers.get("content-range")); // e.g. "bytes 0-1023/52341"
|
|
570
|
+
}
|
|
571
|
+
const tail = await client.downloadAgentRunAttachment("run_id", "attachment_id", {
|
|
572
|
+
rangeSuffix: 512, // the last 512 bytes
|
|
573
|
+
});
|
|
574
|
+
console.log((await tail.arrayBuffer()).byteLength);
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
A range that starts at or past the end of a non-empty file throws
|
|
578
|
+
`SeclaiAPIStatusError` with `statusCode` 416. The error's `headers` field holds
|
|
579
|
+
the response headers, and its `Content-Range` ends in `/<size>`, the file's size
|
|
580
|
+
in bytes (in a browser, only if the server's CORS policy exposes it).
|
|
581
|
+
|
|
582
|
+
```ts
|
|
583
|
+
import { SeclaiAPIStatusError } from "@seclai/sdk";
|
|
584
|
+
|
|
585
|
+
try {
|
|
586
|
+
await client.downloadAgentRunAttachment("run_id", "attachment_id", { rangeStart: 52341 });
|
|
587
|
+
} catch (err) {
|
|
588
|
+
if (err instanceof SeclaiAPIStatusError && err.statusCode === 416) {
|
|
589
|
+
console.log(err.headers.get("content-range")); // e.g. "bytes */52341"
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
Any other combination (`rangeEnd` without `rangeStart`, `rangeSuffix` with
|
|
595
|
+
either, `rangeEnd` below `rangeStart`, a negative `rangeStart` or `rangeEnd`, a
|
|
596
|
+
`rangeSuffix` below 1, or a value that is not a safe integer) throws `SeclaiConfigurationError` before a request is
|
|
597
|
+
sent.
|
|
598
|
+
|
|
515
599
|
### Agent email triggers
|
|
516
600
|
|
|
517
601
|
Configure the inbound address and handling rules on an agent's `EMAIL_RECEIVED`
|
|
@@ -626,7 +710,7 @@ const rejections = await client.listInboundEmailRejections({ agentId: "agent_id"
|
|
|
626
710
|
|
|
627
711
|
// Account-wide overload circuit breaker
|
|
628
712
|
const status = await client.getInboundEmailStatus(); // { paused, queued_backlog }
|
|
629
|
-
await client.cancelQueuedEmailRuns(); //
|
|
713
|
+
await client.cancelQueuedEmailRuns(); // cancel all QUEUED (over-quota parked) runs
|
|
630
714
|
await client.resumeInboundEmail(); // one-shot override; re-arms if still overloaded
|
|
631
715
|
```
|
|
632
716
|
|