/**
 * Type definitions for OpenCode SDK integration
 */
/** Map TAKT PermissionMode to OpenCode permission reply */
export function mapToOpenCodePermissionReply(mode) {
    const mapping = {
        readonly: 'reject',
        edit: 'once',
        full: 'always',
    };
    return mapping[mode];
}
const OPEN_CODE_PERMISSION_KEYS = [
    'read',
    'glob',
    'grep',
    'edit',
    'write',
    'bash',
    'task',
    'websearch',
    'webfetch',
    'question',
];
function buildPermissionMap(mode) {
    const allDeny = {
        read: 'deny',
        glob: 'deny',
        grep: 'deny',
        edit: 'deny',
        write: 'deny',
        bash: 'deny',
        task: 'deny',
        websearch: 'deny',
        webfetch: 'deny',
        question: 'deny',
    };
    if (mode === 'readonly')
        return allDeny;
    if (mode === 'full') {
        return {
            ...allDeny,
            read: 'allow',
            glob: 'allow',
            grep: 'allow',
            edit: 'allow',
            write: 'allow',
            bash: 'allow',
            task: 'allow',
            websearch: 'allow',
            webfetch: 'allow',
            question: 'allow',
        };
    }
    if (mode === 'edit') {
        return {
            ...allDeny,
            read: 'allow',
            glob: 'allow',
            grep: 'allow',
            edit: 'allow',
            write: 'allow',
            bash: 'allow',
            task: 'allow',
            websearch: 'allow',
            webfetch: 'allow',
            question: 'deny',
        };
    }
    return {
        ...allDeny,
        read: 'ask',
        glob: 'ask',
        grep: 'ask',
        edit: 'ask',
        write: 'ask',
        bash: 'ask',
        task: 'ask',
        websearch: 'ask',
        webfetch: 'ask',
        question: 'deny',
    };
}
function applyNetworkAccessOverride(map, networkAccess) {
    if (networkAccess === undefined) {
        return map;
    }
    const action = networkAccess ? 'allow' : 'deny';
    return {
        ...map,
        webfetch: action,
        websearch: action,
    };
}
export function buildOpenCodePermissionConfig(mode, networkAccess) {
    if (networkAccess === undefined) {
        if (mode === 'readonly')
            return 'deny';
        if (mode === 'full')
            return 'allow';
    }
    return applyNetworkAccessOverride(buildPermissionMap(mode), networkAccess);
}
export function buildOpenCodePermissionRuleset(mode, networkAccess) {
    const permissionMap = applyNetworkAccessOverride(buildPermissionMap(mode), networkAccess);
    return OPEN_CODE_PERMISSION_KEYS.map((permission) => ({
        permission,
        pattern: '**',
        action: permissionMap[permission],
    }));
}
const BUILTIN_TOOL_MAP = {
    Read: 'read',
    Glob: 'glob',
    Grep: 'grep',
    Edit: 'edit',
    Write: 'write',
    Bash: 'bash',
    WebSearch: 'websearch',
    WebFetch: 'webfetch',
};
export function mapToOpenCodeTools(allowedTools) {
    if (!allowedTools) {
        return undefined;
    }
    if (allowedTools.length === 0) {
        return {};
    }
    const mapped = new Set();
    for (const tool of allowedTools) {
        const normalized = tool.trim();
        if (!normalized) {
            continue;
        }
        const mappedTool = BUILTIN_TOOL_MAP[normalized] ?? normalized;
        mapped.add(mappedTool);
    }
    if (mapped.size === 0) {
        return {};
    }
    const tools = {};
    for (const tool of mapped) {
        tools[tool] = true;
    }
    return tools;
}
//# sourceMappingURL=types.js.map