@yiyi_zhang/reactflow-ui 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,14 @@
3
3
  "status": "COMPLETED",
4
4
  "startTime": 1704546000000,
5
5
  "endTime": 1704546090000,
6
- "input": { "userType": "premium", "requestId": "req_555" },
7
- "output": { "processed": true, "tier": "premium" },
6
+ "input": {
7
+ "userType": "premium",
8
+ "requestId": "req_555"
9
+ },
10
+ "output": {
11
+ "processed": true,
12
+ "tier": "premium"
13
+ },
8
14
  "workflowDefinition": {
9
15
  "name": "user_tier_workflow",
10
16
  "description": "SWITCH 分支演示:根据用户类型走不同处理路径(premium 分支执行)",
@@ -34,13 +40,18 @@
34
40
  "name": "premium_processing",
35
41
  "taskReferenceName": "premium_proc_ref",
36
42
  "type": "SIMPLE",
37
- "inputParameters": { "priority": "high", "sla": "1h" }
43
+ "inputParameters": {
44
+ "priority": "high",
45
+ "sla": "1h"
46
+ }
38
47
  },
39
48
  {
40
49
  "name": "premium_notify",
41
50
  "taskReferenceName": "premium_notify_ref",
42
51
  "type": "EVENT",
43
- "inputParameters": { "sink": "sqs:premium-events" }
52
+ "inputParameters": {
53
+ "sink": "sqs:premium-events"
54
+ }
44
55
  }
45
56
  ],
46
57
  "standard": [
@@ -48,7 +59,10 @@
48
59
  "name": "standard_processing",
49
60
  "taskReferenceName": "standard_proc_ref",
50
61
  "type": "SIMPLE",
51
- "inputParameters": { "priority": "normal", "sla": "24h" }
62
+ "inputParameters": {
63
+ "priority": "normal",
64
+ "sla": "24h"
65
+ }
52
66
  }
53
67
  ],
54
68
  "free": [
@@ -56,7 +70,9 @@
56
70
  "name": "queue_request",
57
71
  "taskReferenceName": "queue_ref",
58
72
  "type": "SET_VARIABLE",
59
- "inputParameters": { "queuePosition": "${workflow.input.requestId}" }
73
+ "inputParameters": {
74
+ "queuePosition": "${workflow.input.requestId}"
75
+ }
60
76
  }
61
77
  ]
62
78
  },
@@ -81,7 +97,8 @@
81
97
  }
82
98
  }
83
99
  ],
84
- "schemaVersion": 2
100
+ "schemaVersion": 2,
101
+ "restartable": true
85
102
  },
