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,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 { nanoid } from 'nanoid';
import { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('wf_chatflow_24'),
name: CONVERSATION_NAME,
required: true,
type: 'string',
},
};
export const DEFAULT_CONVERSATION_VALUE = [
{
name: CONVERSATION_NAME,
input: {
type: ValueExpressionType.REF,
},
},
];
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
];

View File

@@ -0,0 +1,67 @@
/*
* 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 { type InputValueVO } from '@coze-workflow/base';
import { fireNodeTitleChange } from '@/nodes-v2/materials/fire-node-title-change';
import { createValueExpressionInputValidate } from '@/nodes-v2/materials/create-value-expression-input-validate';
import { transformOnSubmit } from '../transform-on-submit';
import { createTransformOnInit } from '../transform-on-init';
import { syncConversationNameEffect } from '../sync-conversation-name-effect';
import { provideNodeOutputVariablesEffect } from '../../materials/provide-node-output-variables';
import FormRender from './form-render';
import { DEFAULT_CONVERSATION_VALUE, DEFAULT_OUTPUTS } from './constants';
interface FormData {
inputParameters: InputValueVO[];
}
export const CLEAR_CONTEXT_FORM_META: FormMetaV2<FormData> = {
// 节点表单渲染
render: () => <FormRender />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
// 必填
'inputParameters.0.input': createValueExpressionInputValidate({
required: true,
}),
},
// 副作用管理
effect: {
nodeMeta: fireNodeTitleChange,
outputs: provideNodeOutputVariablesEffect,
inputParameters: syncConversationNameEffect,
},
// 节点后端数据 -> 前端表单数据
formatOnInit: createTransformOnInit(
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
),
// 前端表单数据 -> 节点后端数据
formatOnSubmit: transformOnSubmit,
};

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('wf_chatflow_23'),
outputTooltip: I18n.t('wf_chatflow_25'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { CLEAR_CONTEXT_FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const CLEAR_CONTEXT_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.ClearContext,
CLEAR_CONTEXT_FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,41 @@
/*
* 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';
export const CONVERSATION_NAME = 'conversationName';
export const PARAMS_COLUMNS = [
{
title: I18n.t('workflow_detail_node_parameter_name'),
style: { width: 180 },
},
{
title: I18n.t('workflow_detail_node_parameter_value'),
style: { flex: '1' },
},
];
export const INPUT_COLUMNS_NARROW = [
{
title: I18n.t('workflow_detail_node_parameter_name'),
style: { width: 140 },
},
{
title: I18n.t('workflow_detail_node_parameter_value'),
style: { flex: '1' },
},
];

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 { nanoid } from 'nanoid';
import { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('wf_chatflow_14'),
name: CONVERSATION_NAME,
required: true,
type: 'string',
},
};
export const DEFAULT_CONVERSATION_VALUE = [
{
name: CONVERSATION_NAME,
input: {
type: ValueExpressionType.REF,
},
},
];
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
{
key: nanoid(),
name: 'isExisted',
type: ViewVariableType.Boolean,
},
{
key: nanoid(),
name: 'conversationId',
type: ViewVariableType.String,
},
];

View File

@@ -0,0 +1,65 @@
/*
* 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 { type InputValueVO } from '@coze-workflow/base';
import { fireNodeTitleChange } from '@/nodes-v2/materials/fire-node-title-change';
import { createValueExpressionInputValidate } from '@/nodes-v2/materials/create-value-expression-input-validate';
import { transformOnSubmit } from '../transform-on-submit';
import { createTransformOnInit } from '../transform-on-init';
import { provideNodeOutputVariablesEffect } from '../../materials/provide-node-output-variables';
import FormRender from './form-render';
import { DEFAULT_CONVERSATION_VALUE, DEFAULT_OUTPUTS } from './constants';
interface FormData {
inputParameters: InputValueVO[];
}
export const CREATE_CONVERSATION_FORM_META: FormMetaV2<FormData> = {
// 节点表单渲染
render: () => <FormRender />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
// 必填
'inputParameters.0.input': createValueExpressionInputValidate({
required: true,
}),
},
// 副作用管理
effect: {
nodeMeta: fireNodeTitleChange,
outputs: provideNodeOutputVariablesEffect,
},
// 节点后端数据 -> 前端表单数据
formatOnInit: createTransformOnInit(
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
),
// 前端表单数据 -> 节点后端数据
formatOnSubmit: transformOnSubmit,
};

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('wf_chatflow_13'),
outputTooltip: I18n.t('wf_chatflow_15'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { CREATE_CONVERSATION_FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const CREATE_CONVERSATION_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.CreateConversation,
CREATE_CONVERSATION_FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,45 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
hasConversationNode: true,
disableBot: true,
disableBotTooltip: I18n.t('wf_chatflow_141'),
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,93 @@
/*
* 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 from 'react';
import {
ValidateTrigger,
type FormMetaV2,
} from '@flowgram-adapter/free-layout-editor';
import { type InputValueVO } from '@coze-workflow/base';
import { fireNodeTitleChange } from '@/nodes-v2/materials/fire-node-title-change';
import { createValueExpressionInputValidate } from '@/nodes-v2/materials/create-value-expression-input-validate';
import { provideNodeOutputVariablesEffect } from '../materials/provide-node-output-variables';
import { transformOnSubmit } from './transform-on-submit';
import { createTransformOnInit } from './transform-on-init';
import { syncConversationNameEffect } from './sync-conversation-name-effect';
interface ChatFormData {
inputParameters: InputValueVO[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}
export const createFormMeta = ({
fieldConfig,
needSyncConversationName,
defaultInputValue,
defaultOutputValue,
formRenderComponent,
customValidators = {},
}): FormMetaV2<ChatFormData> => {
// 定义首字母大写的变量引用组件
const FormRender = formRenderComponent;
const formMeta = {
// 节点表单渲染
render: () => <FormRender />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
// 必填
'inputParameters.*.input': createValueExpressionInputValidate({
required: ({ name }) => {
const fieldName = name
.replace('inputParameters.', '')
.replace('.input', '');
return Boolean(fieldConfig[fieldName]?.required);
},
}),
...customValidators,
},
// 副作用管理
effect: {
nodeMeta: fireNodeTitleChange,
outputs: provideNodeOutputVariablesEffect,
},
// 节点后端数据 -> 前端表单数据
formatOnInit: createTransformOnInit(defaultInputValue, defaultOutputValue),
// 前端表单数据 -> 节点后端数据
formatOnSubmit: transformOnSubmit,
};
// 需要同步联动 CONVERSATION_NAME 字段的值
if (needSyncConversationName) {
Object.assign(formMeta.effect, {
inputParameters: syncConversationNameEffect,
});
}
return formMeta;
};

View File

@@ -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 { Field } from '@flowgram-adapter/free-layout-editor';
import { PublicScopeProvider } from '@coze-workflow/variable';
import {
type InputValueVO,
type ViewVariableTreeNode,
} from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import { Outputs } from '@/nodes-v2/components/outputs';
import NodeMeta from '../components/node-meta';
import FixedInputParameters from '../components/fixed-input-parameters';
import { INPUT_COLUMNS_NARROW } from './constants';
export interface FormRenderProps {
defaultInputValue: InputValueVO[] | undefined;
defaultOutputValue: ViewVariableTreeNode[] | undefined;
fieldConfig: Record<
string,
{
description: string;
name: string;
required: boolean;
type: string;
optionsList?: {
label: string;
value: string;
}[];
}
>;
readonly: boolean;
inputTooltip: string;
outputTooltip: string;
hasInputs?: boolean;
}
export const createFormRender = ({
defaultInputValue,
defaultOutputValue,
fieldConfig,
readonly,
inputTooltip = '',
outputTooltip = '',
hasInputs = true,
}: FormRenderProps) => (
<PublicScopeProvider>
<>
<NodeMeta fieldName="nodeMeta" />
{hasInputs ? (
<FixedInputParameters
fieldName="inputParameters"
defaultValue={defaultInputValue}
headerTitle={I18n.t('workflow_detail_node_parameter_input')}
headerTootip={inputTooltip}
columns={INPUT_COLUMNS_NARROW}
fieldConfig={fieldConfig}
readonly={readonly}
/>
) : null}
<Field name="outputs" defaultValue={defaultOutputValue}>
{({ field, fieldState }) => (
<Outputs
id={'create-conversation-node-output'}
value={field.value}
onChange={field.onChange}
titleTooltip={outputTooltip}
readonly
needErrorBody={false}
errors={fieldState?.errors}
/>
)}
</Field>
</>
</PublicScopeProvider>
);

View File

@@ -0,0 +1,111 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { type InputValueVO, VariableTypeDTO } from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_005'),
name: CONVERSATION_NAME,
required: true,
type: VariableTypeDTO.string,
},
role: {
description: I18n.t('workflow_250407_006'),
name: 'role',
required: true,
type: VariableTypeDTO.string,
// 选项默认值
defaultValue: 'user',
// 选项列表
optionsList: [
{ label: 'user', value: 'user' },
{ label: 'assistant', value: 'assistant' },
],
},
content: {
description: I18n.t('workflow_250407_007'),
name: 'content',
required: true,
type: VariableTypeDTO.string,
},
};
export const DEFAULT_CONVERSATION_VALUE: InputValueVO[] = Object.keys(
FIELD_CONFIG,
).map(fieldName => {
// 针对 role 字段,需要设置字面量默认值
if (fieldName === 'role') {
return {
name: fieldName,
input: {
type: ValueExpressionType.LITERAL,
content: FIELD_CONFIG[fieldName].defaultValue,
},
};
}
return {
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
};
});
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
{
key: nanoid(),
name: 'message',
type: ViewVariableType.Object,
children: [
{
key: nanoid(),
name: 'messageId',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'role',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'contentType',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'content',
type: ViewVariableType.String,
},
],
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: true,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const CREATE_MESSAGE_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.CreateMessage,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,131 @@
/*
* 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, set } from 'lodash-es';
import { type WorkflowNodeFormMeta } from '@flowgram-adapter/free-layout-editor';
import { variableUtils } from '@coze-workflow/variable';
import {
DEFAULT_NODE_META_PATH,
DEFAULT_NODE_SIZE,
type WorkflowNodeRegistry,
} from '@coze-workflow/nodes';
import {
StandardNodeType,
ValueExpression,
type VariableTypeDTO,
ViewVariableType,
type NodeMeta,
type InputValueDTO,
type RefExpressionContent,
} from '@coze-workflow/base';
const NODE_WIDTH = DEFAULT_NODE_SIZE.width;
const NODE_HEIGHT = 113;
const INPUT_PATH = '/inputParameters';
const helpLinkMap = {
[StandardNodeType.ClearContext]:
'/open/docs/guides/clear_conversation_history',
[StandardNodeType.CreateConversation]:
'/open/docs/guides/create_conversation',
[StandardNodeType.QueryMessageList]: '/open/docs/guides/query_message_list',
[StandardNodeType.UpdateConversation]: '/open/docs/guides/edit_conversation',
[StandardNodeType.DeleteConversation]:
'/open/docs/guides/delete_conversation',
[StandardNodeType.QueryConversationList]:
'/open/docs/guides/query_conversation_list',
[StandardNodeType.QueryConversationHistory]:
'/open/docs/guides/query_conversation_history',
[StandardNodeType.CreateMessage]: '/open/docs/guides/create_message',
[StandardNodeType.UpdateMessage]: '/open/docs/guides/edit_message',
[StandardNodeType.DeleteMessage]: '/open/docs/guides/delete_message',
};
export const createNodeRegistry = (
nodeType: StandardNodeType,
formMeta: WorkflowNodeFormMeta,
fieldConfig: Record<
string,
{
description: string;
name: string;
required: boolean;
type: string;
}
>,
nodeMeta?: Partial<NodeMeta>,
// eslint-disable-next-line max-params
): WorkflowNodeRegistry => ({
type: nodeType,
meta: {
nodeDTOType: nodeType,
style: {
width: NODE_WIDTH,
},
size: { width: NODE_WIDTH, height: NODE_HEIGHT },
nodeMetaPath: DEFAULT_NODE_META_PATH,
inputParametersPath: INPUT_PATH, // 入参路径,试运行等功能依赖该路径提取参数
getInputVariableTag(name, input, extra) {
const field = fieldConfig[name || ''];
let invalid = false;
if (field?.required) {
const content = input?.content as RefExpressionContent;
const isRef = content?.keyPath?.length > 0;
// 初始化流程时,可能变量模块还没有初始化,这里会获取不到变量...
const variable = extra?.variableService.getWorkflowVariableByKeyPath(
content?.keyPath,
{ node: extra?.node, checkScope: true },
);
// 必填场景,如果:
// 1. 为空,报错
// 2. 不为空
// 2.1 引用变量,且变量不存在,报错
invalid = ValueExpression.isEmpty(input) || (isRef && !variable);
}
return {
label: name,
type: field?.type
? variableUtils.DTOTypeToViewType(field.type as VariableTypeDTO)
: ViewVariableType.String,
invalid,
};
},
helpLink: helpLinkMap[nodeType],
...nodeMeta,
},
beforeNodeSubmit: nodeData => {
const inputParameters = get(
nodeData,
'data.inputs.inputParameters',
[],
) as InputValueDTO[];
// 对于固定参数类型,需要将 type 字段设置为预定义的类型,而不是右侧填入的变量类型
inputParameters.forEach(param => {
const config = fieldConfig[param.name || ''];
if (config && param.input.type) {
set(param, 'input.type', config.type);
}
});
return nodeData;
},
formMeta,
});

View File

@@ -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 { nanoid } from 'nanoid';
import { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_023'),
name: CONVERSATION_NAME,
required: true,
type: 'string',
},
};
export const DEFAULT_CONVERSATION_VALUE = Object.keys(FIELD_CONFIG).map(
fieldName => ({
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
}),
);
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: false,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const DELETE_CONVERSATION_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.DeleteConversation,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,45 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
hasConversationNode: true,
disableBot: true,
disableBotTooltip: I18n.t('wf_chatflow_141'),
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,55 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { VariableTypeDTO } from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_015'),
name: CONVERSATION_NAME,
required: true,
type: VariableTypeDTO.string,
},
messageId: {
description: I18n.t('workflow_250407_016'),
name: 'messageId',
required: true,
type: VariableTypeDTO.string,
},
};
export const DEFAULT_CONVERSATION_VALUE = Object.keys(FIELD_CONFIG).map(
fieldName => ({
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
}),
);
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: true,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const DELETE_MESSAGE_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.DeleteMessage,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,26 @@
/*
* 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 { QUERY_MESSAGE_LIST_NODE_REGISTRY } from './query-message-list';
export { CREATE_CONVERSATION_NODE_REGISTRY } from './create-conversation';
export { CLEAR_CONTEXT_NODE_REGISTRY } from './clear-conversation-history';
export { UPDATE_CONVERSATION_NODE_REGISTRY } from './update-conversation';
export { DELETE_CONVERSATION_NODE_REGISTRY } from './delete-conversation';
export { QUERY_CONVERSATION_LIST_NODE_REGISTRY } from './query-conversation-list';
export { QUERY_CONVERSATION_HISTORY_NODE_REGISTRY } from './query-conversation-history';
export { CREATE_MESSAGE_NODE_REGISTRY } from './create-message';
export { UPDATE_MESSAGE_NODE_REGISTRY } from './update-message';
export { DELETE_MESSAGE_NODE_REGISTRY } from './delete-message';

View File

@@ -0,0 +1,66 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { VariableTypeDTO } from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_028'),
name: CONVERSATION_NAME,
required: true,
type: VariableTypeDTO.string,
},
rounds: {
description: I18n.t('workflow_250407_029'),
name: 'rounds',
required: true,
type: VariableTypeDTO.integer,
},
};
export const DEFAULT_CONVERSATION_VALUE = Object.keys(FIELD_CONFIG).map(
fieldName => ({
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
}),
);
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'messageList',
type: ViewVariableType.ArrayObject,
children: [
{
key: nanoid(),
name: 'role',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'content',
type: ViewVariableType.String,
},
],
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: true,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const QUERY_CONVERSATION_HISTORY_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.QueryConversationHistory,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

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 { nanoid } from 'nanoid';
import { ViewVariableType } from '@coze-workflow/variable';
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'conversationList',
type: ViewVariableType.ArrayObject,
children: [
{
key: nanoid(),
name: 'conversationName',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'conversationId',
type: ViewVariableType.String,
},
],
},
];

View File

@@ -0,0 +1,29 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import { DEFAULT_OUTPUTS } from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: {},
needSyncConversationName: false,
defaultInputValue: [],
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

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 { I18n } from '@coze-arch/i18n';
import { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import { DEFAULT_OUTPUTS } from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: [],
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: {},
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
hasInputs: false,
});
};
export default Render;

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

View File

@@ -0,0 +1,28 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
export const QUERY_CONVERSATION_LIST_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.QueryConversationList,
FORM_META,
{},
{ test },
);

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 { I18n } from '@coze-arch/i18n';
import { generateEnvToRelatedContextProperties } from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
hasConversationNode: true,
disableBot: true,
disableBotTooltip: I18n.t('wf_chatflow_141'),
});
},
};

View File

@@ -0,0 +1,120 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
[CONVERSATION_NAME]: {
description: I18n.t('wf_chatflow_24'),
name: CONVERSATION_NAME,
required: true,
type: 'string',
},
limit: {
description: I18n.t('wf_chatflow_34'),
name: 'limit',
required: false,
type: 'integer',
},
beforeId: {
description: I18n.t('wf_chatflow_35'),
name: 'beforeId',
required: false,
type: 'string',
},
afterId: {
description: I18n.t('wf_chatflow_36'),
name: 'afterId',
required: false,
type: 'string',
},
};
export const DEFAULT_CONVERSATION_VALUE = [
{
name: CONVERSATION_NAME,
input: {
type: ValueExpressionType.REF,
},
},
{
name: 'limit',
input: {
type: ValueExpressionType.REF,
},
},
{
name: 'beforeId',
input: {
type: ValueExpressionType.REF,
},
},
{
name: 'afterId',
input: {
type: ValueExpressionType.REF,
},
},
];
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'messageList',
type: ViewVariableType.ArrayObject,
children: [
{
key: nanoid(),
name: 'messageId',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'role',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'contentType',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'content',
type: ViewVariableType.String,
},
],
},
{
key: nanoid(),
name: 'firstId',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'lastId',
type: ViewVariableType.String,
},
{
key: nanoid(),
name: 'hasMore',
type: ViewVariableType.Boolean,
},
];

View File

@@ -0,0 +1,67 @@
/*
* 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 { type InputValueVO } from '@coze-workflow/base';
import { fireNodeTitleChange } from '@/nodes-v2/materials/fire-node-title-change';
import { createValueExpressionInputValidate } from '@/nodes-v2/materials/create-value-expression-input-validate';
import { transformOnSubmit } from '../transform-on-submit';
import { createTransformOnInit } from '../transform-on-init';
import { syncConversationNameEffect } from '../sync-conversation-name-effect';
import { provideNodeOutputVariablesEffect } from '../../materials/provide-node-output-variables';
import FormRender from './form-render';
import { DEFAULT_CONVERSATION_VALUE, DEFAULT_OUTPUTS } from './constants';
interface FormData {
inputParameters: InputValueVO[];
}
export const QUERY_MESSAGE_LIST_FORM_META: FormMetaV2<FormData> = {
// 节点表单渲染
render: props => <FormRender {...props} />,
// 验证触发时机
validateTrigger: ValidateTrigger.onChange,
// 验证规则
validate: {
// 必填
'inputParameters.0.input': createValueExpressionInputValidate({
required: true,
}),
},
// 副作用管理
effect: {
nodeMeta: fireNodeTitleChange,
outputs: provideNodeOutputVariablesEffect,
inputParameters: syncConversationNameEffect,
},
// 节点后端数据 -> 前端表单数据
formatOnInit: createTransformOnInit(
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
),
// 前端表单数据 -> 节点后端数据
formatOnSubmit: transformOnSubmit,
};

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = ({ form }) => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('wf_chatflow_33'),
outputTooltip: I18n.t('wf_chatflow_37'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { QUERY_MESSAGE_LIST_FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const QUERY_MESSAGE_LIST_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.QueryMessageList,
QUERY_MESSAGE_LIST_FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View 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 { set, cloneDeep } from 'lodash-es';
import {
DataEvent,
type EffectOptions,
type Effect,
FlowNodeFormData,
type FormModelV2,
} from '@flowgram-adapter/free-layout-editor';
import { ValueExpression, WorkflowMode } from '@coze-workflow/base';
import { CONVERSATION_NAME } from './constants';
/** 延迟200ms此时等边连上后才能检测变量作用域 */
const DELAY = 200;
const effect: Effect = ({ value, context }) => {
if (!context) {
return;
}
const { node, playgroundContext } = context;
const { variableService, nodesService, globalState } = playgroundContext;
const startNode = nodesService.getStartNode();
const formModel = node.getData(FlowNodeFormData).getFormModel<FormModelV2>();
const isChatflow = globalState.flowMode === WorkflowMode.ChatFlow;
const { isInIDE } = globalState;
setTimeout(() => {
const startConversationNameVar =
variableService.getWorkflowVariableByKeyPath(
[startNode.id, 'CONVERSATION_NAME'],
{
node,
checkScope: true,
},
);
const clonedValue = cloneDeep(value);
const conversationNameItem = clonedValue.find(
v => v.name === CONVERSATION_NAME,
);
const noValue = ValueExpression.isEmpty(
conversationNameItem?.input as ValueExpression,
);
// 如果能够找到开始节点的 CONVERSATION_NAME 参数
if (
startConversationNameVar &&
conversationNameItem &&
isChatflow &&
noValue
) {
if (formModel) {
set(conversationNameItem, 'input', {
type: 'ref',
content: {
keyPath: ['100001', 'CONVERSATION_NAME'],
},
});
formModel.setValueIn('inputParameters', clonedValue);
}
} else if (!isInIDE && !isChatflow && conversationNameItem && noValue) {
// 非项目中的工作流,如果存在没有值的 CONVERSATION_NAME 字段,填入默认值 default
if (formModel) {
set(conversationNameItem, 'input', {
type: 'literal',
content: 'Default',
});
formModel.setValueIn('inputParameters', clonedValue);
}
}
}, DELAY);
};
export const syncConversationNameEffect: EffectOptions[] = [
{
event: DataEvent.onValueInit,
effect,
},
];

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 omit from 'lodash-es/omit';
import {
type InputValueVO,
type ViewVariableTreeNode,
type NodeDataDTO,
} from '@coze-workflow/base';
const isEmptyArrayOrNil = (value: unknown) =>
// eslint-disable-next-line eqeqeq
(Array.isArray(value) && value.length === 0) || value == null;
/**
* 节点后端数据 -> 前端表单数据
*/
export const createTransformOnInit =
(
defaultInputValue: InputValueVO[] = [],
defaultOutputValue: ViewVariableTreeNode[] = [],
) =>
(value: NodeDataDTO) => {
const { inputs, outputs } = value || {};
const inputParameters = inputs?.inputParameters || [];
// 由于在提交时,会将没有填值的变量给过滤掉,所以需要在初始化时,将默认值补充进来
// 参见packages/workflow/nodes/src/workflow-json-format.ts:241
const refillInputParamters = defaultInputValue.map(cur => {
const { name } = cur;
const target = inputParameters.find(item => item.name === name);
if (target) {
return target;
}
return cur;
}, []);
const initValue = {
...omit(value, ['inputs']),
inputParameters: refillInputParamters,
outputs: isEmptyArrayOrNil(outputs) ? defaultOutputValue : outputs,
};
return initValue;
};

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 omit from 'lodash-es/omit';
import { type NodeDataDTO, type InputValueVO } from '@coze-workflow/base';
interface FormData {
inputParameters: InputValueVO[];
}
/**
* 前端表单数据 -> 节点后端数据
* @param value
* @returns
*/
export const transformOnSubmit = (value: FormData): NodeDataDTO => {
const formattedValue: Record<string, unknown> = {
...value,
inputs: {
inputParameters: value?.inputParameters || [],
},
};
return omit(formattedValue, ['inputParameters']) as unknown as NodeDataDTO;
};

