@principal-ai/principal-view-core 0.5.6

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.
Files changed (204) hide show
  1. package/README.md +126 -0
  2. package/dist/ConfigurationLoader.d.ts +76 -0
  3. package/dist/ConfigurationLoader.d.ts.map +1 -0
  4. package/dist/ConfigurationLoader.js +144 -0
  5. package/dist/ConfigurationLoader.js.map +1 -0
  6. package/dist/ConfigurationValidator.d.ts +31 -0
  7. package/dist/ConfigurationValidator.d.ts.map +1 -0
  8. package/dist/ConfigurationValidator.js +242 -0
  9. package/dist/ConfigurationValidator.js.map +1 -0
  10. package/dist/EventProcessor.d.ts +49 -0
  11. package/dist/EventProcessor.d.ts.map +1 -0
  12. package/dist/EventProcessor.js +215 -0
  13. package/dist/EventProcessor.js.map +1 -0
  14. package/dist/EventRecorderService.d.ts +305 -0
  15. package/dist/EventRecorderService.d.ts.map +1 -0
  16. package/dist/EventRecorderService.js +463 -0
  17. package/dist/EventRecorderService.js.map +1 -0
  18. package/dist/LibraryLoader.d.ts +63 -0
  19. package/dist/LibraryLoader.d.ts.map +1 -0
  20. package/dist/LibraryLoader.js +188 -0
  21. package/dist/LibraryLoader.js.map +1 -0
  22. package/dist/PathBasedEventProcessor.d.ts +90 -0
  23. package/dist/PathBasedEventProcessor.d.ts.map +1 -0
  24. package/dist/PathBasedEventProcessor.js +239 -0
  25. package/dist/PathBasedEventProcessor.js.map +1 -0
  26. package/dist/SessionManager.d.ts +194 -0
  27. package/dist/SessionManager.d.ts.map +1 -0
  28. package/dist/SessionManager.js +299 -0
  29. package/dist/SessionManager.js.map +1 -0
  30. package/dist/ValidationEngine.d.ts +31 -0
  31. package/dist/ValidationEngine.d.ts.map +1 -0
  32. package/dist/ValidationEngine.js +158 -0
  33. package/dist/ValidationEngine.js.map +1 -0
  34. package/dist/helpers/GraphInstrumentationHelper.d.ts +93 -0
  35. package/dist/helpers/GraphInstrumentationHelper.d.ts.map +1 -0
  36. package/dist/helpers/GraphInstrumentationHelper.js +248 -0
  37. package/dist/helpers/GraphInstrumentationHelper.js.map +1 -0
  38. package/dist/index.d.ts +33 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +34 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/rules/config.d.ts +57 -0
  43. package/dist/rules/config.d.ts.map +1 -0
  44. package/dist/rules/config.js +382 -0
  45. package/dist/rules/config.js.map +1 -0
  46. package/dist/rules/engine.d.ts +70 -0
  47. package/dist/rules/engine.d.ts.map +1 -0
  48. package/dist/rules/engine.js +252 -0
  49. package/dist/rules/engine.js.map +1 -0
  50. package/dist/rules/implementations/connection-type-references.d.ts +7 -0
  51. package/dist/rules/implementations/connection-type-references.d.ts.map +1 -0
  52. package/dist/rules/implementations/connection-type-references.js +104 -0
  53. package/dist/rules/implementations/connection-type-references.js.map +1 -0
  54. package/dist/rules/implementations/dead-end-states.d.ts +17 -0
  55. package/dist/rules/implementations/dead-end-states.d.ts.map +1 -0
  56. package/dist/rules/implementations/dead-end-states.js +72 -0
  57. package/dist/rules/implementations/dead-end-states.js.map +1 -0
  58. package/dist/rules/implementations/index.d.ts +24 -0
  59. package/dist/rules/implementations/index.d.ts.map +1 -0
  60. package/dist/rules/implementations/index.js +62 -0
  61. package/dist/rules/implementations/index.js.map +1 -0
  62. package/dist/rules/implementations/library-node-type-match.d.ts +17 -0
  63. package/dist/rules/implementations/library-node-type-match.d.ts.map +1 -0
  64. package/dist/rules/implementations/library-node-type-match.js +123 -0
  65. package/dist/rules/implementations/library-node-type-match.js.map +1 -0
  66. package/dist/rules/implementations/minimum-node-sources.d.ts +22 -0
  67. package/dist/rules/implementations/minimum-node-sources.d.ts.map +1 -0
  68. package/dist/rules/implementations/minimum-node-sources.js +54 -0
  69. package/dist/rules/implementations/minimum-node-sources.js.map +1 -0
  70. package/dist/rules/implementations/no-unknown-fields.d.ts +7 -0
  71. package/dist/rules/implementations/no-unknown-fields.d.ts.map +1 -0
  72. package/dist/rules/implementations/no-unknown-fields.js +211 -0
  73. package/dist/rules/implementations/no-unknown-fields.js.map +1 -0
  74. package/dist/rules/implementations/orphaned-edge-types.d.ts +7 -0
  75. package/dist/rules/implementations/orphaned-edge-types.d.ts.map +1 -0
  76. package/dist/rules/implementations/orphaned-edge-types.js +47 -0
  77. package/dist/rules/implementations/orphaned-edge-types.js.map +1 -0
  78. package/dist/rules/implementations/orphaned-node-types.d.ts +7 -0
  79. package/dist/rules/implementations/orphaned-node-types.d.ts.map +1 -0
  80. package/dist/rules/implementations/orphaned-node-types.js +50 -0
  81. package/dist/rules/implementations/orphaned-node-types.js.map +1 -0
  82. package/dist/rules/implementations/required-metadata.d.ts +7 -0
  83. package/dist/rules/implementations/required-metadata.d.ts.map +1 -0
  84. package/dist/rules/implementations/required-metadata.js +57 -0
  85. package/dist/rules/implementations/required-metadata.js.map +1 -0
  86. package/dist/rules/implementations/state-transition-references.d.ts +7 -0
  87. package/dist/rules/implementations/state-transition-references.d.ts.map +1 -0
  88. package/dist/rules/implementations/state-transition-references.js +135 -0
  89. package/dist/rules/implementations/state-transition-references.js.map +1 -0
  90. package/dist/rules/implementations/unreachable-states.d.ts +7 -0
  91. package/dist/rules/implementations/unreachable-states.d.ts.map +1 -0
  92. package/dist/rules/implementations/unreachable-states.js +80 -0
  93. package/dist/rules/implementations/unreachable-states.js.map +1 -0
  94. package/dist/rules/implementations/valid-action-patterns.d.ts +17 -0
  95. package/dist/rules/implementations/valid-action-patterns.d.ts.map +1 -0
  96. package/dist/rules/implementations/valid-action-patterns.js +109 -0
  97. package/dist/rules/implementations/valid-action-patterns.js.map +1 -0
  98. package/dist/rules/implementations/valid-color-format.d.ts +7 -0
  99. package/dist/rules/implementations/valid-color-format.d.ts.map +1 -0
  100. package/dist/rules/implementations/valid-color-format.js +91 -0
  101. package/dist/rules/implementations/valid-color-format.js.map +1 -0
  102. package/dist/rules/implementations/valid-edge-types.d.ts +7 -0
  103. package/dist/rules/implementations/valid-edge-types.d.ts.map +1 -0
  104. package/dist/rules/implementations/valid-edge-types.js +244 -0
  105. package/dist/rules/implementations/valid-edge-types.js.map +1 -0
  106. package/dist/rules/implementations/valid-node-types.d.ts +7 -0
  107. package/dist/rules/implementations/valid-node-types.d.ts.map +1 -0
  108. package/dist/rules/implementations/valid-node-types.js +175 -0
  109. package/dist/rules/implementations/valid-node-types.js.map +1 -0
  110. package/dist/rules/index.d.ts +28 -0
  111. package/dist/rules/index.d.ts.map +1 -0
  112. package/dist/rules/index.js +45 -0
  113. package/dist/rules/index.js.map +1 -0
  114. package/dist/rules/types.d.ts +309 -0
  115. package/dist/rules/types.d.ts.map +1 -0
  116. package/dist/rules/types.js +35 -0
  117. package/dist/rules/types.js.map +1 -0
  118. package/dist/types/canvas.d.ts +409 -0
  119. package/dist/types/canvas.d.ts.map +1 -0
  120. package/dist/types/canvas.js +70 -0
  121. package/dist/types/canvas.js.map +1 -0
  122. package/dist/types/index.d.ts +311 -0
  123. package/dist/types/index.d.ts.map +1 -0
  124. package/dist/types/index.js +13 -0
  125. package/dist/types/index.js.map +1 -0
  126. package/dist/types/library.d.ts +185 -0
  127. package/dist/types/library.d.ts.map +1 -0
  128. package/dist/types/library.js +15 -0
  129. package/dist/types/library.js.map +1 -0
  130. package/dist/types/path-based-config.d.ts +230 -0
  131. package/dist/types/path-based-config.d.ts.map +1 -0
  132. package/dist/types/path-based-config.js +9 -0
  133. package/dist/types/path-based-config.js.map +1 -0
  134. package/dist/utils/CanvasConverter.d.ts +118 -0
  135. package/dist/utils/CanvasConverter.d.ts.map +1 -0
  136. package/dist/utils/CanvasConverter.js +315 -0
  137. package/dist/utils/CanvasConverter.js.map +1 -0
  138. package/dist/utils/GraphConverter.d.ts +18 -0
  139. package/dist/utils/GraphConverter.d.ts.map +1 -0
  140. package/dist/utils/GraphConverter.js +61 -0
  141. package/dist/utils/GraphConverter.js.map +1 -0
  142. package/dist/utils/LibraryConverter.d.ts +113 -0
  143. package/dist/utils/LibraryConverter.d.ts.map +1 -0
  144. package/dist/utils/LibraryConverter.js +166 -0
  145. package/dist/utils/LibraryConverter.js.map +1 -0
  146. package/dist/utils/PathMatcher.d.ts +55 -0
  147. package/dist/utils/PathMatcher.d.ts.map +1 -0
  148. package/dist/utils/PathMatcher.js +172 -0
  149. package/dist/utils/PathMatcher.js.map +1 -0
  150. package/dist/utils/YamlParser.d.ts +36 -0
  151. package/dist/utils/YamlParser.d.ts.map +1 -0
  152. package/dist/utils/YamlParser.js +63 -0
  153. package/dist/utils/YamlParser.js.map +1 -0
  154. package/package.json +47 -0
  155. package/src/ConfigurationLoader.test.ts +490 -0
  156. package/src/ConfigurationLoader.ts +185 -0
  157. package/src/ConfigurationValidator.test.ts +200 -0
  158. package/src/ConfigurationValidator.ts +283 -0
  159. package/src/EventProcessor.test.ts +405 -0
  160. package/src/EventProcessor.ts +250 -0
  161. package/src/EventRecorderService.test.ts +541 -0
  162. package/src/EventRecorderService.ts +744 -0
  163. package/src/LibraryLoader.ts +215 -0
  164. package/src/PathBasedEventProcessor.test.ts +567 -0
  165. package/src/PathBasedEventProcessor.ts +332 -0
  166. package/src/SessionManager.test.ts +424 -0
  167. package/src/SessionManager.ts +470 -0
  168. package/src/ValidationEngine.test.ts +371 -0
  169. package/src/ValidationEngine.ts +196 -0
  170. package/src/helpers/GraphInstrumentationHelper.test.ts +340 -0
  171. package/src/helpers/GraphInstrumentationHelper.ts +326 -0
  172. package/src/index.ts +85 -0
  173. package/src/rules/config.test.ts +278 -0
  174. package/src/rules/config.ts +459 -0
  175. package/src/rules/engine.test.ts +332 -0
  176. package/src/rules/engine.ts +318 -0
  177. package/src/rules/implementations/connection-type-references.ts +117 -0
  178. package/src/rules/implementations/dead-end-states.ts +101 -0
  179. package/src/rules/implementations/index.ts +73 -0
  180. package/src/rules/implementations/library-node-type-match.ts +148 -0
  181. package/src/rules/implementations/minimum-node-sources.ts +82 -0
  182. package/src/rules/implementations/no-unknown-fields.ts +342 -0
  183. package/src/rules/implementations/orphaned-edge-types.ts +55 -0
  184. package/src/rules/implementations/orphaned-node-types.ts +58 -0
  185. package/src/rules/implementations/required-metadata.ts +64 -0
  186. package/src/rules/implementations/state-transition-references.ts +151 -0
  187. package/src/rules/implementations/unreachable-states.ts +94 -0
  188. package/src/rules/implementations/valid-action-patterns.ts +136 -0
  189. package/src/rules/implementations/valid-color-format.ts +140 -0
  190. package/src/rules/implementations/valid-edge-types.ts +258 -0
  191. package/src/rules/implementations/valid-node-types.ts +189 -0
  192. package/src/rules/index.ts +95 -0
  193. package/src/rules/types.ts +426 -0
  194. package/src/types/canvas.ts +496 -0
  195. package/src/types/index.ts +382 -0
  196. package/src/types/library.ts +233 -0
  197. package/src/types/path-based-config.ts +281 -0
  198. package/src/utils/CanvasConverter.ts +431 -0
  199. package/src/utils/GraphConverter.test.ts +195 -0
  200. package/src/utils/GraphConverter.ts +71 -0
  201. package/src/utils/LibraryConverter.ts +245 -0
  202. package/src/utils/PathMatcher.test.ts +148 -0
  203. package/src/utils/PathMatcher.ts +183 -0
  204. package/src/utils/YamlParser.ts +75 -0
