ai.matey.middleware 0.2.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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/caching.js +226 -0
  3. package/dist/cjs/caching.js.map +1 -0
  4. package/dist/cjs/conversation-history.js +213 -0
  5. package/dist/cjs/conversation-history.js.map +1 -0
  6. package/dist/cjs/cost-tracking.js +355 -0
  7. package/dist/cjs/cost-tracking.js.map +1 -0
  8. package/dist/cjs/index.js +37 -0
  9. package/dist/cjs/index.js.map +1 -0
  10. package/dist/cjs/logging.js +174 -0
  11. package/dist/cjs/logging.js.map +1 -0
  12. package/dist/cjs/opentelemetry.js +499 -0
  13. package/dist/cjs/opentelemetry.js.map +1 -0
  14. package/dist/cjs/retry.js +205 -0
  15. package/dist/cjs/retry.js.map +1 -0
  16. package/dist/cjs/security.js +175 -0
  17. package/dist/cjs/security.js.map +1 -0
  18. package/dist/cjs/telemetry.js +216 -0
  19. package/dist/cjs/telemetry.js.map +1 -0
  20. package/dist/cjs/transform.js +284 -0
  21. package/dist/cjs/transform.js.map +1 -0
  22. package/dist/cjs/validation.js +506 -0
  23. package/dist/cjs/validation.js.map +1 -0
  24. package/dist/esm/caching.js +221 -0
  25. package/dist/esm/caching.js.map +1 -0
  26. package/dist/esm/conversation-history.js +207 -0
  27. package/dist/esm/conversation-history.js.map +1 -0
  28. package/dist/esm/cost-tracking.js +347 -0
  29. package/dist/esm/cost-tracking.js.map +1 -0
  30. package/dist/esm/index.js +21 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/logging.js +171 -0
  33. package/dist/esm/logging.js.map +1 -0
  34. package/dist/esm/opentelemetry.js +458 -0
  35. package/dist/esm/opentelemetry.js.map +1 -0
  36. package/dist/esm/retry.js +198 -0
  37. package/dist/esm/retry.js.map +1 -0
  38. package/dist/esm/security.js +169 -0
  39. package/dist/esm/security.js.map +1 -0
  40. package/dist/esm/telemetry.js +210 -0
  41. package/dist/esm/telemetry.js.map +1 -0
  42. package/dist/esm/transform.js +272 -0
  43. package/dist/esm/transform.js.map +1 -0
  44. package/dist/esm/validation.js +494 -0
  45. package/dist/esm/validation.js.map +1 -0
  46. package/dist/types/caching.d.ts +98 -0
  47. package/dist/types/caching.d.ts.map +1 -0
  48. package/dist/types/conversation-history.d.ts +188 -0
  49. package/dist/types/conversation-history.d.ts.map +1 -0
  50. package/dist/types/cost-tracking.d.ts +262 -0
  51. package/dist/types/cost-tracking.d.ts.map +1 -0
  52. package/dist/types/index.d.ts +20 -0
  53. package/dist/types/index.d.ts.map +1 -0
  54. package/dist/types/logging.d.ts +82 -0
  55. package/dist/types/logging.d.ts.map +1 -0
  56. package/dist/types/opentelemetry.d.ts +219 -0
  57. package/dist/types/opentelemetry.d.ts.map +1 -0
  58. package/dist/types/retry.d.ts +86 -0
  59. package/dist/types/retry.d.ts.map +1 -0
  60. package/dist/types/security.d.ts +120 -0
  61. package/dist/types/security.d.ts.map +1 -0
  62. package/dist/types/telemetry.d.ts +120 -0
  63. package/dist/types/telemetry.d.ts.map +1 -0
  64. package/dist/types/transform.d.ts +184 -0
  65. package/dist/types/transform.d.ts.map +1 -0
  66. package/dist/types/validation.d.ts +356 -0
  67. package/dist/types/validation.d.ts.map +1 -0
  68. package/package.json +203 -0
  69. package/readme.md +103 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Transform Middleware
