codecraftai-integration-runtime 1.3.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 (48) hide show
  1. ccai/integrationruntime/__init__.py +27 -0
  2. ccai/integrationruntime/entrypoints.py +59 -0
  3. ccai/integrationruntime/initialize.py +100 -0
  4. ccai/integrationruntime/integratedtestjob.py +100 -0
  5. ccai/integrationruntime/integrationruntimedefaulttypefactory.py +51 -0
  6. ccai/integrationruntime/py.typed +0 -0
  7. ccai/integrationruntime/results/__init__.py +13 -0
  8. ccai/integrationruntime/results/concentrators/__init__.py +13 -0
  9. ccai/integrationruntime/results/concentrators/progressconcentratorservice.py +526 -0
  10. ccai/integrationruntime/results/recorders/__init__.py +22 -0
  11. ccai/integrationruntime/results/recorders/integrationjsonresultrecorder.py +126 -0
  12. ccai/integrationruntime/results/recorders/streamingresultrecorder.py +271 -0
  13. ccai/integrationruntime/results/streaming/__init__.py +25 -0
  14. ccai/integrationruntime/results/streaming/resultstreamer.py +581 -0
  15. ccai/integrationruntime/runtimeoutputcontext.py +68 -0
  16. ccai/integrationruntime/runtimerunmetadata.py +165 -0
  17. ccai/integrationruntime/templates/v2/static/images/test-report-banner-background-image.png +0 -0
  18. ccai/integrationruntime/templates/v2/static/javascript/d3.v7.js +20625 -0
  19. ccai/integrationruntime/templates/v2/static/javascript/icon-components.js +510 -0
  20. ccai/integrationruntime/templates/v2/static/javascript/mojo-components.js +1417 -0
  21. ccai/integrationruntime/templates/v2/static/javascript/prism.js +1789 -0
  22. ccai/integrationruntime/templates/v2/static/javascript/testsummary-accessibility.js +704 -0
  23. ccai/integrationruntime/templates/v2/static/javascript/testsummary-comparison.js +1287 -0
  24. ccai/integrationruntime/templates/v2/static/javascript/testsummary-components.js +3499 -0
  25. ccai/integrationruntime/templates/v2/static/javascript/testsummary-helpers.js +426 -0
  26. ccai/integrationruntime/templates/v2/static/javascript/testsummary-responsive.js +493 -0
  27. ccai/integrationruntime/templates/v2/static/javascript/testsummary.js +1128 -0
  28. ccai/integrationruntime/templates/v2/static/javascript/webcomponent-helpers.js +112 -0
  29. ccai/integrationruntime/templates/v2/static/styles/branding-theme.css +144 -0
  30. ccai/integrationruntime/templates/v2/static/styles/icon-styles.css +9 -0
  31. ccai/integrationruntime/templates/v2/static/styles/mojo-components.css +384 -0
  32. ccai/integrationruntime/templates/v2/static/styles/prism.css +143 -0
  33. ccai/integrationruntime/templates/v2/static/styles/tabs-responsive.css +186 -0
  34. ccai/integrationruntime/templates/v2/static/styles/testsummary-accessibility.css +413 -0
  35. ccai/integrationruntime/templates/v2/static/styles/testsummary-comparison.css +746 -0
  36. ccai/integrationruntime/templates/v2/static/styles/testsummary-responsive.css +679 -0
  37. ccai/integrationruntime/templates/v2/static/styles/testsummary.css +1631 -0
  38. ccai/integrationruntime/templates/v2/tabs/tab-data.html +870 -0
  39. ccai/integrationruntime/templates/v2/tabs/tab-images.html +110 -0
  40. ccai/integrationruntime/templates/v2/tabs/tab-logs.html +594 -0
  41. ccai/integrationruntime/templates/v2/tabs/tab-sounds.html +112 -0
  42. ccai/integrationruntime/templates/v2/tabs/tab-timeseries.html +368 -0
  43. ccai/integrationruntime/templates/v2/tabs/tab-videos.html +372 -0
  44. ccai/integrationruntime/templates/v2/testsummary.html +81 -0
  45. codecraftai_integration_runtime-1.3.0.dist-info/METADATA +73 -0
  46. codecraftai_integration_runtime-1.3.0.dist-info/RECORD +48 -0
  47. codecraftai_integration_runtime-1.3.0.dist-info/WHEEL +4 -0
  48. codecraftai_integration_runtime-1.3.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,870 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <!--
