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,73 @@
/*
* 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 } from '@flowgram-adapter/free-layout-editor';
import { type WorkflowNodeRegistry } from '@coze-workflow/nodes';
import { DatabaseNodeService } from '@/services/database-node-service';
import { provideNodeOutputVariablesEffect } from '@/nodes-v2/materials/provide-node-output-variables';
import { nodeMetaValidate } from '@/nodes-v2/materials/node-meta-validate';
import {
createDatabaseValidator,
createSelectAndSetFieldsValidator,
} from '@/node-registries/database/common/validators';
import { getOutputsDefaultValue } from '@/node-registries/database/common/utils';
import { createSelectAndSetFieldsFieldName } from '@/constants/database-field-names';
import { DatabaseCreateForm } from './database-create-form';
export const DatabaseCreateFormMeta: WorkflowNodeRegistry['formMeta'] = {
render: () => <DatabaseCreateForm />,
validateTrigger: ValidateTrigger.onChange,
validate: {
nodeMeta: nodeMetaValidate,
...createDatabaseValidator(),
...createSelectAndSetFieldsValidator(),
},
defaultValues: {
inputs: {
databaseInfoList: [],
},
outputs: getOutputsDefaultValue(),
},
formatOnInit: (value, context) => {
const databaseNodeService =
context.node.getService<DatabaseNodeService>(DatabaseNodeService);
value = databaseNodeService.convertSettingFieldDTOToField(
createSelectAndSetFieldsFieldName,
value,
);
return value;
},
formatOnSubmit: (value, context) => {
const databaseNodeService =
context.node.getService<DatabaseNodeService>(DatabaseNodeService);
value = databaseNodeService.convertSettingFieldToDTO(
createSelectAndSetFieldsFieldName,
value,
context.node,
);
return value;
},
effect: {
outputs: provideNodeOutputVariablesEffect,
},
};

View File

@@ -0,0 +1,53 @@
/*
* 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 { useResetSelectAndSetFields } from '@/node-registries/database/common/hooks';
import {
SelectAndSetFieldsField,
DatabaseSelectField,
OutputsField,
} from '@/node-registries/database/common/fields';
import { withNodeConfigForm } from '@/node-registries/common/hocs';
import { useCurrentDatabaseQuery } from '@/hooks';
import {
createSelectAndSetFieldsFieldName,
databaseSelectFieldName,
} from '@/constants/database-field-names';
export const DatabaseCreateForm: React.FC = withNodeConfigForm(() => {
const { data: currentDatabase } = useCurrentDatabaseQuery();
const resetSelectAndSetFields = useResetSelectAndSetFields(
createSelectAndSetFieldsFieldName,
);
return (
<>
<DatabaseSelectField
name={databaseSelectFieldName}
afterChange={() => {
resetSelectAndSetFields();
}}
/>
{currentDatabase ? (
<SelectAndSetFieldsField
name={createSelectAndSetFieldsFieldName}
shouldDisableRemove={field => field?.required ?? false}
/>
) : null}
<OutputsField name="outputs" />
</>
);
});

View File

@@ -0,0 +1,68 @@
/*
* 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 { type WorkflowNodeRegistry } from '@coze-workflow/nodes';
import { StandardNodeType } from '@coze-workflow/base';
import { type WorkflowPlaygroundContext } from '@/workflow-playground-context';
import { type NodeTestMeta } from '@/test-run-kit';
import { DatabaseNodeService } from '@/services';
import { test } from './node-test';
import { DatabaseCreateFormMeta } from './database-create-form-meta';
export const DATABASE_CREATE_NODE_REGISTRY: WorkflowNodeRegistry<NodeTestMeta> =
{
type: StandardNodeType.DatabaseCreate,
meta: {
nodeDTOType: StandardNodeType.DatabaseCreate,
test,
helpLink: '/open/docs/guides/database_insert_node',
},
formMeta: DatabaseCreateFormMeta,
onInit: async (nodeJson, context: WorkflowPlaygroundContext) => {
if (!nodeJson) {
return;
}
const databaseNodeService =
context.entityManager.getService<DatabaseNodeService>(
DatabaseNodeService,
);
const databaseId =
nodeJson?.data.inputs.databaseInfoList?.[0]?.databaseInfoID ?? '';
if (!databaseId) {
return;
}
await databaseNodeService.load(databaseId);
},
onDispose: (nodeJson, context: WorkflowPlaygroundContext) => {
if (!nodeJson) {
return;
}
const databaseNodeService =
context.entityManager.getService<DatabaseNodeService>(
DatabaseNodeService,
);
const databaseId =
get(nodeJson, 'inputs.databaseInfoList[0].databaseInfoID') ?? '';
if (!databaseId) {
return;
}
databaseNodeService.clearDatabaseError(databaseId);
},
};

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_CREATE_NODE_REGISTRY } from './database-create-node-registry';

View File

@@ -0,0 +1,51 @@
/*
* 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 { MemoryApi } from '@coze-arch/bot-api';
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 = {
async generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
const databaseID = formData?.inputs?.databaseInfoList[0]?.databaseInfoID;
if (!databaseID) {
return {};
}
const db = await MemoryApi.GetDatabaseByID({
id: databaseID,
need_sys_fields: true,
});
const fieldInfo = formData?.inputs?.insertParam?.fieldInfo ?? [];
const parameters = fieldInfo.map(item => {
const databaseField = db?.database_info?.field_list?.find(
field => field.alterId === item.fieldID,
);
return {
name: `__setting_field_${item?.fieldID}`,
title: databaseField?.name,
input: item?.fieldValue,
};
});
return generateParametersToProperties(parameters, { node });
},
};