@orbytautomation/engine 0.2.4 → 0.3.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 (57) hide show
  1. package/README.md +1 -1
  2. package/dist/errors/ErrorCodes.d.ts +205 -6
  3. package/dist/errors/ErrorCodes.d.ts.map +1 -1
  4. package/dist/errors/ErrorCodes.js +398 -5
  5. package/dist/errors/ErrorCodes.js.map +1 -1
  6. package/dist/errors/ErrorDebugger.d.ts +98 -0
  7. package/dist/errors/ErrorDebugger.d.ts.map +1 -0
  8. package/dist/errors/ErrorDebugger.js +283 -0
  9. package/dist/errors/ErrorDebugger.js.map +1 -0
  10. package/dist/errors/ErrorDetector.d.ts +148 -0
  11. package/dist/errors/ErrorDetector.d.ts.map +1 -0
  12. package/dist/errors/ErrorDetector.js +358 -0
  13. package/dist/errors/ErrorDetector.js.map +1 -0
  14. package/dist/errors/ErrorFormatter.d.ts +92 -3
  15. package/dist/errors/ErrorFormatter.d.ts.map +1 -1
  16. package/dist/errors/ErrorFormatter.js +220 -4
  17. package/dist/errors/ErrorFormatter.js.map +1 -1
  18. package/dist/errors/ErrorHandler.d.ts +259 -0
  19. package/dist/errors/ErrorHandler.d.ts.map +1 -0
  20. package/dist/errors/ErrorHandler.js +378 -0
  21. package/dist/errors/ErrorHandler.js.map +1 -0
  22. package/dist/errors/FieldRegistry.d.ts +39 -0
  23. package/dist/errors/FieldRegistry.d.ts.map +1 -1
  24. package/dist/errors/FieldRegistry.js +172 -74
  25. package/dist/errors/FieldRegistry.js.map +1 -1
  26. package/dist/errors/OrbytError.d.ts +85 -3
  27. package/dist/errors/OrbytError.d.ts.map +1 -1
  28. package/dist/errors/OrbytError.js +151 -4
  29. package/dist/errors/OrbytError.js.map +1 -1
  30. package/dist/errors/SchedulerError.d.ts +93 -1
  31. package/dist/errors/SchedulerError.d.ts.map +1 -1
  32. package/dist/errors/SchedulerError.js +145 -1
  33. package/dist/errors/SchedulerError.js.map +1 -1
  34. package/dist/errors/SecurityErrors.d.ts +94 -12
  35. package/dist/errors/SecurityErrors.d.ts.map +1 -1
  36. package/dist/errors/SecurityErrors.js +162 -18
  37. package/dist/errors/SecurityErrors.js.map +1 -1
  38. package/dist/errors/StepError.d.ts +111 -1
  39. package/dist/errors/StepError.d.ts.map +1 -1
  40. package/dist/errors/StepError.js +182 -1
  41. package/dist/errors/StepError.js.map +1 -1
  42. package/dist/errors/WorkflowError.d.ts +139 -2
  43. package/dist/errors/WorkflowError.d.ts.map +1 -1
  44. package/dist/errors/WorkflowError.js +264 -22
  45. package/dist/errors/WorkflowError.js.map +1 -1
  46. package/dist/errors/index.d.ts +5 -1
  47. package/dist/errors/index.d.ts.map +1 -1
  48. package/dist/errors/index.js +7 -4
  49. package/dist/errors/index.js.map +1 -1
  50. package/dist/loader/WorkflowLoader.d.ts +83 -21
  51. package/dist/loader/WorkflowLoader.d.ts.map +1 -1
  52. package/dist/loader/WorkflowLoader.js +169 -55
  53. package/dist/loader/WorkflowLoader.js.map +1 -1
  54. package/dist/parser/SchemaValidator.d.ts.map +1 -1
  55. package/dist/parser/SchemaValidator.js +2 -1
  56. package/dist/parser/SchemaValidator.js.map +1 -1
  57. package/package.json +1 -1
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Error Debugger (Smart Fix Suggestions)
3
+ *
4
+ * Analyzes errors and provides actionable fix suggestions.
5
+ * Makes debugging easy by suggesting concrete solutions.
6
+ *
7
+ * PHILOSOPHY:
8
+ * ==========
9
+ * Instead of just showing errors, guide users to fix them.
10
+ * Provide step-by-step solutions based on error context.
11
+ *
12
+ * USAGE:
13
+ * ======
14
+ * ```typescript
15
+ * // Get debug info for an error
16
+ * const debug = ErrorDebugger.analyze(error);
17
+ * console.log(debug.explanation);
18
+ * console.log(debug.fixSteps);
19
+ *
20
+ * // Get formatted debug output
21
+ * const output = ErrorDebugger.format(error);
22
+ * console.error(output);
23
+ * ```
24
+ *
25
+ * @module errors/debugger
26
+ */
27
+ import { OrbytErrorCode } from './ErrorCodes.js';
28
+ /**
29
+ * Error Debugger
30
+ *
31
+ * Smart system that analyzes errors and provides fix suggestions.
32
+ */
33
+ export class ErrorDebugger {
34
+ /**
35
+ * Analyze error and generate debug information
36
+ *
37
+ * @param error - OrbytError to analyze
38
+ * @returns Debug information with fix suggestions
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const debug = ErrorDebugger.analyze(error);
43
+ * console.log(debug.explanation);
44
+ * debug.fixSteps.forEach((step, i) => {
45
+ * console.log(`${i + 1}. ${step}`);
46
+ * });
47
+ * ```
48
+ */
49
+ static analyze(error) {
50
+ // Get base information from error code
51
+ const baseInfo = this.getBaseDebugInfo(error.code);
52
+ // Enhance with context-specific information
53
+ const contextInfo = this.analyzeContext(error);
54
+ return {
55
+ ...baseInfo,
56
+ ...contextInfo,
57
+ // Override with more specific information if available
58
+ cause: contextInfo.cause || baseInfo.cause,
59
+ fixSteps: (contextInfo.fixSteps && contextInfo.fixSteps.length > 0) ? contextInfo.fixSteps : baseInfo.fixSteps,
60
+ };
61
+ }
62
+ /**
63
+ * Format debug information for display
64
+ *
65
+ * @param error - Error to format
66
+ * @param useColors - Whether to use ANSI colors (default: true)
67
+ * @returns Formatted debug output
68
+ */
69
+ static format(error, useColors = true) {
70
+ const debug = this.analyze(error);
71
+ const lines = [];
72
+ // Color codes
73
+ const c = useColors ? {
74
+ reset: '\x1b[0m',
75
+ bold: '\x1b[1m',
76
+ dim: '\x1b[2m',
77
+ blue: '\x1b[34m',
78
+ cyan: '\x1b[36m',
79
+ yellow: '\x1b[33m',
80
+ green: '\x1b[32m',
81
+ red: '\x1b[31m',
82
+ } : {
83
+ reset: '', bold: '', dim: '', blue: '', cyan: '', yellow: '', green: '', red: '',
84
+ };
85
+ // Header
86
+ lines.push(`${c.bold}${c.blue}━━━━ DEBUG INFO ━━━━${c.reset}`);
87
+ lines.push('');
88
+ // Explanation
89
+ lines.push(`${c.bold}What went wrong:${c.reset}`);
90
+ lines.push(debug.explanation);
91
+ lines.push('');
92
+ // Cause
93
+ lines.push(`${c.bold}Why it happened:${c.reset}`);
94
+ lines.push(debug.cause);
95
+ lines.push('');
96
+ // Fix steps
97
+ lines.push(`${c.bold}${c.green}How to fix:${c.reset}`);
98
+ debug.fixSteps.forEach((step, i) => {
99
+ lines.push(`${c.cyan}${i + 1}.${c.reset} ${step}`);
100
+ });
101
+ // Common mistakes
102
+ if (debug.commonMistakes && debug.commonMistakes.length > 0) {
103
+ lines.push('');
104
+ lines.push(`${c.bold}${c.yellow}Common mistakes:${c.reset}`);
105
+ debug.commonMistakes.forEach(mistake => {
106
+ lines.push(`${c.dim}•${c.reset} ${mistake}`);
107
+ });
108
+ }
109
+ // Example
110
+ if (debug.example) {
111
+ lines.push('');
112
+ lines.push(`${c.bold}Example:${c.reset}`);
113
+ lines.push(`${c.dim}${debug.example.description}${c.reset}`);
114
+ lines.push('');
115
+ lines.push(c.dim + '```' + c.reset);
116
+ lines.push(debug.example.code);
117
+ lines.push(c.dim + '```' + c.reset);
118
+ }
119
+ // Time estimate
120
+ if (debug.estimatedFixTime) {
121
+ lines.push('');
122
+ lines.push(`${c.dim}⏱ Estimated fix time: ${debug.estimatedFixTime}${c.reset}`);
123
+ }
124
+ return lines.join('\n');
125
+ }
126
+ // ==================== PRIVATE METHODS ====================
127
+ /**
128
+ * Get base debug information for error code
129
+ */
130
+ static getBaseDebugInfo(code) {
131
+ // Map of error codes to debug information
132
+ const debugMap = {
133
+ [OrbytErrorCode.SCHEMA_UNKNOWN_FIELD]: {
134
+ explanation: 'Your workflow contains a field that is not recognized by Orbyt.',
135
+ cause: 'This usually happens due to a typo in the field name or using a field that doesn\'t exist in the schema.',
136
+ fixSteps: [
137
+ 'Check the spelling of the field name',
138
+ 'Refer to Orbyt documentation for valid field names',
139
+ 'Remove the field if it\'s not needed',
140
+ ],
141
+ commonMistakes: [
142
+ 'Typos in field names (e.g., "varion" instead of "version")',
143
+ 'Using deprecated field names',
144
+ 'Copy-pasting from old workflow versions',
145
+ ],
146
+ },
147
+ [OrbytErrorCode.SCHEMA_RESERVED_FIELD]: {
148
+ explanation: 'You tried to use a field name that is reserved by Orbyt engine.',
149
+ cause: 'Reserved fields are used internally for billing, execution tracking, and security. Users cannot set these.',
150
+ fixSteps: [
151
+ 'Rename the field to something else',
152
+ 'Avoid using fields starting with "_" or "__"',
153
+ 'Avoid fields like "executionId", "billingMode", "userId"',
154
+ ],
155
+ commonMistakes: [
156
+ 'Using underscore-prefixed fields (_internal, __context)',
157
+ 'Trying to set billing fields manually',
158
+ 'Using engine-managed field names',
159
+ ],
160
+ docsLinks: ['https://docs.orbyt.dev/reserved-fields'],
161
+ },
162
+ [OrbytErrorCode.SCHEMA_MISSING_FIELD]: {
163
+ explanation: 'A required field is missing from your workflow definition.',
164
+ cause: 'Orbyt requires certain fields to be present for the workflow to be valid.',
165
+ fixSteps: [
166
+ 'Add the missing required field to your workflow',
167
+ 'Check field name spelling',
168
+ 'Refer to schema documentation for required fields',
169
+ ],
170
+ estimatedFixTime: '1-2 minutes',
171
+ },
172
+ [OrbytErrorCode.VALIDATION_DUPLICATE_ID]: {
173
+ explanation: 'Multiple steps in your workflow have the same ID.',
174
+ cause: 'Each step must have a unique identifier so Orbyt can track execution and dependencies.',
175
+ fixSteps: [
176
+ 'Find all steps with the duplicate ID',
177
+ 'Rename one (or both) to make IDs unique',
178
+ 'Use descriptive, meaningful IDs for clarity',
179
+ ],
180
+ commonMistakes: [
181
+ 'Copy-pasting steps without changing IDs',
182
+ 'Using generic IDs like "step1", "step2"',
183
+ ],
184
+ estimatedFixTime: '1 minute',
185
+ },
186
+ [OrbytErrorCode.VALIDATION_CIRCULAR_DEPENDENCY]: {
187
+ explanation: 'Your workflow has steps that depend on each other in a circle.',
188
+ cause: 'Step A depends on Step B, which depends on Step C, which depends on Step A. This creates an infinite loop.',
189
+ fixSteps: [
190
+ 'Review the dependency chain shown in the error',
191
+ 'Identify which dependency can be removed or reordered',
192
+ 'Break the circle by removing one dependency',
193
+ ],
194
+ commonMistakes: [
195
+ 'Not visualizing the dependency graph',
196
+ 'Adding dependencies without checking existing ones',
197
+ ],
198
+ urgent: true,
199
+ estimatedFixTime: '5-10 minutes',
200
+ },
201
+ [OrbytErrorCode.EXECUTION_TIMEOUT]: {
202
+ explanation: 'A step took too long to execute and was terminated.',
203
+ cause: 'The step exceeded its configured timeout limit.',
204
+ fixSteps: [
205
+ 'Increase the timeout value in step configuration',
206
+ 'Optimize the step\'s logic to run faster',
207
+ 'Check if the step is stuck in an infinite loop',
208
+ 'Verify external services are responding',
209
+ ],
210
+ commonMistakes: [
211
+ 'Setting timeout too low for long-running operations',
212
+ 'Not handling network delays',
213
+ 'Infinite loops in custom code',
214
+ ],
215
+ urgent: true,
216
+ estimatedFixTime: '10-30 minutes',
217
+ },
218
+ };
219
+ const info = debugMap[code];
220
+ if (info) {
221
+ return {
222
+ explanation: info.explanation || 'An error occurred in your workflow.',
223
+ cause: info.cause || 'The exact cause depends on the specific error code and context.',
224
+ fixSteps: info.fixSteps || [],
225
+ commonMistakes: info.commonMistakes,
226
+ docsLinks: info.docsLinks,
227
+ example: info.example,
228
+ urgent: info.urgent ?? false,
229
+ estimatedFixTime: info.estimatedFixTime,
230
+ };
231
+ }
232
+ // Default debug info for unknown codes
233
+ return {
234
+ explanation: 'An error occurred in your workflow.',
235
+ cause: 'The exact cause depends on the specific error code and context.',
236
+ fixSteps: [
237
+ 'Review the error message carefully',
238
+ 'Check the path/location mentioned in the error',
239
+ 'Refer to Orbyt documentation',
240
+ 'Contact support if issue persists',
241
+ ],
242
+ urgent: false,
243
+ };
244
+ }
245
+ /**
246
+ * Analyze error context for more specific information
247
+ */
248
+ static analyzeContext(error) {
249
+ const fixSteps = [];
250
+ // Add location-specific fix steps
251
+ if (error.path) {
252
+ fixSteps.push(`Look at: ${error.path}`);
253
+ }
254
+ // Add context-specific information
255
+ if (error.diagnostic.context) {
256
+ const ctx = error.diagnostic.context;
257
+ // For unknown field errors, add suggestion if available
258
+ if (ctx.suggestion) {
259
+ fixSteps.push(`Did you mean: "${ctx.suggestion}"?`);
260
+ }
261
+ // For enum errors, show valid values
262
+ if (ctx.validValues && Array.isArray(ctx.validValues)) {
263
+ fixSteps.push(`Use one of: ${ctx.validValues.join(', ')}`);
264
+ }
265
+ // For type errors, show expected type
266
+ if (ctx.expected) {
267
+ fixSteps.push(`Change type to: ${ctx.expected}`);
268
+ }
269
+ }
270
+ return { fixSteps };
271
+ }
272
+ /**
273
+ * Quick debug - one-line summary
274
+ *
275
+ * @param error - Error to summarize
276
+ * @returns One-line debug summary
277
+ */
278
+ static quickDebug(error) {
279
+ const debug = this.analyze(error);
280
+ return `💡 ${debug.fixSteps[0] || debug.cause}`;
281
+ }
282
+ }
283
+ //# sourceMappingURL=ErrorDebugger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorDebugger.js","sourceRoot":"","sources":["../../src/errors/ErrorDebugger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkCjD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,CAAC,KAAiB;QAC9B,uCAAuC;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEnD,4CAA4C;QAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAE/C,OAAO;YACL,GAAG,QAAQ;YACX,GAAG,WAAW;YACd,uDAAuD;YACvD,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK;YAC1C,QAAQ,EAAE,CAAC,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,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AC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACtD,QAAQ,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC7D,CAAC;YAED,sCAAsC;YACtC,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;gBACjB,QAAQ,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,KAAiB;QACjC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Error Detector (Smart Error Classification)
3
+ *
4
+ * Automatically detects error types and assigns correct error codes.
5
+ * Makes the engine smart enough to classify errors without manual coding.
6
+ * Also enriches errors with debug information for developers.
7
+ *
8
+ * PHILOSOPHY:
9
+ * ==========
10
+ * Instead of manually throwing specific error codes everywhere,
11
+ * the detector analyzes the error context and assigns the right code.
12
+ * Debug information is automatically attached at detection time.
13
+ *
14
+ * USAGE:
15
+ * ======
16
+ * ```typescript
17
+ * // Instead of manual classification:
18
+ * if (field === 'version') {
19
+ * throw SchemaError.missingField('version', 'workflow');
20
+ * }
21
+ *
22
+ * // Let detector classify automatically:
23
+ * const error = ErrorDetector.detect({
24
+ * type: 'missing_field',
25
+ * field: 'version',
26
+ * location: 'workflow'
27
+ * });
28
+ * throw error; // Already has debug info attached!
29
+ * ```
30
+ *
31
+ * @module errors/detector
32
+ */
33
+ import { OrbytError } from './OrbytError.js';
34
+ /**
35
+ * Error context for detection
36
+ * Provides information about what went wrong
37
+ */
38
+ export interface ErrorContext {
39
+ /** Type of error scenario */
40
+ type: ErrorScenario;
41
+ /** Field name (if applicable) */
42
+ field?: string;
43
+ /** Location in workflow where error occurred */
44
+ location?: string;
45
+ /** Expected value/type */
46
+ expected?: string;
47
+ /** Actual value/type received */
48
+ actual?: string;
49
+ /** Related data for context */
50
+ data?: Record<string, any>;
51
+ /** Raw error message (if from exception) */
52
+ rawMessage?: string;
53
+ /** Stack trace (for internal errors) */
54
+ stack?: string;
55
+ }
56
+ /**
57
+ * Error scenarios that detector can identify
58
+ */
59
+ export type ErrorScenario = 'unknown_field' | 'reserved_field' | 'invalid_type' | 'missing_field' | 'invalid_enum' | 'parse_error' | 'invalid_adapter' | 'duplicate_id' | 'unknown_step' | 'circular_dependency' | 'forward_reference' | 'empty_workflow' | 'missing_input' | 'invalid_condition' | 'invalid_variable' | 'step_not_found' | 'step_timeout' | 'step_failed' | 'step_dependency_failed' | 'step_invalid_config' | 'reserved_field_override' | 'reserved_annotation' | 'permission_denied' | 'unknown';
60
+ /**
61
+ * Error Detector
62
+ *
63
+ * Smart system that analyzes error context and produces correct OrbytError.
64
+ */
65
+ export declare class ErrorDetector {
66
+ /**
67
+ * Detect and create appropriate error from context
68
+ *
69
+ * @param context - Error context with information about what went wrong
70
+ * @returns Properly classified OrbytError
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const error = ErrorDetector.detect({
75
+ * type: 'missing_field',
76
+ * field: 'version',
77
+ * location: 'workflow'
78
+ * });
79
+ * ```
80
+ */
81
+ /**
82
+ * Detect error from context and enrich with debug information
83
+ *
84
+ * This is the main entry point for error detection.
85
+ * All detected errors are automatically enriched with debug info.
86
+ *
87
+ * @param context - Error context
88
+ * @returns OrbytError with debug info attached
89
+ */
90
+ static detect(context: ErrorContext): OrbytError;
91
+ /**
92
+ * Detect error from raw exception
93
+ * Analyzes exception and tries to classify it
94
+ *
95
+ * @param error - Raw error/exception
96
+ * @param location - Where the error occurred
97
+ * @returns Classified OrbytError with debug info
98
+ */
99
+ static detectFromException(error: Error, location?: string): OrbytError;
100
+ /**
101
+ * Check if field is reserved by engine
102
+ */
103
+ private static isReservedField;
104
+ /**
105
+ * Check if annotation uses reserved namespace
106
+ */
107
+ private static isReservedAnnotation;
108
+ /**
109
+ * Determine field type for security errors
110
+ */
111
+ private static getFieldType;
112
+ private static handleUnknownField;
113
+ /**
114
+ * Get valid field names based on location in workflow
115
+ */
116
+ private static getValidFieldsForLocation;
117
+ private static handleReservedField;
118
+ private static handleInvalidType;
119
+ private static handleMissingField;
120
+ private static handleInvalidEnum;
121
+ private static handleParseError;
122
+ private static handleInvalidAdapter;
123
+ private static handleDuplicateId;
124
+ private static handleUnknownStep;
125
+ private static handleCircularDependency;
126
+ private static handleForwardReference;
127
+ private static handleMissingInput;
128
+ private static handleInvalidCondition;
129
+ private static handleInvalidVariable;
130
+ private static handleStepTimeout;
131
+ private static handleStepFailed;
132
+ private static handleStepDependencyFailed;
133
+ private static handleStepInvalidConfig;
134
+ private static handlePermissionDenied;
135
+ private static handleUnknown;
136
+ /**
137
+ * Enrich error with debug information
138
+ *
139
+ * This is called automatically after error detection to attach
140
+ * detailed debug info including explanations, fix steps, examples, etc.
141
+ *
142
+ * @param error - Detected OrbytError
143
+ * @returns Same error with debug info attached (for console display)
144
+ * @private
145
+ */
146
+ private static enrichWithDebugInfo;
147
+ }
148
+ //# sourceMappingURL=ErrorDetector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorDetector.d.ts","sourceRoot":"","sources":["../../src/errors/ErrorDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAkB7C;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,6BAA6B;IAC7B,IAAI,EAAE,aAAa,CAAC;IAEpB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,gDAAgD;IAChD,Q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