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,527 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
COMPUTER_TUNABLES
|
|
5
|
+
} from "./chunk-5SM5UAWN.js";
|
|
6
|
+
import {
|
|
7
|
+
quiet
|
|
8
|
+
} from "./chunk-RDDWQBEM.js";
|
|
9
|
+
|
|
10
|
+
// src/gateway/model-names.ts
|
|
11
|
+
var squash = (id) => id.toLowerCase().replace(/[.\-_:\s]/g, "");
|
|
12
|
+
function listedModel(wanted, listed) {
|
|
13
|
+
if (listed.includes(wanted)) return wanted;
|
|
14
|
+
const target = squash(wanted);
|
|
15
|
+
const same = listed.find((id) => squash(id) === target);
|
|
16
|
+
if (same) return same;
|
|
17
|
+
const prefixed = listed.filter((id) => id.includes("/") && squash(id.slice(id.lastIndexOf("/") + 1)) === target);
|
|
18
|
+
if (prefixed.length === 1) return prefixed[0];
|
|
19
|
+
let best;
|
|
20
|
+
for (const id of listed) {
|
|
21
|
+
const stem = squash(id);
|
|
22
|
+
if (stem.length < 4 || stem.length >= target.length || !target.startsWith(stem) || !/^\d+$/.test(target.slice(stem.length))) continue;
|
|
23
|
+
if (!best || stem.length > best.length) best = { id, length: stem.length };
|
|
24
|
+
}
|
|
25
|
+
return best?.id;
|
|
26
|
+
}
|
|
27
|
+
function listedModels(wanted, listed) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const name of wanted) {
|
|
30
|
+
const id = listedModel(name, listed);
|
|
31
|
+
if (id && !out.includes(id)) out.push(id);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/agent/computer/captcha-model.ts
|
|
37
|
+
var defaultList = (name) => String(COMPUTER_TUNABLES[name].default).split(",");
|
|
38
|
+
var ROSTERS = {
|
|
39
|
+
/** Is the outlined square part of the target? (reCAPTCHA grids, GeeTest example matching): many quick asks, the fast models first. */
|
|
40
|
+
tile: defaultList("captchaTileVoters"),
|
|
41
|
+
/** Where should one click? (hCaptcha riddles, unknown challenge boxes) */
|
|
42
|
+
click: defaultList("captchaClickVoters"),
|
|
43
|
+
/** Matching, ordering and choosing among options (GeeTest icons, hCaptcha drags, Arkose picks). */
|
|
44
|
+
order: defaultList("captchaOrderVoters"),
|
|
45
|
+
/** Reading distorted characters. */
|
|
46
|
+
text: defaultList("captchaTextVoters")
|
|
47
|
+
};
|
|
48
|
+
var ROSTER_SETTING = { tile: "captchaTileVoters", click: "captchaClickVoters", order: "captchaOrderVoters", text: "captchaTextVoters" };
|
|
49
|
+
async function rosterSetting(roster) {
|
|
50
|
+
try {
|
|
51
|
+
const [{ computerTunableList }, { stateDirectory }] = await Promise.all([import("./chunk-YHNIQPKY.js"), import("./chunk-HI4VY473.js")]);
|
|
52
|
+
const listed = await computerTunableList(stateDirectory(), ROSTER_SETTING[roster]);
|
|
53
|
+
return listed.length ? listed : ROSTERS[roster];
|
|
54
|
+
} catch (error) {
|
|
55
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
56
|
+
return ROSTERS[roster];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var VOTERS = 3;
|
|
60
|
+
var VISION_TTL_MS = 6e4;
|
|
61
|
+
var cachedVision;
|
|
62
|
+
var newMeter = () => ({ asks: 0, models: {}, votes: [], samples: [] });
|
|
63
|
+
var subsidized = (model) => model.access === "subscription" || model.access === "free";
|
|
64
|
+
var HARD = /* @__PURE__ */ new Set(["click", "order"]);
|
|
65
|
+
var clients = /* @__PURE__ */ new Map();
|
|
66
|
+
function gatewayClient(model, now) {
|
|
67
|
+
const kept = clients.get(model);
|
|
68
|
+
if (kept && now - kept.at <= VISION_TTL_MS) return kept.client;
|
|
69
|
+
const client = makeGatewayClient(model);
|
|
70
|
+
clients.set(model, { at: now, client });
|
|
71
|
+
client.catch(() => clients.delete(model));
|
|
72
|
+
return client;
|
|
73
|
+
}
|
|
74
|
+
async function makeGatewayClient(model) {
|
|
75
|
+
const { gatewayConnection, gatewayModelClient } = await import("./chunk-QYRU2UQI.js");
|
|
76
|
+
const Conf = (await import("./chunk-GSXENUZL.js")).default;
|
|
77
|
+
const { baseUrl, apiKey } = gatewayConnection(new Conf({ projectName: "clikcode", configFileMode: 384 }));
|
|
78
|
+
return gatewayModelClient({ baseUrl, apiKey, vision: true, model, subscriptions: true });
|
|
79
|
+
}
|
|
80
|
+
var benched = /* @__PURE__ */ new Map();
|
|
81
|
+
var BENCH_MS = 5 * 6e4;
|
|
82
|
+
var REFUSAL = /\bI(?:'m| am)? (?:cannot|can't|can not|won't|will not|am unable|am not able|unable|not able)\b|\bprohibited\b|\b(?:against|violates?) (?:my|the|our) (?:guidelines|polic(?:y|ies)|rules)\b/i;
|
|
83
|
+
var isBenched = (name, now = Date.now()) => (benched.get(name) ?? 0) > now;
|
|
84
|
+
var STAND_INS = [];
|
|
85
|
+
function seatOrder(roster, vision, measured = [], listed = ROSTERS[roster]) {
|
|
86
|
+
const wanted = [...measured.filter((name) => listed.includes(name)), ...listed.filter((name) => !measured.includes(name)), ...STAND_INS.filter((name) => !listed.includes(name))];
|
|
87
|
+
const seen = /* @__PURE__ */ new Set();
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const name of wanted) {
|
|
90
|
+
const id = listedModel(name, vision);
|
|
91
|
+
if (id && !seen.has(id)) {
|
|
92
|
+
seen.add(id);
|
|
93
|
+
out.push({ name, id });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
async function gatewayListing() {
|
|
99
|
+
const { gatewayModels } = await import("./chunk-BXPQFSX5.js");
|
|
100
|
+
return gatewayModels();
|
|
101
|
+
}
|
|
102
|
+
async function visionModels(options, now) {
|
|
103
|
+
if (cachedVision && now - cachedVision.at <= VISION_TTL_MS) return cachedVision.ids;
|
|
104
|
+
try {
|
|
105
|
+
const listing = await (options.seats?.listing ?? gatewayListing)();
|
|
106
|
+
cachedVision = { ids: listing.models.filter((model) => model.vision === true && subsidized(model)).map((model) => model.id), at: now };
|
|
107
|
+
return cachedVision.ids;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
110
|
+
return cachedVision?.ids ?? [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function resetCaptchaVoters() {
|
|
114
|
+
cachedVision = void 0;
|
|
115
|
+
clients.clear();
|
|
116
|
+
benched.clear();
|
|
117
|
+
}
|
|
118
|
+
async function votersFor(roster, options) {
|
|
119
|
+
if (options.voters) return options.voters();
|
|
120
|
+
if (options.modelClientsOf) return (await options.modelClientsOf()).map((client) => ({ name: "", client }));
|
|
121
|
+
const now = options.now ?? Date.now;
|
|
122
|
+
const vision = await visionModels(options, now());
|
|
123
|
+
const listed = await (options.seats?.roster ?? rosterSetting)(roster);
|
|
124
|
+
const preferred = seatOrder(roster, vision, options.order?.[roster] ?? [], listed);
|
|
125
|
+
const fit = preferred.filter((model) => !isBenched(model.name, now()));
|
|
126
|
+
const ordered = preferred.length ? [...fit, ...preferred.filter((model) => !fit.includes(model))] : vision.slice(0, 1).map((id) => ({ name: id, id }));
|
|
127
|
+
const clientOf = options.seats?.client ?? ((id) => gatewayClient(id, now()));
|
|
128
|
+
const gateway = (await Promise.all(ordered.map(async (model) => {
|
|
129
|
+
try {
|
|
130
|
+
return { name: model.name, client: await clientOf(model.id) };
|
|
131
|
+
} catch (error) {
|
|
132
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
}))).filter((voter) => !!voter);
|
|
136
|
+
if (roster === "tile") return gateway;
|
|
137
|
+
const subscription = options.seats?.subscription ?? (async () => (await import("./chunk-YMBR6HYP.js")).subscriptionVoter(now));
|
|
138
|
+
const own = await subscription().catch(quiet("agent/computer/captcha-model"));
|
|
139
|
+
if (!own || isBenched(own.name, now())) return gateway;
|
|
140
|
+
return HARD.has(roster) ? [...gateway.slice(0, VOTERS - 1), own, ...gateway.slice(VOTERS - 1)] : [...gateway, own];
|
|
141
|
+
}
|
|
142
|
+
async function untilAgreed(asks, agreed2) {
|
|
143
|
+
const answers = asks.map(() => void 0);
|
|
144
|
+
return new Promise((resolve) => {
|
|
145
|
+
let pending = asks.length, settled = false;
|
|
146
|
+
if (!pending) resolve(answers);
|
|
147
|
+
asks.forEach((ask, index) => {
|
|
148
|
+
void ask.then((value) => {
|
|
149
|
+
answers[index] = value;
|
|
150
|
+
}, () => void 0).then(() => {
|
|
151
|
+
pending--;
|
|
152
|
+
if (settled) return;
|
|
153
|
+
if (pending === 0 || agreed2(answers)) {
|
|
154
|
+
settled = true;
|
|
155
|
+
resolve([...answers]);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async function poll(question, options) {
|
|
162
|
+
let all;
|
|
163
|
+
try {
|
|
164
|
+
all = await votersFor(question.roster, options);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
if (!all.length) return void 0;
|
|
170
|
+
const voting = options.modelClientsOf ? all : all.slice(0, VOTERS);
|
|
171
|
+
const spares = options.modelClientsOf ? [] : all.slice(VOTERS);
|
|
172
|
+
const names = voting.map((voter) => voter.name);
|
|
173
|
+
const settled = new AbortController();
|
|
174
|
+
const signal = options.signal ? AbortSignal.any([options.signal, settled.signal]) : settled.signal;
|
|
175
|
+
const meter = options.meter;
|
|
176
|
+
const sample = meter && question.roster !== "tile" && meter.samples.length < 12 ? { roster: question.roster, text: question.text, images: question.images, answers: {} } : void 0;
|
|
177
|
+
if (sample) meter.samples.push(sample);
|
|
178
|
+
const ask = async (voter, seat) => {
|
|
179
|
+
names[seat] = voter.name;
|
|
180
|
+
if (meter) {
|
|
181
|
+
meter.asks++;
|
|
182
|
+
meter.models[voter.name || "test"] = (meter.models[voter.name || "test"] ?? 0) + 1;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const result = await voter.client.step({
|
|
186
|
+
system: question.system,
|
|
187
|
+
items: [{ type: "text", role: "user", text: question.text, images: question.images }],
|
|
188
|
+
tools: [],
|
|
189
|
+
toolChoice: "none",
|
|
190
|
+
maxOutputTokens: question.maxOutputTokens ?? 800,
|
|
191
|
+
signal,
|
|
192
|
+
onTextDelta: () => void 0
|
|
193
|
+
});
|
|
194
|
+
if (await voteLogOn()) console.error(`vote ${question.roster} ${voter.name}: ${JSON.stringify(result.text.slice(0, 160))}`);
|
|
195
|
+
if (sample) sample.answers[voter.name || `voter-${seat + 1}`] = result.text.slice(0, 600);
|
|
196
|
+
const answer = question.parse(result.text);
|
|
197
|
+
if (answer !== void 0) return answer;
|
|
198
|
+
if (REFUSAL.test(result.text) && voter.name) benched.set(voter.name, (options.now ?? Date.now)() + BENCH_MS);
|
|
199
|
+
const spare = spares.shift();
|
|
200
|
+
return spare ? ask(spare, seat) : void 0;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (signal.aborted) return void 0;
|
|
203
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
204
|
+
if (await voteLogOn()) console.error(`vote ${question.roster} ${voter.name} failed: ${message.slice(0, 160)}`);
|
|
205
|
+
quiet("agent/computer/captcha-model")(message);
|
|
206
|
+
if (voter.name) benched.set(voter.name, (options.now ?? Date.now)() + BENCH_MS);
|
|
207
|
+
const spare = spares.shift();
|
|
208
|
+
return spare ? ask(spare, seat) : void 0;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const enough = question.enough;
|
|
212
|
+
const answers = await untilAgreed(voting.map(ask), (got) => voting.length > 1 && !!enough && enough(got));
|
|
213
|
+
settled.abort();
|
|
214
|
+
return { answers, voters: voting.length, names: [...names], roster: question.roster };
|
|
215
|
+
}
|
|
216
|
+
function credit(polled, options, sides) {
|
|
217
|
+
const meter = options.meter;
|
|
218
|
+
if (!meter) return;
|
|
219
|
+
polled.answers.forEach((answer, seat) => {
|
|
220
|
+
const model = polled.names[seat];
|
|
221
|
+
if (answer !== void 0 && model && meter.votes.length < 600) meter.votes.push({ roster: polled.roster, model, withWinner: sides(answer) });
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function majority(answers) {
|
|
225
|
+
const counts = /* @__PURE__ */ new Map();
|
|
226
|
+
for (const answer of answers) if (answer !== void 0) counts.set(answer, (counts.get(answer) ?? 0) + 1);
|
|
227
|
+
const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
|
|
228
|
+
if (!ranked.length) return void 0;
|
|
229
|
+
if (ranked.length > 1 && ranked[0][1] === ranked[1][1]) return void 0;
|
|
230
|
+
return ranked[0][0];
|
|
231
|
+
}
|
|
232
|
+
function agreed(answers) {
|
|
233
|
+
const winner = majority(answers);
|
|
234
|
+
return winner !== void 0 && answers.filter((answer) => answer === winner).length >= 2 ? winner : void 0;
|
|
235
|
+
}
|
|
236
|
+
var sharedBy = (answers, count) => {
|
|
237
|
+
const seen = /* @__PURE__ */ new Map();
|
|
238
|
+
for (const a of answers) if (a !== void 0) {
|
|
239
|
+
const n = (seen.get(a) ?? 0) + 1;
|
|
240
|
+
if (n >= count) return true;
|
|
241
|
+
seen.set(a, n);
|
|
242
|
+
}
|
|
243
|
+
return false;
|
|
244
|
+
};
|
|
245
|
+
var near = (a, b, radius) => Math.hypot(a.x - b.x, a.y - b.y) <= radius;
|
|
246
|
+
var mean = (values) => values.reduce((total, v) => total + v, 0) / values.length;
|
|
247
|
+
var inPicture = (p) => !!p && typeof p.x === "number" && typeof p.y === "number" && p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1;
|
|
248
|
+
function parsePoints(text) {
|
|
249
|
+
const list = /\{\s*"points"\s*:\s*\[[\s\S]*?\]\s*\}/.exec(text);
|
|
250
|
+
try {
|
|
251
|
+
if (list) {
|
|
252
|
+
const points = JSON.parse(list[0]).points;
|
|
253
|
+
if (Array.isArray(points)) return points.filter(inPicture).map((p) => ({ x: p.x, y: p.y }));
|
|
254
|
+
}
|
|
255
|
+
const one = /\{[^{}]*"x"[^{}]*\}/.exec(text);
|
|
256
|
+
if (one) {
|
|
257
|
+
const p = JSON.parse(one[0]);
|
|
258
|
+
return inPicture(p) ? [{ x: p.x, y: p.y }] : [];
|
|
259
|
+
}
|
|
260
|
+
} catch {
|
|
261
|
+
return void 0;
|
|
262
|
+
}
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
function sameAnswer(answers, radius = 0.08) {
|
|
266
|
+
const given = answers.filter((a) => !!a && a.length > 0);
|
|
267
|
+
for (let i = 0; i < given.length; i++) for (let j = i + 1; j < given.length; j++) {
|
|
268
|
+
const a = given[i], b = given[j];
|
|
269
|
+
if (a.length !== b.length) continue;
|
|
270
|
+
const used = /* @__PURE__ */ new Set();
|
|
271
|
+
const pairs = a.map((p) => {
|
|
272
|
+
const k = b.findIndex((q, index) => !used.has(index) && near(p, q, radius));
|
|
273
|
+
if (k >= 0) used.add(k);
|
|
274
|
+
return k;
|
|
275
|
+
});
|
|
276
|
+
if (pairs.every((k) => k >= 0)) return a.map((p, index) => ({ x: (p.x + b[pairs[index]].x) / 2, y: (p.y + b[pairs[index]].y) / 2 }));
|
|
277
|
+
}
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
function agreedInOrder(answers, radius = 0.09) {
|
|
281
|
+
const given = answers.filter((a) => !!a && a.length > 0);
|
|
282
|
+
if (given.length < 2) return void 0;
|
|
283
|
+
const lengths = /* @__PURE__ */ new Map();
|
|
284
|
+
for (const a of given) lengths.set(a.length, (lengths.get(a.length) ?? 0) + 1);
|
|
285
|
+
const count = [...lengths.entries()].sort((x, y) => y[1] - x[1])[0][0];
|
|
286
|
+
const same = given.filter((a) => a.length === count);
|
|
287
|
+
if (same.length < 2) return void 0;
|
|
288
|
+
const out = [];
|
|
289
|
+
for (let i = 0; i < count; i++) {
|
|
290
|
+
const points = same.map((a) => a[i]);
|
|
291
|
+
const anchor = points.find((p) => points.filter((q) => near(p, q, radius)).length >= 2);
|
|
292
|
+
if (!anchor) return void 0;
|
|
293
|
+
const close = points.filter((q) => near(anchor, q, radius));
|
|
294
|
+
out.push({ x: mean(close.map((q) => q.x)), y: mean(close.map((q) => q.y)) });
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
function tileQuestionText(question) {
|
|
299
|
+
const whole = question.size >= 4 ? "The squares together form one photo, so count the square if even a small part of it shows the object." : "Each square is a separate photo.";
|
|
300
|
+
return `This is an image-selection test: "${question.instruction}". One square is outlined in red. Does the red-outlined square contain any part of ${question.target}? ${whole} Answer one word: yes or no.`;
|
|
301
|
+
}
|
|
302
|
+
var yesNo = (text) => {
|
|
303
|
+
if (REFUSAL.test(text)) return void 0;
|
|
304
|
+
const word = /\b(yes|no)\b/i.exec(text)?.[1];
|
|
305
|
+
return word === void 0 ? void 0 : word.toLowerCase() === "yes";
|
|
306
|
+
};
|
|
307
|
+
async function askTileMatch(question, options = {}) {
|
|
308
|
+
const enough = question.lenient ? (got) => got.includes(true) : (got) => sharedBy(got, 2);
|
|
309
|
+
const polled = await poll({ roster: "tile", system: "You answer image-selection questions with one word: yes or no.", text: tileQuestionText(question), images: [question.image], parse: yesNo, maxOutputTokens: 300, enough }, options);
|
|
310
|
+
if (!polled) return void 0;
|
|
311
|
+
const votes = polled.answers.filter((v) => v !== void 0);
|
|
312
|
+
if (!votes.length) return void 0;
|
|
313
|
+
const yes = question.lenient ? votes.includes(true) : agreed(votes);
|
|
314
|
+
if (yes === void 0) return void 0;
|
|
315
|
+
credit(polled, options, (answer) => answer === yes);
|
|
316
|
+
return yes;
|
|
317
|
+
}
|
|
318
|
+
async function askSquaresLikeExample(example, grid, want, squares = 9, options = {}) {
|
|
319
|
+
const parse = (answer) => {
|
|
320
|
+
const list = /"squares"\s*:\s*\[([^\]]*)\]/.exec(answer)?.[1];
|
|
321
|
+
if (list === void 0) return void 0;
|
|
322
|
+
return [...new Set(list.split(",").map((n) => Number(n.trim())).filter((n) => Number.isInteger(n) && n >= 1 && n <= squares))];
|
|
323
|
+
};
|
|
324
|
+
const text = `The first picture is an example. The second picture is a grid of ${squares} drawings, numbered 1 to ${squares} from left to right, then top to bottom. Exactly ${want} of the drawings show${want === 1 ? "s" : ""} the same object as the example; it may be rotated, resized, recoloured or on another background. Compare the shapes and their parts carefully. Answer with JSON only: {"squares": [<number>, ...]}.`;
|
|
325
|
+
const polled = await poll({ roster: "order", system: "You match drawings to an example and reply with JSON only.", text, images: [example, grid], parse }, options);
|
|
326
|
+
if (!polled) return void 0;
|
|
327
|
+
const votes = /* @__PURE__ */ new Map();
|
|
328
|
+
for (const answer of polled.answers) for (const square of answer ?? []) votes.set(square, (votes.get(square) ?? 0) + 1);
|
|
329
|
+
const need = 2;
|
|
330
|
+
const picked = [...votes].filter(([, count]) => count >= need).sort((a, b) => b[1] - a[1]).slice(0, want).map(([square]) => square);
|
|
331
|
+
if (picked.length) credit(polled, options, (answer) => picked.every((square) => answer.includes(square)));
|
|
332
|
+
return picked;
|
|
333
|
+
}
|
|
334
|
+
async function askClickPoints(images, instruction, options = {}) {
|
|
335
|
+
const frames = Array.isArray(images) ? images : [images];
|
|
336
|
+
const series = frames.length > 1 ? `These ${frames.length} pictures are frames of the same puzzle taken half a second apart, in order; watch what moves. ` : "";
|
|
337
|
+
const text = `${series}This is a visual puzzle. The instruction is: "${instruction}". Where should one click to answer it? If it asks for several things, give a point for each one. Give the spots that are the answer; a begin, proceed or continue button counts when the instruction says to start or begin. Never a skip, refresh or close button. Give each point as fractions of the picture's width and height` + (frames.length > 1 ? " (on the last frame)" : "") + '. Answer with JSON only: {"points": [{"x": 0.0-1.0, "y": 0.0-1.0}]}.';
|
|
338
|
+
const polled = await poll({ roster: "click", system: "You locate answers to visual puzzles and reply with JSON only.", text, images: frames, parse: parsePoints, maxOutputTokens: 1500, enough: (got) => sameAnswer(got).length > 0 }, options);
|
|
339
|
+
if (!polled || polled.answers.every((a) => a === void 0)) return void 0;
|
|
340
|
+
const spots = sameAnswer(polled.answers);
|
|
341
|
+
if (spots.length) credit(polled, options, (answer) => sameAnswer([answer, spots]).length > 0);
|
|
342
|
+
return spots;
|
|
343
|
+
}
|
|
344
|
+
async function askOrderedPoints(image, options = {}) {
|
|
345
|
+
const text = 'This is a "select in this order" puzzle. At the top right are small black icons, in order from left to right. The large picture below contains hand-drawn coloured outline drawings; each small icon matches exactly one drawing (the same object, drawn as a rough outline). For each small icon, in order, give the centre of its matching drawing as fractions of the whole image width and height. Answer with JSON only: {"points": [{"x": 0.0-1.0, "y": 0.0-1.0}]}, one point per icon.';
|
|
346
|
+
const polled = await poll({ roster: "order", system: "You match icons to drawings and reply with JSON only.", text, images: [image], parse: parsePoints, maxOutputTokens: 1500, enough: (got) => !!agreedInOrder(got) }, options);
|
|
347
|
+
if (!polled) return void 0;
|
|
348
|
+
const inOrder = agreedInOrder(polled.answers);
|
|
349
|
+
if (inOrder?.length) credit(polled, options, (answer) => !!agreedInOrder([answer, inOrder]));
|
|
350
|
+
return inOrder;
|
|
351
|
+
}
|
|
352
|
+
function parseDrags(text) {
|
|
353
|
+
const found = /\{\s*"drags"\s*:\s*\[[\s\S]*\]\s*\}/.exec(text);
|
|
354
|
+
if (!found) return void 0;
|
|
355
|
+
try {
|
|
356
|
+
const drags = JSON.parse(found[0]).drags;
|
|
357
|
+
if (!Array.isArray(drags)) return void 0;
|
|
358
|
+
return drags.filter((d) => typeof d.n === "number" && inPicture(d.from) && inPicture(d.to)).map((d) => ({ n: d.n, from: { x: d.from.x, y: d.from.y }, to: { x: d.to.x, y: d.to.y } }));
|
|
359
|
+
} catch {
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function agreedDrags(answers, radius = 0.09) {
|
|
364
|
+
const named = /* @__PURE__ */ new Map();
|
|
365
|
+
for (const answer of answers) for (const n of new Set((answer ?? []).map((d) => d.n))) named.set(n, (named.get(n) ?? 0) + 1);
|
|
366
|
+
const wanted = [...named].filter(([, count]) => count >= 2).map(([n]) => n).sort((a, b) => a - b);
|
|
367
|
+
const out = [];
|
|
368
|
+
for (const n of wanted) {
|
|
369
|
+
const given = answers.map((a) => a?.find((d) => d.n === n)).filter((d) => !!d);
|
|
370
|
+
const alike = (d, e) => near(d.to, e.to, radius) && near(d.from, e.from, radius);
|
|
371
|
+
const anchor = given.find((d) => given.filter((e) => alike(d, e)).length >= 2);
|
|
372
|
+
if (!anchor) return [];
|
|
373
|
+
const close = given.filter((e) => alike(anchor, e));
|
|
374
|
+
out.push({ n, from: { x: mean(close.map((d) => d.from.x)), y: mean(close.map((d) => d.from.y)) }, to: { x: mean(close.map((d) => d.to.x)), y: mean(close.map((d) => d.to.y)) } });
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
async function askDrags(image, instruction, options = {}) {
|
|
379
|
+
const text = `This puzzle's instruction is: "${instruction}". If it is answered by clicking or selecting rather than by dragging something, answer {"drags": []} and nothing else. Otherwise it is a drag puzzle. If numbered pieces form one continuous line (or complete picture) in number order, the pieces labelled "Move" are out of place and the others are already placed. For a slider, the one piece is the slider handle (number it 1) and it is dropped where the puzzle piece fits its gap. For each piece to move, give where to grab it (the centre of its numbered circle, or of the piece) and where that point should end up. Fractions of the whole image. Answer with JSON only: {"drags": [{"n": 2, "from": {"x": 0.0, "y": 0.0}, "to": {"x": 0.0, "y": 0.0}}]}.`;
|
|
380
|
+
const polled = await poll({ roster: "order", system: "You solve drag puzzles and reply with JSON only.", text, images: [image], parse: parseDrags, maxOutputTokens: 1500, enough: (got) => agreedDrags(got).length > 0 && got.filter(Boolean).length >= 2 }, options);
|
|
381
|
+
if (!polled || polled.answers.every((a) => a === void 0)) return void 0;
|
|
382
|
+
const drags = agreedDrags(polled.answers);
|
|
383
|
+
if (drags.length) credit(polled, options, (answer) => agreedDrags([answer, drags]).length === drags.length);
|
|
384
|
+
return drags;
|
|
385
|
+
}
|
|
386
|
+
async function askPick(images, instruction, options = {}) {
|
|
387
|
+
const text = `These ${images.length} pictures are the options of one visual puzzle, numbered 1 to ${images.length} in the order given. The instruction is: "${instruction}". Which one option is the correct answer? Answer with JSON only: {"pick": <number>}.`;
|
|
388
|
+
const parse = (answer) => {
|
|
389
|
+
const pick2 = Number(/"pick"\s*:\s*(\d+)/.exec(answer)?.[1]);
|
|
390
|
+
return Number.isInteger(pick2) && pick2 >= 1 && pick2 <= images.length ? pick2 : void 0;
|
|
391
|
+
};
|
|
392
|
+
const polled = await poll({ roster: "order", system: "You choose the option that answers a visual puzzle and reply with JSON only.", text, images, parse, enough: (got) => sharedBy(got, 2) }, options);
|
|
393
|
+
const pick = polled ? agreed(polled.answers) : void 0;
|
|
394
|
+
if (polled && pick !== void 0) credit(polled, options, (answer) => answer === pick);
|
|
395
|
+
return pick;
|
|
396
|
+
}
|
|
397
|
+
function parseCaptchaText(text) {
|
|
398
|
+
const found = /\{[^{}]*"text"\s*:\s*"([^"]*)"[^{}]*\}/.exec(text);
|
|
399
|
+
const value = found?.[1]?.replace(/\s+/g, "");
|
|
400
|
+
return value && value.length <= 12 ? value : void 0;
|
|
401
|
+
}
|
|
402
|
+
function characterVote(readings) {
|
|
403
|
+
const byLength = /* @__PURE__ */ new Map();
|
|
404
|
+
for (const reading of readings) if (reading) byLength.set(reading.length, [...byLength.get(reading.length) ?? [], reading]);
|
|
405
|
+
const same = [...byLength.values()].sort((a, b) => b.length - a.length)[0];
|
|
406
|
+
if (!same || same.length < 3) return void 0;
|
|
407
|
+
let out = "";
|
|
408
|
+
for (let i = 0; i < same[0].length; i++) {
|
|
409
|
+
const char = majority(same.map((reading) => reading[i]));
|
|
410
|
+
if (char === void 0) return void 0;
|
|
411
|
+
out += char;
|
|
412
|
+
}
|
|
413
|
+
return out;
|
|
414
|
+
}
|
|
415
|
+
async function askCaptchaText(image, options = {}) {
|
|
416
|
+
const polled = await poll({
|
|
417
|
+
roster: "text",
|
|
418
|
+
system: "You read distorted text in pictures and reply with JSON only.",
|
|
419
|
+
images: [image],
|
|
420
|
+
parse: parseCaptchaText,
|
|
421
|
+
enough: (got) => sharedBy(got, 2),
|
|
422
|
+
text: 'This picture is a text captcha: distorted letters and digits on a noisy background. Read the characters exactly as drawn, keeping upper and lower case, ignoring lines and noise. If it shows a simple sum (like 3 + 4), give the result instead. Answer with JSON only: {"text": "..."}.'
|
|
423
|
+
}, options);
|
|
424
|
+
if (!polled) return void 0;
|
|
425
|
+
const reading = agreed(polled.answers) ?? characterVote(polled.answers);
|
|
426
|
+
if (reading) credit(polled, options, (answer) => answer === reading);
|
|
427
|
+
return reading;
|
|
428
|
+
}
|
|
429
|
+
var TRANSCRIBE_MODELS = defaultList("captchaTranscribeModels");
|
|
430
|
+
var TRANSCRIBE_MS = 45e3;
|
|
431
|
+
function transcribeOrder(wanted, speech) {
|
|
432
|
+
const listed = speech ?? [];
|
|
433
|
+
const resolved = listedModels(wanted, listed.map((model) => model.id));
|
|
434
|
+
const free = new Set(listed.filter(subsidized).map((model) => model.id));
|
|
435
|
+
return [...resolved.filter((id) => free.has(id)), ...resolved.filter((id) => !free.has(id))];
|
|
436
|
+
}
|
|
437
|
+
async function askTranscript(audio, mimeType, options = {}) {
|
|
438
|
+
let connection = options.connection;
|
|
439
|
+
let models;
|
|
440
|
+
try {
|
|
441
|
+
if (!connection) {
|
|
442
|
+
const { gatewayConnection } = await import("./chunk-QYRU2UQI.js");
|
|
443
|
+
const Conf = (await import("./chunk-GSXENUZL.js")).default;
|
|
444
|
+
connection = gatewayConnection(new Conf({ projectName: "clikcode", configFileMode: 384 }));
|
|
445
|
+
}
|
|
446
|
+
const wanted = options.models ?? await transcribeSetting();
|
|
447
|
+
models = transcribeOrder(wanted, (await (options.listing ?? gatewayListing)()).speech);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
if (!models.length) {
|
|
453
|
+
quiet("agent/computer/captcha-model")("none of the captchaTranscribeModels is listed by the Gateway: the audio challenge is not asked");
|
|
454
|
+
return void 0;
|
|
455
|
+
}
|
|
456
|
+
const { subscriptionsHeader } = await import("./chunk-LB4OA77N.js");
|
|
457
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
458
|
+
const name = /wav/i.test(mimeType) ? "clip.wav" : /ogg/i.test(mimeType) ? "clip.ogg" : "clip.mp3";
|
|
459
|
+
for (const model of models) {
|
|
460
|
+
if (options.signal?.aborted) return void 0;
|
|
461
|
+
try {
|
|
462
|
+
const form = new FormData();
|
|
463
|
+
form.append("model", model);
|
|
464
|
+
form.append("language", "en");
|
|
465
|
+
form.append("file", new Blob([new Uint8Array(audio)], { type: mimeType }), name);
|
|
466
|
+
const timeout = AbortSignal.timeout(TRANSCRIBE_MS);
|
|
467
|
+
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
|
|
468
|
+
const response = await fetchImpl(`${connection.baseUrl}/v1/audio/transcriptions`, { method: "POST", headers: { authorization: `Bearer ${connection.apiKey}`, ...subscriptionsHeader(true) }, body: form, signal });
|
|
469
|
+
if (!response.ok) continue;
|
|
470
|
+
const text = String((await response.json()).text ?? "").trim();
|
|
471
|
+
if (text) return text;
|
|
472
|
+
} catch (error) {
|
|
473
|
+
quiet("agent/computer/captcha-model")(error instanceof Error ? error.message : String(error));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return void 0;
|
|
477
|
+
}
|
|
478
|
+
async function transcribeSetting() {
|
|
479
|
+
const [{ computerTunableList }, { stateDirectory }] = await Promise.all([import("./chunk-YHNIQPKY.js"), import("./chunk-HI4VY473.js")]);
|
|
480
|
+
const listed = await computerTunableList(stateDirectory(), "captchaTranscribeModels");
|
|
481
|
+
return listed.length ? listed : TRANSCRIBE_MODELS;
|
|
482
|
+
}
|
|
483
|
+
function cleanTranscript(text) {
|
|
484
|
+
return text.toLowerCase().replace(/[^a-z0-9\s']/g, " ").replace(/\s+/g, " ").trim();
|
|
485
|
+
}
|
|
486
|
+
function spokenDigits(text) {
|
|
487
|
+
const words = { zero: "0", oh: "0", one: "1", two: "2", to: "2", too: "2", three: "3", four: "4", for: "4", five: "5", six: "6", seven: "7", eight: "8", ate: "8", nine: "9" };
|
|
488
|
+
return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).map((word) => /^\d+$/.test(word) ? word : words[word] ?? "").join("");
|
|
489
|
+
}
|
|
490
|
+
var voteLog;
|
|
491
|
+
function voteLogOn() {
|
|
492
|
+
voteLog ??= Promise.all([import("./chunk-YHNIQPKY.js"), import("./chunk-HI4VY473.js")]).then(([settings, paths]) => settings.computerTunable(paths.stateDirectory(), "captchaVoteLog")).catch(() => false);
|
|
493
|
+
return voteLog;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export {
|
|
497
|
+
ROSTERS,
|
|
498
|
+
newMeter,
|
|
499
|
+
isBenched,
|
|
500
|
+
STAND_INS,
|
|
501
|
+
seatOrder,
|
|
502
|
+
resetCaptchaVoters,
|
|
503
|
+
votersFor,
|
|
504
|
+
untilAgreed,
|
|
505
|
+
agreed,
|
|
506
|
+
parsePoints,
|
|
507
|
+
sameAnswer,
|
|
508
|
+
agreedInOrder,
|
|
509
|
+
tileQuestionText,
|
|
510
|
+
yesNo,
|
|
511
|
+
askTileMatch,
|
|
512
|
+
askSquaresLikeExample,
|
|
513
|
+
askClickPoints,
|
|
514
|
+
askOrderedPoints,
|
|
515
|
+
parseDrags,
|
|
516
|
+
agreedDrags,
|
|
517
|
+
askDrags,
|
|
518
|
+
askPick,
|
|
519
|
+
parseCaptchaText,
|
|
520
|
+
characterVote,
|
|
521
|
+
askCaptchaText,
|
|
522
|
+
TRANSCRIBE_MODELS,
|
|
523
|
+
transcribeOrder,
|
|
524
|
+
askTranscript,
|
|
525
|
+
cleanTranscript,
|
|
526
|
+
spokenDigits
|
|
527
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
childEnvironment
|
|
5
|
+
} from "./chunk-GYMAI5NY.js";
|
|
6
|
+
import {
|
|
7
|
+
computerPage,
|
|
8
|
+
ownedPages,
|
|
9
|
+
runningHostDisplay,
|
|
10
|
+
serveLiveView,
|
|
11
|
+
tabIsInCloud
|
|
12
|
+
} from "./chunk-MP4KZOQC.js";
|
|
13
|
+
import "./chunk-PWBF2X3V.js";
|
|
14
|
+
import "./chunk-HU5SSUFX.js";
|
|
15
|
+
import "./chunk-AKRYTS2D.js";
|
|
16
|
+
import "./chunk-4GVEJ5FK.js";
|
|
17
|
+
import "./chunk-O7BNJIXU.js";
|
|
18
|
+
import "./chunk-MCBRVPA7.js";
|
|
19
|
+
import "./chunk-RJLHVYQY.js";
|
|
20
|
+
import "./chunk-YMCH3L2S.js";
|
|
21
|
+
import "./chunk-I75EDU75.js";
|
|
22
|
+
import "./chunk-5SM5UAWN.js";
|
|
23
|
+
import "./chunk-PAXYQZH7.js";
|
|
24
|
+
import {
|
|
25
|
+
desktopSession,
|
|
26
|
+
remoteSession
|
|
27
|
+
} from "./chunk-CAADDF6M.js";
|
|
28
|
+
import "./chunk-G3QP67Z7.js";
|
|
29
|
+
import "./chunk-4L2ZZM4Q.js";
|
|
30
|
+
import "./chunk-F6F47QAY.js";
|
|
31
|
+
import {
|
|
32
|
+
lifecycle,
|
|
33
|
+
quiet
|
|
34
|
+
} from "./chunk-RDDWQBEM.js";
|
|
35
|
+
import "./chunk-MPAJ446F.js";
|
|
36
|
+
import {
|
|
37
|
+
sharedState
|
|
38
|
+
} from "./chunk-CBANJFBO.js";
|
|
39
|
+
import "./chunk-PWXII6HF.js";
|
|
40
|
+
|
|
41
|
+
// src/agent/computer/handoff-show.ts
|
|
42
|
+
import { spawn } from "node:child_process";
|
|
43
|
+
var SHOW_NO_TAB_MS = 10 * 6e4;
|
|
44
|
+
var TEND_EVERY_MS = 2e3;
|
|
45
|
+
var views = sharedState("show-views", () => /* @__PURE__ */ new Map());
|
|
46
|
+
var OPENER_SETTLE_MS = 2500;
|
|
47
|
+
async function openOnDesktop(url, session, options = {}) {
|
|
48
|
+
const platform = options.platform ?? process.platform;
|
|
49
|
+
const [command, args] = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
let child;
|
|
52
|
+
try {
|
|
53
|
+
child = (options.start ?? spawn)(command, [...args], { stdio: "ignore", detached: true, windowsHide: true, env: { ...childEnvironment(command, options.env ?? process.env), ...session } });
|
|
54
|
+
} catch (error) {
|
|
55
|
+
quiet("agent/computer/handoff-show")(error);
|
|
56
|
+
resolve(false);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const settle = setTimeout(() => resolve(true), options.settleMs ?? OPENER_SETTLE_MS);
|
|
60
|
+
child.once("error", (error) => {
|
|
61
|
+
clearTimeout(settle);
|
|
62
|
+
quiet("agent/computer/handoff-show")(error);
|
|
63
|
+
resolve(false);
|
|
64
|
+
});
|
|
65
|
+
child.once("exit", (code) => {
|
|
66
|
+
clearTimeout(settle);
|
|
67
|
+
resolve(code === 0);
|
|
68
|
+
});
|
|
69
|
+
child.unref();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function realDeps(stateDir, tab) {
|
|
73
|
+
return {
|
|
74
|
+
page: () => computerPage(stateDir, tab),
|
|
75
|
+
current: () => ownedPages(stateDir, tab).current,
|
|
76
|
+
inCloud: () => tabIsInCloud(stateDir, tab),
|
|
77
|
+
hostDisplay: () => runningHostDisplay(stateDir),
|
|
78
|
+
session: () => desktopSession(),
|
|
79
|
+
remote: () => remoteSession(),
|
|
80
|
+
serve: serveLiveView,
|
|
81
|
+
open: openOnDesktop,
|
|
82
|
+
now: Date.now
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
var SETTING_HINT = "To have the browser window itself on the desktop instead, the user can run `clikcode computer display visible` (it applies the next time the browser starts).";
|
|
86
|
+
async function endShow(key, why) {
|
|
87
|
+
const view = views.get(key);
|
|
88
|
+
if (!view) return false;
|
|
89
|
+
views.delete(key);
|
|
90
|
+
clearInterval(view.timer);
|
|
91
|
+
lifecycle("browser.show.end", { why });
|
|
92
|
+
await view.server.stop().catch(quiet("agent/computer/handoff-show"));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
async function tendShow(key, deps) {
|
|
96
|
+
const view = views.get(key);
|
|
97
|
+
if (!view) return;
|
|
98
|
+
const current = deps.current();
|
|
99
|
+
if (!current || current.isClosed()) {
|
|
100
|
+
view.noTabSince ??= deps.now();
|
|
101
|
+
if (deps.now() - view.noTabSince >= SHOW_NO_TAB_MS) await endShow(key, "no-tab");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
delete view.noTabSince;
|
|
105
|
+
const viewing = view.server.viewing();
|
|
106
|
+
if (viewing && viewing !== current) view.server.reconnect();
|
|
107
|
+
}
|
|
108
|
+
async function showTab(input, overrides = {}) {
|
|
109
|
+
const key = input.tab ? `${input.stateDir}#${input.tab}` : input.stateDir;
|
|
110
|
+
const deps = { ...realDeps(input.stateDir, input.tab), ...overrides };
|
|
111
|
+
if (input.clear === true) return await endShow(key, "cleared") ? "The live view is closed. The tab is unchanged." : "No live view is open on this tab.";
|
|
112
|
+
const page = await deps.page();
|
|
113
|
+
const remote = deps.remote();
|
|
114
|
+
if (!remote && !deps.inCloud() && await deps.hostDisplay() === "visible") {
|
|
115
|
+
await endShow(key, "browser-visible");
|
|
116
|
+
await page.bringToFront();
|
|
117
|
+
return "ClikCode's browser window is on this computer's desktop, and this tab is now in front in it: the user can watch there. Keep working as usual. Nothing else was opened.";
|
|
118
|
+
}
|
|
119
|
+
let view = views.get(key);
|
|
120
|
+
const reused = view !== void 0;
|
|
121
|
+
if (!view) {
|
|
122
|
+
const server = await deps.serve({ host: "127.0.0.1", watch: true, ownHostOnly: true, page: deps.page });
|
|
123
|
+
const timer = setInterval(() => {
|
|
124
|
+
void tendShow(key, deps).catch(quiet("agent/computer/handoff-show"));
|
|
125
|
+
}, TEND_EVERY_MS);
|
|
126
|
+
timer.unref();
|
|
127
|
+
view = { server, timer };
|
|
128
|
+
views.set(key, view);
|
|
129
|
+
}
|
|
130
|
+
const address = view.server.address;
|
|
131
|
+
const carryOn = "It stays open while you work: keep acting on the tab as usual, and it follows this chat to another tab. The user can also click and type in it. show with clear: true closes it.";
|
|
132
|
+
if (reused && view.server.viewing()) {
|
|
133
|
+
lifecycle("browser.show.open", { reused, opened: false, why: "already-viewing" });
|
|
134
|
+
return `The user already has the live view of this tab open (${address}). ${carryOn}`;
|
|
135
|
+
}
|
|
136
|
+
const session = remote ? void 0 : deps.session();
|
|
137
|
+
if (!session) {
|
|
138
|
+
lifecycle("browser.show.open", { reused, opened: false, why: remote ? "remote" : "no-desktop" });
|
|
139
|
+
const why = remote ? "This chat is being driven from a remote session (ssh or a remote terminal), so a window on this computer's desktop would not be in front of the user" : "No desktop session was found from here (no DISPLAY or WAYLAND_DISPLAY: a server, a container)";
|
|
140
|
+
return `NOT OPENED. ${why}. The live view is being served at ${address}, which answers only on this computer itself (127.0.0.1): give the user that address to open in a browser on this computer. For a user on another device, use handoff (a link on their Tailscale network). ${carryOn}`;
|
|
141
|
+
}
|
|
142
|
+
const opened = await deps.open(address, session);
|
|
143
|
+
lifecycle("browser.show.open", { reused, opened });
|
|
144
|
+
if (!opened) return `NOT OPENED. The desktop's browser opener could not be started or reported a failure. The live view is being served at ${address} (this computer only): give the user that address to open in their browser. ${carryOn}`;
|
|
145
|
+
return `${reused ? "Opened the live view again, at the same address" : "Opened a live view of this tab in the user's default browser on their desktop"}: ${address}
|
|
146
|
+
Tell the user it is open (the address answers only on this computer). ${carryOn} ${SETTING_HINT}`;
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
SHOW_NO_TAB_MS,
|
|
150
|
+
openOnDesktop,
|
|
151
|
+
showTab,
|
|
152
|
+
tendShow
|
|
153
|
+
};
|