@stage-labs/metro 0.1.0-beta.2 → 0.1.0-beta.21
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 +103 -0
- package/dist/cli.js +134 -565
- package/dist/control.js +102 -0
- package/dist/prompt.js +10 -0
- package/dist/runtime.js +94 -0
- package/dist/store.js +70 -0
- package/dist/update.js +33 -0
- package/dist/version.js +97 -0
- package/package.json +34 -22
- package/runtime/node_modules/@metro-labs/discord/package.json +28 -0
- package/runtime/node_modules/@metro-labs/discord/src/accounts.ts +119 -0
- package/runtime/node_modules/@metro-labs/discord/src/actions.ts +388 -0
- package/runtime/node_modules/@metro-labs/discord/src/api-base.ts +1 -0
- package/runtime/node_modules/@metro-labs/discord/src/attachments.ts +29 -0
- package/runtime/node_modules/@metro-labs/discord/src/format.ts +210 -0
- package/runtime/node_modules/@metro-labs/discord/src/group-actions.ts +50 -0
- package/runtime/node_modules/@metro-labs/discord/src/group.ts +115 -0
- package/runtime/node_modules/@metro-labs/discord/src/index.ts +127 -0
- package/runtime/node_modules/@metro-labs/discord/src/members.ts +215 -0
- package/runtime/node_modules/@metro-labs/discord/src/send-files.ts +43 -0
- package/runtime/node_modules/@metro-labs/discord/src/station.ts +19 -0
- package/runtime/node_modules/@metro-labs/discord/src/verify.ts +82 -0
- package/runtime/node_modules/@metro-labs/discord/src/voice-speak.ts +195 -0
- package/runtime/node_modules/@metro-labs/discord/src/voice-transcribe.ts +292 -0
- package/runtime/node_modules/@metro-labs/discord/src/voice.ts +197 -0
- package/runtime/node_modules/@metro-labs/discord/src/wire.ts +5 -0
- package/runtime/node_modules/@metro-labs/mcp/package.json +66 -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 +335 -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 +129 -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 +124 -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 +322 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +111 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +20 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +202 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-api.ts +338 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +31 -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/google-auth.ts +164 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +208 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/http.ts +357 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +79 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/log.ts +42 -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 +134 -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/run-api.ts +125 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +18 -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 +41 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +218 -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 +323 -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 +169 -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 +215 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +71 -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-collections.ts +218 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-config.ts +147 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +329 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/ids.ts +19 -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 +364 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +300 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +31 -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 +131 -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 +57 -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 +145 -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 +25 -0
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +120 -0
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +295 -0
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +128 -0
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +172 -0
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +103 -0
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +47 -0
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +17 -0
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +48 -0
- package/runtime/node_modules/@metro-labs/telegram/src/verify.ts +38 -0
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +3 -0
- package/runtime/node_modules/@metro-labs/telegram-user/package.json +28 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/accounts.ts +81 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/actions.ts +254 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/attachments.ts +87 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/client.ts +77 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/format.ts +141 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/group.ts +261 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/history.ts +52 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/inbound.ts +78 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/index.ts +46 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/login.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/media-actions.ts +80 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/members.ts +75 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/normalize.ts +22 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/reactions.ts +167 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/station.ts +24 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/types.ts +7 -0
- package/runtime/node_modules/@metro-labs/telegram-user/src/wire.ts +1 -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 -78
- package/dist/channels/discord.js +0 -148
- package/dist/channels/telegram.js +0 -137
- package/dist/lib/address.js +0 -21
- package/dist/lib/codex-rc.js +0 -274
- package/dist/lib/dotenv.js +0 -31
- package/dist/log.js +0 -12
- package/dist/paths.js +0 -45
- package/dist/tail.js +0 -161
- package/skills/metro/SKILL.md +0 -122
|
@@ -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 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 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
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { MessageFlags, type Message, type MessageReaction, type User } from 'discord.js';
|
|
2
|
+
import { accounts, lineOf } from './accounts.js';
|
|
3
|
+
import { emit, mintId, SELF_URI } from './wire.js';
|
|
4
|
+
import { saveDiscordAttachment } from './attachments.js';
|
|
5
|
+
|
|
6
|
+
export function emitInbound(
|
|
7
|
+
accountId: string,
|
|
8
|
+
e: Record<string, unknown>,
|
|
9
|
+
): void {
|
|
10
|
+
const owner = accounts.get(accountId)?.cfg.owner;
|
|
11
|
+
const payload = {
|
|
12
|
+
...(e.payload as Record<string, unknown> | undefined),
|
|
13
|
+
account: accountId,
|
|
14
|
+
};
|
|
15
|
+
emit({ ...e, ...(owner ? { to: owner } : {}), account: accountId, payload });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function emitAttachmentSaved(
|
|
19
|
+
accountId: string,
|
|
20
|
+
line: string,
|
|
21
|
+
sourceMsgId: string,
|
|
22
|
+
index: number,
|
|
23
|
+
ref: { url: string; name?: string | null; contentType?: string | null },
|
|
24
|
+
messageId: string,
|
|
25
|
+
): void {
|
|
26
|
+
void saveDiscordAttachment(ref, messageId, index)
|
|
27
|
+
.then((saved) => {
|
|
28
|
+
emitInbound(accountId, {
|
|
29
|
+
kind: 'inbound',
|
|
30
|
+
id: mintId(),
|
|
31
|
+
ts: new Date().toISOString(),
|
|
32
|
+
station: 'discord',
|
|
33
|
+
line,
|
|
34
|
+
from: SELF_URI,
|
|
35
|
+
text: `📎 saved: ${saved.path}`,
|
|
36
|
+
payload: {
|
|
37
|
+
contentType: 'attachmentSaved',
|
|
38
|
+
attachmentFor: sourceMsgId,
|
|
39
|
+
index,
|
|
40
|
+
attachmentPath: saved.path,
|
|
41
|
+
localPath: saved.path,
|
|
42
|
+
mime: saved.mime,
|
|
43
|
+
name: saved.name,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
})
|
|
47
|
+
.catch((err: unknown) =>
|
|
48
|
+
process.stderr.write(
|
|
49
|
+
`discord attachment save failed: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const AV_TAG: Record<string, string> = { audio: 'audio', video: 'video' };
|
|
55
|
+
|
|
56
|
+
function tagFor(att: {
|
|
57
|
+
contentType?: string | null;
|
|
58
|
+
name?: string | null;
|
|
59
|
+
voice?: boolean;
|
|
60
|
+
}): string {
|
|
61
|
+
const type = (att.contentType ?? '').split('/')[0] ?? '';
|
|
62
|
+
if (type === 'image') return '[image]';
|
|
63
|
+
if (att.voice && type === 'audio') return '[voice]';
|
|
64
|
+
const kind = AV_TAG[type] ?? 'file';
|
|
65
|
+
return `[${kind}: ${att.name ?? kind}]`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function messageEnvelope(
|
|
69
|
+
accountId: string,
|
|
70
|
+
m: Message,
|
|
71
|
+
): Record<string, unknown> | null {
|
|
72
|
+
if (m.author.bot) return null;
|
|
73
|
+
const voice = m.flags.has(MessageFlags.IsVoiceMessage);
|
|
74
|
+
const tags = m.attachments.map((a) =>
|
|
75
|
+
tagFor({ contentType: a.contentType, name: a.name, voice }),
|
|
76
|
+
);
|
|
77
|
+
const stickerTags = m.stickers.map((s) => `[sticker: ${s.name}]`);
|
|
78
|
+
const text = [m.content.trim(), ...tags, ...stickerTags]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(' ');
|
|
81
|
+
const line = lineOf(accountId, m.channelId);
|
|
82
|
+
const envId = mintId();
|
|
83
|
+
const attachments = [...m.attachments.values()].map((a) => ({
|
|
84
|
+
id: a.id,
|
|
85
|
+
url: a.url,
|
|
86
|
+
proxyURL: a.proxyURL,
|
|
87
|
+
name: a.name,
|
|
88
|
+
contentType: a.contentType,
|
|
89
|
+
size: a.size,
|
|
90
|
+
}));
|
|
91
|
+
attachments.forEach((a, i) => {
|
|
92
|
+
emitAttachmentSaved(
|
|
93
|
+
accountId,
|
|
94
|
+
line,
|
|
95
|
+
envId,
|
|
96
|
+
i,
|
|
97
|
+
{ url: a.url, name: a.name, contentType: a.contentType },
|
|
98
|
+
m.id,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
kind: 'inbound',
|
|
103
|
+
id: envId,
|
|
104
|
+
ts: new Date(m.createdTimestamp).toISOString(),
|
|
105
|
+
station: 'discord',
|
|
106
|
+
line,
|
|
107
|
+
line_name: 'name' in m.channel ? m.channel.name : undefined,
|
|
108
|
+
from: `metro://discord/${accountId}/user/${m.author.id}`,
|
|
109
|
+
from_name: m.author.username,
|
|
110
|
+
from_display_name: m.author.globalName ?? undefined,
|
|
111
|
+
message_id: m.id,
|
|
112
|
+
text,
|
|
113
|
+
is_private: m.guildId == null,
|
|
114
|
+
reply_to: m.reference?.messageId ?? undefined,
|
|
115
|
+
...(m.reference?.messageId
|
|
116
|
+
? { event: { type: 'reply', replyTo: m.reference.messageId } }
|
|
117
|
+
: {}),
|
|
118
|
+
payload: { ...(m.toJSON() as Record<string, unknown>), attachments },
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function reactionEnvelope(
|
|
123
|
+
accountId: string,
|
|
124
|
+
r: MessageReaction,
|
|
125
|
+
u: User,
|
|
126
|
+
): Record<string, unknown> | null {
|
|
127
|
+
if (u.bot) return null;
|
|
128
|
+
return {
|
|
129
|
+
kind: 'react',
|
|
130
|
+
id: mintId(),
|
|
131
|
+
ts: new Date().toISOString(),
|
|
132
|
+
station: 'discord',
|
|
133
|
+
line: lineOf(accountId, r.message.channelId),
|
|
134
|
+
from: `metro://discord/${accountId}/user/${u.id}`,
|
|
135
|
+
from_name: u.username,
|
|
136
|
+
from_display_name: u.globalName ?? undefined,
|
|
137
|
+
message_id: r.message.id,
|
|
138
|
+
emoji: r.emoji.name ?? r.emoji.id ?? '?',
|
|
139
|
+
is_private: r.message.guildId == null,
|
|
140
|
+
event: {
|
|
141
|
+
type: 'react',
|
|
142
|
+
emoji: r.emoji.name ?? r.emoji.id ?? '?',
|
|
143
|
+
targetId: r.message.id,
|
|
144
|
+
},
|
|
145
|
+
payload: {
|
|
146
|
+
channel_id: r.message.channelId,
|
|
147
|
+
guild_id: r.message.guildId,
|
|
148
|
+
emoji: r.emoji.toJSON(),
|
|
149
|
+
user_id: u.id,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function outbound(
|
|
155
|
+
kind: string,
|
|
156
|
+
accountId: string,
|
|
157
|
+
line: string,
|
|
158
|
+
messageId: string,
|
|
159
|
+
extra: object,
|
|
160
|
+
): void {
|
|
161
|
+
emit({
|
|
162
|
+
kind,
|
|
163
|
+
id: mintId(),
|
|
164
|
+
ts: new Date().toISOString(),
|
|
165
|
+
station: 'discord',
|
|
166
|
+
line,
|
|
167
|
+
from: SELF_URI,
|
|
168
|
+
to: line,
|
|
169
|
+
message_id: messageId,
|
|
170
|
+
...extra,
|
|
171
|
+
account: accountId,
|
|
172
|
+
payload: { account: accountId },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function emitOutbound(
|
|
177
|
+
accountId: string,
|
|
178
|
+
line: string,
|
|
179
|
+
messageId: string,
|
|
180
|
+
text: string,
|
|
181
|
+
replyTo?: string,
|
|
182
|
+
): void {
|
|
183
|
+
outbound('outbound', accountId, line, messageId, {
|
|
184
|
+
text,
|
|
185
|
+
reply_to: replyTo,
|
|
186
|
+
...(replyTo ? { event: { type: 'reply', replyTo } } : {}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
export function emitOutboundReact(
|
|
190
|
+
accountId: string,
|
|
191
|
+
line: string,
|
|
192
|
+
messageId: string,
|
|
193
|
+
emoji: string,
|
|
194
|
+
): void {
|
|
195
|
+
outbound('react', accountId, line, messageId, {
|
|
196
|
+
emoji,
|
|
197
|
+
event: { type: 'react', emoji, targetId: messageId },
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
export function emitOutboundEdit(
|
|
201
|
+
accountId: string,
|
|
202
|
+
line: string,
|
|
203
|
+
messageId: string,
|
|
204
|
+
text: string,
|
|
205
|
+
): void {
|
|
206
|
+
outbound('edit', accountId, line, messageId, {
|
|
207
|
+
text,
|
|
208
|
+
event: { type: 'edit', targetId: messageId },
|
|
209
|
+
});
|
|
210
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { routeOf, rest } from './accounts.js';
|
|
2
|
+
import { respond } from './wire.js';
|
|
3
|
+
import {
|
|
4
|
+
groupAddMembers,
|
|
5
|
+
groupCreate,
|
|
6
|
+
groupRemoveMembers,
|
|
7
|
+
} from './group.js';
|
|
8
|
+
|
|
9
|
+
export async function groupCreateHandler(
|
|
10
|
+
id: string,
|
|
11
|
+
args: Record<string, unknown>,
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
const { parent, account } = args as { parent?: string; account?: string };
|
|
14
|
+
if (!parent) {
|
|
15
|
+
respond(id, {
|
|
16
|
+
result: {
|
|
17
|
+
capability: {
|
|
18
|
+
supported: false,
|
|
19
|
+
reason:
|
|
20
|
+
'discord create_group requires `parent` (the metro:// line of the channel to open the thread under)',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { accountId, channelId } = routeOf(parent, account);
|
|
27
|
+
respond(id, { result: await groupCreate(rest, accountId, channelId, args) });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function groupAddHandler(
|
|
31
|
+
id: string,
|
|
32
|
+
args: Record<string, unknown>,
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const { line, account } = args as { line: string; account?: string };
|
|
35
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
36
|
+
respond(id, {
|
|
37
|
+
result: await groupAddMembers(rest, accountId, channelId, line, args),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function groupRemoveHandler(
|
|
42
|
+
id: string,
|
|
43
|
+
args: Record<string, unknown>,
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
const { line, account } = args as { line: string; account?: string };
|
|
46
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
47
|
+
respond(id, {
|
|
48
|
+
result: await groupRemoveMembers(rest, accountId, channelId, line, args),
|
|
49
|
+
});
|
|
50
|
+
}
|