feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { mergeConfig } from 'vite';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
viteFinal: config =>
|
||||
mergeConfig(config, {
|
||||
plugins: [
|
||||
svgr({
|
||||
svgrOptions: {
|
||||
native: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
export default config;
|
||||
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/agent-ide/chat-background/README.md
Normal file
16
frontend/packages/agent-ide/chat-background/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# chat-background
|
||||
|
||||
bot-editor设置背景图
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
68
frontend/packages/agent-ide/chat-background/package.json
Normal file
68
frontend/packages/agent-ide/chat-background/package.json
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "@coze-agent-ide/chat-background",
|
||||
"version": "0.0.1",
|
||||
"description": "chat background setting",
|
||||
"license": "Apache-2.0",
|
||||
"author": "zhangnan.615@bytedance.com",
|
||||
"maintainers": [],
|
||||
"main": "src/index.tsx",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-agent-ide/chat-background-config-content-adapter": "workspace:*",
|
||||
"@coze-agent-ide/chat-background-shared": "workspace:*",
|
||||
"@douyinfe/semi-icons": "^2.36.0",
|
||||
"ahooks": "^3.7.8",
|
||||
"classnames": "^2.3.2",
|
||||
"colorthief": "~2.4.0",
|
||||
"cropperjs": "^1.5.12",
|
||||
"immer": "^10.0.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"nanoid": "^4.0.2",
|
||||
"react-cropper": "^2.3.3",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-api": "workspace:*",
|
||||
"@coze-arch/bot-error": "workspace:*",
|
||||
"@coze-arch/bot-flags": "workspace:*",
|
||||
"@coze-arch/bot-hooks": "workspace:*",
|
||||
"@coze-arch/bot-icons": "workspace:*",
|
||||
"@coze-arch/bot-semi": "workspace:*",
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/bot-utils": "workspace:*",
|
||||
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/i18n": "workspace:*",
|
||||
"@coze-arch/logger": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@coze-common/chat-uikit": "workspace:*",
|
||||
"@coze-studio/bot-detail-store": "workspace:*",
|
||||
"@coze-studio/bot-utils": "workspace:*",
|
||||
"@coze-studio/components": "workspace:*",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/lodash-es": "^4.17.10",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"stylelint": "^15.11.0",
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
},
|
||||
"// deps": "immer@^10.0.3 为脚本自动补齐,请勿改动"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
.icon {
|
||||
svg {
|
||||
width: 15px;
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
};
|
||||
21
frontend/packages/agent-ide/chat-background/src/index.tsx
Normal file
21
frontend/packages/agent-ide/chat-background/src/index.tsx
Normal 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';
|
||||
18
frontend/packages/agent-ide/chat-background/src/typings.d.ts
vendored
Normal file
18
frontend/packages/agent-ide/chat-background/src/typings.d.ts
vendored
Normal 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';
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"compilerOptions": {
|
||||
"types": [],
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-error/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-flags/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-hooks/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-utils/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/logger/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../chat-background-config-content-adapter/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../chat-background-shared/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../common/chat-area/chat-uikit/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../components/bot-icons/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../components/bot-semi/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/stylelint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/vitest-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/bot-utils/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/components/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/stores/bot-detail/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/agent-ide/chat-background/tsconfig.json
Normal file
15
frontend/packages/agent-ide/chat-background/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
],
|
||||
"exclude": ["**/*"]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"include": ["__tests__", "stories", "vitest.config.ts", "tailwind.config.ts"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"types": ["vitest/globals"],
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true
|
||||
}
|
||||
}
|
||||
22
frontend/packages/agent-ide/chat-background/vitest.config.ts
Normal file
22
frontend/packages/agent-ide/chat-background/vitest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user