@engini/sdk 0.18.0 → 0.19.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
@@ -72,6 +72,30 @@ const tools = await client.mcp.availableTools(token, 2139); // candidates for
72
72
  connection entry needs an explicit `connectionId` (MCP servers are account-wide, so there
73
73
  is no per-user default). There is no `create`/`delete`: those stay in the engini.io UI.
74
74
 
75
+ `client.opa` provisions, inspects, configures and credentials on-premise agents — the
76
+ Engini component a customer installs behind their own firewall to reach SQL Server,
77
+ Oracle, Priority ERP and file shares:
78
+
79
+ ```ts
80
+ // Provision one and hand the token to the installer
81
+ const agent = await client.opa.create({ name: "Warehouse SQL", pullPeriodSeconds: 30 });
82
+ console.log(agent.token); // a credential - store it, do not log it
83
+
84
+ // Later: is it healthy?
85
+ const a = await client.opa.get(agent.agentId);
86
+ console.log(a.status, a.version, a.lastSeenAt);
87
+
88
+ // Change its log level; the agent picks it up on its next poll
89
+ const r = await client.opa.update(agent.agentId, { logLevel: "Debug" });
90
+ if (!r.appliedToAgent) console.log("stored; the agent is not Online yet");
91
+ ```
92
+
93
+ An agent polls Engini, so anything that "talks to" it waits for its next poll. `update()`
94
+ **merges** — an omitted member leaves that field alone, unlike `connections.update()`,
95
+ which replaces its whole field map. Settings you omit take the server's defaults, and the
96
+ minimums come from the connector's own declared metadata rather than the client. Agents are
97
+ not connections: `client.connections` never returns them.
98
+
75
99
  `client.toolset(...)` builds a local toolset (no I/O until used) or loads a server one via
76
100
  `client.toolset({ toolsetId })`.
77
101
 
package/dist/client.d.ts CHANGED
@@ -5,6 +5,7 @@ import { ToolsResource } from "./resources/tools.js";
5
5
  import { ConnectionsResource } from "./resources/connections.js";
6
6
  import { ToolsetsResource } from "./resources/toolsets.js";
7
7
  import { McpResource } from "./resources/mcp.js";
8
+ import { OpaResource } from "./resources/opa.js";
8
9
  import { ApplicationsResource } from "./resources/applications.js";
9
10
  import { AuthResource } from "./resources/auth.js";
10
11
  import { Toolset, type ConnectionBinding } from "./toolset.js";
