Dockerfile打包使用pnpm

next.js打包忽略eslint和typescript报错导致打包失败的问题
ant-design引入兼容包,以兼容React19
eslint配置文件由json更换成js
反馈内容由写死的改为获取当前的conversationid会话ID,反馈的用户名称username从cookie里获取
反馈弹窗弹出时使用Promise异步等待如果没有点击确定,则不传递给dify已反馈成功请求
This commit is contained in:
wenyongda 2025-07-14 16:26:45 +08:00
parent d1a47297bf
commit d2d96ab315
18 changed files with 201 additions and 128 deletions

View File

@ -1,28 +0,0 @@
{
"extends": [
"@antfu",
"plugin:react-hooks/recommended"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": [
"error",
"type"
],
"no-console": "off",
"indent": "off",
"@typescript-eslint/indent": [
"error",
2,
{
"SwitchCase": 1,
"flatTernaryExpressions": false,
"ignoredNodes": [
"PropertyDefinition[decorators]",
"TSUnionType",
"FunctionExpression[params]:has(Identifier[decorators])"
]
}
],
"react-hooks/exhaustive-deps": "warn"
}
}

View File

@ -4,9 +4,9 @@ WORKDIR /app
COPY . .
RUN yarn install
RUN yarn build
RUN pnpm install
RUN pnpm build
EXPOSE 3000
CMD ["yarn","start"]
CMD ["pnpm","start"]

View File

@ -1,12 +1,17 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { client, getInfo } from "@/app/api/utils/common";
export async function POST(request: NextRequest, { params }: {
params: { taskId: string }
}) {
const { taskId } = await params
const { user } = getInfo(request)
const { data } = await client.stopChat(taskId, user)
return NextResponse.json(data)
export async function POST(
request: NextRequest,
{
params,
}: {
params: Promise<{ taskId: string }>;
}
) {
const { taskId } = await params;
const { user } = getInfo(request);
const { data } = await client.stopChat(taskId, user);
return NextResponse.json(data);
}

View File

@ -1,19 +1,26 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { client, getInfo } from "@/app/api/utils/common";
export async function POST(request: NextRequest, { params }: {
params: { conversationId: string }
}) {
const body = await request.json()
const {
auto_generate,
name,
} = body
const { conversationId } = await params
const { user } = getInfo(request)
export async function POST(
request: NextRequest,
{
params,
}: {
params: Promise<{ conversationId: string }>;
}
) {
const body = await request.json();
const { auto_generate, name } = body;
const { conversationId } = await params;
const { user } = getInfo(request);
// auto generate name
const { data } = await client.renameConversation(conversationId, name, user, auto_generate)
return NextResponse.json(data)
const { data } = await client.renameConversation(
conversationId,
name,
user,
auto_generate
);
return NextResponse.json(data);
}

View File

@ -1,13 +1,18 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { client, getInfo } from "@/app/api/utils/common";
export async function DELETE(request: NextRequest, { params }: {
params: { conversationId: string }
}) {
const { conversationId } = await params
const { user } = await getInfo(request)
export async function DELETE(
request: NextRequest,
{
params,
}: {
params: Promise<{ conversationId: string }>;
}
) {
const { conversationId } = await params;
const { user } = await getInfo(request);
const { data } = await client.deleteConversation(conversationId, user)
return NextResponse.json(data)
}
const { data } = await client.deleteConversation(conversationId, user);
return NextResponse.json(data);
}

View File

@ -1,16 +1,19 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { client, getInfo } from "@/app/api/utils/common";
export async function POST(request: NextRequest, { params }: {
params: { messageId: string }
}) {
const body = await request.json()
const {
rating,
} = body
const { messageId } = await params
const { user } = getInfo(request)
const { data } = await client.messageFeedback(messageId, rating, user)
return NextResponse.json(data)
export async function POST(
request: NextRequest,
{
params,
}: {
params: Promise<{ messageId: string }>;
}
) {
const body = await request.json();
const { rating } = body;
const { messageId } = await params;
const { user } = getInfo(request);
const { data } = await client.messageFeedback(messageId, rating, user);
return NextResponse.json(data);
}

View File

@ -1,10 +1,17 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { client, getInfo } from "@/app/api/utils/common";
export async function GET(request: NextRequest, params: { messageId: string }) {
const { messageId } = await params
const { user } = getInfo(request)
const { data }: any = await client.getSuggested(messageId, user,)
return NextResponse.json(data)
export async function GET(
request: NextRequest,
{
params,
}: {
params: Promise<{ messageId: string }>;
}
) {
const { messageId } = await params;
const { user } = getInfo(request);
const { data }: any = await client.getSuggested(messageId, user);
return NextResponse.json(data);
}

View File

@ -1,20 +1,30 @@
import { type NextRequest } from 'next/server'
import { ChatClient } from 'dify-client-plus'
import { v4 } from 'uuid'
import { API_KEY, API_URL } from '@/config'
import { type NextRequest } from "next/server";
import { ChatClient } from "dify-client-plus";
import { v4 } from "uuid";
import { API_KEY, API_URL } from "@/config";
export const getInfo = (request: NextRequest) => {
const username = request.cookies.get('username')?.value || 'no-user'
const sessionId = request.cookies.get('session_id')?.value || v4()
const user = `${username}`
const username = request.cookies.get("username")?.value || "no-user";
const sessionId = request.cookies.get("session_id")?.value || v4();
const user = `${username}`;
return {
sessionId,
user,
}
}
};
};
export const setSession = (sessionId: string) => {
return { 'Set-Cookie': `session_id=${sessionId}` }
}
return { "Set-Cookie": `session_id=${sessionId}` };
};
export const client = new ChatClient(API_KEY, API_URL || undefined)
export const client = new ChatClient(API_KEY, API_URL || undefined);
export function getCookieValue(cookieName: string): string | null {
const cookies = document.cookie.split("; ").reduce((acc, cookie) => {
const [name, value] = cookie.split("=");
acc[name] = value;
return acc;
}, {} as Record<string, string>);
return cookies[cookieName] || null;
}

View File

@ -11,7 +11,7 @@ import { ToastContext } from '@/app/components/base/toast'
import Loading from '@/app/components/base/loading'
// import { fetchAgentLogDetail } from '@/service/log'
// TODO
const fetchAgentLogDetail = () => {
const fetchAgentLogDetail: any = (data: any) => {
console.log('TODO MARS')
}

View File

@ -39,8 +39,7 @@ const AnswerIcon: FC<AnswerIconProps> = ({
>
{isValidImageIcon
? <img src={imageUrl} className="w-full h-full rounded-full" alt="answer icon" />
: (icon && icon !== '') ? <em-emoji id={icon} /> : <em-emoji id='🤖' />
}
: (icon && icon !== '') ? (<em-emoji id={icon} />) : (<em-emoji id='🤖' />) }
</div>
}

View File

@ -46,7 +46,7 @@ export type ChatWithHistoryContextValue = {
isMobile: boolean
isInstalledApp: boolean
appId?: string
handleFeedback: (messageId: string, feedback: Feedback) => void
handleFeedback: (messageId: string, feedback: Feedback) => Promise<boolean>
currentChatInstanceRef: RefObject<{ handleStop: () => void }>
themeBuilder?: ThemeBuilder
}
@ -73,7 +73,7 @@ export const ChatWithHistoryContext = createContext<ChatWithHistoryContextValue>
chatShouldReloadKey: '',
isMobile: false,
isInstalledApp: false,
handleFeedback: () => { },
handleFeedback: () => new Promise(() => { }),
currentChatInstanceRef: { current: { handleStop: () => { } } },
})
export const useChatWithHistoryContext = () => useContext(ChatWithHistoryContext)

