@celljs/ta 4.15.2 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -0
- package/README.md +1 -0
- package/dist/cli.mjs +2227 -203
- package/dist/gateway.mjs +2391 -291
- package/dist/pi/CHANGELOG.md +19 -0
- package/dist/pi/package.json +1 -1
- package/dist/pi/packages/ta-3d/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-3d/package.json +2 -1
- package/dist/pi/packages/ta-agents/README.en.md +14 -2
- package/dist/pi/packages/ta-agents/README.md +14 -2
- package/dist/pi/packages/ta-agents/extension/index.mjs +286 -111
- package/dist/pi/packages/ta-agents/host/index.mjs +662 -0
- package/dist/pi/packages/ta-agents/lib/acp-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-agents/lib/acp-protocol.js +5 -0
- package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +36 -2
- package/dist/pi/packages/ta-agents/lib/agent-catalog.js +76 -6
- package/dist/pi/packages/ta-agents/lib/agent-installer.d.ts +55 -0
- package/dist/pi/packages/ta-agents/lib/agent-installer.js +140 -0
- package/dist/pi/packages/ta-agents/lib/agent-installs.d.ts +25 -0
- package/dist/pi/packages/ta-agents/lib/agent-installs.js +64 -0
- package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts +6 -0
- package/dist/pi/packages/ta-agents/lib/agent-prompt.js +9 -0
- package/dist/pi/packages/ta-agents/lib/agent-refresh.d.ts +11 -0
- package/dist/pi/packages/ta-agents/lib/agent-refresh.js +37 -0
- package/dist/pi/packages/ta-agents/lib/agent-session.d.ts +0 -2
- package/dist/pi/packages/ta-agents/lib/agent-session.js +3 -6
- package/dist/pi/packages/ta-agents/lib/agent-turn.d.ts +7 -2
- package/dist/pi/packages/ta-agents/lib/agent-turn.js +8 -4
- package/dist/pi/packages/ta-agents/lib/agents-protocol.d.ts +26 -0
- package/dist/pi/packages/ta-agents/lib/agents-protocol.js +11 -0
- package/dist/pi/packages/ta-agents/lib/agents-settings.d.ts +10 -0
- package/dist/pi/packages/ta-agents/lib/agents-settings.js +165 -0
- package/dist/pi/packages/ta-agents/lib/extension.d.ts +3 -1
- package/dist/pi/packages/ta-agents/lib/extension.js +17 -4
- package/dist/pi/packages/ta-agents/lib/host.d.ts +35 -0
- package/dist/pi/packages/ta-agents/lib/host.js +96 -0
- package/dist/pi/packages/ta-agents/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-agents/lib/react.js +8 -0
- package/dist/pi/packages/ta-agents/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-agents/lib/style.js +30 -0
- package/dist/pi/packages/ta-agents/lib/texts.d.ts +18 -0
- package/dist/pi/packages/ta-agents/lib/texts.js +18 -0
- package/dist/pi/packages/ta-agents/lib/web-words.d.ts +30 -0
- package/dist/pi/packages/ta-agents/lib/web-words.js +98 -0
- package/dist/pi/packages/ta-agents/lib/web.d.ts +4 -0
- package/dist/pi/packages/ta-agents/lib/web.js +14 -0
- package/dist/pi/packages/ta-agents/package.json +21 -5
- package/dist/pi/packages/ta-agents/web/index.js +385 -0
- package/dist/pi/packages/ta-app-use/README.en.md +28 -0
- package/dist/pi/packages/ta-app-use/README.md +28 -0
- package/dist/pi/packages/ta-app-use/extension/index.mjs +534 -0
- package/dist/pi/packages/ta-app-use/host/index.mjs +136 -0
- package/dist/pi/packages/ta-app-use/lib/app-host.d.ts +32 -0
- package/dist/pi/packages/ta-app-use/lib/app-host.js +79 -0
- package/dist/pi/packages/ta-app-use/lib/app-protocol.d.ts +23 -0
- package/dist/pi/packages/ta-app-use/lib/app-protocol.js +9 -0
- package/dist/pi/packages/ta-app-use/lib/app-util.d.ts +18 -0
- package/dist/pi/packages/ta-app-use/lib/app-util.js +71 -0
- package/dist/pi/packages/ta-app-use/lib/extension.d.ts +80 -0
- package/dist/pi/packages/ta-app-use/lib/extension.js +125 -0
- package/dist/pi/packages/ta-app-use/lib/host.d.ts +7 -0
- package/dist/pi/packages/ta-app-use/lib/host.js +16 -0
- package/dist/pi/packages/ta-app-use/lib/i18n.d.ts +38 -0
- package/dist/pi/packages/ta-app-use/lib/i18n.js +130 -0
- package/dist/pi/packages/ta-app-use/lib/index.d.ts +9 -0
- package/dist/pi/packages/ta-app-use/lib/index.js +93 -0
- package/dist/pi/packages/ta-app-use/lib/screen-cursor.d.ts +33 -0
- package/dist/pi/packages/ta-app-use/lib/screen-cursor.js +134 -0
- package/dist/pi/packages/ta-app-use/lib/screen-dom.d.ts +19 -0
- package/dist/pi/packages/ta-app-use/lib/screen-dom.js +184 -0
- package/dist/pi/packages/ta-app-use/lib/screen-driver.d.ts +46 -0
- package/dist/pi/packages/ta-app-use/lib/screen-driver.js +174 -0
- package/dist/pi/packages/ta-app-use/lib/screen-protocol.d.ts +67 -0
- package/dist/pi/packages/ta-app-use/lib/screen-protocol.js +8 -0
- package/dist/pi/packages/ta-app-use/lib/screen-text.d.ts +13 -0
- package/dist/pi/packages/ta-app-use/lib/screen-text.js +69 -0
- package/dist/pi/packages/ta-app-use/lib/screen-window.d.ts +68 -0
- package/dist/pi/packages/ta-app-use/lib/screen-window.js +376 -0
- package/dist/pi/packages/ta-app-use/lib/tool-line.d.ts +11 -0
- package/dist/pi/packages/ta-app-use/lib/tool-line.js +69 -0
- package/dist/pi/packages/ta-app-use/package.json +63 -0
- package/dist/pi/packages/ta-app-use/web/index.js +1520 -0
- package/dist/pi/packages/ta-bots/README.en.md +1 -0
- package/dist/pi/packages/ta-bots/README.md +1 -0
- package/dist/pi/packages/ta-bots/extension/index.mjs +25 -22
- package/dist/pi/packages/ta-bots/host/index.mjs +726 -151
- package/dist/pi/packages/ta-bots/lib/bot-service.d.ts +9 -1
- package/dist/pi/packages/ta-bots/lib/bot-service.js +49 -8
- package/dist/pi/packages/ta-bots/lib/channel-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-bots/lib/extension.d.ts +2 -2
- package/dist/pi/packages/ta-bots/lib/extension.js +28 -24
- package/dist/pi/packages/ta-bots/lib/index.js +4 -0
- package/dist/pi/packages/ta-bots/lib/page.d.ts +7 -1
- package/dist/pi/packages/ta-bots/lib/page.js +17 -0
- package/dist/pi/packages/ta-bots/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-bots/lib/style.js +1 -1
- package/dist/pi/packages/ta-bots/lib/wecom-channel.js +1 -1
- package/dist/pi/packages/ta-bots/lib/weixin-api.d.ts +1 -0
- package/dist/pi/packages/ta-bots/lib/weixin-channel.js +2 -1
- package/dist/pi/packages/ta-bots/package.json +1 -1
- package/dist/pi/packages/ta-bots/web/index.js +13 -2
- package/dist/pi/packages/ta-call/README.en.md +9 -0
- package/dist/pi/packages/ta-call/README.md +9 -0
- package/dist/pi/packages/ta-call/extension/index.mjs +474 -0
- package/dist/pi/packages/ta-call/host/index.mjs +899 -0
- package/dist/pi/packages/ta-call/lib/call-host.d.ts +127 -0
- package/dist/pi/packages/ta-call/lib/call-host.js +377 -0
- package/dist/pi/packages/ta-call/lib/call-protocol.d.ts +33 -0
- package/dist/pi/packages/ta-call/lib/call-protocol.js +10 -0
- package/dist/pi/packages/ta-call/lib/call-util.d.ts +50 -0
- package/dist/pi/packages/ta-call/lib/call-util.js +250 -0
- package/dist/pi/packages/ta-call/lib/extension.d.ts +20 -0
- package/dist/pi/packages/ta-call/lib/extension.js +114 -0
- package/dist/pi/packages/ta-call/lib/host.d.ts +7 -0
- package/dist/pi/packages/ta-call/lib/host.js +20 -0
- package/dist/pi/packages/ta-call/lib/i18n.d.ts +16 -0
- package/dist/pi/packages/ta-call/lib/i18n.js +38 -0
- package/dist/pi/packages/ta-call/lib/index.d.ts +7 -0
- package/dist/pi/packages/ta-call/lib/index.js +60 -0
- package/dist/pi/packages/ta-call/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-call/lib/react.js +8 -0
- package/dist/pi/packages/ta-call/package.json +64 -0
- package/dist/pi/packages/ta-call/web/index.js +552 -0
- package/dist/pi/packages/ta-changes/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-changes/lib/card.js +4 -1
- package/dist/pi/packages/ta-changes/package.json +1 -1
- package/dist/pi/packages/ta-changes/web/index.js +2 -0
- package/dist/pi/packages/ta-channels/extension/index.mjs +155 -194
- package/dist/pi/packages/ta-channels/host/index.mjs +2039 -1503
- package/dist/pi/packages/ta-channels/lib/agent-menu.js +2 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/channel-menu.js +2 -2
- package/dist/pi/packages/ta-channels/lib/channels-text.d.ts +38 -0
- package/dist/pi/packages/ta-channels/lib/channels-text.js +173 -0
- package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +0 -48
- package/dist/pi/packages/ta-channels/lib/channels-util.js +1 -223
- package/dist/pi/packages/ta-channels/lib/create.js +5 -1
- package/dist/pi/packages/ta-channels/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-ja.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh.d.ts +3 -0
- package/dist/pi/packages/ta-channels/lib/i18n-zh.js +182 -0
- package/dist/pi/packages/ta-channels/lib/i18n.js +4 -535
- package/dist/pi/packages/ta-channels/lib/index.js +2 -1
- package/dist/pi/packages/ta-channels/lib/notice-util.d.ts +15 -0
- package/dist/pi/packages/ta-channels/lib/notice-util.js +61 -0
- package/dist/pi/packages/ta-channels/lib/notice.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/notice.js +5 -4
- package/dist/pi/packages/ta-channels/lib/room.js +4 -3
- package/dist/pi/packages/ta-channels/lib/sidebar-head.d.ts +6 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-head.js +67 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-hooks.d.ts +51 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-hooks.js +230 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-rows.d.ts +71 -0
- package/dist/pi/packages/ta-channels/lib/sidebar-rows.js +105 -0
- package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +0 -4
- package/dist/pi/packages/ta-channels/lib/sidebar.js +35 -396
- package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-channels/lib/style.js +0 -1
- package/dist/pi/packages/ta-channels/lib/tasks.js +2 -1
- package/dist/pi/packages/ta-channels/lib/team-store.d.ts +78 -0
- package/dist/pi/packages/ta-channels/lib/team-store.js +261 -0
- package/dist/pi/packages/ta-channels/lib/team-tools.js +3 -2
- package/dist/pi/packages/ta-channels/lib/team.d.ts +3 -76
- package/dist/pi/packages/ta-channels/lib/team.js +5 -254
- package/dist/pi/packages/ta-channels/package.json +1 -1
- package/dist/pi/packages/ta-channels/web/index.js +889 -809
- package/dist/pi/packages/ta-computer-use/package.json +1 -1
- package/dist/pi/packages/ta-cron/README.en.md +19 -3
- package/dist/pi/packages/ta-cron/README.md +19 -3
- package/dist/pi/packages/ta-cron/extension/index.mjs +396 -111
- package/dist/pi/packages/ta-cron/host/index.mjs +633 -49
- package/dist/pi/packages/ta-cron/lib/chat-task.d.ts +5 -3
- package/dist/pi/packages/ta-cron/lib/chat-task.js +15 -10
- package/dist/pi/packages/ta-cron/lib/commands.d.ts +7 -4
- package/dist/pi/packages/ta-cron/lib/commands.js +26 -47
- package/dist/pi/packages/ta-cron/lib/cron-expression.d.ts +8 -0
- package/dist/pi/packages/ta-cron/lib/cron-expression.js +43 -1
- package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts +54 -7
- package/dist/pi/packages/ta-cron/lib/cron-protocol.js +16 -2
- package/dist/pi/packages/ta-cron/lib/editor.d.ts +3 -0
- package/dist/pi/packages/ta-cron/lib/editor.js +106 -36
- package/dist/pi/packages/ta-cron/lib/extension.js +1 -1
- package/dist/pi/packages/ta-cron/lib/form-util.d.ts +16 -6
- package/dist/pi/packages/ta-cron/lib/form-util.js +40 -28
- package/dist/pi/packages/ta-cron/lib/host.js +17 -1
- package/dist/pi/packages/ta-cron/lib/i18n.d.ts +39 -5
- package/dist/pi/packages/ta-cron/lib/i18n.js +160 -24
- package/dist/pi/packages/ta-cron/lib/index.js +4 -0
- package/dist/pi/packages/ta-cron/lib/page.d.ts +3 -2
- package/dist/pi/packages/ta-cron/lib/page.js +13 -2
- package/dist/pi/packages/ta-cron/lib/schedule-util.d.ts +4 -0
- package/dist/pi/packages/ta-cron/lib/schedule-util.js +52 -4
- package/dist/pi/packages/ta-cron/lib/scheduler.d.ts +56 -6
- package/dist/pi/packages/ta-cron/lib/scheduler.js +209 -27
- package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-cron/lib/style.js +50 -21
- package/dist/pi/packages/ta-cron/lib/task-list.d.ts +23 -0
- package/dist/pi/packages/ta-cron/lib/task-list.js +70 -0
- package/dist/pi/packages/ta-cron/lib/task-row.d.ts +19 -0
- package/dist/pi/packages/ta-cron/lib/task-row.js +246 -0
- package/dist/pi/packages/ta-cron/lib/task-util.d.ts +10 -6
- package/dist/pi/packages/ta-cron/lib/task-util.js +53 -19
- package/dist/pi/packages/ta-cron/lib/task-watchers.d.ts +30 -0
- package/dist/pi/packages/ta-cron/lib/task-watchers.js +90 -0
- package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +3 -2
- package/dist/pi/packages/ta-cron/lib/tasks-view.js +48 -193
- package/dist/pi/packages/ta-cron/lib/tool-line.js +4 -0
- package/dist/pi/packages/ta-cron/lib/tool.d.ts +7 -0
- package/dist/pi/packages/ta-cron/lib/tool.js +18 -8
- package/dist/pi/packages/ta-cron/lib/when.d.ts +39 -0
- package/dist/pi/packages/ta-cron/lib/when.js +231 -0
- package/dist/pi/packages/ta-cron/package.json +2 -1
- package/dist/pi/packages/ta-cron/web/index.js +1091 -340
- package/dist/pi/packages/ta-extensions/lib/market-detail.js +9 -5
- package/dist/pi/packages/ta-extensions/lib/page.js +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-extensions/lib/style.js +1 -1
- package/dist/pi/packages/ta-extensions/package.json +1 -1
- package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +9 -7
- package/dist/pi/packages/ta-extensions/web/index.js +777 -237
- package/dist/pi/packages/ta-feedback/README.en.md +10 -0
- package/dist/pi/packages/ta-feedback/README.md +10 -0
- package/dist/pi/packages/ta-feedback/extension/index.mjs +451 -0
- package/dist/pi/packages/ta-feedback/host/index.mjs +1187 -0
- package/dist/pi/packages/ta-feedback/lib/extension.d.ts +31 -0
- package/dist/pi/packages/ta-feedback/lib/extension.js +160 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-git.d.ts +25 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-git.js +44 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-host.d.ts +133 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-host.js +668 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-protocol.d.ts +127 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-protocol.js +41 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-util.d.ts +79 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-util.js +252 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-view.d.ts +11 -0
- package/dist/pi/packages/ta-feedback/lib/feedback-view.js +244 -0
- package/dist/pi/packages/ta-feedback/lib/host.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/host.js +19 -0
- package/dist/pi/packages/ta-feedback/lib/i18n.d.ts +69 -0
- package/dist/pi/packages/ta-feedback/lib/i18n.js +250 -0
- package/dist/pi/packages/ta-feedback/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/index.js +88 -0
- package/dist/pi/packages/ta-feedback/lib/page.d.ts +35 -0
- package/dist/pi/packages/ta-feedback/lib/page.js +135 -0
- package/dist/pi/packages/ta-feedback/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-feedback/lib/react.js +8 -0
- package/dist/pi/packages/ta-feedback/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-feedback/lib/style.js +71 -0
- package/dist/pi/packages/ta-feedback/package.json +65 -0
- package/dist/pi/packages/ta-feedback/web/index.js +939 -0
- package/dist/pi/packages/ta-games/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-games/lib/style.js +1 -1
- package/dist/pi/packages/ta-games/package.json +1 -1
- package/dist/pi/packages/ta-games/web/index.js +1 -1
- package/dist/pi/packages/ta-glance/README.en.md +2 -0
- package/dist/pi/packages/ta-glance/README.md +2 -0
- package/dist/pi/packages/ta-glance/extension/index.mjs +135 -27
- package/dist/pi/packages/ta-glance/lib/card.js +155 -35
- package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/glance-json.js +8 -1
- package/dist/pi/packages/ta-glance/lib/glance-prompt.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/glance-prompt.js +9 -6
- package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +43 -4
- package/dist/pi/packages/ta-glance/lib/glance-protocol.js +39 -1
- package/dist/pi/packages/ta-glance/lib/glance-spec.js +125 -23
- package/dist/pi/packages/ta-glance/lib/glance-speech.d.ts +13 -0
- package/dist/pi/packages/ta-glance/lib/glance-speech.js +45 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.d.ts +13 -0
- package/dist/pi/packages/ta-glance/lib/glance-util.js +28 -0
- package/dist/pi/packages/ta-glance/lib/i18n.d.ts +5 -0
- package/dist/pi/packages/ta-glance/lib/i18n.js +20 -0
- package/dist/pi/packages/ta-glance/lib/index.js +11 -1
- package/dist/pi/packages/ta-glance/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-glance/lib/style.js +82 -5
- package/dist/pi/packages/ta-glance/package.json +2 -1
- package/dist/pi/packages/ta-glance/web/index.js +508 -62
- package/dist/pi/packages/ta-initiative/extension/index.mjs +3 -2
- package/dist/pi/packages/ta-initiative/host/index.mjs +1 -1
- package/dist/pi/packages/ta-initiative/lib/chat-proposals.js +1 -1
- package/dist/pi/packages/ta-initiative/lib/index.js +1 -0
- package/dist/pi/packages/ta-initiative/lib/material-util.js +1 -1
- package/dist/pi/packages/ta-initiative/lib/settings.js +2 -1
- package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
- package/dist/pi/packages/ta-initiative/package.json +1 -1
- package/dist/pi/packages/ta-initiative/web/index.js +5 -3
- package/dist/pi/packages/ta-launcher/package.json +1 -1
- package/dist/pi/packages/ta-manual/lib/manual-util.d.ts +1 -1
- package/dist/pi/packages/ta-manual/lib/pictures-c.js +15 -0
- package/dist/pi/packages/ta-manual/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-manual/lib/style.js +1 -1
- package/dist/pi/packages/ta-manual/lib/topics-a.d.ts +3 -0
- package/dist/pi/packages/ta-manual/lib/topics-a.js +295 -0
- package/dist/pi/packages/ta-manual/lib/topics-model.d.ts +46 -0
- package/dist/pi/packages/ta-manual/lib/topics-model.js +21 -0
- package/dist/pi/packages/ta-manual/lib/topics.d.ts +1 -44
- package/dist/pi/packages/ta-manual/lib/topics.js +28 -318
- package/dist/pi/packages/ta-manual/package.json +1 -1
- package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +12 -10
- package/dist/pi/packages/ta-manual/web/index.js +97 -24
- package/dist/pi/packages/ta-moments/extension/index.mjs +740 -194
- package/dist/pi/packages/ta-moments/host/index.mjs +1393 -834
- package/dist/pi/packages/ta-moments/lib/index.js +3 -1
- package/dist/pi/packages/ta-moments/lib/moments-host-base.d.ts +96 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-base.js +276 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-pictures.d.ts +22 -0
- package/dist/pi/packages/ta-moments/lib/moments-host-pictures.js +167 -0
- package/dist/pi/packages/ta-moments/lib/moments-host.d.ts +4 -84
- package/dist/pi/packages/ta-moments/lib/moments-host.js +13 -426
- package/dist/pi/packages/ta-moments/lib/page.js +3 -3
- package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-moments/lib/style.js +1 -1
- package/dist/pi/packages/ta-moments/lib/talk-host-base.d.ts +71 -0
- package/dist/pi/packages/ta-moments/lib/talk-host-base.js +171 -0
- package/dist/pi/packages/ta-moments/lib/talk-host.d.ts +3 -62
- package/dist/pi/packages/ta-moments/lib/talk-host.js +14 -169
- package/dist/pi/packages/ta-moments/package.json +1 -1
- package/dist/pi/packages/ta-moments/web/index.js +686 -147
- package/dist/pi/packages/ta-nearby/extension/index.mjs +9 -0
- package/dist/pi/packages/ta-nearby/host/index.mjs +1073 -1018
- package/dist/pi/packages/ta-nearby/lib/index.js +8 -5
- package/dist/pi/packages/ta-nearby/lib/nearby-home.d.ts +13 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-home.js +91 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.d.ts +12 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.js +113 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-page.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-page.js +157 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-base.d.ts +161 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-base.js +343 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.d.ts +41 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.js +297 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +6 -167
- package/dist/pi/packages/ta-nearby/lib/nearby-service.js +38 -638
- package/dist/pi/packages/ta-nearby/lib/nearby-show-view.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-show-view.js +88 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-spot.d.ts +6 -0
- package/dist/pi/packages/ta-nearby/lib/nearby-spot.js +25 -3
- package/dist/pi/packages/ta-nearby/lib/page.d.ts +27 -20
- package/dist/pi/packages/ta-nearby/lib/page.js +15 -417
- package/dist/pi/packages/ta-nearby/lib/server-texts.d.ts +1 -1
- package/dist/pi/packages/ta-nearby/lib/server-texts.js +9 -1
- package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
- package/dist/pi/packages/ta-nearby/package.json +1 -1
- package/dist/pi/packages/ta-nearby/web/index.js +370 -362
- package/dist/pi/packages/ta-notify/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-notify/lib/settings.js +1 -0
- package/dist/pi/packages/ta-notify/package.json +1 -1
- package/dist/pi/packages/ta-notify/web/index.js +1 -0
- package/dist/pi/packages/ta-plot/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-plot/package.json +2 -1
- package/dist/pi/packages/ta-recall/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-recall/host/index.mjs +1 -0
- package/dist/pi/packages/ta-recall/lib/settings.js +1 -0
- package/dist/pi/packages/ta-recall/package.json +1 -1
- package/dist/pi/packages/ta-recall/web/index.js +2 -0
- package/dist/pi/packages/ta-rooms/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-rooms/host/index.mjs +497 -492
- package/dist/pi/packages/ta-rooms/lib/double-agents.js +6 -6
- package/dist/pi/packages/ta-rooms/lib/double-grants.js +10 -10
- package/dist/pi/packages/ta-rooms/lib/double-host.js +6 -5
- package/dist/pi/packages/ta-rooms/lib/double-tasks-base.d.ts +55 -0
- package/dist/pi/packages/ta-rooms/lib/double-tasks-base.js +279 -0
- package/dist/pi/packages/ta-rooms/lib/double-tasks.d.ts +3 -45
- package/dist/pi/packages/ta-rooms/lib/double-tasks.js +14 -282
- package/dist/pi/packages/ta-rooms/lib/double-user.js +2 -2
- package/dist/pi/packages/ta-rooms/lib/friend-notices.js +2 -2
- package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +1 -0
- package/dist/pi/packages/ta-rooms/lib/i18n.js +8 -4
- package/dist/pi/packages/ta-rooms/lib/index.js +18 -2
- package/dist/pi/packages/ta-rooms/lib/members-view.js +37 -3
- package/dist/pi/packages/ta-rooms/lib/page.d.ts +36 -1
- package/dist/pi/packages/ta-rooms/lib/page.js +76 -1
- package/dist/pi/packages/ta-rooms/lib/room-view.js +22 -17
- package/dist/pi/packages/ta-rooms/lib/rooms-home.js +1 -0
- package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-rooms/lib/style.js +32 -6
- package/dist/pi/packages/ta-rooms/package.json +1 -1
- package/dist/pi/packages/ta-rooms/web/index.js +223 -38
- package/dist/pi/packages/ta-secrets/README.en.md +22 -0
- package/dist/pi/packages/ta-secrets/README.md +22 -0
- package/dist/pi/packages/ta-secrets/extension/index.mjs +462 -0
- package/dist/pi/packages/ta-secrets/host/index.mjs +1341 -0
- package/dist/pi/packages/ta-secrets/lib/command-prelude.d.ts +36 -0
- package/dist/pi/packages/ta-secrets/lib/command-prelude.js +66 -0
- package/dist/pi/packages/ta-secrets/lib/extension.d.ts +28 -0
- package/dist/pi/packages/ta-secrets/lib/extension.js +156 -0
- package/dist/pi/packages/ta-secrets/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/host.js +15 -0
- package/dist/pi/packages/ta-secrets/lib/i18n.d.ts +47 -0
- package/dist/pi/packages/ta-secrets/lib/i18n.js +166 -0
- package/dist/pi/packages/ta-secrets/lib/index.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/index.js +28 -0
- package/dist/pi/packages/ta-secrets/lib/personal-info.d.ts +26 -0
- package/dist/pi/packages/ta-secrets/lib/personal-info.js +108 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-certs.d.ts +40 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-certs.js +200 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-scenario.d.ts +6 -0
- package/dist/pi/packages/ta-secrets/lib/proxy-scenario.js +91 -0
- package/dist/pi/packages/ta-secrets/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/react.js +8 -0
- package/dist/pi/packages/ta-secrets/lib/scrubber.d.ts +20 -0
- package/dist/pi/packages/ta-secrets/lib/scrubber.js +70 -0
- package/dist/pi/packages/ta-secrets/lib/secrets-protocol.d.ts +106 -0
- package/dist/pi/packages/ta-secrets/lib/secrets-protocol.js +134 -0
- package/dist/pi/packages/ta-secrets/lib/server-texts.d.ts +14 -0
- package/dist/pi/packages/ta-secrets/lib/server-texts.js +62 -0
- package/dist/pi/packages/ta-secrets/lib/settings.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/settings.js +179 -0
- package/dist/pi/packages/ta-secrets/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-secrets/lib/style.js +32 -0
- package/dist/pi/packages/ta-secrets/lib/vault-fixture.d.ts +8 -0
- package/dist/pi/packages/ta-secrets/lib/vault-fixture.js +22 -0
- package/dist/pi/packages/ta-secrets/lib/vault-proxy.d.ts +94 -0
- package/dist/pi/packages/ta-secrets/lib/vault-proxy.js +357 -0
- package/dist/pi/packages/ta-secrets/lib/vault-service.d.ts +111 -0
- package/dist/pi/packages/ta-secrets/lib/vault-service.js +429 -0
- package/dist/pi/packages/ta-secrets/lib/vault-store.d.ts +48 -0
- package/dist/pi/packages/ta-secrets/lib/vault-store.js +107 -0
- package/dist/pi/packages/ta-secrets/package.json +67 -0
- package/dist/pi/packages/ta-secrets/web/index.js +579 -0
- package/dist/pi/packages/ta-share/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-share/host/index.mjs +172 -21
- package/dist/pi/packages/ta-share/lib/i18n.d.ts +1 -0
- package/dist/pi/packages/ta-share/lib/i18n.js +4 -0
- package/dist/pi/packages/ta-share/lib/index.js +1 -1
- package/dist/pi/packages/ta-share/lib/share-dialog.js +1 -0
- package/dist/pi/packages/ta-share/lib/share-protocol.d.ts +2 -0
- package/dist/pi/packages/ta-share/lib/share-service.d.ts +11 -1
- package/dist/pi/packages/ta-share/lib/share-service.js +62 -4
- package/dist/pi/packages/ta-share/lib/snapshot.d.ts +8 -2
- package/dist/pi/packages/ta-share/lib/snapshot.js +93 -7
- package/dist/pi/packages/ta-share/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-share/lib/style.js +1 -1
- package/dist/pi/packages/ta-share/package.json +1 -1
- package/dist/pi/packages/ta-share/web/index.js +7 -2
- package/dist/pi/packages/ta-sync/host/index.mjs +1154 -755
- package/dist/pi/packages/ta-sync/lib/host.js +3 -0
- package/dist/pi/packages/ta-sync/lib/index.js +6 -2
- package/dist/pi/packages/ta-sync/lib/migrate-archive.d.ts +8 -6
- package/dist/pi/packages/ta-sync/lib/migrate-archive.js +24 -28
- package/dist/pi/packages/ta-sync/lib/migrate-i18n.d.ts +10 -0
- package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +40 -0
- package/dist/pi/packages/ta-sync/lib/migrate-paths.d.ts +24 -0
- package/dist/pi/packages/ta-sync/lib/migrate-paths.js +230 -0
- package/dist/pi/packages/ta-sync/lib/migrate-protocol.d.ts +18 -0
- package/dist/pi/packages/ta-sync/lib/migrate-service.d.ts +11 -1
- package/dist/pi/packages/ta-sync/lib/migrate-service.js +28 -1
- package/dist/pi/packages/ta-sync/lib/move-panel.d.ts +9 -1
- package/dist/pi/packages/ta-sync/lib/move-panel.js +69 -5
- package/dist/pi/packages/ta-sync/lib/server-texts.d.ts +1 -0
- package/dist/pi/packages/ta-sync/lib/server-texts.js +9 -0
- package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-sync/lib/style.js +8 -1
- package/dist/pi/packages/ta-sync/lib/sync-service-base.d.ts +78 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-base.js +224 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-space.d.ts +36 -0
- package/dist/pi/packages/ta-sync/lib/sync-service-space.js +210 -0
- package/dist/pi/packages/ta-sync/lib/sync-service.d.ts +3 -99
- package/dist/pi/packages/ta-sync/lib/sync-service.js +2 -412
- package/dist/pi/packages/ta-sync/package.json +1 -1
- package/dist/pi/packages/ta-sync/web/index.js +138 -5
- package/dist/pi/packages/ta-sync-cloud/package.json +1 -1
- package/dist/pi/packages/ta-team/extension/index.mjs +1 -0
- package/dist/pi/packages/ta-team/host/index.mjs +1 -0
- package/dist/pi/packages/ta-team/lib/dialogs.d.ts +0 -2
- package/dist/pi/packages/ta-team/lib/dialogs.js +0 -227
- package/dist/pi/packages/ta-team/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-ja.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh-tw.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/i18n-zh.js +211 -0
- package/dist/pi/packages/ta-team/lib/i18n.d.ts +1 -2
- package/dist/pi/packages/ta-team/lib/i18n.js +6 -624
- package/dist/pi/packages/ta-team/lib/index.js +3 -1
- package/dist/pi/packages/ta-team/lib/join-dialog.d.ts +3 -0
- package/dist/pi/packages/ta-team/lib/join-dialog.js +234 -0
- package/dist/pi/packages/ta-team/lib/members-tab.js +2 -1
- package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
- package/dist/pi/packages/ta-team/lib/style.js +1 -1
- package/dist/pi/packages/ta-team/package.json +1 -1
- package/dist/pi/packages/ta-team/web/index.js +2095 -2086
- package/dist/pi/packages/ta-usage/README.en.md +6 -0
- package/dist/pi/packages/ta-usage/README.md +6 -0
- package/dist/pi/packages/ta-usage/host/index.mjs +220 -0
- package/dist/pi/packages/ta-usage/lib/host.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/host.js +9 -0
- package/dist/pi/packages/ta-usage/lib/i18n.d.ts +30 -0
- package/dist/pi/packages/ta-usage/lib/i18n.js +98 -0
- package/dist/pi/packages/ta-usage/lib/index.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/index.js +20 -0
- package/dist/pi/packages/ta-usage/lib/react.d.ts +8 -0
- package/dist/pi/packages/ta-usage/lib/react.js +8 -0
- package/dist/pi/packages/ta-usage/lib/style.d.ts +4 -0
- package/dist/pi/packages/ta-usage/lib/style.js +53 -0
- package/dist/pi/packages/ta-usage/lib/usage-host.d.ts +25 -0
- package/dist/pi/packages/ta-usage/lib/usage-host.js +70 -0
- package/dist/pi/packages/ta-usage/lib/usage-protocol.d.ts +55 -0
- package/dist/pi/packages/ta-usage/lib/usage-protocol.js +7 -0
- package/dist/pi/packages/ta-usage/lib/usage-util.d.ts +18 -0
- package/dist/pi/packages/ta-usage/lib/usage-util.js +159 -0
- package/dist/pi/packages/ta-usage/lib/usage-view.d.ts +9 -0
- package/dist/pi/packages/ta-usage/lib/usage-view.js +91 -0
- package/dist/pi/packages/ta-usage/package.json +61 -0
- package/dist/pi/packages/ta-usage/web/index.js +471 -0
- package/dist/pi/packages/ta-voice/README.en.md +8 -0
- package/dist/pi/packages/ta-voice/README.md +8 -0
- package/dist/pi/packages/ta-voice/host/index.mjs +662 -0
- package/dist/pi/packages/ta-voice/lib/doubao-frames.d.ts +44 -0
- package/dist/pi/packages/ta-voice/lib/doubao-frames.js +116 -0
- package/dist/pi/packages/ta-voice/lib/doubao-realtime.d.ts +35 -0
- package/dist/pi/packages/ta-voice/lib/doubao-realtime.js +172 -0
- package/dist/pi/packages/ta-voice/lib/host.d.ts +20 -0
- package/dist/pi/packages/ta-voice/lib/host.js +120 -0
- package/dist/pi/packages/ta-voice/lib/openai-realtime.d.ts +73 -0
- package/dist/pi/packages/ta-voice/lib/openai-realtime.js +257 -0
- package/dist/pi/packages/ta-voice/lib/realtime-socket.d.ts +23 -0
- package/dist/pi/packages/ta-voice/lib/realtime-socket.js +80 -0
- package/dist/pi/packages/ta-voice/package.json +67 -0
- package/dist/pi/packages/ta-workspace/README.md +1 -1
- package/dist/pi/packages/ta-workspace/README.zh-cn.md +1 -1
- package/dist/pi/packages/ta-workspace/lib/browser-common.d.ts +4 -0
- package/dist/pi/packages/ta-workspace/lib/browser-common.js +1 -0
- package/dist/pi/packages/ta-workspace/lib/browser-pick.d.ts +49 -0
- package/dist/pi/packages/ta-workspace/lib/browser-pick.js +166 -0
- package/dist/pi/packages/ta-workspace/lib/browser-webview.js +16 -1
- package/dist/pi/packages/ta-workspace/lib/i18n-en.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-en.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-ja.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-ja.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.d.ts +3 -0
- package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.js +215 -0
- package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +7 -3
- package/dist/pi/packages/ta-workspace/lib/i18n.js +11 -621
- package/dist/pi/packages/ta-workspace/package.json +1 -1
- package/dist/pi/packages/ta-workspace/web/index.js +1504 -770
- package/dist/public/assets/{abnfDiagram-S7VZAUFO-Dd51Bqbx.js → abnfDiagram-S7VZAUFO-w8qXXVn-.js} +1 -1
- package/dist/public/assets/{architecture-WOLXFQ4H-BbG3_x7_.js → architecture-WOLXFQ4H-B-FHaYwY.js} +1 -1
- package/dist/public/assets/{architectureDiagram-YGSQEFNW-DbJO4t8I.js → architectureDiagram-YGSQEFNW-DTnoGaaX.js} +1 -1
- package/dist/public/assets/{blockDiagram-APKKGZFW-BwtrHF1f.js → blockDiagram-APKKGZFW-CyeBzv-v.js} +1 -1
- package/dist/public/assets/{browser-D2BcOPKG.js → browser-Cb38iiEE.js} +1 -1
- package/dist/public/assets/{browser-CTbeNBsA.js → browser-DXexCqIh.js} +2 -2
- package/dist/public/assets/{c4Diagram-KJ2TOQU5-CfBe5A0H.js → c4Diagram-KJ2TOQU5-CJJqDqyQ.js} +1 -1
- package/dist/public/assets/{chunk-6MUBBAK2-C7R0mhrg.js → chunk-6MUBBAK2-DbvUMdNm.js} +1 -1
- package/dist/public/assets/{chunk-AXFCVDMN-VQgQruZT.js → chunk-AXFCVDMN-D4hlZGtj.js} +1 -1
- package/dist/public/assets/{chunk-BG4553SI-CkUi_vD5.js → chunk-BG4553SI-VNa9Q9On.js} +1 -1
- package/dist/public/assets/{chunk-DQASFODM-BAQq7ktk.js → chunk-DQASFODM-BtlEbc_V.js} +1 -1
- package/dist/public/assets/{chunk-HFQBQIA3-B1oF8lB7.js → chunk-HFQBQIA3-CAYSo4CJ.js} +1 -1
- package/dist/public/assets/{chunk-KQLB2F66-DE5amcgT.js → chunk-KQLB2F66-CyKdg6hW.js} +1 -1
- package/dist/public/assets/{chunk-KS47KZWR-ev9S_csp.js → chunk-KS47KZWR-BMogCB2r.js} +1 -1
- package/dist/public/assets/{chunk-LEVMRMFU-ziqnRvTG.js → chunk-LEVMRMFU-Y9wr-8qB.js} +1 -1
- package/dist/public/assets/{chunk-M57EVK23-DaqPdEKA.js → chunk-M57EVK23-DL3IAQKR.js} +1 -1
- package/dist/public/assets/{chunk-OY52VR5R-DFOG8j6z.js → chunk-OY52VR5R-CJBFHdg6.js} +1 -1
- package/dist/public/assets/{chunk-QB3YPZ4I-eg35JLLN.js → chunk-QB3YPZ4I-CyuWKZZv.js} +1 -1
- package/dist/public/assets/{chunk-R3KSYZAL-J73nie-R.js → chunk-R3KSYZAL-DxvGhfpm.js} +1 -1
- package/dist/public/assets/{chunk-STOXU5M4-B8EvDZvB.js → chunk-STOXU5M4-Cpdl6bfz.js} +1 -1
- package/dist/public/assets/{chunk-TU62E6Q5-DyCM007V.js → chunk-TU62E6Q5-CIxOg6QF.js} +1 -1
- package/dist/public/assets/{chunk-X4PVCEUW-BBGeCNmA.js → chunk-X4PVCEUW-DCFSCRBh.js} +1 -1
- package/dist/public/assets/{chunk-XXDRQBXY-CAtJ2Wph.js → chunk-XXDRQBXY-B2R8Cxf7.js} +1 -1
- package/dist/public/assets/{classDiagram-v2-L25IHNXF-DhQM6yHy.js → classDiagram-v2-L25IHNXF-B7W9HSbj.js} +1 -1
- package/dist/public/assets/{client-C8gi9Fk2.js → client-D75LfyFa.js} +1 -1
- package/dist/public/assets/{common-DrZR0tgm.js → common-CjqTomRQ.js} +1 -1
- package/dist/public/assets/{cose-bilkent-JH36ORCC-AqIcHabu.js → cose-bilkent-JH36ORCC-CXSLFyCH.js} +1 -1
- package/dist/public/assets/cynefin-EF2NZ3EQ-BIcbDns7.js +1 -0
- package/dist/public/assets/{cynefinDiagram-L36ESFBY-7SyXzhRd.js → cynefinDiagram-L36ESFBY-DTv0Kn1r.js} +1 -1
- package/dist/public/assets/{d3-selection-DsahLieG.js → d3-selection-g4Hl3_NH.js} +1 -1
- package/dist/public/assets/{dagre-SPEB5RXH-DalaGtMS.js → dagre-SPEB5RXH-BujVqk5R.js} +1 -1
- package/dist/public/assets/{diagram-3B7GL73J-BcY-qB9G.js → diagram-3B7GL73J-Ds-VnLzP.js} +1 -1
- package/dist/public/assets/{diagram-DNEMPZML-NV7fbe0h.js → diagram-DNEMPZML-BBoIIK-a.js} +1 -1
- package/dist/public/assets/{diagram-L3MUGCDN-BPx4GHoj.js → diagram-L3MUGCDN-Glgd5N_n.js} +1 -1
- package/dist/public/assets/{diagram-LA4NIPWU-BeUxqmw1.js → diagram-LA4NIPWU-B4EODdUU.js} +1 -1
- package/dist/public/assets/{diagram-MHCOC4E2-Dlg1S5na.js → diagram-MHCOC4E2-pzDDXO2J.js} +1 -1
- package/dist/public/assets/{diagram-XPFHEONP-DQhRoMkK.js → diagram-XPFHEONP-l--gwSuK.js} +1 -1
- package/dist/public/assets/{dist-CQU8zJh_.js → dist-C0u3lAFR.js} +1 -1
- package/dist/public/assets/{ebnfDiagram-UZSYDL2S-gVEs3Um2.js → ebnfDiagram-UZSYDL2S-BVfPeaVX.js} +1 -1
- package/dist/public/assets/{editor.api-SQ1snuat.js → editor.api-BMcewI3C.js} +1 -1
- package/dist/public/assets/{elk-XV6XMXQE-CHtlrPwu.js → elk-XV6XMXQE-BFJtUnG9.js} +1 -1
- package/dist/public/assets/{erDiagram-EYBAPDEH-B0xok726.js → erDiagram-EYBAPDEH-BWxMtfIc.js} +1 -1
- package/dist/public/assets/{eventmodeling-K75KTNOO-CFwphA0e.js → eventmodeling-K75KTNOO-YwYgBgCX.js} +1 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-Dah4--NW.js +1 -0
- package/dist/public/assets/{freemarker2-DJKO-X2B.js → freemarker2-B8HquI7K.js} +1 -1
- package/dist/public/assets/{ganttDiagram-23REXITY-B5wVGN1A.js → ganttDiagram-23REXITY-CBqv7wbi.js} +1 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BwDfrSZS.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-STJD7YCW-DEjNU1R_.js → gitGraphDiagram-STJD7YCW-BLSf23f_.js} +1 -1
- package/dist/public/assets/{handlebars-ChVN7JPd.js → handlebars-P1qmNq4N.js} +1 -1
- package/dist/public/assets/{html-CQ0znKSa.js → html-Ceswbytr.js} +1 -1
- package/dist/public/assets/{index-CLlacdXR.js → index-10isUUN4.js} +2 -2
- package/dist/public/assets/info-OHQRW6UA-Ch8aMV1p.js +1 -0
- package/dist/public/assets/{infoDiagram-KBXO4MBG-CJtrS72M.js → infoDiagram-KBXO4MBG-LvOtgUlm.js} +1 -1
- package/dist/public/assets/{ishikawaDiagram-M35NCXHK-qYI1QBsK.js → ishikawaDiagram-M35NCXHK-CwUZOvcm.js} +1 -1
- package/dist/public/assets/{javascript-B-DHbkyI.js → javascript-B3FXC8qR.js} +1 -1
- package/dist/public/assets/{journeyDiagram-OPLOXDXO-BOQ2y2ZZ.js → journeyDiagram-OPLOXDXO-5j1KtwTt.js} +1 -1
- package/dist/public/assets/{jsonMode-XuGC5N_z.js → jsonMode-CrCyxNQI.js} +1 -1
- package/dist/public/assets/{kanban-definition-BZKZHSQY-BJ64tKdP.js → kanban-definition-BZKZHSQY-BKAB5id1.js} +1 -1
- package/dist/public/assets/{liquid-B0Ujylzc.js → liquid-CXZRIgp2.js} +1 -1
- package/dist/public/assets/{mdx-B19-V510.js → mdx-Dm3uNczM.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-Scb01iBq.js → mermaid-parser.core-C755A-rX.js} +3 -3
- package/dist/public/assets/{mermaid.core-BMuvs7us.js → mermaid.core-CQrYmFAR.js} +4 -4
- package/dist/public/assets/{mindmap-definition-I2QAS2VK-BYfOS3XN.js → mindmap-definition-I2QAS2VK-DNJQKYbK.js} +1 -1
- package/dist/public/assets/module-9otB6_kX.js +1 -0
- package/dist/public/assets/{module-Cm_mLwAQ.js → module-C3jC5acf.js} +1 -1
- package/dist/public/assets/module-C_MyFORb.js +1 -0
- package/dist/public/assets/module-Cjpl4gva.js +1 -0
- package/dist/public/assets/{module-DUYj4E8T.js → module-D8yH9xCl.js} +1 -1
- package/dist/public/assets/module-DlHjBjOg.js +1 -0
- package/dist/public/assets/module-QsLiJaR6.js +1 -0
- package/dist/public/assets/module-aaW5Ri2L.js +2771 -0
- package/dist/public/assets/module-gSy9fKBo.js +1 -0
- package/dist/public/assets/{monaco-Bbe2os7m.js → monaco-BS7JBNW4.js} +3 -3
- package/dist/public/assets/packet-JDAUHWVQ-LqMrrc60.js +1 -0
- package/dist/public/assets/{pegDiagram-FD4XPPHP-D-Vlq9Gm.js → pegDiagram-FD4XPPHP-BzbBCWht.js} +1 -1
- package/dist/public/assets/pie-XZMESJXO-BWzABXQU.js +1 -0
- package/dist/public/assets/{pieDiagram-J4AKIIQI-_-94-aMD.js → pieDiagram-J4AKIIQI-Bf_LDukL.js} +1 -1
- package/dist/public/assets/{python-CWnMIOYq.js → python-jgOUhB-F.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-XTYBLID2-BhFUbUYz.js → quadrantDiagram-XTYBLID2-CdMHWnKX.js} +1 -1
- package/dist/public/assets/radar-ABXABTNO-CR4kNiUj.js +1 -0
- package/dist/public/assets/railroad-I3PHUGI6-BAkWtkGC.js +1 -0
- package/dist/public/assets/{railroad-abnf-LNEFI6M7-yUa9GGCQ.js → railroad-abnf-LNEFI6M7-DQGYaRbc.js} +1 -1
- package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-xY4YiL8M.js → railroad-ebnf-DWYD2UWJ-D6Ljza0U.js} +1 -1
- package/dist/public/assets/{railroad-peg-JR7BVNR7-BYFYCUAQ.js → railroad-peg-JR7BVNR7-Du9hL1Gf.js} +1 -1
- package/dist/public/assets/{railroadDiagram-MRQ6NCDL-C9FVhj0k.js → railroadDiagram-MRQ6NCDL-CS_JnlGN.js} +1 -1
- package/dist/public/assets/{razor-bDtpN6EJ.js → razor-BWj90God.js} +1 -1
- package/dist/public/assets/{requirementDiagram-Y7LWUY3S-DLmAg-6C.js → requirementDiagram-Y7LWUY3S-Cq8rRz2y.js} +1 -1
- package/dist/public/assets/{resolver-0zC31mg5.js → resolver-BPuspqws.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-WGJFYUXA-Bl5IpDk4.js → sankeyDiagram-WGJFYUXA-aK7jRBVK.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-5NDRBG5M-Z-N0OiT_.js → sequenceDiagram-5NDRBG5M-BxcIyc38.js} +1 -1
- package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-ctKQz8Mo.js → stateDiagram-v2-FJ4FJNEA-Ctletlj4.js} +1 -1
- package/dist/public/assets/{swimlanes-UMQ2AFYF-CWLKnALg.js → swimlanes-UMQ2AFYF-DaD55xd2.js} +1 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CytCT4x3.js +8 -0
- package/dist/public/assets/{timeline-definition-SEUHKTQE-DP8Ph_d6.js → timeline-definition-SEUHKTQE-Ce19CDiJ.js} +1 -1
- package/dist/public/assets/treeView-D4JQ5SDB-DvzNkX4G.js +1 -0
- package/dist/public/assets/treemap-SAJKECNS-BuUeBmMd.js +1 -0
- package/dist/public/assets/{typescript-CGpNlLbn.js → typescript-RgyfxmPQ.js} +1 -1
- package/dist/public/assets/{usecaseDiagram-AFA6YXN4-DvFjNj3J.js → usecaseDiagram-AFA6YXN4-CAVEBKQS.js} +1 -1
- package/dist/public/assets/{vennDiagram-NNMJR3RB-3m2F2H-I.js → vennDiagram-NNMJR3RB-DHyJxlHv.js} +1 -1
- package/dist/public/assets/wardley-7MLQ67FV-DSfdKACG.js +1 -0
- package/dist/public/assets/{wardleyDiagram-S7YFUSEH-CsMntu16.js → wardleyDiagram-S7YFUSEH-C-FCHxR7.js} +1 -1
- package/dist/public/assets/{xml-ByiLoakX.js → xml-DiA1T3iN.js} +1 -1
- package/dist/public/assets/{xychartDiagram-GGNKY7IX-C80rxvM0.js → xychartDiagram-GGNKY7IX-BlnHU6Gz.js} +1 -1
- package/dist/public/assets/{yaml-Cz2Af5Rj.js → yaml-dnCcfJBR.js} +1 -1
- package/dist/public/ext/index.json +1 -0
- package/dist/public/ext/ta-3d.js +660 -0
- package/dist/public/ext/ta-glance.js +1611 -0
- package/dist/public/ext/ta-plot.js +1320 -0
- package/dist/public/index.html +2 -2
- package/dist/serve/index.mjs +17829 -14233
- package/package.json +45 -39
- package/dist/public/assets/cynefin-EF2NZ3EQ-yFytgtiy.js +0 -1
- package/dist/public/assets/flowDiagram-MALGAFMO-Cwye_DsX.js +0 -1
- package/dist/public/assets/gitGraph-VSP46ZUC-BYzb--zb.js +0 -1
- package/dist/public/assets/info-OHQRW6UA-na0qX3JP.js +0 -1
- package/dist/public/assets/module-B3SKdB70.js +0 -1
- package/dist/public/assets/module-DDH-aU6z.js +0 -1
- package/dist/public/assets/module-DOrYVZ7B.js +0 -2615
- package/dist/public/assets/module-DRofmFJn.js +0 -1
- package/dist/public/assets/module-MaD4hvv4.js +0 -1
- package/dist/public/assets/module-ZDJutm0b.js +0 -1
- package/dist/public/assets/module-qoBVcE5h.js +0 -1
- package/dist/public/assets/packet-JDAUHWVQ-jhCd70vR.js +0 -1
- package/dist/public/assets/pie-XZMESJXO-DV0NJFsI.js +0 -1
- package/dist/public/assets/radar-ABXABTNO-Co-Hlf34.js +0 -1
- package/dist/public/assets/railroad-I3PHUGI6-DKMPEjDD.js +0 -1
- package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CU76xJSu.js +0 -8
- package/dist/public/assets/treeView-D4JQ5SDB-JMMnu_MW.js +0 -1
- package/dist/public/assets/treemap-SAJKECNS-CPlAD3X1.js +0 -1
- package/dist/public/assets/wardley-7MLQ67FV-Dhc8wpLp.js +0 -1
package/dist/gateway.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// ../../ta-packages/ta-gateway/esm/node/gateway-cli.js
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { join as
|
|
3
|
+
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
|
|
8
|
-
import { createServer as createServer2, request as
|
|
9
|
-
import { request as
|
|
10
|
-
import { extname, join as
|
|
11
|
-
import { pipeline } from "node:stream";
|
|
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
|
+
import { extname, join as join9, normalize, sep } from "node:path";
|
|
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,19 +941,393 @@ 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) {
|
|
812
1289
|
TaLocation2.SSH = "ssh://";
|
|
1290
|
+
TaLocation2.CLOUD = "ta://";
|
|
1291
|
+
const CLOUD_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
813
1292
|
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
814
1293
|
function isRemote(location) {
|
|
815
|
-
return location.startsWith(TaLocation2.SSH);
|
|
1294
|
+
return location.startsWith(TaLocation2.SSH) || location.startsWith(TaLocation2.CLOUD);
|
|
816
1295
|
}
|
|
817
1296
|
TaLocation2.isRemote = isRemote;
|
|
1297
|
+
function isCloud(host2) {
|
|
1298
|
+
return !!host2 && host2.startsWith(TaLocation2.CLOUD);
|
|
1299
|
+
}
|
|
1300
|
+
TaLocation2.isCloud = isCloud;
|
|
1301
|
+
function isCloudName(name) {
|
|
1302
|
+
return CLOUD_NAME.test(name);
|
|
1303
|
+
}
|
|
1304
|
+
TaLocation2.isCloudName = isCloudName;
|
|
1305
|
+
function cloud(name, path2 = "") {
|
|
1306
|
+
return `${TaLocation2.CLOUD}${name}${path2 ? normalize(path2) : ""}`;
|
|
1307
|
+
}
|
|
1308
|
+
TaLocation2.cloud = cloud;
|
|
1309
|
+
function cloudName(hostOrLocation) {
|
|
1310
|
+
if (!hostOrLocation.startsWith(TaLocation2.CLOUD)) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
const rest = hostOrLocation.slice(TaLocation2.CLOUD.length);
|
|
1314
|
+
const slash = rest.indexOf("/");
|
|
1315
|
+
return slash < 0 ? rest : rest.slice(0, slash);
|
|
1316
|
+
}
|
|
1317
|
+
TaLocation2.cloudName = cloudName;
|
|
818
1318
|
function parse(location) {
|
|
1319
|
+
var _a;
|
|
819
1320
|
if (!isRemote(location)) {
|
|
820
1321
|
return;
|
|
821
1322
|
}
|
|
1323
|
+
if (location.startsWith(TaLocation2.CLOUD)) {
|
|
1324
|
+
const name = (_a = cloudName(location)) !== null && _a !== undefined ? _a : "";
|
|
1325
|
+
if (!isCloudName(name)) {
|
|
1326
|
+
throw new Error(`${JSON.stringify(location)} names no cloud workspace: write ta://<name>/<path>.`);
|
|
1327
|
+
}
|
|
1328
|
+
const path3 = location.slice(TaLocation2.CLOUD.length + name.length);
|
|
1329
|
+
return { host: `${TaLocation2.CLOUD}${name}`, path: path3 ? normalize(path3) : "" };
|
|
1330
|
+
}
|
|
822
1331
|
const rest = location.slice(TaLocation2.SSH.length);
|
|
823
1332
|
const slash = rest.indexOf("/");
|
|
824
1333
|
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
@@ -830,24 +1339,24 @@ var TaLocation;
|
|
|
830
1339
|
}
|
|
831
1340
|
TaLocation2.parse = parse;
|
|
832
1341
|
function isHost(host2) {
|
|
833
|
-
return HOST.test(host2);
|
|
1342
|
+
return isCloud(host2) ? isCloudName(host2.slice(TaLocation2.CLOUD.length)) : HOST.test(host2);
|
|
834
1343
|
}
|
|
835
1344
|
TaLocation2.isHost = isHost;
|
|
836
1345
|
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
837
1346
|
function readHost(input) {
|
|
838
|
-
const
|
|
839
|
-
if (
|
|
840
|
-
|
|
1347
|
+
const words2 = input.trim().split(/\s+/).filter(Boolean);
|
|
1348
|
+
if (words2[0] === "ssh") {
|
|
1349
|
+
words2.shift();
|
|
841
1350
|
}
|
|
842
1351
|
let destination;
|
|
843
1352
|
let port;
|
|
844
1353
|
let user;
|
|
845
1354
|
const options = [];
|
|
846
|
-
for (let i = 0;i <
|
|
847
|
-
const word =
|
|
1355
|
+
for (let i = 0;i < words2.length; i++) {
|
|
1356
|
+
const word = words2[i];
|
|
848
1357
|
const glued = /^-([pl])(.+)$/.exec(word);
|
|
849
1358
|
if (word === "-p" || word === "-l" || glued) {
|
|
850
|
-
const value = glued ? glued[2] :
|
|
1359
|
+
const value = glued ? glued[2] : words2[++i];
|
|
851
1360
|
if (value === undefined) {
|
|
852
1361
|
return { error: "invalid" };
|
|
853
1362
|
}
|
|
@@ -857,7 +1366,7 @@ var TaLocation;
|
|
|
857
1366
|
user = value;
|
|
858
1367
|
}
|
|
859
1368
|
} else if (word === "-o" || word.startsWith("-o")) {
|
|
860
|
-
const value = word === "-o" ?
|
|
1369
|
+
const value = word === "-o" ? words2[++i] : word.slice(2);
|
|
861
1370
|
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
862
1371
|
if (!option) {
|
|
863
1372
|
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
@@ -867,7 +1376,7 @@ var TaLocation;
|
|
|
867
1376
|
user = option[2];
|
|
868
1377
|
}
|
|
869
1378
|
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
870
|
-
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) &&
|
|
1379
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
|
|
871
1380
|
} else if (destination === undefined) {
|
|
872
1381
|
destination = word;
|
|
873
1382
|
} else {
|
|
@@ -894,10 +1403,13 @@ var TaLocation;
|
|
|
894
1403
|
}
|
|
895
1404
|
TaLocation2.readHost = readHost;
|
|
896
1405
|
function ssh(host2, path2 = "") {
|
|
897
|
-
return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
1406
|
+
return isCloud(host2) ? `${host2}${path2 ? normalize(path2) : ""}` : `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
898
1407
|
}
|
|
899
1408
|
TaLocation2.ssh = ssh;
|
|
900
1409
|
function hostLabel(host2) {
|
|
1410
|
+
if (isCloud(host2)) {
|
|
1411
|
+
return host2.slice(TaLocation2.CLOUD.length);
|
|
1412
|
+
}
|
|
901
1413
|
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
902
1414
|
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
903
1415
|
}
|
|
@@ -970,65 +1482,7 @@ var TaLocation;
|
|
|
970
1482
|
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
971
1483
|
}
|
|
972
1484
|
})(TaLocation || (TaLocation = {}));
|
|
973
|
-
// ../../ta-packages/ta-protocol/esm/common/
|
|
974
|
-
var TaPackageServer = Symbol("TaPackageServer");
|
|
975
|
-
var TaPackageTextUtil;
|
|
976
|
-
(function(TaPackageTextUtil2) {
|
|
977
|
-
function pick(text, language) {
|
|
978
|
-
var _a, _b, _c, _d, _e;
|
|
979
|
-
if (text === undefined || typeof text === "string") {
|
|
980
|
-
return text;
|
|
981
|
-
}
|
|
982
|
-
const base = language.split("-")[0];
|
|
983
|
-
const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
|
|
984
|
-
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];
|
|
985
|
-
}
|
|
986
|
-
TaPackageTextUtil2.pick = pick;
|
|
987
|
-
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
988
|
-
// ../../ta-packages/ta-protocol/esm/common/ta-protocol.js
|
|
989
|
-
var TaServer = Symbol("TaServer");
|
|
990
|
-
var TaClient = Symbol("TaClient");
|
|
991
|
-
var TA_WEBSOCKET_PATH = "/api/ws";
|
|
992
|
-
var TaErrorCode = {
|
|
993
|
-
SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
|
|
994
|
-
SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
|
|
995
|
-
TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
|
|
996
|
-
MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
|
|
997
|
-
MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
|
|
998
|
-
INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
|
|
999
|
-
COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
|
|
1000
|
-
NOTHING_TO_COMPACT: "CELL_TA_NOTHING_TO_COMPACT",
|
|
1001
|
-
ALREADY_COMPACTED: "CELL_TA_ALREADY_COMPACTED",
|
|
1002
|
-
SESSION_BUSY: "CELL_TA_SESSION_BUSY",
|
|
1003
|
-
CANCELLED: "CELL_TA_CANCELLED",
|
|
1004
|
-
NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
|
|
1005
|
-
ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
|
|
1006
|
-
RATE_LIMITED: "CELL_TA_RATE_LIMITED",
|
|
1007
|
-
FORBIDDEN: "CELL_TA_FORBIDDEN",
|
|
1008
|
-
LIMIT: "CELL_TA_LIMIT",
|
|
1009
|
-
CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
|
|
1010
|
-
};
|
|
1011
|
-
var TaErrorUtil;
|
|
1012
|
-
(function(TaErrorUtil2) {
|
|
1013
|
-
function code(error) {
|
|
1014
|
-
var _a;
|
|
1015
|
-
var _b;
|
|
1016
|
-
const failure = error;
|
|
1017
|
-
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;
|
|
1018
|
-
return typeof code2 === "string" ? code2 : undefined;
|
|
1019
|
-
}
|
|
1020
|
-
TaErrorUtil2.code = code;
|
|
1021
|
-
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
1022
|
-
var TA_RPC_ERROR_CODE = -32050;
|
|
1023
|
-
var TaSlashCommandUtil;
|
|
1024
|
-
(function(TaSlashCommandUtil2) {
|
|
1025
|
-
function description(command, language) {
|
|
1026
|
-
var _a, _b;
|
|
1027
|
-
const { descriptions } = command;
|
|
1028
|
-
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;
|
|
1029
|
-
}
|
|
1030
|
-
TaSlashCommandUtil2.description = description;
|
|
1031
|
-
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
1485
|
+
// ../../ta-packages/ta-protocol/esm/common/message-protocol.js
|
|
1032
1486
|
var TaMessageContext;
|
|
1033
1487
|
(function(TaMessageContext2) {
|
|
1034
1488
|
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
@@ -1191,7 +1645,168 @@ var TaSkillUse;
|
|
|
1191
1645
|
}
|
|
1192
1646
|
TaSkillUse2.command = command;
|
|
1193
1647
|
})(TaSkillUse || (TaSkillUse = {}));
|
|
1194
|
-
|
|
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 = {}));
|
|
1195
1810
|
// ../../ta-packages/ta-protocol/esm/common/presence-protocol.js
|
|
1196
1811
|
var TaPresenceServer = Symbol("TaPresenceServer");
|
|
1197
1812
|
var TaMessageAuthor;
|
|
@@ -1269,98 +1884,19 @@ var TaRoomWatchUtil;
|
|
|
1269
1884
|
})(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
|
|
1270
1885
|
// ../../ta-packages/ta-protocol/esm/common/settings-protocol.js
|
|
1271
1886
|
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
1272
|
-
// ../../ta-packages/ta-protocol/esm/common/ta-
|
|
1273
|
-
var
|
|
1274
|
-
var
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
const request = {
|
|
1283
|
-
name,
|
|
1284
|
-
heard: () => {
|
|
1285
|
-
heard = true;
|
|
1286
|
-
},
|
|
1287
|
-
resolve: (answer) => {
|
|
1288
|
-
answered = true;
|
|
1289
|
-
clearTimeout(timer);
|
|
1290
|
-
resolve(answer);
|
|
1291
|
-
}
|
|
1292
|
-
};
|
|
1293
|
-
events.emit(TA_HOST_EVENT, request);
|
|
1294
|
-
if (!heard && !answered) {
|
|
1295
|
-
clearTimeout(timer);
|
|
1296
|
-
resolve(undefined);
|
|
1297
|
-
}
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1300
|
-
TaHostUtil2.reach = reach;
|
|
1301
|
-
function marked(systemPrompt, mark) {
|
|
1302
|
-
return role(systemPrompt).includes(mark);
|
|
1303
|
-
}
|
|
1304
|
-
TaHostUtil2.marked = marked;
|
|
1305
|
-
function role(systemPrompt) {
|
|
1306
|
-
if (!systemPrompt) {
|
|
1307
|
-
return "";
|
|
1308
|
-
}
|
|
1309
|
-
const open = `<addendum>
|
|
1310
|
-
`;
|
|
1311
|
-
const start = systemPrompt.indexOf(open);
|
|
1312
|
-
const context = systemPrompt.indexOf(`<project_context>
|
|
1313
|
-
`);
|
|
1314
|
-
if (start < 0 || context >= 0 && context < start) {
|
|
1315
|
-
return "";
|
|
1316
|
-
}
|
|
1317
|
-
const end = systemPrompt.indexOf(`
|
|
1318
|
-
</addendum>`, start);
|
|
1319
|
-
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
1320
|
-
}
|
|
1321
|
-
TaHostUtil2.role = role;
|
|
1322
|
-
})(TaHostUtil || (TaHostUtil = {}));
|
|
1323
|
-
var TA_ASK_ENTRY = "ta-ask";
|
|
1324
|
-
var TaAskUtil;
|
|
1325
|
-
(function(TaAskUtil2) {
|
|
1326
|
-
const LENGTH = 120;
|
|
1327
|
-
function entry(question) {
|
|
1328
|
-
const line = question.replace(/\s+/g, " ").trim();
|
|
1329
|
-
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
1330
|
-
}
|
|
1331
|
-
TaAskUtil2.entry = entry;
|
|
1332
|
-
function asking(entries) {
|
|
1333
|
-
var _a;
|
|
1334
|
-
for (let i = entries.length - 1;i >= 0; i--) {
|
|
1335
|
-
const entry2 = entries[i];
|
|
1336
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
1337
|
-
return;
|
|
1338
|
-
}
|
|
1339
|
-
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
1340
|
-
return read(entry2);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
return;
|
|
1344
|
-
}
|
|
1345
|
-
TaAskUtil2.asking = asking;
|
|
1346
|
-
function next(asked, entry2) {
|
|
1347
|
-
var _a;
|
|
1348
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
1352
|
-
}
|
|
1353
|
-
TaAskUtil2.next = next;
|
|
1354
|
-
function read(found) {
|
|
1355
|
-
var _a;
|
|
1356
|
-
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
1357
|
-
if (typeof question !== "string" || !question.trim()) {
|
|
1358
|
-
return;
|
|
1359
|
-
}
|
|
1360
|
-
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
1361
|
-
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;
|
|
1362
1897
|
}
|
|
1363
|
-
|
|
1898
|
+
TaSlashCommandUtil2.description = description;
|
|
1899
|
+
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
1364
1900
|
// ../../ta-packages/ta-protocol/esm/common/team-protocol.js
|
|
1365
1901
|
var TA_UNDECLARED = "extensions.install";
|
|
1366
1902
|
var TaPermissionUtil;
|
|
@@ -1452,6 +1988,8 @@ var TaActionUtil;
|
|
|
1452
1988
|
})(TaActionUtil || (TaActionUtil = {}));
|
|
1453
1989
|
// ../../ta-packages/ta-protocol/esm/common/usage-protocol.js
|
|
1454
1990
|
var TaUsageServer = Symbol("TaUsageServer");
|
|
1991
|
+
// ../../ta-packages/ta-protocol/esm/common/voice-protocol.js
|
|
1992
|
+
var TaVoiceServer = Symbol("TaVoiceServer");
|
|
1455
1993
|
// ../../ta-packages/ta-protocol/esm/common/workspace-protocol.js
|
|
1456
1994
|
var TA_FILES_PATH = "/api/files";
|
|
1457
1995
|
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
@@ -2123,10 +2661,11 @@ var SandboxProviders;
|
|
|
2123
2661
|
}
|
|
2124
2662
|
SandboxProviders2.create = create;
|
|
2125
2663
|
async function loadModule(entry, context) {
|
|
2664
|
+
var _a;
|
|
2126
2665
|
if (typeof entry.path !== "string" || !entry.path) {
|
|
2127
2666
|
throw new SandboxConfigError('A provider of the type "module" names its file in "path".');
|
|
2128
2667
|
}
|
|
2129
|
-
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);
|
|
2130
2669
|
const loaded = await import(pathToFileURL(path).href);
|
|
2131
2670
|
if (typeof loaded.default !== "function") {
|
|
2132
2671
|
throw new SandboxConfigError(`${path} has no default export of a function (id, config, context) => SandboxProvider.`);
|
|
@@ -2172,6 +2711,7 @@ class CommandSandbox {
|
|
|
2172
2711
|
this.id = id;
|
|
2173
2712
|
this.type = "command";
|
|
2174
2713
|
this.name = SandboxProviders.string(config, "name", id);
|
|
2714
|
+
this.gatewayUrl = SandboxProviders.string(config, "gatewayUrl");
|
|
2175
2715
|
const start = SandboxProviders.string(config, "start");
|
|
2176
2716
|
if (!start) {
|
|
2177
2717
|
throw new Error(`The provider "${id}" of the type command needs "start", a command that prints the address of the Ta service.`);
|
|
@@ -2213,7 +2753,15 @@ class CommandSandbox {
|
|
|
2213
2753
|
run(command, tenant, extra = {}) {
|
|
2214
2754
|
return new Promise((resolve, reject) => {
|
|
2215
2755
|
const child = spawn("sh", ["-c", command], {
|
|
2216
|
-
env: {
|
|
2756
|
+
env: {
|
|
2757
|
+
...process.env,
|
|
2758
|
+
...this.env,
|
|
2759
|
+
...tenant.env,
|
|
2760
|
+
TA_TENANT_ID: tenant.id,
|
|
2761
|
+
TA_TENANT_ACCOUNT: tenant.account,
|
|
2762
|
+
TA_SERVE_TOKEN: tenant.token,
|
|
2763
|
+
...extra
|
|
2764
|
+
},
|
|
2217
2765
|
stdio: ["ignore", "pipe", "pipe"]
|
|
2218
2766
|
});
|
|
2219
2767
|
let stdout = "";
|
|
@@ -2237,6 +2785,9 @@ class CommandSandbox {
|
|
|
2237
2785
|
}
|
|
2238
2786
|
}
|
|
2239
2787
|
|
|
2788
|
+
// ../../ta-packages/ta-gateway/esm/node/docker-sandbox.js
|
|
2789
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
2790
|
+
|
|
2240
2791
|
// ../../ta-packages/ta-gateway/esm/node/docker-engine.js
|
|
2241
2792
|
import { request } from "node:http";
|
|
2242
2793
|
|
|
@@ -2348,6 +2899,15 @@ class DockerEngine {
|
|
|
2348
2899
|
throw error;
|
|
2349
2900
|
}
|
|
2350
2901
|
}
|
|
2902
|
+
async remove(name) {
|
|
2903
|
+
try {
|
|
2904
|
+
await this.call("DELETE", `/containers/${encodeURIComponent(name)}?force=true`);
|
|
2905
|
+
} catch (error) {
|
|
2906
|
+
if (!(error instanceof DockerError && error.status === 404)) {
|
|
2907
|
+
throw error;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2351
2911
|
async ensureNetwork(name, isolated) {
|
|
2352
2912
|
try {
|
|
2353
2913
|
await this.call("GET", `/networks/${encodeURIComponent(name)}`);
|
|
@@ -2358,6 +2918,9 @@ class DockerEngine {
|
|
|
2358
2918
|
}
|
|
2359
2919
|
}
|
|
2360
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
|
+
}
|
|
2361
2924
|
await this.call("POST", "/networks/create", { Name: name, Driver: "bridge", Options: options, Labels: { "cell.ta.gateway": "1" } });
|
|
2362
2925
|
}
|
|
2363
2926
|
async ensureImage(image) {
|
|
@@ -2431,6 +2994,23 @@ var DockerEngineUtil;
|
|
|
2431
2994
|
// ../../ta-packages/ta-gateway/esm/node/docker-sandbox.js
|
|
2432
2995
|
var DockerSandboxUtil;
|
|
2433
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;
|
|
3009
|
+
function hasEnv(have, want) {
|
|
3010
|
+
const set = new Set(have !== null && have !== undefined ? have : []);
|
|
3011
|
+
return Object.entries(want !== null && want !== undefined ? want : {}).every(([key, value]) => set.has(`${key}=${value}`));
|
|
3012
|
+
}
|
|
3013
|
+
DockerSandboxUtil2.hasEnv = hasEnv;
|
|
2434
3014
|
function hostname(account) {
|
|
2435
3015
|
const name = account.slice(account.indexOf(":") + 1).split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48).replace(/-+$/, "");
|
|
2436
3016
|
return name || "ta";
|
|
@@ -2468,12 +3048,17 @@ class DockerSandbox {
|
|
|
2468
3048
|
this.options = options;
|
|
2469
3049
|
this.type = "docker";
|
|
2470
3050
|
this.name = SandboxProviders.string(config, "name", "Docker");
|
|
3051
|
+
this.gatewayUrl = SandboxProviders.string(config, "gatewayUrl");
|
|
2471
3052
|
this.engine = engine !== null && engine !== undefined ? engine : new DockerEngine({ host: options.host });
|
|
2472
3053
|
}
|
|
2473
3054
|
async start(tenant) {
|
|
2474
3055
|
var _a, _b, _c;
|
|
2475
3056
|
const name = this.containerName(tenant);
|
|
2476
3057
|
let container = await this.engine.inspect(name);
|
|
3058
|
+
if (container && !DockerSandboxUtil.sameEnv(container.Config, tenant.env)) {
|
|
3059
|
+
await this.engine.remove(name);
|
|
3060
|
+
container = undefined;
|
|
3061
|
+
}
|
|
2477
3062
|
if (!container) {
|
|
2478
3063
|
await this.engine.ensureImage(this.options.image);
|
|
2479
3064
|
await this.engine.ensureNetwork(this.options.network, true);
|
|
@@ -2503,29 +3088,436 @@ class DockerSandbox {
|
|
|
2503
3088
|
logs(tenant, lines) {
|
|
2504
3089
|
return this.engine.logs(this.containerName(tenant), lines);
|
|
2505
3090
|
}
|
|
2506
|
-
spec(tenant) {
|
|
2507
|
-
const name = this.containerName(tenant);
|
|
2508
|
-
return {
|
|
2509
|
-
Image: this.options.image,
|
|
2510
|
-
Hostname: DockerSandboxUtil.hostname(tenant.account),
|
|
2511
|
-
Env: [`TA_SERVE_TOKEN=${tenant.token}`, ...Object.entries(this.options.env).map(([key, value]) => `${key}=${value}`)],
|
|
2512
|
-
Labels: { "cell.ta.tenant": tenant.id, "cell.ta.account": tenant.account },
|
|
2513
|
-
ExposedPorts: { [PORT]: {} },
|
|
2514
|
-
HostConfig: {
|
|
2515
|
-
PortBindings: { [PORT]: [{ HostIp: this.options.bind, HostPort: "" }] },
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
3091
|
+
spec(tenant) {
|
|
3092
|
+
const name = this.containerName(tenant);
|
|
3093
|
+
return {
|
|
3094
|
+
Image: this.options.image,
|
|
3095
|
+
Hostname: DockerSandboxUtil.hostname(tenant.account),
|
|
3096
|
+
Env: [`TA_SERVE_TOKEN=${tenant.token}`, ...Object.entries({ ...this.options.env, ...tenant.env }).map(([key, value]) => `${key}=${value}`)],
|
|
3097
|
+
Labels: { "cell.ta.tenant": tenant.id, "cell.ta.account": tenant.account, [DockerSandboxUtil.ENV_LABEL]: DockerSandboxUtil.envHash(tenant.env) },
|
|
3098
|
+
ExposedPorts: { [PORT]: {} },
|
|
3099
|
+
HostConfig: {
|
|
3100
|
+
PortBindings: { [PORT]: [{ HostIp: this.options.bind, HostPort: "" }] },
|
|
3101
|
+
ExtraHosts: ["host.docker.internal:host-gateway"],
|
|
3102
|
+
Mounts: [{ Type: "volume", Source: name, Target: "/home/ta" }],
|
|
3103
|
+
NetworkMode: this.options.network,
|
|
3104
|
+
Memory: this.options.memory,
|
|
3105
|
+
NanoCpus: this.options.cpus ? Math.round(this.options.cpus * 1e9) : undefined,
|
|
3106
|
+
PidsLimit: this.options.pids,
|
|
3107
|
+
CapDrop: ["NET_RAW"],
|
|
3108
|
+
RestartPolicy: { Name: "unless-stopped" },
|
|
3109
|
+
Init: false
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
containerName(tenant) {
|
|
3114
|
+
return `${this.options.prefix}${tenant.id}`;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
|
|
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}`);
|
|
2526
3513
|
}
|
|
2527
|
-
|
|
2528
|
-
|
|
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
|
+
`);
|
|
2529
3521
|
}
|
|
2530
3522
|
}
|
|
2531
3523
|
|
|
@@ -2867,9 +3859,13 @@ class Environments {
|
|
|
2867
3859
|
running.error = undefined;
|
|
2868
3860
|
const starting = (async () => {
|
|
2869
3861
|
var _a2;
|
|
2870
|
-
|
|
2871
|
-
const
|
|
2872
|
-
|
|
3862
|
+
var _b;
|
|
3863
|
+
const { provider, own } = this.provider(tenant);
|
|
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 } : {} });
|
|
3868
|
+
await EnvironmentsUtil.waitReady(endpoint.url, (_b = this.settings.readyTimeoutMs) !== null && _b !== undefined ? _b : provider.readyTimeoutMs);
|
|
2873
3869
|
return endpoint;
|
|
2874
3870
|
})();
|
|
2875
3871
|
running.starting = starting;
|
|
@@ -3011,12 +4007,74 @@ class GatewayAudit {
|
|
|
3011
4007
|
}
|
|
3012
4008
|
}
|
|
3013
4009
|
|
|
4010
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-exec.js
|
|
4011
|
+
var MAX_QUEUED_BYTES = 16 * 1024 * 1024;
|
|
4012
|
+
|
|
4013
|
+
class GatewayExecProxy {
|
|
4014
|
+
constructor(outer, endpoint, release) {
|
|
4015
|
+
this.outer = outer;
|
|
4016
|
+
this.release = release;
|
|
4017
|
+
this.queued = [];
|
|
4018
|
+
this.queuedBytes = 0;
|
|
4019
|
+
this.closed = false;
|
|
4020
|
+
outer.onMessage((text) => this.send(text));
|
|
4021
|
+
outer.onClose(() => this.dispose());
|
|
4022
|
+
endpoint.then((found) => this.open(found), (error) => this.close(1011, `Your environment did not start: ${error.message}`.slice(0, 120)));
|
|
4023
|
+
}
|
|
4024
|
+
open(endpoint) {
|
|
4025
|
+
if (this.closed) {
|
|
4026
|
+
return;
|
|
4027
|
+
}
|
|
4028
|
+
const url = new URL(`${endpoint.url.replace(/^http/, "ws")}/api/exec`);
|
|
4029
|
+
url.searchParams.set("token", endpoint.token);
|
|
4030
|
+
const inner = new WebSocket(url);
|
|
4031
|
+
this.inner = inner;
|
|
4032
|
+
inner.onopen = () => {
|
|
4033
|
+
for (const text of this.queued.splice(0)) {
|
|
4034
|
+
inner.send(text);
|
|
4035
|
+
}
|
|
4036
|
+
this.queuedBytes = 0;
|
|
4037
|
+
};
|
|
4038
|
+
inner.onmessage = (message) => this.outer.open && this.outer.send(String(message.data));
|
|
4039
|
+
inner.onclose = (event) => this.close(event.code === 1000 || event.code === 1001 ? 1001 : 1011, "The sandbox closed the connection.");
|
|
4040
|
+
inner.onerror = () => {
|
|
4041
|
+
return;
|
|
4042
|
+
};
|
|
4043
|
+
}
|
|
4044
|
+
send(text) {
|
|
4045
|
+
var _a;
|
|
4046
|
+
if (((_a = this.inner) === null || _a === undefined ? undefined : _a.readyState) === WebSocket.OPEN) {
|
|
4047
|
+
this.inner.send(text);
|
|
4048
|
+
} else if (this.queuedBytes + text.length <= MAX_QUEUED_BYTES) {
|
|
4049
|
+
this.queued.push(text);
|
|
4050
|
+
this.queuedBytes += text.length;
|
|
4051
|
+
} else {
|
|
4052
|
+
this.close(1013, "The environment is still starting.");
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
close(code, reason) {
|
|
4056
|
+
if (this.outer.open) {
|
|
4057
|
+
this.outer.close(code, reason);
|
|
4058
|
+
}
|
|
4059
|
+
this.dispose();
|
|
4060
|
+
}
|
|
4061
|
+
dispose() {
|
|
4062
|
+
var _a;
|
|
4063
|
+
if (this.closed) {
|
|
4064
|
+
return;
|
|
4065
|
+
}
|
|
4066
|
+
this.closed = true;
|
|
4067
|
+
this.release();
|
|
4068
|
+
(_a = this.inner) === null || _a === undefined || _a.close();
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
|
|
3014
4072
|
// ../../ta-packages/ta-gateway/esm/node/gateway-policy.js
|
|
3015
4073
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
3016
4074
|
import { join as join4 } from "node:path";
|
|
3017
4075
|
|
|
3018
4076
|
// ../../ta-packages/ta-gateway/esm/node/tenant-store.js
|
|
3019
|
-
import { createHash as
|
|
4077
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "node:crypto";
|
|
3020
4078
|
import { chmodSync as chmodSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
3021
4079
|
import { join as join3 } from "node:path";
|
|
3022
4080
|
function writePrivate(file, data) {
|
|
@@ -3028,7 +4086,7 @@ function writePrivate(file, data) {
|
|
|
3028
4086
|
var TenantUtil;
|
|
3029
4087
|
(function(TenantUtil2) {
|
|
3030
4088
|
function id(account) {
|
|
3031
|
-
return
|
|
4089
|
+
return createHash5("sha256").update(account).digest("hex").slice(0, 16);
|
|
3032
4090
|
}
|
|
3033
4091
|
TenantUtil2.id = id;
|
|
3034
4092
|
})(TenantUtil || (TenantUtil = {}));
|
|
@@ -3069,6 +4127,7 @@ class TenantStore {
|
|
|
3069
4127
|
name: account.name,
|
|
3070
4128
|
avatar: account.avatar,
|
|
3071
4129
|
token: randomBytes3(32).toString("base64url"),
|
|
4130
|
+
modelKey: `tam-${randomBytes3(24).toString("base64url")}`,
|
|
3072
4131
|
createdAt: now
|
|
3073
4132
|
};
|
|
3074
4133
|
this.save(tenant);
|
|
@@ -3083,6 +4142,28 @@ class TenantStore {
|
|
|
3083
4142
|
this.save(next);
|
|
3084
4143
|
return next;
|
|
3085
4144
|
}
|
|
4145
|
+
modelKey(id) {
|
|
4146
|
+
var _a;
|
|
4147
|
+
const tenant = this.get(id);
|
|
4148
|
+
if (!tenant) {
|
|
4149
|
+
throw new Error(`No tenant ${id}`);
|
|
4150
|
+
}
|
|
4151
|
+
return (_a = tenant.modelKey) !== null && _a !== undefined ? _a : this.update(id, { modelKey: `tam-${randomBytes3(24).toString("base64url")}` }).modelKey;
|
|
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
|
+
}
|
|
3086
4167
|
list() {
|
|
3087
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);
|
|
3088
4169
|
}
|
|
@@ -3097,7 +4178,7 @@ class PolicyError extends Error {
|
|
|
3097
4178
|
}
|
|
3098
4179
|
var GatewayPolicyUtil;
|
|
3099
4180
|
(function(GatewayPolicyUtil2) {
|
|
3100
|
-
const NUMBERS = ["freeMinutes", "promptsPerMinute", "connections"];
|
|
4181
|
+
const NUMBERS = ["freeMinutes", "monthlyTokens", "promptsPerMinute", "connections"];
|
|
3101
4182
|
const RANK = { member: 0, admin: 1, owner: 2 };
|
|
3102
4183
|
function rank(role) {
|
|
3103
4184
|
return RANK[role];
|
|
@@ -3165,6 +4246,7 @@ var GatewayPolicyUtil;
|
|
|
3165
4246
|
const own_ = pick("own");
|
|
3166
4247
|
return {
|
|
3167
4248
|
freeMinutes: number("freeMinutes"),
|
|
4249
|
+
monthlyTokens: number("monthlyTokens"),
|
|
3168
4250
|
promptsPerMinute: number("promptsPerMinute"),
|
|
3169
4251
|
connections: number("connections"),
|
|
3170
4252
|
providers: Array.isArray(providers) ? providers : undefined,
|
|
@@ -3198,13 +4280,21 @@ class GatewayPolicy {
|
|
|
3198
4280
|
this.stored = { ...this.stored, defaults: limits };
|
|
3199
4281
|
writePrivate(this.file, this.stored);
|
|
3200
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
|
+
}
|
|
3201
4291
|
setRole(account, role) {
|
|
3202
4292
|
var _a;
|
|
3203
4293
|
const admins = ((_a = this.stored.admins) !== null && _a !== undefined ? _a : []).filter((other) => other !== account);
|
|
3204
4294
|
this.stored = { ...this.stored, admins: role === "admin" ? [...admins, account] : admins };
|
|
3205
4295
|
writePrivate(this.file, this.stored);
|
|
3206
4296
|
}
|
|
3207
|
-
view(idleMinutes) {
|
|
4297
|
+
view(idleMinutes, egress = { enabled: false, networks: [] }) {
|
|
3208
4298
|
var _a;
|
|
3209
4299
|
return {
|
|
3210
4300
|
defaults: this.defaults,
|
|
@@ -3212,7 +4302,8 @@ class GatewayPolicy {
|
|
|
3212
4302
|
...this.owners.map((account) => ({ account, role: "owner" })),
|
|
3213
4303
|
...((_a = this.stored.admins) !== null && _a !== undefined ? _a : []).filter((account) => this.role(account) === "admin").map((account) => ({ account, role: "admin" }))
|
|
3214
4304
|
],
|
|
3215
|
-
idleMinutes
|
|
4305
|
+
idleMinutes,
|
|
4306
|
+
egress: { enabled: egress.enabled, hosts: this.egressHosts, networks: egress.networks }
|
|
3216
4307
|
};
|
|
3217
4308
|
}
|
|
3218
4309
|
read() {
|
|
@@ -3357,11 +4448,12 @@ var MINUTE = 60000;
|
|
|
3357
4448
|
var MAX_TICK_MS = 2 * MINUTE;
|
|
3358
4449
|
|
|
3359
4450
|
class GatewayQuotas {
|
|
3360
|
-
constructor(policy, tenants, usage, ownAllowed) {
|
|
4451
|
+
constructor(policy, tenants, usage, ownAllowed, metered = () => false) {
|
|
3361
4452
|
this.policy = policy;
|
|
3362
4453
|
this.tenants = tenants;
|
|
3363
4454
|
this.usage = usage;
|
|
3364
4455
|
this.ownAllowed = ownAllowed;
|
|
4456
|
+
this.metered = metered;
|
|
3365
4457
|
this.lastTick = Date.now();
|
|
3366
4458
|
this.prompts = new Map;
|
|
3367
4459
|
}
|
|
@@ -3388,20 +4480,59 @@ class GatewayQuotas {
|
|
|
3388
4480
|
return freeMinutes !== undefined && meter.runMs >= (freeMinutes + meter.bonusMinutes) * MINUTE ? "minutes" : undefined;
|
|
3389
4481
|
}
|
|
3390
4482
|
state(tenant, now = Date.now()) {
|
|
4483
|
+
var _a, _b;
|
|
3391
4484
|
const { key, next } = GatewayUsageUtil.month(now);
|
|
3392
4485
|
const meter = this.meter(tenant, now);
|
|
3393
4486
|
const limits = this.limits(tenant);
|
|
3394
|
-
const
|
|
4487
|
+
const metered = this.metered();
|
|
4488
|
+
const month = metered ? { tokens: (_a = meter.tokens) !== null && _a !== undefined ? _a : 0, cost: (_b = meter.cost) !== null && _b !== undefined ? _b : 0 } : this.usage.month(tenant.id, now);
|
|
3395
4489
|
return {
|
|
3396
4490
|
month: key,
|
|
3397
4491
|
resetsAt: next,
|
|
3398
4492
|
minutes: { used: Math.floor(meter.runMs / MINUTE), limit: limits.freeMinutes, bonus: meter.bonusMinutes },
|
|
3399
|
-
tokens: { used: month.tokens, cost: month.cost },
|
|
4493
|
+
tokens: { used: month.tokens, cost: month.cost, limit: metered ? limits.monthlyTokens : undefined, metered },
|
|
3400
4494
|
promptsPerMinute: limits.promptsPerMinute,
|
|
3401
4495
|
connections: limits.connections,
|
|
3402
|
-
blocked: this.blocked(tenant, now)
|
|
4496
|
+
blocked: this.blocked(tenant, now),
|
|
4497
|
+
...this.egressState(tenant, meter)
|
|
3403
4498
|
};
|
|
3404
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
|
+
}
|
|
4515
|
+
refuseModels(tenant, now = Date.now()) {
|
|
4516
|
+
var _a;
|
|
4517
|
+
if (this.role(tenant) === "owner") {
|
|
4518
|
+
return;
|
|
4519
|
+
}
|
|
4520
|
+
if (tenant.suspended) {
|
|
4521
|
+
return "Your account is suspended by an administrator of the gateway.";
|
|
4522
|
+
}
|
|
4523
|
+
const limit = this.limits(tenant).monthlyTokens;
|
|
4524
|
+
const used = (_a = this.meter(tenant, now).tokens) !== null && _a !== undefined ? _a : 0;
|
|
4525
|
+
return limit !== undefined && used >= limit ? `Monthly usage limit reached: ${used} of ${limit} tokens this month; it starts again next month, or ask an administrator.` : undefined;
|
|
4526
|
+
}
|
|
4527
|
+
addTokens(tenantId, tokens, cost, now = Date.now()) {
|
|
4528
|
+
var _a, _b;
|
|
4529
|
+
const tenant = this.tenants.get(tenantId);
|
|
4530
|
+
if (!tenant) {
|
|
4531
|
+
return;
|
|
4532
|
+
}
|
|
4533
|
+
const meter = this.meter(tenant, now);
|
|
4534
|
+
this.tenants.update(tenantId, { meter: { ...meter, tokens: ((_a = meter.tokens) !== null && _a !== undefined ? _a : 0) + tokens, cost: ((_b = meter.cost) !== null && _b !== undefined ? _b : 0) + cost } });
|
|
4535
|
+
}
|
|
3405
4536
|
takePrompt(tenant, now = Date.now()) {
|
|
3406
4537
|
var _a;
|
|
3407
4538
|
const limit = this.limits(tenant).promptsPerMinute;
|
|
@@ -3448,15 +4579,15 @@ class GatewayQuotas {
|
|
|
3448
4579
|
// ../../ta-packages/ta-protocol/esm/common/redactor.js
|
|
3449
4580
|
var REDACTED = "[redacted]";
|
|
3450
4581
|
var WHOLE = [
|
|
3451
|
-
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
|
|
3452
|
-
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
|
|
3453
|
-
/\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
|
|
3454
|
-
/\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
|
|
3455
|
-
/\bglpat-[A-Za-z0-9_-]{20,}\b/g,
|
|
3456
|
-
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
3457
|
-
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
3458
|
-
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
3459
|
-
/\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]
|
|
3460
4591
|
];
|
|
3461
4592
|
var NAMED = [
|
|
3462
4593
|
/(\bBearer\s+)[A-Za-z0-9._~+/-]{16,}=*/gi,
|
|
@@ -3470,7 +4601,7 @@ class Redactor {
|
|
|
3470
4601
|
}
|
|
3471
4602
|
text(text) {
|
|
3472
4603
|
let out = text;
|
|
3473
|
-
for (const pattern of WHOLE) {
|
|
4604
|
+
for (const [, pattern] of WHOLE) {
|
|
3474
4605
|
out = out.replace(pattern, () => this.hide());
|
|
3475
4606
|
}
|
|
3476
4607
|
out = out.replace(NAMED[0], (_match, before) => before + this.hide());
|
|
@@ -3490,6 +4621,39 @@ class Redactor {
|
|
|
3490
4621
|
}
|
|
3491
4622
|
return value;
|
|
3492
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
|
+
}
|
|
3493
4657
|
static cut(text, max) {
|
|
3494
4658
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
3495
4659
|
}
|
|
@@ -3502,7 +4666,7 @@ class Redactor {
|
|
|
3502
4666
|
}
|
|
3503
4667
|
}
|
|
3504
4668
|
|
|
3505
|
-
// ../../ta-packages/ta-gateway/esm/node/gateway-service.js
|
|
4669
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-service-util.js
|
|
3506
4670
|
class GatewayCallError extends Error {
|
|
3507
4671
|
constructor(message, code, hint) {
|
|
3508
4672
|
super(message);
|
|
@@ -3510,7 +4674,6 @@ class GatewayCallError extends Error {
|
|
|
3510
4674
|
this.hint = hint;
|
|
3511
4675
|
}
|
|
3512
4676
|
}
|
|
3513
|
-
var DAY2 = 24 * 3600000;
|
|
3514
4677
|
var GatewayServiceUtil;
|
|
3515
4678
|
(function(GatewayServiceUtil2) {
|
|
3516
4679
|
GatewayServiceUtil2.DEFAULT_LOG_LINES = 200;
|
|
@@ -3536,7 +4699,9 @@ var GatewayServiceUtil;
|
|
|
3536
4699
|
grantMinutes: "admin",
|
|
3537
4700
|
setSuspended: "admin",
|
|
3538
4701
|
setDefaultLimits: "owner",
|
|
3539
|
-
setRole: "owner"
|
|
4702
|
+
setRole: "owner",
|
|
4703
|
+
setEgressHosts: "owner",
|
|
4704
|
+
createAccessToken: "anyone"
|
|
3540
4705
|
},
|
|
3541
4706
|
TaAccessServer: {
|
|
3542
4707
|
getAccess: "anyone",
|
|
@@ -3559,6 +4724,7 @@ var GatewayServiceUtil;
|
|
|
3559
4724
|
"setSuspended",
|
|
3560
4725
|
"setDefaultLimits",
|
|
3561
4726
|
"setRole",
|
|
4727
|
+
"setEgressHosts",
|
|
3562
4728
|
"allow",
|
|
3563
4729
|
"dismiss",
|
|
3564
4730
|
"disallow"
|
|
@@ -3619,48 +4785,450 @@ var GatewayServiceUtil;
|
|
|
3619
4785
|
if (!providers.includes(given.provider)) {
|
|
3620
4786
|
throw invalid(`The gateway has no provider ${given.provider} for you.`, "Pick one of the options of getGateway.");
|
|
3621
4787
|
}
|
|
3622
|
-
return { provider: given.provider };
|
|
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 {
|
|
4870
|
+
config = JSON.parse(readFileSync7(file, "utf8"));
|
|
4871
|
+
} catch (error2) {
|
|
4872
|
+
throw new ModelConfigError(`${file} is not JSON: ${error2.message}`);
|
|
4873
|
+
}
|
|
4874
|
+
for (const [id, provider] of Object.entries((_a = config.providers) !== null && _a !== undefined ? _a : {})) {
|
|
4875
|
+
if (!ID.test(id)) {
|
|
4876
|
+
throw new ModelConfigError(`"${id}" cannot name a provider of models: letters, digits, . _ and -.`);
|
|
4877
|
+
}
|
|
4878
|
+
if (typeof (provider === null || provider === undefined ? undefined : provider.baseUrl) !== "string" || !/^https?:\/\//.test(provider.baseUrl) || typeof provider.api !== "string" || !Array.isArray(provider.models)) {
|
|
4879
|
+
throw new ModelConfigError(`The provider of models "${id}" needs baseUrl (http or https), api and models, as pi's models.json.`);
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
return config;
|
|
4883
|
+
}
|
|
4884
|
+
ModelProxyUtil2.read = read;
|
|
4885
|
+
function key(value, env = process.env) {
|
|
4886
|
+
if (!value) {
|
|
4887
|
+
return;
|
|
4888
|
+
}
|
|
4889
|
+
const name = value.startsWith("$") ? value.slice(1) : value;
|
|
4890
|
+
if (/^[A-Z][A-Z0-9_]*$/.test(name) && env[name]) {
|
|
4891
|
+
return env[name];
|
|
4892
|
+
}
|
|
4893
|
+
return value.startsWith("$") ? undefined : value;
|
|
4894
|
+
}
|
|
4895
|
+
ModelProxyUtil2.key = key;
|
|
4896
|
+
function catalog(config) {
|
|
4897
|
+
var _a;
|
|
4898
|
+
return {
|
|
4899
|
+
providers: Object.entries((_a = config.providers) !== null && _a !== undefined ? _a : {}).map(([id, provider]) => ({
|
|
4900
|
+
id,
|
|
4901
|
+
name: provider.name,
|
|
4902
|
+
api: provider.api,
|
|
4903
|
+
models: provider.models.map((model) => ({ ...model }))
|
|
4904
|
+
}))
|
|
4905
|
+
};
|
|
4906
|
+
}
|
|
4907
|
+
ModelProxyUtil2.catalog = catalog;
|
|
4908
|
+
function presented(request2) {
|
|
4909
|
+
var _a, _b;
|
|
4910
|
+
const bearer = request2.headers.authorization;
|
|
4911
|
+
if (bearer === null || bearer === undefined ? undefined : bearer.startsWith("Bearer ")) {
|
|
4912
|
+
return bearer.slice("Bearer ".length).trim();
|
|
4913
|
+
}
|
|
4914
|
+
for (const name of ["x-api-key", "x-goog-api-key", "api-key"]) {
|
|
4915
|
+
const value = request2.headers[name];
|
|
4916
|
+
if (typeof value === "string" && value) {
|
|
4917
|
+
return value.trim();
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
return (_b = new URL((_a = request2.url) !== null && _a !== undefined ? _a : "/", "http://gateway").searchParams.get("key")) !== null && _b !== undefined ? _b : undefined;
|
|
4921
|
+
}
|
|
4922
|
+
ModelProxyUtil2.presented = presented;
|
|
4923
|
+
function authHeaders(api, key2) {
|
|
4924
|
+
if (!key2) {
|
|
4925
|
+
return {};
|
|
4926
|
+
}
|
|
4927
|
+
if (api.startsWith("anthropic")) {
|
|
4928
|
+
return { "x-api-key": key2 };
|
|
4929
|
+
}
|
|
4930
|
+
if (api.startsWith("google")) {
|
|
4931
|
+
return { "x-goog-api-key": key2 };
|
|
4932
|
+
}
|
|
4933
|
+
if (api.includes("azure")) {
|
|
4934
|
+
return { "api-key": key2 };
|
|
4935
|
+
}
|
|
4936
|
+
return { authorization: `Bearer ${key2}` };
|
|
4937
|
+
}
|
|
4938
|
+
ModelProxyUtil2.authHeaders = authHeaders;
|
|
4939
|
+
function target(baseUrl, rest, query) {
|
|
4940
|
+
const params = new URLSearchParams(query);
|
|
4941
|
+
params.delete("key");
|
|
4942
|
+
const search = params.toString();
|
|
4943
|
+
return `${baseUrl.replace(/\/+$/, "")}${rest}${search ? `?${search}` : ""}`;
|
|
4944
|
+
}
|
|
4945
|
+
ModelProxyUtil2.target = target;
|
|
4946
|
+
function number(value) {
|
|
4947
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
4948
|
+
}
|
|
4949
|
+
function usageOf(value) {
|
|
4950
|
+
var _a, _b, _c, _d;
|
|
4951
|
+
var _e, _f, _g;
|
|
4952
|
+
if (!value || typeof value !== "object") {
|
|
4953
|
+
return;
|
|
4954
|
+
}
|
|
4955
|
+
const object = value;
|
|
4956
|
+
const usage = (_g = (_f = (_e = object.usage) !== null && _e !== undefined ? _e : (_a = object.message) === null || _a === undefined ? undefined : _a.usage) !== null && _f !== undefined ? _f : (_b = object.response) === null || _b === undefined ? undefined : _b.usage) !== null && _g !== undefined ? _g : object.usageMetadata;
|
|
4957
|
+
if (!usage || typeof usage !== "object") {
|
|
4958
|
+
return;
|
|
4959
|
+
}
|
|
4960
|
+
if ("promptTokenCount" in usage || "candidatesTokenCount" in usage) {
|
|
4961
|
+
const cached = number(usage.cachedContentTokenCount);
|
|
4962
|
+
return {
|
|
4963
|
+
input: Math.max(0, number(usage.promptTokenCount) - cached),
|
|
4964
|
+
output: number(usage.candidatesTokenCount) + number(usage.thoughtsTokenCount),
|
|
4965
|
+
cacheRead: cached,
|
|
4966
|
+
cacheWrite: 0
|
|
4967
|
+
};
|
|
4968
|
+
}
|
|
4969
|
+
if ("prompt_tokens" in usage || "completion_tokens" in usage) {
|
|
4970
|
+
const cached = number((_c = usage.prompt_tokens_details) === null || _c === undefined ? undefined : _c.cached_tokens);
|
|
4971
|
+
return { input: Math.max(0, number(usage.prompt_tokens) - cached), output: number(usage.completion_tokens), cacheRead: cached, cacheWrite: 0 };
|
|
4972
|
+
}
|
|
4973
|
+
if ("input_tokens" in usage || "output_tokens" in usage) {
|
|
4974
|
+
const cached = number((_d = usage.input_tokens_details) === null || _d === undefined ? undefined : _d.cached_tokens);
|
|
4975
|
+
return {
|
|
4976
|
+
input: Math.max(0, number(usage.input_tokens) - cached),
|
|
4977
|
+
output: number(usage.output_tokens),
|
|
4978
|
+
cacheRead: cached + number(usage.cache_read_input_tokens),
|
|
4979
|
+
cacheWrite: number(usage.cache_creation_input_tokens)
|
|
4980
|
+
};
|
|
4981
|
+
}
|
|
4982
|
+
return;
|
|
4983
|
+
}
|
|
4984
|
+
ModelProxyUtil2.usageOf = usageOf;
|
|
4985
|
+
function merge(into, next) {
|
|
4986
|
+
if (!next) {
|
|
4987
|
+
return into;
|
|
4988
|
+
}
|
|
4989
|
+
if (!into) {
|
|
4990
|
+
return { ...next };
|
|
4991
|
+
}
|
|
4992
|
+
return {
|
|
4993
|
+
input: Math.max(into.input, next.input),
|
|
4994
|
+
output: Math.max(into.output, next.output),
|
|
4995
|
+
cacheRead: Math.max(into.cacheRead, next.cacheRead),
|
|
4996
|
+
cacheWrite: Math.max(into.cacheWrite, next.cacheWrite)
|
|
4997
|
+
};
|
|
4998
|
+
}
|
|
4999
|
+
ModelProxyUtil2.merge = merge;
|
|
5000
|
+
function total(usage) {
|
|
5001
|
+
return usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
5002
|
+
}
|
|
5003
|
+
ModelProxyUtil2.total = total;
|
|
5004
|
+
function cost(usage, price) {
|
|
5005
|
+
var _a, _b, _c, _d;
|
|
5006
|
+
if (!price) {
|
|
5007
|
+
return 0;
|
|
5008
|
+
}
|
|
5009
|
+
return (usage.input * ((_a = price.input) !== null && _a !== undefined ? _a : 0) + usage.output * ((_b = price.output) !== null && _b !== undefined ? _b : 0) + usage.cacheRead * ((_c = price.cacheRead) !== null && _c !== undefined ? _c : 0) + usage.cacheWrite * ((_d = price.cacheWrite) !== null && _d !== undefined ? _d : 0)) / 1e6;
|
|
5010
|
+
}
|
|
5011
|
+
ModelProxyUtil2.cost = cost;
|
|
5012
|
+
function metered(api, body) {
|
|
5013
|
+
if (api !== "openai-completions") {
|
|
5014
|
+
return body;
|
|
5015
|
+
}
|
|
5016
|
+
let parsed;
|
|
5017
|
+
try {
|
|
5018
|
+
parsed = JSON.parse(body.toString("utf8"));
|
|
5019
|
+
} catch (_a) {
|
|
5020
|
+
return body;
|
|
5021
|
+
}
|
|
5022
|
+
if (!parsed || typeof parsed !== "object" || parsed.stream !== true) {
|
|
5023
|
+
return body;
|
|
5024
|
+
}
|
|
5025
|
+
const options = parsed.stream_options && typeof parsed.stream_options === "object" ? parsed.stream_options : {};
|
|
5026
|
+
return Buffer.from(JSON.stringify({ ...parsed, stream_options: { ...options, include_usage: true } }));
|
|
5027
|
+
}
|
|
5028
|
+
ModelProxyUtil2.metered = metered;
|
|
5029
|
+
function modelOf(body, rest) {
|
|
5030
|
+
var _a;
|
|
5031
|
+
const named = (_a = /\/models\/([^/:]+)/.exec(rest)) === null || _a === undefined ? undefined : _a[1];
|
|
5032
|
+
if (named) {
|
|
5033
|
+
return decodeURIComponent(named);
|
|
5034
|
+
}
|
|
5035
|
+
try {
|
|
5036
|
+
const model = JSON.parse(body.toString("utf8")).model;
|
|
5037
|
+
return typeof model === "string" ? model : undefined;
|
|
5038
|
+
} catch (_b) {
|
|
5039
|
+
return;
|
|
5040
|
+
}
|
|
5041
|
+
}
|
|
5042
|
+
ModelProxyUtil2.modelOf = modelOf;
|
|
5043
|
+
function error(response, status, message, type = "insufficient_quota") {
|
|
5044
|
+
if (response.headersSent) {
|
|
5045
|
+
response.destroy();
|
|
5046
|
+
return;
|
|
5047
|
+
}
|
|
5048
|
+
response.writeHead(status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
5049
|
+
response.end(JSON.stringify({ type: "error", error: { type, code: type, message } }));
|
|
5050
|
+
}
|
|
5051
|
+
ModelProxyUtil2.error = error;
|
|
5052
|
+
function sameKey(given, known) {
|
|
5053
|
+
return timingSafeEqual2(createHash6("sha256").update(given).digest(), createHash6("sha256").update(known).digest());
|
|
5054
|
+
}
|
|
5055
|
+
ModelProxyUtil2.sameKey = sameKey;
|
|
5056
|
+
})(ModelProxyUtil || (ModelProxyUtil = {}));
|
|
5057
|
+
|
|
5058
|
+
class ModelProxy {
|
|
5059
|
+
constructor(config, hooks, env = process.env) {
|
|
5060
|
+
this.config = config;
|
|
5061
|
+
this.hooks = hooks;
|
|
5062
|
+
this.env = env;
|
|
5063
|
+
}
|
|
5064
|
+
get enabled() {
|
|
5065
|
+
var _a;
|
|
5066
|
+
return Object.keys((_a = this.config.providers) !== null && _a !== undefined ? _a : {}).length > 0;
|
|
5067
|
+
}
|
|
5068
|
+
provider(id) {
|
|
5069
|
+
var _a;
|
|
5070
|
+
return new Map(Object.entries((_a = this.config.providers) !== null && _a !== undefined ? _a : {})).get(id);
|
|
5071
|
+
}
|
|
5072
|
+
async handle(request2, response) {
|
|
5073
|
+
var _a, _b;
|
|
5074
|
+
var _c, _d, _e, _f;
|
|
5075
|
+
response.setHeader("Cache-Control", "no-store");
|
|
5076
|
+
const url = new URL((_c = request2.url) !== null && _c !== undefined ? _c : "/", "http://gateway");
|
|
5077
|
+
const given = ModelProxyUtil.presented(request2);
|
|
5078
|
+
const tenant = given ? this.hooks.tenantOfKey(given) : undefined;
|
|
5079
|
+
if (!tenant) {
|
|
5080
|
+
ModelProxyUtil.error(response, 401, "This model key is not one of the gateway.", "authentication_error");
|
|
5081
|
+
return;
|
|
5082
|
+
}
|
|
5083
|
+
const rest = url.pathname.slice(ModelProxyUtil.PATH.length);
|
|
5084
|
+
if (rest === "" || rest === "/") {
|
|
5085
|
+
if (request2.method !== "GET") {
|
|
5086
|
+
ModelProxyUtil.error(response, 405, "Read the catalog with GET.", "invalid_request_error");
|
|
5087
|
+
return;
|
|
5088
|
+
}
|
|
5089
|
+
response.writeHead(200, { "Content-Type": "application/json" });
|
|
5090
|
+
response.end(JSON.stringify(ModelProxyUtil.catalog(this.config)));
|
|
5091
|
+
return;
|
|
3623
5092
|
}
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
5093
|
+
const id = rest.slice(1).split("/")[0];
|
|
5094
|
+
const provider = this.provider(id);
|
|
5095
|
+
if (!provider) {
|
|
5096
|
+
ModelProxyUtil.error(response, 404, `The gateway has no provider of models ${id}.`, "not_found_error");
|
|
5097
|
+
return;
|
|
5098
|
+
}
|
|
5099
|
+
const refused = this.hooks.refuse(tenant.id);
|
|
5100
|
+
if (refused) {
|
|
5101
|
+
ModelProxyUtil.error(response, 429, refused);
|
|
5102
|
+
return;
|
|
5103
|
+
}
|
|
5104
|
+
const received = await this.body(request2);
|
|
5105
|
+
if (!received) {
|
|
5106
|
+
ModelProxyUtil.error(response, 413, "The request is too large.", "invalid_request_error");
|
|
5107
|
+
return;
|
|
5108
|
+
}
|
|
5109
|
+
const body = ModelProxyUtil.metered(provider.api, received);
|
|
5110
|
+
const path = rest.slice(1 + id.length);
|
|
5111
|
+
const model = ModelProxyUtil.modelOf(body, path);
|
|
5112
|
+
const headers = {};
|
|
5113
|
+
for (const [name, value] of Object.entries(request2.headers)) {
|
|
5114
|
+
if (typeof value === "string" && !DROPPED_REQUEST.has(name)) {
|
|
5115
|
+
headers[name] = value;
|
|
3627
5116
|
}
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
5117
|
+
}
|
|
5118
|
+
Object.assign(headers, (_d = provider.headers) !== null && _d !== undefined ? _d : {}, ModelProxyUtil.authHeaders(provider.api, ModelProxyUtil.key(provider.apiKey, this.env)));
|
|
5119
|
+
const abort = new AbortController;
|
|
5120
|
+
response.once("close", () => abort.abort());
|
|
5121
|
+
let upstream;
|
|
5122
|
+
try {
|
|
5123
|
+
upstream = await fetch(ModelProxyUtil.target(provider.baseUrl, path, url.searchParams), {
|
|
5124
|
+
method: request2.method,
|
|
5125
|
+
headers,
|
|
5126
|
+
body: request2.method === "GET" || request2.method === "HEAD" ? undefined : new Uint8Array(body),
|
|
5127
|
+
signal: abort.signal
|
|
5128
|
+
});
|
|
5129
|
+
} catch (error) {
|
|
5130
|
+
ModelProxyUtil.error(response, 502, `The provider of models ${id} is not reachable: ${error.message}`, "api_error");
|
|
5131
|
+
return;
|
|
5132
|
+
}
|
|
5133
|
+
const out = {};
|
|
5134
|
+
upstream.headers.forEach((value, name) => {
|
|
5135
|
+
if (!DROPPED_RESPONSE.has(name)) {
|
|
5136
|
+
out[name] = value;
|
|
3633
5137
|
}
|
|
3634
|
-
|
|
3635
|
-
|
|
5138
|
+
});
|
|
5139
|
+
response.writeHead(upstream.status, out);
|
|
5140
|
+
const stream = ((_e = upstream.headers.get("content-type")) !== null && _e !== undefined ? _e : "").includes("event-stream");
|
|
5141
|
+
let usage;
|
|
5142
|
+
let text = "";
|
|
5143
|
+
const decoder = new TextDecoder;
|
|
5144
|
+
const reader = (_a = upstream.body) === null || _a === undefined ? undefined : _a.getReader();
|
|
5145
|
+
try {
|
|
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
|
+
}
|
|
5166
|
+
}
|
|
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) {}
|
|
5173
|
+
}
|
|
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));
|
|
3636
5181
|
}
|
|
3637
|
-
return { type: "ta", url, token: given.token.trim(), name: typeof given.name === "string" && given.name.trim() ? given.name.trim() : undefined };
|
|
3638
5182
|
}
|
|
3639
|
-
throw invalid("No environment was named.", 'Pass { provider } or { type: "ta", url, token }.');
|
|
3640
5183
|
}
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
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) {
|
|
3656
5217
|
return;
|
|
5218
|
+
}
|
|
5219
|
+
chunks.push(chunk);
|
|
3657
5220
|
}
|
|
5221
|
+
return Buffer.concat(chunks);
|
|
3658
5222
|
}
|
|
3659
|
-
|
|
3660
|
-
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
// ../../ta-packages/ta-gateway/esm/node/gateway-service.js
|
|
5226
|
+
var DAY2 = 24 * 3600000;
|
|
3661
5227
|
|
|
3662
5228
|
class GatewayService {
|
|
3663
5229
|
constructor(parts) {
|
|
5230
|
+
this.models = parts.models;
|
|
5231
|
+
this.egress = parts.egress;
|
|
3664
5232
|
this.flow = parts.flow;
|
|
3665
5233
|
this.tenants = parts.tenants;
|
|
3666
5234
|
this.environments = parts.environments;
|
|
@@ -3708,7 +5276,9 @@ class GatewayService {
|
|
|
3708
5276
|
grantMinutes: () => this.grantMinutes(caller, first, second),
|
|
3709
5277
|
setSuspended: () => this.setSuspended(caller, first, second),
|
|
3710
5278
|
setDefaultLimits: () => this.setDefaultLimits(first),
|
|
3711
|
-
setRole: () => this.setRole(caller, first, second)
|
|
5279
|
+
setRole: () => this.setRole(caller, first, second),
|
|
5280
|
+
setEgressHosts: () => this.setEgressHosts(first),
|
|
5281
|
+
createAccessToken: () => this.accessToken(caller, first)
|
|
3712
5282
|
} : {
|
|
3713
5283
|
getAccess: () => this.access(caller),
|
|
3714
5284
|
bindUrl: () => this.flow.bindUrl(String(first)),
|
|
@@ -3782,8 +5352,8 @@ class GatewayService {
|
|
|
3782
5352
|
};
|
|
3783
5353
|
}
|
|
3784
5354
|
async console(caller) {
|
|
3785
|
-
var _a;
|
|
3786
|
-
var
|
|
5355
|
+
var _a, _b;
|
|
5356
|
+
var _c, _d, _e;
|
|
3787
5357
|
const tenants = this.tenants.list();
|
|
3788
5358
|
const [usages, agents] = await Promise.all([
|
|
3789
5359
|
Promise.all(tenants.map((tenant) => this.environments.usage(tenant).catch(() => {
|
|
@@ -3796,9 +5366,9 @@ class GatewayService {
|
|
|
3796
5366
|
const counts = new Map;
|
|
3797
5367
|
for (const tenant of tenants) {
|
|
3798
5368
|
const { provider } = this.environments.info(tenant);
|
|
3799
|
-
counts.set(provider, ((
|
|
5369
|
+
counts.set(provider, ((_c = counts.get(provider)) !== null && _c !== undefined ? _c : 0) + 1);
|
|
3800
5370
|
}
|
|
3801
|
-
const fallback = (
|
|
5371
|
+
const fallback = (_d = this.environments.settings.default) !== null && _d !== undefined ? _d : (_a = this.environments.providers[0]) === null || _a === undefined ? undefined : _a.id;
|
|
3802
5372
|
return {
|
|
3803
5373
|
version: this.meta.version,
|
|
3804
5374
|
startedAt: this.meta.startedAt,
|
|
@@ -3822,11 +5392,29 @@ class GatewayService {
|
|
|
3822
5392
|
}),
|
|
3823
5393
|
requests: this.flow.store.info(caller.token).requests.length,
|
|
3824
5394
|
role: caller.role,
|
|
3825
|
-
policy: this.policyView()
|
|
5395
|
+
policy: this.policyView(),
|
|
5396
|
+
models: ModelProxyUtil.catalog((_e = (_b = this.models) === null || _b === undefined ? undefined : _b.config) !== null && _e !== undefined ? _e : {}).providers.map((provider) => ({
|
|
5397
|
+
id: provider.id,
|
|
5398
|
+
name: provider.name,
|
|
5399
|
+
api: provider.api,
|
|
5400
|
+
models: provider.models.length
|
|
5401
|
+
}))
|
|
3826
5402
|
};
|
|
3827
5403
|
}
|
|
3828
5404
|
policyView() {
|
|
3829
|
-
|
|
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();
|
|
3830
5418
|
}
|
|
3831
5419
|
tenant(id) {
|
|
3832
5420
|
const tenant = typeof id === "string" ? this.tenants.get(id) : undefined;
|
|
@@ -3932,6 +5520,14 @@ class GatewayService {
|
|
|
3932
5520
|
this.policy.setRole(id, role);
|
|
3933
5521
|
return this.policyView();
|
|
3934
5522
|
}
|
|
5523
|
+
accessToken(caller, label) {
|
|
5524
|
+
var _a;
|
|
5525
|
+
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== undefined ? _a : caller.tenant;
|
|
5526
|
+
const device = typeof label === "string" && label.trim() ? label.trim().slice(0, 60) : "Another Ta";
|
|
5527
|
+
const token = this.flow.store.signIn({ id: caller.account, name: tenant.name, avatar: tenant.avatar }, device);
|
|
5528
|
+
console.log(`ta gateway: ${caller.account} made a token for ${device}`);
|
|
5529
|
+
return { token, url: this.meta.publicUrl };
|
|
5530
|
+
}
|
|
3935
5531
|
access(caller) {
|
|
3936
5532
|
const providers = this.flow.providers.map(({ id, name }) => ({ id, name }));
|
|
3937
5533
|
const info = this.flow.store.info(caller.token);
|
|
@@ -3987,7 +5583,7 @@ class GatewayService {
|
|
|
3987
5583
|
|
|
3988
5584
|
// ../../ta-packages/ta-gateway/esm/node/gateway-socket.js
|
|
3989
5585
|
var MAX_QUEUED = 256;
|
|
3990
|
-
var
|
|
5586
|
+
var MAX_QUEUED_BYTES2 = 16 * 1024 * 1024;
|
|
3991
5587
|
var FLOOD_MESSAGES = 2000;
|
|
3992
5588
|
var FLOOD_WINDOW_MS = 1e4;
|
|
3993
5589
|
|
|
@@ -4110,7 +5706,7 @@ class GatewaySocket {
|
|
|
4110
5706
|
var _a;
|
|
4111
5707
|
if (((_a = this.inner) === null || _a === undefined ? undefined : _a.readyState) === WebSocket.OPEN) {
|
|
4112
5708
|
this.inner.send(text);
|
|
4113
|
-
} else if (this.queued.length < MAX_QUEUED && this.queuedBytes + text.length <=
|
|
5709
|
+
} else if (this.queued.length < MAX_QUEUED && this.queuedBytes + text.length <= MAX_QUEUED_BYTES2) {
|
|
4114
5710
|
this.queued.push(text);
|
|
4115
5711
|
this.queuedBytes += text.length;
|
|
4116
5712
|
} else {
|
|
@@ -4152,11 +5748,371 @@ class GatewaySocket {
|
|
|
4152
5748
|
}
|
|
4153
5749
|
}
|
|
4154
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
|
+
|
|
4155
6111
|
// ../../ta-packages/ta-gateway/esm/node/local-sandbox.js
|
|
4156
6112
|
import { spawn as spawn2 } from "node:child_process";
|
|
4157
6113
|
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
4158
6114
|
import { createServer } from "node:net";
|
|
4159
|
-
import { join as
|
|
6115
|
+
import { join as join7 } from "node:path";
|
|
4160
6116
|
var STOP_TIMEOUT_MS = 1e4;
|
|
4161
6117
|
var KEPT_LINES = 2000;
|
|
4162
6118
|
|
|
@@ -4191,6 +6147,7 @@ class LocalSandbox {
|
|
|
4191
6147
|
this.running = new Map;
|
|
4192
6148
|
this.output = new Map;
|
|
4193
6149
|
this.name = SandboxProviders.string(config, "name", "Local");
|
|
6150
|
+
this.gatewayUrl = SandboxProviders.string(config, "gatewayUrl");
|
|
4194
6151
|
}
|
|
4195
6152
|
async start(tenant) {
|
|
4196
6153
|
var _a, _b;
|
|
@@ -4198,16 +6155,16 @@ class LocalSandbox {
|
|
|
4198
6155
|
if (running && running.child.exitCode === null) {
|
|
4199
6156
|
return { url: running.url, token: tenant.token };
|
|
4200
6157
|
}
|
|
4201
|
-
const root =
|
|
4202
|
-
const agentDir =
|
|
4203
|
-
const cwd =
|
|
6158
|
+
const root = join7(this.context.dir, "local", tenant.id);
|
|
6159
|
+
const agentDir = join7(root, "agent");
|
|
6160
|
+
const cwd = join7(root, "workspace");
|
|
4204
6161
|
mkdirSync4(agentDir, { recursive: true });
|
|
4205
6162
|
mkdirSync4(cwd, { recursive: true });
|
|
4206
6163
|
const port = await LocalSandbox.freePort();
|
|
4207
6164
|
const [command, ...args] = this.context.taCommand;
|
|
4208
6165
|
const child = spawn2(command, [...args, "serve", "--port", String(port)], {
|
|
4209
6166
|
cwd,
|
|
4210
|
-
env: { ...process.env, TA_CODING_AGENT_DIR: agentDir, TA_SERVE_TOKEN: tenant.token, CELL_SERVER__HOST: "127.0.0.1" },
|
|
6167
|
+
env: { ...process.env, ...tenant.env, TA_CODING_AGENT_DIR: agentDir, TA_SERVE_TOKEN: tenant.token, CELL_SERVER__HOST: "127.0.0.1" },
|
|
4211
6168
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4212
6169
|
});
|
|
4213
6170
|
const tail = new LineTail;
|
|
@@ -4267,15 +6224,15 @@ class LocalSandbox {
|
|
|
4267
6224
|
}
|
|
4268
6225
|
|
|
4269
6226
|
// ../../ta-packages/ta-gateway/esm/node/sign-in-links.js
|
|
4270
|
-
import { createHash as
|
|
4271
|
-
import { readFileSync as
|
|
4272
|
-
import { join as
|
|
6227
|
+
import { createHash as createHash7, randomBytes as randomBytes4 } from "node:crypto";
|
|
6228
|
+
import { readFileSync as readFileSync10 } from "node:fs";
|
|
6229
|
+
import { join as join8 } from "node:path";
|
|
4273
6230
|
var SIGN_IN_LINK_PATH = "/sign-in/link/";
|
|
4274
|
-
var hash = (secret) =>
|
|
6231
|
+
var hash = (secret) => createHash7("sha256").update(secret).digest("base64url");
|
|
4275
6232
|
|
|
4276
6233
|
class SignInLinks {
|
|
4277
6234
|
constructor(dir) {
|
|
4278
|
-
this.file =
|
|
6235
|
+
this.file = join8(dir, "links.json");
|
|
4279
6236
|
}
|
|
4280
6237
|
create(account, name, ttlMs = 24 * 3600 * 1000, now = Date.now()) {
|
|
4281
6238
|
if (!/^[a-z][a-z0-9-]*:\S+$/.test(account)) {
|
|
@@ -4297,7 +6254,7 @@ class SignInLinks {
|
|
|
4297
6254
|
}
|
|
4298
6255
|
read(now) {
|
|
4299
6256
|
try {
|
|
4300
|
-
const links = JSON.parse(
|
|
6257
|
+
const links = JSON.parse(readFileSync10(this.file, "utf8"));
|
|
4301
6258
|
return Array.isArray(links) ? links.filter((link) => link.expiresAt > now) : [];
|
|
4302
6259
|
} catch (_a) {
|
|
4303
6260
|
return [];
|
|
@@ -4324,12 +6281,37 @@ var TYPES = {
|
|
|
4324
6281
|
};
|
|
4325
6282
|
var SANDBOX_TYPES = {
|
|
4326
6283
|
docker: (id, config) => new DockerSandbox(id, config),
|
|
6284
|
+
kubernetes: (id, config) => new KubernetesSandbox(id, config),
|
|
4327
6285
|
command: (id, config) => new CommandSandbox(id, config),
|
|
4328
6286
|
local: (id, config, context) => new LocalSandbox(id, config, context),
|
|
4329
6287
|
ta: (id, config) => new TaSandbox(id, config)
|
|
4330
6288
|
};
|
|
4331
6289
|
var GatewayServerUtil;
|
|
4332
6290
|
(function(GatewayServerUtil2) {
|
|
6291
|
+
function reach(type, port, publicUrl) {
|
|
6292
|
+
if (type === "docker") {
|
|
6293
|
+
return `http://host.docker.internal:${port}`;
|
|
6294
|
+
}
|
|
6295
|
+
if (type === "local" || !publicUrl) {
|
|
6296
|
+
return `http://127.0.0.1:${port}`;
|
|
6297
|
+
}
|
|
6298
|
+
return publicUrl;
|
|
6299
|
+
}
|
|
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;
|
|
6314
|
+
GatewayServerUtil2.EXEC_PATH = "/api/exec";
|
|
4333
6315
|
function blockedReason(block) {
|
|
4334
6316
|
switch (block) {
|
|
4335
6317
|
case "suspended":
|
|
@@ -4348,11 +6330,11 @@ var GatewayServerUtil;
|
|
|
4348
6330
|
} catch (_a) {
|
|
4349
6331
|
path = "/";
|
|
4350
6332
|
}
|
|
4351
|
-
const absolute = normalize(
|
|
4352
|
-
if ((absolute === root || absolute.startsWith(root.endsWith(sep) ? root : root + sep)) &&
|
|
6333
|
+
const absolute = normalize(join9(root, path));
|
|
6334
|
+
if ((absolute === root || absolute.startsWith(root.endsWith(sep) ? root : root + sep)) && existsSync4(absolute) && statSync(absolute).isFile()) {
|
|
4353
6335
|
return absolute;
|
|
4354
6336
|
}
|
|
4355
|
-
return
|
|
6337
|
+
return join9(root, "index.html");
|
|
4356
6338
|
}
|
|
4357
6339
|
GatewayServerUtil2.file = file;
|
|
4358
6340
|
function filesTarget(requestUrl, endpoint) {
|
|
@@ -4369,21 +6351,24 @@ var GatewayServerUtil;
|
|
|
4369
6351
|
|
|
4370
6352
|
class GatewayServer {
|
|
4371
6353
|
static async create(options) {
|
|
6354
|
+
var _a, _b;
|
|
6355
|
+
const models = ModelProxyUtil.read((_a = options.config) !== null && _a !== undefined ? _a : options.dir);
|
|
4372
6356
|
mkdirSync5(options.dir, { recursive: true, mode: 448 });
|
|
4373
|
-
const config = SandboxProviders.read(options.dir);
|
|
4374
|
-
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 };
|
|
4375
6359
|
const providers = await SandboxProviders.create(config, context, SANDBOX_TYPES);
|
|
4376
|
-
return new GatewayServer(options, providers, config);
|
|
6360
|
+
return new GatewayServer(options, providers, config, models);
|
|
4377
6361
|
}
|
|
4378
|
-
constructor(options, providers, config) {
|
|
6362
|
+
constructor(options, providers, config, models = {}) {
|
|
4379
6363
|
var _a, _b;
|
|
4380
6364
|
this.options = options;
|
|
4381
6365
|
this.sockets = new Set;
|
|
6366
|
+
this.execs = new Map;
|
|
4382
6367
|
const env = (_a = options.env) !== null && _a !== undefined ? _a : process.env;
|
|
4383
6368
|
const owners = AccessUtil.parseList(env.TA_GATEWAY_ADMINS);
|
|
4384
6369
|
this.policy = new GatewayPolicy(options.dir, owners);
|
|
4385
6370
|
const allowed = [...AccessUtil.parseList(env.TA_ALLOWED_USERS), ...owners];
|
|
4386
|
-
this.flow = new SignInFlow(SignInProviders.fromEnv(env), new AccessStore(
|
|
6371
|
+
this.flow = new SignInFlow(SignInProviders.fromEnv(env), new AccessStore(join9(options.dir, "access.json"), allowed), SignInProviders.publicUrl(env));
|
|
4387
6372
|
this.tenants = new TenantStore(options.dir);
|
|
4388
6373
|
this.links = new SignInLinks(options.dir);
|
|
4389
6374
|
this.environments = new Environments(providers, this.tenants, {
|
|
@@ -4393,8 +6378,36 @@ class GatewayServer {
|
|
|
4393
6378
|
});
|
|
4394
6379
|
this.usage = new GatewayUsage(options.dir);
|
|
4395
6380
|
this.audit = new GatewayAudit(options.dir);
|
|
4396
|
-
this.quotas = new GatewayQuotas(this.policy, this.tenants, this.usage, () => this.environments.settings.own);
|
|
6381
|
+
this.quotas = new GatewayQuotas(this.policy, this.tenants, this.usage, () => this.environments.settings.own, () => this.models.enabled);
|
|
4397
6382
|
this.environments.guard = (tenant) => GatewayServerUtil.blockedReason(this.quotas.blocked(tenant));
|
|
6383
|
+
this.models = new ModelProxy(models, {
|
|
6384
|
+
tenantOfKey: (key) => this.tenants.list().find((tenant) => tenant.modelKey && ModelProxyUtil.sameKey(key, tenant.modelKey)),
|
|
6385
|
+
refuse: (id) => {
|
|
6386
|
+
const tenant = this.tenants.get(id);
|
|
6387
|
+
return tenant ? this.quotas.refuseModels(tenant) : "No such account.";
|
|
6388
|
+
},
|
|
6389
|
+
record: (id, usage, cost) => this.quotas.addTokens(id, ModelProxyUtil.total(usage), cost)
|
|
6390
|
+
}, env);
|
|
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) => {
|
|
6394
|
+
var _a2, _b2, _c;
|
|
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) });
|
|
6404
|
+
}
|
|
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;
|
|
6410
|
+
};
|
|
4398
6411
|
this.service = new GatewayService({
|
|
4399
6412
|
flow: this.flow,
|
|
4400
6413
|
tenants: this.tenants,
|
|
@@ -4404,13 +6417,36 @@ class GatewayServer {
|
|
|
4404
6417
|
usage: this.usage,
|
|
4405
6418
|
audit: this.audit,
|
|
4406
6419
|
hooks: { cutOff: () => this.cutOff(), reset: (id) => this.reset(id) },
|
|
6420
|
+
models: this.models,
|
|
6421
|
+
egress: this.egress,
|
|
4407
6422
|
meta: { links: this.links, startedAt: Date.now(), version: options.version, publicUrl: SandboxProviders.publicBase(env) }
|
|
4408
6423
|
});
|
|
4409
6424
|
}
|
|
4410
6425
|
isAdmin(account) {
|
|
4411
6426
|
return this.policy.role(account) !== "member";
|
|
4412
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
|
+
}
|
|
4413
6446
|
async tick(now = Date.now()) {
|
|
6447
|
+
for (const [id, bytes] of this.egress.flush()) {
|
|
6448
|
+
this.quotas.addEgress(id, bytes, now);
|
|
6449
|
+
}
|
|
4414
6450
|
for (const tenant of this.quotas.tick(this.environments.runningIds(), now)) {
|
|
4415
6451
|
console.log(`ta gateway: ${tenant.account} used its free minutes of the month: its sandbox stops`);
|
|
4416
6452
|
await this.environments.stop(tenant.id).catch(() => {
|
|
@@ -4423,6 +6459,10 @@ class GatewayServer {
|
|
|
4423
6459
|
var _a, _b;
|
|
4424
6460
|
const server = createServer2((request2, response) => void this.handle(request2, response));
|
|
4425
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
|
+
}));
|
|
4426
6466
|
this.server = server;
|
|
4427
6467
|
this.ticker = setInterval(() => void this.tick().catch((error) => console.warn(`ta gateway: counting minutes failed: ${error.message}`)), TICK_MS);
|
|
4428
6468
|
(_b = (_a = this.ticker).unref) === null || _b === undefined || _b.call(_a);
|
|
@@ -4431,6 +6471,7 @@ class GatewayServer {
|
|
|
4431
6471
|
server.once("error", reject);
|
|
4432
6472
|
server.listen((_a2 = this.options.port) !== null && _a2 !== undefined ? _a2 : 4100, (_b2 = this.options.host) !== null && _b2 !== undefined ? _b2 : "127.0.0.1", () => {
|
|
4433
6473
|
const { address, port } = server.address();
|
|
6474
|
+
this.port = port;
|
|
4434
6475
|
resolve(`http://${address.includes(":") ? `[${address}]` : address}:${port}`);
|
|
4435
6476
|
});
|
|
4436
6477
|
});
|
|
@@ -4443,6 +6484,9 @@ class GatewayServer {
|
|
|
4443
6484
|
for (const socket of this.sockets) {
|
|
4444
6485
|
socket.close(1001, "The gateway is stopping.");
|
|
4445
6486
|
}
|
|
6487
|
+
for (const exec of this.execs.keys()) {
|
|
6488
|
+
exec.close(1001, "The gateway is stopping.");
|
|
6489
|
+
}
|
|
4446
6490
|
await this.environments.dispose();
|
|
4447
6491
|
await new Promise((resolve) => this.server ? this.server.close(() => resolve()) : resolve());
|
|
4448
6492
|
}
|
|
@@ -4452,13 +6496,22 @@ class GatewayServer {
|
|
|
4452
6496
|
socket.close(1008, "Signed out");
|
|
4453
6497
|
}
|
|
4454
6498
|
}
|
|
6499
|
+
for (const [exec, { token }] of this.execs) {
|
|
6500
|
+
if (!this.caller(token)) {
|
|
6501
|
+
exec.close(1008, "Signed out");
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
4455
6504
|
}
|
|
4456
6505
|
reset(tenantId) {
|
|
4457
6506
|
const sockets = [...this.sockets].filter((socket) => socket.tenantId === tenantId);
|
|
6507
|
+
const execs = [...this.execs].filter(([, exec]) => exec.tenantId === tenantId).map(([proxy]) => proxy);
|
|
4458
6508
|
setTimeout(() => {
|
|
4459
6509
|
for (const socket of sockets) {
|
|
4460
6510
|
socket.close(1012, "The environment changed.");
|
|
4461
6511
|
}
|
|
6512
|
+
for (const exec of execs) {
|
|
6513
|
+
exec.close(1012, "The environment changed.");
|
|
6514
|
+
}
|
|
4462
6515
|
}, 100);
|
|
4463
6516
|
}
|
|
4464
6517
|
caller(token) {
|
|
@@ -4471,16 +6524,22 @@ class GatewayServer {
|
|
|
4471
6524
|
return { token, account: signIn.account, tenant, role, admin: role !== "member" };
|
|
4472
6525
|
}
|
|
4473
6526
|
async handle(request2, response) {
|
|
4474
|
-
var _a;
|
|
6527
|
+
var _a, _b;
|
|
4475
6528
|
const path = ((_a = request2.url) !== null && _a !== undefined ? _a : "/").split("?")[0];
|
|
4476
6529
|
try {
|
|
4477
|
-
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)) {
|
|
4478
6535
|
this.useLink(request2, response, path.slice(SIGN_IN_LINK_PATH.length));
|
|
4479
6536
|
} else if (SignInPages.matches(request2)) {
|
|
4480
6537
|
await SignInPages.handle(request2, response, this.flow, {
|
|
4481
6538
|
name: "ta gateway",
|
|
4482
6539
|
onSignedIn: (res, token, account, origin) => this.signedIn(res, token, account, origin)
|
|
4483
6540
|
});
|
|
6541
|
+
} else if (path === ModelProxyUtil.PATH || path.startsWith(`${ModelProxyUtil.PATH}/`)) {
|
|
6542
|
+
await this.models.handle(request2, response);
|
|
4484
6543
|
} else if (path.startsWith(`${TA_FILES_PATH}/`)) {
|
|
4485
6544
|
await this.files(request2, response);
|
|
4486
6545
|
} else if (path === "/api" || path.startsWith("/api/")) {
|
|
@@ -4497,6 +6556,24 @@ class GatewayServer {
|
|
|
4497
6556
|
}
|
|
4498
6557
|
}
|
|
4499
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
|
+
}
|
|
4500
6577
|
useLink(request2, response, secret) {
|
|
4501
6578
|
response.setHeader("Cache-Control", "no-store");
|
|
4502
6579
|
response.setHeader("Referrer-Policy", "no-referrer");
|
|
@@ -4550,11 +6627,11 @@ class GatewayServer {
|
|
|
4550
6627
|
}
|
|
4551
6628
|
}
|
|
4552
6629
|
await new Promise((resolve, reject) => {
|
|
4553
|
-
const send = target.protocol === "https:" ?
|
|
6630
|
+
const send = target.protocol === "https:" ? httpsRequest2 : httpRequest3;
|
|
4554
6631
|
const outgoing = send(target, { method: request2.method, headers }, (incoming) => {
|
|
4555
6632
|
var _a2;
|
|
4556
6633
|
response.writeHead((_a2 = incoming.statusCode) !== null && _a2 !== undefined ? _a2 : 502, GatewayServerUtil.filesHeaders(incoming.headers));
|
|
4557
|
-
|
|
6634
|
+
pipeline2(incoming, response, () => resolve());
|
|
4558
6635
|
});
|
|
4559
6636
|
outgoing.on("error", reject);
|
|
4560
6637
|
response.once("close", () => outgoing.destroy());
|
|
@@ -4585,7 +6662,7 @@ class GatewayServer {
|
|
|
4585
6662
|
upgrade(request2, socket, head) {
|
|
4586
6663
|
var _a, _b;
|
|
4587
6664
|
const url = new URL((_a = request2.url) !== null && _a !== undefined ? _a : "/", "http://gateway");
|
|
4588
|
-
if (url.pathname !== TA_WEBSOCKET_PATH) {
|
|
6665
|
+
if (url.pathname !== TA_WEBSOCKET_PATH && url.pathname !== GatewayServerUtil.EXEC_PATH) {
|
|
4589
6666
|
socket.destroy();
|
|
4590
6667
|
return;
|
|
4591
6668
|
}
|
|
@@ -4607,11 +6684,27 @@ class GatewayServer {
|
|
|
4607
6684
|
return;
|
|
4608
6685
|
}
|
|
4609
6686
|
this.tenants.update(caller.tenant.id, { lastActiveAt: Date.now() });
|
|
6687
|
+
if (url.pathname === GatewayServerUtil.EXEC_PATH) {
|
|
6688
|
+
const blocked = GatewayServerUtil.blockedReason(this.quotas.blocked(caller.tenant));
|
|
6689
|
+
if (blocked) {
|
|
6690
|
+
WebSocketConnection.refuse(socket, 403, blocked);
|
|
6691
|
+
return;
|
|
6692
|
+
}
|
|
6693
|
+
const exec = WebSocketConnection.open(socket, checked.key, head, { maxPayload: 64 * 1024 * 1024, heartbeat: 30000 });
|
|
6694
|
+
this.openExec(exec, caller);
|
|
6695
|
+
return;
|
|
6696
|
+
}
|
|
4610
6697
|
const connection = WebSocketConnection.open(socket, checked.key, head, { maxPayload: 32 * 1024 * 1024, heartbeat: 30000, deflate: checked.deflate });
|
|
4611
6698
|
const gatewaySocket = new GatewaySocket(connection, caller, this.environments, this.service, this.quotas);
|
|
4612
6699
|
this.sockets.add(gatewaySocket);
|
|
4613
6700
|
connection.onClose(() => this.sockets.delete(gatewaySocket));
|
|
4614
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
|
+
}
|
|
4615
6708
|
}
|
|
4616
6709
|
|
|
4617
6710
|
// ../../ta-packages/ta-gateway/esm/node/gateway-cli.js
|
|
@@ -4623,9 +6716,11 @@ Ta runs in a sandbox of its own (a container per tenant by default), or in a Ta
|
|
|
4623
6716
|
The web client is served here; each browser's connection goes to the Ta of its tenant. Stops on SIGINT
|
|
4624
6717
|
or SIGTERM.
|
|
4625
6718
|
|
|
4626
|
-
--host
|
|
4627
|
-
--port
|
|
4628
|
-
--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
|
|
4629
6724
|
|
|
4630
6725
|
Accounts sign in with the providers of the environment (TA_GITHUB_*, TA_GOOGLE_*, TA_WECHAT_*,
|
|
4631
6726
|
TA_OIDC_*, as for ta serve) when TA_ALLOWED_USERS lets them in; TA_GATEWAY_ADMINS are let in too and
|
|
@@ -4636,11 +6731,14 @@ The sandboxes are those of sandboxes.json in the directory, as pi's models.json
|
|
|
4636
6731
|
{ "default": "docker", "providers": { "docker": { "type": "docker", "image": "ta:latest", "memory": "4g" } } }
|
|
4637
6732
|
Types: docker, command (shell commands for any platform), local (no isolation: tests), ta (a Ta service
|
|
4638
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.
|
|
4639
6737
|
`;
|
|
4640
6738
|
var GatewayCli;
|
|
4641
6739
|
(function(GatewayCli2) {
|
|
4642
6740
|
async function run(argv, options) {
|
|
4643
|
-
var _a, _b, _c, _d;
|
|
6741
|
+
var _a, _b, _c, _d, _e;
|
|
4644
6742
|
const { values, positionals } = parseArgs({
|
|
4645
6743
|
args: argv,
|
|
4646
6744
|
allowPositionals: true,
|
|
@@ -4648,6 +6746,7 @@ var GatewayCli;
|
|
|
4648
6746
|
host: { type: "string" },
|
|
4649
6747
|
port: { type: "string" },
|
|
4650
6748
|
dir: { type: "string" },
|
|
6749
|
+
config: { type: "string" },
|
|
4651
6750
|
name: { type: "string" },
|
|
4652
6751
|
help: { type: "boolean", short: "h" }
|
|
4653
6752
|
}
|
|
@@ -4656,7 +6755,7 @@ var GatewayCli;
|
|
|
4656
6755
|
process.stdout.write(HELP);
|
|
4657
6756
|
return;
|
|
4658
6757
|
}
|
|
4659
|
-
const dir = (_b = (_a = values.dir) !== null && _a !== undefined ? _a : process.env.TA_GATEWAY_DIR) !== null && _b !== undefined ? _b :
|
|
6758
|
+
const dir = (_b = (_a = values.dir) !== null && _a !== undefined ? _a : process.env.TA_GATEWAY_DIR) !== null && _b !== undefined ? _b : join10(homedir(), ".ta", "gateway");
|
|
4660
6759
|
if (positionals[0] === "link") {
|
|
4661
6760
|
link(dir, positionals[1], values.name);
|
|
4662
6761
|
return;
|
|
@@ -4670,8 +6769,9 @@ var GatewayCli;
|
|
|
4670
6769
|
try {
|
|
4671
6770
|
gateway = await GatewayServer.create({
|
|
4672
6771
|
dir,
|
|
6772
|
+
config: (_c = values.config) !== null && _c !== undefined ? _c : process.env.TA_GATEWAY_CONFIG || undefined,
|
|
4673
6773
|
host: values.host,
|
|
4674
|
-
port: Number((
|
|
6774
|
+
port: Number((_e = (_d = values.port) !== null && _d !== undefined ? _d : process.env.PORT) !== null && _e !== undefined ? _e : 4100),
|
|
4675
6775
|
publicDir: options.publicDir,
|
|
4676
6776
|
taCommand: options.taCommand,
|
|
4677
6777
|
version: options.version
|