This commit is contained in:
heheer 2025-12-17 14:51:50 +08:00
parent f41786f5a7
commit c940705930
No known key found for this signature in database
GPG Key ID: 37DCB43201661540
10 changed files with 76 additions and 58 deletions

View File

@ -251,10 +251,3 @@ export type TemplateTypeSchemaType = {
typeId: string;
typeOrder: number;
};
export type ChatVisibilityConfigType = {
showNodeStatus: boolean;
responseDetail: boolean;
showFullText: boolean;
showRawSource: boolean;
};

View File

@ -1,5 +1,7 @@
import { z } from 'zod';
import type { HistoryItemType } from '../../core/chat/type.d';
import type { OutLinkSchema } from './type.d';
import type { OutLinkSchema, PlaygroundVisibilityConfigType } from './type.d';
import { PlaygroundVisibilityConfigSchema } from './type.d';
export type AuthOutLinkInitProps = {
outLinkUid: string;
@ -10,3 +12,20 @@ export type AuthOutLinkLimitProps = AuthOutLinkChatProps & { outLink: OutLinkSch
export type AuthOutLinkResponse = {
uid: string;
};
export const UpdatePlaygroundVisibilityConfigBodySchema = PlaygroundVisibilityConfigSchema.extend({
appId: z.string().min(1, 'App ID is required')
});
export type UpdatePlaygroundVisibilityConfigBody = z.infer<
typeof UpdatePlaygroundVisibilityConfigBodySchema
>;
export const PlaygroundVisibilityConfigQuerySchema = z.object({
appId: z.string().min(1, 'App ID is required')
});
export type PlaygroundVisibilityConfigQuery = z.infer<typeof PlaygroundVisibilityConfigQuerySchema>;
export const PlaygroundVisibilityConfigResponseSchema = PlaygroundVisibilityConfigSchema;
export type PlaygroundVisibilityConfigResponse = z.infer<
typeof PlaygroundVisibilityConfigResponseSchema
>;

View File

@ -6,5 +6,5 @@ export enum PublishChannelEnum {
dingtalk = 'dingtalk',
wecom = 'wecom',
officialAccount = 'official_account',
chat = 'chat'
playground = 'playground'
}

View File

@ -106,3 +106,10 @@ export type OutLinkEditType<T = undefined> = {
// config for specific platform
app?: T;
};
export type PlaygroundVisibilityConfigType = {
showNodeStatus: boolean;
responseDetail: boolean;
showFullText: boolean;
showRawSource: boolean;
};

View File

@ -5,28 +5,31 @@ import { useForm } from 'react-hook-form';
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { getChatVisibilityConfig, updateChatVisibilityConfig } from '@/web/support/outLink/api';
import type { ChatVisibilityConfigType } from '@fastgpt/global/core/app/type';
import {
getPlaygroundVisibilityConfig,
updatePlaygroundVisibilityConfig
} from '@/web/support/outLink/api';
import type { PlaygroundVisibilityConfigType } from '@fastgpt/global/support/outLink/type';
const defaultChatVisibilityForm: ChatVisibilityConfigType = {
const defaultPlaygroundVisibilityForm: PlaygroundVisibilityConfigType = {
showNodeStatus: true,
responseDetail: true,
showFullText: true,
showRawSource: true
};
const ChatVisibilityConfig = ({ appId }: { appId: string }) => {
const PlaygroundVisibilityConfig = ({ appId }: { appId: string }) => {
const { t } = useTranslation();
const { register, watch, setValue, reset } = useForm({
defaultValues: defaultChatVisibilityForm
defaultValues: defaultPlaygroundVisibilityForm
});
const responseDetail = watch('responseDetail');
const showFullText = watch('showFullText');
const showRawSource = watch('showRawSource');
useRequest2(() => getChatVisibilityConfig({ appId }), {
useRequest2(() => getPlaygroundVisibilityConfig({ appId }), {
onSuccess: (data) => {
reset({
showNodeStatus: data.showNodeStatus,
@ -39,8 +42,8 @@ const ChatVisibilityConfig = ({ appId }: { appId: string }) => {
});
const { runAsync: saveConfig } = useRequest2(
async (data: ChatVisibilityConfigType) => {
return await updateChatVisibilityConfig({
async (data: PlaygroundVisibilityConfigType) => {
return await updatePlaygroundVisibilityConfig({
appId,
...data
});
@ -139,4 +142,4 @@ const ChatVisibilityConfig = ({ appId }: { appId: string }) => {
);
};
export default ChatVisibilityConfig;
export default PlaygroundVisibilityConfig;

View File

@ -19,7 +19,7 @@ const FeiShu = dynamic(() => import('./FeiShu'));
const DingTalk = dynamic(() => import('./DingTalk'));
const Wecom = dynamic(() => import('./Wecom'));
const OffiAccount = dynamic(() => import('./OffiAccount'));
const Chat = dynamic(() => import('./Chat'));
const Playground = dynamic(() => import('./Playground'));
const OutLink = () => {
const { t } = useTranslation();
@ -91,7 +91,7 @@ const OutLink = () => {
icon: 'core/chat/sidebar/home',
title: t('common:navbar.Chat'),
desc: t('app:publish.chat_desc'),
value: PublishChannelEnum.chat,
value: PublishChannelEnum.playground,
isProFn: false
}
]);
@ -149,7 +149,7 @@ const OutLink = () => {
{linkType === PublishChannelEnum.dingtalk && <DingTalk appId={appId} />}
{linkType === PublishChannelEnum.wecom && <Wecom appId={appId} />}
{linkType === PublishChannelEnum.officialAccount && <OffiAccount appId={appId} />}
{linkType === PublishChannelEnum.chat && <Chat appId={appId} />}
{linkType === PublishChannelEnum.playground && <Playground appId={appId} />}
</Flex>
</Box>
);

View File

@ -2,32 +2,31 @@ import { MongoOutLink } from '@fastgpt/service/support/outLink/schema';
import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant';
import type { ApiRequestProps } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry';
import type { ChatVisibilityConfigType } from '@fastgpt/global/core/app/type';
export type ChatVisibilityConfigQuery = {
appId: string;
};
export type ChatVisibilityConfigResponse = ChatVisibilityConfigType;
import {
type PlaygroundVisibilityConfigQuery,
type PlaygroundVisibilityConfigResponse,
PlaygroundVisibilityConfigQuerySchema,
PlaygroundVisibilityConfigResponseSchema
} from '@fastgpt/global/support/outLink/api';
async function handler(
req: ApiRequestProps<{}, ChatVisibilityConfigQuery>
): Promise<ChatVisibilityConfigResponse> {
const { appId } = req.query;
req: ApiRequestProps<{}, PlaygroundVisibilityConfigQuery>
): Promise<PlaygroundVisibilityConfigResponse> {
const { appId } = PlaygroundVisibilityConfigQuerySchema.parse(req.query);
const existingConfig = await MongoOutLink.findOne(
{
appId,
type: PublishChannelEnum.chat
type: PublishChannelEnum.playground
},
'showNodeStatus responseDetail showFullText showRawSource'
).lean();
return {
return PlaygroundVisibilityConfigResponseSchema.parse({
showNodeStatus: existingConfig?.showNodeStatus ?? true,
responseDetail: existingConfig?.responseDetail ?? true,
showFullText: existingConfig?.showFullText ?? true,
showRawSource: existingConfig?.showRawSource ?? true
};
});
}
export default NextAPI(handler);

View File

@ -4,17 +4,14 @@ import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant';
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
import type { ApiRequestProps } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry';
import {
type UpdatePlaygroundVisibilityConfigBody,
UpdatePlaygroundVisibilityConfigBodySchema
} from '@fastgpt/global/support/outLink/api';
export type UpdateChatVisibilityConfigBody = {
appId: string;
showNodeStatus?: boolean;
responseDetail?: boolean;
showFullText?: boolean;
showRawSource?: boolean;
};
async function handler(req: ApiRequestProps<UpdateChatVisibilityConfigBody, {}>) {
const { appId, showNodeStatus, responseDetail, showFullText, showRawSource } = req.body;
async function handler(req: ApiRequestProps<UpdatePlaygroundVisibilityConfigBody, {}>) {
const { appId, showNodeStatus, responseDetail, showFullText, showRawSource } =
UpdatePlaygroundVisibilityConfigBodySchema.parse(req.body);
const { teamId, tmbId } = await authApp({
req,
@ -23,18 +20,18 @@ async function handler(req: ApiRequestProps<UpdateChatVisibilityConfigBody, {}>)
per: ManagePermissionVal
});
await MongoOutLink.findOneAndUpdate(
{ appId, type: PublishChannelEnum.chat },
await MongoOutLink.updateOne(
{ appId, type: PublishChannelEnum.playground },
{
$setOnInsert: {
shareId: `chat-${appId}`,
shareId: `playground-${appId}`,
teamId,
tmbId,
name: 'Home Chat'
name: 'Playground Chat'
},
$set: {
appId,
type: PublishChannelEnum.chat,
type: PublishChannelEnum.playground,
showNodeStatus: showNodeStatus ?? true,
responseDetail: responseDetail ?? true,
showFullText: showFullText ?? true,

View File

@ -174,7 +174,7 @@ export async function getServerSideProps(context: any) {
const config = await MongoOutLink.findOne(
{
appId,
type: PublishChannelEnum.chat
type: PublishChannelEnum.playground
},
'showNodeStatus responseDetail showFullText showRawSource'
).lean();

View File

@ -1,8 +1,8 @@
import type {
ChatVisibilityConfigQuery,
ChatVisibilityConfigResponse
} from '@/pages/api/support/outLink/chat/config';
import type { UpdateChatVisibilityConfigBody } from '@/pages/api/support/outLink/chat/update';
PlaygroundVisibilityConfigQuery,
PlaygroundVisibilityConfigResponse,
UpdatePlaygroundVisibilityConfigBody
} from '@fastgpt/global/support/outLink/api';
import { GET, POST, DELETE } from '@/web/common/api/request';
import type {
OutlinkAppType,
@ -41,12 +41,12 @@ export function updateShareChat<T extends OutlinkAppType>(data: OutLinkEditType<
return POST<string>(`/support/outLink/update`, data);
}
export function getChatVisibilityConfig(data: ChatVisibilityConfigQuery) {
return GET<ChatVisibilityConfigResponse>('/support/outLink/chat/config', data);
export function getPlaygroundVisibilityConfig(data: PlaygroundVisibilityConfigQuery) {
return GET<PlaygroundVisibilityConfigResponse>('/support/outLink/playground/config', data);
}
export function updateChatVisibilityConfig(data: UpdateChatVisibilityConfigBody) {
return POST<string>(`/support/outLink/chat/update`, data);
export function updatePlaygroundVisibilityConfig(data: UpdatePlaygroundVisibilityConfigBody) {
return POST<string>(`/support/outLink/playground/update`, data);
}
// /**