-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowTypes.ts
186 lines (153 loc) · 4.52 KB
/
flowTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { Edge, Node } from '@xyflow/react';
import React from 'react';
// Node types mapping
export const NODE_TYPES = {
begin: 'begin',
interface: 'interface',
generate: 'generate',
categorize: 'categorize',
retrieval: 'retrieval',
decision: 'decision',
} as const;
export type NodeTypeString = keyof typeof NODE_TYPES;
// Input/Output reference system - simplified for specific node types
export interface InputReference {
sourceNodeId: string;
id: string;
}
// Generic Base Node Data with form type parameter
export type BaseNodeData<TForm = any> = {
label: string;
id: string;
position: { x: number; y: number };
type: NodeTypeString;
[key: string]: unknown;
form: TForm;
_lastUpdate?: number; // Add timestamp field for forcing re-renders
};
export interface BaseForm {
name: string; // This field is essential for display and node identification
description?: string; // Make these optional since not all nodes need them
output?: string;
role?: 'developer' | 'assistant' | 'system' | 'user';
inputRefs?: InputReference[]; // Add support for input references
}
// Form types for each node
export interface BeginForm extends BaseForm {
greeting: string;
variables: {
title: string;
dataIndex: number;
key: string;
}[];
}
export interface InterfaceForm extends BaseForm {
// No additional fields needed for Interface nodes as they just display previous output
displayFormat?: 'text' | 'markdown' | 'html';
}
export interface GenerateForm extends BaseForm {
prompt: string;
model: string;
// No input references here, only template variables
templateVariables?: Record<string, string>;
}
export interface ICategory {
name: string;
description?: string;
examples?: string[];
targetNode?: string; // Add target node field
}
export interface CategorizeForm extends BaseForm {
categories: ICategory[];
defaultCategory: string;
model: string;
}
export interface DecisionForm extends BaseForm {
branches: DecisionBranch[];
defaultTarget: string;
}
export interface RetrievalForm extends BaseForm {
knowledgeIds: string[];
maxResults: number;
threshold: number;
}
// Specialized node data types
export type BeginNodeData = BaseNodeData<BeginForm> & {
type: 'begin';
};
export type InterfaceNodeData = BaseNodeData<InterfaceForm> & {
type: 'interface';
};
export type GenerateNodeData = BaseNodeData<GenerateForm> & {
type: 'generate';
};
export type CategorizeNodeData = BaseNodeData<CategorizeForm> & {
type: 'categorize';
};
export type DecisionNodeData = BaseNodeData<DecisionForm> & {
type: 'decision';
};
export type RetrievalNodeData = BaseNodeData<RetrievalForm> & {
type: 'retrieval';
};
export interface DecisionCondition {
input: string;
operator: string;
value: string;
}
export interface ConditionGroup {
conditions: DecisionCondition[];
logicalOperator: 'AND' | 'OR';
}
export interface DecisionBranch {
name: string;
groups: ConditionGroup[];
groupOperator: 'AND' | 'OR';
targetNode?: string;
}
// Union type for all node data
export type NodeData = BeginNodeData | InterfaceNodeData | GenerateNodeData | CategorizeNodeData | RetrievalNodeData | DecisionNodeData;
// Typed node instances
export type BeginNode = Node<BeginNodeData>;
export type InterfaceNode = Node<InterfaceNodeData>;
export type GenerateNode = Node<GenerateNodeData>;
export type CategorizeNode = Node<CategorizeNodeData>;
export type RetrievalNode = Node<RetrievalNodeData>;
export type DecisionNode = Node<DecisionNodeData>;
// Union type for all flow nodes
export type FlowNode = {
type: NodeTypeString;
} & (BeginNode | InterfaceNode | GenerateNode | CategorizeNode | RetrievalNode | DecisionNode);
// Type for a complete flow
export interface Flow {
nodes: FlowNode[];
edges: Edge[];
}
// Node form field configuration
export interface NodeFormField {
name: string;
label: string;
type: 'input' | 'textarea' | 'select' | 'number' | 'tags';
required?: boolean;
options?: { value: string; label: string }[];
placeholder?: string;
min?: number;
rows?: number;
}
// Input/Output information for node configuration
export interface InputOutputInfo {
}
// Node configuration
export interface NodeConfig {
type: NodeTypeString;
icon?: React.ReactNode;
color: {
background: string;
border: string;
handle: string;
};
input: string; // Description of what input the node accepts
output: string; // Description of what output the node produces
references?: InputReference[]; // Optional references for input/output
data: Partial<NodeData>;
}