/* * 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. */ /* eslint-disable @coze-arch/max-line-per-function */ import { useState } from 'react'; import { sortBy } from 'lodash-es'; import classNames from 'classnames'; import { useBoolean } from 'ahooks'; import { type WorkflowNodeJSON } from '@flowgram-adapter/free-layout-editor'; import { ParametersPopover } from '@coze-studio/components/parameters-popover'; import { CardThumbnailPopover } from '@coze-studio/components'; import { I18n } from '@coze-arch/i18n'; import { Space, Tooltip, Typography, UIButton, UITag, } from '@coze-arch/bot-semi'; import { ProductStatus, type public_api, } from '@coze-arch/bot-api/product_api'; import { type PluginApi } from '@coze-arch/bot-api/plugin_develop'; import { useViewExample } from '@coze-agent-ide/bot-plugin-tools/useViewExample'; import { Popconfirm } from '@coze-arch/coze-design'; import { OverflowList } from '@blueprintjs/core'; import { From } from '../../types/plugin-modal-types'; import { PluginPerfStatics } from './plugin-perf-statics'; import s from './index.module.less'; type PluginToolInfo = public_api.PluginToolInfo; export interface PluginItemProps { isAdded?: boolean; onApiToggle: () => Promise; pluginApi: PluginApi; showButton?: boolean; marketStatus?: ProductStatus; from?: From; workflowNodes?: WorkflowNodeJSON[]; loading?: boolean; marketPluginInfo?: PluginToolInfo; isLocalPlugin?: boolean; connectors?: string[]; } interface OverflowTagItem { tagName?: string; key?: string; } // eslint-disable-next-line complexity export const PluginItem: React.FC = ({ isAdded, onApiToggle, pluginApi, marketStatus, showButton, from, workflowNodes, loading, marketPluginInfo, isLocalPlugin, connectors, }) => { const { name, desc, parameters, debug_example } = pluginApi; const { exampleNode, doShowExample } = useViewExample(); const [isMouseIn, { setFalse, setTrue }] = useBoolean(false); const onMouseEnter = () => { setTrue(); }; const onMouseLeave = () => { setFalse(); }; const [count, setCount] = useState((workflowNodes || []).length); const isFromWorkflow = from === From.WorkflowAddNode || from === From.ProjectWorkflow; const renderOverflow = (items: OverflowTagItem[]) => items.length ? ( +{items.length} ) : null; const renderItem = (item: OverflowTagItem) => ( {item.tagName} ); const isDisabled = marketStatus === ProductStatus?.Unlisted; // The end plug-in has not been added, and the applicable channel is prompted. const showAddConfirm = isLocalPlugin && ((!isFromWorkflow && !isAdded) || (isFromWorkflow && count === 0)); return ( <> {exampleNode}
{name} {/* Preview preview card */} {pluginApi?.card_binding_info?.thumbnail ? ( ) : null}
{desc} {!!parameters?.length && (
item.name?.length, )?.map((tag, index) => ({ tagName: tag.name, key: String(index), }))} overflowRenderer={renderOverflow} visibleItemRenderer={renderItem} collapseFrom="end" className={s['params-tags']} />
{I18n.t('parameters')}
{debug_example ? (
doShowExample({ scene: 'bot', requestParams: parameters, debugExample: debug_example, }) } > {I18n.t('plugin_edit_tool_view_example')}
) : null}
)}
{showButton ? ( { onApiToggle?.().then(isSuccess => { if (isSuccess) { setCount(prev => prev + 1); } }); }} >
{ if (showAddConfirm) { return; } onApiToggle?.().then(isSuccess => { if (isSuccess) { setCount(prev => prev + 1); } }); }} onMouseEnter={onMouseEnter} disabled={isDisabled} loading={loading && isFromWorkflow} onMouseLeave={onMouseLeave} > {isAdded && !isDisabled ? ( isMouseIn ? ( I18n.t('Remove') ) : ( I18n.t('Added') ) ) : ( <> {I18n.t('Add_1')} {isFromWorkflow && count !== 0 ? ( {count} ) : null} )}
) : null}
{/* (api.plugin_id?.toString() ?? '0') + (api.name ?? '') === (plugin_id?.toString() ?? '0') + (name ?? ''), ), )} onChange={checked => { if (!checked) { const index = $enabledPluginApiList.apiList.findIndex( api => (api.plugin_id?.toString() ?? '0') + (api.name ?? '') === (plugin_id?.toString() ?? '0') + (name ?? ''), ); if (index >= 0) { $enabledPluginApiList.apiList.splice(index, 1); } return; } $enabledPluginApiList.apiList.push(pluginApi); }} /> */}
); };