-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtdpilot_api_chat.html
More file actions
2273 lines (2178 loc) · 81.1 KB
/
Copy pathtdpilot_api_chat.html
File metadata and controls
2273 lines (2178 loc) · 81.1 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" />
<!--
tdpilot-token: replaced server-side at GET / time with the per-launch
session token. Token is injected into the served HTML body so the
same-origin chat can authenticate against /send /stop /reset /history
/firstrun + the WS handshake. A cross-origin attacker can't read this
meta tag because the server emits ACAO: <our-origin> only — the
token never leaves the served HTML body.
-->
<meta name="tdpilot-token" content="__TDPILOT_TOKEN__" />
<title>TDPILOT_API</title>
<style>
:root {
--bg: #0a0612;
--bg-2: #120a24;
--bg-3: #1c1138;
--accent: #6B47FF;
--accent-2: #9176ff;
--accent-dim:#4d33b8;
--text: #d8d2ec;
--muted: #6a5e8a;
--user-fg: #b6a8ff;
--tool-fg: #7e9aa6;
--error-fg: #ff7878;
--border: #2a1f55;
--rule: #3a2c70;
/* v2.1.1 — high-contrast red mark for user messages so the user's
own prompts are visually unmistakable in the scrollback. White-on-red
stamp + thick red rule + subtle red bg tint. Reads as a terminal
LCD stamp rather than a chat bubble. */
--user-red: #d92020;
--user-red-2: #ff4242;
--user-red-bg: rgba(217, 32, 32, 0.10);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: var(--bg);
color: var(--text);
font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: 12px;
line-height: 1.55;
overflow: hidden;
-webkit-font-smoothing: subpixel-antialiased;
}
body {
display: flex;
flex-direction: column;
}
/* CRT-ish scanline overlay so the panel reads as terminal, not webpage. */
body::before {
content: "";
position: fixed;
inset: 0;
background-image: repeating-linear-gradient(
to bottom,
rgba(255,255,255,0.012) 0,
rgba(255,255,255,0.012) 1px,
transparent 1px,
transparent 3px
);
pointer-events: none;
z-index: 100;
}
/* Top status bar: terminal window-chrome look. */
#status-bar {
flex: 0 0 auto;
padding: 7px 14px;
background: var(--bg-2);
border-bottom: 1px solid var(--rule);
font-size: 10px;
color: var(--muted);
letter-spacing: 0.08em;
text-transform: uppercase;
display: flex;
justify-content: space-between;
align-items: center;
}
#status-bar .lhs {
color: var(--accent-2);
}
/* The ▰▰▰ prefix is a *data attribute* so JS can animate it as a
three-cell wave while the agent is working. CSS reads attr() so we
get smooth swaps without rebuilding DOM each frame. */
#status-bar .lhs::before {
content: attr(data-prefix);
color: var(--accent);
letter-spacing: 0;
margin-right: 6px;
transition: color 120ms;
}
#status-bar.working .lhs::before { color: var(--accent-2); }
#status-bar .rhs {
color: var(--muted);
position: relative;
display: inline-flex;
align-items: center;
gap: 6px;
/* PR-27: keeps .rhs (and the font toggle that follows it as a
sibling) clustered at the right edge in the 3-child status bar.
No-op for the pre-PR-27 2-child layout. */
margin-left: auto;
}
#status-bar .rhs::before {
content: "[";
color: var(--rule);
}
#status-bar .rhs::after {
content: "]";
color: var(--rule);
}
/* Phase 2 (1.8.0) — transport (ws) vs agent state split. The LHS
shows `▰▰▰ tdpilot_api · ws <state>`, the RHS shows agent state
plus the model badge plus a per-turn token counter. */
#ws-state {
color: var(--muted);
font-weight: normal;
}
#ws-state.connected { color: var(--accent); }
#ws-state.connecting,
#ws-state.reconnecting { color: var(--accent-2); }
#model-badge {
color: var(--muted);
}
#model-badge.pro { color: var(--accent); }
#model-badge.flash { color: var(--accent-2); }
#model-badge:empty { display: none; }
#token-meter {
color: var(--muted);
}
#token-meter:empty { display: none; }
/* Faint divider between state, model, tokens, cursor. */
#status-bar .rhs > span + span:not(:empty)::before {
content: '·';
margin-right: 6px;
color: var(--rule);
}
#status-bar .rhs > .cursor::before { content: ''; margin: 0; }
/* Blinking cursor block after the status text — classic CRT vibe.
Visible only while the agent is working; idle hides it. */
#status-bar .cursor {
display: inline-block;
width: 0.6em;
color: var(--accent);
margin-left: 4px;
animation: blink 1s step-end infinite;
visibility: hidden;
}
#status-bar.working .cursor { visibility: visible; }
/* v2.1.0 — quiet-mode toggle replaces the v2.0.0 font-size toggle.
Single-button control at the far right of the status bar. When
active (filled glyph), the chat hides ALL tool-call / tool-
result blocks so the user sees only their prompts + the
assistant's text replies + errors. Status bar still shows the
agent's working state ("thinking" / "calling tool ...") so
there's no progress blackout. Persisted via localStorage. */
#quiet-toggle {
background: transparent;
border: 1px solid var(--rule);
color: var(--muted);
font-family: inherit;
padding: 1px 8px 2px;
margin-left: 10px;
cursor: pointer;
display: inline-flex;
align-items: center;
letter-spacing: 0;
text-transform: none;
line-height: 1;
font-size: 11px;
}
#quiet-toggle:hover {
border-color: var(--accent);
background: var(--bg-3);
}
#quiet-toggle:focus { outline: none; border-color: var(--accent); }
#quiet-toggle:focus:not(:focus-visible) { border-color: var(--rule); }
#quiet-toggle:focus-visible {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 0 8px -2px rgba(107, 71, 255, 0.4);
}
#quiet-toggle .qm-glyph { color: var(--muted); }
:root.quiet-mode #quiet-toggle .qm-glyph { color: var(--accent); }
/* Quiet-mode hiding: tool_call + tool_result + the collapsible
details.tool-pair wrapper all disappear. assistant text, user
prompts, errors, and hints stay visible. Status bar at the top
shows the agent's per-turn state ("calling td_create_node..."
etc.) so the user still has a progress signal. */
:root.quiet-mode .msg.tool_call,
:root.quiet-mode .msg.tool_result,
:root.quiet-mode details.tool-pair { display: none; }
@keyframes blink {
0%, 49% { opacity: 1; }
50%, 100% { opacity: 0; }
}
#history-wrap {
flex: 1 1 auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
#history {
flex: 1 1 auto;
overflow-y: auto;
overflow-x: hidden;
padding: 14px 18px;
display: flex;
flex-direction: column;
gap: 10px;
scroll-behavior: smooth;
}
/* Phase 2 (1.8.0) — floating "↓ N new" button. Visible only when
the user has scrolled up AND new messages have arrived. Click
jumps to bottom and resumes autoscroll. */
#scroll-jump {
position: absolute;
right: 22px;
bottom: 14px;
background: var(--bg-2);
color: var(--accent-2);
border: 1px solid var(--accent);
padding: 4px 10px;
font-family: inherit;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 2px 12px -2px rgba(107, 71, 255, 0.5);
display: none;
z-index: 5;
}
#scroll-jump.visible { display: inline-block; }
#scroll-jump:hover {
background: var(--accent);
color: var(--bg);
}
/* Copy-to-clipboard button on assistant messages. Hidden until
hover for visual quiet — appears in the upper-right of the
message bubble. */
.msg.assistant {
position: relative;
}
.msg-copy {
position: absolute;
top: 4px;
right: 6px;
background: transparent;
border: 1px solid var(--rule);
color: var(--muted);
font-family: inherit;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 1px 6px;
cursor: pointer;
opacity: 0;
transition: opacity 80ms;
}
.msg.assistant:hover .msg-copy { opacity: 1; }
.msg-copy:hover {
background: var(--accent);
color: var(--bg);
border-color: var(--accent);
}
.msg-copy.copied { color: var(--accent); border-color: var(--accent); }
/* v2.1.0 — contextual ASCII flourishes appended to assistant
messages on turn-end. The pool is keyword-matched against the
last user message + last assistant text so geometry / lighting /
audio / particle / camera / error / done topics each draw from
a small theme-specific glyph set. Flourishes are visually quiet
— accent-dim color, lower opacity, centered, generous letter-
spacing — so they read as a punctuation mark, not a decoration
stealing focus. Default pool is generic geometric glyphs. */
.msg-flourish {
margin-top: 10px;
padding-top: 6px;
border-top: 1px dashed var(--rule);
text-align: center;
color: var(--accent-dim);
font-family: inherit;
font-size: 11px;
letter-spacing: 0.5em;
opacity: 0.55;
user-select: none;
line-height: 1;
}
.msg-flourish .topic {
display: block;
margin-top: 4px;
font-size: 9px;
letter-spacing: 0.2em;
text-transform: uppercase;
opacity: 0.7;
}
/* Phase 2 (1.8.0) — node-path chips inside tool result bodies.
Inline chips for TD paths (`/project1/noise1`) so the user can
click to ask about that node. The chip stays inline-flow with
the surrounding monospace text, just visually styled. */
.node-path-chip {
display: inline-block;
background: var(--bg-3);
border: 1px solid var(--accent-dim);
color: var(--accent-2);
padding: 0 4px;
font-family: inherit;
font-size: inherit;
line-height: inherit;
cursor: pointer;
border-radius: 0;
}
.node-path-chip:hover {
background: var(--accent);
color: var(--bg);
border-color: var(--accent);
}
/* Screenshot thumbnail. Bounded so a 4K capture doesn't blow out
the chat layout. Click opens the lightbox overlay. */
.tool-screenshot {
margin: 4px 0 0;
max-width: 320px;
max-height: 240px;
cursor: zoom-in;
border: 1px solid var(--rule);
background: var(--bg);
image-rendering: pixelated;
}
.tool-screenshot-meta {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
/* Lightbox overlay — full-size view triggered by clicking a
thumbnail. ESC or click-outside closes it. */
#lightbox {
position: fixed;
inset: 0;
background: rgba(10, 6, 18, 0.92);
display: none;
align-items: center;
justify-content: center;
z-index: 200;
cursor: zoom-out;
}
#lightbox.visible { display: flex; }
#lightbox img {
max-width: 92%;
max-height: 92%;
image-rendering: pixelated;
box-shadow: 0 0 24px rgba(107, 71, 255, 0.6);
}
#history::-webkit-scrollbar { width: 6px; }
#history::-webkit-scrollbar-track { background: var(--bg); }
#history::-webkit-scrollbar-thumb {
background: var(--accent-dim);
border-radius: 0;
}
/* Messages: no rounded bubbles. Thin left rule + role tag. Terminal log feel. */
.msg {
border-left: 2px solid var(--rule);
padding: 4px 0 4px 14px;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-word;
}
.msg .role {
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
color: var(--muted);
margin-bottom: 3px;
}
.msg .role::before { content: "[ "; color: var(--rule); }
.msg .role::after { content: " ]"; color: var(--rule); }
/* v2.1.1 — user messages get the loudest treatment in the log:
- 4px solid red left rule (other roles use 2px),
- subtle red bg gradient fading right so the message reads as a
highlighted strip, not a solid block,
- pure white body text for max contrast against both the dark
panel and the new red elements,
- role tag flipped to white-on-red ("[ USER ]" stamp). Brackets
inherit the bg via the .role span and switch to white via the
overrides below — the whole `[ USER ]` reads as a single
monospaced LCD stamp. */
.msg.user {
border-left-width: 4px;
border-left-color: var(--user-red);
background: linear-gradient(
90deg,
var(--user-red-bg) 0%,
var(--user-red-bg) 60%,
transparent 100%
);
color: #ffffff;
}
.msg.user .role {
display: inline-block;
background: var(--user-red);
color: #ffffff;
padding: 0 6px;
font-weight: 700;
letter-spacing: 0.18em;
}
.msg.user .role::before { content: "[ "; color: #ffffff; }
.msg.user .role::after { content: " ]"; color: #ffffff; }
.msg.assistant {
border-left-color: var(--accent-2);
}
.msg.assistant .role { color: var(--accent-2); }
.msg.tool_call,
.msg.tool_result {
border-left-color: var(--tool-fg);
color: var(--tool-fg);
font-size: 12px;
opacity: 0.85;
}
.msg.tool_call .role,
.msg.tool_result .role { color: var(--tool-fg); }
.msg.error {
border-left-color: var(--error-fg);
color: var(--error-fg);
}
.msg.error .role { color: var(--error-fg); }
/* Phase 1.3 — soft validation nudge. Distinct from "error": the
turn was successful, this is a non-blocking hint to consider
calling td_get_errors. Yellow-ish, dim, italic. */
.msg.hint {
border-left-color: #d9a900;
color: #d9a900;
font-style: italic;
opacity: 0.85;
}
.msg.hint .role { color: #d9a900; }
/* Phase 2 (1.8.0) — markdown blocks for assistant messages. The
parent .msg has white-space: pre-wrap so paragraphs preserve
newlines, but block elements rendered by the markdown renderer
(.md-pre, .md-ul) override that locally where needed. Inline
<strong>, <em>, <code> are unstyled containers that inherit. */
.msg.assistant .body {
/* Reset pre-wrap so block-level markdown lays out normally. The
inline paragraph wrapper (.md-p) re-applies pre-wrap so casual
newlines from the model still render. */
white-space: normal;
}
.md-p {
white-space: pre-wrap;
margin: 0 0 6px;
}
.md-p:last-child { margin-bottom: 0; }
.md-h {
margin: 6px 0 4px;
color: var(--accent-2);
font-size: 11px;
letter-spacing: 0.05em;
text-transform: uppercase;
font-weight: bold;
}
.md-pre {
background: var(--bg-2);
border: 1px solid var(--rule);
padding: 8px 10px;
margin: 6px 0;
overflow-x: auto;
white-space: pre;
font-size: 12px;
}
.md-pre code {
background: transparent;
border: 0;
padding: 0;
color: var(--text);
}
.md-code {
background: var(--bg-2);
border: 1px solid var(--rule);
padding: 0 4px;
font-size: 12px;
color: var(--accent-2);
}
.md-ul, .md-ol {
margin: 4px 0;
padding-left: 22px;
white-space: normal;
}
.md-ul li, .md-ol li {
margin: 2px 0;
white-space: pre-wrap;
}
.msg.assistant a {
color: var(--accent-2);
text-decoration: underline;
}
.msg.assistant a:hover { color: var(--accent); }
/* Phase 2 (1.8.0) — collapsible tool_call / tool_result pairs.
Each call/result pair becomes a <details> element with a single
summary row "▸ td_create_node(args) → ok (123ms)" and a body that
expands to show the full args + result on click. The body is
bounded by max-height; long results truncate at 400 chars with
an "expand" toggle. */
details.tool-pair {
/* Inherits .msg padding/border. summary becomes the row content. */
cursor: default;
}
details.tool-pair .tool-pair-summary {
cursor: pointer;
list-style: none;
outline: none;
user-select: none;
display: block;
}
details.tool-pair .tool-pair-summary::-webkit-details-marker { display: none; }
details.tool-pair .tool-pair-summary::before {
content: '▸';
display: inline-block;
width: 10px;
margin-right: 4px;
color: var(--tool-fg);
transition: transform 80ms;
}
details.tool-pair[open] > .tool-pair-summary::before {
/* Rotate the chevron when open. Bullet stays in flow. */
transform: rotate(90deg);
}
.tool-pair-summary .tool-name {
color: var(--accent-2);
font-weight: 700;
}
.tool-pair-summary .tool-args {
color: var(--tool-fg);
opacity: 0.85;
}
.tool-pair-summary .tool-status { color: var(--muted); }
.tool-pair-summary .tool-status.ok { color: var(--accent); }
.tool-pair-summary .tool-status.err { color: var(--error-fg); }
.tool-pair-body {
margin: 6px 0 0 14px;
padding: 6px 10px;
background: var(--bg-2);
border-left: 1px solid var(--rule);
font-size: 11px;
}
.tool-args-block {
margin: 0 0 6px;
padding: 0;
background: transparent;
border: 0;
white-space: pre-wrap;
color: var(--tool-fg);
font-size: 11px;
}
.tool-args-block.empty { display: none; }
.tool-result-block { margin-top: 4px; }
.tool-result-body {
margin: 0;
padding: 4px 8px;
background: var(--bg);
border: 1px solid var(--rule);
white-space: pre-wrap;
word-break: break-all;
font-size: 11px;
max-height: 240px;
overflow-y: auto;
color: var(--text);
}
.tool-result-body.err { color: var(--error-fg); }
.tool-result-truncated {
color: var(--muted);
font-style: italic;
}
.tool-expand {
margin-top: 4px;
background: transparent;
border: 1px solid var(--rule);
color: var(--accent-2);
font-family: inherit;
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 2px 8px;
cursor: pointer;
}
.tool-expand:hover {
background: var(--accent);
color: var(--bg);
}
/* Welcome screen: ASCII block logo + minimal instructions. */
.welcome {
color: var(--muted);
text-align: center;
margin: 24px auto;
max-width: 92%;
}
.welcome pre.logo {
color: var(--accent);
font-size: 10px;
line-height: 1.0;
margin: 0 0 18px;
text-shadow: 0 0 8px rgba(107, 71, 255, 0.35);
letter-spacing: 0;
}
.welcome .tag {
color: var(--accent-2);
letter-spacing: 0.3em;
font-size: 10px;
text-transform: uppercase;
margin-bottom: 14px;
}
.welcome .body {
font-size: 12px;
line-height: 1.7;
color: var(--muted);
}
.welcome .body kbd {
font-family: inherit;
background: var(--bg-2);
border: 1px solid var(--rule);
padding: 1px 6px;
color: var(--accent-2);
}
/* Phase 5.2 — first-run wizard checklist. Shown above the
"type a message" hint when /capabilities reports
first_run.is_first_run = true. Steps gain an .done class as
the user works through them; the JS poller updates this on a
short interval until the wizard completes. */
.welcome .wizard {
text-align: left;
margin: 12px auto 16px;
max-width: 480px;
padding: 12px 16px;
border: 1px dashed var(--rule);
border-radius: 4px;
font-size: 12px;
line-height: 1.6;
}
.welcome .wizard h4 {
margin: 0 0 8px;
color: var(--accent-2);
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.welcome .wizard ol {
margin: 0;
padding-left: 22px;
color: var(--muted);
}
.welcome .wizard li.done {
color: var(--accent);
text-decoration: line-through;
opacity: 0.7;
}
.welcome .wizard li.done::marker {
content: "✓ ";
color: var(--accent);
}
.welcome .wizard .opt {
color: var(--muted);
font-size: 10px;
margin-left: 4px;
}
hr.divider {
border: 0;
border-top: 1px dashed var(--rule);
margin: 8px 0;
}
#input-bar {
flex: 0 0 auto;
display: flex;
gap: 8px;
padding: 10px 12px;
background: var(--bg-2);
border-top: 1px solid var(--rule);
align-items: stretch;
}
#input-bar::before {
content: ">";
color: var(--accent);
align-self: center;
font-size: 16px;
font-weight: bold;
margin-right: 2px;
}
#input {
flex: 1 1 auto;
background: var(--bg);
color: var(--text);
border: 1px solid var(--rule);
border-radius: 0;
padding: 8px 10px;
font-family: inherit;
font-size: 12px;
line-height: 1.4;
resize: none;
outline: none;
min-height: 40px;
max-height: 120px;
caret-color: var(--accent);
}
#input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 0 12px -2px rgba(107, 71, 255, 0.4);
}
#input::placeholder { color: var(--muted); }
#send, #stop {
flex: 0 0 auto;
width: 88px;
background: transparent;
border-radius: 0;
font-family: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
cursor: pointer;
transition: all 80ms ease;
}
#send {
color: var(--accent-2);
border: 1px solid var(--accent);
}
#send:hover {
background: var(--accent);
color: var(--bg);
box-shadow: 0 0 12px -2px rgba(107, 71, 255, 0.6);
}
#send:active { background: var(--accent-dim); }
#send:disabled {
background: transparent;
color: var(--rule);
border-color: var(--rule);
cursor: not-allowed;
}
#stop {
/* Hidden by default — only revealed while the agent is working.
Red so the user immediately recognises this as "abort, not send". */
display: none;
width: 72px;
color: var(--error-fg);
border: 1px solid var(--error-fg);
}
#stop.visible { display: inline-block; }
#stop:hover {
background: var(--error-fg);
color: var(--bg);
box-shadow: 0 0 12px -2px rgba(255, 120, 120, 0.6);
}
#stop:active { opacity: 0.7; }
#stop:disabled {
color: var(--rule);
border-color: var(--rule);
cursor: not-allowed;
}
</style>
</head>
<body>
<div id="status-bar">
<span class="lhs" data-prefix="▰▰▰"><span id="ws-label">tdpilot_api</span> · ws <span id="ws-state">connecting</span></span>
<span class="rhs">
<span id="status-text">idle</span><span id="model-badge"></span><span id="token-meter"></span><span class="cursor">█</span>
</span>
<button id="quiet-toggle" type="button"
title="Quiet mode — hide tool-call detail (Cmd/Ctrl + .)"
aria-label="Toggle quiet mode"
aria-pressed="false">
<span class="qm-glyph">●</span>
</button>
</div>
<!--
History is intentionally empty on initial DOM. The IIFE injects the
welcome screen (including the wizard div) via WELCOME_HTML on load.
Single source of truth means the wizard DOM survives both the
initial render AND fullSync([]) — pre-1.7.1 the inline welcome and
fullSync's rebuild diverged so /reset wiped the wizard forever.
The history-wrap holds both the scrollable history and the
floating "↓ N new" jump button (Phase 2 / 1.8.0). The button is
positioned absolutely inside the wrap so it stays anchored when
history scrolls.
-->
<div id="history-wrap">
<div id="history"></div>
<button id="scroll-jump" type="button" title="Jump to bottom (End)"></button>
</div>
<div id="lightbox" role="dialog" aria-hidden="true">
<img id="lightbox-img" alt="screenshot full view" />
</div>
<div id="input-bar">
<textarea id="input" placeholder="ask touchdesigner to do something…" rows="2" autocomplete="off" spellcheck="false"></textarea>
<button id="stop" title="Interrupt the agent (POST /stop)">stop</button>
<button id="send">send</button>
</div>
<script>
(() => {
// ---- bootstrap ------------------------------------------------------
// Hash params let power-users override host/port (e.g. running TD on
// a different machine) but we restrict host to a localhost allowlist
// so a malicious page can't link the user to the chat with host=evil
// and exfiltrate their messages.
const params = new URLSearchParams(location.hash.replace(/^#/, ''));
const SAFE_HOSTS = new Set(['127.0.0.1', 'localhost', '::1', '[::1]']);
let TD_HOST = params.get('host') || '127.0.0.1';
let TD_PORT = params.get('port') || '9987';
if (!SAFE_HOSTS.has(TD_HOST)) TD_HOST = '127.0.0.1';
if (!/^\d{1,5}$/.test(TD_PORT)) TD_PORT = '9987';
const SEND_URL = `http://${TD_HOST}:${TD_PORT}/send`;
const STOP_URL = `http://${TD_HOST}:${TD_PORT}/stop`;
const FIRSTRUN_URL = `http://${TD_HOST}:${TD_PORT}/firstrun`;
// Per-launch session token, server-injected at GET / time. The literal
// `__TDPILOT_TOKEN__` value means the page was loaded out-of-band
// (file://, opened directly from disk) — fetches will 401 in that case
// and the user gets a clear "missing token" error rather than a silent
// CSRF window.
const _tokenMeta = document.querySelector('meta[name="tdpilot-token"]');
const TOKEN = _tokenMeta ? _tokenMeta.getAttribute('content') : '';
const HAS_VALID_TOKEN = TOKEN && TOKEN !== '__TDPILOT_TOKEN__';
const AUTH_HEADERS = HAS_VALID_TOKEN ? { 'X-TDPilot-Token': TOKEN } : {};
// Welcome HTML — single source of truth for the initial render AND
// any fullSync([]) rebuild. Pre-1.7.1 these diverged: only the inline
// initial DOM had the wizard div, so the first /reset wiped it
// permanently. Defining it once means the DOM stays consistent.
const WELCOME_HTML = `
<div class="welcome">
<pre class="logo">████████╗██████╗ ██████╗ ██╗██╗ ██████╗ ████████╗
╚══██╔══╝██╔══██╗██╔══██╗██║██║ ██╔═══██╗╚══██╔══╝
██║ ██║ ██║██████╔╝██║██║ ██║ ██║ ██║
██║ ██║ ██║██╔═══╝ ██║██║ ██║ ██║ ██║
██║ ██████╔╝██║ ██║███████╗╚██████╔╝ ██║
╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝</pre>
<div class="tag">api · standalone · deepseek v4</div>
<hr class="divider" />
<div id="wizard" class="wizard" style="display:none;">
<h4>quickstart</h4>
<ol id="wizard-steps"></ol>
</div>
<div class="body">
type a message and press <kbd>enter</kbd><br/>
<kbd>shift</kbd>+<kbd>enter</kbd> for newline
</div>
</div>`;
const $history = document.getElementById('history');
const $input = document.getElementById('input');
const $send = document.getElementById('send');
const $stop = document.getElementById('stop');
const $status = document.getElementById('status-text');
const $statusBar = document.getElementById('status-bar');
const $lhs = $statusBar.querySelector('.lhs');
const $wsState = document.getElementById('ws-state');
const $modelBadge = document.getElementById('model-badge');
const $tokenMeter = document.getElementById('token-meter');
const $scrollJump = document.getElementById('scroll-jump');
const $quietToggle = document.getElementById('quiet-toggle');
// v2.1.0 — quiet-mode toggle. Replaces the v2.0.0 font-size toggle
// (the `aA` glyph control) which had inconsistent scaling and felt
// out of place. Quiet mode hides the tool-call / tool-result blocks
// so the chat stays readable as a conversation: user prompts +
// assistant text + errors only. The agent's per-turn working state
// is still surfaced via the status bar at the top, so there's no
// progress-blackout. State persists per-browser via localStorage.
const QUIET_KEY = 'tdpilot.quietMode';
function applyQuietMode(on) {
if (on) document.documentElement.classList.add('quiet-mode');
else document.documentElement.classList.remove('quiet-mode');
$quietToggle.setAttribute('aria-pressed', on ? 'true' : 'false');
$quietToggle.querySelector('.qm-glyph').textContent = on ? '●' : '○';
try { localStorage.setItem(QUIET_KEY, on ? '1' : '0'); } catch (_) { /* private mode */ }
}
let _savedQuiet = false;
try { _savedQuiet = localStorage.getItem(QUIET_KEY) === '1'; } catch (_) { /* private mode */ }
applyQuietMode(_savedQuiet);
$quietToggle.addEventListener('click', () => {
applyQuietMode(!document.documentElement.classList.contains('quiet-mode'));
});
// v2.1.0 — contextual ASCII flourishes. On agent turn-end (status
// transitions to idle after a non-idle state), pick a small glyph
// from a topic-matched pool and append it to the latest assistant
// message as a quiet visual punctuation. Retro-monochrome aesthetic
// — geometric / typographic, no emoji, no color beyond --accent-dim.
const ASCII_FLOURISHES = {
default: ['▰▰▰', '∴', '◇ ◇ ◇', '═══', '· · ·', '──◆──', '·:·:·', '▱▰▱', '── ✦ ──'],
light: ['✺ ✸ ✺', '\\●/', '─ ✷ ─', '※ ✺ ※'],
camera: ['[◉]', '▤ ▥ ▤', '▣ ─ ▣', '┌─◎─┐'],
particle: ['· ∴ · ∴ ·', '⋆ ✦ ⋆', '·:·∴·:·', '∗ ⋆ ∗'],
material: ['▓▒░ ░▒▓', '░▒▓▒░', '▓ ─ ▓'],
audio: ['~~~ ∿ ~~~', '∿∿∿∿', '· ∿ · ∿ ·'],
geom: ['◆ ─ ◇ ─ ◆', '△ ▽ △', '□ ▣ □', '◯ ◉ ◯'],
error: ['× × ×', '!? ─ ?!', '× ─ ✗ ─ ×'],
success: ['✓ ✓ ✓', '✦ ─ ▰ ─ ✦', '── ✓ ──', '· · ✦ · ·'],
};
const TOPIC_RULES = [
{ topic: 'light', re: /\b(light|lamp|illuminat|sun|shadow|brightness|expos)/i },
{ topic: 'camera', re: /\b(camera|view|render|frame|lens|fov|projection|cam[0-9]?)\b/i },
{ topic: 'particle', re: /\b(particle|pop|noise|swirl|flow|fluid|sand|spark)/i },
{ topic: 'material', re: /\b(material|texture|color|paint|pbr|phong|shader)/i },
{ topic: 'audio', re: /\b(audio|sound|music|chop|wave|spectrum|fft)/i },
{ topic: 'geom', re: /\b(sop|geom|mesh|sphere|box|grid|line|extrude|topo)/i },
{ topic: 'error', re: /\b(error|fail|broken|crash|exception|traceback)/i },
{ topic: 'success', re: /\b(done|complete|fixed|working|success|ready|shipped|live)/i },
];
function pickFlourish(contextText) {
const text = String(contextText || '');
const matched = ['default'];
for (const { topic, re } of TOPIC_RULES) {
if (re.test(text)) matched.push(topic);
}
// Prefer a matched topic over default (skew last) — pick uniform random
// from matched, but if any non-default topic matched, weight it 2× by
// putting default at the tail of the choice list.
const specific = matched.filter((t) => t !== 'default');
const pool = specific.length > 0 && Math.random() > 0.25
? ASCII_FLOURISHES[specific[Math.floor(Math.random() * specific.length)]]
: ASCII_FLOURISHES.default;
const glyph = pool[Math.floor(Math.random() * pool.length)];
const topic = specific.length > 0 ? specific[0] : '';
return { glyph, topic };
}
function attachFlourishToLastAssistant() {
// Walk backwards through #history children to find the most recent
// assistant message that doesn't already carry a flourish.
const msgs = $history.querySelectorAll('.msg.assistant');
if (msgs.length === 0) return;
const last = msgs[msgs.length - 1];
if (last.querySelector('.msg-flourish')) return;
// Use the last user message as the primary topic source (most
// accurate signal of what the turn is about), with the assistant
// body as fallback so a generic prompt like "fix it" still picks
// up topic from the response.
const userMsgs = $history.querySelectorAll('.msg.user .body');
const lastUser = userMsgs.length > 0 ? userMsgs[userMsgs.length - 1].textContent : '';
const assistantBody = last.querySelector('.body');
const ctx = (lastUser || '') + ' ' + (assistantBody ? assistantBody.textContent : '');
const { glyph, topic } = pickFlourish(ctx);
const f = document.createElement('div');
f.className = 'msg-flourish';
f.textContent = glyph;
if (topic) {
const t = document.createElement('span');
t.className = 'topic';
t.textContent = topic;
f.appendChild(t);
}
last.appendChild(f);
}
// Render the initial welcome from the same template fullSync uses, so
// the wizard DOM is guaranteed present.
$history.innerHTML = WELCOME_HTML;
// Three-cell block-wave animation that ties to the project's ASCII
// logo aesthetic. Active while the agent is working; pauses to a
// steady triple-block when idle.
const PULSE_FRAMES = ['▰▱▱', '▱▰▱', '▱▱▰', '▱▰▱'];
const PULSE_INTERVAL_MS = 180;
const STEADY_PREFIX = '▰▰▰';
let pulseTimer = null;
let pulseIdx = 0;
// Pre-1.7.1 there was a single setStatus() driven by both agent
// events AND ws transport events. Reconnect strings like
// "reconnecting in 500ms" fell through isWorkingStatus's allow-list
// and rendered the Stop button + pulse animation as if a turn were
// in flight. Now agent and ws state are tracked separately and
// composed into the displayed text by render().
let agentState = 'idle'; // idle | thinking | calling | reset | error | <free-form>
let wsState = 'connecting'; // connecting | connected | reconnecting
// Phase 2 (1.8.0) — status-bar split: transport on the LHS, agent
// state + model + token meter on the RHS. modelShort is one of
// "flash" | "pro" | <model name>; tokenMeter accumulates over the
// current turn and resets when the agent transitions out of idle.
let modelShort = '';
let modelTier = '';
let modelFull = '';
let turnInputTokens = 0;