@agentuity/core 0.0.60 → 0.0.61
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/error.d.ts +90 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +258 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +2 -2
- package/dist/json.js.map +1 -1
- package/dist/services/_util.d.ts +2 -6
- package/dist/services/_util.d.ts.map +1 -1
- package/dist/services/_util.js +56 -8
- package/dist/services/_util.js.map +1 -1
- package/dist/services/adapter.d.ts +2 -1
- package/dist/services/adapter.d.ts.map +1 -1
- package/dist/services/exception.d.ts +20 -6
- package/dist/services/exception.d.ts.map +1 -1
- package/dist/services/exception.js +2 -11
- package/dist/services/exception.js.map +1 -1
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/keyvalue.d.ts.map +1 -1
- package/dist/services/keyvalue.js +5 -1
- package/dist/services/keyvalue.js.map +1 -1
- package/dist/services/objectstore.d.ts.map +1 -1
- package/dist/services/objectstore.js +65 -26
- package/dist/services/objectstore.js.map +1 -1
- package/dist/services/stream.d.ts.map +1 -1
- package/dist/services/stream.js +25 -9
- package/dist/services/stream.js.map +1 -1
- package/dist/services/vector.d.ts.map +1 -1
- package/dist/services/vector.js +48 -30
- package/dist/services/vector.js.map +1 -1
- package/dist/workbench-config.d.ts +38 -0
- package/dist/workbench-config.d.ts.map +1 -1
- package/dist/workbench-config.js +7 -5
- package/dist/workbench-config.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/error.test.ts +431 -0
- package/src/error.ts +384 -0
- package/src/index.ts +1 -0
- package/src/json.ts +2 -2
- package/src/services/__test__/vector.test.ts +20 -14
- package/src/services/_util.ts +56 -18
- package/src/services/adapter.ts +3 -1
- package/src/services/exception.ts +7 -9
- package/src/services/index.ts +0 -1
- package/src/services/keyvalue.ts +6 -1
- package/src/services/objectstore.ts +79 -44
- package/src/services/stream.ts +45 -11
- package/src/services/vector.ts +99 -30
- package/src/workbench-config.ts +16 -5
package/src/services/vector.ts
CHANGED
|
@@ -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
|
|
458
|
+
throw new VectorStorageNameRequiredError();
|
|
394
459
|
}
|
|
395
460
|
|
|
396
461
|
if (!documents || documents.length === 0) {
|
|
397
|
-
throw new
|
|
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
|
|
467
|
+
throw new VectorStorageDocumentKeyMissingError();
|
|
403
468
|
}
|
|
404
469
|
|
|
405
470
|
if (!('embeddings' in doc) && !('document' in doc)) {
|
|
406
|
-
throw new
|
|
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
|
|
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
|
|
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
|
-
|
|
447
|
-
|
|
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
|
|
525
|
+
throw new VectorStorageNameRequiredError();
|
|
460
526
|
}
|
|
461
527
|
|
|
462
528
|
if (!key || typeof key !== 'string' || key.trim().length === 0) {
|
|
463
|
-
throw new
|
|
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
|
-
|
|
496
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
601
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
660
|
-
|
|
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
|
|
738
|
+
throw new VectorStorageNameRequiredError();
|
|
670
739
|
}
|
|
671
740
|
|
|
672
741
|
try {
|
package/src/workbench-config.ts
CHANGED
|
@@ -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
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
73
|
+
throw new WorkbenchNotFoundError();
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
// @ts-expect-error - AGENTUITY_WORKBENCH_CONFIG_INLINE will be replaced at build time
|