langmart-gateway-type3 3.0.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 (75) hide show
  1. package/.env.example +29 -0
  2. package/README.md +480 -0
  3. package/dist/bash-tools.d.ts +56 -0
  4. package/dist/bash-tools.d.ts.map +1 -0
  5. package/dist/bash-tools.js +188 -0
  6. package/dist/bash-tools.js.map +1 -0
  7. package/dist/core-tools.d.ts +94 -0
  8. package/dist/core-tools.d.ts.map +1 -0
  9. package/dist/core-tools.js +694 -0
  10. package/dist/core-tools.js.map +1 -0
  11. package/dist/debug-utils.d.ts +22 -0
  12. package/dist/debug-utils.d.ts.map +1 -0
  13. package/dist/debug-utils.js +37 -0
  14. package/dist/debug-utils.js.map +1 -0
  15. package/dist/devops-tools.d.ts +147 -0
  16. package/dist/devops-tools.d.ts.map +1 -0
  17. package/dist/devops-tools.js +718 -0
  18. package/dist/devops-tools.js.map +1 -0
  19. package/dist/gateway-config.d.ts +56 -0
  20. package/dist/gateway-config.d.ts.map +1 -0
  21. package/dist/gateway-config.js +198 -0
  22. package/dist/gateway-config.js.map +1 -0
  23. package/dist/gateway-mode.d.ts +58 -0
  24. package/dist/gateway-mode.d.ts.map +1 -0
  25. package/dist/gateway-mode.js +240 -0
  26. package/dist/gateway-mode.js.map +1 -0
  27. package/dist/gateway-server.d.ts +208 -0
  28. package/dist/gateway-server.d.ts.map +1 -0
  29. package/dist/gateway-server.js +1811 -0
  30. package/dist/gateway-server.js.map +1 -0
  31. package/dist/headless-session.d.ts +192 -0
  32. package/dist/headless-session.d.ts.map +1 -0
  33. package/dist/headless-session.js +584 -0
  34. package/dist/headless-session.js.map +1 -0
  35. package/dist/index-server.d.ts +4 -0
  36. package/dist/index-server.d.ts.map +1 -0
  37. package/dist/index-server.js +129 -0
  38. package/dist/index-server.js.map +1 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +101 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/key-vault.d.ts +102 -0
  44. package/dist/key-vault.d.ts.map +1 -0
  45. package/dist/key-vault.js +365 -0
  46. package/dist/key-vault.js.map +1 -0
  47. package/dist/local-vault.d.ts +195 -0
  48. package/dist/local-vault.d.ts.map +1 -0
  49. package/dist/local-vault.js +571 -0
  50. package/dist/local-vault.js.map +1 -0
  51. package/dist/marketplace-tools.d.ts +104 -0
  52. package/dist/marketplace-tools.d.ts.map +1 -0
  53. package/dist/marketplace-tools.js +2846 -0
  54. package/dist/marketplace-tools.js.map +1 -0
  55. package/dist/mcp-manager.d.ts +114 -0
  56. package/dist/mcp-manager.d.ts.map +1 -0
  57. package/dist/mcp-manager.js +338 -0
  58. package/dist/mcp-manager.js.map +1 -0
  59. package/dist/web-tools.d.ts +86 -0
  60. package/dist/web-tools.d.ts.map +1 -0
  61. package/dist/web-tools.js +431 -0
  62. package/dist/web-tools.js.map +1 -0
  63. package/dist/websocket-handler.d.ts +131 -0
  64. package/dist/websocket-handler.d.ts.map +1 -0
  65. package/dist/websocket-handler.js +596 -0
  66. package/dist/websocket-handler.js.map +1 -0
  67. package/dist/welcome-pages.d.ts +6 -0
  68. package/dist/welcome-pages.d.ts.map +1 -0
  69. package/dist/welcome-pages.js +200 -0
  70. package/dist/welcome-pages.js.map +1 -0
  71. package/package.json +168 -0
  72. package/scripts/install-remote.sh +282 -0
  73. package/scripts/start.sh +85 -0
  74. package/scripts/status.sh +79 -0
  75. package/scripts/stop.sh +67 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ // File: gateway-type3/index-server.ts
