@librechat/agents 3.0.2 → 3.0.3
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/package.json +2 -2
- package/src/tools/Calculator.test.ts +278 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.03",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"https-proxy-agent": "^7.0.6",
|
|
116
116
|
"mathjs": "^15.1.0",
|
|
117
117
|
"nanoid": "^3.3.7",
|
|
118
|
-
"openai": "
|
|
118
|
+
"openai": "5.10.1"
|
|
119
119
|
},
|
|
120
120
|
"imports": {
|
|
121
121
|
"@/*": "./src/*",
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Calculator } from './Calculator';
|
|
2
|
+
|
|
3
|
+
describe('Calculator', () => {
|
|
4
|
+
let calculator: Calculator;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
calculator = new Calculator();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('basic properties', () => {
|
|
11
|
+
it('should have correct name', () => {
|
|
12
|
+
expect(calculator.name).toBe('calculator');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should have correct description', () => {
|
|
16
|
+
expect(calculator.description).toBe(
|
|
17
|
+
'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.'
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should have correct lc_name', () => {
|
|
22
|
+
expect(Calculator.lc_name()).toBe('Calculator');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should have correct lc_namespace', () => {
|
|
26
|
+
const namespace = calculator.lc_namespace;
|
|
27
|
+
expect(namespace).toContain('calculator');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('basic arithmetic operations', () => {
|
|
32
|
+
it('should add two numbers', async () => {
|
|
33
|
+
const result = await calculator._call('2 + 3');
|
|
34
|
+
expect(result).toBe('5');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should subtract two numbers', async () => {
|
|
38
|
+
const result = await calculator._call('10 - 4');
|
|
39
|
+
expect(result).toBe('6');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should multiply two numbers', async () => {
|
|
43
|
+
const result = await calculator._call('6 * 7');
|
|
44
|
+
expect(result).toBe('42');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should divide two numbers', async () => {
|
|
48
|
+
const result = await calculator._call('15 / 3');
|
|
49
|
+
expect(result).toBe('5');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should handle modulo operation', async () => {
|
|
53
|
+
const result = await calculator._call('17 % 5');
|
|
54
|
+
expect(result).toBe('2');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should handle exponentiation', async () => {
|
|
58
|
+
const result = await calculator._call('2 ^ 3');
|
|
59
|
+
expect(result).toBe('8');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('complex expressions', () => {
|
|
64
|
+
it('should handle order of operations', async () => {
|
|
65
|
+
const result = await calculator._call('2 + 3 * 4');
|
|
66
|
+
expect(result).toBe('14');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle parentheses', async () => {
|
|
70
|
+
const result = await calculator._call('(2 + 3) * 4');
|
|
71
|
+
expect(result).toBe('20');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should handle nested parentheses', async () => {
|
|
75
|
+
const result = await calculator._call('((2 + 3) * 4) / 5');
|
|
76
|
+
expect(result).toBe('4');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should handle multiple operations', async () => {
|
|
80
|
+
const result = await calculator._call('(10 + 5) * 2 - 8 / 4');
|
|
81
|
+
expect(result).toBe('28');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('decimal numbers', () => {
|
|
86
|
+
it('should handle decimal addition', async () => {
|
|
87
|
+
const result = await calculator._call('2.5 + 3.7');
|
|
88
|
+
expect(result).toBe('6.2');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle decimal multiplication', async () => {
|
|
92
|
+
const result = await calculator._call('2.5 * 4');
|
|
93
|
+
expect(result).toBe('10');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should handle decimal division', async () => {
|
|
97
|
+
const result = await calculator._call('7.5 / 2.5');
|
|
98
|
+
expect(result).toBe('3');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('negative numbers', () => {
|
|
103
|
+
it('should handle negative numbers in addition', async () => {
|
|
104
|
+
const result = await calculator._call('-5 + 3');
|
|
105
|
+
expect(result).toBe('-2');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handle negative numbers in subtraction', async () => {
|
|
109
|
+
const result = await calculator._call('10 - (-5)');
|
|
110
|
+
expect(result).toBe('15');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should handle negative numbers in multiplication', async () => {
|
|
114
|
+
const result = await calculator._call('-4 * -3');
|
|
115
|
+
expect(result).toBe('12');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should handle negative numbers in division', async () => {
|
|
119
|
+
const result = await calculator._call('-12 / 4');
|
|
120
|
+
expect(result).toBe('-3');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('mathematical functions', () => {
|
|
125
|
+
it('should handle square root', async () => {
|
|
126
|
+
const result = await calculator._call('sqrt(16)');
|
|
127
|
+
expect(result).toBe('4');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should handle absolute value', async () => {
|
|
131
|
+
const result = await calculator._call('abs(-42)');
|
|
132
|
+
expect(result).toBe('42');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should handle sine function', async () => {
|
|
136
|
+
const result = await calculator._call('sin(0)');
|
|
137
|
+
expect(result).toBe('0');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should handle cosine function', async () => {
|
|
141
|
+
const result = await calculator._call('cos(0)');
|
|
142
|
+
expect(result).toBe('1');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should handle logarithm', async () => {
|
|
146
|
+
const result = await calculator._call('log(10)');
|
|
147
|
+
expect(parseFloat(result)).toBeCloseTo(2.302585, 5);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should handle exponential', async () => {
|
|
151
|
+
const result = await calculator._call('exp(0)');
|
|
152
|
+
expect(result).toBe('1');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should handle floor function', async () => {
|
|
156
|
+
const result = await calculator._call('floor(4.7)');
|
|
157
|
+
expect(result).toBe('4');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should handle ceil function', async () => {
|
|
161
|
+
const result = await calculator._call('ceil(4.3)');
|
|
162
|
+
expect(result).toBe('5');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should handle round function', async () => {
|
|
166
|
+
const result = await calculator._call('round(4.5)');
|
|
167
|
+
expect(result).toBe('5');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('constants', () => {
|
|
172
|
+
it('should handle pi constant', async () => {
|
|
173
|
+
const result = await calculator._call('pi');
|
|
174
|
+
expect(parseFloat(result)).toBeCloseTo(3.14159, 5);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should handle e constant', async () => {
|
|
178
|
+
const result = await calculator._call('e');
|
|
179
|
+
expect(parseFloat(result)).toBeCloseTo(2.71828, 5);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should use pi in calculations', async () => {
|
|
183
|
+
const result = await calculator._call('2 * pi');
|
|
184
|
+
expect(parseFloat(result)).toBeCloseTo(6.28318, 4);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('error handling', () => {
|
|
189
|
+
it('should return error message for invalid expression', async () => {
|
|
190
|
+
const result = await calculator._call('invalid expression');
|
|
191
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should handle division by zero', async () => {
|
|
195
|
+
const result = await calculator._call('5 / 0');
|
|
196
|
+
expect(result).toBe('Infinity');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should return error message for incomplete expression', async () => {
|
|
200
|
+
const result = await calculator._call('5 +');
|
|
201
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should return error message for mismatched parentheses', async () => {
|
|
205
|
+
const result = await calculator._call('(5 + 3');
|
|
206
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should return error message for empty input', async () => {
|
|
210
|
+
const result = await calculator._call('');
|
|
211
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should return error message for only whitespace', async () => {
|
|
215
|
+
const result = await calculator._call(' ');
|
|
216
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should return error message for undefined variable', async () => {
|
|
220
|
+
const result = await calculator._call('x + 5');
|
|
221
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('edge cases', () => {
|
|
226
|
+
it('should handle very large numbers', async () => {
|
|
227
|
+
const result = await calculator._call('999999999 * 999999999');
|
|
228
|
+
expect(parseFloat(result)).toBeCloseTo(999999998000000000, -10);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should handle very small decimal numbers', async () => {
|
|
232
|
+
const result = await calculator._call('0.0001 + 0.0002');
|
|
233
|
+
expect(parseFloat(result)).toBeCloseTo(0.0003, 10);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should handle expressions with spaces', async () => {
|
|
237
|
+
const result = await calculator._call(' 5 + 3 ');
|
|
238
|
+
expect(result).toBe('8');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('should handle zero in calculations', async () => {
|
|
242
|
+
const result = await calculator._call('0 + 0');
|
|
243
|
+
expect(result).toBe('0');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should handle power of zero', async () => {
|
|
247
|
+
const result = await calculator._call('5 ^ 0');
|
|
248
|
+
expect(result).toBe('1');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('should handle zero to the power', async () => {
|
|
252
|
+
const result = await calculator._call('0 ^ 5');
|
|
253
|
+
expect(result).toBe('0');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe('complex real-world calculations', () => {
|
|
258
|
+
it('should calculate area of circle', async () => {
|
|
259
|
+
const result = await calculator._call('pi * 5^2');
|
|
260
|
+
expect(parseFloat(result)).toBeCloseTo(78.53981, 4);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should calculate compound interest formula component', async () => {
|
|
264
|
+
const result = await calculator._call('(1 + 0.05/12)^(12*5)');
|
|
265
|
+
expect(parseFloat(result)).toBeCloseTo(1.28336, 4);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('should calculate percentage', async () => {
|
|
269
|
+
const result = await calculator._call('(25 / 200) * 100');
|
|
270
|
+
expect(result).toBe('12.5');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('should calculate average', async () => {
|
|
274
|
+
const result = await calculator._call('(10 + 20 + 30 + 40 + 50) / 5');
|
|
275
|
+
expect(result).toBe('30');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|