agente-toolkit
Version:
A barebones TypeScript library for building AI agents with intelligent tool execution and self-correction capabilities
60 lines (57 loc) • 1.71 kB
JavaScript
;
/**
* Utility functions for schema conversion and manipulation
*/
class SchemaUtils {
/**
* Convert TypeBox schema to JSON Schema format
* This is used by adapters to convert tool parameter schemas
* to the format expected by different LLM APIs
*/
static convertToJsonSchema(schema) {
const schemaObj = schema;
if (schemaObj.type === 'object') {
return {
type: 'object',
properties: schemaObj.properties || {},
required: schemaObj.required || [],
};
}
// For non-object schemas, wrap in an object
return {
type: 'object',
properties: {
value: schemaObj,
},
required: ['value'],
};
}
/**
* Validate that a schema object has the expected structure
*/
static isValidSchema(schema) {
return !!schema && typeof schema === 'object' && 'type' in schema;
}
/**
* Extract required fields from a TypeBox schema
*/
static getRequiredFields(schema) {
const schemaObj = schema;
if (schemaObj.type === 'object' && schemaObj.required) {
return Array.isArray(schemaObj.required) ? schemaObj.required : [];
}
return [];
}
/**
* Get all property names from an object schema
*/
static getPropertyNames(schema) {
const schemaObj = schema;
if (schemaObj.type === 'object' && schemaObj.properties) {
return Object.keys(schemaObj.properties);
}
return [];
}
}
exports.SchemaUtils = SchemaUtils;
//# sourceMappingURL=schemaUtils.js.map