pynode-flow 0.2.0__py3-none-any.whl

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 (227) hide show
  1. pynode/__init__.py +37 -0
  2. pynode/__main__.py +9 -0
  3. pynode/_perf.py +65 -0
  4. pynode/_version.py +24 -0
  5. pynode/api/__init__.py +15 -0
  6. pynode/api/helpers.py +79 -0
  7. pynode/api/nodes.py +423 -0
  8. pynode/api/services.py +124 -0
  9. pynode/api/sse.py +58 -0
  10. pynode/api/uploads.py +59 -0
  11. pynode/api/workflows.py +466 -0
  12. pynode/config.py +93 -0
  13. pynode/install_nodes.py +143 -0
  14. pynode/main.py +118 -0
  15. pynode/node_registry.py +156 -0
  16. pynode/nodes/AutoSyncNode/auto_sync_node.py +151 -0
  17. pynode/nodes/BBoxMetricsNode/__init__.py +3 -0
  18. pynode/nodes/BBoxMetricsNode/bbox_metrics_node.py +250 -0
  19. pynode/nodes/BBoxMetricsNode/requirements.txt +1 -0
  20. pynode/nodes/BatchNode/__init__.py +3 -0
  21. pynode/nodes/BatchNode/batch_node.py +86 -0
  22. pynode/nodes/BatchNode/requirements.txt +1 -0
  23. pynode/nodes/CameraNode/__init__.py +4 -0
  24. pynode/nodes/CameraNode/camera_node.py +204 -0
  25. pynode/nodes/CameraNode/requirements.txt +2 -0
  26. pynode/nodes/ChangeNode/__init__.py +1 -0
  27. pynode/nodes/ChangeNode/change_node.py +255 -0
  28. pynode/nodes/ChangeNode/requirements.txt +1 -0
  29. pynode/nodes/ConfidenceFilterNode/__init__.py +4 -0
  30. pynode/nodes/ConfidenceFilterNode/confidence_filter_node.py +208 -0
  31. pynode/nodes/ConfidenceFilterNode/requirements.txt +1 -0
  32. pynode/nodes/CounterNode/__init__.py +3 -0
  33. pynode/nodes/CounterNode/counter_node.py +191 -0
  34. pynode/nodes/CropNode/__init__.py +4 -0
  35. pynode/nodes/CropNode/crop_node.py +317 -0
  36. pynode/nodes/CropNode/requirements.txt +2 -0
  37. pynode/nodes/DebugNode/__init__.py +4 -0
  38. pynode/nodes/DebugNode/debug_node.py +169 -0
  39. pynode/nodes/DebugNode/requirements.txt +1 -0
  40. pynode/nodes/DelayNode/delay_node.py +218 -0
  41. pynode/nodes/DelayNode/requirements.txt +1 -0
  42. pynode/nodes/DrawPredictionsNode/__init__.py +3 -0
  43. pynode/nodes/DrawPredictionsNode/draw_predictions_node.py +365 -0
  44. pynode/nodes/DrawPredictionsNode/requirements.txt +2 -0
  45. pynode/nodes/ErrorNode/error_node.py +94 -0
  46. pynode/nodes/ErrorNode/requirements.txt +1 -0
  47. pynode/nodes/FilterNode/__init__.py +3 -0
  48. pynode/nodes/FilterNode/filter_node.py +102 -0
  49. pynode/nodes/FilterNode/requirements.txt +1 -0
  50. pynode/nodes/FrameSourceNode/__init__.py +4 -0
  51. pynode/nodes/FrameSourceNode/frame_source_node.py +319 -0
  52. pynode/nodes/FrameSourceNode/requirements.txt +1 -0
  53. pynode/nodes/FunctionNode/__init__.py +3 -0
  54. pynode/nodes/FunctionNode/function_node.py +168 -0
  55. pynode/nodes/FunctionNode/requirements.txt +1 -0
  56. pynode/nodes/GateNode/gate_node.py +60 -0
  57. pynode/nodes/GateNode/requirements.txt +1 -0
  58. pynode/nodes/GetiUploadNode/__init__.py +3 -0
  59. pynode/nodes/GetiUploadNode/geti_upload_node.py +278 -0
  60. pynode/nodes/GetiUploadNode/requirements.txt +1 -0
  61. pynode/nodes/ImageFormatNode/__init__.py +4 -0
  62. pynode/nodes/ImageFormatNode/image_format_node.py +310 -0
  63. pynode/nodes/ImageFormatNode/requirements.txt +2 -0
  64. pynode/nodes/ImageUploadNode/image_upload_node.py +96 -0
  65. pynode/nodes/ImageViewerNode/__init__.py +4 -0
  66. pynode/nodes/ImageViewerNode/image_viewer_node.py +162 -0
  67. pynode/nodes/ImageViewerNode/requirements.txt +2 -0
  68. pynode/nodes/ImageWriterNode/__init__.py +3 -0
  69. pynode/nodes/ImageWriterNode/imagewriter_node.py +352 -0
  70. pynode/nodes/ImageWriterNode/requirements.txt +1 -0
  71. pynode/nodes/InferenceNode/InferenceEngine/__init__.py +15 -0
  72. pynode/nodes/InferenceNode/InferenceEngine/device_detection.py +149 -0
  73. pynode/nodes/InferenceNode/InferenceEngine/engines/base_engine.py +155 -0
  74. pynode/nodes/InferenceNode/InferenceEngine/engines/example_engine_template.py +272 -0
  75. pynode/nodes/InferenceNode/InferenceEngine/engines/geti_engine.py +309 -0
  76. pynode/nodes/InferenceNode/InferenceEngine/engines/onnx_engine.py +346 -0
  77. pynode/nodes/InferenceNode/InferenceEngine/engines/pass_engine.py +86 -0
  78. pynode/nodes/InferenceNode/InferenceEngine/engines/ultralytics_engine.py +863 -0
  79. pynode/nodes/InferenceNode/InferenceEngine/inference_engine_factory.py +533 -0
  80. pynode/nodes/InferenceNode/InferenceEngine/readme.md +107 -0
  81. pynode/nodes/InferenceNode/InferenceEngine/result_converters.py +121 -0
  82. pynode/nodes/InferenceNode/inference_node.py +451 -0
  83. pynode/nodes/InferenceNode/requirements.txt +13 -0
  84. pynode/nodes/InjectNode/inject_node.py +245 -0
  85. pynode/nodes/InjectNode/requirements.txt +1 -0
  86. pynode/nodes/JoinNode/__init__.py +3 -0
  87. pynode/nodes/JoinNode/join_node.py +156 -0
  88. pynode/nodes/JoinNode/requirements.txt +1 -0
  89. pynode/nodes/LabelFilterNode/__init__.py +3 -0
  90. pynode/nodes/LabelFilterNode/label_filter_node.py +188 -0
  91. pynode/nodes/LabelFilterNode/requirements.txt +1 -0
  92. pynode/nodes/MQTTNode/__init__.py +8 -0
  93. pynode/nodes/MQTTNode/mqtt_in_node.py +148 -0
  94. pynode/nodes/MQTTNode/mqtt_out_node.py +157 -0
  95. pynode/nodes/MQTTNode/mqtt_service.py +367 -0
  96. pynode/nodes/MQTTNode/requirements.txt +1 -0
  97. pynode/nodes/MessageWriterNode/__init__.py +7 -0
  98. pynode/nodes/MessageWriterNode/messagereader_node.py +568 -0
  99. pynode/nodes/MessageWriterNode/messagewriter_node.py +505 -0
  100. pynode/nodes/OmronCameraNode/__init__.py +3 -0
  101. pynode/nodes/OmronCameraNode/omron_camera_node.py +652 -0
  102. pynode/nodes/OmronCameraNode/requirements.txt +4 -0
  103. pynode/nodes/OpenCV/__init__.py +1 -0
  104. pynode/nodes/OpenCV/arithmetic_node.py +376 -0
  105. pynode/nodes/OpenCV/bitwise_node.py +127 -0
  106. pynode/nodes/OpenCV/blend_node.py +127 -0
  107. pynode/nodes/OpenCV/blob_detector_node.py +233 -0
  108. pynode/nodes/OpenCV/blur_node.py +141 -0
  109. pynode/nodes/OpenCV/color_space_node.py +139 -0
  110. pynode/nodes/OpenCV/colormap_node.py +262 -0
  111. pynode/nodes/OpenCV/contours_node.py +258 -0
  112. pynode/nodes/OpenCV/denormalize_coords_node.py +365 -0
  113. pynode/nodes/OpenCV/draw_node.py +312 -0
  114. pynode/nodes/OpenCV/edge_detector_node.py +177 -0
  115. pynode/nodes/OpenCV/equirectangular_node.py +447 -0
  116. pynode/nodes/OpenCV/fft_node.py +102 -0
  117. pynode/nodes/OpenCV/focus_estimation_node.py +189 -0
  118. pynode/nodes/OpenCV/frequency_filter_node.py +241 -0
  119. pynode/nodes/OpenCV/histogram_node.py +160 -0
  120. pynode/nodes/OpenCV/hough_circles_node.py +224 -0
  121. pynode/nodes/OpenCV/hough_lines_node.py +243 -0
  122. pynode/nodes/OpenCV/in_range_node.py +186 -0
  123. pynode/nodes/OpenCV/morphology_node.py +136 -0
  124. pynode/nodes/OpenCV/normalize_coords_node.py +344 -0
  125. pynode/nodes/OpenCV/paste_node.py +244 -0
  126. pynode/nodes/OpenCV/perspective_node.py +174 -0
  127. pynode/nodes/OpenCV/realsense_depth_node.py +253 -0
  128. pynode/nodes/OpenCV/requirements.txt +2 -0
  129. pynode/nodes/OpenCV/resize_node.py +175 -0
  130. pynode/nodes/OpenCV/rotate_node.py +159 -0
  131. pynode/nodes/OpenCV/template_match_node.py +227 -0
  132. pynode/nodes/OpenCV/threshold_node.py +167 -0
  133. pynode/nodes/PointInShapeNode/__init__.py +3 -0
  134. pynode/nodes/PointInShapeNode/point_in_shape_node.py +313 -0
  135. pynode/nodes/PointInShapeNode/requirements.txt +2 -0
  136. pynode/nodes/PolygonMetricsNode/__init__.py +3 -0
  137. pynode/nodes/PolygonMetricsNode/polygon_metrics_node.py +331 -0
  138. pynode/nodes/PolygonMetricsNode/requirements.txt +2 -0
  139. pynode/nodes/QueueLengthProbeNode/__init__.py +3 -0
  140. pynode/nodes/QueueLengthProbeNode/queue_length_probe_node.py +116 -0
  141. pynode/nodes/Qwen3VLMNode/__init__.py +3 -0
  142. pynode/nodes/Qwen3VLMNode/qwen3_vlm_node.py +519 -0
  143. pynode/nodes/Qwen3VLMNode/requirements.txt +5 -0
  144. pynode/nodes/RESTEndpointNode/__init__.py +3 -0
  145. pynode/nodes/RESTEndpointNode/rest_endpoint_node.py +491 -0
  146. pynode/nodes/RangeNode/__init__.py +3 -0
  147. pynode/nodes/RangeNode/range_node.py +115 -0
  148. pynode/nodes/RangeNode/requirements.txt +1 -0
  149. pynode/nodes/RateProbeNode/__init__.py +3 -0
  150. pynode/nodes/RateProbeNode/rate_probe_node.py +183 -0
  151. pynode/nodes/RateProbeNode/requirements.txt +1 -0
  152. pynode/nodes/RoboflowUploadNode/__init__.py +3 -0
  153. pynode/nodes/RoboflowUploadNode/requirements.txt +1 -0
  154. pynode/nodes/RoboflowUploadNode/roboflow_upload_node.py +229 -0
  155. pynode/nodes/SliceNode/README.md +149 -0
  156. pynode/nodes/SliceNode/__init__.py +5 -0
  157. pynode/nodes/SliceNode/merge_predictions_node.py +444 -0
  158. pynode/nodes/SliceNode/requirements.txt +3 -0
  159. pynode/nodes/SliceNode/slice_collector_node.py +370 -0
  160. pynode/nodes/SliceNode/slice_image_node.py +380 -0
  161. pynode/nodes/SplitNode/__init__.py +3 -0
  162. pynode/nodes/SplitNode/requirements.txt +1 -0
  163. pynode/nodes/SplitNode/split_node.py +155 -0
  164. pynode/nodes/SwitchNode/requirements.txt +1 -0
  165. pynode/nodes/SwitchNode/switch_node.py +259 -0
  166. pynode/nodes/SyncNode/__init__.py +3 -0
  167. pynode/nodes/SyncNode/sync_node.py +287 -0
  168. pynode/nodes/TemplateNode/requirements.txt +1 -0
  169. pynode/nodes/TemplateNode/template_node.py +86 -0
  170. pynode/nodes/TrackerNode/__init__.py +2 -0
  171. pynode/nodes/TrackerNode/supervision_tracker_node.py +248 -0
  172. pynode/nodes/TrackerNode/tracker_node.py +745 -0
  173. pynode/nodes/UltralyticsNode/__init__.py +4 -0
  174. pynode/nodes/UltralyticsNode/requirements.txt +2 -0
  175. pynode/nodes/UltralyticsNode/ultralytics_node.py +364 -0
  176. pynode/nodes/UnknownNode/__init__.py +93 -0
  177. pynode/nodes/VLLMNode/__init__.py +3 -0
  178. pynode/nodes/VLLMNode/vllm_node.py +345 -0
  179. pynode/nodes/VideoReaderNode/__init__.py +3 -0
  180. pynode/nodes/VideoReaderNode/video_reader_node.py +425 -0
  181. pynode/nodes/VideoWriterNode/__init__.py +3 -0
  182. pynode/nodes/VideoWriterNode/video_writer_node.py +441 -0
  183. pynode/nodes/WebhookNode/__init__.py +3 -0
  184. pynode/nodes/WebhookNode/webhook_node.py +591 -0
  185. pynode/nodes/__init__.py +109 -0
  186. pynode/nodes/base_node.py +562 -0
  187. pynode/nodes/image_utils.py +291 -0
  188. pynode/nodes/info.py +109 -0
  189. pynode/nodes/mDNSNode/__init__.py +13 -0
  190. pynode/nodes/mDNSNode/mdns_broadcast_node.py +214 -0
  191. pynode/nodes/mDNSNode/mdns_discovery_node.py +362 -0
  192. pynode/nodes/mDNSNode/mdns_manager.py +399 -0
  193. pynode/nodes/mDNSNode/requirements.txt +1 -0
  194. pynode/nodes/messages.py +81 -0
  195. pynode/server.py +187 -0
  196. pynode/static/images/favicon4.png +0 -0
  197. pynode/static/index.html +200 -0
  198. pynode/static/js/README.md +139 -0
  199. pynode/static/js/auth.js +89 -0
  200. pynode/static/js/clipboard.js +152 -0
  201. pynode/static/js/config.js +14 -0
  202. pynode/static/js/connections.js +844 -0
  203. pynode/static/js/debug.js +524 -0
  204. pynode/static/js/events.js +775 -0
  205. pynode/static/js/history.js +199 -0
  206. pynode/static/js/main.js +55 -0
  207. pynode/static/js/minimap.js +242 -0
  208. pynode/static/js/nodes.js +995 -0
  209. pynode/static/js/palette.js +255 -0
  210. pynode/static/js/properties.js +1270 -0
  211. pynode/static/js/selection.js +241 -0
  212. pynode/static/js/state.js +211 -0
  213. pynode/static/js/ui-utils.js +28 -0
  214. pynode/static/js/viewport.js +204 -0
  215. pynode/static/js/workflow.js +469 -0
  216. pynode/static/js/workflows.js +344 -0
  217. pynode/static/style.css +2751 -0
  218. pynode/workflow_engine.py +483 -0
  219. pynode/workflow_manager.py +440 -0
  220. pynode_flow-0.2.0.dist-info/METADATA +520 -0
  221. pynode_flow-0.2.0.dist-info/RECORD +227 -0
  222. pynode_flow-0.2.0.dist-info/WHEEL +5 -0
  223. pynode_flow-0.2.0.dist-info/entry_points.txt +3 -0
  224. pynode_flow-0.2.0.dist-info/licenses/LICENSE +21 -0
  225. pynode_flow-0.2.0.dist-info/scm_file_list.json +270 -0
  226. pynode_flow-0.2.0.dist-info/scm_version.json +8 -0
  227. pynode_flow-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,524 @@
