clikcode 1.0.4 → 1.0.5
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 +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +494 -112923
- package/dist/computer-tools.js +36642 -21259
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
TooLarge,
|
|
5
|
+
fetchAsTab
|
|
6
|
+
} from "./chunk-FFGU4GCC.js";
|
|
7
|
+
import "./chunk-O7BNJIXU.js";
|
|
8
|
+
import "./chunk-YMCH3L2S.js";
|
|
9
|
+
import "./chunk-5SM5UAWN.js";
|
|
10
|
+
import "./chunk-PAXYQZH7.js";
|
|
11
|
+
import "./chunk-4L2ZZM4Q.js";
|
|
12
|
+
import "./chunk-F6F47QAY.js";
|
|
13
|
+
import "./chunk-RDDWQBEM.js";
|
|
14
|
+
import "./chunk-MPAJ446F.js";
|
|
15
|
+
import "./chunk-CBANJFBO.js";
|
|
16
|
+
import "./chunk-PWXII6HF.js";
|
|
17
|
+
export {
|
|
18
|
+
TooLarge,
|
|
19
|
+
fetchAsTab
|
|
20
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
userMcpServers
|
|
5
|
+
} from "./chunk-UVXNIUTN.js";
|
|
6
|
+
import {
|
|
7
|
+
BUILT_IN_MCP_NAME
|
|
8
|
+
} from "./chunk-EOBTJV32.js";
|
|
9
|
+
import {
|
|
10
|
+
forgetMcpOAuth,
|
|
11
|
+
isRemoteTarget,
|
|
12
|
+
mcpOAuthState,
|
|
13
|
+
mcpServerNeedsSignIn,
|
|
14
|
+
recordSharedMcpServer,
|
|
15
|
+
removeMcpConfigEntry,
|
|
16
|
+
signInMcpServer
|
|
17
|
+
} from "./chunk-UA5K2BTI.js";
|
|
18
|
+
import {
|
|
19
|
+
hasLocalDisplay,
|
|
20
|
+
loginLinkLine,
|
|
21
|
+
loginUrlNotice,
|
|
22
|
+
openLoginUrl
|
|
23
|
+
} from "./chunk-RE4TGORR.js";
|
|
24
|
+
import {
|
|
25
|
+
MCP_SERVERS_KEY,
|
|
26
|
+
loadMcpServers,
|
|
27
|
+
mcpConfigFilePath,
|
|
28
|
+
writeMcpOAuthConfig
|
|
29
|
+
} from "./chunk-DQYVQ2N7.js";
|
|
30
|
+
import {
|
|
31
|
+
loginPortForwardHint
|
|
32
|
+
} from "./chunk-4AQ5NINV.js";
|
|
33
|
+
import {
|
|
34
|
+
emitResult
|
|
35
|
+
} from "./chunk-JGIWATSG.js";
|
|
36
|
+
import {
|
|
37
|
+
isJsonDefaultMode
|
|
38
|
+
} from "./chunk-5B6TVO4A.js";
|
|
39
|
+
import {
|
|
40
|
+
source_default
|
|
41
|
+
} from "./chunk-LVRRWP4W.js";
|
|
42
|
+
import {
|
|
43
|
+
stateDirectory
|
|
44
|
+
} from "./chunk-MPAJ446F.js";
|
|
45
|
+
|
|
46
|
+
// src/commands/mcp.ts
|
|
47
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
48
|
+
import { createInterface } from "node:readline/promises";
|
|
49
|
+
async function mcpAdd(name, target, args, options = {}) {
|
|
50
|
+
const entry = { name, target, ...args.length ? { args } : {} };
|
|
51
|
+
const port = options.callbackPort === void 0 ? void 0 : Number(options.callbackPort);
|
|
52
|
+
if (port !== void 0 && !(Number.isInteger(port) && port > 0 && port < 65536)) throw new Error(`--callback-port must be a port number, not ${options.callbackPort}`);
|
|
53
|
+
const oauth = {
|
|
54
|
+
...options.clientId?.trim() ? { clientId: options.clientId.trim() } : {},
|
|
55
|
+
...port !== void 0 ? { callbackPort: port } : {},
|
|
56
|
+
...options.scope?.trim() ? { scope: options.scope.trim() } : {}
|
|
57
|
+
};
|
|
58
|
+
const signsIn = Object.keys(oauth).length > 0;
|
|
59
|
+
if (signsIn && !isRemoteTarget(target)) throw new Error("--client-id, --callback-port and --scope apply to a remote (URL) server only");
|
|
60
|
+
await recordSharedMcpServer(entry);
|
|
61
|
+
if (signsIn) await writeMcpOAuthConfig(stateDirectory(), name, oauth);
|
|
62
|
+
if (isJsonDefaultMode()) return emitResult({ mcp: "add", server: { ...entry, ...signsIn ? { oauth } : {} }, recorded: "clikcode" });
|
|
63
|
+
output.write(signsIn ? `
|
|
64
|
+
${source_default.green("\u2713")} ${source_default.bold(name)} recorded for ClikCode's own agent. Sign in with ${source_default.bold(`clikcode mcp login ${name}`)}.
|
|
65
|
+
|
|
66
|
+
` : `
|
|
67
|
+
${source_default.green("\u2713")} ${source_default.bold(name)} recorded for ClikCode's own agent.
|
|
68
|
+
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
async function mcpSignInStates(stateDir, specs) {
|
|
72
|
+
return new Map(await Promise.all(specs.flatMap((spec) => spec.transport === "stdio" ? [] : [(async () => {
|
|
73
|
+
const own = await mcpOAuthState(stateDir, spec);
|
|
74
|
+
if (own !== "none") return [spec.name, own];
|
|
75
|
+
const answer = await mcpServerNeedsSignIn({ name: spec.name, target: spec.url, headers: spec.headers }, { stateDir });
|
|
76
|
+
return [spec.name, answer === "sign-in" ? "needs-sign-in" : answer];
|
|
77
|
+
})()])));
|
|
78
|
+
}
|
|
79
|
+
var SIGN_IN_LABEL = {
|
|
80
|
+
"signed-in": source_default.green("signed in"),
|
|
81
|
+
"needs-sign-in": source_default.yellow("needs sign-in"),
|
|
82
|
+
open: "",
|
|
83
|
+
unknown: source_default.dim("not reachable")
|
|
84
|
+
};
|
|
85
|
+
function mcpSignInUiFor(screen) {
|
|
86
|
+
return { show: (link) => screen.show(link), ask: (prompt) => screen.ask(prompt, false, false, true), signal: screen.signal };
|
|
87
|
+
}
|
|
88
|
+
function terminalSignInUi(name) {
|
|
89
|
+
const cancel = new AbortController();
|
|
90
|
+
let opened = false;
|
|
91
|
+
const onSigint = () => cancel.abort();
|
|
92
|
+
process.once("SIGINT", onSigint);
|
|
93
|
+
return {
|
|
94
|
+
signal: cancel.signal,
|
|
95
|
+
show: (link) => {
|
|
96
|
+
const local = hasLocalDisplay();
|
|
97
|
+
if (local && !opened) {
|
|
98
|
+
opened = true;
|
|
99
|
+
openLoginUrl(link.url);
|
|
100
|
+
}
|
|
101
|
+
output.write(`${local ? "" : loginUrlNotice(link.url).clipboard}
|
|
102
|
+
${source_default.bold(`Sign in to ${name}`)}
|
|
103
|
+
${loginLinkLine(link.url)}
|
|
104
|
+
${loginPortForwardHint(link.url) ? `${loginPortForwardHint(link.url)}
|
|
105
|
+
` : ""}${source_default.dim(local ? "opened in your browser" : "full link copied to clipboard")}
|
|
106
|
+
`);
|
|
107
|
+
},
|
|
108
|
+
ask: async (prompt, signal) => {
|
|
109
|
+
const reader = createInterface({ input, output });
|
|
110
|
+
reader.on("SIGINT", () => cancel.abort());
|
|
111
|
+
try {
|
|
112
|
+
return await reader.question(`${prompt}: `, { signal });
|
|
113
|
+
} finally {
|
|
114
|
+
reader.close();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
done: () => {
|
|
118
|
+
process.off("SIGINT", onSigint);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function loginMcpServer(name, ui, stateDir = stateDirectory()) {
|
|
123
|
+
const { servers } = await userMcpServers(stateDir);
|
|
124
|
+
const spec = servers.find((server) => server.name === name);
|
|
125
|
+
if (!spec) throw new Error(`${name} is not recorded in ClikCode; add it with \`clikcode mcp add ${name} <url>\``);
|
|
126
|
+
if (spec.transport === "stdio") throw new Error(`${name} is a local server; there is nothing to sign in to`);
|
|
127
|
+
await signInMcpServer({ stateDir, spec, ui });
|
|
128
|
+
}
|
|
129
|
+
async function mcpLogin(name) {
|
|
130
|
+
const ui = terminalSignInUi(name);
|
|
131
|
+
try {
|
|
132
|
+
await loginMcpServer(name, ui);
|
|
133
|
+
} finally {
|
|
134
|
+
ui.done();
|
|
135
|
+
}
|
|
136
|
+
if (isJsonDefaultMode()) return emitResult({ mcp: "login", name, signedIn: true });
|
|
137
|
+
output.write(`
|
|
138
|
+
${source_default.green("\u2713")} Signed in to ${source_default.bold(name)}. ClikCode's agent uses it from its next turn.
|
|
139
|
+
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
async function mcpLogout(name) {
|
|
143
|
+
const forgotten = await forgetMcpOAuth(stateDirectory(), name);
|
|
144
|
+
if (isJsonDefaultMode()) return emitResult({ mcp: "logout", name, signedOut: forgotten });
|
|
145
|
+
output.write(forgotten ? `
|
|
146
|
+
${source_default.green("\u2713")} Signed out of ${source_default.bold(name)}.
|
|
147
|
+
|
|
148
|
+
` : `
|
|
149
|
+
${source_default.dim(`ClikCode holds no sign-in for ${name}.`)}
|
|
150
|
+
|
|
151
|
+
`);
|
|
152
|
+
}
|
|
153
|
+
async function mcpServersText(stateDir = stateDirectory()) {
|
|
154
|
+
const { servers, problem } = await userMcpServers(stateDir);
|
|
155
|
+
const states = await mcpSignInStates(stateDir, servers);
|
|
156
|
+
const lines = servers.map((spec) => {
|
|
157
|
+
const state = states.get(spec.name);
|
|
158
|
+
const where = spec.transport === "stdio" ? [spec.command, ...spec.args].join(" ") : spec.url;
|
|
159
|
+
const label = state ? SIGN_IN_LABEL[state] : "";
|
|
160
|
+
return `${source_default.bold(spec.name.padEnd(24))}${source_default.dim(where)}${label ? ` ${label}` : ""}`;
|
|
161
|
+
});
|
|
162
|
+
if (!servers.length) lines.push(source_default.dim("none -- add one with `clikcode mcp add <name> <command-or-url>`"));
|
|
163
|
+
if (problem) lines.push(source_default.yellow(problem));
|
|
164
|
+
if ([...states.values()].includes("needs-sign-in")) lines.push("", source_default.dim("Sign in with /mcp login <name> (or clikcode mcp login <name>); /mcp logout <name> signs out."));
|
|
165
|
+
return lines.join("\n");
|
|
166
|
+
}
|
|
167
|
+
async function mcpList() {
|
|
168
|
+
const stateDir = stateDirectory();
|
|
169
|
+
const { servers, problem } = await loadMcpServers(stateDir);
|
|
170
|
+
const states = await mcpSignInStates(stateDir, servers);
|
|
171
|
+
if (isJsonDefaultMode()) {
|
|
172
|
+
return emitResult({
|
|
173
|
+
mcp: "list",
|
|
174
|
+
builtIn: [{ name: BUILT_IN_MCP_NAME, target: "clikcode", args: ["mcp-serve"], tools: ["browser_use", "account_use", "computer_use"] }],
|
|
175
|
+
servers: servers.map((spec) => ({
|
|
176
|
+
name: spec.name,
|
|
177
|
+
...spec.transport === "stdio" ? { target: spec.command, args: spec.args } : { target: spec.url },
|
|
178
|
+
...states.has(spec.name) ? { signIn: states.get(spec.name) } : {}
|
|
179
|
+
})),
|
|
180
|
+
...problem ? { problem } : {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
output.write(`
|
|
184
|
+
${source_default.bold("Built in, given to every harness session")} ${source_default.dim("(turn off with `clikcode computer off`)")}
|
|
185
|
+
`);
|
|
186
|
+
output.write(` ${source_default.bold(BUILT_IN_MCP_NAME.padEnd(24))}${source_default.dim("clikcode mcp-serve: browser_use, account_use, computer_use")}
|
|
187
|
+
`);
|
|
188
|
+
output.write(`
|
|
189
|
+
${source_default.bold("MCP servers recorded for ClikCode's own agent")}
|
|
190
|
+
`);
|
|
191
|
+
for (const spec of servers) {
|
|
192
|
+
const state = states.get(spec.name);
|
|
193
|
+
const label = state ? SIGN_IN_LABEL[state] : "";
|
|
194
|
+
const where = spec.transport === "stdio" ? [spec.command, ...spec.args].join(" ") : spec.url;
|
|
195
|
+
output.write(` ${source_default.bold(spec.name.padEnd(24))}${source_default.dim(where)}${label ? ` ${label}` : ""}
|
|
196
|
+
`);
|
|
197
|
+
if (state === "needs-sign-in") output.write(` ${"".padEnd(24)}${source_default.dim(`sign in: clikcode mcp login ${spec.name}`)}
|
|
198
|
+
`);
|
|
199
|
+
}
|
|
200
|
+
if (!servers.length) output.write(` ${source_default.dim("none -- add one with `mcp add <name> <command-or-url>`")}
|
|
201
|
+
`);
|
|
202
|
+
if (problem) output.write(` ${source_default.yellow(problem)}
|
|
203
|
+
`);
|
|
204
|
+
output.write("\n");
|
|
205
|
+
}
|
|
206
|
+
async function mcpRemove(name) {
|
|
207
|
+
const stateDir = stateDirectory();
|
|
208
|
+
const removed = await removeMcpConfigEntry(mcpConfigFilePath(stateDir), MCP_SERVERS_KEY, name);
|
|
209
|
+
const forgotten = await forgetMcpOAuth(stateDir, name).catch(() => false);
|
|
210
|
+
if (isJsonDefaultMode()) emitResult({ mcp: "remove", name, removed });
|
|
211
|
+
else if (!removed && !forgotten) output.write(`
|
|
212
|
+
${source_default.dim(`${name} is not recorded in ClikCode.`)}
|
|
213
|
+
|
|
214
|
+
`);
|
|
215
|
+
else output.write(`
|
|
216
|
+
${source_default.green("\u2713")} ${source_default.bold(name)} ${removed ? "removed from ClikCode" : "was not in ClikCode's list"}.
|
|
217
|
+
|
|
218
|
+
`);
|
|
219
|
+
if (!removed && !forgotten) process.exitCode = 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
mcpAdd,
|
|
224
|
+
mcpSignInUiFor,
|
|
225
|
+
loginMcpServer,
|
|
226
|
+
mcpLogin,
|
|
227
|
+
mcpLogout,
|
|
228
|
+
mcpServersText,
|
|
229
|
+
mcpList,
|
|
230
|
+
mcpRemove
|
|
231
|
+
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
quotaScopeForModel,
|
|
5
|
+
recordQuotaRefusal
|
|
6
|
+
} from "./chunk-7TSQLONI.js";
|
|
7
|
+
import {
|
|
8
|
+
accountSwitchNotice,
|
|
9
|
+
accountVerification,
|
|
10
|
+
verificationNotice
|
|
11
|
+
} from "./chunk-2YPAPAR3.js";
|
|
12
|
+
import {
|
|
13
|
+
isTurnCancelled,
|
|
14
|
+
turnCancelledError
|
|
15
|
+
} from "./chunk-4LPDG57B.js";
|
|
16
|
+
import {
|
|
17
|
+
USAGE_RECHECK_MS,
|
|
18
|
+
accountCanTakeTurn,
|
|
19
|
+
modelQuotaRefusalHolds,
|
|
20
|
+
quotaRefusalHolds,
|
|
21
|
+
usageReadingIsCurrent,
|
|
22
|
+
usageWindowMinutes,
|
|
23
|
+
vendorWindows,
|
|
24
|
+
windowSpent
|
|
25
|
+
} from "./chunk-XWAC3MKW.js";
|
|
26
|
+
import {
|
|
27
|
+
readState
|
|
28
|
+
} from "./chunk-MXS6S2PY.js";
|
|
29
|
+
import {
|
|
30
|
+
refreshAccount
|
|
31
|
+
} from "./chunk-BGEMY2JJ.js";
|
|
32
|
+
import {
|
|
33
|
+
loadIndex
|
|
34
|
+
} from "./chunk-XCKQ5BM2.js";
|
|
35
|
+
import {
|
|
36
|
+
isDirectModelProvider
|
|
37
|
+
} from "./chunk-KYUHIFP3.js";
|
|
38
|
+
import {
|
|
39
|
+
quotaResetPhrase
|
|
40
|
+
} from "./chunk-EE4B6A7W.js";
|
|
41
|
+
import {
|
|
42
|
+
source_default
|
|
43
|
+
} from "./chunk-LVRRWP4W.js";
|
|
44
|
+
import {
|
|
45
|
+
quiet
|
|
46
|
+
} from "./chunk-RDDWQBEM.js";
|
|
47
|
+
|
|
48
|
+
// src/turn/usage-exhausted.ts
|
|
49
|
+
function nextQuotaReset(accounts, now = Date.now()) {
|
|
50
|
+
const resets = accounts.flatMap((account) => [
|
|
51
|
+
...vendorWindows(account).filter((window) => windowSpent(window) && window.resetsAt !== void 0).map((window) => window.resetsAt),
|
|
52
|
+
...account.quotaState === "exhausted" && account.quotaRetryAt ? [account.quotaRetryAt] : []
|
|
53
|
+
]).map((at) => Date.parse(at)).filter((at) => Number.isFinite(at) && at > now).sort((left, right) => left - right);
|
|
54
|
+
return resets.length ? new Date(resets[0]) : void 0;
|
|
55
|
+
}
|
|
56
|
+
function usageExhaustedMessage() {
|
|
57
|
+
return "All accounts exhausted";
|
|
58
|
+
}
|
|
59
|
+
function isUsageExhaustedMessage(message) {
|
|
60
|
+
return /^(?:All accounts exhausted|Usage Exhausted|Credits Exhausted)\b/.test(message.trim());
|
|
61
|
+
}
|
|
62
|
+
var RESUME_MAX_SLEEP_MS = 10 * 6e4;
|
|
63
|
+
var RESUME_RECHECK_MS = 6e4;
|
|
64
|
+
var RESUME_GRACE_MS = 60 * 6e4;
|
|
65
|
+
function resumeStep(resumeAt, accounts, provider, now = Date.now(), matchesTransport = () => true) {
|
|
66
|
+
const at = Date.parse(resumeAt.at);
|
|
67
|
+
if (!Number.isFinite(at)) return "give-up";
|
|
68
|
+
if (now < at) return { wait: Math.min(at - now, RESUME_MAX_SLEEP_MS) };
|
|
69
|
+
if (accounts.some((account) => account.provider === provider && matchesTransport(account) && accountCanTakeTurn(account, now))) return "send";
|
|
70
|
+
return now - at >= RESUME_GRACE_MS ? "give-up" : { wait: RESUME_RECHECK_MS };
|
|
71
|
+
}
|
|
72
|
+
function resumeWaitLabel(resumeAt, now = Date.now()) {
|
|
73
|
+
return `waiting for reset \xB7 ${quotaResetPhrase(new Date(resumeAt.at), now)}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/turn/account-burn.ts
|
|
77
|
+
function readingIsFresh(account, now) {
|
|
78
|
+
const at = Date.parse(account.usage?.at ?? "");
|
|
79
|
+
const windows = vendorWindows(account).filter((window) => !window.advisory);
|
|
80
|
+
return Number.isFinite(at) && now - at <= USAGE_RECHECK_MS && windows.length > 0 && usageReadingIsCurrent({ windows }, now);
|
|
81
|
+
}
|
|
82
|
+
function burnPerTurn(account, window, invocations, now) {
|
|
83
|
+
const minutes = usageWindowMinutes(window.name);
|
|
84
|
+
const resets = Date.parse(window.resetsAt ?? "");
|
|
85
|
+
if (!minutes || !Number.isFinite(resets)) return void 0;
|
|
86
|
+
const opened = resets - minutes * 6e4;
|
|
87
|
+
const turns = invocations.filter((item) => item.accountId === account.id && item.kind !== "maintenance" && Date.parse(item.at) >= opened && Date.parse(item.at) <= now).length;
|
|
88
|
+
if (window.usedPct <= 0) return 0;
|
|
89
|
+
return turns > 0 ? window.usedPct / turns : void 0;
|
|
90
|
+
}
|
|
91
|
+
function currentRoom(account, now) {
|
|
92
|
+
if (!readingIsFresh(account, now)) return void 0;
|
|
93
|
+
return Math.min(...vendorWindows(account).filter((window) => !window.advisory).map((window) => Math.max(0, 100 - window.usedPct)));
|
|
94
|
+
}
|
|
95
|
+
function costOf(account, invocations, turns, now) {
|
|
96
|
+
let cost = 0;
|
|
97
|
+
for (const window of vendorWindows(account).filter((item) => !item.advisory)) {
|
|
98
|
+
const burn = burnPerTurn(account, window, invocations, now);
|
|
99
|
+
if (burn === void 0) return void 0;
|
|
100
|
+
cost = Math.max(cost, burn * turns);
|
|
101
|
+
}
|
|
102
|
+
return cost;
|
|
103
|
+
}
|
|
104
|
+
function earlyMoveTarget(current, candidates, invocations, options) {
|
|
105
|
+
const { now, turns } = options;
|
|
106
|
+
const room = currentRoom(current, now);
|
|
107
|
+
const cost = costOf(current, invocations, turns, now);
|
|
108
|
+
if (room === void 0 || cost === void 0 || room >= cost) return void 0;
|
|
109
|
+
return candidates.find((candidate) => (currentRoom(candidate, now) ?? Number.NEGATIVE_INFINITY) >= room + cost);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/turn/account-routing.ts
|
|
113
|
+
function turnBackendForAccount(account) {
|
|
114
|
+
return account.authKind === "api-key" && isDirectModelProvider(account.provider) ? "direct" : "vendor";
|
|
115
|
+
}
|
|
116
|
+
function matchesDirectTurnModel(account, model) {
|
|
117
|
+
return turnBackendForAccount(account) === "direct" && account.models.includes(model);
|
|
118
|
+
}
|
|
119
|
+
function matchesVendorTurn(account) {
|
|
120
|
+
return turnBackendForAccount(account) === "vendor";
|
|
121
|
+
}
|
|
122
|
+
function providerHasAccountForTurn(state, provider, matchesTransport, now = Date.now(), attempted, model) {
|
|
123
|
+
return state.accounts.some((candidate) => candidate.provider === provider && matchesTransport(candidate) && accountCanTakeTurn(candidate, now, quotaScopeForModel(candidate, model)) && !(attempted?.has(candidate.id) && !resetPassedSince(candidate, attempted.get(candidate.id), now)));
|
|
124
|
+
}
|
|
125
|
+
function reportedRoom(account, now = Date.now()) {
|
|
126
|
+
const windows = vendorWindows(account).filter((window) => !window.advisory);
|
|
127
|
+
if (!windows.length || !usageReadingIsCurrent({ windows }, now)) return void 0;
|
|
128
|
+
return Math.min(...windows.map((window) => Math.max(0, 100 - window.usedPct)));
|
|
129
|
+
}
|
|
130
|
+
function resetPassedSince(account, triedAt, now) {
|
|
131
|
+
const at = account.quotaRetryAt ? Date.parse(account.quotaRetryAt) : Number.NaN;
|
|
132
|
+
return Number.isFinite(at) && at > triedAt && at <= now;
|
|
133
|
+
}
|
|
134
|
+
function confirmedAt(account) {
|
|
135
|
+
return Math.max(
|
|
136
|
+
account.usage && !account.usage.failed ? Date.parse(account.usage.at) || Number.NEGATIVE_INFINITY : Number.NEGATIVE_INFINITY,
|
|
137
|
+
Date.parse(account.quotaExhaustedAt ?? "") || Number.NEGATIVE_INFINITY
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
function nextUsableFailoverAccount(state, current, matchesTransport, attempted, now = Date.now(), model) {
|
|
141
|
+
const usable = (candidate) => accountCanTakeTurn(candidate, now, quotaScopeForModel(candidate, model)) && (!attempted.has(candidate.id) || resetPassedSince(candidate, attempted.get(candidate.id), now));
|
|
142
|
+
const unconfirmed = (candidate) => !attempted.has(candidate.id) && candidate.status === "ready" && !candidate.verification && !modelQuotaRefusalHolds(candidate, now, quotaScopeForModel(candidate, model)) && now - confirmedAt(candidate) >= USAGE_RECHECK_MS;
|
|
143
|
+
const rank = (account) => usable(account) ? [0, -(reportedRoom(account, now) ?? -1)] : [1, confirmedAt(account)];
|
|
144
|
+
return state.accounts.filter((candidate) => candidate.id !== current.id && candidate.provider === current.provider && matchesTransport(candidate) && (usable(candidate) || unconfirmed(candidate))).map((account) => ({ account, rank: rank(account) })).sort((left, right) => left.rank[0] - right.rank[0] || left.rank[1] - right.rank[1])[0]?.account;
|
|
145
|
+
}
|
|
146
|
+
function initialAccountChoice(state, current, matchesBackend, attempted, options = {}) {
|
|
147
|
+
const now = options.now ?? Date.now();
|
|
148
|
+
const refused = quotaRefusalHolds(current, now, quotaScopeForModel(current, options.model));
|
|
149
|
+
const fallback = nextUsableFailoverAccount(state, current, matchesBackend, new Map([...attempted, [current.id, now]]), now, options.model);
|
|
150
|
+
if (!fallback) return { kind: "continue" };
|
|
151
|
+
const early = !refused && accountCanTakeTurn(fallback, now, quotaScopeForModel(fallback, options.model)) && earlyMoveTarget(current, [fallback], state.invocations, { now, turns: options.turns ?? 1 }) !== void 0;
|
|
152
|
+
if (!refused && !early) return { kind: "continue" };
|
|
153
|
+
attempted.set(current.id, now);
|
|
154
|
+
return { kind: "switch", account: fallback, reason: refused ? "quota-exhausted" : "low-room" };
|
|
155
|
+
}
|
|
156
|
+
function terminalFailoverError(input) {
|
|
157
|
+
const { state, current, matchesBackend, exhaustedAny, lastFailure, lastOtherFailure, attempted, model } = input;
|
|
158
|
+
if (!exhaustedAny) return lastFailure;
|
|
159
|
+
if (providerHasAccountForTurn(state, current.provider, matchesBackend, Date.now(), attempted, model)) return lastOtherFailure ?? lastFailure;
|
|
160
|
+
return new Error(usageExhaustedMessage());
|
|
161
|
+
}
|
|
162
|
+
async function storedView(state, own) {
|
|
163
|
+
const stored = new Map(((await loadIndex().catch(quiet("turn/account-routing")))?.accounts ?? []).map((account) => [account.id, account]));
|
|
164
|
+
return { ...state, accounts: state.accounts.map((account) => account === own ? account : stored.get(account.id) ?? account) };
|
|
165
|
+
}
|
|
166
|
+
function chosen(state, account) {
|
|
167
|
+
const own = state.accounts.find((item) => item.id === account.id);
|
|
168
|
+
if (!own) return account;
|
|
169
|
+
if (own !== account) refreshAccount(state, account);
|
|
170
|
+
return own;
|
|
171
|
+
}
|
|
172
|
+
var ACCOUNT_FAILURES = /* @__PURE__ */ new Set(["quota-exhausted", "temporarily-throttled", "authentication-required", "account-ineligible"]);
|
|
173
|
+
async function accountAfterFailure(input) {
|
|
174
|
+
const { state, account, failure, kind, tally } = input;
|
|
175
|
+
if (input.signal?.aborted || isTurnCancelled(failure)) {
|
|
176
|
+
throw turnCancelledError();
|
|
177
|
+
}
|
|
178
|
+
if (kind === "authentication-required") account.status = "needs_login";
|
|
179
|
+
if (!ACCOUNT_FAILURES.has(kind)) {
|
|
180
|
+
await input.persist();
|
|
181
|
+
throw failure;
|
|
182
|
+
}
|
|
183
|
+
tally.attempted.set(account.id, Date.now());
|
|
184
|
+
if (kind === "quota-exhausted") {
|
|
185
|
+
recordQuotaRefusal(state, account, failure, Date.now(), input.model);
|
|
186
|
+
tally.exhaustedAny = true;
|
|
187
|
+
} else tally.lastOtherFailure = failure;
|
|
188
|
+
const verification = kind === "account-ineligible" ? accountVerification(failure) : void 0;
|
|
189
|
+
if (verification) {
|
|
190
|
+
account.verification = { ...verification, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
191
|
+
input.notice?.(verificationNotice(verification));
|
|
192
|
+
}
|
|
193
|
+
await input.persist();
|
|
194
|
+
const view = await storedView(state, account);
|
|
195
|
+
const fallback = nextUsableFailoverAccount(view, account, input.matchesBackend, tally.attempted, Date.now(), input.model);
|
|
196
|
+
if (fallback) return chosen(state, fallback);
|
|
197
|
+
throw terminalFailoverError({
|
|
198
|
+
state,
|
|
199
|
+
current: account,
|
|
200
|
+
matchesBackend: input.matchesBackend,
|
|
201
|
+
exhaustedAny: tally.exhaustedAny,
|
|
202
|
+
lastFailure: failure,
|
|
203
|
+
lastOtherFailure: tally.lastOtherFailure,
|
|
204
|
+
attempted: tally.attempted,
|
|
205
|
+
model: input.model
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function turnAccountRecorder(session, persist) {
|
|
209
|
+
let recorded = session.accountId;
|
|
210
|
+
return async (to, save = true) => {
|
|
211
|
+
if (to.id === recorded) return;
|
|
212
|
+
const stored = (await readState({ transcripts: [] })).sessions.find((item) => item.id === session.id);
|
|
213
|
+
if (stored && stored.accountId !== recorded) return;
|
|
214
|
+
session.accountId = to.id;
|
|
215
|
+
recorded = to.id;
|
|
216
|
+
if (save) await persist();
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function turnAccounts(input) {
|
|
220
|
+
const { state, session, prompter, matchesBackend, persist } = input;
|
|
221
|
+
const tally = { attempted: /* @__PURE__ */ new Map(), exhaustedAny: false };
|
|
222
|
+
const recordAccount = turnAccountRecorder(session, persist);
|
|
223
|
+
let switchedFrom;
|
|
224
|
+
let switchReason = "quota-exhausted";
|
|
225
|
+
const switchTo = async (to, why) => {
|
|
226
|
+
prompter?.phase(accountSwitchNotice(why, to.label));
|
|
227
|
+
const closing = input.beforeSwitch?.();
|
|
228
|
+
switchedFrom = input.current().label;
|
|
229
|
+
switchReason = why;
|
|
230
|
+
const first = session.pendingTurn?.accountSwitch?.from ?? switchedFrom;
|
|
231
|
+
if (session.pendingTurn) session.pendingTurn.accountSwitch = { from: first, to: to.label, reason: why };
|
|
232
|
+
input.adopt(to);
|
|
233
|
+
await Promise.all([closing, recordAccount(to, false)]);
|
|
234
|
+
await persist();
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
recordAccount,
|
|
238
|
+
switchTo,
|
|
239
|
+
/** Moves off a spent account before the first attempt; true when it did.
|
|
240
|
+
* `carry` runs first, while the account is still the old one. `turns`: see initialAccountChoice. */
|
|
241
|
+
async start(carry, turns) {
|
|
242
|
+
const view = await storedView(state);
|
|
243
|
+
const current = input.current();
|
|
244
|
+
const stored = view.accounts.find((item) => item.id === current.id) ?? current;
|
|
245
|
+
const initial = initialAccountChoice(view, stored, matchesBackend, tally.attempted, { ...turns === void 0 ? {} : { turns }, ...input.model ? { model: input.model } : {} });
|
|
246
|
+
if (initial.kind !== "switch") {
|
|
247
|
+
chosen(state, stored);
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
const to = chosen(state, initial.account);
|
|
251
|
+
await carry?.(to);
|
|
252
|
+
await switchTo(to, initial.reason);
|
|
253
|
+
return true;
|
|
254
|
+
},
|
|
255
|
+
/** accountAfterFailure for the current account. */
|
|
256
|
+
after: (failure, kind, signal) => accountAfterFailure({
|
|
257
|
+
state,
|
|
258
|
+
account: input.current(),
|
|
259
|
+
failure,
|
|
260
|
+
kind,
|
|
261
|
+
signal,
|
|
262
|
+
matchesBackend,
|
|
263
|
+
tally,
|
|
264
|
+
persist,
|
|
265
|
+
notice: (message) => prompter?.activity(source_default.yellow(message)),
|
|
266
|
+
model: input.model
|
|
267
|
+
}),
|
|
268
|
+
/** What the turn's output says about a move, when there was one. */
|
|
269
|
+
switched: () => switchedFrom ? { accountSwitchedFrom: switchedFrom, reason: switchReason } : {}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export {
|
|
274
|
+
nextQuotaReset,
|
|
275
|
+
usageExhaustedMessage,
|
|
276
|
+
isUsageExhaustedMessage,
|
|
277
|
+
resumeStep,
|
|
278
|
+
resumeWaitLabel,
|
|
279
|
+
turnBackendForAccount,
|
|
280
|
+
matchesDirectTurnModel,
|
|
281
|
+
matchesVendorTurn,
|
|
282
|
+
nextUsableFailoverAccount,
|
|
283
|
+
turnAccounts
|
|
284
|
+
};
|