Forked from bakit/crawler
Project Files
runtime.js
/**
* @fileoverview Self-contained runtime entry point for the Web Search Crawler Plugin.
* This bypasses the potentially flawed lms dev module loader by explicitly
* importing and running the compiled JavaScript modules.
*/
// Ensure all required dependencies are imported from the compiled /dist folder
const { webSearchCrawler } = require('./src/index');
const { executeWebSearch } = require('./src/service');
const { SearchInput } = require('./src/types');
/**
* Main entry point to run the plugin logic.
* This function mimics the role of the original lms dev command but uses direct Node.js requires.
*/
async function initializePlugin() {
console.log("[Runtime Initialized] Web Search Plugin ready.");
}
/**
* Public facing execution method that can be called by a calling process
* (e.g., a testing harness or the LLM wrapper).
* @param inputData The data structured for the web search tool.
* @returns A promise resolving to the search response.
*/
async function executeWebSearchTool(inputData: SearchInput): Promise<any> {
try {
// Call the exported tool function directly, using its compiled version.
const result = await webSearchCrawler(inputData);
console.log("[Runtime Success] Tool executed successfully.");
return result;
} catch (error) {
console.error("[Runtime Error] Failed to execute tool:", error);
throw new Error(`Web Search Tool Failure: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Exporting the functions so they can be required by other scripts if needed
module.exports = {
initializePlugin,
executeWebSearchTool
};