Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

7.4 KB
Raw Blame
/*
 *  Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import { FilterFormField, FormFieldType } from '@/components/dynamic-form';
import { TFunction } from 'i18next';

export const seafileConstant = (t: TFunction) => [
  {
    label: t('setting.dataSourceFieldSeafileServerUrl'),
    name: 'config.seafile_url',
    type: FormFieldType.Text,
    required: true,
    placeholder: 'https://seafile.example.com',
    tooltip: t('setting.seafileUrlTip'),
  },
  {
    label: t('setting.dataSourceFieldSyncScope'),
    name: 'config.sync_scope',
    type: FormFieldType.Segmented,
    options: [
      { label: t('setting.dataSourceOptionEntireAccount'), value: 'account' },
      { label: t('setting.dataSourceOptionSingleLibrary'), value: 'library' },
      {
        label: t('setting.dataSourceOptionSpecificDirectory'),
        value: 'directory',
      },
    ],
    tooltip: t('setting.seafileSyncScopeTip'),
  },

  {
    name: FilterFormField + '.account-tip',
    label: ' ',
    type: FormFieldType.Custom,
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope ?? 'account';
      return scope === 'account';
    },
    render: () => (
      <div className="text-sm text-text-secondary bg-bg-card border border-border-button rounded-md px-3 py-2">
        {t('setting.seafileAccountScopeTip')}
      </div>
    ),
  },
  {
    label: t('setting.dataSourceFieldAccountApiToken'),
    name: 'config.credentials.seafile_token',
    type: FormFieldType.Password,
    required: false,
    defaultValue: '',
    tooltip: t('setting.seafileTokenTip'),
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope ?? 'account';
      return scope === 'account';
    },
    customValidate: (val: string, formValues: any) => {
      const scope = formValues?.config?.sync_scope ?? 'account';
      if ((!val || val.trim() === '') && scope === 'account') {
        return t('setting.seafileValidationAccountTokenRequired');
      }
      return true;
    },
  },
  {
    label: t('setting.dataSourceFieldIncludeSharedLibraries'),
    name: 'config.include_shared',
    type: FormFieldType.Checkbox,
    required: false,
    defaultValue: true,
    tooltip: t('setting.seafileIncludeSharedTip'),
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope ?? 'account';
      return scope === 'account';
    },
  },

  {
    // Contextual info panel explaining the two-token choice
    name: FilterFormField + '.token-tip',
    label: ' ',
    type: FormFieldType.Custom,
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      return scope === 'library' || scope === 'directory';
    },
    render: () => (
      <div className="text-sm text-text-secondary bg-bg-card border border-border-button rounded-md px-3 py-2 space-y-1">
        <p className="font-medium text-text-primary">
          {t('setting.seafileTokenPanelHeading')}
        </p>
        <ul className="list-disc list-inside space-y-0.5">
          <li>
            <span className="font-medium">
              {t('setting.dataSourceFieldAccountApiToken')}
            </span>
            {' ' + t('setting.seafileTokenPanelAccountBullet')}
          </li>
          <li>
            <span className="font-medium">
              {t('setting.dataSourceFieldLibraryToken')}
            </span>
            {' ' + t('setting.seafileTokenPanelLibraryBullet')}
          </li>
        </ul>
      </div>
    ),
  },
  {
    label: t('setting.dataSourceFieldAccountApiToken'),
    name: 'config.credentials.seafile_token',
    type: FormFieldType.Password,
    required: false,
    tooltip: t('setting.seafileTokenTip'),
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      return scope === 'library' || scope === 'directory';
    },
  },
  {
    label: t('setting.dataSourceFieldLibraryToken'),
    name: 'config.credentials.repo_token',
    type: FormFieldType.Password,
    required: false,
    tooltip: t('setting.seafileRepoTokenTip'),
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      return scope === 'library' || scope === 'directory';
    },
    customValidate: (val: string, formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      const accountToken = formValues?.config?.credentials?.seafile_token;
      if (
        !val &&
        !accountToken &&
        (scope === 'library' || scope === 'directory')
      ) {
        return t('setting.seafileValidationTokenRequired');
      }
      return true;
    },
  },
  {
    label: t('setting.dataSourceFieldLibraryId'),
    name: 'config.repo_id',
    type: FormFieldType.Text,
    required: false,
    placeholder: 'e.g. 7a9e1b3c-4d5f-6a7b-8c9d-0e1f2a3b4c5d',
    tooltip: t('setting.seafileRepoIdTip'),
    shouldRender: (formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      return scope === 'library' || scope === 'directory';
    },
    customValidate: (val: string, formValues: any) => {
      const scope = formValues?.config?.sync_scope;
      if (!val && (scope === 'library' || scope === 'directory')) {
        return t('setting.seafileValidationLibraryIdRequired');
      }
      return true;
    },
  },

  {
    label: t('setting.dataSourceFieldDirectoryPath'),
    name: 'config.sync_path',
    type: FormFieldType.Text,
    required: false,
    placeholder: '/Documents/Reports',
    tooltip: t('setting.seafileSyncPathTip'),
    shouldRender: (formValues: any) => {
      return formValues?.config?.sync_scope === 'directory';
    },
    customValidate: (val: string, formValues: any) => {
      if (!val && formValues?.config?.sync_scope === 'directory') {
        return t('setting.seafileValidationDirectoryPathRequired');
      }
      return true;
    },
  },

  {
    label: t('setting.dataSourceFieldBatchSize'),
    name: 'config.batch_size',
    type: FormFieldType.Number,
    required: false,
    placeholder: '100',
    tooltip: t('setting.seafileBatchSizeTip'),
  },

  {
    label: t('setting.dataSourceFieldAccountApiToken'),
    name: 'config.credentials.seafile_token',
    type: FormFieldType.Password,
    required: false,
    hidden: true,
  },
  {
    label: t('setting.dataSourceFieldLibraryToken'),
    name: 'config.credentials.repo_token',
    type: FormFieldType.Password,
    required: false,
    hidden: true,
  },
  {
    label: t('setting.dataSourceFieldLibraryId'),
    name: 'config.repo_id',
    type: FormFieldType.Text,
    required: false,
    hidden: true,
  },
  {
    label: t('setting.dataSourceFieldDirectoryPath'),
    name: 'config.sync_path',
    type: FormFieldType.Text,
    required: false,
    hidden: true,
  },
  {
    label: t('setting.dataSourceFieldIncludeSharedLibraries'),
    name: 'config.include_shared',
    type: FormFieldType.Checkbox,
    required: false,
    hidden: true,
  },
];