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,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;

View File

@@ -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;

View File

@@ -0,0 +1,5 @@
const { defineConfig } = require('@coze-arch/stylelint-config');
module.exports = defineConfig({
extends: [],
});

View File

@@ -0,0 +1,16 @@
# @coze-agent-ide/chat-answer-action
> Project template for react component with storybook.
## Features
- [x] eslint & ts
- [x] esm bundle
- [x] umd bundle
- [x] storybook
## Commands
- init: `rush update`
- dev: `npm run dev`
- build: `npm run build`

View File

@@ -0,0 +1,12 @@
{
"operationSettings": [
{
"operationName": "test:cov",
"outputFolderNames": ["coverage"]
},
{
"operationName": "ts-check",
"outputFolderNames": ["dist"]
}
]
}

View File

@@ -0,0 +1,7 @@
const { defineConfig } = require('@coze-arch/eslint-config');
module.exports = defineConfig({
packageRoot: __dirname,
preset: 'web',
rules: {},
});

View File

@@ -0,0 +1,52 @@
{
"name": "@coze-agent-ide/chat-answer-action-adapter",
"version": "0.0.1",
"description": "agent ide chat answer action adapter",
"license": "Apache-2.0",
"author": "gaoyuanhan.duty@bytedance.com",
"maintainers": [],
"main": "src/index.ts",
"scripts": {
"build": "exit 0",
"lint": "eslint ./ --cache",
"test": "vitest --run --passWithNoTests",
"test:cov": "npm run test -- --coverage"
},
"dependencies": {
"@coze-agent-ide/space-bot": "workspace:*",
"@coze-arch/bot-semi": "workspace:*",
"@coze-arch/bot-tea": "workspace:*",
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
"@coze-arch/i18n": "workspace:*",
"@coze-common/chat-answer-action": "workspace:*",
"@coze-common/chat-area": "workspace:*",
"@coze-common/chat-core": "workspace:*",
"@coze-studio/bot-detail-store": "workspace:*",
"ahooks": "^3.7.8",
"classnames": "^2.3.2",
"dayjs": "^1.11.7"
},
"devDependencies": {
"@coze-arch/bot-typings": "workspace:*",
"@coze-arch/eslint-config": "workspace:*",
"@coze-arch/stylelint-config": "workspace:*",
"@coze-arch/ts-config": "workspace:*",
"@coze-arch/vitest-config": "workspace:*",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@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"
}
}

View File

