@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
|
@@ -5,50 +5,40 @@ const PREFIX = 'metro://';
|
|
|
5
5
|
const build = (station: string, ...seg: (string | number)[]): Line =>
|
|
6
6
|
asLine(`${PREFIX}${station}/${seg.map(String).join('/')}`);
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function parseAccountScoped(
|
|
9
9
|
line: Line | string,
|
|
10
10
|
station: string,
|
|
11
11
|
validate?: (resource: string) => boolean,
|
|
12
12
|
): { accountId: string; resource: string } | null {
|
|
13
13
|
const p = Line.parse(line);
|
|
14
|
-
if (p?.station !== station) return null;
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
accountId = p.path[0];
|
|
18
|
-
resource = p.path[1];
|
|
19
|
-
} else if (p.path.length === 1 && p.path[0] !== undefined) {
|
|
20
|
-
accountId = 'default';
|
|
21
|
-
resource = p.path[0];
|
|
22
|
-
} else return null;
|
|
14
|
+
if (p?.station !== station || p.path.length !== 2) return null;
|
|
15
|
+
const [accountId, resource] = p.path;
|
|
16
|
+
if (accountId === undefined || resource === undefined) return null;
|
|
23
17
|
if (validate && !validate(resource)) return null;
|
|
24
18
|
return { accountId, resource };
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
const isSnowflake = (s: string): boolean => /^\d+$/.test(s);
|
|
22
|
+
const isThreemaResource = (s: string): boolean =>
|
|
23
|
+
/^(?:[A-Z0-9]{8}|\*[A-Z0-9]{7})(?:-[0-9a-f]{16})?$/i.test(s);
|
|
24
|
+
const isMailResource = (s: string): boolean => /^[A-Za-z0-9=_%.@+-]+$/.test(s);
|
|
28
25
|
const isSignedInt = (s: string): boolean => /^-?\d+$/.test(s);
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return { accountId: 'default', rest: path };
|
|
35
|
-
}
|
|
27
|
+
const topicPart = (topicId: string | undefined): { topicId?: number } | null => {
|
|
28
|
+
if (topicId === undefined) return {};
|
|
29
|
+
return isSnowflake(topicId) ? { topicId: Number(topicId) } : null;
|
|
30
|
+
};
|
|
36
31
|
|
|
37
32
|
function parseTelegramLine(
|
|
38
33
|
line: Line | string,
|
|
39
34
|
): { accountId: string; chatId: number; topicId?: number } | null {
|
|
40
35
|
const p = Line.parse(line);
|
|
41
36
|
if (p?.station !== 'telegram-bot') return null;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
accountId,
|
|
49
|
-
chatId: Number(chatId),
|
|
50
|
-
...(topicId !== undefined ? { topicId: Number(topicId) } : {}),
|
|
51
|
-
};
|
|
37
|
+
const [accountId, chatId, topicId, ...extra] = p.path;
|
|
38
|
+
if (accountId === undefined || chatId === undefined || extra.length > 0) return null;
|
|
39
|
+
if (!isSignedInt(chatId)) return null;
|
|
40
|
+
const topic = topicPart(topicId);
|
|
41
|
+
return topic === null ? null : { accountId, chatId: Number(chatId), ...topic };
|
|
52
42
|
}
|
|
53
43
|
|
|
54
44
|
export const Line = {
|
|
@@ -79,4 +69,10 @@ export const Line = {
|
|
|
79
69
|
parseAccountScoped(line, 'discord-bot', isSnowflake),
|
|
80
70
|
|
|
81
71
|
parseTelegram: (line: Line | string) => parseTelegramLine(line),
|
|
72
|
+
|
|
73
|
+
parseThreema: (line: Line | string) =>
|
|
74
|
+
parseAccountScoped(line, 'threema', isThreemaResource),
|
|
75
|
+
|
|
76
|
+
parseMail: (line: Line | string, station: 'outlook' | 'gmail') =>
|
|
77
|
+
parseAccountScoped(line, station, isMailResource),
|
|
82
78
|
};
|
|
@@ -3,7 +3,7 @@ import { join, parse as parsePath } from 'node:path';
|
|
|
3
3
|
import { errMsg, log } from './log.js';
|
|
4
4
|
import { coerceErrorInfo, type TrainErrorInfo } from './train-error.js';
|
|
5
5
|
import type { StructuredEvent } from './events.js';
|
|
6
|
-
import type { CallMsg } from '
|
|
6
|
+
import type { CallMsg } from './stations/station-runtime.js';
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
TrainError,
|
|
@@ -11,7 +11,7 @@ export {
|
|
|
11
11
|
type TrainErrorInfo,
|
|
12
12
|
} from './train-error.js';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const CALL_TIMEOUT_MS = 60_000;
|
|
15
15
|
|
|
16
16
|
export interface Pending {
|
|
17
17
|
resolve: (r: TrainCallResponse) => void;
|
|
@@ -24,7 +24,7 @@ export interface CallTarget {
|
|
|
24
24
|
proc: ({ stdin?: unknown } & Record<string, unknown>) | null;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const STDOUT_LINE_MAX = 4 * 1024 * 1024;
|
|
28
28
|
|
|
29
29
|
export type TrainEvent = {
|
|
30
30
|
station?: string;
|
|
@@ -37,6 +37,9 @@ export type TrainEvent = {
|
|
|
37
37
|
message_id?: string;
|
|
38
38
|
reply_to?: string;
|
|
39
39
|
is_private?: boolean;
|
|
40
|
+
mentions_self?: boolean;
|
|
41
|
+
reply_to_self?: boolean;
|
|
42
|
+
sender_verified?: boolean;
|
|
40
43
|
text?: string;
|
|
41
44
|
emoji?: string;
|
|
42
45
|
payload?: unknown;
|
|
@@ -149,7 +152,7 @@ export function readCalls(
|
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
function encodeCall(id: string, action: string, args: unknown): string {
|
|
153
156
|
return JSON.stringify({ op: 'call', id, action, args }) + '\n';
|
|
154
157
|
}
|
|
155
158
|
|
|
@@ -38,6 +38,23 @@ export function writeSecure(path: string, data: string): void {
|
|
|
38
38
|
chmodIfExists(path, 0o600);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function modeOf(path: string): number | null {
|
|
42
|
+
try {
|
|
43
|
+
return statSync(path).mode & 0o777;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function writeAtomic(path: string, data: string, mode?: number): void {
|
|
50
|
+
const chosen = mode ?? modeOf(path) ?? 0o644;
|
|
51
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
52
|
+
const tmp = `${path}.metro-${String(process.pid)}.tmp`;
|
|
53
|
+
writeFileSync(tmp, data, { mode: chosen });
|
|
54
|
+
chmodSync(tmp, chosen);
|
|
55
|
+
renameSync(tmp, path);
|
|
56
|
+
}
|
|
57
|
+
|
|
41
58
|
export function readJson<T>(
|
|
42
59
|
path: string,
|
|
43
60
|
fallback: T,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readdirSync, rmSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { log } from '../log.js';
|
|
5
|
+
|
|
6
|
+
export interface AccountFiles {
|
|
7
|
+
path: (accountId: string) => string;
|
|
8
|
+
forget: (accountId: string) => void;
|
|
9
|
+
forgetExcept: (keptAccountIds: readonly string[]) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const safeSegment = (s: string): string => s.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
13
|
+
|
|
14
|
+
function listed(dir: string): string[] {
|
|
15
|
+
try {
|
|
16
|
+
return readdirSync(dir);
|
|
17
|
+
} catch {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function accountFiles(dirEnv: string, prefix: string): AccountFiles {
|
|
23
|
+
const dir = (): string => process.env[dirEnv] ?? join(homedir(), '.metro');
|
|
24
|
+
const name = (accountId: string): string => `${prefix}${safeSegment(accountId)}.json`;
|
|
25
|
+
const remove = (file: string, reason: string): void => {
|
|
26
|
+
rmSync(join(dir(), file), { force: true });
|
|
27
|
+
log.info({ file: join(dir(), file) }, reason);
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
path: (accountId) => join(dir(), name(accountId)),
|
|
31
|
+
forget: (accountId) => {
|
|
32
|
+
remove(name(accountId), 'station: removed the files of a detached account');
|
|
33
|
+
},
|
|
34
|
+
forgetExcept: (keptAccountIds) => {
|
|
35
|
+
const kept = new Set(keptAccountIds.map(name));
|
|
36
|
+
for (const file of listed(dir()))
|
|
37
|
+
if (file.startsWith(prefix) && file.endsWith('.json') && !kept.has(file))
|
|
38
|
+
remove(file, 'station: removed the files of an account that is no longer attached');
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { errMsg } from '../log.js';
|
|
5
|
+
import { chmodIfExists } from '../secure-fs.js';
|
|
6
|
+
|
|
7
|
+
export type Die = (msg: string) => never;
|
|
8
|
+
|
|
9
|
+
export interface AccountStoreOpts<T> {
|
|
10
|
+
prefix: string;
|
|
11
|
+
validate?: (raw: T[], die: Die) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Loader<T> {
|
|
15
|
+
die: Die;
|
|
16
|
+
loadAccounts: () => T[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const envName = (prefix: string): string =>
|
|
20
|
+
`${prefix.toUpperCase().replace(/-/g, '_')}_ACCOUNTS_FILE`;
|
|
21
|
+
|
|
22
|
+
const accountsFile = (prefix: string): string =>
|
|
23
|
+
process.env[envName(prefix)] ?? join(homedir(), '.metro', `${prefix}-accounts.json`);
|
|
24
|
+
|
|
25
|
+
function checkIds(raw: { id: string }[], die: Die): void {
|
|
26
|
+
const seen = new Set<string>();
|
|
27
|
+
for (const a of raw) {
|
|
28
|
+
if (!a.id) die('account missing id');
|
|
29
|
+
if (seen.has(a.id)) die(`duplicate account id '${a.id}'`);
|
|
30
|
+
seen.add(a.id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readList<T>(file: string, die: Die): T[] {
|
|
35
|
+
if (!existsSync(file))
|
|
36
|
+
return die(
|
|
37
|
+
`no accounts file ${file} — the daemon writes it from ~/.metro/agents/agent.json at boot; attach an account to this station from the page first`,
|
|
38
|
+
);
|
|
39
|
+
chmodIfExists(file);
|
|
40
|
+
let raw: unknown;
|
|
41
|
+
try {
|
|
42
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return die(`bad ${file}: ${errMsg(e)}`);
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
47
|
+
return die(`${file} must be a non-empty array`);
|
|
48
|
+
return raw as T[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function makeAccountStore<T extends { id: string }>(
|
|
52
|
+
opts: AccountStoreOpts<T>,
|
|
53
|
+
): Loader<T> {
|
|
54
|
+
const die: Die = (msg) => {
|
|
55
|
+
process.stderr.write(`${opts.prefix}: ${msg}\n`);
|
|
56
|
+
process.exit(2);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function loadAccounts(): T[] {
|
|
60
|
+
const raw = readList<T>(accountsFile(opts.prefix), die);
|
|
61
|
+
checkIds(raw, die);
|
|
62
|
+
opts.validate?.(raw, die);
|
|
63
|
+
return raw;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { die, loadAccounts };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function resolveAccountId(
|
|
70
|
+
accounts: Map<string, unknown>,
|
|
71
|
+
args: { account?: string; line?: string },
|
|
72
|
+
parseAccountId: (line: string) => string | undefined,
|
|
73
|
+
): string {
|
|
74
|
+
const have = [...accounts.keys()];
|
|
75
|
+
let id = args.account;
|
|
76
|
+
id ??= args.line ? parseAccountId(args.line) : undefined;
|
|
77
|
+
id ??= have.length === 1 ? have[0] : undefined;
|
|
78
|
+
if (id === undefined)
|
|
79
|
+
throw new Error(`name an account (have: ${have.join(', ')})`);
|
|
80
|
+
if (!accounts.has(id))
|
|
81
|
+
throw new Error(`unknown account '${id}' (have: ${have.join(', ')})`);
|
|
82
|
+
return id;
|
|
83
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const MAX_TEXT_CHARS = 20_000;
|
|
2
|
+
|
|
3
|
+
const ENTITIES: Record<string, string> = {
|
|
4
|
+
amp: '&',
|
|
5
|
+
lt: '<',
|
|
6
|
+
gt: '>',
|
|
7
|
+
quot: '"',
|
|
8
|
+
apos: "'",
|
|
9
|
+
nbsp: ' ',
|
|
10
|
+
ndash: '-',
|
|
11
|
+
mdash: '-',
|
|
12
|
+
hellip: '...',
|
|
13
|
+
rsquo: "'",
|
|
14
|
+
lsquo: "'",
|
|
15
|
+
rdquo: '"',
|
|
16
|
+
ldquo: '"',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function codePoint(n: number): string {
|
|
20
|
+
return Number.isInteger(n) && n > 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function decodeEntities(text: string): string {
|
|
24
|
+
return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, name: string) => {
|
|
25
|
+
if (name.startsWith('#x') || name.startsWith('#X')) return codePoint(parseInt(name.slice(2), 16));
|
|
26
|
+
if (name.startsWith('#')) return codePoint(Number(name.slice(1)));
|
|
27
|
+
return ENTITIES[name.toLowerCase()] ?? whole;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function htmlToText(html: string): string {
|
|
32
|
+
const text = html
|
|
33
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
34
|
+
.replace(/<(head|style|script|title)\b[\s\S]*?<\/\1\s*>/gi, '')
|
|
35
|
+
.replace(/<br\s*\/?>/gi, '\n')
|
|
36
|
+
.replace(/<li\b[^>]*>/gi, '\n- ')
|
|
37
|
+
.replace(/<\/(p|div|tr|h[1-6]|blockquote|table|ul|ol)\s*>/gi, '\n')
|
|
38
|
+
.replace(/<(p|div|tr|h[1-6]|blockquote|table)\b[^>]*>/gi, '\n')
|
|
39
|
+
.replace(/<\/t[dh]\s*>/gi, ' ')
|
|
40
|
+
.replace(/<[^>]*>/g, '');
|
|
41
|
+
return tidy(decodeEntities(text));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function tidy(text: string): string {
|
|
45
|
+
return text
|
|
46
|
+
.replace(/\r\n?/g, '\n')
|
|
47
|
+
.replace(/[ \t ]+/g, ' ')
|
|
48
|
+
.split('\n')
|
|
49
|
+
.map((l) => l.trim())
|
|
50
|
+
.join('\n')
|
|
51
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
52
|
+
.trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function capText(text: string, max = MAX_TEXT_CHARS): string {
|
|
56
|
+
if (text.length <= max) return text;
|
|
57
|
+
return `${text.slice(0, max)}\n[... ${String(text.length - max)} more characters]`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function bodyText(body: { contentType?: unknown; content?: unknown } | undefined): string {
|
|
61
|
+
const content = typeof body?.content === 'string' ? body.content : '';
|
|
62
|
+
return String(body?.contentType).toLowerCase() === 'html' ? htmlToText(content) : tidy(content);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function escapeHtml(text: string): string {
|
|
66
|
+
return text
|
|
67
|
+
.replace(/&/g, '&')
|
|
68
|
+
.replace(/</g, '<')
|
|
69
|
+
.replace(/>/g, '>')
|
|
70
|
+
.replace(/"/g, '"')
|
|
71
|
+
.replace(/\r?\n/g, '<br>');
|
|
72
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface MailHeader {
|
|
2
|
+
name?: string;
|
|
3
|
+
value?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type Screened = { skip: string } | { verified: boolean };
|
|
7
|
+
|
|
8
|
+
const AUTOMATED_LOCAL = /^(no-?reply|do-?not-?reply|donotreply|mailer-daemon|notifications?)([+._-].*)?$/i;
|
|
9
|
+
const BULK = new Set(['bulk', 'list', 'junk']);
|
|
10
|
+
|
|
11
|
+
export const headerValues = (headers: MailHeader[], name: string): string[] =>
|
|
12
|
+
headers.filter((h) => (h.name ?? '').toLowerCase() === name).map((h) => (h.value ?? '').trim());
|
|
13
|
+
|
|
14
|
+
export const firstHeader = (headers: MailHeader[], name: string): string | undefined => headerValues(headers, name)[0];
|
|
15
|
+
|
|
16
|
+
export function automatedBySender(address: string): string | null {
|
|
17
|
+
const local = address.split('@')[0] ?? '';
|
|
18
|
+
return AUTOMATED_LOCAL.test(local) ? `sender ${address}` : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function automatedByHeaders(headers: MailHeader[]): string | null {
|
|
22
|
+
if (firstHeader(headers, 'list-unsubscribe') !== undefined) return 'List-Unsubscribe';
|
|
23
|
+
const auto = firstHeader(headers, 'auto-submitted');
|
|
24
|
+
if (auto !== undefined && auto.toLowerCase() !== 'no') return `Auto-Submitted: ${auto}`;
|
|
25
|
+
const precedence = (firstHeader(headers, 'precedence') ?? '').toLowerCase();
|
|
26
|
+
return BULK.has(precedence) ? `Precedence: ${precedence}` : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const domainOf = (address: string): string => (address.split('@')[1] ?? '').toLowerCase();
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { mintId } from '../ids.js';
|
|
2
|
+
import { Line } from '../lines.js';
|
|
3
|
+
import { TrainError } from '../train-error.js';
|
|
4
|
+
import { capText } from './mail-text.js';
|
|
5
|
+
|
|
6
|
+
export type MailStation = 'outlook' | 'gmail';
|
|
7
|
+
|
|
8
|
+
type Args = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export interface MailItem {
|
|
11
|
+
id: string;
|
|
12
|
+
threadId: string;
|
|
13
|
+
subject: string;
|
|
14
|
+
from: string;
|
|
15
|
+
fromName: string;
|
|
16
|
+
to: string[];
|
|
17
|
+
cc: string[];
|
|
18
|
+
date: string | null;
|
|
19
|
+
preview: string;
|
|
20
|
+
text: string;
|
|
21
|
+
hasAttachments: boolean;
|
|
22
|
+
isRead: boolean;
|
|
23
|
+
internetMessageId: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AttachmentMeta {
|
|
27
|
+
kind: string;
|
|
28
|
+
name: string;
|
|
29
|
+
mime: string;
|
|
30
|
+
size?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface OutgoingFile {
|
|
34
|
+
path: string;
|
|
35
|
+
mime: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ReadQuery {
|
|
40
|
+
threadId: string | null;
|
|
41
|
+
query: string;
|
|
42
|
+
from: string;
|
|
43
|
+
since: string;
|
|
44
|
+
until: string;
|
|
45
|
+
before: string;
|
|
46
|
+
unreadOnly: boolean;
|
|
47
|
+
limit: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const DEFAULT_LIMIT = 20;
|
|
51
|
+
export const MAX_LIMIT = 50;
|
|
52
|
+
const SEEN_MAX = 500;
|
|
53
|
+
const SUBJECT_MAX = 255;
|
|
54
|
+
const ADDRESS_RE = /^[^@\s/]+@[^@\s/]+\.[^@\s/]+$/;
|
|
55
|
+
|
|
56
|
+
export interface MailService {
|
|
57
|
+
station: MailStation;
|
|
58
|
+
company: string;
|
|
59
|
+
product: string;
|
|
60
|
+
api: string;
|
|
61
|
+
apiCode: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function refusalOf(s: MailService, status: number, detail: string): TrainError {
|
|
65
|
+
const refuse = (code: string, text: string, retryable = false): TrainError => new TrainError(`${s.station}_${code}`, text, { retryable });
|
|
66
|
+
if (status === 401) return refuse('signed_out', `${s.company} refused this mailbox's sign-in (${detail}); connect ${s.product} again from the page`);
|
|
67
|
+
if (status === 403) return refuse('forbidden', `${s.company} does not let Metro do that on this mailbox (${detail})`);
|
|
68
|
+
if (status === 404) return refuse('not_found', `${s.product} has no such message or conversation (${detail})`);
|
|
69
|
+
if (status === 413) return refuse('too_large', `${s.product} refused the size of that request (${detail})`);
|
|
70
|
+
if (status === 429) return refuse('throttled', `${s.company} asked Metro to slow down (${detail}); try again in a minute`, true);
|
|
71
|
+
return refuse(s.apiCode, `${s.api} answered ${String(status)} (${detail})`, status >= 500);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const str = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');
|
|
75
|
+
|
|
76
|
+
const encodeResource = (id: string): string => id.replace(/%/g, '%25').replace(/\//g, '%2F').replace(/\+/g, '%2B');
|
|
77
|
+
|
|
78
|
+
export const mailLine = (station: MailStation, accountId: string, threadId: string): string =>
|
|
79
|
+
`metro://${station}/${accountId}/${encodeResource(threadId)}`;
|
|
80
|
+
|
|
81
|
+
const mailUser = (station: MailStation, accountId: string, address: string): string =>
|
|
82
|
+
`metro://${station}/${accountId}/user/${address.toLowerCase()}`;
|
|
83
|
+
|
|
84
|
+
export function threadOfLine(station: MailStation, line: string): { accountId: string; threadId: string } | null {
|
|
85
|
+
const parsed = Line.parseMail(line, station);
|
|
86
|
+
if (parsed === null) return null;
|
|
87
|
+
try {
|
|
88
|
+
return { accountId: parsed.accountId, threadId: decodeURIComponent(parsed.resource) };
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const isPrivateTo = (m: MailItem, self: string): boolean => m.to.length === 1 && m.to[0] === self && m.cc.length === 0;
|
|
95
|
+
|
|
96
|
+
export function mailEnvelope(station: MailStation, accountId: string, self: string, m: MailItem, attachments: AttachmentMeta[], verified: boolean): Record<string, unknown> {
|
|
97
|
+
const body = capText(m.text);
|
|
98
|
+
return {
|
|
99
|
+
id: mintId(),
|
|
100
|
+
ts: m.date ?? new Date().toISOString(),
|
|
101
|
+
station,
|
|
102
|
+
line: mailLine(station, accountId, m.threadId),
|
|
103
|
+
line_name: m.subject === '' ? '(no subject)' : m.subject,
|
|
104
|
+
from: mailUser(station, accountId, m.from === '' ? 'unknown' : m.from),
|
|
105
|
+
from_name: m.fromName || m.from,
|
|
106
|
+
from_display_name: m.fromName || undefined,
|
|
107
|
+
message_id: m.id,
|
|
108
|
+
text: m.subject === '' ? body : `Subject: ${m.subject}\n\n${body}`,
|
|
109
|
+
is_private: isPrivateTo(m, self),
|
|
110
|
+
sender_verified: verified,
|
|
111
|
+
payload: {
|
|
112
|
+
from: m.from,
|
|
113
|
+
to: m.to,
|
|
114
|
+
cc: m.cc,
|
|
115
|
+
subject: m.subject,
|
|
116
|
+
internetMessageId: m.internetMessageId,
|
|
117
|
+
...(attachments.length === 0 ? {} : { attachments }),
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const heading = (station: MailStation, accountId: string, m: MailItem): Record<string, unknown> => ({
|
|
123
|
+
message_id: m.id,
|
|
124
|
+
line: mailLine(station, accountId, m.threadId),
|
|
125
|
+
from: m.from,
|
|
126
|
+
from_name: m.fromName,
|
|
127
|
+
date: m.date,
|
|
128
|
+
title: m.subject,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const mailSummary = (station: MailStation, accountId: string, m: MailItem): Record<string, unknown> => ({
|
|
132
|
+
...heading(station, accountId, m),
|
|
133
|
+
text_preview: m.preview,
|
|
134
|
+
has_attachments: m.hasAttachments,
|
|
135
|
+
is_read: m.isRead,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const mailFull = (station: MailStation, accountId: string, m: MailItem): Record<string, unknown> => ({
|
|
139
|
+
...heading(station, accountId, m),
|
|
140
|
+
has_attachments: m.hasAttachments,
|
|
141
|
+
is_read: m.isRead,
|
|
142
|
+
to: m.to,
|
|
143
|
+
cc: m.cc,
|
|
144
|
+
text: capText(m.text),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
export const isAddress = (target: string): boolean => target.includes('@');
|
|
148
|
+
|
|
149
|
+
export const isEmailAddress = (value: string): boolean => ADDRESS_RE.test(value);
|
|
150
|
+
|
|
151
|
+
export function checkAddress(station: MailStation, to: string): void {
|
|
152
|
+
if (!isEmailAddress(to)) throw new TrainError(`${station}_bad_address`, `not an email address: ${to}`, { retryable: false });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function subjectOf(station: MailStation, subject: string, text: string): string {
|
|
156
|
+
const chosen = subject !== '' ? subject : (text.split('\n').find((l) => l.trim() !== '') ?? '').trim();
|
|
157
|
+
if (chosen === '') throw new TrainError(`${station}_subject_required`, 'a new email needs a subject or some text', { retryable: false });
|
|
158
|
+
return chosen.length > SUBJECT_MAX ? `${chosen.slice(0, SUBJECT_MAX - 3)}...` : chosen;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const filesOf = (raw: unknown): OutgoingFile[] =>
|
|
162
|
+
(Array.isArray(raw) ? raw : [])
|
|
163
|
+
.map((a) => (a ?? {}) as Record<string, unknown>)
|
|
164
|
+
.filter((a) => typeof a.path === 'string' && a.path !== '')
|
|
165
|
+
.map((a) => ({
|
|
166
|
+
path: String(a.path),
|
|
167
|
+
mime: typeof a.mime === 'string' && a.mime !== '' ? a.mime : 'application/octet-stream',
|
|
168
|
+
name: typeof a.name === 'string' && a.name !== '' ? a.name : 'file',
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
function isoOf(station: MailStation, raw: string, field: string): string {
|
|
172
|
+
if (raw === '') return '';
|
|
173
|
+
const at = Date.parse(raw);
|
|
174
|
+
if (Number.isNaN(at)) throw new TrainError(`${station}_bad_date`, `${field} must be a date, for example 2026-09-24 or 2026-09-24T10:00:00Z`, { retryable: false });
|
|
175
|
+
return new Date(at).toISOString();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function readQueryOf(station: MailStation, args: Args): ReadQuery {
|
|
179
|
+
const line = str(args.line);
|
|
180
|
+
const thread = line === '' ? null : threadOfLine(station, line);
|
|
181
|
+
if (line !== '' && thread === null) throw new TrainError(`${station}_bad_line`, `not a valid ${station} line: ${line}`, { retryable: false });
|
|
182
|
+
return {
|
|
183
|
+
threadId: thread?.threadId ?? null,
|
|
184
|
+
query: str(args.query),
|
|
185
|
+
from: str(args.from).toLowerCase(),
|
|
186
|
+
since: isoOf(station, str(args.since), 'since'),
|
|
187
|
+
until: isoOf(station, str(args.until), 'until'),
|
|
188
|
+
before: str(args.before),
|
|
189
|
+
unreadOnly: args.unreadOnly === true,
|
|
190
|
+
limit: typeof args.limit === 'number' && args.limit > 0 ? Math.min(Math.floor(args.limit), MAX_LIMIT) : DEFAULT_LIMIT,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const seenOf = (raw: unknown): string[] => (Array.isArray(raw) ? raw.filter((s): s is string => typeof s === 'string') : []);
|
|
195
|
+
|
|
196
|
+
export function noteSeen(seen: string[], messageId: string): void {
|
|
197
|
+
seen.push(messageId);
|
|
198
|
+
if (seen.length > SEEN_MAX) seen.splice(0, seen.length - SEEN_MAX);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function pollForever(tag: string, once: () => Promise<unknown>, intervalMs: number): void {
|
|
202
|
+
const tick = (): void => {
|
|
203
|
+
once()
|
|
204
|
+
.catch((err: unknown) => {
|
|
205
|
+
process.stderr.write(`${tag} mail check failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
206
|
+
})
|
|
207
|
+
.finally(() => {
|
|
208
|
+
setTimeout(tick, intervalMs);
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
tick();
|
|
212
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Args = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
export interface Normalized {
|
|
4
|
+
action: string;
|
|
5
|
+
args: Args;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type Normalize = (action: string, args: Args) => Normalized;
|
|
9
|
+
|
|
10
|
+
export const messagingAliases =
|
|
11
|
+
(removal: Args = { emoji: '' }): Normalize =>
|
|
12
|
+
(action, args) => {
|
|
13
|
+
if (action === 'reply') return { action: 'send', args };
|
|
14
|
+
if (action === 'unreact') return { action: 'react', args: { ...args, ...removal } };
|
|
15
|
+
return { action, args };
|
|
16
|
+
};
|