@agentuity/server 1.0.29 → 1.0.30

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 (39) 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/org/resources.d.ts +9 -0
  6. package/dist/api/org/resources.d.ts.map +1 -1
  7. package/dist/api/org/resources.js +3 -0
  8. package/dist/api/org/resources.js.map +1 -1
  9. package/dist/api/region/create.js +2 -2
  10. package/dist/api/region/create.js.map +1 -1
  11. package/dist/api/storage/config.d.ts +99 -0
  12. package/dist/api/storage/config.d.ts.map +1 -0
  13. package/dist/api/storage/config.js +61 -0
  14. package/dist/api/storage/config.js.map +1 -0
  15. package/dist/api/storage/index.d.ts +5 -0
  16. package/dist/api/storage/index.d.ts.map +1 -0
  17. package/dist/api/storage/index.js +5 -0
  18. package/dist/api/storage/index.js.map +1 -0
  19. package/dist/api/storage/objects.d.ts +155 -0
  20. package/dist/api/storage/objects.d.ts.map +1 -0
  21. package/dist/api/storage/objects.js +142 -0
  22. package/dist/api/storage/objects.js.map +1 -0
  23. package/dist/api/storage/types.d.ts +161 -0
  24. package/dist/api/storage/types.d.ts.map +1 -0
  25. package/dist/api/storage/types.js +101 -0
  26. package/dist/api/storage/types.js.map +1 -0
  27. package/dist/api/storage/util.d.ts +48 -0
  28. package/dist/api/storage/util.d.ts.map +1 -0
  29. package/dist/api/storage/util.js +8 -0
  30. package/dist/api/storage/util.js.map +1 -0
  31. package/package.json +4 -4
  32. package/src/api/index.ts +1 -0
  33. package/src/api/org/resources.ts +3 -0
  34. package/src/api/region/create.ts +2 -2
  35. package/src/api/storage/config.ts +103 -0
  36. package/src/api/storage/index.ts +4 -0
  37. package/src/api/storage/objects.ts +240 -0
  38. package/src/api/storage/types.ts +134 -0
  39. package/src/api/storage/util.ts +10 -0
