-- 待审批的工具调用
CREATE TABLE IF NOT EXISTS pending_approvals (
    id UUID PRIMARY KEY,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    expires_at TIMESTAMPTZ NOT NULL,
    user_id TEXT NOT NULL,
    skill_name TEXT NOT NULL,
    params JSONB NOT NULL,
    code_hash TEXT NOT NULL,
    attempts_left INTEGER NOT NULL DEFAULT 3,
    status TEXT NOT NULL DEFAULT 'pending',
    result JSONB,
    consumed_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_pending_approvals_user_status
    ON pending_approvals (user_id, status);
