export class ToolPermissionContext {
    denyNames;
    denyPrefixes;
    constructor(denyNames = new Set(), denyPrefixes = []) {
        this.denyNames = denyNames;
        this.denyPrefixes = denyPrefixes;
    }
    static fromIterables(denyNames, denyPrefixes) {
        return new ToolPermissionContext(new Set(denyNames
            ? Array.from(denyNames).map((n) => n.toLowerCase())
            : []), denyPrefixes
            ? Array.from(denyPrefixes).map((p) => p.toLowerCase())
            : []);
    }
    blocks(toolName) {
        const lowered = toolName.toLowerCase();
        return (this.denyNames.has(lowered) ||
            this.denyPrefixes.some((prefix) => lowered.startsWith(prefix)));
    }
    withDenial(name, reason) {
        const newDenyNames = new Set(this.denyNames);
        newDenyNames.add(name.toLowerCase());
        return {
            context: new ToolPermissionContext(newDenyNames, this.denyPrefixes),
            denial: { toolName: name, reason },
        };
    }
}
export function checkPermission(context, toolName, reason) {
    if (context.blocks(toolName)) {
        return {
            allowed: false,
            denialReason: { toolName, reason },
        };
    }
    return { allowed: true };
}
