feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 { injectable } from 'inversify';
|
||||
import {
|
||||
type NodeContribution,
|
||||
type NodeManager,
|
||||
registerNodeErrorRender,
|
||||
registerNodePlaceholderRender,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { nodeSystemErrorRender } from '../components/node-system-error-render';
|
||||
import { NodePlaceholder } from '../components/node-placeholder';
|
||||
|
||||
@injectable()
|
||||
export class WorkflowNodeContribution implements NodeContribution {
|
||||
onRegister(nodeManager: NodeManager) {
|
||||
registerNodeErrorRender(nodeManager, nodeSystemErrorRender);
|
||||
registerNodePlaceholderRender(nodeManager, NodePlaceholder);
|
||||
}
|
||||
}
|
||||
@@ -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 { injectable } from 'inversify';
|
||||
import {
|
||||
type FlowDocument,
|
||||
type FlowDocumentContribution,
|
||||
PlaygroundContext,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
import {
|
||||
addBasicNodeData,
|
||||
WorkflowNodeData,
|
||||
WorkflowNodeTestRunData,
|
||||
} from '@coze-workflow/nodes';
|
||||
|
||||
import { isNodeV2, NODES_V2 } from '@/nodes-v2';
|
||||
import { nodeV2RegistryUtils } from '@/node-registries/common/utils/nodes-v2-registry-utils';
|
||||
|
||||
/**
|
||||
* 注册流程节点
|
||||
*/
|
||||
@injectable()
|
||||
export class WorkflowNodesV2Contribution implements FlowDocumentContribution {
|
||||
/**
|
||||
* 注册节点
|
||||
* @param document
|
||||
*/
|
||||
registerDocument(document: FlowDocument): void {
|
||||
document.registerFlowNodes(
|
||||
...NODES_V2.map(node => nodeV2RegistryUtils.processNodeRegistry(node)),
|
||||
);
|
||||
|
||||
document.registerNodeDatas(WorkflowNodeTestRunData, WorkflowNodeData);
|
||||
|
||||
document.onNodeCreate(({ node }) => {
|
||||
if (isNodeV2(node)) {
|
||||
const playgroundContext =
|
||||
node.getService<PlaygroundContext>(PlaygroundContext);
|
||||
|
||||
addBasicNodeData(node, playgroundContext);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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 { ContainerModule } from 'inversify';
|
||||
import {
|
||||
FormContribution,
|
||||
NodeContribution,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
import { FlowDocumentContribution } from '@flowgram-adapter/free-layout-editor';
|
||||
import { PlaygroundContext } from '@flowgram-adapter/free-layout-editor';
|
||||
import {
|
||||
bindConfigEntity,
|
||||
WorkflowDocumentOptions,
|
||||
WorkflowDragService,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
import { bindContributions } from '@flowgram-adapter/common';
|
||||
import {
|
||||
TestRunService,
|
||||
TestRunReporterService,
|
||||
} from '@coze-workflow/test-run/plugins';
|
||||
import {
|
||||
FlowRendererContribution,
|
||||
WorkflowShortcutsContribution,
|
||||
} from '@coze-workflow/render';
|
||||
import { ValidationService } from '@coze-workflow/base/services';
|
||||
|
||||
import {
|
||||
bindShortcuts,
|
||||
WorkflowCopyShortcutsContribution,
|
||||
// WorkflowDeleteShortcutsContribution,
|
||||
WorkflowExportShortcutsContribution,
|
||||
WorkflowLayoutShortcutsContribution,
|
||||
WorkflowLoadShortcutsContribution,
|
||||
WorkflowPasteShortcutsContribution,
|
||||
WorkflowSelectAllShortcutsContribution,
|
||||
WorkflowZoomShortcutsContribution,
|
||||
} from '@/shortcuts';
|
||||
import { WorkflowNodesV2Contribution } from '@/container/workflow-nodes-v2-contribution';
|
||||
|
||||
import { WorkflowPlaygroundContext } from '../workflow-playground-context';
|
||||
import { WorkflowOperationServiceProvider } from '../services/workflow-operation-service';
|
||||
import {
|
||||
WorkflowLinesService,
|
||||
WorkflowLinesServiceProvider,
|
||||
} from '../services/workflow-line-service';
|
||||
import {
|
||||
WorkflowCustomDragService,
|
||||
WorkflowEditService,
|
||||
WorkflowOperationService,
|
||||
WorkflowRunService,
|
||||
WorkflowSaveService,
|
||||
WorkflowValidationService,
|
||||
WorkflowModelsService,
|
||||
WorkflowFloatLayoutService,
|
||||
ChatflowService,
|
||||
NodeVersionService,
|
||||
RoleService,
|
||||
RelatedCaseDataService,
|
||||
TestRunReporterService as WorkflowTestRunReporterService,
|
||||
ValueExpressionService,
|
||||
ValueExpressionServiceImpl,
|
||||
DatabaseNodeService,
|
||||
DatabaseNodeServiceImpl,
|
||||
TriggerService,
|
||||
PluginNodeService,
|
||||
SubWorkflowNodeService,
|
||||
WorkflowDependencyService,
|
||||
} from '../services';
|
||||
import { WorkflowDocumentCustomOptions } from '../options/workflow-document-custom-options';
|
||||
import { FormAbilityExtensionsFormContribution } from '../form-extensions';
|
||||
import {
|
||||
WorkflowDependencyStateEntity,
|
||||
WorkflowExecStateEntity,
|
||||
WorkflowGlobalStateEntity,
|
||||
WorkflowTestFormStateEntity,
|
||||
} from '../entities';
|
||||
import { WorkflowPageContribution } from './workflow-page-contribution';
|
||||
import { WorkflowNodeContribution } from './workflow-node-contribution';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export const WorkflowPageContainerModule = new ContainerModule(
|
||||
// eslint-disable-next-line max-params
|
||||
(bind, _unbind, _isbound, rebind) => {
|
||||
/**
|
||||
* 校验
|
||||
*/
|
||||
bind(ValidationService).to(WorkflowValidationService).inSingletonScope();
|
||||
// 兼用老的标识符
|
||||
bind(WorkflowValidationService).toService(ValidationService);
|
||||
|
||||
bind(WorkflowEditService).toSelf().inSingletonScope();
|
||||
bind(TestRunReporterService)
|
||||
.to(WorkflowTestRunReporterService)
|
||||
.inSingletonScope();
|
||||
bind(WorkflowTestRunReporterService).toService(TestRunReporterService);
|
||||
bind(WorkflowRunService).toSelf().inSingletonScope();
|
||||
bind(TestRunService).toService(WorkflowRunService);
|
||||
bind(WorkflowSaveService).toSelf().inSingletonScope();
|
||||
bind(WorkflowOperationService).toSelf().inSingletonScope();
|
||||
bind(WorkflowFloatLayoutService).toSelf().inSingletonScope();
|
||||
bind(NodeVersionService).toSelf().inSingletonScope();
|
||||
bind(RoleService).toSelf().inSingletonScope();
|
||||
bind(PluginNodeService).toSelf().inSingletonScope();
|
||||
bind(SubWorkflowNodeService).toSelf().inSingletonScope();
|
||||
bind(RelatedCaseDataService).toSelf().inSingletonScope();
|
||||
bind(WorkflowDependencyService).toSelf().inSingletonScope();
|
||||
|
||||
bind(ChatflowService).toSelf().inSingletonScope();
|
||||
|
||||
bind(WorkflowOperationServiceProvider)
|
||||
.toDynamicValue(ctx => () => ctx.container.get(WorkflowOperationService))
|
||||
.inSingletonScope();
|
||||
|
||||
bind(WorkflowPlaygroundContext).toSelf().inSingletonScope();
|
||||
bind(WorkflowModelsService).toSelf().inSingletonScope();
|
||||
|
||||
bind(WorkflowDocumentCustomOptions).toSelf().inSingletonScope();
|
||||
rebind(WorkflowDocumentOptions).toService(WorkflowDocumentCustomOptions);
|
||||
bind(WorkflowLinesService).toSelf().inSingletonScope();
|
||||
bind(WorkflowCustomDragService).toSelf().inSingletonScope();
|
||||
rebind(WorkflowDragService).toService(WorkflowCustomDragService);
|
||||
|
||||
bind(WorkflowLinesServiceProvider)
|
||||
.toDynamicValue(ctx => () => ctx.container.get(WorkflowLinesService))
|
||||
.inSingletonScope();
|
||||
|
||||
rebind(PlaygroundContext).toService(WorkflowPlaygroundContext);
|
||||
bindConfigEntity(bind, WorkflowExecStateEntity);
|
||||
bindConfigEntity(bind, WorkflowGlobalStateEntity);
|
||||
bindConfigEntity(bind, WorkflowTestFormStateEntity);
|
||||
bindConfigEntity(bind, WorkflowDependencyStateEntity);
|
||||
bindContributions(bind, WorkflowPageContribution, [
|
||||
FlowDocumentContribution,
|
||||
FlowRendererContribution,
|
||||
]);
|
||||
bindShortcuts(bind, WorkflowShortcutsContribution, [
|
||||
WorkflowCopyShortcutsContribution,
|
||||
WorkflowPasteShortcutsContribution,
|
||||
// WorkflowDeleteShortcutsContribution,
|
||||
WorkflowLayoutShortcutsContribution,
|
||||
WorkflowZoomShortcutsContribution,
|
||||
WorkflowExportShortcutsContribution,
|
||||
WorkflowLoadShortcutsContribution,
|
||||
WorkflowSelectAllShortcutsContribution,
|
||||
]);
|
||||
bindContributions(bind, FormAbilityExtensionsFormContribution, [
|
||||
FormContribution,
|
||||
]);
|
||||
bindContributions(bind, WorkflowNodeContribution, [NodeContribution]);
|
||||
// WorkflowPageContainerModule 可以改写成函数生成,接收相关 props,目前可以考虑只接收 WorkflowNodesV2Contribution 参数
|
||||
bindContributions(bind, WorkflowNodesV2Contribution, [
|
||||
FlowDocumentContribution,
|
||||
]);
|
||||
|
||||
bind(ValueExpressionService)
|
||||
.to(ValueExpressionServiceImpl)
|
||||
.inSingletonScope();
|
||||
|
||||
bind(DatabaseNodeService).to(DatabaseNodeServiceImpl).inSingletonScope();
|
||||
|
||||
bind(TriggerService).toSelf().inSingletonScope();
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { injectable } from 'inversify';
|
||||
import { type FlowDocumentContribution } from '@flowgram-adapter/free-layout-editor';
|
||||
import { lazyInject } from '@flowgram-adapter/free-layout-editor';
|
||||
import { type WorkflowDocument } from '@flowgram-adapter/free-layout-editor';
|
||||
import {
|
||||
type FlowRendererContribution,
|
||||
FlowRendererKey,
|
||||
type FlowRendererRegistry,
|
||||
} from '@coze-workflow/render';
|
||||
import { WorkflowRenderKey } from '@coze-workflow/nodes';
|
||||
import { StandardNodeType } from '@coze-workflow/base';
|
||||
|
||||
import { WorkflowSaveService } from '../services';
|
||||
import { SubCanvasRender } from '../components/sub-canvas';
|
||||
import { NodeRender } from '../components/node-render';
|
||||
import { LinePopover } from '../components/line-popover';
|
||||
import { CommentRender } from '../components/comment';
|
||||
|
||||
const LINE_POPOVER = 'line-popover';
|
||||
|
||||
@injectable()
|
||||
export class WorkflowPageContribution
|
||||
implements
|
||||
FlowRendererContribution,
|
||||
FlowDocumentContribution<WorkflowDocument>
|
||||
{
|
||||
@lazyInject(WorkflowSaveService) declare saveService: WorkflowSaveService;
|
||||
protected document: WorkflowDocument;
|
||||
|
||||
/**
|
||||
* 注册表单数据
|
||||
* @param document
|
||||
*/
|
||||
// registerDocument(document: WorkflowDocument): void {
|
||||
// document.registerNodeDatas(...createNodeEntityDatas());
|
||||
// }
|
||||
/**
|
||||
* 加载数据
|
||||
*/
|
||||
async loadDocument(doc: WorkflowDocument): Promise<void> {
|
||||
this.document = doc;
|
||||
await this.saveService.loadDocument(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册节点渲染组件
|
||||
* @param registry
|
||||
*/
|
||||
registerRenderer(renderer: FlowRendererRegistry): void {
|
||||
// 注册节点渲染组件
|
||||
renderer.registerReactComponent(FlowRendererKey.NODE_RENDER, NodeRender);
|
||||
|
||||
renderer.registerReactComponent(
|
||||
FlowRendererKey.SUB_CANVAS,
|
||||
SubCanvasRender,
|
||||
);
|
||||
|
||||
renderer.registerReactComponent(StandardNodeType.Comment, CommentRender);
|
||||
|
||||
renderer.registerReactComponent(LINE_POPOVER, LinePopover as any);
|
||||
|
||||
// 注册节点上方 test run 相关渲染组件
|
||||
renderer.registerReactComponent(
|
||||
WorkflowRenderKey.EXECUTE_STATUS_BAR,
|
||||
() => null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user