@stage-labs/metro 0.1.0-beta.4 → 0.1.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +131 -0
- package/dist/bedrock-eventstream.js +120 -0
- package/dist/bedrock-proxy.js +260 -0
- package/dist/bedrock-upstream.js +72 -0
- package/dist/bedrock.js +106 -0
- package/dist/claude.js +15 -0
- package/dist/cli.js +181 -207
- package/dist/control.js +173 -0
- package/dist/plugin.js +82 -0
- package/dist/prompt.js +61 -0
- package/dist/runtime.js +117 -0
- package/dist/serve.js +77 -0
- package/dist/store.js +93 -0
- package/dist/tail.js +120 -0
- package/dist/update.js +33 -0
- package/dist/version.js +97 -0
- package/package.json +34 -21
- package/runtime/node_modules/@metro-labs/discord-bot/package.json +28 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +119 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +388 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/api-base.ts +1 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +29 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +210 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +50 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +115 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +127 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +215 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +43 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +19 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +82 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +195 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +292 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +197 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +5 -0
- package/runtime/node_modules/@metro-labs/mcp/package.json +67 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +24 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/inbound.ts +367 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/media-note.ts +85 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/pending.ts +75 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/relay.ts +129 -0
- package/runtime/node_modules/@metro-labs/mcp/src/channels/webhook-note.ts +51 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +311 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +334 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-connector-api.ts +150 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-import.ts +76 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-pair.ts +20 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-error.ts +8 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +153 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-grant.ts +99 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-owner.ts +32 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-serve.ts +133 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-session.ts +278 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +383 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +143 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connect-hint.ts +33 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-api.ts +315 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +21 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth-routes.ts +157 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth.ts +127 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +100 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +57 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +333 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cors.ts +29 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/crash-guard.ts +49 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/events.ts +117 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/hosted-connectors.ts +118 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/http.ts +369 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +86 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/import-api.ts +67 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-connectors-api.ts +56 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-mode.ts +187 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-secret.ts +21 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/log.ts +42 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/mode-api.ts +31 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-client.ts +162 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-discovery.ts +120 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +65 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +58 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/paths.ts +145 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +214 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/protocol.ts +224 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/relay.ts +303 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +139 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +105 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/secure-fs.ts +57 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-api.ts +27 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +63 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-config.ts +27 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +218 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-auth.ts +82 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-nonces.ts +43 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-routes.ts +89 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/supervisor-io.ts +97 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/supervisor.ts +320 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/train-call.ts +22 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/train-error.ts +53 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +257 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/upload-api.ts +295 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/upload-store.ts +181 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +91 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +214 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-connectors.ts +143 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +84 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-scope.ts +64 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +37 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-config.ts +147 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-relay.ts +126 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +326 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/file-admin.ts +319 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/file-source.ts +152 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/key-map.ts +45 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +373 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +309 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +24 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +105 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +118 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/token-carry.ts +45 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +72 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +18 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/accounts.ts +141 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/call-tools.ts +203 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +29 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/ctx.ts +62 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/event-store.ts +91 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +21 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/group-tools.ts +129 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/index.ts +192 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/member-tools.ts +72 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +66 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/raw-get-stream.ts +207 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +73 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +172 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +43 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session.ts +211 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/str.ts +5 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/tool-dispatch.ts +212 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/tool-schemas.ts +397 -0
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/upload-tool.ts +66 -0
- package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +240 -0
- package/runtime/node_modules/@metro-labs/mcp/src/server.ts +2 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +80 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-inline.ts +100 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-interactive.ts +161 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-resolve.ts +200 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-xmtp.ts +111 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attach.ts +182 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/attachments.ts +196 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/lines.ts +82 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +88 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/registry.ts +35 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/station-runtime.ts +64 -0
- package/runtime/node_modules/@metro-labs/mcp/src/stations/types.ts +107 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +28 -0
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +81 -0
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +254 -0
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +87 -0
- package/runtime/node_modules/@metro-labs/telegram/src/client.ts +77 -0
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +141 -0
- package/runtime/node_modules/@metro-labs/telegram/src/group.ts +261 -0
- package/runtime/node_modules/@metro-labs/telegram/src/history.ts +52 -0
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +78 -0
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +46 -0
- package/runtime/node_modules/@metro-labs/telegram/src/login.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +80 -0
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +75 -0
- package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +22 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +167 -0
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +24 -0
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +7 -0
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +1 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +25 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +120 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +295 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +128 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +172 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +103 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +47 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +17 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +48 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/verify.ts +38 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +3 -0
- package/runtime/node_modules/@metro-labs/webhook/package.json +23 -0
- package/runtime/node_modules/@metro-labs/webhook/src/station.ts +40 -0
- package/runtime/node_modules/@metro-labs/whatsapp/package.json +29 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +67 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +101 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +178 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +72 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +129 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +318 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/delivery.ts +49 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +132 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +57 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +40 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +59 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/logger.ts +60 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +176 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +84 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +22 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/outbox.ts +38 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +141 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +17 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +98 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +6 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +5 -0
- package/runtime/node_modules/@metro-labs/xmtp/package.json +33 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +113 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +110 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +299 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +157 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +87 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +375 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +107 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +171 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +239 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +55 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +333 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +78 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +34 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +56 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +33 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +125 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +157 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +40 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +349 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +13 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +126 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +212 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +90 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +84 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +39 -0
- package/runtime/runtime.json +3 -0
- package/runtime/trains/.keep +0 -0
- package/LICENSE +0 -21
- package/README.md +0 -117
- package/dist/agents/claude.js +0 -207
- package/dist/agents/codex.js +0 -207
- package/dist/agents/types.js +0 -2
- package/dist/channels/discord.js +0 -104
- package/dist/channels/telegram.js +0 -189
- package/dist/helpers/scope-cache.js +0 -65
- package/dist/helpers/streaming.js +0 -209
- package/dist/helpers/telegram-format.js +0 -39
- package/dist/helpers/turn.js +0 -40
- package/dist/log.js +0 -10
- package/dist/orchestrator.js +0 -208
- package/dist/paths.js +0 -68
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.41",
|
|
4
|
+
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -14,34 +14,47 @@
|
|
|
14
14
|
"node": ">=22"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
|
-
"metro": "
|
|
17
|
+
"metro": "dist/cli.js"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
|
-
"
|
|
22
|
-
"LICENSE"
|
|
21
|
+
"runtime"
|
|
23
22
|
],
|
|
24
23
|
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
24
|
+
"access": "public",
|
|
25
|
+
"tag": "beta"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "tsc",
|
|
29
|
-
"prepublishOnly": "tsc",
|
|
30
|
-
"
|
|
31
|
-
"lint:fix": "eslint src/ --fix",
|
|
32
|
-
"typecheck": "tsc --noEmit"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"discord.js": "^14.14.0",
|
|
36
|
-
"pino": "^9.5.0",
|
|
37
|
-
"ws": "^8.20.0"
|
|
28
|
+
"build": "tsc && node scripts/stage-runtime.mjs",
|
|
29
|
+
"prepublishOnly": "tsc && node scripts/stage-runtime.mjs",
|
|
30
|
+
"test": "tsc --noEmit && node scripts/stage-runtime.mjs && bun test test/"
|
|
38
31
|
},
|
|
39
32
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@types/ws": "^8.18.1",
|
|
33
|
+
"@stage-labs/config": "0.1.0-beta.2",
|
|
42
34
|
"eslint": "^10.3.0",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
35
|
+
"knip": "^6.15.0",
|
|
36
|
+
"madge": "^8.0.0",
|
|
37
|
+
"typescript": "^5"
|
|
45
38
|
},
|
|
46
|
-
"
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@discordjs/voice": "^0.19.2",
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
42
|
+
"@mtcute/bun": "0.30.1",
|
|
43
|
+
"@xmtp/content-type-primitives": "^3.0.1",
|
|
44
|
+
"@xmtp/content-type-reaction": "^2.0.2",
|
|
45
|
+
"@xmtp/content-type-remote-attachment": "^2.0.4",
|
|
46
|
+
"@xmtp/content-type-reply": "^2.0.3",
|
|
47
|
+
"@xmtp/content-type-wallet-send-calls": "^2.0.0",
|
|
48
|
+
"@xmtp/node-bindings": "1.9.1",
|
|
49
|
+
"@xmtp/node-sdk": "^6.0.0",
|
|
50
|
+
"baileys": "7.0.0-rc14",
|
|
51
|
+
"discord.js": "^14.26.4",
|
|
52
|
+
"drizzle-orm": "^0.44.0",
|
|
53
|
+
"pino": "^9.5.0",
|
|
54
|
+
"pino-pretty": "^13.1.3",
|
|
55
|
+
"postgres": "^3.4.5",
|
|
56
|
+
"prism-media": "^1.3.5",
|
|
57
|
+
"viem": "^2.52.2",
|
|
58
|
+
"zod": "^3.23.8"
|
|
59
|
+
}
|
|
47
60
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metro-labs/discord-bot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/station.ts",
|
|
8
|
+
"./train": "./src/index.ts",
|
|
9
|
+
"./verify": "./src/verify.ts"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "tsc --noEmit && bun test test/"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@metro-labs/mcp": "workspace:*",
|
|
17
|
+
"@discordjs/voice": "^0.19.2",
|
|
18
|
+
"discord.js": "^14.26.4",
|
|
19
|
+
"prism-media": "^1.3.5"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@stage-labs/config": "0.1.0-beta.2",
|
|
23
|
+
"eslint": "^10.3.0",
|
|
24
|
+
"knip": "^6.15.0",
|
|
25
|
+
"madge": "^8.0.0",
|
|
26
|
+
"typescript": "^5"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Client } from 'discord.js';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
makeAccountStore,
|
|
6
|
+
resolveAccountId,
|
|
7
|
+
} from '@metro-labs/mcp/stations/account-store';
|
|
8
|
+
import { Line } from '@metro-labs/mcp/lines';
|
|
9
|
+
import { emit } from './wire.js';
|
|
10
|
+
import { API } from './api-base.js';
|
|
11
|
+
|
|
12
|
+
const ACCOUNTS_FILE =
|
|
13
|
+
process.env.DISCORD_BOT_ACCOUNTS_FILE ??
|
|
14
|
+
join(homedir(), '.metro', 'discord-bot-accounts.json');
|
|
15
|
+
|
|
16
|
+
export interface AccountConfig {
|
|
17
|
+
id: string;
|
|
18
|
+
token: string;
|
|
19
|
+
owner?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const { loadAccounts } = makeAccountStore<AccountConfig>({
|
|
23
|
+
prefix: 'discord-bot',
|
|
24
|
+
file: ACCOUNTS_FILE,
|
|
25
|
+
allowlistEnv: ['DISCORD_BOT_ONLY_ACCOUNTS', 'DISCORD_BOT_ACCOUNTS'],
|
|
26
|
+
validate(raw, die) {
|
|
27
|
+
const seen = new Set<string>();
|
|
28
|
+
for (const a of raw) {
|
|
29
|
+
if (!a.id) die('account missing id');
|
|
30
|
+
if (!a.token || typeof a.token !== 'string')
|
|
31
|
+
die(`account '${a.id}' missing token`);
|
|
32
|
+
if (seen.has(a.id)) die(`duplicate account id '${a.id}'`);
|
|
33
|
+
seen.add(a.id);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export interface Account {
|
|
39
|
+
cfg: AccountConfig;
|
|
40
|
+
client: Client;
|
|
41
|
+
}
|
|
42
|
+
export const accounts = new Map<string, Account>();
|
|
43
|
+
|
|
44
|
+
function restBody(
|
|
45
|
+
body: unknown,
|
|
46
|
+
isForm: boolean,
|
|
47
|
+
): RequestInit['body'] | undefined {
|
|
48
|
+
if (body === undefined) return undefined;
|
|
49
|
+
return isForm ? (body as RequestInit['body']) : JSON.stringify(body);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function restResult<T>(res: Response): Promise<T> {
|
|
53
|
+
if (res.status === 204) return undefined as T;
|
|
54
|
+
const ctype = res.headers.get('content-type') ?? '';
|
|
55
|
+
if (ctype.includes('application/json')) return res.json() as Promise<T>;
|
|
56
|
+
return res.arrayBuffer().then((b) => Buffer.from(b) as unknown as T);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function rest<T = unknown>(
|
|
60
|
+
accountId: string,
|
|
61
|
+
method: string,
|
|
62
|
+
path: string,
|
|
63
|
+
body?: unknown,
|
|
64
|
+
isForm = false,
|
|
65
|
+
): Promise<T> {
|
|
66
|
+
const acct = accounts.get(accountId);
|
|
67
|
+
if (!acct) throw new Error(`unknown account '${accountId}'`);
|
|
68
|
+
const headers: Record<string, string> = {
|
|
69
|
+
Authorization: `Bot ${acct.cfg.token}`,
|
|
70
|
+
'User-Agent': 'metro-discord-bot-train (https://github.com/bonustrack/stage)',
|
|
71
|
+
};
|
|
72
|
+
if (body !== undefined && !isForm)
|
|
73
|
+
headers['Content-Type'] = 'application/json';
|
|
74
|
+
emit({ op: 'log', text: `discord-bot[${accountId}] api ${method} ${path}` });
|
|
75
|
+
const res = await fetch(`${API}${path}`, {
|
|
76
|
+
method,
|
|
77
|
+
headers,
|
|
78
|
+
body: restBody(body, isForm),
|
|
79
|
+
signal: AbortSignal.timeout(30_000),
|
|
80
|
+
});
|
|
81
|
+
emit({
|
|
82
|
+
op: 'log',
|
|
83
|
+
text: `discord-bot[${accountId}] api ${method} ${path} -> ${res.status}`,
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const text = await res.text().catch(() => '');
|
|
87
|
+
throw new Error(`discord-bot ${method} ${path}: ${res.status} ${text}`);
|
|
88
|
+
}
|
|
89
|
+
return restResult<T>(res);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function lineOf(accountId: string, channelId: string): string {
|
|
93
|
+
return `metro://discord-bot/${accountId}/${channelId}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function parseLine(
|
|
97
|
+
line: string,
|
|
98
|
+
): { accountId: string; channelId: string } | null {
|
|
99
|
+
const p = Line.parseDiscord(line);
|
|
100
|
+
return p ? { accountId: p.accountId, channelId: p.resource } : null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function accountFor(args: { account?: string; line?: string }): string {
|
|
104
|
+
return resolveAccountId(accounts, args, (line) => parseLine(line)?.accountId);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function routeOf(
|
|
108
|
+
line: string,
|
|
109
|
+
account?: string,
|
|
110
|
+
): { accountId: string; channelId: string } {
|
|
111
|
+
const parsed = parseLine(line);
|
|
112
|
+
if (!parsed) throw new Error(`bad discord-bot line: ${line}`);
|
|
113
|
+
const accountId = account ?? parsed.accountId;
|
|
114
|
+
if (!accounts.has(accountId))
|
|
115
|
+
throw new Error(`unknown account '${accountId}' in line ${line}`);
|
|
116
|
+
return { accountId, channelId: parsed.channelId };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const encodeEmoji = (e: string): string => encodeURIComponent(e);
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActivityType,
|
|
3
|
+
type Message,
|
|
4
|
+
type PresenceStatusData,
|
|
5
|
+
} from 'discord.js';
|
|
6
|
+
import {
|
|
7
|
+
accountFor,
|
|
8
|
+
accounts,
|
|
9
|
+
encodeEmoji,
|
|
10
|
+
lineOf,
|
|
11
|
+
rest,
|
|
12
|
+
routeOf,
|
|
13
|
+
} from './accounts.js';
|
|
14
|
+
import { emitOutbound, emitOutboundEdit, emitOutboundReact } from './format.js';
|
|
15
|
+
import { respond } from './wire.js';
|
|
16
|
+
import { normalizeDiscord } from '@metro-labs/mcp/stations/messaging-normalize';
|
|
17
|
+
import { assertContentLength } from '@metro-labs/mcp/stations/attachments';
|
|
18
|
+
import {
|
|
19
|
+
appendFiles,
|
|
20
|
+
outgoingFiles,
|
|
21
|
+
type OutgoingFile,
|
|
22
|
+
} from './send-files.js';
|
|
23
|
+
import {
|
|
24
|
+
makeStation,
|
|
25
|
+
type CallMsg,
|
|
26
|
+
type StationHandler,
|
|
27
|
+
} from '@metro-labs/mcp/stations/station-runtime';
|
|
28
|
+
import { joinVoice, leaveVoice, voiceDebug, voiceTranscribe } from './voice.js';
|
|
29
|
+
import { speak } from './voice-speak.js';
|
|
30
|
+
import { discordMembers } from './members.js';
|
|
31
|
+
import {
|
|
32
|
+
groupAddHandler,
|
|
33
|
+
groupCreateHandler,
|
|
34
|
+
groupRemoveHandler,
|
|
35
|
+
} from './group-actions.js';
|
|
36
|
+
|
|
37
|
+
async function sendMessage(
|
|
38
|
+
accountId: string,
|
|
39
|
+
channel: string,
|
|
40
|
+
body: Record<string, unknown>,
|
|
41
|
+
files: OutgoingFile[],
|
|
42
|
+
): Promise<{ id: string; delivered: string[] }> {
|
|
43
|
+
if (files.length === 0) {
|
|
44
|
+
const plain = await rest<{ id: string }>(
|
|
45
|
+
accountId,
|
|
46
|
+
'POST',
|
|
47
|
+
`/channels/${channel}/messages`,
|
|
48
|
+
body,
|
|
49
|
+
);
|
|
50
|
+
return { id: plain.id, delivered: [] };
|
|
51
|
+
}
|
|
52
|
+
const form = new FormData();
|
|
53
|
+
form.append('payload_json', JSON.stringify(body));
|
|
54
|
+
const delivered = await appendFiles(form, files);
|
|
55
|
+
const res = await rest<{ id: string }>(
|
|
56
|
+
accountId,
|
|
57
|
+
'POST',
|
|
58
|
+
`/channels/${channel}/messages`,
|
|
59
|
+
form,
|
|
60
|
+
true,
|
|
61
|
+
);
|
|
62
|
+
return { id: res.id, delivered };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type { CallMsg };
|
|
66
|
+
|
|
67
|
+
async function send(id: string, args: Record<string, unknown>): Promise<void> {
|
|
68
|
+
const {
|
|
69
|
+
line,
|
|
70
|
+
text,
|
|
71
|
+
replyTo,
|
|
72
|
+
embeds,
|
|
73
|
+
stickerIds,
|
|
74
|
+
images,
|
|
75
|
+
files,
|
|
76
|
+
account,
|
|
77
|
+
attachmentKinds,
|
|
78
|
+
attachmentNames,
|
|
79
|
+
} = args as {
|
|
80
|
+
line: string;
|
|
81
|
+
text?: string;
|
|
82
|
+
replyTo?: string;
|
|
83
|
+
embeds?: unknown[];
|
|
84
|
+
stickerIds?: string[];
|
|
85
|
+
images?: string[];
|
|
86
|
+
files?: string[];
|
|
87
|
+
account?: string;
|
|
88
|
+
attachmentKinds?: string[];
|
|
89
|
+
attachmentNames?: string[];
|
|
90
|
+
};
|
|
91
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
92
|
+
const body: Record<string, unknown> = { flags: 4 };
|
|
93
|
+
if (text !== undefined) body.content = text;
|
|
94
|
+
if (replyTo) body.message_reference = { message_id: replyTo };
|
|
95
|
+
if (embeds) body.embeds = embeds;
|
|
96
|
+
if (stickerIds) body.sticker_ids = stickerIds;
|
|
97
|
+
const outgoing = outgoingFiles(
|
|
98
|
+
[...(images ?? []), ...(files ?? [])],
|
|
99
|
+
attachmentNames,
|
|
100
|
+
attachmentKinds,
|
|
101
|
+
);
|
|
102
|
+
const res = await sendMessage(accountId, channelId, body, outgoing);
|
|
103
|
+
emitOutbound(accountId, line, res.id, text ?? '', replyTo);
|
|
104
|
+
respond(id, {
|
|
105
|
+
result: {
|
|
106
|
+
messageId: res.id,
|
|
107
|
+
account: accountId,
|
|
108
|
+
...(res.delivered.length ? { attachments: res.delivered } : {}),
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function presence(id: string, args: Record<string, unknown>): void {
|
|
114
|
+
const {
|
|
115
|
+
text,
|
|
116
|
+
status = 'online',
|
|
117
|
+
account,
|
|
118
|
+
} = args as {
|
|
119
|
+
text?: string;
|
|
120
|
+
status?: PresenceStatusData;
|
|
121
|
+
account?: string;
|
|
122
|
+
};
|
|
123
|
+
const accountId = accountFor({ account });
|
|
124
|
+
const acct = accounts.get(accountId);
|
|
125
|
+
if (!acct) {
|
|
126
|
+
respond(id, { error: `unknown account '${accountId}'` });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const client = acct.client;
|
|
130
|
+
if (!client.user) {
|
|
131
|
+
respond(id, { error: `gateway not ready for account '${accountId}'` });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
client.user.setPresence({
|
|
135
|
+
status,
|
|
136
|
+
activities: text
|
|
137
|
+
? [{ name: 'Custom Status', type: ActivityType.Custom, state: text }]
|
|
138
|
+
: [],
|
|
139
|
+
});
|
|
140
|
+
respond(id, {
|
|
141
|
+
result: { ok: true, text: text ?? null, status, account: accountId },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const profileUrl = (userId?: string): string | null =>
|
|
146
|
+
userId === undefined ? null : `https://discord.com/users/${userId}`;
|
|
147
|
+
|
|
148
|
+
function listAccounts(id: string): void {
|
|
149
|
+
respond(id, {
|
|
150
|
+
result: {
|
|
151
|
+
accounts: [...accounts.values()].map((a) => ({
|
|
152
|
+
id: a.cfg.id,
|
|
153
|
+
handle: a.client.user?.username ?? null,
|
|
154
|
+
url: profileUrl(a.client.user?.id),
|
|
155
|
+
userId: a.client.user?.id ?? null,
|
|
156
|
+
username: a.client.user?.username ?? null,
|
|
157
|
+
owner: a.cfg.owner ?? null,
|
|
158
|
+
ready: a.client.isReady(),
|
|
159
|
+
})),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function react(id: string, args: Record<string, unknown>): Promise<void> {
|
|
165
|
+
const { line, messageId, emoji, account } = args as {
|
|
166
|
+
line: string;
|
|
167
|
+
messageId: string;
|
|
168
|
+
emoji: string;
|
|
169
|
+
account?: string;
|
|
170
|
+
};
|
|
171
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
172
|
+
if (emoji) {
|
|
173
|
+
const e = encodeEmoji(emoji);
|
|
174
|
+
await rest(
|
|
175
|
+
accountId,
|
|
176
|
+
'PUT',
|
|
177
|
+
`/channels/${channelId}/messages/${messageId}/reactions/${e}/@me`,
|
|
178
|
+
);
|
|
179
|
+
emitOutboundReact(accountId, line, messageId, emoji);
|
|
180
|
+
} else {
|
|
181
|
+
await rest(
|
|
182
|
+
accountId,
|
|
183
|
+
'DELETE',
|
|
184
|
+
`/channels/${channelId}/messages/${messageId}/reactions/@me`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function edit(id: string, args: Record<string, unknown>): Promise<void> {
|
|
191
|
+
const { line, messageId, text, account } = args as {
|
|
192
|
+
line: string;
|
|
193
|
+
messageId: string;
|
|
194
|
+
text: string;
|
|
195
|
+
account?: string;
|
|
196
|
+
};
|
|
197
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
198
|
+
await rest(accountId, 'PATCH', `/channels/${channelId}/messages/${messageId}`, {
|
|
199
|
+
content: text,
|
|
200
|
+
});
|
|
201
|
+
emitOutboundEdit(accountId, line, messageId, text);
|
|
202
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function remove(
|
|
206
|
+
id: string,
|
|
207
|
+
args: Record<string, unknown>,
|
|
208
|
+
): Promise<void> {
|
|
209
|
+
const { line, messageId, account } = args as {
|
|
210
|
+
line: string;
|
|
211
|
+
messageId: string;
|
|
212
|
+
account?: string;
|
|
213
|
+
};
|
|
214
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
215
|
+
await rest(accountId, 'DELETE', `/channels/${channelId}/messages/${messageId}`);
|
|
216
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function fetchMessages(
|
|
220
|
+
id: string,
|
|
221
|
+
args: Record<string, unknown>,
|
|
222
|
+
): Promise<void> {
|
|
223
|
+
const {
|
|
224
|
+
line,
|
|
225
|
+
limit = 20,
|
|
226
|
+
before,
|
|
227
|
+
account,
|
|
228
|
+
} = args as {
|
|
229
|
+
line: string;
|
|
230
|
+
limit?: number;
|
|
231
|
+
before?: string;
|
|
232
|
+
account?: string;
|
|
233
|
+
};
|
|
234
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
235
|
+
const qs = new URLSearchParams({
|
|
236
|
+
limit: String(limit),
|
|
237
|
+
...(before ? { before } : {}),
|
|
238
|
+
});
|
|
239
|
+
const msgs = await rest<Message[]>(
|
|
240
|
+
accountId,
|
|
241
|
+
'GET',
|
|
242
|
+
`/channels/${channelId}/messages?${qs}`,
|
|
243
|
+
);
|
|
244
|
+
respond(id, { result: { messages: msgs, account: accountId } });
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function download(
|
|
248
|
+
id: string,
|
|
249
|
+
args: Record<string, unknown>,
|
|
250
|
+
): Promise<void> {
|
|
251
|
+
const {
|
|
252
|
+
line,
|
|
253
|
+
messageId,
|
|
254
|
+
outDir = '/tmp',
|
|
255
|
+
account,
|
|
256
|
+
} = args as {
|
|
257
|
+
line: string;
|
|
258
|
+
messageId: string;
|
|
259
|
+
outDir?: string;
|
|
260
|
+
account?: string;
|
|
261
|
+
};
|
|
262
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
263
|
+
const msg = await rest<{
|
|
264
|
+
attachments: { url: string; content_type?: string; filename: string }[];
|
|
265
|
+
}>(accountId, 'GET', `/channels/${channelId}/messages/${messageId}`);
|
|
266
|
+
const files: { path: string; mediaType: string }[] = [];
|
|
267
|
+
for (const att of msg.attachments) {
|
|
268
|
+
const res = await fetch(att.url, { signal: AbortSignal.timeout(60_000) });
|
|
269
|
+
if (!res.ok)
|
|
270
|
+
throw new Error(`discord-bot download ${res.status} for ${att.url}`);
|
|
271
|
+
assertContentLength(res.headers.get('content-length'));
|
|
272
|
+
const buf = await res.arrayBuffer();
|
|
273
|
+
const path = `${outDir}/${messageId}-${att.filename}`;
|
|
274
|
+
await Bun.write(path, buf);
|
|
275
|
+
files.push({
|
|
276
|
+
path,
|
|
277
|
+
mediaType: att.content_type ?? 'application/octet-stream',
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
respond(id, { result: { files, account: accountId } });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function threadCreate(
|
|
284
|
+
id: string,
|
|
285
|
+
args: Record<string, unknown>,
|
|
286
|
+
): Promise<void> {
|
|
287
|
+
const {
|
|
288
|
+
line,
|
|
289
|
+
messageId,
|
|
290
|
+
name,
|
|
291
|
+
autoArchiveDuration = 1440,
|
|
292
|
+
account,
|
|
293
|
+
} = args as {
|
|
294
|
+
line: string;
|
|
295
|
+
messageId?: string;
|
|
296
|
+
name: string;
|
|
297
|
+
autoArchiveDuration?: number;
|
|
298
|
+
account?: string;
|
|
299
|
+
};
|
|
300
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
301
|
+
const path = messageId
|
|
302
|
+
? `/channels/${channelId}/messages/${messageId}/threads`
|
|
303
|
+
: `/channels/${channelId}/threads`;
|
|
304
|
+
const res = await rest<{ id: string }>(accountId, 'POST', path, {
|
|
305
|
+
name,
|
|
306
|
+
auto_archive_duration: autoArchiveDuration,
|
|
307
|
+
});
|
|
308
|
+
respond(id, {
|
|
309
|
+
result: {
|
|
310
|
+
threadId: res.id,
|
|
311
|
+
line: lineOf(accountId, res.id),
|
|
312
|
+
account: accountId,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function pin(id: string, args: Record<string, unknown>): Promise<void> {
|
|
318
|
+
const { line, messageId, account } = args as {
|
|
319
|
+
line: string;
|
|
320
|
+
messageId: string;
|
|
321
|
+
account?: string;
|
|
322
|
+
};
|
|
323
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
324
|
+
await rest(accountId, 'PUT', `/channels/${channelId}/pins/${messageId}`);
|
|
325
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function typing(id: string, args: Record<string, unknown>): Promise<void> {
|
|
329
|
+
const { line, account } = args as { line: string; account?: string };
|
|
330
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
331
|
+
await rest(accountId, 'POST', `/channels/${channelId}/typing`);
|
|
332
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function channel(
|
|
336
|
+
id: string,
|
|
337
|
+
args: Record<string, unknown>,
|
|
338
|
+
): Promise<void> {
|
|
339
|
+
const { line, account } = args as { line: string; account?: string };
|
|
340
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
341
|
+
const res = await rest(accountId, 'GET', `/channels/${channelId}`);
|
|
342
|
+
respond(id, { result: res });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function listMembers(
|
|
346
|
+
id: string,
|
|
347
|
+
args: Record<string, unknown>,
|
|
348
|
+
): Promise<void> {
|
|
349
|
+
const { line, limit, account } = args as {
|
|
350
|
+
line: string;
|
|
351
|
+
limit?: number;
|
|
352
|
+
account?: string;
|
|
353
|
+
};
|
|
354
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
355
|
+
const result = await discordMembers(accountId, channelId, limit);
|
|
356
|
+
respond(id, { result });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const HANDLERS: Record<string, StationHandler> = {
|
|
360
|
+
accounts: (id) => {
|
|
361
|
+
listAccounts(id);
|
|
362
|
+
},
|
|
363
|
+
groupCreate: groupCreateHandler,
|
|
364
|
+
groupAddMembers: groupAddHandler,
|
|
365
|
+
groupRemoveMembers: groupRemoveHandler,
|
|
366
|
+
send,
|
|
367
|
+
react,
|
|
368
|
+
edit,
|
|
369
|
+
delete: remove,
|
|
370
|
+
fetch: fetchMessages,
|
|
371
|
+
download,
|
|
372
|
+
thread_create: threadCreate,
|
|
373
|
+
pin,
|
|
374
|
+
typing,
|
|
375
|
+
channel,
|
|
376
|
+
listMembers,
|
|
377
|
+
set_presence: presence,
|
|
378
|
+
joinVoice,
|
|
379
|
+
leaveVoice,
|
|
380
|
+
speak,
|
|
381
|
+
voiceDebug,
|
|
382
|
+
voiceTranscribe,
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export const handleCall = makeStation({
|
|
386
|
+
handlers: HANDLERS,
|
|
387
|
+
normalize: normalizeDiscord,
|
|
388
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const API = 'https://discord.com/api/v10';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
saveBufferToCache,
|
|
3
|
+
assertContentLength,
|
|
4
|
+
} from '@metro-labs/mcp/stations/attachments';
|
|
5
|
+
import type { SavedAttachment } from '@metro-labs/mcp/stations/attachments';
|
|
6
|
+
|
|
7
|
+
export type { SavedAttachment };
|
|
8
|
+
|
|
9
|
+
export interface DiscordAttachmentRef {
|
|
10
|
+
url: string;
|
|
11
|
+
name?: string | null;
|
|
12
|
+
contentType?: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function saveDiscordAttachment(
|
|
16
|
+
a: DiscordAttachmentRef,
|
|
17
|
+
messageId: string,
|
|
18
|
+
index = 0,
|
|
19
|
+
): Promise<SavedAttachment> {
|
|
20
|
+
const res = await fetch(a.url, { signal: AbortSignal.timeout(60_000) });
|
|
21
|
+
if (!res.ok)
|
|
22
|
+
throw new Error(`discord-bot attachment fetch ${res.status} for ${a.url}`);
|
|
23
|
+
assertContentLength(res.headers.get('content-length'));
|
|
24
|
+
const data = new Uint8Array(await res.arrayBuffer());
|
|
25
|
+
return saveBufferToCache(data, messageId, index, {
|
|
26
|
+
mime: a.contentType ?? undefined,
|
|
27
|
+
name: a.name ?? undefined,
|
|
28
|
+
});
|
|
29
|
+
}
|