From 9edee922be4b93268d720b210cbfb3df1294fc83 Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 12 Nov 2026 08:27:22 +0000 Subject: [PATCH] support bot: move changes to a separate pull request --- apps/simplex-support-bot/README.md | 67 +--- apps/simplex-support-bot/bot.test.ts | 187 ---------- apps/simplex-support-bot/package-lock.json | 348 ++++++++---------- apps/simplex-support-bot/package.json | 7 +- apps/simplex-support-bot/src/bot.ts | 61 +-- apps/simplex-support-bot/src/config.ts | 22 +- apps/simplex-support-bot/src/dryRun.ts | 129 ------- apps/simplex-support-bot/src/index.ts | 106 +----- .../test/__mocks__/simplex-chat-types.js | 3 +- plans/2026-09-12-support-bot-broadcast.md | 51 --- scripts/support-bot/.gitignore | 2 - scripts/support-bot/Dockerfile | 143 ------- scripts/support-bot/Dockerfile.dockerignore | 25 -- scripts/support-bot/compose.yml | 34 -- scripts/support-bot/config/.gitkeep | 0 15 files changed, 176 insertions(+), 1009 deletions(-) delete mode 100644 apps/simplex-support-bot/src/dryRun.ts delete mode 100644 plans/2026-09-12-support-bot-broadcast.md delete mode 100644 scripts/support-bot/.gitignore delete mode 100644 scripts/support-bot/Dockerfile delete mode 100644 scripts/support-bot/Dockerfile.dockerignore delete mode 100644 scripts/support-bot/compose.yml delete mode 100644 scripts/support-bot/config/.gitkeep diff --git a/apps/simplex-support-bot/README.md b/apps/simplex-support-bot/README.md index 8a9caa7b5f..d95aa5b59b 100644 --- a/apps/simplex-support-bot/README.md +++ b/apps/simplex-support-bot/README.md @@ -52,23 +52,12 @@ Run `npm start -- --help` for the auto-generated reference. Summary: | `--pg-conn` | postgres | yes | — | PostgreSQL connection string | | `--pg-schema` | postgres | no | `simplex_v1` | schema prefix used for bot tables | | `-a` / `--auto-add-team-members` | both | no | | comma-separated `ID:name` pairs (e.g. `1:Alice,2:Bob`) | -| `--broadcasters` | both | no | | comma-separated `ID:name` pairs of contacts allowed to use `/broadcast` in the team group | | `--timezone` | both | no | `UTC` | IANA zone for weekend detection | | `--complete-hours` | both | no | `3` | auto-complete chats after N hours idle (`0` disables) | | `--card-flush-seconds` | both | no | `300` | debounce card state writes | | `--context-file` | both | required with `GROK_API_KEY` | | text file with Grok system context | -| `--dry-run` | both | no | | check config, database and state, then exit | -| `--allow-migrations` | both | no | | with `--dry-run`: apply pending migrations instead of reporting them | | `-h` / `--help` | both | no | | show usage and exit | -## Broadcasts - -A contact listed in `--broadcasters` sends `/broadcast ` in the team group. The bot sends the text as a feed message to every customer group and every direct contact of the bot, replies that the broadcast is queued, and replies again when delivery completes or fails. The text after `/broadcast` may span several lines. - -A broadcaster must be a *contact* of the bot, not only a team group member: the bot authorises the sender by `memberContactId`. The bot DMs every team group member the contact id it knows them by; pass that id to `--broadcasters` and restart. - -Feeds are part of the core, so `/broadcast` needs a `libsimplex` and types built from this tree — no released version has them. See [Running against this tree](#running-against-this-tree). - ## Environment variables | Var | Purpose | @@ -76,65 +65,25 @@ Feeds are part of the core, so `/broadcast` needs a `libsimplex` and types built | `GROK_API_KEY` | xAI API key; enables Grok replies | | `SIMPLEX_LIBS_DIR` | directory with a local libsimplex build for the `--db` backend, instead of the downloaded one | | `SIMPLEX_ADDON_PATH` | locally built Node.js add-on (`simplex.node`), instead of the downloaded one | -| `NODE_OPTIONS` | `--max-old-space-size=8192` on a bot with many chats: single API responses outgrow the default heap | -## Running against this tree +## Local development against unreleased lib changes -The manifest points at the released `simplex-chat` and `@simplex-chat/types`, which is what a deployment installs. `scripts/support-bot/Dockerfile` builds both from this checkout instead, with the core; by hand: +This package depends on `simplex-chat` from npm. To test against an in-tree version: ```bash -scripts/desktop/build-lib-linux.sh # libsimplex, hours on a cold cabal store -libs=$(pwd)/apps/multiplatform/common/src/commonMain/cpp/desktop/libs/linux-$(uname -m) +# In packages/simplex-chat-nodejs +npm install && npm run build +npm link -(cd packages/simplex-chat-client/types/typescript && npm install && npx tsc) - -cd packages/simplex-chat-nodejs -npm install -npm install --no-save ../simplex-chat-client/types/typescript -npm run build - -cd ../../apps/simplex-support-bot -npm ci -npm install --no-save \ - ../../packages/simplex-chat-nodejs \ - ../../packages/simplex-chat-client/types/typescript -export SIMPLEX_LIBS_DIR=$libs +# In apps/simplex-support-bot +npm link simplex-chat export SIMPLEX_ADDON_PATH=../../packages/simplex-chat-nodejs/build/Release/simplex.node ``` -`rm -rf node_modules && npm ci` reverts. - -## Dry run - -`--dry-run` opens the database, checks what the next start would do, and exits — it never calls `startChat`, so nothing reaches the network, and migrations are reported rather than applied. - -```bash -npm start -- --dry-run --team-group "Support Team" --db postgres --pg-conn "postgres://user:pass@host/db" \ - --broadcasters 3:alice --context-file ./data/grok-context.yaml -``` - -``` -ok database postgres opened, schema up to date -ok active user: 1:Ask SimpleX Team -ok team group 1: Support Team -FAIL broadcaster 3:bob has display name "alice", the bot would exit -``` - -A pending migration stops it, since the checks need an open database and opening one can only upgrade or refuse: - -``` -FAIL database: 21 migration(s) pending, a real start would apply them: 20260507_relay_inactive_at, … -``` - -`--allow-migrations` lets it apply them first (`applied 21 migration(s): …`) and then run the remaining checks — which makes it a migration rehearsal, so point it at a restored copy unless you mean to migrate for real. The bot must be stopped either way; migrating under a running instance is what breaks things, and the upgrade is one-way. - -Lines are `ok`, `FAIL`, or `?`. A `?` means the check could not be made offline: `getChatPreviews` — the only chat query that works with the chat stopped — filters on `contacts.contact_used`, so a contact whose direct chat was never used is invisible here even though the bot finds it at startup. Those ids are reported, not failed. - -Exit code is 0 when no line is `FAIL`, 1 otherwise. It verifies the database connection, that no migration is pending, that the persisted team group and Grok user still exist (so neither would be recreated), that every `--broadcasters` / `--auto-add-team-members` id resolves to a contact with the expected display name, and that `--context-file` parses. +`npm unlink simplex-chat && npm install` reverts to the registry version. ## Troubleshooting - **`--pg-conn is required with --db postgres`** — pass a connection string, or use `--db sqlite`. - **`libpq5` errors at startup** — install `libpq5` on the host (`apt install libpq5` on Debian/Ubuntu). - **`ENOENT: no such file or directory, open './data/state.json'`** — the parent directory of `--state-file` must exist; `mkdir -p data` before starting. -- **`JavaScript heap out of memory`** — a response outgrew the default heap; restart with `NODE_OPTIONS=--max-old-space-size=8192`. diff --git a/apps/simplex-support-bot/bot.test.ts b/apps/simplex-support-bot/bot.test.ts index 8ff2b7cd75..a9785de1e3 100644 --- a/apps/simplex-support-bot/bot.test.ts +++ b/apps/simplex-support-bot/bot.test.ts @@ -8,7 +8,6 @@ import {CardManager} from "./src/cards.js" import {parseConfig} from "./src/config.js" import {GrokApiClient} from "./src/grok.js" import {loadGrokContext} from "./src/context.js" -import {dryRun} from "./src/dryRun.js" import {welcomeMessage, queueMessage, grokActivatedMessage, teamLockedMessage, teamAlreadyInvitedMessage} from "./src/messages.js" // Silence console output during tests @@ -158,14 +157,8 @@ class MockChatApi { } rawCmds: string[] = [] - feedItemIds: number[] = [] async sendChatCmd(cmd: string) { this.rawCmds.push(cmd) - if (cmd.startsWith("/feed ")) { - const itemId = nextItemId++ - this.feedItemIds.push(itemId) - return {type: "newChatItems", user: makeUser(MAIN_USER_ID), chatItems: [makeFeedAChatItem(itemId, {type: "sndNew"})]} - } return {type: "cmdOk"} } @@ -273,7 +266,6 @@ function makeConfig(overrides: Partial = {}) { {id: TEAM_MEMBER_1_ID, name: "Alice"}, {id: TEAM_MEMBER_2_ID, name: "Bob"}, ], - broadcasters: [{id: TEAM_MEMBER_1_ID, name: "Alice"}], groupLinks: "", timezone: "UTC", completeHours: 3, @@ -368,13 +360,6 @@ function makeDirectAChatItem(chatItem: any, contactId: number): any { } } -function makeFeedAChatItem(itemId: number, itemStatus: any): any { - return { - chatInfo: {type: "feed", feed: {feedId: 1, userId: MAIN_USER_ID}}, - chatItem: {chatDir: {type: "feedSnd"}, meta: {itemId, itemStatus}, content: {type: "sndMsgContent", msgContent: {type: "text", text: ""}}}, - } -} - // ─── Shared test state ─── let chat: MockChatApi @@ -1375,80 +1360,6 @@ describe("/join Command (Team Group)", () => { }) }) -describe("/broadcast Command (Team Group)", () => { - beforeEach(() => setup()) - - function statusEvent(itemId: number, itemStatus: any): any { - return { - type: "chatItemsStatusesUpdated" as const, - user: makeUser(MAIN_USER_ID), - chatItems: [makeFeedAChatItem(itemId, itemStatus)], - } - } - - test("/broadcast from broadcaster → /feed sent with JSON text, queued reply", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast hello everyone")) - expect(chat.rawCmds).toEqual(['/feed "hello everyone"']) - expectSentToGroup(TEAM_GROUP_ID, `Broadcast ${chat.feedItemIds[0]} queued`) - }) - - test("/broadcast keeps newlines and quotes", async () => { - await bot.onNewChatItems(teamGroupMessage('/broadcast line "one"\nline two')) - expect(chat.rawCmds).toEqual(['/feed "line \\"one\\"\\nline two"']) - }) - - test("/broadcast with extra spaces → text has no leading whitespace", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast hello")) - expect(chat.rawCmds).toEqual(['/feed "hello"']) - }) - - test("/broadcast on its own line → text starts after the newline", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast\nline one\nline two")) - expect(chat.rawCmds).toEqual(['/feed "line one\\nline two"']) - }) - - test("/broadcast from a non-broadcaster → error reply, nothing sent", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast hello", TEAM_MEMBER_2_ID)) - expect(chat.rawCmds.length).toBe(0) - expectSentToGroup(TEAM_GROUP_ID, `Error: contact ${TEAM_MEMBER_2_ID} is not allowed to broadcast`) - }) - - test("/broadcast without text → error reply, nothing sent", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast ")) - expect(chat.rawCmds.length).toBe(0) - expectSentToGroup(TEAM_GROUP_ID, "Error: broadcast text is empty") - }) - - test("customer sending /broadcast in customer group → treated as normal message", async () => { - await bot.onNewChatItems(customerMessage("/broadcast hello")) - expect(chat.rawCmds.length).toBe(0) - expectSentToGroup(CUSTOMER_GROUP_ID, "The team will reply to your message") - }) - - test("feed item complete → delivered reply once", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast hello")) - const itemId = chat.feedItemIds[0] - await bot.onChatItemsStatusesUpdated(statusEvent(itemId, {type: "sndSent", sndProgress: "partial"})) - expectNotSentToGroup(TEAM_GROUP_ID, "delivered") - await bot.onChatItemsStatusesUpdated(statusEvent(itemId, {type: "sndSent", sndProgress: "complete"})) - expectSentToGroup(TEAM_GROUP_ID, `Broadcast ${itemId} delivered to all chats`) - await bot.onChatItemsStatusesUpdated(statusEvent(itemId, {type: "sndSent", sndProgress: "complete"})) - expect(chat.sentTo(TEAM_GROUP_ID).filter(m => m.includes("delivered")).length).toBe(1) - }) - - test("feed item error → failure reply", async () => { - await bot.onNewChatItems(teamGroupMessage("/broadcast hello")) - const itemId = chat.feedItemIds[0] - await bot.onChatItemsStatusesUpdated(statusEvent(itemId, {type: "sndError", agentError: {type: "other", sndError: "boom"}})) - expectSentToGroup(TEAM_GROUP_ID, `Broadcast ${itemId} failed`) - }) - - test("status of an unknown feed item → ignored", async () => { - await bot.onChatItemsStatusesUpdated(statusEvent(4242, {type: "sndSent", sndProgress: "complete"})) - expect(chat.sentTo(TEAM_GROUP_ID).length).toBe(0) - }) -}) - describe("DM Handshake", () => { beforeEach(() => setup()) @@ -2541,22 +2452,6 @@ describe("parseConfig Validation", () => { expect(cfg.db).toEqual({type: "sqlite", filePrefix: "./data/simplex", encryptionKey: "secret"}) }) - test("--dry-run and --allow-migrations default to false and parse when given", () => { - const base = ["--team-group", "Team"] - expect(parseConfig(base).dryRun).toBe(false) - expect(parseConfig(base).allowMigrations).toBe(false) - const cfg = parseConfig([...base, "--dry-run", "--allow-migrations"]) - expect(cfg.dryRun).toBe(true) - expect(cfg.allowMigrations).toBe(true) - }) - - test("--broadcasters → parsed as ID:name pairs, empty when absent", () => { - expect(parseConfig(baseArgs).broadcasters).toEqual([]) - const cfg = parseConfig([...baseArgs, "--broadcasters", "3:Carol,4:Dave"]) - expect(cfg.broadcasters).toEqual([{id: 3, name: "Carol"}, {id: 4, name: "Dave"}]) - expect(() => parseConfig([...baseArgs, "--broadcasters", "Carol"])).toThrow(/Invalid ID:name format/) - }) - test("unknown flag → parseArgs throws", () => { expect(() => parseConfig([...baseArgs, "--team-gropu", "typo"])) .toThrow() @@ -2793,85 +2688,3 @@ describe("loadGrokContext", () => { expect(() => loadGrokContext(join(dir, "does-not-exist.yaml"))).toThrow() }) }) - -describe("Dry Run", () => { - const directChat = (contactId: number, displayName: string) => ({ - chatInfo: {type: "direct", contact: {contactId, profile: {displayName}}}, - }) - const groupChat = (groupId: number, displayName: string) => ({ - chatInfo: {type: "group", groupInfo: {groupId, groupProfile: {displayName}}}, - }) - - function mkChat(chats: unknown[], users: number[] = [1]) { - return { - apiGetActiveUser: async () => ({userId: 1, profile: {displayName: "Ask SimpleX Team"}}), - apiListUsers: async () => users.map(userId => ({user: {userId, profile: {displayName: `user${userId}`}}})), - apiGetChats: async (_userId: number, _pagination: unknown, query?: {type: string; search?: string}) => - query?.type === "search" - ? chats.filter((c: any) => - (c.chatInfo.contact?.profile.displayName ?? c.chatInfo.groupInfo?.groupProfile.displayName) === query.search) - : chats, - } as any - } - - const config = (over: object = {}) => - ({ - teamGroup: {id: 0, name: "Support Team"}, - teamMembers: [], - broadcasters: [], - contextFile: null, - ...over, - }) as any - - test("all ids resolve → passes", async () => { - const chat = mkChat([groupChat(1, "Support Team"), directChat(3, "alice")]) - const ok = await dryRun(chat, config({broadcasters: [{id: 3, name: "alice"}]}), {teamGroupId: 1}) - expect(ok).toBe(true) - }) - - test("missing team group → reports it would be created, still passes", async () => { - const chat = mkChat([]) - expect(await dryRun(chat, config(), {})).toBe(true) - }) - - // Absence is unverifiable with the chat stopped: getChatPreviews filters on - // contacts.contact_used, so these ids are reported, not failed. - test("team group id not in chat previews → reported, still passes", async () => { - const chat = mkChat([groupChat(7, "Support Team")]) - expect(await dryRun(chat, config(), {teamGroupId: 1})).toBe(true) - }) - - test("broadcaster id not in chat previews → reported, still passes", async () => { - const chat = mkChat([groupChat(1, "Support Team")]) - expect(await dryRun(chat, config({broadcasters: [{id: 3, name: "alice"}]}), {teamGroupId: 1})).toBe(true) - }) - - test("broadcaster name mismatch → fails even though the id exists", async () => { - const chat = mkChat([groupChat(1, "Support Team"), directChat(3, "alice")]) - expect(await dryRun(chat, config({broadcasters: [{id: 3, name: "bob"}]}), {teamGroupId: 1})).toBe(false) - }) - - test("persisted Grok user missing → fails", async () => { - const chat = mkChat([groupChat(1, "Support Team")], [1]) - expect(await dryRun(chat, config(), {teamGroupId: 1, grokUserId: 2})).toBe(false) - }) - - test("persisted Grok user present → passes", async () => { - const chat = mkChat([groupChat(1, "Support Team")], [1, 2]) - expect(await dryRun(chat, config(), {teamGroupId: 1, grokUserId: 2})).toBe(true) - }) - - test("malformed context file → fails", async () => { - const dir = mkdtempSync(join(tmpdir(), "support-bot-dryrun-")) - const path = join(dir, "ctx.yaml") - writeFileSync(path, "- role: user\n message: [unclosed\n") - const chat = mkChat([groupChat(1, "Support Team")]) - expect(await dryRun(chat, config({contextFile: path}), {teamGroupId: 1})).toBe(false) - }) - - test("missing context file → warning only, passes", async () => { - const chat = mkChat([groupChat(1, "Support Team")]) - const cfg = config({contextFile: join(tmpdir(), "no-such-context.txt")}) - expect(await dryRun(chat, cfg, {teamGroupId: 1})).toBe(true) - }) -}) diff --git a/apps/simplex-support-bot/package-lock.json b/apps/simplex-support-bot/package-lock.json index 3934bd45c6..eddbcb2dff 100644 --- a/apps/simplex-support-bot/package-lock.json +++ b/apps/simplex-support-bot/package-lock.json @@ -9,10 +9,10 @@ "version": "0.1.0", "license": "AGPL-3.0", "dependencies": { - "@simplex-chat/types": "^0.11.2", + "@simplex-chat/types": "^0.6.0", "async-mutex": "^0.5.0", "commander": "^14.0.3", - "simplex-chat": "^7.1.0-beta.2", + "simplex-chat": "^6.5.1", "yaml": "^2.8.4" }, "devDependencies": { @@ -426,36 +426,16 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", - "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", "dev": true, "license": "MIT" }, - "node_modules/@napi-rs/lzma-linux-x64-gnu": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-x64-gnu/-/lzma-linux-x64-gnu-1.5.1.tgz", - "integrity": "sha512-oTXEIha4SsuXdTA4Iyskj0kpdx2yVXdhd75c2v3xGrHFfVMsbhTPZU/nMPL4sWKo4pBHm3aucLaqGlF696dTyQ==", - "cpu": [ - "x64" - ], - "dev": true, - "libc": [ - "glibc" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": "^22.20 || ^24.12 || >=25" - } - }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.63.2.tgz", - "integrity": "sha512-Xa6RDoWa+hNiX6PgsljlH6W75RaONx3y6PVlbLhkEWW+GaPQ3dP5gwbL/erAzQHWwkvW5UxdD5l87Qx2FAQ/4A==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.60.2.tgz", + "integrity": "sha512-dnlp69efPPg6Uaw2dVqzWRfAWRnYVb1XJ8CyyhIbZeaq4CA5/mLeZ1IEt9QqQxmbdvagjLIm2ZL8BxXv5lH4Yw==", "cpu": [ "arm" ], @@ -467,9 +447,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.63.2.tgz", - "integrity": "sha512-vNASxsghMfQ5s+v3PrpnJd+ryL/26lxCCaGI+sDJ7VzmHiYXIrrVltsDhaawxLM1WcoMU2oYlbPHLaYQtBzhcg==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.60.2.tgz", + "integrity": "sha512-OqZTwDRDchGRHHm/hwLOL7uVPB9aUvI0am/eQuWMNyFHf5PSEQmyEeYYheA0EPPKUO/l0uigCp+iaTjoLjVoHg==", "cpu": [ "arm64" ], @@ -481,9 +461,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.63.2.tgz", - "integrity": "sha512-0dWDjmlrpZAgjPD/aPzUDhBW8APLRjAni5bOrM76wiiZm+E+KTMVKNhAzaTBohz8UyO2fKNAl0+fygbe2HZXOA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.60.2.tgz", + "integrity": "sha512-UwRE7CGpvSVEQS8gUMBe1uADWjNnVgP3Iusyda1nSRwNDCsRjnGc7w6El6WLQsXmZTbLZx9cecegumcitNfpmA==", "cpu": [ "arm64" ], @@ -495,9 +475,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.63.2.tgz", - "integrity": "sha512-N58uktcwzk3+qT4KHEuNdIxX1N01RWrkfVoml69EAbSaNDL+sbNVLx2RMl4Qd23lpA0fgPvyh5hHb4weD5WKmg==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.60.2.tgz", + "integrity": "sha512-gjEtURKLCC5VXm1I+2i1u9OhxFsKAQJKTVB8WvDAHF+oZlq0GTVFOlTlO1q3AlCTE/DF32c16ESvfgqR7343/g==", "cpu": [ "x64" ], @@ -509,9 +489,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.63.2.tgz", - "integrity": "sha512-HWF2zH8EAp2scWRpt2PGe6iUGz7zi04waXsdRr3zb4DWCk2ImIo5FZu0jjmD53nP/DGSvnW0e7/1ToCNZs2lZw==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.60.2.tgz", + "integrity": "sha512-Bcl6CYDeAgE70cqZaMojOi/eK63h5Me97ZqAQoh77VPjMysA/4ORQBRGo3rRy45x4MzVlU9uZxs8Uwy7ZaKnBw==", "cpu": [ "arm64" ], @@ -523,9 +503,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.63.2.tgz", - "integrity": "sha512-MkvcwHMnzPSMOQEwB6wHnLzmc+hT8BGc5bW/Mhmjjgx3wbj6VBnlc47XsK74kD0K9MikFfXpQqyz4NUXaUW62A==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.60.2.tgz", + "integrity": "sha512-LU+TPda3mAE2QB0/Hp5VyeKJivpC6+tlOXd1VMoXV/YFMvk/MNk5iXeBfB4MQGRWyOYVJ01625vjkr0Az98OJQ==", "cpu": [ "x64" ], @@ -537,16 +517,13 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.63.2.tgz", - "integrity": "sha512-xe1bCKPJaKsD0tfd7Rb6bGfUogJTpKbTEEthsfdb7hTfTRNJVQTdirabQx0o6ERVba/smkM720soMY+0QnrlSQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.60.2.tgz", + "integrity": "sha512-2QxQrM+KQ7DAW4o22j+XZ6RKdxjLD7BOWTP0Bv0tmjdyhXSsr2Ul1oJDQqh9Zf5qOwTuTc7Ek83mOFaKnodPjg==", "cpu": [ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -554,16 +531,13 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.63.2.tgz", - "integrity": "sha512-yOM7LdK0p6gk6+Q773OEwtlsikT1TL3yMmYsTtRlDRPha5vV2DC5x7LqRWDr6f3cSYNMKVqxzffXv8ivxNBIFQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.60.2.tgz", + "integrity": "sha512-TbziEu2DVsTEOPif2mKWkMeDMLoYjx95oESa9fkQQK7r/Orta0gnkcDpzwufEcAO2BLBsD7mZkXGFqEdMRRwfw==", "cpu": [ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -571,16 +545,13 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.63.2.tgz", - "integrity": "sha512-qiWuJJV3DybA2IfzvRimeKXGrGuVPv1zobSY/26KnP3HbV0VcNb3ECzgvtbvF3xjSMkcooou6HASXZuLdjnhpQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.60.2.tgz", + "integrity": "sha512-bO/rVDiDUuM2YfuCUwZ1t1cP+/yqjqz+Xf2VtkdppefuOFS2OSeAfgafaHNkFn0t02hEyXngZkxtGqXcXwO8Rg==", "cpu": [ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -588,16 +559,13 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.63.2.tgz", - "integrity": "sha512-akcZquRzCY/KpUoZAMBhGf7oi4LmXq1BzRA5CPAC3rkUf28Y/sAYV3jSL+JKd7cwEyFvR5G0XVZ0gaMedP+60A==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.60.2.tgz", + "integrity": "sha512-hr26p7e93Rl0Za+JwW7EAnwAvKkehh12BU1Llm9Ykiibg4uIr2rbpxG9WCf56GuvidlTG9KiiQT/TXT1yAWxTA==", "cpu": [ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -605,16 +573,13 @@ ] }, "node_modules/@rollup/rollup-linux-loong64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.63.2.tgz", - "integrity": "sha512-fNwYHrPyYyxauPzX/cpYw8Z7LQpp+DGA0KCoswA0aVFBpmdMil9XgjB8V3Ny64Ihu797+GKcuJqnsOKEmor7fA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.60.2.tgz", + "integrity": "sha512-pOjB/uSIyDt+ow3k/RcLvUAOGpysT2phDn7TTUB3n75SlIgZzM6NKAqlErPhoFU+npgY3/n+2HYIQVbF70P9/A==", "cpu": [ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -622,16 +587,13 @@ ] }, "node_modules/@rollup/rollup-linux-loong64-musl": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.63.2.tgz", - "integrity": "sha512-XfvsgzR7DZqREdst7K1Mj3ilSUM5xLAHJcIMDFPKdxTs9q5VHOT8aMA+a683fqBu7DQl8+Sd9HCsQYL8EMY9qA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.60.2.tgz", + "integrity": "sha512-2/w+q8jszv9Ww1c+6uJT3OwqhdmGP2/4T17cu8WuwyUuuaCDDJ2ojdyYwZzCxx0GcsZBhzi3HmH+J5pZNXnd+Q==", "cpu": [ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -639,16 +601,13 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.63.2.tgz", - "integrity": "sha512-Pp7gVZggEFlbcuztay+/U0gVG9S1XAh8i7I1Re/htbAzo43P5wHZHw6pTyzotISqlKohoh9RpIfnOz3RbemK1w==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.60.2.tgz", + "integrity": "sha512-11+aL5vKheYgczxtPVVRhdptAM2H7fcDR5Gw4/bTcteuZBlH4oP9f5s9zYO9aGZvoGeBpqXI/9TZZihZ609wKw==", "cpu": [ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -656,16 +615,13 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-musl": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.63.2.tgz", - "integrity": "sha512-zkgL2xff6i7u5hau/m6FGeS8gRkLEdgLw522WGmdWWlLd9btmNl3S80mcEjtGq+kvgUekQ3+BOYLLLcPlS2LIA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.60.2.tgz", + "integrity": "sha512-i16fokAGK46IVZuV8LIIwMdtqhin9hfYkCh8pf8iC3QU3LpwL+1FSFGej+O7l3E/AoknL6Dclh2oTdnRMpTzFQ==", "cpu": [ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -673,16 +629,13 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.63.2.tgz", - "integrity": "sha512-qOheJomrkVCbbHFJ7L3J97cnhfogKqguAQphv26+3ZsAQIF1L19b+dArl//s8rjJHJLz9byykyM8NBP4nmSa1g==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.60.2.tgz", + "integrity": "sha512-49FkKS6RGQoriDSK/6E2GkAsAuU5kETFCh7pG4yD/ylj9rKhTmO3elsnmBvRD4PgJPds5W2PkhC82aVwmUcJ7A==", "cpu": [ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -690,16 +643,13 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-musl": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.63.2.tgz", - "integrity": "sha512-XlxLD54wQhH3FciCgMofxBw27NzUe818gJH410qWvc41UT0ZFcgxVjyX5/EK8MPTupjeVWqN5oy+9pCA9mqfCA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.60.2.tgz", + "integrity": "sha512-mjYNkHPfGpUR00DuM1ZZIgs64Hpf4bWcz9Z41+4Q+pgDx73UwWdAYyf6EG/lRFldmdHHzgrYyge5akFUW0D3mQ==", "cpu": [ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -707,16 +657,13 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.63.2.tgz", - "integrity": "sha512-vdryWeRb2bLJZf0Fv/W8se6nvsHe2PkTCxV0meheK3nQE+G90VCJcke51Miy1yQRsfm2uqIyjXOu4wmUzbTtkQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.60.2.tgz", + "integrity": "sha512-ALyvJz965BQk8E9Al/JDKKDLH2kfKFLTGMlgkAbbYtZuJt9LU8DW3ZoDMCtQpXAltZxwBHevXz5u+gf0yA0YoA==", "cpu": [ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -724,16 +671,13 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.63.2.tgz", - "integrity": "sha512-bcq2h2pkKmH2po4cZV8VWzO4lL40STyu/nLoFpYMQp9C2tCVNTdcVv86MwSsn3D5s1FBe2Ty1atqvVAUTMimNg==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.60.2.tgz", + "integrity": "sha512-UQjrkIdWrKI626Du8lCQ6MJp/6V1LAo2bOK9OTu4mSn8GGXIkPXk/Vsp4bLHCd9Z9Iz2OTEaokUE90VweJgIYQ==", "cpu": [ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -741,16 +685,13 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.63.2.tgz", - "integrity": "sha512-EGoo5DMVMRkTId8fuTDaoxVlR5ZTsKULUezRjd9gCw5eeY+DjCvDpZAOlNUvKPGX+7rS1RWx6j+yOpNPx0cUgQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.60.2.tgz", + "integrity": "sha512-bTsRGj6VlSdn/XD4CGyzMnzaBs9bsRxy79eTqTCBsA8TMIEky7qg48aPkvJvFe1HyzQ5oMZdg7AnVlWQSKLTnw==", "cpu": [ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -758,9 +699,9 @@ ] }, "node_modules/@rollup/rollup-openbsd-x64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.63.2.tgz", - "integrity": "sha512-MErl12k7BFHZG1TI9QF/3lSSZARzq9KgNy/FjnqFMCkv+N4RSSzoUCA5h2mqHX4Mox3WaTVKblyzhQ1zRb2ZuQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.60.2.tgz", + "integrity": "sha512-6d4Z3534xitaA1FcMWP7mQPq5zGwBmGbhphh2DwaA1aNIXUu3KTOfwrWpbwI4/Gr0uANo7NTtaykFyO2hPuFLg==", "cpu": [ "x64" ], @@ -772,9 +713,9 @@ ] }, "node_modules/@rollup/rollup-openharmony-arm64": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.63.2.tgz", - "integrity": "sha512-ILs8k07Wh4p0PsNY4wYLEaXZKMOpVhrG5QDB0yHhGhuzOfDlnyHN6sflL4El/MpUP1y8uY2lUZrv4oBS6pTT3g==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.60.2.tgz", + "integrity": "sha512-NetAg5iO2uN7eB8zE5qrZ3CSil+7IJt4WDFLcC75Ymywq1VZVD6qJ6EvNLjZ3rEm6gB7XW5JdT60c6MN35Z85Q==", "cpu": [ "arm64" ], @@ -786,9 +727,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.63.2.tgz", - "integrity": "sha512-hKgB3nz/TKD3Wv78XEsyXzQsNjvhOHmwKQTvXADGOyU/cIClZDO7DsoggbdmJDPGp5V80tA3Vfv61PaKTLH3LA==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.60.2.tgz", + "integrity": "sha512-NCYhOotpgWZ5kdxCZsv6Iudx0wX8980Q/oW4pNFNihpBKsDbEA1zpkfxJGC0yugsUuyDZ7gL37dbzwhR0VI7pQ==", "cpu": [ "arm64" ], @@ -800,9 +741,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.63.2.tgz", - "integrity": "sha512-T4wf1mudIDxN8Q/CWIBJC1u5gQUc+r5mPvlwoSbIvNkyVTP2TAFeobEmst5AQ4gMyAz4sSByVdoTDfvTmGK/8g==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.60.2.tgz", + "integrity": "sha512-RXsaOqXxfoUBQoOgvmmijVxJnW2IGB0eoMO7F8FAjaj0UTywUO/luSqimWBJn04WNgUkeNhh7fs7pESXajWmkg==", "cpu": [ "ia32" ], @@ -814,9 +755,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-gnu": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.63.2.tgz", - "integrity": "sha512-tC3IY7qoaD9Ll3/8WJQn49j5V2f/NuI9S41NOE2iM5MPs3sPIvOkVToLcz/7Bz4pyF7PSvrtwu8I/pUrGOSecQ==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.60.2.tgz", + "integrity": "sha512-qdAzEULD+/hzObedtmV6iBpdL5TIbKVztGiK7O3/KYSf+HIzU257+MX1EXJcyIiDbMAqmbwaufcYPvyRryeZtA==", "cpu": [ "x64" ], @@ -828,9 +769,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.63.2.tgz", - "integrity": "sha512-6NHnk/K3eq2ZFYcU1X8g67s9qIJRCOTT92gwLMVBp08dB2uuuwI1/Q/empzL2Bfr2f2WRLJVwpp90RmacQyFkw==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.60.2.tgz", + "integrity": "sha512-Nd/SgG27WoA9e+/TdK74KnHz852TLa94ovOYySo/yMPuTmpckK/jIF2jSwS3g7ELSKXK13/cVdmg1Z/DaCWKxA==", "cpu": [ "x64" ], @@ -842,32 +783,32 @@ ] }, "node_modules/@simplex-chat/types": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/@simplex-chat/types/-/types-0.11.2.tgz", - "integrity": "sha512-xn7YmNHf9prPYTOn9hAEHMsxRmjbroVOHISp4Y+6JwsS1fg+goEUEZtZYoFTsJ6eH3H7BbjdVpAGevJ7C9w2Uw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@simplex-chat/types/-/types-0.6.0.tgz", + "integrity": "sha512-QVYvaRsS6TnS+IROjNkekZYvhvy8QoA8vKCuGe9E6lplXDVutJo9tdDOSWS9NDdtwxT1wRZ29zN4xEZEEG/NHw==", "license": "AGPL-3.0", "dependencies": { "typescript": "^5.9.2" } }, "node_modules/@sinclair/typebox": { - "version": "0.27.12", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz", - "integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==", + "version": "0.27.10", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.10.tgz", + "integrity": "sha512-MTBk/3jGLNB2tVxv6uLlFh1iu64iYOQ2PbdOSK3NW8JZsmlaOh2q6sdtKowBhfw8QFLmYNzTW4/oK4uATIi6ZA==", "dev": true, "license": "MIT" }, "node_modules/@types/estree": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", - "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "dev": true, "license": "MIT" }, "node_modules/@types/node": { - "version": "22.20.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.2.tgz", - "integrity": "sha512-xlvWf4Vs9n1PEVYwP1n4vvG07M6y8WgvJ2t0vbrWTmijsIHp1cS+uJ2kMIRdY3nHZK0nCYKrPeD171+SzF4/zw==", + "version": "22.19.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.17.tgz", + "integrity": "sha512-wGdMcf+vPYM6jikpS/qhg6WiqSV/OhG+jeeHT/KlVqxYfD40iYJf9/AE1uQxVWFvU7MipKRkRv8NSHiCGgPr8Q==", "devOptional": true, "license": "MIT", "dependencies": { @@ -959,9 +900,9 @@ } }, "node_modules/acorn": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz", - "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", "bin": { @@ -1429,9 +1370,9 @@ "license": "MIT" }, "node_modules/nanoid": { - "version": "3.3.19", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.19.tgz", - "integrity": "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==", + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", + "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", "dev": true, "funding": [ { @@ -1448,9 +1389,9 @@ } }, "node_modules/node-addon-api": { - "version": "8.9.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.9.2.tgz", - "integrity": "sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.7.0.tgz", + "integrity": "sha512-9MdFxmkKaOYVTV+XVRG8ArDwwQ77XIgIPyKASB1k3JPq3M8fGQQQE3YpMOrKm6g//Ktx8ivZr8xo1Qmtqub+GA==", "license": "MIT", "engines": { "node": "^18 || ^20 || >= 21" @@ -1586,9 +1527,9 @@ "license": "MIT" }, "node_modules/postcss": { - "version": "8.5.28", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.28.tgz", - "integrity": "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==", + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.10.tgz", + "integrity": "sha512-pMMHxBOZKFU6HgAZ4eyGnwXF/EvPGGqUr0MnZ5+99485wwW41kW91A4LOGxSHhgugZmSChL5AlElNdwlNgcnLQ==", "dev": true, "funding": [ { @@ -1606,7 +1547,7 @@ ], "license": "MIT", "dependencies": { - "nanoid": "^3.3.18", + "nanoid": "^3.3.11", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" }, @@ -1647,13 +1588,13 @@ "license": "MIT" }, "node_modules/rollup": { - "version": "4.63.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.63.2.tgz", - "integrity": "sha512-l5eyksV4tPBj6lJyEa37YzIOCSOV7lkZzEHUdpjWZbtD7wTcFYmEYXSgm5bT4vV+dZLb9rBG1W9GROOG4NS4Ew==", + "version": "4.60.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.60.2.tgz", + "integrity": "sha512-J9qZyW++QK/09NyN/zeO0dG/1GdGfyp9lV8ajHnRVLfo/uFsbji5mHnDgn/qYdUHyCkM2N+8VyspgZclfAh0eQ==", "dev": true, "license": "MIT", "dependencies": { - "@types/estree": "1.0.9" + "@types/estree": "1.0.8" }, "bin": { "rollup": "dist/bin/rollup" @@ -1663,32 +1604,31 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@napi-rs/lzma-linux-x64-gnu": "1.5.1", - "@rollup/rollup-android-arm-eabi": "4.63.2", - "@rollup/rollup-android-arm64": "4.63.2", - "@rollup/rollup-darwin-arm64": "4.63.2", - "@rollup/rollup-darwin-x64": "4.63.2", - "@rollup/rollup-freebsd-arm64": "4.63.2", - "@rollup/rollup-freebsd-x64": "4.63.2", - "@rollup/rollup-linux-arm-gnueabihf": "4.63.2", - "@rollup/rollup-linux-arm-musleabihf": "4.63.2", - "@rollup/rollup-linux-arm64-gnu": "4.63.2", - "@rollup/rollup-linux-arm64-musl": "4.63.2", - "@rollup/rollup-linux-loong64-gnu": "4.63.2", - "@rollup/rollup-linux-loong64-musl": "4.63.2", - "@rollup/rollup-linux-ppc64-gnu": "4.63.2", - "@rollup/rollup-linux-ppc64-musl": "4.63.2", - "@rollup/rollup-linux-riscv64-gnu": "4.63.2", - "@rollup/rollup-linux-riscv64-musl": "4.63.2", - "@rollup/rollup-linux-s390x-gnu": "4.63.2", - "@rollup/rollup-linux-x64-gnu": "4.63.2", - "@rollup/rollup-linux-x64-musl": "4.63.2", - "@rollup/rollup-openbsd-x64": "4.63.2", - "@rollup/rollup-openharmony-arm64": "4.63.2", - "@rollup/rollup-win32-arm64-msvc": "4.63.2", - "@rollup/rollup-win32-ia32-msvc": "4.63.2", - "@rollup/rollup-win32-x64-gnu": "4.63.2", - "@rollup/rollup-win32-x64-msvc": "4.63.2", + "@rollup/rollup-android-arm-eabi": "4.60.2", + "@rollup/rollup-android-arm64": "4.60.2", + "@rollup/rollup-darwin-arm64": "4.60.2", + "@rollup/rollup-darwin-x64": "4.60.2", + "@rollup/rollup-freebsd-arm64": "4.60.2", + "@rollup/rollup-freebsd-x64": "4.60.2", + "@rollup/rollup-linux-arm-gnueabihf": "4.60.2", + "@rollup/rollup-linux-arm-musleabihf": "4.60.2", + "@rollup/rollup-linux-arm64-gnu": "4.60.2", + "@rollup/rollup-linux-arm64-musl": "4.60.2", + "@rollup/rollup-linux-loong64-gnu": "4.60.2", + "@rollup/rollup-linux-loong64-musl": "4.60.2", + "@rollup/rollup-linux-ppc64-gnu": "4.60.2", + "@rollup/rollup-linux-ppc64-musl": "4.60.2", + "@rollup/rollup-linux-riscv64-gnu": "4.60.2", + "@rollup/rollup-linux-riscv64-musl": "4.60.2", + "@rollup/rollup-linux-s390x-gnu": "4.60.2", + "@rollup/rollup-linux-x64-gnu": "4.60.2", + "@rollup/rollup-linux-x64-musl": "4.60.2", + "@rollup/rollup-openbsd-x64": "4.60.2", + "@rollup/rollup-openharmony-arm64": "4.60.2", + "@rollup/rollup-win32-arm64-msvc": "4.60.2", + "@rollup/rollup-win32-ia32-msvc": "4.60.2", + "@rollup/rollup-win32-x64-gnu": "4.60.2", + "@rollup/rollup-win32-x64-msvc": "4.60.2", "fsevents": "~2.3.2" } }, @@ -1736,13 +1676,13 @@ } }, "node_modules/simplex-chat": { - "version": "7.1.0-beta.2", - "resolved": "https://registry.npmjs.org/simplex-chat/-/simplex-chat-7.1.0-beta.2.tgz", - "integrity": "sha512-vJzZNck+pgK0IL5jMc8fTibkOrCYZmo7rcYEQBibpGjbH9STwRw2lZxJxn/OvBsTWPskGxZR7QIjrvOFSGQWCw==", + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/simplex-chat/-/simplex-chat-6.5.1.tgz", + "integrity": "sha512-1cv91iMCqtP+9R1PQM3NKazocoUInKT2/06pIOuzORD5/VzulR6cMZnEQmaT02Jz+8FVkEKTsaAIJfVP6/tJmw==", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { - "@simplex-chat/types": "^0.11.2", + "@simplex-chat/types": "^0.6.0", "extract-zip": "^2.0.1", "fast-deep-equal": "^3.1.3", "node-addon-api": "^8.5.0" @@ -1855,9 +1795,9 @@ } }, "node_modules/ufo": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", - "integrity": "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.3.tgz", + "integrity": "sha512-yDJTmhydvl5lJzBmy/hyOAA0d+aqCBuwl818haVdYCRrWV84o7YyeVm4QlVHStqNrrJSTb6jKuFAVqAFsr+K3Q==", "dev": true, "license": "MIT" }, @@ -2057,9 +1997,9 @@ "license": "ISC" }, "node_modules/yaml": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", - "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.4.tgz", + "integrity": "sha512-ml/JPOj9fOQK8RNnWojA67GbZ0ApXAUlN2UQclwv2eVgTgn7O9gg9o7paZWKMp4g0H3nTLtS9LVzhkpOFIKzog==", "license": "ISC", "bin": { "yaml": "bin.mjs" diff --git a/apps/simplex-support-bot/package.json b/apps/simplex-support-bot/package.json index 54de9c3429..97caee2278 100644 --- a/apps/simplex-support-bot/package.json +++ b/apps/simplex-support-bot/package.json @@ -5,14 +5,13 @@ "main": "dist/index.js", "scripts": { "build": "tsc", - "start": "node dist/index.js", - "test": "vitest run" + "start": "node dist/index.js" }, "dependencies": { - "@simplex-chat/types": "^0.11.2", + "@simplex-chat/types": "^0.7.0", "async-mutex": "^0.5.0", "commander": "^14.0.3", - "simplex-chat": "^7.1.0-beta.2", + "simplex-chat": "^6.5.2", "yaml": "^2.8.4" }, "devDependencies": { diff --git a/apps/simplex-support-bot/src/bot.ts b/apps/simplex-support-bot/src/bot.ts index a14a58c11e..28b2080793 100644 --- a/apps/simplex-support-bot/src/bot.ts +++ b/apps/simplex-support-bot/src/bot.ts @@ -67,8 +67,6 @@ export class SupportBot { // Contacts that already received the team DM (dedup) private sentTeamDMs = new Set() - private pendingBroadcasts = new Set() - // Tracked fire-and-forget operations (for testing) private _pendingOps: Promise[] = [] @@ -315,25 +313,6 @@ export class SupportBot { await this.deliverPendingDM(evt.contact.contactId) } - async onChatItemsStatusesUpdated(evt: CEvt.ChatItemsStatusesUpdated): Promise { - if (evt.user.userId !== this.mainUserId) return - for (const {chatInfo, chatItem} of evt.chatItems) { - if (chatInfo.type !== "feed") continue - const itemId = chatItem.meta.itemId - if (!this.pendingBroadcasts.has(itemId)) continue - const status = chatItem.meta.itemStatus - let report: string | undefined - if (status.type === "sndSent" && status.sndProgress === T.SndCIStatusProgress.Complete) { - report = `Broadcast ${itemId} delivered to all chats` - } else if (status.type === "sndError") { - report = `Broadcast ${itemId} failed: ${JSON.stringify(status.agentError)}` - } - if (report === undefined) continue - this.pendingBroadcasts.delete(itemId) - await this.sendToGroup(this.config.teamGroup.id, report) - } - } - private async deliverPendingDM(contactId: number): Promise { if (this.sentTeamDMs.has(contactId)) { this.pendingTeamDMs.delete(contactId) @@ -835,44 +814,14 @@ export class SupportBot { if (!senderContactId) return const cmd = util.ciBotCommand(chatItem) - switch (cmd?.keyword) { - case "join": { - const targetGroupId = Number.parseInt(cmd.params, 10) - if (Number.isNaN(targetGroupId) || targetGroupId <= 0) { - await this.sendToGroup(this.config.teamGroup.id, `Error: invalid group id "${cmd.params}"`) - return - } - await this.handleJoinCommand(targetGroupId, senderContactId) - break - } - case "broadcast": - await this.handleBroadcastCommand(chatItem, senderContactId) - break - } - } + if (cmd?.keyword !== "join") return - private async handleBroadcastCommand(chatItem: T.ChatItem, senderContactId: number): Promise { - const teamGroupId = this.config.teamGroup.id - if (!this.config.broadcasters.some(b => b.id === senderContactId)) { - await this.sendToGroup(teamGroupId, `Error: contact ${senderContactId} is not allowed to broadcast`) + const targetGroupId = Number.parseInt(cmd.params, 10) + if (Number.isNaN(targetGroupId) || targetGroupId <= 0) { + await this.sendToGroup(this.config.teamGroup.id, `Error: invalid group id "${cmd.params}"`) return } - const text = (util.ciContentText(chatItem)?.trim() ?? "").replace(/^\/broadcast\s*/, "") - if (text === "") { - await this.sendToGroup(teamGroupId, "Error: broadcast text is empty") - return - } - try { - const r = await this.withMainProfile(() => this.chat.sendChatCmd(`/feed ${JSON.stringify(text)}`)) - if (r.type !== "newChatItems") throw new Error(`unexpected response ${r.type}`) - const itemId = r.chatItems[0]?.chatItem.meta.itemId - if (itemId === undefined) throw new Error("no feed item in response") - this.pendingBroadcasts.add(itemId) - await this.sendToGroup(teamGroupId, `Broadcast ${itemId} queued for delivery to all chats`) - } catch (err) { - logError("/broadcast failed", err) - await this.sendToGroup(teamGroupId, "Error sending broadcast") - } + await this.handleJoinCommand(targetGroupId, senderContactId) } private async handleJoinCommand(targetGroupId: number, senderContactId: number): Promise { diff --git a/apps/simplex-support-bot/src/config.ts b/apps/simplex-support-bot/src/config.ts index d022215c2b..be33db0c38 100644 --- a/apps/simplex-support-bot/src/config.ts +++ b/apps/simplex-support-bot/src/config.ts @@ -11,14 +11,11 @@ export interface Config { db: api.DbConfig // passed to ChatApi.init / bot.run teamGroup: IdName // name from CLI, id resolved at startup from state file teamMembers: IdName[] // optional, empty if not provided - broadcasters: IdName[] // optional, empty if not provided grokContactId: number | null // resolved at startup timezone: string completeHours: number cardFlushSeconds: number contextFile: string | null - dryRun: boolean - allowMigrations: boolean grokApiKey: string | null } @@ -30,10 +27,6 @@ export function parseIdName(s: string): IdName { return {id, name: s.slice(i + 1)} } -function parseIdNames(list: string | undefined): IdName[] { - return list ? list.split(",").map(parseIdName) : [] -} - function parseNonNegativeInt(flag: string) { return (raw: string): number => { const n = parseInt(raw, 10) @@ -56,13 +49,10 @@ function buildCommand(): Command { .option("--pg-conn ", "PostgreSQL connection string (required with --db postgres)") .option("--pg-schema ", "PostgreSQL schema prefix (default: simplex_v1)") .option("-a, --auto-add-team-members ", "comma-separated ID:name pairs (e.g. 1:Alice,2:Bob)") - .option("--broadcasters ", "comma-separated ID:name pairs of contacts allowed to use /broadcast in the team group") .option("--timezone ", "IANA timezone for weekend detection", "UTC") .option("--complete-hours ", "auto-complete chats after N hours idle (0 disables)", parseNonNegativeInt("--complete-hours"), 3) .option("--card-flush-seconds ", "debounce card state writes", parseNonNegativeInt("--card-flush-seconds"), 300) .option("--context-file ", "text file with Grok system context (required if GROK_API_KEY set)") - .option("--dry-run", "check config, database and state, then exit without starting chat") - .option("--allow-migrations", "with --dry-run: apply pending migrations instead of reporting them") .addHelpText("after", "\nEnvironment:\n GROK_API_KEY xAI API key — enables Grok replies\n SIMPLEX_LIBS_DIR local libsimplex build for the --db backend\n SIMPLEX_ADDON_PATH locally built Node.js add-on\n") } @@ -75,13 +65,10 @@ interface RawOpts { pgConn?: string pgSchema?: string autoAddTeamMembers?: string - broadcasters?: string timezone: string completeHours: number cardFlushSeconds: number contextFile?: string - dryRun?: boolean - allowMigrations?: boolean } export function parseConfig(args: string[]): Config { @@ -114,8 +101,10 @@ export function parseConfig(args: string[]): Config { const teamGroup: IdName = {id: 0, name: opts.teamGroup} - const teamMembers = parseIdNames(opts.autoAddTeamMembers) - const broadcasters = parseIdNames(opts.broadcasters) + const teamMembersRaw = opts.autoAddTeamMembers ?? "" + const teamMembers = teamMembersRaw + ? teamMembersRaw.split(",").map(parseIdName) + : [] try { new Intl.DateTimeFormat("en-US", {timeZone: opts.timezone, weekday: "short"}) @@ -133,14 +122,11 @@ export function parseConfig(args: string[]): Config { db, teamGroup, teamMembers, - broadcasters, grokContactId: null, timezone: opts.timezone, completeHours: opts.completeHours, cardFlushSeconds: opts.cardFlushSeconds, contextFile, - dryRun: opts.dryRun ?? false, - allowMigrations: opts.allowMigrations ?? false, grokApiKey, } } diff --git a/apps/simplex-support-bot/src/dryRun.ts b/apps/simplex-support-bot/src/dryRun.ts deleted file mode 100644 index 2ef1db98f6..0000000000 --- a/apps/simplex-support-bot/src/dryRun.ts +++ /dev/null @@ -1,129 +0,0 @@ -import {api} from "simplex-chat" -import {T} from "@simplex-chat/types" -import {Config, IdName} from "./config.js" -import {loadGrokContext} from "./context.js" - -// Ids the bot persists; a miss means it would create the entity again. -export interface DryRunState { - teamGroupId?: number - grokContactId?: number - grokUserId?: number -} - -// Names are searched rather than listing every chat: a bot with thousands of -// customer chats would otherwise be paged through to find a handful of ids. -const SEARCH_LIMIT = 100 - -// Only for the failure path, where the id has to be reported with the name it -// actually has: a renamed contact does not match the search above. -const LISTING_LIMIT = 1000 - -const GROK_PROFILE_NAME = "Grok" - -export async function dryRun(chat: api.ChatApi, config: Config, state: DryRunState): Promise { - const results: boolean[] = [] - const check = (ok: boolean, msg: string): void => { - results.push(ok) - console.log(`${ok ? "ok " : "FAIL"} ${msg}`) - } - // Absence cannot be proven with the chat stopped: getChatPreviews filters on - // contacts.contact_used, so a contact whose direct chat was never used is - // invisible here even though the bot finds it at startup. - const unverified = (msg: string): void => console.log(`? ${msg}`) - - if (config.contextFile) { - try { - const context = loadGrokContext(config.contextFile) - check(true, `Grok context: ${context.length} message(s) from ${config.contextFile}`) - } catch (err) { - const e = err as NodeJS.ErrnoException - const missing = e.code === "ENOENT" - check(missing, `Grok context ${config.contextFile}: ${missing ? "not found, would start without it" : e.message}`) - } - } - - const user = await chat.apiGetActiveUser() - if (!user) { - check(false, "no active user in database, the bot would create one") - return false - } - check(true, `active user: ${user.userId}:${user.profile.displayName}`) - - if (state.grokUserId !== undefined) { - const users = await chat.apiListUsers() - const found = users.find(u => u.user.userId === state.grokUserId) - check(!!found, `Grok user ${state.grokUserId}: ${found ? found.user.profile.displayName : "missing, the bot would exit"}`) - } - - if (state.teamGroupId !== undefined) { - const group = await findGroup(chat, user.userId, config.teamGroup.name, state.teamGroupId) - if (!group) { - unverified(`team group ${state.teamGroupId} not in chat previews, the bot verifies it at startup`) - } else { - check(true, `team group ${state.teamGroupId}: ${group.groupProfile.displayName}`) - } - if (group && group.groupProfile.displayName !== config.teamGroup.name) { - check(true, `team group name differs from --team-group, profile would be updated to "${config.teamGroup.name}"`) - } - } else { - check(true, `no team group in state, "${config.teamGroup.name}" would be created`) - } - - if (state.grokContactId !== undefined) { - const contact = await findContact(chat, user.userId, GROK_PROFILE_NAME, state.grokContactId) - if (contact) check(true, `Grok contact ${state.grokContactId}: ${contact.profile.displayName}`) - else unverified(`Grok contact ${state.grokContactId} not in chat previews, the bot verifies it at startup`) - } - - await checkContacts(chat, user.userId, "team member", config.teamMembers, check, unverified) - await checkContacts(chat, user.userId, "broadcaster", config.broadcasters, check, unverified) - - return results.every(Boolean) -} - -async function checkContacts( - chat: api.ChatApi, - userId: number, - role: string, - contacts: IdName[], - check: (ok: boolean, msg: string) => void, - unverified: (msg: string) => void -): Promise { - for (const {id, name} of contacts) { - const contact = await findContact(chat, userId, name, id) - if (!contact) { - unverified(`${role} ${id}:${name} not in chat previews, the bot verifies it at startup`) - } else { - const match = contact.profile.displayName === name - check(match, `${role} ${id}:${name}${match ? "" : ` has display name "${contact.profile.displayName}", the bot would exit`}`) - } - } -} - -async function findGroup(chat: api.ChatApi, userId: number, search: string, groupId: number): Promise { - const group = (chats: T.AChat[]): T.GroupInfo | undefined => { - for (const {chatInfo} of chats) { - if (chatInfo.type === "group" && chatInfo.groupInfo.groupId === groupId) return chatInfo.groupInfo - } - return undefined - } - return group(await searchChats(chat, userId, search)) ?? group(await recentChats(chat, userId)) -} - -async function findContact(chat: api.ChatApi, userId: number, search: string, contactId: number): Promise { - const contact = (chats: T.AChat[]): T.Contact | undefined => { - for (const {chatInfo} of chats) { - if (chatInfo.type === "direct" && chatInfo.contact.contactId === contactId) return chatInfo.contact - } - return undefined - } - return contact(await searchChats(chat, userId, search)) ?? contact(await recentChats(chat, userId)) -} - -function searchChats(chat: api.ChatApi, userId: number, search: string): Promise { - return chat.apiGetChats(userId, {type: "last", count: SEARCH_LIMIT}, {type: "search", search}) -} - -function recentChats(chat: api.ChatApi, userId: number): Promise { - return chat.apiGetChats(userId, {type: "last", count: LISTING_LIMIT}) -} diff --git a/apps/simplex-support-bot/src/index.ts b/apps/simplex-support-bot/src/index.ts index 3345682959..c99b1f5842 100644 --- a/apps/simplex-support-bot/src/index.ts +++ b/apps/simplex-support-bot/src/index.ts @@ -1,9 +1,8 @@ import {readFileSync, writeFileSync, existsSync} from "fs" -import {api, bot, core, util} from "simplex-chat" +import {api, bot, util} from "simplex-chat" import {T} from "@simplex-chat/types" -import {Config, IdName, parseConfig} from "./config.js" +import {parseConfig} from "./config.js" import {SupportBot} from "./bot.js" -import {dryRun} from "./dryRun.js" import {GrokApiClient, GrokMessage} from "./grok.js" import {loadGrokContext} from "./context.js" import {welcomeMessage} from "./messages.js" @@ -32,7 +31,6 @@ async function main(): Promise { backend: config.db.type, teamGroup: config.teamGroup, teamMembers: config.teamMembers, - broadcasters: config.broadcasters, timezone: config.timezone, completeHours: config.completeHours, }) @@ -42,10 +40,6 @@ async function main(): Promise { const stateFilePath = config.stateFile const state = readState(stateFilePath) - if (config.dryRun) { - process.exit((await runDryRun(config, state)) ? 0 : 1) - } - // Forward-reference for event handlers during init let supportBot: SupportBot | undefined @@ -119,7 +113,6 @@ async function main(): Promise { newMemberContactReceivedInv: (evt) => supportBot?.onMemberContactReceivedInv(evt), contactConnected: (evt) => supportBot?.onContactConnected(evt), contactSndReady: (evt) => supportBot?.onContactSndReady(evt), - chatItemsStatusesUpdated: (evt) => supportBot?.onChatItemsStatusesUpdated(evt), }, }) log(`Main bot user: ${mainUser.profile.displayName} (userId=${mainUser.userId})`) @@ -236,7 +229,6 @@ async function main(): Promise { fullDelete: {enable: T.GroupFeatureEnabled.On}, commands: [ {type: "command", keyword: "join", label: "Join customer chat", params: "groupId"}, - {type: "command", keyword: "broadcast", label: "Broadcast to all chats", params: "text"}, ], } @@ -308,24 +300,20 @@ async function main(): Promise { inviteLinkTimer.unref() } - // Step 9: Validate team members and broadcasters (lookup by ID, one round-trip per contact) - await validateContacts("Team member", config.teamMembers) - await validateContacts("Broadcaster", config.broadcasters) - - async function validateContacts(role: string, contacts: IdName[]): Promise { - if (contacts.length === 0) return - log(`Validating ${role.toLowerCase()}s...`) - for (const {id, name} of contacts) { - const contact = await getContact(chat, id) + // Step 9: Validate team members (lookup by ID, one round-trip per member) + if (config.teamMembers.length > 0) { + log("Validating team members...") + for (const member of config.teamMembers) { + const contact = await getContact(chat, member.id) if (!contact) { - console.error(`${role} not found: ID=${id}`) + console.error(`Team member not found: ID=${member.id}`) process.exit(1) } - if (contact.profile.displayName !== name) { - console.error(`${role} name mismatch: expected "${name}", got "${contact.profile.displayName}" (ID=${id})`) + if (contact.profile.displayName !== member.name) { + console.error(`Team member name mismatch: expected "${member.name}", got "${contact.profile.displayName}" (ID=${member.id})`) process.exit(1) } - log(`${role} validated: ${id}:${name}`) + log(`Team member validated: ${member.id}:${member.name}`) } } @@ -382,78 +370,6 @@ async function main(): Promise { process.on("SIGTERM", () => shutdown("SIGTERM")) } -// Opens the database without starting chat, so nothing reaches the network. -// MigrationConfirmation.Error makes a pending migration a report instead of an -// upgrade — a dry run must not change the database it is inspecting. -async function runDryRun(config: Config, state: BotState): Promise { - const probe = await probeDatabase(config.db) - if (probe.type === "failed") { - console.log(`FAIL database: ${probe.text}`) - return false - } - const pending = probe.type === "pending" ? probe.names : [] - if (pending.length > 0 && !config.allowMigrations) { - console.log(`FAIL database: ${pending.length} migration(s) pending, a real start would apply them: ${pending.join(", ")}`) - return false - } - const migrating = pending.length > 0 - let chat: api.ChatApi - try { - chat = await api.ChatApi.init( - config.db, - migrating ? core.MigrationConfirmation.YesUp : core.MigrationConfirmation.Error - ) - } catch (err) { - console.log(`FAIL database: ${migrationErrorText(err)}`) - return false - } - const schemaState = migrating ? `applied ${pending.length} migration(s): ${pending.join(", ")}` : "schema up to date" - console.log(`ok database ${config.db.type} opened, ${schemaState}`) - try { - return await dryRun(chat, config, state) - } finally { - await chat.close() - } -} - -// Opening with Error never changes the database, so this reports what a real -// start would migrate. Anything other than pending up-migrations is fatal: a -// wrong key, an unreachable server or a newer database cannot be migrated away. -type DbProbe = {type: "current"} | {type: "pending"; names: string[]} | {type: "failed"; text: string} - -async function probeDatabase(db: api.DbConfig): Promise { - try { - const chat = await api.ChatApi.init(db, core.MigrationConfirmation.Error) - await chat.close() - return {type: "current"} - } catch (err) { - const dbErr = (err as core.ChatInitError).dbMigrationError - if (dbErr?.type === "errorMigration" && dbErr.migrationError.type === "upgrade") { - return {type: "pending", names: dbErr.migrationError.upMigrations.map(m => m.upName)} - } - return {type: "failed", text: migrationErrorText(err)} - } -} - -// The library reports a pending migration as one opaque message; the names are -// in the error payload, and they are what an operator needs before upgrading. -function migrationErrorText(err: unknown): string { - const e = err as core.ChatInitError - const dbErr = e.dbMigrationError - if (dbErr?.type === "errorMigration") { - const me = dbErr.migrationError - switch (me.type) { - case "upgrade": - return `${me.upMigrations.length} migration(s) pending: ${me.upMigrations.map(m => m.upName).join(", ")}` - case "downgrade": - return `database is newer than this build, it would refuse to start; migrations to roll back: ${me.downMigrations.join(", ")}` - default: - return `migration state error: ${JSON.stringify(me)}` - } - } - return e.message -} - main().catch(err => { logError("Fatal error", err) process.exit(1) diff --git a/apps/simplex-support-bot/test/__mocks__/simplex-chat-types.js b/apps/simplex-support-bot/test/__mocks__/simplex-chat-types.js index e1e5556f4e..29fc3d01a4 100644 --- a/apps/simplex-support-bot/test/__mocks__/simplex-chat-types.js +++ b/apps/simplex-support-bot/test/__mocks__/simplex-chat-types.js @@ -5,9 +5,8 @@ const GroupMemberRole = {Member: "member", Owner: "owner", Admin: "admin", Relay const GroupMemberStatus = {Connected: "connected", Complete: "complete", Announced: "announced", Left: "left", Removed: "removed", Invited: "invited"} const GroupFeatureEnabled = {On: "on", Off: "off"} const CIDeleteMode = {Broadcast: "broadcast", Internal: "internal"} -const SndCIStatusProgress = {Partial: "partial", Complete: "complete"} module.exports = { - T: {ChatType, GroupMemberRole, GroupMemberStatus, GroupFeatureEnabled, CIDeleteMode, SndCIStatusProgress}, + T: {ChatType, GroupMemberRole, GroupMemberStatus, GroupFeatureEnabled, CIDeleteMode}, CEvt: {}, } diff --git a/plans/2026-09-12-support-bot-broadcast.md b/plans/2026-09-12-support-bot-broadcast.md deleted file mode 100644 index 60ef996d22..0000000000 --- a/plans/2026-09-12-support-bot-broadcast.md +++ /dev/null @@ -1,51 +0,0 @@ -# Support bot broadcast - -A feed broadcast sent from the support bot's team group. - -## Decisions - -- Trigger: `/broadcast ` in the team group, accepted only from contacts listed in `--broadcasters`. -- Audience: unrestricted. Every customer group and every direct contact receives it, including the Grok contact and team member DMs. -- Content: text only. -- Command: the bot sends the CLI command `/feed ` through `sendChatCmd`. `APISendFeedMessage` stays undocumented and no lookup command is added until the feed API stabilises. -- Reporting: the bot acknowledges on send, and posts again when the feed item reaches `sndSent` `complete` or an error status. - -## Bot - -`apps/simplex-support-bot/src/config.ts`: - -- `--broadcasters `: comma-separated `ID:name` pairs, parsed with `parseIdName` -- `Config.broadcasters: IdName[]` - -`apps/simplex-support-bot/src/index.ts`: - -- broadcasters are validated at startup as team members are: read the contact by id, then compare the display name -- `teamGroupPreferences.commands` gains - `{type: "command", keyword: "broadcast", label: "Broadcast to all chats", params: "text"}` -- the `events` map gains `chatItemsStatusesUpdated` - -`apps/simplex-support-bot/src/bot.ts`: - -- `processTeamGroupMessage` routes the `broadcast` keyword to `handleBroadcastCommand` and keeps the `join` route -- `handleBroadcastCommand`: - - the sender's `memberContactId` must be in `config.broadcasters`, otherwise the bot replies in the team group and stops - - the text is the trimmed message with the `/broadcast` prefix and one following whitespace character removed; `ciBotCommand`'s `params` stops at the first newline, so it is only used for the keyword - - empty text is an error reply - - the command sent is `"/feed " + JSON.stringify(text)`; `msgTextP` decodes the JSON string, so newlines and quotes survive - - the response must be `newChatItems`; its first item id is held in a pending map, and the bot replies that the broadcast is queued -- `onChatItemsStatusesUpdated` matches items whose chat info type is `feed` and whose id is in the pending map: - - `sndSent` with `sndProgress` `complete` replies that the broadcast is delivered, and drops the entry - - `sndError` replies with the error text, and drops the entry -- a restart drops pending reports; delivery continues in the feed workers - -## Status - -Written: config, startup validation, command routing, the broadcast handler, the status handler, the README section, and nine tests in `bot.test.ts` with a `feed` chat item factory and a `/feed` response in the mock API. - -Not run: `tsc` and `vitest`, since the bot's `node_modules` is absent and installing it was declined. - -## Not changed - -- The feed audience. Restricting a broadcast to customer groups would need a scope on the feed itself. -- The API docs, the TypeScript client and the Python client. -- `updateChatSettings`. It still rejects `*` and `%`, so `/feed drop %` is not accepted. diff --git a/scripts/support-bot/.gitignore b/scripts/support-bot/.gitignore deleted file mode 100644 index 0c54f604fc..0000000000 --- a/scripts/support-bot/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -data/ -.env diff --git a/scripts/support-bot/Dockerfile b/scripts/support-bot/Dockerfile deleted file mode 100644 index 25d186616e..0000000000 --- a/scripts/support-bot/Dockerfile +++ /dev/null @@ -1,143 +0,0 @@ -# syntax=docker/dockerfile:1 -# -# Built from the repository root: -# -# docker compose -f scripts/support-bot/compose.yml build -# docker build -f scripts/support-bot/Dockerfile -t simplex-support-bot . -# -# libsimplex, the node library and the types all come from this tree. The first -# stage is a full GHC build of simplexmq and simplex-chat: hours on a cold cache, -# and it needs ~15 GB. - -ARG UBUNTU=24.04 -# A lib built here has to load on a runtime with the same glibc or newer. -ARG UBUNTU_LIBS=22.04 -ARG GHC=9.6.3 -ARG CABAL=3.10.2.0 -ARG NODE=24 -# The core, the node library and the bot must agree on it. -ARG SIMPLEX_BACKEND=postgres - -# --------------------------------------------------------------------------- # -# libsimplex -# --------------------------------------------------------------------------- # -FROM ubuntu:${UBUNTU_LIBS} AS libsimplex - -ARG GHC -ARG CABAL -ARG SIMPLEX_BACKEND -ENV DEBIAN_FRONTEND=noninteractive - -# The toolchain the libs job in .github/workflows/build.yml uses, without the -# Java and Android SDK layers of Dockerfile.build, which the lib does not need. -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential ca-certificates curl git libgmp3-dev libnuma-dev \ - libpq-dev libsqlite3-dev libssl-dev llvm patchelf pkg-config zlib1g-dev && \ - rm -rf /var/lib/apt/lists/* - -ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \ - BOOTSTRAP_HASKELL_GHC_VERSION=${GHC} \ - BOOTSTRAP_HASKELL_CABAL_VERSION=${CABAL} \ - BOOTSTRAP_HASKELL_INSTALL_NO_STACK=true \ - BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK=true -RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh -ENV PATH="/root/.ghcup/bin:/root/.cabal/bin:$PATH" -ENV CABAL_DIR=/root/.cabal - -WORKDIR /src -COPY cabal.project simplex-chat.cabal README.md PRIVACY.md ./ -COPY scripts/cabal.project.local.linux ./cabal.project.local -# libsimplex.dll.def and flake.nix hold the export lists the build script checks. -COPY libsimplex.dll.def flake.nix ./ -COPY scripts/desktop ./scripts/desktop -COPY src ./src - -# The VLC download the script ends with is for the desktop app, and it would run -# after the Haskell build. -RUN sed -i '/prepare-vlc-linux.sh/d' scripts/desktop/build-lib-linux.sh - -# Cache mounts, not layers: the cabal store and the build tree survive a source -# change. build-lib-linux.sh is the command the libs job runs, and the two files -# copied out are what that job publishes. Build trees of other versions are -# removed first: the script's unquoted simplex-chat-* glob fails with "cd: too -# many arguments" when the cache mount holds more than one. -RUN --mount=type=cache,target=/root/.cabal \ - --mount=type=cache,target=/src/dist-newstyle \ - set -eu; \ - ver=$(sed -n 's/^version: *//p' simplex-chat.cabal | tr -d '[:space:]'); \ - build_dir=dist-newstyle/build/$(uname -m)-linux/ghc-${GHC}/simplex-chat-$ver/build; \ - find dist-newstyle/build -maxdepth 3 -type d -name 'simplex-chat-*' \ - ! -path "*/simplex-chat-$ver" -exec rm -rf {} + 2>/dev/null || true; \ - cabal update; \ - scripts/desktop/build-lib-linux.sh "${SIMPLEX_BACKEND}"; \ - mkdir -p /libs; \ - cp "$build_dir"/libsimplex.so "$build_dir"/deps/* /libs/ - -# --------------------------------------------------------------------------- # -# build -# --------------------------------------------------------------------------- # -FROM node:${NODE}-bookworm-slim AS build - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential python3 && \ - rm -rf /var/lib/apt/lists/* - -COPY --from=libsimplex /libs /opt/simplex/libs - -WORKDIR /src -COPY packages/simplex-chat-client/types/typescript packages/simplex-chat-client/types/typescript -RUN cd packages/simplex-chat-client/types/typescript && \ - npm install --no-audit --no-fund && \ - npx tsc - -COPY packages/simplex-chat-nodejs packages/simplex-chat-nodejs -RUN cd packages/simplex-chat-nodejs && \ - npm install --no-audit --no-fund && \ - npm install --no-save --no-audit --no-fund ../simplex-chat-client/types/typescript && \ - npx node-gyp rebuild && \ - npx tsc && \ - cp src/simplex.* dist/ - -WORKDIR /src/apps/simplex-support-bot -COPY apps/simplex-support-bot/package.json apps/simplex-support-bot/package-lock.json ./ -RUN npm ci --no-audit --no-fund -RUN npm install --no-save --no-audit --no-fund \ - /src/packages/simplex-chat-nodejs \ - /src/packages/simplex-chat-client/types/typescript - -COPY apps/simplex-support-bot ./ -RUN npm run build && npm test - -# --------------------------------------------------------------------------- # -# runtime -# --------------------------------------------------------------------------- # -FROM node:${NODE}-bookworm-slim AS runtime - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates dumb-init libgmp10 libnuma1 libpq5 && \ - rm -rf /var/lib/apt/lists/* - -# A named volume at /data takes this ownership and mode; a bind mount instead -# keeps the host directory's, which then has to be owned by uid 1000. -RUN mkdir -p /data && chown node:node /data && chmod 0700 /data - -COPY --from=build /opt/simplex/libs /opt/simplex/libs -COPY --from=build --chown=node:node /src /src -ENV SIMPLEX_LIBS_DIR=/opt/simplex/libs \ - SIMPLEX_ADDON_PATH=/src/packages/simplex-chat-nodejs/build/Release/simplex.node - -USER node -WORKDIR /src/apps/simplex-support-bot - -ENV NODE_ENV=production -# Raised: single API responses grow with the number of chats. -ENV NODE_OPTIONS=--max-old-space-size=8192 - -# Exec form: under `sh -c` the bot would not receive SIGTERM, so it would not -# delete the team group invite link on shutdown. -ENTRYPOINT ["dumb-init", "--", "node", "dist/index.js"] -CMD ["--team-group", "Support Team", "--state-file", "/data/state.json"] diff --git a/scripts/support-bot/Dockerfile.dockerignore b/scripts/support-bot/Dockerfile.dockerignore deleted file mode 100644 index 42ffaa5555..0000000000 --- a/scripts/support-bot/Dockerfile.dockerignore +++ /dev/null @@ -1,25 +0,0 @@ -# The build context is the repository root: everything is excluded, then what the -# image is built from is added back. -* - -!cabal.project -!simplex-chat.cabal -!README.md -!PRIVACY.md -!libsimplex.dll.def -!flake.nix -!src -!scripts/cabal.project.local.linux -!scripts/desktop -!packages/simplex-chat-client -!packages/simplex-chat-nodejs -!apps/simplex-support-bot - -# Build output and local state in those directories; the image builds its own. -**/node_modules -**/dist -**/build -**/libs -**/data -**/.env -**/.npmrc diff --git a/scripts/support-bot/compose.yml b/scripts/support-bot/compose.yml deleted file mode 100644 index c5715bda3a..0000000000 --- a/scripts/support-bot/compose.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Builds the bot from this tree, on the postgres backend. network_mode: host is -# what makes 127.0.0.1 reach PostgreSQL on the host. -# -# PG_CONN='postgres://simplex@127.0.0.1/simplex_support_bot' \ -# docker compose -f scripts/support-bot/compose.yml up --build - -services: - support-bot: - image: simplex-support-bot:latest - build: - context: ../.. - dockerfile: scripts/support-bot/Dockerfile - network_mode: host - restart: on-failure:5 - environment: - GROK_API_KEY: ${GROK_API_KEY:-} - volumes: - - support-bot-data:/data - - ./config:/etc/support-bot:ro - command: - - "--team-group" - - "Support Team" - - "--state-file" - - "/data/state.json" - - "--db" - - "postgres" - - "--pg-conn" - - "${PG_CONN:?set PG_CONN, e.g. postgres://simplex@127.0.0.1/simplex_support_bot}" - - "--context-file" - - "/etc/support-bot/grok-context.txt" - stop_grace_period: 30s - -volumes: - support-bot-data: diff --git a/scripts/support-bot/config/.gitkeep b/scripts/support-bot/config/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000