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,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' />