@agentica/core 0.22.0 → 0.24.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.
Files changed (67) hide show
  1. package/README.md +11 -12
  2. package/lib/Agentica.d.ts +6 -1
  3. package/lib/Agentica.js +8 -3
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/MicroAgentica.d.ts +10 -0
  6. package/lib/MicroAgentica.js +11 -0
  7. package/lib/MicroAgentica.js.map +1 -1
  8. package/lib/context/AgenticaContext.d.ts +4 -0
  9. package/lib/functional/assertHttpController.d.ts +75 -0
  10. package/lib/functional/assertHttpController.js +9622 -0
  11. package/lib/functional/assertHttpController.js.map +1 -0
  12. package/lib/functional/assertHttpLlmApplication.d.ts +1 -0
  13. package/lib/functional/assertHttpLlmApplication.js +1 -0
  14. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  15. package/lib/functional/assertMcpController.d.ts +1 -1
  16. package/lib/functional/assertMcpController.js +1 -1
  17. package/lib/functional/assertMcpController.js.map +1 -1
  18. package/lib/functional/validateHttpController.d.ts +75 -0
  19. package/lib/functional/validateHttpController.js +7952 -0
  20. package/lib/functional/validateHttpController.js.map +1 -0
  21. package/lib/functional/validateHttpLlmApplication.d.ts +1 -0
  22. package/lib/functional/validateHttpLlmApplication.js +1 -0
  23. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  24. package/lib/functional/validateMcpController.d.ts +24 -0
  25. package/lib/functional/validateMcpController.js +3034 -0
  26. package/lib/functional/validateMcpController.js.map +1 -0
  27. package/lib/histories/AgenticaUserInputHistory.d.ts +13 -7
  28. package/lib/index.d.ts +3 -0
  29. package/lib/index.js +3 -0
  30. package/lib/index.js.map +1 -1
  31. package/lib/index.mjs +25981 -5985
  32. package/lib/index.mjs.map +1 -1
  33. package/lib/utils/ChatGptCompletionMessageUtil.spec.d.ts +1 -0
  34. package/lib/utils/ChatGptCompletionMessageUtil.spec.js +288 -0
  35. package/lib/utils/ChatGptCompletionMessageUtil.spec.js.map +1 -0
  36. package/lib/utils/ChatGptTokenUsageAggregator.spec.d.ts +1 -0
  37. package/lib/utils/ChatGptTokenUsageAggregator.spec.js +199 -0
  38. package/lib/utils/ChatGptTokenUsageAggregator.spec.js.map +1 -0
  39. package/lib/utils/Singleton.js +18 -0
  40. package/lib/utils/Singleton.js.map +1 -1
  41. package/lib/utils/Singleton.spec.d.ts +1 -0
  42. package/lib/utils/Singleton.spec.js +106 -0
  43. package/lib/utils/Singleton.spec.js.map +1 -0
  44. package/lib/utils/__map_take.spec.d.ts +1 -0
  45. package/lib/utils/__map_take.spec.js +108 -0
  46. package/lib/utils/__map_take.spec.js.map +1 -0
  47. package/package.json +1 -1
  48. package/src/Agentica.ts +16 -2
  49. package/src/MicroAgentica.ts +13 -0
  50. package/src/context/AgenticaContext.ts +5 -0
  51. package/src/functional/assertHttpController.ts +112 -0
  52. package/src/functional/assertHttpLlmApplication.ts +1 -0
  53. package/src/functional/assertMcpController.ts +1 -2
  54. package/src/functional/validateHttpController.ts +118 -0
  55. package/src/functional/validateHttpLlmApplication.ts +1 -1
  56. package/src/functional/validateMcpController.ts +56 -0
  57. package/src/histories/AgenticaUserInputHistory.ts +14 -8
  58. package/src/index.ts +3 -0
  59. package/src/utils/ChatGptCompletionMessageUtil.spec.ts +320 -0
  60. package/src/utils/ChatGptTokenUsageAggregator.spec.ts +226 -0
  61. package/src/utils/Singleton.spec.ts +138 -0
  62. package/src/utils/Singleton.ts +18 -0
  63. package/src/utils/__map_take.spec.ts +140 -0
  64. package/lib/utils/MathUtil.d.ts +0 -3
  65. package/lib/utils/MathUtil.js +0 -8
  66. package/lib/utils/MathUtil.js.map +0 -1
  67. package/src/utils/MathUtil.ts +0 -3
