feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
.container {
position: relative;
}
.auto-generate {
position: absolute;
top: -32px;
right: 0;
}

View File

@@ -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 React, { useState } from 'react';
import { I18n } from '@coze-arch/i18n';
import { ExpressionEditor } from '@/nodes-v2/components/expression-editor';
import { AutoGenerate } from '@/form-extensions/setters/sql/sql/auto-generate';
import { useField, withField } from '@/form';
import styles from './index.module.less';
const Sql = () => {
const { value, onChange, readonly, errors } = useField<string>();
const [key, setKey] = useState<number>(0);
function handleSubmit(newValue) {
onChange(newValue);
setKey(key + 1);
}
return (
<div className={styles.container}>
{/* The community version does not currently support the AI-generated SQL function for future expansion */}
{!readonly && !IS_OPEN_SOURCE ? (
<AutoGenerate
className={styles['auto-generate']}
onSubmit={handleSubmit}
/>
) : null}
<ExpressionEditor
key={key.toString()}
value={value}
onChange={e => onChange(e)}
readonly={readonly}
isError={Boolean(errors?.length)}
placeholder={I18n.t('workflow_240218_12')}
name={'/sql'}
/>
</div>
);
};
export const SqlField = withField(Sql);

View File

@@ -0,0 +1,38 @@
/*
* 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 function transformOnInit(value) {
if (!value) {
return;
}
const { inputs = {}, nodeMeta, outputs } = value;
return {
nodeMeta,
...inputs,
outputs,
};
}
export function transformOnSubmit(value) {
const { nodeMeta, outputs, ...inputs } = value;
return {
nodeMeta,
inputs,
outputs,
};
}

View File

@@ -0,0 +1,76 @@
/*
* 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 } from 'lodash-es';
import { I18n } from '@coze-arch/i18n';
import {
ValidateTrigger,
type WorkflowNodeRegistry,
} from '@flowgram-adapter/free-layout-editor';
import { provideNodeOutputVariablesEffect } from '@/nodes-v2/materials/provide-node-output-variables';
import { nodeMetaValidate } from '@/nodes-v2/materials/node-meta-validate';
import { createValueExpressionInputValidate } from '@/nodes-v2/materials/create-value-expression-input-validate';
import { createNodeInputNameValidate } from '@/nodes-v2/components/node-input-name/validate';
import { getOutputsDefaultValue } from '@/node-registries/database/common/utils';
import FormRender from './form';
import { transformOnInit, transformOnSubmit } from './data-transformer';
export const DATABASE_NODE_FORM_META: WorkflowNodeRegistry['formMeta'] = {
// 节点表单渲染
render: () => <FormRender />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
nodeMeta: nodeMetaValidate,
'inputParameters.*.name': createNodeInputNameValidate({
getNames: ({ formValues }) =>
(get(formValues, 'inputParameters') || []).map(item => item.name),
}),
'inputParameters.*.input': createValueExpressionInputValidate({
required: true,
}),
sql: ({ value }) =>
!value ? I18n.t('workflow_detail_node_error_empty') : undefined,
databaseInfoList: ({ value }) => {
if (!value || value.length === 0) {
return I18n.t('workflow_detail_node_error_empty');
}
},
},
// 默认值
defaultValues: {
inputParameters: [{ name: 'input' }],
databaseInfoList: [],
outputs: getOutputsDefaultValue(),
},
// 副作用
effect: {
outputs: provideNodeOutputVariablesEffect,
},
// 初始化数据转换
formatOnInit: transformOnInit,
// 提交数据转换
formatOnSubmit: transformOnSubmit,
};

View File

@@ -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 { useNodeTestId } from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import {
DatabaseSelectField,
OutputsField,
} from '@/node-registries/database/common/fields';
import { NodeConfigForm } from '@/node-registries/common/components';
import { Section } from '@/form';
import { InputsParametersField } from '../../common/fields';
import { SqlField } from './components/sql-field';
const Render = () => {
const { getNodeSetterId } = useNodeTestId();
const setterTestId = getNodeSetterId('');
return (
<NodeConfigForm>
<InputsParametersField
testId={setterTestId}
name="inputParameters"
tooltip={I18n.t(
'workflow_240218_07',
{},
'需要添加的输入变量SQL中可直接引用此处添加的变量',
)}
/>
<DatabaseSelectField name="databaseInfoList" />
<Section
title={I18n.t('workflow_240218_09', {}, 'SQL')}
tooltip={I18n.t(
'workflow_240218_10',
{},
'要执行的SQL语句,可以直接使用输入参数中的变量,注意rowNum输出返回的行数或者受影响的行数,outputList中的变量名需与SQL中定义的字段名一致。',
)}
>
<SqlField name="sql" />
</Section>
<OutputsField name="outputs" />
</NodeConfigForm>
);
};
export default Render;

View File

@@ -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 { DATABASE_NODE_REGISTRY } from './node-registry';

View File

@@ -0,0 +1,42 @@
/*
* 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_NODE_SIZE,
type WorkflowNodeRegistry,
} from '@coze-workflow/nodes';
import { StandardNodeType } from '@coze-workflow/base';
import { type NodeTestMeta } from '@/test-run-kit';
import { test } from './node-test';
import { DATABASE_NODE_FORM_META } from './form-meta';
export const DATABASE_NODE_REGISTRY: WorkflowNodeRegistry<NodeTestMeta> = {
type: StandardNodeType.Database,
meta: {
nodeDTOType: StandardNodeType.Database,
style: {
width: 484,
},
size: DEFAULT_NODE_SIZE,
nodeMetaPath: DEFAULT_NODE_META_PATH,
test,
helpLink: '/open/docs/guides/database_sql_node',
},
formMeta: DATABASE_NODE_FORM_META,
};

View 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.
*/
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 formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
const inputParameters = formData?.inputParameters;
return generateParametersToProperties(inputParameters, { node });
},
};