@wirecat/max-cli 0.54.0 → 0.56.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/dist/adapter/max-adapter.d.ts +1 -5
- package/dist/adapter/max-adapter.d.ts.map +1 -1
- package/dist/adapter/max-adapter.js +21 -53
- package/dist/adapter/max-adapter.js.map +1 -1
- package/dist/client/account.d.ts +3 -3
- package/dist/client/account.d.ts.map +1 -1
- package/dist/client/account.js +4 -4
- package/dist/client/account.js.map +1 -1
- package/dist/client/chat-members.d.ts +2 -1
- package/dist/client/chat-members.d.ts.map +1 -1
- package/dist/client/chat-members.js.map +1 -1
- package/dist/client/chat-reads.d.ts +2 -1
- package/dist/client/chat-reads.d.ts.map +1 -1
- package/dist/client/chat-reads.js +9 -7
- package/dist/client/chat-reads.js.map +1 -1
- package/dist/client/chat-writes.d.ts +5 -12
- package/dist/client/chat-writes.d.ts.map +1 -1
- package/dist/client/chat-writes.js +40 -67
- package/dist/client/chat-writes.js.map +1 -1
- package/dist/client/contacts.d.ts +4 -4
- package/dist/client/contacts.d.ts.map +1 -1
- package/dist/client/contacts.js +6 -6
- package/dist/client/contacts.js.map +1 -1
- package/dist/client/delivery.d.ts +1 -1
- package/dist/client/delivery.d.ts.map +1 -1
- package/dist/client/delivery.js.map +1 -1
- package/dist/client/folders.d.ts +2 -3
- package/dist/client/folders.d.ts.map +1 -1
- package/dist/client/folders.js +4 -4
- package/dist/client/folders.js.map +1 -1
- package/dist/client/history.d.ts +2 -1
- package/dist/client/history.d.ts.map +1 -1
- package/dist/client/history.js +4 -3
- package/dist/client/history.js.map +1 -1
- package/dist/client/live.d.ts +2 -1
- package/dist/client/live.d.ts.map +1 -1
- package/dist/client/live.js.map +1 -1
- package/dist/client/message-reads.d.ts +1 -1
- package/dist/client/message-reads.d.ts.map +1 -1
- package/dist/client/message-reads.js +7 -5
- package/dist/client/message-reads.js.map +1 -1
- package/dist/client/message-writes.d.ts +2 -8
- package/dist/client/message-writes.d.ts.map +1 -1
- package/dist/client/message-writes.js +75 -178
- package/dist/client/message-writes.js.map +1 -1
- package/dist/client/people.d.ts +1 -1
- package/dist/client/people.d.ts.map +1 -1
- package/dist/client/people.js.map +1 -1
- package/dist/client/polls.d.ts +5 -10
- package/dist/client/polls.d.ts.map +1 -1
- package/dist/client/polls.js +27 -74
- package/dist/client/polls.js.map +1 -1
- package/dist/client/session.d.ts +1 -1
- package/dist/client/session.d.ts.map +1 -1
- package/dist/client/session.js.map +1 -1
- package/dist/client/shapes.d.ts +59 -0
- package/dist/client/shapes.d.ts.map +1 -0
- package/dist/client/shapes.js +6 -0
- package/dist/client/shapes.js.map +1 -0
- package/dist/client/stickers.d.ts +1 -1
- package/dist/client/stickers.d.ts.map +1 -1
- package/dist/client/stickers.js.map +1 -1
- package/dist/client/types.d.ts +0 -8
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/values.d.ts +7 -1
- package/dist/client/values.d.ts.map +1 -1
- package/dist/client/values.js +5 -0
- package/dist/client/values.js.map +1 -1
- package/dist/client/writes.d.ts +6 -15
- package/dist/client/writes.d.ts.map +1 -1
- package/dist/client/writes.js +21 -118
- package/dist/client/writes.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -19
- package/dist/client.js.map +1 -1
- package/dist/commands/bot.d.ts.map +1 -1
- package/dist/commands/bot.js +4 -4
- package/dist/commands/bot.js.map +1 -1
- package/dist/commands/contacts.d.ts.map +1 -1
- package/dist/commands/contacts.js +7 -5
- package/dist/commands/contacts.js.map +1 -1
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js +2 -6
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +6 -10
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/serve.js +1 -1
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/session.js +1 -1
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +23 -15
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/watch.d.ts +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +6 -4
- package/dist/commands/watch.js.map +1 -1
- package/dist/domain/map.d.ts +4 -3
- package/dist/domain/map.d.ts.map +1 -1
- package/dist/domain/map.js +27 -22
- package/dist/domain/map.js.map +1 -1
- package/dist/download.d.ts +1 -1
- package/dist/download.d.ts.map +1 -1
- package/dist/messenger.d.ts +1 -1
- package/dist/messenger.d.ts.map +1 -1
- package/dist/messenger.js +36 -9
- package/dist/messenger.js.map +1 -1
- package/dist/permissions.d.ts +3 -3
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +20 -4
- package/dist/permissions.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +2 -3
- package/dist/program.js.map +1 -1
- package/dist/report.d.ts +2 -2
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +25 -13
- package/dist/report.js.map +1 -1
- package/dist/resolve.d.ts +1 -1
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js.map +1 -1
- package/dist/sends.d.ts +3 -3
- package/dist/sends.d.ts.map +1 -1
- package/dist/sends.js +3 -3
- package/dist/sends.js.map +1 -1
- package/dist/server/replies.d.ts +1 -2
- package/dist/server/replies.d.ts.map +1 -1
- package/dist/server/replies.js.map +1 -1
- package/dist/server/server-connection.js +1 -1
- package/dist/server/server-connection.js.map +1 -1
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +0 -2
- package/dist/server/server.js.map +1 -1
- package/dist/transcribe/index.d.ts +1 -1
- package/dist/transcribe/index.d.ts.map +1 -1
- package/dist/transcribe/index.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/skills/max-cli/SKILL.md +18 -9
- package/dist/client/read-policy.d.ts +0 -2
- package/dist/client/read-policy.d.ts.map +0 -1
- package/dist/client/read-policy.js +0 -34
- package/dist/client/read-policy.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -29
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js +0 -176
- package/dist/commands/mcp.js.map +0 -1
- package/dist/domain/models.d.ts +0 -238
- package/dist/domain/models.d.ts.map +0 -1
- package/dist/domain/models.js +0 -17
- package/dist/domain/models.js.map +0 -1
- package/dist/mcp/instructions.d.ts +0 -4
- package/dist/mcp/instructions.d.ts.map +0 -1
- package/dist/mcp/instructions.js +0 -16
- package/dist/mcp/instructions.js.map +0 -1
- package/dist/mcp/legacy-check.d.ts +0 -12
- package/dist/mcp/legacy-check.d.ts.map +0 -1
- package/dist/mcp/legacy-check.js +0 -46
- package/dist/mcp/legacy-check.js.map +0 -1
- package/dist/mcp/photo.d.ts +0 -9
- package/dist/mcp/photo.d.ts.map +0 -1
- package/dist/mcp/photo.js +0 -38
- package/dist/mcp/photo.js.map +0 -1
- package/dist/mcp/prompts.d.ts +0 -7
- package/dist/mcp/prompts.d.ts.map +0 -1
- package/dist/mcp/prompts.js +0 -102
- package/dist/mcp/prompts.js.map +0 -1
- package/dist/mcp/resources.d.ts +0 -15
- package/dist/mcp/resources.d.ts.map +0 -1
- package/dist/mcp/resources.js +0 -56
- package/dist/mcp/resources.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -23
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -98
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/session.d.ts +0 -30
- package/dist/mcp/session.d.ts.map +0 -1
- package/dist/mcp/session.js +0 -109
- package/dist/mcp/session.js.map +0 -1
- package/dist/mcp/shared.d.ts +0 -14
- package/dist/mcp/shared.d.ts.map +0 -1
- package/dist/mcp/shared.js +0 -46
- package/dist/mcp/shared.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -19
- package/dist/mcp/tools.d.ts.map +0 -1
- package/dist/mcp/tools.js +0 -257
- package/dist/mcp/tools.js.map +0 -1
- package/dist/moderation/check.d.ts +0 -103
- package/dist/moderation/check.d.ts.map +0 -1
- package/dist/moderation/check.js +0 -273
- package/dist/moderation/check.js.map +0 -1
- package/dist/moderation/points.d.ts +0 -8
- package/dist/moderation/points.d.ts.map +0 -1
- package/dist/moderation/points.js +0 -21
- package/dist/moderation/points.js.map +0 -1
- package/dist/rendering/messages.d.ts +0 -24
- package/dist/rendering/messages.d.ts.map +0 -1
- package/dist/rendering/messages.js +0 -172
- package/dist/rendering/messages.js.map +0 -1
package/dist/mcp/tools.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { AI_SETTING_KEYS, itemOf, personalMcpCommand, personalMcpToolKey, personalMcpTools, registerPersonalMcpSurface, rememberAccount, stored, } from "@wirecat/cli-core/cli";
|
|
3
|
-
import { levelFor } from "@wirecat/cli-core/sends";
|
|
4
|
-
import { openStore } from "@wirecat/cli-core/store";
|
|
5
|
-
import * as v from "valibot";
|
|
6
|
-
import { maxAdapter } from "../adapter/max-adapter.js";
|
|
7
|
-
import { MAX_APP } from "../app.js";
|
|
8
|
-
import { resolveSettings } from "../config.js";
|
|
9
|
-
import { maxMessenger } from "../messenger.js";
|
|
10
|
-
import { migrateModerationPoints } from "../moderation/points.js";
|
|
11
|
-
import { assertReadable, withPermissionApproval } from "../permissions.js";
|
|
12
|
-
import { maxRecord } from "../record.js";
|
|
13
|
-
import { transcribe } from "../transcribe/index.js";
|
|
14
|
-
import { modelsDirectory } from "../transcribe/install.js";
|
|
15
|
-
import { DEFAULT_MODEL, speechModel } from "../transcribe/models.js";
|
|
16
|
-
import { legacyCheckTool } from "./legacy-check.js";
|
|
17
|
-
import { photoForMcp } from "./photo.js";
|
|
18
|
-
import { withShared } from "./shared.js";
|
|
19
|
-
const PASS = { check: () => { }, record: () => { } };
|
|
20
|
-
const READ = { readOnlyHint: true, destructiveHint: false, openWorldHint: true };
|
|
21
|
-
export const registerTools = (server, session, { store, defaultLimit, history, profile, permission, transcribeModel = DEFAULT_MODEL, warn = () => { }, reach, embedders, }) => {
|
|
22
|
-
const settings = () => resolveSettings({ profile, permission });
|
|
23
|
-
const adapters = new WeakMap();
|
|
24
|
-
const definitions = personalMcpTools(maxMessenger);
|
|
25
|
-
for (const name of Object.keys(definitions))
|
|
26
|
-
if (name.startsWith("topics_"))
|
|
27
|
-
delete definitions[name];
|
|
28
|
-
const rules = definitions.chats_rules_show;
|
|
29
|
-
if (rules)
|
|
30
|
-
definitions.chats_rules = { ...rules, key: "chats.rules.show" };
|
|
31
|
-
const keyOf = (name, definition) => name === "status" ? null : (personalMcpToolKey(name, definition) ?? "messages");
|
|
32
|
-
const writable = (name, definition) => {
|
|
33
|
-
const key = keyOf(name, definition);
|
|
34
|
-
if (key === null)
|
|
35
|
-
return null;
|
|
36
|
-
const own = settings();
|
|
37
|
-
assertReadable(own, key);
|
|
38
|
-
if (definition.annotations.readOnlyHint !== true && levelFor(own.permissions, key).level === "readonly")
|
|
39
|
-
throw new CliError("permission_error", `profile ${profile} does not let ${key} write`, { permission: key });
|
|
40
|
-
return key;
|
|
41
|
-
};
|
|
42
|
-
const inScope = (name, definition, work) => {
|
|
43
|
-
const key = writable(name, definition);
|
|
44
|
-
if (key === null)
|
|
45
|
-
return work();
|
|
46
|
-
if (key === "chats.moderate")
|
|
47
|
-
migrateModerationPoints(store);
|
|
48
|
-
return withPermissionApproval(key, () => key === "chats.moderate"
|
|
49
|
-
? withPermissionApproval("messages.delete", () => withPermissionApproval("chats.members.remove", work))
|
|
50
|
-
: work());
|
|
51
|
-
};
|
|
52
|
-
const remember = () => {
|
|
53
|
-
const account = store.readState().viewerId;
|
|
54
|
-
if (!account)
|
|
55
|
-
return;
|
|
56
|
-
try {
|
|
57
|
-
rememberAccount(MAX_APP, profile, account, process.env);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
// A secondary local binding must not replace a successful send or prevent store cleanup.
|
|
61
|
-
warn("could not remember the account for local archive tools");
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
// cli-core asks for the account before a write; a profile that never logged in has none until LOGIN answers.
|
|
65
|
-
const knowAccount = async (client) => {
|
|
66
|
-
if (store.readState().viewerId === undefined)
|
|
67
|
-
await client.connect();
|
|
68
|
-
};
|
|
69
|
-
const adapterFor = (client) => {
|
|
70
|
-
const adapter = maxAdapter(client, store, reach, warn);
|
|
71
|
-
adapters.set(adapter, client);
|
|
72
|
-
return adapter;
|
|
73
|
-
};
|
|
74
|
-
const offered = Object.fromEntries(Object.entries(definitions).filter(([name, definition]) => {
|
|
75
|
-
const key = keyOf(name, definition);
|
|
76
|
-
const level = key === null ? "allow" : levelFor(settings().permissions, key).level;
|
|
77
|
-
return level !== "deny" && (definition.annotations.readOnlyHint === true || level !== "readonly");
|
|
78
|
-
}));
|
|
79
|
-
const direct = offered.messages_transcribe;
|
|
80
|
-
const picture = offered.messages_photo;
|
|
81
|
-
if (picture)
|
|
82
|
-
offered.messages_photo = {
|
|
83
|
-
...picture,
|
|
84
|
-
online: (adapter, args) => {
|
|
85
|
-
const client = adapters.get(adapter);
|
|
86
|
-
if (!client)
|
|
87
|
-
throw new Error("MAX photo preview requires its held adapter");
|
|
88
|
-
return photoForMcp(client, {
|
|
89
|
-
chat: String(args.chat),
|
|
90
|
-
message: String(args.message),
|
|
91
|
-
...(typeof args.index === "number" ? { index: args.index } : {}),
|
|
92
|
-
}, reach);
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
if (direct)
|
|
96
|
-
offered.messages_transcribe = {
|
|
97
|
-
...direct,
|
|
98
|
-
description: "A MAX voice message as text on this machine. Reuses a retained transcript from the same model; never downloads a model. Answers item { message_id, text, pending, via, model }.",
|
|
99
|
-
online: async (adapter, args, defaults) => {
|
|
100
|
-
const client = adapters.get(adapter);
|
|
101
|
-
if (!client)
|
|
102
|
-
throw new Error("MAX transcription requires its held adapter");
|
|
103
|
-
const message = String(args.message);
|
|
104
|
-
if (!/^\d+$/.test(message))
|
|
105
|
-
throw new CliError("validation_error", "MAX message IDs must be decimal strings");
|
|
106
|
-
const chatId = await client.chats.resolve(String(args.chat));
|
|
107
|
-
const model = speechModel(typeof args.model === "string" ? args.model : transcribeModel);
|
|
108
|
-
const record = maxRecord({ account: () => store.readState().viewerId });
|
|
109
|
-
try {
|
|
110
|
-
const kept = await record.transcript(chatId, message);
|
|
111
|
-
const text = kept?.source === model.id
|
|
112
|
-
? kept.text
|
|
113
|
-
: (await transcribe(client, chatId, message, {
|
|
114
|
-
model,
|
|
115
|
-
directory: modelsDirectory(),
|
|
116
|
-
record,
|
|
117
|
-
...(defaults.release ? { release: defaults.release } : {}),
|
|
118
|
-
})).text;
|
|
119
|
-
return itemOf({ message_id: message, text, pending: false, via: "local", model: model.id });
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
await record.close();
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
for (const [name, definition] of Object.entries(offered)) {
|
|
127
|
-
if (!definition._meta)
|
|
128
|
-
continue;
|
|
129
|
-
const metadata = { ...definition._meta };
|
|
130
|
-
delete metadata["anthropic/requiresUserInteraction"];
|
|
131
|
-
offered[name] = { ...definition, _meta: metadata };
|
|
132
|
-
}
|
|
133
|
-
const moderation = definitions.chats_moderate;
|
|
134
|
-
const level = levelFor(settings().permissions, "chats.moderate").level;
|
|
135
|
-
if (moderation && ["allow", "ask"].includes(level))
|
|
136
|
-
offered.chats_check = legacyCheckTool(session, {
|
|
137
|
-
store,
|
|
138
|
-
profile,
|
|
139
|
-
allowDangerous: false,
|
|
140
|
-
yes: true,
|
|
141
|
-
confirmSend: false,
|
|
142
|
-
scope: (work) => inScope("chats_moderate", moderation, work),
|
|
143
|
-
});
|
|
144
|
-
offered.status = {
|
|
145
|
-
title: "This server's profile and login",
|
|
146
|
-
description: "The profile, known account and offered writes. Reads local state only; never connects or prints a token.",
|
|
147
|
-
key: null,
|
|
148
|
-
input: v.strictObject({}),
|
|
149
|
-
annotations: { ...READ, idempotentHint: true },
|
|
150
|
-
local: async () => {
|
|
151
|
-
const account = store.readState().viewerId ?? null;
|
|
152
|
-
let token;
|
|
153
|
-
try {
|
|
154
|
-
token = store.tokenSource() ?? "none";
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
token = "unreachable";
|
|
158
|
-
}
|
|
159
|
-
return itemOf({
|
|
160
|
-
profile,
|
|
161
|
-
account,
|
|
162
|
-
kind: store.isBot() ? "personal + bot" : "personal",
|
|
163
|
-
token,
|
|
164
|
-
logged_in_here: store.hasLoggedIn(),
|
|
165
|
-
has_token: store.readToken() !== undefined,
|
|
166
|
-
has_logged_in: account !== null,
|
|
167
|
-
writes: [
|
|
168
|
-
...Object.entries(offered)
|
|
169
|
-
.filter(([, one]) => one.annotations.readOnlyHint !== true)
|
|
170
|
-
.map(([name]) => personalMcpCommand(name)),
|
|
171
|
-
],
|
|
172
|
-
permissions: settings().permissions,
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
const currentSettings = settings();
|
|
177
|
-
const ai = Object.fromEntries(AI_SETTING_KEYS.map((key) => [key, currentSettings[key]]));
|
|
178
|
-
registerPersonalMcpSurface(server, offered, {
|
|
179
|
-
command: "max",
|
|
180
|
-
messenger: maxMessenger,
|
|
181
|
-
defaults: {
|
|
182
|
-
limit: defaultLimit,
|
|
183
|
-
history: history ?? settings().keepFailedRuns,
|
|
184
|
-
guard: PASS,
|
|
185
|
-
settings: {
|
|
186
|
-
...ai,
|
|
187
|
-
profile,
|
|
188
|
-
searchCatchUp: currentSettings.searchCatchUp,
|
|
189
|
-
configured: ai,
|
|
190
|
-
shared: { ...ai, speechModel: transcribeModel },
|
|
191
|
-
get permissions() {
|
|
192
|
-
return settings().permissions;
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
env: process.env,
|
|
196
|
-
...(embedders ? { embedders } : {}),
|
|
197
|
-
},
|
|
198
|
-
around: inScope,
|
|
199
|
-
session: {
|
|
200
|
-
use: (name, work) => session.use(name, async (client, release) => {
|
|
201
|
-
await knowAccount(client);
|
|
202
|
-
let opened;
|
|
203
|
-
const account = {
|
|
204
|
-
provider: "max",
|
|
205
|
-
get account() {
|
|
206
|
-
const id = store.readState().viewerId;
|
|
207
|
-
if (!id)
|
|
208
|
-
throw new CliError("authentication_error", `no MAX account known for profile ${profile}`);
|
|
209
|
-
return id;
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
const adapter = stored(adapterFor(client), {
|
|
213
|
-
account,
|
|
214
|
-
store: () => (opened ??= openStore()),
|
|
215
|
-
warn,
|
|
216
|
-
events: () => { },
|
|
217
|
-
});
|
|
218
|
-
adapters.set(adapter, client);
|
|
219
|
-
try {
|
|
220
|
-
return await work(adapter, release);
|
|
221
|
-
}
|
|
222
|
-
finally {
|
|
223
|
-
remember();
|
|
224
|
-
if (opened)
|
|
225
|
-
await opened.then((store) => store.close(), () => { });
|
|
226
|
-
}
|
|
227
|
-
}),
|
|
228
|
-
},
|
|
229
|
-
withStore: (work, { name }) => session.local(name, async () => {
|
|
230
|
-
const account = store.readState().viewerId;
|
|
231
|
-
if (!account)
|
|
232
|
-
throw new CliError("authentication_error", `no MAX account known for profile ${profile}`);
|
|
233
|
-
const opened = await openStore();
|
|
234
|
-
try {
|
|
235
|
-
return await work(opened, { provider: "max", account });
|
|
236
|
-
}
|
|
237
|
-
finally {
|
|
238
|
-
await opened.close();
|
|
239
|
-
}
|
|
240
|
-
}),
|
|
241
|
-
withServices: (work, { name }) => session.use(name, async (client, release) => {
|
|
242
|
-
await knowAccount(client);
|
|
243
|
-
return withShared(client, { store, profile, warn }, async (services) => {
|
|
244
|
-
remember();
|
|
245
|
-
return work(services, async (read) => {
|
|
246
|
-
try {
|
|
247
|
-
return await read(adapterFor(client));
|
|
248
|
-
}
|
|
249
|
-
finally {
|
|
250
|
-
await release();
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}, name === "mcp messages link" ? { reads: "store" } : { login: true });
|
|
254
|
-
}),
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
//# sourceMappingURL=tools.js.map
|
package/dist/mcp/tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EACL,eAAe,EACf,MAAM,EAIN,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YA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C;4BAAS,CAAC;wBACT,MAAM,OAAO,EAAE,CAAA;oBACjB,CAAC;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC,EACD,IAAI,KAAK,mBAAmB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CACpE,CAAA;QACH,CAAC,CAAC;KACL,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { MaxClient } from "../client.js";
|
|
2
|
-
import type { GroupMember, Id, Message } from "../domain/models.js";
|
|
3
|
-
import { moderationPoints } from "./points.js";
|
|
4
|
-
import { type GroupRules } from "./rules.js";
|
|
5
|
-
export type Action = "report" | "delete" | "remove";
|
|
6
|
-
export type Outcome = "reported" | "done" | "planned" | "forbidden" | "declined" | "refused" | "failed" | "skipped";
|
|
7
|
-
export interface Finding {
|
|
8
|
-
/** A message, or somebody who joined. */
|
|
9
|
-
kind: "message" | "member";
|
|
10
|
-
rule: "blocked" | "invites" | "links" | "forwards" | "flood" | "newAccount";
|
|
11
|
-
personId: Id;
|
|
12
|
-
personName: string | null;
|
|
13
|
-
messageId?: Id;
|
|
14
|
-
action: Action;
|
|
15
|
-
}
|
|
16
|
-
export interface CheckRow extends Finding {
|
|
17
|
-
outcome: Outcome;
|
|
18
|
-
reason?: string;
|
|
19
|
-
/** What the owner types to do it by hand, on a row that was not done. */
|
|
20
|
-
command?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface CheckInput {
|
|
23
|
-
rules: GroupRules;
|
|
24
|
-
messages: Message[];
|
|
25
|
-
joined: GroupMember[];
|
|
26
|
-
/** The owner's admins; the owner's own messages are known by `outgoing`. */
|
|
27
|
-
answerers: ReadonlySet<Id>;
|
|
28
|
-
now: number;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* What the rules say about what is new. Pure: nothing here talks to MAX. One finding per message —
|
|
32
|
-
* the rule with the strongest action — and one removal per person, whatever else they did.
|
|
33
|
-
*/
|
|
34
|
-
export declare const judge: ({ rules, messages, joined, answerers, now }: CheckInput) => Finding[];
|
|
35
|
-
export interface ActOptions {
|
|
36
|
-
chatId: Id;
|
|
37
|
-
rules: GroupRules;
|
|
38
|
-
/** `--allow-dangerous` on this run: what `flag` asks for. */
|
|
39
|
-
allowDangerous: boolean;
|
|
40
|
-
dryRun: boolean;
|
|
41
|
-
maxActions: number;
|
|
42
|
-
/** Asks the owner about one action; `undefined` when nobody is there to ask. */
|
|
43
|
-
confirm?: (finding: Finding) => Promise<boolean>;
|
|
44
|
-
}
|
|
45
|
-
/** The two things a check may do, whoever does them: the personal account, or a bot. */
|
|
46
|
-
export interface Moderator {
|
|
47
|
-
deleteMessage(chatId: Id, messageId: Id): Promise<void>;
|
|
48
|
-
removePerson(chatId: Id, personId: Id): Promise<void>;
|
|
49
|
-
}
|
|
50
|
-
/** The personal account: deleting is for everyone, removing leaves messages and cannot ban. */
|
|
51
|
-
export declare const personal: (client: MaxClient) => Moderator;
|
|
52
|
-
/**
|
|
53
|
-
* Does what the findings ask, as far as consent, the per-run limit and the guard let it. Stops
|
|
54
|
-
* acting at the first hourly-limit refusal: the rest is `skipped`, never tried.
|
|
55
|
-
*/
|
|
56
|
-
export declare const act: (moderator: Moderator, findings: Finding[], options: ActOptions) => Promise<CheckRow[]>;
|
|
57
|
-
/** One action in words, for a prompt or a confirmation form. */
|
|
58
|
-
export declare const describe: (finding: Finding) => string;
|
|
59
|
-
/** Whether acting on it waits for the owner's yes. */
|
|
60
|
-
export declare const needsConfirm: (rules: GroupRules, finding: Finding) => boolean;
|
|
61
|
-
export interface Gathered extends Omit<CheckInput, "rules" | "now"> {
|
|
62
|
-
/** The newest message read, ISO 8601: where the next check starts. */
|
|
63
|
-
until: string | null;
|
|
64
|
-
/** More history than one check reads. */
|
|
65
|
-
more: boolean;
|
|
66
|
-
notes: string[];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* What is new in the group since `since`: its messages, who joined (from the service messages —
|
|
70
|
-
* `add` measured, `joinByLink` assumed to name the joiner or be sent by them), who asks to join,
|
|
71
|
-
* and who the admins are.
|
|
72
|
-
*/
|
|
73
|
-
export declare const gather: (client: MaxClient, chatId: Id, since: number) => Promise<Gathered>;
|
|
74
|
-
export declare const MAX_ACTIONS = 10;
|
|
75
|
-
/** Where each chat's next check starts, ISO 8601. */
|
|
76
|
-
export interface SavedPoints {
|
|
77
|
-
read(chatId: Id): string | undefined;
|
|
78
|
-
write(chatId: Id, at: string): void;
|
|
79
|
-
}
|
|
80
|
-
export declare const sessionPoints: typeof moderationPoints;
|
|
81
|
-
export interface Prepared {
|
|
82
|
-
chatId: Id;
|
|
83
|
-
title: string | null;
|
|
84
|
-
rules: GroupRules;
|
|
85
|
-
found: Gathered;
|
|
86
|
-
findings: Finding[];
|
|
87
|
-
/** `--since` was given: the saved point is not read, and not moved. */
|
|
88
|
-
explicit: boolean;
|
|
89
|
-
notes: string[];
|
|
90
|
-
}
|
|
91
|
-
/** Reads and judges; changes nothing. `since` overrides the group's saved point. */
|
|
92
|
-
export declare const prepare: (client: MaxClient, { points, profile, chat, since }: {
|
|
93
|
-
points: SavedPoints;
|
|
94
|
-
profile: string;
|
|
95
|
-
chat: string;
|
|
96
|
-
since?: number;
|
|
97
|
-
}) => Promise<Prepared>;
|
|
98
|
-
/** Acts on what `prepare` found, moves the group's saved point, and says what is left. */
|
|
99
|
-
export declare const finish: (moderator: Moderator, points: SavedPoints, prepared: Prepared, options: Omit<ActOptions, "chatId" | "rules">) => Promise<{
|
|
100
|
-
rows: CheckRow[];
|
|
101
|
-
notes: string[];
|
|
102
|
-
}>;
|
|
103
|
-
//# sourceMappingURL=check.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/moderation/check.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAA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;IAC1B,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,SAAS,CAAA;IACpC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CACpC;AAED,eAAO,MAAM,aAAa,yBAAmB,CAAA;AAK7C,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,EAAE,CAAA;IACV,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,EAAE,UAAU,CAAA;IACjB,KAAK,EAAE,QAAQ,CAAA;IACf,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,uEAAuE;IACvE,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,oFAAoF;AACpF,eAAO,MAAM,OAAO,WACV,SAAS,oCACiB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KACvG,OAAO,CAAC,QAAQ,CAmBlB,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,MAAM,cACN,SAAS,UACZ,WAAW,YACT,QAAQ,WACT,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,OAAO,CAAC,KAC5C,OAAO,CAAC;IAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAe/C,CAAA"}
|
package/dist/moderation/check.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { moderationPoints } from "./points.js";
|
|
3
|
-
import { defaultRules, ModerationRules, moderationPathFor } from "./rules.js";
|
|
4
|
-
const INVITE = /max\.ru\/join\//i;
|
|
5
|
-
const LINK = /https?:\/\/\S+/i;
|
|
6
|
-
/** Which action wins when a message breaks several rules; the first rule listed breaks a tie. */
|
|
7
|
-
const STRENGTH = { report: 0, delete: 1, remove: 2 };
|
|
8
|
-
/**
|
|
9
|
-
* What the rules say about what is new. Pure: nothing here talks to MAX. One finding per message —
|
|
10
|
-
* the rule with the strongest action — and one removal per person, whatever else they did.
|
|
11
|
-
*/
|
|
12
|
-
export const judge = ({ rules, messages, joined, answerers, now }) => {
|
|
13
|
-
const trusted = new Set(rules.trusted);
|
|
14
|
-
const blocked = (id, name) => (id !== null && rules.blocked.includes(id)) ||
|
|
15
|
-
(name !== null && rules.blockedNames.some((part) => name.toLocaleLowerCase().includes(part.toLocaleLowerCase())));
|
|
16
|
-
const young = (member) => rules.newAccount.days > 0 &&
|
|
17
|
-
member.registeredAt !== null &&
|
|
18
|
-
now - Date.parse(member.registeredAt) < rules.newAccount.days * 86_400_000;
|
|
19
|
-
const found = [];
|
|
20
|
-
const add = (finding) => {
|
|
21
|
-
if (finding.action === "remove" && found.some((f) => f.action === "remove" && f.personId === finding.personId)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
found.push(finding);
|
|
25
|
-
};
|
|
26
|
-
for (const member of joined) {
|
|
27
|
-
if (trusted.has(member.id) || answerers.has(member.id))
|
|
28
|
-
continue;
|
|
29
|
-
const person = { kind: "member", personId: member.id, personName: member.name };
|
|
30
|
-
if (blocked(member.id, member.name)) {
|
|
31
|
-
add({ ...person, rule: "blocked", action: rules.blockedPeople === "remove" ? "remove" : "report" });
|
|
32
|
-
}
|
|
33
|
-
else if (young(member)) {
|
|
34
|
-
add({ ...person, rule: "newAccount", action: rules.newAccount.action });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const flooding = floodOf(messages, rules.flood);
|
|
38
|
-
for (const message of messages) {
|
|
39
|
-
const id = message.senderId;
|
|
40
|
-
if (id === null || message.outgoing === true || answerers.has(id) || trusted.has(id))
|
|
41
|
-
continue;
|
|
42
|
-
if (message.attachments.some((attachment) => attachment.kind === "control"))
|
|
43
|
-
continue;
|
|
44
|
-
const base = { kind: "message", personId: id, personName: message.senderName, messageId: message.id };
|
|
45
|
-
const text = message.text;
|
|
46
|
-
const broken = [];
|
|
47
|
-
if (blocked(id, message.senderName))
|
|
48
|
-
broken.push(["blocked", rules.blockedPeople]);
|
|
49
|
-
if (INVITE.test(text))
|
|
50
|
-
broken.push(["invites", rules.invites]);
|
|
51
|
-
if (LINK.test(text) || message.attachments.some((attachment) => attachment.kind === "share")) {
|
|
52
|
-
broken.push(["links", rules.links]);
|
|
53
|
-
}
|
|
54
|
-
if (message.forwardedFrom !== null)
|
|
55
|
-
broken.push(["forwards", rules.forwards]);
|
|
56
|
-
if (flooding.has(message.id))
|
|
57
|
-
broken.push(["flood", rules.flood.action]);
|
|
58
|
-
const strongest = broken.reduce((best, rule) => (best === undefined || STRENGTH[rule[1]] > STRENGTH[best[1]] ? rule : best), undefined);
|
|
59
|
-
if (strongest)
|
|
60
|
-
add({ ...base, rule: strongest[0], action: strongest[1] });
|
|
61
|
-
}
|
|
62
|
-
return found;
|
|
63
|
-
};
|
|
64
|
-
/** Messages past the limit: more than `messages` from one person within `minutes`. */
|
|
65
|
-
const floodOf = (messages, flood) => {
|
|
66
|
-
const window = flood.minutes * 60_000;
|
|
67
|
-
const over = new Set();
|
|
68
|
-
const bySender = new Map();
|
|
69
|
-
for (const message of messages) {
|
|
70
|
-
if (message.senderId === null)
|
|
71
|
-
continue;
|
|
72
|
-
const times = bySender.get(message.senderId) ?? [];
|
|
73
|
-
const at = Date.parse(message.timestamp);
|
|
74
|
-
times.push(at);
|
|
75
|
-
bySender.set(message.senderId, times);
|
|
76
|
-
if (times.filter((time) => at - time < window).length > flood.messages)
|
|
77
|
-
over.add(message.id);
|
|
78
|
-
}
|
|
79
|
-
return over;
|
|
80
|
-
};
|
|
81
|
-
const CONSENT = {
|
|
82
|
-
delete: "delete",
|
|
83
|
-
remove: "remove",
|
|
84
|
-
};
|
|
85
|
-
/** The personal account: deleting is for everyone, removing leaves messages and cannot ban. */
|
|
86
|
-
export const personal = (client) => ({
|
|
87
|
-
deleteMessage: async (chatId, messageId) => {
|
|
88
|
-
await client.messages.delete(chatId, [messageId], { forEveryone: true });
|
|
89
|
-
},
|
|
90
|
-
removePerson: async (chatId, personId) => {
|
|
91
|
-
await client.chats.members.remove(chatId, [personId]);
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
/**
|
|
95
|
-
* Does what the findings ask, as far as consent, the per-run limit and the guard let it. Stops
|
|
96
|
-
* acting at the first hourly-limit refusal: the rest is `skipped`, never tried.
|
|
97
|
-
*/
|
|
98
|
-
export const act = async (moderator, findings, options) => {
|
|
99
|
-
const { chatId, rules, allowDangerous, dryRun, maxActions, confirm } = options;
|
|
100
|
-
const rows = [];
|
|
101
|
-
let acted = 0;
|
|
102
|
-
let stopped;
|
|
103
|
-
for (const finding of findings) {
|
|
104
|
-
if (finding.action === "report") {
|
|
105
|
-
rows.push({ ...finding, outcome: "reported" });
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const command = commandFor(chatId, finding);
|
|
109
|
-
const level = rules.consent[CONSENT[finding.action]];
|
|
110
|
-
const row = (outcome, reason) => ({
|
|
111
|
-
...finding,
|
|
112
|
-
outcome,
|
|
113
|
-
...(reason ? { reason } : {}),
|
|
114
|
-
...(outcome === "done" ? {} : { command }),
|
|
115
|
-
});
|
|
116
|
-
if (level === "deny") {
|
|
117
|
-
rows.push(row("forbidden", `consent.${CONSENT[finding.action]} is deny`));
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (dryRun) {
|
|
121
|
-
rows.push(row("planned", "--dry-run"));
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (level === "readonly") {
|
|
125
|
-
rows.push(row("reported", `consent.${CONSENT[finding.action]} is readonly`));
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (stopped || acted >= maxActions) {
|
|
129
|
-
rows.push(row("skipped", stopped ?? `over the limit of ${maxActions} actions per check`));
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (level === "ask" && !allowDangerous) {
|
|
133
|
-
if (!confirm) {
|
|
134
|
-
rows.push(row("planned", `consent.${CONSENT[finding.action]} is ask, and nobody is there to ask`));
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (!(await confirm(finding))) {
|
|
138
|
-
rows.push(row("declined", "not confirmed"));
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
acted += 1;
|
|
143
|
-
try {
|
|
144
|
-
if (finding.action === "delete" && finding.messageId) {
|
|
145
|
-
await moderator.deleteMessage(chatId, finding.messageId);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
await moderator.removePerson(chatId, finding.personId);
|
|
149
|
-
}
|
|
150
|
-
rows.push(row("done"));
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
const failure = asCliError(error);
|
|
154
|
-
if (failure.code === "rate_limited")
|
|
155
|
-
stopped = failure.message;
|
|
156
|
-
const refused = ["rate_limited", "permission_error", "confirmation_required"].includes(failure.code);
|
|
157
|
-
rows.push(row(refused ? "refused" : "failed", failure.message));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return rows;
|
|
161
|
-
};
|
|
162
|
-
const asCliError = (error) => error instanceof CliError
|
|
163
|
-
? error
|
|
164
|
-
: new CliError("provider_error", error instanceof Error ? error.message : String(error));
|
|
165
|
-
const who = (finding) => finding.personName ?? finding.personId;
|
|
166
|
-
/** One action in words, for a prompt or a confirmation form. */
|
|
167
|
-
export const describe = (finding) => finding.action === "delete"
|
|
168
|
-
? `delete message ${finding.messageId} from ${who(finding)} for everyone (${finding.rule})`
|
|
169
|
-
: `remove ${who(finding)} from the group (${finding.rule})`;
|
|
170
|
-
/** Whether acting on it waits for the owner's yes. */
|
|
171
|
-
export const needsConfirm = (rules, finding) => (finding.action === "delete" || finding.action === "remove") && rules.consent[finding.action] === "ask";
|
|
172
|
-
const commandFor = (chatId, finding) => {
|
|
173
|
-
switch (finding.action) {
|
|
174
|
-
case "delete":
|
|
175
|
-
return `max messages delete ${chatId} ${finding.messageId} --for-everyone --allow-dangerous`;
|
|
176
|
-
case "remove":
|
|
177
|
-
return `max chats members remove ${chatId} ${finding.personId}`;
|
|
178
|
-
default:
|
|
179
|
-
return "";
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* What is new in the group since `since`: its messages, who joined (from the service messages —
|
|
184
|
-
* `add` measured, `joinByLink` assumed to name the joiner or be sent by them), who asks to join,
|
|
185
|
-
* and who the admins are.
|
|
186
|
-
*/
|
|
187
|
-
export const gather = async (client, chatId, since) => {
|
|
188
|
-
const notes = [];
|
|
189
|
-
const { messages, more } = await client.chats.since(chatId, since);
|
|
190
|
-
const joinedIds = new Set(messages.flatMap((message) => message.attachments.flatMap((attachment) => {
|
|
191
|
-
if (attachment.event === "add")
|
|
192
|
-
return attachment.userIds ?? [];
|
|
193
|
-
if (attachment.event === "joinByLink") {
|
|
194
|
-
return attachment.userIds?.length ? attachment.userIds : message.senderId ? [message.senderId] : [];
|
|
195
|
-
}
|
|
196
|
-
return [];
|
|
197
|
-
})));
|
|
198
|
-
const joined = joinedIds.size === 0
|
|
199
|
-
? []
|
|
200
|
-
: (await client.chats.members.list(chatId)).members.filter((member) => joinedIds.has(member.id));
|
|
201
|
-
const admins = await client.chats.adminIds(chatId);
|
|
202
|
-
if (admins === undefined)
|
|
203
|
-
notes.push("the group's admins are not known, so only your own messages are exempt");
|
|
204
|
-
return {
|
|
205
|
-
messages,
|
|
206
|
-
joined,
|
|
207
|
-
answerers: new Set(admins ?? []),
|
|
208
|
-
until: messages.at(-1)?.timestamp ?? null,
|
|
209
|
-
more,
|
|
210
|
-
notes,
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
export const MAX_ACTIONS = 10;
|
|
214
|
-
export const sessionPoints = moderationPoints;
|
|
215
|
-
/** A group never checked before is looked at this far back. */
|
|
216
|
-
const FIRST_LOOK_MS = 24 * 3_600_000;
|
|
217
|
-
/** Reads and judges; changes nothing. `since` overrides the group's saved point. */
|
|
218
|
-
export const prepare = async (client, { points, profile, chat, since }) => {
|
|
219
|
-
const group = await client.chats.show(chat);
|
|
220
|
-
const saved = new ModerationRules(moderationPathFor(profile)).read(group.id);
|
|
221
|
-
const rules = saved ?? defaultRules(group.title);
|
|
222
|
-
const point = points.read(group.id);
|
|
223
|
-
const from = since ?? (point === undefined ? Date.now() - FIRST_LOOK_MS : Date.parse(point));
|
|
224
|
-
const found = await gather(client, group.id, from);
|
|
225
|
-
return {
|
|
226
|
-
chatId: group.id,
|
|
227
|
-
title: group.title,
|
|
228
|
-
rules,
|
|
229
|
-
found,
|
|
230
|
-
findings: judge({ ...found, rules, now: Date.now() }),
|
|
231
|
-
explicit: since !== undefined,
|
|
232
|
-
notes: [
|
|
233
|
-
...(saved ? [] : [`${group.title ?? group.id} has no rules yet — the defaults only report`]),
|
|
234
|
-
...found.notes,
|
|
235
|
-
],
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
/** Acts on what `prepare` found, moves the group's saved point, and says what is left. */
|
|
239
|
-
export const finish = async (moderator, points, prepared, options) => {
|
|
240
|
-
const { chatId, rules, found, findings, explicit } = prepared;
|
|
241
|
-
const rows = await act(moderator, findings, { ...options, chatId, rules });
|
|
242
|
-
const notes = [...prepared.notes];
|
|
243
|
-
const next = nextPoint(rows, found);
|
|
244
|
-
if (!explicit && !options.dryRun && next !== null) {
|
|
245
|
-
points.write(chatId, next);
|
|
246
|
-
}
|
|
247
|
-
if (next !== found.until && rows.some(undone)) {
|
|
248
|
-
notes.push("some actions are not done — the next check starts at the first of them");
|
|
249
|
-
}
|
|
250
|
-
else if (found.more) {
|
|
251
|
-
notes.push("more history than one check reads — the next check goes on from here");
|
|
252
|
-
}
|
|
253
|
-
return { rows, notes };
|
|
254
|
-
};
|
|
255
|
-
const undone = (row) => ["planned", "skipped", "failed"].includes(row.outcome);
|
|
256
|
-
/**
|
|
257
|
-
* Where the next check starts: after the newest message read, or just before the first message whose
|
|
258
|
-
* action is still undone — so it is judged again, and what came after it is still read. A person
|
|
259
|
-
* who joined and is still undone keeps the point where it was, since the join is not a row's message.
|
|
260
|
-
*/
|
|
261
|
-
const nextPoint = (rows, found) => {
|
|
262
|
-
const waiting = rows.filter(undone);
|
|
263
|
-
if (waiting.some((row) => row.messageId === undefined))
|
|
264
|
-
return null;
|
|
265
|
-
const times = waiting
|
|
266
|
-
.map((row) => found.messages.find((message) => message.id === row.messageId)?.timestamp)
|
|
267
|
-
.filter((time) => time !== undefined)
|
|
268
|
-
.map(Date.parse);
|
|
269
|
-
if (times.length === 0)
|
|
270
|
-
return found.until;
|
|
271
|
-
return new Date(Math.min(...times) - 1).toISOString();
|
|
272
|
-
};
|
|
273
|
-
//# sourceMappingURL=check.js.map
|