@plastichub/osr-ai-tools
Version:
CLI and library for LLM tools
74 lines (73 loc) • 3.11 kB
JavaScript
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.invokeOptions = exports.invoke = void 0;
const tools_1 = require("../lib/tools/tools");
const __1 = require("../");
const zod_schemas_1 = require("../zod_schemas");
const osr_commons_1 = require("@plastichub/osr-commons");
const write_1 = require("@plastichub/fs/write");
const path = __importStar(require("path"));
const options = (yargs) => (0, osr_commons_1.toYargs)(yargs, zod_schemas_1.InvokeToolSchema);
exports.invokeOptions = options;
const invoke = async (argv) => {
try {
const { tools: toolCategory, function: funcName, target, params, output } = argv;
// Get tool category
const toolSet = tools_1.tools[toolCategory];
if (!toolSet) {
__1.logger.error(`Tool category '${toolCategory}' not found`);
return;
}
// Initialize tools with target directory
const toolList = toolSet(target);
// Find specific function
const tool = toolList.find(t => t.function.name === funcName);
if (!tool) {
__1.logger.error(`Function '${funcName}' not found in ${toolCategory} tools`);
return;
}
// Parse parameters if provided
const parameters = params ? JSON.parse(params) : {};
// Execute tool function
__1.logger.info(`Invoking ${toolCategory}::${funcName}`);
const result = await tool.function.function(parameters);
// Handle output
if (output) {
const outputPath = path.isAbsolute(output) ? output : path.join(process.cwd(), output);
__1.logger.info(`Writing output to ${outputPath}`);
(0, write_1.sync)(outputPath, JSON.stringify(result, null, 2));
}
else {
__1.logger.info('Result:', result);
}
return result;
}
catch (error) {
__1.logger.error('Error invoking tool:', error);
throw error;
}
};
exports.invoke = invoke;
;