@celljs/ta 4.15.2 → 4.17.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 +1 -0
- package/README.md +1 -0
- package/dist/cli.mjs +2227 -203
- package/dist/gateway.mjs +2391 -291
- package/dist/pi/CHANGELOG.md +19 -0
- package/dist/pi/package.json +1 -1
- package/dist/pi/packages/ta-3d/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-3d/package.json +2 -1
- package/dist/pi/packages/ta-agents/README.en.md +14 -2
- package/dist/pi/packages/ta-agents/README.md +14 -2
- package/dist/pi/packages/ta-agents/extension/index.mjs +286 -111
- package/dist/pi/packages/ta-agents/host/index.mjs +662 -0
- package/dist/pi/packages/ta-agents/lib/acp-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-agents/lib/acp-protocol.js +5 -0
- package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +36 -2
- package/dist/pi/packages/ta-agents/lib/agent-catalog.js +76 -6
- package/dist/pi/packages/ta-agents/lib/agent-installer.d.ts +55 -0
- package/dist/pi/packages/ta-agents/lib/agent-installer.js +140 -0
- package/dist/pi/packages/ta-agents/lib/agent-installs.d.ts +25 -0
- package/dist/pi/packages/ta-agents/lib/agent-installs.js +64 -0
- package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts +6 -0
- package/dist/pi/packages/ta-agents/lib/agent-prompt.js +9 -0
- package/dist/pi/packages/ta-agents/lib/agent-refresh.d.ts +11 -0
- package/dist/pi/packages/ta-agents/lib/agent-refresh.js +37 -0
- package/dist/pi/packages/ta-agents/lib/agent-session.d.ts +0 -2
- package/dist/pi/packages/ta-agents/lib/agent-session.js +3 -6
- package/dist/pi/packages/ta-agents/lib/agent-turn.d.ts +7 -2
- package/dist/pi/packages/ta-agents/lib/agent-turn.js +8 -4
- package/dist/pi/packages/ta-agents/lib/agents-protocol.d.ts +26 -0
- package/dist/pi/packages/ta-agents/lib/agents-protocol.js +11 -0
- package/dist/pi/packages/ta-agents/lib/agents-settings.d.ts +10 -0
- package/dist/pi/packages/ta-agents/lib/agents-settings.js +165 -0
- package/dist/pi/packages/ta-agents/lib/extension.d.ts +3 -1
- package/dist/pi/packages/ta-agents/lib/extension.js +17 -4
- package/dist/pi/packages/ta-agents/lib/host.d.ts +35 -0
- package/dist/pi/packages/ta-agents/lib/host.js +96 -0
- package/dist/pi/packages/ta-agents/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-agents/lib/react.js +8 -0
- package/dist/pi/packages/ta-agents/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-agents/lib/style.js +30 -0
- package/dist/pi/packages/ta-agents/lib/texts.d.ts +18 -0
- package/dist/pi/packages/ta-agents/lib/texts.js +18 -0
- package/dist/pi/packages/ta-agents/lib/web-words.d.ts +30 -0
- package/dist/pi/packages/ta-agents/lib/web-words.js +98 -0
- package/dist/pi/packages/ta-agents/lib/web.d.ts +4 -0
- package/dist/pi/packages/ta-agents/lib/web.js +14 -0
- package/dist/pi/packages/ta-agents/package.json +21 -5
- package/dist/pi/packages/ta-agents/web/index.js +385 -0
- package/dist/pi/packages/ta-app-use/README.en.md +28 -0
- package/dist/pi/packages/ta-app-use/README.md +28 -0
- package/dist/pi/packages/ta-app-use/extension/index.mjs +534 -0
- package/dist/pi/packages/ta-app-use/host/index.mjs +136 -0
- package/dist/pi/packages/ta-app-use/lib/app-host.d.ts +32 -0
- package/dist/pi/packages/ta-app-use/lib/app-host.js +79 -0
- package/dist/pi/packages/ta-app-use/lib/app-protocol.d.ts +23 -0
- package/dist/pi/packages/ta-app-use/lib/app-protocol.js +9 -0
- package/dist/pi/packages/ta-app-use/lib/app-util.d.ts +18 -0
- package/dist/pi/packages/ta-app-use/lib/app-util.js +71 -0
- package/dist/pi/packages/ta-app-use/lib/extension.d.ts +80 -0
- package/dist/pi/packages/ta-app-use/lib/extension.js +125 -0
- package/dist/pi/packages/ta-app-use/lib/host.d.ts +7 -0
- package/dist/pi/packages/ta-app-use/lib/host.js +16 -0
- package/dist/pi/packages/ta-app-use/lib/i18n.d.ts +38 -0
- package/dist/pi/packages/ta-app-use/lib/i18n.js +130 -0
- package/dist/pi/packages/ta-app-use/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-app-use/lib/index.js +93 -0
- package/dist/pi/packages/ta-app-use/lib/screen-cursor.d.ts +33 -0
- package/dist/pi/packages/ta-app-use/lib/screen-cursor.js +134 -0
- package/dist/pi/packages/ta-app-use/lib/screen-dom.d.ts +19 -0
- package/dist/pi/packages/ta-app-use/lib/screen-dom.js +184 -0
- package/dist/pi/packages/ta-app-use/lib/screen-driver.d.ts +46 -0
- package/dist/pi/packages/ta-app-use/lib/screen-driver.js +174 -0
- package/dist/pi/packages/ta-app-use/lib/screen-protocol.d.ts +67 -0
- package/dist/pi/packages/ta-app-use/lib/screen-protocol.js +8 -0
- package/dist/pi/packages/ta-app-use/lib/screen-text.d.ts +13 -0
- package/dist/pi/packages/ta-app-use/lib/screen-text.js +69 -0
- package/dist/pi/packages/ta-app-use/lib/screen-window.d.ts +68 -0
- package/dist/pi/packages/ta-app-use/lib/screen-window.js +376 -0
- package/dist/pi/packages/ta-app-use/lib/tool-line.d.ts +11 -0
- package/dist/pi/packages/ta-app-use/lib/tool-line.js +69 -0
- package/dist/pi/packages/ta-app-use/package.json +63 -0
- package/dist/pi/packages/ta-app-use/web/index.js +1520 -0
- package/dist/pi/packages/ta-bots/README.en.md +1 -0
- package/dist/pi/packages/ta-bots/README.md +1 -0
- package/dist/pi/packages/ta-bots/extension/index.mjs +25 -22
- package/dist/pi/packages/ta-bots/host/index.mjs +726 -151
- package/dist/pi/packages/ta-bots/lib/bot-service.d.ts +9 -1
- package/dist/pi/packages/ta-bots/lib/bot-service.js +49 -8
- package/dist/pi/packages/ta-bots/lib/channel-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-bots/lib/extension.d.ts +2 -2
- package/dist/pi/packages/ta-bots/lib/extension.js +28 -24
- package/dist/pi/packages/ta-bots/lib/index.js +4 -0
- package/dist/pi/packages/ta-bots/lib/page.d.ts +7 -1
- package/dist/pi/packages/ta-bots/lib/page.js +17 -0
- package/dist/pi/packages/ta-bots/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-bots/lib/style.js +1 -1
- package/dist/pi/packages/ta-bots/lib/wecom-channel.js +1 -1
- package/dist/pi/packages/ta-bots/lib/weixin-api.d.ts +1 -0
- package/dist/pi/packages/ta-bots/lib/weixin-channel.js +2 -1
- package/dist/pi/packages/ta-bots/package.json +1 -1
- package/dist/pi/packages/ta-bots/web/index.js +13 -2
- package/dist/pi/packages/ta-call/README.en.md +9 -0
- package/dist/pi/packages/ta-call/README.md +9 -0
- package/dist/pi/packages/ta-call/extension/index.mjs +474 -0
- package/dist/pi/packages/ta-call/host/index.mjs +899 -0
- package/dist/pi/packages/ta-call/lib/call-host.d.ts +127 -0
- package/dist/pi/packages/ta-call/lib/call-host.js +377 -0
- package/dist/pi/packages/ta-call/lib/call-protocol.d.ts +33 -0
- package/dist/pi/packages/ta-call/lib/call-protocol.js +10 -0
- package/dist/pi/packages/ta-call/lib/call-util.d.ts +50 -0
- package/dist/pi/packages/ta-call/lib/call-util.js +250 -0
- package/dist/pi/packages/ta-call/lib/extension.d.ts +20 -0
- package/dist/pi/packages/ta-call/lib/extension.js +114 -0
- package/dist/pi/packages/ta-call/lib/host.d.ts +7 -0
- package/dist/pi/packages/ta-call/lib/host.js +20 -0
- package/dist/pi/packages/ta-call/lib/i18n.d.ts +16 -0
- package/dist/pi/packages/ta-call/lib/i18n.js +38 -0
- package/dist/pi/packages/ta-call/lib/index.d.ts +7 -0
- package/dist/pi/packages/ta-call/lib/index.js +60 -0
- package/dist/pi/packages/ta-call/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-call/lib/react.js +8 -0
- package/dist/pi/packages/ta-call/package.json +64 -0
- package/dist/pi/packages/ta-call/web/index.js +552 -0
- package/dist/pi/packages/ta-changes/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-changes/lib/card.js +4 -1
- package/dist/pi/packages/ta-changes/package.json +1 -1
- package/dist/pi/packages/ta-changes/web/index.js +2 -0
- package/dist/pi/packages/ta-channels/extension/index.mjs +155 -194
- package/dist/pi/packages/ta-channels/host/index.mjs +2039 -1503
- package/dist/pi/packages/ta-channels/lib/agent-menu.js +2 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.js +2 -2
- package/dist/pi/packages/ta-channels/lib/channels-text.d.ts +38 -0
- package/dist/pi/packages/ta-channels/lib/channels-text.js +173 -0
- package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +0 -48
- package/dist/pi/packages/ta-channels/lib/channels-util.js +1 -223
- package/dist/pi/packages/ta-channels/lib/create.js +5 -1
- package/dist/pi/packages/ta-channels/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-ja.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n.js +4 -535
- package/dist/pi/packages/ta-channels/lib/index.js +2 -1
- package/dist/pi/packages/ta-channels/lib/notice-util.d.ts +15 -0
- package/dist/pi/packages/ta-channels/lib/notice-util.js +61 -0
- package/dist/pi/packages/ta-channels/lib/notice.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/notice.js +5 -4
- package/dist/pi/packages/ta-channels/lib/room.js +4 -3
- package/dist/pi/packages/ta-channels/lib/sidebar-head.d.ts +6 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-head.js +67 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-hooks.d.ts +51 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-hooks.js +230 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-rows.d.ts +71 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-rows.js +105 -0
- package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +0 -4
- package/dist/pi/packages/ta-channels/lib/sidebar.js +35 -396
- package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/style.js +0 -1
- package/dist/pi/packages/ta-channels/lib/tasks.js +2 -1
- package/dist/pi/packages/ta-channels/lib/team-store.d.ts +78 -0
- package/dist/pi/packages/ta-channels/lib/team-store.js +261 -0
- package/dist/pi/packages/ta-channels/lib/team-tools.js +3 -2
- package/dist/pi/packages/ta-channels/lib/team.d.ts +3 -76
- package/dist/pi/packages/ta-channels/lib/team.js +5 -254
- package/dist/pi/packages/ta-channels/package.json +1 -1
- package/dist/pi/packages/ta-channels/web/index.js +889 -809
- package/dist/pi/packages/ta-computer-use/package.json +1 -1
- package/dist/pi/packages/ta-cron/README.en.md +19 -3
- package/dist/pi/packages/ta-cron/README.md +19 -3
- package/dist/pi/packages/ta-cron/extension/index.mjs +396 -111
- package/dist/pi/packages/ta-cron/host/index.mjs +633 -49
- package/dist/pi/packages/ta-cron/lib/chat-task.d.ts +5 -3
- package/dist/pi/packages/ta-cron/lib/chat-task.js +15 -10
- package/dist/pi/packages/ta-cron/lib/commands.d.ts +7 -4
- package/dist/pi/packages/ta-cron/lib/commands.js +26 -47
- package/dist/pi/packages/ta-cron/lib/cron-expression.d.ts +8 -0
- package/dist/pi/packages/ta-cron/lib/cron-expression.js +43 -1
- package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts +54 -7
- package/dist/pi/packages/ta-cron/lib/cron-protocol.js +16 -2
- package/dist/pi/packages/ta-cron/lib/editor.d.ts +3 -0
- package/dist/pi/packages/ta-cron/lib/editor.js +106 -36
- package/dist/pi/packages/ta-cron/lib/extension.js +1 -1
- package/dist/pi/packages/ta-cron/lib/form-util.d.ts +16 -6
- package/dist/pi/packages/ta-cron/lib/form-util.js +40 -28
- package/dist/pi/packages/ta-cron/lib/host.js +17 -1
- package/dist/pi/packages/ta-cron/lib/i18n.d.ts +39 -5
- package/dist/pi/packages/ta-cron/lib/i18n.js +160 -24
- package/dist/pi/packages/ta-cron/lib/index.js +4 -0
- package/dist/pi/packages/ta-cron/lib/page.d.ts +3 -2
- package/dist/pi/packages/ta-cron/lib/page.js +13 -2
- package/dist/pi/packages/ta-cron/lib/schedule-util.d.ts +4 -0
- package/dist/pi/packages/ta-cron/lib/schedule-util.js +52 -4
- package/dist/pi/packages/ta-cron/lib/scheduler.d.ts +56 -6
- package/dist/pi/packages/ta-cron/lib/scheduler.js +209 -27
- package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-cron/lib/style.js +50 -21
- package/dist/pi/packages/ta-cron/lib/task-list.d.ts +23 -0
- package/dist/pi/packages/ta-cron/lib/task-list.js +70 -0
- package/dist/pi/packages/ta-cron/lib/task-row.d.ts +19 -0
- package/dist/pi/packages/ta-cron/lib/task-row.js +246 -0
- package/dist/pi/packages/ta-cron/lib/task-util.d.ts +10 -6
- package/dist/pi/packages/ta-cron/lib/task-util.js +53 -19
- package/dist/pi/packages/ta-cron/lib/task-watchers.d.ts +30 -0
- package/dist/pi/packages/ta-cron/lib/task-watchers.js +90 -0
- package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +3 -2
- package/dist/pi/packages/ta-cron/lib/tasks-view.js +48 -193
- package/dist/pi/packages/ta-cron/lib/tool-line.js +4 -0
- package/dist/pi/packages/ta-cron/lib/tool.d.ts +7 -0
- package/dist/pi/packages/ta-cron/lib/tool.js +18 -8
- package/dist/pi/packages/ta-cron/lib/when.d.ts +39 -0
- package/dist/pi/packages/ta-cron/lib/when.js +231 -0
- package/dist/pi/packages/ta-cron/package.json +2 -1
- package/dist/pi/packages/ta-cron/web/index.js +1091 -340
- package/dist/pi/packages/ta-extensions/lib/market-detail.js +9 -5
- package/dist/pi/packages/ta-extensions/lib/page.js +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.js +1 -1
- package/dist/pi/packages/ta-extensions/package.json +1 -1
- package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +9 -7
- package/dist/pi/packages/ta-extensions/web/index.js +777 -237
- package/dist/pi/packages/ta-feedback/README.en.md +10 -0
- package/dist/pi/packages/ta-feedback/README.md +10 -0
- package/dist/pi/packages/ta-feedback/extension/index.mjs +451 -0
- package/dist/pi/packages/ta-feedback/host/index.mjs +1187 -0
- package/dist/pi/packages/ta-feedback/lib/extension.d.ts +31 -0
- package/dist/pi/packages/ta-feedback/lib/extension.js +160 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-git.d.ts +25 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-git.js +44 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-host.d.ts +133 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-host.js +668 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-protocol.d.ts +127 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-protocol.js +41 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-util.d.ts +79 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-util.js +252 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-view.d.ts +11 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-view.js +244 -0
- package/dist/pi/packages/ta-feedback/lib/host.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/host.js +19 -0
- package/dist/pi/packages/ta-feedback/lib/i18n.d.ts +69 -0
- package/dist/pi/packages/ta-feedback/lib/i18n.js +250 -0
- package/dist/pi/packages/ta-feedback/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/index.js +88 -0
- package/dist/pi/packages/ta-feedback/lib/page.d.ts +35 -0
- package/dist/pi/packages/ta-feedback/lib/page.js +135 -0
- package/dist/pi/packages/ta-feedback/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/react.js +8 -0
- package/dist/pi/packages/ta-feedback/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-feedback/lib/style.js +71 -0
- package/dist/pi/packages/ta-feedback/package.json +65 -0
- package/dist/pi/packages/ta-feedback/web/index.js +939 -0
- package/dist/pi/packages/ta-games/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-games/lib/style.js +1 -1
- package/dist/pi/packages/ta-games/package.json +1 -1
- package/dist/pi/packages/ta-games/web/index.js +1 -1
- package/dist/pi/packages/ta-glance/README.en.md +2 -0
- package/dist/pi/packages/ta-glance/README.md +2 -0
- package/dist/pi/packages/ta-glance/extension/index.mjs +135 -27
- package/dist/pi/packages/ta-glance/lib/card.js +155 -35
- package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/glance-json.js +8 -1
- package/dist/pi/packages/ta-glance/lib/glance-prompt.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/glance-prompt.js +9 -6
- package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +43 -4
- package/dist/pi/packages/ta-glance/lib/glance-protocol.js +39 -1
- package/dist/pi/packages/ta-glance/lib/glance-spec.js +125 -23
- package/dist/pi/packages/ta-glance/lib/glance-speech.d.ts +13 -0
- package/dist/pi/packages/ta-glance/lib/glance-speech.js +45 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.d.ts +13 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.js +28 -0
- package/dist/pi/packages/ta-glance/lib/i18n.d.ts +5 -0
- package/dist/pi/packages/ta-glance/lib/i18n.js +20 -0
- package/dist/pi/packages/ta-glance/lib/index.js +11 -1
- package/dist/pi/packages/ta-glance/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/style.js +82 -5
- package/dist/pi/packages/ta-glance/package.json +2 -1
- package/dist/pi/packages/ta-glance/web/index.js +508 -62
- package/dist/pi/packages/ta-initiative/extension/index.mjs +3 -2
- package/dist/pi/packages/ta-initiative/host/index.mjs +1 -1
- package/dist/pi/packages/ta-initiative/lib/chat-proposals.js +1 -1
- package/dist/pi/packages/ta-initiative/lib/index.js +1 -0
- package/dist/pi/packages/ta-initiative/lib/material-util.js +1 -1
- package/dist/pi/packages/ta-initiative/lib/settings.js +2 -1
- package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
- package/dist/pi/packages/ta-initiative/package.json +1 -1
- package/dist/pi/packages/ta-initiative/web/index.js +5 -3
- package/dist/pi/packages/ta-launcher/package.json +1 -1
- package/dist/pi/packages/ta-manual/lib/manual-util.d.ts +1 -1
- package/dist/pi/packages/ta-manual/lib/pictures-c.js +15 -0
- package/dist/pi/packages/ta-manual/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-manual/lib/style.js +1 -1
- package/dist/pi/packages/ta-manual/lib/topics-a.d.ts +3 -0
- package/dist/pi/packages/ta-manual/lib/topics-a.js +295 -0
- package/dist/pi/packages/ta-manual/lib/topics-model.d.ts +46 -0
- package/dist/pi/packages/ta-manual/lib/topics-model.js +21 -0
- package/dist/pi/packages/ta-manual/lib/topics.d.ts +1 -44
- package/dist/pi/packages/ta-manual/lib/topics.js +28 -318
- package/dist/pi/packages/ta-manual/package.json +1 -1
- package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +12 -10
- package/dist/pi/packages/ta-manual/web/index.js +97 -24
- package/dist/pi/packages/ta-moments/extension/index.mjs +740 -194
- package/dist/pi/packages/ta-moments/host/index.mjs +1393 -834
- package/dist/pi/packages/ta-moments/lib/index.js +3 -1
- package/dist/pi/packages/ta-moments/lib/moments-host-base.d.ts +96 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-base.js +276 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-pictures.d.ts +22 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-pictures.js +167 -0
- package/dist/pi/packages/ta-moments/lib/moments-host.d.ts +4 -84
- package/dist/pi/packages/ta-moments/lib/moments-host.js +13 -426
- package/dist/pi/packages/ta-moments/lib/page.js +3 -3
- package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-moments/lib/style.js +1 -1
- package/dist/pi/packages/ta-moments/lib/talk-host-base.d.ts +71 -0
- package/dist/pi/packages/ta-moments/lib/talk-host-base.js +171 -0
- package/dist/pi/packages/ta-moments/lib/talk-host.d.ts +3 -62
- package/dist/pi/packages/ta-moments/lib/talk-host.js +14 -169
- package/dist/pi/packages/ta-moments/package.json +1 -1
- package/dist/pi/packages/ta-moments/web/index.js +686 -147
- package/dist/pi/packages/ta-nearby/extension/index.mjs +9 -0
- package/dist/pi/packages/ta-nearby/host/index.mjs +1073 -1018
- package/dist/pi/packages/ta-nearby/lib/index.js +8 -5
- package/dist/pi/packages/ta-nearby/lib/nearby-home.d.ts +13 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-home.js +91 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.d.ts +12 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.js +113 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-page.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-page.js +157 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-base.d.ts +161 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-base.js +343 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.d.ts +41 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.js +297 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +6 -167
- package/dist/pi/packages/ta-nearby/lib/nearby-service.js +38 -638
- package/dist/pi/packages/ta-nearby/lib/nearby-show-view.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-show-view.js +88 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-spot.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-spot.js +25 -3
- package/dist/pi/packages/ta-nearby/lib/page.d.ts +27 -20
- package/dist/pi/packages/ta-nearby/lib/page.js +15 -417
- package/dist/pi/packages/ta-nearby/lib/server-texts.d.ts +1 -1
- package/dist/pi/packages/ta-nearby/lib/server-texts.js +9 -1
- package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
- package/dist/pi/packages/ta-nearby/package.json +1 -1
- package/dist/pi/packages/ta-nearby/web/index.js +370 -362
- package/dist/pi/packages/ta-notify/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-notify/lib/settings.js +1 -0
- package/dist/pi/packages/ta-notify/package.json +1 -1
- package/dist/pi/packages/ta-notify/web/index.js +1 -0
- package/dist/pi/packages/ta-plot/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-plot/package.json +2 -1
- package/dist/pi/packages/ta-recall/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-recall/host/index.mjs +1 -0
- package/dist/pi/packages/ta-recall/lib/settings.js +1 -0
- package/dist/pi/packages/ta-recall/package.json +1 -1
- package/dist/pi/packages/ta-recall/web/index.js +2 -0
- package/dist/pi/packages/ta-rooms/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-rooms/host/index.mjs +497 -492
- package/dist/pi/packages/ta-rooms/lib/double-agents.js +6 -6
- package/dist/pi/packages/ta-rooms/lib/double-grants.js +10 -10
- package/dist/pi/packages/ta-rooms/lib/double-host.js +6 -5
- package/dist/pi/packages/ta-rooms/lib/double-tasks-base.d.ts +55 -0
- package/dist/pi/packages/ta-rooms/lib/double-tasks-base.js +279 -0
- package/dist/pi/packages/ta-rooms/lib/double-tasks.d.ts +3 -45
- package/dist/pi/packages/ta-rooms/lib/double-tasks.js +14 -282
- package/dist/pi/packages/ta-rooms/lib/double-user.js +2 -2
- package/dist/pi/packages/ta-rooms/lib/friend-notices.js +2 -2
- package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +1 -0
- package/dist/pi/packages/ta-rooms/lib/i18n.js +8 -4
- package/dist/pi/packages/ta-rooms/lib/index.js +18 -2
- package/dist/pi/packages/ta-rooms/lib/members-view.js +37 -3
- package/dist/pi/packages/ta-rooms/lib/page.d.ts +36 -1
- package/dist/pi/packages/ta-rooms/lib/page.js +76 -1
- package/dist/pi/packages/ta-rooms/lib/room-view.js +22 -17
- package/dist/pi/packages/ta-rooms/lib/rooms-home.js +1 -0
- package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-rooms/lib/style.js +32 -6
- package/dist/pi/packages/ta-rooms/package.json +1 -1
- package/dist/pi/packages/ta-rooms/web/index.js +223 -38
- package/dist/pi/packages/ta-secrets/README.en.md +22 -0
- package/dist/pi/packages/ta-secrets/README.md +22 -0
- package/dist/pi/packages/ta-secrets/extension/index.mjs +462 -0
- package/dist/pi/packages/ta-secrets/host/index.mjs +1341 -0
- package/dist/pi/packages/ta-secrets/lib/command-prelude.d.ts +36 -0
- package/dist/pi/packages/ta-secrets/lib/command-prelude.js +66 -0
- package/dist/pi/packages/ta-secrets/lib/extension.d.ts +28 -0
- package/dist/pi/packages/ta-secrets/lib/extension.js +156 -0
- package/dist/pi/packages/ta-secrets/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/host.js +15 -0
- package/dist/pi/packages/ta-secrets/lib/i18n.d.ts +47 -0
- package/dist/pi/packages/ta-secrets/lib/i18n.js +166 -0
- package/dist/pi/packages/ta-secrets/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/index.js +28 -0
- package/dist/pi/packages/ta-secrets/lib/personal-info.d.ts +26 -0
- package/dist/pi/packages/ta-secrets/lib/personal-info.js +108 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-certs.d.ts +40 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-certs.js +200 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-scenario.d.ts +6 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-scenario.js +91 -0
- package/dist/pi/packages/ta-secrets/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/react.js +8 -0
- package/dist/pi/packages/ta-secrets/lib/scrubber.d.ts +20 -0
- package/dist/pi/packages/ta-secrets/lib/scrubber.js +70 -0
- package/dist/pi/packages/ta-secrets/lib/secrets-protocol.d.ts +106 -0
- package/dist/pi/packages/ta-secrets/lib/secrets-protocol.js +134 -0
- package/dist/pi/packages/ta-secrets/lib/server-texts.d.ts +14 -0
- package/dist/pi/packages/ta-secrets/lib/server-texts.js +62 -0
- package/dist/pi/packages/ta-secrets/lib/settings.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/settings.js +179 -0
- package/dist/pi/packages/ta-secrets/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/style.js +32 -0
- package/dist/pi/packages/ta-secrets/lib/vault-fixture.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/vault-fixture.js +22 -0
- package/dist/pi/packages/ta-secrets/lib/vault-proxy.d.ts +94 -0
- package/dist/pi/packages/ta-secrets/lib/vault-proxy.js +357 -0
- package/dist/pi/packages/ta-secrets/lib/vault-service.d.ts +111 -0
- package/dist/pi/packages/ta-secrets/lib/vault-service.js +429 -0
- package/dist/pi/packages/ta-secrets/lib/vault-store.d.ts +48 -0
- package/dist/pi/packages/ta-secrets/lib/vault-store.js +107 -0
- package/dist/pi/packages/ta-secrets/package.json +67 -0
- package/dist/pi/packages/ta-secrets/web/index.js +579 -0
- package/dist/pi/packages/ta-share/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-share/host/index.mjs +172 -21
- package/dist/pi/packages/ta-share/lib/i18n.d.ts +1 -0
- package/dist/pi/packages/ta-share/lib/i18n.js +4 -0
- package/dist/pi/packages/ta-share/lib/index.js +1 -1
- package/dist/pi/packages/ta-share/lib/share-dialog.js +1 -0
- package/dist/pi/packages/ta-share/lib/share-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-share/lib/share-service.d.ts +11 -1
- package/dist/pi/packages/ta-share/lib/share-service.js +62 -4
- package/dist/pi/packages/ta-share/lib/snapshot.d.ts +8 -2
- package/dist/pi/packages/ta-share/lib/snapshot.js +93 -7
- package/dist/pi/packages/ta-share/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-share/lib/style.js +1 -1
- package/dist/pi/packages/ta-share/package.json +1 -1
- package/dist/pi/packages/ta-share/web/index.js +7 -2
- package/dist/pi/packages/ta-sync/host/index.mjs +1154 -755
- package/dist/pi/packages/ta-sync/lib/host.js +3 -0
- package/dist/pi/packages/ta-sync/lib/index.js +6 -2
- package/dist/pi/packages/ta-sync/lib/migrate-archive.d.ts +8 -6
- package/dist/pi/packages/ta-sync/lib/migrate-archive.js +24 -28
- package/dist/pi/packages/ta-sync/lib/migrate-i18n.d.ts +10 -0
- package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +40 -0
- package/dist/pi/packages/ta-sync/lib/migrate-paths.d.ts +24 -0
- package/dist/pi/packages/ta-sync/lib/migrate-paths.js +230 -0
- package/dist/pi/packages/ta-sync/lib/migrate-protocol.d.ts +18 -0
- package/dist/pi/packages/ta-sync/lib/migrate-service.d.ts +11 -1
- package/dist/pi/packages/ta-sync/lib/migrate-service.js +28 -1
- package/dist/pi/packages/ta-sync/lib/move-panel.d.ts +9 -1
- package/dist/pi/packages/ta-sync/lib/move-panel.js +69 -5
- package/dist/pi/packages/ta-sync/lib/server-texts.d.ts +1 -0
- package/dist/pi/packages/ta-sync/lib/server-texts.js +9 -0
- package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-sync/lib/style.js +8 -1
- package/dist/pi/packages/ta-sync/lib/sync-service-base.d.ts +78 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-base.js +224 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-space.d.ts +36 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-space.js +210 -0
- package/dist/pi/packages/ta-sync/lib/sync-service.d.ts +3 -99
- package/dist/pi/packages/ta-sync/lib/sync-service.js +2 -412
- package/dist/pi/packages/ta-sync/package.json +1 -1
- package/dist/pi/packages/ta-sync/web/index.js +138 -5
- package/dist/pi/packages/ta-sync-cloud/package.json +1 -1
- package/dist/pi/packages/ta-team/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-team/host/index.mjs +1 -0
- package/dist/pi/packages/ta-team/lib/dialogs.d.ts +0 -2
- package/dist/pi/packages/ta-team/lib/dialogs.js +0 -227
- package/dist/pi/packages/ta-team/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-ja.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh-tw.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n.d.ts +1 -2
- package/dist/pi/packages/ta-team/lib/i18n.js +6 -624
- package/dist/pi/packages/ta-team/lib/index.js +3 -1
- package/dist/pi/packages/ta-team/lib/join-dialog.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/join-dialog.js +234 -0
- package/dist/pi/packages/ta-team/lib/members-tab.js +2 -1
- package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-team/lib/style.js +1 -1
- package/dist/pi/packages/ta-team/package.json +1 -1
- package/dist/pi/packages/ta-team/web/index.js +2095 -2086
- package/dist/pi/packages/ta-usage/README.en.md +6 -0
- package/dist/pi/packages/ta-usage/README.md +6 -0
- package/dist/pi/packages/ta-usage/host/index.mjs +220 -0
- package/dist/pi/packages/ta-usage/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/host.js +9 -0
- package/dist/pi/packages/ta-usage/lib/i18n.d.ts +30 -0
- package/dist/pi/packages/ta-usage/lib/i18n.js +98 -0
- package/dist/pi/packages/ta-usage/lib/index.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/index.js +20 -0
- package/dist/pi/packages/ta-usage/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-usage/lib/react.js +8 -0
- package/dist/pi/packages/ta-usage/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/style.js +53 -0
- package/dist/pi/packages/ta-usage/lib/usage-host.d.ts +25 -0
- package/dist/pi/packages/ta-usage/lib/usage-host.js +70 -0
- package/dist/pi/packages/ta-usage/lib/usage-protocol.d.ts +55 -0
- package/dist/pi/packages/ta-usage/lib/usage-protocol.js +7 -0
- package/dist/pi/packages/ta-usage/lib/usage-util.d.ts +18 -0
- package/dist/pi/packages/ta-usage/lib/usage-util.js +159 -0
- package/dist/pi/packages/ta-usage/lib/usage-view.d.ts +9 -0
- package/dist/pi/packages/ta-usage/lib/usage-view.js +91 -0
- package/dist/pi/packages/ta-usage/package.json +61 -0
- package/dist/pi/packages/ta-usage/web/index.js +471 -0
- package/dist/pi/packages/ta-voice/README.en.md +8 -0
- package/dist/pi/packages/ta-voice/README.md +8 -0
- package/dist/pi/packages/ta-voice/host/index.mjs +662 -0
- package/dist/pi/packages/ta-voice/lib/doubao-frames.d.ts +44 -0
- package/dist/pi/packages/ta-voice/lib/doubao-frames.js +116 -0
- package/dist/pi/packages/ta-voice/lib/doubao-realtime.d.ts +35 -0
- package/dist/pi/packages/ta-voice/lib/doubao-realtime.js +172 -0
- package/dist/pi/packages/ta-voice/lib/host.d.ts +20 -0
- package/dist/pi/packages/ta-voice/lib/host.js +120 -0
- package/dist/pi/packages/ta-voice/lib/openai-realtime.d.ts +73 -0
- package/dist/pi/packages/ta-voice/lib/openai-realtime.js +257 -0
- package/dist/pi/packages/ta-voice/lib/realtime-socket.d.ts +23 -0
- package/dist/pi/packages/ta-voice/lib/realtime-socket.js +80 -0
- package/dist/pi/packages/ta-voice/package.json +67 -0
- package/dist/pi/packages/ta-workspace/README.md +1 -1
- package/dist/pi/packages/ta-workspace/README.zh-cn.md +1 -1
- package/dist/pi/packages/ta-workspace/lib/browser-common.d.ts +4 -0
- package/dist/pi/packages/ta-workspace/lib/browser-common.js +1 -0
- package/dist/pi/packages/ta-workspace/lib/browser-pick.d.ts +49 -0
- package/dist/pi/packages/ta-workspace/lib/browser-pick.js +166 -0
- package/dist/pi/packages/ta-workspace/lib/browser-webview.js +16 -1
- package/dist/pi/packages/ta-workspace/lib/i18n-en.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-en.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-ja.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +7 -3
- package/dist/pi/packages/ta-workspace/lib/i18n.js +11 -621
- package/dist/pi/packages/ta-workspace/package.json +1 -1
- package/dist/pi/packages/ta-workspace/web/index.js +1504 -770
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-Dd51Bqbx.js → abnfDiagram-S7VZAUFO-w8qXXVn-.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-BbG3_x7_.js → architecture-WOLXFQ4H-B-FHaYwY.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-DbJO4t8I.js → architectureDiagram-YGSQEFNW-DTnoGaaX.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-BwtrHF1f.js → blockDiagram-APKKGZFW-CyeBzv-v.js} +1 -1
- package/dist/public/assets/{browser-D2BcOPKG.js → browser-Cb38iiEE.js} +1 -1
- package/dist/public/assets/{browser-CTbeNBsA.js → browser-DXexCqIh.js} +2 -2
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-CfBe5A0H.js → c4Diagram-KJ2TOQU5-CJJqDqyQ.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-C7R0mhrg.js → chunk-6MUBBAK2-DbvUMdNm.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-VQgQruZT.js → chunk-AXFCVDMN-D4hlZGtj.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-CkUi_vD5.js → chunk-BG4553SI-VNa9Q9On.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-BAQq7ktk.js → chunk-DQASFODM-BtlEbc_V.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-B1oF8lB7.js → chunk-HFQBQIA3-CAYSo4CJ.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-DE5amcgT.js → chunk-KQLB2F66-CyKdg6hW.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-ev9S_csp.js → chunk-KS47KZWR-BMogCB2r.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-ziqnRvTG.js → chunk-LEVMRMFU-Y9wr-8qB.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-DaqPdEKA.js → chunk-M57EVK23-DL3IAQKR.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-DFOG8j6z.js → chunk-OY52VR5R-CJBFHdg6.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-eg35JLLN.js → chunk-QB3YPZ4I-CyuWKZZv.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-J73nie-R.js → chunk-R3KSYZAL-DxvGhfpm.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-B8EvDZvB.js → chunk-STOXU5M4-Cpdl6bfz.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-DyCM007V.js → chunk-TU62E6Q5-CIxOg6QF.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-BBGeCNmA.js → chunk-X4PVCEUW-DCFSCRBh.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-CAtJ2Wph.js → chunk-XXDRQBXY-B2R8Cxf7.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-DhQM6yHy.js → classDiagram-v2-L25IHNXF-B7W9HSbj.js} +1 -1
- package/dist/public/assets/{client-C8gi9Fk2.js → client-D75LfyFa.js} +1 -1
- package/dist/public/assets/{common-DrZR0tgm.js → common-CjqTomRQ.js} +1 -1
- package/dist/public/assets/{cose-bilkent-JH36ORCC-AqIcHabu.js → cose-bilkent-JH36ORCC-CXSLFyCH.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-BIcbDns7.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-7SyXzhRd.js → cynefinDiagram-L36ESFBY-DTv0Kn1r.js} +1 -1
- package/dist/public/assets/{d3-selection-DsahLieG.js → d3-selection-g4Hl3_NH.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-DalaGtMS.js → dagre-SPEB5RXH-BujVqk5R.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-BcY-qB9G.js → diagram-3B7GL73J-Ds-VnLzP.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-NV7fbe0h.js → diagram-DNEMPZML-BBoIIK-a.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-BPx4GHoj.js → diagram-L3MUGCDN-Glgd5N_n.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-BeUxqmw1.js → diagram-LA4NIPWU-B4EODdUU.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-Dlg1S5na.js → diagram-MHCOC4E2-pzDDXO2J.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-DQhRoMkK.js → diagram-XPFHEONP-l--gwSuK.js} +1 -1
- package/dist/public/assets/{dist-CQU8zJh_.js → dist-C0u3lAFR.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-gVEs3Um2.js → ebnfDiagram-UZSYDL2S-BVfPeaVX.js} +1 -1
- package/dist/public/assets/{editor.api-SQ1snuat.js → editor.api-BMcewI3C.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-CHtlrPwu.js → elk-XV6XMXQE-BFJtUnG9.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-B0xok726.js → erDiagram-EYBAPDEH-BWxMtfIc.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-CFwphA0e.js → eventmodeling-K75KTNOO-YwYgBgCX.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-Dah4--NW.js +1 -0
- package/dist/public/assets/{freemarker2-DJKO-X2B.js → freemarker2-B8HquI7K.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-B5wVGN1A.js → ganttDiagram-23REXITY-CBqv7wbi.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BwDfrSZS.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW-DEjNU1R_.js → gitGraphDiagram-STJD7YCW-BLSf23f_.js} +1 -1
- package/dist/public/assets/{handlebars-ChVN7JPd.js → handlebars-P1qmNq4N.js} +1 -1
- package/dist/public/assets/{html-CQ0znKSa.js → html-Ceswbytr.js} +1 -1
- package/dist/public/assets/{index-CLlacdXR.js → index-10isUUN4.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-Ch8aMV1p.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-CJtrS72M.js → infoDiagram-KBXO4MBG-LvOtgUlm.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-qYI1QBsK.js → ishikawaDiagram-M35NCXHK-CwUZOvcm.js} +1 -1
- package/dist/public/assets/{javascript-B-DHbkyI.js → javascript-B3FXC8qR.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-BOQ2y2ZZ.js → journeyDiagram-OPLOXDXO-5j1KtwTt.js} +1 -1
- package/dist/public/assets/{jsonMode-XuGC5N_z.js → jsonMode-CrCyxNQI.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-BJ64tKdP.js → kanban-definition-BZKZHSQY-BKAB5id1.js} +1 -1
- package/dist/public/assets/{liquid-B0Ujylzc.js → liquid-CXZRIgp2.js} +1 -1
- package/dist/public/assets/{mdx-B19-V510.js → mdx-Dm3uNczM.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-Scb01iBq.js → mermaid-parser.core-C755A-rX.js} +3 -3
- package/dist/public/assets/{mermaid.core-BMuvs7us.js → mermaid.core-CQrYmFAR.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-BYfOS3XN.js → mindmap-definition-I2QAS2VK-DNJQKYbK.js} +1 -1
- package/dist/public/assets/module-9otB6_kX.js +1 -0
- package/dist/public/assets/{module-Cm_mLwAQ.js → module-C3jC5acf.js} +1 -1
- package/dist/public/assets/module-C_MyFORb.js +1 -0
- package/dist/public/assets/module-Cjpl4gva.js +1 -0
- package/dist/public/assets/{module-DUYj4E8T.js → module-D8yH9xCl.js} +1 -1
- package/dist/public/assets/module-DlHjBjOg.js +1 -0
- package/dist/public/assets/module-QsLiJaR6.js +1 -0
- package/dist/public/assets/module-aaW5Ri2L.js +2771 -0
- package/dist/public/assets/module-gSy9fKBo.js +1 -0
- package/dist/public/assets/{monaco-Bbe2os7m.js → monaco-BS7JBNW4.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-LqMrrc60.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-D-Vlq9Gm.js → pegDiagram-FD4XPPHP-BzbBCWht.js} +1 -1
- package/dist/public/assets/pie-XZMESJXO-BWzABXQU.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-_-94-aMD.js → pieDiagram-J4AKIIQI-Bf_LDukL.js} +1 -1
- package/dist/public/assets/{python-CWnMIOYq.js → python-jgOUhB-F.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2-BhFUbUYz.js → quadrantDiagram-XTYBLID2-CdMHWnKX.js} +1 -1
- package/dist/public/assets/radar-ABXABTNO-CR4kNiUj.js +1 -0
- package/dist/public/assets/railroad-I3PHUGI6-BAkWtkGC.js +1 -0
- package/dist/public/assets/{railroad-abnf-LNEFI6M7-yUa9GGCQ.js → railroad-abnf-LNEFI6M7-DQGYaRbc.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-xY4YiL8M.js → railroad-ebnf-DWYD2UWJ-D6Ljza0U.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-BYFYCUAQ.js → railroad-peg-JR7BVNR7-Du9hL1Gf.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-C9FVhj0k.js → railroadDiagram-MRQ6NCDL-CS_JnlGN.js} +1 -1
- package/dist/public/assets/{razor-bDtpN6EJ.js → razor-BWj90God.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-DLmAg-6C.js → requirementDiagram-Y7LWUY3S-Cq8rRz2y.js} +1 -1
- package/dist/public/assets/{resolver-0zC31mg5.js → resolver-BPuspqws.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-WGJFYUXA-Bl5IpDk4.js → sankeyDiagram-WGJFYUXA-aK7jRBVK.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-Z-N0OiT_.js → sequenceDiagram-5NDRBG5M-BxcIyc38.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-ctKQz8Mo.js → stateDiagram-v2-FJ4FJNEA-Ctletlj4.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-CWLKnALg.js → swimlanes-UMQ2AFYF-DaD55xd2.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CytCT4x3.js +8 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-DP8Ph_d6.js → timeline-definition-SEUHKTQE-Ce19CDiJ.js} +1 -1
- package/dist/public/assets/treeView-D4JQ5SDB-DvzNkX4G.js +1 -0
- package/dist/public/assets/treemap-SAJKECNS-BuUeBmMd.js +1 -0
- package/dist/public/assets/{typescript-CGpNlLbn.js → typescript-RgyfxmPQ.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-DvFjNj3J.js → usecaseDiagram-AFA6YXN4-CAVEBKQS.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-3m2F2H-I.js → vennDiagram-NNMJR3RB-DHyJxlHv.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-DSfdKACG.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-CsMntu16.js → wardleyDiagram-S7YFUSEH-C-FCHxR7.js} +1 -1
- package/dist/public/assets/{xml-ByiLoakX.js → xml-DiA1T3iN.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-C80rxvM0.js → xychartDiagram-GGNKY7IX-BlnHU6Gz.js} +1 -1
- package/dist/public/assets/{yaml-Cz2Af5Rj.js → yaml-dnCcfJBR.js} +1 -1
- package/dist/public/ext/index.json +1 -0
- package/dist/public/ext/ta-3d.js +660 -0
- package/dist/public/ext/ta-glance.js +1611 -0
- package/dist/public/ext/ta-plot.js +1320 -0
- package/dist/public/index.html +2 -2
- package/dist/serve/index.mjs +17829 -14233
- package/package.json +45 -39
- package/dist/public/assets/cynefin-EF2NZ3EQ-yFytgtiy.js +0 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-Cwye_DsX.js +0 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BYzb--zb.js +0 -1
- package/dist/public/assets/info-OHQRW6UA-na0qX3JP.js +0 -1
- package/dist/public/assets/module-B3SKdB70.js +0 -1
- package/dist/public/assets/module-DDH-aU6z.js +0 -1
- package/dist/public/assets/module-DOrYVZ7B.js +0 -2615
- package/dist/public/assets/module-DRofmFJn.js +0 -1
- package/dist/public/assets/module-MaD4hvv4.js +0 -1
- package/dist/public/assets/module-ZDJutm0b.js +0 -1
- package/dist/public/assets/module-qoBVcE5h.js +0 -1
- package/dist/public/assets/packet-JDAUHWVQ-jhCd70vR.js +0 -1
- package/dist/public/assets/pie-XZMESJXO-DV0NJFsI.js +0 -1
- package/dist/public/assets/radar-ABXABTNO-Co-Hlf34.js +0 -1
- package/dist/public/assets/railroad-I3PHUGI6-DKMPEjDD.js +0 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CU76xJSu.js +0 -8
- package/dist/public/assets/treeView-D4JQ5SDB-JMMnu_MW.js +0 -1
- package/dist/public/assets/treemap-SAJKECNS-CPlAD3X1.js +0 -1
- package/dist/public/assets/wardley-7MLQ67FV-Dhc8wpLp.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// web-src/host.ts
|
|
2
|
-
import { readFile as
|
|
3
|
-
import { join as
|
|
2
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
3
|
+
import { join as join9 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// web-src/migrate-protocol.ts
|
|
6
6
|
var MIGRATE_CATEGORIES = [
|
|
@@ -23,15 +23,120 @@ var BACKUP_EXTENSION = ".tabackup";
|
|
|
23
23
|
import { randomBytes as randomBytes3, randomUUID } from "node:crypto";
|
|
24
24
|
import { createSocket } from "node:dgram";
|
|
25
25
|
import { createReadStream, createWriteStream } from "node:fs";
|
|
26
|
-
import { mkdir as mkdir3, readdir as
|
|
26
|
+
import { mkdir as mkdir3, readdir as readdir4, rename as rename3, rm as rm2, stat as stat4 } from "node:fs/promises";
|
|
27
27
|
import { createConnection, createServer } from "node:net";
|
|
28
|
-
import { homedir as
|
|
29
|
-
import { join as
|
|
28
|
+
import { homedir as homedir3, hostname as hostname2 } from "node:os";
|
|
29
|
+
import { join as join4 } from "node:path";
|
|
30
30
|
|
|
31
31
|
// web-src/migrate-archive.ts
|
|
32
|
-
import { mkdir as mkdir2, readdir as
|
|
33
|
-
import { homedir, hostname, platform } from "node:os";
|
|
34
|
-
import { basename, dirname as
|
|
32
|
+
import { mkdir as mkdir2, readdir as readdir3, readFile as readFile3, rename as rename2, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
|
|
33
|
+
import { homedir as homedir2, hostname, platform } from "node:os";
|
|
34
|
+
import { basename, dirname as dirname3, join as join3, relative as relative2, sep as sep2 } from "node:path";
|
|
35
|
+
|
|
36
|
+
// ../ta-protocol/esm/common/path-map.js
|
|
37
|
+
var TaPathMap;
|
|
38
|
+
(function(TaPathMap2) {
|
|
39
|
+
function isWindows(path2) {
|
|
40
|
+
return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
|
|
41
|
+
}
|
|
42
|
+
TaPathMap2.isWindows = isWindows;
|
|
43
|
+
function rest(path2, base) {
|
|
44
|
+
const windows = isWindows(base);
|
|
45
|
+
if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const within = parts(base, windows);
|
|
49
|
+
const all = parts(path2, windows);
|
|
50
|
+
if (!within.length || all.length < within.length) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
54
|
+
return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
|
|
55
|
+
}
|
|
56
|
+
TaPathMap2.rest = rest;
|
|
57
|
+
function under(path2, base) {
|
|
58
|
+
return rest(path2, base) !== undefined;
|
|
59
|
+
}
|
|
60
|
+
TaPathMap2.under = under;
|
|
61
|
+
function join(base, parts2) {
|
|
62
|
+
if (!parts2.length) {
|
|
63
|
+
return base;
|
|
64
|
+
}
|
|
65
|
+
const sep = isWindows(base) ? "\\" : "/";
|
|
66
|
+
return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
|
|
67
|
+
}
|
|
68
|
+
TaPathMap2.join = join;
|
|
69
|
+
function basename(path2) {
|
|
70
|
+
var _a;
|
|
71
|
+
return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
|
|
72
|
+
}
|
|
73
|
+
TaPathMap2.basename = basename;
|
|
74
|
+
function path(value, pairs) {
|
|
75
|
+
for (const [from, to] of deepest(pairs)) {
|
|
76
|
+
const found = rest(value, from);
|
|
77
|
+
if (found) {
|
|
78
|
+
return join(to, found);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
TaPathMap2.path = path;
|
|
84
|
+
function text(value, pairs) {
|
|
85
|
+
const order = deepest(pairs);
|
|
86
|
+
if (!order.length) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
const end = String.raw`\s"'<>|*?:;,`;
|
|
90
|
+
const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
|
|
91
|
+
return value.replace(pattern, (...match) => {
|
|
92
|
+
var _a;
|
|
93
|
+
const before = match[1];
|
|
94
|
+
const found = order.findIndex((_, i) => match[i + 2] !== undefined);
|
|
95
|
+
const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
|
|
96
|
+
return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
TaPathMap2.text = text;
|
|
100
|
+
function json(value, pairs) {
|
|
101
|
+
const order = deepest(pairs);
|
|
102
|
+
if (!order.length) {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
const one = (each) => {
|
|
106
|
+
const whole = path(each, order);
|
|
107
|
+
return whole !== each ? whole : text(each, order);
|
|
108
|
+
};
|
|
109
|
+
const walk = (each) => {
|
|
110
|
+
if (typeof each === "string") {
|
|
111
|
+
return one(each);
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(each)) {
|
|
114
|
+
return each.map(walk);
|
|
115
|
+
}
|
|
116
|
+
if (each && typeof each === "object") {
|
|
117
|
+
return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
|
|
118
|
+
}
|
|
119
|
+
return each;
|
|
120
|
+
};
|
|
121
|
+
return walk(value);
|
|
122
|
+
}
|
|
123
|
+
TaPathMap2.json = json;
|
|
124
|
+
function parts(path2, windows) {
|
|
125
|
+
return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
function deepest(pairs) {
|
|
128
|
+
return pairs.filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0).sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
|
|
129
|
+
}
|
|
130
|
+
function source(base) {
|
|
131
|
+
const windows = isWindows(base);
|
|
132
|
+
const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
|
|
133
|
+
const each = parts(base, windows).map(quote);
|
|
134
|
+
if (!windows) {
|
|
135
|
+
return `/${each.join("/+")}`;
|
|
136
|
+
}
|
|
137
|
+
return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
|
|
138
|
+
}
|
|
139
|
+
})(TaPathMap || (TaPathMap = {}));
|
|
35
140
|
|
|
36
141
|
// web-src/migrate-frames.ts
|
|
37
142
|
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
|
|
@@ -217,6 +322,211 @@ var BackupFile;
|
|
|
217
322
|
BackupFile.readHeader = readHeader;
|
|
218
323
|
})(BackupFile ||= {});
|
|
219
324
|
|
|
325
|
+
// web-src/migrate-paths.ts
|
|
326
|
+
import { open, readdir, readFile, stat } from "node:fs/promises";
|
|
327
|
+
import { homedir } from "node:os";
|
|
328
|
+
import { dirname, join } from "node:path";
|
|
329
|
+
var HEADER_BYTES = 64 * 1024;
|
|
330
|
+
var DEPTH = 4;
|
|
331
|
+
var MAX_FOLDERS = 20000;
|
|
332
|
+
var SKIPPED = new Set([
|
|
333
|
+
"node_modules",
|
|
334
|
+
"Library",
|
|
335
|
+
"AppData",
|
|
336
|
+
"Applications",
|
|
337
|
+
"Pictures",
|
|
338
|
+
"Music",
|
|
339
|
+
"Movies",
|
|
340
|
+
"Videos",
|
|
341
|
+
"snap",
|
|
342
|
+
"go",
|
|
343
|
+
"target",
|
|
344
|
+
"dist",
|
|
345
|
+
"build"
|
|
346
|
+
]);
|
|
347
|
+
var MAX_PROJECTS = 500;
|
|
348
|
+
var MigratePaths;
|
|
349
|
+
((MigratePaths) => {
|
|
350
|
+
async function directories(agentDir) {
|
|
351
|
+
const counts = new Map;
|
|
352
|
+
const root = join(agentDir, "sessions");
|
|
353
|
+
for (const dir of await readdir(root, { withFileTypes: true }).catch(() => [])) {
|
|
354
|
+
if (!dir.isDirectory()) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
for (const name of await readdir(join(root, dir.name)).catch(() => [])) {
|
|
358
|
+
const cwd = name.endsWith(".jsonl") ? await headerCwd(join(root, dir.name, name)) : undefined;
|
|
359
|
+
if (cwd) {
|
|
360
|
+
counts.set(cwd, (counts.get(cwd) ?? 0) + 1);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return counts;
|
|
365
|
+
}
|
|
366
|
+
MigratePaths.directories = directories;
|
|
367
|
+
async function projects(agentDir) {
|
|
368
|
+
const found = [];
|
|
369
|
+
for (const cwd of (await directories(agentDir)).keys()) {
|
|
370
|
+
const remote = await gitRemote(cwd);
|
|
371
|
+
if (remote) {
|
|
372
|
+
found.push({ cwd, remote });
|
|
373
|
+
}
|
|
374
|
+
if (found.length >= MAX_PROJECTS) {
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return found;
|
|
379
|
+
}
|
|
380
|
+
MigratePaths.projects = projects;
|
|
381
|
+
async function missing(agentDir, projects2 = [], map = (path) => path, home = homedir()) {
|
|
382
|
+
const gone = [];
|
|
383
|
+
for (const [cwd, conversations] of await directories(agentDir)) {
|
|
384
|
+
if (!await isDirectory(cwd)) {
|
|
385
|
+
gone.push({ dir: cwd, conversations });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
gone.sort((a, b) => a.dir.length - b.dir.length);
|
|
389
|
+
const groups = [];
|
|
390
|
+
for (const each of gone) {
|
|
391
|
+
const parent = groups.find((group) => TaPathMap.under(each.dir, group.dir));
|
|
392
|
+
if (parent) {
|
|
393
|
+
parent.conversations += each.conversations;
|
|
394
|
+
} else {
|
|
395
|
+
groups.push({ ...each });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (!groups.length) {
|
|
399
|
+
return [];
|
|
400
|
+
}
|
|
401
|
+
const remotes = new Map(projects2.map((project) => [map(project.cwd), normalizeRemote(project.remote)]));
|
|
402
|
+
let found;
|
|
403
|
+
for (const group of groups) {
|
|
404
|
+
const near = await homeGuess(group.dir, home);
|
|
405
|
+
if (near) {
|
|
406
|
+
group.suggestion = near;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
found ??= await look(home, remotes.size > 0);
|
|
410
|
+
const remote = remotes.get(group.dir);
|
|
411
|
+
const byRemote = remote ? found.byRemote.get(remote) : undefined;
|
|
412
|
+
const byName = found.byName.get(TaPathMap.basename(group.dir).toLowerCase());
|
|
413
|
+
const suggestion = byRemote?.length === 1 ? byRemote[0] : byName?.length === 1 ? byName[0] : undefined;
|
|
414
|
+
if (suggestion) {
|
|
415
|
+
group.suggestion = suggestion;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return groups.sort((a, b) => b.conversations - a.conversations);
|
|
419
|
+
}
|
|
420
|
+
MigratePaths.missing = missing;
|
|
421
|
+
async function homeGuess(dir, home) {
|
|
422
|
+
const match = /^(?:[a-zA-Z]:[\\/]+(?:Users|Documents and Settings)[\\/]+[^\\/]+|\/(?:Users|home)\/[^/]+)(?=$|[\\/])/i.exec(dir);
|
|
423
|
+
if (!match) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const guess = TaPathMap.path(dir, [[match[0], home]]);
|
|
427
|
+
return guess !== dir && await isDirectory(guess) ? guess : undefined;
|
|
428
|
+
}
|
|
429
|
+
MigratePaths.homeGuess = homeGuess;
|
|
430
|
+
function normalizeRemote(url) {
|
|
431
|
+
return url.trim().replace(/\.git$/, "").replace(/^[a-z+]+:\/\/(?:[^@/]+@)?/i, "").replace(/^[^@/]+@([^:/]+):/, "$1/").toLowerCase();
|
|
432
|
+
}
|
|
433
|
+
MigratePaths.normalizeRemote = normalizeRemote;
|
|
434
|
+
async function gitRemote(cwd) {
|
|
435
|
+
let dir = cwd;
|
|
436
|
+
for (let i = 0;i < 20; i++) {
|
|
437
|
+
const config = await readFile(join(dir, ".git", "config"), "utf8").catch(() => {
|
|
438
|
+
return;
|
|
439
|
+
});
|
|
440
|
+
if (config !== undefined) {
|
|
441
|
+
return remoteOf(config);
|
|
442
|
+
}
|
|
443
|
+
const parent = dirname(dir);
|
|
444
|
+
if (parent === dir) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
dir = parent;
|
|
448
|
+
}
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
MigratePaths.gitRemote = gitRemote;
|
|
452
|
+
function remoteOf(config) {
|
|
453
|
+
const urls = [];
|
|
454
|
+
let section = "";
|
|
455
|
+
for (const line of config.split(/\r?\n/)) {
|
|
456
|
+
const head = /^\s*\[\s*remote\s+"([^"]+)"\s*\]/.exec(line);
|
|
457
|
+
if (head) {
|
|
458
|
+
section = head[1];
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (/^\s*\[/.test(line)) {
|
|
462
|
+
section = "";
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const url = /^\s*url\s*=\s*(.+?)\s*$/.exec(line);
|
|
466
|
+
if (section && url) {
|
|
467
|
+
urls.push([section, url[1]]);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return (urls.find(([name]) => name === "origin") ?? urls[0])?.[1];
|
|
471
|
+
}
|
|
472
|
+
MigratePaths.remoteOf = remoteOf;
|
|
473
|
+
async function look(home, remotes) {
|
|
474
|
+
const found = { byName: new Map, byRemote: new Map };
|
|
475
|
+
let folders = 0;
|
|
476
|
+
const add = (map, key, path) => map.set(key, [...map.get(key) ?? [], path]);
|
|
477
|
+
const visit = async (dir, depth) => {
|
|
478
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
479
|
+
if (remotes && entries.some((entry) => entry.name === ".git")) {
|
|
480
|
+
const config = await readFile(join(dir, ".git", "config"), "utf8").catch(() => {
|
|
481
|
+
return;
|
|
482
|
+
});
|
|
483
|
+
const remote = config && remoteOf(config);
|
|
484
|
+
if (remote) {
|
|
485
|
+
add(found.byRemote, normalizeRemote(remote), dir);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
for (const entry of entries) {
|
|
489
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name) || ++folders > MAX_FOLDERS) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
const path = join(dir, entry.name);
|
|
493
|
+
add(found.byName, entry.name.toLowerCase(), path);
|
|
494
|
+
if (depth < DEPTH) {
|
|
495
|
+
await visit(path, depth + 1);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
await visit(home, 1);
|
|
500
|
+
return found;
|
|
501
|
+
}
|
|
502
|
+
})(MigratePaths ||= {});
|
|
503
|
+
async function isDirectory(path) {
|
|
504
|
+
return (await stat(path).catch(() => {
|
|
505
|
+
return;
|
|
506
|
+
}))?.isDirectory() ?? false;
|
|
507
|
+
}
|
|
508
|
+
async function headerCwd(file) {
|
|
509
|
+
const handle = await open(file, "r").catch(() => {
|
|
510
|
+
return;
|
|
511
|
+
});
|
|
512
|
+
if (!handle) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
const buffer = Buffer.alloc(HEADER_BYTES);
|
|
517
|
+
const { bytesRead } = await handle.read(buffer, 0, HEADER_BYTES, 0);
|
|
518
|
+
const text = buffer.subarray(0, bytesRead).toString("utf8");
|
|
519
|
+
const end = text.indexOf(`
|
|
520
|
+
`);
|
|
521
|
+
const header = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
522
|
+
return header.type === "session" && typeof header.cwd === "string" ? header.cwd : undefined;
|
|
523
|
+
} catch {
|
|
524
|
+
return;
|
|
525
|
+
} finally {
|
|
526
|
+
await handle.close();
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
220
530
|
// web-src/sync-codec.ts
|
|
221
531
|
import { createHash } from "node:crypto";
|
|
222
532
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
@@ -364,8 +674,8 @@ var SyncCodec;
|
|
|
364
674
|
})(SyncCodec ||= {});
|
|
365
675
|
|
|
366
676
|
// web-src/sync-items.ts
|
|
367
|
-
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
368
|
-
import { dirname, join, relative, sep } from "node:path";
|
|
677
|
+
import { mkdir, readdir as readdir2, readFile as readFile2, rename, rm, stat as stat2, writeFile } from "node:fs/promises";
|
|
678
|
+
import { dirname as dirname2, join as join2, relative, sep } from "node:path";
|
|
369
679
|
var SETTINGS = "settings.json";
|
|
370
680
|
var SYNC_FILES = {
|
|
371
681
|
"keybindings.json": "settings",
|
|
@@ -379,7 +689,7 @@ var SYNC_FILES = {
|
|
|
379
689
|
};
|
|
380
690
|
var IDENTITY_FILES = ["identity.json", "rooms.json", "friends.json"];
|
|
381
691
|
var SYNC_UNITS = { skills: "skills", prompts: "skills", themes: "skills", extensions: "extensions" };
|
|
382
|
-
var
|
|
692
|
+
var SKIPPED2 = new Set(["node_modules", ".git", ".DS_Store"]);
|
|
383
693
|
var MAX_FILE = 4 * 1024 * 1024;
|
|
384
694
|
var PORTABLE = /^(npm:|git:|github:|git@|https?:\/\/)/;
|
|
385
695
|
var SyncItems;
|
|
@@ -453,11 +763,11 @@ var SyncItems;
|
|
|
453
763
|
})(SyncItems ||= {});
|
|
454
764
|
async function readText(file) {
|
|
455
765
|
try {
|
|
456
|
-
const info = await
|
|
766
|
+
const info = await stat2(file);
|
|
457
767
|
if (!info.isFile()) {
|
|
458
768
|
return;
|
|
459
769
|
}
|
|
460
|
-
return { bytes: new Uint8Array(await
|
|
770
|
+
return { bytes: new Uint8Array(await readFile2(file)), at: info.mtimeMs };
|
|
461
771
|
} catch {
|
|
462
772
|
return;
|
|
463
773
|
}
|
|
@@ -466,19 +776,19 @@ async function walk(root) {
|
|
|
466
776
|
const files = new Map;
|
|
467
777
|
let at = 0;
|
|
468
778
|
const visit = async (dir) => {
|
|
469
|
-
for (const entry of await
|
|
470
|
-
if (
|
|
779
|
+
for (const entry of await readdir2(dir, { withFileTypes: true }).catch(() => [])) {
|
|
780
|
+
if (SKIPPED2.has(entry.name)) {
|
|
471
781
|
continue;
|
|
472
782
|
}
|
|
473
|
-
const path =
|
|
783
|
+
const path = join2(dir, entry.name);
|
|
474
784
|
if (entry.isDirectory()) {
|
|
475
785
|
await visit(path);
|
|
476
786
|
} else if (entry.isFile()) {
|
|
477
|
-
const info = await
|
|
787
|
+
const info = await stat2(path).catch(() => {
|
|
478
788
|
return;
|
|
479
789
|
});
|
|
480
790
|
if (info && info.size <= MAX_FILE) {
|
|
481
|
-
files.set(relative(root, path).split(sep).join("/"), new Uint8Array(await
|
|
791
|
+
files.set(relative(root, path).split(sep).join("/"), new Uint8Array(await readFile2(path)));
|
|
482
792
|
at = Math.max(at, info.mtimeMs);
|
|
483
793
|
}
|
|
484
794
|
}
|
|
@@ -499,7 +809,7 @@ class AgentDirPlace {
|
|
|
499
809
|
this.agentDir = agentDir;
|
|
500
810
|
this.side = side;
|
|
501
811
|
this.now = now;
|
|
502
|
-
this.replacedDir =
|
|
812
|
+
this.replacedDir = join2(agentDir, "sync", "replaced");
|
|
503
813
|
}
|
|
504
814
|
begin() {
|
|
505
815
|
this.stamp = undefined;
|
|
@@ -508,7 +818,7 @@ class AgentDirPlace {
|
|
|
508
818
|
const items = new Map;
|
|
509
819
|
const add = (item) => item && items.set(item.id, item);
|
|
510
820
|
if (resources.has("settings") || resources.has("extensions")) {
|
|
511
|
-
const file = await readText(
|
|
821
|
+
const file = await readText(join2(this.agentDir, SETTINGS));
|
|
512
822
|
const parsed = file ? safeParse(file.bytes) : {};
|
|
513
823
|
const settings = SyncMerge.isObject(parsed) ? parsed : undefined;
|
|
514
824
|
if (settings && resources.has("settings")) {
|
|
@@ -522,7 +832,7 @@ class AgentDirPlace {
|
|
|
522
832
|
}
|
|
523
833
|
for (const [name, resource] of Object.entries(SYNC_FILES)) {
|
|
524
834
|
if (resources.has(resource)) {
|
|
525
|
-
const file = await readText(
|
|
835
|
+
const file = await readText(join2(this.agentDir, name));
|
|
526
836
|
add(file && SyncItems.item(`file:${name}`, "bytes", file.bytes, file.at));
|
|
527
837
|
}
|
|
528
838
|
}
|
|
@@ -577,7 +887,7 @@ class AgentDirPlace {
|
|
|
577
887
|
return;
|
|
578
888
|
}
|
|
579
889
|
if (type === "tree") {
|
|
580
|
-
if ((await
|
|
890
|
+
if ((await stat2(path).catch(() => {
|
|
581
891
|
return;
|
|
582
892
|
}))?.isFile()) {
|
|
583
893
|
await rm(path, { force: true });
|
|
@@ -589,7 +899,7 @@ class AgentDirPlace {
|
|
|
589
899
|
}
|
|
590
900
|
}
|
|
591
901
|
async keep(id, type, content, from) {
|
|
592
|
-
const target =
|
|
902
|
+
const target = join2(this.folder(), `from-${from.replace(/[^\w.-]/g, "_")}`, this.asidePath(id));
|
|
593
903
|
if (type === "tree") {
|
|
594
904
|
await this.writeTree(target, SyncCodec.unpack(content));
|
|
595
905
|
} else {
|
|
@@ -602,7 +912,7 @@ class AgentDirPlace {
|
|
|
602
912
|
async signature(resources) {
|
|
603
913
|
const parts = [];
|
|
604
914
|
const note = async (path, deep) => {
|
|
605
|
-
const info = await
|
|
915
|
+
const info = await stat2(path).catch(() => {
|
|
606
916
|
return;
|
|
607
917
|
});
|
|
608
918
|
if (!info) {
|
|
@@ -610,53 +920,53 @@ class AgentDirPlace {
|
|
|
610
920
|
}
|
|
611
921
|
parts.push(`${relative(this.agentDir, path)}:${info.mtimeMs}:${info.size}`);
|
|
612
922
|
if (deep && info.isDirectory()) {
|
|
613
|
-
for (const entry of await
|
|
614
|
-
if (!
|
|
615
|
-
await note(
|
|
923
|
+
for (const entry of await readdir2(path).catch(() => [])) {
|
|
924
|
+
if (!SKIPPED2.has(entry)) {
|
|
925
|
+
await note(join2(path, entry), true);
|
|
616
926
|
}
|
|
617
927
|
}
|
|
618
928
|
}
|
|
619
929
|
};
|
|
620
930
|
if (resources.has("settings") || resources.has("extensions")) {
|
|
621
|
-
await note(
|
|
931
|
+
await note(join2(this.agentDir, SETTINGS), false);
|
|
622
932
|
}
|
|
623
933
|
for (const [name, resource] of Object.entries(SYNC_FILES)) {
|
|
624
934
|
if (resources.has(resource)) {
|
|
625
|
-
await note(
|
|
935
|
+
await note(join2(this.agentDir, name), false);
|
|
626
936
|
}
|
|
627
937
|
}
|
|
628
938
|
for (const [dir, resource] of Object.entries(SYNC_UNITS)) {
|
|
629
939
|
if (resources.has(resource)) {
|
|
630
|
-
await note(
|
|
940
|
+
await note(join2(this.agentDir, dir), true);
|
|
631
941
|
}
|
|
632
942
|
}
|
|
633
943
|
if (resources.has("identity")) {
|
|
634
944
|
for (const name of IDENTITY_FILES) {
|
|
635
|
-
await note(
|
|
945
|
+
await note(join2(this.agentDir, name), false);
|
|
636
946
|
}
|
|
637
947
|
}
|
|
638
948
|
return parts.join(`
|
|
639
949
|
`);
|
|
640
950
|
}
|
|
641
951
|
get usedFolder() {
|
|
642
|
-
return this.stamp ?
|
|
952
|
+
return this.stamp ? join2(this.replacedDir, this.stamp) : undefined;
|
|
643
953
|
}
|
|
644
954
|
async keepAside(path, bytes) {
|
|
645
|
-
await this.writeFile(
|
|
955
|
+
await this.writeFile(join2(this.folder(), ...path.split("/")), bytes);
|
|
646
956
|
}
|
|
647
957
|
async replacedCount() {
|
|
648
|
-
const folders = await
|
|
958
|
+
const folders = await readdir2(this.replacedDir).catch(() => []);
|
|
649
959
|
return folders.length;
|
|
650
960
|
}
|
|
651
961
|
async units(dir) {
|
|
652
|
-
const root =
|
|
962
|
+
const root = join2(this.agentDir, dir);
|
|
653
963
|
const items = [];
|
|
654
|
-
for (const entry of await
|
|
655
|
-
if (
|
|
964
|
+
for (const entry of await readdir2(root, { withFileTypes: true }).catch(() => [])) {
|
|
965
|
+
if (SKIPPED2.has(entry.name) || entry.name.startsWith(".")) {
|
|
656
966
|
continue;
|
|
657
967
|
}
|
|
658
968
|
const id = `${dir}/${entry.name}`;
|
|
659
|
-
const path =
|
|
969
|
+
const path = join2(root, entry.name);
|
|
660
970
|
if (entry.isDirectory()) {
|
|
661
971
|
const { files, at } = await walk(path);
|
|
662
972
|
if (files.size) {
|
|
@@ -676,12 +986,12 @@ class AgentDirPlace {
|
|
|
676
986
|
if (!SyncItems.resourceOf(id) || !SyncItems.safePath(path)) {
|
|
677
987
|
return;
|
|
678
988
|
}
|
|
679
|
-
return
|
|
989
|
+
return join2(this.agentDir, ...path.split("/"));
|
|
680
990
|
}
|
|
681
991
|
asidePath(id) {
|
|
682
992
|
const data = SyncItems.parseDataId(id);
|
|
683
993
|
if (data) {
|
|
684
|
-
return
|
|
994
|
+
return join2("data", ...data.name.split("/"), `${data.key.replace(/[^\w.-]/g, "_")}.json`);
|
|
685
995
|
}
|
|
686
996
|
if (id === "settings" || id === "packages") {
|
|
687
997
|
return `${id}.json`;
|
|
@@ -694,10 +1004,10 @@ class AgentDirPlace {
|
|
|
694
1004
|
const pad = (value) => String(value).padStart(2, "0");
|
|
695
1005
|
this.stamp = `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
696
1006
|
}
|
|
697
|
-
return
|
|
1007
|
+
return join2(this.replacedDir, this.stamp);
|
|
698
1008
|
}
|
|
699
1009
|
async asideOf(id, type) {
|
|
700
|
-
const target =
|
|
1010
|
+
const target = join2(this.folder(), this.asidePath(id));
|
|
701
1011
|
if (id === "settings" || id === "packages" || id.startsWith("data:")) {
|
|
702
1012
|
const current = (await this.read(new Set([SyncItems.resourceOf(id)]))).get(id);
|
|
703
1013
|
if (current) {
|
|
@@ -723,7 +1033,7 @@ class AgentDirPlace {
|
|
|
723
1033
|
}
|
|
724
1034
|
async applyPackages(value) {
|
|
725
1035
|
const wanted = Array.isArray(value) ? value.map((entry) => SyncItems.source(entry)).filter((entry) => !!entry) : [];
|
|
726
|
-
const file = await readText(
|
|
1036
|
+
const file = await readText(join2(this.agentDir, SETTINGS));
|
|
727
1037
|
const settings = file ? safeParse(file.bytes) : {};
|
|
728
1038
|
const have = SyncMerge.isObject(settings) ? SyncItems.portablePackages(settings).map((entry) => SyncItems.source(entry)).filter((entry) => !!entry) : [];
|
|
729
1039
|
for (const source of wanted.filter((entry) => !have.includes(entry))) {
|
|
@@ -737,17 +1047,17 @@ class AgentDirPlace {
|
|
|
737
1047
|
const { files: before } = await walk(root);
|
|
738
1048
|
for (const path of before.keys()) {
|
|
739
1049
|
if (!files.has(path)) {
|
|
740
|
-
await rm(
|
|
1050
|
+
await rm(join2(root, ...path.split("/")), { force: true });
|
|
741
1051
|
}
|
|
742
1052
|
}
|
|
743
1053
|
for (const [path, bytes] of files) {
|
|
744
1054
|
if (SyncItems.safePath(path)) {
|
|
745
|
-
await this.writeFile(
|
|
1055
|
+
await this.writeFile(join2(root, ...path.split("/")), bytes);
|
|
746
1056
|
}
|
|
747
1057
|
}
|
|
748
1058
|
}
|
|
749
1059
|
async writeFile(path, bytes) {
|
|
750
|
-
await mkdir(
|
|
1060
|
+
await mkdir(dirname2(path), { recursive: true });
|
|
751
1061
|
const temporary = `${path}.ta-sync-${process.pid}`;
|
|
752
1062
|
await writeFile(temporary, bytes);
|
|
753
1063
|
await rename(temporary, path);
|
|
@@ -787,14 +1097,14 @@ var MAX_ENTRY = 512 * 1024 * 1024;
|
|
|
787
1097
|
async function files(root, keep = () => true) {
|
|
788
1098
|
const found = [];
|
|
789
1099
|
const visit = async (dir) => {
|
|
790
|
-
for (const entry of await
|
|
791
|
-
const path =
|
|
1100
|
+
for (const entry of await readdir3(dir, { withFileTypes: true }).catch(() => [])) {
|
|
1101
|
+
const path = join3(dir, entry.name);
|
|
792
1102
|
if (entry.isDirectory()) {
|
|
793
1103
|
await visit(path);
|
|
794
1104
|
} else if (entry.isFile()) {
|
|
795
1105
|
const rel = relative2(root, path).split(sep2).join("/");
|
|
796
1106
|
if (keep(rel)) {
|
|
797
|
-
found.push({ path: rel, size: (await
|
|
1107
|
+
found.push({ path: rel, size: (await stat3(path)).size });
|
|
798
1108
|
}
|
|
799
1109
|
}
|
|
800
1110
|
}
|
|
@@ -809,25 +1119,12 @@ var MigrateUtil;
|
|
|
809
1119
|
}
|
|
810
1120
|
MigrateUtil.sessionDir = sessionDir;
|
|
811
1121
|
function remapPath(path, from, to) {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
return to.home + path.slice(from.home.length);
|
|
817
|
-
}
|
|
818
|
-
return path;
|
|
1122
|
+
return TaPathMap.path(path, [
|
|
1123
|
+
[from.agentDir, to.agentDir],
|
|
1124
|
+
[from.home, to.home]
|
|
1125
|
+
]);
|
|
819
1126
|
}
|
|
820
1127
|
MigrateUtil.remapPath = remapPath;
|
|
821
|
-
function remapText(text, pairs) {
|
|
822
|
-
let out = text;
|
|
823
|
-
for (const [before, after] of pairs) {
|
|
824
|
-
if (before && before !== after) {
|
|
825
|
-
out = out.split(before).join(after);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
return out;
|
|
829
|
-
}
|
|
830
|
-
MigrateUtil.remapText = remapText;
|
|
831
1128
|
})(MigrateUtil ||= {});
|
|
832
1129
|
|
|
833
1130
|
class MigrateSource {
|
|
@@ -852,9 +1149,11 @@ class MigrateSource {
|
|
|
852
1149
|
count.bytes += head.size ?? 0;
|
|
853
1150
|
bytes += head.size ?? 0;
|
|
854
1151
|
}
|
|
1152
|
+
const projects = categories.includes("conversations") ? await MigratePaths.projects(this.agentDir) : [];
|
|
855
1153
|
return {
|
|
856
1154
|
v: 1,
|
|
857
|
-
from: { name: this.name, platform: platform(), home:
|
|
1155
|
+
from: { name: this.name, platform: platform(), home: homedir2(), agentDir: this.agentDir },
|
|
1156
|
+
...projects.length ? { projects } : {},
|
|
858
1157
|
categories: [...categories],
|
|
859
1158
|
counts,
|
|
860
1159
|
bytes,
|
|
@@ -873,19 +1172,19 @@ class MigrateSource {
|
|
|
873
1172
|
async entries(categories) {
|
|
874
1173
|
const wanted = new Set(categories);
|
|
875
1174
|
const entries = [];
|
|
876
|
-
const file = (c, k, path, size) => entries.push({ head: { k, c, path, size }, read: async () => new Uint8Array(await
|
|
1175
|
+
const file = (c, k, path, size) => entries.push({ head: { k, c, path, size }, read: async () => new Uint8Array(await readFile3(join3(this.agentDir, ...path.split("/")))) });
|
|
877
1176
|
for (const category of ORDER.filter((each) => wanted.has(each))) {
|
|
878
1177
|
if (category === "conversations") {
|
|
879
|
-
for (const found of await files(
|
|
1178
|
+
for (const found of await files(join3(this.agentDir, "sessions"), (path) => path.endsWith(".jsonl"))) {
|
|
880
1179
|
file(category, "file", `sessions/${found.path}`, found.size);
|
|
881
1180
|
}
|
|
882
1181
|
} else if (category === "changes") {
|
|
883
|
-
for (const found of await files(
|
|
1182
|
+
for (const found of await files(join3(this.agentDir, "changes"))) {
|
|
884
1183
|
file(category, "file", `changes/${found.path}`, found.size);
|
|
885
1184
|
}
|
|
886
1185
|
} else if (category === "credentials") {
|
|
887
1186
|
await this.json(entries, category, "auth.json");
|
|
888
|
-
for (const found of await files(
|
|
1187
|
+
for (const found of await files(join3(this.agentDir, "bots"))) {
|
|
889
1188
|
file(category, "file", `bots/${found.path}`, found.size);
|
|
890
1189
|
}
|
|
891
1190
|
} else if (category === "identity") {
|
|
@@ -906,13 +1205,13 @@ class MigrateSource {
|
|
|
906
1205
|
});
|
|
907
1206
|
}
|
|
908
1207
|
} else if (category === "data") {
|
|
909
|
-
const root =
|
|
1208
|
+
const root = join3(this.agentDir, "extension-data");
|
|
910
1209
|
for (const found of await files(root, (path) => path.endsWith(".json") && !path.startsWith("directories/"))) {
|
|
911
1210
|
const name = found.path.slice(0, -".json".length);
|
|
912
1211
|
if (name !== OWN) {
|
|
913
1212
|
entries.push({
|
|
914
1213
|
head: { k: "data", c: category, name, size: found.size },
|
|
915
|
-
read: async () => new Uint8Array(await
|
|
1214
|
+
read: async () => new Uint8Array(await readFile3(join3(root, ...found.path.split("/"))))
|
|
916
1215
|
});
|
|
917
1216
|
}
|
|
918
1217
|
}
|
|
@@ -946,11 +1245,11 @@ class MigrateSource {
|
|
|
946
1245
|
await send(Frames.record({ k: "end" }));
|
|
947
1246
|
}
|
|
948
1247
|
async json(entries, c, path) {
|
|
949
|
-
const info = await
|
|
1248
|
+
const info = await stat3(join3(this.agentDir, path)).catch(() => {
|
|
950
1249
|
return;
|
|
951
1250
|
});
|
|
952
1251
|
if (info?.isFile()) {
|
|
953
|
-
entries.push({ head: { k: "json", c, path, size: info.size }, read: async () => new Uint8Array(await
|
|
1252
|
+
entries.push({ head: { k: "json", c, path, size: info.size }, read: async () => new Uint8Array(await readFile3(join3(this.agentDir, path))) });
|
|
954
1253
|
}
|
|
955
1254
|
}
|
|
956
1255
|
}
|
|
@@ -961,7 +1260,7 @@ class MigrateTarget {
|
|
|
961
1260
|
side;
|
|
962
1261
|
manifest;
|
|
963
1262
|
report = { conversations: 0, keptConversations: 0, items: 0, data: 0, extensions: 0, files: 0, skipped: [] };
|
|
964
|
-
to = { home:
|
|
1263
|
+
to = { home: homedir2(), agentDir: "" };
|
|
965
1264
|
sessions = new Map;
|
|
966
1265
|
known;
|
|
967
1266
|
locals;
|
|
@@ -998,9 +1297,10 @@ class MigrateTarget {
|
|
|
998
1297
|
this.report.skipped.push({ id, reason: error instanceof Error ? error.message : String(error) });
|
|
999
1298
|
}
|
|
1000
1299
|
}
|
|
1001
|
-
finish() {
|
|
1300
|
+
async finish() {
|
|
1002
1301
|
const replaced = this.place.usedFolder;
|
|
1003
|
-
|
|
1302
|
+
const missing = this.manifest.categories.includes("conversations") ? await MigratePaths.missing(this.agentDir, this.manifest.projects, (path) => MigrateUtil.remapPath(path, this.manifest.from, this.to)).catch(() => []) : [];
|
|
1303
|
+
return { ...this.report, ...replaced ? { replaced } : {}, ...missing.length ? { missing } : {} };
|
|
1004
1304
|
}
|
|
1005
1305
|
async conversation(path, bytes) {
|
|
1006
1306
|
const name = basename(path);
|
|
@@ -1026,7 +1326,7 @@ class MigrateTarget {
|
|
|
1026
1326
|
}
|
|
1027
1327
|
const cwd = MigrateUtil.remapPath(header.cwd, this.manifest.from, this.to);
|
|
1028
1328
|
const rest = end < 0 ? "" : text.slice(end);
|
|
1029
|
-
const file =
|
|
1329
|
+
const file = join3(this.agentDir, "sessions", MigrateUtil.sessionDir(cwd), name);
|
|
1030
1330
|
await this.write(file, new TextEncoder().encode(JSON.stringify({ ...header, cwd }) + rest));
|
|
1031
1331
|
known.set(name, file);
|
|
1032
1332
|
this.sessions.set(from, file);
|
|
@@ -1037,8 +1337,8 @@ class MigrateTarget {
|
|
|
1037
1337
|
if (!SyncItems.safePath(path) || !/^(changes|bots)\//.test(path)) {
|
|
1038
1338
|
throw new Error("Not a file Ta moves.");
|
|
1039
1339
|
}
|
|
1040
|
-
const target =
|
|
1041
|
-
const before = await
|
|
1340
|
+
const target = join3(this.agentDir, ...path.split("/"));
|
|
1341
|
+
const before = await readFile3(target).catch(() => {
|
|
1042
1342
|
return;
|
|
1043
1343
|
});
|
|
1044
1344
|
if (before && Buffer.from(bytes).equals(before)) {
|
|
@@ -1057,11 +1357,12 @@ class MigrateTarget {
|
|
|
1057
1357
|
if (path !== "auth.json" && path !== "ta.json") {
|
|
1058
1358
|
throw new Error("Not a file Ta moves.");
|
|
1059
1359
|
}
|
|
1060
|
-
const target =
|
|
1061
|
-
const before = await
|
|
1360
|
+
const target = join3(this.agentDir, path);
|
|
1361
|
+
const before = await readFile3(target).catch(() => {
|
|
1062
1362
|
return;
|
|
1063
1363
|
});
|
|
1064
|
-
const
|
|
1364
|
+
const read = JSON.parse(new TextDecoder().decode(bytes));
|
|
1365
|
+
const remote = path === "ta.json" ? this.remap(read) : read;
|
|
1065
1366
|
const local = before ? JSON.parse(before.toString("utf8")) : {};
|
|
1066
1367
|
const merged = SyncMerge.value(undefined, local, remote);
|
|
1067
1368
|
if (SyncMerge.same(merged, local)) {
|
|
@@ -1120,7 +1421,7 @@ class MigrateTarget {
|
|
|
1120
1421
|
if (name === OWN) {
|
|
1121
1422
|
return;
|
|
1122
1423
|
}
|
|
1123
|
-
const data = JSON.parse(
|
|
1424
|
+
const data = this.remap(JSON.parse(new TextDecoder().decode(bytes)));
|
|
1124
1425
|
if (!SyncMerge.isObject(data)) {
|
|
1125
1426
|
throw new Error("Not the data of a package.");
|
|
1126
1427
|
}
|
|
@@ -1132,7 +1433,7 @@ class MigrateTarget {
|
|
|
1132
1433
|
}
|
|
1133
1434
|
if (local !== undefined && !this.asideData.has(name)) {
|
|
1134
1435
|
this.asideData.add(name);
|
|
1135
|
-
const file = await
|
|
1436
|
+
const file = await readFile3(join3(this.agentDir, "extension-data", ...`${name}.json`.split("/"))).catch(() => {
|
|
1136
1437
|
return;
|
|
1137
1438
|
});
|
|
1138
1439
|
if (file) {
|
|
@@ -1146,24 +1447,22 @@ class MigrateTarget {
|
|
|
1146
1447
|
this.report.data++;
|
|
1147
1448
|
}
|
|
1148
1449
|
}
|
|
1149
|
-
remap(
|
|
1150
|
-
|
|
1151
|
-
pairs.push([this.manifest.from.agentDir, this.to.agentDir], [`${this.manifest.from.home}/`, `${this.to.home}/`]);
|
|
1152
|
-
return MigrateUtil.remapText(text, pairs);
|
|
1450
|
+
remap(value) {
|
|
1451
|
+
return TaPathMap.json(value, [...this.sessions, [this.manifest.from.agentDir, this.to.agentDir], [this.manifest.from.home, this.to.home]]);
|
|
1153
1452
|
}
|
|
1154
1453
|
async knownSessions() {
|
|
1155
1454
|
if (!this.known) {
|
|
1156
1455
|
const known = new Map;
|
|
1157
|
-
const root =
|
|
1456
|
+
const root = join3(this.agentDir, "sessions");
|
|
1158
1457
|
for (const found of await files(root, (path) => path.endsWith(".jsonl"))) {
|
|
1159
|
-
known.set(basename(found.path),
|
|
1458
|
+
known.set(basename(found.path), join3(root, ...found.path.split("/")));
|
|
1160
1459
|
}
|
|
1161
1460
|
this.known = known;
|
|
1162
1461
|
}
|
|
1163
1462
|
return this.known;
|
|
1164
1463
|
}
|
|
1165
1464
|
async write(file, bytes, mode) {
|
|
1166
|
-
await mkdir2(
|
|
1465
|
+
await mkdir2(dirname3(file), { recursive: true });
|
|
1167
1466
|
const temporary = `${file}.ta-move-${process.pid}`;
|
|
1168
1467
|
await writeFile2(temporary, bytes, mode === undefined ? undefined : { mode });
|
|
1169
1468
|
await rename2(temporary, file);
|
|
@@ -1523,6 +1822,15 @@ var MigrateServerTexts;
|
|
|
1523
1822
|
});
|
|
1524
1823
|
}
|
|
1525
1824
|
MigrateServerTexts.newer = newer;
|
|
1825
|
+
function updateThis() {
|
|
1826
|
+
return TaLanguageUtil.say({
|
|
1827
|
+
"zh-CN": "这台电脑上的 Ta 太旧,先升级 Ta。",
|
|
1828
|
+
"zh-TW": "這台電腦上的 Ta 太舊,先升級 Ta。",
|
|
1829
|
+
"en-US": "Ta here is too old for this: update it first.",
|
|
1830
|
+
"ja-JP": "このコンピューターの Ta が古すぎます。最初に Ta をアップデートしてください。"
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
MigrateServerTexts.updateThis = updateThis;
|
|
1526
1834
|
function cut() {
|
|
1527
1835
|
return TaLanguageUtil.say({
|
|
1528
1836
|
"zh-CN": "传输中断了,没有完成的部分可以重新迁移。",
|
|
@@ -1691,15 +1999,34 @@ class MigrateService {
|
|
|
1691
1999
|
this.importing(path, password || undefined);
|
|
1692
2000
|
return this.status();
|
|
1693
2001
|
}
|
|
2002
|
+
async missing() {
|
|
2003
|
+
const report = this.in?.report;
|
|
2004
|
+
if (report?.missing) {
|
|
2005
|
+
return report.missing;
|
|
2006
|
+
}
|
|
2007
|
+
return MigratePaths.missing(this.options.agentDir);
|
|
2008
|
+
}
|
|
2009
|
+
async relocate(from, to) {
|
|
2010
|
+
if (!this.options.relocate) {
|
|
2011
|
+
throw new Error(MigrateServerTexts.updateThis());
|
|
2012
|
+
}
|
|
2013
|
+
const result = await this.options.relocate(from, to);
|
|
2014
|
+
const report = this.in?.report;
|
|
2015
|
+
if (report?.missing) {
|
|
2016
|
+
report.missing = report.missing.filter((each) => each.dir !== from);
|
|
2017
|
+
this.publish(true);
|
|
2018
|
+
}
|
|
2019
|
+
return result;
|
|
2020
|
+
}
|
|
1694
2021
|
async listBackups() {
|
|
1695
2022
|
const found = [];
|
|
1696
2023
|
for (const dir of this.backupDirs()) {
|
|
1697
|
-
for (const name of await
|
|
2024
|
+
for (const name of await readdir4(dir).catch(() => [])) {
|
|
1698
2025
|
if (!name.endsWith(BACKUP_EXTENSION)) {
|
|
1699
2026
|
continue;
|
|
1700
2027
|
}
|
|
1701
|
-
const path =
|
|
1702
|
-
const info = await
|
|
2028
|
+
const path = join4(dir, name);
|
|
2029
|
+
const info = await stat4(path).catch(() => {
|
|
1703
2030
|
return;
|
|
1704
2031
|
});
|
|
1705
2032
|
if (info?.isFile()) {
|
|
@@ -1733,7 +2060,7 @@ class MigrateService {
|
|
|
1733
2060
|
return chosen;
|
|
1734
2061
|
}
|
|
1735
2062
|
backupDirs() {
|
|
1736
|
-
return this.options.backupDirs ?? [
|
|
2063
|
+
return this.options.backupDirs ?? [join4(homedir3(), "Downloads"), join4(homedir3(), "Desktop"), homedir3()];
|
|
1737
2064
|
}
|
|
1738
2065
|
async accepted(socket, key, categories) {
|
|
1739
2066
|
const out = this.out;
|
|
@@ -1822,8 +2149,8 @@ class MigrateService {
|
|
|
1822
2149
|
if (first.t !== "manifest" || !first.manifest) {
|
|
1823
2150
|
throw new Error(MigrateServerTexts.refused(into.from ?? ""));
|
|
1824
2151
|
}
|
|
1825
|
-
const
|
|
1826
|
-
await this.take(first.manifest, () =>
|
|
2152
|
+
const open2 = channel;
|
|
2153
|
+
await this.take(first.manifest, () => open2.reader.next(), into);
|
|
1827
2154
|
await channel.send(Frames.record({ t: "done" })).catch(() => {
|
|
1828
2155
|
return;
|
|
1829
2156
|
});
|
|
@@ -1876,7 +2203,7 @@ class MigrateService {
|
|
|
1876
2203
|
}
|
|
1877
2204
|
await target.apply(head, bytes);
|
|
1878
2205
|
}
|
|
1879
|
-
into.report = target.finish();
|
|
2206
|
+
into.report = await target.finish();
|
|
1880
2207
|
into.state = "done";
|
|
1881
2208
|
}
|
|
1882
2209
|
async exporting(categories, password, dir) {
|
|
@@ -1885,7 +2212,7 @@ class MigrateService {
|
|
|
1885
2212
|
const date = new Date;
|
|
1886
2213
|
const pad = (value) => String(value).padStart(2, "0");
|
|
1887
2214
|
const stamp = `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}`;
|
|
1888
|
-
const path =
|
|
2215
|
+
const path = join4(folder, `Ta-${this.name.replace(/[^\w.-]/g, "_")}-${stamp}${BACKUP_EXTENSION}`);
|
|
1889
2216
|
let stream;
|
|
1890
2217
|
try {
|
|
1891
2218
|
await mkdir3(folder, { recursive: true });
|
|
@@ -2107,17 +2434,22 @@ var SyncDeclarations;
|
|
|
2107
2434
|
})(SyncDeclarations ||= {});
|
|
2108
2435
|
|
|
2109
2436
|
// web-src/sync-service.ts
|
|
2110
|
-
import {
|
|
2111
|
-
import { hostname as hostname3, platform as platform2 } from "node:os";
|
|
2112
|
-
import { join as join6 } from "node:path";
|
|
2437
|
+
import { rm as rm4 } from "node:fs/promises";
|
|
2113
2438
|
|
|
2114
2439
|
// ../ta-relay/esm/node/relays-file.js
|
|
2115
2440
|
import { accessSync, chmodSync, constants, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
2116
|
-
import { homedir as
|
|
2117
|
-
import { dirname as
|
|
2441
|
+
import { homedir as homedir4 } from "node:os";
|
|
2442
|
+
import { dirname as dirname4, isAbsolute, join as join5, resolve } from "node:path";
|
|
2118
2443
|
|
|
2119
2444
|
// ../ta-relay/esm/common/relay-protocol.js
|
|
2120
2445
|
var RELAY_DEFAULT_URL = "https://relay.cellbang.com";
|
|
2446
|
+
function relayDefaultUrl(env) {
|
|
2447
|
+
var _a, _b;
|
|
2448
|
+
if (env === undefined) {
|
|
2449
|
+
env = (_a = globalThis.process) === null || _a === undefined ? undefined : _a.env;
|
|
2450
|
+
}
|
|
2451
|
+
return ((_b = env === null || env === undefined ? undefined : env.TA_RELAY_URL) === null || _b === undefined ? undefined : _b.trim().replace(/\/+$/, "")) || RELAY_DEFAULT_URL;
|
|
2452
|
+
}
|
|
2121
2453
|
var 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'";
|
|
2122
2454
|
var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
|
|
2123
2455
|
var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
|
|
@@ -2255,13 +2587,13 @@ var RelayServiceUtil;
|
|
|
2255
2587
|
function expand(path) {
|
|
2256
2588
|
const text = String(path !== null && path !== undefined ? path : "").trim();
|
|
2257
2589
|
if (text === "~" || text.startsWith("~/")) {
|
|
2258
|
-
return
|
|
2590
|
+
return join5(homedir4(), text.slice(1));
|
|
2259
2591
|
}
|
|
2260
|
-
return isAbsolute(text) ? resolve(text) : resolve(
|
|
2592
|
+
return isAbsolute(text) ? resolve(text) : resolve(homedir4(), text);
|
|
2261
2593
|
}
|
|
2262
2594
|
RelayServiceUtil2.expand = expand;
|
|
2263
2595
|
function portable(path) {
|
|
2264
|
-
const home =
|
|
2596
|
+
const home = homedir4();
|
|
2265
2597
|
return path === home ? "~" : path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
2266
2598
|
}
|
|
2267
2599
|
RelayServiceUtil2.portable = portable;
|
|
@@ -2288,23 +2620,23 @@ var RelayServiceUtil;
|
|
|
2288
2620
|
}
|
|
2289
2621
|
RelayServiceUtil2.only = only;
|
|
2290
2622
|
function drives() {
|
|
2291
|
-
const home =
|
|
2623
|
+
const home = homedir4();
|
|
2292
2624
|
const found = [];
|
|
2293
2625
|
const add = (name, dir) => {
|
|
2294
2626
|
try {
|
|
2295
2627
|
if (statSync(dir).isDirectory()) {
|
|
2296
|
-
found.push({ name, path: portable(
|
|
2628
|
+
found.push({ name, path: portable(join5(dir, "Ta")) });
|
|
2297
2629
|
}
|
|
2298
2630
|
} catch (_a) {}
|
|
2299
2631
|
};
|
|
2300
|
-
add("iCloud Drive",
|
|
2632
|
+
add("iCloud Drive", join5(home, "Library", "Mobile Documents", "com~apple~CloudDocs"));
|
|
2301
2633
|
try {
|
|
2302
|
-
for (const entry of readdirSync(
|
|
2303
|
-
add(entry.replace(/-.*$/, ""),
|
|
2634
|
+
for (const entry of readdirSync(join5(home, "Library", "CloudStorage"))) {
|
|
2635
|
+
add(entry.replace(/-.*$/, ""), join5(home, "Library", "CloudStorage", entry));
|
|
2304
2636
|
}
|
|
2305
2637
|
} catch (_a) {}
|
|
2306
2638
|
for (const name of ["Dropbox", "OneDrive", "Nutstore Files", "坚果云"]) {
|
|
2307
|
-
add(name,
|
|
2639
|
+
add(name, join5(home, name));
|
|
2308
2640
|
}
|
|
2309
2641
|
return found.filter((drive, index) => found.findIndex((other) => other.path === drive.path) === index);
|
|
2310
2642
|
}
|
|
@@ -2334,7 +2666,7 @@ class RelaysFile {
|
|
|
2334
2666
|
this.agentDir = agentDir;
|
|
2335
2667
|
}
|
|
2336
2668
|
get file() {
|
|
2337
|
-
return
|
|
2669
|
+
return join5(this.agentDir, RelaysFile.FILE);
|
|
2338
2670
|
}
|
|
2339
2671
|
read() {
|
|
2340
2672
|
let text;
|
|
@@ -2365,7 +2697,7 @@ class RelaysFile {
|
|
|
2365
2697
|
const entries = [];
|
|
2366
2698
|
const own = config.relays && typeof config.relays === "object" ? config.relays : {};
|
|
2367
2699
|
if (!own[OFFICIAL_RELAY]) {
|
|
2368
|
-
entries.push({ id: OFFICIAL_RELAY, type: "ta-relay", url:
|
|
2700
|
+
entries.push({ id: OFFICIAL_RELAY, type: "ta-relay", url: relayDefaultUrl(), name: new URL(relayDefaultUrl()).host, builtin: true });
|
|
2369
2701
|
}
|
|
2370
2702
|
for (const [id, service] of Object.entries(own)) {
|
|
2371
2703
|
if (!ID.test(id) || !service || typeof service !== "object") {
|
|
@@ -2398,7 +2730,7 @@ class RelaysFile {
|
|
|
2398
2730
|
if (service) {
|
|
2399
2731
|
return service;
|
|
2400
2732
|
}
|
|
2401
|
-
const url = fallback !== null && fallback !== undefined ? fallback :
|
|
2733
|
+
const url = fallback !== null && fallback !== undefined ? fallback : relayDefaultUrl();
|
|
2402
2734
|
return (_a = this.services(config).find((entry) => RelayServiceUtil.isRelay(entry) && entry.url === url)) !== null && _a !== undefined ? _a : { id: "", type: "ta-relay", url, builtin: false };
|
|
2403
2735
|
}
|
|
2404
2736
|
idFor(feature, config = this.safeRead().config) {
|
|
@@ -2411,7 +2743,7 @@ class RelaysFile {
|
|
|
2411
2743
|
}
|
|
2412
2744
|
urlFor(feature, fallback) {
|
|
2413
2745
|
const service = this.serviceFor(feature, fallback);
|
|
2414
|
-
return RelayServiceUtil.isRelay(service) ? service.url : fallback !== null && fallback !== undefined ? fallback :
|
|
2746
|
+
return RelayServiceUtil.isRelay(service) ? service.url : fallback !== null && fallback !== undefined ? fallback : relayDefaultUrl();
|
|
2415
2747
|
}
|
|
2416
2748
|
add(url, name) {
|
|
2417
2749
|
var _a;
|
|
@@ -2496,6 +2828,52 @@ class RelaysFile {
|
|
|
2496
2828
|
delete relays[id];
|
|
2497
2829
|
this.write({ ...config, relays });
|
|
2498
2830
|
}
|
|
2831
|
+
join(url, deployment) {
|
|
2832
|
+
var _a, _b;
|
|
2833
|
+
const relay = deployment.relay ? this.add(deployment.relay, deployment.name) : undefined;
|
|
2834
|
+
const config = this.read();
|
|
2835
|
+
const name = (_a = deployment.name) === null || _a === undefined ? undefined : _a.trim().slice(0, 80);
|
|
2836
|
+
const joined = {
|
|
2837
|
+
url,
|
|
2838
|
+
...name ? { name } : {},
|
|
2839
|
+
...deployment.gateway ? { gateway: deployment.gateway } : {},
|
|
2840
|
+
...relay ? { relay } : {}
|
|
2841
|
+
};
|
|
2842
|
+
const { default: before, ...rest } = config;
|
|
2843
|
+
const fallback = relay !== null && relay !== undefined ? relay : before === ((_b = config.deployment) === null || _b === undefined ? undefined : _b.relay) ? undefined : before;
|
|
2844
|
+
this.write({ ...rest, ...fallback ? { default: fallback } : {}, deployment: joined });
|
|
2845
|
+
return joined;
|
|
2846
|
+
}
|
|
2847
|
+
leave() {
|
|
2848
|
+
var _a, _b;
|
|
2849
|
+
const config = this.read();
|
|
2850
|
+
const joined = config.deployment;
|
|
2851
|
+
if (!joined) {
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
const { deployment: _left, default: before, ...rest } = config;
|
|
2855
|
+
const relays = { ...(_a = rest.relays) !== null && _a !== undefined ? _a : {} };
|
|
2856
|
+
const used = Object.values((_b = rest.use) !== null && _b !== undefined ? _b : {});
|
|
2857
|
+
if (joined.relay && joined.relay !== OFFICIAL_RELAY && !used.includes(joined.relay)) {
|
|
2858
|
+
delete relays[joined.relay];
|
|
2859
|
+
}
|
|
2860
|
+
const kept = before && before !== joined.relay ? before : undefined;
|
|
2861
|
+
this.write({ ...rest, relays, ...kept ? { default: kept } : {} });
|
|
2862
|
+
}
|
|
2863
|
+
deployment(config = this.safeRead().config) {
|
|
2864
|
+
const joined = config.deployment;
|
|
2865
|
+
if (!joined || typeof joined !== "object" || typeof joined.url !== "string") {
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
const text = (value) => typeof value === "string" && value ? value : undefined;
|
|
2869
|
+
const relay = text(joined.relay);
|
|
2870
|
+
return {
|
|
2871
|
+
url: joined.url,
|
|
2872
|
+
...text(joined.name) ? { name: text(joined.name) } : {},
|
|
2873
|
+
...text(joined.gateway) ? { gateway: text(joined.gateway) } : {},
|
|
2874
|
+
...relay && this.services(config).some((service) => service.id === relay) ? { relay } : {}
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2499
2877
|
use(feature, id) {
|
|
2500
2878
|
var _a;
|
|
2501
2879
|
const config = this.read();
|
|
@@ -2518,7 +2896,7 @@ class RelaysFile {
|
|
|
2518
2896
|
this.write({ ...config, use });
|
|
2519
2897
|
}
|
|
2520
2898
|
write(config) {
|
|
2521
|
-
mkdirSync(
|
|
2899
|
+
mkdirSync(dirname4(this.file), { recursive: true });
|
|
2522
2900
|
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
2523
2901
|
writeFileSync(temporary, `${JSON.stringify(config, null, 2)}
|
|
2524
2902
|
`, { mode: 384 });
|
|
@@ -2538,290 +2916,116 @@ class RelaysFile {
|
|
|
2538
2916
|
}
|
|
2539
2917
|
RelaysFile.FILE = "relays.json";
|
|
2540
2918
|
|
|
2541
|
-
// web-src/sync-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
this.device = device;
|
|
2554
|
-
this.now = now;
|
|
2919
|
+
// web-src/sync-folder.ts
|
|
2920
|
+
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, createHmac, randomBytes as randomBytes4 } from "node:crypto";
|
|
2921
|
+
import { watch } from "node:fs";
|
|
2922
|
+
import { mkdir as mkdir4, readdir as readdir5, readFile as readFile4, rename as rename4, rm as rm3, stat as stat5, writeFile as writeFile3 } from "node:fs/promises";
|
|
2923
|
+
import { join as join6, sep as sep3 } from "node:path";
|
|
2924
|
+
var CHECK = "ta-sync folder v1";
|
|
2925
|
+
var DIR = "ta-sync";
|
|
2926
|
+
var FOLDER_PIECE = 4 * 1024 * 1024;
|
|
2927
|
+
var FolderSyncUtil;
|
|
2928
|
+
((FolderSyncUtil) => {
|
|
2929
|
+
function randomId() {
|
|
2930
|
+
return randomBytes4(16).toString("base64url");
|
|
2555
2931
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2932
|
+
FolderSyncUtil.randomId = randomId;
|
|
2933
|
+
function randomKey() {
|
|
2934
|
+
return randomBytes4(32).toString("base64url");
|
|
2935
|
+
}
|
|
2936
|
+
FolderSyncUtil.randomKey = randomKey;
|
|
2937
|
+
function link(record, name) {
|
|
2938
|
+
const fragment = new URLSearchParams({ v: "1", s: record.id, k: record.key, p: record.path, n: name });
|
|
2939
|
+
return `ta-sync://folder#${fragment}`;
|
|
2940
|
+
}
|
|
2941
|
+
FolderSyncUtil.link = link;
|
|
2942
|
+
function storeLink(record, config, name) {
|
|
2943
|
+
const options = Buffer.from(JSON.stringify(config.options)).toString("base64url");
|
|
2944
|
+
const fragment = new URLSearchParams({
|
|
2945
|
+
v: "1",
|
|
2946
|
+
s: record.id,
|
|
2947
|
+
k: record.key,
|
|
2948
|
+
t: config.type,
|
|
2949
|
+
o: options,
|
|
2950
|
+
...config.name ? { a: config.name } : {},
|
|
2951
|
+
n: name
|
|
2952
|
+
});
|
|
2953
|
+
return `ta-sync://store#${fragment}`;
|
|
2954
|
+
}
|
|
2955
|
+
FolderSyncUtil.storeLink = storeLink;
|
|
2956
|
+
function isStore(text) {
|
|
2957
|
+
return String(text ?? "").trim().startsWith("ta-sync://store#");
|
|
2958
|
+
}
|
|
2959
|
+
FolderSyncUtil.isStore = isStore;
|
|
2960
|
+
function parseStore(text) {
|
|
2961
|
+
const value = String(text ?? "").trim();
|
|
2962
|
+
const fragment = new URLSearchParams(value.slice(value.indexOf("#") + 1));
|
|
2963
|
+
const [id, key, type] = ["s", "k", "t"].map((name) => fragment.get(name) ?? "");
|
|
2964
|
+
let options;
|
|
2965
|
+
try {
|
|
2966
|
+
options = JSON.parse(Buffer.from(fragment.get("o") ?? "", "base64url").toString("utf8"));
|
|
2967
|
+
} catch {
|
|
2968
|
+
options = undefined;
|
|
2563
2969
|
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2970
|
+
if (!isStore(value) || fragment.get("v") !== "1" || !/^[A-Za-z0-9_-]{16,64}$/.test(id) || !/^[A-Za-z0-9_-]{43}$/.test(key) || !/^[a-z][a-z0-9-]{1,31}$/.test(type) || !options || typeof options !== "object" || Array.isArray(options)) {
|
|
2971
|
+
throw new Error("This is not a link of sync in a storage.");
|
|
2972
|
+
}
|
|
2973
|
+
return { id, key, type, options, service: fragment.get("a") ?? "", name: fragment.get("n") ?? "" };
|
|
2566
2974
|
}
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2975
|
+
FolderSyncUtil.parseStore = parseStore;
|
|
2976
|
+
function is(text) {
|
|
2977
|
+
return String(text ?? "").trim().startsWith("ta-sync://folder#");
|
|
2978
|
+
}
|
|
2979
|
+
FolderSyncUtil.is = is;
|
|
2980
|
+
function parse(text) {
|
|
2981
|
+
const value = String(text ?? "").trim();
|
|
2982
|
+
const fragment = new URLSearchParams(value.slice(value.indexOf("#") + 1));
|
|
2983
|
+
const [id, key, path] = ["s", "k", "p"].map((name) => fragment.get(name) ?? "");
|
|
2984
|
+
if (!is(value) || fragment.get("v") !== "1" || !/^[A-Za-z0-9_-]{16,64}$/.test(id) || !/^[A-Za-z0-9_-]{43}$/.test(key) || !path) {
|
|
2985
|
+
throw new Error("This is not a link of sync in a folder.");
|
|
2986
|
+
}
|
|
2987
|
+
return { id, key, path, name: fragment.get("n") ?? "" };
|
|
2988
|
+
}
|
|
2989
|
+
FolderSyncUtil.parse = parse;
|
|
2990
|
+
})(FolderSyncUtil ||= {});
|
|
2991
|
+
|
|
2992
|
+
class LocalFolderStore {
|
|
2993
|
+
root;
|
|
2994
|
+
constructor(root) {
|
|
2995
|
+
this.root = root;
|
|
2996
|
+
}
|
|
2997
|
+
async list(dir) {
|
|
2998
|
+
const found = [];
|
|
2999
|
+
const at = join6(this.root, ...dir.split("/").filter(Boolean));
|
|
3000
|
+
for (const entry of await readdir5(at, { withFileTypes: true }).catch(() => [])) {
|
|
3001
|
+
if (entry.name.startsWith(".")) {
|
|
2575
3002
|
continue;
|
|
2576
3003
|
}
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
}
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
const type = local?.type ?? remote?.entry.t ?? "bytes";
|
|
2587
|
-
const mergeable = type === "json" || type === "set";
|
|
2588
|
-
const had = base.items[id];
|
|
2589
|
-
const action = SyncMerge.decide(local, remote?.entry, had?.h, mergeable && (local?.type ?? type) === (remote?.entry.t ?? type));
|
|
2590
|
-
switch (action) {
|
|
2591
|
-
case "none":
|
|
2592
|
-
base.items[id] = { h: local?.h ?? "", ...local?.value === undefined ? {} : { v: local.value } };
|
|
2593
|
-
return false;
|
|
2594
|
-
case "forget":
|
|
2595
|
-
delete base.items[id];
|
|
2596
|
-
return false;
|
|
2597
|
-
case "push":
|
|
2598
|
-
case "keepLocal": {
|
|
2599
|
-
if (action === "keepLocal" && remote) {
|
|
2600
|
-
const theirs = await this.content(remote.entry);
|
|
2601
|
-
if (theirs) {
|
|
2602
|
-
await this.place.keep(id, remote.entry.t, theirs, remote.entry.by);
|
|
2603
|
-
}
|
|
2604
|
-
}
|
|
2605
|
-
const ok = await this.send(id, local, remote);
|
|
2606
|
-
if (ok) {
|
|
2607
|
-
base.items[id] = { h: local?.h ?? "", ...local?.value === undefined ? {} : { v: local.value } };
|
|
2608
|
-
report.sent++;
|
|
2609
|
-
}
|
|
2610
|
-
return !ok;
|
|
2611
|
-
}
|
|
2612
|
-
case "pull":
|
|
2613
|
-
case "keepRemote": {
|
|
2614
|
-
const entry = remote?.entry;
|
|
2615
|
-
const content = entry && !entry.deleted ? await this.content(entry) : undefined;
|
|
2616
|
-
if (entry && !entry.deleted && !content) {
|
|
2617
|
-
return false;
|
|
2618
|
-
}
|
|
2619
|
-
const aside = !!local && (action === "keepRemote" || had === undefined || local.h !== had.h);
|
|
2620
|
-
await this.place.apply(id, entry?.t ?? type, content, aside);
|
|
2621
|
-
base.items[id] = { h: content ? entry?.h ?? "" : "", ...content && mergeable ? { v: SyncCodec.parse(content) } : {} };
|
|
2622
|
-
if (local || content) {
|
|
2623
|
-
report.received++;
|
|
2624
|
-
}
|
|
2625
|
-
return false;
|
|
2626
|
-
}
|
|
2627
|
-
case "merge":
|
|
2628
|
-
return this.merge(id, local, remote, had, base, report);
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
async merge(id, local, remote, had, base, report) {
|
|
2632
|
-
const content = await this.content(remote.entry);
|
|
2633
|
-
if (!content) {
|
|
2634
|
-
return false;
|
|
2635
|
-
}
|
|
2636
|
-
const theirs = SyncCodec.parse(content);
|
|
2637
|
-
const merged = local.type === "set" ? SyncMerge.set(Array.isArray(had?.v) ? had.v : undefined, Array.isArray(local.value) ? local.value : [], Array.isArray(theirs) ? theirs : []) : SyncMerge.value(had?.v, local.value, theirs);
|
|
2638
|
-
const item = SyncItems.item(id, local.type, SyncCodec.json(merged), this.now(), merged);
|
|
2639
|
-
if (item.h !== remote.entry.h && !await this.send(id, item, remote)) {
|
|
2640
|
-
return true;
|
|
2641
|
-
}
|
|
2642
|
-
if (item.h !== local.h) {
|
|
2643
|
-
await this.place.apply(id, local.type, item.bytes, false);
|
|
2644
|
-
report.received++;
|
|
2645
|
-
}
|
|
2646
|
-
if (item.h !== remote.entry.h) {
|
|
2647
|
-
report.sent++;
|
|
2648
|
-
}
|
|
2649
|
-
base.items[id] = { h: item.h, v: merged };
|
|
2650
|
-
return false;
|
|
2651
|
-
}
|
|
2652
|
-
async send(id, local, remote) {
|
|
2653
|
-
const entry = local ? { t: local.type, h: local.h, at: Math.round(local.at || this.now()), by: this.device, n: 0 } : { t: remote?.entry.t ?? "bytes", h: "", at: this.now(), by: this.device, n: 0, deleted: true };
|
|
2654
|
-
if (local) {
|
|
2655
|
-
const pieces = SyncCodec.encode(local.bytes, this.room.piece);
|
|
2656
|
-
entry.n = pieces.length;
|
|
2657
|
-
const there = await this.room.getState(`${SyncStateKeys.BLOB}${local.h}:`);
|
|
2658
|
-
for (const [index, piece] of pieces.entries()) {
|
|
2659
|
-
const key = SyncStateKeys.blob(local.h, index);
|
|
2660
|
-
if (there[key]?.value !== piece) {
|
|
2661
|
-
await this.room.setState(key, piece);
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
const result = await this.room.setState(SyncStateKeys.item(id), entry, remote?.version ?? 0);
|
|
2666
|
-
if (result.ok && remote && !remote.entry.deleted && remote.entry.h !== entry.h) {
|
|
2667
|
-
await this.dropBlob(remote.entry);
|
|
2668
|
-
}
|
|
2669
|
-
return result.ok;
|
|
2670
|
-
}
|
|
2671
|
-
async dropBlob(entry) {
|
|
2672
|
-
const remote = await this.remote();
|
|
2673
|
-
if ([...remote.values()].some(({ entry: other }) => !other.deleted && other.h === entry.h)) {
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
for (let index = 0;index < entry.n; index++) {
|
|
2677
|
-
await this.room.setState(SyncStateKeys.blob(entry.h, index), null);
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
async content(entry) {
|
|
2681
|
-
const state = await this.room.getState(`${SyncStateKeys.BLOB}${entry.h}:`);
|
|
2682
|
-
const pieces = [];
|
|
2683
|
-
for (let index = 0;index < entry.n; index++) {
|
|
2684
|
-
const piece = state[SyncStateKeys.blob(entry.h, index)]?.value;
|
|
2685
|
-
if (typeof piece !== "string") {
|
|
2686
|
-
return;
|
|
2687
|
-
}
|
|
2688
|
-
pieces.push(piece);
|
|
2689
|
-
}
|
|
2690
|
-
const bytes = SyncCodec.decode(pieces);
|
|
2691
|
-
return SyncCodec.hash(bytes) === entry.h ? bytes : undefined;
|
|
2692
|
-
}
|
|
2693
|
-
async remote() {
|
|
2694
|
-
const items = new Map;
|
|
2695
|
-
for (const [key, { value, version }] of Object.entries(await this.room.getState(SyncStateKeys.ITEM))) {
|
|
2696
|
-
if (isEntry(value)) {
|
|
2697
|
-
items.set(key.slice(SyncStateKeys.ITEM.length), { entry: value, version });
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
return items;
|
|
2701
|
-
}
|
|
2702
|
-
async dropOldMarks() {
|
|
2703
|
-
for (const [id, { entry, version }] of await this.remote()) {
|
|
2704
|
-
if (entry.deleted && this.now() - entry.at > TOMBSTONE_MS) {
|
|
2705
|
-
await this.room.setState(SyncStateKeys.item(id), null, version);
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
function isEntry(value) {
|
|
2711
|
-
const entry = value;
|
|
2712
|
-
return SyncMerge.isObject(value) && ["json", "set", "bytes", "tree"].includes(entry.t) && typeof entry.h === "string" && typeof entry.at === "number" && typeof entry.n === "number" && typeof entry.by === "string";
|
|
2713
|
-
}
|
|
2714
|
-
|
|
2715
|
-
// web-src/sync-folder.ts
|
|
2716
|
-
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, createHmac, randomBytes as randomBytes4 } from "node:crypto";
|
|
2717
|
-
import { watch } from "node:fs";
|
|
2718
|
-
import { mkdir as mkdir4, readdir as readdir4, readFile as readFile3, rename as rename4, rm as rm3, stat as stat4, writeFile as writeFile3 } from "node:fs/promises";
|
|
2719
|
-
import { join as join5, sep as sep3 } from "node:path";
|
|
2720
|
-
var CHECK = "ta-sync folder v1";
|
|
2721
|
-
var DIR = "ta-sync";
|
|
2722
|
-
var FOLDER_PIECE = 4 * 1024 * 1024;
|
|
2723
|
-
var FolderSyncUtil;
|
|
2724
|
-
((FolderSyncUtil) => {
|
|
2725
|
-
function randomId() {
|
|
2726
|
-
return randomBytes4(16).toString("base64url");
|
|
2727
|
-
}
|
|
2728
|
-
FolderSyncUtil.randomId = randomId;
|
|
2729
|
-
function randomKey() {
|
|
2730
|
-
return randomBytes4(32).toString("base64url");
|
|
2731
|
-
}
|
|
2732
|
-
FolderSyncUtil.randomKey = randomKey;
|
|
2733
|
-
function link(record, name) {
|
|
2734
|
-
const fragment = new URLSearchParams({ v: "1", s: record.id, k: record.key, p: record.path, n: name });
|
|
2735
|
-
return `ta-sync://folder#${fragment}`;
|
|
2736
|
-
}
|
|
2737
|
-
FolderSyncUtil.link = link;
|
|
2738
|
-
function storeLink(record, config, name) {
|
|
2739
|
-
const options = Buffer.from(JSON.stringify(config.options)).toString("base64url");
|
|
2740
|
-
const fragment = new URLSearchParams({
|
|
2741
|
-
v: "1",
|
|
2742
|
-
s: record.id,
|
|
2743
|
-
k: record.key,
|
|
2744
|
-
t: config.type,
|
|
2745
|
-
o: options,
|
|
2746
|
-
...config.name ? { a: config.name } : {},
|
|
2747
|
-
n: name
|
|
2748
|
-
});
|
|
2749
|
-
return `ta-sync://store#${fragment}`;
|
|
2750
|
-
}
|
|
2751
|
-
FolderSyncUtil.storeLink = storeLink;
|
|
2752
|
-
function isStore(text) {
|
|
2753
|
-
return String(text ?? "").trim().startsWith("ta-sync://store#");
|
|
2754
|
-
}
|
|
2755
|
-
FolderSyncUtil.isStore = isStore;
|
|
2756
|
-
function parseStore(text) {
|
|
2757
|
-
const value = String(text ?? "").trim();
|
|
2758
|
-
const fragment = new URLSearchParams(value.slice(value.indexOf("#") + 1));
|
|
2759
|
-
const [id, key, type] = ["s", "k", "t"].map((name) => fragment.get(name) ?? "");
|
|
2760
|
-
let options;
|
|
2761
|
-
try {
|
|
2762
|
-
options = JSON.parse(Buffer.from(fragment.get("o") ?? "", "base64url").toString("utf8"));
|
|
2763
|
-
} catch {
|
|
2764
|
-
options = undefined;
|
|
2765
|
-
}
|
|
2766
|
-
if (!isStore(value) || fragment.get("v") !== "1" || !/^[A-Za-z0-9_-]{16,64}$/.test(id) || !/^[A-Za-z0-9_-]{43}$/.test(key) || !/^[a-z][a-z0-9-]{1,31}$/.test(type) || !options || typeof options !== "object" || Array.isArray(options)) {
|
|
2767
|
-
throw new Error("This is not a link of sync in a storage.");
|
|
2768
|
-
}
|
|
2769
|
-
return { id, key, type, options, service: fragment.get("a") ?? "", name: fragment.get("n") ?? "" };
|
|
2770
|
-
}
|
|
2771
|
-
FolderSyncUtil.parseStore = parseStore;
|
|
2772
|
-
function is(text) {
|
|
2773
|
-
return String(text ?? "").trim().startsWith("ta-sync://folder#");
|
|
2774
|
-
}
|
|
2775
|
-
FolderSyncUtil.is = is;
|
|
2776
|
-
function parse(text) {
|
|
2777
|
-
const value = String(text ?? "").trim();
|
|
2778
|
-
const fragment = new URLSearchParams(value.slice(value.indexOf("#") + 1));
|
|
2779
|
-
const [id, key, path] = ["s", "k", "p"].map((name) => fragment.get(name) ?? "");
|
|
2780
|
-
if (!is(value) || fragment.get("v") !== "1" || !/^[A-Za-z0-9_-]{16,64}$/.test(id) || !/^[A-Za-z0-9_-]{43}$/.test(key) || !path) {
|
|
2781
|
-
throw new Error("This is not a link of sync in a folder.");
|
|
2782
|
-
}
|
|
2783
|
-
return { id, key, path, name: fragment.get("n") ?? "" };
|
|
2784
|
-
}
|
|
2785
|
-
FolderSyncUtil.parse = parse;
|
|
2786
|
-
})(FolderSyncUtil ||= {});
|
|
2787
|
-
|
|
2788
|
-
class LocalFolderStore {
|
|
2789
|
-
root;
|
|
2790
|
-
constructor(root) {
|
|
2791
|
-
this.root = root;
|
|
2792
|
-
}
|
|
2793
|
-
async list(dir) {
|
|
2794
|
-
const found = [];
|
|
2795
|
-
const at = join5(this.root, ...dir.split("/").filter(Boolean));
|
|
2796
|
-
for (const entry of await readdir4(at, { withFileTypes: true }).catch(() => [])) {
|
|
2797
|
-
if (entry.name.startsWith(".")) {
|
|
2798
|
-
continue;
|
|
2799
|
-
}
|
|
2800
|
-
if (entry.isDirectory()) {
|
|
2801
|
-
found.push({ name: entry.name, tag: "", dir: true });
|
|
2802
|
-
} else if (entry.isFile()) {
|
|
2803
|
-
const info = await stat4(join5(at, entry.name)).catch(() => {
|
|
2804
|
-
return;
|
|
2805
|
-
});
|
|
2806
|
-
if (info) {
|
|
2807
|
-
found.push({ name: entry.name, tag: `${info.mtimeMs}:${info.size}` });
|
|
2808
|
-
}
|
|
3004
|
+
if (entry.isDirectory()) {
|
|
3005
|
+
found.push({ name: entry.name, tag: "", dir: true });
|
|
3006
|
+
} else if (entry.isFile()) {
|
|
3007
|
+
const info = await stat5(join6(at, entry.name)).catch(() => {
|
|
3008
|
+
return;
|
|
3009
|
+
});
|
|
3010
|
+
if (info) {
|
|
3011
|
+
found.push({ name: entry.name, tag: `${info.mtimeMs}:${info.size}` });
|
|
3012
|
+
}
|
|
2809
3013
|
}
|
|
2810
3014
|
}
|
|
2811
3015
|
return found.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
2812
3016
|
}
|
|
2813
3017
|
async read(path) {
|
|
2814
3018
|
try {
|
|
2815
|
-
return new Uint8Array(await
|
|
3019
|
+
return new Uint8Array(await readFile4(this.path(path)));
|
|
2816
3020
|
} catch {
|
|
2817
3021
|
return;
|
|
2818
3022
|
}
|
|
2819
3023
|
}
|
|
2820
3024
|
async write(path, data) {
|
|
2821
3025
|
const file = this.path(path);
|
|
2822
|
-
const dir =
|
|
3026
|
+
const dir = join6(file, "..");
|
|
2823
3027
|
await mkdir4(dir, { recursive: true });
|
|
2824
|
-
const temporary =
|
|
3028
|
+
const temporary = join6(dir, `.${file.split(sep3).pop()}.${process.pid}.tmp`);
|
|
2825
3029
|
await writeFile3(temporary, data);
|
|
2826
3030
|
await rename4(temporary, file);
|
|
2827
3031
|
}
|
|
@@ -2839,7 +3043,7 @@ class LocalFolderStore {
|
|
|
2839
3043
|
return () => watcher?.close();
|
|
2840
3044
|
}
|
|
2841
3045
|
path(path) {
|
|
2842
|
-
return
|
|
3046
|
+
return join6(this.root, ...path.split("/").filter(Boolean));
|
|
2843
3047
|
}
|
|
2844
3048
|
}
|
|
2845
3049
|
|
|
@@ -3045,32 +3249,216 @@ class FolderSpace extends StoreSpace {
|
|
|
3045
3249
|
this.folder = folder;
|
|
3046
3250
|
}
|
|
3047
3251
|
get dir() {
|
|
3048
|
-
return
|
|
3252
|
+
return join6(this.folder, DIR, this.record.id);
|
|
3049
3253
|
}
|
|
3050
3254
|
}
|
|
3051
3255
|
|
|
3052
|
-
// web-src/sync-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
SyncIdentityKeys.IDENTITY = "id:identity";
|
|
3057
|
-
SyncIdentityKeys.ROOM = "id:room:";
|
|
3058
|
-
SyncIdentityKeys.FRIENDS = "id:friends";
|
|
3059
|
-
function room(member) {
|
|
3060
|
-
return `${SyncIdentityKeys.ROOM}${member}`;
|
|
3061
|
-
}
|
|
3062
|
-
SyncIdentityKeys.room = room;
|
|
3063
|
-
})(SyncIdentityKeys ||= {});
|
|
3064
|
-
var MAX_FRIENDS = 150;
|
|
3256
|
+
// web-src/sync-service-space.ts
|
|
3257
|
+
import { mkdir as mkdir6, readFile as readFile6, rename as rename6, writeFile as writeFile5 } from "node:fs/promises";
|
|
3258
|
+
import { platform as platform3 } from "node:os";
|
|
3259
|
+
import { join as join8 } from "node:path";
|
|
3065
3260
|
|
|
3066
|
-
|
|
3261
|
+
// web-src/sync-service-base.ts
|
|
3262
|
+
import { mkdir as mkdir5, readFile as readFile5, rename as rename5, writeFile as writeFile4 } from "node:fs/promises";
|
|
3263
|
+
import { hostname as hostname3, platform as platform2 } from "node:os";
|
|
3264
|
+
import { join as join7 } from "node:path";
|
|
3265
|
+
|
|
3266
|
+
// web-src/sync-engine.ts
|
|
3267
|
+
var ATTEMPTS = 3;
|
|
3268
|
+
var TOMBSTONE_MS = 90 * 24 * 60 * 60 * 1000;
|
|
3269
|
+
|
|
3270
|
+
class SyncEngine {
|
|
3067
3271
|
room;
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3272
|
+
place;
|
|
3273
|
+
device;
|
|
3274
|
+
now;
|
|
3275
|
+
constructor(room, place, device, now = Date.now) {
|
|
3071
3276
|
this.room = room;
|
|
3072
|
-
this.
|
|
3073
|
-
this.
|
|
3277
|
+
this.place = place;
|
|
3278
|
+
this.device = device;
|
|
3279
|
+
this.now = now;
|
|
3280
|
+
}
|
|
3281
|
+
async round(base, resources) {
|
|
3282
|
+
const report = { at: this.now(), sent: 0, received: 0, skipped: [] };
|
|
3283
|
+
for (let attempt = 0;attempt < ATTEMPTS; attempt++) {
|
|
3284
|
+
const raced = await this.once(base, resources, report);
|
|
3285
|
+
if (!raced) {
|
|
3286
|
+
break;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
await this.dropOldMarks();
|
|
3290
|
+
return report;
|
|
3291
|
+
}
|
|
3292
|
+
async once(base, resources, report) {
|
|
3293
|
+
const remote = await this.remote();
|
|
3294
|
+
const local = await this.place.read(resources);
|
|
3295
|
+
const ids = new Set([...local.keys(), ...remote.keys(), ...Object.keys(base.items)]);
|
|
3296
|
+
let raced = false;
|
|
3297
|
+
for (const id of [...ids].sort()) {
|
|
3298
|
+
const resource = SyncItems.resourceOf(id);
|
|
3299
|
+
if (!resource || !resources.has(resource)) {
|
|
3300
|
+
continue;
|
|
3301
|
+
}
|
|
3302
|
+
try {
|
|
3303
|
+
raced = await this.item(id, local.get(id), remote.get(id), base, report) || raced;
|
|
3304
|
+
} catch (error) {
|
|
3305
|
+
report.skipped.push({ id, reason: error instanceof Error ? error.message : String(error) });
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
return raced;
|
|
3309
|
+
}
|
|
3310
|
+
async item(id, local, remote, base, report) {
|
|
3311
|
+
const type = local?.type ?? remote?.entry.t ?? "bytes";
|
|
3312
|
+
const mergeable = type === "json" || type === "set";
|
|
3313
|
+
const had = base.items[id];
|
|
3314
|
+
const action = SyncMerge.decide(local, remote?.entry, had?.h, mergeable && (local?.type ?? type) === (remote?.entry.t ?? type));
|
|
3315
|
+
switch (action) {
|
|
3316
|
+
case "none":
|
|
3317
|
+
base.items[id] = { h: local?.h ?? "", ...local?.value === undefined ? {} : { v: local.value } };
|
|
3318
|
+
return false;
|
|
3319
|
+
case "forget":
|
|
3320
|
+
delete base.items[id];
|
|
3321
|
+
return false;
|
|
3322
|
+
case "push":
|
|
3323
|
+
case "keepLocal": {
|
|
3324
|
+
if (action === "keepLocal" && remote) {
|
|
3325
|
+
const theirs = await this.content(remote.entry);
|
|
3326
|
+
if (theirs) {
|
|
3327
|
+
await this.place.keep(id, remote.entry.t, theirs, remote.entry.by);
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
const ok = await this.send(id, local, remote);
|
|
3331
|
+
if (ok) {
|
|
3332
|
+
base.items[id] = { h: local?.h ?? "", ...local?.value === undefined ? {} : { v: local.value } };
|
|
3333
|
+
report.sent++;
|
|
3334
|
+
}
|
|
3335
|
+
return !ok;
|
|
3336
|
+
}
|
|
3337
|
+
case "pull":
|
|
3338
|
+
case "keepRemote": {
|
|
3339
|
+
const entry = remote?.entry;
|
|
3340
|
+
const content = entry && !entry.deleted ? await this.content(entry) : undefined;
|
|
3341
|
+
if (entry && !entry.deleted && !content) {
|
|
3342
|
+
return false;
|
|
3343
|
+
}
|
|
3344
|
+
const aside = !!local && (action === "keepRemote" || had === undefined || local.h !== had.h);
|
|
3345
|
+
await this.place.apply(id, entry?.t ?? type, content, aside);
|
|
3346
|
+
base.items[id] = { h: content ? entry?.h ?? "" : "", ...content && mergeable ? { v: SyncCodec.parse(content) } : {} };
|
|
3347
|
+
if (local || content) {
|
|
3348
|
+
report.received++;
|
|
3349
|
+
}
|
|
3350
|
+
return false;
|
|
3351
|
+
}
|
|
3352
|
+
case "merge":
|
|
3353
|
+
return this.merge(id, local, remote, had, base, report);
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
async merge(id, local, remote, had, base, report) {
|
|
3357
|
+
const content = await this.content(remote.entry);
|
|
3358
|
+
if (!content) {
|
|
3359
|
+
return false;
|
|
3360
|
+
}
|
|
3361
|
+
const theirs = SyncCodec.parse(content);
|
|
3362
|
+
const merged = local.type === "set" ? SyncMerge.set(Array.isArray(had?.v) ? had.v : undefined, Array.isArray(local.value) ? local.value : [], Array.isArray(theirs) ? theirs : []) : SyncMerge.value(had?.v, local.value, theirs);
|
|
3363
|
+
const item = SyncItems.item(id, local.type, SyncCodec.json(merged), this.now(), merged);
|
|
3364
|
+
if (item.h !== remote.entry.h && !await this.send(id, item, remote)) {
|
|
3365
|
+
return true;
|
|
3366
|
+
}
|
|
3367
|
+
if (item.h !== local.h) {
|
|
3368
|
+
await this.place.apply(id, local.type, item.bytes, false);
|
|
3369
|
+
report.received++;
|
|
3370
|
+
}
|
|
3371
|
+
if (item.h !== remote.entry.h) {
|
|
3372
|
+
report.sent++;
|
|
3373
|
+
}
|
|
3374
|
+
base.items[id] = { h: item.h, v: merged };
|
|
3375
|
+
return false;
|
|
3376
|
+
}
|
|
3377
|
+
async send(id, local, remote) {
|
|
3378
|
+
const entry = local ? { t: local.type, h: local.h, at: Math.round(local.at || this.now()), by: this.device, n: 0 } : { t: remote?.entry.t ?? "bytes", h: "", at: this.now(), by: this.device, n: 0, deleted: true };
|
|
3379
|
+
if (local) {
|
|
3380
|
+
const pieces = SyncCodec.encode(local.bytes, this.room.piece);
|
|
3381
|
+
entry.n = pieces.length;
|
|
3382
|
+
const there = await this.room.getState(`${SyncStateKeys.BLOB}${local.h}:`);
|
|
3383
|
+
for (const [index, piece] of pieces.entries()) {
|
|
3384
|
+
const key = SyncStateKeys.blob(local.h, index);
|
|
3385
|
+
if (there[key]?.value !== piece) {
|
|
3386
|
+
await this.room.setState(key, piece);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
const result = await this.room.setState(SyncStateKeys.item(id), entry, remote?.version ?? 0);
|
|
3391
|
+
if (result.ok && remote && !remote.entry.deleted && remote.entry.h !== entry.h) {
|
|
3392
|
+
await this.dropBlob(remote.entry);
|
|
3393
|
+
}
|
|
3394
|
+
return result.ok;
|
|
3395
|
+
}
|
|
3396
|
+
async dropBlob(entry) {
|
|
3397
|
+
const remote = await this.remote();
|
|
3398
|
+
if ([...remote.values()].some(({ entry: other }) => !other.deleted && other.h === entry.h)) {
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
for (let index = 0;index < entry.n; index++) {
|
|
3402
|
+
await this.room.setState(SyncStateKeys.blob(entry.h, index), null);
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
async content(entry) {
|
|
3406
|
+
const state = await this.room.getState(`${SyncStateKeys.BLOB}${entry.h}:`);
|
|
3407
|
+
const pieces = [];
|
|
3408
|
+
for (let index = 0;index < entry.n; index++) {
|
|
3409
|
+
const piece = state[SyncStateKeys.blob(entry.h, index)]?.value;
|
|
3410
|
+
if (typeof piece !== "string") {
|
|
3411
|
+
return;
|
|
3412
|
+
}
|
|
3413
|
+
pieces.push(piece);
|
|
3414
|
+
}
|
|
3415
|
+
const bytes = SyncCodec.decode(pieces);
|
|
3416
|
+
return SyncCodec.hash(bytes) === entry.h ? bytes : undefined;
|
|
3417
|
+
}
|
|
3418
|
+
async remote() {
|
|
3419
|
+
const items = new Map;
|
|
3420
|
+
for (const [key, { value, version }] of Object.entries(await this.room.getState(SyncStateKeys.ITEM))) {
|
|
3421
|
+
if (isEntry(value)) {
|
|
3422
|
+
items.set(key.slice(SyncStateKeys.ITEM.length), { entry: value, version });
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
return items;
|
|
3426
|
+
}
|
|
3427
|
+
async dropOldMarks() {
|
|
3428
|
+
for (const [id, { entry, version }] of await this.remote()) {
|
|
3429
|
+
if (entry.deleted && this.now() - entry.at > TOMBSTONE_MS) {
|
|
3430
|
+
await this.room.setState(SyncStateKeys.item(id), null, version);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
function isEntry(value) {
|
|
3436
|
+
const entry = value;
|
|
3437
|
+
return SyncMerge.isObject(value) && ["json", "set", "bytes", "tree"].includes(entry.t) && typeof entry.h === "string" && typeof entry.at === "number" && typeof entry.n === "number" && typeof entry.by === "string";
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
// web-src/sync-identity.ts
|
|
3441
|
+
var SyncIdentityKeys;
|
|
3442
|
+
((SyncIdentityKeys) => {
|
|
3443
|
+
SyncIdentityKeys.PREFIX = "id:";
|
|
3444
|
+
SyncIdentityKeys.IDENTITY = "id:identity";
|
|
3445
|
+
SyncIdentityKeys.ROOM = "id:room:";
|
|
3446
|
+
SyncIdentityKeys.FRIENDS = "id:friends";
|
|
3447
|
+
function room(member) {
|
|
3448
|
+
return `${SyncIdentityKeys.ROOM}${member}`;
|
|
3449
|
+
}
|
|
3450
|
+
SyncIdentityKeys.room = room;
|
|
3451
|
+
})(SyncIdentityKeys ||= {});
|
|
3452
|
+
var MAX_FRIENDS = 150;
|
|
3453
|
+
|
|
3454
|
+
class SyncIdentity {
|
|
3455
|
+
room;
|
|
3456
|
+
side;
|
|
3457
|
+
skip;
|
|
3458
|
+
constructor(room, side, skip) {
|
|
3459
|
+
this.room = room;
|
|
3460
|
+
this.side = side;
|
|
3461
|
+
this.skip = skip;
|
|
3074
3462
|
}
|
|
3075
3463
|
async round(base) {
|
|
3076
3464
|
const report = { switched: false, sent: 0, received: 0 };
|
|
@@ -3224,8 +3612,8 @@ var SyncIdentityUtil;
|
|
|
3224
3612
|
SyncIdentityUtil.byId = byId;
|
|
3225
3613
|
})(SyncIdentityUtil ||= {});
|
|
3226
3614
|
|
|
3227
|
-
// web-src/sync-service.ts
|
|
3228
|
-
class
|
|
3615
|
+
// web-src/sync-service-base.ts
|
|
3616
|
+
class SyncServiceBase {
|
|
3229
3617
|
options;
|
|
3230
3618
|
device;
|
|
3231
3619
|
baseFile;
|
|
@@ -3245,288 +3633,63 @@ class SyncService {
|
|
|
3245
3633
|
folderFile;
|
|
3246
3634
|
constructor(options) {
|
|
3247
3635
|
this.options = options;
|
|
3248
|
-
this.device = options.device ??
|
|
3249
|
-
this.baseFile =
|
|
3250
|
-
this.folderFile =
|
|
3636
|
+
this.device = options.device ?? SyncServiceBase.deviceName();
|
|
3637
|
+
this.baseFile = join7(options.agentDir, "sync", "base.json");
|
|
3638
|
+
this.folderFile = join7(options.agentDir, "sync", "folder.json");
|
|
3251
3639
|
}
|
|
3252
3640
|
static deviceName() {
|
|
3253
3641
|
return hostname3().replace(/\.local$/, "") || platform2();
|
|
3254
3642
|
}
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3643
|
+
heard(event) {
|
|
3644
|
+
if (event.type === "rooms" || event.type === "request") {
|
|
3645
|
+
this.publish();
|
|
3646
|
+
return;
|
|
3647
|
+
}
|
|
3648
|
+
if (event.type === "state" && (event.key.startsWith(SyncStateKeys.ITEM) || event.key.startsWith(SyncStateKeys.BLOB) || event.key.startsWith(SyncIdentityKeys.PREFIX))) {
|
|
3649
|
+
this.room().then((room) => {
|
|
3650
|
+
const self = room?.members.find((member) => member.self)?.member;
|
|
3651
|
+
if (room?.id === event.room && event.by !== self) {
|
|
3652
|
+
this.schedule();
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
}
|
|
3262
3656
|
}
|
|
3263
|
-
|
|
3264
|
-
this.stopped
|
|
3265
|
-
|
|
3266
|
-
clearInterval(this.look);
|
|
3267
|
-
this.space?.stop();
|
|
3268
|
-
for (const stop of this.stops) {
|
|
3269
|
-
stop();
|
|
3657
|
+
schedule(delay = this.options.delayMs ?? 1500) {
|
|
3658
|
+
if (this.stopped) {
|
|
3659
|
+
return;
|
|
3270
3660
|
}
|
|
3661
|
+
clearTimeout(this.timer);
|
|
3662
|
+
this.timer = setTimeout(() => void this.run(), delay);
|
|
3271
3663
|
}
|
|
3272
|
-
|
|
3273
|
-
if (
|
|
3274
|
-
this.
|
|
3664
|
+
run() {
|
|
3665
|
+
if (this.running) {
|
|
3666
|
+
this.again = true;
|
|
3667
|
+
return this.running;
|
|
3275
3668
|
}
|
|
3669
|
+
this.running = this.round().catch((error) => {
|
|
3670
|
+
this.report = { at: Date.now(), sent: 0, received: 0, skipped: [], error: error instanceof Error ? error.message : String(error) };
|
|
3671
|
+
}).finally(async () => {
|
|
3672
|
+
this.running = undefined;
|
|
3673
|
+
await this.options.storage.set(SyncKeys.REPORT, this.report).catch(() => {
|
|
3674
|
+
return;
|
|
3675
|
+
});
|
|
3676
|
+
await this.publish();
|
|
3677
|
+
if (this.again && !this.stopped) {
|
|
3678
|
+
this.again = false;
|
|
3679
|
+
this.schedule(0);
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3682
|
+
this.publish();
|
|
3683
|
+
return this.running;
|
|
3276
3684
|
}
|
|
3277
|
-
async
|
|
3278
|
-
const resources = await this.resources();
|
|
3279
|
-
const replaced = { dir: this.options.place.replacedDir, count: await this.options.place.replacedCount() };
|
|
3280
|
-
const common = { resources, syncing: !!this.running, last: this.report, replaced };
|
|
3685
|
+
async round() {
|
|
3281
3686
|
const folder = await this.folderRecord();
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
return {
|
|
3289
|
-
state: "on",
|
|
3290
|
-
where: "store",
|
|
3291
|
-
via: service?.name ?? service?.where ?? folder.type ?? "",
|
|
3292
|
-
store: { type: folder.type ?? service?.type ?? "", where: service?.where ?? "", ...problem ? { problem } : {} },
|
|
3293
|
-
owner: false,
|
|
3294
|
-
connected: !problem,
|
|
3295
|
-
devices: problem || !opened.space ? [] : await this.folderDevices(opened.space),
|
|
3296
|
-
asks: [],
|
|
3297
|
-
...common
|
|
3298
|
-
};
|
|
3299
|
-
}
|
|
3300
|
-
if (folder) {
|
|
3301
|
-
const opened = await this.openSpace(folder);
|
|
3302
|
-
const space = opened.space;
|
|
3303
|
-
const problem = opened.problem ?? await this.problemOf(space, folder);
|
|
3304
|
-
const target = await this.target();
|
|
3305
|
-
const named = target.type === "folder" && target.path && RelayServiceUtil.expand(target.path) === RelayServiceUtil.expand(folder.path) ? target.name : undefined;
|
|
3306
|
-
return {
|
|
3307
|
-
state: "on",
|
|
3308
|
-
where: "folder",
|
|
3309
|
-
via: named ?? SyncService.lastPart(folder.path),
|
|
3310
|
-
folder: { path: RelayServiceUtil.expand(folder.path), ...problem ? { problem } : {} },
|
|
3311
|
-
owner: false,
|
|
3312
|
-
connected: !problem,
|
|
3313
|
-
devices: problem ? [] : await this.folderDevices(space),
|
|
3314
|
-
asks: [],
|
|
3315
|
-
...common
|
|
3316
|
-
};
|
|
3317
|
-
}
|
|
3318
|
-
const room = await this.room();
|
|
3319
|
-
if (!room) {
|
|
3320
|
-
const target = await this.target();
|
|
3321
|
-
return {
|
|
3322
|
-
state: "off",
|
|
3323
|
-
where: target.type === "ta-relay" ? "relay" : target.type,
|
|
3324
|
-
via: target.name ?? (target.type === "folder" ? SyncService.lastPart(target.path ?? "") : target.type === "store" ? target.where : target.host),
|
|
3325
|
-
...target.type === "folder" ? { folder: { path: RelayServiceUtil.expand(target.path ?? "") } } : {},
|
|
3326
|
-
...target.type === "store" ? { store: { type: target.store ?? "", where: target.where ?? "" } } : {},
|
|
3327
|
-
owner: false,
|
|
3328
|
-
connected: false,
|
|
3329
|
-
devices: [],
|
|
3330
|
-
asks: [],
|
|
3331
|
-
...common
|
|
3332
|
-
};
|
|
3333
|
-
}
|
|
3334
|
-
const state = room.status === "member" ? "on" : room.status;
|
|
3335
|
-
return {
|
|
3336
|
-
state,
|
|
3337
|
-
where: "relay",
|
|
3338
|
-
...room.relay ? { via: await this.relayName(room.relay) } : {},
|
|
3339
|
-
owner: room.owner,
|
|
3340
|
-
ownerName: room.ownerName,
|
|
3341
|
-
connected: room.connected,
|
|
3342
|
-
devices: state === "on" ? await this.devices(room) : [],
|
|
3343
|
-
asks: room.owner ? (await this.options.rooms.listRequests().catch(() => [])).filter((request) => request.room === room.id && !request.guest).map(({ ask, name, at }) => ({ ask, name, at })) : [],
|
|
3344
|
-
...common
|
|
3345
|
-
};
|
|
3346
|
-
}
|
|
3347
|
-
async enable() {
|
|
3348
|
-
const target = await this.target();
|
|
3349
|
-
if (target.type === "folder" && target.path || target.type === "store" && target.id) {
|
|
3350
|
-
const before = await this.room();
|
|
3351
|
-
if (before) {
|
|
3352
|
-
await this.options.rooms.leave(before.id);
|
|
3353
|
-
}
|
|
3354
|
-
const current = await this.folderRecord();
|
|
3355
|
-
const same = !!current && (target.type === "store" ? current.service === target.id : !current.service && RelayServiceUtil.expand(current.path) === RelayServiceUtil.expand(target.path ?? ""));
|
|
3356
|
-
if (!same) {
|
|
3357
|
-
const record = {
|
|
3358
|
-
id: FolderSyncUtil.randomId(),
|
|
3359
|
-
key: FolderSyncUtil.randomKey(),
|
|
3360
|
-
path: target.type === "folder" ? target.path ?? "" : "",
|
|
3361
|
-
...target.type === "store" ? { service: target.id, type: target.store } : {},
|
|
3362
|
-
device: FolderSyncUtil.randomId(),
|
|
3363
|
-
at: Date.now()
|
|
3364
|
-
};
|
|
3365
|
-
const problem = target.type === "folder" ? RelayServiceUtil.checkFolder(record.path) : undefined;
|
|
3366
|
-
if (problem) {
|
|
3367
|
-
throw new Error(problem);
|
|
3368
|
-
}
|
|
3369
|
-
const opened = await this.openSpace(record);
|
|
3370
|
-
if (!opened.space) {
|
|
3371
|
-
throw new Error(opened.problem);
|
|
3372
|
-
}
|
|
3373
|
-
await opened.space.create();
|
|
3374
|
-
await this.saveFolder(record);
|
|
3375
|
-
}
|
|
3376
|
-
await this.publish();
|
|
3377
|
-
this.schedule(0);
|
|
3378
|
-
return this.status();
|
|
3379
|
-
}
|
|
3380
|
-
const room = await this.room();
|
|
3381
|
-
if (room?.status !== "member") {
|
|
3382
|
-
if (room) {
|
|
3383
|
-
await this.options.rooms.leave(room.id);
|
|
3384
|
-
}
|
|
3385
|
-
await this.options.rooms.createRoom({ kind: SYNC_KIND, title: SyncServerTexts.title(), view: SYNC_VIEW, unlisted: true, use: "sync" });
|
|
3386
|
-
}
|
|
3387
|
-
this.schedule(0);
|
|
3388
|
-
return this.status();
|
|
3389
|
-
}
|
|
3390
|
-
async invite(renew = false) {
|
|
3391
|
-
const folder = await this.folderRecord();
|
|
3392
|
-
if (folder?.service) {
|
|
3393
|
-
const config = await this.options.relays?.storeConfig(folder.service);
|
|
3394
|
-
if (!config) {
|
|
3395
|
-
throw new Error(SyncServerTexts.storeUnavailable(folder.type ?? ""));
|
|
3396
|
-
}
|
|
3397
|
-
return { link: FolderSyncUtil.storeLink(folder, config, this.device), expiresAt: 0 };
|
|
3398
|
-
}
|
|
3399
|
-
if (folder) {
|
|
3400
|
-
return { link: FolderSyncUtil.link(folder, this.device), expiresAt: 0 };
|
|
3401
|
-
}
|
|
3402
|
-
const room = await this.room();
|
|
3403
|
-
if (room?.status !== "member") {
|
|
3404
|
-
throw new Error(SyncServerTexts.notOn());
|
|
3405
|
-
}
|
|
3406
|
-
if (!room.owner) {
|
|
3407
|
-
throw new Error(SyncServerTexts.notOwner(room.ownerName));
|
|
3408
|
-
}
|
|
3409
|
-
return this.options.rooms.invite(room.id, { renew });
|
|
3410
|
-
}
|
|
3411
|
-
async join(link) {
|
|
3412
|
-
const room = await this.room();
|
|
3413
|
-
if (room?.status === "member" || await this.folderRecord()) {
|
|
3414
|
-
throw new Error(SyncServerTexts.alreadyOn());
|
|
3415
|
-
}
|
|
3416
|
-
if (FolderSyncUtil.is(link)) {
|
|
3417
|
-
return this.joinFolder(link);
|
|
3418
|
-
}
|
|
3419
|
-
if (FolderSyncUtil.isStore(link)) {
|
|
3420
|
-
return this.joinStore(link);
|
|
3421
|
-
}
|
|
3422
|
-
if (room) {
|
|
3423
|
-
await this.options.rooms.leave(room.id);
|
|
3424
|
-
}
|
|
3425
|
-
const joined = await this.options.rooms.join(link);
|
|
3426
|
-
await this.options.storage.set(SyncKeys.JOINING, joined.id);
|
|
3427
|
-
await this.publish();
|
|
3428
|
-
return this.status();
|
|
3429
|
-
}
|
|
3430
|
-
async leave() {
|
|
3431
|
-
const folder = await this.folderRecord();
|
|
3432
|
-
if (folder) {
|
|
3433
|
-
this.space?.stop();
|
|
3434
|
-
this.space = undefined;
|
|
3435
|
-
await rm4(this.folderFile, { force: true });
|
|
3436
|
-
}
|
|
3437
|
-
const room = await this.room();
|
|
3438
|
-
if (room) {
|
|
3439
|
-
await this.options.rooms.leave(room.id);
|
|
3440
|
-
}
|
|
3441
|
-
await this.options.storage.set(SyncKeys.JOINING, null);
|
|
3442
|
-
await this.saveBase({ room: "", items: {} });
|
|
3443
|
-
await this.publish();
|
|
3444
|
-
return this.status();
|
|
3445
|
-
}
|
|
3446
|
-
async answer(ask, accept) {
|
|
3447
|
-
const room = await this.room();
|
|
3448
|
-
if (room?.owner) {
|
|
3449
|
-
await this.options.rooms.answer(room.id, ask, accept);
|
|
3450
|
-
}
|
|
3451
|
-
await this.publish();
|
|
3452
|
-
return this.status();
|
|
3453
|
-
}
|
|
3454
|
-
async removeDevice(member) {
|
|
3455
|
-
const room = await this.room();
|
|
3456
|
-
if (room?.owner) {
|
|
3457
|
-
await this.options.rooms.removeMember(room.id, member);
|
|
3458
|
-
await this.options.rooms.setState(room.id, SyncStateKeys.device(member), null).catch(() => {
|
|
3459
|
-
return;
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
|
-
return this.status();
|
|
3463
|
-
}
|
|
3464
|
-
async setResources(change) {
|
|
3465
|
-
const resources = { ...await this.resources() };
|
|
3466
|
-
for (const resource of SYNC_RESOURCES) {
|
|
3467
|
-
if (typeof change?.[resource] === "boolean") {
|
|
3468
|
-
resources[resource] = change[resource];
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
|
-
await this.options.storage.set(SyncKeys.RESOURCES, resources);
|
|
3472
|
-
this.schedule(0);
|
|
3473
|
-
return this.status();
|
|
3474
|
-
}
|
|
3475
|
-
async syncNow() {
|
|
3476
|
-
clearTimeout(this.timer);
|
|
3477
|
-
await this.run();
|
|
3478
|
-
return this.status();
|
|
3479
|
-
}
|
|
3480
|
-
heard(event) {
|
|
3481
|
-
if (event.type === "rooms" || event.type === "request") {
|
|
3482
|
-
this.publish();
|
|
3483
|
-
return;
|
|
3484
|
-
}
|
|
3485
|
-
if (event.type === "state" && (event.key.startsWith(SyncStateKeys.ITEM) || event.key.startsWith(SyncStateKeys.BLOB) || event.key.startsWith(SyncIdentityKeys.PREFIX))) {
|
|
3486
|
-
this.room().then((room) => {
|
|
3487
|
-
const self = room?.members.find((member) => member.self)?.member;
|
|
3488
|
-
if (room?.id === event.room && event.by !== self) {
|
|
3489
|
-
this.schedule();
|
|
3490
|
-
}
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
schedule(delay = this.options.delayMs ?? 1500) {
|
|
3495
|
-
if (this.stopped) {
|
|
3496
|
-
return;
|
|
3497
|
-
}
|
|
3498
|
-
clearTimeout(this.timer);
|
|
3499
|
-
this.timer = setTimeout(() => void this.run(), delay);
|
|
3500
|
-
}
|
|
3501
|
-
run() {
|
|
3502
|
-
if (this.running) {
|
|
3503
|
-
this.again = true;
|
|
3504
|
-
return this.running;
|
|
3505
|
-
}
|
|
3506
|
-
this.running = this.round().catch((error) => {
|
|
3507
|
-
this.report = { at: Date.now(), sent: 0, received: 0, skipped: [], error: error instanceof Error ? error.message : String(error) };
|
|
3508
|
-
}).finally(async () => {
|
|
3509
|
-
this.running = undefined;
|
|
3510
|
-
await this.options.storage.set(SyncKeys.REPORT, this.report).catch(() => {
|
|
3511
|
-
return;
|
|
3512
|
-
});
|
|
3513
|
-
await this.publish();
|
|
3514
|
-
if (this.again && !this.stopped) {
|
|
3515
|
-
this.again = false;
|
|
3516
|
-
this.schedule(0);
|
|
3517
|
-
}
|
|
3518
|
-
});
|
|
3519
|
-
this.publish();
|
|
3520
|
-
return this.running;
|
|
3521
|
-
}
|
|
3522
|
-
async round() {
|
|
3523
|
-
const folder = await this.folderRecord();
|
|
3524
|
-
const room = folder ? undefined : await this.room();
|
|
3525
|
-
if (!folder && room?.status !== "member") {
|
|
3526
|
-
return;
|
|
3527
|
-
}
|
|
3528
|
-
let target;
|
|
3529
|
-
if (folder) {
|
|
3687
|
+
const room = folder ? undefined : await this.room();
|
|
3688
|
+
if (!folder && room?.status !== "member") {
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
let target;
|
|
3692
|
+
if (folder) {
|
|
3530
3693
|
const opened = await this.openSpace(folder);
|
|
3531
3694
|
const problem = opened.problem ?? await this.problemOf(opened.space, folder);
|
|
3532
3695
|
if (problem || !opened.space) {
|
|
@@ -3581,21 +3744,101 @@ class SyncService {
|
|
|
3581
3744
|
this.schedule(0);
|
|
3582
3745
|
}
|
|
3583
3746
|
}
|
|
3584
|
-
|
|
3585
|
-
const
|
|
3747
|
+
roomOf(id) {
|
|
3748
|
+
const rooms = this.options.rooms;
|
|
3749
|
+
return {
|
|
3750
|
+
getState: (prefix) => rooms.getState(id, prefix),
|
|
3751
|
+
setState: (key, value, version) => rooms.setState(id, key, value, version)
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
async room() {
|
|
3755
|
+
const joining = await this.options.storage.get(SyncKeys.JOINING).catch(() => {
|
|
3586
3756
|
return;
|
|
3587
3757
|
});
|
|
3588
|
-
const
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3758
|
+
const rooms = (await this.options.rooms.listRooms().catch(() => [])).filter((room) => room.kind === SYNC_KIND || room.id === joining && room.kind === "");
|
|
3759
|
+
const latest = (room) => room.joinedAt ?? room.createdAt;
|
|
3760
|
+
rooms.sort((a, b) => Number(b.status === "member") - Number(a.status === "member") || latest(b) - latest(a));
|
|
3761
|
+
return rooms[0];
|
|
3762
|
+
}
|
|
3763
|
+
async devices(room) {
|
|
3764
|
+
const state = await this.options.rooms.getState(room.id, SyncStateKeys.DEVICE).catch(() => ({}));
|
|
3765
|
+
return room.members.filter((member) => !member.guest).map((member) => {
|
|
3766
|
+
const entry = state[SyncStateKeys.device(member.member)]?.value;
|
|
3767
|
+
return {
|
|
3768
|
+
member: member.member,
|
|
3769
|
+
name: member.self ? this.device : entry?.name ?? member.name,
|
|
3770
|
+
platform: member.self ? platform2() : entry?.platform,
|
|
3771
|
+
online: member.online || member.self,
|
|
3772
|
+
self: member.self,
|
|
3773
|
+
owner: member.owner,
|
|
3774
|
+
...entry?.at ? { at: entry.at } : {}
|
|
3775
|
+
};
|
|
3776
|
+
}).sort((a, b) => Number(b.self) - Number(a.self) || Number(b.owner) - Number(a.owner) || a.name.localeCompare(b.name));
|
|
3777
|
+
}
|
|
3778
|
+
resourcesNow = { ...DEFAULT_RESOURCES };
|
|
3779
|
+
async resources() {
|
|
3780
|
+
const saved = await this.options.storage.get(SyncKeys.RESOURCES).catch(() => {
|
|
3781
|
+
return;
|
|
3782
|
+
});
|
|
3783
|
+
const resources = { ...DEFAULT_RESOURCES };
|
|
3784
|
+
if (SyncMerge.isObject(saved)) {
|
|
3785
|
+
for (const resource of SYNC_RESOURCES) {
|
|
3786
|
+
if (typeof saved[resource] === "boolean") {
|
|
3787
|
+
resources[resource] = saved[resource];
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
this.resourcesNow = resources;
|
|
3792
|
+
return resources;
|
|
3793
|
+
}
|
|
3794
|
+
async publish() {
|
|
3795
|
+
const status = await this.status().catch(() => {
|
|
3796
|
+
return;
|
|
3797
|
+
});
|
|
3798
|
+
const text = status ? SyncMerge.canonical(status) : "";
|
|
3799
|
+
if (status && text !== this.shown) {
|
|
3800
|
+
if (status.state === "on" && this.state !== "on") {
|
|
3801
|
+
this.schedule(0);
|
|
3802
|
+
}
|
|
3803
|
+
this.state = status.state;
|
|
3804
|
+
this.shown = text;
|
|
3805
|
+
await this.options.storage.set(SyncKeys.STATUS, status).catch(() => {
|
|
3806
|
+
return;
|
|
3807
|
+
});
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
async loadBase() {
|
|
3811
|
+
try {
|
|
3812
|
+
const data = JSON.parse(await readFile5(this.baseFile, "utf8"));
|
|
3813
|
+
return SyncMerge.isObject(data) && typeof data.room === "string" && SyncMerge.isObject(data.items) ? data : { room: "", items: {} };
|
|
3814
|
+
} catch {
|
|
3815
|
+
return { room: "", items: {} };
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
async saveBase(base) {
|
|
3819
|
+
await mkdir5(join7(this.options.agentDir, "sync"), { recursive: true });
|
|
3820
|
+
await writeFile4(`${this.baseFile}.tmp`, JSON.stringify(base));
|
|
3821
|
+
await rename5(`${this.baseFile}.tmp`, this.baseFile);
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
// web-src/sync-service-space.ts
|
|
3826
|
+
class SyncServiceSpace extends SyncServiceBase {
|
|
3827
|
+
async target() {
|
|
3828
|
+
const service = await this.options.relays?.serviceFor("sync").catch(() => {
|
|
3829
|
+
return;
|
|
3830
|
+
});
|
|
3831
|
+
const name = service?.builtin ? undefined : service?.name;
|
|
3832
|
+
if (service?.type === "folder") {
|
|
3833
|
+
return { type: "folder", path: service.path, id: service.id, ...name ? { name } : {} };
|
|
3834
|
+
}
|
|
3835
|
+
if (service && service.type !== "ta-relay") {
|
|
3593
3836
|
return { type: "store", id: service.id, store: service.type, where: service.where ?? service.type, ...name ? { name } : {} };
|
|
3594
3837
|
}
|
|
3595
3838
|
return {
|
|
3596
3839
|
type: "ta-relay",
|
|
3597
3840
|
name: service?.builtin || !service ? SyncServerTexts.official() : name,
|
|
3598
|
-
host:
|
|
3841
|
+
host: SyncServiceSpace.host(service?.url ?? "https://relay.cellbang.com")
|
|
3599
3842
|
};
|
|
3600
3843
|
}
|
|
3601
3844
|
async relayName(url) {
|
|
@@ -3603,7 +3846,7 @@ class SyncService {
|
|
|
3603
3846
|
return;
|
|
3604
3847
|
}) ?? [];
|
|
3605
3848
|
const named = relays.find((relay) => relay.url === url);
|
|
3606
|
-
return named?.builtin ? SyncServerTexts.official() : named?.name ??
|
|
3849
|
+
return named?.builtin ? SyncServerTexts.official() : named?.name ?? SyncServiceSpace.host(url);
|
|
3607
3850
|
}
|
|
3608
3851
|
static host(url) {
|
|
3609
3852
|
try {
|
|
@@ -3665,16 +3908,16 @@ class SyncService {
|
|
|
3665
3908
|
}
|
|
3666
3909
|
async folderRecord() {
|
|
3667
3910
|
try {
|
|
3668
|
-
const record = JSON.parse(await
|
|
3911
|
+
const record = JSON.parse(await readFile6(this.folderFile, "utf8"));
|
|
3669
3912
|
return record && typeof record.id === "string" && typeof record.key === "string" && typeof record.path === "string" && typeof record.device === "string" ? record : undefined;
|
|
3670
3913
|
} catch {
|
|
3671
3914
|
return;
|
|
3672
3915
|
}
|
|
3673
3916
|
}
|
|
3674
3917
|
async saveFolder(record) {
|
|
3675
|
-
await
|
|
3676
|
-
await
|
|
3677
|
-
await
|
|
3918
|
+
await mkdir6(join8(this.options.agentDir, "sync"), { recursive: true });
|
|
3919
|
+
await writeFile5(`${this.folderFile}.tmp`, JSON.stringify(record), { mode: 384 });
|
|
3920
|
+
await rename6(`${this.folderFile}.tmp`, this.folderFile);
|
|
3678
3921
|
}
|
|
3679
3922
|
async openSpace(record) {
|
|
3680
3923
|
const where = record.service ? `store:${record.service}` : `folder:${record.path}`;
|
|
@@ -3738,85 +3981,238 @@ class SyncService {
|
|
|
3738
3981
|
at: device.at
|
|
3739
3982
|
}));
|
|
3740
3983
|
if (self && !shown.some((device) => device.self)) {
|
|
3741
|
-
shown.push({ member: self, name: this.device, platform:
|
|
3984
|
+
shown.push({ member: self, name: this.device, platform: platform3(), online: true, self: true, owner: false });
|
|
3742
3985
|
}
|
|
3743
3986
|
return shown.sort((a, b) => Number(b.self) - Number(a.self) || (b.at ?? 0) - (a.at ?? 0));
|
|
3744
3987
|
}
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
return;
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
// web-src/sync-service.ts
|
|
3991
|
+
class SyncService extends SyncServiceSpace {
|
|
3992
|
+
start() {
|
|
3993
|
+
this.stops.push(this.options.rooms.onEvent((event) => this.heard(event)));
|
|
3994
|
+
this.look = setInterval(() => void this.lookAround(), this.options.lookMs ?? 30000);
|
|
3995
|
+
this.options.storage.get(SyncKeys.REPORT).then((report) => {
|
|
3996
|
+
this.report ??= report;
|
|
3755
3997
|
});
|
|
3756
|
-
|
|
3757
|
-
const latest = (room) => room.joinedAt ?? room.createdAt;
|
|
3758
|
-
rooms.sort((a, b) => Number(b.status === "member") - Number(a.status === "member") || latest(b) - latest(a));
|
|
3759
|
-
return rooms[0];
|
|
3998
|
+
this.schedule(2000);
|
|
3760
3999
|
}
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
4000
|
+
dispose() {
|
|
4001
|
+
this.stopped = true;
|
|
4002
|
+
clearTimeout(this.timer);
|
|
4003
|
+
clearInterval(this.look);
|
|
4004
|
+
this.space?.stop();
|
|
4005
|
+
for (const stop of this.stops) {
|
|
4006
|
+
stop();
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
dataChanged(name, key) {
|
|
4010
|
+
if (name === SYNC_PACKAGE ? key === SyncKeys.RESOURCES : this.options.place.tracks(name, key)) {
|
|
4011
|
+
this.schedule();
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
async status() {
|
|
4015
|
+
const resources = await this.resources();
|
|
4016
|
+
const replaced = { dir: this.options.place.replacedDir, count: await this.options.place.replacedCount() };
|
|
4017
|
+
const common = { resources, syncing: !!this.running, last: this.report, replaced };
|
|
4018
|
+
const folder = await this.folderRecord();
|
|
4019
|
+
if (folder?.service) {
|
|
4020
|
+
const opened = await this.openSpace(folder);
|
|
4021
|
+
const problem = opened.problem ?? await this.problemOf(opened.space, folder);
|
|
4022
|
+
const service = (await this.options.relays?.list().catch(() => {
|
|
4023
|
+
return;
|
|
4024
|
+
}) ?? []).find((each) => each.id === folder.service);
|
|
3765
4025
|
return {
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
4026
|
+
state: "on",
|
|
4027
|
+
where: "store",
|
|
4028
|
+
via: service?.name ?? service?.where ?? folder.type ?? "",
|
|
4029
|
+
store: { type: folder.type ?? service?.type ?? "", where: service?.where ?? "", ...problem ? { problem } : {} },
|
|
4030
|
+
owner: false,
|
|
4031
|
+
connected: !problem,
|
|
4032
|
+
devices: problem || !opened.space ? [] : await this.folderDevices(opened.space),
|
|
4033
|
+
asks: [],
|
|
4034
|
+
...common
|
|
3773
4035
|
};
|
|
3774
|
-
}
|
|
4036
|
+
}
|
|
4037
|
+
if (folder) {
|
|
4038
|
+
const opened = await this.openSpace(folder);
|
|
4039
|
+
const space = opened.space;
|
|
4040
|
+
const problem = opened.problem ?? await this.problemOf(space, folder);
|
|
4041
|
+
const target = await this.target();
|
|
4042
|
+
const named = target.type === "folder" && target.path && RelayServiceUtil.expand(target.path) === RelayServiceUtil.expand(folder.path) ? target.name : undefined;
|
|
4043
|
+
return {
|
|
4044
|
+
state: "on",
|
|
4045
|
+
where: "folder",
|
|
4046
|
+
via: named ?? SyncService.lastPart(folder.path),
|
|
4047
|
+
folder: { path: RelayServiceUtil.expand(folder.path), ...problem ? { problem } : {} },
|
|
4048
|
+
owner: false,
|
|
4049
|
+
connected: !problem,
|
|
4050
|
+
devices: problem ? [] : await this.folderDevices(space),
|
|
4051
|
+
asks: [],
|
|
4052
|
+
...common
|
|
4053
|
+
};
|
|
4054
|
+
}
|
|
4055
|
+
const room = await this.room();
|
|
4056
|
+
if (!room) {
|
|
4057
|
+
const target = await this.target();
|
|
4058
|
+
return {
|
|
4059
|
+
state: "off",
|
|
4060
|
+
where: target.type === "ta-relay" ? "relay" : target.type,
|
|
4061
|
+
via: target.name ?? (target.type === "folder" ? SyncService.lastPart(target.path ?? "") : target.type === "store" ? target.where : target.host),
|
|
4062
|
+
...target.type === "folder" ? { folder: { path: RelayServiceUtil.expand(target.path ?? "") } } : {},
|
|
4063
|
+
...target.type === "store" ? { store: { type: target.store ?? "", where: target.where ?? "" } } : {},
|
|
4064
|
+
owner: false,
|
|
4065
|
+
connected: false,
|
|
4066
|
+
devices: [],
|
|
4067
|
+
asks: [],
|
|
4068
|
+
...common
|
|
4069
|
+
};
|
|
4070
|
+
}
|
|
4071
|
+
const state = room.status === "member" ? "on" : room.status;
|
|
4072
|
+
return {
|
|
4073
|
+
state,
|
|
4074
|
+
where: "relay",
|
|
4075
|
+
...room.relay ? { via: await this.relayName(room.relay) } : {},
|
|
4076
|
+
owner: room.owner,
|
|
4077
|
+
ownerName: room.ownerName,
|
|
4078
|
+
connected: room.connected,
|
|
4079
|
+
devices: state === "on" ? await this.devices(room) : [],
|
|
4080
|
+
asks: room.owner ? (await this.options.rooms.listRequests().catch(() => [])).filter((request) => request.room === room.id && !request.guest).map(({ ask, name, at }) => ({ ask, name, at })) : [],
|
|
4081
|
+
...common
|
|
4082
|
+
};
|
|
3775
4083
|
}
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
4084
|
+
async enable() {
|
|
4085
|
+
const target = await this.target();
|
|
4086
|
+
if (target.type === "folder" && target.path || target.type === "store" && target.id) {
|
|
4087
|
+
const before = await this.room();
|
|
4088
|
+
if (before) {
|
|
4089
|
+
await this.options.rooms.leave(before.id);
|
|
4090
|
+
}
|
|
4091
|
+
const current = await this.folderRecord();
|
|
4092
|
+
const same = !!current && (target.type === "store" ? current.service === target.id : !current.service && RelayServiceUtil.expand(current.path) === RelayServiceUtil.expand(target.path ?? ""));
|
|
4093
|
+
if (!same) {
|
|
4094
|
+
const record = {
|
|
4095
|
+
id: FolderSyncUtil.randomId(),
|
|
4096
|
+
key: FolderSyncUtil.randomKey(),
|
|
4097
|
+
path: target.type === "folder" ? target.path ?? "" : "",
|
|
4098
|
+
...target.type === "store" ? { service: target.id, type: target.store } : {},
|
|
4099
|
+
device: FolderSyncUtil.randomId(),
|
|
4100
|
+
at: Date.now()
|
|
4101
|
+
};
|
|
4102
|
+
const problem = target.type === "folder" ? RelayServiceUtil.checkFolder(record.path) : undefined;
|
|
4103
|
+
if (problem) {
|
|
4104
|
+
throw new Error(problem);
|
|
4105
|
+
}
|
|
4106
|
+
const opened = await this.openSpace(record);
|
|
4107
|
+
if (!opened.space) {
|
|
4108
|
+
throw new Error(opened.problem);
|
|
3786
4109
|
}
|
|
4110
|
+
await opened.space.create();
|
|
4111
|
+
await this.saveFolder(record);
|
|
3787
4112
|
}
|
|
4113
|
+
await this.publish();
|
|
4114
|
+
this.schedule(0);
|
|
4115
|
+
return this.status();
|
|
3788
4116
|
}
|
|
3789
|
-
|
|
3790
|
-
|
|
4117
|
+
const room = await this.room();
|
|
4118
|
+
if (room?.status !== "member") {
|
|
4119
|
+
if (room) {
|
|
4120
|
+
await this.options.rooms.leave(room.id);
|
|
4121
|
+
}
|
|
4122
|
+
await this.options.rooms.createRoom({ kind: SYNC_KIND, title: SyncServerTexts.title(), view: SYNC_VIEW, unlisted: true, use: "sync" });
|
|
4123
|
+
}
|
|
4124
|
+
this.schedule(0);
|
|
4125
|
+
return this.status();
|
|
3791
4126
|
}
|
|
3792
|
-
async
|
|
3793
|
-
const
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
if (status.state === "on" && this.state !== "on") {
|
|
3799
|
-
this.schedule(0);
|
|
4127
|
+
async invite(renew = false) {
|
|
4128
|
+
const folder = await this.folderRecord();
|
|
4129
|
+
if (folder?.service) {
|
|
4130
|
+
const config = await this.options.relays?.storeConfig(folder.service);
|
|
4131
|
+
if (!config) {
|
|
4132
|
+
throw new Error(SyncServerTexts.storeUnavailable(folder.type ?? ""));
|
|
3800
4133
|
}
|
|
3801
|
-
this.
|
|
3802
|
-
|
|
3803
|
-
|
|
4134
|
+
return { link: FolderSyncUtil.storeLink(folder, config, this.device), expiresAt: 0 };
|
|
4135
|
+
}
|
|
4136
|
+
if (folder) {
|
|
4137
|
+
return { link: FolderSyncUtil.link(folder, this.device), expiresAt: 0 };
|
|
4138
|
+
}
|
|
4139
|
+
const room = await this.room();
|
|
4140
|
+
if (room?.status !== "member") {
|
|
4141
|
+
throw new Error(SyncServerTexts.notOn());
|
|
4142
|
+
}
|
|
4143
|
+
if (!room.owner) {
|
|
4144
|
+
throw new Error(SyncServerTexts.notOwner(room.ownerName));
|
|
4145
|
+
}
|
|
4146
|
+
return this.options.rooms.invite(room.id, { renew });
|
|
4147
|
+
}
|
|
4148
|
+
async join(link) {
|
|
4149
|
+
const room = await this.room();
|
|
4150
|
+
if (room?.status === "member" || await this.folderRecord()) {
|
|
4151
|
+
throw new Error(SyncServerTexts.alreadyOn());
|
|
4152
|
+
}
|
|
4153
|
+
if (FolderSyncUtil.is(link)) {
|
|
4154
|
+
return this.joinFolder(link);
|
|
4155
|
+
}
|
|
4156
|
+
if (FolderSyncUtil.isStore(link)) {
|
|
4157
|
+
return this.joinStore(link);
|
|
4158
|
+
}
|
|
4159
|
+
if (room) {
|
|
4160
|
+
await this.options.rooms.leave(room.id);
|
|
4161
|
+
}
|
|
4162
|
+
const joined = await this.options.rooms.join(link);
|
|
4163
|
+
await this.options.storage.set(SyncKeys.JOINING, joined.id);
|
|
4164
|
+
await this.publish();
|
|
4165
|
+
return this.status();
|
|
4166
|
+
}
|
|
4167
|
+
async leave() {
|
|
4168
|
+
const folder = await this.folderRecord();
|
|
4169
|
+
if (folder) {
|
|
4170
|
+
this.space?.stop();
|
|
4171
|
+
this.space = undefined;
|
|
4172
|
+
await rm4(this.folderFile, { force: true });
|
|
4173
|
+
}
|
|
4174
|
+
const room = await this.room();
|
|
4175
|
+
if (room) {
|
|
4176
|
+
await this.options.rooms.leave(room.id);
|
|
4177
|
+
}
|
|
4178
|
+
await this.options.storage.set(SyncKeys.JOINING, null);
|
|
4179
|
+
await this.saveBase({ room: "", items: {} });
|
|
4180
|
+
await this.publish();
|
|
4181
|
+
return this.status();
|
|
4182
|
+
}
|
|
4183
|
+
async answer(ask, accept) {
|
|
4184
|
+
const room = await this.room();
|
|
4185
|
+
if (room?.owner) {
|
|
4186
|
+
await this.options.rooms.answer(room.id, ask, accept);
|
|
4187
|
+
}
|
|
4188
|
+
await this.publish();
|
|
4189
|
+
return this.status();
|
|
4190
|
+
}
|
|
4191
|
+
async removeDevice(member) {
|
|
4192
|
+
const room = await this.room();
|
|
4193
|
+
if (room?.owner) {
|
|
4194
|
+
await this.options.rooms.removeMember(room.id, member);
|
|
4195
|
+
await this.options.rooms.setState(room.id, SyncStateKeys.device(member), null).catch(() => {
|
|
3804
4196
|
return;
|
|
3805
4197
|
});
|
|
3806
4198
|
}
|
|
4199
|
+
return this.status();
|
|
3807
4200
|
}
|
|
3808
|
-
async
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
4201
|
+
async setResources(change) {
|
|
4202
|
+
const resources = { ...await this.resources() };
|
|
4203
|
+
for (const resource of SYNC_RESOURCES) {
|
|
4204
|
+
if (typeof change?.[resource] === "boolean") {
|
|
4205
|
+
resources[resource] = change[resource];
|
|
4206
|
+
}
|
|
3814
4207
|
}
|
|
4208
|
+
await this.options.storage.set(SyncKeys.RESOURCES, resources);
|
|
4209
|
+
this.schedule(0);
|
|
4210
|
+
return this.status();
|
|
3815
4211
|
}
|
|
3816
|
-
async
|
|
3817
|
-
|
|
3818
|
-
await
|
|
3819
|
-
|
|
4212
|
+
async syncNow() {
|
|
4213
|
+
clearTimeout(this.timer);
|
|
4214
|
+
await this.run();
|
|
4215
|
+
return this.status();
|
|
3820
4216
|
}
|
|
3821
4217
|
}
|
|
3822
4218
|
|
|
@@ -3840,7 +4236,7 @@ function hostSide(host) {
|
|
|
3840
4236
|
if (!pkg.enabled) {
|
|
3841
4237
|
continue;
|
|
3842
4238
|
}
|
|
3843
|
-
const manifest = await
|
|
4239
|
+
const manifest = await readFile7(join9(pkg.root, "package.json"), "utf8").then((text) => JSON.parse(text), () => {
|
|
3844
4240
|
return;
|
|
3845
4241
|
});
|
|
3846
4242
|
keys.push(...SyncDeclarations.keys(manifest).map((key) => ({ name: pkg.name, key })));
|
|
@@ -3856,6 +4252,7 @@ function activate(host) {
|
|
|
3856
4252
|
agentDir: host.agentDir,
|
|
3857
4253
|
place: new AgentDirPlace(host.agentDir, side),
|
|
3858
4254
|
side,
|
|
4255
|
+
...typeof host.relocateDirectory === "function" ? { relocate: (from, to) => host.relocateDirectory(from, to) } : {},
|
|
3859
4256
|
publish: (status) => void host.setExtensionData(SYNC_PACKAGE, MIGRATE_STATUS_KEY, status).catch(() => {
|
|
3860
4257
|
return;
|
|
3861
4258
|
})
|
|
@@ -3895,6 +4292,8 @@ function activate(host) {
|
|
|
3895
4292
|
migrateExport: (categories, password, dir) => migrate.exportFile(categories, typeof password === "string" ? password : undefined, typeof dir === "string" && dir ? dir : undefined),
|
|
3896
4293
|
migrateImport: (path, password) => migrate.importFile(String(path ?? ""), typeof password === "string" ? password : undefined),
|
|
3897
4294
|
migrateBackups: () => migrate.listBackups(),
|
|
4295
|
+
migrateMissing: () => migrate.missing(),
|
|
4296
|
+
migrateRelocate: (from, to) => migrate.relocate(String(from ?? ""), String(to ?? "")),
|
|
3898
4297
|
dispose: () => {
|
|
3899
4298
|
stopData();
|
|
3900
4299
|
service.dispose();
|