@agentpress/sdk 0.4.15 → 0.5.2
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 +56 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +152 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +55 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -137,8 +137,111 @@ interface WebhookResponse {
|
|
|
137
137
|
/** `true` if an action with the same `externalId` already existed (idempotency). */
|
|
138
138
|
alreadyExists?: boolean;
|
|
139
139
|
skipped?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* `true` when AgentPress accepted the event (HTTP 202) but could not create
|
|
142
|
+
* an action yet — e.g. no action rule configured, the rule is disabled, or
|
|
143
|
+
* the user could not be resolved. The event is buffered durably and
|
|
144
|
+
* auto-processes once an operator fixes the configuration. No `actionId`
|
|
145
|
+
* is returned in this case; use {@link eventId} to correlate.
|
|
146
|
+
*/
|
|
147
|
+
buffered?: boolean;
|
|
148
|
+
/** UUID of the buffered `webhook_events` row (present when `buffered` is `true`). */
|
|
149
|
+
eventId?: string;
|
|
150
|
+
/** Machine-readable reason the event was buffered (e.g. `"no_action_rule_configured"`). */
|
|
151
|
+
reason?: string;
|
|
140
152
|
data?: Record<string, unknown>;
|
|
141
153
|
}
|
|
154
|
+
/** Parameters for {@link signHmacWebhookRequest}. */
|
|
155
|
+
interface SignHmacWebhookRequestParams {
|
|
156
|
+
/** The webhook listener's shared secret. */
|
|
157
|
+
secret: string;
|
|
158
|
+
/**
|
|
159
|
+
* The exact raw request body string that will be sent. The signature is
|
|
160
|
+
* computed over `"${timestamp}.${rawBody}"`, so any re-serialization after
|
|
161
|
+
* signing invalidates it.
|
|
162
|
+
*/
|
|
163
|
+
rawBody: string;
|
|
164
|
+
/** Unix timestamp in seconds. @default now */
|
|
165
|
+
timestamp?: number;
|
|
166
|
+
}
|
|
167
|
+
/** Signed headers returned by {@link signHmacWebhookRequest}. */
|
|
168
|
+
interface SignedHmacWebhookRequest {
|
|
169
|
+
/** Headers to attach to the outbound HTTP request. */
|
|
170
|
+
headers: {
|
|
171
|
+
/** Unix timestamp (seconds) the signature was computed for. */"x-webhook-timestamp": string; /** `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`. */
|
|
172
|
+
"x-webhook-signature": string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Verification scheme for an inbound webhook listener
|
|
177
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
178
|
+
*
|
|
179
|
+
* - `"svix"` — Svix-style signing (`svix-id` / `svix-timestamp` / `svix-signature`).
|
|
180
|
+
* - `"hmac_sha256"` — `x-webhook-timestamp` + `x-webhook-signature` headers;
|
|
181
|
+
* sign with {@link signHmacWebhookRequest}.
|
|
182
|
+
* - `"shared_token"` — `Authorization: Bearer <token>` or `x-webhook-token`;
|
|
183
|
+
* build with {@link sharedTokenHeaders}.
|
|
184
|
+
* - `"none"` — capability URL: the unguessable random suffix appended to the
|
|
185
|
+
* endpoint identifier at creation time is the credential.
|
|
186
|
+
*/
|
|
187
|
+
type WebhookVerificationScheme = "svix" | "hmac_sha256" | "shared_token" | "none";
|
|
188
|
+
/** Environment label for an inbound webhook listener. */
|
|
189
|
+
type WebhookEnvironment = "dev" | "sandbox" | "prod";
|
|
190
|
+
/** Per-listener routing configuration ({@link IWebhookListenerConfig.routingConfig}). */
|
|
191
|
+
interface IWebhookListenerRoutingConfig {
|
|
192
|
+
/** Event types to skip (marked `skipped`, never dispatched to an agent). */
|
|
193
|
+
ignoredEventTypes?: string[];
|
|
194
|
+
/**
|
|
195
|
+
* `"route"` dispatches buffered events to the target agent;
|
|
196
|
+
* `"buffer_only"` accepts + logs events but skips agent dispatch.
|
|
197
|
+
*/
|
|
198
|
+
mode?: "route" | "buffer_only";
|
|
199
|
+
/** Retention window in days for processed/skipped events. */
|
|
200
|
+
retentionDays?: number;
|
|
201
|
+
/** Sender IPs allowed to hit the ingest endpoint. Empty/omitted = all. */
|
|
202
|
+
ipAllowlist?: string[];
|
|
203
|
+
/**
|
|
204
|
+
* Webhook-specific guidance appended to the agent prompt on every
|
|
205
|
+
* dispatched event (payload shapes, which tools to call, etc.).
|
|
206
|
+
*/
|
|
207
|
+
instructions?: string;
|
|
208
|
+
/** Ingest quota for this listener. Defaults to 100, capped at 1000. */
|
|
209
|
+
rateLimitPerMinute?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* An inbound webhook listener as configured in AgentPress. Listeners receive
|
|
213
|
+
* external events on `POST /webhooks/ingest/:org/:identifier`, buffer them
|
|
214
|
+
* durably, and route them into actions for the target agent.
|
|
215
|
+
*/
|
|
216
|
+
interface IWebhookListenerConfig {
|
|
217
|
+
/** Human-readable display name. */
|
|
218
|
+
name: string;
|
|
219
|
+
/** Stable slug used in the ingest URL path. */
|
|
220
|
+
identifier: string;
|
|
221
|
+
/** How inbound requests are authenticated. */
|
|
222
|
+
verificationScheme: WebhookVerificationScheme;
|
|
223
|
+
/** Environment label for the listener. */
|
|
224
|
+
environment: WebhookEnvironment;
|
|
225
|
+
/** Disabled listeners reject inbound events at the edge. */
|
|
226
|
+
enabled: boolean;
|
|
227
|
+
/** Agent on the listener's default action rule (quick-setup path). */
|
|
228
|
+
targetAgentId: string | null;
|
|
229
|
+
/** Fallback user actions run as when the payload does not resolve one. */
|
|
230
|
+
runAsUserId: string | null;
|
|
231
|
+
/** Routing, retention, and rate-limit configuration. */
|
|
232
|
+
routingConfig: IWebhookListenerRoutingConfig;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* An action rule's listen subscription. Rules that subscribe to a listening
|
|
236
|
+
* webhook receive its buffered events in addition to the webhook's default
|
|
237
|
+
* rule, so one listening URL can fan out to several rules.
|
|
238
|
+
*/
|
|
239
|
+
interface IActionRuleListenSubscription {
|
|
240
|
+
/** Webhook listener this rule subscribes to; `null` = no subscription. */
|
|
241
|
+
listenWebhookId: string | null;
|
|
242
|
+
/** Event types to receive; empty array = all event types. */
|
|
243
|
+
listenEventTypes: string[];
|
|
244
|
+
}
|
|
142
245
|
/** Action lifecycle event types emitted by AgentPress. */
|
|
143
246
|
type ActionEventType = "action.pending_approval" | "action.approved" | "action.completed" | "action.failed" | "action.rejected" | "action.expired";
|
|
144
247
|
/** All public action callback event types emitted by AgentPress. */
|
|
@@ -677,6 +780,17 @@ declare class WebhooksClient {
|
|
|
677
780
|
* Send an arbitrary webhook payload to AgentPress.
|
|
678
781
|
* Signs the payload with HMAC-SHA256 (Svix-compatible).
|
|
679
782
|
*
|
|
783
|
+
* On the happy path the response is synchronous: `{ success: true,
|
|
784
|
+
* actionId, data }`, or `{ success, actionId, alreadyExists: true, data }`
|
|
785
|
+
* when an action with the same `externalId` already existed (idempotency).
|
|
786
|
+
*
|
|
787
|
+
* Configuration/resolution failures (no action rule configured, rule
|
|
788
|
+
* disabled, user unresolved, action insert failure) do NOT throw — the
|
|
789
|
+
* event is buffered durably and AgentPress responds **202** with
|
|
790
|
+
* `{ success: true, buffered: true, eventId, reason }`. The event
|
|
791
|
+
* auto-processes once an operator fixes the configuration, so check
|
|
792
|
+
* {@link WebhookResponse.buffered} before relying on `actionId`.
|
|
793
|
+
*
|
|
680
794
|
* @throws ConfigurationError if webhookSecret is not configured
|
|
681
795
|
* @throws HttpError on non-2xx response
|
|
682
796
|
* @throws TimeoutError if request exceeds timeout
|
|
@@ -810,5 +924,42 @@ declare class KeyRotationVerifyError extends AgentPressError {
|
|
|
810
924
|
constructor(reason: KeyRotationVerifyErrorReason, message: string);
|
|
811
925
|
}
|
|
812
926
|
//#endregion
|
|
813
|
-
|
|
927
|
+
//#region src/webhooks/ingestSigning.d.ts
|
|
928
|
+
/**
|
|
929
|
+
* Sign an outbound request for an AgentPress inbound webhook listener that
|
|
930
|
+
* uses the `hmac_sha256` verification scheme
|
|
931
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
932
|
+
*
|
|
933
|
+
* Produces the two headers AgentPress verifies:
|
|
934
|
+
*
|
|
935
|
+
* - `x-webhook-timestamp` — unix seconds; AgentPress rejects timestamps more
|
|
936
|
+
* than 5 minutes from its own clock.
|
|
937
|
+
* - `x-webhook-signature` — `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`.
|
|
938
|
+
*
|
|
939
|
+
* Send the exact `rawBody` string you signed — any re-serialization after
|
|
940
|
+
* signing (re-ordered keys, whitespace changes) invalidates the signature.
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```ts
|
|
944
|
+
* const rawBody = JSON.stringify({ eventType: "review.created", data: {...} });
|
|
945
|
+
* const { headers } = signHmacWebhookRequest({ secret, rawBody });
|
|
946
|
+
* await fetch(ingestUrl, {
|
|
947
|
+
* method: "POST",
|
|
948
|
+
* body: rawBody,
|
|
949
|
+
* headers: { "content-type": "application/json", ...headers },
|
|
950
|
+
* });
|
|
951
|
+
* ```
|
|
952
|
+
*/
|
|
953
|
+
declare function signHmacWebhookRequest(params: SignHmacWebhookRequestParams): SignedHmacWebhookRequest;
|
|
954
|
+
/**
|
|
955
|
+
* Build the auth header for an AgentPress inbound webhook listener that uses
|
|
956
|
+
* the `shared_token` verification scheme. AgentPress also accepts
|
|
957
|
+
* `Authorization: Bearer <token>`; this helper uses the dedicated
|
|
958
|
+
* `x-webhook-token` header so it never collides with other auth middleware.
|
|
959
|
+
*/
|
|
960
|
+
declare function sharedTokenHeaders(token: string): {
|
|
961
|
+
"x-webhook-token": string;
|
|
962
|
+
};
|
|
963
|
+
//#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 IActionRuleListenSubscription, 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 ToolCallResult, type UpdateUserApprovalParams, UserApprovalsClient, type UserToolApproval, type WebhookApprovalMetadata, type WebhookApprovalToolMetadata, type WebhookEnvironment, type WebhookResponse, type WebhookSendParams, WebhookSignatureError, type WebhookVerificationScheme, type WebhookVerifyParams, WebhooksClient, sharedTokenHeaders, signHmacWebhookRequest };
|
|
814
965
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","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"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAkBa;EAhBb,MAAA;EAoBqC;EAlBrC,OAAA;EAkB6C;EAhB7C,OAAA;EAJA;EAMA,GAAA;EAFA;;;;;;;;;EAYA,UAAA,GAAa,iBAAA;EAIwB;EAFrC,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,WAAA;EAEa;EAA7C,UAAA,IAAc,GAAA,UAAa,QAAA,EAAU,QAAA;AAAA;;UAItB,iBAAA;EAAiB;;;;;;;EAQhC,OAAA;EAqBiB;AAInB;;;;EAnBE,MAAA;EAuBA;EArBA,QAAA;EAyBA;EAvBA,mBAAA;EA2BA;;;;;EArBA,cAAA;EAiCC;;AAAW;AAId;EAhCE,iBAAA;AAAA;;UAIe,kBAAA;EA8BG;EA5BlB,GAAA;EAkCS;EAhCT,KAAA;EAgCe;EA9Bf,YAAA;EAkC+B;EAhC/B,GAAA;EAgC+B;EA9B/B,GAAA;EAgCA;EA9BA,GAAA;EAgCA;EA9BA,GAAA;EAkCA;EAhCA,GAAA;EAoCA;EAlCA,MAAA;EAkCM;EAhCN,SAAA;EAoCgC;EAlChC,WAAA;EAsCe;EAAA,CApCd,GAAA;AAAA;;UAIc,uBAAA;EAgCA;EA9Bf,OAAA,WAAkB,MAAA;EAkCgB;;;;;EA5BlC,OAAA,EAAS,MAAM;AAAA;;UAIA,gBAAA;EACf,KAAA;EACA,IAAA;EACA,UAAA;EACA,aAAA;;EAEA,SAAA;EA+BA;EA7BA,WAAA;EAiCA;EA/BA,OAAA;
|
|
1
|
+
{"version":3,"file":"index.d.cts","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/ingestSigning.ts"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAkBa;EAhBb,MAAA;EAoBqC;EAlBrC,OAAA;EAkB6C;EAhB7C,OAAA;EAJA;EAMA,GAAA;EAFA;;;;;;;;;EAYA,UAAA,GAAa,iBAAA;EAIwB;EAFrC,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,WAAA;EAEa;EAA7C,UAAA,IAAc,GAAA,UAAa,QAAA,EAAU,QAAA;AAAA;;UAItB,iBAAA;EAAiB;;;;;;;EAQhC,OAAA;EAqBiB;AAInB;;;;EAnBE,MAAA;EAuBA;EArBA,QAAA;EAyBA;EAvBA,mBAAA;EA2BA;;;;;EArBA,cAAA;EAiCC;;AAAW;AAId;EAhCE,iBAAA;AAAA;;UAIe,kBAAA;EA8BG;EA5BlB,GAAA;EAkCS;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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.d.mts
CHANGED
|
@@ -137,8 +137,111 @@ interface WebhookResponse {
|
|
|
137
137
|
/** `true` if an action with the same `externalId` already existed (idempotency). */
|
|
138
138
|
alreadyExists?: boolean;
|
|
139
139
|
skipped?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* `true` when AgentPress accepted the event (HTTP 202) but could not create
|
|
142
|
+
* an action yet — e.g. no action rule configured, the rule is disabled, or
|
|
143
|
+
* the user could not be resolved. The event is buffered durably and
|
|
144
|
+
* auto-processes once an operator fixes the configuration. No `actionId`
|
|
145
|
+
* is returned in this case; use {@link eventId} to correlate.
|
|
146
|
+
*/
|
|
147
|
+
buffered?: boolean;
|
|
148
|
+
/** UUID of the buffered `webhook_events` row (present when `buffered` is `true`). */
|
|
149
|
+
eventId?: string;
|
|
150
|
+
/** Machine-readable reason the event was buffered (e.g. `"no_action_rule_configured"`). */
|
|
151
|
+
reason?: string;
|
|
140
152
|
data?: Record<string, unknown>;
|
|
141
153
|
}
|
|
154
|
+
/** Parameters for {@link signHmacWebhookRequest}. */
|
|
155
|
+
interface SignHmacWebhookRequestParams {
|
|
156
|
+
/** The webhook listener's shared secret. */
|
|
157
|
+
secret: string;
|
|
158
|
+
/**
|
|
159
|
+
* The exact raw request body string that will be sent. The signature is
|
|
160
|
+
* computed over `"${timestamp}.${rawBody}"`, so any re-serialization after
|
|
161
|
+
* signing invalidates it.
|
|
162
|
+
*/
|
|
163
|
+
rawBody: string;
|
|
164
|
+
/** Unix timestamp in seconds. @default now */
|
|
165
|
+
timestamp?: number;
|
|
166
|
+
}
|
|
167
|
+
/** Signed headers returned by {@link signHmacWebhookRequest}. */
|
|
168
|
+
interface SignedHmacWebhookRequest {
|
|
169
|
+
/** Headers to attach to the outbound HTTP request. */
|
|
170
|
+
headers: {
|
|
171
|
+
/** Unix timestamp (seconds) the signature was computed for. */"x-webhook-timestamp": string; /** `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`. */
|
|
172
|
+
"x-webhook-signature": string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Verification scheme for an inbound webhook listener
|
|
177
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
178
|
+
*
|
|
179
|
+
* - `"svix"` — Svix-style signing (`svix-id` / `svix-timestamp` / `svix-signature`).
|
|
180
|
+
* - `"hmac_sha256"` — `x-webhook-timestamp` + `x-webhook-signature` headers;
|
|
181
|
+
* sign with {@link signHmacWebhookRequest}.
|
|
182
|
+
* - `"shared_token"` — `Authorization: Bearer <token>` or `x-webhook-token`;
|
|
183
|
+
* build with {@link sharedTokenHeaders}.
|
|
184
|
+
* - `"none"` — capability URL: the unguessable random suffix appended to the
|
|
185
|
+
* endpoint identifier at creation time is the credential.
|
|
186
|
+
*/
|
|
187
|
+
type WebhookVerificationScheme = "svix" | "hmac_sha256" | "shared_token" | "none";
|
|
188
|
+
/** Environment label for an inbound webhook listener. */
|
|
189
|
+
type WebhookEnvironment = "dev" | "sandbox" | "prod";
|
|
190
|
+
/** Per-listener routing configuration ({@link IWebhookListenerConfig.routingConfig}). */
|
|
191
|
+
interface IWebhookListenerRoutingConfig {
|
|
192
|
+
/** Event types to skip (marked `skipped`, never dispatched to an agent). */
|
|
193
|
+
ignoredEventTypes?: string[];
|
|
194
|
+
/**
|
|
195
|
+
* `"route"` dispatches buffered events to the target agent;
|
|
196
|
+
* `"buffer_only"` accepts + logs events but skips agent dispatch.
|
|
197
|
+
*/
|
|
198
|
+
mode?: "route" | "buffer_only";
|
|
199
|
+
/** Retention window in days for processed/skipped events. */
|
|
200
|
+
retentionDays?: number;
|
|
201
|
+
/** Sender IPs allowed to hit the ingest endpoint. Empty/omitted = all. */
|
|
202
|
+
ipAllowlist?: string[];
|
|
203
|
+
/**
|
|
204
|
+
* Webhook-specific guidance appended to the agent prompt on every
|
|
205
|
+
* dispatched event (payload shapes, which tools to call, etc.).
|
|
206
|
+
*/
|
|
207
|
+
instructions?: string;
|
|
208
|
+
/** Ingest quota for this listener. Defaults to 100, capped at 1000. */
|
|
209
|
+
rateLimitPerMinute?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* An inbound webhook listener as configured in AgentPress. Listeners receive
|
|
213
|
+
* external events on `POST /webhooks/ingest/:org/:identifier`, buffer them
|
|
214
|
+
* durably, and route them into actions for the target agent.
|
|
215
|
+
*/
|
|
216
|
+
interface IWebhookListenerConfig {
|
|
217
|
+
/** Human-readable display name. */
|
|
218
|
+
name: string;
|
|
219
|
+
/** Stable slug used in the ingest URL path. */
|
|
220
|
+
identifier: string;
|
|
221
|
+
/** How inbound requests are authenticated. */
|
|
222
|
+
verificationScheme: WebhookVerificationScheme;
|
|
223
|
+
/** Environment label for the listener. */
|
|
224
|
+
environment: WebhookEnvironment;
|
|
225
|
+
/** Disabled listeners reject inbound events at the edge. */
|
|
226
|
+
enabled: boolean;
|
|
227
|
+
/** Agent on the listener's default action rule (quick-setup path). */
|
|
228
|
+
targetAgentId: string | null;
|
|
229
|
+
/** Fallback user actions run as when the payload does not resolve one. */
|
|
230
|
+
runAsUserId: string | null;
|
|
231
|
+
/** Routing, retention, and rate-limit configuration. */
|
|
232
|
+
routingConfig: IWebhookListenerRoutingConfig;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* An action rule's listen subscription. Rules that subscribe to a listening
|
|
236
|
+
* webhook receive its buffered events in addition to the webhook's default
|
|
237
|
+
* rule, so one listening URL can fan out to several rules.
|
|
238
|
+
*/
|
|
239
|
+
interface IActionRuleListenSubscription {
|
|
240
|
+
/** Webhook listener this rule subscribes to; `null` = no subscription. */
|
|
241
|
+
listenWebhookId: string | null;
|
|
242
|
+
/** Event types to receive; empty array = all event types. */
|
|
243
|
+
listenEventTypes: string[];
|
|
244
|
+
}
|
|
142
245
|
/** Action lifecycle event types emitted by AgentPress. */
|
|
143
246
|
type ActionEventType = "action.pending_approval" | "action.approved" | "action.completed" | "action.failed" | "action.rejected" | "action.expired";
|
|
144
247
|
/** All public action callback event types emitted by AgentPress. */
|
|
@@ -677,6 +780,17 @@ declare class WebhooksClient {
|
|
|
677
780
|
* Send an arbitrary webhook payload to AgentPress.
|
|
678
781
|
* Signs the payload with HMAC-SHA256 (Svix-compatible).
|
|
679
782
|
*
|
|
783
|
+
* On the happy path the response is synchronous: `{ success: true,
|
|
784
|
+
* actionId, data }`, or `{ success, actionId, alreadyExists: true, data }`
|
|
785
|
+
* when an action with the same `externalId` already existed (idempotency).
|
|
786
|
+
*
|
|
787
|
+
* Configuration/resolution failures (no action rule configured, rule
|
|
788
|
+
* disabled, user unresolved, action insert failure) do NOT throw — the
|
|
789
|
+
* event is buffered durably and AgentPress responds **202** with
|
|
790
|
+
* `{ success: true, buffered: true, eventId, reason }`. The event
|
|
791
|
+
* auto-processes once an operator fixes the configuration, so check
|
|
792
|
+
* {@link WebhookResponse.buffered} before relying on `actionId`.
|
|
793
|
+
*
|
|
680
794
|
* @throws ConfigurationError if webhookSecret is not configured
|
|
681
795
|
* @throws HttpError on non-2xx response
|
|
682
796
|
* @throws TimeoutError if request exceeds timeout
|
|
@@ -810,5 +924,42 @@ declare class KeyRotationVerifyError extends AgentPressError {
|
|
|
810
924
|
constructor(reason: KeyRotationVerifyErrorReason, message: string);
|
|
811
925
|
}
|
|
812
926
|
//#endregion
|
|
813
|
-
|
|
927
|
+
//#region src/webhooks/ingestSigning.d.ts
|
|
928
|
+
/**
|
|
929
|
+
* Sign an outbound request for an AgentPress inbound webhook listener that
|
|
930
|
+
* uses the `hmac_sha256` verification scheme
|
|
931
|
+
* (`POST /webhooks/ingest/:org/:identifier`).
|
|
932
|
+
*
|
|
933
|
+
* Produces the two headers AgentPress verifies:
|
|
934
|
+
*
|
|
935
|
+
* - `x-webhook-timestamp` — unix seconds; AgentPress rejects timestamps more
|
|
936
|
+
* than 5 minutes from its own clock.
|
|
937
|
+
* - `x-webhook-signature` — `v1=<hex HMAC-SHA256 of "${timestamp}.${rawBody}">`.
|
|
938
|
+
*
|
|
939
|
+
* Send the exact `rawBody` string you signed — any re-serialization after
|
|
940
|
+
* signing (re-ordered keys, whitespace changes) invalidates the signature.
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```ts
|
|
944
|
+
* const rawBody = JSON.stringify({ eventType: "review.created", data: {...} });
|
|
945
|
+
* const { headers } = signHmacWebhookRequest({ secret, rawBody });
|
|
946
|
+
* await fetch(ingestUrl, {
|
|
947
|
+
* method: "POST",
|
|
948
|
+
* body: rawBody,
|
|
949
|
+
* headers: { "content-type": "application/json", ...headers },
|
|
950
|
+
* });
|
|
951
|
+
* ```
|
|
952
|
+
*/
|
|
953
|
+
declare function signHmacWebhookRequest(params: SignHmacWebhookRequestParams): SignedHmacWebhookRequest;
|
|
954
|
+
/**
|
|
955
|
+
* Build the auth header for an AgentPress inbound webhook listener that uses
|
|
956
|
+
* the `shared_token` verification scheme. AgentPress also accepts
|
|
957
|
+
* `Authorization: Bearer <token>`; this helper uses the dedicated
|
|
958
|
+
* `x-webhook-token` header so it never collides with other auth middleware.
|
|
959
|
+
*/
|
|
960
|
+
declare function sharedTokenHeaders(token: string): {
|
|
961
|
+
"x-webhook-token": string;
|
|
962
|
+
};
|
|
963
|
+
//#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 IActionRuleListenSubscription, 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 ToolCallResult, type UpdateUserApprovalParams, UserApprovalsClient, type UserToolApproval, type WebhookApprovalMetadata, type WebhookApprovalToolMetadata, type WebhookEnvironment, type WebhookResponse, type WebhookSendParams, WebhookSignatureError, type WebhookVerificationScheme, type WebhookVerifyParams, WebhooksClient, sharedTokenHeaders, signHmacWebhookRequest };
|
|
814
965
|
//# 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"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAkBa;EAhBb,MAAA;EAoBqC;EAlBrC,OAAA;EAkB6C;EAhB7C,OAAA;EAJA;EAMA,GAAA;EAFA;;;;;;;;;EAYA,UAAA,GAAa,iBAAA;EAIwB;EAFrC,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,WAAA;EAEa;EAA7C,UAAA,IAAc,GAAA,UAAa,QAAA,EAAU,QAAA;AAAA;;UAItB,iBAAA;EAAiB;;;;;;;EAQhC,OAAA;EAqBiB;AAInB;;;;EAnBE,MAAA;EAuBA;EArBA,QAAA;EAyBA;EAvBA,mBAAA;EA2BA;;;;;EArBA,cAAA;EAiCC;;AAAW;AAId;EAhCE,iBAAA;AAAA;;UAIe,kBAAA;EA8BG;EA5BlB,GAAA;EAkCS;EAhCT,KAAA;EAgCe;EA9Bf,YAAA;EAkC+B;EAhC/B,GAAA;EAgC+B;EA9B/B,GAAA;EAgCA;EA9BA,GAAA;EAgCA;EA9BA,GAAA;EAkCA;EAhCA,GAAA;EAoCA;EAlCA,MAAA;EAkCM;EAhCN,SAAA;EAoCgC;EAlChC,WAAA;EAsCe;EAAA,CApCd,GAAA;AAAA;;UAIc,uBAAA;EAgCA;EA9Bf,OAAA,WAAkB,MAAA;EAkCgB;;;;;EA5BlC,OAAA,EAAS,MAAM;AAAA;;UAIA,gBAAA;EACf,KAAA;EACA,IAAA;EACA,UAAA;EACA,aAAA;;EAEA,SAAA;EA+BA;EA7BA,WAAA;EAiCA;EA/BA,OAAA;
|
|
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/ingestSigning.ts"],"mappings":";;UACiB,iBAAA;EAAiB;EAEhC,aAAA;EAkBa;EAhBb,MAAA;EAoBqC;EAlBrC,OAAA;EAkB6C;EAhB7C,OAAA;EAJA;EAMA,GAAA;EAFA;;;;;;;;;EAYA,UAAA,GAAa,iBAAA;EAIwB;EAFrC,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,WAAA;EAEa;EAA7C,UAAA,IAAc,GAAA,UAAa,QAAA,EAAU,QAAA;AAAA;;UAItB,iBAAA;EAAiB;;;;;;;EAQhC,OAAA;EAqBiB;AAInB;;;;EAnBE,MAAA;EAuBA;EArBA,QAAA;EAyBA;EAvBA,mBAAA;EA2BA;;;;;EArBA,cAAA;EAiCC;;AAAW;AAId;EAhCE,iBAAA;AAAA;;UAIe,kBAAA;EA8BG;EA5BlB,GAAA;EAkCS;EAhCT,KAAA;EAgCe;EA9Bf,YAAA;EAkC+B;EAhC/B,GAAA;EAgC+B;EA9B/B,GAAA;EAgCA;EA9BA,GAAA;EAgCA;EA9BA,GAA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AwB;;;;;;;iBAqBX,kBAAA,CAAmB,KAAA;EACjC,iBAAiB;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -618,6 +618,17 @@ var WebhooksClient = class {
|
|
|
618
618
|
* Send an arbitrary webhook payload to AgentPress.
|
|
619
619
|
* Signs the payload with HMAC-SHA256 (Svix-compatible).
|
|
620
620
|
*
|
|
621
|
+
* On the happy path the response is synchronous: `{ success: true,
|
|
622
|
+
* actionId, data }`, or `{ success, actionId, alreadyExists: true, data }`
|
|
623
|
+
* when an action with the same `externalId` already existed (idempotency).
|
|
624
|
+
*
|
|
625
|
+
* Configuration/resolution failures (no action rule configured, rule
|
|
626
|
+
* disabled, user unresolved, action insert failure) do NOT throw — the
|
|
627
|
+
* event is buffered durably and AgentPress responds **202** with
|
|
628
|
+
* `{ success: true, buffered: true, eventId, reason }`. The event
|
|
629
|
+
* auto-processes once an operator fixes the configuration, so check
|
|
630
|
+
* {@link WebhookResponse.buffered} before relying on `actionId`.
|
|
631
|
+
*
|
|
621
632
|
* @throws ConfigurationError if webhookSecret is not configured
|
|
622
633
|
* @throws HttpError on non-2xx response
|
|
623
634
|
* @throws TimeoutError if request exceeds timeout
|
|
@@ -781,6 +792,49 @@ const ACTION_EVENT_TYPES = [
|
|
|
781
792
|
"action.expired"
|
|
782
793
|
];
|
|
783
794
|
//#endregion
|
|
784
|
-
|
|
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
|
+
export { ACTION_EVENT_TYPES, ActionsClient, AgentPress, AgentPressError, ConfigurationError, HttpError, KeyRotationVerifyError, PartnerTokenError, PartnersClient, TimeoutError, UserApprovalsClient, WebhookSignatureError, WebhooksClient, sharedTokenHeaders, signHmacWebhookRequest };
|
|
785
839
|
|
|
786
840
|
//# sourceMappingURL=index.mjs.map
|