Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

1.3 KB
Raw Blame
import { useQuery } from '@apollo/client/react';
import { createContext, type ReactNode, useContext, useMemo } from 'react';

import type { FlowFragmentFragment } from '@/graphql/types';

import { FlowsDocument } from '@/graphql/types';

export type Flow = FlowFragmentFragment;

interface SidebarFlowsContextValue {
    flows: Array<Flow>;
}

const SidebarFlowsContext = createContext<SidebarFlowsContextValue | undefined>(undefined);

interface SidebarFlowsProviderProps {
    children: ReactNode;
}

export function SidebarFlowsProvider({ children }: SidebarFlowsProviderProps) {
    // Subscriptions are handled by FlowsProvider in FlowsLayout
    const { data: flowsData } = useQuery(FlowsDocument, {
        fetchPolicy: 'cache-first',
        nextFetchPolicy: 'cache-first',
    });

    const flows = useMemo(() => flowsData?.flows ?? [], [flowsData?.flows]);

    const value = useMemo(
        () => ({
            flows,
        }),
        [flows],
    );

    return <SidebarFlowsContext.Provider value={value}>{children}</SidebarFlowsContext.Provider>;
}

export function useSidebarFlows() {
    const context = useContext(SidebarFlowsContext);

    if (context === undefined) {
        throw new Error('useSidebarFlows must be used within SidebarFlowsProvider');
    }

    return context;
}