@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.
@@ -0,0 +1,313 @@
1
+ //#region src/types.d.ts
2
+ /** Constructor options for the {@link AgentPress} client. All fields are optional. */
3
+ interface AgentPressOptions {
4
+ /** Svix webhook signing secret for verifying inbound webhooks. Must start with `"whsec_"`. */
5
+ webhookSecret?: string;
6
+ /** API key for authenticated requests. */
7
+ apiKey?: string;
8
+ /** @default "https://api.agent.press" */
9
+ baseUrl?: string;
10
+ /** Request timeout in milliseconds. Must be a positive finite number. @default 30000 */
11
+ timeout?: number;
12
+ /** Organization identifier sent with requests. @default "default-org" */
13
+ org?: string;
14
+ /** Hook called before every outbound HTTP request (useful for logging/tracing). */
15
+ onRequest?: (url: string, init: RequestInit) => void;
16
+ /** Hook called after every HTTP response is received. */
17
+ onResponse?: (url: string, response: Response) => void;
18
+ }
19
+ /** Parameters for {@link WebhooksClient.send}. */
20
+ interface WebhookSendParams {
21
+ /** Webhook action name (matches an action rule on the server). */
22
+ action: string;
23
+ /** Arbitrary payload data forwarded to the webhook handler. */
24
+ payload: Record<string, unknown>;
25
+ }
26
+ /** Parameters for verifying an inbound webhook signature via {@link WebhooksClient.verify} or {@link WebhooksClient.verifyOrThrow}. */
27
+ interface WebhookVerifyParams {
28
+ /** Raw request body (string or Buffer) -- must not be parsed/modified. */
29
+ payload: string | Buffer;
30
+ /** Svix signature headers from the incoming request. */
31
+ headers: {
32
+ "svix-id": string;
33
+ "svix-timestamp": string;
34
+ "svix-signature": string;
35
+ };
36
+ }
37
+ /** Response from webhook send operations. */
38
+ interface WebhookResponse {
39
+ success: boolean;
40
+ /** UUID of the created action (present on successful creation). */
41
+ actionId?: string;
42
+ /** `true` if an action with the same `externalId` already existed (idempotency). */
43
+ alreadyExists?: boolean;
44
+ skipped?: boolean;
45
+ data?: Record<string, unknown>;
46
+ }
47
+ /** Action lifecycle event types emitted by AgentPress. */
48
+ type ActionEventType = "action.pending_approval" | "action.approved" | "action.completed" | "action.failed" | "action.rejected" | "action.expired";
49
+ /** A tool call staged for approval (present when eventType is "action.pending_approval"). */
50
+ interface StagedToolCall {
51
+ toolName: string;
52
+ toolCallId: string;
53
+ arguments: Record<string, unknown>;
54
+ }
55
+ /** Parameters for {@link ActionsClient.approve}. */
56
+ interface ApproveActionParams {
57
+ /** Webhook action identifier (from callback's webhookAction field). */
58
+ action: string;
59
+ /** Optionally modify the tool call arguments before execution. */
60
+ editedToolCall?: {
61
+ toolName: string;
62
+ arguments: Record<string, unknown>;
63
+ };
64
+ }
65
+ /** Parameters for {@link ActionsClient.reject}. */
66
+ interface RejectActionParams {
67
+ /** Webhook action identifier (from callback's webhookAction field). */
68
+ action: string;
69
+ /** Reason for rejection. */
70
+ reason?: string;
71
+ }
72
+ /** Response from action approve/reject operations. */
73
+ interface ActionManageResponse {
74
+ success: boolean;
75
+ actionId: string;
76
+ status: ActionStatus;
77
+ }
78
+ /** Status of an action in the AgentPress system. */
79
+ type ActionStatus = "pending" | "staged" | "approved" | "rejected" | "completed" | "failed" | "expired";
80
+ /** A tool call made by the agent during action processing. */
81
+ interface ToolCallResult {
82
+ toolName: string;
83
+ arguments: Record<string, unknown>;
84
+ result: unknown;
85
+ }
86
+ /** The agent's response after processing an action. */
87
+ interface AgentResponse {
88
+ /** The agent's text response, if any. */
89
+ text: string | null;
90
+ /** Tool calls made by the agent during processing. */
91
+ toolCalls: ToolCallResult[];
92
+ }
93
+ /**
94
+ * Payload received from AgentPress outbound webhooks (post-event callbacks).
95
+ * This is what your server receives when an action completes.
96
+ */
97
+ interface ActionCallbackPayload {
98
+ actionId: string;
99
+ status: ActionStatus;
100
+ actionType: string;
101
+ /** Lifecycle event type (e.g., "action.pending_approval", "action.completed"). */
102
+ eventType: ActionEventType;
103
+ /** Webhook action identifier used to create this action. Needed for approve/reject. */
104
+ webhookAction: string | null;
105
+ /** Tool awaiting approval (present only when eventType is "action.pending_approval"). */
106
+ stagedToolCall: StagedToolCall | null;
107
+ /** ISO 8601 timestamp of when the action completed. */
108
+ completedAt: string;
109
+ /** Original data from the inbound webhook that triggered this action. */
110
+ sourceData: Record<string, unknown>;
111
+ /** External system identifier. */
112
+ externalId: string | null;
113
+ /** AgentPress user ID associated with this action. */
114
+ userId: string | null;
115
+ /** Thread ID if the action created a conversation. */
116
+ threadId: string | null;
117
+ /** The agent's response including text and tool call results. */
118
+ agentResponse: AgentResponse;
119
+ /** Error message if the action failed. */
120
+ errorMessage: string | null;
121
+ /** Reason provided if the action was rejected by a human reviewer. */
122
+ rejectionReason: string | null;
123
+ /** Additional custom fields from post-event configuration. */
124
+ [key: string]: unknown;
125
+ }
126
+ /** @internal Resolved (validated, defaulted) options. Not exported from the public API. */
127
+ interface ResolvedOptions {
128
+ baseUrl: string;
129
+ timeout: number;
130
+ org: string;
131
+ webhookSecret?: string;
132
+ apiKey?: string;
133
+ onRequest?: AgentPressOptions["onRequest"];
134
+ onResponse?: AgentPressOptions["onResponse"];
135
+ }
136
+ //#endregion
137
+ //#region src/http.d.ts
138
+ /**
139
+ * Internal shared HTTP client. Not part of the public API -- used by
140
+ * namespace clients (e.g., `WebhooksClient`) to make authenticated requests.
141
+ * @internal
142
+ */
143
+ declare class HttpClient {
144
+ private readonly baseUrl;
145
+ private readonly timeout;
146
+ private readonly onRequest?;
147
+ private readonly onResponse?;
148
+ constructor(options: ResolvedOptions);
149
+ /**
150
+ * Send an HTTP request to the API. Constructs the full URL from `baseUrl` + `path`,
151
+ * applies the configured timeout via `AbortSignal`, fires `onRequest`/`onResponse`
152
+ * hooks, and parses the JSON response.
153
+ *
154
+ * @throws {TimeoutError} If the request exceeds the configured timeout.
155
+ * @throws {HttpError} If the API returns a non-2xx status code.
156
+ * @throws {AgentPressError} On network failures or non-JSON responses.
157
+ */
158
+ request<T>(path: string, init: RequestInit): Promise<T>;
159
+ }
160
+ //#endregion
161
+ //#region src/actions/client.d.ts
162
+ /**
163
+ * Client for programmatically approving or rejecting staged actions.
164
+ * Uses HMAC-SHA256 signing (Svix-compatible), identical to {@link WebhooksClient}.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const client = new AgentPress({ webhookSecret: "whsec_...", org: "my-org" });
169
+ *
170
+ * // Approve a staged action
171
+ * await client.actions.approve("act_123", {
172
+ * action: "my_webhook_action",
173
+ * });
174
+ *
175
+ * // Reject with a reason
176
+ * await client.actions.reject("act_456", {
177
+ * action: "my_webhook_action",
178
+ * reason: "Insufficient data",
179
+ * });
180
+ * ```
181
+ */
182
+ declare class ActionsClient {
183
+ private readonly options;
184
+ private readonly http;
185
+ constructor(options: ResolvedOptions, http: HttpClient);
186
+ /**
187
+ * Approve a staged action, optionally modifying the tool call.
188
+ *
189
+ * @throws ConfigurationError if webhookSecret is not configured
190
+ * @throws HttpError on non-2xx response
191
+ * @throws TimeoutError if request exceeds timeout
192
+ */
193
+ approve(actionId: string, params: ApproveActionParams): Promise<ActionManageResponse>;
194
+ /**
195
+ * Reject a staged action.
196
+ *
197
+ * @throws ConfigurationError if webhookSecret is not configured
198
+ * @throws HttpError on non-2xx response
199
+ * @throws TimeoutError if request exceeds timeout
200
+ */
201
+ reject(actionId: string, params: RejectActionParams): Promise<ActionManageResponse>;
202
+ private manage;
203
+ }
204
+ //#endregion
205
+ //#region src/webhooks/client.d.ts
206
+ declare class WebhooksClient {
207
+ private readonly options;
208
+ private readonly http;
209
+ constructor(options: ResolvedOptions, http: HttpClient);
210
+ /**
211
+ * Send an arbitrary webhook payload to AgentPress.
212
+ * Signs the payload with HMAC-SHA256 (Svix-compatible).
213
+ *
214
+ * @throws ConfigurationError if webhookSecret is not configured
215
+ * @throws HttpError on non-2xx response
216
+ * @throws TimeoutError if request exceeds timeout
217
+ */
218
+ send(params: WebhookSendParams): Promise<WebhookResponse>;
219
+ /**
220
+ * Verify an inbound Svix webhook signature.
221
+ *
222
+ * @returns true if valid, false if invalid or expired
223
+ * @throws ConfigurationError if webhookSecret is not configured
224
+ */
225
+ verify(params: WebhookVerifyParams): boolean;
226
+ /**
227
+ * Verify an inbound Svix webhook signature, throwing on failure.
228
+ * Useful for middleware patterns where invalid signatures should halt processing.
229
+ *
230
+ * @throws WebhookSignatureError if signature is invalid or expired
231
+ * @throws ConfigurationError if webhookSecret is not configured
232
+ */
233
+ verifyOrThrow(params: WebhookVerifyParams): void;
234
+ /**
235
+ * Verify and parse an inbound webhook from AgentPress.
236
+ * Combines signature verification with JSON parsing and type casting.
237
+ * This is the recommended way to handle incoming webhooks.
238
+ *
239
+ * @throws WebhookSignatureError if signature is invalid or expired
240
+ * @throws ConfigurationError if webhookSecret is not configured
241
+ * @throws AgentPressError if payload is not valid JSON
242
+ */
243
+ constructEvent(params: WebhookVerifyParams): ActionCallbackPayload;
244
+ }
245
+ //#endregion
246
+ //#region src/client.d.ts
247
+ /**
248
+ * Main entry point for the AgentPress SDK. Provides namespaced access to API
249
+ * resources (e.g., `client.webhooks.send()`, `client.actions.approve()`).
250
+ * Validates all configuration options at construction time, so invalid config fails fast.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const client = new AgentPress({
255
+ * apiKey: "ak_...",
256
+ * webhookSecret: "whsec_...",
257
+ * });
258
+ * await client.webhooks.send({ action: "my_action", payload: { ... } });
259
+ * await client.actions.approve("act_123", { action: "my_action" });
260
+ * ```
261
+ */
262
+ declare class AgentPress {
263
+ /** Webhook operations: send outbound webhooks and verify inbound signatures. */
264
+ readonly webhooks: WebhooksClient;
265
+ /** Action management: approve or reject staged actions. */
266
+ readonly actions: ActionsClient;
267
+ /**
268
+ * @param options - SDK configuration. All fields are optional with sensible defaults.
269
+ * @throws {ConfigurationError} If `timeout` is non-positive or `webhookSecret` has an invalid prefix.
270
+ */
271
+ constructor(options?: AgentPressOptions);
272
+ }
273
+ //#endregion
274
+ //#region src/errors.d.ts
275
+ /**
276
+ * Base error class for all SDK errors. Catch this to handle any error
277
+ * thrown by the AgentPress SDK regardless of specific type.
278
+ */
279
+ declare class AgentPressError extends Error {
280
+ constructor(message: string);
281
+ }
282
+ /**
283
+ * Thrown at construction time when `AgentPressOptions` contains invalid values
284
+ * (e.g., non-positive timeout, malformed `webhookSecret`).
285
+ */
286
+ declare class ConfigurationError extends AgentPressError {
287
+ constructor(message: string);
288
+ }
289
+ /**
290
+ * Thrown when the API returns a non-2xx HTTP response.
291
+ *
292
+ * Properties:
293
+ * - `statusCode` - HTTP status code (e.g., 401, 404, 500)
294
+ * - `responseBody` - Raw response body text for debugging
295
+ * - `url` - The full request URL that failed
296
+ */
297
+ declare class HttpError extends AgentPressError {
298
+ readonly statusCode: number;
299
+ readonly responseBody: string;
300
+ readonly url: string;
301
+ constructor(statusCode: number, responseBody: string, url: string);
302
+ }
303
+ /** Thrown when a request exceeds the configured `timeout` (default 30s). */
304
+ declare class TimeoutError extends AgentPressError {
305
+ constructor(url: string, timeout: number);
306
+ }
307
+ /** Thrown by {@link WebhooksClient.verifyOrThrow} when an inbound webhook signature is invalid or expired. */
308
+ declare class WebhookSignatureError extends AgentPressError {
309
+ constructor(message: string);
310
+ }
311
+ //#endregion
312
+ export { type ActionCallbackPayload, type ActionEventType, type ActionManageResponse, type ActionStatus, ActionsClient, AgentPress, AgentPressError, type AgentPressOptions, type AgentResponse, type ApproveActionParams, ConfigurationError, HttpError, type RejectActionParams, type StagedToolCall, TimeoutError, type ToolCallResult, type WebhookResponse, type WebhookSendParams, WebhookSignatureError, type WebhookVerifyParams };
313
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/http.ts","../src/actions/client.ts","../src/webhooks/client.ts","../src/client.ts","../src/errors.ts"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAY6C;EAV7C,MAAA;EAAA;EAEA,OAAA;EAEA;EAAA,OAAA;EAIA;EAFA,GAAA;EAEgC;EAAhC,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,WAAA;EAEhC;EAAA,U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