@agentpress/sdk 0.2.78 → 0.2.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,368 +1,364 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ActionsClient: () => ActionsClient,
24
- AgentPress: () => AgentPress,
25
- AgentPressError: () => AgentPressError,
26
- ConfigurationError: () => ConfigurationError,
27
- HttpError: () => HttpError,
28
- TimeoutError: () => TimeoutError,
29
- WebhookSignatureError: () => WebhookSignatureError
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
-
33
- // src/errors.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_crypto = require("node:crypto");
3
+ //#region src/errors.ts
4
+ /**
5
+ * Base error class for all SDK errors. Catch this to handle any error
6
+ * thrown by the AgentPress SDK regardless of specific type.
7
+ */
34
8
  var AgentPressError = class extends Error {
35
- constructor(message) {
36
- super(message);
37
- this.name = "AgentPressError";
38
- Object.setPrototypeOf(this, new.target.prototype);
39
- }
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "AgentPressError";
12
+ Object.setPrototypeOf(this, new.target.prototype);
13
+ }
40
14
  };
15
+ /**
16
+ * Thrown at construction time when `AgentPressOptions` contains invalid values
17
+ * (e.g., non-positive timeout, malformed `webhookSecret`).
18
+ */
41
19
  var ConfigurationError = class extends AgentPressError {
42
- constructor(message) {
43
- super(message);
44
- this.name = "ConfigurationError";
45
- Object.setPrototypeOf(this, new.target.prototype);
46
- }
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "ConfigurationError";
23
+ Object.setPrototypeOf(this, new.target.prototype);
24
+ }
47
25
  };
26
+ /**
27
+ * Thrown when the API returns a non-2xx HTTP response.
28
+ *
29
+ * Properties:
30
+ * - `statusCode` - HTTP status code (e.g., 401, 404, 500)
31
+ * - `responseBody` - Raw response body text for debugging
32
+ * - `url` - The full request URL that failed
33
+ */
48
34
  var HttpError = class extends AgentPressError {
49
- statusCode;
50
- responseBody;
51
- url;
52
- constructor(statusCode, responseBody, url) {
53
- super(`HTTP ${statusCode} from ${url}`);
54
- this.name = "HttpError";
55
- this.statusCode = statusCode;
56
- this.responseBody = responseBody;
57
- this.url = url;
58
- Object.setPrototypeOf(this, new.target.prototype);
59
- }
35
+ statusCode;
36
+ responseBody;
37
+ url;
38
+ constructor(statusCode, responseBody, url) {
39
+ super(`HTTP ${statusCode} from ${url}`);
40
+ this.name = "HttpError";
41
+ this.statusCode = statusCode;
42
+ this.responseBody = responseBody;
43
+ this.url = url;
44
+ Object.setPrototypeOf(this, new.target.prototype);
45
+ }
60
46
  };
47
+ /** Thrown when a request exceeds the configured `timeout` (default 30s). */
61
48
  var TimeoutError = class extends AgentPressError {
62
- constructor(url, timeout) {
63
- super(`Request to ${url} timed out after ${timeout}ms`);
64
- this.name = "TimeoutError";
65
- Object.setPrototypeOf(this, new.target.prototype);
66
- }
49
+ constructor(url, timeout) {
50
+ super(`Request to ${url} timed out after ${timeout}ms`);
51
+ this.name = "TimeoutError";
52
+ Object.setPrototypeOf(this, new.target.prototype);
53
+ }
67
54
  };
55
+ /** Thrown by {@link WebhooksClient.verifyOrThrow} when an inbound webhook signature is invalid or expired. */
68
56
  var WebhookSignatureError = class extends AgentPressError {
69
- constructor(message) {
70
- super(message);
71
- this.name = "WebhookSignatureError";
72
- Object.setPrototypeOf(this, new.target.prototype);
73
- }
57
+ constructor(message) {
58
+ super(message);
59
+ this.name = "WebhookSignatureError";
60
+ Object.setPrototypeOf(this, new.target.prototype);
61
+ }
74
62
  };
