@agtlantis/core 0.5.0 → 0.5.1

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 (265) hide show
  1. package/dist/errors/index.d.ts +4 -0
  2. package/dist/errors/index.d.ts.map +1 -0
  3. package/dist/errors/index.js +3 -0
  4. package/dist/errors/index.js.map +1 -0
  5. package/dist/errors/types.d.ts +69 -0
  6. package/dist/errors/types.d.ts.map +1 -0
  7. package/dist/errors/types.js +119 -0
  8. package/dist/errors/types.js.map +1 -0
  9. package/dist/errors/utils.d.ts +17 -0
  10. package/dist/errors/utils.d.ts.map +1 -0
  11. package/dist/errors/utils.js +16 -0
  12. package/dist/errors/utils.js.map +1 -0
  13. package/dist/execution/constants.d.ts +7 -0
  14. package/dist/execution/constants.d.ts.map +1 -0
  15. package/dist/execution/constants.js +7 -0
  16. package/dist/execution/constants.js.map +1 -0
  17. package/dist/execution/index.d.ts +8 -0
  18. package/dist/execution/index.d.ts.map +1 -0
  19. package/dist/execution/index.js +7 -0
  20. package/dist/execution/index.js.map +1 -0
  21. package/dist/execution/mapping.d.ts +17 -0
  22. package/dist/execution/mapping.d.ts.map +1 -0
  23. package/dist/execution/mapping.js +197 -0
  24. package/dist/execution/mapping.js.map +1 -0
  25. package/dist/execution/shared.d.ts +86 -0
  26. package/dist/execution/shared.d.ts.map +1 -0
  27. package/dist/execution/shared.js +100 -0
  28. package/dist/execution/shared.js.map +1 -0
  29. package/dist/execution/simple-host.d.ts +56 -0
  30. package/dist/execution/simple-host.d.ts.map +1 -0
  31. package/dist/execution/simple-host.js +126 -0
  32. package/dist/execution/simple-host.js.map +1 -0
  33. package/dist/execution/streaming-host.d.ts +79 -0
  34. package/dist/execution/streaming-host.d.ts.map +1 -0
  35. package/dist/execution/streaming-host.js +276 -0
  36. package/dist/execution/streaming-host.js.map +1 -0
  37. package/dist/execution/testing/fixtures.d.ts +67 -0
  38. package/dist/execution/testing/fixtures.d.ts.map +1 -0
  39. package/dist/execution/testing/fixtures.js +145 -0
  40. package/dist/execution/testing/fixtures.js.map +1 -0
  41. package/dist/execution/testing/helpers.d.ts +218 -0
  42. package/dist/execution/testing/helpers.d.ts.map +1 -0
  43. package/dist/execution/testing/helpers.js +327 -0
  44. package/dist/execution/testing/helpers.js.map +1 -0
  45. package/dist/execution/testing/host-configs.d.ts +56 -0
  46. package/dist/execution/testing/host-configs.d.ts.map +1 -0
  47. package/dist/execution/testing/host-configs.js +154 -0
  48. package/dist/execution/testing/host-configs.js.map +1 -0
  49. package/dist/execution/testing/vitest-assertions.d.ts +102 -0
  50. package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
  51. package/dist/execution/testing/vitest-assertions.js +142 -0
  52. package/dist/execution/testing/vitest-assertions.js.map +1 -0
  53. package/dist/execution/types.d.ts +432 -0
  54. package/dist/execution/types.d.ts.map +1 -0
  55. package/dist/execution/types.js +2 -0
  56. package/dist/execution/types.js.map +1 -0
  57. package/dist/execution/utils.d.ts +68 -0
  58. package/dist/execution/utils.d.ts.map +1 -0
  59. package/dist/execution/utils.js +93 -0
  60. package/dist/execution/utils.js.map +1 -0
  61. package/dist/index.d.ts +10 -1506
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +9 -2979
  64. package/dist/index.js.map +1 -1
  65. package/dist/observability/index.d.ts +4 -0
  66. package/dist/observability/index.d.ts.map +1 -0
  67. package/dist/observability/index.js +2 -0
  68. package/dist/observability/index.js.map +1 -0
  69. package/dist/observability/logger.d.ts +161 -0
  70. package/dist/observability/logger.d.ts.map +1 -0
  71. package/dist/observability/logger.js +31 -0
  72. package/dist/observability/logger.js.map +1 -0
  73. package/dist/observability/types.d.ts +46 -0
  74. package/dist/observability/types.d.ts.map +1 -0
  75. package/dist/observability/types.js +2 -0
  76. package/dist/observability/types.js.map +1 -0
  77. package/dist/patterns/index.d.ts +2 -0
  78. package/dist/patterns/index.d.ts.map +1 -0
  79. package/dist/patterns/index.js +2 -0
  80. package/dist/patterns/index.js.map +1 -0
  81. package/dist/patterns/progressive/index.d.ts +2 -0
  82. package/dist/patterns/progressive/index.d.ts.map +1 -0
  83. package/dist/patterns/progressive/index.js +2 -0
  84. package/dist/patterns/progressive/index.js.map +1 -0
  85. package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
  86. package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
  87. package/dist/patterns/progressive/progressive-pattern.js +260 -0
  88. package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
  89. package/dist/pricing/calculator.d.ts +71 -0
  90. package/dist/pricing/calculator.d.ts.map +1 -0
  91. package/dist/pricing/calculator.js +127 -0
  92. package/dist/pricing/calculator.js.map +1 -0
  93. package/dist/pricing/config.d.ts +61 -0
  94. package/dist/pricing/config.d.ts.map +1 -0
  95. package/dist/pricing/config.js +87 -0
  96. package/dist/pricing/config.js.map +1 -0
  97. package/dist/pricing/defaults.d.ts +29 -0
  98. package/dist/pricing/defaults.d.ts.map +1 -0
  99. package/dist/pricing/defaults.js +139 -0
  100. package/dist/pricing/defaults.js.map +1 -0
  101. package/dist/pricing/index.d.ts +40 -0
  102. package/dist/pricing/index.d.ts.map +1 -0
  103. package/dist/pricing/index.js +43 -0
  104. package/dist/pricing/index.js.map +1 -0
  105. package/dist/pricing/types.d.ts +96 -0
  106. package/dist/pricing/types.d.ts.map +1 -0
  107. package/dist/pricing/types.js +7 -0
  108. package/dist/pricing/types.js.map +1 -0
  109. package/dist/pricing/validator.d.ts +55 -0
  110. package/dist/pricing/validator.d.ts.map +1 -0
  111. package/dist/pricing/validator.js +84 -0
  112. package/dist/pricing/validator.js.map +1 -0
  113. package/dist/prompt/errors.d.ts +112 -0
  114. package/dist/prompt/errors.d.ts.map +1 -0
  115. package/dist/prompt/errors.js +175 -0
  116. package/dist/prompt/errors.js.map +1 -0
  117. package/dist/prompt/file-prompt-repository.d.ts +80 -0
  118. package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
  119. package/dist/prompt/file-prompt-repository.js +287 -0
  120. package/dist/prompt/file-prompt-repository.js.map +1 -0
  121. package/dist/prompt/index.d.ts +34 -0
  122. package/dist/prompt/index.d.ts.map +1 -0
  123. package/dist/prompt/index.js +37 -0
  124. package/dist/prompt/index.js.map +1 -0
  125. package/dist/prompt/prompt-template.d.ts +64 -0
  126. package/dist/prompt/prompt-template.d.ts.map +1 -0
  127. package/dist/prompt/prompt-template.js +90 -0
  128. package/dist/prompt/prompt-template.js.map +1 -0
  129. package/dist/prompt/template.d.ts +23 -0
  130. package/dist/prompt/template.d.ts.map +1 -0
  131. package/dist/prompt/template.js +70 -0
  132. package/dist/prompt/template.js.map +1 -0
  133. package/dist/prompt/types.d.ts +148 -0
  134. package/dist/prompt/types.d.ts.map +1 -0
  135. package/dist/prompt/types.js +7 -0
  136. package/dist/prompt/types.js.map +1 -0
  137. package/dist/provider/base-provider.d.ts +41 -0
  138. package/dist/provider/base-provider.d.ts.map +1 -0
  139. package/dist/provider/base-provider.js +21 -0
  140. package/dist/provider/base-provider.js.map +1 -0
  141. package/dist/provider/file-cache.d.ts +14 -0
  142. package/dist/provider/file-cache.d.ts.map +1 -0
  143. package/dist/provider/file-cache.js +29 -0
  144. package/dist/provider/file-cache.js.map +1 -0
  145. package/dist/provider/file-source.d.ts +32 -0
  146. package/dist/provider/file-source.d.ts.map +1 -0
  147. package/dist/provider/file-source.js +180 -0
  148. package/dist/provider/file-source.js.map +1 -0
  149. package/dist/provider/google/factory.d.ts +107 -0
  150. package/dist/provider/google/factory.d.ts.map +1 -0
  151. package/dist/provider/google/factory.js +143 -0
  152. package/dist/provider/google/factory.js.map +1 -0
  153. package/dist/provider/google/file-manager.d.ts +14 -0
  154. package/dist/provider/google/file-manager.d.ts.map +1 -0
  155. package/dist/provider/google/file-manager.js +183 -0
  156. package/dist/provider/google/file-manager.js.map +1 -0
  157. package/dist/provider/google/index.d.ts +8 -0
  158. package/dist/provider/google/index.d.ts.map +1 -0
  159. package/dist/provider/google/index.js +10 -0
  160. package/dist/provider/google/index.js.map +1 -0
  161. package/dist/provider/hash.d.ts +3 -0
  162. package/dist/provider/hash.d.ts.map +1 -0
  163. package/dist/provider/hash.js +34 -0
  164. package/dist/provider/hash.js.map +1 -0
  165. package/dist/provider/index.d.ts +9 -0
  166. package/dist/provider/index.d.ts.map +1 -0
  167. package/dist/provider/index.js +11 -0
  168. package/dist/provider/index.js.map +1 -0
  169. package/dist/provider/noop-file-manager.d.ts +9 -0
  170. package/dist/provider/noop-file-manager.d.ts.map +1 -0
  171. package/dist/provider/noop-file-manager.js +28 -0
  172. package/dist/provider/noop-file-manager.js.map +1 -0
  173. package/dist/provider/openai/factory.d.ts +67 -0
  174. package/dist/provider/openai/factory.d.ts.map +1 -0
  175. package/dist/provider/openai/factory.js +95 -0
  176. package/dist/provider/openai/factory.js.map +1 -0
  177. package/dist/provider/openai/index.d.ts +7 -0
  178. package/dist/provider/openai/index.d.ts.map +1 -0
  179. package/dist/provider/openai/index.js +7 -0
  180. package/dist/provider/openai/index.js.map +1 -0
  181. package/dist/provider/types.d.ts +105 -0
  182. package/dist/provider/types.d.ts.map +1 -0
  183. package/dist/provider/types.js +19 -0
  184. package/dist/provider/types.js.map +1 -0
  185. package/dist/session/index.d.ts +7 -0
  186. package/dist/session/index.d.ts.map +1 -0
  187. package/dist/session/index.js +5 -0
  188. package/dist/session/index.js.map +1 -0
  189. package/dist/session/simple-session.d.ts +98 -0
  190. package/dist/session/simple-session.d.ts.map +1 -0
  191. package/dist/session/simple-session.js +299 -0
  192. package/dist/session/simple-session.js.map +1 -0
  193. package/dist/session/streaming-session.d.ts +90 -0
  194. package/dist/session/streaming-session.d.ts.map +1 -0
  195. package/dist/session/streaming-session.js +151 -0
  196. package/dist/session/streaming-session.js.map +1 -0
  197. package/dist/session/test-utils.d.ts +19 -0
  198. package/dist/session/test-utils.d.ts.map +1 -0
  199. package/dist/session/test-utils.js +65 -0
  200. package/dist/session/test-utils.js.map +1 -0
  201. package/dist/session/types.d.ts +219 -0
  202. package/dist/session/types.d.ts.map +1 -0
  203. package/dist/session/types.js +181 -0
  204. package/dist/session/types.js.map +1 -0
  205. package/dist/session/usage-extractors.d.ts +7 -0
  206. package/dist/session/usage-extractors.d.ts.map +1 -0
  207. package/dist/session/usage-extractors.js +71 -0
  208. package/dist/session/usage-extractors.js.map +1 -0
  209. package/dist/testing/fixtures.d.ts +34 -0
  210. package/dist/testing/fixtures.d.ts.map +1 -0
  211. package/dist/testing/fixtures.js +65 -0
  212. package/dist/testing/fixtures.js.map +1 -0
  213. package/dist/testing/helpers.d.ts +20 -0
  214. package/dist/testing/helpers.d.ts.map +1 -0
  215. package/dist/testing/helpers.js +32 -0
  216. package/dist/testing/helpers.js.map +1 -0
  217. package/dist/testing/index.d.ts +7 -519
  218. package/dist/testing/index.d.ts.map +1 -0
  219. package/dist/testing/index.js +21 -2123
  220. package/dist/testing/index.js.map +1 -1
  221. package/dist/testing/mock-provider.d.ts +79 -0
  222. package/dist/testing/mock-provider.d.ts.map +1 -0
  223. package/dist/testing/mock-provider.js +152 -0
  224. package/dist/testing/mock-provider.js.map +1 -0
  225. package/dist/testing/mock.d.ts +29 -0
  226. package/dist/testing/mock.d.ts.map +1 -0
  227. package/dist/testing/mock.js +154 -0
  228. package/dist/testing/mock.js.map +1 -0
  229. package/dist/testing/test-execution.d.ts +14 -0
  230. package/dist/testing/test-execution.d.ts.map +1 -0
  231. package/dist/testing/test-execution.js +108 -0
  232. package/dist/testing/test-execution.js.map +1 -0
  233. package/dist/utils/deep-merge.d.ts +6 -0
  234. package/dist/utils/deep-merge.d.ts.map +1 -0
  235. package/dist/utils/deep-merge.js +24 -0
  236. package/dist/utils/deep-merge.js.map +1 -0
  237. package/dist/validation/errors.d.ts +28 -0
  238. package/dist/validation/errors.d.ts.map +1 -0
  239. package/dist/validation/errors.js +39 -0
  240. package/dist/validation/errors.js.map +1 -0
  241. package/dist/validation/index.d.ts +5 -0
  242. package/dist/validation/index.d.ts.map +1 -0
  243. package/dist/validation/index.js +4 -0
  244. package/dist/validation/index.js.map +1 -0
  245. package/dist/validation/types.d.ts +49 -0
  246. package/dist/validation/types.d.ts.map +1 -0
  247. package/dist/validation/types.js +2 -0
  248. package/dist/validation/types.js.map +1 -0
  249. package/dist/validation/validation-history.d.ts +12 -0
  250. package/dist/validation/validation-history.d.ts.map +1 -0
  251. package/dist/validation/validation-history.js +29 -0
  252. package/dist/validation/validation-history.js.map +1 -0
  253. package/dist/validation/with-validation.d.ts +38 -0
  254. package/dist/validation/with-validation.d.ts.map +1 -0
  255. package/dist/validation/with-validation.js +58 -0
  256. package/dist/validation/with-validation.js.map +1 -0
  257. package/package.json +72 -76
  258. package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
  259. package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
  260. package/dist/index.cjs +0 -3085
  261. package/dist/index.cjs.map +0 -1
  262. package/dist/index.d.cts +0 -1506
  263. package/dist/testing/index.cjs +0 -2167
  264. package/dist/testing/index.cjs.map +0 -1
  265. 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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -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,GAAW;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAAA,CACjC;IAED,IAAI,IAAI,GAA2C;QACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAAA,CAC7B;IAED,IAAI,GAAG,GAA0C;QAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC;IAAA,CACtB;IAED,IAAI,cAAc,GAAa;QAC7B,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;IAAA,CAC1B;IAED,IAAI,OAAO,GAAY;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAAA,CACjC;IAED,qEAAqE;IACrE,GAAG,CAAC,MAAe,EAAE,UAA4B,EAAQ;QACvD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,MAAM;YACN,GAAG,UAAU;YACb,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;SAClC,CAAC,CAAC;IAAA,CACJ;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,EAC1B;IAClB,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;AAAA,CACH"}
