UNPKG

@2501-ai/cli

Version:

[![npm version](https://img.shields.io/npm/v/@2501-ai/cli.svg)](https://www.npmjs.com/package/@2501-ai/cli) [![HumanEval Score](https://img.shields.io/badge/HumanEval-96.95%25-brightgreen.svg)](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic

66 lines (65 loc) 2.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initPluginCredentials = exports.credentialsService = void 0; const dotenv_1 = __importDefault(require("dotenv")); const logger_1 = __importDefault(require("./logger")); const plugins_1 = require("./plugins"); class CredentialsService { constructor() { this.credentials = {}; } static getInstance() { if (!CredentialsService.instance) { CredentialsService.instance = new CredentialsService(); } return CredentialsService.instance; } initialize(envPath) { if (envPath) { dotenv_1.default.config({ path: envPath }); } const plugins = plugins_1.pluginService.getPlugins(); Object.entries(process.env).forEach(([key, value]) => { if (!value) return; const matches = key.match(/^([A-Z0-9]+)_([A-Z0-9_]+)$/); if (!matches) return; const [, system, credKey] = matches; const systemLower = system.toLowerCase(); if (plugins[systemLower]) { if (!this.credentials[systemLower]) { this.credentials[systemLower] = {}; } this.credentials[systemLower][credKey.toLowerCase()] = value; logger_1.default.debug(`Loaded credential ${key} for plugin ${systemLower}`); } }); logger_1.default.debug('Credentials loaded successfully from environment variables'); } replaceCredentialPlaceholders(command) { if (!(command === null || command === void 0 ? void 0 : command.trim())) return command; const namespacedPattern = /{([a-zA-Z0-9_]+)_([a-zA-Z0-9_]+)}/g; return command.replace(namespacedPattern, (match, plugin, credKey) => { var _a; const value = (_a = this.credentials[plugin.toLowerCase()]) === null || _a === void 0 ? void 0 : _a[credKey.toLowerCase()]; logger_1.default.debug('credential_usage', { plugin, key: credKey, found: !!value, timestamp: Date.now(), }); return value || match; }); } } exports.credentialsService = CredentialsService.getInstance(); const initPluginCredentials = (thisCommand, actionCommand) => { const options = actionCommand.opts(); exports.credentialsService.initialize(options.env); }; exports.initPluginCredentials = initPluginCredentials;