@stage-labs/metro 0.1.0-beta.22 → 0.1.0-beta.221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +9 -101
- package/dist/background.js +123 -0
- package/dist/claude-settings.js +40 -0
- package/dist/claude.js +173 -0
- package/dist/cli.js +52 -109
- package/dist/control.js +47 -75
- package/dist/hold.js +210 -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 +96 -0
- package/dist/runtime.js +29 -52
- package/dist/serve.js +157 -0
- package/dist/service.js +304 -0
- package/dist/tail.js +119 -0
- package/dist/update.js +13 -1
- package/package.json +2 -23
- package/runtime/marketplace/.claude-plugin/marketplace.json +12 -0
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +17 -0
- package/runtime/marketplace/plugin/.mcp.json +1 -0
- package/runtime/marketplace/plugin/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 +26 -0
- package/runtime/node_modules/@metro-labs/core/package.json +51 -0
- package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/events.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp/src/db → core/src}/ids.ts +5 -0
- package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/stations → core/src}/lines.ts +22 -26
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/protocol.ts +7 -4
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/secure-fs.ts +17 -0
- package/runtime/node_modules/@metro-labs/core/src/station-names.ts +14 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-files.ts +41 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +83 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/attachments.ts +0 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +72 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-trust.ts +29 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +212 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +16 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +126 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +58 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/sender-profile.ts +64 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/station-runtime.ts +6 -11
- package/runtime/node_modules/@metro-labs/core/src/stations/train-boot.ts +42 -0
- package/runtime/node_modules/@metro-labs/core/src/stations/train-events.ts +84 -0
- package/runtime/node_modules/@metro-labs/{mcp → core}/src/stations/types.ts +18 -1
- package/runtime/node_modules/@metro-labs/core/src/tickets.ts +37 -0
- package/runtime/node_modules/@metro-labs/core/src/version.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/package.json +49 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/agent-fs.ts +134 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files-api.ts +12 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +89 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/home-fs.ts +113 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/job-env.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/provision.ts +80 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedule-detail.ts +99 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules-api.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +144 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/unit-files.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +89 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-lookups.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/account-routes.ts +76 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +357 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +30 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +59 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +305 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +142 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/key-map.ts → daemon/src/agents/keys.ts} +1 -11
- package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +133 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/policy-route.ts +27 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/db/agent-scope.ts → daemon/src/agents/scope.ts} +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +94 -0
- package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/api.ts +55 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/pending.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/approvals/preview.ts +66 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +219 -0
- package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +36 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/crash-guard.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +21 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/boot}/paths.ts +6 -34
- package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +26 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/inbound.ts +75 -45
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/media-note.ts +11 -7
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/pending.ts +4 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/relay.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +368 -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 +32 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/onboarding.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/plugin-install.ts +149 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session-files.ts +75 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +295 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +109 -0
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +282 -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/{mcp/src/daemon/connector-api.ts → daemon/src/connectors/api.ts} +79 -113
- package/runtime/node_modules/@metro-labs/{mcp/src/db/connector-config.ts → daemon/src/connectors/config.ts} +67 -41
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +72 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/health.ts +18 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-client.ts +14 -17
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/connectors}/oauth-discovery.ts +33 -20
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth-routes.ts → daemon/src/connectors/oauth-routes.ts} +30 -32
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/connector-oauth.ts → daemon/src/connectors/oauth.ts} +61 -22
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +131 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/reach.ts +27 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-policy.ts +90 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +347 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +385 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +81 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +106 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-grant.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-owner.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-reaper.ts +174 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/attach-serve.ts +12 -13
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-api.ts +10 -27
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/files}/upload-store.ts +4 -4
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +233 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +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 +195 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-version.ts +44 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +136 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/effort.ts +93 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +237 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/frames.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +307 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-auth.ts +160 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-client.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-setup.ts +150 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-stream.ts +139 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gemini-translate.ts +224 -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 +278 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-lists.ts +57 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-signin.ts +202 -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 +106 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/pkce.ts +36 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/provider-models.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +18 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/subscription.ts +120 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/text.ts +14 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/tool-search.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/usage.ts +244 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/accounts.ts +28 -17
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/attachment-schema.ts +91 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/call-tools.ts +49 -20
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/ctx.ts +4 -4
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/event-store.ts +15 -16
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/group-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/index.ts +34 -80
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/instructions.ts +19 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/member-tools.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-prompt.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +88 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +82 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-snapshot.ts +79 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-lookup.ts +60 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/profile-tool.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/read-tool.ts +87 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +46 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-slot.ts +71 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/session.ts +47 -44
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +93 -0
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-def.ts +9 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-dispatch.ts +53 -40
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/tool-schemas.ts +64 -113
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/upload-tool.ts +6 -11
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +126 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +37 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/privilege.ts +48 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +132 -0
- package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +316 -0
- package/runtime/node_modules/@metro-labs/daemon/src/policy/policy.ts +118 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/bearer.ts +35 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/body.ts +24 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/routes}/http.ts +63 -51
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +206 -0
- package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +66 -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-browser.ts +102 -0
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-driver.ts +42 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-inline.ts +29 -1
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-interactive.ts +5 -31
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-resolve.ts +38 -13
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/attach-session.ts +32 -22
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach-xmtp.ts +8 -9
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/attach.ts +69 -3
- package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +267 -0
- package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/stations/registry.ts +20 -2
- package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor-io.ts +3 -3
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor.ts +6 -9
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +32 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/train-call.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +84 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +124 -0
- package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +15 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/api.ts +45 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/config.ts +51 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/firewall.ts +9 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/index.ts +96 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/install.ts +56 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/paths.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/proxy.ts +147 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/store.ts +129 -0
- package/runtime/node_modules/@metro-labs/daemon/src/vault/trust.ts +44 -0
- package/runtime/node_modules/@metro-labs/discord-bot/package.json +2 -4
- package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +3 -23
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +19 -187
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +26 -67
- package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +1 -1
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +8 -14
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +68 -0
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +12 -13
- package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/gmail/package.json +25 -0
- package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +81 -0
- package/runtime/node_modules/@metro-labs/gmail/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/gmail/src/api.ts +31 -0
- package/runtime/node_modules/@metro-labs/gmail/src/attachments.ts +35 -0
- package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +105 -0
- package/runtime/node_modules/@metro-labs/gmail/src/config.ts +13 -0
- package/runtime/node_modules/@metro-labs/gmail/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/gmail/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/gmail/src/login.ts +37 -0
- package/runtime/node_modules/@metro-labs/gmail/src/message.ts +125 -0
- package/runtime/node_modules/@metro-labs/gmail/src/mime.ts +70 -0
- package/runtime/node_modules/@metro-labs/gmail/src/outbound.ts +124 -0
- package/runtime/node_modules/@metro-labs/gmail/src/query.ts +99 -0
- package/runtime/node_modules/@metro-labs/gmail/src/state.ts +24 -0
- package/runtime/node_modules/@metro-labs/gmail/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/gmail/src/trust.ts +42 -0
- package/runtime/node_modules/@metro-labs/http/package.json +29 -0
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +135 -0
- package/runtime/node_modules/@metro-labs/{mcp/src/daemon/session-api.ts → http/src/mode-api.ts} +13 -9
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +21 -0
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +149 -0
- package/runtime/node_modules/@metro-labs/outlook/package.json +25 -0
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +78 -0
- package/runtime/node_modules/@metro-labs/outlook/src/actions.ts +14 -0
- package/runtime/node_modules/@metro-labs/outlook/src/attachments.ts +81 -0
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +120 -0
- package/runtime/node_modules/@metro-labs/outlook/src/browser.ts +42 -0
- package/runtime/node_modules/@metro-labs/outlook/src/config.ts +23 -0
- package/runtime/node_modules/@metro-labs/outlook/src/format.ts +59 -0
- package/runtime/node_modules/@metro-labs/outlook/src/graph.ts +55 -0
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +96 -0
- package/runtime/node_modules/@metro-labs/outlook/src/index.ts +12 -0
- package/runtime/node_modules/@metro-labs/outlook/src/login.ts +129 -0
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +31 -0
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +103 -0
- package/runtime/node_modules/@metro-labs/outlook/src/query.ts +84 -0
- package/runtime/node_modules/@metro-labs/outlook/src/state.ts +28 -0
- package/runtime/node_modules/@metro-labs/outlook/src/station.ts +15 -0
- package/runtime/node_modules/@metro-labs/outlook/src/trust.ts +41 -0
- package/runtime/node_modules/@metro-labs/telegram/package.json +1 -3
- package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +5 -24
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +8 -6
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/client.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram/src/format.ts +19 -34
- package/runtime/node_modules/@metro-labs/telegram/src/group.ts +3 -3
- package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +13 -34
- package/runtime/node_modules/@metro-labs/telegram/src/index.ts +4 -43
- package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +2 -3
- package/runtime/node_modules/@metro-labs/telegram/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +70 -0
- package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram/src/station.ts +4 -1
- package/runtime/node_modules/@metro-labs/telegram/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/package.json +1 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +7 -41
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +22 -77
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +46 -48
- package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +15 -15
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +6 -82
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +85 -0
- package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +5 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +20 -12
- package/runtime/node_modules/@metro-labs/threema/package.json +26 -0
- package/runtime/node_modules/@metro-labs/threema/src/accounts.ts +95 -0
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +124 -0
- package/runtime/node_modules/@metro-labs/threema/src/api.ts +152 -0
- package/runtime/node_modules/@metro-labs/threema/src/crypto.ts +100 -0
- package/runtime/node_modules/@metro-labs/threema/src/files.ts +47 -0
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +164 -0
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +96 -0
- package/runtime/node_modules/@metro-labs/threema/src/ids.ts +21 -0
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +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 +1 -1
- package/runtime/node_modules/@metro-labs/webhook/src/station.ts +5 -8
- package/runtime/node_modules/@metro-labs/whatsapp/package.json +2 -5
- package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +6 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +54 -11
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +86 -4
- package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +7 -58
- package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +11 -28
- package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +4 -37
- package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/names.ts +75 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +44 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/resolve.ts +52 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +16 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +5 -9
- package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +0 -1
- package/runtime/node_modules/@metro-labs/xmtp/package.json +3 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +10 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +15 -204
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +4 -43
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +43 -219
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +3 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +7 -24
- package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +8 -18
- package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +30 -16
- package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +12 -20
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +1 -19
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +61 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +153 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/resolve.ts +44 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +112 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/smart.ts +72 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +6 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +4 -51
- package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +30 -44
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +4 -6
- package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +19 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +14 -4
- package/runtime/runtime.json +1 -1
- package/runtime/server.ts +1 -0
- package/runtime/stations.json +38 -0
- package/dist/prompt.js +0 -10
- package/dist/store.js +0 -70
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +0 -195
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +0 -292
- package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +0 -197
- package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/mcp/package.json +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +0 -24
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +0 -311
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +0 -341
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +0 -129
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +0 -322
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +0 -111
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +0 -20
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +0 -202
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +0 -31
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +0 -100
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +0 -333
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-auth.ts +0 -164
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +0 -208
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +0 -79
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +0 -65
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +0 -58
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +0 -214
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +0 -125
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +0 -41
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +0 -169
- package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +0 -91
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +0 -215
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +0 -71
- package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +0 -37
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-collections.ts +0 -218
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +0 -329
- package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +0 -371
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +0 -300
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +0 -31
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +0 -105
- package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +0 -131
- package/runtime/node_modules/@metro-labs/mcp/src/db/token-carry.ts +0 -45
- package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +0 -57
- package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +0 -29
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +0 -21
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +0 -66
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +0 -73
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +0 -172
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +0 -43
- package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +0 -240
- package/runtime/node_modules/@metro-labs/mcp/src/server.ts +0 -2
- package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +0 -80
- package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +0 -88
- package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +0 -1
- package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +0 -3
- package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +0 -22
- package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +0 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +0 -87
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +0 -55
- package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +0 -349
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/log.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/mcp → core/src}/str.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → core/src}/train-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/channels/webhook-note.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp → daemon}/src/mcp/raw-get-stream.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/api-error.ts +0 -0
- /package/runtime/node_modules/@metro-labs/{mcp/src/daemon → http/src}/cors.ts +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { stringOf } from '@metro-labs/http/api-http';
|
|
2
3
|
import { rmSync } from 'node:fs';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { errMsg, log } from '
|
|
5
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
5
6
|
|
|
6
7
|
export class XmtpAttachError extends Error {}
|
|
7
8
|
|
|
@@ -43,8 +44,6 @@ interface VerifyReply {
|
|
|
43
44
|
error?: unknown;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const str = (value: unknown): string => (typeof value === 'string' ? value : '');
|
|
47
|
-
|
|
48
47
|
function readReply(raw: string): VerifyReply {
|
|
49
48
|
const line = raw.trim().split('\n').at(-1) ?? '';
|
|
50
49
|
try {
|
|
@@ -89,7 +88,7 @@ export async function verifyXmtpKeyOutOfProcess(
|
|
|
89
88
|
dbPath: string,
|
|
90
89
|
): Promise<XmtpIdentity> {
|
|
91
90
|
const raw = await runVerifier(
|
|
92
|
-
JSON.stringify({ privateKey, dbPath }),
|
|
91
|
+
JSON.stringify({ privateKey, dbPath, smart: true }),
|
|
93
92
|
).catch((err: unknown) => {
|
|
94
93
|
log.warn({ err: errMsg(err) }, 'attach-xmtp: could not run the inbox check');
|
|
95
94
|
throw new XmtpAttachError(UNREACHABLE);
|
|
@@ -97,13 +96,13 @@ export async function verifyXmtpKeyOutOfProcess(
|
|
|
97
96
|
const reply = readReply(raw);
|
|
98
97
|
if (reply.ok !== true)
|
|
99
98
|
throw new XmtpAttachError(
|
|
100
|
-
withoutKey(
|
|
99
|
+
withoutKey(stringOf(reply.error) || UNREACHABLE, privateKey),
|
|
101
100
|
);
|
|
102
101
|
const identity = {
|
|
103
|
-
inboxId:
|
|
104
|
-
address:
|
|
105
|
-
installationId:
|
|
106
|
-
dbPath:
|
|
102
|
+
inboxId: stringOf(reply.inboxId),
|
|
103
|
+
address: stringOf(reply.address),
|
|
104
|
+
installationId: stringOf(reply.installationId),
|
|
105
|
+
dbPath: stringOf(reply.dbPath),
|
|
107
106
|
};
|
|
108
107
|
if (identity.inboxId === '' || identity.address === '')
|
|
109
108
|
throw new XmtpAttachError(UNREACHABLE);
|
|
@@ -7,8 +7,15 @@ import {
|
|
|
7
7
|
TelegramTokenError,
|
|
8
8
|
verifyTelegramBotToken,
|
|
9
9
|
} from '@metro-labs/telegram-bot/verify';
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
parsePrivateKey,
|
|
12
|
+
ThreemaGatewayError,
|
|
13
|
+
verifyThreemaGateway,
|
|
14
|
+
} from '@metro-labs/threema/verify';
|
|
15
|
+
import { ApiError } from '@metro-labs/http/api-error';
|
|
16
|
+
import { bodyField } from '@metro-labs/http/api-http';
|
|
17
|
+
import { ensureStationDeps } from './runtime-deps.js';
|
|
18
|
+
import { publicBaseOrDefault } from '../files/attach-serve.js';
|
|
12
19
|
import {
|
|
13
20
|
discardXmtpDb,
|
|
14
21
|
newXmtpDbPath,
|
|
@@ -20,6 +27,7 @@ import {
|
|
|
20
27
|
export const ATTACHABLE_STATIONS = [
|
|
21
28
|
'discord-bot',
|
|
22
29
|
'telegram-bot',
|
|
30
|
+
'threema',
|
|
23
31
|
'xmtp',
|
|
24
32
|
'webhook',
|
|
25
33
|
] as const;
|
|
@@ -31,6 +39,9 @@ export class StationAttachError extends ApiError {}
|
|
|
31
39
|
export interface AttachInput {
|
|
32
40
|
station: AttachStation;
|
|
33
41
|
token?: unknown;
|
|
42
|
+
gatewayId?: unknown;
|
|
43
|
+
secret?: unknown;
|
|
44
|
+
privateKey?: unknown;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
export interface OneTimeSecret {
|
|
@@ -52,6 +63,16 @@ const SECP256K1_ORDER = BigInt(
|
|
|
52
63
|
'0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141',
|
|
53
64
|
);
|
|
54
65
|
|
|
66
|
+
export function attachInputOf(station: AttachStation, body: unknown): AttachInput {
|
|
67
|
+
return {
|
|
68
|
+
station,
|
|
69
|
+
token: bodyField(body, 'token'),
|
|
70
|
+
gatewayId: bodyField(body, 'gatewayId'),
|
|
71
|
+
secret: bodyField(body, 'secret'),
|
|
72
|
+
privateKey: bodyField(body, 'privateKey'),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
55
76
|
export function isAttachStation(raw: unknown): raw is AttachStation {
|
|
56
77
|
return (
|
|
57
78
|
typeof raw === 'string' &&
|
|
@@ -137,7 +158,7 @@ async function prepareXmtp(verify: VerifyXmtpKey): Promise<PreparedAccount> {
|
|
|
137
158
|
),
|
|
138
159
|
);
|
|
139
160
|
return {
|
|
140
|
-
config: { privateKey, dbPath },
|
|
161
|
+
config: { privateKey, dbPath, smart: true },
|
|
141
162
|
identity: { inboxId: identity.inboxId, address: identity.address },
|
|
142
163
|
secret: {
|
|
143
164
|
label: 'xmtp private key',
|
|
@@ -162,6 +183,49 @@ export function newWebhookId(): string {
|
|
|
162
183
|
return String(WEBHOOK_ID_FLOOR + (raw % (9n * WEBHOOK_ID_FLOOR)));
|
|
163
184
|
}
|
|
164
185
|
|
|
186
|
+
export const threemaCallbackUrl = (callbackId: string, token: string): string =>
|
|
187
|
+
`${publicBaseOrDefault().replace(/\/+$/, '')}/api/threema/${callbackId}/${token}`;
|
|
188
|
+
|
|
189
|
+
function requireText(raw: unknown, label: string): string {
|
|
190
|
+
const text = typeof raw === 'string' ? raw.trim() : '';
|
|
191
|
+
if (text === '')
|
|
192
|
+
throw new StationAttachError(`the Threema ${label} is required`, 400);
|
|
193
|
+
return text;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function prepareThreema(input: AttachInput): Promise<PreparedAccount> {
|
|
197
|
+
const gatewayId = requireText(input.gatewayId, 'Gateway ID');
|
|
198
|
+
const secret = requireText(input.secret, 'API secret');
|
|
199
|
+
const privateKey = requireText(input.privateKey, 'private key');
|
|
200
|
+
try {
|
|
201
|
+
const identity = await verifyThreemaGateway({ gatewayId, secret, privateKey });
|
|
202
|
+
const callbackId = newWebhookId();
|
|
203
|
+
const callbackToken = randomBytes(48).toString('base64url');
|
|
204
|
+
return {
|
|
205
|
+
config: {
|
|
206
|
+
gatewayId: identity.gatewayId,
|
|
207
|
+
secret,
|
|
208
|
+
privateKey: parsePrivateKey(privateKey) ?? privateKey,
|
|
209
|
+
callbackId,
|
|
210
|
+
callbackToken,
|
|
211
|
+
createdAt: new Date().toISOString(),
|
|
212
|
+
},
|
|
213
|
+
identity: {
|
|
214
|
+
gatewayId: identity.gatewayId,
|
|
215
|
+
credits: String(identity.credits),
|
|
216
|
+
callback: threemaCallbackUrl(callbackId, callbackToken),
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
} catch (err) {
|
|
220
|
+
if (err instanceof StationAttachError) throw err;
|
|
221
|
+
return rejected(
|
|
222
|
+
err,
|
|
223
|
+
err instanceof ThreemaGatewayError,
|
|
224
|
+
'Threema rejected those Gateway credentials',
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
165
229
|
function prepareWebhook(): PreparedAccount {
|
|
166
230
|
const secret = randomBytes(48).toString('base64url');
|
|
167
231
|
const webhookId = newWebhookId();
|
|
@@ -175,8 +239,10 @@ export async function prepareAccount(
|
|
|
175
239
|
input: AttachInput,
|
|
176
240
|
verify: VerifyXmtpKey = verifyXmtpKeyOutOfProcess,
|
|
177
241
|
): Promise<PreparedAccount> {
|
|
242
|
+
ensureStationDeps(input.station);
|
|
178
243
|
if (input.station === 'discord-bot') return prepareDiscord(input.token);
|
|
179
244
|
if (input.station === 'telegram-bot') return prepareTelegram(input.token);
|
|
180
245
|
if (input.station === 'webhook') return prepareWebhook();
|
|
246
|
+
if (input.station === 'threema') return prepareThreema(input);
|
|
181
247
|
return prepareXmtp(verify);
|
|
182
248
|
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { setPolicies, type PolicyTarget, type ToolPolicy } from '../policy/policy.js';
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { log } from '@metro-labs/core/log';
|
|
12
|
+
import { writeSecure } from '@metro-labs/core/secure-fs';
|
|
13
|
+
import { trainsDir } from '../boot/paths.js';
|
|
14
|
+
import {
|
|
15
|
+
setAgentMap,
|
|
16
|
+
setAllowlistMap,
|
|
17
|
+
setApproversMap,
|
|
18
|
+
setDisabledAccounts,
|
|
19
|
+
type AgentMap,
|
|
20
|
+
type AgentNameMap,
|
|
21
|
+
type AllowlistMap,
|
|
22
|
+
} from '../agents/map.js';
|
|
23
|
+
import { setKeyMap } from '../agents/keys.js';
|
|
24
|
+
import { STATIONS, type StationName } from '@metro-labs/core/station-names';
|
|
25
|
+
|
|
26
|
+
interface StationTarget {
|
|
27
|
+
file: string;
|
|
28
|
+
fileEnv: string;
|
|
29
|
+
trainImport: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LoadedAccount {
|
|
33
|
+
station: StationName;
|
|
34
|
+
id: string;
|
|
35
|
+
allowlist: string[] | null;
|
|
36
|
+
approvers?: string[];
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
policy?: ToolPolicy;
|
|
39
|
+
config: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface LoadedConnector {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
url: string;
|
|
46
|
+
config: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface LoadedAgent {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
accounts: LoadedAccount[];
|
|
53
|
+
key: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const METRO_DIR = join(homedir(), '.metro');
|
|
57
|
+
|
|
58
|
+
const STATION_TARGETS: Record<StationName, StationTarget> = {
|
|
59
|
+
xmtp: {
|
|
60
|
+
file: 'xmtp-accounts.json',
|
|
61
|
+
fileEnv: 'XMTP_ACCOUNTS_FILE',
|
|
62
|
+
trainImport: '@metro-labs/xmtp/train',
|
|
63
|
+
},
|
|
64
|
+
'telegram-bot': {
|
|
65
|
+
file: 'telegram-bot-accounts.json',
|
|
66
|
+
fileEnv: 'TELEGRAM_BOT_ACCOUNTS_FILE',
|
|
67
|
+
trainImport: '@metro-labs/telegram-bot/train',
|
|
68
|
+
},
|
|
69
|
+
'telegram': {
|
|
70
|
+
file: 'telegram-accounts.json',
|
|
71
|
+
fileEnv: 'TELEGRAM_ACCOUNTS_FILE',
|
|
72
|
+
trainImport: '@metro-labs/telegram/train',
|
|
73
|
+
},
|
|
74
|
+
'discord-bot': {
|
|
75
|
+
file: 'discord-bot-accounts.json',
|
|
76
|
+
fileEnv: 'DISCORD_BOT_ACCOUNTS_FILE',
|
|
77
|
+
trainImport: '@metro-labs/discord-bot/train',
|
|
78
|
+
},
|
|
79
|
+
whatsapp: {
|
|
80
|
+
file: 'whatsapp-accounts.json',
|
|
81
|
+
fileEnv: 'WHATSAPP_ACCOUNTS_FILE',
|
|
82
|
+
trainImport: '@metro-labs/whatsapp/train',
|
|
83
|
+
},
|
|
84
|
+
threema: {
|
|
85
|
+
file: 'threema-accounts.json',
|
|
86
|
+
fileEnv: 'THREEMA_ACCOUNTS_FILE',
|
|
87
|
+
trainImport: '@metro-labs/threema/train',
|
|
88
|
+
},
|
|
89
|
+
outlook: {
|
|
90
|
+
file: 'outlook-accounts.json',
|
|
91
|
+
fileEnv: 'OUTLOOK_ACCOUNTS_FILE',
|
|
92
|
+
trainImport: '@metro-labs/outlook/train',
|
|
93
|
+
},
|
|
94
|
+
gmail: {
|
|
95
|
+
file: 'gmail-accounts.json',
|
|
96
|
+
fileEnv: 'GMAIL_ACCOUNTS_FILE',
|
|
97
|
+
trainImport: '@metro-labs/gmail/train',
|
|
98
|
+
},
|
|
99
|
+
webhook: {
|
|
100
|
+
file: 'webhook-accounts.json',
|
|
101
|
+
fileEnv: 'WEBHOOK_ACCOUNTS_FILE',
|
|
102
|
+
trainImport: null,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function accountFilePath(station: StationName): string {
|
|
107
|
+
const target = STATION_TARGETS[station];
|
|
108
|
+
return process.env[target.fileEnv] ?? join(METRO_DIR, target.file);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type StationSource = () => Promise<LoadedAgent[]>;
|
|
112
|
+
|
|
113
|
+
export const MOVABLE_STATIONS = new Set<StationName>(
|
|
114
|
+
STATIONS.filter((s) => s !== 'webhook'),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
function trainStubPath(station: StationName): string {
|
|
118
|
+
return join(trainsDir(), `${station}.ts`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function currentText(path: string): string | null {
|
|
122
|
+
try {
|
|
123
|
+
return readFileSync(path, 'utf8');
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function writeIfChanged(path: string, content: string): boolean {
|
|
130
|
+
if (currentText(path) === content) return false;
|
|
131
|
+
writeFileSync(path, content);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface WrittenStations {
|
|
136
|
+
active: Map<StationName, number>;
|
|
137
|
+
changed: StationName[];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const channelPolicies = (list: LoadedAgent[]): [PolicyTarget, ToolPolicy][] =>
|
|
141
|
+
list.flatMap((agent) =>
|
|
142
|
+
agent.accounts.flatMap((a): [PolicyTarget, ToolPolicy][] =>
|
|
143
|
+
a.policy === undefined ? [] : [[{ kind: 'channel', station: a.station, account: a.id }, a.policy]],
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const approversOf = (list: LoadedAgent[]): Record<string, string[]> =>
|
|
148
|
+
Object.fromEntries(
|
|
149
|
+
list.flatMap((agent) => agent.accounts.flatMap((a) => (a.approvers === undefined ? [] : [[`${a.station}/${a.id}`, a.approvers]]))),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
function writeStations(list: LoadedAgent[]): WrittenStations {
|
|
153
|
+
mkdirSync(METRO_DIR, { recursive: true });
|
|
154
|
+
mkdirSync(trainsDir(), { recursive: true });
|
|
155
|
+
|
|
156
|
+
const byStation = new Map<StationName, LoadedAccount[]>();
|
|
157
|
+
const map: AgentMap = {};
|
|
158
|
+
const names: AgentNameMap = {};
|
|
159
|
+
const allow: AllowlistMap = {};
|
|
160
|
+
const disabled = new Set<string>();
|
|
161
|
+
for (const agent of list) {
|
|
162
|
+
names[agent.id] = agent.name;
|
|
163
|
+
for (const a of agent.accounts) {
|
|
164
|
+
if (!(a.station in STATION_TARGETS)) {
|
|
165
|
+
log.error(
|
|
166
|
+
{ station: a.station, id: a.id },
|
|
167
|
+
'unknown station — this metro is older or newer than the row; skipping it',
|
|
168
|
+
);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
map[`${a.station}/${a.id}`] = agent.id;
|
|
172
|
+
if (a.allowlist) allow[`${a.station}/${a.id}`] = a.allowlist;
|
|
173
|
+
if (a.enabled === false) disabled.add(`${a.station}/${a.id}`);
|
|
174
|
+
const cur = byStation.get(a.station);
|
|
175
|
+
if (cur) cur.push(a);
|
|
176
|
+
else byStation.set(a.station, [a]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
setAgentMap(map, names);
|
|
180
|
+
setAllowlistMap(allow);
|
|
181
|
+
setApproversMap(approversOf(list));
|
|
182
|
+
setDisabledAccounts(disabled);
|
|
183
|
+
setPolicies('channel', channelPolicies(list));
|
|
184
|
+
|
|
185
|
+
const active = new Map<StationName, number>();
|
|
186
|
+
const changed: StationName[] = [];
|
|
187
|
+
for (const [station, accts] of byStation) {
|
|
188
|
+
const records = accts.map((a) => ({ id: a.id, ...a.config }));
|
|
189
|
+
const path = accountFilePath(station);
|
|
190
|
+
const content = JSON.stringify(records, null, 2);
|
|
191
|
+
if (currentText(path) !== content) {
|
|
192
|
+
writeSecure(path, content);
|
|
193
|
+
changed.push(station);
|
|
194
|
+
}
|
|
195
|
+
const { trainImport } = STATION_TARGETS[station];
|
|
196
|
+
if (trainImport !== null)
|
|
197
|
+
writeIfChanged(trainStubPath(station), `import '${trainImport}';\n`);
|
|
198
|
+
active.set(station, accts.length);
|
|
199
|
+
}
|
|
200
|
+
return { active, changed };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const BLANKED = '[]\n';
|
|
204
|
+
|
|
205
|
+
function pruneStations(present: Map<StationName, number>): StationName[] {
|
|
206
|
+
const removed: StationName[] = [];
|
|
207
|
+
for (const station of Object.keys(STATION_TARGETS) as StationName[]) {
|
|
208
|
+
if (present.has(station)) continue;
|
|
209
|
+
const hasTrain = STATION_TARGETS[station].trainImport !== null;
|
|
210
|
+
const stub = trainStubPath(station);
|
|
211
|
+
const stubGone = !hasTrain || !existsSync(stub);
|
|
212
|
+
const file = currentText(accountFilePath(station));
|
|
213
|
+
const fileInert = file === null || file === BLANKED;
|
|
214
|
+
if (stubGone && fileInert) continue;
|
|
215
|
+
if (!fileInert) writeSecure(accountFilePath(station), BLANKED);
|
|
216
|
+
if (hasTrain) rmSync(stub, { force: true });
|
|
217
|
+
removed.push(station);
|
|
218
|
+
}
|
|
219
|
+
return removed;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const stationLabels = (m: Map<StationName, number>): string[] =>
|
|
223
|
+
[...m].map(([station, n]) => `${station}(${n})`);
|
|
224
|
+
|
|
225
|
+
function applyKeyMap(list: LoadedAgent[]): void {
|
|
226
|
+
setKeyMap(
|
|
227
|
+
list.flatMap((agent) =>
|
|
228
|
+
agent.key === null ? [] : [{ key: agent.key, agentId: agent.id }],
|
|
229
|
+
),
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function loadAndWrite(
|
|
234
|
+
source: StationSource,
|
|
235
|
+
): Promise<WrittenStations & { agents: number }> {
|
|
236
|
+
const list = await source();
|
|
237
|
+
applyKeyMap(list);
|
|
238
|
+
return { ...writeStations(list), agents: list.length };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export async function materializeFrom(source: StationSource): Promise<void> {
|
|
242
|
+
const { active, agents: found } = await loadAndWrite(source);
|
|
243
|
+
const removed = pruneStations(active);
|
|
244
|
+
log.info(
|
|
245
|
+
{ stations: stationLabels(active), agents: found, removed },
|
|
246
|
+
'materialized station accounts',
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface ReloadedStations {
|
|
251
|
+
active: StationName[];
|
|
252
|
+
removed: StationName[];
|
|
253
|
+
changed: StationName[];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export async function reloadFrom(
|
|
257
|
+
source: StationSource,
|
|
258
|
+
): Promise<ReloadedStations> {
|
|
259
|
+
const { active, changed } = await loadAndWrite(source);
|
|
260
|
+
const removed = pruneStations(active);
|
|
261
|
+
if (removed.length > 0 || changed.length > 0)
|
|
262
|
+
log.info(
|
|
263
|
+
{ stations: stationLabels(active), removed, changed },
|
|
264
|
+
'reloaded station accounts',
|
|
265
|
+
);
|
|
266
|
+
return { active: [...active.keys()], removed, changed };
|
|
267
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { Station } from '
|
|
2
|
-
import { Line } from '
|
|
1
|
+
import type { Station } from '@metro-labs/core/stations/types';
|
|
2
|
+
import { Line } from '@metro-labs/core/lines';
|
|
3
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
3
4
|
import { xmtpStation } from '@metro-labs/xmtp';
|
|
4
5
|
import { telegramBotStation } from '@metro-labs/telegram-bot';
|
|
5
6
|
import { telegramStation } from '@metro-labs/telegram';
|
|
6
7
|
import { discordBotStation } from '@metro-labs/discord-bot';
|
|
7
8
|
import { whatsappStation } from '@metro-labs/whatsapp';
|
|
9
|
+
import { threemaStation } from '@metro-labs/threema';
|
|
10
|
+
import { outlookStation } from '@metro-labs/outlook';
|
|
11
|
+
import { gmailStation } from '@metro-labs/gmail';
|
|
8
12
|
import { webhookStation } from '@metro-labs/webhook';
|
|
9
13
|
|
|
10
14
|
export const STATIONS: readonly Station[] = [
|
|
@@ -13,6 +17,9 @@ export const STATIONS: readonly Station[] = [
|
|
|
13
17
|
telegramStation,
|
|
14
18
|
discordBotStation,
|
|
15
19
|
whatsappStation,
|
|
20
|
+
threemaStation,
|
|
21
|
+
outlookStation,
|
|
22
|
+
gmailStation,
|
|
16
23
|
webhookStation,
|
|
17
24
|
];
|
|
18
25
|
|
|
@@ -33,3 +40,14 @@ export const accountStationCapabilities = (): Record<string, string[]> => {
|
|
|
33
40
|
if (s.hasAccounts) out[s.name] = [...s.messageVerbs].sort();
|
|
34
41
|
return out;
|
|
35
42
|
};
|
|
43
|
+
|
|
44
|
+
export function forgetOrphans(known: readonly { station: string; id: string }[]): void {
|
|
45
|
+
for (const s of STATIONS) {
|
|
46
|
+
if (s.forgetExcept === undefined) continue;
|
|
47
|
+
try {
|
|
48
|
+
s.forgetExcept(known.filter((a) => a.station === s.name).map((a) => a.id));
|
|
49
|
+
} catch (err) {
|
|
50
|
+
log.warn({ station: s.name, err: errMsg(err) }, 'stations: could not remove the files of detached accounts');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { log } from '@metro-labs/core/log';
|
|
5
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
6
|
+
import type { StationName } from '@metro-labs/core/station-names';
|
|
7
|
+
import { knownAccounts } from '../agents/map.js';
|
|
8
|
+
|
|
9
|
+
const INSTALL_TIMEOUT_MS = 15 * 60_000;
|
|
10
|
+
|
|
11
|
+
export interface RuntimeManifest {
|
|
12
|
+
core: Record<string, string>;
|
|
13
|
+
stations: Record<string, Record<string, string>>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RuntimeStore {
|
|
17
|
+
dir: string;
|
|
18
|
+
manifest: RuntimeManifest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ranges = (raw: unknown): Record<string, string> =>
|
|
22
|
+
isRecord(raw)
|
|
23
|
+
? Object.fromEntries(Object.entries(raw).filter((e): e is [string, string] => typeof e[1] === 'string'))
|
|
24
|
+
: {};
|
|
25
|
+
|
|
26
|
+
export function readManifest(path: string): RuntimeManifest {
|
|
27
|
+
const raw: unknown = JSON.parse(readFileSync(path, 'utf8'));
|
|
28
|
+
if (!isRecord(raw)) throw new Error(`${path} is not a runtime manifest`);
|
|
29
|
+
const stations = isRecord(raw.stations) ? raw.stations : {};
|
|
30
|
+
return {
|
|
31
|
+
core: ranges(raw.core),
|
|
32
|
+
stations: Object.fromEntries(Object.entries(stations).map(([name, deps]) => [name, ranges(deps)])),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function runtimeStore(): RuntimeStore | null {
|
|
37
|
+
const dir = process.env.METRO_RUNTIME_STORE?.trim() ?? '';
|
|
38
|
+
const manifest = process.env.METRO_RUNTIME_MANIFEST?.trim() ?? '';
|
|
39
|
+
if (dir === '' || manifest === '') return null;
|
|
40
|
+
return { dir, manifest: readManifest(manifest) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function dependenciesFor(manifest: RuntimeManifest, stations: Iterable<string>): Record<string, string> {
|
|
44
|
+
const out: Record<string, string> = { ...manifest.core };
|
|
45
|
+
for (const station of new Set(stations)) Object.assign(out, manifest.stations[station] ?? {});
|
|
46
|
+
return Object.fromEntries(Object.entries(out).sort(([a], [b]) => a.localeCompare(b)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const packageText = (deps: Record<string, string>): string =>
|
|
50
|
+
`${JSON.stringify({ name: 'metro-runtime', private: true, dependencies: deps }, null, 2)}\n`;
|
|
51
|
+
|
|
52
|
+
function current(dir: string): string | null {
|
|
53
|
+
try {
|
|
54
|
+
return readFileSync(join(dir, 'package.json'), 'utf8');
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function installRuntime(store: RuntimeStore, stations: Iterable<string>): boolean {
|
|
61
|
+
const wanted = packageText(dependenciesFor(store.manifest, stations));
|
|
62
|
+
const installed = existsSync(join(store.dir, 'node_modules', '.metro-installed'));
|
|
63
|
+
if (installed && current(store.dir) === wanted) return false;
|
|
64
|
+
mkdirSync(store.dir, { recursive: true });
|
|
65
|
+
writeFileSync(join(store.dir, 'package.json'), wanted);
|
|
66
|
+
log.info({ dir: store.dir }, 'runtime: installing the channel SDKs this machine needs');
|
|
67
|
+
const run = spawnSync('bun', ['install', '--no-summary', '--no-progress'], {
|
|
68
|
+
cwd: store.dir,
|
|
69
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
70
|
+
timeout: INSTALL_TIMEOUT_MS,
|
|
71
|
+
});
|
|
72
|
+
if (run.error !== undefined || run.status !== 0)
|
|
73
|
+
throw new Error(`bun install failed in ${store.dir}: ${run.error?.message ?? `exit ${String(run.status)}`}`);
|
|
74
|
+
writeFileSync(join(store.dir, 'node_modules', '.metro-installed'), `${new Date().toISOString()}\n`);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function ensureStationDeps(station: StationName): void {
|
|
79
|
+
const store = runtimeStore();
|
|
80
|
+
if (store === null) return;
|
|
81
|
+
installRuntime(store, [...knownAccounts().map((a) => a.station), station]);
|
|
82
|
+
}
|
package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor-io.ts
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { watch, type FSWatcher } from 'node:fs';
|
|
2
2
|
import { join, parse as parsePath } from 'node:path';
|
|
3
|
-
import { errMsg, log } from '
|
|
4
|
-
import type { Pending } from '
|
|
3
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
4
|
+
import type { Pending } from '@metro-labs/core/trains/protocol';
|
|
5
5
|
|
|
6
6
|
export const RESTART_BACKOFFS_MS = [1_000, 5_000, 30_000] as const;
|
|
7
7
|
export const MAX_CONSECUTIVE_FAILS = 5;
|
|
8
8
|
export const HOT_RELOAD_DEBOUNCE_MS = 300;
|
|
9
|
-
|
|
9
|
+
const TRAIN_EXT = /\.(ts|js|mjs)$/;
|
|
10
10
|
|
|
11
11
|
export interface TrainState {
|
|
12
12
|
name: string;
|
package/runtime/node_modules/@metro-labs/{mcp/src/daemon → daemon/src/stations}/supervisor.ts
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, statSync, type FSWatcher } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
2
|
import { join } from 'node:path';
|
|
4
|
-
import { errMsg, log } from '
|
|
5
|
-
import {
|
|
3
|
+
import { errMsg, log } from '@metro-labs/core/log';
|
|
4
|
+
import { userSelf } from '@metro-labs/core/events';
|
|
6
5
|
import {
|
|
7
6
|
drainLines,
|
|
8
7
|
failAllPending,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
sendCall,
|
|
13
12
|
type TrainCallResponse,
|
|
14
13
|
type TrainEvent,
|
|
15
|
-
} from '
|
|
14
|
+
} from '@metro-labs/core/trains/protocol';
|
|
16
15
|
import {
|
|
17
16
|
HOT_RELOAD_DEBOUNCE_MS,
|
|
18
17
|
MAX_CONSECUTIVE_FAILS,
|
|
@@ -22,9 +21,7 @@ import {
|
|
|
22
21
|
startWatcher,
|
|
23
22
|
type TrainState,
|
|
24
23
|
} from './supervisor-io.js';
|
|
25
|
-
|
|
26
|
-
export const TRAINS_DIR =
|
|
27
|
-
process.env.METRO_TRAINS_DIR ?? join(homedir(), '.metro', 'trains');
|
|
24
|
+
import { trainsDir } from '../boot/paths.js';
|
|
28
25
|
|
|
29
26
|
const DYLD_FALLBACK_ENV: Record<string, string> =
|
|
30
27
|
process.platform === 'darwin'
|
|
@@ -45,7 +42,7 @@ export class TrainSupervisor {
|
|
|
45
42
|
private watcher: FSWatcher | null = null;
|
|
46
43
|
private reloadTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
47
44
|
|
|
48
|
-
constructor(private dir: string =
|
|
45
|
+
constructor(private dir: string = trainsDir()) {}
|
|
49
46
|
|
|
50
47
|
running(): string[] {
|
|
51
48
|
return [...this.trains.keys()];
|
|
@@ -212,7 +209,7 @@ export class TrainSupervisor {
|
|
|
212
209
|
...process.env,
|
|
213
210
|
...DYLD_FALLBACK_ENV,
|
|
214
211
|
METRO_TRAIN_NAME: state.name,
|
|
215
|
-
METRO_SELF_URI:
|
|
212
|
+
METRO_SELF_URI: userSelf(),
|
|
216
213
|
},
|
|
217
214
|
});
|
|
218
215
|
state.proc = proc;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readJson } from '@metro-labs/core/secure-fs';
|
|
2
|
+
import { accountFilePath } from './materialize.js';
|
|
3
|
+
|
|
4
|
+
export interface ThreemaCallback {
|
|
5
|
+
id: string;
|
|
6
|
+
callbackId: string;
|
|
7
|
+
callbackToken: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const str = (v: unknown): string | undefined =>
|
|
11
|
+
typeof v === 'string' && v !== '' ? v : undefined;
|
|
12
|
+
|
|
13
|
+
function toCallback(row: unknown): ThreemaCallback | null {
|
|
14
|
+
if (typeof row !== 'object' || row === null) return null;
|
|
15
|
+
const rec = row as Record<string, unknown>;
|
|
16
|
+
const id = str(rec.id);
|
|
17
|
+
const callbackId = str(rec.callbackId);
|
|
18
|
+
const callbackToken = str(rec.callbackToken);
|
|
19
|
+
if (id === undefined || callbackId === undefined || callbackToken === undefined) return null;
|
|
20
|
+
return { id, callbackId, callbackToken };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function listThreemaCallbacks(): ThreemaCallback[] {
|
|
24
|
+
const raw = readJson<unknown[]>(accountFilePath('threema'), [], {
|
|
25
|
+
warn: 'threema-accounts.json: malformed, ignoring',
|
|
26
|
+
});
|
|
27
|
+
if (!Array.isArray(raw)) return [];
|
|
28
|
+
return raw.map(toCallback).filter((c): c is ThreemaCallback => c !== null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const findThreemaCallback = (callbackId: string): ThreemaCallback | undefined =>
|
|
32
|
+
listThreemaCallbacks().find((c) => c.callbackId === callbackId);
|