@seaveyon/harness-switch 0.4.0 → 0.6.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/README.md +20 -4
- package/dist/harness-switch.js +470 -91
- package/package.json +4 -3
- package/public/06ac09dcb8ec7d56.woff2 +0 -0
- package/public/110e2a7693b4a5f3.woff2 +0 -0
- package/public/192d14b24f70b621.woff2 +0 -0
- package/public/2258ff2f7eae77c2.woff +0 -0
- package/public/2a0db5363856276c.woff2 +0 -0
- package/public/5a49cbe35ab2dd3c.woff2 +0 -0
- package/public/60bbe6c85a6afad1.woff2 +0 -0
- package/public/651bc97e3669e21f.woff2 +0 -0
- package/public/66a2e8650a2dcd92.woff2 +0 -0
- package/public/7d495472d32ca07d.woff +0 -0
- package/public/88f8fd5b09b976bb.woff +0 -0
- package/public/9533b5204f120066.woff +0 -0
- package/public/994c96595d20046b.woff +0 -0
- package/public/9faee8e8b774991c.woff2 +0 -0
- package/public/a7358d2e3dd919a9.woff2 +0 -0
- package/public/a8a9073d6f10c294.woff2 +0 -0
- package/public/assets/1044.39aafe87.js +1 -0
- package/public/assets/1045.21280f56.js +1 -0
- package/public/assets/1050.46b86852.js +1 -0
- package/public/assets/1064.d2226313.js +1 -0
- package/public/assets/109.d185b844.js +1 -0
- package/public/assets/117.fbce1498.js +1 -0
- package/public/assets/1216.f58f116a.js +1 -0
- package/public/assets/1266.b0b77ece.js +1 -0
- package/public/assets/1274.36c97e4b.js +1 -0
- package/public/assets/1284.6d1b1fa9.js +1 -0
- package/public/assets/1297.5aa40a92.js +1 -0
- package/public/assets/1337.91282e33.js +1 -0
- package/public/assets/1348.3156645b.js +1 -0
- package/public/assets/1446.08d331b6.js +1 -0
- package/public/assets/1473.b0f70164.js +1 -0
- package/public/assets/1495.98d34a19.js +1 -0
- package/public/assets/1498.a7a38ca7.js +1 -0
- package/public/assets/1506.50339f62.js +1 -0
- package/public/assets/1541.3def363d.js +1 -0
- package/public/assets/1558.a7617461.js +1 -0
- package/public/assets/1565.2f21c8e1.js +1 -0
- package/public/assets/1680.4e882493.js +1 -0
- package/public/assets/1706.b445c403.js +1 -0
- package/public/assets/1811.132227bb.js +1 -0
- package/public/assets/1822.9d44e9b8.js +1 -0
- package/public/assets/1852.561dcf77.js +1 -0
- package/public/assets/1875.f9da64a1.js +1 -0
- package/public/assets/193.86e5680f.js +1 -0
- package/public/assets/1942.edb657de.js +1 -0
- package/public/assets/197.be0123ad.js +1 -0
- package/public/assets/1972.b1548051.js +1 -0
- package/public/assets/198.2702464a.js +1 -0
- package/public/assets/1981.4e7751ba.js +1 -0
- package/public/assets/2048.e0b5be0d.js +1 -0
- package/public/assets/2067.6433a4bd.js +1 -0
- package/public/assets/2082.b2643ed0.js +1 -0
- package/public/assets/2185.248c6b44.js +1 -0
- package/public/assets/2202.e80e4d18.js +1 -0
- package/public/assets/2227.cf7e7a88.js +1 -0
- package/public/assets/2234.f03ed50e.js +1 -0
- package/public/assets/2247.8cd63431.js +1 -0
- package/public/assets/2301.5b08aa31.js +1 -0
- package/public/assets/231.073ec786.js +1 -0
- package/public/assets/233.9eea8428.js +1 -0
- package/public/assets/2332.bec77738.js +1 -0
- package/public/assets/234.e1ec501c.js +1 -0
- package/public/assets/2368.6d60e76e.js +1 -0
- package/public/assets/2378.a09f27ac.js +1 -0
- package/public/assets/2411.1a1e84d8.js +1 -0
- package/public/assets/2426.12abe760.js +1 -0
- package/public/assets/2536.d03279a1.js +1 -0
- package/public/assets/2605.3ae8a730.js +1 -0
- package/public/assets/2645.52e9596b.js +1 -0
- package/public/assets/2707.6df3e122.js +1 -0
- package/public/assets/2725.9a21dc87.js +1 -0
- package/public/assets/2743.d8ff9d1a.js +1 -0
- package/public/assets/2748.a74a539c.js +1 -0
- package/public/assets/2751.3761b15d.js +1 -0
- package/public/assets/278.06c0a585.js +1 -0
- package/public/assets/2810.0805c8d3.js +1 -0
- package/public/assets/2816.52f328bf.js +1 -0
- package/public/assets/2872.712f11ad.js +1 -0
- package/public/assets/2881.812773b3.js +1 -0
- package/public/assets/2895.412a0fef.js +1 -0
- package/public/assets/2918.ca9f8ee6.js +1 -0
- package/public/assets/2948.812bfd61.js +1 -0
- package/public/assets/3008.0e0072bf.js +1 -0
- package/public/assets/3084.812f46dd.js +1 -0
- package/public/assets/311.ff658c78.js +1 -0
- package/public/assets/3115.de6d897d.js +1 -0
- package/public/assets/312.6893cc70.js +1 -0
- package/public/assets/3121.abf15015.js +1 -0
- package/public/assets/3123.bb6961b4.js +1 -0
- package/public/assets/3168.f70fdbe1.js +1 -0
- package/public/assets/3260.b9830b0a.js +1 -0
- package/public/assets/331.5979e79c.js +1 -0
- package/public/assets/3323.33607bff.js +1 -0
- package/public/assets/333.62f29c23.js +1 -0
- package/public/assets/3339.55ba3289.js +1 -0
- package/public/assets/3370.ac044cd4.js +1 -0
- package/public/assets/3381.ebf520a0.js +1 -0
- package/public/assets/3384.97088998.js +1 -0
- package/public/assets/3420.d26395e2.js +1 -0
- package/public/assets/3432.9a6cbc9d.js +1 -0
- package/public/assets/3474.c3b0a117.js +1 -0
- package/public/assets/3502.713d8997.js +1 -0
- package/public/assets/3520.8332b3b9.js +1 -0
- package/public/assets/3663.7e96a229.js +1 -0
- package/public/assets/3707.9a1cc57e.js +1 -0
- package/public/assets/3712.ccdacc8b.js +1 -0
- package/public/assets/3724.c7124c16.js +1 -0
- package/public/assets/379.3eba2174.js +1 -0
- package/public/assets/3793.2f8f8fa2.js +1 -0
- package/public/assets/3808.61543a59.js +1 -0
- package/public/assets/3809.ea90d219.js +1 -0
- package/public/assets/382.df49ab73.js +1 -0
- package/public/assets/3844.ad345570.js +1 -0
- package/public/assets/3853.0041121c.js +1 -0
- package/public/assets/3886.4758be08.js +1 -0
- package/public/assets/3911.67d83e56.js +1 -0
- package/public/assets/3945.02b410f7.js +1 -0
- package/public/assets/4025.faefbdf9.js +1 -0
- package/public/assets/4049.274b3781.js +1 -0
- package/public/assets/4058.9bd8b6fd.js +1 -0
- package/public/assets/4087.f5f2aa77.js +1 -0
- package/public/assets/4145.591efba1.js +1 -0
- package/public/assets/4179.0e70c02d.js +1 -0
- package/public/assets/4261.24d2c946.js +1 -0
- package/public/assets/4301.d36b09ac.js +1 -0
- package/public/assets/438.c9ddabb1.js +1 -0
- package/public/assets/4405.195b8807.js +1 -0
- package/public/assets/4429.20a43aee.js +1 -0
- package/public/assets/4445.0593f53c.js +1 -0
- package/public/assets/4447.1f4c2594.js +1 -0
- package/public/assets/4458.b54836f5.js +1 -0
- package/public/assets/4489.e05c3f02.js +1 -0
- package/public/assets/4496.59f9e494.js +1 -0
- package/public/assets/4498.53895790.js +1 -0
- package/public/assets/452.bf34842d.js +1 -0
- package/public/assets/4525.202e71f0.js +1 -0
- package/public/assets/459.d0de752e.js +1 -0
- package/public/assets/4609.539adc7e.js +1 -0
- package/public/assets/4613.2c9412fc.js +1 -0
- package/public/assets/465.6d0c9900.js +1 -0
- package/public/assets/4655.817d8c16.js +1 -0
- package/public/assets/4704.5bd5cd1f.js +1 -0
- package/public/assets/4705.1b7400d1.js +1 -0
- package/public/assets/4785.2c122907.js +1 -0
- package/public/assets/4795.5b28b5a2.js +1 -0
- package/public/assets/4796.38fc127d.js +1 -0
- package/public/assets/4798.061be689.js +1 -0
- package/public/assets/4846.2f6655eb.js +1 -0
- package/public/assets/485.3fe4cb47.js +1 -0
- package/public/assets/4885.c0812b9f.js +1 -0
- package/public/assets/4952.5b132c3d.js +1 -0
- package/public/assets/4983.565b5198.js +1 -0
- package/public/assets/4992.abfa216e.js +1 -0
- package/public/assets/4994.5eac32c7.js +1 -0
- package/public/assets/4996.46cad67b.js +1 -0
- package/public/assets/5068.3fa2fa23.js +1 -0
- package/public/assets/5072.7adfff93.js +1 -0
- package/public/assets/5108.62165adf.js +1 -0
- package/public/assets/5280.bc09c97b.js +1 -0
- package/public/assets/5281.73e94011.js +1 -0
- package/public/assets/5294.b2f2f0bd.js +1 -0
- package/public/assets/5319.e6dcabf9.js +1 -0
- package/public/assets/5393.e6c80ec4.js +1 -0
- package/public/assets/5398.d0384b7e.js +1 -0
- package/public/assets/5415.c896e0e1.js +1 -0
- package/public/assets/544.64addbc4.js +1 -0
- package/public/assets/5453.08deb63c.js +1 -0
- package/public/assets/5458.0095414b.js +1 -0
- package/public/assets/5462.17536a21.js +1 -0
- package/public/assets/5466.7acd94a7.js +1 -0
- package/public/assets/5518.57996485.js +1 -0
- package/public/assets/5530.828452d4.js +1 -0
- package/public/assets/5542.9162530c.js +1 -0
- package/public/assets/5593.0776f2d3.js +1 -0
- package/public/assets/5596.8a7ddea5.js +1 -0
- package/public/assets/5631.f6c57eaf.js +1 -0
- package/public/assets/5646.1b33e69c.js +1 -0
- package/public/assets/5661.164c0709.js +1 -0
- package/public/assets/5678.c096f6c9.js +1 -0
- package/public/assets/5687.587f0e75.js +1 -0
- package/public/assets/5703.5e666028.js +1 -0
- package/public/assets/5708.164057e0.js +1 -0
- package/public/assets/5712.cc503220.js +1 -0
- package/public/assets/575.e898fd86.js +1 -0
- package/public/assets/5752.e018032d.js +1 -0
- package/public/assets/5813.cc59df28.js +1 -0
- package/public/assets/5865.012fa536.js +1 -0
- package/public/assets/5879.47b8e3c2.js +1 -0
- package/public/assets/590.8c02fbf9.js +1 -0
- package/public/assets/5917.87e0acee.js +1 -0
- package/public/assets/5959.c0de70a1.js +1 -0
- package/public/assets/5970.31600f7b.js +1 -0
- package/public/assets/6005.fb7dbdae.js +1 -0
- package/public/assets/6024.c3f22f35.js +1 -0
- package/public/assets/6070.6f66b5fa.js +1 -0
- package/public/assets/6084.26b44499.js +1 -0
- package/public/assets/6085.cb855236.js +1 -0
- package/public/assets/6093.bebbe3da.js +1 -0
- package/public/assets/6106.39b87fca.js +1 -0
- package/public/assets/6122.f064356d.js +1 -0
- package/public/assets/6150.5cb126a5.js +203 -0
- package/public/assets/6157.7eeb3515.js +1 -0
- package/public/assets/616.a5acd2aa.js +1 -0
- package/public/assets/6226.dd8f1fd9.js +1 -0
- package/public/assets/6231.c10ba8f9.js +1 -0
- package/public/assets/6254.69f98e64.js +1 -0
- package/public/assets/6308.9f7b0778.js +1 -0
- package/public/assets/6309.fd92f229.js +1 -0
- package/public/assets/6378.d0087d79.js +1 -0
- package/public/assets/6380.6a320a57.js +1 -0
- package/public/assets/6427.80120ca0.js +1 -0
- package/public/assets/6468.cd796686.js +1 -0
- package/public/assets/655.2424b6f0.js +1 -0
- package/public/assets/6551.1316a8b4.js +1 -0
- package/public/assets/6563.f0ab8ea9.js +1 -0
- package/public/assets/658.d1870bbc.js +1 -0
- package/public/assets/659.43d1bd18.js +1 -0
- package/public/assets/6629.d5835f7b.js +1 -0
- package/public/assets/670.cc579966.js +1 -0
- package/public/assets/6729.711b6a33.js +1 -0
- package/public/assets/6739.5df85504.js +1 -0
- package/public/assets/6766.b3b93d6b.js +1 -0
- package/public/assets/6781.8330074c.js +1 -0
- package/public/assets/6829.f83cf943.js +1 -0
- package/public/assets/6855.c3b857c6.js +1 -0
- package/public/assets/6883.55fcdbea.js +1 -0
- package/public/assets/6900.abab0925.js +1 -0
- package/public/assets/6956.8307b311.js +1 -0
- package/public/assets/6959.7c488de5.js +1 -0
- package/public/assets/698.ebc84dc0.js +1 -0
- package/public/assets/7015.a05d0b78.js +1 -0
- package/public/assets/702.98bd9103.js +1 -0
- package/public/assets/703.285f3139.js +1 -0
- package/public/assets/7091.027a641c.js +1 -0
- package/public/assets/7104.9c59e320.js +1 -0
- package/public/assets/7113.0dfbe544.js +1 -0
- package/public/assets/7135.e9ab3841.js +1 -0
- package/public/assets/7143.612c372b.js +1 -0
- package/public/assets/7198.dc23f6fa.js +1 -0
- package/public/assets/7228.5b31dd65.js +1 -0
- package/public/assets/7234.bec30557.js +1 -0
- package/public/assets/7330.b15282a7.js +1 -0
- package/public/assets/7342.6f18177c.js +1 -0
- package/public/assets/7350.e46146b3.js +1 -0
- package/public/assets/7372.863b3f51.js +1 -0
- package/public/assets/7387.78fae2d9.js +1 -0
- package/public/assets/7403.acdec0cd.js +1 -0
- package/public/assets/7404.c90b9555.js +1 -0
- package/public/assets/7454.61df5c53.js +1 -0
- package/public/assets/7459.91247a0c.js +1 -0
- package/public/assets/7620.1317e4da.js +1 -0
- package/public/assets/7655.a8e05941.js +1 -0
- package/public/assets/7662.5c5fd466.js +1 -0
- package/public/assets/7698.68eab02c.js +1 -0
- package/public/assets/7714.6a6656ee.js +1 -0
- package/public/assets/7774.b546561d.js +1 -0
- package/public/assets/7822.264595e9.js +1 -0
- package/public/assets/7827.9a988ed6.js +1 -0
- package/public/assets/7858.565180cd.js +1 -0
- package/public/assets/7880.23c4af6f.js +1 -0
- package/public/assets/7921.796cf6f2.js +1 -0
- package/public/assets/7950.9222be47.js +1 -0
- package/public/assets/7992.1bbe27a2.js +1 -0
- package/public/assets/7993.3e415bcd.js +1 -0
- package/public/assets/8012.1df6c7ba.js +1 -0
- package/public/assets/8014.1618a26d.js +1 -0
- package/public/assets/8095.3b776dc1.js +1 -0
- package/public/assets/8115.01697474.js +1 -0
- package/public/assets/8134.2dbefad3.js +1 -0
- package/public/assets/8173.98e9cda8.js +1 -0
- package/public/assets/8178.4448a8c8.js +1 -0
- package/public/assets/8189.726f5bba.js +1 -0
- package/public/assets/8250.6a31d3db.js +1 -0
- package/public/assets/8252.46abb10d.js +1 -0
- package/public/assets/826.55f3327b.js +1 -0
- package/public/assets/8286.7165c5ae.js +1 -0
- package/public/assets/829.57aaa21f.js +1 -0
- package/public/assets/8295.510e74b2.js +1 -0
- package/public/assets/8306.ffe7fef6.js +1 -0
- package/public/assets/8336.071bb524.js +1 -0
- package/public/assets/8346.cfd200d8.js +1 -0
- package/public/assets/8349.8746a8e4.js +1 -0
- package/public/assets/8375.0bf25482.js +1 -0
- package/public/assets/8387.7849a364.js +1 -0
- package/public/assets/8408.7b3b0706.js +1 -0
- package/public/assets/8423.da4adde4.js +1 -0
- package/public/assets/8437.67cbb62b.js +1 -0
- package/public/assets/8439.4ab411cf.js +1 -0
- package/public/assets/8447.805e1fbb.js +1 -0
- package/public/assets/8481.30bb3786.js +1 -0
- package/public/assets/8531.0e8a1bcd.js +1 -0
- package/public/assets/855.c45d80d8.js +1 -0
- package/public/assets/857.47395203.js +1 -0
- package/public/assets/8601.e90cd434.js +1 -0
- package/public/assets/8671.f9b853f6.js +1 -0
- package/public/assets/8696.2db4dd40.js +1 -0
- package/public/assets/8698.d8c25bfd.js +1 -0
- package/public/assets/8725.2a97b2e0.js +1 -0
- package/public/assets/8767.f7dbaf81.js +1 -0
- package/public/assets/877.0d1df971.js +1 -0
- package/public/assets/8799.b2bc36a0.js +1 -0
- package/public/assets/8805.e166d436.js +1 -0
- package/public/assets/8861.8e37cb89.js +1 -0
- package/public/assets/8943.d35181ef.js +1 -0
- package/public/assets/9020.b1614bfe.js +1 -0
- package/public/assets/9048.8a6be463.js +1 -0
- package/public/assets/9060.f88d7ff2.js +1 -0
- package/public/assets/9109.e2cef4ae.js +1 -0
- package/public/assets/9120.0baa1b3f.js +1 -0
- package/public/assets/9172.9b1d2d6a.js +1 -0
- package/public/assets/920.5f971a4e.js +1 -0
- package/public/assets/9279.7ff451d0.js +1 -0
- package/public/assets/9285.c26079c7.js +1 -0
- package/public/assets/9297.7162de0e.js +1 -0
- package/public/assets/9328.a33ba701.js +1 -0
- package/public/assets/940.5806c487.js +1 -0
- package/public/assets/9403.d4200316.js +1 -0
- package/public/assets/9412.5849ed28.js +1 -0
- package/public/assets/9420.c4e70fab.js +1 -0
- package/public/assets/9467.1a7a6c92.js +1 -0
- package/public/assets/9502.c84dc29b.js +1 -0
- package/public/assets/9556.97e5f142.js +1 -0
- package/public/assets/9557.b10d5e41.js +1 -0
- package/public/assets/9597.c517cbfd.js +1 -0
- package/public/assets/96.fdb82714.js +1 -0
- package/public/assets/9619.35683308.js +1 -0
- package/public/assets/9623.437474fc.js +1 -0
- package/public/assets/9663.1210b76e.js +1 -0
- package/public/assets/9671.40a11985.js +1 -0
- package/public/assets/969.ce9121b3.js +1 -0
- package/public/assets/9695.84356bbf.js +1 -0
- package/public/assets/9728.4f98e0ce.js +1 -0
- package/public/assets/9770.df634bdf.js +1 -0
- package/public/assets/9842.6faee06c.js +1 -0
- package/public/assets/9886.1c62a8ff.js +1 -0
- package/public/assets/9888.e3c97777.js +1 -0
- package/public/assets/9918.7ac5f09c.js +1 -0
- package/public/assets/9927.89711a15.js +1 -0
- package/public/assets/9940.70581af3.js +1 -0
- package/public/assets/9990.cf02a3de.js +1 -0
- package/public/assets/main.5b6d51f1.css +2 -0
- package/public/assets/main.7aee2734.js +1 -0
- package/public/b0b919fcf36c2073.woff2 +0 -0
- package/public/bdc4ddcb892cb87b.woff2 +0 -0
- package/public/cd8df815c9344be0.woff2 +0 -0
- package/public/d2ac083e197becc1.woff +0 -0
- package/public/dece0821e8ed059f.woff2 +0 -0
- package/public/e32cf7a40c90e778.woff +0 -0
- package/public/e53d79b9a7d8ae7b.woff +0 -0
- package/public/ef1c8a30e0ed6275.woff2 +0 -0
- package/public/f14ffb91743624fd.woff +0 -0
- package/public/f9f2cfdc8f44d943.woff +0 -0
- package/public/index.html +1 -1
- package/public/assets/main.2375bf2a.css +0 -2
- package/public/assets/main.bd9d3d5b.js +0 -1
package/dist/harness-switch.js
CHANGED
|
@@ -9034,7 +9034,7 @@ var deleteCookie = (c, name, opt) => {
|
|
|
9034
9034
|
};
|
|
9035
9035
|
|
|
9036
9036
|
// src/services/auth.ts
|
|
9037
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
9037
|
+
import { createHash, randomBytes as randomBytes3 } from "crypto";
|
|
9038
9038
|
|
|
9039
9039
|
// src/di/collection.ts
|
|
9040
9040
|
class ServiceCollection {
|
|
@@ -9195,14 +9195,15 @@ class EnvironmentService {
|
|
|
9195
9195
|
homeDir = process.env.HSW_HOME_DIR || homedir();
|
|
9196
9196
|
dataDir = process.env.HSW_DATA_DIR || join2(this.homeDir, ".harness-switch");
|
|
9197
9197
|
publicDir = process.env.HSW_PUBLIC_DIR || resolvePublicDir();
|
|
9198
|
-
sessionTtlMs =
|
|
9198
|
+
sessionTtlMs = resolveSessionTtlMs();
|
|
9199
9199
|
cookieName = "hsw_session";
|
|
9200
9200
|
files = {
|
|
9201
9201
|
profiles: join2(this.dataDir, "profiles.json"),
|
|
9202
9202
|
active: join2(this.dataDir, "active.json"),
|
|
9203
9203
|
password: join2(this.dataDir, "web_password"),
|
|
9204
9204
|
key: join2(this.dataDir, "aes-256-gcm.key"),
|
|
9205
|
-
env: join2(this.dataDir, "env.sh")
|
|
9205
|
+
env: join2(this.dataDir, "env.sh"),
|
|
9206
|
+
sessions: join2(this.dataDir, "sessions.json")
|
|
9206
9207
|
};
|
|
9207
9208
|
backupsDir = join2(this.dataDir, "backups");
|
|
9208
9209
|
backupRetainCount = Math.max(1, Number(process.env.HSW_BACKUP_RETAIN || 10));
|
|
@@ -9210,13 +9211,17 @@ class EnvironmentService {
|
|
|
9210
9211
|
claude: join2(this.homeDir, ".claude"),
|
|
9211
9212
|
codex: process.env.CODEX_HOME || join2(this.homeDir, ".codex"),
|
|
9212
9213
|
kimiCode: process.env.KIMI_CODE_HOME || join2(this.homeDir, ".kimi-code"),
|
|
9213
|
-
piAgent: process.env.PI_CODING_AGENT_DIR || join2(this.homeDir, ".
|
|
9214
|
+
piAgent: process.env.PI_CODING_AGENT_DIR || join2(this.homeDir, ".pi", "agent"),
|
|
9214
9215
|
dsh: process.env.DSH_HOME || join2(this.homeDir, ".dsh")
|
|
9215
9216
|
};
|
|
9216
9217
|
ensureDataDir() {
|
|
9217
9218
|
mkdirSync(this.dataDir, { recursive: true, mode: 448 });
|
|
9218
9219
|
}
|
|
9219
9220
|
}
|
|
9221
|
+
function resolveSessionTtlMs() {
|
|
9222
|
+
const hours = Number(process.env.HSW_SESSION_TTL_HOURS || 24);
|
|
9223
|
+
return (Number.isFinite(hours) && hours > 0 ? hours : 24) * 60 * 60 * 1000;
|
|
9224
|
+
}
|
|
9220
9225
|
function resolvePublicDir() {
|
|
9221
9226
|
const candidates = [
|
|
9222
9227
|
join2(import.meta.dir, "../public"),
|
|
@@ -9404,6 +9409,7 @@ class LogService {
|
|
|
9404
9409
|
}
|
|
9405
9410
|
|
|
9406
9411
|
// src/services/auth.ts
|
|
9412
|
+
var STORE_VERSION = 1;
|
|
9407
9413
|
var IAuthService = createDecorator("authService");
|
|
9408
9414
|
var _dec = [
|
|
9409
9415
|
inject(IEnvironmentService, IFileService, ICryptoService, ILogService)
|
|
@@ -9415,7 +9421,8 @@ class AuthService {
|
|
|
9415
9421
|
files;
|
|
9416
9422
|
crypto;
|
|
9417
9423
|
log;
|
|
9418
|
-
sessions
|
|
9424
|
+
sessions;
|
|
9425
|
+
fingerprint = "";
|
|
9419
9426
|
constructor(environment, files, crypto2, log) {
|
|
9420
9427
|
this.environment = environment;
|
|
9421
9428
|
this.files = files;
|
|
@@ -9438,30 +9445,77 @@ class AuthService {
|
|
|
9438
9445
|
return null;
|
|
9439
9446
|
}
|
|
9440
9447
|
const token = randomBytes3(32).toString("base64url");
|
|
9441
|
-
this.
|
|
9448
|
+
this.load().set(digest("session", token), {
|
|
9449
|
+
expires: Date.now() + this.environment.sessionTtlMs
|
|
9450
|
+
});
|
|
9451
|
+
this.persist();
|
|
9442
9452
|
return token;
|
|
9443
9453
|
}
|
|
9444
9454
|
logout(token) {
|
|
9445
|
-
if (token) {
|
|
9446
|
-
this.
|
|
9455
|
+
if (token && this.load().delete(digest("session", token))) {
|
|
9456
|
+
this.persist();
|
|
9447
9457
|
}
|
|
9448
9458
|
}
|
|
9449
9459
|
isAuthenticated(token) {
|
|
9450
9460
|
if (!token) {
|
|
9451
9461
|
return false;
|
|
9452
9462
|
}
|
|
9453
|
-
const
|
|
9463
|
+
const sessions = this.load();
|
|
9464
|
+
const key = digest("session", token);
|
|
9465
|
+
const session = sessions.get(key);
|
|
9454
9466
|
if (!session || session.expires < Date.now()) {
|
|
9455
|
-
|
|
9467
|
+
if (sessions.delete(key)) {
|
|
9468
|
+
this.persist();
|
|
9469
|
+
}
|
|
9456
9470
|
return false;
|
|
9457
9471
|
}
|
|
9458
9472
|
return true;
|
|
9459
9473
|
}
|
|
9474
|
+
load() {
|
|
9475
|
+
const loaded = this.sessions;
|
|
9476
|
+
if (loaded) {
|
|
9477
|
+
return loaded;
|
|
9478
|
+
}
|
|
9479
|
+
this.fingerprint = digest("password", this.ensurePassword());
|
|
9480
|
+
const store = this.files.readJson(this.environment.files.sessions, {
|
|
9481
|
+
version: STORE_VERSION,
|
|
9482
|
+
password: this.fingerprint,
|
|
9483
|
+
sessions: {}
|
|
9484
|
+
});
|
|
9485
|
+
const sessions = new Map;
|
|
9486
|
+
if (store.version === STORE_VERSION && store.password === this.fingerprint) {
|
|
9487
|
+
const now = Date.now();
|
|
9488
|
+
for (const [key, session] of Object.entries(store.sessions ?? {})) {
|
|
9489
|
+
if (typeof session?.expires === "number" && session.expires > now) {
|
|
9490
|
+
sessions.set(key, { expires: session.expires });
|
|
9491
|
+
}
|
|
9492
|
+
}
|
|
9493
|
+
}
|
|
9494
|
+
this.sessions = sessions;
|
|
9495
|
+
if (sessions.size > 0) {
|
|
9496
|
+
this.log.info(`restored ${sessions.size} web session(s)`);
|
|
9497
|
+
}
|
|
9498
|
+
return sessions;
|
|
9499
|
+
}
|
|
9500
|
+
persist() {
|
|
9501
|
+
const sessions = this.sessions;
|
|
9502
|
+
if (!sessions) {
|
|
9503
|
+
return;
|
|
9504
|
+
}
|
|
9505
|
+
this.files.writeJson(this.environment.files.sessions, {
|
|
9506
|
+
version: STORE_VERSION,
|
|
9507
|
+
password: this.fingerprint,
|
|
9508
|
+
sessions: Object.fromEntries(sessions)
|
|
9509
|
+
});
|
|
9510
|
+
}
|
|
9460
9511
|
}
|
|
9461
9512
|
AuthService = __decorateElement(_init, 0, "AuthService", _dec, AuthService);
|
|
9462
9513
|
__runInitializers(_init, 1, AuthService);
|
|
9463
9514
|
__decoratorMetadata(_init, AuthService);
|
|
9464
9515
|
let _AuthService = AuthService;
|
|
9516
|
+
function digest(kind, value) {
|
|
9517
|
+
return createHash("sha256").update(`${kind}:${value}`).digest("base64url");
|
|
9518
|
+
}
|
|
9465
9519
|
|
|
9466
9520
|
// src/http/middleware.ts
|
|
9467
9521
|
function createServiceMiddleware(services) {
|
|
@@ -9574,23 +9628,42 @@ class BackupService {
|
|
|
9574
9628
|
return id;
|
|
9575
9629
|
}
|
|
9576
9630
|
list() {
|
|
9577
|
-
|
|
9631
|
+
const liveCache = new Map;
|
|
9632
|
+
const readLive = (path) => {
|
|
9633
|
+
if (!liveCache.has(path)) {
|
|
9634
|
+
liveCache.set(path, this.files.readOptional(path) ?? null);
|
|
9635
|
+
}
|
|
9636
|
+
return liveCache.get(path) ?? null;
|
|
9637
|
+
};
|
|
9638
|
+
return this.readManifests().map((manifest) => {
|
|
9639
|
+
const dir = join3(this.environment.backupsDir, manifest.id);
|
|
9640
|
+
return {
|
|
9641
|
+
id: manifest.id,
|
|
9642
|
+
createdAt: manifest.createdAt,
|
|
9643
|
+
harness: manifest.harness,
|
|
9644
|
+
profile: manifest.profile,
|
|
9645
|
+
files: manifest.files.map((file) => ({ path: file.path, existed: file.existed })),
|
|
9646
|
+
current: this.matchesLive(dir, manifest.files, readLive)
|
|
9647
|
+
};
|
|
9648
|
+
}).toSorted((left, right) => right.id.localeCompare(left.id));
|
|
9649
|
+
}
|
|
9650
|
+
detail(id) {
|
|
9651
|
+
const { dir, manifest } = this.requireManifest(id);
|
|
9652
|
+
return {
|
|
9578
9653
|
id: manifest.id,
|
|
9579
9654
|
createdAt: manifest.createdAt,
|
|
9580
9655
|
harness: manifest.harness,
|
|
9581
9656
|
profile: manifest.profile,
|
|
9582
|
-
files: manifest.files.map((file) => ({
|
|
9583
|
-
|
|
9657
|
+
files: manifest.files.map((file) => ({
|
|
9658
|
+
path: file.path,
|
|
9659
|
+
existed: file.existed,
|
|
9660
|
+
content: this.storedContent(dir, file),
|
|
9661
|
+
currentContent: this.files.readOptional(file.path) ?? null
|
|
9662
|
+
}))
|
|
9663
|
+
};
|
|
9584
9664
|
}
|
|
9585
9665
|
restore(id) {
|
|
9586
|
-
|
|
9587
|
-
throw new HttpError(400, "invalid backup id");
|
|
9588
|
-
}
|
|
9589
|
-
const dir = join3(this.environment.backupsDir, id);
|
|
9590
|
-
const manifest = this.files.readJson(join3(dir, MANIFEST), null);
|
|
9591
|
-
if (!manifest) {
|
|
9592
|
-
throw new HttpError(404, "backup not found");
|
|
9593
|
-
}
|
|
9666
|
+
const { dir, manifest } = this.requireManifest(id);
|
|
9594
9667
|
for (const file of manifest.files) {
|
|
9595
9668
|
if (!file.existed || !file.stored) {
|
|
9596
9669
|
this.files.remove(file.path);
|
|
@@ -9603,6 +9676,30 @@ class BackupService {
|
|
|
9603
9676
|
this.files.writeUserFile(file.path, content);
|
|
9604
9677
|
}
|
|
9605
9678
|
}
|
|
9679
|
+
requireManifest(id) {
|
|
9680
|
+
if (id.includes("/") || id.includes("\\") || id.includes("..")) {
|
|
9681
|
+
throw new HttpError(400, "invalid backup id");
|
|
9682
|
+
}
|
|
9683
|
+
const dir = join3(this.environment.backupsDir, id);
|
|
9684
|
+
const manifest = this.files.readJson(join3(dir, MANIFEST), null);
|
|
9685
|
+
if (!manifest) {
|
|
9686
|
+
throw new HttpError(404, "backup not found");
|
|
9687
|
+
}
|
|
9688
|
+
return { dir, manifest };
|
|
9689
|
+
}
|
|
9690
|
+
matchesLive(dir, files, readLive) {
|
|
9691
|
+
return files.every((file) => this.storedContent(dir, file) === readLive(file.path));
|
|
9692
|
+
}
|
|
9693
|
+
storedContent(dir, file) {
|
|
9694
|
+
if (!file.existed || !file.stored) {
|
|
9695
|
+
return null;
|
|
9696
|
+
}
|
|
9697
|
+
const content = this.files.readOptional(join3(dir, file.stored));
|
|
9698
|
+
if (content === undefined) {
|
|
9699
|
+
throw new HttpError(500, `backup payload missing for ${file.path}`);
|
|
9700
|
+
}
|
|
9701
|
+
return content;
|
|
9702
|
+
}
|
|
9606
9703
|
readManifests() {
|
|
9607
9704
|
return this.files.listDirectories(this.environment.backupsDir).map((name) => this.files.readJson(join3(this.environment.backupsDir, name, MANIFEST), null)).filter((manifest) => manifest !== null);
|
|
9608
9705
|
}
|
|
@@ -9636,6 +9733,7 @@ function createBackupRoutes(services) {
|
|
|
9636
9733
|
const app = new Hono2;
|
|
9637
9734
|
const backups = services.get(IBackupService);
|
|
9638
9735
|
app.get("/", (c) => c.json({ items: backups.list() }));
|
|
9736
|
+
app.get("/:id", (c) => c.json(backups.detail(decodeURIComponent(c.req.param("id")))));
|
|
9639
9737
|
app.post("/:id/restore", (c) => {
|
|
9640
9738
|
backups.restore(decodeURIComponent(c.req.param("id")));
|
|
9641
9739
|
return c.json({ ok: true });
|
|
@@ -11122,28 +11220,19 @@ class CodexAdapter {
|
|
|
11122
11220
|
}
|
|
11123
11221
|
return rendered;
|
|
11124
11222
|
}
|
|
11125
|
-
renderOfficial(
|
|
11223
|
+
renderOfficial(_profile, current) {
|
|
11126
11224
|
const config = parseTomlObject(current[CONFIG]);
|
|
11127
|
-
const activeProviderId = readString(config, "model_provider");
|
|
11128
11225
|
delete config.model_provider;
|
|
11129
11226
|
delete config.model;
|
|
11130
11227
|
delete config.model_reasoning_effort;
|
|
11131
|
-
|
|
11132
|
-
if (profile) {
|
|
11133
|
-
delete config.model_providers[this.providerId(profile)];
|
|
11134
|
-
}
|
|
11135
|
-
if (activeProviderId) {
|
|
11136
|
-
delete config.model_providers[activeProviderId];
|
|
11137
|
-
}
|
|
11138
|
-
if (Object.keys(config.model_providers).length === 0) {
|
|
11139
|
-
delete config.model_providers;
|
|
11140
|
-
}
|
|
11141
|
-
}
|
|
11228
|
+
delete config.model_providers;
|
|
11142
11229
|
const rendered = { [CONFIG]: stringifyToml(config) };
|
|
11143
|
-
if (
|
|
11230
|
+
if (current[AUTH] !== undefined) {
|
|
11144
11231
|
const auth = parseJsonObject(current[AUTH]);
|
|
11145
|
-
|
|
11146
|
-
|
|
11232
|
+
if (DEFAULT_ENV_KEY in auth) {
|
|
11233
|
+
delete auth[DEFAULT_ENV_KEY];
|
|
11234
|
+
rendered[AUTH] = stringifyJson(auth);
|
|
11235
|
+
}
|
|
11147
11236
|
}
|
|
11148
11237
|
return rendered;
|
|
11149
11238
|
}
|
|
@@ -11527,7 +11616,7 @@ class KimiAdapter {
|
|
|
11527
11616
|
// src/services/adapters/pi.ts
|
|
11528
11617
|
import { join as join8 } from "path";
|
|
11529
11618
|
var MODELS = "models";
|
|
11530
|
-
var
|
|
11619
|
+
var SETTINGS3 = "settings";
|
|
11531
11620
|
var DEFAULT_CONTEXT3 = 200000;
|
|
11532
11621
|
var DEFAULT_MAX_TOKENS2 = 8192;
|
|
11533
11622
|
|
|
@@ -11536,7 +11625,7 @@ class PiAdapter {
|
|
|
11536
11625
|
id = "pi";
|
|
11537
11626
|
mode = "additive";
|
|
11538
11627
|
envVarNames = [];
|
|
11539
|
-
envNote = "API key \u76F4\u63A5\u5199\u5165 models.
|
|
11628
|
+
envNote = "API key \u76F4\u63A5\u5199\u5165 models.json\uFF0C\u65E0\u9700\u73AF\u5883\u53D8\u91CF\uFF1B\u8FD0\u884C\u65F6\u4ECD\u53EF\u7528 --model \u8986\u76D6\u3002";
|
|
11540
11629
|
fields = [
|
|
11541
11630
|
{
|
|
11542
11631
|
key: "providerId",
|
|
@@ -11552,7 +11641,8 @@ class PiAdapter {
|
|
|
11552
11641
|
defaultValue: "openai-completions",
|
|
11553
11642
|
options: [
|
|
11554
11643
|
{ value: "openai-completions", label: "openai-completions" },
|
|
11555
|
-
{ value: "openai-responses", label: "openai-responses" }
|
|
11644
|
+
{ value: "openai-responses", label: "openai-responses" },
|
|
11645
|
+
{ value: "anthropic-messages", label: "anthropic-messages" }
|
|
11556
11646
|
]
|
|
11557
11647
|
},
|
|
11558
11648
|
{
|
|
@@ -11577,6 +11667,17 @@ class PiAdapter {
|
|
|
11577
11667
|
label: "\u6700\u5927\u8F93\u51FA tokens",
|
|
11578
11668
|
kind: "text",
|
|
11579
11669
|
defaultValue: String(DEFAULT_MAX_TOKENS2)
|
|
11670
|
+
},
|
|
11671
|
+
{
|
|
11672
|
+
key: "reasoning",
|
|
11673
|
+
label: "\u63A8\u7406\u80FD\u529B",
|
|
11674
|
+
kind: "select",
|
|
11675
|
+
defaultValue: "false",
|
|
11676
|
+
help: "\u5BF9\u5E94 models.json \u7684 reasoning\u3002GPT / Claude \u601D\u8003\u6A21\u578B\u9700\u8981\u5F00\u542F\u3002",
|
|
11677
|
+
options: [
|
|
11678
|
+
{ value: "false", label: "\u5173\u95ED" },
|
|
11679
|
+
{ value: "true", label: "\u5F00\u542F" }
|
|
11680
|
+
]
|
|
11580
11681
|
}
|
|
11581
11682
|
];
|
|
11582
11683
|
constructor(environment) {
|
|
@@ -11586,15 +11687,15 @@ class PiAdapter {
|
|
|
11586
11687
|
return [
|
|
11587
11688
|
{
|
|
11588
11689
|
key: MODELS,
|
|
11589
|
-
label: "models.
|
|
11590
|
-
path: join8(this.environment.harnessHomes.piAgent, "models.
|
|
11591
|
-
format: "
|
|
11690
|
+
label: "models.json",
|
|
11691
|
+
path: join8(this.environment.harnessHomes.piAgent, "models.json"),
|
|
11692
|
+
format: "json"
|
|
11592
11693
|
},
|
|
11593
11694
|
{
|
|
11594
|
-
key:
|
|
11595
|
-
label: "
|
|
11596
|
-
path: join8(this.environment.harnessHomes.piAgent, "
|
|
11597
|
-
format: "
|
|
11695
|
+
key: SETTINGS3,
|
|
11696
|
+
label: "settings.json",
|
|
11697
|
+
path: join8(this.environment.harnessHomes.piAgent, "settings.json"),
|
|
11698
|
+
format: "json"
|
|
11598
11699
|
}
|
|
11599
11700
|
];
|
|
11600
11701
|
}
|
|
@@ -11603,30 +11704,37 @@ class PiAdapter {
|
|
|
11603
11704
|
}
|
|
11604
11705
|
validate(profile) {
|
|
11605
11706
|
if (!profile.model.trim()) {
|
|
11606
|
-
throw new HttpError(400, "
|
|
11707
|
+
throw new HttpError(400, "Pi \u9700\u8981\u586B\u5199\u6A21\u578B\u540D\u79F0\uFF0C\u5426\u5219\u65E0\u6CD5\u751F\u6210 models \u6761\u76EE");
|
|
11708
|
+
}
|
|
11709
|
+
if (!profile.apiKey.trim()) {
|
|
11710
|
+
throw new HttpError(400, "Pi \u9700\u8981\u586B\u5199 API key\uFF0C\u5426\u5219\u6A21\u578B\u4E0D\u4F1A\u51FA\u73B0\u5728 /model \u5217\u8868\u91CC");
|
|
11607
11711
|
}
|
|
11608
11712
|
}
|
|
11609
11713
|
render(profile, current) {
|
|
11610
11714
|
this.validate(profile);
|
|
11611
11715
|
const id = this.providerId(profile);
|
|
11612
|
-
const models =
|
|
11613
|
-
models
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11716
|
+
const models = parseJsonObject(current[MODELS]);
|
|
11717
|
+
const provider = ensureObject(ensureObject(models, "providers"), id);
|
|
11718
|
+
const model = {
|
|
11719
|
+
id: profile.model,
|
|
11720
|
+
name: profile.model,
|
|
11721
|
+
contextWindow: this.numeric(profile.extras.contextWindow, DEFAULT_CONTEXT3),
|
|
11722
|
+
maxTokens: this.numeric(profile.extras.maxTokens, DEFAULT_MAX_TOKENS2)
|
|
11723
|
+
};
|
|
11724
|
+
if (profile.extras.reasoning === "true") {
|
|
11725
|
+
model.reasoning = true;
|
|
11726
|
+
}
|
|
11727
|
+
provider.baseUrl = profile.baseUrl;
|
|
11728
|
+
provider.apiKey = profile.apiKey;
|
|
11729
|
+
provider.api = profile.extras.api || "openai-completions";
|
|
11730
|
+
provider.authHeader = profile.extras.authHeader !== "false";
|
|
11731
|
+
provider.models = [model];
|
|
11732
|
+
const settings = parseJsonObject(current[SETTINGS3]);
|
|
11733
|
+
settings.defaultProvider = id;
|
|
11734
|
+
settings.defaultModel = profile.model;
|
|
11627
11735
|
return {
|
|
11628
|
-
[MODELS]: models
|
|
11629
|
-
[
|
|
11736
|
+
[MODELS]: stringifyJson(models),
|
|
11737
|
+
[SETTINGS3]: stringifyJson(settings)
|
|
11630
11738
|
};
|
|
11631
11739
|
}
|
|
11632
11740
|
revoke(profile, current) {
|
|
@@ -11634,34 +11742,48 @@ class PiAdapter {
|
|
|
11634
11742
|
const rendered = {};
|
|
11635
11743
|
if (current[MODELS] !== undefined) {
|
|
11636
11744
|
try {
|
|
11637
|
-
const models =
|
|
11638
|
-
models.
|
|
11639
|
-
|
|
11745
|
+
const models = parseJsonObject(current[MODELS]);
|
|
11746
|
+
const providers = models.providers;
|
|
11747
|
+
if (isPlainObject(providers)) {
|
|
11748
|
+
delete providers[id];
|
|
11749
|
+
}
|
|
11750
|
+
rendered[MODELS] = stringifyJson(models);
|
|
11640
11751
|
} catch {}
|
|
11641
11752
|
}
|
|
11642
|
-
if (current[
|
|
11753
|
+
if (current[SETTINGS3] !== undefined) {
|
|
11643
11754
|
try {
|
|
11644
|
-
const
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
} else {
|
|
11649
|
-
config.deleteIn(["modelProviderOrder"]);
|
|
11755
|
+
const settings = parseJsonObject(current[SETTINGS3]);
|
|
11756
|
+
if (settings.defaultProvider === id) {
|
|
11757
|
+
delete settings.defaultProvider;
|
|
11758
|
+
delete settings.defaultModel;
|
|
11650
11759
|
}
|
|
11651
|
-
rendered[
|
|
11760
|
+
rendered[SETTINGS3] = stringifyJson(settings);
|
|
11652
11761
|
} catch {}
|
|
11653
11762
|
}
|
|
11654
11763
|
return rendered;
|
|
11655
11764
|
}
|
|
11656
11765
|
backfill(profile, current) {
|
|
11657
11766
|
try {
|
|
11658
|
-
const models =
|
|
11767
|
+
const models = parseJsonObject(current[MODELS]);
|
|
11659
11768
|
const id = this.providerId(profile);
|
|
11660
|
-
const
|
|
11661
|
-
const
|
|
11769
|
+
const providers = models.providers;
|
|
11770
|
+
const provider = isPlainObject(providers) ? providers[id] : undefined;
|
|
11771
|
+
if (!isPlainObject(provider)) {
|
|
11772
|
+
return {};
|
|
11773
|
+
}
|
|
11774
|
+
const firstModel = Array.isArray(provider.models) ? provider.models.find((entry) => isPlainObject(entry)) : undefined;
|
|
11775
|
+
const apiKey = readString(provider, "apiKey");
|
|
11662
11776
|
return {
|
|
11663
|
-
baseUrl:
|
|
11664
|
-
apiKey:
|
|
11777
|
+
baseUrl: readString(provider, "baseUrl") || profile.baseUrl,
|
|
11778
|
+
apiKey: apiKey || profile.apiKey,
|
|
11779
|
+
model: readString(firstModel, "id") || profile.model,
|
|
11780
|
+
extras: {
|
|
11781
|
+
...profile.extras,
|
|
11782
|
+
api: readString(provider, "api") || profile.extras.api || "",
|
|
11783
|
+
contextWindow: valueString2(firstModel?.contextWindow, profile.extras.contextWindow),
|
|
11784
|
+
maxTokens: valueString2(firstModel?.maxTokens, profile.extras.maxTokens),
|
|
11785
|
+
reasoning: firstModel?.reasoning === true ? "true" : profile.extras.reasoning || "false"
|
|
11786
|
+
}
|
|
11665
11787
|
};
|
|
11666
11788
|
} catch {
|
|
11667
11789
|
return {};
|
|
@@ -11670,20 +11792,13 @@ class PiAdapter {
|
|
|
11670
11792
|
providerId(profile) {
|
|
11671
11793
|
return slugify(profile.extras.providerId || profile.name, "provider");
|
|
11672
11794
|
}
|
|
11673
|
-
promote(existing, id) {
|
|
11674
|
-
return [id, ...this.toStringArray(existing).filter((entry) => entry !== id)];
|
|
11675
|
-
}
|
|
11676
|
-
toStringArray(value) {
|
|
11677
|
-
const plain = isYamlNode2(value) ? value.toJSON() : value;
|
|
11678
|
-
return Array.isArray(plain) ? plain.filter((entry) => typeof entry === "string") : [];
|
|
11679
|
-
}
|
|
11680
11795
|
numeric(raw2, fallback) {
|
|
11681
11796
|
const parsed = Number(raw2);
|
|
11682
11797
|
return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : fallback;
|
|
11683
11798
|
}
|
|
11684
11799
|
}
|
|
11685
|
-
function
|
|
11686
|
-
return typeof value === "
|
|
11800
|
+
function valueString2(value, fallback) {
|
|
11801
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : fallback || "";
|
|
11687
11802
|
}
|
|
11688
11803
|
|
|
11689
11804
|
// src/services/adapters/index.ts
|
|
@@ -11785,7 +11900,7 @@ var HARNESS_LABELS = {
|
|
|
11785
11900
|
claude: "Claude Code",
|
|
11786
11901
|
codex: "Codex",
|
|
11787
11902
|
kimi: "Kimi Code",
|
|
11788
|
-
pi: "
|
|
11903
|
+
pi: "Pi",
|
|
11789
11904
|
dsh: "DeepSeek Harness"
|
|
11790
11905
|
};
|
|
11791
11906
|
function isHarnessId(value) {
|
|
@@ -12301,6 +12416,266 @@ async function readBody(read) {
|
|
|
12301
12416
|
});
|
|
12302
12417
|
}
|
|
12303
12418
|
|
|
12419
|
+
// src/services/transfer.ts
|
|
12420
|
+
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, randomBytes as randomBytes4, scryptSync } from "crypto";
|
|
12421
|
+
var FORMAT = "harness-switch-encrypted-export";
|
|
12422
|
+
var VERSION = 1;
|
|
12423
|
+
var MAX_ENCRYPTED_BYTES = 10 * 1024 * 1024;
|
|
12424
|
+
var ITransferService = createDecorator("transferService");
|
|
12425
|
+
var _dec = [
|
|
12426
|
+
inject(IEnvironmentService, IFileService, ICryptoService, IAdapterRegistry, IActivationService)
|
|
12427
|
+
];
|
|
12428
|
+
var _init = __decoratorStart(undefined);
|
|
12429
|
+
|
|
12430
|
+
class TransferService {
|
|
12431
|
+
environment;
|
|
12432
|
+
files;
|
|
12433
|
+
crypto;
|
|
12434
|
+
adapters;
|
|
12435
|
+
activation;
|
|
12436
|
+
constructor(environment, files, crypto2, adapters, activation) {
|
|
12437
|
+
this.environment = environment;
|
|
12438
|
+
this.files = files;
|
|
12439
|
+
this.crypto = crypto2;
|
|
12440
|
+
this.adapters = adapters;
|
|
12441
|
+
this.activation = activation;
|
|
12442
|
+
}
|
|
12443
|
+
exportAll(passphrase) {
|
|
12444
|
+
this.assertPassphrase(passphrase);
|
|
12445
|
+
const store = this.readStore();
|
|
12446
|
+
const profiles = [];
|
|
12447
|
+
for (const harness of HARNESS_IDS) {
|
|
12448
|
+
for (const [name, stored] of Object.entries(store[harness] ?? {})) {
|
|
12449
|
+
profiles.push({
|
|
12450
|
+
harness,
|
|
12451
|
+
name,
|
|
12452
|
+
baseUrl: stored.base_url || "",
|
|
12453
|
+
apiKey: this.crypto.decrypt(stored.api_key),
|
|
12454
|
+
model: stored.model || "",
|
|
12455
|
+
notes: stored.notes || "",
|
|
12456
|
+
extras: stored.extras ?? {},
|
|
12457
|
+
overrides: stored.overrides ?? {}
|
|
12458
|
+
});
|
|
12459
|
+
}
|
|
12460
|
+
}
|
|
12461
|
+
const active = HARNESS_IDS.flatMap((harness) => {
|
|
12462
|
+
const entry = this.activation.getActive(harness);
|
|
12463
|
+
return entry ? [
|
|
12464
|
+
{
|
|
12465
|
+
harness,
|
|
12466
|
+
name: entry.name,
|
|
12467
|
+
official: entry.official === true
|
|
12468
|
+
}
|
|
12469
|
+
] : [];
|
|
12470
|
+
});
|
|
12471
|
+
return encrypt({
|
|
12472
|
+
format: "harness-switch-portable-config",
|
|
12473
|
+
version: VERSION,
|
|
12474
|
+
exportedAt: new Date().toISOString(),
|
|
12475
|
+
profiles,
|
|
12476
|
+
active
|
|
12477
|
+
}, passphrase);
|
|
12478
|
+
}
|
|
12479
|
+
preview(envelope, passphrase) {
|
|
12480
|
+
const payload = this.decrypt(envelope, passphrase);
|
|
12481
|
+
const store = this.readStore();
|
|
12482
|
+
return {
|
|
12483
|
+
exportedAt: payload.exportedAt,
|
|
12484
|
+
profileCount: payload.profiles.length,
|
|
12485
|
+
harnesses: HARNESS_IDS.map((harness) => ({
|
|
12486
|
+
harness,
|
|
12487
|
+
profiles: payload.profiles.filter((profile) => profile.harness === harness).length
|
|
12488
|
+
})).filter((item) => item.profiles > 0),
|
|
12489
|
+
conflicts: payload.profiles.filter((profile) => store[profile.harness]?.[profile.name] !== undefined).map(({ harness, name }) => ({ harness, name })),
|
|
12490
|
+
activeCount: payload.active.length
|
|
12491
|
+
};
|
|
12492
|
+
}
|
|
12493
|
+
importAll(envelope, passphrase, conflictPolicy, restoreActive) {
|
|
12494
|
+
if (conflictPolicy !== "skip" && conflictPolicy !== "overwrite") {
|
|
12495
|
+
throw new HttpError(400, "invalid conflict policy");
|
|
12496
|
+
}
|
|
12497
|
+
const payload = this.decrypt(envelope, passphrase);
|
|
12498
|
+
const store = structuredClone(this.readStore());
|
|
12499
|
+
let imported = 0;
|
|
12500
|
+
let overwritten = 0;
|
|
12501
|
+
let skipped = 0;
|
|
12502
|
+
for (const profile of payload.profiles) {
|
|
12503
|
+
this.validateProfile(profile);
|
|
12504
|
+
store[profile.harness] ||= {};
|
|
12505
|
+
const exists = store[profile.harness][profile.name] !== undefined;
|
|
12506
|
+
if (exists && conflictPolicy === "skip") {
|
|
12507
|
+
skipped++;
|
|
12508
|
+
continue;
|
|
12509
|
+
}
|
|
12510
|
+
store[profile.harness][profile.name] = this.toStored(profile);
|
|
12511
|
+
if (exists) {
|
|
12512
|
+
overwritten++;
|
|
12513
|
+
} else {
|
|
12514
|
+
imported++;
|
|
12515
|
+
}
|
|
12516
|
+
}
|
|
12517
|
+
this.files.writeJson(this.environment.files.profiles, store);
|
|
12518
|
+
const warnings = [];
|
|
12519
|
+
let activeRestored = 0;
|
|
12520
|
+
if (restoreActive) {
|
|
12521
|
+
for (const active of payload.active) {
|
|
12522
|
+
try {
|
|
12523
|
+
if (active.official) {
|
|
12524
|
+
this.activation.activateOfficial(active.harness);
|
|
12525
|
+
} else if (store[active.harness]?.[active.name]) {
|
|
12526
|
+
this.activation.activate(active.harness, active.name);
|
|
12527
|
+
} else {
|
|
12528
|
+
throw new Error("\u5BF9\u5E94\u914D\u7F6E\u4E0D\u5B58\u5728");
|
|
12529
|
+
}
|
|
12530
|
+
activeRestored++;
|
|
12531
|
+
} catch (error) {
|
|
12532
|
+
warnings.push(`${active.harness}/${active.name} \u672A\u80FD\u6062\u590D\u6FC0\u6D3B\u72B6\u6001\uFF1A${error.message}`);
|
|
12533
|
+
}
|
|
12534
|
+
}
|
|
12535
|
+
}
|
|
12536
|
+
return { ok: true, imported, overwritten, skipped, activeRestored, warnings };
|
|
12537
|
+
}
|
|
12538
|
+
decrypt(envelope, passphrase) {
|
|
12539
|
+
this.assertPassphrase(passphrase);
|
|
12540
|
+
const payload = decrypt(envelope, passphrase);
|
|
12541
|
+
if (payload.format !== "harness-switch-portable-config" || payload.version !== VERSION || !Array.isArray(payload.profiles) || !Array.isArray(payload.active) || typeof payload.exportedAt !== "string") {
|
|
12542
|
+
throw new HttpError(400, "\u4E0D\u652F\u6301\u7684\u5BFC\u51FA\u6587\u4EF6\u683C\u5F0F");
|
|
12543
|
+
}
|
|
12544
|
+
if (payload.profiles.length > 1e4) {
|
|
12545
|
+
throw new HttpError(400, "\u5BFC\u51FA\u6587\u4EF6\u5305\u542B\u8FC7\u591A\u914D\u7F6E");
|
|
12546
|
+
}
|
|
12547
|
+
for (const profile of payload.profiles) {
|
|
12548
|
+
if (!isPortableProfile(profile)) {
|
|
12549
|
+
throw new HttpError(400, "\u5BFC\u51FA\u6587\u4EF6\u4E2D\u7684\u914D\u7F6E\u6570\u636E\u65E0\u6548");
|
|
12550
|
+
}
|
|
12551
|
+
}
|
|
12552
|
+
for (const active of payload.active) {
|
|
12553
|
+
if (!isPortableActive(active)) {
|
|
12554
|
+
throw new HttpError(400, "\u5BFC\u51FA\u6587\u4EF6\u4E2D\u7684\u6FC0\u6D3B\u72B6\u6001\u65E0\u6548");
|
|
12555
|
+
}
|
|
12556
|
+
}
|
|
12557
|
+
return payload;
|
|
12558
|
+
}
|
|
12559
|
+
validateProfile(profile) {
|
|
12560
|
+
if (!profile.name || profile.name.length > 120 || /[\\/]/.test(profile.name)) {
|
|
12561
|
+
throw new HttpError(400, "\u5BFC\u51FA\u6587\u4EF6\u5305\u542B\u65E0\u6548\u7684\u914D\u7F6E\u540D\u79F0");
|
|
12562
|
+
}
|
|
12563
|
+
this.adapters.get(profile.harness).validate?.({
|
|
12564
|
+
name: profile.name,
|
|
12565
|
+
baseUrl: profile.baseUrl,
|
|
12566
|
+
apiKey: profile.apiKey,
|
|
12567
|
+
model: profile.model,
|
|
12568
|
+
extras: profile.extras
|
|
12569
|
+
});
|
|
12570
|
+
}
|
|
12571
|
+
toStored(profile) {
|
|
12572
|
+
return {
|
|
12573
|
+
base_url: profile.baseUrl,
|
|
12574
|
+
api_key: this.crypto.encrypt(profile.apiKey),
|
|
12575
|
+
model: profile.model,
|
|
12576
|
+
notes: profile.notes,
|
|
12577
|
+
extras: profile.extras,
|
|
12578
|
+
overrides: profile.overrides,
|
|
12579
|
+
updated_at: new Date().toISOString()
|
|
12580
|
+
};
|
|
12581
|
+
}
|
|
12582
|
+
readStore() {
|
|
12583
|
+
return this.files.readJson(this.environment.files.profiles, {});
|
|
12584
|
+
}
|
|
12585
|
+
assertPassphrase(passphrase) {
|
|
12586
|
+
if (passphrase.length < 8) {
|
|
12587
|
+
throw new HttpError(400, "\u8FC1\u79FB\u5BC6\u7801\u81F3\u5C11\u9700\u8981 8 \u4E2A\u5B57\u7B26");
|
|
12588
|
+
}
|
|
12589
|
+
}
|
|
12590
|
+
}
|
|
12591
|
+
TransferService = __decorateElement(_init, 0, "TransferService", _dec, TransferService);
|
|
12592
|
+
__runInitializers(_init, 1, TransferService);
|
|
12593
|
+
__decoratorMetadata(_init, TransferService);
|
|
12594
|
+
let _TransferService = TransferService;
|
|
12595
|
+
function encrypt(payload, passphrase) {
|
|
12596
|
+
const salt = randomBytes4(16);
|
|
12597
|
+
const iv = randomBytes4(12);
|
|
12598
|
+
const key = scryptSync(passphrase, salt, 32);
|
|
12599
|
+
const cipher = createCipheriv2("aes-256-gcm", key, iv);
|
|
12600
|
+
const data = Buffer.concat([cipher.update(JSON.stringify(payload), "utf8"), cipher.final()]);
|
|
12601
|
+
return {
|
|
12602
|
+
format: FORMAT,
|
|
12603
|
+
version: VERSION,
|
|
12604
|
+
kdf: { name: "scrypt", salt: salt.toString("base64url") },
|
|
12605
|
+
cipher: {
|
|
12606
|
+
name: "aes-256-gcm",
|
|
12607
|
+
iv: iv.toString("base64url"),
|
|
12608
|
+
tag: cipher.getAuthTag().toString("base64url"),
|
|
12609
|
+
data: data.toString("base64url")
|
|
12610
|
+
}
|
|
12611
|
+
};
|
|
12612
|
+
}
|
|
12613
|
+
function decrypt(envelope, passphrase) {
|
|
12614
|
+
try {
|
|
12615
|
+
if (envelope?.format !== FORMAT || envelope.version !== VERSION || envelope.kdf?.name !== "scrypt" || envelope.cipher?.name !== "aes-256-gcm" || typeof envelope.kdf.salt !== "string" || typeof envelope.cipher.iv !== "string" || typeof envelope.cipher.tag !== "string" || typeof envelope.cipher.data !== "string" || envelope.cipher.data.length > MAX_ENCRYPTED_BYTES) {
|
|
12616
|
+
throw new Error("invalid envelope");
|
|
12617
|
+
}
|
|
12618
|
+
const salt = Buffer.from(envelope.kdf.salt, "base64url");
|
|
12619
|
+
const key = scryptSync(passphrase, salt, 32);
|
|
12620
|
+
const decipher = createDecipheriv2("aes-256-gcm", key, Buffer.from(envelope.cipher.iv, "base64url"));
|
|
12621
|
+
decipher.setAuthTag(Buffer.from(envelope.cipher.tag, "base64url"));
|
|
12622
|
+
const plain = Buffer.concat([
|
|
12623
|
+
decipher.update(Buffer.from(envelope.cipher.data, "base64url")),
|
|
12624
|
+
decipher.final()
|
|
12625
|
+
]).toString("utf8");
|
|
12626
|
+
return JSON.parse(plain);
|
|
12627
|
+
} catch {
|
|
12628
|
+
throw new HttpError(400, "\u8FC1\u79FB\u5BC6\u7801\u9519\u8BEF\u6216\u5BFC\u51FA\u6587\u4EF6\u5DF2\u635F\u574F");
|
|
12629
|
+
}
|
|
12630
|
+
}
|
|
12631
|
+
function isStringRecord(value) {
|
|
12632
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((item) => typeof item === "string");
|
|
12633
|
+
}
|
|
12634
|
+
function isPortableProfile(value) {
|
|
12635
|
+
if (typeof value !== "object" || value === null) {
|
|
12636
|
+
return false;
|
|
12637
|
+
}
|
|
12638
|
+
const profile = value;
|
|
12639
|
+
return typeof profile.harness === "string" && isHarnessId(profile.harness) && typeof profile.name === "string" && typeof profile.baseUrl === "string" && typeof profile.apiKey === "string" && typeof profile.model === "string" && typeof profile.notes === "string" && isStringRecord(profile.extras) && isStringRecord(profile.overrides);
|
|
12640
|
+
}
|
|
12641
|
+
function isPortableActive(value) {
|
|
12642
|
+
if (typeof value !== "object" || value === null) {
|
|
12643
|
+
return false;
|
|
12644
|
+
}
|
|
12645
|
+
const active = value;
|
|
12646
|
+
return typeof active.harness === "string" && isHarnessId(active.harness) && typeof active.name === "string" && typeof active.official === "boolean";
|
|
12647
|
+
}
|
|
12648
|
+
|
|
12649
|
+
// src/http/routes/transfer.ts
|
|
12650
|
+
function createTransferRoutes(services) {
|
|
12651
|
+
const app = new Hono2;
|
|
12652
|
+
const transfer = services.get(ITransferService);
|
|
12653
|
+
app.post("/export", async (c) => {
|
|
12654
|
+
const body = await readBody2(c.req.json.bind(c.req));
|
|
12655
|
+
return c.json(transfer.exportAll(String(body.passphrase ?? "")));
|
|
12656
|
+
});
|
|
12657
|
+
app.post("/preview", async (c) => {
|
|
12658
|
+
const body = await readBody2(c.req.json.bind(c.req));
|
|
12659
|
+
return c.json(transfer.preview(requireEnvelope(body.envelope), String(body.passphrase ?? "")));
|
|
12660
|
+
});
|
|
12661
|
+
app.post("/import", async (c) => {
|
|
12662
|
+
const body = await readBody2(c.req.json.bind(c.req));
|
|
12663
|
+
return c.json(transfer.importAll(requireEnvelope(body.envelope), String(body.passphrase ?? ""), body.conflictPolicy ?? "skip", body.restoreActive === true));
|
|
12664
|
+
});
|
|
12665
|
+
return app;
|
|
12666
|
+
}
|
|
12667
|
+
function requireEnvelope(envelope) {
|
|
12668
|
+
if (!envelope || typeof envelope !== "object") {
|
|
12669
|
+
throw new HttpError(400, "\u7F3A\u5C11\u6709\u6548\u7684\u5BFC\u51FA\u6587\u4EF6");
|
|
12670
|
+
}
|
|
12671
|
+
return envelope;
|
|
12672
|
+
}
|
|
12673
|
+
async function readBody2(read) {
|
|
12674
|
+
return read().catch(() => {
|
|
12675
|
+
throw new HttpError(400, "invalid json");
|
|
12676
|
+
});
|
|
12677
|
+
}
|
|
12678
|
+
|
|
12304
12679
|
// src/app.ts
|
|
12305
12680
|
function createApp(services) {
|
|
12306
12681
|
const app = new Hono2;
|
|
@@ -12317,6 +12692,8 @@ function createApp(services) {
|
|
|
12317
12692
|
api.use("/backups/*", createAuthGuard(services));
|
|
12318
12693
|
api.use("/backups", createAuthGuard(services));
|
|
12319
12694
|
api.route("/backups", createBackupRoutes(services));
|
|
12695
|
+
api.use("/transfer/*", createAuthGuard(services));
|
|
12696
|
+
api.route("/transfer", createTransferRoutes(services));
|
|
12320
12697
|
app.route("/api", api);
|
|
12321
12698
|
const publicDir = environment.publicDir;
|
|
12322
12699
|
if (existsSync3(publicDir)) {
|
|
@@ -12331,6 +12708,7 @@ function createApp(services) {
|
|
|
12331
12708
|
}
|
|
12332
12709
|
const index = join9(publicDir, "index.html");
|
|
12333
12710
|
if (existsSync3(index)) {
|
|
12711
|
+
c.header("Cache-Control", "no-store");
|
|
12334
12712
|
return c.html(await Bun.file(index).text());
|
|
12335
12713
|
}
|
|
12336
12714
|
return c.text("frontend not built", 503);
|
|
@@ -12361,6 +12739,7 @@ function createServices() {
|
|
|
12361
12739
|
collection.set(ILiveWriteService, new SyncDescriptor(LiveWriteService));
|
|
12362
12740
|
collection.set(IProfileService, new SyncDescriptor(ProfileService));
|
|
12363
12741
|
collection.set(IActivationService, new SyncDescriptor(ActivationService));
|
|
12742
|
+
collection.set(ITransferService, new SyncDescriptor(TransferService));
|
|
12364
12743
|
return new InstantiationService(collection);
|
|
12365
12744
|
}
|
|
12366
12745
|
|