@agentuity/server 1.0.22 → 1.0.23

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.
Files changed (62) hide show
  1. package/dist/api/index.d.ts +1 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +1 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/project/deploy.d.ts +8 -0
  6. package/dist/api/project/deploy.d.ts.map +1 -1
  7. package/dist/api/project/deploy.js +14 -13
  8. package/dist/api/project/deploy.js.map +1 -1
  9. package/dist/api/sandbox/execute.d.ts +2 -2
  10. package/dist/api/sandbox/execution.d.ts +4 -4
  11. package/dist/api/sandbox/snapshot-build.d.ts +2 -0
  12. package/dist/api/sandbox/snapshot-build.d.ts.map +1 -1
  13. package/dist/api/sandbox/snapshot-build.js +4 -0
  14. package/dist/api/sandbox/snapshot-build.js.map +1 -1
  15. package/dist/api/webhook/deliveries.d.ts +94 -0
  16. package/dist/api/webhook/deliveries.d.ts.map +1 -0
  17. package/dist/api/webhook/deliveries.js +79 -0
  18. package/dist/api/webhook/deliveries.js.map +1 -0
  19. package/dist/api/webhook/destinations.d.ts +136 -0
  20. package/dist/api/webhook/destinations.d.ts.map +1 -0
  21. package/dist/api/webhook/destinations.js +137 -0
  22. package/dist/api/webhook/destinations.js.map +1 -0
  23. package/dist/api/webhook/index.d.ts +41 -0
  24. package/dist/api/webhook/index.d.ts.map +1 -0
  25. package/dist/api/webhook/index.js +59 -0
  26. package/dist/api/webhook/index.js.map +1 -0
  27. package/dist/api/webhook/receipts.d.ts +77 -0
  28. package/dist/api/webhook/receipts.d.ts.map +1 -0
  29. package/dist/api/webhook/receipts.js +78 -0
  30. package/dist/api/webhook/receipts.js.map +1 -0
  31. package/dist/api/webhook/types.d.ts +249 -0
  32. package/dist/api/webhook/types.d.ts.map +1 -0
  33. package/dist/api/webhook/types.js +221 -0
  34. package/dist/api/webhook/types.js.map +1 -0
  35. package/dist/api/webhook/util.d.ts +202 -0
  36. package/dist/api/webhook/util.d.ts.map +1 -0
  37. package/dist/api/webhook/util.js +201 -0
  38. package/dist/api/webhook/util.js.map +1 -0
  39. package/dist/api/webhook/webhooks.d.ts +146 -0
  40. package/dist/api/webhook/webhooks.d.ts.map +1 -0
  41. package/dist/api/webhook/webhooks.js +165 -0
  42. package/dist/api/webhook/webhooks.js.map +1 -0
  43. package/dist/config.d.ts +1 -0
  44. package/dist/config.d.ts.map +1 -1
  45. package/dist/config.js +1 -0
  46. package/dist/config.js.map +1 -1
  47. package/dist/runtime-bootstrap.d.ts.map +1 -1
  48. package/dist/runtime-bootstrap.js +3 -0
  49. package/dist/runtime-bootstrap.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/api/index.ts +1 -0
  52. package/src/api/project/deploy.ts +16 -16
  53. package/src/api/sandbox/snapshot-build.ts +6 -0
  54. package/src/api/webhook/deliveries.ts +129 -0
  55. package/src/api/webhook/destinations.ts +224 -0
  56. package/src/api/webhook/index.ts +133 -0
  57. package/src/api/webhook/receipts.ts +124 -0
  58. package/src/api/webhook/types.ts +309 -0
  59. package/src/api/webhook/util.ts +237 -0
  60. package/src/api/webhook/webhooks.ts +260 -0
  61. package/src/config.ts +2 -0
  62. package/src/runtime-bootstrap.ts +3 -0
