mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 01:56:53 +00:00
Add a Bun script to apply and normalize AGPL copyright headers across the default frontend source files. The script keeps headers idempotent, upgrades existing headers to the 2023-2026 QuantumNous range, and is exposed through `bun run copyright` for future maintenance.
168 lines
5.4 KiB
TypeScript
Vendored
168 lines
5.4 KiB
TypeScript
Vendored
/*
|
|
Copyright (C) 2023-2026 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
import { useEffect } from 'react'
|
|
import * as z from 'zod'
|
|
import { useForm } from 'react-hook-form'
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { Button } from '@/components/ui/button'
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form'
|
|
import { Switch } from '@/components/ui/switch'
|
|
import { Textarea } from '@/components/ui/textarea'
|
|
import { SettingsSection } from '../components/settings-section'
|
|
import { useUpdateOption } from '../hooks/use-update-option'
|
|
|
|
const sensitiveSchema = z.object({
|
|
CheckSensitiveEnabled: z.boolean(),
|
|
CheckSensitiveOnPromptEnabled: z.boolean(),
|
|
SensitiveWords: z.string().optional(),
|
|
})
|
|
|
|
type SensitiveFormValues = z.infer<typeof sensitiveSchema>
|
|
|
|
type SensitiveWordsSectionProps = {
|
|
defaultValues: SensitiveFormValues
|
|
}
|
|
|
|
export function SensitiveWordsSection({
|
|
defaultValues,
|
|
}: SensitiveWordsSectionProps) {
|
|
const { t } = useTranslation()
|
|
const updateOption = useUpdateOption()
|
|
const form = useForm<SensitiveFormValues>({
|
|
resolver: zodResolver(sensitiveSchema),
|
|
defaultValues,
|
|
})
|
|
|
|
useEffect(() => {
|
|
form.reset(defaultValues)
|
|
}, [defaultValues, form])
|
|
|
|
const onSubmit = async (values: SensitiveFormValues) => {
|
|
const updates = Object.entries(values).filter(
|
|
([key, value]) =>
|
|
value !== defaultValues[key as keyof SensitiveFormValues]
|
|
)
|
|
|
|
for (const [key, value] of updates) {
|
|
await updateOption.mutateAsync({ key, value: value ?? '' })
|
|
}
|
|
}
|
|
|
|
return (
|
|
<SettingsSection
|
|
title={t('Sensitive Words')}
|
|
description={t('Configure keyword filtering for prompts and responses.')}
|
|
>
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className='space-y-6'>
|
|
<div className='space-y-4'>
|
|
<FormField
|
|
control={form.control}
|
|
name='CheckSensitiveEnabled'
|
|
render={({ field }) => (
|
|
<FormItem className='flex flex-row items-center justify-between rounded-lg border p-4'>
|
|
<div className='space-y-0.5'>
|
|
<FormLabel className='text-base'>
|
|
{t('Enable filtering')}
|
|
</FormLabel>
|
|
<FormDescription>
|
|
{t(
|
|
'Blocks messages when sensitive keywords are detected.'
|
|
)}
|
|
</FormDescription>
|
|
</div>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
/>
|
|
</FormControl>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name='CheckSensitiveOnPromptEnabled'
|
|
render={({ field }) => (
|
|
<FormItem className='flex flex-row items-center justify-between rounded-lg border p-4'>
|
|
<div className='space-y-0.5'>
|
|
<FormLabel className='text-base'>
|
|
{t('Inspect user prompts')}
|
|
</FormLabel>
|
|
<FormDescription>
|
|
{t(
|
|
'When enabled, prompts are scanned before reaching upstream models.'
|
|
)}
|
|
</FormDescription>
|
|
</div>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
/>
|
|
</FormControl>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name='SensitiveWords'
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('Blocked keywords')}</FormLabel>
|
|
<FormControl>
|
|
<Textarea
|
|
rows={12}
|
|
placeholder={t('Enter one keyword per line')}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
{t(
|
|
'Each line represents one keyword. Leave blank to disable the list but keep the switch states.'
|
|
)}
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<Button type='submit' disabled={updateOption.isPending}>
|
|
{updateOption.isPending
|
|
? t('Saving...')
|
|
: t('Save sensitive words')}
|
|
</Button>
|
|
</form>
|
|
</Form>
|
|
</SettingsSection>
|
|
)
|
|
}
|