@kabmo-labs/kabmo 0.33.0 → 0.34.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +785 -624
- package/dist/client/static/js/{CsvGrid-fncjbg6j.js → CsvGrid-vze4m5ag.js} +1 -1
- package/dist/client/static/js/{DocxView-c9v2vr3r.js → DocxView-jbf21gmh.js} +5 -5
- package/dist/client/static/js/{DrawioView-vxjksm12.js → DrawioView-b52qybx5.js} +2 -2
- package/dist/client/static/js/{ImageView-a3g5k226.js → ImageView-mdgzj8px.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-hnjfwsjh.js → LayoutWrapper-3c49dvtt.js} +2 -2
- package/dist/client/static/js/Modal-sqp864vd.js +38 -0
- package/dist/client/static/js/{PdfView-ksaes53y.js → PdfView-g06rxqb1.js} +1 -1
- package/dist/client/static/js/{SessionsView-30vcr95v.js → SessionsView-521adxyr.js} +1 -1
- package/dist/client/static/js/{SheetView-vc484scg.js → SheetView-h8xmsz7q.js} +22 -22
- package/dist/client/static/js/{SvgPreview-tph89jet.js → SvgPreview-1j4jvcvz.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-xbar278c.js → abnfDiagram-O67JEVCF-pasxh4b6.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-fc9kmq1w.js +1 -0
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-s171n2z6.js → architectureDiagram-NJMV4G6O-ms14g0bm.js} +4 -4
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-gzx6rv9n.js → blockDiagram-BEXU5L5S-ycn78fcq.js} +4 -4
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-7f00skch.js → c4Diagram-YGBWAQC7-vn2gpjfm.js} +5 -5
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-j79v95nc.js → classDiagram-v2-NBCMYWYE-fyrm1pr5.js} +4 -4
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-5fkn7ee5.js → cose-bilkent-JH36ORCC-ea5nwvgq.js} +1 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-a4t8992q.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-cfs1yvrd.js → cynefinDiagram-VND7K2PF-j6bsjpre.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-44bgc48p.js → dagre-6A5THRUB-4smdkwv8.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-a4g4x83k.js → diagram-22UHCM2B-9sm4kqwc.js} +11 -11
- package/dist/client/static/js/{diagram-3UASUU5V-gm4rg5na.js → diagram-3UASUU5V-2h3qxaed.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-a95y41vk.js → diagram-ATOU4E4O-1981bc94.js} +3 -3
- package/dist/client/static/js/{diagram-CDSNMT55-t3j93mmc.js → diagram-CDSNMT55-3vgsxavc.js} +4 -4
- package/dist/client/static/js/{diagram-MLGK6HIB-c2wdez02.js → diagram-MLGK6HIB-c9gf2r3f.js} +2 -2
- package/dist/client/static/js/{diagram-MPIPVDR6-gya9jhs5.js → diagram-MPIPVDR6-gjqeq92d.js} +2 -2
- package/dist/client/static/js/{dockerfile-a7q6174s.js → dockerfile-8v935dkn.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-jjhkza6t.js → ebnfDiagram-ZINNZB2B-4vbsgh99.js} +1 -1
- package/dist/client/static/js/{elixir-rpa1g4gy.js → elixir-vcbg60wv.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-f7re45mw.js → elk-276RUBZZ-nca3t891.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-tpm9g5te.js → erDiagram-OPXOYQCR-5kfkev03.js} +2 -2
- package/dist/client/static/js/eventmodeling-NTZA5JFV-18bdrkv5.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-fg0yqx0h.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-fz43n12d.js → ganttDiagram-FUAMR5RP-mxc73wmq.js} +3 -3
- package/dist/client/static/js/gitGraph-4MIJSDKK-8fa6y40p.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-f61hgbn6.js → gitGraphDiagram-X574FWY7-7en3ag0e.js} +12 -12
- package/dist/client/static/js/html-dbrwss36.js +1 -0
- package/dist/client/static/js/{index-m73za75e.js → index-0vm41je9.js} +3 -3
- package/dist/client/static/js/{index-eyzeya95.js → index-1b0t1428.js} +5 -5
- package/dist/client/static/js/{index-2x5f66t6.js → index-1ksg88qf.js} +1 -1
- package/dist/client/static/js/{index-sffjtm5w.js → index-231241f4.js} +9 -9
- package/dist/client/static/js/index-2mx9ej4k.css +1 -0
- package/dist/client/static/js/{index-8239j2v1.js → index-4g46wbdw.js} +1 -1
- package/dist/client/static/js/{index-1xqs14fr.js → index-4qwzxj81.js} +1 -1
- package/dist/client/static/js/{index-gcs49f3p.js → index-52rqxgya.js} +1 -1
- package/dist/client/static/js/{index-at6bhjyf.js → index-6sf2vsp2.js} +1 -1
- package/dist/client/static/js/{index-q2w6s8n7.js → index-7a64yjrm.js} +4 -4
- package/dist/client/static/js/{index-rg8jpbsw.js → index-8acv5b77.js} +2 -2
- package/dist/client/static/js/{index-js7t1vb1.js → index-a0fmsv1d.js} +5 -5
- package/dist/client/static/js/{index-w0fwb80e.js → index-ag2rmtas.js} +1 -1
- package/dist/client/static/js/{index-djmg1d7h.js → index-b29afsjh.js} +1 -1
- package/dist/client/static/js/{index-e4p4cd3r.js → index-c3ek61zv.js} +1 -1
- package/dist/client/static/js/{index-0e40xskg.js → index-cd65zqba.js} +1 -1
- package/dist/client/static/js/{index-zt75xpq0.js → index-cgzrpvzj.js} +204 -204
- package/dist/client/static/js/{index-0n5wwe60.js → index-ev3yt353.js} +2 -2
- package/dist/client/static/js/{index-9y3gjdj7.js → index-eyfcm0cy.js} +1 -1
- package/dist/client/static/js/{index-qsm2z36d.js → index-f7jhhqtk.js} +1 -1
- package/dist/client/static/js/{index-vw5k8csz.js → index-fta1y9pc.js} +50 -50
- package/dist/client/static/js/{index-ajs3jj6j.js → index-fvmfge3p.js} +1 -1
- package/dist/client/static/js/{index-pxv2nw9w.js → index-g2dyfze9.js} +1 -1
- package/dist/client/static/js/{index-bkye8mz4.js → index-h5bn97p6.js} +1 -1
- package/dist/client/static/js/{index-trm9x02n.js → index-j51d5a5m.js} +6 -6
- package/dist/client/static/js/{index-pbe4yed4.js → index-jsyekbx9.js} +2 -2
- package/dist/client/static/js/{index-gs6f0qwa.js → index-nccwxv0s.js} +2 -2
- package/dist/client/static/js/{index-d495kfm0.js → index-p0nz38bm.js} +1 -1
- package/dist/client/static/js/{index-sdtye3jy.js → index-pm6xxwz1.js} +2 -2
- package/dist/client/static/js/{index-3rcjx70v.js → index-ptcrwswj.js} +1 -1
- package/dist/client/static/js/{index-14vndmcr.js → index-ptcwae2n.js} +1 -1
- package/dist/client/static/js/{index-5tgq7aqx.js → index-r014brzs.js} +2 -2
- package/dist/client/static/js/{index-xj9649ac.js → index-ray2czf6.js} +7 -7
- package/dist/client/static/js/{index-apvkd37e.js → index-rs80cwsv.js} +3 -3
- package/dist/client/static/js/{index-vw4brsdx.js → index-rzxcj7cg.js} +1 -1
- package/dist/client/static/js/{index-a293pdg7.js → index-s7gkkkyz.js} +2 -2
- package/dist/client/static/js/{index-1a0zkj8h.js → index-sd66wv26.js} +2 -2
- package/dist/client/static/js/{index-ypx3qmhq.js → index-vhqe0y82.js} +1 -1
- package/dist/client/static/js/{index-9fjt5anh.js → index-vy6termr.js} +1 -1
- package/dist/client/static/js/{index-0tf0arsp.js → index-xx6mqpxm.js} +3 -3
- package/dist/client/static/js/{index-03h3bkcf.js → index-ybm2x4vh.js} +1 -1
- package/dist/client/static/js/info-A6RAGUB7-3hk844f7.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-1qj804sn.js → infoDiagram-VRGFBTTK-sef80132.js} +2 -2
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-4j4qsnzw.js → ishikawaDiagram-OU5B5YK6-yhvepp1q.js} +6 -6
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-j0brnfft.js → journeyDiagram-ZHPQQLJL-5w77y95w.js} +5 -5
- package/dist/client/static/js/{julia-4ghmfy3e.js → julia-d4j6wgvf.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-qqc22br0.js → kanban-definition-PNTS6WVX-02znqtna.js} +6 -6
- package/dist/client/static/js/{mermaid.core-vv3wbe65.js → mermaid.core-a6e6vck4.js} +5 -5
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-y5b2z8zp.js → mindmap-definition-NLK3R4M7-y4n74q9x.js} +8 -8
- package/dist/client/static/js/one-dark-pro-vwhfpzr8.js +1 -0
- package/dist/client/static/js/one-light-y5t9x6zh.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-4nj2yy10.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-0be07mqs.js → pegDiagram-GJSIUBJH-pr7ehgzb.js} +1 -1
- package/dist/client/static/js/{perl-sd00t4b4.js → perl-srptw5vm.js} +1 -1
- package/dist/client/static/js/{php-2zfyqa61.js → php-n89g3fk7.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-k7rde3f9.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-544w86jk.js → pieDiagram-5QR66LMP-39wpsk08.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-p09e7z5s.js → quadrantDiagram-O4NWA36T-esm913km.js} +5 -5
- package/dist/client/static/js/radar-RG4KPBEZ-513dpw4f.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-9bqnst9c.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-7367d5bv.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-b806b1mj.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-5a67rwf8.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-de830ed2.js → railroadDiagram-XR7U4H2S-wy2mgya6.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b47d74p1.js → requirementDiagram-PLB6GJNP-6z9xdgbq.js} +2 -2
- package/dist/client/static/js/{ruby-v9qaqhby.js → ruby-r81ytgcm.js} +1 -1
- package/dist/client/static/js/{rust-fkt0qyrs.js → rust-frn3szvc.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-6ezc2fpj.js → sankeyDiagram-IPEJSGJF-rtmxk3ys.js} +4 -4
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-by5zqj6w.js → sequenceDiagram-PO4LG4MO-awzcrafg.js} +18 -18
- package/dist/client/static/js/{sizeCapture-INFHLROL-q85r06j6.js → sizeCapture-INFHLROL-03gy196j.js} +1 -1
- package/dist/client/static/js/sql-0e9mnrda.js +1 -0
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-ep5pyexs.js → stateDiagram-v2-GCMORJYK-an8v3q5n.js} +3 -3
- package/dist/client/static/js/{swimlanes-2SLR337P-95fcqkh8.js → swimlanes-2SLR337P-n9yb4wcs.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-xs2en5dv.js → swimlanesDiagram-TC7HE7FX-nx5nfnf0.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-461e615g.js → timeline-definition-EJHVYXUP-jceb575g.js} +4 -4
- package/dist/client/static/js/treeView-Q6P3EWNA-kcy40evb.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-fsrvqxf4.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ftqfnvhg.js → usecaseDiagram-POWQR4AR-888h3100.js} +13 -13
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-7t96h6ez.js → vennDiagram-UO4OBE2U-wbfz0rzv.js} +7 -7
- package/dist/client/static/js/{vue-j8vb9d7r.js → vue-c0rtg1wf.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-36dmxww4.js +1 -0
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-0de8w8c6.js → wardleyDiagram-VNRHLVJA-rn8c5qf9.js} +4 -4
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-dez9phkf.js → xychartDiagram-PMCCYNJV-8sn1apt6.js} +5 -5
- package/package.json +4 -1
- package/src/client/components/auth/login-screen/index.tsx +1 -0
- package/src/client/components/common/MarkdownRenderer.tsx +9 -12
- package/src/client/components/settings/Modal.tsx +14 -84
- package/src/client/components/settings/Sidebar.tsx +3 -1
- package/src/client/components/settings/categories/ConnectSettings.tsx +105 -0
- package/src/client/components/settings/categories/connect-settings/DeviceTable.tsx +145 -0
- package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +160 -0
- package/src/client/components/settings/categories/connect-settings/QrCode.tsx +73 -0
- package/src/client/components/settings/categories/connect-settings/ServerCard.tsx +94 -0
- package/src/client/components/settings/categories/connect-settings/TunnelRow.tsx +127 -0
- package/src/client/components/settings/category-content.tsx +116 -0
- package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.test.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.tsx +56 -20
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +1 -0
- package/src/client/hooks/chat/timeline/change-stats.ts +57 -0
- package/src/client/hooks/connect/use-connect-status.ts +116 -0
- package/src/client/hooks/connect/use-pairing.ts +100 -0
- package/src/client/hooks/ui/clipboard.ts +26 -0
- package/src/client/tailwind.css +5 -0
- package/src/server/index.ts +2 -0
- package/src/server/lib/assets/font-css.server.test.ts +19 -0
- package/src/server/lib/auth/client-address.test.ts +58 -0
- package/src/server/lib/auth/client-address.ts +37 -3
- package/src/server/lib/auth/guard.ts +31 -4
- package/src/server/lib/auth/rate-limit.test.ts +25 -8
- package/src/server/lib/auth/rate-limit.ts +8 -5
- package/src/server/lib/connect/cloudflared.lifecycle.test.ts +88 -0
- package/src/server/lib/connect/cloudflared.server.test.ts +65 -0
- package/src/server/lib/connect/cloudflared.server.ts +206 -0
- package/src/server/lib/connect/devices.server.ts +192 -0
- package/src/server/lib/connect/identity.server.ts +81 -0
- package/src/server/lib/connect/pairing.server.test.ts +56 -0
- package/src/server/lib/connect/pairing.server.ts +113 -0
- package/src/server/lib/connect/qr.roundtrip.test.ts +106 -0
- package/src/server/lib/connect/qr.server.ts +36 -0
- package/src/server/lib/connect/run.server.ts +101 -0
- package/src/server/lib/connect/status.server.ts +177 -0
- package/src/server/lib/connect/tailscale.server.test.ts +117 -0
- package/src/server/lib/connect/tailscale.server.ts +172 -0
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/omp/session/changes.test.ts +64 -1
- package/src/server/lib/omp/session/changes.ts +94 -1
- package/src/server/routes/connect/devices.ts +56 -0
- package/src/server/routes/connect/index.ts +15 -0
- package/src/server/routes/connect/pair-page.ts +177 -0
- package/src/server/routes/connect/pair.ts +158 -0
- package/src/server/routes/connect/status.ts +19 -0
- package/src/server/routes/connect/tunnels.ts +76 -0
- package/src/server/routes/health/probe.ts +5 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/sessions/changes.test.ts +12 -3
- package/src/server/routes/sessions/changes.ts +27 -3
- package/src/server/routes/sessions/index.ts +2 -1
- package/src/shared/lib/connect/payload.test.ts +144 -0
- package/src/shared/lib/connect/payload.ts +229 -0
- package/src/shared/lib/connect/tier.test.ts +73 -0
- package/src/shared/lib/connect/tier.ts +105 -0
- package/src/shared/lib/connect/types.ts +99 -0
- package/src/shared/lib/markdown/fira-code-fonts.css +65 -6
- package/src/shared/lib/markdown/marked.ts +7 -4
- package/src/shared/lib/markdown/mermaid-actions.test.ts +78 -0
- package/src/shared/lib/markdown/mermaid-actions.ts +45 -0
- package/src/shared/lib/markdown/mermaid.ts +41 -7
- package/src/shared/lib/settings/sections.ts +6 -1
- package/src/shared/types/session-changes.ts +6 -0
- package/src/shared/types/settings/state.ts +2 -0
- package/dist/client/static/js/Modal-qtftcp2t.js +0 -38
- package/dist/client/static/js/architecture-7GRP2DOG-tavtgb8a.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-cdh3n2z2.js +0 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-as97tpyp.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-ggm06d12.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-eqz7p9ng.js +0 -1
- package/dist/client/static/js/html-pv88ny12.js +0 -1
- package/dist/client/static/js/index-e94a1en0.css +0 -1
- package/dist/client/static/js/info-A6RAGUB7-4pkzh1qx.js +0 -1
- package/dist/client/static/js/one-dark-pro-hm3f56n1.js +0 -1
- package/dist/client/static/js/one-light-xrz49rct.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-yg71sp88.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-89wd6np0.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-avn0b8r9.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-de27xv5w.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-rg4zzj7x.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-d84fhj8v.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-dvf8xrmc.js +0 -1
- package/dist/client/static/js/sql-g8wcshpc.js +0 -1
- package/dist/client/static/js/treeView-Q6P3EWNA-mham0bh6.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-mxrxax86.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-8vrvh9p3.js +0 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pairing payload a QR code carries, and the parser that refuses a bad one.
|
|
8
|
+
*
|
|
9
|
+
* The payload is a deep link rather than a bare JSON blob so a desktop shell can
|
|
10
|
+
* accept it as a pasted link, and so the OS can route it to the app. The secret
|
|
11
|
+
* lives inside the encoded body, never in a query parameter of its own: a
|
|
12
|
+
* fragment or an opaque `p=` is not logged by proxies the way a named parameter
|
|
13
|
+
* is, and the whole point of the secret is that it is single-use and short-lived.
|
|
14
|
+
*
|
|
15
|
+
* Versioned from the first release. A payload that grows a field later must not
|
|
16
|
+
* be readable by an older shell as if the field were absent — `v` is what makes
|
|
17
|
+
* that a refusal instead of a silent downgrade.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { ConnectCandidate, ConnectRouteKind } from '@/shared/lib/connect/types';
|
|
21
|
+
|
|
22
|
+
/** The scheme the shells register and the desktop shells accept as a paste. */
|
|
23
|
+
export const PAIRING_SCHEME = 'kabmo';
|
|
24
|
+
export const PAIRING_HOST = 'connect';
|
|
25
|
+
export const PAIRING_VERSION = 1;
|
|
26
|
+
|
|
27
|
+
/** Longest payload accepted, so a hostile QR cannot make the parser allocate. */
|
|
28
|
+
export const MAX_PAIRING_PAYLOAD_LENGTH = 8_192;
|
|
29
|
+
|
|
30
|
+
export interface PairingPayload {
|
|
31
|
+
v: typeof PAIRING_VERSION;
|
|
32
|
+
pairingId: string;
|
|
33
|
+
/** One-time secret. Consumed by the first successful claim. */
|
|
34
|
+
secret: string;
|
|
35
|
+
/** Stable identity of the server, pinned by the device. */
|
|
36
|
+
serverId: string;
|
|
37
|
+
/** The server's display name, so the phone can label it. */
|
|
38
|
+
label: string;
|
|
39
|
+
/** ISO timestamp. A payload past this is refused before any network call. */
|
|
40
|
+
expiresAt: string;
|
|
41
|
+
candidates: ConnectCandidate[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ROUTE_KINDS: readonly ConnectRouteKind[] = ['cloudflare', 'lan', 'tailscale'];
|
|
45
|
+
|
|
46
|
+
function isRouteKind(value: unknown): value is ConnectRouteKind {
|
|
47
|
+
return typeof value === 'string' && (ROUTE_KINDS as readonly string[]).includes(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An origin with no path, no query and no trailing slash, or null. */
|
|
51
|
+
export function normalizeOrigin(value: unknown): string | null {
|
|
52
|
+
if (typeof value !== 'string') return null;
|
|
53
|
+
const trimmed = value.trim();
|
|
54
|
+
if (!trimmed) return null;
|
|
55
|
+
try {
|
|
56
|
+
const parsed = new URL(trimmed);
|
|
57
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
|
|
58
|
+
parsed.hash = '';
|
|
59
|
+
parsed.search = '';
|
|
60
|
+
return parsed.origin;
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function base64UrlEncode(value: string): string {
|
|
67
|
+
const bytes = new TextEncoder().encode(value);
|
|
68
|
+
let binary = '';
|
|
69
|
+
for (let index = 0; index < bytes.length; index += 0x8000) {
|
|
70
|
+
binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
|
71
|
+
}
|
|
72
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function base64UrlDecode(value: string): string | null {
|
|
76
|
+
try {
|
|
77
|
+
const padded = value.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
78
|
+
const binary = atob(padded);
|
|
79
|
+
const bytes = new Uint8Array(binary.length);
|
|
80
|
+
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
|
|
81
|
+
return new TextDecoder().decode(bytes);
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Keep only the fields a candidate is allowed to carry. */
|
|
88
|
+
function normalizeCandidate(value: unknown): ConnectCandidate | null {
|
|
89
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
90
|
+
const record = value as Record<string, unknown>;
|
|
91
|
+
if (!isRouteKind(record.kind)) return null;
|
|
92
|
+
const url = normalizeOrigin(record.url);
|
|
93
|
+
if (!url) return null;
|
|
94
|
+
return { kind: record.kind, url };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A payload from parsed JSON, or null.
|
|
99
|
+
*
|
|
100
|
+
* Every field is checked rather than trusted: this object arrives from a camera
|
|
101
|
+
* and is the input to a request that hands out a credential.
|
|
102
|
+
*/
|
|
103
|
+
export function normalizePairingPayload(value: unknown, now: number = Date.now()): PairingPayload | null {
|
|
104
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
105
|
+
const record = value as Record<string, unknown>;
|
|
106
|
+
if (record.v !== PAIRING_VERSION) return null;
|
|
107
|
+
|
|
108
|
+
const pairingId = typeof record.pairingId === 'string' ? record.pairingId.trim() : '';
|
|
109
|
+
const secret = typeof record.secret === 'string' ? record.secret.trim() : '';
|
|
110
|
+
const serverId = typeof record.serverId === 'string' ? record.serverId.trim() : '';
|
|
111
|
+
const label = typeof record.label === 'string' ? record.label.trim() : '';
|
|
112
|
+
const expiresAt = typeof record.expiresAt === 'string' ? record.expiresAt.trim() : '';
|
|
113
|
+
if (!pairingId || !secret || !serverId || !expiresAt) return null;
|
|
114
|
+
|
|
115
|
+
const expires = Date.parse(expiresAt);
|
|
116
|
+
if (!Number.isFinite(expires) || expires <= now) return null;
|
|
117
|
+
|
|
118
|
+
const candidates = Array.isArray(record.candidates)
|
|
119
|
+
? record.candidates
|
|
120
|
+
.map(normalizeCandidate)
|
|
121
|
+
.filter((candidate): candidate is ConnectCandidate => candidate !== null)
|
|
122
|
+
: [];
|
|
123
|
+
if (candidates.length === 0) return null;
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
v: PAIRING_VERSION,
|
|
127
|
+
pairingId,
|
|
128
|
+
secret,
|
|
129
|
+
serverId,
|
|
130
|
+
label: label || 'Kabmo',
|
|
131
|
+
expiresAt,
|
|
132
|
+
candidates,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The encoded body alone, for a URL fragment.
|
|
138
|
+
*
|
|
139
|
+
* A fragment is never sent to the server, so the one-time secret in it does not
|
|
140
|
+
* reach an access log, a proxy, or a `Referer`. The browser pairing page reads
|
|
141
|
+
* it with `location.hash`; the deep link below carries the same bytes in a query
|
|
142
|
+
* parameter, which is acceptable only because a `kabmo://` URL is handed to an
|
|
143
|
+
* app rather than requested over the network.
|
|
144
|
+
*/
|
|
145
|
+
export function encodePairingFragment(payload: PairingPayload): string {
|
|
146
|
+
const normalized = normalizePairingPayload(payload);
|
|
147
|
+
if (!normalized) throw new Error('Invalid pairing payload');
|
|
148
|
+
return base64UrlEncode(JSON.stringify(normalized));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The deep link a QR encodes for a native shell. */
|
|
152
|
+
export function encodePairingPayload(payload: PairingPayload): string {
|
|
153
|
+
const params = new URLSearchParams();
|
|
154
|
+
params.set('v', String(PAIRING_VERSION));
|
|
155
|
+
params.set('p', encodePairingFragment(payload));
|
|
156
|
+
return `${PAIRING_SCHEME}://${PAIRING_HOST}?${params.toString()}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A payload from a scanned or pasted string, or null.
|
|
161
|
+
*
|
|
162
|
+
* Parsed by hand rather than through `new URL`: an old Android WebView (114)
|
|
163
|
+
* mis-parses a non-special scheme, yielding an empty hostname and a path of
|
|
164
|
+
* `//connect`, which made a valid link look invalid. The head is matched with a
|
|
165
|
+
* regex and the two parameters are read off the query string directly.
|
|
166
|
+
*/
|
|
167
|
+
export function parsePairingPayload(value: string, now: number = Date.now()): PairingPayload | null {
|
|
168
|
+
const trimmed = value.trim();
|
|
169
|
+
if (!trimmed || trimmed.length > MAX_PAIRING_PAYLOAD_LENGTH) return null;
|
|
170
|
+
|
|
171
|
+
const question = trimmed.indexOf('?');
|
|
172
|
+
if (question === -1) return null;
|
|
173
|
+
const head = trimmed.slice(0, question);
|
|
174
|
+
if (!new RegExp(`^${PAIRING_SCHEME}://${PAIRING_HOST}/?$`, 'i').test(head)) return null;
|
|
175
|
+
|
|
176
|
+
let version: string | null = null;
|
|
177
|
+
let encoded: string | null = null;
|
|
178
|
+
for (const part of trimmed.slice(question + 1).split('&')) {
|
|
179
|
+
const equals = part.indexOf('=');
|
|
180
|
+
if (equals === -1) continue;
|
|
181
|
+
const key = part.slice(0, equals);
|
|
182
|
+
const raw = part.slice(equals + 1);
|
|
183
|
+
if (key === 'v') version = raw;
|
|
184
|
+
else if (key === 'p') encoded = raw;
|
|
185
|
+
}
|
|
186
|
+
if (version !== String(PAIRING_VERSION) || !encoded) return null;
|
|
187
|
+
return decodeFragment(encoded, now);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A payload from the fragment of a browser pairing link, or null.
|
|
192
|
+
*
|
|
193
|
+
* The QR encodes `https://<address>/pair#<fragment>`, so a device that decoded
|
|
194
|
+
* the code from a screenshot has this form rather than the deep link. Both are
|
|
195
|
+
* accepted by {@link parsePairingLink}, which is what a scanner should call.
|
|
196
|
+
*/
|
|
197
|
+
export function parsePairingFragment(fragment: string, now: number = Date.now()): PairingPayload | null {
|
|
198
|
+
const trimmed = fragment.trim().replace(/^#/, '');
|
|
199
|
+
if (!trimmed) return null;
|
|
200
|
+
return decodeFragment(trimmed, now);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A payload from either form a QR can hold, or null.
|
|
205
|
+
*
|
|
206
|
+
* One entry point for a scanner: the code may be the browser link (what this
|
|
207
|
+
* server encodes) or the deep link (what a native shell registers), and the
|
|
208
|
+
* caller should not have to know which.
|
|
209
|
+
*/
|
|
210
|
+
export function parsePairingLink(value: string, now: number = Date.now()): PairingPayload | null {
|
|
211
|
+
const trimmed = value.trim();
|
|
212
|
+
if (!trimmed) return null;
|
|
213
|
+
if (trimmed.toLowerCase().startsWith(`${PAIRING_SCHEME}://`)) return parsePairingPayload(trimmed, now);
|
|
214
|
+
const hash = trimmed.indexOf('#');
|
|
215
|
+
if (hash === -1) return null;
|
|
216
|
+
return parsePairingFragment(trimmed.slice(hash + 1), now);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Decode one base64url body into a validated payload. */
|
|
220
|
+
function decodeFragment(encoded: string, now: number): PairingPayload | null {
|
|
221
|
+
if (!encoded || encoded.length > MAX_PAIRING_PAYLOAD_LENGTH) return null;
|
|
222
|
+
const decoded = base64UrlDecode(encoded);
|
|
223
|
+
if (!decoded || decoded.length > MAX_PAIRING_PAYLOAD_LENGTH) return null;
|
|
224
|
+
try {
|
|
225
|
+
return normalizePairingPayload(JSON.parse(decoded) as unknown, now);
|
|
226
|
+
} catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The route order, pinned.
|
|
8
|
+
*
|
|
9
|
+
* The case that matters is the one a "fastest wins" rule gets wrong: a LAN
|
|
10
|
+
* address that answers in 2 ms must still lose to Tailscale at 4 ms, because the
|
|
11
|
+
* LAN origin is not a secure context and dictation, clipboard read and the
|
|
12
|
+
* service worker are all absent there. A test that only compared round trips
|
|
13
|
+
* would pass while the product regressed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { pickRoute, shouldSwitch, type ProbedCandidate } from '@/shared/lib/connect/tier';
|
|
18
|
+
|
|
19
|
+
function candidate(kind: ProbedCandidate['kind'], rttMs: number | null): ProbedCandidate {
|
|
20
|
+
return { kind, url: `https://${kind}.example`, rttMs };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('pickRoute', () => {
|
|
24
|
+
test('prefers Tailscale over a faster LAN address', () => {
|
|
25
|
+
const winner = pickRoute([candidate('lan', 2), candidate('tailscale', 4)]);
|
|
26
|
+
expect(winner?.kind).toBe('tailscale');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('falls back to LAN when Tailscale did not answer', () => {
|
|
30
|
+
const winner = pickRoute([candidate('lan', 2), candidate('tailscale', null)]);
|
|
31
|
+
expect(winner?.kind).toBe('lan');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('uses Cloudflare only when nothing better answered', () => {
|
|
35
|
+
const winner = pickRoute([candidate('lan', null), candidate('cloudflare', 40)]);
|
|
36
|
+
expect(winner?.kind).toBe('cloudflare');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('breaks a tie inside one tier by round trip', () => {
|
|
40
|
+
const winner = pickRoute([
|
|
41
|
+
{ kind: 'tailscale', url: 'https://ipv4.example', rttMs: 9 },
|
|
42
|
+
{ kind: 'tailscale', url: 'https://magicdns.example', rttMs: 3 },
|
|
43
|
+
]);
|
|
44
|
+
expect(winner?.url).toBe('https://magicdns.example');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('answers null when nothing answered', () => {
|
|
48
|
+
expect(pickRoute([candidate('lan', null), candidate('tailscale', null)])).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('shouldSwitch', () => {
|
|
53
|
+
test('switches to a better tier even when it is slower', () => {
|
|
54
|
+
expect(shouldSwitch(candidate('lan', 2), candidate('tailscale', 30))).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('never switches down a tier', () => {
|
|
58
|
+
expect(shouldSwitch(candidate('tailscale', 30), candidate('lan', 1))).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('ignores a same-tier win that is too small to feel', () => {
|
|
62
|
+
// 40 ms -> 30 ms is a 25% gain but only 10 ms: a reload costs more than that.
|
|
63
|
+
expect(shouldSwitch(candidate('tailscale', 40), candidate('tailscale', 30))).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('takes a same-tier win that is both large and proportional', () => {
|
|
67
|
+
expect(shouldSwitch(candidate('tailscale', 200), candidate('tailscale', 60))).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('switches when the active route stopped answering', () => {
|
|
71
|
+
expect(shouldSwitch(candidate('tailscale', null), candidate('lan', 5))).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which route a client should use, and why the order is not "fastest wins".
|
|
8
|
+
*
|
|
9
|
+
* The naive rule — pick the lowest round-trip time — is wrong here, and the
|
|
10
|
+
* measurement is what makes it wrong. On a LAN, `http://192.168.x.x` is not a
|
|
11
|
+
* secure context: `crypto.subtle`, `getUserMedia`, `navigator.clipboard.readText`
|
|
12
|
+
* and `serviceWorker` are all absent (measured in Chromium, Pixel 7 profile).
|
|
13
|
+
* Dictation stops working, copy/paste degrades, and the password crosses the
|
|
14
|
+
* Wi-Fi in cleartext. Tailscale on the SAME network is a direct WireGuard peer
|
|
15
|
+
* connection, so its round trip is the LAN's plus a fraction of a millisecond —
|
|
16
|
+
* it costs nothing and it restores all four capabilities.
|
|
17
|
+
*
|
|
18
|
+
* So the order is a TIER, not a score: a lower tier always wins while it is
|
|
19
|
+
* reachable, and the round trip only breaks ties inside a tier (an IPv4 address
|
|
20
|
+
* and a MagicDNS name for the same node).
|
|
21
|
+
*
|
|
22
|
+
* **This module has no TypeScript caller, and that is deliberate.** A page
|
|
23
|
+
* cannot probe another origin — `https` to `http` is mixed content, and
|
|
24
|
+
* `/api/health` carries no CORS headers — so the probe and the switch can only
|
|
25
|
+
* run in a native shell. What lives here is the contract those shells port, with
|
|
26
|
+
* the hysteresis numbers pinned by tests, so the Kotlin and Swift versions have
|
|
27
|
+
* one definition to match instead of three guesses.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import type { ConnectCandidate, ConnectRouteKind } from '@/shared/lib/connect/types';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Preference order. Lower is better.
|
|
34
|
+
*
|
|
35
|
+
* `lan` sits below `tailscale` deliberately: it is the fallback for a device
|
|
36
|
+
* that has no tailnet, not the preferred route at home.
|
|
37
|
+
*/
|
|
38
|
+
export const ROUTE_TIER: Record<ConnectRouteKind, number> = {
|
|
39
|
+
tailscale: 0,
|
|
40
|
+
lan: 1,
|
|
41
|
+
cloudflare: 2,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** A candidate with the measurement the client took of it. */
|
|
45
|
+
export interface ProbedCandidate extends ConnectCandidate {
|
|
46
|
+
/** Round trip to `/api/health`, in milliseconds. Null when unreachable. */
|
|
47
|
+
rttMs: number | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The best reachable candidate, or null when none answered.
|
|
52
|
+
*
|
|
53
|
+
* Ties inside a tier are broken by the round trip, and a candidate with no
|
|
54
|
+
* measurement is treated as unreachable rather than as infinitely fast — a
|
|
55
|
+
* probe that never ran must not win.
|
|
56
|
+
*/
|
|
57
|
+
export function pickRoute(candidates: readonly ProbedCandidate[]): ProbedCandidate | null {
|
|
58
|
+
let best: ProbedCandidate | null = null;
|
|
59
|
+
for (const candidate of candidates) {
|
|
60
|
+
if (candidate.rttMs === null) continue;
|
|
61
|
+
if (!best) {
|
|
62
|
+
best = candidate;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const tier = ROUTE_TIER[candidate.kind];
|
|
66
|
+
const bestTier = ROUTE_TIER[best.kind];
|
|
67
|
+
if (tier < bestTier) {
|
|
68
|
+
best = candidate;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (tier === bestTier && candidate.rttMs < (best.rttMs ?? Number.POSITIVE_INFINITY)) {
|
|
72
|
+
best = candidate;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return best;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether a newly measured winner is worth switching to.
|
|
80
|
+
*
|
|
81
|
+
* Without hysteresis two routes with near-equal round trips take turns being
|
|
82
|
+
* "best", and every switch is a webview navigation — a visible reload. The
|
|
83
|
+
* margin is deliberately asymmetric: a lower TIER always wins (that is a
|
|
84
|
+
* capability change, not a speed one), while a same-tier win needs to be
|
|
85
|
+
* meaningfully faster.
|
|
86
|
+
*/
|
|
87
|
+
export function shouldSwitch(
|
|
88
|
+
active: ProbedCandidate | null,
|
|
89
|
+
candidate: ProbedCandidate | null,
|
|
90
|
+
options: { minGainMs?: number; minGainRatio?: number } = {},
|
|
91
|
+
): boolean {
|
|
92
|
+
if (!candidate) return false;
|
|
93
|
+
if (!active) return true;
|
|
94
|
+
if (active.rttMs === null) return true;
|
|
95
|
+
|
|
96
|
+
const activeTier = ROUTE_TIER[active.kind];
|
|
97
|
+
const candidateTier = ROUTE_TIER[candidate.kind];
|
|
98
|
+
if (candidateTier < activeTier) return true;
|
|
99
|
+
if (candidateTier > activeTier) return false;
|
|
100
|
+
|
|
101
|
+
const minGainMs = options.minGainMs ?? 30;
|
|
102
|
+
const minGainRatio = options.minGainRatio ?? 0.2;
|
|
103
|
+
const gain = active.rttMs - (candidate.rttMs ?? Number.POSITIVE_INFINITY);
|
|
104
|
+
return gain > minGainMs && gain / active.rttMs > minGainRatio;
|
|
105
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shapes the Connect page, the pairing QR and the shells all agree on.
|
|
8
|
+
*
|
|
9
|
+
* One module because the same three facts travel through all of them: which
|
|
10
|
+
* addresses this server answers on, which tunnel is up, and which devices have
|
|
11
|
+
* been paired. A second copy of any of these shapes is how the QR starts
|
|
12
|
+
* carrying a field the server stopped sending.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* How a client reaches this server.
|
|
17
|
+
*
|
|
18
|
+
* The order of this union is NOT the preference order — see `ROUTE_TIER` in
|
|
19
|
+
* `tier.ts`. It is alphabetical-ish by how the address is produced, so a reader
|
|
20
|
+
* scanning a payload does not mistake the declaration order for a ranking.
|
|
21
|
+
*/
|
|
22
|
+
export type ConnectRouteKind = 'cloudflare' | 'lan' | 'tailscale';
|
|
23
|
+
|
|
24
|
+
/** One way to reach the server, as it appears in a pairing payload. */
|
|
25
|
+
export interface ConnectCandidate {
|
|
26
|
+
kind: ConnectRouteKind;
|
|
27
|
+
/** Origin only — no path, no trailing slash. */
|
|
28
|
+
url: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** One address the server knows about, and whether it is usable right now. */
|
|
32
|
+
export interface ConnectAddress extends ConnectCandidate {
|
|
33
|
+
/**
|
|
34
|
+
* Why this address cannot be used, when it cannot.
|
|
35
|
+
*
|
|
36
|
+
* A sentence, never a boolean: "tailscale is not running" and "no cloudflared
|
|
37
|
+
* config" are different problems with different fixes, and a greyed-out row
|
|
38
|
+
* with no text is the failure mode this field exists to prevent.
|
|
39
|
+
*/
|
|
40
|
+
unavailable: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The lifecycle of one tunnel provider. */
|
|
44
|
+
export type TunnelPhase = 'off' | 'starting' | 'up' | 'degraded' | 'failed';
|
|
45
|
+
|
|
46
|
+
export interface TunnelState {
|
|
47
|
+
provider: 'cloudflare' | 'tailscale';
|
|
48
|
+
phase: TunnelPhase;
|
|
49
|
+
/** The public origin while `phase` is `up` or `degraded`. */
|
|
50
|
+
url: string | null;
|
|
51
|
+
/** One sentence naming why it is not up. Null while it is. */
|
|
52
|
+
reason: string | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A device that has redeemed a pairing code. */
|
|
56
|
+
export interface PairedDevice {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
/** `ios`, `android`, `macos`, `windows`, `linux`, `web` — self-reported. */
|
|
60
|
+
platform: string;
|
|
61
|
+
/** The route this device last connected over, when it has said. */
|
|
62
|
+
route: ConnectRouteKind | null;
|
|
63
|
+
/** The device's own measurement of that route, in milliseconds. */
|
|
64
|
+
rttMs: number | null;
|
|
65
|
+
lastSeenAt: string | null;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Everything the Connect page draws, in one read. */
|
|
70
|
+
export interface ConnectStatus {
|
|
71
|
+
/**
|
|
72
|
+
* Stable identity of this server, derived from a persisted key.
|
|
73
|
+
*
|
|
74
|
+
* A device pins this and refuses a candidate that answers with a different
|
|
75
|
+
* one: a LAN address handed to another machine by DHCP must not receive the
|
|
76
|
+
* device's token.
|
|
77
|
+
*/
|
|
78
|
+
serverId: string;
|
|
79
|
+
/** The machine's display name, so a phone can label the server. */
|
|
80
|
+
label: string;
|
|
81
|
+
version: string;
|
|
82
|
+
addresses: ConnectAddress[];
|
|
83
|
+
tunnels: TunnelState[];
|
|
84
|
+
devices: PairedDevice[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A QR code as rows of `0`/`1`.
|
|
89
|
+
*
|
|
90
|
+
* Shared rather than server-only because the client draws it: the server encodes
|
|
91
|
+
* the payload, the page renders one `<rect>` per dark module. Sending markup
|
|
92
|
+
* instead would put a string built from a one-time secret into the DOM.
|
|
93
|
+
*/
|
|
94
|
+
export interface QrMatrix {
|
|
95
|
+
/** Modules per side, excluding the quiet zone. */
|
|
96
|
+
size: number;
|
|
97
|
+
/** `size` strings of `size` characters, `1` for a dark module. */
|
|
98
|
+
rows: string[];
|
|
99
|
+
}
|
|
@@ -7,12 +7,29 @@
|
|
|
7
7
|
* GENERATED — do not edit by hand. Run `bun run scripts/katex-fonts-woff2.mjs`
|
|
8
8
|
* after upgrading @fontsource/fira-code.
|
|
9
9
|
*
|
|
10
|
-
* Fira Code, latin
|
|
11
|
-
* `main.tsx` imports. Replaces
|
|
12
|
-
* which pulled 7 subsets
|
|
13
|
-
* latin-ext, symbols2) x 4
|
|
14
|
-
*
|
|
15
|
-
* fallback is never fetched by
|
|
10
|
+
* Fira Code, latin + symbols2 subsets, woff2-only, weights 400/500/600/700 —
|
|
11
|
+
* the faces `main.tsx` imports. Replaces
|
|
12
|
+
* `@fontsource/fira-code/{400,500,600,700}.css`, which pulled 7 subsets
|
|
13
|
+
* (cyrillic, cyrillic-ext, greek, greek-ext, latin, latin-ext, symbols2) x 4
|
|
14
|
+
* weights x 2 formats = 56 files. This console is English-only, so the
|
|
15
|
+
* language subsets were dead weight, and the woff fallback is never fetched by
|
|
16
|
+
* a browser that supports woff2.
|
|
17
|
+
*
|
|
18
|
+
* ## `symbols2` is NOT a language subset — dropping it broke every ASCII box
|
|
19
|
+
*
|
|
20
|
+
* It is the only subset carrying U+2500-259F (box drawing) and U+2000-200A
|
|
21
|
+
* (the fixed-width spaces). Without it those codepoints have no Fira Code face
|
|
22
|
+
* and fall through to the next family in the stack, `monospace` — a system
|
|
23
|
+
* face whose advance is not 0.6 em. Measured in WebKit at 12px: `M` 7.2px,
|
|
24
|
+
* `─`/`│`/`┌` 8.502px, so a box drawn with `─` overshoots its own `│` border by
|
|
25
|
+
* 1.3px per column and an agent's ASCII diagram arrives visibly skewed. With
|
|
26
|
+
* the face below declared, all four measure 7.2px.
|
|
27
|
+
*
|
|
28
|
+
* The `unicode-range` on every face is upstream's, and it is what keeps the
|
|
29
|
+
* 4 kB symbols2 files off the wire: a page that lays out no box-drawing glyph
|
|
30
|
+
* never requests them. Declaring the ranges also makes the face choice
|
|
31
|
+
* explicit instead of relying on "last declared wins" for the U+2000-200A
|
|
32
|
+
* overlap with latin.
|
|
16
33
|
*
|
|
17
34
|
* `font-display: swap` and the family/style/weight declarations match upstream,
|
|
18
35
|
* so text metrics are unchanged.
|
|
@@ -24,6 +41,7 @@
|
|
|
24
41
|
font-display: swap;
|
|
25
42
|
font-weight: 400;
|
|
26
43
|
src: url('@fontsource/fira-code/files/fira-code-latin-400-normal.woff2') format('woff2');
|
|
44
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
@font-face {
|
|
@@ -32,6 +50,7 @@
|
|
|
32
50
|
font-display: swap;
|
|
33
51
|
font-weight: 500;
|
|
34
52
|
src: url('@fontsource/fira-code/files/fira-code-latin-500-normal.woff2') format('woff2');
|
|
53
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
35
54
|
}
|
|
36
55
|
|
|
37
56
|
@font-face {
|
|
@@ -40,6 +59,7 @@
|
|
|
40
59
|
font-display: swap;
|
|
41
60
|
font-weight: 600;
|
|
42
61
|
src: url('@fontsource/fira-code/files/fira-code-latin-600-normal.woff2') format('woff2');
|
|
62
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
@font-face {
|
|
@@ -48,4 +68,43 @@
|
|
|
48
68
|
font-display: swap;
|
|
49
69
|
font-weight: 700;
|
|
50
70
|
src: url('@fontsource/fira-code/files/fira-code-latin-700-normal.woff2') format('woff2');
|
|
71
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Box drawing, block elements and the fixed-width spaces — see the note above.
|
|
75
|
+
* Declared AFTER latin so the U+2000-200A overlap resolves to this face. */
|
|
76
|
+
@font-face {
|
|
77
|
+
font-family: 'Fira Code';
|
|
78
|
+
font-style: normal;
|
|
79
|
+
font-display: swap;
|
|
80
|
+
font-weight: 400;
|
|
81
|
+
src: url('@fontsource/fira-code/files/fira-code-symbols2-400-normal.woff2') format('woff2');
|
|
82
|
+
unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@font-face {
|
|
86
|
+
font-family: 'Fira Code';
|
|
87
|
+
font-style: normal;
|
|
88
|
+
font-display: swap;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
src: url('@fontsource/fira-code/files/fira-code-symbols2-500-normal.woff2') format('woff2');
|
|
91
|
+
unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@font-face {
|
|
95
|
+
font-family: 'Fira Code';
|
|
96
|
+
font-style: normal;
|
|
97
|
+
font-display: swap;
|
|
98
|
+
font-weight: 600;
|
|
99
|
+
src: url('@fontsource/fira-code/files/fira-code-symbols2-600-normal.woff2') format('woff2');
|
|
100
|
+
unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@font-face {
|
|
104
|
+
font-family: 'Fira Code';
|
|
105
|
+
font-style: normal;
|
|
106
|
+
font-display: swap;
|
|
107
|
+
font-weight: 700;
|
|
108
|
+
src: url('@fontsource/fira-code/files/fira-code-symbols2-700-normal.woff2') format('woff2');
|
|
109
|
+
unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;
|
|
51
110
|
}
|
|
@@ -32,6 +32,7 @@ import { codeSafeAutolink } from '@/shared/lib/markdown/autolink';
|
|
|
32
32
|
import remend from 'remend';
|
|
33
33
|
import { highlightCode } from '@/shared/lib/code/syntax-highlight';
|
|
34
34
|
import { directiveBlockHtml, isDirectiveLanguage, parseDirectiveAttributes } from '@/shared/lib/markdown/directives';
|
|
35
|
+
import { mermaidActionsHtml, mermaidSourceHtml } from '@/shared/lib/markdown/mermaid-actions';
|
|
35
36
|
import { mathExtensions, setProseEscaped } from '@/shared/lib/markdown/math-extensions';
|
|
36
37
|
import { registerBlockMapper } from '@/shared/lib/markdown/blocks/renderer';
|
|
37
38
|
import { mapBlocks } from '@/shared/lib/markdown/blocks/scan';
|
|
@@ -82,11 +83,13 @@ function codeBlockShell(code: string, bodyHtml: string): string {
|
|
|
82
83
|
</div>\n`;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
// ```mermaid fences become a placeholder hydrated to SVG by mermaid.ts.
|
|
86
|
+
// ```mermaid fences become a placeholder hydrated to SVG by mermaid.ts. The
|
|
87
|
+
// actions come from `mermaid-actions.ts` rather than `codeBlockShell` because
|
|
88
|
+
// the hydrated block carries a refresh button too, and both states must show
|
|
89
|
+
// the same set.
|
|
86
90
|
function mermaidBlockRenderer(code: string): string {
|
|
87
|
-
const body = `<
|
|
88
|
-
|
|
89
|
-
return `<div class="mermaid-block" data-mermaid="${encodeURIComponent(code)}" data-mermaid-state="pending">${shell}</div>`;
|
|
91
|
+
const body = `<div class="code-block">${mermaidActionsHtml(code)}${mermaidSourceHtml(code)}</div>`;
|
|
92
|
+
return `<div class="mermaid-block" data-mermaid="${encodeURIComponent(code)}" data-mermaid-state="pending">${body}</div>`;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
function codeBlockRenderer(token: CodeToken): string {
|