@agentuity/core 0.0.60 → 0.0.62

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 (60) hide show
  1. package/dist/error.d.ts +90 -0
  2. package/dist/error.d.ts.map +1 -0
  3. package/dist/error.js +258 -0
  4. package/dist/error.js.map +1 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/json.d.ts +1 -1
  10. package/dist/json.d.ts.map +1 -1
  11. package/dist/json.js +2 -2
  12. package/dist/json.js.map +1 -1
  13. package/dist/services/_util.d.ts +2 -6
  14. package/dist/services/_util.d.ts.map +1 -1
  15. package/dist/services/_util.js +56 -8
  16. package/dist/services/_util.js.map +1 -1
  17. package/dist/services/adapter.d.ts +2 -1
  18. package/dist/services/adapter.d.ts.map +1 -1
  19. package/dist/services/exception.d.ts +20 -6
  20. package/dist/services/exception.d.ts.map +1 -1
  21. package/dist/services/exception.js +2 -11
  22. package/dist/services/exception.js.map +1 -1
  23. package/dist/services/index.d.ts +0 -1
  24. package/dist/services/index.d.ts.map +1 -1
  25. package/dist/services/keyvalue.d.ts.map +1 -1
  26. package/dist/services/keyvalue.js +5 -1
  27. package/dist/services/keyvalue.js.map +1 -1
  28. package/dist/services/objectstore.d.ts.map +1 -1
  29. package/dist/services/objectstore.js +65 -26
  30. package/dist/services/objectstore.js.map +1 -1
  31. package/dist/services/session.d.ts +2 -0
  32. package/dist/services/session.d.ts.map +1 -1
  33. package/dist/services/session.js +1 -0
  34. package/dist/services/session.js.map +1 -1
  35. package/dist/services/stream.d.ts.map +1 -1
  36. package/dist/services/stream.js +25 -9
  37. package/dist/services/stream.js.map +1 -1
  38. package/dist/services/vector.d.ts.map +1 -1
  39. package/dist/services/vector.js +48 -30
  40. package/dist/services/vector.js.map +1 -1
  41. package/dist/workbench-config.d.ts +38 -0
  42. package/dist/workbench-config.d.ts.map +1 -1
  43. package/dist/workbench-config.js +7 -5
  44. package/dist/workbench-config.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/__test__/error.test.ts +431 -0
  47. package/src/error.ts +384 -0
  48. package/src/index.ts +1 -0
  49. package/src/json.ts +2 -2
  50. package/src/services/__test__/vector.test.ts +20 -14
  51. package/src/services/_util.ts +56 -18
  52. package/src/services/adapter.ts +3 -1
  53. package/src/services/exception.ts +7 -9
  54. package/src/services/index.ts +0 -1
  55. package/src/services/keyvalue.ts +6 -1
  56. package/src/services/objectstore.ts +79 -44
  57. package/src/services/session.ts +1 -0
  58. package/src/services/stream.ts +45 -11
  59. package/src/services/vector.ts +99 -30
  60. package/src/workbench-config.ts +16 -5
@@ -1,6 +1,7 @@
1
1
  import { FetchAdapter } from './adapter';
2
2
  import { buildUrl, toServiceException } from './_util';
3
3
  import { safeStringify } from '../json';
4
+ import { StructuredError } from '../error';
4
5
 
