@agentuity/core 0.0.68 → 0.0.70

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.
@@ -1,257 +0,0 @@
1
- import type { FetchAdapter } from './adapter';
2
- /**
3
- * Parameters for putting an object into the object store
4
- */
5
- export interface ObjectStorePutParams {
6
- /**
7
- * the content type of the object
8
- */
9
- contentType?: string;
10
- /**
11
- * the content encoding of the object
12
- */
13
- contentEncoding?: string;
14
- /**
15
- * the cache control header for the object
16
- */
17
- cacheControl?: string;
18
- /**
19
- * the content disposition header for the object
20
- */
21
- contentDisposition?: string;
22
- /**
23
- * the content language header for the object
24
- */
25
- contentLanguage?: string;
26
- /**
27
- * arbitrary metadata to attach to the object but not returned as part of the object when fetched via HTTP
28
- */
29
- metadata?: Record<string, string>;
30
- }
31
- /**
32
- * Result when an object is found in the object store
33
- */
34
- export interface ObjectResultFound {
35
- /**
36
- * the object data
37
- */
38
- data: Uint8Array;
39
- /**
40
- * the content type of the object
41
- */
42
- contentType: string;
43
- /**
44
- * the object was found
45
- */
46
- exists: true;
47
- }
48
- /**
49
- * Result when an object is not found in the object store
50
- */
51
- export interface ObjectResultNotFound {
52
- data: never;
53
- /**
54
- * the object was not found
55
- */
56
- exists: false;
57
- }
58
- /**
59
- * The result of an object store get operation
60
- */
61
- export type ObjectResult = ObjectResultFound | ObjectResultNotFound;
62
- /**
63
- * Parameters for creating a public URL
64
- */
65
- export interface CreatePublicURLParams {
66
- /**
67
- * the duration of the signed URL in milliseconds. If not provided, the default is 1 hour.
68
- */
69
- expiresDuration?: number;
70
- }
71
- /**
72
- * Information about an object in the object store
73
- */
74
- export interface ObjectInfo {
75
- key: string;
76
- size: number;
77
- etag: string;
78
- created_at: string;
79
- updated_at: string;
80
- }
81
- /**
82
- * Information about a bucket in the object store
83
- */
84
- export interface BucketInfo {
85
- name: string;
86
- object_count: number;
87
- total_bytes: number;
88
- }
89
- /**
90
- * Object store service for storing and retrieving binary data
91
- */
92
- export interface ObjectStorage {
93
- /**
94
- * Get an object from the object store
95
- *
96
- * @param bucket - the bucket to get the object from
97
- * @param key - the key of the object to get
98
- * @returns a Promise that resolves to the object result
99
- *
100
- * @example
101
- * ```typescript
102
- * const result = await objectStore.get('my-bucket', 'my-key');
103
- * if (result.exists) {
104
- * console.log('Content type:', result.contentType);
105
- * console.log('Data:', result.data);
106
- * }
107
- * ```
108
- */
109
- get(bucket: string, key: string): Promise<ObjectResult>;
110
- /**
111
- * Put an object into the object store
112
- *
113
- * @param bucket - the bucket to put the object into
114
- * @param key - the key of the object to put
115
- * @param data - the data to put (Uint8Array, ArrayBuffer, or ReadableStream)
116
- * @param params - optional parameters for the put operation
117
- *
118
- * @example
119
- * ```typescript
120
- * const data = new TextEncoder().encode('Hello, world!');
121
- * await objectStore.put('my-bucket', 'greeting.txt', data, {
122
- * contentType: 'text/plain',
123
- * metadata: { author: 'user123' }
124
- * });
125
- * ```
126
- */
127
- put(bucket: string, key: string, data: Uint8Array | ArrayBuffer | ReadableStream, params?: ObjectStorePutParams): Promise<void>;
128
- /**
129
- * Delete an object from the object store
130
- *
131
- * @param bucket - the bucket to delete the object from
132
- * @param key - the key of the object to delete
133
- * @returns true if the object was deleted, false if the object did not exist
134
- *
135
- * @example
136
- * ```typescript
137
- * const deleted = await objectStore.delete('my-bucket', 'my-key');
138
- * if (deleted) {
139
- * console.log('Object was deleted');
140
- * } else {
141
- * console.log('Object did not exist');
142
- * }
143
- * ```
144
- */
145
- delete(bucket: string, key: string): Promise<boolean>;
146
- /**
147
- * Create a public URL for an object. This URL can be used to access the object without authentication.
148
- *
149
- * @param bucket - the bucket to create the signed URL for
150
- * @param key - the key of the object to create the signed URL for
151
- * @param params - optional parameters including expiration duration
152
- * @returns the public URL
153
- *
154
- * @example
155
- * ```typescript
156
- * const url = await objectStore.createPublicURL('my-bucket', 'my-key', {
157
- * expiresDuration: 3600000 // 1 hour in milliseconds
158
- * });
159
- * console.log('Public URL:', url);
160
- * ```
161
- */
162
- createPublicURL(bucket: string, key: string, params?: CreatePublicURLParams): Promise<string>;
163
- /**
164
- * List all buckets in the object store
165
- *
166
- * @returns array of bucket information
167
- *
168
- * @example
169
- * ```typescript
170
- * const buckets = await objectStore.listBuckets();
171
- * for (const bucket of buckets) {
172
- * console.log(`${bucket.name}: ${bucket.object_count} objects, ${bucket.total_bytes} bytes`);
173
- * }
174
- * ```
175
- */
176
- listBuckets(): Promise<BucketInfo[]>;
177
- /**
178
- * List all keys in a bucket
179
- *
180
- * @param bucket - the bucket to list keys from
181
- * @returns array of object information
182
- *
183
- * @example
184
- * ```typescript
185
- * const objects = await objectStore.listKeys('my-bucket');
186
- * for (const obj of objects) {
187
- * console.log(`${obj.key}: ${obj.size} bytes`);
188
- * }
189
- * ```
190
- */
191
- listKeys(bucket: string): Promise<ObjectInfo[]>;
192
- /**
193
- * List objects in a bucket with optional filtering
194
- *
195
- * @param bucket - the bucket to list objects from
196
- * @param options - optional filtering (prefix, limit)
197
- * @returns array of object information
198
- *
199
- * @example
200
- * ```typescript
201
- * const objects = await objectStore.listObjects('my-bucket', { prefix: 'docs/', limit: 100 });
202
- * for (const obj of objects) {
203
- * console.log(`${obj.key}: ${obj.size} bytes`);
204
- * }
205
- * ```
206
- */
207
- listObjects(bucket: string, options?: {
208
- prefix?: string;
209
- limit?: number;
210
- }): Promise<ObjectInfo[]>;
211
- /**
212
- * Get object metadata without retrieving the data
213
- *
214
- * @param bucket - the bucket containing the object
215
- * @param key - the key of the object
216
- * @returns object metadata (size, contentType, etc.)
217
- *
218
- * @example
219
- * ```typescript
220
- * const metadata = await objectStore.headObject('my-bucket', 'my-key');
221
- * console.log(`Size: ${metadata.size}, Type: ${metadata.contentType}`);
222
- * ```
223
- */
224
- headObject(bucket: string, key: string): Promise<ObjectInfo>;
225
- /**
226
- * Delete a bucket and all its contents
227
- *
228
- * @param bucket - the bucket to delete
229
- * @returns true if the bucket was deleted
230
- *
231
- * @example
232
- * ```typescript
233
- * await objectStore.deleteBucket('my-bucket');
234
- * ```
235
- */
236
- deleteBucket(bucket: string): Promise<boolean>;
237
- }
238
- /**
239
- * Implementation of the ObjectStorage interface
240
- */
241
- export declare class ObjectStorageService implements ObjectStorage {
242
- #private;
243
- constructor(baseUrl: string, adapter: FetchAdapter);
244
- get(bucket: string, key: string): Promise<ObjectResult>;
245
- put(bucket: string, key: string, data: Uint8Array | ArrayBuffer | ReadableStream, params?: ObjectStorePutParams): Promise<void>;
246
- delete(bucket: string, key: string): Promise<boolean>;
247
- createPublicURL(bucket: string, key: string, params?: CreatePublicURLParams): Promise<string>;
248
- listBuckets(): Promise<BucketInfo[]>;
249
- listKeys(bucket: string): Promise<ObjectInfo[]>;
250
- listObjects(bucket: string, options?: {
251
- prefix?: string;
252
- limit?: number;
253
- }): Promise<ObjectInfo[]>;
254
- headObject(bucket: string, key: string): Promise<ObjectInfo>;
255
- deleteBucket(bucket: string): Promise<boolean>;
256
- }
257
- //# sourceMappingURL=objectstore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"objectstore.d.ts","sourceRoot":"","sources":["../../src/services/objectstore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAsB,MAAM,WAAW,CAAC;AAIlE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,WA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CAAC,EAAE,qBAAqB,GAC5B,OAAO,CAAC,MAAM,CAAC;IAoEZ,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAgCpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAyC/C,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3C,OAAO,CAAC,UAAU,EAAE,CAAC;IAuDlB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAgD5D,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAyCpD"}
@@ -1,422 +0,0 @@
1
- import { buildUrl, toServiceException } from './_util';
2
- import { StructuredError } from '../error';
3
- const ObjectStoreBucketMissingError = StructuredError('ObjectStoreBucketMissingError', 'bucket is required and cannot be empty');
4
- const ObjectStoreKeyMissingError = StructuredError('ObjectStoreKeyMissingError', 'key is required and cannot be empty');
5
- const ObjectStoreDataMissingError = StructuredError('ObjectStoreDataMissingError', 'data is required');
6
- const ObjectStoreResponseError = StructuredError('ObjectStoreResponseError')();
7
- const ObjectStoreResponseInvalidError = StructuredError('ObjectStoreResponseInvalidError');
8
- const ObjectStoreNotFoundError = StructuredError('ObjectStoreNotFoundError', 'object not found');
9
- /**
10
- * Implementation of the ObjectStorage interface
11
- */
12
- export class ObjectStorageService {
13
- #adapter;
14
- #baseUrl;
15
- constructor(baseUrl, adapter) {
16
- this.#baseUrl = baseUrl;
17
- this.#adapter = adapter;
18
- }
19
- async get(bucket, key) {
20
- if (!bucket?.trim()) {
21
- throw new ObjectStoreBucketMissingError();
22
- }
23
- if (!key?.trim()) {
24
- throw new ObjectStoreKeyMissingError();
25
- }
26
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`);
27
- const signal = AbortSignal.timeout(10_000);
28
- const options = {
29
- method: 'GET',
30
- signal,
31
- telemetry: {
32
- name: 'agentuity.objectstore.get',
33
- attributes: {
34
- 'objectstore.bucket': bucket,
35
- 'objectstore.key': key,
36
- },
37
- },
38
- };
39
- try {
40
- const result = await this.#adapter.invoke(url, options);
41
- if (result.response.status === 404) {
42
- return { exists: false };
43
- }
44
- if (!result.ok) {
45
- throw new ObjectStoreResponseError({
46
- status: result.response.status,
47
- message: `Failed to get object: ${result.response.statusText} (${result.response.status})`,
48
- });
49
- }
50
- const data = result.data;
51
- if (!(data instanceof ArrayBuffer)) {
52
- throw new ObjectStoreResponseInvalidError({
53
- message: 'Expected ArrayBuffer response from object store',
54
- });
55
- }
56
- const contentType = result.response.headers.get('content-type') || 'application/octet-stream';
57
- return {
58
- exists: true,
59
- data: new Uint8Array(data),
60
- contentType,
61
- };
62
- }
63
- catch (err) {
64
- if (err instanceof Response) {
65
- throw await toServiceException('GET', url, err);
66
- }
67
- throw err;
68
- }
69
- }
70
- async put(bucket, key, data, params) {
71
- if (!bucket?.trim()) {
72
- throw new ObjectStoreBucketMissingError();
73
- }
74
- if (!key?.trim()) {
75
- throw new ObjectStoreKeyMissingError();
76
- }
77
- if (!data) {
78
- throw new ObjectStoreDataMissingError();
79
- }
80
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`);
81
- const headers = {
82
- 'Content-Type': params?.contentType || 'application/octet-stream',
83
- };
84
- if (params?.contentEncoding) {
85
- headers['Content-Encoding'] = params.contentEncoding;
86
- }
87
- if (params?.cacheControl) {
88
- headers['Cache-Control'] = params.cacheControl;
89
- }
90
- if (params?.contentDisposition) {
91
- headers['Content-Disposition'] = params.contentDisposition;
92
- }
93
- if (params?.contentLanguage) {
94
- headers['Content-Language'] = params.contentLanguage;
95
- }
96
- if (params?.metadata) {
97
- for (const [metaKey, metaValue] of Object.entries(params.metadata)) {
98
- headers[`x-metadata-${metaKey}`] = metaValue;
99
- }
100
- }
101
- let body;
102
- if (data instanceof ArrayBuffer) {
103
- body = data;
104
- }
105
- else if (data instanceof Uint8Array) {
106
- if (data.byteOffset !== 0 || data.byteLength !== data.buffer.byteLength) {
107
- body = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
108
- }
109
- else {
110
- body = data.buffer;
111
- }
112
- }
113
- else {
114
- body = data;
115
- }
116
- const signal = AbortSignal.timeout(30_000);
117
- const options = {
118
- method: 'PUT',
119
- headers,
120
- body,
121
- signal,
122
- telemetry: {
123
- name: 'agentuity.objectstore.put',
124
- attributes: {
125
- 'objectstore.bucket': bucket,
126
- 'objectstore.key': key,
127
- 'objectstore.contentType': params?.contentType || 'application/octet-stream',
128
- },
129
- },
130
- };
131
- try {
132
- const result = await this.#adapter.invoke(url, options);
133
- if (!result.ok || (result.response.status !== 200 && result.response.status !== 201)) {
134
- throw new ObjectStoreResponseError({
135
- status: result.response.status,
136
- message: `Failed to put object: ${result.response.statusText} (${result.response.status})`,
137
- });
138
- }
139
- }
140
- catch (err) {
141
- if (err instanceof Response) {
142
- throw await toServiceException('PUT', url, err);
143
- }
144
- throw err;
145
- }
146
- }
147
- async delete(bucket, key) {
148
- if (!bucket?.trim()) {
149
- throw new ObjectStoreBucketMissingError();
150
- }
151
- if (!key?.trim()) {
152
- throw new ObjectStoreKeyMissingError();
153
- }
154
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`);
155
- const signal = AbortSignal.timeout(10_000);
156
- const options = {
157
- method: 'DELETE',
158
- signal,
159
- telemetry: {
160
- name: 'agentuity.objectstore.delete',
161
- attributes: {
162
- 'objectstore.bucket': bucket,
163
- 'objectstore.key': key,
164
- },
165
- },
166
- };
167
- try {
168
- const result = await this.#adapter.invoke(url, options);
169
- if (result.response.status === 404) {
170
- return false;
171
- }
172
- if (result.response.status === 200) {
173
- return true;
174
- }
175
- throw new ObjectStoreResponseError({
176
- status: result.response.status,
177
- message: `Failed to delete object: ${result.response.statusText} (${result.response.status})`,
178
- });
179
- }
180
- catch (err) {
181
- if (err instanceof Response) {
182
- throw await toServiceException('DELETE', url, err);
183
- }
184
- throw err;
185
- }
186
- }
187
- async createPublicURL(bucket, key, params) {
188
- if (!bucket?.trim()) {
189
- throw new ObjectStoreBucketMissingError();
190
- }
191
- if (!key?.trim()) {
192
- throw new ObjectStoreKeyMissingError();
193
- }
194
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/presigned/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`);
195
- const requestBody = {};
196
- if (params?.expiresDuration) {
197
- requestBody.expires = params.expiresDuration;
198
- }
199
- const signal = AbortSignal.timeout(10_000);
200
- const options = {
201
- method: 'POST',
202
- contentType: 'application/json',
203
- body: JSON.stringify(requestBody),
204
- signal,
205
- telemetry: {
206
- name: 'agentuity.objectstore.createPublicURL',
207
- attributes: {
208
- 'objectstore.bucket': bucket,
209
- 'objectstore.key': key,
210
- 'objectstore.expiresDuration': params?.expiresDuration?.toString() || '',
211
- },
212
- },
213
- };
214
- try {
215
- const result = await this.#adapter.invoke(url, options);
216
- if (!result.ok) {
217
- throw new ObjectStoreResponseError({
218
- status: result.response.status,
219
- message: `Failed to create public URL: ${result.response.statusText} (${result.response.status})`,
220
- });
221
- }
222
- const data = result.data;
223
- if (!data.success) {
224
- throw new ObjectStoreResponseError({
225
- status: result.response.status,
226
- message: data.message || 'Failed to create public URL',
227
- });
228
- }
229
- return data.url;
230
- }
231
- catch (err) {
232
- if (err instanceof Error && err.message.includes('Object not found')) {
233
- throw err;
234
- }
235
- if (err instanceof Response) {
236
- throw await toServiceException('POST', url, err);
237
- }
238
- throw err;
239
- }
240
- }
241
- async listBuckets() {
242
- const url = buildUrl(this.#baseUrl, '/object/2025-03-17/buckets');
243
- const signal = AbortSignal.timeout(10_000);
244
- const options = {
245
- method: 'GET',
246
- signal,
247
- telemetry: {
248
- name: 'agentuity.objectstore.listBuckets',
249
- attributes: {},
250
- },
251
- };
252
- try {
253
- const result = await this.#adapter.invoke(url, options);
254
- if (!result.ok) {
255
- throw new ObjectStoreResponseError({
256
- status: result.response.status,
257
- message: `Failed to list buckets: ${result.response.statusText} (${result.response.status})`,
258
- });
259
- }
260
- return result.data.buckets;
261
- }
262
- catch (err) {
263
- if (err instanceof Response) {
264
- throw await toServiceException('GET', url, err);
265
- }
266
- throw err;
267
- }
268
- }
269
- async listKeys(bucket) {
270
- if (!bucket?.trim()) {
271
- throw new ObjectStoreBucketMissingError();
272
- }
273
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/keys/${encodeURIComponent(bucket)}`);
274
- const signal = AbortSignal.timeout(10_000);
275
- const options = {
276
- method: 'GET',
277
- signal,
278
- telemetry: {
279
- name: 'agentuity.objectstore.listKeys',
280
- attributes: {
281
- 'objectstore.bucket': bucket,
282
- },
283
- },
284
- };
285
- try {
286
- const result = await this.#adapter.invoke(url, options);
287
- if (!result.ok) {
288
- throw new ObjectStoreResponseError({
289
- status: result.response.status,
290
- message: `Failed to list keys: ${result.response.statusText} (${result.response.status})`,
291
- });
292
- }
293
- return result.data.objects;
294
- }
295
- catch (err) {
296
- if (err instanceof Response) {
297
- throw await toServiceException('GET', url, err);
298
- }
299
- throw err;
300
- }
301
- }
302
- async listObjects(bucket, options) {
303
- if (!bucket?.trim()) {
304
- throw new ObjectStoreBucketMissingError();
305
- }
306
- const params = new URLSearchParams();
307
- if (options?.prefix) {
308
- params.set('prefix', options.prefix);
309
- }
310
- if (options?.limit) {
311
- params.set('limit', options.limit.toString());
312
- }
313
- const queryString = params.toString();
314
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/objects/${encodeURIComponent(bucket)}${queryString ? `?${queryString}` : ''}`);
315
- const signal = AbortSignal.timeout(10_000);
316
- const fetchOptions = {
317
- method: 'GET',
318
- signal,
319
- telemetry: {
320
- name: 'agentuity.objectstore.listObjects',
321
- attributes: {
322
- 'objectstore.bucket': bucket,
323
- 'objectstore.prefix': options?.prefix || '',
324
- 'objectstore.limit': (options?.limit || 1000).toString(),
325
- },
326
- },
327
- };
328
- try {
329
- const result = await this.#adapter.invoke(url, fetchOptions);
330
- if (!result.ok) {
331
- throw new ObjectStoreResponseError({
332
- status: result.response.status,
333
- message: `Failed to list objects: ${result.response.statusText} (${result.response.status})`,
334
- });
335
- }
336
- return result.data.objects;
337
- }
338
- catch (err) {
339
- if (err instanceof Response) {
340
- throw await toServiceException('GET', url, err);
341
- }
342
- throw err;
343
- }
344
- }
345
- async headObject(bucket, key) {
346
- if (!bucket?.trim()) {
347
- throw new ObjectStoreBucketMissingError();
348
- }
349
- if (!key?.trim()) {
350
- throw new ObjectStoreKeyMissingError();
351
- }
352
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/head/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`);
353
- const signal = AbortSignal.timeout(10_000);
354
- const fetchOptions = {
355
- method: 'GET',
356
- signal,
357
- telemetry: {
358
- name: 'agentuity.objectstore.headObject',
359
- attributes: {
360
- 'objectstore.bucket': bucket,
361
- 'objectstore.key': key,
362
- },
363
- },
364
- };
365
- try {
366
- const result = await this.#adapter.invoke(url, fetchOptions);
367
- if (!result.ok) {
368
- if (result.response.status === 404) {
369
- throw new ObjectStoreNotFoundError();
370
- }
371
- throw new ObjectStoreResponseError({
372
- status: result.response.status,
373
- message: `Failed to get object metadata: ${result.response.statusText} (${result.response.status})`,
374
- });
375
- }
376
- return result.data;
377
- }
378
- catch (err) {
379
- if (err instanceof Response) {
380
- throw await toServiceException('GET', url, err);
381
- }
382
- throw err;
383
- }
384
- }
385
- async deleteBucket(bucket) {
386
- if (!bucket?.trim()) {
387
- throw new ObjectStoreBucketMissingError();
388
- }
389
- const url = buildUrl(this.#baseUrl, `/object/2025-03-17/${encodeURIComponent(bucket)}`);
390
- const signal = AbortSignal.timeout(30_000);
391
- const options = {
392
- method: 'DELETE',
393
- signal,
394
- telemetry: {
395
- name: 'agentuity.objectstore.deleteBucket',
396
- attributes: {
397
- 'objectstore.bucket': bucket,
398
- },
399
- },
400
- };
401
- try {
402
- const result = await this.#adapter.invoke(url, options);
403
- if (result.response.status === 404) {
404
- return false;
405
- }
406
- if (result.response.status === 200) {
407
- return true;
408
- }
409
- throw new ObjectStoreResponseError({
410
- status: result.response.status,
411
- message: `Failed to delete bucket: ${result.response.statusText} (${result.response.status})`,
412
- });
413
- }
414
- catch (err) {
415
- if (err instanceof Response) {
416
- throw await toServiceException('DELETE', url, err);
417
- }
418
- throw err;
419
- }
420
- }
421
- }
422
- //# sourceMappingURL=objectstore.js.map