@agentuity/server 1.0.22 → 1.0.24

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 (86) hide show
  1. package/dist/api/index.d.ts +2 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +2 -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/disk-checkpoint.d.ts +103 -0
  10. package/dist/api/sandbox/disk-checkpoint.d.ts.map +1 -0
  11. package/dist/api/sandbox/disk-checkpoint.js +104 -0
  12. package/dist/api/sandbox/disk-checkpoint.js.map +1 -0
  13. package/dist/api/sandbox/execute.d.ts +2 -2
  14. package/dist/api/sandbox/execution.d.ts +4 -4
  15. package/dist/api/sandbox/index.d.ts +2 -0
  16. package/dist/api/sandbox/index.d.ts.map +1 -1
  17. package/dist/api/sandbox/index.js +1 -0
  18. package/dist/api/sandbox/index.js.map +1 -1
  19. package/dist/api/sandbox/snapshot-build.d.ts +2 -0
  20. package/dist/api/sandbox/snapshot-build.d.ts.map +1 -1
  21. package/dist/api/sandbox/snapshot-build.js +4 -0
  22. package/dist/api/sandbox/snapshot-build.js.map +1 -1
  23. package/dist/api/services/index.d.ts +2 -0
  24. package/dist/api/services/index.d.ts.map +1 -0
  25. package/dist/api/services/index.js +2 -0
  26. package/dist/api/services/index.js.map +1 -0
  27. package/dist/api/services/stats.d.ts +257 -0
  28. package/dist/api/services/stats.d.ts.map +1 -0
  29. package/dist/api/services/stats.js +142 -0
  30. package/dist/api/services/stats.js.map +1 -0
  31. package/dist/api/webhook/deliveries.d.ts +94 -0
  32. package/dist/api/webhook/deliveries.d.ts.map +1 -0
  33. package/dist/api/webhook/deliveries.js +79 -0
  34. package/dist/api/webhook/deliveries.js.map +1 -0
  35. package/dist/api/webhook/destinations.d.ts +136 -0
  36. package/dist/api/webhook/destinations.d.ts.map +1 -0
  37. package/dist/api/webhook/destinations.js +137 -0
  38. package/dist/api/webhook/destinations.js.map +1 -0
  39. package/dist/api/webhook/index.d.ts +41 -0
  40. package/dist/api/webhook/index.d.ts.map +1 -0
  41. package/dist/api/webhook/index.js +59 -0
  42. package/dist/api/webhook/index.js.map +1 -0
  43. package/dist/api/webhook/receipts.d.ts +77 -0
  44. package/dist/api/webhook/receipts.d.ts.map +1 -0
  45. package/dist/api/webhook/receipts.js +78 -0
  46. package/dist/api/webhook/receipts.js.map +1 -0
  47. package/dist/api/webhook/types.d.ts +249 -0
  48. package/dist/api/webhook/types.d.ts.map +1 -0
  49. package/dist/api/webhook/types.js +221 -0
  50. package/dist/api/webhook/types.js.map +1 -0
  51. package/dist/api/webhook/util.d.ts +202 -0
  52. package/dist/api/webhook/util.d.ts.map +1 -0
  53. package/dist/api/webhook/util.js +201 -0
  54. package/dist/api/webhook/util.js.map +1 -0
  55. package/dist/api/webhook/webhooks.d.ts +146 -0
  56. package/dist/api/webhook/webhooks.d.ts.map +1 -0
  57. package/dist/api/webhook/webhooks.js +165 -0
  58. package/dist/api/webhook/webhooks.js.map +1 -0
  59. package/dist/config.d.ts +1 -0
  60. package/dist/config.d.ts.map +1 -1
  61. package/dist/config.js +1 -0
  62. package/dist/config.js.map +1 -1
  63. package/dist/runtime-bootstrap.d.ts.map +1 -1
  64. package/dist/runtime-bootstrap.js +3 -0
  65. package/dist/runtime-bootstrap.js.map +1 -1
  66. package/dist/server.d.ts.map +1 -1
  67. package/dist/server.js +4 -0
  68. package/dist/server.js.map +1 -1
  69. package/package.json +4 -4
  70. package/src/api/index.ts +2 -0
  71. package/src/api/project/deploy.ts +16 -16
  72. package/src/api/sandbox/disk-checkpoint.ts +179 -0
  73. package/src/api/sandbox/index.ts +18 -0
  74. package/src/api/sandbox/snapshot-build.ts +6 -0
  75. package/src/api/services/index.ts +1 -0
  76. package/src/api/services/stats.ts +211 -0
  77. package/src/api/webhook/deliveries.ts +129 -0
  78. package/src/api/webhook/destinations.ts +224 -0
  79. package/src/api/webhook/index.ts +133 -0
  80. package/src/api/webhook/receipts.ts +124 -0
  81. package/src/api/webhook/types.ts +309 -0
  82. package/src/api/webhook/util.ts +237 -0
  83. package/src/api/webhook/webhooks.ts +260 -0
  84. package/src/config.ts +2 -0
  85. package/src/runtime-bootstrap.ts +3 -0
  86. package/src/server.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/server",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -25,12 +25,12 @@
