@celljs/ta 4.8.0 → 4.9.0
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/README.en.md +37 -2
- package/README.md +37 -2
- package/bin/ta.mjs +1 -1
- package/dist/cli.mjs +591 -15
- package/dist/gateway.mjs +2812 -0
- package/dist/pi/CHANGELOG.md +27 -0
- package/dist/pi/package.json +1 -1
- package/dist/pi/packages/ta-agents/extension/index.mjs +11 -1
- package/dist/pi/packages/ta-agents/lib/agent-session.js +5 -0
- package/dist/pi/packages/ta-agents/lib/agent-streamer.js +10 -1
- package/dist/pi/packages/ta-agents/package.json +11 -3
- package/dist/pi/packages/ta-bots/README.en.md +46 -0
- package/dist/pi/packages/ta-bots/README.md +46 -0
- package/dist/pi/packages/ta-bots/extension/index.mjs +629 -0
- package/dist/pi/packages/ta-bots/host/index.mjs +2313 -0
- package/dist/pi/packages/ta-bots/lib/bot-service.d.ts +96 -0
- package/dist/pi/packages/ta-bots/lib/bot-service.js +391 -0
- package/dist/pi/packages/ta-bots/lib/bot-store.d.ts +42 -0
- package/dist/pi/packages/ta-bots/lib/bot-store.js +97 -0
- package/dist/pi/packages/ta-bots/lib/bots-protocol.d.ts +131 -0
- package/dist/pi/packages/ta-bots/lib/bots-protocol.js +46 -0
- package/dist/pi/packages/ta-bots/lib/bots-view.d.ts +7 -0
- package/dist/pi/packages/ta-bots/lib/bots-view.js +84 -0
- package/dist/pi/packages/ta-bots/lib/channel-protocol.d.ts +58 -0
- package/dist/pi/packages/ta-bots/lib/channel-protocol.js +37 -0
- package/dist/pi/packages/ta-bots/lib/composer.d.ts +21 -0
- package/dist/pi/packages/ta-bots/lib/composer.js +104 -0
- package/dist/pi/packages/ta-bots/lib/connect-dialog.d.ts +18 -0
- package/dist/pi/packages/ta-bots/lib/connect-dialog.js +198 -0
- package/dist/pi/packages/ta-bots/lib/extension.d.ts +34 -0
- package/dist/pi/packages/ta-bots/lib/extension.js +207 -0
- package/dist/pi/packages/ta-bots/lib/host.d.ts +8 -0
- package/dist/pi/packages/ta-bots/lib/host.js +15 -0
- package/dist/pi/packages/ta-bots/lib/i18n.d.ts +87 -0
- package/dist/pi/packages/ta-bots/lib/i18n.js +175 -0
- package/dist/pi/packages/ta-bots/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-bots/lib/index.js +40 -0
- package/dist/pi/packages/ta-bots/lib/login-book.d.ts +17 -0
- package/dist/pi/packages/ta-bots/lib/login-book.js +55 -0
- package/dist/pi/packages/ta-bots/lib/media-crypto.d.ts +19 -0
- package/dist/pi/packages/ta-bots/lib/media-crypto.js +70 -0
- package/dist/pi/packages/ta-bots/lib/message.d.ts +13 -0
- package/dist/pi/packages/ta-bots/lib/message.js +74 -0
- package/dist/pi/packages/ta-bots/lib/page.d.ts +54 -0
- package/dist/pi/packages/ta-bots/lib/page.js +131 -0
- package/dist/pi/packages/ta-bots/lib/pictures.d.ts +3 -0
- package/dist/pi/packages/ta-bots/lib/pictures.js +21 -0
- package/dist/pi/packages/ta-bots/lib/qr-image.d.ts +16 -0
- package/dist/pi/packages/ta-bots/lib/qr-image.js +70 -0
- package/dist/pi/packages/ta-bots/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-bots/lib/react.js +8 -0
- package/dist/pi/packages/ta-bots/lib/server-texts.d.ts +12 -0
- package/dist/pi/packages/ta-bots/lib/server-texts.js +45 -0
- package/dist/pi/packages/ta-bots/lib/session-bridge.d.ts +43 -0
- package/dist/pi/packages/ta-bots/lib/session-bridge.js +118 -0
- package/dist/pi/packages/ta-bots/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-bots/lib/style.js +114 -0
- package/dist/pi/packages/ta-bots/lib/test-fakes.d.ts +37 -0
- package/dist/pi/packages/ta-bots/lib/test-fakes.js +94 -0
- package/dist/pi/packages/ta-bots/lib/text-util.d.ts +16 -0
- package/dist/pi/packages/ta-bots/lib/text-util.js +158 -0
- package/dist/pi/packages/ta-bots/lib/web-socket-client.d.ts +38 -0
- package/dist/pi/packages/ta-bots/lib/web-socket-client.js +213 -0
- package/dist/pi/packages/ta-bots/lib/wecom-channel.d.ts +38 -0
- package/dist/pi/packages/ta-bots/lib/wecom-channel.js +222 -0
- package/dist/pi/packages/ta-bots/lib/wecom-login.d.ts +34 -0
- package/dist/pi/packages/ta-bots/lib/wecom-login.js +84 -0
- package/dist/pi/packages/ta-bots/lib/wecom-socket.d.ts +74 -0
- package/dist/pi/packages/ta-bots/lib/wecom-socket.js +214 -0
- package/dist/pi/packages/ta-bots/lib/weixin-api.d.ts +112 -0
- package/dist/pi/packages/ta-bots/lib/weixin-api.js +171 -0
- package/dist/pi/packages/ta-bots/lib/weixin-channel.d.ts +49 -0
- package/dist/pi/packages/ta-bots/lib/weixin-channel.js +258 -0
- package/dist/pi/packages/ta-bots/lib/weixin-login.d.ts +31 -0
- package/dist/pi/packages/ta-bots/lib/weixin-login.js +110 -0
- package/dist/pi/packages/ta-bots/package.json +55 -0
- package/dist/pi/packages/ta-bots/web/index.js +1241 -0
- package/dist/pi/packages/ta-changes/lib/diff-tab.js +1 -1
- package/dist/pi/packages/ta-changes/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-changes/lib/style.js +12 -10
- package/dist/pi/packages/ta-changes/package.json +11 -2
- package/dist/pi/packages/ta-changes/web/index.js +16 -13
- package/dist/pi/packages/ta-channels/README.en.md +3 -2
- package/dist/pi/packages/ta-channels/README.md +3 -2
- package/dist/pi/packages/ta-channels/extension/index.mjs +109 -8
- package/dist/pi/packages/ta-channels/host/index.mjs +281 -5
- package/dist/pi/packages/ta-channels/lib/agent-menu.d.ts +2 -0
- package/dist/pi/packages/ta-channels/lib/agent-menu.js +19 -6
- package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts +2 -0
- package/dist/pi/packages/ta-channels/lib/channel-menu.js +15 -12
- package/dist/pi/packages/ta-channels/lib/channels-model.d.ts +10 -0
- package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +10 -0
- package/dist/pi/packages/ta-channels/lib/channels-util.js +29 -2
- package/dist/pi/packages/ta-channels/lib/channels.d.ts +2 -0
- package/dist/pi/packages/ta-channels/lib/channels.js +1 -0
- package/dist/pi/packages/ta-channels/lib/create.js +2 -2
- package/dist/pi/packages/ta-channels/lib/extension.d.ts +5 -0
- package/dist/pi/packages/ta-channels/lib/extension.js +25 -2
- package/dist/pi/packages/ta-channels/lib/i18n.d.ts +40 -9
- package/dist/pi/packages/ta-channels/lib/i18n.js +81 -19
- package/dist/pi/packages/ta-channels/lib/index.d.ts +3 -2
- package/dist/pi/packages/ta-channels/lib/index.js +14 -2
- package/dist/pi/packages/ta-channels/lib/members.js +10 -5
- package/dist/pi/packages/ta-channels/lib/more-menu.d.ts +5 -1
- package/dist/pi/packages/ta-channels/lib/more-menu.js +55 -9
- package/dist/pi/packages/ta-channels/lib/room.d.ts +11 -2
- package/dist/pi/packages/ta-channels/lib/room.js +47 -6
- package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +5 -1
- package/dist/pi/packages/ta-channels/lib/sidebar.js +189 -31
- package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/style.js +136 -73
- package/dist/pi/packages/ta-channels/lib/tasks.d.ts +48 -0
- package/dist/pi/packages/ta-channels/lib/tasks.js +226 -0
- package/dist/pi/packages/ta-channels/lib/team-ask.d.ts +21 -0
- package/dist/pi/packages/ta-channels/lib/team-ask.js +73 -0
- package/dist/pi/packages/ta-channels/lib/team-tools.d.ts +6 -1
- package/dist/pi/packages/ta-channels/lib/team-tools.js +5 -4
- package/dist/pi/packages/ta-channels/lib/team.d.ts +5 -1
- package/dist/pi/packages/ta-channels/lib/team.js +10 -4
- package/dist/pi/packages/ta-channels/lib/views.d.ts +18 -3
- package/dist/pi/packages/ta-channels/lib/views.js +40 -9
- package/dist/pi/packages/ta-channels/package.json +11 -2
- package/dist/pi/packages/ta-channels/web/index.js +992 -205
- package/dist/pi/packages/ta-computer-use/package.json +11 -2
- package/dist/pi/packages/ta-cron/README.en.md +3 -3
- package/dist/pi/packages/ta-cron/README.md +3 -3
- package/dist/pi/packages/ta-cron/host/index.mjs +19 -12
- package/dist/pi/packages/ta-cron/lib/editor.js +1 -3
- package/dist/pi/packages/ta-cron/lib/i18n.d.ts +2 -4
- package/dist/pi/packages/ta-cron/lib/i18n.js +4 -8
- package/dist/pi/packages/ta-cron/lib/index.js +11 -0
- package/dist/pi/packages/ta-cron/lib/next-card.d.ts +9 -0
- package/dist/pi/packages/ta-cron/lib/next-card.js +35 -0
- package/dist/pi/packages/ta-cron/lib/page.d.ts +3 -0
- package/dist/pi/packages/ta-cron/lib/page.js +4 -1
- package/dist/pi/packages/ta-cron/lib/pictures.d.ts +6 -0
- package/dist/pi/packages/ta-cron/lib/pictures.js +46 -0
- package/dist/pi/packages/ta-cron/lib/scheduler.d.ts +2 -0
- package/dist/pi/packages/ta-cron/lib/scheduler.js +24 -14
- package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-cron/lib/style.js +30 -44
- package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +4 -0
- package/dist/pi/packages/ta-cron/lib/tasks-view.js +36 -21
- package/dist/pi/packages/ta-cron/package.json +11 -2
- package/dist/pi/packages/ta-cron/web/index.js +249 -281
- package/dist/pi/packages/ta-extensions/README.en.md +4 -1
- package/dist/pi/packages/ta-extensions/README.md +4 -1
- package/dist/pi/packages/ta-extensions/host/index.mjs +64 -61
- package/dist/pi/packages/ta-extensions/lib/actions.d.ts +2 -0
- package/dist/pi/packages/ta-extensions/lib/actions.js +9 -1
- package/dist/pi/packages/ta-extensions/lib/host.d.ts +0 -8
- package/dist/pi/packages/ta-extensions/lib/host.js +7 -49
- package/dist/pi/packages/ta-extensions/lib/i18n.d.ts +8 -0
- package/dist/pi/packages/ta-extensions/lib/i18n.js +20 -4
- package/dist/pi/packages/ta-extensions/lib/index.js +2 -0
- package/dist/pi/packages/ta-extensions/lib/market-detail.js +14 -2
- package/dist/pi/packages/ta-extensions/lib/market-style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/market-style.js +18 -18
- package/dist/pi/packages/ta-extensions/lib/page.js +22 -11
- package/dist/pi/packages/ta-extensions/lib/pictures.d.ts +3 -1
- package/dist/pi/packages/ta-extensions/lib/pictures.js +28 -32
- package/dist/pi/packages/ta-extensions/lib/search.d.ts +10 -0
- package/dist/pi/packages/ta-extensions/lib/search.js +139 -0
- package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.js +15 -34
- package/dist/pi/packages/ta-extensions/package.json +12 -2
- package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +12 -8
- package/dist/pi/packages/ta-extensions/web/index.js +488 -120
- package/dist/pi/packages/ta-launcher/README.en.md +15 -0
- package/dist/pi/packages/ta-launcher/README.md +15 -0
- package/dist/pi/packages/ta-launcher/lib/actions.d.ts +31 -0
- package/dist/pi/packages/ta-launcher/lib/actions.js +134 -0
- package/dist/pi/packages/ta-launcher/lib/i18n.d.ts +38 -0
- package/dist/pi/packages/ta-launcher/lib/i18n.js +77 -0
- package/dist/pi/packages/ta-launcher/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-launcher/lib/index.js +48 -0
- package/dist/pi/packages/ta-launcher/lib/launcher-util.d.ts +19 -0
- package/dist/pi/packages/ta-launcher/lib/launcher-util.js +47 -0
- package/dist/pi/packages/ta-launcher/lib/launcher-view.d.ts +20 -0
- package/dist/pi/packages/ta-launcher/lib/launcher-view.js +99 -0
- package/dist/pi/packages/ta-launcher/lib/mine-store.d.ts +22 -0
- package/dist/pi/packages/ta-launcher/lib/mine-store.js +60 -0
- package/dist/pi/packages/ta-launcher/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-launcher/lib/react.js +8 -0
- package/dist/pi/packages/ta-launcher/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-launcher/lib/style.js +48 -0
- package/dist/pi/packages/ta-launcher/package.json +49 -0
- package/dist/pi/packages/ta-launcher/web/index.js +553 -0
- package/dist/pi/packages/ta-workspace/README.md +2 -2
- package/dist/pi/packages/ta-workspace/README.zh-cn.md +2 -2
- package/dist/pi/packages/ta-workspace/lib/common.d.ts +8 -5
- package/dist/pi/packages/ta-workspace/lib/common.js +53 -14
- package/dist/pi/packages/ta-workspace/lib/explorer-excluded.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/explorer-excluded.js +39 -0
- package/dist/pi/packages/ta-workspace/lib/explorer-transfer.d.ts +31 -0
- package/dist/pi/packages/ta-workspace/lib/explorer-transfer.js +156 -0
- package/dist/pi/packages/ta-workspace/lib/explorer.js +45 -153
- package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +10 -0
- package/dist/pi/packages/ta-workspace/lib/i18n.js +30 -10
- package/dist/pi/packages/ta-workspace/lib/open-files.js +1 -1
- package/dist/pi/packages/ta-workspace/lib/preview.js +6 -2
- package/dist/pi/packages/ta-workspace/lib/scm.js +4 -4
- package/dist/pi/packages/ta-workspace/lib/search.js +1 -1
- package/dist/pi/packages/ta-workspace/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-workspace/lib/style.js +100 -55
- package/dist/pi/packages/ta-workspace/lib/terminal.d.ts +24 -2
- package/dist/pi/packages/ta-workspace/lib/terminal.js +305 -43
- package/dist/pi/packages/ta-workspace/lib/util/terminal.d.ts +25 -0
- package/dist/pi/packages/ta-workspace/lib/util/terminal.js +55 -0
- package/dist/pi/packages/ta-workspace/lib/util/workspace.d.ts +3 -2
- package/dist/pi/packages/ta-workspace/lib/util/workspace.js +7 -3
- package/dist/pi/packages/ta-workspace/lib/workspace-client.d.ts +1 -1
- package/dist/pi/packages/ta-workspace/lib/workspace-client.js +2 -2
- package/dist/pi/packages/ta-workspace/package.json +11 -2
- package/dist/pi/packages/ta-workspace/web/index.js +913 -294
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-CNqfsCwx.js → abnfDiagram-S7VZAUFO-C1tb6dM5.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-_WaGq-Qk.js → architecture-WOLXFQ4H-DN1Va8BF.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-Bn63Lctu.js → architectureDiagram-YGSQEFNW-BmK2SYtQ.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-BGaAecnk.js → blockDiagram-APKKGZFW-DvLrLzTm.js} +1 -1
- package/dist/public/assets/{browser-DKagIN4Y.js → browser-DAv3ly6M.js} +1 -1
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-CK9Z_9Zp.js → c4Diagram-KJ2TOQU5-CrQlWwrG.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-H3j3MGva.js → chunk-6MUBBAK2-CHKMsuY_.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-Beljdjs9.js → chunk-AXFCVDMN-CWJ7Np6s.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-TYEV5wLO.js → chunk-BG4553SI-3v5XbQGM.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-gmWJrizf.js → chunk-DQASFODM-2CC-yiCz.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-BTa7yKXI.js → chunk-HFQBQIA3-D2hzQPAy.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-BlwMm4R0.js → chunk-KQLB2F66-SifAZs2r.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-CKTXjzwD.js → chunk-KS47KZWR-BP0C0VCC.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-Bn9Xkefl.js → chunk-LEVMRMFU-B1f5vw5b.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-B_QLqohG.js → chunk-M57EVK23-B2MCJt7Y.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-BflzJHPz.js → chunk-OY52VR5R-cDpZJMk4.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-BXucfaFg.js → chunk-QB3YPZ4I-BE0we2xc.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-CGwkwxm9.js → chunk-R3KSYZAL-D9wOfqqH.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-DQGOPuM5.js → chunk-STOXU5M4-BIaVsc0K.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-BCrs6AYI.js → chunk-TU62E6Q5-BZc0OZEM.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-MTv7nXJX.js → chunk-X4PVCEUW-Bngfwwzm.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-fPaX8VIb.js → chunk-XXDRQBXY-C5FQ6XHK.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-tm4uT08q.js → classDiagram-v2-L25IHNXF-_om54nmt.js} +1 -1
- package/dist/public/assets/{cose-bilkent-JH36ORCC-Dkk3pDZj.js → cose-bilkent-JH36ORCC-Dwpeee_6.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-CW_93VVD.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-BcoArW00.js → cynefinDiagram-L36ESFBY-DP5_y9Dq.js} +1 -1
- package/dist/public/assets/{d3-selection-BzUITLov.js → d3-selection-DFiMlEmn.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-oiU-wJxw.js → dagre-SPEB5RXH-DYwsk6gk.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-BwlCOIW4.js → diagram-3B7GL73J-Dq_nT3AZ.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-CZGQiFrl.js → diagram-DNEMPZML-ChURW6y9.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-BJGDa24C.js → diagram-L3MUGCDN-CgVp4Rto.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-DdwHRhnP.js → diagram-LA4NIPWU-vrqLMDby.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-IjreLUB9.js → diagram-MHCOC4E2-lvfOr5ij.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-CvaG0Zzq.js → diagram-XPFHEONP-oQ18TeVp.js} +1 -1
- package/dist/public/assets/{dist-Cm4zqoMA.js → dist-BOxxmveI.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-C-FOI67M.js → ebnfDiagram-UZSYDL2S-C7_tlZCS.js} +1 -1
- package/dist/public/assets/{editor.api-hteKufWf.js → editor.api-CoZ8MEuz.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-C_ClfkLy.js → elk-XV6XMXQE-Dkt5-ikg.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-DSr0aRYm.js → erDiagram-EYBAPDEH-27kh3zlx.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-COU_atV6.js → eventmodeling-K75KTNOO-CxVEejjN.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-BRowRdve.js +1 -0
- package/dist/public/assets/{freemarker2-CBJnhymu.js → freemarker2-D6CwPIXh.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-BAcXXNjI.js → ganttDiagram-23REXITY-C-amlwpX.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BGmojXlx.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW-Bk9sns6k.js → gitGraphDiagram-STJD7YCW-DKhzI0Xz.js} +1 -1
- package/dist/public/assets/{handlebars-CiqYW1im.js → handlebars-mxNr68Gm.js} +1 -1
- package/dist/public/assets/{html-kafkm1Z0.js → html-Bze6s9R9.js} +1 -1
- package/dist/public/assets/{index-DPLd0-lb.js → index-BhQUc9PU.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-CRRVgGj2.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-2hRQLVWa.js → infoDiagram-KBXO4MBG-WHuWjEDO.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-hrOnhWJs.js → ishikawaDiagram-M35NCXHK-DFHUwD0J.js} +1 -1
- package/dist/public/assets/{javascript-Dt5MiA9w.js → javascript-4NMPu7y1.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-d8HJd04q.js → journeyDiagram-OPLOXDXO-C7gV6zEr.js} +1 -1
- package/dist/public/assets/{jsonMode-DBICoo6P.js → jsonMode-B1JEHPMp.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-DOUuZDiv.js → kanban-definition-BZKZHSQY-DlRu_d2Q.js} +1 -1
- package/dist/public/assets/{liquid-BGYhBP2h.js → liquid-B7sIf4NX.js} +1 -1
- package/dist/public/assets/{mdx-Ct_gzcP3.js → mdx-CAN0qez6.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-2yhxYNxq.js → mermaid-parser.core-BGmotBhf.js} +3 -3
- package/dist/public/assets/{mermaid.core-sx7teU8z.js → mermaid.core-Cl6SS3cM.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-DIc9LejH.js → mindmap-definition-I2QAS2VK-DiQ8Feqr.js} +1 -1
- package/dist/public/assets/module-1nDbf1AK.js +1761 -0
- package/dist/public/assets/module-BkKfSTDV.js +1 -0
- package/dist/public/assets/{monaco-DJecWyyV.js → monaco-CwCjTWAO.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-DUlqTCWQ.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-BfiT6-Vx.js → pegDiagram-FD4XPPHP-XhCpv6BX.js} +1 -1
- package/dist/public/assets/pie-XZMESJXO-2RgP4ScO.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-DJ0sF_Eg.js → pieDiagram-J4AKIIQI-DUVzuXUd.js} +1 -1
- package/dist/public/assets/{python-BrnocsK9.js → python-DsoF66Sp.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2-C3iF5PG6.js → quadrantDiagram-XTYBLID2-Ddobf0z0.js} +1 -1
- package/dist/public/assets/radar-ABXABTNO-Dap8k-yH.js +1 -0
- package/dist/public/assets/railroad-I3PHUGI6-Ds10NBze.js +1 -0
- package/dist/public/assets/{railroad-abnf-LNEFI6M7-BI4N-mtq.js → railroad-abnf-LNEFI6M7-DkrNo-Gf.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-Ck2MUlyV.js → railroad-ebnf-DWYD2UWJ-DaB7gY8P.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-Cuc9S0f4.js → railroad-peg-JR7BVNR7-D_QG87QV.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-Cw24sb_5.js → railroadDiagram-MRQ6NCDL-x-nUoBjv.js} +1 -1
- package/dist/public/assets/{razor-BDHTAmlI.js → razor-DSrcJyQe.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-QQUXFr1R.js → requirementDiagram-Y7LWUY3S-kNNcbsty.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-WGJFYUXA-mSlfAHND.js → sankeyDiagram-WGJFYUXA-ClC12Odk.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-3t8hVott.js → sequenceDiagram-5NDRBG5M-DDQITP2g.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-9EW807AL.js → stateDiagram-v2-FJ4FJNEA-N1t_36oh.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-EbMBX_e0.js → swimlanes-UMQ2AFYF-DSt9fFYE.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-BHAN4SQO.js +8 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-D14kjjsp.js → timeline-definition-SEUHKTQE-CfymOw_s.js} +1 -1
- package/dist/public/assets/treeView-D4JQ5SDB-f1hLUBjI.js +1 -0
- package/dist/public/assets/treemap-SAJKECNS-_NPRpuUC.js +1 -0
- package/dist/public/assets/{typescript-BEEbbq69.js → typescript-J7rF-zX8.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-DKemtzU9.js → usecaseDiagram-AFA6YXN4-CK_mRc2_.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-DOBq9oeY.js → vennDiagram-NNMJR3RB-DW8xR6IJ.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-CLBqtefx.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-DquSJ4y-.js → wardleyDiagram-S7YFUSEH-Css55Zq5.js} +1 -1
- package/dist/public/assets/{xml-DvTQKQ_W.js → xml-CJeviG_a.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-ClE_9jz4.js → xychartDiagram-GGNKY7IX-BnhK9cFS.js} +1 -1
- package/dist/public/assets/{yaml-ffiFfPtJ.js → yaml-Gw3uo6rF.js} +1 -1
- package/dist/public/index.html +35 -6
- package/dist/public/launch.svg +49 -0
- package/dist/serve/index.mjs +3693 -889
- package/package.json +25 -22
- package/dist/pi/packages/ta-agents/fixtures/fake-acp-agent.mjs +0 -183
- package/dist/pi/packages/ta-agents/lib/acp-agent.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/acp-agent.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/acp-protocol.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/acp-protocol.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-bindings.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-bindings.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-catalog.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-prompt.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-session.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-session.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-streamer.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-streamer.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-tool.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-tool.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-turn.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/agent-turn.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/extension.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/extension.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/json-rpc.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/json-rpc.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/message-stream.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/message-stream.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/pi-types.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/pi-types.js.map +0 -1
- package/dist/pi/packages/ta-agents/lib/texts.d.ts.map +0 -1
- package/dist/pi/packages/ta-agents/lib/texts.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/blob-store.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/blob-store.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/card.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/card.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-protocol.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-protocol.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-service.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-service.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/changes-util.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/diff-tab.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/diff-tab.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/extension.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/extension.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/host.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/host.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/i18n.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/i18n.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/index.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/index.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/line-diff.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/line-diff.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/page.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/page.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/react.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/react.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/recorder.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/recorder.js.map +0 -1
- package/dist/pi/packages/ta-changes/lib/style.d.ts.map +0 -1
- package/dist/pi/packages/ta-changes/lib/style.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/agent-menu.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/agent-menu.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels-model.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels-model.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels-util.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/channels.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/create.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/create.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/extension.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/extension.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/faces.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/faces.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/host.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/host.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/i18n.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/i18n.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/index.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/index.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/members.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/members.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/more-menu.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/more-menu.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/react.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/react.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/room.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/room.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/sidebar.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/sidebar.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/style.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/style.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/team-tools.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/team-tools.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/team.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/team.js.map +0 -1
- package/dist/pi/packages/ta-channels/lib/views.d.ts.map +0 -1
- package/dist/pi/packages/ta-channels/lib/views.js.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver-access.d.ts.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver-access.js.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver-daemon.d.ts.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver-daemon.js.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver.d.ts.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/cua-driver.js.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/extension.d.ts.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/extension.js.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/pi-types.d.ts.map +0 -1
- package/dist/pi/packages/ta-computer-use/lib/pi-types.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/commands.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/commands.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/cron-expression.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/cron-expression.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/cron-protocol.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/editor.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/editor.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/extension.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/extension.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/form-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/form-util.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/host.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/host.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/i18n.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/i18n.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/index.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/index.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/model-picker.d.ts +0 -33
- package/dist/pi/packages/ta-cron/lib/model-picker.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/model-picker.js +0 -178
- package/dist/pi/packages/ta-cron/lib/model-picker.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/notifier.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/notifier.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/page.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/page.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/react.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/react.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/reply.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/reply.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/schedule-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/schedule-util.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/scheduler.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/scheduler.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/server-texts.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/server-texts.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/style.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/style.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/task-store.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/task-store.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/task-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/task-util.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/tasks-view.js.map +0 -1
- package/dist/pi/packages/ta-cron/lib/tool.d.ts.map +0 -1
- package/dist/pi/packages/ta-cron/lib/tool.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/actions.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/actions.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/archive.d.ts +0 -30
- package/dist/pi/packages/ta-extensions/lib/archive.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/archive.js +0 -213
- package/dist/pi/packages/ta-extensions/lib/archive.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/context.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/context.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/extensions-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/extensions-util.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/host.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/host.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/i18n.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/i18n.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/import-dialog.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/import-dialog.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/index.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/index.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-detail.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-detail.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-parts.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-parts.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-store.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-store.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-style.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-style.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-util.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-util.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-view.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market-view.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/market.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/page.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/page.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/pictures.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/pictures.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/react.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/react.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/signal.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/signal.js.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/style.d.ts.map +0 -1
- package/dist/pi/packages/ta-extensions/lib/style.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-agent.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-agent.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-common.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-common.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-import.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-import.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-webview.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser-webview.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/browser.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/common.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/common.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/editors.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/editors.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/explorer.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/explorer.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/file-icon.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/file-icon.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/host.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/host.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/i18n.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/i18n.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/index.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/index.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/open-files.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/open-files.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/preview.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/preview.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/react.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/react.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/scm.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/scm.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/search.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/search.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/style.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/style.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/terminal.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/terminal.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/browser-snapshot.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/browser-snapshot.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/file-icon.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/file-icon.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/git.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/git.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/preview.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/preview.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/search.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/search.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/seti-font.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/seti-font.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/seti.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/seti.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/upload.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/upload.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/workspace.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/workspace.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/zip.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/util/zip.js.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/workspace-client.d.ts.map +0 -1
- package/dist/pi/packages/ta-workspace/lib/workspace-client.js.map +0 -1
- package/dist/pi/packages/ta-workspace/scripts/seti.ts +0 -173
- package/dist/public/assets/cynefin-EF2NZ3EQ-D_QV_BJg.js +0 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-QGLBPpjQ.js +0 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-ByODkoVe.js +0 -1
- package/dist/public/assets/info-OHQRW6UA-BMphWS2h.js +0 -1
- package/dist/public/assets/module-BX2fJibj.js +0 -1124
- package/dist/public/assets/module-N1D-AOa6.js +0 -1
- package/dist/public/assets/packet-JDAUHWVQ-Ca8klABu.js +0 -1
- package/dist/public/assets/pie-XZMESJXO-B-SN2eCI.js +0 -1
- package/dist/public/assets/radar-ABXABTNO-DzDnNRnq.js +0 -1
- package/dist/public/assets/railroad-I3PHUGI6-7QAv0_1N.js +0 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CIFqDFf2.js +0 -8
- package/dist/public/assets/treeView-D4JQ5SDB-cznq7PJK.js +0 -1
- package/dist/public/assets/treemap-SAJKECNS-CBYUiQGU.js +0 -1
- package/dist/public/assets/wardley-7MLQ67FV-DV8bp8Ml.js +0 -1
package/dist/gateway.mjs
ADDED
|
@@ -0,0 +1,2812 @@
|
|
|
1
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-cli.js
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join as join6 } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-server.js
|
|
7
|
+
import { createReadStream, existsSync as existsSync2, mkdirSync as mkdirSync4, statSync } from "node:fs";
|
|
8
|
+
import { createServer as createServer2, request as httpRequest } from "node:http";
|
|
9
|
+
import { request as httpsRequest } from "node:https";
|
|
10
|
+
import { extname, join as join5, normalize, sep } from "node:path";
|
|
11
|
+
|
|
12
|
+
// ../../packages/rpc/esm/node/websocket/websocket-connection.js
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
// ../../packages/core/esm/common/utils/event.js
|
|
16
|
+
var Event;
|
|
17
|
+
(function(Event2) {
|
|
18
|
+
const _disposable = { dispose() {} };
|
|
19
|
+
Event2.None = Object.assign(function() {
|
|
20
|
+
return _disposable;
|
|
21
|
+
}, {
|
|
22
|
+
get maxListeners() {
|
|
23
|
+
return 0;
|
|
24
|
+
},
|
|
25
|
+
set maxListeners(maxListeners) {}
|
|
26
|
+
});
|
|
27
|
+
function map(event, mapFunc) {
|
|
28
|
+
return Object.assign((listener, thisArgs, disposables) => event((i) => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
|
|
29
|
+
maxListeners: 0
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
Event2.map = map;
|
|
33
|
+
})(Event || (Event = {}));
|
|
34
|
+
|
|
35
|
+
class CallbackList {
|
|
36
|
+
get length() {
|
|
37
|
+
return this._callbacks && this._callbacks.length || 0;
|
|
38
|
+
}
|
|
39
|
+
add(callback, context = undefined, bucket) {
|
|
40
|
+
if (!this._callbacks) {
|
|
41
|
+
this._callbacks = [];
|
|
42
|
+
this._contexts = [];
|
|
43
|
+
}
|
|
44
|
+
this._callbacks.push(callback);
|
|
45
|
+
this._contexts.push(context);
|
|
46
|
+
if (Array.isArray(bucket)) {
|
|
47
|
+
bucket.push({ dispose: () => this.remove(callback, context) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
remove(callback, context = undefined) {
|
|
51
|
+
if (!this._callbacks) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let foundCallbackWithDifferentContext = false;
|
|
55
|
+
for (let i = 0;i < this._callbacks.length; i++) {
|
|
56
|
+
if (this._callbacks[i] === callback) {
|
|
57
|
+
if (this._contexts[i] === context) {
|
|
58
|
+
this._callbacks.splice(i, 1);
|
|
59
|
+
this._contexts.splice(i, 1);
|
|
60
|
+
return;
|
|
61
|
+
} else {
|
|
62
|
+
foundCallbackWithDifferentContext = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (foundCallbackWithDifferentContext) {
|
|
67
|
+
throw new Error("When adding a listener with a context, you should remove it with the same context");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
*[Symbol.iterator]() {
|
|
71
|
+
if (!this._callbacks) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const callbacks = this._callbacks.slice(0);
|
|
75
|
+
const contexts = this._contexts.slice(0);
|
|
76
|
+
for (let i = 0;i < callbacks.length; i++) {
|
|
77
|
+
const callback = callbacks[i];
|
|
78
|
+
const context = contexts[i];
|
|
79
|
+
yield (...args) => callback.apply(context, args);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
invoke(...args) {
|
|
83
|
+
if (!this._callbacks) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const callbacks = this._callbacks.slice(0);
|
|
87
|
+
const contexts = this._contexts.slice(0);
|
|
88
|
+
const ret = [];
|
|
89
|
+
for (let i = 0;i < callbacks.length; i++) {
|
|
90
|
+
try {
|
|
91
|
+
ret.push(callbacks[i].apply(contexts[i], args));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.error(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
isEmpty() {
|
|
99
|
+
return !this._callbacks || this._callbacks.length === 0;
|
|
100
|
+
}
|
|
101
|
+
dispose() {
|
|
102
|
+
this._callbacks = undefined;
|
|
103
|
+
this._contexts = undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ../../packages/core/esm/common/utils/emitter.js
|
|
108
|
+
class Emitter {
|
|
109
|
+
constructor(_options) {
|
|
110
|
+
this._options = _options;
|
|
111
|
+
this._disposed = false;
|
|
112
|
+
this._leakWarnCountdown = 0;
|
|
113
|
+
}
|
|
114
|
+
get event() {
|
|
115
|
+
if (!this._event) {
|
|
116
|
+
this._event = Object.assign((listener, thisArgs, disposables) => {
|
|
117
|
+
if (!this._callbacks) {
|
|
118
|
+
this._callbacks = new CallbackList;
|
|
119
|
+
}
|
|
120
|
+
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
|
|
121
|
+
this._options.onFirstListenerAdd(this);
|
|
122
|
+
}
|
|
123
|
+
this._callbacks.add(listener, thisArgs);
|
|
124
|
+
const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
|
|
125
|
+
const result = {
|
|
126
|
+
dispose: () => {
|
|
127
|
+
if (removeMaxListenersCheck) {
|
|
128
|
+
removeMaxListenersCheck();
|
|
129
|
+
}
|
|
130
|
+
result.dispose = Emitter._noop;
|
|
131
|
+
if (!this._disposed) {
|
|
132
|
+
this._callbacks.remove(listener, thisArgs);
|
|
133
|
+
result.dispose = Emitter._noop;
|
|
134
|
+
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
|
|
135
|
+
this._options.onLastListenerRemove(this);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
if (Array.isArray(disposables)) {
|
|
141
|
+
disposables.push(result);
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}, {
|
|
145
|
+
maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return this._event;
|
|
149
|
+
}
|
|
150
|
+
checkMaxListeners(maxListeners) {
|
|
151
|
+
if (maxListeners === 0 || !this._callbacks) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const listenerCount = this._callbacks.length;
|
|
155
|
+
if (listenerCount <= maxListeners) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const popStack = this.pushLeakingStack();
|
|
159
|
+
this._leakWarnCountdown -= 1;
|
|
160
|
+
if (this._leakWarnCountdown <= 0) {
|
|
161
|
+
this._leakWarnCountdown = maxListeners * 0.5;
|
|
162
|
+
let topStack;
|
|
163
|
+
let topCount = 0;
|
|
164
|
+
this._leakingStacks.forEach((stackCount, stack) => {
|
|
165
|
+
if (!topStack || topCount < stackCount) {
|
|
166
|
+
topStack = stack;
|
|
167
|
+
topCount = stackCount;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
|
|
171
|
+
console.warn(topStack);
|
|
172
|
+
}
|
|
173
|
+
return popStack;
|
|
174
|
+
}
|
|
175
|
+
pushLeakingStack() {
|
|
176
|
+
if (!this._leakingStacks) {
|
|
177
|
+
this._leakingStacks = new Map;
|
|
178
|
+
}
|
|
179
|
+
const stack = new Error().stack.split(`
|
|
180
|
+
`).slice(3).join(`
|
|
181
|
+
`);
|
|
182
|
+
const count = this._leakingStacks.get(stack) || 0;
|
|
183
|
+
this._leakingStacks.set(stack, count + 1);
|
|
184
|
+
return () => this.popLeakingStack(stack);
|
|
185
|
+
}
|
|
186
|
+
popLeakingStack(stack) {
|
|
187
|
+
if (!this._leakingStacks) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const count = this._leakingStacks.get(stack) || 0;
|
|
191
|
+
this._leakingStacks.set(stack, count - 1);
|
|
192
|
+
}
|
|
193
|
+
get hasListeners() {
|
|
194
|
+
return !!this._callbacks && !this._callbacks.isEmpty();
|
|
195
|
+
}
|
|
196
|
+
fire(event) {
|
|
197
|
+
if (this._callbacks) {
|
|
198
|
+
this._callbacks.invoke(event);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async sequence(processor) {
|
|
202
|
+
if (this._callbacks) {
|
|
203
|
+
for (const listener of this._callbacks) {
|
|
204
|
+
if (!await processor(listener)) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
dispose() {
|
|
211
|
+
if (this._leakingStacks) {
|
|
212
|
+
this._leakingStacks.clear();
|
|
213
|
+
this._leakingStacks = undefined;
|
|
214
|
+
}
|
|
215
|
+
if (this._callbacks) {
|
|
216
|
+
this._callbacks.dispose();
|
|
217
|
+
this._callbacks = undefined;
|
|
218
|
+
}
|
|
219
|
+
this._disposed = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
Emitter.LEAK_WARNING_THRESHHOLD = 175;
|
|
223
|
+
Emitter._noop = function() {};
|
|
224
|
+
var WaitUntilEvent;
|
|
225
|
+
(function(WaitUntilEvent2) {
|
|
226
|
+
async function fire(emitter, event, timeout = undefined) {
|
|
227
|
+
const waitables = [];
|
|
228
|
+
const asyncEvent = Object.assign(event, {
|
|
229
|
+
waitUntil: (thenable) => {
|
|
230
|
+
if (Object.isFrozen(waitables)) {
|
|
231
|
+
throw new Error("waitUntil cannot be called asynchronously.");
|
|
232
|
+
}
|
|
233
|
+
waitables.push(thenable);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
try {
|
|
237
|
+
emitter.fire(asyncEvent);
|
|
238
|
+
Object.freeze(waitables);
|
|
239
|
+
} finally {
|
|
240
|
+
delete asyncEvent["waitUntil"];
|
|
241
|
+
}
|
|
242
|
+
if (!waitables.length) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (timeout !== undefined) {
|
|
246
|
+
await Promise.race([Promise.all(waitables), new Promise((resolve) => setTimeout(resolve, timeout))]);
|
|
247
|
+
} else {
|
|
248
|
+
await Promise.all(waitables);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
WaitUntilEvent2.fire = fire;
|
|
252
|
+
})(WaitUntilEvent || (WaitUntilEvent = {}));
|
|
253
|
+
|
|
254
|
+
// ../../packages/rpc/esm/node/websocket/websocket-frames.js
|
|
255
|
+
class WebSocketProtocolError extends Error {
|
|
256
|
+
constructor(code, message) {
|
|
257
|
+
super(message);
|
|
258
|
+
this.code = code;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
var WebSocketFrames;
|
|
262
|
+
(function(WebSocketFrames2) {
|
|
263
|
+
WebSocketFrames2.CONTINUATION = 0;
|
|
264
|
+
WebSocketFrames2.TEXT = 1;
|
|
265
|
+
WebSocketFrames2.BINARY = 2;
|
|
266
|
+
WebSocketFrames2.CLOSE = 8;
|
|
267
|
+
WebSocketFrames2.PING = 9;
|
|
268
|
+
WebSocketFrames2.PONG = 10;
|
|
269
|
+
function encode(opcode, payload = Buffer.alloc(0)) {
|
|
270
|
+
const length = payload.length;
|
|
271
|
+
const size = length < 126 ? 2 : length < 65536 ? 4 : 10;
|
|
272
|
+
const header = Buffer.alloc(size);
|
|
273
|
+
header[0] = 128 | opcode;
|
|
274
|
+
if (length < 126) {
|
|
275
|
+
header[1] = length;
|
|
276
|
+
} else if (length < 65536) {
|
|
277
|
+
header[1] = 126;
|
|
278
|
+
header.writeUInt16BE(length, 2);
|
|
279
|
+
} else {
|
|
280
|
+
header[1] = 127;
|
|
281
|
+
header.writeUInt32BE(Math.floor(length / 4294967296), 2);
|
|
282
|
+
header.writeUInt32BE(length >>> 0, 6);
|
|
283
|
+
}
|
|
284
|
+
return Buffer.concat([header, payload]);
|
|
285
|
+
}
|
|
286
|
+
WebSocketFrames2.encode = encode;
|
|
287
|
+
function closePayload(code, reason = "") {
|
|
288
|
+
const text = Buffer.from(reason).subarray(0, 123);
|
|
289
|
+
const payload = Buffer.alloc(2 + text.length);
|
|
290
|
+
payload.writeUInt16BE(code, 0);
|
|
291
|
+
text.copy(payload, 2);
|
|
292
|
+
return payload;
|
|
293
|
+
}
|
|
294
|
+
WebSocketFrames2.closePayload = closePayload;
|
|
295
|
+
function isControl(opcode) {
|
|
296
|
+
return (opcode & 8) !== 0;
|
|
297
|
+
}
|
|
298
|
+
WebSocketFrames2.isControl = isControl;
|
|
299
|
+
})(WebSocketFrames || (WebSocketFrames = {}));
|
|
300
|
+
|
|
301
|
+
class WebSocketFrameParser {
|
|
302
|
+
constructor(maxPayload) {
|
|
303
|
+
this.maxPayload = maxPayload;
|
|
304
|
+
this.buffer = Buffer.alloc(0);
|
|
305
|
+
}
|
|
306
|
+
push(chunk) {
|
|
307
|
+
this.buffer = this.buffer.length ? Buffer.concat([this.buffer, chunk]) : chunk;
|
|
308
|
+
const frames = [];
|
|
309
|
+
for (let frame = this.next();frame; frame = this.next()) {
|
|
310
|
+
frames.push(frame);
|
|
311
|
+
}
|
|
312
|
+
return frames;
|
|
313
|
+
}
|
|
314
|
+
next() {
|
|
315
|
+
const buffer = this.buffer;
|
|
316
|
+
if (buffer.length < 2) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const fin = (buffer[0] & 128) !== 0;
|
|
320
|
+
const opcode = buffer[0] & 15;
|
|
321
|
+
if ((buffer[0] & 112) !== 0) {
|
|
322
|
+
throw new WebSocketProtocolError(1002, "Reserved bits are set.");
|
|
323
|
+
}
|
|
324
|
+
if (![0, 1, 2, 8, 9, 10].includes(opcode)) {
|
|
325
|
+
throw new WebSocketProtocolError(1002, `Unknown opcode ${opcode}.`);
|
|
326
|
+
}
|
|
327
|
+
if ((buffer[1] & 128) === 0) {
|
|
328
|
+
throw new WebSocketProtocolError(1002, "Frames of a client must be masked.");
|
|
329
|
+
}
|
|
330
|
+
let length = buffer[1] & 127;
|
|
331
|
+
let offset = 2;
|
|
332
|
+
if (length === 126) {
|
|
333
|
+
if (buffer.length < 4) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
length = buffer.readUInt16BE(2);
|
|
337
|
+
offset = 4;
|
|
338
|
+
} else if (length === 127) {
|
|
339
|
+
if (buffer.length < 10) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const high = buffer.readUInt32BE(2);
|
|
343
|
+
if (high > 2097151) {
|
|
344
|
+
throw new WebSocketProtocolError(1009, "The frame is too large.");
|
|
345
|
+
}
|
|
346
|
+
length = high * 4294967296 + buffer.readUInt32BE(6);
|
|
347
|
+
offset = 10;
|
|
348
|
+
}
|
|
349
|
+
if (WebSocketFrames.isControl(opcode) && (length > 125 || !fin)) {
|
|
350
|
+
throw new WebSocketProtocolError(1002, "Control frames are at most 125 bytes and not fragmented.");
|
|
351
|
+
}
|
|
352
|
+
if (length > this.maxPayload) {
|
|
353
|
+
throw new WebSocketProtocolError(1009, `The message is larger than ${this.maxPayload} bytes.`);
|
|
354
|
+
}
|
|
355
|
+
if (buffer.length < offset + 4 + length) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const mask = buffer.subarray(offset, offset + 4);
|
|
359
|
+
const payload = Buffer.from(buffer.subarray(offset + 4, offset + 4 + length));
|
|
360
|
+
for (let i = 0;i < payload.length; i++) {
|
|
361
|
+
payload[i] ^= mask[i & 3];
|
|
362
|
+
}
|
|
363
|
+
this.buffer = buffer.subarray(offset + 4 + length);
|
|
364
|
+
return { fin, opcode, payload };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ../../packages/rpc/esm/node/websocket/websocket-connection.js
|
|
369
|
+
class WebSocketConnection {
|
|
370
|
+
static runtimeSupported(bunVersion) {
|
|
371
|
+
var _a;
|
|
372
|
+
var _b;
|
|
373
|
+
if (bunVersion === undefined) {
|
|
374
|
+
bunVersion = (_b = (_a = globalThis.Bun) === null || _a === undefined ? undefined : _a.version) !== null && _b !== undefined ? _b : null;
|
|
375
|
+
}
|
|
376
|
+
if (bunVersion === null) {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
const [major, minor] = bunVersion.split(".").map(Number);
|
|
380
|
+
return major > 1 || major === 1 && minor >= 4;
|
|
381
|
+
}
|
|
382
|
+
static check(request) {
|
|
383
|
+
var _a, _b;
|
|
384
|
+
const upgrade = String((_a = request.headers.upgrade) !== null && _a !== undefined ? _a : "").toLowerCase();
|
|
385
|
+
const connection = String((_b = request.headers.connection) !== null && _b !== undefined ? _b : "").toLowerCase();
|
|
386
|
+
const key = request.headers["sec-websocket-key"];
|
|
387
|
+
if (request.method !== "GET" || upgrade !== "websocket" || !connection.includes("upgrade")) {
|
|
388
|
+
return { status: 400, message: "Not a WebSocket upgrade request." };
|
|
389
|
+
}
|
|
390
|
+
if (request.headers["sec-websocket-version"] !== "13") {
|
|
391
|
+
return { status: 426, message: "Only WebSocket version 13 is supported." };
|
|
392
|
+
}
|
|
393
|
+
if (typeof key !== "string" || Buffer.from(key, "base64").length !== 16) {
|
|
394
|
+
return { status: 400, message: "Missing or invalid Sec-WebSocket-Key." };
|
|
395
|
+
}
|
|
396
|
+
return { key };
|
|
397
|
+
}
|
|
398
|
+
static accept(key) {
|
|
399
|
+
return createHash("sha1").update(key + WebSocketConnection.GUID).digest("base64");
|
|
400
|
+
}
|
|
401
|
+
static open(socket, key, head, options) {
|
|
402
|
+
socket.write(`HTTP/1.1 101 Switching Protocols\r
|
|
403
|
+
Upgrade: websocket\r
|
|
404
|
+
Connection: Upgrade\r
|
|
405
|
+
Sec-WebSocket-Accept: ${WebSocketConnection.accept(key)}\r
|
|
406
|
+
\r
|
|
407
|
+
`);
|
|
408
|
+
const connection = new WebSocketConnection(socket, options);
|
|
409
|
+
connection.start(head);
|
|
410
|
+
return connection;
|
|
411
|
+
}
|
|
412
|
+
static refuse(socket, status, message) {
|
|
413
|
+
socket.on("error", () => socket.destroy());
|
|
414
|
+
socket.end(`HTTP/1.1 ${status} ${message}\r
|
|
415
|
+
Connection: close\r
|
|
416
|
+
Content-Type: text/plain\r
|
|
417
|
+
Content-Length: ${Buffer.byteLength(message)}\r
|
|
418
|
+
\r
|
|
419
|
+
${message}`);
|
|
420
|
+
}
|
|
421
|
+
constructor(socket, options) {
|
|
422
|
+
this.socket = socket;
|
|
423
|
+
this.options = options;
|
|
424
|
+
this.onMessageEmitter = new Emitter;
|
|
425
|
+
this.onCloseEmitter = new Emitter;
|
|
426
|
+
this.decoder = new TextDecoder("utf-8", { fatal: true });
|
|
427
|
+
this.fragments = [];
|
|
428
|
+
this.fragmentsLength = 0;
|
|
429
|
+
this.state = "open";
|
|
430
|
+
this.alive = true;
|
|
431
|
+
this.parser = new WebSocketFrameParser(options.maxPayload);
|
|
432
|
+
}
|
|
433
|
+
get onMessage() {
|
|
434
|
+
return this.onMessageEmitter.event;
|
|
435
|
+
}
|
|
436
|
+
get onClose() {
|
|
437
|
+
return this.onCloseEmitter.event;
|
|
438
|
+
}
|
|
439
|
+
get open() {
|
|
440
|
+
return this.state === "open";
|
|
441
|
+
}
|
|
442
|
+
send(text) {
|
|
443
|
+
if (this.state === "open") {
|
|
444
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.TEXT, Buffer.from(text)));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
close(code = 1000, reason = "") {
|
|
448
|
+
var _a, _b;
|
|
449
|
+
if (this.state !== "open") {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.state = "closing";
|
|
453
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.CLOSE, WebSocketFrames.closePayload(code, reason)));
|
|
454
|
+
(_b = (_a = setTimeout(() => this.socket.destroy(), 1000)).unref) === null || _b === undefined || _b.call(_a);
|
|
455
|
+
this.finish(code, reason);
|
|
456
|
+
}
|
|
457
|
+
start(head) {
|
|
458
|
+
var _a, _b;
|
|
459
|
+
this.socket.on("data", (chunk) => this.receive(chunk));
|
|
460
|
+
this.socket.on("close", () => this.finish(1006, ""));
|
|
461
|
+
this.socket.on("error", () => this.socket.destroy());
|
|
462
|
+
if (this.options.heartbeat > 0) {
|
|
463
|
+
this.heartbeat = setInterval(() => {
|
|
464
|
+
if (!this.alive) {
|
|
465
|
+
this.socket.destroy();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
this.alive = false;
|
|
469
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.PING));
|
|
470
|
+
}, this.options.heartbeat);
|
|
471
|
+
(_b = (_a = this.heartbeat).unref) === null || _b === undefined || _b.call(_a);
|
|
472
|
+
}
|
|
473
|
+
if (head.length) {
|
|
474
|
+
this.receive(head);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
receive(chunk) {
|
|
478
|
+
try {
|
|
479
|
+
for (const frame of this.parser.push(chunk)) {
|
|
480
|
+
this.alive = true;
|
|
481
|
+
this.handle(frame.opcode, frame.fin, frame.payload);
|
|
482
|
+
}
|
|
483
|
+
} catch (error) {
|
|
484
|
+
this.close(error instanceof WebSocketProtocolError ? error.code : 1011, error instanceof Error ? error.message : "");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
handle(opcode, fin, payload) {
|
|
488
|
+
switch (opcode) {
|
|
489
|
+
case WebSocketFrames.PING:
|
|
490
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.PONG, payload));
|
|
491
|
+
return;
|
|
492
|
+
case WebSocketFrames.PONG:
|
|
493
|
+
return;
|
|
494
|
+
case WebSocketFrames.CLOSE: {
|
|
495
|
+
const code = payload.length >= 2 ? payload.readUInt16BE(0) : 1005;
|
|
496
|
+
if (this.state === "open") {
|
|
497
|
+
this.state = "closing";
|
|
498
|
+
this.socket.end(WebSocketFrames.encode(WebSocketFrames.CLOSE, payload.subarray(0, 2)));
|
|
499
|
+
} else {
|
|
500
|
+
this.socket.end();
|
|
501
|
+
}
|
|
502
|
+
this.finish(code, payload.subarray(2).toString());
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
case WebSocketFrames.BINARY:
|
|
506
|
+
throw new WebSocketProtocolError(1003, "Only text messages are accepted.");
|
|
507
|
+
case WebSocketFrames.TEXT:
|
|
508
|
+
if (this.fragments.length) {
|
|
509
|
+
throw new WebSocketProtocolError(1002, "A new message started inside a fragmented one.");
|
|
510
|
+
}
|
|
511
|
+
break;
|
|
512
|
+
case WebSocketFrames.CONTINUATION:
|
|
513
|
+
if (!this.fragments.length) {
|
|
514
|
+
throw new WebSocketProtocolError(1002, "A continuation frame without a message.");
|
|
515
|
+
}
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
this.fragmentsLength += payload.length;
|
|
519
|
+
if (this.fragmentsLength > this.options.maxPayload) {
|
|
520
|
+
throw new WebSocketProtocolError(1009, `The message is larger than ${this.options.maxPayload} bytes.`);
|
|
521
|
+
}
|
|
522
|
+
this.fragments.push(payload);
|
|
523
|
+
if (fin) {
|
|
524
|
+
const message = this.fragments.length === 1 ? this.fragments[0] : Buffer.concat(this.fragments);
|
|
525
|
+
this.fragments = [];
|
|
526
|
+
this.fragmentsLength = 0;
|
|
527
|
+
let text;
|
|
528
|
+
try {
|
|
529
|
+
text = this.decoder.decode(message);
|
|
530
|
+
} catch (_a) {
|
|
531
|
+
throw new WebSocketProtocolError(1007, "The message is not UTF-8.");
|
|
532
|
+
}
|
|
533
|
+
if (this.state === "open") {
|
|
534
|
+
this.onMessageEmitter.fire(text);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
finish(code, reason) {
|
|
539
|
+
if (this.state === "closed") {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
this.state = "closed";
|
|
543
|
+
clearInterval(this.heartbeat);
|
|
544
|
+
this.onCloseEmitter.fire({ code, reason });
|
|
545
|
+
this.onMessageEmitter.dispose();
|
|
546
|
+
this.onCloseEmitter.dispose();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
WebSocketConnection.GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
550
|
+
|
|
551
|
+
// ../../ta-packages/ta-host/esm/node/sign-in/access-store.js
|
|
552
|
+
import { createHash as createHash2, randomBytes } from "node:crypto";
|
|
553
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
554
|
+
import { dirname } from "node:path";
|
|
555
|
+
var MAX_REQUESTS = 20;
|
|
556
|
+
var REQUEST_TTL_MS = 7 * 24 * 3600 * 1000;
|
|
557
|
+
var TOUCH_INTERVAL_MS = 3600 * 1000;
|
|
558
|
+
var AccessUtil;
|
|
559
|
+
(function(AccessUtil2) {
|
|
560
|
+
function normalize(account) {
|
|
561
|
+
const value = account.trim();
|
|
562
|
+
return value.startsWith("github:") || value.includes("@") ? value.toLowerCase() : value;
|
|
563
|
+
}
|
|
564
|
+
AccessUtil2.normalize = normalize;
|
|
565
|
+
function matches(pattern, account) {
|
|
566
|
+
const [want, have] = [normalize(pattern), normalize(account)];
|
|
567
|
+
const star = want.indexOf(":*@");
|
|
568
|
+
if (star > 0) {
|
|
569
|
+
return have.startsWith(want.slice(0, star + 1)) && have.endsWith(want.slice(star + 2));
|
|
570
|
+
}
|
|
571
|
+
return want === have;
|
|
572
|
+
}
|
|
573
|
+
AccessUtil2.matches = matches;
|
|
574
|
+
function parseList(list) {
|
|
575
|
+
return (list !== null && list !== undefined ? list : "").split(/[\s,]+/).map((entry) => entry.trim()).filter((entry) => /^[a-z][a-z0-9-]*:.+/.test(entry));
|
|
576
|
+
}
|
|
577
|
+
AccessUtil2.parseList = parseList;
|
|
578
|
+
function hash(token) {
|
|
579
|
+
return createHash2("sha256").update(token).digest("base64url");
|
|
580
|
+
}
|
|
581
|
+
AccessUtil2.hash = hash;
|
|
582
|
+
})(AccessUtil || (AccessUtil = {}));
|
|
583
|
+
|
|
584
|
+
class AccessStore {
|
|
585
|
+
constructor(file, fromEnv = []) {
|
|
586
|
+
this.file = file;
|
|
587
|
+
this.fromEnv = fromEnv;
|
|
588
|
+
this.touched = new Map;
|
|
589
|
+
}
|
|
590
|
+
allows(account) {
|
|
591
|
+
return this.fromEnv.some((pattern) => AccessUtil.matches(pattern, account)) || this.read().accounts.some((added) => AccessUtil.matches(added.id, account));
|
|
592
|
+
}
|
|
593
|
+
get open() {
|
|
594
|
+
return this.fromEnv.length > 0 || this.read().accounts.length > 0;
|
|
595
|
+
}
|
|
596
|
+
signIn(account, device, now = Date.now()) {
|
|
597
|
+
const token = randomBytes(32).toString("base64url");
|
|
598
|
+
const data = this.read();
|
|
599
|
+
data.signIns.push({
|
|
600
|
+
id: randomBytes(9).toString("base64url"),
|
|
601
|
+
hash: AccessUtil.hash(token),
|
|
602
|
+
account: account.id,
|
|
603
|
+
name: account.name,
|
|
604
|
+
avatar: account.avatar,
|
|
605
|
+
createdAt: now,
|
|
606
|
+
lastUsedAt: now,
|
|
607
|
+
device: device === null || device === undefined ? undefined : device.slice(0, 300)
|
|
608
|
+
});
|
|
609
|
+
data.requests = data.requests.filter((request) => request.id !== account.id);
|
|
610
|
+
this.write();
|
|
611
|
+
return token;
|
|
612
|
+
}
|
|
613
|
+
check(token, now = Date.now()) {
|
|
614
|
+
var _a;
|
|
615
|
+
const hash = AccessUtil.hash(token);
|
|
616
|
+
const signIn = this.read().signIns.find((one) => one.hash === hash);
|
|
617
|
+
if (!signIn || !this.allows(signIn.account)) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
signIn.lastUsedAt = now;
|
|
621
|
+
if (now - ((_a = this.touched.get(signIn.id)) !== null && _a !== undefined ? _a : signIn.createdAt) >= TOUCH_INTERVAL_MS) {
|
|
622
|
+
this.touched.set(signIn.id, now);
|
|
623
|
+
this.write();
|
|
624
|
+
}
|
|
625
|
+
return signIn;
|
|
626
|
+
}
|
|
627
|
+
request(account, now = Date.now()) {
|
|
628
|
+
const data = this.read();
|
|
629
|
+
const others = data.requests.filter((request) => request.id !== account.id && now - request.at < REQUEST_TTL_MS);
|
|
630
|
+
data.requests = [{ id: account.id, name: account.name, avatar: account.avatar, at: now }, ...others].slice(0, MAX_REQUESTS);
|
|
631
|
+
this.write();
|
|
632
|
+
}
|
|
633
|
+
allow(account, name, now = Date.now()) {
|
|
634
|
+
const id = AccessUtil.normalize(account);
|
|
635
|
+
const data = this.read();
|
|
636
|
+
const request = data.requests.find((one) => one.id === id);
|
|
637
|
+
data.requests = data.requests.filter((one) => one.id !== id);
|
|
638
|
+
if (!data.accounts.some((added) => added.id === id)) {
|
|
639
|
+
data.accounts.push({ id, name: name !== null && name !== undefined ? name : request === null || request === undefined ? undefined : request.name, avatar: request === null || request === undefined ? undefined : request.avatar, addedAt: now });
|
|
640
|
+
}
|
|
641
|
+
this.write();
|
|
642
|
+
}
|
|
643
|
+
dismiss(account) {
|
|
644
|
+
const data = this.read();
|
|
645
|
+
data.requests = data.requests.filter((one) => one.id !== AccessUtil.normalize(account));
|
|
646
|
+
this.write();
|
|
647
|
+
}
|
|
648
|
+
disallow(account) {
|
|
649
|
+
const id = AccessUtil.normalize(account);
|
|
650
|
+
const data = this.read();
|
|
651
|
+
data.accounts = data.accounts.filter((added) => added.id !== id);
|
|
652
|
+
data.signIns = data.signIns.filter((signIn) => this.allows(signIn.account));
|
|
653
|
+
this.write();
|
|
654
|
+
}
|
|
655
|
+
signOut(signInId) {
|
|
656
|
+
const data = this.read();
|
|
657
|
+
data.signIns = data.signIns.filter((signIn) => signIn.id !== signInId);
|
|
658
|
+
this.write();
|
|
659
|
+
}
|
|
660
|
+
info(currentToken, now = Date.now()) {
|
|
661
|
+
const data = this.read();
|
|
662
|
+
const current = currentToken && AccessUtil.hash(currentToken);
|
|
663
|
+
const accounts = [
|
|
664
|
+
...this.fromEnv.map((id) => ({ id, source: "env" })),
|
|
665
|
+
...data.accounts.map(({ id, name, avatar, addedAt }) => ({ id, name, avatar, addedAt, source: "added" }))
|
|
666
|
+
];
|
|
667
|
+
return {
|
|
668
|
+
accounts,
|
|
669
|
+
requests: data.requests.filter((request) => now - request.at < REQUEST_TTL_MS && !this.allows(request.id)),
|
|
670
|
+
signIns: data.signIns.filter((signIn) => this.allows(signIn.account)).map(({ id, account, name, createdAt, lastUsedAt, device, hash }) => ({
|
|
671
|
+
id,
|
|
672
|
+
account,
|
|
673
|
+
name,
|
|
674
|
+
createdAt,
|
|
675
|
+
lastUsedAt,
|
|
676
|
+
device,
|
|
677
|
+
current: hash === current
|
|
678
|
+
}))
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
read() {
|
|
682
|
+
if (!this.data) {
|
|
683
|
+
try {
|
|
684
|
+
const parsed = JSON.parse(readFileSync(this.file, "utf8"));
|
|
685
|
+
this.data = {
|
|
686
|
+
accounts: Array.isArray(parsed.accounts) ? parsed.accounts : [],
|
|
687
|
+
requests: Array.isArray(parsed.requests) ? parsed.requests : [],
|
|
688
|
+
signIns: Array.isArray(parsed.signIns) ? parsed.signIns : []
|
|
689
|
+
};
|
|
690
|
+
} catch (_a) {
|
|
691
|
+
this.data = { accounts: [], requests: [], signIns: [] };
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return this.data;
|
|
695
|
+
}
|
|
696
|
+
write() {
|
|
697
|
+
mkdirSync(dirname(this.file), { recursive: true });
|
|
698
|
+
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
699
|
+
writeFileSync(temporary, JSON.stringify(this.data, undefined, 2), { mode: 384 });
|
|
700
|
+
chmodSync(temporary, 384);
|
|
701
|
+
renameSync(temporary, this.file);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// ../../ta-packages/ta-host/esm/node/sign-in/sign-in-flow.js
|
|
706
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
707
|
+
|
|
708
|
+
// ../../ta-packages/ta-protocol/esm/common/access-protocol.js
|
|
709
|
+
var TaAccessServer = Symbol("TaAccessServer");
|
|
710
|
+
var TA_SIGN_IN_PATH = "/sign-in";
|
|
711
|
+
// ../../ta-packages/ta-protocol/esm/common/auth-protocol.js
|
|
712
|
+
var TaAuthServer = Symbol("TaAuthServer");
|
|
713
|
+
// ../../ta-packages/ta-protocol/esm/common/gateway-protocol.js
|
|
714
|
+
var TaGatewayServer = Symbol("TaGatewayServer");
|
|
715
|
+
// ../../ta-packages/ta-protocol/esm/common/location.js
|
|
716
|
+
var TaLocation;
|
|
717
|
+
(function(TaLocation2) {
|
|
718
|
+
TaLocation2.SSH = "ssh://";
|
|
719
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
720
|
+
function isRemote(location) {
|
|
721
|
+
return location.startsWith(TaLocation2.SSH);
|
|
722
|
+
}
|
|
723
|
+
TaLocation2.isRemote = isRemote;
|
|
724
|
+
function parse(location) {
|
|
725
|
+
if (!isRemote(location)) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
const rest = location.slice(TaLocation2.SSH.length);
|
|
729
|
+
const slash = rest.indexOf("/");
|
|
730
|
+
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
731
|
+
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
732
|
+
if (!isHost(host2)) {
|
|
733
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
734
|
+
}
|
|
735
|
+
return { host: host2, path: path2 };
|
|
736
|
+
}
|
|
737
|
+
TaLocation2.parse = parse;
|
|
738
|
+
function isHost(host2) {
|
|
739
|
+
return HOST.test(host2);
|
|
740
|
+
}
|
|
741
|
+
TaLocation2.isHost = isHost;
|
|
742
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
743
|
+
function readHost(input) {
|
|
744
|
+
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
745
|
+
if (words[0] === "ssh") {
|
|
746
|
+
words.shift();
|
|
747
|
+
}
|
|
748
|
+
let destination;
|
|
749
|
+
let port;
|
|
750
|
+
let user;
|
|
751
|
+
const options = [];
|
|
752
|
+
for (let i = 0;i < words.length; i++) {
|
|
753
|
+
const word = words[i];
|
|
754
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
755
|
+
if (word === "-p" || word === "-l" || glued) {
|
|
756
|
+
const value = glued ? glued[2] : words[++i];
|
|
757
|
+
if (value === undefined) {
|
|
758
|
+
return { error: "invalid" };
|
|
759
|
+
}
|
|
760
|
+
if ((glued ? glued[1] : word[1]) === "p") {
|
|
761
|
+
port = value;
|
|
762
|
+
} else {
|
|
763
|
+
user = value;
|
|
764
|
+
}
|
|
765
|
+
} else if (word === "-o" || word.startsWith("-o")) {
|
|
766
|
+
const value = word === "-o" ? words[++i] : word.slice(2);
|
|
767
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
768
|
+
if (!option) {
|
|
769
|
+
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
770
|
+
} else if (option[1].toLowerCase() === "port") {
|
|
771
|
+
port = option[2];
|
|
772
|
+
} else {
|
|
773
|
+
user = option[2];
|
|
774
|
+
}
|
|
775
|
+
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
776
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
777
|
+
} else if (destination === undefined) {
|
|
778
|
+
destination = word;
|
|
779
|
+
} else {
|
|
780
|
+
return { error: "invalid" };
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (options.length > 0) {
|
|
784
|
+
return { error: "options", options };
|
|
785
|
+
}
|
|
786
|
+
if (!destination) {
|
|
787
|
+
return { error: "empty" };
|
|
788
|
+
}
|
|
789
|
+
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
790
|
+
if (user && !host2.includes("@")) {
|
|
791
|
+
host2 = `${user}@${host2}`;
|
|
792
|
+
}
|
|
793
|
+
if (port) {
|
|
794
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
795
|
+
return { error: "invalid" };
|
|
796
|
+
}
|
|
797
|
+
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
798
|
+
}
|
|
799
|
+
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
800
|
+
}
|
|
801
|
+
TaLocation2.readHost = readHost;
|
|
802
|
+
function ssh(host2, path2 = "") {
|
|
803
|
+
return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
804
|
+
}
|
|
805
|
+
TaLocation2.ssh = ssh;
|
|
806
|
+
function hostLabel(host2) {
|
|
807
|
+
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
808
|
+
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
809
|
+
}
|
|
810
|
+
TaLocation2.hostLabel = hostLabel;
|
|
811
|
+
function host(location) {
|
|
812
|
+
var _a;
|
|
813
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
814
|
+
}
|
|
815
|
+
TaLocation2.host = host;
|
|
816
|
+
function path(location) {
|
|
817
|
+
var _a;
|
|
818
|
+
var _b;
|
|
819
|
+
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
820
|
+
}
|
|
821
|
+
TaLocation2.path = path;
|
|
822
|
+
function parent(location) {
|
|
823
|
+
const remote = parse(location);
|
|
824
|
+
if (remote) {
|
|
825
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
826
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
827
|
+
}
|
|
828
|
+
return parentPath(location);
|
|
829
|
+
}
|
|
830
|
+
TaLocation2.parent = parent;
|
|
831
|
+
function child(location, name) {
|
|
832
|
+
const remote = parse(location);
|
|
833
|
+
if (remote) {
|
|
834
|
+
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
835
|
+
}
|
|
836
|
+
return childPath(location, name);
|
|
837
|
+
}
|
|
838
|
+
TaLocation2.child = child;
|
|
839
|
+
function basename(location) {
|
|
840
|
+
const remote = parse(location);
|
|
841
|
+
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
842
|
+
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
843
|
+
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
844
|
+
}
|
|
845
|
+
TaLocation2.basename = basename;
|
|
846
|
+
function parentPath(path2) {
|
|
847
|
+
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
848
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
849
|
+
if (at < 0) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
const head = trimmed.slice(0, at);
|
|
853
|
+
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
854
|
+
}
|
|
855
|
+
function childPath(path2, name) {
|
|
856
|
+
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
857
|
+
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
858
|
+
}
|
|
859
|
+
function normalize(path2) {
|
|
860
|
+
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
861
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
862
|
+
}
|
|
863
|
+
})(TaLocation || (TaLocation = {}));
|
|
864
|
+
// ../../ta-packages/ta-protocol/esm/common/package-protocol.js
|
|
865
|
+
var TaPackageServer = Symbol("TaPackageServer");
|
|
866
|
+
var TaPackageTextUtil;
|
|
867
|
+
(function(TaPackageTextUtil2) {
|
|
868
|
+
function pick(text, language) {
|
|
869
|
+
var _a, _b, _c, _d;
|
|
870
|
+
if (text === undefined || typeof text === "string") {
|
|
871
|
+
return text;
|
|
872
|
+
}
|
|
873
|
+
return (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[language.split("-")[0]]) !== null && _b !== undefined ? _b : text.en) !== null && _c !== undefined ? _c : text["en-US"]) !== null && _d !== undefined ? _d : Object.values(text)[0];
|
|
874
|
+
}
|
|
875
|
+
TaPackageTextUtil2.pick = pick;
|
|
876
|
+
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
877
|
+
// ../../ta-packages/ta-protocol/esm/common/relay-protocol.js
|
|
878
|
+
var TaRelayServer = Symbol("TaRelayServer");
|
|
879
|
+
// ../../ta-packages/ta-protocol/esm/common/remote-protocol.js
|
|
880
|
+
var TaRemoteServer = Symbol("TaRemoteServer");
|
|
881
|
+
// ../../ta-packages/ta-protocol/esm/common/settings-protocol.js
|
|
882
|
+
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
883
|
+
// ../../ta-packages/ta-protocol/esm/common/ta-protocol.js
|
|
884
|
+
var TaServer = Symbol("TaServer");
|
|
885
|
+
var TaClient = Symbol("TaClient");
|
|
886
|
+
var TA_WEBSOCKET_PATH = "/api/ws";
|
|
887
|
+
var TaErrorCode = {
|
|
888
|
+
SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
|
|
889
|
+
SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
|
|
890
|
+
TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
|
|
891
|
+
MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
|
|
892
|
+
MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
|
|
893
|
+
INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
|
|
894
|
+
COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
|
|
895
|
+
NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
|
|
896
|
+
ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
|
|
897
|
+
CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
|
|
898
|
+
};
|
|
899
|
+
var TaErrorUtil;
|
|
900
|
+
(function(TaErrorUtil2) {
|
|
901
|
+
function code(error) {
|
|
902
|
+
var _a;
|
|
903
|
+
var _b;
|
|
904
|
+
const failure = error;
|
|
905
|
+
const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
|
|
906
|
+
return typeof code2 === "string" ? code2 : undefined;
|
|
907
|
+
}
|
|
908
|
+
TaErrorUtil2.code = code;
|
|
909
|
+
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
910
|
+
var TA_RPC_ERROR_CODE = -32050;
|
|
911
|
+
var TaMessageContext;
|
|
912
|
+
(function(TaMessageContext2) {
|
|
913
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
914
|
+
function wrap(context, message) {
|
|
915
|
+
return `<context>
|
|
916
|
+
${context}
|
|
917
|
+
</context>
|
|
918
|
+
${message}`;
|
|
919
|
+
}
|
|
920
|
+
TaMessageContext2.wrap = wrap;
|
|
921
|
+
function strip(message) {
|
|
922
|
+
return message.replace(BLOCK, "");
|
|
923
|
+
}
|
|
924
|
+
TaMessageContext2.strip = strip;
|
|
925
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
926
|
+
var TaSkillUse;
|
|
927
|
+
(function(TaSkillUse2) {
|
|
928
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
929
|
+
function parse(message) {
|
|
930
|
+
var _a;
|
|
931
|
+
const match = BLOCK.exec(message);
|
|
932
|
+
if (!match) {
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
936
|
+
}
|
|
937
|
+
TaSkillUse2.parse = parse;
|
|
938
|
+
function command(use) {
|
|
939
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
940
|
+
}
|
|
941
|
+
TaSkillUse2.command = command;
|
|
942
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
943
|
+
// ../../ta-packages/ta-protocol/esm/common/workspace-protocol.js
|
|
944
|
+
var TA_FILES_PATH = "/api/files";
|
|
945
|
+
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
946
|
+
var TaTerminalServer = Symbol("TaTerminalServer");
|
|
947
|
+
var TaExcludedFiles;
|
|
948
|
+
(function(TaExcludedFiles2) {
|
|
949
|
+
TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
|
|
950
|
+
function has(name) {
|
|
951
|
+
return TaExcludedFiles2.NAMES.includes(name);
|
|
952
|
+
}
|
|
953
|
+
TaExcludedFiles2.has = has;
|
|
954
|
+
function filter(entries) {
|
|
955
|
+
return entries.filter((entry) => !has(entry.name));
|
|
956
|
+
}
|
|
957
|
+
TaExcludedFiles2.filter = filter;
|
|
958
|
+
})(TaExcludedFiles || (TaExcludedFiles = {}));
|
|
959
|
+
var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
|
|
960
|
+
// ../../ta-packages/ta-host/esm/node/sign-in/sign-in-provider.js
|
|
961
|
+
class SignInError extends Error {
|
|
962
|
+
}
|
|
963
|
+
var TIMEOUT_MS = 1e4;
|
|
964
|
+
var SignInHttp;
|
|
965
|
+
(function(SignInHttp2) {
|
|
966
|
+
function url(base, params) {
|
|
967
|
+
const url2 = new URL(base);
|
|
968
|
+
for (const [key, value] of Object.entries(params)) {
|
|
969
|
+
if (value !== undefined) {
|
|
970
|
+
url2.searchParams.set(key, value);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
return url2.toString();
|
|
974
|
+
}
|
|
975
|
+
SignInHttp2.url = url;
|
|
976
|
+
async function json(url2, init = {}) {
|
|
977
|
+
const response = await fetch(url2, { ...init, signal: AbortSignal.timeout(TIMEOUT_MS) });
|
|
978
|
+
const text = await response.text();
|
|
979
|
+
if (!response.ok) {
|
|
980
|
+
throw new SignInError(`${new URL(url2).host} answered ${response.status}: ${text.slice(0, 200)}`);
|
|
981
|
+
}
|
|
982
|
+
try {
|
|
983
|
+
return JSON.parse(text);
|
|
984
|
+
} catch (_a) {
|
|
985
|
+
throw new SignInError(`${new URL(url2).host} did not answer JSON: ${text.slice(0, 200)}`);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
SignInHttp2.json = json;
|
|
989
|
+
function form(params) {
|
|
990
|
+
return {
|
|
991
|
+
method: "POST",
|
|
992
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
993
|
+
body: new URLSearchParams(params).toString()
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
SignInHttp2.form = form;
|
|
997
|
+
})(SignInHttp || (SignInHttp = {}));
|
|
998
|
+
|
|
999
|
+
class GitHubSignIn {
|
|
1000
|
+
static endpoints(url = "https://github.com") {
|
|
1001
|
+
const base = url.replace(/\/+$/, "");
|
|
1002
|
+
const api = base === "https://github.com" ? "https://api.github.com" : `${base}/api/v3`;
|
|
1003
|
+
return { authorize: `${base}/login/oauth/authorize`, token: `${base}/login/oauth/access_token`, user: `${api}/user` };
|
|
1004
|
+
}
|
|
1005
|
+
constructor(clientId, clientSecret, endpoints = GitHubSignIn.endpoints()) {
|
|
1006
|
+
this.clientId = clientId;
|
|
1007
|
+
this.clientSecret = clientSecret;
|
|
1008
|
+
this.endpoints = endpoints;
|
|
1009
|
+
this.id = "github";
|
|
1010
|
+
this.name = "GitHub";
|
|
1011
|
+
}
|
|
1012
|
+
async authorizeUrl({ redirectUri, state, challenge }) {
|
|
1013
|
+
return SignInHttp.url(this.endpoints.authorize, {
|
|
1014
|
+
client_id: this.clientId,
|
|
1015
|
+
redirect_uri: redirectUri,
|
|
1016
|
+
scope: "read:user",
|
|
1017
|
+
state,
|
|
1018
|
+
allow_signup: "false",
|
|
1019
|
+
code_challenge: challenge,
|
|
1020
|
+
code_challenge_method: "S256"
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
async account({ code, redirectUri, verifier }) {
|
|
1024
|
+
var _a, _b;
|
|
1025
|
+
const token = await SignInHttp.json(this.endpoints.token, SignInHttp.form({ client_id: this.clientId, client_secret: this.clientSecret, code, redirect_uri: redirectUri, code_verifier: verifier }));
|
|
1026
|
+
if (!token.access_token) {
|
|
1027
|
+
throw new SignInError(`GitHub: ${(_b = (_a = token.error_description) !== null && _a !== undefined ? _a : token.error) !== null && _b !== undefined ? _b : "no access token"}`);
|
|
1028
|
+
}
|
|
1029
|
+
const user = await SignInHttp.json(this.endpoints.user, {
|
|
1030
|
+
headers: { Authorization: `Bearer ${token.access_token}`, Accept: "application/vnd.github+json", "User-Agent": "Ta" }
|
|
1031
|
+
});
|
|
1032
|
+
if (!user.login) {
|
|
1033
|
+
throw new SignInError("GitHub: the user has no login");
|
|
1034
|
+
}
|
|
1035
|
+
return { id: `github:${user.login.toLowerCase()}`, name: user.name || user.login, avatar: user.avatar_url };
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
class OidcSignIn {
|
|
1040
|
+
static google(clientId, clientSecret) {
|
|
1041
|
+
return new OidcSignIn({
|
|
1042
|
+
id: "google",
|
|
1043
|
+
name: "Google",
|
|
1044
|
+
issuer: "https://accounts.google.com",
|
|
1045
|
+
clientId,
|
|
1046
|
+
clientSecret,
|
|
1047
|
+
requireEmail: true,
|
|
1048
|
+
extra: { prompt: "select_account" }
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
constructor(options) {
|
|
1052
|
+
this.options = options;
|
|
1053
|
+
this.id = options.id;
|
|
1054
|
+
this.name = options.name;
|
|
1055
|
+
}
|
|
1056
|
+
async authorizeUrl({ redirectUri, state, challenge }) {
|
|
1057
|
+
const { authorization_endpoint } = await this.discover();
|
|
1058
|
+
return SignInHttp.url(authorization_endpoint, {
|
|
1059
|
+
response_type: "code",
|
|
1060
|
+
client_id: this.options.clientId,
|
|
1061
|
+
redirect_uri: redirectUri,
|
|
1062
|
+
scope: "openid email profile",
|
|
1063
|
+
state,
|
|
1064
|
+
code_challenge: challenge,
|
|
1065
|
+
code_challenge_method: "S256",
|
|
1066
|
+
...this.options.extra
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
async account({ code, redirectUri, verifier }) {
|
|
1070
|
+
var _a, _b;
|
|
1071
|
+
const { token_endpoint, userinfo_endpoint } = await this.discover();
|
|
1072
|
+
const token = await SignInHttp.json(token_endpoint, SignInHttp.form({
|
|
1073
|
+
grant_type: "authorization_code",
|
|
1074
|
+
code,
|
|
1075
|
+
redirect_uri: redirectUri,
|
|
1076
|
+
client_id: this.options.clientId,
|
|
1077
|
+
client_secret: this.options.clientSecret,
|
|
1078
|
+
code_verifier: verifier
|
|
1079
|
+
}));
|
|
1080
|
+
if (!token.access_token) {
|
|
1081
|
+
throw new SignInError(`${this.name}: ${(_b = (_a = token.error_description) !== null && _a !== undefined ? _a : token.error) !== null && _b !== undefined ? _b : "no access token"}`);
|
|
1082
|
+
}
|
|
1083
|
+
const user = await SignInHttp.json(userinfo_endpoint, { headers: { Authorization: `Bearer ${token.access_token}`, Accept: "application/json" } });
|
|
1084
|
+
const email = user.email && user.email_verified !== false && user.email_verified !== "false" ? user.email : undefined;
|
|
1085
|
+
if (!email && (this.options.requireEmail || !user.sub)) {
|
|
1086
|
+
throw new SignInError(`${this.name}: the account has no verified email address`);
|
|
1087
|
+
}
|
|
1088
|
+
const id = email ? `${this.id}:${email.toLowerCase()}` : `${this.id}:${user.sub}`;
|
|
1089
|
+
return { id, name: user.name || user.email || user.sub, avatar: user.picture };
|
|
1090
|
+
}
|
|
1091
|
+
discover() {
|
|
1092
|
+
if (!this.configuration) {
|
|
1093
|
+
const url = `${this.options.issuer.replace(/\/+$/, "")}/.well-known/openid-configuration`;
|
|
1094
|
+
this.configuration = SignInHttp.json(url);
|
|
1095
|
+
this.configuration.catch(() => this.configuration = undefined);
|
|
1096
|
+
}
|
|
1097
|
+
return this.configuration;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
class WeChatSignIn {
|
|
1102
|
+
constructor(appId, appSecret, endpoints = WeChatSignIn.ENDPOINTS) {
|
|
1103
|
+
this.appId = appId;
|
|
1104
|
+
this.appSecret = appSecret;
|
|
1105
|
+
this.endpoints = endpoints;
|
|
1106
|
+
this.id = "wechat";
|
|
1107
|
+
this.name = "WeChat";
|
|
1108
|
+
}
|
|
1109
|
+
async authorizeUrl({ redirectUri, state }) {
|
|
1110
|
+
const url = SignInHttp.url(this.endpoints.authorize, {
|
|
1111
|
+
appid: this.appId,
|
|
1112
|
+
redirect_uri: redirectUri,
|
|
1113
|
+
response_type: "code",
|
|
1114
|
+
scope: "snsapi_login",
|
|
1115
|
+
state
|
|
1116
|
+
});
|
|
1117
|
+
return `${url}#wechat_redirect`;
|
|
1118
|
+
}
|
|
1119
|
+
async account({ code }) {
|
|
1120
|
+
var _a, _b, _c, _d;
|
|
1121
|
+
const token = await SignInHttp.json(SignInHttp.url(this.endpoints.token, { appid: this.appId, secret: this.appSecret, code, grant_type: "authorization_code" }));
|
|
1122
|
+
if (!token.access_token || !token.openid) {
|
|
1123
|
+
throw new SignInError(`WeChat: ${(_a = token.errmsg) !== null && _a !== undefined ? _a : "no access token"} (${(_b = token.errcode) !== null && _b !== undefined ? _b : "-"})`);
|
|
1124
|
+
}
|
|
1125
|
+
const user = await SignInHttp.json(SignInHttp.url(this.endpoints.user, { access_token: token.access_token, openid: token.openid }));
|
|
1126
|
+
return { id: `wechat:${(_d = (_c = user.unionid) !== null && _c !== undefined ? _c : token.unionid) !== null && _d !== undefined ? _d : token.openid}`, name: user.nickname, avatar: user.headimgurl || undefined };
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
WeChatSignIn.ENDPOINTS = {
|
|
1130
|
+
authorize: "https://open.weixin.qq.com/connect/qrconnect",
|
|
1131
|
+
token: "https://api.weixin.qq.com/sns/oauth2/access_token",
|
|
1132
|
+
user: "https://api.weixin.qq.com/sns/userinfo"
|
|
1133
|
+
};
|
|
1134
|
+
var SignInProviders;
|
|
1135
|
+
(function(SignInProviders2) {
|
|
1136
|
+
function publicUrl(env) {
|
|
1137
|
+
var _a;
|
|
1138
|
+
return ((_a = env.TA_PUBLIC_URL) === null || _a === undefined ? undefined : _a.trim().replace(/\/+$/, "")) || undefined;
|
|
1139
|
+
}
|
|
1140
|
+
SignInProviders2.publicUrl = publicUrl;
|
|
1141
|
+
function fromEnv(env) {
|
|
1142
|
+
const providers = [];
|
|
1143
|
+
if (env.TA_GITHUB_CLIENT_ID && env.TA_GITHUB_CLIENT_SECRET) {
|
|
1144
|
+
providers.push(new GitHubSignIn(env.TA_GITHUB_CLIENT_ID, env.TA_GITHUB_CLIENT_SECRET, GitHubSignIn.endpoints(env.TA_GITHUB_URL || undefined)));
|
|
1145
|
+
}
|
|
1146
|
+
if (env.TA_GOOGLE_CLIENT_ID && env.TA_GOOGLE_CLIENT_SECRET) {
|
|
1147
|
+
providers.push(OidcSignIn.google(env.TA_GOOGLE_CLIENT_ID, env.TA_GOOGLE_CLIENT_SECRET));
|
|
1148
|
+
}
|
|
1149
|
+
if (env.TA_WECHAT_APP_ID && env.TA_WECHAT_APP_SECRET) {
|
|
1150
|
+
providers.push(new WeChatSignIn(env.TA_WECHAT_APP_ID, env.TA_WECHAT_APP_SECRET));
|
|
1151
|
+
}
|
|
1152
|
+
if (env.TA_OIDC_ISSUER && env.TA_OIDC_CLIENT_ID && env.TA_OIDC_CLIENT_SECRET) {
|
|
1153
|
+
providers.push(new OidcSignIn({
|
|
1154
|
+
id: "oidc",
|
|
1155
|
+
name: env.TA_OIDC_NAME || "SSO",
|
|
1156
|
+
issuer: env.TA_OIDC_ISSUER,
|
|
1157
|
+
clientId: env.TA_OIDC_CLIENT_ID,
|
|
1158
|
+
clientSecret: env.TA_OIDC_CLIENT_SECRET
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1161
|
+
return providers;
|
|
1162
|
+
}
|
|
1163
|
+
SignInProviders2.fromEnv = fromEnv;
|
|
1164
|
+
})(SignInProviders || (SignInProviders = {}));
|
|
1165
|
+
|
|
1166
|
+
// ../../ta-packages/ta-host/esm/node/sign-in/sign-in-flow.js
|
|
1167
|
+
var PENDING_TTL_MS = 10 * 60 * 1000;
|
|
1168
|
+
var BIND_TTL_MS = 5 * 60 * 1000;
|
|
1169
|
+
var SignInUtil;
|
|
1170
|
+
(function(SignInUtil2) {
|
|
1171
|
+
function origin(request, publicUrl) {
|
|
1172
|
+
var _a;
|
|
1173
|
+
if (publicUrl) {
|
|
1174
|
+
return publicUrl;
|
|
1175
|
+
}
|
|
1176
|
+
const first = (value) => {
|
|
1177
|
+
var _a2;
|
|
1178
|
+
return (_a2 = Array.isArray(value) ? value[0] : value) === null || _a2 === undefined ? undefined : _a2.split(",")[0].trim();
|
|
1179
|
+
};
|
|
1180
|
+
const proto = first(request.headers["x-forwarded-proto"]) || (((_a = request.socket) === null || _a === undefined ? undefined : _a.encrypted) ? "https" : "http");
|
|
1181
|
+
return `${proto}://${first(request.headers["x-forwarded-host"]) || request.headers.host}`;
|
|
1182
|
+
}
|
|
1183
|
+
SignInUtil2.origin = origin;
|
|
1184
|
+
function redirectUri(origin2, provider) {
|
|
1185
|
+
return `${origin2}${TA_SIGN_IN_PATH}/${provider}/callback`;
|
|
1186
|
+
}
|
|
1187
|
+
SignInUtil2.redirectUri = redirectUri;
|
|
1188
|
+
function pkce() {
|
|
1189
|
+
const verifier = randomBytes2(32).toString("base64url");
|
|
1190
|
+
return { verifier, challenge: createHash3("sha256").update(verifier).digest("base64url") };
|
|
1191
|
+
}
|
|
1192
|
+
SignInUtil2.pkce = pkce;
|
|
1193
|
+
})(SignInUtil || (SignInUtil = {}));
|
|
1194
|
+
|
|
1195
|
+
class SignInFlow {
|
|
1196
|
+
constructor(providers, store, publicUrl) {
|
|
1197
|
+
this.providers = providers;
|
|
1198
|
+
this.store = store;
|
|
1199
|
+
this.publicUrl = publicUrl;
|
|
1200
|
+
this.pending = new Map;
|
|
1201
|
+
this.binds = new Map;
|
|
1202
|
+
}
|
|
1203
|
+
provider(id) {
|
|
1204
|
+
return this.providers.find((provider) => provider.id === id);
|
|
1205
|
+
}
|
|
1206
|
+
bindUrl(provider, now = Date.now()) {
|
|
1207
|
+
const nonce = randomBytes2(18).toString("base64url");
|
|
1208
|
+
this.binds.set(nonce, { provider, at: now });
|
|
1209
|
+
return `${TA_SIGN_IN_PATH}/${provider}?bind=${nonce}`;
|
|
1210
|
+
}
|
|
1211
|
+
async start(providerId, origin, bind, now = Date.now()) {
|
|
1212
|
+
const provider = this.provider(providerId);
|
|
1213
|
+
if (!provider) {
|
|
1214
|
+
throw new SignInError(`No provider ${providerId}`);
|
|
1215
|
+
}
|
|
1216
|
+
this.prune(now);
|
|
1217
|
+
const binding = bind ? this.binds.get(bind) : undefined;
|
|
1218
|
+
if (bind) {
|
|
1219
|
+
this.binds.delete(bind);
|
|
1220
|
+
}
|
|
1221
|
+
const state = randomBytes2(18).toString("base64url");
|
|
1222
|
+
const { verifier, challenge } = SignInUtil.pkce();
|
|
1223
|
+
const redirectUri = SignInUtil.redirectUri(origin, provider.id);
|
|
1224
|
+
this.pending.set(state, { provider: provider.id, verifier, redirectUri, bind: (binding === null || binding === undefined ? undefined : binding.provider) === provider.id, at: now });
|
|
1225
|
+
return { url: await provider.authorizeUrl({ redirectUri, state, challenge }), state };
|
|
1226
|
+
}
|
|
1227
|
+
async finish(providerId, state, code, device, now = Date.now()) {
|
|
1228
|
+
const pending = this.pending.get(state);
|
|
1229
|
+
this.pending.delete(state);
|
|
1230
|
+
const provider = this.provider(providerId);
|
|
1231
|
+
if (!pending || !provider || pending.provider !== providerId || now - pending.at > PENDING_TTL_MS) {
|
|
1232
|
+
throw new SignInError("The sign-in expired or was not started here");
|
|
1233
|
+
}
|
|
1234
|
+
const account = await provider.account({ code, redirectUri: pending.redirectUri, verifier: pending.verifier });
|
|
1235
|
+
if (pending.bind) {
|
|
1236
|
+
this.store.allow(account.id, account.name, now);
|
|
1237
|
+
}
|
|
1238
|
+
if (!this.store.allows(account.id)) {
|
|
1239
|
+
this.store.request(account, now);
|
|
1240
|
+
return { denied: account };
|
|
1241
|
+
}
|
|
1242
|
+
return { token: this.store.signIn(account, device, now), account };
|
|
1243
|
+
}
|
|
1244
|
+
prune(now) {
|
|
1245
|
+
for (const [state, pending] of this.pending) {
|
|
1246
|
+
if (now - pending.at > PENDING_TTL_MS) {
|
|
1247
|
+
this.pending.delete(state);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
for (const [nonce, bind] of this.binds) {
|
|
1251
|
+
if (now - bind.at > BIND_TTL_MS) {
|
|
1252
|
+
this.binds.delete(nonce);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// ../../ta-packages/ta-host/esm/node/sign-in/sign-in-pages.js
|
|
1259
|
+
var STATE_COOKIE = "ta_sign_in";
|
|
1260
|
+
var SignInPageUtil;
|
|
1261
|
+
(function(SignInPageUtil2) {
|
|
1262
|
+
function cookie(header, name) {
|
|
1263
|
+
for (const part of (header !== null && header !== undefined ? header : "").split(";")) {
|
|
1264
|
+
const [key, ...value] = part.trim().split("=");
|
|
1265
|
+
if (key === name) {
|
|
1266
|
+
return decodeURIComponent(value.join("="));
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
SignInPageUtil2.cookie = cookie;
|
|
1272
|
+
function back(fragment) {
|
|
1273
|
+
const params = new URLSearchParams("token" in fragment ? { token: fragment.token } : { "sign-in": fragment.outcome, ...fragment.account ? { account: fragment.account } : {} });
|
|
1274
|
+
return `/#${params.toString()}`;
|
|
1275
|
+
}
|
|
1276
|
+
SignInPageUtil2.back = back;
|
|
1277
|
+
function redirect(response, location2) {
|
|
1278
|
+
response.statusCode = 302;
|
|
1279
|
+
response.setHeader("Location", location2);
|
|
1280
|
+
response.end();
|
|
1281
|
+
}
|
|
1282
|
+
SignInPageUtil2.redirect = redirect;
|
|
1283
|
+
function end(response, status, body = "") {
|
|
1284
|
+
response.statusCode = status;
|
|
1285
|
+
response.end(body);
|
|
1286
|
+
}
|
|
1287
|
+
SignInPageUtil2.end = end;
|
|
1288
|
+
})(SignInPageUtil || (SignInPageUtil = {}));
|
|
1289
|
+
var SignInPages;
|
|
1290
|
+
(function(SignInPages2) {
|
|
1291
|
+
function matches(request) {
|
|
1292
|
+
var _a;
|
|
1293
|
+
const path = ((_a = request.url) !== null && _a !== undefined ? _a : "/").split("?")[0];
|
|
1294
|
+
return path === TA_SIGN_IN_PATH || path.startsWith(`${TA_SIGN_IN_PATH}/`);
|
|
1295
|
+
}
|
|
1296
|
+
SignInPages2.matches = matches;
|
|
1297
|
+
async function handle(request, response, flow, options) {
|
|
1298
|
+
var _a, _b;
|
|
1299
|
+
const url = new URL((_a = request.url) !== null && _a !== undefined ? _a : "/", "http://localhost");
|
|
1300
|
+
response.setHeader("Cache-Control", "no-store");
|
|
1301
|
+
response.setHeader("Referrer-Policy", "no-referrer");
|
|
1302
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
1303
|
+
response.setHeader("Allow", "GET, HEAD");
|
|
1304
|
+
SignInPageUtil.end(response, 405);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
const [providerId, step, ...rest] = url.pathname.slice(TA_SIGN_IN_PATH.length + 1).split("/");
|
|
1308
|
+
if (!providerId) {
|
|
1309
|
+
const ways = { providers: flow.providers.map(({ id, name }) => ({ id, name })) };
|
|
1310
|
+
response.setHeader("Content-Type", "application/json");
|
|
1311
|
+
SignInPageUtil.end(response, 200, JSON.stringify(ways));
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
if (!flow.provider(providerId) || rest.length > 0 || step && step !== "callback") {
|
|
1315
|
+
SignInPageUtil.end(response, 404);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
if (!step) {
|
|
1319
|
+
await go(request, response, flow, providerId, (_b = url.searchParams.get("bind")) !== null && _b !== undefined ? _b : undefined, options);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
await back(request, response, flow, providerId, url.searchParams, options);
|
|
1323
|
+
}
|
|
1324
|
+
SignInPages2.handle = handle;
|
|
1325
|
+
async function go(request, response, flow, providerId, bind, options) {
|
|
1326
|
+
const origin = SignInUtil.origin(request, flow.publicUrl);
|
|
1327
|
+
try {
|
|
1328
|
+
const { url, state } = await flow.start(providerId, origin, bind);
|
|
1329
|
+
const secure = origin.startsWith("https:") ? "; Secure" : "";
|
|
1330
|
+
response.setHeader("Set-Cookie", `${STATE_COOKIE}=${state}; Path=${TA_SIGN_IN_PATH}; Max-Age=600; HttpOnly; SameSite=Lax${secure}`);
|
|
1331
|
+
SignInPageUtil.redirect(response, url);
|
|
1332
|
+
} catch (error) {
|
|
1333
|
+
console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
|
|
1334
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: "failed" }));
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
async function back(request, response, flow, providerId, params, options) {
|
|
1338
|
+
var _a;
|
|
1339
|
+
var _b;
|
|
1340
|
+
const state = (_b = params.get("state")) !== null && _b !== undefined ? _b : "";
|
|
1341
|
+
const code = params.get("code");
|
|
1342
|
+
response.setHeader("Set-Cookie", `${STATE_COOKIE}=; Path=${TA_SIGN_IN_PATH}; Max-Age=0; HttpOnly; SameSite=Lax`);
|
|
1343
|
+
if (!code || !state || SignInPageUtil.cookie(request.headers.cookie, STATE_COOKIE) !== state) {
|
|
1344
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: "failed" }));
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
try {
|
|
1348
|
+
const result = await flow.finish(providerId, state, code, request.headers["user-agent"]);
|
|
1349
|
+
if ("token" in result) {
|
|
1350
|
+
console.log(`${options.name}: ${result.account.id} signed in`);
|
|
1351
|
+
await ((_a = options.onSignedIn) === null || _a === undefined ? undefined : _a.call(options, response, result.token, result.account, SignInUtil.origin(request, flow.publicUrl)));
|
|
1352
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ token: result.token }));
|
|
1353
|
+
} else {
|
|
1354
|
+
console.log(`${options.name}: ${result.denied.id} signed in and waits to be let in`);
|
|
1355
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: "denied", account: result.denied.id }));
|
|
1356
|
+
}
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
|
|
1359
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: "failed" }));
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
})(SignInPages || (SignInPages = {}));
|
|
1363
|
+
|
|
1364
|
+
// ../../ta-packages/ta-gateway/esm/node/command-sandbox.js
|
|
1365
|
+
import { spawn } from "node:child_process";
|
|
1366
|
+
|
|
1367
|
+
// ../../ta-packages/ta-gateway/esm/node/sandbox-provider.js
|
|
1368
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
1369
|
+
import { isAbsolute, join } from "node:path";
|
|
1370
|
+
import { pathToFileURL } from "node:url";
|
|
1371
|
+
|
|
1372
|
+
class SandboxConfigError extends Error {
|
|
1373
|
+
}
|
|
1374
|
+
var SandboxProviders;
|
|
1375
|
+
(function(SandboxProviders2) {
|
|
1376
|
+
SandboxProviders2.FILE = "sandboxes.json";
|
|
1377
|
+
SandboxProviders2.DEFAULT = { default: "docker", providers: { docker: { type: "docker", name: "Docker" } } };
|
|
1378
|
+
function publicBase(env2) {
|
|
1379
|
+
var _a;
|
|
1380
|
+
return ((_a = env2.TA_PUBLIC_URL) === null || _a === undefined ? undefined : _a.trim().replace(/\/+$/, "")) || undefined;
|
|
1381
|
+
}
|
|
1382
|
+
SandboxProviders2.publicBase = publicBase;
|
|
1383
|
+
function read(dir) {
|
|
1384
|
+
const file = join(dir, SandboxProviders2.FILE);
|
|
1385
|
+
if (!existsSync(file)) {
|
|
1386
|
+
return SandboxProviders2.DEFAULT;
|
|
1387
|
+
}
|
|
1388
|
+
try {
|
|
1389
|
+
return JSON.parse(readFileSync2(file, "utf8"));
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
throw new SandboxConfigError(`${file} is not JSON: ${error.message}`);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
SandboxProviders2.read = read;
|
|
1395
|
+
async function create(config, context, factories) {
|
|
1396
|
+
var _a;
|
|
1397
|
+
const providers = [];
|
|
1398
|
+
for (const [id, entry] of Object.entries((_a = config.providers) !== null && _a !== undefined ? _a : {})) {
|
|
1399
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id) || id === "own") {
|
|
1400
|
+
throw new SandboxConfigError(`"${id}" cannot name a provider of sandboxes: use lower-case letters, digits and -, not "own".`);
|
|
1401
|
+
}
|
|
1402
|
+
const factory = entry.type === "module" ? await loadModule(entry, context) : factories[entry.type];
|
|
1403
|
+
if (!factory) {
|
|
1404
|
+
throw new SandboxConfigError(`The provider "${id}" has the type "${entry.type}", which is none of ${[...Object.keys(factories), "module"].join(", ")}.`);
|
|
1405
|
+
}
|
|
1406
|
+
providers.push(await factory(id, entry, context));
|
|
1407
|
+
}
|
|
1408
|
+
if (config.default && !providers.some((provider) => provider.id === config.default)) {
|
|
1409
|
+
throw new SandboxConfigError(`The default provider "${config.default}" is not among the providers of ${SandboxProviders2.FILE}.`);
|
|
1410
|
+
}
|
|
1411
|
+
return providers;
|
|
1412
|
+
}
|
|
1413
|
+
SandboxProviders2.create = create;
|
|
1414
|
+
async function loadModule(entry, context) {
|
|
1415
|
+
if (typeof entry.path !== "string" || !entry.path) {
|
|
1416
|
+
throw new SandboxConfigError('A provider of the type "module" names its file in "path".');
|
|
1417
|
+
}
|
|
1418
|
+
const path = isAbsolute(entry.path) ? entry.path : join(context.dir, entry.path);
|
|
1419
|
+
const loaded = await import(pathToFileURL(path).href);
|
|
1420
|
+
if (typeof loaded.default !== "function") {
|
|
1421
|
+
throw new SandboxConfigError(`${path} has no default export of a function (id, config, context) => SandboxProvider.`);
|
|
1422
|
+
}
|
|
1423
|
+
return loaded.default;
|
|
1424
|
+
}
|
|
1425
|
+
function string(config, key, fallback) {
|
|
1426
|
+
const value = config[key];
|
|
1427
|
+
if (value === undefined) {
|
|
1428
|
+
return fallback;
|
|
1429
|
+
}
|
|
1430
|
+
if (typeof value !== "string") {
|
|
1431
|
+
throw new SandboxConfigError(`"${key}" of a provider of the type "${config.type}" is a string.`);
|
|
1432
|
+
}
|
|
1433
|
+
return value;
|
|
1434
|
+
}
|
|
1435
|
+
SandboxProviders2.string = string;
|
|
1436
|
+
function env(config) {
|
|
1437
|
+
var _a;
|
|
1438
|
+
const value = (_a = config.env) !== null && _a !== undefined ? _a : {};
|
|
1439
|
+
if (typeof value !== "object" || Array.isArray(value) || Object.values(value).some((item) => typeof item !== "string")) {
|
|
1440
|
+
throw new SandboxConfigError('"env" of a provider is an object of strings.');
|
|
1441
|
+
}
|
|
1442
|
+
return value;
|
|
1443
|
+
}
|
|
1444
|
+
SandboxProviders2.env = env;
|
|
1445
|
+
})(SandboxProviders || (SandboxProviders = {}));
|
|
1446
|
+
|
|
1447
|
+
// ../../ta-packages/ta-gateway/esm/node/command-sandbox.js
|
|
1448
|
+
var TIMEOUT_MS2 = 10 * 60 * 1000;
|
|
1449
|
+
var CommandSandboxUtil;
|
|
1450
|
+
(function(CommandSandboxUtil2) {
|
|
1451
|
+
function url(stdout) {
|
|
1452
|
+
var _a;
|
|
1453
|
+
return (_a = stdout.split(`
|
|
1454
|
+
`).map((line) => line.trim()).reverse().find((line) => /^https?:\/\/\S+$/.test(line))) === null || _a === undefined ? undefined : _a.replace(/\/+$/, "");
|
|
1455
|
+
}
|
|
1456
|
+
CommandSandboxUtil2.url = url;
|
|
1457
|
+
})(CommandSandboxUtil || (CommandSandboxUtil = {}));
|
|
1458
|
+
|
|
1459
|
+
class CommandSandbox {
|
|
1460
|
+
constructor(id, config) {
|
|
1461
|
+
this.id = id;
|
|
1462
|
+
this.type = "command";
|
|
1463
|
+
this.name = SandboxProviders.string(config, "name", id);
|
|
1464
|
+
const start = SandboxProviders.string(config, "start");
|
|
1465
|
+
if (!start) {
|
|
1466
|
+
throw new Error(`The provider "${id}" of the type command needs "start", a command that prints the address of the Ta service.`);
|
|
1467
|
+
}
|
|
1468
|
+
this.commands = { start, stop: SandboxProviders.string(config, "stop"), state: SandboxProviders.string(config, "state") };
|
|
1469
|
+
this.env = SandboxProviders.env(config);
|
|
1470
|
+
}
|
|
1471
|
+
async start(tenant) {
|
|
1472
|
+
const stdout = await this.run(this.commands.start, tenant);
|
|
1473
|
+
const url = CommandSandboxUtil.url(stdout);
|
|
1474
|
+
if (!url) {
|
|
1475
|
+
throw new Error(`"start" of the provider "${this.id}" printed no address (http:// or https://) last.`);
|
|
1476
|
+
}
|
|
1477
|
+
return { url, token: tenant.token };
|
|
1478
|
+
}
|
|
1479
|
+
async stop(tenant) {
|
|
1480
|
+
if (this.commands.stop) {
|
|
1481
|
+
await this.run(this.commands.stop, tenant);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
async state(tenant) {
|
|
1485
|
+
if (!this.commands.state) {
|
|
1486
|
+
return "missing";
|
|
1487
|
+
}
|
|
1488
|
+
const word = (await this.run(this.commands.state, tenant)).trim().split(/\s+/).pop();
|
|
1489
|
+
return word === "running" || word === "stopped" ? word : "missing";
|
|
1490
|
+
}
|
|
1491
|
+
run(command, tenant) {
|
|
1492
|
+
return new Promise((resolve, reject) => {
|
|
1493
|
+
const child = spawn("sh", ["-c", command], {
|
|
1494
|
+
env: { ...process.env, ...this.env, TA_TENANT_ID: tenant.id, TA_TENANT_ACCOUNT: tenant.account, TA_SERVE_TOKEN: tenant.token },
|
|
1495
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1496
|
+
});
|
|
1497
|
+
let stdout = "";
|
|
1498
|
+
let stderr = "";
|
|
1499
|
+
child.stdout.on("data", (data) => stdout += data);
|
|
1500
|
+
child.stderr.on("data", (data) => stderr += data);
|
|
1501
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), TIMEOUT_MS2);
|
|
1502
|
+
child.on("error", (error) => {
|
|
1503
|
+
clearTimeout(timer);
|
|
1504
|
+
reject(error);
|
|
1505
|
+
});
|
|
1506
|
+
child.on("close", (code) => {
|
|
1507
|
+
clearTimeout(timer);
|
|
1508
|
+
if (code === 0) {
|
|
1509
|
+
resolve(stdout);
|
|
1510
|
+
} else {
|
|
1511
|
+
reject(new Error(`"${command.split(/\s+/)[0]}…" of the provider "${this.id}" exited with ${code}: ${stderr.trim().slice(-300)}`));
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// ../../ta-packages/ta-gateway/esm/node/docker-engine.js
|
|
1519
|
+
import { request } from "node:http";
|
|
1520
|
+
|
|
1521
|
+
class DockerError extends Error {
|
|
1522
|
+
constructor(message, status) {
|
|
1523
|
+
super(message);
|
|
1524
|
+
this.status = status;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
class DockerEngine {
|
|
1529
|
+
constructor(options = {}) {
|
|
1530
|
+
const host = options.host || process.env.DOCKER_HOST || "unix:///var/run/docker.sock";
|
|
1531
|
+
if (host.startsWith("unix://")) {
|
|
1532
|
+
this.target = { socketPath: host.slice("unix://".length) };
|
|
1533
|
+
} else if (host.startsWith("tcp://")) {
|
|
1534
|
+
const url = new URL(`http://${host.slice("tcp://".length)}`);
|
|
1535
|
+
this.target = { host: url.hostname, port: Number(url.port || 2375) };
|
|
1536
|
+
} else {
|
|
1537
|
+
throw new DockerError(`${host} is not a Docker host: write unix://<socket> or tcp://<host>:<port>.`, 0);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
call(method, path, body, timeoutMs = 120000) {
|
|
1541
|
+
return new Promise((resolve, reject) => {
|
|
1542
|
+
const payload = body === undefined ? undefined : JSON.stringify(body);
|
|
1543
|
+
const req = request({
|
|
1544
|
+
...this.target,
|
|
1545
|
+
method,
|
|
1546
|
+
path,
|
|
1547
|
+
headers: payload ? { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(payload) } : {},
|
|
1548
|
+
timeout: timeoutMs
|
|
1549
|
+
}, (res) => {
|
|
1550
|
+
const chunks = [];
|
|
1551
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
1552
|
+
res.on("end", () => {
|
|
1553
|
+
var _a, _b;
|
|
1554
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
1555
|
+
let parsed = text;
|
|
1556
|
+
try {
|
|
1557
|
+
parsed = text ? JSON.parse(text) : undefined;
|
|
1558
|
+
} catch (_c) {}
|
|
1559
|
+
const status = (_a = res.statusCode) !== null && _a !== undefined ? _a : 0;
|
|
1560
|
+
if (status >= 400) {
|
|
1561
|
+
const message = (_b = parsed === null || parsed === undefined ? undefined : parsed.message) !== null && _b !== undefined ? _b : text;
|
|
1562
|
+
reject(new DockerError(`Docker: ${method} ${path.split("?")[0]} answered ${status}: ${message}`, status));
|
|
1563
|
+
} else {
|
|
1564
|
+
resolve({ status, body: parsed });
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
});
|
|
1568
|
+
req.on("timeout", () => req.destroy(new DockerError(`Docker: ${method} ${path} took too long`, 0)));
|
|
1569
|
+
req.on("error", (error) => reject(error instanceof DockerError ? error : new DockerError(`Docker is not reachable (${"socketPath" in this.target ? this.target.socketPath : this.target.host}): ${error.message}`, 0)));
|
|
1570
|
+
req.end(payload);
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
async inspect(name) {
|
|
1574
|
+
try {
|
|
1575
|
+
return (await this.call("GET", `/containers/${encodeURIComponent(name)}/json`)).body;
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
if (error instanceof DockerError && error.status === 404) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
throw error;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
async create(name, spec) {
|
|
1584
|
+
await this.call("POST", `/containers/create?name=${encodeURIComponent(name)}`, spec);
|
|
1585
|
+
}
|
|
1586
|
+
async start(name) {
|
|
1587
|
+
await this.call("POST", `/containers/${encodeURIComponent(name)}/start`);
|
|
1588
|
+
}
|
|
1589
|
+
async stop(name, seconds = 10) {
|
|
1590
|
+
try {
|
|
1591
|
+
await this.call("POST", `/containers/${encodeURIComponent(name)}/stop?t=${seconds}`, undefined, (seconds + 30) * 1000);
|
|
1592
|
+
} catch (error) {
|
|
1593
|
+
if (!(error instanceof DockerError && error.status === 404)) {
|
|
1594
|
+
throw error;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
async ensureNetwork(name, isolated) {
|
|
1599
|
+
try {
|
|
1600
|
+
await this.call("GET", `/networks/${encodeURIComponent(name)}`);
|
|
1601
|
+
return;
|
|
1602
|
+
} catch (error) {
|
|
1603
|
+
if (!(error instanceof DockerError && error.status === 404)) {
|
|
1604
|
+
throw error;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
const options = isolated ? { "com.docker.network.bridge.enable_icc": "false" } : {};
|
|
1608
|
+
await this.call("POST", "/networks/create", { Name: name, Driver: "bridge", Options: options, Labels: { "cell.ta.gateway": "1" } });
|
|
1609
|
+
}
|
|
1610
|
+
async ensureImage(image) {
|
|
1611
|
+
try {
|
|
1612
|
+
await this.call("GET", `/images/${encodeURIComponent(image)}/json`);
|
|
1613
|
+
return;
|
|
1614
|
+
} catch (error) {
|
|
1615
|
+
if (!(error instanceof DockerError && error.status === 404)) {
|
|
1616
|
+
throw error;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
const [repository, tag = "latest"] = DockerEngineUtil.splitImage(image);
|
|
1620
|
+
await this.call("POST", `/images/create?fromImage=${encodeURIComponent(repository)}&tag=${encodeURIComponent(tag)}`, undefined, 30 * 60 * 1000);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
var DockerEngineUtil;
|
|
1624
|
+
(function(DockerEngineUtil2) {
|
|
1625
|
+
function splitImage(image) {
|
|
1626
|
+
const slash = image.lastIndexOf("/");
|
|
1627
|
+
const colon = image.lastIndexOf(":");
|
|
1628
|
+
return colon > slash ? [image.slice(0, colon), image.slice(colon + 1)] : [image];
|
|
1629
|
+
}
|
|
1630
|
+
DockerEngineUtil2.splitImage = splitImage;
|
|
1631
|
+
function bytes(value) {
|
|
1632
|
+
if (value === undefined || value === "") {
|
|
1633
|
+
return;
|
|
1634
|
+
}
|
|
1635
|
+
if (typeof value === "number") {
|
|
1636
|
+
return value;
|
|
1637
|
+
}
|
|
1638
|
+
const match = /^(\d+(?:\.\d+)?)\s*([kmg]?)b?$/i.exec(value.trim());
|
|
1639
|
+
if (!match) {
|
|
1640
|
+
throw new DockerError(`${value} is not an amount of memory: write 512m or 4g.`, 0);
|
|
1641
|
+
}
|
|
1642
|
+
const unit = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[match[2].toLowerCase()];
|
|
1643
|
+
return Math.round(Number(match[1]) * unit);
|
|
1644
|
+
}
|
|
1645
|
+
DockerEngineUtil2.bytes = bytes;
|
|
1646
|
+
})(DockerEngineUtil || (DockerEngineUtil = {}));
|
|
1647
|
+
|
|
1648
|
+
// ../../ta-packages/ta-gateway/esm/node/docker-sandbox.js
|
|
1649
|
+
var DockerSandboxUtil;
|
|
1650
|
+
(function(DockerSandboxUtil2) {
|
|
1651
|
+
function hostname(account) {
|
|
1652
|
+
const name = account.slice(account.indexOf(":") + 1).split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48).replace(/-+$/, "");
|
|
1653
|
+
return name || "ta";
|
|
1654
|
+
}
|
|
1655
|
+
DockerSandboxUtil2.hostname = hostname;
|
|
1656
|
+
})(DockerSandboxUtil || (DockerSandboxUtil = {}));
|
|
1657
|
+
var PORT = "4100/tcp";
|
|
1658
|
+
|
|
1659
|
+
class DockerSandbox {
|
|
1660
|
+
static options(config) {
|
|
1661
|
+
var _a;
|
|
1662
|
+
const number = (key, fallback) => {
|
|
1663
|
+
var _a2;
|
|
1664
|
+
const value = (_a2 = config[key]) !== null && _a2 !== undefined ? _a2 : fallback;
|
|
1665
|
+
if (typeof value !== "number" || value < 0) {
|
|
1666
|
+
throw new Error(`"${key}" of a provider of the type docker is a number.`);
|
|
1667
|
+
}
|
|
1668
|
+
return value || undefined;
|
|
1669
|
+
};
|
|
1670
|
+
return {
|
|
1671
|
+
image: SandboxProviders.string(config, "image", "ta:latest"),
|
|
1672
|
+
host: SandboxProviders.string(config, "host"),
|
|
1673
|
+
memory: DockerEngineUtil.bytes((_a = config.memory) !== null && _a !== undefined ? _a : "4g"),
|
|
1674
|
+
cpus: number("cpus", 2),
|
|
1675
|
+
pids: number("pids", 1024),
|
|
1676
|
+
network: SandboxProviders.string(config, "network", "ta-sandbox"),
|
|
1677
|
+
bind: SandboxProviders.string(config, "bind", "127.0.0.1"),
|
|
1678
|
+
address: SandboxProviders.string(config, "address", "127.0.0.1"),
|
|
1679
|
+
prefix: SandboxProviders.string(config, "prefix", "ta-"),
|
|
1680
|
+
env: SandboxProviders.env(config)
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
constructor(id, config, options = DockerSandbox.options(config), engine) {
|
|
1684
|
+
this.id = id;
|
|
1685
|
+
this.options = options;
|
|
1686
|
+
this.type = "docker";
|
|
1687
|
+
this.name = SandboxProviders.string(config, "name", "Docker");
|
|
1688
|
+
this.engine = engine !== null && engine !== undefined ? engine : new DockerEngine({ host: options.host });
|
|
1689
|
+
}
|
|
1690
|
+
async start(tenant) {
|
|
1691
|
+
var _a, _b, _c;
|
|
1692
|
+
const name = this.containerName(tenant);
|
|
1693
|
+
let container = await this.engine.inspect(name);
|
|
1694
|
+
if (!container) {
|
|
1695
|
+
await this.engine.ensureImage(this.options.image);
|
|
1696
|
+
await this.engine.ensureNetwork(this.options.network, true);
|
|
1697
|
+
await this.engine.create(name, this.spec(tenant));
|
|
1698
|
+
container = await this.engine.inspect(name);
|
|
1699
|
+
}
|
|
1700
|
+
if (!(container === null || container === undefined ? undefined : container.State.Running)) {
|
|
1701
|
+
await this.engine.start(name);
|
|
1702
|
+
container = await this.engine.inspect(name);
|
|
1703
|
+
}
|
|
1704
|
+
const port = (_c = (_b = (_a = container === null || container === undefined ? undefined : container.NetworkSettings.Ports) === null || _a === undefined ? undefined : _a[PORT]) === null || _b === undefined ? undefined : _b[0]) === null || _c === undefined ? undefined : _c.HostPort;
|
|
1705
|
+
if (!port) {
|
|
1706
|
+
throw new Error(`The container ${name} publishes no port for ${PORT}.`);
|
|
1707
|
+
}
|
|
1708
|
+
return { url: `http://${this.options.address}:${port}`, token: tenant.token };
|
|
1709
|
+
}
|
|
1710
|
+
async stop(tenant) {
|
|
1711
|
+
await this.engine.stop(this.containerName(tenant));
|
|
1712
|
+
}
|
|
1713
|
+
async state(tenant) {
|
|
1714
|
+
const container = await this.engine.inspect(this.containerName(tenant));
|
|
1715
|
+
return !container ? "missing" : container.State.Running ? "running" : "stopped";
|
|
1716
|
+
}
|
|
1717
|
+
spec(tenant) {
|
|
1718
|
+
const name = this.containerName(tenant);
|
|
1719
|
+
return {
|
|
1720
|
+
Image: this.options.image,
|
|
1721
|
+
Hostname: DockerSandboxUtil.hostname(tenant.account),
|
|
1722
|
+
Env: [`TA_SERVE_TOKEN=${tenant.token}`, ...Object.entries(this.options.env).map(([key, value]) => `${key}=${value}`)],
|
|
1723
|
+
Labels: { "cell.ta.tenant": tenant.id, "cell.ta.account": tenant.account },
|
|
1724
|
+
ExposedPorts: { [PORT]: {} },
|
|
1725
|
+
HostConfig: {
|
|
1726
|
+
PortBindings: { [PORT]: [{ HostIp: this.options.bind, HostPort: "" }] },
|
|
1727
|
+
Mounts: [{ Type: "volume", Source: name, Target: "/home/ta" }],
|
|
1728
|
+
NetworkMode: this.options.network,
|
|
1729
|
+
Memory: this.options.memory,
|
|
1730
|
+
NanoCpus: this.options.cpus ? Math.round(this.options.cpus * 1e9) : undefined,
|
|
1731
|
+
PidsLimit: this.options.pids,
|
|
1732
|
+
RestartPolicy: { Name: "unless-stopped" },
|
|
1733
|
+
Init: false
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
containerName(tenant) {
|
|
1738
|
+
return `${this.options.prefix}${tenant.id}`;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
// ../../ta-packages/ta-gateway/esm/node/ta-sandbox.js
|
|
1743
|
+
var TaSandboxUtil;
|
|
1744
|
+
(function(TaSandboxUtil2) {
|
|
1745
|
+
function url(text) {
|
|
1746
|
+
let url2;
|
|
1747
|
+
try {
|
|
1748
|
+
url2 = new URL(text.trim());
|
|
1749
|
+
} catch (_a) {
|
|
1750
|
+
throw new Error(`${text} is not an address: write http(s)://<host>[:<port>].`);
|
|
1751
|
+
}
|
|
1752
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:" || url2.username || url2.password || url2.search || url2.hash) {
|
|
1753
|
+
throw new Error(`${text} is not an address of a Ta service: write http(s)://<host>[:<port>].`);
|
|
1754
|
+
}
|
|
1755
|
+
return `${url2.origin}${url2.pathname.replace(/\/+$/, "")}`;
|
|
1756
|
+
}
|
|
1757
|
+
TaSandboxUtil2.url = url;
|
|
1758
|
+
})(TaSandboxUtil || (TaSandboxUtil = {}));
|
|
1759
|
+
|
|
1760
|
+
class TaSandbox {
|
|
1761
|
+
constructor(id, config) {
|
|
1762
|
+
var _a, _b;
|
|
1763
|
+
this.id = id;
|
|
1764
|
+
this.type = "ta";
|
|
1765
|
+
this.readyTimeoutMs = 1e4;
|
|
1766
|
+
this.name = SandboxProviders.string(config, "name", id);
|
|
1767
|
+
this.url = TaSandboxUtil.url((_a = SandboxProviders.string(config, "url")) !== null && _a !== undefined ? _a : "");
|
|
1768
|
+
this.token = (_b = SandboxProviders.string(config, "token")) !== null && _b !== undefined ? _b : "";
|
|
1769
|
+
if (!this.token) {
|
|
1770
|
+
throw new Error("A Ta service is reached with its access token.");
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
async start() {
|
|
1774
|
+
return { url: this.url, token: this.token };
|
|
1775
|
+
}
|
|
1776
|
+
async stop() {}
|
|
1777
|
+
async state() {
|
|
1778
|
+
return "running";
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
// ../../ta-packages/ta-gateway/esm/node/environments.js
|
|
1783
|
+
var READY_TIMEOUT_MS = 120000;
|
|
1784
|
+
|
|
1785
|
+
class EnvironmentError extends Error {
|
|
1786
|
+
}
|
|
1787
|
+
var EnvironmentsUtil;
|
|
1788
|
+
(function(EnvironmentsUtil2) {
|
|
1789
|
+
async function waitReady(url, timeoutMs = READY_TIMEOUT_MS, fetcher = fetch) {
|
|
1790
|
+
var _a;
|
|
1791
|
+
const until = Date.now() + timeoutMs;
|
|
1792
|
+
let last;
|
|
1793
|
+
while (Date.now() < until) {
|
|
1794
|
+
try {
|
|
1795
|
+
const response = await fetcher(`${url}/`, { method: "HEAD", signal: AbortSignal.timeout(5000) });
|
|
1796
|
+
await ((_a = response.body) === null || _a === undefined ? undefined : _a.cancel());
|
|
1797
|
+
return;
|
|
1798
|
+
} catch (error) {
|
|
1799
|
+
last = error;
|
|
1800
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
throw new EnvironmentError(`Nothing answered at ${url} within ${Math.round(timeoutMs / 1000)} seconds${last instanceof Error ? `: ${last.message}` : ""}.`);
|
|
1804
|
+
}
|
|
1805
|
+
EnvironmentsUtil2.waitReady = waitReady;
|
|
1806
|
+
function call(endpoint, method, params = [], timeoutMs = 1e4) {
|
|
1807
|
+
return new Promise((resolve, reject) => {
|
|
1808
|
+
const url = new URL(`${endpoint.url.replace(/^http/, "ws")}${TA_WEBSOCKET_PATH}`);
|
|
1809
|
+
url.searchParams.set("token", endpoint.token);
|
|
1810
|
+
const socket = new WebSocket(url);
|
|
1811
|
+
const timer = setTimeout(() => finish(new EnvironmentError(`${method} took too long`)), timeoutMs);
|
|
1812
|
+
const finish = (error, result) => {
|
|
1813
|
+
clearTimeout(timer);
|
|
1814
|
+
socket.close();
|
|
1815
|
+
if (error) {
|
|
1816
|
+
reject(error);
|
|
1817
|
+
} else {
|
|
1818
|
+
resolve(result);
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
socket.onopen = () => socket.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }));
|
|
1822
|
+
socket.onerror = () => finish(new EnvironmentError(`Cannot reach ${endpoint.url}`));
|
|
1823
|
+
socket.onmessage = (message) => {
|
|
1824
|
+
const answer = JSON.parse(String(message.data));
|
|
1825
|
+
if (answer.id === 1) {
|
|
1826
|
+
finish(answer.error ? new EnvironmentError(answer.error.message) : undefined, answer.result);
|
|
1827
|
+
} else if (answer.method !== undefined && answer.id !== undefined) {
|
|
1828
|
+
socket.send(JSON.stringify({ jsonrpc: "2.0", id: answer.id, result: null }));
|
|
1829
|
+
}
|
|
1830
|
+
};
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
EnvironmentsUtil2.call = call;
|
|
1834
|
+
function sandboxTenant(tenant) {
|
|
1835
|
+
return { id: tenant.id, account: tenant.account, token: tenant.token };
|
|
1836
|
+
}
|
|
1837
|
+
EnvironmentsUtil2.sandboxTenant = sandboxTenant;
|
|
1838
|
+
})(EnvironmentsUtil || (EnvironmentsUtil = {}));
|
|
1839
|
+
|
|
1840
|
+
class Environments {
|
|
1841
|
+
constructor(providers, tenants, settings) {
|
|
1842
|
+
this.providers = providers;
|
|
1843
|
+
this.tenants = tenants;
|
|
1844
|
+
this.settings = settings;
|
|
1845
|
+
this.running = new Map;
|
|
1846
|
+
}
|
|
1847
|
+
choices() {
|
|
1848
|
+
return this.providers.map(({ id, name, type }) => ({ id, name, type }));
|
|
1849
|
+
}
|
|
1850
|
+
provider(tenant) {
|
|
1851
|
+
var _a;
|
|
1852
|
+
var _b, _c, _d, _e;
|
|
1853
|
+
const choice = tenant.environment;
|
|
1854
|
+
if (choice && "type" in choice) {
|
|
1855
|
+
return {
|
|
1856
|
+
provider: new TaSandbox("own", { type: "ta", url: choice.url, token: choice.token, name: (_b = choice.name) !== null && _b !== undefined ? _b : new URL(choice.url).host }),
|
|
1857
|
+
own: true
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
const id = (_d = (_c = choice === null || choice === undefined ? undefined : choice.provider) !== null && _c !== undefined ? _c : this.settings.default) !== null && _d !== undefined ? _d : (_a = this.providers[0]) === null || _a === undefined ? undefined : _a.id;
|
|
1861
|
+
const provider = (_e = this.providers.find((one) => one.id === id)) !== null && _e !== undefined ? _e : this.providers.find((one) => one.id === this.settings.default);
|
|
1862
|
+
if (!provider) {
|
|
1863
|
+
throw new EnvironmentError("The gateway has no provider of sandboxes: add one to sandboxes.json, or use a Ta service of your own.");
|
|
1864
|
+
}
|
|
1865
|
+
return { provider, own: false };
|
|
1866
|
+
}
|
|
1867
|
+
info(tenant) {
|
|
1868
|
+
var _a;
|
|
1869
|
+
const running = this.running.get(tenant.id);
|
|
1870
|
+
let picked;
|
|
1871
|
+
try {
|
|
1872
|
+
picked = this.provider(tenant);
|
|
1873
|
+
} catch (error) {
|
|
1874
|
+
return { provider: "", name: "", status: "failed", error: error.message };
|
|
1875
|
+
}
|
|
1876
|
+
const { provider, own } = picked;
|
|
1877
|
+
return {
|
|
1878
|
+
provider: own ? "own" : provider.id,
|
|
1879
|
+
name: provider.name,
|
|
1880
|
+
status: (_a = running === null || running === undefined ? undefined : running.status) !== null && _a !== undefined ? _a : "stopped",
|
|
1881
|
+
error: running === null || running === undefined ? undefined : running.error,
|
|
1882
|
+
url: own && provider instanceof TaSandbox ? provider.url : undefined
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
connections(tenantId) {
|
|
1886
|
+
var _a;
|
|
1887
|
+
var _b;
|
|
1888
|
+
return (_b = (_a = this.running.get(tenantId)) === null || _a === undefined ? undefined : _a.connections) !== null && _b !== undefined ? _b : 0;
|
|
1889
|
+
}
|
|
1890
|
+
ensure(tenant) {
|
|
1891
|
+
const running = this.state(tenant.id);
|
|
1892
|
+
if (running.status === "running" && running.endpoint) {
|
|
1893
|
+
return Promise.resolve(running.endpoint);
|
|
1894
|
+
}
|
|
1895
|
+
if (running.starting) {
|
|
1896
|
+
return running.starting;
|
|
1897
|
+
}
|
|
1898
|
+
running.status = "starting";
|
|
1899
|
+
running.error = undefined;
|
|
1900
|
+
const starting = (async () => {
|
|
1901
|
+
var _a;
|
|
1902
|
+
const { provider } = this.provider(tenant);
|
|
1903
|
+
const endpoint = await provider.start(EnvironmentsUtil.sandboxTenant(tenant));
|
|
1904
|
+
await EnvironmentsUtil.waitReady(endpoint.url, (_a = this.settings.readyTimeoutMs) !== null && _a !== undefined ? _a : provider.readyTimeoutMs);
|
|
1905
|
+
return endpoint;
|
|
1906
|
+
})();
|
|
1907
|
+
running.starting = starting;
|
|
1908
|
+
starting.then((endpoint) => {
|
|
1909
|
+
if (running.starting === starting) {
|
|
1910
|
+
Object.assign(running, { status: "running", endpoint, starting: undefined });
|
|
1911
|
+
}
|
|
1912
|
+
}, (error) => {
|
|
1913
|
+
if (running.starting === starting) {
|
|
1914
|
+
Object.assign(running, { status: "failed", error: error.message, endpoint: undefined, starting: undefined });
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
return starting;
|
|
1918
|
+
}
|
|
1919
|
+
lost(tenantId) {
|
|
1920
|
+
const running = this.running.get(tenantId);
|
|
1921
|
+
if (running && !running.starting) {
|
|
1922
|
+
Object.assign(running, { status: "stopped", endpoint: undefined });
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
connect(tenantId) {
|
|
1926
|
+
const running = this.state(tenantId);
|
|
1927
|
+
running.connections++;
|
|
1928
|
+
clearTimeout(running.idle);
|
|
1929
|
+
let done = false;
|
|
1930
|
+
return () => {
|
|
1931
|
+
var _a, _b;
|
|
1932
|
+
if (done) {
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
done = true;
|
|
1936
|
+
running.connections--;
|
|
1937
|
+
const minutes = this.settings.idleMinutes;
|
|
1938
|
+
if (running.connections === 0 && minutes > 0) {
|
|
1939
|
+
running.idle = setTimeout(() => void this.stop(tenantId).catch(() => {
|
|
1940
|
+
return;
|
|
1941
|
+
}), minutes * 60000);
|
|
1942
|
+
(_b = (_a = running.idle).unref) === null || _b === undefined || _b.call(_a);
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
async stop(tenantId) {
|
|
1947
|
+
var _a;
|
|
1948
|
+
const tenant = this.tenants.get(tenantId);
|
|
1949
|
+
if (!tenant) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
const running = this.state(tenantId);
|
|
1953
|
+
await ((_a = running.starting) === null || _a === undefined ? undefined : _a.catch(() => {
|
|
1954
|
+
return;
|
|
1955
|
+
}));
|
|
1956
|
+
Object.assign(running, { status: "stopped", endpoint: undefined, error: undefined });
|
|
1957
|
+
await this.provider(tenant).provider.stop(EnvironmentsUtil.sandboxTenant(tenant));
|
|
1958
|
+
}
|
|
1959
|
+
async revoke(tenant) {
|
|
1960
|
+
const { provider, own } = this.provider(tenant);
|
|
1961
|
+
if (own) {
|
|
1962
|
+
return 0;
|
|
1963
|
+
}
|
|
1964
|
+
let unpaired = 0;
|
|
1965
|
+
if (await provider.state(EnvironmentsUtil.sandboxTenant(tenant)) === "running") {
|
|
1966
|
+
const endpoint = await provider.start(EnvironmentsUtil.sandboxTenant(tenant));
|
|
1967
|
+
const info = await EnvironmentsUtil.call(endpoint, "TaRelayServer/getRelay");
|
|
1968
|
+
for (const device of info.devices) {
|
|
1969
|
+
await EnvironmentsUtil.call(endpoint, "TaRelayServer/unpair", [device.id]);
|
|
1970
|
+
unpaired++;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
await this.stop(tenant.id);
|
|
1974
|
+
return unpaired;
|
|
1975
|
+
}
|
|
1976
|
+
async change(tenant, choice) {
|
|
1977
|
+
await this.stop(tenant.id).catch(() => {
|
|
1978
|
+
return;
|
|
1979
|
+
});
|
|
1980
|
+
const next = this.tenants.update(tenant.id, { environment: choice });
|
|
1981
|
+
this.provider(next);
|
|
1982
|
+
this.running.delete(tenant.id);
|
|
1983
|
+
return next;
|
|
1984
|
+
}
|
|
1985
|
+
async dispose() {
|
|
1986
|
+
for (const running of this.running.values()) {
|
|
1987
|
+
clearTimeout(running.idle);
|
|
1988
|
+
}
|
|
1989
|
+
await Promise.all(this.providers.map((provider) => {
|
|
1990
|
+
var _a;
|
|
1991
|
+
return (_a = provider.dispose) === null || _a === undefined ? undefined : _a.call(provider);
|
|
1992
|
+
}));
|
|
1993
|
+
}
|
|
1994
|
+
state(tenantId) {
|
|
1995
|
+
let running = this.running.get(tenantId);
|
|
1996
|
+
if (!running) {
|
|
1997
|
+
running = { status: "stopped", connections: 0 };
|
|
1998
|
+
this.running.set(tenantId, running);
|
|
1999
|
+
}
|
|
2000
|
+
return running;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-service.js
|
|
2005
|
+
class GatewayCallError extends Error {
|
|
2006
|
+
constructor(message, code, hint) {
|
|
2007
|
+
super(message);
|
|
2008
|
+
this.code = code;
|
|
2009
|
+
this.hint = hint;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
var GatewayServiceUtil;
|
|
2013
|
+
(function(GatewayServiceUtil2) {
|
|
2014
|
+
GatewayServiceUtil2.SERVICES = ["TaGatewayServer", "TaAccessServer"];
|
|
2015
|
+
function owns(method) {
|
|
2016
|
+
return typeof method === "string" && GatewayServiceUtil2.SERVICES.includes(method.split("/")[0]);
|
|
2017
|
+
}
|
|
2018
|
+
GatewayServiceUtil2.owns = owns;
|
|
2019
|
+
function error(id, message, code, hint) {
|
|
2020
|
+
return JSON.stringify({ jsonrpc: "2.0", id, error: { code: TA_RPC_ERROR_CODE, message, data: { kind: "application", data: { code, hint } } } });
|
|
2021
|
+
}
|
|
2022
|
+
GatewayServiceUtil2.error = error;
|
|
2023
|
+
function result(id, result2) {
|
|
2024
|
+
return JSON.stringify({ jsonrpc: "2.0", id, result: result2 !== null && result2 !== undefined ? result2 : null });
|
|
2025
|
+
}
|
|
2026
|
+
GatewayServiceUtil2.result = result;
|
|
2027
|
+
function invalid(message, hint) {
|
|
2028
|
+
return new GatewayCallError(message, TaErrorCode.INVALID_ARGUMENT, hint);
|
|
2029
|
+
}
|
|
2030
|
+
function choice(value, own, providers) {
|
|
2031
|
+
var _a;
|
|
2032
|
+
const given = value !== null && value !== undefined ? value : {};
|
|
2033
|
+
if (typeof given.provider === "string") {
|
|
2034
|
+
if (!providers.includes(given.provider)) {
|
|
2035
|
+
throw invalid(`The gateway has no provider ${given.provider}.`, "Pick one of the options of getGateway.");
|
|
2036
|
+
}
|
|
2037
|
+
return { provider: given.provider };
|
|
2038
|
+
}
|
|
2039
|
+
if (given.type === "ta") {
|
|
2040
|
+
if (!own) {
|
|
2041
|
+
throw invalid("This gateway runs Ta in its own sandboxes only.", "Pick one of the options of getGateway.");
|
|
2042
|
+
}
|
|
2043
|
+
let url;
|
|
2044
|
+
try {
|
|
2045
|
+
url = TaSandboxUtil.url(String((_a = given.url) !== null && _a !== undefined ? _a : ""));
|
|
2046
|
+
} catch (error2) {
|
|
2047
|
+
throw invalid(error2.message, "Write the address its Ta service is reached at, such as https://ta.example.com.");
|
|
2048
|
+
}
|
|
2049
|
+
if (typeof given.token !== "string" || !given.token.trim()) {
|
|
2050
|
+
throw invalid("A Ta service of your own is reached with its access token.", "Copy it from ~/.ta/agent/serve.json there, or the link ta serve printed.");
|
|
2051
|
+
}
|
|
2052
|
+
return { type: "ta", url, token: given.token.trim(), name: typeof given.name === "string" && given.name.trim() ? given.name.trim() : undefined };
|
|
2053
|
+
}
|
|
2054
|
+
throw invalid("No environment was named.", 'Pass { provider } or { type: "ta", url, token }.');
|
|
2055
|
+
}
|
|
2056
|
+
GatewayServiceUtil2.choice = choice;
|
|
2057
|
+
})(GatewayServiceUtil || (GatewayServiceUtil = {}));
|
|
2058
|
+
|
|
2059
|
+
class GatewayService {
|
|
2060
|
+
constructor(flow, tenants, environments, hooks) {
|
|
2061
|
+
this.flow = flow;
|
|
2062
|
+
this.tenants = tenants;
|
|
2063
|
+
this.environments = environments;
|
|
2064
|
+
this.hooks = hooks;
|
|
2065
|
+
}
|
|
2066
|
+
async call(caller, method, params) {
|
|
2067
|
+
const [service, name] = method.split("/");
|
|
2068
|
+
const handlers = service === "TaGatewayServer" ? {
|
|
2069
|
+
getGateway: async () => this.info(caller),
|
|
2070
|
+
setEnvironment: async (choice) => this.setEnvironment(caller, choice),
|
|
2071
|
+
restartEnvironment: async () => this.restart(caller),
|
|
2072
|
+
listTenants: async () => this.listTenants(caller),
|
|
2073
|
+
stopTenant: async (id) => this.stopTenant(caller, id)
|
|
2074
|
+
} : {
|
|
2075
|
+
getAccess: async () => this.access(caller),
|
|
2076
|
+
bindUrl: async (provider) => this.admin(caller, () => this.flow.bindUrl(String(provider))),
|
|
2077
|
+
allow: async (account, name2) => this.admin(caller, () => this.allow(account, name2)),
|
|
2078
|
+
dismiss: async (account) => this.admin(caller, () => this.flow.store.dismiss(String(account))),
|
|
2079
|
+
disallow: async (account) => this.admin(caller, () => this.disallow(String(account))),
|
|
2080
|
+
signOut: async (id) => this.signOut(caller, String(id))
|
|
2081
|
+
};
|
|
2082
|
+
const handler = new Map(Object.entries(handlers)).get(name);
|
|
2083
|
+
if (!handler) {
|
|
2084
|
+
throw new GatewayCallError(`${method} is not a method of the gateway.`, TaErrorCode.INVALID_ARGUMENT, "Call a method of TaGatewayServer or TaAccessServer.");
|
|
2085
|
+
}
|
|
2086
|
+
return handler(...params);
|
|
2087
|
+
}
|
|
2088
|
+
info(caller) {
|
|
2089
|
+
var _a;
|
|
2090
|
+
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== undefined ? _a : caller.tenant;
|
|
2091
|
+
return {
|
|
2092
|
+
account: { id: tenant.account, name: tenant.name, avatar: tenant.avatar },
|
|
2093
|
+
tenant: tenant.id,
|
|
2094
|
+
environment: this.environments.info(tenant),
|
|
2095
|
+
options: this.environments.choices(),
|
|
2096
|
+
own: this.ownAllowed(),
|
|
2097
|
+
admin: caller.admin
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
ownAllowed() {
|
|
2101
|
+
return this.environments.settings.own;
|
|
2102
|
+
}
|
|
2103
|
+
async setEnvironment(caller, value) {
|
|
2104
|
+
var _a;
|
|
2105
|
+
const choice = GatewayServiceUtil.choice(value, this.ownAllowed(), this.environments.providers.map((provider) => provider.id));
|
|
2106
|
+
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== undefined ? _a : caller.tenant;
|
|
2107
|
+
const next = await this.environments.change(tenant, choice);
|
|
2108
|
+
caller.tenant = next;
|
|
2109
|
+
this.hooks.reset(next.id);
|
|
2110
|
+
return this.info(caller);
|
|
2111
|
+
}
|
|
2112
|
+
async restart(caller) {
|
|
2113
|
+
await this.environments.stop(caller.tenant.id).catch(() => {
|
|
2114
|
+
return;
|
|
2115
|
+
});
|
|
2116
|
+
this.hooks.reset(caller.tenant.id);
|
|
2117
|
+
return this.info(caller);
|
|
2118
|
+
}
|
|
2119
|
+
async listTenants(caller) {
|
|
2120
|
+
return this.admin(caller, () => this.tenants.list().map((tenant) => ({
|
|
2121
|
+
id: tenant.id,
|
|
2122
|
+
account: tenant.account,
|
|
2123
|
+
name: tenant.name,
|
|
2124
|
+
environment: this.environments.info(tenant),
|
|
2125
|
+
connections: this.environments.connections(tenant.id),
|
|
2126
|
+
createdAt: tenant.createdAt,
|
|
2127
|
+
lastActiveAt: tenant.lastActiveAt
|
|
2128
|
+
})));
|
|
2129
|
+
}
|
|
2130
|
+
async stopTenant(caller, id) {
|
|
2131
|
+
await this.admin(caller, () => this.environments.stop(String(id)));
|
|
2132
|
+
this.hooks.reset(String(id));
|
|
2133
|
+
}
|
|
2134
|
+
access(caller) {
|
|
2135
|
+
const providers = this.flow.providers.map(({ id, name }) => ({ id, name }));
|
|
2136
|
+
const info = this.flow.store.info(caller.token);
|
|
2137
|
+
if (caller.admin) {
|
|
2138
|
+
return { providers, canManage: true, ...info };
|
|
2139
|
+
}
|
|
2140
|
+
return { providers, canManage: false, accounts: [], requests: [], signIns: info.signIns.filter((signIn) => signIn.account === caller.account) };
|
|
2141
|
+
}
|
|
2142
|
+
allow(account, name) {
|
|
2143
|
+
if (typeof account !== "string" || !/^[a-z][a-z0-9-]*:\S+$/.test(account.trim())) {
|
|
2144
|
+
throw new GatewayCallError(`${account} is not an account.`, TaErrorCode.INVALID_ARGUMENT, "Write it <provider>:<login or address>, such as github:octocat.");
|
|
2145
|
+
}
|
|
2146
|
+
this.flow.store.allow(account.trim(), typeof name === "string" ? name : undefined);
|
|
2147
|
+
}
|
|
2148
|
+
async disallow(account) {
|
|
2149
|
+
this.flow.store.disallow(AccessUtil.normalize(account));
|
|
2150
|
+
this.hooks.cutOff();
|
|
2151
|
+
for (const tenant of this.tenants.list().filter((one) => !this.flow.store.allows(one.account))) {
|
|
2152
|
+
const unpaired = await this.environments.revoke(tenant).catch((error) => {
|
|
2153
|
+
console.warn(`ta gateway: revoking ${tenant.account} failed: ${error.message}`);
|
|
2154
|
+
return 0;
|
|
2155
|
+
});
|
|
2156
|
+
console.log(`ta gateway: ${tenant.account} is no longer let in: its sandbox stopped, ${unpaired} paired devices removed`);
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
async signOut(caller, id) {
|
|
2160
|
+
const own = this.flow.store.info(caller.token).signIns.find((signIn) => signIn.id === id);
|
|
2161
|
+
if (!caller.admin && (own === null || own === undefined ? undefined : own.account) !== caller.account) {
|
|
2162
|
+
throw new GatewayCallError("That sign-in is not yours.", TaErrorCode.INVALID_ARGUMENT, "Sign out of the browsers of your own account.");
|
|
2163
|
+
}
|
|
2164
|
+
this.flow.store.signOut(id);
|
|
2165
|
+
this.hooks.cutOff();
|
|
2166
|
+
}
|
|
2167
|
+
async admin(caller, action) {
|
|
2168
|
+
if (!caller.admin) {
|
|
2169
|
+
throw new GatewayCallError("Only administrators of the gateway may do that.", TaErrorCode.INVALID_ARGUMENT, "Ask one of those of TA_GATEWAY_ADMINS.");
|
|
2170
|
+
}
|
|
2171
|
+
return action();
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-socket.js
|
|
2176
|
+
var MAX_QUEUED = 256;
|
|
2177
|
+
|
|
2178
|
+
class GatewaySocket {
|
|
2179
|
+
constructor(browser, caller, environments, service) {
|
|
2180
|
+
this.browser = browser;
|
|
2181
|
+
this.caller = caller;
|
|
2182
|
+
this.environments = environments;
|
|
2183
|
+
this.service = service;
|
|
2184
|
+
this.queued = [];
|
|
2185
|
+
this.closed = false;
|
|
2186
|
+
this.answering = 0;
|
|
2187
|
+
this.release = environments.connect(caller.tenant.id);
|
|
2188
|
+
browser.onMessage((text) => this.fromBrowser(text));
|
|
2189
|
+
browser.onClose(() => this.dispose());
|
|
2190
|
+
this.open();
|
|
2191
|
+
}
|
|
2192
|
+
get tenantId() {
|
|
2193
|
+
return this.caller.tenant.id;
|
|
2194
|
+
}
|
|
2195
|
+
close(code, reason) {
|
|
2196
|
+
this.browser.close(code, reason);
|
|
2197
|
+
this.dispose();
|
|
2198
|
+
}
|
|
2199
|
+
async open() {
|
|
2200
|
+
let endpoint;
|
|
2201
|
+
try {
|
|
2202
|
+
endpoint = await this.environments.ensure(this.caller.tenant);
|
|
2203
|
+
} catch (error) {
|
|
2204
|
+
this.fail(error.message);
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
if (this.closed) {
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
const url = new URL(`${endpoint.url.replace(/^http/, "ws")}${TA_WEBSOCKET_PATH}`);
|
|
2211
|
+
url.searchParams.set("token", endpoint.token);
|
|
2212
|
+
const inner = new WebSocket(url);
|
|
2213
|
+
this.inner = inner;
|
|
2214
|
+
inner.onopen = () => {
|
|
2215
|
+
for (const text of this.queued.splice(0)) {
|
|
2216
|
+
inner.send(text);
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
inner.onmessage = (message) => this.browser.open && this.browser.send(String(message.data));
|
|
2220
|
+
inner.onclose = (event) => {
|
|
2221
|
+
if (this.closed) {
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
this.environments.lost(this.tenantId);
|
|
2225
|
+
const reason = `The environment went away (${event.code}).`;
|
|
2226
|
+
if (this.answering > 0) {
|
|
2227
|
+
this.closeAfterAnswers = reason;
|
|
2228
|
+
} else {
|
|
2229
|
+
this.close(1012, reason);
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
fromBrowser(text) {
|
|
2234
|
+
var _a;
|
|
2235
|
+
let message;
|
|
2236
|
+
try {
|
|
2237
|
+
message = JSON.parse(text);
|
|
2238
|
+
} catch (_b) {
|
|
2239
|
+
this.close(1007, "Not JSON.");
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2242
|
+
if (GatewayServiceUtil.owns(message.method)) {
|
|
2243
|
+
this.answer(message.id, message.method, Array.isArray(message.params) ? message.params : []);
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
if (this.failure !== undefined) {
|
|
2247
|
+
if (message.method !== undefined && message.id !== undefined) {
|
|
2248
|
+
this.browser.send(GatewayServiceUtil.error(message.id, `Your environment did not start: ${this.failure}`, TaErrorCode.ENVIRONMENT_FAILED, "Restart it, or pick another (TaGatewayServer)."));
|
|
2249
|
+
}
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
2252
|
+
if (((_a = this.inner) === null || _a === undefined ? undefined : _a.readyState) === WebSocket.OPEN) {
|
|
2253
|
+
this.inner.send(text);
|
|
2254
|
+
} else if (this.queued.length < MAX_QUEUED) {
|
|
2255
|
+
this.queued.push(text);
|
|
2256
|
+
} else {
|
|
2257
|
+
this.close(1013, "The environment is still starting.");
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
async answer(id, method, params) {
|
|
2261
|
+
let reply;
|
|
2262
|
+
this.answering++;
|
|
2263
|
+
try {
|
|
2264
|
+
reply = GatewayServiceUtil.result(id, await this.service.call(this.caller, method, params));
|
|
2265
|
+
} catch (error) {
|
|
2266
|
+
const known = error instanceof GatewayCallError;
|
|
2267
|
+
reply = GatewayServiceUtil.error(id, error.message, known ? error.code : TaErrorCode.COMMAND_FAILED, known ? error.hint : "The gateway could not do it; try again.");
|
|
2268
|
+
}
|
|
2269
|
+
this.answering--;
|
|
2270
|
+
if (id !== undefined && this.browser.open) {
|
|
2271
|
+
this.browser.send(reply);
|
|
2272
|
+
}
|
|
2273
|
+
if (this.answering === 0 && this.closeAfterAnswers) {
|
|
2274
|
+
this.close(1012, this.closeAfterAnswers);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
fail(reason) {
|
|
2278
|
+
this.failure = reason;
|
|
2279
|
+
for (const text of this.queued.splice(0)) {
|
|
2280
|
+
this.fromBrowser(text);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
dispose() {
|
|
2284
|
+
var _a;
|
|
2285
|
+
if (this.closed) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
this.closed = true;
|
|
2289
|
+
this.release();
|
|
2290
|
+
(_a = this.inner) === null || _a === undefined || _a.close();
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
// ../../ta-packages/ta-gateway/esm/node/local-sandbox.js
|
|
2295
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
2296
|
+
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
2297
|
+
import { createServer } from "node:net";
|
|
2298
|
+
import { join as join2 } from "node:path";
|
|
2299
|
+
class LocalSandbox {
|
|
2300
|
+
constructor(id, config, context) {
|
|
2301
|
+
this.id = id;
|
|
2302
|
+
this.context = context;
|
|
2303
|
+
this.type = "local";
|
|
2304
|
+
this.running = new Map;
|
|
2305
|
+
this.name = SandboxProviders.string(config, "name", "Local");
|
|
2306
|
+
}
|
|
2307
|
+
async start(tenant) {
|
|
2308
|
+
const running = this.running.get(tenant.id);
|
|
2309
|
+
if (running && running.child.exitCode === null) {
|
|
2310
|
+
return { url: running.url, token: tenant.token };
|
|
2311
|
+
}
|
|
2312
|
+
const root = join2(this.context.dir, "local", tenant.id);
|
|
2313
|
+
const agentDir = join2(root, "agent");
|
|
2314
|
+
const cwd = join2(root, "workspace");
|
|
2315
|
+
mkdirSync2(agentDir, { recursive: true });
|
|
2316
|
+
mkdirSync2(cwd, { recursive: true });
|
|
2317
|
+
const port = await LocalSandbox.freePort();
|
|
2318
|
+
const [command, ...args] = this.context.taCommand;
|
|
2319
|
+
const child = spawn2(command, [...args, "serve", "--port", String(port)], {
|
|
2320
|
+
cwd,
|
|
2321
|
+
env: { ...process.env, TA_CODING_AGENT_DIR: agentDir, TA_SERVE_TOKEN: tenant.token, CELL_SERVER__HOST: "127.0.0.1" },
|
|
2322
|
+
stdio: "ignore"
|
|
2323
|
+
});
|
|
2324
|
+
const url = `http://127.0.0.1:${port}`;
|
|
2325
|
+
this.running.set(tenant.id, { child, url });
|
|
2326
|
+
child.once("exit", () => {
|
|
2327
|
+
var _a;
|
|
2328
|
+
if (((_a = this.running.get(tenant.id)) === null || _a === undefined ? undefined : _a.child) === child) {
|
|
2329
|
+
this.running.delete(tenant.id);
|
|
2330
|
+
}
|
|
2331
|
+
});
|
|
2332
|
+
return { url, token: tenant.token };
|
|
2333
|
+
}
|
|
2334
|
+
async stop(tenant) {
|
|
2335
|
+
const running = this.running.get(tenant.id);
|
|
2336
|
+
this.running.delete(tenant.id);
|
|
2337
|
+
if (running && running.child.exitCode === null) {
|
|
2338
|
+
await new Promise((done) => {
|
|
2339
|
+
running.child.once("exit", () => done());
|
|
2340
|
+
running.child.kill("SIGTERM");
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
async state(tenant) {
|
|
2345
|
+
return this.running.has(tenant.id) ? "running" : "stopped";
|
|
2346
|
+
}
|
|
2347
|
+
async dispose() {
|
|
2348
|
+
await Promise.all([...this.running.keys()].map((id) => this.stop({ id, account: "", token: "" })));
|
|
2349
|
+
}
|
|
2350
|
+
static freePort() {
|
|
2351
|
+
return new Promise((resolve, reject) => {
|
|
2352
|
+
const server = createServer();
|
|
2353
|
+
server.once("error", reject);
|
|
2354
|
+
server.listen(0, "127.0.0.1", () => {
|
|
2355
|
+
const { port } = server.address();
|
|
2356
|
+
server.close(() => resolve(port));
|
|
2357
|
+
});
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// ../../ta-packages/ta-gateway/esm/node/sign-in-links.js
|
|
2363
|
+
import { createHash as createHash5, randomBytes as randomBytes4 } from "node:crypto";
|
|
2364
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
2365
|
+
import { join as join4 } from "node:path";
|
|
2366
|
+
|
|
2367
|
+
// ../../ta-packages/ta-gateway/esm/node/tenant-store.js
|
|
2368
|
+
import { createHash as createHash4, randomBytes as randomBytes3 } from "node:crypto";
|
|
2369
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync3, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2370
|
+
import { join as join3 } from "node:path";
|
|
2371
|
+
function writePrivate(file, data) {
|
|
2372
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
2373
|
+
writeFileSync2(temporary, JSON.stringify(data, undefined, 2), { mode: 384 });
|
|
2374
|
+
chmodSync2(temporary, 384);
|
|
2375
|
+
renameSync2(temporary, file);
|
|
2376
|
+
}
|
|
2377
|
+
var TenantUtil;
|
|
2378
|
+
(function(TenantUtil2) {
|
|
2379
|
+
function id(account) {
|
|
2380
|
+
return createHash4("sha256").update(account).digest("hex").slice(0, 16);
|
|
2381
|
+
}
|
|
2382
|
+
TenantUtil2.id = id;
|
|
2383
|
+
})(TenantUtil || (TenantUtil = {}));
|
|
2384
|
+
|
|
2385
|
+
class TenantStore {
|
|
2386
|
+
constructor(root) {
|
|
2387
|
+
this.cache = new Map;
|
|
2388
|
+
this.dir = join3(root, "tenants");
|
|
2389
|
+
mkdirSync3(this.dir, { recursive: true, mode: 448 });
|
|
2390
|
+
}
|
|
2391
|
+
get(id) {
|
|
2392
|
+
if (!/^[0-9a-f]{16}$/.test(id)) {
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
let tenant = this.cache.get(id);
|
|
2396
|
+
if (!tenant) {
|
|
2397
|
+
try {
|
|
2398
|
+
tenant = JSON.parse(readFileSync3(join3(this.dir, `${id}.json`), "utf8"));
|
|
2399
|
+
this.cache.set(id, tenant);
|
|
2400
|
+
} catch (_a) {
|
|
2401
|
+
return;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
return tenant;
|
|
2405
|
+
}
|
|
2406
|
+
ensure(account, now = Date.now()) {
|
|
2407
|
+
const id = TenantUtil.id(account.id);
|
|
2408
|
+
const known = this.get(id);
|
|
2409
|
+
if (known) {
|
|
2410
|
+
if (account.name && (known.name !== account.name || known.avatar !== account.avatar)) {
|
|
2411
|
+
return this.update(id, { name: account.name, avatar: account.avatar });
|
|
2412
|
+
}
|
|
2413
|
+
return known;
|
|
2414
|
+
}
|
|
2415
|
+
const tenant = {
|
|
2416
|
+
id,
|
|
2417
|
+
account: account.id,
|
|
2418
|
+
name: account.name,
|
|
2419
|
+
avatar: account.avatar,
|
|
2420
|
+
token: randomBytes3(32).toString("base64url"),
|
|
2421
|
+
createdAt: now
|
|
2422
|
+
};
|
|
2423
|
+
this.save(tenant);
|
|
2424
|
+
return tenant;
|
|
2425
|
+
}
|
|
2426
|
+
update(id, change) {
|
|
2427
|
+
const tenant = this.get(id);
|
|
2428
|
+
if (!tenant) {
|
|
2429
|
+
throw new Error(`No tenant ${id}`);
|
|
2430
|
+
}
|
|
2431
|
+
const next = { ...tenant, ...change };
|
|
2432
|
+
this.save(next);
|
|
2433
|
+
return next;
|
|
2434
|
+
}
|
|
2435
|
+
list() {
|
|
2436
|
+
return readdirSync(this.dir).filter((name) => /^[0-9a-f]{16}\.json$/.test(name)).map((name) => this.get(name.slice(0, -5))).filter((tenant) => tenant !== undefined);
|
|
2437
|
+
}
|
|
2438
|
+
save(tenant) {
|
|
2439
|
+
writePrivate(join3(this.dir, `${tenant.id}.json`), tenant);
|
|
2440
|
+
this.cache.set(tenant.id, tenant);
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// ../../ta-packages/ta-gateway/esm/node/sign-in-links.js
|
|
2445
|
+
var SIGN_IN_LINK_PATH = "/sign-in/link/";
|
|
2446
|
+
var hash = (secret) => createHash5("sha256").update(secret).digest("base64url");
|
|
2447
|
+
|
|
2448
|
+
class SignInLinks {
|
|
2449
|
+
constructor(dir) {
|
|
2450
|
+
this.file = join4(dir, "links.json");
|
|
2451
|
+
}
|
|
2452
|
+
create(account, name, ttlMs = 24 * 3600 * 1000, now = Date.now()) {
|
|
2453
|
+
if (!/^[a-z][a-z0-9-]*:\S+$/.test(account)) {
|
|
2454
|
+
throw new Error(`${account} is not an account: write <kind>:<name>, such as github:octocat or user:alice.`);
|
|
2455
|
+
}
|
|
2456
|
+
const secret = randomBytes4(24).toString("base64url");
|
|
2457
|
+
const links = this.read(now);
|
|
2458
|
+
links.push({ hash: hash(secret), account, name, expiresAt: now + ttlMs });
|
|
2459
|
+
writePrivate(this.file, links);
|
|
2460
|
+
return `${SIGN_IN_LINK_PATH}${secret}`;
|
|
2461
|
+
}
|
|
2462
|
+
use(secret, now = Date.now()) {
|
|
2463
|
+
const links = this.read(now);
|
|
2464
|
+
const link = links.find((one) => one.hash === hash(secret));
|
|
2465
|
+
writePrivate(this.file, links.filter((one) => one !== link));
|
|
2466
|
+
return link && { account: link.account, name: link.name };
|
|
2467
|
+
}
|
|
2468
|
+
read(now) {
|
|
2469
|
+
try {
|
|
2470
|
+
const links = JSON.parse(readFileSync4(this.file, "utf8"));
|
|
2471
|
+
return Array.isArray(links) ? links.filter((link) => link.expiresAt > now) : [];
|
|
2472
|
+
} catch (_a) {
|
|
2473
|
+
return [];
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-server.js
|
|
2479
|
+
var FILES_COOKIE = "ta_gateway";
|
|
2480
|
+
var TYPES = {
|
|
2481
|
+
".html": "text/html; charset=utf-8",
|
|
2482
|
+
".js": "text/javascript",
|
|
2483
|
+
".mjs": "text/javascript",
|
|
2484
|
+
".css": "text/css",
|
|
2485
|
+
".json": "application/json",
|
|
2486
|
+
".webmanifest": "application/manifest+json",
|
|
2487
|
+
".svg": "image/svg+xml",
|
|
2488
|
+
".png": "image/png",
|
|
2489
|
+
".ico": "image/x-icon",
|
|
2490
|
+
".woff2": "font/woff2",
|
|
2491
|
+
".wasm": "application/wasm",
|
|
2492
|
+
".ttf": "font/ttf"
|
|
2493
|
+
};
|
|
2494
|
+
var SANDBOX_TYPES = {
|
|
2495
|
+
docker: (id, config) => new DockerSandbox(id, config),
|
|
2496
|
+
command: (id, config) => new CommandSandbox(id, config),
|
|
2497
|
+
local: (id, config, context) => new LocalSandbox(id, config, context),
|
|
2498
|
+
ta: (id, config) => new TaSandbox(id, config)
|
|
2499
|
+
};
|
|
2500
|
+
var GatewayServerUtil;
|
|
2501
|
+
(function(GatewayServerUtil2) {
|
|
2502
|
+
function file(root, urlPath) {
|
|
2503
|
+
let path;
|
|
2504
|
+
try {
|
|
2505
|
+
path = decodeURIComponent(urlPath.split("?")[0]);
|
|
2506
|
+
} catch (_a) {
|
|
2507
|
+
path = "/";
|
|
2508
|
+
}
|
|
2509
|
+
const absolute = normalize(join5(root, path));
|
|
2510
|
+
if ((absolute === root || absolute.startsWith(root.endsWith(sep) ? root : root + sep)) && existsSync2(absolute) && statSync(absolute).isFile()) {
|
|
2511
|
+
return absolute;
|
|
2512
|
+
}
|
|
2513
|
+
return join5(root, "index.html");
|
|
2514
|
+
}
|
|
2515
|
+
GatewayServerUtil2.file = file;
|
|
2516
|
+
})(GatewayServerUtil || (GatewayServerUtil = {}));
|
|
2517
|
+
|
|
2518
|
+
class GatewayServer {
|
|
2519
|
+
static async create(options) {
|
|
2520
|
+
mkdirSync4(options.dir, { recursive: true, mode: 448 });
|
|
2521
|
+
const config = SandboxProviders.read(options.dir);
|
|
2522
|
+
const context = { dir: options.dir, taCommand: options.taCommand };
|
|
2523
|
+
const providers = await SandboxProviders.create(config, context, SANDBOX_TYPES);
|
|
2524
|
+
return new GatewayServer(options, providers, config);
|
|
2525
|
+
}
|
|
2526
|
+
constructor(options, providers, config) {
|
|
2527
|
+
var _a, _b;
|
|
2528
|
+
this.options = options;
|
|
2529
|
+
this.sockets = new Set;
|
|
2530
|
+
const env = (_a = options.env) !== null && _a !== undefined ? _a : process.env;
|
|
2531
|
+
this.admins = AccessUtil.parseList(env.TA_GATEWAY_ADMINS);
|
|
2532
|
+
const allowed = [...AccessUtil.parseList(env.TA_ALLOWED_USERS), ...this.admins];
|
|
2533
|
+
this.flow = new SignInFlow(SignInProviders.fromEnv(env), new AccessStore(join5(options.dir, "access.json"), allowed), SignInProviders.publicUrl(env));
|
|
2534
|
+
this.tenants = new TenantStore(options.dir);
|
|
2535
|
+
this.links = new SignInLinks(options.dir);
|
|
2536
|
+
this.environments = new Environments(providers, this.tenants, {
|
|
2537
|
+
default: config.default,
|
|
2538
|
+
own: config.ownEnvironments !== false,
|
|
2539
|
+
idleMinutes: (_b = config.idleMinutes) !== null && _b !== undefined ? _b : 0
|
|
2540
|
+
});
|
|
2541
|
+
this.service = new GatewayService(this.flow, this.tenants, this.environments, { cutOff: () => this.cutOff(), reset: (id) => this.reset(id) });
|
|
2542
|
+
}
|
|
2543
|
+
isAdmin(account) {
|
|
2544
|
+
return this.admins.some((pattern) => AccessUtil.matches(pattern, account));
|
|
2545
|
+
}
|
|
2546
|
+
listen() {
|
|
2547
|
+
const server = createServer2((request2, response) => void this.handle(request2, response));
|
|
2548
|
+
server.on("upgrade", (request2, socket, head) => this.upgrade(request2, socket, head));
|
|
2549
|
+
this.server = server;
|
|
2550
|
+
return new Promise((resolve, reject) => {
|
|
2551
|
+
var _a, _b;
|
|
2552
|
+
server.once("error", reject);
|
|
2553
|
+
server.listen((_a = this.options.port) !== null && _a !== undefined ? _a : 4100, (_b = this.options.host) !== null && _b !== undefined ? _b : "127.0.0.1", () => {
|
|
2554
|
+
const { address, port } = server.address();
|
|
2555
|
+
resolve(`http://${address.includes(":") ? `[${address}]` : address}:${port}`);
|
|
2556
|
+
});
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2559
|
+
async close() {
|
|
2560
|
+
for (const socket of this.sockets) {
|
|
2561
|
+
socket.close(1001, "The gateway is stopping.");
|
|
2562
|
+
}
|
|
2563
|
+
await this.environments.dispose();
|
|
2564
|
+
await new Promise((resolve) => this.server ? this.server.close(() => resolve()) : resolve());
|
|
2565
|
+
}
|
|
2566
|
+
cutOff() {
|
|
2567
|
+
for (const socket of this.sockets) {
|
|
2568
|
+
if (!this.caller(socket.caller.token)) {
|
|
2569
|
+
socket.close(1008, "Signed out");
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
reset(tenantId) {
|
|
2574
|
+
const sockets = [...this.sockets].filter((socket) => socket.tenantId === tenantId);
|
|
2575
|
+
setTimeout(() => {
|
|
2576
|
+
for (const socket of sockets) {
|
|
2577
|
+
socket.close(1012, "The environment changed.");
|
|
2578
|
+
}
|
|
2579
|
+
}, 100);
|
|
2580
|
+
}
|
|
2581
|
+
caller(token) {
|
|
2582
|
+
const signIn = token ? this.flow.store.check(token) : undefined;
|
|
2583
|
+
if (!signIn) {
|
|
2584
|
+
return;
|
|
2585
|
+
}
|
|
2586
|
+
const tenant = this.tenants.ensure({ id: signIn.account, name: signIn.name, avatar: signIn.avatar });
|
|
2587
|
+
return { token, account: signIn.account, tenant, admin: this.isAdmin(signIn.account) };
|
|
2588
|
+
}
|
|
2589
|
+
async handle(request2, response) {
|
|
2590
|
+
var _a;
|
|
2591
|
+
const path = ((_a = request2.url) !== null && _a !== undefined ? _a : "/").split("?")[0];
|
|
2592
|
+
try {
|
|
2593
|
+
if (path.startsWith(SIGN_IN_LINK_PATH)) {
|
|
2594
|
+
this.useLink(request2, response, path.slice(SIGN_IN_LINK_PATH.length));
|
|
2595
|
+
} else if (SignInPages.matches(request2)) {
|
|
2596
|
+
await SignInPages.handle(request2, response, this.flow, {
|
|
2597
|
+
name: "ta gateway",
|
|
2598
|
+
onSignedIn: (res, token, account, origin) => this.signedIn(res, token, account, origin)
|
|
2599
|
+
});
|
|
2600
|
+
} else if (path.startsWith(`${TA_FILES_PATH}/`)) {
|
|
2601
|
+
await this.files(request2, response);
|
|
2602
|
+
} else if (path === "/api" || path.startsWith("/api/")) {
|
|
2603
|
+
SignInPageUtil.end(response, 404);
|
|
2604
|
+
} else {
|
|
2605
|
+
this.page(request2, response, path);
|
|
2606
|
+
}
|
|
2607
|
+
} catch (error) {
|
|
2608
|
+
console.warn(`ta gateway: ${request2.method} ${path} failed: ${error.message}`);
|
|
2609
|
+
if (!response.headersSent) {
|
|
2610
|
+
SignInPageUtil.end(response, 502);
|
|
2611
|
+
} else {
|
|
2612
|
+
response.destroy();
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
useLink(request2, response, secret) {
|
|
2617
|
+
response.setHeader("Cache-Control", "no-store");
|
|
2618
|
+
response.setHeader("Referrer-Policy", "no-referrer");
|
|
2619
|
+
const link = request2.method === "GET" ? this.links.use(secret) : undefined;
|
|
2620
|
+
if (!link) {
|
|
2621
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: "failed" }));
|
|
2622
|
+
return;
|
|
2623
|
+
}
|
|
2624
|
+
if (!this.flow.store.allows(link.account)) {
|
|
2625
|
+
this.flow.store.allow(link.account, link.name);
|
|
2626
|
+
}
|
|
2627
|
+
const account = { id: link.account, name: link.name };
|
|
2628
|
+
const token = this.flow.store.signIn(account, request2.headers["user-agent"]);
|
|
2629
|
+
console.log(`ta gateway: ${link.account} signed in with a link`);
|
|
2630
|
+
this.signedIn(response, token, account, this.origin(request2));
|
|
2631
|
+
SignInPageUtil.redirect(response, SignInPageUtil.back({ token }));
|
|
2632
|
+
}
|
|
2633
|
+
signedIn(response, token, account, origin) {
|
|
2634
|
+
this.tenants.ensure(account);
|
|
2635
|
+
const secure = origin.startsWith("https:") ? "; Secure" : "";
|
|
2636
|
+
const cookies = response.getHeader("Set-Cookie");
|
|
2637
|
+
const list = Array.isArray(cookies) ? cookies : cookies ? [String(cookies)] : [];
|
|
2638
|
+
response.setHeader("Set-Cookie", [...list, `${FILES_COOKIE}=${token}; Path=${TA_FILES_PATH}; Max-Age=31536000; HttpOnly; SameSite=Lax${secure}`]);
|
|
2639
|
+
}
|
|
2640
|
+
origin(request2) {
|
|
2641
|
+
var _a;
|
|
2642
|
+
return (_a = this.flow.publicUrl) !== null && _a !== undefined ? _a : `http://${request2.headers.host}`;
|
|
2643
|
+
}
|
|
2644
|
+
async files(request2, response) {
|
|
2645
|
+
var _a, _b;
|
|
2646
|
+
const caller = this.caller((_a = SignInPageUtil.cookie(request2.headers.cookie, FILES_COOKIE)) !== null && _a !== undefined ? _a : "");
|
|
2647
|
+
if (!caller) {
|
|
2648
|
+
SignInPageUtil.end(response, 404);
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2651
|
+
const endpoint = await this.environments.ensure(caller.tenant);
|
|
2652
|
+
const target = new URL((_b = request2.url) !== null && _b !== undefined ? _b : "/", endpoint.url);
|
|
2653
|
+
const headers = {};
|
|
2654
|
+
for (const name of ["range", "if-none-match", "accept", "accept-encoding", "user-agent"]) {
|
|
2655
|
+
const value = request2.headers[name];
|
|
2656
|
+
if (value !== undefined) {
|
|
2657
|
+
headers[name] = value;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
await new Promise((resolve, reject) => {
|
|
2661
|
+
const send = target.protocol === "https:" ? httpsRequest : httpRequest;
|
|
2662
|
+
const outgoing = send(target, { method: request2.method, headers }, (incoming) => {
|
|
2663
|
+
var _a2;
|
|
2664
|
+
response.writeHead((_a2 = incoming.statusCode) !== null && _a2 !== undefined ? _a2 : 502, incoming.headers);
|
|
2665
|
+
incoming.pipe(response);
|
|
2666
|
+
incoming.on("end", () => resolve());
|
|
2667
|
+
incoming.on("error", reject);
|
|
2668
|
+
});
|
|
2669
|
+
outgoing.on("error", reject);
|
|
2670
|
+
outgoing.end();
|
|
2671
|
+
});
|
|
2672
|
+
}
|
|
2673
|
+
page(request2, response, path) {
|
|
2674
|
+
var _a;
|
|
2675
|
+
if (request2.method !== "GET" && request2.method !== "HEAD") {
|
|
2676
|
+
response.setHeader("Allow", "GET, HEAD");
|
|
2677
|
+
SignInPageUtil.end(response, 405);
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
const root = normalize(this.options.publicDir);
|
|
2681
|
+
const file = GatewayServerUtil.file(root, path);
|
|
2682
|
+
response.setHeader("Content-Type", (_a = TYPES[extname(file)]) !== null && _a !== undefined ? _a : "application/octet-stream");
|
|
2683
|
+
response.setHeader("X-Content-Type-Options", "nosniff");
|
|
2684
|
+
response.setHeader("Cache-Control", path.startsWith("/assets/") ? "public, max-age=31536000, immutable" : "no-cache");
|
|
2685
|
+
if (request2.method === "HEAD") {
|
|
2686
|
+
response.end();
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
createReadStream(file).pipe(response);
|
|
2690
|
+
}
|
|
2691
|
+
upgrade(request2, socket, head) {
|
|
2692
|
+
var _a, _b;
|
|
2693
|
+
const url = new URL((_a = request2.url) !== null && _a !== undefined ? _a : "/", "http://gateway");
|
|
2694
|
+
if (url.pathname !== TA_WEBSOCKET_PATH) {
|
|
2695
|
+
socket.destroy();
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
2698
|
+
const checked = WebSocketConnection.check(request2);
|
|
2699
|
+
if ("status" in checked) {
|
|
2700
|
+
WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
const header = request2.headers.authorization;
|
|
2704
|
+
const token = (header === null || header === undefined ? undefined : header.startsWith("Bearer ")) ? header.slice("Bearer ".length) : (_b = url.searchParams.get("token")) !== null && _b !== undefined ? _b : "";
|
|
2705
|
+
const caller = this.caller(token);
|
|
2706
|
+
if (!caller) {
|
|
2707
|
+
WebSocketConnection.refuse(socket, 401, "Not authorized.");
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
this.tenants.update(caller.tenant.id, { lastActiveAt: Date.now() });
|
|
2711
|
+
const connection = WebSocketConnection.open(socket, checked.key, head, { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 });
|
|
2712
|
+
const gatewaySocket = new GatewaySocket(connection, caller, this.environments, this.service);
|
|
2713
|
+
this.sockets.add(gatewaySocket);
|
|
2714
|
+
connection.onClose(() => this.sockets.delete(gatewaySocket));
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-cli.js
|
|
2719
|
+
var HELP = `Usage: ta gateway [--host <host>] [--port <port>] [--dir <dir>]
|
|
2720
|
+
ta gateway link <account> [--name <name>] [--dir <dir>]
|
|
2721
|
+
|
|
2722
|
+
One sign-in for many people, each with a Ta of their own: an account that signs in is a tenant, whose Ta
|
|
2723
|
+
runs in a sandbox of its own (a container per tenant by default), or in a Ta service of the user's. The web
|
|
2724
|
+
client is served here; each browser's connection goes to the Ta of its tenant. Stops on SIGINT or SIGTERM.
|
|
2725
|
+
|
|
2726
|
+
--host Address to listen on. Default: 127.0.0.1
|
|
2727
|
+
--port Port to listen on. Default: 4100, or PORT
|
|
2728
|
+
--dir Its configuration and data. Default: TA_GATEWAY_DIR, else ~/.ta/gateway
|
|
2729
|
+
|
|
2730
|
+
Accounts sign in with the providers of the environment (TA_GITHUB_*, TA_GOOGLE_*, TA_WECHAT_*, TA_OIDC_*, as
|
|
2731
|
+
for ta serve) when TA_ALLOWED_USERS lets them in; TA_GATEWAY_ADMINS are let in too and manage the others.
|
|
2732
|
+
"ta gateway link <account>" prints a link that signs in as the account once, within a day, and lets it in:
|
|
2733
|
+
for someone without a provider of accounts (user:alice), or before one is set up.
|
|
2734
|
+
|
|
2735
|
+
The sandboxes are those of sandboxes.json in the directory, as pi's models.json for models:
|
|
2736
|
+
{ "default": "docker", "providers": { "docker": { "type": "docker", "image": "ta:latest", "memory": "4g" } } }
|
|
2737
|
+
Types: docker, command (shell commands for any platform), local (no isolation: tests), ta (a Ta service that
|
|
2738
|
+
runs), module (a file whose default export makes a provider). See the README of @celljs/ta-gateway.
|
|
2739
|
+
`;
|
|
2740
|
+
var GatewayCli;
|
|
2741
|
+
(function(GatewayCli2) {
|
|
2742
|
+
async function run(argv, options) {
|
|
2743
|
+
var _a, _b, _c, _d;
|
|
2744
|
+
const { values, positionals } = parseArgs({
|
|
2745
|
+
args: argv,
|
|
2746
|
+
allowPositionals: true,
|
|
2747
|
+
options: {
|
|
2748
|
+
host: { type: "string" },
|
|
2749
|
+
port: { type: "string" },
|
|
2750
|
+
dir: { type: "string" },
|
|
2751
|
+
name: { type: "string" },
|
|
2752
|
+
help: { type: "boolean", short: "h" }
|
|
2753
|
+
}
|
|
2754
|
+
});
|
|
2755
|
+
if (values.help) {
|
|
2756
|
+
process.stdout.write(HELP);
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
const dir = (_b = (_a = values.dir) !== null && _a !== undefined ? _a : process.env.TA_GATEWAY_DIR) !== null && _b !== undefined ? _b : join6(homedir(), ".ta", "gateway");
|
|
2760
|
+
if (positionals[0] === "link") {
|
|
2761
|
+
link(dir, positionals[1], values.name);
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
if (positionals.length > 0) {
|
|
2765
|
+
process.stdout.write(HELP);
|
|
2766
|
+
process.exitCode = 1;
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
let gateway;
|
|
2770
|
+
try {
|
|
2771
|
+
gateway = await GatewayServer.create({
|
|
2772
|
+
dir,
|
|
2773
|
+
host: values.host,
|
|
2774
|
+
port: Number((_d = (_c = values.port) !== null && _c !== undefined ? _c : process.env.PORT) !== null && _d !== undefined ? _d : 4100),
|
|
2775
|
+
publicDir: options.publicDir,
|
|
2776
|
+
taCommand: options.taCommand
|
|
2777
|
+
});
|
|
2778
|
+
} catch (error) {
|
|
2779
|
+
console.error(`ta gateway: ${error.message}`);
|
|
2780
|
+
process.exitCode = 1;
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
const url = await gateway.listen();
|
|
2784
|
+
const ways = gateway.flow.providers.map((provider) => provider.name);
|
|
2785
|
+
console.log(`ta gateway: ${url} (${dir})`);
|
|
2786
|
+
console.log(`ta gateway: sandboxes of ${gateway.environments.providers.map((provider) => `${provider.id} (${provider.type})`).join(", ") || "none"}${ways.length ? `; sign-in with ${ways.join(", ")}` : "; no provider of accounts: sign people in with ta gateway link <account>"}`);
|
|
2787
|
+
const stop = () => void gateway.close().then(() => process.exit(0));
|
|
2788
|
+
process.once("SIGINT", stop);
|
|
2789
|
+
process.once("SIGTERM", stop);
|
|
2790
|
+
}
|
|
2791
|
+
GatewayCli2.run = run;
|
|
2792
|
+
function link(dir, account, name) {
|
|
2793
|
+
if (!account) {
|
|
2794
|
+
console.error("ta gateway link: name the account, such as github:octocat or user:alice.");
|
|
2795
|
+
process.exitCode = 1;
|
|
2796
|
+
return;
|
|
2797
|
+
}
|
|
2798
|
+
try {
|
|
2799
|
+
const path = new SignInLinks(dir).create(account, name);
|
|
2800
|
+
const base = SandboxProviders.publicBase(process.env);
|
|
2801
|
+
console.log(`Open this link to sign in as the account, once, within a day. Anyone with it signs in as it: send it to its owner only.
|
|
2802
|
+
`);
|
|
2803
|
+
console.log(base ? `${base}${path}` : `<address of the gateway>${path}`);
|
|
2804
|
+
} catch (error) {
|
|
2805
|
+
console.error(`ta gateway link: ${error.message}`);
|
|
2806
|
+
process.exitCode = 1;
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
})(GatewayCli || (GatewayCli = {}));
|
|
2810
|
+
export {
|
|
2811
|
+
GatewayCli
|
|
2812
|
+
};
|