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,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 { MessageOutput as OutputTextContent } from '@/components/node-render/node-render-new/fields/message-output'

View 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 INPUT_PATH = 'inputs.inputParameters';
export const ANSWER_CONTENT_PATH = 'inputs.content';
export const STREAMING_OUTPUT_PATH = 'inputs.streamingOutput';

View File

@@ -0,0 +1,58 @@
/*
* 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 FormData, type NodeDataDTO } from './types';
import { get, set } from 'lodash-es';
import { VariableTypeDTO } from '@coze-workflow/base';
/**
* 节点后端数据 -> 前端表单数据
*/
export const transformOnInit = (value: NodeDataDTO) => {
const finalValue = {
...value,
inputs: {
...value?.inputs,
content: get(value, 'inputs.content.value.content') as string | undefined,
},
};
// 设置各字段初始值
if (typeof finalValue.inputs.inputParameters === 'undefined') {
set(finalValue, 'inputs.inputParameters', [{ name: 'output' }]);
}
return finalValue;
};
/**
* 前端表单数据 -> 节点后端数据
* @param value
* @returns
*/
export const transformOnSubmit = (value: FormData) => {
return {
...value,
inputs: {
...value.inputs,
content: {
type: VariableTypeDTO.string,
value: {
type: 'literal',
content: value.inputs.content,
}
}
}
}
};

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 {
ValidateTrigger,
type FormMetaV2,
} from '@flowgram-adapter/free-layout-editor';
import { fireNodeTitleChange } from '@/node-registries/common/effects';
import { nodeMetaValidate } from '@/nodes-v2/materials/node-meta-validate';
import { type FormData } from './types';
import { FormRender } from './form';
import { transformOnInit, transformOnSubmit } from './data-transformer';
import { createInputsValidator } from '../common/fields';
export const OUTPUT_FORM_META: FormMetaV2<FormData> = {
// 节点表单渲染
render: () => <FormRender />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
nodeMeta: nodeMetaValidate,
...createInputsValidator(true),
},
// 副作用管理
effect: {
nodeMeta: fireNodeTitleChange,
},
// 节点后端数据 -> 前端表单数据
formatOnInit: transformOnInit,
// 前端表单数据 -> 节点后端数据
formatOnSubmit: transformOnSubmit,
};

View File

@@ -0,0 +1,57 @@
/*
* 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';
import { I18n } from '@coze-arch/i18n';
import { withNodeConfigForm } from '@/node-registries/common/hocs';
import { useWatch } from '@/form';
import { InputsParametersField, AnswerContentField } from '../common/fields';
import {
INPUT_PATH,
ANSWER_CONTENT_PATH,
STREAMING_OUTPUT_PATH,
} from './constants';
export const FormRender = withNodeConfigForm(() => {
const inputParameters = useWatch<InputValueVO[]>(INPUT_PATH);
return (
<>
<InputsParametersField
key={INPUT_PATH}
name={INPUT_PATH}
title={I18n.t('workflow_detail_end_output')}
tooltip={I18n.t('workflow_message_variable_tooltips')}
isTree={true}
/>
<AnswerContentField
key={ANSWER_CONTENT_PATH}
editorFieldName={ANSWER_CONTENT_PATH}
switchFieldName={STREAMING_OUTPUT_PATH}
title={I18n.t('workflow_241111_01')}
tooltip={I18n.t('workflow_message_anwser_tooltips')}
enableStreamingOutput
switchLabel={I18n.t('workflow_message_streaming_name')}
switchTooltip={I18n.t('workflow_message_streaming_tooltips')}
// 适配旧的 testId 格式
testId={`/${ANSWER_CONTENT_PATH.split('.').join('/')}`}
switchTestId={STREAMING_OUTPUT_PATH.split('.')?.at(-1)}
inputParameters={inputParameters}
/>
</>
);
});

View 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 { OUTPUT_NODE_REGISTRY } from './node-registry';
export { OutputContent } from './node-content';

View File

@@ -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 { InputParameters } from '../common/components';
import { useFlags } from '@coze-arch/bot-flags';
import { MessageContent as OutputContentOld } from '@/components/node-render/node-render-new/content/message-content';
import { OutputTextContent } from './components/output-text-content';
import { I18n } from '@coze-arch/i18n';
export function OutputContent() {
const [FLAGS] = useFlags();
// 社区版暂不支持该功能
if (!FLAGS['bot.automation.output_node_v2']) {
return <OutputContentOld />;
}
return (
<>
<InputParameters label={I18n.t('workflow_detail_node_output')} />
<OutputTextContent />
</>
);
}

View File

@@ -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 { DEFAULT_NODE_META_PATH } from '@coze-workflow/nodes';
import {
StandardNodeType,
type WorkflowNodeRegistry,
} from '@coze-workflow/base';
import { OUTPUT_FORM_META } from './form-meta';
import { INPUT_PATH } from './constants';
export const OUTPUT_NODE_REGISTRY: WorkflowNodeRegistry = {
type: StandardNodeType.Output,
meta: {
hideTest: true,
nodeDTOType: StandardNodeType.Output,
size: { width: 360, height: 78.2 },
nodeMetaPath: DEFAULT_NODE_META_PATH,
inputParametersPath: INPUT_PATH, // 入参路径,试运行等功能依赖该路径提取参数
helpLink: '/open/docs/guides/message_node',
},
formMeta: OUTPUT_FORM_META,
};

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.
*/
import {
type InputValueVO,
type InputValueDTO,
type ValueExpressionDTO,
type NodeDataDTO as BaseNodeDataDTO,
} from '@coze-workflow/base';
export type FormData = {
inputs: {
inputParameters: InputValueVO[];
streamingOutput?: boolean;
content?: string;
};
} & Pick<BaseNodeDataDTO, 'nodeMeta'>;
export interface NodeDataDTO {
inputs: {
inputParameters?: InputValueDTO[];
streamingOutput?: boolean;
content?: ValueExpressionDTO;
};
}