@wirecat/yandex-disk-cli 0.0.0-stage → 0.1.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 +25 -0
- package/LICENSE +204 -0
- package/README.md +243 -2
- package/contracts/wirecat.json +1554 -0
- package/dist/bin/ydisk.d.ts +3 -0
- package/dist/bin/ydisk.d.ts.map +1 -0
- package/dist/bin/ydisk.js +40 -0
- package/dist/bin/ydisk.js.map +1 -0
- package/dist/bundle/all-profiles-4OLZF3RT.js +279 -0
- package/dist/bundle/anthropic-DKB4OJXZ.js +91 -0
- package/dist/bundle/app-server-G4545SSV.js +247 -0
- package/dist/bundle/bun-RXEQKFED.js +169 -0
- package/dist/bundle/bun-sqlite-VHT5LN7U.js +76 -0
- package/dist/bundle/chunk-2BITUXGC.js +12289 -0
- package/dist/bundle/chunk-2CLWDQKA.js +39330 -0
- package/dist/bundle/chunk-2JFDOPKA.js +9575 -0
- package/dist/bundle/chunk-3GVI2MAO.js +106 -0
- package/dist/bundle/chunk-3SZBWBMI.js +131 -0
- package/dist/bundle/chunk-44VSEXW6.js +4054 -0
- package/dist/bundle/chunk-4YPRRQBE.js +95 -0
- package/dist/bundle/chunk-5COYRL5B.js +379 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5DM7DIZL.js +1402 -0
- package/dist/bundle/chunk-6R2DVTVZ.js +24 -0
- package/dist/bundle/chunk-762BS35H.js +2787 -0
- package/dist/bundle/chunk-AG64V7AB.js +1233 -0
- package/dist/bundle/chunk-BC5HGIXB.js +334 -0
- package/dist/bundle/chunk-BH7LFEX7.js +36 -0
- package/dist/bundle/chunk-BLNPGY7N.js +53 -0
- package/dist/bundle/chunk-CNIA2LJF.js +372 -0
- package/dist/bundle/chunk-COSXMDC7.js +230 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-D7FO33KU.js +785 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DJH26PQ3.js +1396 -0
- package/dist/bundle/chunk-DJPT7IUC.js +64567 -0
- package/dist/bundle/chunk-DTMSCZDW.js +209 -0
- package/dist/bundle/chunk-E6LGZ5LX.js +16 -0
- package/dist/bundle/chunk-E6YRIHS5.js +92 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-F3DDSZTF.js +78 -0
- package/dist/bundle/chunk-F4WWTQNL.js +188 -0
- package/dist/bundle/chunk-FDDAUASC.js +1028 -0
- package/dist/bundle/chunk-FMNPG6N2.js +170 -0
- package/dist/bundle/chunk-FOKJ4POB.js +274 -0
- package/dist/bundle/chunk-G22C7JG6.js +731 -0
- package/dist/bundle/chunk-GA442SYZ.js +161 -0
- package/dist/bundle/chunk-GEBSW7UK.js +6848 -0
- package/dist/bundle/chunk-GGRKWAOK.js +594 -0
- package/dist/bundle/chunk-HHINRNZA.js +788 -0
- package/dist/bundle/chunk-HUZCL33L.js +128 -0
- package/dist/bundle/chunk-IALSIQVT.js +142 -0
- package/dist/bundle/chunk-IOXR2QBX.js +398 -0
- package/dist/bundle/chunk-J5CXR6VX.js +63 -0
- package/dist/bundle/chunk-J5PWSTOX.js +82 -0
- package/dist/bundle/chunk-J7BVAEHR.js +364 -0
- package/dist/bundle/chunk-JH46HMZW.js +1334 -0
- package/dist/bundle/chunk-JOBO7F6W.js +52 -0
- package/dist/bundle/chunk-JXZ5B3L5.js +2333 -0
- package/dist/bundle/chunk-KBIAMDZN.js +66 -0
- package/dist/bundle/chunk-KFVDL2QS.js +146 -0
- package/dist/bundle/chunk-LNHTLSR5.js +288 -0
- package/dist/bundle/chunk-M24RAKMJ.js +58 -0
- package/dist/bundle/chunk-MDQ57Q3H.js +1197 -0
- package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
- package/dist/bundle/chunk-MLXQ4X5L.js +206 -0
- package/dist/bundle/chunk-NQAKARHE.js +54 -0
- package/dist/bundle/chunk-OF7VVUDQ.js +23 -0
- package/dist/bundle/chunk-OQVPE3XK.js +324 -0
- package/dist/bundle/chunk-OR3QG7UR.js +259 -0
- package/dist/bundle/chunk-OUUYVROP.js +76 -0
- package/dist/bundle/chunk-PQBAM64O.js +168 -0
- package/dist/bundle/chunk-PYVIA7WF.js +88 -0
- package/dist/bundle/chunk-Q6HK3PHE.js +72 -0
- package/dist/bundle/chunk-QB3KECV2.js +218 -0
- package/dist/bundle/chunk-QGWXSFYN.js +73 -0
- package/dist/bundle/chunk-RC5QAAAE.js +29 -0
- package/dist/bundle/chunk-RMJ26HLB.js +18 -0
- package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
- package/dist/bundle/chunk-T7ZUDA4C.js +72 -0
- package/dist/bundle/chunk-TRCSMVV5.js +72 -0
- package/dist/bundle/chunk-UD2BQEKA.js +46 -0
- package/dist/bundle/chunk-V4TL55GS.js +1068 -0
- package/dist/bundle/chunk-VJNWN5VU.js +4072 -0
- package/dist/bundle/chunk-VRRNBLMA.js +1227 -0
- package/dist/bundle/chunk-WUCMMNFJ.js +771 -0
- package/dist/bundle/chunk-XDESE3NY.js +44 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-Z2QEON7B.js +2275 -0
- package/dist/bundle/chunk-ZMJ56GME.js +7 -0
- package/dist/bundle/chunk-ZTSB3D7Q.js +100 -0
- package/dist/bundle/chunk-ZVJWD3FK.js +38 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-YIOYGPJA.js +40 -0
- package/dist/bundle/command-server-entry-MHBQDXS4.js +169 -0
- package/dist/bundle/decode-NUGJIOUW.js +297 -0
- package/dist/bundle/definitions-AILHKEQT.js +2005 -0
- package/dist/bundle/dispatch-5LC4UEGY.js +411 -0
- package/dist/bundle/dist-4I2W6X2I.js +7577 -0
- package/dist/bundle/echarts-MHSH6PGC.js +42501 -0
- package/dist/bundle/embed-ZDXTHHYS.js +38 -0
- package/dist/bundle/embedder-XFEELFUL.js +111 -0
- package/dist/bundle/failure-5S7VPBYK.js +25 -0
- package/dist/bundle/first-run-JHCHT3RJ.js +29 -0
- package/dist/bundle/first-screen-FHGQ6QRV.js +40 -0
- package/dist/bundle/instructions-WKSMBUFX.js +11 -0
- package/dist/bundle/mcp-HS2ZDUVR.js +167 -0
- package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
- package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
- package/dist/bundle/meeting-combined-K4U4NYRZ.js +25 -0
- package/dist/bundle/meeting-model-KCEG6Y5O.js +26 -0
- package/dist/bundle/meeting-semantic-VYGSV3H6.js +22 -0
- package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
- package/dist/bundle/node-CM6NC6UE.js +176 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-5YDQ3LIJ.js +74 -0
- package/dist/bundle/notes-search-PGO7KM2U.js +62 -0
- package/dist/bundle/oauth-NY4C5UCK.js +20 -0
- package/dist/bundle/open-YNUTA6ZE.js +23 -0
- package/dist/bundle/openai-4CVT5PHH.js +241 -0
- package/dist/bundle/process-2XT3TL27.js +91 -0
- package/dist/bundle/program-FMIVF5T6.js +31904 -0
- package/dist/bundle/prompt-VNWY3H6S.js +17 -0
- package/dist/bundle/recognize-JS4PBPSZ.js +26 -0
- package/dist/bundle/remote-RCLFH4V2.js +32 -0
- package/dist/bundle/rerank-EG6VKYGO.js +52 -0
- package/dist/bundle/schemas-ED2LHKXK.js +645 -0
- package/dist/bundle/serve-AHG25QXB.js +199 -0
- package/dist/bundle/server-5FTB7WM3.js +78 -0
- package/dist/bundle/server-JNZVSAZE.js +209 -0
- package/dist/bundle/sqlite-runtime-XSZOAQPF.js +20 -0
- package/dist/bundle/state-XGVAJFF7.js +36 -0
- package/dist/bundle/store-OHSCWZEV.js +177 -0
- package/dist/bundle/store-PKSPKJXL.js +293 -0
- package/dist/bundle/store-maintenance-command-KAWGBSWK.js +69 -0
- package/dist/bundle/ydisk.js +183 -0
- package/dist/commands/api.d.ts +9 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +59 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/files.d.ts +3 -0
- package/dist/commands/files.d.ts.map +1 -0
- package/dist/commands/files.js +272 -0
- package/dist/commands/files.js.map +1 -0
- package/dist/commands/library.d.ts +13 -0
- package/dist/commands/library.d.ts.map +1 -0
- package/dist/commands/library.js +118 -0
- package/dist/commands/library.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +99 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +62 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +80 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +77 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +2001 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +1473 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/schemas.d.ts +127 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +545 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +829 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +10 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +33 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +65 -0
- package/dist/program.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- 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/dist/yandex/source.d.ts +39 -0
- package/dist/yandex/source.d.ts.map +1 -0
- package/dist/yandex/source.js +189 -0
- package/dist/yandex/source.js.map +1 -0
- package/dist/yandex/transport.d.ts +41 -0
- package/dist/yandex/transport.d.ts.map +1 -0
- package/dist/yandex/transport.js +152 -0
- package/dist/yandex/transport.js.map +1 -0
- package/dist/yandex/writes.d.ts +27 -0
- package/dist/yandex/writes.d.ts.map +1 -0
- package/dist/yandex/writes.js +61 -0
- package/dist/yandex/writes.js.map +1 -0
- package/package.json +88 -4
- package/skills/yandex-disk-cli/SKILL.md +46 -0
- package/skills/yandex-disk-cli/references/api/api-disk-operations-operation-id.md +13 -0
- package/skills/yandex-disk-cli/references/api/api-disk-public-resources.md +50 -0
- package/skills/yandex-disk-cli/references/api/api-disk-resources.md +171 -0
- package/skills/yandex-disk-cli/references/api/api-disk-trash-resources.md +48 -0
- package/skills/yandex-disk-cli/references/api/api-disk.md +13 -0
- package/skills/yandex-disk-cli/references/api.md +17 -0
|
@@ -0,0 +1,1396 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_PACE,
|
|
5
|
+
FloodMemory,
|
|
6
|
+
Pacer,
|
|
7
|
+
RecipientList,
|
|
8
|
+
ceilingRefusal,
|
|
9
|
+
floodPathFor,
|
|
10
|
+
guardFor,
|
|
11
|
+
holdEnd,
|
|
12
|
+
pacePathFor,
|
|
13
|
+
recipientsPathFor,
|
|
14
|
+
refuseLacking,
|
|
15
|
+
servicesFor,
|
|
16
|
+
waitForTurn
|
|
17
|
+
} from "./chunk-2CLWDQKA.js";
|
|
18
|
+
import {
|
|
19
|
+
OFFLINE,
|
|
20
|
+
capability,
|
|
21
|
+
chatIdIn,
|
|
22
|
+
profilesOnAccount,
|
|
23
|
+
throughWrapper
|
|
24
|
+
} from "./chunk-Z2QEON7B.js";
|
|
25
|
+
import {
|
|
26
|
+
servingProfiles
|
|
27
|
+
} from "./chunk-QGWXSFYN.js";
|
|
28
|
+
import {
|
|
29
|
+
AUTHORITY_KEY,
|
|
30
|
+
CEILING_KEY,
|
|
31
|
+
DEFAULT_PERMISSIONS,
|
|
32
|
+
KEYED_UNDER_HOUSEKEEPING,
|
|
33
|
+
WRITE_KEYS,
|
|
34
|
+
asFirstWord,
|
|
35
|
+
baseContext,
|
|
36
|
+
environmentOf,
|
|
37
|
+
fetchesUnder,
|
|
38
|
+
issueMessage,
|
|
39
|
+
keyForCommand,
|
|
40
|
+
levelFor,
|
|
41
|
+
limitBatch,
|
|
42
|
+
permissionIssues,
|
|
43
|
+
publicIssue,
|
|
44
|
+
readKeysForCommand,
|
|
45
|
+
recalledAccount,
|
|
46
|
+
rememberAccount,
|
|
47
|
+
rootOf2 as rootOf,
|
|
48
|
+
skipFlagFor
|
|
49
|
+
} from "./chunk-2BITUXGC.js";
|
|
50
|
+
import {
|
|
51
|
+
providerErrorKey
|
|
52
|
+
} from "./chunk-J7BVAEHR.js";
|
|
53
|
+
import {
|
|
54
|
+
codeOf,
|
|
55
|
+
currentOperation
|
|
56
|
+
} from "./chunk-IOXR2QBX.js";
|
|
57
|
+
import {
|
|
58
|
+
openStore
|
|
59
|
+
} from "./chunk-DJPT7IUC.js";
|
|
60
|
+
import {
|
|
61
|
+
chatReferenceOf,
|
|
62
|
+
ensureAccount,
|
|
63
|
+
foldName,
|
|
64
|
+
isId,
|
|
65
|
+
pickPerson
|
|
66
|
+
} from "./chunk-GGRKWAOK.js";
|
|
67
|
+
import {
|
|
68
|
+
isCliFailure
|
|
69
|
+
} from "./chunk-TRCSMVV5.js";
|
|
70
|
+
import {
|
|
71
|
+
CliError
|
|
72
|
+
} from "./chunk-T7ZUDA4C.js";
|
|
73
|
+
import {
|
|
74
|
+
__name
|
|
75
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
76
|
+
|
|
77
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
|
|
78
|
+
import { openSync } from "node:fs";
|
|
79
|
+
import { createInterface } from "node:readline";
|
|
80
|
+
import { ReadStream } from "node:tty";
|
|
81
|
+
var fromTerminal = /* @__PURE__ */ __name(async (question) => {
|
|
82
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY)
|
|
83
|
+
return null;
|
|
84
|
+
let input;
|
|
85
|
+
try {
|
|
86
|
+
input = new ReadStream(openSync("/dev/tty", "r"));
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const reader = createInterface({ input, output: process.stderr, terminal: true });
|
|
91
|
+
try {
|
|
92
|
+
return await new Promise((resolve, reject) => {
|
|
93
|
+
const cancel = /* @__PURE__ */ __name(() => reject(new CliError("cancelled", "cancelled \u2014 nothing was done")), "cancel");
|
|
94
|
+
reader.once("SIGINT", cancel);
|
|
95
|
+
reader.once("close", cancel);
|
|
96
|
+
reader.question(question, resolve);
|
|
97
|
+
});
|
|
98
|
+
} finally {
|
|
99
|
+
reader.close();
|
|
100
|
+
input.destroy();
|
|
101
|
+
}
|
|
102
|
+
}, "fromTerminal");
|
|
103
|
+
var what = /* @__PURE__ */ __name((key, { chatId, count, personIds, forEveryone }) => [
|
|
104
|
+
key,
|
|
105
|
+
forEveryone ? "for everyone" : void 0,
|
|
106
|
+
count !== void 0 ? `${count} ${count === 1 ? "item" : "items"}` : void 0,
|
|
107
|
+
personIds?.length ? `${personIds.length} ${personIds.length === 1 ? "person" : "people"}` : void 0,
|
|
108
|
+
chatId !== null ? `in chat ${chatId}` : void 0
|
|
109
|
+
].filter(Boolean).join(", "), "what");
|
|
110
|
+
var answerOf = /* @__PURE__ */ __name(async (command, question) => {
|
|
111
|
+
const given = command.optsWithGlobals();
|
|
112
|
+
if (given.json === true || given.jsonl === true)
|
|
113
|
+
return null;
|
|
114
|
+
return (environmentOf(command).answer ?? fromTerminal)(question);
|
|
115
|
+
}, "answerOf");
|
|
116
|
+
var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) => {
|
|
117
|
+
if (environmentOf(command).agent)
|
|
118
|
+
return;
|
|
119
|
+
const flag = skipFlagFor(key);
|
|
120
|
+
const given = command.optsWithGlobals();
|
|
121
|
+
if (flag === "--yes" ? given.yes === true : given.allowDangerous === true)
|
|
122
|
+
return;
|
|
123
|
+
const machine = given.json === true || given.jsonl === true;
|
|
124
|
+
const answer = machine ? null : await (environmentOf(command).answer ?? fromTerminal)(`${what(key, request)} \u2014 go ahead? [y/N] `);
|
|
125
|
+
if (answer === null) {
|
|
126
|
+
throw new CliError("confirmation_required", `${key} asks before it acts (its permission level is ask), and nobody is at a terminal to answer \u2014 add ${flag} to go ahead`, { permission: key });
|
|
127
|
+
}
|
|
128
|
+
if (!/^\s*y(es)?\s*$/i.test(answer))
|
|
129
|
+
throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
|
|
130
|
+
}, "terminalAsker");
|
|
131
|
+
|
|
132
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
|
|
133
|
+
var HOUSEKEEPING = /* @__PURE__ */ new Set([
|
|
134
|
+
"help",
|
|
135
|
+
"guide",
|
|
136
|
+
"config",
|
|
137
|
+
"session",
|
|
138
|
+
"doctor",
|
|
139
|
+
"commands",
|
|
140
|
+
"complete",
|
|
141
|
+
"upgrade",
|
|
142
|
+
"skill",
|
|
143
|
+
"mcp",
|
|
144
|
+
"runs"
|
|
145
|
+
]);
|
|
146
|
+
var commandPathKey = /* @__PURE__ */ __name((path) => path[0] === void 0 || HOUSEKEEPING.has(path[0]) && !KEYED_UNDER_HOUSEKEEPING.has(path.join(".")) ? null : path.join("."), "commandPathKey");
|
|
147
|
+
var commandPermissions = /* @__PURE__ */ __name(({ keyOf = commandPathKey, extra = [], defaults = {}, alsoChecks } = {}) => ({
|
|
148
|
+
keyOf,
|
|
149
|
+
extra: [AUTHORITY_KEY, ...extra],
|
|
150
|
+
defaults: { ...DEFAULT_PERMISSIONS, ...defaults },
|
|
151
|
+
...alsoChecks ? { alsoChecks } : {}
|
|
152
|
+
}), "commandPermissions");
|
|
153
|
+
var pathOf = /* @__PURE__ */ __name((command) => {
|
|
154
|
+
const words = [];
|
|
155
|
+
for (let at = command; at?.parent; at = at.parent)
|
|
156
|
+
words.unshift(at.name());
|
|
157
|
+
return words;
|
|
158
|
+
}, "pathOf");
|
|
159
|
+
var rootOf2 = /* @__PURE__ */ __name((command) => {
|
|
160
|
+
let at = command;
|
|
161
|
+
while (at.parent)
|
|
162
|
+
at = at.parent;
|
|
163
|
+
return at;
|
|
164
|
+
}, "rootOf");
|
|
165
|
+
var everyCommand = /* @__PURE__ */ __name((command) => [command, ...command.commands.flatMap(everyCommand)], "everyCommand");
|
|
166
|
+
var knownPermissionKeys = /* @__PURE__ */ __name((command, keyOf = (one) => keyForCommand(pathOf(one)), extra = []) => {
|
|
167
|
+
const known = /* @__PURE__ */ new Set();
|
|
168
|
+
const add = /* @__PURE__ */ __name((key) => {
|
|
169
|
+
for (let parts = key.split("."); parts.length > 0; parts = parts.slice(0, -1))
|
|
170
|
+
known.add(parts.join("."));
|
|
171
|
+
}, "add");
|
|
172
|
+
if (typeof keyOf !== "function") {
|
|
173
|
+
for (const one of everyCommand(rootOf2(command))) {
|
|
174
|
+
const key = keyOf.keyOf(pathOf(one));
|
|
175
|
+
if (key)
|
|
176
|
+
add(key);
|
|
177
|
+
}
|
|
178
|
+
for (const key of [...keyOf.extra, ...extra])
|
|
179
|
+
add(key);
|
|
180
|
+
return known;
|
|
181
|
+
}
|
|
182
|
+
for (const one of everyCommand(rootOf2(command))) {
|
|
183
|
+
const own = keyOf(one);
|
|
184
|
+
const key = own === void 0 ? keyForCommand(pathOf(one)) : own;
|
|
185
|
+
if (key)
|
|
186
|
+
add(key);
|
|
187
|
+
}
|
|
188
|
+
for (const key of [...WRITE_KEYS, ...extra])
|
|
189
|
+
add(key);
|
|
190
|
+
return known;
|
|
191
|
+
}, "knownPermissionKeys");
|
|
192
|
+
var knownBeside = /* @__PURE__ */ __name((key, known) => {
|
|
193
|
+
const parent = key.split(".").slice(0, -1).join(".");
|
|
194
|
+
const depth = parent === "" ? 1 : parent.split(".").length + 1;
|
|
195
|
+
return [...known].filter((one) => one.split(".").length === depth && (parent === "" || one.startsWith(`${parent}.`))).sort();
|
|
196
|
+
}, "knownBeside");
|
|
197
|
+
var unknownPermissionKeys = /* @__PURE__ */ __name((levels, known) => Object.keys(levels).filter((key) => key !== CEILING_KEY && !known.has(key)), "unknownPermissionKeys");
|
|
198
|
+
var unknownPermissionIssues = /* @__PURE__ */ __name((command, settings, tool, keyOf) => {
|
|
199
|
+
const saved = settings.savedPermissions ?? Object.keys(settings.permissions).filter((key) => key !== CEILING_KEY && settings.permissionSources[key] !== "flag").map((key) => ({ key, at: ["profiles", settings.profile, "permissions", key] }));
|
|
200
|
+
return permissionIssues(saved, knownPermissionKeys(command, keyOf), { file: settings.configPath, tool }).map(publicIssue);
|
|
201
|
+
}, "unknownPermissionIssues");
|
|
202
|
+
var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, tool, keyOf) => {
|
|
203
|
+
const issues = unknownPermissionIssues(command, settings, tool, keyOf);
|
|
204
|
+
if (issues.length > 0)
|
|
205
|
+
throw new CliError("configuration_error", issueMessage(issues), { permission: issues[0]?.key });
|
|
206
|
+
const flagged = Object.keys(settings.permissions).filter((key2) => settings.permissionSources[key2] === "flag");
|
|
207
|
+
const [key] = unknownPermissionKeys(Object.fromEntries(flagged.map((one) => [one, true])), knownPermissionKeys(command, keyOf));
|
|
208
|
+
if (key !== void 0)
|
|
209
|
+
throw new CliError("validation_error", `--permission ${key} names no command`, { permission: key });
|
|
210
|
+
}, "refuseUnknownPermissionKeys");
|
|
211
|
+
|
|
212
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
|
|
213
|
+
var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
|
|
214
|
+
var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
|
|
215
|
+
var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
|
|
216
|
+
var chatOf = /* @__PURE__ */ __name((args) => typeof args[0] === "string" && /^-?\d+$/.test(args[0]) ? args[0] : void 0, "chatOf");
|
|
217
|
+
var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer }) => {
|
|
218
|
+
const kept = /* @__PURE__ */ __name(async (operation, what2) => {
|
|
219
|
+
try {
|
|
220
|
+
await what2();
|
|
221
|
+
} catch (error) {
|
|
222
|
+
warn(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
223
|
+
event: "warning",
|
|
224
|
+
code: "wait_not_remembered",
|
|
225
|
+
operation
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}, "kept");
|
|
229
|
+
const noted = /* @__PURE__ */ __name(async (operation, chatId, error) => {
|
|
230
|
+
if (!isCliFailure(error))
|
|
231
|
+
return;
|
|
232
|
+
const details = error.details ?? {};
|
|
233
|
+
const standing = details.standing;
|
|
234
|
+
if (standing && BLOCKING.has(standing.state)) {
|
|
235
|
+
await kept(operation, () => {
|
|
236
|
+
const block = memory.block({
|
|
237
|
+
state: standing.state,
|
|
238
|
+
hint: standing.hint ?? error.message,
|
|
239
|
+
...standing.until ? { until: standing.until } : {}
|
|
240
|
+
});
|
|
241
|
+
warn(`writes from this profile are held ${holdEnd(block)}: ${block.hint}`, {
|
|
242
|
+
event: "warning",
|
|
243
|
+
code: `account_${block.state}`,
|
|
244
|
+
operation
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const waitMs = Number(details.retry_after_ms);
|
|
250
|
+
if (error.code !== "rate_limited" || details.remembered === true || !Number.isFinite(waitMs) || waitMs <= 0)
|
|
251
|
+
return;
|
|
252
|
+
const providerError = providerErrorKey(details.provider_error);
|
|
253
|
+
await kept(operation, () => {
|
|
254
|
+
const deadline = memory.remember({
|
|
255
|
+
operation,
|
|
256
|
+
...chatId ? { chatId } : {},
|
|
257
|
+
...providerError ? { providerError } : {},
|
|
258
|
+
waitMs
|
|
259
|
+
});
|
|
260
|
+
warn(`${name} asked to wait before ${operation} again \u2014 until ${deadline.until}`, {
|
|
261
|
+
event: "warning",
|
|
262
|
+
code: "flood_wait",
|
|
263
|
+
operation,
|
|
264
|
+
counts: { seconds: Math.ceil(waitMs / 1e3) }
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
if (pacer)
|
|
268
|
+
await kept(operation, () => pacer.holdFor(waitMs));
|
|
269
|
+
}, "noted");
|
|
270
|
+
const turn = /* @__PURE__ */ __name(async (operation) => {
|
|
271
|
+
if (pacer)
|
|
272
|
+
await waitForTurn(pacer, { name, operation, warn });
|
|
273
|
+
}, "turn");
|
|
274
|
+
return throughWrapper(messenger, {}, (operation, call) => {
|
|
275
|
+
if (LONG_LIVED.has(operation))
|
|
276
|
+
return call;
|
|
277
|
+
if (LISTENING.has(operation))
|
|
278
|
+
return (async (...args) => {
|
|
279
|
+
try {
|
|
280
|
+
return await call(...args);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
await noted(operation, void 0, error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
return (async (...args) => {
|
|
287
|
+
const chatId = chatOf(args);
|
|
288
|
+
const owed = memory.owed(operation, chatId);
|
|
289
|
+
if (owed) {
|
|
290
|
+
const waitMs = Math.max(0, Date.parse(owed.until) - Date.now());
|
|
291
|
+
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}`, {
|
|
292
|
+
retry_after_ms: waitMs,
|
|
293
|
+
retry_at: owed.until,
|
|
294
|
+
remembered: true,
|
|
295
|
+
...owed.providerError ? { provider_error: owed.providerError } : {}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
await turn(operation);
|
|
299
|
+
try {
|
|
300
|
+
return await call(...args);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
await noted(operation, chatId, error);
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}, "flooded");
|
|
308
|
+
|
|
309
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
|
|
310
|
+
var observed = /* @__PURE__ */ __name((messenger, events) => {
|
|
311
|
+
const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
|
|
312
|
+
const write = currentOperation();
|
|
313
|
+
const marked = /* @__PURE__ */ __name((part = {}) => write === void 0 ? part : { ...part, ids: { ...part.ids, operation: write } }, "marked");
|
|
314
|
+
events({ event: "request", operation, level: "operation", ...marked(named) });
|
|
315
|
+
const started = performance.now();
|
|
316
|
+
const durationMs = /* @__PURE__ */ __name(() => Math.round(performance.now() - started), "durationMs");
|
|
317
|
+
try {
|
|
318
|
+
const answer = await work();
|
|
319
|
+
events({
|
|
320
|
+
event: "response",
|
|
321
|
+
operation,
|
|
322
|
+
level: "operation",
|
|
323
|
+
durationMs: durationMs(),
|
|
324
|
+
outcome: "ok",
|
|
325
|
+
...marked(after?.(answer))
|
|
326
|
+
});
|
|
327
|
+
return answer;
|
|
328
|
+
} catch (error) {
|
|
329
|
+
const providerError = isCliFailure(error) ? providerErrorKey(error.details?.provider_error) : void 0;
|
|
330
|
+
events({
|
|
331
|
+
event: "response",
|
|
332
|
+
operation,
|
|
333
|
+
level: "operation",
|
|
334
|
+
durationMs: durationMs(),
|
|
335
|
+
outcome: "error",
|
|
336
|
+
errorCode: isCliFailure(error) ? error.code : "generic_failure",
|
|
337
|
+
...providerError ? { providerError } : {},
|
|
338
|
+
...marked()
|
|
339
|
+
});
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
}, "timed");
|
|
343
|
+
const counted = /* @__PURE__ */ __name(async (operation, onItem, work, count) => {
|
|
344
|
+
const counts = {};
|
|
345
|
+
await timed(operation, {}, () => work((item, ...rest) => {
|
|
346
|
+
count(item, counts);
|
|
347
|
+
return onItem(item, ...rest);
|
|
348
|
+
}), () => ({ counts }));
|
|
349
|
+
}, "counted");
|
|
350
|
+
const mint = messenger.newSendId;
|
|
351
|
+
const { chats, history, contact, around, watch, feed, listen, listenHistory } = messenger;
|
|
352
|
+
return throughWrapper(messenger, {
|
|
353
|
+
self: /* @__PURE__ */ __name(() => messenger.self(), "self"),
|
|
354
|
+
...mint ? { newSendId: /* @__PURE__ */ __name(() => mint.call(messenger), "newSendId") } : {},
|
|
355
|
+
me: /* @__PURE__ */ __name(() => timed("account.me", {}, () => messenger.me()), "me"),
|
|
356
|
+
...chats ? {
|
|
357
|
+
chats: /* @__PURE__ */ __name((window) => timed("chats.list", {}, () => chats.call(messenger, window), (page) => ({ counts: { chats: page.items.length } })), "chats")
|
|
358
|
+
} : {},
|
|
359
|
+
...history ? {
|
|
360
|
+
history: /* @__PURE__ */ __name((reference, options) => timed("messages.list", {}, () => history.call(messenger, reference, options), (page) => ({
|
|
361
|
+
...page.items[0] ? { ids: { chat: page.items[0].chatId } } : {},
|
|
362
|
+
counts: { messages: page.items.length }
|
|
363
|
+
})), "history")
|
|
364
|
+
} : {},
|
|
365
|
+
resolve: /* @__PURE__ */ __name((reference) => timed("chats.resolve", {}, () => messenger.resolve(reference), (chat) => ({ ids: { chat: chat.id } })), "resolve"),
|
|
366
|
+
chat: /* @__PURE__ */ __name((reference) => timed("chats.show", {}, () => messenger.chat(reference), (card) => ({ ids: { chat: card.id }, ...card.members ? { counts: { members: card.members.length } } : {} })), "chat"),
|
|
367
|
+
...contact ? {
|
|
368
|
+
contact: /* @__PURE__ */ __name((reference) => timed("contacts.show", {}, () => contact.call(messenger, reference), (card) => ({ ids: { person: card.id }, counts: { chats: card.chats.length } })), "contact")
|
|
369
|
+
} : {},
|
|
370
|
+
...around ? {
|
|
371
|
+
around: /* @__PURE__ */ __name((reference, messageId, window) => timed("messages.around", { ids: { message_id: messageId } }, () => around.call(messenger, reference, messageId, window), (items) => ({
|
|
372
|
+
...items[0] ? { ids: { chat: items[0].chatId, message_id: messageId } } : {},
|
|
373
|
+
counts: { messages: items.length }
|
|
374
|
+
})), "around")
|
|
375
|
+
} : {},
|
|
376
|
+
send: /* @__PURE__ */ __name((chatId, text, options) => timed("messages.send", {
|
|
377
|
+
ids: {
|
|
378
|
+
chat: chatId,
|
|
379
|
+
send: options.sendId,
|
|
380
|
+
...options.replyTo ? { reply: options.replyTo } : {},
|
|
381
|
+
...options.threadId ? { thread: options.threadId } : {}
|
|
382
|
+
}
|
|
383
|
+
}, () => messenger.send(chatId, text, options), (sent) => ({ ids: { chat: sent.message.chatId || chatId, message_id: sent.message.id } })), "send"),
|
|
384
|
+
...watch ? {
|
|
385
|
+
watch: /* @__PURE__ */ __name((onEvent, signal, onReady) => counted("messages.watch", onEvent, (counting) => watch.call(messenger, counting, signal, onReady), byEvent), "watch")
|
|
386
|
+
} : {},
|
|
387
|
+
...feed ? { feed: /* @__PURE__ */ __name((onBatch, signal) => timed("history.feed", {}, () => feed.call(messenger, onBatch, signal)), "feed") } : {},
|
|
388
|
+
...listen ? {
|
|
389
|
+
listen: /* @__PURE__ */ __name((onEvent, signal) => counted("messages.listen", onEvent, (counting) => listen.call(messenger, counting, signal), byEvent), "listen")
|
|
390
|
+
} : {},
|
|
391
|
+
...listenHistory ? {
|
|
392
|
+
listenHistory: /* @__PURE__ */ __name((onBatch, signal) => counted("history.listen", onBatch, (counting) => listenHistory.call(messenger, counting, signal), byPart), "listenHistory")
|
|
393
|
+
} : {},
|
|
394
|
+
logout: /* @__PURE__ */ __name(() => timed("session.logout", {}, () => messenger.logout()), "logout"),
|
|
395
|
+
close: /* @__PURE__ */ __name(() => messenger.close(), "close")
|
|
396
|
+
}, (name, call) => (...args) => timed(`adapter.${name}`, {}, () => call(...args)));
|
|
397
|
+
}, "observed");
|
|
398
|
+
var byEvent = /* @__PURE__ */ __name((event, counts) => {
|
|
399
|
+
counts[event.event] = (counts[event.event] ?? 0) + 1;
|
|
400
|
+
}, "byEvent");
|
|
401
|
+
var byPart = /* @__PURE__ */ __name((batch, counts) => {
|
|
402
|
+
counts.batches = (counts.batches ?? 0) + 1;
|
|
403
|
+
for (const [part, items] of Object.entries(batch))
|
|
404
|
+
if (Array.isArray(items) && items.length > 0)
|
|
405
|
+
counts[part] = (counts[part] ?? 0) + items.length;
|
|
406
|
+
}, "byPart");
|
|
407
|
+
|
|
408
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
|
|
409
|
+
var REKEY_PACING = { lockMs: 50, pauseMs: 25 };
|
|
410
|
+
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" }) => {
|
|
411
|
+
let warned = false;
|
|
412
|
+
let limitedNoted = false;
|
|
413
|
+
const limited = /* @__PURE__ */ __name(async (opened, batch) => {
|
|
414
|
+
if (!historyLimits || !batch.messages?.length)
|
|
415
|
+
return { batch, skipped: /* @__PURE__ */ new Map() };
|
|
416
|
+
const shapes = await opened.chats.historyShapes(account, [...new Set(batch.messages.map((one) => one.chatId))]);
|
|
417
|
+
return limitBatch(batch, (chatId) => shapes.get(chatId), (chatId) => shapes.get(chatId)?.included === true, historyLimits);
|
|
418
|
+
}, "limited");
|
|
419
|
+
const noteLimited = /* @__PURE__ */ __name((skipped) => {
|
|
420
|
+
if (skipped.size === 0)
|
|
421
|
+
return;
|
|
422
|
+
const counts = {
|
|
423
|
+
chats: skipped.size,
|
|
424
|
+
messages: 0,
|
|
425
|
+
group_too_large: 0,
|
|
426
|
+
older_than_window: 0
|
|
427
|
+
};
|
|
428
|
+
for (const skip of skipped.values()) {
|
|
429
|
+
counts.messages = (counts.messages ?? 0) + skip.messages;
|
|
430
|
+
counts[skip.reason] = (counts[skip.reason] ?? 0) + 1;
|
|
431
|
+
}
|
|
432
|
+
const warning = { event: "warning", code: "history_limited", operation: "history.save", counts };
|
|
433
|
+
events(warning);
|
|
434
|
+
if (limitedNoted)
|
|
435
|
+
return;
|
|
436
|
+
limitedNoted = true;
|
|
437
|
+
warn(`history limits left out ${counts.messages} pushed messages of ${skipped.size} chats (big groups, older than the window) \u2014 \`${command} store status\` lists them; \`${command} messages sync <chat> --full-history\` fetches one and keeps it in full`, warning);
|
|
438
|
+
}, "noteLimited");
|
|
439
|
+
let recorded = profile === void 0;
|
|
440
|
+
const notWritten = /* @__PURE__ */ __name((operation, error) => {
|
|
441
|
+
const warning = { event: "warning", code: "store_not_written", operation };
|
|
442
|
+
events(warning);
|
|
443
|
+
if (!warned)
|
|
444
|
+
warn(`not saved to the local store: ${error instanceof Error ? error.message : String(error)}`, warning);
|
|
445
|
+
warned = true;
|
|
446
|
+
}, "notWritten");
|
|
447
|
+
const attempt = /* @__PURE__ */ __name(async (operation, write) => {
|
|
448
|
+
try {
|
|
449
|
+
const opened = await store();
|
|
450
|
+
if (!opened)
|
|
451
|
+
return false;
|
|
452
|
+
await write(opened);
|
|
453
|
+
if (opened && !recorded && profile) {
|
|
454
|
+
recorded = true;
|
|
455
|
+
await Promise.resolve().then(() => opened.accounts.saveProfile(profile.app, profile.name, account)).catch(() => {
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
return true;
|
|
459
|
+
} catch (error) {
|
|
460
|
+
notWritten(operation, error);
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}, "attempt");
|
|
464
|
+
const save = /* @__PURE__ */ __name((operation, writing) => {
|
|
465
|
+
const saving = attempt(operation, writing);
|
|
466
|
+
pending?.add(saving);
|
|
467
|
+
return saving.finally(() => pending?.delete(saving));
|
|
468
|
+
}, "save");
|
|
469
|
+
const { chats, history, around, people } = messenger;
|
|
470
|
+
const followed = /* @__PURE__ */ __name(async (opened, scoped, held) => {
|
|
471
|
+
let answered;
|
|
472
|
+
try {
|
|
473
|
+
answered = await messenger.resolve(held.id);
|
|
474
|
+
} catch (error) {
|
|
475
|
+
if (codeOf(error) === "not_found")
|
|
476
|
+
return void 0;
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
479
|
+
if (answered.id === held.id)
|
|
480
|
+
return void 0;
|
|
481
|
+
await attempt("history.rekey", async (store2) => {
|
|
482
|
+
await store2.chats.rekeyChat(scoped, held.id, answered.id);
|
|
483
|
+
await rekeyed?.(held.id, answered.id);
|
|
484
|
+
});
|
|
485
|
+
return (await storedChat(opened, scoped, namesFromStore ?? {}, answered.id)).held ?? answered;
|
|
486
|
+
}, "followed");
|
|
487
|
+
const titles = /* @__PURE__ */ new Map();
|
|
488
|
+
const storedPeople = /* @__PURE__ */ __name(async () => {
|
|
489
|
+
try {
|
|
490
|
+
return await (await store())?.people.people(account.provider, { account: account.account });
|
|
491
|
+
} catch {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
}, "storedPeople");
|
|
495
|
+
let rekeysQueued = 0;
|
|
496
|
+
let rekeyRound = 0;
|
|
497
|
+
const rekeysOnly = /* @__PURE__ */ new Set();
|
|
498
|
+
const giveUpRekeys = /* @__PURE__ */ __name(() => {
|
|
499
|
+
rekeyRound += 1;
|
|
500
|
+
const count = rekeysQueued;
|
|
501
|
+
rekeysQueued = 0;
|
|
502
|
+
for (const saving of rekeysOnly)
|
|
503
|
+
pending?.delete(saving);
|
|
504
|
+
if (count === 0)
|
|
505
|
+
return;
|
|
506
|
+
const warning = {
|
|
507
|
+
event: "warning",
|
|
508
|
+
code: "rekeys_not_applied",
|
|
509
|
+
operation: "history.rekey",
|
|
510
|
+
counts: { rekeys: count }
|
|
511
|
+
};
|
|
512
|
+
events(warning);
|
|
513
|
+
warn(`${count} chat re-key${count === 1 ? "" : "s"} not applied yet; the next serve applies them`, warning);
|
|
514
|
+
}, "giveUpRekeys");
|
|
515
|
+
closing?.addEventListener("abort", giveUpRekeys, { once: true });
|
|
516
|
+
const saveRekeys = /* @__PURE__ */ __name(async (pairs, round) => {
|
|
517
|
+
let rest = pairs;
|
|
518
|
+
while (rest.length > 0 && round === rekeyRound) {
|
|
519
|
+
let pass;
|
|
520
|
+
try {
|
|
521
|
+
pass = await (await store())?.chats.rekeyChats(account, rest, rekeyPacing.lockMs);
|
|
522
|
+
} catch {
|
|
523
|
+
if (round === rekeyRound)
|
|
524
|
+
giveUpRekeys();
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (round !== rekeyRound)
|
|
528
|
+
return;
|
|
529
|
+
const taken = pass?.taken ?? rest.length;
|
|
530
|
+
rekeysQueued -= taken;
|
|
531
|
+
for (const { from, to } of pass?.applied ?? [])
|
|
532
|
+
await Promise.resolve().then(() => rekeyed?.(from, to)).catch((error) => notWritten("history.rekey", error));
|
|
533
|
+
for (const { error } of pass?.refused ?? [])
|
|
534
|
+
notWritten("history.rekey", error);
|
|
535
|
+
rest = rest.slice(taken);
|
|
536
|
+
if (rest.length > 0)
|
|
537
|
+
await new Promise((resolve) => setTimeout(resolve, rekeyPacing.pauseMs));
|
|
538
|
+
}
|
|
539
|
+
}, "saveRekeys");
|
|
540
|
+
const saveBatches = /* @__PURE__ */ __name((operation, onBatch) => {
|
|
541
|
+
let previous = Promise.resolve();
|
|
542
|
+
return (batch) => {
|
|
543
|
+
if (namesFromStore) {
|
|
544
|
+
for (const { from, to } of batch.rekeys ?? []) {
|
|
545
|
+
const title = titles.get(from);
|
|
546
|
+
titles.delete(from);
|
|
547
|
+
if (title && !titles.has(to))
|
|
548
|
+
titles.set(to, title);
|
|
549
|
+
}
|
|
550
|
+
for (const chat of batch.chats ?? [])
|
|
551
|
+
if (chat.title)
|
|
552
|
+
titles.set(chat.id, chat.title);
|
|
553
|
+
}
|
|
554
|
+
const rekeys = batch.rekeys ?? [];
|
|
555
|
+
const round = rekeyRound;
|
|
556
|
+
rekeysQueued += rekeys.length;
|
|
557
|
+
const saving = previous.then(async () => {
|
|
558
|
+
await saveRekeys(rekeys, round);
|
|
559
|
+
return attempt(operation, async (opened) => {
|
|
560
|
+
const { batch: kept, skipped } = await limited(opened, batch);
|
|
561
|
+
await fill(opened, account, kept);
|
|
562
|
+
if (skipped.size > 0)
|
|
563
|
+
await opened.chats.recordHistorySkips(account, skipped);
|
|
564
|
+
noteLimited(skipped);
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
previous = saving;
|
|
568
|
+
pending?.add(saving);
|
|
569
|
+
if (onlyRekeys(batch))
|
|
570
|
+
rekeysOnly.add(saving);
|
|
571
|
+
void saving.finally(() => {
|
|
572
|
+
pending?.delete(saving);
|
|
573
|
+
rekeysOnly.delete(saving);
|
|
574
|
+
});
|
|
575
|
+
void onBatch(batch, saving);
|
|
576
|
+
return saving;
|
|
577
|
+
};
|
|
578
|
+
}, "saveBatches");
|
|
579
|
+
const wrapped = throughWrapper(messenger, {
|
|
580
|
+
...messenger.forumState ? {
|
|
581
|
+
forumState: /* @__PURE__ */ __name(async (chatId) => {
|
|
582
|
+
const state = await capability(messenger, "forumState", "read forum settings")(chatId);
|
|
583
|
+
await save("forum.read", (opened) => opened.chats.saveChats(account, [state.chat]));
|
|
584
|
+
return state;
|
|
585
|
+
}, "forumState")
|
|
586
|
+
} : {},
|
|
587
|
+
...messenger.upgradeForum ? {
|
|
588
|
+
upgradeForum: /* @__PURE__ */ __name(async (chatId) => {
|
|
589
|
+
const state = await capability(messenger, "upgradeForum", "upgrade a group")(chatId);
|
|
590
|
+
await save("forum.upgrade", (opened) => opened.chats.saveChats(account, [state.chat]));
|
|
591
|
+
return state;
|
|
592
|
+
}, "upgradeForum")
|
|
593
|
+
} : {},
|
|
594
|
+
...messenger.enableForum ? {
|
|
595
|
+
enableForum: /* @__PURE__ */ __name(async (chatId) => {
|
|
596
|
+
const state = await capability(messenger, "enableForum", "enable forum topics")(chatId);
|
|
597
|
+
await save("forum.enable", (opened) => opened.chats.saveChats(account, [state.chat]));
|
|
598
|
+
return state;
|
|
599
|
+
}, "enableForum")
|
|
600
|
+
} : {},
|
|
601
|
+
self: /* @__PURE__ */ __name(() => messenger.self(), "self"),
|
|
602
|
+
resolve: /* @__PURE__ */ __name(async (reference) => {
|
|
603
|
+
if (isId(reference) && !namesFromStore)
|
|
604
|
+
return messenger.resolve(reference);
|
|
605
|
+
let accountId;
|
|
606
|
+
try {
|
|
607
|
+
accountId = account.account;
|
|
608
|
+
} catch {
|
|
609
|
+
return messenger.resolve(reference);
|
|
610
|
+
}
|
|
611
|
+
const scoped = { provider: account.provider, account: accountId };
|
|
612
|
+
const opened = await store().catch(() => void 0);
|
|
613
|
+
if (!opened)
|
|
614
|
+
return messenger.resolve(reference);
|
|
615
|
+
const { id, held } = namesFromStore ? await storedChat(opened, scoped, namesFromStore, reference) : {};
|
|
616
|
+
if (!isId(reference)) {
|
|
617
|
+
const people2 = await opened.people.people(scoped.provider, { account: scoped.account });
|
|
618
|
+
const wanted = foldName(reference.trim());
|
|
619
|
+
if (people2.all().some((person) => person.alias && foldName(person.alias).includes(wanted))) {
|
|
620
|
+
const person = pickPerson(reference, people2);
|
|
621
|
+
const chats2 = (await opened.chats.chatsWith(scoped, person.id)).filter((chat) => chat.kind === "dialog");
|
|
622
|
+
if (chats2.length !== 1 || !chats2[0])
|
|
623
|
+
throw new CliError("validation_error", "the alias has no unique stored direct chat; use a chat id");
|
|
624
|
+
let remote;
|
|
625
|
+
if (namesFromStore)
|
|
626
|
+
remote = held;
|
|
627
|
+
else
|
|
628
|
+
try {
|
|
629
|
+
remote = await messenger.resolve(reference);
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (!(error instanceof CliError) || error.code !== "not_found")
|
|
632
|
+
throw error;
|
|
633
|
+
}
|
|
634
|
+
if (remote && remote.id !== chats2[0].id)
|
|
635
|
+
throw new CliError("validation_error", "the local alias also names another messenger chat; use a chat id", {
|
|
636
|
+
candidates: [{ id: chats2[0].id }, { id: remote.id }]
|
|
637
|
+
});
|
|
638
|
+
return remote ?? (namesFromStore ? chats2[0] : messenger.resolve(chats2[0].id));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (held && held.id === reference.trim())
|
|
642
|
+
return await followed(opened, scoped, held) ?? held;
|
|
643
|
+
return held ?? messenger.resolve(id ?? reference);
|
|
644
|
+
}, "resolve"),
|
|
645
|
+
chat: /* @__PURE__ */ __name((reference) => messenger.chat(reference), "chat"),
|
|
646
|
+
...people && namesFromStore ? {
|
|
647
|
+
people: /* @__PURE__ */ __name(async (references) => {
|
|
648
|
+
const known = await storedPeople();
|
|
649
|
+
const found = references.map((reference) => known ? personIn(known, reference) : void 0);
|
|
650
|
+
const asked = references.filter((_, at) => found[at] === void 0);
|
|
651
|
+
const answered = asked.length === 0 ? [] : await people.call(messenger, asked);
|
|
652
|
+
const ids = [];
|
|
653
|
+
for (const id of found) {
|
|
654
|
+
const one = id ?? answered.shift();
|
|
655
|
+
if (one === void 0)
|
|
656
|
+
throw new CliError("not_found", "the messenger found fewer people than it was asked");
|
|
657
|
+
ids.push(one);
|
|
658
|
+
}
|
|
659
|
+
return ids;
|
|
660
|
+
}, "people")
|
|
661
|
+
} : {},
|
|
662
|
+
logout: /* @__PURE__ */ __name(() => messenger.logout(), "logout"),
|
|
663
|
+
close: /* @__PURE__ */ __name(() => messenger.close(), "close"),
|
|
664
|
+
me: /* @__PURE__ */ __name(async () => {
|
|
665
|
+
const me = await messenger.me();
|
|
666
|
+
await save("account.me", (opened) => opened.accounts.saveAccount(account, { name: me.name }));
|
|
667
|
+
return me;
|
|
668
|
+
}, "me"),
|
|
669
|
+
...chats ? {
|
|
670
|
+
chats: /* @__PURE__ */ __name(async (window) => {
|
|
671
|
+
const page = await chats.call(messenger, window);
|
|
672
|
+
const complete = window.offset === 0 && !page.hasMore && page.items.length > 0;
|
|
673
|
+
await save("chats.list", async (opened) => {
|
|
674
|
+
await opened.chats.saveChats(account, page.items);
|
|
675
|
+
const ids = page.items.map((chat) => chat.id);
|
|
676
|
+
if (complete)
|
|
677
|
+
await opened.chats.markChatsLeft(account, ids);
|
|
678
|
+
else
|
|
679
|
+
await opened.chats.rejoinChats(account, ids);
|
|
680
|
+
});
|
|
681
|
+
return page;
|
|
682
|
+
}, "chats")
|
|
683
|
+
} : {},
|
|
684
|
+
...history ? {
|
|
685
|
+
history: /* @__PURE__ */ __name(async (reference, options) => {
|
|
686
|
+
const seenAt = Date.now();
|
|
687
|
+
const page = await history.call(messenger, reference, options);
|
|
688
|
+
const chatId = page.items[0]?.chatId;
|
|
689
|
+
if (chatId !== void 0) {
|
|
690
|
+
await save("messages.list", (opened) => opened.messages.saveMessages(account, chatId, page.items, { via: "history", seenAt }));
|
|
691
|
+
}
|
|
692
|
+
return page;
|
|
693
|
+
}, "history")
|
|
694
|
+
} : {},
|
|
695
|
+
...around ? {
|
|
696
|
+
around: /* @__PURE__ */ __name(async (reference, messageId, window) => {
|
|
697
|
+
const seenAt = Date.now();
|
|
698
|
+
const items = await around.call(messenger, reference, messageId, window);
|
|
699
|
+
const chatId = items[0]?.chatId;
|
|
700
|
+
if (chatId !== void 0) {
|
|
701
|
+
const plain = items.map(({ anchor, ...message }) => message);
|
|
702
|
+
await save("messages.around", (opened) => opened.messages.saveMessages(account, chatId, plain, { via: "context", seenAt }));
|
|
703
|
+
}
|
|
704
|
+
return items;
|
|
705
|
+
}, "around")
|
|
706
|
+
} : {},
|
|
707
|
+
...messenger.watch ? {
|
|
708
|
+
watch: /* @__PURE__ */ __name(async (onEvent, signal, onReady) => {
|
|
709
|
+
if (namesFromStore)
|
|
710
|
+
await rememberTitles(store, account, titles);
|
|
711
|
+
return messenger.watch?.((event) => {
|
|
712
|
+
const seenAt = Date.now();
|
|
713
|
+
void save("messages.watch", (opened) => keep(opened, account, event, seenAt, deletedWithoutChat, countsUnread));
|
|
714
|
+
onEvent(namesFromStore ? titled(event, titles) : event);
|
|
715
|
+
}, signal, onReady) ?? Promise.resolve();
|
|
716
|
+
}, "watch")
|
|
717
|
+
} : {},
|
|
718
|
+
...messenger.listen ? {
|
|
719
|
+
listen: /* @__PURE__ */ __name((onEvent, signal) => messenger.listen?.((event) => {
|
|
720
|
+
void save("messages.listen", (opened) => keep(opened, account, event, Date.now(), deletedWithoutChat, countsUnread));
|
|
721
|
+
onEvent(event);
|
|
722
|
+
}, signal) ?? Promise.resolve(), "listen")
|
|
723
|
+
} : {},
|
|
724
|
+
...messenger.feed ? {
|
|
725
|
+
feed: /* @__PURE__ */ __name((onBatch, signal) => {
|
|
726
|
+
if (messenger.storedChats) {
|
|
727
|
+
const announced = announceStoredChats(messenger, store, account, events, warn, recipientIds);
|
|
728
|
+
announcing?.add(announced);
|
|
729
|
+
void announced.finally(() => announcing?.delete(announced));
|
|
730
|
+
}
|
|
731
|
+
return messenger.feed?.(saveBatches("history.feed", onBatch), signal) ?? Promise.resolve();
|
|
732
|
+
}, "feed")
|
|
733
|
+
} : {},
|
|
734
|
+
...messenger.listenHistory ? {
|
|
735
|
+
listenHistory: /* @__PURE__ */ __name((onBatch, signal) => messenger.listenHistory?.(saveBatches("history.listen", onBatch), signal) ?? Promise.resolve(), "listenHistory")
|
|
736
|
+
} : {},
|
|
737
|
+
...messenger.edit ? {
|
|
738
|
+
edit: /* @__PURE__ */ __name(async (chatId, messageId, text, options) => {
|
|
739
|
+
const seenAt = Date.now();
|
|
740
|
+
const edited = await capability(messenger, "edit", "edit")(chatId, messageId, text, options);
|
|
741
|
+
await save("messages.edit", async (opened) => {
|
|
742
|
+
const held = await opened.messages.message(account, messageId, { chatId }) !== void 0;
|
|
743
|
+
await saveSent(opened, account, chatId, edited, { via: "update", seenAt }, held ? chatId : void 0);
|
|
744
|
+
});
|
|
745
|
+
return edited;
|
|
746
|
+
}, "edit")
|
|
747
|
+
} : {},
|
|
748
|
+
...messenger.createPoll ? {
|
|
749
|
+
// A messenger that never echoes a device's own message back would otherwise never hold the poll.
|
|
750
|
+
createPoll: /* @__PURE__ */ __name(async (chatId, poll, options) => {
|
|
751
|
+
const sent = await capability(messenger, "createPoll", "create a poll")(chatId, poll, options);
|
|
752
|
+
await save("polls.create", (opened) => saveSent(opened, account, chatId, sent.message, { via: "send" }));
|
|
753
|
+
return sent;
|
|
754
|
+
}, "createPoll")
|
|
755
|
+
} : {},
|
|
756
|
+
...messenger.vote ? {
|
|
757
|
+
vote: /* @__PURE__ */ __name(async (chatId, messageId, answerIds) => {
|
|
758
|
+
const poll = await capability(messenger, "vote", "vote in a poll")(chatId, messageId, answerIds);
|
|
759
|
+
const votedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
760
|
+
await save("polls.vote", (opened) => opened.messages.saveVote(account, chatId, messageId, {
|
|
761
|
+
person: { id: account.account, name: null, username: null },
|
|
762
|
+
answers: answerIds,
|
|
763
|
+
votedAt
|
|
764
|
+
}));
|
|
765
|
+
return poll;
|
|
766
|
+
}, "vote")
|
|
767
|
+
} : {},
|
|
768
|
+
...messenger.star ? {
|
|
769
|
+
// The messenger may not echo the owner's own star back, and `messages list starred:true` reads the store.
|
|
770
|
+
star: /* @__PURE__ */ __name(async (chatId, messageId, starred) => {
|
|
771
|
+
await capability(messenger, "star", "star a message")(chatId, messageId, starred);
|
|
772
|
+
await save("messages.star", (opened) => opened.messages.saveStar(account, chatId, messageId, starred));
|
|
773
|
+
}, "star")
|
|
774
|
+
} : {},
|
|
775
|
+
...messenger.forward ? {
|
|
776
|
+
forward: /* @__PURE__ */ __name(async (fromChatId, messageId, toChatId, options) => {
|
|
777
|
+
const copy = await capability(messenger, "forward", "forward")(fromChatId, messageId, toChatId, options);
|
|
778
|
+
await save("messages.forward", (opened) => saveSent(opened, account, toChatId, copy, { via: "send" }));
|
|
779
|
+
return copy;
|
|
780
|
+
}, "forward")
|
|
781
|
+
} : {},
|
|
782
|
+
// Without this, a message deleted here would still be found by `search messages` and read `--offline`.
|
|
783
|
+
...messenger.delete ? {
|
|
784
|
+
delete: /* @__PURE__ */ __name(async (chatId, messageIds, options) => {
|
|
785
|
+
await capability(messenger, "delete", "delete")(chatId, messageIds, options);
|
|
786
|
+
await save("messages.delete", (opened) => opened.messages.markDeleted(account, messageIds, { chatId }));
|
|
787
|
+
}, "delete")
|
|
788
|
+
} : {},
|
|
789
|
+
send: /* @__PURE__ */ __name(async (chatId, text, options) => {
|
|
790
|
+
const sent = await messenger.send(chatId, text, options);
|
|
791
|
+
if (options.at === void 0) {
|
|
792
|
+
await save("messages.send", async (opened) => {
|
|
793
|
+
for (const message of sent.messages ?? [sent.message])
|
|
794
|
+
await saveSent(opened, account, chatId, message, { via: "send" });
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
return sent;
|
|
798
|
+
}, "send")
|
|
799
|
+
});
|
|
800
|
+
const chatOf2 = /* @__PURE__ */ __name(async (typed) => {
|
|
801
|
+
const named = chatReferenceOf(typed, account.provider);
|
|
802
|
+
if (!named)
|
|
803
|
+
return typed;
|
|
804
|
+
let known;
|
|
805
|
+
try {
|
|
806
|
+
known = account.account;
|
|
807
|
+
} catch {
|
|
808
|
+
}
|
|
809
|
+
await ensureAccount(named, { account: known, ...profile ? { profile: profile.name } : {} }, async (other) => {
|
|
810
|
+
const opened = await store();
|
|
811
|
+
return opened && profilesOnAccount(opened, profile?.app, account.provider)(other);
|
|
812
|
+
});
|
|
813
|
+
return named.chat;
|
|
814
|
+
}, "chatOf");
|
|
815
|
+
return withChatReferences(wrapped, chatOf2);
|
|
816
|
+
}, "stored");
|
|
817
|
+
var TYPED_CHAT = [
|
|
818
|
+
"resolve",
|
|
819
|
+
"chat",
|
|
820
|
+
"history",
|
|
821
|
+
"around",
|
|
822
|
+
"historyAfter",
|
|
823
|
+
"historyBefore",
|
|
824
|
+
"historyFrom",
|
|
825
|
+
"topics",
|
|
826
|
+
"topic",
|
|
827
|
+
"topicHistory",
|
|
828
|
+
"download",
|
|
829
|
+
"transcribe",
|
|
830
|
+
"scheduled",
|
|
831
|
+
"admins",
|
|
832
|
+
"chatEvents",
|
|
833
|
+
"leave",
|
|
834
|
+
"group",
|
|
835
|
+
"officialChatStats"
|
|
836
|
+
];
|
|
837
|
+
var withChatReferences = /* @__PURE__ */ __name((adapter, chatOf2) => {
|
|
838
|
+
const methods = adapter;
|
|
839
|
+
const own = Object.fromEntries(TYPED_CHAT.flatMap((name) => {
|
|
840
|
+
const method = methods[name];
|
|
841
|
+
if (typeof method !== "function")
|
|
842
|
+
return [];
|
|
843
|
+
const call = /* @__PURE__ */ __name(async (typed, ...rest) => method.call(adapter, await chatOf2(typed), ...rest), "call");
|
|
844
|
+
return [[name, call]];
|
|
845
|
+
}));
|
|
846
|
+
return throughWrapper(adapter, own);
|
|
847
|
+
}, "withChatReferences");
|
|
848
|
+
var saveSent = /* @__PURE__ */ __name((opened, account, typed, message, options, into = message.chatId || typed) => opened.messages.saveMessages(account, into, [message], { ...options, typedChatId: typed }), "saveSent");
|
|
849
|
+
var storedChat = /* @__PURE__ */ __name(async (store, account, traits, reference) => {
|
|
850
|
+
const bound = store.forAccount(account);
|
|
851
|
+
const id = await chatIdIn(traits, reference, bound).catch((error) => {
|
|
852
|
+
if (codeOf(error) === "not_found")
|
|
853
|
+
return void 0;
|
|
854
|
+
throw error;
|
|
855
|
+
});
|
|
856
|
+
if (id === void 0)
|
|
857
|
+
return {};
|
|
858
|
+
const held = (await bound.chats.chats({})).items.find((chat) => chat.id === id);
|
|
859
|
+
return held ? { id, held } : { id };
|
|
860
|
+
}, "storedChat");
|
|
861
|
+
var personIn = /* @__PURE__ */ __name((people, reference) => {
|
|
862
|
+
try {
|
|
863
|
+
return pickPerson(reference, people).id;
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (codeOf(error) === "not_found")
|
|
866
|
+
return void 0;
|
|
867
|
+
throw error;
|
|
868
|
+
}
|
|
869
|
+
}, "personIn");
|
|
870
|
+
var announceStoredChats = /* @__PURE__ */ __name(async (messenger, store, account, events, warn, recipientIds) => {
|
|
871
|
+
let listed = [];
|
|
872
|
+
try {
|
|
873
|
+
listed = recipientIds?.() ?? [];
|
|
874
|
+
} catch (error) {
|
|
875
|
+
warn(`the messenger was not told the recipient list: ${error instanceof Error ? error.message : String(error)}`, {
|
|
876
|
+
event: "warning",
|
|
877
|
+
code: "recipients_not_read",
|
|
878
|
+
operation: "history.stored_chats"
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
try {
|
|
882
|
+
const opened = await store();
|
|
883
|
+
const held = opened ? (await opened.forAccount(account).chats.chats({})).items.map((chat) => chat.id) : [];
|
|
884
|
+
const recipients = [...new Set(listed)].filter((id) => !held.includes(id));
|
|
885
|
+
if (recipients.length > 0)
|
|
886
|
+
await messenger.storedChats?.(held, recipients);
|
|
887
|
+
else if (opened)
|
|
888
|
+
await messenger.storedChats?.(held);
|
|
889
|
+
} catch (error) {
|
|
890
|
+
const warning = { event: "warning", code: "stored_chats_failed", operation: "history.stored_chats" };
|
|
891
|
+
events(warning);
|
|
892
|
+
warn(`the messenger was not told the stored chats: ${error instanceof Error ? error.message : String(error)}`, warning);
|
|
893
|
+
}
|
|
894
|
+
}, "announceStoredChats");
|
|
895
|
+
var rememberTitles = /* @__PURE__ */ __name(async (store, account, titles) => {
|
|
896
|
+
try {
|
|
897
|
+
const opened = await store();
|
|
898
|
+
for (const chat of (await opened?.forAccount(account).chats.chats({}))?.items ?? [])
|
|
899
|
+
if (chat.title && !titles.has(chat.id))
|
|
900
|
+
titles.set(chat.id, chat.title);
|
|
901
|
+
} catch {
|
|
902
|
+
}
|
|
903
|
+
}, "rememberTitles");
|
|
904
|
+
var titled = /* @__PURE__ */ __name((event, titles) => {
|
|
905
|
+
if (event.event === "message" || event.event === "edit") {
|
|
906
|
+
const title2 = event.message.chatTitle ?? titles.get(event.message.chatId);
|
|
907
|
+
return title2 ? { ...event, message: { ...event.message, chatTitle: title2 } } : event;
|
|
908
|
+
}
|
|
909
|
+
if (event.event === "chat_event" && event.change.event === "title" && event.change.title)
|
|
910
|
+
titles.set(event.chatId, event.change.title);
|
|
911
|
+
if (event.chatTitle !== null || event.chatId === null)
|
|
912
|
+
return event;
|
|
913
|
+
const title = titles.get(event.chatId);
|
|
914
|
+
return title ? { ...event, chatTitle: title } : event;
|
|
915
|
+
}, "titled");
|
|
916
|
+
var onlyRekeys = /* @__PURE__ */ __name((batch) => Object.entries(batch).every(([part, items]) => part === "rekeys" === (items?.length ?? 0) > 0), "onlyRekeys");
|
|
917
|
+
var fill = /* @__PURE__ */ __name(async (store, account, batch) => {
|
|
918
|
+
if (batch.chats?.length)
|
|
919
|
+
await store.chats.saveChats(account, batch.chats);
|
|
920
|
+
if (batch.people?.length)
|
|
921
|
+
await store.people.savePeople(account, batch.people);
|
|
922
|
+
const byChat = /* @__PURE__ */ new Map();
|
|
923
|
+
const of = /* @__PURE__ */ __name((chatId) => {
|
|
924
|
+
const held = byChat.get(chatId) ?? { messages: [], votes: [], reactions: [], stars: [] };
|
|
925
|
+
byChat.set(chatId, held);
|
|
926
|
+
return held;
|
|
927
|
+
}, "of");
|
|
928
|
+
for (const message of batch.messages ?? [])
|
|
929
|
+
of(message.chatId).messages.push(message);
|
|
930
|
+
for (const { chatId, messageId, vote } of batch.votes ?? [])
|
|
931
|
+
of(chatId).votes.push({ messageId, vote });
|
|
932
|
+
for (const { chatId, messageId, reaction } of batch.reactions ?? [])
|
|
933
|
+
of(chatId).reactions.push({ messageId, reaction });
|
|
934
|
+
for (const { chatId, messageId, starred } of batch.stars ?? [])
|
|
935
|
+
of(chatId).stars.push({ messageId, starred });
|
|
936
|
+
for (const [chatId, { messages, votes, reactions, stars }] of byChat)
|
|
937
|
+
await store.messages.saveMessages(account, chatId, messages, { via: "history", votes, reactions, stars });
|
|
938
|
+
const deletions = /* @__PURE__ */ new Map();
|
|
939
|
+
for (const { chatId, messageId } of batch.deletions ?? [])
|
|
940
|
+
deletions.set(chatId, [...deletions.get(chatId) ?? [], messageId]);
|
|
941
|
+
for (const [chatId, ids] of deletions)
|
|
942
|
+
await store.messages.markDeleted(account, ids, { chatId });
|
|
943
|
+
const changes = /* @__PURE__ */ new Map();
|
|
944
|
+
for (const { chatId, change } of batch.events ?? [])
|
|
945
|
+
changes.set(chatId, [...changes.get(chatId) ?? [], change]);
|
|
946
|
+
for (const [chatId, events] of changes)
|
|
947
|
+
await store.roster.saveChatEvents(account, chatId, events);
|
|
948
|
+
}, "fill");
|
|
949
|
+
var keep = /* @__PURE__ */ __name(async (store, account, event, seenAt, among, countsUnread) => {
|
|
950
|
+
switch (event.event) {
|
|
951
|
+
case "message":
|
|
952
|
+
case "edit": {
|
|
953
|
+
const { chatTitle, ...message } = event.message;
|
|
954
|
+
await store.messages.saveMessages(account, message.chatId, [message], {
|
|
955
|
+
via: "update",
|
|
956
|
+
seenAt,
|
|
957
|
+
...countsUnread && event.event === "message" ? { countUnread: true } : {}
|
|
958
|
+
});
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
case "delete":
|
|
962
|
+
await store.messages.markDeleted(account, [event.messageId], event.chatId === null ? among ? { among } : {} : { chatId: event.chatId });
|
|
963
|
+
return;
|
|
964
|
+
case "vote":
|
|
965
|
+
await store.messages.saveVote(account, event.chatId, event.messageId, event.vote);
|
|
966
|
+
return;
|
|
967
|
+
case "person_reaction":
|
|
968
|
+
await store.messages.saveReaction(account, event.chatId, event.messageId, event.reaction);
|
|
969
|
+
return;
|
|
970
|
+
case "star":
|
|
971
|
+
await store.messages.saveStar(account, event.chatId, event.messageId, event.starred);
|
|
972
|
+
return;
|
|
973
|
+
case "delivery":
|
|
974
|
+
await store.messages.saveDelivery(account, event.chatId, event.messageId, event.delivery);
|
|
975
|
+
return;
|
|
976
|
+
case "chat_event":
|
|
977
|
+
await store.roster.saveChatEvents(account, event.chatId, [event.change]);
|
|
978
|
+
return;
|
|
979
|
+
case "reaction":
|
|
980
|
+
await store.messages.saveReactions(account, event.chatId, event.messageId, event.reactions, event.counterObservation ? { observation: event.counterObservation } : {});
|
|
981
|
+
}
|
|
982
|
+
}, "keep");
|
|
983
|
+
|
|
984
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
|
|
985
|
+
var lazyStore = /* @__PURE__ */ __name((env, command, version) => {
|
|
986
|
+
let opened;
|
|
987
|
+
return {
|
|
988
|
+
open: /* @__PURE__ */ __name(() => {
|
|
989
|
+
opened ??= openStore({ env, command, ...version ? { version } : {} });
|
|
990
|
+
return opened;
|
|
991
|
+
}, "open"),
|
|
992
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
993
|
+
if (opened)
|
|
994
|
+
await (await opened.catch(() => void 0))?.close();
|
|
995
|
+
}, "close")
|
|
996
|
+
};
|
|
997
|
+
}, "lazyStore");
|
|
998
|
+
var storedMessages = /* @__PURE__ */ __name((provider, store, account) => {
|
|
999
|
+
const key = /* @__PURE__ */ __name(() => {
|
|
1000
|
+
const self = account();
|
|
1001
|
+
return self ? { provider, account: self } : void 0;
|
|
1002
|
+
}, "key");
|
|
1003
|
+
return {
|
|
1004
|
+
message: /* @__PURE__ */ __name(async (chatId, messageId) => {
|
|
1005
|
+
const at = key();
|
|
1006
|
+
return at && (await store()).messages.message(at, messageId, { chatId });
|
|
1007
|
+
}, "message"),
|
|
1008
|
+
threadMessages: /* @__PURE__ */ __name(async (chatId, threadId, window) => {
|
|
1009
|
+
const owner = key();
|
|
1010
|
+
return owner ? (await store()).messages.messages(owner, chatId, { ...window, threadId }) : { items: [], hasMore: false };
|
|
1011
|
+
}, "threadMessages"),
|
|
1012
|
+
newestIncoming: /* @__PURE__ */ __name(async (chatId, before) => {
|
|
1013
|
+
const at = key();
|
|
1014
|
+
if (!at)
|
|
1015
|
+
return void 0;
|
|
1016
|
+
const page = await (await store()).messages.messages(at, chatId, {
|
|
1017
|
+
limit: 1,
|
|
1018
|
+
outgoing: false,
|
|
1019
|
+
...before === void 0 ? {} : { before }
|
|
1020
|
+
});
|
|
1021
|
+
return page.items.at(-1);
|
|
1022
|
+
}, "newestIncoming"),
|
|
1023
|
+
anchor: /* @__PURE__ */ __name(async (chatId, at) => {
|
|
1024
|
+
const owner = key();
|
|
1025
|
+
if (!owner)
|
|
1026
|
+
return void 0;
|
|
1027
|
+
const window = at === void 0 ? { at: (/* @__PURE__ */ new Date(0)).toISOString(), before: 0, after: 1 } : { at, before: 1, after: 0 };
|
|
1028
|
+
return (await (await store()).messages.messagesWindow(owner, chatId, window))[0];
|
|
1029
|
+
}, "anchor"),
|
|
1030
|
+
wroteTo: /* @__PURE__ */ __name(async (personId) => {
|
|
1031
|
+
const owner = key();
|
|
1032
|
+
if (!owner)
|
|
1033
|
+
return false;
|
|
1034
|
+
const opened = await store();
|
|
1035
|
+
const dialogs = /* @__PURE__ */ new Set([
|
|
1036
|
+
personId,
|
|
1037
|
+
...(await opened.chats.chatsWith(owner, personId)).filter((chat) => chat.kind === "dialog").map((chat) => chat.id)
|
|
1038
|
+
]);
|
|
1039
|
+
for (const chatId of dialogs)
|
|
1040
|
+
if ((await opened.messages.messages(owner, chatId, { limit: 1, outgoing: true })).items.length > 0)
|
|
1041
|
+
return true;
|
|
1042
|
+
return false;
|
|
1043
|
+
}, "wroteTo"),
|
|
1044
|
+
pollVotes: /* @__PURE__ */ __name(async (chatId, messageId) => {
|
|
1045
|
+
const owner = key();
|
|
1046
|
+
return owner ? (await store()).messages.pollVotes(owner, chatId, messageId) : [];
|
|
1047
|
+
}, "pollVotes"),
|
|
1048
|
+
reactors: /* @__PURE__ */ __name(async (chatId, messageId) => {
|
|
1049
|
+
const owner = key();
|
|
1050
|
+
return owner ? (await store()).messages.reactors(owner, chatId, messageId) : [];
|
|
1051
|
+
}, "reactors")
|
|
1052
|
+
};
|
|
1053
|
+
}, "storedMessages");
|
|
1054
|
+
var connectFor = /* @__PURE__ */ __name((command, messenger, base, options = {}) => {
|
|
1055
|
+
const { relayed } = environmentOf(command);
|
|
1056
|
+
if (!relayed)
|
|
1057
|
+
return messenger.connect(command, base, options);
|
|
1058
|
+
if (base.settings.profile !== relayed.profile) {
|
|
1059
|
+
return Promise.reject(new CliError("permission_error", `this serve holds profile ${relayed.profile}; it does not run commands for profile ${base.settings.profile}`, { sent: false }));
|
|
1060
|
+
}
|
|
1061
|
+
return Promise.resolve(relayed.connection());
|
|
1062
|
+
}, "connectFor");
|
|
1063
|
+
var SAVES_WAIT_MS = 5e3;
|
|
1064
|
+
var REKEY_LOCK_WAIT_MS = 250;
|
|
1065
|
+
var settled = /* @__PURE__ */ __name(async (pending, ms) => {
|
|
1066
|
+
if (pending.size === 0)
|
|
1067
|
+
return true;
|
|
1068
|
+
let timer;
|
|
1069
|
+
const late = new Promise((resolve) => {
|
|
1070
|
+
timer = setTimeout(() => resolve(false), ms);
|
|
1071
|
+
});
|
|
1072
|
+
try {
|
|
1073
|
+
return await Promise.race([Promise.all([...pending]).then(() => true), late]);
|
|
1074
|
+
} finally {
|
|
1075
|
+
clearTimeout(timer);
|
|
1076
|
+
}
|
|
1077
|
+
}, "settled");
|
|
1078
|
+
var listened = /* @__PURE__ */ __name(({ run, operation, what: what2 }, events, warn, waitMs) => {
|
|
1079
|
+
const abort = new AbortController();
|
|
1080
|
+
let closing = false;
|
|
1081
|
+
const ended = Promise.resolve().then(() => run(abort.signal)).catch((error) => {
|
|
1082
|
+
if (closing)
|
|
1083
|
+
return;
|
|
1084
|
+
const warning = { event: "warning", code: "listen_failed", operation };
|
|
1085
|
+
events(warning);
|
|
1086
|
+
warn(`${what2} arriving during this command are not saved: ${error instanceof Error ? error.message : String(error)}`, warning);
|
|
1087
|
+
});
|
|
1088
|
+
return {
|
|
1089
|
+
operation,
|
|
1090
|
+
what: what2,
|
|
1091
|
+
closing: /* @__PURE__ */ __name(() => {
|
|
1092
|
+
closing = true;
|
|
1093
|
+
}, "closing"),
|
|
1094
|
+
stop: /* @__PURE__ */ __name(() => {
|
|
1095
|
+
abort.abort();
|
|
1096
|
+
return settled(/* @__PURE__ */ new Set([ended]), waitMs);
|
|
1097
|
+
}, "stop")
|
|
1098
|
+
};
|
|
1099
|
+
}, "listened");
|
|
1100
|
+
var passivesOf = /* @__PURE__ */ __name((adapter) => [
|
|
1101
|
+
...adapter.listen ? [
|
|
1102
|
+
{
|
|
1103
|
+
run: /* @__PURE__ */ __name((signal) => adapter.listen?.(() => {
|
|
1104
|
+
}, signal), "run"),
|
|
1105
|
+
operation: "messages.listen",
|
|
1106
|
+
what: "messages"
|
|
1107
|
+
}
|
|
1108
|
+
] : [],
|
|
1109
|
+
...adapter.listenHistory ? [
|
|
1110
|
+
{
|
|
1111
|
+
run: /* @__PURE__ */ __name((signal) => adapter.listenHistory?.(() => {
|
|
1112
|
+
}, signal), "run"),
|
|
1113
|
+
operation: "history.listen",
|
|
1114
|
+
what: "history batches"
|
|
1115
|
+
}
|
|
1116
|
+
] : []
|
|
1117
|
+
], "passivesOf");
|
|
1118
|
+
var rekeyRecipients = /* @__PURE__ */ __name(async (app, profile, env, warn, from, to) => {
|
|
1119
|
+
try {
|
|
1120
|
+
await new RecipientList(recipientsPathFor(app, profile, env), app.command, REKEY_LOCK_WAIT_MS).rekey(from, to);
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
warn(`the recipient list still names ${from}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
1123
|
+
event: "warning",
|
|
1124
|
+
code: "recipients_not_rekeyed",
|
|
1125
|
+
operation: "recipients.rekey"
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
}, "rekeyRecipients");
|
|
1129
|
+
var waitsOf = /* @__PURE__ */ __name((command) => {
|
|
1130
|
+
const { closeWaitMs, rekeyPacing } = environmentOf(command);
|
|
1131
|
+
return { ...closeWaitMs === void 0 ? {} : { closeWaitMs }, ...rekeyPacing ? { rekeyPacing } : {} };
|
|
1132
|
+
}, "waitsOf");
|
|
1133
|
+
var connected = /* @__PURE__ */ __name((connection, { app, provider, name, deletedWithoutChat, pace, history, savedChatId, unreadCounts }, { settings, env, renderer }, events, store = lazyStore(env, app.command, app.version), { listen: watching = false, closeWaitMs = SAVES_WAIT_MS, rekeyPacing } = {}) => {
|
|
1134
|
+
const self = connection.self();
|
|
1135
|
+
if (self !== null)
|
|
1136
|
+
rememberAccount(app, settings.profile, self, env);
|
|
1137
|
+
const memory = new FloodMemory(floodPathFor(app, settings.profile, env));
|
|
1138
|
+
const rate = {
|
|
1139
|
+
...DEFAULT_PACE,
|
|
1140
|
+
...pace,
|
|
1141
|
+
...settings.requestsPerMinute === void 0 ? {} : { perMinute: settings.requestsPerMinute }
|
|
1142
|
+
};
|
|
1143
|
+
const pacer = new Pacer(pacePathFor(app, settings.profile, env), rate);
|
|
1144
|
+
const adapter = observed(flooded(connection, memory, { name: name ?? app.command, warn: renderer.warn, pacer }), events);
|
|
1145
|
+
const pending = /* @__PURE__ */ new Set();
|
|
1146
|
+
const announcing = /* @__PURE__ */ new Set();
|
|
1147
|
+
const closing = new AbortController();
|
|
1148
|
+
const saving = self === null ? adapter : stored(adapter, {
|
|
1149
|
+
account: { provider, account: self },
|
|
1150
|
+
profile: { app: app.command, name: settings.profile },
|
|
1151
|
+
store: store.open,
|
|
1152
|
+
warn: renderer.warn,
|
|
1153
|
+
events,
|
|
1154
|
+
pending,
|
|
1155
|
+
announcing,
|
|
1156
|
+
closing: closing.signal,
|
|
1157
|
+
...deletedWithoutChat ? { deletedWithoutChat } : {},
|
|
1158
|
+
...rekeyPacing ? { rekeyPacing } : {},
|
|
1159
|
+
rekeyed: /* @__PURE__ */ __name((from, to) => rekeyRecipients(app, settings.profile, env, renderer.warn, from, to), "rekeyed"),
|
|
1160
|
+
recipientIds: /* @__PURE__ */ __name(() => (new RecipientList(recipientsPathFor(app, settings.profile, env), app.command).read() ?? []).flatMap((recipient) => [recipient.id, ...recipient.partnerId ? [recipient.partnerId] : []]), "recipientIds"),
|
|
1161
|
+
...history === "store" ? { namesFromStore: savedChatId ? { savedChatId } : {} } : {},
|
|
1162
|
+
...unreadCounts === "store" ? { countsUnread: true } : {},
|
|
1163
|
+
...history === "store" && settings.historyLimits ? { historyLimits: settings.historyLimits, command: `${app.command} ${settings.profile}` } : {}
|
|
1164
|
+
});
|
|
1165
|
+
const passives = history === "store" && self !== null && !watching ? passivesOf(saving).map((passive) => listened(passive, events, renderer.warn, closeWaitMs)) : [];
|
|
1166
|
+
return {
|
|
1167
|
+
adapter: saving,
|
|
1168
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
1169
|
+
for (const passive of passives)
|
|
1170
|
+
passive.closing();
|
|
1171
|
+
try {
|
|
1172
|
+
await connection.close();
|
|
1173
|
+
} finally {
|
|
1174
|
+
try {
|
|
1175
|
+
const ended = await Promise.all(passives.map((passive) => passive.stop()));
|
|
1176
|
+
const warn = renderer.warn;
|
|
1177
|
+
const warned = /* @__PURE__ */ __name((warning, text) => {
|
|
1178
|
+
events(warning);
|
|
1179
|
+
warn(text, warning);
|
|
1180
|
+
}, "warned");
|
|
1181
|
+
passives.forEach(({ operation, what: what2 }, at) => {
|
|
1182
|
+
if (ended[at])
|
|
1183
|
+
return;
|
|
1184
|
+
warned({ event: "warning", code: "store_not_written", operation }, `not saved to the local store: the messenger was still handing on ${what2} at exit`);
|
|
1185
|
+
});
|
|
1186
|
+
await settled(/* @__PURE__ */ new Set([...pending, ...announcing]), closeWaitMs);
|
|
1187
|
+
closing.abort();
|
|
1188
|
+
if (pending.size > 0)
|
|
1189
|
+
warned({ event: "warning", code: "store_not_written", operation: "close" }, "not saved to the local store: the last messages were still being written at exit");
|
|
1190
|
+
if (announcing.size > 0)
|
|
1191
|
+
warned({ event: "warning", code: "stored_chats_failed", operation: "close" }, "the messenger's stored-chats hook did not finish and was abandoned at exit; nothing is lost");
|
|
1192
|
+
} finally {
|
|
1193
|
+
await store.close();
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}, "close")
|
|
1197
|
+
};
|
|
1198
|
+
}, "connected");
|
|
1199
|
+
var connectedFor = /* @__PURE__ */ __name(async (command, messenger, base, options) => {
|
|
1200
|
+
const store = lazyStore(base.env, messenger.app.command, messenger.app.version);
|
|
1201
|
+
let connection;
|
|
1202
|
+
try {
|
|
1203
|
+
connection = await connectFor(command, messenger, base, {
|
|
1204
|
+
...options,
|
|
1205
|
+
stored: storedMessages(messenger.provider, store.open, () => connection?.self())
|
|
1206
|
+
});
|
|
1207
|
+
} catch (error) {
|
|
1208
|
+
await store.close();
|
|
1209
|
+
throw error;
|
|
1210
|
+
}
|
|
1211
|
+
return {
|
|
1212
|
+
connection,
|
|
1213
|
+
...connected(connection, messenger, base, options.events, store, {
|
|
1214
|
+
...waitsOf(command),
|
|
1215
|
+
...options.listen ? { listen: true } : {}
|
|
1216
|
+
})
|
|
1217
|
+
};
|
|
1218
|
+
}, "connectedFor");
|
|
1219
|
+
var markedProfile = /* @__PURE__ */ __name((messenger, profile, env) => messenger.profileState?.(profile, env) === "signed-out" ? `${profile} (not signed in)` : profile, "markedProfile");
|
|
1220
|
+
var unrecorded = /* @__PURE__ */ __name((command, messenger, profile, { offline, profilesHere }, env) => {
|
|
1221
|
+
if (!profilesHere.includes(profile)) {
|
|
1222
|
+
return new CliError("not_found", `no profile named "${profile}" \u2014 profiles here: ${profilesHere.length > 0 ? profilesHere.map((one) => markedProfile(messenger, one, env)).join(", ") : "none"}`, { profiles: profilesHere });
|
|
1223
|
+
}
|
|
1224
|
+
const words = `${messenger.app.command} ${asFirstWord(profile)}`;
|
|
1225
|
+
const setup = rootOf(command).commands.some((one) => one.name() === "setup") ? `\`${words}setup\`` : void 0;
|
|
1226
|
+
if (messenger.history === "store")
|
|
1227
|
+
return new CliError("not_found", `nothing recorded for profile "${profile}" yet \u2014 ${setup ? `link it with ${setup}, then ` : ""}run \`${words}serve\` or \`${words}watch\` once to fill the local store`);
|
|
1228
|
+
const ways = [
|
|
1229
|
+
...setup ? [`log in with ${setup}`] : [],
|
|
1230
|
+
...offline ? ["run the command once without --offline"] : []
|
|
1231
|
+
];
|
|
1232
|
+
return new CliError("not_found", `nothing recorded for profile "${profile}" yet \u2014 ${ways.length > 0 ? ways.join(", or ") : "log in to it first"}`);
|
|
1233
|
+
}, "unrecorded");
|
|
1234
|
+
var warnUnserved = /* @__PURE__ */ __name(async (messenger, profile, { env, renderer }, store) => {
|
|
1235
|
+
if (servingProfiles(messenger.app, env).includes(profile))
|
|
1236
|
+
return;
|
|
1237
|
+
const account = recalledAccount(messenger.app, messenger.provider, profile, env);
|
|
1238
|
+
if (!account)
|
|
1239
|
+
return;
|
|
1240
|
+
const newest = (await store.chats.chatStats(account)).map((one) => one.newestAt).reduce((latest, at) => at !== null && (latest === null || at > latest) ? at : latest, null);
|
|
1241
|
+
renderer.warn(`no \`${messenger.app.command} ${profile} serve\` keeps profile "${profile}" up to date \u2014 ` + (newest === null ? "the local store holds no messages yet" : `the newest stored message is from ${newest}`));
|
|
1242
|
+
}, "warnUnserved");
|
|
1243
|
+
var pathOf2 = /* @__PURE__ */ __name((command) => {
|
|
1244
|
+
const words = [];
|
|
1245
|
+
for (let at = command; at?.parent; at = at.parent)
|
|
1246
|
+
words.unshift(at.name());
|
|
1247
|
+
return words;
|
|
1248
|
+
}, "pathOf");
|
|
1249
|
+
var refuseDenied = /* @__PURE__ */ __name((command, settings) => {
|
|
1250
|
+
for (const key of readKeysForCommand(pathOf2(command))) {
|
|
1251
|
+
const { level, key: named } = levelFor(settings.permissions, key);
|
|
1252
|
+
if (level !== "deny")
|
|
1253
|
+
continue;
|
|
1254
|
+
throw new CliError("permission_error", `profile ${settings.profile} denies ${key} (permissions.${named} is deny, from the ${settings.permissionSources[named ?? ""] ?? "default"})`, { permission: key });
|
|
1255
|
+
}
|
|
1256
|
+
}, "refuseDenied");
|
|
1257
|
+
var refuseLocalWrite = /* @__PURE__ */ __name((context, command, permission) => {
|
|
1258
|
+
const { settings } = context;
|
|
1259
|
+
const { level, key } = levelFor(settings.permissions, permission);
|
|
1260
|
+
if (level === "allow" || level === "ask" && context.agent)
|
|
1261
|
+
return;
|
|
1262
|
+
if (fetchesUnder(level, permission))
|
|
1263
|
+
return;
|
|
1264
|
+
if (key === CEILING_KEY)
|
|
1265
|
+
throw ceilingRefusal(permission, command);
|
|
1266
|
+
throw new CliError(level === "ask" ? "confirmation_required" : "permission_error", `profile ${settings.profile} does not let ${permission} write (permissions.${key} is ${level}, from the ${settings.permissionSources[key ?? ""] ?? "default"}); to allow it: ${command} ${settings.profile} config set permissions.${permission} allow`, { permission });
|
|
1267
|
+
}, "refuseLocalWrite");
|
|
1268
|
+
var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {}) => {
|
|
1269
|
+
const { app, provider } = messenger;
|
|
1270
|
+
const base = baseContext(command, (flags, options) => messenger.resolveSettings(flags, { ...options, ...resolving }));
|
|
1271
|
+
const { profile } = base.settings;
|
|
1272
|
+
refuseDenied(command, base.settings);
|
|
1273
|
+
refuseLacking(messenger, pathOf2(command));
|
|
1274
|
+
refuseUnknownPermissionKeys(command, base.settings, app.command, messenger.permissionKey);
|
|
1275
|
+
const warn = /* @__PURE__ */ __name((text, warning) => base.renderer.warn(text, warning), "warn");
|
|
1276
|
+
const accountFor = /* @__PURE__ */ __name(() => {
|
|
1277
|
+
const account = messenger.accountOf?.(command) ?? recalledAccount(app, provider, profile, base.env);
|
|
1278
|
+
if (!account)
|
|
1279
|
+
throw unrecorded(command, messenger, profile, base.settings, base.env);
|
|
1280
|
+
return account;
|
|
1281
|
+
}, "accountFor");
|
|
1282
|
+
const guard = messenger.guard?.(command, base.settings, warn) ?? guardFor(app, base.settings, warn, base.env, terminalAsker(command));
|
|
1283
|
+
const { embedders } = environmentOf(command);
|
|
1284
|
+
return {
|
|
1285
|
+
...base,
|
|
1286
|
+
agent: environmentOf(command).agent !== void 0,
|
|
1287
|
+
profile,
|
|
1288
|
+
stdin: environmentOf(command).stdin ?? process.stdin,
|
|
1289
|
+
...environmentOf(command).recognizer ? { recognizer: environmentOf(command).recognizer } : {},
|
|
1290
|
+
guard,
|
|
1291
|
+
withMessenger: /* @__PURE__ */ __name((work, options = {}) => base.run(async (events) => {
|
|
1292
|
+
if (base.settings.offline)
|
|
1293
|
+
throw new CliError("validation_error", OFFLINE);
|
|
1294
|
+
const { connection, adapter, close } = await connectedFor(command, messenger, base, { ...options, events });
|
|
1295
|
+
base.track(connection);
|
|
1296
|
+
try {
|
|
1297
|
+
return await work(adapter);
|
|
1298
|
+
} finally {
|
|
1299
|
+
await close();
|
|
1300
|
+
}
|
|
1301
|
+
}, { unbounded: options.listen === true }), "withMessenger"),
|
|
1302
|
+
withStore: /* @__PURE__ */ __name((work, { name } = {}) => base.run(async () => {
|
|
1303
|
+
const account = accountFor();
|
|
1304
|
+
const store = await openStore({ env: base.env, command: app.command, version: app.version });
|
|
1305
|
+
try {
|
|
1306
|
+
return await work(store, account);
|
|
1307
|
+
} finally {
|
|
1308
|
+
await store.close();
|
|
1309
|
+
}
|
|
1310
|
+
}, name === void 0 ? {} : { name }), "withStore"),
|
|
1311
|
+
withServices: /* @__PURE__ */ __name((work, { name } = {}) => base.run(async (events) => {
|
|
1312
|
+
let held;
|
|
1313
|
+
let store;
|
|
1314
|
+
let warned;
|
|
1315
|
+
let released;
|
|
1316
|
+
const releaseConnection = /* @__PURE__ */ __name(() => released ??= held?.close() ?? Promise.resolve(), "releaseConnection");
|
|
1317
|
+
const openOnce = /* @__PURE__ */ __name(() => store ??= openStore({ env: base.env, command: app.command, version: app.version }), "openOnce");
|
|
1318
|
+
const deps = {
|
|
1319
|
+
messenger,
|
|
1320
|
+
profile,
|
|
1321
|
+
env: base.env,
|
|
1322
|
+
offline: base.settings.offline,
|
|
1323
|
+
reads: messenger.history ?? "server",
|
|
1324
|
+
// Turning recording off by name (--no-record, or record: false) keeps no search history either.
|
|
1325
|
+
history: base.settings.record,
|
|
1326
|
+
searchCatchUp: base.settings.searchCatchUp,
|
|
1327
|
+
...base.settings.historyLimits ? { historyLimits: base.settings.historyLimits } : {},
|
|
1328
|
+
historyMuted: base.settings.historyMuted,
|
|
1329
|
+
pictures: base.settings.pictureSearch,
|
|
1330
|
+
reranker: base.settings.searchReranker,
|
|
1331
|
+
guard,
|
|
1332
|
+
...embedders ? { embedders } : {},
|
|
1333
|
+
connection: /* @__PURE__ */ __name(async () => {
|
|
1334
|
+
if (base.settings.offline)
|
|
1335
|
+
throw new CliError("validation_error", OFFLINE);
|
|
1336
|
+
if (released)
|
|
1337
|
+
throw new CliError("validation_error", "the read connection has already been released");
|
|
1338
|
+
if (!held) {
|
|
1339
|
+
let connection;
|
|
1340
|
+
connection = await connectFor(command, messenger, base, {
|
|
1341
|
+
events,
|
|
1342
|
+
stored: storedMessages(messenger.provider, openOnce, () => connection?.self())
|
|
1343
|
+
});
|
|
1344
|
+
if (released) {
|
|
1345
|
+
await connection.close();
|
|
1346
|
+
throw new CliError("validation_error", "the read connection has already been released");
|
|
1347
|
+
}
|
|
1348
|
+
base.track(connection);
|
|
1349
|
+
held = connected(connection, messenger, base, events, void 0, waitsOf(command));
|
|
1350
|
+
}
|
|
1351
|
+
return held.adapter;
|
|
1352
|
+
}, "connection"),
|
|
1353
|
+
account: /* @__PURE__ */ __name(async () => accountFor(), "account"),
|
|
1354
|
+
// The connect's stored lookup opens the store too; only a service reading its answer there warns.
|
|
1355
|
+
store: /* @__PURE__ */ __name(() => {
|
|
1356
|
+
warned ??= openOnce().then(async (opened) => {
|
|
1357
|
+
if (messenger.history === "store")
|
|
1358
|
+
await warnUnserved(messenger, profile, base, opened);
|
|
1359
|
+
return opened;
|
|
1360
|
+
});
|
|
1361
|
+
return warned;
|
|
1362
|
+
}, "store")
|
|
1363
|
+
};
|
|
1364
|
+
try {
|
|
1365
|
+
return await work(servicesFor(deps), async (read) => {
|
|
1366
|
+
try {
|
|
1367
|
+
return await read(await deps.connection());
|
|
1368
|
+
} finally {
|
|
1369
|
+
await releaseConnection();
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
} finally {
|
|
1373
|
+
try {
|
|
1374
|
+
await releaseConnection();
|
|
1375
|
+
} finally {
|
|
1376
|
+
if (store)
|
|
1377
|
+
await (await store.catch(() => void 0))?.close();
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
}, name === void 0 ? {} : { name }), "withServices")
|
|
1381
|
+
};
|
|
1382
|
+
}, "messengerContext");
|
|
1383
|
+
|
|
1384
|
+
export {
|
|
1385
|
+
answerOf,
|
|
1386
|
+
terminalAsker,
|
|
1387
|
+
commandPermissions,
|
|
1388
|
+
knownPermissionKeys,
|
|
1389
|
+
knownBeside,
|
|
1390
|
+
unknownPermissionIssues,
|
|
1391
|
+
refuseUnknownPermissionKeys,
|
|
1392
|
+
fill,
|
|
1393
|
+
connectedFor,
|
|
1394
|
+
refuseLocalWrite,
|
|
1395
|
+
messengerContext
|
|
1396
|
+
};
|