5
6
  /**
6
7
  * Base properties shared by all vector upsert operations
@@ -379,6 +380,70 @@ interface VectorDeleteErrorResponse {
379
380
 
380
381
  type VectorDeleteResponse = VectorDeleteSuccessResponse | VectorDeleteErrorResponse;
381
382
 
383
+ const VectorStorageNameRequiredError = StructuredError(
384
+ 'VectorStorageNameRequiredError',
385
+ 'Vector storage name is required and must be a non-empty string'
386
+ );
387
+
388
+ const VectorStorageKeyRequiredError = StructuredError(
389
+ 'VectorStorageKeyRequiredError',
390
+ 'Vector storage key is required and must be a non-empty string'
391
+ );
392
+
393
+ const VectorStorageKeysError = StructuredError(
394
+ 'VectorStorageKeysError',
395
+ 'Vector storage requires all keys to be non-empty strings'
396
+ );
397
+
398
+ const VectorStorageQueryError = StructuredError(
399
+ 'VectorStorageQueryError',
400
+ 'Vector storage query property is required and must be a non-empty string'
401
+ );
402
+
403
+ const VectorStorageLimitError = StructuredError(
404
+ 'VectorStorageLimitError',
405
+ 'Vector storage limit property must be positive number'
406
+ );
407
+
408
+ const VectorStorageSimilarityError = StructuredError(
409
+ 'VectorStorageSimilarityError',
410
+ 'Vector storage similarity property must be a number between 0.0 and 1.0'
411
+ );
412
+
413
+ const VectorStorageMetadataError = StructuredError(
414
+ 'VectorStorageMetadataError',
415
+ 'Vector storage metadata property must be a valid object'
416
+ );
417
+
418
+ const VectorStorageDocumentRequiredError = StructuredError(
419
+ 'VectorStorageDocumentRequiredError',
420
+ 'Vector storage requires at least one document for this method'
421
+ );
422
+
423
+ const VectorStorageDocumentKeyMissingError = StructuredError(
424
+ 'VectorStorageDocumentKeyMissingError',
425
+ 'Vector storage requires each document to have a non-empty key'
426
+ );
427
+
428
+ const VectorStorageInvalidError = StructuredError(
429
+ 'VectorStorageInvalidError',
430
+ 'Vector storage requires each document to have either embeddings or document property'
431
+ );
432
+
433
+ const VectorStorageEmbeddingInvalidError = StructuredError(
434
+ 'VectorStorageEmbeddingInvalidError',
435
+ 'Vector storage requires each embeddings property to have a non-empty array of numbers'
436
+ );
437
+
438
+ const VectorStorageDocumentInvalidError = StructuredError(
439
+ 'VectorStorageDocumentInvalidError',
440
+ 'Vector storage requires each document property to have a non-empty string value'
441
+ );
442
+
443
+ const VectorStorageResponseError = StructuredError('VectorStorageResponseError')<{
444
+ status: number;
445
+ }>();
446
+
382
447
  export class VectorStorageService implements VectorStorage {
383
448
  #adapter: FetchAdapter;
384
449
  #baseUrl: string;
@@ -390,31 +455,31 @@ export class VectorStorageService implements VectorStorage {
390
455
 
391
456
  async upsert(name: string, ...documents: VectorUpsertParams[]): Promise<VectorUpsertResult[]> {
392
457
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
393
- throw new Error('Vector storage name is required and must be a non-empty string');
458
+ throw new VectorStorageNameRequiredError();
394
459
  }
395
460
 
396
461
  if (!documents || documents.length === 0) {
397
- throw new Error('At least one document is required for upsert');
462
+ throw new VectorStorageDocumentRequiredError();
398
463
  }
399
464
 
400
465
  for (const doc of documents) {
401
466
  if (!doc.key || typeof doc.key !== 'string' || doc.key.trim().length === 0) {
402
- throw new Error('Each document must have a non-empty key');
467
+ throw new VectorStorageDocumentKeyMissingError();
403
468
  }
404
469
 
405
470
  if (!('embeddings' in doc) && !('document' in doc)) {
406
- throw new Error('Each document must have either embeddings or document text');
471
+ throw new VectorStorageInvalidError();
407
472
  }
408
473
 
409
474
  if ('embeddings' in doc && doc.embeddings) {
410
475
  if (!Array.isArray(doc.embeddings) || doc.embeddings.length === 0) {
411
- throw new Error('Embeddings must be a non-empty array of numbers');
476
+ throw new VectorStorageEmbeddingInvalidError();
412
477
  }
413
478
  }
414
479
 
415
480
  if ('document' in doc && doc.document) {
416
481
  if (typeof doc.document !== 'string' || doc.document.trim().length === 0) {
417
- throw new Error('Document must be a non-empty string');
482
+ throw new VectorStorageDocumentInvalidError();
418
483
  }
419
484
  }
420
485
  }
@@ -443,9 +508,10 @@ export class VectorStorageService implements VectorStorage {
443
508
  id: o.id,
444
509
  }));
445
510
  }
446
- if ('message' in res.data) {
447
- throw new Error(res.data.message);
448
- }
511
+ throw new VectorStorageResponseError({
512
+ status: res.response.status,
513
+ message: res.data.message,
514
+ });
449
515
  }
450
516
 
451
517
  throw await toServiceException('PUT', url, res.response);
@@ -456,11 +522,11 @@ export class VectorStorageService implements VectorStorage {
456
522
  key: string
457
523
  ): Promise<VectorResult<T>> {
458
524
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
459
- throw new Error('Vector storage name is required and must be a non-empty string');
525
+ throw new VectorStorageNameRequiredError();
460
526
  }
461
527
 
462
528
  if (!key || typeof key !== 'string' || key.trim().length === 0) {
463
- throw new Error('Key is required and must be a non-empty string');
529
+ throw new VectorStorageKeyRequiredError();
464
530
  }
465
531
 
466
532
  const url = buildUrl(
@@ -492,9 +558,10 @@ export class VectorStorageService implements VectorStorage {
492
558
  exists: true,
493
559
  };
494
560
  }
495
- if ('message' in res.data) {
496
- throw new Error(res.data.message);
497
- }
561
+ throw new VectorStorageResponseError({
562
+ status: res.response.status,
563
+ message: res.data.message,
564
+ });
498
565
  }
499
566
 
500
567
  throw await toServiceException('GET', url, res.response);
@@ -505,7 +572,7 @@ export class VectorStorageService implements VectorStorage {
505
572
  ...keys: string[]
506
573
  ): Promise<Map<string, VectorSearchResultWithDocument<T>>> {
507
574
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
508
- throw new Error('Vector storage name is required and must be a non-empty string');
575
+ throw new VectorStorageNameRequiredError();
509
576
  }
510
577
 
511
578
  if (keys.length === 0) {
@@ -514,7 +581,7 @@ export class VectorStorageService implements VectorStorage {
514
581
 
515
582
  for (const key of keys) {
516
583
  if (!key || typeof key !== 'string' || key.trim().length === 0) {
517
- throw new Error('All keys must be non-empty strings');
584
+ throw new VectorStorageKeysError();
518
585
  }
519
586
  }
520
587
 
@@ -535,16 +602,16 @@ export class VectorStorageService implements VectorStorage {
535
602
  params: VectorSearchParams<T>
536
603
  ): Promise<VectorSearchResult<T>[]> {
537
604
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
538
- throw new Error('Vector storage name is required and must be a non-empty string');
605
+ throw new VectorStorageNameRequiredError();
539
606
  }
540
607
 
541
608
  if (!params.query || typeof params.query !== 'string' || params.query.trim().length === 0) {
542
- throw new Error('Query is required and must be a non-empty string');
609
+ throw new VectorStorageQueryError();
543
610
  }
544
611
 
545
612
  if (params.limit !== undefined) {
546
613
  if (typeof params.limit !== 'number' || params.limit <= 0) {
547
- throw new Error('Limit must be a positive number');
614
+ throw new VectorStorageLimitError();
548
615
  }
549
616
  }
550
617
 
@@ -554,13 +621,13 @@ export class VectorStorageService implements VectorStorage {
554
621
  params.similarity < 0 ||
555
622
  params.similarity > 1
556
623
  ) {
557
- throw new Error('Similarity must be a number between 0.0 and 1.0');
624
+ throw new VectorStorageSimilarityError();
558
625
  }
559
626
  }
560
627
 
561
628
  if (params.metadata !== undefined) {
562
629
  if (typeof params.metadata !== 'object' || params.metadata === null) {
563
- throw new Error('Metadata must be a valid object');
630
+ throw new VectorStorageMetadataError();
564
631
  }
565
632
  }
566
633
 
@@ -597,9 +664,10 @@ export class VectorStorageService implements VectorStorage {
597
664
  if (res.data.success) {
598
665
  return res.data.data as VectorSearchResult<T>[];
599
666
  }
600
- if ('message' in res.data) {
601
- throw new Error(res.data.message);
602
- }
667
+ throw new VectorStorageResponseError({
668
+ status: res.response.status,
669
+ message: res.data.message,
670
+ });
603
671
  }
604
672
 
605
673
  throw await toServiceException('POST', url, res.response);
@@ -607,7 +675,7 @@ export class VectorStorageService implements VectorStorage {
607
675
 
608
676
  async delete(name: string, ...keys: string[]): Promise<number> {
609
677
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
610
- throw new Error('Vector storage name is required and must be a non-empty string');
678
+ throw new VectorStorageNameRequiredError();
611
679
  }
612
680
 
613
681
  if (keys.length === 0) {
@@ -616,7 +684,7 @@ export class VectorStorageService implements VectorStorage {
616
684
 
617
685
  for (const key of keys) {
618
686
  if (!key || typeof key !== 'string' || key.trim().length === 0) {
619
- throw new Error('All keys must be non-empty strings');
687
+ throw new VectorStorageKeysError();
620
688
  }
621
689
  }
622
690
 
@@ -656,9 +724,10 @@ export class VectorStorageService implements VectorStorage {
656
724
  if (res.data.success) {
657
725
  return res.data.data;
658
726
  }
659
- if ('message' in res.data) {
660
- throw new Error(res.data.message);
661
- }
727
+ throw new VectorStorageResponseError({
728
+ status: res.response.status,
729
+ message: res.data.message,
730
+ });
662
731
  }
663
732
 
664
733
  throw await toServiceException('DELETE', url, res.response);
@@ -666,7 +735,7 @@ export class VectorStorageService implements VectorStorage {
666
735
 
667
736
  async exists(name: string): Promise<boolean> {
668
737
  if (!name || typeof name !== 'string' || name.trim().length === 0) {
669
- throw new Error('Vector storage name is required and must be a non-empty string');
738
+ throw new VectorStorageNameRequiredError();
670
739
  }
671
740
 
672
741
  try {
@@ -1,3 +1,15 @@
1
+ import { StructuredError } from './error';
2
+
3
+ export const WorkbenchConfigError = StructuredError(
4
+ 'WorkbenchConfigError',
5
+ 'The workbench configuration is invalid'
6
+ );
7
+
8
+ export const WorkbenchNotFoundError = StructuredError(
9
+ 'WorkbenchNotFoundError',
10
+ 'Workbench config not found - build process did not inline config'
11
+ );
12
+
1
13
  /**
2
14
  * Workbench configuration utilities shared across packages
3
15
  */
@@ -44,10 +56,9 @@ export function decodeWorkbenchConfig(encoded: string): WorkbenchConfig {
44
56
  const config = JSON.parse(json) as WorkbenchConfig;
45
57
  return config;
46
58
  } catch (error) {
47
- throw new Error(
48
- `Failed to decode workbench config: ${error instanceof Error ? error.message : String(error)}`,
49
- { cause: error }
50
- );
59
+ throw new WorkbenchConfigError({
60
+ cause: error,
61
+ });
51
62
  }
52
63
  }
53
64
 
@@ -59,7 +70,7 @@ export function getWorkbenchConfig(): WorkbenchConfig {
59
70
  // This will be replaced at build time by Bun's define mechanism
60
71
  // @ts-expect-error - AGENTUITY_WORKBENCH_CONFIG_INLINE will be replaced at build time
61
72
  if (typeof AGENTUITY_WORKBENCH_CONFIG_INLINE === 'undefined') {
62
- throw new Error('Workbench config not found - build process did not inline config');
73
+ throw new WorkbenchNotFoundError();
63
74
  }
64
75
 
65
76
  // @ts-expect-error - AGENTUITY_WORKBENCH_CONFIG_INLINE will be replaced at build time