@stage-labs/metro 0.1.0-beta.13 → 0.1.0-beta.131
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 +14 -0
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +176 -0
- package/dist/cli.js +101 -0
- package/dist/control.js +74 -0
- package/dist/hold.js +211 -0
- package/dist/local.js +93 -0
- package/dist/mcp-config.js +25 -0
- package/dist/node-name.js +71 -0
- package/dist/onboarding.js +43 -0
- package/dist/plugin.js +120 -0
- package/dist/provider-flags.js +9 -0
- package/dist/route.js +38 -0
- package/dist/runtime-install.js +97 -0
- package/dist/runtime.js +74 -0
- package/dist/serve.js +150 -0
- package/dist/service.js +242 -0
- package/dist/tail.js +119 -0
- package/dist/update.js +45 -0
- package/dist/version.js +97 -0
- package/package.json +14 -27
- package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +18 -0
- package/runtime/marketplace/plugin/.mcp.json +1 -0
- package/runtime/marketplace/plugin/bin/guard.mjs +55 -0
- package/runtime/marketplace/plugin/bin/metro-plugin.mjs +122 -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 +16 -0
- package/runtime/marketplace/plugin/skills/refresh/SKILL.md +15 -0
- package/runtime/node_modules/@metro-labs/core/package.json +43 -0
- package/runtime/node_modules/@metro-labs/core/src/address.ts +6 -0
- package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/node_modules/@metro-labs/core/src/events.ts +120 -0
- package/runtime/node_modules/@metro-labs/core/src/identity.ts +7 -0
- package/runtime/node_modules/@metro-labs/core/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/node_modules/@metro-labs/core/src/lines.ts +87 -0
- package/runtime/node_modules/@metro-labs/core/src/log.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/protocol.ts +226 -0
- package/runtime/node_modules/@metro-labs/core/src/secure-fs.ts +57 -0
- package/runtime/node_modules/@metro-labs/core/src/station-names.ts +13 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +60 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/attachments.ts +196 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +88 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/station-runtime.ts +64 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +108 -0
- package/runtime/node_modules/@metro-labs/core/src/str.ts +5 -0
- package/runtime/node_modules/@metro-labs/core/src/train-error.ts +53 -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/agents/account-attach.ts +19 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +70 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +365 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +43 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +300 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +122 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +371 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +155 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/keys.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +95 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/scope.ts +64 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/seed.ts +33 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +209 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/crash-guard.ts +49 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +14 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/paths.ts +106 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +25 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/dedupe.ts +24 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +377 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/media-note.ts +85 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +75 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/relay.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/webhook-note.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +309 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +358 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +169 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +56 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +140 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +253 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +117 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +239 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +154 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/version.ts +109 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/api.ts +310 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/cli-api.ts +63 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/config.ts +175 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/json.ts +21 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/model.ts +77 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-client.ts +166 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-discovery.ts +139 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-pending.ts +65 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-routes.ts +171 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth.ts +155 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +122 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-target.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +296 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +286 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +98 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +70 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +332 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/watch.ts +54 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-grant.ts +99 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-owner.ts +32 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +121 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +294 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/upload-store.ts +181 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +259 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +231 -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 +288 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +203 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +231 -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 +187 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +229 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +269 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +207 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +65 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +17 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +229 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +151 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +216 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/channel-owner.ts +29 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/ctx.ts +62 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/event-store.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/frame-scope.ts +21 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/group-tools.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/index.ts +191 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/member-tools.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/raw-get-stream.ts +207 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +47 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-registry.ts +172 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-route.ts +43 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +215 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-dispatch.ts +215 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-schemas.ts +400 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/upload-tool.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +237 -0
- package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +389 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +372 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/identity.ts +54 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +223 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +60 -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 +64 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +61 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +116 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-inline.ts +100 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-interactive.ts +161 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +202 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-session.ts +280 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-xmtp.ts +111 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach.ts +248 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +261 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/registry.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor-io.ts +97 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor.ts +320 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +32 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/train-call.ts +22 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +40 -0
- package/runtime/node_modules/@metro-labs/discord-bot/package.json +28 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +118 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +388 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/api-base.ts +1 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +29 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +220 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +50 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +115 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +127 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +215 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +43 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +19 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +82 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +195 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +292 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +197 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +5 -0
- package/runtime/node_modules/@metro-labs/http/package.json +33 -0
- package/runtime/node_modules/@metro-labs/http/src/api-error.ts +8 -0
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +95 -0
- package/runtime/node_modules/@metro-labs/http/src/cors.ts +29 -0
- package/runtime/node_modules/@metro-labs/http/src/identity-key.ts +33 -0
- package/runtime/node_modules/@metro-labs/http/src/identity-registry.ts +13 -0
- package/runtime/node_modules/@metro-labs/http/src/mode-api.ts +32 -0
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +21 -0
- package/runtime/node_modules/@metro-labs/http/src/signed-identity.ts +36 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +26 -0
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +80 -0
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +254 -0
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +87 -0
- package/runtime/node_modules/@metro-labs/telegram/src/client.ts +77 -0
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +156 -0
- package/runtime/node_modules/@metro-labs/telegram/src/group.ts +261 -0
- package/runtime/node_modules/@metro-labs/telegram/src/history.ts +52 -0
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +78 -0
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +46 -0
- package/runtime/node_modules/@metro-labs/telegram/src/login.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +80 -0
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +75 -0
- package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +22 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +167 -0
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +24 -0
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +7 -0
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +1 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +25 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +120 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +295 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +128 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +201 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +109 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +166 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +47 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +17 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +58 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/verify.ts +38 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +3 -0
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +100 -0
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +219 -0
- package/runtime/node_modules/@metro-labs/threema/src/api.ts +130 -0
- package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +132 -0
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +123 -0
- package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/threema/src/index.ts +29 -0
- package/runtime/node_modules/@metro-labs/threema/src/station.ts +10 -0
- package/runtime/node_modules/@metro-labs/threema/src/verify.ts +117 -0
- package/runtime/node_modules/@metro-labs/webhook/package.json +23 -0
- package/runtime/node_modules/@metro-labs/webhook/src/station.ts +37 -0
- package/runtime/node_modules/@metro-labs/whatsapp/package.json +27 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +66 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +101 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +190 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +72 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +129 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +347 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/delivery.ts +49 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +138 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +57 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +40 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +59 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/logger.ts +60 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +176 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +84 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +22 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/outbox.ts +38 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +185 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/resolve.ts +52 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +18 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +98 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +6 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +5 -0
- package/runtime/node_modules/@metro-labs/xmtp/package.json +33 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +112 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +110 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +299 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +157 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +87 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +375 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +107 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +171 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +239 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +55 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +335 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +80 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +34 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +56 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +33 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +125 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +157 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +40 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +349 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +13 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +126 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +212 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +90 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +84 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +53 -0
- package/runtime/runtime.json +3 -0
- package/runtime/server.ts +1 -0
- package/runtime/stations.json +39 -0
- package/runtime/trains/.keep +0 -0
- package/LICENSE +0 -21
- package/README.md +0 -252
- package/dist/broker.js +0 -202
- package/dist/cache.js +0 -69
- package/dist/cli/actions.js +0 -206
- package/dist/cli/config.js +0 -185
- package/dist/cli/index.js +0 -188
- package/dist/cli/skill.js +0 -62
- package/dist/cli/tail.js +0 -164
- package/dist/cli/util.js +0 -72
- package/dist/cli/webhook.js +0 -81
- package/dist/codex-rc.js +0 -245
- package/dist/dispatcher.js +0 -128
- package/dist/history.js +0 -121
- package/dist/ipc.js +0 -72
- package/dist/log.js +0 -15
- package/dist/monitor.js +0 -194
- package/dist/paths.js +0 -68
- package/dist/registry.js +0 -48
- package/dist/stations/claude.js +0 -45
- package/dist/stations/codex.js +0 -68
- package/dist/stations/discord.js +0 -216
- package/dist/stations/index.js +0 -129
- package/dist/stations/telegram-md.js +0 -34
- package/dist/stations/telegram-upload.js +0 -113
- package/dist/stations/telegram.js +0 -234
- package/dist/stations/webhook.js +0 -103
- package/dist/tunnel.js +0 -64
- package/dist/webhooks.js +0 -41
- package/docs/broker.md +0 -214
- package/docs/monitor.md +0 -163
- package/docs/uri-scheme.md +0 -124
- package/docs/users.md +0 -226
- package/skills/metro/SKILL.md +0 -256
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { IdentifierKind } from '@xmtp/node-sdk';
|
|
2
|
+
import { convOf, type Account } from './accounts.js';
|
|
3
|
+
import { inboxEthCache, cacheInboxEth } from './wire.js';
|
|
4
|
+
import { TrainError } from '@metro-labs/core/train-error';
|
|
5
|
+
import type { MemberList, MetroMember } from '@metro-labs/core/stations/types';
|
|
6
|
+
import { readAppData, type GroupLike } from './labels.js';
|
|
7
|
+
|
|
8
|
+
export { parseMemberArgs, resolveMembers } from './member-args.js';
|
|
9
|
+
|
|
10
|
+
type Conv = Awaited<ReturnType<typeof convOf>>['conv'] & object;
|
|
11
|
+
export interface EthId {
|
|
12
|
+
identifier: string;
|
|
13
|
+
identifierKind: IdentifierKind;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function ethIdentifiers(addrs: string[]): EthId[] {
|
|
17
|
+
return addrs.map((a) => ({
|
|
18
|
+
identifier: a,
|
|
19
|
+
identifierKind: IdentifierKind.Ethereum,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function createGroupWithMembers(
|
|
24
|
+
acct: Account,
|
|
25
|
+
addrs: string[],
|
|
26
|
+
inboxes: string[],
|
|
27
|
+
opts: { groupName: string; groupDescription?: string; appData?: string },
|
|
28
|
+
): Promise<GroupLike> {
|
|
29
|
+
if (!addrs.length)
|
|
30
|
+
return acct.client.conversations.createGroup(inboxes, opts);
|
|
31
|
+
const created = await acct.client.conversations.createGroupWithIdentifiers(
|
|
32
|
+
ethIdentifiers(addrs),
|
|
33
|
+
opts,
|
|
34
|
+
);
|
|
35
|
+
if (inboxes.length)
|
|
36
|
+
await (
|
|
37
|
+
created as unknown as { addMembers: (ids: string[]) => Promise<unknown> }
|
|
38
|
+
).addMembers(inboxes);
|
|
39
|
+
return created;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function resolveAddresses(
|
|
43
|
+
acct: Account,
|
|
44
|
+
inboxIds: string[],
|
|
45
|
+
): Promise<Record<string, string>> {
|
|
46
|
+
const addresses: Record<string, string> = {};
|
|
47
|
+
const missing = inboxIds.filter((iid) => {
|
|
48
|
+
const cached = inboxEthCache.get(iid);
|
|
49
|
+
if (cached) {
|
|
50
|
+
addresses[iid] = cached;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
if (!missing.length) return addresses;
|
|
56
|
+
try {
|
|
57
|
+
const states = await acct.client.preferences.fetchInboxStates(missing);
|
|
58
|
+
for (let i = 0; i < missing.length; i++) {
|
|
59
|
+
const key = missing[i];
|
|
60
|
+
if (key === undefined) continue;
|
|
61
|
+
const eth = states[i]?.identifiers.find(
|
|
62
|
+
(it: { identifierKind: IdentifierKind }) =>
|
|
63
|
+
it.identifierKind === IdentifierKind.Ethereum,
|
|
64
|
+
);
|
|
65
|
+
if (eth?.identifier) {
|
|
66
|
+
addresses[key] = eth.identifier;
|
|
67
|
+
cacheInboxEth(key, eth.identifier);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
return addresses;
|
|
72
|
+
}
|
|
73
|
+
return addresses;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function buildGroupInfo(
|
|
77
|
+
line: string,
|
|
78
|
+
acct: Account,
|
|
79
|
+
conv: Conv,
|
|
80
|
+
): Promise<Record<string, unknown>> {
|
|
81
|
+
const inboxIds = (await conv.members()).map((m) => m.inboxId);
|
|
82
|
+
const addresses = await resolveAddresses(acct, inboxIds);
|
|
83
|
+
const isDm =
|
|
84
|
+
typeof (conv as unknown as { peerInboxId?: unknown }).peerInboxId ===
|
|
85
|
+
'function';
|
|
86
|
+
const gn = (conv as unknown as { name?: string | (() => Promise<string>) })
|
|
87
|
+
.name;
|
|
88
|
+
const resolvedName = typeof gn === 'function' ? await gn() : (gn ?? '');
|
|
89
|
+
const { labels, github, preview } = readAppData(
|
|
90
|
+
(conv as unknown as GroupLike).appData,
|
|
91
|
+
);
|
|
92
|
+
return {
|
|
93
|
+
line,
|
|
94
|
+
id: conv.id,
|
|
95
|
+
account: acct.cfg.id,
|
|
96
|
+
version: isDm ? 'dm' : 'group',
|
|
97
|
+
name: resolvedName ?? '',
|
|
98
|
+
memberCount: inboxIds.length,
|
|
99
|
+
labels,
|
|
100
|
+
github,
|
|
101
|
+
preview,
|
|
102
|
+
members: inboxIds.map((iid) => ({
|
|
103
|
+
inboxId: iid,
|
|
104
|
+
address: addresses[iid] ?? null,
|
|
105
|
+
})),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface RawMember {
|
|
110
|
+
inboxId: string;
|
|
111
|
+
permissionLevel?: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toMetroMember(
|
|
115
|
+
m: RawMember,
|
|
116
|
+
addresses: Record<string, string>,
|
|
117
|
+
): MetroMember {
|
|
118
|
+
const member: MetroMember = { id: m.inboxId };
|
|
119
|
+
const address = addresses[m.inboxId];
|
|
120
|
+
if (address) member.address = address;
|
|
121
|
+
if (typeof m.permissionLevel === 'number')
|
|
122
|
+
member.is_admin = m.permissionLevel >= 1;
|
|
123
|
+
return member;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function buildMemberList(
|
|
127
|
+
acct: Account,
|
|
128
|
+
conv: Conv,
|
|
129
|
+
): Promise<MemberList> {
|
|
130
|
+
const raw = (await conv.members()) as RawMember[];
|
|
131
|
+
const addresses = await resolveAddresses(
|
|
132
|
+
acct,
|
|
133
|
+
raw.map((m) => m.inboxId),
|
|
134
|
+
);
|
|
135
|
+
return {
|
|
136
|
+
members: raw.map((m) => toMetroMember(m, addresses)),
|
|
137
|
+
capability: { supported: true, complete: true, total: raw.length },
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface MemberGroup {
|
|
142
|
+
sync?: () => Promise<unknown>;
|
|
143
|
+
addMembers?: (ids: string[]) => Promise<unknown>;
|
|
144
|
+
addMembersByIdentifiers?: (ids: EthId[]) => Promise<unknown>;
|
|
145
|
+
removeMembers?: (ids: string[]) => Promise<unknown>;
|
|
146
|
+
removeMembersByIdentifiers?: (ids: EthId[]) => Promise<unknown>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function applyByIdentifiers(
|
|
150
|
+
group: MemberGroup,
|
|
151
|
+
byIdent: ((ids: EthId[]) => Promise<unknown>) | undefined,
|
|
152
|
+
addrs: string[],
|
|
153
|
+
verb: string,
|
|
154
|
+
): Promise<void> {
|
|
155
|
+
if (!addrs.length) return;
|
|
156
|
+
if (typeof byIdent !== 'function')
|
|
157
|
+
throw new TrainError(
|
|
158
|
+
'INVALID_ARGS',
|
|
159
|
+
`group does not support ${verb}ByIdentifiers; pass inboxIds instead`,
|
|
160
|
+
);
|
|
161
|
+
await byIdent.call(group, ethIdentifiers(addrs));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function applyByInboxId(
|
|
165
|
+
group: MemberGroup,
|
|
166
|
+
byId: ((ids: string[]) => Promise<unknown>) | undefined,
|
|
167
|
+
inboxes: string[],
|
|
168
|
+
verb: string,
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
if (!inboxes.length) return;
|
|
171
|
+
if (typeof byId !== 'function')
|
|
172
|
+
throw new TrainError(
|
|
173
|
+
'INVALID_ARGS',
|
|
174
|
+
`group does not support ${verb} by inboxId`,
|
|
175
|
+
);
|
|
176
|
+
await byId.call(group, inboxes);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function applyMemberOp(
|
|
180
|
+
conv: Conv,
|
|
181
|
+
addrs: string[],
|
|
182
|
+
inboxes: string[],
|
|
183
|
+
mode: 'add' | 'remove',
|
|
184
|
+
): Promise<void> {
|
|
185
|
+
const group = conv as unknown as MemberGroup;
|
|
186
|
+
const byId = mode === 'add' ? group.addMembers : group.removeMembers;
|
|
187
|
+
const byIdent =
|
|
188
|
+
mode === 'add'
|
|
189
|
+
? group.addMembersByIdentifiers
|
|
190
|
+
: group.removeMembersByIdentifiers;
|
|
191
|
+
const verb = mode === 'add' ? 'addMembers' : 'removeMembers';
|
|
192
|
+
if (typeof byId !== 'function' && typeof byIdent !== 'function')
|
|
193
|
+
throw new TrainError(
|
|
194
|
+
'INVALID_ARGS',
|
|
195
|
+
`${verb} target is not a group (no ${verb})`,
|
|
196
|
+
);
|
|
197
|
+
await group.sync?.().catch(() => undefined);
|
|
198
|
+
await applyByIdentifiers(group, byIdent, addrs, verb);
|
|
199
|
+
await applyByInboxId(group, byId, inboxes, verb);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const NAME_CACHE_MAX = 5000;
|
|
203
|
+
const convNameCache = new Map<string, string>();
|
|
204
|
+
|
|
205
|
+
function remember(convId: string, name: string): void {
|
|
206
|
+
convNameCache.delete(convId);
|
|
207
|
+
convNameCache.set(convId, name);
|
|
208
|
+
if (convNameCache.size > NAME_CACHE_MAX) {
|
|
209
|
+
const oldest = convNameCache.keys().next().value;
|
|
210
|
+
if (oldest !== undefined) convNameCache.delete(oldest);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function readName(conv: unknown): Promise<string> {
|
|
215
|
+
try {
|
|
216
|
+
if (typeof (conv as { peerInboxId?: unknown }).peerInboxId === 'function')
|
|
217
|
+
return '';
|
|
218
|
+
const n = (conv as { name?: string | (() => Promise<string>) }).name;
|
|
219
|
+
const resolved = typeof n === 'function' ? await n() : n;
|
|
220
|
+
return typeof resolved === 'string' ? resolved : '';
|
|
221
|
+
} catch {
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function groupNameFor(
|
|
227
|
+
convId: string,
|
|
228
|
+
conv: unknown,
|
|
229
|
+
): Promise<string> {
|
|
230
|
+
const cached = convNameCache.get(convId);
|
|
231
|
+
if (cached !== undefined) return cached;
|
|
232
|
+
const name = await readName(conv);
|
|
233
|
+
remember(convId, name);
|
|
234
|
+
return name;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function warmGroupName(convId: string, name: string | undefined): void {
|
|
238
|
+
if (typeof name === 'string' && name) remember(convId, name);
|
|
239
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { accounts } from './accounts.js';
|
|
2
|
+
import { emit, mintId, SELF_URI } from './wire.js';
|
|
3
|
+
|
|
4
|
+
export function emitInbound(
|
|
5
|
+
accountId: string,
|
|
6
|
+
e: Record<string, unknown>,
|
|
7
|
+
): void {
|
|
8
|
+
const acct = accounts.get(accountId);
|
|
9
|
+
const owner = acct?.cfg.owner;
|
|
10
|
+
const payload = {
|
|
11
|
+
...(e.payload as Record<string, unknown> | undefined),
|
|
12
|
+
account: accountId,
|
|
13
|
+
};
|
|
14
|
+
emit({
|
|
15
|
+
kind: 'inbound',
|
|
16
|
+
...e,
|
|
17
|
+
...(owner ? { to: owner } : {}),
|
|
18
|
+
account: accountId,
|
|
19
|
+
payload,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function emitAttachmentSaved(
|
|
24
|
+
accountId: string,
|
|
25
|
+
line: string,
|
|
26
|
+
sourceMsgId: string,
|
|
27
|
+
index: number,
|
|
28
|
+
save: Promise<{ path: string; mime?: string; name?: string }>,
|
|
29
|
+
): void {
|
|
30
|
+
void save
|
|
31
|
+
.then((saved) => {
|
|
32
|
+
emitInbound(accountId, {
|
|
33
|
+
id: mintId(),
|
|
34
|
+
ts: new Date().toISOString(),
|
|
35
|
+
station: 'xmtp',
|
|
36
|
+
line,
|
|
37
|
+
from: SELF_URI,
|
|
38
|
+
text: `📎 saved: ${saved.path}`,
|
|
39
|
+
payload: {
|
|
40
|
+
contentType: 'attachmentSaved',
|
|
41
|
+
attachmentFor: sourceMsgId,
|
|
42
|
+
index,
|
|
43
|
+
attachmentPath: saved.path,
|
|
44
|
+
localPath: saved.path,
|
|
45
|
+
mime: saved.mime,
|
|
46
|
+
name: saved.name,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
.catch((err: unknown) =>
|
|
51
|
+
process.stderr.write(
|
|
52
|
+
`xmtp attachment save failed: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import type { Reaction } from '@xmtp/content-type-reaction';
|
|
2
|
+
import type { Reply } from '@xmtp/content-type-reply';
|
|
3
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
4
|
+
import { transcribeAndEmit } from './transcribe.js';
|
|
5
|
+
import {
|
|
6
|
+
saveInlineAttachment,
|
|
7
|
+
saveRemoteAttachment,
|
|
8
|
+
type RemoteEntry,
|
|
9
|
+
} from './attachments.js';
|
|
10
|
+
import { emitInbound, emitAttachmentSaved } from './emit-core.js';
|
|
11
|
+
import { sentByMe } from './wire.js';
|
|
12
|
+
|
|
13
|
+
export interface EnvelopeCtx {
|
|
14
|
+
accountId: string;
|
|
15
|
+
msgId: string;
|
|
16
|
+
line: string;
|
|
17
|
+
baseId: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface RemoteAtt {
|
|
21
|
+
url: string;
|
|
22
|
+
filename?: string;
|
|
23
|
+
contentDigest?: string;
|
|
24
|
+
nonce?: Uint8Array;
|
|
25
|
+
salt?: Uint8Array;
|
|
26
|
+
secret?: Uint8Array;
|
|
27
|
+
scheme?: string;
|
|
28
|
+
contentLength?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface AttView {
|
|
32
|
+
kind: string;
|
|
33
|
+
url: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
remote: {
|
|
37
|
+
contentDigest?: string;
|
|
38
|
+
nonce?: string;
|
|
39
|
+
salt?: string;
|
|
40
|
+
secret?: string;
|
|
41
|
+
scheme?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const b64 = (u?: Uint8Array): string | undefined =>
|
|
46
|
+
u ? Buffer.from(u).toString('base64') : undefined;
|
|
47
|
+
|
|
48
|
+
function remoteAtt(r: RemoteAtt, kind: string): AttView {
|
|
49
|
+
return {
|
|
50
|
+
kind,
|
|
51
|
+
url: r.url,
|
|
52
|
+
name: r.filename,
|
|
53
|
+
size: r.contentLength,
|
|
54
|
+
remote: {
|
|
55
|
+
contentDigest: r.contentDigest,
|
|
56
|
+
nonce: b64(r.nonce),
|
|
57
|
+
salt: b64(r.salt),
|
|
58
|
+
secret: b64(r.secret),
|
|
59
|
+
scheme: r.scheme,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const IMG_RE = /\.(png|jpg|jpeg|gif|webp|heic)(\?|$)/i;
|
|
65
|
+
const VID_RE = /\.(mp4|mov|webm|m4v)(\?|$)/i;
|
|
66
|
+
|
|
67
|
+
function attKindFor(r: RemoteAtt): string {
|
|
68
|
+
const isImg = IMG_RE.test(r.url) || IMG_RE.test(r.filename ?? '');
|
|
69
|
+
if (isImg) return 'image';
|
|
70
|
+
const isVid = VID_RE.test(r.url) || VID_RE.test(r.filename ?? '');
|
|
71
|
+
return isVid ? 'video' : 'file';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function singleAttText(one: AttView): string {
|
|
75
|
+
if (one.kind === 'video') return `🎥 ${one.name ?? 'video'}`;
|
|
76
|
+
return `[${one.kind}: ${one.name ?? one.url}]`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function multiAttText(attachments: AttView[]): string {
|
|
80
|
+
const total = attachments.length;
|
|
81
|
+
const imgCount = attachments.filter((a) => a.kind === 'image').length;
|
|
82
|
+
const vidCount = attachments.filter((a) => a.kind === 'video').length;
|
|
83
|
+
if (imgCount === total && imgCount > 1) return `📷 ${imgCount} photos`;
|
|
84
|
+
if (vidCount === total && vidCount > 1) return `🎥 ${vidCount} videos`;
|
|
85
|
+
const one = attachments[0];
|
|
86
|
+
if (total === 1 && one) return singleAttText(one);
|
|
87
|
+
return `📎 ${total} attachments`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function multiRemotePayload(
|
|
91
|
+
base: Record<string, unknown>,
|
|
92
|
+
typeId: string,
|
|
93
|
+
c: object,
|
|
94
|
+
): Record<string, unknown> {
|
|
95
|
+
const m = c as { attachments?: RemoteAtt[] };
|
|
96
|
+
const list = Array.isArray(m.attachments) ? m.attachments : [];
|
|
97
|
+
const attachments = list.map((r) => remoteAtt(r, attKindFor(r)));
|
|
98
|
+
return {
|
|
99
|
+
...base,
|
|
100
|
+
text: multiAttText(attachments),
|
|
101
|
+
payload: { contentType: typeId, attachments },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function reactionPayload(
|
|
106
|
+
base: Record<string, unknown>,
|
|
107
|
+
r: Reaction,
|
|
108
|
+
): Record<string, unknown> {
|
|
109
|
+
const schemaStr = ((): string | undefined => {
|
|
110
|
+
const s = (r as { schema?: unknown }).schema;
|
|
111
|
+
if (typeof s === 'string') return s.toLowerCase();
|
|
112
|
+
if (s === 3) return 'custom';
|
|
113
|
+
if (s === 2) return 'shortcode';
|
|
114
|
+
if (s === 1) return 'unicode';
|
|
115
|
+
return undefined;
|
|
116
|
+
})();
|
|
117
|
+
const actionStr = ((): string | undefined => {
|
|
118
|
+
const a = (r as { action?: unknown }).action;
|
|
119
|
+
if (typeof a === 'string') return a.toLowerCase();
|
|
120
|
+
if (a === 2) return 'removed';
|
|
121
|
+
if (a === 1) return 'added';
|
|
122
|
+
return undefined;
|
|
123
|
+
})();
|
|
124
|
+
const removed = actionStr === 'removed';
|
|
125
|
+
return {
|
|
126
|
+
...base,
|
|
127
|
+
text: `[react ${r.content ?? ''}${removed ? ' (removed)' : ''}]`,
|
|
128
|
+
event: { type: 'react', emoji: r.content, targetId: r.reference },
|
|
129
|
+
payload: {
|
|
130
|
+
contentType: 'reaction',
|
|
131
|
+
reactTo: r.reference,
|
|
132
|
+
emoji: r.content,
|
|
133
|
+
content: r.content,
|
|
134
|
+
schema: schemaStr,
|
|
135
|
+
action: actionStr,
|
|
136
|
+
removed,
|
|
137
|
+
optionIndex: schemaStr === 'custom' ? Number(r.content) : undefined,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function replyPayload(
|
|
143
|
+
base: Record<string, unknown>,
|
|
144
|
+
typeId: string,
|
|
145
|
+
c: Reply,
|
|
146
|
+
): Record<string, unknown> {
|
|
147
|
+
return {
|
|
148
|
+
...base,
|
|
149
|
+
text:
|
|
150
|
+
typeof c.content === 'string'
|
|
151
|
+
? c.content
|
|
152
|
+
: `[reply with ${c.contentType?.typeId ?? 'unknown'}]`,
|
|
153
|
+
event: { type: 'reply', replyTo: c.reference },
|
|
154
|
+
...(sentByMe(c.reference) ? { reply_to_self: true } : {}),
|
|
155
|
+
payload: {
|
|
156
|
+
contentType: typeId,
|
|
157
|
+
replyTo: c.reference,
|
|
158
|
+
replyContentType: c.contentType?.typeId,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function attachmentKind(mime: string | undefined): string {
|
|
164
|
+
if (mime?.startsWith('image/')) return 'image';
|
|
165
|
+
if (mime?.startsWith('audio/')) return 'audio';
|
|
166
|
+
if (mime?.startsWith('video/')) return 'video';
|
|
167
|
+
return 'file';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function inlineAttachmentPayload(
|
|
171
|
+
base: Record<string, unknown>,
|
|
172
|
+
typeId: string,
|
|
173
|
+
c: { filename?: string; mimeType: string; content: Uint8Array },
|
|
174
|
+
ctx: EnvelopeCtx,
|
|
175
|
+
): Record<string, unknown> {
|
|
176
|
+
const kind = attachmentKind(c.mimeType);
|
|
177
|
+
const dataB64 = Buffer.from(c.content).toString('base64');
|
|
178
|
+
const out = {
|
|
179
|
+
...base,
|
|
180
|
+
text: `[${kind}: ${c.filename ?? 'attachment'}]`,
|
|
181
|
+
payload: {
|
|
182
|
+
contentType: typeId,
|
|
183
|
+
attachments: [{ kind, mime: c.mimeType, name: c.filename, dataB64 }],
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
if (kind === 'audio')
|
|
187
|
+
transcribeAndEmit(
|
|
188
|
+
c.content,
|
|
189
|
+
ctx.line,
|
|
190
|
+
ctx.accountId,
|
|
191
|
+
ctx.baseId,
|
|
192
|
+
emitInbound,
|
|
193
|
+
).catch((err: unknown) => {
|
|
194
|
+
process.stderr.write(
|
|
195
|
+
`xmtp[${ctx.accountId}] voice transcription failed: ${errMsg(err)}\n`,
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
emitAttachmentSaved(
|
|
199
|
+
ctx.accountId,
|
|
200
|
+
ctx.line,
|
|
201
|
+
ctx.baseId,
|
|
202
|
+
0,
|
|
203
|
+
saveInlineAttachment(c, ctx.msgId, 0),
|
|
204
|
+
);
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function remoteStaticPayload(
|
|
209
|
+
base: Record<string, unknown>,
|
|
210
|
+
typeId: string,
|
|
211
|
+
c: RemoteAtt,
|
|
212
|
+
ctx: EnvelopeCtx,
|
|
213
|
+
): Record<string, unknown> {
|
|
214
|
+
const kind = IMG_RE.test(c.url) ? 'image' : 'file';
|
|
215
|
+
emitAttachmentSaved(
|
|
216
|
+
ctx.accountId,
|
|
217
|
+
ctx.line,
|
|
218
|
+
ctx.baseId,
|
|
219
|
+
0,
|
|
220
|
+
saveRemoteAttachment(c, ctx.msgId, 0),
|
|
221
|
+
);
|
|
222
|
+
return {
|
|
223
|
+
...base,
|
|
224
|
+
text: `[${kind}: ${c.filename ?? c.url}]`,
|
|
225
|
+
payload: { contentType: typeId, attachments: [remoteAtt(c, kind)] },
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function multiRemoteEnvelope(
|
|
230
|
+
base: Record<string, unknown>,
|
|
231
|
+
typeId: string,
|
|
232
|
+
c: object,
|
|
233
|
+
ctx: EnvelopeCtx,
|
|
234
|
+
): Record<string, unknown> {
|
|
235
|
+
const m = c as { attachments?: RemoteEntry[] };
|
|
236
|
+
(Array.isArray(m.attachments) ? m.attachments : []).forEach((r, i) => {
|
|
237
|
+
emitAttachmentSaved(
|
|
238
|
+
ctx.accountId,
|
|
239
|
+
ctx.line,
|
|
240
|
+
ctx.baseId,
|
|
241
|
+
i,
|
|
242
|
+
saveRemoteAttachment(r, ctx.msgId, i),
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
return multiRemotePayload(base, typeId, c);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function pollPayload(
|
|
249
|
+
base: Record<string, unknown>,
|
|
250
|
+
typeId: string,
|
|
251
|
+
c: object,
|
|
252
|
+
): Record<string, unknown> {
|
|
253
|
+
const p = c as { question?: string };
|
|
254
|
+
return {
|
|
255
|
+
...base,
|
|
256
|
+
text: `Poll: ${p.question ?? ''}`,
|
|
257
|
+
payload: { contentType: typeId, poll: c },
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function labeledPayload(
|
|
262
|
+
base: Record<string, unknown>,
|
|
263
|
+
typeId: string,
|
|
264
|
+
text: string,
|
|
265
|
+
key: string,
|
|
266
|
+
c: unknown,
|
|
267
|
+
): Record<string, unknown> {
|
|
268
|
+
return { ...base, text, payload: { contentType: typeId, [key]: c } };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function attachmentEnvelope(
|
|
272
|
+
base: Record<string, unknown>,
|
|
273
|
+
typeId: string,
|
|
274
|
+
c: object,
|
|
275
|
+
ctx: EnvelopeCtx,
|
|
276
|
+
): Record<string, unknown> | undefined {
|
|
277
|
+
if (typeId === 'attachment')
|
|
278
|
+
return inlineAttachmentPayload(
|
|
279
|
+
base,
|
|
280
|
+
typeId,
|
|
281
|
+
c as { filename?: string; mimeType: string; content: Uint8Array },
|
|
282
|
+
ctx,
|
|
283
|
+
);
|
|
284
|
+
if (typeId === 'remoteStaticAttachment')
|
|
285
|
+
return remoteStaticPayload(base, typeId, c as RemoteAtt, ctx);
|
|
286
|
+
if (
|
|
287
|
+
typeId === 'multiRemoteStaticAttachment' ||
|
|
288
|
+
typeId === 'multiRemoteAttachment'
|
|
289
|
+
)
|
|
290
|
+
return multiRemoteEnvelope(base, typeId, c, ctx);
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function refEnvelope(
|
|
295
|
+
base: Record<string, unknown>,
|
|
296
|
+
typeId: string | undefined,
|
|
297
|
+
c: object,
|
|
298
|
+
): Record<string, unknown> | undefined {
|
|
299
|
+
if (typeId === 'walletSendCalls')
|
|
300
|
+
return labeledPayload(
|
|
301
|
+
base,
|
|
302
|
+
typeId,
|
|
303
|
+
'Payment request',
|
|
304
|
+
'walletSendCalls',
|
|
305
|
+
c,
|
|
306
|
+
);
|
|
307
|
+
if (typeId === 'transactionReference')
|
|
308
|
+
return labeledPayload(
|
|
309
|
+
base,
|
|
310
|
+
typeId,
|
|
311
|
+
'Transaction',
|
|
312
|
+
'transactionReference',
|
|
313
|
+
c,
|
|
314
|
+
);
|
|
315
|
+
if (typeId === 'signatureRequest')
|
|
316
|
+
return labeledPayload(base, typeId, 'Signature request', 'signatureRequest', c);
|
|
317
|
+
if (typeId === 'signatureReference')
|
|
318
|
+
return labeledPayload(base, typeId, 'Signature', 'signatureReference', c);
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function typedEnvelope(
|
|
323
|
+
base: Record<string, unknown>,
|
|
324
|
+
typeId: string | undefined,
|
|
325
|
+
c: object,
|
|
326
|
+
ctx: EnvelopeCtx,
|
|
327
|
+
): Record<string, unknown> | undefined {
|
|
328
|
+
if (typeId === 'reaction') return reactionPayload(base, c as Reaction);
|
|
329
|
+
if (typeId === 'reply') return replyPayload(base, typeId, c as Reply);
|
|
330
|
+
if (typeId === 'poll') return pollPayload(base, typeId, c);
|
|
331
|
+
return (
|
|
332
|
+
attachmentEnvelope(base, typeId ?? '', c, ctx) ??
|
|
333
|
+
refEnvelope(base, typeId, c)
|
|
334
|
+
);
|
|
335
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Conversation, DecodedMessage } from '@xmtp/node-sdk';
|
|
2
|
+
import { lineOf, parseLine } from './accounts.js';
|
|
3
|
+
import { emit, mintId, rememberSent, rememberUid, SELF_URI } from './wire.js';
|
|
4
|
+
import { fcmPushToAll } from './push.js';
|
|
5
|
+
import { emitInbound, emitAttachmentSaved } from './emit-core.js';
|
|
6
|
+
import { typedEnvelope, type EnvelopeCtx } from './emit-payloads.js';
|
|
7
|
+
import type { StructuredEvent } from '@metro-labs/core/events';
|
|
8
|
+
|
|
9
|
+
export { emitInbound, emitAttachmentSaved };
|
|
10
|
+
|
|
11
|
+
export function envelope(
|
|
12
|
+
accountId: string,
|
|
13
|
+
msg: DecodedMessage,
|
|
14
|
+
conv: Conversation,
|
|
15
|
+
): Record<string, unknown> {
|
|
16
|
+
const typeId = msg.contentType?.typeId;
|
|
17
|
+
const c = msg.content;
|
|
18
|
+
const line = lineOf(accountId, conv.id);
|
|
19
|
+
const base = {
|
|
20
|
+
id: mintId(),
|
|
21
|
+
ts: msg.sentAt.toISOString(),
|
|
22
|
+
station: 'xmtp',
|
|
23
|
+
line,
|
|
24
|
+
from: `metro://xmtp/${accountId}/user/${msg.senderInboxId}`,
|
|
25
|
+
message_id: msg.id,
|
|
26
|
+
is_private: typeof (conv as unknown as { peerInboxId?: unknown }).peerInboxId === 'function',
|
|
27
|
+
};
|
|
28
|
+
rememberUid(base.id, msg.id);
|
|
29
|
+
if (typeof c === 'string')
|
|
30
|
+
return { ...base, text: c, payload: { contentType: typeId } };
|
|
31
|
+
if (c && typeof c === 'object') {
|
|
32
|
+
const ctx: EnvelopeCtx = {
|
|
33
|
+
accountId,
|
|
34
|
+
msgId: msg.id,
|
|
35
|
+
line,
|
|
36
|
+
baseId: base.id,
|
|
37
|
+
};
|
|
38
|
+
const out = typedEnvelope(base, typeId, c, ctx);
|
|
39
|
+
if (out) return out;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
...base,
|
|
43
|
+
text: `[${typeId ?? 'unknown'} payload]`,
|
|
44
|
+
payload: { contentType: typeId },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function emitOutbound(
|
|
49
|
+
accountId: string,
|
|
50
|
+
line: string,
|
|
51
|
+
messageId: string,
|
|
52
|
+
text: string,
|
|
53
|
+
event?: StructuredEvent,
|
|
54
|
+
): void {
|
|
55
|
+
const uid = mintId();
|
|
56
|
+
rememberUid(uid, messageId);
|
|
57
|
+
rememberSent(messageId);
|
|
58
|
+
emit({
|
|
59
|
+
kind: 'outbound',
|
|
60
|
+
id: uid,
|
|
61
|
+
ts: new Date().toISOString(),
|
|
62
|
+
station: 'xmtp',
|
|
63
|
+
line,
|
|
64
|
+
from: SELF_URI,
|
|
65
|
+
to: line,
|
|
66
|
+
message_id: messageId,
|
|
67
|
+
text,
|
|
68
|
+
account: accountId,
|
|
69
|
+
...(event ? { event } : {}),
|
|
70
|
+
payload: { account: accountId },
|
|
71
|
+
});
|
|
72
|
+
void (async (): Promise<void> => {
|
|
73
|
+
const data: Record<string, string> = { line, messageId };
|
|
74
|
+
{
|
|
75
|
+
const p = parseLine(line);
|
|
76
|
+
if (p) data.convId = p.convId.toLowerCase();
|
|
77
|
+
}
|
|
78
|
+
await fcmPushToAll(accountId, data);
|
|
79
|
+
})().catch(() => undefined);
|
|
80
|
+
}
|