@stage-labs/metro 0.1.0-beta.7 → 0.1.0-beta.71

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.
Files changed (279) hide show
  1. package/dist/api.js +14 -0
  2. package/dist/bedrock-eventstream.js +120 -0
  3. package/dist/bedrock-proxy.js +260 -0
  4. package/dist/bedrock-upstream.js +72 -0
  5. package/dist/bedrock.js +37 -0
  6. package/dist/claude-settings.js +40 -0
  7. package/dist/claude.js +107 -0
  8. package/dist/cli.js +101 -0
  9. package/dist/control.js +74 -0
  10. package/dist/hold.js +211 -0
  11. package/dist/local.js +93 -0
  12. package/dist/node-name.js +51 -0
  13. package/dist/plugin.js +80 -0
  14. package/dist/provider-flags.js +9 -0
  15. package/dist/runtime-install.js +84 -0
  16. package/dist/runtime.js +70 -0
  17. package/dist/serve.js +147 -0
  18. package/dist/service.js +224 -0
  19. package/dist/tail.js +119 -0
  20. package/dist/update.js +45 -0
  21. package/dist/version.js +97 -0
  22. package/package.json +14 -25
  23. package/runtime/node_modules/@metro-labs/discord-bot/package.json +28 -0
  24. package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +118 -0
  25. package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +388 -0
  26. package/runtime/node_modules/@metro-labs/discord-bot/src/api-base.ts +1 -0
  27. package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +29 -0
  28. package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +220 -0
  29. package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +50 -0
  30. package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +115 -0
  31. package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +127 -0
  32. package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +215 -0
  33. package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +43 -0
  34. package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +19 -0
  35. package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +82 -0
  36. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +195 -0
  37. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +292 -0
  38. package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +197 -0
  39. package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +5 -0
  40. package/runtime/node_modules/@metro-labs/mcp/package.json +64 -0
  41. package/runtime/node_modules/@metro-labs/mcp/src/channels/addressed.ts +25 -0
  42. package/runtime/node_modules/@metro-labs/mcp/src/channels/dedupe.ts +24 -0
  43. package/runtime/node_modules/@metro-labs/mcp/src/channels/inbound.ts +377 -0
  44. package/runtime/node_modules/@metro-labs/mcp/src/channels/media-note.ts +85 -0
  45. package/runtime/node_modules/@metro-labs/mcp/src/channels/pending.ts +75 -0
  46. package/runtime/node_modules/@metro-labs/mcp/src/channels/relay.ts +129 -0
  47. package/runtime/node_modules/@metro-labs/mcp/src/channels/webhook-note.ts +51 -0
  48. package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +311 -0
  49. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +302 -0
  50. package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-error.ts +8 -0
  51. package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +95 -0
  52. package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-grant.ts +99 -0
  53. package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-owner.ts +32 -0
  54. package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-serve.ts +128 -0
  55. package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-session.ts +280 -0
  56. package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +204 -0
  57. package/runtime/node_modules/@metro-labs/mcp/src/daemon/bundle-api.ts +111 -0
  58. package/runtime/node_modules/@metro-labs/mcp/src/daemon/claude-api.ts +97 -0
  59. package/runtime/node_modules/@metro-labs/mcp/src/daemon/claude-files.ts +329 -0
  60. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connect-hint.ts +39 -0
  61. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-api.ts +307 -0
  62. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-json.ts +21 -0
  63. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth-routes.ts +157 -0
  64. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth.ts +127 -0
  65. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-tools.ts +98 -0
  66. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-url.ts +70 -0
  67. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-verify.ts +330 -0
  68. package/runtime/node_modules/@metro-labs/mcp/src/daemon/control-api.ts +64 -0
  69. package/runtime/node_modules/@metro-labs/mcp/src/daemon/cors.ts +29 -0
  70. package/runtime/node_modules/@metro-labs/mcp/src/daemon/crash-guard.ts +49 -0
  71. package/runtime/node_modules/@metro-labs/mcp/src/daemon/events.ts +120 -0
  72. package/runtime/node_modules/@metro-labs/mcp/src/daemon/http.ts +390 -0
  73. package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity-key.ts +33 -0
  74. package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity-registry.ts +13 -0
  75. package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity-routes.ts +54 -0
  76. package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +7 -0
  77. package/runtime/node_modules/@metro-labs/mcp/src/daemon/is-record.ts +2 -0
  78. package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-cli-api.ts +63 -0
  79. package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-mode.ts +187 -0
  80. package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-owner.ts +14 -0
  81. package/runtime/node_modules/@metro-labs/mcp/src/daemon/log.ts +42 -0
  82. package/runtime/node_modules/@metro-labs/mcp/src/daemon/machine-api.ts +61 -0
  83. package/runtime/node_modules/@metro-labs/mcp/src/daemon/mode-api.ts +32 -0
  84. package/runtime/node_modules/@metro-labs/mcp/src/daemon/model-api.ts +169 -0
  85. package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-client.ts +159 -0
  86. package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-discovery.ts +117 -0
  87. package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +65 -0
  88. package/runtime/node_modules/@metro-labs/mcp/src/daemon/paths.ts +109 -0
  89. package/runtime/node_modules/@metro-labs/mcp/src/daemon/protocol.ts +226 -0
  90. package/runtime/node_modules/@metro-labs/mcp/src/daemon/relay.ts +295 -0
  91. package/runtime/node_modules/@metro-labs/mcp/src/daemon/return-to.ts +21 -0
  92. package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-deps.ts +82 -0
  93. package/runtime/node_modules/@metro-labs/mcp/src/daemon/secure-fs.ts +57 -0
  94. package/runtime/node_modules/@metro-labs/mcp/src/daemon/server-types.ts +21 -0
  95. package/runtime/node_modules/@metro-labs/mcp/src/daemon/servers-api.ts +80 -0
  96. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-api.ts +29 -0
  97. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +66 -0
  98. package/runtime/node_modules/@metro-labs/mcp/src/daemon/signed-identity.ts +36 -0
  99. package/runtime/node_modules/@metro-labs/mcp/src/daemon/supervisor-io.ts +97 -0
  100. package/runtime/node_modules/@metro-labs/mcp/src/daemon/supervisor.ts +320 -0
  101. package/runtime/node_modules/@metro-labs/mcp/src/daemon/terminal-api.ts +71 -0
  102. package/runtime/node_modules/@metro-labs/mcp/src/daemon/terminal-tickets.ts +40 -0
  103. package/runtime/node_modules/@metro-labs/mcp/src/daemon/terminal-ws.ts +114 -0
  104. package/runtime/node_modules/@metro-labs/mcp/src/daemon/train-call.ts +22 -0
  105. package/runtime/node_modules/@metro-labs/mcp/src/daemon/train-error.ts +53 -0
  106. package/runtime/node_modules/@metro-labs/mcp/src/daemon/tunnel.ts +352 -0
  107. package/runtime/node_modules/@metro-labs/mcp/src/daemon/update-api.ts +116 -0
  108. package/runtime/node_modules/@metro-labs/mcp/src/daemon/upload-api.ts +294 -0
  109. package/runtime/node_modules/@metro-labs/mcp/src/daemon/upload-store.ts +181 -0
  110. package/runtime/node_modules/@metro-labs/mcp/src/daemon/vault-api.ts +78 -0
  111. package/runtime/node_modules/@metro-labs/mcp/src/daemon/vault-types.ts +12 -0
  112. package/runtime/node_modules/@metro-labs/mcp/src/daemon/version.ts +2 -0
  113. package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +19 -0
  114. package/runtime/node_modules/@metro-labs/mcp/src/db/address.ts +6 -0
  115. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +43 -0
  116. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-map.ts +84 -0
  117. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-scope.ts +64 -0
  118. package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +32 -0
  119. package/runtime/node_modules/@metro-labs/mcp/src/db/connector-config.ts +144 -0
  120. package/runtime/node_modules/@metro-labs/mcp/src/db/connector-relay.ts +39 -0
  121. package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +69 -0
  122. package/runtime/node_modules/@metro-labs/mcp/src/db/file-admin.ts +329 -0
  123. package/runtime/node_modules/@metro-labs/mcp/src/db/file-source.ts +155 -0
  124. package/runtime/node_modules/@metro-labs/mcp/src/db/ids.ts +21 -0
  125. package/runtime/node_modules/@metro-labs/mcp/src/db/key-map.ts +45 -0
  126. package/runtime/node_modules/@metro-labs/mcp/src/db/local-connectors.ts +277 -0
  127. package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +253 -0
  128. package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +33 -0
  129. package/runtime/node_modules/@metro-labs/mcp/src/db/servers.ts +83 -0
  130. package/runtime/node_modules/@metro-labs/mcp/src/db/stations.ts +12 -0
  131. package/runtime/node_modules/@metro-labs/mcp/src/db/vault.ts +109 -0
  132. package/runtime/node_modules/@metro-labs/mcp/src/gateway/bedrock.ts +252 -0
  133. package/runtime/node_modules/@metro-labs/mcp/src/gateway/codex-auth.ts +231 -0
  134. package/runtime/node_modules/@metro-labs/mcp/src/gateway/codex-device.ts +91 -0
  135. package/runtime/node_modules/@metro-labs/mcp/src/gateway/codex-stream.ts +288 -0
  136. package/runtime/node_modules/@metro-labs/mcp/src/gateway/codex-translate.ts +203 -0
  137. package/runtime/node_modules/@metro-labs/mcp/src/gateway/codex.ts +211 -0
  138. package/runtime/node_modules/@metro-labs/mcp/src/gateway/eventstream.ts +123 -0
  139. package/runtime/node_modules/@metro-labs/mcp/src/gateway/forward.ts +169 -0
  140. package/runtime/node_modules/@metro-labs/mcp/src/gateway/gateway.ts +193 -0
  141. package/runtime/node_modules/@metro-labs/mcp/src/gateway/model-config.ts +180 -0
  142. package/runtime/node_modules/@metro-labs/mcp/src/mcp/accounts.ts +141 -0
  143. package/runtime/node_modules/@metro-labs/mcp/src/mcp/call-tools.ts +216 -0
  144. package/runtime/node_modules/@metro-labs/mcp/src/mcp/channel-owner.ts +29 -0
  145. package/runtime/node_modules/@metro-labs/mcp/src/mcp/ctx.ts +62 -0
  146. package/runtime/node_modules/@metro-labs/mcp/src/mcp/event-store.ts +91 -0
  147. package/runtime/node_modules/@metro-labs/mcp/src/mcp/frame-scope.ts +21 -0
  148. package/runtime/node_modules/@metro-labs/mcp/src/mcp/group-tools.ts +129 -0
  149. package/runtime/node_modules/@metro-labs/mcp/src/mcp/index.ts +191 -0
  150. package/runtime/node_modules/@metro-labs/mcp/src/mcp/member-tools.ts +72 -0
  151. package/runtime/node_modules/@metro-labs/mcp/src/mcp/permission-relay.ts +66 -0
  152. package/runtime/node_modules/@metro-labs/mcp/src/mcp/raw-get-stream.ts +207 -0
  153. package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +47 -0
  154. package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-registry.ts +172 -0
  155. package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +43 -0
  156. package/runtime/node_modules/@metro-labs/mcp/src/mcp/session.ts +215 -0
  157. package/runtime/node_modules/@metro-labs/mcp/src/mcp/str.ts +5 -0
  158. package/runtime/node_modules/@metro-labs/mcp/src/mcp/tool-dispatch.ts +215 -0
  159. package/runtime/node_modules/@metro-labs/mcp/src/mcp/tool-schemas.ts +400 -0
  160. package/runtime/node_modules/@metro-labs/mcp/src/mcp/upload-tool.ts +66 -0
  161. package/runtime/node_modules/@metro-labs/mcp/src/monitor/api.ts +237 -0
  162. package/runtime/node_modules/@metro-labs/mcp/src/server.ts +2 -0
  163. package/runtime/node_modules/@metro-labs/mcp/src/stations/account-store.ts +60 -0
  164. package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-inline.ts +100 -0
  165. package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-interactive.ts +161 -0
  166. package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-resolve.ts +200 -0
  167. package/runtime/node_modules/@metro-labs/mcp/src/stations/attach-xmtp.ts +111 -0
  168. package/runtime/node_modules/@metro-labs/mcp/src/stations/attach.ts +184 -0
  169. package/runtime/node_modules/@metro-labs/mcp/src/stations/attachments.ts +196 -0
  170. package/runtime/node_modules/@metro-labs/mcp/src/stations/lines.ts +82 -0
  171. package/runtime/node_modules/@metro-labs/mcp/src/stations/messaging-normalize.ts +88 -0
  172. package/runtime/node_modules/@metro-labs/mcp/src/stations/registry.ts +35 -0
  173. package/runtime/node_modules/@metro-labs/mcp/src/stations/station-runtime.ts +64 -0
  174. package/runtime/node_modules/@metro-labs/mcp/src/stations/types.ts +107 -0
  175. package/runtime/node_modules/@metro-labs/telegram/package.json +26 -0
  176. package/runtime/node_modules/@metro-labs/telegram/src/accounts.ts +80 -0
  177. package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +254 -0
  178. package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +87 -0
  179. package/runtime/node_modules/@metro-labs/telegram/src/client.ts +77 -0
  180. package/runtime/node_modules/@metro-labs/telegram/src/format.ts +156 -0
  181. package/runtime/node_modules/@metro-labs/telegram/src/group.ts +261 -0
  182. package/runtime/node_modules/@metro-labs/telegram/src/history.ts +52 -0
  183. package/runtime/node_modules/@metro-labs/telegram/src/inbound.ts +78 -0
  184. package/runtime/node_modules/@metro-labs/telegram/src/index.ts +46 -0
  185. package/runtime/node_modules/@metro-labs/telegram/src/login.ts +166 -0
  186. package/runtime/node_modules/@metro-labs/telegram/src/media-actions.ts +80 -0
  187. package/runtime/node_modules/@metro-labs/telegram/src/members.ts +75 -0
  188. package/runtime/node_modules/@metro-labs/telegram/src/normalize.ts +22 -0
  189. package/runtime/node_modules/@metro-labs/telegram/src/reactions.ts +167 -0
  190. package/runtime/node_modules/@metro-labs/telegram/src/station.ts +24 -0
  191. package/runtime/node_modules/@metro-labs/telegram/src/types.ts +7 -0
  192. package/runtime/node_modules/@metro-labs/telegram/src/wire.ts +1 -0
  193. package/runtime/node_modules/@metro-labs/telegram-bot/package.json +25 -0
  194. package/runtime/node_modules/@metro-labs/telegram-bot/src/accounts.ts +120 -0
  195. package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +295 -0
  196. package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +128 -0
  197. package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +201 -0
  198. package/runtime/node_modules/@metro-labs/telegram-bot/src/index.ts +109 -0
  199. package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +166 -0
  200. package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +47 -0
  201. package/runtime/node_modules/@metro-labs/telegram-bot/src/station.ts +17 -0
  202. package/runtime/node_modules/@metro-labs/telegram-bot/src/types.ts +58 -0
  203. package/runtime/node_modules/@metro-labs/telegram-bot/src/verify.ts +38 -0
  204. package/runtime/node_modules/@metro-labs/telegram-bot/src/wire.ts +3 -0
  205. package/runtime/node_modules/@metro-labs/webhook/package.json +23 -0
  206. package/runtime/node_modules/@metro-labs/webhook/src/station.ts +37 -0
  207. package/runtime/node_modules/@metro-labs/whatsapp/package.json +27 -0
  208. package/runtime/node_modules/@metro-labs/whatsapp/src/accounts.ts +66 -0
  209. package/runtime/node_modules/@metro-labs/whatsapp/src/ack.ts +101 -0
  210. package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +178 -0
  211. package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +72 -0
  212. package/runtime/node_modules/@metro-labs/whatsapp/src/auth-state.ts +129 -0
  213. package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +327 -0
  214. package/runtime/node_modules/@metro-labs/whatsapp/src/delivery.ts +49 -0
  215. package/runtime/node_modules/@metro-labs/whatsapp/src/format.ts +138 -0
  216. package/runtime/node_modules/@metro-labs/whatsapp/src/inbound.ts +57 -0
  217. package/runtime/node_modules/@metro-labs/whatsapp/src/index.ts +40 -0
  218. package/runtime/node_modules/@metro-labs/whatsapp/src/keys.ts +59 -0
  219. package/runtime/node_modules/@metro-labs/whatsapp/src/logger.ts +60 -0
  220. package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +176 -0
  221. package/runtime/node_modules/@metro-labs/whatsapp/src/media.ts +84 -0
  222. package/runtime/node_modules/@metro-labs/whatsapp/src/normalize.ts +22 -0
  223. package/runtime/node_modules/@metro-labs/whatsapp/src/outbox.ts +38 -0
  224. package/runtime/node_modules/@metro-labs/whatsapp/src/parse.ts +185 -0
  225. package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +17 -0
  226. package/runtime/node_modules/@metro-labs/whatsapp/src/token-store.ts +98 -0
  227. package/runtime/node_modules/@metro-labs/whatsapp/src/types.ts +6 -0
  228. package/runtime/node_modules/@metro-labs/whatsapp/src/wire.ts +5 -0
  229. package/runtime/node_modules/@metro-labs/xmtp/package.json +33 -0
  230. package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +112 -0
  231. package/runtime/node_modules/@metro-labs/xmtp/src/actions-close.ts +110 -0
  232. package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +299 -0
  233. package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +157 -0
  234. package/runtime/node_modules/@metro-labs/xmtp/src/actions-push.ts +87 -0
  235. package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +375 -0
  236. package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +107 -0
  237. package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +171 -0
  238. package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +239 -0
  239. package/runtime/node_modules/@metro-labs/xmtp/src/emit-core.ts +55 -0
  240. package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +335 -0
  241. package/runtime/node_modules/@metro-labs/xmtp/src/emit.ts +80 -0
  242. package/runtime/node_modules/@metro-labs/xmtp/src/group-members.ts +34 -0
  243. package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +56 -0
  244. package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +33 -0
  245. package/runtime/node_modules/@metro-labs/xmtp/src/index.ts +125 -0
  246. package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +157 -0
  247. package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +40 -0
  248. package/runtime/node_modules/@metro-labs/xmtp/src/push.ts +349 -0
  249. package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +13 -0
  250. package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +126 -0
  251. package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +212 -0
  252. package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +90 -0
  253. package/runtime/node_modules/@metro-labs/xmtp/src/verify.ts +84 -0
  254. package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +53 -0
  255. package/runtime/runtime.json +3 -0
  256. package/runtime/stations.json +36 -0
  257. package/runtime/trains/.keep +0 -0
  258. package/LICENSE +0 -21
  259. package/README.md +0 -193
  260. package/dist/cache.js +0 -75
  261. package/dist/cli/actions.js +0 -139
  262. package/dist/cli/config.js +0 -185
  263. package/dist/cli/index.js +0 -159
  264. package/dist/cli/skill.js +0 -62
  265. package/dist/cli/util.js +0 -72
  266. package/dist/codex-rc.js +0 -236
  267. package/dist/dispatcher.js +0 -95
  268. package/dist/history.js +0 -84
  269. package/dist/ipc.js +0 -72
  270. package/dist/log.js +0 -15
  271. package/dist/paths.js +0 -68
  272. package/dist/stations/discord.js +0 -200
  273. package/dist/stations/index.js +0 -73
  274. package/dist/stations/telegram-md.js +0 -34
  275. package/dist/stations/telegram-upload.js +0 -113
  276. package/dist/stations/telegram.js +0 -213
  277. package/docs/agents.md +0 -185
  278. package/docs/uri-scheme.md +0 -71
  279. package/skills/metro/SKILL.md +0 -241
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@metro-labs/mcp",
3
+ "version": "0.1.0-beta.15",
4
+ "private": true,
5
+ "description": "Event-interception wire. Supervises train subprocesses in ~/.metro/trains/, multiplexes their JSON event stream onto stdout, and routes outbound action calls back via stdin. Per-platform code is written by the agent (or user) as train scripts — metro core is pure transport.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bonustrack/metro.git"
10
+ },
11
+ "homepage": "https://github.com/bonustrack/metro#readme",
12
+ "bugs": "https://github.com/bonustrack/metro/issues",
13
+ "type": "module",
14
+ "engines": {
15
+ "node": ">=22"
16
+ },
17
+ "exports": {
18
+ ".": "./src/mcp/index.ts",
19
+ "./log": "./src/daemon/log.ts",
20
+ "./train-error": "./src/daemon/train-error.ts",
21
+ "./secure-fs": "./src/daemon/secure-fs.ts",
22
+ "./lines": "./src/stations/lines.ts",
23
+ "./events": "./src/daemon/events.ts",
24
+ "./endpoints": "./src/daemon/tunnel.ts",
25
+ "./trains/protocol": "./src/daemon/protocol.ts",
26
+ "./stations/types": "./src/stations/types.ts",
27
+ "./stations/station-runtime": "./src/stations/station-runtime.ts",
28
+ "./stations/account-store": "./src/stations/account-store.ts",
29
+ "./stations/attachments": "./src/stations/attachments.ts",
30
+ "./stations/messaging-normalize": "./src/stations/messaging-normalize.ts"
31
+ },
32
+ "scripts": {
33
+ "start": "bun src/server.ts",
34
+ "build": "tsc",
35
+ "db:migrate": "drizzle-kit migrate",
36
+ "test": "tsc --noEmit && DYLD_FALLBACK_LIBRARY_PATH=/usr/lib METRO_STATE_DIR=\"$(mktemp -d /tmp/metro-test.XXXXXX)\" bun test test/"
37
+ },
38
+ "dependencies": {
39
+ "@metro-labs/discord-bot": "workspace:*",
40
+ "@metro-labs/telegram": "workspace:*",
41
+ "@metro-labs/telegram-bot": "workspace:*",
42
+ "@metro-labs/webhook": "workspace:*",
43
+ "@metro-labs/whatsapp": "workspace:*",
44
+ "@metro-labs/xmtp": "workspace:*",
45
+ "@modelcontextprotocol/sdk": "^1.12.0",
46
+ "@noble/curves": "^1.9.7",
47
+ "drizzle-kit": "^0.31.0",
48
+ "drizzle-orm": "^0.44.0",
49
+ "pino": "^9.5.0",
50
+ "pino-pretty": "^13.1.3",
51
+ "postgres": "^3.4.5",
52
+ "viem": "2.52.2",
53
+ "ws": "^8.18.0",
54
+ "zod": "^3.23.8"
55
+ },
56
+ "devDependencies": {
57
+ "@stage-labs/config": "0.1.0-beta.2",
58
+ "@types/ws": "^8.18.0",
59
+ "eslint": "^10.3.0",
60
+ "knip": "^6.15.0",
61
+ "madge": "^8.0.0",
62
+ "typescript": "^5"
63
+ }
64
+ }
@@ -0,0 +1,25 @@
1
+ import { str } from '../mcp/str.js';
2
+
3
+ export type Addressed = 'direct' | 'mention' | 'reply';
4
+
5
+ interface AddressFacts {
6
+ isPrivate?: unknown;
7
+ mentionsSelf?: unknown;
8
+ replyToSelf?: unknown;
9
+ }
10
+
11
+ export function addressedBy(facts: AddressFacts, replyTo: string, sent: ReadonlySet<string>): Addressed | undefined {
12
+ if (facts.isPrivate === true) return 'direct';
13
+ if (facts.mentionsSelf === true) return 'mention';
14
+ if (facts.replyToSelf === true || (replyTo !== '' && sent.has(replyTo))) return 'reply';
15
+ return undefined;
16
+ }
17
+
18
+ export function replyMeta(ev: Record<string, unknown>, sent: ReadonlySet<string>): Record<string, string> {
19
+ const replyTo = str(ev.replyTo);
20
+ const addressed = addressedBy(ev, replyTo, sent);
21
+ return {
22
+ ...(replyTo ? { reply_to: replyTo } : {}),
23
+ ...(addressed === undefined ? {} : { addressed }),
24
+ };
25
+ }
@@ -0,0 +1,24 @@
1
+ import { accountFromLine, agentIdForAccount } from '../db/agent-map.js';
2
+
3
+ const accountStrippedLine = (line: string): string => {
4
+ const parts = line.split('/');
5
+ if (parts.length < 5) return line;
6
+ return [parts[0], parts[1], parts[2], ...parts.slice(4)].join('/');
7
+ };
8
+
9
+ export const dedupeOwner = (line: string): string => {
10
+ const acct = accountFromLine(line);
11
+ if (!acct) return 'unowned';
12
+ const agentId = agentIdForAccount(acct.station, acct.accountId);
13
+ return agentId === undefined
14
+ ? `account:${acct.accountId}`
15
+ : `agent:${agentId}`;
16
+ };
17
+
18
+ export const dedupeKey = (
19
+ station: string,
20
+ line: string,
21
+ kind: string,
22
+ messageId: string,
23
+ ): string =>
24
+ `${dedupeOwner(line)} ${station} ${accountStrippedLine(line)} ${kind} ${messageId}`;
@@ -0,0 +1,377 @@
1
+ import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { str } from '../mcp/str.js';
3
+ import { dedupeKey } from './dedupe.js';
4
+ import {
5
+ buildMediaFailureNote,
6
+ buildMediaNote,
7
+ type MediaNote,
8
+ type SavedMedia,
9
+ } from './media-note.js';
10
+ import { buildWebhookNote } from './webhook-note.js';
11
+ import { replyMeta } from './addressed.js';
12
+ import {
13
+ capSet,
14
+ displayNameMeta,
15
+ senderMeta,
16
+ tsMeta,
17
+ takeMediaCtx,
18
+ type MediaCtx,
19
+ type PendingAtt,
20
+ type PendingMsg,
21
+ } from './pending.js';
22
+
23
+ interface InboundDeps {
24
+ mcp: Server;
25
+ log: (...a: unknown[]) => void;
26
+ getStations: () => Set<string>;
27
+ senderAllowed: (from: string, line: string) => boolean;
28
+ }
29
+
30
+ const ATTACH_TIMEOUT_MS = 15_000;
31
+ const DEDUPE_TTL_MS = 30_000;
32
+ const DEDUPE_MAX = 2_000;
33
+ const ALLOWED_LINES_MAX = 2_000;
34
+ const PENDING_PERMISSIONS_MAX = 500;
35
+ const SENT_IDS_MAX = 2_000;
36
+
37
+ const PERMISSION_REPLY_RE = /^\s*(y|yes|n|no)\s+([a-km-z]{5})\s*$/i;
38
+
39
+ const shortId = (id: string): string =>
40
+ id.length > 10 ? `${id.slice(0, 6)}…` : id;
41
+
42
+ export class InboundRelay {
43
+ private readonly deps: InboundDeps;
44
+ private readonly pendingAttachments = new Map<string, PendingMsg>();
45
+ private readonly seenEvents = new Map<string, number>();
46
+ private readonly allowedLines = new Set<string>();
47
+ private readonly pendingPermissions = new Set<string>();
48
+ private readonly sentIds = new Set<string>();
49
+ private lastLine: string | undefined;
50
+
51
+ constructor(deps: InboundDeps) {
52
+ this.deps = deps;
53
+ }
54
+
55
+ get knownLine(): string | undefined {
56
+ return this.lastLine;
57
+ }
58
+
59
+ registerPermission(requestId: string): void {
60
+ this.pendingPermissions.add(requestId);
61
+ capSet(this.pendingPermissions, PENDING_PERMISSIONS_MAX);
62
+ }
63
+
64
+ noteSent(messageId: string): void {
65
+ if (!messageId) return;
66
+ this.sentIds.add(messageId);
67
+ capSet(this.sentIds, SENT_IDS_MAX);
68
+ }
69
+
70
+ private notify(method: string, params: Record<string, unknown>): Promise<void> {
71
+ return this.deps.mcp.notification({ method, params });
72
+ }
73
+
74
+ private isDuplicate(
75
+ station: string,
76
+ line: string,
77
+ kind: string,
78
+ messageId: string,
79
+ ): boolean {
80
+ if (!messageId) return false;
81
+ const key = dedupeKey(station, line, kind, messageId);
82
+ const now = Date.now();
83
+ if (this.seenEvents.size >= DEDUPE_MAX) {
84
+ for (const [k, t] of this.seenEvents) {
85
+ if (now - t > DEDUPE_TTL_MS) this.seenEvents.delete(k);
86
+ }
87
+ }
88
+ const prev = this.seenEvents.get(key);
89
+ if (prev !== undefined && now - prev < DEDUPE_TTL_MS) return true;
90
+ this.seenEvents.set(key, now);
91
+ return false;
92
+ }
93
+
94
+ private surfaceNote(
95
+ ctx: MediaCtx,
96
+ p: SavedMedia,
97
+ note: MediaNote,
98
+ extra: Record<string, unknown>,
99
+ ): Promise<void> {
100
+ return this.notify('notifications/claude/channel', {
101
+ content: note.content,
102
+ meta: {
103
+ line: ctx.line,
104
+ from: ctx.from,
105
+ station: ctx.station,
106
+ ...senderMeta(ctx),
107
+ kind: note.kind,
108
+ mime: p.mime ?? '',
109
+ name: note.name,
110
+ ...extra,
111
+ },
112
+ });
113
+ }
114
+
115
+ private async surfaceMedia(ctx: MediaCtx, p: SavedMedia): Promise<void> {
116
+ const note = await buildMediaNote(p, ctx.text ?? '');
117
+ if (!note) return;
118
+ await this.surfaceNote(ctx, p, note, {
119
+ ...(p.url ? { url: p.url } : {}),
120
+ local_path: note.path,
121
+ });
122
+ }
123
+
124
+ private surfaceMediaFailure(ctx: MediaCtx, p: SavedMedia): Promise<void> {
125
+ return this.surfaceNote(ctx, p, buildMediaFailureNote(p, ctx.text ?? ''), {
126
+ attachment_error: p.reason ?? '',
127
+ });
128
+ }
129
+
130
+ private async flushPendingFallback(id: string): Promise<void> {
131
+ const e = this.pendingAttachments.get(id);
132
+ if (!e) return;
133
+ this.pendingAttachments.delete(id);
134
+ const missing = e.attachments.filter((_, i) => !e.saved.has(i));
135
+ if (!missing.length) return;
136
+ const names = missing
137
+ .map((a) => a.name ?? a.kind ?? 'attachment')
138
+ .join(', ');
139
+ await this.notify('notifications/claude/channel', {
140
+ content:
141
+ (e.text ? `${e.text}\n` : '') +
142
+ `[attachment(s) could not be fetched in time: ${names}]`,
143
+ meta: {
144
+ line: e.line,
145
+ from: e.from,
146
+ station: e.station,
147
+ ...tsMeta(e.ts),
148
+ message_id: e.messageId,
149
+ line_name: e.lineName,
150
+ from_name: e.fromName,
151
+ ...displayNameMeta(e.fromDisplayName),
152
+ },
153
+ });
154
+ }
155
+
156
+ private mediaCtxFor(
157
+ ev: Record<string, unknown>,
158
+ payload: SavedMedia,
159
+ ): MediaCtx | null {
160
+ const forId = str(payload.attachmentFor);
161
+ const buf = forId ? this.pendingAttachments.get(forId) : undefined;
162
+ if (buf) {
163
+ buf.saved.add(typeof payload.index === 'number' ? payload.index : 0);
164
+ const ctx = takeMediaCtx(buf);
165
+ if (buf.saved.size >= buf.attachments.length) {
166
+ clearTimeout(buf.timer);
167
+ this.pendingAttachments.delete(forId);
168
+ }
169
+ return ctx;
170
+ }
171
+ const line = str(ev.line);
172
+ if (!line || !this.allowedLines.has(line)) return null;
173
+ return {
174
+ line,
175
+ from: 'metro://attachment',
176
+ station: str(ev.station) || 'xmtp',
177
+ ts: str(ev.ts),
178
+ };
179
+ }
180
+
181
+ private async routeAttachment(ev: Record<string, unknown>): Promise<boolean> {
182
+ const p = ev.payload as SavedMedia | undefined;
183
+ if (!p) return false;
184
+ const type = p.contentType;
185
+ if (type !== 'attachmentSaved' && type !== 'attachmentFailed') return false;
186
+ const ctx = this.mediaCtxFor(ev, p);
187
+ if (!ctx) return true;
188
+ if (type === 'attachmentFailed') await this.surfaceMediaFailure(ctx, p);
189
+ else await this.surfaceMedia(ctx, p);
190
+ return true;
191
+ }
192
+
193
+ private bufferAttachments(
194
+ ev: Record<string, unknown>,
195
+ base: { line: string; from: string; station: string; text: string },
196
+ atts: PendingAtt[],
197
+ ): void {
198
+ const id = str(ev.id);
199
+ if (!id) return;
200
+ const existing = this.pendingAttachments.get(id);
201
+ if (existing) clearTimeout(existing.timer);
202
+ this.pendingAttachments.set(id, {
203
+ ...base,
204
+ ts: str(ev.ts),
205
+ messageId: str(ev.messageId),
206
+ lineName: str(ev.lineName),
207
+ fromName: str(ev.fromName),
208
+ fromDisplayName: str(ev.fromDisplayName),
209
+ attachments: atts.map((a) => ({ kind: a.kind, name: a.name })),
210
+ saved: new Set<number>(),
211
+ timer: setTimeout(() => {
212
+ this.flushPendingFallback(id).catch((err: unknown) => {
213
+ this.deps.log(
214
+ 'inbound: attachment fallback not delivered',
215
+ 'id',
216
+ id,
217
+ 'line',
218
+ base.line,
219
+ err,
220
+ );
221
+ });
222
+ }, ATTACH_TIMEOUT_MS),
223
+ });
224
+ }
225
+
226
+ private async handleReact(
227
+ ev: Record<string, unknown>,
228
+ base: { line: string; from: string; station: string; text: string },
229
+ ): Promise<void> {
230
+ const re = ev.event as { emoji?: unknown; targetId?: string };
231
+ const emoji = reactionEmoji(re.emoji);
232
+ const target = re.targetId ?? str(ev.messageId);
233
+ const removed =
234
+ (ev.payload as { removed?: boolean } | undefined)?.removed === true ||
235
+ / \(removed\)\]?$/.test(base.text);
236
+ const verb = removed ? 'removed from' : 'reacted to';
237
+ const label = removed ? emoji || 'reaction' : emoji || 'reacted';
238
+ const content = `${label} ${verb} message ${shortId(target)}`.trim();
239
+ await this.notify('notifications/claude/channel', {
240
+ content,
241
+ meta: {
242
+ line: base.line,
243
+ from: base.from,
244
+ station: base.station,
245
+ ...tsMeta(ev.ts),
246
+ message_id: str(ev.messageId),
247
+ line_name: str(ev.lineName),
248
+ from_name: str(ev.fromName),
249
+ ...displayNameMeta(ev.fromDisplayName),
250
+ reaction: emoji,
251
+ target_id: target,
252
+ },
253
+ });
254
+ }
255
+
256
+ private async handlePermissionReply(text: string): Promise<boolean> {
257
+ const m = PERMISSION_REPLY_RE.exec(text);
258
+ if (m?.[1] === undefined || m[2] === undefined || !this.pendingPermissions.size)
259
+ return false;
260
+ const id = m[2].toLowerCase();
261
+ if (!this.pendingPermissions.has(id)) return false;
262
+ this.pendingPermissions.delete(id);
263
+ await this.notify('notifications/claude/channel/permission', {
264
+ request_id: id,
265
+ behavior: m[1].toLowerCase().startsWith('y') ? 'allow' : 'deny',
266
+ });
267
+ return true;
268
+ }
269
+
270
+ private droppedSender(from: string, line: string): boolean {
271
+ if (
272
+ from.startsWith('metro://claude') ||
273
+ from === 'metro://user' ||
274
+ !from.startsWith('metro://')
275
+ )
276
+ return true;
277
+ if (!this.deps.senderAllowed(from, line)) {
278
+ this.deps.log('drop: sender not allowed', from);
279
+ return true;
280
+ }
281
+ return false;
282
+ }
283
+
284
+ private routable(
285
+ ev: Record<string, unknown>,
286
+ replay: boolean,
287
+ ): EventBase | null {
288
+ const rawType = ev.event ? (ev.event as { type?: string }).type : 'msg';
289
+ const evType = rawType === 'reply' ? 'msg' : rawType;
290
+ if (evType !== 'msg' && evType !== 'react' && evType !== 'system')
291
+ return null;
292
+ const station = str(ev.station);
293
+ if (!this.deps.getStations().has(station)) return null;
294
+ const from = str(ev.from);
295
+ const line = str(ev.line);
296
+ if (this.droppedSender(from, line)) return null;
297
+ const text = str(ev.text);
298
+ if (!replay && this.isDuplicate(station, line, evType, str(ev.messageId))) {
299
+ this.deps.log(
300
+ 'drop: duplicate (per-account) event',
301
+ evType,
302
+ station,
303
+ str(ev.messageId),
304
+ );
305
+ return null;
306
+ }
307
+ return { evType, station, from, line, text };
308
+ }
309
+
310
+ private async emitMessage(
311
+ ev: Record<string, unknown>,
312
+ base: EventBase,
313
+ ): Promise<void> {
314
+ if (base.evType === 'msg' && (await this.handlePermissionReply(base.text)))
315
+ return;
316
+ await this.notify('notifications/claude/channel', {
317
+ content:
318
+ base.evType === 'system'
319
+ ? buildWebhookNote(base.text, str(ev.lineName), ev.payload)
320
+ : base.text,
321
+ meta: {
322
+ line: base.line,
323
+ from: base.from,
324
+ station: base.station,
325
+ ...tsMeta(ev.ts),
326
+ message_id: str(ev.messageId),
327
+ line_name: str(ev.lineName),
328
+ from_name: str(ev.fromName),
329
+ ...displayNameMeta(ev.fromDisplayName),
330
+ ...replyMeta(ev, this.sentIds),
331
+ },
332
+ });
333
+ }
334
+
335
+ async handleEvent(
336
+ ev: Record<string, unknown>,
337
+ replay = false,
338
+ ): Promise<void> {
339
+ if (await this.routeAttachment(ev)) return;
340
+
341
+ const base = this.routable(ev, replay);
342
+ if (!base) return;
343
+ if (base.evType !== 'system') this.lastLine = base.line;
344
+ if (base.line) {
345
+ this.allowedLines.add(base.line);
346
+ capSet(this.allowedLines, ALLOWED_LINES_MAX);
347
+ }
348
+
349
+ const atts = (ev.payload as { attachments?: PendingAtt[] } | undefined)
350
+ ?.attachments;
351
+ if (Array.isArray(atts) && atts.length) {
352
+ this.bufferAttachments(ev, base, atts);
353
+ return;
354
+ }
355
+
356
+ if (base.evType === 'react') {
357
+ await this.handleReact(ev, base);
358
+ return;
359
+ }
360
+
361
+ await this.emitMessage(ev, base);
362
+ }
363
+ }
364
+
365
+ interface EventBase {
366
+ evType: string;
367
+ station: string;
368
+ from: string;
369
+ line: string;
370
+ text: string;
371
+ }
372
+
373
+ function reactionEmoji(raw: unknown): string {
374
+ if (typeof raw === 'string') return raw;
375
+ const obj = raw as { name?: string; reaction?: string } | undefined;
376
+ return obj?.name ?? obj?.reaction ?? '';
377
+ }
@@ -0,0 +1,85 @@
1
+ import { stat } from 'node:fs/promises';
2
+
3
+ const MAX_INLINE_BYTES = 4 * 1024 * 1024;
4
+
5
+ export interface SavedMedia {
6
+ contentType?: string;
7
+ attachmentFor?: string;
8
+ attachmentPath?: string;
9
+ localPath?: string;
10
+ url?: string;
11
+ mime?: string;
12
+ name?: string;
13
+ kind?: string;
14
+ index?: number;
15
+ reason?: string;
16
+ }
17
+
18
+ export interface MediaNote {
19
+ content: string;
20
+ kind: string;
21
+ name: string;
22
+ path: string;
23
+ }
24
+
25
+ export function mediaKind(mime?: string, name?: string): string {
26
+ const m = (mime ?? '').toLowerCase();
27
+ if (m.startsWith('image/')) return 'image';
28
+ if (m.startsWith('video/')) return 'video';
29
+ if (m.startsWith('audio/')) return 'audio';
30
+ const n = name ?? '';
31
+ if (/\.(png|jpe?g|gif|webp|heic)$/i.test(n)) return 'image';
32
+ if (/\.(mp4|mov|webm|m4v)$/i.test(n)) return 'video';
33
+ if (/\.(m4a|mp3|ogg|wav)$/i.test(n)) return 'audio';
34
+ return 'file';
35
+ }
36
+
37
+ async function fileSize(path: string): Promise<number> {
38
+ try {
39
+ return (await stat(path)).size;
40
+ } catch {
41
+ return 0;
42
+ }
43
+ }
44
+
45
+ function howToRead(url: string | undefined, tooBig: boolean): string {
46
+ if (!url)
47
+ return 'That path is on the daemon host, not on yours - this file is readable only by an agent running there.';
48
+ if (tooBig)
49
+ return 'Large file - fetch the Public URL only if you need the bytes, and do not inline it. The path is on the daemon host, not on yours.';
50
+ return 'Fetch the Public URL to view it. The path is on the daemon host, so the Read tool works only for an agent running there.';
51
+ }
52
+
53
+ export async function buildMediaNote(
54
+ p: SavedMedia,
55
+ caption: string,
56
+ ): Promise<MediaNote | null> {
57
+ const path = p.attachmentPath ?? p.localPath;
58
+ if (!path) return null;
59
+ const kind = p.kind ?? mediaKind(p.mime, p.name);
60
+ const name = p.name ?? path.split('/').pop() ?? 'attachment';
61
+ const size = await fileSize(path);
62
+ const sizeNote = size ? ` (${(size / 1024 / 1024).toFixed(2)} MB)` : '';
63
+ const content =
64
+ (caption ? `${caption}\n` : '') +
65
+ `[${kind} attachment received: ${name}${p.mime ? `, ${p.mime}` : ''}${sizeNote}]\n` +
66
+ (p.url ? `Public URL: ${p.url}\n` : '') +
67
+ `Daemon-host path: ${path}\n` +
68
+ howToRead(p.url, size > MAX_INLINE_BYTES);
69
+ return { content, kind, name, path };
70
+ }
71
+
72
+ export function buildMediaFailureNote(
73
+ p: SavedMedia,
74
+ caption: string,
75
+ ): MediaNote {
76
+ const kind = p.kind ?? mediaKind(p.mime, p.name);
77
+ const name = p.name ?? 'attachment';
78
+ const reason = p.reason ?? 'no reason reported';
79
+ const content =
80
+ (caption ? `${caption}\n` : '') +
81
+ `[${kind} attachment could not be fetched: ${name}]\n` +
82
+ `Reason: ${reason}\n` +
83
+ 'The sender still has the file; nothing was saved. Ask them to resend it, or say why it could not be taken.';
84
+ return { content, kind, name, path: '' };
85
+ }
@@ -0,0 +1,75 @@
1
+ import { str } from '../mcp/str.js';
2
+
3
+ export interface PendingAtt {
4
+ kind?: string;
5
+ name?: string;
6
+ }
7
+
8
+ export interface PendingMsg {
9
+ line: string;
10
+ from: string;
11
+ station: string;
12
+ text: string;
13
+ ts: string;
14
+ messageId: string;
15
+ lineName: string;
16
+ fromName: string;
17
+ fromDisplayName: string;
18
+ attachments: PendingAtt[];
19
+ saved: Set<number>;
20
+ timer: ReturnType<typeof setTimeout>;
21
+ }
22
+
23
+ export interface MediaCtx {
24
+ line: string;
25
+ from: string;
26
+ station: string;
27
+ text?: string;
28
+ ts?: string;
29
+ messageId?: string;
30
+ lineName?: string;
31
+ fromName?: string;
32
+ fromDisplayName?: string;
33
+ }
34
+
35
+ export function capSet(set: Set<string>, max: number): void {
36
+ while (set.size > max) {
37
+ const oldest = set.values().next();
38
+ if (oldest.done) break;
39
+ set.delete(oldest.value);
40
+ }
41
+ }
42
+
43
+ export const tsMeta = (v: unknown): Record<string, string> => {
44
+ const ts = str(v);
45
+ return ts ? { ts } : {};
46
+ };
47
+
48
+ export const displayNameMeta = (v: unknown): Record<string, string> => {
49
+ const name = str(v);
50
+ return name ? { from_display_name: name } : {};
51
+ };
52
+
53
+ export const senderMeta = (c: MediaCtx): Record<string, string> => ({
54
+ ...tsMeta(c.ts),
55
+ ...(c.messageId ? { message_id: c.messageId } : {}),
56
+ ...(c.lineName ? { line_name: c.lineName } : {}),
57
+ ...(c.fromName ? { from_name: c.fromName } : {}),
58
+ ...displayNameMeta(c.fromDisplayName),
59
+ });
60
+
61
+ export function takeMediaCtx(buf: PendingMsg): MediaCtx {
62
+ const ctx: MediaCtx = {
63
+ line: buf.line,
64
+ from: buf.from,
65
+ station: buf.station,
66
+ text: buf.text,
67
+ ts: buf.ts,
68
+ messageId: buf.messageId,
69
+ lineName: buf.lineName,
70
+ fromName: buf.fromName,
71
+ fromDisplayName: buf.fromDisplayName,
72
+ };
73
+ buf.text = '';
74
+ return ctx;
75
+ }