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 { init } from 'emoji-mart'
import data from '@emoji-mart/data'
import classNames from '@/utils/classnames'
import type { AppIconType } from '@/types/app'
import type { FC } from "react";
import { init } from "emoji-mart";
import data from "@emoji-mart/data";
import classNames from "@/utils/classnames";
import type { AppIconType } from "@/types/app";
init({ data })
init({ data });
export type AnswerIconProps = {
iconType?: AppIconType | null
icon?: string | null
background?: string | null
imageUrl?: string | null
}
iconType?: AppIconType | null;
icon?: string | null;
background?: string | null;
imageUrl: string;
};
const AnswerIcon: FC<AnswerIconProps> = ({
iconType,
icon,
background,
imageUrl,
}) => {
const wrapperClassName = classNames(
'flex',
'items-center',
'justify-center',
'w-full',
'h-full',
'rounded-full',
'border-[0.5px]',
'border-black/5',
'text-xl',
)
const isValidImageIcon = iconType === 'image' && imageUrl
return <div
className={wrapperClassName}
style={{ background: background || '#D5F5F6' }}
>
{isValidImageIcon
? <img src={imageUrl} className="h-full w-full rounded-full" alt="answer icon" />
: (icon && icon !== '') ? <em-emoji id={icon} /> : <em-emoji id='🤖' />
}
</div>
}
"flex",
"items-center",
"justify-center",
"w-full",
"h-full",
"rounded-full",
"border-[0.5px]",
"border-black/5",
"text-xl"
);
return (
<div
className={wrapperClassName}
style={{ background: background || "#D5F5F6" }}
>
<img
src={imageUrl}
className="h-full w-full rounded-full"
alt="answer icon"
/>
</div>
);
};
export default AnswerIcon
export default AnswerIcon;
import { useCallback, useState } from 'react'
import {
RiEditBoxLine,
RiLayoutRight2Line,
RiResetLeftLine,
} from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import {
useChatWithHistoryContext,
} from '../context'
import Operation from './operation'
import ActionButton, { ActionButtonState } from '@/app/components/base/action-button'
import AppIcon from '@/app/components/base/app-icon'
import Tooltip from '@/app/components/base/tooltip'
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])
/*
* @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-22 19:06:23
* @FilePath: \glsk-ai-assistant\app\components\base\chat\chat-with-history\header\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { AVATAR_AI_URL } from "@/app/components/base/chat/constants";
type Props = {
avatar: string;
title: string;
};
const Header = ({ avatar, title }: Props) => {
return (
<>
<div className='flex h-14 shrink-0 items-center justify-between p-3'>
<div className={cn('flex items-center gap-1 transition-all duration-200 ease-in-out', !isSidebarCollapsed && 'user-select-none opacity-0')}>
<ActionButton className={cn(!isSidebarCollapsed && 'cursor-default')} size='l' onClick={() => handleSidebarCollapse(false)}>
<RiLayoutRight2Line className='h-[18px] w-[18px]' />
</ActionButton>
<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}
<div className="flex items-center justify-between h-12 px-8">
<div className=" flex items-center">
<img
src={AVATAR_AI_URL}
className="rounded-full size-8"
alt="answer icon"
/>
)}
{showRename && (
<RenameModal
isShow
onClose={handleCancelRename}
saveLoading={conversationRenaming}
name={showRename?.name || ''}
onSave={handleRename}
/>
)}
</>
)
}
<span className="ml-2 font-bold">{title}</span>
</div>
<img src={avatar} className="rounded-full size-8" alt="answer icon" />
</div>
);
};
export default Header
export default Header;
......@@ -4,7 +4,7 @@ import type { ChatItem } from '../../types'
import { useChatContext } from '../context'
import Button from '@/app/components/base/button'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import {AUTO_INPUT} from "@/app/components/base/chat/constants";
type SuggestedQuestionsProps = {
item: ChatItem
}
......@@ -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 {
isOpeningStatement,
suggestedQuestions,
} = item
if (!isOpeningStatement || !suggestedQuestions?.length)
if (!suggestedQuestions?.length)
return null
return (
......@@ -31,7 +29,7 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({
key={index}
variant='secondary-accent'
className={klassName}
onClick={() => onSend?.(question)}
onClick={() => onSend?.({message:question,type:AUTO_INPUT})}
>
{question}
</Button>),
......
import { memo } from 'react'
import {
RiMicLine,
RiSendPlane2Fill,
} from '@remixicon/react'
import type {
EnableType,
} from '../../types'
import type { Theme } from '../../embedded-chatbot/theme/theme-context'
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'
import { memo } from "react";
import { RiMicLine, RiSendPlane2Fill } from "@remixicon/react";
import type { EnableType } from "../../types";
import type { Theme } from "../../embedded-chatbot/theme/theme-context";
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 = {
fileConfig?: FileUpload
speechToTextConfig?: EnableType
onShowVoiceInput?: () => void
onSend: () => void
theme?: Theme | null
}
const Operation = (
{
ref,
fileConfig,
speechToTextConfig,
onShowVoiceInput,
onSend,
theme,
}: OperationProps & {
ref: React.RefObject<HTMLDivElement>;
},
) => {
fileConfig?: FileUpload;
speechToTextConfig?: EnableType;
onShowVoiceInput?: () => void;
onSend: () => void;
theme?: Theme | null;
};
const Operation = ({
ref,
fileConfig,
speechToTextConfig,
onShowVoiceInput,
onSend,
theme,
}: OperationProps & {
ref: React.RefObject<HTMLDivElement>;
}) => {
return (
<div
className={cn(
'flex shrink-0 items-center justify-end',
)}
>
<div
className='flex items-center pl-1'
ref={ref}
>
<div className='flex items-center space-x-1'>
<div className={cn("flex shrink-0 items-center justify-end")}>
<div className="flex items-center pl-1" ref={ref}>
{/* <div className='flex items-center space-x-1'>
{fileConfig?.enabled && <FileUploaderInChatInput fileConfig={fileConfig} />}
{
speechToTextConfig?.enabled && (
......@@ -54,25 +40,25 @@ const Operation = (
</ActionButton>
)
}
</div>
</div> */}
<Button
className='ml-3 w-8 px-0'
variant='primary'
className="ml-3 w-8 px-0"
variant="primary"
onClick={onSend}
style={
theme
? {
backgroundColor: theme.primaryColor,
}
backgroundColor: theme.primaryColor,
}
: {}
}
>
<RiSendPlane2Fill className='h-4 w-4' />
<RiSendPlane2Fill className="h-4 w-4" />
</Button>
</div>
</div>
)
}
Operation.displayName = 'Operation'
);
};
Operation.displayName = "Operation";
export default memo(Operation)
export default memo(Operation);
import type {
FC,
ReactNode,
} from 'react'
import {
memo,
} from 'react'
import type { ChatItem } from '../types'
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'
import type { FC, ReactNode } from "react";
import { memo } from "react";
import type { ChatItem } from "../types";
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 = {
item: ChatItem
questionIcon?: ReactNode
theme: Theme | null | undefined
}
const Question: FC<QuestionProps> = ({
item,
questionIcon,
theme,
}) => {
const {
content,
message_files,
} = item
item: ChatItem;
questionIcon?: ReactNode;
theme: Theme | null | undefined;
};
const Question: FC<QuestionProps> = ({ item, questionIcon, theme }) => {
const { content, message_files } = item;
return (
<div className='mb-2 flex justify-end pl-14 last:mb-0'>
<div className='group relative mr-4 max-w-full'>
<div className="mb-2 flex justify-end pl-14 last:mb-0">
<div className="group relative mr-4 max-w-full">
<div
className='rounded-2xl bg-[#D1E9FF]/50 px-4 py-3 text-sm text-gray-900'
style={theme?.chatBubbleColorStyle ? CssTransform(theme.chatBubbleColorStyle) : {}}
>
{
!!message_files?.length && (
<FileList
files={message_files}
showDeleteAction={false}
showDownloadAction={true}
/>
)
className="rounded-2xl bg-[#D1E9FF]/50 px-4 py-3 text-sm text-gray-900"
style={
theme?.chatBubbleColorStyle
? CssTransform(theme.chatBubbleColorStyle)
: {}
}
>
{!!message_files?.length && (
<FileList
files={message_files}
showDeleteAction={false}
showDownloadAction={true}
/>
)}
<Markdown content={content} />
</div>
<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 className="mt-1 h-[18px]" />
</div>
<div className="h-10 w-10 shrink-0">{questionIcon}</div>
</div>
)
}
);
};
export default memo(Question)
export default memo(Question);
export const CONVERSATION_ID_INFO = 'conversationIdInfo'
export const UUID_NIL = '00000000-0000-0000-0000-000000000000'
export const CONVERSATION_ID_INFO = "conversationIdInfo";
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 & {
export type ChatItemInTree = {
children?: ChatItemInTree[]
} & ChatItem
export type messageProp = {
message:string
type:string
}
export type OnSend = {
(message: string, files?: FileEntity[]): void
(message: string, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
(message: messageProp, files?: FileEntity[]): void
(message: messageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
}
export type OnRegenerate = (chatItem: ChatItem) => void
......
......@@ -735,5 +735,9 @@ html[data-theme="dark"] {
--color-saas-background: #0b0b0e;
--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
......@@ -735,5 +735,9 @@ html[data-theme="light"] {
--color-saas-background: #fcfcfd;
--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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!