View File

@@ -0,0 +1,63 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_019'),
name: CONVERSATION_NAME,
required: true,
type: 'string',
},
newConversationName: {
description: I18n.t('workflow_250407_020'),
name: 'newConversationName',
required: true,
type: 'string',
},
};
export const DEFAULT_CONVERSATION_VALUE = Object.keys(FIELD_CONFIG).map(
fieldName => ({
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
}),
);
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
{
key: nanoid(),
name: 'isExisted',
type: ViewVariableType.Boolean,
},
{
key: nanoid(),
name: 'conversationId',
type: ViewVariableType.String,
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: false,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const UPDATE_CONVERSATION_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.UpdateConversation,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,45 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
hasConversationNode: true,
disableBot: true,
disableBotTooltip: I18n.t('wf_chatflow_141'),
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};

View File

@@ -0,0 +1,62 @@
/*
* 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 { ValueExpressionType, ViewVariableType } from '@coze-workflow/variable';
import { VariableTypeDTO } from '@coze-workflow/base';
import { I18n } from '@coze-arch/i18n';
import { CONVERSATION_NAME } from '../constants';
export const FIELD_CONFIG = {
conversationName: {
description: I18n.t('workflow_250407_010'),
name: CONVERSATION_NAME,
required: true,
type: VariableTypeDTO.string,
},
messageId: {
description: I18n.t('workflow_250407_011'),
name: 'messageId',
required: true,
type: VariableTypeDTO.string,
},
newContent: {
description: I18n.t('workflow_250407_012'),
name: 'newContent',
required: true,
type: VariableTypeDTO.string,
},
};
export const DEFAULT_CONVERSATION_VALUE = Object.keys(FIELD_CONFIG).map(
fieldName => ({
name: fieldName,
input: {
type: ValueExpressionType.REF,
},
}),
);
export const DEFAULT_OUTPUTS = [
{
key: nanoid(),
name: 'isSuccess',
type: ViewVariableType.Boolean,
},
];

View File

@@ -0,0 +1,33 @@
/*
* 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 FormMetaV2 } from '@flowgram-adapter/free-layout-editor';
import { createFormMeta } from '../create-form-meta';
import FormRender from './form-render';
import {
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
FIELD_CONFIG,
} from './constants';
export const FORM_META: FormMetaV2 = createFormMeta({
fieldConfig: FIELD_CONFIG,
needSyncConversationName: true,
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
formRenderComponent: FormRender,
});

View File

@@ -0,0 +1,41 @@
/*
* 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 { useReadonly } from '@/nodes-v2/hooks/use-readonly';
import { createFormRender } from '../create-form-render';
import {
FIELD_CONFIG,
DEFAULT_CONVERSATION_VALUE,
DEFAULT_OUTPUTS,
} from './constants';
const Render = () => {
const readonly = useReadonly();
return createFormRender({
defaultInputValue: DEFAULT_CONVERSATION_VALUE,
defaultOutputValue: DEFAULT_OUTPUTS,
fieldConfig: FIELD_CONFIG,
readonly,
inputTooltip: I18n.t('Input'),
outputTooltip: I18n.t('Output'),
});
};
export default Render;

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

View File

@@ -0,0 +1,29 @@
/*
* 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 { StandardNodeType } from '@coze-workflow/base';
import { createNodeRegistry } from '../create-node-registry';
import { test } from './node-test';
import { FORM_META } from './form-meta';
import { FIELD_CONFIG } from './constants';
export const UPDATE_MESSAGE_NODE_REGISTRY = createNodeRegistry(
StandardNodeType.UpdateMessage,
FORM_META,
FIELD_CONFIG,
{ test },
);

View File

@@ -0,0 +1,41 @@
/*
* 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,
generateEnvToRelatedContextProperties,
} from '@/test-run-kit';
import { type NodeTestMeta } from '@/test-run-kit';
export const test: NodeTestMeta = {
generateRelatedContext(node, context) {
const { isInProject } = context;
if (isInProject) {
return {};
}
return generateEnvToRelatedContextProperties({
isNeedBot: true,
});
},
generateFormInputProperties(node) {
const formData = node
.getData(FlowNodeFormData)
.formModel.getFormItemValueByPath('/');
return generateParametersToProperties(formData?.inputParameters, { node });
},
};