@agtlantis/core 0.5.0 → 0.6.0
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/README.md +18 -5
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +69 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +116 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/errors/utils.d.ts +17 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +16 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/execution/constants.d.ts +7 -0
- package/dist/execution/constants.d.ts.map +1 -0
- package/dist/execution/constants.js +7 -0
- package/dist/execution/constants.js.map +1 -0
- package/dist/execution/index.d.ts +8 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/mapping.d.ts +17 -0
- package/dist/execution/mapping.d.ts.map +1 -0
- package/dist/execution/mapping.js +197 -0
- package/dist/execution/mapping.js.map +1 -0
- package/dist/execution/shared.d.ts +86 -0
- package/dist/execution/shared.d.ts.map +1 -0
- package/dist/execution/shared.js +100 -0
- package/dist/execution/shared.js.map +1 -0
- package/dist/execution/simple-host.d.ts +56 -0
- package/dist/execution/simple-host.d.ts.map +1 -0
- package/dist/execution/simple-host.js +126 -0
- package/dist/execution/simple-host.js.map +1 -0
- package/dist/execution/streaming-host.d.ts +79 -0
- package/dist/execution/streaming-host.d.ts.map +1 -0
- package/dist/execution/streaming-host.js +276 -0
- package/dist/execution/streaming-host.js.map +1 -0
- package/dist/execution/testing/fixtures.d.ts +67 -0
- package/dist/execution/testing/fixtures.d.ts.map +1 -0
- package/dist/execution/testing/fixtures.js +145 -0
- package/dist/execution/testing/fixtures.js.map +1 -0
- package/dist/execution/testing/helpers.d.ts +218 -0
- package/dist/execution/testing/helpers.d.ts.map +1 -0
- package/dist/execution/testing/helpers.js +327 -0
- package/dist/execution/testing/helpers.js.map +1 -0
- package/dist/execution/testing/host-configs.d.ts +56 -0
- package/dist/execution/testing/host-configs.d.ts.map +1 -0
- package/dist/execution/testing/host-configs.js +154 -0
- package/dist/execution/testing/host-configs.js.map +1 -0
- package/dist/execution/testing/vitest-assertions.d.ts +102 -0
- package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
- package/dist/execution/testing/vitest-assertions.js +142 -0
- package/dist/execution/testing/vitest-assertions.js.map +1 -0
- package/dist/execution/types.d.ts +432 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +2 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/utils.d.ts +68 -0
- package/dist/execution/utils.d.ts.map +1 -0
- package/dist/execution/utils.js +93 -0
- package/dist/execution/utils.js.map +1 -0
- package/dist/index.d.ts +10 -1506
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2979
- package/dist/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +2 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +161 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +31 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/types.d.ts +46 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +2 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/patterns/index.d.ts +2 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +2 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/progressive/index.d.ts +2 -0
- package/dist/patterns/progressive/index.d.ts.map +1 -0
- package/dist/patterns/progressive/index.js +2 -0
- package/dist/patterns/progressive/index.js.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.js +260 -0
- package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
- package/dist/pricing/calculator.d.ts +71 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +127 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/config.d.ts +61 -0
- package/dist/pricing/config.d.ts.map +1 -0
- package/dist/pricing/config.js +87 -0
- package/dist/pricing/config.js.map +1 -0
- package/dist/pricing/defaults.d.ts +29 -0
- package/dist/pricing/defaults.d.ts.map +1 -0
- package/dist/pricing/defaults.js +139 -0
- package/dist/pricing/defaults.js.map +1 -0
- package/dist/pricing/index.d.ts +40 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +43 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/types.d.ts +96 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +7 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/pricing/validator.d.ts +55 -0
- package/dist/pricing/validator.d.ts.map +1 -0
- package/dist/pricing/validator.js +84 -0
- package/dist/pricing/validator.js.map +1 -0
- package/dist/prompt/errors.d.ts +112 -0
- package/dist/prompt/errors.d.ts.map +1 -0
- package/dist/prompt/errors.js +174 -0
- package/dist/prompt/errors.js.map +1 -0
- package/dist/prompt/file-prompt-repository.d.ts +80 -0
- package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
- package/dist/prompt/file-prompt-repository.js +287 -0
- package/dist/prompt/file-prompt-repository.js.map +1 -0
- package/dist/prompt/index.d.ts +34 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +37 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/prompt-template.d.ts +64 -0
- package/dist/prompt/prompt-template.d.ts.map +1 -0
- package/dist/prompt/prompt-template.js +90 -0
- package/dist/prompt/prompt-template.js.map +1 -0
- package/dist/prompt/template.d.ts +23 -0
- package/dist/prompt/template.d.ts.map +1 -0
- package/dist/prompt/template.js +70 -0
- package/dist/prompt/template.js.map +1 -0
- package/dist/prompt/types.d.ts +148 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +7 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/provider/base-file-manager.d.ts +14 -0
- package/dist/provider/base-file-manager.d.ts.map +1 -0
- package/dist/provider/base-file-manager.js +91 -0
- package/dist/provider/base-file-manager.js.map +1 -0
- package/dist/provider/base-provider.d.ts +41 -0
- package/dist/provider/base-provider.d.ts.map +1 -0
- package/dist/provider/base-provider.js +21 -0
- package/dist/provider/base-provider.js.map +1 -0
- package/dist/provider/file-cache.d.ts +14 -0
- package/dist/provider/file-cache.d.ts.map +1 -0
- package/dist/provider/file-cache.js +29 -0
- package/dist/provider/file-cache.js.map +1 -0
- package/dist/provider/file-source.d.ts +32 -0
- package/dist/provider/file-source.d.ts.map +1 -0
- package/dist/provider/file-source.js +180 -0
- package/dist/provider/file-source.js.map +1 -0
- package/dist/provider/file-utils.d.ts +5 -0
- package/dist/provider/file-utils.d.ts.map +1 -0
- package/dist/provider/file-utils.js +15 -0
- package/dist/provider/file-utils.js.map +1 -0
- package/dist/provider/google/factory.d.ts +107 -0
- package/dist/provider/google/factory.d.ts.map +1 -0
- package/dist/provider/google/factory.js +143 -0
- package/dist/provider/google/factory.js.map +1 -0
- package/dist/provider/google/file-manager.d.ts +10 -0
- package/dist/provider/google/file-manager.d.ts.map +1 -0
- package/dist/provider/google/file-manager.js +93 -0
- package/dist/provider/google/file-manager.js.map +1 -0
- package/dist/provider/google/index.d.ts +8 -0
- package/dist/provider/google/index.d.ts.map +1 -0
- package/dist/provider/google/index.js +10 -0
- package/dist/provider/google/index.js.map +1 -0
- package/dist/provider/hash.d.ts +3 -0
- package/dist/provider/hash.d.ts.map +1 -0
- package/dist/provider/hash.js +34 -0
- package/dist/provider/hash.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +12 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/noop-file-manager.d.ts +9 -0
- package/dist/provider/noop-file-manager.d.ts.map +1 -0
- package/dist/provider/noop-file-manager.js +28 -0
- package/dist/provider/noop-file-manager.js.map +1 -0
- package/dist/provider/openai/factory.d.ts +67 -0
- package/dist/provider/openai/factory.d.ts.map +1 -0
- package/dist/provider/openai/factory.js +100 -0
- package/dist/provider/openai/factory.js.map +1 -0
- package/dist/provider/openai/file-manager.d.ts +17 -0
- package/dist/provider/openai/file-manager.d.ts.map +1 -0
- package/dist/provider/openai/file-manager.js +108 -0
- package/dist/provider/openai/file-manager.js.map +1 -0
- package/dist/provider/openai/index.d.ts +8 -0
- package/dist/provider/openai/index.d.ts.map +1 -0
- package/dist/provider/openai/index.js +8 -0
- package/dist/provider/openai/index.js.map +1 -0
- package/dist/provider/types.d.ts +105 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +19 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/simple-session.d.ts +98 -0
- package/dist/session/simple-session.d.ts.map +1 -0
- package/dist/session/simple-session.js +299 -0
- package/dist/session/simple-session.js.map +1 -0
- package/dist/session/streaming-session.d.ts +90 -0
- package/dist/session/streaming-session.d.ts.map +1 -0
- package/dist/session/streaming-session.js +151 -0
- package/dist/session/streaming-session.js.map +1 -0
- package/dist/session/test-utils.d.ts +19 -0
- package/dist/session/test-utils.d.ts.map +1 -0
- package/dist/session/test-utils.js +65 -0
- package/dist/session/test-utils.js.map +1 -0
- package/dist/session/types.d.ts +219 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +181 -0
- package/dist/session/types.js.map +1 -0
- package/dist/session/usage-extractors.d.ts +7 -0
- package/dist/session/usage-extractors.d.ts.map +1 -0
- package/dist/session/usage-extractors.js +71 -0
- package/dist/session/usage-extractors.js.map +1 -0
- package/dist/testing/fixtures.d.ts +34 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +65 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +20 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +32 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +7 -519
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +21 -2123
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock-provider.d.ts +79 -0
- package/dist/testing/mock-provider.d.ts.map +1 -0
- package/dist/testing/mock-provider.js +152 -0
- package/dist/testing/mock-provider.js.map +1 -0
- package/dist/testing/mock.d.ts +29 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +154 -0
- package/dist/testing/mock.js.map +1 -0
- package/dist/testing/test-execution.d.ts +14 -0
- package/dist/testing/test-execution.d.ts.map +1 -0
- package/dist/testing/test-execution.js +108 -0
- package/dist/testing/test-execution.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +6 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +24 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/validation/errors.d.ts +28 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/errors.js +38 -0
- package/dist/validation/errors.js.map +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +4 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +49 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/dist/validation/validation-history.d.ts +12 -0
- package/dist/validation/validation-history.d.ts.map +1 -0
- package/dist/validation/validation-history.js +29 -0
- package/dist/validation/validation-history.js.map +1 -0
- package/dist/validation/with-validation.d.ts +38 -0
- package/dist/validation/with-validation.d.ts.map +1 -0
- package/dist/validation/with-validation.js +58 -0
- package/dist/validation/with-validation.js.map +1 -0
- package/package.json +71 -75
- package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
- package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
- package/dist/index.cjs +0 -3085
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1506
- package/dist/testing/index.cjs +0 -2167
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -520
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
reason?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ValidationAttempt<TResult> extends ValidationResult {
|
|
6
|
+
result: TResult;
|
|
7
|
+
attempt: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ReadonlyValidationHistory<TResult> {
|
|
10
|
+
/** 1-based attempt number for the next attempt. */
|
|
11
|
+
readonly nextAttempt: number;
|
|
12
|
+
/** Last validation attempt, or undefined if no attempts yet. */
|
|
13
|
+
readonly last: ValidationAttempt<TResult> | undefined;
|
|
14
|
+
/** All validation attempts as a readonly array. */
|
|
15
|
+
readonly all: readonly ValidationAttempt<TResult>[];
|
|
16
|
+
/** Reasons from all failed attempts. */
|
|
17
|
+
readonly failureReasons: string[];
|
|
18
|
+
/** True if at least one previous attempt exists. */
|
|
19
|
+
readonly isRetry: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ValidationOptions<TResult> {
|
|
22
|
+
/**
|
|
23
|
+
* Validation function that checks the result.
|
|
24
|
+
* Can access history to compare with previous attempts.
|
|
25
|
+
*/
|
|
26
|
+
validate: (result: TResult, history: ReadonlyValidationHistory<TResult>) => ValidationResult | Promise<ValidationResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of attempts before throwing ValidationExhaustedError.
|
|
29
|
+
* @default 3
|
|
30
|
+
* @minimum 1
|
|
31
|
+
*/
|
|
32
|
+
maxAttempts?: number;
|
|
33
|
+
/**
|
|
34
|
+
* AbortSignal for cancellation support.
|
|
35
|
+
* When aborted, throws the abort reason before the next attempt.
|
|
36
|
+
*/
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/**
|
|
39
|
+
* Delay between retry attempts in milliseconds.
|
|
40
|
+
* Only applied when there will be another attempt after a failure.
|
|
41
|
+
*/
|
|
42
|
+
retryDelay?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Callback invoked after each attempt (success or failure).
|
|
45
|
+
* Useful for logging or progress tracking.
|
|
46
|
+
*/
|
|
47
|
+
onAttempt?: (attempt: ValidationAttempt<TResult>) => void;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB,CAAC,OAAO,CAAE,SAAQ,gBAAgB;IAClE,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB,CAAC,OAAO;IAChD,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEtD,mDAAmD;IACnD,QAAQ,CAAC,GAAG,EAAE,SAAS,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;IAEpD,wCAAwC;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAElC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC;;;OAGG;IACH,QAAQ,EAAE,CACR,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,KACxC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAElD;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationAttempt, ReadonlyValidationHistory } from './types.js';
|
|
2
|
+
export declare class ValidationHistory<TResult> implements ReadonlyValidationHistory<TResult> {
|
|
3
|
+
private attempts;
|
|
4
|
+
get nextAttempt(): number;
|
|
5
|
+
get last(): ValidationAttempt<TResult> | undefined;
|
|
6
|
+
get all(): readonly ValidationAttempt<TResult>[];
|
|
7
|
+
get failureReasons(): string[];
|
|
8
|
+
get isRetry(): boolean;
|
|
9
|
+
/** Internal use only - not exposed via ReadonlyValidationHistory. */
|
|
10
|
+
add(result: TResult, validation: ValidationResult): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=validation-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-history.d.ts","sourceRoot":"","sources":["../../src/validation/validation-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB,qBAAa,iBAAiB,CAAC,OAAO,CACpC,YAAW,yBAAyB,CAAC,OAAO,CAAC;IAE7C,OAAO,CAAC,QAAQ,CAAoC;IAEpD,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS,CAEjD;IAED,IAAI,GAAG,IAAI,SAAS,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAE/C;IAED,IAAI,cAAc,IAAI,MAAM,EAAE,CAI7B;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,qEAAqE;IACrE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAMvD;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class ValidationHistory {
|
|
2
|
+
attempts = [];
|
|
3
|
+
get nextAttempt() {
|
|
4
|
+
return this.attempts.length + 1;
|
|
5
|
+
}
|
|
6
|
+
get last() {
|
|
7
|
+
return this.attempts.at(-1);
|
|
8
|
+
}
|
|
9
|
+
get all() {
|
|
10
|
+
return this.attempts;
|
|
11
|
+
}
|
|
12
|
+
get failureReasons() {
|
|
13
|
+
return this.attempts
|
|
14
|
+
.filter((a) => !a.valid && a.reason)
|
|
15
|
+
.map((a) => a.reason);
|
|
16
|
+
}
|
|
17
|
+
get isRetry() {
|
|
18
|
+
return this.attempts.length > 0;
|
|
19
|
+
}
|
|
20
|
+
/** Internal use only - not exposed via ReadonlyValidationHistory. */
|
|
21
|
+
add(result, validation) {
|
|
22
|
+
this.attempts.push({
|
|
23
|
+
result,
|
|
24
|
+
...validation,
|
|
25
|
+
attempt: this.attempts.length + 1,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=validation-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-history.js","sourceRoot":"","sources":["../../src/validation/validation-history.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,iBAAiB;IAGpB,QAAQ,GAAiC,EAAE,CAAC;IAEpD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,QAAQ;aACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAO,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,qEAAqE;IACrE,GAAG,CAAC,MAAe,EAAE,UAA4B;QAC/C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM;YACN,GAAG,UAAU;YACb,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;SAClC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ReadonlyValidationHistory, ValidationOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an async operation with validation and retry logic.
|
|
4
|
+
*
|
|
5
|
+
* Executes the function and validates the result. If validation fails,
|
|
6
|
+
* retries up to maxAttempts times, passing the history to the execute
|
|
7
|
+
* function so it can adjust its approach based on previous failures.
|
|
8
|
+
*
|
|
9
|
+
* @param execute - Function to execute. Receives history for retry context.
|
|
10
|
+
* @param options - Validation options including the validate function.
|
|
11
|
+
* @returns The first result that passes validation.
|
|
12
|
+
* @throws {ValidationExhaustedError} If all attempts fail validation.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const result = await withValidation(
|
|
17
|
+
* (history) => session.generateText({
|
|
18
|
+
* messages: [
|
|
19
|
+
* { role: 'user', content: prompt },
|
|
20
|
+
* ...(history.isRetry ? [{
|
|
21
|
+
* role: 'user' as const,
|
|
22
|
+
* content: `Fix: ${history.last!.reason}`,
|
|
23
|
+
* }] : []),
|
|
24
|
+
* ],
|
|
25
|
+
* schema,
|
|
26
|
+
* }),
|
|
27
|
+
* {
|
|
28
|
+
* validate: (result) => ({
|
|
29
|
+
* valid: result.confidence > 0.8,
|
|
30
|
+
* reason: `Confidence ${result.confidence} below 0.8`,
|
|
31
|
+
* }),
|
|
32
|
+
* maxAttempts: 3,
|
|
33
|
+
* }
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function withValidation<TResult>(execute: (history: ReadonlyValidationHistory<NoInfer<TResult>>) => Promise<TResult>, options: ValidationOptions<NoInfer<TResult>>): Promise<TResult>;
|
|
38
|
+
//# sourceMappingURL=with-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-validation.d.ts","sourceRoot":"","sources":["../../src/validation/with-validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAI/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAC1C,OAAO,EAAE,CAAC,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,EACnF,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAC3C,OAAO,CAAC,OAAO,CAAC,CA4BlB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ValidationHistory } from './validation-history.js';
|
|
2
|
+
import { ValidationExhaustedError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an async operation with validation and retry logic.
|
|
5
|
+
*
|
|
6
|
+
* Executes the function and validates the result. If validation fails,
|
|
7
|
+
* retries up to maxAttempts times, passing the history to the execute
|
|
8
|
+
* function so it can adjust its approach based on previous failures.
|
|
9
|
+
*
|
|
10
|
+
* @param execute - Function to execute. Receives history for retry context.
|
|
11
|
+
* @param options - Validation options including the validate function.
|
|
12
|
+
* @returns The first result that passes validation.
|
|
13
|
+
* @throws {ValidationExhaustedError} If all attempts fail validation.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const result = await withValidation(
|
|
18
|
+
* (history) => session.generateText({
|
|
19
|
+
* messages: [
|
|
20
|
+
* { role: 'user', content: prompt },
|
|
21
|
+
* ...(history.isRetry ? [{
|
|
22
|
+
* role: 'user' as const,
|
|
23
|
+
* content: `Fix: ${history.last!.reason}`,
|
|
24
|
+
* }] : []),
|
|
25
|
+
* ],
|
|
26
|
+
* schema,
|
|
27
|
+
* }),
|
|
28
|
+
* {
|
|
29
|
+
* validate: (result) => ({
|
|
30
|
+
* valid: result.confidence > 0.8,
|
|
31
|
+
* reason: `Confidence ${result.confidence} below 0.8`,
|
|
32
|
+
* }),
|
|
33
|
+
* maxAttempts: 3,
|
|
34
|
+
* }
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function withValidation(execute, options) {
|
|
39
|
+
const { validate, maxAttempts: rawMax, signal, retryDelay, onAttempt } = options;
|
|
40
|
+
const maxAttempts = Math.max(1, rawMax ?? 3);
|
|
41
|
+
const history = new ValidationHistory();
|
|
42
|
+
while (history.nextAttempt <= maxAttempts) {
|
|
43
|
+
signal?.throwIfAborted();
|
|
44
|
+
const result = await execute(history);
|
|
45
|
+
const validation = await validate(result, history);
|
|
46
|
+
history.add(result, validation);
|
|
47
|
+
onAttempt?.(history.last);
|
|
48
|
+
if (validation.valid) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
const hasMoreAttempts = history.nextAttempt <= maxAttempts;
|
|
52
|
+
if (retryDelay && hasMoreAttempts) {
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new ValidationExhaustedError(`Validation failed after ${history.all.length} attempts`, history);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=with-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-validation.js","sourceRoot":"","sources":["../../src/validation/with-validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAmF,EACnF,OAA4C;IAE5C,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACjF,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAW,CAAC;IAEjD,OAAO,OAAO,CAAC,WAAW,IAAI,WAAW,EAAE,CAAC;QAC1C,MAAM,EAAE,cAAc,EAAE,CAAC;QAEzB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAEhC,SAAS,EAAE,CAAC,OAAO,CAAC,IAAK,CAAC,CAAC;QAE3B,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC;QAC3D,IAAI,UAAU,IAAI,eAAe,EAAE,CAAC;YAClC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED,MAAM,IAAI,wBAAwB,CAChC,2BAA2B,OAAO,CAAC,GAAG,CAAC,MAAM,WAAW,EACxD,OAAO,CACR,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,80 +1,76 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"./testing": {
|
|
16
|
-
"types": "./dist/testing/index.d.ts",
|
|
17
|
-
"import": "./dist/testing/index.js",
|
|
18
|
-
"require": "./dist/testing/index.cjs"
|
|
19
|
-
}
|
|
2
|
+
"name": "@agtlantis/core",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "A framework for building Agents and Pipelines consistently on top of AI SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
20
11
|
},
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
"./testing": {
|
|
13
|
+
"types": "./dist/testing/index.d.ts",
|
|
14
|
+
"import": "./dist/testing/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rm -rf dist && tsgo -p tsconfig.build.json",
|
|
23
|
+
"test": "vitest run src/",
|
|
24
|
+
"test:unit": "vitest run src/",
|
|
25
|
+
"test:e2e": "REAL_AI_ENABLED=true vitest run e2e/",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"handlebars": "^4.7.8",
|
|
31
|
+
"yaml": "^2.8.2",
|
|
32
|
+
"zod-to-json-schema": "^3.25.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@ai-sdk/google": "^3.0.0",
|
|
36
|
+
"@ai-sdk/openai": "^3.0.0",
|
|
37
|
+
"@google/genai": "^1.0.0",
|
|
38
|
+
"ai": "^6.0.0",
|
|
39
|
+
"zod": "^3.23.0 || ^4.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@ai-sdk/google": {
|
|
43
|
+
"optional": true
|
|
32
44
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"yaml": "^2.8.2",
|
|
36
|
-
"zod-to-json-schema": "^3.25.1"
|
|
45
|
+
"@ai-sdk/openai": {
|
|
46
|
+
"optional": true
|
|
37
47
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
"engines": {
|
|
68
|
-
"node": ">=18.0.0"
|
|
69
|
-
},
|
|
70
|
-
"publishConfig": {
|
|
71
|
-
"access": "public"
|
|
72
|
-
},
|
|
73
|
-
"keywords": [
|
|
74
|
-
"ai",
|
|
75
|
-
"agent",
|
|
76
|
-
"llm",
|
|
77
|
-
"framework"
|
|
78
|
-
],
|
|
79
|
-
"license": "MIT"
|
|
48
|
+
"@google/genai": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@ai-sdk/google": "^3.0.10",
|
|
54
|
+
"@ai-sdk/openai": "^3.0.12",
|
|
55
|
+
"@google/genai": "^1.37.0",
|
|
56
|
+
"ai": "^6.0.39",
|
|
57
|
+
"dotenv": "^17.2.3",
|
|
58
|
+
"@typescript/native-preview": "^7.0.0-dev",
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"vitest": "^4.0.17",
|
|
61
|
+
"zod": "^4.3.5"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.0.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"keywords": [
|
|
70
|
+
"ai",
|
|
71
|
+
"agent",
|
|
72
|
+
"llm",
|
|
73
|
+
"framework"
|
|
74
|
+
],
|
|
75
|
+
"license": "MIT"
|
|
80
76
|
}
|