export function requiredAnyToolGroupsForConstraint(constraint) {
    const groups = [
        ...(constraint.requiredAnyToolGroups ?? []),
        ...(constraint.requiredAnyToolNames ? [constraint.requiredAnyToolNames] : []),
    ];
    const normalizedGroups = [];
    for (const group of groups) {
        const normalizedGroup = [...new Set(group)].filter((toolName) => toolName.length > 0);
        if (normalizedGroup.length > 1 &&
            !normalizedGroups.some((existingGroup) => existingGroup.length === normalizedGroup.length &&
                existingGroup.every((toolName, index) => toolName === normalizedGroup[index]))) {
            normalizedGroups.push(normalizedGroup);
        }
    }
    return normalizedGroups;
}
export function splitRequiredToolGroups(constraint) {
    const requiredAnyToolGroups = requiredAnyToolGroupsForConstraint(constraint);
    const requiredAnyToolNames = [...new Set(requiredAnyToolGroups.flat())];
    if (constraint.requiredAllToolNames) {
        return {
            requiredAllToolNames: constraint.requiredAllToolNames,
            requiredAnyToolGroups,
            requiredAnyToolNames,
        };
    }
    return {
        // Legacy fallback for persisted constraints that predate requiredAllToolNames.
        requiredAllToolNames: constraint.requiredToolNames.filter((toolName) => !requiredAnyToolNames.includes(toolName)),
        requiredAnyToolGroups,
        requiredAnyToolNames,
    };
}
//# sourceMappingURL=tool-constraint-types.js.map