@@ -0,0 +1,382 @@
1
+ /**
2
+ * Core type definitions for the Principal View Framework
3
+ * Based on GENERIC_GRAPH_PANEL_DESIGN.md
4
+ */
5
+
6
+ // ============================================================================
7
+ // Graph Configuration Types
8
+ // ============================================================================
9
+
10
+ export interface GraphConfiguration {
11
+ /** Metadata about the system being visualized */
12
+ metadata: {
13
+ name: string;
14
+ version: string;
15
+ description?: string;
16
+ };
17
+
18
+ /** Node type definitions */
19
+ nodeTypes: Record<string, NodeTypeDefinition>;
20
+
21
+ /** Edge type definitions */
22
+ edgeTypes: Record<string, EdgeTypeDefinition>;
23
+
24
+ /** Allowed connections between node types */
25
+ allowedConnections: ConnectionRule[];
26
+
27
+ /** Optional validation rules */
28
+ validation?: ValidationRules;
29
+
30
+ /** Display preferences */
31
+ display?: DisplayConfiguration;
32
+ }
33
+
34
+ export interface NodeTypeDefinition {
35
+ /** Visual representation */
36
+ shape: 'circle' | 'rectangle' | 'hexagon' | 'diamond' | 'custom';
37
+ icon?: string;
38
+ /** Fill color (used as primary node color) */
39
+ color?: string;
40
+ /** Stroke/border color */
41
+ stroke?: string;
42
+ size?: { width: number; height: number };
43
+
44
+ /** Data schema for this node type */
45
+ dataSchema: {
46
+ [field: string]: {
47
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
48
+ required?: boolean;
49
+ displayInLabel?: boolean;
50
+ };
51
+ };
52
+
53
+ /** State definitions */
54
+ states?: Record<
55
+ string,
56
+ {
57
+ color?: string;
58
+ icon?: string;
59
+ label?: string;
60
+ }
61
+ >;
62
+
63
+ /** Layout hints */
64
+ layout?: {
65
+ layer?: number;
66
+ cluster?: string;
67
+ };
68
+ }
69
+
70
+ export interface EdgeTypeDefinition {
71
+ /** Visual style */
72
+ style: 'solid' | 'dashed' | 'dotted' | 'animated';
73
+ color?: string;
74
+ width?: number;
75
+ directed?: boolean;
76
+ animated?: boolean;
77
+
78
+ /** Edge label configuration */
79
+ label?: {
80
+ field?: string;
81
+ position?: 'start' | 'middle' | 'end';
82
+ };
83
+
84
+ /** Animation configuration */
85
+ animation?: {
86
+ type: 'flow' | 'pulse' | 'particle' | 'glow';
87
+ duration?: number;
88
+ color?: string;
89
+ };
90
+
91
+ /** Data schema for edge metadata - fields to display when edge is clicked */
92
+ dataSchema?: {
93
+ [field: string]: {
94
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
95
+ label?: string;
96
+ displayInInfo?: boolean;
97
+ };
98
+ };
99
+ }
100
+
101
+ export interface ConnectionRule {
102
+ from: string; // Node type
103
+ to: string; // Node type
104
+ via: string; // Edge type
105
+
106
+ /** Optional constraints */
107
+ constraints?: {
108
+ maxInstances?: number;
109
+ bidirectional?: boolean;
110
+ exclusive?: boolean;
111
+ };
112
+ }
113
+
114
+ export interface ValidationRules {
115
+ /** State transition rules per node type */
116
+ stateTransitions?: Record<
117
+ string,
118
+ Array<{
119
+ from: string;
120
+ to: string[];
121
+ }>
122
+ >;
123
+
124
+ /** Global constraints */
125
+ constraints?: Array<{
126
+ id: string;
127
+ description: string;
128
+ check: string;
129
+ severity: 'info' | 'warning' | 'error';
130
+ }>;
131
+
132
+ /** Cardinality rules */
133
+ cardinality?: Record<
134
+ string,
135
+ {
136
+ min?: number;
137
+ max?: number;
138
+ }
139
+ >;
140
+ }
141
+
142
+ export interface DisplayConfiguration {
143
+ /** Default layout algorithm */
144
+ layout: 'hierarchical' | 'force-directed' | 'circular' | 'manual';
145
+
146
+ /** Color scheme */
147
+ theme?: {
148
+ primary?: string;
149
+ success?: string;
150
+ warning?: string;
151
+ danger?: string;
152
+ info?: string;
153
+ };
154
+
155
+ /** Animation preferences */
156
+ animations?: {
157
+ enabled?: boolean;
158
+ speed?: number;
159
+ };
160
+ }
161
+
162
+ // ============================================================================
163
+ // Event System Types
164
+ // ============================================================================
165
+
166
+ export interface GraphEvent {
167
+ /** Unique event ID */
168
+ id: string;
169
+
170
+ /** Event type (user-defined) */
171
+ type: string;
172
+
173
+ /** When this event occurred */
174
+ timestamp: number;
175
+
176
+ /** Event category */
177
+ category: 'node' | 'edge' | 'state' | 'data' | 'system';
178
+
179
+ /** Event operation */
180
+ operation: 'create' | 'update' | 'delete' | 'animate';
181
+
182
+ /** Event payload */
183
+ payload: NodeEvent | EdgeEvent | StateEvent | DataEvent | SystemEvent;
184
+
185
+ /** Whether this event was expected */
186
+ expected?: boolean;
187
+
188
+ /** Optional metadata */
189
+ metadata?: {
190
+ source?: string;
191
+ tags?: string[];
192
+ description?: string;
193
+ };
194
+ }
195
+
196
+ export interface NodeEvent {
197
+ operation: 'create' | 'update' | 'delete';
198
+ nodeId: string;
199
+ nodeType: string;
200
+ data?: Record<string, any>;
201
+ position?: { x: number; y: number };
202
+ }
203
+
204
+ export interface EdgeEvent {
205
+ operation: 'create' | 'update' | 'delete' | 'animate';
206
+ edgeId: string;
207
+ edgeType: string;
208
+ from: string;
209
+ to: string;
210
+ data?: Record<string, any>;
211
+ animation?: {
212
+ duration?: number;
213
+ direction?: 'forward' | 'backward' | 'bidirectional';
214
+ };
215
+ }
216
+
217
+ export interface StateEvent {
218
+ nodeId: string;
219
+ previousState?: string;
220
+ newState: string;
221
+ data?: Record<string, any>;
222
+ }
223
+
224
+ export interface DataEvent {
225
+ targetId: string;
226
+ targetType: 'node' | 'edge';
227
+ updates: Record<string, any>;
228
+ }
229
+
230
+ export interface SystemEvent {
231
+ action: 'reset' | 'pause' | 'resume' | 'snapshot';
232
+ data?: any;
233
+ }
234
+
235
+ // ============================================================================
236
+ // Event Stream Protocol
237
+ // ============================================================================
238
+
239
+ export interface EventStream {
240
+ /** Configuration (emitted once at start) */
241
+ configuration: GraphConfiguration;
242
+
243
+ /** Initial graph state (optional) */
244
+ initialState?: {
245
+ nodes: Array<{ id: string; type: string; data: any }>;
246
+ edges: Array<{ id: string; type: string; from: string; to: string; data?: any }>;
247
+ };
248
+
249
+ /** Stream of events */
250
+ events: GraphEvent[];
251
+
252
+ /** Optional expected events for validation */
253
+ expectedEvents?: Array<{
254
+ type: string;
255
+ constraints: Record<string, any>;
256
+ timing?: { minTime: number; maxTime: number };
257
+ }>;
258
+ }
259
+
260
+ // ============================================================================
261
+ // Validation Types
262
+ // ============================================================================
263
+
264
+ export interface ValidationResult {
265
+ valid: boolean;
266
+ violations: Violation[];
267
+ warnings: Warning[];
268
+ metrics: ValidationMetrics;
269
+ }
270
+
271
+ export interface Violation {
272
+ id: string;
273
+ severity: 'warning' | 'error';
274
+ type: 'connection' | 'state' | 'cardinality' | 'constraint' | 'unexpected_event';
275
+ description: string;
276
+ event?: GraphEvent;
277
+ context?: {
278
+ nodeId?: string;
279
+ edgeId?: string;
280
+ rule?: string;
281
+ };
282
+ }
283
+
284
+ export interface Warning {
285
+ id: string;
286
+ type: string;
287
+ message: string;
288
+ event?: GraphEvent;
289
+ }
290
+
291
+ export interface ValidationMetrics {
292
+ totalEvents: number;
293
+ validEvents: number;
294
+ violations: number;
295
+ warnings: number;
296
+ unexpectedEvents: number;
297
+ expectedEventsMissing: number;
298
+ }
299
+
300
+ // ============================================================================
301
+ // Graph State Types
302
+ // ============================================================================
303
+
304
+ export interface GraphState {
305
+ nodes: Map<string, NodeState>;
306
+ edges: Map<string, EdgeState>;
307
+ configuration: GraphConfiguration;
308
+ }
309
+
310
+ export interface NodeState {
311
+ id: string;
312
+ type: string;
313
+ data: Record<string, any>;
314
+ state?: string;
315
+ position?: { x: number; y: number };
316
+ createdAt: number;
317
+ updatedAt: number;
318
+ }
319
+
320
+ export interface EdgeState {
321
+ id: string;
322
+ type: string;
323
+ from: string;
324
+ to: string;
325
+ data?: Record<string, any>;
326
+ createdAt: number;
327
+ updatedAt: number;
328
+ }
329
+
330
+ // ============================================================================
331
+ // Metrics Types
332
+ // ============================================================================
333
+
334
+ export interface GraphMetrics {
335
+ /** Node metrics */
336
+ nodes: {
337
+ total: number;
338
+ byType: Record<string, number>;
339
+ byState: Record<string, number>;
340
+ };
341
+
342
+ /** Edge metrics */
343
+ edges: {
344
+ total: number;
345
+ byType: Record<string, number>;
346
+ };
347
+
348
+ /** Event metrics */
349
+ events: {
350
+ total: number;
351
+ byCategory: Record<string, number>;
352
+ byType: Record<string, number>;
353
+ rate: number;
354
+ };
355
+
356
+ /** Validation metrics */
357
+ validation: {
358
+ violations: number;
359
+ warnings: number;
360
+ unexpectedEvents: number;
361
+ healthScore: number;
362
+ };
363
+
364
+ /** Performance metrics */
365
+ performance: {
366
+ renderTime: number;
367
+ eventProcessingTime: number;
368
+ layoutTime: number;
369
+ };
370
+ }
371
+
372
+ // ============================================================================
373
+ // Path-Based Configuration Types (Milestone 1 & 2)
374
+ // ============================================================================
375
+
376
+ export * from './path-based-config';
377
+
378
+ // ============================================================================
379
+ // Component Library Types
380
+ // ============================================================================
381
+
382
+ export * from './library';
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Component Library Types
3
+ *
4
+ * Defines the structure for component libraries (.yaml/.json files)
5
+ * that contain reusable node and edge type definitions.
6
+ *
7
+ * Libraries are separate from canvas files:
8
+ * - Canvas files (.canvas) = actual graph layouts that get rendered
9
+ * - Library files (.yaml/.json) = collections of reusable type definitions
10
+ *
11
+ * When a user adds a component from the library to a canvas,
12
+ * the type definition gets embedded into the node's `pv` field.
13
+ */
14
+
15
+ import type { PVNodeShape, PVEdgeStyle, PVAnimationType, PVActionPattern, PVNodeState } from './canvas';
16
+
17
+ // ============================================================================
18
+ // Library Component Types
19
+ // ============================================================================
20
+
21
+ /**
22
+ * A reusable node component definition in the library.
23
+ * Contains all the information needed to create a canvas node.
24
+ */
25
+ export interface LibraryNodeComponent {
26
+ /** Human-readable description for the library UI */
27
+ description?: string;
28
+
29
+ /** Tags for filtering/categorizing in the library UI */
30
+ tags?: string[];
31
+
32
+ /** Default label/text for the node when added to canvas */
33
+ defaultLabel?: string;
34
+
35
+ /** Visual shape */
36
+ shape: PVNodeShape;
37
+
38
+ /** Icon identifier (Lucide icons) */
39
+ icon?: string;
40
+
41
+ /** Default color */
42
+ color?: string;
43
+
44
+ /** Default size */
45
+ size?: { width: number; height: number };
46
+
47
+ /** State definitions */
48
+ states?: Record<string, PVNodeState>;
49
+
50
+ /** Source file patterns for log association */
51
+ sources?: string[];
52
+
53
+ /** Action patterns for event extraction */
54
+ actions?: PVActionPattern[];
55
+
56
+ /** Data schema for typed fields */
57
+ dataSchema?: Record<
58
+ string,
59
+ {
60
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
61
+ required?: boolean;
62
+ displayInLabel?: boolean;
63
+ }
64
+ >;
65
+
66
+ /** Layout hints */
67
+ layout?: {
68
+ layer?: number;
69
+ cluster?: string;
70
+ };
71
+ }
72
+
73
+ /**
74
+ * A reusable edge type definition in the library.
75
+ */
76
+ export interface LibraryEdgeComponent {
77
+ /** Human-readable description for the library UI */
78
+ description?: string;
79
+
80
+ /** Tags for filtering/categorizing in the library UI */
81
+ tags?: string[];
82
+
83
+ /** Line style */
84
+ style: PVEdgeStyle;
85
+
86
+ /** Line color */
87
+ color?: string;
88
+
89
+ /** Line width in pixels */
90
+ width?: number;
91
+
92
+ /** Whether edge is directed (has arrow) */
93
+ directed?: boolean;
94
+
95
+ /** Default animation */
96
+ animation?: {
97
+ type: PVAnimationType;
98
+ duration?: number;
99
+ color?: string;
100
+ };
101
+
102
+ /** Label configuration */
103
+ label?: {
104
+ field?: string;
105
+ position?: 'start' | 'middle' | 'end';
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Connection rule template for the library.
111
+ * Defines which node types can connect via which edge types.
112
+ */
113
+ export interface LibraryConnectionRule {
114
+ /** Source node type (key from nodeComponents) */
115
+ from: string;
116
+
117
+ /** Target node type (key from nodeComponents) */
118
+ to: string;
119
+
120
+ /** Edge type to use (key from edgeComponents) */
121
+ via: string;
122
+
123
+ /** Optional constraints */
124
+ constraints?: {
125
+ maxInstances?: number;
126
+ bidirectional?: boolean;
127
+ exclusive?: boolean;
128
+ };
129
+ }
130
+
131
+ // ============================================================================
132
+ // Component Library Root Type
133
+ // ============================================================================
134
+
135
+ /**
136
+ * Root type for a component library file (.yaml or .json).
137
+ *
138
+ * Example library.yaml:
139
+ * ```yaml
140
+ * version: "1.0.0"
141
+ * name: "My Project Components"
142
+ * description: "Reusable components for my microservices project"
143
+ *
144
+ * nodeComponents:
145
+ * postgres-db:
146
+ * description: "PostgreSQL database"
147
+ * tags: ["database", "storage"]
148
+ * shape: circle
149
+ * icon: Database
150
+ * color: "#336791"
151
+ * states:
152
+ * connected: { color: "#22c55e", label: "Connected" }
153
+ * disconnected: { color: "#ef4444", label: "Disconnected" }
154
+ * sources:
155
+ * - "src/database/**\/*.ts"
156
+ *
157
+ * rest-api:
158
+ * description: "REST API endpoint"
159
+ * tags: ["api", "http"]
160
+ * shape: rectangle
161
+ * icon: Globe
162
+ * color: "#4A90E2"
163
+ * sources:
164
+ * - "src/api/**\/*.ts"
165
+ *
166
+ * edgeComponents:
167
+ * http-request:
168
+ * description: "HTTP request between services"
169
+ * tags: ["http"]
170
+ * style: solid
171
+ * color: "#4A90E2"
172
+ * directed: true
173
+ * animation:
174
+ * type: flow
175
+ * duration: 1000
176
+ *
177
+ * connectionRules:
178
+ * - from: rest-api
179
+ * to: postgres-db
180
+ * via: db-query
181
+ * ```
182
+ */
183
+ export interface ComponentLibrary {
184
+ /** Library schema version */
185
+ version: string;
186
+
187
+ /** Library name */
188
+ name: string;
189
+
190
+ /** Library description */
191
+ description?: string;
192
+
193
+ /** Reusable node component definitions */
194
+ nodeComponents: Record<string, LibraryNodeComponent>;
195
+
196
+ /** Reusable edge type definitions */
197
+ edgeComponents: Record<string, LibraryEdgeComponent>;
198
+
199
+ /** Optional connection rules (which nodes can connect via which edges) */
200
+ connectionRules?: LibraryConnectionRule[];
201
+ }
202
+
203
+ // ============================================================================
204
+ // Utility Types
205
+ // ============================================================================
206
+
207
+ /**
208
+ * Result of loading a component library
209
+ */
210
+ export interface LibraryLoadResult {
211
+ /** Whether the library was loaded successfully */
212
+ success: boolean;
213
+
214
+ /** The loaded library (if successful) */
215
+ library?: ComponentLibrary;
216
+
217
+ /** Error message (if failed) */
218
+ error?: string;
219
+
220
+ /** Path the library was loaded from */
221
+ path: string;
222
+ }
223
+
224
+ /**
225
+ * Options for the library loader
226
+ */
227
+ export interface LibraryLoaderOptions {
228
+ /** Base directory to search for library files */
229
+ baseDir?: string;
230
+
231
+ /** Custom library file name (default: "library.yaml" or "library.json") */
232
+ fileName?: string;
233
+ }