75
-
76
- // src/utils.ts
77
- var import_node_crypto = require("crypto");
63
+ //#endregion
64
+ //#region src/utils.ts
78
65
  function randomMessageId() {
79
- return `msg_${(0, import_node_crypto.randomUUID)()}`;
66
+ return `msg_${(0, node_crypto.randomUUID)()}`;
80
67
  }
81
-
82
- // src/webhooks/signing.ts
83
- var import_node_crypto2 = require("crypto");
84
- var SIGNATURE_PREFIX = "v1,";
85
- var DEFAULT_TOLERANCE_SECONDS = 5 * 60;
68
+ //#endregion
69
+ //#region src/webhooks/signing.ts
70
+ const SIGNATURE_PREFIX = "v1,";
71
+ const DEFAULT_TOLERANCE_SECONDS = 300;
72
+ /**
73
+ * Sign a webhook payload using Svix-compatible HMAC-SHA256.
74
+ *
75
+ * @param secret - The webhook secret (with "whsec_" prefix)
76
+ * @param msgId - Unique message ID (e.g., "msg_<uuid>")
77
+ * @param timestamp - Unix timestamp in seconds
78
+ * @param body - JSON stringified payload
79
+ * @returns Signature string in format "v1,<base64>"
80
+ */
86
81
  function sign(secret, msgId, timestamp, body) {
87
- const secretBytes = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
88
- const message = `${msgId}.${timestamp}.${body}`;
89
- const signature = (0, import_node_crypto2.createHmac)("sha256", secretBytes).update(message).digest("base64");
90
- return `${SIGNATURE_PREFIX}${signature}`;
82
+ const secretBytes = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
83
+ const message = `${msgId}.${timestamp}.${body}`;
84
+ return `${SIGNATURE_PREFIX}${(0, node_crypto.createHmac)("sha256", secretBytes).update(message).digest("base64")}`;
91
85
  }
86
+ /**
87
+ * Verify a Svix webhook signature.
88
+ *
89
+ * @param secret - The webhook secret (with "whsec_" prefix)
90
+ * @param payload - Raw request body (string or Buffer)
91
+ * @param headers - Svix headers object
92
+ * @param toleranceSeconds - Max age of signature in seconds (default: 5 min)
93
+ * @returns true if valid, false if invalid or expired
94
+ */
92
95
  function verify(secret, payload, headers, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS) {
93
- const msgId = headers["svix-id"];
94
- const timestampStr = headers["svix-timestamp"];
95
- const signatureHeader = headers["svix-signature"];
96
- const timestamp = parseInt(timestampStr, 10);
97
- if (Number.isNaN(timestamp)) return false;
98
- const now = Math.floor(Date.now() / 1e3);
99
- if (Math.abs(now - timestamp) > toleranceSeconds) return false;
100
- const body = typeof payload === "string" ? payload : payload.toString("utf-8");
101
- const expected = sign(secret, msgId, timestamp, body);
102
- const signatures = signatureHeader.split(" ");
103
- const expectedBuf = Buffer.from(expected);
104
- for (const sig of signatures) {
105
- const sigBuf = Buffer.from(sig);
106
- if (sigBuf.length === expectedBuf.length && (0, import_node_crypto2.timingSafeEqual)(sigBuf, expectedBuf)) {
107
- return true;
108
- }
109
- }
110
- return false;
96
+ const msgId = headers["svix-id"];
97
+ const timestampStr = headers["svix-timestamp"];
98
+ const signatureHeader = headers["svix-signature"];
99
+ const timestamp = parseInt(timestampStr, 10);
100
+ if (Number.isNaN(timestamp)) return false;
101
+ const now = Math.floor(Date.now() / 1e3);
102
+ if (Math.abs(now - timestamp) > toleranceSeconds) return false;
103
+ const expected = sign(secret, msgId, timestamp, typeof payload === "string" ? payload : payload.toString("utf-8"));
104
+ const signatures = signatureHeader.split(" ");
105
+ const expectedBuf = Buffer.from(expected);
106
+ for (const sig of signatures) {
107
+ const sigBuf = Buffer.from(sig);
108
+ if (sigBuf.length === expectedBuf.length && (0, node_crypto.timingSafeEqual)(sigBuf, expectedBuf)) return true;
109
+ }
110
+ return false;
111
111
  }
