feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
18
frontend/packages/workflow/nodes/src/entity-datas/index.ts
Normal file
18
frontend/packages/workflow/nodes/src/entity-datas/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 * from './workflow-node-test-run-data';
|
||||
export * from './workflow-node-data';
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 * from './workflow-node-data';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 StandardNodeType,
|
||||
type BasicStandardNodeTypes,
|
||||
type DTODefine,
|
||||
} from '@coze-workflow/base/types';
|
||||
import { type ReleasedWorkflow } from '@coze-arch/bot-api/workflow_api';
|
||||
|
||||
import { type ApiNodeDetailDTO } from '../../typings';
|
||||
|
||||
/**
|
||||
* api 节点上存储的 api 的相关数据
|
||||
*/
|
||||
export type ApiNodeData = CommonNodeData &
|
||||
Readonly<
|
||||
Partial<ApiNodeDetailDTO> & {
|
||||
/**
|
||||
* 项目内插件节点需要保存 projectId
|
||||
*/
|
||||
projectId?: string;
|
||||
/** 该插件的最新版本的时间戳 */
|
||||
latestVersionTs?: string;
|
||||
/** 插件最新版本的展示名称,形如 v1.0.0 */
|
||||
latestVersionName?: string;
|
||||
/** 该插件当前版本的展示名称,形如 v1.0.0 */
|
||||
versionName?: string;
|
||||
}
|
||||
>;
|
||||
|
||||
/**
|
||||
* 子流程节点上存储的相关数据
|
||||
*/
|
||||
export type SubWorkflowNodeData = CommonNodeData &
|
||||
Readonly<Omit<ReleasedWorkflow, 'inputs' | 'outputs'>> & {
|
||||
/** 子流程节点输入定义 */
|
||||
inputsDefinition: DTODefine.InputVariableDTO[];
|
||||
/**
|
||||
* 项目内子流程需要保存 projectId
|
||||
*/
|
||||
projectId?: string;
|
||||
/** 该子流程的最新版本 */
|
||||
latestVersion?: string;
|
||||
};
|
||||
|
||||
export type QuestionNodeData = CommonNodeData & {
|
||||
question: string;
|
||||
options: any;
|
||||
answerType: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 通用节点类型的相关数据
|
||||
* 基础节点定义见类型 BasicStandardNodeTypes
|
||||
*/
|
||||
export interface CommonNodeData {
|
||||
/**
|
||||
*
|
||||
* 节点图标
|
||||
*/
|
||||
readonly icon: string;
|
||||
/**
|
||||
* 节点描述
|
||||
*/
|
||||
description: string;
|
||||
/**
|
||||
* 节点标题
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* 节点主色
|
||||
*/
|
||||
mainColor: string;
|
||||
}
|
||||
|
||||
export enum LLMNodeDataSkillType {
|
||||
Plugin = 1,
|
||||
Workflow = 4,
|
||||
Dataset = 3,
|
||||
}
|
||||
|
||||
export interface LLMNodeDataPluginSkill {
|
||||
type: LLMNodeDataSkillType.Plugin;
|
||||
pluginId?: string;
|
||||
pluginName?: string;
|
||||
apiId?: string;
|
||||
apiName?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface LLMNodeDataWorkflowSkill {
|
||||
type: LLMNodeDataSkillType.Workflow;
|
||||
workflowId: string;
|
||||
pluginId?: string;
|
||||
name?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface LLMNodeDataDatasetSkill {
|
||||
type: LLMNodeDataSkillType.Dataset;
|
||||
id: string;
|
||||
name?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export type LLMNodeDataSkill =
|
||||
| LLMNodeDataPluginSkill
|
||||
| LLMNodeDataWorkflowSkill
|
||||
| LLMNodeDataDatasetSkill;
|
||||
|
||||
export interface LLMNodeData extends CommonNodeData {
|
||||
skills: LLMNodeDataSkill[];
|
||||
}
|
||||
|
||||
type BasicNodeDataMap = {
|
||||
[K in BasicStandardNodeTypes]: CommonNodeData;
|
||||
};
|
||||
|
||||
export interface NodeData extends BasicNodeDataMap {
|
||||
[StandardNodeType.Api]: ApiNodeData;
|
||||
[StandardNodeType.SubWorkflow]: SubWorkflowNodeData;
|
||||
[StandardNodeType.Question]: QuestionNodeData;
|
||||
[StandardNodeType.LLM]: LLMNodeData;
|
||||
}
|
||||
|
||||
type IfEquals<X, Y, A = X, B = never> =
|
||||
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
||||
|
||||
type EditAbleProperties<T> = {
|
||||
[P in keyof T]: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>;
|
||||
}[keyof T];
|
||||
|
||||
export type EditAbleNodeData<T extends keyof NodeData> = Pick<
|
||||
NodeData[T],
|
||||
EditAbleProperties<NodeData[T]>
|
||||
>;
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 这个模块是干什么的
|
||||
* 在 workflow 的 node 模型中,默认对于数据的存储只有表单,即 formMeta。这部分数据实际上代表的是提交给后端用来做 workflow 运行的数据
|
||||
* 然而实际业务场景中,我们需要的不仅是提交给后端用来做运行的数据,还有一些前端业务场景下需要消费,而后端用不到的数据。比如:
|
||||
* 1. api 节点的 spaceId、发布状态
|
||||
* 2. 子流程节点的 spaceId、发布状态
|
||||
* 所以这个模块增加一个 NodeData 实体,来管理每一个node 上的一些数据,让业务层消费使用
|
||||
*/
|
||||
import { EntityData } from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { type EditAbleNodeData, type NodeData } from './types';
|
||||
|
||||
export class WorkflowNodeData extends EntityData {
|
||||
private nodeData;
|
||||
|
||||
private hasSetNodeData = false;
|
||||
|
||||
init() {
|
||||
this.hasSetNodeData = false;
|
||||
this.nodeData = undefined;
|
||||
}
|
||||
|
||||
getDefaultData() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* 设置节点上除form之外的数据
|
||||
* 泛型必须传入节点类型 StandardNodeType
|
||||
*/
|
||||
setNodeData<T extends keyof NodeData = never>(data: NodeData[T]) {
|
||||
if (this.hasSetNodeData) {
|
||||
// 撤销重做时会重复设置,没必要报错
|
||||
console.warn(`node ${this.entity.id} has already set WorkflowNodeData`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.nodeData = { ...data };
|
||||
this.hasSetNodeData = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* 更新数据,只放非readonly字段的更新
|
||||
* 泛型必须传入节点类型 StandardNodeType
|
||||
*/
|
||||
updateNodeData<T extends keyof NodeData = never>(
|
||||
data: Partial<EditAbleNodeData<T>>,
|
||||
) {
|
||||
this.nodeData = { ...this.nodeData, ...data };
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
* 获取节点上除form之外的数据
|
||||
*/
|
||||
getNodeData<T extends keyof NodeData>(): NodeData[T] {
|
||||
return this.nodeData;
|
||||
}
|
||||
}
|
||||
@@ -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 * from './workflow-node-test-run-data';
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 enum TestRunStatus {
|
||||
success = 'success',
|
||||
failed = 'failed',
|
||||
}
|
||||
|
||||
export interface NodeTestRunResult {
|
||||
status: TestRunStatus;
|
||||
duration: number;
|
||||
input: string | null;
|
||||
output: string | null;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 { EntityData } from '@flowgram-adapter/free-layout-editor';
|
||||
import { type WorkflowNodeEntity } from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { type NodeTestRunResult } from './typings';
|
||||
|
||||
export class WorkflowNodeTestRunData extends EntityData<NodeTestRunResult | null> {
|
||||
static readonly type = 'WorkflowNodeTestRunData';
|
||||
entity: WorkflowNodeEntity;
|
||||
|
||||
get result(): NodeTestRunResult | null {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
set result(result: NodeTestRunResult | null) {
|
||||
this.update(result);
|
||||
}
|
||||
|
||||
getDefaultData(): NodeTestRunResult | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user