25
25
  "prepublishOnly": "bun run clean && bun run build"
26
26
  },
27
27
  "dependencies": {
28
- "@agentuity/core": "1.0.22",
29
- "@agentuity/schema": "1.0.22",
28
+ "@agentuity/core": "1.0.24",
29
+ "@agentuity/schema": "1.0.24",
30
30
  "zod": "^4.3.5"
31
31
  },
32
32
  "devDependencies": {
33
- "@agentuity/test-utils": "1.0.22",
33
+ "@agentuity/test-utils": "1.0.24",
34
34
  "@types/bun": "latest",
35
35
  "@types/node": "^22.0.0",
36
36
  "bun-types": "latest",
package/src/api/index.ts CHANGED
@@ -7,7 +7,9 @@ export * from './org/index.ts';
7
7
  export * from './project/index.ts';
8
8
  export * from './queue/index.ts';
9
9
  export * from './region/index.ts';
10
+ export * from './webhook/index.ts';
10
11
  export * from './sandbox/index.ts';
12
+ export * from './services/index.ts';
11
13
  export * from './session/index.ts';
12
14
  export * from './stream/index.ts';
13
15
  export * from './thread/index.ts';
@@ -16,6 +16,18 @@ export const Mode = z.object({
16
16
  idle: z.string().optional().describe('duration in seconds if on-demand'),
17
17
  });
18
18
 
19
+ export const ProjectBuildConfig = z.object({
20
+ timeout: z.string().optional().describe('Build execution timeout (e.g. "30m")'),
21
+ resources: z
22
+ .object({
23
+ memory: z.string().optional().describe('Build sandbox memory (e.g. "4Gi")'),
24
+ cpu: z.string().optional().describe('Build sandbox CPU (e.g. "2")'),
25
+ disk: z.string().optional().describe('Build sandbox disk (e.g. "4Gi")'),
26
+ })
27
+ .optional()
28
+ .describe('Build sandbox resource limits'),
29
+ });
30
+
19
31
  export const DeploymentConfig = z.object({
20
32
  resources: Resources.optional().describe('the resource requirements for your deployed project'),
21
33
  mode: Mode.optional().describe('the provisioning mode for the project'),
@@ -70,14 +82,8 @@ export const BuildMetadataSchema = z.object({
70
82
  method: z.enum(['get', 'post', 'put', 'delete', 'patch']).describe('the HTTP method'),
71
83
  version: z.string().describe('the SHA256 content of the file'),
72
84
  type: z.enum(['api', 'sms', 'email', 'cron', 'websocket', 'sse', 'stream']),
73
- agentIds: z
74
- .array(z.string())
75
- .optional()
76
- .describe('the agent ids associated with this route'),
77
- config: z
78
- .record(z.string(), z.unknown())
79
- .optional()
80
- .describe('type specific configuration'),
85
+ agentIds: z.array(z.string()).optional().describe('the agent ids associated with this route'),
86
+ config: z.record(z.string(), z.unknown()).optional().describe('type specific configuration'),
81
87
  schema: z
82
88
  .object({
83
89
  input: z.string().optional().describe('JSON schema for input (stringified JSON)'),
@@ -127,11 +133,7 @@ export const BuildMetadataSchema = z.object({
127
133
  .default('cli')
128
134
  .optional()
129
135
  .describe('the trigger that caused the build'),
130
- url: z
131
- .string()
132
- .url()
133
- .optional()
134
- .describe('the url to the commit for the CI provider'),
136
+ url: z.string().url().optional().describe('the url to the commit for the CI provider'),
135
137
  buildUrl: z
136
138
  .string()
137
139
  .url()
@@ -150,9 +152,7 @@ export const BuildMetadataSchema = z.object({
150
152
  url: z.string().optional(),
151
153
  })
152
154
  .optional()
153
- .describe(
154
- 'This is only present when the deployment was triggered via a pull request.'
155
- ),
155
+ .describe('This is only present when the deployment was triggered via a pull request.'),
156
156
  })
157
157
  .optional()
158
158
  .describe('git commit information'),
@@ -0,0 +1,179 @@
1
+ import { z } from 'zod';
2
+ import type { z as zType } from 'zod';
3
+ import { type APIClient, APIResponseSchema, APIResponseSchemaNoData } from '../api';
4
+ import { API_VERSION, throwSandboxError } from './util';
5
+
6
+ // --- Schemas ---
7
+
8
+ export const DiskCheckpointInfoSchema = z.object({
9
+ id: z.string().describe('Globally unique checkpoint ID (ckpt_xxx)'),
10
+ name: z.string().describe('User-provided checkpoint name'),
11
+ createdAt: z.string().describe('ISO timestamp of creation'),
12
+ parent: z.string().describe('Parent checkpoint name (empty for base)'),
13
+ });
14
+
15
+ export type DiskCheckpointInfo = z.infer<typeof DiskCheckpointInfoSchema>;
16
+
17
+ const CreateDiskCheckpointDataSchema = DiskCheckpointInfoSchema;
18
+ export const CreateDiskCheckpointResponseSchema = APIResponseSchema(CreateDiskCheckpointDataSchema);
19
+
20
+ const ListDiskCheckpointsDataSchema = z.object({
21
+ checkpoints: z.array(DiskCheckpointInfoSchema),
22
+ });
23
+ export const ListDiskCheckpointsResponseSchema = APIResponseSchema(ListDiskCheckpointsDataSchema);
24
+
25
+ export const RestoreDiskCheckpointResponseSchema = APIResponseSchemaNoData();
26
+ export const DeleteDiskCheckpointResponseSchema = APIResponseSchemaNoData();
27
+
28
+ // --- Params ---
29
+
30
+ export interface DiskCheckpointCreateParams {
31
+ sandboxId: string;
32
+ name: string;
33
+ orgId?: string;
34
+ }
35
+
36
+ export interface DiskCheckpointListParams {
37
+ sandboxId: string;
38
+ orgId?: string;
39
+ }
40
+
41
+ export interface DiskCheckpointRestoreParams {
42
+ sandboxId: string;
43
+ checkpointId: string;
44
+ orgId?: string;
45
+ }
46
+
47
+ export interface DiskCheckpointDeleteParams {
48
+ sandboxId: string;
49
+ checkpointId: string;
50
+ orgId?: string;
51
+ }
52
+
53
+ // --- API Functions ---
54
+
55
+ /**
56
+ * Creates a new disk checkpoint for a sandbox.
57
+ *
58
+ * @param client - The API client to use for the request
59
+ * @param params - Parameters including the sandbox ID and checkpoint name
60
+ * @throws {SandboxResponseError} If the sandbox is not found or checkpoint creation fails
61
+ */
62
+ export async function diskCheckpointCreate(
63
+ client: APIClient,
64
+ params: DiskCheckpointCreateParams
65
+ ): Promise<DiskCheckpointInfo> {
66
+ const { sandboxId, name, orgId } = params;
67
+ const queryParams = new URLSearchParams();
68
+ if (orgId) {
69
+ queryParams.set('orgId', orgId);
70
+ }
71
+ const queryString = queryParams.toString();
72
+ const url = `/sandbox/${API_VERSION}/${encodeURIComponent(sandboxId)}/checkpoint${queryString ? `?${queryString}` : ''}`;
73
+
74
+ const resp = await client.post<zType.infer<typeof CreateDiskCheckpointResponseSchema>>(
75
+ url,
76
+ { name },
77
+ CreateDiskCheckpointResponseSchema
78
+ );
79
+
80
+ if (resp.success) {
81
+ return resp.data;
82
+ }
83
+
84
+ throwSandboxError(resp, { sandboxId });
85
+ }
86
+
87
+ /**
88
+ * Lists all disk checkpoints for a sandbox.
89
+ *
90
+ * @param client - The API client to use for the request
91
+ * @param params - Parameters including the sandbox ID
92
+ * @throws {SandboxResponseError} If the sandbox is not found or listing fails
93
+ */
94
+ export async function diskCheckpointList(
95
+ client: APIClient,
96
+ params: DiskCheckpointListParams
97
+ ): Promise<DiskCheckpointInfo[]> {
98
+ const { sandboxId, orgId } = params;
99
+ const queryParams = new URLSearchParams();
100
+ if (orgId) {
101
+ queryParams.set('orgId', orgId);
102
+ }
103
+ const queryString = queryParams.toString();
104
+ const url = `/sandbox/${API_VERSION}/checkpoints/${encodeURIComponent(sandboxId)}${queryString ? `?${queryString}` : ''}`;
105
+
106
+ const resp = await client.get<zType.infer<typeof ListDiskCheckpointsResponseSchema>>(
107
+ url,
108
+ ListDiskCheckpointsResponseSchema
109
+ );
110
+
111
+ if (resp.success) {
112
+ return resp.data.checkpoints;
113
+ }
114
+
115
+ throwSandboxError(resp, { sandboxId });
116
+ }
117
+
118
+ /**
119
+ * Restores a sandbox to a specific disk checkpoint.
120
+ *
121
+ * @param client - The API client to use for the request
122
+ * @param params - Parameters including the sandbox ID and checkpoint ID
123
+ * @throws {SandboxResponseError} If the sandbox or checkpoint is not found, or restore fails
124
+ */
125
+ export async function diskCheckpointRestore(
126
+ client: APIClient,
127
+ params: DiskCheckpointRestoreParams
128
+ ): Promise<void> {
129
+ const { sandboxId, checkpointId, orgId } = params;
130
+ const queryParams = new URLSearchParams();
131
+ if (orgId) {
132
+ queryParams.set('orgId', orgId);
133
+ }
134
+ const queryString = queryParams.toString();
135
+ const url = `/sandbox/${API_VERSION}/${encodeURIComponent(sandboxId)}/checkpoint/${encodeURIComponent(checkpointId)}/restore${queryString ? `?${queryString}` : ''}`;
136
+
137
+ const resp = await client.post<zType.infer<typeof RestoreDiskCheckpointResponseSchema>>(
138
+ url,
139
+ undefined,
140
+ RestoreDiskCheckpointResponseSchema
141
+ );
142
+
143
+ if (resp.success) {
144
+ return;
145
+ }
146
+
147
+ throwSandboxError(resp, { sandboxId });
148
+ }
149
+
150
+ /**
151
+ * Deletes a disk checkpoint from a sandbox.
152
+ *
153
+ * @param client - The API client to use for the request
154
+ * @param params - Parameters including the sandbox ID and checkpoint ID
155
+ * @throws {SandboxResponseError} If the sandbox or checkpoint is not found, or deletion fails
156
+ */
157
+ export async function diskCheckpointDelete(
158
+ client: APIClient,
159
+ params: DiskCheckpointDeleteParams
160
+ ): Promise<void> {
161
+ const { sandboxId, checkpointId, orgId } = params;
162
+ const queryParams = new URLSearchParams();
163
+ if (orgId) {
164
+ queryParams.set('orgId', orgId);
165
+ }
166
+ const queryString = queryParams.toString();
167
+ const url = `/sandbox/${API_VERSION}/${encodeURIComponent(sandboxId)}/checkpoint/${encodeURIComponent(checkpointId)}${queryString ? `?${queryString}` : ''}`;
168
+
169
+ const resp = await client.delete<zType.infer<typeof DeleteDiskCheckpointResponseSchema>>(
170
+ url,
171
+ DeleteDiskCheckpointResponseSchema
172
+ );
173
+
174
+ if (resp.success) {
175
+ return;
176
+ }
177
+
178
+ throwSandboxError(resp, { sandboxId });
179
+ }
@@ -16,6 +16,24 @@ export {
16
16
  } from './create.ts';
17
17
  export type { SandboxDestroyParams } from './destroy.ts';
18
18
  export { DestroyResponseSchema, sandboxDestroy } from './destroy.ts';
19
+ export type {
20
+ DiskCheckpointInfo,
21
+ DiskCheckpointCreateParams,
22
+ DiskCheckpointListParams,
23
+ DiskCheckpointRestoreParams,
24
+ DiskCheckpointDeleteParams,
25
+ } from './disk-checkpoint.ts';
26
+ export {
27
+ DiskCheckpointInfoSchema,
28
+ CreateDiskCheckpointResponseSchema,
29
+ ListDiskCheckpointsResponseSchema,
30
+ RestoreDiskCheckpointResponseSchema,
31
+ DeleteDiskCheckpointResponseSchema,
32
+ diskCheckpointCreate,
33
+ diskCheckpointList,
34
+ diskCheckpointRestore,
35
+ diskCheckpointDelete,
36
+ } from './disk-checkpoint.ts';
19
37
  export type { SandboxPauseParams } from './pause.ts';
20
38
  export { PauseResponseSchema, sandboxPause } from './pause.ts';
21
39
  export type { SandboxResumeParams } from './resume.ts';
@@ -28,6 +28,12 @@ export const SnapshotBuildFileBaseSchema = z
28
28
  .optional()
29
29
  .describe('Snapshot name (alphanumeric, underscores, dashes only)'),
30
30
  description: z.string().optional().describe('Human-readable description of the snapshot'),
31
+ dir: z
32
+ .string()
33
+ .optional()
34
+ .describe(
35
+ 'Subdirectory to use as the build context for file resolution (relative to the CLI directory argument)'
36
+ ),
31
37
  dependencies: z
32
38
  .array(z.string())
33
39
  .optional()
@@ -0,0 +1 @@
1
+ export * from './stats.ts';
@@ -0,0 +1,211 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema } from '../api.ts';
3
+ import { StructuredError } from '@agentuity/core';
4
+
5
+ // --- Error ---
6
+
7
+ export const ServiceStatsError = StructuredError('ServiceStatsError')<{
8
+ message: string;
9
+ }>();
10
+
11
+ // --- Per-Service Stat Schemas ---
12
+
13
+ export const KeyValueStatSchema = z.object({
14
+ namespaceCount: z.number(),
15
+ keyCount: z.number(),
16
+ totalSizeBytes: z.number(),
17
+ });
18
+
19
+ export const VectorStatSchema = z.object({
20
+ namespaceCount: z.number(),
21
+ documentCount: z.number(),
22
+ totalSizeBytes: z.number(),
23
+ });
24
+
25
+ export const QueueStatSchema = z.object({
26
+ queueCount: z.number(),
27
+ totalMessages: z.number(),
28
+ totalDlq: z.number(),
29
+ });
30
+
31
+ export const StreamStatSchema = z.object({
32
+ streamCount: z.number(),
33
+ totalSizeBytes: z.number(),
34
+ });
35
+
36
+ export const SandboxStatSchema = z.object({
37
+ totalActive: z.number(),
38
+ running: z.number(),
39
+ idle: z.number(),
40
+ creating: z.number(),
41
+ totalExecutions: z.number(),
42
+ totalCpuTimeMs: z.number(),
43
+ totalMemoryByteSec: z.number(),
44
+ totalNetworkEgressBytes: z.number(),
45
+ });
46
+
47
+ export const EmailStatSchema = z.object({
48
+ addressCount: z.number(),
49
+ inboundCount: z.number(),
50
+ outboundCount: z.number(),
51
+ outboundSuccess: z.number(),
52
+ outboundFailed: z.number(),
53
+ });
54
+
55
+ export const TaskStatSchema = z.object({
56
+ total: z.number(),
57
+ open: z.number(),
58
+ inProgress: z.number(),
59
+ closed: z.number(),
60
+ });
61
+
62
+ export const ScheduleStatSchema = z.object({
63
+ scheduleCount: z.number(),
64
+ totalDeliveries: z.number(),
65
+ successDeliveries: z.number(),
66
+ failedDeliveries: z.number(),
67
+ });
68
+
69
+ export const DatabaseStatSchema = z.object({
70
+ databaseCount: z.number(),
71
+ totalTableCount: z.number(),
72
+ totalRecordCount: z.number(),
73
+ totalSizeBytes: z.number(),
74
+ });
75
+
76
+ // --- Aggregate Schema ---
77
+
78
+ export const ServiceStatsDataSchema = z.object({
79
+ services: z.object({
80
+ database: DatabaseStatSchema.optional(),
81
+ keyvalue: KeyValueStatSchema.optional(),
82
+ vector: VectorStatSchema.optional(),
83
+ queue: QueueStatSchema.optional(),
84
+ stream: StreamStatSchema.optional(),
85
+ sandbox: SandboxStatSchema.optional(),
86
+ email: EmailStatSchema.optional(),
87
+ task: TaskStatSchema.optional(),
88
+ schedule: ScheduleStatSchema.optional(),
89
+ }),
90
+ });
91
+
92
+ export const ServiceStatsResponseSchema = APIResponseSchema(ServiceStatsDataSchema);
93
+
94
+ // --- Types ---
95
+
96
+ export type KeyValueStat = z.infer<typeof KeyValueStatSchema>;
97
+ export type VectorStat = z.infer<typeof VectorStatSchema>;
98
+ export type QueueStat = z.infer<typeof QueueStatSchema>;
99
+ export type StreamStat = z.infer<typeof StreamStatSchema>;
100
+ export type SandboxStat = z.infer<typeof SandboxStatSchema>;
101
+ export type EmailStat = z.infer<typeof EmailStatSchema>;
102
+ export type TaskStat = z.infer<typeof TaskStatSchema>;
103
+ export type ScheduleStat = z.infer<typeof ScheduleStatSchema>;
104
+ export type DatabaseStat = z.infer<typeof DatabaseStatSchema>;
105
+ export type ServiceStatsData = z.infer<typeof ServiceStatsDataSchema>;
106
+ export type ServiceStatsResponse = z.infer<typeof ServiceStatsResponseSchema>;
107
+
108
+ // --- Valid Services ---
109
+
110
+ /**
111
+ * Valid service names that can be used to filter stats.
112
+ */
113
+ export const VALID_SERVICES = [
114
+ 'database',
115
+ 'keyvalue',
116
+ 'email',
117
+ 'vector',
118
+ 'schedule',
119
+ 'task',
120
+ 'stream',
121
+ 'sandbox',
122
+ 'queue',
123
+ ] as const;
124
+
125
+ export type ServiceName = (typeof VALID_SERVICES)[number];
126
+
127
+ // --- Options ---
128
+
129
+ export interface ServiceStatsOptions {
130
+ /**
131
+ * Filter to a specific service. If omitted, returns stats for all services.
132
+ */
133
+ service?: ServiceName;
134
+ /**
135
+ * Start time filter (ISO 8601 timestamp).
136
+ */
137
+ start?: string;
138
+ /**
139
+ * End time filter (ISO 8601 timestamp).
140
+ */
141
+ end?: string;
142
+ /**
143
+ * For CLI auth: sets x-agentuity-orgid header.
144
+ * Required when using CLI token auth (bearer tokens without embedded org).
145
+ */
146
+ orgIdHeader?: string;
147
+ }
148
+
149
+ // --- API Function ---
150
+
151
+ /**
152
+ * Get aggregated stats for services used by an organization.
153
+ *
154
+ * Returns per-service stats with service-specific fields (counts, sizes, etc.).
155
+ * Services that error on the backend are omitted from the response.
156
+ * Services with no provisioned tenant DB return zero values.
157
+ *
158
+ * @param client - The API client instance
159
+ * @param orgId - The organization ID
160
+ * @param options - Optional filtering (service, time range)
161
+ * @returns Service stats data with per-service breakdown
162
+ * @throws {ServiceStatsError} If the API request fails
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * // Get stats for all services
167
+ * const stats = await getServiceStats(client, 'org_123');
168
+ * console.log(`KV keys: ${stats.services.keyvalue?.keyCount}`);
169
+ * ```
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Get stats for a specific service
174
+ * const stats = await getServiceStats(client, 'org_123', {
175
+ * service: 'keyvalue',
176
+ * });
177
+ * ```
178
+ */
179
+ export async function getServiceStats(
180
+ client: APIClient,
181
+ orgId: string,
182
+ options?: ServiceStatsOptions,
183
+ ): Promise<ServiceStatsData> {
184
+ const params = new URLSearchParams();
185
+ if (options?.service) params.set('service', options.service);
186
+ if (options?.start) params.set('start', options.start);
187
+ if (options?.end) params.set('end', options.end);
188
+
189
+ const queryString = params.toString();
190
+ const url = `/services/stats/2026-02-26/${encodeURIComponent(orgId)}${queryString ? `?${queryString}` : ''}`;
191
+
192
+ const headers: Record<string, string> = {};
193
+ if (options?.orgIdHeader) {
194
+ headers['x-agentuity-orgid'] = options.orgIdHeader;
195
+ }
196
+
197
+ const resp = await client.get(
198
+ url,
199
+ ServiceStatsResponseSchema,
200
+ undefined,
201
+ Object.keys(headers).length > 0 ? headers : undefined,
202
+ );
203
+
204
+ if (resp.success) {
205
+ return resp.data;
206
+ }
207
+
208
+ throw new ServiceStatsError({
209
+ message: resp.message || 'Failed to get service stats',
210
+ });
211
+ }
@@ -0,0 +1,129 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema } from '../api.ts';
3
+ import {
4
+ type ListWebhookDeliveriesRequest,
5
+ type WebhookApiOptions,
6
+ type WebhookDelivery,
7
+ WebhookDeliverySchema,
8
+ } from './types.ts';
9
+ import {
10
+ buildWebhookHeaders,
11
+ WebhookError,
12
+ webhookApiPath,
13
+ webhookApiPathWithQuery,
14
+ withWebhookErrorHandling,
15
+ } from './util.ts';
16
+
17
+ export const WebhookDeliveryResponseSchema = APIResponseSchema(WebhookDeliverySchema);
18
+ export const WebhookDeliveriesListResponseSchema = APIResponseSchema(
19
+ z.array(WebhookDeliverySchema)
20
+ );
21
+
22
+ /**
23
+ * List deliveries for a webhook with optional pagination.
24
+ *
25
+ * Deliveries represent attempts to forward a received webhook payload to a destination.
26
+ *
27
+ * @param client - The API client instance
28
+ * @param webhookId - The webhook ID (prefixed with wh_)
29
+ * @param params - Optional pagination parameters
30
+ * @param options - Optional API options (e.g., orgId)
31
+ * @returns Object containing the list of deliveries
32
+ * @throws {WebhookNotFoundError} If the webhook does not exist
33
+ * @throws {WebhookError} If the API request fails
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const { deliveries } = await listWebhookDeliveries(client, 'wh_abc123', { limit: 10 });
38
+ * for (const delivery of deliveries) {
39
+ * console.log(`Delivery ${delivery.id}: ${delivery.status}`);
40
+ * }
41
+ * ```
42
+ */
43
+ export async function listWebhookDeliveries(
44
+ client: APIClient,
45
+ webhookId: string,
46
+ params?: ListWebhookDeliveriesRequest,
47
+ options?: WebhookApiOptions
48
+ ): Promise<{ deliveries: WebhookDelivery[] }> {
49
+ const searchParams = new URLSearchParams();
50
+ if (params?.limit !== undefined) {
51
+ searchParams.set('limit', String(params.limit));
52
+ }
53
+ if (params?.offset !== undefined) {
54
+ searchParams.set('offset', String(params.offset));
55
+ }
56
+
57
+ const queryString = searchParams.toString();
58
+ const url = webhookApiPathWithQuery('delivery-list', queryString || undefined, webhookId);
59
+ const resp = await withWebhookErrorHandling(
60
+ () =>
61
+ client.get(
62
+ url,
63
+ WebhookDeliveriesListResponseSchema,
64
+ undefined,
65
+ buildWebhookHeaders(options?.orgId)
66
+ ),
67
+ { webhookId }
68
+ );
69
+
70
+ if (resp.success) {
71
+ return { deliveries: resp.data };
72
+ }
73
+
74
+ throw new WebhookError({
75
+ webhookId,
76
+ message: resp.message || 'Failed to list webhook deliveries',
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Retry a failed webhook delivery.
82
+ *
83
+ * Re-attempts delivery of a webhook payload to the destination. This creates
84
+ * a new delivery attempt for the same receipt and destination.
85
+ *
86
+ * @param client - The API client instance
87
+ * @param webhookId - The webhook ID (prefixed with wh_)
88
+ * @param deliveryId - The delivery ID to retry (prefixed with whdv_)
89
+ * @param options - Optional API options (e.g., orgId)
90
+ * @returns The new delivery attempt
91
+ * @throws {WebhookDeliveryNotFoundError} If the delivery does not exist
92
+ * @throws {WebhookNotFoundError} If the webhook does not exist
93
+ * @throws {WebhookError} If the API request fails
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const delivery = await retryWebhookDelivery(client, 'wh_abc123', 'whdv_def456');
98
+ * console.log(`Retry delivery ${delivery.id}: ${delivery.status}`);
99
+ * ```
100
+ */
101
+ export async function retryWebhookDelivery(
102
+ client: APIClient,
103
+ webhookId: string,
104
+ deliveryId: string,
105
+ options?: WebhookApiOptions
106
+ ): Promise<WebhookDelivery> {
107
+ const url = webhookApiPath('delivery-retry', webhookId, deliveryId);
108
+ const resp = await withWebhookErrorHandling(
109
+ () =>
110
+ client.post(
111
+ url,
112
+ {},
113
+ WebhookDeliveryResponseSchema,
114
+ z.object({}),
115
+ undefined,
116
+ buildWebhookHeaders(options?.orgId)
117
+ ),
118
+ { webhookId, deliveryId }
119
+ );
120
+
121
+ if (resp.success) {
122
+ return resp.data;
123
+ }
124
+
125
+ throw new WebhookError({
126
+ webhookId,
127
+ message: resp.message || 'Failed to retry webhook delivery',
128
+ });
129
+ }