112
-
113
- // src/actions/client.ts
112
+ //#endregion
113
+ //#region src/actions/client.ts
114
+ /**
115
+ * Client for programmatically approving or rejecting staged actions.
116
+ * Uses HMAC-SHA256 signing (Svix-compatible), identical to {@link WebhooksClient}.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const client = new AgentPress({ webhookSecret: "whsec_...", org: "my-org" });
121
+ *
122
+ * // Approve a staged action
123
+ * await client.actions.approve("act_123", {
124
+ * action: "my_webhook_action",
125
+ * });
126
+ *
127
+ * // Reject with a reason
128
+ * await client.actions.reject("act_456", {
129
+ * action: "my_webhook_action",
130
+ * reason: "Insufficient data",
131
+ * });
132
+ * ```
133
+ */
114
134
  var ActionsClient = class {
115
- options;
116
- http;
117
- constructor(options, http) {
118
- this.options = options;
119
- this.http = http;
120
- }
121
- /**
122
- * Approve a staged action, optionally modifying the tool call.
123
- *
124
- * @throws ConfigurationError if webhookSecret is not configured
125
- * @throws HttpError on non-2xx response
126
- * @throws TimeoutError if request exceeds timeout
127
- */
128
- async approve(actionId, params) {
129
- return this.manage(actionId, params.action, "approve", {
130
- editedToolCall: params.editedToolCall
131
- });
132
- }
133
- /**
134
- * Reject a staged action.
135
- *
136
- * @throws ConfigurationError if webhookSecret is not configured
137
- * @throws HttpError on non-2xx response
138
- * @throws TimeoutError if request exceeds timeout
139
- */
140
- async reject(actionId, params) {
141
- return this.manage(actionId, params.action, "reject", {
142
- reason: params.reason
143
- });
144
- }
145
- async manage(actionId, webhookAction, operation, body) {
146
- if (!this.options.webhookSecret) {
147
- throw new ConfigurationError(
148
- "webhookSecret is required for action management operations"
149
- );
150
- }
151
- const path = `/webhooks/actions/${this.options.org}/${webhookAction}/manage/${actionId}/${operation}`;
152
- const bodyStr = JSON.stringify(body);
153
- const msgId = randomMessageId();
154
- const timestamp = Math.floor(Date.now() / 1e3);
155
- const signature = sign(
156
- this.options.webhookSecret,
157
- msgId,
158
- timestamp,
159
- bodyStr
160
- );
161
- return this.http.request(path, {
162
- method: "POST",
163
- body: bodyStr,
164
- headers: {
165
- "svix-id": msgId,
166
- "svix-timestamp": String(timestamp),
167
- "svix-signature": signature
168
- }
169
- });
170
- }
135
+ options;
136
+ http;
137
+ constructor(options, http) {
138
+ this.options = options;
139
+ this.http = http;
140
+ }
141
+ /**
142
+ * Approve a staged action, optionally modifying the tool call.
143
+ *
144
+ * @throws ConfigurationError if webhookSecret is not configured
145
+ * @throws HttpError on non-2xx response
146
+ * @throws TimeoutError if request exceeds timeout
147
+ */
148
+ async approve(actionId, params) {
149
+ return this.manage(actionId, params.action, "approve", { editedToolCall: params.editedToolCall });
150
+ }
151
+ /**
152
+ * Reject a staged action.
153
+ *
154
+ * @throws ConfigurationError if webhookSecret is not configured
155
+ * @throws HttpError on non-2xx response
156
+ * @throws TimeoutError if request exceeds timeout
157
+ */
158
+ async reject(actionId, params) {
159
+ return this.manage(actionId, params.action, "reject", { reason: params.reason });
160
+ }
161
+ async manage(actionId, webhookAction, operation, body) {
162
+ if (!this.options.webhookSecret) throw new ConfigurationError("webhookSecret is required for action management operations");
163
+ const path = `/webhooks/actions/${this.options.org}/${webhookAction}/manage/${actionId}/${operation}`;
164
+ const bodyStr = JSON.stringify(body);
165
+ const msgId = randomMessageId();
166
+ const timestamp = Math.floor(Date.now() / 1e3);
167
+ const signature = sign(this.options.webhookSecret, msgId, timestamp, bodyStr);
168
+ return this.http.request(path, {
169
+ method: "POST",
170
+ body: bodyStr,
171
+ headers: {
172
+ "svix-id": msgId,
173
+ "svix-timestamp": String(timestamp),
174
+ "svix-signature": signature
175
+ }
176
+ });
177
+ }
171
178
  };