4
+ __author__ = "Myron Walker"
5
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
6
+
7
+ JSON/XML Data Viewer Tab
8
+
9
+ This tab page displays JSON and XML data files with syntax highlighting,
10
+ collapsible tree view, and search functionality.
11
+ -->
12
+ <head>
13
+ <title>Data Files</title>
14
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
15
+
16
+ <script type="text/javascript" src="/static/v2/javascript/testsummary-helpers.js"></script>
17
+ <link rel="stylesheet" href="/static/v2/styles/tabs-responsive.css" ></link>
18
+
19
+ <style>
20
+ * {
21
+ box-sizing: border-box;
22
+ }
23
+
24
+ body {
25
+ margin: 0;
26
+ padding: 10px;
27
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
28
+ font-size: 14px;
29
+ line-height: 1.5;
30
+ }
31
+
32
+ .page-header {
33
+ display: flex;
34
+ flex-wrap: wrap;
35
+ justify-content: space-between;
36
+ align-items: center;
37
+ margin-bottom: 15px;
38
+ padding-bottom: 10px;
39
+ border-bottom: 1px solid #ddd;
40
+ gap: 10px;
41
+ }
42
+
43
+ .page-title {
44
+ margin: 0;
45
+ font-size: 1.5em;
46
+ color: #333;
47
+ }
48
+
49
+ .search-container {
50
+ display: flex;
51
+ flex-wrap: wrap;
52
+ gap: 10px;
53
+ align-items: center;
54
+ }
55
+
56
+ .search-input {
57
+ padding: 8px 12px;
58
+ border: 1px solid #ccc;
59
+ border-radius: 4px;
60
+ font-size: 14px;
61
+ width: 250px;
62
+ max-width: 100%;
63
+ min-height: 44px;
64
+ }
65
+
66
+ .search-input:focus {
67
+ outline: none;
68
+ border-color: #2E5A8F;
69
+ box-shadow: 0 0 3px rgba(46, 90, 143, 0.3);
70
+ }
71
+
72
+ .view-toggle {
73
+ display: flex;
74
+ gap: 5px;
75
+ }
76
+
77
+ .view-btn {
78
+ padding: 8px 12px;
79
+ border: 1px solid #ccc;
80
+ border-radius: 4px;
81
+ background-color: #fff;
82
+ cursor: pointer;
83
+ font-size: 12px;
84
+ min-height: 44px;
85
+ min-width: 44px;
86
+ }
87
+
88
+ .view-btn:hover {
89
+ background-color: #e9e9e9;
90
+ }
91
+
92
+ .view-btn.active {
93
+ background-color: #2E5A8F;
94
+ color: #fff;
95
+ border-color: #2E5A8F;
96
+ }
97
+
98
+ .data-container {
99
+ margin-bottom: 20px;
100
+ border: 1px solid #ddd;
101
+ border-radius: 4px;
102
+ overflow: hidden;
103
+ }
104
+
105
+ .data-header {
106
+ display: flex;
107
+ flex-wrap: wrap;
108
+ justify-content: space-between;
109
+ align-items: center;
110
+ padding: 10px 15px;
111
+ background-color: #f5f5f5;
112
+ border-bottom: 1px solid #ddd;
113
+ cursor: pointer;
114
+ gap: 10px;
115
+ }
116
+
117
+ .data-header:hover {
118
+ background-color: #eee;
119
+ }
120
+
121
+ .data-header-left {
122
+ display: flex;
123
+ flex-wrap: wrap;
124
+ align-items: center;
125
+ gap: 10px;
126
+ }
127
+
128
+ .data-filename {
129
+ font-weight: bold;
130
+ color: #333;
131
+ word-break: break-all;
132
+ }
133
+
134
+ .data-type {
135
+ font-size: 11px;
136
+ padding: 2px 6px;
137
+ border-radius: 3px;
138
+ text-transform: uppercase;
139
+ }
140
+
141
+ .data-type.json {
142
+ background-color: #f0db4f;
143
+ color: #323330;
144
+ }
145
+
146
+ .data-type.xml {
147
+ background-color: #e44d26;
148
+ color: #fff;
149
+ }
150
+
151
+ .data-meta {
152
+ font-size: 12px;
153
+ color: #666;
154
+ }
155
+
156
+ .data-header-right {
157
+ display: flex;
158
+ flex-wrap: wrap;
159
+ align-items: center;
160
+ gap: 10px;
161
+ }
162
+
163
+ .data-btn {
164
+ padding: 8px 12px;
165
+ border: 1px solid #ccc;
166
+ border-radius: 4px;
167
+ background-color: #fff;
168
+ cursor: pointer;
169
+ font-size: 12px;
170
+ min-height: 44px;
171
+ }
172
+
173
+ .data-btn:hover {
174
+ background-color: #e9e9e9;
175
+ }
176
+
177
+ .data-toggle {
178
+ font-size: 18px;
179
+ color: #666;
180
+ user-select: none;
181
+ }
182
+
183
+ .data-content {
184
+ max-height: 600px;
185
+ overflow: auto;
186
+ background-color: #1e1e1e;
187
+ color: #d4d4d4;
188
+ -webkit-overflow-scrolling: touch;
189
+ }
190
+
191
+ .data-content.collapsed {
192
+ display: none;
193
+ }
194
+
195
+ .data-content pre {
196
+ margin: 0;
197
+ padding: 15px;
198
+ font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
199
+ font-size: 13px;
200
+ line-height: 1.4;
201
+ white-space: pre-wrap;
202
+ word-wrap: break-word;
203
+ }
204
+
205
+ /* JSON Syntax Highlighting */
206
+ .json-key {
207
+ color: #9cdcfe;
208
+ }
209
+
210
+ .json-string {
211
+ color: #ce9178;
212
+ }
213
+
214
+ .json-number {
215
+ color: #b5cea8;
216
+ }
217
+
218
+ .json-boolean {
219
+ color: #569cd6;
220
+ }
221
+
222
+ .json-null {
223
+ color: #569cd6;
224
+ }
225
+
226
+ .json-bracket {
227
+ color: #ffd700;
228
+ }
229
+
230
+ /* XML Syntax Highlighting */
231
+ .xml-tag {
232
+ color: #569cd6;
233
+ }
234
+
235
+ .xml-attr-name {
236
+ color: #9cdcfe;
237
+ }
238
+
239
+ .xml-attr-value {
240
+ color: #ce9178;
241
+ }
242
+
243
+ .xml-text {
244
+ color: #d4d4d4;
245
+ }
246
+
247
+ .xml-comment {
248
+ color: #6a9955;
249
+ font-style: italic;
250
+ }
251
+
252
+ /* Tree View Styles */
253
+ .tree-view {
254
+ padding: 15px;
255
+ }
256
+
257
+ .tree-node {
258
+ margin-left: 20px;
259
+ }
260
+
261
+ .tree-node-header {
262
+ display: flex;
263
+ align-items: center;
264
+ cursor: pointer;
265
+ padding: 2px 0;
266
+ }
267
+
268
+ .tree-node-header:hover {
269
+ background-color: #2d2d2d;
270
+ }
271
+
272
+ .tree-toggle {
273
+ width: 16px;
274
+ color: #858585;
275
+ user-select: none;
276
+ }
277
+
278
+ .tree-key {
279
+ color: #9cdcfe;
280
+ margin-right: 5px;
281
+ }
282
+
283
+ .tree-value {
284
+ color: #ce9178;
285
+ }
286
+
287
+ .tree-value.number {
288
+ color: #b5cea8;
289
+ }
290
+
291
+ .tree-value.boolean {
292
+ color: #569cd6;
293
+ }
294
+
295
+ .tree-value.null {
296
+ color: #569cd6;
297
+ }
298
+
299
+ .tree-children {
300
+ display: none;
301
+ }
302
+
303
+ .tree-children.expanded {
304
+ display: block;
305
+ }
306
+
307
+ .tree-type {
308
+ color: #858585;
309
+ font-size: 11px;
310
+ margin-left: 5px;
311
+ }
312
+
313
+ .highlight {
314
+ background-color: #613214;
315
+ color: #fff;
316
+ padding: 1px 2px;
317
+ border-radius: 2px;
318
+ }
319
+
320
+ .no-data {
321
+ padding: 40px;
322
+ text-align: center;
323
+ color: #666;
324
+ }
325
+
326
+ .loading {
327
+ padding: 40px;
328
+ text-align: center;
329
+ color: #666;
330
+ }
331
+
332
+ .copy-feedback {
333
+ position: fixed;
334
+ bottom: 20px;
335
+ right: 20px;
336
+ padding: 10px 20px;
337
+ background-color: #4caf50;
338
+ color: #fff;
339
+ border-radius: 4px;
340
+ display: none;
341
+ z-index: 1000;
342
+ }
343
+ </style>
344
+
345
+ <script type="text/javascript">
346
+ // Supported data file extensions
347
+ const DATA_EXTENSIONS = ["json", "xml", "jsos"];
348
+
349
+ // Global state
350
+ let g_dataFiles = [];
351
+ let g_searchTerm = "";
352
+ let g_viewMode = "formatted"; // "formatted" or "tree"
353
+
354
+ /**
355
+ * Fetch data files from the catalog
356
+ */
357
+ async function fetch_data_files() {
358
+ try {
359
+ const catalog = await fetch_json("catalog.json");
360
+ if (!catalog || !catalog.files) {
361
+ return [];
362
+ }
363
+
364
+ return catalog.files.filter(filename => {
365
+ const ext = filename.split('.').pop().toLowerCase();
366
+ return DATA_EXTENSIONS.includes(ext);
367
+ });
368
+ } catch (err) {
369
+ console.error("Failed to load catalog:", err);
370
+ return [];
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Fetch the content of a data file
376
+ */
377
+ async function fetch_data_content(filename) {
378
+ try {
379
+ const response = await fetch(filename);
380
+ if (!response.ok) {
381
+ throw new Error(`HTTP ${response.status}`);
382
+ }
383
+ return await response.text();
384
+ } catch (err) {
385
+ console.error(`Failed to load ${filename}:`, err);
386
+ return null;
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Escape HTML entities
392
+ */
393
+ function escapeHtml(str) {
394
+ return str
395
+ .replace(/&/g, '&amp;')
396
+ .replace(/</g, '&lt;')
397
+ .replace(/>/g, '&gt;')
398
+ .replace(/"/g, '&quot;');
399
+ }
400
+
401
+ /**
402
+ * Escape special regex characters
403
+ */
404
+ function escapeRegex(string) {
405
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
406
+ }
407
+
408
+ /**
409
+ * Apply search highlighting
410
+ */
411
+ function applyHighlight(text, searchTerm) {
412
+ if (!searchTerm) return text;
413
+ const regex = new RegExp(`(${escapeRegex(searchTerm)})`, 'gi');
414
+ return text.replace(regex, '<span class="highlight">$1</span>');
415
+ }
416
+
417
+ /**
418
+ * Format JSON with syntax highlighting
419
+ */
420
+ function formatJson(content, searchTerm) {
421
+ try {
422
+ const obj = JSON.parse(content);
423
+ const formatted = JSON.stringify(obj, null, 2);
424
+
425
+ // Apply syntax highlighting
426
+ let highlighted = escapeHtml(formatted);
427
+
428
+ // Highlight keys
429
+ highlighted = highlighted.replace(/"([^"]+)":/g, '<span class="json-key">"$1"</span>:');
430
+
431
+ // Highlight string values
432
+ highlighted = highlighted.replace(/: "([^"]*)"/g, ': <span class="json-string">"$1"</span>');
433
+
434
+ // Highlight numbers
435
+ highlighted = highlighted.replace(/: (-?\d+\.?\d*)/g, ': <span class="json-number">$1</span>');
436
+
437
+ // Highlight booleans
438
+ highlighted = highlighted.replace(/: (true|false)/g, ': <span class="json-boolean">$1</span>');
439
+
440
+ // Highlight null
441
+ highlighted = highlighted.replace(/: (null)/g, ': <span class="json-null">$1</span>');
442
+
443
+ // Highlight brackets
444
+ highlighted = highlighted.replace(/([{}\[\]])/g, '<span class="json-bracket">$1</span>');
445
+
446
+ // Apply search highlighting
447
+ if (searchTerm) {
448
+ highlighted = applyHighlight(highlighted, searchTerm);
449
+ }
450
+
451
+ return highlighted;
452
+ } catch (err) {
453
+ return `<span style="color: #f48771;">Error parsing JSON: ${escapeHtml(err.message)}</span>\n\n${escapeHtml(content)}`;
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Format XML with syntax highlighting
459
+ */
460
+ function formatXml(content, searchTerm) {
461
+ let formatted = content;
462
+
463
+ // Simple XML formatting
464
+ let indent = 0;
465
+ const lines = [];
466
+ const tokens = formatted.match(/<[^>]+>|[^<]+/g) || [];
467
+
468
+ tokens.forEach(token => {
469
+ if (token.startsWith('</')) {
470
+ indent--;
471
+ lines.push(' '.repeat(Math.max(0, indent)) + token);
472
+ } else if (token.startsWith('<') && token.endsWith('/>')) {
473
+ lines.push(' '.repeat(indent) + token);
474
+ } else if (token.startsWith('<')) {
475
+ lines.push(' '.repeat(indent) + token);
476
+ if (!token.startsWith('<?') && !token.startsWith('<!')) {
477
+ indent++;
478
+ }
479
+ } else {
480
+ const trimmed = token.trim();
481
+ if (trimmed) {
482
+ lines.push(' '.repeat(indent) + trimmed);
483
+ }
484
+ }
485
+ });
486
+
487
+ formatted = lines.join('\n');
488
+
489
+ // Escape HTML
490
+ let highlighted = escapeHtml(formatted);
491
+
492
+ // Highlight tags
493
+ highlighted = highlighted.replace(/&lt;(\/?[\w:-]+)/g, '&lt;<span class="xml-tag">$1</span>');
494
+ highlighted = highlighted.replace(/([\w:-]+)&gt;/g, '<span class="xml-tag">$1</span>&gt;');
495
+
496
+ // Highlight attributes
497
+ highlighted = highlighted.replace(/(\s)([\w:-]+)=/g, '$1<span class="xml-attr-name">$2</span>=');
498
+ highlighted = highlighted.replace(/="([^"]*)"/g, '="<span class="xml-attr-value">$1</span>"');
499
+
500
+ // Highlight comments
501
+ highlighted = highlighted.replace(/&lt;!--(.*)--&gt;/g, '<span class="xml-comment">&lt;!--$1--&gt;</span>');
502
+
503
+ // Apply search highlighting
504
+ if (searchTerm) {
505
+ highlighted = applyHighlight(highlighted, searchTerm);
506
+ }
507
+
508
+ return highlighted;
509
+ }
510
+
511
+ /**
512
+ * Format JSOS (JSON Stream) with syntax highlighting
513
+ */
514
+ function formatJsos(content, searchTerm) {
515
+ const records = content.split('\x1e').filter(r => r.trim());
516
+ let formatted = '';
517
+
518
+ records.forEach((record, index) => {
519
+ try {
520
+ const obj = JSON.parse(record.trim());
521
+ formatted += `// Record ${index + 1}\n`;
522
+ formatted += formatJson(JSON.stringify(obj), searchTerm);
523
+ formatted += '\n\n';
524
+ } catch (err) {
525
+ formatted += `// Record ${index + 1} (parse error)\n`;
526
+ formatted += escapeHtml(record.trim());
527
+ formatted += '\n\n';
528
+ }
529
+ });
530
+
531
+ return formatted;
532
+ }
533
+
534
+ /**
535
+ * Build tree view for JSON data
536
+ */
537
+ function buildTreeView(data, key = null, depth = 0) {
538
+ const nodeId = `tree-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
539
+
540
+ if (data === null) {
541
+ return `<span class="tree-value null">null</span>`;
542
+ }
543
+
544
+ if (typeof data === 'boolean') {
545
+ return `<span class="tree-value boolean">${data}</span>`;
546
+ }
547
+
548
+ if (typeof data === 'number') {
549
+ return `<span class="tree-value number">${data}</span>`;
550
+ }
551
+
552
+ if (typeof data === 'string') {
553
+ return `<span class="tree-value">"${escapeHtml(data)}"</span>`;
554
+ }
555
+
556
+ if (Array.isArray(data)) {
557
+ if (data.length === 0) {
558
+ return `<span class="json-bracket">[]</span>`;
559
+ }
560
+
561
+ let html = `<div class="tree-node">`;
562
+ html += `<div class="tree-node-header" onclick="toggleTreeNode('${nodeId}')">`;
563
+ html += `<span class="tree-toggle" id="toggle-${nodeId}">â–¶</span>`;
564
+ if (key !== null) {
565
+ html += `<span class="tree-key">"${escapeHtml(key)}":</span>`;
566
+ }
567
+ html += `<span class="json-bracket">[</span>`;
568
+ html += `<span class="tree-type">Array(${data.length})</span>`;
569
+ html += `</div>`;
570
+ html += `<div class="tree-children" id="${nodeId}">`;
571
+
572
+ data.forEach((item, index) => {
573
+ html += `<div class="tree-node">`;
574
+ html += `<span class="tree-key">${index}:</span>`;
575
+ html += buildTreeView(item, null, depth + 1);
576
+ html += `</div>`;
577
+ });
578
+
579
+ html += `</div>`;
580
+ html += `<span class="json-bracket">]</span>`;
581
+ html += `</div>`;
582
+ return html;
583
+ }
584
+
585
+ if (typeof data === 'object') {
586
+ const keys = Object.keys(data);
587
+ if (keys.length === 0) {
588
+ return `<span class="json-bracket">{}</span>`;
589
+ }
590
+
591
+ let html = `<div class="tree-node">`;
592
+ html += `<div class="tree-node-header" onclick="toggleTreeNode('${nodeId}')">`;
593
+ html += `<span class="tree-toggle" id="toggle-${nodeId}">â–¶</span>`;
594
+ if (key !== null) {
595
+ html += `<span class="tree-key">"${escapeHtml(key)}":</span>`;
596
+ }
597
+ html += `<span class="json-bracket">{</span>`;
598
+ html += `<span class="tree-type">Object(${keys.length})</span>`;
599
+ html += `</div>`;
600
+ html += `<div class="tree-children" id="${nodeId}">`;
601
+
602
+ keys.forEach(k => {
603
+ html += `<div class="tree-node">`;
604
+ html += `<span class="tree-key">"${escapeHtml(k)}":</span>`;
605
+ html += buildTreeView(data[k], null, depth + 1);
606
+ html += `</div>`;
607
+ });
608
+
609
+ html += `</div>`;
610
+ html += `<span class="json-bracket">}</span>`;
611
+ html += `</div>`;
612
+ return html;
613
+ }
614
+
615
+ return `<span class="tree-value">${escapeHtml(String(data))}</span>`;
616
+ }
617
+
618
+ /**
619
+ * Toggle tree node expansion
620
+ */
621
+ function toggleTreeNode(nodeId) {
622
+ const children = document.getElementById(nodeId);
623
+ const toggle = document.getElementById(`toggle-${nodeId}`);
624
+
625
+ if (children.classList.contains('expanded')) {
626
+ children.classList.remove('expanded');
627
+ toggle.textContent = 'â–¶';
628
+ } else {
629
+ children.classList.add('expanded');
630
+ toggle.textContent = 'â–¼';
631
+ }
632
+ }
633
+
634
+ /**
635
+ * Toggle data content visibility
636
+ */
637
+ function toggleData(dataId) {
638
+ const contentEl = document.getElementById(`data-content-${dataId}`);
639
+ const toggleEl = document.getElementById(`data-toggle-${dataId}`);
640
+
641
+ if (contentEl.classList.contains('collapsed')) {
642
+ contentEl.classList.remove('collapsed');
643
+ toggleEl.textContent = '−';
644
+ } else {
645
+ contentEl.classList.add('collapsed');
646
+ toggleEl.textContent = '+';
647
+ }
648
+ }
649
+
650
+ /**
651
+ * Copy content to clipboard
652
+ */
653
+ function copyContent(index, event) {
654
+ event.stopPropagation();
655
+ const dataFile = g_dataFiles[index];
656
+ if (dataFile && dataFile.content) {
657
+ navigator.clipboard.writeText(dataFile.content).then(() => {
658
+ showCopyFeedback();
659
+ });
660
+ }
661
+ }
662
+
663
+ /**
664
+ * Download a data file
665
+ */
666
+ function downloadData(filename, event) {
667
+ event.stopPropagation();
668
+ const link = document.createElement('a');
669
+ link.href = filename;
670
+ link.download = filename;
671
+ document.body.appendChild(link);
672
+ link.click();
673
+ document.body.removeChild(link);
674
+ }
675
+
676
+ /**
677
+ * Show copy feedback
678
+ */
679
+ function showCopyFeedback() {
680
+ const feedback = document.getElementById('copy-feedback');
681
+ feedback.style.display = 'block';
682
+ setTimeout(() => {
683
+ feedback.style.display = 'none';
684
+ }, 2000);
685
+ }
686
+
687
+ /**
688
+ * Get file type from extension
689
+ */
690
+ function getFileType(filename) {
691
+ const ext = filename.split('.').pop().toLowerCase();
692
+ if (ext === 'json' || ext === 'jsos') return 'json';
693
+ if (ext === 'xml') return 'xml';
694
+ return 'json';
695
+ }
696
+
697
+ /**
698
+ * Format content based on file type
699
+ */
700
+ function formatContent(content, fileType, searchTerm) {
701
+ if (fileType === 'xml') {
702
+ return formatXml(content, searchTerm);
703
+ }
704
+
705
+ // Check if it's JSOS
706
+ if (content.includes('\x1e')) {
707
+ return formatJsos(content, searchTerm);
708
+ }
709
+
710
+ return formatJson(content, searchTerm);
711
+ }
712
+
713
+ /**
714
+ * Create a data container element
715
+ */
716
+ function createDataContainer(filename, content, index) {
717
+ const container = document.createElement('div');
718
+ container.className = 'data-container';
719
+ container.id = `data-${index}`;
720
+
721
+ const fileType = getFileType(filename);
722
+ const fileSize = new Blob([content]).size;
723
+ const sizeStr = fileSize > 1024
724
+ ? `${(fileSize / 1024).toFixed(1)} KB`
725
+ : `${fileSize} bytes`;
726
+
727
+ let formattedContent;
728
+ if (g_viewMode === 'tree' && fileType === 'json' && !content.includes('\x1e')) {
729
+ try {
730
+ const obj = JSON.parse(content);
731
+ formattedContent = `<div class="tree-view">${buildTreeView(obj)}</div>`;
732
+ } catch (err) {
733
+ formattedContent = `<pre>${formatContent(content, fileType, g_searchTerm)}</pre>`;
734
+ }
735
+ } else {
736
+ formattedContent = `<pre>${formatContent(content, fileType, g_searchTerm)}</pre>`;
737
+ }
738
+
739
+ container.innerHTML = `
740
+ <div class="data-header" onclick="toggleData(${index})">
741
+ <div class="data-header-left">
742
+ <span class="data-filename">${filename}</span>
743
+ <span class="data-type ${fileType}">${fileType}</span>
744
+ <span class="data-meta">${sizeStr}</span>
745
+ </div>
746
+ <div class="data-header-right">
747
+ <button class="data-btn" onclick="copyContent(${index}, event)" title="Copy">📋 Copy</button>
748
+ <button class="data-btn" onclick="downloadData('${filename}', event)" title="Download">⬇ Download</button>
749
+ <span class="data-toggle" id="data-toggle-${index}">−</span>
750
+ </div>
751
+ </div>
752
+ <div class="data-content" id="data-content-${index}">
753
+ ${formattedContent}
754
+ </div>
755
+ `;
756
+
757
+ return container;
758
+ }
759
+
760
+ /**
761
+ * Re-render all data content
762
+ */
763
+ function rerenderData() {
764
+ g_dataFiles.forEach((dataFile, index) => {
765
+ const contentEl = document.getElementById(`data-content-${index}`);
766
+ if (contentEl && dataFile.content) {
767
+ const fileType = getFileType(dataFile.filename);
768
+
769
+ if (g_viewMode === 'tree' && fileType === 'json' && !dataFile.content.includes('\x1e')) {
770
+ try {
771
+ const obj = JSON.parse(dataFile.content);
772
+ contentEl.innerHTML = `<div class="tree-view">${buildTreeView(obj)}</div>`;
773
+ } catch (err) {
774
+ contentEl.innerHTML = `<pre>${formatContent(dataFile.content, fileType, g_searchTerm)}</pre>`;
775
+ }
776
+ } else {
777
+ contentEl.innerHTML = `<pre>${formatContent(dataFile.content, fileType, g_searchTerm)}</pre>`;
778
+ }
779
+ }
780
+ });
781
+ }
782
+
783
+ /**
784
+ * Handle search input
785
+ */
786
+ function handleSearch(event) {
787
+ g_searchTerm = event.target.value;
788
+ rerenderData();
789
+ }
790
+
791
+ /**
792
+ * Set view mode
793
+ */
794
+ function setViewMode(mode) {
795
+ g_viewMode = mode;
796
+
797
+ document.querySelectorAll('.view-btn').forEach(btn => {
798
+ btn.classList.remove('active');
799
+ });
800
+ document.querySelector(`.view-btn[data-mode="${mode}"]`).classList.add('active');
801
+
802
+ rerenderData();
803
+ }
804
+
805
+ /**
806
+ * Refresh the data display
807
+ */
808
+ async function refreshData() {
809
+ const containerEl = document.getElementById('data-container');
810
+ containerEl.innerHTML = '<div class="loading">Loading data files...</div>';
811
+
812
+ const dataFiles = await fetch_data_files();
813
+
814
+ if (dataFiles.length === 0) {
815
+ containerEl.innerHTML = '<div class="no-data">No JSON or XML files found in this directory.</div>';
816
+ return;
817
+ }
818
+
819
+ containerEl.innerHTML = '';
820
+ g_dataFiles = [];
821
+
822
+ for (let i = 0; i < dataFiles.length; i++) {
823
+ const filename = dataFiles[i];
824
+ const content = await fetch_data_content(filename);
825
+
826
+ if (content !== null) {
827
+ g_dataFiles.push({ filename, content });
828
+
829
+ const dataEl = createDataContainer(filename, content, g_dataFiles.length - 1);
830
+ containerEl.appendChild(dataEl);
831
+ }
832
+ }
833
+ }
834
+
835
+ /**
836
+ * Initialize the page
837
+ */
838
+ async function initPage() {
839
+ await refreshData();
840
+ }
841
+
842
+ // Start loading when the page is ready
843
+ document.addEventListener('DOMContentLoaded', initPage);
844
+ </script>
845
+ </head>
846
+
847
+ <body>
848
+ <div class="page-header">
849
+ <h3 class="page-title">Data Files</h3>
850
+ <div class="search-container">
851
+ <input
852
+ type="text"
853
+ class="search-input"
854
+ placeholder="Search in data..."
855
+ oninput="handleSearch(event)"
856
+ >
857
+ <div class="view-toggle">
858
+ <button class="view-btn active" data-mode="formatted" onclick="setViewMode('formatted')">Formatted</button>
859
+ <button class="view-btn" data-mode="tree" onclick="setViewMode('tree')">Tree View</button>
860
+ </div>
861
+ </div>
862
+ </div>
863
+
864
+ <div id="data-container">
865
+ <div class="loading">Loading...</div>
866
+ </div>
867
+
868
+ <div id="copy-feedback" class="copy-feedback">Copied to clipboard!</div>
869
+ </body>
870
+ </html>