import { useRef, useState } from "react"; import type { AutomationFilter, AutomationSort, } from "@/components/settings/system/AutomationsSettings"; import { DEFAULT_CUSTOM_MCP_FORM, type AppsKindFilter, type CustomMcpForm, } from "@/components/settings/system/AppsSettings"; import type { ApiServicePayload, AutomationsPayload, CliAppsPayload, McpOAuthFlowPayload, McpPresetsPayload, NanobotFeatureInfo, NanobotFeaturesPayload, SessionAutomationJob, } from "@/lib/types"; export function useSystemSettingsState() { const [cliApps, setCliApps] = useState(null); const [nanobotFeatures, setNanobotFeatures] = useState(null); const [mcpPresets, setMcpPresets] = useState(null); const [automations, setAutomations] = useState(null); const [cliAppsLoading, setCliAppsLoading] = useState(true); const [nanobotFeaturesLoading, setNanobotFeaturesLoading] = useState(true); const [mcpPresetsLoading, setMcpPresetsLoading] = useState(true); const [automationsLoading, setAutomationsLoading] = useState(false); const [cliAppsAction, setCliAppsAction] = useState(null); const [nanobotFeatureAction, setNanobotFeatureAction] = useState(null); const [nanobotFeatureConfirm, setNanobotFeatureConfirm] = useState(null); const [mcpPresetAction, setMcpPresetAction] = useState(null); const [mcpOAuthFlow, setMcpOAuthFlow] = useState(null); const mcpOAuthFlowRef = useRef(null); const mcpOAuthPopupRef = useRef(null); const mcpOAuthNavigatedUrlRef = useRef(null); const [mcpOAuthPopupBlocked, setMcpOAuthPopupBlocked] = useState(false); const [mcpOAuthCallbackUrl, setMcpOAuthCallbackUrl] = useState(""); const [mcpOAuthCompleting, setMcpOAuthCompleting] = useState(false); const [mcpOAuthCallbackError, setMcpOAuthCallbackError] = useState(null); const [apiService, setApiService] = useState(null); const [apiServiceLoading, setApiServiceLoading] = useState(false); const [apiServiceAction, setApiServiceAction] = useState<"start" | "stop" | null>(null); const [apiServiceError, setApiServiceError] = useState(null); const [appsQuery, setAppsQuery] = useState(""); const [automationsQuery, setAutomationsQuery] = useState(""); const [automationsFilter, setAutomationsFilter] = useState("all"); const [automationsSort, setAutomationsSort] = useState("next"); const [cliAppsMessage, setCliAppsMessage] = useState(null); const [cliAppsError, setCliAppsError] = useState(null); const [nanobotFeaturesError, setNanobotFeaturesError] = useState(null); const [cliAppsFocusName, setCliAppsFocusName] = useState(null); const [appsKindFilter, setAppsKindFilter] = useState("cli"); const [mcpMessage, setMcpMessage] = useState(null); const [mcpError, setMcpError] = useState(null); const [automationsError, setAutomationsError] = useState(null); const [automationAction, setAutomationAction] = useState(null); const [automationPendingDelete, setAutomationPendingDelete] = useState(null); const [automationPendingEdit, setAutomationPendingEdit] = useState(null); const [mcpFieldValues, setMcpFieldValues] = useState>>({}); const [customMcpForm, setCustomMcpForm] = useState(DEFAULT_CUSTOM_MCP_FORM); const [mcpConfigImport, setMcpConfigImport] = useState(""); return { apiService, apiServiceAction, apiServiceError, apiServiceLoading, appsKindFilter, appsQuery, automationAction, automationPendingDelete, automationPendingEdit, automations, automationsError, automationsFilter, automationsLoading, automationsQuery, automationsSort, cliApps, cliAppsAction, cliAppsError, cliAppsFocusName, cliAppsLoading, cliAppsMessage, customMcpForm, mcpConfigImport, mcpError, mcpFieldValues, mcpMessage, mcpOAuthCallbackError, mcpOAuthCallbackUrl, mcpOAuthCompleting, mcpOAuthFlow, mcpOAuthFlowRef, mcpOAuthNavigatedUrlRef, mcpOAuthPopupBlocked, mcpOAuthPopupRef, mcpPresetAction, mcpPresets, mcpPresetsLoading, nanobotFeatureAction, nanobotFeatureConfirm, nanobotFeatures, nanobotFeaturesError, nanobotFeaturesLoading, setApiService, setApiServiceAction, setApiServiceError, setApiServiceLoading, setAppsKindFilter, setAppsQuery, setAutomationAction, setAutomationPendingDelete, setAutomationPendingEdit, setAutomations, setAutomationsError, setAutomationsFilter, setAutomationsLoading, setAutomationsQuery, setAutomationsSort, setCliApps, setCliAppsAction, setCliAppsError, setCliAppsFocusName, setCliAppsLoading, setCliAppsMessage, setCustomMcpForm, setMcpConfigImport, setMcpError, setMcpFieldValues, setMcpMessage, setMcpOAuthCallbackError, setMcpOAuthCallbackUrl, setMcpOAuthCompleting, setMcpOAuthFlow, setMcpOAuthPopupBlocked, setMcpPresetAction, setMcpPresets, setMcpPresetsLoading, setNanobotFeatureAction, setNanobotFeatureConfirm, setNanobotFeatures, setNanobotFeaturesError, setNanobotFeaturesLoading, }; } export type SystemSettingsState = ReturnType;