172
-
173
- // src/http.ts
179
+ //#endregion
180
+ //#region src/http.ts
181
+ /**
182
+ * Internal shared HTTP client. Not part of the public API -- used by
183
+ * namespace clients (e.g., `WebhooksClient`) to make authenticated requests.
184
+ * @internal
185
+ */
174
186
  var HttpClient = class {
175
- baseUrl;
176
- timeout;
177
- onRequest;
178
- onResponse;
179
- constructor(options) {
180
- this.baseUrl = options.baseUrl;
181
- this.timeout = options.timeout;
182
- this.onRequest = options.onRequest;
183
- this.onResponse = options.onResponse;
184
- }
185
- /**
186
- * Send an HTTP request to the API. Constructs the full URL from `baseUrl` + `path`,
187
- * applies the configured timeout via `AbortSignal`, fires `onRequest`/`onResponse`
188
- * hooks, and parses the JSON response.
189
- *
190
- * @throws {TimeoutError} If the request exceeds the configured timeout.
191
- * @throws {HttpError} If the API returns a non-2xx status code.
192
- * @throws {AgentPressError} On network failures or non-JSON responses.
193
- */
194
- async request(path, init) {
195
- const url = `${this.baseUrl}${path}`;
196
- const headers = new Headers(init.headers);
197
- if (!headers.has("Content-Type")) {
198
- headers.set("Content-Type", "application/json");
199
- }
200
- const requestInit = {
201
- ...init,
202
- headers,
203
- signal: AbortSignal.timeout(this.timeout)
204
- };
205
- this.onRequest?.(url, requestInit);
206
- let response;
207
- try {
208
- response = await fetch(url, requestInit);
209
- } catch (error) {
210
- if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) {
211
- throw new TimeoutError(url, this.timeout);
212
- }
213
- const message = error instanceof Error ? error.message : "Unknown fetch error";
214
- throw new AgentPressError(`Request to ${url} failed: ${message}`);
215
- }
216
- this.onResponse?.(url, response.clone());
217
- const text = await response.text();
218
- if (!response.ok) {
219
- throw new HttpError(response.status, text, url);
220
- }
221
- try {
222
- return JSON.parse(text);
223
- } catch {
224
- throw new AgentPressError(
225
- `Expected JSON response from ${url} but received: ${text.slice(0, 200)}`
226
- );
227
- }
228
- }
187
+ baseUrl;
188
+ timeout;
189
+ onRequest;
190
+ onResponse;
191
+ constructor(options) {
192
+ this.baseUrl = options.baseUrl;
193
+ this.timeout = options.timeout;
194
+ this.onRequest = options.onRequest;
195
+ this.onResponse = options.onResponse;
196
+ }
197
+ /**
198
+ * Send an HTTP request to the API. Constructs the full URL from `baseUrl` + `path`,
199
+ * applies the configured timeout via `AbortSignal`, fires `onRequest`/`onResponse`
200
+ * hooks, and parses the JSON response.
201
+ *
202
+ * @throws {TimeoutError} If the request exceeds the configured timeout.
203
+ * @throws {HttpError} If the API returns a non-2xx status code.
204
+ * @throws {AgentPressError} On network failures or non-JSON responses.
205
+ */
206
+ async request(path, init) {
207
+ const url = `${this.baseUrl}${path}`;
208
+ const headers = new Headers(init.headers);
209
+ if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
210
+ const requestInit = {
211
+ ...init,
212
+ headers,
213
+ signal: AbortSignal.timeout(this.timeout)
214
+ };
215
+ this.onRequest?.(url, requestInit);
216
+ let response;
217
+ try {
218
+ response = await fetch(url, requestInit);
219
+ } catch (error) {
220
+ if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) throw new TimeoutError(url, this.timeout);
221
+ throw new AgentPressError(`Request to ${url} failed: ${error instanceof Error ? error.message : "Unknown fetch error"}`);
222
+ }
223
+ this.onResponse?.(url, response.clone());
224
+ const text = await response.text();
225
+ if (!response.ok) throw new HttpError(response.status, text, url);
226
+ try {
227
+ return JSON.parse(text);
228
+ } catch {
229
+ throw new AgentPressError(`Expected JSON response from ${url} but received: ${text.slice(0, 200)}`);
230
+ }
231
+ }
229
232
  };