@@ -0,0 +1,324 @@
/* stylelint-disable */
.collapse-block {
display: flex;
flex-direction: column;
width: 100%;
margin-bottom: 16px;
&:last-child {
margin-bottom: 16px !important;
}
}
.collapse-block-close {
margin-bottom: 8px;
}
.collapse-info-row {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
margin-bottom: 16px;
font-size: 12px;
font-weight: 400;
line-height: 16px;
color: var(--light-usage-text-color-text-1, rgba(28, 31, 35, 80%));
/* 133.333% */
}
.collapse-row-close {
margin-bottom: 0;
}
.collapse-content {
width: 100%;
padding: 16px;
font-size: 12px;
font-weight: 400;
line-height: 16px;
color: #fff;
word-wrap: break-word;
background: #22262b;
border-radius: 8px;
.collapse-title {
font-weight: 600;
line-height: 16px;
/* 133.333% */
}
:global {
.markdown-body p>code {
color: #a5d6ff;
background-color: transparent;
}
}
}
.assistant-pop {
font-size: 14px;
font-weight: 400;
line-height: 22px;
color: var(--light-color-grey-grey-8, #2e3238);
background: #f7f7fa;
border-radius: 12px;
}
.assistant-pop-img {
width: 100%;
}
.user-pop {
font-weight: 400;
line-height: 22px;
color: #fff;
white-space: pre-wrap;
background: #6e75ed;
}
.image-pop {
display: flex;
align-items: flex-end;
}
.image-wrapper {
width: 160px;
height: 120px;
padding: 0 !important;
border-radius: 0 !important;
:global {
.semi-image-status {
background: transparent;
}
}
img {
cursor: zoom-in;
// object-position: 50% 50%;
position: absolute;
bottom: 0;
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}
}
.pop {
overflow: hidden;
max-width: 100%;
padding: 8px 12px;
font-size: 14px;
word-wrap: break-word;
border-radius: 6px;
&.assistant-pop-card {
width: 400px;
padding: 0;
background-color: transparent;
border-radius: 0;
.assistant-pop-card-empty {
padding-bottom: 24px;
background-color: #fff;
border-radius: 8px;
}
}
&.assistant-pop-full-screen-card {
width: 100%;
}
}
.onboarding-default {
display: flex;
flex-direction: column;
justify-content: center;
width: 100%;
height: 100%;
}
// .onboarding-wrapper {
// transition: height 0.5s ease-out;
// white-space: break-spaces;
.onboarding-avatar {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.bot-avatar {
width: 96px;
height: 96px;
border-radius: 16px;
}
.bot-title {
margin-top: 8px;
margin-bottom: 26px;
font-size: 14px;
font-weight: 600;
line-height: 20px;
color: var(--Light-usage-text---color-text-1, rgba(29, 28, 35, 80%));
}
}
// }
.message-row {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 100%;
margin-bottom: 24px;
}
.pop-show-info {
margin-bottom: 6px;
}
.message-info {
cursor: pointer;
display: flex;
column-gap: 10px;
justify-content: space-between;
width: 100%;
height: 32px;
margin-bottom: 8px;
padding-top: 8px;
}
.message-info-user-message-only {
column-gap: 0;
justify-content: flex-start;
}
.message-info-text {
display: flex;
flex-shrink: 0;
align-items: center;
font-size: 12px;
font-weight: 400;
line-height: 16px;
}
.chunk-message-content {
flex: 1;
width: calc(100% - 32px);
>div:last-child {
margin-bottom: 0;
}
&.multi {
margin-top: 24px;
&:first-child {
margin-top: 0;
}
}
}
.chunk {
position: relative;
display: flex;
flex-direction: column;
margin-bottom: 4px;
padding: 10px;
border: 1px solid transparent;
}
.chunk-hover {
border: 1px solid rgba(28, 29, 35, 8%);
border-radius: 8px;
}
.remove-button {
cursor: pointer;
position: absolute;
top: -7px;
right: -7px;
flex-shrink: 0;
color: rgba(255, 68, 30, 100%);
svg {
width: 14px;
height: 14px;
}
}
.vertical-divider {
display: block;
width: 1px;
height: 8px;
margin: 0 8px;
background: var(--light-color-grey-grey-4, #888d92);
}
.responding-suggestions {
padding-top: 10px;
padding-left: 10px;
>div {
padding: 16px;
background-color: transparent;
border: 1px solid rgba(46, 50, 56, 13%);
}
}
.debug-description {
:global {
.semi-descriptions-item-td {
width: 100%;
}
}
}
.agent-info {
margin-bottom: 8px;
font-size: 12px;
line-height: 16px;
color: rgba(29, 28, 35, 60%);
}
.assistant_image_box {
picture>img {
cursor: zoom-in;
}
}
.suggestion-question-list {
display: flex;
flex-direction: column;
}

View File

@@ -0,0 +1,177 @@
/*
* 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 { useEffect, useRef } from 'react';
import dayjs from 'dayjs';
import classNames from 'classnames';
import { useHover } from 'ahooks';
import { useChatBackgroundState } from '@coze-studio/bot-detail-store';
import {
type ComponentTypesMap,
useMessageBoxContext,
} from '@coze-common/chat-area';
import {
CopyTextMessage,
DeleteMessage,
RegenerateMessage,
QuoteMessage,
} from '@coze-common/chat-answer-action';
import { I18n } from '@coze-arch/i18n';
import { Space, UITag } from '@coze-arch/bot-semi';
import s from './index.module.less';
const LOG_ID_TIME_PREFIX_DIGITS = 14;
export const isQueryWithinOneWeek = (logId: string) => {
const logIdTimeString = logId.slice(0, LOG_ID_TIME_PREFIX_DIGITS);
const logIdTime = dayjs(logIdTimeString, 'YYYYMMDDHHmmss');
if (!logIdTime.isValid()) {
return false;
}
const oneWeekAgoTime = dayjs().subtract(1, 'week');
// 最近 6 天,从 0 点开始
return logIdTime.isAfter(oneWeekAgoTime, 'day');
};
const VerticalDivider = () => <div className={s['vertical-divider']} />;
const ActionBarWithMultiActions = () => {
const { message, meta } = useMessageBoxContext();
const ref = useRef<HTMLDivElement>(null);
const hover = useHover(ref);
const { role, type } = message;
const { time_cost, token } = message.extra_info;
const isLatestGroupAnswer = meta?.isFromLatestGroup;
const isTrigger = type === 'task_manual_trigger';
const isUserMessage = role === 'user';
const { showBackground, backgroundModeClassName: buttonClass } =
useChatBackgroundState();
const isEmptyTimeCost = time_cost === '';
const isEmptyToken = token === '';
const isTimeCostAndTokenNotEmpty = !isEmptyTimeCost && !isEmptyToken;
const isShowVerticalDivider = isTimeCostAndTokenNotEmpty || isTrigger;
return (
<>
<div
className={classNames(
s['message-info'],
isUserMessage && s['message-info-user-message-only'],
)}
ref={ref}
>
<div
data-testid="chat-area.answer-action.left-content"
className={classNames(
s['message-info-text'],
'coz-fg-secondary',
showBackground && '!coz-fg-images-secondary',
)}
>
<>
{!isTrigger && !isEmptyTimeCost && (
<Space spacing={4}>
<div>{time_cost}s</div>
</Space>
)}
{isTrigger ? (
<Space spacing={4}>
<UITag color="cyan">
{I18n.t('platfrom_trigger_dialog_trigge_icon')}
</UITag>
</Space>
) : null}
{isShowVerticalDivider ? <VerticalDivider /> : null}
{!isEmptyToken && (
<div>
<Space spacing={4}>
<div>{token} Tokens</div>
</Space>
</div>
)}
</>
</div>
{hover || isLatestGroupAnswer || isUserMessage ? (
<Space
spacing={4}
data-testid="chat-area.answer-action.right-content"
>
<CopyTextMessage className={buttonClass} />
<QuoteMessage className={buttonClass} />
<RegenerateMessage className={buttonClass} />
<DeleteMessage className={classNames(buttonClass)} />
</Space>
) : null}
</div>
</>
);
};
/**
* 带有标题的footer
* 1、中间消息用于展示Plugin、workflow的中间调用状态
*/
const ActionBarWithTitle = () => {
const { message } = useMessageBoxContext();
const { message_title } = message.extra_info;
const { showBackground } = useChatBackgroundState();
return (
<div className={s['message-info']}>
<div
className={classNames(
s['message-info-text'],
'coz-fg-secondary',
showBackground && '!coz-fg-images-secondary',
)}
>
{message_title}
</div>
</div>
);
};
export const MessageBoxActionBarAdapter: ComponentTypesMap['messageActionBarFooter'] =
({ refreshContainerWidth }) => {
const { message, meta } = useMessageBoxContext();
const isLastMessage = meta.isGroupLastMessage;
const messageTitle = message?.extra_info.message_title;
useEffect(() => {
refreshContainerWidth();
}, []);
if (isLastMessage) {
return <ActionBarWithMultiActions />;
}
if (messageTitle) {
return <ActionBarWithTitle />;
}
return null;
};
MessageBoxActionBarAdapter.displayName = 'MessageBoxActionBar';

View File

@@ -0,0 +1,17 @@
/*
* 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 { MessageBoxActionBarAdapter } from './components/message-box-action-bar';

View File

@@ -0,0 +1,17 @@
/*
* 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' />

View File

@@ -0,0 +1,55 @@
{
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"jsx": "react-jsx",
"lib": ["DOM", "ESNext"],
"target": "ES2020",
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
},
"include": ["src"],
"exclude": ["node_modules", "dist"],
"references": [
{
"path": "../../arch/bot-tea/tsconfig.build.json"
},
{
"path": "../../arch/bot-typings/tsconfig.build.json"
},
{
"path": "../../arch/i18n/tsconfig.build.json"
},
{
"path": "../../common/chat-area/chat-answer-action/tsconfig.build.json"
},
{
"path": "../../common/chat-area/chat-area/tsconfig.build.json"
},
{
"path": "../../common/chat-area/chat-core/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": "../space-bot/tsconfig.build.json"
},
{
"path": "../../studio/stores/bot-detail/tsconfig.build.json"
}
]
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"exclude": ["**/*"],
"compilerOptions": {
"composite": true
},
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.misc.json"
}
]
}

View File

@@ -0,0 +1,20 @@
{
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist",
"jsx": "react-jsx",
"lib": ["DOM", "ESNext"],
"module": "ESNext",
"target": "ES2020",
"moduleResolution": "bundler"
},
"include": ["__tests__", "vitest.config.ts", "stories"],
"exclude": ["./dist"],
"references": [
{
"path": "./tsconfig.build.json"
}
]
}

View 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',
});