@agentuity/core 0.0.69 → 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.
- package/dist/services/_util.d.ts.map +1 -1
- package/dist/services/_util.js +11 -1
- package/dist/services/_util.js.map +1 -1
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +0 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/stream.d.ts.map +1 -1
- package/dist/services/stream.js +6 -5
- package/dist/services/stream.js.map +1 -1
- package/package.json +2 -1
- package/src/services/_util.ts +10 -1
- package/src/services/index.ts +0 -1
- package/src/services/stream.ts +10 -8
- package/dist/services/objectstore.d.ts +0 -257
- package/dist/services/objectstore.d.ts.map +0 -1
- package/dist/services/objectstore.js +0 -422
- package/dist/services/objectstore.js.map +0 -1
- package/src/__test__/error.test.ts +0 -431
- package/src/services/__test__/keyvalue.test.ts +0 -402
- package/src/services/__test__/mock-adapter.ts +0 -114
- package/src/services/__test__/objectstore.test.ts +0 -431
- package/src/services/__test__/stream.test.ts +0 -554
- package/src/services/__test__/vector.test.ts +0 -819
- package/src/services/objectstore.ts +0 -816
|
@@ -1,554 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
import { StreamStorageService } from '../stream';
|
|
3
|
-
import { createMockAdapter } from './mock-adapter';
|
|
4
|
-
import { ServiceException } from '../exception';
|
|
5
|
-
|
|
6
|
-
describe('StreamStorageService', () => {
|
|
7
|
-
const baseUrl = 'https://api.example.com/stream';
|
|
8
|
-
|
|
9
|
-
describe('create', () => {
|
|
10
|
-
test('should create a stream with valid name', async () => {
|
|
11
|
-
const { adapter, calls } = createMockAdapter([
|
|
12
|
-
{ ok: true, data: { id: 'stream-123' } },
|
|
13
|
-
{ ok: true },
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
17
|
-
const stream = await service.create('test-stream');
|
|
18
|
-
|
|
19
|
-
expect(stream).toBeDefined();
|
|
20
|
-
expect(stream.id).toBe('stream-123');
|
|
21
|
-
expect(stream.url).toBe(`${baseUrl}/stream-123`);
|
|
22
|
-
expect(stream.bytesWritten).toBe(0);
|
|
23
|
-
expect(stream.compressed).toBe(false);
|
|
24
|
-
expect(calls[0].url).toBe(baseUrl);
|
|
25
|
-
expect(calls[0].options?.method).toBe('POST');
|
|
26
|
-
expect(calls[0].options?.contentType).toBe('application/json');
|
|
27
|
-
|
|
28
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
29
|
-
expect(body.name).toBe('test-stream');
|
|
30
|
-
expect(body.contentType).toBe('application/octet-stream');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should create a stream with metadata', async () => {
|
|
34
|
-
const { adapter, calls } = createMockAdapter([
|
|
35
|
-
{ ok: true, data: { id: 'stream-456' } },
|
|
36
|
-
{ ok: true },
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
40
|
-
const metadata = { userId: '123', type: 'video' };
|
|
41
|
-
const stream = await service.create('test-stream', { metadata });
|
|
42
|
-
|
|
43
|
-
expect(stream.id).toBe('stream-456');
|
|
44
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
45
|
-
expect(body.metadata).toEqual(metadata);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should create a stream with custom contentType', async () => {
|
|
49
|
-
const { adapter, calls } = createMockAdapter([
|
|
50
|
-
{ ok: true, data: { id: 'stream-789' } },
|
|
51
|
-
{ ok: true },
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
55
|
-
const stream = await service.create('test-stream', { contentType: 'application/json' });
|
|
56
|
-
|
|
57
|
-
expect(stream.id).toBe('stream-789');
|
|
58
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
59
|
-
expect(body.contentType).toBe('application/json');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('should create a compressed stream', async () => {
|
|
63
|
-
const { adapter } = createMockAdapter([
|
|
64
|
-
{ ok: true, data: { id: 'stream-compressed' } },
|
|
65
|
-
{ ok: true },
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
69
|
-
const stream = await service.create('test-stream', { compress: true });
|
|
70
|
-
|
|
71
|
-
expect(stream.compressed).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('should throw error for empty stream name', async () => {
|
|
75
|
-
const { adapter } = createMockAdapter([]);
|
|
76
|
-
|
|
77
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
78
|
-
|
|
79
|
-
await expect(service.create('')).rejects.toThrow(
|
|
80
|
-
'Stream name must be between 1 and 254 characters'
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should throw error for stream name too long', async () => {
|
|
85
|
-
const { adapter } = createMockAdapter([]);
|
|
86
|
-
|
|
87
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
88
|
-
const longName = 'a'.repeat(255);
|
|
89
|
-
|
|
90
|
-
await expect(service.create(longName)).rejects.toThrow(
|
|
91
|
-
'Stream name must be between 1 and 254 characters'
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('should throw ServiceException on error response', async () => {
|
|
96
|
-
const { adapter } = createMockAdapter([
|
|
97
|
-
{ ok: false, status: 500, body: { error: 'Internal Server Error' } },
|
|
98
|
-
]);
|
|
99
|
-
|
|
100
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
101
|
-
|
|
102
|
-
await expect(service.create('test-stream')).rejects.toBeInstanceOf(ServiceException);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('should set timeout signal', async () => {
|
|
106
|
-
const { adapter, calls } = createMockAdapter([
|
|
107
|
-
{ ok: true, data: { id: 'stream-123' } },
|
|
108
|
-
{ ok: true },
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
112
|
-
await service.create('test-stream');
|
|
113
|
-
|
|
114
|
-
expect(calls[0].options?.signal).toBeDefined();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('list', () => {
|
|
119
|
-
test('should list streams without filters', async () => {
|
|
120
|
-
const mockResponse = {
|
|
121
|
-
success: true,
|
|
122
|
-
streams: [
|
|
123
|
-
{
|
|
124
|
-
id: 'stream-1',
|
|
125
|
-
name: 'stream-one',
|
|
126
|
-
metadata: {},
|
|
127
|
-
url: 'https://example.com/stream-1',
|
|
128
|
-
sizeBytes: 1024,
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
total: 1,
|
|
132
|
-
};
|
|
133
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
134
|
-
|
|
135
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
136
|
-
const result = await service.list();
|
|
137
|
-
|
|
138
|
-
expect(result.success).toBe(true);
|
|
139
|
-
expect(result.streams).toHaveLength(1);
|
|
140
|
-
expect(result.total).toBe(1);
|
|
141
|
-
expect(calls).toHaveLength(1);
|
|
142
|
-
expect(calls[0].url).toBe(`${baseUrl}/list`);
|
|
143
|
-
expect(calls[0].options?.method).toBe('POST');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('should list streams with name filter', async () => {
|
|
147
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
148
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
149
|
-
|
|
150
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
151
|
-
await service.list({ name: 'test-stream' });
|
|
152
|
-
|
|
153
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
154
|
-
expect(body.name).toBe('test-stream');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('should list streams with metadata filter', async () => {
|
|
158
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
159
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
160
|
-
|
|
161
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
162
|
-
const metadata = { type: 'video' };
|
|
163
|
-
await service.list({ metadata });
|
|
164
|
-
|
|
165
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
166
|
-
expect(body.metadata).toEqual(metadata);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('should list streams with limit', async () => {
|
|
170
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
171
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
172
|
-
|
|
173
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
174
|
-
await service.list({ limit: 50 });
|
|
175
|
-
|
|
176
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
177
|
-
expect(body.limit).toBe(50);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('should list streams with offset', async () => {
|
|
181
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
182
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
183
|
-
|
|
184
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
185
|
-
await service.list({ offset: 100 });
|
|
186
|
-
|
|
187
|
-
const body = JSON.parse(calls[0].options?.body as string);
|
|
188
|
-
expect(body.offset).toBe(100);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('should throw error for invalid limit (zero)', async () => {
|
|
192
|
-
const { adapter } = createMockAdapter([]);
|
|
193
|
-
|
|
194
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
195
|
-
|
|
196
|
-
await expect(service.list({ limit: 0 })).rejects.toThrow(
|
|
197
|
-
'limit must be greater than 0 and less than or equal to 1000'
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('should throw error for invalid limit (too high)', async () => {
|
|
202
|
-
const { adapter } = createMockAdapter([]);
|
|
203
|
-
|
|
204
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
205
|
-
|
|
206
|
-
await expect(service.list({ limit: 1001 })).rejects.toThrow(
|
|
207
|
-
'limit must be greater than 0 and less than or equal to 1000'
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('should throw ServiceException on error response', async () => {
|
|
212
|
-
const { adapter } = createMockAdapter([
|
|
213
|
-
{ ok: false, status: 500, body: { error: 'Internal Server Error' } },
|
|
214
|
-
]);
|
|
215
|
-
|
|
216
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
217
|
-
|
|
218
|
-
await expect(service.list()).rejects.toBeInstanceOf(ServiceException);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('should set timeout signal', async () => {
|
|
222
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
223
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
224
|
-
|
|
225
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
226
|
-
await service.list();
|
|
227
|
-
|
|
228
|
-
expect(calls[0].options?.signal).toBeDefined();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe('delete', () => {
|
|
233
|
-
test('should delete stream by id', async () => {
|
|
234
|
-
const { adapter, calls } = createMockAdapter([{ ok: true }]);
|
|
235
|
-
|
|
236
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
237
|
-
await service.delete('stream-123');
|
|
238
|
-
|
|
239
|
-
expect(calls).toHaveLength(1);
|
|
240
|
-
expect(calls[0].url).toBe(`${baseUrl}/stream-123`);
|
|
241
|
-
expect(calls[0].options?.method).toBe('DELETE');
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test('should throw error for empty id', async () => {
|
|
245
|
-
const { adapter } = createMockAdapter([]);
|
|
246
|
-
|
|
247
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
248
|
-
|
|
249
|
-
await expect(service.delete('')).rejects.toThrow(
|
|
250
|
-
'Stream id is required and must be a non-empty string'
|
|
251
|
-
);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test('should throw error for whitespace id', async () => {
|
|
255
|
-
const { adapter } = createMockAdapter([]);
|
|
256
|
-
|
|
257
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
258
|
-
|
|
259
|
-
await expect(service.delete(' ')).rejects.toThrow(
|
|
260
|
-
'Stream id is required and must be a non-empty string'
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
test('should throw ServiceException on error response', async () => {
|
|
265
|
-
const { adapter } = createMockAdapter([
|
|
266
|
-
{ ok: false, status: 404, body: { error: 'Not Found' } },
|
|
267
|
-
]);
|
|
268
|
-
|
|
269
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
270
|
-
|
|
271
|
-
await expect(service.delete('nonexistent-stream')).rejects.toBeInstanceOf(
|
|
272
|
-
ServiceException
|
|
273
|
-
);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test('should set timeout signal', async () => {
|
|
277
|
-
const { adapter, calls } = createMockAdapter([{ ok: true }]);
|
|
278
|
-
|
|
279
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
280
|
-
await service.delete('stream-123');
|
|
281
|
-
|
|
282
|
-
expect(calls[0].options?.signal).toBeDefined();
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
describe('Stream operations', () => {
|
|
287
|
-
test('should write string data to stream', async () => {
|
|
288
|
-
const { adapter } = createMockAdapter([
|
|
289
|
-
{ ok: true, data: { id: 'stream-write' } },
|
|
290
|
-
{ ok: true },
|
|
291
|
-
]);
|
|
292
|
-
|
|
293
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
294
|
-
const stream = await service.create('test-stream');
|
|
295
|
-
|
|
296
|
-
const writePromise = stream.write('hello world');
|
|
297
|
-
const closePromise = stream.close();
|
|
298
|
-
|
|
299
|
-
await Promise.all([writePromise, closePromise]);
|
|
300
|
-
|
|
301
|
-
expect(stream.bytesWritten).toBeGreaterThan(0);
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
test('should write object data to stream', async () => {
|
|
305
|
-
const { adapter } = createMockAdapter([
|
|
306
|
-
{ ok: true, data: { id: 'stream-write' } },
|
|
307
|
-
{ ok: true },
|
|
308
|
-
]);
|
|
309
|
-
|
|
310
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
311
|
-
const stream = await service.create('test-stream');
|
|
312
|
-
|
|
313
|
-
const writePromise = stream.write({ foo: 'bar', num: 42 });
|
|
314
|
-
const closePromise = stream.close();
|
|
315
|
-
|
|
316
|
-
await Promise.all([writePromise, closePromise]);
|
|
317
|
-
|
|
318
|
-
expect(stream.bytesWritten).toBeGreaterThan(0);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
test('should write Uint8Array data to stream', async () => {
|
|
322
|
-
const { adapter } = createMockAdapter([
|
|
323
|
-
{ ok: true, data: { id: 'stream-write' } },
|
|
324
|
-
{ ok: true },
|
|
325
|
-
]);
|
|
326
|
-
|
|
327
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
328
|
-
const stream = await service.create('test-stream');
|
|
329
|
-
|
|
330
|
-
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
331
|
-
const writePromise = stream.write(data);
|
|
332
|
-
const closePromise = stream.close();
|
|
333
|
-
|
|
334
|
-
await Promise.all([writePromise, closePromise]);
|
|
335
|
-
|
|
336
|
-
expect(stream.bytesWritten).toBe(5);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
test('should write ArrayBuffer data to stream', async () => {
|
|
340
|
-
const { adapter } = createMockAdapter([
|
|
341
|
-
{ ok: true, data: { id: 'stream-write' } },
|
|
342
|
-
{ ok: true },
|
|
343
|
-
]);
|
|
344
|
-
|
|
345
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
346
|
-
const stream = await service.create('test-stream');
|
|
347
|
-
|
|
348
|
-
const buffer = new ArrayBuffer(10);
|
|
349
|
-
const writePromise = stream.write(buffer);
|
|
350
|
-
const closePromise = stream.close();
|
|
351
|
-
|
|
352
|
-
await Promise.all([writePromise, closePromise]);
|
|
353
|
-
|
|
354
|
-
expect(stream.bytesWritten).toBe(10);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
test('should handle close on already closed stream', async () => {
|
|
358
|
-
const { adapter } = createMockAdapter([
|
|
359
|
-
{ ok: true, data: { id: 'stream-close' } },
|
|
360
|
-
{ ok: true },
|
|
361
|
-
]);
|
|
362
|
-
|
|
363
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
364
|
-
const stream = await service.create('test-stream');
|
|
365
|
-
|
|
366
|
-
await stream.close();
|
|
367
|
-
await stream.close();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
test('should track bytesWritten correctly', async () => {
|
|
371
|
-
const { adapter } = createMockAdapter([
|
|
372
|
-
{ ok: true, data: { id: 'stream-bytes' } },
|
|
373
|
-
{ ok: true },
|
|
374
|
-
]);
|
|
375
|
-
|
|
376
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
377
|
-
const stream = await service.create('test-stream');
|
|
378
|
-
|
|
379
|
-
expect(stream.bytesWritten).toBe(0);
|
|
380
|
-
|
|
381
|
-
const write1 = stream.write('hello');
|
|
382
|
-
await write1;
|
|
383
|
-
const bytes1 = stream.bytesWritten;
|
|
384
|
-
expect(bytes1).toBeGreaterThan(0);
|
|
385
|
-
|
|
386
|
-
const write2 = stream.write(' world');
|
|
387
|
-
const closePromise = stream.close();
|
|
388
|
-
|
|
389
|
-
await Promise.all([write2, closePromise]);
|
|
390
|
-
const bytes2 = stream.bytesWritten;
|
|
391
|
-
expect(bytes2).toBeGreaterThan(bytes1);
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
describe('onBefore hook', () => {
|
|
396
|
-
test('should call onBefore for create operation', async () => {
|
|
397
|
-
let postCallMade = false;
|
|
398
|
-
const { adapter } = createMockAdapter(
|
|
399
|
-
[{ ok: true, data: { id: 'stream-before' } }, { ok: true }],
|
|
400
|
-
{
|
|
401
|
-
onBefore: async (url, options, invoke) => {
|
|
402
|
-
if (options.method === 'POST' && url === baseUrl) {
|
|
403
|
-
postCallMade = true;
|
|
404
|
-
}
|
|
405
|
-
await invoke();
|
|
406
|
-
},
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
|
|
410
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
411
|
-
await service.create('test-stream');
|
|
412
|
-
|
|
413
|
-
expect(postCallMade).toBe(true);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
test('should call onBefore for list operation', async () => {
|
|
417
|
-
let beforeCalled = false;
|
|
418
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
419
|
-
const { adapter } = createMockAdapter([{ ok: true, data: mockResponse }], {
|
|
420
|
-
onBefore: async (url, options, invoke) => {
|
|
421
|
-
beforeCalled = true;
|
|
422
|
-
expect(url).toBe(`${baseUrl}/list`);
|
|
423
|
-
expect(options.method).toBe('POST');
|
|
424
|
-
await invoke();
|
|
425
|
-
},
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
429
|
-
await service.list();
|
|
430
|
-
|
|
431
|
-
expect(beforeCalled).toBe(true);
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
test('should call onBefore for delete operation', async () => {
|
|
435
|
-
let beforeCalled = false;
|
|
436
|
-
const { adapter } = createMockAdapter([{ ok: true }], {
|
|
437
|
-
onBefore: async (url, options, invoke) => {
|
|
438
|
-
beforeCalled = true;
|
|
439
|
-
expect(url).toBe(`${baseUrl}/stream-123`);
|
|
440
|
-
expect(options.method).toBe('DELETE');
|
|
441
|
-
await invoke();
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
446
|
-
await service.delete('stream-123');
|
|
447
|
-
|
|
448
|
-
expect(beforeCalled).toBe(true);
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
describe('onAfter hook', () => {
|
|
453
|
-
test('should call onAfter on successful create', async () => {
|
|
454
|
-
let afterCalled = false;
|
|
455
|
-
const { adapter } = createMockAdapter(
|
|
456
|
-
[{ ok: true, data: { id: 'stream-after' } }, { ok: true }],
|
|
457
|
-
{
|
|
458
|
-
onAfter: async (response) => {
|
|
459
|
-
afterCalled = true;
|
|
460
|
-
expect(response.status).toBe(200);
|
|
461
|
-
},
|
|
462
|
-
}
|
|
463
|
-
);
|
|
464
|
-
|
|
465
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
466
|
-
await service.create('test-stream');
|
|
467
|
-
|
|
468
|
-
expect(afterCalled).toBe(true);
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
test('should call onAfter on successful list', async () => {
|
|
472
|
-
let afterCalled = false;
|
|
473
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
474
|
-
const { adapter } = createMockAdapter([{ ok: true, data: mockResponse }], {
|
|
475
|
-
onAfter: async (response) => {
|
|
476
|
-
afterCalled = true;
|
|
477
|
-
expect(response.status).toBe(200);
|
|
478
|
-
},
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
482
|
-
await service.list();
|
|
483
|
-
|
|
484
|
-
expect(afterCalled).toBe(true);
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
test('should call onAfter on error response', async () => {
|
|
488
|
-
let afterCalled = false;
|
|
489
|
-
const { adapter } = createMockAdapter(
|
|
490
|
-
[{ ok: false, status: 500, body: { error: 'Internal Server Error' } }],
|
|
491
|
-
{
|
|
492
|
-
onAfter: async (response, error) => {
|
|
493
|
-
afterCalled = true;
|
|
494
|
-
expect(response.status).toBe(500);
|
|
495
|
-
expect(error).toBeDefined();
|
|
496
|
-
},
|
|
497
|
-
}
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
501
|
-
|
|
502
|
-
try {
|
|
503
|
-
await service.create('test-stream');
|
|
504
|
-
} catch {
|
|
505
|
-
// Expected to throw
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
expect(afterCalled).toBe(true);
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
describe('telemetry attributes', () => {
|
|
513
|
-
test('should include telemetry for create operation', async () => {
|
|
514
|
-
const { adapter, calls } = createMockAdapter([
|
|
515
|
-
{ ok: true, data: { id: 'stream-123' } },
|
|
516
|
-
{ ok: true },
|
|
517
|
-
]);
|
|
518
|
-
|
|
519
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
520
|
-
await service.create('test-stream', {
|
|
521
|
-
metadata: { userId: '123' },
|
|
522
|
-
contentType: 'application/json',
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
expect(calls[0].options?.telemetry).toBeDefined();
|
|
526
|
-
expect(calls[0].options?.telemetry?.name).toBe('agentuity.stream.create');
|
|
527
|
-
expect(calls[0].options?.telemetry?.attributes?.name).toBe('test-stream');
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
test('should include telemetry for list operation', async () => {
|
|
531
|
-
const mockResponse = { success: true, streams: [], total: 0 };
|
|
532
|
-
const { adapter, calls } = createMockAdapter([{ ok: true, data: mockResponse }]);
|
|
533
|
-
|
|
534
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
535
|
-
await service.list({ name: 'test', limit: 10 });
|
|
536
|
-
|
|
537
|
-
expect(calls[0].options?.telemetry).toBeDefined();
|
|
538
|
-
expect(calls[0].options?.telemetry?.name).toBe('agentuity.stream.list');
|
|
539
|
-
expect(calls[0].options?.telemetry?.attributes?.name).toBe('test');
|
|
540
|
-
expect(calls[0].options?.telemetry?.attributes?.limit).toBe('10');
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
test('should include telemetry for delete operation', async () => {
|
|
544
|
-
const { adapter, calls } = createMockAdapter([{ ok: true }]);
|
|
545
|
-
|
|
546
|
-
const service = new StreamStorageService(baseUrl, adapter);
|
|
547
|
-
await service.delete('stream-123');
|
|
548
|
-
|
|
549
|
-
expect(calls[0].options?.telemetry).toBeDefined();
|
|
550
|
-
expect(calls[0].options?.telemetry?.name).toBe('agentuity.stream.delete');
|
|
551
|
-
expect(calls[0].options?.telemetry?.attributes?.['stream.id']).toBe('stream-123');
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
});
|