@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.
@@ -0,0 +1,1236 @@
1
+ import { LanguageModelUsage, ToolSet, generateText, streamText, generateObject, FilePart, ImagePart, LanguageModel } from 'ai';
2
+ import * as zod from 'zod';
3
+
4
+ /**
5
+ * Timing metrics attached to each streaming event.
6
+ * Enables performance monitoring and latency debugging.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const event = {
11
+ * type: 'progress',
12
+ * message: 'Processing...',
13
+ * metrics: {
14
+ * timestamp: Date.now(),
15
+ * elapsedMs: 150,
16
+ * deltaMs: 50,
17
+ * },
18
+ * };
19
+ * ```
20
+ */
21
+ interface EventMetrics {
22
+ timestamp: number;
23
+ elapsedMs: number;
24
+ deltaMs: number;
25
+ }
26
+
27
+ /**
28
+ * Metadata collected during agent execution.
29
+ * Available after execution completes via `getSummary()`.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const metadata: ExecutionMetadata = {
34
+ * duration: 1250,
35
+ * usage: {
36
+ * inputTokens: 500,
37
+ * outputTokens: 200,
38
+ * totalTokens: 700,
39
+ * },
40
+ * };
41
+ * ```
42
+ */
43
+ interface ExecutionMetadata {
44
+ duration: number;
45
+ languageModelUsage?: LanguageModelUsage;
46
+ [key: string]: unknown;
47
+ }
48
+
49
+ /**
50
+ * Pricing types for cost calculation.
51
+ *
52
+ * @module pricing/types
53
+ */
54
+ /**
55
+ * AI provider type identifier.
56
+ *
57
+ * Common values: 'google', 'openai', 'anthropic', 'mock'
58
+ * Extensible to support custom providers.
59
+ */
60
+ type ProviderType = string;
61
+ /**
62
+ * Pricing for a specific model in USD per million tokens.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const gpt4Pricing: ModelPricing = {
67
+ * inputPricePerMillion: 2.5,
68
+ * outputPricePerMillion: 10.0,
69
+ * cachedInputPricePerMillion: 1.25, // 50% discount for cached tokens
70
+ * };
71
+ * ```
72
+ */
73
+ interface ModelPricing {
74
+ inputPricePerMillion: number;
75
+ outputPricePerMillion: number;
76
+ /** Defaults to inputPricePerMillion if not set */
77
+ cachedInputPricePerMillion?: number;
78
+ }
79
+ /**
80
+ * Pricing map for a provider's models.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const googlePricing: ProviderPricing = {
85
+ * 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 },
86
+ * 'gemini-2.5-pro': { inputPricePerMillion: 1.25, outputPricePerMillion: 10.0 },
87
+ * };
88
+ * ```
89
+ */
90
+ type ProviderPricing = Record<string, ModelPricing>;
91
+ /**
92
+ * Global pricing configuration.
93
+ *
94
+ * Allows overriding built-in pricing defaults for any provider/model.
95
+ * Used with `configurePricing()` for global overrides or
96
+ * `Provider.withPricing()` for provider-level overrides.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const config: PricingConfig = {
101
+ * providers: {
102
+ * google: {
103
+ * 'gemini-2.5-flash': { inputPricePerMillion: 0.5, outputPricePerMillion: 3.0 },
104
+ * },
105
+ * },
106
+ * fallback: {
107
+ * inputPricePerMillion: 1.0,
108
+ * outputPricePerMillion: 5.0,
109
+ * },
110
+ * };
111
+ * ```
112
+ */
113
+ interface PricingConfig {
114
+ providers?: Partial<Record<ProviderType, ProviderPricing>>;
115
+ fallback?: ModelPricing;
116
+ }
117
+ /**
118
+ * Parameters for cost calculation.
119
+ */
120
+ interface CalculateCostParams {
121
+ /**
122
+ * Total input tokens INCLUDING cached tokens.
123
+ * The cost calculator subtracts cachedInputTokens to get non-cached tokens.
124
+ */
125
+ inputTokens: number;
126
+ outputTokens: number;
127
+ /**
128
+ * Cached input tokens count (optional).
129
+ * Must be <= inputTokens. Cached tokens are billed at a lower rate.
130
+ */
131
+ cachedInputTokens?: number;
132
+ model: string;
133
+ provider: ProviderType;
134
+ }
135
+ /**
136
+ * Result of cost calculation.
137
+ */
138
+ interface CostResult {
139
+ total: number;
140
+ inputCost: number;
141
+ outputCost: number;
142
+ cachedInputCost: number;
143
+ }
144
+
145
+ /**
146
+ * Structural interface matching AI SDK's internal Output<OUTPUT, PARTIAL>.
147
+ *
148
+ * AI SDK exports `output as Output` (runtime value), not the interface directly.
149
+ * We define this compatible interface to enable structural typing.
150
+ *
151
+ * CRITICAL: Method signatures MUST exactly match AI SDK's internal interface
152
+ * for generic type inference to work.
153
+ *
154
+ * @see AI SDK source: node_modules/ai/dist/index.d.ts lines 572-596
155
+ */
156
+ interface OutputSpec<OUTPUT = unknown, PARTIAL = unknown> {
157
+ responseFormat: PromiseLike<unknown>;
158
+ parseCompleteOutput(options: {
159
+ text: string;
160
+ }, context: {
161
+ response: unknown;
162
+ usage: unknown;
163
+ finishReason: unknown;
164
+ }): Promise<OUTPUT>;
165
+ parsePartialOutput(options: {
166
+ text: string;
167
+ }): Promise<{
168
+ partial: PARTIAL;
169
+ } | undefined>;
170
+ }
171
+ type DefaultOutput = OutputSpec<string, string>;
172
+ type InferOutputComplete<T> = T extends OutputSpec<infer O, unknown> ? O : string;
173
+ type GenerateTextResultTyped<TOOLS extends ToolSet, OUTPUT extends OutputSpec> = Awaited<ReturnType<typeof generateText<TOOLS>>> & {
174
+ output: InferOutputComplete<OUTPUT> | undefined;
175
+ };
176
+ type StreamTextResultTyped<TOOLS extends ToolSet, OUTPUT extends OutputSpec> = ReturnType<typeof streamText<TOOLS>> & {
177
+ output: Promise<InferOutputComplete<OUTPUT> | undefined>;
178
+ };
179
+ /**
180
+ * Parameters for session.generateText().
181
+ * Mirrors AI SDK's generateText() with 'model' excluded (injected by session).
182
+ */
183
+ type GenerateTextParams<TOOLS extends ToolSet = {}, OUTPUT extends OutputSpec = DefaultOutput> = Omit<Parameters<typeof generateText<TOOLS>>[0], 'model' | 'output'> & {
184
+ model?: string;
185
+ output?: OUTPUT;
186
+ };
187
+
188
+ /**
189
+ * Parameters for session.streamText().
190
+ * Mirrors AI SDK's streamText() with 'model' excluded (injected by session).
191
+ */
192
+ type StreamTextParams<TOOLS extends ToolSet = {}, OUTPUT extends OutputSpec = DefaultOutput> = Omit<Parameters<typeof streamText<TOOLS>>[0], 'model' | 'output'> & {
193
+ model?: string;
194
+ output?: OUTPUT;
195
+ };
196
+
197
+ /**
198
+ * @deprecated Use generateText with Output.object instead
199
+ */
200
+ type GenerateObjectParams = Omit<Parameters<typeof generateObject>[0], 'model'>;
201
+
202
+ interface ToolCallSummary {
203
+ name: string;
204
+ duration?: number;
205
+ success: boolean;
206
+ error?: string;
207
+ }
208
+ type LLMCallType = 'generateText' | 'streamText' | 'generateObject' | 'manual';
209
+ interface LLMCallRecord {
210
+ startTime: number;
211
+ endTime: number;
212
+ duration: number;
213
+ usage: LanguageModelUsage;
214
+ type: LLMCallType;
215
+ model: string;
216
+ provider: ProviderType;
217
+ }
218
+ /**
219
+ * Aggregated summary of all activity within an execution session.
220
+ * Used for cost tracking, performance analysis, and metadata reporting.
221
+ */
222
+ interface AdditionalCost {
223
+ type: string;
224
+ cost: number;
225
+ label?: string;
226
+ metadata?: Record<string, unknown>;
227
+ timestamp: number;
228
+ }
229
+ /**
230
+ * Internal data structure for SessionSummary constructor.
231
+ */
232
+ interface SessionSummaryData {
233
+ totalLLMUsage: LanguageModelUsage;
234
+ llmCalls: LLMCallRecord[];
235
+ toolCalls: ToolCallSummary[];
236
+ customRecords: Record<string, unknown>[];
237
+ llmCost: number;
238
+ additionalCosts: AdditionalCost[];
239
+ metadata: Record<string, unknown>;
240
+ costByModel: Record<string, number>;
241
+ }
242
+ /**
243
+ * Aggregated summary of all activity within an execution session.
244
+ * Used for cost tracking, performance analysis, and metadata reporting.
245
+ *
246
+ * This is an immutable Value Object. All mutation methods return new instances.
247
+ */
248
+ declare class SessionSummary {
249
+ readonly totalLLMUsage: LanguageModelUsage;
250
+ readonly llmCallCount: number;
251
+ readonly llmCalls: readonly LLMCallRecord[];
252
+ readonly toolCalls: readonly ToolCallSummary[];
253
+ readonly customRecords: readonly Record<string, unknown>[];
254
+ readonly llmCost: number;
255
+ readonly additionalCosts: readonly AdditionalCost[];
256
+ readonly metadata: Readonly<Record<string, unknown>>;
257
+ /** Cost breakdown by model. Key format: `${provider}/${model}` */
258
+ readonly costByModel: Readonly<Record<string, number>>;
259
+ private readonly startTime;
260
+ private constructor();
261
+ /**
262
+ * Total duration from session start to now (computed dynamically).
263
+ */
264
+ get totalDuration(): number;
265
+ /**
266
+ * Creates an empty SessionSummary.
267
+ */
268
+ static empty(startTime: number): SessionSummary;
269
+ /**
270
+ * Creates a SessionSummary with custom data for testing purposes.
271
+ * @internal For testing only - do not use in production code.
272
+ */
273
+ static forTest(data: Partial<SessionSummaryData> & {
274
+ startTime?: number;
275
+ }): SessionSummary;
276
+ /**
277
+ * Total cost of all additional (non-LLM) operations.
278
+ */
279
+ get totalAdditionalCost(): number;
280
+ /**
281
+ * Total cost including LLM and additional costs.
282
+ */
283
+ get totalCost(): number;
284
+ /**
285
+ * Returns a new SessionSummary with an LLM call added.
286
+ */
287
+ withLLMCall(call: LLMCallRecord, newLlmCost: number, newCostByModel: Record<string, number>, newTotalUsage: LanguageModelUsage): SessionSummary;
288
+ /**
289
+ * Returns a new SessionSummary with an additional cost recorded.
290
+ */
291
+ withAdditionalCost(cost: AdditionalCost): SessionSummary;
292
+ /**
293
+ * Returns a new SessionSummary with metadata updated.
294
+ */
295
+ withMetadata(key: string, value: unknown): SessionSummary;
296
+ /**
297
+ * Returns a new SessionSummary with a tool call added.
298
+ */
299
+ withToolCall(call: ToolCallSummary): SessionSummary;
300
+ /**
301
+ * Returns a new SessionSummary with a custom record added.
302
+ */
303
+ withCustomRecord(record: Record<string, unknown>): SessionSummary;
304
+ /**
305
+ * Serializes to plain JSON object for database storage.
306
+ */
307
+ toJSON(): SessionSummaryJSON;
308
+ }
309
+ /**
310
+ * JSON representation of SessionSummary for database storage.
311
+ */
312
+ interface SessionSummaryJSON {
313
+ totalDuration: number;
314
+ totalLLMUsage: LanguageModelUsage;
315
+ llmCallCount: number;
316
+ llmCalls: LLMCallRecord[];
317
+ toolCalls: ToolCallSummary[];
318
+ customRecords: Record<string, unknown>[];
319
+ llmCost: number;
320
+ additionalCosts: AdditionalCost[];
321
+ metadata: Record<string, unknown>;
322
+ costByModel: Record<string, number>;
323
+ totalCost: number;
324
+ totalAdditionalCost: number;
325
+ }
326
+ /**
327
+ * Session for tracking LLM calls, tool calls, and custom records.
328
+ * Provides AI SDK wrappers with auto-tracking and manual recording methods.
329
+ */
330
+ interface ExecutionSession {
331
+ generateText(params: GenerateTextParams): Promise<Awaited<ReturnType<typeof generateText>>>;
332
+ streamText(params: StreamTextParams): ReturnType<typeof streamText>;
333
+ generateObject<T>(params: GenerateObjectParams & {
334
+ schema: zod.ZodType<T>;
335
+ }): Promise<Awaited<ReturnType<typeof generateObject>>>;
336
+ recordToolCall(summary: ToolCallSummary): void;
337
+ recordLLMCall(record: Omit<LLMCallRecord, 'type'> & {
338
+ type?: LLMCallType;
339
+ }): void;
340
+ record(data: Record<string, unknown>): void;
341
+ recordAdditionalCost(cost: Omit<AdditionalCost, 'timestamp'>): void;
342
+ setMetadata(key: string, value: unknown): void;
343
+ setMetadata(data: Record<string, unknown>): void;
344
+ summary(): Promise<SessionSummary>;
345
+ }
346
+ /**
347
+ * Metadata passed to done() and fail() in StreamGeneratorControl.
348
+ * Union of SessionSummary and ExecutionMetadata for flexible usage.
349
+ */
350
+ type DoneMetadata = SessionSummary | ExecutionMetadata;
351
+
352
+ /**
353
+ * Logger interface for observability.
354
+ * All methods are optional - implement only the events you care about.
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * const myLogger: Logger = {
359
+ * onLLMCallEnd(event) {
360
+ * console.log(`${event.modelId}: ${event.response.duration}ms`);
361
+ * },
362
+ * onExecutionDone(event) {
363
+ * console.log('Total duration:', event.duration);
364
+ * },
365
+ * };
366
+ * ```
367
+ */
368
+ interface Logger {
369
+ onLLMCallStart?(event: LLMCallStartEvent): void;
370
+ onLLMCallEnd?(event: LLMCallEndEvent): void;
371
+ onExecutionStart?(event: ExecutionStartEvent): void;
372
+ onExecutionEmit?<TEvent>(event: ExecutionEmitEvent<TEvent>): void;
373
+ onExecutionDone?<TResult>(event: ExecutionDoneEvent<TResult>): void;
374
+ onExecutionError?<TResult>(event: ExecutionErrorEvent<TResult>): void;
375
+ log?(level: LogLevel, message: string, data?: Record<string, unknown>): void;
376
+ }
377
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
378
+ type LLMCallLogType = 'generateText' | 'streamText';
379
+ /**
380
+ * Event emitted when an LLM call starts.
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * logger.onLLMCallStart?.({
385
+ * type: 'llm_call_start',
386
+ * callType: 'generateText',
387
+ * modelId: 'gemini-2.5-flash',
388
+ * timestamp: Date.now(),
389
+ * request: { params: { prompt: 'Hello' } },
390
+ * });
391
+ * ```
392
+ */
393
+ interface LLMCallStartEvent {
394
+ type: 'llm_call_start';
395
+ callType: LLMCallLogType;
396
+ modelId: string;
397
+ timestamp: number;
398
+ request: {
399
+ params: Record<string, unknown>;
400
+ };
401
+ }
402
+ /**
403
+ * Event emitted when an LLM call ends (success or error).
404
+ *
405
+ * @example Success case:
406
+ * ```typescript
407
+ * logger.onLLMCallEnd?.({
408
+ * type: 'llm_call_end',
409
+ * callType: 'generateText',
410
+ * modelId: 'gemini-2.5-flash',
411
+ * timestamp: Date.now(),
412
+ * response: {
413
+ * duration: 1500,
414
+ * usage: { inputTokens: 100, outputTokens: 50, totalTokens: 150 },
415
+ * raw: result,
416
+ * },
417
+ * });
418
+ * ```
419
+ *
420
+ * @example Error case:
421
+ * ```typescript
422
+ * logger.onLLMCallEnd?.({
423
+ * type: 'llm_call_end',
424
+ * callType: 'streamText',
425
+ * modelId: 'gpt-4o',
426
+ * timestamp: Date.now(),
427
+ * response: {
428
+ * duration: 500,
429
+ * error: new Error('Rate limit exceeded'),
430
+ * raw: null,
431
+ * },
432
+ * });
433
+ * ```
434
+ */
435
+ interface LLMCallEndEvent {
436
+ type: 'llm_call_end';
437
+ callType: LLMCallLogType;
438
+ modelId: string;
439
+ timestamp: number;
440
+ response: {
441
+ duration: number;
442
+ usage?: LanguageModelUsage;
443
+ raw: unknown;
444
+ error?: Error;
445
+ };
446
+ }
447
+ interface ExecutionStartEvent {
448
+ type: 'execution_start';
449
+ timestamp: number;
450
+ }
451
+ /**
452
+ * Event emitted for each intermediate event during execution.
453
+ * @typeParam TEvent - The type of the emitted event (includes metrics)
454
+ */
455
+ interface ExecutionEmitEvent<TEvent = unknown> {
456
+ type: 'execution_emit';
457
+ event: TEvent;
458
+ }
459
+ /**
460
+ * Event emitted when execution completes successfully.
461
+ * @typeParam TResult - The type of the execution result
462
+ */
463
+ interface ExecutionDoneEvent<TResult = unknown> {
464
+ type: 'execution_done';
465
+ timestamp: number;
466
+ duration: number;
467
+ data: TResult;
468
+ summary: SessionSummary;
469
+ }
470
+ /**
471
+ * Event emitted when execution fails with an error.
472
+ * @typeParam TResult - The type of partial result data (if available)
473
+ */
474
+ interface ExecutionErrorEvent<TResult = unknown> {
475
+ type: 'execution_error';
476
+ timestamp: number;
477
+ duration: number;
478
+ error: Error;
479
+ data?: TResult;
480
+ summary?: SessionSummary;
481
+ }
482
+ /**
483
+ * No-op logger (default when no logger provided).
484
+ *
485
+ * @example
486
+ * ```typescript
487
+ * const provider = createGoogleProvider({
488
+ * apiKey: 'xxx',
489
+ * logger: noopLogger,
490
+ * });
491
+ * ```
492
+ */
493
+ declare const noopLogger: Logger;
494
+ /**
495
+ * Helper to create a logger with only the handlers you need.
496
+ *
497
+ * @example
498
+ * ```typescript
499
+ * const metricsLogger = createLogger({
500
+ * onLLMCallEnd(event) {
501
+ * metrics.recordLatency(event.response.duration);
502
+ * },
503
+ * onExecutionDone(event) {
504
+ * metrics.recordTokens(event.summary.totalLLMUsage.totalTokens);
505
+ * },
506
+ * });
507
+ * ```
508
+ */
509
+ declare function createLogger(handlers: Partial<Logger>): Logger;
510
+
511
+ /** Result of uploading a file to a provider's file storage */
512
+ interface UploadedFile {
513
+ /** Unique identifier from the provider (used for deletion, null for external URLs) */
514
+ id: string | null;
515
+ /** AI SDK part ready for use in prompts */
516
+ part: FilePart | ImagePart;
517
+ }
518
+ /** Provider-agnostic file manager interface for upload/delete operations */
519
+ interface FileManager {
520
+ upload(files: FileSource[]): Promise<UploadedFile[]>;
521
+ delete(fileId: string): Promise<void>;
522
+ clear(): Promise<void>;
523
+ getUploadedFiles(): UploadedFile[];
524
+ }
525
+ /** Cache for uploaded files to prevent duplicate uploads */
526
+ interface FileCache {
527
+ get(hash: string): UploadedFile | null;
528
+ set(hash: string, file: UploadedFile, ttl?: number): void;
529
+ delete(hash: string): void;
530
+ clear(): void;
531
+ }
532
+ interface FileManagerOptions {
533
+ cache?: FileCache;
534
+ }
535
+ interface FileSourcePath {
536
+ source: 'path';
537
+ path: string;
538
+ mediaType?: string;
539
+ filename?: string;
540
+ hash?: string;
541
+ }
542
+ interface FileSourceData {
543
+ source: 'data';
544
+ data: Buffer | Uint8Array;
545
+ mediaType: string;
546
+ filename?: string;
547
+ hash?: string;
548
+ }
549
+ interface FileSourceBase64 {
550
+ source: 'base64';
551
+ data: string;
552
+ mediaType: string;
553
+ filename?: string;
554
+ hash?: string;
555
+ }
556
+ interface FileSourceUrl {
557
+ source: 'url';
558
+ url: string;
559
+ mediaType?: string;
560
+ filename?: string;
561
+ hash?: string;
562
+ }
563
+ /** Union of all file part types. Use `source` to discriminate. */
564
+ type FileSource = FileSourcePath | FileSourceData | FileSourceBase64 | FileSourceUrl;
565
+ declare function isFileSource(v: unknown): v is FileSource;
566
+ declare function isFileSourcePath(v: FileSource): v is FileSourcePath;
567
+ declare function isFileSourceData(v: FileSource): v is FileSourceData;
568
+ declare function isFileSourceBase64(v: FileSource): v is FileSourceBase64;
569
+ declare function isFileSourceUrl(v: FileSource): v is FileSourceUrl;
570
+ /** Provider interface with fluent configuration for AI model operations */
571
+ interface Provider {
572
+ withDefaultModel(modelId: string): Provider;
573
+ withLogger(logger: Logger): Provider;
574
+ withPricing(pricing: ProviderPricing): Provider;
575
+ /**
576
+ * Set default provider-specific options for all LLM calls.
577
+ * These options will be deep-merged with per-call providerOptions.
578
+ * The actual options type depends on the provider (Google, OpenAI, etc.).
579
+ */
580
+ withDefaultOptions(options: Record<string, unknown>): Provider;
581
+ streamingExecution<TEvent extends {
582
+ type: string;
583
+ }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
584
+ /**
585
+ * Execute a non-streaming function with the provider.
586
+ * Returns immediately (sync) - execution starts in the background.
587
+ *
588
+ * Breaking change: Previously returned Promise<Execution<TResult>>.
589
+ * Now returns SimpleExecution<TResult> directly (no await needed).
590
+ *
591
+ * @example
592
+ * ```typescript
593
+ * // Before (v1.x):
594
+ * const execution = provider.simpleExecution(fn);
595
+ *
596
+ * // After (v2.x):
597
+ * const execution = provider.simpleExecution(fn);
598
+ * execution.cancel(); // Can cancel in-progress LLM calls
599
+ * const result = await execution.result();
600
+ * ```
601
+ */
602
+ simpleExecution<TResult>(fn: (session: SimpleSession) => Promise<TResult>, options?: ExecutionOptions): SimpleExecution<TResult>;
603
+ }
604
+
605
+ /**
606
+ * Provider-specific options type.
607
+ * Maps provider names (e.g., 'google', 'openai') to their option objects.
608
+ */
609
+ type ProviderOptions$1 = Record<string, Record<string, unknown>>;
610
+ interface SimpleSessionOptions {
611
+ defaultLanguageModel?: LanguageModel | null;
612
+ modelFactory?: (modelId: string) => LanguageModel;
613
+ providerType: ProviderType;
614
+ providerPricing?: ProviderPricing;
615
+ fileManager: FileManager;
616
+ logger?: Logger;
617
+ startTime?: number;
618
+ /**
619
+ * AbortSignal for cancelling AI SDK calls.
620
+ * When aborted, ongoing generateText/streamText calls will be cancelled.
621
+ */
622
+ signal?: AbortSignal;
623
+ /**
624
+ * Default provider-specific options to apply to all LLM calls.
625
+ * These will be deep-merged with per-call providerOptions (per-call takes precedence).
626
+ */
627
+ defaultProviderOptions?: ProviderOptions$1;
628
+ /**
629
+ * Default tools to apply to all LLM calls (e.g., google_search, url_context).
630
+ * These will be merged with per-call tools (per-call takes precedence).
631
+ */
632
+ defaultTools?: ToolSet;
633
+ }
634
+ declare class SimpleSession {
635
+ private readonly defaultLanguageModel;
636
+ private readonly modelFactory;
637
+ private readonly providerType;
638
+ private readonly providerPricing;
639
+ private readonly defaultProviderOptions;
640
+ private readonly defaultTools;
641
+ private readonly _fileManager;
642
+ private readonly logger;
643
+ private readonly sessionStartTime;
644
+ private readonly signal?;
645
+ private summary;
646
+ private readonly pendingUsagePromises;
647
+ private readonly onDoneFns;
648
+ constructor(options: SimpleSessionOptions);
649
+ private getModel;
650
+ private extractModelId;
651
+ generateText<TOOLS extends ToolSet = {}, OUTPUT extends OutputSpec = DefaultOutput>(params: GenerateTextParams<TOOLS, OUTPUT>): Promise<GenerateTextResultTyped<TOOLS, OUTPUT>>;
652
+ streamText<TOOLS extends ToolSet = {}, OUTPUT extends OutputSpec = DefaultOutput>(params: StreamTextParams<TOOLS, OUTPUT>): StreamTextResultTyped<TOOLS, OUTPUT>;
653
+ get fileManager(): FileManager;
654
+ record(data: Record<string, unknown>): void;
655
+ recordToolCall(toolCallSummary: ToolCallSummary): void;
656
+ recordLLMCall(record: Omit<LLMCallRecord, 'type'> & {
657
+ type?: LLMCallType;
658
+ }): void;
659
+ recordAdditionalCost(cost: Omit<AdditionalCost, 'timestamp'>): void;
660
+ setMetadata(key: string, value: unknown): void;
661
+ setMetadata(data: Record<string, unknown>): void;
662
+ private updateSummaryWithLLMCall;
663
+ onDone(fn: () => Promise<void> | void): void;
664
+ runOnDoneHooks(): Promise<void>;
665
+ getSummary(): Promise<SessionSummary>;
666
+ /**
667
+ * Notifies Logger of execution start.
668
+ * @internal Called by SimpleExecutionHost - not intended for direct use.
669
+ */
670
+ notifyExecutionStart(): void;
671
+ /**
672
+ * Notifies Logger of execution completion with result data and summary.
673
+ * @param data - The execution result data
674
+ * @param startTime - Execution start timestamp for duration calculation
675
+ * @internal Called by SimpleExecutionHost - not intended for direct use.
676
+ */
677
+ notifyExecutionDone<T>(data: T, startTime: number): Promise<void>;
678
+ /**
679
+ * Notifies Logger of execution error with error details and summary (if available).
680
+ * Gracefully handles getSummary() failures - summary will be undefined if it fails.
681
+ * @param error - The error that occurred
682
+ * @param startTime - Execution start timestamp for duration calculation
683
+ * @internal Called by SimpleExecutionHost - not intended for direct use.
684
+ */
685
+ notifyExecutionError(error: Error, startTime: number): Promise<void>;
686
+ protected get _logger(): Logger;
687
+ protected get _startTime(): number;
688
+ protected get _modelId(): string;
689
+ }
690
+
691
+ type ProviderOptions = Record<string, Record<string, unknown>>;
692
+ interface StreamingSessionOptions {
693
+ defaultLanguageModel?: LanguageModel | null;
694
+ modelFactory?: (modelId: string) => LanguageModel;
695
+ providerType: ProviderType;
696
+ providerPricing?: ProviderPricing;
697
+ fileManager: FileManager;
698
+ logger?: Logger;
699
+ startTime?: number;
700
+ signal?: AbortSignal;
701
+ defaultProviderOptions?: ProviderOptions;
702
+ defaultTools?: ToolSet;
703
+ }
704
+ declare class StreamingSession<TEvent extends {
705
+ type: string;
706
+ }> extends SimpleSession {
707
+ private lastEventTime;
708
+ private _terminated;
709
+ constructor(options: StreamingSessionOptions);
710
+ /**
711
+ * Emits a streaming event with automatically attached metrics.
712
+ *
713
+ * Reserved types ('complete', 'error') throw at runtime - use session.done()
714
+ * or session.fail() instead.
715
+ *
716
+ * @param event - The event to emit (metrics will be added automatically)
717
+ * @returns The complete event with metrics attached
718
+ * @throws Error when attempting to emit reserved types ('complete', 'error')
719
+ */
720
+ emit(event: EmittableEventInput<TEvent>): SessionEvent<TEvent>;
721
+ /**
722
+ * Internal emit method - bypasses reserved type check.
723
+ * Used by done() and fail() to emit terminal events.
724
+ */
725
+ private emitInternal;
726
+ /**
727
+ * Signals successful completion of the streaming execution.
728
+ * Emits a 'complete' event with the result data and session summary.
729
+ * Also triggers Logger.onExecutionDone for observability.
730
+ * @param data - The final result data
731
+ * @returns The complete event with data and summary
732
+ */
733
+ done(data: ExtractResult<TEvent>): Promise<SessionEvent<TEvent>>;
734
+ /**
735
+ * Signals that the streaming execution failed with an error.
736
+ * Emits an 'error' event and triggers Logger.onExecutionError for observability.
737
+ * Gracefully handles getSummary() failures - summary will be undefined if it fails.
738
+ * @param error - The error that caused the failure
739
+ * @param data - Optional partial result data (if any was produced before failure)
740
+ * @returns The error event
741
+ */
742
+ fail(error: Error, data?: ExtractResult<TEvent>): Promise<SessionEvent<TEvent>>;
743
+ private createMetrics;
744
+ }
745
+ interface StreamingSessionInternal<TEvent extends {
746
+ type: string;
747
+ }> {
748
+ generateText: SimpleSession['generateText'];
749
+ streamText: SimpleSession['streamText'];
750
+ fileManager: FileManager;
751
+ onDone: SimpleSession['onDone'];
752
+ record: SimpleSession['record'];
753
+ recordToolCall: SimpleSession['recordToolCall'];
754
+ emit(event: EmittableEventInput<TEvent>): SessionEvent<TEvent>;
755
+ done(data: ExtractResult<TEvent>): Promise<SessionEvent<TEvent>>;
756
+ fail(error: Error, data?: ExtractResult<TEvent>): Promise<SessionEvent<TEvent>>;
757
+ runOnDoneHooks(): Promise<void>;
758
+ getSummary(): Promise<SessionSummary>;
759
+ }
760
+ interface CreateStreamingSessionOptions {
761
+ defaultLanguageModel: LanguageModel;
762
+ providerType: ProviderType;
763
+ fileManager: FileManager;
764
+ logger?: Logger;
765
+ startTime?: number;
766
+ signal?: AbortSignal;
767
+ }
768
+ declare function createStreamingSession<TEvent extends {
769
+ type: string;
770
+ }>(options: CreateStreamingSessionOptions): StreamingSessionInternal<TEvent>;
771
+
772
+ /**
773
+ * Agent execution types for @agtlantis/core.
774
+ * Provides abstractions for streaming and non-streaming agent execution.
775
+ */
776
+
777
+ /**
778
+ * Distributive version of Omit that properly handles union types.
779
+ *
780
+ * Standard `Omit<A | B, K>` loses unique properties from union members.
781
+ * `DistributiveOmit<A | B, K>` preserves them by distributing over the union.
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * type A = { type: 'a'; foo: string; metrics: EventMetrics };
786
+ * type B = { type: 'b'; bar: number; metrics: EventMetrics };
787
+ * type Union = A | B;
788
+ *
789
+ * // ❌ Standard Omit - loses foo and bar
790
+ * type Bad = Omit<Union, 'metrics'>;
791
+ * // Result: { type: 'a' | 'b' }
792
+ *
793
+ * // ✅ DistributiveOmit - preserves unique properties
794
+ * type Good = DistributiveOmit<Union, 'metrics'>;
795
+ * // Result: { type: 'a'; foo: string } | { type: 'b'; bar: number }
796
+ * ```
797
+ */
798
+ type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
799
+ /**
800
+ * Adds `metrics: EventMetrics` to event types.
801
+ * The framework uses this internally to wrap user-defined events with timing info.
802
+ *
803
+ * **For most use cases, you don't need this type.** Simply define your events
804
+ * without metrics, and the framework handles the wrapping automatically.
805
+ *
806
+ * **When you need SessionEvent:**
807
+ * - Creating mock/stub streaming executions for testing
808
+ * - Explicitly typing `StreamingResult.events` arrays
809
+ *
810
+ * @example
811
+ * ```typescript
812
+ * // User defines pure event types (recommended)
813
+ * type MyEvent =
814
+ * | { type: 'progress'; step: string }
815
+ * | { type: 'complete'; data: string };
816
+ *
817
+ * // Framework internally wraps as SessionEvent<MyEvent>
818
+ * // StreamingResult.events returns SessionEvent<MyEvent>[]
819
+ *
820
+ * // Testing: Create mock events with explicit metrics
821
+ * const mockEvents: SessionEvent<MyEvent>[] = [
822
+ * { type: 'progress', step: 'loading', metrics: { timestamp: Date.now(), elapsedMs: 0, deltaMs: 0 } },
823
+ * ];
824
+ * ```
825
+ */
826
+ type SessionEvent<T extends {
827
+ type: string;
828
+ }> = T & {
829
+ metrics: EventMetrics;
830
+ };
831
+ /**
832
+ * Input type for session.emit() - removes metrics from event types.
833
+ * Uses DistributiveOmit to properly handle union types.
834
+ *
835
+ * @example
836
+ * ```typescript
837
+ * type MyAgentEvent = SessionEvent<ProgressEvent | CompleteEvent | ErrorEvent>;
838
+ *
839
+ * // For emit input, metrics is not required
840
+ * type EmitInput = SessionEventInput<MyAgentEvent>;
841
+ *
842
+ * // Usage in session.emit()
843
+ * session.emit({ type: 'progress', step: 'reading', message: 'Loading...' });
844
+ * // No casting needed!
845
+ * ```
846
+ */
847
+ /**
848
+ * @deprecated TEvent no longer requires metrics constraint - use TEvent directly
849
+ * This type is kept for backwards compatibility during migration
850
+ */
851
+ type SessionEventInput<T extends {
852
+ type: string;
853
+ }> = T;
854
+ /**
855
+ * Reserved event types that cannot be emitted directly via session.emit().
856
+ * These types are controlled internally by session.done() and session.fail().
857
+ */
858
+ type ReservedEventType = 'complete' | 'error';
859
+ /**
860
+ * Input type for emit() - excludes reserved event types.
861
+ * Users define pure domain events; framework adds metrics wrapper.
862
+ */
863
+ type EmittableEventInput<T extends {
864
+ type: string;
865
+ }> = T extends {
866
+ type: ReservedEventType;
867
+ } ? never : T;
868
+ /**
869
+ * Completion event emitted by session.done().
870
+ * Include this in your event union to define the result type.
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * type MyEvent =
875
+ * | { type: 'progress'; step: string }
876
+ * | CompletionEvent<MyResult>;
877
+ *
878
+ * // session.done(result) emits { type: 'complete', data: result, summary }
879
+ * ```
880
+ */
881
+ type CompletionEvent<TResult> = {
882
+ type: 'complete';
883
+ data: TResult;
884
+ summary: SessionSummary;
885
+ };
886
+ /**
887
+ * Error event emitted by session.fail().
888
+ * Auto-added to stream() return type — users don't need to include this in their event union.
889
+ *
890
+ * @example
891
+ * ```typescript
892
+ * for await (const event of execution.stream()) {
893
+ * if (event.type === 'error') {
894
+ * console.error(event.error.message);
895
+ * }
896
+ * }
897
+ * ```
898
+ */
899
+ type ErrorEvent = {
900
+ type: 'error';
901
+ error: Error;
902
+ summary?: SessionSummary;
903
+ data?: unknown;
904
+ };
905
+ /**
906
+ * Extract the result type from an event union containing CompletionEvent<T>.
907
+ * Returns `never` if no CompletionEvent member exists (making session.done() uncallable).
908
+ *
909
+ * @example
910
+ * ```typescript
911
+ * type MyEvent =
912
+ * | { type: 'progress'; step: string }
913
+ * | CompletionEvent<{ answer: string }>;
914
+ *
915
+ * type Result = ExtractResult<MyEvent>;
916
+ * // Result = { answer: string }
917
+ * ```
918
+ */
919
+ type ExtractResult<TEvent extends {
920
+ type: string;
921
+ }> = Extract<TEvent, {
922
+ type: 'complete';
923
+ }> extends {
924
+ data: infer R;
925
+ } ? R : never;
926
+ /**
927
+ * Options for execution.
928
+ * Used by both simpleExecution and streamingExecution.
929
+ */
930
+ interface ExecutionOptions {
931
+ /**
932
+ * AbortSignal for cancellation.
933
+ * Combined with internal AbortController - both can trigger cancellation.
934
+ *
935
+ * @example
936
+ * ```typescript
937
+ * const controller = new AbortController();
938
+ *
939
+ * // Pass signal to execution
940
+ * const execution = provider.simpleExecution(fn, { signal: controller.signal });
941
+ *
942
+ * // Cancel externally
943
+ * setTimeout(() => controller.abort(), 5000);
944
+ *
945
+ * // Or use execution.cancel() directly
946
+ * execution.cancel();
947
+ * ```
948
+ */
949
+ signal?: AbortSignal;
950
+ }
951
+ /**
952
+ * Status of an execution after completion.
953
+ * - `succeeded`: Execution completed normally with a result
954
+ * - `failed`: Execution threw an error
955
+ * - `canceled`: Execution was canceled via cancel() or AbortSignal
956
+ */
957
+ type ExecutionStatus = 'succeeded' | 'failed' | 'canceled';
958
+ /**
959
+ * Discriminated union representing the outcome of an execution.
960
+ * Summary is always available, regardless of execution status.
961
+ *
962
+ * @typeParam T - The result type on success
963
+ *
964
+ * @example
965
+ * ```typescript
966
+ * const result = await execution.result();
967
+ *
968
+ * if (result.status === 'succeeded') {
969
+ * console.log(result.value);
970
+ * } else if (result.status === 'failed') {
971
+ * console.error(result.error);
972
+ * }
973
+ *
974
+ * // Summary always available
975
+ * console.log(`Cost: $${result.summary.totalCost}`);
976
+ * ```
977
+ */
978
+ type ExecutionResult<T> = {
979
+ status: 'succeeded';
980
+ value: T;
981
+ summary: SessionSummary;
982
+ } | {
983
+ status: 'failed';
984
+ error: Error;
985
+ summary: SessionSummary;
986
+ } | {
987
+ status: 'canceled';
988
+ summary: SessionSummary;
989
+ };
990
+ /**
991
+ * Result type for SimpleExecution.
992
+ * Alias for ExecutionResult for clarity in type annotations.
993
+ */
994
+ type SimpleResult<T> = ExecutionResult<T>;
995
+ /**
996
+ * Result type for StreamingExecution.
997
+ * Extends ExecutionResult with readonly events array.
998
+ * Events are always available, even on failure or cancellation.
999
+ *
1000
+ * @typeParam TEvent - Event type
1001
+ * @typeParam T - Result type on success
1002
+ *
1003
+ * @example
1004
+ * ```typescript
1005
+ * const result = await execution.result();
1006
+ *
1007
+ * // Events always available, regardless of status
1008
+ * console.log(`Received ${result.events.length} events`);
1009
+ *
1010
+ * if (result.status === 'succeeded') {
1011
+ * console.log(result.value);
1012
+ * }
1013
+ * ```
1014
+ */
1015
+ type StreamingResult<TEvent, T> = ExecutionResult<T> & {
1016
+ readonly events: readonly TEvent[];
1017
+ };
1018
+ /**
1019
+ * Base interface for all execution types.
1020
+ * Both streaming and non-streaming executions implement this interface,
1021
+ * enabling unified handling at outer layers.
1022
+ *
1023
+ * @typeParam TResult - The final result type
1024
+ *
1025
+ * @example
1026
+ * ```typescript
1027
+ * // Option 1: Automatic cleanup with await using (recommended)
1028
+ * await using execution = agent.execute(input);
1029
+ * const result = await execution.result();
1030
+ * if (result.status === 'succeeded') {
1031
+ * console.log(result.value, result.summary.totalCost);
1032
+ * }
1033
+ * // cleanup() called automatically on scope exit
1034
+ *
1035
+ * // Option 2: Manual cleanup with try/finally
1036
+ * const execution = agent.execute(input);
1037
+ * try {
1038
+ * const result = await execution.result();
1039
+ * } finally {
1040
+ * await execution.cleanup();
1041
+ * }
1042
+ * ```
1043
+ */
1044
+ interface Execution<TResult> extends AsyncDisposable {
1045
+ /**
1046
+ * Get the execution result with status and summary.
1047
+ * Returns a discriminated union that always includes the summary,
1048
+ * regardless of whether execution succeeded, failed, or was canceled.
1049
+ *
1050
+ * For streaming executions, this waits for all events to complete.
1051
+ *
1052
+ * @example
1053
+ * ```typescript
1054
+ * const result = await execution.result();
1055
+ *
1056
+ * if (result.status === 'succeeded') {
1057
+ * console.log(result.value);
1058
+ * } else if (result.status === 'failed') {
1059
+ * console.error(result.error);
1060
+ * }
1061
+ *
1062
+ * // Summary always available
1063
+ * console.log(`Cost: $${result.summary.totalCost}`);
1064
+ * ```
1065
+ */
1066
+ result(): Promise<ExecutionResult<TResult>>;
1067
+ /**
1068
+ * Request cancellation of the execution.
1069
+ * Aborts the current operation if in progress.
1070
+ * Works even if custom signal was provided (signals are combined).
1071
+ *
1072
+ * No-op if execution already completed.
1073
+ */
1074
+ cancel(): void;
1075
+ /**
1076
+ * Cleanup resources (uploaded files, connections, etc.).
1077
+ * Should always be called after execution, even on error.
1078
+ * Safe to call multiple times.
1079
+ */
1080
+ cleanup(): Promise<void>;
1081
+ /**
1082
+ * Async disposal for `await using` syntax (TS 5.2+).
1083
+ * Delegates to cleanup().
1084
+ */
1085
+ [Symbol.asyncDispose](): Promise<void>;
1086
+ }
1087
+ /**
1088
+ * Simple (non-streaming) execution.
1089
+ * Starts eagerly on construction - execution begins immediately.
1090
+ *
1091
+ * @typeParam TResult - The final result type
1092
+ *
1093
+ * @example
1094
+ * ```typescript
1095
+ * // Start execution (sync - no await, starts immediately)
1096
+ * const execution = provider.simpleExecution(async (session) => {
1097
+ * const response = await session.generateText({ prompt: 'Hello' });
1098
+ * return response.text;
1099
+ * });
1100
+ *
1101
+ * // Cancel if needed
1102
+ * setTimeout(() => execution.cancel(), 5000);
1103
+ *
1104
+ * // Get result (status-based, never throws)
1105
+ * const result = await execution.result();
1106
+ *
1107
+ * if (result.status === 'succeeded') {
1108
+ * console.log(result.value);
1109
+ * } else if (result.status === 'canceled') {
1110
+ * console.log('Execution was canceled');
1111
+ * }
1112
+ *
1113
+ * // Summary always available
1114
+ * console.log(`Cost: $${result.summary.totalCost}`);
1115
+ * ```
1116
+ */
1117
+ interface SimpleExecution<TResult> extends Execution<TResult> {
1118
+ /**
1119
+ * Get the execution result with status and summary.
1120
+ *
1121
+ * @example
1122
+ * ```typescript
1123
+ * const execution = provider.simpleExecution(async (session) => {
1124
+ * const response = await session.generateText({ prompt: 'Hello' });
1125
+ * return response.text;
1126
+ * });
1127
+ *
1128
+ * const result = await execution.result();
1129
+ *
1130
+ * if (result.status === 'succeeded') {
1131
+ * console.log(result.value);
1132
+ * } else if (result.status === 'failed') {
1133
+ * console.error(result.error);
1134
+ * }
1135
+ *
1136
+ * // Summary always available
1137
+ * console.log(`Cost: $${result.summary.totalCost}`);
1138
+ * ```
1139
+ */
1140
+ result(): Promise<SimpleResult<TResult>>;
1141
+ }
1142
+ /**
1143
+ * Represents a streaming execution that emits events as they occur.
1144
+ * TEvent is the user's pure domain event type (without metrics).
1145
+ * stream() and result() return SessionEvent<TEvent> which includes metrics.
1146
+ */
1147
+ interface StreamingExecution<TEvent extends {
1148
+ type: string;
1149
+ }> extends Execution<ExtractResult<TEvent>> {
1150
+ /**
1151
+ * Get the event stream.
1152
+ * Returns an AsyncIterable that yields all events with metrics:
1153
+ * - Events already in the buffer (from eager execution)
1154
+ * - Real-time events as they occur
1155
+ * - ErrorEvent is auto-included — no need to add it to your event union
1156
+ *
1157
+ * Can be called multiple times - each call replays buffered events.
1158
+ * After execution completes, replays all events from buffer.
1159
+ *
1160
+ * @example
1161
+ * ```typescript
1162
+ * type MyEvent =
1163
+ * | { type: 'progress'; step: number }
1164
+ * | CompletionEvent<MyResult>;
1165
+ *
1166
+ * const execution = provider.streamingExecution<MyEvent>(...);
1167
+ *
1168
+ * for await (const event of execution.stream()) {
1169
+ * // event is SessionEvent<MyEvent | ErrorEvent>
1170
+ * console.log(`[${event.metrics.elapsedMs}ms] ${event.type}`);
1171
+ * }
1172
+ * ```
1173
+ */
1174
+ stream(): AsyncIterable<SessionEvent<TEvent | ErrorEvent>>;
1175
+ /**
1176
+ * Get the execution result with status, summary, and all events.
1177
+ *
1178
+ * @example
1179
+ * ```typescript
1180
+ * const result = await execution.result();
1181
+ *
1182
+ * // Events always available
1183
+ * console.log(`Received ${result.events.length} events`);
1184
+ *
1185
+ * if (result.status === 'succeeded') {
1186
+ * console.log(result.value);
1187
+ * }
1188
+ *
1189
+ * console.log(`Cost: $${result.summary.totalCost}`);
1190
+ * ```
1191
+ */
1192
+ result(): Promise<StreamingResult<SessionEvent<TEvent | ErrorEvent>, ExtractResult<TEvent>>>;
1193
+ }
1194
+ /**
1195
+ * Generator function type for streaming executions.
1196
+ * TEvent is the user's pure domain event type (without metrics).
1197
+ * The generator yields SessionEvent<TEvent> which includes metrics.
1198
+ */
1199
+ type SessionStreamGeneratorFn<TEvent extends {
1200
+ type: string;
1201
+ }> = (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>> | undefined, unknown>;
1202
+
1203
+ /**
1204
+ * Abstract base class for AI providers.
1205
+ *
1206
+ * Provides common streamingExecution and simpleExecution implementation.
1207
+ * Subclasses implement session creation and fluent configuration methods.
1208
+ */
1209
+ declare abstract class BaseProvider implements Provider {
1210
+ /**
1211
+ * Create a SimpleSession for non-streaming execution.
1212
+ * @param signal - AbortSignal for cancellation support
1213
+ */
1214
+ protected abstract createSimpleSession(signal?: AbortSignal): SimpleSession;
1215
+ /**
1216
+ * Create a StreamingSession for streaming execution.
1217
+ * @param signal - AbortSignal for cancellation support
1218
+ */
1219
+ protected abstract createStreamingSession<TEvent extends {
1220
+ type: string;
1221
+ }>(signal?: AbortSignal): StreamingSession<TEvent>;
1222
+ abstract withDefaultModel(modelId: string): Provider;
1223
+ abstract withLogger(logger: Logger): Provider;
1224
+ abstract withPricing(pricing: ProviderPricing): Provider;
1225
+ abstract withDefaultOptions(options: Record<string, unknown>): Provider;
1226
+ streamingExecution<TEvent extends {
1227
+ type: string;
1228
+ }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
1229
+ /**
1230
+ * Execute a non-streaming function with cancellation support.
1231
+ * Returns immediately - execution starts in the background.
1232
+ */
1233
+ simpleExecution<TResult>(fn: (session: SimpleSession) => Promise<TResult>, options?: ExecutionOptions): SimpleExecution<TResult>;
1234
+ }
1235
+
1236
+ export { isFileSourceBase64 as $, type LLMCallStartEvent as A, BaseProvider as B, type CalculateCostParams as C, type DistributiveOmit as D, type ErrorEvent as E, type FileSource as F, type LLMCallEndEvent as G, type ExecutionStartEvent as H, type ExecutionEmitEvent as I, type ExecutionDoneEvent as J, type ExecutionErrorEvent as K, type Logger as L, type ModelPricing as M, noopLogger as N, createLogger as O, type ProviderType as P, type Provider as Q, type ReservedEventType as R, type StreamingExecution as S, type FileSourcePath as T, type UploadedFile as U, type FileSourceData as V, type FileSourceBase64 as W, type FileSourceUrl as X, isFileSource as Y, isFileSourcePath as Z, isFileSourceData as _, type PricingConfig as a, isFileSourceUrl as a0, type SimpleSessionOptions as a1, createStreamingSession as a2, type StreamingSessionOptions as a3, type CreateStreamingSessionOptions as a4, type StreamingSessionInternal as a5, type OutputSpec as a6, type DefaultOutput as a7, type InferOutputComplete as a8, type GenerateTextResultTyped as a9, type StreamTextResultTyped as aa, type GenerateTextParams as ab, type GenerateObjectParams as ac, type ToolCallSummary as ad, type LLMCallType as ae, type LLMCallRecord as af, type AdditionalCost as ag, SessionSummary as ah, type SessionSummaryJSON as ai, type ExecutionSession as aj, type DoneMetadata as ak, type ProviderPricing as b, type CostResult as c, StreamingSession as d, type SessionStreamGeneratorFn as e, type SessionEvent as f, type StreamingResult as g, type ExtractResult as h, type SimpleExecution as i, SimpleSession as j, type SimpleResult as k, type ExecutionStatus as l, type CompletionEvent as m, type StreamTextParams as n, type FileCache as o, type FileManager as p, type FileManagerOptions as q, type Execution as r, type ExecutionOptions as s, type ExecutionResult as t, type SessionEventInput as u, type EmittableEventInput as v, type EventMetrics as w, type ExecutionMetadata as x, type LogLevel as y, type LLMCallLogType as z };