@stage-labs/metro 0.1.0-beta.13 → 0.1.0-beta.130
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/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +207 -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,88 @@
|
|
|
1
|
+
type Args = Record<string, unknown>;
|
|
2
|
+
export interface Normalized {
|
|
3
|
+
action: string;
|
|
4
|
+
args: Args;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface Attachment {
|
|
8
|
+
kind?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
data?: string;
|
|
12
|
+
mime?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DiscordFile {
|
|
17
|
+
file: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const discordFile = (a: Attachment): DiscordFile | null => {
|
|
23
|
+
const file = a.path ?? a.url;
|
|
24
|
+
if (typeof file !== 'string') return null;
|
|
25
|
+
return { file, kind: a.kind ?? 'file', name: a.name ?? '' };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function discordAttachments(att: Attachment[]): Args {
|
|
29
|
+
const usable = att
|
|
30
|
+
.map(discordFile)
|
|
31
|
+
.filter((f): f is DiscordFile => f !== null);
|
|
32
|
+
if (!usable.length) return {};
|
|
33
|
+
return {
|
|
34
|
+
files: usable.map((f) => f.file),
|
|
35
|
+
attachmentKinds: usable.map((f) => f.kind),
|
|
36
|
+
attachmentNames: usable.map((f) => f.name),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function normalizeDiscord(action: string, env: Args): Normalized {
|
|
41
|
+
const att = (env.attachments as Attachment[] | undefined) ?? [];
|
|
42
|
+
if (action === 'send') {
|
|
43
|
+
return { action: 'send', args: { ...env, ...discordAttachments(att) } };
|
|
44
|
+
}
|
|
45
|
+
if (action === 'reply') {
|
|
46
|
+
const replyTo = env.replyTo ?? env.messageId;
|
|
47
|
+
return {
|
|
48
|
+
action: 'send',
|
|
49
|
+
args: { ...env, replyTo, ...discordAttachments(att) },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (action === 'unreact')
|
|
53
|
+
return { action: 'react', args: { ...env, emoji: '' } };
|
|
54
|
+
if (action === 'read') {
|
|
55
|
+
return {
|
|
56
|
+
action: 'fetch',
|
|
57
|
+
args: { line: env.line, limit: env.limit, before: env.before },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { action, args: env };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function normalizeTelegram(action: string, env: Args): Normalized {
|
|
64
|
+
if (action === 'reply') {
|
|
65
|
+
return {
|
|
66
|
+
action: 'send',
|
|
67
|
+
args: {
|
|
68
|
+
line: env.line,
|
|
69
|
+
text: env.text,
|
|
70
|
+
replyTo: env.replyTo,
|
|
71
|
+
attachments: env.attachments,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (action === 'unreact')
|
|
76
|
+
return { action: 'react', args: { ...env, emoji: '' } };
|
|
77
|
+
return { action, args: env };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function normalizeXmtp(action: string, env: Args): Normalized {
|
|
81
|
+
if (action === 'unreact') {
|
|
82
|
+
return { action: 'react', args: { ...env, action: 'removed' } };
|
|
83
|
+
}
|
|
84
|
+
if (action === 'read') {
|
|
85
|
+
return { action: 'query', args: { line: env.line, limit: env.limit } };
|
|
86
|
+
}
|
|
87
|
+
return { action, args: env };
|
|
88
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { serializeTrainError, type TrainErrorInfo } from '../train-error.js';
|
|
2
|
+
import type { Normalized } from './messaging-normalize.js';
|
|
3
|
+
|
|
4
|
+
export const emit = (e: unknown): void =>
|
|
5
|
+
void process.stdout.write(JSON.stringify(e) + '\n');
|
|
6
|
+
|
|
7
|
+
export const respond = (
|
|
8
|
+
id: string,
|
|
9
|
+
body: { result?: unknown; error?: string; errorInfo?: TrainErrorInfo },
|
|
10
|
+
): void =>
|
|
11
|
+
void process.stdout.write(
|
|
12
|
+
JSON.stringify({ op: 'response', id, ...body }) + '\n',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const mintId = (): string =>
|
|
16
|
+
`msg_${Math.random().toString(36).slice(2, 10)}`;
|
|
17
|
+
|
|
18
|
+
type Args = Record<string, unknown>;
|
|
19
|
+
|
|
20
|
+
export interface CallMsg {
|
|
21
|
+
op: 'call';
|
|
22
|
+
id: string;
|
|
23
|
+
action: string;
|
|
24
|
+
args: Args;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type StationHandler = (id: string, args: Args) => void | Promise<void>;
|
|
28
|
+
|
|
29
|
+
export interface StationConfig {
|
|
30
|
+
handlers: Record<string, StationHandler>;
|
|
31
|
+
normalize: (action: string, args: Args) => Normalized;
|
|
32
|
+
preDispatch?: (id: string, action: string) => boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const lineTag = (args: Args): string =>
|
|
36
|
+
typeof args.line === 'string' ? args.line : '?';
|
|
37
|
+
|
|
38
|
+
export function makeStation({ handlers, normalize, preDispatch }: StationConfig) {
|
|
39
|
+
const known = Object.keys(handlers).join(', ');
|
|
40
|
+
return async function handleCall(msg: CallMsg): Promise<void> {
|
|
41
|
+
const { id } = msg;
|
|
42
|
+
let action = msg.action;
|
|
43
|
+
let args: Args = msg.args;
|
|
44
|
+
try {
|
|
45
|
+
({ action, args } = normalize(msg.action, msg.args));
|
|
46
|
+
emit({ op: 'log', text: `call ${action} recv (line=${lineTag(args)})` });
|
|
47
|
+
if (preDispatch?.(id, action)) return;
|
|
48
|
+
const handler = handlers[action];
|
|
49
|
+
if (!handler) {
|
|
50
|
+
respond(id, { error: `unknown action '${action}' (have: ${known})` });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await handler(id, args);
|
|
54
|
+
emit({ op: 'log', text: `call ${action} done (line=${lineTag(args)})` });
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const info = serializeTrainError(err);
|
|
57
|
+
emit({
|
|
58
|
+
op: 'log',
|
|
59
|
+
text: `call ${action} FAILED (line=${lineTag(args)}): ${info.error}`,
|
|
60
|
+
});
|
|
61
|
+
respond(id, info);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export type Verb =
|
|
2
|
+
| 'send'
|
|
3
|
+
| 'reply'
|
|
4
|
+
| 'react'
|
|
5
|
+
| 'unreact'
|
|
6
|
+
| 'edit'
|
|
7
|
+
| 'delete'
|
|
8
|
+
| 'read';
|
|
9
|
+
|
|
10
|
+
export interface ToolResult {
|
|
11
|
+
content: { type: 'text'; text: string }[];
|
|
12
|
+
isError?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CanonicalAttachment {
|
|
16
|
+
path?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
data?: string;
|
|
19
|
+
upload?: string;
|
|
20
|
+
mime?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ToolContext {
|
|
25
|
+
call(
|
|
26
|
+
action: string,
|
|
27
|
+
args: Record<string, unknown>,
|
|
28
|
+
): Promise<{ result: unknown }>;
|
|
29
|
+
ok(text: string): ToolResult;
|
|
30
|
+
okJson(value: unknown): ToolResult;
|
|
31
|
+
err(text: string): ToolResult;
|
|
32
|
+
readFile(path: string): Promise<Buffer>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StationTool {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
inputSchema: Record<string, unknown>;
|
|
39
|
+
handle(args: Record<string, unknown>, ctx: ToolContext): Promise<ToolResult>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MetroMember {
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
display_name?: string;
|
|
46
|
+
address?: string;
|
|
47
|
+
roles?: string[];
|
|
48
|
+
is_admin?: boolean;
|
|
49
|
+
is_bot?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface MemberCapability {
|
|
53
|
+
supported: boolean;
|
|
54
|
+
complete: boolean;
|
|
55
|
+
reason?: string;
|
|
56
|
+
total?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface MemberList {
|
|
60
|
+
members: MetroMember[];
|
|
61
|
+
capability: MemberCapability;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type GroupOp =
|
|
65
|
+
| 'create_group'
|
|
66
|
+
| 'add_members'
|
|
67
|
+
| 'remove_members'
|
|
68
|
+
| 'invite_link';
|
|
69
|
+
|
|
70
|
+
export type MemberOutcomeStatus = 'added' | 'invited' | 'removed' | 'failed';
|
|
71
|
+
|
|
72
|
+
export interface MemberOutcome {
|
|
73
|
+
id: string;
|
|
74
|
+
status: MemberOutcomeStatus;
|
|
75
|
+
reason?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface GroupCapability {
|
|
79
|
+
supported: boolean;
|
|
80
|
+
reason?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface GroupResult {
|
|
84
|
+
capability: GroupCapability;
|
|
85
|
+
line?: string;
|
|
86
|
+
id?: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
members?: MemberOutcome[];
|
|
89
|
+
inviteLink?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type AttachmentMode = 'canonical' | 'native' | 'none';
|
|
93
|
+
|
|
94
|
+
export interface Station {
|
|
95
|
+
name: string;
|
|
96
|
+
hasAccounts: boolean;
|
|
97
|
+
hasTrain: boolean;
|
|
98
|
+
messageVerbs: ReadonlySet<Verb>;
|
|
99
|
+
groupOps?: ReadonlySet<GroupOp>;
|
|
100
|
+
resolvesSenders?: boolean;
|
|
101
|
+
attachmentMode: AttachmentMode;
|
|
102
|
+
sendAttachments?(
|
|
103
|
+
line: string,
|
|
104
|
+
atts: CanonicalAttachment[],
|
|
105
|
+
ctx: ToolContext,
|
|
106
|
+
): Promise<string[]>;
|
|
107
|
+
tools: StationTool[];
|
|
108
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface TrainErrorInfo {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
retryable?: boolean;
|
|
5
|
+
retryAfterMs?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class TrainError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly retryable?: boolean;
|
|
11
|
+
readonly retryAfterMs?: number;
|
|
12
|
+
constructor(
|
|
13
|
+
code: string,
|
|
14
|
+
message: string,
|
|
15
|
+
opts?: { retryable?: boolean; retryAfterMs?: number },
|
|
16
|
+
) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'TrainError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.retryable = opts?.retryable;
|
|
21
|
+
this.retryAfterMs = opts?.retryAfterMs;
|
|
22
|
+
}
|
|
23
|
+
toErrorInfo(): TrainErrorInfo {
|
|
24
|
+
return {
|
|
25
|
+
code: this.code,
|
|
26
|
+
message: this.message,
|
|
27
|
+
...(this.retryable !== undefined ? { retryable: this.retryable } : {}),
|
|
28
|
+
...(this.retryAfterMs !== undefined
|
|
29
|
+
? { retryAfterMs: this.retryAfterMs }
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function serializeTrainError(err: unknown): {
|
|
36
|
+
error: string;
|
|
37
|
+
errorInfo?: TrainErrorInfo;
|
|
38
|
+
} {
|
|
39
|
+
if (err instanceof TrainError)
|
|
40
|
+
return { error: err.message, errorInfo: err.toErrorInfo() };
|
|
41
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function coerceErrorInfo(v: unknown): TrainErrorInfo | undefined {
|
|
45
|
+
if (!v || typeof v !== 'object') return undefined;
|
|
46
|
+
const o = v as Record<string, unknown>;
|
|
47
|
+
if (typeof o.code !== 'string' || typeof o.message !== 'string')
|
|
48
|
+
return undefined;
|
|
49
|
+
const info: TrainErrorInfo = { code: o.code, message: o.message };
|
|
50
|
+
if (typeof o.retryable === 'boolean') info.retryable = o.retryable;
|
|
51
|
+
if (typeof o.retryAfterMs === 'number') info.retryAfterMs = o.retryAfterMs;
|
|
52
|
+
return info;
|
|
53
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metro-labs/daemon",
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "The metro daemon a user runs on their own machine with `metro serve`: the MCP server Claude Code connects to, the station subprocesses it supervises, the model gateway, and the signed-identity APIs the page at metro.box talks to.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/bonustrack/metro.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/bonustrack/metro#readme",
|
|
12
|
+
"bugs": "https://github.com/bonustrack/metro/issues",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/mcp/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"start": "bun src/server.ts",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"test": "tsc --noEmit && DYLD_FALLBACK_LIBRARY_PATH=/usr/lib METRO_STATE_DIR=\"$(mktemp -d /tmp/metro-test.XXXXXX)\" bun test test/"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@metro-labs/core": "workspace:*",
|
|
27
|
+
"@metro-labs/http": "workspace:*",
|
|
28
|
+
"@metro-labs/discord-bot": "workspace:*",
|
|
29
|
+
"@metro-labs/telegram": "workspace:*",
|
|
30
|
+
"@metro-labs/telegram-bot": "workspace:*",
|
|
31
|
+
"@metro-labs/threema": "workspace:*",
|
|
32
|
+
"@metro-labs/webhook": "workspace:*",
|
|
33
|
+
"@metro-labs/whatsapp": "workspace:*",
|
|
34
|
+
"@metro-labs/xmtp": "workspace:*",
|
|
35
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
36
|
+
"viem": "2.52.2",
|
|
37
|
+
"ws": "^8.18.0",
|
|
38
|
+
"zod": "^3.23.8"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@stage-labs/config": "0.1.0-beta.2",
|
|
42
|
+
"@types/ws": "^8.18.0",
|
|
43
|
+
"eslint": "^10.3.0",
|
|
44
|
+
"knip": "^6.15.0",
|
|
45
|
+
"madge": "^8.0.0",
|
|
46
|
+
"typescript": "^5"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { STATIONS, type StationName } from '@metro-labs/core/station-names';
|
|
2
|
+
|
|
3
|
+
const ACCOUNT_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
4
|
+
|
|
5
|
+
export interface AccountRef {
|
|
6
|
+
agentId: string;
|
|
7
|
+
station: StationName;
|
|
8
|
+
accountId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isStationName(raw: unknown): raw is StationName {
|
|
12
|
+
return (
|
|
13
|
+
typeof raw === 'string' && (STATIONS as readonly string[]).includes(raw)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function parseAccountId(raw: string): string | null {
|
|
18
|
+
return ACCOUNT_ID_RE.test(raw) ? raw : null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isStationName, parseAccountId } from './account-attach.js';
|
|
2
|
+
import type { StationName } from '@metro-labs/core/station-names';
|
|
3
|
+
import { ATTACH_ID_RE } from '../stations/attach-session.js';
|
|
4
|
+
|
|
5
|
+
export type AccountRoute =
|
|
6
|
+
| { kind: 'start' }
|
|
7
|
+
| { kind: 'session'; attachId: string }
|
|
8
|
+
| { kind: 'step'; attachId: string }
|
|
9
|
+
| { kind: 'account'; station: StationName; accountId: string }
|
|
10
|
+
| { kind: 'allowlist'; station: StationName; accountId: string }
|
|
11
|
+
| { kind: 'senders'; station: StationName; accountId: string }
|
|
12
|
+
| { kind: 'resolve'; station: StationName; accountId: string }
|
|
13
|
+
| { kind: 'enabled'; station: StationName; accountId: string };
|
|
14
|
+
|
|
15
|
+
const ROUTE_METHODS: Record<AccountRoute['kind'], string[]> = {
|
|
16
|
+
start: ['POST'],
|
|
17
|
+
session: ['GET', 'DELETE'],
|
|
18
|
+
step: ['POST'],
|
|
19
|
+
account: ['DELETE'],
|
|
20
|
+
allowlist: ['PUT'],
|
|
21
|
+
senders: ['GET'],
|
|
22
|
+
resolve: ['GET'],
|
|
23
|
+
enabled: ['PUT'],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const SUB_ROUTES = ['allowlist', 'senders', 'resolve', 'enabled'] as const;
|
|
27
|
+
|
|
28
|
+
type SubRoute = (typeof SUB_ROUTES)[number];
|
|
29
|
+
|
|
30
|
+
const isSubRoute = (value: string | undefined): value is SubRoute =>
|
|
31
|
+
SUB_ROUTES.some((sub) => sub === value);
|
|
32
|
+
|
|
33
|
+
function twoSegmentRoute(head: string, tail: string): AccountRoute | null {
|
|
34
|
+
if (ATTACH_ID_RE.test(head))
|
|
35
|
+
return tail === 'step' ? { kind: 'step', attachId: head } : null;
|
|
36
|
+
if (!isStationName(head)) return null;
|
|
37
|
+
const accountId = parseAccountId(tail);
|
|
38
|
+
return accountId === null ? null : { kind: 'account', station: head, accountId };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function accountSubRoute(
|
|
42
|
+
head: string,
|
|
43
|
+
tail: string,
|
|
44
|
+
sub: string | undefined,
|
|
45
|
+
): AccountRoute | null {
|
|
46
|
+
if (!isStationName(head) || !isSubRoute(sub)) return null;
|
|
47
|
+
const accountId = parseAccountId(tail);
|
|
48
|
+
return accountId === null ? null : { kind: sub, station: head, accountId };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function accountRoute(rest: string[]): AccountRoute | null {
|
|
52
|
+
const [head, tail] = rest;
|
|
53
|
+
if (head === undefined) return null;
|
|
54
|
+
if (rest.length === 1)
|
|
55
|
+
return head === 'start'
|
|
56
|
+
? { kind: 'start' }
|
|
57
|
+
: ATTACH_ID_RE.test(head)
|
|
58
|
+
? { kind: 'session', attachId: head }
|
|
59
|
+
: null;
|
|
60
|
+
if (rest.length === 3 && tail !== undefined) return accountSubRoute(head, tail, rest[2]);
|
|
61
|
+
if (rest.length !== 2 || tail === undefined) return null;
|
|
62
|
+
return twoSegmentRoute(head, tail);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function accountRouteAllows(
|
|
66
|
+
route: AccountRoute,
|
|
67
|
+
method: string | undefined,
|
|
68
|
+
): boolean {
|
|
69
|
+
return ROUTE_METHODS[route.kind].includes(method ?? '');
|
|
70
|
+
}
|