homebridge 2.0.0-alpha.4 → 2.0.0-alpha.40

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 (89) hide show
  1. package/README.md +1 -1
  2. package/bin/homebridge.js +22 -0
  3. package/config-sample.json +12 -1
  4. package/dist/api.d.ts +226 -0
  5. package/dist/api.d.ts.map +1 -0
  6. package/dist/api.js +166 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/bridgeService.d.ts +125 -0
  9. package/dist/bridgeService.d.ts.map +1 -0
  10. package/dist/bridgeService.js +396 -0
  11. package/dist/bridgeService.js.map +1 -0
  12. package/dist/childBridgeFork.d.ts +38 -0
  13. package/dist/childBridgeFork.d.ts.map +1 -0
  14. package/dist/childBridgeFork.js +241 -2
  15. package/dist/childBridgeFork.js.map +1 -7
  16. package/dist/childBridgeService.d.ts +203 -0
  17. package/dist/childBridgeService.d.ts.map +1 -0
  18. package/dist/childBridgeService.js +451 -0
  19. package/dist/childBridgeService.js.map +1 -0
  20. package/dist/cli.d.ts +3 -0
  21. package/dist/cli.d.ts.map +1 -0
  22. package/dist/cli.js +90 -2
  23. package/dist/cli.js.map +1 -7
  24. package/dist/externalPortService.d.ts +33 -0
  25. package/dist/externalPortService.d.ts.map +1 -0
  26. package/dist/externalPortService.js +59 -0
  27. package/dist/externalPortService.js.map +1 -0
  28. package/dist/index.d.ts +85 -1099
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +20 -2
  31. package/dist/index.js.map +1 -7
  32. package/dist/ipcService.d.ts +30 -0
  33. package/dist/ipcService.d.ts.map +1 -0
  34. package/dist/ipcService.js +49 -0
  35. package/dist/ipcService.js.map +1 -0
  36. package/dist/logger.d.ts +78 -0
  37. package/dist/logger.d.ts.map +1 -0
  38. package/dist/logger.js +138 -0
  39. package/dist/logger.js.map +1 -0
  40. package/dist/matterConfigValidator.d.ts +34 -0
  41. package/dist/matterConfigValidator.d.ts.map +1 -0
  42. package/dist/matterConfigValidator.js +249 -0
  43. package/dist/matterConfigValidator.js.map +1 -0
  44. package/dist/matterService.d.ts +168 -0
  45. package/dist/matterService.d.ts.map +1 -0
  46. package/dist/matterService.js +677 -0
  47. package/dist/matterService.js.map +1 -0
  48. package/dist/matterTypes.d.ts +20 -0
  49. package/dist/matterTypes.d.ts.map +1 -0
  50. package/dist/matterTypes.js +278 -0
  51. package/dist/matterTypes.js.map +1 -0
  52. package/dist/platformAccessory.d.ts +56 -0
  53. package/dist/platformAccessory.d.ts.map +1 -0
  54. package/dist/platformAccessory.js +105 -0
  55. package/dist/platformAccessory.js.map +1 -0
  56. package/dist/plugin.d.ts +30 -0
  57. package/dist/plugin.d.ts.map +1 -0
  58. package/dist/plugin.js +182 -0
  59. package/dist/plugin.js.map +1 -0
  60. package/dist/pluginManager.d.ts +77 -0
  61. package/dist/pluginManager.d.ts.map +1 -0
  62. package/dist/pluginManager.js +375 -0
  63. package/dist/pluginManager.js.map +1 -0
  64. package/dist/server.d.ts +61 -0
  65. package/dist/server.d.ts.map +1 -0
  66. package/dist/server.js +467 -0
  67. package/dist/server.js.map +1 -0
  68. package/dist/storageService.d.ts +13 -0
  69. package/dist/storageService.d.ts.map +1 -0
  70. package/dist/storageService.js +41 -0
  71. package/dist/storageService.js.map +1 -0
  72. package/dist/user.d.ts +13 -0
  73. package/dist/user.d.ts.map +1 -0
  74. package/dist/user.js +29 -0
  75. package/dist/user.js.map +1 -0
  76. package/dist/util/mac.d.ts +5 -0
  77. package/dist/util/mac.d.ts.map +1 -0
  78. package/dist/util/mac.js +14 -0
  79. package/dist/util/mac.js.map +1 -0
  80. package/dist/util/matter-cli.d.ts +3 -0
  81. package/dist/util/matter-cli.d.ts.map +1 -0
  82. package/dist/util/matter-cli.js +211 -0
  83. package/dist/util/matter-cli.js.map +1 -0
  84. package/dist/version.d.ts +3 -0
  85. package/dist/version.d.ts.map +1 -0
  86. package/dist/version.js +16 -0
  87. package/dist/version.js.map +1 -0
  88. package/package.json +31 -34
  89. package/bin/homebridge +0 -19
