({
apiBaseUrl,
token,
requestInterceptor,
isDarkMode = false,
components,
readOnly = false,
initialFlow,
children
}: AgentflowProviderProps)
| 34 | * Sets up all required contexts for API access, configuration, and state management. |
| 35 | */ |
| 36 | export function AgentflowProvider({ |
| 37 | apiBaseUrl, |
| 38 | token, |
| 39 | requestInterceptor, |
| 40 | isDarkMode = false, |
| 41 | components, |
| 42 | readOnly = false, |
| 43 | initialFlow, |
| 44 | children |
| 45 | }: AgentflowProviderProps) { |
| 46 | // Create MUI theme based on dark mode |
| 47 | const theme = useMemo(() => createAgentflowTheme(isDarkMode), [isDarkMode]) |
| 48 | |
| 49 | // Inject CSS variables into DOM for use in CSS files. |
| 50 | // Split into two effects: one for updates (runs on isDarkMode change) |
| 51 | // and one for cleanup (runs only on unmount) to avoid a flash of |
| 52 | // missing variables when toggling dark mode. |
| 53 | const styleId = 'agentflow-css-variables' |
| 54 | |
| 55 | useEffect(() => { |
| 56 | let style = document.getElementById(styleId) as HTMLStyleElement |
| 57 | |
| 58 | if (!style) { |
| 59 | style = document.createElement('style') |
| 60 | style.id = styleId |
| 61 | document.head.appendChild(style) |
| 62 | } |
| 63 | |
| 64 | style.textContent = `:root { ${generateCSSVariables(isDarkMode)} }` |
| 65 | }, [isDarkMode]) |
| 66 | |
| 67 | useEffect(() => { |
| 68 | return () => { |
| 69 | const existingStyle = document.getElementById(styleId) |
| 70 | if (existingStyle) { |
| 71 | document.head.removeChild(existingStyle) |
| 72 | } |
| 73 | } |
| 74 | }, []) |
| 75 | |
| 76 | return ( |
| 77 | <ReactFlowProvider> |
| 78 | <ThemeProvider theme={theme}> |
| 79 | <ApiProvider apiBaseUrl={apiBaseUrl} token={token} requestInterceptor={requestInterceptor}> |
| 80 | <ConfigProvider isDarkMode={isDarkMode} components={components} readOnly={readOnly}> |
| 81 | <AgentflowStateProvider initialFlow={initialFlow}>{children}</AgentflowStateProvider> |
| 82 | </ConfigProvider> |
| 83 | </ApiProvider> |
| 84 | </ThemeProvider> |
| 85 | </ReactFlowProvider> |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | export default AgentflowProvider |
nothing calls this directly
no test coverage detected