feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 { get, isEmpty } from 'lodash-es';
|
||||
import { VariableTypeDTO } from '@coze-workflow/base';
|
||||
|
||||
interface ListRefSchema {
|
||||
type: 'list';
|
||||
value: {
|
||||
type: 'ref';
|
||||
content: {
|
||||
source: string;
|
||||
blockID: string;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const toListRefSchema = (value: string[]): ListRefSchema => {
|
||||
const [nodeId, ...keyPaths] = value;
|
||||
return {
|
||||
type: VariableTypeDTO.list,
|
||||
value: {
|
||||
type: 'ref',
|
||||
content: {
|
||||
source: 'block-output',
|
||||
blockID: `${nodeId}`,
|
||||
name: keyPaths.join('.'), // 这是使用当前循环的变量,固定名字叫item
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const listRefSchemaToValue = (
|
||||
listRefSchema: ListRefSchema,
|
||||
): string[] => {
|
||||
if (!listRefSchema || isEmpty(listRefSchema)) {
|
||||
return [];
|
||||
}
|
||||
const nodeId = get(listRefSchema, 'value.content.blockID', '');
|
||||
const keys = get(listRefSchema, 'value.content.name', '');
|
||||
|
||||
if (!nodeId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [nodeId].concat(keys ? keys.split('.') : []);
|
||||
};
|
||||
31
frontend/packages/workflow/nodes/src/typings/index.ts
Normal file
31
frontend/packages/workflow/nodes/src/typings/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 {
|
||||
type WorkflowNodeMeta,
|
||||
type WorkflowNodeRenderProps,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
export {
|
||||
type ViewVariableMeta,
|
||||
ViewVariableTreeNode,
|
||||
ViewVariableType,
|
||||
} from '@coze-workflow/base';
|
||||
export * from './node';
|
||||
export * from './playground-context';
|
||||
export * from './form-value-to-dto';
|
||||
export * from './test-run';
|
||||
export * from './services';
|
||||
export * from './trigger';
|
||||
116
frontend/packages/workflow/nodes/src/typings/node.ts
Normal file
116
frontend/packages/workflow/nodes/src/typings/node.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 {
|
||||
DTODefine,
|
||||
VariableMetaDTO,
|
||||
ApiDetailData,
|
||||
BlockInput,
|
||||
} from '@coze-workflow/base';
|
||||
import type {
|
||||
PluginProductStatus,
|
||||
ProductUnlistType,
|
||||
DebugExample as OriginDebugExample,
|
||||
} from '@coze-arch/bot-api/developer_api';
|
||||
|
||||
export {
|
||||
WorkflowNodeVariablesMeta,
|
||||
type NodeMeta,
|
||||
type WorkflowNodeRegistry,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
export interface FormNodeMeta {
|
||||
title: string;
|
||||
icon: string;
|
||||
description: string;
|
||||
subTitle?: string;
|
||||
}
|
||||
|
||||
export interface NodeTemplateInfo {
|
||||
title: string;
|
||||
icon: string;
|
||||
subTitle: string;
|
||||
description: string;
|
||||
mainColor: string;
|
||||
}
|
||||
|
||||
export interface ApiNodeIdentifier {
|
||||
api_id?: string;
|
||||
pluginID: string;
|
||||
apiName: string;
|
||||
plugin_version?: string;
|
||||
}
|
||||
|
||||
export type DebugExample = OriginDebugExample;
|
||||
|
||||
/**
|
||||
* Plugin扩展协议新增的属性
|
||||
*
|
||||
*/
|
||||
export interface PluginExtendProps {
|
||||
title?: string;
|
||||
label?: string;
|
||||
enum?: string[];
|
||||
enumVarNames?: string[];
|
||||
minimum?: number;
|
||||
maximum?: number;
|
||||
exclusiveMinimum?: boolean;
|
||||
exclusiveMaximum?: boolean;
|
||||
defaultValue?: DTODefine.LiteralExpressionContent;
|
||||
bizExtend?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口 /api/workflow_api/apiDetail 返回的插件数据结构
|
||||
* 由于 inputs 和 outputs 等参数类型后端没有定义清楚,这里补充完善下
|
||||
*/
|
||||
export type ApiNodeDetailDTO = Required<ApiDetailData> & {
|
||||
inputs: (VariableMetaDTO & PluginExtendProps)[]; // name, type, schema, required, description
|
||||
outputs: VariableMetaDTO[]; // name, type, schema, required, description
|
||||
pluginProductStatus: PluginProductStatus;
|
||||
pluginProductUnlistType: ProductUnlistType;
|
||||
};
|
||||
|
||||
/**
|
||||
* 插件节点数据部分结构定义后端
|
||||
*/
|
||||
export interface ApiNodeDataDTO {
|
||||
data: {
|
||||
nodeMeta: {
|
||||
title?: string;
|
||||
icon?: string;
|
||||
subtitle?: string;
|
||||
description?: string;
|
||||
};
|
||||
inputs: {
|
||||
apiParam: BlockInput[];
|
||||
inputParameters?: BlockInput[];
|
||||
inputDefs?: DTODefine.InputVariableDTO[];
|
||||
batch?: {
|
||||
batchEnable: boolean;
|
||||
batchSize: number;
|
||||
concurrentSize: number;
|
||||
inputLists: BlockInput[];
|
||||
};
|
||||
batchMode?: string;
|
||||
settingOnError?: {
|
||||
switch?: boolean;
|
||||
dataOnErr?: string;
|
||||
};
|
||||
};
|
||||
outputs?: VariableMetaDTO[];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 { PlaygroundContext as PlaygroudContextOrigin } from '@flowgram-adapter/free-layout-editor';
|
||||
import {
|
||||
type WorkflowBatchService,
|
||||
type WorkflowVariableService,
|
||||
type WorkflowVariableValidationService,
|
||||
} from '@coze-workflow/variable';
|
||||
import { type StandardNodeType } from '@coze-workflow/base';
|
||||
|
||||
import { type WorkflowNodesService } from '../service';
|
||||
import { type NodeTemplateInfo } from './node';
|
||||
|
||||
export const PlaygroundContext = PlaygroudContextOrigin;
|
||||
|
||||
export interface PlaygroundContext {
|
||||
readonly variableService: WorkflowVariableService;
|
||||
readonly batchService: WorkflowBatchService;
|
||||
readonly nodesService: WorkflowNodesService;
|
||||
readonly variableValidationService: WorkflowVariableValidationService;
|
||||
|
||||
/**
|
||||
* 根据meta 类型获取信息
|
||||
* @param type
|
||||
*/
|
||||
getNodeTemplateInfoByType: (
|
||||
type: StandardNodeType,
|
||||
) => NodeTemplateInfo | undefined;
|
||||
/**
|
||||
* 是否为 不可编辑模式
|
||||
*/
|
||||
disabled: boolean;
|
||||
}
|
||||
21
frontend/packages/workflow/nodes/src/typings/services.ts
Normal file
21
frontend/packages/workflow/nodes/src/typings/services.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 const DeveloperApiService = Symbol('DeveloperAPIService');
|
||||
|
||||
export interface DeveloperApiService {
|
||||
GetReleasedWorkflows: (req?: unknown) => Promise<{ data: any }>;
|
||||
}
|
||||
19
frontend/packages/workflow/nodes/src/typings/test-run.ts
Normal file
19
frontend/packages/workflow/nodes/src/typings/test-run.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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 WorkflowRenderKey {
|
||||
EXECUTE_STATUS_BAR = 'execute_status_bar', // test run 顶部 bar
|
||||
}
|
||||
96
frontend/packages/workflow/nodes/src/typings/trigger.ts
Normal file
96
frontend/packages/workflow/nodes/src/typings/trigger.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 ValueExpression,
|
||||
type OutputValueVO,
|
||||
} from '@coze-workflow/base/types';
|
||||
import {
|
||||
type FormDataTypeName,
|
||||
type IFormItemMeta,
|
||||
type ValidatorProps,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
export namespace TriggerForm {
|
||||
export const TabName = 'tab';
|
||||
export enum Tab {
|
||||
Basic = 'basic',
|
||||
Trigger = 'trigger',
|
||||
}
|
||||
export const TriggerFormName = 'trigger';
|
||||
export const TriggerFormIsOpenName = 'isOpen';
|
||||
export const TriggerFormEventTypeName = 'event';
|
||||
export const TriggerFormEventIdName = 'eventID';
|
||||
export const TriggerFormAppIdName = 'appID';
|
||||
export const TriggerFormParametersName = 'parameters';
|
||||
export const TriggerFormCronjobName = 'crontab';
|
||||
export const TriggerFormCronjobTypeName = 'crontabType';
|
||||
export const TriggerFormBindWorkflowName = 'workflowId';
|
||||
export enum TriggerFormEventType {
|
||||
Time = 'time',
|
||||
Event = 'event',
|
||||
}
|
||||
|
||||
export const getVariableName = (variable: OutputValueVO): string =>
|
||||
`${variable?.type},${variable?.key ?? variable?.name}`;
|
||||
|
||||
export type Validation =
|
||||
| 'requiredWhenTriggerOpenedAndSelectedTime'
|
||||
| 'requiredWhenTriggerOpenedAndSelectedEvent'
|
||||
| 'required'
|
||||
| 'cronValidateWhenTriggerOpenedAndSelectedTime'
|
||||
| 'cronValidate';
|
||||
export type ValidationFn = (props: ValidatorProps<any, any>) => string | true;
|
||||
|
||||
export interface FormItemMeta {
|
||||
name: string;
|
||||
label: string;
|
||||
required?: boolean;
|
||||
type: FormDataTypeName;
|
||||
isInTriggerNode?: boolean;
|
||||
setter: string;
|
||||
setterProps?: {
|
||||
defaultValue?: any;
|
||||
size?: string;
|
||||
[k: string]: any;
|
||||
};
|
||||
tooltip?: string;
|
||||
hidden?: string | boolean; // '{{$values.tab === "time"}}'
|
||||
validation?: Validation | ValidationFn;
|
||||
otherAbilities?: IFormItemMeta['abilities'];
|
||||
otherMetaProps?: { [k: string]: any };
|
||||
otherDecoratorProps?: { [k: string]: any };
|
||||
}
|
||||
|
||||
export type FormMeta = FormItemMeta[];
|
||||
|
||||
// 表单值
|
||||
export interface FormValue {
|
||||
[TriggerFormIsOpenName]?: boolean;
|
||||
[TriggerFormEventTypeName]?: TriggerFormEventType;
|
||||
[k: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
export enum CronJobType {
|
||||
Cronjob = 'cronjob',
|
||||
Selecting = 'selecting',
|
||||
}
|
||||
|
||||
export interface CronJobValue {
|
||||
type?: CronJobType;
|
||||
content?: ValueExpression;
|
||||
}
|
||||
Reference in New Issue
Block a user