const TOOL_TOKEN_REGEX = /[a-z0-9]+/g;
const STANDARD_NAMESPACE_SEPARATOR_REGEX = /[.:/]/;
export function normalizeToolName(name) {
    return name.trim().toLowerCase();
}
export function tokenizeToolName(name) {
    const normalized = normalizeToolName(name);
    return normalized.match(TOOL_TOKEN_REGEX) ?? [];
}
export function getToolLeafName(name) {
    const tokens = tokenizeToolName(name);
    return tokens.length > 0 ? tokens[tokens.length - 1] : null;
}
export function isSpeakToolName(name) {
    return getToolLeafName(name) === "speak";
}
export function isLikelyNamespacedToolName(name) {
    const normalized = normalizeToolName(name);
    if (STANDARD_NAMESPACE_SEPARATOR_REGEX.test(normalized)) {
        return true;
    }
    if (!normalized.includes("__")) {
        return false;
    }
    // Keep `__` handling strict to avoid false positives on arbitrary custom names.
    const segments = normalized.split("__").filter((segment) => segment.length > 0);
    if (segments.length >= 3) {
        return true;
    }
    if (segments.length === 2 && segments[1].includes("_")) {
        return true;
    }
    return false;
}
export function isLikelyExternalToolName(name) {
    const normalized = normalizeToolName(name);
    if (!normalized) {
        return false;
    }
    if (isSpeakToolName(normalized)) {
        return true;
    }
    return isLikelyNamespacedToolName(normalized);
}
//# sourceMappingURL=tool-name-normalization.js.map