feat: add Bun polyfills and refactor LiteMCP implementation
- Introduced polyfills for Node.js compatibility in Bun runtime - Moved LiteMCP implementation to a dedicated module - Updated package.json to include @digital-alchemy/hass dependency - Refactored import for LiteMCP to use local module path
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@digital-alchemy/core": "^0.1.0",
|
"@digital-alchemy/core": "^0.1.0",
|
||||||
|
"@digital-alchemy/hass": "^25.1.1",
|
||||||
"@jest/globals": "^29.7.0",
|
"@jest/globals": "^29.7.0",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ console.log(`Loading environment from ${envFile}`);
|
|||||||
config({ path: resolve(process.cwd(), envFile) });
|
config({ path: resolve(process.cwd(), envFile) });
|
||||||
|
|
||||||
import { get_hass } from './hass/index.js';
|
import { get_hass } from './hass/index.js';
|
||||||
import { LiteMCP } from 'litemcp';
|
import { LiteMCP } from './mcp/litemcp.js';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { DomainSchema } from './schemas.js';
|
import { DomainSchema } from './schemas.js';
|
||||||
|
|
||||||
|
|||||||
61
src/mcp/litemcp.ts
Normal file
61
src/mcp/litemcp.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
|
export class LiteMCP extends EventEmitter {
|
||||||
|
private static instance: LiteMCP;
|
||||||
|
private constructor() {
|
||||||
|
super();
|
||||||
|
// Initialize with default configuration
|
||||||
|
this.configure({});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getInstance(): LiteMCP {
|
||||||
|
if (!LiteMCP.instance) {
|
||||||
|
LiteMCP.instance = new LiteMCP();
|
||||||
|
}
|
||||||
|
return LiteMCP.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public configure(config: Record<string, any>): void {
|
||||||
|
// Store configuration
|
||||||
|
this.config = {
|
||||||
|
...this.defaultConfig,
|
||||||
|
...config
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private config: Record<string, any> = {};
|
||||||
|
private defaultConfig = {
|
||||||
|
maxRetries: 3,
|
||||||
|
retryDelay: 1000,
|
||||||
|
timeout: 5000
|
||||||
|
};
|
||||||
|
|
||||||
|
public async execute(command: string, params: Record<string, any> = {}): Promise<any> {
|
||||||
|
try {
|
||||||
|
// Emit command execution event
|
||||||
|
this.emit('command', { command, params });
|
||||||
|
|
||||||
|
// Execute command logic here
|
||||||
|
const result = await this.processCommand(command, params);
|
||||||
|
|
||||||
|
// Emit success event
|
||||||
|
this.emit('success', { command, params, result });
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
// Emit error event
|
||||||
|
this.emit('error', { command, params, error });
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async processCommand(command: string, params: Record<string, any>): Promise<any> {
|
||||||
|
// Command processing logic
|
||||||
|
return { command, params, status: 'processed' };
|
||||||
|
}
|
||||||
|
|
||||||
|
public async shutdown(): Promise<void> {
|
||||||
|
// Cleanup logic
|
||||||
|
this.removeAllListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/polyfills.js
Normal file
9
src/polyfills.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Add necessary polyfills for Node.js compatibility in Bun
|
||||||
|
import { webcrypto } from 'node:crypto';
|
||||||
|
|
||||||
|
// Polyfill for crypto.subtle in Bun
|
||||||
|
if (!globalThis.crypto?.subtle) {
|
||||||
|
globalThis.crypto = webcrypto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any other necessary polyfills here
|
||||||
Reference in New Issue
Block a user