@@ -49,6 +50,7 @@ export declare class Engini {
49
50
  readonly connections: ConnectionsResource;
50
51
  readonly toolsets: ToolsetsResource;
51
52
  readonly mcp: McpResource;
53
+ readonly opa: OpaResource;
52
54
  readonly applications: ApplicationsResource;
53
55
  readonly auth: AuthResource;
54
56
  readonly provider: Provider;
package/dist/client.js CHANGED
@@ -6,6 +6,7 @@ import { ToolsResource } from "./resources/tools.js";
6
6
  import { ConnectionsResource } from "./resources/connections.js";
7
7
  import { ToolsetsResource } from "./resources/toolsets.js";
8
8
  import { McpResource } from "./resources/mcp.js";
9
+ import { OpaResource } from "./resources/opa.js";
9
10
  import { ApplicationsResource } from "./resources/applications.js";
10
11
  import { AuthResource } from "./resources/auth.js";
11
12
  import { Toolset } from "./toolset.js";
@@ -16,6 +17,7 @@ export class Engini {
16
17
  connections;
17
18
  toolsets;
18
19
  mcp;
20
+ opa;
19
21
  applications;
20
22
  auth;
21
23
  provider;
@@ -69,6 +71,7 @@ export class Engini {
69
71
  this.connections = new ConnectionsResource(this);
70
72
  this.toolsets = new ToolsetsResource(this);
71
73
  this.mcp = new McpResource(this);
74
+ this.opa = new OpaResource(this);
72
75
  this.applications = new ApplicationsResource(this);
73
76
  this.auth = new AuthResource(this);
74
77
  }
package/dist/errors.d.ts CHANGED
@@ -8,8 +8,25 @@ export declare class EnginiError extends Error {
8
8
  /** Transport-level failure before a response was received. */
9
9
  export declare class EnginiNetworkError extends EnginiError {
10
10
  }
11
- /** Any non-2xx API response with a parseable body. */
11
+ /**
12
+ * Any non-2xx API response with a parseable body.
13
+ *
14
+ * `errorCode` is the wire `ErrorResponse.errorCode` when the body parsed, else
15
+ * `undefined`; `details` is the wire `details[]`, else `[]`.
16
+ *
17
+ * Both exist because a status code stopped being enough to describe an error:
18
+ * three OPA conditions share 409/5xx and differ only by `errorCode`, and
19
+ * `OPA_APPLICATION_AMBIGUOUS` carries its candidate slugs in `details` — the only
20
+ * place a caller can learn them. `message` is unchanged, so code reading it is
21
+ * unaffected.
22
+ */
12
23
  export declare class EnginiAPIError extends EnginiError {
24
+ readonly errorCode: string | undefined;
25
+ readonly details: unknown[];
26
+ constructor(message: string, options?: {
27
+ errorCode?: string;
28
+ details?: unknown[];
29
+ });
13
30
  }
14
31
  /** 401 or 403 — token missing, invalid, expired, or lacking permission. */
15
32
  export declare class EnginiAuthError extends EnginiAPIError {
@@ -71,3 +88,45 @@ export declare class EnginiToolExecutionError extends EnginiError {
71
88
  historyId?: number | null;
72
89
  });
73
90
  }
91
+ /**
92
+ * No on-premise agent with that id is visible to this account. Also thrown when the id
93
+ * exists but belongs to another account, or is not an OPA agent at all — the API answers
94
+ * 404 for all three deliberately, so the endpoint cannot be used to probe which ids exist
95
+ * in other tenants.
96
+ */
97
+ export declare class EnginiOpaAgentNotFoundError extends EnginiNotFoundError {
98
+ }
99
+ /**
100
+ * The agent is not Online, so an operation needing a live round-trip cannot run
101
+ * (wire code `OPA_AGENT_OFFLINE`). Thrown by `logs`. A settings update does *not* throw
102
+ * this: it persists the change and reports `appliedToAgent: false` instead, so the caller
103
+ * knows the write landed but the agent has not seen it.
104
+ */
105
+ export declare class EnginiOpaAgentOfflineError extends EnginiConflictError {
106
+ }
107
+ /**
108
+ * More than one on-premise-agent application exists; `create` needs an `applicationSlug`
109
+ * (wire code `OPA_APPLICATION_AMBIGUOUS`). `candidateSlugs` is the only place a caller can
110
+ * learn them: `/v1/applications` does not list OPA applications.
111
+ */
112
+ export declare class EnginiOpaApplicationAmbiguousError extends EnginiConflictError {
113
+ readonly candidateSlugs: string[];
114
+ constructor(message: string, candidateSlugs: string[], options?: {
115
+ errorCode?: string;
116
+ details?: unknown[];
117
+ });
118
+ }
119
+ /**
120
+ * The agent did not answer a live round-trip within the server's bound (wire code
121
+ * `OPA_AGENT_TIMEOUT`, 504). Extends `EnginiServerError` rather than `EnginiTimeoutError`:
122
+ * that one is a *client-side* deadline outside the API-error tree, whereas this is a
123
+ * server-reported outcome carrying an `errorCode`.
124
+ */
125
+ export declare class EnginiOpaAgentTimeoutError extends EnginiServerError {
126
+ }
127
+ /**
128
+ * The agent was reached but reported a failure collecting or applying
129
+ * (wire code `OPA_AGENT_DISPATCH_FAILED`, 502).
130
+ */
131
+ export declare class EnginiOpaAgentDispatchError extends EnginiServerError {
132
+ }
package/dist/errors.js CHANGED
@@ -11,8 +11,26 @@ export class EnginiError extends Error {
11
11
  /** Transport-level failure before a response was received. */
12
12
  export class EnginiNetworkError extends EnginiError {
13
13
  }
14
- /** Any non-2xx API response with a parseable body. */
14
+ /**
15
+ * Any non-2xx API response with a parseable body.
16
+ *
17
+ * `errorCode` is the wire `ErrorResponse.errorCode` when the body parsed, else
18
+ * `undefined`; `details` is the wire `details[]`, else `[]`.
19
+ *
20
+ * Both exist because a status code stopped being enough to describe an error:
21
+ * three OPA conditions share 409/5xx and differ only by `errorCode`, and
22
+ * `OPA_APPLICATION_AMBIGUOUS` carries its candidate slugs in `details` — the only
23
+ * place a caller can learn them. `message` is unchanged, so code reading it is
24
+ * unaffected.
25
+ */
15
26
  export class EnginiAPIError extends EnginiError {
27
+ errorCode;
28
+ details;
29
+ constructor(message, options) {
30
+ super(message);
31
+ this.errorCode = options?.errorCode;
32
+ this.details = options?.details ?? [];
33
+ }
16
34
  }
17
35
  /** 401 or 403 — token missing, invalid, expired, or lacking permission. */
18
36
  export class EnginiAuthError extends EnginiAPIError {
@@ -76,3 +94,45 @@ export class EnginiToolExecutionError extends EnginiError {
76
94
  this.historyId = opts.historyId ?? null;
77
95
  }
78
96
  }
97
+ /**
98
+ * No on-premise agent with that id is visible to this account. Also thrown when the id
99
+ * exists but belongs to another account, or is not an OPA agent at all — the API answers
100
+ * 404 for all three deliberately, so the endpoint cannot be used to probe which ids exist
101
+ * in other tenants.
102
+ */
103
+ export class EnginiOpaAgentNotFoundError extends EnginiNotFoundError {
104
+ }
105
+ /**
106
+ * The agent is not Online, so an operation needing a live round-trip cannot run
107
+ * (wire code `OPA_AGENT_OFFLINE`). Thrown by `logs`. A settings update does *not* throw
108
+ * this: it persists the change and reports `appliedToAgent: false` instead, so the caller
109
+ * knows the write landed but the agent has not seen it.
110
+ */
111
+ export class EnginiOpaAgentOfflineError extends EnginiConflictError {
112
+ }
113
+ /**
114
+ * More than one on-premise-agent application exists; `create` needs an `applicationSlug`
115
+ * (wire code `OPA_APPLICATION_AMBIGUOUS`). `candidateSlugs` is the only place a caller can
116
+ * learn them: `/v1/applications` does not list OPA applications.
117
+ */
118
+ export class EnginiOpaApplicationAmbiguousError extends EnginiConflictError {
119
+ candidateSlugs;
120
+ constructor(message, candidateSlugs, options) {
121
+ super(message, options);
122
+ this.candidateSlugs = candidateSlugs;
123
+ }
124
+ }
125
+ /**
126
+ * The agent did not answer a live round-trip within the server's bound (wire code
127
+ * `OPA_AGENT_TIMEOUT`, 504). Extends `EnginiServerError` rather than `EnginiTimeoutError`:
128
+ * that one is a *client-side* deadline outside the API-error tree, whereas this is a
129
+ * server-reported outcome carrying an `errorCode`.
130
+ */
131
+ export class EnginiOpaAgentTimeoutError extends EnginiServerError {
132
+ }
133
+ /**
134
+ * The agent was reached but reported a failure collecting or applying
135
+ * (wire code `OPA_AGENT_DISPATCH_FAILED`, 502).
136
+ */
137
+ export class EnginiOpaAgentDispatchError extends EnginiServerError {
138
+ }
package/dist/http.js CHANGED
@@ -99,7 +99,14 @@ export function buildClient(baseUrl, auth, companyToken, options = {}) {
99
99
  function errorForStatus(status, error) {
100
100
  const message = errorMessage(error, status);
101
101
  const Ctor = STATUS_TO_ERROR[status] ?? (status >= 500 ? EnginiServerError : EnginiAPIError);
102
- return new Ctor(message);
102
+ // Carry the parsed body, not just its rendered message: callers need to tell
103
+ // apart conditions that share a status, and `details` is the only channel for
104
+ // structured hints (e.g. the candidate slugs on OPA_APPLICATION_AMBIGUOUS).
105
+ const body = (error ?? {});
106
+ return new Ctor(message, {
107
+ errorCode: typeof body.errorCode === "string" ? body.errorCode : undefined,
108
+ details: Array.isArray(body.details) ? body.details : [],
109
+ });
103
110
  }
104
111
  /** Run a generated operation, map errors, return parsed success data. */
105
112
  export async function call(operation, options) {
package/dist/index.d.ts CHANGED
@@ -5,8 +5,8 @@ export type { Auth } from "./auth.js";
5
5
  export { composeUserAgent } from "./http.js";
6
6
  export type { Verify } from "./http.js";
7
7
  export { VERSION } from "./version.js";
8
- export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, } from "./errors.js";
9
- export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
8
+ export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, } from "./errors.js";
9
+ export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
10
10
  export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions } from "./resources/index.js";
11
11
  export { Toolset } from "./toolset.js";
12
12
  export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
@@ -14,6 +14,7 @@ export { File } from "./files.js";
14
14
  export type { FileWire } from "./files.js";
15
15
  export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, ConnectionObject, WhoAmI, } from "./types.js";
16
16
  export type { ToolsetConnectionDto, ToolsetConnectionRequest, ToolsetDto } from "@engini/client";
17
+ export type { OpaAgentListItem, OpaAgentDetail, OpaAgentSettings, OpaAgentTokenResponse, OpaAgentCreateResponse, OpaReleaseManifest, CreateOpaAgentRequest, UpdateOpaAgentRequest, } from "@engini/client";
17
18
  export type { McpServerPublicDto, McpServerConnectionDto, McpServerConnectionRequest, McpServerWorkflowDto, McpServerWorkflowRequest, McpAvailableToolDto, } from "@engini/client";
18
19
  export type { Provider, ToolCall, ToolResultOptions } from "./providers/base.js";
19
20
  export { OpenAIProvider } from "./providers/openai.js";
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@ export { Engini, DEFAULT_BASE_URL } from "./client.js";
2
2
  export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
3
3
  export { composeUserAgent } from "./http.js";
4
4
  export { VERSION } from "./version.js";
5
- export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, } from "./errors.js";
6
- export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
5
+ export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, } from "./errors.js";
6
+ export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
7
7
  export { Toolset } from "./toolset.js";
