diff --git a/client/app/factory/edit/[id]/page.tsx b/client/app/factory/edit/[id]/page.tsx index 6dfbb7d0..05edab00 100644 --- a/client/app/factory/edit/[id]/page.tsx +++ b/client/app/factory/edit/[id]/page.tsx @@ -5,6 +5,7 @@ import BotCreateFrom from '@/app/factory/edit/components/BotCreateFrom'; import { toast, ToastContainer } from 'react-toastify'; import BackIcon from '@/public/icons/BackIcon'; import { CopyToClipboard } from 'react-copy-to-clipboard'; +import { useRouter } from 'next/navigation'; import { useBotConfigGenerator, useBotConfig, @@ -20,12 +21,13 @@ import ChatIcon from '@/public/icons/ChatIcon'; import ConfigIcon from '@/public/icons/ConfigIcon'; import SaveIcon from '@/public/icons/SaveIcon'; import { useBot } from '@/app/contexts/BotContext'; - -import 'react-toastify/dist/ReactToastify.css'; +import useUser from '@/app/hooks/useUser'; import Knowledge from '../components/Knowledge'; import KnowledgeBtn from '../components/KnowledgeBtn'; import { BotTaskProvider } from '../components/TaskContext'; +import 'react-toastify/dist/ReactToastify.css'; + const API_HOST = process.env.NEXT_PUBLIC_API_DOMAIN; enum VisibleTypeEnum { BOT_CONFIG = 'BOT_CONFIG', @@ -37,13 +39,21 @@ enum ConfigTypeEnum { } export default function Edit({ params }: { params: { id: string } }) { const { botProfile, setBotProfile } = useBot(); - + const { data: user, status } = useUser(); + const router = useRouter(); const [activeTab, setActiveTab] = React.useState( ConfigTypeEnum.CHAT_CONFIG, ); const [visibleType, setVisibleType] = React.useState( VisibleTypeEnum.BOT_CONFIG, ); + const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN; + + useEffect(() => { + if (!user || status !== 'success' || user.id.startsWith('client|')) { + router.push(`${apiDomain}/api/auth/login`); + } + }, [user, status]); const { updateBot: onUpdateBot, diff --git a/server/agent/prompts/bot_builder.py b/server/agent/prompts/bot_builder.py index 688987e6..05757bb9 100644 --- a/server/agent/prompts/bot_builder.py +++ b/server/agent/prompts/bot_builder.py @@ -28,6 +28,13 @@ - Can only create a Q&A bot or update the configuration of the bot based on the GitHub repository information provided by the user. - During the process of creating a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository. - When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission. +- Whenever you encounter a 401 or Unauthorized error that seems to be an authentication failure, please inform the user in the language they are using to converse with you. For example: + +If user is conversing with you in Chinese: +“您必须先使用 GitHub 登录 Petercat 才能使用此功能。[登录地址](https://api.petercat.ai/api/auth/login) + +If user is conversing with you in English: +“You must log in to Petercat using GitHub before accessing this feature.” [Login URL](https://api.petercat.ai/api/auth/login) """ EDIT_PROMPT = """ @@ -45,11 +52,17 @@ - Can only update the configuration of the bot based on the GitHub repository information provided by the user. - During the process of a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository. - When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission. + +If user is conversing with you in Chinese: +“您必须先使用 GitHub 登录 Petercat 才能使用此功能。[登录地址](https://api.petercat.ai/api/auth/login) + +If user is conversing with you in English: +“You must log in to Petercat using GitHub before accessing this feature.” [Login URL](https://api.petercat.ai/api/auth/login) """ def generate_prompt_by_user_id(user_id: str, bot_id: Optional[str]): if bot_id: - return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id) + return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id) else: - return CREATE_PROMPT.format(user_id=user_id) + return CREATE_PROMPT.format(user_id=user_id)