@@ -0,0 +1,140 @@
1
+ import { __map_take } from "./__map_take";
2
+
3
+ describe("__map_take", () => {
4
+ describe("basic functionality", () => {
5
+ it("should generate value for new key", () => {
6
+ const map = new Map<string, number>();
7
+ const generator = () => 42;
8
+
9
+ const result = __map_take(map, "test", generator);
10
+
11
+ expect(result).toBe(42);
12
+ expect(map.get("test")).toBe(42);
13
+ });
14
+
15
+ it("should return existing value for existing key", () => {
16
+ const map = new Map<string, number>();
17
+ map.set("test", 100);
18
+
19
+ const generator = () => 42;
20
+ const result = __map_take(map, "test", generator);
21
+
22
+ expect(result).toBe(100);
23
+ expect(map.get("test")).toBe(100);
24
+ });
25
+ });
26
+
27
+ describe("various type tests", () => {
28
+ it("should handle object type", () => {
29
+ const map = new Map<string, { value: number }>();
30
+ const generator = () => ({ value: 42 });
31
+
32
+ const result = __map_take(map, "test", generator);
33
+
34
+ expect(result).toEqual({ value: 42 });
35
+ expect(map.get("test")).toEqual({ value: 42 });
36
+ });
37
+
38
+ it("should handle array type", () => {
39
+ const map = new Map<string, number[]>();
40
+ const generator = () => [1, 2, 3];
41
+
42
+ const result = __map_take(map, "test", generator);
43
+
44
+ expect(result).toEqual([1, 2, 3]);
45
+ expect(map.get("test")).toEqual([1, 2, 3]);
46
+ });
47
+
48
+ it("should handle function type", () => {
49
+ const map = new Map<string, () => number>();
50
+ const generator = () => () => 42;
51
+
52
+ const result = __map_take(map, "test", generator);
53
+
54
+ expect(result()).toBe(42);
55
+ expect(map.get("test")?.()).toBe(42);
56
+ });
57
+ });
58
+
59
+ describe("edge cases", () => {
60
+ it("should handle null key", () => {
61
+ const map = new Map<null, string>();
62
+ const generator = () => "test";
63
+
64
+ const result = __map_take(map, null, generator);
65
+
66
+ expect(result).toBe("test");
67
+ expect(map.get(null)).toBe("test");
68
+ });
69
+
70
+ it("should handle undefined key", () => {
71
+ const map = new Map<undefined, string>();
72
+ const generator = () => "test";
73
+
74
+ const result = __map_take(map, undefined, generator);
75
+
76
+ expect(result).toBe("test");
77
+ expect(map.get(undefined)).toBe("test");
78
+ });
79
+
80
+ it("should handle empty string key", () => {
81
+ const map = new Map<string, string>();
82
+ const generator = () => "test";
83
+
84
+ const result = __map_take(map, "", generator);
85
+
86
+ expect(result).toBe("test");
87
+ expect(map.get("")).toBe("test");
88
+ });
89
+ });
90
+
91
+ describe("generator function tests", () => {
92
+ it("should not call generator multiple times", () => {
93
+ const map = new Map<string, number>();
94
+ let callCount = 0;
95
+
96
+ const generator = () => {
97
+ callCount++;
98
+ return 42;
99
+ };
100
+
101
+ __map_take(map, "test", generator);
102
+ __map_take(map, "test", generator);
103
+
104
+ expect(callCount).toBe(1);
105
+ });
106
+
107
+ it("should handle generator throwing error", () => {
108
+ const map = new Map<string, number>();
109
+ const generator = () => {
110
+ throw new Error("Generator error");
111
+ };
112
+
113
+ expect(() => __map_take(map, "test", generator)).toThrow("Generator error");
114
+ });
115
+
116
+ it("should handle generator returning undefined", () => {
117
+ const map = new Map<string, undefined>();
118
+ const generator = () => undefined;
119
+
120
+ const result = __map_take(map, "test", generator);
121
+
122
+ expect(result).toBeUndefined();
123
+ expect(map.get("test")).toBeUndefined();
124
+ });
125
+ });
126
+
127
+ describe("concurrency tests", () => {
128
+ it("should handle concurrent access to same key", () => {
129
+ const map = new Map<string, number>();
130
+ const generator = () => 42;
131
+
132
+ const result1 = __map_take(map, "test", generator);
133
+ const result2 = __map_take(map, "test", generator);
134
+
135
+ expect(result1).toBe(42);
136
+ expect(result2).toBe(42);
137
+ expect(map.get("test")).toBe(42);
138
+ });
139
+ });
140
+ });
@@ -1,3 +0,0 @@
1
- export declare namespace MathUtil {
2
- const round: (value: number) => number;
3
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MathUtil = void 0;
4
- var MathUtil;
5
- (function (MathUtil) {
6
- MathUtil.round = (value) => Math.floor(value * 100) / 100;
7
- })(MathUtil || (exports.MathUtil = MathUtil = {}));
8
- //# sourceMappingURL=MathUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MathUtil.js","sourceRoot":"","sources":["../../src/utils/MathUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,QAAQ,CAExB;AAFD,WAAiB,QAAQ;IACV,cAAK,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAChF,CAAC,EAFgB,QAAQ,wBAAR,QAAQ,QAExB"}
@@ -1,3 +0,0 @@
1
- export namespace MathUtil {
2
- export const round = (value: number): number => Math.floor(value * 100) / 100;
3
- }