@@ -0,0 +1,249 @@
1
+ import { Logger } from './logger.js';
2
+ const log = Logger.internal;
3
+ /**
4
+ * Validate Matter configuration for production readiness
5
+ */
6
+ export class MatterConfigValidator {
7
+ /**
8
+ * Validate a Matter configuration object
9
+ */
10
+ static validate(config) {
11
+ const result = {
12
+ isValid: true,
13
+ errors: [],
14
+ warnings: [],
15
+ };
16
+ if (!config.enabled) {
17
+ // No validation needed if Matter is disabled
18
+ return result;
19
+ }
20
+ // Validate required fields
21
+ this.validateRequired(config, result);
22
+ // Validate port configuration
23
+ this.validatePort(config, result);
24
+ // Validate discriminator
25
+ this.validateDiscriminator(config, result);
26
+ // Validate passcode
27
+ this.validatePasscode(config, result);
28
+ // Validate vendor and product IDs
29
+ this.validateVendorProductIds(config, result);
30
+ // Validate device name
31
+ this.validateDeviceName(config, result);
32
+ // Validate timeout values
33
+ this.validateTimeouts(config, result);
34
+ // Check for production readiness
35
+ this.checkProductionReadiness(config, result);
36
+ result.isValid = result.errors.length === 0;
37
+ if (result.warnings.length > 0) {
38
+ log.warn('Matter configuration warnings:');
39
+ result.warnings.forEach(warning => log.warn(` - ${warning}`));
40
+ }
41
+ if (result.errors.length > 0) {
42
+ log.error('Matter configuration errors:');
43
+ result.errors.forEach(error => log.error(` - ${error}`));
44
+ }
45
+ return result;
46
+ }
47
+ static validateRequired(config, result) {
48
+ const requiredFields = ['port', 'discriminator', 'passcode', 'vendorId', 'productId', 'deviceName'];
49
+ for (const field of requiredFields) {
50
+ if (config[field] === undefined || config[field] === null) {
51
+ result.errors.push(`Missing required field: ${field}`);
52
+ }
53
+ }
54
+ }
55
+ static validatePort(config, result) {
56
+ const port = config.port;
57
+ if (port !== undefined) {
58
+ if (!Number.isInteger(port) || port < 1024 || port > 65535) {
59
+ result.errors.push(`Port ${port} is invalid. Must be an integer between 1024-65535.`);
60
+ }
61
+ // Check for common conflicts
62
+ const conflictPorts = [5353, 8080, 8443]; // mDNS, common HTTP ports
63
+ if (conflictPorts.includes(port)) {
64
+ result.warnings.push(`Port ${port} may conflict with other services. Consider using a different port.`);
65
+ }
66
+ }
67
+ }
68
+ static validateDiscriminator(config, result) {
69
+ const discriminator = config.discriminator;
70
+ if (discriminator !== undefined) {
71
+ if (!Number.isInteger(discriminator) || discriminator < 0 || discriminator > 4095) {
72
+ result.errors.push(`Discriminator ${discriminator} is invalid. Must be an integer between 0-4095.`);
73
+ }
74
+ }
75
+ }
76
+ static validatePasscode(config, result) {
77
+ const passcode = config.passcode;
78
+ if (passcode !== undefined) {
79
+ const passcodeStr = passcode.toString();
80
+ // Check length
81
+ if (passcodeStr.length !== 8) {
82
+ result.errors.push(`Passcode ${passcode} is invalid. Must be exactly 8 digits.`);
83
+ return;
84
+ }
85
+ // Check if all digits
86
+ if (!/^\d{8}$/.test(passcodeStr)) {
87
+ result.errors.push(`Passcode ${passcode} is invalid. Must contain only digits.`);
88
+ return;
89
+ }
90
+ // Check for invalid patterns
91
+ const invalidPasscodes = [
92
+ '00000000',
93
+ '11111111',
94
+ '22222222',
95
+ '33333333',
96
+ '44444444',
97
+ '55555555',
98
+ '66666666',
99
+ '77777777',
100
+ '88888888',
101
+ '99999999',
102
+ '12345678',
103
+ '87654321',
104
+ '01234567',
105
+ '76543210',
106
+ ];
107
+ if (invalidPasscodes.includes(passcodeStr)) {
108
+ result.errors.push(`Passcode ${passcode} is not allowed. Use a more secure, non-sequential passcode.`);
109
+ return;
110
+ }
111
+ // Check for repeating patterns
112
+ if (this.hasRepeatingPattern(passcodeStr)) {
113
+ result.warnings.push(`Passcode ${passcode} has repeating patterns. Consider using a more random passcode.`);
114
+ }
115
+ // Check for common weak patterns
116
+ if (this.isWeakPasscode(passcodeStr)) {
117
+ result.errors.push(`Passcode ${passcode} is too weak. Use a more secure passcode.`);
118
+ }
119
+ }
120
+ }
121
+ static validateVendorProductIds(config, result) {
122
+ const vendorId = config.vendorId;
123
+ const productId = config.productId;
124
+ if (vendorId !== undefined) {
125
+ if (!Number.isInteger(vendorId) || vendorId < 0 || vendorId > 0xFFFF) {
126
+ result.errors.push(`Vendor ID ${vendorId} is invalid. Must be an integer between 0-65535.`);
127
+ }
128
+ // Check for test vendor IDs in production
129
+ const testVendorIds = [0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4];
130
+ if (testVendorIds.includes(vendorId)) {
131
+ result.warnings.push(`Using test vendor ID ${vendorId}. This should not be used in production.`);
132
+ }
133
+ }
134
+ if (productId !== undefined) {
135
+ if (!Number.isInteger(productId) || productId < 0 || productId > 0xFFFF) {
136
+ result.errors.push(`Product ID ${productId} is invalid. Must be an integer between 0-65535.`);
137
+ }
138
+ }
139
+ }
140
+ static validateDeviceName(config, result) {
141
+ const deviceName = config.deviceName;
142
+ if (deviceName !== undefined) {
143
+ if (typeof deviceName !== 'string') {
144
+ result.errors.push('Device name must be a string.');
145
+ return;
146
+ }
147
+ if (deviceName.length === 0) {
148
+ result.errors.push('Device name cannot be empty.');
149
+ return;
150
+ }
151
+ if (deviceName.length > 32) {
152
+ result.errors.push(`Device name "${deviceName}" is too long. Must be 32 characters or less.`);
153
+ }
154
+ // Check for invalid characters
155
+ if (!/^[\x20-\x7E]*$/.test(deviceName)) {
156
+ result.errors.push(`Device name "${deviceName}" contains invalid characters. Use only printable ASCII characters.`);
157
+ }
158
+ }
159
+ }
160
+ static validateTimeouts(config, result) {
161
+ const announceInterval = config.announceInterval;
162
+ const commissioningTimeout = config.commissioningTimeout;
163
+ if (announceInterval !== undefined) {
164
+ if (!Number.isInteger(announceInterval) || announceInterval < 1 || announceInterval > 3600) {
165
+ result.errors.push(`Announce interval ${announceInterval} is invalid. Must be between 1-3600 seconds.`);
166
+ }
167
+ }
168
+ if (commissioningTimeout !== undefined) {
169
+ if (!Number.isInteger(commissioningTimeout) || commissioningTimeout < 60 || commissioningTimeout > 7200) {
170
+ result.errors.push(`Commissioning timeout ${commissioningTimeout} is invalid. Must be between 60-7200 seconds.`);
171
+ }
172
+ }
173
+ }
174
+ static checkProductionReadiness(config, result) {
175
+ // Check for default/example values that shouldn't be used in production
176
+ if (config.passcode === 20202021) {
177
+ result.warnings.push('Using default passcode. Change this for production deployment.');
178
+ }
179
+ if (config.discriminator === 3840) {
180
+ result.warnings.push('Using default discriminator. Consider changing this for production deployment.');
181
+ }
182
+ if (config.deviceName === 'Homebridge Matter Bridge') {
183
+ result.warnings.push('Using default device name. Consider customizing for your deployment.');
184
+ }
185
+ // Check storage configuration
186
+ if (!config.storageDir || config.storageDir === './persist') {
187
+ result.warnings.push('Using default storage directory. Ensure this directory is persistent and backed up.');
188
+ }
189
+ // Check debug settings
190
+ if (config.debugEnabled) {
191
+ result.warnings.push('Debug mode is enabled. Disable this in production for better performance.');
192
+ }
193
+ }
194
+ static hasRepeatingPattern(passcode) {
195
+ // Check for simple repeating patterns like "1212" or "123123"
196
+ for (let len = 2; len <= 4; len++) {
197
+ const pattern = passcode.substring(0, len);
198
+ const repeated = pattern.repeat(Math.ceil(8 / len)).substring(0, 8);
199
+ if (passcode === repeated) {
200
+ return true;
201
+ }
202
+ }
203
+ return false;
204
+ }
205
+ static isWeakPasscode(passcode) {
206
+ // Check for ascending/descending sequences
207
+ let ascending = 0;
208
+ let descending = 0;
209
+ for (let i = 1; i < passcode.length; i++) {
210
+ const current = Number.parseInt(passcode[i]);
211
+ const previous = Number.parseInt(passcode[i - 1]);
212
+ if (current === previous + 1) {
213
+ ascending++;
214
+ }
215
+ else if (current === previous - 1) {
216
+ descending++;
217
+ }
218
+ }
219
+ // If more than half the digits follow a pattern, consider it weak
220
+ return ascending >= 4 || descending >= 4;
221
+ }
222
+ /**
223
+ * Generate a secure random passcode
224
+ */
225
+ static generateSecurePasscode() {
226
+ let passcode;
227
+ let attempts = 0;
228
+ const maxAttempts = 100;
229
+ do {
230
+ // Generate 8 random digits, ensuring first digit is not 0
231
+ passcode = (Math.floor(Math.random() * 9) + 1).toString(); // First digit 1-9
232
+ for (let i = 1; i < 8; i++) {
233
+ passcode += Math.floor(Math.random() * 10).toString(); // Remaining digits 0-9
234
+ }
235
+ attempts++;
236
+ if (attempts > maxAttempts) {
237
+ throw new Error('Failed to generate secure passcode after maximum attempts');
238
+ }
239
+ } while (this.isWeakPasscode(passcode) || this.hasRepeatingPattern(passcode));
240
+ return Number.parseInt(passcode);
241
+ }
242
+ /**
243
+ * Generate a random discriminator
244
+ */
245
+ static generateRandomDiscriminator() {
246
+ return Math.floor(Math.random() * 4096);
247
+ }
248
+ }
249
+ //# sourceMappingURL=matterConfigValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matterConfigValidator.js","sourceRoot":"","sources":["../src/matterConfigValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAA;AAQ3B;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAChC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,MAA2B;QACzC,MAAM,MAAM,GAAiC;YAC3C,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACb,CAAA;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,6CAA6C;YAC7C,OAAO,MAAM,CAAA;QACf,CAAC;QAED,2BAA2B;QAC3B,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAErC,8BAA8B;QAC9B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAEjC,yBAAyB;QACzB,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAE1C,oBAAoB;QACpB,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAErC,kCAAkC;QAClC,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAE7C,uBAAuB;QACvB,IAAI,CAAC,kBAAkB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AAC,QAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAC;QAE7E,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,2BAA2B;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IACzC,CAAC;CACF"}
@@ -0,0 +1,168 @@
1
+ import { HomebridgeAPI } from './api.js';
2
+ import { ExternalPortService } from './externalPortService.js';
3
+ import { PlatformAccessory } from './platformAccessory.js';
4
+ import { PluginManager } from './pluginManager.js';
5
+ import { HomebridgeOptions } from './server.js';
6
+ import '@matter/main';
7
+ export interface MatterConfiguration {
8
+ enabled?: boolean;
9
+ port?: number;
10
+ discriminator?: number;
11
+ passcode?: number;
12
+ vendorId?: number;
13
+ productId?: number;
14
+ deviceName?: string;
15
+ deviceType?: number;
16
+ storageDir?: string;
17
+ debugEnabled?: boolean;
18
+ interfaceName?: string;
19
+ announceInterval?: number;
20
+ commissioningTimeout?: number;
21
+ }
22
+ export interface MatterBridgeOptions extends HomebridgeOptions {
23
+ matterConfig?: MatterConfiguration;
24
+ }
25
+ /**
26
+ * Matter service for publishing accessories via Matter protocol
27
+ * This runs alongside the existing HAP bridge service
28
+ */
29
+ export declare class MatterService {
30
+ private matterConfiguration;
31
+ private pluginManager;
32
+ private externalPortService;
33
+ private api;
34
+ private options;
35
+ private matterServer;
36
+ private commissioningServer;
37
+ private storageManager;
38
+ private readonly isEnabled;
39
+ private readonly matterConfig;
40
+ private publishedAccessories;
41
+ private isInitialized;
42
+ private isStarted;
43
+ constructor(matterConfiguration: MatterConfiguration, pluginManager: PluginManager, externalPortService: ExternalPortService, api: HomebridgeAPI, options: HomebridgeOptions);
44
+ /**
45
+ * Validate Matter configuration parameters
46
+ */
47
+ private validateConfiguration;
48
+ /**
49
+ * Initialize the Matter server if enabled
50
+ */
51
+ initialize(): Promise<void>;
52
+ /**
53
+ * Initialize storage for Matter server
54
+ */
55
+ private initializeStorage;
56
+ /**
57
+ * Create the Matter server node
58
+ */
59
+ private createMatterServer;
60
+ /**
61
+ * Setup commissioning server for device pairing
62
+ */
63
+ private setupCommissioningServer;
64
+ /**
65
+ * Generate a unique serial number for the Matter bridge
66
+ */
67
+ private generateSerialNumber;
68
+ /**
69
+ * Generate a unique identifier for the Matter bridge
70
+ */
71
+ private generateUniqueId;
72
+ /**
73
+ * Log commissioning information for users
74
+ */
75
+ private logCommissioningInfo;
76
+ /**
77
+ * Format passcode for manual pairing
78
+ */
79
+ private formatPairingCode;
80
+ /**
81
+ * Start the Matter server
82
+ */
83
+ start(): Promise<void>;
84
+ /**
85
+ * Stop the Matter server
86
+ */
87
+ stop(): Promise<void>;
88
+ /**
89
+ * Clean up resources
90
+ */
91
+ private cleanup;
92
+ /**
93
+ * Publish a platform accessory via Matter protocol
94
+ */
95
+ publishAccessory(accessory: PlatformAccessory): Promise<void>;
96
+ /**
97
+ * Unpublish a platform accessory from Matter protocol
98
+ */
99
+ unpublishAccessory(accessory: PlatformAccessory): Promise<void>;
100
+ /**
101
+ * Convert HAP accessory to Matter device
102
+ * This maps HAP services and characteristics to appropriate Matter clusters and attributes
103
+ */
104
+ private convertToMatterDevice;
105
+ /**
106
+ * Get the primary service from an accessory (excluding utility services)
107
+ */
108
+ private getPrimaryService;
109
+ /**
110
+ * Determine the appropriate Matter device type for a HAP service
111
+ */
112
+ private getMatterDeviceType;
113
+ /**
114
+ * Create a Matter device with the specified type and map characteristics
115
+ */
116
+ private createMatterDevice;
117
+ /**
118
+ * Get placeholder clusters for a device type
119
+ */
120
+ private getPlaceholderClusters;
121
+ /**
122
+ * Map HAP characteristics to Matter cluster attributes
123
+ */
124
+ private mapCharacteristicsToMatter;
125
+ /**
126
+ * Get the Matter cluster name for a HAP characteristic
127
+ */
128
+ private getMatterClusterForCharacteristic;
129
+ /**
130
+ * Get the Matter attribute name for a HAP characteristic
131
+ */
132
+ private getMatterAttributeForCharacteristic;
133
+ /**
134
+ * Get Matter server status
135
+ */
136
+ getStatus(): {
137
+ enabled: boolean;
138
+ running: boolean;
139
+ accessoryCount: number;
140
+ qrCode?: string;
141
+ setupCode?: string;
142
+ };
143
+ /**
144
+ * Get commissioning QR code for setup
145
+ */
146
+ getCommissioningQRCode(): string | null;
147
+ /**
148
+ * Get manual pairing code for setup
149
+ */
150
+ getManualPairingCode(): string | null;
151
+ /**
152
+ * Get list of published accessories
153
+ */
154
+ getPublishedAccessories(): PlatformAccessory[];
155
+ /**
156
+ * Check if an accessory is published via Matter
157
+ */
158
+ isAccessoryPublished(accessory: PlatformAccessory): boolean;
159
+ /**
160
+ * Get Matter configuration (read-only)
161
+ */
162
+ getConfiguration(): Readonly<MatterConfiguration>;
163
+ /**
164
+ * Force restart the Matter server (for configuration changes)
165
+ */
166
+ restart(): Promise<void>;
167
+ }
168
+ //# sourceMappingURL=matterService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matterService.d.ts","sourceRoot":"","sources":["../src/matterService.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,cAAc,CAAA;AAIrB,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,E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