230
-
231
- // src/webhooks/client.ts
233
+ //#endregion
234
+ //#region src/webhooks/client.ts
232
235
  var WebhooksClient = class {
233
- options;
234
- http;
235
- constructor(options, http) {
236
- this.options = options;
237
- this.http = http;
238
- }
239
- /**
240
- * Send an arbitrary webhook payload to AgentPress.
241
- * Signs the payload with HMAC-SHA256 (Svix-compatible).
242
- *
243
- * @throws ConfigurationError if webhookSecret is not configured
244
- * @throws HttpError on non-2xx response
245
- * @throws TimeoutError if request exceeds timeout
246
- */
247
- async send(params) {
248
- if (!this.options.webhookSecret) {
249
- throw new ConfigurationError(
250
- "webhookSecret is required for webhook operations"
251
- );
252
- }
253
- const path = `/webhooks/actions/${this.options.org}/${params.action}`;
254
- const body = JSON.stringify(params.payload);
255
- const msgId = randomMessageId();
256
- const timestamp = Math.floor(Date.now() / 1e3);
257
- const signature = sign(this.options.webhookSecret, msgId, timestamp, body);
258
- return this.http.request(path, {
259
- method: "POST",
260
- body,
261
- headers: {
262
- "svix-id": msgId,
263
- "svix-timestamp": String(timestamp),
264
- "svix-signature": signature
265
- }
266
- });
267
- }
268
- /**
269
- * Verify an inbound Svix webhook signature.
270
- *
271
- * @returns true if valid, false if invalid or expired
272
- * @throws ConfigurationError if webhookSecret is not configured
273
- */
274
- verify(params) {
275
- if (!this.options.webhookSecret) {
276
- throw new ConfigurationError(
277
- "webhookSecret is required for webhook verification"
278
- );
279
- }
280
- return verify(
281
- this.options.webhookSecret,
282
- params.payload,
283
- params.headers
284
- );
285
- }
286
- /**
287
- * Verify an inbound Svix webhook signature, throwing on failure.
288
- * Useful for middleware patterns where invalid signatures should halt processing.
289
- *
290
- * @throws WebhookSignatureError if signature is invalid or expired
291
- * @throws ConfigurationError if webhookSecret is not configured
292
- */
293
- verifyOrThrow(params) {
294
- if (!this.verify(params)) {
295
- throw new WebhookSignatureError("Invalid webhook signature");
296
- }
297
- }
298
- /**
299
- * Verify and parse an inbound webhook from AgentPress.
300
- * Combines signature verification with JSON parsing and type casting.
301
- * This is the recommended way to handle incoming webhooks.
302
- *
303
- * @throws WebhookSignatureError if signature is invalid or expired
304
- * @throws ConfigurationError if webhookSecret is not configured
305
- * @throws AgentPressError if payload is not valid JSON
306
- */
307
- constructEvent(params) {
308
- this.verifyOrThrow(params);
309
- const body = typeof params.payload === "string" ? params.payload : params.payload.toString("utf-8");
310
- try {
311
- return JSON.parse(body);
312
- } catch {
313
- throw new AgentPressError("Webhook payload is not valid JSON");
314
- }
315
- }
236
+ options;
237
+ http;
238
+ constructor(options, http) {
239
+ this.options = options;
240
+ this.http = http;
241
+ }
242
+ /**
243
+ * Send an arbitrary webhook payload to AgentPress.
244
+ * Signs the payload with HMAC-SHA256 (Svix-compatible).
245
+ *
246
+ * @throws ConfigurationError if webhookSecret is not configured
247
+ * @throws HttpError on non-2xx response
248
+ * @throws TimeoutError if request exceeds timeout
249
+ */
250
+ async send(params) {
251
+ if (!this.options.webhookSecret) throw new ConfigurationError("webhookSecret is required for webhook operations");
252
+ const path = `/webhooks/actions/${this.options.org}/${params.action}`;
253
+ const body = JSON.stringify(params.payload);
254
+ const msgId = randomMessageId();
255
+ const timestamp = Math.floor(Date.now() / 1e3);
256
+ const signature = sign(this.options.webhookSecret, msgId, timestamp, body);
257
+ return this.http.request(path, {
258
+ method: "POST",
259
+ body,
260
+ headers: {
261
+ "svix-id": msgId,
262
+ "svix-timestamp": String(timestamp),
263
+ "svix-signature": signature
264
+ }
265
+ });
266
+ }
267
+ /**
268
+ * Verify an inbound Svix webhook signature.
269
+ *
270
+ * @returns true if valid, false if invalid or expired
271
+ * @throws ConfigurationError if webhookSecret is not configured
272
+ */
273
+ verify(params) {
274
+ if (!this.options.webhookSecret) throw new ConfigurationError("webhookSecret is required for webhook verification");
275
+ return verify(this.options.webhookSecret, params.payload, params.headers);
276
+ }
277
+ /**
278
+ * Verify an inbound Svix webhook signature, throwing on failure.
279
+ * Useful for middleware patterns where invalid signatures should halt processing.
280
+ *
281
+ * @throws WebhookSignatureError if signature is invalid or expired
282
+ * @throws ConfigurationError if webhookSecret is not configured
283
+ */
284
+ verifyOrThrow(params) {
285
+ if (!this.verify(params)) throw new WebhookSignatureError("Invalid webhook signature");
286
+ }
287
+ /**
288
+ * Verify and parse an inbound webhook from AgentPress.
289
+ * Combines signature verification with JSON parsing and type casting.
290
+ * This is the recommended way to handle incoming webhooks.
291
+ *
292
+ * @throws WebhookSignatureError if signature is invalid or expired
293
+ * @throws ConfigurationError if webhookSecret is not configured
294
+ * @throws AgentPressError if payload is not valid JSON
295
+ */
296
+ constructEvent(params) {
297
+ this.verifyOrThrow(params);
298
+ const body = typeof params.payload === "string" ? params.payload : params.payload.toString("utf-8");
299
+ try {
300
+ return JSON.parse(body);
301
+ } catch {
302
+ throw new AgentPressError("Webhook payload is not valid JSON");
303
+ }
304
+ }
316
305
  };
