@celljs/ta 4.16.0 → 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 +2224 -203
- package/dist/gateway.mjs +2011 -528
- package/dist/pi/CHANGELOG.md +12 -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 +278 -105
- package/dist/pi/packages/ta-agents/host/index.mjs +662 -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.js +2 -1
- 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 +688 -148
- 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 +2035 -1534
- 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 +739 -234
- 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/extension/index.mjs +27 -8
- package/dist/pi/packages/ta-glance/lib/card.js +67 -27
- 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.js +3 -3
- package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +9 -2
- package/dist/pi/packages/ta-glance/lib/glance-spec.js +33 -5
- 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/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 +17 -3
- package/dist/pi/packages/ta-glance/package.json +2 -1
- package/dist/pi/packages/ta-glance/web/index.js +180 -30
- 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 +702 -191
- package/dist/pi/packages/ta-moments/host/index.mjs +1361 -837
- 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 +648 -144
- 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 +1464 -765
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-FSEuUCgT.js → abnfDiagram-S7VZAUFO-w8qXXVn-.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-Do_DyWCg.js → architecture-WOLXFQ4H-B-FHaYwY.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-D-N2qDs4.js → architectureDiagram-YGSQEFNW-DTnoGaaX.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-Ds6DzHNZ.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-KlrZxPbE.js → browser-DXexCqIh.js} +2 -2
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-D5ZdqxrP.js → c4Diagram-KJ2TOQU5-CJJqDqyQ.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-CWOwhB3b.js → chunk-6MUBBAK2-DbvUMdNm.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-Dr6p2RGg.js → chunk-AXFCVDMN-D4hlZGtj.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-DUCV_pmW.js → chunk-BG4553SI-VNa9Q9On.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-Yxd3jIXM.js → chunk-DQASFODM-BtlEbc_V.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-C24I15MF.js → chunk-HFQBQIA3-CAYSo4CJ.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-Dxk-aejD.js → chunk-KQLB2F66-CyKdg6hW.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-DPyr7gb8.js → chunk-KS47KZWR-BMogCB2r.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-D_mEFJGR.js → chunk-LEVMRMFU-Y9wr-8qB.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-DfMFxQib.js → chunk-M57EVK23-DL3IAQKR.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-O9W83Laa.js → chunk-OY52VR5R-CJBFHdg6.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-IdikGcw1.js → chunk-QB3YPZ4I-CyuWKZZv.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-DLpaFCvz.js → chunk-R3KSYZAL-DxvGhfpm.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-Lx-CZ4Ql.js → chunk-STOXU5M4-Cpdl6bfz.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-DCnr5NsA.js → chunk-TU62E6Q5-CIxOg6QF.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-Ct7aUJFY.js → chunk-X4PVCEUW-DCFSCRBh.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-CQhxfoYw.js → chunk-XXDRQBXY-B2R8Cxf7.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-DPSu5qYq.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-CFimsFsN.js → cose-bilkent-JH36ORCC-CXSLFyCH.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-BIcbDns7.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-CiAWhkVp.js → cynefinDiagram-L36ESFBY-DTv0Kn1r.js} +1 -1
- package/dist/public/assets/{d3-selection-C8RIDfkO.js → d3-selection-g4Hl3_NH.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-l1nRD1Fx.js → dagre-SPEB5RXH-BujVqk5R.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-ipqtnhoX.js → diagram-3B7GL73J-Ds-VnLzP.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-VpIcHRUP.js → diagram-DNEMPZML-BBoIIK-a.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-8VdVmcS6.js → diagram-L3MUGCDN-Glgd5N_n.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-Bej-aiF0.js → diagram-LA4NIPWU-B4EODdUU.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-D8gW4bVQ.js → diagram-MHCOC4E2-pzDDXO2J.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-BMevAJ1M.js → diagram-XPFHEONP-l--gwSuK.js} +1 -1
- package/dist/public/assets/{dist-DBKJcjvW.js → dist-C0u3lAFR.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-C3HDTOzn.js → ebnfDiagram-UZSYDL2S-BVfPeaVX.js} +1 -1
- package/dist/public/assets/{editor.api-BMWdjwhK.js → editor.api-BMcewI3C.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-XOOPrVin.js → elk-XV6XMXQE-BFJtUnG9.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-Cr-vwx1l.js → erDiagram-EYBAPDEH-BWxMtfIc.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-DbPhpfxn.js → eventmodeling-K75KTNOO-YwYgBgCX.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-Dah4--NW.js +1 -0
- package/dist/public/assets/{freemarker2-6h_1-8qB.js → freemarker2-B8HquI7K.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-C7kNPXx3.js → ganttDiagram-23REXITY-CBqv7wbi.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BwDfrSZS.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW-CVnEJEZr.js → gitGraphDiagram-STJD7YCW-BLSf23f_.js} +1 -1
- package/dist/public/assets/{handlebars-F4lp3oLr.js → handlebars-P1qmNq4N.js} +1 -1
- package/dist/public/assets/{html-Dj6f8B_g.js → html-Ceswbytr.js} +1 -1
- package/dist/public/assets/{index-DnNrrk68.js → index-10isUUN4.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-Ch8aMV1p.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-DcttQWdp.js → infoDiagram-KBXO4MBG-LvOtgUlm.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-BSUYTZf6.js → ishikawaDiagram-M35NCXHK-CwUZOvcm.js} +1 -1
- package/dist/public/assets/{javascript-b_BkOE5Y.js → javascript-B3FXC8qR.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-BCfd5-6n.js → journeyDiagram-OPLOXDXO-5j1KtwTt.js} +1 -1
- package/dist/public/assets/{jsonMode-Cq5QJbVZ.js → jsonMode-CrCyxNQI.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-B3nenaw_.js → kanban-definition-BZKZHSQY-BKAB5id1.js} +1 -1
- package/dist/public/assets/{liquid-CGuZI_Aa.js → liquid-CXZRIgp2.js} +1 -1
- package/dist/public/assets/{mdx-Dt9yTqnf.js → mdx-Dm3uNczM.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-CquzROwT.js → mermaid-parser.core-C755A-rX.js} +3 -3
- package/dist/public/assets/{mermaid.core-Bx-e_Scq.js → mermaid.core-CQrYmFAR.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-DyeewbnH.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-nvIdDTWu.js → monaco-BS7JBNW4.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-LqMrrc60.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-B884_KoR.js → pegDiagram-FD4XPPHP-BzbBCWht.js} +1 -1
- package/dist/public/assets/pie-XZMESJXO-BWzABXQU.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-I40wRwyy.js → pieDiagram-J4AKIIQI-Bf_LDukL.js} +1 -1
- package/dist/public/assets/{python-Djw4wvG9.js → python-jgOUhB-F.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2-DyNOImfk.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-3G0zWzgf.js → railroad-abnf-LNEFI6M7-DQGYaRbc.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-B5XRDRWS.js → railroad-ebnf-DWYD2UWJ-D6Ljza0U.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-rcIioIyH.js → railroad-peg-JR7BVNR7-Du9hL1Gf.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-CDM2ahQM.js → railroadDiagram-MRQ6NCDL-CS_JnlGN.js} +1 -1
- package/dist/public/assets/{razor-CStezNUn.js → razor-BWj90God.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-hbb6WtfM.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-DLV3Aoae.js → sankeyDiagram-WGJFYUXA-aK7jRBVK.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-BWxOV5U9.js → sequenceDiagram-5NDRBG5M-BxcIyc38.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-C-TaUPaQ.js → stateDiagram-v2-FJ4FJNEA-Ctletlj4.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-CJY0BFmc.js → swimlanes-UMQ2AFYF-DaD55xd2.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CytCT4x3.js +8 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-CUfQb8Gv.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-B7kmi8MF.js → typescript-RgyfxmPQ.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-BKTVAp-G.js → usecaseDiagram-AFA6YXN4-CAVEBKQS.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-CN1RxNTS.js → vennDiagram-NNMJR3RB-DHyJxlHv.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-DSfdKACG.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-JJ6qcpu1.js → wardleyDiagram-S7YFUSEH-C-FCHxR7.js} +1 -1
- package/dist/public/assets/{xml-DVamlHEU.js → xml-DiA1T3iN.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-BNakYgUZ.js → xychartDiagram-GGNKY7IX-BlnHU6Gz.js} +1 -1
- package/dist/public/assets/{yaml-BihGeFrM.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 +10558 -7361
- package/package.json +45 -39
- package/dist/public/assets/cynefin-EF2NZ3EQ-Dcc0sCHf.js +0 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-CDXqnHAQ.js +0 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-KPsoB6Z1.js +0 -1
- package/dist/public/assets/info-OHQRW6UA-CtM6s0SQ.js +0 -1
- package/dist/public/assets/module-C-ofp7U4.js +0 -1
- package/dist/public/assets/module-DDH-aU6z.js +0 -1
- 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-dnDlIzeV.js +0 -2616
- package/dist/public/assets/module-qoBVcE5h.js +0 -1
- package/dist/public/assets/packet-JDAUHWVQ-XKjiwdar.js +0 -1
- package/dist/public/assets/pie-XZMESJXO-MuCMavHL.js +0 -1
- package/dist/public/assets/radar-ABXABTNO-Cq12GHJS.js +0 -1
- package/dist/public/assets/railroad-I3PHUGI6-CfeMswZU.js +0 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-DdFDl6aK.js +0 -8
- package/dist/public/assets/treeView-D4JQ5SDB-BQ4uUy4s.js +0 -1
- package/dist/public/assets/treemap-SAJKECNS-BFTTkjF9.js +0 -1
- package/dist/public/assets/wardley-7MLQ67FV-BbyzsA8S.js +0 -1
package/dist/gateway.mjs
CHANGED
|
@@ -4,11 +4,11 @@ import { join as join10 } from "node:path";
|
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
|
|
6
6
|
// ../../ta-packages/ta-gateway/esm/node/gateway-server.js
|
|
7
|
-
import { createReadStream, existsSync as existsSync4, mkdirSync as mkdirSync5, statSync } from "node:fs";
|
|
8
|
-
import { createServer as createServer2, request as
|
|
9
|
-
import { request as
|
|
7
|
+
import { accessSync, constants as constants2, createReadStream, existsSync as existsSync4, mkdirSync as mkdirSync5, statSync } from "node:fs";
|
|
8
|
+
import { createServer as createServer2, request as httpRequest3 } from "node:http";
|
|
9
|
+
import { request as httpsRequest2 } from "node:https";
|
|
10
10
|
import { extname, join as join9, normalize, sep } from "node:path";
|
|
11
|
-
import { pipeline } from "node:stream";
|
|
11
|
+
import { pipeline as pipeline2 } from "node:stream";
|
|
12
12
|
|
|
13
13
|
// ../../packages/rpc/esm/node/websocket/websocket-connection.js
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
@@ -764,10 +764,145 @@ import { createHash as createHash3, randomBytes as randomBytes2 } from "node:cry
|
|
|
764
764
|
// ../../ta-packages/ta-protocol/esm/common/access-protocol.js
|
|
765
765
|
var TaAccessServer = Symbol("TaAccessServer");
|
|
766
766
|
var TA_SIGN_IN_PATH = "/sign-in";
|
|
767
|
-
// ../../ta-packages/ta-protocol/esm/common/
|
|
768
|
-
var
|
|
769
|
-
|
|
770
|
-
var
|
|
767
|
+
// ../../ta-packages/ta-protocol/esm/common/ta-extension-host.js
|
|
768
|
+
var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
|
|
769
|
+
var TA_HOST_EVENT = "ta:host";
|
|
770
|
+
var TaHostUtil;
|
|
771
|
+
(function(TaHostUtil2) {
|
|
772
|
+
TaHostUtil2.WAIT_MS = 1000;
|
|
773
|
+
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
774
|
+
return new Promise((resolve) => {
|
|
775
|
+
let heard = false;
|
|
776
|
+
let answered = false;
|
|
777
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
778
|
+
const request = {
|
|
779
|
+
name,
|
|
780
|
+
heard: () => {
|
|
781
|
+
heard = true;
|
|
782
|
+
},
|
|
783
|
+
resolve: (answer) => {
|
|
784
|
+
answered = true;
|
|
785
|
+
clearTimeout(timer);
|
|
786
|
+
resolve(answer);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
events.emit(TA_HOST_EVENT, request);
|
|
790
|
+
if (!heard && !answered) {
|
|
791
|
+
clearTimeout(timer);
|
|
792
|
+
resolve(undefined);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
TaHostUtil2.reach = reach;
|
|
797
|
+
function marked(systemPrompt, mark) {
|
|
798
|
+
return role(systemPrompt).includes(mark);
|
|
799
|
+
}
|
|
800
|
+
TaHostUtil2.marked = marked;
|
|
801
|
+
function role(systemPrompt) {
|
|
802
|
+
if (!systemPrompt) {
|
|
803
|
+
return "";
|
|
804
|
+
}
|
|
805
|
+
const open = `<addendum>
|
|
806
|
+
`;
|
|
807
|
+
const start = systemPrompt.indexOf(open);
|
|
808
|
+
const context = systemPrompt.indexOf(`<project_context>
|
|
809
|
+
`);
|
|
810
|
+
if (start < 0 || context >= 0 && context < start) {
|
|
811
|
+
return "";
|
|
812
|
+
}
|
|
813
|
+
const end = systemPrompt.indexOf(`
|
|
814
|
+
</addendum>`, start);
|
|
815
|
+
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
816
|
+
}
|
|
817
|
+
TaHostUtil2.role = role;
|
|
818
|
+
})(TaHostUtil || (TaHostUtil = {}));
|
|
819
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
820
|
+
var TaAskUtil;
|
|
821
|
+
(function(TaAskUtil2) {
|
|
822
|
+
const LENGTH = 120;
|
|
823
|
+
function entry(question) {
|
|
824
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
825
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
826
|
+
}
|
|
827
|
+
TaAskUtil2.entry = entry;
|
|
828
|
+
function asking(entries) {
|
|
829
|
+
var _a;
|
|
830
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
831
|
+
const entry2 = entries[i];
|
|
832
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
836
|
+
return read(entry2);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
TaAskUtil2.asking = asking;
|
|
842
|
+
function next(asked, entry2) {
|
|
843
|
+
var _a;
|
|
844
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
848
|
+
}
|
|
849
|
+
TaAskUtil2.next = next;
|
|
850
|
+
function read(found) {
|
|
851
|
+
var _a;
|
|
852
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
853
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
857
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
858
|
+
}
|
|
859
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
860
|
+
|
|
861
|
+
// ../../ta-packages/ta-protocol/esm/common/delegate-protocol.js
|
|
862
|
+
var TaDelegateUtil;
|
|
863
|
+
(function(TaDelegateUtil2) {
|
|
864
|
+
TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
|
|
865
|
+
TaDelegateUtil2.DEFAULT = "balanced";
|
|
866
|
+
TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
|
|
867
|
+
TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
|
|
868
|
+
const LIMITS = {
|
|
869
|
+
less: { noChanges: false },
|
|
870
|
+
balanced: { noChanges: true, steps: 6 },
|
|
871
|
+
more: { noChanges: true, steps: 2 }
|
|
872
|
+
};
|
|
873
|
+
function parse(value) {
|
|
874
|
+
return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
|
|
875
|
+
}
|
|
876
|
+
TaDelegateUtil2.parse = parse;
|
|
877
|
+
function mark(level) {
|
|
878
|
+
return `(delegate=${level})`;
|
|
879
|
+
}
|
|
880
|
+
TaDelegateUtil2.mark = mark;
|
|
881
|
+
function levelOf(systemPrompt) {
|
|
882
|
+
const role = TaHostUtil.role(systemPrompt);
|
|
883
|
+
return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
|
|
884
|
+
}
|
|
885
|
+
TaDelegateUtil2.levelOf = levelOf;
|
|
886
|
+
function limits(level) {
|
|
887
|
+
return LIMITS[level];
|
|
888
|
+
}
|
|
889
|
+
TaDelegateUtil2.limits = limits;
|
|
890
|
+
function refusal(level, tool, steps) {
|
|
891
|
+
if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const limit = LIMITS[level];
|
|
895
|
+
if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
|
|
896
|
+
return "You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.";
|
|
897
|
+
}
|
|
898
|
+
if (limit.steps !== undefined && steps >= limit.steps) {
|
|
899
|
+
return "You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.";
|
|
900
|
+
}
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
TaDelegateUtil2.refusal = refusal;
|
|
904
|
+
})(TaDelegateUtil || (TaDelegateUtil = {}));
|
|
905
|
+
|
|
771
906
|
// ../../ta-packages/ta-protocol/esm/common/language.js
|
|
772
907
|
var TaLanguageUtil;
|
|
773
908
|
(function(TaLanguageUtil2) {
|
|
@@ -806,6 +941,348 @@ var TaLanguageUtil;
|
|
|
806
941
|
}
|
|
807
942
|
TaLanguageUtil2.list = list;
|
|
808
943
|
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
944
|
+
|
|
945
|
+
// ../../ta-packages/ta-protocol/esm/common/app-protocol.js
|
|
946
|
+
var FONT_SIZES = ["small", "standard", "large", "xlarge"];
|
|
947
|
+
var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
|
|
948
|
+
var SYSTEM = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
|
|
949
|
+
var FONT_SHOWN = {
|
|
950
|
+
small: words("small", "小", "小", "小"),
|
|
951
|
+
standard: words("standard", "标准", "標準", "標準"),
|
|
952
|
+
large: words("large", "大", "大", "大"),
|
|
953
|
+
xlarge: words("extra large", "特大", "特大", "特大")
|
|
954
|
+
};
|
|
955
|
+
var TA_WEB_SETTINGS = [
|
|
956
|
+
{
|
|
957
|
+
key: "theme",
|
|
958
|
+
type: "enum",
|
|
959
|
+
values: ["system", "light", "dark"],
|
|
960
|
+
default: "system",
|
|
961
|
+
what: "Light or dark look; system follows the device.",
|
|
962
|
+
title: words("Theme", "外观", "外觀", "外観"),
|
|
963
|
+
shown: { system: SYSTEM, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
key: "language",
|
|
967
|
+
type: "enum",
|
|
968
|
+
values: ["system", ...TaLanguageUtil.ALL],
|
|
969
|
+
default: "system",
|
|
970
|
+
what: "The language of Ta's pages and of what Ta says; system follows the device.",
|
|
971
|
+
title: words("Language", "语言", "語言", "言語"),
|
|
972
|
+
shown: {
|
|
973
|
+
system: SYSTEM,
|
|
974
|
+
...Object.fromEntries(TaLanguageUtil.ALL.map((language) => [
|
|
975
|
+
language,
|
|
976
|
+
words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language])
|
|
977
|
+
]))
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
key: "fontSize",
|
|
982
|
+
type: "enum",
|
|
983
|
+
values: FONT_SIZES,
|
|
984
|
+
default: "standard",
|
|
985
|
+
what: "The size of the text of the whole page.",
|
|
986
|
+
title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
|
|
987
|
+
shown: FONT_SHOWN
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
key: "chatFontSize",
|
|
991
|
+
type: "enum",
|
|
992
|
+
values: FONT_SIZES,
|
|
993
|
+
default: "standard",
|
|
994
|
+
what: "The size of the text of conversations, on top of fontSize.",
|
|
995
|
+
title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
|
|
996
|
+
shown: FONT_SHOWN
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
key: "speak",
|
|
1000
|
+
type: "boolean",
|
|
1001
|
+
default: false,
|
|
1002
|
+
what: "Read every reply aloud.",
|
|
1003
|
+
title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
key: "speakTalk",
|
|
1007
|
+
type: "boolean",
|
|
1008
|
+
default: false,
|
|
1009
|
+
what: "Read the reply aloud when the user spoke to the double by voice.",
|
|
1010
|
+
title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
key: "callCaptions",
|
|
1014
|
+
type: "boolean",
|
|
1015
|
+
default: false,
|
|
1016
|
+
what: "Show captions in a call: what the user says and what Ta reads.",
|
|
1017
|
+
title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
key: "voice",
|
|
1021
|
+
type: "string",
|
|
1022
|
+
default: "",
|
|
1023
|
+
what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
|
|
1024
|
+
title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
key: "confirmTasks",
|
|
1028
|
+
type: "boolean",
|
|
1029
|
+
default: false,
|
|
1030
|
+
what: "The double asks before it hands out work.",
|
|
1031
|
+
title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
key: "maxTasks",
|
|
1035
|
+
type: "number",
|
|
1036
|
+
values: [0, 2, 4, 8],
|
|
1037
|
+
default: 0,
|
|
1038
|
+
what: "How many of the double's tasks run at once; 0 for as many as it starts.",
|
|
1039
|
+
title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
key: "delegate",
|
|
1043
|
+
type: "enum",
|
|
1044
|
+
values: TaDelegateUtil.LEVELS,
|
|
1045
|
+
default: TaDelegateUtil.DEFAULT,
|
|
1046
|
+
what: "How much of the work the double hands out to tasks rather than doing it itself.",
|
|
1047
|
+
title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
|
|
1048
|
+
shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
key: "assistantModel",
|
|
1052
|
+
type: "model",
|
|
1053
|
+
default: "",
|
|
1054
|
+
what: "The model of the double, <provider>/<model id>; empty for the default model.",
|
|
1055
|
+
title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
key: "taskModel",
|
|
1059
|
+
type: "model",
|
|
1060
|
+
default: "",
|
|
1061
|
+
what: "The model of the tasks the double starts; empty for the default model.",
|
|
1062
|
+
title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
|
|
1063
|
+
},
|
|
1064
|
+
{ key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
|
|
1065
|
+
{
|
|
1066
|
+
key: "keepAliveMinutes",
|
|
1067
|
+
type: "number",
|
|
1068
|
+
values: [1, 5, 15, 30],
|
|
1069
|
+
default: 5,
|
|
1070
|
+
what: "How long an extension started on open keeps running once left, in minutes.",
|
|
1071
|
+
title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
key: "chatFoldDays",
|
|
1075
|
+
type: "number",
|
|
1076
|
+
values: [3, 7, 30, 0],
|
|
1077
|
+
default: 7,
|
|
1078
|
+
what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
|
|
1079
|
+
title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
key: "chatArchiveDays",
|
|
1083
|
+
type: "number",
|
|
1084
|
+
values: [30, 90, 365, 0],
|
|
1085
|
+
default: 30,
|
|
1086
|
+
what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
|
|
1087
|
+
title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
key: "recentShots",
|
|
1091
|
+
type: "boolean",
|
|
1092
|
+
default: true,
|
|
1093
|
+
what: "The screenshot just taken is offered above the message box, once.",
|
|
1094
|
+
title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
|
|
1095
|
+
}
|
|
1096
|
+
];
|
|
1097
|
+
var TaAppUtil;
|
|
1098
|
+
(function(TaAppUtil2) {
|
|
1099
|
+
function check(spec, value) {
|
|
1100
|
+
var _a, _b;
|
|
1101
|
+
switch (spec.type) {
|
|
1102
|
+
case "boolean":
|
|
1103
|
+
return typeof value === "boolean" ? undefined : "true or false";
|
|
1104
|
+
case "string":
|
|
1105
|
+
return typeof value === "string" ? undefined : "a string";
|
|
1106
|
+
case "model":
|
|
1107
|
+
return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
|
|
1108
|
+
default:
|
|
1109
|
+
return ((_a = spec.values) === null || _a === undefined ? undefined : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === undefined ? undefined : _b.map((one) => JSON.stringify(one)).join(", ")}`;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
TaAppUtil2.check = check;
|
|
1113
|
+
function shown(value, language, spec) {
|
|
1114
|
+
var _a;
|
|
1115
|
+
const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
|
|
1116
|
+
if (named) {
|
|
1117
|
+
return TaLanguageUtil.pick(language, named);
|
|
1118
|
+
}
|
|
1119
|
+
if (typeof value === "boolean") {
|
|
1120
|
+
return TaLanguageUtil.pick(language, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
|
|
1121
|
+
}
|
|
1122
|
+
if (value === "" || value === undefined || value === null) {
|
|
1123
|
+
return TaLanguageUtil.pick(language, words("default", "默认", "預設", "デフォルト"));
|
|
1124
|
+
}
|
|
1125
|
+
return String(value);
|
|
1126
|
+
}
|
|
1127
|
+
TaAppUtil2.shown = shown;
|
|
1128
|
+
})(TaAppUtil || (TaAppUtil = {}));
|
|
1129
|
+
// ../../ta-packages/ta-protocol/esm/common/auth-protocol.js
|
|
1130
|
+
var TaAuthServer = Symbol("TaAuthServer");
|
|
1131
|
+
// ../../ta-packages/ta-protocol/esm/common/deployment-protocol.js
|
|
1132
|
+
var TA_WELL_KNOWN_PATH = "/.well-known/ta";
|
|
1133
|
+
|
|
1134
|
+
class TaDeploymentError extends Error {
|
|
1135
|
+
}
|
|
1136
|
+
var TaDeploymentUtil;
|
|
1137
|
+
(function(TaDeploymentUtil2) {
|
|
1138
|
+
TaDeploymentUtil2.DISTRIBUTION_FILE = "distribution.json";
|
|
1139
|
+
function url(value) {
|
|
1140
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
try {
|
|
1144
|
+
const parsed = new URL(value.trim());
|
|
1145
|
+
if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
|
|
1149
|
+
} catch (_a) {
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
TaDeploymentUtil2.url = url;
|
|
1154
|
+
function name(value) {
|
|
1155
|
+
return typeof value === "string" && value.trim() ? value.trim().slice(0, 80) : undefined;
|
|
1156
|
+
}
|
|
1157
|
+
function describe(env, own, version) {
|
|
1158
|
+
var _a, _b;
|
|
1159
|
+
const gateway = (_a = url(own.gateway)) !== null && _a !== undefined ? _a : url(env.TA_GATEWAY_URL);
|
|
1160
|
+
const relay = (_b = url(own.relay)) !== null && _b !== undefined ? _b : url(env.TA_RELAY_URL);
|
|
1161
|
+
const called = name(env.TA_DEPLOYMENT_NAME);
|
|
1162
|
+
return { v: 1, ...called ? { name: called } : {}, ...gateway ? { gateway } : {}, ...relay ? { relay } : {}, ...version ? { version } : {} };
|
|
1163
|
+
}
|
|
1164
|
+
TaDeploymentUtil2.describe = describe;
|
|
1165
|
+
TaDeploymentUtil2.HEADERS = {
|
|
1166
|
+
"content-type": "application/json",
|
|
1167
|
+
"access-control-allow-origin": "*",
|
|
1168
|
+
"cache-control": "no-store"
|
|
1169
|
+
};
|
|
1170
|
+
function parse(value) {
|
|
1171
|
+
const given = value;
|
|
1172
|
+
if (!given || typeof given !== "object" || given.v !== 1) {
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
|
|
1176
|
+
const version = name(given.version);
|
|
1177
|
+
return version ? { ...deployment, version } : deployment;
|
|
1178
|
+
}
|
|
1179
|
+
TaDeploymentUtil2.parse = parse;
|
|
1180
|
+
async function discover(address, timeoutMs = 6000) {
|
|
1181
|
+
const base = url(address);
|
|
1182
|
+
if (!base) {
|
|
1183
|
+
throw new TaDeploymentError(`${address} is not an address of http or https.`);
|
|
1184
|
+
}
|
|
1185
|
+
const controller = new AbortController;
|
|
1186
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1187
|
+
try {
|
|
1188
|
+
const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: "follow" });
|
|
1189
|
+
if (!response.ok) {
|
|
1190
|
+
throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
|
|
1191
|
+
}
|
|
1192
|
+
const deployment = parse(await response.json().catch(() => {
|
|
1193
|
+
return;
|
|
1194
|
+
}));
|
|
1195
|
+
if (!deployment || !deployment.gateway && !deployment.relay) {
|
|
1196
|
+
throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
|
|
1197
|
+
}
|
|
1198
|
+
return deployment;
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
if ((error === null || error === undefined ? undefined : error.name) === "AbortError") {
|
|
1201
|
+
throw new TaDeploymentError(`${base} did not answer in time.`);
|
|
1202
|
+
}
|
|
1203
|
+
throw error;
|
|
1204
|
+
} finally {
|
|
1205
|
+
clearTimeout(timer);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
TaDeploymentUtil2.discover = discover;
|
|
1209
|
+
function distribution(value) {
|
|
1210
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1211
|
+
throw new TaDeploymentError(`${TaDeploymentUtil2.DISTRIBUTION_FILE} holds a JSON object.`);
|
|
1212
|
+
}
|
|
1213
|
+
const given = value;
|
|
1214
|
+
const result = {};
|
|
1215
|
+
if (given.name !== undefined) {
|
|
1216
|
+
result.name = name(given.name);
|
|
1217
|
+
}
|
|
1218
|
+
for (const key of ["relay", "gateway"]) {
|
|
1219
|
+
if (given[key] !== undefined) {
|
|
1220
|
+
const address = url(given[key]);
|
|
1221
|
+
if (!address) {
|
|
1222
|
+
throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
|
|
1223
|
+
}
|
|
1224
|
+
result[key] = address;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (given.updates !== undefined) {
|
|
1228
|
+
const updates = given.updates;
|
|
1229
|
+
const base = url(updates === null || updates === undefined ? undefined : updates.base);
|
|
1230
|
+
if (!base && (updates === null || updates === undefined ? undefined : updates.base) !== undefined) {
|
|
1231
|
+
throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
|
|
1232
|
+
}
|
|
1233
|
+
const key = typeof (updates === null || updates === undefined ? undefined : updates.key) === "string" && updates.key.includes("PUBLIC KEY") ? updates.key : undefined;
|
|
1234
|
+
if ((updates === null || updates === undefined ? undefined : updates.key) !== undefined && !key) {
|
|
1235
|
+
throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a public key in PEM.`);
|
|
1236
|
+
}
|
|
1237
|
+
result.updates = { ...base ? { base } : {}, ...key ? { key } : {} };
|
|
1238
|
+
}
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
TaDeploymentUtil2.distribution = distribution;
|
|
1242
|
+
function apply(distribution2, env) {
|
|
1243
|
+
const defaults = { TA_DEPLOYMENT_NAME: distribution2.name, TA_RELAY_URL: distribution2.relay, TA_GATEWAY_URL: distribution2.gateway };
|
|
1244
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
1245
|
+
if (value && !env[key]) {
|
|
1246
|
+
env[key] = value;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
TaDeploymentUtil2.apply = apply;
|
|
1251
|
+
})(TaDeploymentUtil || (TaDeploymentUtil = {}));
|
|
1252
|
+
// ../../ta-packages/ta-protocol/esm/common/error-protocol.js
|
|
1253
|
+
var TaErrorCode = {
|
|
1254
|
+
SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
|
|
1255
|
+
SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
|
|
1256
|
+
TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
|
|
1257
|
+
MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
|
|
1258
|
+
MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
|
|
1259
|
+
INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
|
|
1260
|
+
COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
|
|
1261
|
+
NOTHING_TO_COMPACT: "CELL_TA_NOTHING_TO_COMPACT",
|
|
1262
|
+
ALREADY_COMPACTED: "CELL_TA_ALREADY_COMPACTED",
|
|
1263
|
+
SESSION_BUSY: "CELL_TA_SESSION_BUSY",
|
|
1264
|
+
CANCELLED: "CELL_TA_CANCELLED",
|
|
1265
|
+
NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
|
|
1266
|
+
ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
|
|
1267
|
+
RATE_LIMITED: "CELL_TA_RATE_LIMITED",
|
|
1268
|
+
FORBIDDEN: "CELL_TA_FORBIDDEN",
|
|
1269
|
+
LIMIT: "CELL_TA_LIMIT",
|
|
1270
|
+
CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
|
|
1271
|
+
};
|
|
1272
|
+
var TaErrorUtil;
|
|
1273
|
+
(function(TaErrorUtil2) {
|
|
1274
|
+
function code(error) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
var _b;
|
|
1277
|
+
const failure = error;
|
|
1278
|
+
const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
|
|
1279
|
+
return typeof code2 === "string" ? code2 : undefined;
|
|
1280
|
+
}
|
|
1281
|
+
TaErrorUtil2.code = code;
|
|
1282
|
+
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
1283
|
+
var TA_RPC_ERROR_CODE = -32050;
|
|
1284
|
+
// ../../ta-packages/ta-protocol/esm/common/gateway-protocol.js
|
|
1285
|
+
var TaGatewayServer = Symbol("TaGatewayServer");
|
|
809
1286
|
// ../../ta-packages/ta-protocol/esm/common/location.js
|
|
810
1287
|
var TaLocation;
|
|
811
1288
|
(function(TaLocation2) {
|
|
@@ -867,19 +1344,19 @@ var TaLocation;
|
|
|
867
1344
|
TaLocation2.isHost = isHost;
|
|
868
1345
|
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
869
1346
|
function readHost(input) {
|
|
870
|
-
const
|
|
871
|
-
if (
|
|
872
|
-
|
|
1347
|
+
const words2 = input.trim().split(/\s+/).filter(Boolean);
|
|
1348
|
+
if (words2[0] === "ssh") {
|
|
1349
|
+
words2.shift();
|
|
873
1350
|
}
|
|
874
1351
|
let destination;
|
|
875
1352
|
let port;
|
|
876
1353
|
let user;
|
|
877
1354
|
const options = [];
|
|
878
|
-
for (let i = 0;i <
|
|
879
|
-
const word =
|
|
1355
|
+
for (let i = 0;i < words2.length; i++) {
|
|
1356
|
+
const word = words2[i];
|
|
880
1357
|
const glued = /^-([pl])(.+)$/.exec(word);
|
|
881
1358
|
if (word === "-p" || word === "-l" || glued) {
|
|
882
|
-
const value = glued ? glued[2] :
|
|
1359
|
+
const value = glued ? glued[2] : words2[++i];
|
|
883
1360
|
if (value === undefined) {
|
|
884
1361
|
return { error: "invalid" };
|
|
885
1362
|
}
|
|
@@ -889,7 +1366,7 @@ var TaLocation;
|
|
|
889
1366
|
user = value;
|
|
890
1367
|
}
|
|
891
1368
|
} else if (word === "-o" || word.startsWith("-o")) {
|
|
892
|
-
const value = word === "-o" ?
|
|
1369
|
+
const value = word === "-o" ? words2[++i] : word.slice(2);
|
|
893
1370
|
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
894
1371
|
if (!option) {
|
|
895
1372
|
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
@@ -899,7 +1376,7 @@ var TaLocation;
|
|
|
899
1376
|
user = option[2];
|
|
900
1377
|
}
|
|
901
1378
|
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
902
|
-
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) &&
|
|
1379
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
|
|
903
1380
|
} else if (destination === undefined) {
|
|
904
1381
|
destination = word;
|
|
905
1382
|
} else {
|
|
@@ -1005,98 +1482,40 @@ var TaLocation;
|
|
|
1005
1482
|
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
1006
1483
|
}
|
|
1007
1484
|
})(TaLocation || (TaLocation = {}));
|
|
1008
|
-
// ../../ta-packages/ta-protocol/esm/common/
|
|
1009
|
-
var
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
function
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1485
|
+
// ../../ta-packages/ta-protocol/esm/common/message-protocol.js
|
|
1486
|
+
var TaMessageContext;
|
|
1487
|
+
(function(TaMessageContext2) {
|
|
1488
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
1489
|
+
function wrap(context, message) {
|
|
1490
|
+
return `<context>
|
|
1491
|
+
${context}
|
|
1492
|
+
</context>
|
|
1493
|
+
${message}`;
|
|
1494
|
+
}
|
|
1495
|
+
TaMessageContext2.wrap = wrap;
|
|
1496
|
+
function strip(message) {
|
|
1497
|
+
return message.replace(BLOCK, "");
|
|
1498
|
+
}
|
|
1499
|
+
TaMessageContext2.strip = strip;
|
|
1500
|
+
function read(message) {
|
|
1501
|
+
var _a;
|
|
1502
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
1503
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
1504
|
+
}
|
|
1505
|
+
TaMessageContext2.read = read;
|
|
1506
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
1507
|
+
var TaMessageSource;
|
|
1508
|
+
(function(TaMessageSource2) {
|
|
1509
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
1510
|
+
const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
1511
|
+
function mark(message, from, detail) {
|
|
1512
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
1513
|
+
return message;
|
|
1016
1514
|
}
|
|
1017
|
-
const
|
|
1018
|
-
const
|
|
1019
|
-
return (
|
|
1020
|
-
|
|
1021
|
-
TaPackageTextUtil2.pick = pick;
|
|
1022
|
-
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
1023
|
-
// ../../ta-packages/ta-protocol/esm/common/ta-protocol.js
|
|
1024
|
-
var TaServer = Symbol("TaServer");
|
|
1025
|
-
var TaClient = Symbol("TaClient");
|
|
1026
|
-
var TA_WEBSOCKET_PATH = "/api/ws";
|
|
1027
|
-
var TaErrorCode = {
|
|
1028
|
-
SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
|
|
1029
|
-
SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
|
|
1030
|
-
TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
|
|
1031
|
-
MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
|
|
1032
|
-
MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
|
|
1033
|
-
INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
|
|
1034
|
-
COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
|
|
1035
|
-
NOTHING_TO_COMPACT: "CELL_TA_NOTHING_TO_COMPACT",
|
|
1036
|
-
ALREADY_COMPACTED: "CELL_TA_ALREADY_COMPACTED",
|
|
1037
|
-
SESSION_BUSY: "CELL_TA_SESSION_BUSY",
|
|
1038
|
-
CANCELLED: "CELL_TA_CANCELLED",
|
|
1039
|
-
NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
|
|
1040
|
-
ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
|
|
1041
|
-
RATE_LIMITED: "CELL_TA_RATE_LIMITED",
|
|
1042
|
-
FORBIDDEN: "CELL_TA_FORBIDDEN",
|
|
1043
|
-
LIMIT: "CELL_TA_LIMIT",
|
|
1044
|
-
CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
|
|
1045
|
-
};
|
|
1046
|
-
var TaErrorUtil;
|
|
1047
|
-
(function(TaErrorUtil2) {
|
|
1048
|
-
function code(error) {
|
|
1049
|
-
var _a;
|
|
1050
|
-
var _b;
|
|
1051
|
-
const failure = error;
|
|
1052
|
-
const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
|
|
1053
|
-
return typeof code2 === "string" ? code2 : undefined;
|
|
1054
|
-
}
|
|
1055
|
-
TaErrorUtil2.code = code;
|
|
1056
|
-
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
1057
|
-
var TA_RPC_ERROR_CODE = -32050;
|
|
1058
|
-
var TaSlashCommandUtil;
|
|
1059
|
-
(function(TaSlashCommandUtil2) {
|
|
1060
|
-
function description(command, language) {
|
|
1061
|
-
var _a, _b;
|
|
1062
|
-
const { descriptions } = command;
|
|
1063
|
-
return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
|
|
1064
|
-
}
|
|
1065
|
-
TaSlashCommandUtil2.description = description;
|
|
1066
|
-
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
1067
|
-
var TaMessageContext;
|
|
1068
|
-
(function(TaMessageContext2) {
|
|
1069
|
-
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
1070
|
-
function wrap(context, message) {
|
|
1071
|
-
return `<context>
|
|
1072
|
-
${context}
|
|
1073
|
-
</context>
|
|
1074
|
-
${message}`;
|
|
1075
|
-
}
|
|
1076
|
-
TaMessageContext2.wrap = wrap;
|
|
1077
|
-
function strip(message) {
|
|
1078
|
-
return message.replace(BLOCK, "");
|
|
1079
|
-
}
|
|
1080
|
-
TaMessageContext2.strip = strip;
|
|
1081
|
-
function read(message) {
|
|
1082
|
-
var _a;
|
|
1083
|
-
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
1084
|
-
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
1085
|
-
}
|
|
1086
|
-
TaMessageContext2.read = read;
|
|
1087
|
-
})(TaMessageContext || (TaMessageContext = {}));
|
|
1088
|
-
var TaMessageSource;
|
|
1089
|
-
(function(TaMessageSource2) {
|
|
1090
|
-
TaMessageSource2.DOUBLE = "ta:double";
|
|
1091
|
-
const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
1092
|
-
function mark(message, from, detail) {
|
|
1093
|
-
if (/^[/!]/.test(message) || of(message)) {
|
|
1094
|
-
return message;
|
|
1095
|
-
}
|
|
1096
|
-
const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
1097
|
-
const context = TaMessageContext.read(message);
|
|
1098
|
-
return TaMessageContext.wrap(context === undefined ? line : `${context}
|
|
1099
|
-
${line}`, TaMessageContext.strip(message));
|
|
1515
|
+
const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
1516
|
+
const context = TaMessageContext.read(message);
|
|
1517
|
+
return TaMessageContext.wrap(context === undefined ? line : `${context}
|
|
1518
|
+
${line}`, TaMessageContext.strip(message));
|
|
1100
1519
|
}
|
|
1101
1520
|
TaMessageSource2.mark = mark;
|
|
1102
1521
|
function of(message) {
|
|
@@ -1226,7 +1645,168 @@ var TaSkillUse;
|
|
|
1226
1645
|
}
|
|
1227
1646
|
TaSkillUse2.command = command;
|
|
1228
1647
|
})(TaSkillUse || (TaSkillUse = {}));
|
|
1229
|
-
|
|
1648
|
+
var TaTaskNote;
|
|
1649
|
+
(function(TaTaskNote2) {
|
|
1650
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
1651
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1652
|
+
function write(note) {
|
|
1653
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
1654
|
+
if (note.was !== undefined) {
|
|
1655
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
1656
|
+
}
|
|
1657
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
1658
|
+
if (note.status !== undefined) {
|
|
1659
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
1660
|
+
}
|
|
1661
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
1662
|
+
${note.body}
|
|
1663
|
+
</task_${note.kind}>`;
|
|
1664
|
+
}
|
|
1665
|
+
TaTaskNote2.write = write;
|
|
1666
|
+
function parse(text) {
|
|
1667
|
+
const match = NOTE.exec(text.trim());
|
|
1668
|
+
if (!match) {
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
const attributes = {};
|
|
1672
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
1673
|
+
attributes[name] = unquote(value);
|
|
1674
|
+
}
|
|
1675
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
const { id, title, status, was } = attributes;
|
|
1679
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
1680
|
+
}
|
|
1681
|
+
TaTaskNote2.parse = parse;
|
|
1682
|
+
function quote(text) {
|
|
1683
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
1684
|
+
}
|
|
1685
|
+
function unquote(text) {
|
|
1686
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
1687
|
+
}
|
|
1688
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
1689
|
+
// ../../ta-packages/ta-protocol/esm/common/package-protocol.js
|
|
1690
|
+
var TaPackageServer = Symbol("TaPackageServer");
|
|
1691
|
+
var TaPackageTextUtil;
|
|
1692
|
+
(function(TaPackageTextUtil2) {
|
|
1693
|
+
function pick(text, language) {
|
|
1694
|
+
var _a, _b, _c, _d, _e;
|
|
1695
|
+
if (text === undefined || typeof text === "string") {
|
|
1696
|
+
return text;
|
|
1697
|
+
}
|
|
1698
|
+
const base = language.split("-")[0];
|
|
1699
|
+
const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
|
|
1700
|
+
return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
|
|
1701
|
+
}
|
|
1702
|
+
TaPackageTextUtil2.pick = pick;
|
|
1703
|
+
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
1704
|
+
// ../../ta-packages/ta-protocol/esm/common/page-protocol.js
|
|
1705
|
+
var TaPageServer = Symbol("TaPageServer");
|
|
1706
|
+
// ../../ta-packages/ta-protocol/esm/common/path-map.js
|
|
1707
|
+
var TaPathMap;
|
|
1708
|
+
(function(TaPathMap2) {
|
|
1709
|
+
function isWindows(path2) {
|
|
1710
|
+
return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
|
|
1711
|
+
}
|
|
1712
|
+
TaPathMap2.isWindows = isWindows;
|
|
1713
|
+
function rest(path2, base) {
|
|
1714
|
+
const windows = isWindows(base);
|
|
1715
|
+
if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const within = parts(base, windows);
|
|
1719
|
+
const all = parts(path2, windows);
|
|
1720
|
+
if (!within.length || all.length < within.length) {
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
1724
|
+
return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
|
|
1725
|
+
}
|
|
1726
|
+
TaPathMap2.rest = rest;
|
|
1727
|
+
function under(path2, base) {
|
|
1728
|
+
return rest(path2, base) !== undefined;
|
|
1729
|
+
}
|
|
1730
|
+
TaPathMap2.under = under;
|
|
1731
|
+
function join(base, parts2) {
|
|
1732
|
+
if (!parts2.length) {
|
|
1733
|
+
return base;
|
|
1734
|
+
}
|
|
1735
|
+
const sep = isWindows(base) ? "\\" : "/";
|
|
1736
|
+
return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
|
|
1737
|
+
}
|
|
1738
|
+
TaPathMap2.join = join;
|
|
1739
|
+
function basename(path2) {
|
|
1740
|
+
var _a;
|
|
1741
|
+
return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
|
|
1742
|
+
}
|
|
1743
|
+
TaPathMap2.basename = basename;
|
|
1744
|
+
function path(value, pairs) {
|
|
1745
|
+
for (const [from, to] of deepest(pairs)) {
|
|
1746
|
+
const found = rest(value, from);
|
|
1747
|
+
if (found) {
|
|
1748
|
+
return join(to, found);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
return value;
|
|
1752
|
+
}
|
|
1753
|
+
TaPathMap2.path = path;
|
|
1754
|
+
function text(value, pairs) {
|
|
1755
|
+
const order = deepest(pairs);
|
|
1756
|
+
if (!order.length) {
|
|
1757
|
+
return value;
|
|
1758
|
+
}
|
|
1759
|
+
const end = String.raw`\s"'<>|*?:;,`;
|
|
1760
|
+
const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
|
|
1761
|
+
return value.replace(pattern, (...match) => {
|
|
1762
|
+
var _a;
|
|
1763
|
+
const before = match[1];
|
|
1764
|
+
const found = order.findIndex((_, i) => match[i + 2] !== undefined);
|
|
1765
|
+
const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
|
|
1766
|
+
return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
TaPathMap2.text = text;
|
|
1770
|
+
function json(value, pairs) {
|
|
1771
|
+
const order = deepest(pairs);
|
|
1772
|
+
if (!order.length) {
|
|
1773
|
+
return value;
|
|
1774
|
+
}
|
|
1775
|
+
const one = (each) => {
|
|
1776
|
+
const whole = path(each, order);
|
|
1777
|
+
return whole !== each ? whole : text(each, order);
|
|
1778
|
+
};
|
|
1779
|
+
const walk = (each) => {
|
|
1780
|
+
if (typeof each === "string") {
|
|
1781
|
+
return one(each);
|
|
1782
|
+
}
|
|
1783
|
+
if (Array.isArray(each)) {
|
|
1784
|
+
return each.map(walk);
|
|
1785
|
+
}
|
|
1786
|
+
if (each && typeof each === "object") {
|
|
1787
|
+
return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
|
|
1788
|
+
}
|
|
1789
|
+
return each;
|
|
1790
|
+
};
|
|
1791
|
+
return walk(value);
|
|
1792
|
+
}
|
|
1793
|
+
TaPathMap2.json = json;
|
|
1794
|
+
function parts(path2, windows) {
|
|
1795
|
+
return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
|
|
1796
|
+
}
|
|
1797
|
+
function deepest(pairs) {
|
|
1798
|
+
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);
|
|
1799
|
+
}
|
|
1800
|
+
function source(base) {
|
|
1801
|
+
const windows = isWindows(base);
|
|
1802
|
+
const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
|
|
1803
|
+
const each = parts(base, windows).map(quote);
|
|
1804
|
+
if (!windows) {
|
|
1805
|
+
return `/${each.join("/+")}`;
|
|
1806
|
+
}
|
|
1807
|
+
return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
|
|
1808
|
+
}
|
|
1809
|
+
})(TaPathMap || (TaPathMap = {}));
|
|
1230
1810
|
// ../../ta-packages/ta-protocol/esm/common/presence-protocol.js
|
|
1231
1811
|
var TaPresenceServer = Symbol("TaPresenceServer");
|
|
1232
1812
|
var TaMessageAuthor;
|
|
@@ -1304,98 +1884,19 @@ var TaRoomWatchUtil;
|
|
|
1304
1884
|
})(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
|
|
1305
1885
|
// ../../ta-packages/ta-protocol/esm/common/settings-protocol.js
|
|
1306
1886
|
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
1307
|
-
// ../../ta-packages/ta-protocol/esm/common/ta-
|
|
1308
|
-
var
|
|
1309
|
-
var
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
const request = {
|
|
1318
|
-
name,
|
|
1319
|
-
heard: () => {
|
|
1320
|
-
heard = true;
|
|
1321
|
-
},
|
|
1322
|
-
resolve: (answer) => {
|
|
1323
|
-
answered = true;
|
|
1324
|
-
clearTimeout(timer);
|
|
1325
|
-
resolve(answer);
|
|
1326
|
-
}
|
|
1327
|
-
};
|
|
1328
|
-
events.emit(TA_HOST_EVENT, request);
|
|
1329
|
-
if (!heard && !answered) {
|
|
1330
|
-
clearTimeout(timer);
|
|
1331
|
-
resolve(undefined);
|
|
1332
|
-
}
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
TaHostUtil2.reach = reach;
|
|
1336
|
-
function marked(systemPrompt, mark) {
|
|
1337
|
-
return role(systemPrompt).includes(mark);
|
|
1338
|
-
}
|
|
1339
|
-
TaHostUtil2.marked = marked;
|
|
1340
|
-
function role(systemPrompt) {
|
|
1341
|
-
if (!systemPrompt) {
|
|
1342
|
-
return "";
|
|
1343
|
-
}
|
|
1344
|
-
const open = `<addendum>
|
|
1345
|
-
`;
|
|
1346
|
-
const start = systemPrompt.indexOf(open);
|
|
1347
|
-
const context = systemPrompt.indexOf(`<project_context>
|
|
1348
|
-
`);
|
|
1349
|
-
if (start < 0 || context >= 0 && context < start) {
|
|
1350
|
-
return "";
|
|
1351
|
-
}
|
|
1352
|
-
const end = systemPrompt.indexOf(`
|
|
1353
|
-
</addendum>`, start);
|
|
1354
|
-
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
1355
|
-
}
|
|
1356
|
-
TaHostUtil2.role = role;
|
|
1357
|
-
})(TaHostUtil || (TaHostUtil = {}));
|
|
1358
|
-
var TA_ASK_ENTRY = "ta-ask";
|
|
1359
|
-
var TaAskUtil;
|
|
1360
|
-
(function(TaAskUtil2) {
|
|
1361
|
-
const LENGTH = 120;
|
|
1362
|
-
function entry(question) {
|
|
1363
|
-
const line = question.replace(/\s+/g, " ").trim();
|
|
1364
|
-
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
1365
|
-
}
|
|
1366
|
-
TaAskUtil2.entry = entry;
|
|
1367
|
-
function asking(entries) {
|
|
1368
|
-
var _a;
|
|
1369
|
-
for (let i = entries.length - 1;i >= 0; i--) {
|
|
1370
|
-
const entry2 = entries[i];
|
|
1371
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
1372
|
-
return;
|
|
1373
|
-
}
|
|
1374
|
-
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
1375
|
-
return read(entry2);
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
return;
|
|
1379
|
-
}
|
|
1380
|
-
TaAskUtil2.asking = asking;
|
|
1381
|
-
function next(asked, entry2) {
|
|
1382
|
-
var _a;
|
|
1383
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
1384
|
-
return;
|
|
1385
|
-
}
|
|
1386
|
-
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
1387
|
-
}
|
|
1388
|
-
TaAskUtil2.next = next;
|
|
1389
|
-
function read(found) {
|
|
1390
|
-
var _a;
|
|
1391
|
-
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
1392
|
-
if (typeof question !== "string" || !question.trim()) {
|
|
1393
|
-
return;
|
|
1394
|
-
}
|
|
1395
|
-
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
1396
|
-
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
1887
|
+
// ../../ta-packages/ta-protocol/esm/common/ta-protocol.js
|
|
1888
|
+
var TaServer = Symbol("TaServer");
|
|
1889
|
+
var TaClient = Symbol("TaClient");
|
|
1890
|
+
var TA_WEBSOCKET_PATH = "/api/ws";
|
|
1891
|
+
var TaSlashCommandUtil;
|
|
1892
|
+
(function(TaSlashCommandUtil2) {
|
|
1893
|
+
function description(command, language) {
|
|
1894
|
+
var _a, _b;
|
|
1895
|
+
const { descriptions } = command;
|
|
1896
|
+
return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
|
|
1397
1897
|
}
|
|
1398
|
-
|
|
1898
|
+
TaSlashCommandUtil2.description = description;
|
|
1899
|
+
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
1399
1900
|
// ../../ta-packages/ta-protocol/esm/common/team-protocol.js
|
|
1400
1901
|
var TA_UNDECLARED = "extensions.install";
|
|
1401
1902
|
var TaPermissionUtil;
|
|
@@ -1487,6 +1988,8 @@ var TaActionUtil;
|
|
|
1487
1988
|
})(TaActionUtil || (TaActionUtil = {}));
|
|
1488
1989
|
// ../../ta-packages/ta-protocol/esm/common/usage-protocol.js
|
|
1489
1990
|
var TaUsageServer = Symbol("TaUsageServer");
|
|
1991
|
+
// ../../ta-packages/ta-protocol/esm/common/voice-protocol.js
|
|
1992
|
+
var TaVoiceServer = Symbol("TaVoiceServer");
|
|
1490
1993
|
// ../../ta-packages/ta-protocol/esm/common/workspace-protocol.js
|
|
1491
1994
|
var TA_FILES_PATH = "/api/files";
|
|
1492
1995
|
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
@@ -2158,10 +2661,11 @@ var SandboxProviders;
|
|
|
2158
2661
|
}
|
|
2159
2662
|
SandboxProviders2.create = create;
|
|
2160
2663
|
async function loadModule(entry, context) {
|
|
2664
|
+
var _a;
|
|
2161
2665
|
if (typeof entry.path !== "string" || !entry.path) {
|
|
2162
2666
|
throw new SandboxConfigError('A provider of the type "module" names its file in "path".');
|
|
2163
2667
|
}
|
|
2164
|
-
const path = isAbsolute(entry.path) ? entry.path : join(context.dir, entry.path);
|
|
2668
|
+
const path = isAbsolute(entry.path) ? entry.path : join((_a = context.config) !== null && _a !== undefined ? _a : context.dir, entry.path);
|
|
2165
2669
|
const loaded = await import(pathToFileURL(path).href);
|
|
2166
2670
|
if (typeof loaded.default !== "function") {
|
|
2167
2671
|
throw new SandboxConfigError(`${path} has no default export of a function (id, config, context) => SandboxProvider.`);
|
|
@@ -2281,6 +2785,9 @@ class CommandSandbox {
|
|
|
2281
2785
|
}
|
|
2282
2786
|
}
|
|
2283
2787
|
|
|
2788
|
+
// ../../ta-packages/ta-gateway/esm/node/docker-sandbox.js
|
|
2789
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
2790
|
+
|
|
2284
2791
|
// ../../ta-packages/ta-gateway/esm/node/docker-engine.js
|
|
2285
2792
|
import { request } from "node:http";
|
|
2286
2793
|
|
|
@@ -2411,6 +2918,9 @@ class DockerEngine {
|
|
|
2411
2918
|
}
|
|
2412
2919
|
}
|
|
2413
2920
|
const options = isolated ? { "com.docker.network.bridge.enable_icc": "false" } : {};
|
|
2921
|
+
if (/^[a-zA-Z0-9_.-]{1,15}$/.test(name)) {
|
|
2922
|
+
options["com.docker.network.bridge.name"] = name;
|
|
2923
|
+
}
|
|
2414
2924
|
await this.call("POST", "/networks/create", { Name: name, Driver: "bridge", Options: options, Labels: { "cell.ta.gateway": "1" } });
|
|
2415
2925
|
}
|
|
2416
2926
|
async ensureImage(image) {
|
|
@@ -2484,6 +2994,18 @@ var DockerEngineUtil;
|
|
|
2484
2994
|
// ../../ta-packages/ta-gateway/esm/node/docker-sandbox.js
|
|
2485
2995
|
var DockerSandboxUtil;
|
|
2486
2996
|
(function(DockerSandboxUtil2) {
|
|
2997
|
+
DockerSandboxUtil2.ENV_LABEL = "cell.ta.env";
|
|
2998
|
+
function envHash(env) {
|
|
2999
|
+
const entries = Object.entries(env !== null && env !== undefined ? env : {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
3000
|
+
return createHash4("sha256").update(JSON.stringify(entries)).digest("hex").slice(0, 16);
|
|
3001
|
+
}
|
|
3002
|
+
DockerSandboxUtil2.envHash = envHash;
|
|
3003
|
+
function sameEnv(config, want) {
|
|
3004
|
+
var _a;
|
|
3005
|
+
const made = (_a = config === null || config === undefined ? undefined : config.Labels) === null || _a === undefined ? undefined : _a[DockerSandboxUtil2.ENV_LABEL];
|
|
3006
|
+
return made !== undefined ? made === envHash(want) : hasEnv(config === null || config === undefined ? undefined : config.Env, want);
|
|
3007
|
+
}
|
|
3008
|
+
DockerSandboxUtil2.sameEnv = sameEnv;
|
|
2487
3009
|
function hasEnv(have, want) {
|
|
2488
3010
|
const set = new Set(have !== null && have !== undefined ? have : []);
|
|
2489
3011
|
return Object.entries(want !== null && want !== undefined ? want : {}).every(([key, value]) => set.has(`${key}=${value}`));
|
|
@@ -2530,10 +3052,10 @@ class DockerSandbox {
|
|
|
2530
3052
|
this.engine = engine !== null && engine !== undefined ? engine : new DockerEngine({ host: options.host });
|
|
2531
3053
|
}
|
|
2532
3054
|
async start(tenant) {
|
|
2533
|
-
var _a, _b, _c
|
|
3055
|
+
var _a, _b, _c;
|
|
2534
3056
|
const name = this.containerName(tenant);
|
|
2535
3057
|
let container = await this.engine.inspect(name);
|
|
2536
|
-
if (container && !DockerSandboxUtil.
|
|
3058
|
+
if (container && !DockerSandboxUtil.sameEnv(container.Config, tenant.env)) {
|
|
2537
3059
|
await this.engine.remove(name);
|
|
2538
3060
|
container = undefined;
|
|
2539
3061
|
}
|
|
@@ -2547,7 +3069,7 @@ class DockerSandbox {
|
|
|
2547
3069
|
await this.engine.start(name);
|
|
2548
3070
|
container = await this.engine.inspect(name);
|
|
2549
3071
|
}
|
|
2550
|
-
const port = (
|
|
3072
|
+
const port = (_c = (_b = (_a = container === null || container === undefined ? undefined : container.NetworkSettings.Ports) === null || _a === undefined ? undefined : _a[PORT]) === null || _b === undefined ? undefined : _b[0]) === null || _c === undefined ? undefined : _c.HostPort;
|
|
2551
3073
|
if (!port) {
|
|
2552
3074
|
throw new Error(`The container ${name} publishes no port for ${PORT}.`);
|
|
2553
3075
|
}
|
|
@@ -2572,7 +3094,7 @@ class DockerSandbox {
|
|
|
2572
3094
|
Image: this.options.image,
|
|
2573
3095
|
Hostname: DockerSandboxUtil.hostname(tenant.account),
|
|
2574
3096
|
Env: [`TA_SERVE_TOKEN=${tenant.token}`, ...Object.entries({ ...this.options.env, ...tenant.env }).map(([key, value]) => `${key}=${value}`)],
|
|
2575
|
-
Labels: { "cell.ta.tenant": tenant.id, "cell.ta.account": tenant.account },
|
|
3097
|
+
Labels: { "cell.ta.tenant": tenant.id, "cell.ta.account": tenant.account, [DockerSandboxUtil.ENV_LABEL]: DockerSandboxUtil.envHash(tenant.env) },
|
|
2576
3098
|
ExposedPorts: { [PORT]: {} },
|
|
2577
3099
|
HostConfig: {
|
|
2578
3100
|
PortBindings: { [PORT]: [{ HostIp: this.options.bind, HostPort: "" }] },
|
|
@@ -2593,23 +3115,429 @@ class DockerSandbox {
|
|
|
2593
3115
|
}
|
|
2594
3116
|
}
|
|
2595
3117
|
|
|
2596
|
-
// ../../ta-packages/ta-gateway/esm/node/
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
3118
|
+
// ../../ta-packages/ta-gateway/esm/node/egress-proxy.js
|
|
3119
|
+
import { timingSafeEqual } from "node:crypto";
|
|
3120
|
+
import { lookup } from "node:dns/promises";
|
|
3121
|
+
import { request as httpRequest, STATUS_CODES } from "node:http";
|
|
3122
|
+
import { BlockList, connect, isIP } from "node:net";
|
|
3123
|
+
import { networkInterfaces } from "node:os";
|
|
3124
|
+
import { pipeline } from "node:stream";
|
|
3125
|
+
|
|
3126
|
+
class EgressConfigError extends Error {
|
|
3127
|
+
}
|
|
3128
|
+
var PORTS = new Set([80, 443]);
|
|
3129
|
+
var REFUSALS = 10;
|
|
3130
|
+
var CONNECT_TIMEOUT_MS = 15000;
|
|
3131
|
+
var HOP_BY_HOP = new Set([
|
|
3132
|
+
"connection",
|
|
3133
|
+
"keep-alive",
|
|
3134
|
+
"proxy-authenticate",
|
|
3135
|
+
"proxy-authorization",
|
|
3136
|
+
"proxy-connection",
|
|
3137
|
+
"te",
|
|
3138
|
+
"trailer",
|
|
3139
|
+
"transfer-encoding",
|
|
3140
|
+
"upgrade"
|
|
3141
|
+
]);
|
|
3142
|
+
var PATTERN = /^(\*|(\*\.)?[a-z0-9_]([a-z0-9_-]*[a-z0-9_])?(\.[a-z0-9_]([a-z0-9_-]*[a-z0-9_])?)*)(:(\d{1,5}|\*))?$/;
|
|
3143
|
+
var NEVER = new BlockList;
|
|
3144
|
+
for (const [network, prefix] of [
|
|
3145
|
+
["0.0.0.0", 8],
|
|
3146
|
+
["127.0.0.0", 8],
|
|
3147
|
+
["169.254.0.0", 16],
|
|
3148
|
+
["224.0.0.0", 4],
|
|
3149
|
+
["240.0.0.0", 4]
|
|
3150
|
+
]) {
|
|
3151
|
+
NEVER.addSubnet(network, prefix, "ipv4");
|
|
3152
|
+
}
|
|
3153
|
+
for (const [network, prefix] of [
|
|
3154
|
+
["::", 128],
|
|
3155
|
+
["::1", 128],
|
|
3156
|
+
["fe80::", 10],
|
|
3157
|
+
["ff00::", 8]
|
|
3158
|
+
]) {
|
|
3159
|
+
NEVER.addSubnet(network, prefix, "ipv6");
|
|
3160
|
+
}
|
|
3161
|
+
var PRIVATE = new BlockList;
|
|
3162
|
+
for (const [network, prefix] of [
|
|
3163
|
+
["10.0.0.0", 8],
|
|
3164
|
+
["172.16.0.0", 12],
|
|
3165
|
+
["192.168.0.0", 16],
|
|
3166
|
+
["100.64.0.0", 10],
|
|
3167
|
+
["198.18.0.0", 15]
|
|
3168
|
+
]) {
|
|
3169
|
+
PRIVATE.addSubnet(network, prefix, "ipv4");
|
|
3170
|
+
}
|
|
3171
|
+
for (const [network, prefix] of [
|
|
3172
|
+
["fc00::", 7],
|
|
3173
|
+
["64:ff9b::", 96]
|
|
3174
|
+
]) {
|
|
3175
|
+
PRIVATE.addSubnet(network, prefix, "ipv6");
|
|
3176
|
+
}
|
|
3177
|
+
var EgressProxyUtil;
|
|
3178
|
+
(function(EgressProxyUtil2) {
|
|
3179
|
+
function settings(config) {
|
|
3180
|
+
var _a;
|
|
3181
|
+
if (config === undefined || config === false) {
|
|
3182
|
+
return { enabled: false, networks: [] };
|
|
3183
|
+
}
|
|
3184
|
+
if (config === true) {
|
|
3185
|
+
return { enabled: true, networks: [] };
|
|
3186
|
+
}
|
|
3187
|
+
if (typeof config !== "object" || config === null || config.networks !== undefined && !Array.isArray(config.networks)) {
|
|
3188
|
+
throw new EgressConfigError('"egress" of sandboxes.json is true, false or { "networks": ["10.0.0.0/8"] }.');
|
|
3189
|
+
}
|
|
3190
|
+
const networks = (_a = config.networks) !== null && _a !== undefined ? _a : [];
|
|
3191
|
+
networksOf(networks);
|
|
3192
|
+
return { enabled: true, networks };
|
|
3193
|
+
}
|
|
3194
|
+
EgressProxyUtil2.settings = settings;
|
|
3195
|
+
function networksOf(networks) {
|
|
3196
|
+
const list = new BlockList;
|
|
3197
|
+
for (const network of networks) {
|
|
3198
|
+
const [address, bits, ...rest] = String(network).trim().split("/");
|
|
3199
|
+
const family = isIP(address);
|
|
3200
|
+
const max = family === 6 ? 128 : 32;
|
|
3201
|
+
const prefix = bits === undefined ? max : Number(bits);
|
|
3202
|
+
if (!family || rest.length > 0 || !Number.isInteger(prefix) || prefix < 0 || prefix > max || bits !== undefined && !/^\d+$/.test(bits)) {
|
|
3203
|
+
throw new EgressConfigError(`"${network}" of egress.networks is no network: write it as 10.0.0.0/8, or one address.`);
|
|
3204
|
+
}
|
|
3205
|
+
list.addSubnet(address, prefix, family === 6 ? "ipv6" : "ipv4");
|
|
3206
|
+
}
|
|
3207
|
+
return list;
|
|
3208
|
+
}
|
|
3209
|
+
EgressProxyUtil2.networksOf = networksOf;
|
|
3210
|
+
function hosts(value) {
|
|
3211
|
+
var _a;
|
|
3212
|
+
if (!Array.isArray(value) || value.length > 200) {
|
|
3213
|
+
throw new EgressConfigError("The hosts are a list of at most 200.");
|
|
3214
|
+
}
|
|
3215
|
+
const hosts2 = new Set;
|
|
3216
|
+
for (const item of value) {
|
|
3217
|
+
const host = typeof item === "string" ? item.trim().toLowerCase().replace(/\.$/, "") : "";
|
|
3218
|
+
if (!host) {
|
|
3219
|
+
continue;
|
|
3220
|
+
}
|
|
3221
|
+
const port = (_a = /:(\d+)$/.exec(host)) === null || _a === undefined ? undefined : _a[1];
|
|
3222
|
+
if (!PATTERN.test(host) || port !== undefined && (Number(port) < 1 || Number(port) > 65535)) {
|
|
3223
|
+
throw new EgressConfigError(`"${item}" is no host: write example.com, *.example.com or example.com:8443.`);
|
|
3224
|
+
}
|
|
3225
|
+
hosts2.add(host);
|
|
3226
|
+
}
|
|
3227
|
+
return [...hosts2];
|
|
3228
|
+
}
|
|
3229
|
+
EgressProxyUtil2.hosts = hosts;
|
|
3230
|
+
function credentials(header) {
|
|
3231
|
+
var _a;
|
|
3232
|
+
const match = /^Basic\s+(\S+)$/i.exec((_a = header === null || header === undefined ? undefined : header.trim()) !== null && _a !== undefined ? _a : "");
|
|
3233
|
+
if (!match) {
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
const text = Buffer.from(match[1], "base64").toString("utf8");
|
|
3237
|
+
const colon = text.indexOf(":");
|
|
3238
|
+
return colon < 0 ? undefined : { user: decodeURIComponent(text.slice(0, colon)), password: decodeURIComponent(text.slice(colon + 1)) };
|
|
3239
|
+
}
|
|
3240
|
+
EgressProxyUtil2.credentials = credentials;
|
|
3241
|
+
function target(authority, fallbackPort) {
|
|
3242
|
+
var _a;
|
|
3243
|
+
const match = /^(?:\[([0-9a-f:.]+)\]|([^\s:/[\]]+))(?::(\d{1,5}))?$/i.exec(authority.trim());
|
|
3244
|
+
if (!match) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
const port = match[3] === undefined ? fallbackPort : Number(match[3]);
|
|
3248
|
+
if (port < 1 || port > 65535) {
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
return { host: ((_a = match[1]) !== null && _a !== undefined ? _a : match[2]).toLowerCase().replace(/\.$/, ""), port };
|
|
3252
|
+
}
|
|
3253
|
+
EgressProxyUtil2.target = target;
|
|
3254
|
+
function refusal(hosts2, target2) {
|
|
3255
|
+
if (!hosts2 || hosts2.length === 0) {
|
|
3256
|
+
return PORTS.has(target2.port) ? undefined : "port";
|
|
3257
|
+
}
|
|
3258
|
+
let named = false;
|
|
3259
|
+
for (const pattern of hosts2) {
|
|
3260
|
+
const colon = pattern.lastIndexOf(":");
|
|
3261
|
+
const name = colon < 0 ? pattern : pattern.slice(0, colon);
|
|
3262
|
+
const port = colon < 0 ? undefined : pattern.slice(colon + 1);
|
|
3263
|
+
const matches = name === "*" || name === target2.host || name.startsWith("*.") && target2.host.endsWith(name.slice(1));
|
|
3264
|
+
if (!matches) {
|
|
3265
|
+
continue;
|
|
3266
|
+
}
|
|
3267
|
+
named = true;
|
|
3268
|
+
if (port === "*" || (port === undefined ? PORTS.has(target2.port) : Number(port) === target2.port)) {
|
|
3269
|
+
return;
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
return named ? "port" : "host";
|
|
3273
|
+
}
|
|
3274
|
+
EgressProxyUtil2.refusal = refusal;
|
|
3275
|
+
function plain(address) {
|
|
3276
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(address);
|
|
3277
|
+
return mapped ? mapped[1] : address;
|
|
3278
|
+
}
|
|
3279
|
+
EgressProxyUtil2.plain = plain;
|
|
3280
|
+
function reachable(address, networks, own = ownAddresses()) {
|
|
3281
|
+
const ip = plain(address);
|
|
3282
|
+
const family = isIP(ip);
|
|
3283
|
+
if (!family) {
|
|
3284
|
+
return false;
|
|
3285
|
+
}
|
|
3286
|
+
const type = family === 6 ? "ipv6" : "ipv4";
|
|
3287
|
+
if (own.has(ip) || NEVER.check(ip, type)) {
|
|
3288
|
+
return false;
|
|
3289
|
+
}
|
|
3290
|
+
return !PRIVATE.check(ip, type) || networks.check(ip, type);
|
|
3291
|
+
}
|
|
3292
|
+
EgressProxyUtil2.reachable = reachable;
|
|
3293
|
+
function ownAddresses() {
|
|
3294
|
+
return new Set(Object.values(networkInterfaces()).flat().map((each) => {
|
|
3295
|
+
var _a;
|
|
3296
|
+
return plain((_a = each === null || each === undefined ? undefined : each.address) !== null && _a !== undefined ? _a : "").toLowerCase();
|
|
3297
|
+
}).filter(Boolean));
|
|
3298
|
+
}
|
|
3299
|
+
EgressProxyUtil2.ownAddresses = ownAddresses;
|
|
3300
|
+
function env(url, user, password) {
|
|
3301
|
+
const base = new URL(url);
|
|
3302
|
+
const port = base.port || (base.protocol === "https:" ? "443" : "80");
|
|
3303
|
+
const proxy = `${base.protocol}//${encodeURIComponent(user)}:${encodeURIComponent(password)}@${base.hostname}:${port}`;
|
|
3304
|
+
const direct = ["localhost", "127.0.0.1", "::1", new URL(url).hostname].filter((each, index, all) => all.indexOf(each) === index).join(",");
|
|
3305
|
+
return {
|
|
3306
|
+
HTTP_PROXY: proxy,
|
|
3307
|
+
HTTPS_PROXY: proxy,
|
|
3308
|
+
http_proxy: proxy,
|
|
3309
|
+
https_proxy: proxy,
|
|
3310
|
+
NO_PROXY: direct,
|
|
3311
|
+
no_proxy: direct,
|
|
3312
|
+
NODE_USE_ENV_PROXY: "1"
|
|
3313
|
+
};
|
|
3314
|
+
}
|
|
3315
|
+
EgressProxyUtil2.env = env;
|
|
3316
|
+
function sameSecret(given, known) {
|
|
3317
|
+
const a = Buffer.from(given);
|
|
3318
|
+
const b = Buffer.from(known);
|
|
3319
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
3320
|
+
}
|
|
3321
|
+
EgressProxyUtil2.sameSecret = sameSecret;
|
|
3322
|
+
function headers(given) {
|
|
3323
|
+
const kept = {};
|
|
3324
|
+
for (const [name, value] of Object.entries(given)) {
|
|
3325
|
+
if (value !== undefined && !HOP_BY_HOP.has(name.toLowerCase())) {
|
|
3326
|
+
kept[name] = value;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
return kept;
|
|
3330
|
+
}
|
|
3331
|
+
EgressProxyUtil2.headers = headers;
|
|
3332
|
+
})(EgressProxyUtil || (EgressProxyUtil = {}));
|
|
3333
|
+
|
|
3334
|
+
class EgressProxy {
|
|
3335
|
+
constructor(settings, hooks) {
|
|
3336
|
+
this.settings = settings;
|
|
3337
|
+
this.hooks = hooks;
|
|
3338
|
+
this.pending = new Map;
|
|
3339
|
+
this.refusals = new Map;
|
|
3340
|
+
this.networks = EgressProxyUtil.networksOf(settings.networks);
|
|
3341
|
+
}
|
|
3342
|
+
get enabled() {
|
|
3343
|
+
return this.settings.enabled;
|
|
3344
|
+
}
|
|
3345
|
+
flush() {
|
|
3346
|
+
const moved = new Map(this.pending);
|
|
3347
|
+
this.pending.clear();
|
|
3348
|
+
return moved;
|
|
3349
|
+
}
|
|
3350
|
+
refused(tenantId) {
|
|
3351
|
+
var _a;
|
|
3352
|
+
return (_a = this.refusals.get(tenantId)) !== null && _a !== undefined ? _a : [];
|
|
3353
|
+
}
|
|
3354
|
+
async connect(request2, socket, head) {
|
|
3355
|
+
var _a;
|
|
3356
|
+
socket.on("error", () => socket.destroy());
|
|
3357
|
+
const who = this.authorize(request2);
|
|
3358
|
+
if ("status" in who) {
|
|
3359
|
+
this.reply(socket, who.status, who.message);
|
|
3360
|
+
return;
|
|
3361
|
+
}
|
|
3362
|
+
const target = EgressProxyUtil.target((_a = request2.url) !== null && _a !== undefined ? _a : "", 443);
|
|
3363
|
+
if (!target) {
|
|
3364
|
+
this.reply(socket, 400, "ta gateway: CONNECT takes host:port.");
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
const address = await this.resolve(who, target);
|
|
3368
|
+
if (typeof address !== "string") {
|
|
3369
|
+
this.reply(socket, address.status, address.message);
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3372
|
+
const upstream = connect({ host: address, port: target.port });
|
|
3373
|
+
let open = false;
|
|
3374
|
+
let moved = head.length;
|
|
3375
|
+
upstream.setTimeout(CONNECT_TIMEOUT_MS, () => upstream.destroy(new Error("timed out")));
|
|
3376
|
+
upstream.once("connect", () => {
|
|
3377
|
+
open = true;
|
|
3378
|
+
upstream.setTimeout(0);
|
|
3379
|
+
socket.write(`HTTP/1.1 200 Connection Established\r
|
|
3380
|
+
\r
|
|
3381
|
+
`);
|
|
3382
|
+
if (head.length > 0) {
|
|
3383
|
+
upstream.write(head);
|
|
3384
|
+
}
|
|
3385
|
+
upstream.on("data", (chunk) => moved += chunk.length);
|
|
3386
|
+
socket.on("data", (chunk) => moved += chunk.length);
|
|
3387
|
+
upstream.pipe(socket);
|
|
3388
|
+
socket.pipe(upstream);
|
|
3389
|
+
});
|
|
3390
|
+
upstream.once("error", (error) => {
|
|
3391
|
+
if (!open) {
|
|
3392
|
+
this.reply(socket, 502, `ta gateway: ${target.host}:${target.port} did not answer: ${error.message}`);
|
|
3393
|
+
}
|
|
3394
|
+
socket.destroy();
|
|
3395
|
+
});
|
|
3396
|
+
upstream.once("close", () => socket.destroy());
|
|
3397
|
+
socket.once("close", () => {
|
|
3398
|
+
upstream.destroy();
|
|
3399
|
+
this.count(who.tenantId, moved);
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
async request(request2, response) {
|
|
3403
|
+
var _a;
|
|
3404
|
+
const who = this.authorize(request2);
|
|
3405
|
+
if ("status" in who) {
|
|
3406
|
+
this.end(response, who.status, who.message);
|
|
3407
|
+
return;
|
|
3408
|
+
}
|
|
3409
|
+
let url;
|
|
3410
|
+
try {
|
|
3411
|
+
url = new URL((_a = request2.url) !== null && _a !== undefined ? _a : "");
|
|
3412
|
+
} catch (_b) {
|
|
3413
|
+
this.end(response, 400, "ta gateway: not a URL.");
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
const target = url.protocol === "http:" ? EgressProxyUtil.target(url.host, 80) : undefined;
|
|
3417
|
+
if (!target) {
|
|
3418
|
+
this.end(response, 400, "ta gateway: only http:// is forwarded this way; https goes by CONNECT.");
|
|
3419
|
+
return;
|
|
3420
|
+
}
|
|
3421
|
+
const address = await this.resolve(who, target);
|
|
3422
|
+
if (typeof address !== "string") {
|
|
3423
|
+
this.end(response, address.status, address.message);
|
|
3424
|
+
return;
|
|
3425
|
+
}
|
|
3426
|
+
let moved = 0;
|
|
3427
|
+
await new Promise((resolve) => {
|
|
3428
|
+
const outgoing = httpRequest({
|
|
3429
|
+
host: address,
|
|
3430
|
+
port: target.port,
|
|
3431
|
+
method: request2.method,
|
|
3432
|
+
path: `${url.pathname}${url.search}`,
|
|
3433
|
+
headers: { ...EgressProxyUtil.headers(request2.headers), host: url.host },
|
|
3434
|
+
setHost: false
|
|
3435
|
+
}, (incoming) => {
|
|
3436
|
+
var _a2;
|
|
3437
|
+
response.writeHead((_a2 = incoming.statusCode) !== null && _a2 !== undefined ? _a2 : 502, EgressProxyUtil.headers(incoming.headers));
|
|
3438
|
+
incoming.on("data", (chunk) => moved += chunk.length);
|
|
3439
|
+
pipeline(incoming, response, () => resolve());
|
|
3440
|
+
});
|
|
3441
|
+
outgoing.setTimeout(CONNECT_TIMEOUT_MS * 4, () => outgoing.destroy(new Error("timed out")));
|
|
3442
|
+
outgoing.once("error", (error) => {
|
|
3443
|
+
if (!response.headersSent) {
|
|
3444
|
+
this.end(response, 502, `ta gateway: ${target.host} did not answer: ${error.message}`);
|
|
3445
|
+
} else {
|
|
3446
|
+
response.destroy();
|
|
3447
|
+
}
|
|
3448
|
+
resolve();
|
|
3449
|
+
});
|
|
3450
|
+
request2.on("data", (chunk) => moved += chunk.length);
|
|
3451
|
+
request2.pipe(outgoing);
|
|
3452
|
+
});
|
|
3453
|
+
this.count(who.tenantId, moved);
|
|
3454
|
+
}
|
|
3455
|
+
authorize(request2) {
|
|
3456
|
+
if (!this.enabled) {
|
|
3457
|
+
return { status: 403, message: 'ta gateway: this gateway is no proxy ("egress" of sandboxes.json is off).' };
|
|
3458
|
+
}
|
|
3459
|
+
const credentials = EgressProxyUtil.credentials(request2.headers["proxy-authorization"]);
|
|
3460
|
+
return credentials ? this.hooks.authorize(credentials.user, credentials.password) : { status: 407, message: "ta gateway: a sandbox of the gateway goes out with the credentials of HTTPS_PROXY." };
|
|
3461
|
+
}
|
|
3462
|
+
async resolve(who, target) {
|
|
3463
|
+
const refusal = EgressProxyUtil.refusal(who.hosts, target);
|
|
3464
|
+
if (refusal) {
|
|
3465
|
+
this.refuse(who.tenantId, target, refusal);
|
|
3466
|
+
return {
|
|
3467
|
+
status: 403,
|
|
3468
|
+
message: refusal === "host" ? `ta gateway: ${target.host} is not among the hosts the gateway lets sandboxes reach; an administrator adds it in the console (Policy).` : `ta gateway: port ${target.port} of ${target.host} is not let out: 80 and 443 only, unless the policy names it (${target.host}:${target.port}).`
|
|
3469
|
+
};
|
|
3470
|
+
}
|
|
3471
|
+
let addresses;
|
|
3472
|
+
try {
|
|
3473
|
+
addresses = isIP(target.host) ? [target.host] : (await lookup(target.host, { all: true, verbatim: true })).map((each) => each.address);
|
|
3474
|
+
} catch (error) {
|
|
3475
|
+
return { status: 502, message: `ta gateway: cannot resolve ${target.host}: ${error.message}` };
|
|
3476
|
+
}
|
|
3477
|
+
const own = EgressProxyUtil.ownAddresses();
|
|
3478
|
+
const address = addresses.find((each) => this.reachable(each, own));
|
|
3479
|
+
if (!address) {
|
|
3480
|
+
this.refuse(who.tenantId, target, "network");
|
|
3481
|
+
return { status: 403, message: `ta gateway: ${target.host} is in a private network or on this machine, which sandboxes do not reach.` };
|
|
3482
|
+
}
|
|
3483
|
+
return EgressProxyUtil.plain(address);
|
|
3484
|
+
}
|
|
3485
|
+
reachable(address, own) {
|
|
3486
|
+
return EgressProxyUtil.reachable(address, this.networks, own);
|
|
3487
|
+
}
|
|
3488
|
+
refuse(tenantId, target, reason) {
|
|
3489
|
+
var _a, _b;
|
|
3490
|
+
const host = PORTS.has(target.port) ? target.host : `${target.host}:${target.port}`;
|
|
3491
|
+
const list = (_a = this.refusals.get(tenantId)) !== null && _a !== undefined ? _a : [];
|
|
3492
|
+
const known = list.find((each) => each.host === host && each.reason === reason);
|
|
3493
|
+
const entry = { host, reason, at: Date.now(), count: ((_b = known === null || known === undefined ? undefined : known.count) !== null && _b !== undefined ? _b : 0) + 1 };
|
|
3494
|
+
this.refusals.set(tenantId, [entry, ...list.filter((each) => each !== known)].slice(0, REFUSALS));
|
|
3495
|
+
}
|
|
3496
|
+
count(tenantId, bytes) {
|
|
3497
|
+
var _a;
|
|
3498
|
+
if (bytes > 0) {
|
|
3499
|
+
this.pending.set(tenantId, ((_a = this.pending.get(tenantId)) !== null && _a !== undefined ? _a : 0) + bytes);
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
reply(socket, status, message) {
|
|
3503
|
+
const body = Buffer.from(`${message}
|
|
3504
|
+
`);
|
|
3505
|
+
const challenge = status === 407 ? `Proxy-Authenticate: Basic realm="ta gateway"\r
|
|
3506
|
+
` : "";
|
|
3507
|
+
socket.end(`HTTP/1.1 ${status} ${STATUS_CODES[status]}\r
|
|
3508
|
+
Content-Type: text/plain; charset=utf-8\r
|
|
3509
|
+
Content-Length: ${body.length}\r
|
|
3510
|
+
Connection: close\r
|
|
3511
|
+
${challenge}\r
|
|
3512
|
+
${body}`);
|
|
3513
|
+
}
|
|
3514
|
+
end(response, status, message) {
|
|
3515
|
+
response.writeHead(status, {
|
|
3516
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
3517
|
+
...status === 407 ? { "Proxy-Authenticate": 'Basic realm="ta gateway"' } : {}
|
|
3518
|
+
});
|
|
3519
|
+
response.end(`${message}
|
|
3520
|
+
`);
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
|
|
3524
|
+
// ../../ta-packages/ta-gateway/esm/node/ta-sandbox.js
|
|
3525
|
+
var TaSandboxUtil;
|
|
3526
|
+
(function(TaSandboxUtil2) {
|
|
3527
|
+
function url(text) {
|
|
3528
|
+
let url2;
|
|
3529
|
+
try {
|
|
3530
|
+
url2 = new URL(text.trim());
|
|
3531
|
+
} catch (_a) {
|
|
3532
|
+
throw new Error(`${text} is not an address: write http(s)://<host>[:<port>].`);
|
|
3533
|
+
}
|
|
3534
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:" || url2.username || url2.password || url2.search || url2.hash) {
|
|
3535
|
+
throw new Error(`${text} is not an address of a Ta service: write http(s)://<host>[:<port>].`);
|
|
3536
|
+
}
|
|
3537
|
+
return `${url2.origin}${url2.pathname.replace(/\/+$/, "")}`;
|
|
3538
|
+
}
|
|
3539
|
+
TaSandboxUtil2.url = url;
|
|
3540
|
+
})(TaSandboxUtil || (TaSandboxUtil = {}));
|
|
2613
3541
|
|
|
2614
3542
|
class TaSandbox {
|
|
2615
3543
|
constructor(id, config) {
|
|
@@ -2933,8 +3861,10 @@ class Environments {
|
|
|
2933
3861
|
var _a2;
|
|
2934
3862
|
var _b;
|
|
2935
3863
|
const { provider, own } = this.provider(tenant);
|
|
2936
|
-
const
|
|
2937
|
-
const
|
|
3864
|
+
const sandbox = EnvironmentsUtil.sandboxTenant(tenant);
|
|
3865
|
+
const fresh = !own && this.envOf ? await provider.state(sandbox).catch(() => "missing") === "missing" : false;
|
|
3866
|
+
const env = own ? undefined : (_a2 = this.envOf) === null || _a2 === undefined ? undefined : _a2.call(this, tenant, provider, fresh);
|
|
3867
|
+
const endpoint = await provider.start({ ...sandbox, ...env ? { env } : {} });
|
|
2938
3868
|
await EnvironmentsUtil.waitReady(endpoint.url, (_b = this.settings.readyTimeoutMs) !== null && _b !== undefined ? _b : provider.readyTimeoutMs);
|
|
2939
3869
|
return endpoint;
|
|
2940
3870
|
})();
|
|
@@ -3144,7 +4074,7 @@ import { readFileSync as readFileSync5 } from "node:fs";
|
|
|
3144
4074
|
import { join as join4 } from "node:path";
|
|
3145
4075
|
|
|
3146
4076
|
// ../../ta-packages/ta-gateway/esm/node/tenant-store.js
|
|
3147
|
-
import { createHash as
|
|
4077
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "node:crypto";
|
|
3148
4078
|
import { chmodSync as chmodSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
3149
4079
|
import { join as join3 } from "node:path";
|
|
3150
4080
|
function writePrivate(file, data) {
|
|
@@ -3156,7 +4086,7 @@ function writePrivate(file, data) {
|
|
|
3156
4086
|
var TenantUtil;
|
|
3157
4087
|
(function(TenantUtil2) {
|
|
3158
4088
|
function id(account) {
|
|
3159
|
-
return
|
|
4089
|
+
return createHash5("sha256").update(account).digest("hex").slice(0, 16);
|
|
3160
4090
|
}
|
|
3161
4091
|
TenantUtil2.id = id;
|
|
3162
4092
|
})(TenantUtil || (TenantUtil = {}));
|
|
@@ -3220,6 +4150,20 @@ class TenantStore {
|
|
|
3220
4150
|
}
|
|
3221
4151
|
return (_a = tenant.modelKey) !== null && _a !== undefined ? _a : this.update(id, { modelKey: `tam-${randomBytes3(24).toString("base64url")}` }).modelKey;
|
|
3222
4152
|
}
|
|
4153
|
+
egressKey(id, renew) {
|
|
4154
|
+
var _a;
|
|
4155
|
+
var _b;
|
|
4156
|
+
const tenant = this.get(id);
|
|
4157
|
+
if (!tenant) {
|
|
4158
|
+
throw new Error(`No tenant ${id}`);
|
|
4159
|
+
}
|
|
4160
|
+
if (tenant.egress && !renew) {
|
|
4161
|
+
return tenant.egress;
|
|
4162
|
+
}
|
|
4163
|
+
const egress = { epoch: ((_b = (_a = tenant.egress) === null || _a === undefined ? undefined : _a.epoch) !== null && _b !== undefined ? _b : 0) + 1, secret: randomBytes3(24).toString("base64url") };
|
|
4164
|
+
this.update(id, { egress });
|
|
4165
|
+
return egress;
|
|
4166
|
+
}
|
|
3223
4167
|
list() {
|
|
3224
4168
|
return readdirSync(this.dir).filter((name) => /^[0-9a-f]{16}\.json$/.test(name)).map((name) => this.get(name.slice(0, -5))).filter((tenant) => tenant !== undefined);
|
|
3225
4169
|
}
|
|
@@ -3336,13 +4280,21 @@ class GatewayPolicy {
|
|
|
3336
4280
|
this.stored = { ...this.stored, defaults: limits };
|
|
3337
4281
|
writePrivate(this.file, this.stored);
|
|
3338
4282
|
}
|
|
4283
|
+
get egressHosts() {
|
|
4284
|
+
var _a;
|
|
4285
|
+
return (_a = this.stored.egressHosts) !== null && _a !== undefined ? _a : [];
|
|
4286
|
+
}
|
|
4287
|
+
setEgressHosts(hosts) {
|
|
4288
|
+
this.stored = { ...this.stored, egressHosts: hosts.length > 0 ? hosts : undefined };
|
|
4289
|
+
writePrivate(this.file, this.stored);
|
|
4290
|
+
}
|
|
3339
4291
|
setRole(account, role) {
|
|
3340
4292
|
var _a;
|
|
3341
4293
|
const admins = ((_a = this.stored.admins) !== null && _a !== undefined ? _a : []).filter((other) => other !== account);
|
|
3342
4294
|
this.stored = { ...this.stored, admins: role === "admin" ? [...admins, account] : admins };
|
|
3343
4295
|
writePrivate(this.file, this.stored);
|
|
3344
4296
|
}
|
|
3345
|
-
view(idleMinutes) {
|
|
4297
|
+
view(idleMinutes, egress = { enabled: false, networks: [] }) {
|
|
3346
4298
|
var _a;
|
|
3347
4299
|
return {
|
|
3348
4300
|
defaults: this.defaults,
|
|
@@ -3350,7 +4302,8 @@ class GatewayPolicy {
|
|
|
3350
4302
|
...this.owners.map((account) => ({ account, role: "owner" })),
|
|
3351
4303
|
...((_a = this.stored.admins) !== null && _a !== undefined ? _a : []).filter((account) => this.role(account) === "admin").map((account) => ({ account, role: "admin" }))
|
|
3352
4304
|
],
|
|
3353
|
-
idleMinutes
|
|
4305
|
+
idleMinutes,
|
|
4306
|
+
egress: { enabled: egress.enabled, hosts: this.egressHosts, networks: egress.networks }
|
|
3354
4307
|
};
|
|
3355
4308
|
}
|
|
3356
4309
|
read() {
|
|
@@ -3540,9 +4493,25 @@ class GatewayQuotas {
|
|
|
3540
4493
|
tokens: { used: month.tokens, cost: month.cost, limit: metered ? limits.monthlyTokens : undefined, metered },
|
|
3541
4494
|
promptsPerMinute: limits.promptsPerMinute,
|
|
3542
4495
|
connections: limits.connections,
|
|
3543
|
-
blocked: this.blocked(tenant, now)
|
|
4496
|
+
blocked: this.blocked(tenant, now),
|
|
4497
|
+
...this.egressState(tenant, meter)
|
|
3544
4498
|
};
|
|
3545
4499
|
}
|
|
4500
|
+
egressState(tenant, meter) {
|
|
4501
|
+
var _a;
|
|
4502
|
+
var _b;
|
|
4503
|
+
const refused = (_a = this.egressOf) === null || _a === undefined ? undefined : _a.call(this, tenant);
|
|
4504
|
+
return refused ? { egress: { bytes: (_b = meter.egressBytes) !== null && _b !== undefined ? _b : 0, refused } } : {};
|
|
4505
|
+
}
|
|
4506
|
+
addEgress(tenantId, bytes, now = Date.now()) {
|
|
4507
|
+
var _a;
|
|
4508
|
+
const tenant = this.tenants.get(tenantId);
|
|
4509
|
+
if (!tenant || bytes <= 0) {
|
|
4510
|
+
return;
|
|
4511
|
+
}
|
|
4512
|
+
const meter = this.meter(tenant, now);
|
|
4513
|
+
this.tenants.update(tenantId, { meter: { ...meter, egressBytes: ((_a = meter.egressBytes) !== null && _a !== undefined ? _a : 0) + bytes } });
|
|
4514
|
+
}
|
|
3546
4515
|
refuseModels(tenant, now = Date.now()) {
|
|
3547
4516
|
var _a;
|
|
3548
4517
|
if (this.role(tenant) === "owner") {
|
|
@@ -3610,15 +4579,15 @@ class GatewayQuotas {
|
|
|
3610
4579
|
// ../../ta-packages/ta-protocol/esm/common/redactor.js
|
|
3611
4580
|
var REDACTED = "[redacted]";
|
|
3612
4581
|
var WHOLE = [
|
|
3613
|
-
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
|
|
3614
|
-
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
|
|
3615
|
-
/\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
|
|
3616
|
-
/\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
|
|
3617
|
-
/\bglpat-[A-Za-z0-9_-]{20,}\b/g,
|
|
3618
|
-
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
3619
|
-
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
3620
|
-
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
3621
|
-
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g
|
|
4582
|
+
["PRIVATE_KEY", /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
|
|
4583
|
+
["API_KEY", /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g],
|
|
4584
|
+
["GITHUB_TOKEN", /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g],
|
|
4585
|
+
["GITHUB_TOKEN", /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g],
|
|
4586
|
+
["GITLAB_TOKEN", /\bglpat-[A-Za-z0-9_-]{20,}\b/g],
|
|
4587
|
+
["SLACK_TOKEN", /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g],
|
|
4588
|
+
["AWS_ACCESS_KEY_ID", /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
|
|
4589
|
+
["GOOGLE_API_KEY", /\bAIza[0-9A-Za-z_-]{35}\b/g],
|
|
4590
|
+
["JWT", /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g]
|
|
3622
4591
|
];
|
|
3623
4592
|
var NAMED = [
|
|
3624
4593
|
/(\bBearer\s+)[A-Za-z0-9._~+/-]{16,}=*/gi,
|
|
@@ -3632,7 +4601,7 @@ class Redactor {
|
|
|
3632
4601
|
}
|
|
3633
4602
|
text(text) {
|
|
3634
4603
|
let out = text;
|
|
3635
|
-
for (const pattern of WHOLE) {
|
|
4604
|
+
for (const [, pattern] of WHOLE) {
|
|
3636
4605
|
out = out.replace(pattern, () => this.hide());
|
|
3637
4606
|
}
|
|
3638
4607
|
out = out.replace(NAMED[0], (_match, before) => before + this.hide());
|
|
@@ -3652,6 +4621,39 @@ class Redactor {
|
|
|
3652
4621
|
}
|
|
3653
4622
|
return value;
|
|
3654
4623
|
}
|
|
4624
|
+
static spans(text) {
|
|
4625
|
+
var _a;
|
|
4626
|
+
var _b;
|
|
4627
|
+
const found = [];
|
|
4628
|
+
for (const [kind, pattern] of WHOLE) {
|
|
4629
|
+
for (const match of text.matchAll(pattern)) {
|
|
4630
|
+
found.push({ start: match.index, end: match.index + match[0].length, kind });
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
4633
|
+
for (const match of text.matchAll(NAMED[0])) {
|
|
4634
|
+
found.push({ start: match.index + match[1].length, end: match.index + match[0].length, kind: "BEARER_TOKEN" });
|
|
4635
|
+
}
|
|
4636
|
+
for (const match of text.matchAll(NAMED[1])) {
|
|
4637
|
+
if (!Redactor.placeholder(match[2])) {
|
|
4638
|
+
const start = match.index + match[1].length;
|
|
4639
|
+
const name = (_b = (_a = /[A-Za-z0-9_.-]+/.exec(match[1])) === null || _a === undefined ? undefined : _a[0]) !== null && _b !== undefined ? _b : "SECRET";
|
|
4640
|
+
found.push({ start, end: start + match[2].length, kind: name.replace(/[^A-Za-z0-9]+/g, "_").toUpperCase() });
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
for (const match of text.matchAll(NAMED[2])) {
|
|
4644
|
+
const start = match.index + match[1].length;
|
|
4645
|
+
found.push({ start, end: start + match[2].length, kind: "URL_PASSWORD" });
|
|
4646
|
+
}
|
|
4647
|
+
found.sort((a, b) => a.start - b.start || b.end - a.end);
|
|
4648
|
+
const spans = [];
|
|
4649
|
+
for (const span of found) {
|
|
4650
|
+
const last = spans.at(-1);
|
|
4651
|
+
if (!last || span.start >= last.end) {
|
|
4652
|
+
spans.push(span);
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
return spans;
|
|
4656
|
+
}
|
|
3655
4657
|
static cut(text, max) {
|
|
3656
4658
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
3657
4659
|
}
|
|
@@ -3664,46 +4666,207 @@ class Redactor {
|
|
|
3664
4666
|
}
|
|
3665
4667
|
}
|
|
3666
4668
|
|
|
3667
|
-
// ../../ta-packages/ta-gateway/esm/node/
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
4669
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-service-util.js
|
|
4670
|
+
class GatewayCallError extends Error {
|
|
4671
|
+
constructor(message, code, hint) {
|
|
4672
|
+
super(message);
|
|
4673
|
+
this.code = code;
|
|
4674
|
+
this.hint = hint;
|
|
4675
|
+
}
|
|
3673
4676
|
}
|
|
3674
|
-
var
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
4677
|
+
var GatewayServiceUtil;
|
|
4678
|
+
(function(GatewayServiceUtil2) {
|
|
4679
|
+
GatewayServiceUtil2.DEFAULT_LOG_LINES = 200;
|
|
4680
|
+
GatewayServiceUtil2.MAX_LOG_LINES = 2000;
|
|
4681
|
+
GatewayServiceUtil2.RULES = {
|
|
4682
|
+
TaGatewayServer: {
|
|
4683
|
+
getGateway: "anyone",
|
|
4684
|
+
setEnvironment: "anyone",
|
|
4685
|
+
restartEnvironment: "anyone",
|
|
4686
|
+
listTenants: "admin",
|
|
4687
|
+
getConsole: "admin",
|
|
4688
|
+
getTenantAgents: "admin",
|
|
4689
|
+
getAgentActivity: "admin",
|
|
4690
|
+
getTenantLogs: "admin",
|
|
4691
|
+
getUsageTrend: "admin",
|
|
4692
|
+
getPolicy: "admin",
|
|
4693
|
+
getAudit: "admin",
|
|
4694
|
+
startTenant: "admin",
|
|
4695
|
+
stopTenant: "admin",
|
|
4696
|
+
restartTenant: "admin",
|
|
4697
|
+
createSignInLink: "admin",
|
|
4698
|
+
setTenantLimits: "admin",
|
|
4699
|
+
grantMinutes: "admin",
|
|
4700
|
+
setSuspended: "admin",
|
|
4701
|
+
setDefaultLimits: "owner",
|
|
4702
|
+
setRole: "owner",
|
|
4703
|
+
setEgressHosts: "owner",
|
|
4704
|
+
createAccessToken: "anyone"
|
|
4705
|
+
},
|
|
4706
|
+
TaAccessServer: {
|
|
4707
|
+
getAccess: "anyone",
|
|
4708
|
+
signOut: "anyone",
|
|
4709
|
+
bindUrl: "admin",
|
|
4710
|
+
allow: "admin",
|
|
4711
|
+
dismiss: "admin",
|
|
4712
|
+
disallow: "admin"
|
|
3704
4713
|
}
|
|
3705
|
-
|
|
3706
|
-
|
|
4714
|
+
};
|
|
4715
|
+
GatewayServiceUtil2.AUDITED = new Set([
|
|
4716
|
+
"startTenant",
|
|
4717
|
+
"stopTenant",
|
|
4718
|
+
"restartTenant",
|
|
4719
|
+
"getTenantLogs",
|
|
4720
|
+
"getAgentActivity",
|
|
4721
|
+
"createSignInLink",
|
|
4722
|
+
"setTenantLimits",
|
|
4723
|
+
"grantMinutes",
|
|
4724
|
+
"setSuspended",
|
|
4725
|
+
"setDefaultLimits",
|
|
4726
|
+
"setRole",
|
|
4727
|
+
"setEgressHosts",
|
|
4728
|
+
"allow",
|
|
4729
|
+
"dismiss",
|
|
4730
|
+
"disallow"
|
|
4731
|
+
]);
|
|
4732
|
+
const BY_SERVICE = new Map(Object.entries(GatewayServiceUtil2.RULES).map(([service, rules]) => [service, new Map(Object.entries(rules))]));
|
|
4733
|
+
function need(service, name) {
|
|
4734
|
+
var _a;
|
|
4735
|
+
return (_a = BY_SERVICE.get(service)) === null || _a === undefined ? undefined : _a.get(name);
|
|
4736
|
+
}
|
|
4737
|
+
GatewayServiceUtil2.need = need;
|
|
4738
|
+
function allowed(role, need2) {
|
|
4739
|
+
return need2 === "anyone" || GatewayPolicyUtil.rank(role) >= GatewayPolicyUtil.rank(need2);
|
|
4740
|
+
}
|
|
4741
|
+
GatewayServiceUtil2.allowed = allowed;
|
|
4742
|
+
function lines(value) {
|
|
4743
|
+
const count = Math.floor(Number(value !== null && value !== undefined ? value : GatewayServiceUtil2.DEFAULT_LOG_LINES));
|
|
4744
|
+
return Number.isFinite(count) && count > 0 ? Math.min(count, GatewayServiceUtil2.MAX_LOG_LINES) : GatewayServiceUtil2.DEFAULT_LOG_LINES;
|
|
4745
|
+
}
|
|
4746
|
+
GatewayServiceUtil2.lines = lines;
|
|
4747
|
+
function days(value) {
|
|
4748
|
+
const count = Math.floor(Number(value !== null && value !== undefined ? value : 7));
|
|
4749
|
+
return Number.isFinite(count) ? Math.min(31, Math.max(1, count)) : 7;
|
|
4750
|
+
}
|
|
4751
|
+
GatewayServiceUtil2.days = days;
|
|
4752
|
+
GatewayServiceUtil2.SERVICES = Object.keys(GatewayServiceUtil2.RULES);
|
|
4753
|
+
function owns(method) {
|
|
4754
|
+
return typeof method === "string" && GatewayServiceUtil2.SERVICES.includes(method.split("/")[0]);
|
|
4755
|
+
}
|
|
4756
|
+
GatewayServiceUtil2.owns = owns;
|
|
4757
|
+
function mayOwn(text) {
|
|
4758
|
+
return GatewayServiceUtil2.SERVICES.some((service) => text.includes(`"${service}/`));
|
|
4759
|
+
}
|
|
4760
|
+
GatewayServiceUtil2.mayOwn = mayOwn;
|
|
4761
|
+
GatewayServiceUtil2.PROMPTS = ["TaServer/prompt", "TaServer/steer", "TaServer/followUp"];
|
|
4762
|
+
function mayPrompt(text) {
|
|
4763
|
+
return GatewayServiceUtil2.PROMPTS.some((method) => text.includes(`"${method}"`));
|
|
4764
|
+
}
|
|
4765
|
+
GatewayServiceUtil2.mayPrompt = mayPrompt;
|
|
4766
|
+
function error(id, message, code, hint) {
|
|
4767
|
+
return JSON.stringify({ jsonrpc: "2.0", id, error: { code: TA_RPC_ERROR_CODE, message, data: { kind: "application", data: { code, hint } } } });
|
|
4768
|
+
}
|
|
4769
|
+
GatewayServiceUtil2.error = error;
|
|
4770
|
+
function result(id, result2) {
|
|
4771
|
+
return JSON.stringify({ jsonrpc: "2.0", id, result: result2 !== null && result2 !== undefined ? result2 : null });
|
|
4772
|
+
}
|
|
4773
|
+
GatewayServiceUtil2.result = result;
|
|
4774
|
+
function invalid(message, hint) {
|
|
4775
|
+
return new GatewayCallError(message, TaErrorCode.INVALID_ARGUMENT, hint);
|
|
4776
|
+
}
|
|
4777
|
+
function forbidden(message, hint) {
|
|
4778
|
+
return new GatewayCallError(message, TaErrorCode.FORBIDDEN, hint);
|
|
4779
|
+
}
|
|
4780
|
+
GatewayServiceUtil2.forbidden = forbidden;
|
|
4781
|
+
function choice(value, own, providers) {
|
|
4782
|
+
var _a;
|
|
4783
|
+
const given = value !== null && value !== undefined ? value : {};
|
|
4784
|
+
if (typeof given.provider === "string") {
|
|
4785
|
+
if (!providers.includes(given.provider)) {
|
|
4786
|
+
throw invalid(`The gateway has no provider ${given.provider} for you.`, "Pick one of the options of getGateway.");
|
|
4787
|
+
}
|
|
4788
|
+
return { provider: given.provider };
|
|
4789
|
+
}
|
|
4790
|
+
if (given.type === "ta") {
|
|
4791
|
+
if (!own) {
|
|
4792
|
+
throw invalid("This gateway runs your Ta in its own sandboxes only.", "Pick one of the options of getGateway.");
|
|
4793
|
+
}
|
|
4794
|
+
let url;
|
|
4795
|
+
try {
|
|
4796
|
+
url = TaSandboxUtil.url(String((_a = given.url) !== null && _a !== undefined ? _a : ""));
|
|
4797
|
+
} catch (error2) {
|
|
4798
|
+
throw invalid(error2.message, "Write the address its Ta service is reached at, such as https://ta.example.com.");
|
|
4799
|
+
}
|
|
4800
|
+
if (typeof given.token !== "string" || !given.token.trim()) {
|
|
4801
|
+
throw invalid("A Ta service of your own is reached with its access token.", "Copy it from ~/.ta/agent/serve.json there, or the link ta serve printed.");
|
|
4802
|
+
}
|
|
4803
|
+
return { type: "ta", url, token: given.token.trim(), name: typeof given.name === "string" && given.name.trim() ? given.name.trim() : undefined };
|
|
4804
|
+
}
|
|
4805
|
+
throw invalid("No environment was named.", 'Pass { provider } or { type: "ta", url, token }.');
|
|
4806
|
+
}
|
|
4807
|
+
GatewayServiceUtil2.choice = choice;
|
|
4808
|
+
function detail(method, params) {
|
|
4809
|
+
const [, second] = params;
|
|
4810
|
+
switch (method) {
|
|
4811
|
+
case "setTenantLimits":
|
|
4812
|
+
case "setDefaultLimits":
|
|
4813
|
+
return JSON.stringify(method === "setDefaultLimits" ? params[0] : second);
|
|
4814
|
+
case "grantMinutes":
|
|
4815
|
+
case "getTenantLogs":
|
|
4816
|
+
return String(second !== null && second !== undefined ? second : "");
|
|
4817
|
+
case "setSuspended":
|
|
4818
|
+
return second ? "suspended" : "let go";
|
|
4819
|
+
case "setRole":
|
|
4820
|
+
return String(second);
|
|
4821
|
+
case "setEgressHosts":
|
|
4822
|
+
return Array.isArray(params[0]) ? params[0].join(", ") || "any public host" : undefined;
|
|
4823
|
+
default:
|
|
4824
|
+
return;
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
GatewayServiceUtil2.detail = detail;
|
|
4828
|
+
})(GatewayServiceUtil || (GatewayServiceUtil = {}));
|
|
4829
|
+
|
|
4830
|
+
// ../../ta-packages/ta-gateway/esm/node/model-proxy.js
|
|
4831
|
+
import { createHash as createHash6, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
4832
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "node:fs";
|
|
4833
|
+
import { join as join6 } from "node:path";
|
|
4834
|
+
|
|
4835
|
+
class ModelConfigError extends Error {
|
|
4836
|
+
}
|
|
4837
|
+
var MAX_BODY = 32 * 1024 * 1024;
|
|
4838
|
+
var MAX_READ = 8 * 1024 * 1024;
|
|
4839
|
+
var DROPPED_REQUEST = new Set([
|
|
4840
|
+
"host",
|
|
4841
|
+
"authorization",
|
|
4842
|
+
"x-api-key",
|
|
4843
|
+
"x-goog-api-key",
|
|
4844
|
+
"api-key",
|
|
4845
|
+
"cookie",
|
|
4846
|
+
"connection",
|
|
4847
|
+
"content-length",
|
|
4848
|
+
"accept-encoding",
|
|
4849
|
+
"transfer-encoding",
|
|
4850
|
+
"keep-alive",
|
|
4851
|
+
"upgrade",
|
|
4852
|
+
"proxy-authorization",
|
|
4853
|
+
"x-forwarded-for",
|
|
4854
|
+
"x-forwarded-proto",
|
|
4855
|
+
"x-forwarded-host"
|
|
4856
|
+
]);
|
|
4857
|
+
var DROPPED_RESPONSE = new Set(["content-encoding", "content-length", "transfer-encoding", "connection", "keep-alive", "set-cookie"]);
|
|
4858
|
+
var ModelProxyUtil;
|
|
4859
|
+
(function(ModelProxyUtil2) {
|
|
4860
|
+
ModelProxyUtil2.PATH = "/api/models";
|
|
4861
|
+
const ID = /^[a-z0-9][a-z0-9._-]{0,63}$/i;
|
|
4862
|
+
function read(dir) {
|
|
4863
|
+
var _a;
|
|
4864
|
+
const file = join6(dir, "models.json");
|
|
4865
|
+
if (!existsSync3(file)) {
|
|
4866
|
+
return {};
|
|
4867
|
+
}
|
|
4868
|
+
let config;
|
|
4869
|
+
try {
|
|
3707
4870
|
config = JSON.parse(readFileSync7(file, "utf8"));
|
|
3708
4871
|
} catch (error2) {
|
|
3709
4872
|
throw new ModelConfigError(`${file} is not JSON: ${error2.message}`);
|
|
@@ -3887,7 +5050,7 @@ var ModelProxyUtil;
|
|
|
3887
5050
|
}
|
|
3888
5051
|
ModelProxyUtil2.error = error;
|
|
3889
5052
|
function sameKey(given, known) {
|
|
3890
|
-
return
|
|
5053
|
+
return timingSafeEqual2(createHash6("sha256").update(given).digest(), createHash6("sha256").update(known).digest());
|
|
3891
5054
|
}
|
|
3892
5055
|
ModelProxyUtil2.sameKey = sameKey;
|
|
3893
5056
|
})(ModelProxyUtil || (ModelProxyUtil = {}));
|
|
@@ -3980,246 +5143,92 @@ class ModelProxy {
|
|
|
3980
5143
|
const decoder = new TextDecoder;
|
|
3981
5144
|
const reader = (_a = upstream.body) === null || _a === undefined ? undefined : _a.getReader();
|
|
3982
5145
|
try {
|
|
3983
|
-
while (reader) {
|
|
3984
|
-
const { done, value } = await reader.read();
|
|
3985
|
-
if (done) {
|
|
3986
|
-
break;
|
|
3987
|
-
}
|
|
3988
|
-
if (!response.write(value) && !await this.drained(response)) {
|
|
3989
|
-
break;
|
|
3990
|
-
}
|
|
3991
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
3992
|
-
if (stream) {
|
|
3993
|
-
text += chunk;
|
|
3994
|
-
const lines = text.split(`
|
|
3995
|
-
`);
|
|
3996
|
-
text = (_f = lines.pop()) !== null && _f !== undefined ? _f : "";
|
|
3997
|
-
for (const line of lines) {
|
|
3998
|
-
usage = ModelProxyUtil.merge(usage, this.event(line));
|
|
3999
|
-
}
|
|
4000
|
-
} else if (text.length < MAX_READ) {
|
|
4001
|
-
text += chunk;
|
|
4002
|
-
}
|
|
4003
|
-
}
|
|
4004
|
-
if (stream) {
|
|
4005
|
-
usage = ModelProxyUtil.merge(usage, this.event(text));
|
|
4006
|
-
} else if (upstream.ok) {
|
|
4007
|
-
try {
|
|
4008
|
-
usage = ModelProxyUtil.usageOf(JSON.parse(text));
|
|
4009
|
-
} catch (_g) {}
|
|
4010
|
-
}
|
|
4011
|
-
response.end();
|
|
4012
|
-
} catch (_h) {
|
|
4013
|
-
response.destroy();
|
|
4014
|
-
} finally {
|
|
4015
|
-
if (usage && ModelProxyUtil.total(usage) > 0) {
|
|
4016
|
-
const price = (_b = provider.models.find((each) => each.id === model)) === null || _b === undefined ? undefined : _b.cost;
|
|
4017
|
-
this.hooks.record(tenant.id, usage, ModelProxyUtil.cost(usage, price));
|
|
4018
|
-
}
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
drained(response) {
|
|
4022
|
-
if (response.destroyed) {
|
|
4023
|
-
return Promise.resolve(false);
|
|
4024
|
-
}
|
|
4025
|
-
return new Promise((resolve) => {
|
|
4026
|
-
const done = (drained) => {
|
|
4027
|
-
response.off("drain", onDrain);
|
|
4028
|
-
response.off("close", onClose);
|
|
4029
|
-
resolve(drained);
|
|
4030
|
-
};
|
|
4031
|
-
const onDrain = () => done(true);
|
|
4032
|
-
const onClose = () => done(false);
|
|
4033
|
-
response.on("drain", onDrain);
|
|
4034
|
-
response.on("close", onClose);
|
|
4035
|
-
});
|
|
4036
|
-
}
|
|
4037
|
-
event(line) {
|
|
4038
|
-
const trimmed = line.trim();
|
|
4039
|
-
if (!trimmed.startsWith("data:")) {
|
|
4040
|
-
return;
|
|
4041
|
-
}
|
|
4042
|
-
try {
|
|
4043
|
-
return ModelProxyUtil.usageOf(JSON.parse(trimmed.slice(5)));
|
|
4044
|
-
} catch (_a) {
|
|
4045
|
-
return;
|
|
4046
|
-
}
|
|
4047
|
-
}
|
|
4048
|
-
async body(request2) {
|
|
4049
|
-
const chunks = [];
|
|
4050
|
-
let size = 0;
|
|
4051
|
-
for await (const chunk of request2) {
|
|
4052
|
-
size += chunk.length;
|
|
4053
|
-
if (size > MAX_BODY) {
|
|
4054
|
-
return;
|
|
4055
|
-
}
|
|
4056
|
-
chunks.push(chunk);
|
|
4057
|
-
}
|
|
4058
|
-
return Buffer.concat(chunks);
|
|
4059
|
-
}
|
|
4060
|
-
}
|
|
4061
|
-
|
|
4062
|
-
// ../../ta-packages/ta-gateway/esm/node/gateway-service.js
|
|
4063
|
-
class GatewayCallError extends Error {
|
|
4064
|
-
constructor(message, code, hint) {
|
|
4065
|
-
super(message);
|
|
4066
|
-
this.code = code;
|
|
4067
|
-
this.hint = hint;
|
|
4068
|
-
}
|
|
4069
|
-
}
|
|
4070
|
-
var DAY2 = 24 * 3600000;
|
|
4071
|
-
var GatewayServiceUtil;
|
|
4072
|
-
(function(GatewayServiceUtil2) {
|
|
4073
|
-
GatewayServiceUtil2.DEFAULT_LOG_LINES = 200;
|
|
4074
|
-
GatewayServiceUtil2.MAX_LOG_LINES = 2000;
|
|
4075
|
-
GatewayServiceUtil2.RULES = {
|
|
4076
|
-
TaGatewayServer: {
|
|
4077
|
-
getGateway: "anyone",
|
|
4078
|
-
setEnvironment: "anyone",
|
|
4079
|
-
restartEnvironment: "anyone",
|
|
4080
|
-
listTenants: "admin",
|
|
4081
|
-
getConsole: "admin",
|
|
4082
|
-
getTenantAgents: "admin",
|
|
4083
|
-
getAgentActivity: "admin",
|
|
4084
|
-
getTenantLogs: "admin",
|
|
4085
|
-
getUsageTrend: "admin",
|
|
4086
|
-
getPolicy: "admin",
|
|
4087
|
-
getAudit: "admin",
|
|
4088
|
-
startTenant: "admin",
|
|
4089
|
-
stopTenant: "admin",
|
|
4090
|
-
restartTenant: "admin",
|
|
4091
|
-
createSignInLink: "admin",
|
|
4092
|
-
setTenantLimits: "admin",
|
|
4093
|
-
grantMinutes: "admin",
|
|
4094
|
-
setSuspended: "admin",
|
|
4095
|
-
setDefaultLimits: "owner",
|
|
4096
|
-
setRole: "owner",
|
|
4097
|
-
createAccessToken: "anyone"
|
|
4098
|
-
},
|
|
4099
|
-
TaAccessServer: {
|
|
4100
|
-
getAccess: "anyone",
|
|
4101
|
-
signOut: "anyone",
|
|
4102
|
-
bindUrl: "admin",
|
|
4103
|
-
allow: "admin",
|
|
4104
|
-
dismiss: "admin",
|
|
4105
|
-
disallow: "admin"
|
|
4106
|
-
}
|
|
4107
|
-
};
|
|
4108
|
-
GatewayServiceUtil2.AUDITED = new Set([
|
|
4109
|
-
"startTenant",
|
|
4110
|
-
"stopTenant",
|
|
4111
|
-
"restartTenant",
|
|
4112
|
-
"getTenantLogs",
|
|
4113
|
-
"getAgentActivity",
|
|
4114
|
-
"createSignInLink",
|
|
4115
|
-
"setTenantLimits",
|
|
4116
|
-
"grantMinutes",
|
|
4117
|
-
"setSuspended",
|
|
4118
|
-
"setDefaultLimits",
|
|
4119
|
-
"setRole",
|
|
4120
|
-
"allow",
|
|
4121
|
-
"dismiss",
|
|
4122
|
-
"disallow"
|
|
4123
|
-
]);
|
|
4124
|
-
const BY_SERVICE = new Map(Object.entries(GatewayServiceUtil2.RULES).map(([service, rules]) => [service, new Map(Object.entries(rules))]));
|
|
4125
|
-
function need(service, name) {
|
|
4126
|
-
var _a;
|
|
4127
|
-
return (_a = BY_SERVICE.get(service)) === null || _a === undefined ? undefined : _a.get(name);
|
|
4128
|
-
}
|
|
4129
|
-
GatewayServiceUtil2.need = need;
|
|
4130
|
-
function allowed(role, need2) {
|
|
4131
|
-
return need2 === "anyone" || GatewayPolicyUtil.rank(role) >= GatewayPolicyUtil.rank(need2);
|
|
4132
|
-
}
|
|
4133
|
-
GatewayServiceUtil2.allowed = allowed;
|
|
4134
|
-
function lines(value) {
|
|
4135
|
-
const count = Math.floor(Number(value !== null && value !== undefined ? value : GatewayServiceUtil2.DEFAULT_LOG_LINES));
|
|
4136
|
-
return Number.isFinite(count) && count > 0 ? Math.min(count, GatewayServiceUtil2.MAX_LOG_LINES) : GatewayServiceUtil2.DEFAULT_LOG_LINES;
|
|
4137
|
-
}
|
|
4138
|
-
GatewayServiceUtil2.lines = lines;
|
|
4139
|
-
function days(value) {
|
|
4140
|
-
const count = Math.floor(Number(value !== null && value !== undefined ? value : 7));
|
|
4141
|
-
return Number.isFinite(count) ? Math.min(31, Math.max(1, count)) : 7;
|
|
4142
|
-
}
|
|
4143
|
-
GatewayServiceUtil2.days = days;
|
|
4144
|
-
GatewayServiceUtil2.SERVICES = Object.keys(GatewayServiceUtil2.RULES);
|
|
4145
|
-
function owns(method) {
|
|
4146
|
-
return typeof method === "string" && GatewayServiceUtil2.SERVICES.includes(method.split("/")[0]);
|
|
4147
|
-
}
|
|
4148
|
-
GatewayServiceUtil2.owns = owns;
|
|
4149
|
-
function mayOwn(text) {
|
|
4150
|
-
return GatewayServiceUtil2.SERVICES.some((service) => text.includes(`"${service}/`));
|
|
4151
|
-
}
|
|
4152
|
-
GatewayServiceUtil2.mayOwn = mayOwn;
|
|
4153
|
-
GatewayServiceUtil2.PROMPTS = ["TaServer/prompt", "TaServer/steer", "TaServer/followUp"];
|
|
4154
|
-
function mayPrompt(text) {
|
|
4155
|
-
return GatewayServiceUtil2.PROMPTS.some((method) => text.includes(`"${method}"`));
|
|
4156
|
-
}
|
|
4157
|
-
GatewayServiceUtil2.mayPrompt = mayPrompt;
|
|
4158
|
-
function error(id, message, code, hint) {
|
|
4159
|
-
return JSON.stringify({ jsonrpc: "2.0", id, error: { code: TA_RPC_ERROR_CODE, message, data: { kind: "application", data: { code, hint } } } });
|
|
4160
|
-
}
|
|
4161
|
-
GatewayServiceUtil2.error = error;
|
|
4162
|
-
function result(id, result2) {
|
|
4163
|
-
return JSON.stringify({ jsonrpc: "2.0", id, result: result2 !== null && result2 !== undefined ? result2 : null });
|
|
4164
|
-
}
|
|
4165
|
-
GatewayServiceUtil2.result = result;
|
|
4166
|
-
function invalid(message, hint) {
|
|
4167
|
-
return new GatewayCallError(message, TaErrorCode.INVALID_ARGUMENT, hint);
|
|
4168
|
-
}
|
|
4169
|
-
function forbidden(message, hint) {
|
|
4170
|
-
return new GatewayCallError(message, TaErrorCode.FORBIDDEN, hint);
|
|
4171
|
-
}
|
|
4172
|
-
GatewayServiceUtil2.forbidden = forbidden;
|
|
4173
|
-
function choice(value, own, providers) {
|
|
4174
|
-
var _a;
|
|
4175
|
-
const given = value !== null && value !== undefined ? value : {};
|
|
4176
|
-
if (typeof given.provider === "string") {
|
|
4177
|
-
if (!providers.includes(given.provider)) {
|
|
4178
|
-
throw invalid(`The gateway has no provider ${given.provider} for you.`, "Pick one of the options of getGateway.");
|
|
4179
|
-
}
|
|
4180
|
-
return { provider: given.provider };
|
|
4181
|
-
}
|
|
4182
|
-
if (given.type === "ta") {
|
|
4183
|
-
if (!own) {
|
|
4184
|
-
throw invalid("This gateway runs your Ta in its own sandboxes only.", "Pick one of the options of getGateway.");
|
|
5146
|
+
while (reader) {
|
|
5147
|
+
const { done, value } = await reader.read();
|
|
5148
|
+
if (done) {
|
|
5149
|
+
break;
|
|
5150
|
+
}
|
|
5151
|
+
if (!response.write(value) && !await this.drained(response)) {
|
|
5152
|
+
break;
|
|
5153
|
+
}
|
|
5154
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
5155
|
+
if (stream) {
|
|
5156
|
+
text += chunk;
|
|
5157
|
+
const lines = text.split(`
|
|
5158
|
+
`);
|
|
5159
|
+
text = (_f = lines.pop()) !== null && _f !== undefined ? _f : "";
|
|
5160
|
+
for (const line of lines) {
|
|
5161
|
+
usage = ModelProxyUtil.merge(usage, this.event(line));
|
|
5162
|
+
}
|
|
5163
|
+
} else if (text.length < MAX_READ) {
|
|
5164
|
+
text += chunk;
|
|
5165
|
+
}
|
|
4185
5166
|
}
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
5167
|
+
if (stream) {
|
|
5168
|
+
usage = ModelProxyUtil.merge(usage, this.event(text));
|
|
5169
|
+
} else if (upstream.ok) {
|
|
5170
|
+
try {
|
|
5171
|
+
usage = ModelProxyUtil.usageOf(JSON.parse(text));
|
|
5172
|
+
} catch (_g) {}
|
|
4191
5173
|
}
|
|
4192
|
-
|
|
4193
|
-
|
|
5174
|
+
response.end();
|
|
5175
|
+
} catch (_h) {
|
|
5176
|
+
response.destroy();
|
|
5177
|
+
} finally {
|
|
5178
|
+
if (usage && ModelProxyUtil.total(usage) > 0) {
|
|
5179
|
+
const price = (_b = provider.models.find((each) => each.id === model)) === null || _b === undefined ? undefined : _b.cost;
|
|
5180
|
+
this.hooks.record(tenant.id, usage, ModelProxyUtil.cost(usage, price));
|
|
4194
5181
|
}
|
|
4195
|
-
return { type: "ta", url, token: given.token.trim(), name: typeof given.name === "string" && given.name.trim() ? given.name.trim() : undefined };
|
|
4196
5182
|
}
|
|
4197
|
-
throw invalid("No environment was named.", 'Pass { provider } or { type: "ta", url, token }.');
|
|
4198
5183
|
}
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
5184
|
+
drained(response) {
|
|
5185
|
+
if (response.destroyed) {
|
|
5186
|
+
return Promise.resolve(false);
|
|
5187
|
+
}
|
|
5188
|
+
return new Promise((resolve) => {
|
|
5189
|
+
const done = (drained) => {
|
|
5190
|
+
response.off("drain", onDrain);
|
|
5191
|
+
response.off("close", onClose);
|
|
5192
|
+
resolve(drained);
|
|
5193
|
+
};
|
|
5194
|
+
const onDrain = () => done(true);
|
|
5195
|
+
const onClose = () => done(false);
|
|
5196
|
+
response.on("drain", onDrain);
|
|
5197
|
+
response.on("close", onClose);
|
|
5198
|
+
});
|
|
5199
|
+
}
|
|
5200
|
+
event(line) {
|
|
5201
|
+
const trimmed = line.trim();
|
|
5202
|
+
if (!trimmed.startsWith("data:")) {
|
|
5203
|
+
return;
|
|
5204
|
+
}
|
|
5205
|
+
try {
|
|
5206
|
+
return ModelProxyUtil.usageOf(JSON.parse(trimmed.slice(5)));
|
|
5207
|
+
} catch (_a) {
|
|
5208
|
+
return;
|
|
5209
|
+
}
|
|
5210
|
+
}
|
|
5211
|
+
async body(request2) {
|
|
5212
|
+
const chunks = [];
|
|
5213
|
+
let size = 0;
|
|
5214
|
+
for await (const chunk of request2) {
|
|
5215
|
+
size += chunk.length;
|
|
5216
|
+
if (size > MAX_BODY) {
|
|
4214
5217
|
return;
|
|
5218
|
+
}
|
|
5219
|
+
chunks.push(chunk);
|
|
4215
5220
|
}
|
|
5221
|
+
return Buffer.concat(chunks);
|
|
4216
5222
|
}
|
|
4217
|
-
|
|
4218
|
-
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-service.js
|
|
5226
|
+
var DAY2 = 24 * 3600000;
|
|
4219
5227
|
|
|
4220
5228
|
class GatewayService {
|
|
4221
5229
|
constructor(parts) {
|
|
4222
5230
|
this.models = parts.models;
|
|
5231
|
+
this.egress = parts.egress;
|
|
4223
5232
|
this.flow = parts.flow;
|
|
4224
5233
|
this.tenants = parts.tenants;
|
|
4225
5234
|
this.environments = parts.environments;
|
|
@@ -4268,6 +5277,7 @@ class GatewayService {
|
|
|
4268
5277
|
setSuspended: () => this.setSuspended(caller, first, second),
|
|
4269
5278
|
setDefaultLimits: () => this.setDefaultLimits(first),
|
|
4270
5279
|
setRole: () => this.setRole(caller, first, second),
|
|
5280
|
+
setEgressHosts: () => this.setEgressHosts(first),
|
|
4271
5281
|
createAccessToken: () => this.accessToken(caller, first)
|
|
4272
5282
|
} : {
|
|
4273
5283
|
getAccess: () => this.access(caller),
|
|
@@ -4392,7 +5402,19 @@ class GatewayService {
|
|
|
4392
5402
|
};
|
|
4393
5403
|
}
|
|
4394
5404
|
policyView() {
|
|
4395
|
-
|
|
5405
|
+
var _a;
|
|
5406
|
+
return this.policy.view(this.environments.settings.idleMinutes, (_a = this.egress) === null || _a === undefined ? undefined : _a.settings);
|
|
5407
|
+
}
|
|
5408
|
+
setEgressHosts(value) {
|
|
5409
|
+
try {
|
|
5410
|
+
this.policy.setEgressHosts(EgressProxyUtil.hosts(value));
|
|
5411
|
+
} catch (error) {
|
|
5412
|
+
if (error instanceof EgressConfigError) {
|
|
5413
|
+
throw new GatewayCallError(error.message, TaErrorCode.INVALID_ARGUMENT, "Send hosts such as registry.npmjs.org, *.github.com or example.com:8443.");
|
|
5414
|
+
}
|
|
5415
|
+
throw error;
|
|
5416
|
+
}
|
|
5417
|
+
return this.policyView();
|
|
4396
5418
|
}
|
|
4397
5419
|
tenant(id) {
|
|
4398
5420
|
const tenant = typeof id === "string" ? this.tenants.get(id) : undefined;
|
|
@@ -4726,6 +5748,366 @@ class GatewaySocket {
|
|
|
4726
5748
|
}
|
|
4727
5749
|
}
|
|
4728
5750
|
|
|
5751
|
+
// ../../ta-packages/ta-gateway/esm/node/kubernetes-sandbox.js
|
|
5752
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
5753
|
+
|
|
5754
|
+
// ../../ta-packages/ta-gateway/esm/node/kubernetes-api.js
|
|
5755
|
+
import { readFileSync as readFileSync8 } from "node:fs";
|
|
5756
|
+
import { request as httpRequest2 } from "node:http";
|
|
5757
|
+
import { request as httpsRequest } from "node:https";
|
|
5758
|
+
var ACCOUNT = "/var/run/secrets/kubernetes.io/serviceaccount";
|
|
5759
|
+
|
|
5760
|
+
class KubernetesError extends Error {
|
|
5761
|
+
constructor(status, message) {
|
|
5762
|
+
super(message);
|
|
5763
|
+
this.status = status;
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
|
|
5767
|
+
class KubernetesApi {
|
|
5768
|
+
static inCluster(env = process.env, read = (path) => readFileSync8(path, "utf8")) {
|
|
5769
|
+
var _a;
|
|
5770
|
+
const host = env.KUBERNETES_SERVICE_HOST;
|
|
5771
|
+
if (!host) {
|
|
5772
|
+
throw new Error('Not in a pod of Kubernetes (no KUBERNETES_SERVICE_HOST): give "server" and "token" of the cluster.');
|
|
5773
|
+
}
|
|
5774
|
+
const port = (_a = env.KUBERNETES_SERVICE_PORT) !== null && _a !== undefined ? _a : "443";
|
|
5775
|
+
return {
|
|
5776
|
+
server: `https://${host.includes(":") ? `[${host}]` : host}:${port}`,
|
|
5777
|
+
token: read(`${ACCOUNT}/token`).trim(),
|
|
5778
|
+
ca: read(`${ACCOUNT}/ca.crt`),
|
|
5779
|
+
namespace: read(`${ACCOUNT}/namespace`).trim()
|
|
5780
|
+
};
|
|
5781
|
+
}
|
|
5782
|
+
constructor(options) {
|
|
5783
|
+
this.options = options;
|
|
5784
|
+
}
|
|
5785
|
+
async call(method, path, body, type = "application/json") {
|
|
5786
|
+
const text = await this.send(method, path, body === undefined ? undefined : JSON.stringify(body), type);
|
|
5787
|
+
return text ? JSON.parse(text) : undefined;
|
|
5788
|
+
}
|
|
5789
|
+
text(path) {
|
|
5790
|
+
return this.send("GET", path);
|
|
5791
|
+
}
|
|
5792
|
+
send(method, path, body, type) {
|
|
5793
|
+
const url = new URL(path, this.options.server);
|
|
5794
|
+
const options = {
|
|
5795
|
+
method,
|
|
5796
|
+
headers: {
|
|
5797
|
+
accept: "application/json, */*",
|
|
5798
|
+
...this.options.token ? { authorization: `Bearer ${this.options.token}` } : {},
|
|
5799
|
+
...body !== undefined ? { "content-type": type !== null && type !== undefined ? type : "application/json", "content-length": Buffer.byteLength(body) } : {}
|
|
5800
|
+
},
|
|
5801
|
+
...this.options.ca ? { ca: this.options.ca } : {},
|
|
5802
|
+
timeout: 30000
|
|
5803
|
+
};
|
|
5804
|
+
const send = url.protocol === "https:" ? httpsRequest : httpRequest2;
|
|
5805
|
+
return new Promise((resolve, reject) => {
|
|
5806
|
+
const request2 = send(url, options, (response) => {
|
|
5807
|
+
const chunks = [];
|
|
5808
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
5809
|
+
response.on("end", () => {
|
|
5810
|
+
var _a, _b;
|
|
5811
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
5812
|
+
const status = (_a = response.statusCode) !== null && _a !== undefined ? _a : 0;
|
|
5813
|
+
if (status >= 200 && status < 300) {
|
|
5814
|
+
resolve(text);
|
|
5815
|
+
return;
|
|
5816
|
+
}
|
|
5817
|
+
let message = text.slice(0, 300);
|
|
5818
|
+
try {
|
|
5819
|
+
message = (_b = JSON.parse(text).message) !== null && _b !== undefined ? _b : message;
|
|
5820
|
+
} catch (_c) {}
|
|
5821
|
+
reject(new KubernetesError(status, `${method} ${url.pathname}: ${status} ${message}`));
|
|
5822
|
+
});
|
|
5823
|
+
response.on("error", reject);
|
|
5824
|
+
});
|
|
5825
|
+
request2.on("timeout", () => request2.destroy(new Error(`${method} ${url.pathname}: no answer in time`)));
|
|
5826
|
+
request2.on("error", reject);
|
|
5827
|
+
request2.end(body);
|
|
5828
|
+
});
|
|
5829
|
+
}
|
|
5830
|
+
}
|
|
5831
|
+
var KubernetesUtil;
|
|
5832
|
+
(function(KubernetesUtil2) {
|
|
5833
|
+
function quantity(value) {
|
|
5834
|
+
if (typeof value === "number") {
|
|
5835
|
+
return value;
|
|
5836
|
+
}
|
|
5837
|
+
const match = /^([0-9.]+)([a-zA-Z]*)$/.exec(String(value !== null && value !== undefined ? value : "").trim());
|
|
5838
|
+
if (!match) {
|
|
5839
|
+
return;
|
|
5840
|
+
}
|
|
5841
|
+
const scale = {
|
|
5842
|
+
"": 1,
|
|
5843
|
+
n: 0.000000001,
|
|
5844
|
+
u: 0.000001,
|
|
5845
|
+
m: 0.001,
|
|
5846
|
+
k: 1000,
|
|
5847
|
+
K: 1000,
|
|
5848
|
+
M: 1e6,
|
|
5849
|
+
G: 1e9,
|
|
5850
|
+
T: 1000000000000,
|
|
5851
|
+
Ki: 2 ** 10,
|
|
5852
|
+
Mi: 2 ** 20,
|
|
5853
|
+
Gi: 2 ** 30,
|
|
5854
|
+
Ti: 2 ** 40
|
|
5855
|
+
};
|
|
5856
|
+
const factor = scale[match[2]];
|
|
5857
|
+
return factor === undefined ? undefined : Number(match[1]) * factor;
|
|
5858
|
+
}
|
|
5859
|
+
KubernetesUtil2.quantity = quantity;
|
|
5860
|
+
})(KubernetesUtil || (KubernetesUtil = {}));
|
|
5861
|
+
|
|
5862
|
+
// ../../ta-packages/ta-gateway/esm/node/kubernetes-sandbox.js
|
|
5863
|
+
var GROUP = "/apis/agents.x-k8s.io/v1beta1";
|
|
5864
|
+
var PORT2 = 4100;
|
|
5865
|
+
var KubernetesSandboxUtil;
|
|
5866
|
+
(function(KubernetesSandboxUtil2) {
|
|
5867
|
+
KubernetesSandboxUtil2.ENV_ANNOTATION = "cell.ta/env";
|
|
5868
|
+
KubernetesSandboxUtil2.COMPONENT = "ta-sandbox";
|
|
5869
|
+
function options(config, inCluster) {
|
|
5870
|
+
var _a, _b, _c, _d, _e;
|
|
5871
|
+
const text = (key, fallback) => SandboxProviders.string(config, key, fallback);
|
|
5872
|
+
const cpus = (_a = config.cpus) !== null && _a !== undefined ? _a : 2;
|
|
5873
|
+
if (typeof cpus !== "number" || cpus <= 0) {
|
|
5874
|
+
throw new SandboxConfigError('"cpus" of a provider of the type kubernetes is a number above 0.');
|
|
5875
|
+
}
|
|
5876
|
+
const memory = String((_b = config.memory) !== null && _b !== undefined ? _b : "4Gi");
|
|
5877
|
+
const storage = String((_c = config.storage) !== null && _c !== undefined ? _c : "10Gi");
|
|
5878
|
+
for (const [key, value] of [
|
|
5879
|
+
["memory", memory],
|
|
5880
|
+
["storage", storage]
|
|
5881
|
+
]) {
|
|
5882
|
+
if (!KubernetesUtil.quantity(value)) {
|
|
5883
|
+
throw new SandboxConfigError(`"${key}" of a provider of the type kubernetes is a quantity such as 4Gi.`);
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
const strings = (key) => {
|
|
5887
|
+
const value = config[key];
|
|
5888
|
+
if (value !== undefined && (!Array.isArray(value) || value.some((item) => typeof item !== "string"))) {
|
|
5889
|
+
throw new SandboxConfigError(`"${key}" of a provider of the type kubernetes is a list of strings.`);
|
|
5890
|
+
}
|
|
5891
|
+
return value;
|
|
5892
|
+
};
|
|
5893
|
+
const selector = config.nodeSelector;
|
|
5894
|
+
if (selector !== undefined && (typeof selector !== "object" || Array.isArray(selector) || Object.values(selector).some((item) => typeof item !== "string"))) {
|
|
5895
|
+
throw new SandboxConfigError('"nodeSelector" of a provider of the type kubernetes is an object of strings.');
|
|
5896
|
+
}
|
|
5897
|
+
const prefix = text("prefix", "ta-");
|
|
5898
|
+
if (!/^[a-z][a-z0-9-]{0,20}$/.test(prefix)) {
|
|
5899
|
+
throw new SandboxConfigError('"prefix" of a provider of the type kubernetes starts with a letter: lower-case letters, digits and -.');
|
|
5900
|
+
}
|
|
5901
|
+
return {
|
|
5902
|
+
image: text("image", "ta:latest"),
|
|
5903
|
+
imagePullPolicy: text("imagePullPolicy"),
|
|
5904
|
+
namespace: (_e = (_d = text("namespace")) !== null && _d !== undefined ? _d : inCluster === null || inCluster === undefined ? undefined : inCluster().namespace) !== null && _e !== undefined ? _e : "default",
|
|
5905
|
+
memory,
|
|
5906
|
+
cpus,
|
|
5907
|
+
storage,
|
|
5908
|
+
storageClass: text("storageClass"),
|
|
5909
|
+
runtimeClass: text("runtimeClass"),
|
|
5910
|
+
prefix,
|
|
5911
|
+
env: SandboxProviders.env(config),
|
|
5912
|
+
nodeSelector: selector,
|
|
5913
|
+
imagePullSecrets: strings("imagePullSecrets"),
|
|
5914
|
+
clusterDomain: text("clusterDomain", "cluster.local")
|
|
5915
|
+
};
|
|
5916
|
+
}
|
|
5917
|
+
KubernetesSandboxUtil2.options = options;
|
|
5918
|
+
function api(config, env = process.env) {
|
|
5919
|
+
const server = SandboxProviders.string(config, "server");
|
|
5920
|
+
if (!server) {
|
|
5921
|
+
return new KubernetesApi(KubernetesApi.inCluster(env));
|
|
5922
|
+
}
|
|
5923
|
+
const given = SandboxProviders.string(config, "token");
|
|
5924
|
+
const token = (given === null || given === undefined ? undefined : given.startsWith("$")) ? env[given.slice(1).replace(/^\{|\}$/g, "")] : given;
|
|
5925
|
+
const caFile = SandboxProviders.string(config, "caFile");
|
|
5926
|
+
return new KubernetesApi({ server, token, ...caFile ? { ca: readFileSync9(caFile, "utf8") } : {} });
|
|
5927
|
+
}
|
|
5928
|
+
KubernetesSandboxUtil2.api = api;
|
|
5929
|
+
function ready(sandbox) {
|
|
5930
|
+
var _a, _b;
|
|
5931
|
+
var _c;
|
|
5932
|
+
return (_c = (_b = (_a = sandbox === null || sandbox === undefined ? undefined : sandbox.status) === null || _a === undefined ? undefined : _a.conditions) === null || _b === undefined ? undefined : _b.some((condition) => condition.type === "Ready" && condition.status === "True")) !== null && _c !== undefined ? _c : false;
|
|
5933
|
+
}
|
|
5934
|
+
KubernetesSandboxUtil2.ready = ready;
|
|
5935
|
+
})(KubernetesSandboxUtil || (KubernetesSandboxUtil = {}));
|
|
5936
|
+
|
|
5937
|
+
class KubernetesSandbox {
|
|
5938
|
+
constructor(id, config, api, options = KubernetesSandboxUtil.options(config, () => KubernetesApi.inCluster())) {
|
|
5939
|
+
this.id = id;
|
|
5940
|
+
this.options = options;
|
|
5941
|
+
this.type = "kubernetes";
|
|
5942
|
+
this.readyTimeoutMs = 5 * 60 * 1000;
|
|
5943
|
+
this.name = SandboxProviders.string(config, "name", "Kubernetes");
|
|
5944
|
+
this.gatewayUrl = SandboxProviders.string(config, "gatewayUrl");
|
|
5945
|
+
this.api = api !== null && api !== undefined ? api : KubernetesSandboxUtil.api(config);
|
|
5946
|
+
}
|
|
5947
|
+
async start(tenant) {
|
|
5948
|
+
var _a;
|
|
5949
|
+
const name = this.resourceName(tenant);
|
|
5950
|
+
const hash = DockerSandboxUtil.envHash(tenant.env);
|
|
5951
|
+
let sandbox = await this.read(name);
|
|
5952
|
+
if (!sandbox) {
|
|
5953
|
+
sandbox = await this.api.call("POST", this.path(), this.manifest(tenant));
|
|
5954
|
+
await this.putSecret(tenant, sandbox);
|
|
5955
|
+
} else {
|
|
5956
|
+
await this.putSecret(tenant, sandbox);
|
|
5957
|
+
const changed = ((_a = sandbox.metadata.annotations) === null || _a === undefined ? undefined : _a[KubernetesSandboxUtil.ENV_ANNOTATION]) !== hash;
|
|
5958
|
+
if (changed || sandbox.spec.operatingMode === "Suspended") {
|
|
5959
|
+
const { metadata, spec } = this.manifest(tenant);
|
|
5960
|
+
await this.api.call("PATCH", this.path(name), { metadata: { annotations: metadata.annotations }, spec }, "application/merge-patch+json");
|
|
5961
|
+
if (changed && sandbox.spec.operatingMode !== "Suspended") {
|
|
5962
|
+
await this.deletePod(name);
|
|
5963
|
+
}
|
|
5964
|
+
}
|
|
5965
|
+
}
|
|
5966
|
+
return { url: `http://${name}.${this.options.namespace}.svc.${this.options.clusterDomain}:${PORT2}`, token: tenant.token };
|
|
5967
|
+
}
|
|
5968
|
+
async stop(tenant) {
|
|
5969
|
+
const name = this.resourceName(tenant);
|
|
5970
|
+
if (await this.read(name)) {
|
|
5971
|
+
await this.api.call("PATCH", this.path(name), { spec: { operatingMode: "Suspended" } }, "application/merge-patch+json");
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
async state(tenant) {
|
|
5975
|
+
const sandbox = await this.read(this.resourceName(tenant));
|
|
5976
|
+
return !sandbox ? "missing" : sandbox.spec.operatingMode === "Suspended" ? "stopped" : "running";
|
|
5977
|
+
}
|
|
5978
|
+
async usage(tenant) {
|
|
5979
|
+
var _a, _b;
|
|
5980
|
+
const name = this.resourceName(tenant);
|
|
5981
|
+
const metrics = await this.api.call("GET", `/apis/metrics.k8s.io/v1beta1/namespaces/${this.options.namespace}/pods/${name}`).catch(() => {
|
|
5982
|
+
return;
|
|
5983
|
+
});
|
|
5984
|
+
const usage = (_b = (_a = metrics === null || metrics === undefined ? undefined : metrics.containers) === null || _a === undefined ? undefined : _a.find((container) => container.name === "ta")) === null || _b === undefined ? undefined : _b.usage;
|
|
5985
|
+
if (!usage) {
|
|
5986
|
+
return;
|
|
5987
|
+
}
|
|
5988
|
+
const cpu = KubernetesUtil.quantity(usage.cpu);
|
|
5989
|
+
return {
|
|
5990
|
+
cpu: cpu === undefined ? undefined : Math.round(cpu * 1000) / 10,
|
|
5991
|
+
memory: KubernetesUtil.quantity(usage.memory),
|
|
5992
|
+
memoryLimit: KubernetesUtil.quantity(this.options.memory)
|
|
5993
|
+
};
|
|
5994
|
+
}
|
|
5995
|
+
logs(tenant, lines) {
|
|
5996
|
+
const name = this.resourceName(tenant);
|
|
5997
|
+
return this.api.text(`/api/v1/namespaces/${this.options.namespace}/pods/${name}/log?container=ta&tailLines=${Math.max(1, Math.floor(lines))}`).catch((error) => error instanceof KubernetesError && error.status === 404 ? "" : Promise.reject(error));
|
|
5998
|
+
}
|
|
5999
|
+
manifest(tenant) {
|
|
6000
|
+
var _a;
|
|
6001
|
+
const name = this.resourceName(tenant);
|
|
6002
|
+
const hash = DockerSandboxUtil.envHash(tenant.env);
|
|
6003
|
+
const labels = { "app.kubernetes.io/name": "ta", "app.kubernetes.io/component": KubernetesSandboxUtil.COMPONENT, "cell.ta/tenant": tenant.id };
|
|
6004
|
+
const options = this.options;
|
|
6005
|
+
return {
|
|
6006
|
+
apiVersion: "agents.x-k8s.io/v1beta1",
|
|
6007
|
+
kind: "Sandbox",
|
|
6008
|
+
metadata: { name, labels, annotations: { [KubernetesSandboxUtil.ENV_ANNOTATION]: hash, "cell.ta/account": tenant.account } },
|
|
6009
|
+
spec: {
|
|
6010
|
+
operatingMode: "Running",
|
|
6011
|
+
service: true,
|
|
6012
|
+
failedPodPolicy: "Recreate",
|
|
6013
|
+
podTemplate: {
|
|
6014
|
+
metadata: { labels, annotations: { [KubernetesSandboxUtil.ENV_ANNOTATION]: hash } },
|
|
6015
|
+
spec: {
|
|
6016
|
+
automountServiceAccountToken: false,
|
|
6017
|
+
enableServiceLinks: false,
|
|
6018
|
+
hostname: DockerSandboxUtil.hostname(tenant.account),
|
|
6019
|
+
securityContext: { runAsUser: 1000, runAsGroup: 1000, fsGroup: 1000, seccompProfile: { type: "RuntimeDefault" } },
|
|
6020
|
+
...options.runtimeClass ? { runtimeClassName: options.runtimeClass } : {},
|
|
6021
|
+
...options.nodeSelector ? { nodeSelector: options.nodeSelector } : {},
|
|
6022
|
+
...((_a = options.imagePullSecrets) === null || _a === undefined ? undefined : _a.length) ? { imagePullSecrets: options.imagePullSecrets.map((secret) => ({ name: secret })) } : {},
|
|
6023
|
+
containers: [
|
|
6024
|
+
{
|
|
6025
|
+
name: "ta",
|
|
6026
|
+
image: options.image,
|
|
6027
|
+
...options.imagePullPolicy ? { imagePullPolicy: options.imagePullPolicy } : {},
|
|
6028
|
+
workingDir: "/home/ta",
|
|
6029
|
+
command: [
|
|
6030
|
+
"tini",
|
|
6031
|
+
"--",
|
|
6032
|
+
"sh",
|
|
6033
|
+
"-c",
|
|
6034
|
+
`mkdir -p /home/ta/workspace && cd /home/ta/workspace && exec ta serve --host 0.0.0.0 --port ${PORT2}`
|
|
6035
|
+
],
|
|
6036
|
+
envFrom: [{ secretRef: { name } }],
|
|
6037
|
+
ports: [{ name: "ta", containerPort: PORT2 }],
|
|
6038
|
+
resources: {
|
|
6039
|
+
limits: { memory: options.memory, cpu: String(options.cpus) },
|
|
6040
|
+
requests: { memory: "256Mi", cpu: "100m" }
|
|
6041
|
+
},
|
|
6042
|
+
securityContext: { capabilities: { drop: ["NET_RAW"] } },
|
|
6043
|
+
readinessProbe: { httpGet: { path: "/", port: PORT2 }, periodSeconds: 5, failureThreshold: 3 },
|
|
6044
|
+
volumeMounts: [{ name: "home", mountPath: "/home/ta" }]
|
|
6045
|
+
}
|
|
6046
|
+
]
|
|
6047
|
+
}
|
|
6048
|
+
},
|
|
6049
|
+
volumeClaimTemplates: [
|
|
6050
|
+
{
|
|
6051
|
+
metadata: { name: "home", labels },
|
|
6052
|
+
spec: {
|
|
6053
|
+
accessModes: ["ReadWriteOnce"],
|
|
6054
|
+
resources: { requests: { storage: options.storage } },
|
|
6055
|
+
...options.storageClass ? { storageClassName: options.storageClass } : {}
|
|
6056
|
+
}
|
|
6057
|
+
}
|
|
6058
|
+
]
|
|
6059
|
+
}
|
|
6060
|
+
};
|
|
6061
|
+
}
|
|
6062
|
+
async putSecret(tenant, sandbox) {
|
|
6063
|
+
const name = this.resourceName(tenant);
|
|
6064
|
+
const env = { ...this.options.env, ...tenant.env, TA_SERVE_TOKEN: tenant.token };
|
|
6065
|
+
const secret = {
|
|
6066
|
+
apiVersion: "v1",
|
|
6067
|
+
kind: "Secret",
|
|
6068
|
+
metadata: {
|
|
6069
|
+
name,
|
|
6070
|
+
labels: { "app.kubernetes.io/name": "ta", "app.kubernetes.io/component": KubernetesSandboxUtil.COMPONENT, "cell.ta/tenant": tenant.id },
|
|
6071
|
+
...sandbox.metadata.uid ? { ownerReferences: [{ apiVersion: "agents.x-k8s.io/v1beta1", kind: "Sandbox", name, uid: sandbox.metadata.uid }] } : {}
|
|
6072
|
+
},
|
|
6073
|
+
type: "Opaque",
|
|
6074
|
+
stringData: env
|
|
6075
|
+
};
|
|
6076
|
+
const path = `/api/v1/namespaces/${this.options.namespace}/secrets`;
|
|
6077
|
+
try {
|
|
6078
|
+
await this.api.call("PUT", `${path}/${name}`, secret);
|
|
6079
|
+
} catch (error) {
|
|
6080
|
+
if (!(error instanceof KubernetesError && error.status === 404)) {
|
|
6081
|
+
throw error;
|
|
6082
|
+
}
|
|
6083
|
+
await this.api.call("POST", path, secret);
|
|
6084
|
+
}
|
|
6085
|
+
}
|
|
6086
|
+
async deletePod(name) {
|
|
6087
|
+
await this.api.call("DELETE", `/api/v1/namespaces/${this.options.namespace}/pods/${name}`).catch((error) => {
|
|
6088
|
+
if (!(error instanceof KubernetesError && error.status === 404)) {
|
|
6089
|
+
throw error;
|
|
6090
|
+
}
|
|
6091
|
+
});
|
|
6092
|
+
}
|
|
6093
|
+
async read(name) {
|
|
6094
|
+
try {
|
|
6095
|
+
return await this.api.call("GET", this.path(name));
|
|
6096
|
+
} catch (error) {
|
|
6097
|
+
if (error instanceof KubernetesError && error.status === 404) {
|
|
6098
|
+
return;
|
|
6099
|
+
}
|
|
6100
|
+
throw error;
|
|
6101
|
+
}
|
|
6102
|
+
}
|
|
6103
|
+
path(name) {
|
|
6104
|
+
return `${GROUP}/namespaces/${this.options.namespace}/sandboxes${name ? `/${name}` : ""}`;
|
|
6105
|
+
}
|
|
6106
|
+
resourceName(tenant) {
|
|
6107
|
+
return `${this.options.prefix}${tenant.id}`;
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
|
|
4729
6111
|
// ../../ta-packages/ta-gateway/esm/node/local-sandbox.js
|
|
4730
6112
|
import { spawn as spawn2 } from "node:child_process";
|
|
4731
6113
|
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
@@ -4842,11 +6224,11 @@ class LocalSandbox {
|
|
|
4842
6224
|
}
|
|
4843
6225
|
|
|
4844
6226
|
// ../../ta-packages/ta-gateway/esm/node/sign-in-links.js
|
|
4845
|
-
import { createHash as
|
|
4846
|
-
import { readFileSync as
|
|
6227
|
+
import { createHash as createHash7, randomBytes as randomBytes4 } from "node:crypto";
|
|
6228
|
+
import { readFileSync as readFileSync10 } from "node:fs";
|
|
4847
6229
|
import { join as join8 } from "node:path";
|
|
4848
6230
|
var SIGN_IN_LINK_PATH = "/sign-in/link/";
|
|
4849
|
-
var hash = (secret) =>
|
|
6231
|
+
var hash = (secret) => createHash7("sha256").update(secret).digest("base64url");
|
|
4850
6232
|
|
|
4851
6233
|
class SignInLinks {
|
|
4852
6234
|
constructor(dir) {
|
|
@@ -4872,7 +6254,7 @@ class SignInLinks {
|
|
|
4872
6254
|
}
|
|
4873
6255
|
read(now) {
|
|
4874
6256
|
try {
|
|
4875
|
-
const links = JSON.parse(
|
|
6257
|
+
const links = JSON.parse(readFileSync10(this.file, "utf8"));
|
|
4876
6258
|
return Array.isArray(links) ? links.filter((link) => link.expiresAt > now) : [];
|
|
4877
6259
|
} catch (_a) {
|
|
4878
6260
|
return [];
|
|
@@ -4899,6 +6281,7 @@ var TYPES = {
|
|
|
4899
6281
|
};
|
|
4900
6282
|
var SANDBOX_TYPES = {
|
|
4901
6283
|
docker: (id, config) => new DockerSandbox(id, config),
|
|
6284
|
+
kubernetes: (id, config) => new KubernetesSandbox(id, config),
|
|
4902
6285
|
command: (id, config) => new CommandSandbox(id, config),
|
|
4903
6286
|
local: (id, config, context) => new LocalSandbox(id, config, context),
|
|
4904
6287
|
ta: (id, config) => new TaSandbox(id, config)
|
|
@@ -4915,6 +6298,19 @@ var GatewayServerUtil;
|
|
|
4915
6298
|
return publicUrl;
|
|
4916
6299
|
}
|
|
4917
6300
|
GatewayServerUtil2.reach = reach;
|
|
6301
|
+
function deploymentEnv(env) {
|
|
6302
|
+
var _a;
|
|
6303
|
+
const given = {};
|
|
6304
|
+
const relay = TaDeploymentUtil.url(env.TA_RELAY_URL);
|
|
6305
|
+
if (relay) {
|
|
6306
|
+
given.TA_RELAY_URL = relay;
|
|
6307
|
+
}
|
|
6308
|
+
if ((_a = env.TA_DEPLOYMENT_NAME) === null || _a === undefined ? undefined : _a.trim()) {
|
|
6309
|
+
given.TA_DEPLOYMENT_NAME = env.TA_DEPLOYMENT_NAME.trim();
|
|
6310
|
+
}
|
|
6311
|
+
return given;
|
|
6312
|
+
}
|
|
6313
|
+
GatewayServerUtil2.deploymentEnv = deploymentEnv;
|
|
4918
6314
|
GatewayServerUtil2.EXEC_PATH = "/api/exec";
|
|
4919
6315
|
function blockedReason(block) {
|
|
4920
6316
|
switch (block) {
|
|
@@ -4955,10 +6351,11 @@ var GatewayServerUtil;
|
|
|
4955
6351
|
|
|
4956
6352
|
class GatewayServer {
|
|
4957
6353
|
static async create(options) {
|
|
4958
|
-
|
|
6354
|
+
var _a, _b;
|
|
6355
|
+
const models = ModelProxyUtil.read((_a = options.config) !== null && _a !== undefined ? _a : options.dir);
|
|
4959
6356
|
mkdirSync5(options.dir, { recursive: true, mode: 448 });
|
|
4960
|
-
const config = SandboxProviders.read(options.dir);
|
|
4961
|
-
const context = { dir: options.dir, taCommand: options.taCommand };
|
|
6357
|
+
const config = SandboxProviders.read((_b = options.config) !== null && _b !== undefined ? _b : options.dir);
|
|
6358
|
+
const context = { dir: options.dir, config: options.config, taCommand: options.taCommand };
|
|
4962
6359
|
const providers = await SandboxProviders.create(config, context, SANDBOX_TYPES);
|
|
4963
6360
|
return new GatewayServer(options, providers, config, models);
|
|
4964
6361
|
}
|
|
@@ -4966,6 +6363,7 @@ class GatewayServer {
|
|
|
4966
6363
|
var _a, _b;
|
|
4967
6364
|
this.options = options;
|
|
4968
6365
|
this.sockets = new Set;
|
|
6366
|
+
this.execs = new Map;
|
|
4969
6367
|
const env = (_a = options.env) !== null && _a !== undefined ? _a : process.env;
|
|
4970
6368
|
const owners = AccessUtil.parseList(env.TA_GATEWAY_ADMINS);
|
|
4971
6369
|
this.policy = new GatewayPolicy(options.dir, owners);
|
|
@@ -4990,13 +6388,25 @@ class GatewayServer {
|
|
|
4990
6388
|
},
|
|
4991
6389
|
record: (id, usage, cost) => this.quotas.addTokens(id, ModelProxyUtil.total(usage), cost)
|
|
4992
6390
|
}, env);
|
|
4993
|
-
this.
|
|
6391
|
+
this.egress = new EgressProxy(EgressProxyUtil.settings(config.egress), { authorize: (user, password) => this.authorizeEgress(user, password) });
|
|
6392
|
+
this.quotas.egressOf = (tenant) => this.egress.enabled ? this.egress.refused(tenant.id) : undefined;
|
|
6393
|
+
this.environments.envOf = (tenant, provider, fresh) => {
|
|
4994
6394
|
var _a2, _b2, _c;
|
|
4995
|
-
|
|
4996
|
-
|
|
6395
|
+
const deployment = GatewayServerUtil.deploymentEnv(env);
|
|
6396
|
+
if (!this.models.enabled && !this.egress.enabled) {
|
|
6397
|
+
return Object.keys(deployment).length ? deployment : undefined;
|
|
6398
|
+
}
|
|
6399
|
+
const base = (_a2 = provider.gatewayUrl) !== null && _a2 !== undefined ? _a2 : GatewayServerUtil.reach(provider.type, (_c = (_b2 = this.port) !== null && _b2 !== undefined ? _b2 : options.port) !== null && _c !== undefined ? _c : 4100, SandboxProviders.publicBase(env));
|
|
6400
|
+
const url = base.replace(/\/+$/, "");
|
|
6401
|
+
const given = { ...deployment };
|
|
6402
|
+
if (this.models.enabled) {
|
|
6403
|
+
Object.assign(given, { TA_MODEL_PROXY_URL: url, TA_MODEL_PROXY_KEY: this.tenants.modelKey(tenant.id) });
|
|
4997
6404
|
}
|
|
4998
|
-
|
|
4999
|
-
|
|
6405
|
+
if (this.egress.enabled) {
|
|
6406
|
+
const key = this.tenants.egressKey(tenant.id, fresh);
|
|
6407
|
+
Object.assign(given, EgressProxyUtil.env(url, tenant.id, `${key.epoch}.${key.secret}`));
|
|
6408
|
+
}
|
|
6409
|
+
return given;
|
|
5000
6410
|
};
|
|
5001
6411
|
this.service = new GatewayService({
|
|
5002
6412
|
flow: this.flow,
|
|
@@ -5008,13 +6418,35 @@ class GatewayServer {
|
|
|
5008
6418
|
audit: this.audit,
|
|
5009
6419
|
hooks: { cutOff: () => this.cutOff(), reset: (id) => this.reset(id) },
|
|
5010
6420
|
models: this.models,
|
|
6421
|
+
egress: this.egress,
|
|
5011
6422
|
meta: { links: this.links, startedAt: Date.now(), version: options.version, publicUrl: SandboxProviders.publicBase(env) }
|
|
5012
6423
|
});
|
|
5013
6424
|
}
|
|
5014
6425
|
isAdmin(account) {
|
|
5015
6426
|
return this.policy.role(account) !== "member";
|
|
5016
6427
|
}
|
|
6428
|
+
authorizeEgress(user, password) {
|
|
6429
|
+
const tenant = this.tenants.get(user);
|
|
6430
|
+
const dot = password.indexOf(".");
|
|
6431
|
+
const epoch = Number(password.slice(0, dot));
|
|
6432
|
+
const known = tenant === null || tenant === undefined ? undefined : tenant.egress;
|
|
6433
|
+
if (!tenant || !known || dot < 1 || !EgressProxyUtil.sameSecret(password.slice(dot + 1), epoch === known.epoch ? known.secret : "")) {
|
|
6434
|
+
const stale = known !== undefined && Number.isInteger(epoch) && epoch < known.epoch;
|
|
6435
|
+
return {
|
|
6436
|
+
status: 407,
|
|
6437
|
+
message: stale ? `ta gateway: a sandbox of epoch ${known.epoch} took over from this one (epoch ${epoch}); it goes out no more.` : "ta gateway: these credentials are of no sandbox of the gateway."
|
|
6438
|
+
};
|
|
6439
|
+
}
|
|
6440
|
+
if (this.quotas.blocked(tenant) === "suspended") {
|
|
6441
|
+
return { status: 403, message: "ta gateway: your account is suspended by an administrator of the gateway." };
|
|
6442
|
+
}
|
|
6443
|
+
const hosts = this.policy.egressHosts;
|
|
6444
|
+
return { tenantId: tenant.id, hosts: this.quotas.role(tenant) === "owner" || hosts.length === 0 ? undefined : hosts };
|
|
6445
|
+
}
|
|
5017
6446
|
async tick(now = Date.now()) {
|
|
6447
|
+
for (const [id, bytes] of this.egress.flush()) {
|
|
6448
|
+
this.quotas.addEgress(id, bytes, now);
|
|
6449
|
+
}
|
|
5018
6450
|
for (const tenant of this.quotas.tick(this.environments.runningIds(), now)) {
|
|
5019
6451
|
console.log(`ta gateway: ${tenant.account} used its free minutes of the month: its sandbox stops`);
|
|
5020
6452
|
await this.environments.stop(tenant.id).catch(() => {
|
|
@@ -5027,6 +6459,10 @@ class GatewayServer {
|
|
|
5027
6459
|
var _a, _b;
|
|
5028
6460
|
const server = createServer2((request2, response) => void this.handle(request2, response));
|
|
5029
6461
|
server.on("upgrade", (request2, socket, head) => this.upgrade(request2, socket, head));
|
|
6462
|
+
server.on("connect", (request2, socket, head) => this.egress.connect(request2, socket, head).catch((error) => {
|
|
6463
|
+
console.warn(`ta gateway: CONNECT ${request2.url} failed: ${error.message}`);
|
|
6464
|
+
socket.destroy();
|
|
6465
|
+
}));
|
|
5030
6466
|
this.server = server;
|
|
5031
6467
|
this.ticker = setInterval(() => void this.tick().catch((error) => console.warn(`ta gateway: counting minutes failed: ${error.message}`)), TICK_MS);
|
|
5032
6468
|
(_b = (_a = this.ticker).unref) === null || _b === undefined || _b.call(_a);
|
|
@@ -5048,6 +6484,9 @@ class GatewayServer {
|
|
|
5048
6484
|
for (const socket of this.sockets) {
|
|
5049
6485
|
socket.close(1001, "The gateway is stopping.");
|
|
5050
6486
|
}
|
|
6487
|
+
for (const exec of this.execs.keys()) {
|
|
6488
|
+
exec.close(1001, "The gateway is stopping.");
|
|
6489
|
+
}
|
|
5051
6490
|
await this.environments.dispose();
|
|
5052
6491
|
await new Promise((resolve) => this.server ? this.server.close(() => resolve()) : resolve());
|
|
5053
6492
|
}
|
|
@@ -5057,13 +6496,22 @@ class GatewayServer {
|
|
|
5057
6496
|
socket.close(1008, "Signed out");
|
|
5058
6497
|
}
|
|
5059
6498
|
}
|
|
6499
|
+
for (const [exec, { token }] of this.execs) {
|
|
6500
|
+
if (!this.caller(token)) {
|
|
6501
|
+
exec.close(1008, "Signed out");
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
5060
6504
|
}
|
|
5061
6505
|
reset(tenantId) {
|
|
5062
6506
|
const sockets = [...this.sockets].filter((socket) => socket.tenantId === tenantId);
|
|
6507
|
+
const execs = [...this.execs].filter(([, exec]) => exec.tenantId === tenantId).map(([proxy]) => proxy);
|
|
5063
6508
|
setTimeout(() => {
|
|
5064
6509
|
for (const socket of sockets) {
|
|
5065
6510
|
socket.close(1012, "The environment changed.");
|
|
5066
6511
|
}
|
|
6512
|
+
for (const exec of execs) {
|
|
6513
|
+
exec.close(1012, "The environment changed.");
|
|
6514
|
+
}
|
|
5067
6515
|
}, 100);
|
|
5068
6516
|
}
|
|
5069
6517
|
caller(token) {
|
|
@@ -5076,10 +6524,14 @@ class GatewayServer {
|
|
|
5076
6524
|
return { token, account: signIn.account, tenant, role, admin: role !== "member" };
|
|
5077
6525
|
}
|
|
5078
6526
|
async handle(request2, response) {
|
|
5079
|
-
var _a;
|
|
6527
|
+
var _a, _b;
|
|
5080
6528
|
const path = ((_a = request2.url) !== null && _a !== undefined ? _a : "/").split("?")[0];
|
|
5081
6529
|
try {
|
|
5082
|
-
if (
|
|
6530
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test((_b = request2.url) !== null && _b !== undefined ? _b : "")) {
|
|
6531
|
+
await this.egress.request(request2, response);
|
|
6532
|
+
} else if (path === TA_WELL_KNOWN_PATH || path === "/healthz" || path === "/readyz") {
|
|
6533
|
+
this.describe(path, request2, response);
|
|
6534
|
+
} else if (path.startsWith(SIGN_IN_LINK_PATH)) {
|
|
5083
6535
|
this.useLink(request2, response, path.slice(SIGN_IN_LINK_PATH.length));
|
|
5084
6536
|
} else if (SignInPages.matches(request2)) {
|
|
5085
6537
|
await SignInPages.handle(request2, response, this.flow, {
|
|
@@ -5104,6 +6556,24 @@ class GatewayServer {
|
|
|
5104
6556
|
}
|
|
5105
6557
|
}
|
|
5106
6558
|
}
|
|
6559
|
+
describe(path, request2, response) {
|
|
6560
|
+
var _a;
|
|
6561
|
+
const version = this.options.version;
|
|
6562
|
+
let body = { ok: true, ...version ? { version } : {} };
|
|
6563
|
+
let status = 200;
|
|
6564
|
+
if (path === TA_WELL_KNOWN_PATH) {
|
|
6565
|
+
body = TaDeploymentUtil.describe((_a = this.options.env) !== null && _a !== undefined ? _a : process.env, { gateway: this.origin(request2) }, version);
|
|
6566
|
+
} else if (path === "/readyz") {
|
|
6567
|
+
try {
|
|
6568
|
+
accessSync(this.options.dir, constants2.W_OK);
|
|
6569
|
+
} catch (error) {
|
|
6570
|
+
status = 503;
|
|
6571
|
+
body = { ok: false, error: `${this.options.dir} cannot be written: ${error.message}` };
|
|
6572
|
+
}
|
|
6573
|
+
}
|
|
6574
|
+
response.writeHead(status, TaDeploymentUtil.HEADERS);
|
|
6575
|
+
response.end(JSON.stringify(body));
|
|
6576
|
+
}
|
|
5107
6577
|
useLink(request2, response, secret) {
|
|
5108
6578
|
response.setHeader("Cache-Control", "no-store");
|
|
5109
6579
|
response.setHeader("Referrer-Policy", "no-referrer");
|
|
@@ -5157,11 +6627,11 @@ class GatewayServer {
|
|
|
5157
6627
|
}
|
|
5158
6628
|
}
|
|
5159
6629
|
await new Promise((resolve, reject) => {
|
|
5160
|
-
const send = target.protocol === "https:" ?
|
|
6630
|
+
const send = target.protocol === "https:" ? httpsRequest2 : httpRequest3;
|
|
5161
6631
|
const outgoing = send(target, { method: request2.method, headers }, (incoming) => {
|
|
5162
6632
|
var _a2;
|
|
5163
6633
|
response.writeHead((_a2 = incoming.statusCode) !== null && _a2 !== undefined ? _a2 : 502, GatewayServerUtil.filesHeaders(incoming.headers));
|
|
5164
|
-
|
|
6634
|
+
pipeline2(incoming, response, () => resolve());
|
|
5165
6635
|
});
|
|
5166
6636
|
outgoing.on("error", reject);
|
|
5167
6637
|
response.once("close", () => outgoing.destroy());
|
|
@@ -5221,7 +6691,7 @@ class GatewayServer {
|
|
|
5221
6691
|
return;
|
|
5222
6692
|
}
|
|
5223
6693
|
const exec = WebSocketConnection.open(socket, checked.key, head, { maxPayload: 64 * 1024 * 1024, heartbeat: 30000 });
|
|
5224
|
-
|
|
6694
|
+
this.openExec(exec, caller);
|
|
5225
6695
|
return;
|
|
5226
6696
|
}
|
|
5227
6697
|
const connection = WebSocketConnection.open(socket, checked.key, head, { maxPayload: 32 * 1024 * 1024, heartbeat: 30000, deflate: checked.deflate });
|
|
@@ -5229,6 +6699,12 @@ class GatewayServer {
|
|
|
5229
6699
|
this.sockets.add(gatewaySocket);
|
|
5230
6700
|
connection.onClose(() => this.sockets.delete(gatewaySocket));
|
|
5231
6701
|
}
|
|
6702
|
+
openExec(exec, caller) {
|
|
6703
|
+
const proxy = new GatewayExecProxy(exec, this.environments.ensure(caller.tenant), this.environments.connect(caller.tenant.id));
|
|
6704
|
+
this.execs.set(proxy, { token: caller.token, tenantId: caller.tenant.id });
|
|
6705
|
+
exec.onClose(() => this.execs.delete(proxy));
|
|
6706
|
+
return proxy;
|
|
6707
|
+
}
|
|
5232
6708
|
}
|
|
5233
6709
|
|
|
5234
6710
|
// ../../ta-packages/ta-gateway/esm/node/gateway-cli.js
|
|
@@ -5240,9 +6716,11 @@ Ta runs in a sandbox of its own (a container per tenant by default), or in a Ta
|
|
|
5240
6716
|
The web client is served here; each browser's connection goes to the Ta of its tenant. Stops on SIGINT
|
|
5241
6717
|
or SIGTERM.
|
|
5242
6718
|
|
|
5243
|
-
--host
|
|
5244
|
-
--port
|
|
5245
|
-
--dir
|
|
6719
|
+
--host Address to listen on. Default: 127.0.0.1
|
|
6720
|
+
--port Port to listen on. Default: 4100, or PORT
|
|
6721
|
+
--dir Its configuration and data. Default: TA_GATEWAY_DIR, else ~/.ta/gateway
|
|
6722
|
+
--config Where sandboxes.json and models.json are, when not in --dir (a directory mounted read-only).
|
|
6723
|
+
Default: TA_GATEWAY_CONFIG
|
|
5246
6724
|
|
|
5247
6725
|
Accounts sign in with the providers of the environment (TA_GITHUB_*, TA_GOOGLE_*, TA_WECHAT_*,
|
|
5248
6726
|
TA_OIDC_*, as for ta serve) when TA_ALLOWED_USERS lets them in; TA_GATEWAY_ADMINS are let in too and
|
|
@@ -5253,11 +6731,14 @@ The sandboxes are those of sandboxes.json in the directory, as pi's models.json
|
|
|
5253
6731
|
{ "default": "docker", "providers": { "docker": { "type": "docker", "image": "ta:latest", "memory": "4g" } } }
|
|
5254
6732
|
Types: docker, command (shell commands for any platform), local (no isolation: tests), ta (a Ta service
|
|
5255
6733
|
that runs), module (a file whose default export makes a provider). See the README of @celljs/ta-gateway.
|
|
6734
|
+
|
|
6735
|
+
At /.well-known/ta it tells the deployment it is part of: TA_DEPLOYMENT_NAME, its own address and the
|
|
6736
|
+
relay (TA_RELAY_URL), which every sandbox is given too; /healthz and /readyz are for probes.
|
|
5256
6737
|
`;
|
|
5257
6738
|
var GatewayCli;
|
|
5258
6739
|
(function(GatewayCli2) {
|
|
5259
6740
|
async function run(argv, options) {
|
|
5260
|
-
var _a, _b, _c, _d;
|
|
6741
|
+
var _a, _b, _c, _d, _e;
|
|
5261
6742
|
const { values, positionals } = parseArgs({
|
|
5262
6743
|
args: argv,
|
|
5263
6744
|
allowPositionals: true,
|
|
@@ -5265,6 +6746,7 @@ var GatewayCli;
|
|
|
5265
6746
|
host: { type: "string" },
|
|
5266
6747
|
port: { type: "string" },
|
|
5267
6748
|
dir: { type: "string" },
|
|
6749
|
+
config: { type: "string" },
|
|
5268
6750
|
name: { type: "string" },
|
|
5269
6751
|
help: { type: "boolean", short: "h" }
|
|
5270
6752
|
}
|
|
@@ -5287,8 +6769,9 @@ var GatewayCli;
|
|
|
5287
6769
|
try {
|
|
5288
6770
|
gateway = await GatewayServer.create({
|
|
5289
6771
|
dir,
|
|
6772
|
+
config: (_c = values.config) !== null && _c !== undefined ? _c : process.env.TA_GATEWAY_CONFIG || undefined,
|
|
5290
6773
|
host: values.host,
|
|
5291
|
-
port: Number((
|
|
6774
|
+
port: Number((_e = (_d = values.port) !== null && _d !== undefined ? _d : process.env.PORT) !== null && _e !== undefined ? _e : 4100),
|
|
5292
6775
|
publicDir: options.publicDir,
|
|
5293
6776
|
taCommand: options.taCommand,
|
|
5294
6777
|
version: options.version
|