@agtlantis/core 0.5.0 → 0.6.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/README.md +18 -5
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +69 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +116 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/errors/utils.d.ts +17 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +16 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/execution/constants.d.ts +7 -0
- package/dist/execution/constants.d.ts.map +1 -0
- package/dist/execution/constants.js +7 -0
- package/dist/execution/constants.js.map +1 -0
- package/dist/execution/index.d.ts +8 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/mapping.d.ts +17 -0
- package/dist/execution/mapping.d.ts.map +1 -0
- package/dist/execution/mapping.js +197 -0
- package/dist/execution/mapping.js.map +1 -0
- package/dist/execution/shared.d.ts +86 -0
- package/dist/execution/shared.d.ts.map +1 -0
- package/dist/execution/shared.js +100 -0
- package/dist/execution/shared.js.map +1 -0
- package/dist/execution/simple-host.d.ts +56 -0
- package/dist/execution/simple-host.d.ts.map +1 -0
- package/dist/execution/simple-host.js +126 -0
- package/dist/execution/simple-host.js.map +1 -0
- package/dist/execution/streaming-host.d.ts +79 -0
- package/dist/execution/streaming-host.d.ts.map +1 -0
- package/dist/execution/streaming-host.js +276 -0
- package/dist/execution/streaming-host.js.map +1 -0
- package/dist/execution/testing/fixtures.d.ts +67 -0
- package/dist/execution/testing/fixtures.d.ts.map +1 -0
- package/dist/execution/testing/fixtures.js +145 -0
- package/dist/execution/testing/fixtures.js.map +1 -0
- package/dist/execution/testing/helpers.d.ts +218 -0
- package/dist/execution/testing/helpers.d.ts.map +1 -0
- package/dist/execution/testing/helpers.js +327 -0
- package/dist/execution/testing/helpers.js.map +1 -0
- package/dist/execution/testing/host-configs.d.ts +56 -0
- package/dist/execution/testing/host-configs.d.ts.map +1 -0
- package/dist/execution/testing/host-configs.js +154 -0
- package/dist/execution/testing/host-configs.js.map +1 -0
- package/dist/execution/testing/vitest-assertions.d.ts +102 -0
- package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
- package/dist/execution/testing/vitest-assertions.js +142 -0
- package/dist/execution/testing/vitest-assertions.js.map +1 -0
- package/dist/execution/types.d.ts +432 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +2 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/utils.d.ts +68 -0
- package/dist/execution/utils.d.ts.map +1 -0
- package/dist/execution/utils.js +93 -0
- package/dist/execution/utils.js.map +1 -0
- package/dist/index.d.ts +10 -1506
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2979
- package/dist/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +2 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +161 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +31 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/types.d.ts +46 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +2 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/patterns/index.d.ts +2 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +2 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/progressive/index.d.ts +2 -0
- package/dist/patterns/progressive/index.d.ts.map +1 -0
- package/dist/patterns/progressive/index.js +2 -0
- package/dist/patterns/progressive/index.js.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.js +260 -0
- package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
- package/dist/pricing/calculator.d.ts +71 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +127 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/config.d.ts +61 -0
- package/dist/pricing/config.d.ts.map +1 -0
- package/dist/pricing/config.js +87 -0
- package/dist/pricing/config.js.map +1 -0
- package/dist/pricing/defaults.d.ts +29 -0
- package/dist/pricing/defaults.d.ts.map +1 -0
- package/dist/pricing/defaults.js +139 -0
- package/dist/pricing/defaults.js.map +1 -0
- package/dist/pricing/index.d.ts +40 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +43 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/types.d.ts +96 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +7 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/pricing/validator.d.ts +55 -0
- package/dist/pricing/validator.d.ts.map +1 -0
- package/dist/pricing/validator.js +84 -0
- package/dist/pricing/validator.js.map +1 -0
- package/dist/prompt/errors.d.ts +112 -0
- package/dist/prompt/errors.d.ts.map +1 -0
- package/dist/prompt/errors.js +174 -0
- package/dist/prompt/errors.js.map +1 -0
- package/dist/prompt/file-prompt-repository.d.ts +80 -0
- package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
- package/dist/prompt/file-prompt-repository.js +287 -0
- package/dist/prompt/file-prompt-repository.js.map +1 -0
- package/dist/prompt/index.d.ts +34 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +37 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/prompt-template.d.ts +64 -0
- package/dist/prompt/prompt-template.d.ts.map +1 -0
- package/dist/prompt/prompt-template.js +90 -0
- package/dist/prompt/prompt-template.js.map +1 -0
- package/dist/prompt/template.d.ts +23 -0
- package/dist/prompt/template.d.ts.map +1 -0
- package/dist/prompt/template.js +70 -0
- package/dist/prompt/template.js.map +1 -0
- package/dist/prompt/types.d.ts +148 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +7 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/provider/base-file-manager.d.ts +14 -0
- package/dist/provider/base-file-manager.d.ts.map +1 -0
- package/dist/provider/base-file-manager.js +91 -0
- package/dist/provider/base-file-manager.js.map +1 -0
- package/dist/provider/base-provider.d.ts +41 -0
- package/dist/provider/base-provider.d.ts.map +1 -0
- package/dist/provider/base-provider.js +21 -0
- package/dist/provider/base-provider.js.map +1 -0
- package/dist/provider/file-cache.d.ts +14 -0
- package/dist/provider/file-cache.d.ts.map +1 -0
- package/dist/provider/file-cache.js +29 -0
- package/dist/provider/file-cache.js.map +1 -0
- package/dist/provider/file-source.d.ts +32 -0
- package/dist/provider/file-source.d.ts.map +1 -0
- package/dist/provider/file-source.js +180 -0
- package/dist/provider/file-source.js.map +1 -0
- package/dist/provider/file-utils.d.ts +5 -0
- package/dist/provider/file-utils.d.ts.map +1 -0
- package/dist/provider/file-utils.js +15 -0
- package/dist/provider/file-utils.js.map +1 -0
- package/dist/provider/google/factory.d.ts +107 -0
- package/dist/provider/google/factory.d.ts.map +1 -0
- package/dist/provider/google/factory.js +143 -0
- package/dist/provider/google/factory.js.map +1 -0
- package/dist/provider/google/file-manager.d.ts +10 -0
- package/dist/provider/google/file-manager.d.ts.map +1 -0
- package/dist/provider/google/file-manager.js +93 -0
- package/dist/provider/google/file-manager.js.map +1 -0
- package/dist/provider/google/index.d.ts +8 -0
- package/dist/provider/google/index.d.ts.map +1 -0
- package/dist/provider/google/index.js +10 -0
- package/dist/provider/google/index.js.map +1 -0
- package/dist/provider/hash.d.ts +3 -0
- package/dist/provider/hash.d.ts.map +1 -0
- package/dist/provider/hash.js +34 -0
- package/dist/provider/hash.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +12 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/noop-file-manager.d.ts +9 -0
- package/dist/provider/noop-file-manager.d.ts.map +1 -0
- package/dist/provider/noop-file-manager.js +28 -0
- package/dist/provider/noop-file-manager.js.map +1 -0
- package/dist/provider/openai/factory.d.ts +67 -0
- package/dist/provider/openai/factory.d.ts.map +1 -0
- package/dist/provider/openai/factory.js +100 -0
- package/dist/provider/openai/factory.js.map +1 -0
- package/dist/provider/openai/file-manager.d.ts +17 -0
- package/dist/provider/openai/file-manager.d.ts.map +1 -0
- package/dist/provider/openai/file-manager.js +108 -0
- package/dist/provider/openai/file-manager.js.map +1 -0
- package/dist/provider/openai/index.d.ts +8 -0
- package/dist/provider/openai/index.d.ts.map +1 -0
- package/dist/provider/openai/index.js +8 -0
- package/dist/provider/openai/index.js.map +1 -0
- package/dist/provider/types.d.ts +105 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +19 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/simple-session.d.ts +98 -0
- package/dist/session/simple-session.d.ts.map +1 -0
- package/dist/session/simple-session.js +299 -0
- package/dist/session/simple-session.js.map +1 -0
- package/dist/session/streaming-session.d.ts +90 -0
- package/dist/session/streaming-session.d.ts.map +1 -0
- package/dist/session/streaming-session.js +151 -0
- package/dist/session/streaming-session.js.map +1 -0
- package/dist/session/test-utils.d.ts +19 -0
- package/dist/session/test-utils.d.ts.map +1 -0
- package/dist/session/test-utils.js +65 -0
- package/dist/session/test-utils.js.map +1 -0
- package/dist/session/types.d.ts +219 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +181 -0
- package/dist/session/types.js.map +1 -0
- package/dist/session/usage-extractors.d.ts +7 -0
- package/dist/session/usage-extractors.d.ts.map +1 -0
- package/dist/session/usage-extractors.js +71 -0
- package/dist/session/usage-extractors.js.map +1 -0
- package/dist/testing/fixtures.d.ts +34 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +65 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +20 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +32 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +7 -519
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +21 -2123
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock-provider.d.ts +79 -0
- package/dist/testing/mock-provider.d.ts.map +1 -0
- package/dist/testing/mock-provider.js +152 -0
- package/dist/testing/mock-provider.js.map +1 -0
- package/dist/testing/mock.d.ts +29 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +154 -0
- package/dist/testing/mock.js.map +1 -0
- package/dist/testing/test-execution.d.ts +14 -0
- package/dist/testing/test-execution.d.ts.map +1 -0
- package/dist/testing/test-execution.js +108 -0
- package/dist/testing/test-execution.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +6 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +24 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/validation/errors.d.ts +28 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/errors.js +38 -0
- package/dist/validation/errors.js.map +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +4 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +49 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/dist/validation/validation-history.d.ts +12 -0
- package/dist/validation/validation-history.d.ts.map +1 -0
- package/dist/validation/validation-history.js +29 -0
- package/dist/validation/validation-history.js.map +1 -0
- package/dist/validation/with-validation.d.ts +38 -0
- package/dist/validation/with-validation.d.ts.map +1 -0
- package/dist/validation/with-validation.js +58 -0
- package/dist/validation/with-validation.js.map +1 -0
- package/package.json +71 -75
- package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
- package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
- package/dist/index.cjs +0 -3085
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1506
- package/dist/testing/index.cjs +0 -2167
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -520
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent execution types for @agtlantis/core.
|
|
3
|
+
* Provides abstractions for streaming and non-streaming agent execution.
|
|
4
|
+
*/
|
|
5
|
+
import type { EventMetrics } from '../observability/index.js';
|
|
6
|
+
import type { SessionSummary, StreamingSession } from '../session/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Distributive version of Omit that properly handles union types.
|
|
9
|
+
*
|
|
10
|
+
* Standard `Omit<A | B, K>` loses unique properties from union members.
|
|
11
|
+
* `DistributiveOmit<A | B, K>` preserves them by distributing over the union.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* type A = { type: 'a'; foo: string; metrics: EventMetrics };
|
|
16
|
+
* type B = { type: 'b'; bar: number; metrics: EventMetrics };
|
|
17
|
+
* type Union = A | B;
|
|
18
|
+
*
|
|
19
|
+
* // ❌ Standard Omit - loses foo and bar
|
|
20
|
+
* type Bad = Omit<Union, 'metrics'>;
|
|
21
|
+
* // Result: { type: 'a' | 'b' }
|
|
22
|
+
*
|
|
23
|
+
* // ✅ DistributiveOmit - preserves unique properties
|
|
24
|
+
* type Good = DistributiveOmit<Union, 'metrics'>;
|
|
25
|
+
* // Result: { type: 'a'; foo: string } | { type: 'b'; bar: number }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
29
|
+
/**
|
|
30
|
+
* Adds `metrics: EventMetrics` to event types.
|
|
31
|
+
* The framework uses this internally to wrap user-defined events with timing info.
|
|
32
|
+
*
|
|
33
|
+
* **For most use cases, you don't need this type.** Simply define your events
|
|
34
|
+
* without metrics, and the framework handles the wrapping automatically.
|
|
35
|
+
*
|
|
36
|
+
* **When you need SessionEvent:**
|
|
37
|
+
* - Creating mock/stub streaming executions for testing
|
|
38
|
+
* - Explicitly typing `StreamingResult.events` arrays
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // User defines pure event types (recommended)
|
|
43
|
+
* type MyEvent =
|
|
44
|
+
* | { type: 'progress'; step: string }
|
|
45
|
+
* | { type: 'complete'; data: string };
|
|
46
|
+
*
|
|
47
|
+
* // Framework internally wraps as SessionEvent<MyEvent>
|
|
48
|
+
* // StreamingResult.events returns SessionEvent<MyEvent>[]
|
|
49
|
+
*
|
|
50
|
+
* // Testing: Create mock events with explicit metrics
|
|
51
|
+
* const mockEvents: SessionEvent<MyEvent>[] = [
|
|
52
|
+
* { type: 'progress', step: 'loading', metrics: { timestamp: Date.now(), elapsedMs: 0, deltaMs: 0 } },
|
|
53
|
+
* ];
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type SessionEvent<T extends {
|
|
57
|
+
type: string;
|
|
58
|
+
}> = T & {
|
|
59
|
+
metrics: EventMetrics;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Input type for session.emit() - removes metrics from event types.
|
|
63
|
+
* Uses DistributiveOmit to properly handle union types.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* type MyAgentEvent = SessionEvent<ProgressEvent | CompleteEvent | ErrorEvent>;
|
|
68
|
+
*
|
|
69
|
+
* // For emit input, metrics is not required
|
|
70
|
+
* type EmitInput = SessionEventInput<MyAgentEvent>;
|
|
71
|
+
*
|
|
72
|
+
* // Usage in session.emit()
|
|
73
|
+
* session.emit({ type: 'progress', step: 'reading', message: 'Loading...' });
|
|
74
|
+
* // No casting needed!
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated TEvent no longer requires metrics constraint - use TEvent directly
|
|
79
|
+
* This type is kept for backwards compatibility during migration
|
|
80
|
+
*/
|
|
81
|
+
export type SessionEventInput<T extends {
|
|
82
|
+
type: string;
|
|
83
|
+
}> = T;
|
|
84
|
+
/**
|
|
85
|
+
* Reserved event types that cannot be emitted directly via session.emit().
|
|
86
|
+
* These types are controlled internally by session.done() and session.fail().
|
|
87
|
+
*/
|
|
88
|
+
export type ReservedEventType = 'complete' | 'error';
|
|
89
|
+
/**
|
|
90
|
+
* Input type for emit() - excludes reserved event types.
|
|
91
|
+
* Users define pure domain events; framework adds metrics wrapper.
|
|
92
|
+
*/
|
|
93
|
+
export type EmittableEventInput<T extends {
|
|
94
|
+
type: string;
|
|
95
|
+
}> = T extends {
|
|
96
|
+
type: ReservedEventType;
|
|
97
|
+
} ? never : T;
|
|
98
|
+
/**
|
|
99
|
+
* Completion event emitted by session.done().
|
|
100
|
+
* Include this in your event union to define the result type.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* type MyEvent =
|
|
105
|
+
* | { type: 'progress'; step: string }
|
|
106
|
+
* | CompletionEvent<MyResult>;
|
|
107
|
+
*
|
|
108
|
+
* // session.done(result) emits { type: 'complete', data: result, summary }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export type CompletionEvent<TResult> = {
|
|
112
|
+
type: 'complete';
|
|
113
|
+
data: TResult;
|
|
114
|
+
summary: SessionSummary;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Error event emitted by session.fail().
|
|
118
|
+
* Auto-added to stream() return type — users don't need to include this in their event union.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* for await (const event of execution.stream()) {
|
|
123
|
+
* if (event.type === 'error') {
|
|
124
|
+
* console.error(event.error.message);
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export type ErrorEvent = {
|
|
130
|
+
type: 'error';
|
|
131
|
+
error: Error;
|
|
132
|
+
summary?: SessionSummary;
|
|
133
|
+
data?: unknown;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Extract the result type from an event union containing CompletionEvent<T>.
|
|
137
|
+
* Returns `never` if no CompletionEvent member exists (making session.done() uncallable).
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* type MyEvent =
|
|
142
|
+
* | { type: 'progress'; step: string }
|
|
143
|
+
* | CompletionEvent<{ answer: string }>;
|
|
144
|
+
*
|
|
145
|
+
* type Result = ExtractResult<MyEvent>;
|
|
146
|
+
* // Result = { answer: string }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export type ExtractResult<TEvent extends {
|
|
150
|
+
type: string;
|
|
151
|
+
}> = Extract<TEvent, {
|
|
152
|
+
type: 'complete';
|
|
153
|
+
}> extends {
|
|
154
|
+
data: infer R;
|
|
155
|
+
} ? R : never;
|
|
156
|
+
/**
|
|
157
|
+
* Options for execution.
|
|
158
|
+
* Used by both simpleExecution and streamingExecution.
|
|
159
|
+
*/
|
|
160
|
+
export interface ExecutionOptions {
|
|
161
|
+
/**
|
|
162
|
+
* AbortSignal for cancellation.
|
|
163
|
+
* Combined with internal AbortController - both can trigger cancellation.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const controller = new AbortController();
|
|
168
|
+
*
|
|
169
|
+
* // Pass signal to execution
|
|
170
|
+
* const execution = provider.simpleExecution(fn, { signal: controller.signal });
|
|
171
|
+
*
|
|
172
|
+
* // Cancel externally
|
|
173
|
+
* setTimeout(() => controller.abort(), 5000);
|
|
174
|
+
*
|
|
175
|
+
* // Or use execution.cancel() directly
|
|
176
|
+
* execution.cancel();
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
signal?: AbortSignal;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Status of an execution after completion.
|
|
183
|
+
* - `succeeded`: Execution completed normally with a result
|
|
184
|
+
* - `failed`: Execution threw an error
|
|
185
|
+
* - `canceled`: Execution was canceled via cancel() or AbortSignal
|
|
186
|
+
*/
|
|
187
|
+
export type ExecutionStatus = 'succeeded' | 'failed' | 'canceled';
|
|
188
|
+
/**
|
|
189
|
+
* Discriminated union representing the outcome of an execution.
|
|
190
|
+
* Summary is always available, regardless of execution status.
|
|
191
|
+
*
|
|
192
|
+
* @typeParam T - The result type on success
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const result = await execution.result();
|
|
197
|
+
*
|
|
198
|
+
* if (result.status === 'succeeded') {
|
|
199
|
+
* console.log(result.value);
|
|
200
|
+
* } else if (result.status === 'failed') {
|
|
201
|
+
* console.error(result.error);
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* // Summary always available
|
|
205
|
+
* console.log(`Cost: $${result.summary.totalCost}`);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export type ExecutionResult<T> = {
|
|
209
|
+
status: 'succeeded';
|
|
210
|
+
value: T;
|
|
211
|
+
summary: SessionSummary;
|
|
212
|
+
} | {
|
|
213
|
+
status: 'failed';
|
|
214
|
+
error: Error;
|
|
215
|
+
summary: SessionSummary;
|
|
216
|
+
} | {
|
|
217
|
+
status: 'canceled';
|
|
218
|
+
summary: SessionSummary;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Result type for SimpleExecution.
|
|
222
|
+
* Alias for ExecutionResult for clarity in type annotations.
|
|
223
|
+
*/
|
|
224
|
+
export type SimpleResult<T> = ExecutionResult<T>;
|
|
225
|
+
/**
|
|
226
|
+
* Result type for StreamingExecution.
|
|
227
|
+
* Extends ExecutionResult with readonly events array.
|
|
228
|
+
* Events are always available, even on failure or cancellation.
|
|
229
|
+
*
|
|
230
|
+
* @typeParam TEvent - Event type
|
|
231
|
+
* @typeParam T - Result type on success
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const result = await execution.result();
|
|
236
|
+
*
|
|
237
|
+
* // Events always available, regardless of status
|
|
238
|
+
* console.log(`Received ${result.events.length} events`);
|
|
239
|
+
*
|
|
240
|
+
* if (result.status === 'succeeded') {
|
|
241
|
+
* console.log(result.value);
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export type StreamingResult<TEvent, T> = ExecutionResult<T> & {
|
|
246
|
+
readonly events: readonly TEvent[];
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Base interface for all execution types.
|
|
250
|
+
* Both streaming and non-streaming executions implement this interface,
|
|
251
|
+
* enabling unified handling at outer layers.
|
|
252
|
+
*
|
|
253
|
+
* @typeParam TResult - The final result type
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* // Option 1: Automatic cleanup with await using (recommended)
|
|
258
|
+
* await using execution = agent.execute(input);
|
|
259
|
+
* const result = await execution.result();
|
|
260
|
+
* if (result.status === 'succeeded') {
|
|
261
|
+
* console.log(result.value, result.summary.totalCost);
|
|
262
|
+
* }
|
|
263
|
+
* // cleanup() called automatically on scope exit
|
|
264
|
+
*
|
|
265
|
+
* // Option 2: Manual cleanup with try/finally
|
|
266
|
+
* const execution = agent.execute(input);
|
|
267
|
+
* try {
|
|
268
|
+
* const result = await execution.result();
|
|
269
|
+
* } finally {
|
|
270
|
+
* await execution.cleanup();
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export interface Execution<TResult> extends AsyncDisposable {
|
|
275
|
+
/**
|
|
276
|
+
* Get the execution result with status and summary.
|
|
277
|
+
* Returns a discriminated union that always includes the summary,
|
|
278
|
+
* regardless of whether execution succeeded, failed, or was canceled.
|
|
279
|
+
*
|
|
280
|
+
* For streaming executions, this waits for all events to complete.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* const result = await execution.result();
|
|
285
|
+
*
|
|
286
|
+
* if (result.status === 'succeeded') {
|
|
287
|
+
* console.log(result.value);
|
|
288
|
+
* } else if (result.status === 'failed') {
|
|
289
|
+
* console.error(result.error);
|
|
290
|
+
* }
|
|
291
|
+
*
|
|
292
|
+
* // Summary always available
|
|
293
|
+
* console.log(`Cost: $${result.summary.totalCost}`);
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
result(): Promise<ExecutionResult<TResult>>;
|
|
297
|
+
/**
|
|
298
|
+
* Request cancellation of the execution.
|
|
299
|
+
* Aborts the current operation if in progress.
|
|
300
|
+
* Works even if custom signal was provided (signals are combined).
|
|
301
|
+
*
|
|
302
|
+
* No-op if execution already completed.
|
|
303
|
+
*/
|
|
304
|
+
cancel(): void;
|
|
305
|
+
/**
|
|
306
|
+
* Cleanup resources (uploaded files, connections, etc.).
|
|
307
|
+
* Should always be called after execution, even on error.
|
|
308
|
+
* Safe to call multiple times.
|
|
309
|
+
*/
|
|
310
|
+
cleanup(): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Async disposal for `await using` syntax (TS 5.2+).
|
|
313
|
+
* Delegates to cleanup().
|
|
314
|
+
*/
|
|
315
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Simple (non-streaming) execution.
|
|
319
|
+
* Starts eagerly on construction - execution begins immediately.
|
|
320
|
+
*
|
|
321
|
+
* @typeParam TResult - The final result type
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* // Start execution (sync - no await, starts immediately)
|
|
326
|
+
* const execution = provider.simpleExecution(async (session) => {
|
|
327
|
+
* const response = await session.generateText({ prompt: 'Hello' });
|
|
328
|
+
* return response.text;
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* // Cancel if needed
|
|
332
|
+
* setTimeout(() => execution.cancel(), 5000);
|
|
333
|
+
*
|
|
334
|
+
* // Get result (status-based, never throws)
|
|
335
|
+
* const result = await execution.result();
|
|
336
|
+
*
|
|
337
|
+
* if (result.status === 'succeeded') {
|
|
338
|
+
* console.log(result.value);
|
|
339
|
+
* } else if (result.status === 'canceled') {
|
|
340
|
+
* console.log('Execution was canceled');
|
|
341
|
+
* }
|
|
342
|
+
*
|
|
343
|
+
* // Summary always available
|
|
344
|
+
* console.log(`Cost: $${result.summary.totalCost}`);
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export interface SimpleExecution<TResult> extends Execution<TResult> {
|
|
348
|
+
/**
|
|
349
|
+
* Get the execution result with status and summary.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const execution = provider.simpleExecution(async (session) => {
|
|
354
|
+
* const response = await session.generateText({ prompt: 'Hello' });
|
|
355
|
+
* return response.text;
|
|
356
|
+
* });
|
|
357
|
+
*
|
|
358
|
+
* const result = await execution.result();
|
|
359
|
+
*
|
|
360
|
+
* if (result.status === 'succeeded') {
|
|
361
|
+
* console.log(result.value);
|
|
362
|
+
* } else if (result.status === 'failed') {
|
|
363
|
+
* console.error(result.error);
|
|
364
|
+
* }
|
|
365
|
+
*
|
|
366
|
+
* // Summary always available
|
|
367
|
+
* console.log(`Cost: $${result.summary.totalCost}`);
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
result(): Promise<SimpleResult<TResult>>;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Represents a streaming execution that emits events as they occur.
|
|
374
|
+
* TEvent is the user's pure domain event type (without metrics).
|
|
375
|
+
* stream() and result() return SessionEvent<TEvent> which includes metrics.
|
|
376
|
+
*/
|
|
377
|
+
export interface StreamingExecution<TEvent extends {
|
|
378
|
+
type: string;
|
|
379
|
+
}> extends Execution<ExtractResult<TEvent>> {
|
|
380
|
+
/**
|
|
381
|
+
* Get the event stream.
|
|
382
|
+
* Returns an AsyncIterable that yields all events with metrics:
|
|
383
|
+
* - Events already in the buffer (from eager execution)
|
|
384
|
+
* - Real-time events as they occur
|
|
385
|
+
* - ErrorEvent is auto-included — no need to add it to your event union
|
|
386
|
+
*
|
|
387
|
+
* Can be called multiple times - each call replays buffered events.
|
|
388
|
+
* After execution completes, replays all events from buffer.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* type MyEvent =
|
|
393
|
+
* | { type: 'progress'; step: number }
|
|
394
|
+
* | CompletionEvent<MyResult>;
|
|
395
|
+
*
|
|
396
|
+
* const execution = provider.streamingExecution<MyEvent>(...);
|
|
397
|
+
*
|
|
398
|
+
* for await (const event of execution.stream()) {
|
|
399
|
+
* // event is SessionEvent<MyEvent | ErrorEvent>
|
|
400
|
+
* console.log(`[${event.metrics.elapsedMs}ms] ${event.type}`);
|
|
401
|
+
* }
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
stream(): AsyncIterable<SessionEvent<TEvent | ErrorEvent>>;
|
|
405
|
+
/**
|
|
406
|
+
* Get the execution result with status, summary, and all events.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const result = await execution.result();
|
|
411
|
+
*
|
|
412
|
+
* // Events always available
|
|
413
|
+
* console.log(`Received ${result.events.length} events`);
|
|
414
|
+
*
|
|
415
|
+
* if (result.status === 'succeeded') {
|
|
416
|
+
* console.log(result.value);
|
|
417
|
+
* }
|
|
418
|
+
*
|
|
419
|
+
* console.log(`Cost: $${result.summary.totalCost}`);
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
result(): Promise<StreamingResult<SessionEvent<TEvent | ErrorEvent>, ExtractResult<TEvent>>>;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Generator function type for streaming executions.
|
|
426
|
+
* TEvent is the user's pure domain event type (without metrics).
|
|
427
|
+
* The generator yields SessionEvent<TEvent> which includes metrics.
|
|
428
|
+
*/
|
|
429
|
+
export type SessionStreamGeneratorFn<TEvent extends {
|
|
430
|
+
type: string;
|
|
431
|
+
}> = (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>> | undefined, unknown>;
|
|
432
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/execution/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/execution/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate duration from start time in milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* @param startTime - The start timestamp from Date.now()
|
|
5
|
+
* @returns Duration in milliseconds
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDuration(startTime: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Combine multiple AbortSignals into a single signal.
|
|
10
|
+
* The combined signal aborts when ANY of the source signals abort.
|
|
11
|
+
*
|
|
12
|
+
* Node 18 compatible - doesn't use AbortSignal.any() which is Node 20+.
|
|
13
|
+
*
|
|
14
|
+
* @param signals - AbortSignals to combine
|
|
15
|
+
* @returns A new AbortSignal that aborts when any input signal aborts
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const userController = new AbortController();
|
|
20
|
+
* const timeoutController = new AbortController();
|
|
21
|
+
*
|
|
22
|
+
* const combined = combineSignals(userController.signal, timeoutController.signal);
|
|
23
|
+
*
|
|
24
|
+
* // Either abort triggers the combined signal
|
|
25
|
+
* userController.abort(); // combined.aborted === true
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function combineSignals(...signals: AbortSignal[]): AbortSignal;
|
|
29
|
+
/**
|
|
30
|
+
* A Promise that can be resolved or rejected externally.
|
|
31
|
+
*
|
|
32
|
+
* Useful for bridging callback-based APIs to async/await patterns.
|
|
33
|
+
* The resolve/reject functions are exposed as instance properties,
|
|
34
|
+
* allowing external code to control when the promise settles.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - The type of the resolved value (defaults to void)
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const deferred = new Deferred<string>();
|
|
41
|
+
*
|
|
42
|
+
* // Later, in a callback:
|
|
43
|
+
* someApi.onData((data) => deferred.resolve(data));
|
|
44
|
+
* someApi.onError((err) => deferred.reject(err));
|
|
45
|
+
*
|
|
46
|
+
* // Await the result:
|
|
47
|
+
* const result = await deferred.promise;
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // In async generator for event notification:
|
|
53
|
+
* let pending = new Deferred<void>();
|
|
54
|
+
* const subscriber = () => pending.resolve();
|
|
55
|
+
*
|
|
56
|
+
* while (!done) {
|
|
57
|
+
* await pending.promise;
|
|
58
|
+
* pending = new Deferred<void>(); // Reset for next wait
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class Deferred<T = void> {
|
|
63
|
+
readonly promise: Promise<T>;
|
|
64
|
+
readonly resolve: (value: T) => void;
|
|
65
|
+
readonly reject: (error: Error) => void;
|
|
66
|
+
constructor();
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/execution/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,GAAG,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,CAiBrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,QAAQ,CAAC,CAAC,GAAG,IAAI;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAExC,cASC;CACF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate duration from start time in milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* @param startTime - The start timestamp from Date.now()
|
|
5
|
+
* @returns Duration in milliseconds
|
|
6
|
+
*/
|
|
7
|
+
export function getDuration(startTime) {
|
|
8
|
+
return Date.now() - startTime;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Combine multiple AbortSignals into a single signal.
|
|
12
|
+
* The combined signal aborts when ANY of the source signals abort.
|
|
13
|
+
*
|
|
14
|
+
* Node 18 compatible - doesn't use AbortSignal.any() which is Node 20+.
|
|
15
|
+
*
|
|
16
|
+
* @param signals - AbortSignals to combine
|
|
17
|
+
* @returns A new AbortSignal that aborts when any input signal aborts
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const userController = new AbortController();
|
|
22
|
+
* const timeoutController = new AbortController();
|
|
23
|
+
*
|
|
24
|
+
* const combined = combineSignals(userController.signal, timeoutController.signal);
|
|
25
|
+
*
|
|
26
|
+
* // Either abort triggers the combined signal
|
|
27
|
+
* userController.abort(); // combined.aborted === true
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function combineSignals(...signals) {
|
|
31
|
+
const controller = new AbortController();
|
|
32
|
+
for (const signal of signals) {
|
|
33
|
+
// If any signal is already aborted, immediately abort and return
|
|
34
|
+
if (signal.aborted) {
|
|
35
|
+
controller.abort(signal.reason);
|
|
36
|
+
return controller.signal;
|
|
37
|
+
}
|
|
38
|
+
// Listen for future aborts
|
|
39
|
+
signal.addEventListener('abort', () => controller.abort(signal.reason), {
|
|
40
|
+
once: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return controller.signal;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A Promise that can be resolved or rejected externally.
|
|
47
|
+
*
|
|
48
|
+
* Useful for bridging callback-based APIs to async/await patterns.
|
|
49
|
+
* The resolve/reject functions are exposed as instance properties,
|
|
50
|
+
* allowing external code to control when the promise settles.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam T - The type of the resolved value (defaults to void)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const deferred = new Deferred<string>();
|
|
57
|
+
*
|
|
58
|
+
* // Later, in a callback:
|
|
59
|
+
* someApi.onData((data) => deferred.resolve(data));
|
|
60
|
+
* someApi.onError((err) => deferred.reject(err));
|
|
61
|
+
*
|
|
62
|
+
* // Await the result:
|
|
63
|
+
* const result = await deferred.promise;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // In async generator for event notification:
|
|
69
|
+
* let pending = new Deferred<void>();
|
|
70
|
+
* const subscriber = () => pending.resolve();
|
|
71
|
+
*
|
|
72
|
+
* while (!done) {
|
|
73
|
+
* await pending.promise;
|
|
74
|
+
* pending = new Deferred<void>(); // Reset for next wait
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export class Deferred {
|
|
79
|
+
promise;
|
|
80
|
+
resolve;
|
|
81
|
+
reject;
|
|
82
|
+
constructor() {
|
|
83
|
+
let res;
|
|
84
|
+
let rej;
|
|
85
|
+
this.promise = new Promise((resolve, reject) => {
|
|
86
|
+
res = resolve;
|
|
87
|
+
rej = reject;
|
|
88
|
+
});
|
|
89
|
+
this.resolve = res;
|
|
90
|
+
this.reject = rej;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/execution/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc,CAAC,GAAG,OAAsB;IACtD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAEzC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,iEAAiE;QACjE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,CAAC;QAED,2BAA2B;QAC3B,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACtE,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,QAAQ;IACV,OAAO,CAAa;IACpB,OAAO,CAAqB;IAC5B,MAAM,CAAyB;IAExC;QACE,IAAI,GAAwB,CAAC;QAC7B,IAAI,GAA4B,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAChD,GAAG,GAAG,OAAO,CAAC;YACd,GAAG,GAAG,MAAM,CAAC;QACf,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;IACpB,CAAC;CACF"}
|