@agentuity/core 1.0.34 → 1.0.35
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/services/db/index.d.ts +1 -0
- package/dist/services/db/index.d.ts.map +1 -1
- package/dist/services/db/index.js +1 -0
- package/dist/services/db/index.js.map +1 -1
- package/dist/services/db/stats.d.ts +146 -0
- package/dist/services/db/stats.d.ts.map +1 -0
- package/dist/services/db/stats.js +94 -0
- package/dist/services/db/stats.js.map +1 -0
- package/dist/services/queue/types.d.ts.map +1 -1
- package/dist/services/queue/types.js +8 -2
- package/dist/services/queue/types.js.map +1 -1
- package/dist/services/queue/websocket.d.ts.map +1 -1
- package/dist/services/queue/websocket.js +27 -8
- package/dist/services/queue/websocket.js.map +1 -1
- package/dist/services/sandbox/types.d.ts.map +1 -1
- package/dist/services/sandbox/types.js.map +1 -1
- package/dist/services/webhook/analytics.d.ts +77 -0
- package/dist/services/webhook/analytics.d.ts.map +1 -0
- package/dist/services/webhook/analytics.js +56 -0
- package/dist/services/webhook/analytics.js.map +1 -0
- package/dist/services/webhook/destinations.d.ts +4 -0
- package/dist/services/webhook/destinations.d.ts.map +1 -1
- package/dist/services/webhook/index.d.ts +2 -1
- package/dist/services/webhook/index.d.ts.map +1 -1
- package/dist/services/webhook/index.js +5 -1
- package/dist/services/webhook/index.js.map +1 -1
- package/dist/services/webhook/service.d.ts +43 -1
- package/dist/services/webhook/service.d.ts.map +1 -1
- package/dist/services/webhook/service.js +74 -0
- package/dist/services/webhook/service.js.map +1 -1
- package/dist/services/webhook/types.d.ts +79 -0
- package/dist/services/webhook/types.d.ts.map +1 -1
- package/dist/services/webhook/types.js +62 -0
- package/dist/services/webhook/types.js.map +1 -1
- package/dist/services/webhook/webhooks.d.ts +4 -0
- package/dist/services/webhook/webhooks.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/services/db/index.ts +15 -0
- package/src/services/db/stats.ts +121 -0
- package/src/services/queue/types.ts +12 -2
- package/src/services/queue/websocket.ts +32 -8
- package/src/services/sandbox/types.ts +0 -1
- package/src/services/webhook/analytics.ts +80 -0
- package/src/services/webhook/index.ts +25 -0
- package/src/services/webhook/service.ts +124 -0
- package/src/services/webhook/types.ts +92 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type APIClient, APIResponseSchema } from '../api.ts';
|
|
3
|
+
import {
|
|
4
|
+
type WebhookAnalyticsOptions,
|
|
5
|
+
type WebhookOrgAnalytics,
|
|
6
|
+
WebhookOrgAnalyticsSchema,
|
|
7
|
+
type WebhookTimeSeriesData,
|
|
8
|
+
WebhookTimeSeriesDataSchema,
|
|
9
|
+
} from './types.ts';
|
|
10
|
+
import { buildWebhookHeaders, WebhookError, webhookApiPathWithQuery } from './util.ts';
|
|
11
|
+
|
|
12
|
+
export const WebhookOrgAnalyticsResponseSchema = APIResponseSchema(
|
|
13
|
+
z.object({ analytics: WebhookOrgAnalyticsSchema })
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const WebhookTimeSeriesResponseSchema = APIResponseSchema(
|
|
17
|
+
z.object({ timeseries: WebhookTimeSeriesDataSchema })
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
function buildAnalyticsQuery(options?: WebhookAnalyticsOptions): string | undefined {
|
|
21
|
+
if (!options) return undefined;
|
|
22
|
+
const params = new URLSearchParams();
|
|
23
|
+
if (options.start) params.set('start', options.start);
|
|
24
|
+
if (options.end) params.set('end', options.end);
|
|
25
|
+
if (options.granularity) params.set('granularity', options.granularity);
|
|
26
|
+
const query = params.toString();
|
|
27
|
+
return query || undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get org-level webhook analytics summary.
|
|
32
|
+
*
|
|
33
|
+
* Returns total received, delivered, and failed counts for all webhooks in the org
|
|
34
|
+
* within the specified time period.
|
|
35
|
+
*
|
|
36
|
+
* @param client - The API client
|
|
37
|
+
* @param options - Analytics options (start, end, granularity)
|
|
38
|
+
* @returns Org-level webhook analytics
|
|
39
|
+
*/
|
|
40
|
+
export async function getWebhookOrgAnalytics(
|
|
41
|
+
client: APIClient,
|
|
42
|
+
options?: WebhookAnalyticsOptions
|
|
43
|
+
): Promise<WebhookOrgAnalytics> {
|
|
44
|
+
const queryString = buildAnalyticsQuery(options);
|
|
45
|
+
const url = webhookApiPathWithQuery('analytics/org', queryString);
|
|
46
|
+
const resp = await client.get(
|
|
47
|
+
url,
|
|
48
|
+
WebhookOrgAnalyticsResponseSchema,
|
|
49
|
+
undefined,
|
|
50
|
+
buildWebhookHeaders(options?.orgId)
|
|
51
|
+
);
|
|
52
|
+
if (resp.success) return resp.data.analytics;
|
|
53
|
+
throw new WebhookError({ message: resp.message || 'Failed to get webhook org analytics' });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get org-level webhook time series data.
|
|
58
|
+
*
|
|
59
|
+
* Returns time-bucketed received, delivered, and failed counts for all webhooks
|
|
60
|
+
* in the org within the specified time period.
|
|
61
|
+
*
|
|
62
|
+
* @param client - The API client
|
|
63
|
+
* @param options - Analytics options (start, end, granularity)
|
|
64
|
+
* @returns Webhook time series data
|
|
65
|
+
*/
|
|
66
|
+
export async function getWebhookOrgTimeSeries(
|
|
67
|
+
client: APIClient,
|
|
68
|
+
options?: WebhookAnalyticsOptions
|
|
69
|
+
): Promise<WebhookTimeSeriesData> {
|
|
70
|
+
const queryString = buildAnalyticsQuery(options);
|
|
71
|
+
const url = webhookApiPathWithQuery('analytics/org/timeseries', queryString);
|
|
72
|
+
const resp = await client.get(
|
|
73
|
+
url,
|
|
74
|
+
WebhookTimeSeriesResponseSchema,
|
|
75
|
+
undefined,
|
|
76
|
+
buildWebhookHeaders(options?.orgId)
|
|
77
|
+
);
|
|
78
|
+
if (resp.success) return resp.data.timeseries;
|
|
79
|
+
throw new WebhookError({ message: resp.message || 'Failed to get webhook org time series' });
|
|
80
|
+
}
|
|
@@ -68,6 +68,20 @@ export {
|
|
|
68
68
|
WebhookDestinationTypeSchema,
|
|
69
69
|
type WebhookReceipt,
|
|
70
70
|
WebhookReceiptSchema,
|
|
71
|
+
type WebhookAnalyticsGranularity,
|
|
72
|
+
WebhookAnalyticsGranularitySchema,
|
|
73
|
+
type WebhookAnalyticsOptions,
|
|
74
|
+
WebhookAnalyticsOptionsSchema,
|
|
75
|
+
type WebhookAnalyticsSummary,
|
|
76
|
+
WebhookAnalyticsSummarySchema,
|
|
77
|
+
type WebhookOrgAnalytics,
|
|
78
|
+
WebhookOrgAnalyticsSchema,
|
|
79
|
+
type WebhookTimePeriod,
|
|
80
|
+
WebhookTimePeriodSchema,
|
|
81
|
+
type WebhookTimeSeriesData,
|
|
82
|
+
WebhookTimeSeriesDataSchema,
|
|
83
|
+
type WebhookTimeSeriesPoint,
|
|
84
|
+
WebhookTimeSeriesPointSchema,
|
|
71
85
|
WebhookSchema,
|
|
72
86
|
} from './types.ts';
|
|
73
87
|
|
|
@@ -133,3 +147,14 @@ export {
|
|
|
133
147
|
WebhookDeliveriesListResponseSchema,
|
|
134
148
|
WebhookDeliveryResponseSchema,
|
|
135
149
|
} from './deliveries.ts';
|
|
150
|
+
|
|
151
|
+
// ============================================================================
|
|
152
|
+
// Analytics Operations
|
|
153
|
+
// ============================================================================
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
getWebhookOrgAnalytics,
|
|
157
|
+
getWebhookOrgTimeSeries,
|
|
158
|
+
WebhookOrgAnalyticsResponseSchema,
|
|
159
|
+
WebhookTimeSeriesResponseSchema,
|
|
160
|
+
} from './analytics.ts';
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
Webhook,
|
|
9
9
|
WebhookDelivery,
|
|
10
10
|
WebhookDestination,
|
|
11
|
+
WebhookOrgAnalytics,
|
|
11
12
|
WebhookReceipt,
|
|
12
13
|
} from './types.ts';
|
|
13
14
|
|
|
@@ -773,4 +774,127 @@ export class WebhookService {
|
|
|
773
774
|
|
|
774
775
|
throw await toServiceException('POST', url, res.response);
|
|
775
776
|
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Get org-level webhook analytics summary.
|
|
780
|
+
*
|
|
781
|
+
* Returns total received, delivered, and failed counts for all webhooks
|
|
782
|
+
* in the org within the specified time period.
|
|
783
|
+
*
|
|
784
|
+
* @param options - Analytics options (start, end, granularity)
|
|
785
|
+
* @returns Org-level webhook analytics with period and summary
|
|
786
|
+
* @throws {@link ServiceException} if the API request fails
|
|
787
|
+
*/
|
|
788
|
+
async getOrgAnalytics(options?: {
|
|
789
|
+
start?: string;
|
|
790
|
+
end?: string;
|
|
791
|
+
granularity?: string;
|
|
792
|
+
}): Promise<WebhookOrgAnalytics> {
|
|
793
|
+
const params = new URLSearchParams();
|
|
794
|
+
if (options?.start) params.set('start', options.start);
|
|
795
|
+
if (options?.end) params.set('end', options.end);
|
|
796
|
+
if (options?.granularity) params.set('granularity', options.granularity);
|
|
797
|
+
const query = params.toString();
|
|
798
|
+
const path = query ? `/webhook/analytics/org?${query}` : '/webhook/analytics/org';
|
|
799
|
+
const url = buildUrl(this.#baseUrl, path);
|
|
800
|
+
const signal = createTimeoutSignal();
|
|
801
|
+
const res = await this.#adapter.invoke<
|
|
802
|
+
WebhookResponse<{
|
|
803
|
+
analytics: {
|
|
804
|
+
period: { start: string; end: string };
|
|
805
|
+
summary: { total_received: number; total_delivered: number; total_failed: number };
|
|
806
|
+
};
|
|
807
|
+
}>
|
|
808
|
+
>(url, {
|
|
809
|
+
method: 'GET',
|
|
810
|
+
signal,
|
|
811
|
+
telemetry: { name: 'agentuity.webhook.analytics.org' },
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
if (res.ok) {
|
|
815
|
+
if (res.data.success) {
|
|
816
|
+
const unwrapped = this.#unwrap<{
|
|
817
|
+
analytics: {
|
|
818
|
+
period: { start: string; end: string };
|
|
819
|
+
summary: {
|
|
820
|
+
total_received: number;
|
|
821
|
+
total_delivered: number;
|
|
822
|
+
total_failed: number;
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
}>(res.data.data);
|
|
826
|
+
return unwrapped.analytics;
|
|
827
|
+
}
|
|
828
|
+
throw new WebhookResponseError({ status: res.response.status, message: res.data.message });
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
throw await toServiceException('GET', url, res.response);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Get org-level webhook time series data.
|
|
836
|
+
*
|
|
837
|
+
* Returns time-bucketed received, delivered, and failed counts for all webhooks
|
|
838
|
+
* in the org within the specified time period.
|
|
839
|
+
*
|
|
840
|
+
* @param options - Analytics options (start, end, granularity)
|
|
841
|
+
* @returns Webhook time series data with period and series array
|
|
842
|
+
* @throws {@link ServiceException} if the API request fails
|
|
843
|
+
*/
|
|
844
|
+
async getOrgTimeSeries(options?: {
|
|
845
|
+
start?: string;
|
|
846
|
+
end?: string;
|
|
847
|
+
granularity?: string;
|
|
848
|
+
}): Promise<{
|
|
849
|
+
period: { start: string; end: string; granularity?: string };
|
|
850
|
+
series: Array<{ timestamp: string; received: number; delivered: number; failed: number }>;
|
|
851
|
+
}> {
|
|
852
|
+
const params = new URLSearchParams();
|
|
853
|
+
if (options?.start) params.set('start', options.start);
|
|
854
|
+
if (options?.end) params.set('end', options.end);
|
|
855
|
+
if (options?.granularity) params.set('granularity', options.granularity);
|
|
856
|
+
const query = params.toString();
|
|
857
|
+
const path = query
|
|
858
|
+
? `/webhook/analytics/org/timeseries?${query}`
|
|
859
|
+
: '/webhook/analytics/org/timeseries';
|
|
860
|
+
const url = buildUrl(this.#baseUrl, path);
|
|
861
|
+
const signal = createTimeoutSignal();
|
|
862
|
+
const res = await this.#adapter.invoke<
|
|
863
|
+
WebhookResponse<{
|
|
864
|
+
timeseries: {
|
|
865
|
+
period: { start: string; end: string; granularity?: string };
|
|
866
|
+
series: Array<{
|
|
867
|
+
timestamp: string;
|
|
868
|
+
received: number;
|
|
869
|
+
delivered: number;
|
|
870
|
+
failed: number;
|
|
871
|
+
}>;
|
|
872
|
+
};
|
|
873
|
+
}>
|
|
874
|
+
>(url, {
|
|
875
|
+
method: 'GET',
|
|
876
|
+
signal,
|
|
877
|
+
telemetry: { name: 'agentuity.webhook.analytics.org.timeseries' },
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
if (res.ok) {
|
|
881
|
+
if (res.data.success) {
|
|
882
|
+
const unwrapped = this.#unwrap<{
|
|
883
|
+
timeseries: {
|
|
884
|
+
period: { start: string; end: string; granularity?: string };
|
|
885
|
+
series: Array<{
|
|
886
|
+
timestamp: string;
|
|
887
|
+
received: number;
|
|
888
|
+
delivered: number;
|
|
889
|
+
failed: number;
|
|
890
|
+
}>;
|
|
891
|
+
};
|
|
892
|
+
}>(res.data.data);
|
|
893
|
+
return unwrapped.timeseries;
|
|
894
|
+
}
|
|
895
|
+
throw new WebhookResponseError({ status: res.response.status, message: res.data.message });
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
throw await toServiceException('GET', url, res.response);
|
|
899
|
+
}
|
|
776
900
|
}
|
|
@@ -40,6 +40,17 @@ export const WebhookSchema = z
|
|
|
40
40
|
.describe(
|
|
41
41
|
'Fully-qualified ingest URL for sending events to this webhook. Only present on create'
|
|
42
42
|
),
|
|
43
|
+
internal: z
|
|
44
|
+
.boolean()
|
|
45
|
+
.describe(
|
|
46
|
+
'Whether this is a system-managed webhook (e.g., S3 bucket notifications). Internal webhooks cannot be modified or deleted by users'
|
|
47
|
+
),
|
|
48
|
+
metadata: z
|
|
49
|
+
.record(z.string(), z.unknown())
|
|
50
|
+
.nullable()
|
|
51
|
+
.describe(
|
|
52
|
+
'System metadata for internal webhooks (e.g., bucket_name, type). Null for user-created webhooks'
|
|
53
|
+
),
|
|
43
54
|
})
|
|
44
55
|
.describe('Webhook endpoint configuration');
|
|
45
56
|
|
|
@@ -56,6 +67,17 @@ export const WebhookDestinationSchema = z
|
|
|
56
67
|
config: z
|
|
57
68
|
.record(z.string(), z.unknown())
|
|
58
69
|
.describe('Configuration object for the destination (e.g., URL, headers)'),
|
|
70
|
+
internal: z
|
|
71
|
+
.boolean()
|
|
72
|
+
.describe(
|
|
73
|
+
'Whether this is a system-managed destination. Internal destinations cannot be modified or deleted by users'
|
|
74
|
+
),
|
|
75
|
+
metadata: z
|
|
76
|
+
.record(z.string(), z.unknown())
|
|
77
|
+
.nullable()
|
|
78
|
+
.describe(
|
|
79
|
+
'System metadata for internal destinations (e.g., bucket_name, type). Null for user-created destinations'
|
|
80
|
+
),
|
|
59
81
|
})
|
|
60
82
|
.describe('Webhook destination representing a delivery target for webhook events');
|
|
61
83
|
|
|
@@ -98,6 +120,76 @@ export const WebhookDeliverySchema = z
|
|
|
98
120
|
|
|
99
121
|
export type WebhookDelivery = z.infer<typeof WebhookDeliverySchema>;
|
|
100
122
|
|
|
123
|
+
// ============================================================================
|
|
124
|
+
// Analytics Types
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
export const WebhookAnalyticsGranularitySchema = z
|
|
128
|
+
.enum(['minute', 'hour', 'day'])
|
|
129
|
+
.describe('Time bucket granularity for analytics queries');
|
|
130
|
+
|
|
131
|
+
export type WebhookAnalyticsGranularity = z.infer<typeof WebhookAnalyticsGranularitySchema>;
|
|
132
|
+
|
|
133
|
+
export const WebhookAnalyticsOptionsSchema = z
|
|
134
|
+
.object({
|
|
135
|
+
start: z.string().optional().describe('ISO 8601 start time for the analytics window'),
|
|
136
|
+
end: z.string().optional().describe('ISO 8601 end time for the analytics window'),
|
|
137
|
+
granularity: WebhookAnalyticsGranularitySchema.optional().describe('Time bucket granularity'),
|
|
138
|
+
orgId: z.string().optional().describe('Organization ID for CLI-authenticated requests'),
|
|
139
|
+
})
|
|
140
|
+
.describe('Options for webhook analytics queries');
|
|
141
|
+
|
|
142
|
+
export type WebhookAnalyticsOptions = z.infer<typeof WebhookAnalyticsOptionsSchema>;
|
|
143
|
+
|
|
144
|
+
export const WebhookTimePeriodSchema = z
|
|
145
|
+
.object({
|
|
146
|
+
start: z.string().describe('ISO 8601 start time'),
|
|
147
|
+
end: z.string().describe('ISO 8601 end time'),
|
|
148
|
+
granularity: WebhookAnalyticsGranularitySchema.optional(),
|
|
149
|
+
})
|
|
150
|
+
.describe('Time period for analytics data');
|
|
151
|
+
|
|
152
|
+
export type WebhookTimePeriod = z.infer<typeof WebhookTimePeriodSchema>;
|
|
153
|
+
|
|
154
|
+
export const WebhookAnalyticsSummarySchema = z
|
|
155
|
+
.object({
|
|
156
|
+
total_received: z.number().describe('Total webhook receipts in the period'),
|
|
157
|
+
total_delivered: z.number().describe('Total successful deliveries in the period'),
|
|
158
|
+
total_failed: z.number().describe('Total failed deliveries in the period'),
|
|
159
|
+
})
|
|
160
|
+
.describe('Summary analytics for webhook activity');
|
|
161
|
+
|
|
162
|
+
export type WebhookAnalyticsSummary = z.infer<typeof WebhookAnalyticsSummarySchema>;
|
|
163
|
+
|
|
164
|
+
export const WebhookOrgAnalyticsSchema = z
|
|
165
|
+
.object({
|
|
166
|
+
period: WebhookTimePeriodSchema,
|
|
167
|
+
summary: WebhookAnalyticsSummarySchema,
|
|
168
|
+
})
|
|
169
|
+
.describe('Org-level webhook analytics response');
|
|
170
|
+
|
|
171
|
+
export type WebhookOrgAnalytics = z.infer<typeof WebhookOrgAnalyticsSchema>;
|
|
172
|
+
|
|
173
|
+
export const WebhookTimeSeriesPointSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
timestamp: z.string().describe('ISO 8601 timestamp for this data point'),
|
|
176
|
+
received: z.number().describe('Number of receipts in this bucket'),
|
|
177
|
+
delivered: z.number().describe('Number of successful deliveries in this bucket'),
|
|
178
|
+
failed: z.number().describe('Number of failed deliveries in this bucket'),
|
|
179
|
+
})
|
|
180
|
+
.describe('Single data point in webhook time series');
|
|
181
|
+
|
|
182
|
+
export type WebhookTimeSeriesPoint = z.infer<typeof WebhookTimeSeriesPointSchema>;
|
|
183
|
+
|
|
184
|
+
export const WebhookTimeSeriesDataSchema = z
|
|
185
|
+
.object({
|
|
186
|
+
period: WebhookTimePeriodSchema,
|
|
187
|
+
series: z.array(WebhookTimeSeriesPointSchema),
|
|
188
|
+
})
|
|
189
|
+
.describe('Webhook time series analytics data');
|
|
190
|
+
|
|
191
|
+
export type WebhookTimeSeriesData = z.infer<typeof WebhookTimeSeriesDataSchema>;
|
|
192
|
+
|
|
101
193
|
// ============================================================================
|
|
102
194
|
// API Options
|
|
103
195
|
// ============================================================================
|