@celljs/ta 4.9.1 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -1
- package/README.md +3 -1
- package/dist/cli.mjs +1753 -75
- package/dist/gateway.mjs +311 -25
- package/dist/pi/CHANGELOG.md +30 -0
- package/dist/pi/dist/bundle/chunks/anthropic-messages-CA3HHOL3.js +6 -0
- package/dist/pi/dist/bundle/chunks/{azure-openai-responses-FSC6BAW3.js → azure-openai-responses-76TWS6DT.js} +1 -1
- package/dist/pi/dist/bundle/chunks/bedrock-converse-stream.js +3 -3
- package/dist/pi/dist/bundle/chunks/chunk-4KSTFUIK.js +19 -0
- package/dist/pi/dist/bundle/chunks/chunk-4UNPP53I.js +55 -0
- package/dist/pi/dist/bundle/chunks/chunk-AUUCDC7R.js +4 -0
- package/dist/pi/dist/bundle/chunks/{chunk-V6KH5QG4.js → chunk-BAC3QPNW.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{chunk-4EYXVSA5.js → chunk-FF6XOTWB.js} +9 -9
- package/dist/pi/dist/bundle/chunks/chunk-FMPAMX2W.js +82 -0
- package/dist/pi/dist/bundle/chunks/chunk-GFUN2N5K.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-IEBK4HQA.js +2 -0
- package/dist/pi/dist/bundle/chunks/{chunk-C2WU32PX.js → chunk-IQUU5XIT.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{chunk-EBFHJFEE.js → chunk-LQLJ7CDW.js} +1 -1
- package/dist/pi/dist/bundle/chunks/chunk-MMDXLZVS.js +30 -0
- package/dist/pi/dist/bundle/chunks/{chunk-GN3QYODH.js → chunk-QN4TOIZN.js} +1 -1
- package/dist/pi/dist/bundle/chunks/chunk-RKNK4Y6L.js +2 -0
- package/dist/pi/dist/bundle/chunks/{chunk-B46VJEHW.js → chunk-V7SLUK6A.js} +1 -1
- package/dist/pi/dist/bundle/chunks/chunk-VEJDBY3O.js +1237 -0
- package/dist/pi/dist/bundle/chunks/chunk-VKJQ6CME.js +8 -0
- package/dist/pi/dist/bundle/chunks/{chunk-3TGLJEWK.js → chunk-WL4TUXY7.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{chunk-YZKQS34S.js → chunk-Y55SJART.js} +5 -1
- package/dist/pi/dist/bundle/chunks/{chunk-EOO47QGR.js → chunk-ZBIZYD6W.js} +1 -1
- package/dist/pi/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-ZGYS4UTC.js +2 -0
- package/dist/pi/dist/bundle/chunks/{cli-MCOUW5WS.js → cli-7RHMDOHL.js} +7 -7
- package/dist/pi/dist/bundle/chunks/{cloudflare-workers-ai-system-one-WLAFJSP6.js → cloudflare-workers-ai-system-one-U4J7D646.js} +1 -1
- package/dist/pi/dist/bundle/chunks/codemode-worker.js +2 -0
- package/dist/pi/dist/bundle/chunks/{easter-egg-3d-WMBNSJ4M.js → easter-egg-3d-GEVPKQF6.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{execute-4CEBORGZ.js → execute-L2EEDV3L.js} +5 -3
- package/dist/pi/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/pi/dist/bundle/chunks/{google-generative-ai-INGKNW72.js → google-generative-ai-D5B6W47J.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{google-vertex-IBTX6MBF.js → google-vertex-U4H5YDEW.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{llama-cpp-classify-V5U3QKXI.js → llama-cpp-classify-EJXCQRUQ.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{mistral-conversations-S4OWXIXQ.js → mistral-conversations-S277EKLB.js} +1 -1
- package/dist/pi/dist/bundle/chunks/openai-codex-responses-TEQRB65N.js +10 -0
- package/dist/pi/dist/bundle/chunks/{openai-completions-EJNYB6IX.js → openai-completions-HRZOSLBO.js} +3 -3
- package/dist/pi/dist/bundle/chunks/{openai-decisions-IXI34BYG.js → openai-decisions-F66BDLOM.js} +1 -1
- package/dist/pi/dist/bundle/chunks/openai-responses-BAKFWTGE.js +4 -0
- package/dist/pi/dist/bundle/chunks/{openrouter-images-PISKSFMS.js → openrouter-images-VXF5TVIK.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{pi-messages-NORUKF4E.js → pi-messages-UBJKNDRN.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{runtime-FQB7RU7U.js → runtime-J5ZSBGTX.js} +1 -1
- package/dist/pi/dist/bundle/chunks/{typesafe-system-one-CHVC2UUI.js → typesafe-system-one-56TEMIHL.js} +1 -1
- package/dist/pi/dist/bundle/chunks/virtual-modules-KITQRTYM.js +2 -0
- package/dist/pi/dist/bundle/cli-runtime.js +1 -1
- package/dist/pi/dist/bundle/index.js +1 -1
- package/dist/pi/dist/bundle/rpc-entry.js +1 -1
- package/dist/pi/docs/cli.md +14 -1
- package/dist/pi/docs/extensions.md +27 -7
- package/dist/pi/docs/keybindings.md +1 -1
- package/dist/pi/docs/llama-cpp.md +5 -8
- package/dist/pi/docs/models-configuration.md +6 -1
- package/dist/pi/docs/models.md +2 -1
- package/dist/pi/docs/prompt-templates.md +1 -1
- package/dist/pi/docs/providers.md +1 -1
- package/dist/pi/docs/rpc.md +4 -2
- package/dist/pi/docs/sessions.md +7 -1
- package/dist/pi/docs/settings.md +1 -1
- package/dist/pi/docs/tui.md +1 -1
- package/dist/pi/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/dist/pi/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/dist/pi/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/dist/pi/examples/extensions/gondolin/package-lock.json +2 -2
- package/dist/pi/examples/extensions/gondolin/package.json +1 -1
- package/dist/pi/examples/extensions/plan-mode/index.ts +23 -13
- package/dist/pi/examples/extensions/plan-mode/utils.ts +42 -16
- package/dist/pi/examples/extensions/subagent/README.md +14 -11
- package/dist/pi/examples/extensions/subagent/index.ts +392 -171
- package/dist/pi/examples/extensions/with-deps/package-lock.json +2 -2
- package/dist/pi/examples/extensions/with-deps/package.json +1 -1
- package/dist/pi/examples/tsconfig.json +63 -35
- package/dist/pi/package.json +1 -1
- package/dist/pi/packages/ta-agents/extension/index.mjs +185 -140
- package/dist/pi/packages/ta-agents/lib/acp-agent.js +30 -10
- package/dist/pi/packages/ta-agents/lib/agent-bindings.d.ts +2 -0
- package/dist/pi/packages/ta-agents/lib/agent-bindings.js +4 -0
- package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +2 -2
- package/dist/pi/packages/ta-agents/lib/agent-catalog.js +4 -4
- package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts +6 -0
- package/dist/pi/packages/ta-agents/lib/agent-prompt.js +19 -0
- package/dist/pi/packages/ta-agents/lib/agent-session.d.ts +2 -0
- package/dist/pi/packages/ta-agents/lib/agent-session.js +2 -0
- package/dist/pi/packages/ta-agents/lib/agent-streamer.js +7 -0
- package/dist/pi/packages/ta-agents/lib/agent-tool.js +3 -2
- package/dist/pi/packages/ta-agents/lib/extension.js +15 -1
- package/dist/pi/packages/ta-agents/lib/texts.d.ts +4 -0
- package/dist/pi/packages/ta-agents/lib/texts.js +4 -0
- package/dist/pi/packages/ta-agents/package.json +3 -3
- package/dist/pi/packages/ta-bots/extension/index.mjs +31 -253
- package/dist/pi/packages/ta-bots/host/index.mjs +189 -1
- package/dist/pi/packages/ta-bots/lib/bots-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-bots/lib/bots-protocol.js +3 -1
- package/dist/pi/packages/ta-bots/lib/bots-view.js +24 -12
- package/dist/pi/packages/ta-bots/lib/composer.js +1 -0
- package/dist/pi/packages/ta-bots/lib/extension.js +10 -17
- package/dist/pi/packages/ta-bots/lib/i18n.d.ts +1 -0
- package/dist/pi/packages/ta-bots/lib/i18n.js +2 -0
- package/dist/pi/packages/ta-bots/lib/index.js +2 -0
- package/dist/pi/packages/ta-bots/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-bots/lib/style.js +1 -0
- package/dist/pi/packages/ta-bots/lib/text-util.js +8 -1
- package/dist/pi/packages/ta-bots/lib/tool-line.d.ts +8 -0
- package/dist/pi/packages/ta-bots/lib/tool-line.js +19 -0
- package/dist/pi/packages/ta-bots/package.json +1 -1
- package/dist/pi/packages/ta-bots/web/index.js +47 -16
- package/dist/pi/packages/ta-changes/extension/index.mjs +23 -13
- package/dist/pi/packages/ta-changes/lib/card.js +18 -4
- package/dist/pi/packages/ta-changes/lib/changes-protocol.d.ts +0 -4
- package/dist/pi/packages/ta-changes/lib/changes-protocol.js +1 -5
- package/dist/pi/packages/ta-changes/lib/extension.js +5 -13
- package/dist/pi/packages/ta-changes/package.json +1 -1
- package/dist/pi/packages/ta-changes/web/index.js +16 -3
- package/dist/pi/packages/ta-channels/README.en.md +6 -5
- package/dist/pi/packages/ta-channels/README.md +6 -5
- package/dist/pi/packages/ta-channels/extension/index.mjs +350 -28
- package/dist/pi/packages/ta-channels/host/index.mjs +638 -43
- package/dist/pi/packages/ta-channels/lib/agent-cards.d.ts +19 -0
- package/dist/pi/packages/ta-channels/lib/agent-cards.js +58 -0
- package/dist/pi/packages/ta-channels/lib/agent-menu.d.ts +2 -2
- package/dist/pi/packages/ta-channels/lib/agent-menu.js +20 -6
- package/dist/pi/packages/ta-channels/lib/card.d.ts +27 -0
- package/dist/pi/packages/ta-channels/lib/card.js +178 -0
- package/dist/pi/packages/ta-channels/lib/channels-model.d.ts +65 -13
- package/dist/pi/packages/ta-channels/lib/channels-model.js +15 -6
- package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +31 -2
- package/dist/pi/packages/ta-channels/lib/channels-util.js +100 -6
- package/dist/pi/packages/ta-channels/lib/channels.d.ts +28 -18
- package/dist/pi/packages/ta-channels/lib/channels.js +65 -65
- package/dist/pi/packages/ta-channels/lib/create.js +14 -4
- package/dist/pi/packages/ta-channels/lib/extension.d.ts +8 -0
- package/dist/pi/packages/ta-channels/lib/extension.js +104 -18
- package/dist/pi/packages/ta-channels/lib/faces.d.ts +2 -0
- package/dist/pi/packages/ta-channels/lib/faces.js +7 -1
- package/dist/pi/packages/ta-channels/lib/handoff-view.d.ts +19 -0
- package/dist/pi/packages/ta-channels/lib/handoff-view.js +113 -0
- package/dist/pi/packages/ta-channels/lib/handoff.d.ts +67 -0
- package/dist/pi/packages/ta-channels/lib/handoff.js +114 -0
- package/dist/pi/packages/ta-channels/lib/host.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/host.js +1 -1
- package/dist/pi/packages/ta-channels/lib/i18n.d.ts +49 -8
- package/dist/pi/packages/ta-channels/lib/i18n.js +98 -16
- package/dist/pi/packages/ta-channels/lib/index.js +10 -1
- package/dist/pi/packages/ta-channels/lib/member-tools.d.ts +23 -0
- package/dist/pi/packages/ta-channels/lib/member-tools.js +56 -0
- package/dist/pi/packages/ta-channels/lib/members.js +6 -2
- package/dist/pi/packages/ta-channels/lib/more-menu.d.ts +3 -2
- package/dist/pi/packages/ta-channels/lib/more-menu.js +21 -29
- package/dist/pi/packages/ta-channels/lib/notice.d.ts +25 -0
- package/dist/pi/packages/ta-channels/lib/notice.js +101 -0
- package/dist/pi/packages/ta-channels/lib/room.js +26 -10
- package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +1 -6
- package/dist/pi/packages/ta-channels/lib/sidebar.js +257 -84
- package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/style.js +151 -40
- package/dist/pi/packages/ta-channels/lib/tasks.js +3 -4
- package/dist/pi/packages/ta-channels/lib/team.d.ts +58 -10
- package/dist/pi/packages/ta-channels/lib/team.js +159 -38
- package/dist/pi/packages/ta-channels/lib/tool-lines.d.ts +22 -0
- package/dist/pi/packages/ta-channels/lib/tool-lines.js +113 -0
- package/dist/pi/packages/ta-channels/lib/views.d.ts +54 -1
- package/dist/pi/packages/ta-channels/lib/views.js +129 -1
- package/dist/pi/packages/ta-channels/package.json +2 -1
- package/dist/pi/packages/ta-channels/web/index.js +1792 -439
- package/dist/pi/packages/ta-computer-use/package.json +7 -2
- package/dist/pi/packages/ta-cron/README.en.md +6 -4
- package/dist/pi/packages/ta-cron/README.md +6 -4
- package/dist/pi/packages/ta-cron/extension/index.mjs +416 -44
- package/dist/pi/packages/ta-cron/host/index.mjs +30 -3
- package/dist/pi/packages/ta-cron/lib/chat-task.d.ts +48 -0
- package/dist/pi/packages/ta-cron/lib/chat-task.js +133 -0
- package/dist/pi/packages/ta-cron/lib/commands.d.ts +2 -1
- package/dist/pi/packages/ta-cron/lib/commands.js +10 -4
- package/dist/pi/packages/ta-cron/lib/composer.d.ts +11 -0
- package/dist/pi/packages/ta-cron/lib/composer.js +58 -0
- package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts +10 -3
- package/dist/pi/packages/ta-cron/lib/cron-protocol.js +6 -3
- package/dist/pi/packages/ta-cron/lib/editor.js +65 -30
- package/dist/pi/packages/ta-cron/lib/extension.d.ts +2 -0
- package/dist/pi/packages/ta-cron/lib/extension.js +33 -13
- package/dist/pi/packages/ta-cron/lib/i18n.d.ts +30 -1
- package/dist/pi/packages/ta-cron/lib/i18n.js +60 -2
- package/dist/pi/packages/ta-cron/lib/index.js +4 -0
- package/dist/pi/packages/ta-cron/lib/page.d.ts +38 -4
- package/dist/pi/packages/ta-cron/lib/page.js +131 -4
- package/dist/pi/packages/ta-cron/lib/react.d.ts +3 -0
- package/dist/pi/packages/ta-cron/lib/react.js +8 -0
- package/dist/pi/packages/ta-cron/lib/scheduler.js +3 -2
- package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-cron/lib/style.js +168 -50
- package/dist/pi/packages/ta-cron/lib/task-extension.d.ts +15 -0
- package/dist/pi/packages/ta-cron/lib/task-extension.js +56 -0
- package/dist/pi/packages/ta-cron/lib/task-util.d.ts +4 -0
- package/dist/pi/packages/ta-cron/lib/task-util.js +31 -1
- package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +4 -1
- package/dist/pi/packages/ta-cron/lib/tasks-view.js +107 -67
- package/dist/pi/packages/ta-cron/lib/tool-line.d.ts +9 -0
- package/dist/pi/packages/ta-cron/lib/tool-line.js +40 -0
- package/dist/pi/packages/ta-cron/lib/tool.d.ts +5 -1
- package/dist/pi/packages/ta-cron/lib/tool.js +6 -3
- package/dist/pi/packages/ta-cron/package.json +12 -1
- package/dist/pi/packages/ta-cron/web/index.js +1346 -415
- package/dist/pi/packages/ta-extensions/README.en.md +4 -2
- package/dist/pi/packages/ta-extensions/README.md +4 -2
- package/dist/pi/packages/ta-extensions/host/index.mjs +3 -2
- package/dist/pi/packages/ta-extensions/lib/actions.d.ts +4 -0
- package/dist/pi/packages/ta-extensions/lib/actions.js +16 -5
- package/dist/pi/packages/ta-extensions/lib/composer.d.ts +17 -0
- package/dist/pi/packages/ta-extensions/lib/composer.js +84 -0
- package/dist/pi/packages/ta-extensions/lib/extensions-util.d.ts +5 -0
- package/dist/pi/packages/ta-extensions/lib/extensions-util.js +10 -0
- package/dist/pi/packages/ta-extensions/lib/i18n.d.ts +9 -0
- package/dist/pi/packages/ta-extensions/lib/i18n.js +18 -0
- package/dist/pi/packages/ta-extensions/lib/index.js +4 -0
- package/dist/pi/packages/ta-extensions/lib/make-model.d.ts +20 -0
- package/dist/pi/packages/ta-extensions/lib/make-model.js +43 -0
- package/dist/pi/packages/ta-extensions/lib/market-parts.js +8 -2
- package/dist/pi/packages/ta-extensions/lib/market-style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/market-style.js +4 -5
- package/dist/pi/packages/ta-extensions/lib/market-util.d.ts +2 -2
- package/dist/pi/packages/ta-extensions/lib/market-util.js +2 -2
- package/dist/pi/packages/ta-extensions/lib/page.js +52 -23
- package/dist/pi/packages/ta-extensions/lib/react.d.ts +3 -0
- package/dist/pi/packages/ta-extensions/lib/react.js +8 -0
- package/dist/pi/packages/ta-extensions/lib/settings.d.ts +4 -0
- package/dist/pi/packages/ta-extensions/lib/settings.js +44 -0
- package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.js +13 -6
- package/dist/pi/packages/ta-extensions/package.json +6 -1
- package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +25 -10
- package/dist/pi/packages/ta-extensions/web/index.js +459 -47
- package/dist/pi/packages/ta-games/README.en.md +47 -0
- package/dist/pi/packages/ta-games/README.md +47 -0
- package/dist/pi/packages/ta-games/host/index.mjs +65 -0
- package/dist/pi/packages/ta-games/lib/games-view.d.ts +16 -0
- package/dist/pi/packages/ta-games/lib/games-view.js +77 -0
- package/dist/pi/packages/ta-games/lib/host.d.ts +36 -0
- package/dist/pi/packages/ta-games/lib/host.js +83 -0
- package/dist/pi/packages/ta-games/lib/i18n.d.ts +35 -0
- package/dist/pi/packages/ta-games/lib/i18n.js +71 -0
- package/dist/pi/packages/ta-games/lib/ideas.d.ts +6 -0
- package/dist/pi/packages/ta-games/lib/ideas.js +62 -0
- package/dist/pi/packages/ta-games/lib/index.d.ts +7 -0
- package/dist/pi/packages/ta-games/lib/index.js +24 -0
- package/dist/pi/packages/ta-games/lib/make-game.d.ts +23 -0
- package/dist/pi/packages/ta-games/lib/make-game.js +67 -0
- package/dist/pi/packages/ta-games/lib/react.d.ts +11 -0
- package/dist/pi/packages/ta-games/lib/react.js +16 -0
- package/dist/pi/packages/ta-games/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-games/lib/style.js +33 -0
- package/dist/pi/packages/ta-games/package.json +60 -0
- package/dist/pi/packages/ta-games/skills/ta-game/SKILL.md +127 -0
- package/dist/pi/packages/ta-games/skills/ta-game/examples/dino-run/package.json +22 -0
- package/dist/pi/packages/ta-games/skills/ta-game/examples/dino-run/web.js +389 -0
- package/dist/pi/packages/ta-games/skills/ta-game/examples/stack/package.json +22 -0
- package/dist/pi/packages/ta-games/skills/ta-game/examples/stack/web.js +423 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/LICENSE.md +22 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/actions-and-utilities/SKILL.md +343 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/animations/SKILL.md +481 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/audio-and-sound/SKILL.md +453 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/cameras/SKILL.md +497 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/cameras/references/REFERENCE.md +128 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/curves-and-paths/SKILL.md +359 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/data-manager/SKILL.md +406 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/events-system/SKILL.md +497 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/filters-and-postfx/SKILL.md +449 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/game-object-components/SKILL.md +478 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/game-object-components/references/REFERENCE.md +76 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/game-setup-and-config/SKILL.md +485 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/geometry-and-math/SKILL.md +497 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/graphics-and-shapes/SKILL.md +473 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/groups-and-containers/SKILL.md +418 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/input-keyboard-mouse-touch/SKILL.md +500 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/input-keyboard-mouse-touch/references/REFERENCE.md +372 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/loading-assets/SKILL.md +474 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/loading-assets/references/REFERENCE.md +148 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/particles/SKILL.md +499 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/particles/references/REFERENCE.md +17 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/physics-arcade/SKILL.md +468 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/physics-matter/SKILL.md +499 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/render-textures/SKILL.md +441 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/scale-and-responsive/SKILL.md +371 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/scenes/SKILL.md +450 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/scenes/references/REFERENCE.md +78 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/sprites-and-images/SKILL.md +417 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/sprites-and-images/references/REFERENCE.md +160 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/text-and-bitmaptext/SKILL.md +460 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/tilemaps/SKILL.md +440 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/time-and-timers/SKILL.md +496 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/tweens/SKILL.md +414 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/v3-to-v4-migration/SKILL.md +430 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/v4-new-features/SKILL.md +384 -0
- package/dist/pi/packages/ta-games/skills/ta-game/phaser/v4-new-features/references/REFERENCE.md +69 -0
- package/dist/pi/packages/ta-games/web/index.js +431 -0
- package/dist/pi/packages/ta-glance/README.en.md +11 -0
- package/dist/pi/packages/ta-glance/README.md +11 -0
- package/dist/pi/packages/ta-glance/extension/index.mjs +67 -0
- package/dist/pi/packages/ta-glance/lib/card.d.ts +8 -0
- package/dist/pi/packages/ta-glance/lib/card.js +268 -0
- package/dist/pi/packages/ta-glance/lib/extension.d.ts +15 -0
- package/dist/pi/packages/ta-glance/lib/extension.js +24 -0
- package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +9 -0
- package/dist/pi/packages/ta-glance/lib/glance-json.js +85 -0
- package/dist/pi/packages/ta-glance/lib/glance-prompt.d.ts +7 -0
- package/dist/pi/packages/ta-glance/lib/glance-prompt.js +34 -0
- package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +98 -0
- package/dist/pi/packages/ta-glance/lib/glance-protocol.js +8 -0
- package/dist/pi/packages/ta-glance/lib/glance-spec.d.ts +6 -0
- package/dist/pi/packages/ta-glance/lib/glance-spec.js +204 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.d.ts +3 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.js +12 -0
- package/dist/pi/packages/ta-glance/lib/i18n.d.ts +22 -0
- package/dist/pi/packages/ta-glance/lib/i18n.js +41 -0
- package/dist/pi/packages/ta-glance/lib/index.d.ts +7 -0
- package/dist/pi/packages/ta-glance/lib/index.js +22 -0
- package/dist/pi/packages/ta-glance/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-glance/lib/react.js +8 -0
- package/dist/pi/packages/ta-glance/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-glance/lib/style.js +164 -0
- package/dist/pi/packages/ta-glance/package.json +53 -0
- package/dist/pi/packages/ta-glance/web/index.js +933 -0
- package/dist/pi/packages/ta-launcher/lib/actions.d.ts +4 -4
- package/dist/pi/packages/ta-launcher/lib/actions.js +7 -3
- package/dist/pi/packages/ta-launcher/lib/launcher-util.d.ts +7 -7
- package/dist/pi/packages/ta-launcher/lib/launcher-util.js +11 -8
- package/dist/pi/packages/ta-launcher/lib/launcher-view.js +13 -7
- package/dist/pi/packages/ta-launcher/lib/react.d.ts +3 -0
- package/dist/pi/packages/ta-launcher/lib/react.js +8 -0
- package/dist/pi/packages/ta-launcher/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-launcher/lib/style.js +6 -4
- package/dist/pi/packages/ta-launcher/package.json +1 -1
- package/dist/pi/packages/ta-launcher/web/index.js +34 -17
- package/dist/pi/packages/ta-manual/README.en.md +10 -0
- package/dist/pi/packages/ta-manual/README.md +10 -0
- package/dist/pi/packages/ta-manual/lib/i18n.d.ts +15 -0
- package/dist/pi/packages/ta-manual/lib/i18n.js +31 -0
- package/dist/pi/packages/ta-manual/lib/index.d.ts +7 -0
- package/dist/pi/packages/ta-manual/lib/index.js +24 -0
- package/dist/pi/packages/ta-manual/lib/manual-util.d.ts +18 -0
- package/dist/pi/packages/ta-manual/lib/manual-util.js +40 -0
- package/dist/pi/packages/ta-manual/lib/manual-view.d.ts +9 -0
- package/dist/pi/packages/ta-manual/lib/manual-view.js +81 -0
- package/dist/pi/packages/ta-manual/lib/pictures-a.d.ts +2 -0
- package/dist/pi/packages/ta-manual/lib/pictures-a.js +263 -0
- package/dist/pi/packages/ta-manual/lib/pictures-b.d.ts +2 -0
- package/dist/pi/packages/ta-manual/lib/pictures-b.js +216 -0
- package/dist/pi/packages/ta-manual/lib/pictures.d.ts +9 -0
- package/dist/pi/packages/ta-manual/lib/pictures.js +16 -0
- package/dist/pi/packages/ta-manual/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-manual/lib/react.js +8 -0
- package/dist/pi/packages/ta-manual/lib/scene.d.ts +68 -0
- package/dist/pi/packages/ta-manual/lib/scene.js +115 -0
- package/dist/pi/packages/ta-manual/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-manual/lib/style.js +47 -0
- package/dist/pi/packages/ta-manual/lib/topics.d.ts +42 -0
- package/dist/pi/packages/ta-manual/lib/topics.js +354 -0
- package/dist/pi/packages/ta-manual/package.json +54 -0
- package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +119 -0
- package/dist/pi/packages/ta-manual/web/index.js +2223 -0
- package/dist/pi/packages/ta-notify/README.en.md +29 -0
- package/dist/pi/packages/ta-notify/README.md +29 -0
- package/dist/pi/packages/ta-notify/extension/index.mjs +259 -0
- package/dist/pi/packages/ta-notify/host/index.mjs +163 -0
- package/dist/pi/packages/ta-notify/lib/ask-card.d.ts +9 -0
- package/dist/pi/packages/ta-notify/lib/ask-card.js +40 -0
- package/dist/pi/packages/ta-notify/lib/extension.d.ts +24 -0
- package/dist/pi/packages/ta-notify/lib/extension.js +102 -0
- package/dist/pi/packages/ta-notify/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-notify/lib/host.js +9 -0
- package/dist/pi/packages/ta-notify/lib/i18n.d.ts +31 -0
- package/dist/pi/packages/ta-notify/lib/i18n.js +63 -0
- package/dist/pi/packages/ta-notify/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-notify/lib/index.js +29 -0
- package/dist/pi/packages/ta-notify/lib/notify-protocol.d.ts +74 -0
- package/dist/pi/packages/ta-notify/lib/notify-protocol.js +23 -0
- package/dist/pi/packages/ta-notify/lib/notify-service.d.ts +21 -0
- package/dist/pi/packages/ta-notify/lib/notify-service.js +75 -0
- package/dist/pi/packages/ta-notify/lib/notify-util.d.ts +39 -0
- package/dist/pi/packages/ta-notify/lib/notify-util.js +119 -0
- package/dist/pi/packages/ta-notify/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-notify/lib/react.js +8 -0
- package/dist/pi/packages/ta-notify/lib/server-texts.d.ts +9 -0
- package/dist/pi/packages/ta-notify/lib/server-texts.js +22 -0
- package/dist/pi/packages/ta-notify/lib/settings.d.ts +8 -0
- package/dist/pi/packages/ta-notify/lib/settings.js +85 -0
- package/dist/pi/packages/ta-notify/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-notify/lib/style.js +29 -0
- package/dist/pi/packages/ta-notify/lib/tool-line.d.ts +9 -0
- package/dist/pi/packages/ta-notify/lib/tool-line.js +20 -0
- package/dist/pi/packages/ta-notify/lib/tool.d.ts +37 -0
- package/dist/pi/packages/ta-notify/lib/tool.js +46 -0
- package/dist/pi/packages/ta-notify/lib/watcher.d.ts +15 -0
- package/dist/pi/packages/ta-notify/lib/watcher.js +81 -0
- package/dist/pi/packages/ta-notify/package.json +55 -0
- package/dist/pi/packages/ta-notify/web/index.js +436 -0
- package/dist/pi/packages/ta-recall/README.en.md +19 -0
- package/dist/pi/packages/ta-recall/README.md +19 -0
- package/dist/pi/packages/ta-recall/extension/index.mjs +614 -0
- package/dist/pi/packages/ta-recall/host/index.mjs +820 -0
- package/dist/pi/packages/ta-recall/lib/brief-card.d.ts +21 -0
- package/dist/pi/packages/ta-recall/lib/brief-card.js +67 -0
- package/dist/pi/packages/ta-recall/lib/brief-home.d.ts +49 -0
- package/dist/pi/packages/ta-recall/lib/brief-home.js +143 -0
- package/dist/pi/packages/ta-recall/lib/brief-seen.d.ts +9 -0
- package/dist/pi/packages/ta-recall/lib/brief-seen.js +26 -0
- package/dist/pi/packages/ta-recall/lib/brief-util.d.ts +64 -0
- package/dist/pi/packages/ta-recall/lib/brief-util.js +179 -0
- package/dist/pi/packages/ta-recall/lib/chat-icons.d.ts +8 -0
- package/dist/pi/packages/ta-recall/lib/chat-icons.js +56 -0
- package/dist/pi/packages/ta-recall/lib/composer.d.ts +7 -0
- package/dist/pi/packages/ta-recall/lib/composer.js +38 -0
- package/dist/pi/packages/ta-recall/lib/conversation-index.d.ts +25 -0
- package/dist/pi/packages/ta-recall/lib/conversation-index.js +72 -0
- package/dist/pi/packages/ta-recall/lib/conversation-util.d.ts +16 -0
- package/dist/pi/packages/ta-recall/lib/conversation-util.js +109 -0
- package/dist/pi/packages/ta-recall/lib/conversations.d.ts +11 -0
- package/dist/pi/packages/ta-recall/lib/conversations.js +46 -0
- package/dist/pi/packages/ta-recall/lib/extension.d.ts +24 -0
- package/dist/pi/packages/ta-recall/lib/extension.js +131 -0
- package/dist/pi/packages/ta-recall/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-recall/lib/host.js +11 -0
- package/dist/pi/packages/ta-recall/lib/i18n.d.ts +41 -0
- package/dist/pi/packages/ta-recall/lib/i18n.js +83 -0
- package/dist/pi/packages/ta-recall/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-recall/lib/index.js +45 -0
- package/dist/pi/packages/ta-recall/lib/react.d.ts +11 -0
- package/dist/pi/packages/ta-recall/lib/react.js +16 -0
- package/dist/pi/packages/ta-recall/lib/recall-protocol.d.ts +186 -0
- package/dist/pi/packages/ta-recall/lib/recall-protocol.js +60 -0
- package/dist/pi/packages/ta-recall/lib/recall-service.d.ts +42 -0
- package/dist/pi/packages/ta-recall/lib/recall-service.js +241 -0
- package/dist/pi/packages/ta-recall/lib/search-source.d.ts +7 -0
- package/dist/pi/packages/ta-recall/lib/search-source.js +49 -0
- package/dist/pi/packages/ta-recall/lib/search-util.d.ts +30 -0
- package/dist/pi/packages/ta-recall/lib/search-util.js +167 -0
- package/dist/pi/packages/ta-recall/lib/server-texts.d.ts +7 -0
- package/dist/pi/packages/ta-recall/lib/server-texts.js +17 -0
- package/dist/pi/packages/ta-recall/lib/settings.d.ts +4 -0
- package/dist/pi/packages/ta-recall/lib/settings.js +77 -0
- package/dist/pi/packages/ta-recall/lib/skill-card.d.ts +9 -0
- package/dist/pi/packages/ta-recall/lib/skill-card.js +51 -0
- package/dist/pi/packages/ta-recall/lib/skill-util.d.ts +19 -0
- package/dist/pi/packages/ta-recall/lib/skill-util.js +110 -0
- package/dist/pi/packages/ta-recall/lib/stored.d.ts +5 -0
- package/dist/pi/packages/ta-recall/lib/stored.js +28 -0
- package/dist/pi/packages/ta-recall/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-recall/lib/style.js +48 -0
- package/dist/pi/packages/ta-recall/lib/tool-line.d.ts +10 -0
- package/dist/pi/packages/ta-recall/lib/tool-line.js +23 -0
- package/dist/pi/packages/ta-recall/lib/tool.d.ts +63 -0
- package/dist/pi/packages/ta-recall/lib/tool.js +71 -0
- package/dist/pi/packages/ta-recall/package.json +55 -0
- package/dist/pi/packages/ta-recall/web/index.js +1038 -0
- package/dist/pi/packages/ta-rooms/README.en.md +23 -0
- package/dist/pi/packages/ta-rooms/README.md +23 -0
- package/dist/pi/packages/ta-rooms/lib/dialogs.d.ts +39 -0
- package/dist/pi/packages/ta-rooms/lib/dialogs.js +235 -0
- package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +101 -0
- package/dist/pi/packages/ta-rooms/lib/i18n.js +203 -0
- package/dist/pi/packages/ta-rooms/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-rooms/lib/index.js +85 -0
- package/dist/pi/packages/ta-rooms/lib/members-view.d.ts +3 -0
- package/dist/pi/packages/ta-rooms/lib/members-view.js +64 -0
- package/dist/pi/packages/ta-rooms/lib/page.d.ts +105 -0
- package/dist/pi/packages/ta-rooms/lib/page.js +306 -0
- package/dist/pi/packages/ta-rooms/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-rooms/lib/react.js +8 -0
- package/dist/pi/packages/ta-rooms/lib/room-view.d.ts +17 -0
- package/dist/pi/packages/ta-rooms/lib/room-view.js +150 -0
- package/dist/pi/packages/ta-rooms/lib/rooms-page.d.ts +8 -0
- package/dist/pi/packages/ta-rooms/lib/rooms-page.js +174 -0
- package/dist/pi/packages/ta-rooms/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-rooms/lib/style.js +154 -0
- package/dist/pi/packages/ta-rooms/package.json +50 -0
- package/dist/pi/packages/ta-rooms/web/index.js +1932 -0
- package/dist/pi/packages/ta-share/README.en.md +27 -0
- package/dist/pi/packages/ta-share/README.md +27 -0
- package/dist/pi/packages/ta-share/extension/index.mjs +184 -0
- package/dist/pi/packages/ta-share/host/index.mjs +364 -0
- package/dist/pi/packages/ta-share/lib/extension.d.ts +15 -0
- package/dist/pi/packages/ta-share/lib/extension.js +115 -0
- package/dist/pi/packages/ta-share/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-share/lib/host.js +9 -0
- package/dist/pi/packages/ta-share/lib/i18n.d.ts +106 -0
- package/dist/pi/packages/ta-share/lib/i18n.js +213 -0
- package/dist/pi/packages/ta-share/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-share/lib/index.js +77 -0
- package/dist/pi/packages/ta-share/lib/page.d.ts +48 -0
- package/dist/pi/packages/ta-share/lib/page.js +105 -0
- package/dist/pi/packages/ta-share/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-share/lib/react.js +8 -0
- package/dist/pi/packages/ta-share/lib/server-texts.d.ts +14 -0
- package/dist/pi/packages/ta-share/lib/server-texts.js +52 -0
- package/dist/pi/packages/ta-share/lib/share-dialog.d.ts +18 -0
- package/dist/pi/packages/ta-share/lib/share-dialog.js +233 -0
- package/dist/pi/packages/ta-share/lib/share-protocol.d.ts +86 -0
- package/dist/pi/packages/ta-share/lib/share-protocol.js +30 -0
- package/dist/pi/packages/ta-share/lib/share-service.d.ts +50 -0
- package/dist/pi/packages/ta-share/lib/share-service.js +130 -0
- package/dist/pi/packages/ta-share/lib/shared-view.d.ts +18 -0
- package/dist/pi/packages/ta-share/lib/shared-view.js +225 -0
- package/dist/pi/packages/ta-share/lib/shares-page.d.ts +3 -0
- package/dist/pi/packages/ta-share/lib/shares-page.js +54 -0
- package/dist/pi/packages/ta-share/lib/snapshot.d.ts +30 -0
- package/dist/pi/packages/ta-share/lib/snapshot.js +195 -0
- package/dist/pi/packages/ta-share/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-share/lib/style.js +111 -0
- package/dist/pi/packages/ta-share/package.json +56 -0
- package/dist/pi/packages/ta-share/web/index.js +1197 -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/browser-common.d.ts +1 -1
- package/dist/pi/packages/ta-workspace/lib/browser-common.js +29 -30
- package/dist/pi/packages/ta-workspace/lib/browser-tool-line.d.ts +15 -0
- package/dist/pi/packages/ta-workspace/lib/browser-tool-line.js +70 -0
- package/dist/pi/packages/ta-workspace/lib/bytes.d.ts +11 -0
- package/dist/pi/packages/ta-workspace/lib/bytes.js +40 -0
- package/dist/pi/packages/ta-workspace/lib/common.d.ts +2 -1
- package/dist/pi/packages/ta-workspace/lib/common.js +15 -37
- package/dist/pi/packages/ta-workspace/lib/editors.js +40 -4
- package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +14 -4
- package/dist/pi/packages/ta-workspace/lib/i18n.js +31 -11
- package/dist/pi/packages/ta-workspace/lib/index.js +17 -0
- package/dist/pi/packages/ta-workspace/lib/launcher.d.ts +9 -0
- package/dist/pi/packages/ta-workspace/lib/launcher.js +39 -0
- package/dist/pi/packages/ta-workspace/lib/preview.d.ts +22 -3
- package/dist/pi/packages/ta-workspace/lib/preview.js +150 -22
- package/dist/pi/packages/ta-workspace/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-workspace/lib/style.js +70 -41
- package/dist/pi/packages/ta-workspace/lib/terminal-sessions.d.ts +15 -4
- package/dist/pi/packages/ta-workspace/lib/terminal-sessions.js +31 -9
- package/dist/pi/packages/ta-workspace/lib/terminal.d.ts +3 -2
- package/dist/pi/packages/ta-workspace/lib/terminal.js +51 -21
- package/dist/pi/packages/ta-workspace/lib/util/keys.d.ts +18 -0
- package/dist/pi/packages/ta-workspace/lib/util/keys.js +23 -0
- package/dist/pi/packages/ta-workspace/lib/util/preview.d.ts +46 -0
- package/dist/pi/packages/ta-workspace/lib/util/preview.js +106 -1
- package/dist/pi/packages/ta-workspace/lib/util/terminal.d.ts +5 -0
- package/dist/pi/packages/ta-workspace/lib/util/terminal.js +14 -0
- package/dist/pi/packages/ta-workspace/package.json +1 -1
- package/dist/pi/packages/ta-workspace/web/index.js +1032 -382
- package/dist/public/assets/OrbitControls-DVf70a7w.js +1 -0
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-EVMX_yOb.js → abnfDiagram-S7VZAUFO-D9uU0Tx2.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-CDgbgZ_o.js → architecture-WOLXFQ4H-f7Nm7EIo.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-dHreaCWz.js → architectureDiagram-YGSQEFNW-DSAqlcms.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-D6FhzBDq.js → blockDiagram-APKKGZFW-C0lPIW9g.js} +1 -1
- package/dist/public/assets/browser-WLpgVYno.js +12 -0
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-BFpcr8Cs.js → c4Diagram-KJ2TOQU5-CDcZ7mJq.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-BczXkMV-.js → chunk-6MUBBAK2-CXPuyqPL.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-CjJsv3jB.js → chunk-AXFCVDMN-Du6JRX1x.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-FBaleaLz.js → chunk-BG4553SI-D592E55X.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-BFdXY5sX.js → chunk-DQASFODM-BW2r2SL4.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-C5cwK-Fg.js → chunk-HFQBQIA3-C3yoe54R.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-BUek3IRk.js → chunk-KQLB2F66-DF8gfYCy.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-BxsYBzt6.js → chunk-KS47KZWR-C8CRMTv1.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-Bdcwz9fS.js → chunk-LEVMRMFU-BDcMKiwj.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-kkpP5oug.js → chunk-M57EVK23-CKJPBygc.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-CFhQgxmD.js → chunk-OY52VR5R-B3ZWH07L.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-BVXqu0eC.js → chunk-QB3YPZ4I-DI-z4UPL.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-B7SUqqLI.js → chunk-R3KSYZAL-Bg4-haAc.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-B3abfbnH.js → chunk-STOXU5M4-l_SHib3p.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-C9NqnUav.js → chunk-TU62E6Q5-BINu9tIm.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-BeLfETDx.js → chunk-X4PVCEUW-BQn-mvV5.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-DXai1i8p.js → chunk-XXDRQBXY-uvpAu0Ys.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-Zj6ne_tC.js → classDiagram-v2-L25IHNXF-BIowooW1.js} +1 -1
- package/dist/public/assets/{cose-bilkent-JH36ORCC-C0-TjqfJ.js → cose-bilkent-JH36ORCC-BTyx1Mh2.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-Dg54eFzZ.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-BnqxfzPa.js → cynefinDiagram-L36ESFBY-D64EU9I0.js} +1 -1
- package/dist/public/assets/{d3-selection-DfFLTR9d.js → d3-selection-CN9k6_B9.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-kI17e5cH.js → dagre-SPEB5RXH-FCbz2-Kk.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-DgPjeLA5.js → diagram-3B7GL73J-OhHUSI7j.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-CRhPfa0I.js → diagram-DNEMPZML-Be4xMtp6.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-ExuTg12b.js → diagram-L3MUGCDN-CmKSs3aG.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-Dgx5xNiY.js → diagram-LA4NIPWU-D1C32rMN.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-BuifkUTl.js → diagram-MHCOC4E2-BjoE6JXs.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-CFEaBo7z.js → diagram-XPFHEONP-B22k4v8R.js} +1 -1
- package/dist/public/assets/{dist-C-iJHcSK.js → dist-DcBP8Cf6.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-D-hp5yNt.js → ebnfDiagram-UZSYDL2S-Tn-K8-X7.js} +1 -1
- package/dist/public/assets/{editor.api-BopUWpqY.js → editor.api-Bz4sjRz_.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-CBbk_IpU.js → elk-XV6XMXQE-COnQsWlN.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-B02R_WWE.js → erDiagram-EYBAPDEH-c53dJilq.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-aCZfYnCI.js → eventmodeling-K75KTNOO-DaFpPPks.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-V5qkYWIO.js +1 -0
- package/dist/public/assets/{freemarker2-DMN60LeK.js → freemarker2-BLxfRHsw.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-DioU8TlD.js → ganttDiagram-23REXITY-Md-SavIS.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-1q8ldRXU.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW--q3ctg6y.js → gitGraphDiagram-STJD7YCW-CMSwTghO.js} +1 -1
- package/dist/public/assets/{handlebars-B_-qdvpB.js → handlebars-sNpu01kP.js} +1 -1
- package/dist/public/assets/{html-BN8Ah3Js.js → html-C_tKd-uP.js} +1 -1
- package/dist/public/assets/{index-B3A--ac8.js → index-Bn86rI4n.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-Crere6sx.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-CGXteYo9.js → infoDiagram-KBXO4MBG-CwgNj-7i.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-DM2LmOAc.js → ishikawaDiagram-M35NCXHK-BSlzQNMN.js} +1 -1
- package/dist/public/assets/{javascript-BlizGb0q.js → javascript-l3qKw0L-.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-CNITRtGl.js → journeyDiagram-OPLOXDXO-B09LPEnF.js} +1 -1
- package/dist/public/assets/{jsonMode-CEUmT5sN.js → jsonMode-5SQQn1EX.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-BPUuS9um.js → kanban-definition-BZKZHSQY-BiW4aJ29.js} +1 -1
- package/dist/public/assets/{liquid-BbyLjUbE.js → liquid-BGyTIIUt.js} +1 -1
- package/dist/public/assets/{mdx-DiQz7Q35.js → mdx-8tGjz4em.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-Dum100hC.js → mermaid-parser.core-CctN5b0z.js} +3 -3
- package/dist/public/assets/{mermaid.core-BWmWf6XO.js → mermaid.core-7ERSdZ4-.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-L8HyYUDY.js → mindmap-definition-I2QAS2VK-D-GOUwW1.js} +1 -1
- package/dist/public/assets/module-DEqsdd00.js +1 -0
- package/dist/public/assets/module-TWc52XwT.js +2244 -0
- package/dist/public/assets/{monaco-zOOyBmxy.js → monaco-B_9hlk78.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-qMf5LkHT.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-CTZKPo0Z.js → pegDiagram-FD4XPPHP-Dmy1fWB3.js} +1 -1
- package/dist/public/assets/phaser.esm-BxCDEWDb.js +3202 -0
- package/dist/public/assets/pie-XZMESJXO-BjqLn4qm.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-DAeT3dFi.js → pieDiagram-J4AKIIQI-CXFHLYTg.js} +1 -1
- package/dist/public/assets/{python-C984gt98.js → python-e-JK0s5M.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2--PXxwV1Z.js → quadrantDiagram-XTYBLID2-RQvEpGWO.js} +1 -1
- package/dist/public/assets/radar-ABXABTNO-DWO6t_4C.js +1 -0
- package/dist/public/assets/railroad-I3PHUGI6-D1XOJPWy.js +1 -0
- package/dist/public/assets/{railroad-abnf-LNEFI6M7-BYcFfrCa.js → railroad-abnf-LNEFI6M7-CDOSPZwX.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-Cd33qxAm.js → railroad-ebnf-DWYD2UWJ-BTrNQ0DX.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-C5TpzaU8.js → railroad-peg-JR7BVNR7-B7NtVofS.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-DlWwjbhH.js → railroadDiagram-MRQ6NCDL-DsDrT0Jf.js} +1 -1
- package/dist/public/assets/{razor-BBqMR1Qn.js → razor-DtSPwumi.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-CsYBy9HS.js → requirementDiagram-Y7LWUY3S-BQh0hFuA.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-WGJFYUXA-Baxyb5p9.js → sankeyDiagram-WGJFYUXA-BUXNAQEF.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-Cq6VeBT_.js → sequenceDiagram-5NDRBG5M-05f-N5V_.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-O60WKaE7.js → stateDiagram-v2-FJ4FJNEA-D6V1fGWV.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-C2nf1-Cc.js → swimlanes-UMQ2AFYF-DWhlPvKs.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CRn5uHsY.js +8 -0
- package/dist/public/assets/three.module-CeVBJVoU.js +4225 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-DEfUG6YH.js → timeline-definition-SEUHKTQE-CMdocOui.js} +1 -1
- package/dist/public/assets/treeView-D4JQ5SDB-D09wHNzT.js +1 -0
- package/dist/public/assets/treemap-SAJKECNS-ChxAT7Fq.js +1 -0
- package/dist/public/assets/{typescript-Gtq7f0aU.js → typescript-65jNyipU.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-Gw9DyJcx.js → usecaseDiagram-AFA6YXN4-BQTHUX1f.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-Clb3MLWF.js → vennDiagram-NNMJR3RB-BULkVTfA.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-DfSjKzbJ.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-BrTRpwu2.js → wardleyDiagram-S7YFUSEH-Cek6l8lz.js} +1 -1
- package/dist/public/assets/{xml-Bx3nk7iG.js → xml-DWBejfu-.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-BfjTcIsb.js → xychartDiagram-GGNKY7IX-ujnZQTWA.js} +1 -1
- package/dist/public/assets/{yaml-dFLE_rSl.js → yaml-CwRCT7q1.js} +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/launch.svg +46 -42
- package/dist/serve/index.mjs +8244 -3756
- package/package.json +33 -26
- package/dist/pi/dist/bundle/chunks/anthropic-messages-BWGCKOF4.js +0 -6
- package/dist/pi/dist/bundle/chunks/chunk-44DLKSKE.js +0 -1232
- package/dist/pi/dist/bundle/chunks/chunk-62VOPMLK.js +0 -65
- package/dist/pi/dist/bundle/chunks/chunk-7O7QKK6A.js +0 -2
- package/dist/pi/dist/bundle/chunks/chunk-CHWNPHIS.js +0 -82
- package/dist/pi/dist/bundle/chunks/chunk-NL4X6LBY.js +0 -4
- package/dist/pi/dist/bundle/chunks/chunk-NZY7EIPA.js +0 -4
- package/dist/pi/dist/bundle/chunks/chunk-R2EGYMOO.js +0 -7
- package/dist/pi/dist/bundle/chunks/chunk-UKVNB6C4.js +0 -2
- package/dist/pi/dist/bundle/chunks/chunk-USJZMAIR.js +0 -2
- package/dist/pi/dist/bundle/chunks/chunk-VOLAXWGI.js +0 -2
- package/dist/pi/dist/bundle/chunks/openai-codex-responses-QAWLOQSN.js +0 -10
- package/dist/pi/dist/bundle/chunks/openai-responses-MD3562FB.js +0 -4
- package/dist/pi/dist/bundle/chunks/virtual-modules-O76XM3OB.js +0 -2
- package/dist/public/assets/browser-y6EDNUmc.js +0 -12
- package/dist/public/assets/cynefin-EF2NZ3EQ-CoY4CrZu.js +0 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-CATkJShO.js +0 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-g4yHXXxx.js +0 -1
- package/dist/public/assets/info-OHQRW6UA-CKADJjz4.js +0 -1
- package/dist/public/assets/module-CH7IXa5L.js +0 -1781
- package/dist/public/assets/module-DNAasuMC.js +0 -1
- package/dist/public/assets/packet-JDAUHWVQ-CpKMhX4K.js +0 -1
- package/dist/public/assets/pie-XZMESJXO-CW-zGDRd.js +0 -1
- package/dist/public/assets/radar-ABXABTNO-Cg8W433p.js +0 -1
- package/dist/public/assets/railroad-I3PHUGI6-DriMt2PQ.js +0 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-B46JxqS8.js +0 -8
- package/dist/public/assets/treeView-D4JQ5SDB-1LhEWwC9.js +0 -1
- package/dist/public/assets/treemap-SAJKECNS-D3t3N7nS.js +0 -1
- package/dist/public/assets/wardley-7MLQ67FV-D3sAsd8p.js +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -258,9 +258,12 @@ var init_emitter = __esm(() => {
|
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
// ../../packages/rpc/esm/node/websocket/websocket-frames.js
|
|
261
|
+
import { constants, deflateRawSync, inflateRawSync } from "node:zlib";
|
|
262
|
+
|
|
261
263
|
class WebSocketFrameParser {
|
|
262
|
-
constructor(maxPayload) {
|
|
264
|
+
constructor(maxPayload, deflate = false) {
|
|
263
265
|
this.maxPayload = maxPayload;
|
|
266
|
+
this.deflate = deflate;
|
|
264
267
|
this.buffer = Buffer.alloc(0);
|
|
265
268
|
}
|
|
266
269
|
push(chunk) {
|
|
@@ -278,7 +281,8 @@ class WebSocketFrameParser {
|
|
|
278
281
|
}
|
|
279
282
|
const fin = (buffer[0] & 128) !== 0;
|
|
280
283
|
const opcode = buffer[0] & 15;
|
|
281
|
-
|
|
284
|
+
const compressed = (buffer[0] & 64) !== 0;
|
|
285
|
+
if ((buffer[0] & (this.deflate ? 48 : 112)) !== 0) {
|
|
282
286
|
throw new WebSocketProtocolError(1002, "Reserved bits are set.");
|
|
283
287
|
}
|
|
284
288
|
if (![0, 1, 2, 8, 9, 10].includes(opcode)) {
|
|
@@ -306,8 +310,11 @@ class WebSocketFrameParser {
|
|
|
306
310
|
length = high * 4294967296 + buffer.readUInt32BE(6);
|
|
307
311
|
offset = 10;
|
|
308
312
|
}
|
|
309
|
-
if (WebSocketFrames.isControl(opcode) && (length > 125 || !fin)) {
|
|
310
|
-
throw new WebSocketProtocolError(1002, "Control frames are at most 125 bytes and not
|
|
313
|
+
if (WebSocketFrames.isControl(opcode) && (length > 125 || !fin || compressed)) {
|
|
314
|
+
throw new WebSocketProtocolError(1002, "Control frames are at most 125 bytes, not fragmented and not compressed.");
|
|
315
|
+
}
|
|
316
|
+
if (compressed && opcode === WebSocketFrames.CONTINUATION) {
|
|
317
|
+
throw new WebSocketProtocolError(1002, "Only the first frame of a message says it is compressed.");
|
|
311
318
|
}
|
|
312
319
|
if (length > this.maxPayload) {
|
|
313
320
|
throw new WebSocketProtocolError(1009, `The message is larger than ${this.maxPayload} bytes.`);
|
|
@@ -321,10 +328,10 @@ class WebSocketFrameParser {
|
|
|
321
328
|
payload[i] ^= mask[i & 3];
|
|
322
329
|
}
|
|
323
330
|
this.buffer = buffer.subarray(offset + 4 + length);
|
|
324
|
-
return { fin, opcode, payload };
|
|
331
|
+
return { fin, compressed, opcode, payload };
|
|
325
332
|
}
|
|
326
333
|
}
|
|
327
|
-
var WebSocketProtocolError, WebSocketFrames;
|
|
334
|
+
var WebSocketProtocolError, WebSocketFrames, TAIL, WebSocketDeflate;
|
|
328
335
|
var init_websocket_frames = __esm(() => {
|
|
329
336
|
WebSocketProtocolError = class WebSocketProtocolError extends Error {
|
|
330
337
|
constructor(code, message) {
|
|
@@ -339,11 +346,11 @@ var init_websocket_frames = __esm(() => {
|
|
|
339
346
|
WebSocketFrames2.CLOSE = 8;
|
|
340
347
|
WebSocketFrames2.PING = 9;
|
|
341
348
|
WebSocketFrames2.PONG = 10;
|
|
342
|
-
function encode(opcode, payload = Buffer.alloc(0)) {
|
|
349
|
+
function encode(opcode, payload = Buffer.alloc(0), compressed = false) {
|
|
343
350
|
const length = payload.length;
|
|
344
351
|
const size = length < 126 ? 2 : length < 65536 ? 4 : 10;
|
|
345
352
|
const header = Buffer.alloc(size);
|
|
346
|
-
header[0] = 128 | opcode;
|
|
353
|
+
header[0] = 128 | (compressed ? 64 : 0) | opcode;
|
|
347
354
|
if (length < 126) {
|
|
348
355
|
header[1] = length;
|
|
349
356
|
} else if (length < 65536) {
|
|
@@ -370,6 +377,41 @@ var init_websocket_frames = __esm(() => {
|
|
|
370
377
|
}
|
|
371
378
|
WebSocketFrames2.isControl = isControl;
|
|
372
379
|
})(WebSocketFrames || (WebSocketFrames = {}));
|
|
380
|
+
TAIL = Buffer.from([0, 0, 255, 255]);
|
|
381
|
+
(function(WebSocketDeflate2) {
|
|
382
|
+
WebSocketDeflate2.RESPONSE = "permessage-deflate; server_no_context_takeover; client_no_context_takeover";
|
|
383
|
+
WebSocketDeflate2.MIN_BYTES = 1024;
|
|
384
|
+
function offered(header) {
|
|
385
|
+
const offers = (Array.isArray(header) ? header.join(",") : header !== null && header !== undefined ? header : "").split(",");
|
|
386
|
+
return offers.some((offer) => {
|
|
387
|
+
const [name, ...params] = offer.split(";").map((part) => part.trim().toLowerCase());
|
|
388
|
+
if (name !== "permessage-deflate") {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
return params.every((param) => {
|
|
392
|
+
const [key, value] = param.split("=").map((part) => part.trim().replace(/^"|"$/g, ""));
|
|
393
|
+
return key !== "server_max_window_bits" || value === "15";
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
WebSocketDeflate2.offered = offered;
|
|
398
|
+
function compress(data) {
|
|
399
|
+
const deflated = deflateRawSync(data, { level: 3, finishFlush: constants.Z_SYNC_FLUSH });
|
|
400
|
+
return deflated.subarray(0, deflated.length - TAIL.length);
|
|
401
|
+
}
|
|
402
|
+
WebSocketDeflate2.compress = compress;
|
|
403
|
+
function decompress(data, maxBytes) {
|
|
404
|
+
try {
|
|
405
|
+
return inflateRawSync(Buffer.concat([data, TAIL]), { maxOutputLength: maxBytes, finishFlush: constants.Z_SYNC_FLUSH });
|
|
406
|
+
} catch (error) {
|
|
407
|
+
if (error.code === "ERR_BUFFER_TOO_LARGE") {
|
|
408
|
+
throw new WebSocketProtocolError(1009, `The message is larger than ${maxBytes} bytes.`);
|
|
409
|
+
}
|
|
410
|
+
throw new WebSocketProtocolError(1007, "A compressed message does not inflate.");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
WebSocketDeflate2.decompress = decompress;
|
|
414
|
+
})(WebSocketDeflate || (WebSocketDeflate = {}));
|
|
373
415
|
});
|
|
374
416
|
|
|
375
417
|
// ../../packages/rpc/esm/node/websocket/websocket-connection.js
|
|
@@ -402,17 +444,20 @@ class WebSocketConnection {
|
|
|
402
444
|
if (typeof key !== "string" || Buffer.from(key, "base64").length !== 16) {
|
|
403
445
|
return { status: 400, message: "Missing or invalid Sec-WebSocket-Key." };
|
|
404
446
|
}
|
|
405
|
-
|
|
447
|
+
const deflate = !!request.headers.origin && WebSocketDeflate.offered(request.headers["sec-websocket-extensions"]);
|
|
448
|
+
return { key, deflate };
|
|
406
449
|
}
|
|
407
450
|
static accept(key) {
|
|
408
451
|
return createHash("sha1").update(key + WebSocketConnection.GUID).digest("base64");
|
|
409
452
|
}
|
|
410
453
|
static open(socket, key, head, options) {
|
|
454
|
+
const extensions = options.deflate ? `Sec-WebSocket-Extensions: ${WebSocketDeflate.RESPONSE}\r
|
|
455
|
+
` : "";
|
|
411
456
|
socket.write(`HTTP/1.1 101 Switching Protocols\r
|
|
412
457
|
Upgrade: websocket\r
|
|
413
458
|
Connection: Upgrade\r
|
|
414
459
|
Sec-WebSocket-Accept: ${WebSocketConnection.accept(key)}\r
|
|
415
|
-
\r
|
|
460
|
+
${extensions}\r
|
|
416
461
|
`);
|
|
417
462
|
const connection = new WebSocketConnection(socket, options);
|
|
418
463
|
connection.start(head);
|
|
@@ -434,10 +479,11 @@ ${message}`);
|
|
|
434
479
|
this.onCloseEmitter = new Emitter;
|
|
435
480
|
this.decoder = new TextDecoder("utf-8", { fatal: true });
|
|
436
481
|
this.fragments = [];
|
|
482
|
+
this.compressed = false;
|
|
437
483
|
this.fragmentsLength = 0;
|
|
438
484
|
this.state = "open";
|
|
439
485
|
this.alive = true;
|
|
440
|
-
this.parser = new WebSocketFrameParser(options.maxPayload);
|
|
486
|
+
this.parser = new WebSocketFrameParser(options.maxPayload, !!options.deflate);
|
|
441
487
|
}
|
|
442
488
|
get onMessage() {
|
|
443
489
|
return this.onMessageEmitter.event;
|
|
@@ -450,7 +496,12 @@ ${message}`);
|
|
|
450
496
|
}
|
|
451
497
|
send(text) {
|
|
452
498
|
if (this.state === "open") {
|
|
453
|
-
|
|
499
|
+
const data = Buffer.from(text);
|
|
500
|
+
if (this.options.deflate && data.length >= WebSocketDeflate.MIN_BYTES) {
|
|
501
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.TEXT, WebSocketDeflate.compress(data), true));
|
|
502
|
+
} else {
|
|
503
|
+
this.socket.write(WebSocketFrames.encode(WebSocketFrames.TEXT, data));
|
|
504
|
+
}
|
|
454
505
|
}
|
|
455
506
|
}
|
|
456
507
|
close(code = 1000, reason = "") {
|
|
@@ -487,13 +538,13 @@ ${message}`);
|
|
|
487
538
|
try {
|
|
488
539
|
for (const frame of this.parser.push(chunk)) {
|
|
489
540
|
this.alive = true;
|
|
490
|
-
this.handle(frame.opcode, frame.fin, frame.payload);
|
|
541
|
+
this.handle(frame.opcode, frame.fin, frame.payload, frame.compressed);
|
|
491
542
|
}
|
|
492
543
|
} catch (error) {
|
|
493
544
|
this.close(error instanceof WebSocketProtocolError ? error.code : 1011, error instanceof Error ? error.message : "");
|
|
494
545
|
}
|
|
495
546
|
}
|
|
496
|
-
handle(opcode, fin, payload) {
|
|
547
|
+
handle(opcode, fin, payload, compressed = false) {
|
|
497
548
|
switch (opcode) {
|
|
498
549
|
case WebSocketFrames.PING:
|
|
499
550
|
this.socket.write(WebSocketFrames.encode(WebSocketFrames.PONG, payload));
|
|
@@ -517,6 +568,7 @@ ${message}`);
|
|
|
517
568
|
if (this.fragments.length) {
|
|
518
569
|
throw new WebSocketProtocolError(1002, "A new message started inside a fragmented one.");
|
|
519
570
|
}
|
|
571
|
+
this.compressed = compressed;
|
|
520
572
|
break;
|
|
521
573
|
case WebSocketFrames.CONTINUATION:
|
|
522
574
|
if (!this.fragments.length) {
|
|
@@ -530,9 +582,11 @@ ${message}`);
|
|
|
530
582
|
}
|
|
531
583
|
this.fragments.push(payload);
|
|
532
584
|
if (fin) {
|
|
533
|
-
const
|
|
585
|
+
const joined = this.fragments.length === 1 ? this.fragments[0] : Buffer.concat(this.fragments);
|
|
586
|
+
const message = this.compressed ? WebSocketDeflate.decompress(joined, this.options.maxPayload) : joined;
|
|
534
587
|
this.fragments = [];
|
|
535
588
|
this.fragmentsLength = 0;
|
|
589
|
+
this.compressed = false;
|
|
536
590
|
let text;
|
|
537
591
|
try {
|
|
538
592
|
text = this.decoder.decode(message);
|
|
@@ -561,16 +615,59 @@ var init_websocket_connection = __esm(() => {
|
|
|
561
615
|
WebSocketConnection.GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
562
616
|
});
|
|
563
617
|
|
|
618
|
+
// ../../ta-packages/ta-relay/esm/common/relay-bytes.js
|
|
619
|
+
var RelayBytes;
|
|
620
|
+
var init_relay_bytes = __esm(() => {
|
|
621
|
+
(function(RelayBytes2) {
|
|
622
|
+
function random(length) {
|
|
623
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(length));
|
|
624
|
+
}
|
|
625
|
+
RelayBytes2.random = random;
|
|
626
|
+
function toBase64(bytes) {
|
|
627
|
+
let binary = "";
|
|
628
|
+
for (const byte of bytes) {
|
|
629
|
+
binary += String.fromCharCode(byte);
|
|
630
|
+
}
|
|
631
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
632
|
+
}
|
|
633
|
+
RelayBytes2.toBase64 = toBase64;
|
|
634
|
+
function fromBase64(text) {
|
|
635
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text)) {
|
|
636
|
+
throw new Error("Not base64url.");
|
|
637
|
+
}
|
|
638
|
+
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
|
|
639
|
+
const bytes = new Uint8Array(binary.length);
|
|
640
|
+
for (let i = 0;i < binary.length; i++) {
|
|
641
|
+
bytes[i] = binary.charCodeAt(i);
|
|
642
|
+
}
|
|
643
|
+
return bytes;
|
|
644
|
+
}
|
|
645
|
+
RelayBytes2.fromBase64 = fromBase64;
|
|
646
|
+
function concat(...parts) {
|
|
647
|
+
const bytes = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
|
|
648
|
+
let offset = 0;
|
|
649
|
+
for (const part of parts) {
|
|
650
|
+
bytes.set(part, offset);
|
|
651
|
+
offset += part.length;
|
|
652
|
+
}
|
|
653
|
+
return bytes;
|
|
654
|
+
}
|
|
655
|
+
RelayBytes2.concat = concat;
|
|
656
|
+
})(RelayBytes || (RelayBytes = {}));
|
|
657
|
+
});
|
|
658
|
+
|
|
564
659
|
// ../../ta-packages/ta-relay/esm/common/relay-protocol.js
|
|
565
660
|
var exports_relay_protocol = {};
|
|
566
661
|
__export(exports_relay_protocol, {
|
|
567
662
|
RelayCloseCode: () => RelayCloseCode,
|
|
663
|
+
RELAY_VIEWER_HEADERS: () => RELAY_VIEWER_HEADERS,
|
|
568
664
|
RELAY_STALE_MS: () => RELAY_STALE_MS,
|
|
569
665
|
RELAY_SHARE_PATH: () => RELAY_SHARE_PATH,
|
|
570
666
|
RELAY_SHARE_PAGE: () => RELAY_SHARE_PAGE,
|
|
571
667
|
RELAY_SHARE_MAX_BYTES: () => RELAY_SHARE_MAX_BYTES,
|
|
572
668
|
RELAY_SHARE_DAYS: () => RELAY_SHARE_DAYS,
|
|
573
669
|
RELAY_SHARE_CHUNK_BYTES: () => RELAY_SHARE_CHUNK_BYTES,
|
|
670
|
+
RELAY_ROOM_PATH: () => RELAY_ROOM_PATH,
|
|
574
671
|
RELAY_PROOF: () => RELAY_PROOF,
|
|
575
672
|
RELAY_PONG: () => RELAY_PONG,
|
|
576
673
|
RELAY_PING_MS: () => RELAY_PING_MS,
|
|
@@ -578,20 +675,44 @@ __export(exports_relay_protocol, {
|
|
|
578
675
|
RELAY_PAIR_PATH: () => RELAY_PAIR_PATH,
|
|
579
676
|
RELAY_PAIR_PAGE: () => RELAY_PAIR_PAGE,
|
|
580
677
|
RELAY_ID: () => RELAY_ID,
|
|
678
|
+
RELAY_HUB_RATE: () => RELAY_HUB_RATE,
|
|
679
|
+
RELAY_HUB_PATH: () => RELAY_HUB_PATH,
|
|
680
|
+
RELAY_HUB_MAX_VALUE: () => RELAY_HUB_MAX_VALUE,
|
|
681
|
+
RELAY_HUB_MAX_STATE: () => RELAY_HUB_MAX_STATE,
|
|
682
|
+
RELAY_HUB_MAX_MEMBERS: () => RELAY_HUB_MAX_MEMBERS,
|
|
683
|
+
RELAY_HUB_MAX_KEYS: () => RELAY_HUB_MAX_KEYS,
|
|
684
|
+
RELAY_HUB_MAX_ASKS: () => RELAY_HUB_MAX_ASKS,
|
|
685
|
+
RELAY_HUB_IDLE_DAYS: () => RELAY_HUB_IDLE_DAYS,
|
|
686
|
+
RELAY_HUB_ASK_DAYS: () => RELAY_HUB_ASK_DAYS,
|
|
581
687
|
RELAY_HOST_PATH: () => RELAY_HOST_PATH,
|
|
688
|
+
RELAY_FRAME_PATH: () => RELAY_FRAME_PATH,
|
|
689
|
+
RELAY_FRAME_HEADER_CSP: () => RELAY_FRAME_HEADER_CSP,
|
|
690
|
+
RELAY_FRAME_CSP: () => RELAY_FRAME_CSP,
|
|
582
691
|
RELAY_DEFAULT_URL: () => RELAY_DEFAULT_URL,
|
|
583
|
-
|
|
692
|
+
RELAY_CONTENT_PATH: () => RELAY_CONTENT_PATH,
|
|
693
|
+
RELAY_CONTENT_MAX_BYTES: () => RELAY_CONTENT_MAX_BYTES,
|
|
694
|
+
RELAY_CONNECT_PATH: () => RELAY_CONNECT_PATH,
|
|
695
|
+
RELAY_BLOB_PATH: () => RELAY_BLOB_PATH,
|
|
696
|
+
RELAY_BLOB_MAX_DAYS: () => RELAY_BLOB_MAX_DAYS
|
|
584
697
|
});
|
|
585
|
-
var RELAY_DEFAULT_URL = "https://relay.cellbang.com", RELAY_HOST_PATH = "/v1/host/", RELAY_CONNECT_PATH = "/v1/connect/", RELAY_PAIR_PATH = "/pair", RELAY_SHARE_PATH = "/share", RELAY_PAIR_PAGE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Ta</title>
|
|
698
|
+
var RELAY_DEFAULT_URL = "https://relay.cellbang.com", RELAY_HOST_PATH = "/v1/host/", RELAY_CONNECT_PATH = "/v1/connect/", RELAY_PAIR_PATH = "/pair", RELAY_SHARE_PATH = "/share", RELAY_CONTENT_PATH = "/s", RELAY_FRAME_PATH = "/s/frame", RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'", RELAY_FRAME_HEADER_CSP, RELAY_VIEWER_HEADERS, RELAY_BLOB_PATH = "/v1/blob/", RELAY_PAIR_PAGE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Ta</title>
|
|
586
699
|
<body style="font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em">
|
|
587
700
|
<h1>Ta</h1><p>Open this link in the Ta app, or paste it there, to reach your Ta from this device.</p>
|
|
588
701
|
<p>打开 Ta 应用,粘贴这个链接,就能从这台设备连到你的 Ta。</p></body>`, RELAY_SHARE_PAGE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Ta</title>
|
|
589
702
|
<body style="font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em">
|
|
590
703
|
<h1>Ta</h1><p>Someone shared an extension of Ta. Scan the code in the Ta app, or paste this link in its Quick open, to open it.</p>
|
|
591
|
-
<p>有人分享了一个 Ta 扩展。在 Ta 应用里扫码,或把这个链接粘贴到“快捷打开”,就能打开它。</p></body>`, RELAY_SHARE_MAX_BYTES, RELAY_SHARE_CHUNK_BYTES, RELAY_SHARE_DAYS = 7, RELAY_ID, RelayCloseCode, RELAY_PING = "ping", RELAY_PONG = "pong", RELAY_PING_MS = 25000, RELAY_STALE_MS = 80000, RELAY_PROOF = "ta-relay ready";
|
|
704
|
+
<p>有人分享了一个 Ta 扩展。在 Ta 应用里扫码,或把这个链接粘贴到“快捷打开”,就能打开它。</p></body>`, RELAY_SHARE_MAX_BYTES, RELAY_SHARE_CHUNK_BYTES, RELAY_SHARE_DAYS = 7, RELAY_CONTENT_MAX_BYTES, RELAY_BLOB_MAX_DAYS = 30, RELAY_ID, RelayCloseCode, RELAY_PING = "ping", RELAY_PONG = "pong", RELAY_PING_MS = 25000, RELAY_STALE_MS = 80000, RELAY_PROOF = "ta-relay ready", RELAY_HUB_PATH = "/v1/hub/", RELAY_ROOM_PATH = "/r", RELAY_HUB_MAX_MEMBERS = 16, RELAY_HUB_MAX_VALUE, RELAY_HUB_MAX_KEYS = 512, RELAY_HUB_MAX_STATE, RELAY_HUB_MAX_ASKS = 20, RELAY_HUB_ASK_DAYS = 7, RELAY_HUB_IDLE_DAYS = 90, RELAY_HUB_RATE = 40;
|
|
592
705
|
var init_relay_protocol = __esm(() => {
|
|
706
|
+
RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
|
|
707
|
+
RELAY_VIEWER_HEADERS = {
|
|
708
|
+
"content-type": "text/html; charset=utf-8",
|
|
709
|
+
"cache-control": "no-cache",
|
|
710
|
+
"referrer-policy": "no-referrer",
|
|
711
|
+
"x-content-type-options": "nosniff"
|
|
712
|
+
};
|
|
593
713
|
RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
|
|
594
714
|
RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
|
|
715
|
+
RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
|
|
595
716
|
RELAY_ID = /^[A-Za-z0-9_-]{16,64}$/;
|
|
596
717
|
(function(RelayCloseCode2) {
|
|
597
718
|
RelayCloseCode2[RelayCloseCode2["HOST_OFFLINE"] = 4404] = "HOST_OFFLINE";
|
|
@@ -601,6 +722,678 @@ var init_relay_protocol = __esm(() => {
|
|
|
601
722
|
RelayCloseCode2[RelayCloseCode2["FULL"] = 4429] = "FULL";
|
|
602
723
|
RelayCloseCode2[RelayCloseCode2["TIMEOUT"] = 4408] = "TIMEOUT";
|
|
603
724
|
})(RelayCloseCode || (RelayCloseCode = {}));
|
|
725
|
+
RELAY_HUB_MAX_VALUE = 96 * 1024;
|
|
726
|
+
RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// ../../ta-packages/ta-relay/esm/common/relay-blobs.js
|
|
730
|
+
class RelayBlobs {
|
|
731
|
+
constructor(storage, now = Date.now) {
|
|
732
|
+
this.storage = storage;
|
|
733
|
+
this.now = now;
|
|
734
|
+
}
|
|
735
|
+
async handle(request) {
|
|
736
|
+
switch (request.method) {
|
|
737
|
+
case "OPTIONS":
|
|
738
|
+
return new Response(null, { status: 204, headers: READ_HEADERS });
|
|
739
|
+
case "GET":
|
|
740
|
+
return this.read(request);
|
|
741
|
+
case "PUT":
|
|
742
|
+
return this.write(request);
|
|
743
|
+
case "DELETE":
|
|
744
|
+
return this.remove(request);
|
|
745
|
+
default:
|
|
746
|
+
return RelayBlobs.answer(405, "Not allowed.");
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
async read(request) {
|
|
750
|
+
var _a, _b;
|
|
751
|
+
const meta = await this.meta();
|
|
752
|
+
if (!meta) {
|
|
753
|
+
return RelayBlobs.answer(404, "No copy.", READ_HEADERS);
|
|
754
|
+
}
|
|
755
|
+
const fails = (_a = await this.storage.get("fails")) !== null && _a !== undefined ? _a : { count: 0, since: 0 };
|
|
756
|
+
const now = this.now();
|
|
757
|
+
const recent = now - fails.since < FAIL_WINDOW_MS ? fails : { count: 0, since: now };
|
|
758
|
+
if (recent.count >= MAX_FAILS) {
|
|
759
|
+
return RelayBlobs.answer(429, "Too many tries.", READ_HEADERS);
|
|
760
|
+
}
|
|
761
|
+
if (await RelayBlobs.hash((_b = request.headers.get("x-ta-auth")) !== null && _b !== undefined ? _b : "") !== meta.authHash) {
|
|
762
|
+
await this.storage.put("fails", { count: recent.count + 1, since: recent.since });
|
|
763
|
+
return RelayBlobs.answer(403, "Refused.", READ_HEADERS);
|
|
764
|
+
}
|
|
765
|
+
const parts = [];
|
|
766
|
+
for (let index = 0;index < meta.chunks; index++) {
|
|
767
|
+
const part = await this.storage.get(`c${index}`);
|
|
768
|
+
if (!part) {
|
|
769
|
+
return RelayBlobs.answer(404, "No copy.", READ_HEADERS);
|
|
770
|
+
}
|
|
771
|
+
parts.push(new Uint8Array(part));
|
|
772
|
+
}
|
|
773
|
+
return new Response(RelayBytes.concat(...parts), {
|
|
774
|
+
headers: { ...READ_HEADERS, "content-type": "application/octet-stream", "cache-control": "no-store" }
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
async write(request) {
|
|
778
|
+
var _a, _b;
|
|
779
|
+
var _c;
|
|
780
|
+
const writeHash = await RelayBlobs.hash(RelayBlobs.bearer(request));
|
|
781
|
+
const before = await this.storage.get("meta");
|
|
782
|
+
if (before && before.writeHash !== writeHash && before.expiresAt > this.now()) {
|
|
783
|
+
return RelayBlobs.answer(403, "Another host keeps this copy.");
|
|
784
|
+
}
|
|
785
|
+
const authHash = (_c = request.headers.get("x-ta-auth-hash")) !== null && _c !== undefined ? _c : "";
|
|
786
|
+
const expiresAt = Number(request.headers.get("x-ta-expires"));
|
|
787
|
+
const now = this.now();
|
|
788
|
+
if (RelayBlobs.bearer(request).length < 32 || !/^[A-Za-z0-9_-]{43}$/.test(authHash) || !(expiresAt > now) || expiresAt > now + RELAY_BLOB_MAX_DAYS * DAY_MS + DAY_MS) {
|
|
789
|
+
return RelayBlobs.answer(400, "A token, the hash of what reads it and when it runs out are needed.");
|
|
790
|
+
}
|
|
791
|
+
const length = Number(request.headers.get("content-length"));
|
|
792
|
+
if (length > MAX_BYTES) {
|
|
793
|
+
return RelayBlobs.answer(413, "Too large.");
|
|
794
|
+
}
|
|
795
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
796
|
+
if (bytes.length === 0 || bytes.length > MAX_BYTES) {
|
|
797
|
+
return RelayBlobs.answer(bytes.length === 0 ? 400 : 413, bytes.length === 0 ? "Empty." : "Too large.");
|
|
798
|
+
}
|
|
799
|
+
await this.storage.deleteAll();
|
|
800
|
+
const chunks = Math.ceil(bytes.length / CHUNK_BYTES);
|
|
801
|
+
for (let index = 0;index < chunks; index++) {
|
|
802
|
+
await this.storage.put(`c${index}`, bytes.slice(index * CHUNK_BYTES, (index + 1) * CHUNK_BYTES));
|
|
803
|
+
}
|
|
804
|
+
await this.storage.put("meta", { writeHash, authHash, expiresAt, size: bytes.length, chunks });
|
|
805
|
+
await ((_b = (_a = this.storage).setAlarm) === null || _b === undefined ? undefined : _b.call(_a, expiresAt));
|
|
806
|
+
return RelayBlobs.answer(201, "Kept.");
|
|
807
|
+
}
|
|
808
|
+
async remove(request) {
|
|
809
|
+
const meta = await this.storage.get("meta");
|
|
810
|
+
if (meta && meta.writeHash !== await RelayBlobs.hash(RelayBlobs.bearer(request))) {
|
|
811
|
+
return RelayBlobs.answer(403, "Refused.");
|
|
812
|
+
}
|
|
813
|
+
await this.storage.deleteAll();
|
|
814
|
+
return RelayBlobs.answer(200, "Deleted.");
|
|
815
|
+
}
|
|
816
|
+
async meta() {
|
|
817
|
+
const meta = await this.storage.get("meta");
|
|
818
|
+
if (meta && meta.expiresAt <= this.now()) {
|
|
819
|
+
await this.storage.deleteAll();
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
return meta;
|
|
823
|
+
}
|
|
824
|
+
static bearer(request) {
|
|
825
|
+
var _a;
|
|
826
|
+
var _b, _c;
|
|
827
|
+
return (_c = (_a = /^Bearer (\S+)$/.exec((_b = request.headers.get("authorization")) !== null && _b !== undefined ? _b : "")) === null || _a === undefined ? undefined : _a[1]) !== null && _c !== undefined ? _c : "";
|
|
828
|
+
}
|
|
829
|
+
static async hash(text) {
|
|
830
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
831
|
+
return RelayBytes.toBase64(new Uint8Array(digest));
|
|
832
|
+
}
|
|
833
|
+
static answer(status, text, headers = {}) {
|
|
834
|
+
return new Response(`${text}
|
|
835
|
+
`, { status, headers: { ...headers, "content-type": "text/plain; charset=utf-8" } });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
var CHUNK_BYTES, MAX_BYTES, FAIL_WINDOW_MS, MAX_FAILS = 20, DAY_MS, READ_HEADERS, RelayBlobClient;
|
|
839
|
+
var init_relay_blobs = __esm(() => {
|
|
840
|
+
init_relay_bytes();
|
|
841
|
+
init_relay_protocol();
|
|
842
|
+
CHUNK_BYTES = 1024 * 1024;
|
|
843
|
+
MAX_BYTES = RELAY_CONTENT_MAX_BYTES + 64 * 1024;
|
|
844
|
+
FAIL_WINDOW_MS = 10 * 60 * 1000;
|
|
845
|
+
DAY_MS = 24 * 60 * 60 * 1000;
|
|
846
|
+
READ_HEADERS = { "access-control-allow-origin": "*", "access-control-allow-headers": "x-ta-auth", "access-control-allow-methods": "GET, OPTIONS" };
|
|
847
|
+
RelayBlobs.MAX_BYTES = MAX_BYTES;
|
|
848
|
+
(function(RelayBlobClient2) {
|
|
849
|
+
async function put(copy) {
|
|
850
|
+
const response = await fetch(`${copy.relay}${RELAY_BLOB_PATH}${copy.share}`, {
|
|
851
|
+
method: "PUT",
|
|
852
|
+
headers: {
|
|
853
|
+
authorization: `Bearer ${copy.token}`,
|
|
854
|
+
"x-ta-auth-hash": copy.authHash,
|
|
855
|
+
"x-ta-expires": String(copy.expiresAt),
|
|
856
|
+
"content-type": "application/octet-stream"
|
|
857
|
+
},
|
|
858
|
+
body: copy.bytes
|
|
859
|
+
});
|
|
860
|
+
if (!response.ok) {
|
|
861
|
+
throw new Error(`The relay did not keep the copy: ${response.status} ${(await response.text()).trim()}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
RelayBlobClient2.put = put;
|
|
865
|
+
async function remove(relay, share, token) {
|
|
866
|
+
await fetch(`${relay}${RELAY_BLOB_PATH}${share}`, { method: "DELETE", headers: { authorization: `Bearer ${token}` } });
|
|
867
|
+
}
|
|
868
|
+
RelayBlobClient2.remove = remove;
|
|
869
|
+
})(RelayBlobClient || (RelayBlobClient = {}));
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
// ../../ta-packages/ta-relay/esm/common/relay-identity.js
|
|
873
|
+
var encoder, decoder, subtle = () => globalThis.crypto.subtle, SIGN, BOX, SIGNATURE, RelayKeys, RelayIdentityUtil;
|
|
874
|
+
var init_relay_identity = __esm(() => {
|
|
875
|
+
init_relay_bytes();
|
|
876
|
+
encoder = new TextEncoder;
|
|
877
|
+
decoder = new TextDecoder;
|
|
878
|
+
SIGN = { name: "ECDSA", namedCurve: "P-256" };
|
|
879
|
+
BOX = { name: "ECDH", namedCurve: "P-256" };
|
|
880
|
+
SIGNATURE = { name: "ECDSA", hash: "SHA-256" };
|
|
881
|
+
(function(RelayKeys2) {
|
|
882
|
+
async function hkdf(key, salt, info) {
|
|
883
|
+
const secret = await subtle().importKey("raw", key, "HKDF", false, ["deriveBits"]);
|
|
884
|
+
const bits = await subtle().deriveBits({ name: "HKDF", hash: "SHA-256", salt, info: encoder.encode(info) }, secret, 256);
|
|
885
|
+
return new Uint8Array(bits);
|
|
886
|
+
}
|
|
887
|
+
RelayKeys2.hkdf = hkdf;
|
|
888
|
+
async function sha256(bytes) {
|
|
889
|
+
const data = typeof bytes === "string" ? encoder.encode(bytes) : bytes;
|
|
890
|
+
return new Uint8Array(await subtle().digest("SHA-256", data));
|
|
891
|
+
}
|
|
892
|
+
RelayKeys2.sha256 = sha256;
|
|
893
|
+
async function hash(text) {
|
|
894
|
+
return RelayBytes.toBase64(await sha256(text));
|
|
895
|
+
}
|
|
896
|
+
RelayKeys2.hash = hash;
|
|
897
|
+
async function hmac(key, text) {
|
|
898
|
+
const imported = await subtle().importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
899
|
+
return RelayBytes.toBase64(new Uint8Array(await subtle().sign("HMAC", imported, encoder.encode(text))));
|
|
900
|
+
}
|
|
901
|
+
RelayKeys2.hmac = hmac;
|
|
902
|
+
function aesKey(key) {
|
|
903
|
+
return subtle().importKey("raw", key, "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
904
|
+
}
|
|
905
|
+
RelayKeys2.aesKey = aesKey;
|
|
906
|
+
async function seal(key, text) {
|
|
907
|
+
const iv = RelayBytes.random(12);
|
|
908
|
+
const sealed = await subtle().encrypt({ name: "AES-GCM", iv }, key, encoder.encode(text));
|
|
909
|
+
return RelayBytes.toBase64(RelayBytes.concat(iv, new Uint8Array(sealed)));
|
|
910
|
+
}
|
|
911
|
+
RelayKeys2.seal = seal;
|
|
912
|
+
async function open(key, sealed) {
|
|
913
|
+
const bytes = RelayBytes.fromBase64(sealed);
|
|
914
|
+
const opened = await subtle().decrypt({ name: "AES-GCM", iv: bytes.subarray(0, 12) }, key, bytes.subarray(12));
|
|
915
|
+
return decoder.decode(opened);
|
|
916
|
+
}
|
|
917
|
+
RelayKeys2.open = open;
|
|
918
|
+
})(RelayKeys || (RelayKeys = {}));
|
|
919
|
+
(function(RelayIdentityUtil2) {
|
|
920
|
+
async function create(name, now = Date.now()) {
|
|
921
|
+
const sign2 = await subtle().generateKey(SIGN, true, ["sign", "verify"]);
|
|
922
|
+
const box = await subtle().generateKey(BOX, true, ["deriveBits"]);
|
|
923
|
+
const raw = async (key) => RelayBytes.toBase64(new Uint8Array(await subtle().exportKey("raw", key)));
|
|
924
|
+
const [signPublic, boxPublic] = await Promise.all([raw(sign2.publicKey), raw(box.publicKey)]);
|
|
925
|
+
return {
|
|
926
|
+
id: await id(signPublic, boxPublic),
|
|
927
|
+
name,
|
|
928
|
+
sign: signPublic,
|
|
929
|
+
box: boxPublic,
|
|
930
|
+
signKey: await subtle().exportKey("jwk", sign2.privateKey),
|
|
931
|
+
boxKey: await subtle().exportKey("jwk", box.privateKey),
|
|
932
|
+
createdAt: now
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
RelayIdentityUtil2.create = create;
|
|
936
|
+
async function id(sign2, box) {
|
|
937
|
+
const digest = await RelayKeys.sha256(RelayBytes.concat(RelayBytes.fromBase64(sign2), RelayBytes.fromBase64(box)));
|
|
938
|
+
return RelayBytes.toBase64(digest.subarray(0, 16));
|
|
939
|
+
}
|
|
940
|
+
RelayIdentityUtil2.id = id;
|
|
941
|
+
async function check(identity) {
|
|
942
|
+
try {
|
|
943
|
+
if (identity.id !== await id(identity.sign, identity.box)) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
await Promise.all([importSign(identity.sign), importBox(identity.box)]);
|
|
947
|
+
return true;
|
|
948
|
+
} catch (_a) {
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
RelayIdentityUtil2.check = check;
|
|
953
|
+
function publicOf(identity) {
|
|
954
|
+
return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
|
|
955
|
+
}
|
|
956
|
+
RelayIdentityUtil2.publicOf = publicOf;
|
|
957
|
+
async function sign(identity, text) {
|
|
958
|
+
const key = await subtle().importKey("jwk", identity.signKey, SIGN, false, ["sign"]);
|
|
959
|
+
return RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
|
|
960
|
+
}
|
|
961
|
+
RelayIdentityUtil2.sign = sign;
|
|
962
|
+
async function verify(signPublic, text, signature) {
|
|
963
|
+
try {
|
|
964
|
+
return await subtle().verify(SIGNATURE, await importSign(signPublic), RelayBytes.fromBase64(signature), encoder.encode(text));
|
|
965
|
+
} catch (_a) {
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
RelayIdentityUtil2.verify = verify;
|
|
970
|
+
async function agree(identity, otherBox, salt, info) {
|
|
971
|
+
const own = await subtle().importKey("jwk", identity.boxKey, BOX, false, ["deriveBits"]);
|
|
972
|
+
const shared = await subtle().deriveBits({ name: "ECDH", public: await importBox(otherBox) }, own, 256);
|
|
973
|
+
return RelayKeys.hkdf(new Uint8Array(shared), encoder.encode(salt), info);
|
|
974
|
+
}
|
|
975
|
+
RelayIdentityUtil2.agree = agree;
|
|
976
|
+
function importSign(raw) {
|
|
977
|
+
return subtle().importKey("raw", RelayBytes.fromBase64(raw), SIGN, false, ["verify"]);
|
|
978
|
+
}
|
|
979
|
+
function importBox(raw) {
|
|
980
|
+
return subtle().importKey("raw", RelayBytes.fromBase64(raw), BOX, false, []);
|
|
981
|
+
}
|
|
982
|
+
})(RelayIdentityUtil || (RelayIdentityUtil = {}));
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
// ../../ta-packages/ta-relay/esm/common/relay-hub.js
|
|
986
|
+
class RelayHub {
|
|
987
|
+
constructor(storage, sockets, now = Date.now) {
|
|
988
|
+
this.storage = storage;
|
|
989
|
+
this.sockets = sockets;
|
|
990
|
+
this.now = now;
|
|
991
|
+
this.rates = new Map;
|
|
992
|
+
}
|
|
993
|
+
async receive(socket, text) {
|
|
994
|
+
if (text === RELAY_PING) {
|
|
995
|
+
socket.send(RELAY_PONG);
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
let request;
|
|
999
|
+
try {
|
|
1000
|
+
request = JSON.parse(text);
|
|
1001
|
+
} catch (_a) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (!request || typeof request !== "object") {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
if (!this.allowed(socket)) {
|
|
1008
|
+
this.send(socket, { t: "error", code: "rate", message: "Too many messages." });
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
const who = socket.who;
|
|
1012
|
+
if (!who) {
|
|
1013
|
+
await this.first(socket, request);
|
|
1014
|
+
} else if ("member" in who) {
|
|
1015
|
+
await this.fromMember(socket, who.member, request);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
closed(socket) {
|
|
1019
|
+
this.rates.delete(socket.key);
|
|
1020
|
+
const who = socket.who;
|
|
1021
|
+
if (who && "member" in who && !this.online(who.member, socket)) {
|
|
1022
|
+
this.broadcast({ t: "presence", member: who.member, online: false });
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
async alarm() {
|
|
1026
|
+
var _a, _b;
|
|
1027
|
+
const meta = await this.storage.get("meta");
|
|
1028
|
+
if (meta && this.now() - meta.touched < RELAY_HUB_IDLE_DAYS * DAY_MS2) {
|
|
1029
|
+
await ((_b = (_a = this.storage).setAlarm) === null || _b === undefined ? undefined : _b.call(_a, meta.touched + RELAY_HUB_IDLE_DAYS * DAY_MS2));
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
await this.storage.deleteAll();
|
|
1033
|
+
}
|
|
1034
|
+
async first(socket, request) {
|
|
1035
|
+
switch (request.t) {
|
|
1036
|
+
case "create":
|
|
1037
|
+
return this.create(socket, request.member, request.token);
|
|
1038
|
+
case "auth":
|
|
1039
|
+
return this.auth(socket, request.member, request.token);
|
|
1040
|
+
case "ask":
|
|
1041
|
+
return this.ask(socket, request);
|
|
1042
|
+
case "wait":
|
|
1043
|
+
return this.wait(socket, request.ask, request.token);
|
|
1044
|
+
default:
|
|
1045
|
+
this.refuse(socket, "invalid", "Say who you are first.", RelayHubCloseCode.INVALID);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
async create(socket, member, token) {
|
|
1049
|
+
var _a, _b;
|
|
1050
|
+
if (!RelayHub.id(member) || !RelayHub.token(token)) {
|
|
1051
|
+
this.refuse(socket, "invalid", "A member and a token are needed.", RelayHubCloseCode.INVALID);
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (await this.storage.get("meta")) {
|
|
1055
|
+
this.refuse(socket, "exists", "This room is made already.", RelayHubCloseCode.REFUSED);
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
const now = this.now();
|
|
1059
|
+
await this.storage.put("meta", { owner: member, createdAt: now, touched: now, keys: 0, size: 0 });
|
|
1060
|
+
await this.storage.put("members", { [member]: { hash: await RelayKeys.hash(token), at: now } });
|
|
1061
|
+
await ((_b = (_a = this.storage).setAlarm) === null || _b === undefined ? undefined : _b.call(_a, now + RELAY_HUB_IDLE_DAYS * DAY_MS2));
|
|
1062
|
+
await this.auth(socket, member, token);
|
|
1063
|
+
}
|
|
1064
|
+
async auth(socket, member, token) {
|
|
1065
|
+
var _a;
|
|
1066
|
+
var _b;
|
|
1067
|
+
const meta = await this.storage.get("meta");
|
|
1068
|
+
if (!meta) {
|
|
1069
|
+
this.refuse(socket, "gone", "No such room.", RelayHubCloseCode.GONE);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
const members = (_b = await this.storage.get("members")) !== null && _b !== undefined ? _b : {};
|
|
1073
|
+
if (!RelayHub.id(member) || ((_a = members[member]) === null || _a === undefined ? undefined : _a.hash) !== await RelayKeys.hash(String(token))) {
|
|
1074
|
+
this.refuse(socket, "auth", "Not a member of this room.", RelayHubCloseCode.REFUSED);
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
const wasOnline = this.online(member, socket);
|
|
1078
|
+
socket.who = { member };
|
|
1079
|
+
await this.touch(meta);
|
|
1080
|
+
const owner = member === meta.owner;
|
|
1081
|
+
const asks = owner ? await this.pendingAsks() : undefined;
|
|
1082
|
+
const roster = await this.storage.get("roster");
|
|
1083
|
+
const online = [...new Set(this.members().map((other) => other.who.member))];
|
|
1084
|
+
this.send(socket, { t: "welcome", owner: meta.owner, online, ...roster ? { roster } : {}, ...asks ? { asks } : {} });
|
|
1085
|
+
let batch = [];
|
|
1086
|
+
let size = 0;
|
|
1087
|
+
for (const entry of (await this.storage.list({ prefix: STATE })).values()) {
|
|
1088
|
+
if (size + entry.d.length > ENTRIES_BYTES && batch.length) {
|
|
1089
|
+
this.send(socket, { t: "entries", entries: batch });
|
|
1090
|
+
batch = [];
|
|
1091
|
+
size = 0;
|
|
1092
|
+
}
|
|
1093
|
+
batch.push(entry);
|
|
1094
|
+
size += entry.d.length;
|
|
1095
|
+
}
|
|
1096
|
+
if (batch.length) {
|
|
1097
|
+
this.send(socket, { t: "entries", entries: batch });
|
|
1098
|
+
}
|
|
1099
|
+
this.send(socket, { t: "synced" });
|
|
1100
|
+
if (!wasOnline) {
|
|
1101
|
+
this.broadcast({ t: "presence", member, online: true }, socket);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
async ask(socket, request) {
|
|
1105
|
+
var _a;
|
|
1106
|
+
const meta = await this.storage.get("meta");
|
|
1107
|
+
if (!meta) {
|
|
1108
|
+
this.refuse(socket, "gone", "No such room.", RelayHubCloseCode.GONE);
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
if (!RelayHub.id(request.ask) || !RelayHub.token(request.token) || typeof request.d !== "string" || request.d.length > RELAY_HUB_MAX_VALUE) {
|
|
1112
|
+
this.refuse(socket, "invalid", "An ask needs an id, a token and what it says.", RelayHubCloseCode.INVALID);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
const now = this.now();
|
|
1116
|
+
if (!meta.invite || meta.invite.expiresAt <= now || meta.invite.hash !== await RelayKeys.hash(String(request.proof))) {
|
|
1117
|
+
this.refuse(socket, "invite", "This invitation no longer works.", RelayHubCloseCode.REFUSED);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const asks = await this.asks();
|
|
1121
|
+
const members = (_a = await this.storage.get("members")) !== null && _a !== undefined ? _a : {};
|
|
1122
|
+
if (asks[request.ask] || members[request.ask]) {
|
|
1123
|
+
this.refuse(socket, "exists", "Asked already.", RelayHubCloseCode.REFUSED);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (Object.keys(asks).length >= RELAY_HUB_MAX_ASKS) {
|
|
1127
|
+
this.refuse(socket, "full", "Too many ask to join this room now.", RelayHubCloseCode.REFUSED);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
asks[request.ask] = { hash: await RelayKeys.hash(request.token), d: request.d, at: now };
|
|
1131
|
+
await this.storage.put("asks", asks);
|
|
1132
|
+
socket.who = { ask: request.ask };
|
|
1133
|
+
this.send(socket, { t: "waiting" });
|
|
1134
|
+
for (const owner of this.members(meta.owner)) {
|
|
1135
|
+
this.send(owner, { t: "asked", ask: { ask: request.ask, d: request.d, at: now } });
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
async wait(socket, ask, token) {
|
|
1139
|
+
var _a;
|
|
1140
|
+
var _b;
|
|
1141
|
+
const members = (_b = await this.storage.get("members")) !== null && _b !== undefined ? _b : {};
|
|
1142
|
+
const asks = await this.asks();
|
|
1143
|
+
const pending = asks[ask];
|
|
1144
|
+
const hash = await RelayKeys.hash(String(token));
|
|
1145
|
+
if (!pending || pending.hash !== hash) {
|
|
1146
|
+
if (((_a = members[ask]) === null || _a === undefined ? undefined : _a.hash) === hash) {
|
|
1147
|
+
this.refuse(socket, "exists", "A member already.", RelayHubCloseCode.ANSWERED);
|
|
1148
|
+
} else {
|
|
1149
|
+
this.refuse(socket, pending ? "auth" : "gone", "No such ask.", pending ? RelayHubCloseCode.REFUSED : RelayHubCloseCode.GONE);
|
|
1150
|
+
}
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
if (pending.answer !== undefined || pending.refused) {
|
|
1154
|
+
await this.answered(socket, ask, pending);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
socket.who = { ask };
|
|
1158
|
+
this.send(socket, { t: "waiting" });
|
|
1159
|
+
}
|
|
1160
|
+
async answered(socket, ask, pending) {
|
|
1161
|
+
this.send(socket, pending.answer !== undefined ? { t: "admitted", answer: pending.answer } : { t: "refused" });
|
|
1162
|
+
const asks = await this.asks();
|
|
1163
|
+
delete asks[ask];
|
|
1164
|
+
await this.storage.put("asks", asks);
|
|
1165
|
+
socket.close(RelayHubCloseCode.ANSWERED, "Answered.");
|
|
1166
|
+
}
|
|
1167
|
+
async fromMember(socket, member, request) {
|
|
1168
|
+
var _a;
|
|
1169
|
+
const meta = await this.storage.get("meta");
|
|
1170
|
+
const members = (_a = await this.storage.get("members")) !== null && _a !== undefined ? _a : {};
|
|
1171
|
+
if (!meta || !members[member]) {
|
|
1172
|
+
this.refuse(socket, "gone", "Not in this room any more.", RelayHubCloseCode.REMOVED);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
const owner = member === meta.owner;
|
|
1176
|
+
switch (request.t) {
|
|
1177
|
+
case "send":
|
|
1178
|
+
return this.forward(socket, member, request);
|
|
1179
|
+
case "set":
|
|
1180
|
+
return this.set(socket, member, meta, request);
|
|
1181
|
+
case "leave":
|
|
1182
|
+
if (owner) {
|
|
1183
|
+
return this.closeRoom();
|
|
1184
|
+
}
|
|
1185
|
+
delete members[member];
|
|
1186
|
+
await this.storage.put("members", members);
|
|
1187
|
+
for (const other of this.members(member)) {
|
|
1188
|
+
other.close(RelayHubCloseCode.REMOVED, "Left the room.");
|
|
1189
|
+
}
|
|
1190
|
+
this.broadcast({ t: "left", member });
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
if (!owner) {
|
|
1194
|
+
this.send(socket, { t: "error", code: "owner", message: "Only the owner does that." });
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
switch (request.t) {
|
|
1198
|
+
case "invite":
|
|
1199
|
+
if (!/^[A-Za-z0-9_-]{43}$/.test(String(request.hash)) || !(request.expiresAt > this.now())) {
|
|
1200
|
+
this.send(socket, { t: "error", code: "invalid", message: "An invitation needs a hash and a time." });
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
meta.invite = { hash: request.hash, expiresAt: Math.min(request.expiresAt, this.now() + 30 * DAY_MS2) };
|
|
1204
|
+
await this.storage.put("meta", meta);
|
|
1205
|
+
return;
|
|
1206
|
+
case "admit":
|
|
1207
|
+
return this.admit(socket, members, request);
|
|
1208
|
+
case "refuse": {
|
|
1209
|
+
const asks = await this.asks();
|
|
1210
|
+
if (asks[request.ask]) {
|
|
1211
|
+
asks[request.ask] = { ...asks[request.ask], refused: true };
|
|
1212
|
+
await this.storage.put("asks", asks);
|
|
1213
|
+
const waiting = this.sockets().find((other) => other.who && ("ask" in other.who) && other.who.ask === request.ask);
|
|
1214
|
+
if (waiting) {
|
|
1215
|
+
await this.answered(waiting, request.ask, asks[request.ask]);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
case "roster":
|
|
1221
|
+
return this.setRoster(socket, request.roster);
|
|
1222
|
+
case "remove": {
|
|
1223
|
+
if (request.member === member || !members[request.member]) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
delete members[request.member];
|
|
1227
|
+
await this.storage.put("members", members);
|
|
1228
|
+
for (const other of this.members(request.member)) {
|
|
1229
|
+
this.refuse(other, "auth", "Removed by the owner.", RelayHubCloseCode.REMOVED);
|
|
1230
|
+
}
|
|
1231
|
+
await this.setRoster(socket, request.roster);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
case "close":
|
|
1235
|
+
return this.closeRoom();
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
forward(socket, member, request) {
|
|
1239
|
+
if (typeof request.d !== "string" || request.d.length > RELAY_HUB_MAX_VALUE) {
|
|
1240
|
+
this.send(socket, { t: "error", code: "large", message: "A message is too large." });
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
const event = { t: "msg", from: member, d: request.d };
|
|
1244
|
+
const targets = typeof request.to === "string" ? this.members(request.to) : this.members().filter((other) => other !== socket && other.key !== socket.key);
|
|
1245
|
+
for (const target of targets) {
|
|
1246
|
+
this.send(target, event);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
async set(socket, member, meta, request) {
|
|
1250
|
+
var _a, _b;
|
|
1251
|
+
const id = Number(request.id);
|
|
1252
|
+
const done = (ok, v, error) => this.send(socket, { t: "done", id, ok, v, ...error ? { error } : {} });
|
|
1253
|
+
if (typeof request.k !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(request.k) || typeof request.d !== "string") {
|
|
1254
|
+
done(false, 0, "invalid");
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
if (request.d.length > RELAY_HUB_MAX_VALUE) {
|
|
1258
|
+
done(false, 0, "large");
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
const key = STATE + request.k;
|
|
1262
|
+
const before = await this.storage.get(key);
|
|
1263
|
+
const version = (_a = before === null || before === undefined ? undefined : before.v) !== null && _a !== undefined ? _a : 0;
|
|
1264
|
+
if (request.v !== undefined && request.v !== version) {
|
|
1265
|
+
done(false, version);
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
const keys = meta.keys + (before ? 0 : 1);
|
|
1269
|
+
const size = meta.size - ((_b = before === null || before === undefined ? undefined : before.d.length) !== null && _b !== undefined ? _b : 0) + request.d.length;
|
|
1270
|
+
if (keys > RELAY_HUB_MAX_KEYS || size > RELAY_HUB_MAX_STATE) {
|
|
1271
|
+
done(false, version, "limit");
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
const entry = { k: request.k, v: version + 1, d: request.d, by: member };
|
|
1275
|
+
await this.storage.put(key, entry);
|
|
1276
|
+
meta.keys = keys;
|
|
1277
|
+
meta.size = size;
|
|
1278
|
+
await this.touch(meta, true);
|
|
1279
|
+
done(true, entry.v);
|
|
1280
|
+
this.broadcast({ t: "state", entry }, socket);
|
|
1281
|
+
}
|
|
1282
|
+
async admit(socket, members, request) {
|
|
1283
|
+
const asks = await this.asks();
|
|
1284
|
+
const pending = asks[request.ask];
|
|
1285
|
+
if (!pending || pending.answer !== undefined || pending.refused || typeof request.answer !== "string" || request.answer.length > RELAY_HUB_MAX_VALUE) {
|
|
1286
|
+
this.send(socket, { t: "error", code: "gone", message: "No such ask." });
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
if (Object.keys(members).length >= RELAY_HUB_MAX_MEMBERS) {
|
|
1290
|
+
this.send(socket, { t: "error", code: "full", message: "The room is full." });
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
members[request.ask] = { hash: pending.hash, at: this.now() };
|
|
1294
|
+
await this.storage.put("members", members);
|
|
1295
|
+
asks[request.ask] = { ...pending, answer: request.answer };
|
|
1296
|
+
await this.storage.put("asks", asks);
|
|
1297
|
+
await this.setRoster(socket, request.roster);
|
|
1298
|
+
const waiting = this.sockets().find((other) => other.who && ("ask" in other.who) && other.who.ask === request.ask);
|
|
1299
|
+
if (waiting) {
|
|
1300
|
+
await this.answered(waiting, request.ask, asks[request.ask]);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
async setRoster(socket, roster) {
|
|
1304
|
+
var _a;
|
|
1305
|
+
const before = await this.storage.get("roster");
|
|
1306
|
+
if (!roster || typeof roster.d !== "string" || roster.d.length > RELAY_HUB_MAX_VALUE || !(roster.v > ((_a = before === null || before === undefined ? undefined : before.v) !== null && _a !== undefined ? _a : 0))) {
|
|
1307
|
+
this.send(socket, { t: "error", code: "invalid", message: "A roster needs a newer version." });
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
await this.storage.put("roster", { v: roster.v, d: roster.d });
|
|
1311
|
+
this.broadcast({ t: "roster", roster: { v: roster.v, d: roster.d } });
|
|
1312
|
+
}
|
|
1313
|
+
async closeRoom() {
|
|
1314
|
+
await this.storage.deleteAll();
|
|
1315
|
+
for (const socket of this.sockets()) {
|
|
1316
|
+
this.refuse(socket, "gone", "The room was closed.", RelayHubCloseCode.REMOVED);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
async asks() {
|
|
1320
|
+
var _a;
|
|
1321
|
+
const asks = (_a = await this.storage.get("asks")) !== null && _a !== undefined ? _a : {};
|
|
1322
|
+
const since = this.now() - RELAY_HUB_ASK_DAYS * DAY_MS2;
|
|
1323
|
+
for (const [id, ask] of Object.entries(asks)) {
|
|
1324
|
+
if (ask.at < since) {
|
|
1325
|
+
delete asks[id];
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return asks;
|
|
1329
|
+
}
|
|
1330
|
+
async pendingAsks() {
|
|
1331
|
+
return Object.entries(await this.asks()).filter(([, ask]) => ask.answer === undefined && !ask.refused).map(([ask, { d, at }]) => ({ ask, d, at }));
|
|
1332
|
+
}
|
|
1333
|
+
async touch(meta, write = false) {
|
|
1334
|
+
var _a, _b;
|
|
1335
|
+
const now = this.now();
|
|
1336
|
+
if (now - meta.touched > TOUCH_MS) {
|
|
1337
|
+
meta.touched = now;
|
|
1338
|
+
write = true;
|
|
1339
|
+
await ((_b = (_a = this.storage).setAlarm) === null || _b === undefined ? undefined : _b.call(_a, now + RELAY_HUB_IDLE_DAYS * DAY_MS2));
|
|
1340
|
+
}
|
|
1341
|
+
if (write) {
|
|
1342
|
+
await this.storage.put("meta", meta);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
members(member) {
|
|
1346
|
+
return this.sockets().filter((socket) => !!socket.who && ("member" in socket.who) && (member === undefined || socket.who.member === member));
|
|
1347
|
+
}
|
|
1348
|
+
online(member, except) {
|
|
1349
|
+
return this.members(member).some((socket) => socket.key !== except.key);
|
|
1350
|
+
}
|
|
1351
|
+
broadcast(event, except) {
|
|
1352
|
+
const text = JSON.stringify(event);
|
|
1353
|
+
for (const socket of this.members()) {
|
|
1354
|
+
if (socket.key !== (except === null || except === undefined ? undefined : except.key)) {
|
|
1355
|
+
socket.send(text);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
send(socket, event) {
|
|
1360
|
+
socket.send(JSON.stringify(event));
|
|
1361
|
+
}
|
|
1362
|
+
refuse(socket, code, message, close) {
|
|
1363
|
+
this.send(socket, { t: "error", code, message });
|
|
1364
|
+
socket.close(close, message);
|
|
1365
|
+
}
|
|
1366
|
+
allowed(socket) {
|
|
1367
|
+
const second = Math.floor(this.now() / 1000);
|
|
1368
|
+
const rate = this.rates.get(socket.key);
|
|
1369
|
+
if (!rate || rate.second !== second) {
|
|
1370
|
+
this.rates.set(socket.key, { second, count: 1 });
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
rate.count++;
|
|
1374
|
+
return rate.count <= RELAY_HUB_RATE;
|
|
1375
|
+
}
|
|
1376
|
+
static id(id) {
|
|
1377
|
+
return typeof id === "string" && RELAY_ID.test(id);
|
|
1378
|
+
}
|
|
1379
|
+
static token(token) {
|
|
1380
|
+
return typeof token === "string" && token.length >= 32 && token.length <= 128;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
var RelayHubCloseCode, DAY_MS2, TOUCH_MS, ENTRIES_BYTES, STATE = "s:";
|
|
1384
|
+
var init_relay_hub = __esm(() => {
|
|
1385
|
+
init_relay_identity();
|
|
1386
|
+
init_relay_protocol();
|
|
1387
|
+
(function(RelayHubCloseCode2) {
|
|
1388
|
+
RelayHubCloseCode2[RelayHubCloseCode2["REFUSED"] = 4401] = "REFUSED";
|
|
1389
|
+
RelayHubCloseCode2[RelayHubCloseCode2["GONE"] = 4404] = "GONE";
|
|
1390
|
+
RelayHubCloseCode2[RelayHubCloseCode2["REMOVED"] = 4410] = "REMOVED";
|
|
1391
|
+
RelayHubCloseCode2[RelayHubCloseCode2["ANSWERED"] = 4411] = "ANSWERED";
|
|
1392
|
+
RelayHubCloseCode2[RelayHubCloseCode2["INVALID"] = 4400] = "INVALID";
|
|
1393
|
+
})(RelayHubCloseCode || (RelayHubCloseCode = {}));
|
|
1394
|
+
DAY_MS2 = 24 * 60 * 60 * 1000;
|
|
1395
|
+
TOUCH_MS = 60 * 60 * 1000;
|
|
1396
|
+
ENTRIES_BYTES = 512 * 1024;
|
|
604
1397
|
});
|
|
605
1398
|
|
|
606
1399
|
// ../../ta-packages/ta-relay/esm/common/relay-room.js
|
|
@@ -669,6 +1462,40 @@ var init_relay_room = __esm(() => {
|
|
|
669
1462
|
init_relay_protocol();
|
|
670
1463
|
});
|
|
671
1464
|
|
|
1465
|
+
// ../../ta-packages/ta-relay/esm/node/relay-viewer.js
|
|
1466
|
+
import { fileURLToPath as __cellFileURLToPath3 } from "node:url";
|
|
1467
|
+
import { dirname as __cellDirname3 } from "node:path";
|
|
1468
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
1469
|
+
import { join as join5 } from "node:path";
|
|
1470
|
+
var __filename4, __dirname4, RelayViewer;
|
|
1471
|
+
var init_relay_viewer = __esm(() => {
|
|
1472
|
+
__filename4 = __cellFileURLToPath3(import.meta.url);
|
|
1473
|
+
__dirname4 = __cellDirname3(__filename4);
|
|
1474
|
+
(function(RelayViewer2) {
|
|
1475
|
+
let pages;
|
|
1476
|
+
function read() {
|
|
1477
|
+
if (!pages) {
|
|
1478
|
+
const dir = join5(__dirname4, "../../viewer");
|
|
1479
|
+
const file = (name) => readFileSync5(join5(dir, name), "utf8");
|
|
1480
|
+
pages = { page: file("page.html"), frame: file("frame.html"), room: file("room.html") };
|
|
1481
|
+
}
|
|
1482
|
+
return pages;
|
|
1483
|
+
}
|
|
1484
|
+
function room() {
|
|
1485
|
+
return read().room;
|
|
1486
|
+
}
|
|
1487
|
+
RelayViewer2.room = room;
|
|
1488
|
+
function page() {
|
|
1489
|
+
return read().page;
|
|
1490
|
+
}
|
|
1491
|
+
RelayViewer2.page = page;
|
|
1492
|
+
function frame() {
|
|
1493
|
+
return read().frame;
|
|
1494
|
+
}
|
|
1495
|
+
RelayViewer2.frame = frame;
|
|
1496
|
+
})(RelayViewer || (RelayViewer = {}));
|
|
1497
|
+
});
|
|
1498
|
+
|
|
672
1499
|
// ../../ta-packages/ta-relay/esm/node/relay-server.js
|
|
673
1500
|
var exports_relay_server = {};
|
|
674
1501
|
__export(exports_relay_server, {
|
|
@@ -677,15 +1504,96 @@ __export(exports_relay_server, {
|
|
|
677
1504
|
import { createHash as createHash2, randomBytes, timingSafeEqual } from "node:crypto";
|
|
678
1505
|
import { createServer as createServer2 } from "node:http";
|
|
679
1506
|
|
|
1507
|
+
class MemoryBlobStorage {
|
|
1508
|
+
constructor() {
|
|
1509
|
+
this.values = new Map;
|
|
1510
|
+
}
|
|
1511
|
+
async get(key) {
|
|
1512
|
+
return this.values.get(key);
|
|
1513
|
+
}
|
|
1514
|
+
async put(key, value) {
|
|
1515
|
+
this.values.set(key, value);
|
|
1516
|
+
}
|
|
1517
|
+
async deleteAll() {
|
|
1518
|
+
this.values.clear();
|
|
1519
|
+
clearTimeout(this.timer);
|
|
1520
|
+
}
|
|
1521
|
+
get empty() {
|
|
1522
|
+
return this.values.size === 0;
|
|
1523
|
+
}
|
|
1524
|
+
async setAlarm(at) {
|
|
1525
|
+
var _a, _b;
|
|
1526
|
+
clearTimeout(this.timer);
|
|
1527
|
+
this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
|
|
1528
|
+
(_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
class MemoryHubStorage {
|
|
1533
|
+
constructor() {
|
|
1534
|
+
this.values = new Map;
|
|
1535
|
+
}
|
|
1536
|
+
async get(key) {
|
|
1537
|
+
const value = this.values.get(key);
|
|
1538
|
+
return value === undefined ? undefined : structuredClone(value);
|
|
1539
|
+
}
|
|
1540
|
+
async put(key, value) {
|
|
1541
|
+
this.values.set(key, structuredClone(value));
|
|
1542
|
+
}
|
|
1543
|
+
async delete(key) {
|
|
1544
|
+
return this.values.delete(key);
|
|
1545
|
+
}
|
|
1546
|
+
async list(options) {
|
|
1547
|
+
const found = new Map;
|
|
1548
|
+
for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1549
|
+
if (key.startsWith(options.prefix)) {
|
|
1550
|
+
found.set(key, structuredClone(value));
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
return found;
|
|
1554
|
+
}
|
|
1555
|
+
async deleteAll() {
|
|
1556
|
+
this.values.clear();
|
|
1557
|
+
}
|
|
1558
|
+
get empty() {
|
|
1559
|
+
return this.values.size === 0;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
680
1563
|
class RelayServer {
|
|
681
1564
|
constructor(options = {}) {
|
|
682
1565
|
this.options = options;
|
|
683
1566
|
this.rooms = new Map;
|
|
1567
|
+
this.blobs = new Map;
|
|
1568
|
+
this.hubs = new Map;
|
|
684
1569
|
}
|
|
685
1570
|
listen() {
|
|
686
1571
|
const server = createServer2((request, response) => {
|
|
687
1572
|
var _a;
|
|
688
1573
|
const path = ((_a = request.url) !== null && _a !== undefined ? _a : "/").split(/[?#]/)[0];
|
|
1574
|
+
if (path.startsWith(RELAY_BLOB_PATH)) {
|
|
1575
|
+
this.blob(path.slice(RELAY_BLOB_PATH.length), request, response).catch(() => {
|
|
1576
|
+
if (!response.headersSent) {
|
|
1577
|
+
response.writeHead(400);
|
|
1578
|
+
}
|
|
1579
|
+
response.end();
|
|
1580
|
+
});
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
if (path === RELAY_ROOM_PATH) {
|
|
1584
|
+
response.writeHead(200, { ...RELAY_VIEWER_HEADERS, "x-frame-options": "DENY" });
|
|
1585
|
+
response.end(RelayViewer.room());
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
if (path === RELAY_CONTENT_PATH || path === RELAY_FRAME_PATH) {
|
|
1589
|
+
const frame = path === RELAY_FRAME_PATH;
|
|
1590
|
+
response.writeHead(200, {
|
|
1591
|
+
...RELAY_VIEWER_HEADERS,
|
|
1592
|
+
...frame ? { "content-security-policy": RELAY_FRAME_HEADER_CSP } : { "x-frame-options": "DENY" }
|
|
1593
|
+
});
|
|
1594
|
+
response.end(frame ? RelayViewer.frame() : RelayViewer.page());
|
|
1595
|
+
return;
|
|
1596
|
+
}
|
|
689
1597
|
const page = path === RELAY_PAIR_PATH ? RELAY_PAIR_PAGE : path === RELAY_SHARE_PATH ? RELAY_SHARE_PAGE : undefined;
|
|
690
1598
|
response.writeHead(200, { "content-type": page ? "text/html; charset=utf-8" : "text/plain" });
|
|
691
1599
|
response.end(page !== null && page !== undefined ? page : `Ta relay
|
|
@@ -704,6 +1612,12 @@ class RelayServer {
|
|
|
704
1612
|
}
|
|
705
1613
|
close() {
|
|
706
1614
|
var _a;
|
|
1615
|
+
for (const { sockets } of this.hubs.values()) {
|
|
1616
|
+
for (const connection of sockets.keys()) {
|
|
1617
|
+
connection.close(1001, "The relay is stopping.");
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
this.hubs.clear();
|
|
707
1621
|
for (const room of this.rooms.values()) {
|
|
708
1622
|
(_a = room.host) === null || _a === undefined || _a.close(1001, "The relay is stopping.");
|
|
709
1623
|
for (const client of room.clients.values()) {
|
|
@@ -713,20 +1627,89 @@ class RelayServer {
|
|
|
713
1627
|
this.rooms.clear();
|
|
714
1628
|
return new Promise((resolve) => this.server ? this.server.close(() => resolve()) : resolve());
|
|
715
1629
|
}
|
|
716
|
-
|
|
717
|
-
var _a
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
if ("status" in checked) {
|
|
721
|
-
WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
1630
|
+
async blob(id, request, response) {
|
|
1631
|
+
var _a;
|
|
1632
|
+
if (!RELAY_ID.test(id)) {
|
|
1633
|
+
response.writeHead(404).end();
|
|
722
1634
|
return;
|
|
723
1635
|
}
|
|
724
|
-
const
|
|
725
|
-
if (!
|
|
726
|
-
|
|
1636
|
+
const read = await RelayServer.body(request, RelayBlobs.MAX_BYTES);
|
|
1637
|
+
if (!read) {
|
|
1638
|
+
response.writeHead(413, { connection: "close" }).end(`Too large.
|
|
1639
|
+
`);
|
|
727
1640
|
return;
|
|
728
1641
|
}
|
|
729
|
-
|
|
1642
|
+
let copy = this.blobs.get(id);
|
|
1643
|
+
if (!copy) {
|
|
1644
|
+
const storage = new MemoryBlobStorage;
|
|
1645
|
+
copy = { blobs: new RelayBlobs(storage), storage, pending: 0 };
|
|
1646
|
+
this.blobs.set(id, copy);
|
|
1647
|
+
}
|
|
1648
|
+
const headers = new Headers;
|
|
1649
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
1650
|
+
if (typeof value === "string") {
|
|
1651
|
+
headers.set(name, value);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
const method = (_a = request.method) !== null && _a !== undefined ? _a : "GET";
|
|
1655
|
+
const body = read.length && method !== "GET" && method !== "HEAD" ? read : undefined;
|
|
1656
|
+
copy.pending++;
|
|
1657
|
+
let answer;
|
|
1658
|
+
try {
|
|
1659
|
+
answer = await copy.blobs.handle(new Request(`http://relay${request.url}`, { method, headers, body }));
|
|
1660
|
+
} finally {
|
|
1661
|
+
copy.pending--;
|
|
1662
|
+
if (copy.pending === 0 && copy.storage.empty && this.blobs.get(id) === copy) {
|
|
1663
|
+
this.blobs.delete(id);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
response.writeHead(answer.status, Object.fromEntries(answer.headers));
|
|
1667
|
+
response.end(Buffer.from(await answer.arrayBuffer()));
|
|
1668
|
+
}
|
|
1669
|
+
static body(request, max) {
|
|
1670
|
+
return new Promise((resolve, reject) => {
|
|
1671
|
+
const chunks = [];
|
|
1672
|
+
let size = 0;
|
|
1673
|
+
request.on("data", (chunk) => {
|
|
1674
|
+
if (size < 0) {
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
size += chunk.length;
|
|
1678
|
+
if (size > max) {
|
|
1679
|
+
size = -1;
|
|
1680
|
+
chunks.length = 0;
|
|
1681
|
+
resolve(undefined);
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
chunks.push(chunk);
|
|
1685
|
+
});
|
|
1686
|
+
request.on("end", () => size >= 0 && resolve(Buffer.concat(chunks)));
|
|
1687
|
+
request.on("error", reject);
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
upgrade(request, socket, head) {
|
|
1691
|
+
var _a, _b;
|
|
1692
|
+
const url = new URL((_a = request.url) !== null && _a !== undefined ? _a : "/", "http://relay");
|
|
1693
|
+
const checked = WebSocketConnection.check(request);
|
|
1694
|
+
if ("status" in checked) {
|
|
1695
|
+
WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
if (url.pathname.startsWith(RELAY_HUB_PATH)) {
|
|
1699
|
+
const id2 = url.pathname.slice(RELAY_HUB_PATH.length);
|
|
1700
|
+
if (!RELAY_ID.test(id2)) {
|
|
1701
|
+
WebSocketConnection.refuse(socket, 404, "Not found.");
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
this.openHub(id2, WebSocketConnection.open(socket, checked.key, head, WEBSOCKET));
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const [path, id] = url.pathname.startsWith(RELAY_HOST_PATH) ? [RELAY_HOST_PATH, url.pathname.slice(RELAY_HOST_PATH.length)] : [RELAY_CONNECT_PATH, url.pathname.slice(RELAY_CONNECT_PATH.length)];
|
|
1708
|
+
if (!url.pathname.startsWith(path) || !RELAY_ID.test(id)) {
|
|
1709
|
+
WebSocketConnection.refuse(socket, 404, "Not found.");
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
|
|
730
1713
|
if (path === RELAY_HOST_PATH) {
|
|
731
1714
|
this.openHost(id, (_b = url.searchParams.get("secret")) !== null && _b !== undefined ? _b : "", connection);
|
|
732
1715
|
} else {
|
|
@@ -771,6 +1754,65 @@ class RelayServer {
|
|
|
771
1754
|
}
|
|
772
1755
|
});
|
|
773
1756
|
}
|
|
1757
|
+
openHub(id, connection) {
|
|
1758
|
+
let hub = this.hubs.get(id);
|
|
1759
|
+
if (!hub) {
|
|
1760
|
+
const sockets2 = new Map;
|
|
1761
|
+
const socketOf = (other) => {
|
|
1762
|
+
var _a;
|
|
1763
|
+
const state = (_a = sockets2.get(other)) !== null && _a !== undefined ? _a : {};
|
|
1764
|
+
return {
|
|
1765
|
+
key: other,
|
|
1766
|
+
get who() {
|
|
1767
|
+
return state.who;
|
|
1768
|
+
},
|
|
1769
|
+
set who(who) {
|
|
1770
|
+
state.who = who;
|
|
1771
|
+
},
|
|
1772
|
+
send: (text) => other.send(text),
|
|
1773
|
+
close: (code, reason) => other.close(code, reason)
|
|
1774
|
+
};
|
|
1775
|
+
};
|
|
1776
|
+
const storage = new MemoryHubStorage;
|
|
1777
|
+
hub = { sockets: sockets2, storage, hub: new RelayHub(storage, () => [...sockets2.keys()].map(socketOf)) };
|
|
1778
|
+
this.hubs.set(id, hub);
|
|
1779
|
+
}
|
|
1780
|
+
const current = hub;
|
|
1781
|
+
const { sockets, hub: relay } = current;
|
|
1782
|
+
sockets.set(connection, {});
|
|
1783
|
+
let chain = Promise.resolve();
|
|
1784
|
+
const socket = {
|
|
1785
|
+
key: connection,
|
|
1786
|
+
get who() {
|
|
1787
|
+
var _a;
|
|
1788
|
+
return (_a = sockets.get(connection)) === null || _a === undefined ? undefined : _a.who;
|
|
1789
|
+
},
|
|
1790
|
+
set who(who) {
|
|
1791
|
+
const state = sockets.get(connection);
|
|
1792
|
+
if (state) {
|
|
1793
|
+
state.who = who;
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
send: (text) => connection.send(text),
|
|
1797
|
+
close: (code, reason) => connection.close(code, reason)
|
|
1798
|
+
};
|
|
1799
|
+
connection.onMessage((text) => {
|
|
1800
|
+
chain = chain.then(() => relay.receive(socket, text)).catch(() => {
|
|
1801
|
+
return;
|
|
1802
|
+
});
|
|
1803
|
+
});
|
|
1804
|
+
connection.onClose(() => {
|
|
1805
|
+
chain.then(() => {
|
|
1806
|
+
if (sockets.has(connection)) {
|
|
1807
|
+
relay.closed(socket);
|
|
1808
|
+
sockets.delete(connection);
|
|
1809
|
+
}
|
|
1810
|
+
if (sockets.size === 0 && current.storage.empty && this.hubs.get(id) === current) {
|
|
1811
|
+
this.hubs.delete(id);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
774
1816
|
createRoom(id, secretHash) {
|
|
775
1817
|
const room = {
|
|
776
1818
|
secretHash,
|
|
@@ -795,36 +1837,594 @@ class RelayServer {
|
|
|
795
1837
|
var WEBSOCKET, peer = (connection) => ({ send: (text) => connection.send(text), close: (code, reason) => connection.close(code, reason) });
|
|
796
1838
|
var init_relay_server = __esm(() => {
|
|
797
1839
|
init_websocket_connection();
|
|
1840
|
+
init_relay_blobs();
|
|
1841
|
+
init_relay_hub();
|
|
798
1842
|
init_relay_protocol();
|
|
799
1843
|
init_relay_room();
|
|
1844
|
+
init_relay_viewer();
|
|
800
1845
|
WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
801
1846
|
});
|
|
802
1847
|
|
|
1848
|
+
// ../../ta-packages/ta-relay/esm/common/relay-cipher.js
|
|
1849
|
+
class RelayCipher {
|
|
1850
|
+
constructor(sendKey, receiveKey) {
|
|
1851
|
+
this.sendKey = sendKey;
|
|
1852
|
+
this.receiveKey = receiveKey;
|
|
1853
|
+
this.compress = false;
|
|
1854
|
+
this.sent = 0;
|
|
1855
|
+
this.received = 0;
|
|
1856
|
+
this.sealing = Promise.resolve();
|
|
1857
|
+
this.opening = Promise.resolve();
|
|
1858
|
+
}
|
|
1859
|
+
static async derive(deviceKey, clientNonce, hostNonce, side) {
|
|
1860
|
+
const subtle2 = globalThis.crypto.subtle;
|
|
1861
|
+
const secret = await subtle2.importKey("raw", deviceKey, "HKDF", false, ["deriveKey"]);
|
|
1862
|
+
const salt = RelayBytes.concat(clientNonce, hostNonce);
|
|
1863
|
+
const key = (direction) => subtle2.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: encoder2.encode(`ta-relay/1 ${direction}`) }, secret, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
1864
|
+
const [toHost, toClient] = await Promise.all([key("client-to-host"), key("host-to-client")]);
|
|
1865
|
+
return side === "client" ? new RelayCipher(toHost, toClient) : new RelayCipher(toClient, toHost);
|
|
1866
|
+
}
|
|
1867
|
+
seal(text) {
|
|
1868
|
+
const iv = RelayCipher.iv(this.sent++);
|
|
1869
|
+
const sealed = this.sealing.then(async () => {
|
|
1870
|
+
const data = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, this.sendKey, await this.pack(text));
|
|
1871
|
+
return RelayBytes.toBase64(new Uint8Array(data));
|
|
1872
|
+
});
|
|
1873
|
+
this.sealing = sealed.catch(() => {
|
|
1874
|
+
return;
|
|
1875
|
+
});
|
|
1876
|
+
return sealed;
|
|
1877
|
+
}
|
|
1878
|
+
open(frame) {
|
|
1879
|
+
const iv = RelayCipher.iv(this.received++);
|
|
1880
|
+
const opened = this.opening.then(async () => {
|
|
1881
|
+
const data = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv }, this.receiveKey, RelayBytes.fromBase64(frame));
|
|
1882
|
+
return this.unpack(new Uint8Array(data));
|
|
1883
|
+
});
|
|
1884
|
+
this.opening = opened.catch(() => {
|
|
1885
|
+
return;
|
|
1886
|
+
});
|
|
1887
|
+
return opened;
|
|
1888
|
+
}
|
|
1889
|
+
async pack(text) {
|
|
1890
|
+
const bytes = encoder2.encode(text);
|
|
1891
|
+
if (!this.compress) {
|
|
1892
|
+
return bytes;
|
|
1893
|
+
}
|
|
1894
|
+
const deflated = bytes.length >= DEFLATE_MIN_BYTES ? await RelayDeflate.compress(bytes) : undefined;
|
|
1895
|
+
return deflated && deflated.length < bytes.length ? RelayBytes.concat(Uint8Array.of(DEFLATED), deflated) : RelayBytes.concat(Uint8Array.of(PLAIN), bytes);
|
|
1896
|
+
}
|
|
1897
|
+
async unpack(bytes) {
|
|
1898
|
+
if (!this.compress) {
|
|
1899
|
+
return decoder2.decode(bytes);
|
|
1900
|
+
}
|
|
1901
|
+
const body = bytes.subarray(1);
|
|
1902
|
+
return decoder2.decode(bytes[0] === DEFLATED ? await RelayDeflate.decompress(body) : body);
|
|
1903
|
+
}
|
|
1904
|
+
static iv(counter) {
|
|
1905
|
+
const iv = new Uint8Array(IV_LENGTH);
|
|
1906
|
+
new DataView(iv.buffer).setUint32(IV_LENGTH - 8, Math.floor(counter / 2 ** 32));
|
|
1907
|
+
new DataView(iv.buffer).setUint32(IV_LENGTH - 4, counter >>> 0);
|
|
1908
|
+
return iv;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
var encoder2, decoder2, IV_LENGTH = 12, PLAIN = 0, DEFLATED = 1, DEFLATE_MIN_BYTES = 1024, RelayDeflate;
|
|
1912
|
+
var init_relay_cipher = __esm(() => {
|
|
1913
|
+
init_relay_bytes();
|
|
1914
|
+
encoder2 = new TextEncoder;
|
|
1915
|
+
decoder2 = new TextDecoder;
|
|
1916
|
+
(function(RelayDeflate2) {
|
|
1917
|
+
let support;
|
|
1918
|
+
function supported() {
|
|
1919
|
+
if (support === undefined) {
|
|
1920
|
+
try {
|
|
1921
|
+
new CompressionStream("deflate-raw");
|
|
1922
|
+
new DecompressionStream("deflate-raw");
|
|
1923
|
+
support = true;
|
|
1924
|
+
} catch (_a) {
|
|
1925
|
+
support = false;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return support;
|
|
1929
|
+
}
|
|
1930
|
+
RelayDeflate2.supported = supported;
|
|
1931
|
+
function compress(bytes) {
|
|
1932
|
+
return through(bytes, new CompressionStream("deflate-raw"));
|
|
1933
|
+
}
|
|
1934
|
+
RelayDeflate2.compress = compress;
|
|
1935
|
+
function decompress(bytes) {
|
|
1936
|
+
return through(bytes, new DecompressionStream("deflate-raw"));
|
|
1937
|
+
}
|
|
1938
|
+
RelayDeflate2.decompress = decompress;
|
|
1939
|
+
async function through(bytes, stream) {
|
|
1940
|
+
const piped = new Blob([bytes]).stream().pipeThrough(stream);
|
|
1941
|
+
return new Uint8Array(await new Response(piped).arrayBuffer());
|
|
1942
|
+
}
|
|
1943
|
+
})(RelayDeflate || (RelayDeflate = {}));
|
|
1944
|
+
});
|
|
1945
|
+
|
|
1946
|
+
// ../../ta-packages/ta-relay/esm/common/relay-pairing.js
|
|
1947
|
+
var exports_relay_pairing = {};
|
|
1948
|
+
__export(exports_relay_pairing, {
|
|
1949
|
+
RelayPairingUtil: () => RelayPairingUtil
|
|
1950
|
+
});
|
|
1951
|
+
var RelayPairingUtil;
|
|
1952
|
+
var init_relay_pairing = __esm(() => {
|
|
1953
|
+
init_relay_protocol();
|
|
1954
|
+
(function(RelayPairingUtil2) {
|
|
1955
|
+
function link(pairing) {
|
|
1956
|
+
const fragment = new URLSearchParams({ v: "1", h: pairing.host, d: pairing.device, k: pairing.key });
|
|
1957
|
+
if (pairing.name) {
|
|
1958
|
+
fragment.set("n", pairing.name);
|
|
1959
|
+
}
|
|
1960
|
+
return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
|
|
1961
|
+
}
|
|
1962
|
+
RelayPairingUtil2.link = link;
|
|
1963
|
+
function parse(link2) {
|
|
1964
|
+
var _a;
|
|
1965
|
+
const url = new URL(link2.trim());
|
|
1966
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
1967
|
+
const [host, device, key] = ["h", "d", "k"].map((name) => {
|
|
1968
|
+
var _a2;
|
|
1969
|
+
return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
|
|
1970
|
+
});
|
|
1971
|
+
if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_PAIR_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
|
|
1972
|
+
throw new Error("Not a pairing link of Ta.");
|
|
1973
|
+
}
|
|
1974
|
+
return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined };
|
|
1975
|
+
}
|
|
1976
|
+
RelayPairingUtil2.parse = parse;
|
|
1977
|
+
function websocketUrl(relay, path) {
|
|
1978
|
+
return relay.replace(/^http/, "ws") + path;
|
|
1979
|
+
}
|
|
1980
|
+
RelayPairingUtil2.websocketUrl = websocketUrl;
|
|
1981
|
+
})(RelayPairingUtil || (RelayPairingUtil = {}));
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
// ../../ta-packages/ta-relay/esm/common/relay-socket.js
|
|
1985
|
+
class RelaySocket {
|
|
1986
|
+
constructor(pairing, options = {}) {
|
|
1987
|
+
var _a;
|
|
1988
|
+
this.pairing = pairing;
|
|
1989
|
+
this.options = options;
|
|
1990
|
+
this.onopen = null;
|
|
1991
|
+
this.onmessage = null;
|
|
1992
|
+
this.onclose = null;
|
|
1993
|
+
this.onerror = null;
|
|
1994
|
+
this.state = CONNECTING;
|
|
1995
|
+
this.nonce = RelayBytes.random(16);
|
|
1996
|
+
this.ponged = false;
|
|
1997
|
+
this.awaitingPong = false;
|
|
1998
|
+
this.receiving = Promise.resolve();
|
|
1999
|
+
this.socket = new WebSocket(RelayPairingUtil.websocketUrl(pairing.relay, RELAY_CONNECT_PATH + pairing.host));
|
|
2000
|
+
this.helloTimer = setTimeout(() => this.drop(RelayCloseCode.TIMEOUT, "The host did not answer."), (_a = options.helloMs) !== null && _a !== undefined ? _a : HELLO_MS);
|
|
2001
|
+
this.socket.onopen = () => {
|
|
2002
|
+
var _a2;
|
|
2003
|
+
const hello = {
|
|
2004
|
+
t: "hello",
|
|
2005
|
+
v: 1,
|
|
2006
|
+
device: pairing.device,
|
|
2007
|
+
nonce: RelayBytes.toBase64(this.nonce),
|
|
2008
|
+
...RelayDeflate.supported() ? { z: 1 } : {}
|
|
2009
|
+
};
|
|
2010
|
+
this.socket.send(JSON.stringify(hello));
|
|
2011
|
+
this.pingTimer = setInterval(() => this.ping(), (_a2 = options.pingMs) !== null && _a2 !== undefined ? _a2 : RELAY_PING_MS);
|
|
2012
|
+
};
|
|
2013
|
+
this.socket.onmessage = (message) => {
|
|
2014
|
+
const text = String(message.data);
|
|
2015
|
+
if (text === RELAY_PONG) {
|
|
2016
|
+
this.ponged = true;
|
|
2017
|
+
this.awaitingPong = false;
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
this.receiving = this.receiving.then(() => this.receive(text));
|
|
2021
|
+
};
|
|
2022
|
+
this.socket.onerror = (event) => {
|
|
2023
|
+
var _a2;
|
|
2024
|
+
return (_a2 = this.onerror) === null || _a2 === undefined ? undefined : _a2.call(this, event);
|
|
2025
|
+
};
|
|
2026
|
+
this.socket.onclose = (event) => void this.receiving.then(() => this.finish(event.code, event.reason));
|
|
2027
|
+
}
|
|
2028
|
+
get readyState() {
|
|
2029
|
+
return this.state;
|
|
2030
|
+
}
|
|
2031
|
+
get closeCode() {
|
|
2032
|
+
return this.code;
|
|
2033
|
+
}
|
|
2034
|
+
send(text) {
|
|
2035
|
+
if (this.state !== OPEN || !this.cipher) {
|
|
2036
|
+
throw new Error("The connection is not open.");
|
|
2037
|
+
}
|
|
2038
|
+
this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
|
|
2039
|
+
}
|
|
2040
|
+
close(code = 1000, reason = "") {
|
|
2041
|
+
if (this.state === CLOSED) {
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
this.state = CLOSING;
|
|
2045
|
+
this.socket.close(code, reason);
|
|
2046
|
+
}
|
|
2047
|
+
async receive(text) {
|
|
2048
|
+
var _a, _b;
|
|
2049
|
+
if (this.cipher) {
|
|
2050
|
+
if (this.options.proveFirst && text.startsWith("{")) {
|
|
2051
|
+
this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
|
|
2052
|
+
return;
|
|
2053
|
+
}
|
|
2054
|
+
try {
|
|
2055
|
+
const data = await this.cipher.open(text);
|
|
2056
|
+
(_a = this.onmessage) === null || _a === undefined || _a.call(this, { data });
|
|
2057
|
+
} catch (_c) {
|
|
2058
|
+
this.close(4400, "A message did not open.");
|
|
2059
|
+
}
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
try {
|
|
2063
|
+
const welcome = JSON.parse(text);
|
|
2064
|
+
if (welcome.t !== "ready") {
|
|
2065
|
+
this.drop(RelaySocket.REFUSED, this.options.proveFirst ? RelaySocket.refusal(text) : "The host refused this device.");
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
const cipher = await RelayCipher.derive(RelayBytes.fromBase64(this.pairing.key), this.nonce, RelayBytes.fromBase64(welcome.nonce), "client");
|
|
2069
|
+
if (welcome.proof === undefined && this.options.proveFirst) {
|
|
2070
|
+
this.socket.send(await cipher.seal(RELAY_PROOF));
|
|
2071
|
+
} else if (welcome.proof === undefined || await cipher.open(welcome.proof) !== RELAY_PROOF) {
|
|
2072
|
+
throw new Error("The host did not show the key.");
|
|
2073
|
+
}
|
|
2074
|
+
cipher.compress = welcome.z === 1 && RelayDeflate.supported();
|
|
2075
|
+
this.cipher = cipher;
|
|
2076
|
+
clearTimeout(this.helloTimer);
|
|
2077
|
+
this.state = OPEN;
|
|
2078
|
+
(_b = this.onopen) === null || _b === undefined || _b.call(this);
|
|
2079
|
+
} catch (_d) {
|
|
2080
|
+
this.drop(RelaySocket.REFUSED, "The host refused this device.");
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
static refusal(text) {
|
|
2084
|
+
try {
|
|
2085
|
+
const reason = JSON.parse(text).reason;
|
|
2086
|
+
return reason === "key" || reason === "busy" ? reason : "gone";
|
|
2087
|
+
} catch (_a) {
|
|
2088
|
+
return "gone";
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
ping() {
|
|
2092
|
+
if (this.awaitingPong && this.ponged) {
|
|
2093
|
+
this.drop(RelayCloseCode.TIMEOUT, "The relay did not answer.");
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
this.awaitingPong = true;
|
|
2097
|
+
if (this.socket.readyState === OPEN) {
|
|
2098
|
+
this.socket.send(RELAY_PING);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
drop(code, reason) {
|
|
2102
|
+
this.close(code, reason);
|
|
2103
|
+
this.finish(code, reason);
|
|
2104
|
+
}
|
|
2105
|
+
finish(code, reason) {
|
|
2106
|
+
var _a;
|
|
2107
|
+
if (this.state === CLOSED) {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
clearTimeout(this.helloTimer);
|
|
2111
|
+
clearInterval(this.pingTimer);
|
|
2112
|
+
this.state = CLOSED;
|
|
2113
|
+
this.code = code;
|
|
2114
|
+
(_a = this.onclose) === null || _a === undefined || _a.call(this, { code, reason });
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
var CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3, HELLO_MS = 15000;
|
|
2118
|
+
var init_relay_socket = __esm(() => {
|
|
2119
|
+
init_relay_bytes();
|
|
2120
|
+
init_relay_cipher();
|
|
2121
|
+
init_relay_pairing();
|
|
2122
|
+
init_relay_protocol();
|
|
2123
|
+
RelaySocket.CONNECTING = CONNECTING;
|
|
2124
|
+
RelaySocket.OPEN = OPEN;
|
|
2125
|
+
RelaySocket.CLOSING = CLOSING;
|
|
2126
|
+
RelaySocket.CLOSED = CLOSED;
|
|
2127
|
+
RelaySocket.REFUSED = 4403;
|
|
2128
|
+
});
|
|
2129
|
+
|
|
2130
|
+
// ../../ta-packages/ta-relay/esm/common/relay-content.js
|
|
2131
|
+
var encoder3, decoder3, RelayContentError, PBKDF2_ITERATIONS = 600000, PLAIN_KINDS, KIND, RelayContentUtil;
|
|
2132
|
+
var init_relay_content = __esm(() => {
|
|
2133
|
+
init_relay_bytes();
|
|
2134
|
+
init_relay_identity();
|
|
2135
|
+
init_relay_protocol();
|
|
2136
|
+
init_relay_socket();
|
|
2137
|
+
encoder3 = new TextEncoder;
|
|
2138
|
+
decoder3 = new TextDecoder;
|
|
2139
|
+
RelayContentError = class RelayContentError extends Error {
|
|
2140
|
+
constructor(reason, message) {
|
|
2141
|
+
super(message);
|
|
2142
|
+
this.reason = reason;
|
|
2143
|
+
this.name = "RelayContentError";
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
PLAIN_KINDS = new Set(["ta-conversation", "file"]);
|
|
2147
|
+
KIND = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
2148
|
+
(function(RelayContentUtil2) {
|
|
2149
|
+
function link(content) {
|
|
2150
|
+
var _a;
|
|
2151
|
+
const fragment = new URLSearchParams({ v: "1", h: content.host, s: content.share });
|
|
2152
|
+
if (content.access === "self") {
|
|
2153
|
+
fragment.set("m", "self");
|
|
2154
|
+
} else if (content.access === "people") {
|
|
2155
|
+
fragment.set("m", "people");
|
|
2156
|
+
fragment.set("o", (_a = content.owner) !== null && _a !== undefined ? _a : "");
|
|
2157
|
+
} else if (content.key) {
|
|
2158
|
+
fragment.set("k", content.key);
|
|
2159
|
+
}
|
|
2160
|
+
if (content.access === "password") {
|
|
2161
|
+
fragment.set("p", "1");
|
|
2162
|
+
}
|
|
2163
|
+
if (content.offline && content.access !== "self" && content.access !== "people") {
|
|
2164
|
+
fragment.set("o", "1");
|
|
2165
|
+
}
|
|
2166
|
+
if (content.kind && !PLAIN_KINDS.has(content.kind) && KIND.test(content.kind)) {
|
|
2167
|
+
fragment.set("c", content.kind);
|
|
2168
|
+
}
|
|
2169
|
+
return `${content.relay}${RELAY_CONTENT_PATH}#${fragment}`;
|
|
2170
|
+
}
|
|
2171
|
+
RelayContentUtil2.link = link;
|
|
2172
|
+
function is(text) {
|
|
2173
|
+
try {
|
|
2174
|
+
parse(text);
|
|
2175
|
+
return true;
|
|
2176
|
+
} catch (_a) {
|
|
2177
|
+
return false;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
RelayContentUtil2.is = is;
|
|
2181
|
+
function parse(text) {
|
|
2182
|
+
var _a, _b;
|
|
2183
|
+
const url = new URL(text.trim());
|
|
2184
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
2185
|
+
const [host, share, key] = ["h", "s", "k"].map((name) => {
|
|
2186
|
+
var _a2;
|
|
2187
|
+
return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
|
|
2188
|
+
});
|
|
2189
|
+
const self = fragment.get("m") === "self";
|
|
2190
|
+
const people = fragment.get("m") === "people";
|
|
2191
|
+
const owner = (_a = fragment.get("o")) !== null && _a !== undefined ? _a : "";
|
|
2192
|
+
if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_CONTENT_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(share) || (people ? !/^[A-Za-z0-9_-]{22}$/.test(owner) : !self && !/^[A-Za-z0-9_-]{43}$/.test(key))) {
|
|
2193
|
+
throw new RelayContentError("invalid", "Not a link of something shared from Ta.");
|
|
2194
|
+
}
|
|
2195
|
+
const kind = (_b = fragment.get("c")) !== null && _b !== undefined ? _b : "";
|
|
2196
|
+
if (people) {
|
|
2197
|
+
return { relay: url.origin, host, share, access: "people", owner, offline: false, ...KIND.test(kind) ? { kind } : {} };
|
|
2198
|
+
}
|
|
2199
|
+
return {
|
|
2200
|
+
relay: url.origin,
|
|
2201
|
+
host,
|
|
2202
|
+
share,
|
|
2203
|
+
key: self ? undefined : key,
|
|
2204
|
+
access: self ? "self" : fragment.get("p") === "1" ? "password" : "link",
|
|
2205
|
+
offline: !self && fragment.get("o") === "1",
|
|
2206
|
+
...KIND.test(kind) ? { kind } : {}
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
RelayContentUtil2.parse = parse;
|
|
2210
|
+
async function contentKey(linkKey, share, password) {
|
|
2211
|
+
if (password === undefined) {
|
|
2212
|
+
return linkKey;
|
|
2213
|
+
}
|
|
2214
|
+
const subtle2 = globalThis.crypto.subtle;
|
|
2215
|
+
const secret = await subtle2.importKey("raw", encoder3.encode(password.normalize("NFC")), "PBKDF2", false, ["deriveBits"]);
|
|
2216
|
+
const stretched = await subtle2.deriveBits({ name: "PBKDF2", hash: "SHA-256", salt: encoder3.encode(`ta-share:${share}`), iterations: PBKDF2_ITERATIONS }, secret, 256);
|
|
2217
|
+
return hkdf(linkKey, new Uint8Array(stretched), "ta-share/1 password");
|
|
2218
|
+
}
|
|
2219
|
+
RelayContentUtil2.contentKey = contentKey;
|
|
2220
|
+
function peopleKey(identity, otherBox, share) {
|
|
2221
|
+
return RelayIdentityUtil.agree(identity, otherBox, share, "ta-share/1 people");
|
|
2222
|
+
}
|
|
2223
|
+
RelayContentUtil2.peopleKey = peopleKey;
|
|
2224
|
+
async function authToken(key) {
|
|
2225
|
+
return RelayBytes.toBase64(await hkdf(key, new Uint8Array(0), "ta-share/1 auth"));
|
|
2226
|
+
}
|
|
2227
|
+
RelayContentUtil2.authToken = authToken;
|
|
2228
|
+
async function sha256(text) {
|
|
2229
|
+
return RelayBytes.toBase64(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", encoder3.encode(text))));
|
|
2230
|
+
}
|
|
2231
|
+
RelayContentUtil2.sha256 = sha256;
|
|
2232
|
+
async function seal(key, item) {
|
|
2233
|
+
const iv = RelayBytes.random(12);
|
|
2234
|
+
const sealed = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, await blobKey(key), encode(item));
|
|
2235
|
+
return RelayBytes.concat(iv, new Uint8Array(sealed));
|
|
2236
|
+
}
|
|
2237
|
+
RelayContentUtil2.seal = seal;
|
|
2238
|
+
async function open(key, bytes) {
|
|
2239
|
+
const opened = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv: bytes.subarray(0, 12) }, await blobKey(key), bytes.subarray(12));
|
|
2240
|
+
return decode(new Uint8Array(opened));
|
|
2241
|
+
}
|
|
2242
|
+
RelayContentUtil2.open = open;
|
|
2243
|
+
function encode(item) {
|
|
2244
|
+
const { data, ...header } = item;
|
|
2245
|
+
const head = encoder3.encode(JSON.stringify(header));
|
|
2246
|
+
const length = new Uint8Array(4);
|
|
2247
|
+
new DataView(length.buffer).setUint32(0, head.length);
|
|
2248
|
+
return RelayBytes.concat(length, head, data);
|
|
2249
|
+
}
|
|
2250
|
+
RelayContentUtil2.encode = encode;
|
|
2251
|
+
function decode(bytes) {
|
|
2252
|
+
const length = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0);
|
|
2253
|
+
const header = JSON.parse(decoder3.decode(bytes.subarray(4, 4 + length)));
|
|
2254
|
+
return {
|
|
2255
|
+
kind: String(header.kind),
|
|
2256
|
+
title: String(header.title),
|
|
2257
|
+
createdAt: Number(header.createdAt),
|
|
2258
|
+
type: header.type,
|
|
2259
|
+
data: bytes.slice(4 + length)
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
RelayContentUtil2.decode = decode;
|
|
2263
|
+
async function fetch2(text, options = {}) {
|
|
2264
|
+
const link2 = typeof text === "string" ? parse(text) : text;
|
|
2265
|
+
if (link2.access === "people") {
|
|
2266
|
+
if (!options.people) {
|
|
2267
|
+
throw new RelayContentError("people", "Only the Ta friends it was shared with open it, in their own Ta.");
|
|
2268
|
+
}
|
|
2269
|
+
return fromHost(link2, await peopleKey(options.people.identity, options.people.ownerBox, link2.share), options);
|
|
2270
|
+
}
|
|
2271
|
+
if (link2.access === "self" || !link2.key) {
|
|
2272
|
+
throw new RelayContentError("self", "Only the one who shared it opens it, in their own Ta.");
|
|
2273
|
+
}
|
|
2274
|
+
if (link2.access === "password" && !options.password) {
|
|
2275
|
+
throw new RelayContentError("password", "It is shared with a password.");
|
|
2276
|
+
}
|
|
2277
|
+
const key = await contentKey(RelayBytes.fromBase64(link2.key), link2.share, link2.access === "password" ? options.password : undefined);
|
|
2278
|
+
if (link2.offline) {
|
|
2279
|
+
const copy = await fromRelay(link2, key);
|
|
2280
|
+
if (copy) {
|
|
2281
|
+
return copy;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return fromHost(link2, key, options);
|
|
2285
|
+
}
|
|
2286
|
+
RelayContentUtil2.fetch = fetch2;
|
|
2287
|
+
async function fromRelay(link2, key) {
|
|
2288
|
+
let response;
|
|
2289
|
+
try {
|
|
2290
|
+
response = await globalThis.fetch(`${link2.relay}${RELAY_BLOB_PATH}${link2.share}`, { headers: { "x-ta-auth": await authToken(key) } });
|
|
2291
|
+
} catch (_a) {
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
if (response.status === 403) {
|
|
2295
|
+
throw link2.access === "password" ? new RelayContentError("wrong", "The password is wrong.") : new RelayContentError("gone", "This link no longer works.");
|
|
2296
|
+
}
|
|
2297
|
+
if (response.status === 429) {
|
|
2298
|
+
throw new RelayContentError("busy", "Too many wrong passwords: try again in a few minutes.");
|
|
2299
|
+
}
|
|
2300
|
+
if (!response.ok) {
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
try {
|
|
2304
|
+
return await open(key, new Uint8Array(await response.arrayBuffer()));
|
|
2305
|
+
} catch (_b) {
|
|
2306
|
+
throw new RelayContentError("wrong", "The password is wrong.");
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
function fromHost(link2, key, options) {
|
|
2310
|
+
var _a;
|
|
2311
|
+
const max = (_a = options.maxBytes) !== null && _a !== undefined ? _a : RELAY_CONTENT_MAX_BYTES;
|
|
2312
|
+
const pairing = { relay: link2.relay, host: link2.host, device: link2.share, key: RelayBytes.toBase64(key) };
|
|
2313
|
+
return new Promise((resolve, reject) => {
|
|
2314
|
+
var _a2;
|
|
2315
|
+
const socket = new RelaySocket(pairing, { proveFirst: true });
|
|
2316
|
+
const chunks = [];
|
|
2317
|
+
let received = 0;
|
|
2318
|
+
let header;
|
|
2319
|
+
let done = false;
|
|
2320
|
+
const finish = (error, item) => {
|
|
2321
|
+
if (done) {
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2324
|
+
done = true;
|
|
2325
|
+
clearTimeout(timer);
|
|
2326
|
+
socket.onclose = null;
|
|
2327
|
+
socket.close();
|
|
2328
|
+
if (item) {
|
|
2329
|
+
resolve(item);
|
|
2330
|
+
} else {
|
|
2331
|
+
reject(error);
|
|
2332
|
+
}
|
|
2333
|
+
};
|
|
2334
|
+
const timer = setTimeout(() => finish(new RelayContentError("timeout", "The computer that shared it took too long to send it.")), (_a2 = options.timeoutMs) !== null && _a2 !== undefined ? _a2 : 60000);
|
|
2335
|
+
socket.onmessage = ({ data }) => {
|
|
2336
|
+
let message;
|
|
2337
|
+
try {
|
|
2338
|
+
message = JSON.parse(data);
|
|
2339
|
+
} catch (_a3) {
|
|
2340
|
+
finish(new RelayContentError("invalid", "The computer that shared it sent what is not content."));
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
if (message.t === "error") {
|
|
2344
|
+
finish(new RelayContentError("gone", message.message));
|
|
2345
|
+
} else if (message.t === "content") {
|
|
2346
|
+
if (!(message.size >= 0) || message.size > max) {
|
|
2347
|
+
finish(new RelayContentError("large", `It is larger than ${Math.round(max / 1024 / 1024)} MB.`));
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
header = {
|
|
2351
|
+
kind: String(message.kind),
|
|
2352
|
+
title: String(message.title),
|
|
2353
|
+
createdAt: Number(message.createdAt),
|
|
2354
|
+
type: message.type,
|
|
2355
|
+
size: message.size
|
|
2356
|
+
};
|
|
2357
|
+
} else if (message.t === "chunk" && header) {
|
|
2358
|
+
const bytes = RelayBytes.fromBase64(message.d);
|
|
2359
|
+
received += bytes.length;
|
|
2360
|
+
if (received > header.size) {
|
|
2361
|
+
finish(new RelayContentError("invalid", "It is larger than it said."));
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
chunks.push(bytes);
|
|
2365
|
+
} else if (message.t === "end" && header) {
|
|
2366
|
+
if (received !== header.size) {
|
|
2367
|
+
finish(new RelayContentError("invalid", "It came short."));
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
const { size: _size, ...rest } = header;
|
|
2371
|
+
finish(undefined, { ...rest, data: RelayBytes.concat(...chunks) });
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
socket.onclose = ({ code, reason }) => finish(closed(code, reason, link2));
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
function closed(code, reason, link2) {
|
|
2378
|
+
if (code === RelaySocket.REFUSED) {
|
|
2379
|
+
if (reason === "key") {
|
|
2380
|
+
return link2.access === "password" ? new RelayContentError("wrong", "The password is wrong.") : new RelayContentError("gone", "This link no longer works.");
|
|
2381
|
+
}
|
|
2382
|
+
if (reason === "busy") {
|
|
2383
|
+
return new RelayContentError("busy", "Too many wrong passwords: try again in a few minutes.");
|
|
2384
|
+
}
|
|
2385
|
+
return new RelayContentError("gone", "This link no longer works: the share was stopped or ran out.");
|
|
2386
|
+
}
|
|
2387
|
+
return code === RelayCloseCode.HOST_OFFLINE || code === RelayCloseCode.TIMEOUT ? new RelayContentError("offline", "The computer that shared it is not running Ta now. Try again later.") : new RelayContentError("offline", "The computer that shared it cannot be reached now. Try again later.");
|
|
2388
|
+
}
|
|
2389
|
+
async function blobKey(key) {
|
|
2390
|
+
const bytes = await hkdf(key, new Uint8Array(0), "ta-share/1 blob");
|
|
2391
|
+
return globalThis.crypto.subtle.importKey("raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
2392
|
+
}
|
|
2393
|
+
async function hkdf(key, salt, info) {
|
|
2394
|
+
const subtle2 = globalThis.crypto.subtle;
|
|
2395
|
+
const secret = await subtle2.importKey("raw", key, "HKDF", false, ["deriveBits"]);
|
|
2396
|
+
const bits = await subtle2.deriveBits({ name: "HKDF", hash: "SHA-256", salt, info: encoder3.encode(info) }, secret, 256);
|
|
2397
|
+
return new Uint8Array(bits);
|
|
2398
|
+
}
|
|
2399
|
+
})(RelayContentUtil || (RelayContentUtil = {}));
|
|
2400
|
+
});
|
|
2401
|
+
|
|
803
2402
|
// ../../ta-packages/ta-relay/esm/node/relay-store.js
|
|
804
2403
|
var exports_relay_store = {};
|
|
805
2404
|
__export(exports_relay_store, {
|
|
806
2405
|
RelayStore: () => RelayStore
|
|
807
2406
|
});
|
|
808
2407
|
import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
809
|
-
import { chmodSync as chmodSync2, mkdirSync as mkdirSync4, readFileSync as
|
|
2408
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
810
2409
|
import { hostname as hostname2 } from "node:os";
|
|
811
|
-
import { dirname as dirname4, join as
|
|
2410
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
812
2411
|
|
|
813
2412
|
class RelayStore {
|
|
814
2413
|
constructor(agentDir) {
|
|
815
2414
|
this.agentDir = agentDir;
|
|
816
2415
|
}
|
|
817
2416
|
get file() {
|
|
818
|
-
return
|
|
2417
|
+
return join6(this.agentDir, RelayStore.FILE);
|
|
819
2418
|
}
|
|
820
2419
|
read() {
|
|
821
2420
|
try {
|
|
822
|
-
const config = JSON.parse(
|
|
2421
|
+
const config = JSON.parse(readFileSync6(this.file, "utf8"));
|
|
823
2422
|
return {
|
|
824
2423
|
url: config.url,
|
|
825
2424
|
host: config.host,
|
|
826
2425
|
devices: Array.isArray(config.devices) ? config.devices : [],
|
|
827
|
-
shares: Array.isArray(config.shares) ? config.shares : []
|
|
2426
|
+
shares: Array.isArray(config.shares) ? config.shares : [],
|
|
2427
|
+
contents: Array.isArray(config.contents) ? config.contents : []
|
|
828
2428
|
};
|
|
829
2429
|
} catch (_a) {
|
|
830
2430
|
return { devices: [] };
|
|
@@ -841,6 +2441,103 @@ class RelayStore {
|
|
|
841
2441
|
var _a;
|
|
842
2442
|
return ((_a = this.read().shares) !== null && _a !== undefined ? _a : []).filter((share) => share.expiresAt > now);
|
|
843
2443
|
}
|
|
2444
|
+
content(contentId, now = Date.now()) {
|
|
2445
|
+
return this.contents(now).find((content) => content.id === contentId);
|
|
2446
|
+
}
|
|
2447
|
+
contents(now = Date.now()) {
|
|
2448
|
+
var _a;
|
|
2449
|
+
return ((_a = this.read().contents) !== null && _a !== undefined ? _a : []).filter((content) => RelayStore.live(content, now)).sort((a, b) => b.createdAt - a.createdAt);
|
|
2450
|
+
}
|
|
2451
|
+
contentData(content) {
|
|
2452
|
+
try {
|
|
2453
|
+
return new Uint8Array(readFileSync6(this.contentFile(content.id)));
|
|
2454
|
+
} catch (_a) {
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
async addContent(input, now = Date.now()) {
|
|
2459
|
+
var _a, _b, _c;
|
|
2460
|
+
const linkKey = randomBytes2(32);
|
|
2461
|
+
const id2 = randomBytes2(16).toString("base64url");
|
|
2462
|
+
const password = input.access === "password" ? input.password : undefined;
|
|
2463
|
+
if (input.access === "password" && !password) {
|
|
2464
|
+
throw new Error("A share with a password needs the password.");
|
|
2465
|
+
}
|
|
2466
|
+
const people = input.access === "people" ? await RelayStore.people(input, id2) : undefined;
|
|
2467
|
+
const key = await RelayContentUtil.contentKey(new Uint8Array(linkKey), id2, password);
|
|
2468
|
+
const days = input.offline ? Math.min(input.days || RELAY_BLOB_MAX_DAYS, RELAY_BLOB_MAX_DAYS) : input.days;
|
|
2469
|
+
const expiresAt = days ? now + days * 24 * 60 * 60 * 1000 : undefined;
|
|
2470
|
+
const offline = input.offline && input.access !== "self" && input.access !== "people";
|
|
2471
|
+
const content = {
|
|
2472
|
+
id: id2,
|
|
2473
|
+
kind: input.kind,
|
|
2474
|
+
title: input.title,
|
|
2475
|
+
createdAt: input.createdAt,
|
|
2476
|
+
...input.type ? { type: input.type } : {},
|
|
2477
|
+
access: input.access,
|
|
2478
|
+
key: RelayBytes.toBase64(key),
|
|
2479
|
+
...input.access === "self" || people ? {} : { linkKey: linkKey.toString("base64url") },
|
|
2480
|
+
...people && input.identity ? { people, owner: input.identity.id } : {},
|
|
2481
|
+
size: input.data.length,
|
|
2482
|
+
...expiresAt ? { expiresAt } : {},
|
|
2483
|
+
...offline && expiresAt ? { offline: { token: randomBytes2(32).toString("base64url"), expiresAt } } : {}
|
|
2484
|
+
};
|
|
2485
|
+
mkdirSync4(dirname4(this.contentFile(id2)), { recursive: true, mode: 448 });
|
|
2486
|
+
writeFileSync4(this.contentFile(id2), input.data, { mode: 384 });
|
|
2487
|
+
const before = this.read();
|
|
2488
|
+
const url = (_a = before.url) !== null && _a !== undefined ? _a : RELAY_DEFAULT_URL;
|
|
2489
|
+
const host = (_b = before.host) !== null && _b !== undefined ? _b : { id: RelayStore.id(), secret: randomBytes2(32).toString("base64url") };
|
|
2490
|
+
this.write({ ...before, url, host, contents: [...(_c = before.contents) !== null && _c !== undefined ? _c : [], content] });
|
|
2491
|
+
return { content, link: this.contentLink(content, { url, host }) };
|
|
2492
|
+
}
|
|
2493
|
+
contentLink(content, config = this.read()) {
|
|
2494
|
+
var _a;
|
|
2495
|
+
var _b, _c;
|
|
2496
|
+
return {
|
|
2497
|
+
relay: (_b = config.url) !== null && _b !== undefined ? _b : RELAY_DEFAULT_URL,
|
|
2498
|
+
host: (_c = (_a = config.host) === null || _a === undefined ? undefined : _a.id) !== null && _c !== undefined ? _c : "",
|
|
2499
|
+
share: content.id,
|
|
2500
|
+
key: content.linkKey,
|
|
2501
|
+
access: content.access,
|
|
2502
|
+
...content.owner ? { owner: content.owner } : {},
|
|
2503
|
+
offline: !!content.offline,
|
|
2504
|
+
kind: content.kind
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
removeContent(contentId) {
|
|
2508
|
+
var _a, _b;
|
|
2509
|
+
const config = this.read();
|
|
2510
|
+
const content = (_a = config.contents) === null || _a === undefined ? undefined : _a.find((candidate) => candidate.id === contentId);
|
|
2511
|
+
if (!content) {
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
this.write({ ...config, contents: (_b = config.contents) === null || _b === undefined ? undefined : _b.filter((candidate) => candidate.id !== contentId) });
|
|
2515
|
+
rmSync2(this.contentFile(contentId), { force: true });
|
|
2516
|
+
return content;
|
|
2517
|
+
}
|
|
2518
|
+
static async people(input, id2) {
|
|
2519
|
+
var _a;
|
|
2520
|
+
const { identity } = input;
|
|
2521
|
+
const people = (_a = input.people) !== null && _a !== undefined ? _a : [];
|
|
2522
|
+
if (!identity || people.length === 0) {
|
|
2523
|
+
throw new Error("A share with Ta friends needs them, and this Ta.");
|
|
2524
|
+
}
|
|
2525
|
+
return Promise.all(people.map(async (person) => {
|
|
2526
|
+
if (!await RelayIdentityUtil.check(person)) {
|
|
2527
|
+
throw new Error(`${person.name} is not a Ta friend whose keys check.`);
|
|
2528
|
+
}
|
|
2529
|
+
return { id: person.id, name: person.name, key: RelayBytes.toBase64(await RelayContentUtil.peopleKey(identity, person.box, id2)) };
|
|
2530
|
+
}));
|
|
2531
|
+
}
|
|
2532
|
+
contentFile(contentId) {
|
|
2533
|
+
return join6(this.agentDir, "shares", contentId);
|
|
2534
|
+
}
|
|
2535
|
+
static live(content, now) {
|
|
2536
|
+
return content.expiresAt === undefined || content.expiresAt > now;
|
|
2537
|
+
}
|
|
2538
|
+
static id() {
|
|
2539
|
+
return id();
|
|
2540
|
+
}
|
|
844
2541
|
shareRoot(root, name, now = Date.now()) {
|
|
845
2542
|
var _a, _b, _c;
|
|
846
2543
|
const before = this.read();
|
|
@@ -894,6 +2591,15 @@ class RelayStore {
|
|
|
894
2591
|
return createHash3("sha256").update(secret).digest("base64url");
|
|
895
2592
|
}
|
|
896
2593
|
write(config) {
|
|
2594
|
+
var _a;
|
|
2595
|
+
var _b;
|
|
2596
|
+
const now = Date.now();
|
|
2597
|
+
for (const content of (_b = config.contents) !== null && _b !== undefined ? _b : []) {
|
|
2598
|
+
if (!RelayStore.live(content, now)) {
|
|
2599
|
+
rmSync2(this.contentFile(content.id), { force: true });
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
config = { ...config, contents: (_a = config.contents) === null || _a === undefined ? undefined : _a.filter((content) => RelayStore.live(content, now)) };
|
|
897
2603
|
mkdirSync4(dirname4(this.file), { recursive: true });
|
|
898
2604
|
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
899
2605
|
writeFileSync4(temporary, `${JSON.stringify(config, null, 2)}
|
|
@@ -904,48 +2610,13 @@ class RelayStore {
|
|
|
904
2610
|
}
|
|
905
2611
|
var id = () => randomBytes2(16).toString("base64url");
|
|
906
2612
|
var init_relay_store = __esm(() => {
|
|
2613
|
+
init_relay_bytes();
|
|
2614
|
+
init_relay_content();
|
|
2615
|
+
init_relay_identity();
|
|
907
2616
|
init_relay_protocol();
|
|
908
2617
|
RelayStore.FILE = "relay.json";
|
|
909
2618
|
});
|
|
910
2619
|
|
|
911
|
-
// ../../ta-packages/ta-relay/esm/common/relay-pairing.js
|
|
912
|
-
var exports_relay_pairing = {};
|
|
913
|
-
__export(exports_relay_pairing, {
|
|
914
|
-
RelayPairingUtil: () => RelayPairingUtil
|
|
915
|
-
});
|
|
916
|
-
var RelayPairingUtil;
|
|
917
|
-
var init_relay_pairing = __esm(() => {
|
|
918
|
-
init_relay_protocol();
|
|
919
|
-
(function(RelayPairingUtil2) {
|
|
920
|
-
function link(pairing) {
|
|
921
|
-
const fragment = new URLSearchParams({ v: "1", h: pairing.host, d: pairing.device, k: pairing.key });
|
|
922
|
-
if (pairing.name) {
|
|
923
|
-
fragment.set("n", pairing.name);
|
|
924
|
-
}
|
|
925
|
-
return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
|
|
926
|
-
}
|
|
927
|
-
RelayPairingUtil2.link = link;
|
|
928
|
-
function parse(link2) {
|
|
929
|
-
var _a;
|
|
930
|
-
const url = new URL(link2.trim());
|
|
931
|
-
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
932
|
-
const [host, device, key] = ["h", "d", "k"].map((name) => {
|
|
933
|
-
var _a2;
|
|
934
|
-
return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
|
|
935
|
-
});
|
|
936
|
-
if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_PAIR_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
|
|
937
|
-
throw new Error("Not a pairing link of Ta.");
|
|
938
|
-
}
|
|
939
|
-
return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined };
|
|
940
|
-
}
|
|
941
|
-
RelayPairingUtil2.parse = parse;
|
|
942
|
-
function websocketUrl(relay, path) {
|
|
943
|
-
return relay.replace(/^http/, "ws") + path;
|
|
944
|
-
}
|
|
945
|
-
RelayPairingUtil2.websocketUrl = websocketUrl;
|
|
946
|
-
})(RelayPairingUtil || (RelayPairingUtil = {}));
|
|
947
|
-
});
|
|
948
|
-
|
|
949
2620
|
// ../../ta-packages/ta-relay/esm/common/qr-code.js
|
|
950
2621
|
var exports_qr_code = {};
|
|
951
2622
|
__export(exports_qr_code, {
|
|
@@ -1793,7 +3464,7 @@ var init_exec_server = __esm(() => {
|
|
|
1793
3464
|
|
|
1794
3465
|
// ../../ta-packages/ta-harness/esm/node/ta-cli.js
|
|
1795
3466
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
1796
|
-
import { dirname as dirname5, join as
|
|
3467
|
+
import { dirname as dirname5, join as join7 } from "node:path";
|
|
1797
3468
|
import { parseArgs } from "node:util";
|
|
1798
3469
|
|
|
1799
3470
|
// ../../ai-packages/ai-coding-agent/esm/node/pi/pi-bundle-util.js
|
|
@@ -2372,8 +4043,15 @@ var TaPackages;
|
|
|
2372
4043
|
"@celljs/ta-computer-use",
|
|
2373
4044
|
"@celljs/ta-changes",
|
|
2374
4045
|
"@celljs/ta-cron",
|
|
4046
|
+
"@celljs/ta-notify",
|
|
4047
|
+
"@celljs/ta-recall",
|
|
4048
|
+
"@celljs/ta-glance",
|
|
4049
|
+
"@celljs/ta-games",
|
|
2375
4050
|
"@celljs/ta-bots",
|
|
2376
|
-
"@celljs/ta-agents"
|
|
4051
|
+
"@celljs/ta-agents",
|
|
4052
|
+
"@celljs/ta-manual",
|
|
4053
|
+
"@celljs/ta-share",
|
|
4054
|
+
"@celljs/ta-rooms"
|
|
2377
4055
|
];
|
|
2378
4056
|
TaPackages2.SETTINGS_FILE = "ta.json";
|
|
2379
4057
|
function builtins(packageDir = process.env.PI_PACKAGE_DIR) {
|
|
@@ -2519,7 +4197,7 @@ var TaPackages;
|
|
|
2519
4197
|
// ../../ta-packages/ta-harness/esm/node/ta-cli.js
|
|
2520
4198
|
var SERVE_HELP = `Usage: ta serve [--host <host>] [--port <port>] [--web] [--exec <url>]
|
|
2521
4199
|
|
|
2522
|
-
Serves
|
|
4200
|
+
Serves the sessions of Ta over WebSocket to any number of clients, and its web client. Stops on SIGINT or SIGTERM.
|
|
2523
4201
|
|
|
2524
4202
|
--host Address to listen on. Default: 127.0.0.1
|
|
2525
4203
|
--port Port to listen on. Default: the port of the last start if it is free, so that a web app
|
|
@@ -2582,7 +4260,7 @@ var TaCli;
|
|
|
2582
4260
|
if (argv[0] === "gateway" && options.gatewayEntry) {
|
|
2583
4261
|
const { GatewayCli } = await import(options.gatewayEntry);
|
|
2584
4262
|
await GatewayCli.run(argv.slice(1), {
|
|
2585
|
-
publicDir:
|
|
4263
|
+
publicDir: join7(dirname5(options.serveEntry), "..", "public"),
|
|
2586
4264
|
taCommand: [process.execPath, process.argv[1]]
|
|
2587
4265
|
});
|
|
2588
4266
|
return;
|