UNPKG

@comake/skl-js-engine

Version:

Standard Knowledge Language Javascript Engine

59 lines 2.21 kB
"use strict"; /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable no-console */ Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); // Example 1: Simple custom capability index_1.customCapabilities.register('greetUser', async (args) => ({ '@type': 'GreetingResult', '@value': `Hello, ${args.name}! Welcome to SKL Engine.` })); // Example 2: Custom capability that uses SKL Engine instance index_1.customCapabilities.register('countEntitiesWithProcessing', async (args, sklEngine) => { try { // Use the SKL engine to count entities const count = await sklEngine.count(args); // Add some processing const processedCount = count * 2; return { '@type': 'ProcessedCountResult', '@value': { originalCount: count, processedCount, timestamp: new Date().toISOString() } }; } catch (error) { return { '@type': 'ErrorResult', '@value': { error: error instanceof Error ? error.message : 'Unknown error', timestamp: new Date().toISOString() } }; } }); // Example 3: Custom capability that returns multiple results index_1.customCapabilities.register('generateMultipleGreetings', async (args) => { const names = args.names || []; return names.map((name, index) => ({ '@type': 'IndexedGreeting', '@value': { index, message: `Hello, ${name}!`, timestamp: new Date().toISOString() } })); }); // Usage example: console.log('Custom capabilities registered:'); console.log('- greetUser'); console.log('- countEntitiesWithProcessing'); console.log('- generateMultipleGreetings'); console.log('\nAll registered capabilities:', index_1.customCapabilities.getAll()); // Check if capabilities exist console.log('\nCapability checks:'); console.log('greetUser exists:', index_1.customCapabilities.has('greetUser')); console.log('nonExistent exists:', index_1.customCapabilities.has('nonExistent')); //# sourceMappingURL=customCapabilitiesExample.js.map