import { createHash } from "node:crypto";
/**
 * Recursively sorts object keys for deterministic JSON stringification.
 */
function sortObjectKeys(obj) {
    if (obj === null || typeof obj !== "object") {
        return obj;
    }
    if (Array.isArray(obj)) {
        return obj.map(sortObjectKeys);
    }
    const sorted = {};
    for (const key of Object.keys(obj).sort()) {
        sorted[key] = sortObjectKeys(obj[key]);
    }
    return sorted;
}
/**
 * Creates a unique identifier based on message, toolname, and input.
 *
 * This generates a deterministic hash that can be used to identify
 * a specific tool call based on its parameters.
 *
 * @param messageId - The message ID (or any message identifier)
 * @param toolName - The name of the tool
 * @param input - The input parameters for the tool
 * @returns A unique identifier string
 */
export function getToolCallSignature(toolName, input) {
    const hash = createHash("sha256");
    // Sort keys for deterministic JSON stringification
    const sortedInput = JSON.stringify(sortObjectKeys(input)) ?? "null";
    hash.update(toolName ?? "");
    hash.update(sortedInput);
    const hashValue = hash.digest("hex");
    return hashValue;
}
//# sourceMappingURL=tool-signature.js.map