Commit f7d2b090 by 杨明

参数设置

1 parent b0411a55
'use client' /*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-04-24 09:45:21
* @FilePath: \glsk-ai-assistant\app\components\base\answer-icon\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
"use client";
import type { FC } from 'react' import type { FC } from "react";
import { init } from 'emoji-mart' import { init } from "emoji-mart";
import data from '@emoji-mart/data' import data from "@emoji-mart/data";
import classNames from '@/utils/classnames' import classNames from "@/utils/classnames";
import type { AppIconType } from '@/types/app' import type { AppIconType } from "@/types/app";
init({ data }) init({ data });
export type AnswerIconProps = { export type AnswerIconProps = {
iconType?: AppIconType | null iconType?: AppIconType | null;
icon?: string | null icon?: string | null;
background?: string | null background?: string | null;
imageUrl?: string | null imageUrl: string;
} };
const AnswerIcon: FC<AnswerIconProps> = ({ const AnswerIcon: FC<AnswerIconProps> = ({
iconType, iconType,
icon,
background, background,
imageUrl, imageUrl,
}) => { }) => {
const wrapperClassName = classNames( const wrapperClassName = classNames(
'flex', "flex",
'items-center', "items-center",
'justify-center', "justify-center",
'w-full', "w-full",
'h-full', "h-full",
'rounded-full', "rounded-full",
'border-[0.5px]', "border-[0.5px]",
'border-black/5', "border-black/5",
'text-xl', "text-xl"
) );
const isValidImageIcon = iconType === 'image' && imageUrl return (
return <div <div
className={wrapperClassName} className={wrapperClassName}
style={{ background: background || '#D5F5F6' }} style={{ background: background || "#D5F5F6" }}
> >
{isValidImageIcon <img
? <img src={imageUrl} className="h-full w-full rounded-full" alt="answer icon" /> src={imageUrl}
: (icon && icon !== '') ? <em-emoji id={icon} /> : <em-emoji id='🤖' /> className="h-full w-full rounded-full"
} alt="answer icon"
</div> />
} </div>
);
};
export default AnswerIcon export default AnswerIcon;
import { useCallback, useState } from 'react' /*
import { * @Author: yangming@didihu.com.cn yangming@didihu.com.cn
RiEditBoxLine, * @Date: 2025-04-22 09:29:17
RiLayoutRight2Line, * @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
RiResetLeftLine, * @LastEditTime: 2025-04-22 19:06:23
} from '@remixicon/react' * @FilePath: \glsk-ai-assistant\app\components\base\chat\chat-with-history\header\index.tsx
import { useTranslation } from 'react-i18next' * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
import { */
useChatWithHistoryContext, import { AVATAR_AI_URL } from "@/app/components/base/chat/constants";
} from '../context' type Props = {
import Operation from './operation' avatar: string;
import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' title: string;
import AppIcon from '@/app/components/base/app-icon' };
import Tooltip from '@/app/components/base/tooltip' const Header = ({ avatar, title }: Props) => {
import ViewFormDropdown from '@/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown'
import Confirm from '@/app/components/base/confirm'
import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal'
import type { ConversationItem } from '@/models/share'
import cn from '@/utils/classnames'
const Header = () => {
const {
appData,
currentConversationId,
currentConversationItem,
inputsForms,
pinnedConversationList,
handlePinConversation,
handleUnpinConversation,
conversationRenaming,
handleRenameConversation,
handleDeleteConversation,
handleNewConversation,
sidebarCollapseState,
handleSidebarCollapse,
isResponding,
} = useChatWithHistoryContext()
const { t } = useTranslation()
const isSidebarCollapsed = sidebarCollapseState
const isPin = pinnedConversationList.some(item => item.id === currentConversationId)
const [showConfirm, setShowConfirm] = useState<ConversationItem | null>(null)
const [showRename, setShowRename] = useState<ConversationItem | null>(null)
const handleOperate = useCallback((type: string) => {
if (type === 'pin')
handlePinConversation(currentConversationId)
if (type === 'unpin')
handleUnpinConversation(currentConversationId)
if (type === 'delete')
setShowConfirm(currentConversationItem as any)
if (type === 'rename')
setShowRename(currentConversationItem as any)
}, [currentConversationId, currentConversationItem, handlePinConversation, handleUnpinConversation])
const handleCancelConfirm = useCallback(() => {
setShowConfirm(null)
}, [])
const handleDelete = useCallback(() => {
if (showConfirm)
handleDeleteConversation(showConfirm.id, { onSuccess: handleCancelConfirm })
}, [showConfirm, handleDeleteConversation, handleCancelConfirm])
const handleCancelRename = useCallback(() => {
setShowRename(null)
}, [])
const handleRename = useCallback((newName: string) => {
if (showRename)
handleRenameConversation(showRename.id, newName, { onSuccess: handleCancelRename })
}, [showRename, handleRenameConversation, handleCancelRename])
return ( return (
<> <div className="flex items-center justify-between h-12 px-8">
<div className='flex h-14 shrink-0 items-center justify-between p-3'> <div className=" flex items-center">
<div className={cn('flex items-center gap-1 transition-all duration-200 ease-in-out', !isSidebarCollapsed && 'user-select-none opacity-0')}> <img
<ActionButton className={cn(!isSidebarCollapsed && 'cursor-default')} size='l' onClick={() => handleSidebarCollapse(false)}> src={AVATAR_AI_URL}
<RiLayoutRight2Line className='h-[18px] w-[18px]' /> className="rounded-full size-8"
</ActionButton> alt="answer icon"
<div className='mr-1 shrink-0'>
<AppIcon
size='large'
iconType={appData?.site.icon_type}
icon={appData?.site.icon}
background={appData?.site.icon_background}
imageUrl={appData?.site.icon_url}
/>
</div>
{!currentConversationId && (
<div className={cn('system-md-semibold grow truncate text-text-secondary')}>{appData?.site.title}</div>
)}
{currentConversationId && currentConversationItem && isSidebarCollapsed && (
<>
<div className='p-1 text-divider-deep'>/</div>
<Operation
title={currentConversationItem?.name || ''}
isPinned={!!isPin}
togglePin={() => handleOperate(isPin ? 'unpin' : 'pin')}
isShowDelete
isShowRenameConversation
onRenameConversation={() => handleOperate('rename')}
onDelete={() => handleOperate('delete')}
/>
</>
)}
<div className='flex items-center px-1'>
<div className='h-[14px] w-px bg-divider-regular'></div>
</div>
{isSidebarCollapsed && (
<Tooltip
disabled={!!currentConversationId}
popupContent={t('share.chat.newChatTip')}
>
<div>
<ActionButton
size='l'
state={(!currentConversationId || isResponding) ? ActionButtonState.Disabled : ActionButtonState.Default}
disabled={!currentConversationId || isResponding}
onClick={handleNewConversation}
>
<RiEditBoxLine className='h-[18px] w-[18px]' />
</ActionButton>
</div>
</Tooltip>
)}
</div>
<div className='flex items-center gap-1'>
{currentConversationId && (
<Tooltip
popupContent={t('share.chat.resetChat')}
>
<ActionButton size='l' onClick={handleNewConversation}>
<RiResetLeftLine className='h-[18px] w-[18px]' />
</ActionButton>
</Tooltip>
)}
{currentConversationId && inputsForms.length > 0 && (
<ViewFormDropdown />
)}
</div>
</div>
{!!showConfirm && (
<Confirm
title={t('share.chat.deleteConversation.title')}
content={t('share.chat.deleteConversation.content') || ''}
isShow
onCancel={handleCancelConfirm}
onConfirm={handleDelete}
/> />
)} <span className="ml-2 font-bold">{title}</span>
{showRename && ( </div>
<RenameModal <img src={avatar} className="rounded-full size-8" alt="answer icon" />
isShow </div>
onClose={handleCancelRename} );
saveLoading={conversationRenaming} };
name={showRename?.name || ''}
onSave={handleRename}
/>
)}
</>
)
}
export default Header export default Header;
...@@ -4,7 +4,7 @@ import type { ChatItem } from '../../types' ...@@ -4,7 +4,7 @@ import type { ChatItem } from '../../types'
import { useChatContext } from '../context' import { useChatContext } from '../context'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import {AUTO_INPUT} from "@/app/components/base/chat/constants";
type SuggestedQuestionsProps = { type SuggestedQuestionsProps = {
item: ChatItem item: ChatItem
} }
...@@ -17,11 +17,9 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({ ...@@ -17,11 +17,9 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({
const klassName = `mr-1 mt-1 ${isMobile ? 'block overflow-hidden text-ellipsis' : ''} max-w-full shrink-0 last:mr-0` const klassName = `mr-1 mt-1 ${isMobile ? 'block overflow-hidden text-ellipsis' : ''} max-w-full shrink-0 last:mr-0`
const { const {
isOpeningStatement,
suggestedQuestions, suggestedQuestions,
} = item } = item
if (!suggestedQuestions?.length)
if (!isOpeningStatement || !suggestedQuestions?.length)
return null return null
return ( return (
...@@ -31,7 +29,7 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({ ...@@ -31,7 +29,7 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({
key={index} key={index}
variant='secondary-accent' variant='secondary-accent'
className={klassName} className={klassName}
onClick={() => onSend?.(question)} onClick={() => onSend?.({message:question,type:AUTO_INPUT})}
> >
{question} {question}
</Button>), </Button>),
......
import { memo } from 'react' import { memo } from "react";
import { import { RiMicLine, RiSendPlane2Fill } from "@remixicon/react";
RiMicLine, import type { EnableType } from "../../types";
RiSendPlane2Fill, import type { Theme } from "../../embedded-chatbot/theme/theme-context";
} from '@remixicon/react' import Button from "@/app/components/base/button";
import type { import ActionButton from "@/app/components/base/action-button";
EnableType, import { FileUploaderInChatInput } from "@/app/components/base/file-uploader";
} from '../../types' import type { FileUpload } from "@/app/components/base/features/types";
import type { Theme } from '../../embedded-chatbot/theme/theme-context' import cn from "@/utils/classnames";
import Button from '@/app/components/base/button'
import ActionButton from '@/app/components/base/action-button'
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
import type { FileUpload } from '@/app/components/base/features/types'
import cn from '@/utils/classnames'
type OperationProps = { type OperationProps = {
fileConfig?: FileUpload fileConfig?: FileUpload;
speechToTextConfig?: EnableType speechToTextConfig?: EnableType;
onShowVoiceInput?: () => void onShowVoiceInput?: () => void;
onSend: () => void onSend: () => void;
theme?: Theme | null theme?: Theme | null;
} };
const Operation = ( const Operation = ({
{ ref,
ref, fileConfig,
fileConfig, speechToTextConfig,
speechToTextConfig, onShowVoiceInput,
onShowVoiceInput, onSend,
onSend, theme,
theme, }: OperationProps & {
}: OperationProps & { ref: React.RefObject<HTMLDivElement>;
ref: React.RefObject<HTMLDivElement>; }) => {
},
) => {
return ( return (
<div <div className={cn("flex shrink-0 items-center justify-end")}>
className={cn( <div className="flex items-center pl-1" ref={ref}>
'flex shrink-0 items-center justify-end', {/* <div className='flex items-center space-x-1'>
)}
>
<div
className='flex items-center pl-1'
ref={ref}
>
<div className='flex items-center space-x-1'>
{fileConfig?.enabled && <FileUploaderInChatInput fileConfig={fileConfig} />} {fileConfig?.enabled && <FileUploaderInChatInput fileConfig={fileConfig} />}
{ {
speechToTextConfig?.enabled && ( speechToTextConfig?.enabled && (
...@@ -54,25 +40,25 @@ const Operation = ( ...@@ -54,25 +40,25 @@ const Operation = (
</ActionButton> </ActionButton>
) )
} }
</div> </div> */}
<Button <Button
className='ml-3 w-8 px-0' className="ml-3 w-8 px-0"
variant='primary' variant="primary"
onClick={onSend} onClick={onSend}
style={ style={
theme theme
? { ? {
backgroundColor: theme.primaryColor, backgroundColor: theme.primaryColor,
} }
: {} : {}
} }
> >
<RiSendPlane2Fill className='h-4 w-4' /> <RiSendPlane2Fill className="h-4 w-4" />
</Button> </Button>
</div> </div>
</div> </div>
) );
} };
Operation.displayName = 'Operation' Operation.displayName = "Operation";
export default memo(Operation) export default memo(Operation);
import type { import type { FC, ReactNode } from "react";
FC, import { memo } from "react";
ReactNode, import type { ChatItem } from "../types";
} from 'react' import type { Theme } from "../embedded-chatbot/theme/theme-context";
import { import { CssTransform } from "../embedded-chatbot/theme/utils";
memo, import { User } from "@/app/components/base/icons/src/public/avatar";
} from 'react' import { Markdown } from "@/app/components/base/markdown";
import type { ChatItem } from '../types' import { FileList } from "@/app/components/base/file-uploader";
import type { Theme } from '../embedded-chatbot/theme/theme-context'
import { CssTransform } from '../embedded-chatbot/theme/utils'
import { User } from '@/app/components/base/icons/src/public/avatar'
import { Markdown } from '@/app/components/base/markdown'
import { FileList } from '@/app/components/base/file-uploader'
type QuestionProps = { type QuestionProps = {
item: ChatItem item: ChatItem;
questionIcon?: ReactNode questionIcon?: ReactNode;
theme: Theme | null | undefined theme: Theme | null | undefined;
} };
const Question: FC<QuestionProps> = ({ const Question: FC<QuestionProps> = ({ item, questionIcon, theme }) => {
item, const { content, message_files } = item;
questionIcon,
theme,
}) => {
const {
content,
message_files,
} = item
return ( return (
<div className='mb-2 flex justify-end pl-14 last:mb-0'> <div className="mb-2 flex justify-end pl-14 last:mb-0">
<div className='group relative mr-4 max-w-full'> <div className="group relative mr-4 max-w-full">
<div <div
className='rounded-2xl bg-[#D1E9FF]/50 px-4 py-3 text-sm text-gray-900' className="rounded-2xl bg-[#D1E9FF]/50 px-4 py-3 text-sm text-gray-900"
style={theme?.chatBubbleColorStyle ? CssTransform(theme.chatBubbleColorStyle) : {}} style={
> theme?.chatBubbleColorStyle
{ ? CssTransform(theme.chatBubbleColorStyle)
!!message_files?.length && ( : {}
<FileList
files={message_files}
showDeleteAction={false}
showDownloadAction={true}
/>
)
} }
>
{!!message_files?.length && (
<FileList
files={message_files}
showDeleteAction={false}
showDownloadAction={true}
/>
)}
<Markdown content={content} /> <Markdown content={content} />
</div> </div>
<div className='mt-1 h-[18px]' /> <div className="mt-1 h-[18px]" />
</div>
<div className='h-10 w-10 shrink-0'>
{
questionIcon || (
<div className='h-full w-full rounded-full border-[0.5px] border-black/5'>
<User className='h-full w-full' />
</div>
)
}
</div> </div>
<div className="h-10 w-10 shrink-0">{questionIcon}</div>
</div> </div>
) );
} };
export default memo(Question) export default memo(Question);
export const CONVERSATION_ID_INFO = 'conversationIdInfo' export const CONVERSATION_ID_INFO = "conversationIdInfo";
export const UUID_NIL = '00000000-0000-0000-0000-000000000000' export const UUID_NIL = "00000000-0000-0000-0000-000000000000";
export const AVATAR_AI_URL =
"https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-avatar.png";
export const AVATAR_USER_URL =
"https://img02.glsx.com.cn/weapp/resource/saas/ai/user-avatar.png";
export const MAIN_TITLE = "广联AI集市";
export const SELF_INPUT = "0";
export const AUTO_INPUT = "1";
...@@ -68,10 +68,13 @@ export type ChatItem = IChatItem & { ...@@ -68,10 +68,13 @@ export type ChatItem = IChatItem & {
export type ChatItemInTree = { export type ChatItemInTree = {
children?: ChatItemInTree[] children?: ChatItemInTree[]
} & ChatItem } & ChatItem
export type messageProp = {
message:string
type:string
}
export type OnSend = { export type OnSend = {
(message: string, files?: FileEntity[]): void (message: messageProp, files?: FileEntity[]): void
(message: string, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void (message: messageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
} }
export type OnRegenerate = (chatItem: ChatItem) => void export type OnRegenerate = (chatItem: ChatItem) => void
......
...@@ -735,5 +735,9 @@ html[data-theme="dark"] { ...@@ -735,5 +735,9 @@ html[data-theme="dark"] {
--color-saas-background: #0b0b0e; --color-saas-background: #0b0b0e;
--color-saas-pricing-grid-bg: #c8ceda33; --color-saas-pricing-grid-bg: #c8ceda33;
.chat-panel-bg {
background:
url("https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-bg.png") top / 100% 240px no-repeat,
#f5f9ff 0 240px / 100% calc(100% - 240px) no-repeat;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -735,5 +735,9 @@ html[data-theme="light"] { ...@@ -735,5 +735,9 @@ html[data-theme="light"] {
--color-saas-background: #fcfcfd; --color-saas-background: #fcfcfd;
--color-saas-pricing-grid-bg: #c8ceda80; --color-saas-pricing-grid-bg: #c8ceda80;
.chat-panel-bg {
background:
url("https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-bg.png") top / 100% 240px no-repeat,
#f5f9ff 0 240px / 100% calc(100% - 240px) no-repeat;
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!