View File

@ -4,7 +4,7 @@ import useSWR from "swr";
import { useLocalStorageState } from "ahooks";
import { produce } from "immer";
import { message } from "antd";
import { client, getInfo } from "@/app/api/utils/common";
import { client, getCookieValue } from "@/app/api/utils/common";
import type { Callback, ChatConfig, ChatItem, Feedback } from "../types";
import { CONVERSATION_ID_INFO } from "../constants";
import { buildChatItemTree } from "../utils";
@ -537,12 +537,19 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
setCurrentConversationIdForFeedback,
] = useState<string | null>(null);
const [resolveFeedback, setResolveFeedback] = useState<(value: boolean | PromiseLike<boolean>) => void | null>(null);
const handleFeedback = useCallback(
(messageId: string, feedback: Feedback, conversationId: string) => {
setCurrentMessageId(messageId);
setCurrentFeedback(feedback);
setCurrentConversationIdForFeedback(conversationId);
setIsFeedbackModalVisible(true);
return new Promise<boolean>((resolve) => {
console.log('handleFeedback', messageId, feedback, conversationId);
setCurrentMessageId(messageId);
setCurrentFeedback(feedback);
setCurrentConversationIdForFeedback(conversationId);
setIsFeedbackModalVisible(true);
setResolveFeedback(() => resolve);
})
},
[]
);
@ -557,9 +564,9 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
const requestBody = {
operationType: selectedOption, // 0 或 1
feedbackText, // 用户反馈建议
conversationId: '89fba8a7-e4e2-4167-8b7c-b3c103797053', // 会话 ID
conversationId: currentConversationId, // 会话 ID
messageId: currentMessageId, // 消息 ID
username: "user_admin", // 用户名
username: getCookieValue('username'), // 用户名
};
// 调用 Java 接口
@ -578,15 +585,20 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
await updateFeedback(
{
url: `/messages/${currentMessageId}/feedbacks`,
body: { rating: currentFeedback.rating },
body: { rating: currentFeedback!.rating },
},
isInstalledApp,
appId
// isInstalledApp,
// appId
);
// 显示成功通知
notify({ type: "success", message: t("common.api.success") });
if (resolveFeedback) {
resolveFeedback(true); // 用户取消了反馈
setResolveFeedback(null);
}
// 关闭对话框
setIsFeedbackModalVisible(false);
} catch (error) {
@ -597,7 +609,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
[
currentMessageId,
currentFeedback,
currentConversationIdForFeedback,
currentConversationId,
isInstalledApp,
appId,
notify,
@ -649,7 +661,13 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
<FeedbackModal
open={isFeedbackModalVisible}
onOk={handleFeedbackSubmit}
onCancel={() => setIsFeedbackModalVisible(false)}
onCancel={() => {
if (resolveFeedback) {
resolveFeedback(false); // 用户取消了反馈
setResolveFeedback(null);
}
setIsFeedbackModalVisible(false)
}}
/>
),
};

