@stage-labs/metro 0.1.0-beta.9 → 0.1.0-beta.91

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 (287) hide show
  1. package/dist/api.js +14 -0
  2. package/dist/claude-settings.js +40 -0
  3. package/dist/claude.js +129 -0
  4. package/dist/cli.js +101 -0
  5. package/dist/control.js +74 -0
  6. package/dist/hold.js +211 -0
  7. package/dist/local.js +93 -0
  8. package/dist/node-name.js +71 -0
  9. package/dist/plugin.js +80 -0
  10. package/dist/provider-flags.js +9 -0
  11. package/dist/runtime-install.js +87 -0
  12. package/dist/runtime.js +74 -0
  13. package/dist/serve.js +150 -0
  14. package/dist/service.js +242 -0
  15. package/dist/tail.js +119 -0
  16. package/dist/update.js +45 -0
  17. package/dist/version.js +97 -0
  18. package/package.json +14 -25
  19. package/runtime/node_modules/@metro-labs/core/package.json +43 -0
  20. package/runtime/node_modules/@metro-labs/core/src/address.ts +6 -0
  21. package/runtime/node_modules/@metro-labs/core/src/endpoints.ts +7 -0
  22. package/runtime/node_modules/@metro-labs/core/src/events.ts +120 -0
  23. package/runtime/node_modules/@metro-labs/core/src/identity.ts +7 -0
  24. package/runtime/node_modules/@metro-labs/core/src/ids.ts +21 -0
  25. package/runtime/node_modules/@metro-labs/core/src/is-record.ts +2 -0
  26. package/runtime/node_modules/@metro-labs/core/src/lines.ts +82 -0
  27. package/runtime/node_modules/@metro-labs/core/src/log.ts +42 -0
  28. package/runtime/node_modules/@metro-labs/core/src/protocol.ts +226 -0
  29. package/runtime/node_modules/@metro-labs/core/src/secure-fs.ts +57 -0
  30. package/runtime/node_modules/@metro-labs/core/src/station-names.ts +12 -0
  31. package/runtime/node_modules/@metro-labs/core/src/stations/account-store.ts +60 -0
  32. package/runtime/node_modules/@metro-labs/core/src/stations/attachments.ts +196 -0
  33. package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +88 -0
  34. package/runtime/node_modules/@metro-labs/core/src/stations/station-runtime.ts +64 -0
  35. package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +107 -0
  36. package/runtime/node_modules/@metro-labs/core/src/str.ts +5 -0
  37. package/runtime/node_modules/@metro-labs/core/src/train-error.ts +53 -0
  38. package/runtime/node_modules/@metro-labs/core/src/version.ts +2 -0
  39. package/runtime/node_modules/@metro-labs/daemon/package.json +47 -0
  40. package/runtime/node_modules/@metro-labs/daemon/src/agents/account-attach.ts +19 -0
  41. package/runtime/node_modules/@metro-labs/daemon/src/agents/accounts-api.ts +368 -0
  42. package/runtime/node_modules/@metro-labs/daemon/src/agents/admin.ts +43 -0
  43. package/runtime/node_modules/@metro-labs/daemon/src/agents/allowlist.ts +37 -0
  44. package/runtime/node_modules/@metro-labs/daemon/src/agents/api.ts +302 -0
  45. package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +111 -0
  46. package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +345 -0
  47. package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +155 -0
  48. package/runtime/node_modules/@metro-labs/daemon/src/agents/keys.ts +45 -0
  49. package/runtime/node_modules/@metro-labs/daemon/src/agents/map.ts +88 -0
  50. package/runtime/node_modules/@metro-labs/daemon/src/agents/scope.ts +64 -0
  51. package/runtime/node_modules/@metro-labs/daemon/src/agents/senders.ts +38 -0
  52. package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +193 -0
  53. package/runtime/node_modules/@metro-labs/daemon/src/boot/connect-hint.ts +39 -0
  54. package/runtime/node_modules/@metro-labs/daemon/src/boot/crash-guard.ts +49 -0
  55. package/runtime/node_modules/@metro-labs/daemon/src/boot/local-owner.ts +14 -0
  56. package/runtime/node_modules/@metro-labs/daemon/src/boot/paths.ts +106 -0
  57. package/runtime/node_modules/@metro-labs/daemon/src/channels/addressed.ts +25 -0
  58. package/runtime/node_modules/@metro-labs/daemon/src/channels/dedupe.ts +24 -0
  59. package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +377 -0
  60. package/runtime/node_modules/@metro-labs/daemon/src/channels/media-note.ts +85 -0
  61. package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +75 -0
  62. package/runtime/node_modules/@metro-labs/daemon/src/channels/relay.ts +129 -0
  63. package/runtime/node_modules/@metro-labs/daemon/src/channels/webhook-note.ts +51 -0
  64. package/runtime/node_modules/@metro-labs/daemon/src/claude/api.ts +176 -0
  65. package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +329 -0
  66. package/runtime/node_modules/@metro-labs/daemon/src/claude/login.ts +167 -0
  67. package/runtime/node_modules/@metro-labs/daemon/src/claude/settings.ts +117 -0
  68. package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +154 -0
  69. package/runtime/node_modules/@metro-labs/daemon/src/connectors/api.ts +307 -0
  70. package/runtime/node_modules/@metro-labs/daemon/src/connectors/cli-api.ts +63 -0
  71. package/runtime/node_modules/@metro-labs/daemon/src/connectors/config.ts +144 -0
  72. package/runtime/node_modules/@metro-labs/daemon/src/connectors/json.ts +21 -0
  73. package/runtime/node_modules/@metro-labs/daemon/src/connectors/model.ts +69 -0
  74. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-client.ts +159 -0
  75. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-discovery.ts +117 -0
  76. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-pending.ts +65 -0
  77. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-routes.ts +157 -0
  78. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth.ts +127 -0
  79. package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +112 -0
  80. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-target.ts +39 -0
  81. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +295 -0
  82. package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +277 -0
  83. package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +98 -0
  84. package/runtime/node_modules/@metro-labs/daemon/src/connectors/url.ts +70 -0
  85. package/runtime/node_modules/@metro-labs/daemon/src/connectors/verify.ts +330 -0
  86. package/runtime/node_modules/@metro-labs/daemon/src/connectors/watch.ts +54 -0
  87. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-grant.ts +99 -0
  88. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-owner.ts +32 -0
  89. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +121 -0
  90. package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +294 -0
  91. package/runtime/node_modules/@metro-labs/daemon/src/files/upload-store.ts +181 -0
  92. package/runtime/node_modules/@metro-labs/daemon/src/gateway/bedrock.ts +252 -0
  93. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-auth.ts +231 -0
  94. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-device.ts +91 -0
  95. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-stream.ts +288 -0
  96. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex-translate.ts +203 -0
  97. package/runtime/node_modules/@metro-labs/daemon/src/gateway/codex.ts +220 -0
  98. package/runtime/node_modules/@metro-labs/daemon/src/gateway/eventstream.ts +123 -0
  99. package/runtime/node_modules/@metro-labs/daemon/src/gateway/forward.ts +182 -0
  100. package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +208 -0
  101. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +195 -0
  102. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +198 -0
  103. package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +40 -0
  104. package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +17 -0
  105. package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +139 -0
  106. package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +216 -0
  107. package/runtime/node_modules/@metro-labs/daemon/src/mcp/channel-owner.ts +29 -0
  108. package/runtime/node_modules/@metro-labs/daemon/src/mcp/ctx.ts +62 -0
  109. package/runtime/node_modules/@metro-labs/daemon/src/mcp/event-store.ts +91 -0
  110. package/runtime/node_modules/@metro-labs/daemon/src/mcp/frame-scope.ts +21 -0
  111. package/runtime/node_modules/@metro-labs/daemon/src/mcp/group-tools.ts +129 -0
  112. package/runtime/node_modules/@metro-labs/daemon/src/mcp/index.ts +191 -0
  113. package/runtime/node_modules/@metro-labs/daemon/src/mcp/member-tools.ts +72 -0
  114. package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-relay.ts +66 -0
  115. package/runtime/node_modules/@metro-labs/daemon/src/mcp/raw-get-stream.ts +207 -0
  116. package/runtime/node_modules/@metro-labs/daemon/src/mcp/request-identity.ts +47 -0
  117. package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-registry.ts +172 -0
  118. package/runtime/node_modules/@metro-labs/daemon/src/mcp/session-route.ts +43 -0
  119. package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +215 -0
  120. package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-dispatch.ts +215 -0
  121. package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-schemas.ts +400 -0
  122. package/runtime/node_modules/@metro-labs/daemon/src/mcp/upload-tool.ts +66 -0
  123. package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +237 -0
  124. package/runtime/node_modules/@metro-labs/daemon/src/net/tunnel.ts +389 -0
  125. package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +390 -0
  126. package/runtime/node_modules/@metro-labs/daemon/src/routes/identity.ts +54 -0
  127. package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +198 -0
  128. package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +60 -0
  129. package/runtime/node_modules/@metro-labs/daemon/src/routes/session.ts +29 -0
  130. package/runtime/node_modules/@metro-labs/daemon/src/server/control.ts +64 -0
  131. package/runtime/node_modules/@metro-labs/daemon/src/server/machine.ts +61 -0
  132. package/runtime/node_modules/@metro-labs/daemon/src/server/update.ts +116 -0
  133. package/runtime/node_modules/@metro-labs/daemon/src/server.ts +2 -0
  134. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-inline.ts +100 -0
  135. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-interactive.ts +161 -0
  136. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +202 -0
  137. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-session.ts +280 -0
  138. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-xmtp.ts +111 -0
  139. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach.ts +184 -0
  140. package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +248 -0
  141. package/runtime/node_modules/@metro-labs/daemon/src/stations/registry.ts +35 -0
  142. package/runtime/node_modules/@metro-labs/daemon/src/stations/runtime-deps.ts +82 -0
  143. package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor-io.ts +97 -0
  144. package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor.ts +320 -0
  145. package/runtime/node_modules/@metro-labs/daemon/src/stations/train-call.ts +22 -0
  146. package/runtime/node_modules/@metro-labs/daemon/src/terminal/api.ts +91 -0
  147. package/runtime/node_modules/@metro-labs/daemon/src/terminal/socket.ts +123 -0
  148. package/runtime/node_modules/@metro-labs/daemon/src/terminal/tickets.ts +40 -0
  149. package/runtime/node_modules/@metro-labs/discord-bot/package.json +28 -0
  150. package/runtime/node_modules/@metro-labs/discord-bot/src/accounts.ts +118 -0
  151. package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +388 -0
  152. package/runtime/node_modules/@metro-labs/discord-bot/src/api-base.ts +1 -0
  153. package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +29 -0
  154. package/runtime/node_modules/@metro-labs/discord-bot/src/format.ts +220 -0
  155. package/runtime/node_modules/@metro-labs/discord-bot/src/group-actions.ts +50 -0
  156. package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +115 -0
  157. package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +127 -0
  158. package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +215 -0
  159. package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +43 -0
  160. package/runtime/node_modules/@metro-labs/discord-bot/src/station.ts +19 -0
  161. package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +82 -0
  162. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-speak.ts +195 -0
  163. package/runtime/node_modules/@metro-labs/discord-bot/src/voice-transcribe.ts +292 -0
  164. package/runtime/node_modules/@metro-labs/discord-bot/src/voice.ts +197 -0
  165. package/runtime/node_modules/@metro-labs/discord-bot/src/wire.ts +5 -0
  166. package/runtime/node_modules/@metro-labs/http/package.json +33 -0
  167. package/runtime/node_modules/@metro-labs/http/src/api-error.ts +8 -0
  168. package/runtime/node_modules/@metro-labs/http/src/api-http.ts +95 -0
  169. package/runtime/node_modules/@metro-labs/http/src/cors.ts +29 -0
  170. package/runtime/node_modules/@metro-labs/http/src/identity-key.ts +33 -0
  171. package/runtime/node_modules/@metro-labs/http/src/identity-registry.ts +13 -0
  172. package/runtime/node_modules/@metro-labs/http/src/mode-api.ts +32 -0
  173. package/runtime/node_modules/@metro-labs/http/src/return-to.ts +21 -0
  174. package/runtime/node_modules/@metro-labs/http/src/signed-identity.ts +36 -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/server.ts +1 -0
  257. package/runtime/stations.json +36 -0
  258. package/runtime/trains/.keep +0 -0
  259. package/LICENSE +0 -21
  260. package/README.md +0 -249
  261. package/dist/cache.js +0 -75
  262. package/dist/cli/actions.js +0 -139
  263. package/dist/cli/config.js +0 -185
  264. package/dist/cli/index.js +0 -177
  265. package/dist/cli/skill.js +0 -62
  266. package/dist/cli/util.js +0 -72
  267. package/dist/cli/webhook.js +0 -83
  268. package/dist/codex-rc.js +0 -245
  269. package/dist/dispatcher.js +0 -122
  270. package/dist/history.js +0 -99
  271. package/dist/ipc.js +0 -72
  272. package/dist/log.js +0 -15
  273. package/dist/paths.js +0 -68
  274. package/dist/registry.js +0 -48
  275. package/dist/stations/claude.js +0 -45
  276. package/dist/stations/codex.js +0 -68
  277. package/dist/stations/discord.js +0 -200
  278. package/dist/stations/index.js +0 -133
  279. package/dist/stations/telegram-md.js +0 -34
  280. package/dist/stations/telegram-upload.js +0 -113
  281. package/dist/stations/telegram.js +0 -213
  282. package/dist/stations/webhook.js +0 -100
  283. package/dist/tunnel.js +0 -66
  284. package/dist/webhooks.js +0 -40
  285. package/docs/agents.md +0 -216
  286. package/docs/uri-scheme.md +0 -125
  287. package/skills/metro/SKILL.md +0 -249
