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/plugin-area-adapter
> 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,58 @@
{
"name": "@coze-agent-ide/plugin-area-adapter",
"version": "0.0.1",
"description": "agent ide plugin area 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/bot-plugin": "workspace:*",
"@coze-agent-ide/plugin-content-adapter": "workspace:*",
"@coze-agent-ide/plugin-risk-warning": "workspace:*",
"@coze-agent-ide/tool": "workspace:*",
"@coze-agent-ide/tool-config": "workspace:*",
"@coze-arch/bot-api": "workspace:*",
"@coze-arch/bot-hooks": "workspace:*",
"@coze-arch/bot-semi": "workspace:*",
"@coze-arch/bot-space-api": "workspace:*",
"@coze-arch/bot-studio-store": "workspace:*",
"@coze-arch/bot-utils": "workspace:*",
"@coze-arch/i18n": "workspace:*",
"@coze-common/assets": "workspace:*",
"@coze-studio/bot-detail-store": "workspace:*",
"classnames": "^2.3.2",
"lodash-es": "^4.17.21",
"zustand": "^4.4.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/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"
}
}

View File

@@ -0,0 +1,346 @@
/* stylelint-disable no-descending-specificity */
/* stylelint-disable declaration-no-important */
@import '@coze-common/assets/style/common.less';
@import '@coze-common/assets/style/mixins.less';
.tools-content {
.tools-table-thead {
padding-bottom: 6px;
th {
padding: var(--spacing-spacing-button-default-padding-top, 6px) 0 var(--spacing-tight, 8px) 0;
}
}
}
.api-table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
height: 32px;
font-size: 12px;
font-weight: 400;
line-height: 16px; // 133.333%
color: var(--light-usage-text-color-text-2, rgb(28 31 35 / 60%));
word-wrap: break-word;
thead {
th {
font-size: 12px;
font-weight: 400;
line-height: 16px; // 133.333%
color: var(--light-color-grey-grey-4,
var(--light-color-grey-grey-4, #888d92));
text-align: left;
}
}
.auto-add-api {
animation: flash 6s linear;
animation-delay: 300ms;
td:first-child {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
td:last-child {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
}
@keyframes flash {
10% {
background: rgb(180 186 246 / 24%);
}
20% {
background: unset;
}
30% {
background: rgb(180 186 246 / 24%);
}
40% {
background: unset;
}
50% {
background: rgb(180 186 246 / 24%);
}
95% {
background: rgb(180 186 246 / 24%);
}
}
.api-row {
border-bottom: 1px solid transparent;
&.border-top {
position: relative;
td {
margin-top: 4px;
}
}
// &:last-child {
// border-bottom: 1px solid #f9f9f9;
// }
td {
overflow: hidden;
padding: 2px 4px;
}
&-name {
vertical-align: middle;
}
:global {
.semi-tag-grey-light {
height: 20px;
background: var(--light-color-white-white, #fff);
border-radius: var(--spacing-spacing-button-default-padding-top, 6px);
}
.semi-tag-content {
align-items: center;
justify-content: space-between;
}
}
&.api-disable {
.api-plugin-name,
.api-name-text,
.icon-disabled,
{
cursor: default;
opacity: 0.2;
}
}
}
.api-plugin {
display: flex;
align-items: center;
height: 24px;
padding-right: 10px;
&-image {
display: flex;
flex-shrink: 0;
margin-right: 8px;
>img {
width: 16px;
height: 16px;
}
}
:global {
.semi-image-status {
background-color: rgba(#fff, 0) !important;
}
}
&-name {
font-size: 12px;
font-weight: 400;
line-height: 22px;
color: var(--light-usage-text-color-text-1, rgb(28 29 35 / 80%));
}
&-icon {
margin-left: 4px;
}
}
.api-method {
justify-content: space-between;
width: 100%;
height: 100%;
text-align: center;
span {
color: var(--light-color-grey-grey-5, rgb(107 107 117 / 100%));
}
.icon-config {
cursor: pointer;
color: rgb(107 109 117 / 100%);
}
}
.api-method-read {
justify-content: flex-end;
}
.api-name {
display: flex;
align-items: center;
padding: 2px 0;
padding-right: 10px;
&-text {
margin-right: 4px;
font-size: 12px;
font-weight: 400;
line-height: 16px;
color: rgb(29 28 35 / 80%);
}
:global {
.semi-tag-grey-light {
background: #fff !important;
}
}
.api-divider {
height: 12px;
border-color: var(--light-color-brand-brand-2, #b3c4ff);
}
.copy {
cursor: copy;
}
.icon-tips {
cursor: pointer;
.common-svg-icon(14px, rgba(107, 109, 117, 1));
padding: 1px;
border-radius: 4px;
}
&-publish {
flex-shrink: 0;
margin-left: 4px;
}
}
}
.plugin-modal {
height: 100%;
.plugin-filter {
display: flex;
flex-direction: column;
flex-shrink: 0;
width: 218px;
background: #ebedf0;
}
:global {
.semi-modal-content {
padding: 0;
}
.semi-spin-children {
height: 100%;
}
}
}
.plugin-collapse {
:global {
.semi-collapse-header {
height: 120px !important;
margin: 0 !important;
padding: 14px 16px;
&[aria-expanded='true'] {
border-radius: 8px 8px 0 0 !important;
}
}
.semi-collapse {
padding: 16px 0 12px;
}
.semi-collapse-content {
// background-color: #fff;
padding: 0;
border-radius: 0 0 8px 8px;
// border-color: var(
// --light-usage-border-color-border,
// rgba(28, 31, 35, 0.08)
// );
// border-width: 0 1px 1px 1px;
// border-style: solid;
}
.semi-collapse-item {
// border: 0;
}
}
}
.default-text {
.tip-text;
}
.hide-button-model-wrap {
.ml20 {
margin-left: 20px;
}
.h56 {
height: 56px;
}
.search-input {
position: absolute;
z-index: 9;
top: 20px;
width: 100%;
background: #fff;
}
}
.plugin-func-collapse {
.plugin-api-desc {
cursor: pointer;
width: 200px !important;
}
}
.icon-button-16 {
cursor: pointer;
&:hover {
border-radius: 4px;
}
:global {
.semi-button {
&.semi-button-size-small {
height: 16px;
padding: 1px !important;
svg {
@apply text-foreground-2;
}
}
}
}
}
// 能力模块默认说明文案样式
.tip-text {
font-size: 14px;
font-weight: 400;
font-style: normal;
line-height: 22px;
color: var(--light-usage-text-color-text-2, rgb(28 29 35 / 60%));
}

View File

@@ -0,0 +1,157 @@
/*
* 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 { type FC, useEffect, useRef, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { groupBy } from 'lodash-es';
import { SkillKeyEnum } from '@coze-agent-ide/tool-config';
import {
AddButton,
ToolContentBlock,
useToolValidData,
type ToolEntryCommonProps,
} from '@coze-agent-ide/tool';
import { I18n } from '@coze-arch/i18n';
import {
removeEvent,
OpenModalEvent,
OpenBlockEvent,
handleEvent,
} from '@coze-arch/bot-utils';
import { useSpaceStore } from '@coze-arch/bot-studio-store';
import { type PluginInfoForPlayground } from '@coze-arch/bot-api/plugin_develop';
import { usePageRuntimeStore } from '@coze-studio/bot-detail-store/page-runtime';
import { useBotSkillStore } from '@coze-studio/bot-detail-store/bot-skill';
import { useBotInfoStore } from '@coze-studio/bot-detail-store/bot-info';
import { useBotDetailIsReadonly } from '@coze-studio/bot-detail-store';
import { useDefaultExPandCheck } from '@coze-arch/bot-hooks';
import { handlePluginRiskWarning } from '@coze-agent-ide/plugin-risk-warning';
import { PluginContent } from '@coze-agent-ide/plugin-content-adapter';
import { usePluginApisModal } from '@coze-agent-ide/bot-plugin/component';
import s from './index.module.less';
export type IPluginApisAreaProps = ToolEntryCommonProps;
export const PluginApisArea: FC<IPluginApisAreaProps> = ({ title }) => {
const [plugins, setPlugins] = useState<PluginInfoForPlayground[]>([]);
const pluginApis = useBotSkillStore(state => state.pluginApis);
const { botId } = useBotInfoStore(
useShallow(store => ({
botId: store.botId,
})),
);
const { init } = usePageRuntimeStore(
useShallow(store => ({
init: store.init,
})),
);
const isReadonly = useBotDetailIsReadonly();
const { node, open } = usePluginApisModal();
const spaceID = useSpaceStore(store => store.space.id);
const setToolValidData = useToolValidData();
const prevLength = useRef(pluginApis.length);
const updatePluginApis = () => {
if (!pluginApis.length) {
return;
}
setPlugins(
pluginApis.map(item => ({
...item,
id: item.plugin_id,
name: item.plugin_name,
})),
);
};
useEffect(() => {
setToolValidData(Boolean(pluginApis.length));
const len = Object.keys(groupBy(pluginApis, api => api.plugin_id)).length;
if (init || len > prevLength.current) {
updatePluginApis();
}
prevLength.current = len;
}, [pluginApis.length, init]);
// @ts-expect-error -- linter-disable-autofix
const openHandler = $data => {
open(($data as unknown as { type: number }).type);
};
useEffect(() => {
handleEvent(OpenModalEvent.PLUGIN_API_MODAL_OPEN, openHandler);
return () => {
removeEvent(OpenModalEvent.PLUGIN_API_MODAL_OPEN, openHandler);
};
}, [open]);
const defaultExpand = useDefaultExPandCheck({
blockKey: SkillKeyEnum.PLUGIN_API_BLOCK,
configured: pluginApis.length > 0,
});
return (
<>
{node}
<ToolContentBlock
blockEventName={OpenBlockEvent.PLUGIN_API_BLOCK_OPEN}
header={title}
defaultExpand={defaultExpand}
actionButton={
<>
<AddButton
tooltips={I18n.t('bot_edit_plugin_add_tooltip')}
onClick={() => {
open();
handlePluginRiskWarning();
}}
enableAutoHidden={true}
data-testid="bot.editor.tool.plugin.add-button"
/>
</>
}
>
<div className={s['tools-content']}>
{pluginApis.length ? (
<>
<PluginContent
spaceID={spaceID}
botId={botId}
pluginApis={pluginApis}
plugins={plugins}
readonly={isReadonly}
/>
</>
) : (
<div
className={s['default-text']}
data-testid="bot.ide.bot_creator.bot_edit_plugin_explain"
>
{I18n.t('bot_edit_plugin_explain')}
</div>
)}
</div>
</ToolContentBlock>
</>
);
};

View File

@@ -0,0 +1,20 @@
/*
* 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 {
PluginApisArea,
type IPluginApisAreaProps,
} from './components/plugin-apis-area';

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,77 @@
{
"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"],
"module": "ESNext",
"target": "ES2020",
"moduleResolution": "bundler",
"noImplicitAny": true,
"strictNullChecks": true,
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
},
"include": ["src"],
"exclude": ["node_modules", "dist"],
"references": [
{
"path": "../../arch/bot-api/tsconfig.build.json"
},
{
"path": "../../arch/bot-hooks/tsconfig.build.json"
},
{
"path": "../../arch/bot-space-api/tsconfig.build.json"
},
{
"path": "../../arch/bot-store/tsconfig.build.json"
},
{
"path": "../../arch/bot-typings/tsconfig.build.json"
},
{
"path": "../../arch/bot-utils/tsconfig.build.json"
},
{
"path": "../../arch/i18n/tsconfig.build.json"
},
{
"path": "../bot-plugin/entry/tsconfig.build.json"
},
{
"path": "../bot-plugin/plugin-risk-warning/tsconfig.build.json"
},
{
"path": "../../common/assets/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": "../plugin-content-adapter/tsconfig.build.json"
},
{
"path": "../../studio/stores/bot-detail/tsconfig.build.json"
},
{
"path": "../tool-config/tsconfig.build.json"
},
{
"path": "../tool/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',
});