@stage-labs/metro 0.1.0-beta.21 → 0.1.0-beta.211
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 +9 -101
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +152 -0
- package/dist/cli.js +52 -109
- package/dist/control.js +47 -75
- package/dist/hold.js +210 -0
- package/dist/local.js +43 -0
- package/dist/mcp-config.js +25 -0
- package/dist/node-name.js +71 -0
- package/dist/onboarding.js +44 -0
- package/dist/provider-flags.js +9 -0
- package/dist/route.js +58 -0
- package/dist/runtime-install.js +96 -0
- package/dist/runtime.js +29 -52
- package/dist/serve.js +157 -0
- package/dist/service.js +304 -0
- package/dist/tail.js +119 -0
- package/dist/update.js +13 -1
- package/package.json +2 -23
- package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +17 -0
- package/runtime/marketplace/plugin/.mcp.json +1 -0
- package/runtime/marketplace/plugin/bin/guard.mjs +71 -0
- package/runtime/marketplace/plugin/bin/metro-plugin.mjs +30 -0
- package/runtime/marketplace/plugin/bin/policy.mjs +97 -0
- package/runtime/marketplace/plugin/bin/session-start.mjs +31 -0
- package/runtime/marketplace/plugin/hooks/hooks.json +25 -0
- package/runtime/marketplace/plugin/orchestrator.md +26 -0
- package/runtime/node_modules/@metro-labs/core/package.json +47 -0
- package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/events.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp/src/db → core/src}/ids.ts +5 -0
- package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/stations → core/src}/lines.ts +24 -28
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/protocol.ts +7 -4
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/secure-fs.ts +17 -0
- package/runtime/node_modules/@metro-labs/core/src/station-names.ts +13 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +83 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/attachments.ts +0 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +58 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/station-runtime.ts +6 -11
- package/runtime/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/train-events.ts +84 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/types.ts +18 -1
- package/runtime/node_modules/@metro-labs/core/src/tickets.ts +37 -0
- package/runtime/node_modules/@metro-labs/core/src/version.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/package.json +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/agent-fs.ts +134 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files-api.ts +12 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +89 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/home-fs.ts +113 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/job-env.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/provision.ts +80 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedule-detail.ts +99 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules-api.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +144 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/unit-files.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +89 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-lookups.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +76 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +357 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +30 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +59 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +305 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +142 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/key-map.ts → daemon/src/agents/keys.ts} +1 -11
- package/runtime/node_modules/@metro-labs/{mcp/src/db/agent-map.ts → daemon/src/agents/map.ts} +58 -1
- package/runtime/node_modules/@metro-labs/daemon/src/agents/policy-route.ts +27 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/agent-scope.ts → daemon/src/agents/scope.ts} +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +94 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/api.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/pending.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/preview.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +218 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +36 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/crash-guard.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +21 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/paths.ts +6 -34
- package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +26 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/inbound.ts +70 -45
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/media-note.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/pending.ts +4 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/relay.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +355 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +359 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/memory.ts +32 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +149 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +75 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +313 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +109 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +273 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/version.ts +113 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-api.ts → daemon/src/connectors/api.ts} +79 -113
- package/runtime/node_modules/@metro-labs/{mcp/src/db/connector-config.ts → daemon/src/connectors/config.ts} +67 -41
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/health.ts +18 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-client.ts +14 -17
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-discovery.ts +33 -20
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth-routes.ts → daemon/src/connectors/oauth-routes.ts} +30 -32
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth.ts → daemon/src/connectors/oauth.ts} +61 -22
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-policy.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +347 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +385 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +81 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +106 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-grant.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-owner.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-reaper.ts +174 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-serve.ts +12 -13
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-api.ts +10 -27
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-store.ts +4 -4
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +233 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-device.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-stream.ts +173 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +195 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-version.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +128 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +77 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +237 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/frames.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +274 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-auth.ts +160 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-client.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-setup.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-stream.ts +139 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-translate.ts +224 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +199 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +278 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +193 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-store.ts +70 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/pkce.ts +36 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/subscription.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/text.ts +14 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +244 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/accounts.ts +28 -17
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/attachment-schema.ts +91 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/call-tools.ts +49 -20
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/ctx.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/event-store.ts +15 -16
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/group-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/index.ts +24 -79
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/instructions.ts +19 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/member-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-prompt.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +82 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-snapshot.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-lookup.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-tool.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/read-tool.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-slot.ts +48 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/session.ts +33 -42
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +88 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-def.ts +9 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-dispatch.ts +53 -40
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-schemas.ts +68 -119
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/upload-tool.ts +6 -11
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/privilege.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +316 -0
- package/runtime/node_modules/@metro-labs/daemon/src/policy/policy.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/bearer.ts +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/routes}/http.ts +59 -51
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +205 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session.ts +29 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/threema-callback.ts +103 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/control.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +58 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/owner.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-driver.ts +42 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-inline.ts +29 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-interactive.ts +9 -36
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-outlook.ts +63 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-resolve.ts +38 -13
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/attach-session.ts +32 -22
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-xmtp.ts +8 -9
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach.ts +75 -9
- package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +265 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/registry.ts +22 -6
- package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor-io.ts +3 -3
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor.ts +6 -9
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +32 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/train-call.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +84 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +124 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +15 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/api.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/config.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/firewall.ts +9 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/index.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/install.ts +56 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/paths.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/proxy.ts +147 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/store.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/trust.ts +44 -0
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/package.json +3 -5
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/accounts.ts +8 -28
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/actions.ts +19 -187
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/attachments.ts +3 -3
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/format.ts +31 -72
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/group-actions.ts +2 -2
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/index.ts +15 -21
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/members.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +68 -0
- package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/send-files.ts +12 -13
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +23 -0
- package/runtime/node_modules/@metro-labs/http/package.json +29 -0
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +135 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/session-api.ts → http/src/mode-api.ts} +13 -9
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +21 -0
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +149 -0
- package/runtime/node_modules/@metro-labs/{telegram-user → outlook}/package.json +2 -5
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +93 -0
- package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +97 -0
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +150 -0
- package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +53 -0
- package/runtime/node_modules/@metro-labs/outlook/src/config.ts +36 -0
- package/runtime/node_modules/@metro-labs/outlook/src/format.ts +140 -0
- package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +60 -0
- package/runtime/node_modules/@metro-labs/outlook/src/html.ts +72 -0
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +104 -0
- package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/outlook/src/login.ts +150 -0
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +41 -0
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +116 -0
- package/runtime/node_modules/@metro-labs/outlook/src/query.ts +119 -0
- package/runtime/node_modules/@metro-labs/outlook/src/state.ts +43 -0
- package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +3 -2
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +38 -96
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +214 -253
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +67 -108
- package/runtime/node_modules/@metro-labs/{telegram-user → telegram}/src/client.ts +6 -6
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +101 -147
- package/runtime/node_modules/@metro-labs/{telegram-user → telegram}/src/group.ts +4 -4
- package/runtime/node_modules/@metro-labs/{telegram-user → telegram}/src/history.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +57 -0
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +6 -102
- package/runtime/node_modules/@metro-labs/{telegram-user → telegram}/src/login.ts +20 -20
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +64 -151
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +61 -33
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +70 -0
- package/runtime/node_modules/@metro-labs/{telegram-user → telegram}/src/reactions.ts +3 -3
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +11 -1
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +5 -47
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +25 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +86 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +240 -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 +170 -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 +90 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +47 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +85 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +21 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +56 -0
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +95 -0
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +124 -0
- package/runtime/node_modules/@metro-labs/threema/src/api.ts +152 -0
- package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +100 -0
- package/runtime/node_modules/@metro-labs/threema/src/files.ts +47 -0
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +164 -0
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +96 -0
- package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +89 -0
- package/runtime/node_modules/@metro-labs/threema/src/index.ts +24 -0
- package/runtime/node_modules/@metro-labs/threema/src/messages.ts +264 -0
- package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +160 -0
- package/runtime/node_modules/@metro-labs/threema/src/station.ts +13 -0
- package/runtime/node_modules/@metro-labs/threema/src/verify.ts +117 -0
- package/runtime/node_modules/@metro-labs/webhook/package.json +1 -1
- package/runtime/node_modules/@metro-labs/webhook/src/station.ts +5 -8
- package/runtime/node_modules/@metro-labs/whatsapp/package.json +2 -5
- package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +6 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +54 -11
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +86 -4
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +7 -58
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +11 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +4 -37
- package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/names.ts +75 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +44 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/resolve.ts +52 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +16 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +5 -9
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/xmtp/package.json +3 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +10 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +15 -204
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +4 -43
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +41 -219
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +7 -24
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +8 -18
- package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +30 -16
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +12 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +1 -19
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +61 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +153 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +112 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/smart.ts +72 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +4 -51
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +30 -44
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +4 -6
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +19 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +14 -4
- package/runtime/runtime.json +1 -1
- package/runtime/server.ts +1 -0
- package/runtime/stations.json +37 -0
- package/dist/prompt.js +0 -10
- package/dist/store.js +0 -70
- package/runtime/node_modules/@metro-labs/discord/src/station.ts +0 -19
- package/runtime/node_modules/@metro-labs/discord/src/voice-speak.ts +0 -195
- package/runtime/node_modules/@metro-labs/discord/src/voice-transcribe.ts +0 -292
- package/runtime/node_modules/@metro-labs/discord/src/voice.ts +0 -197
- package/runtime/node_modules/@metro-labs/discord/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/mcp/package.json +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +0 -24
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +0 -311
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +0 -335
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +0 -129
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +0 -322
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +0 -111
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +0 -20
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +0 -202
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +0 -31
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +0 -100
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +0 -333
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-auth.ts +0 -164
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +0 -208
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +0 -79
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +0 -65
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +0 -58
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +0 -214
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +0 -125
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +0 -41
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +0 -169
- package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +0 -91
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +0 -215
- package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +0 -37
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-collections.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +0 -329
- package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +0 -364
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +0 -300
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +0 -31
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +0 -131
- package/runtime/node_modules/@metro-labs/mcp/src/db/token-carry.ts +0 -45
- package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +0 -29
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +0 -21
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +0 -73
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +0 -172
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +0 -43
- package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +0 -240
- package/runtime/node_modules/@metro-labs/mcp/src/server.ts +0 -2
- package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +0 -80
- package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +0 -88
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +0 -3
- package/runtime/node_modules/@metro-labs/telegram-user/src/accounts.ts +0 -81
- package/runtime/node_modules/@metro-labs/telegram-user/src/actions.ts +0 -254
- package/runtime/node_modules/@metro-labs/telegram-user/src/attachments.ts +0 -87
- package/runtime/node_modules/@metro-labs/telegram-user/src/format.ts +0 -141
- package/runtime/node_modules/@metro-labs/telegram-user/src/inbound.ts +0 -78
- package/runtime/node_modules/@metro-labs/telegram-user/src/index.ts +0 -46
- package/runtime/node_modules/@metro-labs/telegram-user/src/media-actions.ts +0 -80
- package/runtime/node_modules/@metro-labs/telegram-user/src/members.ts +0 -75
- package/runtime/node_modules/@metro-labs/telegram-user/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/telegram-user/src/station.ts +0 -24
- package/runtime/node_modules/@metro-labs/telegram-user/src/types.ts +0 -7
- package/runtime/node_modules/@metro-labs/telegram-user/src/wire.ts +0 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +0 -87
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +0 -55
- package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +0 -349
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/log.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/mcp → core/src}/str.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/train-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/webhook-note.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/raw-get-stream.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/api-base.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{discord → discord-bot}/src/verify.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/api-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/cors.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{telegram → telegram-bot}/src/verify.ts +0 -0
|
@@ -1,32 +1,19 @@
|
|
|
1
|
+
import type { Message } from 'discord.js';
|
|
1
2
|
import {
|
|
2
|
-
ActivityType,
|
|
3
|
-
type Message,
|
|
4
|
-
type PresenceStatusData,
|
|
5
|
-
} from 'discord.js';
|
|
6
|
-
import {
|
|
7
|
-
accountFor,
|
|
8
3
|
accounts,
|
|
9
4
|
encodeEmoji,
|
|
10
|
-
lineOf,
|
|
11
5
|
rest,
|
|
12
6
|
routeOf,
|
|
13
7
|
} from './accounts.js';
|
|
14
8
|
import { emitOutbound, emitOutboundEdit, emitOutboundReact } from './format.js';
|
|
15
|
-
import {
|
|
16
|
-
import { normalizeDiscord } from '@metro-labs/mcp/stations/messaging-normalize';
|
|
17
|
-
import { assertContentLength } from '@metro-labs/mcp/stations/attachments';
|
|
9
|
+
import { messagingAliases } from '@metro-labs/core/stations/messaging-normalize';
|
|
18
10
|
import {
|
|
19
11
|
appendFiles,
|
|
20
12
|
outgoingFiles,
|
|
21
13
|
type OutgoingFile,
|
|
22
14
|
} from './send-files.js';
|
|
23
|
-
import {
|
|
24
|
-
|
|
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';
|
|
15
|
+
import { makeStation, respond, type CallMsg, type StationHandler } from '@metro-labs/core/stations/station-runtime';
|
|
16
|
+
import { readProfile, setProfile } from './profile.js';
|
|
30
17
|
import { discordMembers } from './members.js';
|
|
31
18
|
import {
|
|
32
19
|
groupAddHandler,
|
|
@@ -65,40 +52,17 @@ async function sendMessage(
|
|
|
65
52
|
export type { CallMsg };
|
|
66
53
|
|
|
67
54
|
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 {
|
|
55
|
+
const { line, text, replyTo, account } = args as {
|
|
80
56
|
line: string;
|
|
81
57
|
text?: string;
|
|
82
58
|
replyTo?: string;
|
|
83
|
-
embeds?: unknown[];
|
|
84
|
-
stickerIds?: string[];
|
|
85
|
-
images?: string[];
|
|
86
|
-
files?: string[];
|
|
87
59
|
account?: string;
|
|
88
|
-
attachmentKinds?: string[];
|
|
89
|
-
attachmentNames?: string[];
|
|
90
60
|
};
|
|
91
61
|
const { accountId, channelId } = routeOf(line, account);
|
|
92
62
|
const body: Record<string, unknown> = { flags: 4 };
|
|
93
63
|
if (text !== undefined) body.content = text;
|
|
94
64
|
if (replyTo) body.message_reference = { message_id: replyTo };
|
|
95
|
-
|
|
96
|
-
if (stickerIds) body.sticker_ids = stickerIds;
|
|
97
|
-
const outgoing = outgoingFiles(
|
|
98
|
-
[...(images ?? []), ...(files ?? [])],
|
|
99
|
-
attachmentNames,
|
|
100
|
-
attachmentKinds,
|
|
101
|
-
);
|
|
65
|
+
const outgoing = outgoingFiles(args.attachments);
|
|
102
66
|
const res = await sendMessage(accountId, channelId, body, outgoing);
|
|
103
67
|
emitOutbound(accountId, line, res.id, text ?? '', replyTo);
|
|
104
68
|
respond(id, {
|
|
@@ -110,38 +74,6 @@ async function send(id: string, args: Record<string, unknown>): Promise<void> {
|
|
|
110
74
|
});
|
|
111
75
|
}
|
|
112
76
|
|
|
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
77
|
const profileUrl = (userId?: string): string | null =>
|
|
146
78
|
userId === undefined ? null : `https://discord.com/users/${userId}`;
|
|
147
79
|
|
|
@@ -154,13 +86,19 @@ function listAccounts(id: string): void {
|
|
|
154
86
|
url: profileUrl(a.client.user?.id),
|
|
155
87
|
userId: a.client.user?.id ?? null,
|
|
156
88
|
username: a.client.user?.username ?? null,
|
|
157
|
-
owner: a.cfg.owner ?? null,
|
|
158
89
|
ready: a.client.isReady(),
|
|
159
90
|
})),
|
|
160
91
|
},
|
|
161
92
|
});
|
|
162
93
|
}
|
|
163
94
|
|
|
95
|
+
async function typing(id: string, args: Record<string, unknown>): Promise<void> {
|
|
96
|
+
const { line, account } = args as { line: string; account?: string };
|
|
97
|
+
const { accountId, channelId } = routeOf(line, account);
|
|
98
|
+
await rest(accountId, 'POST', `/channels/${channelId}/typing`);
|
|
99
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
100
|
+
}
|
|
101
|
+
|
|
164
102
|
async function react(id: string, args: Record<string, unknown>): Promise<void> {
|
|
165
103
|
const { line, messageId, emoji, account } = args as {
|
|
166
104
|
line: string;
|
|
@@ -216,7 +154,7 @@ async function remove(
|
|
|
216
154
|
respond(id, { result: { ok: true, account: accountId } });
|
|
217
155
|
}
|
|
218
156
|
|
|
219
|
-
async function
|
|
157
|
+
async function read(
|
|
220
158
|
id: string,
|
|
221
159
|
args: Record<string, unknown>,
|
|
222
160
|
): Promise<void> {
|
|
@@ -244,104 +182,6 @@ async function fetchMessages(
|
|
|
244
182
|
respond(id, { result: { messages: msgs, account: accountId } });
|
|
245
183
|
}
|
|
246
184
|
|
|
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
185
|
async function listMembers(
|
|
346
186
|
id: string,
|
|
347
187
|
args: Record<string, unknown>,
|
|
@@ -365,24 +205,16 @@ const HANDLERS: Record<string, StationHandler> = {
|
|
|
365
205
|
groupRemoveMembers: groupRemoveHandler,
|
|
366
206
|
send,
|
|
367
207
|
react,
|
|
208
|
+
typing,
|
|
368
209
|
edit,
|
|
369
210
|
delete: remove,
|
|
370
|
-
|
|
371
|
-
download,
|
|
372
|
-
thread_create: threadCreate,
|
|
373
|
-
pin,
|
|
374
|
-
typing,
|
|
375
|
-
channel,
|
|
211
|
+
read,
|
|
376
212
|
listMembers,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
leaveVoice,
|
|
380
|
-
speak,
|
|
381
|
-
voiceDebug,
|
|
382
|
-
voiceTranscribe,
|
|
213
|
+
set_profile: setProfile,
|
|
214
|
+
profile: readProfile,
|
|
383
215
|
};
|
|
384
216
|
|
|
385
217
|
export const handleCall = makeStation({
|
|
386
218
|
handlers: HANDLERS,
|
|
387
|
-
normalize:
|
|
219
|
+
normalize: messagingAliases(),
|
|
388
220
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
saveBufferToCache,
|
|
3
3
|
assertContentLength,
|
|
4
|
-
} from '@metro-labs/
|
|
5
|
-
import type { SavedAttachment } from '@metro-labs/
|
|
4
|
+
} from '@metro-labs/core/stations/attachments';
|
|
5
|
+
import type { SavedAttachment } from '@metro-labs/core/stations/attachments';
|
|
6
6
|
|
|
7
7
|
export type { SavedAttachment };
|
|
8
8
|
|
|
@@ -19,7 +19,7 @@ export async function saveDiscordAttachment(
|
|
|
19
19
|
): Promise<SavedAttachment> {
|
|
20
20
|
const res = await fetch(a.url, { signal: AbortSignal.timeout(60_000) });
|
|
21
21
|
if (!res.ok)
|
|
22
|
-
throw new Error(`discord attachment fetch ${res.status} for ${a.url}`);
|
|
22
|
+
throw new Error(`discord-bot attachment fetch ${res.status} for ${a.url}`);
|
|
23
23
|
assertContentLength(res.headers.get('content-length'));
|
|
24
24
|
const data = new Uint8Array(await res.arrayBuffer());
|
|
25
25
|
return saveBufferToCache(data, messageId, index, {
|
|
@@ -1,56 +1,9 @@
|
|
|
1
1
|
import { MessageFlags, type Message, type MessageReaction, type User } from 'discord.js';
|
|
2
|
+
import { reportAttachment, selfUri } from '@metro-labs/core/stations/train-events';
|
|
2
3
|
import { accounts, lineOf } from './accounts.js';
|
|
3
|
-
import { emit, mintId
|
|
4
|
+
import { emit, mintId } from '@metro-labs/core/stations/station-runtime';
|
|
4
5
|
import { saveDiscordAttachment } from './attachments.js';
|
|
5
6
|
|
|
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
7
|
const AV_TAG: Record<string, string> = { audio: 'audio', video: 'video' };
|
|
55
8
|
|
|
56
9
|
function tagFor(att: {
|
|
@@ -65,6 +18,20 @@ function tagFor(att: {
|
|
|
65
18
|
return `[${kind}: ${att.name ?? kind}]`;
|
|
66
19
|
}
|
|
67
20
|
|
|
21
|
+
function addressing(accountId: string, m: Message): { mentions_self: boolean; reply_to_self: boolean } {
|
|
22
|
+
const me = accounts.get(accountId)?.client.user ?? null;
|
|
23
|
+
if (me === null) return { mentions_self: false, reply_to_self: false };
|
|
24
|
+
return {
|
|
25
|
+
mentions_self: m.mentions.has(me, { ignoreRepliedUser: true, ignoreEveryone: true }),
|
|
26
|
+
reply_to_self: m.mentions.repliedUser?.id === me.id,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const senderOf = (m: Message): Record<string, string | undefined> => ({
|
|
31
|
+
from_name: m.author.username,
|
|
32
|
+
from_display_name: m.member?.displayName ?? m.author.globalName ?? undefined,
|
|
33
|
+
});
|
|
34
|
+
|
|
68
35
|
export function messageEnvelope(
|
|
69
36
|
accountId: string,
|
|
70
37
|
m: Message,
|
|
@@ -89,29 +56,25 @@ export function messageEnvelope(
|
|
|
89
56
|
size: a.size,
|
|
90
57
|
}));
|
|
91
58
|
attachments.forEach((a, i) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
line,
|
|
95
|
-
|
|
96
|
-
i,
|
|
97
|
-
{ url: a.url, name: a.name, contentType: a.contentType },
|
|
98
|
-
m.id,
|
|
59
|
+
reportAttachment(
|
|
60
|
+
saveDiscordAttachment({ url: a.url, name: a.name, contentType: a.contentType }, m.id, i),
|
|
61
|
+
{ station: 'discord-bot', account: accountId, line, forId: envId, index: i },
|
|
62
|
+
{ failed: { name: a.name, mime: a.contentType ?? undefined } },
|
|
99
63
|
);
|
|
100
64
|
});
|
|
101
65
|
return {
|
|
102
|
-
kind: 'inbound',
|
|
103
66
|
id: envId,
|
|
104
67
|
ts: new Date(m.createdTimestamp).toISOString(),
|
|
105
|
-
station: 'discord',
|
|
68
|
+
station: 'discord-bot',
|
|
106
69
|
line,
|
|
107
70
|
line_name: 'name' in m.channel ? m.channel.name : undefined,
|
|
108
|
-
from: `metro://discord/${accountId}/user/${m.author.id}`,
|
|
109
|
-
|
|
110
|
-
from_display_name: m.author.globalName ?? undefined,
|
|
71
|
+
from: `metro://discord-bot/${accountId}/user/${m.author.id}`,
|
|
72
|
+
...senderOf(m),
|
|
111
73
|
message_id: m.id,
|
|
112
74
|
text,
|
|
113
75
|
is_private: m.guildId == null,
|
|
114
76
|
reply_to: m.reference?.messageId ?? undefined,
|
|
77
|
+
...addressing(accountId, m),
|
|
115
78
|
...(m.reference?.messageId
|
|
116
79
|
? { event: { type: 'reply', replyTo: m.reference.messageId } }
|
|
117
80
|
: {}),
|
|
@@ -126,12 +89,11 @@ export function reactionEnvelope(
|
|
|
126
89
|
): Record<string, unknown> | null {
|
|
127
90
|
if (u.bot) return null;
|
|
128
91
|
return {
|
|
129
|
-
kind: 'react',
|
|
130
92
|
id: mintId(),
|
|
131
93
|
ts: new Date().toISOString(),
|
|
132
|
-
station: 'discord',
|
|
94
|
+
station: 'discord-bot',
|
|
133
95
|
line: lineOf(accountId, r.message.channelId),
|
|
134
|
-
from: `metro://discord/${accountId}/user/${u.id}`,
|
|
96
|
+
from: `metro://discord-bot/${accountId}/user/${u.id}`,
|
|
135
97
|
from_name: u.username,
|
|
136
98
|
from_display_name: u.globalName ?? undefined,
|
|
137
99
|
message_id: r.message.id,
|
|
@@ -152,23 +114,20 @@ export function reactionEnvelope(
|
|
|
152
114
|
}
|
|
153
115
|
|
|
154
116
|
function outbound(
|
|
155
|
-
kind: string,
|
|
156
117
|
accountId: string,
|
|
157
118
|
line: string,
|
|
158
119
|
messageId: string,
|
|
159
120
|
extra: object,
|
|
160
121
|
): void {
|
|
161
122
|
emit({
|
|
162
|
-
kind,
|
|
163
123
|
id: mintId(),
|
|
164
124
|
ts: new Date().toISOString(),
|
|
165
|
-
station: 'discord',
|
|
125
|
+
station: 'discord-bot',
|
|
166
126
|
line,
|
|
167
|
-
from:
|
|
127
|
+
from: selfUri(),
|
|
168
128
|
to: line,
|
|
169
129
|
message_id: messageId,
|
|
170
130
|
...extra,
|
|
171
|
-
account: accountId,
|
|
172
131
|
payload: { account: accountId },
|
|
173
132
|
});
|
|
174
133
|
}
|
|
@@ -180,7 +139,7 @@ export function emitOutbound(
|
|
|
180
139
|
text: string,
|
|
181
140
|
replyTo?: string,
|
|
182
141
|
): void {
|
|
183
|
-
outbound(
|
|
142
|
+
outbound(accountId, line, messageId, {
|
|
184
143
|
text,
|
|
185
144
|
reply_to: replyTo,
|
|
186
145
|
...(replyTo ? { event: { type: 'reply', replyTo } } : {}),
|
|
@@ -192,7 +151,7 @@ export function emitOutboundReact(
|
|
|
192
151
|
messageId: string,
|
|
193
152
|
emoji: string,
|
|
194
153
|
): void {
|
|
195
|
-
outbound(
|
|
154
|
+
outbound(accountId, line, messageId, {
|
|
196
155
|
emoji,
|
|
197
156
|
event: { type: 'react', emoji, targetId: messageId },
|
|
198
157
|
});
|
|
@@ -203,7 +162,7 @@ export function emitOutboundEdit(
|
|
|
203
162
|
messageId: string,
|
|
204
163
|
text: string,
|
|
205
164
|
): void {
|
|
206
|
-
outbound(
|
|
165
|
+
outbound(accountId, line, messageId, {
|
|
207
166
|
text,
|
|
208
167
|
event: { type: 'edit', targetId: messageId },
|
|
209
168
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { routeOf, rest } from './accounts.js';
|
|
2
|
-
import { respond } from '
|
|
2
|
+
import { respond } from '@metro-labs/core/stations/station-runtime';
|
|
3
3
|
import {
|
|
4
4
|
groupAddMembers,
|
|
5
5
|
groupCreate,
|
|
@@ -17,7 +17,7 @@ export async function groupCreateHandler(
|
|
|
17
17
|
capability: {
|
|
18
18
|
supported: false,
|
|
19
19
|
reason:
|
|
20
|
-
'discord create_group requires `parent` (the metro:// line of the channel to open the thread under)',
|
|
20
|
+
'discord-bot create_group requires `parent` (the metro:// line of the channel to open the thread under)',
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { errMsg } from '@metro-labs/
|
|
1
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
2
2
|
import type {
|
|
3
3
|
GroupResult,
|
|
4
4
|
MemberOutcome,
|
|
5
|
-
} from '@metro-labs/
|
|
5
|
+
} from '@metro-labs/core/stations/types';
|
|
6
6
|
import { lineOf } from './accounts.js';
|
|
7
7
|
|
|
8
8
|
export type RestFn = <T = unknown>(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errMsg } from '@metro-labs/
|
|
1
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
2
2
|
import {
|
|
3
3
|
Client,
|
|
4
4
|
Events,
|
|
@@ -14,12 +14,14 @@ import {
|
|
|
14
14
|
lineOf,
|
|
15
15
|
type AccountConfig,
|
|
16
16
|
} from './accounts.js';
|
|
17
|
-
import { emitInbound
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
17
|
+
import { emitInbound } from '@metro-labs/core/stations/train-events';
|
|
18
|
+
import { messageEnvelope, reactionEnvelope } from './format.js';
|
|
19
|
+
import { mintId } from '@metro-labs/core/stations/station-runtime';
|
|
20
|
+
import { readCalls } from '@metro-labs/core/trains/protocol';
|
|
21
|
+
import { announceAccounts } from '@metro-labs/core/stations/train-boot';
|
|
20
22
|
import { handleCall } from './actions.js';
|
|
21
23
|
|
|
22
|
-
readCalls('discord', handleCall);
|
|
24
|
+
readCalls('discord-bot', handleCall);
|
|
23
25
|
|
|
24
26
|
function makeClient(): Client {
|
|
25
27
|
return new Client({
|
|
@@ -30,7 +32,6 @@ function makeClient(): Client {
|
|
|
30
32
|
GatewayIntentBits.GuildMessageReactions,
|
|
31
33
|
GatewayIntentBits.DirectMessages,
|
|
32
34
|
GatewayIntentBits.DirectMessageReactions,
|
|
33
|
-
GatewayIntentBits.GuildVoiceStates,
|
|
34
35
|
],
|
|
35
36
|
partials: [
|
|
36
37
|
Partials.Channel,
|
|
@@ -44,12 +45,11 @@ function makeClient(): Client {
|
|
|
44
45
|
function onEdit(accountId: string, m: Message): void {
|
|
45
46
|
if (m.author.bot) return;
|
|
46
47
|
emitInbound(accountId, {
|
|
47
|
-
kind: 'edit',
|
|
48
48
|
id: mintId(),
|
|
49
49
|
ts: new Date(m.editedTimestamp ?? Date.now()).toISOString(),
|
|
50
|
-
station: 'discord',
|
|
50
|
+
station: 'discord-bot',
|
|
51
51
|
line: lineOf(accountId, m.channelId),
|
|
52
|
-
from: `metro://discord/${accountId}/user/${m.author.id}`,
|
|
52
|
+
from: `metro://discord-bot/${accountId}/user/${m.author.id}`,
|
|
53
53
|
from_name: m.author.username,
|
|
54
54
|
from_display_name: m.author.globalName ?? undefined,
|
|
55
55
|
message_id: m.id,
|
|
@@ -80,7 +80,7 @@ async function bootAccount(cfg: AccountConfig): Promise<void> {
|
|
|
80
80
|
if (env) emitInbound(accountId, env);
|
|
81
81
|
})().catch((err: unknown) => {
|
|
82
82
|
process.stderr.write(
|
|
83
|
-
`discord[${accountId}] reaction handler failed: ${errMsg(err)}\n`,
|
|
83
|
+
`discord-bot[${accountId}] reaction handler failed: ${errMsg(err)}\n`,
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
});
|
|
@@ -91,12 +91,12 @@ async function bootAccount(cfg: AccountConfig): Promise<void> {
|
|
|
91
91
|
onEdit(accountId, _new.partial ? await _new.fetch() : _new);
|
|
92
92
|
} catch (err) {
|
|
93
93
|
process.stderr.write(
|
|
94
|
-
`discord[${accountId}] message update fetch failed: ${errMsg(err)}\n`,
|
|
94
|
+
`discord-bot[${accountId}] message update fetch failed: ${errMsg(err)}\n`,
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
})().catch((err: unknown) => {
|
|
98
98
|
process.stderr.write(
|
|
99
|
-
`discord[${accountId}] message update handler failed: ${errMsg(err)}\n`,
|
|
99
|
+
`discord-bot[${accountId}] message update handler failed: ${errMsg(err)}\n`,
|
|
100
100
|
);
|
|
101
101
|
});
|
|
102
102
|
});
|
|
@@ -104,7 +104,7 @@ async function bootAccount(cfg: AccountConfig): Promise<void> {
|
|
|
104
104
|
accounts.set(accountId, { cfg, client });
|
|
105
105
|
await client.login(cfg.token);
|
|
106
106
|
process.stderr.write(
|
|
107
|
-
`discord[${accountId}] ready — ${client.user?.tag ?? '?'}
|
|
107
|
+
`discord-bot[${accountId}] ready — ${client.user?.tag ?? '?'}\n`,
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -114,14 +114,8 @@ for (const cfg of cfgs) {
|
|
|
114
114
|
await bootAccount(cfg);
|
|
115
115
|
} catch (err) {
|
|
116
116
|
process.stderr.write(
|
|
117
|
-
`discord[${cfg.id}] boot FAILED: ${errMsg(err)}\n`,
|
|
117
|
+
`discord-bot[${cfg.id}] boot FAILED: ${errMsg(err)}\n`,
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
process.stderr.write('discord: no accounts booted, exiting\n');
|
|
123
|
-
process.exit(2);
|
|
124
|
-
}
|
|
125
|
-
process.stderr.write(
|
|
126
|
-
`discord train ready — ${accounts.size} account(s): ${[...accounts.keys()].join(', ')}\n`,
|
|
127
|
-
);
|
|
121
|
+
announceAccounts('discord-bot', accounts.keys());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { errMsg } from '@metro-labs/
|
|
2
|
-
import type { MemberList, MetroMember } from '@metro-labs/
|
|
1
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
2
|
+
import type { MemberList, MetroMember } from '@metro-labs/core/stations/types';
|
|
3
3
|
import { rest } from './accounts.js';
|
|
4
4
|
|
|
5
5
|
export interface DiscordRole {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import type { Client } from 'discord.js';
|
|
3
|
+
import { TrainError } from '@metro-labs/core/train-error';
|
|
4
|
+
import {
|
|
5
|
+
assertImage,
|
|
6
|
+
fieldsOf,
|
|
7
|
+
parseProfileChange,
|
|
8
|
+
type ProfileApplied,
|
|
9
|
+
type ProfileChange,
|
|
10
|
+
} from '@metro-labs/core/stations/profile';
|
|
11
|
+
import type { SenderProfile } from '@metro-labs/core/stations/sender-profile';
|
|
12
|
+
import { accountFor, accounts } from './accounts.js';
|
|
13
|
+
import { respond } from '@metro-labs/core/stations/station-runtime';
|
|
14
|
+
|
|
15
|
+
export async function applyProfile(
|
|
16
|
+
client: Client,
|
|
17
|
+
change: ProfileChange,
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
const user = client.user;
|
|
20
|
+
if (!user) throw new TrainError('discord_not_ready', 'the gateway is not ready yet');
|
|
21
|
+
if (change.avatar !== undefined) assertImage(change.avatar);
|
|
22
|
+
const avatar = change.avatar === undefined ? undefined : await readFile(change.avatar.path);
|
|
23
|
+
if (change.name !== undefined || avatar !== undefined)
|
|
24
|
+
await user.edit({
|
|
25
|
+
...(change.name === undefined ? {} : { username: change.name }),
|
|
26
|
+
...(avatar === undefined ? {} : { avatar }),
|
|
27
|
+
});
|
|
28
|
+
if (change.bio !== undefined) {
|
|
29
|
+
const app = client.application;
|
|
30
|
+
if (!app) throw new TrainError('discord_not_ready', 'the application is not loaded yet');
|
|
31
|
+
await app.edit({ description: change.bio });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function setProfile(
|
|
36
|
+
id: string,
|
|
37
|
+
args: Record<string, unknown>,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const accountId = accountFor({ account: args.account as string | undefined });
|
|
40
|
+
const acct = accounts.get(accountId);
|
|
41
|
+
if (!acct) {
|
|
42
|
+
respond(id, { error: `unknown account '${accountId}'` });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const change = parseProfileChange(args);
|
|
46
|
+
await applyProfile(acct.client, change);
|
|
47
|
+
const result: ProfileApplied = { account: accountId, applied: fieldsOf(change) };
|
|
48
|
+
respond(id, { result });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function readProfile(id: string, args: Record<string, unknown>): Promise<void> {
|
|
52
|
+
const accountId = accountFor({ account: args.account as string | undefined });
|
|
53
|
+
const acct = accounts.get(accountId);
|
|
54
|
+
if (!acct) {
|
|
55
|
+
respond(id, { error: `unknown account '${accountId}'` });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const user = typeof args.user === 'string' ? args.user.trim() : '';
|
|
59
|
+
if (!/^\d+$/.test(user)) throw new TrainError('discord_user_required', 'profile needs the Discord id of the person', { retryable: false });
|
|
60
|
+
const found = await acct.client.users.fetch(user);
|
|
61
|
+
const result: SenderProfile = {
|
|
62
|
+
id: user,
|
|
63
|
+
name: found.username,
|
|
64
|
+
...(found.globalName === null ? {} : { display_name: found.globalName }),
|
|
65
|
+
avatar: found.displayAvatarURL({ size: 256 }),
|
|
66
|
+
};
|
|
67
|
+
respond(id, { result });
|
|
68
|
+
}
|