UNPKG

@kya-os/mcp-i

Version:

COMING SOON:Production-ready MCP Identity with automatic registration, key rotation, and optimized performance

275 lines (274 loc) 9.27 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.detectPlatform = detectPlatform; exports.generateClientInfo = generateClientInfo; exports.getPlatformRecommendations = getPlatformRecommendations; exports.getCachedPlatformInfo = getCachedPlatformInfo; const fs = __importStar(require("fs")); const path = __importStar(require("path")); function getSdkVersion() { try { const strategies = [ () => { if (typeof require !== 'undefined') { try { return require('../package.json').version; } catch { const packagePath = path.join(process.cwd(), 'node_modules', '@kya-os', 'mcp-i', 'package.json'); if (fs.existsSync(packagePath)) { return JSON.parse(fs.readFileSync(packagePath, 'utf-8')).version; } } } throw new Error('require not available'); }, () => { const possiblePaths = [ path.join(__dirname, '..', 'package.json'), path.join(__dirname, '..', '..', 'package.json'), path.join(process.cwd(), 'packages', 'mcp-i', 'package.json') ]; for (const packagePath of possiblePaths) { if (fs.existsSync(packagePath)) { return JSON.parse(fs.readFileSync(packagePath, 'utf-8')).version; } } throw new Error('package.json not found'); }, () => '0.1.0-alpha.3.6' ]; for (const strategy of strategies) { try { return strategy(); } catch { } } } catch { } return '0.1.0'; } function detectPlatform() { try { if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return { platform: 'browser', runtime: 'browser', capabilities: { fileSystem: false, asyncRuntime: true, persistentStorage: true, longRunning: false } }; } } catch { } if (typeof Deno !== 'undefined') { return { platform: 'deno', runtime: 'deno', version: Deno.version?.deno, capabilities: { fileSystem: true, asyncRuntime: true, persistentStorage: true, longRunning: true } }; } if (typeof Bun !== 'undefined') { return { platform: 'bun', runtime: 'bun', version: Bun.version, capabilities: { fileSystem: true, asyncRuntime: true, persistentStorage: true, longRunning: true } }; } if (typeof process !== 'undefined' && process.versions?.node) { let environment; if (process.env.VERCEL_EDGE || process.env.EDGE_RUNTIME) { return { platform: 'edge-light', runtime: 'vercel-edge', version: process.versions.node, environment: 'vercel', capabilities: { fileSystem: false, asyncRuntime: true, persistentStorage: false, longRunning: false } }; } if (process.env.CF_WORKERS || (typeof globalThis !== 'undefined' && globalThis.caches)) { return { platform: 'edge-light', runtime: 'cloudflare-workers', environment: 'cloudflare', capabilities: { fileSystem: false, asyncRuntime: true, persistentStorage: true, longRunning: false } }; } if (process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.LAMBDA_TASK_ROOT) { environment = 'lambda'; return { platform: 'node', runtime: 'node', version: process.versions.node, environment, capabilities: { fileSystem: true, asyncRuntime: true, persistentStorage: false, longRunning: false } }; } if (process.env.VERCEL && !process.env.VERCEL_EDGE) { environment = 'vercel-functions'; } if (process.env.NETLIFY) { environment = 'netlify-functions'; } if (process.env.DOCKER_CONTAINER) { environment = 'docker'; } else { try { if (fs.existsSync('/proc/1/cgroup') && fs.readFileSync('/proc/1/cgroup', 'utf-8').includes('docker')) { environment = 'docker'; } } catch { } } if (process.env.NEXT_RUNTIME) { environment = `nextjs-${process.env.NEXT_RUNTIME}`; } return { platform: 'node', runtime: 'node', version: process.versions.node, environment, capabilities: { fileSystem: true, asyncRuntime: true, persistentStorage: true, longRunning: environment !== 'lambda' && environment !== 'vercel-functions' } }; } return { platform: 'unknown', runtime: 'unknown', capabilities: { fileSystem: false, asyncRuntime: true, persistentStorage: false, longRunning: false } }; } function generateClientInfo(options) { const platformInfo = detectPlatform(); const sdkVersion = getSdkVersion(); let defaultProcessingMode = 'sync'; if (!platformInfo.capabilities.longRunning || platformInfo.platform === 'edge-light') { defaultProcessingMode = 'async'; } const clientInfo = { sdkVersion, language: 'javascript', platform: platformInfo.platform, processingMode: options?.processingMode || defaultProcessingMode }; if (platformInfo.runtime !== platformInfo.platform) { clientInfo.runtime = { name: platformInfo.runtime, version: platformInfo.version, environment: platformInfo.environment }; } if (options?.customMetadata) { clientInfo.metadata = options.customMetadata; } return clientInfo; } function getPlatformRecommendations(platformInfo) { const info = platformInfo || detectPlatform(); const recommendations = { storage: 'auto', transport: 'auto', processingMode: 'sync', logLevel: 'info' }; if (!info.capabilities.fileSystem || !info.capabilities.persistentStorage) { recommendations.storage = 'memory'; } else { recommendations.storage = 'file'; } if (info.platform === 'edge-light' || info.platform === 'browser') { recommendations.transport = 'fetch'; } if (!info.capabilities.longRunning) { recommendations.processingMode = 'async'; } if (info.environment === 'lambda' || info.platform === 'edge-light') { recommendations.logLevel = 'error'; } return recommendations; } let cachedPlatformInfo = null; function getCachedPlatformInfo() { if (!cachedPlatformInfo) { cachedPlatformInfo = detectPlatform(); } return cachedPlatformInfo; }