@agentpress/sdk 0.5.4 → 0.6.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 +69 -7
- package/dist/index.cjs +114 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +171 -53
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +171 -53
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +114 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -111,12 +111,48 @@ interface KeyRotationEvent {
|
|
|
111
111
|
/** Present only on `type: "emergency"` rotations. */
|
|
112
112
|
reason?: string;
|
|
113
113
|
}
|
|
114
|
+
/** Per-tool approval mode for action webhooks: run automatically, always
|
|
115
|
+
* require human approval, or let the agent decide per call. Mirrors the core
|
|
116
|
+
* `ToolApprovalMode`. */
|
|
117
|
+
type ToolApprovalMode = "allow" | "ask" | "agent";
|
|
118
|
+
/**
|
|
119
|
+
* Typed shape of the JSON body sent to `POST /webhooks/actions/:org/:identifier`.
|
|
120
|
+
* `WebhookSendParams.payload` is intentionally `Record<string, unknown>`; use
|
|
121
|
+
* this interface to type your payload object for editor help.
|
|
122
|
+
*/
|
|
123
|
+
interface ActionWebhookPayload {
|
|
124
|
+
/** Event type (e.g. "review.created"). */
|
|
125
|
+
eventType: string;
|
|
126
|
+
/** External system's unique id for idempotency. */
|
|
127
|
+
externalId?: string;
|
|
128
|
+
/** External user id (resolved via `authProvider`) or an internal user UUID. */
|
|
129
|
+
userId?: string;
|
|
130
|
+
/** Registered external auth provider name used to resolve `userId`. */
|
|
131
|
+
authProvider?: string;
|
|
132
|
+
/** Override the webhook's default action rule. */
|
|
133
|
+
actionRuleId?: string;
|
|
134
|
+
/** Extra per-request instructions appended to the rule's instructions. */
|
|
135
|
+
instructions?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Per-request tool-approval overrides keyed by tool name. Honored only when
|
|
138
|
+
* the webhook has `allowApprovalOverride` enabled in AgentPress. A user's
|
|
139
|
+
* always_deny preference still wins over any override.
|
|
140
|
+
*/
|
|
141
|
+
toolApprovals?: Record<string, ToolApprovalMode>;
|
|
142
|
+
/** Arbitrary event data forwarded to the agent as sourceData. */
|
|
143
|
+
data?: Record<string, unknown>;
|
|
144
|
+
}
|
|
114
145
|
/** Parameters for {@link WebhooksClient.send}. */
|
|
115
146
|
interface WebhookSendParams {
|
|
116
|
-
/**
|
|
147
|
+
/** Action webhook identifier (used in `/webhooks/actions/:org/:identifier`). */
|
|
117
148
|
action: string;
|
|
118
149
|
/** Arbitrary payload data forwarded to the webhook handler. */
|
|
119
150
|
payload: Record<string, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Verification scheme for the outbound request. Defaults to Svix signing
|
|
153
|
+
* with the client's `webhookSecret`.
|
|
154
|
+
*/
|
|
155
|
+
auth?: WebhookSendAuth;
|
|
120
156
|
}
|
|
121
157
|
/** Parameters for verifying an inbound webhook signature via {@link WebhooksClient.verify} or {@link WebhooksClient.verifyOrThrow}. */
|
|
122
158
|
interface WebhookVerifyParams {
|
|
@@ -136,6 +172,7 @@ interface WebhookResponse {
|
|
|
136
172
|
actionId?: string;
|
|
137
173
|
/** `true` if an action with the same `externalId` already existed (idempotency). */
|
|
138
174
|
alreadyExists?: boolean;
|
|
175
|
+
/** `true` when AgentPress accepted the event but intentionally skipped dispatch. */
|
|
139
176
|
skipped?: boolean;
|
|
140
177
|
/**
|
|
141
178
|
* `true` when AgentPress accepted the event (HTTP 202) but could not create
|
|
@@ -145,15 +182,69 @@ interface WebhookResponse {
|
|
|
145
182
|
* is returned in this case; use {@link eventId} to correlate.
|
|
146
183
|
*/
|
|
147
184
|
buffered?: boolean;
|
|
148
|
-
/** UUID of the
|
|
185
|
+
/** UUID of the persisted `webhook_events` row for buffered or skipped events. */
|
|
149
186
|
eventId?: string;
|
|
150
|
-
/** Machine-readable reason the event was buffered
|
|
187
|
+
/** Machine-readable reason the event was buffered or skipped. */
|
|
151
188
|
reason?: string;
|
|
152
189
|
data?: Record<string, unknown>;
|
|
153
190
|
}
|
|
191
|
+
/** Authentication options for {@link WebhooksClient.send}. */
|
|
192
|
+
type WebhookSendAuth = {
|
|
193
|
+
scheme: "svix"; /** Action webhook secret. Defaults to the client's `webhookSecret`. */
|
|
194
|
+
secret?: string; /** Optional stable message id for deterministic tests/retries. */
|
|
195
|
+
msgId?: string; /** Unix timestamp in seconds. Defaults to now. */
|
|
196
|
+
timestamp?: number;
|
|
197
|
+
} | {
|
|
198
|
+
scheme: "hmac_sha256"; /** Action webhook secret. Defaults to the client's `webhookSecret`. */
|
|
199
|
+
secret?: string; /** Unix timestamp in seconds. Defaults to now. */
|
|
200
|
+
timestamp?: number;
|
|
201
|
+
} | {
|
|
202
|
+
scheme: "shared_token"; /** Action webhook token. Defaults to the client's `webhookSecret`. */
|
|
203
|
+
token?: string;
|
|
204
|
+
} | {
|
|
205
|
+
/** No verification headers. Only use for intentionally public webhooks. */scheme: "none";
|
|
206
|
+
};
|
|
207
|
+
/** Response from sending an event to the legacy Actions listener endpoint. */
|
|
208
|
+
interface WebhookIngestResponse {
|
|
209
|
+
/** UUID of the persisted `webhook_events` row. */
|
|
210
|
+
eventId: string;
|
|
211
|
+
/** True when the event matched an existing source/dedupe key. */
|
|
212
|
+
duplicate: boolean;
|
|
213
|
+
}
|
|
214
|
+
/** Authentication options for {@link WebhooksClient.sendToActionsListener}. */
|
|
215
|
+
type WebhookIngestAuth = {
|
|
216
|
+
scheme: "svix"; /** Listener secret shown once on create/rotation. */
|
|
217
|
+
secret: string; /** Optional stable message id for deterministic tests/retries. */
|
|
218
|
+
msgId?: string; /** Unix timestamp in seconds. Defaults to now. */
|
|
219
|
+
timestamp?: number;
|
|
220
|
+
} | {
|
|
221
|
+
scheme: "hmac_sha256"; /** Listener secret shown once on create/rotation. */
|
|
222
|
+
secret: string; /** Unix timestamp in seconds. Defaults to now. */
|
|
223
|
+
timestamp?: number;
|
|
224
|
+
} | {
|
|
225
|
+
scheme: "shared_token"; /** Listener token shown once on create/rotation. */
|
|
226
|
+
token: string;
|
|
227
|
+
} | {
|
|
228
|
+
/** Secret-URL listener. The endpoint URL itself is the credential. */scheme: "none";
|
|
229
|
+
};
|
|
230
|
+
/** Parameters for sending directly to the legacy Actions listener endpoint. */
|
|
231
|
+
interface WebhookIngestSendParams {
|
|
232
|
+
/** Listener identifier used in `/webhooks/ingest/:org/:identifier`. */
|
|
233
|
+
identifier: string;
|
|
234
|
+
/** Arbitrary JSON payload to buffer and route through the listener. */
|
|
235
|
+
payload: Record<string, unknown>;
|
|
236
|
+
/** Auth scheme matching the listener verification setting. */
|
|
237
|
+
auth: WebhookIngestAuth;
|
|
238
|
+
}
|
|
239
|
+
/** Preferred response name for Actions listener integrations. */
|
|
240
|
+
type ActionsListenerResponse = WebhookIngestResponse;
|
|
241
|
+
/** Preferred auth name for Actions listener integrations. */
|
|
242
|
+
type ActionsListenerAuth = WebhookIngestAuth;
|
|
243
|
+
/** Preferred parameter name for {@link WebhooksClient.sendToActionsListener}. */
|
|
244
|
+
type ActionsListenerSendParams = WebhookIngestSendParams;
|
|
154
245
|
/** Parameters for {@link signHmacWebhookRequest}. */
|
|
155
246
|
interface SignHmacWebhookRequestParams {
|
|
156
|
-
/** The webhook
|
|
247
|
+
/** The action webhook's shared secret. */
|
|
157
248
|
secret: string;
|
|
158
249
|
/**
|
|
159
250
|
* The exact raw request body string that will be sent. The signature is
|
|
@@ -173,71 +264,75 @@ interface SignedHmacWebhookRequest {
|
|
|
173
264
|
};
|
|
174
265
|
}
|
|
175
266
|
/**
|
|
176
|
-
* Verification scheme for an
|
|
177
|
-
* (`POST /webhooks/
|
|
267
|
+
* Verification scheme for an action webhook
|
|
268
|
+
* (`POST /webhooks/actions/:org/:identifier`).
|
|
178
269
|
*
|
|
179
270
|
* - `"svix"` — Svix-style signing (`svix-id` / `svix-timestamp` / `svix-signature`).
|
|
180
271
|
* - `"hmac_sha256"` — `x-webhook-timestamp` + `x-webhook-signature` headers;
|
|
181
272
|
* sign with {@link signHmacWebhookRequest}.
|
|
182
273
|
* - `"shared_token"` — `Authorization: Bearer <token>` or `x-webhook-token`;
|
|
183
274
|
* build with {@link sharedTokenHeaders}.
|
|
184
|
-
* - `"none"` —
|
|
185
|
-
*
|
|
275
|
+
* - `"none"` — no verification headers; intended only for deliberately public
|
|
276
|
+
* or legacy endpoints.
|
|
186
277
|
*/
|
|
187
278
|
type WebhookVerificationScheme = "svix" | "hmac_sha256" | "shared_token" | "none";
|
|
188
|
-
/**
|
|
279
|
+
/** Preferred verification-scheme name for Actions listener integrations. */
|
|
280
|
+
type ActionsListenerVerificationScheme = WebhookVerificationScheme;
|
|
281
|
+
/** Environment label for an action webhook. */
|
|
189
282
|
type WebhookEnvironment = "dev" | "sandbox" | "prod";
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
|
|
283
|
+
/** Preferred environment name for Actions listener integrations. */
|
|
284
|
+
type ActionsListenerEnvironment = WebhookEnvironment;
|
|
285
|
+
/** Per-action-webhook routing configuration. */
|
|
286
|
+
interface IActionWebhookRoutingConfig {
|
|
287
|
+
/** Legacy listener compatibility: event types to log but never dispatch. */
|
|
193
288
|
ignoredEventTypes?: string[];
|
|
194
|
-
/**
|
|
195
|
-
* `"route"` dispatches buffered events to the target agent;
|
|
196
|
-
* `"buffer_only"` accepts + logs events but skips agent dispatch.
|
|
197
|
-
*/
|
|
289
|
+
/** Legacy listener compatibility: buffer events without dispatching. */
|
|
198
290
|
mode?: "route" | "buffer_only";
|
|
199
291
|
/** Retention window in days for processed/skipped events. */
|
|
200
292
|
retentionDays?: number;
|
|
201
|
-
/** Sender IPs allowed to hit the
|
|
293
|
+
/** Sender IPs allowed to hit the webhook endpoint. Empty/omitted = all. */
|
|
202
294
|
ipAllowlist?: string[];
|
|
203
|
-
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
*/
|
|
207
|
-
instructions?: string;
|
|
208
|
-
/** Ingest quota for this listener. Defaults to 100, capped at 1000. */
|
|
295
|
+
/** Browser sender origins allowed to hit the webhook endpoint. Empty/omitted = all. */
|
|
296
|
+
allowedOrigins?: string[];
|
|
297
|
+
/** Request quota for this action webhook. Defaults to 100/minute, capped at 1000. */
|
|
209
298
|
rateLimitPerMinute?: number;
|
|
299
|
+
/** Legacy listener compatibility. New instructions should live on the action rule. */
|
|
300
|
+
instructions?: string;
|
|
210
301
|
}
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
*/
|
|
216
|
-
interface
|
|
302
|
+
/** Compatibility routing-config name for Actions listener integrations. */
|
|
303
|
+
type IWebhookListenerRoutingConfig = IActionWebhookRoutingConfig;
|
|
304
|
+
/** Preferred routing-config name for Actions listener integrations. */
|
|
305
|
+
type IActionsListenerRoutingConfig = IActionWebhookRoutingConfig;
|
|
306
|
+
/** Action webhook configuration as exposed to SDK consumers. */
|
|
307
|
+
interface IActionWebhookConfig {
|
|
217
308
|
/** Human-readable display name. */
|
|
218
309
|
name: string;
|
|
219
|
-
/** Stable slug used in the
|
|
310
|
+
/** Stable slug used in the webhook URL path. */
|
|
220
311
|
identifier: string;
|
|
221
312
|
/** How inbound requests are authenticated. */
|
|
222
313
|
verificationScheme: WebhookVerificationScheme;
|
|
223
|
-
/** Environment label for the
|
|
314
|
+
/** Environment label for the webhook. */
|
|
224
315
|
environment: WebhookEnvironment;
|
|
225
|
-
/** Disabled
|
|
316
|
+
/** Disabled webhooks reject inbound events at the edge. */
|
|
226
317
|
enabled: boolean;
|
|
227
|
-
/** Agent on the
|
|
318
|
+
/** Agent on the default action rule. */
|
|
228
319
|
targetAgentId: string | null;
|
|
229
320
|
/** Fallback user actions run as when the payload does not resolve one. */
|
|
230
321
|
runAsUserId: string | null;
|
|
231
322
|
/** Routing, retention, and rate-limit configuration. */
|
|
232
|
-
routingConfig:
|
|
323
|
+
routingConfig: IActionWebhookRoutingConfig;
|
|
233
324
|
}
|
|
325
|
+
/** Compatibility config name for Actions listener integrations. */
|
|
326
|
+
type IWebhookListenerConfig = IActionWebhookConfig;
|
|
327
|
+
/** Preferred config name for Actions listener integrations. */
|
|
328
|
+
type IActionsListenerConfig = IActionWebhookConfig;
|
|
234
329
|
/**
|
|
235
|
-
* An action rule's
|
|
330
|
+
* An action rule's webhook subscription. Rules that subscribe to an action
|
|
236
331
|
* webhook receive its buffered events in addition to the webhook's default
|
|
237
|
-
* rule, so one
|
|
332
|
+
* rule, so one action webhook can fan out to several rules.
|
|
238
333
|
*/
|
|
239
|
-
interface
|
|
240
|
-
/**
|
|
334
|
+
interface IActionRuleWebhookSubscription {
|
|
335
|
+
/** Action webhook this rule subscribes to; `null` = no subscription. */
|
|
241
336
|
listenWebhookId: string | null;
|
|
242
337
|
/** Event types to receive; empty array = all event types. */
|
|
243
338
|
listenEventTypes: string[];
|
|
@@ -263,6 +358,11 @@ interface StagedToolCall {
|
|
|
263
358
|
* callbacks may contain a plain string.
|
|
264
359
|
*/
|
|
265
360
|
summary?: string | StagedToolCallSummary;
|
|
361
|
+
/**
|
|
362
|
+
* For agent-decided approvals: the agent's one-line rationale for requiring
|
|
363
|
+
* approval. Untrusted, bounded audit metadata — not authorization evidence.
|
|
364
|
+
*/
|
|
365
|
+
agentApprovalRationale?: string;
|
|
266
366
|
}
|
|
267
367
|
/** Parameters for {@link ActionsClient.approve}. */
|
|
268
368
|
interface ApproveActionParams {
|
|
@@ -359,13 +459,14 @@ interface ActionCallbackPayload {
|
|
|
359
459
|
[key: string]: unknown;
|
|
360
460
|
}
|
|
361
461
|
/** Mode of a user tool approval rule. */
|
|
362
|
-
type ApprovalMode = "always_allow" | "always_deny";
|
|
462
|
+
type ApprovalMode = "always_allow" | "always_deny" | "agent_decides";
|
|
363
463
|
/**
|
|
364
|
-
* Mode accepted by settings UIs that sync Allow/Ask choices.
|
|
365
|
-
* persists an allow rule
|
|
366
|
-
*
|
|
464
|
+
* Mode accepted by settings UIs that sync Allow/Ask/Agent choices.
|
|
465
|
+
* `always_allow` persists an allow rule, `agent_decides` persists an
|
|
466
|
+
* agent-decide rule, and `ask` means no stored rule for that listed tool.
|
|
467
|
+
* `always_deny` is intentionally not accepted by sync.
|
|
367
468
|
*/
|
|
368
|
-
type ApprovalRuleSyncMode = "always_allow" | "ask";
|
|
469
|
+
type ApprovalRuleSyncMode = "always_allow" | "agent_decides" | "ask";
|
|
369
470
|
/**
|
|
370
471
|
* A persisted rule that auto-approves (or auto-denies) a specific
|
|
371
472
|
* `(user, webhook, tool)` triple, bypassing the per-action approval prompt.
|
|
@@ -420,6 +521,8 @@ interface WebhookApprovalToolMetadata {
|
|
|
420
521
|
destructiveHint: boolean | null;
|
|
421
522
|
/** True/false when known; null when the tool catalog does not expose it. */
|
|
422
523
|
sensitiveHint: boolean | null;
|
|
524
|
+
/** The rule's configured default approval mode for this tool, when exposed. */
|
|
525
|
+
mode?: "ask" | "agent";
|
|
423
526
|
}
|
|
424
527
|
/** Webhook metadata plus the ordered approval-tool catalog for partner UIs. */
|
|
425
528
|
interface WebhookApprovalMetadata {
|
|
@@ -778,7 +881,8 @@ declare class WebhooksClient {
|
|
|
778
881
|
constructor(options: ResolvedOptions, http: HttpClient);
|
|
779
882
|
/**
|
|
780
883
|
* Send an arbitrary webhook payload to AgentPress.
|
|
781
|
-
* Signs the payload with
|
|
884
|
+
* Signs the payload with the verification scheme configured on the action
|
|
885
|
+
* webhook. Defaults to Svix-compatible signing.
|
|
782
886
|
*
|
|
783
887
|
* On the happy path the response is synchronous: `{ success: true,
|
|
784
888
|
* actionId, data }`, or `{ success, actionId, alreadyExists: true, data }`
|
|
@@ -791,11 +895,25 @@ declare class WebhooksClient {
|
|
|
791
895
|
* auto-processes once an operator fixes the configuration, so check
|
|
792
896
|
* {@link WebhookResponse.buffered} before relying on `actionId`.
|
|
793
897
|
*
|
|
794
|
-
* @throws ConfigurationError if
|
|
898
|
+
* @throws ConfigurationError if the selected verification scheme needs a
|
|
899
|
+
* secret/token and none is configured
|
|
795
900
|
* @throws HttpError on non-2xx response
|
|
796
901
|
* @throws TimeoutError if request exceeds timeout
|
|
797
902
|
*/
|
|
798
903
|
send(params: WebhookSendParams): Promise<WebhookResponse>;
|
|
904
|
+
/**
|
|
905
|
+
* Send a payload to the legacy Actions listener ingestion endpoint
|
|
906
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
907
|
+
*
|
|
908
|
+
* New integrations should prefer {@link send}; this method is kept for
|
|
909
|
+
* existing listener integrations and SDK patch compatibility.
|
|
910
|
+
*/
|
|
911
|
+
sendToActionsListener(params: ActionsListenerSendParams): Promise<ActionsListenerResponse>;
|
|
912
|
+
/**
|
|
913
|
+
* @deprecated Use {@link sendToActionsListener}. Kept as a compatibility
|
|
914
|
+
* alias for integrations created before the Actions listener naming update.
|
|
915
|
+
*/
|
|
916
|
+
sendToListener(params: WebhookIngestSendParams): Promise<WebhookIngestResponse>;
|
|
799
917
|
/**
|
|
800
918
|
* Verify an inbound Svix webhook signature.
|
|
801
919
|
*
|
|
@@ -924,11 +1042,11 @@ declare class KeyRotationVerifyError extends AgentPressError {
|
|
|
924
1042
|
constructor(reason: KeyRotationVerifyErrorReason, message: string);
|
|
925
1043
|
}
|
|
926
1044
|
//#endregion
|
|
927
|
-
//#region src/webhooks/
|
|
1045
|
+
//#region src/webhooks/actionWebhookSigning.d.ts
|
|
928
1046
|
/**
|
|
929
|
-
* Sign an outbound request for an AgentPress
|
|
930
|
-
*
|
|
931
|
-
* (`POST /webhooks/
|
|
1047
|
+
* Sign an outbound request for an AgentPress action webhook that uses the
|
|
1048
|
+
* `hmac_sha256` verification scheme
|
|
1049
|
+
* (`POST /webhooks/actions/:org/:identifier`).
|
|
932
1050
|
*
|
|
933
1051
|
* Produces the two headers AgentPress verifies:
|
|
934
1052
|
*
|
|
@@ -943,7 +1061,7 @@ declare class KeyRotationVerifyError extends AgentPressError {
|
|
|
943
1061
|
* ```ts
|
|
944
1062
|
* const rawBody = JSON.stringify({ eventType: "review.created", data: {...} });
|
|
945
1063
|
* const { headers } = signHmacWebhookRequest({ secret, rawBody });
|
|
946
|
-
* await fetch(
|
|
1064
|
+
* await fetch(actionWebhookUrl, {
|
|
947
1065
|
* method: "POST",
|
|
948
1066
|
* body: rawBody,
|
|
949
1067
|
* headers: { "content-type": "application/json", ...headers },
|
|
@@ -952,8 +1070,8 @@ declare class KeyRotationVerifyError extends AgentPressError {
|
|
|
952
1070
|
*/
|
|
953
1071
|
declare function signHmacWebhookRequest(params: SignHmacWebhookRequestParams): SignedHmacWebhookRequest;
|
|
954
1072
|
/**
|
|
955
|
-
* Build the auth header for an AgentPress
|
|
956
|
-
*
|
|
1073
|
+
* Build the auth header for an AgentPress action webhook that uses the
|
|
1074
|
+
* `shared_token` verification scheme. AgentPress also accepts
|
|
957
1075
|
* `Authorization: Bearer <token>`; this helper uses the dedicated
|
|
958
1076
|
* `x-webhook-token` header so it never collides with other auth middleware.
|
|
959
1077
|
*/
|
|
@@ -961,5 +1079,5 @@ declare function sharedTokenHeaders(token: string): {
|
|
|
961
1079
|
"x-webhook-token": string;
|
|
962
1080
|
};
|
|
963
1081
|
//#endregion
|
|
964
|
-
export { ACTION_EVENT_TYPES, type ActionCallbackPayload, type ActionEventType, type ActionManageResponse, type ActionStatus, ActionsClient, AgentPress, AgentPressError, type AgentPressOptions, type AgentResponse, type ApprovalMode, type ApprovalRuleSyncMode, type ApproveActionParams, ConfigurationError, type CreateUserApprovalParams, type DeleteUserApprovalParams, type GetUserApprovalWebhookMetadataParams, HttpError, type
|
|
1082
|
+
export { ACTION_EVENT_TYPES, type ActionCallbackPayload, type ActionEventType, type ActionManageResponse, type ActionStatus, type ActionWebhookPayload, ActionsClient, type ActionsListenerAuth, type ActionsListenerEnvironment, type ActionsListenerResponse, type ActionsListenerSendParams, type ActionsListenerVerificationScheme, AgentPress, AgentPressError, type AgentPressOptions, type AgentResponse, type ApprovalMode, type ApprovalRuleSyncMode, type ApproveActionParams, ConfigurationError, type CreateUserApprovalParams, type DeleteUserApprovalParams, type GetUserApprovalWebhookMetadataParams, HttpError, type IActionRuleWebhookSubscription, type IActionWebhookConfig, type IActionWebhookRoutingConfig, type IActionsListenerConfig, type IActionsListenerRoutingConfig, type IWebhookListenerConfig, type IWebhookListenerRoutingConfig, type KeyRotationEvent, KeyRotationVerifyError, type KeyRotationVerifyErrorReason, type KeyRotationVerifyParams, type ListUserApprovalsParams, type ListUserApprovalsResponse, type PartnerMcpOptions, type PartnerTokenClaims, PartnerTokenError, type PartnerTokenErrorReason, PartnersClient, type RejectActionParams, type SignHmacWebhookRequestParams, type SignedHmacWebhookRequest, type StagedToolCall, type StagedToolCallSummary, type SyncUserApprovalRule, type SyncUserApprovalsParams, type SyncUserApprovalsResponse, TimeoutError, type ToolApprovalMode, type ToolCallResult, type UpdateUserApprovalParams, UserApprovalsClient, type UserToolApproval, type WebhookApprovalMetadata, type WebhookApprovalToolMetadata, type WebhookEnvironment, type WebhookIngestAuth, type WebhookIngestResponse, type WebhookIngestSendParams, type WebhookResponse, type WebhookSendAuth, type WebhookSendParams, WebhookSignatureError, type WebhookVerificationScheme, type WebhookVerifyParams, WebhooksClient, sharedTokenHeaders, signHmacWebhookRequest };
|
|
965
1083
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/http.ts","../src/actions/client.ts","../src/partners/client.ts","../src/userApprovals/client.ts","../src/webhooks/client.ts","../src/client.ts","../src/errors.ts","../src/webhooks/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/http.ts","../src/actions/client.ts","../src/partners/client.ts","../src/userApprovals/client.ts","../src/webhooks/client.ts","../src/client.ts","../src/errors.ts","../src/webhooks/actionWebhookSigning.ts"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAkBa;EAhBb,MAAA;EAoBqC;EAlBrC,OAAA;EAk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B;EAAA,SMQ7B,aAAA,EAAe,mBAAA;ENJC;EAAA,SMMhB,QAAA,EAAU,cAAA;ENNM;;;;cMYpB,OAAA,GAAS,iBAAA;AAAA;;;;ANxCvB;;;cOGa,eAAA,SAAwB,KAAK;cAC5B,OAAA;AAAA;;;;;cAWD,kBAAA,SAA2B,eAAe;cACzC,OAAA;AAAA;;;;;;;;;cAeD,SAAA,SAAkB,eAAe;EAAA,SAC5B,UAAA;EAAA,SACA,YAAA;EAAA,SACA,GAAA;cAEJ,UAAA,UAAoB,YAAA,UAAsB,GAAA;AAAA;;cAW3C,YAAA,SAAqB,eAAe;cACnC,GAAA,UAAa,OAAA;AAAA;;cAQd,qBAAA,SAA8B,eAAe;cAC5C,OAAA;AAAA;;KAQF,uBAAA;APJZ;;;;;AAAA,cOqBa,iBAAA,SAA0B,eAAA;EAAA,SACrB,MAAA,EAAQ,uBAAA;cAEZ,MAAA,EAAQ,uBAAA,EAAyB,OAAA;AAAA;;KASnC,4BAAA;;;;;cAYC,sBAAA,SAA+B,eAAA;EAAA,SAC1B,MAAA,EAAQ,4BAAA;cAEZ,MAAA,EAAQ,4BAAA,EAA8B,OAAA;AAAA;;;AP7GpD;;;;;;;;;;;;;;;;;;;;;;;;AAwB+C;AAxB/C,iBQ+BgB,sBAAA,CACd,MAAA,EAAQ,4BAAA,GACP,wBAAwB;;;;;;;iBAqBX,kBAAA,CAAmB,KAAA;EACjC,iBAAiB;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -606,7 +606,57 @@ function validatePayload(raw) {
|
|
|
606
606
|
return event;
|
|
607
607
|
}
|
|
608
608
|
//#endregion
|
|
609
|
+
//#region src/webhooks/actionWebhookSigning.ts
|
|
610
|
+
/**
|
|
611
|
+
* Sign an outbound request for an AgentPress action webhook that uses the
|
|
612
|
+
* `hmac_sha256` verification scheme
|
|
613
|
+
* (`POST /webhooks/actions/:org/:identifier`).
|
|
614
|
+
*
|
|
615
|
+
* Produces the two headers AgentPress verifies:
|
|
616
|
+
*
|
|
617
|
+
* - `x-webhook-timestamp` — unix seconds; AgentPress rejects timestamps more
|
|
618
|
+
* than 5 minutes from its own clock.
|
|
619
|
+
* - `x-webhook-signature` — `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`.
|
|
620
|
+
*
|
|
621
|
+
* Send the exact `rawBody` string you signed — any re-serialization after
|
|
622
|
+
* signing (re-ordered keys, whitespace changes) invalidates the signature.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```ts
|
|
626
|
+
* const rawBody = JSON.stringify({ eventType: "review.created", data: {...} });
|
|
627
|
+
* const { headers } = signHmacWebhookRequest({ secret, rawBody });
|
|
628
|
+
* await fetch(actionWebhookUrl, {
|
|
629
|
+
* method: "POST",
|
|
630
|
+
* body: rawBody,
|
|
631
|
+
* headers: { "content-type": "application/json", ...headers },
|
|
632
|
+
* });
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
function signHmacWebhookRequest(params) {
|
|
636
|
+
const timestamp = Math.floor(params.timestamp ?? Date.now() / 1e3).toString();
|
|
637
|
+
return { headers: {
|
|
638
|
+
"x-webhook-timestamp": timestamp,
|
|
639
|
+
"x-webhook-signature": `v1=${createHmac("sha256", params.secret).update(`${timestamp}.${params.rawBody}`).digest("hex")}`
|
|
640
|
+
} };
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Build the auth header for an AgentPress action webhook that uses the
|
|
644
|
+
* `shared_token` verification scheme. AgentPress also accepts
|
|
645
|
+
* `Authorization: Bearer <token>`; this helper uses the dedicated
|
|
646
|
+
* `x-webhook-token` header so it never collides with other auth middleware.
|
|
647
|
+
*/
|
|
648
|
+
function sharedTokenHeaders(token) {
|
|
649
|
+
return { "x-webhook-token": token };
|
|
650
|
+
}
|
|
651
|
+
//#endregion
|
|
609
652
|
//#region src/webhooks/client.ts
|
|
653
|
+
function pathSegment(value) {
|
|
654
|
+
return encodeURIComponent(value);
|
|
655
|
+
}
|
|
656
|
+
function requireSecret(scheme, secret) {
|
|
657
|
+
if (!secret) throw new ConfigurationError(`webhookSecret or auth.${scheme === "shared_token" ? "token" : "secret"} is required for ${scheme} action webhook sends`);
|
|
658
|
+
return secret;
|
|
659
|
+
}
|
|
610
660
|
var WebhooksClient = class {
|
|
611
661
|
options;
|
|
612
662
|
http;
|
|
@@ -616,7 +666,8 @@ var WebhooksClient = class {
|
|
|
616
666
|
}
|
|
617
667
|
/**
|
|
618
668
|
* Send an arbitrary webhook payload to AgentPress.
|
|
619
|
-
* Signs the payload with
|
|
669
|
+
* Signs the payload with the verification scheme configured on the action
|
|
670
|
+
* webhook. Defaults to Svix-compatible signing.
|
|
620
671
|
*
|
|
621
672
|
* On the happy path the response is synchronous: `{ success: true,
|
|
622
673
|
* actionId, data }`, or `{ success, actionId, alreadyExists: true, data }`
|
|
@@ -629,28 +680,81 @@ var WebhooksClient = class {
|
|
|
629
680
|
* auto-processes once an operator fixes the configuration, so check
|
|
630
681
|
* {@link WebhookResponse.buffered} before relying on `actionId`.
|
|
631
682
|
*
|
|
632
|
-
* @throws ConfigurationError if
|
|
683
|
+
* @throws ConfigurationError if the selected verification scheme needs a
|
|
684
|
+
* secret/token and none is configured
|
|
633
685
|
* @throws HttpError on non-2xx response
|
|
634
686
|
* @throws TimeoutError if request exceeds timeout
|
|
635
687
|
*/
|
|
636
688
|
async send(params) {
|
|
637
|
-
|
|
638
|
-
const path = `/webhooks/actions/${this.options.org}/${params.action}`;
|
|
689
|
+
const path = `/webhooks/actions/${pathSegment(this.options.org)}/${pathSegment(params.action)}`;
|
|
639
690
|
const body = JSON.stringify(params.payload);
|
|
640
|
-
const
|
|
641
|
-
const
|
|
642
|
-
|
|
691
|
+
const auth = params.auth ?? { scheme: "svix" };
|
|
692
|
+
const headers = {};
|
|
693
|
+
if (auth.scheme === "svix") {
|
|
694
|
+
const secret = requireSecret("svix", auth.secret ?? this.options.webhookSecret);
|
|
695
|
+
const msgId = auth.msgId ?? randomMessageId();
|
|
696
|
+
const timestamp = Math.floor(auth.timestamp ?? Date.now() / 1e3);
|
|
697
|
+
Object.assign(headers, {
|
|
698
|
+
"svix-id": msgId,
|
|
699
|
+
"svix-timestamp": String(timestamp),
|
|
700
|
+
"svix-signature": sign(secret, msgId, timestamp, body)
|
|
701
|
+
});
|
|
702
|
+
} else if (auth.scheme === "hmac_sha256") {
|
|
703
|
+
const secret = requireSecret("hmac_sha256", auth.secret ?? this.options.webhookSecret);
|
|
704
|
+
Object.assign(headers, signHmacWebhookRequest({
|
|
705
|
+
secret,
|
|
706
|
+
rawBody: body,
|
|
707
|
+
timestamp: auth.timestamp
|
|
708
|
+
}).headers);
|
|
709
|
+
} else if (auth.scheme === "shared_token") {
|
|
710
|
+
const token = requireSecret("shared_token", auth.token ?? this.options.webhookSecret);
|
|
711
|
+
Object.assign(headers, sharedTokenHeaders(token));
|
|
712
|
+
}
|
|
643
713
|
return this.http.request(path, {
|
|
644
714
|
method: "POST",
|
|
645
715
|
body,
|
|
646
|
-
headers
|
|
716
|
+
headers
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Send a payload to the legacy Actions listener ingestion endpoint
|
|
721
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
722
|
+
*
|
|
723
|
+
* New integrations should prefer {@link send}; this method is kept for
|
|
724
|
+
* existing listener integrations and SDK patch compatibility.
|
|
725
|
+
*/
|
|
726
|
+
async sendToActionsListener(params) {
|
|
727
|
+
const path = `/webhooks/ingest/${pathSegment(this.options.org)}/${pathSegment(params.identifier)}`;
|
|
728
|
+
const body = JSON.stringify(params.payload);
|
|
729
|
+
const headers = {};
|
|
730
|
+
if (params.auth.scheme === "svix") {
|
|
731
|
+
const msgId = params.auth.msgId ?? randomMessageId();
|
|
732
|
+
const timestamp = Math.floor(params.auth.timestamp ?? Date.now() / 1e3);
|
|
733
|
+
Object.assign(headers, {
|
|
647
734
|
"svix-id": msgId,
|
|
648
735
|
"svix-timestamp": String(timestamp),
|
|
649
|
-
"svix-signature":
|
|
650
|
-
}
|
|
736
|
+
"svix-signature": sign(params.auth.secret, msgId, timestamp, body)
|
|
737
|
+
});
|
|
738
|
+
} else if (params.auth.scheme === "hmac_sha256") Object.assign(headers, signHmacWebhookRequest({
|
|
739
|
+
secret: params.auth.secret,
|
|
740
|
+
rawBody: body,
|
|
741
|
+
timestamp: params.auth.timestamp
|
|
742
|
+
}).headers);
|
|
743
|
+
else if (params.auth.scheme === "shared_token") Object.assign(headers, sharedTokenHeaders(params.auth.token));
|
|
744
|
+
return this.http.request(path, {
|
|
745
|
+
method: "POST",
|
|
746
|
+
body,
|
|
747
|
+
headers
|
|
651
748
|
});
|
|
652
749
|
}
|
|
653
750
|
/**
|
|
751
|
+
* @deprecated Use {@link sendToActionsListener}. Kept as a compatibility
|
|
752
|
+
* alias for integrations created before the Actions listener naming update.
|
|
753
|
+
*/
|
|
754
|
+
async sendToListener(params) {
|
|
755
|
+
return this.sendToActionsListener(params);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
654
758
|
* Verify an inbound Svix webhook signature.
|
|
655
759
|
*
|
|
656
760
|
* @returns true if valid, false if invalid or expired
|
|
@@ -792,49 +896,6 @@ const ACTION_EVENT_TYPES = [
|
|
|
792
896
|
"action.expired"
|
|
793
897
|
];
|
|
794
898
|
//#endregion
|
|
795
|
-
//#region src/webhooks/ingestSigning.ts
|
|
796
|
-
/**
|
|
797
|
-
* Sign an outbound request for an AgentPress inbound webhook listener that
|
|
798
|
-
* uses the `hmac_sha256` verification scheme
|
|
799
|
-
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
800
|
-
*
|
|
801
|
-
* Produces the two headers AgentPress verifies:
|
|
802
|
-
*
|
|
803
|
-
* - `x-webhook-timestamp` — unix seconds; AgentPress rejects timestamps more
|
|
804
|
-
* than 5 minutes from its own clock.
|
|
805
|
-
* - `x-webhook-signature` — `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`.
|
|
806
|
-
*
|
|
807
|
-
* Send the exact `rawBody` string you signed — any re-serialization after
|
|
808
|
-
* signing (re-ordered keys, whitespace changes) invalidates the signature.
|
|
809
|
-
*
|
|
810
|
-
* @example
|
|
811
|
-
* ```ts
|
|
812
|
-
* const rawBody = JSON.stringify({ eventType: "review.created", data: {...} });
|
|
813
|
-
* const { headers } = signHmacWebhookRequest({ secret, rawBody });
|
|
814
|
-
* await fetch(ingestUrl, {
|
|
815
|
-
* method: "POST",
|
|
816
|
-
* body: rawBody,
|
|
817
|
-
* headers: { "content-type": "application/json", ...headers },
|
|
818
|
-
* });
|
|
819
|
-
* ```
|
|
820
|
-
*/
|
|
821
|
-
function signHmacWebhookRequest(params) {
|
|
822
|
-
const timestamp = Math.floor(params.timestamp ?? Date.now() / 1e3).toString();
|
|
823
|
-
return { headers: {
|
|
824
|
-
"x-webhook-timestamp": timestamp,
|
|
825
|
-
"x-webhook-signature": `v1=${createHmac("sha256", params.secret).update(`${timestamp}.${params.rawBody}`).digest("hex")}`
|
|
826
|
-
} };
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Build the auth header for an AgentPress inbound webhook listener that uses
|
|
830
|
-
* the `shared_token` verification scheme. AgentPress also accepts
|
|
831
|
-
* `Authorization: Bearer <token>`; this helper uses the dedicated
|
|
832
|
-
* `x-webhook-token` header so it never collides with other auth middleware.
|
|
833
|
-
*/
|
|
834
|
-
function sharedTokenHeaders(token) {
|
|
835
|
-
return { "x-webhook-token": token };
|
|
836
|
-
}
|
|
837
|
-
//#endregion
|
|
838
899
|
export { ACTION_EVENT_TYPES, ActionsClient, AgentPress, AgentPressError, ConfigurationError, HttpError, KeyRotationVerifyError, PartnerTokenError, PartnersClient, TimeoutError, UserApprovalsClient, WebhookSignatureError, WebhooksClient, sharedTokenHeaders, signHmacWebhookRequest };
|
|
839
900
|
|
|
840
901
|
//# sourceMappingURL=index.mjs.map
|