@stage-labs/metro 0.1.0-beta.23 → 0.1.0-beta.231
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/background.js +123 -0
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +197 -0
- package/dist/cli.js +52 -110
- package/dist/control.js +19 -103
- package/dist/hold.js +210 -0
- package/dist/local.js +43 -0
- package/dist/mcp-config.js +25 -0
- package/dist/memory.js +222 -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/MEMORY.md +78 -0
- package/runtime/marketplace/plugin/METRO.md +26 -0
- package/runtime/marketplace/plugin/STAGE.md +42 -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/node_modules/@metro-labs/core/package.json +51 -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 +22 -26
- 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 +14 -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/mail-text.ts +72 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-trust.ts +29 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +212 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +126 -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 +49 -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/crontab.ts +44 -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 +39 -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 +43 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +91 -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/daemon/src/agents/map.ts +133 -0
- 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 +223 -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 +75 -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 +380 -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-routine.ts +114 -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 +295 -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 +346 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/usage-probe.ts +127 -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/transfer-api.ts +116 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-crypto.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-store.ts +48 -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 +214 -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 +209 -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 +155 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +93 -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 +307 -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 +235 -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 +203 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +285 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-lists.ts +57 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +161 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-store.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +104 -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 +118 -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 +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/tool-search.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage-refresh.ts +102 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +348 -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 +34 -80
- 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 +88 -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 +71 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/session.ts +47 -44
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +93 -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 +64 -113
- 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 +63 -51
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +209 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +69 -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/cloudwatch.ts +178 -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-browser.ts +102 -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 +5 -31
- 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 +69 -3
- package/runtime/node_modules/@metro-labs/{mcp/src/db → daemon/src/stations}/materialize.ts +60 -179
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/registry.ts +20 -2
- 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-bot/package.json +2 -4
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +3 -23
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +19 -187
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +26 -67
- package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +1 -1
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +8 -14
- package/runtime/node_modules/@metro-labs/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-bot/src/send-files.ts +12 -13
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/gmail/package.json +25 -0
- package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +81 -0
- package/runtime/node_modules/@metro-labs/gmail/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/gmail/src/api.ts +31 -0
- package/runtime/node_modules/@metro-labs/gmail/src/attachments.ts +35 -0
- package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +105 -0
- package/runtime/node_modules/@metro-labs/gmail/src/config.ts +13 -0
- package/runtime/node_modules/@metro-labs/gmail/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/gmail/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/gmail/src/login.ts +37 -0
- package/runtime/node_modules/@metro-labs/gmail/src/message.ts +125 -0
- package/runtime/node_modules/@metro-labs/gmail/src/mime.ts +70 -0
- package/runtime/node_modules/@metro-labs/gmail/src/outbound.ts +124 -0
- package/runtime/node_modules/@metro-labs/gmail/src/query.ts +99 -0
- package/runtime/node_modules/@metro-labs/gmail/src/state.ts +24 -0
- package/runtime/node_modules/@metro-labs/gmail/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/gmail/src/trust.ts +42 -0
- package/runtime/node_modules/@metro-labs/http/package.json +30 -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/sigv4.ts +90 -0
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +149 -0
- package/runtime/node_modules/@metro-labs/outlook/package.json +25 -0
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +78 -0
- package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +81 -0
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +120 -0
- package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +42 -0
- package/runtime/node_modules/@metro-labs/outlook/src/config.ts +23 -0
- package/runtime/node_modules/@metro-labs/outlook/src/format.ts +59 -0
- package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +55 -0
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/outlook/src/login.ts +129 -0
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +31 -0
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +103 -0
- package/runtime/node_modules/@metro-labs/outlook/src/query.ts +84 -0
- package/runtime/node_modules/@metro-labs/outlook/src/state.ts +28 -0
- package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +41 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +1 -3
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +5 -24
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +8 -6
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/client.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +19 -34
- package/runtime/node_modules/@metro-labs/telegram/src/group.ts +3 -3
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +13 -34
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +4 -43
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +2 -3
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +4 -1
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +1 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +7 -41
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +22 -77
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +46 -48
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +15 -15
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +6 -82
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +85 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +20 -12
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +96 -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 +87 -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 +40 -53
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +72 -220
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +27 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +11 -7
- 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 +57 -33
- 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/resolve.ts +44 -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 +7 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +22 -58
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +55 -48
- 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 +38 -0
- package/dist/prompt.js +0 -61
- package/dist/store.js +0 -70
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +0 -195
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +0 -292
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +0 -197
- package/runtime/node_modules/@metro-labs/discord-bot/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 -341
- 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 -320
- 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/agent-map.ts +0 -71
- 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/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/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +0 -3
- 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/{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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Chat, Message, Peer, User } from '@mtcute/bun';
|
|
2
|
-
import type { SavedAttachment } from '@metro-labs/mcp/stations/attachments';
|
|
3
2
|
import { lineOf } from './accounts.js';
|
|
4
|
-
import { mintId } from '
|
|
3
|
+
import { mintId } from '@metro-labs/core/stations/station-runtime';
|
|
5
4
|
import { isDownloadable, pendingDescriptorOf } from './attachments.js';
|
|
6
5
|
|
|
7
6
|
const isUser = (peer: Peer): peer is User => peer.type === 'user';
|
|
@@ -13,8 +12,9 @@ export function senderName(peer: Peer): string | undefined {
|
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export function displayName(peer: Peer): string | undefined {
|
|
16
|
-
if (isUser(peer)) return peer.
|
|
17
|
-
|
|
15
|
+
if (!isUser(peer)) return peer.title;
|
|
16
|
+
const name = [peer.firstName, peer.lastName].filter((part) => typeof part === 'string' && part !== '').join(' ');
|
|
17
|
+
return name === '' ? undefined : name;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function chatName(peer: Peer): string | undefined {
|
|
@@ -45,6 +45,20 @@ export function isOwnEcho(m: Message): boolean {
|
|
|
45
45
|
return isUser(sender) && sender.isSelf;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function replyMeta(m: Message): Record<string, unknown> {
|
|
49
|
+
const replied = m.replyToMessage;
|
|
50
|
+
const target = replied?.id;
|
|
51
|
+
if (replied === null || typeof target !== 'number') return {};
|
|
52
|
+
if (m.isTopicMessage && target === replied.threadId) return {};
|
|
53
|
+
const id = String(target);
|
|
54
|
+
const sender = replied.sender;
|
|
55
|
+
return {
|
|
56
|
+
reply_to: id,
|
|
57
|
+
event: { type: 'reply', replyTo: id },
|
|
58
|
+
reply_to_self: sender?.type === 'user' && sender.isSelf,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
export function envelope(
|
|
49
63
|
accountId: string,
|
|
50
64
|
m: Message,
|
|
@@ -58,7 +72,6 @@ export function envelope(
|
|
|
58
72
|
? [pendingDescriptorOf(media)]
|
|
59
73
|
: undefined;
|
|
60
74
|
return {
|
|
61
|
-
kind: 'inbound',
|
|
62
75
|
id: mintId(),
|
|
63
76
|
ts: m.date.toISOString(),
|
|
64
77
|
station: 'telegram',
|
|
@@ -71,6 +84,7 @@ export function envelope(
|
|
|
71
84
|
text: projectText(m),
|
|
72
85
|
is_private: isPrivate,
|
|
73
86
|
has_media: media !== null,
|
|
87
|
+
...replyMeta(m),
|
|
74
88
|
payload: {
|
|
75
89
|
account: accountId,
|
|
76
90
|
message_id: String(m.id),
|
|
@@ -79,34 +93,6 @@ export function envelope(
|
|
|
79
93
|
};
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
export function attachmentSavedEnvelope(
|
|
83
|
-
accountId: string,
|
|
84
|
-
line: string,
|
|
85
|
-
sourceEnvId: string,
|
|
86
|
-
saved: SavedAttachment,
|
|
87
|
-
index = 0,
|
|
88
|
-
): Record<string, unknown> {
|
|
89
|
-
return {
|
|
90
|
-
kind: 'inbound',
|
|
91
|
-
id: mintId(),
|
|
92
|
-
ts: new Date().toISOString(),
|
|
93
|
-
station: 'telegram',
|
|
94
|
-
line,
|
|
95
|
-
from: `metro://telegram/${accountId}/self`,
|
|
96
|
-
text: `📎 saved: ${saved.path}`,
|
|
97
|
-
payload: {
|
|
98
|
-
account: accountId,
|
|
99
|
-
contentType: 'attachmentSaved',
|
|
100
|
-
attachmentFor: sourceEnvId,
|
|
101
|
-
index,
|
|
102
|
-
attachmentPath: saved.path,
|
|
103
|
-
localPath: saved.path,
|
|
104
|
-
mime: saved.mime,
|
|
105
|
-
name: saved.name,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
96
|
export interface ReactionInput {
|
|
111
97
|
accountId: string;
|
|
112
98
|
chatId: number;
|
|
@@ -121,7 +107,6 @@ export interface ReactionInput {
|
|
|
121
107
|
|
|
122
108
|
export function reactionEnvelope(r: ReactionInput): Record<string, unknown> {
|
|
123
109
|
return {
|
|
124
|
-
kind: 'react',
|
|
125
110
|
id: mintId(),
|
|
126
111
|
ts: r.date.toISOString(),
|
|
127
112
|
station: 'telegram',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
GroupResult,
|
|
3
3
|
MemberOutcome,
|
|
4
|
-
} from '@metro-labs/
|
|
5
|
-
import { TrainError } from '@metro-labs/
|
|
6
|
-
import { errMsg } from '@metro-labs/
|
|
4
|
+
} from '@metro-labs/core/stations/types';
|
|
5
|
+
import { TrainError } from '@metro-labs/core/train-error';
|
|
6
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
7
7
|
import type { UserClient } from './client.js';
|
|
8
8
|
import { lineOf } from './accounts.js';
|
|
9
9
|
|
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import type { Message } from '@mtcute/bun';
|
|
2
|
-
import { errMsg, log } from '@metro-labs/
|
|
3
|
-
import { emit } from '
|
|
4
|
-
import {
|
|
2
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
3
|
+
import { emit } from '@metro-labs/core/stations/station-runtime';
|
|
4
|
+
import { reportAttachment } from '@metro-labs/core/stations/train-events';
|
|
5
|
+
import { envelope, isOwnEcho } from './format.js';
|
|
5
6
|
import { downloadMedia, isDownloadable } from './attachments.js';
|
|
6
7
|
import { subscribeReactions } from './reactions.js';
|
|
7
8
|
import type { UserClient } from './client.js';
|
|
8
9
|
|
|
9
|
-
async function saveMediaAndEmit(
|
|
10
|
-
client: UserClient,
|
|
11
|
-
m: Message,
|
|
12
|
-
env: Record<string, unknown>,
|
|
13
|
-
): Promise<void> {
|
|
14
|
-
const { media } = m;
|
|
15
|
-
if (media === null || !isDownloadable(media)) return;
|
|
16
|
-
const accountId = client.account.id;
|
|
17
|
-
try {
|
|
18
|
-
const saved = await downloadMedia(client, media, String(m.id), 0);
|
|
19
|
-
emit(
|
|
20
|
-
attachmentSavedEnvelope(
|
|
21
|
-
accountId,
|
|
22
|
-
env.line as string,
|
|
23
|
-
env.id as string,
|
|
24
|
-
saved,
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
process.stderr.write(
|
|
29
|
-
`telegram[${accountId}] media save failed: ${errMsg(e)}\n`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
10
|
function emitMessage(client: UserClient, m: Message): void {
|
|
35
11
|
log.debug(
|
|
36
12
|
{ train: 'telegram', account: client.account.id, messageId: m.id },
|
|
@@ -39,12 +15,15 @@ function emitMessage(client: UserClient, m: Message): void {
|
|
|
39
15
|
if (isOwnEcho(m)) return;
|
|
40
16
|
const env = envelope(client.account.id, m);
|
|
41
17
|
emit(env);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
const { media } = m;
|
|
19
|
+
if (media === null || !isDownloadable(media)) return;
|
|
20
|
+
reportAttachment(downloadMedia(client, media, String(m.id), 0), {
|
|
21
|
+
station: 'telegram',
|
|
22
|
+
account: client.account.id,
|
|
23
|
+
line: String(env.line),
|
|
24
|
+
forId: String(env.id),
|
|
25
|
+
index: 0,
|
|
26
|
+
});
|
|
48
27
|
}
|
|
49
28
|
|
|
50
29
|
function subscribe(client: UserClient): void {
|
|
@@ -1,46 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
accounts,
|
|
6
|
-
loadAccounts,
|
|
7
|
-
accountFor,
|
|
8
|
-
lineOf,
|
|
9
|
-
targetOf,
|
|
10
|
-
} from './accounts.js';
|
|
11
|
-
import { createClient, type UserClient } from './client.js';
|
|
1
|
+
import { runClientTrain } from '@metro-labs/core/stations/train-boot';
|
|
2
|
+
import { accounts, loadAccounts } from './accounts.js';
|
|
3
|
+
import { createClient } from './client.js';
|
|
12
4
|
import { startInbound } from './inbound.js';
|
|
13
5
|
import { makeHandleCall } from './actions.js';
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function clientFor(accountId: string): UserClient {
|
|
18
|
-
let client = clients.get(accountId);
|
|
19
|
-
if (!client) {
|
|
20
|
-
const account = accounts.get(accountId);
|
|
21
|
-
if (!account)
|
|
22
|
-
throw new TrainError('not_implemented', `unknown account '${accountId}'`);
|
|
23
|
-
client = createClient(account);
|
|
24
|
-
clients.set(accountId, client);
|
|
25
|
-
}
|
|
26
|
-
return client;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const handleCall = makeHandleCall(clientFor);
|
|
30
|
-
|
|
31
|
-
readCalls('telegram', handleCall);
|
|
32
|
-
|
|
33
|
-
function boot(): void {
|
|
34
|
-
for (const cfg of loadAccounts()) accounts.set(cfg.id, cfg);
|
|
35
|
-
for (const id of accounts.keys())
|
|
36
|
-
startInbound(clientFor(id)).catch((err: unknown) => {
|
|
37
|
-
process.stderr.write(`telegram[${id}] inbound failed: ${errMsg(err)}\n`);
|
|
38
|
-
});
|
|
39
|
-
process.stderr.write(
|
|
40
|
-
`telegram train ready (inbound+outbound) — ${accounts.size} account(s): ${[...accounts.keys()].join(', ')}\n`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
boot();
|
|
45
|
-
|
|
46
|
-
export { clients, accounts, clientFor, accountFor, lineOf, targetOf };
|
|
7
|
+
runClientTrain({ station: 'telegram', accounts, loadAccounts, createClient, startInbound, makeHandleCall });
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { InputMediaLike, Message } from '@mtcute/bun';
|
|
2
2
|
import { InputMedia } from '@mtcute/bun';
|
|
3
|
-
import { isImageMime, isImageExt } from '@metro-labs/
|
|
3
|
+
import { isImageMime, isImageExt } from '@metro-labs/core/stations/attachments';
|
|
4
4
|
import type { UserClient } from './client.js';
|
|
5
5
|
|
|
6
6
|
export interface CanonicalAttachment {
|
|
7
7
|
kind?: string;
|
|
8
8
|
path?: string;
|
|
9
|
-
url?: string;
|
|
10
9
|
mime?: string;
|
|
11
10
|
name?: string;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
const srcOf = (att: CanonicalAttachment): string => att.path ??
|
|
13
|
+
const srcOf = (att: CanonicalAttachment): string => att.path ?? '';
|
|
15
14
|
|
|
16
15
|
function isImage(att: CanonicalAttachment): boolean {
|
|
17
16
|
if (att.kind === 'image') return true;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { TelegramClient } from '@mtcute/bun';
|
|
2
|
+
import {
|
|
3
|
+
assertImage,
|
|
4
|
+
fieldsOf,
|
|
5
|
+
parseProfileChange,
|
|
6
|
+
type ProfileApplied,
|
|
7
|
+
type ProfileChange,
|
|
8
|
+
} from '@metro-labs/core/stations/profile';
|
|
9
|
+
import { respond, type StationHandler } from '@metro-labs/core/stations/station-runtime';
|
|
10
|
+
import { str } from '@metro-labs/core/str';
|
|
11
|
+
import { makeProfileCache, nonEmpty, type ProfileCache, type SenderProfile } from '@metro-labs/core/stations/sender-profile';
|
|
12
|
+
import { TrainError } from '@metro-labs/core/train-error';
|
|
13
|
+
import { accountFor } from './accounts.js';
|
|
14
|
+
import type { UserClient } from './client.js';
|
|
15
|
+
|
|
16
|
+
const BIO_MAX = 70;
|
|
17
|
+
|
|
18
|
+
export async function applyProfile(tg: TelegramClient, change: ProfileChange): Promise<void> {
|
|
19
|
+
if (change.name !== undefined || change.bio !== undefined)
|
|
20
|
+
await tg.updateProfile({
|
|
21
|
+
...(change.name === undefined ? {} : { firstName: change.name }),
|
|
22
|
+
...(change.bio === undefined ? {} : { bio: change.bio.slice(0, BIO_MAX) }),
|
|
23
|
+
});
|
|
24
|
+
if (change.avatar !== undefined) {
|
|
25
|
+
assertImage(change.avatar);
|
|
26
|
+
await tg.setMyProfilePhoto({ type: 'photo', media: `file:${change.avatar.path}` });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function makeSetProfile(clientFor: (accountId: string) => UserClient): StationHandler {
|
|
31
|
+
return async (id, args) => {
|
|
32
|
+
const accountId = accountFor({ account: str(args.account) });
|
|
33
|
+
const change = parseProfileChange(args);
|
|
34
|
+
await applyProfile(clientFor(accountId).tg, change);
|
|
35
|
+
const result: ProfileApplied = { account: accountId, applied: fieldsOf(change) };
|
|
36
|
+
respond(id, { result });
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const senders = new Map<string, ProfileCache<SenderProfile>>();
|
|
41
|
+
|
|
42
|
+
function sendersOf(client: UserClient): ProfileCache<SenderProfile> {
|
|
43
|
+
const held = senders.get(client.account.id);
|
|
44
|
+
if (held !== undefined) return held;
|
|
45
|
+
const made = makeProfileCache<SenderProfile>(
|
|
46
|
+
async (user) => {
|
|
47
|
+
const full = await client.tg.getFullUser(Number(user));
|
|
48
|
+
const handle = nonEmpty(full.username);
|
|
49
|
+
const display = nonEmpty([full.firstName, full.lastName].filter((part) => typeof part === 'string').join(' '));
|
|
50
|
+
return {
|
|
51
|
+
id: user,
|
|
52
|
+
...(handle === undefined ? {} : { name: `@${handle}` }),
|
|
53
|
+
...(display === undefined ? {} : { display_name: display }),
|
|
54
|
+
...(nonEmpty(full.bio) === undefined ? {} : { about: nonEmpty(full.bio) }),
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
{ onError: (user, err) => process.stderr.write(`telegram[${client.account.id}] could not read the profile of ${user}: ${err instanceof Error ? err.message : String(err)}\n`) },
|
|
58
|
+
);
|
|
59
|
+
senders.set(client.account.id, made);
|
|
60
|
+
return made;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function makeReadProfile(clientFor: (accountId: string) => UserClient): StationHandler {
|
|
64
|
+
return async (id, args) => {
|
|
65
|
+
const accountId = accountFor({ account: str(args.account) });
|
|
66
|
+
const user = str(args.user) ?? '';
|
|
67
|
+
if (!/^\d+$/.test(user)) throw new TrainError('telegram_user_required', 'profile needs the numeric Telegram id of the person', { retryable: false });
|
|
68
|
+
respond(id, { result: (await sendersOf(clientFor(accountId)).get(user)) ?? { id: user } });
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { tl } from '@mtcute/bun';
|
|
2
2
|
import { getBarePeerId, getMarkedPeerId } from '@mtcute/bun';
|
|
3
|
-
import { errMsg } from '@metro-labs/
|
|
4
|
-
import { emit } from '
|
|
3
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
4
|
+
import { emit } from '@metro-labs/core/stations/station-runtime';
|
|
5
5
|
import { reactionEnvelope } from './format.js';
|
|
6
6
|
import type { UserClient } from './client.js';
|
|
7
7
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { GroupOp, Station, Verb } from '@metro-labs/
|
|
1
|
+
import type { GroupOp, Station, Verb } from '@metro-labs/core/stations/types';
|
|
2
|
+
import { PROFILE_FIELDS, type ProfileField } from '@metro-labs/core/stations/profile';
|
|
2
3
|
|
|
3
4
|
export const telegramStation: Station = {
|
|
4
5
|
name: 'telegram',
|
|
@@ -20,5 +21,7 @@ export const telegramStation: Station = {
|
|
|
20
21
|
'invite_link',
|
|
21
22
|
]),
|
|
22
23
|
attachmentMode: 'canonical',
|
|
24
|
+
profileFields: new Set<ProfileField>(PROFILE_FIELDS),
|
|
25
|
+
readsProfiles: true,
|
|
23
26
|
tools: [],
|
|
24
27
|
};
|
|
@@ -1,38 +1,25 @@
|
|
|
1
|
-
import { homedir } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
1
|
import {
|
|
4
2
|
makeAccountStore,
|
|
5
3
|
resolveAccountId,
|
|
6
|
-
} from '@metro-labs/
|
|
7
|
-
import { Line } from '@metro-labs/
|
|
8
|
-
|
|
9
|
-
const ACCOUNTS_FILE =
|
|
10
|
-
process.env.TELEGRAM_BOT_ACCOUNTS_FILE ??
|
|
11
|
-
join(homedir(), '.metro', 'telegram-bot-accounts.json');
|
|
4
|
+
} from '@metro-labs/core/stations/account-store';
|
|
5
|
+
import { Line } from '@metro-labs/core/lines';
|
|
12
6
|
|
|
13
7
|
export interface AccountConfig {
|
|
14
8
|
id: string;
|
|
15
9
|
token: string;
|
|
16
|
-
owner?: string;
|
|
17
10
|
}
|
|
18
11
|
|
|
19
12
|
export const { loadAccounts } = makeAccountStore<AccountConfig>({
|
|
20
13
|
prefix: 'telegram-bot',
|
|
21
|
-
file: ACCOUNTS_FILE,
|
|
22
|
-
allowlistEnv: ['TELEGRAM_BOT_ONLY_ACCOUNTS', 'TELEGRAM_BOT_ACCOUNTS'],
|
|
23
14
|
validate(raw, die) {
|
|
24
|
-
const seenId = new Set<string>();
|
|
25
15
|
const seenTok = new Set<string>();
|
|
26
16
|
for (const a of raw) {
|
|
27
|
-
if (!a.id) die('account missing id');
|
|
28
17
|
if (!a.token || typeof a.token !== 'string')
|
|
29
18
|
die(`account '${a.id}' missing token`);
|
|
30
|
-
if (seenId.has(a.id)) die(`duplicate account id '${a.id}'`);
|
|
31
19
|
if (seenTok.has(a.token))
|
|
32
20
|
die(
|
|
33
21
|
`account '${a.id}' reuses a token used by another account (409 on getUpdates)`,
|
|
34
22
|
);
|
|
35
|
-
seenId.add(a.id);
|
|
36
23
|
seenTok.add(a.token);
|
|
37
24
|
}
|
|
38
25
|
},
|
|
@@ -43,6 +30,7 @@ export interface Account {
|
|
|
43
30
|
api: string;
|
|
44
31
|
fileApi: string;
|
|
45
32
|
offset: number;
|
|
33
|
+
username?: string;
|
|
46
34
|
}
|
|
47
35
|
export const accounts = new Map<string, Account>();
|
|
48
36
|
|
|
@@ -50,37 +38,15 @@ export async function tg<T>(
|
|
|
50
38
|
accountId: string,
|
|
51
39
|
method: string,
|
|
52
40
|
body: unknown,
|
|
53
|
-
timeoutMs = 30_000,
|
|
54
|
-
): Promise<T> {
|
|
55
|
-
const acct = accounts.get(accountId);
|
|
56
|
-
if (!acct) throw new Error(`unknown account '${accountId}'`);
|
|
57
|
-
const res = await fetch(`${acct.api}/${method}`, {
|
|
58
|
-
method: 'POST',
|
|
59
|
-
headers: { 'Content-Type': 'application/json' },
|
|
60
|
-
body: JSON.stringify(body),
|
|
61
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
62
|
-
});
|
|
63
|
-
const json = (await res.json()) as {
|
|
64
|
-
ok: boolean;
|
|
65
|
-
description?: string;
|
|
66
|
-
result?: T;
|
|
67
|
-
};
|
|
68
|
-
if (!json.ok)
|
|
69
|
-
throw new Error(`telegram-bot ${method}: ${json.description ?? 'unknown'}`);
|
|
70
|
-
return json.result as T;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function tgForm<T>(
|
|
74
|
-
accountId: string,
|
|
75
|
-
method: string,
|
|
76
|
-
form: FormData,
|
|
77
|
-
timeoutMs = 60_000,
|
|
41
|
+
timeoutMs = body instanceof FormData ? 60_000 : 30_000,
|
|
78
42
|
): Promise<T> {
|
|
79
43
|
const acct = accounts.get(accountId);
|
|
80
44
|
if (!acct) throw new Error(`unknown account '${accountId}'`);
|
|
45
|
+
const form = body instanceof FormData;
|
|
81
46
|
const res = await fetch(`${acct.api}/${method}`, {
|
|
82
47
|
method: 'POST',
|
|
83
|
-
|
|
48
|
+
...(form ? {} : { headers: { 'Content-Type': 'application/json' } }),
|
|
49
|
+
body: form ? body : JSON.stringify(body),
|
|
84
50
|
signal: AbortSignal.timeout(timeoutMs),
|
|
85
51
|
});
|
|
86
52
|
const json = (await res.json()) as {
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { normalizeTelegram } from '@metro-labs/mcp/stations/messaging-normalize';
|
|
1
|
+
import { accounts, tg, targetOf } from './accounts.js';
|
|
2
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
3
|
+
import { messagingAliases } from '@metro-labs/core/stations/messaging-normalize';
|
|
5
4
|
import {
|
|
6
5
|
adminMemberList,
|
|
7
6
|
inaccessibleMemberList,
|
|
8
7
|
type TgChatMember,
|
|
9
8
|
} from './members.js';
|
|
10
|
-
import {
|
|
11
|
-
makeStation,
|
|
12
|
-
type CallMsg,
|
|
13
|
-
type StationHandler,
|
|
14
|
-
} from '@metro-labs/mcp/stations/station-runtime';
|
|
9
|
+
import { makeStation, respond, type CallMsg, type StationHandler } from '@metro-labs/core/stations/station-runtime';
|
|
15
10
|
import { mediaKindOf } from './attachments.js';
|
|
16
|
-
import { assertContentLength } from '@metro-labs/mcp/stations/attachments';
|
|
17
11
|
import {
|
|
18
12
|
emitOutbound,
|
|
19
13
|
finishSend,
|
|
20
|
-
media,
|
|
21
14
|
MEDIA_METHOD_FIELD,
|
|
22
|
-
sendDice,
|
|
23
|
-
sendLocation,
|
|
24
15
|
sendMedia,
|
|
25
16
|
} from './media-actions.js';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
import { readProfile, setProfile } from './profile.js';
|
|
29
18
|
|
|
30
19
|
export type { CallMsg };
|
|
31
20
|
|
|
@@ -59,7 +48,6 @@ async function listAccounts(id: string): Promise<void> {
|
|
|
59
48
|
id: a.cfg.id,
|
|
60
49
|
handle: username === null ? null : `@${username}`,
|
|
61
50
|
url: username === null ? null : `https://t.me/${username}`,
|
|
62
|
-
owner: a.cfg.owner ?? null,
|
|
63
51
|
botId: me?.id ?? null,
|
|
64
52
|
username,
|
|
65
53
|
};
|
|
@@ -72,13 +60,10 @@ interface SendArgs {
|
|
|
72
60
|
line: string;
|
|
73
61
|
text: string;
|
|
74
62
|
replyTo?: string;
|
|
75
|
-
parseMode?: string;
|
|
76
|
-
buttons?: { text: string; url: string }[][];
|
|
77
63
|
account?: string;
|
|
78
64
|
attachments?: {
|
|
79
65
|
kind?: string;
|
|
80
66
|
path?: string;
|
|
81
|
-
url?: string;
|
|
82
67
|
mime?: string;
|
|
83
68
|
name?: string;
|
|
84
69
|
}[];
|
|
@@ -87,11 +72,8 @@ interface SendArgs {
|
|
|
87
72
|
|
|
88
73
|
type WireAttachment = NonNullable<SendArgs['attachments']>[number];
|
|
89
74
|
|
|
90
|
-
const attachmentSrc = (att: WireAttachment): string | undefined =>
|
|
91
|
-
att.path ?? att.url;
|
|
92
|
-
|
|
93
75
|
const attachmentKind = (att: WireAttachment): string =>
|
|
94
|
-
mediaKindOf(att.kind, att.mime,
|
|
76
|
+
mediaKindOf(att.kind, att.mime, att.path ?? att.name);
|
|
95
77
|
|
|
96
78
|
async function sendOneAttachment(
|
|
97
79
|
a: SendArgs,
|
|
@@ -103,10 +85,9 @@ async function sendOneAttachment(
|
|
|
103
85
|
if (!mf) throw new Error(`telegram-bot cannot send a '${kind}' attachment`);
|
|
104
86
|
const sent = await sendMedia(mf.method, mf.field, {
|
|
105
87
|
line: a.line,
|
|
106
|
-
path:
|
|
88
|
+
path: att.path,
|
|
107
89
|
caption,
|
|
108
90
|
replyTo: a.replyTo,
|
|
109
|
-
parseMode: a.parseMode,
|
|
110
91
|
account: a.account,
|
|
111
92
|
name: att.name,
|
|
112
93
|
});
|
|
@@ -151,13 +132,11 @@ async function send(id: string, args: Record<string, unknown>): Promise<void> {
|
|
|
151
132
|
await sendAttachments(id, a);
|
|
152
133
|
return;
|
|
153
134
|
}
|
|
154
|
-
const { line, text, replyTo,
|
|
135
|
+
const { line, text, replyTo, account } = a;
|
|
155
136
|
const { accountId, chatId, topicId } = targetOf(line, account);
|
|
156
137
|
const body: Record<string, unknown> = { chat_id: chatId, text };
|
|
157
138
|
if (topicId !== undefined) body.message_thread_id = topicId;
|
|
158
139
|
if (replyTo) body.reply_parameters = { message_id: Number(replyTo) };
|
|
159
|
-
if (parseMode) body.parse_mode = parseMode;
|
|
160
|
-
if (buttons) body.reply_markup = { inline_keyboard: buttons };
|
|
161
140
|
const sent = await tg<{ message_id: number }>(accountId, 'sendMessage', body);
|
|
162
141
|
finishSend(id, accountId, line, String(sent.message_id), text, replyTo);
|
|
163
142
|
}
|
|
@@ -178,12 +157,20 @@ async function react(id: string, args: Record<string, unknown>): Promise<void> {
|
|
|
178
157
|
respond(id, { result: { ok: true, account: accountId } });
|
|
179
158
|
}
|
|
180
159
|
|
|
160
|
+
async function typing(id: string, args: Record<string, unknown>): Promise<void> {
|
|
161
|
+
const { line, account } = args as { line: string; account?: string };
|
|
162
|
+
const { accountId, chatId, topicId } = targetOf(line, account);
|
|
163
|
+
const body: Record<string, unknown> = { chat_id: chatId, action: 'typing' };
|
|
164
|
+
if (topicId !== undefined) body.message_thread_id = topicId;
|
|
165
|
+
await tg(accountId, 'sendChatAction', body);
|
|
166
|
+
respond(id, { result: { ok: true, account: accountId } });
|
|
167
|
+
}
|
|
168
|
+
|
|
181
169
|
async function edit(id: string, args: Record<string, unknown>): Promise<void> {
|
|
182
|
-
const { line, messageId, text,
|
|
170
|
+
const { line, messageId, text, account } = args as {
|
|
183
171
|
line: string;
|
|
184
172
|
messageId: string;
|
|
185
173
|
text: string;
|
|
186
|
-
parseMode?: string;
|
|
187
174
|
account?: string;
|
|
188
175
|
};
|
|
189
176
|
const { accountId, chatId } = targetOf(line, account);
|
|
@@ -191,7 +178,6 @@ async function edit(id: string, args: Record<string, unknown>): Promise<void> {
|
|
|
191
178
|
chat_id: chatId,
|
|
192
179
|
message_id: Number(messageId),
|
|
193
180
|
text,
|
|
194
|
-
parse_mode: parseMode,
|
|
195
181
|
});
|
|
196
182
|
respond(id, { result: { ok: true, account: accountId } });
|
|
197
183
|
}
|
|
@@ -210,34 +196,6 @@ async function remove(id: string, args: Record<string, unknown>): Promise<void>
|
|
|
210
196
|
respond(id, { result: { ok: true, account: accountId } });
|
|
211
197
|
}
|
|
212
198
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
async function download(id: string, args: Record<string, unknown>): Promise<void> {
|
|
216
|
-
const {
|
|
217
|
-
fileId,
|
|
218
|
-
outDir = '/tmp',
|
|
219
|
-
account,
|
|
220
|
-
} = args as { fileId: string; outDir?: string; account?: string };
|
|
221
|
-
const accountId = accountFor({ account });
|
|
222
|
-
const acct = accounts.get(accountId);
|
|
223
|
-
if (!acct) throw new Error(`unknown account '${accountId}'`);
|
|
224
|
-
const meta = await tg<{ file_path: string }>(accountId, 'getFile', {
|
|
225
|
-
file_id: fileId,
|
|
226
|
-
});
|
|
227
|
-
const res = await fetch(`${acct.fileApi}/${meta.file_path}`, {
|
|
228
|
-
signal: AbortSignal.timeout(60_000),
|
|
229
|
-
});
|
|
230
|
-
if (!res.ok) throw new Error(`telegram-bot download ${res.status}`);
|
|
231
|
-
assertContentLength(res.headers.get('content-length'));
|
|
232
|
-
const data = await res.arrayBuffer();
|
|
233
|
-
const filename = meta.file_path.split('/').pop() ?? `${fileId}.bin`;
|
|
234
|
-
const path = `${outDir}/${Date.now()}-${filename}`;
|
|
235
|
-
await Bun.write(path, data);
|
|
236
|
-
respond(id, {
|
|
237
|
-
result: { path, fileSize: data.byteLength, account: accountId },
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
199
|
async function listMembers(
|
|
242
200
|
id: string,
|
|
243
201
|
args: Record<string, unknown>,
|
|
@@ -268,28 +226,15 @@ const HANDLERS: Record<string, StationHandler> = {
|
|
|
268
226
|
accounts: (id) => listAccounts(id),
|
|
269
227
|
send,
|
|
270
228
|
react,
|
|
229
|
+
typing,
|
|
271
230
|
edit,
|
|
272
231
|
delete: remove,
|
|
273
232
|
listMembers,
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
send_document: (id, args) =>
|
|
277
|
-
media(id, 'sendDocument', 'document', ((args.caption as string) ?? '') + ' [file]', args),
|
|
278
|
-
send_voice: (id, args) => media(id, 'sendVoice', 'voice', '[voice]', args),
|
|
279
|
-
send_sticker: (id, args) => media(id, 'sendSticker', 'sticker', '[sticker]', args),
|
|
280
|
-
send_dice: sendDice,
|
|
281
|
-
send_location: sendLocation,
|
|
282
|
-
download,
|
|
233
|
+
set_profile: setProfile,
|
|
234
|
+
profile: readProfile,
|
|
283
235
|
};
|
|
284
236
|
|
|
285
237
|
export const handleCall = makeStation({
|
|
286
238
|
handlers: HANDLERS,
|
|
287
|
-
normalize:
|
|
288
|
-
preDispatch: (id, action) => {
|
|
289
|
-
if (action === 'read') {
|
|
290
|
-
respond(id, { error: "unsupported verb 'read' on telegram-bot" });
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
return false;
|
|
294
|
-
},
|
|
239
|
+
normalize: messagingAliases(),
|
|
295
240
|
});
|
|
@@ -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
|
import { tg, accounts } from './accounts.js';
|
|
7
7
|
import type { TgMsg } from './types.js';
|
|
8
8
|
|