capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
56 lines • 1.91 kB
JavaScript
export class BaseTool {
icon;
permissions = {};
ui = {
showProgress: false,
collapsible: true,
dangerous: false
};
validateParameters(params) {
for (const param of this.parameters) {
const value = params[param.name];
if (param.required && value === undefined) {
throw new Error(`Missing required parameter: ${param.name}`);
}
if (value === undefined || value === null)
continue;
const actualType = Array.isArray(value) ? 'array' : typeof value;
if (actualType !== param.type) {
throw new Error(`Parameter ${param.name} must be of type ${param.type}, got ${actualType}`);
}
if (param.enum && !param.enum.includes(value)) {
throw new Error(`Parameter ${param.name} must be one of: ${param.enum.join(', ')}`);
}
}
}
async measureExecution(fn) {
const startTime = Date.now();
const result = await fn();
const executionTime = Date.now() - startTime;
return { result, executionTime };
}
async execute(params, context) {
try {
this.validateParameters(params);
const { result, executionTime } = await this.measureExecution(() => this.run(params, context));
return {
success: true,
output: result,
executionTime
};
}
catch (error) {
return {
success: false,
error: error.message || 'Unknown error',
executionTime: 0
};
}
}
reportProgress(context, message, percentage, details) {
if (context.onProgress) {
context.onProgress({ message, percentage, details });
}
}
}
//# sourceMappingURL=base.js.map