@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,365 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
3
|
+
import { normalizeAllowlist } from './allowlist.js';
|
|
4
|
+
import type { RecentSender } from './senders.js';
|
|
5
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
6
|
+
import {
|
|
7
|
+
apiFailure,
|
|
8
|
+
bodyField,
|
|
9
|
+
readJsonBody,
|
|
10
|
+
sendJson,
|
|
11
|
+
type ApiSession,
|
|
12
|
+
} from '@metro-labs/http/api-http';
|
|
13
|
+
import { type AccountRef } from './account-attach.js';
|
|
14
|
+
import { type AccountRoute } from './account-routes.js';
|
|
15
|
+
import { stationByName } from '../stations/registry.js';
|
|
16
|
+
import type { StationName } from '@metro-labs/core/station-names';
|
|
17
|
+
import {
|
|
18
|
+
ATTACHABLE_STATIONS,
|
|
19
|
+
attachInputOf,
|
|
20
|
+
isAttachStation,
|
|
21
|
+
type AttachInput,
|
|
22
|
+
type OneTimeSecret,
|
|
23
|
+
type PreparedAccount,
|
|
24
|
+
} from '../stations/attach.js';
|
|
25
|
+
import {
|
|
26
|
+
INTERACTIVE_STATIONS,
|
|
27
|
+
isInteractiveStation,
|
|
28
|
+
type InteractiveStation,
|
|
29
|
+
} from '../stations/attach-interactive.js';
|
|
30
|
+
import {
|
|
31
|
+
type AttachOwner,
|
|
32
|
+
type AttachView,
|
|
33
|
+
} from '../stations/attach-session.js';
|
|
34
|
+
|
|
35
|
+
export interface AttachSessionApi {
|
|
36
|
+
start: (
|
|
37
|
+
owner: AttachOwner,
|
|
38
|
+
station: InteractiveStation,
|
|
39
|
+
input: Record<string, unknown>,
|
|
40
|
+
) => Promise<AttachView>;
|
|
41
|
+
view: (owner: AttachOwner, attachId: string) => AttachView;
|
|
42
|
+
submit: (
|
|
43
|
+
owner: AttachOwner,
|
|
44
|
+
attachId: string,
|
|
45
|
+
input: { code?: unknown; password?: unknown },
|
|
46
|
+
) => Promise<AttachView>;
|
|
47
|
+
cancel: (owner: AttachOwner, attachId: string) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface AccountApiDeps {
|
|
51
|
+
attachSessions: AttachSessionApi;
|
|
52
|
+
prepareAccount: (input: AttachInput) => Promise<PreparedAccount>;
|
|
53
|
+
attachAccount: (
|
|
54
|
+
subject: string,
|
|
55
|
+
agentId: string,
|
|
56
|
+
station: StationName,
|
|
57
|
+
config: Record<string, unknown>,
|
|
58
|
+
) => Promise<AccountRef>;
|
|
59
|
+
detachAccount: (
|
|
60
|
+
subject: string,
|
|
61
|
+
agentId: string,
|
|
62
|
+
station: StationName,
|
|
63
|
+
accountId: string,
|
|
64
|
+
) => Promise<AccountRef>;
|
|
65
|
+
syncStations: (station: StationName) => Promise<void>;
|
|
66
|
+
reloadAgents: () => Promise<void>;
|
|
67
|
+
setAllowlist: (
|
|
68
|
+
subject: string,
|
|
69
|
+
agentId: string,
|
|
70
|
+
station: StationName,
|
|
71
|
+
accountId: string,
|
|
72
|
+
allowlist: string[],
|
|
73
|
+
) => Promise<string[]>;
|
|
74
|
+
recentSenders: (station: StationName, accountId: string) => RecentSender[];
|
|
75
|
+
resolveSender: (
|
|
76
|
+
station: StationName,
|
|
77
|
+
accountId: string,
|
|
78
|
+
query: string,
|
|
79
|
+
) => Promise<unknown>;
|
|
80
|
+
setAccountEnabled: (
|
|
81
|
+
subject: string,
|
|
82
|
+
agentId: string,
|
|
83
|
+
station: StationName,
|
|
84
|
+
accountId: string,
|
|
85
|
+
enabled: boolean,
|
|
86
|
+
) => Promise<boolean>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const ATTACHABLE: string[] = [
|
|
90
|
+
...ATTACHABLE_STATIONS,
|
|
91
|
+
...INTERACTIVE_STATIONS,
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
function lookupQuery(req: IncomingMessage): string {
|
|
95
|
+
const params = new URLSearchParams((req.url ?? '').split('?')[1] ?? '');
|
|
96
|
+
return (params.get('q') ?? '').trim();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function handleResolve(
|
|
100
|
+
req: IncomingMessage,
|
|
101
|
+
res: ServerResponse,
|
|
102
|
+
deps: AccountApiDeps,
|
|
103
|
+
target: { station: StationName; accountId: string },
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
if (stationByName(target.station)?.resolvesSenders !== true)
|
|
106
|
+
throw new ApiError(`metro cannot look a sender up on ${target.station}`, 400);
|
|
107
|
+
const query = lookupQuery(req);
|
|
108
|
+
if (query === '') throw new ApiError('a number to look up is required', 400);
|
|
109
|
+
const found = await deps.resolveSender(target.station, target.accountId, query);
|
|
110
|
+
sendJson(req, res, 200, found);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function activate(
|
|
114
|
+
deps: AccountApiDeps,
|
|
115
|
+
station: StationName,
|
|
116
|
+
): Promise<boolean> {
|
|
117
|
+
try {
|
|
118
|
+
await deps.syncStations(station);
|
|
119
|
+
return true;
|
|
120
|
+
} catch (err) {
|
|
121
|
+
log.warn(
|
|
122
|
+
{ station, err: errMsg(err) },
|
|
123
|
+
'account-api: station reload failed, the change lands at the next boot',
|
|
124
|
+
);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface AttachPayload {
|
|
130
|
+
status: 'done';
|
|
131
|
+
agentId: string;
|
|
132
|
+
station: string;
|
|
133
|
+
accountId: string;
|
|
134
|
+
identity: Record<string, string>;
|
|
135
|
+
activated: boolean;
|
|
136
|
+
secret?: OneTimeSecret;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function storeAccount(
|
|
140
|
+
deps: AccountApiDeps,
|
|
141
|
+
session: ApiSession,
|
|
142
|
+
agentId: string,
|
|
143
|
+
station: StationName,
|
|
144
|
+
prepared: PreparedAccount,
|
|
145
|
+
): Promise<AccountRef> {
|
|
146
|
+
try {
|
|
147
|
+
return await deps.attachAccount(
|
|
148
|
+
session.subject,
|
|
149
|
+
agentId,
|
|
150
|
+
station,
|
|
151
|
+
prepared.config,
|
|
152
|
+
);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
prepared.discard?.();
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function ownerOf(session: ApiSession, agentId: string): AttachOwner {
|
|
160
|
+
return { subject: session.subject, agentId };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function asInput(body: unknown): Record<string, unknown> {
|
|
164
|
+
const out: Record<string, unknown> = {};
|
|
165
|
+
for (const key of ['apiId', 'apiHash', 'phone'])
|
|
166
|
+
out[key] = bodyField(body, key);
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function handleStart(
|
|
171
|
+
req: IncomingMessage,
|
|
172
|
+
res: ServerResponse,
|
|
173
|
+
deps: AccountApiDeps,
|
|
174
|
+
session: ApiSession,
|
|
175
|
+
agentId: string,
|
|
176
|
+
): Promise<void> {
|
|
177
|
+
const body = await readJsonBody(req);
|
|
178
|
+
const station = bodyField(body, 'station');
|
|
179
|
+
if (isInteractiveStation(station)) {
|
|
180
|
+
const view = await deps.attachSessions.start(
|
|
181
|
+
ownerOf(session, agentId),
|
|
182
|
+
station,
|
|
183
|
+
asInput(body),
|
|
184
|
+
);
|
|
185
|
+
sendJson(req, res, 201, view);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!isAttachStation(station))
|
|
189
|
+
throw new ApiError(`station must be one of ${ATTACHABLE.join(', ')}`, 400);
|
|
190
|
+
const prepared = await deps.prepareAccount(attachInputOf(station, body));
|
|
191
|
+
const ref = await storeAccount(deps, session, agentId, station, prepared);
|
|
192
|
+
log.info(
|
|
193
|
+
{ agentId: ref.agentId, station, account: ref.accountId },
|
|
194
|
+
'account-api: attached a station account',
|
|
195
|
+
);
|
|
196
|
+
const payload: AttachPayload = {
|
|
197
|
+
status: 'done',
|
|
198
|
+
agentId: ref.agentId,
|
|
199
|
+
station,
|
|
200
|
+
accountId: ref.accountId,
|
|
201
|
+
identity: prepared.identity,
|
|
202
|
+
activated: await activate(deps, station),
|
|
203
|
+
};
|
|
204
|
+
sendJson(
|
|
205
|
+
req,
|
|
206
|
+
res,
|
|
207
|
+
201,
|
|
208
|
+
prepared.secret === undefined
|
|
209
|
+
? payload
|
|
210
|
+
: { ...payload, secret: prepared.secret },
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function handleDetach(
|
|
215
|
+
req: IncomingMessage,
|
|
216
|
+
res: ServerResponse,
|
|
217
|
+
deps: AccountApiDeps,
|
|
218
|
+
session: ApiSession,
|
|
219
|
+
agentId: string,
|
|
220
|
+
target: { station: StationName; accountId: string },
|
|
221
|
+
): Promise<void> {
|
|
222
|
+
const ref = await deps.detachAccount(
|
|
223
|
+
session.subject,
|
|
224
|
+
agentId,
|
|
225
|
+
target.station,
|
|
226
|
+
target.accountId,
|
|
227
|
+
);
|
|
228
|
+
log.info(
|
|
229
|
+
{ agentId: ref.agentId, station: ref.station, account: ref.accountId },
|
|
230
|
+
'account-api: detached a station account',
|
|
231
|
+
);
|
|
232
|
+
sendJson(req, res, 200, {
|
|
233
|
+
agentId: ref.agentId,
|
|
234
|
+
station: ref.station,
|
|
235
|
+
accountId: ref.accountId,
|
|
236
|
+
detached: true,
|
|
237
|
+
activated: await activate(deps, ref.station),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function applied(deps: AccountApiDeps): Promise<boolean> {
|
|
242
|
+
try {
|
|
243
|
+
await deps.reloadAgents();
|
|
244
|
+
return true;
|
|
245
|
+
} catch (err) {
|
|
246
|
+
log.warn({ err: errMsg(err) }, 'account-api: allowlist reload failed, the change lands at the next boot');
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function handleAllowlist(
|
|
252
|
+
req: IncomingMessage,
|
|
253
|
+
res: ServerResponse,
|
|
254
|
+
deps: AccountApiDeps,
|
|
255
|
+
session: ApiSession,
|
|
256
|
+
agentId: string,
|
|
257
|
+
target: { station: StationName; accountId: string },
|
|
258
|
+
): Promise<void> {
|
|
259
|
+
const wanted = normalizeAllowlist(bodyField(await readJsonBody(req), 'allowlist'));
|
|
260
|
+
const allowlist = await deps.setAllowlist(session.subject, agentId, target.station, target.accountId, wanted);
|
|
261
|
+
log.info({ agentId, station: target.station, account: target.accountId, senders: allowlist.length }, 'account-api: allowlist set');
|
|
262
|
+
sendJson(req, res, 200, {
|
|
263
|
+
agentId,
|
|
264
|
+
station: target.station,
|
|
265
|
+
accountId: target.accountId,
|
|
266
|
+
allowlist,
|
|
267
|
+
activated: await applied(deps),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function handleEnabled(
|
|
272
|
+
req: IncomingMessage,
|
|
273
|
+
res: ServerResponse,
|
|
274
|
+
deps: AccountApiDeps,
|
|
275
|
+
session: ApiSession,
|
|
276
|
+
agentId: string,
|
|
277
|
+
target: { station: StationName; accountId: string },
|
|
278
|
+
): Promise<void> {
|
|
279
|
+
const wanted = bodyField(await readJsonBody(req), 'enabled');
|
|
280
|
+
if (typeof wanted !== 'boolean') throw new ApiError('enabled must be true or false', 400);
|
|
281
|
+
const enabled = await deps.setAccountEnabled(session.subject, agentId, target.station, target.accountId, wanted);
|
|
282
|
+
log.info({ agentId, station: target.station, account: target.accountId, enabled }, 'account-api: account enabled flag set');
|
|
283
|
+
sendJson(req, res, 200, {
|
|
284
|
+
agentId,
|
|
285
|
+
station: target.station,
|
|
286
|
+
accountId: target.accountId,
|
|
287
|
+
enabled,
|
|
288
|
+
activated: await activate(deps, target.station),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function handleSession(
|
|
293
|
+
req: IncomingMessage,
|
|
294
|
+
res: ServerResponse,
|
|
295
|
+
deps: AccountApiDeps,
|
|
296
|
+
owner: AttachOwner,
|
|
297
|
+
attachId: string,
|
|
298
|
+
): Promise<void> {
|
|
299
|
+
if (req.method === 'DELETE') {
|
|
300
|
+
await deps.attachSessions.cancel(owner, attachId);
|
|
301
|
+
sendJson(req, res, 200, { attachId, cancelled: true });
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
sendJson(req, res, 200, deps.attachSessions.view(owner, attachId));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function handleStep(
|
|
308
|
+
req: IncomingMessage,
|
|
309
|
+
res: ServerResponse,
|
|
310
|
+
deps: AccountApiDeps,
|
|
311
|
+
owner: AttachOwner,
|
|
312
|
+
attachId: string,
|
|
313
|
+
): Promise<void> {
|
|
314
|
+
const body = await readJsonBody(req);
|
|
315
|
+
const view = await deps.attachSessions.submit(owner, attachId, {
|
|
316
|
+
code: bodyField(body, 'code'),
|
|
317
|
+
password: bodyField(body, 'password'),
|
|
318
|
+
});
|
|
319
|
+
sendJson(req, res, 200, view);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function dispatchRoute(
|
|
323
|
+
req: IncomingMessage,
|
|
324
|
+
res: ServerResponse,
|
|
325
|
+
deps: AccountApiDeps,
|
|
326
|
+
session: ApiSession,
|
|
327
|
+
agentId: string,
|
|
328
|
+
route: AccountRoute,
|
|
329
|
+
): Promise<void> {
|
|
330
|
+
if (route.kind === 'start')
|
|
331
|
+
return handleStart(req, res, deps, session, agentId);
|
|
332
|
+
if (route.kind === 'session')
|
|
333
|
+
return handleSession(
|
|
334
|
+
req,
|
|
335
|
+
res,
|
|
336
|
+
deps,
|
|
337
|
+
ownerOf(session, agentId),
|
|
338
|
+
route.attachId,
|
|
339
|
+
);
|
|
340
|
+
if (route.kind === 'step')
|
|
341
|
+
return handleStep(req, res, deps, ownerOf(session, agentId), route.attachId);
|
|
342
|
+
if (route.kind === 'allowlist') return handleAllowlist(req, res, deps, session, agentId, route);
|
|
343
|
+
if (route.kind === 'enabled') return handleEnabled(req, res, deps, session, agentId, route);
|
|
344
|
+
if (route.kind === 'resolve') return handleResolve(req, res, deps, route);
|
|
345
|
+
if (route.kind === 'senders') {
|
|
346
|
+
sendJson(req, res, 200, { senders: deps.recentSenders(route.station, route.accountId) });
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
return handleDetach(req, res, deps, session, agentId, route);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export async function handleAccountRoute(
|
|
353
|
+
req: IncomingMessage,
|
|
354
|
+
res: ServerResponse,
|
|
355
|
+
deps: AccountApiDeps,
|
|
356
|
+
session: ApiSession,
|
|
357
|
+
agentId: string,
|
|
358
|
+
route: AccountRoute,
|
|
359
|
+
): Promise<void> {
|
|
360
|
+
try {
|
|
361
|
+
await dispatchRoute(req, res, deps, session, agentId, route);
|
|
362
|
+
} catch (err) {
|
|
363
|
+
apiFailure(req, res, err);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
3
|
+
import { AGENT_NAME_RE } from '@metro-labs/core/ids';
|
|
4
|
+
|
|
5
|
+
export class AgentAdminError extends ApiError {}
|
|
6
|
+
|
|
7
|
+
export interface AgentSummary {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
owned: boolean;
|
|
11
|
+
key: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CreatedAgent {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
key: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OwnedAgent {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type DeletedAgent = OwnedAgent;
|
|
26
|
+
|
|
27
|
+
export interface ResetAgentKey extends OwnedAgent {
|
|
28
|
+
key: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function normalizeAgentName(raw: unknown): string {
|
|
32
|
+
const name = typeof raw === 'string' ? raw.trim() : '';
|
|
33
|
+
if (!AGENT_NAME_RE.test(name))
|
|
34
|
+
throw new AgentAdminError(
|
|
35
|
+
'name must be 2-32 characters of A-Z, a-z, 0-9, - or _, starting with a letter or digit',
|
|
36
|
+
400,
|
|
37
|
+
);
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function newApiKey(): string {
|
|
42
|
+
return `mk_${randomBytes(32).toString('base64url')}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
2
|
+
|
|
3
|
+
export const EVERYONE = '*';
|
|
4
|
+
const MAX_ENTRIES = 500;
|
|
5
|
+
const MAX_LENGTH = 200;
|
|
6
|
+
|
|
7
|
+
function hasControlChar(value: string): boolean {
|
|
8
|
+
for (const ch of value) {
|
|
9
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
10
|
+
if (code < 0x20 || code === 0x7f) return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function senderId(entry: unknown): string {
|
|
16
|
+
if (typeof entry !== 'string') throw new ApiError('allowlist must be a list of sender ids', 400);
|
|
17
|
+
const value = entry.trim();
|
|
18
|
+
if (value.length > MAX_LENGTH || hasControlChar(value))
|
|
19
|
+
throw new ApiError(`a sender id is at most ${String(MAX_LENGTH)} plain characters`, 400);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function normalizeAllowlist(raw: unknown): string[] {
|
|
24
|
+
if (!Array.isArray(raw)) throw new ApiError('allowlist must be a list of sender ids', 400);
|
|
25
|
+
if (raw.length > MAX_ENTRIES) throw new ApiError(`allowlist holds at most ${String(MAX_ENTRIES)} senders`, 400);
|
|
26
|
+
const seen = new Set<string>();
|
|
27
|
+
const out: string[] = [];
|
|
28
|
+
for (const entry of raw) {
|
|
29
|
+
const value = senderId(entry);
|
|
30
|
+
if (value === EVERYONE) return [EVERYONE];
|
|
31
|
+
const key = value.toLowerCase();
|
|
32
|
+
if (key === '' || seen.has(key)) continue;
|
|
33
|
+
seen.add(key);
|
|
34
|
+
out.push(value);
|
|
35
|
+
}
|
|
36
|
+
return out.length === 0 ? [EVERYONE] : out;
|
|
37
|
+
}
|