Files
coze-studio/frontend/packages/workflow/playground/src/hooks/use-add-node-modal/helper.ts
fanlv 890153324f feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
2025-07-20 17:36:12 +08:00

95 lines
2.4 KiB
TypeScript

/*
* 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 semver from 'semver';
import { type BotPluginWorkFlowItem } from '@coze-workflow/components';
import { type ApiNodeDataDTO } from '@coze-workflow/nodes';
import { BlockInput } from '@coze-workflow/base';
interface PluginApi {
name: string;
plugin_name: string;
api_id: string;
plugin_id: string;
plugin_icon: string;
desc: string;
plugin_product_status: number;
version_name?: string;
version_ts?: string;
}
export const createApiNodeInfo = (
apiParams: Partial<PluginApi> | undefined,
templateIcon?: string,
): ApiNodeDataDTO => {
const { name, plugin_name, api_id, plugin_id, desc, version_ts } =
apiParams || {};
return {
data: {
nodeMeta: {
title: name,
icon: templateIcon,
subtitle: `${plugin_name}:${name}`,
description: desc,
},
inputs: {
apiParam: [
BlockInput.create('apiID', api_id),
BlockInput.create('apiName', name),
BlockInput.create('pluginID', plugin_id),
BlockInput.create('pluginName', plugin_name),
BlockInput.create('pluginVersion', version_ts || ''),
BlockInput.create('tips', ''),
BlockInput.create('outDocLink', ''),
],
},
},
};
};
export const createSubWorkflowNodeInfo = ({
workflowItem,
spaceId,
templateIcon,
isImageflow,
}: {
workflowItem: BotPluginWorkFlowItem | undefined;
spaceId: string;
isImageflow: boolean;
templateIcon?: string;
}) => {
const { name, workflow_id, desc, version_name } = workflowItem || {};
const nodeJson = {
data: {
nodeMeta: {
title: name,
description: desc,
icon: templateIcon,
isImageflow,
},
inputs: {
workflowId: workflow_id,
spaceId,
workflowVersion: semver.valid(version_name) ? version_name : '',
},
},
};
return nodeJson;
};