@agtlantis/core 0.4.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/README.md +267 -0
- package/dist/base-provider-C3mFLNiN.d.cts +1236 -0
- package/dist/base-provider-C3mFLNiN.d.ts +1236 -0
- package/dist/index.cjs +3188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1502 -0
- package/dist/index.d.ts +1502 -0
- package/dist/index.js +3082 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/index.cjs +2144 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +516 -0
- package/dist/testing/index.d.ts +516 -0
- package/dist/testing/index.js +2098 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { af as LLMCallRecord, ad as ToolCallSummary, ag as AdditionalCost, ah as SessionSummary, m as CompletionEvent, S as StreamingExecution, f as SessionEvent, E as ErrorEvent, p as FileManager, L as Logger, B as BaseProvider, b as ProviderPricing, j as SimpleSession, d as StreamingSession, h as ExtractResult, v as EmittableEventInput } from '../base-provider-C3mFLNiN.js';
|
|
2
|
+
import { LanguageModelUsage, LanguageModel } from 'ai';
|
|
3
|
+
import { MockLanguageModelV3 } from 'ai/test';
|
|
4
|
+
export { MockLanguageModelV3, simulateReadableStream } from 'ai/test';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
declare const TEST_API_KEY = "test-api-key";
|
|
8
|
+
declare function createMockUsage$1(overrides?: Partial<LanguageModelUsage>): LanguageModelUsage;
|
|
9
|
+
interface TestBaseEvent$1 {
|
|
10
|
+
type: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
data?: string;
|
|
13
|
+
}
|
|
14
|
+
type TestEvent$1 = TestBaseEvent$1 | CompletionEvent<string>;
|
|
15
|
+
interface TestResult {
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
declare function createTestEvent(type: string, overrides?: Partial<Omit<TestBaseEvent$1, 'type'>>): TestBaseEvent$1;
|
|
19
|
+
interface MockSessionSummaryOptions {
|
|
20
|
+
/** @deprecated Use startTime instead. totalDuration is computed from startTime. */
|
|
21
|
+
totalDuration?: number;
|
|
22
|
+
startTime?: number;
|
|
23
|
+
totalLLMUsage?: LanguageModelUsage;
|
|
24
|
+
/** @deprecated Provide llmCalls array instead. llmCallCount creates dummy records. */
|
|
25
|
+
llmCallCount?: number;
|
|
26
|
+
llmCalls?: LLMCallRecord[];
|
|
27
|
+
toolCalls?: ToolCallSummary[];
|
|
28
|
+
customRecords?: Record<string, unknown>[];
|
|
29
|
+
/** @deprecated Use llmCost instead */
|
|
30
|
+
totalCost?: number;
|
|
31
|
+
llmCost?: number;
|
|
32
|
+
additionalCosts?: AdditionalCost[];
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
costByModel?: Record<string, number>;
|
|
35
|
+
}
|
|
36
|
+
declare function createMockSessionSummary(overrides?: MockSessionSummaryOptions): SessionSummary;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Collects all events from a StreamingExecution into an array.
|
|
40
|
+
* Works with both StreamingExecution (via .stream()) and raw AsyncIterable.
|
|
41
|
+
*/
|
|
42
|
+
declare function collectEvents$1<T extends {
|
|
43
|
+
type: string;
|
|
44
|
+
}>(execution: StreamingExecution<T>): Promise<SessionEvent<T | ErrorEvent>[]>;
|
|
45
|
+
declare function collectEvents$1<T extends {
|
|
46
|
+
type: string;
|
|
47
|
+
}>(execution: AsyncIterable<SessionEvent<T>>): Promise<SessionEvent<T>[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Drains a StreamingExecution or AsyncIterable without storing events.
|
|
50
|
+
*/
|
|
51
|
+
declare function consumeExecution<T extends {
|
|
52
|
+
type: string;
|
|
53
|
+
}>(execution: StreamingExecution<T> | AsyncIterable<SessionEvent<T>>): Promise<void>;
|
|
54
|
+
declare function expectFileManagerInterface(obj: unknown): asserts obj is FileManager;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* MockProvider - Test provider for @agtlantis/core.
|
|
58
|
+
*
|
|
59
|
+
* Extends BaseProvider to provide mock LLM responses with call tracking.
|
|
60
|
+
* Use `mock.provider()` factory for convenient creation.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { mock } from '@agtlantis/core/testing';
|
|
65
|
+
*
|
|
66
|
+
* const provider = mock.provider(mock.text('Hello!'));
|
|
67
|
+
* const execution = provider.simpleExecution(async (session) => {
|
|
68
|
+
* const { text } = await session.generateText({ prompt: 'Say hi' });
|
|
69
|
+
* return text;
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* expect(await execution.toResult()).toBe('Hello!');
|
|
73
|
+
* expect(provider.getCalls()).toHaveLength(1);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
type ModelFactory = (modelId: string) => MockLanguageModelV3;
|
|
78
|
+
interface MockProviderConfig {
|
|
79
|
+
model?: MockLanguageModelV3;
|
|
80
|
+
modelFactory?: ModelFactory;
|
|
81
|
+
fileManager?: FileManager;
|
|
82
|
+
logger?: Logger;
|
|
83
|
+
providerType?: string;
|
|
84
|
+
}
|
|
85
|
+
interface MockCall {
|
|
86
|
+
modelId: string;
|
|
87
|
+
type: 'generate' | 'stream';
|
|
88
|
+
timestamp: number;
|
|
89
|
+
params: unknown;
|
|
90
|
+
}
|
|
91
|
+
declare class MockProvider extends BaseProvider {
|
|
92
|
+
private readonly calls;
|
|
93
|
+
private readonly modelSource;
|
|
94
|
+
private readonly fileManagerInstance;
|
|
95
|
+
private readonly loggerInstance;
|
|
96
|
+
private readonly defaultModelId;
|
|
97
|
+
private readonly pricingConfig?;
|
|
98
|
+
private readonly providerTypeId;
|
|
99
|
+
constructor(config: MockProviderConfig);
|
|
100
|
+
/**
|
|
101
|
+
* Creates instance for fluent API without calling constructor.
|
|
102
|
+
* Shares calls array between fluent instances for tracking.
|
|
103
|
+
*/
|
|
104
|
+
private static createWithConfig;
|
|
105
|
+
getCalls(): MockCall[];
|
|
106
|
+
clearCalls(): void;
|
|
107
|
+
withDefaultModel(modelId: string): MockProvider;
|
|
108
|
+
withLogger(logger: Logger): MockProvider;
|
|
109
|
+
withPricing(pricing: ProviderPricing): MockProvider;
|
|
110
|
+
/**
|
|
111
|
+
* Mock implementation - returns same provider since mocks don't use provider options.
|
|
112
|
+
*/
|
|
113
|
+
withDefaultOptions(_options: Record<string, unknown>): MockProvider;
|
|
114
|
+
protected createSimpleSession(signal?: AbortSignal): SimpleSession;
|
|
115
|
+
protected createStreamingSession<TEvent extends {
|
|
116
|
+
type: string;
|
|
117
|
+
}>(signal?: AbortSignal): StreamingSession<TEvent>;
|
|
118
|
+
private buildSessionConfig;
|
|
119
|
+
private getBaseModel;
|
|
120
|
+
private createTrackingModel;
|
|
121
|
+
}
|
|
122
|
+
declare function createMockProvider(configOrModel: MockProviderConfig | MockLanguageModelV3 | ModelFactory): MockProvider;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Mock factory functions for AI SDK testing.
|
|
126
|
+
*
|
|
127
|
+
* Provides convenient helpers to create MockLanguageModelV3 instances
|
|
128
|
+
* with predefined responses for unit testing.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* import { generateText } from 'ai';
|
|
132
|
+
* import { mock } from '@agtlantis/core/testing';
|
|
133
|
+
*
|
|
134
|
+
* const result = await generateText({
|
|
135
|
+
* model: mock.text('Hello, world!'),
|
|
136
|
+
* prompt: 'Say hello',
|
|
137
|
+
* });
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
type DoGenerateResult = Awaited<ReturnType<MockLanguageModelV3['doGenerate']>>;
|
|
141
|
+
type ResponseOptions = Partial<Omit<DoGenerateResult, 'content'>>;
|
|
142
|
+
declare const mock: {
|
|
143
|
+
/**
|
|
144
|
+
* Creates a MockLanguageModelV3 that returns text content.
|
|
145
|
+
*
|
|
146
|
+
* @param text - The text to return from generateText
|
|
147
|
+
* @param options - Optional overrides for usage, finishReason, etc.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const model = mock.text('Hello, world!');
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // With custom usage for cost calculation tests
|
|
154
|
+
* const model = mock.text('Hello', {
|
|
155
|
+
* usage: {
|
|
156
|
+
* inputTokens: { total: 100 },
|
|
157
|
+
* outputTokens: { total: 50 },
|
|
158
|
+
* },
|
|
159
|
+
* });
|
|
160
|
+
*/
|
|
161
|
+
text(text: string, options?: ResponseOptions): MockLanguageModelV3;
|
|
162
|
+
/**
|
|
163
|
+
* Creates a MockLanguageModelV3 that returns JSON content.
|
|
164
|
+
*
|
|
165
|
+
* Automatically stringifies the data. Use with generateObject or
|
|
166
|
+
* generateText + Output.object.
|
|
167
|
+
*
|
|
168
|
+
* @param data - The object to return as JSON
|
|
169
|
+
* @param options - Optional overrides for usage, finishReason, etc.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* const model = mock.json({ name: 'Alice', age: 30 });
|
|
173
|
+
*/
|
|
174
|
+
json<T>(data: T, options?: ResponseOptions): MockLanguageModelV3;
|
|
175
|
+
/**
|
|
176
|
+
* Creates a MockLanguageModelV3 that streams text chunks.
|
|
177
|
+
*
|
|
178
|
+
* @param chunks - Array of text strings to stream
|
|
179
|
+
* @param options - Optional overrides for finishReason, usage, etc.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const model = mock.stream(['Hello', ', ', 'world!']);
|
|
183
|
+
*/
|
|
184
|
+
stream(chunks: string[], options?: ResponseOptions): MockLanguageModelV3;
|
|
185
|
+
/**
|
|
186
|
+
* Creates a MockLanguageModelV3 that throws an error.
|
|
187
|
+
*
|
|
188
|
+
* @param error - The error to throw
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* const model = mock.error(new Error('Rate limit exceeded'));
|
|
192
|
+
*
|
|
193
|
+
* await expect(generateText({ model, prompt: 'Hi' }))
|
|
194
|
+
* .rejects.toThrow('Rate limit exceeded');
|
|
195
|
+
*/
|
|
196
|
+
error(error: Error): MockLanguageModelV3;
|
|
197
|
+
/**
|
|
198
|
+
* Creates a MockProvider with call tracking.
|
|
199
|
+
*
|
|
200
|
+
* Supports three input styles:
|
|
201
|
+
* - Single model: `mock.provider(mock.text('Hello'))`
|
|
202
|
+
* - Model factory: `mock.provider((modelId) => mock.text(modelId))`
|
|
203
|
+
* - Full config: `mock.provider({ model, fileManager, logger })`
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Basic usage
|
|
208
|
+
* const provider = mock.provider(mock.text('Hello!'));
|
|
209
|
+
* const execution = provider.simpleExecution(async (session) => {
|
|
210
|
+
* const { text } = await session.generateText({ prompt: 'Say hi' });
|
|
211
|
+
* return text;
|
|
212
|
+
* });
|
|
213
|
+
* expect(await execution.toResult()).toBe('Hello!');
|
|
214
|
+
* expect(provider.getCalls()).toHaveLength(1);
|
|
215
|
+
*
|
|
216
|
+
* // With model factory for different responses per model
|
|
217
|
+
* const provider = mock.provider((modelId) => {
|
|
218
|
+
* if (modelId === 'gpt-4') return mock.text('GPT-4 response');
|
|
219
|
+
* return mock.text('Default response');
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
provider(configOrModel: MockProviderConfig | MockLanguageModelV3 | ModelFactory): MockProvider;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Test helpers for execution module tests.
|
|
228
|
+
* Provides reusable utilities for abort scenarios, generator creation,
|
|
229
|
+
* and logger tracking.
|
|
230
|
+
*
|
|
231
|
+
* These helpers are framework-agnostic (no vitest/jest dependency).
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
type LoggerEventType = 'start' | 'emit' | 'done' | 'error';
|
|
235
|
+
/**
|
|
236
|
+
* Abort scenario helper for testing cancellation flows.
|
|
237
|
+
*/
|
|
238
|
+
interface AbortScenario {
|
|
239
|
+
/** The AbortController instance */
|
|
240
|
+
controller: AbortController;
|
|
241
|
+
/** The AbortSignal to pass to execution */
|
|
242
|
+
signal: AbortSignal;
|
|
243
|
+
/** Call to abort with optional reason */
|
|
244
|
+
abort: (reason?: string) => void;
|
|
245
|
+
/** Check if signal is aborted */
|
|
246
|
+
isAborted: () => boolean;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Create an abort scenario for testing cancellation.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const { signal, abort, isAborted } = createAbortScenario();
|
|
254
|
+
* const execution = new SimpleExecutionHost(factory, fn, signal);
|
|
255
|
+
*
|
|
256
|
+
* abort('User canceled');
|
|
257
|
+
* expect(isAborted()).toBe(true);
|
|
258
|
+
*
|
|
259
|
+
* const result = await execution.result();
|
|
260
|
+
* expectCanceledResult(result);
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
declare function createAbortScenario(): AbortScenario;
|
|
264
|
+
/**
|
|
265
|
+
* Create an already-aborted signal for testing pre-aborted scenarios.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const signal = createAlreadyAbortedSignal('Pre-aborted');
|
|
270
|
+
* const execution = new SimpleExecutionHost(factory, fn, signal);
|
|
271
|
+
*
|
|
272
|
+
* const result = await execution.result();
|
|
273
|
+
* expectCanceledResult(result);
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
declare function createAlreadyAbortedSignal(reason?: string): AbortSignal;
|
|
277
|
+
/**
|
|
278
|
+
* Create a simple generator that emits specified events and returns the result.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const generator = createSimpleGenerator('result-value', [
|
|
283
|
+
* { type: 'progress', message: 'step 1' },
|
|
284
|
+
* { type: 'progress', message: 'step 2' },
|
|
285
|
+
* ]);
|
|
286
|
+
* const execution = new StreamingExecutionHost(factory, generator);
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
declare function createSimpleGenerator<TEvent extends {
|
|
290
|
+
type: string;
|
|
291
|
+
}>(result: ExtractResult<TEvent>, events?: EmittableEventInput<TEvent>[]): (session: {
|
|
292
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
293
|
+
done: (value: ExtractResult<TEvent>) => Promise<SessionEvent<TEvent>>;
|
|
294
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>, unknown>;
|
|
295
|
+
/**
|
|
296
|
+
* Create a generator that throws an error.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const generator = createErrorGenerator(new Error('Test error'));
|
|
301
|
+
* const execution = new StreamingExecutionHost(factory, generator);
|
|
302
|
+
*
|
|
303
|
+
* const result = await execution.result();
|
|
304
|
+
* expectFailedResult(result, 'Test error');
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
declare function createErrorGenerator<TEvent extends {
|
|
308
|
+
type: string;
|
|
309
|
+
}>(error: Error, eventsBeforeError?: EmittableEventInput<TEvent>[]): (session: {
|
|
310
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
311
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, never, unknown>;
|
|
312
|
+
/**
|
|
313
|
+
* Create a generator that waits for cancellation using closure pattern.
|
|
314
|
+
* Uses the provided AbortScenario to detect when to abort.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const abortScenario = createAbortScenario();
|
|
319
|
+
* const onCancelCalled = vi.fn();
|
|
320
|
+
* const generator = createCancelableGenerator(abortScenario, onCancelCalled);
|
|
321
|
+
*
|
|
322
|
+
* const execution = new StreamingExecutionHost(factory, generator, abortScenario.signal);
|
|
323
|
+
* abortScenario.abort();
|
|
324
|
+
*
|
|
325
|
+
* const result = await execution.result();
|
|
326
|
+
* expectCanceledResult(result);
|
|
327
|
+
* expect(onCancelCalled).toHaveBeenCalled();
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
declare function createCancelableGenerator<TEvent extends {
|
|
331
|
+
type: string;
|
|
332
|
+
}>(abortScenario: AbortScenario, onCancel?: () => void, eventsBeforeWait?: EmittableEventInput<TEvent>[]): (session: {
|
|
333
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
334
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, void, unknown>;
|
|
335
|
+
/**
|
|
336
|
+
* Create a function that waits for cancellation using closure pattern.
|
|
337
|
+
* Uses the provided AbortScenario to detect when to abort.
|
|
338
|
+
* Equivalent of createCancelableGenerator for SimpleExecutionHost.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const abortScenario = createAbortScenario();
|
|
343
|
+
* const onCancelCalled = vi.fn();
|
|
344
|
+
* const fn = createCancelableFunction(abortScenario, onCancelCalled);
|
|
345
|
+
*
|
|
346
|
+
* const execution = new SimpleExecutionHost(factory, fn, abortScenario.signal);
|
|
347
|
+
* abortScenario.abort();
|
|
348
|
+
*
|
|
349
|
+
* const result = await execution.result();
|
|
350
|
+
* expectCanceledResult(result);
|
|
351
|
+
* expect(onCancelCalled).toHaveBeenCalled();
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
declare function createCancelableFunction(abortScenario: AbortScenario, onCancel?: () => void): (session: SimpleSession) => Promise<unknown>;
|
|
355
|
+
/**
|
|
356
|
+
* Create a generator with delay, useful for timing-related tests.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const generator = createDelayedGenerator(100, 'result');
|
|
361
|
+
* const execution = new StreamingExecutionHost(factory, generator);
|
|
362
|
+
*
|
|
363
|
+
* // Cancel before delay completes
|
|
364
|
+
* setTimeout(() => execution.cancel(), 50);
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
declare function createDelayedGenerator<TEvent extends {
|
|
368
|
+
type: string;
|
|
369
|
+
}>(delayMs: number, result: ExtractResult<TEvent>, abortScenario?: AbortScenario): (session: {
|
|
370
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
371
|
+
done: (value: ExtractResult<TEvent>) => Promise<SessionEvent<TEvent>>;
|
|
372
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>, unknown>;
|
|
373
|
+
/**
|
|
374
|
+
* Create a generator that yields events with a configurable delay between each.
|
|
375
|
+
* Useful for race condition testing where timing control is needed.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* const generator = createSlowGenerator([
|
|
380
|
+
* { type: 'chunk', content: 'A' },
|
|
381
|
+
* { type: 'chunk', content: 'B' },
|
|
382
|
+
* ], 10);
|
|
383
|
+
* const execution = new StreamingExecutionHost(factory, generator);
|
|
384
|
+
*
|
|
385
|
+
* // Cancel mid-stream
|
|
386
|
+
* setTimeout(() => execution.cancel(), 15);
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
declare function createSlowGenerator<TEvent extends {
|
|
390
|
+
type: string;
|
|
391
|
+
}>(events: EmittableEventInput<TEvent>[], delayBetweenEventsMs: number, abortScenario?: AbortScenario): (session: {
|
|
392
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
393
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | undefined, unknown>;
|
|
394
|
+
/**
|
|
395
|
+
* Collect all events from an async iterable stream.
|
|
396
|
+
* Useful for testing stream() output in race condition scenarios.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```typescript
|
|
400
|
+
* const events = await collectStreamAsync(execution.stream());
|
|
401
|
+
* expect(events).toHaveLength(3);
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
declare function collectStreamAsync<T>(stream: AsyncIterable<T>): Promise<T[]>;
|
|
405
|
+
/**
|
|
406
|
+
* Create a generator that never completes (infinite wait).
|
|
407
|
+
* Useful for testing cleanup and cancellation behavior.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const generator = createNeverEndingGenerator([
|
|
412
|
+
* { type: 'chunk', content: 'A' },
|
|
413
|
+
* ]);
|
|
414
|
+
* const execution = new StreamingExecutionHost(factory, generator);
|
|
415
|
+
*
|
|
416
|
+
* // Must cancel to complete
|
|
417
|
+
* execution.cancel();
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function createNeverEndingGenerator<TEvent extends {
|
|
421
|
+
type: string;
|
|
422
|
+
}>(eventsBeforeWait?: EmittableEventInput<TEvent>[], abortScenario?: AbortScenario): (session: {
|
|
423
|
+
emit: (event: EmittableEventInput<TEvent>) => SessionEvent<TEvent>;
|
|
424
|
+
}) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | undefined, unknown>;
|
|
425
|
+
/**
|
|
426
|
+
* Create a logger that tracks call order for sequence verification.
|
|
427
|
+
* This version is framework-agnostic (no vitest/jest dependency).
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* const { logger, getCallOrder } = createOrderTrackingLogger();
|
|
432
|
+
* // ... run execution with logger ...
|
|
433
|
+
*
|
|
434
|
+
* expect(getCallOrder()).toEqual(['start', 'emit', 'done']);
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function createOrderTrackingLogger(): {
|
|
438
|
+
logger: Logger;
|
|
439
|
+
getCallOrder: () => LoggerEventType[];
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Test fixtures for execution module tests.
|
|
444
|
+
* Provides mock factories and session factories for testing.
|
|
445
|
+
*
|
|
446
|
+
* These fixtures are framework-agnostic (no vitest/jest dependency).
|
|
447
|
+
* Pass your own mock function (vi.fn, jest.fn, etc.) or use the noop default.
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
type MockFn = (...args: unknown[]) => unknown;
|
|
451
|
+
type MockFnFactory = () => MockFn;
|
|
452
|
+
declare const TEST_PROVIDER_TYPE: "google";
|
|
453
|
+
/**
|
|
454
|
+
* Base test event — the domain event users emit via session.emit().
|
|
455
|
+
*/
|
|
456
|
+
interface TestBaseEvent {
|
|
457
|
+
type: string;
|
|
458
|
+
message?: string;
|
|
459
|
+
data?: string;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Full test event union including CompletionEvent.
|
|
463
|
+
* ExtractResult<TestEvent> = string, EmittableEventInput<TestEvent> = TestBaseEvent.
|
|
464
|
+
*/
|
|
465
|
+
type TestEvent = TestBaseEvent | CompletionEvent<string>;
|
|
466
|
+
interface CreateMockModelOptions {
|
|
467
|
+
mockFn?: MockFnFactory;
|
|
468
|
+
}
|
|
469
|
+
declare function createMockModel(options?: CreateMockModelOptions): LanguageModel;
|
|
470
|
+
interface CreateMockFileManagerOptions {
|
|
471
|
+
mockFn?: MockFnFactory;
|
|
472
|
+
}
|
|
473
|
+
declare function createMockFileManager(options?: CreateMockFileManagerOptions): FileManager;
|
|
474
|
+
interface CreateMockLoggerOptions {
|
|
475
|
+
mockFn?: MockFnFactory;
|
|
476
|
+
}
|
|
477
|
+
declare function createMockLogger(options?: CreateMockLoggerOptions): Logger;
|
|
478
|
+
declare function createMockUsage(overrides?: Partial<LanguageModelUsage>): LanguageModelUsage;
|
|
479
|
+
interface CreateSessionFactoryOptions {
|
|
480
|
+
mockFn?: MockFnFactory;
|
|
481
|
+
logger?: Logger;
|
|
482
|
+
}
|
|
483
|
+
declare function createSimpleSessionFactory(options?: CreateSessionFactoryOptions): (signal?: AbortSignal) => SimpleSession;
|
|
484
|
+
declare function createStreamingSessionFactory<TEvent extends {
|
|
485
|
+
type: string;
|
|
486
|
+
} = TestEvent>(options?: CreateSessionFactoryOptions): () => StreamingSession<TEvent>;
|
|
487
|
+
interface CreateStreamingSessionFactoryWithSignalOptions extends CreateSessionFactoryOptions {
|
|
488
|
+
onSignalCapture?: (signal: AbortSignal | undefined) => void;
|
|
489
|
+
}
|
|
490
|
+
declare function createStreamingSessionFactoryWithSignal<TEvent extends {
|
|
491
|
+
type: string;
|
|
492
|
+
} = TestEvent>(options?: CreateStreamingSessionFactoryWithSignalOptions): (signal?: AbortSignal) => StreamingSession<TEvent>;
|
|
493
|
+
declare function collectEvents<T>(stream: AsyncIterable<T>): Promise<T[]>;
|
|
494
|
+
/**
|
|
495
|
+
* Creates a controllable promise for testing async flows
|
|
496
|
+
*/
|
|
497
|
+
declare function createControllablePromise<T = void>(): {
|
|
498
|
+
promise: Promise<T>;
|
|
499
|
+
resolve: (value: T) => void;
|
|
500
|
+
reject: (error: Error) => void;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
declare function createTestExecution<TEvent extends {
|
|
504
|
+
type: string;
|
|
505
|
+
}>(result: ExtractResult<TEvent>, events?: EmittableEventInput<TEvent>[]): StreamingExecution<TEvent>;
|
|
506
|
+
declare function createTestErrorExecution<TEvent extends {
|
|
507
|
+
type: string;
|
|
508
|
+
}>(error: Error, options?: {
|
|
509
|
+
events?: EmittableEventInput<TEvent>[];
|
|
510
|
+
data?: ExtractResult<TEvent>;
|
|
511
|
+
}): StreamingExecution<TEvent>;
|
|
512
|
+
declare function createTestCanceledExecution<TEvent extends {
|
|
513
|
+
type: string;
|
|
514
|
+
}>(events?: EmittableEventInput<TEvent>[]): StreamingExecution<TEvent>;
|
|
515
|
+
|
|
516
|
+
export { type AbortScenario, type CreateMockFileManagerOptions, type CreateMockLoggerOptions, type CreateMockModelOptions, type CreateSessionFactoryOptions, type CreateStreamingSessionFactoryWithSignalOptions, type TestBaseEvent as ExecutionTestBaseEvent, type TestEvent as ExecutionTestEvent, type LoggerEventType, type MockCall, type MockFn, type MockFnFactory, MockProvider, type MockProviderConfig, type ModelFactory, type ResponseOptions, TEST_API_KEY, TEST_PROVIDER_TYPE, type TestBaseEvent$1 as TestBaseEvent, type TestEvent$1 as TestEvent, type TestResult, collectEvents$1 as collectEvents, collectEvents as collectExecutionEvents, collectStreamAsync, consumeExecution, createAbortScenario, createAlreadyAbortedSignal, createCancelableFunction, createCancelableGenerator, createControllablePromise, createDelayedGenerator, createErrorGenerator, createMockFileManager, createMockUsage as createMockLanguageModelUsage, createMockLogger, createMockModel, createMockProvider, createMockSessionSummary, createMockUsage$1 as createMockUsage, createNeverEndingGenerator, createOrderTrackingLogger, createSimpleGenerator, createSimpleSessionFactory, createSlowGenerator, createStreamingSessionFactory, createStreamingSessionFactoryWithSignal, createTestCanceledExecution, createTestErrorExecution, createTestEvent, createTestExecution, expectFileManagerInterface, mock };
|