317
-
318
- // src/client.ts
306
+ //#endregion
307
+ //#region src/client.ts
308
+ /**
309
+ * Main entry point for the AgentPress SDK. Provides namespaced access to API
310
+ * resources (e.g., `client.webhooks.send()`, `client.actions.approve()`).
311
+ * Validates all configuration options at construction time, so invalid config fails fast.
312
+ *
313
+ * @example
314
+ * ```ts
315
+ * const client = new AgentPress({
316
+ * apiKey: "ak_...",
317
+ * webhookSecret: "whsec_...",
318
+ * });
319
+ * await client.webhooks.send({ action: "my_action", payload: { ... } });
320
+ * await client.actions.approve("act_123", { action: "my_action" });
321
+ * ```
322
+ */
319
323
  var AgentPress = class {
320
- /** Webhook operations: send outbound webhooks and verify inbound signatures. */
321
- webhooks;
322
- /** Action management: approve or reject staged actions. */
323
- actions;
324
- /**
325
- * @param options - SDK configuration. All fields are optional with sensible defaults.
326
- * @throws {ConfigurationError} If `timeout` is non-positive or `webhookSecret` has an invalid prefix.
327
- */
328
- constructor(options = {}) {
329
- const resolved = resolveOptions(options);
330
- const http = new HttpClient(resolved);
331
- this.webhooks = new WebhooksClient(resolved, http);
332
- this.actions = new ActionsClient(resolved, http);
333
- }
324
+ /** Webhook operations: send outbound webhooks and verify inbound signatures. */
325
+ webhooks;
326
+ /** Action management: approve or reject staged actions. */
327
+ actions;
328
+ /**
329
+ * @param options - SDK configuration. All fields are optional with sensible defaults.
330
+ * @throws {ConfigurationError} If `timeout` is non-positive or `webhookSecret` has an invalid prefix.
331
+ */
332
+ constructor(options = {}) {
333
+ const resolved = resolveOptions(options);
334
+ const http = new HttpClient(resolved);
335
+ this.webhooks = new WebhooksClient(resolved, http);
336
+ this.actions = new ActionsClient(resolved, http);
337
+ }
334
338
  };
