@engini/sdk 0.22.0 → 0.24.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/README.md CHANGED
@@ -153,6 +153,22 @@ for await (const event of client.triggers.subscribe({ triggerId: trigger.id }))
153
153
  }
154
154
  ```
155
155
 
156
+ Pass a `signal` to stop the subscription on your own terms, including mid-read on an idle
157
+ stream - the abort reaches the pending connection immediately, it is not just abandoned:
158
+
159
+ ```ts
160
+ const controller = new AbortController();
161
+ process.once("SIGINT", () => controller.abort());
162
+
163
+ for await (const event of client.triggers.subscribe({
164
+ triggerId: trigger.id,
165
+ signal: controller.signal,
166
+ })) {
167
+ console.log(event.id, event.payload);
168
+ }
169
+ // The generator returns normally once aborted - no try/catch needed for this path.
170
+ ```
171
+
156
172
  `client.toolset(...)` builds a local toolset (no I/O until used) or loads a server one via
157
173
  `client.toolset({ toolsetId })`.
158
174
 
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { Toolset } from "./toolset.js";
13
13
  export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
14
14
  export { File } from "./files.js";
15
15
  export type { FileWire } from "./files.js";
16
- export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, ConnectionObject, WhoAmI, } from "./types.js";
16
+ export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, ConnectionObject, WhoAmI, AccessTokenResponse, } from "./types.js";
17
17
  export type { ToolsetConnectionDto, ToolsetConnectionRequest, ToolsetDto } from "@engini/client";
18
18
  export type { OpaAgentListItem, OpaAgentDetail, OpaAgentSettings, OpaAgentTokenResponse, OpaAgentCreateResponse, OpaReleaseManifest, CreateOpaAgentRequest, UpdateOpaAgentRequest, } from "@engini/client";
19
19
  export type { TriggerTypeDto, TriggerTypeDetailDto, TriggerParametersDto, TriggerInstanceView, TriggerInstanceStatus, TriggerKind, TriggerStatusReason, TriggerScheduleDto, TriggerScheduleFrequency, TriggerTimeFrameDto, TriggerEventView, TriggerEventDetailView, TriggerEventDeliveryStateDto, TriggerDeliveryAttemptView, TriggerDestinationView, TriggerDestinationCreated, TriggerDestinationStatusDto, CreateTriggerRequest, PatchTriggerRequest, CreateTriggerDestinationRequest, PatchTriggerDestinationRequest, PutDefaultDestinationRequest, } from "@engini/client";
@@ -4,8 +4,9 @@
4
4
  * `waitForRefresh` poll helper) that backs the interactive `engini connect` CLI.
5
5
  * See `docs/superpowers/specs/2026-06-18-cli-connect-flow-design.md`.
6
6
  */
7
- import { type ConnectionObject, type ConnectionReplaceResult, type ConnectionPublicDetail, type ConnectionPublicListItem, type DefaultConnectionDto, type AccessTokenResponse, type RefreshStatusResponse, type SignInUrlResponse } from "@engini/client";
7
+ import { type ConnectionObject, type ConnectionReplaceResult, type ConnectionPublicDetail, type ConnectionPublicListItem, type DefaultConnectionDto, type RefreshStatusResponse, type SignInUrlResponse } from "@engini/client";
8
8
  import { type Transport } from "../http.js";
9
+ import type { AccessTokenResponse } from "../types.js";
9
10
  /**
10
11
  * Whether a refresh status is terminal (finished, error, or otherwise not running).
11
12
  * Unknown descriptions count as terminal — erring that way avoids hanging on a
@@ -233,9 +233,9 @@ export declare class TriggersResource {
233
233
  /**
234
234
  * Create a trigger instance from a trigger type.
235
235
  *
236
- * Pass `connectionId` or `connectionName`; with neither, the server uses the account's
237
- * default connection for the application and answers `MISSING_DEFAULT_CONNECTION`
238
- * (500) when there is none.
236
+ * Pass `connectionId` or `connectionName`; omitting both is legal only for a trigger
237
+ * type whose application does not require a connection, where the server substitutes
238
+ * its own default connection — otherwise it answers `400 EMPTY_QUERY`.
239
239
  *
240
240
  * Which of `schedule` / `pollIntervalMinutes` / `listenColumns` apply is per trigger
241
241
  * type — read `types.get(slug).parameters` first.
@@ -341,6 +341,10 @@ export declare class TriggersResource {
341
341
  * exhausts it.
342
342
  * @param params.heartbeatTimeoutMs Milliseconds of total silence before the socket is
343
343
  * treated as dead.
344
+ * @param params.signal Abort the subscription immediately, including mid-read on an
345
+ * idle connection. The generator returns normally rather than throwing; the
346
+ * in-flight connection is aborted (not merely abandoned), so no lingering socket
347
+ * keeps the process alive after the caller stops iterating.
344
348
  */
345
349
  subscribe(params?: {
346
350
  triggerId?: string;
@@ -350,6 +354,7 @@ export declare class TriggersResource {
350
354
  autoResume?: boolean;
351
355
  maxReconnects?: number;
352
356
  heartbeatTimeoutMs?: number;
357
+ signal?: AbortSignal;
353
358
  }): AsyncGenerator<TriggerEventView>;
354
359
  }
355
360
  export {};
@@ -82,6 +82,37 @@ export const backoffTimer = {
82
82
  setTimeout(resolve, ms);
83
83
  }),
84
84
  };
85
+ /**
86
+ * `backoffTimer.sleep`, but resolved early by an abort signal.
87
+ *
88
+ * The `signal?.aborted` guards at the top of `subscribe`'s loop and the head of its
89
+ * `catch` only run *after* whichever `await` they follow settles — and the backoff they
90
+ * guard can be `MAX_RETRY_AFTER_MS` (300s) on the 429 path. Without this, a Ctrl-C
91
+ * landing inside that wait would sit until the sleep finishes on its own.
92
+ */
93
+ function interruptibleSleep(ms, signal) {
94
+ if (signal === undefined)
95
+ return backoffTimer.sleep(ms);
96
+ if (signal.aborted)
97
+ return Promise.resolve();
98
+ return new Promise((resolve) => {
99
+ let settled = false;
100
+ const onAbort = () => {
101
+ if (settled)
102
+ return;
103
+ settled = true;
104
+ resolve();
105
+ };
106
+ signal.addEventListener("abort", onAbort, { once: true });
107
+ void backoffTimer.sleep(ms).then(() => {
108
+ if (settled)
109
+ return;
110
+ settled = true;
111
+ signal.removeEventListener("abort", onAbort);
112
+ resolve();
113
+ });
114
+ });
115
+ }
85
116
  /**
86
117
  * Map the trigger wire codes onto their typed errors.
87
118
  *
@@ -457,9 +488,9 @@ export class TriggersResource {
457
488
  /**
458
489
  * Create a trigger instance from a trigger type.
459
490
  *
460
- * Pass `connectionId` or `connectionName`; with neither, the server uses the account's
461
- * default connection for the application and answers `MISSING_DEFAULT_CONNECTION`
462
- * (500) when there is none.
491
+ * Pass `connectionId` or `connectionName`; omitting both is legal only for a trigger
492
+ * type whose application does not require a connection, where the server substitutes
493
+ * its own default connection — otherwise it answers `400 EMPTY_QUERY`.
463
494
  *
464
495
  * Which of `schedule` / `pollIntervalMinutes` / `listenColumns` apply is per trigger
465
496
  * type — read `types.get(slug).parameters` first.
@@ -602,8 +633,19 @@ export class TriggersResource {
602
633
  * written at the deadline — the body is simply truncated. It is indistinguishable from
603
634
  * a network blip by design, and handled the same way.
604
635
  */
605
- async *streamOnce(query, heartbeatTimeoutMs, progress) {
636
+ async *streamOnce(query, heartbeatTimeoutMs, progress, signal) {
606
637
  const controller = new AbortController();
638
+ // Bridges the caller's signal onto this attempt's own controller, which also carries
639
+ // the watchdog's aborts. `{ once: true }` on the listener pairs with the explicit
640
+ // removal below — this generator is re-created on every reconnect, so a listener left
641
+ // on a long-lived external `signal` would accumulate across an hour of resumes.
642
+ const onExternalAbort = () => controller.abort();
643
+ if (signal !== undefined) {
644
+ if (signal.aborted)
645
+ controller.abort();
646
+ else
647
+ signal.addEventListener("abort", onExternalAbort, { once: true });
648
+ }
607
649
  // The heartbeat watchdog. The server promises a frame every 20s, so silence past the
608
650
  // timeout means the socket is dead even though nothing closed it; aborting turns that
609
651
  // into the same resumable ending as a dropped connection.
@@ -716,6 +758,8 @@ export class TriggersResource {
716
758
  }
717
759
  finally {
718
760
  disarmWatchdog();
761
+ if (signal !== undefined)
762
+ signal.removeEventListener("abort", onExternalAbort);
719
763
  // `abort()` first: it is synchronous and guaranteed, so the socket is released
720
764
  // even though the cancel below may never settle.
721
765
  controller.abort();
@@ -765,14 +809,24 @@ export class TriggersResource {
765
809
  * exhausts it.
766
810
  * @param params.heartbeatTimeoutMs Milliseconds of total silence before the socket is
767
811
  * treated as dead.
812
+ * @param params.signal Abort the subscription immediately, including mid-read on an
813
+ * idle connection. The generator returns normally rather than throwing; the
814
+ * in-flight connection is aborted (not merely abandoned), so no lingering socket
815
+ * keeps the process alive after the caller stops iterating.
768
816
  */
769
817
  async *subscribe(params = {}) {
770
818
  const autoResume = params.autoResume ?? true;
771
819
  const maxReconnects = params.maxReconnects ?? MAX_RECONNECTS;
772
820
  const heartbeatTimeoutMs = params.heartbeatTimeoutMs ?? HEARTBEAT_TIMEOUT_MS;
821
+ const signal = params.signal;
773
822
  let cursor = params.since;
774
823
  let reconnects = 0;
775
824
  for (;;) {
825
+ // Every path that lands back at the top of this loop passes through here first,
826
+ // including after a backoff sleep — so this and the mirror guard at the head of
827
+ // `catch` are what stop an abort from being reinterpreted as "reconnect".
828
+ if (signal?.aborted)
829
+ return;
776
830
  const started = Date.now();
777
831
  const progress = { sawFrame: false };
778
832
  const query = new URLSearchParams();
@@ -785,7 +839,7 @@ export class TriggersResource {
785
839
  if (cursor !== undefined)
786
840
  query.set("since", cursor);
787
841
  try {
788
- for await (const [kind, frame] of this.streamOnce(query, heartbeatTimeoutMs, progress)) {
842
+ for await (const [kind, frame] of this.streamOnce(query, heartbeatTimeoutMs, progress, signal)) {
789
843
  if (kind === "control") {
790
844
  if (frame.reconnect !== true) {
791
845
  // `!== ""` as well as the type check: Python coerces an empty reason to
@@ -806,6 +860,12 @@ export class TriggersResource {
806
860
  }
807
861
  }
808
862
  catch (err) {
863
+ // An abort surfaces here as `EnginiNetworkError` — the aborted `reader.read()`
864
+ // is wrapped by `streamOnce`'s own catch, and that is also the one error this
865
+ // loop is built to retry. Must precede both branches below, or an interrupt
866
+ // during a read gets reconnected instead of ending the generator.
867
+ if (signal?.aborted)
868
+ return;
809
869
  if (err instanceof EnginiRateLimitError) {
810
870
  // The base class, not `EnginiTriggerStreamLimitError`: a 429 whose body is not
811
871
  // the JSON error envelope — an ingress or CDN limiter, or a future server code
@@ -821,7 +881,7 @@ export class TriggersResource {
821
881
  // honouring that literally would retry back-to-back against a server that just
822
882
  // said "slow down".
823
883
  const delay = Math.max((err.retryAfter ?? 0) * 1000, backoffMs(reconnects));
824
- await backoffTimer.sleep(Math.min(delay, MAX_RETRY_AFTER_MS));
884
+ await interruptibleSleep(Math.min(delay, MAX_RETRY_AFTER_MS), signal);
825
885
  continue;
826
886
  }
827
887
  if (err instanceof EnginiNetworkError) {
@@ -834,7 +894,7 @@ export class TriggersResource {
834
894
  reconnects = nextAttempt(reconnects, started, progress);
835
895
  if (reconnects > maxReconnects)
836
896
  throw err;
837
- await backoffTimer.sleep(backoffMs(reconnects));
897
+ await interruptibleSleep(backoffMs(reconnects), signal);
838
898
  continue;
839
899
  }
840
900
  throw err;
@@ -845,7 +905,7 @@ export class TriggersResource {
845
905
  if (reconnects > maxReconnects) {
846
906
  throw new EnginiNetworkError(`The trigger event stream could not be resumed after ${maxReconnects} consecutive attempts.`);
847
907
  }
848
- await backoffTimer.sleep(backoffMs(reconnects));
908
+ await interruptibleSleep(backoffMs(reconnects), signal);
849
909
  }
850
910
  }
851
911
  }
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Canonical, provider-agnostic tool schema and execution result types.
3
3
  * Bound to the autogen `@engini/client` models — the SDK's public surface.
4
4
  */
5
- import type { ToolDetailDto, ActivityCondition, ActivitySort, ApplicationDto, ApplicationDetailDto, ConnectionPublicListItem, ConnectionPublicDetail, ConnectionObject as ConnectionObjectModel, WhoAmIResponse } from "@engini/client";
5
+ import type { ToolDetailDto, ActivityCondition, ActivitySort, ApplicationDto, ApplicationDetailDto, ConnectionPublicListItem, ConnectionPublicDetail, ConnectionObject as ConnectionObjectModel, WhoAmIResponse, AccessTokenResponse as ClientAccessTokenResponse } from "@engini/client";
6
6
  /** Canonical tool schema (== client `ToolDetailDto`; carries `inputSchema` + `supports*`). */
7
7
  export type ToolSchema = ToolDetailDto;
8
8
  /** A connector application summary (== client `ApplicationDto`). */
@@ -17,6 +17,24 @@ export type ConnectionDetail = ConnectionPublicDetail;
17
17
  export type ConnectionObject = ConnectionObjectModel;
18
18
  /** Authenticated caller identity (== client `WhoAmIResponse`). */
19
19
  export type WhoAmI = WhoAmIResponse;
20
+ /**
21
+ * Access-token poll response, incl. `fieldOptions` — legal values for a declared
22
+ * connection field discovered from the signed-in org on the terminal poll of the
23
+ * OAuth sign-in (WorkflowApi #1401), shaped `{ [fieldName]: { [valueToSave]: labelToShow } }`.
24
+ * e.g. Salesforce's `ApiVersionUrl` -> `{ "/services/data/v60.0": "60.0" }` — the KEY is
25
+ * the value a `create`/`update` must send, the VALUE is only a display label; getting
26
+ * that backwards saves exactly the broken connection this feature exists to prevent.
27
+ *
28
+ * `@engini/client`'s generated `AccessTokenResponse` now declares `fieldOptions` itself
29
+ * (required, non-null — the C# DTO is `= new()`), so this is a straight re-export, not
30
+ * a local intersection. That non-nullability is deliberate, not an oversight: the merged
31
+ * server (`ConnectionsController.cs`, terminal poll) maps a failed/empty lookup to `{}`
32
+ * explicitly, so **absent is the only signal of an older server** (one that predates
33
+ * WorkflowApi #1401); `{}` means the lookup ran and found no options, same as "the field
34
+ * genuinely has none". A failed lookup is indistinguishable from "no options" once it's
35
+ * on the wire (logged server-side, not surfaced here) - same as it is from absent.
36
+ */
37
+ export type AccessTokenResponse = ClientAccessTokenResponse;
20
38
  /** Execute-time filter condition (gated by `supportsFilters`). */
21
39
  export type Filter = ActivityCondition;
22
40
  /** Execute-time sort directive (gated by `supportsSort`). */
package/dist/version.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export declare const VERSION = "0.22.0";
6
+ export declare const VERSION = "0.24.0";
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export const VERSION = "0.22.0";
6
+ export const VERSION = "0.24.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "test": "vitest run"
28
28
  },
29
29
  "dependencies": {
30
- "@engini/client": "0.10.0",
30
+ "@engini/client": "0.11.0",
31
31
  "undici": "^6.0.0"
32
32
  },
33
33
  "devDependencies": {