llmist 7.0.0 → 8.0.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/dist/index.cjs +410 -1038
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6073 -4
- package/dist/index.d.ts +6073 -4
- package/dist/index.js +11955 -115
- package/dist/index.js.map +1 -1
- package/package.json +8 -36
- package/LICENSE +0 -21
- package/README.md +0 -511
- package/dist/chunk-5KEZ7SQX.js +0 -1182
- package/dist/chunk-5KEZ7SQX.js.map +0 -1
- package/dist/chunk-SFZIL2VR.js +0 -12214
- package/dist/chunk-SFZIL2VR.js.map +0 -1
- package/dist/cli.cjs +0 -18226
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -7819
- package/dist/cli.js.map +0 -1
- package/dist/mock-stream-r5vjy2Iq.d.cts +0 -6397
- package/dist/mock-stream-r5vjy2Iq.d.ts +0 -6397
- package/dist/testing/index.cjs +0 -12088
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -710
- package/dist/testing/index.d.ts +0 -710
- package/dist/testing/index.js +0 -83
- package/dist/testing/index.js.map +0 -1
package/dist/testing/index.d.cts
DELETED
|
@@ -1,710 +0,0 @@
|
|
|
1
|
-
import { PassThrough, Readable, Writable } from 'node:stream';
|
|
2
|
-
import { L as LLMMessage, A as AbstractGadget, I as IConversationManager, a as LLMStream, b as LLMStreamChunk } from '../mock-stream-r5vjy2Iq.cjs';
|
|
3
|
-
export { j as MockAudioData, d as MockBuilder, k as MockImageData, f as MockManager, l as MockMatcher, n as MockMatcherContext, o as MockOptions, M as MockProviderAdapter, p as MockRegistration, q as MockResponse, r as MockStats, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM } from '../mock-stream-r5vjy2Iq.cjs';
|
|
4
|
-
import { ZodType } from 'zod';
|
|
5
|
-
import 'tslog';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* CLI testing utilities for llmist.
|
|
9
|
-
* Provides helpers for testing CLI commands without real I/O.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for creating a test environment.
|
|
14
|
-
*/
|
|
15
|
-
interface TestEnvironmentOptions {
|
|
16
|
-
/** Input to provide via stdin (string or line array) */
|
|
17
|
-
stdin?: string | string[];
|
|
18
|
-
/** Whether stdin is a TTY (default: false) */
|
|
19
|
-
isTTY?: boolean;
|
|
20
|
-
/** Environment variables to set */
|
|
21
|
-
env?: Record<string, string>;
|
|
22
|
-
/** Command line arguments (default: ["node", "llmist"]) */
|
|
23
|
-
argv?: string[];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A test environment with captured I/O streams.
|
|
27
|
-
*/
|
|
28
|
-
interface TestEnvironment {
|
|
29
|
-
/** Stdin readable stream */
|
|
30
|
-
stdin: Readable;
|
|
31
|
-
/** Stdout writable stream (PassThrough for capturing) */
|
|
32
|
-
stdout: PassThrough;
|
|
33
|
-
/** Stderr writable stream (PassThrough for capturing) */
|
|
34
|
-
stderr: PassThrough;
|
|
35
|
-
/** Whether stdin is TTY */
|
|
36
|
-
isTTY: boolean;
|
|
37
|
-
/** Command line arguments */
|
|
38
|
-
argv: string[];
|
|
39
|
-
/** Environment variables */
|
|
40
|
-
env: Record<string, string>;
|
|
41
|
-
/** Exit code if set */
|
|
42
|
-
exitCode?: number;
|
|
43
|
-
/** Function to set exit code */
|
|
44
|
-
setExitCode: (code: number) => void;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a test environment with mocked I/O streams.
|
|
48
|
-
*
|
|
49
|
-
* @param options - Configuration options
|
|
50
|
-
* @returns A test environment with captured streams
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const env = createTestEnvironment({
|
|
55
|
-
* stdin: '{"param": "value"}',
|
|
56
|
-
* isTTY: false
|
|
57
|
-
* });
|
|
58
|
-
*
|
|
59
|
-
* // Pass to CLI command
|
|
60
|
-
* await executeCommand(env);
|
|
61
|
-
*
|
|
62
|
-
* // Check output
|
|
63
|
-
* const output = await collectOutput(env.stdout);
|
|
64
|
-
* expect(output).toContain("Success");
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function createTestEnvironment(options?: TestEnvironmentOptions): TestEnvironment;
|
|
68
|
-
/**
|
|
69
|
-
* Create a readable stream from a string or array of lines.
|
|
70
|
-
*
|
|
71
|
-
* @param input - String content or array of lines
|
|
72
|
-
* @returns A Readable stream
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const stream = createMockReadable("line1\nline2\n");
|
|
77
|
-
* // or
|
|
78
|
-
* const stream = createMockReadable(["line1", "line2"]);
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
declare function createMockReadable(input?: string | string[]): Readable;
|
|
82
|
-
/**
|
|
83
|
-
* Create a writable stream that collects all written data.
|
|
84
|
-
*
|
|
85
|
-
* @returns A writable stream with getData() method
|
|
86
|
-
*/
|
|
87
|
-
declare function createMockWritable(): Writable & {
|
|
88
|
-
getData(): string;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Collect all output from a PassThrough stream.
|
|
92
|
-
* Waits for the stream to end before returning.
|
|
93
|
-
*
|
|
94
|
-
* @param stream - The stream to collect from
|
|
95
|
-
* @param timeout - Maximum time to wait in ms (default: 5000)
|
|
96
|
-
* @returns All data written to the stream
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const output = await collectOutput(env.stdout);
|
|
101
|
-
* expect(output).toContain("Expected text");
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
declare function collectOutput(stream: PassThrough, timeout?: number): Promise<string>;
|
|
105
|
-
/**
|
|
106
|
-
* Collect output without waiting for stream end.
|
|
107
|
-
* Returns immediately with whatever has been written.
|
|
108
|
-
*
|
|
109
|
-
* @param stream - The stream to read from
|
|
110
|
-
* @returns Currently buffered data
|
|
111
|
-
*/
|
|
112
|
-
declare function getBufferedOutput(stream: PassThrough): string;
|
|
113
|
-
/**
|
|
114
|
-
* Create a mock prompt function for testing interactive input.
|
|
115
|
-
*
|
|
116
|
-
* @param responses - Array of responses to return in order
|
|
117
|
-
* @returns A prompt function that returns the next response
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* const prompt = createMockPrompt(["yes", "no", "maybe"]);
|
|
122
|
-
* expect(await prompt("Question 1?")).toBe("yes");
|
|
123
|
-
* expect(await prompt("Question 2?")).toBe("no");
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
declare function createMockPrompt(responses: string[]): (question: string) => Promise<string>;
|
|
127
|
-
/**
|
|
128
|
-
* Mock prompt that records questions and returns configured responses.
|
|
129
|
-
*/
|
|
130
|
-
declare class MockPromptRecorder {
|
|
131
|
-
private responses;
|
|
132
|
-
private index;
|
|
133
|
-
private questions;
|
|
134
|
-
constructor(responses: string[]);
|
|
135
|
-
/**
|
|
136
|
-
* The prompt function to use in tests.
|
|
137
|
-
*/
|
|
138
|
-
prompt: (question: string) => Promise<string>;
|
|
139
|
-
/**
|
|
140
|
-
* Get all questions that were asked.
|
|
141
|
-
*/
|
|
142
|
-
getQuestions(): string[];
|
|
143
|
-
/**
|
|
144
|
-
* Get the number of questions asked.
|
|
145
|
-
*/
|
|
146
|
-
getQuestionCount(): number;
|
|
147
|
-
/**
|
|
148
|
-
* Reset the recorder state.
|
|
149
|
-
*/
|
|
150
|
-
reset(newResponses?: string[]): void;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Wait for a condition to be true, with timeout.
|
|
154
|
-
* Useful for async testing scenarios.
|
|
155
|
-
*
|
|
156
|
-
* @param condition - Function that returns true when condition is met
|
|
157
|
-
* @param timeout - Maximum time to wait in ms (default: 5000)
|
|
158
|
-
* @param interval - Check interval in ms (default: 50)
|
|
159
|
-
*/
|
|
160
|
-
declare function waitFor(condition: () => boolean, timeout?: number, interval?: number): Promise<void>;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Conversation fixture generators for testing.
|
|
164
|
-
* Provides utilities for creating test conversation data.
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Create a conversation with a specified number of turns.
|
|
169
|
-
* Each turn consists of a user message and an assistant response.
|
|
170
|
-
*
|
|
171
|
-
* @param turnCount - Number of conversation turns to generate
|
|
172
|
-
* @param options - Configuration options
|
|
173
|
-
* @returns Array of LLMMessages representing the conversation
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const messages = createConversation(5);
|
|
178
|
-
* // Creates 10 messages: 5 user + 5 assistant
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
declare function createConversation(turnCount: number, options?: {
|
|
182
|
-
/** Prefix for user messages (default: "User message") */
|
|
183
|
-
userPrefix?: string;
|
|
184
|
-
/** Prefix for assistant messages (default: "Assistant response") */
|
|
185
|
-
assistantPrefix?: string;
|
|
186
|
-
/** Base content length per message (default: 100 chars) */
|
|
187
|
-
contentLength?: number;
|
|
188
|
-
}): LLMMessage[];
|
|
189
|
-
/**
|
|
190
|
-
* Create a conversation with gadget calls interspersed.
|
|
191
|
-
* Simulates an agent conversation with tool usage.
|
|
192
|
-
*
|
|
193
|
-
* @param turnCount - Number of conversation turns
|
|
194
|
-
* @param gadgetCallsPerTurn - Number of gadget calls per assistant turn
|
|
195
|
-
* @returns Array of LLMMessages including gadget call/result pairs
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* const messages = createConversationWithGadgets(3, 2);
|
|
200
|
-
* // Creates: user, assistant+gadget, gadget-result, assistant+gadget, gadget-result, assistant (per turn)
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
declare function createConversationWithGadgets(turnCount: number, gadgetCallsPerTurn?: number, options?: {
|
|
204
|
-
/** Gadget names to cycle through (default: ["search", "calculate", "read"]) */
|
|
205
|
-
gadgetNames?: string[];
|
|
206
|
-
/** Content length for messages */
|
|
207
|
-
contentLength?: number;
|
|
208
|
-
}): LLMMessage[];
|
|
209
|
-
/**
|
|
210
|
-
* Estimate token count for a message array.
|
|
211
|
-
* Uses a simple 4-characters-per-token heuristic.
|
|
212
|
-
*
|
|
213
|
-
* @param messages - Messages to estimate tokens for
|
|
214
|
-
* @returns Estimated token count
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* const messages = createConversation(10);
|
|
219
|
-
* const tokens = estimateTokens(messages);
|
|
220
|
-
* // Returns approximate token count
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
declare function estimateTokens(messages: LLMMessage[]): number;
|
|
224
|
-
/**
|
|
225
|
-
* Create a single user message.
|
|
226
|
-
*/
|
|
227
|
-
declare function createUserMessage(content: string): LLMMessage;
|
|
228
|
-
/**
|
|
229
|
-
* Create a single assistant message.
|
|
230
|
-
*/
|
|
231
|
-
declare function createAssistantMessage(content: string): LLMMessage;
|
|
232
|
-
/**
|
|
233
|
-
* Create a system message.
|
|
234
|
-
*/
|
|
235
|
-
declare function createSystemMessage(content: string): LLMMessage;
|
|
236
|
-
/**
|
|
237
|
-
* Create a minimal conversation for quick tests.
|
|
238
|
-
* Returns a single turn: one user message and one assistant response.
|
|
239
|
-
*/
|
|
240
|
-
declare function createMinimalConversation(): LLMMessage[];
|
|
241
|
-
/**
|
|
242
|
-
* Create a conversation that exceeds a target token count.
|
|
243
|
-
* Useful for testing compaction triggers.
|
|
244
|
-
*
|
|
245
|
-
* @param targetTokens - Minimum token count to exceed
|
|
246
|
-
* @param options - Configuration options
|
|
247
|
-
* @returns Conversation with at least targetTokens tokens
|
|
248
|
-
*/
|
|
249
|
-
declare function createLargeConversation(targetTokens: number, options?: {
|
|
250
|
-
/** Average tokens per turn (default: 200) */
|
|
251
|
-
tokensPerTurn?: number;
|
|
252
|
-
}): LLMMessage[];
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Testing utilities for gadgets.
|
|
256
|
-
*
|
|
257
|
-
* Provides helpers for testing gadgets with schema validation without
|
|
258
|
-
* requiring full executor setup.
|
|
259
|
-
*
|
|
260
|
-
* @module testing/gadget-testing
|
|
261
|
-
*/
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Result of testing a gadget.
|
|
265
|
-
*/
|
|
266
|
-
interface TestGadgetResult {
|
|
267
|
-
/** Result string if execution succeeded */
|
|
268
|
-
result?: string;
|
|
269
|
-
/** Error message if validation or execution failed */
|
|
270
|
-
error?: string;
|
|
271
|
-
/** Parameters after validation and default application */
|
|
272
|
-
validatedParams?: Record<string, unknown>;
|
|
273
|
-
/** Cost reported by the gadget in USD (e.g., 0.001 for $0.001) */
|
|
274
|
-
cost?: number;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Options for testGadget.
|
|
278
|
-
*/
|
|
279
|
-
interface TestGadgetOptions {
|
|
280
|
-
/**
|
|
281
|
-
* If true, skip schema validation.
|
|
282
|
-
* Useful for testing gadget behavior with invalid parameters.
|
|
283
|
-
*/
|
|
284
|
-
skipValidation?: boolean;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Test a gadget with schema validation and default application.
|
|
288
|
-
*
|
|
289
|
-
* This helper replicates the validation behavior from GadgetExecutor.execute(),
|
|
290
|
-
* making it easy to test gadgets in isolation without setting up a full
|
|
291
|
-
* registry and executor.
|
|
292
|
-
*
|
|
293
|
-
* @param gadget - Gadget instance to test
|
|
294
|
-
* @param params - Raw parameters (before validation)
|
|
295
|
-
* @param options - Test options
|
|
296
|
-
* @returns Promise resolving to test result
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```typescript
|
|
300
|
-
* import { testGadget } from 'llmist/testing';
|
|
301
|
-
* import { createGadget } from 'llmist';
|
|
302
|
-
* import { z } from 'zod';
|
|
303
|
-
*
|
|
304
|
-
* const calculator = createGadget({
|
|
305
|
-
* description: 'Add numbers',
|
|
306
|
-
* schema: z.object({
|
|
307
|
-
* a: z.number(),
|
|
308
|
-
* b: z.number().default(0),
|
|
309
|
-
* }),
|
|
310
|
-
* execute: ({ a, b }) => String(a + b),
|
|
311
|
-
* });
|
|
312
|
-
*
|
|
313
|
-
* // Test with defaults applied
|
|
314
|
-
* const result = await testGadget(calculator, { a: 5 });
|
|
315
|
-
* expect(result.result).toBe('5');
|
|
316
|
-
* expect(result.validatedParams).toEqual({ a: 5, b: 0 });
|
|
317
|
-
*
|
|
318
|
-
* // Test validation errors
|
|
319
|
-
* const invalid = await testGadget(calculator, { a: 'not a number' });
|
|
320
|
-
* expect(invalid.error).toContain('Invalid parameters');
|
|
321
|
-
*
|
|
322
|
-
* // Test with validation skipped
|
|
323
|
-
* const skipped = await testGadget(calculator, { a: 5 }, { skipValidation: true });
|
|
324
|
-
* expect(skipped.validatedParams).toEqual({ a: 5 }); // No defaults applied
|
|
325
|
-
* ```
|
|
326
|
-
*/
|
|
327
|
-
declare function testGadget(gadget: AbstractGadget, params: Record<string, unknown>, options?: TestGadgetOptions): Promise<TestGadgetResult>;
|
|
328
|
-
/**
|
|
329
|
-
* Test multiple parameter sets against a gadget.
|
|
330
|
-
*
|
|
331
|
-
* Convenience helper for running the same gadget with different inputs.
|
|
332
|
-
*
|
|
333
|
-
* @param gadget - Gadget instance to test
|
|
334
|
-
* @param paramSets - Array of parameter sets to test
|
|
335
|
-
* @param options - Test options applied to all tests
|
|
336
|
-
* @returns Promise resolving to array of test results
|
|
337
|
-
*
|
|
338
|
-
* @example
|
|
339
|
-
* ```typescript
|
|
340
|
-
* const results = await testGadgetBatch(calculator, [
|
|
341
|
-
* { a: 1, b: 2 },
|
|
342
|
-
* { a: 5 },
|
|
343
|
-
* { a: 'invalid' },
|
|
344
|
-
* ]);
|
|
345
|
-
*
|
|
346
|
-
* expect(results[0].result).toBe('3');
|
|
347
|
-
* expect(results[1].result).toBe('5');
|
|
348
|
-
* expect(results[2].error).toBeDefined();
|
|
349
|
-
* ```
|
|
350
|
-
*/
|
|
351
|
-
declare function testGadgetBatch(gadget: AbstractGadget, paramSets: Record<string, unknown>[], options?: TestGadgetOptions): Promise<TestGadgetResult[]>;
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Mock ConversationManager for testing compaction and agent components.
|
|
355
|
-
* Implements IConversationManager interface with test-friendly features.
|
|
356
|
-
*/
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* A mock implementation of IConversationManager for testing.
|
|
360
|
-
* Tracks all operations and allows inspection of state changes.
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* const mockConvo = new MockConversationManager([
|
|
365
|
-
* { role: "user", content: "Hello" },
|
|
366
|
-
* { role: "assistant", content: "Hi!" }
|
|
367
|
-
* ]);
|
|
368
|
-
*
|
|
369
|
-
* // Use in compaction tests
|
|
370
|
-
* compactionManager.checkAndCompact(mockConvo, 1);
|
|
371
|
-
*
|
|
372
|
-
* // Assert on state changes
|
|
373
|
-
* expect(mockConvo.wasReplaceHistoryCalled()).toBe(true);
|
|
374
|
-
* expect(mockConvo.getReplacementHistory()).toHaveLength(2);
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
declare class MockConversationManager implements IConversationManager {
|
|
378
|
-
private history;
|
|
379
|
-
private readonly baseMessages;
|
|
380
|
-
private replacementHistory;
|
|
381
|
-
private replaceHistoryCallCount;
|
|
382
|
-
private addedMessages;
|
|
383
|
-
constructor(history?: LLMMessage[], baseMessages?: LLMMessage[]);
|
|
384
|
-
addUserMessage(content: string): void;
|
|
385
|
-
addAssistantMessage(content: string): void;
|
|
386
|
-
addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, invocationId: string): void;
|
|
387
|
-
getMessages(): LLMMessage[];
|
|
388
|
-
getHistoryMessages(): LLMMessage[];
|
|
389
|
-
getBaseMessages(): LLMMessage[];
|
|
390
|
-
replaceHistory(newHistory: LLMMessage[]): void;
|
|
391
|
-
/**
|
|
392
|
-
* Check if replaceHistory was called.
|
|
393
|
-
*/
|
|
394
|
-
wasReplaceHistoryCalled(): boolean;
|
|
395
|
-
/**
|
|
396
|
-
* Get the number of times replaceHistory was called.
|
|
397
|
-
*/
|
|
398
|
-
getReplaceHistoryCallCount(): number;
|
|
399
|
-
/**
|
|
400
|
-
* Get the most recent history passed to replaceHistory.
|
|
401
|
-
* Returns undefined if replaceHistory was never called.
|
|
402
|
-
*/
|
|
403
|
-
getReplacementHistory(): LLMMessage[] | undefined;
|
|
404
|
-
/**
|
|
405
|
-
* Get all messages that were added via add* methods.
|
|
406
|
-
*/
|
|
407
|
-
getAddedMessages(): LLMMessage[];
|
|
408
|
-
/**
|
|
409
|
-
* Reset all tracking state while preserving the conversation.
|
|
410
|
-
*/
|
|
411
|
-
resetTracking(): void;
|
|
412
|
-
/**
|
|
413
|
-
* Completely reset the mock to initial state.
|
|
414
|
-
* Note: baseMessages cannot be changed after construction.
|
|
415
|
-
*/
|
|
416
|
-
reset(history?: LLMMessage[]): void;
|
|
417
|
-
/**
|
|
418
|
-
* Set the history directly (for test setup).
|
|
419
|
-
*/
|
|
420
|
-
setHistory(messages: LLMMessage[]): void;
|
|
421
|
-
/**
|
|
422
|
-
* Get the current history length.
|
|
423
|
-
*/
|
|
424
|
-
getHistoryLength(): number;
|
|
425
|
-
/**
|
|
426
|
-
* Get total message count (base + history).
|
|
427
|
-
*/
|
|
428
|
-
getTotalMessageCount(): number;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Create a mock conversation manager with a pre-populated conversation.
|
|
432
|
-
*
|
|
433
|
-
* @param turnCount - Number of conversation turns
|
|
434
|
-
* @param baseMessages - Optional base messages (system prompts)
|
|
435
|
-
* @returns Configured MockConversationManager
|
|
436
|
-
*/
|
|
437
|
-
declare function createMockConversationManager(turnCount: number, baseMessages?: LLMMessage[]): MockConversationManager;
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Mock gadget utilities for testing.
|
|
441
|
-
*
|
|
442
|
-
* Provides helpers for creating mock gadgets with configurable behavior
|
|
443
|
-
* and call tracking.
|
|
444
|
-
*
|
|
445
|
-
* @module testing/mock-gadget
|
|
446
|
-
*/
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Recorded gadget call for tracking.
|
|
450
|
-
*/
|
|
451
|
-
interface RecordedCall {
|
|
452
|
-
/** Parameters passed to execute() */
|
|
453
|
-
params: Record<string, unknown>;
|
|
454
|
-
/** When the call was made */
|
|
455
|
-
timestamp: number;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Mock gadget with call tracking capabilities.
|
|
459
|
-
*/
|
|
460
|
-
interface MockGadget extends AbstractGadget {
|
|
461
|
-
/** Get all recorded calls */
|
|
462
|
-
getCalls(): RecordedCall[];
|
|
463
|
-
/** Get number of times the gadget was executed */
|
|
464
|
-
getCallCount(): number;
|
|
465
|
-
/** Reset call history */
|
|
466
|
-
resetCalls(): void;
|
|
467
|
-
/** Check if gadget was called with specific params (partial match) */
|
|
468
|
-
wasCalledWith(params: Partial<Record<string, unknown>>): boolean;
|
|
469
|
-
/** Get the last call's parameters */
|
|
470
|
-
getLastCall(): RecordedCall | undefined;
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Configuration for creating a mock gadget.
|
|
474
|
-
*/
|
|
475
|
-
interface MockGadgetConfig<TSchema extends ZodType = ZodType> {
|
|
476
|
-
/** Gadget name (required) */
|
|
477
|
-
name: string;
|
|
478
|
-
/** Gadget description */
|
|
479
|
-
description?: string;
|
|
480
|
-
/** Parameter schema */
|
|
481
|
-
schema?: TSchema;
|
|
482
|
-
/** Static result to return */
|
|
483
|
-
result?: string;
|
|
484
|
-
/** Dynamic result based on parameters */
|
|
485
|
-
resultFn?: (params: Record<string, unknown>) => string | Promise<string>;
|
|
486
|
-
/** Error to throw on execution */
|
|
487
|
-
error?: Error | string;
|
|
488
|
-
/** Enable call tracking (default: true) */
|
|
489
|
-
trackCalls?: boolean;
|
|
490
|
-
/** Execution delay in ms */
|
|
491
|
-
delayMs?: number;
|
|
492
|
-
/** Gadget timeout setting */
|
|
493
|
-
timeoutMs?: number;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Create a mock gadget for testing.
|
|
497
|
-
*
|
|
498
|
-
* @param config - Mock gadget configuration
|
|
499
|
-
* @returns MockGadget instance with call tracking
|
|
500
|
-
*
|
|
501
|
-
* @example
|
|
502
|
-
* ```typescript
|
|
503
|
-
* import { createMockGadget } from 'llmist/testing';
|
|
504
|
-
* import { z } from 'zod';
|
|
505
|
-
*
|
|
506
|
-
* const calculator = createMockGadget({
|
|
507
|
-
* name: 'Calculator',
|
|
508
|
-
* schema: z.object({ a: z.number(), b: z.number() }),
|
|
509
|
-
* resultFn: ({ a, b }) => String(Number(a) + Number(b)),
|
|
510
|
-
* });
|
|
511
|
-
*
|
|
512
|
-
* // Use in tests
|
|
513
|
-
* const registry = new GadgetRegistry();
|
|
514
|
-
* registry.registerByClass(calculator);
|
|
515
|
-
*
|
|
516
|
-
* // After running agent...
|
|
517
|
-
* expect(calculator.getCallCount()).toBe(1);
|
|
518
|
-
* expect(calculator.wasCalledWith({ a: 5 })).toBe(true);
|
|
519
|
-
* ```
|
|
520
|
-
*/
|
|
521
|
-
declare function createMockGadget<TSchema extends ZodType>(config: MockGadgetConfig<TSchema>): MockGadget;
|
|
522
|
-
/**
|
|
523
|
-
* Fluent builder for creating mock gadgets.
|
|
524
|
-
*
|
|
525
|
-
* @example
|
|
526
|
-
* ```typescript
|
|
527
|
-
* import { mockGadget } from 'llmist/testing';
|
|
528
|
-
* import { z } from 'zod';
|
|
529
|
-
*
|
|
530
|
-
* const mock = mockGadget()
|
|
531
|
-
* .withName('Weather')
|
|
532
|
-
* .withDescription('Get weather for a city')
|
|
533
|
-
* .withSchema(z.object({ city: z.string() }))
|
|
534
|
-
* .returns('Sunny, 72F')
|
|
535
|
-
* .trackCalls()
|
|
536
|
-
* .build();
|
|
537
|
-
*
|
|
538
|
-
* // Or for error testing
|
|
539
|
-
* const errorMock = mockGadget()
|
|
540
|
-
* .withName('Unstable')
|
|
541
|
-
* .throws('Service unavailable')
|
|
542
|
-
* .build();
|
|
543
|
-
* ```
|
|
544
|
-
*/
|
|
545
|
-
declare class MockGadgetBuilder {
|
|
546
|
-
private config;
|
|
547
|
-
/**
|
|
548
|
-
* Set the gadget name.
|
|
549
|
-
*/
|
|
550
|
-
withName(name: string): this;
|
|
551
|
-
/**
|
|
552
|
-
* Set the gadget description.
|
|
553
|
-
*/
|
|
554
|
-
withDescription(description: string): this;
|
|
555
|
-
/**
|
|
556
|
-
* Set the parameter schema.
|
|
557
|
-
*/
|
|
558
|
-
withSchema<T extends ZodType>(schema: T): MockGadgetBuilder;
|
|
559
|
-
/**
|
|
560
|
-
* Set a static result to return.
|
|
561
|
-
*/
|
|
562
|
-
returns(result: string): this;
|
|
563
|
-
/**
|
|
564
|
-
* Set a dynamic result function.
|
|
565
|
-
*/
|
|
566
|
-
returnsAsync(resultFn: (params: Record<string, unknown>) => string | Promise<string>): this;
|
|
567
|
-
/**
|
|
568
|
-
* Make the gadget throw an error on execution.
|
|
569
|
-
*/
|
|
570
|
-
throws(error: Error | string): this;
|
|
571
|
-
/**
|
|
572
|
-
* Add execution delay.
|
|
573
|
-
*/
|
|
574
|
-
withDelay(ms: number): this;
|
|
575
|
-
/**
|
|
576
|
-
* Set timeout for the gadget.
|
|
577
|
-
*/
|
|
578
|
-
withTimeout(ms: number): this;
|
|
579
|
-
/**
|
|
580
|
-
* Enable call tracking (enabled by default).
|
|
581
|
-
*/
|
|
582
|
-
trackCalls(): this;
|
|
583
|
-
/**
|
|
584
|
-
* Disable call tracking.
|
|
585
|
-
*/
|
|
586
|
-
noTracking(): this;
|
|
587
|
-
/**
|
|
588
|
-
* Build the mock gadget.
|
|
589
|
-
*/
|
|
590
|
-
build(): MockGadget;
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Create a fluent builder for mock gadgets.
|
|
594
|
-
*
|
|
595
|
-
* @returns New MockGadgetBuilder instance
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```typescript
|
|
599
|
-
* const mock = mockGadget()
|
|
600
|
-
* .withName('Search')
|
|
601
|
-
* .withSchema(z.object({ query: z.string() }))
|
|
602
|
-
* .returnsAsync(async ({ query }) => {
|
|
603
|
-
* return `Results for: ${query}`;
|
|
604
|
-
* })
|
|
605
|
-
* .build();
|
|
606
|
-
* ```
|
|
607
|
-
*/
|
|
608
|
-
declare function mockGadget(): MockGadgetBuilder;
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Stream testing utilities for llmist.
|
|
612
|
-
* Provides helpers for creating and consuming test streams.
|
|
613
|
-
*/
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Create an async iterable stream from an array of chunks.
|
|
617
|
-
* Useful for creating deterministic test streams.
|
|
618
|
-
*
|
|
619
|
-
* @param chunks - Array of chunks to yield
|
|
620
|
-
* @returns An async iterable that yields the chunks in order
|
|
621
|
-
*
|
|
622
|
-
* @example
|
|
623
|
-
* ```typescript
|
|
624
|
-
* const stream = createTestStream([
|
|
625
|
-
* { text: "Hello " },
|
|
626
|
-
* { text: "world", finishReason: "stop", usage: { inputTokens: 10, outputTokens: 5 } }
|
|
627
|
-
* ]);
|
|
628
|
-
* ```
|
|
629
|
-
*/
|
|
630
|
-
declare function createTestStream(chunks: LLMStreamChunk[]): LLMStream;
|
|
631
|
-
/**
|
|
632
|
-
* Create a stream that yields text in specified chunks.
|
|
633
|
-
* Automatically adds finishReason and usage to the final chunk.
|
|
634
|
-
*
|
|
635
|
-
* @param text - The full text to stream
|
|
636
|
-
* @param options - Configuration options
|
|
637
|
-
* @returns An async iterable stream
|
|
638
|
-
*
|
|
639
|
-
* @example
|
|
640
|
-
* ```typescript
|
|
641
|
-
* const stream = createTextStream("Hello, world!", { chunkSize: 5 });
|
|
642
|
-
* // Yields: "Hello", ", wor", "ld!"
|
|
643
|
-
* ```
|
|
644
|
-
*/
|
|
645
|
-
declare function createTextStream(text: string, options?: {
|
|
646
|
-
/** Size of each chunk (default: entire text as one chunk) */
|
|
647
|
-
chunkSize?: number;
|
|
648
|
-
/** Delay before starting the stream in ms */
|
|
649
|
-
delayMs?: number;
|
|
650
|
-
/** Delay between chunks in ms */
|
|
651
|
-
chunkDelayMs?: number;
|
|
652
|
-
/** Custom usage stats */
|
|
653
|
-
usage?: {
|
|
654
|
-
inputTokens: number;
|
|
655
|
-
outputTokens: number;
|
|
656
|
-
totalTokens: number;
|
|
657
|
-
};
|
|
658
|
-
/** Custom finish reason (default: "stop") */
|
|
659
|
-
finishReason?: string;
|
|
660
|
-
}): LLMStream;
|
|
661
|
-
/**
|
|
662
|
-
* Collect all chunks from a stream into an array.
|
|
663
|
-
* Useful for asserting on stream output in tests.
|
|
664
|
-
*
|
|
665
|
-
* @param stream - The stream to collect from
|
|
666
|
-
* @returns Array of all chunks from the stream
|
|
667
|
-
*
|
|
668
|
-
* @example
|
|
669
|
-
* ```typescript
|
|
670
|
-
* const chunks = await collectStream(myStream);
|
|
671
|
-
* expect(chunks).toHaveLength(3);
|
|
672
|
-
* expect(chunks[2].finishReason).toBe("stop");
|
|
673
|
-
* ```
|
|
674
|
-
*/
|
|
675
|
-
declare function collectStream(stream: LLMStream): Promise<LLMStreamChunk[]>;
|
|
676
|
-
/**
|
|
677
|
-
* Collect all text from a stream into a single string.
|
|
678
|
-
*
|
|
679
|
-
* @param stream - The stream to collect from
|
|
680
|
-
* @returns Concatenated text from all chunks
|
|
681
|
-
*
|
|
682
|
-
* @example
|
|
683
|
-
* ```typescript
|
|
684
|
-
* const text = await collectStreamText(myStream);
|
|
685
|
-
* expect(text).toBe("Hello, world!");
|
|
686
|
-
* ```
|
|
687
|
-
*/
|
|
688
|
-
declare function collectStreamText(stream: LLMStream): Promise<string>;
|
|
689
|
-
/**
|
|
690
|
-
* Get the final chunk from a stream (containing finishReason and usage).
|
|
691
|
-
*
|
|
692
|
-
* @param stream - The stream to consume
|
|
693
|
-
* @returns The final chunk from the stream
|
|
694
|
-
*/
|
|
695
|
-
declare function getStreamFinalChunk(stream: LLMStream): Promise<LLMStreamChunk | undefined>;
|
|
696
|
-
/**
|
|
697
|
-
* Create an empty stream that yields nothing.
|
|
698
|
-
* Useful for testing edge cases.
|
|
699
|
-
*/
|
|
700
|
-
declare function createEmptyStream(): LLMStream;
|
|
701
|
-
/**
|
|
702
|
-
* Create a stream that throws an error after yielding some chunks.
|
|
703
|
-
* Useful for testing error handling.
|
|
704
|
-
*
|
|
705
|
-
* @param chunksBeforeError - Chunks to yield before throwing
|
|
706
|
-
* @param error - The error to throw
|
|
707
|
-
*/
|
|
708
|
-
declare function createErrorStream(chunksBeforeError: LLMStreamChunk[], error: Error): LLMStream;
|
|
709
|
-
|
|
710
|
-
export { MockConversationManager, type MockGadget, MockGadgetBuilder, type MockGadgetConfig, MockPromptRecorder, type RecordedCall, type TestEnvironment, type TestEnvironmentOptions, type TestGadgetOptions, type TestGadgetResult, collectOutput, collectStream, collectStreamText, createAssistantMessage, createConversation, createConversationWithGadgets, createEmptyStream, createErrorStream, createLargeConversation, createMinimalConversation, createMockConversationManager, createMockGadget, createMockPrompt, createMockReadable, createMockWritable, createSystemMessage, createTestEnvironment, createTestStream, createTextStream, createUserMessage, estimateTokens, getBufferedOutput, getStreamFinalChunk, mockGadget, testGadget, testGadgetBatch, waitFor };
|