3
+ *
4
+ * Transforms requests and responses with custom functions.
5
+ *
6
+ * @module
7
+ */
8
+ import type { Middleware } from 'ai.matey.types';
9
+ import type { IRChatRequest, IRChatResponse, IRMessage } from 'ai.matey.types';
10
+ /**
11
+ * Request transformer function.
12
+ */
13
+ export type RequestTransformer = (request: IRChatRequest) => IRChatRequest | Promise<IRChatRequest>;
14
+ /**
15
+ * Response transformer function.
16
+ */
17
+ export type ResponseTransformer = (response: IRChatResponse) => IRChatResponse | Promise<IRChatResponse>;
18
+ /**
19
+ * Message transformer function.
20
+ */
21
+ export type MessageTransformer = (message: IRMessage) => IRMessage | Promise<IRMessage>;
22
+ /**
23
+ * Configuration for transform middleware.
24
+ */
25
+ export interface TransformConfig {
26
+ /**
27
+ * Transform function to apply to requests.
28
+ */
29
+ transformRequest?: RequestTransformer;
30
+ /**
31
+ * Transform function to apply to responses.
32
+ */
33
+ transformResponse?: ResponseTransformer;
34
+ /**
35
+ * Transform function to apply to each message in request.
36
+ */
37
+ transformMessages?: MessageTransformer;
38
+ }
39
+ /**
40
+ * Create transform middleware.
41
+ *
42
+ * Applies custom transformations to requests and responses.
43
+ *
44
+ * @param config Transform configuration
45
+ * @returns Transform middleware
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Add system message prefix
50
+ * const transform = createTransformMiddleware({
51
+ * transformRequest: (request) => ({
52
+ * ...request,
53
+ * messages: [
54
+ * { role: 'system', content: 'You are helpful.' },
55
+ * ...request.messages
56
+ * ]
57
+ * })
58
+ * });
59
+ *
60
+ * bridge.use(transform);
61
+ * ```
62
+ */
63
+ export declare function createTransformMiddleware(config?: TransformConfig): Middleware;
64
+ /**
65
+ * Create a prompt rewriting transformer.
66
+ *
67
+ * @param rewriter Function to rewrite prompt text
68
+ * @returns Message transformer
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const transformer = createPromptRewriter((text) => {
73
+ * return text.replace(/foo/g, 'bar');
74
+ * });
75
+ * ```
76
+ */
77
+ export declare function createPromptRewriter(rewriter: (text: string) => string | Promise<string>): MessageTransformer;
78
+ /**
79
+ * Create a parameter modifier transformer.
80
+ *
81
+ * @param modifier Function to modify parameters
82
+ * @returns Request transformer
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const transformer = createParameterModifier((params) => ({
87
+ * ...params,
88
+ * temperature: Math.min(params.temperature ?? 0.7, 0.9)
89
+ * }));
90
+ * ```
91
+ */
92
+ export declare function createParameterModifier(modifier: (params: IRChatRequest['parameters']) => IRChatRequest['parameters'] | Promise<IRChatRequest['parameters']>): RequestTransformer;
93
+ /**
94
+ * Create a response filter transformer.
95
+ *
96
+ * @param filter Function to filter/modify response
97
+ * @returns Response transformer
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const transformer = createResponseFilter((response) => {
102
+ * // Remove custom metadata
103
+ * const { custom, ...metadata } = response.metadata;
104
+ * return { ...response, metadata };
105
+ * });
106
+ * ```
107
+ */
108
+ export declare function createResponseFilter(filter: (response: IRChatResponse) => IRChatResponse | Promise<IRChatResponse>): ResponseTransformer;
109
+ /**
110
+ * Create a system message injector.
111
+ *
112
+ * @param systemMessage System message to inject
113
+ * @param position Where to inject ('start' or 'end')
114
+ * @returns Request transformer
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const transformer = createSystemMessageInjector(
119
+ * 'You are a helpful assistant.',
120
+ * 'start'
121
+ * );
122
+ * ```
123
+ */
124
+ export declare function createSystemMessageInjector(systemMessage: string, position?: 'start' | 'end'): RequestTransformer;
125
+ /**
126
+ * Create a message filter transformer.
127
+ *
128
+ * @param predicate Function to determine if message should be kept
129
+ * @returns Request transformer
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Remove all system messages
134
+ * const transformer = createMessageFilter(
135
+ * (msg) => msg.role !== 'system'
136
+ * );
137
+ * ```
138
+ */
139
+ export declare function createMessageFilter(predicate: (message: IRMessage) => boolean | Promise<boolean>): RequestTransformer;
140
+ /**
141
+ * Create a content sanitizer transformer.
142
+ *
143
+ * @param sanitizer Function to sanitize message content
144
+ * @returns Message transformer
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Remove sensitive data
149
+ * const transformer = createContentSanitizer((text) => {
150
+ * return text.replace(/\b\d{3}-\d{2}-\d{4}\b/g, '[SSN]');
151
+ * });
152
+ * ```
153
+ */
154
+ export declare function createContentSanitizer(sanitizer: (text: string) => string | Promise<string>): MessageTransformer;
155
+ /**
156
+ * Compose multiple request transformers.
157
+ *
158
+ * @param transformers Request transformers to compose
159
+ * @returns Composed request transformer
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const composed = composeRequestTransformers(
164
+ * createSystemMessageInjector('Be helpful'),
165
+ * createParameterModifier(params => ({ ...params, temperature: 0.7 }))
166
+ * );
167
+ * ```
168
+ */
169
+ export declare function composeRequestTransformers(...transformers: RequestTransformer[]): RequestTransformer;
170
+ /**
171
+ * Compose multiple response transformers.
172
+ *
173
+ * @param transformers Response transformers to compose
174
+ * @returns Composed response transformer
175
+ */
176
+ export declare function composeResponseTransformers(...transformers: ResponseTransformer[]): ResponseTransformer;
177
+ /**
178
+ * Compose multiple message transformers.
179
+ *
180
+ * @param transformers Message transformers to compose
181
+ * @returns Composed message transformer
182
+ */
183
+ export declare function composeMessageTransformers(...transformers: MessageTransformer[]): MessageTransformer;
184
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAqC,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM/E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEpG;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,QAAQ,EAAE,cAAc,KACrB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,SAAS,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IAEtC;;OAEG;IACH,iBAAiB,CAAC,EAAE,mBAAmB,CAAC;IAExC;;OAEG;IACH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AgB,2BAA2B,CACzC,GAAG,YAAY,EAAE,mBAAmB,EAAE,GACrC,mBAAmB,CAUrB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,YAAY,EAAE,kBAAkB,EAAE,GACpC,kBAAkB,CAUpB"}
@@ -0,0 +1,356 @@
1
+ /**
2
+ * Input Validation & Sanitization Middleware
3
+ *
4
+ * Validates and sanitizes requests to prevent security issues and ensure data quality.
5
+ *
6
+ * ## Separation of Concerns
7
+ *
8
+ * This middleware focuses on **SECURITY validation**:
9
+ * - PII detection and redaction
10
+ * - Prompt injection prevention
11
+ * - Content moderation
12
+ * - Message length/token limits
13
+ * - Sanitization
14
+ *
15
+ * For **IR format validation** (structural correctness), use ai.matey.utils/validation.ts:
16
+ * - Message structure and content validation
17
+ * - Parameter type and range validation
18
+ * - Request format validation
19
+ *
20
+ * @module
21
+ */
22
+ import type { Middleware } from 'ai.matey.types';
23
+ import type { IRChatRequest } from 'ai.matey.types';
24
+ import { ValidationError } from 'ai.matey.errors';
25
+ /**
26
+ * Validation result
27
+ */
28
+ export interface ValidationResult {
29
+ /**
30
+ * Whether validation passed
31
+ */
32
+ valid: boolean;
33
+ /**
34
+ * Validation errors
35
+ */
36
+ errors: ValidationError[];
37
+ /**
38
+ * Warnings (non-blocking)
39
+ */
40
+ warnings: string[];
41
+ }
42
+ /**
43
+ * PII detection result
44
+ */
45
+ export interface PIIDetectionResult {
46
+ /**
47
+ * Whether PII was detected
48
+ */
49
+ detected: boolean;
50
+ /**
51
+ * Types of PII found
52
+ */
53
+ types: string[];
54
+ /**
55
+ * Matched patterns (for debugging)
56
+ */
57
+ matches: Array<{
58
+ type: string;
59
+ value: string;
60
+ }>;
61
+ }
62
+ /**
63
+ * Content moderation result
64
+ */
65
+ export interface ModerationResult {
66
+ /**
67
+ * Whether content is flagged
68
+ */
69
+ flagged: boolean;
70
+ /**
71
+ * Categories flagged
72
+ */
73
+ categories: string[];
74
+ /**
75
+ * Confidence scores
76
+ */
77
+ scores?: Record<string, number>;
78
+ }
79
+ /**
80
+ * Validation configuration
81
+ */
82
+ export interface ValidationConfig {
83
+ /**
84
+ * Maximum number of messages in conversation
85
+ * @default undefined (no limit)
86
+ */
87
+ maxMessages?: number;
88
+ /**
89
+ * Maximum total tokens across all messages
90
+ * @default undefined (no limit)
91
+ */
92
+ maxTotalTokens?: number;
93
+ /**
94
+ * Maximum tokens per message
95
+ * @default undefined (no limit)
96
+ */
97
+ maxTokensPerMessage?: number;
98
+ /**
99
+ * Maximum message content length (characters)
100
+ * @default undefined (no limit)
101
+ */
102
+ maxMessageLength?: number;
103
+ /**
104
+ * Maximum system message length (characters)
105
+ * @default undefined (no limit)
106
+ */
107
+ maxSystemLength?: number;
108
+ /**
109
+ * Allowed message roles
110
+ * @default ['user', 'assistant', 'system']
111
+ */
112
+ allowedRoles?: Array<'user' | 'assistant' | 'system'>;
113
+ /**
114
+ * Block requests with empty messages
115
+ * @default true
116
+ */
117
+ blockEmptyMessages?: boolean;
118
+ /**
119
+ * Detect and handle PII (Personally Identifiable Information)
120
+ * @default false
121
+ */
122
+ detectPII?: boolean;
123
+ /**
124
+ * Action when PII is detected
125
+ * @default 'warn'
126
+ */
127
+ piiAction?: 'block' | 'redact' | 'warn' | 'log';
128
+ /**
129
+ * PII patterns to detect (regex patterns)
130
+ */
131
+ piiPatterns?: Record<string, RegExp>;
132
+ /**
133
+ * Custom PII detector function
134
+ */
135
+ piiDetector?: (text: string) => PIIDetectionResult | Promise<PIIDetectionResult>;
136
+ /**
137
+ * Content moderation callback
138
+ * Return true to block, false to allow
139
+ */
140
+ moderationCallback?: (content: string) => ModerationResult | Promise<ModerationResult>;
141
+ /**
142
+ * Block content flagged by moderation
143
+ * @default false
144
+ */
145
+ blockFlaggedContent?: boolean;
146
+ /**
147
+ * Prevent prompt injection attempts
148
+ * @default true
149
+ */
150
+ preventPromptInjection?: boolean;
151
+ /**
152
+ * Prompt injection patterns to detect
153
+ */
154
+ injectionPatterns?: RegExp[];
155
+ /**
156
+ * Sanitize messages before processing
157
+ * @default true
158
+ */
159
+ sanitizeMessages?: boolean;
160
+ /**
161
+ * Custom sanitization function
162
+ */
163
+ sanitizer?: (text: string) => string;
164
+ /**
165
+ * Validate model parameter
166
+ * @default false
167
+ */
168
+ validateModel?: boolean;
169
+ /**
170
+ * Allowed models (if validateModel is true)
171
+ */
172
+ allowedModels?: string[];
173
+ /**
174
+ * Perform IR format validation before security validation
175
+ * Uses ai.matey.utils/validation.ts for structural correctness
176
+ * @default false
177
+ */
178
+ validateIRFormat?: boolean;
179
+ /**
180
+ * Validate temperature parameter using ai.matey.utils
181
+ * @default false
182
+ * @deprecated Use validateIRFormat instead for comprehensive parameter validation
183
+ */
184
+ validateTemperature?: boolean;
185
+ /**
186
+ * Temperature range (only used if validateTemperature is true)
187
+ * @default [0, 2]
188
+ * @deprecated Temperature validation now uses ai.matey.utils range (0-2)
189
+ */
190
+ temperatureRange?: [number, number];
191
+ /**
192
+ * Custom validation function
193
+ * Return errors to block, empty array to allow
194
+ */
195
+ customValidator?: (request: IRChatRequest) => ValidationError[] | Promise<ValidationError[]>;
196
+ /**
197
+ * Throw errors on validation failure
198
+ * @default true
199
+ */
200
+ throwOnError?: boolean;
201
+ /**
202
+ * Log validation warnings
203
+ * @default true
204
+ */
205
+ logWarnings?: boolean;
206
+ }
207
+ /**
208
+ * Default PII patterns
209
+ */
210
+ export declare const DEFAULT_PII_PATTERNS: Record<string, RegExp>;
211
+ /**
212
+ * Default prompt injection patterns
213
+ */
214
+ export declare const DEFAULT_INJECTION_PATTERNS: RegExp[];
215
+ /**
216
+ * Detect PII in text
217
+ */
218
+ export declare function detectPII(text: string, patterns?: Record<string, RegExp>): PIIDetectionResult;
219
+ /**
220
+ * Redact PII from text
221
+ */
222
+ export declare function redactPII(text: string, patterns?: Record<string, RegExp>): string;
223
+ /**
224
+ * Detect prompt injection attempts
225
+ */
226
+ export declare function detectPromptInjection(text: string, patterns?: RegExp[]): boolean;
227
+ /**
228
+ * Sanitize text content
229
+ */
230
+ export declare function sanitizeText(text: string): string;
231
+ /**
232
+ * Validate request
233
+ */
234
+ export declare function validateRequest(request: IRChatRequest, config: ValidationConfig): Promise<ValidationResult>;
235
+ /**
236
+ * Sanitize request
237
+ */
238
+ export declare function sanitizeRequest(request: IRChatRequest, config: ValidationConfig): IRChatRequest;
239
+ /**
240
+ * Create input validation middleware
241
+ *
242
+ * Validates and sanitizes requests to prevent security issues and ensure data quality.
243
+ *
244
+ * @param config - Validation configuration
245
+ * @returns Middleware function
246
+ *
247
+ * @example Basic Usage
248
+ * ```typescript
249
+ * import { createValidationMiddleware } from 'ai.matey';
250
+ *
251
+ * const validation = createValidationMiddleware({
252
+ * maxMessages: 100,
253
+ * maxTotalTokens: 128000,
254
+ * preventPromptInjection: true,
255
+ * });
256
+ *
257
+ * bridge.use(validation);
258
+ * ```
259
+ *
260
+ * @example PII Detection & Redaction
261
+ * ```typescript
262
+ * const validation = createValidationMiddleware({
263
+ * detectPII: true,
264
+ * piiAction: 'redact', // or 'block', 'warn', 'log'
265
+ * piiPatterns: {
266
+ * email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
267
+ * ssn: /\b\d{3}-\d{2}-\d{4}\b/g,
268
+ * },
269
+ * });
270
+ * ```
271
+ *
272
+ * @example Content Moderation
273
+ * ```typescript
274
+ * const validation = createValidationMiddleware({
275
+ * moderationCallback: async (content) => {
276
+ * // Call external moderation API
277
+ * const result = await moderationAPI.check(content);
278
+ * return {
279
+ * flagged: result.flagged,
280
+ * categories: result.categories,
281
+ * scores: result.scores,
282
+ * };
283
+ * },
284
+ * blockFlaggedContent: true,
285
+ * });
286
+ * ```
287
+ *
288
+ * @example Custom Validation
289
+ * ```typescript
290
+ * const validation = createValidationMiddleware({
291
+ * customValidator: async (request) => {
292
+ * const errors: ValidationError[] = [];
293
+ *
294
+ * // Custom business logic
295
+ * if (request.messages.some(m => m.content.includes('forbidden'))) {
296
+ * errors.push(new ValidationError(
297
+ * 'Forbidden content detected',
298
+ * 'messages',
299
+ * 'forbidden'
300
+ * ));
301
+ * }
302
+ *
303
+ * return errors;
304
+ * },
305
+ * });
306
+ * ```
307
+ *
308
+ * @example Production Configuration
309
+ * ```typescript
310
+ * const validation = createValidationMiddleware({
311
+ * maxMessages: 100,
312
+ * maxTotalTokens: 128000,
313
+ * maxTokensPerMessage: 32000,
314
+ * maxMessageLength: 100000,
315
+ * blockEmptyMessages: true,
316
+ * detectPII: true,
317
+ * piiAction: 'redact',
318
+ * preventPromptInjection: true,
319
+ * sanitizeMessages: true,
320
+ * validateModel: true,
321
+ * allowedModels: ['gpt-4', 'claude-3-sonnet', 'gemini-pro'],
322
+ * validateTemperature: true,
323
+ * temperatureRange: [0, 2],
324
+ * throwOnError: true,
325
+ * logWarnings: true,
326
+ * });
327
+ * ```
328
+ */
329
+ export declare function createValidationMiddleware(config?: ValidationConfig): Middleware;
330
+ /**
331
+ * Create production-ready validation middleware with strict settings
332
+ *
333
+ * @returns Middleware with production validation settings
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * import { createProductionValidationMiddleware } from 'ai.matey';
338
+ *
339
+ * bridge.use(createProductionValidationMiddleware());
340
+ * ```
341
+ */
342
+ export declare function createProductionValidationMiddleware(): Middleware;
343
+ /**
344
+ * Create development-friendly validation middleware with relaxed settings
345
+ *
346
+ * @returns Middleware with development validation settings
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * import { createDevelopmentValidationMiddleware } from 'ai.matey';
351
+ *
352
+ * bridge.use(createDevelopmentValidationMiddleware());
353
+ * ```
354
+ */
355
+ export declare function createDevelopmentValidationMiddleware(): Middleware;
356
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM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