86
103
  "tasks": [
87
104
  {
@@ -91,8 +108,14 @@
91
108
  "taskType": "HTTP",
92
109
  "startTime": 1704546000000,
93
110
  "endTime": 1704546005000,
94
- "inputData": { "uri": "https://api.example.com/users/req_555" },
95
- "outputData": { "userId": "usr_999", "tier": "premium", "email": "user@example.com" }
111
+ "inputData": {
112
+ "uri": "https://api.example.com/users/req_555"
113
+ },
114
+ "outputData": {
115
+ "userId": "usr_999",
116
+ "tier": "premium",
117
+ "email": "user@example.com"
118
+ }
96
119
  },
97
120
  {
98
121
  "taskId": "task_switch_001",
@@ -101,8 +124,12 @@
101
124
  "taskType": "SWITCH",
102
125
  "startTime": 1704546006000,
103
126
  "endTime": 1704546006500,
104
- "inputData": { "switchCaseValue": "premium" },
105
- "outputData": { "caseOutput": "premium" }
127
+ "inputData": {
128
+ "switchCaseValue": "premium"
129
+ },
130
+ "outputData": {
131
+ "caseOutput": "premium"
132
+ }
106
133
  },
107
134
  {
108
135
  "taskId": "task_premium_proc_001",
@@ -111,8 +138,14 @@
111
138
  "taskType": "SIMPLE",
112
139
  "startTime": 1704546007000,
113
140
  "endTime": 1704546040000,
114
- "inputData": { "priority": "high", "sla": "1h" },
115
- "outputData": { "jobId": "job_premium_789", "estimatedTime": "45m" }
141
+ "inputData": {
142
+ "priority": "high",
143
+ "sla": "1h"
144
+ },
145
+ "outputData": {
146
+ "jobId": "job_premium_789",
147
+ "estimatedTime": "45m"
148
+ }
116
149
  },
117
150
  {
118
151
  "taskId": "task_premium_notify_001",
@@ -121,7 +154,9 @@
121
154
  "taskType": "EVENT",
122
155
  "startTime": 1704546041000,
123
156
  "endTime": 1704546043000,
124
- "outputData": { "eventId": "evt_premium_sent" }
157
+ "outputData": {
158
+ "eventId": "evt_premium_sent"
159
+ }
125
160
  },
126
161
  {
127
162
  "taskId": "task_log_001",
@@ -130,7 +165,9 @@
130
165
  "taskType": "INLINE",
131
166
  "startTime": 1704546044000,
132
167
  "endTime": 1704546046000,
133
- "outputData": { "result": "logged" }
168
+ "outputData": {
169
+ "result": "logged"
170
+ }
134
171
  }
135
172
  ]
