@wirecat/drive-cli 0.64.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/wirecat.json +2871 -0
- package/dist/bin/drive.js +2 -2
- package/dist/bin/drive.js.map +1 -1
- package/dist/browse.d.ts +1 -1
- package/dist/browse.d.ts.map +1 -1
- package/dist/browse.js +1 -1
- package/dist/bundle/{all-profiles-BPPT2AK5.js → all-profiles-WCQLIHUG.js} +14 -13
- package/dist/bundle/{anthropic-JW6GOJUD.js → anthropic-5RJMB6O7.js} +32 -16
- package/dist/bundle/{app-server-KAQIOJMZ.js → app-server-3RGYXPKG.js} +72 -58
- package/dist/bundle/{bun-UT7GNTPV.js → bun-L34VEKGG.js} +2 -2
- package/dist/bundle/{bun-sqlite-2OIVV3LS.js → bun-sqlite-H6IAXQXI.js} +12 -8
- package/dist/bundle/chunk-2AF77WMH.js +13 -0
- package/dist/bundle/{chunk-KVW4XNKB.js → chunk-2S3E2HVV.js} +107 -48
- package/dist/bundle/{chunk-IX7NQJLY.js → chunk-3NYH756U.js} +49 -116
- package/dist/bundle/chunk-3QFUDXMQ.js +53 -0
- package/dist/bundle/{chunk-5ZBR55US.js → chunk-3SDJIMZB.js} +1 -1
- package/dist/bundle/{chunk-AHB4OJCI.js → chunk-4UHBJSMI.js} +21735 -27143
- package/dist/bundle/chunk-5HVJK3ZJ.js +101 -0
- package/dist/bundle/{chunk-GSMYXGFR.js → chunk-5K54RZBK.js} +13 -5
- package/dist/bundle/{chunk-LOMW6F2E.js → chunk-5PLINHEY.js} +5403 -4847
- package/dist/bundle/{chunk-J62DI53V.js → chunk-5VDVGDOC.js} +1 -1
- package/dist/bundle/{chunk-66AF4FBW.js → chunk-5XLU4NN6.js} +4 -4
- package/dist/bundle/{chunk-4CNTID2X.js → chunk-6UJCCOZC.js} +4 -4
- package/dist/bundle/{chunk-G4KEKKDE.js → chunk-6X3KUFRQ.js} +60 -29
- package/dist/bundle/{chunk-QEAD2LF4.js → chunk-7EP4AU6A.js} +3 -3
- package/dist/bundle/{chunk-ZRZ4HTCK.js → chunk-7LT2G5BC.js} +171 -174
- package/dist/bundle/{chunk-2W464HAE.js → chunk-7ZGJRVBH.js} +7 -5
- package/dist/bundle/{chunk-FXBHOCJK.js → chunk-ADLS6FVG.js} +1 -1
- package/dist/bundle/{chunk-KG2XKEHL.js → chunk-ALE67WRR.js} +5 -5
- package/dist/bundle/{chunk-ZSZJLJIA.js → chunk-AP4MX247.js} +38 -28
- package/dist/bundle/{chunk-EWGVDFPT.js → chunk-BIJW6AYA.js} +41873 -36466
- package/dist/bundle/{chunk-B7XBIOMR.js → chunk-BQXSE645.js} +16 -16
- package/dist/bundle/{chunk-F2VDAG32.js → chunk-COGWKO2T.js} +3 -3
- package/dist/bundle/{chunk-EZ6O3ST3.js → chunk-D4MIMH2N.js} +12 -6
- package/dist/bundle/{chunk-4YRENUB5.js → chunk-D7KOAPG6.js} +2 -2
- package/dist/bundle/chunk-E2F2XIX6.js +224 -0
- package/dist/bundle/{chunk-36GPBPWM.js → chunk-FA2TNA5X.js} +3 -1
- package/dist/bundle/{chunk-SIOIMO62.js → chunk-FHBTQPA3.js} +69 -63
- package/dist/bundle/{chunk-34BIDKF4.js → chunk-FKKPVPZR.js} +649 -212
- package/dist/bundle/chunk-G4TNKBDX.js +185 -0
- package/dist/bundle/{chunk-2FEZ24DK.js → chunk-GVA3KTCD.js} +20 -20
- package/dist/bundle/chunk-GY4DAJSK.js +167 -0
- package/dist/bundle/{chunk-5OFA5EXE.js → chunk-H7XL6WTW.js} +2 -2
- package/dist/bundle/{chunk-K6BSB53R.js → chunk-HHRJPLFO.js} +1 -1
- package/dist/bundle/{chunk-P7DEGRZA.js → chunk-HPKE2GDP.js} +49 -28
- package/dist/bundle/{chunk-QXCKJUZY.js → chunk-HPSHQVJU.js} +633 -465
- package/dist/bundle/{chunk-BEZJA44H.js → chunk-HQBLJLYH.js} +7 -7
- package/dist/bundle/{chunk-JRXFW7HE.js → chunk-I5R5CMQR.js} +5 -5
- package/dist/bundle/{chunk-EJ4PNHPP.js → chunk-IIHZTV6V.js} +1 -1
- package/dist/bundle/{chunk-G3NULXOM.js → chunk-IRNDYNQX.js} +4 -4
- package/dist/bundle/{chunk-N622LRPM.js → chunk-JCHF7LZT.js} +4 -4
- package/dist/bundle/{chunk-WWCYTMAV.js → chunk-JHMEETXI.js} +2 -2
- package/dist/bundle/{chunk-ZF6GUZCE.js → chunk-JLCR24UM.js} +1 -1
- package/dist/bundle/{chunk-IDAK4DDK.js → chunk-JQXK3M5M.js} +1 -1
- package/dist/bundle/{chunk-KIN6PDFE.js → chunk-KOY5HUBY.js} +14 -5
- package/dist/bundle/{chunk-5HSRQ53R.js → chunk-KRG5X5PH.js} +2 -2
- package/dist/bundle/{chunk-VIJ6ACYB.js → chunk-LVAPSAHF.js} +8 -8
- package/dist/bundle/{chunk-OEVHZOHC.js → chunk-M7543RUJ.js} +50 -18
- package/dist/bundle/{chunk-BZ2ZKILM.js → chunk-MZWXTJ4O.js} +3 -3
- package/dist/bundle/{chunk-EC2XGDKJ.js → chunk-NK4GVFJH.js} +4 -4
- package/dist/bundle/chunk-NYECVHFH.js +10283 -0
- package/dist/bundle/{chunk-HW4UPST2.js → chunk-NYZS2LKF.js} +2 -2
- package/dist/bundle/chunk-O53WLYX3.js +72 -0
- package/dist/bundle/{chunk-IK6KH3RE.js → chunk-OIF4B526.js} +1 -1
- package/dist/bundle/{chunk-UJR272CP.js → chunk-OT7SQQJK.js} +359 -903
- package/dist/bundle/chunk-OZOQLAWK.js +72 -0
- package/dist/bundle/{chunk-VT2UFYPJ.js → chunk-P7HQFII6.js} +22 -15
- package/dist/bundle/{chunk-6G53ZFUT.js → chunk-PJGOQSE5.js} +1 -1
- package/dist/bundle/{chunk-OH3K2E7X.js → chunk-PKM55ZRR.js} +704 -1214
- package/dist/bundle/{chunk-GW3U6OLD.js → chunk-PUMDOCAF.js} +1 -1
- package/dist/bundle/{chunk-EQEGJVO2.js → chunk-QF7VL4C3.js} +1 -1
- package/dist/bundle/{chunk-CPMRM3GQ.js → chunk-QJ57PV55.js} +1941 -662
- package/dist/bundle/{chunk-O2QO5UZC.js → chunk-QSELSDWE.js} +13 -13
- package/dist/bundle/{chunk-BEUAICUD.js → chunk-SOOU5WO6.js} +2 -2
- package/dist/bundle/{chunk-46CD64J2.js → chunk-SZ6JFOL4.js} +269 -64
- package/dist/bundle/{chunk-UD55VB2N.js → chunk-T3ULDA7C.js} +3 -3
- package/dist/bundle/{chunk-E2LBCCTG.js → chunk-TAHISPDE.js} +5 -5
- package/dist/bundle/{chunk-6B37XO6B.js → chunk-TYLEICTX.js} +3 -3
- package/dist/bundle/{chunk-TNV2FXVK.js → chunk-UAKX6DP4.js} +5 -5
- package/dist/bundle/{chunk-VPLFD5RJ.js → chunk-UG3GHFGY.js} +4 -4
- package/dist/bundle/{chunk-B67BLRAI.js → chunk-ULXEW6FT.js} +3 -60
- package/dist/bundle/{chunk-C7WBNOYW.js → chunk-UNTIVT47.js} +26 -2
- package/dist/bundle/chunk-UQPW42HF.js +18 -0
- package/dist/bundle/{chunk-USLZE36C.js → chunk-V2WXTILT.js} +6 -6
- package/dist/bundle/{chunk-BDYWZ7JE.js → chunk-VQKNKJYL.js} +46 -7
- package/dist/bundle/{chunk-XPXKD63J.js → chunk-VR3YKXHL.js} +93 -31
- package/dist/bundle/{chunk-UIEA6FIV.js → chunk-VUUPFDRU.js} +27 -28
- package/dist/bundle/{chunk-KE4XPPRQ.js → chunk-WYTYHUFH.js} +1750 -138
- package/dist/bundle/{chunk-PBMSBCVB.js → chunk-XLGDNI4S.js} +1 -1
- package/dist/bundle/{chunk-3J5KAFNA.js → chunk-XVZNFA2P.js} +4935 -3623
- package/dist/bundle/chunk-Y5U4HIZS.js +71 -0
- package/dist/bundle/chunk-YTIPTHEE.js +47 -0
- package/dist/bundle/cli-KW6QQVS5.js +1101 -0
- package/dist/bundle/command-contract-CE543JBN.js +41 -0
- package/dist/bundle/command-server-entry-OC4E4DED.js +171 -0
- package/dist/bundle/{decode-HTOQ6S3V.js → decode-AH5ZLLDK.js} +8 -8
- package/dist/bundle/{dispatch-SH5SP6LA.js → dispatch-CDWZZ54Q.js} +9 -9
- package/dist/bundle/drive.js +13 -13
- package/dist/bundle/{echarts-KFHB6SLX.js → echarts-VC7MTXWY.js} +2 -2
- package/dist/bundle/{embed-YATFB2PN.js → embed-EPSQY6QG.js} +9 -9
- package/dist/bundle/{embedder-MQPDFGTJ.js → embedder-TK4U4TJR.js} +12 -12
- package/dist/bundle/entry-3VN23M7M.js +25 -0
- package/dist/bundle/{failure-4FQL4XJI.js → failure-WSVZOPFE.js} +4 -4
- package/dist/bundle/first-run-7ZYJ7EB3.js +30 -0
- package/dist/bundle/first-screen-CZDH7QY3.js +39 -0
- package/dist/bundle/google-OBZMWA7J.js +45 -0
- package/dist/bundle/{google-api-QMFGCXBM.js → google-api-AV4X2JH3.js} +68 -57
- package/dist/bundle/grants-WTRLN4ZI.js +111 -0
- package/dist/bundle/{identity-FYVDK4M2.js → identity-CGHHF7AK.js} +8 -6
- package/dist/bundle/{instructions-D3GF3B7M.js → instructions-24PHDBBE.js} +1 -1
- package/dist/bundle/{login-COFZ2IWP.js → login-XHFESAFM.js} +73 -64
- package/dist/bundle/{mcp-RKJG22KM.js → mcp-M5YCSWJJ.js} +2 -2
- package/dist/bundle/{node-OFICOKX3.js → node-GIDULTV5.js} +2 -2
- package/dist/bundle/{node-KM3CUABH.js → node-P4E63KXA.js} +9 -9
- package/dist/bundle/{node-sqlite-DNBTDOXD.js → node-sqlite-LINBOAWK.js} +13 -9
- package/dist/bundle/oauth-JHUX3KE3.js +22 -0
- package/dist/bundle/{open-PTPR2YWX.js → open-RYFKPNCJ.js} +8 -8
- package/dist/bundle/{openai-2KV5LUW4.js → openai-Q7YYUHJF.js} +28 -42
- package/dist/bundle/{process-EAW6NST2.js → process-VPIZTIJR.js} +1 -1
- package/dist/bundle/{program-6UV5Q5YN.js → program-IUXFRBZA.js} +419 -604
- package/dist/bundle/{prompt-634TPMJK.js → prompt-LF4KX3XL.js} +8 -8
- package/dist/bundle/{reasons-DDWCEYSQ.js → reasons-JPYOU5GV.js} +5 -5
- package/dist/bundle/{recognize-SJO6QUDW.js → recognize-KEWTJXFH.js} +7 -7
- package/dist/bundle/{remote-6JXZITKF.js → remote-HGGLB76S.js} +13 -10
- package/dist/bundle/{rerank-MD5VOPQ6.js → rerank-TDUKETFT.js} +10 -10
- package/dist/bundle/{serve-LZTROA2M.js → serve-XFYMKW5W.js} +12 -12
- package/dist/bundle/server-BDEV3CZJ.js +74 -0
- package/dist/bundle/{server-NSA3UAFY.js → server-PXIPSGFP.js} +48 -44
- package/dist/bundle/{services-F5A6XQCV.js → services-2BOCGMJU.js} +111 -41
- package/dist/bundle/{sqlite-runtime-7YF6REKS.js → sqlite-runtime-R7M5XUMW.js} +9 -9
- package/dist/bundle/{start-MUFLE6FA.js → start-YRLT4MQZ.js} +7 -7
- package/dist/bundle/{state-UC54F3YZ.js → state-NZ7WRJWH.js} +9 -9
- package/dist/bundle/{store-F5FJGWMR.js → store-7LCVDO7G.js} +63 -28
- package/dist/bundle/{store-J53YNAH6.js → store-ICDGPSEN.js} +27 -18
- package/dist/bundle/store-maintenance-command-SJPLY6IH.js +65 -0
- package/dist/bundle/tokens-FGTBE7VW.js +111 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +6 -5
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/context.d.ts +4 -2
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/discovery.d.ts +0 -1
- package/dist/commands/discovery.d.ts.map +1 -1
- package/dist/commands/discovery.js +6 -26
- package/dist/commands/discovery.js.map +1 -1
- package/dist/commands/documents.d.ts +2 -0
- package/dist/commands/documents.d.ts.map +1 -1
- package/dist/commands/documents.js +39 -3
- package/dist/commands/documents.js.map +1 -1
- package/dist/commands/knowledge.d.ts.map +1 -1
- package/dist/commands/knowledge.js +7 -6
- package/dist/commands/knowledge.js.map +1 -1
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +11 -8
- package/dist/commands/search.js.map +1 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -4
- package/dist/config.js.map +1 -1
- package/dist/contract-overrides.d.ts +16 -4
- package/dist/contract-overrides.d.ts.map +1 -1
- package/dist/contract-overrides.js +86 -410
- package/dist/contract-overrides.js.map +1 -1
- package/dist/documents-add.d.ts +49 -0
- package/dist/documents-add.d.ts.map +1 -0
- package/dist/documents-add.js +122 -0
- package/dist/documents-add.js.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -1
- package/dist/errors.js.map +1 -1
- package/dist/google-api.d.ts.map +1 -1
- package/dist/google-api.js +4 -1
- package/dist/google-api.js.map +1 -1
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +22 -0
- package/dist/identity.js.map +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.d.ts.map +1 -1
- package/dist/knowledge.js +17 -19
- package/dist/knowledge.js.map +1 -1
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +2 -2
- package/dist/login.js.map +1 -1
- package/dist/model.d.ts +3 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +30 -21
- package/dist/program.js.map +1 -1
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +25 -1
- package/dist/reasons.js.map +1 -1
- package/dist/store-transition.js +2 -2
- package/dist/store-transition.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +27 -7
- package/dist/store.js.map +1 -1
- package/dist/tokens.d.ts +9 -2
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +18 -15
- package/dist/tokens.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +8 -8
- package/dist/bundle/chunk-3NULZGQU.js +0 -27
- package/dist/bundle/chunk-DD7EFG6B.js +0 -35
- package/dist/bundle/chunk-M73NNJ3X.js +0 -26
- package/dist/bundle/chunk-SBZB7HMU.js +0 -1055
- package/dist/bundle/command-contract-H5OYJOPF.js +0 -38
- package/dist/bundle/dist-PY3MVR3G.js +0 -21
- package/dist/bundle/entry-YZBB647C.js +0 -22
- package/dist/bundle/first-run-5JT3UQZB.js +0 -30
- package/dist/bundle/first-screen-BEMDEWO7.js +0 -36
- package/dist/bundle/google-DVADVICN.js +0 -36
- package/dist/bundle/grants-WKB2E4TA.js +0 -103
- package/dist/bundle/oauth-PDQHWFBF.js +0 -22
- package/dist/bundle/server-GT7X666D.js +0 -69
- package/dist/bundle/store-maintenance-command-GJVXLBAB.js +0 -58
- package/dist/bundle/tokens-H2EJKGA5.js +0 -101
- package/dist/bundle/{chunk-SW6C6WH5.js → chunk-HVJJWJYQ.js} +0 -0
- package/dist/bundle/{mdast-util-from-markdown-FXEPSNER.js → mdast-util-from-markdown-CE73EWJ2.js} +3 -3
|
@@ -2,7 +2,26 @@ import { createRequire as __bundleRequire } from "node:module";
|
|
|
2
2
|
const require = __bundleRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
refuseLacking
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HPKE2GDP.js";
|
|
6
|
+
import {
|
|
7
|
+
FloodMemory,
|
|
8
|
+
OFFLINE,
|
|
9
|
+
RecipientList,
|
|
10
|
+
capability,
|
|
11
|
+
ceilingRefusal,
|
|
12
|
+
chatIdIn,
|
|
13
|
+
floodPathFor,
|
|
14
|
+
guardFor,
|
|
15
|
+
holdEnd,
|
|
16
|
+
profilesOnAccount,
|
|
17
|
+
recipientsPathFor,
|
|
18
|
+
servicesFor,
|
|
19
|
+
throughWrapper,
|
|
20
|
+
withFileLockAsync
|
|
21
|
+
} from "./chunk-XVZNFA2P.js";
|
|
22
|
+
import {
|
|
23
|
+
servingProfiles
|
|
24
|
+
} from "./chunk-COGWKO2T.js";
|
|
6
25
|
import {
|
|
7
26
|
asFirstWord,
|
|
8
27
|
baseContext,
|
|
@@ -13,68 +32,46 @@ import {
|
|
|
13
32
|
recalledAccount,
|
|
14
33
|
rememberAccount,
|
|
15
34
|
rootOf2 as rootOf
|
|
16
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-5PLINHEY.js";
|
|
17
36
|
import {
|
|
18
37
|
providerErrorKey
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import {
|
|
21
|
-
servingProfiles
|
|
22
|
-
} from "./chunk-F2VDAG32.js";
|
|
23
|
-
import {
|
|
24
|
-
OFFLINE,
|
|
25
|
-
capability,
|
|
26
|
-
chatIdIn,
|
|
27
|
-
chatReferenceOf,
|
|
28
|
-
ensureAccount,
|
|
29
|
-
foldName,
|
|
30
|
-
isId,
|
|
31
|
-
pickPerson,
|
|
32
|
-
profilesOnAccount,
|
|
33
|
-
servicesFor,
|
|
34
|
-
throughWrapper
|
|
35
|
-
} from "./chunk-3J5KAFNA.js";
|
|
38
|
+
} from "./chunk-P7HQFII6.js";
|
|
36
39
|
import {
|
|
37
40
|
AUTHORITY_KEY,
|
|
38
41
|
CEILING_KEY,
|
|
39
42
|
DEFAULT_PERMISSIONS,
|
|
40
|
-
|
|
43
|
+
KEYED_UNDER_HOUSEKEEPING,
|
|
41
44
|
WRITE_KEYS,
|
|
42
45
|
codeOf,
|
|
43
46
|
currentOperation,
|
|
44
|
-
currentRun,
|
|
45
|
-
fromLogAttributes,
|
|
46
47
|
keyForCommand,
|
|
47
|
-
keyForWrite,
|
|
48
48
|
levelFor,
|
|
49
49
|
limitBatch,
|
|
50
|
-
logAttributes,
|
|
51
50
|
readKeysForCommand,
|
|
52
51
|
skipFlagFor
|
|
53
|
-
} from "./chunk-
|
|
54
|
-
import {
|
|
55
|
-
MESSENGER_CHANGE_REFUSAL,
|
|
56
|
-
readOnlyRefusal
|
|
57
|
-
} from "./chunk-3NULZGQU.js";
|
|
52
|
+
} from "./chunk-PKM55ZRR.js";
|
|
58
53
|
import {
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
chatReferenceOf,
|
|
55
|
+
ensureAccount,
|
|
56
|
+
foldName,
|
|
57
|
+
isId,
|
|
58
|
+
openStore,
|
|
59
|
+
pickPerson
|
|
60
|
+
} from "./chunk-BIJW6AYA.js";
|
|
61
61
|
import {
|
|
62
62
|
isCliFailure
|
|
63
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-O53WLYX3.js";
|
|
64
64
|
import {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
resolvePaths,
|
|
68
|
-
writeSecurely
|
|
69
|
-
} from "./chunk-G4KEKKDE.js";
|
|
65
|
+
resolvePaths
|
|
66
|
+
} from "./chunk-6X3KUFRQ.js";
|
|
70
67
|
import {
|
|
71
68
|
CliError
|
|
72
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-IIHZTV6V.js";
|
|
73
70
|
import {
|
|
74
71
|
__name
|
|
75
72
|
} from "./chunk-ZVVMGPBJ.js";
|
|
76
73
|
|
|
77
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
74
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
|
|
78
75
|
import { openSync } from "node:fs";
|
|
79
76
|
import { createInterface } from "node:readline";
|
|
80
77
|
import { ReadStream } from "node:tty";
|
|
@@ -129,637 +126,7 @@ var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) =>
|
|
|
129
126
|
throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
|
|
130
127
|
}, "terminalAsker");
|
|
131
128
|
|
|
132
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
133
|
-
import { randomUUID } from "node:crypto";
|
|
134
|
-
|
|
135
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/flood.js
|
|
136
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
137
|
-
import { dirname, join } from "node:path";
|
|
138
|
-
var MOST_DEADLINES = 50;
|
|
139
|
-
var LIMITED_HOLD_MS = 60 * 60 * 1e3;
|
|
140
|
-
var FROZEN_HOLD_MS = 24 * 60 * 60 * 1e3;
|
|
141
|
-
var NO_END = "9999-12-31T23:59:59.999Z";
|
|
142
|
-
var holdEnd = /* @__PURE__ */ __name((block, show = (iso) => iso) => block.until === null ? "until lifted" : `until ${show(block.until)}`, "holdEnd");
|
|
143
|
-
var floodPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "flood", `${profile}.json`), "floodPathFor");
|
|
144
|
-
var FloodMemory = class {
|
|
145
|
-
static {
|
|
146
|
-
__name(this, "FloodMemory");
|
|
147
|
-
}
|
|
148
|
-
path;
|
|
149
|
-
now;
|
|
150
|
-
constructor(path, now = Date.now) {
|
|
151
|
-
this.path = path;
|
|
152
|
-
this.now = now;
|
|
153
|
-
}
|
|
154
|
-
/** What is still in force; anything expired is left out. */
|
|
155
|
-
read() {
|
|
156
|
-
const now = this.now();
|
|
157
|
-
let raw;
|
|
158
|
-
try {
|
|
159
|
-
raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
160
|
-
} catch {
|
|
161
|
-
return { deadlines: [] };
|
|
162
|
-
}
|
|
163
|
-
const alive = /* @__PURE__ */ __name((until) => typeof until === "string" && Date.parse(until) > now, "alive");
|
|
164
|
-
const deadlines = Array.isArray(raw.deadlines) ? raw.deadlines.filter((one) => typeof one?.operation === "string" && alive(one.until)) : [];
|
|
165
|
-
const block = raw.sendBlock && (raw.sendBlock.until === NO_END ? { ...raw.sendBlock, until: null } : raw.sendBlock);
|
|
166
|
-
const held = block && (block.until === null || alive(block.until));
|
|
167
|
-
return { deadlines, ...held ? { sendBlock: block } : {} };
|
|
168
|
-
}
|
|
169
|
-
/** The deadline this call is still under: one for its chat, or one for the call in every chat. */
|
|
170
|
-
owed(operation, chatId) {
|
|
171
|
-
return this.read().deadlines.filter((one) => one.operation === operation && (one.chatId === void 0 || one.chatId === chatId)).sort((a, b) => b.until.localeCompare(a.until))[0];
|
|
172
|
-
}
|
|
173
|
-
remember(deadline) {
|
|
174
|
-
const { waitMs, ...rest } = deadline;
|
|
175
|
-
const kept = { ...rest, until: new Date(this.now() + waitMs).toISOString() };
|
|
176
|
-
const state = this.read();
|
|
177
|
-
const others = state.deadlines.filter((one) => one.operation !== kept.operation || one.chatId !== kept.chatId);
|
|
178
|
-
const deadlines = [...others, kept].sort((a, b) => b.until.localeCompare(a.until)).slice(0, MOST_DEADLINES);
|
|
179
|
-
this.#write({ ...state, deadlines });
|
|
180
|
-
return kept;
|
|
181
|
-
}
|
|
182
|
-
sendBlock() {
|
|
183
|
-
return this.read().sendBlock;
|
|
184
|
-
}
|
|
185
|
-
/** A ban the messenger gave no end for holds until lifted; a spam limit or a freeze without one, for a while. */
|
|
186
|
-
block(block) {
|
|
187
|
-
const now = this.now();
|
|
188
|
-
const holdMs = { limited: LIMITED_HOLD_MS, frozen: FROZEN_HOLD_MS, banned: void 0 }[block.state];
|
|
189
|
-
const kept = {
|
|
190
|
-
...block,
|
|
191
|
-
since: new Date(now).toISOString(),
|
|
192
|
-
until: block.until ?? (holdMs === void 0 ? null : new Date(now + holdMs).toISOString())
|
|
193
|
-
};
|
|
194
|
-
this.#write({ ...this.read(), sendBlock: kept });
|
|
195
|
-
return kept;
|
|
196
|
-
}
|
|
197
|
-
/** Lifts only a block of this state: an account found not frozen may still be limited for spam. */
|
|
198
|
-
unblock(state) {
|
|
199
|
-
const { sendBlock, ...rest } = this.read();
|
|
200
|
-
if (sendBlock?.state === state)
|
|
201
|
-
this.#write(rest);
|
|
202
|
-
}
|
|
203
|
-
/** Forgets every wait and lifts the hold, and answers with what was still in force. */
|
|
204
|
-
clear() {
|
|
205
|
-
const cleared = this.read();
|
|
206
|
-
this.#write({ deadlines: [] });
|
|
207
|
-
return cleared;
|
|
208
|
-
}
|
|
209
|
-
#write({ sendBlock, ...rest }) {
|
|
210
|
-
const state = sendBlock ? { ...rest, sendBlock: { ...sendBlock, until: sendBlock.until ?? NO_END } } : rest;
|
|
211
|
-
mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
|
|
212
|
-
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
213
|
-
writeFileSync(temporary, `${JSON.stringify(state)}
|
|
214
|
-
`, { mode: 384 });
|
|
215
|
-
renameSync(temporary, this.path);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
220
|
-
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
221
|
-
import { dirname as dirname3, join as join2 } from "node:path";
|
|
222
|
-
|
|
223
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
|
|
224
|
-
import { closeSync, mkdirSync as mkdirSync2, openSync as openSync2, statSync, unlinkSync } from "node:fs";
|
|
225
|
-
import { dirname as dirname2 } from "node:path";
|
|
226
|
-
var LOCK_WAIT_MS = 5e3;
|
|
227
|
-
var LOCK_STALE_MS = 3e4;
|
|
228
|
-
var RETRY_MS = 20;
|
|
229
|
-
var pause = new Int32Array(new SharedArrayBuffer(4));
|
|
230
|
-
var withFileLock = /* @__PURE__ */ __name((path, what2, body, waitMs = LOCK_WAIT_MS) => {
|
|
231
|
-
const lock = lockFor(path);
|
|
232
|
-
const deadline = Date.now() + waitMs;
|
|
233
|
-
while (!taken(lock)) {
|
|
234
|
-
if (Date.now() >= deadline)
|
|
235
|
-
throw lockTimeout(what2, waitMs, lock);
|
|
236
|
-
Atomics.wait(pause, 0, 0, RETRY_MS);
|
|
237
|
-
}
|
|
238
|
-
return holding(lock, body);
|
|
239
|
-
}, "withFileLock");
|
|
240
|
-
var withFileLockAsync = /* @__PURE__ */ __name(async (path, what2, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
|
|
241
|
-
const lock = lockFor(path);
|
|
242
|
-
const deadline = Date.now() + waitMs;
|
|
243
|
-
while (!taken(lock)) {
|
|
244
|
-
if (Date.now() >= deadline)
|
|
245
|
-
throw lockTimeout(what2, waitMs, lock);
|
|
246
|
-
await sleep(RETRY_MS);
|
|
247
|
-
}
|
|
248
|
-
return holding(lock, body);
|
|
249
|
-
}, "withFileLockAsync");
|
|
250
|
-
var lockFor = /* @__PURE__ */ __name((path) => {
|
|
251
|
-
mkdirSync2(dirname2(path), { recursive: true, mode: 448 });
|
|
252
|
-
return `${path}.lock`;
|
|
253
|
-
}, "lockFor");
|
|
254
|
-
var taken = /* @__PURE__ */ __name((lock) => {
|
|
255
|
-
for (; ; ) {
|
|
256
|
-
try {
|
|
257
|
-
closeSync(openSync2(lock, "wx", 384));
|
|
258
|
-
return true;
|
|
259
|
-
} catch (error) {
|
|
260
|
-
if (error.code !== "EEXIST")
|
|
261
|
-
throw error;
|
|
262
|
-
if (Date.now() - lockTime(lock) <= LOCK_STALE_MS)
|
|
263
|
-
return false;
|
|
264
|
-
try {
|
|
265
|
-
unlinkSync(lock);
|
|
266
|
-
} catch {
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}, "taken");
|
|
271
|
-
var holding = /* @__PURE__ */ __name((lock, body) => {
|
|
272
|
-
try {
|
|
273
|
-
return body();
|
|
274
|
-
} finally {
|
|
275
|
-
try {
|
|
276
|
-
unlinkSync(lock);
|
|
277
|
-
} catch {
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}, "holding");
|
|
281
|
-
var lockTimeout = /* @__PURE__ */ __name((what2, waitMs, lock) => new CliError("timeout", `${what2} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
|
|
282
|
-
var lockTime = /* @__PURE__ */ __name((lock) => {
|
|
283
|
-
try {
|
|
284
|
-
return statSync(lock).mtimeMs;
|
|
285
|
-
} catch {
|
|
286
|
-
return Date.now();
|
|
287
|
-
}
|
|
288
|
-
}, "lockTime");
|
|
289
|
-
|
|
290
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
291
|
-
var sendsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "sends", `${profile}.jsonl`), "sendsPathFor");
|
|
292
|
-
var SendJournal = class {
|
|
293
|
-
static {
|
|
294
|
-
__name(this, "SendJournal");
|
|
295
|
-
}
|
|
296
|
-
path;
|
|
297
|
-
resource;
|
|
298
|
-
constructor(path, resource = { service: "unknown", version: "unknown" }) {
|
|
299
|
-
this.path = path;
|
|
300
|
-
this.resource = resource;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Runs `body` with the journal to itself, across processes: two sends at the limit must not both
|
|
304
|
-
* read "one left". A lock file opened with `wx`, because `flock` is not there on Windows.
|
|
305
|
-
*/
|
|
306
|
-
locked(body) {
|
|
307
|
-
return withFileLock(this.path, "the send journal", body);
|
|
308
|
-
}
|
|
309
|
-
/** `locked` without blocking the thread while another process holds the journal: what `serve` uses. */
|
|
310
|
-
lockedAsync(body) {
|
|
311
|
-
return withFileLockAsync(this.path, "the send journal", body);
|
|
312
|
-
}
|
|
313
|
-
append(entry) {
|
|
314
|
-
const { at, ...attributes } = entry;
|
|
315
|
-
const { runId, command, traceId } = currentRun();
|
|
316
|
-
const record = logRecordOf({
|
|
317
|
-
severity: entry.outcome === "sent" || entry.outcome === "reserved" ? "info" : "warn",
|
|
318
|
-
event: logAttributes({ event: "send.recorded", ...attributes }),
|
|
319
|
-
time: at,
|
|
320
|
-
runId,
|
|
321
|
-
...traceId === void 0 ? {} : { traceId },
|
|
322
|
-
command,
|
|
323
|
-
resource: this.resource,
|
|
324
|
-
allow: LOG_ATTRIBUTES
|
|
325
|
-
});
|
|
326
|
-
mkdirSync3(dirname3(this.path), { recursive: true, mode: 448 });
|
|
327
|
-
appendFileSync(this.path, `${JSON.stringify(record)}
|
|
328
|
-
`, { mode: 384 });
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Oldest first, each reservation folded into its outcome; one with no outcome yet is in flight,
|
|
332
|
-
* or its process died. A line that does not parse is skipped: a torn last write must not block sending.
|
|
333
|
-
*/
|
|
334
|
-
entries(filter) {
|
|
335
|
-
const lines = this.#lines();
|
|
336
|
-
const settled2 = new Set(lines.filter((entry) => entry.outcome !== "reserved").map((entry) => entry.reservation));
|
|
337
|
-
const entries = lines.filter((entry) => entry.outcome !== "reserved" || !settled2.has(entry.reservation)).map(({ reservation, ...entry }) => entry.outcome === "reserved" ? { ...entry, reservation } : entry).map(withSendId);
|
|
338
|
-
return filter === void 0 ? entries : entries.filter((entry) => (filter.outcome === void 0 || entry.outcome === filter.outcome) && (filter.chatId === void 0 || entry.chatId === filter.chatId) && (filter.operationId === void 0 || entry.operationId === filter.operationId) && (filter.errorCode === void 0 || entry.errorCode === filter.errorCode) && (filter.key === void 0 || entry.key === filter.key));
|
|
339
|
-
}
|
|
340
|
-
#lines() {
|
|
341
|
-
let text;
|
|
342
|
-
try {
|
|
343
|
-
text = readFileSync2(this.path, "utf8");
|
|
344
|
-
} catch {
|
|
345
|
-
return [];
|
|
346
|
-
}
|
|
347
|
-
return text.split("\n").filter((line) => line.trim() !== "").flatMap((line) => {
|
|
348
|
-
try {
|
|
349
|
-
return [entryOf(JSON.parse(line))];
|
|
350
|
-
} catch {
|
|
351
|
-
return [];
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
var entryOf = /* @__PURE__ */ __name((line) => {
|
|
357
|
-
if (!("attributes" in line))
|
|
358
|
-
return line;
|
|
359
|
-
const { event: _, ...attributes } = line.attributes;
|
|
360
|
-
return { at: line.time, ...fromLogAttributes(attributes) };
|
|
361
|
-
}, "entryOf");
|
|
362
|
-
var withSendId = /* @__PURE__ */ __name((entry) => {
|
|
363
|
-
const { cid, ...rest } = entry;
|
|
364
|
-
return cid === void 0 || rest.sendId !== void 0 ? rest : { ...rest, sendId: String(cid) };
|
|
365
|
-
}, "withSendId");
|
|
366
|
-
|
|
367
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/recipients.js
|
|
368
|
-
import { existsSync, readFileSync as readFileSync3, rmSync } from "node:fs";
|
|
369
|
-
import { join as join3 } from "node:path";
|
|
370
|
-
var recipientsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "profiles", `${profile}.recipients.json`), "recipientsPathFor");
|
|
371
|
-
var RecipientList = class {
|
|
372
|
-
static {
|
|
373
|
-
__name(this, "RecipientList");
|
|
374
|
-
}
|
|
375
|
-
path;
|
|
376
|
-
command;
|
|
377
|
-
lockWaitMs;
|
|
378
|
-
/** `command` names the program in the hint that turns the list off. */
|
|
379
|
-
constructor(path, command, lockWaitMs) {
|
|
380
|
-
this.path = path;
|
|
381
|
-
this.command = command;
|
|
382
|
-
this.lockWaitMs = lockWaitMs;
|
|
383
|
-
}
|
|
384
|
-
/** `undefined` when the list is off. A file that cannot be read refuses rather than opening up. */
|
|
385
|
-
read() {
|
|
386
|
-
if (!existsSync(this.path))
|
|
387
|
-
return void 0;
|
|
388
|
-
try {
|
|
389
|
-
const parsed = JSON.parse(readFileSync3(this.path, "utf8"));
|
|
390
|
-
if (!Array.isArray(parsed.chats))
|
|
391
|
-
throw new Error("no `chats` array");
|
|
392
|
-
return parsed.chats;
|
|
393
|
-
} catch (error) {
|
|
394
|
-
throw new CliError("configuration_error", `the recipient list ${this.path} cannot be read (${error instanceof Error ? error.message : String(error)}) \u2014 fix the file or turn the list off with \`${this.command} recipients clear\``);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
list(filter = {}) {
|
|
398
|
-
const chats = this.read();
|
|
399
|
-
return {
|
|
400
|
-
state: chats === void 0 ? "off" : chats.length === 0 ? "empty" : "on",
|
|
401
|
-
items: (chats ?? []).filter((chat) => (filter.id === void 0 || chat.id === filter.id) && (filter.title === void 0 || chat.title?.toLocaleLowerCase() === filter.title.toLocaleLowerCase()))
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
/** Whether it was new. Adding one again fills in a partner an older entry was stored without. */
|
|
405
|
-
add(recipient) {
|
|
406
|
-
return this.#locked(() => this.#added(recipient));
|
|
407
|
-
}
|
|
408
|
-
/** `add` waiting for the lock on timers: `recipients add` connects, so it runs inside `serve` when one holds the account. */
|
|
409
|
-
addAsync(recipient) {
|
|
410
|
-
return withFileLockAsync(this.path, "the recipient list", () => this.#added(recipient), this.lockWaitMs);
|
|
411
|
-
}
|
|
412
|
-
#added(recipient) {
|
|
413
|
-
const chats = this.read() ?? [];
|
|
414
|
-
const known = chats.find((chat) => chat.id === recipient.id);
|
|
415
|
-
if (known) {
|
|
416
|
-
if (recipient.partnerId && !known.partnerId) {
|
|
417
|
-
this.#write(chats.map((chat) => chat === known ? { ...known, partnerId: recipient.partnerId } : chat));
|
|
418
|
-
}
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
this.#write([...chats, recipient]);
|
|
422
|
-
return true;
|
|
423
|
-
}
|
|
424
|
-
/** The id or the title as it was stored; `undefined` when neither matched. */
|
|
425
|
-
remove(reference) {
|
|
426
|
-
return this.#locked(() => {
|
|
427
|
-
const chats = this.read() ?? [];
|
|
428
|
-
const wanted = reference.trim();
|
|
429
|
-
const gone = chats.find((chat) => chat.id === wanted) ?? chats.find((chat) => chat.title?.toLocaleLowerCase() === wanted.toLocaleLowerCase());
|
|
430
|
-
if (gone)
|
|
431
|
-
this.#write(chats.filter((chat) => chat !== gone));
|
|
432
|
-
return gone;
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* The chat the messenger now names `to`: its entry, and a partner of that id, follow it. Only an entry already there
|
|
437
|
-
* changes, and no list is created, so the list never opens up. Whether anything changed.
|
|
438
|
-
*/
|
|
439
|
-
async rekey(from, to) {
|
|
440
|
-
if (from === to)
|
|
441
|
-
return false;
|
|
442
|
-
return withFileLockAsync(this.path, "the recipient list", () => {
|
|
443
|
-
const chats = this.read();
|
|
444
|
-
if (!chats?.some((chat) => chat.id === from || chat.partnerId === from))
|
|
445
|
-
return false;
|
|
446
|
-
const held = chats.some((chat) => chat.id === to);
|
|
447
|
-
this.#write(chats.filter((chat) => !(held && chat.id === from)).map((chat) => ({
|
|
448
|
-
...chat,
|
|
449
|
-
...chat.id === from ? { id: to } : {},
|
|
450
|
-
...chat.partnerId === from ? { partnerId: to } : {}
|
|
451
|
-
})));
|
|
452
|
-
return true;
|
|
453
|
-
}, this.lockWaitMs);
|
|
454
|
-
}
|
|
455
|
-
/** Whether there was a list to turn off. */
|
|
456
|
-
off() {
|
|
457
|
-
return this.#locked(() => {
|
|
458
|
-
if (!existsSync(this.path))
|
|
459
|
-
return false;
|
|
460
|
-
rmSync(this.path);
|
|
461
|
-
return true;
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Every change reads and writes under one lock: a `serve` re-keying while the owner removes a chat must not write
|
|
466
|
-
* the removed chat back. A lock held too long refuses the change and leaves the list as it was. Blocks the thread
|
|
467
|
-
* while it waits: for callers that cannot be async, and `recipients remove` and `clear`, which never
|
|
468
|
-
* connect and so never run inside `serve`.
|
|
469
|
-
*/
|
|
470
|
-
#locked(body) {
|
|
471
|
-
return withFileLock(this.path, "the recipient list", body, this.lockWaitMs);
|
|
472
|
-
}
|
|
473
|
-
#write(chats) {
|
|
474
|
-
writeSecurely(this.path, `${JSON.stringify({ chats }, null, 2)}
|
|
475
|
-
`, 384);
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/guard.js
|
|
480
|
-
var HOUR_MS = 60 * 60 * 1e3;
|
|
481
|
-
var READS_UNDER_HOLD = /* @__PURE__ */ new Set([
|
|
482
|
-
"attachments.extract",
|
|
483
|
-
"conversations.embeddings",
|
|
484
|
-
"conversations.links",
|
|
485
|
-
"messages.server-search",
|
|
486
|
-
"messages.sync-first",
|
|
487
|
-
"stats.contacts.top.sync-first",
|
|
488
|
-
"stats.messages.counters.sync",
|
|
489
|
-
"stats.messages.show.sync-first",
|
|
490
|
-
"stats.messages.top.sync-first",
|
|
491
|
-
"store.gaps.repair"
|
|
492
|
-
]);
|
|
493
|
-
var countsTowardLimit = /* @__PURE__ */ __name(({ kind = "message", action, notify }) => kind === "message" || kind === "forward" || kind === "edit" || kind === "delete" || kind === "pin" && notify === true || action === "create" || action === "members.add" || action === "requests.accept" || action === "join" || action === "contact-import", "countsTowardLimit");
|
|
494
|
-
var weightOf = /* @__PURE__ */ __name(({ kind = "message", action, count, people }) => kind === "delete" || kind === "message" && action === void 0 ? Math.max(1, count ?? 1) : action === "create" || action === "members.add" || action === "requests.accept" || action === "contact-import" ? Math.max(1, people ?? count ?? 1) : 1, "weightOf");
|
|
495
|
-
var timeOf = /* @__PURE__ */ __name((entry) => Date.parse(entry.scheduledFor ?? entry.at), "timeOf");
|
|
496
|
-
var ceilingRefusal = /* @__PURE__ */ __name((key, command) => new CliError("permission_error", `${key} is not allowed: setup's answer keeps every WireCat tool read-only; the owner changes it at a terminal with \`${command} setup\``, { permission: key }), "ceilingRefusal");
|
|
497
|
-
var levelRefusal = /* @__PURE__ */ __name((refused, fix = `${refused.command} ${refused.profile} config set permissions.${refused.key} allow`) => refused.named === CEILING_KEY ? ceilingRefusal(refused.key, refused.command) : new CliError("permission_error", `profile ${refused.profile} does not let ${refused.key} write (permissions.${refused.named} is ${refused.level}, from the ${refused.permissionSources[refused.named ?? ""] ?? "default"}); to allow it: ${fix}`, { permission: refused.key }), "levelRefusal");
|
|
498
|
-
var sendGuard = /* @__PURE__ */ __name(({ profile, recipients, command = recipients.command, readOnlyLock, permissions, permissionSources = {}, permissionDefaults, permissionFix, ask = refuseToAsk, sendsPerHour, journal, flood, warn, now = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now") }) => {
|
|
499
|
-
const currentPermissions = /* @__PURE__ */ __name(() => typeof permissions === "function" ? permissions() : permissions, "currentPermissions");
|
|
500
|
-
let reservation;
|
|
501
|
-
const answered = /* @__PURE__ */ new WeakSet();
|
|
502
|
-
const refuseReadOnly = /* @__PURE__ */ __name(() => {
|
|
503
|
-
if (readOnlyLock)
|
|
504
|
-
throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
|
|
505
|
-
}, "refuseReadOnly");
|
|
506
|
-
const refuseHeld = /* @__PURE__ */ __name(({ key }) => {
|
|
507
|
-
if (key !== void 0 && READS_UNDER_HOLD.has(key))
|
|
508
|
-
return;
|
|
509
|
-
const block = flood?.sendBlock();
|
|
510
|
-
if (!block)
|
|
511
|
-
return;
|
|
512
|
-
throw new CliError("permission_error", `profile ${profile} holds its writes ${holdEnd(block)}: ${block.hint} \u2014 reads still work; do not retry: the owner checks the account with \`${command} ${profile} doctor --online\`, and lifts the hold with \`${command} ${profile} flood clear\` once it is over`, { sendBlock: block, standing: { state: block.state, hint: block.hint } });
|
|
513
|
-
}, "refuseHeld");
|
|
514
|
-
const permitted = /* @__PURE__ */ __name((request) => {
|
|
515
|
-
const { chatId, kind = "message", action, personIds } = request;
|
|
516
|
-
refuseReadOnly();
|
|
517
|
-
const levels = currentPermissions();
|
|
518
|
-
if (levels !== void 0) {
|
|
519
|
-
const key = request.key ?? keyForWrite(kind, action);
|
|
520
|
-
const { level, key: named } = levelFor(levels, key, permissionDefaults);
|
|
521
|
-
if (level === "deny" || level === "readonly")
|
|
522
|
-
throw levelRefusal({ profile, command, key, level, named, permissionSources }, permissionFix?.(request, key));
|
|
523
|
-
if (level === "ask" && !answered.has(request)) {
|
|
524
|
-
throw new CliError("confirmation_required", `${key} asks before it acts, and it was not asked`);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const allowed = recipients.read();
|
|
528
|
-
if (chatId !== null && allowed && !allowed.some((chat) => chat.id === chatId)) {
|
|
529
|
-
throw new CliError("confirmation_required", `chat ${chatId} is not on the recipient list of profile ${profile} \u2014 the owner adds it with \`${command} ${profile} recipients add ${chatId}\``, { chat_id: chatId });
|
|
530
|
-
}
|
|
531
|
-
const strangers = allowed ? (personIds ?? []).filter((id) => !allowed.some((chat) => chat.partnerId === id)) : [];
|
|
532
|
-
if (strangers.length > 0) {
|
|
533
|
-
throw new CliError("confirmation_required", `${strangers.join(", ")} ${strangers.length === 1 ? "is" : "are"} not on the recipient list of profile ${profile} \u2014 the owner adds the one-to-one chat with each person (\`${command} ${profile} recipients add <chat>\`); a chat added to the list earlier is added again to be recognised`, { person_ids: strangers });
|
|
534
|
-
}
|
|
535
|
-
}, "permitted");
|
|
536
|
-
const withinLimit = /* @__PURE__ */ __name((request, entries) => {
|
|
537
|
-
const { chatId, sendId } = request;
|
|
538
|
-
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
539
|
-
const count = weightOf(asked);
|
|
540
|
-
if (count > sendsPerHour) {
|
|
541
|
-
throw new CliError("rate_limited", `${count} at once is more than the hourly limit of profile ${profile} (sendsPerHour ${sendsPerHour}) \u2014 do fewer at a time`);
|
|
542
|
-
}
|
|
543
|
-
const at = request.scheduledFor ? Date.parse(request.scheduledFor) : now().getTime();
|
|
544
|
-
const counted = entries.filter(countsTowardLimit).filter((entry) => entry.outcome === "sent" || entry.outcome === "outcome_unknown" || entry.outcome === "reserved").filter((entry) => Math.abs(timeOf(entry) - at) < HOUR_MS);
|
|
545
|
-
const unsure = /* @__PURE__ */ __name((entry) => entry.outcome === "outcome_unknown", "unsure");
|
|
546
|
-
const same = /* @__PURE__ */ __name((a, b) => a.sendId !== void 0 && a.sendId === b.sendId && a.chatId === b.chatId, "same");
|
|
547
|
-
const last = [...counted].reverse().find((entry) => same(entry, { chatId, sendId }));
|
|
548
|
-
if (sendId !== void 0 && last && unsure(last)) {
|
|
549
|
-
if (last.sendAs !== request.sendAs) {
|
|
550
|
-
throw new CliError("validation_error", "this send id was tried under another identity; repeat it with the same --send-as, or it may post twice", { operation_id: sendId, retryable: false });
|
|
551
|
-
}
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
const recent = counted.filter((entry, index) => !(unsure(entry) && counted.slice(index + 1).some((later) => same(later, entry)))).map((entry) => ({ time: timeOf(entry), weight: weightOf(entry) })).sort((a, b) => a.time - b.time);
|
|
555
|
-
const used = recent.reduce((sum, { weight }) => sum + weight, 0);
|
|
556
|
-
if (used + count > sendsPerHour) {
|
|
557
|
-
let freed = 0;
|
|
558
|
-
const opening = recent.find(({ weight }) => {
|
|
559
|
-
freed += weight;
|
|
560
|
-
return used - freed + count <= sendsPerHour;
|
|
561
|
-
});
|
|
562
|
-
const nextMs = (opening?.time ?? 0) + HOUR_MS;
|
|
563
|
-
const next = new Date(nextMs).toISOString();
|
|
564
|
-
throw new CliError("rate_limited", `profile ${profile} has sent ${used} messages in the hour around ${new Date(at).toISOString()}, and its limit is ${sendsPerHour} (sendsPerHour) \u2014 the next send is possible at ${next}`, { retry_after_ms: nextMs - now().getTime(), retry_at: next });
|
|
565
|
-
}
|
|
566
|
-
return true;
|
|
567
|
-
}, "withinLimit");
|
|
568
|
-
const counting = /* @__PURE__ */ __name((request) => {
|
|
569
|
-
permitted(request);
|
|
570
|
-
refuseHeld(request);
|
|
571
|
-
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
572
|
-
const creatingTopic = request.kind === "chat" && request.action === "topic-create";
|
|
573
|
-
if (!countsTowardLimit(asked) && !creatingTopic)
|
|
574
|
-
return void 0;
|
|
575
|
-
const checked = /* @__PURE__ */ __name((entries) => {
|
|
576
|
-
if (!creatingTopic)
|
|
577
|
-
return withinLimit(request, entries);
|
|
578
|
-
if (request.sendId === void 0)
|
|
579
|
-
throw new CliError("validation_error", "a topic creation needs an attempt id");
|
|
580
|
-
if (entries.some((entry) => entry.action === "topic-create" && entry.sendId === request.sendId && ["sent", "outcome_unknown", "reserved"].includes(entry.outcome))) {
|
|
581
|
-
throw new CliError("validation_error", "this topic creation was already attempted; check topics list and do not repeat an unknown creation", { operation_id: request.sendId, retryable: false });
|
|
582
|
-
}
|
|
583
|
-
return true;
|
|
584
|
-
}, "checked");
|
|
585
|
-
const reserving = /* @__PURE__ */ __name(() => {
|
|
586
|
-
if (!checked(journal.entries()))
|
|
587
|
-
return;
|
|
588
|
-
const id = randomUUID();
|
|
589
|
-
const { chatId, kind, action, sendId, operationId, scheduledFor, notify } = request;
|
|
590
|
-
journal.append({
|
|
591
|
-
at: now().toISOString(),
|
|
592
|
-
profile,
|
|
593
|
-
chatId,
|
|
594
|
-
outcome: "reserved",
|
|
595
|
-
reservation: id,
|
|
596
|
-
...kind ? { kind } : {},
|
|
597
|
-
...action ? { action } : {},
|
|
598
|
-
...asked.people === void 0 ? {} : kind === "delete" || kind === "message" || kind === void 0 ? { count: asked.people } : { people: asked.people },
|
|
599
|
-
...sendId === void 0 ? {} : { sendId },
|
|
600
|
-
...operationId === void 0 ? {} : { operationId },
|
|
601
|
-
...scheduledFor ? { scheduledFor } : {},
|
|
602
|
-
...notify === void 0 ? {} : { notify }
|
|
603
|
-
});
|
|
604
|
-
reservation = id;
|
|
605
|
-
}, "reserving");
|
|
606
|
-
return { checked, reserving };
|
|
607
|
-
}, "counting");
|
|
608
|
-
return {
|
|
609
|
-
ask: /* @__PURE__ */ __name(async (request) => {
|
|
610
|
-
refuseReadOnly();
|
|
611
|
-
const levels = currentPermissions();
|
|
612
|
-
if (levels === void 0)
|
|
613
|
-
return;
|
|
614
|
-
const key = request.key ?? keyForWrite(request.kind ?? "message", request.action);
|
|
615
|
-
if (levelFor(levels, key, permissionDefaults).level !== "ask")
|
|
616
|
-
return;
|
|
617
|
-
refuseHeld(request);
|
|
618
|
-
await ask(key, request);
|
|
619
|
-
answered.add(request);
|
|
620
|
-
}, "ask"),
|
|
621
|
-
check: /* @__PURE__ */ __name((request, { reserve = true } = {}) => {
|
|
622
|
-
const counted = counting(request);
|
|
623
|
-
if (!counted)
|
|
624
|
-
return;
|
|
625
|
-
if (reserve)
|
|
626
|
-
journal.locked(counted.reserving);
|
|
627
|
-
else
|
|
628
|
-
counted.checked(journal.entries());
|
|
629
|
-
}, "check"),
|
|
630
|
-
reserve: /* @__PURE__ */ __name(async (request) => {
|
|
631
|
-
const counted = counting(request);
|
|
632
|
-
if (counted)
|
|
633
|
-
await journal.lockedAsync(counted.reserving);
|
|
634
|
-
}, "reserve"),
|
|
635
|
-
// After a send, a failure to write here must not become the command's answer: the message is
|
|
636
|
-
// already with a person, and an error would invite the caller to send it again.
|
|
637
|
-
record: /* @__PURE__ */ __name((entry) => {
|
|
638
|
-
const { personIds: _, ...kept } = entry;
|
|
639
|
-
const settles = entry.outcome === "refused" ? void 0 : reservation;
|
|
640
|
-
reservation = void 0;
|
|
641
|
-
try {
|
|
642
|
-
journal.append({ at: now().toISOString(), profile, ...kept, ...settles ? { reservation: settles } : {} });
|
|
643
|
-
} catch (error) {
|
|
644
|
-
warn(`this send is not in the send journal: ${journalFailure(error)}`, {
|
|
645
|
-
event: "warning",
|
|
646
|
-
code: "send_not_journaled",
|
|
647
|
-
operation: "sends.journal"
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
}, "record")
|
|
651
|
-
};
|
|
652
|
-
}, "sendGuard");
|
|
653
|
-
var refuseToAsk = /* @__PURE__ */ __name(async (key) => {
|
|
654
|
-
throw new CliError("confirmation_required", `${key} asks before it acts (its permission level is ask), and nobody is here to answer \u2014 add ${skipFlagFor(key)} to go ahead`);
|
|
655
|
-
}, "refuseToAsk");
|
|
656
|
-
var guardFor = /* @__PURE__ */ __name((app, settings, warn, env = process.env, ask) => sendGuard({
|
|
657
|
-
profile: settings.profile,
|
|
658
|
-
command: app.command,
|
|
659
|
-
...settings.readOnlyLock ? { readOnlyLock: settings.readOnlyLock } : {},
|
|
660
|
-
permissions: /* @__PURE__ */ __name(() => settings.permissions, "permissions"),
|
|
661
|
-
permissionSources: settings.permissionSources,
|
|
662
|
-
...settings.permissionDefaults ? { permissionDefaults: settings.permissionDefaults } : {},
|
|
663
|
-
...ask ? { ask } : {},
|
|
664
|
-
sendsPerHour: settings.sendsPerHour,
|
|
665
|
-
journal: new SendJournal(sendsPathFor(app, settings.profile, env), { service: app.command, version: app.version }),
|
|
666
|
-
recipients: new RecipientList(recipientsPathFor(app, settings.profile, env), app.command),
|
|
667
|
-
flood: new FloodMemory(floodPathFor(app, settings.profile, env)),
|
|
668
|
-
warn
|
|
669
|
-
}), "guardFor");
|
|
670
|
-
var journalFailure = /* @__PURE__ */ __name((error) => error?.code ?? (error instanceof Error ? error.name : "error"), "journalFailure");
|
|
671
|
-
|
|
672
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sends/pace.js
|
|
673
|
-
import { readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
674
|
-
import { join as join4 } from "node:path";
|
|
675
|
-
var DEFAULT_PACE = { perMinute: 60, burst: 20 };
|
|
676
|
-
var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
|
|
677
|
-
var Pacer = class {
|
|
678
|
-
static {
|
|
679
|
-
__name(this, "Pacer");
|
|
680
|
-
}
|
|
681
|
-
path;
|
|
682
|
-
rate;
|
|
683
|
-
now;
|
|
684
|
-
constructor(path, rate, now = Date.now) {
|
|
685
|
-
this.path = path;
|
|
686
|
-
this.rate = rate;
|
|
687
|
-
this.now = now;
|
|
688
|
-
}
|
|
689
|
-
get interval() {
|
|
690
|
-
return this.rate.perMinute > 0 ? 6e4 / this.rate.perMinute : 0;
|
|
691
|
-
}
|
|
692
|
-
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
693
|
-
async reserve() {
|
|
694
|
-
const now = this.now();
|
|
695
|
-
if (this.interval === 0)
|
|
696
|
-
return now;
|
|
697
|
-
return withFileLockAsync(this.path, "the request pace", () => {
|
|
698
|
-
const tat = Math.max(this.read(), now);
|
|
699
|
-
this.write(tat + this.interval);
|
|
700
|
-
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
/** The messenger asked every caller to wait: nothing goes before `now + waitMs`, in any process. */
|
|
704
|
-
async holdFor(waitMs) {
|
|
705
|
-
if (this.interval === 0)
|
|
706
|
-
return;
|
|
707
|
-
await withFileLockAsync(this.path, "the request pace", () => {
|
|
708
|
-
const hold = this.now() + waitMs + this.rate.burst * this.interval;
|
|
709
|
-
this.write(Math.max(this.read(), hold));
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
/** The owner's `flood clear`: every process may go again at once. */
|
|
713
|
-
async reset() {
|
|
714
|
-
await withFileLockAsync(this.path, "the request pace", () => this.write(0));
|
|
715
|
-
}
|
|
716
|
-
read() {
|
|
717
|
-
try {
|
|
718
|
-
const tat = Number(JSON.parse(readFileSync4(this.path, "utf8")).tat);
|
|
719
|
-
return Number.isFinite(tat) ? tat : 0;
|
|
720
|
-
} catch {
|
|
721
|
-
return 0;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
write(tat) {
|
|
725
|
-
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
726
|
-
writeFileSync2(temporary, JSON.stringify({ tat }), { mode: 384 });
|
|
727
|
-
renameSync2(temporary, this.path);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
var ANNOUNCE_WAIT_MS = 5e3;
|
|
731
|
-
var LONGEST_PACE_WAIT_MS = 5 * 6e4;
|
|
732
|
-
var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
|
|
733
|
-
const { name, operation, warn } = options;
|
|
734
|
-
const now = options.now ?? Date.now;
|
|
735
|
-
let at = now();
|
|
736
|
-
try {
|
|
737
|
-
at = await pacer.reserve();
|
|
738
|
-
} catch (error) {
|
|
739
|
-
warn?.(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
740
|
-
event: "warning",
|
|
741
|
-
code: "wait_not_remembered",
|
|
742
|
-
operation
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
const waitMs = at - now();
|
|
746
|
-
if (waitMs <= 0)
|
|
747
|
-
return;
|
|
748
|
-
if (waitMs > LONGEST_PACE_WAIT_MS)
|
|
749
|
-
throw new CliError("rate_limited", `${name} asked this profile to wait, ${Math.ceil(waitMs / 1e3)} s are left \u2014 nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
750
|
-
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
751
|
-
const seconds = Math.ceil(waitMs / 1e3);
|
|
752
|
-
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
|
753
|
-
event: "warning",
|
|
754
|
-
code: "pace_wait",
|
|
755
|
-
operation,
|
|
756
|
-
counts: { seconds }
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
|
|
760
|
-
}, "waitForTurn");
|
|
761
|
-
|
|
762
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
|
|
129
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
|
|
763
130
|
var HOUSEKEEPING = /* @__PURE__ */ new Set([
|
|
764
131
|
"help",
|
|
765
132
|
"guide",
|
|
@@ -773,7 +140,7 @@ var HOUSEKEEPING = /* @__PURE__ */ new Set([
|
|
|
773
140
|
"mcp",
|
|
774
141
|
"runs"
|
|
775
142
|
]);
|
|
776
|
-
var commandPathKey = /* @__PURE__ */ __name((path) => path[0] === void 0 || HOUSEKEEPING.has(path[0]) ? null : path.join("."), "commandPathKey");
|
|
143
|
+
var commandPathKey = /* @__PURE__ */ __name((path) => path[0] === void 0 || HOUSEKEEPING.has(path[0]) && !KEYED_UNDER_HOUSEKEEPING.has(path.join(".")) ? null : path.join("."), "commandPathKey");
|
|
777
144
|
var commandPermissions = /* @__PURE__ */ __name(({ keyOf = commandPathKey, extra = [], defaults = {}, alsoChecks } = {}) => ({
|
|
778
145
|
keyOf,
|
|
779
146
|
extra: [AUTHORITY_KEY, ...extra],
|
|
@@ -839,203 +206,7 @@ var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, too
|
|
|
839
206
|
throw new CliError("validation_error", `--permission ${key} names no command`, { permission: key });
|
|
840
207
|
}, "refuseUnknownPermissionKeys");
|
|
841
208
|
|
|
842
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
843
|
-
var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
|
|
844
|
-
var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
|
|
845
|
-
var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
|
|
846
|
-
var chatOf = /* @__PURE__ */ __name((args) => typeof args[0] === "string" && /^-?\d+$/.test(args[0]) ? args[0] : void 0, "chatOf");
|
|
847
|
-
var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer }) => {
|
|
848
|
-
const kept = /* @__PURE__ */ __name(async (operation, what2) => {
|
|
849
|
-
try {
|
|
850
|
-
await what2();
|
|
851
|
-
} catch (error) {
|
|
852
|
-
warn(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
853
|
-
event: "warning",
|
|
854
|
-
code: "wait_not_remembered",
|
|
855
|
-
operation
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
}, "kept");
|
|
859
|
-
const noted = /* @__PURE__ */ __name(async (operation, chatId, error) => {
|
|
860
|
-
if (!isCliFailure(error))
|
|
861
|
-
return;
|
|
862
|
-
const details = error.details ?? {};
|
|
863
|
-
const standing = details.standing;
|
|
864
|
-
if (standing && BLOCKING.has(standing.state)) {
|
|
865
|
-
await kept(operation, () => {
|
|
866
|
-
const block = memory.block({
|
|
867
|
-
state: standing.state,
|
|
868
|
-
hint: standing.hint ?? error.message,
|
|
869
|
-
...standing.until ? { until: standing.until } : {}
|
|
870
|
-
});
|
|
871
|
-
warn(`writes from this profile are held ${holdEnd(block)}: ${block.hint}`, {
|
|
872
|
-
event: "warning",
|
|
873
|
-
code: `account_${block.state}`,
|
|
874
|
-
operation
|
|
875
|
-
});
|
|
876
|
-
});
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
const waitMs = Number(details.retry_after_ms);
|
|
880
|
-
if (error.code !== "rate_limited" || details.remembered === true || !Number.isFinite(waitMs) || waitMs <= 0)
|
|
881
|
-
return;
|
|
882
|
-
const providerError = providerErrorKey(details.provider_error);
|
|
883
|
-
await kept(operation, () => {
|
|
884
|
-
const deadline = memory.remember({
|
|
885
|
-
operation,
|
|
886
|
-
...chatId ? { chatId } : {},
|
|
887
|
-
...providerError ? { providerError } : {},
|
|
888
|
-
waitMs
|
|
889
|
-
});
|
|
890
|
-
warn(`${name} asked to wait before ${operation} again \u2014 until ${deadline.until}`, {
|
|
891
|
-
event: "warning",
|
|
892
|
-
code: "flood_wait",
|
|
893
|
-
operation,
|
|
894
|
-
counts: { seconds: Math.ceil(waitMs / 1e3) }
|
|
895
|
-
});
|
|
896
|
-
});
|
|
897
|
-
if (pacer)
|
|
898
|
-
await kept(operation, () => pacer.holdFor(waitMs));
|
|
899
|
-
}, "noted");
|
|
900
|
-
const turn = /* @__PURE__ */ __name(async (operation) => {
|
|
901
|
-
if (pacer)
|
|
902
|
-
await waitForTurn(pacer, { name, operation, warn });
|
|
903
|
-
}, "turn");
|
|
904
|
-
return throughWrapper(messenger, {}, (operation, call) => {
|
|
905
|
-
if (LONG_LIVED.has(operation))
|
|
906
|
-
return call;
|
|
907
|
-
if (LISTENING.has(operation))
|
|
908
|
-
return (async (...args) => {
|
|
909
|
-
try {
|
|
910
|
-
return await call(...args);
|
|
911
|
-
} catch (error) {
|
|
912
|
-
await noted(operation, void 0, error);
|
|
913
|
-
throw error;
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
return (async (...args) => {
|
|
917
|
-
const chatId = chatOf(args);
|
|
918
|
-
const owed = memory.owed(operation, chatId);
|
|
919
|
-
if (owed) {
|
|
920
|
-
const waitMs = Math.max(0, Date.parse(owed.until) - Date.now());
|
|
921
|
-
throw new CliError("rate_limited", `${name} asked to wait before ${operation} again, ${Math.ceil(waitMs / 1e3)} s are left \u2014 nothing was sent to ${name}`, {
|
|
922
|
-
retry_after_ms: waitMs,
|
|
923
|
-
retry_at: owed.until,
|
|
924
|
-
remembered: true,
|
|
925
|
-
...owed.providerError ? { provider_error: owed.providerError } : {}
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
await turn(operation);
|
|
929
|
-
try {
|
|
930
|
-
return await call(...args);
|
|
931
|
-
} catch (error) {
|
|
932
|
-
await noted(operation, chatId, error);
|
|
933
|
-
throw error;
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
});
|
|
937
|
-
}, "flooded");
|
|
938
|
-
|
|
939
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
|
|
940
|
-
var observed = /* @__PURE__ */ __name((messenger, events) => {
|
|
941
|
-
const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
|
|
942
|
-
const write = currentOperation();
|
|
943
|
-
const marked = /* @__PURE__ */ __name((part = {}) => write === void 0 ? part : { ...part, ids: { ...part.ids, operation: write } }, "marked");
|
|
944
|
-
events({ event: "request", operation, level: "operation", ...marked(named) });
|
|
945
|
-
const started = performance.now();
|
|
946
|
-
const durationMs = /* @__PURE__ */ __name(() => Math.round(performance.now() - started), "durationMs");
|
|
947
|
-
try {
|
|
948
|
-
const answer = await work();
|
|
949
|
-
events({
|
|
950
|
-
event: "response",
|
|
951
|
-
operation,
|
|
952
|
-
level: "operation",
|
|
953
|
-
durationMs: durationMs(),
|
|
954
|
-
outcome: "ok",
|
|
955
|
-
...marked(after?.(answer))
|
|
956
|
-
});
|
|
957
|
-
return answer;
|
|
958
|
-
} catch (error) {
|
|
959
|
-
const providerError = isCliFailure(error) ? providerErrorKey(error.details?.provider_error) : void 0;
|
|
960
|
-
events({
|
|
961
|
-
event: "response",
|
|
962
|
-
operation,
|
|
963
|
-
level: "operation",
|
|
964
|
-
durationMs: durationMs(),
|
|
965
|
-
outcome: "error",
|
|
966
|
-
errorCode: isCliFailure(error) ? error.code : "generic_failure",
|
|
967
|
-
...providerError ? { providerError } : {},
|
|
968
|
-
...marked()
|
|
969
|
-
});
|
|
970
|
-
throw error;
|
|
971
|
-
}
|
|
972
|
-
}, "timed");
|
|
973
|
-
const counted = /* @__PURE__ */ __name(async (operation, onItem, work, count) => {
|
|
974
|
-
const counts = {};
|
|
975
|
-
await timed(operation, {}, () => work((item, ...rest) => {
|
|
976
|
-
count(item, counts);
|
|
977
|
-
return onItem(item, ...rest);
|
|
978
|
-
}), () => ({ counts }));
|
|
979
|
-
}, "counted");
|
|
980
|
-
const mint = messenger.newSendId;
|
|
981
|
-
const { chats, history, contact, around, watch, feed, listen, listenHistory } = messenger;
|
|
982
|
-
return throughWrapper(messenger, {
|
|
983
|
-
self: /* @__PURE__ */ __name(() => messenger.self(), "self"),
|
|
984
|
-
...mint ? { newSendId: /* @__PURE__ */ __name(() => mint.call(messenger), "newSendId") } : {},
|
|
985
|
-
me: /* @__PURE__ */ __name(() => timed("account.me", {}, () => messenger.me()), "me"),
|
|
986
|
-
...chats ? {
|
|
987
|
-
chats: /* @__PURE__ */ __name((window) => timed("chats.list", {}, () => chats.call(messenger, window), (page) => ({ counts: { chats: page.items.length } })), "chats")
|
|
988
|
-
} : {},
|
|
989
|
-
...history ? {
|
|
990
|
-
history: /* @__PURE__ */ __name((reference, options) => timed("messages.list", {}, () => history.call(messenger, reference, options), (page) => ({
|
|
991
|
-
...page.items[0] ? { ids: { chat: page.items[0].chatId } } : {},
|
|
992
|
-
counts: { messages: page.items.length }
|
|
993
|
-
})), "history")
|
|
994
|
-
} : {},
|
|
995
|
-
resolve: /* @__PURE__ */ __name((reference) => timed("chats.resolve", {}, () => messenger.resolve(reference), (chat) => ({ ids: { chat: chat.id } })), "resolve"),
|
|
996
|
-
chat: /* @__PURE__ */ __name((reference) => timed("chats.show", {}, () => messenger.chat(reference), (card) => ({ ids: { chat: card.id }, ...card.members ? { counts: { members: card.members.length } } : {} })), "chat"),
|
|
997
|
-
...contact ? {
|
|
998
|
-
contact: /* @__PURE__ */ __name((reference) => timed("contacts.show", {}, () => contact.call(messenger, reference), (card) => ({ ids: { person: card.id }, counts: { chats: card.chats.length } })), "contact")
|
|
999
|
-
} : {},
|
|
1000
|
-
...around ? {
|
|
1001
|
-
around: /* @__PURE__ */ __name((reference, messageId, window) => timed("messages.around", { ids: { message_id: messageId } }, () => around.call(messenger, reference, messageId, window), (items) => ({
|
|
1002
|
-
...items[0] ? { ids: { chat: items[0].chatId, message_id: messageId } } : {},
|
|
1003
|
-
counts: { messages: items.length }
|
|
1004
|
-
})), "around")
|
|
1005
|
-
} : {},
|
|
1006
|
-
send: /* @__PURE__ */ __name((chatId, text, options) => timed("messages.send", {
|
|
1007
|
-
ids: {
|
|
1008
|
-
chat: chatId,
|
|
1009
|
-
send: options.sendId,
|
|
1010
|
-
...options.replyTo ? { reply: options.replyTo } : {},
|
|
1011
|
-
...options.threadId ? { thread: options.threadId } : {}
|
|
1012
|
-
}
|
|
1013
|
-
}, () => messenger.send(chatId, text, options), (sent) => ({ ids: { chat: sent.message.chatId || chatId, message_id: sent.message.id } })), "send"),
|
|
1014
|
-
...watch ? {
|
|
1015
|
-
watch: /* @__PURE__ */ __name((onEvent, signal, onReady) => counted("messages.watch", onEvent, (counting) => watch.call(messenger, counting, signal, onReady), byEvent), "watch")
|
|
1016
|
-
} : {},
|
|
1017
|
-
...feed ? { feed: /* @__PURE__ */ __name((onBatch, signal) => timed("history.feed", {}, () => feed.call(messenger, onBatch, signal)), "feed") } : {},
|
|
1018
|
-
...listen ? {
|
|
1019
|
-
listen: /* @__PURE__ */ __name((onEvent, signal) => counted("messages.listen", onEvent, (counting) => listen.call(messenger, counting, signal), byEvent), "listen")
|
|
1020
|
-
} : {},
|
|
1021
|
-
...listenHistory ? {
|
|
1022
|
-
listenHistory: /* @__PURE__ */ __name((onBatch, signal) => counted("history.listen", onBatch, (counting) => listenHistory.call(messenger, counting, signal), byPart), "listenHistory")
|
|
1023
|
-
} : {},
|
|
1024
|
-
logout: /* @__PURE__ */ __name(() => timed("session.logout", {}, () => messenger.logout()), "logout"),
|
|
1025
|
-
close: /* @__PURE__ */ __name(() => messenger.close(), "close")
|
|
1026
|
-
}, (name, call) => (...args) => timed(`adapter.${name}`, {}, () => call(...args)));
|
|
1027
|
-
}, "observed");
|
|
1028
|
-
var byEvent = /* @__PURE__ */ __name((event, counts) => {
|
|
1029
|
-
counts[event.event] = (counts[event.event] ?? 0) + 1;
|
|
1030
|
-
}, "byEvent");
|
|
1031
|
-
var byPart = /* @__PURE__ */ __name((batch, counts) => {
|
|
1032
|
-
counts.batches = (counts.batches ?? 0) + 1;
|
|
1033
|
-
for (const [part, items] of Object.entries(batch))
|
|
1034
|
-
if (Array.isArray(items) && items.length > 0)
|
|
1035
|
-
counts[part] = (counts[part] ?? 0) + items.length;
|
|
1036
|
-
}, "byPart");
|
|
1037
|
-
|
|
1038
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
|
|
209
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
|
|
1039
210
|
var REKEY_PACING = { lockMs: 50, pauseMs: 25 };
|
|
1040
211
|
var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, rekeyPacing = REKEY_PACING, closing, namesFromStore, recipientIds, countsUnread = false, historyLimits, command = "cli" }) => {
|
|
1041
212
|
let warned = false;
|
|
@@ -1156,13 +327,13 @@ var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events,
|
|
|
1156
327
|
}
|
|
1157
328
|
if (round !== rekeyRound)
|
|
1158
329
|
return;
|
|
1159
|
-
const
|
|
1160
|
-
rekeysQueued -=
|
|
330
|
+
const taken = pass?.taken ?? rest.length;
|
|
331
|
+
rekeysQueued -= taken;
|
|
1161
332
|
for (const { from, to } of pass?.applied ?? [])
|
|
1162
333
|
await Promise.resolve().then(() => rekeyed?.(from, to)).catch((error) => notWritten("history.rekey", error));
|
|
1163
334
|
for (const { error } of pass?.refused ?? [])
|
|
1164
335
|
notWritten("history.rekey", error);
|
|
1165
|
-
rest = rest.slice(
|
|
336
|
+
rest = rest.slice(taken);
|
|
1166
337
|
if (rest.length > 0)
|
|
1167
338
|
await new Promise((resolve) => setTimeout(resolve, rekeyPacing.pauseMs));
|
|
1168
339
|
}
|
|
@@ -1586,32 +757,323 @@ var keep = /* @__PURE__ */ __name(async (store, account, event, seenAt, among, c
|
|
|
1586
757
|
seenAt,
|
|
1587
758
|
...countsUnread && event.event === "message" ? { countUnread: true } : {}
|
|
1588
759
|
});
|
|
1589
|
-
return;
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
case "delete":
|
|
763
|
+
await store.messages.markDeleted(account, [event.messageId], event.chatId === null ? among ? { among } : {} : { chatId: event.chatId });
|
|
764
|
+
return;
|
|
765
|
+
case "vote":
|
|
766
|
+
await store.messages.saveVote(account, event.chatId, event.messageId, event.vote);
|
|
767
|
+
return;
|
|
768
|
+
case "person_reaction":
|
|
769
|
+
await store.messages.saveReaction(account, event.chatId, event.messageId, event.reaction);
|
|
770
|
+
return;
|
|
771
|
+
case "star":
|
|
772
|
+
await store.messages.saveStar(account, event.chatId, event.messageId, event.starred);
|
|
773
|
+
return;
|
|
774
|
+
case "delivery":
|
|
775
|
+
await store.messages.saveDelivery(account, event.chatId, event.messageId, event.delivery);
|
|
776
|
+
return;
|
|
777
|
+
case "chat_event":
|
|
778
|
+
await store.roster.saveChatEvents(account, event.chatId, [event.change]);
|
|
779
|
+
return;
|
|
780
|
+
case "reaction":
|
|
781
|
+
await store.messages.saveReactions(account, event.chatId, event.messageId, event.reactions, event.counterObservation ? { observation: event.counterObservation } : {});
|
|
782
|
+
}
|
|
783
|
+
}, "keep");
|
|
784
|
+
|
|
785
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/sends/pace.js
|
|
786
|
+
import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
787
|
+
import { join } from "node:path";
|
|
788
|
+
var DEFAULT_PACE = { perMinute: 60, burst: 20 };
|
|
789
|
+
var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
|
|
790
|
+
var Pacer = class {
|
|
791
|
+
static {
|
|
792
|
+
__name(this, "Pacer");
|
|
793
|
+
}
|
|
794
|
+
path;
|
|
795
|
+
rate;
|
|
796
|
+
now;
|
|
797
|
+
constructor(path, rate, now = Date.now) {
|
|
798
|
+
this.path = path;
|
|
799
|
+
this.rate = rate;
|
|
800
|
+
this.now = now;
|
|
801
|
+
}
|
|
802
|
+
get interval() {
|
|
803
|
+
return this.rate.perMinute > 0 ? 6e4 / this.rate.perMinute : 0;
|
|
804
|
+
}
|
|
805
|
+
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
806
|
+
async reserve() {
|
|
807
|
+
if (this.interval === 0)
|
|
808
|
+
return this.now();
|
|
809
|
+
return withFileLockAsync(this.path, "the request pace", () => {
|
|
810
|
+
const now = this.now();
|
|
811
|
+
const tat = Math.max(this.read(now), now);
|
|
812
|
+
this.write(tat + this.interval, now);
|
|
813
|
+
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
/** The messenger asked every caller to wait: nothing goes before `now + waitMs`, in any process. */
|
|
817
|
+
async holdFor(waitMs) {
|
|
818
|
+
if (this.interval === 0)
|
|
819
|
+
return;
|
|
820
|
+
await withFileLockAsync(this.path, "the request pace", () => {
|
|
821
|
+
const now = this.now();
|
|
822
|
+
const hold = now + waitMs + this.rate.burst * this.interval;
|
|
823
|
+
this.write(Math.max(this.read(now), hold), now);
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
/** The owner's `flood clear`: every process may go again at once. */
|
|
827
|
+
async reset() {
|
|
828
|
+
await withFileLockAsync(this.path, "the request pace", () => this.write(0, this.now()));
|
|
829
|
+
}
|
|
830
|
+
read(now) {
|
|
831
|
+
try {
|
|
832
|
+
const file = JSON.parse(readFileSync(this.path, "utf8"));
|
|
833
|
+
const tat = Number(file.tat);
|
|
834
|
+
if (!Number.isFinite(tat))
|
|
835
|
+
return 0;
|
|
836
|
+
const at = Number(file.at);
|
|
837
|
+
return Number.isFinite(at) && at > now ? now + Math.max(0, tat - at) : tat;
|
|
838
|
+
} catch {
|
|
839
|
+
return 0;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
write(tat, at) {
|
|
843
|
+
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
844
|
+
writeFileSync(temporary, JSON.stringify({ tat, at }), { mode: 384 });
|
|
845
|
+
renameSync(temporary, this.path);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
var ANNOUNCE_WAIT_MS = 5e3;
|
|
849
|
+
var LONGEST_PACE_WAIT_MS = 5 * 6e4;
|
|
850
|
+
var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
|
|
851
|
+
const { name, operation, warn } = options;
|
|
852
|
+
const now = options.now ?? Date.now;
|
|
853
|
+
let at = now();
|
|
854
|
+
try {
|
|
855
|
+
at = await pacer.reserve();
|
|
856
|
+
} catch (error) {
|
|
857
|
+
warn?.(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
858
|
+
event: "warning",
|
|
859
|
+
code: "wait_not_remembered",
|
|
860
|
+
operation
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
const waitMs = at - now();
|
|
864
|
+
if (waitMs <= 0)
|
|
865
|
+
return;
|
|
866
|
+
if (waitMs > (options.longestWaitMs ?? LONGEST_PACE_WAIT_MS))
|
|
867
|
+
throw new CliError("rate_limited", `this profile's next request to ${name} has to wait ${Math.ceil(waitMs / 1e3)} s more \u2014 nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
868
|
+
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
869
|
+
const seconds = Math.ceil(waitMs / 1e3);
|
|
870
|
+
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
|
871
|
+
event: "warning",
|
|
872
|
+
code: "pace_wait",
|
|
873
|
+
operation,
|
|
874
|
+
counts: { seconds }
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
|
|
878
|
+
}, "waitForTurn");
|
|
879
|
+
|
|
880
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
|
|
881
|
+
var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
|
|
882
|
+
var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
|
|
883
|
+
var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
|
|
884
|
+
var chatOf = /* @__PURE__ */ __name((args) => typeof args[0] === "string" && /^-?\d+$/.test(args[0]) ? args[0] : void 0, "chatOf");
|
|
885
|
+
var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer }) => {
|
|
886
|
+
const kept = /* @__PURE__ */ __name(async (operation, what2) => {
|
|
887
|
+
try {
|
|
888
|
+
await what2();
|
|
889
|
+
} catch (error) {
|
|
890
|
+
warn(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
891
|
+
event: "warning",
|
|
892
|
+
code: "wait_not_remembered",
|
|
893
|
+
operation
|
|
894
|
+
});
|
|
1590
895
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
case "vote":
|
|
1595
|
-
await store.messages.saveVote(account, event.chatId, event.messageId, event.vote);
|
|
1596
|
-
return;
|
|
1597
|
-
case "person_reaction":
|
|
1598
|
-
await store.messages.saveReaction(account, event.chatId, event.messageId, event.reaction);
|
|
1599
|
-
return;
|
|
1600
|
-
case "star":
|
|
1601
|
-
await store.messages.saveStar(account, event.chatId, event.messageId, event.starred);
|
|
896
|
+
}, "kept");
|
|
897
|
+
const noted = /* @__PURE__ */ __name(async (operation, chatId, error) => {
|
|
898
|
+
if (!isCliFailure(error))
|
|
1602
899
|
return;
|
|
1603
|
-
|
|
1604
|
-
|
|
900
|
+
const details = error.details ?? {};
|
|
901
|
+
const standing = details.standing;
|
|
902
|
+
if (standing && BLOCKING.has(standing.state)) {
|
|
903
|
+
await kept(operation, () => {
|
|
904
|
+
const block = memory.block({
|
|
905
|
+
state: standing.state,
|
|
906
|
+
hint: standing.hint ?? error.message,
|
|
907
|
+
...standing.until ? { until: standing.until } : {}
|
|
908
|
+
});
|
|
909
|
+
warn(`writes from this profile are held ${holdEnd(block)}: ${block.hint}`, {
|
|
910
|
+
event: "warning",
|
|
911
|
+
code: `account_${block.state}`,
|
|
912
|
+
operation
|
|
913
|
+
});
|
|
914
|
+
});
|
|
1605
915
|
return;
|
|
1606
|
-
|
|
1607
|
-
|
|
916
|
+
}
|
|
917
|
+
const waitMs = Number(details.retry_after_ms);
|
|
918
|
+
if (error.code !== "rate_limited" || details.remembered === true || !Number.isFinite(waitMs) || waitMs <= 0)
|
|
1608
919
|
return;
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
920
|
+
const providerError = providerErrorKey(details.provider_error);
|
|
921
|
+
await kept(operation, () => {
|
|
922
|
+
const deadline = memory.remember({
|
|
923
|
+
operation,
|
|
924
|
+
...chatId ? { chatId } : {},
|
|
925
|
+
...providerError ? { providerError } : {},
|
|
926
|
+
waitMs
|
|
927
|
+
});
|
|
928
|
+
warn(`${name} asked to wait before ${operation} again \u2014 until ${deadline.until}`, {
|
|
929
|
+
event: "warning",
|
|
930
|
+
code: "flood_wait",
|
|
931
|
+
operation,
|
|
932
|
+
counts: { seconds: Math.ceil(waitMs / 1e3) }
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
if (pacer)
|
|
936
|
+
await kept(operation, () => pacer.holdFor(waitMs));
|
|
937
|
+
}, "noted");
|
|
938
|
+
const turn = /* @__PURE__ */ __name(async (operation) => {
|
|
939
|
+
if (pacer)
|
|
940
|
+
await waitForTurn(pacer, { name, operation, warn });
|
|
941
|
+
}, "turn");
|
|
942
|
+
return throughWrapper(messenger, {}, (operation, call) => {
|
|
943
|
+
if (LONG_LIVED.has(operation))
|
|
944
|
+
return call;
|
|
945
|
+
if (LISTENING.has(operation))
|
|
946
|
+
return (async (...args) => {
|
|
947
|
+
try {
|
|
948
|
+
return await call(...args);
|
|
949
|
+
} catch (error) {
|
|
950
|
+
await noted(operation, void 0, error);
|
|
951
|
+
throw error;
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
return (async (...args) => {
|
|
955
|
+
const chatId = chatOf(args);
|
|
956
|
+
const owed = memory.owed(operation, chatId);
|
|
957
|
+
if (owed) {
|
|
958
|
+
const waitMs = Math.max(0, Date.parse(owed.until) - Date.now());
|
|
959
|
+
throw new CliError("rate_limited", `${name} asked to wait before ${operation} again, ${Math.ceil(waitMs / 1e3)} s are left \u2014 nothing was sent to ${name}`, {
|
|
960
|
+
retry_after_ms: waitMs,
|
|
961
|
+
retry_at: owed.until,
|
|
962
|
+
remembered: true,
|
|
963
|
+
...owed.providerError ? { provider_error: owed.providerError } : {}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
await turn(operation);
|
|
967
|
+
try {
|
|
968
|
+
return await call(...args);
|
|
969
|
+
} catch (error) {
|
|
970
|
+
await noted(operation, chatId, error);
|
|
971
|
+
throw error;
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
}, "flooded");
|
|
976
|
+
|
|
977
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
|
|
978
|
+
var observed = /* @__PURE__ */ __name((messenger, events) => {
|
|
979
|
+
const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
|
|
980
|
+
const write = currentOperation();
|
|
981
|
+
const marked = /* @__PURE__ */ __name((part = {}) => write === void 0 ? part : { ...part, ids: { ...part.ids, operation: write } }, "marked");
|
|
982
|
+
events({ event: "request", operation, level: "operation", ...marked(named) });
|
|
983
|
+
const started = performance.now();
|
|
984
|
+
const durationMs = /* @__PURE__ */ __name(() => Math.round(performance.now() - started), "durationMs");
|
|
985
|
+
try {
|
|
986
|
+
const answer = await work();
|
|
987
|
+
events({
|
|
988
|
+
event: "response",
|
|
989
|
+
operation,
|
|
990
|
+
level: "operation",
|
|
991
|
+
durationMs: durationMs(),
|
|
992
|
+
outcome: "ok",
|
|
993
|
+
...marked(after?.(answer))
|
|
994
|
+
});
|
|
995
|
+
return answer;
|
|
996
|
+
} catch (error) {
|
|
997
|
+
const providerError = isCliFailure(error) ? providerErrorKey(error.details?.provider_error) : void 0;
|
|
998
|
+
events({
|
|
999
|
+
event: "response",
|
|
1000
|
+
operation,
|
|
1001
|
+
level: "operation",
|
|
1002
|
+
durationMs: durationMs(),
|
|
1003
|
+
outcome: "error",
|
|
1004
|
+
errorCode: isCliFailure(error) ? error.code : "generic_failure",
|
|
1005
|
+
...providerError ? { providerError } : {},
|
|
1006
|
+
...marked()
|
|
1007
|
+
});
|
|
1008
|
+
throw error;
|
|
1009
|
+
}
|
|
1010
|
+
}, "timed");
|
|
1011
|
+
const counted = /* @__PURE__ */ __name(async (operation, onItem, work, count) => {
|
|
1012
|
+
const counts = {};
|
|
1013
|
+
await timed(operation, {}, () => work((item, ...rest) => {
|
|
1014
|
+
count(item, counts);
|
|
1015
|
+
return onItem(item, ...rest);
|
|
1016
|
+
}), () => ({ counts }));
|
|
1017
|
+
}, "counted");
|
|
1018
|
+
const mint = messenger.newSendId;
|
|
1019
|
+
const { chats, history, contact, around, watch, feed, listen, listenHistory } = messenger;
|
|
1020
|
+
return throughWrapper(messenger, {
|
|
1021
|
+
self: /* @__PURE__ */ __name(() => messenger.self(), "self"),
|
|
1022
|
+
...mint ? { newSendId: /* @__PURE__ */ __name(() => mint.call(messenger), "newSendId") } : {},
|
|
1023
|
+
me: /* @__PURE__ */ __name(() => timed("account.me", {}, () => messenger.me()), "me"),
|
|
1024
|
+
...chats ? {
|
|
1025
|
+
chats: /* @__PURE__ */ __name((window) => timed("chats.list", {}, () => chats.call(messenger, window), (page) => ({ counts: { chats: page.items.length } })), "chats")
|
|
1026
|
+
} : {},
|
|
1027
|
+
...history ? {
|
|
1028
|
+
history: /* @__PURE__ */ __name((reference, options) => timed("messages.list", {}, () => history.call(messenger, reference, options), (page) => ({
|
|
1029
|
+
...page.items[0] ? { ids: { chat: page.items[0].chatId } } : {},
|
|
1030
|
+
counts: { messages: page.items.length }
|
|
1031
|
+
})), "history")
|
|
1032
|
+
} : {},
|
|
1033
|
+
resolve: /* @__PURE__ */ __name((reference) => timed("chats.resolve", {}, () => messenger.resolve(reference), (chat) => ({ ids: { chat: chat.id } })), "resolve"),
|
|
1034
|
+
chat: /* @__PURE__ */ __name((reference) => timed("chats.show", {}, () => messenger.chat(reference), (card) => ({ ids: { chat: card.id }, ...card.members ? { counts: { members: card.members.length } } : {} })), "chat"),
|
|
1035
|
+
...contact ? {
|
|
1036
|
+
contact: /* @__PURE__ */ __name((reference) => timed("contacts.show", {}, () => contact.call(messenger, reference), (card) => ({ ids: { person: card.id }, counts: { chats: card.chats.length } })), "contact")
|
|
1037
|
+
} : {},
|
|
1038
|
+
...around ? {
|
|
1039
|
+
around: /* @__PURE__ */ __name((reference, messageId, window) => timed("messages.around", { ids: { message_id: messageId } }, () => around.call(messenger, reference, messageId, window), (items) => ({
|
|
1040
|
+
...items[0] ? { ids: { chat: items[0].chatId, message_id: messageId } } : {},
|
|
1041
|
+
counts: { messages: items.length }
|
|
1042
|
+
})), "around")
|
|
1043
|
+
} : {},
|
|
1044
|
+
send: /* @__PURE__ */ __name((chatId, text, options) => timed("messages.send", {
|
|
1045
|
+
ids: {
|
|
1046
|
+
chat: chatId,
|
|
1047
|
+
send: options.sendId,
|
|
1048
|
+
...options.replyTo ? { reply: options.replyTo } : {},
|
|
1049
|
+
...options.threadId ? { thread: options.threadId } : {}
|
|
1050
|
+
}
|
|
1051
|
+
}, () => messenger.send(chatId, text, options), (sent) => ({ ids: { chat: sent.message.chatId || chatId, message_id: sent.message.id } })), "send"),
|
|
1052
|
+
...watch ? {
|
|
1053
|
+
watch: /* @__PURE__ */ __name((onEvent, signal, onReady) => counted("messages.watch", onEvent, (counting) => watch.call(messenger, counting, signal, onReady), byEvent), "watch")
|
|
1054
|
+
} : {},
|
|
1055
|
+
...feed ? { feed: /* @__PURE__ */ __name((onBatch, signal) => timed("history.feed", {}, () => feed.call(messenger, onBatch, signal)), "feed") } : {},
|
|
1056
|
+
...listen ? {
|
|
1057
|
+
listen: /* @__PURE__ */ __name((onEvent, signal) => counted("messages.listen", onEvent, (counting) => listen.call(messenger, counting, signal), byEvent), "listen")
|
|
1058
|
+
} : {},
|
|
1059
|
+
...listenHistory ? {
|
|
1060
|
+
listenHistory: /* @__PURE__ */ __name((onBatch, signal) => counted("history.listen", onBatch, (counting) => listenHistory.call(messenger, counting, signal), byPart), "listenHistory")
|
|
1061
|
+
} : {},
|
|
1062
|
+
logout: /* @__PURE__ */ __name(() => timed("session.logout", {}, () => messenger.logout()), "logout"),
|
|
1063
|
+
close: /* @__PURE__ */ __name(() => messenger.close(), "close")
|
|
1064
|
+
}, (name, call) => (...args) => timed(`adapter.${name}`, {}, () => call(...args)));
|
|
1065
|
+
}, "observed");
|
|
1066
|
+
var byEvent = /* @__PURE__ */ __name((event, counts) => {
|
|
1067
|
+
counts[event.event] = (counts[event.event] ?? 0) + 1;
|
|
1068
|
+
}, "byEvent");
|
|
1069
|
+
var byPart = /* @__PURE__ */ __name((batch, counts) => {
|
|
1070
|
+
counts.batches = (counts.batches ?? 0) + 1;
|
|
1071
|
+
for (const [part, items] of Object.entries(batch))
|
|
1072
|
+
if (Array.isArray(items) && items.length > 0)
|
|
1073
|
+
counts[part] = (counts[part] ?? 0) + items.length;
|
|
1074
|
+
}, "byPart");
|
|
1613
1075
|
|
|
1614
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
1076
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
|
|
1615
1077
|
var lazyStore = /* @__PURE__ */ __name((env, command, version) => {
|
|
1616
1078
|
let opened;
|
|
1617
1079
|
return {
|
|
@@ -1953,6 +1415,7 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
|
|
|
1953
1415
|
history: base.settings.record,
|
|
1954
1416
|
searchCatchUp: base.settings.searchCatchUp,
|
|
1955
1417
|
...base.settings.historyLimits ? { historyLimits: base.settings.historyLimits } : {},
|
|
1418
|
+
historyMuted: base.settings.historyMuted,
|
|
1956
1419
|
pictures: base.settings.pictureSearch,
|
|
1957
1420
|
reranker: base.settings.searchReranker,
|
|
1958
1421
|
guard,
|
|
@@ -2011,17 +1474,6 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
|
|
|
2011
1474
|
export {
|
|
2012
1475
|
answerOf,
|
|
2013
1476
|
terminalAsker,
|
|
2014
|
-
holdEnd,
|
|
2015
|
-
floodPathFor,
|
|
2016
|
-
FloodMemory,
|
|
2017
|
-
sendsPathFor,
|
|
2018
|
-
SendJournal,
|
|
2019
|
-
recipientsPathFor,
|
|
2020
|
-
RecipientList,
|
|
2021
|
-
ceilingRefusal,
|
|
2022
|
-
levelRefusal,
|
|
2023
|
-
sendGuard,
|
|
2024
|
-
guardFor,
|
|
2025
1477
|
DEFAULT_PACE,
|
|
2026
1478
|
pacePathFor,
|
|
2027
1479
|
Pacer,
|
|
@@ -2029,8 +1481,12 @@ export {
|
|
|
2029
1481
|
commandPermissions,
|
|
2030
1482
|
knownPermissionKeys,
|
|
2031
1483
|
knownBeside,
|
|
1484
|
+
unknownPermissionKeys,
|
|
2032
1485
|
unknownPermissionIssues,
|
|
2033
1486
|
refuseUnknownPermissionKeys,
|
|
1487
|
+
stored,
|
|
1488
|
+
fill,
|
|
1489
|
+
connectFor,
|
|
2034
1490
|
connectedFor,
|
|
2035
1491
|
refuseLocalWrite,
|
|
2036
1492
|
messengerContext
|