import { EmptyRequest } from "@shared/proto/index.cline" import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react" import { useEffect, useRef, useState } from "react" import { useTranslation } from "react-i18next" import { RemoteConfigToggle } from "@/components/account/RemoteConfigToggle" import { useClineAuth } from "@/context/ClineAuthContext" import { useExtensionState } from "@/context/ExtensionStateContext" import { StateServiceClient } from "@/services/grpc-client" import Section from "../Section" interface RemoteConfigSectionProps { renderSectionHeader: (tabId: string) => JSX.Element | null } function BaseRemoteConfigSection({ renderSectionHeader, children }: React.PropsWithChildren) { return (
{renderSectionHeader("remote-config")}
{children}
) } const AUTOMATIC_DELAY_MS = 30000 function RefreshButton() { const { t } = useTranslation("settings") const [isLoading, setIsLoading] = useState(false) const [retryIn, setRetryIn] = useState(null) const intervalRef = useRef() useEffect(() => { return () => { if (intervalRef.current) { clearInterval(intervalRef.current) } } }, []) const onRefresh = () => { setIsLoading(true) StateServiceClient.refreshRemoteConfig(EmptyRequest.create()).finally(() => { setIsLoading(false) setRetryIn(AUTOMATIC_DELAY_MS / 1000) intervalRef.current = setInterval(() => { setRetryIn((old) => { if (old && old > 0) return old - 1 intervalRef.current && clearInterval(intervalRef.current) return null }) }, 1000) }) } return ( 0)} onClick={() => onRefresh()}> 刷新 {retryIn && retryIn > 0 && <>({retryIn} 秒后可重试)} ) } interface SettingRowProps { label: string value: string | number | boolean | undefined | null isSecret?: boolean } function SettingRow({ label, value, isSecret }: SettingRowProps) { const { t } = useTranslation("settings") const displayValue = (() => { if (value === undefined || value === null) { return {t("remoteConfig.notConfigured")} } if (typeof value === "boolean") { return value ? ( {t("remoteConfig.enabled")} ) : ( {t("remoteConfig.disabled")} ) } if (isSecret && typeof value === "string" && value.length > 0) { return {"•".repeat(Math.min(value.length, 20))} } return {String(value)} })() const isLongValue = typeof value === "string" && value.length > 25 if (isLongValue) { return (
{label}
{displayValue}
) } return (
{label} {displayValue}
) } interface TestButtonProps { label: string onClick: () => Promise disabled?: boolean successMessage?: string } function TestButton({ label, onClick, disabled, successMessage }: TestButtonProps) { const { t } = useTranslation("settings") const [isLoading, setIsLoading] = useState(false) const [result, setResult] = useState<{ success: boolean; message: string } | null>(null) const timeoutRef = useRef() useEffect(() => { return () => { if (timeoutRef.current) { clearTimeout(timeoutRef.current) } } }, []) const handleClick = async () => { setIsLoading(true) setResult(null) try { await onClick() setResult({ success: true, message: successMessage || t("remoteConfig.success") }) } catch (error) { setResult({ success: false, message: error instanceof Error ? error.message : t("remoteConfig.failed") }) } finally { setIsLoading(false) timeoutRef.current = setTimeout(() => setResult(null), 5000) } } return (
{isLoading ? t("remoteConfig.testing") : label} {result && {result.message}}
) } function OtelSettingsSection() { const { t } = useTranslation("settings") const { remoteConfigSettings } = useExtensionState() const otelEnabled = remoteConfigSettings?.openTelemetryEnabled const hasOtelConfig = otelEnabled !== undefined || remoteConfigSettings?.openTelemetryOtlpEndpoint !== undefined || remoteConfigSettings?.openTelemetryMetricsExporter !== undefined || remoteConfigSettings?.openTelemetryLogsExporter !== undefined if (!hasOtelConfig) { return null } const handleTestOtel = async () => { const response = await StateServiceClient.testOtelConnection(EmptyRequest.create({})) if (!response.success) { throw new Error(response.error || "Test failed") } } return (

OpenTelemetry 配置

{remoteConfigSettings?.openTelemetryOtlpMetricsEndpoint && ( )} {remoteConfigSettings?.openTelemetryOtlpLogsEndpoint && ( )} {remoteConfigSettings?.openTelemetryOtlpHeaders && ( )} {remoteConfigSettings?.openTelemetryMetricExportInterval && ( )} {remoteConfigSettings?.openTelemetryOtlpInsecure !== undefined && ( )} {remoteConfigSettings?.openTelemetryLogBatchSize && ( )} {remoteConfigSettings?.openTelemetryLogBatchTimeout && ( )} {remoteConfigSettings?.openTelemetryLogMaxQueueSize && ( )}
{otelEnabled && (
)}
) } function PromptUploadingSection() { const { t } = useTranslation("settings") const { remoteConfigSettings } = useExtensionState() const blobStoreConfig = remoteConfigSettings?.blobStoreConfig if (!blobStoreConfig) { return null } const handleTestPromptUploading = async () => { const response = await StateServiceClient.testPromptUploading(EmptyRequest.create({})) if (!response.success) { throw new Error(response.error || "Test failed") } } return (

提示词上传配置

{blobStoreConfig.endpoint && } {blobStoreConfig.accountId && ( )} {blobStoreConfig.intervalMs && ( )} {blobStoreConfig.batchSize && ( )} {blobStoreConfig.maxRetries && ( )} {blobStoreConfig.maxQueueSize && ( )}
) } export function RemoteConfigSection({ renderSectionHeader }: RemoteConfigSectionProps) { const { t } = useTranslation("settings") const { remoteConfigSettings, optOutOfRemoteConfig } = useExtensionState() const { activeOrganization } = useClineAuth() if (optOutOfRemoteConfig) { return (

{t("remoteConfig.optedOut")}

) } if (!remoteConfigSettings || Object.keys(remoteConfigSettings).length === 0) { return (

您尚未配置远程配置。请前往{" "} {t("remoteConfig.dashboard")} 进行设置。

) } return (

{t("remoteConfig.settingsManagedByOrg")}

) }