pi-tps-web 1.0.0

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.
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none" viewBox="0 0 256 256">
2
+ <rect width="256" height="256" rx="48" fill="#0891b2" />
3
+ <!-- Outer gauge arc (semicircle) -->
4
+ <path fill="none" stroke="#fff" stroke-width="14" stroke-linecap="round" d="M48 172 A80 80 0 0 1 208 172" />
5
+ <!-- Tick marks -->
6
+ <line x1="128" y1="56" x2="128" y2="76" stroke="#fff" stroke-width="10" stroke-linecap="round" />
7
+ <line x1="76.6" y1="78.6" x2="88.3" y2="94.3" stroke="#fff" stroke-width="8" stroke-linecap="round" />
8
+ <line x1="179.4" y1="78.6" x2="167.7" y2="94.3" stroke="#fff" stroke-width="8" stroke-linecap="round" />
9
+ <!-- Needle pointing toward upper-right (around 60% mark) -->
10
+ <line x1="128" y1="148" x2="170" y2="90" stroke="#fff" stroke-width="11" stroke-linecap="round" />
11
+ <!-- Center dot -->
12
+ <circle cx="128" cy="148" r="9" fill="#0891b2" stroke="#fff" stroke-width="5" />
13
+ </svg>
package/dist/icons.svg ADDED
@@ -0,0 +1,24 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg">
2
+ <symbol id="bluesky-icon" viewBox="0 0 16 17">
3
+ <g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
4
+ <defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
5
+ </symbol>
6
+ <symbol id="discord-icon" viewBox="0 0 20 19">
7
+ <path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
8
+ </symbol>
9
+ <symbol id="documentation-icon" viewBox="0 0 21 20">
10
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
11
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
12
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
13
+ </symbol>
14
+ <symbol id="github-icon" viewBox="0 0 19 19">
15
+ <path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
16
+ </symbol>
17
+ <symbol id="social-icon" viewBox="0 0 20 20">
18
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
19
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
20
+ </symbol>
21
+ <symbol id="x-icon" viewBox="0 0 19 19">
22
+ <path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
23
+ </symbol>
24
+ </svg>
@@ -0,0 +1,25 @@
1
+ <!doctype html>
2
+ <html lang="en" class="">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <link rel="apple-touch-icon" href="/favicon.svg" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
+ <title>pi-tps — Telemetry Inspector</title>
9
+ <meta name="description" content="Inspect pi telemetry JSONL files. Analyze LLM tokens-per-second, timing, cache behavior, and routing performance." />
10
+ <script>
11
+ // Inline script to prevent flash of wrong theme
12
+ (function() {
13
+ var stored = localStorage.getItem('theme');
14
+ if (stored === 'dark' || (!stored && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
15
+ document.documentElement.classList.add('dark');
16
+ }
17
+ })();
18
+ </script>
19
+ <script type="module" crossorigin src="/assets/index-BwpWPmjQ.js"></script>
20
+ <link rel="stylesheet" crossorigin href="/assets/index-DRtHH789.css">
21
+ </head>
22
+ <body>
23
+ <div id="root"></div>
24
+ </body>
25
+ </html>
Binary file
@@ -0,0 +1,80 @@
1
+ {"type":"model_change","id":"43da7bba","parentId":null,"timestamp":"2026-04-27T02:53:43.804Z","provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"}
2
+ {"type":"model_change","id":"fe093596","parentId":"43da7bba","timestamp":"2026-04-27T02:53:45.919Z","provider":"deepseek","modelId":"deepseek-v4-flash"}
3
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":2054,"output":147,"cacheRead":0,"cacheWrite":0,"total":2201},"timing":{"ttftMs":832,"totalMs":3247,"generationMs":2341,"stallMs":0,"stallCount":0,"messageCount":1},"tps":62.8,"timestamp":1777258432869,"cost":{"input":0.00028756,"output":4.116e-05,"cacheRead":0.0,"cacheWrite":0.0,"total":0.00032872}},"id":"c01c9425","parentId":"fe093596","timestamp":"2026-04-27T02:53:52.872Z"}
4
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":699,"output":664,"cacheRead":2048,"cacheWrite":0,"total":3411},"timing":{"ttftMs":544,"totalMs":9148,"generationMs":8853,"stallMs":0,"stallCount":0,"messageCount":1},"tps":75,"timestamp":1777258442021,"cost":{"input":9.786e-05,"output":0.00018592,"cacheRead":5.734e-05,"cacheWrite":0.0,"total":0.00034112}},"id":"0a92c6e3","parentId":"c01c9425","timestamp":"2026-04-27T02:54:02.021Z"}
5
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":17244,"output":181,"cacheRead":2688,"cacheWrite":0,"total":20113},"timing":{"ttftMs":1170,"totalMs":10840,"generationMs":3455,"stallMs":0,"stallCount":0,"messageCount":1},"tps":52.4,"timestamp":1777258452862,"cost":{"input":0.00241416,"output":5.068e-05,"cacheRead":7.526e-05,"cacheWrite":0.0,"total":0.0025401}},"id":"62131488","parentId":"0a92c6e3","timestamp":"2026-04-27T02:54:12.862Z"}
6
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":421,"output":1935,"cacheRead":19840,"cacheWrite":0,"total":22196},"timing":{"ttftMs":659,"totalMs":27070,"generationMs":26659,"stallMs":0,"stallCount":0,"messageCount":1},"tps":72.6,"timestamp":1777258479932,"cost":{"input":5.894e-05,"output":0.0005418,"cacheRead":0.00055552,"cacheWrite":0.0,"total":0.00115626}},"id":"47fbc1a4","parentId":"62131488","timestamp":"2026-04-27T02:54:39.932Z"}
7
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["4fc02dbf4212f3c23ca318cad6dd043b9fc70a08"],"bindings":[["01278344",0],["ff4a356e",0],["dde06e56",0],["c3d7e693",0],["b1ed73e7",0]]},"id":"ef9f2bc9","parentId":"47fbc1a4","timestamp":"2026-04-27T02:54:39.932Z"}
8
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1989,"output":2570,"cacheRead":20224,"cacheWrite":0,"total":24783},"timing":{"ttftMs":1385,"totalMs":37030,"generationMs":35934,"stallMs":0,"stallCount":0,"messageCount":1},"tps":71.5,"timestamp":1777258547748,"cost":{"input":0.00027846,"output":0.0007196,"cacheRead":0.00056627,"cacheWrite":0.0,"total":0.00156433}},"id":"61469373","parentId":"ef9f2bc9","timestamp":"2026-04-27T02:55:47.748Z"}
9
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["4fc02dbf4212f3c23ca318cad6dd043b9fc70a08"],"bindings":[["01278344",0],["d636c42b",0]]},"id":"1a642379","parentId":"61469373","timestamp":"2026-04-27T02:55:47.748Z"}
10
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1529,"output":3899,"cacheRead":22144,"cacheWrite":0,"total":27572},"timing":{"ttftMs":804,"totalMs":56414,"generationMs":55933,"stallMs":0,"stallCount":0,"messageCount":1},"tps":69.7,"timestamp":1777258606543,"cost":{"input":0.00021406,"output":0.00109172,"cacheRead":0.00062003,"cacheWrite":0.0,"total":0.00192581}},"id":"96d576ff","parentId":"1a642379","timestamp":"2026-04-27T02:56:46.543Z"}
11
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":7947,"output":215,"cacheRead":23552,"cacheWrite":0,"total":31714},"timing":{"ttftMs":942,"totalMs":3867,"generationMs":3355,"stallMs":0,"stallCount":0,"messageCount":1},"tps":64.1,"timestamp":1777258610410,"cost":{"input":0.00111258,"output":6.02e-05,"cacheRead":0.00065946,"cacheWrite":0.0,"total":0.00183224}},"id":"033c424b","parentId":"96d576ff","timestamp":"2026-04-27T02:56:50.411Z"}
12
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":10829,"output":276,"cacheRead":31488,"cacheWrite":0,"total":42593},"timing":{"ttftMs":1268,"totalMs":4831,"generationMs":4244,"stallMs":0,"stallCount":0,"messageCount":1},"tps":65,"timestamp":1777258615242,"cost":{"input":0.00151606,"output":7.728e-05,"cacheRead":0.00088166,"cacheWrite":0.0,"total":0.002475}},"id":"40e542b6","parentId":"033c424b","timestamp":"2026-04-27T02:56:55.242Z"}
13
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":416,"output":115,"cacheRead":42240,"cacheWrite":0,"total":42771},"timing":{"ttftMs":963,"totalMs":2644,"generationMs":2096,"stallMs":0,"stallCount":0,"messageCount":1},"tps":54.9,"timestamp":1777258617886,"cost":{"input":5.824e-05,"output":3.22e-05,"cacheRead":0.00118272,"cacheWrite":0.0,"total":0.00127316}},"id":"742ea5fb","parentId":"40e542b6","timestamp":"2026-04-27T02:56:57.886Z"}
14
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1395,"output":105,"cacheRead":42624,"cacheWrite":0,"total":44124},"timing":{"ttftMs":1133,"totalMs":2353,"generationMs":1669,"stallMs":0,"stallCount":0,"messageCount":1},"tps":62.9,"timestamp":1777258620239,"cost":{"input":0.0001953,"output":2.94e-05,"cacheRead":0.00119347,"cacheWrite":0.0,"total":0.00141817}},"id":"dbde9770","parentId":"742ea5fb","timestamp":"2026-04-27T02:57:00.239Z"}
15
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":493,"output":109,"cacheRead":43904,"cacheWrite":0,"total":44506},"timing":{"ttftMs":1306,"totalMs":2666,"generationMs":1940,"stallMs":0,"stallCount":0,"messageCount":1},"tps":56.2,"timestamp":1777258622905,"cost":{"input":6.902e-05,"output":3.052e-05,"cacheRead":0.00122931,"cacheWrite":0.0,"total":0.00132885}},"id":"b444db08","parentId":"dbde9770","timestamp":"2026-04-27T02:57:02.905Z"}
16
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":880,"output":127,"cacheRead":44288,"cacheWrite":0,"total":45295},"timing":{"ttftMs":886,"totalMs":2774,"generationMs":2086,"stallMs":0,"stallCount":0,"messageCount":1},"tps":60.9,"timestamp":1777258625679,"cost":{"input":0.0001232,"output":3.556e-05,"cacheRead":0.00124006,"cacheWrite":0.0,"total":0.00139882}},"id":"d2db3dc1","parentId":"b444db08","timestamp":"2026-04-27T02:57:05.679Z"}
17
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":257,"output":109,"cacheRead":45056,"cacheWrite":0,"total":45422},"timing":{"ttftMs":1013,"totalMs":2307,"generationMs":1727,"stallMs":0,"stallCount":0,"messageCount":1},"tps":63.1,"timestamp":1777258627986,"cost":{"input":3.598e-05,"output":3.052e-05,"cacheRead":0.00126157,"cacheWrite":0.0,"total":0.00132807}},"id":"d242d8bf","parentId":"d2db3dc1","timestamp":"2026-04-27T02:57:07.986Z"}
18
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":292,"output":139,"cacheRead":45312,"cacheWrite":0,"total":45743},"timing":{"ttftMs":1132,"totalMs":2996,"generationMs":2431,"stallMs":0,"stallCount":0,"messageCount":1},"tps":57.2,"timestamp":1777258630982,"cost":{"input":4.088e-05,"output":3.892e-05,"cacheRead":0.00126874,"cacheWrite":0.0,"total":0.00134854}},"id":"991d1a36","parentId":"d242d8bf","timestamp":"2026-04-27T02:57:10.982Z"}
19
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":189,"output":2529,"cacheRead":45568,"cacheWrite":0,"total":48286},"timing":{"ttftMs":925,"totalMs":36394,"generationMs":35631,"stallMs":0,"stallCount":0,"messageCount":1},"tps":71,"timestamp":1777258667376,"cost":{"input":2.646e-05,"output":0.00070812,"cacheRead":0.0012759,"cacheWrite":0.0,"total":0.00201048}},"id":"c8867f21","parentId":"991d1a36","timestamp":"2026-04-27T02:57:47.376Z"}
20
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":2637,"output":569,"cacheRead":45696,"cacheWrite":0,"total":48902},"timing":{"ttftMs":807,"totalMs":8030,"generationMs":7385,"stallMs":0,"stallCount":0,"messageCount":1},"tps":77,"timestamp":1777258675406,"cost":{"input":0.00036918,"output":0.00015932,"cacheRead":0.00127949,"cacheWrite":0.0,"total":0.00180799}},"id":"3ca6f834","parentId":"c8867f21","timestamp":"2026-04-27T02:57:55.406Z"}
21
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":695,"output":285,"cacheRead":48256,"cacheWrite":0,"total":49236},"timing":{"ttftMs":818,"totalMs":4852,"generationMs":4275,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66.7,"timestamp":1777258680258,"cost":{"input":9.73e-05,"output":7.98e-05,"cacheRead":0.00135117,"cacheWrite":0.0,"total":0.00152827}},"id":"c2fba4fb","parentId":"3ca6f834","timestamp":"2026-04-27T02:58:00.258Z"}
22
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":389,"output":151,"cacheRead":48896,"cacheWrite":0,"total":49436},"timing":{"ttftMs":904,"totalMs":2995,"generationMs":2468,"stallMs":0,"stallCount":0,"messageCount":1},"tps":61.2,"timestamp":1777258683253,"cost":{"input":5.446e-05,"output":4.228e-05,"cacheRead":0.00136909,"cacheWrite":0.0,"total":0.00146583}},"id":"4e3b2d7f","parentId":"c2fba4fb","timestamp":"2026-04-27T02:58:03.253Z"}
23
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":205,"output":402,"cacheRead":49280,"cacheWrite":0,"total":49887},"timing":{"ttftMs":984,"totalMs":6306,"generationMs":5711,"stallMs":0,"stallCount":0,"messageCount":1},"tps":70.4,"timestamp":1777258689559,"cost":{"input":2.87e-05,"output":0.00011256,"cacheRead":0.00137984,"cacheWrite":0.0,"total":0.0015211}},"id":"d3559103","parentId":"4e3b2d7f","timestamp":"2026-04-27T02:58:09.559Z"}
24
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":528,"output":620,"cacheRead":49408,"cacheWrite":0,"total":50556},"timing":{"ttftMs":795,"totalMs":9513,"generationMs":8953,"stallMs":0,"stallCount":0,"messageCount":1},"tps":69.3,"timestamp":1777258699072,"cost":{"input":7.392e-05,"output":0.0001736,"cacheRead":0.00138342,"cacheWrite":0.0,"total":0.00163094}},"id":"89174383","parentId":"d3559103","timestamp":"2026-04-27T02:58:19.072Z"}
25
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":691,"output":203,"cacheRead":49920,"cacheWrite":0,"total":50814},"timing":{"ttftMs":763,"totalMs":3573,"generationMs":2993,"stallMs":0,"stallCount":0,"messageCount":1},"tps":67.8,"timestamp":1777258702645,"cost":{"input":9.674e-05,"output":5.684e-05,"cacheRead":0.00139776,"cacheWrite":0.0,"total":0.00155134}},"id":"1282fb3c","parentId":"89174383","timestamp":"2026-04-27T02:58:22.645Z"}
26
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":545,"output":251,"cacheRead":50560,"cacheWrite":0,"total":51356},"timing":{"ttftMs":790,"totalMs":4556,"generationMs":3981,"stallMs":0,"stallCount":0,"messageCount":1},"tps":63,"timestamp":1777258707201,"cost":{"input":7.63e-05,"output":7.028e-05,"cacheRead":0.00141568,"cacheWrite":0.0,"total":0.00156226}},"id":"22244f40","parentId":"1282fb3c","timestamp":"2026-04-27T02:58:27.201Z"}
27
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":339,"output":403,"cacheRead":51072,"cacheWrite":0,"total":51814},"timing":{"ttftMs":950,"totalMs":6356,"generationMs":5824,"stallMs":0,"stallCount":0,"messageCount":1},"tps":69.2,"timestamp":1777258713557,"cost":{"input":4.746e-05,"output":0.00011284,"cacheRead":0.00143002,"cacheWrite":0.0,"total":0.00159032}},"id":"217b736f","parentId":"22244f40","timestamp":"2026-04-27T02:58:33.557Z"}
28
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":541,"output":159,"cacheRead":51328,"cacheWrite":0,"total":52028},"timing":{"ttftMs":770,"totalMs":3032,"generationMs":2431,"stallMs":0,"stallCount":0,"messageCount":1},"tps":65.4,"timestamp":1777258716589,"cost":{"input":7.574e-05,"output":4.452e-05,"cacheRead":0.00143718,"cacheWrite":0.0,"total":0.00155744}},"id":"9d8f8819","parentId":"217b736f","timestamp":"2026-04-27T02:58:36.589Z"}
29
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":298,"output":125,"cacheRead":51840,"cacheWrite":0,"total":52263},"timing":{"ttftMs":1322,"totalMs":2976,"generationMs":2373,"stallMs":0,"stallCount":0,"messageCount":1},"tps":52.7,"timestamp":1777258719565,"cost":{"input":4.172e-05,"output":3.5e-05,"cacheRead":0.00145152,"cacheWrite":0.0,"total":0.00152824}},"id":"7e1b84cf","parentId":"9d8f8819","timestamp":"2026-04-27T02:58:39.565Z"}
30
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":479,"output":590,"cacheRead":52096,"cacheWrite":0,"total":53165},"timing":{"ttftMs":836,"totalMs":9105,"generationMs":8398,"stallMs":0,"stallCount":0,"messageCount":1},"tps":70.3,"timestamp":1777258728670,"cost":{"input":6.706e-05,"output":0.0001652,"cacheRead":0.00145869,"cacheWrite":0.0,"total":0.00169095}},"id":"a4dcdc17","parentId":"7e1b84cf","timestamp":"2026-04-27T02:58:48.670Z"}
31
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":780,"output":221,"cacheRead":52480,"cacheWrite":0,"total":53481},"timing":{"ttftMs":1697,"totalMs":4217,"generationMs":3481,"stallMs":0,"stallCount":0,"messageCount":1},"tps":63.5,"timestamp":1777258732887,"cost":{"input":0.0001092,"output":6.188e-05,"cacheRead":0.00146944,"cacheWrite":0.0,"total":0.00164052}},"id":"2b452ae1","parentId":"a4dcdc17","timestamp":"2026-04-27T02:58:52.888Z"}
32
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":288,"output":154,"cacheRead":53248,"cacheWrite":0,"total":53690},"timing":{"ttftMs":954,"totalMs":3300,"generationMs":2690,"stallMs":0,"stallCount":0,"messageCount":1},"tps":57.2,"timestamp":1777258736188,"cost":{"input":4.032e-05,"output":4.312e-05,"cacheRead":0.00149094,"cacheWrite":0.0,"total":0.00157438}},"id":"6b346dc7","parentId":"2b452ae1","timestamp":"2026-04-27T02:58:56.188Z"}
33
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1496,"output":781,"cacheRead":53504,"cacheWrite":0,"total":55781},"timing":{"ttftMs":844,"totalMs":10895,"generationMs":10196,"stallMs":0,"stallCount":0,"messageCount":1},"tps":76.6,"timestamp":1777258747083,"cost":{"input":0.00020944,"output":0.00021868,"cacheRead":0.00149811,"cacheWrite":0.0,"total":0.00192623}},"id":"6c06c2fa","parentId":"6b346dc7","timestamp":"2026-04-27T02:59:07.083Z"}
34
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":924,"output":187,"cacheRead":54912,"cacheWrite":0,"total":56023},"timing":{"ttftMs":918,"totalMs":10616,"generationMs":2777,"stallMs":0,"stallCount":0,"messageCount":1},"tps":67.3,"timestamp":1777258757699,"cost":{"input":0.00012936,"output":5.236e-05,"cacheRead":0.00153754,"cacheWrite":0.0,"total":0.00171926}},"id":"014cab71","parentId":"6c06c2fa","timestamp":"2026-04-27T02:59:17.699Z"}
35
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":505,"output":408,"cacheRead":55808,"cacheWrite":0,"total":56721},"timing":{"ttftMs":1066,"totalMs":6997,"generationMs":6147,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66.4,"timestamp":1777258764696,"cost":{"input":7.07e-05,"output":0.00011424,"cacheRead":0.00156262,"cacheWrite":0.0,"total":0.00174756}},"id":"91446c37","parentId":"014cab71","timestamp":"2026-04-27T02:59:24.696Z"}
36
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":550,"output":147,"cacheRead":56192,"cacheWrite":0,"total":56889},"timing":{"ttftMs":865,"totalMs":2955,"generationMs":2277,"stallMs":0,"stallCount":0,"messageCount":1},"tps":64.6,"timestamp":1777258767651,"cost":{"input":7.7e-05,"output":4.116e-05,"cacheRead":0.00157338,"cacheWrite":0.0,"total":0.00169154}},"id":"0e16a0e8","parentId":"91446c37","timestamp":"2026-04-27T02:59:27.651Z"}
37
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":670,"output":158,"cacheRead":56704,"cacheWrite":0,"total":57532},"timing":{"ttftMs":796,"totalMs":3176,"generationMs":2581,"stallMs":0,"stallCount":0,"messageCount":1},"tps":61.2,"timestamp":1777258770828,"cost":{"input":9.38e-05,"output":4.424e-05,"cacheRead":0.00158771,"cacheWrite":0.0,"total":0.00172575}},"id":"947c42d1","parentId":"0e16a0e8","timestamp":"2026-04-27T02:59:30.828Z"}
38
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":241,"output":133,"cacheRead":57344,"cacheWrite":0,"total":57718},"timing":{"ttftMs":900,"totalMs":2931,"generationMs":2273,"stallMs":0,"stallCount":0,"messageCount":1},"tps":58.5,"timestamp":1777258773760,"cost":{"input":3.374e-05,"output":3.724e-05,"cacheRead":0.00160563,"cacheWrite":0.0,"total":0.00167661}},"id":"d1d3e435","parentId":"947c42d1","timestamp":"2026-04-27T02:59:33.760Z"}
39
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":267,"output":162,"cacheRead":57472,"cacheWrite":0,"total":57901},"timing":{"ttftMs":837,"totalMs":3129,"generationMs":2456,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66,"timestamp":1777258776890,"cost":{"input":3.738e-05,"output":4.536e-05,"cacheRead":0.00160922,"cacheWrite":0.0,"total":0.00169196}},"id":"3e7378c9","parentId":"d1d3e435","timestamp":"2026-04-27T02:59:36.890Z"}
40
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1896,"output":957,"cacheRead":57728,"cacheWrite":0,"total":60581},"timing":{"ttftMs":1075,"totalMs":14513,"generationMs":13818,"stallMs":0,"stallCount":0,"messageCount":1},"tps":69.3,"timestamp":1777258791403,"cost":{"input":0.00026544,"output":0.00026796,"cacheRead":0.00161638,"cacheWrite":0.0,"total":0.00214978}},"id":"afebd9c7","parentId":"3e7378c9","timestamp":"2026-04-27T02:59:51.403Z"}
41
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":1715,"output":789,"cacheRead":59520,"cacheWrite":0,"total":62024},"timing":{"ttftMs":911,"totalMs":11235,"generationMs":10327,"stallMs":0,"stallCount":0,"messageCount":1},"tps":76.4,"timestamp":1777258802639,"cost":{"input":0.0002401,"output":0.00022092,"cacheRead":0.00166656,"cacheWrite":0.0,"total":0.00212758}},"id":"afeef8de","parentId":"afebd9c7","timestamp":"2026-04-27T03:00:02.639Z"}
42
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":889,"output":438,"cacheRead":61184,"cacheWrite":0,"total":62511},"timing":{"ttftMs":937,"totalMs":7320,"generationMs":6552,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66.8,"timestamp":1777258809959,"cost":{"input":0.00012446,"output":0.00012264,"cacheRead":0.00171315,"cacheWrite":0.0,"total":0.00196025}},"id":"b8327a14","parentId":"afeef8de","timestamp":"2026-04-27T03:00:09.959Z"}
43
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":614,"output":117,"cacheRead":61952,"cacheWrite":0,"total":62683},"timing":{"ttftMs":1268,"totalMs":10715,"generationMs":2177,"stallMs":0,"stallCount":0,"messageCount":1},"tps":53.7,"timestamp":1777258820674,"cost":{"input":8.596e-05,"output":3.276e-05,"cacheRead":0.00173466,"cacheWrite":0.0,"total":0.00185338}},"id":"c887b7be","parentId":"b8327a14","timestamp":"2026-04-27T03:00:20.674Z"}
44
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":360,"output":106,"cacheRead":62464,"cacheWrite":0,"total":62930},"timing":{"ttftMs":1125,"totalMs":2778,"generationMs":1983,"stallMs":0,"stallCount":0,"messageCount":1},"tps":53.5,"timestamp":1777258823452,"cost":{"input":5.04e-05,"output":2.968e-05,"cacheRead":0.00174899,"cacheWrite":0.0,"total":0.00182907}},"id":"6d2482e3","parentId":"c887b7be","timestamp":"2026-04-27T03:00:23.452Z"}
45
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":4172,"output":488,"cacheRead":62720,"cacheWrite":0,"total":67380},"timing":{"ttftMs":1628,"totalMs":8081,"generationMs":7376,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66.2,"timestamp":1777258831533,"cost":{"input":0.00058408,"output":0.00013664,"cacheRead":0.00175616,"cacheWrite":0.0,"total":0.00247688}},"id":"c28ab64d","parentId":"6d2482e3","timestamp":"2026-04-27T03:00:31.533Z"}
46
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["4fc02dbf4212f3c23ca318cad6dd043b9fc70a08","d2836a5e2156ae4c68ea6e034c0200faa303d766","ea64153b0d1031209a2a66c33c8cf9094960e0a8","bc53b98e50e91f17510f3b2d285857b5057f46a5","24997cd8a633136d4dfbc9bc7b0fb91dc85f0a87","4bcd5bd1b47ef85da784de1b566ef13038d06df6","b05d9ff440bad2f70d922aaabc10bc97f5e5fed2","1dad32590da08e7f79b9807c5078b229c65978d8","adeffc22a9ddd379370ef41c89f3dd1bf44bb99c","364e3a5951a11ec42173d76bf9f43c659bbb76da","d4b1090dddb881772b88dfd16c3237135f1541b4","8fcab086aef648769d84fe4a9332f19667ccfc77","d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"bindings":[["7d09d7c7",0],["0eedb817",0],["f1772cb6",0],["a4e354c9",0],["f660b01c",0],["33d5f051",0],["b9aae25d",0],["e7c2f49d",0],["d40a6aea",0],["4610b3b9",0],["15230934",1],["52d47112",2],["05e9c4d1",3],["adee190a",4],["4bf9d1e9",5],["31be0e67",6],["15335182",6],["b491eac0",7],["186d1d91",8],["2d21a522",8],["229488c0",8],["75153da5",8],["83d23cf5",9],["028352d3",9],["83d8e38e",10],["6a39ba79",10],["be527a3f",10],["bc9a91d6",10],["9e482d77",10],["f69f981d",10],["b8a395b1",10],["60040c8e",10],["aced0f5f",11],["bb2de4f6",12],["85f676f8",12],["ada8a0b5",12],["aa823bcd",12]]},"id":"d95dae69","parentId":"c28ab64d","timestamp":"2026-04-27T03:00:31.534Z"}
47
+ {"type":"model_change","id":"4b4d7b2e","parentId":"d95dae69","timestamp":"2026-04-27T03:39:19.397Z","provider":"wafer","modelId":"GLM-5.1"}
48
+ {"type":"custom","customType":"rewind-op","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"current":0},"id":"89cb923b","parentId":"fe093596","timestamp":"2026-04-27T03:39:26.892Z"}
49
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":1874,"output":115,"cacheRead":0,"cacheWrite":0,"total":1989},"timing":{"ttftMs":2971,"totalMs":5430,"generationMs":2412,"stallMs":2142,"stallCount":2,"messageCount":1},"tps":47.7,"timestamp":1777261172409,"cost":{"input":0.002811,"output":0.0005175,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0033285}},"id":"ab28fe1f","parentId":"89cb923b","timestamp":"2026-04-27T03:39:32.409Z"}
50
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"bindings":[["ce692d64",0],["7d57cd5d",0],["f1c7ed74",0]]},"id":"7178db16","parentId":"ab28fe1f","timestamp":"2026-04-27T03:39:32.877Z"}
51
+ {"type":"custom","customType":"rewind-op","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"current":0},"id":"f8e97467","parentId":"6d2482e3","timestamp":"2026-04-27T03:39:40.617Z"}
52
+ {"type":"model_change","id":"7bc6154a","parentId":"f8e97467","timestamp":"2026-04-27T03:39:44.496Z","provider":"deepseek","modelId":"deepseek-v4-flash"}
53
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":578,"output":116,"cacheRead":66816,"cacheWrite":0,"total":67510},"timing":{"ttftMs":1001,"totalMs":2656,"generationMs":1865,"stallMs":0,"stallCount":0,"messageCount":1},"tps":62.2,"timestamp":1777261193158,"cost":{"input":8.092e-05,"output":3.248e-05,"cacheRead":0.00187085,"cacheWrite":0.0,"total":0.00198425}},"id":"058a9432","parentId":"7bc6154a","timestamp":"2026-04-27T03:39:53.158Z"}
54
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":298,"output":380,"cacheRead":67328,"cacheWrite":0,"total":68006},"timing":{"ttftMs":1013,"totalMs":8103,"generationMs":6323,"stallMs":0,"stallCount":0,"messageCount":1},"tps":60.1,"timestamp":1777261201262,"cost":{"input":4.172e-05,"output":0.0001064,"cacheRead":0.00188518,"cacheWrite":0.0,"total":0.0020333}},"id":"c2fb6c08","parentId":"058a9432","timestamp":"2026-04-27T03:40:01.262Z"}
55
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"deepseek","modelId":"deepseek-v4-flash"},"tokens":{"input":637,"output":102,"cacheRead":67584,"cacheWrite":0,"total":68323},"timing":{"ttftMs":911,"totalMs":2641,"generationMs":1951,"stallMs":0,"stallCount":0,"messageCount":1},"tps":52.3,"timestamp":1777261203903,"cost":{"input":8.918e-05,"output":2.856e-05,"cacheRead":0.00189235,"cacheWrite":0.0,"total":0.00201009}},"id":"0359e521","parentId":"c2fb6c08","timestamp":"2026-04-27T03:40:03.903Z"}
56
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"bindings":[["bb1fca49",0],["4c9826b7",0],["d2cb75a2",0],["7fe93e63",0]]},"id":"e795946f","parentId":"0359e521","timestamp":"2026-04-27T03:40:03.903Z"}
57
+ {"type":"model_change","id":"923a7c4a","parentId":"e795946f","timestamp":"2026-04-27T03:40:16.791Z","provider":"wafer","modelId":"GLM-5.1"}
58
+ {"type":"custom","customType":"rewind-op","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"current":0},"id":"fac8c302","parentId":"fe093596","timestamp":"2026-04-27T03:40:19.157Z"}
59
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":18,"output":108,"cacheRead":1856,"cacheWrite":0,"total":1982},"timing":{"ttftMs":1152,"totalMs":1892,"generationMs":669,"stallMs":0,"stallCount":0,"messageCount":1},"tps":161.4,"timestamp":1777261221164,"cost":{"input":2.7e-05,"output":0.000486,"cacheRead":0.0002784,"cacheWrite":0.0,"total":0.0007914}},"id":"f3aab89e","parentId":"fac8c302","timestamp":"2026-04-27T03:40:21.164Z"}
60
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":4790,"output":112,"cacheRead":0,"cacheWrite":0,"total":4902},"timing":{"ttftMs":1016,"totalMs":1722,"generationMs":280,"stallMs":0,"stallCount":0,"messageCount":1},"tps":400,"timestamp":1777261222886,"cost":{"input":0.007185,"output":0.000504,"cacheRead":0.0,"cacheWrite":0.0,"total":0.007689}},"id":"a4384ee6","parentId":"f3aab89e","timestamp":"2026-04-27T03:40:22.886Z"}
61
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":1510,"output":282,"cacheRead":4864,"cacheWrite":0,"total":6656},"timing":{"ttftMs":1076,"totalMs":8069,"generationMs":7291,"stallMs":5940,"stallCount":4,"messageCount":1},"tps":38.7,"timestamp":1777261230955,"cost":{"input":0.002265,"output":0.001269,"cacheRead":0.0007296,"cacheWrite":0.0,"total":0.0042636}},"id":"0059005f","parentId":"a4384ee6","timestamp":"2026-04-27T03:40:30.955Z"}
62
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":21193,"output":99,"cacheRead":0,"cacheWrite":0,"total":21292},"timing":{"ttftMs":7268,"totalMs":15889,"generationMs":1820,"stallMs":1228,"stallCount":2,"messageCount":1},"tps":54.4,"timestamp":1777261246844,"cost":{"input":0.0317895,"output":0.0004455,"cacheRead":0.0,"cacheWrite":0.0,"total":0.032235}},"id":"d9844866","parentId":"0059005f","timestamp":"2026-04-27T03:40:46.844Z"}
63
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":183,"output":40,"cacheRead":21248,"cacheWrite":0,"total":21471},"timing":{"ttftMs":2316,"totalMs":2907,"generationMs":527,"stallMs":0,"stallCount":0,"messageCount":1},"tps":75.9,"timestamp":1777261249751,"cost":{"input":0.0002745,"output":0.00018,"cacheRead":0.0031872,"cacheWrite":0.0,"total":0.0036417}},"id":"8354582c","parentId":"d9844866","timestamp":"2026-04-27T03:40:49.751Z"}
64
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":78,"output":40,"cacheRead":21440,"cacheWrite":0,"total":21558},"timing":{"ttftMs":993,"totalMs":8585,"generationMs":558,"stallMs":514,"stallCount":1,"messageCount":1},"tps":71.7,"timestamp":1777261258336,"cost":{"input":0.000117,"output":0.00018,"cacheRead":0.003216,"cacheWrite":0.0,"total":0.003513}},"id":"a61e5b7c","parentId":"8354582c","timestamp":"2026-04-27T03:40:58.336Z"}
65
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"wafer","modelId":"GLM-5.1"},"tokens":{"input":373,"output":1294,"cacheRead":21504,"cacheWrite":0,"total":23171},"timing":{"ttftMs":2102,"totalMs":20771,"generationMs":18637,"stallMs":9969,"stallCount":10,"messageCount":1},"tps":69.4,"timestamp":1777261279108,"cost":{"input":0.0005595,"output":0.005823,"cacheRead":0.0032256,"cacheWrite":0.0,"total":0.0096081}},"id":"9083b4ea","parentId":"a61e5b7c","timestamp":"2026-04-27T03:41:19.108Z"}
66
+ {"type":"custom","customType":"rewind-turn","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"bindings":[["6b1c26bf",0],["6753037c",0],["dc91e083",0],["4a5533ce",0],["4acc761b",0],["ab5be046",0],["9ea238cd",0],["f0a791bf",0]]},"id":"8bca37eb","parentId":"9083b4ea","timestamp":"2026-04-27T03:41:19.108Z"}
67
+ {"type":"model_change","id":"26a28b8b","parentId":"8bca37eb","timestamp":"2026-04-27T03:41:29.759Z","provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"}
68
+ {"type":"custom","customType":"rewind-op","data":{"v":2,"snapshots":["d09ad77c42e33fe053e93209b7227ea4a37bbf2c"],"current":0},"id":"20bd21d7","parentId":"fac8c302","timestamp":"2026-04-27T03:41:31.434Z"}
69
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":849,"output":124,"cacheRead":768,"cacheWrite":0,"total":1741},"timing":{"ttftMs":1613,"totalMs":4468,"generationMs":2627,"stallMs":0,"stallCount":0,"messageCount":1},"tps":47.2,"timestamp":1777261296005,"cost":{"input":0.0005943,"output":0.0003968,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0009911}},"id":"f640cde8","parentId":"20bd21d7","timestamp":"2026-04-27T03:41:36.005Z"}
70
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":1232.54,"cost_usd":0.001712,"sse_energy_raw":{"energy_joules":1232.54,"energy_kwh":0.0003423722222222222,"avg_power_watts":3805.3,"duration_seconds":0.32,"attribution_method":"prorated_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":17607.714285714283,"uncapped_energy_kwh":0.004891031746031745,"carbon_g_co2eq":0.1181184,"grid_carbon_intensity_gco2perkwhr":345,"grid_id":"US-MIDA-PJM","carbon_source":"agent_cache","mcr":{"compaction_triggered":false,"inference_energy_joules":1232.54,"compaction_energy_joules":0,"session_turns":1,"context_tokens":1725,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":1531,"all_chunks_cached":false,"mcr_compacted_tokens":0,"mcr_original_tokens":1612,"session_fp":"sample_fp_abc123","apc_hit_tokens":473,"apc_miss_tokens":1252,"apc_hit_rate":0.274,"current_turn_new_tokens":1500}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":2,"safe_drop_before":0,"apc_hit_tokens":473,"apc_miss_tokens":1252,"apc_hit_rate":0.274,"current_turn_new_tokens":1500},"sse_cost_raw":{"request_cost_usd":0.001712,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"206ddb12","parentId":"f640cde8","timestamp":"2026-04-27T03:41:36.005Z"}
71
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":756,"output":165,"cacheRead":1616,"cacheWrite":0,"total":2537},"timing":{"ttftMs":810,"totalMs":3397,"generationMs":2499,"stallMs":0,"stallCount":0,"messageCount":1},"tps":66,"timestamp":1777261299402,"cost":{"input":0.0005292,"output":0.000528,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0010572}},"id":"3d0ba14a","parentId":"206ddb12","timestamp":"2026-04-27T03:41:39.402Z"}
72
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":1174.47,"cost_usd":0.001631,"sse_energy_raw":{"energy_joules":1174.47,"energy_kwh":0.00032624166666666665,"avg_power_watts":3980.5,"duration_seconds":0.3,"attribution_method":"prorated_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":16778.142857142855,"uncapped_energy_kwh":0.004660595238095237,"carbon_g_co2eq":0.0652483,"grid_carbon_intensity_gco2perkwhr":200,"grid_id":"DE","carbon_source":"agent_cache","mcr":{"compaction_triggered":false,"inference_energy_joules":1174.47,"compaction_energy_joules":0,"session_turns":2,"context_tokens":5816,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":5705,"all_chunks_cached":false,"mcr_compacted_tokens":0,"mcr_original_tokens":5689,"session_fp":"sample_fp_abc123","apc_hit_tokens":2088,"apc_miss_tokens":3728,"apc_hit_rate":0.359,"current_turn_new_tokens":1900}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":3,"safe_drop_before":0,"apc_hit_tokens":2088,"apc_miss_tokens":3728,"apc_hit_rate":0.359,"current_turn_new_tokens":1900},"sse_cost_raw":{"request_cost_usd":0.001631,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"7c740bc7","parentId":"3d0ba14a","timestamp":"2026-04-27T03:41:39.402Z"}
73
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":15934,"output":4283,"cacheRead":2368,"cacheWrite":0,"total":22585},"timing":{"ttftMs":2656,"totalMs":85407,"generationMs":75692,"stallMs":22901,"stallCount":6,"messageCount":1},"tps":56.6,"timestamp":1777261384809,"cost":{"input":0.0111538,"output":0.0137056,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0248594}},"id":"041fa53a","parentId":"7c740bc7","timestamp":"2026-04-27T03:43:04.810Z"}
74
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":28436.7,"cost_usd":0.039495,"sse_energy_raw":{"energy_joules":28436.7,"energy_kwh":0.007899083333333334,"avg_power_watts":1893.5,"duration_seconds":15.02,"attribution_method":"counter_exact_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":406238.5714285714,"uncapped_energy_kwh":0.11284404761904762,"carbon_g_co2eq":1.5798167,"grid_carbon_intensity_gco2perkwhr":200,"grid_id":"DE","carbon_source":"agent_cache","mcr":{"compaction_triggered":false,"inference_energy_joules":28436.7,"compaction_energy_joules":0,"session_turns":3,"context_tokens":9701,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":9512,"all_chunks_cached":false,"mcr_compacted_tokens":0,"mcr_original_tokens":9532,"session_fp":"sample_fp_abc123","apc_hit_tokens":4880,"apc_miss_tokens":4821,"apc_hit_rate":0.503,"current_turn_new_tokens":2300}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":4,"safe_drop_before":0,"apc_hit_tokens":4880,"apc_miss_tokens":4821,"apc_hit_rate":0.503,"current_turn_new_tokens":2300},"sse_cost_raw":{"request_cost_usd":0.039495,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"4555f67d","parentId":"041fa53a","timestamp":"2026-04-27T03:43:04.810Z"}
75
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":217,"output":1454,"cacheRead":18288,"cacheWrite":0,"total":19959},"timing":{"ttftMs":2707,"totalMs":20584,"generationMs":17193,"stallMs":0,"stallCount":0,"messageCount":1},"tps":84.6,"timestamp":1777261405394,"cost":{"input":0.0001519,"output":0.0046528,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0048047}},"id":"832a0040","parentId":"4555f67d","timestamp":"2026-04-27T03:43:25.394Z"}
76
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":5303.8,"cost_usd":0.007366,"sse_energy_raw":{"energy_joules":5303.8,"energy_kwh":0.0014732777777777778,"avg_power_watts":2771.7,"duration_seconds":1.91,"attribution_method":"counter_exact_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":75768.57142857142,"uncapped_energy_kwh":0.021046825396825394,"carbon_g_co2eq":0.0677708,"grid_carbon_intensity_gco2perkwhr":46,"grid_id":"FI","carbon_source":"agent_cache","mcr":{"compaction_triggered":false,"inference_energy_joules":5303.8,"compaction_energy_joules":0,"session_turns":4,"context_tokens":13603,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":13483,"all_chunks_cached":false,"mcr_compacted_tokens":0,"mcr_original_tokens":13414,"session_fp":"sample_fp_abc123","apc_hit_tokens":9645,"apc_miss_tokens":3958,"apc_hit_rate":0.709,"current_turn_new_tokens":2700}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":5,"safe_drop_before":0,"apc_hit_tokens":9645,"apc_miss_tokens":3958,"apc_hit_rate":0.709,"current_turn_new_tokens":2700},"sse_cost_raw":{"request_cost_usd":0.007366,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"562066b0","parentId":"832a0040","timestamp":"2026-04-27T03:43:25.394Z"}
77
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":255,"output":1074,"cacheRead":18496,"cacheWrite":0,"total":19825},"timing":{"ttftMs":1014,"totalMs":13619,"generationMs":12566,"stallMs":1272,"stallCount":1,"messageCount":1},"tps":85.5,"timestamp":1777261419013,"cost":{"input":0.0001785,"output":0.0034368,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0036153}},"id":"47eebf1f","parentId":"562066b0","timestamp":"2026-04-27T03:43:39.013Z"}
78
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":3165.7,"cost_usd":0.004397,"sse_energy_raw":{"energy_joules":3165.7,"energy_kwh":0.000879361111111111,"avg_power_watts":2786.3,"duration_seconds":1.14,"attribution_method":"counter_exact_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":45224.28571428571,"uncapped_energy_kwh":0.012562301587301586,"carbon_g_co2eq":0.0404506,"grid_carbon_intensity_gco2perkwhr":46,"grid_id":"FI","carbon_source":"agent_cache","mcr":{"compaction_triggered":true,"inference_energy_joules":3165.7,"compaction_energy_joules":45.0,"session_turns":5,"context_tokens":17990,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":17879,"all_chunks_cached":true,"mcr_compacted_tokens":0,"mcr_original_tokens":17842,"session_fp":"sample_fp_abc123","apc_hit_tokens":14680,"apc_miss_tokens":3310,"apc_hit_rate":0.816,"current_turn_new_tokens":3100}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":6,"safe_drop_before":0,"apc_hit_tokens":14680,"apc_miss_tokens":3310,"apc_hit_rate":0.816,"current_turn_new_tokens":3100},"sse_cost_raw":{"request_cost_usd":0.004397,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"6ae0de8b","parentId":"47eebf1f","timestamp":"2026-04-27T03:43:39.013Z"}
79
+ {"type":"custom","customType":"tps","data":{"model":{"provider":"neuralwatt","modelId":"moonshotai/Kimi-K2.6"},"tokens":{"input":56,"output":1282,"cacheRead":18736,"cacheWrite":0,"total":20074},"timing":{"ttftMs":1025,"totalMs":19602,"generationMs":18543,"stallMs":1975,"stallCount":3,"messageCount":1},"tps":69.1,"timestamp":1777261438615,"cost":{"input":3.92e-05,"output":0.0041024,"cacheRead":0.0,"cacheWrite":0.0,"total":0.0041416}},"id":"68bec416","parentId":"6ae0de8b","timestamp":"2026-04-27T03:43:58.615Z"}
80
+ {"type":"custom","customType":"neuralwatt-energy","data":{"energy_joules":6108.9,"cost_usd":0.008485,"sse_energy_raw":{"energy_joules":6108.9,"energy_kwh":0.0016969166666666667,"avg_power_watts":1254.6,"duration_seconds":4.87,"attribution_method":"counter_exact_multi_gpu_8","attribution_ratio":0.07,"ratio_was_capped":true,"energy_max_ratio":0.07,"uncapped_attribution_ratio":1,"uncapped_energy_joules":87269.99999999999,"uncapped_energy_kwh":0.02424166666666666,"carbon_g_co2eq":0.0780582,"grid_carbon_intensity_gco2perkwhr":46,"grid_id":"FI","carbon_source":"agent_cache","mcr":{"compaction_triggered":false,"inference_energy_joules":6108.9,"compaction_energy_joules":0,"session_turns":6,"context_tokens":21622,"mode":"virtual_context","summaries_used":0,"sync_compaction_ran":false,"chunks_pending_compaction":0,"original_tokens":21454,"all_chunks_cached":true,"mcr_compacted_tokens":0,"mcr_original_tokens":21507,"session_fp":"sample_fp_abc123","apc_hit_tokens":21622,"apc_miss_tokens":0,"apc_hit_rate":1.0,"current_turn_new_tokens":3500}},"sse_mcr_session_raw":{"session_fp":"sample_fp_abc123","stored_through":7,"safe_drop_before":0,"apc_hit_tokens":21622,"apc_miss_tokens":0,"apc_hit_rate":1.0,"current_turn_new_tokens":3500},"sse_cost_raw":{"request_cost_usd":0.008485,"cache_savings_usd":0,"allowance_remaining_usd":79.62,"budget_remaining_usd":79.62}},"id":"0f0e6f84","parentId":"68bec416","timestamp":"2026-04-27T03:43:58.615Z"}
@@ -0,0 +1,335 @@
1
+ /**
2
+ * pi-tps-web — Web Telemetry Inspector for pi
3
+ *
4
+ * Registers /tps-web command that exports telemetry JSONL
5
+ * (keeping the folder-opening logic from pi-tps's /tps-export),
6
+ * starts a local HTTP server serving the built web inspector,
7
+ * and opens it in the browser.
8
+ *
9
+ * Designed to work alongside pi-tps — both extensions can be loaded
10
+ * simultaneously. pi-tps provides TPS tracking and notifications;
11
+ * pi-tps-web provides the visual web dashboard.
12
+ */
13
+
14
+ import { execFile } from 'child_process';
15
+ import { writeFileSync, mkdirSync, readFileSync, existsSync, statSync } from 'fs';
16
+ import { homedir } from 'os';
17
+ import { join, extname, resolve, sep } from 'path';
18
+ import { createServer } from 'http';
19
+
20
+ import type {
21
+ ExtensionAPI,
22
+ ExtensionCommandContext,
23
+ } from '@earendil-works/pi-coding-agent';
24
+
25
+ const MIME_TYPES: Record<string, string> = {
26
+ '.html': 'text/html; charset=utf-8',
27
+ '.js': 'application/javascript',
28
+ '.mjs': 'application/javascript',
29
+ '.css': 'text/css; charset=utf-8',
30
+ '.json': 'application/json',
31
+ '.svg': 'image/svg+xml',
32
+ '.png': 'image/png',
33
+ '.jpg': 'image/jpeg',
34
+ '.jpeg': 'image/jpeg',
35
+ '.ico': 'image/x-icon',
36
+ '.wasm': 'application/wasm',
37
+ '.woff': 'font/woff',
38
+ '.woff2': 'font/woff2',
39
+ '.map': 'application/json',
40
+ };
41
+
42
+ const DEFAULT_PORT = 3141;
43
+
44
+ // Resolve the dist/ directory relative to this extension file.
45
+ // jiti always provides __dirname — works for npm install, git install,
46
+ // pi -e, .pi/extensions, and global extensions.
47
+ const PKG_ROOT = join(__dirname, '..', '..');
48
+ const DIST_PATH = join(PKG_ROOT, 'dist');
49
+
50
+ /**
51
+ * Ensure the built web app exists. For npm installs, dist/ is shipped
52
+ * in the tarball. For git installs (where dist/ is .gitignored and
53
+ * pi runs npm install --omit=dev), we attempt a full install + build.
54
+ * The build persists in the git clone directory so this only runs once.
55
+ *
56
+ * Returns true if dist/ is available (pre-built or after auto-build).
57
+ */
58
+ async function ensureDist(): Promise<boolean> {
59
+ if (existsSync(join(DIST_PATH, 'index.html'))) return true;
60
+
61
+ // Auto-build: need dev deps (vite, typescript, etc.) which
62
+ // --omit=dev skips. Full install + build in the package root.
63
+ const run = (cmd: string, args: string[]): Promise<void> =>
64
+ new Promise((res, rej) => {
65
+ execFile(cmd, args, { cwd: PKG_ROOT, timeout: 180_000 }, (err) =>
66
+ err ? rej(err) : res(),
67
+ );
68
+ });
69
+
70
+ try {
71
+ await run('npm', ['install']);
72
+ await run('npx', ['vite', 'build']);
73
+ } catch {
74
+ return false;
75
+ }
76
+
77
+ return existsSync(join(DIST_PATH, 'index.html'));
78
+ }
79
+
80
+ function isPathSafe(requestPath: string, root: string): boolean {
81
+ const resolved = resolve(root, requestPath);
82
+ return resolved.startsWith(root + sep) || resolved === root;
83
+ }
84
+
85
+ function serveStatic(
86
+ root: string,
87
+ req: import('http').IncomingMessage,
88
+ res: import('http').ServerResponse,
89
+ ): void {
90
+ const urlPath = req.url?.split('?')[0] || '/';
91
+ // Strip leading slash so resolve() treats this as relative to root,
92
+ // not as an absolute path that replaces the base.
93
+ const relativePath = urlPath === '/' ? 'index.html' : urlPath.replace(/^\/+/, '');
94
+
95
+ if (!isPathSafe(relativePath, root)) {
96
+ res.writeHead(403);
97
+ res.end('Forbidden');
98
+ return;
99
+ }
100
+
101
+ const filePath = join(root, relativePath);
102
+
103
+ // SPA fallback: if file doesn't exist or is a directory, serve index.html
104
+ if (!existsSync(filePath) || statSync(filePath).isDirectory()) {
105
+ const fallback = join(root, 'index.html');
106
+ if (existsSync(fallback)) {
107
+ const content = readFileSync(fallback);
108
+ res.writeHead(200, {
109
+ 'Content-Type': MIME_TYPES['.html'],
110
+ 'Cache-Control': 'no-cache',
111
+ });
112
+ res.end(content);
113
+ return;
114
+ }
115
+ res.writeHead(404);
116
+ res.end('Not found');
117
+ return;
118
+ }
119
+
120
+ const ext = extname(filePath);
121
+ const contentType = MIME_TYPES[ext] || 'application/octet-stream';
122
+
123
+ try {
124
+ const content = readFileSync(filePath);
125
+ res.writeHead(200, {
126
+ 'Content-Type': contentType,
127
+ 'Cache-Control': 'no-cache',
128
+ });
129
+ res.end(content);
130
+ } catch {
131
+ res.writeHead(500);
132
+ res.end('Internal server error');
133
+ }
134
+ }
135
+
136
+ export default function tpsWebExtension(pi: ExtensionAPI) {
137
+ let server: ReturnType<typeof createServer> | null = null;
138
+ let serverPort = DEFAULT_PORT;
139
+
140
+ // In-memory telemetry data served via the API endpoint.
141
+ // Updated on each /tps-web invocation.
142
+ let telemetryJsonl: string | null = null;
143
+ let telemetryVersion = 0;
144
+
145
+ function startServer(): Promise<number> {
146
+ if (server) return Promise.resolve(serverPort);
147
+
148
+ return new Promise((resolve, reject) => {
149
+ const s = createServer((req, res) => {
150
+ const urlPath = req.url?.split('?')[0] || '/';
151
+
152
+ // API: return the current telemetry data as JSONL
153
+ if (urlPath === '/api/telemetry') {
154
+ const data = telemetryJsonl || '';
155
+ res.writeHead(200, {
156
+ 'Content-Type': 'text/plain; charset=utf-8',
157
+ 'Cache-Control': 'no-store',
158
+ 'Access-Control-Allow-Origin': '*',
159
+ });
160
+ res.end(data);
161
+ return;
162
+ }
163
+
164
+ // API: version counter for polling (web app checks this to detect data changes)
165
+ if (urlPath === '/api/version') {
166
+ res.writeHead(200, {
167
+ 'Content-Type': 'application/json',
168
+ 'Cache-Control': 'no-store',
169
+ });
170
+ res.end(JSON.stringify({ version: telemetryVersion }));
171
+ return;
172
+ }
173
+
174
+ // Static files from dist/
175
+ serveStatic(DIST_PATH, req, res);
176
+ });
177
+
178
+ s.listen(serverPort, () => {
179
+ server = s;
180
+ resolve(serverPort);
181
+ });
182
+
183
+ s.on('error', (err: NodeJS.ErrnoException) => {
184
+ if (err.code === 'EADDRINUSE') {
185
+ // Port taken — try next one
186
+ serverPort++;
187
+ startServer().then(resolve, reject);
188
+ } else {
189
+ reject(err);
190
+ }
191
+ });
192
+ });
193
+ }
194
+
195
+ // Clean up server on session shutdown
196
+ pi.on('session_shutdown', () => {
197
+ if (server) {
198
+ server.close();
199
+ server = null;
200
+ }
201
+ });
202
+
203
+ /**
204
+ * Open a URL or path with the system's default handler.
205
+ * Non-blocking — uses execFile instead of execSync.
206
+ */
207
+ function openInSystem(target: string): void {
208
+ const [cmd, args] =
209
+ process.platform === 'darwin'
210
+ ? ['open', [target]]
211
+ : ['xdg-open', [target]];
212
+ execFile(cmd, args, (err) => {
213
+ if (err) {
214
+ // opener not available — ignore silently
215
+ }
216
+ });
217
+ }
218
+
219
+ pi.registerCommand('tps-web', {
220
+ description:
221
+ 'Export telemetry and view in the pi-tps web inspector (--full for all branches)',
222
+ getArgumentCompletions: (argumentPrefix: string) => {
223
+ if ('--full'.startsWith(argumentPrefix)) {
224
+ return [{ value: '--full', label: '--full (all branches, not just current)' }];
225
+ }
226
+ return [];
227
+ },
228
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
229
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
230
+ const full = tokens.includes('--full');
231
+
232
+ // Snapshot the session data synchronously — this is fast (returns
233
+ // references to in-memory objects). All heavy processing (filtering,
234
+ // re-chaining, serializing, file I/O) is deferred to the background
235
+ // so the handler returns immediately and the TUI stays responsive.
236
+ const entries = full ? ctx.sessionManager.getEntries() : ctx.sessionManager.getBranch();
237
+ const notify = ctx.ui.notify.bind(ctx.ui);
238
+
239
+ if (entries.length === 0) {
240
+ const scope = full ? 'all-entries' : 'current-branch';
241
+ ctx.ui.notify(`No entries found in ${scope}`, 'warning');
242
+ return;
243
+ }
244
+
245
+ // Everything below is fire-and-forget — the handler returns now.
246
+ (async () => {
247
+ const isStructural = (e: { type: string }) =>
248
+ e.type === 'model_change' || e.type === 'branch_summary';
249
+
250
+ const exportedEntries = entries.filter(
251
+ (e: { type: string }) => isStructural(e) || e.type === 'custom',
252
+ );
253
+
254
+ if (exportedEntries.length === 0) {
255
+ const scope = full ? 'all-entries' : 'current-branch';
256
+ notify(`No matching entries found in ${scope}`, 'warning');
257
+ return;
258
+ }
259
+
260
+ // Re-chain parentIds so the exported entries form a valid tree
261
+ const byId = new Map(entries.map((e: { id: string }) => [e.id, e]));
262
+ const exportedIds = new Set(exportedEntries.map((e: { id: string }) => e.id));
263
+
264
+ const rechainParentId = (entry: { parentId: string | null }): string | null => {
265
+ let current: string | null = entry.parentId;
266
+ while (current) {
267
+ if (exportedIds.has(current)) return current;
268
+ const parent = byId.get(current) as { parentId?: string | null } | undefined;
269
+ current = parent?.parentId ?? null;
270
+ }
271
+ return null;
272
+ };
273
+
274
+ const rechained = exportedEntries.map((e: { parentId: string | null }) => ({
275
+ ...e,
276
+ parentId: rechainParentId(e),
277
+ }));
278
+
279
+ const content = rechained.map((e: object) => JSON.stringify(e)).join('\n') + '\n';
280
+
281
+ // Write JSONL file — keeping the folder opening logic from pi-tps
282
+ const cacheBase = process.env.XDG_CACHE_HOME || join(homedir(), '.cache');
283
+ const dir = join(cacheBase, 'pi-telemetry');
284
+ mkdirSync(dir, { recursive: true });
285
+
286
+ const sessionId = ctx.sessionManager.getSessionId?.() ?? 'unknown';
287
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
288
+ const scope = full ? 'full' : 'branch';
289
+ const filename = `pi-telemetry-${scope}-${sessionId.slice(0, 8)}-${timestamp}.jsonl`;
290
+ const filepath = join(dir, filename);
291
+ writeFileSync(filepath, content);
292
+
293
+ // Open the folder containing the exported JSONL
294
+ openInSystem(dir);
295
+
296
+ // Update in-memory data for the API endpoint
297
+ telemetryJsonl = content;
298
+ telemetryVersion++;
299
+
300
+ const structuralCount = exportedEntries.filter((e: { type: string }) => isStructural(e)).length;
301
+ const customCount = exportedEntries.length - structuralCount;
302
+ const parts: string[] = [];
303
+ if (customCount > 0) parts.push(`${customCount} telemetry`);
304
+ if (structuralCount > 0) parts.push(`${structuralCount} structural`);
305
+ const summary = parts.length > 0 ? parts.join(' + ') : `${exportedEntries.length} entries`;
306
+
307
+ notify(`Exporting ${summary} + starting web inspector…`, 'info');
308
+
309
+ // Build (if needed), start server, open browser
310
+ if (!(await ensureDist())) {
311
+ notify(
312
+ `Web inspector not available: dist/ not built.\n` +
313
+ `Run in the pi-tps-web package directory:\n` +
314
+ ` npm install && npm run build\n` +
315
+ `Then /reload and try again.`,
316
+ 'warning',
317
+ );
318
+ return;
319
+ }
320
+
321
+ try {
322
+ if (!server) {
323
+ serverPort = DEFAULT_PORT;
324
+ }
325
+ const port = await startServer();
326
+ const url = `http://localhost:${port}?auto=1&v=${telemetryVersion}`;
327
+ openInSystem(url);
328
+ notify(`Exported ${summary} → ${filepath}\nWeb inspector: http://localhost:${port}`, 'info');
329
+ } catch (err) {
330
+ notify(`Failed to start web server: ${err}`, 'error');
331
+ }
332
+ })();
333
+ },
334
+ });
335
+ }