package/package.json CHANGED
@@ -1,80 +1,76 @@
1
1
  {
2
- "name": "@agtlantis/core",
3
- "version": "0.5.0",
4
- "description": "A framework for building Agents and Pipelines consistently on top of AI SDK",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
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.5.1",
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
- "files": [
22
- "dist",
23
- "README.md"
24
- ],
25
- "scripts": {
26
- "build": "rm -rf dist && tsup",
27
- "test": "vitest run src/",
28
- "test:unit": "vitest run src/",
29
- "test:e2e": "REAL_AI_ENABLED=true vitest run e2e/",
30
- "test:watch": "vitest",
31
- "typecheck": "tsc --noEmit"
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
+ "dependencies": {
22
+ "handlebars": "^4.7.8",
23
+ "yaml": "^2.8.2",
24
+ "zod-to-json-schema": "^3.25.1"
25
+ },
26
+ "peerDependencies": {
27
+ "@ai-sdk/google": "^3.0.0",
28
+ "@ai-sdk/openai": "^3.0.0",
29
+ "@google/genai": "^1.0.0",
30
+ "ai": "^6.0.0",
31
+ "zod": "^3.23.0 || ^4.0.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@ai-sdk/google": {
35
+ "optional": true
32
36
  },
33
- "dependencies": {
34
- "handlebars": "^4.7.8",
35
- "yaml": "^2.8.2",
36
- "zod-to-json-schema": "^3.25.1"
37
+ "@ai-sdk/openai": {
38
+ "optional": true
37
39
  },
38
- "peerDependencies": {
39
- "@ai-sdk/google": "^3.0.0",
40
- "@ai-sdk/openai": "^3.0.0",
41
- "@google/genai": "^1.0.0",
42
- "ai": "^6.0.0",
43
- "zod": "^3.23.0 || ^4.0.0"
44
- },
45
- "peerDependenciesMeta": {
46
- "@ai-sdk/google": {
47
- "optional": true
48
- },
49
- "@ai-sdk/openai": {
50
- "optional": true
51
- },
52
- "@google/genai": {
53
- "optional": true
54
- }
55
- },
56
- "devDependencies": {
57
- "@ai-sdk/google": "^3.0.10",
58
- "@ai-sdk/openai": "^3.0.12",
59
- "@google/genai": "^1.37.0",
60
- "ai": "^6.0.39",
61
- "dotenv": "^17.2.3",
62
- "tsup": "^8.5.1",
63
- "typescript": "^5.9.3",
64
- "vitest": "^4.0.17",
65
- "zod": "^4.3.5"
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"
80
- }
40
+ "@google/genai": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "@ai-sdk/google": "^3.0.10",
46
+ "@ai-sdk/openai": "^3.0.12",
47
+ "@google/genai": "^1.37.0",
48
+ "ai": "^6.0.39",
49
+ "dotenv": "^17.2.3",
50
+ "@typescript/native-preview": "^7.0.0-dev",
51
+ "typescript": "^5.9.3",
52
+ "vitest": "^4.0.17",
53
+ "zod": "^4.3.5"
54
+ },
55
+ "engines": {
56
+ "node": ">=18.0.0"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "keywords": [
62
+ "ai",
63
+ "agent",
64
+ "llm",
65
+ "framework"
66
+ ],
67
+ "license": "MIT",
68
+ "scripts": {
69
+ "build": "rm -rf dist && tsgo -p tsconfig.build.json",
70
+ "test": "vitest run src/",
71
+ "test:unit": "vitest run src/",
72
+ "test:e2e": "REAL_AI_ENABLED=true vitest run e2e/",
73
+ "test:watch": "vitest",
74
+ "typecheck": "tsc --noEmit"
75
+ }
76
+ }