feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 { nanoid } from 'nanoid';
|
||||
import { ViewVariableType } from '@coze-workflow/variable';
|
||||
|
||||
// 入参路径,试运行等功能依赖该路径提取参数
|
||||
export const INPUT_PATH = 'inputs.inputParameters';
|
||||
|
||||
// 定义固定出参
|
||||
export const OUTPUTS = [
|
||||
{
|
||||
key: nanoid(),
|
||||
name: 'success',
|
||||
type: ViewVariableType.Boolean,
|
||||
},
|
||||
{
|
||||
key: nanoid(),
|
||||
name: 'numberOfDeletions',
|
||||
type: ViewVariableType.Number,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 { omit } from 'lodash-es';
|
||||
import { nodeUtils } from '@coze-workflow/nodes';
|
||||
import {
|
||||
type ValueExpression,
|
||||
type NodeDataDTO,
|
||||
ValueExpressionType,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
import { getInputIsEmpty } from '../trigger-upsert/utils';
|
||||
import { type FormData } from './types';
|
||||
import { OUTPUTS } from './constants';
|
||||
|
||||
export const createTransformOnInit =
|
||||
outputs => (value: NodeDataDTO, context) => {
|
||||
if (!value) {
|
||||
return {
|
||||
inputs: {
|
||||
inputParameters: {
|
||||
triggerId: {
|
||||
type: ValueExpressionType.LITERAL,
|
||||
},
|
||||
userId: {
|
||||
type: ValueExpressionType.LITERAL,
|
||||
},
|
||||
},
|
||||
},
|
||||
outputs,
|
||||
};
|
||||
}
|
||||
const { inputs } = value;
|
||||
const inputParameters = {};
|
||||
|
||||
(inputs?.inputParameters ?? []).forEach(item => {
|
||||
inputParameters[item.name as string] = nodeUtils.refExpressionDTOToVO(
|
||||
item,
|
||||
context,
|
||||
);
|
||||
});
|
||||
return {
|
||||
...(value ?? {}),
|
||||
outputs: value?.outputs ?? outputs,
|
||||
inputs: {
|
||||
...omit(value.inputs ?? {}, ['inputParameters']),
|
||||
inputParameters,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 节点后端数据 -> 前端表单数据
|
||||
*/
|
||||
export const transformOnInit = createTransformOnInit(OUTPUTS);
|
||||
|
||||
/**
|
||||
* 前端表单数据 -> 节点后端数据
|
||||
* @param value
|
||||
* @returns
|
||||
*/
|
||||
export const transformOnSubmit = (value: FormData, context): NodeDataDTO => {
|
||||
const { inputs, ...rest } = value;
|
||||
return {
|
||||
...rest,
|
||||
inputs: {
|
||||
...omit(value.inputs ?? {}, ['inputParameters']),
|
||||
inputParameters: Object.entries(inputs.inputParameters ?? {})
|
||||
.filter(([k, v]) => !!getInputIsEmpty(v))
|
||||
.map(([k, v]) => ({
|
||||
name: k,
|
||||
input: nodeUtils.refExpressionToValueDTO(
|
||||
v as unknown as ValueExpression,
|
||||
context,
|
||||
)?.input,
|
||||
})),
|
||||
},
|
||||
} as unknown as NodeDataDTO;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 {
|
||||
ValidateTrigger,
|
||||
type FormMetaV2,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { nodeMetaValidate } from '@/nodes-v2/materials/node-meta-validate';
|
||||
import { createValueExpressionInputValidate } from '@/node-registries/common/validators';
|
||||
import {
|
||||
fireNodeTitleChange,
|
||||
provideNodeOutputVariablesEffect,
|
||||
} from '@/node-registries/common/effects';
|
||||
|
||||
import { type FormData } from './types';
|
||||
import { FormRender } from './form';
|
||||
import { transformOnInit, transformOnSubmit } from './data-transformer';
|
||||
|
||||
export const TRIGGER_DELETE_FORM_META: FormMetaV2<FormData> = {
|
||||
// 节点表单渲染
|
||||
render: () => <FormRender />,
|
||||
|
||||
// 验证触发时机
|
||||
validateTrigger: ValidateTrigger.onChange,
|
||||
|
||||
// 验证规则
|
||||
validate: {
|
||||
nodeMeta: nodeMetaValidate,
|
||||
// 必填
|
||||
'inputs.inputParameters.userId': createValueExpressionInputValidate({
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
|
||||
// 副作用管理
|
||||
effect: {
|
||||
nodeMeta: fireNodeTitleChange,
|
||||
outputs: provideNodeOutputVariablesEffect,
|
||||
},
|
||||
|
||||
// 节点后端数据 -> 前端表单数据
|
||||
formatOnInit: transformOnInit,
|
||||
|
||||
// 前端表单数据 -> 节点后端数据
|
||||
formatOnSubmit: transformOnSubmit,
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 { ViewVariableType } from '@coze-workflow/base';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import { Section } from '@/form';
|
||||
|
||||
import { FixedInputParameter } from '../trigger-upsert/components/fixed-input-parameter-field';
|
||||
import { withNodeConfigForm } from '../common/hocs';
|
||||
import { OutputsField } from '../common/fields';
|
||||
import { INPUT_PATH } from './constants';
|
||||
|
||||
export const FormRender = withNodeConfigForm(() => (
|
||||
<>
|
||||
<Section title={I18n.t('workflow_detail_node_input', {}, '输入')}>
|
||||
<div className="flex flex-col gap-[8px]">
|
||||
<FixedInputParameter
|
||||
layout="horizontal"
|
||||
name={INPUT_PATH}
|
||||
fieldConfig={[
|
||||
{
|
||||
description: '',
|
||||
name: 'triggerId',
|
||||
label: I18n.t('workflow_trigger_user_create_id', {}, 'id'),
|
||||
required: false,
|
||||
type: ViewVariableType.String,
|
||||
},
|
||||
{
|
||||
label: I18n.t(
|
||||
'workflow_trigger_user_create_userid',
|
||||
{},
|
||||
'userId',
|
||||
),
|
||||
description: I18n.t(
|
||||
'workflow_trigger_user_create_userid_tooltips',
|
||||
{},
|
||||
'用于设置触发器所属用户,可以使用变量-系统变量中的sys_uuid来唯一标识用户',
|
||||
),
|
||||
name: 'userId',
|
||||
required: true,
|
||||
type: ViewVariableType.String,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
<OutputsField
|
||||
title={I18n.t('workflow_detail_node_output')}
|
||||
tooltip={I18n.t('node_http_response_data')}
|
||||
id="triggerDelete-node-outputs"
|
||||
name="outputs"
|
||||
topLevelReadonly={true}
|
||||
customReadonly
|
||||
/>
|
||||
</>
|
||||
));
|
||||
@@ -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 { TRIGGER_DELETE_NODE_REGISTRY } from './node-registry';
|
||||
export { TriggerDeleteContent } from './node-content';
|
||||
@@ -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 { useWorkflowNode, ValueExpression } from '@coze-workflow/base';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import { VariableTagList } from '@/components/node-render/node-render-new/fields/variable-tag-list';
|
||||
import { useInputParametersVariableTags } from '@/components/node-render/node-render-new/fields/use-input-parameters-variable-tags';
|
||||
import { Field } from '@/components/node-render/node-render-new/fields';
|
||||
|
||||
import { Outputs } from '../common/components';
|
||||
|
||||
export function TriggerDeleteContent() {
|
||||
const { data } = useWorkflowNode();
|
||||
const variableTags = useInputParametersVariableTags({
|
||||
[I18n.t('workflow_trigger_user_create_id', {}, 'id')]:
|
||||
ValueExpression.isEmpty(data?.inputs?.inputParameters?.triggerId)
|
||||
? undefined
|
||||
: data?.inputs?.inputParameters?.triggerId,
|
||||
[I18n.t('workflow_trigger_user_create_userid', {}, 'userId')]:
|
||||
ValueExpression.isEmpty(data?.inputs?.inputParameters?.userId)
|
||||
? undefined
|
||||
: data?.inputs?.inputParameters?.userId,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Field label={I18n.t('workflow_detail_node_parameter_input')}>
|
||||
<VariableTagList value={variableTags} />
|
||||
</Field>
|
||||
<Outputs />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 {
|
||||
DEFAULT_NODE_META_PATH,
|
||||
DEFAULT_OUTPUTS_PATH,
|
||||
} from '@coze-workflow/nodes';
|
||||
import {
|
||||
StandardNodeType,
|
||||
type WorkflowNodeRegistry,
|
||||
} from '@coze-workflow/base';
|
||||
|
||||
import { type NodeTestMeta } from '@/test-run-kit';
|
||||
|
||||
import { test } from './node-test';
|
||||
import { TRIGGER_DELETE_FORM_META } from './form-meta';
|
||||
import { INPUT_PATH } from './constants';
|
||||
|
||||
export const TRIGGER_DELETE_NODE_REGISTRY: WorkflowNodeRegistry<NodeTestMeta> =
|
||||
{
|
||||
type: StandardNodeType.TriggerDelete,
|
||||
meta: {
|
||||
nodeDTOType: StandardNodeType.TriggerDelete,
|
||||
size: { width: 360, height: 130.7 },
|
||||
nodeMetaPath: DEFAULT_NODE_META_PATH,
|
||||
outputsPath: DEFAULT_OUTPUTS_PATH,
|
||||
inputParametersPath: INPUT_PATH, // 入参路径,试运行等功能依赖该路径提取参数
|
||||
test,
|
||||
helpLink: '/open/docs/guides/delete_timed_trigger',
|
||||
},
|
||||
variablesMeta: {
|
||||
inputsPathList: [],
|
||||
outputsPathList: ['outputs'],
|
||||
},
|
||||
formMeta: TRIGGER_DELETE_FORM_META,
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 { I18n } from '@coze-arch/i18n';
|
||||
import { FlowNodeFormData } from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { generateParametersToProperties } from '@/test-run-kit';
|
||||
import { type NodeTestMeta } from '@/test-run-kit';
|
||||
|
||||
export const test: NodeTestMeta = {
|
||||
generateFormInputProperties(node) {
|
||||
const labelMap = {
|
||||
userId: I18n.t('workflow_trigger_user_create_userid'),
|
||||
};
|
||||
const requiredKeys = ['userId'];
|
||||
const formData = node
|
||||
.getData(FlowNodeFormData)
|
||||
.formModel.getFormItemValueByPath('/');
|
||||
const inputParameters = formData?.inputs?.inputParameters;
|
||||
|
||||
return generateParametersToProperties(
|
||||
Object.entries(inputParameters || {}).map(([key, value]) => ({
|
||||
name: key,
|
||||
title: labelMap[key] || key,
|
||||
required: requiredKeys.includes(key),
|
||||
input: value,
|
||||
})),
|
||||
{ node },
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import { type InputValueVO } from '@coze-workflow/base';
|
||||
|
||||
export interface FormData {
|
||||
inputs: { inputParameters: InputValueVO[] };
|
||||
}
|
||||
Reference in New Issue
Block a user