@wirecat/mail-cli 0.23.1 → 0.25.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/CHANGELOG.md +23 -0
- package/dist/bin/mail.js +2 -2
- package/dist/bundle/{all-profiles-FJHJCGRU.js → all-profiles-QEV2PSOR.js} +11 -11
- package/dist/bundle/{anthropic-AFL7NKVZ.js → anthropic-5NKQXIHM.js} +28 -12
- package/dist/bundle/{app-server-WKCBJMHI.js → app-server-G2CJNT4R.js} +62 -50
- package/dist/bundle/{bun-HQATAQJQ.js → bun-6HBYWQIX.js} +2 -2
- package/dist/bundle/{bun-sqlite-4ECAV7OU.js → bun-sqlite-DXIQ7BVR.js} +9 -5
- package/dist/bundle/{chunk-MUDHCYN4.js → chunk-37F6QYTO.js} +6 -6
- package/dist/bundle/{chunk-NMGF3UOZ.js → chunk-3XVR2ROR.js} +50 -46
- package/dist/bundle/{chunk-QUKD5SO2.js → chunk-434YOD6A.js} +4 -4
- package/dist/bundle/{chunk-7SWWVDEZ.js → chunk-4W4EVVL4.js} +61 -21
- package/dist/bundle/{chunk-CCYHBNRL.js → chunk-5QYK3LWS.js} +326 -56
- package/dist/bundle/{chunk-7YRKUEYE.js → chunk-5ZYFV6FD.js} +694 -228
- package/dist/bundle/chunk-7GLJSJ7M.js +16 -0
- package/dist/bundle/{chunk-NOA6E6MM.js → chunk-A6BPOX5O.js} +38841 -24161
- package/dist/bundle/{chunk-34743C4C.js → chunk-ADKMBXY4.js} +1 -1
- package/dist/bundle/{chunk-2HXHAFRP.js → chunk-B7SWTH5O.js} +2 -2
- package/dist/bundle/{chunk-NKBAZ4VC.js → chunk-BC7PFQL7.js} +2 -2
- package/dist/bundle/{chunk-ROKTS7WM.js → chunk-CBYBZCQP.js} +1 -1
- package/dist/bundle/chunk-CIWWNBVW.js +188 -0
- package/dist/bundle/{chunk-SBGXKM4U.js → chunk-DIA56CS7.js} +8 -7
- package/dist/bundle/{chunk-VYHIX3OP.js → chunk-EXVY76VO.js} +61 -607
- package/dist/bundle/{chunk-BVJQBAGL.js → chunk-FZZD4AFY.js} +14 -14
- package/dist/bundle/{chunk-VFKX5UMJ.js → chunk-G5LHHAW2.js} +6 -6
- package/dist/bundle/{chunk-QV3M2MHG.js → chunk-GJRYZXBN.js} +13 -136
- package/dist/bundle/{chunk-GJNFNC76.js → chunk-GY4XCLCO.js} +10 -15
- package/dist/bundle/{chunk-V7CFZ773.js → chunk-HEIDAHRC.js} +2 -2
- package/dist/bundle/{chunk-AGNAT7CM.js → chunk-HEYVMAAQ.js} +2 -2
- package/dist/bundle/{chunk-HOKGIYUO.js → chunk-HJSJBNCJ.js} +119 -9
- package/dist/bundle/{chunk-KKGX7JMX.js → chunk-HLXVUMZJ.js} +2 -2
- package/dist/bundle/{chunk-OU5CWCG2.js → chunk-IACWKZWS.js} +1 -1
- package/dist/bundle/{chunk-QR7JZM3D.js → chunk-IXO4SCKE.js} +1 -1
- package/dist/bundle/{chunk-GOMJNH56.js → chunk-IZOYW4Z4.js} +32 -8
- package/dist/bundle/{chunk-WN4HP7IZ.js → chunk-J4OYK4WL.js} +14 -14
- package/dist/bundle/{chunk-76RTQYJQ.js → chunk-JG4MNYG2.js} +1 -1
- package/dist/bundle/{chunk-VAMCRP47.js → chunk-K2OGF7KC.js} +2 -2
- package/dist/bundle/chunk-K6HR6HCO.js +32 -0
- package/dist/bundle/{chunk-B6QMMRIM.js → chunk-KFB2X6KE.js} +1530 -1525
- package/dist/bundle/{chunk-3UFD76IR.js → chunk-KK4HD3SI.js} +6 -6
- package/dist/bundle/{chunk-3QVGB2CI.js → chunk-L4QVOEOB.js} +4 -4
- package/dist/bundle/chunk-LGZPKKBN.js +53 -0
- package/dist/bundle/chunk-LVGX7VTD.js +138 -0
- package/dist/bundle/chunk-MBFPFWCO.js +1243 -0
- package/dist/bundle/{chunk-3DQYO7FB.js → chunk-MCPOZNWG.js} +1 -1
- package/dist/bundle/{chunk-SR3ADLGX.js → chunk-MWGH3M46.js} +3 -3
- package/dist/bundle/{chunk-OJCUSHZG.js → chunk-ND5H5ADM.js} +4 -4
- package/dist/bundle/chunk-NMZQTYKJ.js +18 -0
- package/dist/bundle/{chunk-4YJJQNNJ.js → chunk-OLKCJBZY.js} +5 -5
- package/dist/bundle/{chunk-E7ZVKQHG.js → chunk-OLLIWNFG.js} +3 -3
- package/dist/bundle/{chunk-R5MYOLQP.js → chunk-P6GXNT7Z.js} +13 -13
- package/dist/bundle/{chunk-M7RGG3UU.js → chunk-PGC5TRH6.js} +3 -3
- package/dist/bundle/{chunk-3OZKDC6Y.js → chunk-PHHH2NQP.js} +15 -9
- package/dist/bundle/{chunk-S5OTP7XS.js → chunk-PP3YOAWG.js} +3 -3
- package/dist/bundle/{chunk-4IFX4HV2.js → chunk-PQMJ5BXH.js} +4 -4
- package/dist/bundle/{chunk-ZXIPJF3Y.js → chunk-QB3DP2TN.js} +2 -2
- package/dist/bundle/{chunk-4IWJARFA.js → chunk-QQUY4MZY.js} +1 -1
- package/dist/bundle/{chunk-UHC5I3JV.js → chunk-RX5CJ55S.js} +1 -1
- package/dist/bundle/{chunk-CYQVWITQ.js → chunk-S2QRAKQI.js} +99 -42
- package/dist/bundle/{chunk-V3TDQUXD.js → chunk-SMTBV62X.js} +44 -60
- package/dist/bundle/{chunk-SNTLN2QT.js → chunk-T27IMG6X.js} +3 -1
- package/dist/bundle/{chunk-LLYVBO3R.js → chunk-TY644DKQ.js} +19 -19
- package/dist/bundle/{chunk-R554W7ZO.js → chunk-U6IQ6YQ2.js} +2 -2
- package/dist/bundle/{chunk-MBKNL5TX.js → chunk-VFU7PVPQ.js} +373 -133
- package/dist/bundle/{chunk-UMXVQIGD.js → chunk-VL6H2BND.js} +377 -12
- package/dist/bundle/{chunk-DALBYUPC.js → chunk-VUBZFMGP.js} +2 -2
- package/dist/bundle/{chunk-VYIIX6VN.js → chunk-WOAYHCM2.js} +1 -1
- package/dist/bundle/{chunk-LQDMUMA2.js → chunk-WX6OYVCH.js} +5370 -3700
- package/dist/bundle/chunk-XMDEM6BZ.js +2094 -0
- package/dist/bundle/{chunk-CUOCDJFI.js → chunk-XQYKIZMG.js} +13 -9
- package/dist/bundle/{chunk-PMIKRELC.js → chunk-YNS2YVUR.js} +69 -6
- package/dist/bundle/{chunk-CBWA2T3N.js → chunk-Z5T6OW3V.js} +14 -5
- package/dist/bundle/command-contract-XSW2Q33S.js +36 -0
- package/dist/bundle/command-server-entry-XMSSY5ID.js +165 -0
- package/dist/bundle/{decode-QXKTMOTH.js → decode-RYGB4PGT.js} +5 -5
- package/dist/bundle/{dispatch-G4CYFWQ2.js → dispatch-PLQOIZG5.js} +10 -10
- package/dist/bundle/{dist-5FX36DAW.js → dist-GY2AQETI.js} +79 -46
- package/dist/bundle/{echarts-HHUM43TU.js → echarts-7CM2MCMW.js} +2 -2
- package/dist/bundle/{embed-SRZSDZVI.js → embed-FTBDPOPT.js} +6 -6
- package/dist/bundle/{embedder-WZIZCWLX.js → embedder-B43WGNBD.js} +9 -9
- package/dist/bundle/{failure-FFPK2WYB.js → failure-XP5QYV2T.js} +2 -2
- package/dist/bundle/{first-run-6DVWZ3JQ.js → first-run-XIIUARNM.js} +12 -11
- package/dist/bundle/first-screen-Z7HC6PQU.js +34 -0
- package/dist/bundle/{instructions-UWONE6UT.js → instructions-R7OHVAWH.js} +1 -1
- package/dist/bundle/mail.js +37 -13
- package/dist/bundle/{mcp-CFVG2OUS.js → mcp-7KQUJNFN.js} +2 -2
- package/dist/bundle/{node-HLAOYJDB.js → node-3N2JGZ7V.js} +2 -2
- package/dist/bundle/{node-sqlite-RO66I7W6.js → node-sqlite-WFJXW3CZ.js} +10 -6
- package/dist/bundle/{oauth-VNLB2TET.js → oauth-SVJLQTWV.js} +7 -7
- package/dist/bundle/{open-QQSG343L.js → open-ZDONVKSX.js} +5 -5
- package/dist/bundle/{openai-JTFC7OGF.js → openai-XVEW6XOU.js} +21 -38
- package/dist/bundle/{process-3CZAXR6P.js → process-YAHHUFR5.js} +1 -1
- package/dist/bundle/{program-XTOS4RAM.js → program-HU2UVMJE.js} +7071 -5421
- package/dist/bundle/{prompt-HGQ6GPYL.js → prompt-JAJ2CUJI.js} +5 -5
- package/dist/bundle/{recognize-2SHMNEIZ.js → recognize-UFBWUNFR.js} +4 -4
- package/dist/bundle/{remote-GBQC3433.js → remote-2GFOVLCR.js} +9 -7
- package/dist/bundle/{rerank-FQHQXFNR.js → rerank-BGPSMXTL.js} +7 -7
- package/dist/bundle/{serve-THU67QUZ.js → serve-CB3XJTH3.js} +9 -9
- package/dist/bundle/server-34GEF22R.js +68 -0
- package/dist/bundle/{server-LOT3CLYX.js → server-M7FQY7TX.js} +42 -40
- package/dist/bundle/{sqlite-runtime-NOOUMBC4.js → sqlite-runtime-AEV6PGDR.js} +6 -6
- package/dist/bundle/{state-KSKZCV2U.js → state-YLBEQLBI.js} +6 -6
- package/dist/bundle/{store-BAKSHTKF.js → store-CDUL3HKK.js} +19 -16
- package/dist/bundle/{store-OHNZOQ7U.js → store-EKWKY6GG.js} +49 -20
- package/dist/bundle/store-maintenance-command-XH2JUM5F.js +58 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/dist/bundle/chunk-5UKBUI4I.js +0 -35
- package/dist/bundle/chunk-EXPR6QAX.js +0 -394
- package/dist/bundle/chunk-FWFNUJQD.js +0 -12172
- package/dist/bundle/command-contract-IIHBNF7J.js +0 -35
- package/dist/bundle/first-screen-SRZ7NYHZ.js +0 -33
- package/dist/bundle/server-VKMUX7ZT.js +0 -65
- package/dist/bundle/store-maintenance-command-ROQHJVEA.js +0 -54
- /package/dist/bundle/{chunk-QZLK2ISN.js → chunk-YVNHQFLC.js} +0 -0
|
@@ -1,78 +1,76 @@
|
|
|
1
1
|
import { createRequire as __bundleRequire } from "node:module";
|
|
2
2
|
const require = __bundleRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
+
FloodMemory,
|
|
4
5
|
OFFLINE,
|
|
6
|
+
RecipientList,
|
|
5
7
|
capability,
|
|
8
|
+
ceilingRefusal,
|
|
6
9
|
chatIdIn,
|
|
10
|
+
floodPathFor,
|
|
11
|
+
guardFor,
|
|
12
|
+
holdEnd,
|
|
7
13
|
profilesOnAccount,
|
|
14
|
+
recipientsPathFor,
|
|
8
15
|
refuseLacking,
|
|
9
16
|
servicesFor,
|
|
10
|
-
throughWrapper
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
chatReferenceOf,
|
|
14
|
-
ensureAccount,
|
|
15
|
-
foldName,
|
|
16
|
-
isId,
|
|
17
|
-
pickPerson
|
|
18
|
-
} from "./chunk-QV3M2MHG.js";
|
|
17
|
+
throughWrapper,
|
|
18
|
+
withFileLockAsync
|
|
19
|
+
} from "./chunk-WX6OYVCH.js";
|
|
19
20
|
import {
|
|
20
21
|
servingProfiles
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-PGC5TRH6.js";
|
|
22
23
|
import {
|
|
23
|
-
LOG_ATTRIBUTES,
|
|
24
|
-
MESSENGER_CHANGE_REFUSAL,
|
|
25
24
|
asFirstWord,
|
|
26
25
|
baseContext,
|
|
27
26
|
codeOf,
|
|
28
27
|
currentOperation,
|
|
29
|
-
currentRun,
|
|
30
28
|
environmentOf,
|
|
31
|
-
fromLogAttributes,
|
|
32
29
|
issueMessage,
|
|
33
30
|
limitBatch,
|
|
34
|
-
logAttributes,
|
|
35
31
|
permissionIssues,
|
|
36
32
|
publicIssue,
|
|
37
|
-
readOnlyRefusal,
|
|
38
33
|
recalledAccount,
|
|
39
34
|
rememberAccount,
|
|
40
35
|
rootOf2 as rootOf
|
|
41
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-KFB2X6KE.js";
|
|
42
37
|
import {
|
|
43
38
|
AUTHORITY_KEY,
|
|
44
39
|
CEILING_KEY,
|
|
45
40
|
DEFAULT_PERMISSIONS,
|
|
46
41
|
WRITE_KEYS,
|
|
47
42
|
keyForCommand,
|
|
48
|
-
keyForWrite,
|
|
49
43
|
levelFor,
|
|
50
44
|
readKeysForCommand,
|
|
51
45
|
skipFlagFor
|
|
52
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-DIA56CS7.js";
|
|
53
47
|
import {
|
|
54
48
|
providerErrorKey
|
|
55
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-XQYKIZMG.js";
|
|
56
50
|
import {
|
|
57
51
|
openStore
|
|
58
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-A6BPOX5O.js";
|
|
53
|
+
import {
|
|
54
|
+
chatReferenceOf,
|
|
55
|
+
ensureAccount,
|
|
56
|
+
foldName,
|
|
57
|
+
isId,
|
|
58
|
+
pickPerson
|
|
59
|
+
} from "./chunk-XMDEM6BZ.js";
|
|
59
60
|
import {
|
|
60
61
|
isCliFailure
|
|
61
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-U6IQ6YQ2.js";
|
|
62
63
|
import {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
resolvePaths,
|
|
66
|
-
writeSecurely
|
|
67
|
-
} from "./chunk-LLYVBO3R.js";
|
|
64
|
+
resolvePaths
|
|
65
|
+
} from "./chunk-TY644DKQ.js";
|
|
68
66
|
import {
|
|
69
67
|
CliError
|
|
70
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-VUBZFMGP.js";
|
|
71
69
|
import {
|
|
72
70
|
__name
|
|
73
71
|
} from "./chunk-ZVVMGPBJ.js";
|
|
74
72
|
|
|
75
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
73
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
|
|
76
74
|
import { openSync } from "node:fs";
|
|
77
75
|
import { createInterface } from "node:readline";
|
|
78
76
|
import { ReadStream } from "node:tty";
|
|
@@ -127,551 +125,11 @@ var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) =>
|
|
|
127
125
|
throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
|
|
128
126
|
}, "terminalAsker");
|
|
129
127
|
|
|
130
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
131
|
-
import {
|
|
132
|
-
|
|
133
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/flood.js
|
|
134
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
135
|
-
import { dirname, join } from "node:path";
|
|
136
|
-
var MOST_DEADLINES = 50;
|
|
137
|
-
var LIMITED_HOLD_MS = 60 * 60 * 1e3;
|
|
138
|
-
var FROZEN_HOLD_MS = 24 * 60 * 60 * 1e3;
|
|
139
|
-
var NO_END = "9999-12-31T23:59:59.999Z";
|
|
140
|
-
var holdEnd = /* @__PURE__ */ __name((block, show = (iso) => iso) => block.until === null ? "until lifted" : `until ${show(block.until)}`, "holdEnd");
|
|
141
|
-
var floodPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "flood", `${profile}.json`), "floodPathFor");
|
|
142
|
-
var FloodMemory = class {
|
|
143
|
-
static {
|
|
144
|
-
__name(this, "FloodMemory");
|
|
145
|
-
}
|
|
146
|
-
path;
|
|
147
|
-
now;
|
|
148
|
-
constructor(path, now = Date.now) {
|
|
149
|
-
this.path = path;
|
|
150
|
-
this.now = now;
|
|
151
|
-
}
|
|
152
|
-
/** What is still in force; anything expired is left out. */
|
|
153
|
-
read() {
|
|
154
|
-
const now = this.now();
|
|
155
|
-
let raw;
|
|
156
|
-
try {
|
|
157
|
-
raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
158
|
-
} catch {
|
|
159
|
-
return { deadlines: [] };
|
|
160
|
-
}
|
|
161
|
-
const alive = /* @__PURE__ */ __name((until) => typeof until === "string" && Date.parse(until) > now, "alive");
|
|
162
|
-
const deadlines = Array.isArray(raw.deadlines) ? raw.deadlines.filter((one) => typeof one?.operation === "string" && alive(one.until)) : [];
|
|
163
|
-
const block = raw.sendBlock && (raw.sendBlock.until === NO_END ? { ...raw.sendBlock, until: null } : raw.sendBlock);
|
|
164
|
-
const held = block && (block.until === null || alive(block.until));
|
|
165
|
-
return { deadlines, ...held ? { sendBlock: block } : {} };
|
|
166
|
-
}
|
|
167
|
-
/** The deadline this call is still under: one for its chat, or one for the call in every chat. */
|
|
168
|
-
owed(operation, chatId) {
|
|
169
|
-
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];
|
|
170
|
-
}
|
|
171
|
-
remember(deadline) {
|
|
172
|
-
const { waitMs, ...rest } = deadline;
|
|
173
|
-
const kept = { ...rest, until: new Date(this.now() + waitMs).toISOString() };
|
|
174
|
-
const state = this.read();
|
|
175
|
-
const others = state.deadlines.filter((one) => one.operation !== kept.operation || one.chatId !== kept.chatId);
|
|
176
|
-
const deadlines = [...others, kept].sort((a, b) => b.until.localeCompare(a.until)).slice(0, MOST_DEADLINES);
|
|
177
|
-
this.#write({ ...state, deadlines });
|
|
178
|
-
return kept;
|
|
179
|
-
}
|
|
180
|
-
sendBlock() {
|
|
181
|
-
return this.read().sendBlock;
|
|
182
|
-
}
|
|
183
|
-
/** A ban the messenger gave no end for holds until lifted; a spam limit or a freeze without one, for a while. */
|
|
184
|
-
block(block) {
|
|
185
|
-
const now = this.now();
|
|
186
|
-
const holdMs = { limited: LIMITED_HOLD_MS, frozen: FROZEN_HOLD_MS, banned: void 0 }[block.state];
|
|
187
|
-
const kept = {
|
|
188
|
-
...block,
|
|
189
|
-
since: new Date(now).toISOString(),
|
|
190
|
-
until: block.until ?? (holdMs === void 0 ? null : new Date(now + holdMs).toISOString())
|
|
191
|
-
};
|
|
192
|
-
this.#write({ ...this.read(), sendBlock: kept });
|
|
193
|
-
return kept;
|
|
194
|
-
}
|
|
195
|
-
/** Lifts only a block of this state: an account found not frozen may still be limited for spam. */
|
|
196
|
-
unblock(state) {
|
|
197
|
-
const { sendBlock, ...rest } = this.read();
|
|
198
|
-
if (sendBlock?.state === state)
|
|
199
|
-
this.#write(rest);
|
|
200
|
-
}
|
|
201
|
-
/** Forgets every wait and lifts the hold, and answers with what was still in force. */
|
|
202
|
-
clear() {
|
|
203
|
-
const cleared = this.read();
|
|
204
|
-
this.#write({ deadlines: [] });
|
|
205
|
-
return cleared;
|
|
206
|
-
}
|
|
207
|
-
#write({ sendBlock, ...rest }) {
|
|
208
|
-
const state = sendBlock ? { ...rest, sendBlock: { ...sendBlock, until: sendBlock.until ?? NO_END } } : rest;
|
|
209
|
-
mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
|
|
210
|
-
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
211
|
-
writeFileSync(temporary, `${JSON.stringify(state)}
|
|
212
|
-
`, { mode: 384 });
|
|
213
|
-
renameSync(temporary, this.path);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
218
|
-
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
219
|
-
import { dirname as dirname3, join as join2 } from "node:path";
|
|
220
|
-
|
|
221
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
|
|
222
|
-
import { closeSync, mkdirSync as mkdirSync2, openSync as openSync2, statSync, unlinkSync } from "node:fs";
|
|
223
|
-
import { dirname as dirname2 } from "node:path";
|
|
224
|
-
var LOCK_WAIT_MS = 5e3;
|
|
225
|
-
var LOCK_STALE_MS = 3e4;
|
|
226
|
-
var RETRY_MS = 20;
|
|
227
|
-
var pause = new Int32Array(new SharedArrayBuffer(4));
|
|
228
|
-
var withFileLock = /* @__PURE__ */ __name((path, what2, body, waitMs = LOCK_WAIT_MS) => {
|
|
229
|
-
const lock = lockFor(path);
|
|
230
|
-
const deadline = Date.now() + waitMs;
|
|
231
|
-
while (!taken(lock)) {
|
|
232
|
-
if (Date.now() >= deadline)
|
|
233
|
-
throw lockTimeout(what2, waitMs, lock);
|
|
234
|
-
Atomics.wait(pause, 0, 0, RETRY_MS);
|
|
235
|
-
}
|
|
236
|
-
return holding(lock, body);
|
|
237
|
-
}, "withFileLock");
|
|
238
|
-
var withFileLockAsync = /* @__PURE__ */ __name(async (path, what2, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
|
|
239
|
-
const lock = lockFor(path);
|
|
240
|
-
const deadline = Date.now() + waitMs;
|
|
241
|
-
while (!taken(lock)) {
|
|
242
|
-
if (Date.now() >= deadline)
|
|
243
|
-
throw lockTimeout(what2, waitMs, lock);
|
|
244
|
-
await sleep(RETRY_MS);
|
|
245
|
-
}
|
|
246
|
-
return holding(lock, body);
|
|
247
|
-
}, "withFileLockAsync");
|
|
248
|
-
var lockFor = /* @__PURE__ */ __name((path) => {
|
|
249
|
-
mkdirSync2(dirname2(path), { recursive: true, mode: 448 });
|
|
250
|
-
return `${path}.lock`;
|
|
251
|
-
}, "lockFor");
|
|
252
|
-
var taken = /* @__PURE__ */ __name((lock) => {
|
|
253
|
-
for (; ; ) {
|
|
254
|
-
try {
|
|
255
|
-
closeSync(openSync2(lock, "wx", 384));
|
|
256
|
-
return true;
|
|
257
|
-
} catch (error) {
|
|
258
|
-
if (error.code !== "EEXIST")
|
|
259
|
-
throw error;
|
|
260
|
-
if (Date.now() - lockTime(lock) <= LOCK_STALE_MS)
|
|
261
|
-
return false;
|
|
262
|
-
try {
|
|
263
|
-
unlinkSync(lock);
|
|
264
|
-
} catch {
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}, "taken");
|
|
269
|
-
var holding = /* @__PURE__ */ __name((lock, body) => {
|
|
270
|
-
try {
|
|
271
|
-
return body();
|
|
272
|
-
} finally {
|
|
273
|
-
try {
|
|
274
|
-
unlinkSync(lock);
|
|
275
|
-
} catch {
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}, "holding");
|
|
279
|
-
var lockTimeout = /* @__PURE__ */ __name((what2, waitMs, lock) => new CliError("timeout", `${what2} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
|
|
280
|
-
var lockTime = /* @__PURE__ */ __name((lock) => {
|
|
281
|
-
try {
|
|
282
|
-
return statSync(lock).mtimeMs;
|
|
283
|
-
} catch {
|
|
284
|
-
return Date.now();
|
|
285
|
-
}
|
|
286
|
-
}, "lockTime");
|
|
287
|
-
|
|
288
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
289
|
-
var sendsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "sends", `${profile}.jsonl`), "sendsPathFor");
|
|
290
|
-
var SendJournal = class {
|
|
291
|
-
static {
|
|
292
|
-
__name(this, "SendJournal");
|
|
293
|
-
}
|
|
294
|
-
path;
|
|
295
|
-
resource;
|
|
296
|
-
constructor(path, resource = { service: "unknown", version: "unknown" }) {
|
|
297
|
-
this.path = path;
|
|
298
|
-
this.resource = resource;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Runs `body` with the journal to itself, across processes: two sends at the limit must not both
|
|
302
|
-
* read "one left". A lock file opened with `wx`, because `flock` is not there on Windows.
|
|
303
|
-
*/
|
|
304
|
-
locked(body) {
|
|
305
|
-
return withFileLock(this.path, "the send journal", body);
|
|
306
|
-
}
|
|
307
|
-
/** `locked` without blocking the thread while another process holds the journal: what `serve` uses. */
|
|
308
|
-
lockedAsync(body) {
|
|
309
|
-
return withFileLockAsync(this.path, "the send journal", body);
|
|
310
|
-
}
|
|
311
|
-
append(entry) {
|
|
312
|
-
const { at, ...attributes } = entry;
|
|
313
|
-
const { runId, command, traceId } = currentRun();
|
|
314
|
-
const record = logRecordOf({
|
|
315
|
-
severity: entry.outcome === "sent" || entry.outcome === "reserved" ? "info" : "warn",
|
|
316
|
-
event: logAttributes({ event: "send.recorded", ...attributes }),
|
|
317
|
-
time: at,
|
|
318
|
-
runId,
|
|
319
|
-
...traceId === void 0 ? {} : { traceId },
|
|
320
|
-
command,
|
|
321
|
-
resource: this.resource,
|
|
322
|
-
allow: LOG_ATTRIBUTES
|
|
323
|
-
});
|
|
324
|
-
mkdirSync3(dirname3(this.path), { recursive: true, mode: 448 });
|
|
325
|
-
appendFileSync(this.path, `${JSON.stringify(record)}
|
|
326
|
-
`, { mode: 384 });
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Oldest first, each reservation folded into its outcome; one with no outcome yet is in flight,
|
|
330
|
-
* or its process died. A line that does not parse is skipped: a torn last write must not block sending.
|
|
331
|
-
*/
|
|
332
|
-
entries(filter) {
|
|
333
|
-
const lines = this.#lines();
|
|
334
|
-
const settled2 = new Set(lines.filter((entry) => entry.outcome !== "reserved").map((entry) => entry.reservation));
|
|
335
|
-
const entries = lines.filter((entry) => entry.outcome !== "reserved" || !settled2.has(entry.reservation)).map(({ reservation, ...entry }) => entry.outcome === "reserved" ? { ...entry, reservation } : entry).map(withSendId);
|
|
336
|
-
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));
|
|
337
|
-
}
|
|
338
|
-
#lines() {
|
|
339
|
-
let text;
|
|
340
|
-
try {
|
|
341
|
-
text = readFileSync2(this.path, "utf8");
|
|
342
|
-
} catch {
|
|
343
|
-
return [];
|
|
344
|
-
}
|
|
345
|
-
return text.split("\n").filter((line) => line.trim() !== "").flatMap((line) => {
|
|
346
|
-
try {
|
|
347
|
-
return [entryOf(JSON.parse(line))];
|
|
348
|
-
} catch {
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
var entryOf = /* @__PURE__ */ __name((line) => {
|
|
355
|
-
if (!("attributes" in line))
|
|
356
|
-
return line;
|
|
357
|
-
const { event: _, ...attributes } = line.attributes;
|
|
358
|
-
return { at: line.time, ...fromLogAttributes(attributes) };
|
|
359
|
-
}, "entryOf");
|
|
360
|
-
var withSendId = /* @__PURE__ */ __name((entry) => {
|
|
361
|
-
const { cid, ...rest } = entry;
|
|
362
|
-
return cid === void 0 || rest.sendId !== void 0 ? rest : { ...rest, sendId: String(cid) };
|
|
363
|
-
}, "withSendId");
|
|
364
|
-
|
|
365
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/recipients.js
|
|
366
|
-
import { existsSync, readFileSync as readFileSync3, rmSync } from "node:fs";
|
|
367
|
-
import { join as join3 } from "node:path";
|
|
368
|
-
var recipientsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "profiles", `${profile}.recipients.json`), "recipientsPathFor");
|
|
369
|
-
var RecipientList = class {
|
|
370
|
-
static {
|
|
371
|
-
__name(this, "RecipientList");
|
|
372
|
-
}
|
|
373
|
-
path;
|
|
374
|
-
command;
|
|
375
|
-
lockWaitMs;
|
|
376
|
-
/** `command` names the program in the hint that turns the list off. */
|
|
377
|
-
constructor(path, command, lockWaitMs) {
|
|
378
|
-
this.path = path;
|
|
379
|
-
this.command = command;
|
|
380
|
-
this.lockWaitMs = lockWaitMs;
|
|
381
|
-
}
|
|
382
|
-
/** `undefined` when the list is off. A file that cannot be read refuses rather than opening up. */
|
|
383
|
-
read() {
|
|
384
|
-
if (!existsSync(this.path))
|
|
385
|
-
return void 0;
|
|
386
|
-
try {
|
|
387
|
-
const parsed = JSON.parse(readFileSync3(this.path, "utf8"));
|
|
388
|
-
if (!Array.isArray(parsed.chats))
|
|
389
|
-
throw new Error("no `chats` array");
|
|
390
|
-
return parsed.chats;
|
|
391
|
-
} catch (error) {
|
|
392
|
-
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\``);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
list(filter = {}) {
|
|
396
|
-
const chats = this.read();
|
|
397
|
-
return {
|
|
398
|
-
state: chats === void 0 ? "off" : chats.length === 0 ? "empty" : "on",
|
|
399
|
-
items: (chats ?? []).filter((chat) => (filter.id === void 0 || chat.id === filter.id) && (filter.title === void 0 || chat.title?.toLocaleLowerCase() === filter.title.toLocaleLowerCase()))
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/** Whether it was new. Adding one again fills in a partner an older entry was stored without. */
|
|
403
|
-
add(recipient) {
|
|
404
|
-
return this.#locked(() => this.#added(recipient));
|
|
405
|
-
}
|
|
406
|
-
/** `add` waiting for the lock on timers: `recipients add` connects, so it runs inside `serve` when one holds the account. */
|
|
407
|
-
addAsync(recipient) {
|
|
408
|
-
return withFileLockAsync(this.path, "the recipient list", () => this.#added(recipient), this.lockWaitMs);
|
|
409
|
-
}
|
|
410
|
-
#added(recipient) {
|
|
411
|
-
const chats = this.read() ?? [];
|
|
412
|
-
const known = chats.find((chat) => chat.id === recipient.id);
|
|
413
|
-
if (known) {
|
|
414
|
-
if (recipient.partnerId && !known.partnerId) {
|
|
415
|
-
this.#write(chats.map((chat) => chat === known ? { ...known, partnerId: recipient.partnerId } : chat));
|
|
416
|
-
}
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
this.#write([...chats, recipient]);
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
/** The id or the title as it was stored; `undefined` when neither matched. */
|
|
423
|
-
remove(reference) {
|
|
424
|
-
return this.#locked(() => {
|
|
425
|
-
const chats = this.read() ?? [];
|
|
426
|
-
const wanted = reference.trim();
|
|
427
|
-
const gone = chats.find((chat) => chat.id === wanted) ?? chats.find((chat) => chat.title?.toLocaleLowerCase() === wanted.toLocaleLowerCase());
|
|
428
|
-
if (gone)
|
|
429
|
-
this.#write(chats.filter((chat) => chat !== gone));
|
|
430
|
-
return gone;
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* The chat the messenger now names `to`: its entry, and a partner of that id, follow it. Only an entry already there
|
|
435
|
-
* changes, and no list is created, so the list never opens up. Whether anything changed.
|
|
436
|
-
*/
|
|
437
|
-
async rekey(from, to) {
|
|
438
|
-
if (from === to)
|
|
439
|
-
return false;
|
|
440
|
-
return withFileLockAsync(this.path, "the recipient list", () => {
|
|
441
|
-
const chats = this.read();
|
|
442
|
-
if (!chats?.some((chat) => chat.id === from || chat.partnerId === from))
|
|
443
|
-
return false;
|
|
444
|
-
const held = chats.some((chat) => chat.id === to);
|
|
445
|
-
this.#write(chats.filter((chat) => !(held && chat.id === from)).map((chat) => ({
|
|
446
|
-
...chat,
|
|
447
|
-
...chat.id === from ? { id: to } : {},
|
|
448
|
-
...chat.partnerId === from ? { partnerId: to } : {}
|
|
449
|
-
})));
|
|
450
|
-
return true;
|
|
451
|
-
}, this.lockWaitMs);
|
|
452
|
-
}
|
|
453
|
-
/** Whether there was a list to turn off. */
|
|
454
|
-
off() {
|
|
455
|
-
return this.#locked(() => {
|
|
456
|
-
if (!existsSync(this.path))
|
|
457
|
-
return false;
|
|
458
|
-
rmSync(this.path);
|
|
459
|
-
return true;
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Every change reads and writes under one lock: a `serve` re-keying while the owner removes a chat must not write
|
|
464
|
-
* the removed chat back. A lock held too long refuses the change and leaves the list as it was. Blocks the thread
|
|
465
|
-
* while it waits: for callers that cannot be async, and `recipients remove` and `clear`, which never
|
|
466
|
-
* connect and so never run inside `serve`.
|
|
467
|
-
*/
|
|
468
|
-
#locked(body) {
|
|
469
|
-
return withFileLock(this.path, "the recipient list", body, this.lockWaitMs);
|
|
470
|
-
}
|
|
471
|
-
#write(chats) {
|
|
472
|
-
writeSecurely(this.path, `${JSON.stringify({ chats }, null, 2)}
|
|
473
|
-
`, 384);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/guard.js
|
|
478
|
-
var HOUR_MS = 60 * 60 * 1e3;
|
|
479
|
-
var READS_UNDER_HOLD = /* @__PURE__ */ new Set([
|
|
480
|
-
"attachments.extract",
|
|
481
|
-
"conversations.embeddings",
|
|
482
|
-
"conversations.links",
|
|
483
|
-
"messages.server-search",
|
|
484
|
-
"messages.sync-first",
|
|
485
|
-
"stats.contacts.top.sync-first",
|
|
486
|
-
"stats.messages.counters.sync",
|
|
487
|
-
"stats.messages.show.sync-first",
|
|
488
|
-
"stats.messages.top.sync-first",
|
|
489
|
-
"store.gaps.repair"
|
|
490
|
-
]);
|
|
491
|
-
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");
|
|
492
|
-
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");
|
|
493
|
-
var timeOf = /* @__PURE__ */ __name((entry) => Date.parse(entry.scheduledFor ?? entry.at), "timeOf");
|
|
494
|
-
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");
|
|
495
|
-
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");
|
|
496
|
-
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") }) => {
|
|
497
|
-
const currentPermissions = /* @__PURE__ */ __name(() => typeof permissions === "function" ? permissions() : permissions, "currentPermissions");
|
|
498
|
-
let reservation;
|
|
499
|
-
const answered = /* @__PURE__ */ new WeakSet();
|
|
500
|
-
const refuseReadOnly = /* @__PURE__ */ __name(() => {
|
|
501
|
-
if (readOnlyLock)
|
|
502
|
-
throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
|
|
503
|
-
}, "refuseReadOnly");
|
|
504
|
-
const refuseHeld = /* @__PURE__ */ __name(({ key }) => {
|
|
505
|
-
if (key !== void 0 && READS_UNDER_HOLD.has(key))
|
|
506
|
-
return;
|
|
507
|
-
const block = flood?.sendBlock();
|
|
508
|
-
if (!block)
|
|
509
|
-
return;
|
|
510
|
-
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 } });
|
|
511
|
-
}, "refuseHeld");
|
|
512
|
-
const permitted = /* @__PURE__ */ __name((request) => {
|
|
513
|
-
const { chatId, kind = "message", action, personIds } = request;
|
|
514
|
-
refuseReadOnly();
|
|
515
|
-
const levels = currentPermissions();
|
|
516
|
-
if (levels !== void 0) {
|
|
517
|
-
const key = request.key ?? keyForWrite(kind, action);
|
|
518
|
-
const { level, key: named } = levelFor(levels, key, permissionDefaults);
|
|
519
|
-
if (level === "deny" || level === "readonly")
|
|
520
|
-
throw levelRefusal({ profile, command, key, level, named, permissionSources }, permissionFix?.(request, key));
|
|
521
|
-
if (level === "ask" && !answered.has(request)) {
|
|
522
|
-
throw new CliError("confirmation_required", `${key} asks before it acts, and it was not asked`);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
const allowed = recipients.read();
|
|
526
|
-
if (chatId !== null && allowed && !allowed.some((chat) => chat.id === chatId)) {
|
|
527
|
-
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 });
|
|
528
|
-
}
|
|
529
|
-
const strangers = allowed ? (personIds ?? []).filter((id) => !allowed.some((chat) => chat.partnerId === id)) : [];
|
|
530
|
-
if (strangers.length > 0) {
|
|
531
|
-
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 });
|
|
532
|
-
}
|
|
533
|
-
}, "permitted");
|
|
534
|
-
const withinLimit = /* @__PURE__ */ __name((request, entries) => {
|
|
535
|
-
const { chatId, sendId } = request;
|
|
536
|
-
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
537
|
-
const count = weightOf(asked);
|
|
538
|
-
if (count > sendsPerHour) {
|
|
539
|
-
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`);
|
|
540
|
-
}
|
|
541
|
-
const at = request.scheduledFor ? Date.parse(request.scheduledFor) : now().getTime();
|
|
542
|
-
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);
|
|
543
|
-
const unsure = /* @__PURE__ */ __name((entry) => entry.outcome === "outcome_unknown", "unsure");
|
|
544
|
-
const same = /* @__PURE__ */ __name((a, b) => a.sendId !== void 0 && a.sendId === b.sendId && a.chatId === b.chatId, "same");
|
|
545
|
-
const last = [...counted].reverse().find((entry) => same(entry, { chatId, sendId }));
|
|
546
|
-
if (sendId !== void 0 && last && unsure(last)) {
|
|
547
|
-
if (last.sendAs !== request.sendAs) {
|
|
548
|
-
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 });
|
|
549
|
-
}
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
|
-
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);
|
|
553
|
-
const used = recent.reduce((sum, { weight }) => sum + weight, 0);
|
|
554
|
-
if (used + count > sendsPerHour) {
|
|
555
|
-
let freed = 0;
|
|
556
|
-
const opening = recent.find(({ weight }) => {
|
|
557
|
-
freed += weight;
|
|
558
|
-
return used - freed + count <= sendsPerHour;
|
|
559
|
-
});
|
|
560
|
-
const nextMs = (opening?.time ?? 0) + HOUR_MS;
|
|
561
|
-
const next = new Date(nextMs).toISOString();
|
|
562
|
-
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 });
|
|
563
|
-
}
|
|
564
|
-
return true;
|
|
565
|
-
}, "withinLimit");
|
|
566
|
-
const counting = /* @__PURE__ */ __name((request) => {
|
|
567
|
-
permitted(request);
|
|
568
|
-
refuseHeld(request);
|
|
569
|
-
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
570
|
-
const creatingTopic = request.kind === "chat" && request.action === "topic-create";
|
|
571
|
-
if (!countsTowardLimit(asked) && !creatingTopic)
|
|
572
|
-
return void 0;
|
|
573
|
-
const checked = /* @__PURE__ */ __name((entries) => {
|
|
574
|
-
if (!creatingTopic)
|
|
575
|
-
return withinLimit(request, entries);
|
|
576
|
-
if (request.sendId === void 0)
|
|
577
|
-
throw new CliError("validation_error", "a topic creation needs an attempt id");
|
|
578
|
-
if (entries.some((entry) => entry.action === "topic-create" && entry.sendId === request.sendId && ["sent", "outcome_unknown", "reserved"].includes(entry.outcome))) {
|
|
579
|
-
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 });
|
|
580
|
-
}
|
|
581
|
-
return true;
|
|
582
|
-
}, "checked");
|
|
583
|
-
const reserving = /* @__PURE__ */ __name(() => {
|
|
584
|
-
if (!checked(journal.entries()))
|
|
585
|
-
return;
|
|
586
|
-
const id = randomUUID();
|
|
587
|
-
const { chatId, kind, action, sendId, operationId, scheduledFor, notify } = request;
|
|
588
|
-
journal.append({
|
|
589
|
-
at: now().toISOString(),
|
|
590
|
-
profile,
|
|
591
|
-
chatId,
|
|
592
|
-
outcome: "reserved",
|
|
593
|
-
reservation: id,
|
|
594
|
-
...kind ? { kind } : {},
|
|
595
|
-
...action ? { action } : {},
|
|
596
|
-
...asked.people === void 0 ? {} : kind === "delete" || kind === "message" || kind === void 0 ? { count: asked.people } : { people: asked.people },
|
|
597
|
-
...sendId === void 0 ? {} : { sendId },
|
|
598
|
-
...operationId === void 0 ? {} : { operationId },
|
|
599
|
-
...scheduledFor ? { scheduledFor } : {},
|
|
600
|
-
...notify === void 0 ? {} : { notify }
|
|
601
|
-
});
|
|
602
|
-
reservation = id;
|
|
603
|
-
}, "reserving");
|
|
604
|
-
return { checked, reserving };
|
|
605
|
-
}, "counting");
|
|
606
|
-
return {
|
|
607
|
-
ask: /* @__PURE__ */ __name(async (request) => {
|
|
608
|
-
refuseReadOnly();
|
|
609
|
-
const levels = currentPermissions();
|
|
610
|
-
if (levels === void 0)
|
|
611
|
-
return;
|
|
612
|
-
const key = request.key ?? keyForWrite(request.kind ?? "message", request.action);
|
|
613
|
-
if (levelFor(levels, key, permissionDefaults).level !== "ask")
|
|
614
|
-
return;
|
|
615
|
-
refuseHeld(request);
|
|
616
|
-
await ask(key, request);
|
|
617
|
-
answered.add(request);
|
|
618
|
-
}, "ask"),
|
|
619
|
-
check: /* @__PURE__ */ __name((request, { reserve = true } = {}) => {
|
|
620
|
-
const counted = counting(request);
|
|
621
|
-
if (!counted)
|
|
622
|
-
return;
|
|
623
|
-
if (reserve)
|
|
624
|
-
journal.locked(counted.reserving);
|
|
625
|
-
else
|
|
626
|
-
counted.checked(journal.entries());
|
|
627
|
-
}, "check"),
|
|
628
|
-
reserve: /* @__PURE__ */ __name(async (request) => {
|
|
629
|
-
const counted = counting(request);
|
|
630
|
-
if (counted)
|
|
631
|
-
await journal.lockedAsync(counted.reserving);
|
|
632
|
-
}, "reserve"),
|
|
633
|
-
// After a send, a failure to write here must not become the command's answer: the message is
|
|
634
|
-
// already with a person, and an error would invite the caller to send it again.
|
|
635
|
-
record: /* @__PURE__ */ __name((entry) => {
|
|
636
|
-
const { personIds: _, ...kept } = entry;
|
|
637
|
-
const settles = entry.outcome === "refused" ? void 0 : reservation;
|
|
638
|
-
reservation = void 0;
|
|
639
|
-
try {
|
|
640
|
-
journal.append({ at: now().toISOString(), profile, ...kept, ...settles ? { reservation: settles } : {} });
|
|
641
|
-
} catch (error) {
|
|
642
|
-
warn(`this send is not in the send journal: ${journalFailure(error)}`, {
|
|
643
|
-
event: "warning",
|
|
644
|
-
code: "send_not_journaled",
|
|
645
|
-
operation: "sends.journal"
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
}, "record")
|
|
649
|
-
};
|
|
650
|
-
}, "sendGuard");
|
|
651
|
-
var refuseToAsk = /* @__PURE__ */ __name(async (key) => {
|
|
652
|
-
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`);
|
|
653
|
-
}, "refuseToAsk");
|
|
654
|
-
var guardFor = /* @__PURE__ */ __name((app, settings, warn, env = process.env, ask) => sendGuard({
|
|
655
|
-
profile: settings.profile,
|
|
656
|
-
command: app.command,
|
|
657
|
-
...settings.readOnlyLock ? { readOnlyLock: settings.readOnlyLock } : {},
|
|
658
|
-
permissions: /* @__PURE__ */ __name(() => settings.permissions, "permissions"),
|
|
659
|
-
permissionSources: settings.permissionSources,
|
|
660
|
-
...settings.permissionDefaults ? { permissionDefaults: settings.permissionDefaults } : {},
|
|
661
|
-
...ask ? { ask } : {},
|
|
662
|
-
sendsPerHour: settings.sendsPerHour,
|
|
663
|
-
journal: new SendJournal(sendsPathFor(app, settings.profile, env), { service: app.command, version: app.version }),
|
|
664
|
-
recipients: new RecipientList(recipientsPathFor(app, settings.profile, env), app.command),
|
|
665
|
-
flood: new FloodMemory(floodPathFor(app, settings.profile, env)),
|
|
666
|
-
warn
|
|
667
|
-
}), "guardFor");
|
|
668
|
-
var journalFailure = /* @__PURE__ */ __name((error) => error?.code ?? (error instanceof Error ? error.name : "error"), "journalFailure");
|
|
669
|
-
|
|
670
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/sends/pace.js
|
|
671
|
-
import { readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
672
|
-
import { join as join4 } from "node:path";
|
|
128
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/sends/pace.js
|
|
129
|
+
import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
130
|
+
import { join } from "node:path";
|
|
673
131
|
var DEFAULT_PACE = { perMinute: 60, burst: 20 };
|
|
674
|
-
var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
132
|
+
var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
|
|
675
133
|
var Pacer = class {
|
|
676
134
|
static {
|
|
677
135
|
__name(this, "Pacer");
|
|
@@ -689,12 +147,12 @@ var Pacer = class {
|
|
|
689
147
|
}
|
|
690
148
|
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
691
149
|
async reserve() {
|
|
692
|
-
const now = this.now();
|
|
693
150
|
if (this.interval === 0)
|
|
694
|
-
return now;
|
|
151
|
+
return this.now();
|
|
695
152
|
return withFileLockAsync(this.path, "the request pace", () => {
|
|
696
|
-
const
|
|
697
|
-
|
|
153
|
+
const now = this.now();
|
|
154
|
+
const tat = Math.max(this.read(now), now);
|
|
155
|
+
this.write(tat + this.interval, now);
|
|
698
156
|
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
699
157
|
});
|
|
700
158
|
}
|
|
@@ -703,26 +161,31 @@ var Pacer = class {
|
|
|
703
161
|
if (this.interval === 0)
|
|
704
162
|
return;
|
|
705
163
|
await withFileLockAsync(this.path, "the request pace", () => {
|
|
706
|
-
const
|
|
707
|
-
this.
|
|
164
|
+
const now = this.now();
|
|
165
|
+
const hold = now + waitMs + this.rate.burst * this.interval;
|
|
166
|
+
this.write(Math.max(this.read(now), hold), now);
|
|
708
167
|
});
|
|
709
168
|
}
|
|
710
169
|
/** The owner's `flood clear`: every process may go again at once. */
|
|
711
170
|
async reset() {
|
|
712
|
-
await withFileLockAsync(this.path, "the request pace", () => this.write(0));
|
|
171
|
+
await withFileLockAsync(this.path, "the request pace", () => this.write(0, this.now()));
|
|
713
172
|
}
|
|
714
|
-
read() {
|
|
173
|
+
read(now) {
|
|
715
174
|
try {
|
|
716
|
-
const
|
|
717
|
-
|
|
175
|
+
const file = JSON.parse(readFileSync(this.path, "utf8"));
|
|
176
|
+
const tat = Number(file.tat);
|
|
177
|
+
if (!Number.isFinite(tat))
|
|
178
|
+
return 0;
|
|
179
|
+
const at = Number(file.at);
|
|
180
|
+
return Number.isFinite(at) && at > now ? now + Math.max(0, tat - at) : tat;
|
|
718
181
|
} catch {
|
|
719
182
|
return 0;
|
|
720
183
|
}
|
|
721
184
|
}
|
|
722
|
-
write(tat) {
|
|
185
|
+
write(tat, at) {
|
|
723
186
|
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
724
|
-
|
|
725
|
-
|
|
187
|
+
writeFileSync(temporary, JSON.stringify({ tat, at }), { mode: 384 });
|
|
188
|
+
renameSync(temporary, this.path);
|
|
726
189
|
}
|
|
727
190
|
};
|
|
728
191
|
var ANNOUNCE_WAIT_MS = 5e3;
|
|
@@ -743,8 +206,8 @@ var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
|
|
|
743
206
|
const waitMs = at - now();
|
|
744
207
|
if (waitMs <= 0)
|
|
745
208
|
return;
|
|
746
|
-
if (waitMs > LONGEST_PACE_WAIT_MS)
|
|
747
|
-
throw new CliError("rate_limited",
|
|
209
|
+
if (waitMs > (options.longestWaitMs ?? LONGEST_PACE_WAIT_MS))
|
|
210
|
+
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 });
|
|
748
211
|
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
749
212
|
const seconds = Math.ceil(waitMs / 1e3);
|
|
750
213
|
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
|
@@ -757,7 +220,7 @@ var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
|
|
|
757
220
|
await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
|
|
758
221
|
}, "waitForTurn");
|
|
759
222
|
|
|
760
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
223
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
|
|
761
224
|
var HOUSEKEEPING = /* @__PURE__ */ new Set([
|
|
762
225
|
"help",
|
|
763
226
|
"guide",
|
|
@@ -837,7 +300,7 @@ var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, too
|
|
|
837
300
|
throw new CliError("validation_error", `--permission ${key} names no command`, { permission: key });
|
|
838
301
|
}, "refuseUnknownPermissionKeys");
|
|
839
302
|
|
|
840
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
303
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
|
|
841
304
|
var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
|
|
842
305
|
var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
|
|
843
306
|
var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
|
|
@@ -934,7 +397,7 @@ var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer })
|
|
|
934
397
|
});
|
|
935
398
|
}, "flooded");
|
|
936
399
|
|
|
937
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
400
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
|
|
938
401
|
var observed = /* @__PURE__ */ __name((messenger, events) => {
|
|
939
402
|
const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
|
|
940
403
|
const write = currentOperation();
|
|
@@ -1033,7 +496,7 @@ var byPart = /* @__PURE__ */ __name((batch, counts) => {
|
|
|
1033
496
|
counts[part] = (counts[part] ?? 0) + items.length;
|
|
1034
497
|
}, "byPart");
|
|
1035
498
|
|
|
1036
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
499
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
|
|
1037
500
|
var REKEY_PACING = { lockMs: 50, pauseMs: 25 };
|
|
1038
501
|
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" }) => {
|
|
1039
502
|
let warned = false;
|
|
@@ -1154,13 +617,13 @@ var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events,
|
|
|
1154
617
|
}
|
|
1155
618
|
if (round !== rekeyRound)
|
|
1156
619
|
return;
|
|
1157
|
-
const
|
|
1158
|
-
rekeysQueued -=
|
|
620
|
+
const taken = pass?.taken ?? rest.length;
|
|
621
|
+
rekeysQueued -= taken;
|
|
1159
622
|
for (const { from, to } of pass?.applied ?? [])
|
|
1160
623
|
await Promise.resolve().then(() => rekeyed?.(from, to)).catch((error) => notWritten("history.rekey", error));
|
|
1161
624
|
for (const { error } of pass?.refused ?? [])
|
|
1162
625
|
notWritten("history.rekey", error);
|
|
1163
|
-
rest = rest.slice(
|
|
626
|
+
rest = rest.slice(taken);
|
|
1164
627
|
if (rest.length > 0)
|
|
1165
628
|
await new Promise((resolve) => setTimeout(resolve, rekeyPacing.pauseMs));
|
|
1166
629
|
}
|
|
@@ -1609,7 +1072,7 @@ var keep = /* @__PURE__ */ __name(async (store, account, event, seenAt, among, c
|
|
|
1609
1072
|
}
|
|
1610
1073
|
}, "keep");
|
|
1611
1074
|
|
|
1612
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
1075
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
|
|
1613
1076
|
var lazyStore = /* @__PURE__ */ __name((env, command, version) => {
|
|
1614
1077
|
let opened;
|
|
1615
1078
|
return {
|
|
@@ -1951,6 +1414,7 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
|
|
|
1951
1414
|
history: base.settings.record,
|
|
1952
1415
|
searchCatchUp: base.settings.searchCatchUp,
|
|
1953
1416
|
...base.settings.historyLimits ? { historyLimits: base.settings.historyLimits } : {},
|
|
1417
|
+
historyMuted: base.settings.historyMuted,
|
|
1954
1418
|
pictures: base.settings.pictureSearch,
|
|
1955
1419
|
reranker: base.settings.searchReranker,
|
|
1956
1420
|
guard,
|
|
@@ -2007,27 +1471,17 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
|
|
|
2007
1471
|
}, "messengerContext");
|
|
2008
1472
|
|
|
2009
1473
|
export {
|
|
2010
|
-
sendsPathFor,
|
|
2011
|
-
SendJournal,
|
|
2012
1474
|
answerOf,
|
|
2013
1475
|
terminalAsker,
|
|
2014
|
-
holdEnd,
|
|
2015
|
-
floodPathFor,
|
|
2016
|
-
FloodMemory,
|
|
2017
1476
|
DEFAULT_PACE,
|
|
2018
1477
|
pacePathFor,
|
|
2019
1478
|
Pacer,
|
|
2020
|
-
recipientsPathFor,
|
|
2021
|
-
RecipientList,
|
|
2022
|
-
ceilingRefusal,
|
|
2023
|
-
levelRefusal,
|
|
2024
|
-
sendGuard,
|
|
2025
|
-
guardFor,
|
|
2026
1479
|
commandPermissions,
|
|
2027
1480
|
knownPermissionKeys,
|
|
2028
1481
|
knownBeside,
|
|
2029
1482
|
unknownPermissionIssues,
|
|
2030
1483
|
refuseUnknownPermissionKeys,
|
|
1484
|
+
fill,
|
|
2031
1485
|
connectedFor,
|
|
2032
1486
|
refuseLocalWrite,
|
|
2033
1487
|
messengerContext
|