const CHINESE_GET_MESSAGE_HINT = "\u53d6\u6d88\u606f";
/**
 * Main flow: normalize common MCP separators, then use the final segment as
 * the semantic tool name exposed to the agent.
 */
export function getSemanticToolName(toolName) {
    const normalized = toolName.trim().toLowerCase();
    const segments = normalized.split(/__|[./]/).filter(Boolean);
    return segments.at(-1) ?? normalized;
}
/**
 * Main flow: detect free-form idle guidance that asks the agent to enter the
 * message-polling loop.
 */
export function isMessagePollingIdleCommand(command) {
    const normalized = command.trim();
    if (!normalized)
        return false;
    const lower = normalized.toLowerCase();
    return (lower.includes("poll_message") ||
        lower.includes("get_message") ||
        normalized.includes(CHINESE_GET_MESSAGE_HINT));
}
function hasExactToolSegment(value, toolName) {
    if (typeof value !== "string") {
        return false;
    }
    return getSemanticToolName(value) === toolName;
}
/**
 * Main flow: validate startup MCP tool descriptors against the exact
 * poll_message semantic tool name instead of substring matching.
 */
export function isPollMessageToolDescriptor(tool) {
    return (hasExactToolSegment(tool.name, "poll_message") ||
        hasExactToolSegment(tool.source, "poll_message"));
}