3
+ // Entry point for Gateway Type 3 Server
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.GatewayMode = exports.LocalVault = exports.Type3GatewayServer = void 0;
6
+ const gateway_server_1 = require("./gateway-server");
7
+ const local_vault_1 = require("./local-vault");
8
+ const gateway_mode_1 = require("./gateway-mode");
9
+ async function main() {
10
+ console.log('[Gateway Type 3] Starting Gateway Type 3 Server');
11
+ console.log('[Gateway Type 3] Environment:', process.env.NODE_ENV || 'development');
12
+ // Step 1: Select gateway mode (interactive or from env)
13
+ let modeConfig;
14
+ try {
15
+ modeConfig = await (0, gateway_mode_1.getGatewayMode)();
16
+ (0, gateway_mode_1.displayModeBanner)(modeConfig);
17
+ }
18
+ catch (error) {
19
+ console.error('[Gateway Type 3] Failed to select gateway mode:', error);
20
+ process.exit(1);
21
+ }
22
+ // Initialize vault to check for stored auth key
23
+ const vault = new local_vault_1.LocalVault({
24
+ vaultPath: process.env.VAULT_PATH,
25
+ masterPassword: process.env.VAULT_PASSWORD
26
+ });
27
+ // Auto-load API key from vault if not in environment
28
+ let apiKey = process.env.GATEWAY_API_KEY || process.env.API_KEY || '';
29
+ if (!apiKey && vault.hasAuthKey()) {
30
+ apiKey = vault.getAuthKey() || '';
31
+ if (apiKey) {
32
+ console.log('[Gateway Type 3] 🔐 Loaded authentication key from vault');
33
+ }
34
+ }
35
+ // Configuration
36
+ const config = {
37
+ port: parseInt(process.env.GATEWAY_PORT || '8083'),
38
+ marketplaceUrl: process.env.MARKETPLACE_URL || 'ws://localhost:8081',
39
+ instanceId: process.env.INSTANCE_ID || 'gw3-local-001',
40
+ apiKey: apiKey,
41
+ vaultPath: process.env.VAULT_PATH,
42
+ vaultPassword: process.env.VAULT_PASSWORD,
43
+ // Mode configuration
44
+ mode: modeConfig.mode,
45
+ enableRemoteLLMSession: modeConfig.enableRemoteLLMSession,
46
+ enableLLMRouting: modeConfig.enableLLMRouting
47
+ };
48
+ // Validate API key
49
+ if (!config.apiKey) {
50
+ console.error('[Gateway Type 3] FATAL: API key is required for gateway authentication');
51
+ console.error('[Gateway Type 3] Please set GATEWAY_API_KEY environment variable or authenticate with CLI:');
52
+ console.error('[Gateway Type 3] npm run cli auth <your-api-key>');
53
+ console.error('[Gateway Type 3] Example: GATEWAY_API_KEY=sk-test-inference-key');
54
+ process.exit(1);
55
+ }
56
+ console.log('[Gateway Type 3] Starting with configuration:', {
57
+ port: config.port,
58
+ marketplaceUrl: config.marketplaceUrl,
59
+ instanceId: config.instanceId,
60
+ hasApiKey: !!config.apiKey,
61
+ mode: modeConfig.modeName,
62
+ enableRemoteLLMSession: config.enableRemoteLLMSession,
63
+ enableLLMRouting: config.enableLLMRouting,
64
+ environment: process.env.NODE_ENV || 'development'
65
+ });
66
+ // Create gateway server
67
+ const gateway = new gateway_server_1.Type3GatewayServer(config);
68
+ // Event handlers
69
+ gateway.on('error', (error) => {
70
+ console.error('[Gateway Type 3] Error:', error.message);
71
+ });
72
+ gateway.on('max_reconnect_exceeded', () => {
73
+ console.error('[Gateway Type 3] Max reconnection attempts exceeded, exiting...');
74
+ process.exit(1);
75
+ });
76
+ // Start the gateway
77
+ console.log('[Gateway Type 3] Connecting to marketplace...');
78
+ try {
79
+ await gateway.start();
80
+ console.log('[Gateway Type 3] Successfully started');
81
+ console.log('[Gateway Type 3] Connected to marketplace at', config.marketplaceUrl);
82
+ // Mode-specific ready messages
83
+ if (config.enableLLMRouting) {
84
+ console.log('[Gateway Type 3] Ready to handle LLM routing requests');
85
+ }
86
+ if (config.enableRemoteLLMSession) {
87
+ console.log('[Gateway Type 3] Ready to handle remote sessions');
88
+ }
89
+ }
90
+ catch (error) {
91
+ console.error('[Gateway Type 3] Failed to start:', error);
92
+ process.exit(1);
93
+ }
94
+ // Handle shutdown signals
95
+ process.on('SIGTERM', async () => {
96
+ console.log('[Gateway Type 3] Received SIGTERM, shutting down gracefully...');
97
+ await gateway.gracefulShutdown();
98
+ setTimeout(() => process.exit(0), 1000);
99
+ });
100
+ process.on('SIGINT', async () => {
101
+ console.log('[Gateway Type 3] Received SIGINT, shutting down gracefully...');
102
+ await gateway.gracefulShutdown();
103
+ setTimeout(() => process.exit(0), 1000);
104
+ });
105
+ // Handle uncaught errors
106
+ process.on('uncaughtException', async (error) => {
107
+ console.error('[Gateway Type 3] Uncaught exception:', error);
108
+ await gateway.gracefulShutdown();
109
+ process.exit(1);
110
+ });
111
+ process.on('unhandledRejection', async (reason) => {
112
+ console.error('[Gateway Type 3] Unhandled rejection:', reason);
113
+ await gateway.gracefulShutdown();
114
+ process.exit(1);
115
+ });
116
+ return gateway;
117
+ }
118
+ // Run main function
119
+ main().catch((error) => {
120
+ console.error('[Gateway Type 3] Fatal error during startup:', error);
121
+ process.exit(1);
122
+ });
123
+ var gateway_server_2 = require("./gateway-server");
124
+ Object.defineProperty(exports, "Type3GatewayServer", { enumerable: true, get: function () { return gateway_server_2.Type3GatewayServer; } });
125
+ var local_vault_2 = require("./local-vault");
126
+ Object.defineProperty(exports, "LocalVault", { enumerable: true, get: function () { return local_vault_2.LocalVault; } });
127
+ var gateway_mode_2 = require("./gateway-mode");
128
+ Object.defineProperty(exports, "GatewayMode", { enumerable: true, get: function () { return gateway_mode_2.GatewayMode; } });
129
+ //# sourceMappingURL=index-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-server.js","sourceRoot":"","sources":["../index-server.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,wCAAwC;;;AAExC,qDAAsD;AACtD,+CAA2C;AAC3C,iDAAsF;AAEtF,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;IAC/D,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC,CAAC;IAEpF,wDAAwD;IACxD,IAAI,UAA6B,CAAC;IAClC,IAAI,CAAC;QACD,UAAU,GAAG,MAAM,IAAA,6BAAc,GAAE,CAAC;QACpC,IAAA,gCAAiB,EAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,gDAAgD;IAChD,MAAM,KAAK,GAAG,IAAI,wBAAU,C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EAAE;QACnD,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,MAAM,CAAC,CAAC;QAC/D,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,oBAAoB;AACpB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;IACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,mDAAsD;AAA7C,oHAAA,kBAAkB,OAAA;AAC3B,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,+CAAgE;AAAvD,2GAAA,WAAW,OAAA"}
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { Type3GatewayClient } from './websocket-handler';
3
+ declare const gateway: Type3GatewayClient;
4
+ export { Type3GatewayClient };
5
+ export default gateway;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAuCzD,QAAA,MAAM,OAAO,oBAAiC,CAAC;AAwE/C,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,eAAe,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // Gateway Type 3 - Seller-Managed Gateway Entry Point
4
+ // This is a pure client that connects to the marketplace via WebSocket
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Type3GatewayClient = void 0;
7
+ const websocket_handler_1 = require("./websocket-handler");
8
+ Object.defineProperty(exports, "Type3GatewayClient", { enumerable: true, get: function () { return websocket_handler_1.Type3GatewayClient; } });
9
+ // Read configuration from environment variables or use defaults
10
+ const config = {
11
+ // Gateway identification
12
+ gatewayId: process.env.GATEWAY3_ID || process.env.GATEWAY_ID || 'gw3-seller-local-001',
13
+ // Authentication
14
+ apiKey: process.env.GATEWAY3_API_KEY || process.env.MARKETPLACE_API_KEY || 'sk-test-001-abcdef123456',
15
+ // Marketplace connection (WebSocket)
16
+ marketplaceUrl: process.env.MARKETPLACE_URL || process.env.MARKETPLACE_WS_URL || 'ws://localhost:8090',
17
+ // Provider API keys (seller's own keys)
18
+ providerKeys: {
19
+ 'openai': process.env.OPENAI_API_KEY || process.env.PROVIDER_OPENAI_KEY || 'sk-mock-seller-openai-key',
20
+ 'anthropic': process.env.ANTHROPIC_API_KEY || process.env.PROVIDER_ANTHROPIC_KEY || 'sk-mock-seller-anthropic-key',
21
+ 'google': process.env.GOOGLE_API_KEY || process.env.PROVIDER_GOOGLE_KEY || 'mock-seller-google-key',
22
+ 'deepseek': process.env.DEEPSEEK_API_KEY || process.env.PROVIDER_DEEPSEEK_KEY || 'sk-mock-seller-deepseek-key'
23
+ }
24
+ };
25
+ // Remove undefined provider keys
26
+ Object.keys(config.providerKeys).forEach(key => {
27
+ if (!config.providerKeys[key] ||
28
+ config.providerKeys[key]?.includes('mock')) {
29
+ console.log(`[Gateway Type 3] Warning: No real API key for ${key}, using mock`);
30
+ }
31
+ });
32
+ // Log startup configuration (hide sensitive API keys)
33
+ console.log('[Gateway Type 3] Starting with configuration:', {
34
+ gatewayId: config.gatewayId,
35
+ marketplaceUrl: config.marketplaceUrl,
36
+ providers: Object.keys(config.providerKeys),
37
+ environment: process.env.NODE_ENV || 'development'
38
+ });
39
+ // Create the gateway client
40
+ const gateway = new websocket_handler_1.Type3GatewayClient(config);
41
+ // Set up event handlers
42
+ gateway.on('connected', () => {
43
+ console.log('[Gateway Type 3] Successfully connected to marketplace');
44
+ console.log('[Gateway Type 3] Ready to handle inference requests');
45
+ });
46
+ gateway.on('disconnected', () => {
47
+ console.log('[Gateway Type 3] Disconnected from marketplace');
48
+ // Will automatically attempt to reconnect
49
+ });
50
+ gateway.on('error', (error) => {
51
+ console.error('[Gateway Type 3] Error:', error.message);
52
+ });
53
+ gateway.on('request', (request) => {
54
+ console.log('[Gateway Type 3] Processing request:', request.request_id);
55
+ });
56
+ gateway.on('request_complete', (requestId, duration) => {
57
+ console.log(`[Gateway Type 3] Request ${requestId} completed in ${duration}ms`);
58
+ });
59
+ // Connect to marketplace
60
+ console.log('[Gateway Type 3] Connecting to marketplace...');
61
+ gateway.connect()
62
+ .then(() => {
63
+ console.log('[Gateway Type 3] Initial connection established');
64
+ console.log('[Gateway Type 3] Waiting for inference requests from marketplace...');
65
+ })
66
+ .catch((error) => {
67
+ console.error('[Gateway Type 3] Failed to connect:', error);
68
+ process.exit(1);
69
+ });
70
+ // Handle shutdown signals gracefully
71
+ process.on('SIGTERM', async () => {
72
+ console.log('[Gateway Type 3] Received SIGTERM, disconnecting...');
73
+ if (gateway.ws) {
74
+ gateway.ws.close();
75
+ }
76
+ setTimeout(() => process.exit(0), 1000); // Give time for cleanup
77
+ });
78
+ process.on('SIGINT', async () => {
79
+ console.log('[Gateway Type 3] Received SIGINT, disconnecting...');
80
+ if (gateway.ws) {
81
+ gateway.ws.close();
82
+ }
83
+ setTimeout(() => process.exit(0), 1000); // Give time for cleanup
84
+ });
85
+ // Handle uncaught errors
86
+ process.on('uncaughtException', (error) => {
87
+ console.error('[Gateway Type 3] Uncaught exception:', error);
88
+ if (gateway.ws) {
89
+ gateway.ws.close();
90
+ }
91
+ process.exit(1);
92
+ });
93
+ process.on('unhandledRejection', (reason, promise) => {
94
+ console.error('[Gateway Type 3] Unhandled rejection at:', promise, 'reason:', reason);
95
+ if (gateway.ws) {
96
+ gateway.ws.close();
97
+ }
98
+ process.exit(1);
99
+ });
100
+ exports.default = gateway;
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sour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CAAC,mBAAmB,EAAE,CAAC,KAAY,EAAE,EAAE;IAC7C,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACb,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAW,EAAE,OAAqB,EAAE,EAAE;IACpE,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACtF,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACb,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAIH,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,102 @@
1
+ export declare class KeyVault {
2
+ private keyMappings;
3
+ private readonly KEY_PATTERNS;
4
+ /**
5
+ * Generate a random key with the same format as the original
6
+ */
7
+ private generateRandomKey;
8
+ /**
9
+ * Detect and redact API keys in text
10
+ * Returns both redacted text and list of detected keys
11
+ */
12
+ redactKeys(text: string): {
13
+ redactedText: string;
14
+ detectedCount: number;
15
+ };
16
+ /**
17
+ * Restore real API keys in text (for LLM responses and tool calls)
18
+ */
19
+ restoreKeys(text: string): {
20
+ restoredText: string;
21
+ restoredCount: number;
22
+ };
23
+ /**
24
+ * Check if text contains any API keys (real or redacted)
25
+ */
26
+ containsKeys(text: string): boolean;
27
+ /**
28
+ * Get statistics about redacted keys
29
+ */
30
+ getStats(): {
31
+ totalKeys: number;
32
+ byProvider: Record<string, number>;
33
+ oldestKey?: {
34
+ provider: string;
35
+ ageMinutes: number;
36
+ };
37
+ newestKey?: {
38
+ provider: string;
39
+ ageMinutes: number;
40
+ };
41
+ averageAge: number;
42
+ };
43
+ /**
44
+ * Get keys older than specified age in minutes
45
+ */
46
+ getOldKeys(maxAgeMinutes: number): Array<{
47
+ provider: string;
48
+ ageMinutes: number;
49
+ lastUsedMinutes: number;
50
+ useCount: number;
51
+ }>;
52
+ /**
53
+ * Clean up keys older than specified age in minutes
54
+ * Returns number of keys removed
55
+ */
56
+ cleanupOldKeys(maxAgeMinutes: number): number;
57
+ /**
58
+ * Clean up keys not used for specified time in minutes
59
+ * Returns number of keys removed
60
+ */
61
+ cleanupUnusedKeys(unusedMinutes: number): number;
62
+ /**
63
+ * Get age of a specific redacted key in minutes
64
+ */
65
+ getKeyAge(redactedKey: string): number | null;
66
+ /**
67
+ * Get detailed info about all stored keys
68
+ */
69
+ getAllKeysInfo(): Array<{
70
+ provider: string;
71
+ redactedPrefix: string;
72
+ ageMinutes: number;
73
+ lastUsedMinutes: number;
74
+ useCount: number;
75
+ }>;
76
+ /**
77
+ * Get comprehensive statistics for UI display
78
+ */
79
+ getStatistics(): {
80
+ totalKeys: number;
81
+ keys: Array<{
82
+ provider: string;
83
+ redactedPrefix: string;
84
+ detectedAt: Date;
85
+ age: number;
86
+ useCount: number;
87
+ }>;
88
+ };
89
+ /**
90
+ * Clear all stored key mappings (use when starting new chat session)
91
+ */
92
+ clear(): void;
93
+ /**
94
+ * Process a chat message before sending to LLM
95
+ */
96
+ processOutgoingMessage(message: string): string;
97
+ /**
98
+ * Process a response from LLM before showing to user
99
+ */
100
+ processIncomingMessage(message: string): string;
101
+ }
102
+ //# sourceMappingURL=key-vault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-vault.d.ts","sourceRoot":"","sources":["../key-vault.ts"],"names":[],"mappings":"AAqBA,qBAAa,QAAQ;IACjB,OAAO,CAAC,WAAW,CAAsC;IAIzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CA2C3B;IAEF;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA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