refactor(api)!: remove the standalone API server (#6614)

This commit is contained in:
Xubin Ren authored and GitHub committed 2026-11-10 10:46:14 +08:00
1 parent 5c72ced2fe
commit 220d5e6970
99 files changed
+240 -4133

No files matched your search

@@ -467,15 +467,10 @@ export function SettingsPage({
onRestart={showSidebar ? undefined : restartViaSettingsSurface}
isRestarting={restartInProgress}
requiresRestartPending={pendingRestartSections.runtime}
apiService={systemState.apiService}
apiServiceLoading={systemState.apiServiceLoading}
apiServiceAction={systemState.apiServiceAction}
apiServiceError={systemState.apiServiceError}
langfuseFeature={featureCatalog.find((feature) => feature.name === "langfuse")}
capabilitiesLoading={systemState.nanobotFeaturesLoading}
capabilityAction={systemState.nanobotFeatureAction}
capabilityError={systemState.nanobotFeaturesError}
onApiServiceAction={systemActions.handleApiServiceAction}
onInstallCapability={(name) => void systemActions.installCapabilities([name])}
/>
</div>
@@ -119,7 +119,7 @@ export function SettingsSectionSkeleton({ section, showRestart = false, sandboxS
</SettingsGroup><div className="settings-footer flex items-center justify-between gap-2"><div className="flex h-11 items-center sm:h-9"><div className={cn(block, "h-3 w-20")} /></div><div className="flex h-11 items-center sm:h-9"><div className={cn(block, "h-3 w-28")} /></div></div></section>;
break;
case "runtime":
content = <><RuntimeGroups page="runtime" /><Group controls={["input", "segments", "input", "input"]} /><Group controls={["input"]} /><Group controls={showRestart ? ["text", "text", "input"] : ["text", "text"]} /></>;
content = <><RuntimeGroups page="runtime" /><Group controls={["input"]} /><Group controls={showRestart ? ["text", "text", "input"] : ["text", "text"]} /></>;
break;
case "advanced":
content = <RuntimeGroups page="advanced" sandboxSupported={sandboxSupported} />;
@@ -93,7 +93,7 @@ export function useRuntimeConfigSettings(
const maximum = field.kind === "duration" ? settings.advanced.exec_max_runtime_limit : field.max;
const parsed = Number(raw);
if (String(raw).trim() === "" || !Number.isFinite(parsed)
|| (field.path !== "api.timeout" && !Number.isInteger(parsed))
|| !Number.isInteger(parsed)
|| (field.min !== undefined && parsed < field.min)
|| (maximum !== undefined && parsed > maximum)) {
setErrors((prev) => ({ ...prev, [group]: t("settings.runtimeConfig.numberError") }));
@@ -288,7 +288,7 @@ export function RuntimeConfigSettings({
onChange={(next) => state.change(field, next === "__none__" ? "" : next)} />
) : (
<Input {...common} type={field.kind === "number" ? "number" : "text"}
min={field.min} max={field.max} step={field.path === "api.timeout" ? "any" : 1}
min={field.min} max={field.max} step={1}
value={String(current)} className="h-9 rounded-full text-[13px]" autoComplete="off"
onChange={(event) => state.change(field, event.target.value)} />
)}
@@ -1,10 +1,9 @@
import { useEffect, useState } from "react";
import { Eye, EyeOff, Loader2, PauseCircle, PlayCircle, RotateCcw } from "lucide-react";
import { useState } from "react";
import { Loader2, RotateCcw } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { AgentSettingsDraft } from "@/components/settings/models/ModelsSettings";
import {
NumberInput,
ReadOnlyRow,
SettingsGroup,
SettingsRow,
@@ -12,11 +11,8 @@ import {
StatusPill,
} from "@/components/settings/shared/SettingsControls";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { SegmentedControl } from "@/components/ui/segmented-control";
import { isLoopbackHost } from "@/lib/network";
import { getRuntimeHost, isNativeRuntime } from "@/lib/runtime";
import type { ApiServicePayload, NanobotFeatureInfo, SettingsPayload } from "@/lib/types";
import type { NanobotFeatureInfo, SettingsPayload } from "@/lib/types";
export function RuntimeSettings({
form,
@@ -24,15 +20,10 @@ export function RuntimeSettings({
onRestart,
isRestarting,
requiresRestartPending,
apiService,
apiServiceLoading,
apiServiceAction,
apiServiceError,
langfuseFeature,
capabilitiesLoading,
capabilityAction,
capabilityError,
onApiServiceAction,
onInstallCapability,
}: {
form: AgentSettingsDraft;
@@ -40,18 +31,10 @@ export function RuntimeSettings({
onRestart?: () => void;
isRestarting?: boolean;
requiresRestartPending: boolean;
apiService: ApiServicePayload | null;
apiServiceLoading: boolean;
apiServiceAction: "start" | "stop" | null;
apiServiceError: string | null;
langfuseFeature?: NanobotFeatureInfo;
capabilitiesLoading: boolean;
capabilityAction: string | null;
capabilityError: string | null;
onApiServiceAction: (
action: "start" | "stop",
values?: { host: string; port: number; timeout: number; apiKey?: string },
) => void;
onInstallCapability: (name: string) => void;
}) {
const { t } = useTranslation();
@@ -74,30 +57,6 @@ export function RuntimeSettings({
} | null>(null);
const [hostActionBusy, setHostActionBusy] =
useState<"logs" | "diagnostics" | null>(null);
const apiDefaults = apiService ?? {
installed: false,
running: false,
managed: false,
host: settings.api?.host ?? "127.0.0.1",
port: settings.api?.port ?? 8900,
timeout: settings.api?.timeout ?? 120,
api_key_hint: settings.api?.api_key_hint,
endpoint: `http://127.0.0.1:${settings.api?.port ?? 8900}/v1`,
command: "nanobot serve",
};
const [apiHost, setApiHost] = useState(apiDefaults.host);
const [apiPort, setApiPort] = useState(apiDefaults.port);
const [apiKey, setApiKey] = useState("");
const [apiKeyVisible, setApiKeyVisible] = useState(false);
useEffect(() => {
if (!apiService) return;
setApiHost(settings.api?.host ?? apiService.host);
setApiPort(settings.api?.port ?? apiService.port);
setApiKey("");
setApiKeyVisible(false);
}, [apiService, settings.api?.host, settings.api?.port]);
const apiNetworkAccess = !isLoopbackHost(apiHost);
const apiMissingNetworkKey = apiNetworkAccess && !apiKey.trim() && !apiDefaults.api_key_hint;
const engineState = isRestarting
? tx("settings.values.restartingEngine", "Restarting")
: settings.apply_state?.status === "pending"
@@ -205,118 +164,6 @@ export function RuntimeSettings({
</section>
) : null}
<section>
<SettingsSectionTitle>{tx("settings.api.title", "API server")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.api.openaiCompatible", "OpenAI-compatible API")}
description={
apiServiceError
? apiServiceError
: apiDefaults.running
? apiDefaults.endpoint
: undefined
}
>
<div className="flex items-center justify-end gap-2">
<StatusPill tone={apiDefaults.running ? "success" : "neutral"}>
{apiServiceLoading
? tx("settings.values.checking", "Checking")
: apiDefaults.running
? tx("settings.values.running", "Running")
: tx("settings.values.off", "Off")}
</StatusPill>
<Button
size="sm"
variant="outline"
disabled={apiServiceLoading || apiServiceAction !== null || apiMissingNetworkKey}
onClick={() =>
onApiServiceAction(
apiDefaults.running ? "stop" : "start",
apiDefaults.running
? undefined
: {
host: apiHost,
port: apiPort,
timeout: settings.api?.timeout ?? apiDefaults.timeout,
apiKey: apiKey.trim() || undefined,
},
)
}
className="rounded-full"
>
{apiServiceAction ? (
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden />
) : apiDefaults.running ? (
<PauseCircle className="mr-1.5 h-3.5 w-3.5" aria-hidden />
) : (
<PlayCircle className="mr-1.5 h-3.5 w-3.5" aria-hidden />
)}
{apiServiceAction === "start"
? tx("settings.api.starting", "Starting...")
: apiServiceAction === "stop"
? tx("settings.api.stopping", "Stopping...")
: apiDefaults.running
? tx("settings.api.stop", "Stop")
: tx("settings.api.start", "Start API server")}
</Button>
</div>
</SettingsRow>
{!apiDefaults.running ? (
<>
<SettingsRow
title={tx("settings.api.access", "Access")}
description={
apiNetworkAccess
? tx("settings.api.networkHelp", "Other devices can connect; an API key is required.")
: tx("settings.api.localHelp", "Only this device can connect.")
}
>
<SegmentedControl
value={apiNetworkAccess ? "network" : "local"}
options={[
{ value: "local", label: tx("settings.api.thisDevice", "This device") },
{ value: "network", label: tx("settings.api.localNetwork", "Local network") },
]}
onChange={(value) => setApiHost(value === "network" ? "0.0.0.0" : "127.0.0.1")}
/>
</SettingsRow>
<SettingsRow title={tx("settings.api.port", "Port")}>
<NumberInput value={apiPort} min={1} max={65535} onChange={setApiPort} />
</SettingsRow>
<SettingsRow
title={tx("settings.api.apiKey", "API key")}
description={
apiMissingNetworkKey
? tx("settings.api.apiKeyRequired", "Required before exposing the API to your network.")
: tx("settings.api.apiKeyHelp", "Clients send this as a Bearer token.")
}
>
<div className="relative w-full">
<Input
type={apiKeyVisible ? "text" : "password"}
value={apiKey}
onChange={(event) => setApiKey(event.target.value)}
placeholder={apiDefaults.api_key_hint ?? tx("settings.api.apiKeyPlaceholder", "Enter an API key")}
className="h-9 rounded-full pr-10 text-[13px]"
/>
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => setApiKeyVisible((visible) => !visible)}
aria-label={apiKeyVisible ? tx("settings.byok.hideApiKey", "Hide API key") : tx("settings.byok.showApiKey", "Show API key")}
className="absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full"
>
{apiKeyVisible ? <EyeOff className="h-3.5 w-3.5" /> : <Eye className="h-3.5 w-3.5" />}
</Button>
</div>
</SettingsRow>
</>
) : null}
</SettingsGroup>
</section>
<section>
<SettingsSectionTitle>{tx("settings.observability.title", "Observability")}</SettingsSectionTitle>
<SettingsGroup>
@@ -2,7 +2,6 @@ import type { Dispatch, SetStateAction } from "react";
import type { TFunction } from "i18next";
import type {
ApplySettingsPayload,
MaybeRestartHostEngine,
PendingRestartSections,
} from "@/components/settings/contracts";
@@ -15,8 +14,6 @@ import {
completeMcpOAuth,
disableNanobotFeature,
enableNanobotFeature,
fetchNanobotFeatures,
fetchSettings,
fetchMcpOAuthStatus,
fetchMcpPresets,
importMcpConfig,
@@ -25,8 +22,6 @@ import {
runMcpPresetAction,
saveCustomMcpServer,
startMcpOAuth,
startApiService,
stopApiService,
updateAutomation,
updateMcpServerTools,
} from "@/lib/api";
@@ -71,10 +66,8 @@ interface SystemSettingsActionsOptions {
state: SystemSettingsState;
featureCatalog: NanobotFeatureInfo[];
client: NanobotClient;
token: string;
getToken: () => string;
t: TFunction;
applyPayload: ApplySettingsPayload;
maybeRestartHostEngine: MaybeRestartHostEngine;
setPendingRestartSections: Dispatch<SetStateAction<PendingRestartSections>>;
refreshAutomations: (showLoading?: boolean) => Promise<void>;
@@ -84,16 +77,13 @@ export function createSystemSettingsActions({
state,
featureCatalog,
client,
token,
getToken,
t,
applyPayload,
maybeRestartHostEngine,
setPendingRestartSections,
refreshAutomations,
}: SystemSettingsActionsOptions) {
const {
apiServiceAction,
customMcpForm,
mcpConfigImport,
mcpOAuthCallbackUrl,
@@ -102,9 +92,6 @@ export function createSystemSettingsActions({
mcpOAuthPopupRef,
nanobotFeatureActionRef,
nanobotFeatures,
setApiService,
setApiServiceAction,
setApiServiceError,
setAutomationAction,
setAutomationPendingDelete,
setAutomationPendingEdit,
@@ -172,29 +159,6 @@ export function createSystemSettingsActions({
}
};
const handleApiServiceAction = async (
action: "start" | "stop",
values?: { host: string; port: number; timeout: number; apiKey?: string },
) => {
if (apiServiceAction) return;
setApiServiceAction(action);
setApiServiceError(null);
try {
const payload = action === "start"
? await startApiService(client, values!)
: await stopApiService(client);
setApiService(payload);
const refreshed = await fetchNanobotFeatures(token);
setNanobotFeatures(refreshed);
const nextSettings = await fetchSettings(token);
applyPayload(nextSettings);
} catch (err) {
setApiServiceError((err as Error).message);
} finally {
setApiServiceAction(null);
}
};
const handleCliAppAction = async (
action: "install" | "update" | "uninstall" | "test",
name: string,
@@ -709,7 +673,6 @@ export function createSystemSettingsActions({
};
return {
handleApiServiceAction,
handleAutomationAction,
handleAutomationEdit,
handleAutomationChat,
@@ -25,7 +25,6 @@ export const RUNTIME_CONFIG_GROUPS: { id: string; page: RuntimeConfigPage; enabl
{ id: "safety", page: "advanced" },
{ id: "cli", page: "advanced", enabledBy: "tools.cli_apps.enable" },
{ id: "gateway", page: "advanced" },
{ id: "api", page: "advanced" },
{ id: "storage", page: "image" },
];
@@ -68,7 +67,5 @@ export const RUNTIME_CONFIG_FIELDS: RuntimeConfigField[] = [
{ group: "gateway", path: "gateway.host", kind: "text", manual: true },
{ group: "gateway", path: "gateway.port", kind: "number", min: 1, max: 65535, manual: true },
{ group: "gateway", path: "gateway.restart_mode", kind: "select", options: ["auto", "exec", "spawn", "exit"] },
{ group: "api", path: "api.host", kind: "text", manual: true },
{ group: "api", path: "api.timeout", kind: "number", min: 1, max: 3600 },
{ group: "storage", path: "tools.image_generation.save_dir", kind: "text" },
];
@@ -7,7 +7,6 @@ import {
} from "@/components/settings/system/AppsSettings";
import type { SystemSettingsState } from "@/components/settings/system/useSystemSettingsState";
import {
fetchApiService,
fetchAutomations,
fetchNanobotFeatures,
} from "@/lib/api";
@@ -28,9 +27,6 @@ export function useSystemSettingsEffects({
pageVisible,
}: SystemSettingsEffectsOptions) {
const {
setApiService,
setApiServiceError,
setApiServiceLoading,
setAutomations,
setAutomationsError,
setAutomationsLoading,
@@ -136,28 +132,6 @@ export function useSystemSettingsEffects({
};
}, [activeSection, getToken, pageVisible]);
useEffect(() => {
if (activeSection !== "runtime") return;
let cancelled = false;
setApiServiceLoading(true);
fetchApiService(getToken())
.then((payload) => {
if (!cancelled) {
setApiService(payload);
setApiServiceError(null);
}
})
.catch((err) => {
if (!cancelled) setApiServiceError((err as Error).message);
})
.finally(() => {
if (!cancelled) setApiServiceLoading(false);
});
return () => {
cancelled = true;
};
}, [activeSection, getToken]);
useEffect(() => {
if (activeSection !== "apps" || !pageVisible) return;
let cancelled = false;
@@ -9,7 +9,6 @@ import {
type CustomMcpForm,
} from "@/components/settings/system/AppsSettings";
import type {
ApiServicePayload,
AutomationsPayload,
McpOAuthFlowPayload,
NanobotFeatureInfo,
@@ -45,10 +44,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
const [mcpOAuthCallbackUrl, setMcpOAuthCallbackUrl] = useState("");
const [mcpOAuthCompleting, setMcpOAuthCompleting] = useState(false);
const [mcpOAuthCallbackError, setMcpOAuthCallbackError] = useState<string | null>(null);
const [apiService, setApiService] = useState<ApiServicePayload | null>(null);
const [apiServiceLoading, setApiServiceLoading] = useState(false);
const [apiServiceAction, setApiServiceAction] = useState<"start" | "stop" | null>(null);
const [apiServiceError, setApiServiceError] = useState<string | null>(null);
const [appsQuery, setAppsQuery] = useState("");
const [automationsFilter, setAutomationsFilter] = useState<AutomationFilter>("all");
const [cliAppsMessage, setCliAppsMessage] = useState<string | null>(null);
@@ -71,10 +66,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
return {
toolsCatalog,
toolsCatalogInvalidation,
apiService,
apiServiceAction,
apiServiceError,
apiServiceLoading,
appsKindFilter,
appsQuery,
automationAction,
@@ -112,10 +103,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
nanobotFeatures,
nanobotFeaturesError,
nanobotFeaturesLoading,
setApiService,
setApiServiceAction,
setApiServiceError,
setApiServiceLoading,
setAppsKindFilter,
setAppsQuery,
setAutomationAction,
@@ -415,10 +415,8 @@ export function useSettingsController({
state: systemState,
featureCatalog,
client,
token,
getToken,
t,
applyPayload,
maybeRestartHostEngine,
setPendingRestartSections,
refreshAutomations,