1
+ // Debug panel and SSE handling
2
+ import { API_BASE } from './config.js';
3
+ import { state } from './state.js';
4
+
5
+ const MAX_DEBUG_MESSAGES = 100; // Maximum number of messages to keep in UI
6
+ let messageIdCounter = 0; // Unique ID counter for message elements
7
+
8
+ const debugState = {
9
+ messageMap: new Map(), // For collapsing similar messages
10
+ showInfo: true,
11
+ showErrors: true,
12
+ collapseSimilar: false,
13
+ paused: false // When true, new debug/error messages are not added to the list
14
+ };
15
+
16
+ export function startDebugPolling() {
17
+ // EventSource cannot send headers, so the API key (if any) goes in the
18
+ // query string. window.pynodeApiKey is installed by js/auth.js.
19
+ const apiKey = (window.pynodeApiKey && window.pynodeApiKey()) || '';
20
+ const streamUrl = `${API_BASE}/debug/stream` +
21
+ (apiKey ? `?api_key=${encodeURIComponent(apiKey)}` : '');
22
+ const eventSource = new EventSource(streamUrl);
23
+
24
+ eventSource.onmessage = (event) => {
25
+ try {
26
+ const data = JSON.parse(event.data);
27
+
28
+ // Filter by active workflow (skip messages from other workflows)
29
+ if (data.workflowId && state.activeWorkflowId && data.workflowId !== state.activeWorkflowId) {
30
+ return;
31
+ }
32
+
33
+ if (data.type === 'messages' && data.data.length > 0) {
34
+ displayDebugMessages(data.data);
35
+ } else if (data.type === 'errors' && data.data.length > 0) {
36
+ displayErrorMessages(data.data);
37
+ } else if (data.type === 'frame') {
38
+ updateImageViewer(data.nodeId, data.data);
39
+ } else if (data.type === 'rate') {
40
+ updateRateDisplay(data.nodeId, data.display);
41
+ } else if (data.type === 'queue_length') {
42
+ updateQueueLengthDisplay(data.nodeId, data.display);
43
+ } else if (data.type === 'counter') {
44
+ updateCounterDisplay(data.nodeId, data.display);
45
+ } else if (data.type === 'video_position') {
46
+ updateVideoPosition(data.nodeId, data);
47
+ }
48
+ } catch (error) {
49
+ console.error('Error processing SSE message:', error);
50
+ }
51
+ };
52
+
53
+ eventSource.onerror = (error) => {
54
+ console.error('SSE connection error:', error);
55
+ };
56
+
57
+ window.debugEventSource = eventSource;
58
+ }
59
+
60
+ export function updateRateDisplay(nodeId, displayText) {
61
+ const rateEl = document.getElementById(`rate-${nodeId}`);
62
+ if (rateEl) {
63
+ rateEl.textContent = displayText;
64
+ }
65
+ }
66
+
67
+ export function updateQueueLengthDisplay(nodeId, displayText) {
68
+ const queueEl = document.getElementById(`queue-${nodeId}`);
69
+ if (queueEl) {
70
+ queueEl.textContent = displayText;
71
+ }
72
+ }
73
+
74
+ export function updateCounterDisplay(nodeId, displayText) {
75
+ const counterEl = document.getElementById(`counter-${nodeId}`);
76
+ if (counterEl) {
77
+ counterEl.textContent = displayText;
78
+ }
79
+ }
80
+
81
+ export function updateVideoPosition(nodeId, data) {
82
+ const posEl = document.getElementById(`transport-pos-${nodeId}`);
83
+ const sliderEl = document.getElementById(`transport-progress-${nodeId}`);
84
+ const total = data.total > 0 ? data.total : 0;
85
+ const frame = data.frame ?? 0;
86
+ if (posEl) {
87
+ // Zero-pad the current frame to the total's digit count so the label
88
+ // width (and therefore the node width) stays constant as the frame
89
+ // number gains digits (e.g. 003/600 -> 010/600 -> 100/600).
90
+ const current = frame + 1;
91
+ const currentText = total > 0
92
+ ? String(current).padStart(String(total).length, '0')
93
+ : String(current);
94
+ posEl.textContent = `${currentText}/${total > 0 ? total : '?'}`;
95
+ posEl.title = data.playing ? 'Playing' : 'Paused / stopped';
96
+ }
97
+ // Keep the scrub slider in sync unless the user is currently dragging it.
98
+ if (sliderEl && sliderEl.dataset.seeking !== 'true') {
99
+ sliderEl.max = total > 0 ? total - 1 : 0;
100
+ sliderEl.value = frame;
101
+ }
102
+ }
103
+
104
+ export function updateImageViewer(nodeId, frameData) {
105
+ const imgEl = document.getElementById(`viewer-${nodeId}`);
106
+ if (!imgEl) return;
107
+
108
+ if (frameData.format === 'jpeg' && frameData.encoding === 'base64') {
109
+ imgEl.src = `data:image/jpeg;base64,${frameData.data}`;
110
+ }
111
+ }
112
+
113
+ export function displayDebugMessages(messages) {
114
+ // While paused, drop incoming messages so the user can inspect the list
115
+ // without it scrolling. Node UI displays (frames, rates, counters) keep
116
+ // updating - only the debug message list is frozen.
117
+ if (debugState.paused) {
118
+ return;
119
+ }
120
+
121
+ const container = document.getElementById('debug-messages');
122
+
123
+ messages.forEach(msg => {
124
+ const messageKey = `${msg.node}:${JSON.stringify(msg.output)}`;
125
+
126
+ if (debugState.collapseSimilar && debugState.messageMap.has(messageKey)) {
127
+ // Update existing message count
128
+ const existingData = debugState.messageMap.get(messageKey);
129
+ existingData.count++;
130
+ existingData.timestamp = msg.timestamp;
131
+ updateMessageElement(existingData);
132
+ } else {
133
+ // Create new message
134
+ const messageData = {
135
+ id: `msg-${++messageIdCounter}`,
136
+ key: messageKey,
137
+ node: msg.node,
138
+ nodeId: msg.node_id,
139
+ output: msg.output,
140
+ timestamp: msg.timestamp,
141
+ count: 1,
142
+ isError: false,
143
+ display_key: msg.display_key || '',
144
+ element: null // Will be set when element is created
145
+ };
146
+
147
+ if (debugState.collapseSimilar) {
148
+ debugState.messageMap.set(messageKey, messageData);
149
+ }
150
+
151
+ createMessageElement(messageData, container);
152
+ }
153
+ });
154
+
155
+ // Limit number of messages
156
+ trimDebugMessages(container);
157
+
158
+ container.scrollTop = container.scrollHeight;
159
+ }
160
+
161
+ export function displayErrorMessages(errors) {
162
+ // While paused, freeze the list (see displayDebugMessages).
163
+ if (debugState.paused) {
164
+ return;
165
+ }
166
+
167
+ const container = document.getElementById('debug-messages');
168
+
169
+ // Don't process or scroll if errors are hidden
170
+ if (!debugState.showErrors) {
171
+ return;
172
+ }
173
+
174
+ errors.forEach(error => {
175
+ const messageKey = `error:${error.source_node_name}:${error.message}`;
176
+
177
+ if (debugState.collapseSimilar && debugState.messageMap.has(messageKey)) {
178
+ // Update existing error count
179
+ const existingData = debugState.messageMap.get(messageKey);
180
+ existingData.count++;
181
+ existingData.timestamp = new Date(error.timestamp * 1000).toLocaleTimeString();
182
+ updateMessageElement(existingData);
183
+ } else {
184
+ // Create new error message
185
+ const messageData = {
186
+ id: `msg-${++messageIdCounter}`,
187
+ key: messageKey,
188
+ node: error.source_node_name,
189
+ nodeId: error.source_node_id,
190
+ output: error.message,
191
+ timestamp: new Date(error.timestamp * 1000).toLocaleTimeString(),
192
+ count: 1,
193
+ isError: true,
194
+ element: null // Will be set when element is created
195
+ };
196
+
197
+ if (debugState.collapseSimilar) {
198
+ debugState.messageMap.set(messageKey, messageData);
199
+ }
200
+
201
+ createMessageElement(messageData, container);
202
+ }
203
+ });
204
+
205
+ // Limit number of messages
206
+ trimDebugMessages(container);
207
+
208
+ container.scrollTop = container.scrollHeight;
209
+ }
210
+
211
+ function createMessageElement(messageData, container) {
212
+ const msgEl = document.createElement('div');
213
+ msgEl.className = messageData.isError ? 'debug-message error-message' : 'debug-message';
214
+ msgEl.id = messageData.id;
215
+ msgEl.dataset.nodeId = messageData.nodeId;
216
+ msgEl.dataset.isError = messageData.isError;
217
+
218
+ // Store reference to the element
219
+ messageData.element = msgEl;
220
+
221
+ updateMessageContent(msgEl, messageData);
222
+
223
+ // Make message clickable to jump to node
224
+ msgEl.addEventListener('click', () => {
225
+ jumpToNode(messageData.nodeId);
226
+ });
227
+
228
+ // Apply filters
229
+ applyFiltersToMessage(msgEl);
230
+
231
+ container.appendChild(msgEl);
232
+ }
233
+
234
+ function updateMessageElement(messageData) {
235
+ // Use stored element reference instead of querySelector
236
+ if (messageData.element) {
237
+ updateMessageContent(messageData.element, messageData);
238
+ }
239
+ }
240
+
241
+ // Get type label for a value
242
+ function getTypeLabel(value) {
243
+ if (value === null) return 'null';
244
+ if (value === undefined) return 'undefined';
245
+ if (Array.isArray(value)) return `array[${value.length}]`;
246
+ if (typeof value === 'object') return 'object';
247
+ return typeof value;
248
+ }
249
+
250
+ // Render a value as a collapsible tree (compact single-line style)
251
+ function renderTreeValue(value, key = null, depth = 0) {
252
+ if (value === null) {
253
+ return `<span class="tv-null">null</span>`;
254
+ }
255
+ if (value === undefined) {
256
+ return `<span class="tv-undefined">undefined</span>`;
257
+ }
258
+ if (typeof value === 'boolean') {
259
+ return `<span class="tv-bool">${value}</span>`;
260
+ }
261
+ if (typeof value === 'number') {
262
+ return `<span class="tv-num">${value}</span>`;
263
+ }
264
+ if (typeof value === 'string') {
265
+ const maxLen = 100;
266
+ const displayStr = value.length > maxLen ? value.substring(0, maxLen) + '...' : value;
267
+ const escaped = displayStr.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
268
+ return `<span class="tv-str" title="${value.length > maxLen ? value.length + ' chars' : ''}">"${escaped}"</span>`;
269
+ }
270
+
271
+ if (Array.isArray(value)) {
272
+ if (value.length === 0) {
273
+ return `<span class="tv-empty">[]</span>`;
274
+ }
275
+ let childrenHtml = '';
276
+ value.forEach((item, index) => {
277
+ const typeLabel = getTypeLabel(item);
278
+ const isExpandable = item !== null && typeof item === 'object';
279
+ if (isExpandable) {
280
+ childrenHtml += `<div class="ti c" style="margin-left:${(depth+1)*8}px"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${index}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(item, depth+1)}</div></div>`;
281
+ } else {
282
+ childrenHtml += `<div class="ti" style="margin-left:${(depth+1)*8}px"><span class="tk">${index}</span>: ${renderTreeValue(item, index, depth+1)}</div>`;
283
+ }
284
+ });
285
+ return childrenHtml;
286
+ }
287
+
288
+ if (typeof value === 'object') {
289
+ const keys = Object.keys(value);
290
+ if (keys.length === 0) {
291
+ return `<span class="tv-empty">{}</span>`;
292
+ }
293
+ let childrenHtml = '';
294
+ keys.forEach(k => {
295
+ const v = value[k];
296
+ const typeLabel = getTypeLabel(v);
297
+ const isExpandable = v !== null && typeof v === 'object';
298
+ const escaped = k.replace(/</g, '&lt;').replace(/>/g, '&gt;');
299
+ if (isExpandable) {
300
+ childrenHtml += `<div class="ti c" style="margin-left:${(depth+1)*8}px"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${escaped}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(v, depth+1)}</div></div>`;
301
+ } else {
302
+ childrenHtml += `<div class="ti" style="margin-left:${(depth+1)*8}px"><span class="tk">${escaped}</span>: ${renderTreeValue(v, k, depth+1)}</div>`;
303
+ }
304
+ });
305
+ return childrenHtml;
306
+ }
307
+
308
+ return `<span class="tv">${String(value)}</span>`;
309
+ }
310
+
311
+ // Render children of an object/array
312
+ function renderTreeChildren(value, depth) {
313
+ if (Array.isArray(value)) {
314
+ let html = '';
315
+ value.forEach((item, index) => {
316
+ const typeLabel = getTypeLabel(item);
317
+ const isExpandable = item !== null && typeof item === 'object';
318
+ if (isExpandable) {
319
+ html += `<div class="ti c" style="margin-left:${(depth+1)*8}px"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${index}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(item, depth+1)}</div></div>`;
320
+ } else {
321
+ html += `<div class="ti" style="margin-left:${(depth+1)*8}px"><span class="tk">${index}</span>: ${renderTreeValue(item, index, depth+1)}</div>`;
322
+ }
323
+ });
324
+ return html;
325
+ }
326
+ if (typeof value === 'object' && value !== null) {
327
+ let html = '';
328
+ Object.keys(value).forEach(k => {
329
+ const v = value[k];
330
+ const typeLabel = getTypeLabel(v);
331
+ const isExpandable = v !== null && typeof v === 'object';
332
+ const escaped = k.replace(/</g, '&lt;').replace(/>/g, '&gt;');
333
+ if (isExpandable) {
334
+ html += `<div class="ti c" style="margin-left:${(depth+1)*8}px"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${escaped}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(v, depth+1)}</div></div>`;
335
+ } else {
336
+ html += `<div class="ti" style="margin-left:${(depth+1)*8}px"><span class="tk">${escaped}</span>: ${renderTreeValue(v, k, depth+1)}</div>`;
337
+ }
338
+ });
339
+ return html;
340
+ }
341
+ return renderTreeValue(value, null, depth);
342
+ }
343
+
344
+ // Render the complete message output as a tree
345
+ function renderOutputTree(output, isError) {
346
+ if (output === null || output === undefined) {
347
+ return `<span class="tv-null">${output}</span>`;
348
+ }
349
+ if (typeof output !== 'object') {
350
+ return renderTreeValue(output);
351
+ }
352
+
353
+ const icon = isError ? '⚠️ ' : '';
354
+ let html = icon + '<div class="tree-root">';
355
+
356
+ if (Array.isArray(output)) {
357
+ output.forEach((item, index) => {
358
+ const typeLabel = getTypeLabel(item);
359
+ const isExpandable = item !== null && typeof item === 'object';
360
+ if (isExpandable) {
361
+ html += `<div class="ti c"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${index}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(item, 0)}</div></div>`;
362
+ } else {
363
+ html += `<div class="ti"><span class="tk">${index}</span>: ${renderTreeValue(item, index, 0)}</div>`;
364
+ }
365
+ });
366
+ } else {
367
+ Object.keys(output).forEach(key => {
368
+ const v = output[key];
369
+ const typeLabel = getTypeLabel(v);
370
+ const isExpandable = v !== null && typeof v === 'object';
371
+ const escaped = key.replace(/</g, '&lt;').replace(/>/g, '&gt;');
372
+ if (isExpandable) {
373
+ html += `<div class="ti c"><span class="tt" onclick="event.stopPropagation();this.parentElement.classList.toggle('c')">▶</span><span class="tk">${escaped}</span>: <span class="tl">${typeLabel}</span><div class="tc">${renderTreeChildren(v, 0)}</div></div>`;
374
+ } else {
375
+ html += `<div class="ti"><span class="tk">${escaped}</span>: ${renderTreeValue(v, key, 0)}</div>`;
376
+ }
377
+ });
378
+ }
379
+
380
+ html += '</div>';
381
+ return html;
382
+ }
383
+
384
+ function updateMessageContent(msgEl, messageData) {
385
+ const countBadge = messageData.count > 1 ? `<span class="debug-count">${messageData.count}</span>` : '';
386
+ const nodeClass = messageData.isError ? 'debug-node error-node' : 'debug-node';
387
+ const outputClass = messageData.isError ? 'debug-output error-output' : 'debug-output';
388
+
389
+ // Show display_key (e.g. "msg.payload") before node name in header, if present
390
+ const keyLabel = messageData.display_key ? `<span class="debug-key">${messageData.display_key}</span> ` : '';
391
+
392
+ // Render output as collapsible tree
393
+ const outputHtml = renderOutputTree(messageData.output, messageData.isError);
394
+
395
+ msgEl.innerHTML = `
396
+ <div class="debug-message-header">
397
+ <span class="debug-timestamp">${messageData.timestamp}</span>
398
+ <span class="${nodeClass}">[${messageData.node}]</span>
399
+ ${countBadge}
400
+ </div>
401
+ ${keyLabel ? `<div class="debug-key-label">${keyLabel}:</div>` : ''}
402
+ <div class="${outputClass}">${outputHtml}</div>
403
+ `;
404
+ }
405
+
406
+ function jumpToNode(nodeId) {
407
+ if (!nodeId) return;
408
+
409
+ const nodeEl = document.getElementById(`node-${nodeId}`);
410
+ if (!nodeEl) return;
411
+
412
+ // Deselect all nodes first
413
+ import('./selection.js').then(({ deselectAllNodes, selectNode }) => {
414
+ deselectAllNodes();
415
+ selectNode(nodeId);
416
+
417
+ // Scroll node into view. offsetLeft/offsetWidth are canvas
418
+ // (untransformed) px; scroll offsets are in zoomed px, so scale.
419
+ const canvasContainer = document.querySelector('.canvas-container');
420
+ const containerRect = canvasContainer.getBoundingClientRect();
421
+
422
+ import('./viewport.js').then(({ getZoom }) => {
423
+ const zoom = getZoom();
424
+ const nodeCenterX = nodeEl.offsetLeft + nodeEl.offsetWidth / 2;
425
+ const nodeCenterY = nodeEl.offsetTop + nodeEl.offsetHeight / 2;
426
+
427
+ // Calculate scroll position to center the node
428
+ const scrollX = nodeCenterX * zoom - containerRect.width / 2;
429
+ const scrollY = nodeCenterY * zoom - containerRect.height / 2;
430
+
431
+ canvasContainer.scrollTo({
432
+ left: scrollX,
433
+ top: scrollY,
434
+ behavior: 'smooth'
435
+ });
436
+ });
437
+
438
+ // Flash effect
439
+ nodeEl.style.animation = 'none';
440
+ setTimeout(() => {
441
+ nodeEl.style.animation = 'flash 0.5s ease-in-out 2';
442
+ }, 10);
443
+ });
444
+ }
445
+
446
+ function applyFiltersToMessage(msgEl) {
447
+ const isError = msgEl.dataset.isError === 'true';
448
+
449
+ if (isError && !debugState.showErrors) {
450
+ msgEl.classList.add('hidden');
451
+ } else if (!isError && !debugState.showInfo) {
452
+ msgEl.classList.add('hidden');
453
+ } else {
454
+ msgEl.classList.remove('hidden');
455
+ }
456
+ }
457
+
458
+ function applyAllFilters() {
459
+ const messages = document.querySelectorAll('.debug-message');
460
+ messages.forEach(msgEl => applyFiltersToMessage(msgEl));
461
+ }
462
+
463
+ export function toggleInfoMessages(show) {
464
+ debugState.showInfo = show;
465
+ applyAllFilters();
466
+ }
467
+
468
+ export function toggleErrorMessages(show) {
469
+ debugState.showErrors = show;
470
+ applyAllFilters();
471
+ }
472
+
473
+ /**
474
+ * Toggle the paused state of the debug list. When paused, new debug/error
475
+ * messages are dropped (not rendered) so the current view stays put.
476
+ * Returns the new paused state.
477
+ */
478
+ export function toggleDebugPaused() {
479
+ debugState.paused = !debugState.paused;
480
+ return debugState.paused;
481
+ }
482
+
483
+ export function isDebugPaused() {
484
+ return debugState.paused;
485
+ }
486
+
487
+ export function toggleCollapseSimilar(collapse) {
488
+ debugState.collapseSimilar = collapse;
489
+
490
+ if (!collapse) {
491
+ // Clear the message map and reset all counts to 1
492
+ debugState.messageMap.clear();
493
+ const messages = document.querySelectorAll('.debug-message');
494
+ messages.forEach(msgEl => {
495
+ const countBadge = msgEl.querySelector('.debug-count');
496
+ if (countBadge) {
497
+ countBadge.remove();
498
+ }
499
+ });
500
+ }
501
+ }
502
+
503
+ function trimDebugMessages(container) {
504
+ const messages = container.querySelectorAll('.debug-message');
505
+ if (messages.length > MAX_DEBUG_MESSAGES) {
506
+ const removeCount = messages.length - MAX_DEBUG_MESSAGES;
507
+ for (let i = 0; i < removeCount; i++) {
508
+ const msgEl = messages[i];
509
+ // Find and remove from messageMap by element reference
510
+ for (const [key, data] of debugState.messageMap.entries()) {
511
+ if (data.element === msgEl) {
512
+ debugState.messageMap.delete(key);
513
+ break;
514
+ }
515
+ }
516
+ msgEl.remove();
517
+ }
518
+ }
519
+ }
520
+
521
+ export function clearDebug() {
522
+ document.getElementById('debug-messages').innerHTML = '';
523
+ debugState.messageMap.clear();
524
+ }