// engine/compact-obj.ts — Remove null/undefined/empty values from objects recursively
/**
 * Recursively removes null, undefined, and empty strings from an object.
 * Empty arrays are kept (they have semantic meaning — "empty list" vs. "no field").
 * Reduces token waste in MCP responses by omitting absent fields.
 */
export function compactObj(obj) {
    const result = {};
    for (const key of Object.keys(obj)) {
        const value = obj[key];
        if (value === null || value === undefined) {
            continue;
        }
        if (value === '') {
            continue;
        }
        if (typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0) {
            const nested = compactObj(value);
            if (Object.keys(nested).length > 0) {
                result[key] = nested;
            }
            continue;
        }
        result[key] = value;
    }
    return result;
}
//# sourceMappingURL=compact-obj.js.map