335
339
  function resolveOptions(options) {
336
- const baseUrl = (options.baseUrl ?? "https://api.agent.press").replace(
337
- /\/+$/,
338
- ""
339
- );
340
- const timeout = options.timeout ?? 3e4;
341
- const org = options.org ?? "default-org";
342
- if (timeout <= 0 || !Number.isFinite(timeout)) {
343
- throw new ConfigurationError("timeout must be a positive number");
344
- }
345
- if (options.webhookSecret !== void 0 && !options.webhookSecret.startsWith("whsec_")) {
346
- throw new ConfigurationError('webhookSecret must start with "whsec_"');
347
- }
348
- return {
349
- baseUrl,
350
- timeout,
351
- org,
352
- webhookSecret: options.webhookSecret,
353
- apiKey: options.apiKey,
354
- onRequest: options.onRequest,
355
- onResponse: options.onResponse
356
- };
340
+ const baseUrl = (options.baseUrl ?? "https://api.agent.press").replace(/\/+$/, "");
341
+ const timeout = options.timeout ?? 3e4;
342
+ const org = options.org ?? "default-org";
343
+ if (timeout <= 0 || !Number.isFinite(timeout)) throw new ConfigurationError("timeout must be a positive number");
344
+ if (options.webhookSecret !== void 0 && !options.webhookSecret.startsWith("whsec_")) throw new ConfigurationError("webhookSecret must start with \"whsec_\"");
345
+ return {
346
+ baseUrl,
347
+ timeout,
348
+ org,
349
+ webhookSecret: options.webhookSecret,
350
+ apiKey: options.apiKey,
351
+ onRequest: options.onRequest,
352
+ onResponse: options.onResponse
353
+ };
357
354
  }
358
- // Annotate the CommonJS export names for ESM import in node:
359
- 0 && (module.exports = {
360
- ActionsClient,
361
- AgentPress,
362
- AgentPressError,
363
- ConfigurationError,
364
- HttpError,
365
- TimeoutError,
366
- WebhookSignatureError
367
- });
355
+ //#endregion
356
+ exports.ActionsClient = ActionsClient;
357
+ exports.AgentPress = AgentPress;
358
+ exports.AgentPressError = AgentPressError;
359
+ exports.ConfigurationError = ConfigurationError;
360
+ exports.HttpError = HttpError;
361
+ exports.TimeoutError = TimeoutError;
362
+ exports.WebhookSignatureError = WebhookSignatureError;
363
+
368
364
  //# sourceMappingURL=index.cjs.map