Sfoglia il codice sorgente

implementation ai integration disable mode

Shun Miyazawa 1 anno fa
parent
commit
98c5be2380

+ 1 - 0
apps/app/.env.development

@@ -30,3 +30,4 @@ QUESTIONNAIRE_SERVER_ORIGIN="http://host.docker.internal:3003"
 # AUDIT_LOG_ACTION_GROUP_SIZE=SMALL
 # AUDIT_LOG_ADDITIONAL_ACTIONS=
 # AUDIT_LOG_EXCLUDE_ACTIONS=
+AI_ENABLED = true

+ 2 - 1
apps/app/public/static/locales/en_US/admin.json

@@ -1134,6 +1134,7 @@
     "do_not_have_admin_permission": "Users without administrative rights cannot access the administration screen"
   },
   "ai_integration": {
-    "ai_integration": "AI Integration"
+    "ai_integration": "AI Integration",
+    "disable_mode_explanation": "Currently, AI integration is disabled. To enable it, please set the environment variable <code>AI_ENABLED</code> to true."
   }
 }

+ 2 - 1
apps/app/public/static/locales/fr_FR/admin.json

@@ -1133,6 +1133,7 @@
     "do_not_have_admin_permission": "Seul les administrateurs peuvent accéder à cette page."
   },
   "ai_integration": {
-    "ai_integration": "Intégration de l'IA"
+    "ai_integration": "Intégration de l'IA",
+    "disable_mode_explanation": "Actuellement, l'intégration de l'IA est désactivée. Pour l'activer, veuillez définir la variable d'environnement <code>AI_ENABLED</code> sur true"
   }
 }

+ 2 - 1
apps/app/public/static/locales/ja_JP/admin.json

@@ -1144,6 +1144,7 @@
     "do_not_have_admin_permission": "管理者権限のないユーザーでは管理画面にはアクセスできません"
   },
   "ai_integration": {
-    "ai_integration": "AI 連携"
+    "ai_integration": "AI 連携",
+    "disable_mode_explanation": "現在、AI 連携は無効になっています。有効にする場合は環境変数 <code>AI_ENABLED</code> を true に設定してください。"
   }
 }

+ 2 - 1
apps/app/public/static/locales/zh_CN/admin.json

@@ -1143,6 +1143,7 @@
     "do_not_have_admin_permission": "没有管理权限的用户无法访问管理屏幕"
   },
   "ai_integration": {
-    "ai_integration": "AI 集成"
+    "ai_integration": "AI 集成",
+    "disable_mode_explanation": "目前,AI 集成已禁用。要启用它,请将环境变量 <code>AI_ENABLED</code> 设置为 true”"
   }
 }

+ 28 - 0
apps/app/src/client/components/Admin/AiIntegration/AiIntegrationDisableMode.tsx

@@ -0,0 +1,28 @@
+import type { FC } from 'react';
+import React from 'react';
+
+import { useTranslation } from 'react-i18next';
+
+export const AiIntegrationDisableMode: FC = () => {
+  const { t } = useTranslation('admin');
+
+  return (
+    <div className="ccontainer-lg">
+      <div className="container">
+        <div className="row justify-content-md-center">
+          <div className="col-md-6 mt-5">
+            <div className="text-center">
+              {/* error icon large */}
+              <h1><span className="material-symbols-outlined">error</span></h1>
+              <h1 className="text-center">{t('ai_integration.ai_integration')}</h1>
+              <h3
+                // eslint-disable-next-line react/no-danger
+                dangerouslySetInnerHTML={{ __html: t('ai_integration.disable_mode_explanation') }}
+              />
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  );
+};

+ 11 - 1
apps/app/src/pages/admin/ai-integration.page.tsx

@@ -13,9 +13,12 @@ import { retrieveServerSideProps } from '../../utils/admin-page-util';
 
 const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
 const ForbiddenPage = dynamic(() => import('~/client/components/Admin/ForbiddenPage').then(mod => mod.ForbiddenPage), { ssr: false });
+const AiIntegrationDisableMode = dynamic(
+  () => import('~/client/components/Admin/AiIntegration/AiIntegrationDisableMode').then(mod => mod.AiIntegrationDisableMode), { ssr: false },
+);
 
 type Props = CommonProps & {
-  //
+  aiEnabled: boolean,
 };
 
 const AdminAiIntegrationPage: NextPage<Props> = (props) => {
@@ -33,6 +36,10 @@ const AdminAiIntegrationPage: NextPage<Props> = (props) => {
       <Head>
         <title>{headTitle}</title>
       </Head>
+      {props.aiEnabled
+        ? <></> // TODO: implement admin page
+        : <AiIntegrationDisableMode />
+      }
     </AdminLayout>
   );
 };
@@ -40,6 +47,9 @@ const AdminAiIntegrationPage: NextPage<Props> = (props) => {
 const injectServerConfigurations = async(context: GetServerSidePropsContext, props: Props): Promise<void> => {
   const req: CrowiRequest = context.req as CrowiRequest;
   const { crowi } = req;
+  const { configManager } = crowi;
+
+  props.aiEnabled = configManager.getConfig('crowi', 'app:aiEnabled');
 };
 
 export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {

+ 12 - 0
apps/app/src/server/service/config-loader.ts

@@ -736,6 +736,18 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type: ValueType.NUMBER,
     default: 172800, // 2 days
   },
+  AI_ENABLED: {
+    ns: 'crowi',
+    key: 'app:aiEnabled',
+    type: ValueType.BOOLEAN,
+    default: false,
+  },
+  AI_SERVICE_TYPE: {
+    ns: 'crowi',
+    key: 'app:aiServiceType',
+    type: ValueType.STRING,
+    default: null,
+  },
   OPENAI_API_KEY: {
     ns: 'crowi',
     key: 'app:openaiApiKey',