-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2451 lines (2245 loc) · 107 KB
/
index.html
File metadata and controls
2451 lines (2245 loc) · 107 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; form-action 'none'; base-uri 'none';">
<meta name="referrer" content="no-referrer">
<title>AgentLens — Agentforce Trace Visualizer</title>
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{height:100%}
:root{
--bg:#0f1117;--surface:#1a1d27;--surface2:#242836;--border:#2e3348;
--text:#e2e4ed;--text-dim:#8b8fa3;--text-bright:#ffffff;
--blue:#4e8cff;--blue-bg:rgba(78,140,255,.12);--blue-border:rgba(78,140,255,.3);
--green:#34d399;--green-bg:rgba(52,211,153,.12);--green-border:rgba(52,211,153,.3);
--purple:#a78bfa;--purple-bg:rgba(167,139,250,.12);--purple-border:rgba(167,139,250,.3);
--orange:#fb923c;--orange-bg:rgba(251,146,60,.12);--orange-border:rgba(251,146,60,.3);
--gray:#6b7280;--teal:#2dd4bf;--cyan:#22d3ee;--yellow:#fbbf24;--red:#f87171;
--radius:10px;--radius-sm:6px;
--font-mono:'SF Mono','Cascadia Code','Fira Code',Consolas,monospace;
}
.light{
--bg:#f5f6fa;--surface:#ffffff;--surface2:#f0f1f5;--border:#d4d7e3;
--text:#1e2030;--text-dim:#6b7084;--text-bright:#000000;
--blue:#2563eb;--blue-bg:rgba(37,99,235,.08);--blue-border:rgba(37,99,235,.25);
--green:#059669;--green-bg:rgba(5,150,105,.08);--green-border:rgba(5,150,105,.25);
--purple:#7c3aed;--purple-bg:rgba(124,58,237,.08);--purple-border:rgba(124,58,237,.25);
--orange:#ea580c;--orange-bg:rgba(234,88,12,.08);--orange-border:rgba(234,88,12,.25);
--gray:#6b7280;--teal:#0d9488;--cyan:#0891b2;--yellow:#d97706;--red:#dc2626;
}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,sans-serif;
background:var(--bg);color:var(--text);line-height:1.5;min-height:100vh;
display:flex;flex-direction:column}
body.app-viz{height:100vh;overflow:hidden}
.app-header{flex-shrink:0;background:var(--surface);border-bottom:1px solid var(--border);padding:8px 20px;
display:flex;align-items:center;gap:14px;flex-wrap:wrap;z-index:100}
.app-header h1{font-size:17px;font-weight:700;color:var(--text-bright)}
.header-meta{display:flex;gap:12px;flex-wrap:wrap;flex:1}
.meta-chip{font-size:11px;background:var(--surface2);border:1px solid var(--border);
border-radius:20px;padding:4px 10px;color:var(--text-dim)}
.meta-chip strong{color:var(--text);font-weight:600}
.header-actions{display:flex;gap:8px;align-items:center}
.btn{background:var(--surface2);border:1px solid var(--border);border-radius:var(--radius-sm);
color:var(--text);padding:6px 12px;font-size:12px;cursor:pointer;font-weight:500}
.btn:hover{border-color:var(--blue);color:var(--blue)}
#mainViz:not(.hidden){display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden}
.layout{display:grid;grid-template-columns:1.1fr 1fr;gap:10px;max-width:1680px;width:100%;
margin:0 auto;padding:10px 16px;flex:1;min-height:0;align-items:stretch}
@media(max-width:1024px){.layout{grid-template-columns:1fr;height:auto;min-height:0}}
.panel--inspector{display:flex;flex-direction:column;min-height:0;overflow:hidden}
.panel--inspector .fsm-playbar{flex-shrink:0}
.panel--inspector .fsm-single-card{flex:1;overflow-y:auto;padding:14px 16px}
.panel--context{display:flex;flex-direction:column;min-height:0;overflow:hidden}
.panel--context .graph-wrap#fsmWrap{flex:1 1 0;min-height:120px;overflow:hidden}
.panel--context .topic-list{flex-shrink:0;border-bottom:1px solid var(--border);display:flex;flex-wrap:wrap;gap:4px;padding:6px 10px}
.topic-pill{font-size:11px;padding:4px 10px;border-radius:999px;background:var(--surface2);border:1px solid var(--border);
color:var(--text-dim);cursor:pointer;font-weight:500;transition:border-color .15s,color .15s,background .15s;white-space:nowrap}
.topic-pill:hover{border-color:var(--blue);color:var(--blue)}
.topic-pill.active{border-color:var(--cyan);color:var(--cyan);background:rgba(34,211,238,.1)}
.light .topic-pill.active{border-color:var(--cyan);color:var(--cyan);background:rgba(8,145,178,.08)}
.panel{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);
overflow:hidden;display:flex;flex-direction:column;min-height:0;max-height:100%;transition:width .3s ease,min-width .3s ease}
.panel-h{padding:10px 14px;border-bottom:1px solid var(--border);font-size:clamp(11px,1.4vw,13px);font-weight:700;
color:var(--text-bright);text-transform:uppercase;letter-spacing:.5px;display:flex;align-items:center;justify-content:space-between}
.graph-wrap{flex:1;width:100%;min-height:200px;background:var(--surface2);position:relative;touch-action:none}
.graph-wrap#topicGraph{
flex:1 1 0;min-height:120px;
overflow:hidden;position:relative;min-width:0}
.graph-wrap#topicGraph svg{display:block;width:100%;height:100%;cursor:grab}
.graph-wrap#topicGraph svg.panning{cursor:grabbing}
.graph-wrap svg{display:block;width:100%;height:100%;cursor:default}
.graph-wrap#fsmWrap{flex:1 1 0;min-height:120px;height:auto!important;max-height:none;display:flex;flex-direction:column;overflow:hidden}
.fsm-playbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--border);background:var(--surface);flex-shrink:0}
.fsm-playbar select,.fsm-playbar .btn-fsm{font-size:12px;padding:6px 12px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface2);color:var(--text);cursor:pointer}
.fsm-playbar .btn-fsm{font-weight:600}
.fsm-playbar .btn-fsm:hover{border-color:var(--blue);color:var(--blue)}
.fsm-macro-slot{flex:1;min-height:160px;background:var(--surface2);border-bottom:1px solid var(--border);position:relative;overflow:hidden}
.fsm-macro-slot svg{display:block;width:100%;height:100%;cursor:grab}
.fsm-macro-slot svg.panning{cursor:grabbing}
.fsm-zoom-controls{position:absolute;top:8px;right:8px;display:flex;gap:4px;z-index:10}
.fsm-zoom-btn,.graph-expand-btn{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-sm);
color:var(--text);width:28px;height:28px;font-size:14px;font-weight:700;cursor:pointer;display:flex;
align-items:center;justify-content:center;opacity:.85;transition:opacity .15s,border-color .15s;padding:0}
.fsm-zoom-btn:hover,.graph-expand-btn:hover{opacity:1;border-color:var(--blue);color:var(--blue)}
.graph-expand-btn{color:var(--text-dim);font-size:15px;font-weight:400}
.fsm-zoom-level{font-size:10px;color:var(--text-dim);font-family:var(--font-mono);align-self:center;padding:0 4px;user-select:none}
.graph-fullscreen-overlay{position:fixed;inset:0;z-index:9999;background:var(--bg);display:flex;flex-direction:column;animation:fadeIn .15s ease}
.graph-fullscreen-overlay .gf-header{flex-shrink:0;display:flex;align-items:center;justify-content:space-between;
padding:12px 24px;border-bottom:1px solid var(--border);background:var(--surface)}
.graph-fullscreen-overlay .gf-header h2{font-size:16px;font-weight:700;color:var(--text-bright);text-transform:uppercase;letter-spacing:.5px}
.graph-fullscreen-overlay .gf-close{background:var(--surface2);border:1px solid var(--border);border-radius:var(--radius-sm);
color:var(--text);padding:6px 14px;font-size:12px;cursor:pointer;font-weight:600}
.graph-fullscreen-overlay .gf-close:hover{border-color:var(--blue);color:var(--blue)}
.graph-fullscreen-overlay .gf-body{flex:1;min-height:0;background:var(--surface2);display:flex;align-items:center;justify-content:center;overflow:hidden;touch-action:none}
.graph-fullscreen-overlay .gf-body svg{width:100%;height:100%;cursor:grab}
.graph-fullscreen-overlay .gf-body svg.panning{cursor:grabbing}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.fsm-detail-slot{flex:1;min-height:0;overflow-y:auto;background:var(--surface);
padding:14px 16px;font-size:clamp(11px,1.3vw,13px);line-height:1.5}
.fsm-detail-slot:empty{display:none}
.fsm-detail-h{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.55px;color:var(--text-dim);margin:0 0 8px;display:flex;align-items:center;gap:8px}
.fsm-detail-h .fsm-detail-badge{font-size:10px;font-weight:700;padding:3px 9px;border-radius:999px;border:1px solid var(--border);background:var(--surface2)}
.fsm-detail-h .fsm-detail-badge.badge-blue{color:var(--blue);border-color:var(--blue-border)}
.fsm-detail-h .fsm-detail-badge.badge-teal{color:var(--teal);border-color:rgba(45,212,191,.35)}
.fsm-detail-h .fsm-detail-badge.badge-green{color:var(--green);border-color:var(--green-border)}
.fsm-detail-h .fsm-detail-badge.badge-purple{color:var(--purple);border-color:var(--purple-border)}
.fsm-detail-h .fsm-detail-badge.badge-orange{color:var(--orange);border-color:var(--orange-border)}
.fsm-detail-h .fsm-detail-badge.badge-yellow{color:var(--yellow);border-color:rgba(251,191,36,.35)}
.fsm-detail-section{margin-top:10px}
.fsm-detail-section:first-child{margin-top:0}
.fsm-detail-section-h{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--text-dim);margin-bottom:5px}
.fsm-detail-var{margin:6px 0;padding:8px 10px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface2)}
.fsm-detail-var-name{font-weight:700;color:var(--purple);font-family:var(--font-mono);font-size:12px;margin-bottom:3px}
.fsm-detail-var-val{font-family:var(--font-mono);font-size:12px;color:var(--text);word-break:break-word}
.fsm-detail-var-val.old{opacity:.55;text-decoration:line-through}
.fsm-detail-prompt-buf{margin:6px 0;padding:10px;border-radius:var(--radius-sm);border:1px solid var(--purple-border);
background:var(--purple-bg);font-family:var(--font-mono);font-size:12px;white-space:pre-wrap;word-break:break-word;
max-height:180px;overflow-y:auto;line-height:1.5;color:var(--text)}
.fsm-detail-response{margin:6px 0;padding:12px 14px;border-radius:var(--radius-sm);border:1px solid var(--green-border);
background:var(--green-bg);font-size:13px;line-height:1.65;white-space:pre-wrap;word-break:break-word;color:var(--text)}
.fsm-detail-reason{margin:6px 0;padding:10px 12px;border-radius:var(--radius-sm);border:1px solid var(--border);
background:var(--surface2);font-size:12px;line-height:1.55;white-space:pre-wrap;word-break:break-word;color:var(--text);font-style:italic}
.fsm-detail-exec{margin:6px 0;padding:8px 10px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface2)}
.fsm-detail-exec pre{font-family:var(--font-mono);font-size:12px;white-space:pre-wrap;word-break:break-word;
max-height:160px;overflow-y:auto;margin:4px 0;line-height:1.4}
.fsm-detail-slot .fsm-llm-section{margin-top:10px}
.fsm-detail-slot .fsm-llm-section:first-child{margin-top:0}
.fsm-detail-slot .fsm-pre{max-height:240px}
.fsm-detail-slot .fsm-msg-bubble{max-height:240px}
.fsm-detail-meta{font-size:11px;color:var(--text-dim);font-family:var(--font-mono);margin-bottom:8px}
.fsm-kv{font-size:12px;color:var(--text-dim);margin:2px 0 0;font-family:var(--font-mono);word-break:break-word}
.fsm-chips{display:flex;flex-wrap:wrap;gap:6px}
.fsm-chip{font-size:11px;padding:4px 9px;border-radius:6px;background:var(--surface2);border:1px solid var(--border);font-family:var(--font-mono)}
.fsm-chip-sent{border-color:rgba(34,211,238,.35);color:var(--cyan)}
.fsm-pre{margin:6px 0 0;font-size:12px;font-family:var(--font-mono);white-space:pre-wrap;word-break:break-word;max-height:120px;overflow:auto;background:var(--surface2);padding:8px;border-radius:var(--radius-sm);border:1px solid var(--border)}
.fsm-llm-section{margin-top:10px}
.fsm-llm-section:first-child{margin-top:0}
.fsm-llm-h{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.55px;color:var(--text-dim);margin-bottom:5px}
.fsm-msg-bubble{margin:6px 0;padding:8px 12px;border-radius:var(--radius-sm);font-size:12px;line-height:1.5;max-height:200px;overflow-y:auto;border:1px solid var(--border)}
.fsm-msg-role{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;margin-bottom:4px;opacity:.78}
.fsm-msg-system{background:var(--purple-bg);border-color:var(--purple-border)}
.fsm-msg-user{background:var(--blue-bg);border-color:var(--blue-border)}
.fsm-msg-assistant{background:var(--green-bg);border-color:var(--green-border)}
.fsm-msg-tool{background:rgba(45,212,191,.1);border-color:rgba(45,212,191,.35)}
.light .fsm-msg-tool{background:rgba(13,148,136,.08);border-color:rgba(13,148,136,.25)}
.fsm-msg-body{white-space:pre-wrap;word-break:break-word;font-family:var(--font-mono)}
.svg-graph.fsm .fsm-node.dim rect{opacity:.32}
.svg-graph.fsm .fsm-node.active rect{opacity:1;stroke:var(--cyan)!important;stroke-width:3px;filter:drop-shadow(0 0 12px rgba(34,211,238,.45))}
.light .svg-graph.fsm .fsm-node.active rect{filter:drop-shadow(0 0 10px rgba(8,145,178,.4))}
.svg-graph .edge{fill:none;stroke:var(--text);stroke-width:2.2;opacity:.5;stroke-linecap:round;stroke-linejoin:round}
.svg-graph{overflow:visible}
.svg-graph .edge-label{font-size:11px;fill:var(--text);font-family:var(--font-mono);pointer-events:none;font-weight:600}
.svg-graph .topic-node{cursor:pointer}
.svg-graph .topic-node circle{fill:var(--bg);stroke:var(--blue);stroke-width:2;transition:stroke-width .15s,filter .15s,stroke .15s}
.svg-graph .topic-node.selected circle{stroke-width:2.8;filter:brightness(1.06)}
.svg-graph .topic-node text{font-size:12px;fill:var(--text);font-weight:600;font-family:system-ui,sans-serif;pointer-events:none;text-anchor:middle}
.svg-graph.fsm .fsm-node rect{fill:var(--bg);stroke:var(--blue);stroke-width:2;transition:stroke .25s,stroke-width .25s,opacity .25s,filter .25s}
.svg-graph.fsm .fsm-node.fsm-node--tool rect{stroke:var(--teal)}
.svg-graph.fsm .fsm-node.fsm-node--process rect{stroke:var(--purple);stroke-dasharray:6,3;fill:var(--purple-bg)}
.svg-graph.fsm .fsm-node.fsm-node--llm rect{stroke:var(--blue);fill:var(--blue-bg)}
.svg-graph.fsm .fsm-node.fsm-node--response rect{stroke:var(--green)}
.svg-graph.fsm .fsm-node.fsm-node--user rect{stroke:var(--yellow)}
.svg-graph.fsm .fsm-node.fsm-node--handoff rect{stroke:var(--orange);stroke-dasharray:5,3;fill:var(--orange-bg)}
.svg-graph.fsm .fsm-node-label{fill:var(--text);font-weight:600;font-family:system-ui,sans-serif;pointer-events:none;text-anchor:middle}
.svg-graph.fsm .fsm-node-sublabel{fill:var(--text-dim);font-weight:400;font-family:var(--font-mono);pointer-events:none;text-anchor:middle}
.svg-graph.fsm .edge-back{stroke:var(--teal);stroke-dasharray:6,4;opacity:.65}
.svg-graph.fsm .edge.dim{opacity:.15}
.svg-graph.fsm .edge-back.dim{opacity:.15}
.svg-graph.fsm .edge.active{opacity:1;stroke:var(--cyan);stroke-width:3;filter:drop-shadow(0 0 8px rgba(34,211,238,.45));transition:opacity .2s,stroke .2s,stroke-width .2s}
.svg-graph.fsm .edge-back.active{opacity:1;stroke-width:3;filter:drop-shadow(0 0 8px rgba(45,212,191,.5));transition:opacity .2s,stroke-width .2s}
.light .svg-graph.fsm .edge.active{filter:drop-shadow(0 0 6px rgba(8,145,178,.45))}
.light .svg-graph.fsm .edge-back.active{filter:drop-shadow(0 0 6px rgba(13,148,136,.45))}
.svg-graph.fsm .fsm-back-label{fill:var(--teal);font-size:10px}
.svg-graph.fsm .fsm-loop-box{fill:none;stroke-width:1.5;stroke-dasharray:8,4;opacity:.35;pointer-events:none}
.svg-graph.fsm .fsm-loop-box--tool{stroke:var(--teal)}
.svg-graph.fsm .fsm-loop-label-text{font-size:11px;fill:var(--text-dim);font-weight:700;letter-spacing:.5px;font-family:system-ui,sans-serif}
.light .svg-graph.fsm .fsm-node.fsm-node--tool rect{stroke:var(--teal)}
.light .svg-graph.fsm .fsm-node.fsm-node--process rect{stroke:var(--purple);fill:rgba(124,58,237,.06)}
.light .svg-graph.fsm .fsm-node.fsm-node--llm rect{fill:rgba(37,99,235,.06)}
.light .svg-graph.fsm .fsm-node.fsm-node--handoff rect{stroke:var(--orange);fill:rgba(251,146,60,.06)}
.metrics-bar{flex-shrink:0;background:var(--surface);border-bottom:1px solid var(--border);
padding:4px 20px;font-size:11px;display:flex;flex-wrap:wrap;gap:6px 14px;align-items:center}
.metrics-bar.hidden{display:none}
.exec-stats-strip{display:flex;flex-wrap:wrap;gap:6px 14px;align-items:center;font-size:11px;color:var(--text-dim)}
.exec-stats-strip b{color:var(--text);font-weight:600}
.viz-toolbar{background:var(--surface);border-bottom:1px solid var(--border);padding:6px 16px;
display:flex;flex-wrap:wrap;gap:6px 14px;align-items:center}
.viz-toolbar .viz-toolbar-title{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--text-dim)}
.viz-toolbar label{font-size:11px;color:var(--text);display:inline-flex;align-items:center;gap:5px;cursor:pointer;white-space:nowrap}
.viz-toolbar input[type=checkbox]{accent-color:var(--blue);flex-shrink:0}
#mainEmpty:not(.hidden){flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:min(560px,calc(100vh - 56px))}
.empty-state{text-align:center;padding:48px 24px;color:var(--text-dim)}
.empty-state h2{color:var(--text-bright);margin-bottom:8px;font-size:20px}
.drop-zone{max-width:560px;margin:16px auto;border:2px dashed var(--border);border-radius:var(--radius);
padding:32px;cursor:pointer}
.drop-zone:hover{border-color:var(--blue);background:var(--blue-bg)}
.btn-large{padding:10px 22px;font-size:13px;font-weight:600;border-radius:var(--radius);cursor:pointer;
border:1px solid var(--blue);background:var(--blue);color:#fff;margin:4px}
.upload-overlay{position:fixed;inset:0;background:rgba(0,0,0,.7);z-index:200;display:flex;
align-items:center;justify-content:center}
.upload-modal{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);
padding:20px;width:90%;max-width:640px}
.upload-modal textarea{width:100%;height:240px;background:var(--surface2);border:1px solid var(--border);
border-radius:var(--radius-sm);color:var(--text);font-family:var(--font-mono);font-size:11px;padding:10px}
.btn-row{display:flex;gap:8px;justify-content:flex-end;margin-top:12px}
.btn-primary{background:var(--blue);color:#fff;border:none;padding:8px 18px;border-radius:var(--radius-sm);
font-weight:600;cursor:pointer}
.hidden{display:none}
.error-toast{position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:rgba(248,113,113,.15);
border:1px solid rgba(248,113,113,.4);color:var(--red);padding:10px 18px;border-radius:var(--radius);z-index:300}
@media(max-width:1024px){
.layout{padding:10px 12px;gap:10px;grid-template-columns:1fr;height:auto}
.panel--context{max-height:340px}
}
@media(max-width:768px){
.app-header{padding:10px 14px;gap:10px}
.app-header h1{font-size:14px}
.header-meta{gap:6px}
.meta-chip{font-size:10px;padding:3px 8px}
.header-actions .btn{padding:5px 10px;font-size:11px}
.layout{padding:8px 10px;gap:8px}
.panel-h{padding:8px 12px;font-size:clamp(11px,1.4vw,13px)}
.fsm-playbar{padding:8px 10px;gap:6px}
.viz-toolbar label{font-size:10px;gap:4px}
.viz-toolbar .viz-toolbar-title{font-size:10px}
.exec-stats-strip{font-size:10px;gap:4px 8px}
}
</style>
</head>
<body class="light">
<div class="app-header">
<h1>AgentLens</h1>
<div class="header-meta" id="headerMeta"></div>
<div class="header-actions">
<button class="btn" id="btnTheme">Dark</button>
<button class="btn" id="btnLoad">Load JSON</button>
<button class="btn hidden" id="btnClear">Clear</button>
</div>
</div>
<div class="metrics-bar hidden" id="metricsCard"></div>
<div id="mainEmpty" class="empty-state">
<h2>Visualize any Agentforce agent trace</h2>
<p>Load a plan response from the <strong>Agentforce DX</strong> extension, then explore sub agent handoffs, finite state machines, and LLM calls — all in one view.</p>
<p style="font-size:12px;max-width:520px;margin:12px auto 0">Zero dependencies — runs entirely in the browser. Works with <code>file://</code> and local servers alike.</p>
<button class="btn-large" id="btnPaste">Paste JSON</button>
<label class="btn-large" style="display:inline-block;background:var(--surface2);color:var(--text);border-color:var(--border)">
Upload <input type="file" accept=".json,application/json" id="fileInput" class="hidden">
</label>
<div class="drop-zone" id="dropZone"><strong>Drop JSON here</strong></div>
</div>
<div id="mainViz" class="hidden">
<div class="layout">
<div class="panel panel--inspector" id="inspectorPanel">
<div class="panel-h"><span id="fsmTopicLabel" style="opacity:.5">select a sub agent →</span></div>
<div class="viz-toolbar" id="vizToolbar">
<span class="viz-toolbar-title">Show:</span>
<label title="Variable assignment and mutation steps"><input type="checkbox" id="chkVarUpdates" checked /> Variable Updates</label>
<label title="Planner reasoning, grounding checks, and prep actions"><input type="checkbox" id="chkReasoning" checked /> Reasoning</label>
<label title="State captured when entering a node"><input type="checkbox" id="chkNodeEntry" checked /> Node Entry</label>
<label title="Tools made available to the LLM at each step"><input type="checkbox" id="chkEnabledTools" checked /> Enabled Tools</label>
<label title="AgentScriptInternal_* system variables (usually noisy)"><input type="checkbox" id="chkAgentScriptVars" /> Internal Vars</label>
</div>
<div class="fsm-playbar" id="inspectorPlaybar" style="display:none">
<button type="button" class="btn-fsm" id="fsmBtnPrev" title="Previous event (← or K)">← Prev</button>
<span id="fsmStepLabel" style="font-size:12px;font-family:var(--font-mono);color:var(--text-dim);white-space:nowrap">—</span>
<button type="button" class="btn-fsm" id="fsmBtnNext" title="Next event (→ or J)">Next →</button>
<span style="font-size:10px;color:var(--text-dim);margin-left:auto">← → keys</span>
</div>
<div class="fsm-single-card" id="fsmDetailSlot"></div>
</div>
<div class="panel panel--context" id="contextPanel">
<div class="panel-h">Agent Graph <button type="button" class="graph-expand-btn" id="btnExpandGraph" title="Pop out graph (fullscreen)">⛶</button></div>
<div class="graph-wrap" id="topicGraph"></div>
<div class="topic-list" id="topicList"></div>
<div class="panel-h" style="font-size:11px">Finite State Machine — <span id="fsmDiagramLabel" style="font-weight:400;color:var(--text-dim)">select a sub agent</span> <button type="button" class="graph-expand-btn" id="btnExpandFsm" title="Pop out FSM (fullscreen)" style="margin-left:auto">⛶</button></div>
<div class="graph-wrap" id="fsmWrap"></div>
</div>
</div>
</div>
<div class="upload-overlay hidden" id="uploadOverlay">
<div class="upload-modal">
<h2 style="font-size:15px;margin-bottom:10px;color:var(--text-bright)">Paste Plan JSON</h2>
<textarea id="jsonInput" placeholder='Paste the plan response JSON from Agentforce DX here…'></textarea>
<div class="btn-row">
<button class="btn" id="btnCancel">Cancel</button>
<button class="btn-primary" id="btnParse">Visualize</button>
</div>
</div>
</div>
<script>
const LS_FILTERS = 'afViz2.filters';
let currentData = null;
let analysis = null;
let vizParsed = null;
let selectedTopicId = null;
let fsmPlayback = { events: [], rawEvents: [], idx: -1, nodeMap: null, edgePathMap: null };
let fsmKeyNavHandler = null;
function detachFsmKeyboardNav() {
if (fsmKeyNavHandler) {
window.removeEventListener('keydown', fsmKeyNavHandler, true);
fsmKeyNavHandler = null;
}
}
function attachFsmKeyboardNav() {
detachFsmKeyboardNav();
fsmKeyNavHandler = ev => {
if (!selectedTopicId || !fsmPlayback.events || fsmPlayback.events.length === 0) return;
const tag = ev.target && ev.target.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || ev.target.isContentEditable) return;
if (ev.key === 'ArrowLeft' || ev.key === 'k' || ev.key === 'K') {
ev.preventDefault();
stepFsmPrev();
} else if (ev.key === 'ArrowRight' || ev.key === 'j' || ev.key === 'J') {
ev.preventDefault();
stepFsmNext();
}
};
window.addEventListener('keydown', fsmKeyNavHandler, true);
}
const timelineFilterPrefs = {
varUpdates: true,
reasoning: true,
nodeEntry: true,
enabledTools: true,
showAgentScriptVars: false,
};
function loadTimelineFilterPrefs() {
try {
const s = localStorage.getItem(LS_FILTERS);
if (!s) return;
const parsed = JSON.parse(s);
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return;
const allowed = Object.keys(timelineFilterPrefs);
for (const key of allowed) {
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
timelineFilterPrefs[key] = !!parsed[key];
}
}
} catch (_) {}
}
function saveTimelineFilterPrefs() {
try {
localStorage.setItem(LS_FILTERS, JSON.stringify(timelineFilterPrefs));
} catch (_) {}
}
function syncFilterUiFromPrefs() {
const m = {
chkVarUpdates: 'varUpdates',
chkReasoning: 'reasoning',
chkNodeEntry: 'nodeEntry',
chkEnabledTools: 'enabledTools',
chkAgentScriptVars: 'showAgentScriptVars',
};
for (const [id, key] of Object.entries(m)) {
const el = document.getElementById(id);
if (el) el.checked = !!timelineFilterPrefs[key];
}
}
function readFilterUiToPrefs() {
timelineFilterPrefs.varUpdates = !!document.getElementById('chkVarUpdates')?.checked;
timelineFilterPrefs.reasoning = !!document.getElementById('chkReasoning')?.checked;
timelineFilterPrefs.nodeEntry = !!document.getElementById('chkNodeEntry')?.checked;
timelineFilterPrefs.enabledTools = !!document.getElementById('chkEnabledTools')?.checked;
timelineFilterPrefs.showAgentScriptVars = !!document.getElementById('chkAgentScriptVars')?.checked;
}
function stepDurationMs(step) {
const a = step.startExecutionTime;
const b = step.endExecutionTime;
if (a == null || b == null) return 0;
const d = b - a;
return d > 0 ? d : 0;
}
function withStepDuration(subtitle, step) {
const d = stepDurationMs(step);
if (!d) return subtitle || '';
const bit = `${d}ms`;
if (!subtitle) return bit;
return subtitle.includes(bit) ? subtitle : `${subtitle} · ${bit}`;
}
function computePlanExecutionStats(plan) {
const empty = { steps: 0, llm: 0, fn: 0, transition: 0, wall: 0 };
if (!plan || !plan.length) return empty;
let llm = 0;
let fn = 0;
let transition = 0;
for (const s of plan) {
if (s.type === 'LLMStep') llm++;
if (s.type === 'FunctionStep') fn++;
if (s.type === 'TransitionStep') transition++;
}
const wall =
plan.length > 1
? (plan[plan.length - 1].endExecutionTime || 0) - (plan[0].startExecutionTime || 0)
: stepDurationMs(plan[0]) || 0;
return { steps: plan.length, llm, fn, transition, wall };
}
function filterVariableUpdates(updates, prefs) {
return updates.filter(u => {
const n = String(u.variable_name || '');
if (!prefs.showAgentScriptVars && n.startsWith('AgentScriptInternal_')) return false;
return true;
});
}
function countVisibleVarUpdates(step, prefs) {
const updates = step.data?.variable_updates || [];
if (!updates.length) return 0;
return filterVariableUpdates(updates, prefs).length;
}
function timelineEventMatchesFilters(ev, plan, prefs) {
const k = ev.kind;
if (k === 'variable') {
if (!prefs.varUpdates) return false;
const step = plan[ev.stepIndex];
const all = step.data?.variable_updates || [];
if (!all.length) return true;
return countVisibleVarUpdates(step, prefs) > 0;
}
if (k === 'action' || k === 'response') return !!prefs.reasoning;
if (k === 'entry') return !!prefs.nodeEntry;
if (k === 'enabled') return !!prefs.enabledTools;
return true;
}
function applyTimelineFilters(plan, rawEvents, prefs) {
return rawEvents.filter(ev => timelineEventMatchesFilters(ev, plan, prefs));
}
const _escDiv = document.createElement('div');
function esc(s) {
if (s == null) return '';
_escDiv.textContent = String(s);
return _escDiv.innerHTML.replace(/"/g, '"').replace(/'/g, ''');
}
function extractToolInvocations(msg) {
if (!msg) return [];
const out = [];
if (msg.tool_invocation && msg.tool_invocation.name) {
out.push({ name: msg.tool_invocation.name, arguments: msg.tool_invocation.arguments });
}
const arr = msg.tool_invocations;
if (Array.isArray(arr)) {
for (let i = 0; i < arr.length; i++) {
const fn = arr[i].function;
if (fn && fn.name) out.push({ name: fn.name, arguments: fn.arguments });
}
}
return out;
}
function agentKey(name) {
if (!name) return 'none';
return String(name).toLowerCase().replace(/\s+/g, '_');
}
function getAgentForStep(step, prevAgent) {
const d = step.data || {};
if (step.type === 'LLMStep' || step.type === 'EnabledToolsStep') return agentKey(d.agent_name);
if (step.type === 'NodeEntryStateStep' || step.type === 'BeforeReasoningIterationStep' || step.type === 'AfterReasoningStep')
return agentKey(d.agent_name);
if (step.type === 'TransitionStep') return agentKey(d.from_agent);
if (step.type === 'FunctionStep') return prevAgent;
if (step.type === 'VariableUpdateStep') return prevAgent;
return prevAgent || 'none';
}
function recordDisplay(map, id, raw) {
if (!id || id === 'none' || !raw) return;
const s = String(raw).trim();
if (!s) return;
if (!map[id] || s.length > map[id].length) map[id] = s;
}
/** Induced FSM states for orchestration (not per-tool names). */
const FSM_BUILTIN_MACRO_IDS = new Set(['Entry', 'Prep', 'LLM', 'Response', 'UserInput', 'Function']);
const FSM_MACRO_RING_ORDER = ['Entry', 'UserInput', 'Prep', 'LLM', 'Response', 'Function'];
const HANDOFF_PREFIX = 'Handoff\u2192';
function handoffMacroId(toAgent) { return HANDOFF_PREFIX + String(toAgent).trim(); }
function isHandoffMacroId(id) { return typeof id === 'string' && id.startsWith(HANDOFF_PREFIX); }
function handoffTargetName(id) { return id.slice(HANDOFF_PREFIX.length); }
function functionStepMacroId(step) {
const fn = step.function;
const raw = fn && fn.name != null ? String(fn.name).trim() : '';
if (!raw) return 'Function';
if (FSM_BUILTIN_MACRO_IDS.has(raw)) return `${raw} ·tool`;
return raw;
}
function stepToMacro(step) {
const t = step.type;
if (t === 'TransitionStep') {
const toAgent = step.data && step.data.to_agent;
if (toAgent) return handoffMacroId(toAgent);
return null;
}
if (t === 'NodeEntryStateStep') return 'Entry';
if (t === 'VariableUpdateStep' || t === 'BeforeReasoningIterationStep' || t === 'AfterReasoningStep' || t === 'EnabledToolsStep')
return 'Prep';
if (t === 'LLMStep') return 'LLM';
if (t === 'FunctionStep') return functionStepMacroId(step);
if (t === 'UserInputStep') return 'UserInput';
if (t === 'PlannerResponseStep' || t === 'ReasoningStep') return 'Response';
return null;
}
function emptyTopicDetails() {
return {
variableNames: new Set(),
variableUpdates: [],
enabledTools: new Set(),
toolsSent: new Set(),
toolsInvoked: new Set(),
toolsExecuted: new Set(),
toolInvocations: [],
functionsExecuted: [],
promptNames: new Set(),
beforeReasoningActions: new Set(),
};
}
function ensureTopicDetails(map, topic) {
if (!topic || topic === 'none') return null;
if (!map[topic]) map[topic] = emptyTopicDetails();
return map[topic];
}
function truncateJSON(obj, n) {
try {
const s = typeof obj === 'string' ? obj : JSON.stringify(obj);
return s.length > n ? s.slice(0, n - 1) + '…' : s;
} catch {
return String(obj).slice(0, n);
}
}
function parsePromptContentToMessages(str) {
if (!str || typeof str !== 'string') return [];
try {
const arr = JSON.parse(str);
if (!Array.isArray(arr)) return [];
return arr.map(item => {
const role = item.role || 'unknown';
let content = '';
if (item.blocks && Array.isArray(item.blocks)) {
content = item.blocks.map(b => (b && b.text != null ? String(b.text) : '')).join('\n');
} else if (typeof item.content === 'string') {
content = item.content;
}
return { role, content };
});
} catch {
return [];
}
}
function normalizeLlmMessages(step) {
const d = step.data || {};
let msgs = step.messages_sent;
if (!msgs || !msgs.length) msgs = parsePromptContentToMessages(d.prompt_content);
return Array.isArray(msgs) ? msgs : [];
}
function splitLlmMessages(msgs) {
const system = [];
const thread = [];
for (const m of msgs) {
const role = (m && m.role) || 'unknown';
const content = m.content == null ? '' : String(m.content);
if (role === 'system') system.push({ role, content });
else thread.push({ role, content });
}
return { system, thread };
}
function fsmLlmMessageBubble(role, content) {
const r = role === 'tool' ? 'tool' : role === 'user' ? 'user' : role === 'assistant' ? 'assistant' : 'system';
const cls = 'fsm-msg-bubble fsm-msg-' + r;
const trimmed = (content || '').trim();
let body;
if (trimmed) body = esc(content);
else if (role === 'assistant')
body = '<span style="opacity:.75;font-style:italic">(no text — likely tool call)</span>';
else body = '<span style="opacity:.65">(empty)</span>';
return `<div class="${cls}"><div class="fsm-msg-role">${esc(role)}</div><div class="fsm-msg-body">${body}</div></div>`;
}
function renderToolChipsHtml(tools) {
return tools.length > 0
? `<div class="fsm-chips">${tools.map(x => `<span class="fsm-chip fsm-chip-sent">${esc(String(x))}</span>`).join(' ')}</div>`
: '<div class="fsm-kv">—</div>';
}
function renderResponseMessagesHtml(resp, maxHeight, truncLen) {
if (!resp.length) return '<div class="fsm-kv">—</div>';
return resp.map(m => {
const invocations = extractToolInvocations(m);
if (invocations.length) {
return invocations.map(inv =>
`<pre class="fsm-pre" style="max-height:${maxHeight}px"><b>Tool call</b> ${esc(String(inv.name))}(${esc(truncateJSON(inv.arguments, truncLen))})</pre>`
).join('');
}
if (truncLen < 400) {
return `<pre class="fsm-pre" style="max-height:${maxHeight}px">${esc(truncateJSON(m.content, truncLen))}</pre>`;
}
return fsmLlmMessageBubble('assistant', m.content || '');
}).join('');
}
function formatFsmLlmStepBody(step) {
const msgs = normalizeLlmMessages(step);
const { system, thread } = splitLlmMessages(msgs);
let html = '';
html += '<div class="fsm-llm-section"><div class="fsm-llm-h">Tools available to the model</div>';
html += renderToolChipsHtml(step.tools_sent || []);
html += '</div>';
html += '<div class="fsm-llm-section"><div class="fsm-llm-h">System prompt</div>';
if (!system.length) html += '<div class="fsm-kv">—</div>';
else {
system.forEach((m, i) => {
if (system.length > 1)
html += `<div class="fsm-kv" style="margin-bottom:4px">Part ${i + 1} of ${system.length}</div>`;
html += `<pre class="fsm-pre" style="max-height:160px">${esc(m.content)}</pre>`;
});
}
html += '</div>';
html += '<div class="fsm-llm-section"><div class="fsm-llm-h">Messages sent to the model</div>';
if (!thread.length) html += '<div class="fsm-kv">—</div>';
else html += thread.map(m => fsmLlmMessageBubble(m.role, m.content)).join('');
html += '</div>';
html += '<div class="fsm-llm-section"><div class="fsm-llm-h">Model output</div>';
html += renderResponseMessagesHtml(step.response_messages || [], 100, 600);
html += '</div>';
return html;
}
function prettyJSON(obj, limit) {
try {
const s = typeof obj === 'string' ? obj : JSON.stringify(obj, null, 2);
return s.length > (limit || 2000) ? s.slice(0, (limit || 2000) - 1) + '\u2026' : s;
} catch { return String(obj); }
}
function buildFsmDetailHtml(ev, step) {
if (!ev || !step) return '';
const d = step.data || {};
switch (ev.kind) {
case 'variable': {
const updates = d.variable_updates || [];
if (!updates.length) return '<div class="fsm-detail-h">Sub Agent Setup <span class="fsm-detail-badge badge-purple">Variable Update</span></div><div class="fsm-kv">(empty)</div>';
let html = '<div class="fsm-detail-h">Sub Agent Setup <span class="fsm-detail-badge badge-purple">Variable Update</span></div>';
const promptVar = 'AgentScriptInternal_agent_instructions';
const promptUpdates = updates.filter(u => String(u.variable_name || '') === promptVar);
const otherUpdates = updates.filter(u => String(u.variable_name || '') !== promptVar);
if (promptUpdates.length) {
html += '<div class="fsm-detail-section"><div class="fsm-detail-section-h">Prompt Buffer</div>';
for (const u of promptUpdates) {
const newVal = u.variable_new_value != null ? String(u.variable_new_value) : '';
html += `<div class="fsm-detail-prompt-buf">${esc(newVal || '(empty)')}</div>`;
if (u.variable_change_reason) html += `<div class="fsm-kv" style="margin-top:4px;opacity:.75">${esc(String(u.variable_change_reason))}</div>`;
}
html += '</div>';
}
if (otherUpdates.length) {
html += '<div class="fsm-detail-section"><div class="fsm-detail-section-h">Variables Changed</div>';
for (const u of otherUpdates) {
const name = String(u.variable_name || '');
html += '<div class="fsm-detail-var">';
html += `<div class="fsm-detail-var-name">${esc(name)}</div>`;
html += `<div class="fsm-detail-var-val old">${esc(truncateJSON(u.variable_past_value, 200))}</div>`;
html += `<div class="fsm-detail-var-val">\u2192 ${esc(truncateJSON(u.variable_new_value, 200))}</div>`;
if (u.variable_change_reason) html += `<div class="fsm-kv" style="margin-top:3px;opacity:.75">${esc(String(u.variable_change_reason))}</div>`;
html += '</div>';
}
html += '</div>';
}
return html;
}
case 'action': {
let html = '<div class="fsm-detail-h">Sub Agent Setup <span class="fsm-detail-badge badge-purple">Actions Processed</span></div>';
const names = d.action_names || [];
if (names.length) {
html += '<div class="fsm-detail-section"><div class="fsm-detail-section-h">Actions</div>';
html += names.map(n => `<div class="fsm-kv">${esc(String(n))}</div>`).join('');
html += '</div>';
} else html += '<div class="fsm-kv">\u2014</div>';
return html;
}
case 'enabled': {
let html = '<div class="fsm-detail-h">Sub Agent Setup <span class="fsm-detail-badge badge-purple">Enabled Tools</span></div>';
const tools = d.enabled_tools || [];
html += `<div class="fsm-chips" style="margin-top:6px">${tools.map(x => `<span class="fsm-chip">${esc(String(x))}</span>`).join(' ') || '\u2014'}</div>`;
return html;
}
case 'entry': {
let html = '<div class="fsm-detail-h">Sub Agent Setup <span class="fsm-detail-badge badge-blue">Node Entry</span></div>';
const sv = d.state_variables;
if (sv && typeof sv === 'object') {
const keys = Object.keys(sv);
html += `<div class="fsm-detail-section"><div class="fsm-detail-section-h">${keys.length} State Variables on Entry</div>`;
const promptVal = sv['AgentScriptInternal_agent_instructions'];
if (promptVal != null && String(promptVal).trim()) {
html += '<div class="fsm-detail-section-h" style="margin-top:8px">Current Prompt Buffer</div>';
html += `<div class="fsm-detail-prompt-buf">${esc(String(promptVal))}</div>`;
}
const display = keys.filter(k => !k.startsWith('__') && !k.startsWith('AgentScriptInternal_')).slice(0, 20);
if (display.length) {
html += '<div class="fsm-detail-section-h" style="margin-top:8px">Key Variables</div>';
for (const k of display) {
html += `<div class="fsm-detail-var"><div class="fsm-detail-var-name">${esc(k)}</div><div class="fsm-detail-var-val">${esc(truncateJSON(sv[k], 200))}</div></div>`;
}
}
html += '</div>';
} else html += '<div class="fsm-kv">(no state variables)</div>';
return html;
}
case 'llm_sent': {
const lat = d.execution_latency != null ? `${esc(String(d.execution_latency))} ms` : '';
const parts = [d.agent_name && esc(String(d.agent_name)), d.prompt_name && esc(String(d.prompt_name)), lat].filter(Boolean);
let html = '<div class="fsm-detail-h">LLM Request <span class="fsm-detail-badge badge-blue">LLM</span></div>';
if (parts.length) html += `<div class="fsm-detail-meta">${parts.join(' \u00b7 ')}</div>`;
html += formatFsmLlmStepBody(step);
return html;
}
case 'execute': {
const fn = step.function || {};
const fnName = fn.name != null ? String(fn.name) : 'Function';
const lat = step.executionLatency != null ? `${step.executionLatency} ms` : '';
let html = `<div class="fsm-detail-h">Tool Execution <span class="fsm-detail-badge badge-teal">${esc(fnName)}</span>${lat ? ` <span class="fsm-detail-badge">${esc(lat)}</span>` : ''}</div>`;
html += '<div class="fsm-detail-exec">';
html += '<div class="fsm-detail-section-h">Input</div>';
html += `<pre>${esc(prettyJSON(fn.input, 1500))}</pre>`;
html += '<div class="fsm-detail-section-h" style="margin-top:8px">Output</div>';
html += `<pre>${esc(prettyJSON(fn.output, 2000))}</pre>`;
html += '</div>';
return html;
}
case 'response': {
if (step.type === 'PlannerResponseStep') {
const msg = step.message || '';
const rType = step.responseType || '';
const safe = step.isContentSafe;
let html = '<div class="fsm-detail-h">Agent Response <span class="fsm-detail-badge badge-green">Response</span>';
if (rType) html += ` <span class="fsm-detail-badge">${esc(rType)}</span>`;
if (safe != null) html += ` <span class="fsm-detail-badge ${safe ? 'badge-green' : 'badge-orange'}">${safe ? 'Safe' : 'Unsafe'}</span>`;
html += '</div>';
html += `<div class="fsm-detail-response">${esc(msg)}</div>`;
return html;
}
if (step.type === 'ReasoningStep') {
const cat = step.category || '';
const reason = step.reason || '';
let html = '<div class="fsm-detail-h">Grounding Check <span class="fsm-detail-badge badge-orange">Reasoning</span>';
if (cat) html += ` <span class="fsm-detail-badge">${esc(cat)}</span>`;
html += '</div>';
html += `<div class="fsm-detail-reason">${esc(reason)}</div>`;
return html;
}
return `<div class="fsm-detail-h">Response</div><div class="fsm-kv">${esc(truncateJSON(d, 300))}</div>`;
}
case 'user': {
let html = '<div class="fsm-detail-h">User Input <span class="fsm-detail-badge badge-yellow">User</span></div>';
html += `<div class="fsm-detail-response" style="border-color:rgba(251,191,36,.35);background:rgba(251,191,36,.08)">${esc(step.message || '')}</div>`;
return html;
}
case 'transition': {
let html = '<div class="fsm-detail-h">Sub Agent Handoff <span class="fsm-detail-badge badge-orange">Transition</span></div>';
html += `<div class="fsm-kv">To: <strong>${esc(String(d.to_agent || ''))}</strong></div>`;
html += `<div class="fsm-kv">${esc(String(d.transition_type || ''))} \u00b7 ${esc(String(d.transition_mode || ''))}</div>`;
if (d.from_agent) html += `<div class="fsm-kv">From: ${esc(String(d.from_agent))}</div>`;
return html;
}
default:
return '';
}
}
function makeTimelineEvent(stepIndex, t, macro, kind, title, subtitle) {
return { stepIndex, t, macro, kind, title, subtitle };
}
function buildRawTopicTimeline(plan, topicId, stepTopicMap) {
const events = [];
if (!plan || !topicId) return events;
for (let i = 0; i < plan.length; i++) {
const topic = stepTopicMap ? stepTopicMap[i] : 'none';
if (topic !== topicId) continue;
const step = plan[i];
const d = step.data || {};
const t = step.startExecutionTime || 0;
if (step.type === 'TransitionStep') {
const toAgent = d.to_agent ? String(d.to_agent).trim() : '';
events.push(makeTimelineEvent(i, t, toAgent ? handoffMacroId(toAgent) : null, 'transition',
toAgent ? `Handoff \u2192 ${toAgent}` : 'Handoff (leaving sub agent)', withStepDuration('', step)));
continue;
}
if (step.type === 'UserInputStep') {
events.push(makeTimelineEvent(i, t, 'UserInput', 'user', 'User input', withStepDuration('', step)));
}
if (step.type === 'NodeEntryStateStep') {
const sub = d.directive_context ? esc(String(d.directive_context)) : '';
events.push(makeTimelineEvent(i, t, 'Entry', 'entry', 'Node entry', withStepDuration(sub, step)));
}
if (step.type === 'VariableUpdateStep') {
events.push(makeTimelineEvent(i, t, 'Prep', 'variable', 'Variable update', withStepDuration('', step)));
}
if (step.type === 'BeforeReasoningIterationStep') {
events.push(makeTimelineEvent(i, t, 'Prep', 'action', 'Prep \u00b7 actions processed', withStepDuration('', step)));
}
if (step.type === 'EnabledToolsStep') {
events.push(makeTimelineEvent(i, t, 'Prep', 'enabled', 'Tools enabled for agent', withStepDuration('', step)));
}
if (step.type === 'LLMStep') {
const lat = d.execution_latency != null ? `${esc(String(d.execution_latency))} ms` : '';
const subParts = [d.agent_name && esc(String(d.agent_name)), d.prompt_name && esc(String(d.prompt_name)), lat].filter(Boolean);
events.push(makeTimelineEvent(i, t, 'LLM', 'llm_sent', 'LLM call', withStepDuration(subParts.join(' \u00b7 '), step)));
}
if (step.type === 'FunctionStep') {
const fn = step.function || {};
const macroId = functionStepMacroId(step);
const latSub = step.executionLatency != null ? `${esc(String(step.executionLatency))} ms` : '';
events.push(makeTimelineEvent(i, t, macroId, 'execute', 'Tool executed', withStepDuration(latSub, step)));
}
if (step.type === 'PlannerResponseStep' || step.type === 'ReasoningStep') {
events.push(makeTimelineEvent(i, t, 'Response', 'response',
step.type === 'PlannerResponseStep' ? 'Planner response' : 'Reasoning', withStepDuration('', step)));
}
}
return events;
}
function parsePlan(plan) {
const displayNames = Object.create(null);
const topicSet = new Set();
const edgeMap = new Map();
const fsmSequences = Object.create(null);
const topicDetails = Object.create(null);
const stepTopicMap = new Array(plan.length);
let prevAgent = 'none';
for (let i = 0; i < plan.length; i++) {
const step = plan[i];
const d = step.data || {};
if (step.type === 'TransitionStep') {
recordDisplay(displayNames, agentKey(d.from_agent), d.from_agent);
recordDisplay(displayNames, agentKey(d.to_agent), d.to_agent);
const from = agentKey(d.from_agent);
const to = agentKey(d.to_agent);
if (from !== 'none' && d.current_state && typeof d.current_state === 'object') {
const td = ensureTopicDetails(topicDetails, from);
if (td) for (const k of Object.keys(d.current_state)) td.variableNames.add(k);
}
if (from !== 'none' && to !== 'none') {
topicSet.add(from);
topicSet.add(to);
const key = from + '\0' + to;
const dur = (step.endExecutionTime - step.startExecutionTime) || 0;
if (!edgeMap.has(key)) edgeMap.set(key, { from, to, count: 0, weight: 0 });
const e = edgeMap.get(key);
e.count++;
e.weight += dur;
}
}
if (step.type === 'NodeEntryStateStep') {
recordDisplay(displayNames, agentKey(d.agent_name), d.agent_name);
const nk = agentKey(d.agent_name);
if (nk !== 'none' && d.state_variables && typeof d.state_variables === 'object') {
const td = ensureTopicDetails(topicDetails, nk);
if (td) for (const k of Object.keys(d.state_variables)) td.variableNames.add(k);
}
}
if (step.type === 'LLMStep' || step.type === 'EnabledToolsStep') recordDisplay(displayNames, agentKey(d.agent_name), d.agent_name);
const topic = getAgentForStep(step, prevAgent);
stepTopicMap[i] = topic;
if (step.type === 'VariableUpdateStep') {
const td = ensureTopicDetails(topicDetails, topic);
if (td) {
const updates = d.variable_updates || [];
for (const u of updates) {
if (u.variable_name) td.variableNames.add(String(u.variable_name));
td.variableUpdates.push({
stepIndex: i,
name: u.variable_name,
past: u.variable_past_value,
new: u.variable_new_value,
reason: u.variable_change_reason,
directive: u.directive_context,
});
}
}
}
if (step.type === 'BeforeReasoningIterationStep') {
const td = ensureTopicDetails(topicDetails, topic);
if (td) for (const a of d.action_names || []) td.beforeReasoningActions.add(String(a));
}
if (step.type === 'EnabledToolsStep') {
const td = ensureTopicDetails(topicDetails, topic);
if (td) for (const x of d.enabled_tools || []) td.enabledTools.add(String(x));
}
if (step.type === 'LLMStep') {
const td = ensureTopicDetails(topicDetails, topic);
if (td) {
if (d.prompt_name) td.promptNames.add(String(d.prompt_name));
for (const x of step.tools_sent || []) td.toolsSent.add(String(x));
for (const m of step.response_messages || []) {
const invocations = extractToolInvocations(m);
for (const inv of invocations) {
const nm = String(inv.name);
td.toolsInvoked.add(nm);
td.toolInvocations.push({
name: nm,
arguments: inv.arguments,
stepIndex: i,
});
}
}
}
}
if (step.type === 'FunctionStep') {
const fn = step.function;
const td = ensureTopicDetails(topicDetails, topic);
if (td && fn && fn.name) {
const nm = String(fn.name);
td.toolsExecuted.add(nm);
td.functionsExecuted.push({
name: nm,
input: fn.input,
output: fn.output,
latency: step.executionLatency,
start: step.startExecutionTime,
stepIndex: i,
});
}
}
prevAgent = topic;
if (topic !== 'none') topicSet.add(topic);
const macro = stepToMacro(step);
if (macro && topic !== 'none') {
if (!fsmSequences[topic]) fsmSequences[topic] = [];
fsmSequences[topic].push(macro);
}
}
const fsmEdges = Object.create(null);
for (const topic of Object.keys(fsmSequences)) {
const seq = fsmSequences[topic];
const trans = new Map();
for (let j = 1; j < seq.length; j++) {
const a = seq[j - 1];
const b = seq[j];
const k = a + '\0' + b;
trans.set(k, (trans.get(k) || 0) + 1);
}