@@ -0,0 +1,224 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema, APIResponseSchemaNoData } from '../api.ts';
3
+ import {
4
+ type CreateWebhookDestinationRequest,
5
+ CreateWebhookDestinationRequestSchema,
6
+ type UpdateWebhookDestinationRequest,
7
+ UpdateWebhookDestinationRequestSchema,
8
+ type WebhookApiOptions,
9
+ type WebhookDestination,
10
+ WebhookDestinationSchema,
11
+ } from './types.ts';
12
+ import {
13
+ buildWebhookHeaders,
14
+ WebhookError,
15
+ webhookApiPath,
16
+ withWebhookErrorHandling,
17
+ } from './util.ts';
18
+
19
+ export const WebhookDestinationResponseSchema = APIResponseSchema(WebhookDestinationSchema);
20
+ export const WebhookDestinationsListResponseSchema = APIResponseSchema(
21
+ z.array(WebhookDestinationSchema)
22
+ );
23
+ export const DeleteWebhookDestinationResponseSchema = APIResponseSchemaNoData();
24
+
25
+ /**
26
+ * Create a destination for a webhook.
27
+ *
28
+ * Destinations define where incoming webhook payloads are forwarded to.
29
+ * When a webhook receives a payload, it will be delivered to all configured destinations.
30
+ *
31
+ * @param client - The API client instance
32
+ * @param webhookId - The webhook ID (prefixed with wh_)
33
+ * @param params - Destination configuration including type and config
34
+ * @param options - Optional API options (e.g., orgId)
35
+ * @returns The created destination
36
+ * @throws {WebhookNotFoundError} If the webhook does not exist
37
+ * @throws {WebhookError} If the API request fails
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const destination = await createWebhookDestination(client, 'wh_abc123', {
42
+ * type: 'url',
43
+ * config: { url: 'https://api.example.com/webhook' },
44
+ * });
45
+ * console.log(`Created destination ${destination.id}`);
46
+ * ```
47
+ */
48
+ export async function createWebhookDestination(
49
+ client: APIClient,
50
+ webhookId: string,
51
+ params: CreateWebhookDestinationRequest,
52
+ options?: WebhookApiOptions
53
+ ): Promise<WebhookDestination> {
54
+ const url = webhookApiPath('destination-create', webhookId);
55
+ const resp = await withWebhookErrorHandling(
56
+ () =>
57
+ client.post(
58
+ url,
59
+ params,
60
+ WebhookDestinationResponseSchema,
61
+ CreateWebhookDestinationRequestSchema,
62
+ undefined,
63
+ buildWebhookHeaders(options?.orgId)
64
+ ),
65
+ { webhookId }
66
+ );
67
+
68
+ if (resp.success) {
69
+ return resp.data;
70
+ }
71
+
72
+ throw new WebhookError({
73
+ webhookId,
74
+ message: resp.message || 'Failed to create webhook destination',
75
+ });
76
+ }
77
+
78
+ /**
79
+ * List all destinations for a webhook.
80
+ *
81
+ * Retrieves all destinations configured for a webhook.
82
+ *
83
+ * @param client - The API client instance
84
+ * @param webhookId - The webhook ID (prefixed with wh_)
85
+ * @param options - Optional API options (e.g., orgId)
86
+ * @returns Array of destinations configured for the webhook
87
+ * @throws {WebhookNotFoundError} If the webhook does not exist
88
+ * @throws {WebhookError} If the API request fails
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const destinations = await listWebhookDestinations(client, 'wh_abc123');
93
+ * for (const dest of destinations) {
94
+ * console.log(`Destination ${dest.id}: type=${dest.type}`);
95
+ * }
96
+ * ```
97
+ */
98
+ export async function listWebhookDestinations(
99
+ client: APIClient,
100
+ webhookId: string,
101
+ options?: WebhookApiOptions
102
+ ): Promise<WebhookDestination[]> {
103
+ const url = webhookApiPath('destination-list', webhookId);
104
+ const resp = await withWebhookErrorHandling(
105
+ () =>
106
+ client.get(
107
+ url,
108
+ WebhookDestinationsListResponseSchema,
109
+ undefined,
110
+ buildWebhookHeaders(options?.orgId)
111
+ ),
112
+ { webhookId }
113
+ );
114
+
115
+ if (resp.success) {
116
+ return resp.data;
117
+ }
118
+
119
+ throw new WebhookError({
120
+ webhookId,
121
+ message: resp.message || 'Failed to list webhook destinations',
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Update a webhook destination's configuration.
127
+ *
128
+ * Modifies an existing destination's config. Only the fields provided in params will be updated.
129
+ *
130
+ * @param client - The API client instance
131
+ * @param webhookId - The webhook ID (prefixed with wh_)
132
+ * @param destinationId - The destination ID to update (prefixed with whds_)
133
+ * @param params - Fields to update
134
+ * @param options - Optional API options (e.g., orgId)
135
+ * @returns The updated destination
136
+ * @throws {WebhookDestinationNotFoundError} If the destination does not exist
137
+ * @throws {WebhookNotFoundError} If the webhook does not exist
138
+ * @throws {WebhookError} If the API request fails
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const updated = await updateWebhookDestination(client, 'wh_abc123', 'whds_def456', {
143
+ * config: { url: 'https://api.example.com/webhook/v2' },
144
+ * });
145
+ * ```
146
+ */
147
+ export async function updateWebhookDestination(
148
+ client: APIClient,
149
+ webhookId: string,
150
+ destinationId: string,
151
+ params: UpdateWebhookDestinationRequest,
152
+ options?: WebhookApiOptions
153
+ ): Promise<WebhookDestination> {
154
+ const url = webhookApiPath('destination-update', webhookId, destinationId);
155
+ const resp = await withWebhookErrorHandling(
156
+ () =>
157
+ client.put(
158
+ url,
159
+ params,
160
+ WebhookDestinationResponseSchema,
161
+ UpdateWebhookDestinationRequestSchema,
162
+ undefined,
163
+ buildWebhookHeaders(options?.orgId)
164
+ ),
165
+ { webhookId, destinationId }
166
+ );
167
+
168
+ if (resp.success) {
169
+ return resp.data;
170
+ }
171
+
172
+ throw new WebhookError({
173
+ webhookId,
174
+ message: resp.message || 'Failed to update webhook destination',
175
+ });
176
+ }
177
+
178
+ /**
179
+ * Delete a webhook destination.
180
+ *
181
+ * Permanently removes a destination. Webhook payloads will no longer be
182
+ * forwarded to this endpoint. This action cannot be undone.
183
+ *
184
+ * @param client - The API client instance
185
+ * @param webhookId - The webhook ID (prefixed with wh_)
186
+ * @param destinationId - The destination ID to delete (prefixed with whds_)
187
+ * @param options - Optional API options (e.g., orgId)
188
+ * @throws {WebhookDestinationNotFoundError} If the destination does not exist
189
+ * @throws {WebhookNotFoundError} If the webhook does not exist
190
+ * @throws {WebhookError} If the API request fails
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * await deleteWebhookDestination(client, 'wh_abc123', 'whds_def456');
195
+ * console.log('Destination deleted');
196
+ * ```
197
+ */
198
+ export async function deleteWebhookDestination(
199
+ client: APIClient,
200
+ webhookId: string,
201
+ destinationId: string,
202
+ options?: WebhookApiOptions
203
+ ): Promise<void> {
204
+ const url = webhookApiPath('destination-delete', webhookId, destinationId);
205
+ const resp = await withWebhookErrorHandling(
206
+ () =>
207
+ client.delete(
208
+ url,
209
+ DeleteWebhookDestinationResponseSchema,
210
+ undefined,
211
+ buildWebhookHeaders(options?.orgId)
212
+ ),
213
+ { webhookId, destinationId }
214
+ );
215
+
216
+ if (resp.success) {
217
+ return;
218
+ }
219
+
220
+ throw new WebhookError({
221
+ webhookId,
222
+ message: resp.message || 'Failed to delete webhook destination',
223
+ });
224
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @module webhook
3
+ *
4
+ * Webhook API client for managing webhooks, destinations, receipts, and deliveries.
5
+ *
6
+ * This module provides a complete client for the Agentuity Webhook API, supporting:
7
+ * - **Webhook Management**: Create, read, update, and delete webhooks
8
+ * - **Destinations**: Configure URL endpoints for webhook payload forwarding
9
+ * - **Receipts**: View incoming webhook payloads that were received
10
+ * - **Deliveries**: Track delivery attempts and retry failed deliveries
11
+ *
12
+ * @example Basic Webhook Operations
13
+ * ```typescript
14
+ * import { createWebhook, createWebhookDestination, listWebhookReceipts } from '@agentuity/server';
15
+ *
16
+ * // Create a webhook
17
+ * const webhook = await createWebhook(client, {
18
+ * name: 'github-events',
19
+ * description: 'Receives GitHub webhook events',
20
+ * });
21
+ *
22
+ * // Add a destination
23
+ * await createWebhookDestination(client, webhook.id, {
24
+ * type: 'url',
25
+ * config: { url: 'https://api.example.com/webhook' },
26
+ * });
27
+ *
28
+ * // List receipts
29
+ * const { receipts } = await listWebhookReceipts(client, webhook.id);
30
+ * for (const receipt of receipts) {
31
+ * console.log(`Received: ${receipt.id} at ${receipt.date}`);
32
+ * }
33
+ * ```
34
+ */
35
+
36
+ // ============================================================================
37
+ // Types & Schemas
38
+ // ============================================================================
39
+
40
+ export {
41
+ type CreateWebhookDestinationRequest,
42
+ CreateWebhookDestinationRequestSchema,
43
+ type CreateWebhookRequest,
44
+ CreateWebhookRequestSchema,
45
+ type ListWebhookDeliveriesRequest,
46
+ ListWebhookDeliveriesRequestSchema,
47
+ type ListWebhookReceiptsRequest,
48
+ ListWebhookReceiptsRequestSchema,
49
+ type ListWebhooksRequest,
50
+ ListWebhooksRequestSchema,
51
+ type PaginationRequest,
52
+ PaginationRequestSchema,
53
+ type UpdateWebhookDestinationRequest,
54
+ UpdateWebhookDestinationRequestSchema,
55
+ type UpdateWebhookRequest,
56
+ UpdateWebhookRequestSchema,
57
+ type Webhook,
58
+ type WebhookApiOptions,
59
+ type WebhookDelivery,
60
+ WebhookDeliverySchema,
61
+ type WebhookDeliveryStatus,
62
+ WebhookDeliveryStatusSchema,
63
+ type WebhookDestination,
64
+ WebhookDestinationSchema,
65
+ type WebhookDestinationType,
66
+ WebhookDestinationTypeSchema,
67
+ type WebhookReceipt,
68
+ WebhookReceiptSchema,
69
+ WebhookSchema,
70
+ } from './types.ts';
71
+
72
+ // ============================================================================
73
+ // Errors
74
+ // ============================================================================
75
+
76
+ export {
77
+ WebhookDeliveryNotFoundError,
78
+ WebhookDestinationNotFoundError,
79
+ WebhookError,
80
+ WebhookNotFoundError,
81
+ WebhookReceiptNotFoundError,
82
+ } from './util.ts';
83
+
84
+ // ============================================================================
85
+ // Webhook Operations
86
+ // ============================================================================
87
+
88
+ export {
89
+ createWebhook,
90
+ DeleteWebhookResponseSchema,
91
+ deleteWebhook,
92
+ getWebhook,
93
+ listWebhooks,
94
+ WebhookResponseSchema,
95
+ WebhooksListResponseSchema,
96
+ updateWebhook,
97
+ } from './webhooks.ts';
98
+
99
+ // ============================================================================
100
+ // Destination Operations
101
+ // ============================================================================
102
+
103
+ export {
104
+ createWebhookDestination,
105
+ DeleteWebhookDestinationResponseSchema,
106
+ deleteWebhookDestination,
107
+ listWebhookDestinations,
108
+ updateWebhookDestination,
109
+ WebhookDestinationResponseSchema,
110
+ WebhookDestinationsListResponseSchema,
111
+ } from './destinations.ts';
112
+
113
+ // ============================================================================
114
+ // Receipt Operations
115
+ // ============================================================================
116
+
117
+ export {
118
+ getWebhookReceipt,
119
+ listWebhookReceipts,
120
+ WebhookReceiptResponseSchema,
121
+ WebhookReceiptsListResponseSchema,
122
+ } from './receipts.ts';
123
+
124
+ // ============================================================================
125
+ // Delivery Operations
126
+ // ============================================================================
127
+
128
+ export {
129
+ listWebhookDeliveries,
130
+ retryWebhookDelivery,
131
+ WebhookDeliveriesListResponseSchema,
132
+ WebhookDeliveryResponseSchema,
133
+ } from './deliveries.ts';
@@ -0,0 +1,124 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema } from '../api.ts';
3
+ import {
4
+ type ListWebhookReceiptsRequest,
5
+ type WebhookApiOptions,
6
+ type WebhookReceipt,
7
+ WebhookReceiptSchema,
8
+ } from './types.ts';
9
+ import {
10
+ buildWebhookHeaders,
11
+ WebhookError,
12
+ webhookApiPath,
13
+ webhookApiPathWithQuery,
14
+ withWebhookErrorHandling,
15
+ } from './util.ts';
16
+
17
+ export const WebhookReceiptResponseSchema = APIResponseSchema(WebhookReceiptSchema);
18
+ export const WebhookReceiptsListResponseSchema = APIResponseSchema(z.array(WebhookReceiptSchema));
19
+
20
+ /**
21
+ * List receipts for a webhook with optional pagination.
22
+ *
23
+ * Receipts represent incoming webhook payloads that were received.
24
+ *
25
+ * @param client - The API client instance
26
+ * @param webhookId - The webhook ID (prefixed with wh_)
27
+ * @param params - Optional pagination parameters
28
+ * @param options - Optional API options (e.g., orgId)
29
+ * @returns Object containing the list of receipts
30
+ * @throws {WebhookNotFoundError} If the webhook does not exist
31
+ * @throws {WebhookError} If the API request fails
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const { receipts } = await listWebhookReceipts(client, 'wh_abc123', { limit: 10 });
36
+ * for (const receipt of receipts) {
37
+ * console.log(`Receipt ${receipt.id}: received at ${receipt.date}`);
38
+ * }
39
+ * ```
40
+ */
41
+ export async function listWebhookReceipts(
42
+ client: APIClient,
43
+ webhookId: string,
44
+ params?: ListWebhookReceiptsRequest,
45
+ options?: WebhookApiOptions
46
+ ): Promise<{ receipts: WebhookReceipt[] }> {
47
+ const searchParams = new URLSearchParams();
48
+ if (params?.limit !== undefined) {
49
+ searchParams.set('limit', String(params.limit));
50
+ }
51
+ if (params?.offset !== undefined) {
52
+ searchParams.set('offset', String(params.offset));
53
+ }
54
+
55
+ const queryString = searchParams.toString();
56
+ const url = webhookApiPathWithQuery('receipt-list', queryString || undefined, webhookId);
57
+ const resp = await withWebhookErrorHandling(
58
+ () =>
59
+ client.get(
60
+ url,
61
+ WebhookReceiptsListResponseSchema,
62
+ undefined,
63
+ buildWebhookHeaders(options?.orgId)
64
+ ),
65
+ { webhookId }
66
+ );
67
+
68
+ if (resp.success) {
69
+ return { receipts: resp.data };
70
+ }
71
+
72
+ throw new WebhookError({
73
+ webhookId,
74
+ message: resp.message || 'Failed to list webhook receipts',
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Get a specific receipt for a webhook.
80
+ *
81
+ * Retrieves the full receipt details including headers and payload.
82
+ *
83
+ * @param client - The API client instance
84
+ * @param webhookId - The webhook ID (prefixed with wh_)
85
+ * @param receiptId - The receipt ID (prefixed with whrc_)
86
+ * @param options - Optional API options (e.g., orgId)
87
+ * @returns The receipt details
88
+ * @throws {WebhookReceiptNotFoundError} If the receipt does not exist
89
+ * @throws {WebhookNotFoundError} If the webhook does not exist
90
+ * @throws {WebhookError} If the API request fails
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const receipt = await getWebhookReceipt(client, 'wh_abc123', 'whrc_def456');
95
+ * console.log(`Receipt payload:`, receipt.payload);
96
+ * ```
97
+ */
98
+ export async function getWebhookReceipt(
99
+ client: APIClient,
100
+ webhookId: string,
101
+ receiptId: string,
102
+ options?: WebhookApiOptions
103
+ ): Promise<WebhookReceipt> {
104
+ const url = webhookApiPath('receipt-get', webhookId, receiptId);
105
+ const resp = await withWebhookErrorHandling(
106
+ () =>
107
+ client.get(
108
+ url,
109
+ WebhookReceiptResponseSchema,
110
+ undefined,
111
+ buildWebhookHeaders(options?.orgId)
112
+ ),
113
+ { webhookId, receiptId }
114
+ );
115
+
116
+ if (resp.success) {
117
+ return resp.data;
118
+ }
119
+
120
+ throw new WebhookError({
121
+ webhookId,
122
+ message: resp.message || 'Failed to get webhook receipt',
123
+ });
124
+ }