feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
.icon {
svg {
width: 15px;
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { AvatarBackgroundNoticeDot } from '@coze-studio/components';
import { I18n } from '@coze-arch/i18n';
import { IconCozImage } from '@coze-arch/coze-design/icons';
import { Button, Popconfirm } from '@coze-arch/coze-design';
import { IconEdit, IconNo } from '@coze-arch/bot-icons';
import { type BackgroundImageInfo } from '@coze-arch/bot-api/developer_api';
import {
getOriginImageFromBackgroundInfo,
useBackgroundContent,
} from '@coze-agent-ide/chat-background-shared';
import s from './index.module.less';
export interface ChatBackGroundContentProps {
backgroundImageInfoList: BackgroundImageInfo[];
isReadOnly: boolean;
openConfig: () => void;
setBackgroundImageInfoList: (value: BackgroundImageInfo[]) => void;
}
export const ChatBackGroundContent: React.FC<ChatBackGroundContentProps> = ({
backgroundImageInfoList = [],
isReadOnly = false,
openConfig,
setBackgroundImageInfoList,
}) => {
const originImgUrl = getOriginImageFromBackgroundInfo(
backgroundImageInfoList,
).url;
const { handleEdit, showDot, showDotStatus, handleRemove } =
useBackgroundContent({
openConfig,
setBackgroundImageInfoList,
});
return (
<div>
{!originImgUrl && !showDot ? (
<div className="coz-fg-secondary text-lg">{I18n.t('bgi_desc')}</div>
) : (
<div className="p-2 w-full flex items-center justify-between coz-mg-primary hover:coz-mg-primary-hovered rounded-small cursor-pointer">
<div
className="w-8 h-8 rounded-[6px] relative flex items-center justify-center coz-mg-primary"
style={{
backgroundImage: originImgUrl ? `url(${originImgUrl})` : 'none',
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
}}
>
{showDot && !originImgUrl ? <IconCozImage /> : null}
{showDot ? (
<AvatarBackgroundNoticeDot status={showDotStatus} />
) : null}
</div>
{!isReadOnly && (
<div className="flex gap-1 items-center">
<Button
icon={<IconEdit className={s.icon} />}
color="primary"
size={'mini'}
className="!bg-transparent hover:!coz-mg-primary-hovered !p-1 !h-6 coz-fg-secondary"
onClick={handleEdit}
/>
<Popconfirm
content={I18n.t('bgi_remove_popup_content')}
okButtonColor="red"
title={I18n.t('bgi_remove_popup_title')}
okText={I18n.t('Remove')}
onConfirm={handleRemove}
>
<Button
icon={<IconNo className={s.icon} />}
color="primary"
size={'mini'}
className={
'!bg-transparent hover:!coz-mg-primary-hovered !p-1 !h-6 coz-fg-secondary'
}
/>
</Popconfirm>
</div>
)}
</div>
)}
</div>
);
};

View File

@@ -0,0 +1,39 @@
.background-config-modal {
:global {
.semi-modal-content {
padding: 0;
background: var(--coz-bg-primary, #F4F4F6);
.semi-modal-header {
padding: 0 24px;
}
.semi-modal-body {
padding: 0;
}
.semi-modal-footer {
@apply mt-0;
}
}
@media screen and (max-height: 840px) {
.semi-modal-content {
max-height: calc(100vh - 80px);
}
}
}
}
.error-message {
@apply text-left;
@apply coz-bg-max;
margin-bottom: 24px;
color: rgb(255, 68, 30);
.link {
color: #4d53e8;
}
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { type ReactNode, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import {
DotStatus,
useGenerateImageStore,
} from '@coze-studio/bot-detail-store';
import { I18n } from '@coze-arch/i18n';
import { UIModal } from '@coze-arch/bot-semi';
import { type BackgroundImageInfo } from '@coze-arch/bot-api/developer_api';
import { useBackgroundContent } from '@coze-agent-ide/chat-background-shared';
import { BackgroundConfigContent } from '@coze-agent-ide/chat-background-config-content-adapter';
import s from './index.module.less';
export interface UseChatBackgroundUploaderProps {
onSuccess: (value: BackgroundImageInfo[]) => void;
backgroundValue: BackgroundImageInfo[];
getUserId: () => {
userId: string;
};
}
export interface UseChatBackgroundUploaderReturn {
node: ReactNode;
open: () => void;
}
export const useChatBackgroundUploader = (
props: UseChatBackgroundUploaderProps,
): UseChatBackgroundUploaderReturn => {
const [show, setShow] = useState(false);
const { markRead } = useBackgroundContent();
const { imageLoading, gifLoading, setGenerateBackgroundModalByImmer } =
useGenerateImageStore(
useShallow(state => ({
imageLoading: state.generateBackGroundModal.image.loading,
gifLoading: state.generateBackGroundModal.gif.loading,
setGenerateBackgroundModalByImmer:
state.setGenerateBackgroundModalByImmer,
})),
);
const cancel = () => {
// 需要标记消息已读的标记
markRead();
// close Modal
setShow(false);
// 存在正在生图的扭转Badge状态
if (gifLoading || imageLoading) {
setGenerateBackgroundModalByImmer(state => {
if (gifLoading) {
state.gif.dotStatus = DotStatus.Generating;
} else {
state.image.dotStatus = DotStatus.Generating;
}
});
}
};
return {
node: show && (
<UIModal
type="action"
title={I18n.t('bgi_title')}
visible
width={800}
className={s['background-config-modal']}
bodyStyle={{
display: 'flex',
flexDirection: 'column',
}}
centered
footer={null}
onCancel={cancel}
>
<BackgroundConfigContent {...props} cancel={cancel} />
</UIModal>
),
open: () => {
setShow(true);
},
};
};

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {
useChatBackgroundUploader,
type UseChatBackgroundUploaderProps,
} from './chat-background-modal/use-chat-background-uploader';
export { ChatBackGroundContent } from './chat-background-content';

View File

@@ -0,0 +1,18 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference types='@coze-arch/bot-typings' />
declare module 'colorthief';