index.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { nanoid } from 'nanoid';
  6. import { WorkflowNodeType } from '../constants';
  7. import { FlowNodeRegistry } from '../../typings';
  8. import iconNode from '../../assets/icon-{NODE_NAME}.svg'; // TODO: 准备图标文件
  9. let index = 0;
  10. export const {NODE_NAME}NodeRegistry: FlowNodeRegistry = {
  11. type: WorkflowNodeType.{NODE_TYPE}, // TODO: 在 constants.ts 中定义
  12. info: {
  13. icon: iconNode,
  14. description: '{节点功能描述}', // TODO: 修改描述
  15. },
  16. meta: {
  17. size: {
  18. width: 360,
  19. height: 390,
  20. },
  21. },
  22. onAdd() {
  23. // 返回节点的初始数据,这些数据会被保存到后端
  24. return {
  25. id: `{node_name}_${nanoid(5)}`, // TODO: 修改前缀
  26. type: '{node_type}', // TODO: 与 WorkflowNodeType 保持一致
  27. data: {
  28. title: `{NODE_NAME}_${++index}`, // TODO: 修改标题前缀
  29. // 节点表单字段的初始值
  30. inputsValues: {
  31. // TODO: 根据实际需求定义字段初始值
  32. field1: {
  33. type: 'constant', // 常量类型
  34. content: '默认值', // 字段的初始值
  35. },
  36. field2: {
  37. type: 'constant',
  38. content: 100,
  39. },
  40. promptField: {
  41. type: 'template', // 支持变量的模板类型
  42. content: '',
  43. },
  44. },
  45. // 节点表单的 JSON Schema(定义表单结构)
  46. inputs: {
  47. type: 'object',
  48. required: ['field1'], // TODO: 定义必填字段
  49. properties: {
  50. // TODO: 根据实际需求定义字段 Schema
  51. field1: {
  52. type: 'string',
  53. // 使用默认 Input 组件
  54. },
  55. field2: {
  56. type: 'number',
  57. minimum: 0,
  58. maximum: 100,
  59. },
  60. promptField: {
  61. type: 'string',
  62. // 使用 PromptEditorWithVariables 组件
  63. extra: {
  64. formComponent: 'prompt-editor',
  65. },
  66. },
  67. booleanField: {
  68. type: 'boolean',
  69. // 使用 Switch 组件
  70. },
  71. objectField: {
  72. type: 'object',
  73. // 使用 JsonCodeEditor 组件
  74. },
  75. },
  76. },
  77. // 节点输出数据的 JSON Schema(工作流执行时的输出)
  78. outputs: {
  79. type: 'object',
  80. properties: {
  81. // TODO: 定义节点执行后的输出结构
  82. result: { type: 'string' },
  83. status: { type: 'number' },
  84. },
  85. },
  86. },
  87. };
  88. },
  89. };