View File

@ -75,8 +75,9 @@ const Operation: FC<OperationProps> = ({
if (!config?.supportFeedback || !onFeedback)
return
await onFeedback?.(id, { rating })
setLocalFeedback({ rating })
if (await onFeedback?.(id, { rating })) {
setLocalFeedback({ rating })
}
}
const operationWidth = useMemo(() => {
@ -138,7 +139,7 @@ const Operation: FC<OperationProps> = ({
)}
</div>
)}
{/*
{/*
{(!isOpeningStatement && config?.supportAnnotation && config.annotation_reply?.enabled) && (
<AnnotationCtrlBtn
appId={config?.appId || ''}

View File

@ -60,7 +60,7 @@ export type ChatProps = {
onAnnotationAdded?: (annotationId: string, authorName: string, question: string, answer: string, index: number) => void
onAnnotationRemoved?: (index: number) => void
chatNode?: ReactNode
onFeedback?: (messageId: string, feedback: Feedback) => void
onFeedback?: (messageId: string, feedback: Feedback) => Promise<boolean>
chatAnswerContainerInner?: string
hideProcessDetail?: boolean
hideLogModal?: boolean

View File

@ -4,6 +4,7 @@ import React from 'react'
import type { IMainProps } from '@/app/components'
import ChatWithHistoryWrapWithCheckToken from '@/app/components/chat-with-history'
import '@ant-design/v5-patch-for-react-19';
const App: FC<IMainProps> = ({
params,

32
eslint.config.js Normal file
View File

@ -0,0 +1,32 @@
const antfu = require('@antfu/eslint-config').default
// module.exports = antfu()
export default {
extends: [
'@antfu',
'plugin:react-hooks/recommended',
],
rules: {
'@typescript-eslint/consistent-type-definitions': [
'error',
'type',
],
'no-console': 'off',
'indent': 'off',
'@typescript-eslint/indent': [
'error',
2,
{
SwitchCase: 1,
flatTernaryExpressions: false,
ignoredNodes: [
'PropertyDefinition[decorators]',
'TSUnionType',
'FunctionExpression[params]:has(Identifier[decorators])',
],
},
],
'react-hooks/exhaustive-deps': 'warn',
},
}

View File

@ -1,22 +1,34 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
reactStrictMode: true,
// 压缩优化Next.js 13+默认启用SWC无需手动配置
compress: true,
// 图片优化
images: {
formats: ["image/avif", "image/webp"],
domains: ["cdn.yourdomain.com"],
formats: ['image/avif', 'image/webp'],
domains: ['cdn.yourdomain.com'],
},
// 修正后的开发指示器配置
devIndicators: {
position: "bottom-right", // 新版统一用position
position: 'bottom-right', // 新版统一用position
},
// 页面扩展名
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
// 路由重写
async rewrites() {
@ -27,6 +39,6 @@ const nextConfig = {
},
]
},
};
}
module.exports = nextConfig;
module.exports = nextConfig

View File

@ -37,6 +37,7 @@
]
},
"dependencies": {
"@ant-design/v5-patch-for-react-19": "^1.0.3",
"@emoji-mart/data": "^1.2.1",
"@floating-ui/react": "^0.27.3",
"@formatjs/intl-localematcher": "^0.5.10",