@@ -0,0 +1,240 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient, APIResponseSchema } from '../api.ts';
3
+ import {
4
+ StorageListResponseSchema,
5
+ StorageDeleteResponseSchema,
6
+ StoragePresignResponseSchema,
7
+ StorageStatsResponseSchema,
8
+ StorageAnalyticsResponseSchema,
9
+ type StorageListResponse,
10
+ type StorageDeleteResponse,
11
+ type StoragePresignResponse,
12
+ type StorageStatsResponse,
13
+ type StorageAnalyticsResponse,
14
+ } from './types.ts';
15
+ import { STORAGE_OBJECTS_API_VERSION, StorageObjectsResponseError } from './util.ts';
16
+
17
+ export const StorageListAPIResponseSchema = APIResponseSchema(StorageListResponseSchema);
18
+ export const StorageDeleteAPIResponseSchema = APIResponseSchema(StorageDeleteResponseSchema);
19
+ export const StoragePresignAPIResponseSchema = APIResponseSchema(StoragePresignResponseSchema);
20
+ export const StorageStatsAPIResponseSchema = APIResponseSchema(StorageStatsResponseSchema);
21
+ export const StorageAnalyticsAPIResponseSchema = APIResponseSchema(StorageAnalyticsResponseSchema);
22
+
23
+ export interface ListStorageObjectsOptions {
24
+ prefix?: string;
25
+ limit?: number;
26
+ offset?: number;
27
+ }
28
+
29
+ /**
30
+ * List objects in a storage bucket with optional prefix filtering and pagination.
31
+ *
32
+ * @param client - The API client to use for the request
33
+ * @param bucketName - Name of the bucket to list objects from
34
+ * @param options - Optional filtering/pagination options
35
+ * @param extraHeaders - Optional extra headers (e.g. x-agentuity-orgid for CLI auth)
36
+ * @returns Paginated list of objects with total count
37
+ * @throws {StorageObjectsResponseError} If the request fails
38
+ */
39
+ export async function listStorageObjects(
40
+ client: APIClient,
41
+ bucketName: string,
42
+ options?: ListStorageObjectsOptions,
43
+ extraHeaders?: Record<string, string>,
44
+ ): Promise<StorageListResponse> {
45
+ const params = new URLSearchParams();
46
+ if (options?.prefix) params.set('prefix', options.prefix);
47
+ if (options?.limit !== undefined) {
48
+ if (!Number.isFinite(options.limit) || !Number.isInteger(options.limit) || options.limit < 0) {
49
+ throw new TypeError('limit must be a non-negative integer');
50
+ }
51
+ params.set('limit', String(options.limit));
52
+ }
53
+ if (options?.offset !== undefined) {
54
+ if (!Number.isFinite(options.offset) || !Number.isInteger(options.offset) || options.offset < 0) {
55
+ throw new TypeError('offset must be a non-negative integer');
56
+ }
57
+ params.set('offset', String(options.offset));
58
+ }
59
+
60
+ const query = params.toString();
61
+ const url = `/storage/objects/${STORAGE_OBJECTS_API_VERSION}/${encodeURIComponent(bucketName)}${query ? `?${query}` : ''}`;
62
+
63
+ const resp = await client.get<z.infer<typeof StorageListAPIResponseSchema>>(
64
+ url,
65
+ StorageListAPIResponseSchema,
66
+ undefined,
67
+ extraHeaders,
68
+ );
69
+
70
+ if (resp.success) {
71
+ return resp.data;
72
+ }
73
+
74
+ throw new StorageObjectsResponseError({ message: resp.message });
75
+ }
76
+
77
+ export interface DeleteStorageObjectsOptions {
78
+ key?: string;
79
+ prefix?: string;
80
+ }
81
+
82
+ /**
83
+ * Delete objects from a storage bucket.
84
+ * Provide either `key` (single object) or `prefix` (all matching objects), but not both.
85
+ *
86
+ * @param client - The API client to use for the request
87
+ * @param bucketName - Name of the bucket to delete from
88
+ * @param options - Must include either key or prefix (mutually exclusive)
89
+ * @param extraHeaders - Optional extra headers (e.g. x-agentuity-orgid for CLI auth)
90
+ * @returns The count of deleted objects
91
+ * @throws {StorageObjectsResponseError} If the request fails
92
+ */
93
+ export async function deleteStorageObjects(
94
+ client: APIClient,
95
+ bucketName: string,
96
+ options: DeleteStorageObjectsOptions,
97
+ extraHeaders?: Record<string, string>,
98
+ ): Promise<StorageDeleteResponse> {
99
+ if (!options.key && !options.prefix) {
100
+ throw new StorageObjectsResponseError({ message: "Either 'key' or 'prefix' is required" });
101
+ }
102
+ if (options.key && options.prefix) {
103
+ throw new StorageObjectsResponseError({ message: "Provide either 'key' or 'prefix', not both" });
104
+ }
105
+
106
+ const params = new URLSearchParams();
107
+ if (options.key) params.set('key', options.key);
108
+ if (options.prefix) params.set('prefix', options.prefix);
109
+
110
+ const url = `/storage/objects/${STORAGE_OBJECTS_API_VERSION}/${encodeURIComponent(bucketName)}?${params.toString()}`;
111
+
112
+ const resp = await client.delete<z.infer<typeof StorageDeleteAPIResponseSchema>>(
113
+ url,
114
+ StorageDeleteAPIResponseSchema,
115
+ undefined,
116
+ extraHeaders,
117
+ );
118
+
119
+ if (resp.success) {
120
+ return resp.data;
121
+ }
122
+
123
+ throw new StorageObjectsResponseError({ message: resp.message });
124
+ }
125
+
126
+ /**
127
+ * Generate a presigned URL for downloading or uploading an object.
128
+ *
129
+ * @param client - The API client to use for the request
130
+ * @param bucketName - Name of the bucket
131
+ * @param key - Object key
132
+ * @param operation - 'download' (default) or 'upload'
133
+ * @param extraHeaders - Optional extra headers (e.g. x-agentuity-orgid for CLI auth)
134
+ * @returns Presigned URL and expiry info
135
+ * @throws {StorageObjectsResponseError} If the request fails
136
+ */
137
+ export async function presignStorageObject(
138
+ client: APIClient,
139
+ bucketName: string,
140
+ key: string,
141
+ operation: 'download' | 'upload' = 'download',
142
+ extraHeaders?: Record<string, string>,
143
+ ): Promise<StoragePresignResponse> {
144
+ if (!key) {
145
+ throw new StorageObjectsResponseError({ message: "'key' must be a non-empty string" });
146
+ }
147
+ const params = new URLSearchParams();
148
+ params.set('key', key);
149
+ if (operation !== 'download') {
150
+ params.set('operation', operation);
151
+ }
152
+
153
+ const url = `/storage/presign/${STORAGE_OBJECTS_API_VERSION}/${encodeURIComponent(bucketName)}?${params.toString()}`;
154
+
155
+ const resp = await client.get<z.infer<typeof StoragePresignAPIResponseSchema>>(
156
+ url,
157
+ StoragePresignAPIResponseSchema,
158
+ undefined,
159
+ extraHeaders,
160
+ );
161
+
162
+ if (resp.success) {
163
+ return resp.data;
164
+ }
165
+
166
+ throw new StorageObjectsResponseError({ message: resp.message });
167
+ }
168
+
169
+ /**
170
+ * Get aggregate stats for a storage bucket (object count, total size).
171
+ *
172
+ * @param client - The API client to use for the request
173
+ * @param bucketName - Name of the bucket
174
+ * @param extraHeaders - Optional extra headers (e.g. x-agentuity-orgid for CLI auth)
175
+ * @returns Bucket statistics
176
+ * @throws {StorageObjectsResponseError} If the request fails
177
+ */
178
+ export async function getStorageStats(
179
+ client: APIClient,
180
+ bucketName: string,
181
+ extraHeaders?: Record<string, string>,
182
+ ): Promise<StorageStatsResponse> {
183
+ const url = `/storage/stats/${STORAGE_OBJECTS_API_VERSION}/${encodeURIComponent(bucketName)}`;
184
+
185
+ const resp = await client.get<z.infer<typeof StorageStatsAPIResponseSchema>>(
186
+ url,
187
+ StorageStatsAPIResponseSchema,
188
+ undefined,
189
+ extraHeaders,
190
+ );
191
+
192
+ if (resp.success) {
193
+ return resp.data;
194
+ }
195
+
196
+ throw new StorageObjectsResponseError({ message: resp.message });
197
+ }
198
+
199
+ export interface GetStorageAnalyticsOptions {
200
+ days?: number;
201
+ }
202
+
203
+ /**
204
+ * Get storage analytics for the org: summary totals, per-bucket breakdown, and daily snapshots.
205
+ *
206
+ * @param client - The API client to use for the request
207
+ * @param options - Optional options (days for sparkline history, default 180)
208
+ * @param extraHeaders - Optional extra headers (e.g. x-agentuity-orgid for CLI auth)
209
+ * @returns Analytics data with summary, buckets, and daily snapshots
210
+ * @throws {StorageObjectsResponseError} If the request fails
211
+ */
212
+ export async function getStorageAnalytics(
213
+ client: APIClient,
214
+ options?: GetStorageAnalyticsOptions,
215
+ extraHeaders?: Record<string, string>,
216
+ ): Promise<StorageAnalyticsResponse> {
217
+ const params = new URLSearchParams();
218
+ if (options?.days !== undefined) {
219
+ if (!Number.isFinite(options.days) || !Number.isInteger(options.days) || options.days < 0) {
220
+ throw new TypeError('days must be a non-negative integer');
221
+ }
222
+ params.set('days', String(options.days));
223
+ }
224
+
225
+ const query = params.toString();
226
+ const url = `/storage/analytics/${STORAGE_OBJECTS_API_VERSION}${query ? `?${query}` : ''}`;
227
+
228
+ const resp = await client.get<z.infer<typeof StorageAnalyticsAPIResponseSchema>>(
229
+ url,
230
+ StorageAnalyticsAPIResponseSchema,
231
+ undefined,
232
+ extraHeaders,
233
+ );
234
+
235
+ if (resp.success) {
236
+ return resp.data;
237
+ }
238
+
239
+ throw new StorageObjectsResponseError({ message: resp.message });
240
+ }
@@ -0,0 +1,134 @@
1
+ import { z } from 'zod';
2
+
3
+ /** Valid storage tier values */
4
+ export const StorageTierValues = ['STANDARD', 'INFREQUENT_ACCESS', 'ARCHIVE'] as const;
5
+
6
+ /** Storage tier enum schema */
7
+ export const StorageTierSchema = z.enum(StorageTierValues).describe('Storage tier for the bucket');
8
+
9
+ /** Storage tier type */
10
+ export type StorageTier = z.infer<typeof StorageTierSchema>;
11
+
12
+ /** CORS configuration for a bucket */
13
+ export const CORSConfigSchema = z.object({
14
+ allowed_origins: z.array(z.string().describe('An allowed origin URL')).optional().describe('List of allowed origin URLs for CORS requests'),
15
+ allowed_methods: z.array(z.string().describe('An allowed HTTP method')).optional().describe('List of allowed HTTP methods for CORS requests'),
16
+ allowed_headers: z.array(z.string().describe('An allowed request header')).optional().describe('List of allowed request headers for CORS requests'),
17
+ expose_headers: z.array(z.string().describe('A response header to expose')).optional().describe('List of response headers to expose to the browser'),
18
+ max_age_seconds: z.number().int().min(0).nullable().optional().describe('Maximum time in seconds that preflight results can be cached'),
19
+ });
20
+
21
+ /** Full bucket config (response from GET/PUT) */
22
+ export const BucketConfigSchema = z.object({
23
+ bucket_name: z.string().describe('The name of the storage bucket'),
24
+ storage_tier: StorageTierSchema.nullable().optional().describe('Storage tier for the bucket'),
25
+ ttl: z.number().int().min(0).nullable().optional().describe('Object TTL in seconds'),
26
+ public: z.boolean().nullable().optional().describe('Whether the bucket is publicly accessible'),
27
+ cache_control: z.string().nullable().optional().describe('Default Cache-Control header for objects'),
28
+ cors: CORSConfigSchema.nullable().optional().describe('Custom CORS configuration'),
29
+ additional_headers: z.record(z.string(), z.string()).nullable().optional().describe('Additional response headers as key-value pairs'),
30
+ bucket_location: z.string().nullable().optional().describe('Bucket location or region override'),
31
+ });
32
+
33
+ /**
34
+ * Update request body (all fields optional — partial update).
35
+ * Send a field with a value to set it, send null to unset it, omit to leave unchanged.
36
+ */
37
+ export const BucketConfigUpdateSchema = z.object({
38
+ storage_tier: StorageTierSchema.nullable().optional().describe('Storage tier for the bucket'),
39
+ ttl: z.number().int().min(0).nullable().optional().describe('Object TTL in seconds (0 to clear)'),
40
+ public: z.boolean().nullable().optional().describe('Whether the bucket is publicly accessible'),
41
+ cache_control: z.string().nullable().optional().describe('Default Cache-Control header for objects'),
42
+ cors: CORSConfigSchema.nullable().optional().describe('Custom CORS configuration'),
43
+ additional_headers: z.record(z.string(), z.string()).nullable().optional().describe('Additional response headers as key-value pairs'),
44
+ });
45
+
46
+ /** TypeScript types derived from Zod schemas */
47
+ export type CORSConfig = z.infer<typeof CORSConfigSchema>;
48
+ export type BucketConfig = z.infer<typeof BucketConfigSchema>;
49
+ export type BucketConfigUpdate = z.infer<typeof BucketConfigUpdateSchema>;
50
+
51
+ // --- Storage Objects types ---
52
+
53
+ /** A storage object in a bucket */
54
+ export const StorageObjectSchema = z.object({
55
+ bucket_name: z.string().describe('The bucket this object belongs to'),
56
+ key: z.string().describe('Object key (path)'),
57
+ size: z.number().int().nonnegative().describe('Object size in bytes'),
58
+ etag: z.string().optional().describe('Object ETag'),
59
+ content_type: z.string().optional().describe('Object content type'),
60
+ last_modified: z.string().optional().describe('Last modified timestamp (ISO8601)'),
61
+ });
62
+
63
+ /** Paginated list of storage objects */
64
+ export const StorageListResponseSchema = z.object({
65
+ objects: z.array(StorageObjectSchema).describe('List of objects'),
66
+ total: z.number().int().nonnegative().describe('Total count matching the query'),
67
+ prefix: z.string().describe('Prefix filter applied'),
68
+ limit: z.number().int().nonnegative().describe('Page size'),
69
+ offset: z.number().int().nonnegative().describe('Page offset'),
70
+ });
71
+
72
+ /** Delete response */
73
+ export const StorageDeleteResponseSchema = z.object({
74
+ deleted_count: z.number().int().nonnegative().describe('Number of objects deleted'),
75
+ });
76
+
77
+ /** Presigned URL response */
78
+ export const StoragePresignResponseSchema = z.object({
79
+ presigned_url: z.string().describe('The presigned URL'),
80
+ expiry_seconds: z.number().int().nonnegative().describe('URL expiry time in seconds'),
81
+ });
82
+
83
+ /** Bucket stats response */
84
+ export const StorageStatsResponseSchema = z.object({
85
+ bucket_name: z.string().describe('The bucket name'),
86
+ object_count: z.number().int().nonnegative().describe('Number of objects'),
87
+ total_size: z.number().int().nonnegative().describe('Total size in bytes'),
88
+ last_event_at: z.string().optional().describe('Last event timestamp (ISO8601)'),
89
+ });
90
+
91
+ // --- Storage Analytics types ---
92
+
93
+ /** Summary totals across all buckets */
94
+ export const StorageAnalyticsSummarySchema = z.object({
95
+ total_object_count: z.number().int().nonnegative().describe('Total objects across all buckets'),
96
+ total_size: z.number().int().nonnegative().describe('Total size in bytes across all buckets'),
97
+ estimated_monthly_cost: z.number().describe('Estimated monthly cost in USD'),
98
+ cost_per_gb_month: z.number().describe('Cost rate per GB per month in USD'),
99
+ });
100
+
101
+ /** Per-bucket breakdown */
102
+ export const StorageAnalyticsBucketSchema = z.object({
103
+ bucket_name: z.string().describe('The bucket name'),
104
+ object_count: z.number().int().nonnegative().describe('Number of objects in this bucket'),
105
+ total_size: z.number().int().nonnegative().describe('Total size in bytes for this bucket'),
106
+ last_event_at: z.string().optional().describe('Last event timestamp (ISO8601)'),
107
+ estimated_monthly_cost: z.number().describe('Estimated monthly cost for this bucket in USD'),
108
+ });
109
+
110
+ /** Daily snapshot for sparklines */
111
+ export const StorageAnalyticsDailySnapshotSchema = z.object({
112
+ date: z.string().describe('Snapshot date (YYYY-MM-DD)'),
113
+ total_object_count: z.number().int().nonnegative().describe('Total objects on this date'),
114
+ total_size: z.number().int().nonnegative().describe('Total size in bytes on this date'),
115
+ estimated_cost: z.number().describe('Estimated monthly cost at this snapshot in USD'),
116
+ });
117
+
118
+ /** Full analytics response */
119
+ export const StorageAnalyticsResponseSchema = z.object({
120
+ summary: StorageAnalyticsSummarySchema.describe('Org-wide totals'),
121
+ buckets: z.array(StorageAnalyticsBucketSchema).describe('Per-bucket breakdown'),
122
+ daily: z.array(StorageAnalyticsDailySnapshotSchema).describe('Daily snapshots for sparklines'),
123
+ days: z.number().int().nonnegative().describe('Number of days requested'),
124
+ });
125
+
126
+ export type StorageObject = z.infer<typeof StorageObjectSchema>;
127
+ export type StorageListResponse = z.infer<typeof StorageListResponseSchema>;
128
+ export type StorageDeleteResponse = z.infer<typeof StorageDeleteResponseSchema>;
129
+ export type StoragePresignResponse = z.infer<typeof StoragePresignResponseSchema>;
130
+ export type StorageStatsResponse = z.infer<typeof StorageStatsResponseSchema>;
131
+ export type StorageAnalyticsSummary = z.infer<typeof StorageAnalyticsSummarySchema>;
132
+ export type StorageAnalyticsBucket = z.infer<typeof StorageAnalyticsBucketSchema>;
133
+ export type StorageAnalyticsDailySnapshot = z.infer<typeof StorageAnalyticsDailySnapshotSchema>;
134
+ export type StorageAnalyticsResponse = z.infer<typeof StorageAnalyticsResponseSchema>;
@@ -0,0 +1,10 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+
3
+ export const BUCKET_CONFIG_API_VERSION = '2026-02-28';
4
+ export const STORAGE_OBJECTS_API_VERSION = '2026-03-01';
5
+
6
+ // Keep the old name exported for backward compat
7
+ export const API_VERSION = BUCKET_CONFIG_API_VERSION;
8
+
9
+ export const BucketConfigResponseError = StructuredError('BucketConfigResponseError');
10
+ export const StorageObjectsResponseError = StructuredError('StorageObjectsResponseError');