136
- }
173
+ }
@@ -18,6 +18,26 @@ export declare const callAICopilot: (messages: ChatMessage[], config?: Partial<A
18
18
  * 流式调用 - 通过 onToken 回调逐 token 返回内容
19
19
  */
20
20
  export declare const callAICopilotStream: (messages: ChatMessage[], config: Partial<AIServiceConfig> | undefined, onToken: (token: string) => void, onDone?: () => void, signal?: AbortSignal) => Promise<string>;
21
+ /**
22
+ * 生成任务 inputParameters 的 AI prompt(P4.1)
23
+ */
24
+ export declare const generateTaskParametersPrompt: (taskType: string, taskRef: string, workflowInputParams: string[], upstreamTasks: Array<{
25
+ ref: string;
26
+ type: string;
27
+ name: string;
28
+ }>, currentParams: Record<string, any>) => string;
29
+ /**
30
+ * System Prompt for execution analysis / fault diagnosis(P4.3)
31
+ */
32
+ export declare const EXECUTION_ANALYSIS_SYSTEM_PROMPT = "\nYou are a Netflix Conductor workflow debugging expert.\nWhen given a failed workflow execution, you analyze the task inputs, outputs, and errors to diagnose root causes.\n\nFocus on:\n1. JSONPath expressions that failed to resolve (NullPointerException, PathNotFoundException)\n2. Wrong or missing parameter fields for the task type\n3. Type mismatches between upstream output and task input\n4. Timeout and retry configuration issues\n5. HTTP error codes and what they imply about the request parameters\n\nAlways respond in Chinese. Be concise and actionable.\nIf you suggest a fix, describe specifically which task and which parameter field to change.\n";
33
+ /**
34
+ * AI 自动生成任务 inputParameters(P4.1)
35
+ */
36
+ export declare const generateTaskParameters: (taskType: string, taskRef: string, workflowInputParams: string[], upstreamTasks: Array<{
37
+ ref: string;
38
+ type: string;
39
+ name: string;
40
+ }>, currentParams: Record<string, any>, config?: Partial<AIServiceConfig>) => Promise<Record<string, any>>;
21
41
  /**
22
42
  * System Prompt for Conductor Workflow Modeling
23
43
  */
@@ -72,6 +72,27 @@ export interface TaskDef {
72
72
  timeoutSeconds?: number;
73
73
  timeoutPolicy?: 'RETRY' | 'TIME_OUT_WF' | 'ALERT_ONLY' | 'FAIL_WORKFLOW';
74
74
  }
75
+ /**
76
+ * 工作流入参定义(结构化,向后兼容 string[] 旧格式)
77
+ */
78
+ export interface WorkflowInputParam {
79
+ /** 参数名 */
80
+ name: string;
81
+ /** 参数类型 */
82
+ type?: 'string' | 'number' | 'boolean' | 'object' | 'array';
83
+ /** 用途说明 */
84
+ description?: string;
85
+ /** 是否必填 */
86
+ required?: boolean;
87
+ /** 默认值 */
88
+ defaultValue?: any;
89
+ /** 示例值(在执行验证表单中展示) */
90
+ example?: any;
91
+ }
92
+ /**
93
+ * 解析工作流入参声明:兼容 string[] 旧格式与 WorkflowInputParam[] 新格式
94
+ */
95
+ export declare function parseWorkflowInputParams(raw: any[] | undefined): WorkflowInputParam[];
75
96
  /**
76
97
  * Conductor 工作流定义
77
98
  */
@@ -87,8 +108,8 @@ export interface WorkflowDef {
87
108
  version?: number;
88
109
  /** 任务列表 (DAG 定义) */
89
110
  tasks: TaskDef[];
90
- /** 输入参数定义 (用于文档生成) */
91
- inputParameters?: any[];
111
+ /** 输入参数定义:支持 string[](旧格式)或 WorkflowInputParam[](结构化新格式) */
112
+ inputParameters?: string[] | WorkflowInputParam[];
92
113
  /** 输出参数映射 */
93
114
  outputParameters?: Record<string, any>;
94
115
  schemaVersion?: number;
@@ -1,5 +1,70 @@
1
1
  import { Node, Edge, Position } from 'reactflow';
2
2
  import { WorkflowDef, TaskDef, WorkflowInstance, TaskInstance } from './conductor';
3
+ /**
4
+ * 视图详情级别(独立于编辑模式)
5
+ * - `business`:仅展示核心业务节点,控制/数据节点折叠为边标签
6
+ * - `standard`:业务 + 控制流节点
7
+ * - `developer`:全部节点(含数据转换等)
8
+ */
9
+ export type ViewMode = 'business' | 'standard' | 'developer';
10
+ export interface WorkflowDiffRow {
11
+ kind: 'add' | 'mod' | 'del';
12
+ desc: string;
13
+ }
14
+ export type WorkflowPatchOp = {
15
+ op: 'patchTask';
16
+ ref: string;
17
+ set: Partial<TaskDef>;
18
+ } | {
19
+ op: 'insertAfter';
20
+ after: string;
21
+ edgeTo: string;
22
+ task: TaskDef;
23
+ } | {
24
+ op: 'insertBefore';
25
+ before: string;
26
+ task: TaskDef;
27
+ } | {
28
+ op: 'addTask';
29
+ task: TaskDef;
30
+ extraEdges?: Array<{
31
+ from: string;
32
+ to: string;
33
+ label?: string;
34
+ }>;
35
+ removeEdges?: Array<{
36
+ from: string;
37
+ to: string;
38
+ }>;
39
+ } | {
40
+ op: 'removeTask';
41
+ ref: string;
42
+ } | {
43
+ op: 'addEdge';
44
+ from: string;
45
+ to: string;
46
+ label?: string;
47
+ } | {
48
+ op: 'removeEdge';
49
+ from: string;
50
+ to: string;
51
+ };
52
+ export interface WorkflowDiff {
53
+ kind: 'add' | 'mod' | 'del' | 'replace';
54
+ summary: string;
55
+ rows: WorkflowDiffRow[];
56
+ patch?: WorkflowPatchOp[];
57
+ payload?: WorkflowDef;
58
+ }
59
+ export interface AIChatMessage {
60
+ id: string;
61
+ role: 'user' | 'ai';
62
+ content?: string;
63
+ thinking?: boolean;
64
+ diff?: WorkflowDiff;
65
+ applied?: boolean;
66
+ inverse?: WorkflowDiff;
67
+ }
3
68
  /**
4
69
  * 布局方向
5
70
  */
@@ -74,6 +139,10 @@ export interface WorkflowNodeData {
74
139
  parentRef?: string;
75
140
  edgeData?: Record<string, any>;
76
141
  isDynamicRuntime?: boolean;
142
+ simRunning?: boolean;
143
+ simDone?: boolean;
144
+ _layoutWidth?: number;
145
+ _layoutHeight?: number;
77
146
  }
78
147
  /**
79
148
  * 强类型节点
@@ -91,11 +160,21 @@ export type ThemeMode = 'dark' | 'light';
91
160
  * - `orange`: 活力橙
92
161
  */
93
162
  export type ThemeColor = 'blue' | 'orange';
163
+ /**
164
+ * 执行触发状态机
165
+ * - `idle`: 未触发
166
+ * - `triggering`: 正在调用 onTriggerExecution
167
+ * - `polling`: 已获得 workflowId,正在轮询执行结果
168
+ * - `done`: 执行到达终态(COMPLETED/FAILED/TIMED_OUT/TERMINATED)
169
+ * - `error`: 触发或轮询过程中发生错误
170
+ */
171
+ export type RunState = 'idle' | 'triggering' | 'polling' | 'done' | 'error';
94
172
  /**
95
173
  * 工作流存储状态
96
174
  */
97
175
  export interface WorkflowState {
98
176
  mode: EditorMode;
177
+ viewMode: ViewMode;
99
178
  workflowDef: WorkflowDef | null;
100
179
  workflowInstance: WorkflowInstance | null;
101
180
  nodes: WorkflowNode[];
@@ -113,6 +192,18 @@ export interface WorkflowState {
113
192
  nodesLocked: boolean;
114
193
  copiedTask: TaskDef | null;
115
194
  isDetailPanelOpen: boolean;
195
+ simState: Record<string, 'idle' | 'running' | 'done'>;
196
+ isSimRunning: boolean;
197
+ /** 每次 setWorkflow() 调用时递增,用于触发 WorkflowDesigner 的 fitView */
198
+ workflowLoadKey: number;
199
+ /** P4.2 执行触发状态 */
200
+ runState: RunState;
201
+ pendingExecutionId: string | null;
202
+ executionError: string | null;
203
+ showRunPanel: boolean;
204
+ showAnalysisPanel: boolean;
205
+ /** P4.1 聚焦参数字段("去修复"跳转时使用) */
206
+ focusedParamKey: string | null;
116
207
  }
117
208
  /**
118
209
  * 工作流操作接口
@@ -139,6 +230,7 @@ export interface WorkflowActions {
139
230
  removeLoopTask: (loopRef: string, taskRef: string) => void;
140
231
  addDecisionBranch: (taskRef: string, caseName: string) => void;
141
232
  removeDecisionBranch: (taskRef: string, caseName: string) => void;
233
+ renameDecisionBranch: (taskRef: string, oldName: string, newName: string) => void;
142
234
  addForkBranch: (taskRef: string) => void;
143
235
  copyTask: (task: TaskDef) => void;
144
236
  pasteTask: (task: TaskDef) => void;
@@ -150,18 +242,75 @@ export interface WorkflowActions {
150
242
  applyAIGeneratedWorkflow: (workflowJson: any) => void;
151
243
  setIsDetailPanelOpen: (isOpen: boolean) => void;
152
244
  selectTaskAction: (task: TaskDef | null, openPanel?: boolean) => void;
245
+ setViewMode: (viewMode: ViewMode) => void;
246
+ startSimulation: () => void;
247
+ stopSimulation: () => void;
248
+ /** P4.2: 显示/隐藏执行触发面板 */
249
+ setShowRunPanel: (show: boolean) => void;
250
+ /** P4.2: 显示/隐藏执行分析面板 */
251
+ setShowAnalysisPanel: (show: boolean) => void;
252
+ /** P4.2: 更新执行触发状态 */
253
+ setRunState: (state: RunState, execId?: string | null, error?: string | null) => void;
254
+ /** P4.3: 切回 edit 模式并聚焦到指定任务的指定参数字段 */
255
+ switchToEditAndFocusParam: (taskRef: string, paramKey?: string) => void;
256
+ }
257
+ /**
258
+ * 重启选项
259
+ * - `useLatestDef: true` 使用当前最新工作流定义版本重启
260
+ * - `useLatestDef: false` 使用本次执行时的定义版本重启(默认)
261
+ */
262
+ export interface RestartOptions {
263
+ useLatestDef?: boolean;
153
264
  }
154
265
  /**
155
266
  * 运行态操作回调
156
- * 集成方通过此接口注入工作流执行操作(暂停/恢复/停止/重试/重启)的回调函数。
157
- * 未传入的回调对应的按钮不会渲染。
267
+ * 集成方通过此接口注入工作流执行操作的回调函数;未传入的回调对应的按钮不会渲染。
268
+ *
269
+ * 工作流级别操作:暂停、继续、终止、重试、重新运行(支持版本选择)
270
+ * 任务级别操作:从指定任务重新运行、跳过任务
158
271
  */
159
272
  export interface ExecutionActions {
160
- onRestart?: (workflowId: string) => void;
273
+ /**
274
+ * 是否允许操作。
275
+ * - `true`(默认):所有操作按钮正常可用。
276
+ * - `false`:所有操作按钮置灰并提示"操作权限受限"。
277
+ * @default true
278
+ */
279
+ allowOperations?: boolean;
280
+ /** 暂停工作流(RUNNING → PAUSED) */
161
281
  onPause?: (workflowId: string) => void;
282
+ /** 继续执行暂停中的工作流(PAUSED → RUNNING) */
162
283
  onResume?: (workflowId: string) => void;
284
+ /** 终止工作流(RUNNING/PAUSED → TERMINATED) */
163
285
  onTerminate?: (workflowId: string) => void;
286
+ /** 重试失败的工作流(FAILED/TIMED_OUT/TERMINATED) */
164
287
  onRetry?: (workflowId: string) => void;
288
+ /**
289
+ * 重新运行工作流(需要 workflowDef.restartable = true)
290
+ * @param options.useLatestDef true=使用最新定义版本;false=使用执行时的版本(默认)
291
+ */
292
+ onRestart?: (workflowId: string, options?: RestartOptions) => void;
293
+ /**
294
+ * 从指定任务重新运行(工作流须处于终态:FAILED/TERMINATED/COMPLETED)
295
+ *
296
+ * 对应 Conductor OSS API:POST /workflow/{workflowId}/rerun
297
+ * - body: { reRunFromTaskId: taskId, taskInput: {} }
298
+ *
299
+ * @param workflowId 工作流实例 ID
300
+ * @param taskReferenceName 目标任务的引用名(taskReferenceName)
301
+ * @param taskId 目标任务实例 ID(对应 Conductor API 的 reRunFromTaskId)
302
+ */
303
+ onRerunFromTask?: (workflowId: string, taskReferenceName: string, taskId?: string) => void;
304
+ /**
305
+ * 跳过指定任务(任务须处于 SCHEDULED 或 IN_PROGRESS 状态)
306
+ *
307
+ * 对应 Conductor OSS API:PUT /workflow/{workflowId}/skiptask/{taskReferenceName}
308
+ *
309
+ * @param workflowId 工作流实例 ID
310
+ * @param taskReferenceName 目标任务的引用名(URL path 参数)
311
+ * @param taskId 目标任务实例 ID(可用于请求体附加校验)
312
+ */
313
+ onSkipTask?: (workflowId: string, taskReferenceName: string, taskId?: string) => void;
165
314
  }
166
315
  /**
167
316
  * 组合 Store 类型
@@ -0,0 +1,32 @@
1
+ import { TaskExecutionData, ExecutionStatus } from '../types/workflow';
2
+ import { WorkflowInstance } from '../types/conductor';
3
+ export interface DiagnosticResult {
4
+ category: 'parameter' | 'timeout' | 'auth' | 'network' | 'logic';
5
+ title: string;
6
+ explanation: string;
7
+ suggestEditParam?: string;
8
+ }
9
+ export interface StepInfo {
10
+ taskRef: string;
11
+ status: ExecutionStatus;
12
+ startTime?: number;
13
+ endTime?: number;
14
+ durationMs?: number;
15
+ retryCount: number;
16
+ reasonForIncompletion?: string;
17
+ diagnostics: DiagnosticResult[];
18
+ }
19
+ export interface ExecutionSummary {
20
+ totalTasks: number;
21
+ completedTasks: number;
22
+ failedTasks: number;
23
+ skippedTasks: number;
24
+ totalDurationMs: number;
25
+ steps: StepInfo[];
26
+ hasFailed: boolean;
27
+ }
28
+ export declare function diagnoseTask(taskRef: string, executionData: Record<string, TaskExecutionData>): DiagnosticResult[];
29
+ export declare function analyzeExecution(executionData: Record<string, TaskExecutionData>, workflowInstance: WorkflowInstance | null): ExecutionSummary;
30
+ export declare function formatDuration(ms?: number): string;
31
+ export declare function getCategoryIcon(category: DiagnosticResult['category']): string;
32
+ export declare function getCategoryColor(category: DiagnosticResult['category']): string;
@@ -0,0 +1,11 @@
1
+ import { ViewMode, WorkflowNodeData } from '../types/workflow';
2
+ declare function truncate(s: string, max: number): string;
3
+ /**
4
+ * Returns the meta subtitle for a node based on the current viewMode.
5
+ * - business: task.description (fallback to label)
6
+ * - standard: unchanged (returns fallback)
7
+ * - developer: key config field for the task type
8
+ */
9
+ export declare function getNodeMeta(taskType: string, data: WorkflowNodeData, viewMode: ViewMode, fallback: string): string;
10
+ /** Truncate helper exported for use in node components (e.g. DecisionNode). */
11
+ export { truncate };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 对工作流任务进行拓扑排序,返回按并行波浪分组的执行顺序。
3
+ * 每一波内的任务可以并行执行,波与波之间有依赖关系。
4
+ */
5
+ export declare function buildExecutionWaves(taskRefs: string[], edges: Array<{
6
+ source: string;
7
+ target: string;
8
+ }>): string[][];
@@ -0,0 +1,15 @@
1
+ import { WorkflowDef } from '../types/conductor';
2
+ import { WorkflowDiff } from '../types/workflow';
3
+ /**
4
+ * 将 WorkflowDiff 应用到 WorkflowDef,返回新的 def 以及用于撤销的逆操作 diff。
5
+ * 不修改入参(深拷贝)。
6
+ */
7
+ export declare function applyWorkflowDiff(def: WorkflowDef, diff: WorkflowDiff): {
8
+ next: WorkflowDef;
9
+ inverse: WorkflowDiff;
10
+ };
11
+ /**
12
+ * 从 AI 响应文本中提取 ```diff-json ... ``` 块并解析为 WorkflowDiff。
13
+ * 找不到或解析失败时返回 null。
14
+ */
15
+ export declare function parseDiffFromAIResponse(text: string): WorkflowDiff | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiyi_zhang/reactflow-ui",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Conductor Workflow IDE — a visual workflow designer built with React 19, ReactFlow and Zustand for editing, validating and monitoring Netflix Conductor workflows.",
5
5
  "keywords": [
6
6
  "conductor",
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "scripts": {
38
38
  "dev": "vite",
39
- "build": "tsc && vite build && tsc -p tsconfig.build.json",
39
+ "build": "vite build && tsc -p tsconfig.build.json",
40
40
  "lint": "eslint .",
41
41
  "preview": "vite preview"
42
42
  },