@stage-labs/metro 0.1.0-beta.2 → 0.1.0-beta.200
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 +11 -0
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +163 -0
- package/dist/cli.js +77 -567
- package/dist/control.js +74 -0
- package/dist/hold.js +211 -0
- package/dist/local.js +43 -0
- package/dist/mcp-config.js +25 -0
- package/dist/node-name.js +71 -0
- package/dist/onboarding.js +44 -0
- package/dist/provider-flags.js +9 -0
- package/dist/route.js +58 -0
- package/dist/runtime-install.js +97 -0
- package/dist/runtime.js +74 -0
- package/dist/serve.js +158 -0
- package/dist/service.js +243 -0
- package/dist/tail.js +102 -144
- package/dist/update.js +45 -0
- package/dist/version.js +97 -0
- package/package.json +14 -23
- package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +17 -0
- package/runtime/marketplace/plugin/.mcp.json +1 -0
- package/runtime/marketplace/plugin/bin/guard.mjs +71 -0
- package/runtime/marketplace/plugin/bin/metro-plugin.mjs +30 -0
- package/runtime/marketplace/plugin/bin/policy.mjs +97 -0
- package/runtime/marketplace/plugin/bin/session-start.mjs +31 -0
- package/runtime/marketplace/plugin/hooks/hooks.json +25 -0
- package/runtime/marketplace/plugin/orchestrator.md +24 -0
- package/runtime/node_modules/@metro-labs/core/package.json +47 -0
- package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/node_modules/@metro-labs/core/src/events.ts +119 -0
- package/runtime/node_modules/@metro-labs/core/src/identity.ts +7 -0
- package/runtime/node_modules/@metro-labs/core/src/ids.ts +24 -0
- package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/node_modules/@metro-labs/core/src/lines.ts +91 -0
- package/runtime/node_modules/@metro-labs/core/src/log.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/protocol.ts +227 -0
- package/runtime/node_modules/@metro-labs/core/src/secure-fs.ts +74 -0
- package/runtime/node_modules/@metro-labs/core/src/station-names.ts +13 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +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/profile.ts +58 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/station-runtime.ts +61 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/train-events.ts +89 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +123 -0
- package/runtime/node_modules/@metro-labs/core/src/str.ts +5 -0
- package/runtime/node_modules/@metro-labs/core/src/tickets.ts +37 -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/agent-user/agent-fs.ts +134 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files-api.ts +12 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +119 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/home-fs.ts +113 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/job-env.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/provision.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedule-detail.ts +100 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules-api.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +252 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/unit-files.ts +61 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-lookups.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +76 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +357 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +30 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +59 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +305 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +168 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/keys.ts +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +128 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/policy-route.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/scope.ts +64 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +86 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/api.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/needs.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/pending.ts +149 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/preview.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +221 -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 +21 -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 +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/dedupe.ts +12 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +370 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/media-note.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +78 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/react-note.ts +13 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/relay.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/channels/reply-id.ts +1 -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 +355 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +359 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/memory.ts +82 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +149 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +75 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +283 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +109 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +271 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/version.ts +113 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/api.ts +306 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/config.ts +176 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/health.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-client.ts +159 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-discovery.ts +135 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-routes.ts +158 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth.ts +166 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-policy.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-target.ts +29 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +348 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +358 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +81 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +106 -0
- package/runtime/node_modules/@metro-labs/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-reaper.ts +174 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +278 -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 +233 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-device.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-stream.ts +173 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +194 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +137 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +77 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +237 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/frames.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +274 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-auth.ts +160 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-client.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-setup.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-stream.ts +139 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-translate.ts +223 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +199 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +299 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +193 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-store.ts +70 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/pkce.ts +36 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/subscription.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/text.ts +15 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +244 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +156 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/attachment-schema.ts +91 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +226 -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 +90 -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 +137 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/instructions.ts +19 -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-prompt.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +83 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-snapshot.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-lookup.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-tool.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/raw-get-stream.ts +207 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/read-tool.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-slot.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +202 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +88 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-def.ts +9 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-dispatch.ts +225 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-schemas.ts +333 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/upload-tool.ts +61 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/api.ts +43 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/move.ts +165 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/privilege.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +316 -0
- package/runtime/node_modules/@metro-labs/daemon/src/policy/policy.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/bearer.ts +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +365 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +208 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +71 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session.ts +29 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/threema-callback.ts +103 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/control.ts +39 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +58 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/owner.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-driver.ts +42 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-inline.ts +128 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-interactive.ts +134 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-outlook.ts +63 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +225 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-session.ts +288 -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 +265 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/registry.ts +51 -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/stations/webhook-endpoints.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +84 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +124 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +15 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/api.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/config.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/firewall.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/index.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/install.ts +56 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/paths.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/proxy.ts +148 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/store.ts +130 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/trust.ts +61 -0
- package/runtime/node_modules/@metro-labs/discord-bot/package.json +26 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +117 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +240 -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 +174 -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 +122 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +215 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +68 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +43 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +22 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +82 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +1 -0
- package/runtime/node_modules/@metro-labs/http/package.json +29 -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 +138 -0
- package/runtime/node_modules/@metro-labs/http/src/cors.ts +29 -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/workos-token.ts +149 -0
- package/runtime/node_modules/@metro-labs/outlook/package.json +25 -0
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +107 -0
- package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +20 -0
- package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +97 -0
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +150 -0
- package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +53 -0
- package/runtime/node_modules/@metro-labs/outlook/src/config.ts +36 -0
- package/runtime/node_modules/@metro-labs/outlook/src/format.ts +141 -0
- package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +60 -0
- package/runtime/node_modules/@metro-labs/outlook/src/html.ts +72 -0
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +104 -0
- package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/outlook/src/login.ts +150 -0
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +41 -0
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +116 -0
- package/runtime/node_modules/@metro-labs/outlook/src/query.ts +119 -0
- package/runtime/node_modules/@metro-labs/outlook/src/state.ts +43 -0
- package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +26 -0
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +80 -0
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +256 -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 +128 -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 +57 -0
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +7 -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/profile.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +167 -0
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +27 -0
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +6 -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 +119 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +246 -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 +173 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +103 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +95 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +47 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +65 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +20 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +56 -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 +1 -0
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +106 -0
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +134 -0
- package/runtime/node_modules/@metro-labs/threema/src/api.ts +152 -0
- package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +100 -0
- package/runtime/node_modules/@metro-labs/threema/src/files.ts +58 -0
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +169 -0
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +96 -0
- package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +89 -0
- package/runtime/node_modules/@metro-labs/threema/src/index.ts +24 -0
- package/runtime/node_modules/@metro-labs/threema/src/messages.ts +264 -0
- package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +160 -0
- package/runtime/node_modules/@metro-labs/threema/src/station.ts +13 -0
- package/runtime/node_modules/@metro-labs/threema/src/verify.ts +117 -0
- package/runtime/node_modules/@metro-labs/webhook/package.json +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 +213 -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 +388 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/delivery.ts +49 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +83 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +40 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +7 -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/names.ts +28 -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 +24 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +94 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +5 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +1 -0
- package/runtime/node_modules/@metro-labs/xmtp/package.json +34 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +114 -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 +101 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +118 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +244 -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-payloads.ts +316 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +69 -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 +47 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +122 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +139 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +40 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +61 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +153 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +112 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/smart.ts +72 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +17 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +79 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +198 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +88 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +98 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +51 -0
- package/runtime/runtime.json +3 -0
- package/runtime/server.ts +1 -0
- package/runtime/stations.json +37 -0
- package/runtime/trains/.keep +0 -0
- package/LICENSE +0 -21
- package/README.md +0 -78
- package/dist/channels/discord.js +0 -148
- package/dist/channels/telegram.js +0 -137
- package/dist/lib/address.js +0 -21
- package/dist/lib/codex-rc.js +0 -274
- package/dist/lib/dotenv.js +0 -31
- package/dist/log.js +0 -12
- package/dist/paths.js +0 -45
- package/skills/metro/SKILL.md +0 -122
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type {
|
|
3
|
+
StreamableHTTPServerTransport,
|
|
4
|
+
EventId,
|
|
5
|
+
} from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
6
|
+
import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import type { BoundedEventStore } from './event-store.js';
|
|
8
|
+
|
|
9
|
+
const STANDALONE_STREAM_ID = '_GET_stream';
|
|
10
|
+
const KEEPALIVE_MS = 15_000;
|
|
11
|
+
const RECONNECT_RETRY_MS = 15_000;
|
|
12
|
+
const COMMENT = ':\n\n';
|
|
13
|
+
const RETRY_DIRECTIVE = `retry: ${RECONNECT_RETRY_MS}\n\n`;
|
|
14
|
+
|
|
15
|
+
interface StreamEntry {
|
|
16
|
+
controller: { enqueue: (chunk: Uint8Array) => void };
|
|
17
|
+
encoder: { encode: (input: string) => Uint8Array };
|
|
18
|
+
cleanup: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WebTransport {
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
_initialized?: boolean;
|
|
24
|
+
_streamMapping?: Map<string, StreamEntry>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface AdaptedTransport {
|
|
28
|
+
_webStandardTransport?: WebTransport;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const web = (
|
|
32
|
+
transport: StreamableHTTPServerTransport,
|
|
33
|
+
): WebTransport | undefined =>
|
|
34
|
+
(transport as unknown as AdaptedTransport)._webStandardTransport;
|
|
35
|
+
|
|
36
|
+
export const isStandaloneGet = (req: IncomingMessage): boolean => {
|
|
37
|
+
if (req.method !== 'GET') return false;
|
|
38
|
+
const accept = req.headers.accept;
|
|
39
|
+
const value = Array.isArray(accept) ? accept.join(',') : (accept ?? '');
|
|
40
|
+
return value.includes('text/event-stream');
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const headerValue = (
|
|
44
|
+
req: IncomingMessage,
|
|
45
|
+
name: string,
|
|
46
|
+
): string | undefined => {
|
|
47
|
+
const raw = req.headers[name];
|
|
48
|
+
if (Array.isArray(raw)) return raw[0];
|
|
49
|
+
return typeof raw === 'string' ? raw : undefined;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export interface RawGetSink {
|
|
53
|
+
closed: boolean;
|
|
54
|
+
attach: (transport: StreamableHTTPServerTransport) => void;
|
|
55
|
+
close: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ValidateResult {
|
|
59
|
+
ok: boolean;
|
|
60
|
+
status?: number;
|
|
61
|
+
message?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function validateStandaloneSession(
|
|
65
|
+
transport: StreamableHTTPServerTransport,
|
|
66
|
+
req: IncomingMessage,
|
|
67
|
+
): ValidateResult {
|
|
68
|
+
const inner = web(transport);
|
|
69
|
+
if (!inner) return { ok: false, status: 500, message: 'transport not ready' };
|
|
70
|
+
if (!inner._initialized)
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
status: 400,
|
|
74
|
+
message: 'Bad Request: Server not initialized',
|
|
75
|
+
};
|
|
76
|
+
const presented = headerValue(req, 'mcp-session-id');
|
|
77
|
+
if (!presented)
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
status: 400,
|
|
81
|
+
message: 'Bad Request: Mcp-Session-Id header is required',
|
|
82
|
+
};
|
|
83
|
+
if (presented !== inner.sessionId)
|
|
84
|
+
return { ok: false, status: 404, message: 'Session not found' };
|
|
85
|
+
return { ok: true };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ServeOpts {
|
|
89
|
+
transport: StreamableHTTPServerTransport;
|
|
90
|
+
eventStore: BoundedEventStore;
|
|
91
|
+
scope: Set<string>;
|
|
92
|
+
req: IncomingMessage;
|
|
93
|
+
res: ServerResponse;
|
|
94
|
+
log: (...a: unknown[]) => void;
|
|
95
|
+
registerSink: (sink: RawGetSink | undefined) => void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function serveStandaloneGet(opts: ServeOpts): Promise<void> {
|
|
99
|
+
const { transport, eventStore, scope, req, res, log, registerSink } = opts;
|
|
100
|
+
const sessionId = web(transport)?.sessionId;
|
|
101
|
+
|
|
102
|
+
res.writeHead(200, {
|
|
103
|
+
'content-type': 'text/event-stream',
|
|
104
|
+
'cache-control': 'no-cache, no-transform',
|
|
105
|
+
connection: 'keep-alive',
|
|
106
|
+
'x-accel-buffering': 'no',
|
|
107
|
+
...(sessionId ? { 'mcp-session-id': sessionId } : {}),
|
|
108
|
+
});
|
|
109
|
+
res.flushHeaders?.();
|
|
110
|
+
res.write(RETRY_DIRECTIVE);
|
|
111
|
+
res.write(COMMENT);
|
|
112
|
+
|
|
113
|
+
let active = transport;
|
|
114
|
+
const timers: { keepalive?: ReturnType<typeof setInterval> } = {};
|
|
115
|
+
const closeStream = (): void => {
|
|
116
|
+
if (sink.closed) return;
|
|
117
|
+
sink.closed = true;
|
|
118
|
+
if (timers.keepalive) clearInterval(timers.keepalive);
|
|
119
|
+
web(active)?._streamMapping?.delete(STANDALONE_STREAM_ID);
|
|
120
|
+
registerSink(undefined);
|
|
121
|
+
try {
|
|
122
|
+
res.end();
|
|
123
|
+
} catch {
|
|
124
|
+
log('raw-get-stream: end failed');
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const sink: RawGetSink = {
|
|
128
|
+
closed: false,
|
|
129
|
+
attach: (next: StreamableHTTPServerTransport): void => {
|
|
130
|
+
active = next;
|
|
131
|
+
const entry: StreamEntry = {
|
|
132
|
+
controller: {
|
|
133
|
+
enqueue: (chunk: Uint8Array): void => {
|
|
134
|
+
if (sink.closed) return;
|
|
135
|
+
if (res.destroyed || res.writableEnded) {
|
|
136
|
+
closeStream();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
res.write(Buffer.from(chunk));
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
encoder: { encode: (input: string): Uint8Array => Buffer.from(input) },
|
|
143
|
+
cleanup: closeStream,
|
|
144
|
+
};
|
|
145
|
+
web(next)?._streamMapping?.set(STANDALONE_STREAM_ID, entry);
|
|
146
|
+
},
|
|
147
|
+
close: closeStream,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const lastEventId = headerValue(req, 'last-event-id');
|
|
151
|
+
if (lastEventId) {
|
|
152
|
+
await eventStore.replayEventsAfter(lastEventId, {
|
|
153
|
+
scope,
|
|
154
|
+
send: (id: EventId, message: JSONRPCMessage): Promise<void> => {
|
|
155
|
+
if (!sink.closed)
|
|
156
|
+
res.write(`event: message\nid: ${id}\ndata: ${JSON.stringify(message)}\n\n`);
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
},
|
|
159
|
+
onWithheld: (id: EventId, line: string | undefined): void => {
|
|
160
|
+
log(
|
|
161
|
+
'raw-get-stream: withheld replay (frame outside the reconnecting session scope)',
|
|
162
|
+
'id',
|
|
163
|
+
id,
|
|
164
|
+
'line',
|
|
165
|
+
line ?? '(none)',
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
sink.attach(transport);
|
|
172
|
+
registerSink(sink);
|
|
173
|
+
|
|
174
|
+
timers.keepalive = setInterval(() => {
|
|
175
|
+
if (sink.closed) return;
|
|
176
|
+
if (res.destroyed || res.writableEnded) {
|
|
177
|
+
closeStream();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
res.write(COMMENT);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
log('raw-get-stream: keepalive write failed', err);
|
|
184
|
+
closeStream();
|
|
185
|
+
}
|
|
186
|
+
}, KEEPALIVE_MS);
|
|
187
|
+
timers.keepalive.unref?.();
|
|
188
|
+
|
|
189
|
+
res.on('close', closeStream);
|
|
190
|
+
res.on('error', closeStream);
|
|
191
|
+
req.on('close', closeStream);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface ChannelGetOpts extends ServeOpts {
|
|
195
|
+
previous: RawGetSink | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function serveChannelGet(opts: ChannelGetOpts): Promise<boolean> {
|
|
199
|
+
const check = validateStandaloneSession(opts.transport, opts.req);
|
|
200
|
+
if (!check.ok) {
|
|
201
|
+
opts.res.writeHead(check.status ?? 400).end(check.message ?? 'bad request');
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
if (opts.previous && !opts.previous.closed) opts.previous.close();
|
|
205
|
+
await serveStandaloneGet(opts);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
2
|
+
import { str } from '@metro-labs/core/str';
|
|
3
|
+
import type { ReadFilter, Station, ToolResult } from '@metro-labs/core/stations/types';
|
|
4
|
+
import { agentIdForAccount, accountFromLine, knownAccounts } from '../agents/map.js';
|
|
5
|
+
import { attachmentUrl } from '../files/attach-serve.js';
|
|
6
|
+
import { stationByName } from '../stations/registry.js';
|
|
7
|
+
import { errResult, makeCtx, okJson, toErr } from './ctx.js';
|
|
8
|
+
import { agentUser } from '../agent-user/user.js';
|
|
9
|
+
|
|
10
|
+
const FILTERS: readonly (readonly [string, ReadFilter, string])[] = [
|
|
11
|
+
['query', 'query', 'query'],
|
|
12
|
+
['from', 'from', 'from'],
|
|
13
|
+
['until', 'until', 'until'],
|
|
14
|
+
['unread_only', 'unread_only', 'unreadOnly'],
|
|
15
|
+
['message_id', 'message_id', 'messageId'],
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const given = (v: unknown): boolean => v !== undefined && v !== null && v !== '' && v !== false;
|
|
19
|
+
|
|
20
|
+
export function stationOfAccount(account: string): string | undefined {
|
|
21
|
+
const hits = knownAccounts().filter((a) => a.id === account);
|
|
22
|
+
return hits.length === 1 ? hits[0]?.station : undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readArgs(a: Record<string, unknown>): Record<string, unknown> {
|
|
26
|
+
const args: Record<string, unknown> = {};
|
|
27
|
+
if (str(a.line)) args.line = str(a.line);
|
|
28
|
+
if (str(a.account)) args.account = str(a.account);
|
|
29
|
+
if (typeof a.limit === 'number') args.limit = a.limit;
|
|
30
|
+
if (a.before) args.before = str(a.before);
|
|
31
|
+
if (a.since) args.since = str(a.since);
|
|
32
|
+
for (const [snake, , camel] of FILTERS)
|
|
33
|
+
if (given(a[snake])) args[camel] = typeof a[snake] === 'boolean' ? a[snake] : str(a[snake]);
|
|
34
|
+
return args;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function ignoredFilters(station: Station, a: Record<string, unknown>): string[] {
|
|
38
|
+
const supported = station.readFilters ?? new Set<ReadFilter>();
|
|
39
|
+
return FILTERS.filter(([snake, filter]) => given(a[snake]) && !supported.has(filter)).map(([snake]) => snake);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function withUrls(result: unknown, agentId: string | undefined): unknown {
|
|
43
|
+
if (agentId === undefined || !isRecord(result) || !isRecord(result.message)) return result;
|
|
44
|
+
const files = result.message.attachments;
|
|
45
|
+
if (!Array.isArray(files)) return result;
|
|
46
|
+
const attachments = files.map((f: unknown) => {
|
|
47
|
+
if (!isRecord(f) || typeof f.local_path !== 'string') return f;
|
|
48
|
+
const url = attachmentUrl(f.local_path, agentId);
|
|
49
|
+
const shown = agentUser() === null ? f : Object.fromEntries(Object.entries(f).filter(([key]) => key !== 'local_path'));
|
|
50
|
+
return url === null ? shown : { ...shown, url };
|
|
51
|
+
});
|
|
52
|
+
return { ...result, message: { ...result.message, attachments } };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function answer(result: unknown, ignored: string[]): unknown {
|
|
56
|
+
if (ignored.length === 0) return result;
|
|
57
|
+
return isRecord(result) && !Array.isArray(result) ? { ...result, ignored } : { result, ignored };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function accountOfCall(station: Station, a: Record<string, unknown>, result: unknown): string | undefined {
|
|
61
|
+
const named = str(a.account) || (isRecord(result) ? str(result.account) : '');
|
|
62
|
+
const account = named || accountFromLine(str(a.line))?.accountId;
|
|
63
|
+
return account === undefined ? undefined : agentIdForAccount(station.name, account);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function runRead(station: Station, a: Record<string, unknown>): Promise<ToolResult> {
|
|
67
|
+
try {
|
|
68
|
+
const response = await makeCtx(station.name).call('read', readArgs(a));
|
|
69
|
+
const result = withUrls(response.result, accountOfCall(station, a, response.result));
|
|
70
|
+
return okJson(answer(result, ignoredFilters(station, a)));
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return toErr('read', e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function linelessRead(a: Record<string, unknown>): Promise<ToolResult> | ToolResult {
|
|
77
|
+
const account = str(a.account);
|
|
78
|
+
if (!account) return errResult('read requires `line` or `account`');
|
|
79
|
+
const name = stationOfAccount(account);
|
|
80
|
+
const station = name === undefined ? undefined : stationByName(name);
|
|
81
|
+
if (station === undefined) return errResult(`no account ${account} on this box; list_accounts names them`);
|
|
82
|
+
if (!station.messageVerbs.has('read'))
|
|
83
|
+
return errResult(`${station.name} does not support read; it supports ${[...station.messageVerbs].join(', ')}.`);
|
|
84
|
+
if (!station.readFilters?.has('account'))
|
|
85
|
+
return errResult(`${station.name} reads one conversation at a time; give a \`line\` instead of an account`);
|
|
86
|
+
return runRead(station, a);
|
|
87
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import { agentIdForKey } from '../agents/keys.js';
|
|
4
|
+
|
|
5
|
+
export interface RequestIdentity {
|
|
6
|
+
kind: 'agent';
|
|
7
|
+
agentId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const storage = new AsyncLocalStorage<RequestIdentity>();
|
|
11
|
+
|
|
12
|
+
export function runWithIdentity<T>(
|
|
13
|
+
identity: RequestIdentity,
|
|
14
|
+
fn: () => Promise<T>,
|
|
15
|
+
): Promise<T> {
|
|
16
|
+
return storage.run(identity, fn);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function currentIdentity(): RequestIdentity | undefined {
|
|
20
|
+
return storage.getStore();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function extractToken(req: IncomingMessage): string | undefined {
|
|
24
|
+
const header = req.headers.authorization;
|
|
25
|
+
if (header?.startsWith('Bearer ')) {
|
|
26
|
+
const t = header.slice(7).trim();
|
|
27
|
+
if (t) return t;
|
|
28
|
+
}
|
|
29
|
+
const qt = new URL(req.url ?? '/', 'http://localhost').searchParams.get(
|
|
30
|
+
'token',
|
|
31
|
+
);
|
|
32
|
+
return qt ?? undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function authenticate(req: IncomingMessage): RequestIdentity | null {
|
|
36
|
+
const token = extractToken(req);
|
|
37
|
+
if (!token) return null;
|
|
38
|
+
const agentId = agentIdForKey(token);
|
|
39
|
+
return agentId === undefined ? null : { kind: 'agent', agentId };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function allowedAgents(
|
|
43
|
+
identity: RequestIdentity | undefined,
|
|
44
|
+
): Set<string> {
|
|
45
|
+
return identity ? new Set([identity.agentId]) : new Set();
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { currentBusSeq } from '@metro-labs/core/events';
|
|
3
|
+
import { newReplayLedger } from '../channels/relay.js';
|
|
4
|
+
import { McpSession, channelLog } from './session.js';
|
|
5
|
+
import { allowedAgents, type RequestIdentity } from './request-identity.js';
|
|
6
|
+
|
|
7
|
+
export class SessionSlot {
|
|
8
|
+
private session: McpSession | undefined;
|
|
9
|
+
private readonly ledger = newReplayLedger();
|
|
10
|
+
private started = false;
|
|
11
|
+
|
|
12
|
+
get current(): McpSession | undefined {
|
|
13
|
+
return this.session;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
startInbound(): void {
|
|
17
|
+
if (this.started) return;
|
|
18
|
+
this.started = true;
|
|
19
|
+
if (this.ledger.startAt < 0) this.ledger.startAt = currentBusSeq();
|
|
20
|
+
this.session?.startChannel();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async open(
|
|
24
|
+
identity: RequestIdentity,
|
|
25
|
+
adoptId?: string,
|
|
26
|
+
): Promise<McpSession> {
|
|
27
|
+
await this.session?.close();
|
|
28
|
+
if (this.ledger.startAt < 0) this.ledger.startAt = currentBusSeq();
|
|
29
|
+
const id = adoptId ?? randomUUID();
|
|
30
|
+
const session = await McpSession.open({
|
|
31
|
+
id,
|
|
32
|
+
scope: allowedAgents(identity),
|
|
33
|
+
adopted: adoptId !== undefined,
|
|
34
|
+
ledger: this.ledger,
|
|
35
|
+
onClosed: (s) => {
|
|
36
|
+
if (this.session === s) this.session = undefined;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
this.session = session;
|
|
40
|
+
if (this.started) session.startChannel();
|
|
41
|
+
channelLog('session: opened', 'id', id, 'adopted', adoptId !== undefined);
|
|
42
|
+
return session;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async close(): Promise<void> {
|
|
46
|
+
await this.session?.close();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
+
import { InboundRelay } from '../channels/inbound.js';
|
|
4
|
+
import { answerPrompt, forgetPromptsOf, promptLine } from '../approvals/pending.js';
|
|
5
|
+
import { ChannelRelay, type ReplayLedger } from '../channels/relay.js';
|
|
6
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
7
|
+
import { allowlistForLine, mayApprove, senderPermitted } from '../agents/map.js';
|
|
8
|
+
import { accountStationNames, stationByName } from '../stations/registry.js';
|
|
9
|
+
import { eventInScope } from '../agents/scope.js';
|
|
10
|
+
import { MCP_INSTRUCTIONS } from './instructions.js';
|
|
11
|
+
import { BoundedEventStore } from './event-store.js';
|
|
12
|
+
import { registerPermissionRelay } from './permission-relay.js';
|
|
13
|
+
import { registerToolHandlers, toolSchemaSignature } from './tool-dispatch.js';
|
|
14
|
+
import { web, type RawGetSink } from './raw-get-stream.js';
|
|
15
|
+
|
|
16
|
+
export const channelLog = (...a: unknown[]): void => {
|
|
17
|
+
console.error('[metro-mcp]', ...a);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getStations = (): Set<string> => new Set(accountStationNames());
|
|
21
|
+
|
|
22
|
+
const senderAllowed = (from: string, line: string, verified?: boolean): boolean =>
|
|
23
|
+
senderPermitted(allowlistForLine(line), from, verified);
|
|
24
|
+
|
|
25
|
+
const approves = (station: string): boolean => stationByName(station)?.approvals !== false;
|
|
26
|
+
|
|
27
|
+
async function answerPermission(requestId: string, behavior: 'allow' | 'deny', line: string, from: string): Promise<boolean> {
|
|
28
|
+
if (promptLine(requestId) !== line || !mayApprove(line, from)) return false;
|
|
29
|
+
return (await answerPrompt(requestId, behavior, 'chat', line)) !== undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function makeTransport(
|
|
33
|
+
id: string,
|
|
34
|
+
eventStore: BoundedEventStore,
|
|
35
|
+
adopted: boolean,
|
|
36
|
+
): StreamableHTTPServerTransport {
|
|
37
|
+
const t = new StreamableHTTPServerTransport({
|
|
38
|
+
sessionIdGenerator: () => id,
|
|
39
|
+
eventStore,
|
|
40
|
+
});
|
|
41
|
+
if (!adopted) return t;
|
|
42
|
+
const inner = web(t);
|
|
43
|
+
if (inner) {
|
|
44
|
+
inner.sessionId = id;
|
|
45
|
+
inner._initialized = true;
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SessionInit {
|
|
51
|
+
id: string;
|
|
52
|
+
scope: Set<string>;
|
|
53
|
+
adopted: boolean;
|
|
54
|
+
ledger: ReplayLedger;
|
|
55
|
+
onClosed: (session: McpSession) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class McpSession {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
readonly scope: Set<string>;
|
|
61
|
+
readonly eventStore: BoundedEventStore;
|
|
62
|
+
readonly transport: StreamableHTTPServerTransport;
|
|
63
|
+
readonly server: Server;
|
|
64
|
+
readonly relay: InboundRelay;
|
|
65
|
+
readonly channel: ChannelRelay;
|
|
66
|
+
private sink: RawGetSink | undefined;
|
|
67
|
+
private unsubscribe: (() => void) | undefined;
|
|
68
|
+
private closed = false;
|
|
69
|
+
private issuedSchema: string | undefined;
|
|
70
|
+
private announcing = false;
|
|
71
|
+
private readonly onClosed: (session: McpSession) => void;
|
|
72
|
+
|
|
73
|
+
private constructor(init: SessionInit) {
|
|
74
|
+
this.id = init.id;
|
|
75
|
+
this.scope = init.scope;
|
|
76
|
+
this.issuedSchema = init.adopted ? undefined : toolSchemaSignature();
|
|
77
|
+
this.onClosed = init.onClosed;
|
|
78
|
+
this.eventStore = new BoundedEventStore();
|
|
79
|
+
this.transport = makeTransport(init.id, this.eventStore, init.adopted);
|
|
80
|
+
this.server = new Server(
|
|
81
|
+
{ name: 'metro', version: '0.1.0' },
|
|
82
|
+
{
|
|
83
|
+
capabilities: {
|
|
84
|
+
experimental: {
|
|
85
|
+
'claude/channel': {},
|
|
86
|
+
'claude/channel/permission': {},
|
|
87
|
+
},
|
|
88
|
+
tools: { listChanged: true },
|
|
89
|
+
},
|
|
90
|
+
instructions: MCP_INSTRUCTIONS,
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
registerToolHandlers(this.server, {
|
|
94
|
+
markCurrent: (): void => {
|
|
95
|
+
this.issuedSchema = toolSchemaSignature();
|
|
96
|
+
},
|
|
97
|
+
deliver: (send): void => {
|
|
98
|
+
this.deliverSchemaNotice(send, 'request');
|
|
99
|
+
},
|
|
100
|
+
}, {
|
|
101
|
+
onSent: (id): void => {
|
|
102
|
+
this.relay.noteSent(id);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
this.relay = new InboundRelay({
|
|
106
|
+
mcp: this.server,
|
|
107
|
+
log: channelLog,
|
|
108
|
+
getStations,
|
|
109
|
+
senderAllowed,
|
|
110
|
+
approves,
|
|
111
|
+
answerPermission,
|
|
112
|
+
});
|
|
113
|
+
registerPermissionRelay({
|
|
114
|
+
mcp: this.server,
|
|
115
|
+
relay: this.relay,
|
|
116
|
+
inScope: (line) => this.inScope(line),
|
|
117
|
+
log: channelLog,
|
|
118
|
+
});
|
|
119
|
+
this.channel = new ChannelRelay({
|
|
120
|
+
relay: this.relay,
|
|
121
|
+
log: channelLog,
|
|
122
|
+
inScope: (line) => this.inScope(line),
|
|
123
|
+
ledger: init.ledger,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static async open(init: SessionInit): Promise<McpSession> {
|
|
128
|
+
const session = new McpSession(init);
|
|
129
|
+
await session.server.connect(session.transport);
|
|
130
|
+
session.server.onclose = (): void => {
|
|
131
|
+
session.close().catch((err: unknown) => {
|
|
132
|
+
channelLog('session: close failed', 'id', init.id, errMsg(err));
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
return session;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get streamAttached(): boolean {
|
|
139
|
+
return this.sink !== undefined && !this.sink.closed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get currentSink(): RawGetSink | undefined {
|
|
143
|
+
return this.sink;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
inScope(line: string): boolean {
|
|
147
|
+
return this.streamAttached && eventInScope(this.scope, line);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
startChannel(): void {
|
|
151
|
+
this.unsubscribe ??= this.channel.start();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
bindSink(sink: RawGetSink | undefined): void {
|
|
155
|
+
this.sink = sink;
|
|
156
|
+
if (sink !== undefined) this.announceToolSchema();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private get schemaNoticeDue(): boolean {
|
|
160
|
+
return this.issuedSchema !== toolSchemaSignature();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private announceToolSchema(): void {
|
|
164
|
+
if (!this.streamAttached) return;
|
|
165
|
+
this.deliverSchemaNotice(
|
|
166
|
+
() => this.server.sendToolListChanged(),
|
|
167
|
+
'stream',
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private deliverSchemaNotice(send: () => Promise<void>, via: string): void {
|
|
172
|
+
if (!this.schemaNoticeDue || this.announcing) return;
|
|
173
|
+
this.announcing = true;
|
|
174
|
+
channelLog('session: tool list changed', 'id', this.id, 'via', via);
|
|
175
|
+
send()
|
|
176
|
+
.then(() => {
|
|
177
|
+
this.issuedSchema = toolSchemaSignature();
|
|
178
|
+
this.announcing = false;
|
|
179
|
+
})
|
|
180
|
+
.catch((err: unknown) => {
|
|
181
|
+
this.announcing = false;
|
|
182
|
+
channelLog('session: tool list changed notice failed', errMsg(err));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
dropStream(): void {
|
|
187
|
+
const sink = this.sink;
|
|
188
|
+
this.sink = undefined;
|
|
189
|
+
sink?.close();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async close(): Promise<void> {
|
|
193
|
+
if (this.closed) return;
|
|
194
|
+
this.closed = true;
|
|
195
|
+
this.onClosed(this);
|
|
196
|
+
forgetPromptsOf(this.server);
|
|
197
|
+
this.dropStream();
|
|
198
|
+
this.unsubscribe?.();
|
|
199
|
+
this.unsubscribe = undefined;
|
|
200
|
+
await this.server.close().catch(() => undefined);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { GroupOp, Station, StationTool, ToolGroup } from '@metro-labs/core/stations/types';
|
|
2
|
+
import { STATIONS } from '../stations/registry.js';
|
|
3
|
+
import { COMMON_TOOLS, LIST_ACCOUNTS_TOOL } from './tool-schemas.js';
|
|
4
|
+
import { SET_PROFILE_TOOL } from './profile-tool.js';
|
|
5
|
+
import { GET_PROFILE_TOOL } from './profile-lookup.js';
|
|
6
|
+
import type { ToolDef } from './tool-def.js';
|
|
7
|
+
|
|
8
|
+
const defOf = (tool: StationTool): ToolDef => ({
|
|
9
|
+
name: tool.name,
|
|
10
|
+
description: tool.description,
|
|
11
|
+
inputSchema: tool.inputSchema,
|
|
12
|
+
...(tool.group === undefined ? {} : { group: tool.group }),
|
|
13
|
+
...(tool.destructive === true ? { destructive: true } : {}),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const TOOL_DEFS: ToolDef[] = [
|
|
17
|
+
...COMMON_TOOLS,
|
|
18
|
+
...STATIONS.flatMap((s) => s.tools.map(defOf)),
|
|
19
|
+
LIST_ACCOUNTS_TOOL,
|
|
20
|
+
SET_PROFILE_TOOL,
|
|
21
|
+
GET_PROFILE_TOOL,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const BY_NAME = new Map(TOOL_DEFS.map((d) => [d.name, d] as const));
|
|
25
|
+
|
|
26
|
+
export const declaredGroup = (name: string): ToolGroup | undefined => BY_NAME.get(name)?.group;
|
|
27
|
+
|
|
28
|
+
export const toolGroupOf = (name: string): ToolGroup => declaredGroup(name) ?? 'write';
|
|
29
|
+
|
|
30
|
+
export interface ToolAnnotations {
|
|
31
|
+
readOnlyHint: boolean;
|
|
32
|
+
destructiveHint?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PublishedTool {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
inputSchema: Record<string, unknown>;
|
|
39
|
+
annotations: ToolAnnotations;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const annotationsOf = (def: ToolDef): ToolAnnotations =>
|
|
43
|
+
toolGroupOf(def.name) === 'read'
|
|
44
|
+
? { readOnlyHint: true }
|
|
45
|
+
: { readOnlyHint: false, destructiveHint: def.destructive === true };
|
|
46
|
+
|
|
47
|
+
export const listedTools = (): PublishedTool[] =>
|
|
48
|
+
TOOL_DEFS.map((def) => ({
|
|
49
|
+
name: def.name,
|
|
50
|
+
description: def.description,
|
|
51
|
+
inputSchema: def.inputSchema,
|
|
52
|
+
annotations: annotationsOf(def),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const STATION_OF_TOOL = new Map(STATIONS.flatMap((s) => s.tools.map((t) => [t.name, s.name] as const)));
|
|
56
|
+
|
|
57
|
+
export const stationToolOwners = (): Record<string, string> => Object.fromEntries(STATION_OF_TOOL);
|
|
58
|
+
|
|
59
|
+
export function stationForTool(name: string, args: Record<string, unknown>): string | undefined {
|
|
60
|
+
if (name === 'create_group' || name === 'set_profile')
|
|
61
|
+
return typeof args.station === 'string' && args.station !== '' ? args.station : undefined;
|
|
62
|
+
return STATION_OF_TOOL.get(name);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const GROUP_OP_TOOLS: Record<GroupOp, string> = {
|
|
66
|
+
create_group: 'create_group',
|
|
67
|
+
add_members: 'add_members',
|
|
68
|
+
remove_members: 'remove_members',
|
|
69
|
+
invite_link: 'export_invite',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export interface GroupedTool {
|
|
73
|
+
name: string;
|
|
74
|
+
group: ToolGroup;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const stationToolGroups = (): Record<string, GroupedTool[]> =>
|
|
78
|
+
Object.fromEntries(STATIONS.filter((s) => s.hasAccounts).map((s) => [s.name, channelToolsOf(s)]));
|
|
79
|
+
|
|
80
|
+
export function channelToolsOf(station: Station): GroupedTool[] {
|
|
81
|
+
const names: string[] = [...station.messageVerbs];
|
|
82
|
+
if (station.hasTrain && station.hasAccounts) names.push('list_members');
|
|
83
|
+
for (const op of station.groupOps ?? []) names.push(GROUP_OP_TOOLS[op]);
|
|
84
|
+
if ((station.profileFields?.size ?? 0) > 0) names.push('set_profile');
|
|
85
|
+
if (station.readsProfiles === true) names.push('get_profile');
|
|
86
|
+
names.push(...station.tools.map((t) => t.name));
|
|
87
|
+
return names.map((name) => ({ name, group: toolGroupOf(name) }));
|
|
88
|
+
}
|