8
8
  export { File } from "./files.js";
9
9
  export { OpenAIProvider } from "./providers/openai.js";
@@ -3,5 +3,7 @@ export type { ToolsGetOptions, ToolsExecuteOptions } from "./tools.js";
3
3
  export { ConnectionsResource, refreshFailed } from "./connections.js";
4
4
  export { ToolsetsResource } from "./toolsets.js";
5
5
  export { McpResource } from "./mcp.js";
6
+ export { OpaResource } from "./opa.js";
7
+ export type { OpaClient } from "./opa.js";
6
8
  export { ApplicationsResource } from "./applications.js";
7
9
  export type { ApplicationsListOptions } from "./applications.js";
@@ -2,4 +2,5 @@ export { ToolsResource } from "./tools.js";
2
2
  export { ConnectionsResource, refreshFailed } from "./connections.js";
3
3
  export { ToolsetsResource } from "./toolsets.js";
4
4
  export { McpResource } from "./mcp.js";
5
+ export { OpaResource } from "./opa.js";
5
6
  export { ApplicationsResource } from "./applications.js";
@@ -0,0 +1,175 @@
1
+ /**
2
+ * On-premise agents resource — provision, inspect, configure and credential OPA agents.
3
+ *
4
+ * An on-premise agent (OPA) is the Engini component a customer runs on their own
5
+ * hardware, behind their firewall, to reach systems the cloud cannot: SQL Server,
6
+ * Oracle, Priority ERP, file shares. It polls Engini for work; Engini never connects
7
+ * to it. Every operation here that "talks to the agent" therefore waits for the
8
+ * agent's next poll, bounded server-side.
9
+ *
10
+ * Agents are NOT connections on this surface: `client.connections` never returns them,
11
+ * and `connections.get(agentId)` is a 404.
12
+ */
13
+ import { type OpaAgentCreateResponse, type OpaAgentDetail, type OpaAgentListItem, type OpaAgentTokenResponse, type OpaReleaseManifest } from "@engini/client";
14
+ import { type Transport } from "../http.js";
15
+ /** The settings members every write accepts. Each is independently optional. */
16
+ interface OpaSettingsParams {
17
+ parallelTasks?: number;
18
+ pullPeriodSeconds?: number;
19
+ logLevel?: string;
20
+ }
21
+ /** Minimal client surface this resource needs (satisfied by `Engini`). */
22
+ export interface OpaClient {
23
+ _transport: Transport;
24
+ }
25
+ export declare class OpaResource {
26
+ private readonly client;
27
+ constructor(client: OpaClient);
28
+ /**
29
+ * Remap a 404 onto the OPA-specific not-found, which the CLI maps to its
30
+ * NOT_FOUND exit code. Anything else passes through untouched.
31
+ *
32
+ * Unlike the MCP equivalent the id is echoed back: an agent id is an ordinary
33
+ * integer, not a secret-equivalent URL component, so it is safe in an error
34
+ * string and it is the one thing that makes the message actionable.
35
+ */
36
+ private retypeNotFound;
37
+ /**
38
+ * Every on-premise agent on the account, paginated.
39
+ *
40
+ * `status` is one of `WaitingForConnection`, `Online`, `Offline` or `Disabled`
41
+ * (case-insensitive on the wire; an unknown value is a 400, not a silently-ignored
42
+ * filter). `name` is a substring match.
43
+ */
44
+ list(params?: {
45
+ status?: string;
46
+ name?: string;
47
+ }): Promise<OpaAgentListItem[]>;
48
+ /**
49
+ * One agent's status, self-reported version, last heartbeat and settings.
50
+ *
51
+ * Throws `EnginiOpaAgentNotFoundError` when the id is unknown, belongs to another
52
+ * account, or is not an on-premise agent — the API answers 404 for all three
53
+ * deliberately and does not distinguish them.
54
+ */
55
+ get(agentId: number): Promise<OpaAgentDetail>;
56
+ /**
57
+ * Where to download the current agent installer.
58
+ *
59
+ * `degraded: true` means the release manifest was not reachable and the result was
60
+ * reconstructed from the installer URL alone: `sha256`, `sizeBytes` and `releasedAt`
61
+ * are then null. A caller that needs integrity verification should refuse a degraded
62
+ * manifest.
63
+ */
64
+ latestRelease(): Promise<OpaReleaseManifest>;
65
+ /**
66
+ * Build a settings object carrying ONLY what the caller supplied, or `undefined`
67
+ * when nothing was.
68
+ *
69
+ * Every member is nullable on the wire and absent means "leave it alone / use the
70
+ * server default". A client-side default here would either override a real value on
71
+ * update or be rejected on create: the minimums are the connector's own declared
72
+ * metadata, read server-side. Duplicating those numbers here is how they drifted
73
+ * before.
74
+ */
75
+ private static settings;
76
+ /**
77
+ * Retype a 409 `OPA_APPLICATION_AMBIGUOUS` so it carries the candidate slugs.
78
+ *
79
+ * They arrive as `details[].issue === "applicationSlug: <slug>"`, and are worth the
80
+ * parsing: `/v1/applications` does not list OPA applications, so this error is the
81
+ * only way a caller can discover what to pass as `applicationSlug`.
82
+ */
83
+ private retypeAmbiguous;
84
+ /**
85
+ * Register a new on-premise agent. The response carries its token.
86
+ *
87
+ * The token is the credential the agent uses to authenticate to Engini; it is
88
+ * returned here so a box can be provisioned in one round-trip. Treat the result as a
89
+ * secret. Settings you omit take the server's defaults (2 parallel tasks, 10s pull,
90
+ * `Information`).
91
+ *
92
+ * `applicationSlug` is only needed when more than one on-premise-agent application
93
+ * exists; `EnginiOpaApplicationAmbiguousError.candidateSlugs` tells you what to pass.
94
+ */
95
+ create(params: {
96
+ name: string;
97
+ description?: string;
98
+ applicationSlug?: string;
99
+ } & OpaSettingsParams): Promise<OpaAgentCreateResponse>;
100
+ /**
101
+ * Change an agent's name, description or runtime settings.
102
+ *
103
+ * **Merges, does not replace**: anything you omit is left unchanged. This is
104
+ * deliberately unlike `connections.update`, which replaces its whole field map.
105
+ *
106
+ * Check `appliedToAgent` on the result. `false` means the change is stored but the
107
+ * agent was not Online to receive it — it picks the new settings up when it
108
+ * reconnects. That is an outcome, not an error.
109
+ */
110
+ update(agentId: number, params: {
111
+ name?: string;
112
+ description?: string;
113
+ } & OpaSettingsParams): Promise<OpaAgentDetail>;
114
+ /** Permanently delete an agent. Workflows routed through it stop working. */
115
+ delete(agentId: number): Promise<void>;
116
+ /**
117
+ * Re-enable a disabled agent; it returns to `WaitingForConnection`.
118
+ *
119
+ * A no-op on an agent that is not disabled — its reported liveness is left alone
120
+ * rather than being reset.
121
+ */
122
+ enable(agentId: number): Promise<OpaAgentDetail>;
123
+ /**
124
+ * Disable an agent so it stops being marked online.
125
+ *
126
+ * Not a delete and not a pause of in-flight work: tasks it already holds still run
127
+ * to completion.
128
+ */
129
+ disable(agentId: number): Promise<OpaAgentDetail>;
130
+ /**
131
+ * The agent's token — the credential it authenticates to Engini with.
132
+ *
133
+ * Treat the result as a secret: it is equivalent to the agent's identity. Reads are
134
+ * audit-logged server-side.
135
+ */
136
+ getToken(agentId: number): Promise<OpaAgentTokenResponse>;
137
+ /**
138
+ * Issue a new token, invalidating the current one immediately.
139
+ *
140
+ * **Destructive to a running agent**: it stops authenticating the moment this
141
+ * resolves and stays down until it is reconfigured with the new token.
142
+ *
143
+ * The API requires `confirm=true` and the SDK sends it unconditionally — the human
144
+ * confirmation gate belongs in the CLI, not in library code where a prompt would be
145
+ * unreachable.
146
+ */
147
+ rotateToken(agentId: number): Promise<OpaAgentTokenResponse>;
148
+ /**
149
+ * Map the OPA agent-side wire codes onto their typed errors.
150
+ *
151
+ * Returns the error untouched for anything else, so an unrelated 409 or 5xx stays
152
+ * exactly what the status mapping made it. Discriminating on `errorCode` rather than
153
+ * the status matters: OPA puts three distinct conditions on 409/5xx.
154
+ */
155
+ private retypeAgentError;
156
+ /**
157
+ * Collect the agent's logs as a zip archive, returned as bytes.
158
+ *
159
+ * A live round-trip to the agent, bounded server-side. Throws
160
+ * `EnginiOpaAgentOfflineError` when the agent is not Online,
161
+ * `EnginiOpaAgentTimeoutError` when it did not answer in time, and
162
+ * `EnginiOpaAgentDispatchError` when it answered with a failure.
163
+ *
164
+ * Returns bytes rather than writing a file: the SDK does not know where the caller
165
+ * wants it. `engini opa logs -o` does the writing.
166
+ *
167
+ * `parseAs: "blob"` is passed explicitly rather than relying on hey-api's default
168
+ * `"auto"`. Auto picks a parser from the response Content-Type, so a server or proxy
169
+ * that answered `application/octet-stream` — or nothing — would land on a different
170
+ * branch and hand back something that is not a Blob. This is the only operation in
171
+ * the SDK whose body is genuinely binary, so it is the only one where that matters.
172
+ */
173
+ downloadLogs(agentId: number): Promise<Uint8Array>;
174
+ }
175
+ export {};
@@ -0,0 +1,322 @@
1
+ /**
2
+ * On-premise agents resource — provision, inspect, configure and credential OPA agents.
3
+ *
4
+ * An on-premise agent (OPA) is the Engini component a customer runs on their own
5
+ * hardware, behind their firewall, to reach systems the cloud cannot: SQL Server,
6
+ * Oracle, Priority ERP, file shares. It polls Engini for work; Engini never connects
7
+ * to it. Every operation here that "talks to the agent" therefore waits for the
8
+ * agent's next poll, bounded server-side.
9
+ *
10
+ * Agents are NOT connections on this surface: `client.connections` never returns them,
11
+ * and `connections.get(agentId)` is a 404.
12
+ */
13
+ import { opaAgentsCreateAgent, opaAgentsDeleteAgent, opaAgentsDisableAgent, opaAgentsEnableAgent, opaAgentsGetAgent, opaAgentsGetAgentLogs, opaAgentsGetAgentToken, opaAgentsGetLatestRelease, opaAgentsListAgents, opaAgentsRotateAgentToken, opaAgentsUpdateAgent, } from "@engini/client";
14
+ import { call } from "../http.js";
15
+ import { paginate, collect } from "../pagination.js";
16
+ import { EnginiAPIError, EnginiNotFoundError, EnginiOpaAgentDispatchError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaAgentTimeoutError, EnginiOpaApplicationAmbiguousError, } from "../errors.js";
17
+ export class OpaResource {
18
+ client;
19
+ constructor(client) {
20
+ this.client = client;
21
+ }
22
+ /**
23
+ * Remap a 404 onto the OPA-specific not-found, which the CLI maps to its
24
+ * NOT_FOUND exit code. Anything else passes through untouched.
25
+ *
26
+ * Unlike the MCP equivalent the id is echoed back: an agent id is an ordinary
27
+ * integer, not a secret-equivalent URL component, so it is safe in an error
28
+ * string and it is the one thing that makes the message actionable.
29
+ */
30
+ retypeNotFound(err, agentId) {
31
+ if (err instanceof EnginiNotFoundError) {
32
+ return new EnginiOpaAgentNotFoundError(`Unknown on-premise agent id ${agentId}.`);
33
+ }
34
+ return err;
35
+ }
36
+ // ---- reads -----------------------------------------------------------------------
37
+ /**
38
+ * Every on-premise agent on the account, paginated.
39
+ *
40
+ * `status` is one of `WaitingForConnection`, `Online`, `Offline` or `Disabled`
41
+ * (case-insensitive on the wire; an unknown value is a 400, not a silently-ignored
42
+ * filter). `name` is a substring match.
43
+ */
44
+ async list(params = {}) {
45
+ const transport = this.client._transport;
46
+ return collect(paginate((offset, top) => call(opaAgentsListAgents, {
47
+ client: transport,
48
+ query: { offset, top, status: params.status, name: params.name },
49
+ })));
50
+ }
51
+ /**
52
+ * One agent's status, self-reported version, last heartbeat and settings.
53
+ *
54
+ * Throws `EnginiOpaAgentNotFoundError` when the id is unknown, belongs to another
55
+ * account, or is not an on-premise agent — the API answers 404 for all three
56
+ * deliberately and does not distinguish them.
57
+ */
58
+ async get(agentId) {
59
+ try {
60
+ return await call(opaAgentsGetAgent, {
61
+ client: this.client._transport,
62
+ path: { id: agentId },
63
+ });
64
+ }
65
+ catch (err) {
66
+ throw this.retypeNotFound(err, agentId);
67
+ }
68
+ }
69
+ /**
70
+ * Where to download the current agent installer.
71
+ *
72
+ * `degraded: true` means the release manifest was not reachable and the result was
73
+ * reconstructed from the installer URL alone: `sha256`, `sizeBytes` and `releasedAt`
74
+ * are then null. A caller that needs integrity verification should refuse a degraded
75
+ * manifest.
76
+ */
77
+ async latestRelease() {
78
+ return call(opaAgentsGetLatestRelease, { client: this.client._transport });
79
+ }
80
+ // ---- lifecycle -------------------------------------------------------------------
81
+ /**
82
+ * Build a settings object carrying ONLY what the caller supplied, or `undefined`
83
+ * when nothing was.
84
+ *
85
+ * Every member is nullable on the wire and absent means "leave it alone / use the
86
+ * server default". A client-side default here would either override a real value on
87
+ * update or be rejected on create: the minimums are the connector's own declared
88
+ * metadata, read server-side. Duplicating those numbers here is how they drifted
89
+ * before.
90
+ */
91
+ static settings(params) {
92
+ const { parallelTasks, pullPeriodSeconds, logLevel } = params;
93
+ if (parallelTasks === undefined && pullPeriodSeconds === undefined && logLevel === undefined) {
94
+ return undefined;
95
+ }
96
+ return { parallelTasks, pullPeriodSeconds, logLevel };
97
+ }
98
+ /**
99
+ * Retype a 409 `OPA_APPLICATION_AMBIGUOUS` so it carries the candidate slugs.
100
+ *
101
+ * They arrive as `details[].issue === "applicationSlug: <slug>"`, and are worth the
102
+ * parsing: `/v1/applications` does not list OPA applications, so this error is the
103
+ * only way a caller can discover what to pass as `applicationSlug`.
104
+ */
105
+ retypeAmbiguous(err) {
106
+ if (!(err instanceof EnginiAPIError) || err.errorCode !== "OPA_APPLICATION_AMBIGUOUS") {
107
+ return err;
108
+ }
109
+ const prefix = "applicationSlug: ";
110
+ const slugs = err.details
111
+ .map((d) => d.issue)
112
+ .filter((issue) => typeof issue === "string" && issue.startsWith(prefix))
113
+ .map((issue) => issue.slice(prefix.length));
114
+ return new EnginiOpaApplicationAmbiguousError(err.message, slugs, {
115
+ errorCode: err.errorCode,
116
+ details: err.details,
117
+ });
118
+ }
119
+ /**
120
+ * Register a new on-premise agent. The response carries its token.
121
+ *
122
+ * The token is the credential the agent uses to authenticate to Engini; it is
123
+ * returned here so a box can be provisioned in one round-trip. Treat the result as a
124
+ * secret. Settings you omit take the server's defaults (2 parallel tasks, 10s pull,
125
+ * `Information`).
126
+ *
127
+ * `applicationSlug` is only needed when more than one on-premise-agent application
128
+ * exists; `EnginiOpaApplicationAmbiguousError.candidateSlugs` tells you what to pass.
129
+ */
130
+ async create(params) {
131
+ try {
132
+ return await call(opaAgentsCreateAgent, {
133
+ client: this.client._transport,
134
+ body: {
135
+ name: params.name,
136
+ description: params.description,
137
+ applicationSlug: params.applicationSlug,
138
+ settings: OpaResource.settings(params),
139
+ },
140
+ });
141
+ }
142
+ catch (err) {
143
+ throw this.retypeAmbiguous(err);
144
+ }
145
+ }
146
+ /**
147
+ * Change an agent's name, description or runtime settings.
148
+ *
149
+ * **Merges, does not replace**: anything you omit is left unchanged. This is
150
+ * deliberately unlike `connections.update`, which replaces its whole field map.
151
+ *
152
+ * Check `appliedToAgent` on the result. `false` means the change is stored but the
153
+ * agent was not Online to receive it — it picks the new settings up when it
154
+ * reconnects. That is an outcome, not an error.
155
+ */
156
+ async update(agentId, params) {
157
+ try {
158
+ return await call(opaAgentsUpdateAgent, {
159
+ client: this.client._transport,
160
+ path: { id: agentId },
161
+ body: {
162
+ name: params.name,
163
+ description: params.description,
164
+ settings: OpaResource.settings(params),
165
+ },
166
+ });
167
+ }
168
+ catch (err) {
169
+ throw this.retypeNotFound(err, agentId);
170
+ }
171
+ }
172
+ /** Permanently delete an agent. Workflows routed through it stop working. */
173
+ async delete(agentId) {
174
+ try {
175
+ await call(opaAgentsDeleteAgent, {
176
+ client: this.client._transport,
177
+ path: { id: agentId },
178
+ });
179
+ }
180
+ catch (err) {
181
+ throw this.retypeNotFound(err, agentId);
182
+ }
183
+ }
184
+ /**
185
+ * Re-enable a disabled agent; it returns to `WaitingForConnection`.
186
+ *
187
+ * A no-op on an agent that is not disabled — its reported liveness is left alone
188
+ * rather than being reset.
189
+ */
190
+ async enable(agentId) {
191
+ try {
192
+ return await call(opaAgentsEnableAgent, {
193
+ client: this.client._transport,
194
+ path: { id: agentId },
195
+ });
196
+ }
197
+ catch (err) {
198
+ throw this.retypeNotFound(err, agentId);
199
+ }
200
+ }
201
+ /**
202
+ * Disable an agent so it stops being marked online.
203
+ *
204
+ * Not a delete and not a pause of in-flight work: tasks it already holds still run
205
+ * to completion.
206
+ */
207
+ async disable(agentId) {
208
+ try {
209
+ return await call(opaAgentsDisableAgent, {
210
+ client: this.client._transport,
211
+ path: { id: agentId },
212
+ });
213
+ }
214
+ catch (err) {
215
+ throw this.retypeNotFound(err, agentId);
216
+ }
217
+ }
218
+ // ---- credential ------------------------------------------------------------------
219
+ /**
220
+ * The agent's token — the credential it authenticates to Engini with.
221
+ *
222
+ * Treat the result as a secret: it is equivalent to the agent's identity. Reads are
223
+ * audit-logged server-side.
224
+ */
225
+ async getToken(agentId) {
226
+ try {
227
+ return await call(opaAgentsGetAgentToken, {
228
+ client: this.client._transport,
229
+ path: { id: agentId },
230
+ });
231
+ }
232
+ catch (err) {
233
+ throw this.retypeNotFound(err, agentId);
234
+ }
235
+ }
236
+ /**
237
+ * Issue a new token, invalidating the current one immediately.
238
+ *
239
+ * **Destructive to a running agent**: it stops authenticating the moment this
240
+ * resolves and stays down until it is reconfigured with the new token.
241
+ *
242
+ * The API requires `confirm=true` and the SDK sends it unconditionally — the human
243
+ * confirmation gate belongs in the CLI, not in library code where a prompt would be
244
+ * unreachable.
245
+ */
246
+ async rotateToken(agentId) {
247
+ try {
248
+ return await call(opaAgentsRotateAgentToken, {
249
+ client: this.client._transport,
250
+ path: { id: agentId },
251
+ query: { confirm: true },
252
+ });
253
+ }
254
+ catch (err) {
255
+ throw this.retypeNotFound(err, agentId);
256
+ }
257
+ }
258
+ // ---- logs ------------------------------------------------------------------------
259
+ /**
260
+ * Map the OPA agent-side wire codes onto their typed errors.
261
+ *
262
+ * Returns the error untouched for anything else, so an unrelated 409 or 5xx stays
263
+ * exactly what the status mapping made it. Discriminating on `errorCode` rather than
264
+ * the status matters: OPA puts three distinct conditions on 409/5xx.
265
+ */
266
+ retypeAgentError(err) {
267
+ if (!(err instanceof EnginiAPIError))
268
+ return err;
269
+ const options = { errorCode: err.errorCode, details: err.details };
270
+ switch (err.errorCode) {
271
+ case "OPA_AGENT_OFFLINE":
272
+ return new EnginiOpaAgentOfflineError(err.message, options);
273
+ case "OPA_AGENT_TIMEOUT":
274
+ return new EnginiOpaAgentTimeoutError(err.message, options);
275
+ case "OPA_AGENT_DISPATCH_FAILED":
276
+ return new EnginiOpaAgentDispatchError(err.message, options);
277
+ default:
278
+ return err;
279
+ }
280
+ }
281
+ /**
282
+ * Collect the agent's logs as a zip archive, returned as bytes.
283
+ *
284
+ * A live round-trip to the agent, bounded server-side. Throws
285
+ * `EnginiOpaAgentOfflineError` when the agent is not Online,
286
+ * `EnginiOpaAgentTimeoutError` when it did not answer in time, and
287
+ * `EnginiOpaAgentDispatchError` when it answered with a failure.
288
+ *
289
+ * Returns bytes rather than writing a file: the SDK does not know where the caller
290
+ * wants it. `engini opa logs -o` does the writing.
291
+ *
292
+ * `parseAs: "blob"` is passed explicitly rather than relying on hey-api's default
293
+ * `"auto"`. Auto picks a parser from the response Content-Type, so a server or proxy
294
+ * that answered `application/octet-stream` — or nothing — would land on a different
295
+ * branch and hand back something that is not a Blob. This is the only operation in
296
+ * the SDK whose body is genuinely binary, so it is the only one where that matters.
297
+ */
298
+ async downloadLogs(agentId) {
299
+ let payload;
300
+ try {
301
+ payload = await call(opaAgentsGetAgentLogs, {
302
+ client: this.client._transport,
303
+ path: { id: agentId },
304
+ // `as const` is load-bearing: through `call`'s generic inference the literal
305
+ // would otherwise widen to `string` and fail the generated option type.
306
+ parseAs: "blob",
307
+ });
308
+ }
309
+ catch (err) {
310
+ throw this.retypeAgentError(this.retypeNotFound(err, agentId));
311
+ }
312
+ if (payload instanceof Blob)
313
+ return new Uint8Array(await payload.arrayBuffer());
314
+ if (payload instanceof Uint8Array)
315
+ return payload;
316
+ if (payload instanceof ArrayBuffer)
317
+ return new Uint8Array(payload);
318
+ // A 2xx with no body at all: report it as the agent having produced nothing rather
319
+ // than returning a Uint8Array built from something that is not bytes.
320
+ throw new EnginiOpaAgentDispatchError(`OPA agent ${agentId} returned no log archive.`);
321
+ }
322
+ }
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.18.0";
6
+ export declare const VERSION = "0.19.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.18.0";
6
+ export const VERSION = "0.19.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.18.0",
3
+ "version": "0.19.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.7.0",
30
+ "@engini/client": "0.8.0",
31
31
  "undici": "^6.0.0"
32
32
  },
33
33
  "devDependencies": {