@celljs/ta 4.8.0 → 4.9.1
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 +2830 -0
- package/dist/pi/CHANGELOG.md +31 -0
- package/dist/pi/package.json +1 -1
- package/dist/pi/packages/ta-agents/README.en.md +2 -2
- package/dist/pi/packages/ta-agents/README.md +2 -2
- package/dist/pi/packages/ta-agents/extension/index.mjs +61 -13
- package/dist/pi/packages/ta-agents/lib/agent-bindings.d.ts +17 -4
- package/dist/pi/packages/ta-agents/lib/agent-bindings.js +39 -9
- package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +2 -0
- package/dist/pi/packages/ta-agents/lib/agent-catalog.js +3 -0
- 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/lib/extension.d.ts +2 -1
- package/dist/pi/packages/ta-agents/lib/extension.js +11 -3
- package/dist/pi/packages/ta-agents/lib/json-rpc.js +7 -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 +41 -9
- package/dist/pi/packages/ta-channels/lib/i18n.js +83 -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 +241 -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 +50 -0
- package/dist/pi/packages/ta-channels/lib/tasks.js +237 -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 +1061 -206
- 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/index.js +2 -1
- 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-sessions.d.ts +51 -0
- package/dist/pi/packages/ta-workspace/lib/terminal-sessions.js +226 -0
- package/dist/pi/packages/ta-workspace/lib/terminal.d.ts +5 -22
- package/dist/pi/packages/ta-workspace/lib/terminal.js +191 -141
- 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 +916 -295
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-CNqfsCwx.js → abnfDiagram-S7VZAUFO-EVMX_yOb.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-_WaGq-Qk.js → architecture-WOLXFQ4H-CDgbgZ_o.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-Bn63Lctu.js → architectureDiagram-YGSQEFNW-dHreaCWz.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-BGaAecnk.js → blockDiagram-APKKGZFW-D6FhzBDq.js} +1 -1
- package/dist/public/assets/{browser-DKagIN4Y.js → browser-y6EDNUmc.js} +1 -1
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-CK9Z_9Zp.js → c4Diagram-KJ2TOQU5-BFpcr8Cs.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-H3j3MGva.js → chunk-6MUBBAK2-BczXkMV-.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-Beljdjs9.js → chunk-AXFCVDMN-CjJsv3jB.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-TYEV5wLO.js → chunk-BG4553SI-FBaleaLz.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-gmWJrizf.js → chunk-DQASFODM-BFdXY5sX.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-BTa7yKXI.js → chunk-HFQBQIA3-C5cwK-Fg.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-BlwMm4R0.js → chunk-KQLB2F66-BUek3IRk.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-CKTXjzwD.js → chunk-KS47KZWR-BxsYBzt6.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-Bn9Xkefl.js → chunk-LEVMRMFU-Bdcwz9fS.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-B_QLqohG.js → chunk-M57EVK23-kkpP5oug.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-BflzJHPz.js → chunk-OY52VR5R-CFhQgxmD.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-BXucfaFg.js → chunk-QB3YPZ4I-BVXqu0eC.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-CGwkwxm9.js → chunk-R3KSYZAL-B7SUqqLI.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-DQGOPuM5.js → chunk-STOXU5M4-B3abfbnH.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-BCrs6AYI.js → chunk-TU62E6Q5-C9NqnUav.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-MTv7nXJX.js → chunk-X4PVCEUW-BeLfETDx.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-fPaX8VIb.js → chunk-XXDRQBXY-DXai1i8p.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-tm4uT08q.js → classDiagram-v2-L25IHNXF-Zj6ne_tC.js} +1 -1
- package/dist/public/assets/{cose-bilkent-JH36ORCC-Dkk3pDZj.js → cose-bilkent-JH36ORCC-C0-TjqfJ.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-CoY4CrZu.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-BcoArW00.js → cynefinDiagram-L36ESFBY-BnqxfzPa.js} +1 -1
- package/dist/public/assets/{d3-selection-BzUITLov.js → d3-selection-DfFLTR9d.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-oiU-wJxw.js → dagre-SPEB5RXH-kI17e5cH.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-BwlCOIW4.js → diagram-3B7GL73J-DgPjeLA5.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-CZGQiFrl.js → diagram-DNEMPZML-CRhPfa0I.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-BJGDa24C.js → diagram-L3MUGCDN-ExuTg12b.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-DdwHRhnP.js → diagram-LA4NIPWU-Dgx5xNiY.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-IjreLUB9.js → diagram-MHCOC4E2-BuifkUTl.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-CvaG0Zzq.js → diagram-XPFHEONP-CFEaBo7z.js} +1 -1
- package/dist/public/assets/{dist-Cm4zqoMA.js → dist-C-iJHcSK.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-C-FOI67M.js → ebnfDiagram-UZSYDL2S-D-hp5yNt.js} +1 -1
- package/dist/public/assets/{editor.api-hteKufWf.js → editor.api-BopUWpqY.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-C_ClfkLy.js → elk-XV6XMXQE-CBbk_IpU.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-DSr0aRYm.js → erDiagram-EYBAPDEH-B02R_WWE.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-COU_atV6.js → eventmodeling-K75KTNOO-aCZfYnCI.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-CATkJShO.js +1 -0
- package/dist/public/assets/{freemarker2-CBJnhymu.js → freemarker2-DMN60LeK.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-BAcXXNjI.js → ganttDiagram-23REXITY-DioU8TlD.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-g4yHXXxx.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW-Bk9sns6k.js → gitGraphDiagram-STJD7YCW--q3ctg6y.js} +1 -1
- package/dist/public/assets/{handlebars-CiqYW1im.js → handlebars-B_-qdvpB.js} +1 -1
- package/dist/public/assets/{html-kafkm1Z0.js → html-BN8Ah3Js.js} +1 -1
- package/dist/public/assets/{index-DPLd0-lb.js → index-B3A--ac8.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-CKADJjz4.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-2hRQLVWa.js → infoDiagram-KBXO4MBG-CGXteYo9.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-hrOnhWJs.js → ishikawaDiagram-M35NCXHK-DM2LmOAc.js} +1 -1
- package/dist/public/assets/{javascript-Dt5MiA9w.js → javascript-BlizGb0q.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-d8HJd04q.js → journeyDiagram-OPLOXDXO-CNITRtGl.js} +1 -1
- package/dist/public/assets/{jsonMode-DBICoo6P.js → jsonMode-CEUmT5sN.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-DOUuZDiv.js → kanban-definition-BZKZHSQY-BPUuS9um.js} +1 -1
- package/dist/public/assets/{liquid-BGYhBP2h.js → liquid-BbyLjUbE.js} +1 -1
- package/dist/public/assets/{mdx-Ct_gzcP3.js → mdx-DiQz7Q35.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-2yhxYNxq.js → mermaid-parser.core-Dum100hC.js} +3 -3
- package/dist/public/assets/{mermaid.core-sx7teU8z.js → mermaid.core-BWmWf6XO.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-DIc9LejH.js → mindmap-definition-I2QAS2VK-L8HyYUDY.js} +1 -1
- package/dist/public/assets/module-CH7IXa5L.js +1781 -0
- package/dist/public/assets/module-DNAasuMC.js +1 -0
- package/dist/public/assets/{monaco-DJecWyyV.js → monaco-zOOyBmxy.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-CpKMhX4K.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-BfiT6-Vx.js → pegDiagram-FD4XPPHP-CTZKPo0Z.js} +1 -1
- package/dist/public/assets/pie-XZMESJXO-CW-zGDRd.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-DJ0sF_Eg.js → pieDiagram-J4AKIIQI-DAeT3dFi.js} +1 -1
- package/dist/public/assets/{python-BrnocsK9.js → python-C984gt98.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2-C3iF5PG6.js → quadrantDiagram-XTYBLID2--PXxwV1Z.js} +1 -1
- package/dist/public/assets/radar-ABXABTNO-Cg8W433p.js +1 -0
- package/dist/public/assets/railroad-I3PHUGI6-DriMt2PQ.js +1 -0
- package/dist/public/assets/{railroad-abnf-LNEFI6M7-BI4N-mtq.js → railroad-abnf-LNEFI6M7-BYcFfrCa.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-Ck2MUlyV.js → railroad-ebnf-DWYD2UWJ-Cd33qxAm.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-Cuc9S0f4.js → railroad-peg-JR7BVNR7-C5TpzaU8.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-Cw24sb_5.js → railroadDiagram-MRQ6NCDL-DlWwjbhH.js} +1 -1
- package/dist/public/assets/{razor-BDHTAmlI.js → razor-BBqMR1Qn.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-QQUXFr1R.js → requirementDiagram-Y7LWUY3S-CsYBy9HS.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-WGJFYUXA-mSlfAHND.js → sankeyDiagram-WGJFYUXA-Baxyb5p9.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-3t8hVott.js → sequenceDiagram-5NDRBG5M-Cq6VeBT_.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-9EW807AL.js → stateDiagram-v2-FJ4FJNEA-O60WKaE7.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-EbMBX_e0.js → swimlanes-UMQ2AFYF-C2nf1-Cc.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-B46JxqS8.js +8 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-D14kjjsp.js → timeline-definition-SEUHKTQE-DEfUG6YH.js} +1 -1
- package/dist/public/assets/treeView-D4JQ5SDB-1LhEWwC9.js +1 -0
- package/dist/public/assets/treemap-SAJKECNS-D3t3N7nS.js +1 -0
- package/dist/public/assets/{typescript-BEEbbq69.js → typescript-Gtq7f0aU.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-DKemtzU9.js → usecaseDiagram-AFA6YXN4-Gw9DyJcx.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-DOBq9oeY.js → vennDiagram-NNMJR3RB-Clb3MLWF.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-D3sAsd8p.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-DquSJ4y-.js → wardleyDiagram-S7YFUSEH-BrTRpwu2.js} +1 -1
- package/dist/public/assets/{xml-DvTQKQ_W.js → xml-Bx3nk7iG.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-ClE_9jz4.js → xychartDiagram-GGNKY7IX-BfjTcIsb.js} +1 -1
- package/dist/public/assets/{yaml-ffiFfPtJ.js → yaml-dFLE_rSl.js} +1 -1
- package/dist/public/index.html +35 -6
- package/dist/public/launch.svg +49 -0
- package/dist/serve/index.mjs +3699 -887
- 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
|
@@ -0,0 +1,2313 @@
|
|
|
1
|
+
// web-src/bot-service.ts
|
|
2
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
// web-src/bot-store.ts
|
|
5
|
+
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
// web-src/bots-protocol.ts
|
|
9
|
+
var NAME = "@celljs/ta-bots";
|
|
10
|
+
var Keys;
|
|
11
|
+
((Keys) => {
|
|
12
|
+
Keys.BOTS = "bots";
|
|
13
|
+
Keys.STATUS = "status";
|
|
14
|
+
})(Keys ||= {});
|
|
15
|
+
var BotTargetUtil;
|
|
16
|
+
((BotTargetUtil) => {
|
|
17
|
+
function same(a, b) {
|
|
18
|
+
if (!a || !b || a.kind !== b.kind) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return a.kind === "double" || b.kind === "session" && a.sessionFile === b.sessionFile;
|
|
22
|
+
}
|
|
23
|
+
BotTargetUtil.same = same;
|
|
24
|
+
function parse(value) {
|
|
25
|
+
if (!value || typeof value !== "object") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const target = value;
|
|
29
|
+
if (target.kind === "double") {
|
|
30
|
+
return { kind: "double" };
|
|
31
|
+
}
|
|
32
|
+
if (target.kind === "session" && typeof target.sessionFile === "string" && target.sessionFile) {
|
|
33
|
+
const text = (key) => typeof target[key] === "string" && target[key] ? { [key]: target[key] } : {};
|
|
34
|
+
return { kind: "session", sessionFile: target.sessionFile, ...text("cwd"), ...text("title"), ...text("group") };
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
BotTargetUtil.parse = parse;
|
|
39
|
+
})(BotTargetUtil ||= {});
|
|
40
|
+
|
|
41
|
+
// web-src/bot-store.ts
|
|
42
|
+
class BotStore {
|
|
43
|
+
host;
|
|
44
|
+
dir;
|
|
45
|
+
secrets;
|
|
46
|
+
writing = Promise.resolve();
|
|
47
|
+
constructor(host) {
|
|
48
|
+
this.host = host;
|
|
49
|
+
this.dir = join(host.agentDir, "bots");
|
|
50
|
+
}
|
|
51
|
+
async bots() {
|
|
52
|
+
const value = await this.host.getExtensionData(NAME, Keys.BOTS);
|
|
53
|
+
return Array.isArray(value) ? value.filter((bot) => bot && typeof bot.id === "string") : [];
|
|
54
|
+
}
|
|
55
|
+
saveBots(bots) {
|
|
56
|
+
return this.host.setExtensionData(NAME, Keys.BOTS, bots);
|
|
57
|
+
}
|
|
58
|
+
saveStatus(status) {
|
|
59
|
+
return this.host.setExtensionData(NAME, Keys.STATUS, status);
|
|
60
|
+
}
|
|
61
|
+
async secret(id) {
|
|
62
|
+
return (await this.allSecrets())[id];
|
|
63
|
+
}
|
|
64
|
+
async tokens() {
|
|
65
|
+
return Object.values(await this.allSecrets()).flatMap((secret) => secret.kind === "weixin" ? [secret.token] : []);
|
|
66
|
+
}
|
|
67
|
+
async setSecret(id, secret) {
|
|
68
|
+
const secrets = { ...await this.allSecrets() };
|
|
69
|
+
if (secret) {
|
|
70
|
+
secrets[id] = secret;
|
|
71
|
+
} else {
|
|
72
|
+
delete secrets[id];
|
|
73
|
+
}
|
|
74
|
+
this.secrets = secrets;
|
|
75
|
+
await this.write("secrets.json", secrets);
|
|
76
|
+
}
|
|
77
|
+
memory(id) {
|
|
78
|
+
const file = `${id.replace(/[^\w.-]+/g, "_")}.json`;
|
|
79
|
+
let state;
|
|
80
|
+
const load = async () => state ??= await this.read(file) ?? {};
|
|
81
|
+
const save = () => this.write(file, state);
|
|
82
|
+
return {
|
|
83
|
+
cursor: async () => (await load())?.cursor ?? "",
|
|
84
|
+
setCursor: async (cursor) => {
|
|
85
|
+
(await load()).cursor = cursor;
|
|
86
|
+
await save();
|
|
87
|
+
},
|
|
88
|
+
contexts: async () => ({ ...(await load())?.contexts ?? {} }),
|
|
89
|
+
setContext: async (chat, token) => {
|
|
90
|
+
const current = await load();
|
|
91
|
+
current.contexts = { ...current.contexts, [chat]: token };
|
|
92
|
+
await save();
|
|
93
|
+
},
|
|
94
|
+
forget: async () => {
|
|
95
|
+
state = {};
|
|
96
|
+
await save();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async allSecrets() {
|
|
101
|
+
this.secrets ??= await this.read("secrets.json") ?? {};
|
|
102
|
+
return this.secrets;
|
|
103
|
+
}
|
|
104
|
+
async read(file) {
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(await readFile(join(this.dir, file), "utf8"));
|
|
107
|
+
} catch {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
write(file, value) {
|
|
112
|
+
const next = this.writing.then(async () => {
|
|
113
|
+
await mkdir(this.dir, { recursive: true, mode: 448 });
|
|
114
|
+
const path = join(this.dir, file);
|
|
115
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
116
|
+
await writeFile(temporary, `${JSON.stringify(value ?? {}, null, 2)}
|
|
117
|
+
`, { mode: 384 });
|
|
118
|
+
await rename(temporary, path);
|
|
119
|
+
await chmod(path, 384).catch(() => {
|
|
120
|
+
return;
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
this.writing = next.catch(() => {
|
|
124
|
+
return;
|
|
125
|
+
});
|
|
126
|
+
return next;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// web-src/channel-protocol.ts
|
|
131
|
+
var BotEndpointsUtil;
|
|
132
|
+
((BotEndpointsUtil) => {
|
|
133
|
+
function of(env = process.env) {
|
|
134
|
+
return {
|
|
135
|
+
weixinApi: env.TA_BOTS_WEIXIN_URL || "https://ilinkai.weixin.qq.com",
|
|
136
|
+
weixinCdn: env.TA_BOTS_WEIXIN_CDN || "https://novac2c.cdn.weixin.qq.com/c2c",
|
|
137
|
+
wecomSocket: env.TA_BOTS_WECOM_URL || "wss://openws.work.weixin.qq.com",
|
|
138
|
+
wecomQr: env.TA_BOTS_WECOM_QR_URL || "https://work.weixin.qq.com"
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
BotEndpointsUtil.of = of;
|
|
142
|
+
})(BotEndpointsUtil ||= {});
|
|
143
|
+
function errorText(error) {
|
|
144
|
+
return error instanceof Error ? error.message : String(error);
|
|
145
|
+
}
|
|
146
|
+
function sleep(ms, signal) {
|
|
147
|
+
return new Promise((resolve) => {
|
|
148
|
+
if (signal?.aborted) {
|
|
149
|
+
resolve();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const timer = setTimeout(done, ms);
|
|
153
|
+
function done() {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
signal?.removeEventListener("abort", done);
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
158
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// web-src/server-texts.ts
|
|
163
|
+
var BotServerTexts;
|
|
164
|
+
((BotServerTexts) => {
|
|
165
|
+
function zh(env = process.env) {
|
|
166
|
+
return /^zh/i.test(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
167
|
+
}
|
|
168
|
+
BotServerTexts.zh = zh;
|
|
169
|
+
function unbound() {
|
|
170
|
+
return zh() ? "这个机器人还没有连接到 Ta 的任何对话。在 Ta 里打开一个对话,点输入框左侧的 +,选“机器人”连接它。" : "This bot is not connected to a conversation of Ta yet. Open one in Ta, click + left of the message box and pick it under Bots.";
|
|
171
|
+
}
|
|
172
|
+
BotServerTexts.unbound = unbound;
|
|
173
|
+
function noDouble() {
|
|
174
|
+
return zh() ? "Ta 的分身还没有对话:先在 Ta 里打开一次分身。" : "The double of Ta has no conversation yet: open it once in Ta.";
|
|
175
|
+
}
|
|
176
|
+
BotServerTexts.noDouble = noDouble;
|
|
177
|
+
function failed(reason) {
|
|
178
|
+
return zh() ? `没能交给 Ta:${reason}` : `Ta did not get it: ${reason}`;
|
|
179
|
+
}
|
|
180
|
+
BotServerTexts.failed = failed;
|
|
181
|
+
function stopped() {
|
|
182
|
+
return zh() ? "(Ta 停下了,没有回复)" : "(Ta stopped without an answer)";
|
|
183
|
+
}
|
|
184
|
+
BotServerTexts.stopped = stopped;
|
|
185
|
+
function error(reason) {
|
|
186
|
+
return zh() ? `Ta 出错了:${reason}` : `Ta failed: ${reason}`;
|
|
187
|
+
}
|
|
188
|
+
BotServerTexts.error = error;
|
|
189
|
+
function defaultName(kind, taken = []) {
|
|
190
|
+
const base = kind === "weixin" ? zh() ? "我的微信" : "My WeChat" : zh() ? "企业微信机器人" : "WeCom bot";
|
|
191
|
+
for (let n = 1;; n++) {
|
|
192
|
+
const name = n === 1 ? base : `${base} ${n}`;
|
|
193
|
+
if (!taken.includes(name)) {
|
|
194
|
+
return name;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
BotServerTexts.defaultName = defaultName;
|
|
199
|
+
})(BotServerTexts ||= {});
|
|
200
|
+
|
|
201
|
+
// ../ta-protocol/esm/common/access-protocol.js
|
|
202
|
+
var TaAccessServer = Symbol("TaAccessServer");
|
|
203
|
+
// ../ta-protocol/esm/common/auth-protocol.js
|
|
204
|
+
var TaAuthServer = Symbol("TaAuthServer");
|
|
205
|
+
// ../ta-protocol/esm/common/gateway-protocol.js
|
|
206
|
+
var TaGatewayServer = Symbol("TaGatewayServer");
|
|
207
|
+
// ../ta-protocol/esm/common/location.js
|
|
208
|
+
var TaLocation;
|
|
209
|
+
(function(TaLocation2) {
|
|
210
|
+
TaLocation2.SSH = "ssh://";
|
|
211
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
212
|
+
function isRemote(location) {
|
|
213
|
+
return location.startsWith(TaLocation2.SSH);
|
|
214
|
+
}
|
|
215
|
+
TaLocation2.isRemote = isRemote;
|
|
216
|
+
function parse(location) {
|
|
217
|
+
if (!isRemote(location)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const rest = location.slice(TaLocation2.SSH.length);
|
|
221
|
+
const slash = rest.indexOf("/");
|
|
222
|
+
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
223
|
+
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
224
|
+
if (!isHost(host2)) {
|
|
225
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
226
|
+
}
|
|
227
|
+
return { host: host2, path: path2 };
|
|
228
|
+
}
|
|
229
|
+
TaLocation2.parse = parse;
|
|
230
|
+
function isHost(host2) {
|
|
231
|
+
return HOST.test(host2);
|
|
232
|
+
}
|
|
233
|
+
TaLocation2.isHost = isHost;
|
|
234
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
235
|
+
function readHost(input) {
|
|
236
|
+
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
237
|
+
if (words[0] === "ssh") {
|
|
238
|
+
words.shift();
|
|
239
|
+
}
|
|
240
|
+
let destination;
|
|
241
|
+
let port;
|
|
242
|
+
let user;
|
|
243
|
+
const options = [];
|
|
244
|
+
for (let i = 0;i < words.length; i++) {
|
|
245
|
+
const word = words[i];
|
|
246
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
247
|
+
if (word === "-p" || word === "-l" || glued) {
|
|
248
|
+
const value = glued ? glued[2] : words[++i];
|
|
249
|
+
if (value === undefined) {
|
|
250
|
+
return { error: "invalid" };
|
|
251
|
+
}
|
|
252
|
+
if ((glued ? glued[1] : word[1]) === "p") {
|
|
253
|
+
port = value;
|
|
254
|
+
} else {
|
|
255
|
+
user = value;
|
|
256
|
+
}
|
|
257
|
+
} else if (word === "-o" || word.startsWith("-o")) {
|
|
258
|
+
const value = word === "-o" ? words[++i] : word.slice(2);
|
|
259
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
260
|
+
if (!option) {
|
|
261
|
+
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
262
|
+
} else if (option[1].toLowerCase() === "port") {
|
|
263
|
+
port = option[2];
|
|
264
|
+
} else {
|
|
265
|
+
user = option[2];
|
|
266
|
+
}
|
|
267
|
+
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
268
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
269
|
+
} else if (destination === undefined) {
|
|
270
|
+
destination = word;
|
|
271
|
+
} else {
|
|
272
|
+
return { error: "invalid" };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (options.length > 0) {
|
|
276
|
+
return { error: "options", options };
|
|
277
|
+
}
|
|
278
|
+
if (!destination) {
|
|
279
|
+
return { error: "empty" };
|
|
280
|
+
}
|
|
281
|
+
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
282
|
+
if (user && !host2.includes("@")) {
|
|
283
|
+
host2 = `${user}@${host2}`;
|
|
284
|
+
}
|
|
285
|
+
if (port) {
|
|
286
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
287
|
+
return { error: "invalid" };
|
|
288
|
+
}
|
|
289
|
+
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
290
|
+
}
|
|
291
|
+
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
292
|
+
}
|
|
293
|
+
TaLocation2.readHost = readHost;
|
|
294
|
+
function ssh(host2, path2 = "") {
|
|
295
|
+
return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
296
|
+
}
|
|
297
|
+
TaLocation2.ssh = ssh;
|
|
298
|
+
function hostLabel(host2) {
|
|
299
|
+
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
300
|
+
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
301
|
+
}
|
|
302
|
+
TaLocation2.hostLabel = hostLabel;
|
|
303
|
+
function host(location) {
|
|
304
|
+
var _a;
|
|
305
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
306
|
+
}
|
|
307
|
+
TaLocation2.host = host;
|
|
308
|
+
function path(location) {
|
|
309
|
+
var _a;
|
|
310
|
+
var _b;
|
|
311
|
+
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
312
|
+
}
|
|
313
|
+
TaLocation2.path = path;
|
|
314
|
+
function parent(location) {
|
|
315
|
+
const remote = parse(location);
|
|
316
|
+
if (remote) {
|
|
317
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
318
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
319
|
+
}
|
|
320
|
+
return parentPath(location);
|
|
321
|
+
}
|
|
322
|
+
TaLocation2.parent = parent;
|
|
323
|
+
function child(location, name) {
|
|
324
|
+
const remote = parse(location);
|
|
325
|
+
if (remote) {
|
|
326
|
+
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
327
|
+
}
|
|
328
|
+
return childPath(location, name);
|
|
329
|
+
}
|
|
330
|
+
TaLocation2.child = child;
|
|
331
|
+
function basename(location) {
|
|
332
|
+
const remote = parse(location);
|
|
333
|
+
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
334
|
+
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
335
|
+
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
336
|
+
}
|
|
337
|
+
TaLocation2.basename = basename;
|
|
338
|
+
function parentPath(path2) {
|
|
339
|
+
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
340
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
341
|
+
if (at < 0) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const head = trimmed.slice(0, at);
|
|
345
|
+
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
346
|
+
}
|
|
347
|
+
function childPath(path2, name) {
|
|
348
|
+
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
349
|
+
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
350
|
+
}
|
|
351
|
+
function normalize(path2) {
|
|
352
|
+
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
353
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
354
|
+
}
|
|
355
|
+
})(TaLocation || (TaLocation = {}));
|
|
356
|
+
// ../ta-protocol/esm/common/package-protocol.js
|
|
357
|
+
var TaPackageServer = Symbol("TaPackageServer");
|
|
358
|
+
var TaPackageTextUtil;
|
|
359
|
+
(function(TaPackageTextUtil2) {
|
|
360
|
+
function pick(text, language) {
|
|
361
|
+
var _a, _b, _c, _d;
|
|
362
|
+
if (text === undefined || typeof text === "string") {
|
|
363
|
+
return text;
|
|
364
|
+
}
|
|
365
|
+
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];
|
|
366
|
+
}
|
|
367
|
+
TaPackageTextUtil2.pick = pick;
|
|
368
|
+
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
369
|
+
// ../ta-protocol/esm/common/relay-protocol.js
|
|
370
|
+
var TaRelayServer = Symbol("TaRelayServer");
|
|
371
|
+
// ../ta-protocol/esm/common/remote-protocol.js
|
|
372
|
+
var TaRemoteServer = Symbol("TaRemoteServer");
|
|
373
|
+
// ../ta-protocol/esm/common/settings-protocol.js
|
|
374
|
+
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
375
|
+
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
376
|
+
var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
|
|
377
|
+
// ../ta-protocol/esm/common/ta-protocol.js
|
|
378
|
+
var TaServer = Symbol("TaServer");
|
|
379
|
+
var TaClient = Symbol("TaClient");
|
|
380
|
+
var TaErrorUtil;
|
|
381
|
+
(function(TaErrorUtil2) {
|
|
382
|
+
function code(error) {
|
|
383
|
+
var _a;
|
|
384
|
+
var _b;
|
|
385
|
+
const failure = error;
|
|
386
|
+
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;
|
|
387
|
+
return typeof code2 === "string" ? code2 : undefined;
|
|
388
|
+
}
|
|
389
|
+
TaErrorUtil2.code = code;
|
|
390
|
+
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
391
|
+
var TaMessageContext;
|
|
392
|
+
(function(TaMessageContext2) {
|
|
393
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
394
|
+
function wrap(context, message) {
|
|
395
|
+
return `<context>
|
|
396
|
+
${context}
|
|
397
|
+
</context>
|
|
398
|
+
${message}`;
|
|
399
|
+
}
|
|
400
|
+
TaMessageContext2.wrap = wrap;
|
|
401
|
+
function strip(message) {
|
|
402
|
+
return message.replace(BLOCK, "");
|
|
403
|
+
}
|
|
404
|
+
TaMessageContext2.strip = strip;
|
|
405
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
406
|
+
var TaSkillUse;
|
|
407
|
+
(function(TaSkillUse2) {
|
|
408
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
409
|
+
function parse(message) {
|
|
410
|
+
var _a;
|
|
411
|
+
const match = BLOCK.exec(message);
|
|
412
|
+
if (!match) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
416
|
+
}
|
|
417
|
+
TaSkillUse2.parse = parse;
|
|
418
|
+
function command(use) {
|
|
419
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
420
|
+
}
|
|
421
|
+
TaSkillUse2.command = command;
|
|
422
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
423
|
+
// ../ta-protocol/esm/common/workspace-protocol.js
|
|
424
|
+
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
425
|
+
var TaTerminalServer = Symbol("TaTerminalServer");
|
|
426
|
+
var TaExcludedFiles;
|
|
427
|
+
(function(TaExcludedFiles2) {
|
|
428
|
+
TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
|
|
429
|
+
function has(name) {
|
|
430
|
+
return TaExcludedFiles2.NAMES.includes(name);
|
|
431
|
+
}
|
|
432
|
+
TaExcludedFiles2.has = has;
|
|
433
|
+
function filter(entries) {
|
|
434
|
+
return entries.filter((entry) => !has(entry.name));
|
|
435
|
+
}
|
|
436
|
+
TaExcludedFiles2.filter = filter;
|
|
437
|
+
})(TaExcludedFiles || (TaExcludedFiles = {}));
|
|
438
|
+
var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
|
|
439
|
+
// web-src/session-bridge.ts
|
|
440
|
+
class NoDoubleError extends Error {
|
|
441
|
+
constructor() {
|
|
442
|
+
super("The double has no conversation yet.");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
var ATTACH_MS = 15000;
|
|
446
|
+
var SWEEP_MS = 60000;
|
|
447
|
+
|
|
448
|
+
class SessionBridge {
|
|
449
|
+
host;
|
|
450
|
+
attachMs;
|
|
451
|
+
handlers = new Map;
|
|
452
|
+
waiting = new Map;
|
|
453
|
+
opened = new Set;
|
|
454
|
+
timer;
|
|
455
|
+
constructor(host, attachMs = ATTACH_MS) {
|
|
456
|
+
this.host = host;
|
|
457
|
+
this.attachMs = attachMs;
|
|
458
|
+
}
|
|
459
|
+
attach(piSessionId, handler) {
|
|
460
|
+
this.handlers.set(piSessionId, handler);
|
|
461
|
+
for (const resolve of this.waiting.get(piSessionId) ?? []) {
|
|
462
|
+
resolve(handler);
|
|
463
|
+
}
|
|
464
|
+
this.waiting.delete(piSessionId);
|
|
465
|
+
return () => {
|
|
466
|
+
if (this.handlers.get(piSessionId) === handler) {
|
|
467
|
+
this.handlers.delete(piSessionId);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async sessionFile(target) {
|
|
472
|
+
if (target.kind === "session") {
|
|
473
|
+
return target.sessionFile;
|
|
474
|
+
}
|
|
475
|
+
const file = await this.host.getExtensionData(TA_DOUBLE_FILE.name, TA_DOUBLE_FILE.key);
|
|
476
|
+
return typeof file === "string" && file ? file : undefined;
|
|
477
|
+
}
|
|
478
|
+
async deliver(target, delivery) {
|
|
479
|
+
const file = await this.sessionFile(target);
|
|
480
|
+
if (!file) {
|
|
481
|
+
throw new NoDoubleError;
|
|
482
|
+
}
|
|
483
|
+
const handler = await this.handler(file, target);
|
|
484
|
+
handler.deliver(delivery);
|
|
485
|
+
}
|
|
486
|
+
dispose() {
|
|
487
|
+
clearInterval(this.timer);
|
|
488
|
+
this.timer = undefined;
|
|
489
|
+
}
|
|
490
|
+
async handler(file, target) {
|
|
491
|
+
const open = (await this.host.listSessions()).find((session) => session.sessionFile === file);
|
|
492
|
+
let info = open;
|
|
493
|
+
if (!info) {
|
|
494
|
+
const cwd = target.kind === "session" && target.cwd || await this.host.sessionCwd(file) || (await this.host.getServerInfo()).cwd;
|
|
495
|
+
info = await this.host.openSession({ cwd, sessionFile: file });
|
|
496
|
+
this.opened.add(info.sessionId);
|
|
497
|
+
this.sweepLater();
|
|
498
|
+
}
|
|
499
|
+
const ready = this.handlers.get(info.piSessionId);
|
|
500
|
+
if (ready) {
|
|
501
|
+
return ready;
|
|
502
|
+
}
|
|
503
|
+
const piSessionId = info.piSessionId;
|
|
504
|
+
return new Promise((resolve, reject) => {
|
|
505
|
+
const timer = setTimeout(() => {
|
|
506
|
+
this.waiting.set(piSessionId, (this.waiting.get(piSessionId) ?? []).filter((other) => other !== done));
|
|
507
|
+
reject(new Error("The conversation did not load the extension of the bots; it may be turned off."));
|
|
508
|
+
}, this.attachMs);
|
|
509
|
+
const done = (handler) => {
|
|
510
|
+
clearTimeout(timer);
|
|
511
|
+
resolve(handler);
|
|
512
|
+
};
|
|
513
|
+
this.waiting.set(piSessionId, [...this.waiting.get(piSessionId) ?? [], done]);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
sweepLater() {
|
|
517
|
+
if (this.timer) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
this.timer = setInterval(() => void this.sweep().catch(() => {
|
|
521
|
+
return;
|
|
522
|
+
}), SWEEP_MS);
|
|
523
|
+
this.timer.unref?.();
|
|
524
|
+
}
|
|
525
|
+
async sweep() {
|
|
526
|
+
const open = new Map((await this.host.listSessions()).map((info) => [info.sessionId, info]));
|
|
527
|
+
for (const sessionId of [...this.opened]) {
|
|
528
|
+
const info = open.get(sessionId);
|
|
529
|
+
if (!info) {
|
|
530
|
+
this.opened.delete(sessionId);
|
|
531
|
+
} else if (info.attached === 0 && !info.isStreaming) {
|
|
532
|
+
this.opened.delete(sessionId);
|
|
533
|
+
await this.host.closeSession(sessionId).catch(() => {
|
|
534
|
+
return;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (this.opened.size === 0) {
|
|
539
|
+
this.dispose();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// web-src/media-crypto.ts
|
|
545
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
546
|
+
var MediaCrypto;
|
|
547
|
+
((MediaCrypto) => {
|
|
548
|
+
function encryptEcb(data, key) {
|
|
549
|
+
const cipher = createCipheriv("aes-128-ecb", key, null);
|
|
550
|
+
return Buffer.concat([cipher.update(data), cipher.final()]);
|
|
551
|
+
}
|
|
552
|
+
MediaCrypto.encryptEcb = encryptEcb;
|
|
553
|
+
function decryptEcb(data, key) {
|
|
554
|
+
const decipher = createDecipheriv("aes-128-ecb", key, null);
|
|
555
|
+
return Buffer.concat([decipher.update(data), decipher.final()]);
|
|
556
|
+
}
|
|
557
|
+
MediaCrypto.decryptEcb = decryptEcb;
|
|
558
|
+
function ecbSize(size) {
|
|
559
|
+
return Math.ceil((size + 1) / 16) * 16;
|
|
560
|
+
}
|
|
561
|
+
MediaCrypto.ecbSize = ecbSize;
|
|
562
|
+
function weixinKey(aesKey) {
|
|
563
|
+
const decoded = Buffer.from(aesKey, "base64");
|
|
564
|
+
if (decoded.length === 16) {
|
|
565
|
+
return decoded;
|
|
566
|
+
}
|
|
567
|
+
const text = decoded.toString("ascii");
|
|
568
|
+
if (decoded.length === 32 && /^[0-9a-f]{32}$/i.test(text)) {
|
|
569
|
+
return Buffer.from(text, "hex");
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`The key of the file is ${decoded.length} bytes, not 16.`);
|
|
572
|
+
}
|
|
573
|
+
MediaCrypto.weixinKey = weixinKey;
|
|
574
|
+
function decryptWecom(data, aesKey) {
|
|
575
|
+
const key = Buffer.from(aesKey, "base64");
|
|
576
|
+
const decipher = createDecipheriv("aes-256-cbc", key, key.subarray(0, 16));
|
|
577
|
+
decipher.setAutoPadding(false);
|
|
578
|
+
const plain = Buffer.concat([decipher.update(data), decipher.final()]);
|
|
579
|
+
const pad = plain[plain.length - 1];
|
|
580
|
+
if (!pad || pad > 32 || pad > plain.length || plain.subarray(plain.length - pad).some((byte) => byte !== pad)) {
|
|
581
|
+
throw new Error("The file of WeCom did not decrypt: its padding is wrong.");
|
|
582
|
+
}
|
|
583
|
+
return plain.subarray(0, plain.length - pad);
|
|
584
|
+
}
|
|
585
|
+
MediaCrypto.decryptWecom = decryptWecom;
|
|
586
|
+
function encryptWecom(data, aesKey) {
|
|
587
|
+
const key = Buffer.from(aesKey, "base64");
|
|
588
|
+
const pad = 32 - data.length % 32;
|
|
589
|
+
const cipher = createCipheriv("aes-256-cbc", key, key.subarray(0, 16));
|
|
590
|
+
cipher.setAutoPadding(false);
|
|
591
|
+
return Buffer.concat([cipher.update(Buffer.concat([data, Buffer.alloc(pad, pad)])), cipher.final()]);
|
|
592
|
+
}
|
|
593
|
+
MediaCrypto.encryptWecom = encryptWecom;
|
|
594
|
+
function md5(data) {
|
|
595
|
+
return createHash("md5").update(data).digest("hex");
|
|
596
|
+
}
|
|
597
|
+
MediaCrypto.md5 = md5;
|
|
598
|
+
function random(bytes) {
|
|
599
|
+
return randomBytes(bytes);
|
|
600
|
+
}
|
|
601
|
+
MediaCrypto.random = random;
|
|
602
|
+
})(MediaCrypto ||= {});
|
|
603
|
+
|
|
604
|
+
// web-src/text-util.ts
|
|
605
|
+
var MIME = {
|
|
606
|
+
jpg: "image/jpeg",
|
|
607
|
+
jpeg: "image/jpeg",
|
|
608
|
+
png: "image/png",
|
|
609
|
+
gif: "image/gif",
|
|
610
|
+
webp: "image/webp",
|
|
611
|
+
bmp: "image/bmp",
|
|
612
|
+
mp4: "video/mp4",
|
|
613
|
+
mov: "video/quicktime",
|
|
614
|
+
webm: "video/webm",
|
|
615
|
+
mp3: "audio/mpeg",
|
|
616
|
+
wav: "audio/wav",
|
|
617
|
+
amr: "audio/amr",
|
|
618
|
+
silk: "audio/silk",
|
|
619
|
+
pdf: "application/pdf",
|
|
620
|
+
txt: "text/plain",
|
|
621
|
+
md: "text/markdown",
|
|
622
|
+
json: "application/json",
|
|
623
|
+
zip: "application/zip",
|
|
624
|
+
csv: "text/csv",
|
|
625
|
+
html: "text/html",
|
|
626
|
+
doc: "application/msword",
|
|
627
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
628
|
+
xls: "application/vnd.ms-excel",
|
|
629
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
630
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
631
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
632
|
+
};
|
|
633
|
+
var BotText;
|
|
634
|
+
((BotText) => {
|
|
635
|
+
function mimeOf(name) {
|
|
636
|
+
const ext = /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toLowerCase();
|
|
637
|
+
return ext && MIME[ext] || "application/octet-stream";
|
|
638
|
+
}
|
|
639
|
+
BotText.mimeOf = mimeOf;
|
|
640
|
+
function extensionOf(data) {
|
|
641
|
+
const hex = Array.from(data.subarray(0, 12), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
642
|
+
if (hex.startsWith("ffd8ff")) {
|
|
643
|
+
return ".jpg";
|
|
644
|
+
}
|
|
645
|
+
if (hex.startsWith("89504e47")) {
|
|
646
|
+
return ".png";
|
|
647
|
+
}
|
|
648
|
+
if (hex.startsWith("47494638")) {
|
|
649
|
+
return ".gif";
|
|
650
|
+
}
|
|
651
|
+
if (hex.startsWith("52494646") && hex.slice(16, 24) === "57454250") {
|
|
652
|
+
return ".webp";
|
|
653
|
+
}
|
|
654
|
+
if (hex.slice(8, 16) === "66747970") {
|
|
655
|
+
return ".mp4";
|
|
656
|
+
}
|
|
657
|
+
return "";
|
|
658
|
+
}
|
|
659
|
+
BotText.extensionOf = extensionOf;
|
|
660
|
+
function fileName(name, fallback) {
|
|
661
|
+
const clean = (name.split(/[\\/]/).pop() ?? "").replace(/[\\/:*?"<>|]+/g, "_").replace(/\p{Cc}+/gu, "_").replace(/^\.+/, "").trim().slice(0, 120);
|
|
662
|
+
return clean || fallback;
|
|
663
|
+
}
|
|
664
|
+
BotText.fileName = fileName;
|
|
665
|
+
function plain(markdown) {
|
|
666
|
+
const lines = [];
|
|
667
|
+
let fenced = false;
|
|
668
|
+
for (const line of markdown.replace(/\r\n/g, `
|
|
669
|
+
`).split(`
|
|
670
|
+
`)) {
|
|
671
|
+
if (/^\s*(```|~~~)/.test(line)) {
|
|
672
|
+
fenced = !fenced;
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (fenced) {
|
|
676
|
+
lines.push(line);
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
const text = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s{0,3}>\s?/, "│ ").replace(/^(\s*)[-*+]\s+\[( |x)\]\s+/i, (_, indent, mark) => `${indent}${mark.trim() ? "☑" : "☐"} `).replace(/^(\s*)[-*+]\s+/, "$1• ").replace(/^\s*([-*_])\s*\1\s*\1[\s\-*_]*$/, "──────").replace(/!\[([^\]]*)\]\(([^)\s]+)[^)]*\)/g, (_, alt, url) => alt ? `${alt} ${url}` : url).replace(/\[([^\]]+)\]\(([^)\s]+)[^)]*\)/g, (_, label, url) => label === url ? url : `${label} (${url})`).replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "$2").replace(/(^|[^*\w])\*(?=\S)([^*]*?\S)\*(?!\w)/g, "$1$2").replace(/~~(?=\S)([\s\S]*?\S)~~/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/^\|(.*)\|\s*$/, (_, cells) => /^[\s|:-]+$/.test(cells) ? "" : cells.split("|").map((cell) => cell.trim()).join(" "));
|
|
680
|
+
lines.push(text);
|
|
681
|
+
}
|
|
682
|
+
return lines.join(`
|
|
683
|
+
`).replace(/\n{3,}/g, `
|
|
684
|
+
|
|
685
|
+
`).trim();
|
|
686
|
+
}
|
|
687
|
+
BotText.plain = plain;
|
|
688
|
+
function split(text, max) {
|
|
689
|
+
const encoder = new TextEncoder;
|
|
690
|
+
const pieces = [];
|
|
691
|
+
let rest = text;
|
|
692
|
+
while (encoder.encode(rest).length > max) {
|
|
693
|
+
let end = fit(rest, max, encoder);
|
|
694
|
+
const window = rest.slice(0, end);
|
|
695
|
+
const cut = Math.max(window.lastIndexOf(`
|
|
696
|
+
|
|
697
|
+
`), window.lastIndexOf(`
|
|
698
|
+
`));
|
|
699
|
+
const space = window.lastIndexOf(" ");
|
|
700
|
+
if (cut > end / 2) {
|
|
701
|
+
end = cut;
|
|
702
|
+
} else if (space > end / 2) {
|
|
703
|
+
end = space;
|
|
704
|
+
}
|
|
705
|
+
pieces.push(rest.slice(0, end).trimEnd());
|
|
706
|
+
rest = rest.slice(end).replace(/^\s+/, "");
|
|
707
|
+
}
|
|
708
|
+
if (rest) {
|
|
709
|
+
pieces.push(rest);
|
|
710
|
+
}
|
|
711
|
+
return pieces;
|
|
712
|
+
}
|
|
713
|
+
BotText.split = split;
|
|
714
|
+
function fit(text, max, encoder) {
|
|
715
|
+
let low = 0;
|
|
716
|
+
let high = text.length;
|
|
717
|
+
while (low < high) {
|
|
718
|
+
const middle = Math.ceil((low + high) / 2);
|
|
719
|
+
if (encoder.encode(text.slice(0, middle)).length <= max) {
|
|
720
|
+
low = middle;
|
|
721
|
+
} else {
|
|
722
|
+
high = middle - 1;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const code = text.charCodeAt(low - 1);
|
|
726
|
+
return code >= 55296 && code <= 56319 ? low - 1 : Math.max(1, low);
|
|
727
|
+
}
|
|
728
|
+
})(BotText ||= {});
|
|
729
|
+
|
|
730
|
+
// web-src/wecom-socket.ts
|
|
731
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
732
|
+
|
|
733
|
+
// web-src/web-socket-client.ts
|
|
734
|
+
import { createHash as createHash2, randomBytes as randomBytes2 } from "node:crypto";
|
|
735
|
+
import { connect as connectTcp } from "node:net";
|
|
736
|
+
import { connect as connectTls } from "node:tls";
|
|
737
|
+
var GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
738
|
+
var MAX_MESSAGE = 32 * 1024 * 1024;
|
|
739
|
+
var HANDSHAKE_MS = 15000;
|
|
740
|
+
|
|
741
|
+
class WebSocketClient {
|
|
742
|
+
readyState = 0;
|
|
743
|
+
socket;
|
|
744
|
+
key = randomBytes2(16).toString("base64");
|
|
745
|
+
listeners = new Map;
|
|
746
|
+
buffer = Buffer.alloc(0);
|
|
747
|
+
handshaken = false;
|
|
748
|
+
fragments = [];
|
|
749
|
+
fragmentType = 0;
|
|
750
|
+
ended = false;
|
|
751
|
+
timer;
|
|
752
|
+
constructor(url) {
|
|
753
|
+
const target = new URL(url);
|
|
754
|
+
const secure = target.protocol === "wss:";
|
|
755
|
+
const host = target.hostname;
|
|
756
|
+
const port = Number(target.port) || (secure ? 443 : 80);
|
|
757
|
+
this.socket = secure ? connectTls({ host, port, servername: host }) : connectTcp({ host, port });
|
|
758
|
+
this.socket.once(secure ? "secureConnect" : "connect", () => {
|
|
759
|
+
const path = `${target.pathname || "/"}${target.search}`;
|
|
760
|
+
this.socket.write([
|
|
761
|
+
`GET ${path} HTTP/1.1`,
|
|
762
|
+
`Host: ${target.host}`,
|
|
763
|
+
"Upgrade: websocket",
|
|
764
|
+
"Connection: Upgrade",
|
|
765
|
+
`Sec-WebSocket-Key: ${this.key}`,
|
|
766
|
+
"Sec-WebSocket-Version: 13",
|
|
767
|
+
"User-Agent: Ta",
|
|
768
|
+
"",
|
|
769
|
+
""
|
|
770
|
+
].join(`\r
|
|
771
|
+
`));
|
|
772
|
+
});
|
|
773
|
+
this.socket.on("data", (chunk) => this.receive(chunk));
|
|
774
|
+
this.socket.on("error", () => this.emit("error", {}));
|
|
775
|
+
this.socket.on("close", () => this.end());
|
|
776
|
+
this.timer = setTimeout(() => !this.handshaken && this.socket.destroy(), HANDSHAKE_MS);
|
|
777
|
+
this.timer.unref?.();
|
|
778
|
+
}
|
|
779
|
+
addEventListener(type, listener) {
|
|
780
|
+
this.listeners.set(type, [...this.listeners.get(type) ?? [], listener]);
|
|
781
|
+
}
|
|
782
|
+
send(data) {
|
|
783
|
+
if (this.readyState !== 1) {
|
|
784
|
+
throw new Error("The WebSocket is not open.");
|
|
785
|
+
}
|
|
786
|
+
this.socket.write(WebSocketClient.frame(1, Buffer.from(data)));
|
|
787
|
+
}
|
|
788
|
+
close() {
|
|
789
|
+
if (this.readyState === 1) {
|
|
790
|
+
this.readyState = 2;
|
|
791
|
+
this.socket.write(WebSocketClient.frame(8, Buffer.alloc(0)));
|
|
792
|
+
this.socket.end();
|
|
793
|
+
const timer = setTimeout(() => this.socket.destroy(), 1000);
|
|
794
|
+
timer.unref?.();
|
|
795
|
+
} else if (this.readyState === 0) {
|
|
796
|
+
this.socket.destroy();
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
static frame(opcode, payload) {
|
|
800
|
+
const length = payload.length;
|
|
801
|
+
const head = length < 126 ? Buffer.alloc(2) : length < 65536 ? Buffer.alloc(4) : Buffer.alloc(10);
|
|
802
|
+
head[0] = 128 | opcode;
|
|
803
|
+
if (length < 126) {
|
|
804
|
+
head[1] = 128 | length;
|
|
805
|
+
} else if (length < 65536) {
|
|
806
|
+
head[1] = 128 | 126;
|
|
807
|
+
head.writeUInt16BE(length, 2);
|
|
808
|
+
} else {
|
|
809
|
+
head[1] = 128 | 127;
|
|
810
|
+
head.writeBigUInt64BE(BigInt(length), 2);
|
|
811
|
+
}
|
|
812
|
+
const mask = randomBytes2(4);
|
|
813
|
+
const masked = Buffer.alloc(length);
|
|
814
|
+
for (let index = 0;index < length; index++) {
|
|
815
|
+
masked[index] = payload[index] ^ mask[index & 3];
|
|
816
|
+
}
|
|
817
|
+
return Buffer.concat([head, mask, masked]);
|
|
818
|
+
}
|
|
819
|
+
receive(chunk) {
|
|
820
|
+
this.buffer = this.buffer.length ? Buffer.concat([this.buffer, chunk]) : chunk;
|
|
821
|
+
if (!this.handshaken) {
|
|
822
|
+
const end = this.buffer.indexOf(`\r
|
|
823
|
+
\r
|
|
824
|
+
`);
|
|
825
|
+
if (end < 0) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const head = this.buffer.subarray(0, end).toString("latin1");
|
|
829
|
+
this.buffer = this.buffer.subarray(end + 4);
|
|
830
|
+
const accept = /^sec-websocket-accept:\s*(\S+)/im.exec(head)?.[1];
|
|
831
|
+
const expected = createHash2("sha1").update(this.key + GUID).digest("base64");
|
|
832
|
+
if (!/^HTTP\/1\.1 101 /.test(head) || accept !== expected) {
|
|
833
|
+
this.socket.destroy();
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
this.handshaken = true;
|
|
837
|
+
clearTimeout(this.timer);
|
|
838
|
+
this.readyState = 1;
|
|
839
|
+
this.emit("open", {});
|
|
840
|
+
}
|
|
841
|
+
this.frames();
|
|
842
|
+
}
|
|
843
|
+
frames() {
|
|
844
|
+
for (;; ) {
|
|
845
|
+
if (this.buffer.length < 2) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const first = this.buffer[0];
|
|
849
|
+
const second = this.buffer[1];
|
|
850
|
+
let length = second & 127;
|
|
851
|
+
let offset = 2;
|
|
852
|
+
if (length === 126) {
|
|
853
|
+
if (this.buffer.length < 4) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
length = this.buffer.readUInt16BE(2);
|
|
857
|
+
offset = 4;
|
|
858
|
+
} else if (length === 127) {
|
|
859
|
+
if (this.buffer.length < 10) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
length = Number(this.buffer.readBigUInt64BE(2));
|
|
863
|
+
offset = 10;
|
|
864
|
+
}
|
|
865
|
+
const masked = (second & 128) !== 0;
|
|
866
|
+
const total = offset + (masked ? 4 : 0) + length;
|
|
867
|
+
if (length > MAX_MESSAGE) {
|
|
868
|
+
this.socket.destroy();
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if (this.buffer.length < total) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
let payload = this.buffer.subarray(offset + (masked ? 4 : 0), total);
|
|
875
|
+
if (masked) {
|
|
876
|
+
const mask = this.buffer.subarray(offset, offset + 4);
|
|
877
|
+
payload = Buffer.from(payload.map((byte, index) => byte ^ mask[index & 3]));
|
|
878
|
+
}
|
|
879
|
+
this.buffer = this.buffer.subarray(total);
|
|
880
|
+
this.frame((first & 128) !== 0, first & 15, payload);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
frame(fin, opcode, payload) {
|
|
884
|
+
switch (opcode) {
|
|
885
|
+
case 0:
|
|
886
|
+
case 1:
|
|
887
|
+
case 2: {
|
|
888
|
+
if (opcode !== 0) {
|
|
889
|
+
this.fragmentType = opcode;
|
|
890
|
+
this.fragments = [];
|
|
891
|
+
}
|
|
892
|
+
this.fragments.push(payload);
|
|
893
|
+
if (fin) {
|
|
894
|
+
const data = Buffer.concat(this.fragments);
|
|
895
|
+
this.fragments = [];
|
|
896
|
+
this.emit("message", { data: this.fragmentType === 1 ? data.toString("utf8") : data });
|
|
897
|
+
}
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
case 8:
|
|
901
|
+
if (this.readyState === 1) {
|
|
902
|
+
this.readyState = 2;
|
|
903
|
+
this.socket.end(WebSocketClient.frame(8, Buffer.alloc(0)));
|
|
904
|
+
}
|
|
905
|
+
return;
|
|
906
|
+
case 9:
|
|
907
|
+
if (this.readyState === 1) {
|
|
908
|
+
this.socket.write(WebSocketClient.frame(10, payload));
|
|
909
|
+
}
|
|
910
|
+
return;
|
|
911
|
+
default:
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
end() {
|
|
916
|
+
if (this.ended) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
this.ended = true;
|
|
920
|
+
clearTimeout(this.timer);
|
|
921
|
+
this.readyState = 3;
|
|
922
|
+
this.emit("close", {});
|
|
923
|
+
}
|
|
924
|
+
emit(type, event) {
|
|
925
|
+
for (const listener of this.listeners.get(type) ?? []) {
|
|
926
|
+
listener(event);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// web-src/wecom-socket.ts
|
|
932
|
+
var HEARTBEAT_MS = 30000;
|
|
933
|
+
var ACK_MS = 1e4;
|
|
934
|
+
var MAX_DELAY_MS = 30000;
|
|
935
|
+
var MAX_AUTH_FAILURES = 5;
|
|
936
|
+
var OPEN = 1;
|
|
937
|
+
function requestId(prefix) {
|
|
938
|
+
return `${prefix}_${Date.now()}_${randomBytes3(4).toString("hex")}`;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
class WecomSocket {
|
|
942
|
+
url;
|
|
943
|
+
credentials;
|
|
944
|
+
events;
|
|
945
|
+
factory;
|
|
946
|
+
socket;
|
|
947
|
+
stopped = true;
|
|
948
|
+
ready = false;
|
|
949
|
+
attempts = 0;
|
|
950
|
+
authFailures = 0;
|
|
951
|
+
missed = 0;
|
|
952
|
+
heartbeat;
|
|
953
|
+
retry;
|
|
954
|
+
pending = new Map;
|
|
955
|
+
chains = new Map;
|
|
956
|
+
constructor(url, credentials, events, factory = (url2) => new WebSocketClient(url2)) {
|
|
957
|
+
this.url = url;
|
|
958
|
+
this.credentials = credentials;
|
|
959
|
+
this.events = events;
|
|
960
|
+
this.factory = factory;
|
|
961
|
+
}
|
|
962
|
+
get connected() {
|
|
963
|
+
return this.ready;
|
|
964
|
+
}
|
|
965
|
+
start() {
|
|
966
|
+
if (!this.stopped) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
this.stopped = false;
|
|
970
|
+
this.connect();
|
|
971
|
+
}
|
|
972
|
+
stop() {
|
|
973
|
+
this.stopped = true;
|
|
974
|
+
clearTimeout(this.retry);
|
|
975
|
+
this.drop("stopped");
|
|
976
|
+
}
|
|
977
|
+
request(cmd, body, reqId = requestId(cmd)) {
|
|
978
|
+
const previous = this.chains.get(reqId) ?? Promise.resolve();
|
|
979
|
+
const next = previous.catch(() => {
|
|
980
|
+
return;
|
|
981
|
+
}).then(() => this.send(cmd, body, reqId));
|
|
982
|
+
this.chains.set(reqId, next);
|
|
983
|
+
next.catch(() => {
|
|
984
|
+
return;
|
|
985
|
+
}).finally(() => {
|
|
986
|
+
if (this.chains.get(reqId) === next) {
|
|
987
|
+
this.chains.delete(reqId);
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
return next;
|
|
991
|
+
}
|
|
992
|
+
send(cmd, body, reqId) {
|
|
993
|
+
return new Promise((resolve, reject) => {
|
|
994
|
+
if (!this.socket || this.socket.readyState !== OPEN || !this.ready) {
|
|
995
|
+
reject(new Error("The robot of WeCom is not connected."));
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
const timer = setTimeout(() => {
|
|
999
|
+
this.pending.delete(reqId);
|
|
1000
|
+
reject(new Error(`WeCom did not answer ${cmd}.`));
|
|
1001
|
+
}, ACK_MS);
|
|
1002
|
+
this.pending.set(reqId, { resolve, reject, timer });
|
|
1003
|
+
this.socket.send(JSON.stringify({ cmd, headers: { req_id: reqId }, body }));
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
connect() {
|
|
1007
|
+
let socket;
|
|
1008
|
+
try {
|
|
1009
|
+
socket = this.factory(this.url);
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
this.events.down(errorText(error), false);
|
|
1012
|
+
this.schedule();
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
this.socket = socket;
|
|
1016
|
+
socket.addEventListener("open", () => {
|
|
1017
|
+
socket.send(JSON.stringify({
|
|
1018
|
+
cmd: "aibot_subscribe",
|
|
1019
|
+
headers: { req_id: requestId("aibot_subscribe") },
|
|
1020
|
+
body: { bot_id: this.credentials.botId, secret: this.credentials.secret }
|
|
1021
|
+
}));
|
|
1022
|
+
});
|
|
1023
|
+
socket.addEventListener("message", (event) => {
|
|
1024
|
+
if (this.socket === socket) {
|
|
1025
|
+
this.receive(String(event.data ?? ""));
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
socket.addEventListener("close", () => {
|
|
1029
|
+
if (this.socket === socket) {
|
|
1030
|
+
this.drop("closed");
|
|
1031
|
+
this.events.down("The connection to WeCom closed.", false);
|
|
1032
|
+
this.schedule();
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
socket.addEventListener("error", () => {
|
|
1036
|
+
return;
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
receive(data) {
|
|
1040
|
+
let frame;
|
|
1041
|
+
try {
|
|
1042
|
+
frame = JSON.parse(data);
|
|
1043
|
+
} catch {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
const reqId = frame.headers?.req_id ?? "";
|
|
1047
|
+
if (frame.cmd) {
|
|
1048
|
+
if (frame.cmd === "aibot_event_callback" && frame.body?.event?.eventtype === "disconnected_event") {
|
|
1049
|
+
this.stopped = true;
|
|
1050
|
+
this.drop("replaced");
|
|
1051
|
+
this.events.down("This robot connected from somewhere else.", true);
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
this.events.frame(frame);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (reqId.startsWith("aibot_subscribe")) {
|
|
1058
|
+
if (frame.errcode) {
|
|
1059
|
+
const fatal = ++this.authFailures >= MAX_AUTH_FAILURES;
|
|
1060
|
+
this.events.down(`WeCom refused the robot's id or secret (${frame.errcode}${frame.errmsg ? `: ${frame.errmsg}` : ""}).`, fatal);
|
|
1061
|
+
if (fatal) {
|
|
1062
|
+
this.stopped = true;
|
|
1063
|
+
}
|
|
1064
|
+
this.socket?.close();
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
this.ready = true;
|
|
1068
|
+
this.attempts = 0;
|
|
1069
|
+
this.authFailures = 0;
|
|
1070
|
+
this.missed = 0;
|
|
1071
|
+
clearInterval(this.heartbeat);
|
|
1072
|
+
this.heartbeat = setInterval(() => this.ping(), HEARTBEAT_MS);
|
|
1073
|
+
this.heartbeat.unref?.();
|
|
1074
|
+
this.events.ready();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (reqId.startsWith("ping")) {
|
|
1078
|
+
this.missed = 0;
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
const waiting = this.pending.get(reqId);
|
|
1082
|
+
if (waiting) {
|
|
1083
|
+
this.pending.delete(reqId);
|
|
1084
|
+
clearTimeout(waiting.timer);
|
|
1085
|
+
if (frame.errcode) {
|
|
1086
|
+
waiting.reject(Object.assign(new Error(`WeCom answered ${frame.errcode}${frame.errmsg ? `: ${frame.errmsg}` : ""}`), { errcode: frame.errcode }));
|
|
1087
|
+
} else {
|
|
1088
|
+
waiting.resolve(frame);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
ping() {
|
|
1093
|
+
if (this.missed >= 2) {
|
|
1094
|
+
this.socket?.close();
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
this.missed++;
|
|
1098
|
+
try {
|
|
1099
|
+
this.socket?.send(JSON.stringify({ cmd: "ping", headers: { req_id: requestId("ping") } }));
|
|
1100
|
+
} catch {
|
|
1101
|
+
this.socket?.close();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
drop(reason) {
|
|
1105
|
+
this.ready = false;
|
|
1106
|
+
clearInterval(this.heartbeat);
|
|
1107
|
+
const socket = this.socket;
|
|
1108
|
+
this.socket = undefined;
|
|
1109
|
+
try {
|
|
1110
|
+
socket?.close();
|
|
1111
|
+
} catch {}
|
|
1112
|
+
for (const [reqId, waiting] of this.pending) {
|
|
1113
|
+
clearTimeout(waiting.timer);
|
|
1114
|
+
waiting.reject(new Error(`The connection to WeCom went (${reason}).`));
|
|
1115
|
+
this.pending.delete(reqId);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
schedule() {
|
|
1119
|
+
if (this.stopped) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
clearTimeout(this.retry);
|
|
1123
|
+
const delay = Math.min(MAX_DELAY_MS, 1000 * 2 ** this.attempts++);
|
|
1124
|
+
this.retry = setTimeout(() => !this.stopped && this.connect(), delay);
|
|
1125
|
+
this.retry.unref?.();
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// web-src/wecom-channel.ts
|
|
1130
|
+
var STREAM_BYTES = 20000;
|
|
1131
|
+
var MARKDOWN_BYTES = 4000;
|
|
1132
|
+
var THINKING = "<think></think>";
|
|
1133
|
+
var CHUNK_BYTES = 512 * 1024;
|
|
1134
|
+
var MAX_CHUNKS = 100;
|
|
1135
|
+
var LIMITS = { image: 10 * 1024 * 1024, video: 10 * 1024 * 1024, voice: 2 * 1024 * 1024, file: 20 * 1024 * 1024 };
|
|
1136
|
+
var DOWNLOAD_MS = 60000;
|
|
1137
|
+
|
|
1138
|
+
class WecomChannel {
|
|
1139
|
+
fetcher;
|
|
1140
|
+
kind = "wecom";
|
|
1141
|
+
socket;
|
|
1142
|
+
messageHandler = () => {
|
|
1143
|
+
return;
|
|
1144
|
+
};
|
|
1145
|
+
stateHandler = () => {
|
|
1146
|
+
return;
|
|
1147
|
+
};
|
|
1148
|
+
constructor(url, credentials, fetcher = fetch, factory) {
|
|
1149
|
+
this.fetcher = fetcher;
|
|
1150
|
+
this.socket = new WecomSocket(url, credentials, {
|
|
1151
|
+
ready: () => this.stateHandler({ status: "online" }),
|
|
1152
|
+
frame: (frame) => void this.receive(frame).catch((error) => console.error(`ta-bots: a message of WeCom failed: ${errorText(error)}`)),
|
|
1153
|
+
down: (reason, fatal) => this.stateHandler({ status: fatal ? "error" : "connecting", error: reason })
|
|
1154
|
+
}, factory);
|
|
1155
|
+
}
|
|
1156
|
+
onMessage(handler) {
|
|
1157
|
+
this.messageHandler = handler;
|
|
1158
|
+
}
|
|
1159
|
+
onState(handler) {
|
|
1160
|
+
this.stateHandler = handler;
|
|
1161
|
+
}
|
|
1162
|
+
start() {
|
|
1163
|
+
this.stateHandler({ status: "connecting" });
|
|
1164
|
+
this.socket.start();
|
|
1165
|
+
}
|
|
1166
|
+
async stop() {
|
|
1167
|
+
this.socket.stop();
|
|
1168
|
+
this.stateHandler({ status: "offline" });
|
|
1169
|
+
}
|
|
1170
|
+
begin(chat, handle) {
|
|
1171
|
+
const stream = requestId("stream");
|
|
1172
|
+
const respond = (content, finish) => handle ? this.socket.request("aibot_respond_msg", { msgtype: "stream", stream: { id: stream, finish, content } }, handle) : Promise.reject(new Error("no frame"));
|
|
1173
|
+
const started = respond(THINKING, false).then(() => true, () => false);
|
|
1174
|
+
return {
|
|
1175
|
+
finish: async (text) => {
|
|
1176
|
+
const [first, ...rest] = BotText.split(text || "…", STREAM_BYTES);
|
|
1177
|
+
const streamed = await started && await respond(first, true).then(() => true, () => false);
|
|
1178
|
+
for (const piece of streamed ? rest : [first, ...rest]) {
|
|
1179
|
+
await this.sendText(chat, piece);
|
|
1180
|
+
}
|
|
1181
|
+
},
|
|
1182
|
+
cancel: async () => {
|
|
1183
|
+
if (await started) {
|
|
1184
|
+
await respond("…", true).catch(() => {
|
|
1185
|
+
return;
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
async sendText(chat, text) {
|
|
1192
|
+
for (const piece of BotText.split(text, MARKDOWN_BYTES)) {
|
|
1193
|
+
await this.socket.request("aibot_send_msg", { chatid: chat, msgtype: "markdown", markdown: { content: piece } });
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
async sendFile(chat, file) {
|
|
1197
|
+
let type = file.kind;
|
|
1198
|
+
if (type !== "file" && file.data.length > LIMITS[type]) {
|
|
1199
|
+
type = "file";
|
|
1200
|
+
}
|
|
1201
|
+
if (file.data.length > LIMITS.file) {
|
|
1202
|
+
throw new Error(`WeCom takes files up to 20 MB; ${file.name} is ${Math.ceil(file.data.length / 1024 / 1024)} MB.`);
|
|
1203
|
+
}
|
|
1204
|
+
const total = Math.max(1, Math.ceil(file.data.length / CHUNK_BYTES));
|
|
1205
|
+
if (total > MAX_CHUNKS) {
|
|
1206
|
+
throw new Error(`${file.name} is too large for WeCom.`);
|
|
1207
|
+
}
|
|
1208
|
+
const init = await this.socket.request("aibot_upload_media_init", {
|
|
1209
|
+
type,
|
|
1210
|
+
filename: file.name,
|
|
1211
|
+
total_size: file.data.length,
|
|
1212
|
+
total_chunks: total,
|
|
1213
|
+
md5: MediaCrypto.md5(file.data)
|
|
1214
|
+
});
|
|
1215
|
+
const uploadId = init.body?.upload_id;
|
|
1216
|
+
if (typeof uploadId !== "string" || !uploadId) {
|
|
1217
|
+
throw new Error("WeCom did not start the upload.");
|
|
1218
|
+
}
|
|
1219
|
+
for (let index = 0;index < total; index++) {
|
|
1220
|
+
const chunk = file.data.subarray(index * CHUNK_BYTES, (index + 1) * CHUNK_BYTES);
|
|
1221
|
+
await this.chunk(uploadId, index, Buffer.from(chunk).toString("base64"));
|
|
1222
|
+
}
|
|
1223
|
+
const finished = await this.socket.request("aibot_upload_media_finish", { upload_id: uploadId });
|
|
1224
|
+
const mediaId = finished.body?.media_id;
|
|
1225
|
+
if (typeof mediaId !== "string" || !mediaId) {
|
|
1226
|
+
throw new Error("WeCom did not finish the upload.");
|
|
1227
|
+
}
|
|
1228
|
+
await this.socket.request("aibot_send_msg", { chatid: chat, msgtype: type, [type]: { media_id: mediaId } });
|
|
1229
|
+
}
|
|
1230
|
+
async chunk(uploadId, index, data) {
|
|
1231
|
+
for (let attempt = 0;; attempt++) {
|
|
1232
|
+
try {
|
|
1233
|
+
await this.socket.request("aibot_upload_media_chunk", { upload_id: uploadId, chunk_index: index, base64_data: data });
|
|
1234
|
+
return;
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
if (attempt >= 2) {
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
async receive(frame) {
|
|
1244
|
+
if (frame.cmd !== "aibot_msg_callback" || !frame.body) {
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const body = frame.body;
|
|
1248
|
+
const from = body.from?.userid ?? "";
|
|
1249
|
+
const group = body.chattype === "group";
|
|
1250
|
+
const chat = group ? body.chatid ?? "" : from;
|
|
1251
|
+
if (!chat) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
const texts = [];
|
|
1255
|
+
const files = [];
|
|
1256
|
+
const quoted = body.quote?.text?.content ?? body.quote?.voice?.content;
|
|
1257
|
+
if (quoted) {
|
|
1258
|
+
texts.push(`> ${quoted.replace(/\n/g, `
|
|
1259
|
+
> `)}`);
|
|
1260
|
+
}
|
|
1261
|
+
const take = async (kind, media) => {
|
|
1262
|
+
if (!media?.url) {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
try {
|
|
1266
|
+
files.push(await this.download(kind, media));
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
texts.push(`[${kind}: ${errorText(error)}]`);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
switch (body.msgtype) {
|
|
1272
|
+
case "text":
|
|
1273
|
+
texts.push(body.text?.content ?? "");
|
|
1274
|
+
break;
|
|
1275
|
+
case "voice":
|
|
1276
|
+
texts.push(body.voice?.content ?? "");
|
|
1277
|
+
break;
|
|
1278
|
+
case "image":
|
|
1279
|
+
await take("image", body.image);
|
|
1280
|
+
break;
|
|
1281
|
+
case "file":
|
|
1282
|
+
await take("file", body.file);
|
|
1283
|
+
break;
|
|
1284
|
+
case "video":
|
|
1285
|
+
await take("video", body.video);
|
|
1286
|
+
break;
|
|
1287
|
+
case "mixed":
|
|
1288
|
+
for (const item of body.mixed?.msg_item ?? []) {
|
|
1289
|
+
if (item.msgtype === "text" && item.text?.content) {
|
|
1290
|
+
texts.push(item.text.content);
|
|
1291
|
+
} else if (item.msgtype === "image") {
|
|
1292
|
+
await take("image", item.image);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
break;
|
|
1296
|
+
default:
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const text = texts.filter(Boolean).join(`
|
|
1300
|
+
`).trim();
|
|
1301
|
+
if (!text && files.length === 0) {
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
this.messageHandler({ chat, from: { id: from }, group, text, files, handle: frame.headers?.req_id });
|
|
1305
|
+
}
|
|
1306
|
+
async download(kind, media) {
|
|
1307
|
+
const response = await this.fetcher(media.url, { signal: AbortSignal.timeout(DOWNLOAD_MS) });
|
|
1308
|
+
if (!response.ok) {
|
|
1309
|
+
throw new Error(`the file did not download (${response.status})`);
|
|
1310
|
+
}
|
|
1311
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1312
|
+
const data = media.aeskey ? MediaCrypto.decryptWecom(bytes, media.aeskey) : bytes;
|
|
1313
|
+
const named = WecomChannel.fileName(response.headers.get("content-disposition"));
|
|
1314
|
+
const name = BotText.fileName(named ?? "", `${kind}-${Date.now()}${BotText.extensionOf(data)}`);
|
|
1315
|
+
return { kind, name, mimeType: BotText.mimeOf(name), data };
|
|
1316
|
+
}
|
|
1317
|
+
static fileName(disposition) {
|
|
1318
|
+
if (!disposition) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
const encoded = /filename\*=UTF-8''([^;\s]+)/i.exec(disposition)?.[1];
|
|
1322
|
+
const plain = /filename="?([^";]+)"?/i.exec(disposition)?.[1];
|
|
1323
|
+
try {
|
|
1324
|
+
return decodeURIComponent(encoded ?? plain ?? "") || undefined;
|
|
1325
|
+
} catch {
|
|
1326
|
+
return plain;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// web-src/login-book.ts
|
|
1332
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
1333
|
+
var KEEP_MS = 2 * 60000;
|
|
1334
|
+
|
|
1335
|
+
class LoginBook {
|
|
1336
|
+
logins = new Map;
|
|
1337
|
+
owns(id) {
|
|
1338
|
+
return this.logins.has(id);
|
|
1339
|
+
}
|
|
1340
|
+
get(id) {
|
|
1341
|
+
const login = this.logins.get(id);
|
|
1342
|
+
if (!login) {
|
|
1343
|
+
return { id, status: "failed", error: "This sign-in is over; start again." };
|
|
1344
|
+
}
|
|
1345
|
+
return { ...login.state };
|
|
1346
|
+
}
|
|
1347
|
+
cancel(id) {
|
|
1348
|
+
const login = this.logins.get(id);
|
|
1349
|
+
if (login) {
|
|
1350
|
+
login.abort.abort();
|
|
1351
|
+
this.logins.delete(id);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
dispose() {
|
|
1355
|
+
for (const id of [...this.logins.keys()]) {
|
|
1356
|
+
this.cancel(id);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
add(state, extra) {
|
|
1360
|
+
const id = randomBytes4(8).toString("hex");
|
|
1361
|
+
const login = { ...extra, state: { ...state, id }, abort: new AbortController };
|
|
1362
|
+
this.logins.set(id, login);
|
|
1363
|
+
return login;
|
|
1364
|
+
}
|
|
1365
|
+
update(login, change) {
|
|
1366
|
+
login.state = { ...login.state, ...change };
|
|
1367
|
+
}
|
|
1368
|
+
end(login, change) {
|
|
1369
|
+
this.update(login, { ...change, qr: change.status === "done" ? undefined : login.state.qr });
|
|
1370
|
+
const timer = setTimeout(() => {
|
|
1371
|
+
if (this.logins.get(login.state.id) === login) {
|
|
1372
|
+
this.logins.delete(login.state.id);
|
|
1373
|
+
}
|
|
1374
|
+
}, KEEP_MS);
|
|
1375
|
+
timer.unref?.();
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// web-src/wecom-login.ts
|
|
1380
|
+
var LOGIN_MS = 5 * 60000;
|
|
1381
|
+
var POLL_MS = 2000;
|
|
1382
|
+
var REQUEST_MS = 15000;
|
|
1383
|
+
|
|
1384
|
+
class WecomLogins extends LoginBook {
|
|
1385
|
+
baseUrl;
|
|
1386
|
+
fetcher;
|
|
1387
|
+
pollMs;
|
|
1388
|
+
constructor(baseUrl, fetcher = fetch, pollMs = POLL_MS) {
|
|
1389
|
+
super();
|
|
1390
|
+
this.baseUrl = baseUrl;
|
|
1391
|
+
this.fetcher = fetcher;
|
|
1392
|
+
this.pollMs = pollMs;
|
|
1393
|
+
}
|
|
1394
|
+
async start(done) {
|
|
1395
|
+
const plat = { darwin: 1, win32: 2, linux: 3 }[process.platform] ?? 0;
|
|
1396
|
+
const { data } = await this.request(`ai/qc/generate?source=wecom-cli&plat=${plat}`);
|
|
1397
|
+
if (!data?.scode || !data.auth_url) {
|
|
1398
|
+
throw new Error("WeCom gave no code to scan.");
|
|
1399
|
+
}
|
|
1400
|
+
const login = this.add({ status: "waiting", qr: data.auth_url });
|
|
1401
|
+
this.wait(login, data.scode, done).catch((error) => this.end(login, { status: "failed", error: errorText(error) }));
|
|
1402
|
+
return { ...login.state };
|
|
1403
|
+
}
|
|
1404
|
+
async wait(login, scode, done) {
|
|
1405
|
+
const { signal } = login.abort;
|
|
1406
|
+
const deadline = Date.now() + LOGIN_MS;
|
|
1407
|
+
while (!signal.aborted) {
|
|
1408
|
+
await sleep(this.pollMs, signal);
|
|
1409
|
+
if (signal.aborted) {
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
if (Date.now() > deadline) {
|
|
1413
|
+
this.end(login, { status: "expired" });
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
const answer = await this.request(`ai/qc/query_result?scode=${encodeURIComponent(scode)}`, signal).catch(() => {
|
|
1417
|
+
return;
|
|
1418
|
+
});
|
|
1419
|
+
const status = answer?.data?.status ?? "";
|
|
1420
|
+
if (status === "success") {
|
|
1421
|
+
const bot = answer?.data?.bot_info;
|
|
1422
|
+
if (!bot?.botid || !bot.secret) {
|
|
1423
|
+
this.end(login, { status: "failed", error: "WeCom made the robot but gave no Bot ID or Secret." });
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
const botId = await done({ botId: bot.botid, secret: bot.secret });
|
|
1427
|
+
this.end(login, { status: "done", botId });
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
if (/expire|timeout/i.test(status)) {
|
|
1431
|
+
this.end(login, { status: "expired" });
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
if (/fail|cancel|refuse|reject|deny/i.test(status)) {
|
|
1435
|
+
this.end(login, { status: "failed", error: `WeCom: ${status}` });
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
if (/scan|confirm/i.test(status) && login.state.status !== "scanned") {
|
|
1439
|
+
this.update(login, { status: "scanned" });
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
async request(endpoint, signal) {
|
|
1444
|
+
const response = await this.fetcher(new URL(endpoint, this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`), {
|
|
1445
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(REQUEST_MS)]) : AbortSignal.timeout(REQUEST_MS)
|
|
1446
|
+
});
|
|
1447
|
+
if (!response.ok) {
|
|
1448
|
+
throw new Error(`WeCom answered ${response.status}.`);
|
|
1449
|
+
}
|
|
1450
|
+
return await response.json();
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// web-src/weixin-api.ts
|
|
1455
|
+
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
1456
|
+
var CHANNEL_VERSION = "2.4.10";
|
|
1457
|
+
var APP_ID = "bot";
|
|
1458
|
+
var CLIENT_VERSION = String(2 << 16 | 4 << 8 | 10);
|
|
1459
|
+
var BOT_AGENT = "Ta/1.0";
|
|
1460
|
+
var API_TIMEOUT_MS = 15000;
|
|
1461
|
+
var POLL_TIMEOUT_MS = 35000;
|
|
1462
|
+
var STALE_TOKEN = -14;
|
|
1463
|
+
var WeixinItemType;
|
|
1464
|
+
((WeixinItemType) => {
|
|
1465
|
+
WeixinItemType.TEXT = 1;
|
|
1466
|
+
WeixinItemType.IMAGE = 2;
|
|
1467
|
+
WeixinItemType.VOICE = 3;
|
|
1468
|
+
WeixinItemType.FILE = 4;
|
|
1469
|
+
WeixinItemType.VIDEO = 5;
|
|
1470
|
+
})(WeixinItemType ||= {});
|
|
1471
|
+
var WeixinUploadType;
|
|
1472
|
+
((WeixinUploadType) => {
|
|
1473
|
+
WeixinUploadType.IMAGE = 1;
|
|
1474
|
+
WeixinUploadType.VIDEO = 2;
|
|
1475
|
+
WeixinUploadType.FILE = 3;
|
|
1476
|
+
})(WeixinUploadType ||= {});
|
|
1477
|
+
|
|
1478
|
+
class WeixinApi {
|
|
1479
|
+
endpoints;
|
|
1480
|
+
fetcher;
|
|
1481
|
+
constructor(endpoints, fetcher = fetch) {
|
|
1482
|
+
this.endpoints = endpoints;
|
|
1483
|
+
this.fetcher = fetcher;
|
|
1484
|
+
}
|
|
1485
|
+
async qrcode(tokens) {
|
|
1486
|
+
return this.post(this.endpoints.weixinApi, "ilink/bot/get_bot_qrcode?bot_type=3", { local_token_list: tokens.slice(0, 10) }, undefined, API_TIMEOUT_MS, false);
|
|
1487
|
+
}
|
|
1488
|
+
async qrStatus(baseUrl, qrcode, code, signal) {
|
|
1489
|
+
const query = `qrcode=${encodeURIComponent(qrcode)}${code ? `&verify_code=${encodeURIComponent(code)}` : ""}`;
|
|
1490
|
+
try {
|
|
1491
|
+
return JSON.parse(await this.request(baseUrl, `ilink/bot/get_qrcode_status?${query}`, { method: "GET", headers: this.common() }, POLL_TIMEOUT_MS, signal));
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
if (signal?.aborted) {
|
|
1494
|
+
throw error;
|
|
1495
|
+
}
|
|
1496
|
+
return { status: "wait" };
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
async getUpdates(account, buf, timeoutMs = POLL_TIMEOUT_MS, signal) {
|
|
1500
|
+
try {
|
|
1501
|
+
return await this.post(account.baseUrl, "ilink/bot/getupdates", { get_updates_buf: buf }, account.token, timeoutMs, true, signal);
|
|
1502
|
+
} catch (error) {
|
|
1503
|
+
if (error.name === "AbortError" && !signal?.aborted) {
|
|
1504
|
+
return { ret: 0, msgs: [], get_updates_buf: buf };
|
|
1505
|
+
}
|
|
1506
|
+
throw error;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
async send(account, to, items, contextToken) {
|
|
1510
|
+
const answer = await this.post(account.baseUrl, "ilink/bot/sendmessage", {
|
|
1511
|
+
msg: {
|
|
1512
|
+
from_user_id: "",
|
|
1513
|
+
to_user_id: to,
|
|
1514
|
+
client_id: `ta-bots-${Date.now()}-${randomBytes5(4).toString("hex")}`,
|
|
1515
|
+
message_type: 2,
|
|
1516
|
+
message_state: 2,
|
|
1517
|
+
item_list: items,
|
|
1518
|
+
context_token: contextToken
|
|
1519
|
+
}
|
|
1520
|
+
}, account.token);
|
|
1521
|
+
if (answer.ret) {
|
|
1522
|
+
throw new Error(`WeChat did not take the message (${answer.ret}${answer.errmsg ? `: ${answer.errmsg}` : ""}).`);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
async uploadUrl(account, body) {
|
|
1526
|
+
return this.post(account.baseUrl, "ilink/bot/getuploadurl", body, account.token);
|
|
1527
|
+
}
|
|
1528
|
+
async typingTicket(account, user, contextToken) {
|
|
1529
|
+
const answer = await this.post(account.baseUrl, "ilink/bot/getconfig", { ilink_user_id: user, context_token: contextToken }, account.token, 1e4);
|
|
1530
|
+
return answer.typing_ticket || undefined;
|
|
1531
|
+
}
|
|
1532
|
+
async typing(account, user, ticket, on) {
|
|
1533
|
+
await this.post(account.baseUrl, "ilink/bot/sendtyping", { ilink_user_id: user, typing_ticket: ticket, status: on ? 1 : 2 }, account.token, 1e4);
|
|
1534
|
+
}
|
|
1535
|
+
async notify(account, what) {
|
|
1536
|
+
await this.post(account.baseUrl, `ilink/bot/msg/notify${what}`, {}, account.token, 1e4);
|
|
1537
|
+
}
|
|
1538
|
+
async upload(url, data) {
|
|
1539
|
+
let failure;
|
|
1540
|
+
for (let attempt = 0;attempt < 3; attempt++) {
|
|
1541
|
+
const response = await this.fetcher(url, { method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: data }).catch((error) => error);
|
|
1542
|
+
if (response instanceof Error) {
|
|
1543
|
+
failure = response;
|
|
1544
|
+
continue;
|
|
1545
|
+
}
|
|
1546
|
+
const param = response.headers.get("x-encrypted-param");
|
|
1547
|
+
if (response.status === 200 && param) {
|
|
1548
|
+
return param;
|
|
1549
|
+
}
|
|
1550
|
+
failure = new Error(`The CDN of WeChat refused the file (${response.status}${response.headers.get("x-error-message") ? `: ${response.headers.get("x-error-message")}` : ""}).`);
|
|
1551
|
+
if (response.status >= 400 && response.status < 500) {
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
throw failure;
|
|
1556
|
+
}
|
|
1557
|
+
async download(media) {
|
|
1558
|
+
const url = media.full_url || `${this.endpoints.weixinCdn}/download?encrypted_query_param=${encodeURIComponent(media.encrypt_query_param ?? "")}`;
|
|
1559
|
+
const response = await this.fetcher(url);
|
|
1560
|
+
if (!response.ok) {
|
|
1561
|
+
throw new Error(`The file did not download from WeChat (${response.status}).`);
|
|
1562
|
+
}
|
|
1563
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
1564
|
+
}
|
|
1565
|
+
uploadTarget(answer, filekey) {
|
|
1566
|
+
if (answer.upload_full_url?.trim()) {
|
|
1567
|
+
return answer.upload_full_url.trim();
|
|
1568
|
+
}
|
|
1569
|
+
if (!answer.upload_param) {
|
|
1570
|
+
throw new Error("WeChat gave no address to upload the file to.");
|
|
1571
|
+
}
|
|
1572
|
+
return `${this.endpoints.weixinCdn}/upload?encrypted_query_param=${encodeURIComponent(answer.upload_param)}&filekey=${encodeURIComponent(filekey)}`;
|
|
1573
|
+
}
|
|
1574
|
+
common() {
|
|
1575
|
+
return { "iLink-App-Id": APP_ID, "iLink-App-ClientVersion": CLIENT_VERSION };
|
|
1576
|
+
}
|
|
1577
|
+
async post(baseUrl, endpoint, body, token, timeoutMs = API_TIMEOUT_MS, withInfo = true, signal) {
|
|
1578
|
+
const headers = {
|
|
1579
|
+
...this.common(),
|
|
1580
|
+
"Content-Type": "application/json",
|
|
1581
|
+
AuthorizationType: "ilink_bot_token",
|
|
1582
|
+
"X-WECHAT-UIN": Buffer.from(String(randomBytes5(4).readUInt32BE(0))).toString("base64")
|
|
1583
|
+
};
|
|
1584
|
+
if (token) {
|
|
1585
|
+
headers.Authorization = `Bearer ${token}`;
|
|
1586
|
+
}
|
|
1587
|
+
const payload = withInfo ? { ...body, base_info: { channel_version: CHANNEL_VERSION, bot_agent: BOT_AGENT } } : body;
|
|
1588
|
+
return JSON.parse(await this.request(baseUrl, endpoint, { method: "POST", headers, body: JSON.stringify(payload) }, timeoutMs, signal));
|
|
1589
|
+
}
|
|
1590
|
+
async request(baseUrl, endpoint, init, timeoutMs, signal) {
|
|
1591
|
+
const url = new URL(endpoint, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`);
|
|
1592
|
+
const controller = new AbortController;
|
|
1593
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1594
|
+
const stop = () => controller.abort();
|
|
1595
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
1596
|
+
try {
|
|
1597
|
+
const response = await this.fetcher(url, { ...init, signal: controller.signal });
|
|
1598
|
+
const text = await response.text();
|
|
1599
|
+
if (!response.ok) {
|
|
1600
|
+
throw new Error(`WeChat answered ${response.status}: ${text.slice(0, 200)}`);
|
|
1601
|
+
}
|
|
1602
|
+
return text;
|
|
1603
|
+
} finally {
|
|
1604
|
+
clearTimeout(timer);
|
|
1605
|
+
signal?.removeEventListener("abort", stop);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// web-src/weixin-channel.ts
|
|
1611
|
+
var TEXT_BYTES = 4000;
|
|
1612
|
+
var RETRY_MS = 2000;
|
|
1613
|
+
var BACKOFF_MS = 30000;
|
|
1614
|
+
var TYPING_MS = 8000;
|
|
1615
|
+
var MEDIA_MAX_BYTES = 100 * 1024 * 1024;
|
|
1616
|
+
|
|
1617
|
+
class WeixinChannel {
|
|
1618
|
+
api;
|
|
1619
|
+
account;
|
|
1620
|
+
memory;
|
|
1621
|
+
kind = "weixin";
|
|
1622
|
+
messageHandler = () => {
|
|
1623
|
+
return;
|
|
1624
|
+
};
|
|
1625
|
+
stateHandler = () => {
|
|
1626
|
+
return;
|
|
1627
|
+
};
|
|
1628
|
+
abort;
|
|
1629
|
+
running;
|
|
1630
|
+
contextTokens;
|
|
1631
|
+
tickets = new Map;
|
|
1632
|
+
constructor(api, account, memory) {
|
|
1633
|
+
this.api = api;
|
|
1634
|
+
this.account = account;
|
|
1635
|
+
this.memory = memory;
|
|
1636
|
+
}
|
|
1637
|
+
onMessage(handler) {
|
|
1638
|
+
this.messageHandler = handler;
|
|
1639
|
+
}
|
|
1640
|
+
onState(handler) {
|
|
1641
|
+
this.stateHandler = handler;
|
|
1642
|
+
}
|
|
1643
|
+
start() {
|
|
1644
|
+
if (this.running) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
this.abort = new AbortController;
|
|
1648
|
+
const signal = this.abort.signal;
|
|
1649
|
+
this.running = this.poll(signal).finally(() => {
|
|
1650
|
+
this.running = undefined;
|
|
1651
|
+
});
|
|
1652
|
+
this.api.notify(this.account, "start").catch(() => {
|
|
1653
|
+
return;
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
async stop() {
|
|
1657
|
+
this.abort?.abort();
|
|
1658
|
+
await this.running;
|
|
1659
|
+
await this.api.notify(this.account, "stop").catch(() => {
|
|
1660
|
+
return;
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
begin(chat) {
|
|
1664
|
+
let done = false;
|
|
1665
|
+
let timer;
|
|
1666
|
+
const type = async (on) => {
|
|
1667
|
+
const ticket = await this.ticket(chat);
|
|
1668
|
+
if (ticket) {
|
|
1669
|
+
await this.api.typing(this.account, chat, ticket, on).catch(() => {
|
|
1670
|
+
return;
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
const again = () => {
|
|
1675
|
+
timer = setTimeout(() => {
|
|
1676
|
+
if (!done) {
|
|
1677
|
+
type(true).then(again);
|
|
1678
|
+
}
|
|
1679
|
+
}, TYPING_MS);
|
|
1680
|
+
timer.unref?.();
|
|
1681
|
+
};
|
|
1682
|
+
type(true).then(again);
|
|
1683
|
+
const end = async () => {
|
|
1684
|
+
done = true;
|
|
1685
|
+
clearTimeout(timer);
|
|
1686
|
+
await type(false);
|
|
1687
|
+
};
|
|
1688
|
+
return {
|
|
1689
|
+
finish: async (text) => {
|
|
1690
|
+
await end();
|
|
1691
|
+
await this.sendText(chat, text);
|
|
1692
|
+
},
|
|
1693
|
+
cancel: end
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
async sendText(chat, text) {
|
|
1697
|
+
const context = (await this.contexts())[chat];
|
|
1698
|
+
for (const piece of BotText.split(BotText.plain(text), TEXT_BYTES)) {
|
|
1699
|
+
await this.api.send(this.account, chat, [{ type: WeixinItemType.TEXT, text_item: { text: piece } }], context);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
async sendFile(chat, file) {
|
|
1703
|
+
const kind = file.kind === "image" ? "image" : file.kind === "video" ? "video" : "file";
|
|
1704
|
+
const key = MediaCrypto.random(16);
|
|
1705
|
+
const filekey = MediaCrypto.random(16).toString("hex");
|
|
1706
|
+
const encrypted = MediaCrypto.encryptEcb(file.data, key);
|
|
1707
|
+
const answer = await this.api.uploadUrl(this.account, {
|
|
1708
|
+
filekey,
|
|
1709
|
+
media_type: kind === "image" ? WeixinUploadType.IMAGE : kind === "video" ? WeixinUploadType.VIDEO : WeixinUploadType.FILE,
|
|
1710
|
+
to_user_id: chat,
|
|
1711
|
+
rawsize: file.data.length,
|
|
1712
|
+
rawfilemd5: MediaCrypto.md5(file.data),
|
|
1713
|
+
filesize: encrypted.length,
|
|
1714
|
+
no_need_thumb: true,
|
|
1715
|
+
aeskey: key.toString("hex")
|
|
1716
|
+
});
|
|
1717
|
+
const param = await this.api.upload(this.api.uploadTarget(answer, filekey), encrypted);
|
|
1718
|
+
const media = { encrypt_query_param: param, aes_key: Buffer.from(key.toString("hex")).toString("base64"), encrypt_type: 1 };
|
|
1719
|
+
const item = kind === "image" ? { type: WeixinItemType.IMAGE, image_item: { media, mid_size: encrypted.length } } : kind === "video" ? { type: WeixinItemType.VIDEO, video_item: { media, video_size: encrypted.length } } : { type: WeixinItemType.FILE, file_item: { media, file_name: file.name, len: String(file.data.length) } };
|
|
1720
|
+
await this.api.send(this.account, chat, [item], (await this.contexts())[chat]);
|
|
1721
|
+
}
|
|
1722
|
+
async poll(signal) {
|
|
1723
|
+
let cursor = await this.memory.cursor();
|
|
1724
|
+
let timeout;
|
|
1725
|
+
let failures = 0;
|
|
1726
|
+
this.stateHandler({ status: "connecting" });
|
|
1727
|
+
while (!signal.aborted) {
|
|
1728
|
+
try {
|
|
1729
|
+
const updates = await this.api.getUpdates(this.account, cursor, timeout, signal);
|
|
1730
|
+
if (signal.aborted) {
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
if (updates.errcode === STALE_TOKEN || updates.ret === STALE_TOKEN) {
|
|
1734
|
+
this.stateHandler({ status: "expired", error: "WeChat signed this bot out; scan its code again." });
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if ((updates.ret ?? 0) !== 0 || (updates.errcode ?? 0) !== 0) {
|
|
1738
|
+
throw new Error(`WeChat answered ${updates.errcode ?? updates.ret}${updates.errmsg ? `: ${updates.errmsg}` : ""}`);
|
|
1739
|
+
}
|
|
1740
|
+
failures = 0;
|
|
1741
|
+
this.stateHandler({ status: "online" });
|
|
1742
|
+
if (updates.longpolling_timeout_ms && updates.longpolling_timeout_ms > 0) {
|
|
1743
|
+
timeout = updates.longpolling_timeout_ms;
|
|
1744
|
+
}
|
|
1745
|
+
if (updates.get_updates_buf) {
|
|
1746
|
+
cursor = updates.get_updates_buf;
|
|
1747
|
+
await this.memory.setCursor(cursor);
|
|
1748
|
+
}
|
|
1749
|
+
for (const message of updates.msgs ?? []) {
|
|
1750
|
+
await this.receive(message).catch((error) => console.error(`ta-bots: a message of WeChat failed: ${errorText(error)}`));
|
|
1751
|
+
}
|
|
1752
|
+
} catch (error) {
|
|
1753
|
+
if (signal.aborted) {
|
|
1754
|
+
break;
|
|
1755
|
+
}
|
|
1756
|
+
failures++;
|
|
1757
|
+
this.stateHandler({ status: failures >= 3 ? "error" : "connecting", error: errorText(error) });
|
|
1758
|
+
await sleep(failures >= 3 ? BACKOFF_MS : RETRY_MS, signal);
|
|
1759
|
+
if (failures >= 3) {
|
|
1760
|
+
failures = 0;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
this.stateHandler({ status: "offline" });
|
|
1765
|
+
}
|
|
1766
|
+
async receive(message) {
|
|
1767
|
+
if (message.message_type === 2 || !message.from_user_id) {
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
const chat = message.from_user_id;
|
|
1771
|
+
if (message.context_token) {
|
|
1772
|
+
(await this.contexts())[chat] = message.context_token;
|
|
1773
|
+
await this.memory.setContext(chat, message.context_token);
|
|
1774
|
+
}
|
|
1775
|
+
const texts = [];
|
|
1776
|
+
const files = [];
|
|
1777
|
+
for (const item of message.item_list ?? []) {
|
|
1778
|
+
const quoted = item.ref_msg && WeixinChannel.quote(item.ref_msg);
|
|
1779
|
+
if (quoted) {
|
|
1780
|
+
texts.push(quoted);
|
|
1781
|
+
}
|
|
1782
|
+
if (item.type === WeixinItemType.TEXT && item.text_item?.text) {
|
|
1783
|
+
texts.push(item.text_item.text);
|
|
1784
|
+
} else if (item.type === WeixinItemType.VOICE && item.voice_item?.text) {
|
|
1785
|
+
texts.push(item.voice_item.text);
|
|
1786
|
+
}
|
|
1787
|
+
const file = await this.media(item).catch((error) => {
|
|
1788
|
+
texts.push(`[${WeixinChannel.label(item.type)}: ${errorText(error)}]`);
|
|
1789
|
+
return;
|
|
1790
|
+
});
|
|
1791
|
+
if (file) {
|
|
1792
|
+
files.push(file);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
if (texts.length === 0 && files.length === 0) {
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
this.messageHandler({ chat, from: { id: chat }, text: texts.join(`
|
|
1799
|
+
`), files });
|
|
1800
|
+
}
|
|
1801
|
+
async media(item) {
|
|
1802
|
+
const of = (kind, media, aesKey) => media?.media && (media.media.encrypt_query_param || media.media.full_url) ? { kind, media: media.media, aesKey: aesKey ?? media.media.aes_key } : undefined;
|
|
1803
|
+
const found = item.type === WeixinItemType.IMAGE ? of("image", item.image_item, item.image_item?.aeskey ? Buffer.from(item.image_item.aeskey, "hex").toString("base64") : undefined) : item.type === WeixinItemType.VOICE ? of("voice", item.voice_item) : item.type === WeixinItemType.FILE ? of("file", item.file_item) : item.type === WeixinItemType.VIDEO ? of("video", item.video_item) : undefined;
|
|
1804
|
+
if (!found) {
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
const bytes = await this.api.download(found.media);
|
|
1808
|
+
if (bytes.length > MEDIA_MAX_BYTES) {
|
|
1809
|
+
throw new Error("larger than 100 MB");
|
|
1810
|
+
}
|
|
1811
|
+
const data = found.aesKey ? MediaCrypto.decryptEcb(bytes, MediaCrypto.weixinKey(found.aesKey)) : bytes;
|
|
1812
|
+
const ext = found.kind === "voice" ? ".silk" : BotText.extensionOf(data);
|
|
1813
|
+
const name = BotText.fileName(item.file_item?.file_name ?? "", `${found.kind}-${Date.now()}${ext}`);
|
|
1814
|
+
return { kind: found.kind, name, mimeType: found.kind === "voice" ? "audio/silk" : BotText.mimeOf(name), data };
|
|
1815
|
+
}
|
|
1816
|
+
async contexts() {
|
|
1817
|
+
this.contextTokens ??= await this.memory.contexts();
|
|
1818
|
+
return this.contextTokens;
|
|
1819
|
+
}
|
|
1820
|
+
async ticket(chat) {
|
|
1821
|
+
const known = this.tickets.get(chat);
|
|
1822
|
+
if (known && Date.now() - known.at < 10 * 60000) {
|
|
1823
|
+
return known.ticket;
|
|
1824
|
+
}
|
|
1825
|
+
const ticket = await this.api.typingTicket(this.account, chat, (await this.contexts())[chat]).catch(() => {
|
|
1826
|
+
return;
|
|
1827
|
+
});
|
|
1828
|
+
this.tickets.set(chat, { ticket, at: Date.now() });
|
|
1829
|
+
return ticket;
|
|
1830
|
+
}
|
|
1831
|
+
static label(type) {
|
|
1832
|
+
return { [WeixinItemType.IMAGE]: "image", [WeixinItemType.VOICE]: "voice", [WeixinItemType.FILE]: "file", [WeixinItemType.VIDEO]: "video" }[type ?? 0] ?? "message";
|
|
1833
|
+
}
|
|
1834
|
+
static quote(ref) {
|
|
1835
|
+
const item = ref.message_item;
|
|
1836
|
+
const text = item?.text_item?.text ?? item?.voice_item?.text ?? (item?.type ? `[${WeixinChannel.label(item.type)}]` : "");
|
|
1837
|
+
const quoted = [ref.title, text].filter(Boolean).join(": ");
|
|
1838
|
+
return quoted ? `> ${quoted.replace(/\n/g, `
|
|
1839
|
+
> `)}` : undefined;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// web-src/weixin-login.ts
|
|
1844
|
+
var LOGIN_MS2 = 8 * 60000;
|
|
1845
|
+
var MAX_CODES = 3;
|
|
1846
|
+
|
|
1847
|
+
class WeixinLogins extends LoginBook {
|
|
1848
|
+
api;
|
|
1849
|
+
baseUrl;
|
|
1850
|
+
constructor(api, baseUrl) {
|
|
1851
|
+
super();
|
|
1852
|
+
this.api = api;
|
|
1853
|
+
this.baseUrl = baseUrl;
|
|
1854
|
+
}
|
|
1855
|
+
async start(tokens, done) {
|
|
1856
|
+
const { qrcode, qrcode_img_content } = await this.api.qrcode(tokens);
|
|
1857
|
+
const login = this.add({ status: "waiting", qr: qrcode_img_content });
|
|
1858
|
+
this.wait(login, qrcode, tokens, done).catch((error) => this.end(login, { status: "failed", error: errorText(error) }));
|
|
1859
|
+
return { ...login.state };
|
|
1860
|
+
}
|
|
1861
|
+
verify(id, code) {
|
|
1862
|
+
const login = this.logins.get(id);
|
|
1863
|
+
if (login && (login.state.status === "code" || login.state.status === "wrongCode") && code.trim()) {
|
|
1864
|
+
login.code = code.trim();
|
|
1865
|
+
login.state = { ...login.state, status: "scanned" };
|
|
1866
|
+
login.codeWaiting?.(login.code);
|
|
1867
|
+
}
|
|
1868
|
+
return this.get(id);
|
|
1869
|
+
}
|
|
1870
|
+
async wait(login, first, tokens, done) {
|
|
1871
|
+
const { signal } = login.abort;
|
|
1872
|
+
const deadline = Date.now() + LOGIN_MS2;
|
|
1873
|
+
let qrcode = first;
|
|
1874
|
+
let codes = 1;
|
|
1875
|
+
let baseUrl = this.baseUrl;
|
|
1876
|
+
while (!signal.aborted) {
|
|
1877
|
+
if (Date.now() > deadline) {
|
|
1878
|
+
this.end(login, { status: "expired" });
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
const sent = login.code;
|
|
1882
|
+
const status = await this.api.qrStatus(baseUrl, qrcode, sent, signal);
|
|
1883
|
+
if (signal.aborted) {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
switch (status.status) {
|
|
1887
|
+
case "wait":
|
|
1888
|
+
break;
|
|
1889
|
+
case "scaned":
|
|
1890
|
+
login.code = undefined;
|
|
1891
|
+
this.update(login, { status: "scanned" });
|
|
1892
|
+
break;
|
|
1893
|
+
case "scaned_but_redirect":
|
|
1894
|
+
if (status.redirect_host) {
|
|
1895
|
+
baseUrl = `https://${status.redirect_host}`;
|
|
1896
|
+
}
|
|
1897
|
+
break;
|
|
1898
|
+
case "need_verifycode": {
|
|
1899
|
+
this.update(login, { status: sent ? "wrongCode" : "code" });
|
|
1900
|
+
login.code = undefined;
|
|
1901
|
+
await new Promise((resolve) => {
|
|
1902
|
+
login.codeWaiting = () => resolve();
|
|
1903
|
+
signal.addEventListener("abort", () => resolve(), { once: true });
|
|
1904
|
+
});
|
|
1905
|
+
login.codeWaiting = undefined;
|
|
1906
|
+
continue;
|
|
1907
|
+
}
|
|
1908
|
+
case "expired":
|
|
1909
|
+
case "verify_code_blocked": {
|
|
1910
|
+
if (++codes > MAX_CODES) {
|
|
1911
|
+
this.end(login, { status: "expired" });
|
|
1912
|
+
return;
|
|
1913
|
+
}
|
|
1914
|
+
const next = await this.api.qrcode(tokens);
|
|
1915
|
+
qrcode = next.qrcode;
|
|
1916
|
+
login.code = undefined;
|
|
1917
|
+
this.update(login, { status: "waiting", qr: next.qrcode_img_content });
|
|
1918
|
+
break;
|
|
1919
|
+
}
|
|
1920
|
+
case "binded_redirect":
|
|
1921
|
+
this.end(login, { status: "already" });
|
|
1922
|
+
return;
|
|
1923
|
+
case "confirmed": {
|
|
1924
|
+
if (!status.ilink_bot_id || !status.bot_token) {
|
|
1925
|
+
this.end(login, { status: "failed", error: "WeChat confirmed the sign-in without a bot." });
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
const botId = await done({
|
|
1929
|
+
botId: status.ilink_bot_id,
|
|
1930
|
+
token: status.bot_token,
|
|
1931
|
+
baseUrl: status.baseurl || this.baseUrl,
|
|
1932
|
+
userId: status.ilink_user_id
|
|
1933
|
+
});
|
|
1934
|
+
this.end(login, { status: "done", botId });
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
await sleep(1000, signal);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
// web-src/bot-service.ts
|
|
1944
|
+
var PENDING_MS = 30 * 60000;
|
|
1945
|
+
|
|
1946
|
+
class BotService {
|
|
1947
|
+
host;
|
|
1948
|
+
bots = [];
|
|
1949
|
+
status = {};
|
|
1950
|
+
channels = new Map;
|
|
1951
|
+
pending = new Map;
|
|
1952
|
+
lastChat = new Map;
|
|
1953
|
+
store;
|
|
1954
|
+
bridge;
|
|
1955
|
+
logins;
|
|
1956
|
+
wecomLogins;
|
|
1957
|
+
api;
|
|
1958
|
+
options;
|
|
1959
|
+
statusTimer;
|
|
1960
|
+
disposed = false;
|
|
1961
|
+
constructor(host, options = {}) {
|
|
1962
|
+
this.host = host;
|
|
1963
|
+
this.options = { endpoints: BotEndpointsUtil.of(), verifyMs: 15000, ...options };
|
|
1964
|
+
this.store = new BotStore(host);
|
|
1965
|
+
this.bridge = new SessionBridge(host);
|
|
1966
|
+
this.api = new WeixinApi(this.options.endpoints);
|
|
1967
|
+
this.logins = new WeixinLogins(this.api, this.options.endpoints.weixinApi);
|
|
1968
|
+
this.wecomLogins = new WecomLogins(this.options.endpoints.wecomQr, options.fetcher);
|
|
1969
|
+
}
|
|
1970
|
+
async start() {
|
|
1971
|
+
this.bots = await this.store.bots();
|
|
1972
|
+
this.status = {};
|
|
1973
|
+
for (const bot of this.bots) {
|
|
1974
|
+
await this.connect(bot);
|
|
1975
|
+
}
|
|
1976
|
+
await this.store.saveStatus(this.status);
|
|
1977
|
+
}
|
|
1978
|
+
async dispose() {
|
|
1979
|
+
this.disposed = true;
|
|
1980
|
+
this.logins.dispose();
|
|
1981
|
+
this.wecomLogins.dispose();
|
|
1982
|
+
this.bridge.dispose();
|
|
1983
|
+
clearTimeout(this.statusTimer);
|
|
1984
|
+
for (const pending of this.pending.values()) {
|
|
1985
|
+
clearTimeout(pending.timer);
|
|
1986
|
+
}
|
|
1987
|
+
await Promise.all([...this.channels.values()].map((channel) => channel.stop().catch(() => {
|
|
1988
|
+
return;
|
|
1989
|
+
})));
|
|
1990
|
+
this.channels.clear();
|
|
1991
|
+
}
|
|
1992
|
+
async list() {
|
|
1993
|
+
return this.bots.map((bot) => this.info(bot));
|
|
1994
|
+
}
|
|
1995
|
+
async startWeixinLogin(target) {
|
|
1996
|
+
const where = BotTargetUtil.parse(target);
|
|
1997
|
+
return this.logins.start(await this.store.tokens(), (signIn) => this.signedIn(signIn, where));
|
|
1998
|
+
}
|
|
1999
|
+
async startWecomLogin(target) {
|
|
2000
|
+
const where = BotTargetUtil.parse(target);
|
|
2001
|
+
return this.wecomLogins.start(async ({ botId, secret }) => (await this.keepWecom(botId, secret, undefined, where, false)).id);
|
|
2002
|
+
}
|
|
2003
|
+
async login(id) {
|
|
2004
|
+
return this.book(String(id)).get(String(id));
|
|
2005
|
+
}
|
|
2006
|
+
async verifyLogin(id, code) {
|
|
2007
|
+
return this.logins.verify(String(id), String(code ?? ""));
|
|
2008
|
+
}
|
|
2009
|
+
async cancelLogin(id) {
|
|
2010
|
+
this.book(String(id)).cancel(String(id));
|
|
2011
|
+
}
|
|
2012
|
+
async addWecom(input) {
|
|
2013
|
+
const botId = typeof input?.botId === "string" ? input.botId.trim() : "";
|
|
2014
|
+
const secret = typeof input?.secret === "string" ? input.secret.trim() : "";
|
|
2015
|
+
if (!botId || !secret) {
|
|
2016
|
+
throw new Error("Give the Bot ID and the Secret of the robot, from its page in the admin console of WeCom.");
|
|
2017
|
+
}
|
|
2018
|
+
return this.keepWecom(botId, secret, input.name, BotTargetUtil.parse(input.target), true);
|
|
2019
|
+
}
|
|
2020
|
+
async keepWecom(botId, secret, name, target, check) {
|
|
2021
|
+
const id = `wecom:${botId}`;
|
|
2022
|
+
const before = this.bots.find((bot2) => bot2.id === id);
|
|
2023
|
+
const bot = {
|
|
2024
|
+
id,
|
|
2025
|
+
kind: "wecom",
|
|
2026
|
+
name: typeof name === "string" && name.trim() || before?.name || BotServerTexts.defaultName("wecom", this.names()),
|
|
2027
|
+
account: botId.length > 10 ? `${botId.slice(0, 6)}…${botId.slice(-4)}` : botId,
|
|
2028
|
+
target: target ?? before?.target,
|
|
2029
|
+
createdAt: before?.createdAt ?? Date.now()
|
|
2030
|
+
};
|
|
2031
|
+
if (check) {
|
|
2032
|
+
await this.verify(bot, { kind: "wecom", botId, secret });
|
|
2033
|
+
} else {
|
|
2034
|
+
await this.disconnect(id);
|
|
2035
|
+
}
|
|
2036
|
+
await this.store.setSecret(id, { kind: "wecom", botId, secret });
|
|
2037
|
+
await this.put(bot);
|
|
2038
|
+
await this.connect(bot);
|
|
2039
|
+
return this.info(bot);
|
|
2040
|
+
}
|
|
2041
|
+
async bind(botId, target) {
|
|
2042
|
+
const bot = this.find(botId);
|
|
2043
|
+
const next = target === null ? undefined : BotTargetUtil.parse(target);
|
|
2044
|
+
if (target !== null && !next) {
|
|
2045
|
+
throw new Error("Connect a bot to the double or to a conversation that has a session file.");
|
|
2046
|
+
}
|
|
2047
|
+
const before = bot.target;
|
|
2048
|
+
await this.put({ ...bot, target: next });
|
|
2049
|
+
return { bot: this.info(this.find(botId)), before };
|
|
2050
|
+
}
|
|
2051
|
+
async rename(botId, name) {
|
|
2052
|
+
const bot = this.find(botId);
|
|
2053
|
+
const trimmed = String(name ?? "").trim().slice(0, 40);
|
|
2054
|
+
if (!trimmed) {
|
|
2055
|
+
throw new Error("A bot needs a name.");
|
|
2056
|
+
}
|
|
2057
|
+
await this.put({ ...bot, name: trimmed });
|
|
2058
|
+
return this.info(this.find(botId));
|
|
2059
|
+
}
|
|
2060
|
+
async remove(botId) {
|
|
2061
|
+
const bot = this.find(botId);
|
|
2062
|
+
await this.disconnect(bot.id);
|
|
2063
|
+
await this.store.setSecret(bot.id, undefined);
|
|
2064
|
+
await this.store.memory(bot.id).forget();
|
|
2065
|
+
this.bots = this.bots.filter((other) => other.id !== bot.id);
|
|
2066
|
+
delete this.status[bot.id];
|
|
2067
|
+
await this.store.saveBots(this.bots);
|
|
2068
|
+
this.saveStatusLater();
|
|
2069
|
+
}
|
|
2070
|
+
attach(piSessionId, handler) {
|
|
2071
|
+
return this.bridge.attach(piSessionId, handler);
|
|
2072
|
+
}
|
|
2073
|
+
async boundTo(sessionFile) {
|
|
2074
|
+
if (!sessionFile) {
|
|
2075
|
+
return [];
|
|
2076
|
+
}
|
|
2077
|
+
const double = await this.bridge.sessionFile({ kind: "double" });
|
|
2078
|
+
return this.bots.filter((bot) => bot.target && (bot.target.kind === "double" ? double === sessionFile : bot.target.sessionFile === sessionFile));
|
|
2079
|
+
}
|
|
2080
|
+
async replied(origins, text) {
|
|
2081
|
+
const sent = [];
|
|
2082
|
+
for (const origin of BotService.unique(origins)) {
|
|
2083
|
+
const bot = this.bots.find((other) => other.id === origin.botId);
|
|
2084
|
+
const channel = this.channels.get(origin.botId);
|
|
2085
|
+
if (!bot || !channel) {
|
|
2086
|
+
continue;
|
|
2087
|
+
}
|
|
2088
|
+
const pending = origin.reply ? this.pending.get(origin.reply) : undefined;
|
|
2089
|
+
try {
|
|
2090
|
+
if (pending) {
|
|
2091
|
+
this.done(origin.reply);
|
|
2092
|
+
await (text ? pending.reply.finish(text) : pending.reply.cancel());
|
|
2093
|
+
} else if (text) {
|
|
2094
|
+
await channel.sendText(origin.chat, text);
|
|
2095
|
+
}
|
|
2096
|
+
sent.push({ botId: bot.id, kind: bot.kind, botName: bot.name, text });
|
|
2097
|
+
} catch (error) {
|
|
2098
|
+
sent.push({ botId: bot.id, kind: bot.kind, botName: bot.name, error: errorText(error) });
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
return sent;
|
|
2102
|
+
}
|
|
2103
|
+
async sendFile(origins, file) {
|
|
2104
|
+
const sent = [];
|
|
2105
|
+
for (const origin of BotService.unique(origins)) {
|
|
2106
|
+
const bot = this.bots.find((other) => other.id === origin.botId);
|
|
2107
|
+
const channel = this.channels.get(origin.botId);
|
|
2108
|
+
if (!bot || !channel) {
|
|
2109
|
+
continue;
|
|
2110
|
+
}
|
|
2111
|
+
try {
|
|
2112
|
+
await channel.sendFile(origin.chat, file);
|
|
2113
|
+
sent.push({ botId: bot.id, kind: bot.kind, botName: bot.name, files: [file.name] });
|
|
2114
|
+
} catch (error) {
|
|
2115
|
+
sent.push({ botId: bot.id, kind: bot.kind, botName: bot.name, files: [file.name], error: errorText(error) });
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
return sent;
|
|
2119
|
+
}
|
|
2120
|
+
lastChats(bots) {
|
|
2121
|
+
return bots.flatMap((bot) => {
|
|
2122
|
+
const chat = this.lastChat.get(bot.id);
|
|
2123
|
+
return chat ? [{ botId: bot.id, chat }] : [];
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
async signedIn(signIn, target) {
|
|
2127
|
+
const id = `weixin:${signIn.botId}`;
|
|
2128
|
+
const secrets = await Promise.all(this.bots.map(async (bot2) => [bot2, await this.store.secret(bot2.id)]));
|
|
2129
|
+
const before = this.bots.find((bot2) => bot2.id === id) ?? secrets.find(([bot2, secret]) => bot2.kind === "weixin" && signIn.userId && secret?.kind === "weixin" && secret.userId === signIn.userId)?.[0];
|
|
2130
|
+
if (before && before.id !== id) {
|
|
2131
|
+
await this.remove(before.id);
|
|
2132
|
+
}
|
|
2133
|
+
const bot = {
|
|
2134
|
+
id,
|
|
2135
|
+
kind: "weixin",
|
|
2136
|
+
name: before?.name ?? BotServerTexts.defaultName("weixin", this.names()),
|
|
2137
|
+
account: BotService.short(signIn.userId ?? signIn.botId),
|
|
2138
|
+
target: target ?? before?.target,
|
|
2139
|
+
createdAt: before?.createdAt ?? Date.now()
|
|
2140
|
+
};
|
|
2141
|
+
await this.disconnect(id);
|
|
2142
|
+
await this.store.setSecret(id, { kind: "weixin", token: signIn.token, baseUrl: signIn.baseUrl, userId: signIn.userId });
|
|
2143
|
+
await this.put(bot);
|
|
2144
|
+
await this.connect(bot);
|
|
2145
|
+
return id;
|
|
2146
|
+
}
|
|
2147
|
+
async verify(bot, secret) {
|
|
2148
|
+
const channel = this.channel(bot, secret);
|
|
2149
|
+
try {
|
|
2150
|
+
await new Promise((resolve, reject) => {
|
|
2151
|
+
const timer = setTimeout(() => reject(new Error("WeCom did not answer; check the network of this computer.")), this.options.verifyMs);
|
|
2152
|
+
channel.onState((state) => {
|
|
2153
|
+
if (state.status === "online") {
|
|
2154
|
+
clearTimeout(timer);
|
|
2155
|
+
resolve();
|
|
2156
|
+
} else if (state.error && state.status !== "offline") {
|
|
2157
|
+
clearTimeout(timer);
|
|
2158
|
+
reject(new Error(state.error));
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
this.disconnect(bot.id).then(() => channel.start());
|
|
2162
|
+
});
|
|
2163
|
+
} finally {
|
|
2164
|
+
await channel.stop();
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
channel(bot, secret) {
|
|
2168
|
+
if (this.options.channel) {
|
|
2169
|
+
return this.options.channel(bot, secret);
|
|
2170
|
+
}
|
|
2171
|
+
if (secret.kind === "weixin") {
|
|
2172
|
+
return new WeixinChannel(this.api, { token: secret.token, baseUrl: secret.baseUrl }, this.store.memory(bot.id));
|
|
2173
|
+
}
|
|
2174
|
+
return new WecomChannel(this.options.endpoints.wecomSocket, { botId: secret.botId, secret: secret.secret });
|
|
2175
|
+
}
|
|
2176
|
+
async connect(bot) {
|
|
2177
|
+
if (this.disposed || this.channels.has(bot.id)) {
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
const secret = await this.store.secret(bot.id);
|
|
2181
|
+
if (!secret) {
|
|
2182
|
+
this.setStatus(bot.id, { status: "expired", error: "Its credentials are gone; connect it again." });
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const channel = this.channel(bot, secret);
|
|
2186
|
+
this.channels.set(bot.id, channel);
|
|
2187
|
+
channel.onState((state) => {
|
|
2188
|
+
if (this.channels.get(bot.id) === channel) {
|
|
2189
|
+
this.setStatus(bot.id, { ...state, lastMessageAt: this.status[bot.id]?.lastMessageAt });
|
|
2190
|
+
}
|
|
2191
|
+
});
|
|
2192
|
+
channel.onMessage((message) => void this.receive(bot.id, channel, message));
|
|
2193
|
+
channel.start();
|
|
2194
|
+
}
|
|
2195
|
+
async disconnect(id) {
|
|
2196
|
+
const channel = this.channels.get(id);
|
|
2197
|
+
this.channels.delete(id);
|
|
2198
|
+
await channel?.stop().catch(() => {
|
|
2199
|
+
return;
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
async receive(botId, channel, message) {
|
|
2203
|
+
const bot = this.bots.find((other) => other.id === botId);
|
|
2204
|
+
if (!bot) {
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
this.lastChat.set(bot.id, message.chat);
|
|
2208
|
+
this.setStatus(bot.id, { ...this.status[bot.id] ?? { status: "online" }, lastMessageAt: Date.now() });
|
|
2209
|
+
if (!bot.target) {
|
|
2210
|
+
await channel.sendText(message.chat, BotServerTexts.unbound()).catch(() => {
|
|
2211
|
+
return;
|
|
2212
|
+
});
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
const reply = channel.begin(message.chat, message.handle);
|
|
2216
|
+
const id = randomBytes6(8).toString("hex");
|
|
2217
|
+
const timer = setTimeout(() => {
|
|
2218
|
+
this.done(id);
|
|
2219
|
+
reply.cancel().catch(() => {
|
|
2220
|
+
return;
|
|
2221
|
+
});
|
|
2222
|
+
}, PENDING_MS);
|
|
2223
|
+
timer.unref?.();
|
|
2224
|
+
this.pending.set(id, { botId: bot.id, chat: message.chat, reply, timer });
|
|
2225
|
+
try {
|
|
2226
|
+
await this.bridge.deliver(bot.target, {
|
|
2227
|
+
details: {
|
|
2228
|
+
origin: { botId: bot.id, chat: message.chat, reply: id },
|
|
2229
|
+
kind: bot.kind,
|
|
2230
|
+
botName: bot.name,
|
|
2231
|
+
from: message.from,
|
|
2232
|
+
...message.group ? { group: true } : {},
|
|
2233
|
+
text: message.text,
|
|
2234
|
+
attachments: [],
|
|
2235
|
+
at: Date.now()
|
|
2236
|
+
},
|
|
2237
|
+
files: message.files
|
|
2238
|
+
});
|
|
2239
|
+
} catch (error) {
|
|
2240
|
+
this.done(id);
|
|
2241
|
+
const text = error instanceof NoDoubleError ? BotServerTexts.noDouble() : BotServerTexts.failed(errorText(error));
|
|
2242
|
+
await reply.finish(text).catch(() => {
|
|
2243
|
+
return;
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
done(id) {
|
|
2248
|
+
const pending = this.pending.get(id);
|
|
2249
|
+
if (pending) {
|
|
2250
|
+
clearTimeout(pending.timer);
|
|
2251
|
+
this.pending.delete(id);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
book(id) {
|
|
2255
|
+
return this.wecomLogins.owns(id) ? this.wecomLogins : this.logins;
|
|
2256
|
+
}
|
|
2257
|
+
names() {
|
|
2258
|
+
return this.bots.map((bot) => bot.name);
|
|
2259
|
+
}
|
|
2260
|
+
find(id) {
|
|
2261
|
+
const bot = this.bots.find((other) => other.id === id);
|
|
2262
|
+
if (!bot) {
|
|
2263
|
+
throw new Error(`No bot is ${id}.`);
|
|
2264
|
+
}
|
|
2265
|
+
return bot;
|
|
2266
|
+
}
|
|
2267
|
+
async put(bot) {
|
|
2268
|
+
const index = this.bots.findIndex((other) => other.id === bot.id);
|
|
2269
|
+
this.bots = index < 0 ? [...this.bots, bot] : this.bots.map((other) => other.id === bot.id ? bot : other);
|
|
2270
|
+
await this.store.saveBots(this.bots);
|
|
2271
|
+
}
|
|
2272
|
+
info(bot) {
|
|
2273
|
+
return { ...bot, ...this.status[bot.id] ?? { status: "offline" } };
|
|
2274
|
+
}
|
|
2275
|
+
setStatus(id, state) {
|
|
2276
|
+
const before = this.status[id];
|
|
2277
|
+
if (before && before.status === state.status && before.error === state.error && before.lastMessageAt === state.lastMessageAt) {
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
this.status = { ...this.status, [id]: state };
|
|
2281
|
+
this.saveStatusLater();
|
|
2282
|
+
}
|
|
2283
|
+
saveStatusLater() {
|
|
2284
|
+
clearTimeout(this.statusTimer);
|
|
2285
|
+
this.statusTimer = setTimeout(() => void this.store.saveStatus(this.status).catch(() => {
|
|
2286
|
+
return;
|
|
2287
|
+
}), 200);
|
|
2288
|
+
this.statusTimer.unref?.();
|
|
2289
|
+
}
|
|
2290
|
+
static unique(origins) {
|
|
2291
|
+
const seen = new Set;
|
|
2292
|
+
return origins.filter((origin) => {
|
|
2293
|
+
const key = `${origin.botId}
|
|
2294
|
+
${origin.chat}
|
|
2295
|
+
${origin.reply ?? ""}`;
|
|
2296
|
+
return !seen.has(key) && seen.add(key) !== undefined;
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
static short(account) {
|
|
2300
|
+
const name = account.split("@")[0];
|
|
2301
|
+
return name.length > 10 ? `${name.slice(0, 4)}…${name.slice(-4)}` : name;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
// web-src/host.ts
|
|
2306
|
+
async function activate(host) {
|
|
2307
|
+
const service = new BotService(host);
|
|
2308
|
+
await service.start();
|
|
2309
|
+
return service;
|
|
2310
|
+
}
|
|
2311
|
+
export {
|
|
2312
|
+
activate as default
|
|
2313
|
+
};
|