shadok-ai 0.20.16 → 0.20.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -3
- package/dist/server.js +57 -11
- package/dist/server.js.map +1 -1
- package/dist/tg-guests.d.ts +1 -1
- package/dist/tg-guests.js +20 -0
- package/dist/tg-guests.js.map +1 -1
- package/dist/wa-baileys.d.ts +3 -3
- package/dist/wa-baileys.js +68 -7
- package/dist/wa-baileys.js.map +1 -1
- package/dist/wa-bridge.d.ts +24 -1
- package/dist/wa-bridge.js +391 -41
- package/dist/wa-bridge.js.map +1 -1
- package/dist/wa-fake.d.ts +9 -0
- package/dist/wa-fake.js +17 -0
- package/dist/wa-fake.js.map +1 -1
- package/dist/wa-format.d.ts +54 -0
- package/dist/wa-format.js +87 -1
- package/dist/wa-format.js.map +1 -1
- package/dist/wa-guests.d.ts +38 -0
- package/dist/wa-guests.js +24 -3
- package/dist/wa-guests.js.map +1 -1
- package/dist/wa-inbox.d.ts +10 -0
- package/dist/wa-inbox.js.map +1 -1
- package/dist/wa-transport.d.ts +13 -0
- package/dist/wa-transport.js.map +1 -1
- package/dist/wa-worker-host.js +8 -0
- package/dist/wa-worker-host.js.map +1 -1
- package/dist/wa-worker.js +5 -1
- package/dist/wa-worker.js.map +1 -1
- package/dist/whatsapp.d.ts +3 -1
- package/dist/whatsapp.js +6 -0
- package/dist/whatsapp.js.map +1 -1
- package/package.json +1 -1
- package/public/index.html +24 -14
package/README.md
CHANGED
|
@@ -967,9 +967,24 @@ from the phone's *Linked devices* list too.
|
|
|
967
967
|
being started, or while the server was updating, is answered once it is back.
|
|
968
968
|
- **Closing a guest's agent in the cockpit** ends that conversation: their next
|
|
969
969
|
message starts a new agent. A link that drops ends nothing.
|
|
970
|
-
- **
|
|
971
|
-
|
|
972
|
-
|
|
970
|
+
- **Pictures, documents, voice notes and videos** reach the person's agent the
|
|
971
|
+
way Telegram attachments do (a voice note is transcribed, and what was
|
|
972
|
+
understood is echoed back to the person; a video is looked at through a few
|
|
973
|
+
stills). Up to **50 MB** per file; a larger one gets a line asking for a
|
|
974
|
+
smaller file or a link.
|
|
975
|
+
- **Files the agent hands over** reach the person as a picture or a document.
|
|
976
|
+
Pictures go out without WhatsApp's blurred preview thumbnail, because the
|
|
977
|
+
WhatsApp library is installed without an image-processing library; the
|
|
978
|
+
picture itself is intact.
|
|
979
|
+
- **Questions** the agent asks arrive as a numbered list: the person answers
|
|
980
|
+
with the number (several numbers for a multiple choice), or with their own
|
|
981
|
+
words where the question offers that.
|
|
982
|
+
- **A first message that arrives unreadable** (WhatsApp sometimes delivers the
|
|
983
|
+
first messages from a new sender before they are readable by a linked
|
|
984
|
+
device) gets one line asking the person to send it again — at most once
|
|
985
|
+
every ten minutes, never with the door shut.
|
|
986
|
+
- **Closing a guest's agent** tells the person, once, that their next message
|
|
987
|
+
starts a new conversation.
|
|
973
988
|
- The panel always shows the link's true state, one at a time: *Not linked*,
|
|
974
989
|
*Linking*, *Connected*, *Reconnecting* (a link that stops answering leaves
|
|
975
990
|
*Connected* within about two minutes, even with no disconnect event),
|
|
@@ -1166,6 +1181,15 @@ know before opening it up:
|
|
|
1166
1181
|
the cockpit renews it — or 30 days after the sign-in at the latest), the open tab
|
|
1167
1182
|
returns you to the login screen on its next request instead of failing in
|
|
1168
1183
|
place — a paste that would not send, an agent list that would not refresh.
|
|
1184
|
+
- **Someone forgot their password.** An admin opens *reset password…* on that
|
|
1185
|
+
person's row in the **Users** panel and hands over the link it shows — valid
|
|
1186
|
+
48 hours, single use, and they choose the new password themselves, so the
|
|
1187
|
+
admin never types or sees it. Their open sessions stop working right away,
|
|
1188
|
+
including a stolen one. Nobody can reset themselves: ask another admin. The
|
|
1189
|
+
instance password (`admin`) is not an account and is not reset here — change
|
|
1190
|
+
`--password` / `SHADOK_GUI_PASSWORD` and restart. With **two-factor** on that
|
|
1191
|
+
same row reads *recover access…* and offers the three levels below, each
|
|
1192
|
+
confirmed with the acting admin's own passkey.
|
|
1169
1193
|
- **Two-factor sign-in (passkeys).** From the **Users** panel, anyone signed in
|
|
1170
1194
|
with a named account can register a passkey on their device — the
|
|
1171
1195
|
fingerprint / face / PIN unlock of the phone or laptop (WebAuthn, user
|
package/dist/server.js
CHANGED
|
@@ -1198,9 +1198,11 @@ function loginHtml(v) {
|
|
|
1198
1198
|
const e = escapeXml;
|
|
1199
1199
|
const accent = accentFor(v.theme);
|
|
1200
1200
|
const name = v.instance || "Shadok-AI";
|
|
1201
|
-
const heading = v.invite ?
|
|
1201
|
+
const heading = v.invite ? `${v.invite.reset ? "Hello again" : "Welcome"}, ${e(v.invite.name)}` : e(name);
|
|
1202
1202
|
const sub = v.invite
|
|
1203
|
-
?
|
|
1203
|
+
? v.invite.reset
|
|
1204
|
+
? "Choose a new password. The old one no longer works."
|
|
1205
|
+
: "Choose a password to join this cockpit."
|
|
1204
1206
|
: v.agent
|
|
1205
1207
|
? `Sign in to open <b>${e(v.agent)}</b>.`
|
|
1206
1208
|
: "Sign in to continue.";
|
|
@@ -1209,7 +1211,7 @@ function loginHtml(v) {
|
|
|
1209
1211
|
const pw = v.invite
|
|
1210
1212
|
? '<input id=pw type=password placeholder="Choose a password (8+ characters)" autofocus autocomplete=new-password>'
|
|
1211
1213
|
: '<input id=pw type=password placeholder="Password" autofocus autocomplete=current-password>';
|
|
1212
|
-
const title = v.invite ? `${e(name)} — choose a password` : `${e(name)} — sign in`;
|
|
1214
|
+
const title = v.invite ? `${e(name)} — ${v.invite.reset ? "new password" : "choose a password"}` : `${e(name)} — sign in`;
|
|
1213
1215
|
return `<!doctype html><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1">
|
|
1214
1216
|
<meta name=robots content="noindex,nofollow"><link rel=icon href="/icons/icon-192.png">
|
|
1215
1217
|
<title>${title}</title>${v.meta ? "\n" + v.meta : ""}
|
|
@@ -1329,8 +1331,8 @@ function sendLogin(req, res, agentId) {
|
|
|
1329
1331
|
/** The page an invited person lands on: the login shell, pointed at the
|
|
1330
1332
|
* redemption route. Same CSP and same nonce — a page that exempted itself from
|
|
1331
1333
|
* the policy protecting every other page would be a strange message. */
|
|
1332
|
-
function invitePage(name, token) {
|
|
1333
|
-
return loginHtml({ ...brandView(), invite: { name, token } });
|
|
1334
|
+
function invitePage(name, token, reset = false) {
|
|
1335
|
+
return loginHtml({ ...brandView(), invite: { name, token, reset } });
|
|
1334
1336
|
}
|
|
1335
1337
|
/** This server's same-origin guard (see `originAllowed`). */
|
|
1336
1338
|
/**
|
|
@@ -1736,7 +1738,8 @@ app.get("/invite/:token", (req, res) => {
|
|
|
1736
1738
|
const v = inviteVerdict(acct, token, Date.now());
|
|
1737
1739
|
if (!v.ok)
|
|
1738
1740
|
return res.status(400).type("text").send(v.error);
|
|
1739
|
-
|
|
1741
|
+
// A level-1 reset link wears the same form with a different sentence.
|
|
1742
|
+
return sendAuthPage(res, invitePage(acct.name, token, acct.invite?.reason === "password"), 200);
|
|
1740
1743
|
});
|
|
1741
1744
|
app.post("/invite/:token", async (req, res) => {
|
|
1742
1745
|
const token = String(req.params.token ?? "");
|
|
@@ -6822,7 +6825,8 @@ function askRequest(me, kind, target) {
|
|
|
6822
6825
|
* 2 lost passkey, password known: two admins, then a device code.
|
|
6823
6826
|
* 3 lost everything: a full reset, effective in 24 h or at a second admin's approval.
|
|
6824
6827
|
* With two-factor OFF, levels 2 and 3 have nothing to protect and act at once
|
|
6825
|
-
* (a device code / the v1 reset), like before
|
|
6828
|
+
* (a device code / the v1 reset), like before — and no level asks the issuing
|
|
6829
|
+
* admin for a passkey, since there are none to assert there.
|
|
6826
6830
|
*/
|
|
6827
6831
|
app.post("/2fa/recover", async (req, res) => {
|
|
6828
6832
|
const me = tfaPerson(req, res, true);
|
|
@@ -6835,7 +6839,26 @@ app.post("/2fa/recover", async (req, res) => {
|
|
|
6835
6839
|
const v = resetVerdict({ actor: me, target, accounts: loadAccounts() });
|
|
6836
6840
|
if (!v.ok)
|
|
6837
6841
|
return res.status(400).json({ error: v.error });
|
|
6838
|
-
|
|
6842
|
+
// A FRESH passkey, but only while two-factor is ON — `stepUpIfTwoFactor`, the
|
|
6843
|
+
// same gate as inviting or deleting an account.
|
|
6844
|
+
//
|
|
6845
|
+
// Unconditional, this route could not run at all on an instance with
|
|
6846
|
+
// two-factor off: nobody there HAS a passkey (registering one is what turning
|
|
6847
|
+
// it on requires, not the reverse), and the bootstrap admin — the instance
|
|
6848
|
+
// password, which is who an admin is until named accounts exist — cannot hold
|
|
6849
|
+
// one by construction (invariant 46). So every level answered "confirm with
|
|
6850
|
+
// your passkey first", and a lost password had no remedy short of editing the
|
|
6851
|
+
// account file by hand. The comment above this handler already described the
|
|
6852
|
+
// intent ("with two-factor OFF, levels 2 and 3 ... act at once"); the gate
|
|
6853
|
+
// contradicted it.
|
|
6854
|
+
//
|
|
6855
|
+
// What remains when it is off: an admin, signed in, from a same-origin
|
|
6856
|
+
// browser (`tfaPerson(req, res, true)`) — exactly the bar `DELETE /users`
|
|
6857
|
+
// clears, and that one destroys a private space irreversibly. The assertion
|
|
6858
|
+
// defends the SECOND FACTOR, so it is worth demanding only where there is one;
|
|
6859
|
+
// the routes that could undo it for someone (`/2fa/enabled`,
|
|
6860
|
+
// `/2fa/passkey/delete`, `/2fa/enroll-code`) keep it unconditionally.
|
|
6861
|
+
if (!(await stepUpIfTwoFactor(req, res, me)))
|
|
6839
6862
|
return;
|
|
6840
6863
|
const now = Date.now();
|
|
6841
6864
|
if (level === 1) {
|
|
@@ -7318,6 +7341,13 @@ function startWhatsAppHandle() {
|
|
|
7318
7341
|
channels: { load: loadChannels, upsert: upsertChannel },
|
|
7319
7342
|
inbox: openInbox(path.join(waFake ? `${stateDir}-fake` : stateDir, "inbox.json")),
|
|
7320
7343
|
sessionAlive: (id) => tmuxHasSession("sk-" + id),
|
|
7344
|
+
// Step 3: a received medium waits beside the inbox, then lands in the
|
|
7345
|
+
// agent's GROUP media directory; a file an agent hands over is read with
|
|
7346
|
+
// the agent's rights — both exactly Telegram's rules (invariant 60).
|
|
7347
|
+
stagingDir: path.join(waFake ? `${stateDir}-fake` : stateDir, "media"),
|
|
7348
|
+
mediaDirFor: mediaDirForSession,
|
|
7349
|
+
readAgentFile: readSessionFile,
|
|
7350
|
+
multiTenant: DEPLOYMENT_MODE === "multi-tenant",
|
|
7321
7351
|
});
|
|
7322
7352
|
}
|
|
7323
7353
|
// The boot breaker (src/whatsapp.ts) reads a resume cut short by the process
|
|
@@ -7364,6 +7394,7 @@ app.get("/whatsapp", async (req, res) => {
|
|
|
7364
7394
|
// the bridge's answers. Fake mode only: a real instance never echoes a
|
|
7365
7395
|
// guest's conversation through this route.
|
|
7366
7396
|
out.fakeSent = waFake.sent.slice(-20);
|
|
7397
|
+
out.fakeFiles = waFake.files.slice(-20);
|
|
7367
7398
|
}
|
|
7368
7399
|
res.json(out);
|
|
7369
7400
|
});
|
|
@@ -7470,7 +7501,22 @@ app.post("/whatsapp/fake/:action", (req, res) => {
|
|
|
7470
7501
|
const chat = str("chat");
|
|
7471
7502
|
if (!chat)
|
|
7472
7503
|
return res.status(400).json({ error: "chat is required" });
|
|
7473
|
-
|
|
7504
|
+
// A medium for the side instance: `media` = image | document | audio |
|
|
7505
|
+
// video (`voice: true` for a voice note), its bytes as base64 `data`.
|
|
7506
|
+
const kind = str("media");
|
|
7507
|
+
const media = kind === "image" || kind === "document" || kind === "audio" || kind === "video"
|
|
7508
|
+
? { kind: kind, ...(str("mime") ? { mime: str("mime") } : {}), ...(str("fileName") ? { fileName: str("fileName") } : {}), ...(b.voice === true ? { voice: true } : {}) }
|
|
7509
|
+
: undefined;
|
|
7510
|
+
waFake.script.deliver({
|
|
7511
|
+
chat,
|
|
7512
|
+
chatAlt: str("chatAlt"),
|
|
7513
|
+
text: str("text"),
|
|
7514
|
+
pushName: str("pushName"),
|
|
7515
|
+
id: str("id"),
|
|
7516
|
+
...(media ? { media } : {}),
|
|
7517
|
+
...(str("data") ? { mediaData: Buffer.from(str("data"), "base64") } : {}),
|
|
7518
|
+
...(b.unreadable === true ? { unreadable: true } : {}),
|
|
7519
|
+
});
|
|
7474
7520
|
}
|
|
7475
7521
|
else if (action === "mapLid") {
|
|
7476
7522
|
const pn = str("pn"), lid = str("lid");
|
|
@@ -8192,7 +8238,7 @@ async function readSessionFile(sessionId, p) {
|
|
|
8192
8238
|
if (!st?.isFile)
|
|
8193
8239
|
throw new Error("not a readable file");
|
|
8194
8240
|
if (st.size > MAX)
|
|
8195
|
-
throw new Error("file too large
|
|
8241
|
+
throw new Error("file too large to send (over 50 MB)");
|
|
8196
8242
|
const { cmd, argv } = readAsUserArgv(user, p);
|
|
8197
8243
|
return new Promise((resolve, reject) => execFile(cmd, argv, { encoding: "buffer", maxBuffer: MAX + 1, timeout: 60_000 }, (err, out) => err ? reject(new Error("could not read the file as the agent's user")) : resolve(out)));
|
|
8198
8244
|
}
|
|
@@ -8201,7 +8247,7 @@ async function readSessionFile(sessionId, p) {
|
|
|
8201
8247
|
throw new Error("not a readable file");
|
|
8202
8248
|
try {
|
|
8203
8249
|
if (opened.stat.size > MAX)
|
|
8204
|
-
throw new Error("file too large
|
|
8250
|
+
throw new Error("file too large to send (over 50 MB)");
|
|
8205
8251
|
const buf = Buffer.alloc(opened.stat.size);
|
|
8206
8252
|
let off = 0;
|
|
8207
8253
|
while (off < buf.length) {
|