llmist 0.1.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.
- package/LICENSE +21 -0
- package/README.md +394 -0
- package/dist/chunk-DCW33WV7.js +901 -0
- package/dist/chunk-DCW33WV7.js.map +1 -0
- package/dist/chunk-JEBGLCDW.js +22 -0
- package/dist/chunk-JEBGLCDW.js.map +1 -0
- package/dist/chunk-TP7HE3MN.js +4450 -0
- package/dist/chunk-TP7HE3MN.js.map +1 -0
- package/dist/cli.cjs +5333 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +987 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +5511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1101 -0
- package/dist/index.d.ts +1101 -0
- package/dist/index.js +421 -0
- package/dist/index.js.map +1 -0
- package/dist/mock-stream-D4erlo7B.d.cts +2602 -0
- package/dist/mock-stream-D4erlo7B.d.ts +2602 -0
- package/dist/testing/index.cjs +5260 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +274 -0
- package/dist/testing/index.d.ts +274 -0
- package/dist/testing/index.js +34 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { B as BaseGadget } from '../mock-stream-D4erlo7B.cjs';
|
|
2
|
+
export { a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM } from '../mock-stream-D4erlo7B.cjs';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import 'tslog';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Testing utilities for gadgets.
|
|
8
|
+
*
|
|
9
|
+
* Provides helpers for testing gadgets with schema validation without
|
|
10
|
+
* requiring full executor setup.
|
|
11
|
+
*
|
|
12
|
+
* @module testing/gadget-testing
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Result of testing a gadget.
|
|
17
|
+
*/
|
|
18
|
+
interface TestGadgetResult {
|
|
19
|
+
/** Result string if execution succeeded */
|
|
20
|
+
result?: string;
|
|
21
|
+
/** Error message if validation or execution failed */
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Parameters after validation and default application */
|
|
24
|
+
validatedParams?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for testGadget.
|
|
28
|
+
*/
|
|
29
|
+
interface TestGadgetOptions {
|
|
30
|
+
/**
|
|
31
|
+
* If true, skip schema validation.
|
|
32
|
+
* Useful for testing gadget behavior with invalid parameters.
|
|
33
|
+
*/
|
|
34
|
+
skipValidation?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Test a gadget with schema validation and default application.
|
|
38
|
+
*
|
|
39
|
+
* This helper replicates the validation behavior from GadgetExecutor.execute(),
|
|
40
|
+
* making it easy to test gadgets in isolation without setting up a full
|
|
41
|
+
* registry and executor.
|
|
42
|
+
*
|
|
43
|
+
* @param gadget - Gadget instance to test
|
|
44
|
+
* @param params - Raw parameters (before validation)
|
|
45
|
+
* @param options - Test options
|
|
46
|
+
* @returns Promise resolving to test result
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { testGadget } from 'llmist/testing';
|
|
51
|
+
* import { createGadget } from 'llmist';
|
|
52
|
+
* import { z } from 'zod';
|
|
53
|
+
*
|
|
54
|
+
* const calculator = createGadget({
|
|
55
|
+
* description: 'Add numbers',
|
|
56
|
+
* schema: z.object({
|
|
57
|
+
* a: z.number(),
|
|
58
|
+
* b: z.number().default(0),
|
|
59
|
+
* }),
|
|
60
|
+
* execute: ({ a, b }) => String(a + b),
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Test with defaults applied
|
|
64
|
+
* const result = await testGadget(calculator, { a: 5 });
|
|
65
|
+
* expect(result.result).toBe('5');
|
|
66
|
+
* expect(result.validatedParams).toEqual({ a: 5, b: 0 });
|
|
67
|
+
*
|
|
68
|
+
* // Test validation errors
|
|
69
|
+
* const invalid = await testGadget(calculator, { a: 'not a number' });
|
|
70
|
+
* expect(invalid.error).toContain('Invalid parameters');
|
|
71
|
+
*
|
|
72
|
+
* // Test with validation skipped
|
|
73
|
+
* const skipped = await testGadget(calculator, { a: 5 }, { skipValidation: true });
|
|
74
|
+
* expect(skipped.validatedParams).toEqual({ a: 5 }); // No defaults applied
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function testGadget(gadget: BaseGadget, params: Record<string, unknown>, options?: TestGadgetOptions): Promise<TestGadgetResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Test multiple parameter sets against a gadget.
|
|
80
|
+
*
|
|
81
|
+
* Convenience helper for running the same gadget with different inputs.
|
|
82
|
+
*
|
|
83
|
+
* @param gadget - Gadget instance to test
|
|
84
|
+
* @param paramSets - Array of parameter sets to test
|
|
85
|
+
* @param options - Test options applied to all tests
|
|
86
|
+
* @returns Promise resolving to array of test results
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const results = await testGadgetBatch(calculator, [
|
|
91
|
+
* { a: 1, b: 2 },
|
|
92
|
+
* { a: 5 },
|
|
93
|
+
* { a: 'invalid' },
|
|
94
|
+
* ]);
|
|
95
|
+
*
|
|
96
|
+
* expect(results[0].result).toBe('3');
|
|
97
|
+
* expect(results[1].result).toBe('5');
|
|
98
|
+
* expect(results[2].error).toBeDefined();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function testGadgetBatch(gadget: BaseGadget, paramSets: Record<string, unknown>[], options?: TestGadgetOptions): Promise<TestGadgetResult[]>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Mock gadget utilities for testing.
|
|
105
|
+
*
|
|
106
|
+
* Provides helpers for creating mock gadgets with configurable behavior
|
|
107
|
+
* and call tracking.
|
|
108
|
+
*
|
|
109
|
+
* @module testing/mock-gadget
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Recorded gadget call for tracking.
|
|
114
|
+
*/
|
|
115
|
+
interface RecordedCall {
|
|
116
|
+
/** Parameters passed to execute() */
|
|
117
|
+
params: Record<string, unknown>;
|
|
118
|
+
/** When the call was made */
|
|
119
|
+
timestamp: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Mock gadget with call tracking capabilities.
|
|
123
|
+
*/
|
|
124
|
+
interface MockGadget extends BaseGadget {
|
|
125
|
+
/** Get all recorded calls */
|
|
126
|
+
getCalls(): RecordedCall[];
|
|
127
|
+
/** Get number of times the gadget was executed */
|
|
128
|
+
getCallCount(): number;
|
|
129
|
+
/** Reset call history */
|
|
130
|
+
resetCalls(): void;
|
|
131
|
+
/** Check if gadget was called with specific params (partial match) */
|
|
132
|
+
wasCalledWith(params: Partial<Record<string, unknown>>): boolean;
|
|
133
|
+
/** Get the last call's parameters */
|
|
134
|
+
getLastCall(): RecordedCall | undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Configuration for creating a mock gadget.
|
|
138
|
+
*/
|
|
139
|
+
interface MockGadgetConfig<TSchema extends ZodType = ZodType> {
|
|
140
|
+
/** Gadget name (required) */
|
|
141
|
+
name: string;
|
|
142
|
+
/** Gadget description */
|
|
143
|
+
description?: string;
|
|
144
|
+
/** Parameter schema */
|
|
145
|
+
schema?: TSchema;
|
|
146
|
+
/** Static result to return */
|
|
147
|
+
result?: string;
|
|
148
|
+
/** Dynamic result based on parameters */
|
|
149
|
+
resultFn?: (params: Record<string, unknown>) => string | Promise<string>;
|
|
150
|
+
/** Error to throw on execution */
|
|
151
|
+
error?: Error | string;
|
|
152
|
+
/** Enable call tracking (default: true) */
|
|
153
|
+
trackCalls?: boolean;
|
|
154
|
+
/** Execution delay in ms */
|
|
155
|
+
delayMs?: number;
|
|
156
|
+
/** Gadget timeout setting */
|
|
157
|
+
timeoutMs?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a mock gadget for testing.
|
|
161
|
+
*
|
|
162
|
+
* @param config - Mock gadget configuration
|
|
163
|
+
* @returns MockGadget instance with call tracking
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* import { createMockGadget } from 'llmist/testing';
|
|
168
|
+
* import { z } from 'zod';
|
|
169
|
+
*
|
|
170
|
+
* const calculator = createMockGadget({
|
|
171
|
+
* name: 'Calculator',
|
|
172
|
+
* schema: z.object({ a: z.number(), b: z.number() }),
|
|
173
|
+
* resultFn: ({ a, b }) => String(Number(a) + Number(b)),
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Use in tests
|
|
177
|
+
* const registry = new GadgetRegistry();
|
|
178
|
+
* registry.registerByClass(calculator);
|
|
179
|
+
*
|
|
180
|
+
* // After running agent...
|
|
181
|
+
* expect(calculator.getCallCount()).toBe(1);
|
|
182
|
+
* expect(calculator.wasCalledWith({ a: 5 })).toBe(true);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function createMockGadget<TSchema extends ZodType>(config: MockGadgetConfig<TSchema>): MockGadget;
|
|
186
|
+
/**
|
|
187
|
+
* Fluent builder for creating mock gadgets.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import { mockGadget } from 'llmist/testing';
|
|
192
|
+
* import { z } from 'zod';
|
|
193
|
+
*
|
|
194
|
+
* const mock = mockGadget()
|
|
195
|
+
* .withName('Weather')
|
|
196
|
+
* .withDescription('Get weather for a city')
|
|
197
|
+
* .withSchema(z.object({ city: z.string() }))
|
|
198
|
+
* .returns('Sunny, 72F')
|
|
199
|
+
* .trackCalls()
|
|
200
|
+
* .build();
|
|
201
|
+
*
|
|
202
|
+
* // Or for error testing
|
|
203
|
+
* const errorMock = mockGadget()
|
|
204
|
+
* .withName('Unstable')
|
|
205
|
+
* .throws('Service unavailable')
|
|
206
|
+
* .build();
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare class MockGadgetBuilder {
|
|
210
|
+
private config;
|
|
211
|
+
/**
|
|
212
|
+
* Set the gadget name.
|
|
213
|
+
*/
|
|
214
|
+
withName(name: string): this;
|
|
215
|
+
/**
|
|
216
|
+
* Set the gadget description.
|
|
217
|
+
*/
|
|
218
|
+
withDescription(description: string): this;
|
|
219
|
+
/**
|
|
220
|
+
* Set the parameter schema.
|
|
221
|
+
*/
|
|
222
|
+
withSchema<T extends ZodType>(schema: T): MockGadgetBuilder;
|
|
223
|
+
/**
|
|
224
|
+
* Set a static result to return.
|
|
225
|
+
*/
|
|
226
|
+
returns(result: string): this;
|
|
227
|
+
/**
|
|
228
|
+
* Set a dynamic result function.
|
|
229
|
+
*/
|
|
230
|
+
returnsAsync(resultFn: (params: Record<string, unknown>) => string | Promise<string>): this;
|
|
231
|
+
/**
|
|
232
|
+
* Make the gadget throw an error on execution.
|
|
233
|
+
*/
|
|
234
|
+
throws(error: Error | string): this;
|
|
235
|
+
/**
|
|
236
|
+
* Add execution delay.
|
|
237
|
+
*/
|
|
238
|
+
withDelay(ms: number): this;
|
|
239
|
+
/**
|
|
240
|
+
* Set timeout for the gadget.
|
|
241
|
+
*/
|
|
242
|
+
withTimeout(ms: number): this;
|
|
243
|
+
/**
|
|
244
|
+
* Enable call tracking (enabled by default).
|
|
245
|
+
*/
|
|
246
|
+
trackCalls(): this;
|
|
247
|
+
/**
|
|
248
|
+
* Disable call tracking.
|
|
249
|
+
*/
|
|
250
|
+
noTracking(): this;
|
|
251
|
+
/**
|
|
252
|
+
* Build the mock gadget.
|
|
253
|
+
*/
|
|
254
|
+
build(): MockGadget;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a fluent builder for mock gadgets.
|
|
258
|
+
*
|
|
259
|
+
* @returns New MockGadgetBuilder instance
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const mock = mockGadget()
|
|
264
|
+
* .withName('Search')
|
|
265
|
+
* .withSchema(z.object({ query: z.string() }))
|
|
266
|
+
* .returnsAsync(async ({ query }) => {
|
|
267
|
+
* return `Results for: ${query}`;
|
|
268
|
+
* })
|
|
269
|
+
* .build();
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
declare function mockGadget(): MockGadgetBuilder;
|
|
273
|
+
|
|
274
|
+
export { type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type RecordedCall, type TestGadgetOptions, type TestGadgetResult, createMockGadget, mockGadget, testGadget, testGadgetBatch };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { B as BaseGadget } from '../mock-stream-D4erlo7B.js';
|
|
2
|
+
export { a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM } from '../mock-stream-D4erlo7B.js';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import 'tslog';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Testing utilities for gadgets.
|
|
8
|
+
*
|
|
9
|
+
* Provides helpers for testing gadgets with schema validation without
|
|
10
|
+
* requiring full executor setup.
|
|
11
|
+
*
|
|
12
|
+
* @module testing/gadget-testing
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Result of testing a gadget.
|
|
17
|
+
*/
|
|
18
|
+
interface TestGadgetResult {
|
|
19
|
+
/** Result string if execution succeeded */
|
|
20
|
+
result?: string;
|
|
21
|
+
/** Error message if validation or execution failed */
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Parameters after validation and default application */
|
|
24
|
+
validatedParams?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for testGadget.
|
|
28
|
+
*/
|
|
29
|
+
interface TestGadgetOptions {
|
|
30
|
+
/**
|
|
31
|
+
* If true, skip schema validation.
|
|
32
|
+
* Useful for testing gadget behavior with invalid parameters.
|
|
33
|
+
*/
|
|
34
|
+
skipValidation?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Test a gadget with schema validation and default application.
|
|
38
|
+
*
|
|
39
|
+
* This helper replicates the validation behavior from GadgetExecutor.execute(),
|
|
40
|
+
* making it easy to test gadgets in isolation without setting up a full
|
|
41
|
+
* registry and executor.
|
|
42
|
+
*
|
|
43
|
+
* @param gadget - Gadget instance to test
|
|
44
|
+
* @param params - Raw parameters (before validation)
|
|
45
|
+
* @param options - Test options
|
|
46
|
+
* @returns Promise resolving to test result
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { testGadget } from 'llmist/testing';
|
|
51
|
+
* import { createGadget } from 'llmist';
|
|
52
|
+
* import { z } from 'zod';
|
|
53
|
+
*
|
|
54
|
+
* const calculator = createGadget({
|
|
55
|
+
* description: 'Add numbers',
|
|
56
|
+
* schema: z.object({
|
|
57
|
+
* a: z.number(),
|
|
58
|
+
* b: z.number().default(0),
|
|
59
|
+
* }),
|
|
60
|
+
* execute: ({ a, b }) => String(a + b),
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Test with defaults applied
|
|
64
|
+
* const result = await testGadget(calculator, { a: 5 });
|
|
65
|
+
* expect(result.result).toBe('5');
|
|
66
|
+
* expect(result.validatedParams).toEqual({ a: 5, b: 0 });
|
|
67
|
+
*
|
|
68
|
+
* // Test validation errors
|
|
69
|
+
* const invalid = await testGadget(calculator, { a: 'not a number' });
|
|
70
|
+
* expect(invalid.error).toContain('Invalid parameters');
|
|
71
|
+
*
|
|
72
|
+
* // Test with validation skipped
|
|
73
|
+
* const skipped = await testGadget(calculator, { a: 5 }, { skipValidation: true });
|
|
74
|
+
* expect(skipped.validatedParams).toEqual({ a: 5 }); // No defaults applied
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function testGadget(gadget: BaseGadget, params: Record<string, unknown>, options?: TestGadgetOptions): Promise<TestGadgetResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Test multiple parameter sets against a gadget.
|
|
80
|
+
*
|
|
81
|
+
* Convenience helper for running the same gadget with different inputs.
|
|
82
|
+
*
|
|
83
|
+
* @param gadget - Gadget instance to test
|
|
84
|
+
* @param paramSets - Array of parameter sets to test
|
|
85
|
+
* @param options - Test options applied to all tests
|
|
86
|
+
* @returns Promise resolving to array of test results
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const results = await testGadgetBatch(calculator, [
|
|
91
|
+
* { a: 1, b: 2 },
|
|
92
|
+
* { a: 5 },
|
|
93
|
+
* { a: 'invalid' },
|
|
94
|
+
* ]);
|
|
95
|
+
*
|
|
96
|
+
* expect(results[0].result).toBe('3');
|
|
97
|
+
* expect(results[1].result).toBe('5');
|
|
98
|
+
* expect(results[2].error).toBeDefined();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function testGadgetBatch(gadget: BaseGadget, paramSets: Record<string, unknown>[], options?: TestGadgetOptions): Promise<TestGadgetResult[]>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Mock gadget utilities for testing.
|
|
105
|
+
*
|
|
106
|
+
* Provides helpers for creating mock gadgets with configurable behavior
|
|
107
|
+
* and call tracking.
|
|
108
|
+
*
|
|
109
|
+
* @module testing/mock-gadget
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Recorded gadget call for tracking.
|
|
114
|
+
*/
|
|
115
|
+
interface RecordedCall {
|
|
116
|
+
/** Parameters passed to execute() */
|
|
117
|
+
params: Record<string, unknown>;
|
|
118
|
+
/** When the call was made */
|
|
119
|
+
timestamp: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Mock gadget with call tracking capabilities.
|
|
123
|
+
*/
|
|
124
|
+
interface MockGadget extends BaseGadget {
|
|
125
|
+
/** Get all recorded calls */
|
|
126
|
+
getCalls(): RecordedCall[];
|
|
127
|
+
/** Get number of times the gadget was executed */
|
|
128
|
+
getCallCount(): number;
|
|
129
|
+
/** Reset call history */
|
|
130
|
+
resetCalls(): void;
|
|
131
|
+
/** Check if gadget was called with specific params (partial match) */
|
|
132
|
+
wasCalledWith(params: Partial<Record<string, unknown>>): boolean;
|
|
133
|
+
/** Get the last call's parameters */
|
|
134
|
+
getLastCall(): RecordedCall | undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Configuration for creating a mock gadget.
|
|
138
|
+
*/
|
|
139
|
+
interface MockGadgetConfig<TSchema extends ZodType = ZodType> {
|
|
140
|
+
/** Gadget name (required) */
|
|
141
|
+
name: string;
|
|
142
|
+
/** Gadget description */
|
|
143
|
+
description?: string;
|
|
144
|
+
/** Parameter schema */
|
|
145
|
+
schema?: TSchema;
|
|
146
|
+
/** Static result to return */
|
|
147
|
+
result?: string;
|
|
148
|
+
/** Dynamic result based on parameters */
|
|
149
|
+
resultFn?: (params: Record<string, unknown>) => string | Promise<string>;
|
|
150
|
+
/** Error to throw on execution */
|
|
151
|
+
error?: Error | string;
|
|
152
|
+
/** Enable call tracking (default: true) */
|
|
153
|
+
trackCalls?: boolean;
|
|
154
|
+
/** Execution delay in ms */
|
|
155
|
+
delayMs?: number;
|
|
156
|
+
/** Gadget timeout setting */
|
|
157
|
+
timeoutMs?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a mock gadget for testing.
|
|
161
|
+
*
|
|
162
|
+
* @param config - Mock gadget configuration
|
|
163
|
+
* @returns MockGadget instance with call tracking
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* import { createMockGadget } from 'llmist/testing';
|
|
168
|
+
* import { z } from 'zod';
|
|
169
|
+
*
|
|
170
|
+
* const calculator = createMockGadget({
|
|
171
|
+
* name: 'Calculator',
|
|
172
|
+
* schema: z.object({ a: z.number(), b: z.number() }),
|
|
173
|
+
* resultFn: ({ a, b }) => String(Number(a) + Number(b)),
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Use in tests
|
|
177
|
+
* const registry = new GadgetRegistry();
|
|
178
|
+
* registry.registerByClass(calculator);
|
|
179
|
+
*
|
|
180
|
+
* // After running agent...
|
|
181
|
+
* expect(calculator.getCallCount()).toBe(1);
|
|
182
|
+
* expect(calculator.wasCalledWith({ a: 5 })).toBe(true);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function createMockGadget<TSchema extends ZodType>(config: MockGadgetConfig<TSchema>): MockGadget;
|
|
186
|
+
/**
|
|
187
|
+
* Fluent builder for creating mock gadgets.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import { mockGadget } from 'llmist/testing';
|
|
192
|
+
* import { z } from 'zod';
|
|
193
|
+
*
|
|
194
|
+
* const mock = mockGadget()
|
|
195
|
+
* .withName('Weather')
|
|
196
|
+
* .withDescription('Get weather for a city')
|
|
197
|
+
* .withSchema(z.object({ city: z.string() }))
|
|
198
|
+
* .returns('Sunny, 72F')
|
|
199
|
+
* .trackCalls()
|
|
200
|
+
* .build();
|
|
201
|
+
*
|
|
202
|
+
* // Or for error testing
|
|
203
|
+
* const errorMock = mockGadget()
|
|
204
|
+
* .withName('Unstable')
|
|
205
|
+
* .throws('Service unavailable')
|
|
206
|
+
* .build();
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare class MockGadgetBuilder {
|
|
210
|
+
private config;
|
|
211
|
+
/**
|
|
212
|
+
* Set the gadget name.
|
|
213
|
+
*/
|
|
214
|
+
withName(name: string): this;
|
|
215
|
+
/**
|
|
216
|
+
* Set the gadget description.
|
|
217
|
+
*/
|
|
218
|
+
withDescription(description: string): this;
|
|
219
|
+
/**
|
|
220
|
+
* Set the parameter schema.
|
|
221
|
+
*/
|
|
222
|
+
withSchema<T extends ZodType>(schema: T): MockGadgetBuilder;
|
|
223
|
+
/**
|
|
224
|
+
* Set a static result to return.
|
|
225
|
+
*/
|
|
226
|
+
returns(result: string): this;
|
|
227
|
+
/**
|
|
228
|
+
* Set a dynamic result function.
|
|
229
|
+
*/
|
|
230
|
+
returnsAsync(resultFn: (params: Record<string, unknown>) => string | Promise<string>): this;
|
|
231
|
+
/**
|
|
232
|
+
* Make the gadget throw an error on execution.
|
|
233
|
+
*/
|
|
234
|
+
throws(error: Error | string): this;
|
|
235
|
+
/**
|
|
236
|
+
* Add execution delay.
|
|
237
|
+
*/
|
|
238
|
+
withDelay(ms: number): this;
|
|
239
|
+
/**
|
|
240
|
+
* Set timeout for the gadget.
|
|
241
|
+
*/
|
|
242
|
+
withTimeout(ms: number): this;
|
|
243
|
+
/**
|
|
244
|
+
* Enable call tracking (enabled by default).
|
|
245
|
+
*/
|
|
246
|
+
trackCalls(): this;
|
|
247
|
+
/**
|
|
248
|
+
* Disable call tracking.
|
|
249
|
+
*/
|
|
250
|
+
noTracking(): this;
|
|
251
|
+
/**
|
|
252
|
+
* Build the mock gadget.
|
|
253
|
+
*/
|
|
254
|
+
build(): MockGadget;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a fluent builder for mock gadgets.
|
|
258
|
+
*
|
|
259
|
+
* @returns New MockGadgetBuilder instance
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const mock = mockGadget()
|
|
264
|
+
* .withName('Search')
|
|
265
|
+
* .withSchema(z.object({ query: z.string() }))
|
|
266
|
+
* .returnsAsync(async ({ query }) => {
|
|
267
|
+
* return `Results for: ${query}`;
|
|
268
|
+
* })
|
|
269
|
+
* .build();
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
declare function mockGadget(): MockGadgetBuilder;
|
|
273
|
+
|
|
274
|
+
export { type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type RecordedCall, type TestGadgetOptions, type TestGadgetResult, createMockGadget, mockGadget, testGadget, testGadgetBatch };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MockBuilder,
|
|
3
|
+
MockGadgetBuilder,
|
|
4
|
+
MockManager,
|
|
5
|
+
MockProviderAdapter,
|
|
6
|
+
createMockAdapter,
|
|
7
|
+
createMockClient,
|
|
8
|
+
createMockGadget,
|
|
9
|
+
createMockStream,
|
|
10
|
+
createTextMockStream,
|
|
11
|
+
getMockManager,
|
|
12
|
+
mockGadget,
|
|
13
|
+
mockLLM,
|
|
14
|
+
testGadget,
|
|
15
|
+
testGadgetBatch
|
|
16
|
+
} from "../chunk-DCW33WV7.js";
|
|
17
|
+
import "../chunk-TP7HE3MN.js";
|
|
18
|
+
export {
|
|
19
|
+
MockBuilder,
|
|
20
|
+
MockGadgetBuilder,
|
|
21
|
+
MockManager,
|
|
22
|
+
MockProviderAdapter,
|
|
23
|
+
createMockAdapter,
|
|
24
|
+
createMockClient,
|
|
25
|
+
createMockGadget,
|
|
26
|
+
createMockStream,
|
|
27
|
+
createTextMockStream,
|
|
28
|
+
getMockManager,
|
|
29
|
+
mockGadget,
|
|
30
|
+
mockLLM,
|
|
31
|
+
testGadget,
|
|
32
|
+
testGadgetBatch
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "llmist",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Universal TypeScript LLM client with streaming-first agent framework. Works with any model - no structured outputs or native tool calling required. Implements its own flexible grammar for function calling.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./testing": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/testing/index.d.ts",
|
|
23
|
+
"default": "./dist/testing/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/testing/index.d.cts",
|
|
27
|
+
"default": "./dist/testing/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"cli": "bun run scripts/cli-runner.ts",
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"lint": "biome lint .",
|
|
36
|
+
"format": "biome format --write .",
|
|
37
|
+
"check": "biome check --write .",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"test:unit": "bun test src/agent src/core src/gadgets src/providers src/testing",
|
|
40
|
+
"test:watch": "bun test --watch",
|
|
41
|
+
"test:e2e": "bun test src/e2e --timeout 60000 --bail 1",
|
|
42
|
+
"test:e2e:watch": "bun test src/e2e --watch --timeout 60000",
|
|
43
|
+
"test:all": "bun run test && bun run test:e2e",
|
|
44
|
+
"clean": "rimraf dist",
|
|
45
|
+
"postinstall": "node scripts/install-hooks.js"
|
|
46
|
+
},
|
|
47
|
+
"bin": {
|
|
48
|
+
"llmist": "dist/cli.cjs"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/zbigniewsobiecki/llmist.git"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist"
|
|
59
|
+
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"llm",
|
|
62
|
+
"ai",
|
|
63
|
+
"agent",
|
|
64
|
+
"agents",
|
|
65
|
+
"openai",
|
|
66
|
+
"anthropic",
|
|
67
|
+
"claude",
|
|
68
|
+
"gemini",
|
|
69
|
+
"gpt",
|
|
70
|
+
"streaming",
|
|
71
|
+
"function-calling",
|
|
72
|
+
"tool-calling",
|
|
73
|
+
"typescript",
|
|
74
|
+
"universal-client",
|
|
75
|
+
"multi-provider",
|
|
76
|
+
"hooks",
|
|
77
|
+
"gadgets"
|
|
78
|
+
],
|
|
79
|
+
"author": "",
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@anthropic-ai/sdk": "^0.69.0",
|
|
83
|
+
"@google/genai": "^1.27.0",
|
|
84
|
+
"chalk": "^5.6.2",
|
|
85
|
+
"commander": "^12.1.0",
|
|
86
|
+
"js-yaml": "^4.1.0",
|
|
87
|
+
"openai": "^4.0.0",
|
|
88
|
+
"tiktoken": "^1.0.22",
|
|
89
|
+
"tslog": "^4.10.2",
|
|
90
|
+
"zod": "^4.1.12"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@biomejs/biome": "^2.3.2",
|
|
94
|
+
"@types/js-yaml": "^4.0.9",
|
|
95
|
+
"@types/node": "^20.12.7",
|
|
96
|
+
"bun-types": "^1.3.2",
|
|
97
|
+
"dotenv": "^17.2.3",
|
|
98
|
+
"rimraf": "^5.0.5",
|
|
99
|
+
"tsup": "^8.3.5",
|
|
100
|
+
"typescript": "^5.4.5"
|
|
101
|
+
}
|
|
102
|
+
}
|