@mulmobridge/discord 0.1.1 → 1.0.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.
Files changed (3) hide show
  1. package/README.md +18 -0
  2. package/dist/index.js +12 -8
  3. package/package.json +8 -6
package/README.md CHANGED
@@ -50,6 +50,24 @@ npx @mulmobridge/discord
50
50
  | `DISCORD_BRIDGE_DEFAULT_ROLE` | No | Role id to seed new bridge sessions with (e.g. `coder`, `general`). Applied ONLY when a discord session first appears — once the user switches role via `/role <id>` the session's own role wins. Unknown role ids silently fall back to the server's default with a warn log. |
51
51
  | `BRIDGE_DEFAULT_ROLE` | No | Same as above but shared across every bridge. Transport-specific `DISCORD_BRIDGE_DEFAULT_ROLE` wins when both are set. |
52
52
 
53
+ ### Auth token persistence across server restarts
54
+
55
+ The MulmoClaude server regenerates a fresh bearer token on every startup and writes it to `~/mulmoclaude/.session-token`. The bridge reads that file once at launch and keeps the token in memory — so if the server restarts while the bridge is running, the bridge keeps using the **old** token and every API call returns **401**, silently.
56
+
57
+ **Fix**: set `MULMOCLAUDE_AUTH_TOKEN` to the same long random value on **both** the server and the bridge. The server uses it verbatim instead of regenerating, so the token survives restarts and the bridge stays authenticated.
58
+
59
+ ```bash
60
+ # Server (one-time setup — same value across restarts)
61
+ MULMOCLAUDE_AUTH_TOKEN=long-random-string yarn dev
62
+
63
+ # Bridge (separate process / machine — same value)
64
+ MULMOCLAUDE_AUTH_TOKEN=long-random-string \
65
+ <bridge-specific-envs> \
66
+ npx <this-package>@latest
67
+ ```
68
+
69
+ Recommended: at least 32 characters of random data (the server logs a warning at startup for shorter values).
70
+
53
71
  ## Ecosystem
54
72
 
55
73
  Part of the [`@mulmobridge/*`](https://www.npmjs.com/~mulmobridge) package family.
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@
11
11
  import "dotenv/config";
12
12
  import { Client, GatewayIntentBits, Partials } from "discord.js";
13
13
  import { createBridgeClient } from "@mulmobridge/client";
14
+ import { parseCsvSet } from "@mulmoclaude/common";
14
15
  const TRANSPORT_ID = "discord";
15
16
  const MAX_DISCORD_LENGTH = 2000;
16
17
  const token = process.env.DISCORD_BOT_TOKEN;
@@ -18,10 +19,7 @@ if (!token) {
18
19
  console.error("DISCORD_BOT_TOKEN is required.\nSee README for setup instructions.");
19
20
  process.exit(1);
20
21
  }
21
- const allowedChannels = new Set((process.env.DISCORD_ALLOWED_CHANNELS ?? "")
22
- .split(",")
23
- .map((channelId) => channelId.trim())
24
- .filter(Boolean));
22
+ const allowedChannels = parseCsvSet(process.env.DISCORD_ALLOWED_CHANNELS);
25
23
  const allowAll = allowedChannels.size === 0;
26
24
  const discord = new Client({
27
25
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent],
@@ -30,7 +28,10 @@ const discord = new Client({
30
28
  partials: [Partials.Channel],
31
29
  });
32
30
  const mulmo = createBridgeClient({ transportId: TRANSPORT_ID });
33
- mulmo.onPush(async (pushEvent) => {
31
+ mulmo.onPush((pushEvent) => {
32
+ onPushEvent(pushEvent).catch((err) => console.error(`[discord] push handler error: ${err}`));
33
+ });
34
+ async function onPushEvent(pushEvent) {
34
35
  try {
35
36
  const channel = discord.channels.cache.get(pushEvent.chatId) ?? (await discord.channels.fetch(pushEvent.chatId).catch(() => null));
36
37
  if (channel?.isTextBased() && "send" in channel) {
@@ -44,11 +45,14 @@ mulmo.onPush(async (pushEvent) => {
44
45
  catch (err) {
45
46
  console.error(`[discord] push send failed: ${err}`);
46
47
  }
48
+ }
49
+ discord.on("messageCreate", (msg) => {
50
+ onMessageCreate(msg).catch((err) => console.error(`[discord] messageCreate handler error: ${err}`));
47
51
  });
48
- discord.on("messageCreate", async (msg) => {
52
+ async function onMessageCreate(msg) {
49
53
  if (msg.author.bot)
50
54
  return;
51
- const channelId = msg.channelId;
55
+ const { channelId } = msg;
52
56
  const text = msg.content.trim();
53
57
  if (!text)
54
58
  return;
@@ -68,7 +72,7 @@ discord.on("messageCreate", async (msg) => {
68
72
  catch (err) {
69
73
  console.error(`[discord] message handling failed: ${err}`);
70
74
  }
71
- });
75
+ }
72
76
  async function sendChunked(msg, text) {
73
77
  if (text.length === 0) {
74
78
  await msg.reply("(empty reply)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulmobridge/discord",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "description": "Discord bridge for MulmoBridge — connect a Discord bot to MulmoClaude",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,18 +16,20 @@
16
16
  "build": "tsc",
17
17
  "prepack": "yarn build",
18
18
  "typecheck": "tsc --noEmit",
19
- "test": "echo no tests yet"
19
+ "test": "echo no tests yet",
20
+ "lint": "eslint src"
20
21
  },
21
22
  "license": "MIT",
22
23
  "author": "Receptron Team",
23
24
  "dependencies": {
24
- "@mulmobridge/client": "^0.1.4",
25
- "@mulmobridge/protocol": "^0.1.4",
26
- "discord.js": "^14.26.3",
25
+ "@mulmobridge/client": "^1.0.0",
26
+ "@mulmobridge/protocol": "^1.0.0",
27
+ "@mulmoclaude/common": "^1.1.0",
28
+ "discord.js": "^14.27.0",
27
29
  "dotenv": "^17.0.0"
28
30
  },
29
31
  "devDependencies": {
30
- "@types/node": "^25.6.0",
32
+ "@types/node": "^26.1.1",
31
33
  "typescript": "^6.0.3"
32
34
  }
33
35
  }