@@ -0,0 +1,368 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { errMsg, log } from '@metro-labs/core/log';
3
+ import { normalizeAllowlist } from './allowlist.js';
4
+ import type { RecentSender } from './senders.js';
5
+ import { ApiError } from '@metro-labs/http/api-error';
6
+ import {
7
+ apiFailure,
8
+ bodyField,
9
+ readJsonBody,
10
+ sendJson,
11
+ type ApiSession,
12
+ } from '@metro-labs/http/api-http';
13
+ import {
14
+ isStationName,
15
+ parseAccountId,
16
+ type AccountRef,
17
+ } from './account-attach.js';
18
+ import type { StationName } from '@metro-labs/core/station-names';
19
+ import {
20
+ ATTACHABLE_STATIONS,
21
+ isAttachStation,
22
+ type AttachInput,
23
+ type OneTimeSecret,
24
+ type PreparedAccount,
25
+ } from '../stations/attach.js';
26
+ import {
27
+ INTERACTIVE_STATIONS,
28
+ isInteractiveStation,
29
+ type InteractiveStation,
30
+ } from '../stations/attach-interactive.js';
31
+ import {
32
+ ATTACH_ID_RE,
33
+ type AttachOwner,
34
+ type AttachView,
35
+ } from '../stations/attach-session.js';
36
+
37
+ export interface AttachSessionApi {
38
+ start: (
39
+ owner: AttachOwner,
40
+ station: InteractiveStation,
41
+ input: Record<string, unknown>,
42
+ ) => Promise<AttachView>;
43
+ view: (owner: AttachOwner, attachId: string) => AttachView;
44
+ submit: (
45
+ owner: AttachOwner,
46
+ attachId: string,
47
+ input: { code?: unknown; password?: unknown },
48
+ ) => Promise<AttachView>;
49
+ cancel: (owner: AttachOwner, attachId: string) => Promise<void>;
50
+ }
51
+
52
+ export interface AccountApiDeps {
53
+ attachSessions: AttachSessionApi;
54
+ prepareAccount: (input: AttachInput) => Promise<PreparedAccount>;
55
+ attachAccount: (
56
+ subject: string,
57
+ agentId: string,
58
+ station: StationName,
59
+ config: Record<string, unknown>,
60
+ ) => Promise<AccountRef>;
61
+ detachAccount: (
62
+ subject: string,
63
+ agentId: string,
64
+ station: StationName,
65
+ accountId: string,
66
+ ) => Promise<AccountRef>;
67
+ syncStations: (station: StationName) => Promise<void>;
68
+ reloadAgents: () => Promise<void>;
69
+ setAllowlist: (
70
+ subject: string,
71
+ agentId: string,
72
+ station: StationName,
73
+ accountId: string,
74
+ allowlist: string[],
75
+ ) => Promise<string[]>;
76
+ recentSenders: (station: StationName, accountId: string) => RecentSender[];
77
+ }
78
+
79
+ export type AccountRoute =
80
+ | { kind: 'start' }
81
+ | { kind: 'session'; attachId: string }
82
+ | { kind: 'step'; attachId: string }
83
+ | { kind: 'account'; station: StationName; accountId: string }
84
+ | { kind: 'allowlist'; station: StationName; accountId: string }
85
+ | { kind: 'senders'; station: StationName; accountId: string };
86
+
87
+ export const ATTACHABLE: string[] = [
88
+ ...ATTACHABLE_STATIONS,
89
+ ...INTERACTIVE_STATIONS,
90
+ ];
91
+
92
+ const ROUTE_METHODS: Record<AccountRoute['kind'], string[]> = {
93
+ start: ['POST'],
94
+ session: ['GET', 'DELETE'],
95
+ step: ['POST'],
96
+ account: ['DELETE'],
97
+ allowlist: ['PUT'],
98
+ senders: ['GET'],
99
+ };
100
+
101
+ function twoSegmentRoute(head: string, tail: string): AccountRoute | null {
102
+ if (ATTACH_ID_RE.test(head))
103
+ return tail === 'step' ? { kind: 'step', attachId: head } : null;
104
+ if (!isStationName(head)) return null;
105
+ const accountId = parseAccountId(tail);
106
+ return accountId === null ? null : { kind: 'account', station: head, accountId };
107
+ }
108
+
109
+ export function accountRoute(rest: string[]): AccountRoute | null {
110
+ const [head, tail] = rest;
111
+ if (head === undefined) return null;
112
+ if (rest.length === 1)
113
+ return head === 'start'
114
+ ? { kind: 'start' }
115
+ : ATTACH_ID_RE.test(head)
116
+ ? { kind: 'session', attachId: head }
117
+ : null;
118
+ if (rest.length === 3 && tail !== undefined) return accountSubRoute(head, tail, rest[2]);
119
+ if (rest.length !== 2 || tail === undefined) return null;
120
+ return twoSegmentRoute(head, tail);
121
+ }
122
+
123
+ function accountSubRoute(head: string, tail: string, sub: string | undefined): AccountRoute | null {
124
+ if (!isStationName(head) || (sub !== 'allowlist' && sub !== 'senders')) return null;
125
+ const accountId = parseAccountId(tail);
126
+ return accountId === null ? null : { kind: sub, station: head, accountId };
127
+ }
128
+
129
+ export function accountRouteAllows(
130
+ route: AccountRoute,
131
+ method: string | undefined,
132
+ ): boolean {
133
+ return ROUTE_METHODS[route.kind].includes(method ?? '');
134
+ }
135
+
136
+ async function activate(
137
+ deps: AccountApiDeps,
138
+ station: StationName,
139
+ ): Promise<boolean> {
140
+ try {
141
+ await deps.syncStations(station);
142
+ return true;
143
+ } catch (err) {
144
+ log.warn(
145
+ { station, err: errMsg(err) },
146
+ 'account-api: station reload failed, the change lands at the next boot',
147
+ );
148
+ return false;
149
+ }
150
+ }
151
+
152
+ interface AttachPayload {
153
+ status: 'done';
154
+ agentId: string;
155
+ station: string;
156
+ accountId: string;
157
+ identity: Record<string, string>;
158
+ activated: boolean;
159
+ secret?: OneTimeSecret;
160
+ }
161
+
162
+ async function storeAccount(
163
+ deps: AccountApiDeps,
164
+ session: ApiSession,
165
+ agentId: string,
166
+ station: StationName,
167
+ prepared: PreparedAccount,
168
+ ): Promise<AccountRef> {
169
+ try {
170
+ return await deps.attachAccount(
171
+ session.subject,
172
+ agentId,
173
+ station,
174
+ prepared.config,
175
+ );
176
+ } catch (err) {
177
+ prepared.discard?.();
178
+ throw err;
179
+ }
180
+ }
181
+
182
+ function ownerOf(session: ApiSession, agentId: string): AttachOwner {
183
+ return { subject: session.subject, agentId };
184
+ }
185
+
186
+ function asInput(body: unknown): Record<string, unknown> {
187
+ const out: Record<string, unknown> = {};
188
+ for (const key of ['apiId', 'apiHash', 'phone'])
189
+ out[key] = bodyField(body, key);
190
+ return out;
191
+ }
192
+
193
+ async function handleStart(
194
+ req: IncomingMessage,
195
+ res: ServerResponse,
196
+ deps: AccountApiDeps,
197
+ session: ApiSession,
198
+ agentId: string,
199
+ ): Promise<void> {
200
+ const body = await readJsonBody(req);
201
+ const station = bodyField(body, 'station');
202
+ if (isInteractiveStation(station)) {
203
+ const view = await deps.attachSessions.start(
204
+ ownerOf(session, agentId),
205
+ station,
206
+ asInput(body),
207
+ );
208
+ sendJson(req, res, 201, view);
209
+ return;
210
+ }
211
+ if (!isAttachStation(station))
212
+ throw new ApiError(`station must be one of ${ATTACHABLE.join(', ')}`, 400);
213
+ const prepared = await deps.prepareAccount({
214
+ station,
215
+ token: bodyField(body, 'token'),
216
+ });
217
+ const ref = await storeAccount(deps, session, agentId, station, prepared);
218
+ log.info(
219
+ { agentId: ref.agentId, station, account: ref.accountId },
220
+ 'account-api: attached a station account',
221
+ );
222
+ const payload: AttachPayload = {
223
+ status: 'done',
224
+ agentId: ref.agentId,
225
+ station,
226
+ accountId: ref.accountId,
227
+ identity: prepared.identity,
228
+ activated: await activate(deps, station),
229
+ };
230
+ sendJson(
231
+ req,
232
+ res,
233
+ 201,
234
+ prepared.secret === undefined
235
+ ? payload
236
+ : { ...payload, secret: prepared.secret },
237
+ );
238
+ }
239
+
240
+ async function handleDetach(
241
+ req: IncomingMessage,
242
+ res: ServerResponse,
243
+ deps: AccountApiDeps,
244
+ session: ApiSession,
245
+ agentId: string,
246
+ target: { station: StationName; accountId: string },
247
+ ): Promise<void> {
248
+ const ref = await deps.detachAccount(
249
+ session.subject,
250
+ agentId,
251
+ target.station,
252
+ target.accountId,
253
+ );
254
+ log.info(
255
+ { agentId: ref.agentId, station: ref.station, account: ref.accountId },
256
+ 'account-api: detached a station account',
257
+ );
258
+ sendJson(req, res, 200, {
259
+ agentId: ref.agentId,
260
+ station: ref.station,
261
+ accountId: ref.accountId,
262
+ detached: true,
263
+ activated: await activate(deps, ref.station),
264
+ });
265
+ }
266
+
267
+ async function applied(deps: AccountApiDeps): Promise<boolean> {
268
+ try {
269
+ await deps.reloadAgents();
270
+ return true;
271
+ } catch (err) {
272
+ log.warn({ err: errMsg(err) }, 'account-api: allowlist reload failed, the change lands at the next boot');
273
+ return false;
274
+ }
275
+ }
276
+
277
+ async function handleAllowlist(
278
+ req: IncomingMessage,
279
+ res: ServerResponse,
280
+ deps: AccountApiDeps,
281
+ session: ApiSession,
282
+ agentId: string,
283
+ target: { station: StationName; accountId: string },
284
+ ): Promise<void> {
285
+ const wanted = normalizeAllowlist(bodyField(await readJsonBody(req), 'allowlist'));
286
+ const allowlist = await deps.setAllowlist(session.subject, agentId, target.station, target.accountId, wanted);
287
+ log.info({ agentId, station: target.station, account: target.accountId, senders: allowlist.length }, 'account-api: allowlist set');
288
+ sendJson(req, res, 200, {
289
+ agentId,
290
+ station: target.station,
291
+ accountId: target.accountId,
292
+ allowlist,
293
+ activated: await applied(deps),
294
+ });
295
+ }
296
+
297
+ async function handleSession(
298
+ req: IncomingMessage,
299
+ res: ServerResponse,
300
+ deps: AccountApiDeps,
301
+ owner: AttachOwner,
302
+ attachId: string,
303
+ ): Promise<void> {
304
+ if (req.method === 'DELETE') {
305
+ await deps.attachSessions.cancel(owner, attachId);
306
+ sendJson(req, res, 200, { attachId, cancelled: true });
307
+ return;
308
+ }
309
+ sendJson(req, res, 200, deps.attachSessions.view(owner, attachId));
310
+ }
311
+
312
+ async function handleStep(
313
+ req: IncomingMessage,
314
+ res: ServerResponse,
315
+ deps: AccountApiDeps,
316
+ owner: AttachOwner,
317
+ attachId: string,
318
+ ): Promise<void> {
319
+ const body = await readJsonBody(req);
320
+ const view = await deps.attachSessions.submit(owner, attachId, {
321
+ code: bodyField(body, 'code'),
322
+ password: bodyField(body, 'password'),
323
+ });
324
+ sendJson(req, res, 200, view);
325
+ }
326
+
327
+ async function dispatchRoute(
328
+ req: IncomingMessage,
329
+ res: ServerResponse,
330
+ deps: AccountApiDeps,
331
+ session: ApiSession,
332
+ agentId: string,
333
+ route: AccountRoute,
334
+ ): Promise<void> {
335
+ if (route.kind === 'start')
336
+ return handleStart(req, res, deps, session, agentId);
337
+ if (route.kind === 'session')
338
+ return handleSession(
339
+ req,
340
+ res,
341
+ deps,
342
+ ownerOf(session, agentId),
343
+ route.attachId,
344
+ );
345
+ if (route.kind === 'step')
346
+ return handleStep(req, res, deps, ownerOf(session, agentId), route.attachId);
347
+ if (route.kind === 'allowlist') return handleAllowlist(req, res, deps, session, agentId, route);
348
+ if (route.kind === 'senders') {
349
+ sendJson(req, res, 200, { senders: deps.recentSenders(route.station, route.accountId) });
350
+ return;
351
+ }
352
+ return handleDetach(req, res, deps, session, agentId, route);
353
+ }
354
+
355
+ export async function handleAccountRoute(
356
+ req: IncomingMessage,
357
+ res: ServerResponse,
358
+ deps: AccountApiDeps,
359
+ session: ApiSession,
360
+ agentId: string,
361
+ route: AccountRoute,
362
+ ): Promise<void> {
363
+ try {
364
+ await dispatchRoute(req, res, deps, session, agentId, route);
365
+ } catch (err) {
366
+ apiFailure(req, res, err);
367
+ }
368
+ }
@@ -0,0 +1,43 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { ApiError } from '@metro-labs/http/api-error';
3
+ import { AGENT_NAME_RE } from '@metro-labs/core/ids';
4
+
5
+ export class AgentAdminError extends ApiError {}
6
+
7
+ export interface AgentSummary {
8
+ id: string;
9
+ name: string;
10
+ owned: boolean;
11
+ key: string | null;
12
+ }
13
+
14
+ export interface CreatedAgent {
15
+ id: string;
16
+ name: string;
17
+ key: string;
18
+ }
19
+
20
+ export interface OwnedAgent {
21
+ id: string;
22
+ name: string;
23
+ }
24
+
25
+ export type DeletedAgent = OwnedAgent;
26
+
27
+ export interface ResetAgentKey extends OwnedAgent {
28
+ key: string;
29
+ }
30
+
31
+ export function normalizeAgentName(raw: unknown): string {
32
+ const name = typeof raw === 'string' ? raw.trim() : '';
33
+ if (!AGENT_NAME_RE.test(name))
34
+ throw new AgentAdminError(
35
+ 'name must be 2-32 characters of A-Z, a-z, 0-9, - or _, starting with a letter or digit',
36
+ 400,
37
+ );
38
+ return name;
39
+ }
40
+
41
+ export function newApiKey(): string {
42
+ return `mk_${randomBytes(32).toString('base64url')}`;
43
+ }
@@ -0,0 +1,37 @@
1
+ import { ApiError } from '@metro-labs/http/api-error';
2
+
3
+ export const EVERYONE = '*';
4
+ const MAX_ENTRIES = 500;
5
+ const MAX_LENGTH = 200;
6
+
7
+ function hasControlChar(value: string): boolean {
8
+ for (const ch of value) {
9
+ const code = ch.codePointAt(0) ?? 0;
10
+ if (code < 0x20 || code === 0x7f) return true;
11
+ }
12
+ return false;
13
+ }
14
+
15
+ function senderId(entry: unknown): string {
16
+ if (typeof entry !== 'string') throw new ApiError('allowlist must be a list of sender ids', 400);
17
+ const value = entry.trim();
18
+ if (value.length > MAX_LENGTH || hasControlChar(value))
19
+ throw new ApiError(`a sender id is at most ${String(MAX_LENGTH)} plain characters`, 400);
20
+ return value;
21
+ }
22
+
23
+ export function normalizeAllowlist(raw: unknown): string[] {
24
+ if (!Array.isArray(raw)) throw new ApiError('allowlist must be a list of sender ids', 400);
25
+ if (raw.length > MAX_ENTRIES) throw new ApiError(`allowlist holds at most ${String(MAX_ENTRIES)} senders`, 400);
26
+ const seen = new Set<string>();
27
+ const out: string[] = [];
28
+ for (const entry of raw) {
29
+ const value = senderId(entry);
30
+ if (value === EVERYONE) return [EVERYONE];
31
+ const key = value.toLowerCase();
32
+ if (key === '' || seen.has(key)) continue;
33
+ seen.add(key);
34
+ out.push(value);
35
+ }
36
+ return out.length === 0 ? [EVERYONE] : out;
37
+ }