UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

104 lines (103 loc) 4.25 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPlugins = getPlugins; exports.getPlugin = getPlugin; exports.printPlugins = printPlugins; const chalk_1 = __importDefault(require("chalk")); const enums_1 = require("../types/enums"); // Her plugin ayrı dosyada default export olacak şekilde tasarlandı async function getPlugins() { const availablePlugins = []; for (const pluginName of Object.values(enums_1.plugins)) { try { const pluginModule = await Promise.resolve(`${`../plugins/${pluginName}/${pluginName}Plugin`}`).then(s => __importStar(require(s))); const pluginInstance = new pluginModule.default(); const InitConfigExample = pluginInstance.InitConfigExample || {}; const RunConfigExample = pluginInstance.RunConfigExample || {}; availablePlugins.push({ name: pluginInstance.name, description: pluginInstance.description, type: pluginInstance.type, InitConfigExample, RunConfigExample }); } catch (err) { console.warn(`Plugin '${pluginName}' yüklenemedi:`, err); } } return availablePlugins; } async function getPlugin(pluginName) { try { const pluginModule = await Promise.resolve(`${`../plugins/${pluginName}/${pluginName}Plugin`}`).then(s => __importStar(require(s))); const pluginInstance = new pluginModule.default(); const InitConfigExample = pluginInstance.InitConfigExample || {}; const RunConfigExample = pluginInstance.RunConfigExample || {}; return { name: pluginInstance.name, description: pluginInstance.description, type: pluginInstance.type, InitConfigExample, RunConfigExample }; } catch (err) { console.warn(`Plugin '${pluginName}' yüklenemedi:`, err); return null; } } async function printPlugins() { const Allplugins = await getPlugins(); Allplugins.forEach((p, index) => { const border = chalk_1.default.gray("═".repeat(50)); console.log("\n" + border); console.log(chalk_1.default.bold.cyan(`🔌 Plugin: ${p.name}`)); console.log(chalk_1.default.gray("📄 Description:"), chalk_1.default.white(p.description)); console.log(chalk_1.default.gray("🧪 Example Config:")); console.log(JSON.stringify(p.InitConfigExample, null, 2) .split("\n") .map((line) => " " + chalk_1.default.green(line)) .join("\n")); console.log(border); }); } function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); }