diff --git a/packages/frontend/core/src/components/root-app-sidebar/user-info/ai-usage.tsx b/packages/frontend/core/src/components/root-app-sidebar/user-info/ai-usage.tsx --- a/packages/frontend/core/src/components/root-app-sidebar/user-info/ai-usage.tsx +++ b/packages/frontend/core/src/components/root-app-sidebar/user-info/ai-usage.tsx @@ -1,8 +1,10 @@ import { + ServerService, SubscriptionService, UserCopilotQuotaService, } from '@affine/core/modules/cloud'; import { WorkspaceDialogService } from '@affine/core/modules/dialogs'; +import { ServerDeploymentType } from '@affine/graphql'; import { useI18n } from '@affine/i18n'; import { useLiveData, useService } from '@toeverything/infra'; import { cssVar } from '@toeverything/theme'; @@ -15,6 +17,12 @@ import * as styles from './index.css'; export const AIUsage = () => { const t = useI18n(); const copilotQuotaService = useService(UserCopilotQuotaService); + const serverService = useService(ServerService); + const isSelfhosted = useLiveData( + serverService.server.config$.selector( + c => c.type === ServerDeploymentType.Selfhosted + ) + ); const subscriptionService = useService(SubscriptionService); useEffect(() => { @@ -49,6 +55,24 @@ export const AIUsage = () => { }); }, [workspaceDialogService]); + if (isSelfhosted) { + return ( +
+
+
+ {t['com.affine.selfhosted-ai-usage.title']()} +
+
+
+ {t['com.affine.selfhosted-ai-usage.description']()} +
+
+ ); + } + if (loading) { if (loadError) console.error(loadError); return null; diff --git a/packages/frontend/core/src/desktop/dialogs/setting/account-setting/ai-usage-panel.tsx b/packages/frontend/core/src/desktop/dialogs/setting/account-setting/ai-usage-panel.tsx --- a/packages/frontend/core/src/desktop/dialogs/setting/account-setting/ai-usage-panel.tsx +++ b/packages/frontend/core/src/desktop/dialogs/setting/account-setting/ai-usage-panel.tsx @@ -5,7 +5,7 @@ import { SubscriptionService, UserCopilotQuotaService, } from '@affine/core/modules/cloud'; -import { SubscriptionPlan } from '@affine/graphql'; +import { ServerDeploymentType, SubscriptionPlan } from '@affine/graphql'; import { useI18n } from '@affine/i18n'; import { track } from '@affine/track'; import { useLiveData, useService } from '@toeverything/infra'; @@ -26,6 +26,11 @@ export const AIUsagePanel = ({ const hasPaymentFeature = useLiveData( serverService.server.features$.map(f => f?.payment) ); + const isSelfhosted = useLiveData( + serverService.server.config$.selector( + c => c.type === ServerDeploymentType.Selfhosted + ) + ); const subscriptionService = useService(SubscriptionService); const aiSubscription = useLiveData(subscriptionService.subscription.ai$); useEffect(() => { @@ -53,6 +58,17 @@ export const AIUsagePanel = ({ track.$.settingsPanel.accountUsage.viewPlans({ plan: SubscriptionPlan.AI }); }, [onChangeSettingState]); + if (isSelfhosted) { + return ( + + ); + } + if (loading) { if (loadError) { return ( diff --git a/packages/frontend/core/src/mobile/dialogs/setting/user-usage/index.tsx b/packages/frontend/core/src/mobile/dialogs/setting/user-usage/index.tsx --- a/packages/frontend/core/src/mobile/dialogs/setting/user-usage/index.tsx +++ b/packages/frontend/core/src/mobile/dialogs/setting/user-usage/index.tsx @@ -5,6 +5,8 @@ import { UserCopilotQuotaService, UserQuotaService, } from '@affine/core/modules/cloud'; +import { ServerDeploymentType } from '@affine/graphql'; +import { useI18n } from '@affine/i18n'; import { useLiveData, useService } from '@toeverything/infra'; import { cssVar } from '@toeverything/theme'; import { cssVarV2 } from '@toeverything/theme/v2'; @@ -30,16 +32,20 @@ const Progress = ({ desc, color, children, + hideBar = false, + 'data-testid': testId, }: { name: ReactNode; desc: ReactNode; percent?: number; color?: string | null; children?: React.ReactNode; + hideBar?: boolean; + 'data-testid'?: string; }) => { return ( -
+
{name} {desc}
@@ -46 +52 @@ const Progress = ({ - {children ?? ( + {!hideBar && (children ?? ( @@ -56 +62 @@ const Progress = ({ - )} + ))} @@ -110,6 +116,13 @@ const CloudUsage = () => { }; const AiUsage = () => { + const t = useI18n(); const copilotQuotaService = useService(UserCopilotQuotaService); + const serverService = useService(ServerService); + const isSelfhosted = useLiveData( + serverService.server.config$.selector( + c => c.type === ServerDeploymentType.Selfhosted + ) + ); const copilotActionLimit = useLiveData( copilotQuotaService.copilotQuota.copilotActionLimit$ @@ -124,6 +137,17 @@ const AiUsage = () => { copilotQuotaService.copilotQuota.revalidate(); }, [copilotQuotaService]); + if (isSelfhosted) { + return ( + + ); + } + if (loading || loadError) { return ; } diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.json --- a/packages/frontend/i18n/src/resources/en.json +++ b/packages/frontend/i18n/src/resources/en.json @@ -931,6 +931,8 @@ "com.affine.payment.ai.usage.purchase-button-label": "Purchase", "com.affine.payment.ai.usage.used-caption": "Times used", "com.affine.payment.ai.usage.used-detail": "{{used}}/{{limit}} times", + "com.affine.selfhosted-ai-usage.title": "Self-hosted AI", + "com.affine.selfhosted-ai-usage.description": "Provider and server limits may apply.", "com.affine.payment.subscription-status.active": "Active", "com.affine.payment.subscription-status.past-due": "Past-due bill", "com.affine.payment.subscription-status.trialing": "Trialing", diff --git a/packages/frontend/i18n/src/resources/ru.json b/packages/frontend/i18n/src/resources/ru.json --- a/packages/frontend/i18n/src/resources/ru.json +++ b/packages/frontend/i18n/src/resources/ru.json @@ -848,6 +848,8 @@ "com.affine.payment.ai.usage.purchase-button-label": "Улучшить", "com.affine.payment.ai.usage.used-caption": "Использовалось", "com.affine.payment.ai.usage.used-detail": "\n{{used}}/{{limit}} Раз", + "com.affine.selfhosted-ai-usage.title": "AI на своём сервере", + "com.affine.selfhosted-ai-usage.description": "Могут действовать ограничения провайдера и сервера.", "com.affine.payment.subscription-status.active": "Активный", "com.affine.payment.subscription-status.past-due": "Просроченный счёт", "com.affine.payment.subscription-status.trialing": "Пробный период",