export function buildKnowledgePath(endpointPrefix = '', path = '') {
  if (!endpointPrefix) {
    return path;
  }
  const normalizedPrefix = endpointPrefix.endsWith('/')
    ? endpointPrefix.slice(0, -1)
    : endpointPrefix;
  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
  if (normalizedPath.startsWith(`${normalizedPrefix}/`)) {
    return normalizedPath;
  }
  if (normalizedPath.startsWith('/api/v1/')) {
    return `${normalizedPrefix}${normalizedPath.slice('/api/v1'.length)}`;
  }
  return `${normalizedPrefix}${normalizedPath}`;
}
