synabun 2.0.5 → 2.0.9
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/CHANGELOG.md +78 -0
- package/README.md +2 -1
- package/THIRD-PARTY-LICENSES.md +13 -0
- package/docs/whatsapp.md +151 -16
- package/hooks/claude-code/post-plan.mjs +6 -30
- package/hooks/claude-code/session-start.mjs +1 -4
- package/hooks/claude-code/shared.mjs +112 -75
- package/lib/child-path.js +303 -0
- package/lib/claude-hooks.js +2 -1
- package/lib/data-home-migration.js +2 -0
- package/lib/desktop-app.js +265 -0
- package/lib/external-tools.js +7 -3
- package/lib/log-redact.js +102 -0
- package/lib/package-processes.js +670 -0
- package/lib/packaged-runtime.js +138 -11
- package/lib/runtime-dependencies.js +225 -0
- package/mcp-server/dist/http.d.ts +3 -1
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +15 -4
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +9 -6
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts.map +1 -1
- package/mcp-server/dist/services/browser-bench.js +1 -1
- package/mcp-server/dist/services/browser-bench.js.map +1 -1
- package/mcp-server/dist/services/budget-judgments.d.ts +108 -0
- package/mcp-server/dist/services/budget-judgments.d.ts.map +1 -0
- package/mcp-server/dist/services/budget-judgments.js +153 -0
- package/mcp-server/dist/services/budget-judgments.js.map +1 -0
- package/mcp-server/dist/services/categories.d.ts +35 -2
- package/mcp-server/dist/services/categories.d.ts.map +1 -1
- package/mcp-server/dist/services/categories.js +77 -33
- package/mcp-server/dist/services/categories.js.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.d.ts +5 -1
- package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.js +41 -4
- package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
- package/mcp-server/dist/services/desktop-bench.d.ts +7 -7
- package/mcp-server/dist/services/desktop-bench.d.ts.map +1 -1
- package/mcp-server/dist/services/desktop-bench.js +1 -1
- package/mcp-server/dist/services/desktop-bench.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +11 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +24 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +13 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +34 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +4 -1
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +11 -8
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +35 -14
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/bluesky.js +1 -1
- package/mcp-server/dist/tools/bluesky.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +1 -1
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-batch.d.ts +1 -1
- package/mcp-server/dist/tools/browser-batch.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-batch.js +1 -1
- package/mcp-server/dist/tools/browser-batch.js.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.js +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
- package/mcp-server/dist/tools/browser-interact.d.ts +1 -1
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +1 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.d.ts +1 -1
- package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.js +1 -1
- package/mcp-server/dist/tools/browser-navigate.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +1 -1
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/card-tools.d.ts +1 -1
- package/mcp-server/dist/tools/card-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/card-tools.js +1 -1
- package/mcp-server/dist/tools/card-tools.js.map +1 -1
- package/mcp-server/dist/tools/category.d.ts +1 -1
- package/mcp-server/dist/tools/category.d.ts.map +1 -1
- package/mcp-server/dist/tools/category.js +5 -1
- package/mcp-server/dist/tools/category.js.map +1 -1
- package/mcp-server/dist/tools/choice.d.ts +1 -1
- package/mcp-server/dist/tools/choice.d.ts.map +1 -1
- package/mcp-server/dist/tools/choice.js +1 -1
- package/mcp-server/dist/tools/choice.js.map +1 -1
- package/mcp-server/dist/tools/computer.d.ts +1 -1
- package/mcp-server/dist/tools/computer.d.ts.map +1 -1
- package/mcp-server/dist/tools/computer.js +1 -1
- package/mcp-server/dist/tools/computer.js.map +1 -1
- package/mcp-server/dist/tools/discord-channel.d.ts +1 -1
- package/mcp-server/dist/tools/discord-channel.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-channel.js +1 -1
- package/mcp-server/dist/tools/discord-channel.js.map +1 -1
- package/mcp-server/dist/tools/discord-guild.d.ts +1 -1
- package/mcp-server/dist/tools/discord-guild.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-guild.js +1 -1
- package/mcp-server/dist/tools/discord-guild.js.map +1 -1
- package/mcp-server/dist/tools/discord-member.d.ts +1 -1
- package/mcp-server/dist/tools/discord-member.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-member.js +1 -1
- package/mcp-server/dist/tools/discord-member.js.map +1 -1
- package/mcp-server/dist/tools/discord-message.d.ts +1 -1
- package/mcp-server/dist/tools/discord-message.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-message.js +1 -1
- package/mcp-server/dist/tools/discord-message.js.map +1 -1
- package/mcp-server/dist/tools/discord-onboarding.d.ts +1 -1
- package/mcp-server/dist/tools/discord-onboarding.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-onboarding.js +1 -1
- package/mcp-server/dist/tools/discord-onboarding.js.map +1 -1
- package/mcp-server/dist/tools/discord-role.d.ts +1 -1
- package/mcp-server/dist/tools/discord-role.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-role.js +1 -1
- package/mcp-server/dist/tools/discord-role.js.map +1 -1
- package/mcp-server/dist/tools/discord-thread.d.ts +1 -1
- package/mcp-server/dist/tools/discord-thread.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-thread.js +1 -1
- package/mcp-server/dist/tools/discord-thread.js.map +1 -1
- package/mcp-server/dist/tools/discord-webhook.d.ts +1 -1
- package/mcp-server/dist/tools/discord-webhook.d.ts.map +1 -1
- package/mcp-server/dist/tools/discord-webhook.js +1 -1
- package/mcp-server/dist/tools/discord-webhook.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts.map +1 -1
- package/mcp-server/dist/tools/fb-groups.js +1 -1
- package/mcp-server/dist/tools/fb-groups.js.map +1 -1
- package/mcp-server/dist/tools/forget.d.ts +1 -1
- package/mcp-server/dist/tools/forget.d.ts.map +1 -1
- package/mcp-server/dist/tools/forget.js +1 -1
- package/mcp-server/dist/tools/forget.js.map +1 -1
- package/mcp-server/dist/tools/git-tools.d.ts +1 -1
- package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/git-tools.js +1 -1
- package/mcp-server/dist/tools/git-tools.js.map +1 -1
- package/mcp-server/dist/tools/gsc/experience.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/experience.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/experience.js +1 -1
- package/mcp-server/dist/tools/gsc/experience.js.map +1 -1
- package/mcp-server/dist/tools/gsc/indexing.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/indexing.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/indexing.js +1 -1
- package/mcp-server/dist/tools/gsc/indexing.js.map +1 -1
- package/mcp-server/dist/tools/gsc/inspect.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/inspect.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/inspect.js +1 -1
- package/mcp-server/dist/tools/gsc/inspect.js.map +1 -1
- package/mcp-server/dist/tools/gsc/navigate.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/navigate.js +1 -1
- package/mcp-server/dist/tools/gsc/navigate.js.map +1 -1
- package/mcp-server/dist/tools/gsc/performance.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/performance.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/performance.js +1 -1
- package/mcp-server/dist/tools/gsc/performance.js.map +1 -1
- package/mcp-server/dist/tools/gsc/settings.d.ts +1 -1
- package/mcp-server/dist/tools/gsc/settings.d.ts.map +1 -1
- package/mcp-server/dist/tools/gsc/settings.js +1 -1
- package/mcp-server/dist/tools/gsc/settings.js.map +1 -1
- package/mcp-server/dist/tools/image-tools.d.ts +1 -1
- package/mcp-server/dist/tools/image-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/image-tools.js +1 -1
- package/mcp-server/dist/tools/image-tools.js.map +1 -1
- package/mcp-server/dist/tools/leonardo-browser-tools.d.ts +1 -1
- package/mcp-server/dist/tools/leonardo-browser-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/leonardo-browser-tools.js +1 -1
- package/mcp-server/dist/tools/leonardo-browser-tools.js.map +1 -1
- package/mcp-server/dist/tools/loop.d.ts +1 -1
- package/mcp-server/dist/tools/loop.d.ts.map +1 -1
- package/mcp-server/dist/tools/loop.js +1 -1
- package/mcp-server/dist/tools/loop.js.map +1 -1
- package/mcp-server/dist/tools/memories.d.ts +1 -1
- package/mcp-server/dist/tools/memories.d.ts.map +1 -1
- package/mcp-server/dist/tools/memories.js +1 -1
- package/mcp-server/dist/tools/memories.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +1 -1
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/profile.d.ts +1 -1
- package/mcp-server/dist/tools/profile.d.ts.map +1 -1
- package/mcp-server/dist/tools/profile.js +1 -1
- package/mcp-server/dist/tools/profile.js.map +1 -1
- package/mcp-server/dist/tools/recall.d.ts +1 -1
- package/mcp-server/dist/tools/recall.d.ts.map +1 -1
- package/mcp-server/dist/tools/recall.js +1 -1
- package/mcp-server/dist/tools/recall.js.map +1 -1
- package/mcp-server/dist/tools/reflect.d.ts +1 -1
- package/mcp-server/dist/tools/reflect.d.ts.map +1 -1
- package/mcp-server/dist/tools/reflect.js +1 -1
- package/mcp-server/dist/tools/reflect.js.map +1 -1
- package/mcp-server/dist/tools/remember.d.ts +1 -1
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +13 -11
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/restore.d.ts +1 -1
- package/mcp-server/dist/tools/restore.d.ts.map +1 -1
- package/mcp-server/dist/tools/restore.js +1 -1
- package/mcp-server/dist/tools/restore.js.map +1 -1
- package/mcp-server/dist/tools/style-guide-tools.d.ts +1 -1
- package/mcp-server/dist/tools/style-guide-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/style-guide-tools.js +1 -1
- package/mcp-server/dist/tools/style-guide-tools.js.map +1 -1
- package/mcp-server/dist/tools/sync.d.ts +1 -1
- package/mcp-server/dist/tools/sync.d.ts.map +1 -1
- package/mcp-server/dist/tools/sync.js +1 -1
- package/mcp-server/dist/tools/sync.js.map +1 -1
- package/mcp-server/dist/tools/tictactoe-tools.d.ts +1 -1
- package/mcp-server/dist/tools/tictactoe-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/tictactoe-tools.js +1 -1
- package/mcp-server/dist/tools/tictactoe-tools.js.map +1 -1
- package/mcp-server/dist/tools/utils.d.ts +1 -1
- package/mcp-server/dist/tools/utils.d.ts.map +1 -1
- package/mcp-server/dist/tools/utils.js +1 -1
- package/mcp-server/dist/tools/utils.js.map +1 -1
- package/mcp-server/dist/tools/whatsapp-send-file.d.ts +17 -0
- package/mcp-server/dist/tools/whatsapp-send-file.d.ts.map +1 -0
- package/mcp-server/dist/tools/whatsapp-send-file.js +44 -0
- package/mcp-server/dist/tools/whatsapp-send-file.js.map +1 -0
- package/mcp-server/dist/tools/whiteboard-tools.d.ts +3 -3
- package/mcp-server/dist/tools/whiteboard-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/whiteboard-tools.js +1 -1
- package/mcp-server/dist/tools/whiteboard-tools.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/download.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/download.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/download.js +1 -1
- package/mcp-server/dist/tools/youtube/download.js.map +1 -1
- package/mcp-server/dist/tools/youtube/media.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/media.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/media.js +1 -1
- package/mcp-server/dist/tools/youtube/media.js.map +1 -1
- package/mcp-server/dist/tools/youtube/metadata.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/metadata.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/metadata.js +1 -1
- package/mcp-server/dist/tools/youtube/metadata.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/playlist.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/schedule.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/schedule.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/schedule.js +1 -1
- package/mcp-server/dist/tools/youtube/schedule.js.map +1 -1
- package/mcp-server/dist/tools/youtube/source.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/source.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/source.js +1 -1
- package/mcp-server/dist/tools/youtube/source.js.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.d.ts +1 -1
- package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.js +4 -9
- package/mcp-server/dist/tools/youtube/upload.js.map +1 -1
- package/mcp-server/dist/tui.js +18 -5
- package/mcp-server/dist/tui.js.map +1 -1
- package/mcp-server/dist/version.d.ts +5 -0
- package/mcp-server/dist/version.d.ts.map +1 -0
- package/mcp-server/dist/version.js +21 -0
- package/mcp-server/dist/version.js.map +1 -0
- package/mcp-server/package-lock.json +3 -3
- package/mcp-server/package.json +3 -3
- package/mcp-server/run.mjs +15 -9
- package/mcp-server/src/http.ts +18 -3
- package/mcp-server/src/index.ts +9 -6
- package/mcp-server/src/services/browser-bench.ts +1 -1
- package/mcp-server/src/services/budget-judgments.ts +183 -0
- package/mcp-server/src/services/categories.ts +77 -32
- package/mcp-server/src/services/codex-config-heal.ts +35 -4
- package/mcp-server/src/services/desktop-bench.ts +1 -1
- package/mcp-server/src/services/identity.ts +27 -0
- package/mcp-server/src/services/neural-interface.ts +34 -2
- package/mcp-server/src/services/typesafe-config.ts +4 -1
- package/mcp-server/src/tools/agents.ts +34 -15
- package/mcp-server/src/tools/bluesky.ts +1 -1
- package/mcp-server/src/tools/browser-advanced.ts +1 -1
- package/mcp-server/src/tools/browser-batch.ts +1 -1
- package/mcp-server/src/tools/browser-cheatsheet.ts +1 -1
- package/mcp-server/src/tools/browser-interact.ts +1 -1
- package/mcp-server/src/tools/browser-navigate.ts +1 -1
- package/mcp-server/src/tools/browser-observe.ts +1 -1
- package/mcp-server/src/tools/card-tools.ts +1 -1
- package/mcp-server/src/tools/category.ts +6 -1
- package/mcp-server/src/tools/choice.ts +1 -1
- package/mcp-server/src/tools/computer.ts +1 -1
- package/mcp-server/src/tools/discord-channel.ts +1 -1
- package/mcp-server/src/tools/discord-guild.ts +1 -1
- package/mcp-server/src/tools/discord-member.ts +1 -1
- package/mcp-server/src/tools/discord-message.ts +1 -1
- package/mcp-server/src/tools/discord-onboarding.ts +1 -1
- package/mcp-server/src/tools/discord-role.ts +1 -1
- package/mcp-server/src/tools/discord-thread.ts +1 -1
- package/mcp-server/src/tools/discord-webhook.ts +1 -1
- package/mcp-server/src/tools/fb-groups.ts +1 -1
- package/mcp-server/src/tools/forget.ts +1 -1
- package/mcp-server/src/tools/git-tools.ts +1 -1
- package/mcp-server/src/tools/gsc/experience.ts +1 -1
- package/mcp-server/src/tools/gsc/indexing.ts +1 -1
- package/mcp-server/src/tools/gsc/inspect.ts +1 -1
- package/mcp-server/src/tools/gsc/navigate.ts +1 -1
- package/mcp-server/src/tools/gsc/performance.ts +1 -1
- package/mcp-server/src/tools/gsc/settings.ts +1 -1
- package/mcp-server/src/tools/image-tools.ts +1 -1
- package/mcp-server/src/tools/leonardo-browser-tools.ts +1 -1
- package/mcp-server/src/tools/loop.ts +1 -1
- package/mcp-server/src/tools/memories.ts +1 -1
- package/mcp-server/src/tools/morelogin.ts +1 -1
- package/mcp-server/src/tools/profile.ts +1 -1
- package/mcp-server/src/tools/recall.ts +1 -1
- package/mcp-server/src/tools/reflect.ts +1 -1
- package/mcp-server/src/tools/remember.ts +13 -12
- package/mcp-server/src/tools/restore.ts +1 -1
- package/mcp-server/src/tools/style-guide-tools.ts +1 -1
- package/mcp-server/src/tools/sync.ts +1 -1
- package/mcp-server/src/tools/tictactoe-tools.ts +1 -1
- package/mcp-server/src/tools/utils.ts +1 -1
- package/mcp-server/src/tools/whatsapp-send-file.ts +51 -0
- package/mcp-server/src/tools/whiteboard-tools.ts +1 -1
- package/mcp-server/src/tools/youtube/analytics.ts +1 -1
- package/mcp-server/src/tools/youtube/download.ts +1 -1
- package/mcp-server/src/tools/youtube/media.ts +1 -1
- package/mcp-server/src/tools/youtube/metadata.ts +1 -1
- package/mcp-server/src/tools/youtube/navigate.ts +1 -1
- package/mcp-server/src/tools/youtube/playlist.ts +1 -1
- package/mcp-server/src/tools/youtube/schedule.ts +1 -1
- package/mcp-server/src/tools/youtube/source.ts +1 -1
- package/mcp-server/src/tools/youtube/upload.ts +4 -12
- package/mcp-server/src/tui.ts +24 -10
- package/mcp-server/src/version.ts +22 -0
- package/neural-interface/i18n/en.json +645 -57
- package/neural-interface/i18n/pt-BR.json +644 -56
- package/neural-interface/lib/account-usage.js +163 -0
- package/neural-interface/lib/agent-sandbox-elevation.js +102 -0
- package/neural-interface/lib/agent-sandbox-setting.js +57 -0
- package/neural-interface/lib/assistant-api.js +274 -52
- package/neural-interface/lib/assistant-brains/claude.js +15 -2
- package/neural-interface/lib/assistant-brains/codex.js +3 -0
- package/neural-interface/lib/assistant-brains/opencode.js +17 -4
- package/neural-interface/lib/assistant-budget-planner.js +390 -0
- package/neural-interface/lib/assistant-budget-split.js +408 -0
- package/neural-interface/lib/assistant-budget.js +94 -95
- package/neural-interface/lib/assistant-config.js +62 -14
- package/neural-interface/lib/assistant-dispatch.js +432 -125
- package/neural-interface/lib/assistant-jev.js +26 -3
- package/neural-interface/lib/assistant-persona.js +68 -11
- package/neural-interface/lib/assistant-plan-permissions.js +8 -1
- package/neural-interface/lib/assistant-route-accounts.js +14 -0
- package/neural-interface/lib/assistant-route-gate-codex.js +3 -1
- package/neural-interface/lib/assistant-route-gate.js +19 -3
- package/neural-interface/lib/assistant-router.js +373 -42
- package/neural-interface/lib/assistant-runtime.js +312 -48
- package/neural-interface/lib/assistant-user-writer.js +4 -2
- package/neural-interface/lib/augmented-path.js +317 -53
- package/neural-interface/lib/claude-accounts.js +342 -31
- package/neural-interface/lib/claude-agent-bridge.js +90 -3
- package/neural-interface/lib/claude-executable.js +6 -1
- package/neural-interface/lib/claude-model-catalog.js +3 -3
- package/neural-interface/lib/claude-panel-auth.js +221 -0
- package/neural-interface/lib/claude-profile-api-key.js +62 -0
- package/neural-interface/lib/cli-install-api.js +137 -0
- package/neural-interface/lib/cli-install.js +797 -0
- package/neural-interface/lib/cli-path.js +130 -0
- package/neural-interface/lib/cli-resolver.js +744 -0
- package/neural-interface/lib/cli-update-planner.js +143 -7
- package/neural-interface/lib/codex-account-auth.js +180 -0
- package/neural-interface/lib/codex-accounts.js +502 -0
- package/neural-interface/lib/codex-capabilities.js +2 -1
- package/neural-interface/lib/codex-compat-rpc.js +8 -2
- package/neural-interface/lib/codex-mcp-approvals.js +5 -1
- package/neural-interface/lib/codex-panel-auth.js +62 -0
- package/neural-interface/lib/codex-session-settings.js +1 -1
- package/neural-interface/lib/codex-settings-schema.js +122 -0
- package/neural-interface/lib/desktop/config.js +3 -0
- package/neural-interface/lib/exec-loop-command.js +3 -1
- package/neural-interface/lib/git-bash/bzip2.js +339 -0
- package/neural-interface/lib/git-bash/claude-settings.js +73 -0
- package/neural-interface/lib/git-bash/extract-worker.js +34 -0
- package/neural-interface/lib/git-bash/install.js +529 -0
- package/neural-interface/lib/git-bash/licenses/COPYING +360 -0
- package/neural-interface/lib/git-bash/licenses/LGPL-2.1 +511 -0
- package/neural-interface/lib/git-bash/manager.js +268 -0
- package/neural-interface/lib/git-bash/pins.js +206 -0
- package/neural-interface/lib/git-bash/pins.json +34 -0
- package/neural-interface/lib/git-bash/resolver.js +194 -0
- package/neural-interface/lib/git-read.js +34 -2
- package/neural-interface/lib/install-details.js +163 -0
- package/neural-interface/lib/mcp-installer.js +14 -2
- package/neural-interface/lib/native-loop-providers.js +22 -4
- package/neural-interface/lib/native-loop-runtime.js +9 -4
- package/neural-interface/lib/os-path.js +319 -0
- package/neural-interface/lib/provider-panel-api-key-auth.js +92 -0
- package/neural-interface/lib/provider-panel-terminal-auth.js +96 -0
- package/neural-interface/lib/pty-host/core.js +2 -1
- package/neural-interface/lib/pty-host/manager.js +27 -2
- package/neural-interface/lib/remote-policy.js +20 -11
- package/neural-interface/lib/session-indexer.js +3 -1
- package/neural-interface/lib/session-title-generator.js +6 -3
- package/neural-interface/lib/system-about.js +340 -0
- package/neural-interface/lib/system-activity.js +66 -0
- package/neural-interface/lib/terminal-env.js +11 -3
- package/neural-interface/lib/terminal-path.js +55 -0
- package/neural-interface/lib/virtual-socket.js +12 -1
- package/neural-interface/lib/whatsapp/baileys-adapter.js +165 -45
- package/neural-interface/lib/whatsapp/bridge.js +78 -34
- package/neural-interface/lib/whatsapp/commands.js +13 -14
- package/neural-interface/lib/whatsapp/config.js +134 -20
- package/neural-interface/lib/whatsapp/fake-baileys.js +99 -14
- package/neural-interface/lib/whatsapp/host-core.js +168 -35
- package/neural-interface/lib/whatsapp/inbound.js +5 -3
- package/neural-interface/lib/whatsapp/local-file.js +524 -0
- package/neural-interface/lib/whatsapp/manager.js +92 -32
- package/neural-interface/lib/whatsapp/paths.js +11 -1
- package/neural-interface/lib/whatsapp/protocol.js +65 -5
- package/neural-interface/lib/whatsapp/redact.js +63 -0
- package/neural-interface/lib/whatsapp/service.js +343 -91
- package/neural-interface/lib/whatsapp/transcription.js +463 -0
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +2 -0
- package/neural-interface/public/index2d.html +2 -0
- package/neural-interface/public/offline.html +16 -1
- package/neural-interface/public/onboarding.html +96 -2
- package/neural-interface/public/shared/account-i18n.js +7 -0
- package/neural-interface/public/shared/account-menu.js +542 -0
- package/neural-interface/public/shared/account-usage.js +79 -0
- package/neural-interface/public/shared/account-view.js +336 -0
- package/neural-interface/public/shared/agent-runtime-options.js +28 -8
- package/neural-interface/public/shared/assistant/asst-account-menu.js +298 -0
- package/neural-interface/public/shared/assistant/asst-accounts.js +182 -184
- package/neural-interface/public/shared/assistant/asst-api.js +39 -2
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +288 -32
- package/neural-interface/public/shared/assistant/asst-budget.js +259 -303
- package/neural-interface/public/shared/assistant/asst-mascot.js +126 -7
- package/neural-interface/public/shared/assistant/asst-menu.js +219 -80
- package/neural-interface/public/shared/assistant/asst-model-chip.js +135 -0
- package/neural-interface/public/shared/assistant/asst-panel.js +87 -16
- package/neural-interface/public/shared/assistant/asst-render.js +38 -7
- package/neural-interface/public/shared/assistant/asst-route.js +72 -14
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +45 -6
- package/neural-interface/public/shared/assistant/asst-slash.js +1 -1
- package/neural-interface/public/shared/assistant/asst-state.js +1 -1
- package/neural-interface/public/shared/assistant/asst-styles.js +160 -29
- package/neural-interface/public/shared/cdx/cdx-commands.js +4 -1
- package/neural-interface/public/shared/cdx/cdx-features.js +22 -14
- package/neural-interface/public/shared/cdx/cdx-icons.js +2 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +49 -108
- package/neural-interface/public/shared/cdx/cdx-settings.js +231 -0
- package/neural-interface/public/shared/cdx/cdx-styles.js +172 -111
- package/neural-interface/public/shared/cdx/cdx-tabs.js +264 -664
- package/neural-interface/public/shared/cdx/cdx-ws.js +2 -0
- package/neural-interface/public/shared/claude-account-view.js +3 -0
- package/neural-interface/public/shared/cli-install-view.js +392 -0
- package/neural-interface/public/shared/cli-status.js +282 -22
- package/neural-interface/public/shared/cp/cp-events.js +2 -1
- package/neural-interface/public/shared/cp/cp-styles.js +46 -0
- package/neural-interface/public/shared/desktop-bridge.js +39 -0
- package/neural-interface/public/shared/desktop-titlebar-page.js +59 -0
- package/neural-interface/public/shared/desktop-titlebar-view.js +122 -0
- package/neural-interface/public/shared/desktop-titlebar.js +153 -0
- package/neural-interface/public/shared/desktop-update-view.js +462 -0
- package/neural-interface/public/shared/editor/editor-panel.js +1 -1
- package/neural-interface/public/shared/explorer/fx-main.js +1 -1
- package/neural-interface/public/shared/git-bash-view.js +145 -0
- package/neural-interface/public/shared/html-shell.js +1 -0
- package/neural-interface/public/shared/i18n.js +19 -1
- package/neural-interface/public/shared/install-details-view.js +86 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +4 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +36 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +17 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +169 -2
- package/neural-interface/public/shared/pwa-install-page.js +3 -1
- package/neural-interface/public/shared/settings/settings-about-pane.js +271 -0
- package/neural-interface/public/shared/settings/settings-about.js +254 -0
- package/neural-interface/public/shared/settings/settings-ia.js +15 -0
- package/neural-interface/public/shared/showcase-privacy.js +490 -0
- package/neural-interface/public/shared/storage.js +30 -3
- package/neural-interface/public/shared/styles.css +281 -32
- package/neural-interface/public/shared/synabun-mascot.js +48 -2
- package/neural-interface/public/shared/ui-claude-panel.js +262 -217
- package/neural-interface/public/shared/ui-cli-banner.js +355 -0
- package/neural-interface/public/shared/ui-explorer.js +2 -0
- package/neural-interface/public/shared/ui-git-bash.js +124 -0
- package/neural-interface/public/shared/ui-judgments.js +10 -1
- package/neural-interface/public/shared/ui-loading.js +30 -6
- package/neural-interface/public/shared/ui-menubar.js +13 -3
- package/neural-interface/public/shared/ui-navbar.js +3 -1
- package/neural-interface/public/shared/ui-provider-auth.js +104 -0
- package/neural-interface/public/shared/ui-provider-terminal-auth.js +223 -0
- package/neural-interface/public/shared/ui-sessions.js +9 -3
- package/neural-interface/public/shared/ui-settings.js +55 -3
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +3 -1
- package/neural-interface/public/shared/ui-sync.js +8 -0
- package/neural-interface/public/shared/ui-terminal.js +17 -0
- package/neural-interface/public/shared/ui-tool-updates.js +5 -0
- package/neural-interface/public/shared/ui-update.js +598 -7
- package/neural-interface/public/shared/ui-whatsapp.js +21 -6
- package/neural-interface/public/shared/whatsapp/wa-view.js +51 -8
- package/neural-interface/public/shared/worker-end.js +2 -0
- package/neural-interface/public/sw.js +1 -1
- package/neural-interface/public/variant/2d/main.js +10 -1
- package/neural-interface/public/variant/3d/main.js +10 -1
- package/neural-interface/scripts/rebuild-pty.js +14 -2
- package/neural-interface/server.js +1384 -679
- package/npm-shrinkwrap.json +4424 -0
- package/package.json +57 -2
- package/postinstall.js +61 -47
- package/preuninstall.js +8 -35
- package/setup.js +80 -47
- package/skills/synabun/modules/idea.md +1 -1
- package/skills/synabun/modules/schedule.md +1 -1
- package/updater.cmd +2 -2
- package/updater.mjs +97 -3
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
// The account menu in a side panel's header: one component for the Claude and
|
|
2
|
+
// the Codex panel (docs/claude-sidepanel.md, docs/codex-sidepanel.md →
|
|
3
|
+
// Accounts). The trigger names the tab's account and what it runs on; the menu
|
|
4
|
+
// lists every account (picking one switches the tab under the panel's rules)
|
|
5
|
+
// and manages them: add, sign in, use an API key, the "Uses" switch, sign out
|
|
6
|
+
// per credential, rename, remove. account-view.js decides every word; the
|
|
7
|
+
// panel hands in its rows and does the work (`actions`).
|
|
8
|
+
//
|
|
9
|
+
// Keyboard: the trigger is a menu button (Enter, Space, ArrowDown, ArrowUp).
|
|
10
|
+
// In the list, arrows move, Home / End jump, Tab and Escape close and give the
|
|
11
|
+
// focus back to the trigger. "Manage …" turns the popup into a small dialog:
|
|
12
|
+
// Escape goes back to the list (or leaves an open form), Tab stays inside.
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
accountManageModel, accountMenuModel, accountText, apiKeyErrorText, serverAccountId,
|
|
16
|
+
} from './account-view.js';
|
|
17
|
+
|
|
18
|
+
const STYLE_ID = 'account-menu-styles';
|
|
19
|
+
// Values come from the panel's own tokens: Claude's global --t-* / --s-* scale, Codex's --cxp-* scale
|
|
20
|
+
// (cdx-styles.js lists .acct-menu--codex in its token scope, as it does for its context popover).
|
|
21
|
+
const STYLES = `
|
|
22
|
+
.acct-menu, .acct-menu-trigger {
|
|
23
|
+
--acct-bg: rgba(22,22,26,0.98); --acct-border: var(--b-light); --acct-line: var(--b-subtle);
|
|
24
|
+
--acct-text: var(--t-bright); --acct-muted: var(--t-primary); --acct-faint: var(--t-secondary);
|
|
25
|
+
--acct-hover: var(--s-hover); --acct-active: var(--s-light); --acct-ok: #86efac; --acct-warn: #fbbf24;
|
|
26
|
+
--acct-focus: var(--t-primary); --acct-radius: 5px; --acct-pop-radius: var(--r-card); --acct-shadow: 0 8px 32px rgba(0,0,0,0.4);
|
|
27
|
+
--acct-font: Inter, -apple-system, sans-serif; --acct-fs: 12px; --acct-fs-sm: 11px;
|
|
28
|
+
}
|
|
29
|
+
.acct-menu--codex, .acct-menu-trigger.acct-menu--codex {
|
|
30
|
+
--acct-bg: var(--cxp-pop); --acct-border: var(--cxp-border); --acct-line: var(--cxp-border);
|
|
31
|
+
--acct-text: var(--cxp-text); --acct-muted: var(--cxp-text-2); --acct-faint: var(--cxp-text-3);
|
|
32
|
+
--acct-hover: var(--cxp-surface-1); --acct-active: var(--cxp-surface-2); --acct-ok: var(--cxp-success); --acct-warn: var(--cxp-warning);
|
|
33
|
+
--acct-focus: var(--cxp-focus); --acct-radius: var(--cxp-radius-sm); --acct-pop-radius: var(--cxp-radius-md); --acct-shadow: var(--cxp-shadow-pop);
|
|
34
|
+
--acct-font: var(--cxp-font); --acct-fs: var(--cxp-fs-md); --acct-fs-sm: var(--cxp-fs-sm);
|
|
35
|
+
}
|
|
36
|
+
.acct-menu-trigger {
|
|
37
|
+
display: inline-flex; align-items: center; gap: 6px; min-width: 64px; max-width: 150px; width: 140px; height: 24px; padding: 0 8px;
|
|
38
|
+
border: 1px solid transparent; border-radius: var(--acct-radius); background: transparent; color: var(--acct-text);
|
|
39
|
+
font: 500 var(--acct-fs-sm)/1 var(--acct-font); cursor: pointer; flex: 0 1 140px; container: acct-trigger / inline-size;
|
|
40
|
+
}
|
|
41
|
+
.acct-menu-trigger:hover, .acct-menu-trigger[aria-expanded="true"] { background: var(--acct-hover); border-color: var(--acct-border); }
|
|
42
|
+
.acct-menu-trigger:focus-visible { outline: 1px solid var(--acct-focus); outline-offset: 1px; }
|
|
43
|
+
.acct-menu-trigger[hidden] { display: none; }
|
|
44
|
+
.acct-menu-trigger-name { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: start; }
|
|
45
|
+
.acct-menu-trigger-badge { flex-shrink: 0; color: var(--acct-muted); font-weight: 400; white-space: nowrap; }
|
|
46
|
+
.acct-menu-trigger[data-tone="warn"] .acct-menu-trigger-badge { color: var(--acct-warn); }
|
|
47
|
+
.acct-menu-trigger-arrow { flex-shrink: 0; color: var(--acct-faint); font-size: 9px; }
|
|
48
|
+
@container acct-trigger (max-width: 110px) { .acct-menu-trigger-badge { display: none; } }
|
|
49
|
+
.acct-menu {
|
|
50
|
+
position: fixed; box-sizing: border-box; width: 320px; max-width: calc(100vw - 16px); max-height: min(70vh, 520px); overflow-x: hidden; overflow-y: auto;
|
|
51
|
+
padding: 4px; background: var(--acct-bg); border: 1px solid var(--acct-border); border-radius: var(--acct-pop-radius);
|
|
52
|
+
box-shadow: var(--acct-shadow); color: var(--acct-text); font: 400 var(--acct-fs)/1.45 var(--acct-font); outline: none;
|
|
53
|
+
scrollbar-width: thin; scrollbar-color: var(--acct-border) transparent; overscroll-behavior: contain;
|
|
54
|
+
}
|
|
55
|
+
.acct-menu[hidden] { display: none; }
|
|
56
|
+
.acct-menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; padding: 0 4px 0 8px; }
|
|
57
|
+
.acct-menu-title { flex: 1 1 0; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 var(--acct-fs)/16px var(--acct-font); color: var(--acct-text); }
|
|
58
|
+
.acct-menu-note { margin: 0 0 8px; color: var(--acct-muted); font-size: var(--acct-fs-sm); }
|
|
59
|
+
.acct-menu-footnote { margin: 0; padding: 4px 8px 6px; color: var(--acct-muted); font-size: var(--acct-fs-sm); overflow-wrap: anywhere; }
|
|
60
|
+
.acct-menu-section + .acct-menu-section { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--acct-line); }
|
|
61
|
+
.acct-menu-row { display: flex; align-items: stretch; border-radius: var(--acct-radius); margin: 2px 0; }
|
|
62
|
+
.acct-menu-row[data-current="true"] { background: var(--acct-active); }
|
|
63
|
+
.acct-menu-row:hover, .acct-menu-row:focus-within { background: var(--acct-hover); }
|
|
64
|
+
.acct-menu-item {
|
|
65
|
+
flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 6px 4px 6px 8px; box-sizing: border-box;
|
|
66
|
+
border: none; border-radius: var(--acct-radius); background: transparent; color: var(--acct-text); font: inherit; text-align: left; cursor: pointer;
|
|
67
|
+
}
|
|
68
|
+
.acct-menu-item:focus-visible, .acct-menu-more:focus-visible, .acct-menu-action:focus-visible, .acct-menu-refresh:focus-visible { outline: 2px solid var(--acct-focus); outline-offset: -2px; }
|
|
69
|
+
.acct-menu-avatar { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 28px; height: 28px; border-radius: var(--acct-radius); background: var(--acct-hover); color: var(--acct-muted); font-weight: 500; }
|
|
70
|
+
.acct-menu-item-main { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
71
|
+
.acct-menu-item-heading, .acct-menu-item-meta { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
72
|
+
.acct-menu-item-name { flex: 1 1 0; font-weight: 500; }
|
|
73
|
+
.acct-menu-item-name, .acct-menu-item-id { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
74
|
+
.acct-menu-item-id { min-width: 0; color: var(--acct-muted); font-size: var(--acct-fs-sm); }
|
|
75
|
+
.acct-menu-badge { flex-shrink: 0; color: var(--acct-muted); font-size: var(--acct-fs-sm); white-space: nowrap; }
|
|
76
|
+
.acct-menu-item-meta .acct-menu-badge { background: var(--acct-hover); border-radius: var(--acct-radius); padding: 0 4px; }
|
|
77
|
+
.acct-menu-badge[data-tone="warn"] { color: var(--acct-warn); }
|
|
78
|
+
.acct-menu-badge[data-tone="ok"] { color: var(--acct-muted); }
|
|
79
|
+
.acct-menu-check { flex-shrink: 0; color: var(--acct-text); font-size: 11px; }
|
|
80
|
+
.acct-menu-usage { color: var(--acct-muted); font-size: var(--acct-fs-sm); }
|
|
81
|
+
.acct-menu-usage[data-tone="warn"] { color: var(--acct-warn); }
|
|
82
|
+
.acct-menu-more {
|
|
83
|
+
flex: 0 0 28px; align-self: center; height: 28px; margin-inline-end: 4px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--acct-radius);
|
|
84
|
+
background: transparent; color: var(--acct-muted); font: inherit; cursor: pointer; opacity: 0;
|
|
85
|
+
}
|
|
86
|
+
.acct-menu-row:hover .acct-menu-more, .acct-menu-row:focus-within .acct-menu-more { opacity: 1; }
|
|
87
|
+
.acct-menu-more:hover { background: var(--acct-hover); color: var(--acct-text); }
|
|
88
|
+
.acct-menu-refresh { flex: 0 0 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--acct-radius); background: transparent; color: var(--acct-muted); cursor: pointer; }
|
|
89
|
+
.acct-menu-refresh:hover { background: var(--acct-hover); color: var(--acct-text); }
|
|
90
|
+
.acct-menu-refresh:disabled { opacity: .5; cursor: default; }
|
|
91
|
+
.acct-menu-refresh-icon { width: 14px; height: 14px; background: currentColor; mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="none" stroke="black" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 7v5h-5M4 17v-5h5"/><path d="M6.1 6a8 8 0 0 1 13.3 4M4.6 14A8 8 0 0 0 17.9 18"/></g></svg>') center / contain no-repeat; }
|
|
92
|
+
.acct-menu-refresh[aria-busy="true"] .acct-menu-refresh-icon { animation: acct-refresh 1s linear infinite; }
|
|
93
|
+
.acct-menu-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
94
|
+
.acct-menu-action {
|
|
95
|
+
display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 6px 8px; box-sizing: border-box; border: none; border-radius: var(--acct-radius);
|
|
96
|
+
background: transparent; color: var(--acct-text); font: inherit; text-align: left; cursor: pointer;
|
|
97
|
+
}
|
|
98
|
+
.acct-menu-add::before { content: '+'; flex: 0 0 28px; text-align: center; color: var(--acct-muted); font-size: 18px; font-weight: 300; }
|
|
99
|
+
.acct-menu-action:hover { background: var(--acct-hover); }
|
|
100
|
+
.acct-menu-back { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 6px 0 0; border: none; background: none; color: var(--acct-muted); font: inherit; cursor: pointer; }
|
|
101
|
+
.acct-menu-back:hover, .acct-menu-back:focus-visible { color: var(--acct-text); outline: none; }
|
|
102
|
+
.acct-menu-kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; }
|
|
103
|
+
.acct-menu-k { flex: 0 0 auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--acct-muted); }
|
|
104
|
+
.acct-menu-v { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
|
|
105
|
+
.acct-menu-inuse { color: var(--acct-ok); font-size: var(--acct-fs-sm); }
|
|
106
|
+
.acct-menu-btn {
|
|
107
|
+
box-sizing: border-box; flex-shrink: 0; height: 22px; padding: 0 10px; border: 1px solid var(--acct-border); border-radius: var(--acct-radius);
|
|
108
|
+
background: var(--acct-hover); color: var(--acct-text); font: 400 var(--acct-fs)/20px var(--acct-font); cursor: pointer;
|
|
109
|
+
}
|
|
110
|
+
.acct-menu-btn:hover:not(:disabled) { background: var(--acct-active); }
|
|
111
|
+
.acct-menu-btn:disabled { opacity: 0.45; cursor: default; }
|
|
112
|
+
.acct-menu-btn:focus-visible, .acct-menu-seg button:focus-visible, .acct-menu-input:focus-visible { outline: 1px solid var(--acct-focus); outline-offset: 2px; }
|
|
113
|
+
.acct-menu-seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--acct-border); border-radius: var(--acct-radius); }
|
|
114
|
+
.acct-menu-seg button { height: 20px; padding: 0 8px; border: none; border-radius: var(--acct-radius); background: transparent; color: var(--acct-muted); font: inherit; font-size: var(--acct-fs-sm); cursor: pointer; }
|
|
115
|
+
.acct-menu-seg button[aria-checked="true"] { background: var(--acct-active); color: var(--acct-text); }
|
|
116
|
+
.acct-menu-form { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
|
|
117
|
+
.acct-menu-input {
|
|
118
|
+
flex: 1 1 0; min-width: 0; height: 24px; box-sizing: border-box; padding: 0 8px; border: 1px solid var(--acct-border); border-radius: var(--acct-radius);
|
|
119
|
+
background: var(--acct-hover); color: var(--acct-text); font: inherit;
|
|
120
|
+
}
|
|
121
|
+
.acct-menu-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
|
|
122
|
+
.acct-menu-status { margin: 8px 0 0; color: var(--acct-muted); font-size: var(--acct-fs-sm); }
|
|
123
|
+
.acct-menu-status:empty { display: none; }
|
|
124
|
+
.acct-menu-status { padding: 0 8px 4px; overflow-wrap: anywhere; }
|
|
125
|
+
.acct-menu[data-view="manage"] { padding: 8px; }
|
|
126
|
+
.acct-menu[data-view="manage"] .acct-menu-kv { flex-wrap: wrap; gap: 6px; }
|
|
127
|
+
.acct-menu[data-view="manage"] .acct-menu-note { overflow-wrap: anywhere; }
|
|
128
|
+
@keyframes acct-refresh { to { transform: rotate(360deg); } }
|
|
129
|
+
@media (hover: none), (pointer: coarse) {
|
|
130
|
+
.acct-menu-more { opacity: 1; flex-basis: 44px; height: 44px; }
|
|
131
|
+
.acct-menu-refresh { flex-basis: 44px; height: 44px; }
|
|
132
|
+
.acct-menu-action { min-height: 44px; }
|
|
133
|
+
}
|
|
134
|
+
@media (prefers-reduced-motion: reduce) { .acct-menu-refresh[aria-busy="true"] .acct-menu-refresh-icon { animation: none; } }
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
function ensureStyles() {
|
|
138
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
139
|
+
const style = document.createElement('style');
|
|
140
|
+
style.id = STYLE_ID;
|
|
141
|
+
style.textContent = STYLES;
|
|
142
|
+
document.head.append(style);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function h(tag, attrs = {}, ...children) {
|
|
146
|
+
const node = document.createElement(tag);
|
|
147
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
148
|
+
if (value === null || value === undefined || value === false) continue;
|
|
149
|
+
if (key === 'className') node.className = value;
|
|
150
|
+
else if (key === 'text') node.textContent = value;
|
|
151
|
+
else if (key === 'dataset') Object.assign(node.dataset, value);
|
|
152
|
+
else if (key.startsWith('on') && typeof value === 'function') node.addEventListener(key.slice(2).toLowerCase(), value);
|
|
153
|
+
else node.setAttribute(key, value === true ? '' : String(value));
|
|
154
|
+
}
|
|
155
|
+
for (const child of children.flat()) if (child !== null && child !== undefined && child !== false) node.append(child);
|
|
156
|
+
return node;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let _menuIds = 0;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Mount the trigger into `container` (before `before`, if given) and return the
|
|
163
|
+
* menu's controller: { trigger, open({ manage, fresh, status }), close(), toggle(), render(), isOpen(), destroy() }.
|
|
164
|
+
* `read()` → { rows, currentId, hasConversation, available, busy, error, loading }.
|
|
165
|
+
* `actions`: pick(id), add() → row, signIn(id), saveKey(id, key), setMode(id, mode),
|
|
166
|
+
* signOut(id, credential), rename(id, label), remove(id), load({ refresh }).
|
|
167
|
+
*/
|
|
168
|
+
export function mountAccountMenu({ provider = 'claude', container, before = null, read, actions = {}, layer = null, confirm = (text) => window.confirm(text) } = {}) {
|
|
169
|
+
ensureStyles();
|
|
170
|
+
const p = provider === 'codex' ? 'codex' : 'claude';
|
|
171
|
+
const menuId = `acct-menu-${p}-${++_menuIds}`;
|
|
172
|
+
const trigger = h('button', {
|
|
173
|
+
type: 'button', className: `acct-menu-trigger acct-menu--${p}`, 'aria-haspopup': 'menu', 'aria-expanded': 'false', 'aria-controls': menuId,
|
|
174
|
+
}, h('span', { className: 'acct-menu-trigger-name' }), h('span', { className: 'acct-menu-trigger-badge' }), h('span', { className: 'acct-menu-trigger-arrow', 'aria-hidden': 'true', text: '▾' }));
|
|
175
|
+
if (container) container.insertBefore(trigger, before && before.parentNode === container ? before : container.firstChild);
|
|
176
|
+
const popup = h('div', { id: menuId, className: `acct-menu acct-menu--${p}`, role: 'menu', tabindex: '-1', hidden: true });
|
|
177
|
+
document.body.append(popup);
|
|
178
|
+
|
|
179
|
+
// view: 'list' | 'manage'; manageId: the account being managed; form: 'key' | 'rename' | ''; status: the last word said.
|
|
180
|
+
const ui = { view: 'list', manageId: '', form: '', status: '', statusId: '', untilSignedIn: '', working: false, refreshing: false };
|
|
181
|
+
let open = false;
|
|
182
|
+
let destroyed = false;
|
|
183
|
+
|
|
184
|
+
const state = () => {
|
|
185
|
+
const value = (typeof read === 'function' ? read() : null) || {};
|
|
186
|
+
return { rows: Array.isArray(value.rows) ? value.rows : [], currentId: value.currentId || '', hasConversation: !!value.hasConversation, available: value.available !== false, busy: !!value.busy, error: value.error || '', loading: !!value.loading };
|
|
187
|
+
};
|
|
188
|
+
const rowOf = (id) => state().rows.find((row) => row.id === id) || null;
|
|
189
|
+
const say = (text, id = '') => { ui.status = text || ''; ui.statusId = id; };
|
|
190
|
+
|
|
191
|
+
function renderTrigger() {
|
|
192
|
+
const s = state();
|
|
193
|
+
const model = accountMenuModel({ provider: p, rows: s.rows, currentId: s.currentId, hasConversation: s.hasConversation });
|
|
194
|
+
trigger.hidden = !s.available;
|
|
195
|
+
trigger.querySelector('.acct-menu-trigger-name').textContent = model.trigger.name;
|
|
196
|
+
trigger.querySelector('.acct-menu-trigger-badge').textContent = model.trigger.short || model.trigger.badge;
|
|
197
|
+
trigger.dataset.tone = model.trigger.tone || 'muted';
|
|
198
|
+
trigger.setAttribute('aria-label', model.trigger.label);
|
|
199
|
+
trigger.title = model.trigger.label;
|
|
200
|
+
return model;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function focusables() {
|
|
204
|
+
return [...popup.querySelectorAll('button:not(:disabled), input:not(:disabled)')].filter((node) => !node.closest('[hidden]'));
|
|
205
|
+
}
|
|
206
|
+
function focusKey(node) { return node?.dataset?.focus || ''; }
|
|
207
|
+
function restoreFocus(key) {
|
|
208
|
+
if (!open) return;
|
|
209
|
+
// Only while the menu owns the focus: a sign-in terminal that just opened (or anything else the
|
|
210
|
+
// user moved to) keeps it, so the keys typed there never land in the menu.
|
|
211
|
+
const active = document.activeElement;
|
|
212
|
+
if (active && active !== document.body && active !== trigger && !popup.contains(active)) return;
|
|
213
|
+
const target = (key && popup.querySelector(`[data-focus="${CSS.escape(key)}"]`)) || focusables()[0] || popup;
|
|
214
|
+
target.focus?.();
|
|
215
|
+
target.scrollIntoView?.({ block: 'nearest' });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function listView(model, s) {
|
|
219
|
+
const rows = model.rows.map((item) => {
|
|
220
|
+
const row = s.rows.find((value) => value.id === item.id);
|
|
221
|
+
const identity = row?.mode === 'apiKey' ? row.apiKey?.hint || row.identity : row?.subscription?.email || row?.identity;
|
|
222
|
+
// Compare the identity itself, before a plan is appended. An email used as
|
|
223
|
+
// the account name is shown once; CSS performs the only truncation.
|
|
224
|
+
const duplicate = String(identity || '').trim().toLowerCase() === item.label.trim().toLowerCase();
|
|
225
|
+
const detail = duplicate ? '' : item.identity;
|
|
226
|
+
const badge = row?.mode === 'subscription' && row.signedIn === true ? accountText('subscriptionShort', {}, p) : item.badge;
|
|
227
|
+
const usage = row?.mode === 'subscription' && row.signedIn === true ? row.usage : null;
|
|
228
|
+
const percent = typeof usage?.remainingPercent === 'number' && Number.isFinite(usage.remainingPercent)
|
|
229
|
+
? Math.round(Math.max(0, Math.min(100, usage.remainingPercent))) : null;
|
|
230
|
+
const usageLabel = usage?.limited ? accountText('usageLimited', {}, p) : percent !== null ? accountText('usageLeft', { percent }, p) : '';
|
|
231
|
+
const reset = usage?.resetsAt ? new Date(usage.resetsAt) : null;
|
|
232
|
+
const resetTitle = reset && Number.isFinite(reset.getTime()) ? accountText('usageResets', { time: reset.toLocaleString(document.documentElement?.lang || undefined) }, p) : '';
|
|
233
|
+
return h('div', { className: 'acct-menu-row', role: 'none', dataset: { current: String(item.current) } },
|
|
234
|
+
h('button', {
|
|
235
|
+
type: 'button', className: 'acct-menu-item', role: 'menuitemradio', 'aria-checked': String(item.current), dataset: { focus: `pick:${item.id}` },
|
|
236
|
+
title: [item.label, item.badge, item.identity].filter(Boolean).join(' · '),
|
|
237
|
+
'aria-label': [item.label, detail, item.badge, usageLabel].filter(Boolean).join(' · '),
|
|
238
|
+
onClick: () => pick(item.id),
|
|
239
|
+
},
|
|
240
|
+
h('span', { className: 'acct-menu-avatar', 'aria-hidden': 'true', text: Array.from(item.label.trim())[0]?.toLocaleUpperCase() || '?' }),
|
|
241
|
+
h('span', { className: 'acct-menu-item-main' },
|
|
242
|
+
h('span', { className: 'acct-menu-item-heading' },
|
|
243
|
+
h('span', { className: 'acct-menu-item-name', text: item.label, title: item.label }),
|
|
244
|
+
item.current ? h('span', { className: 'acct-menu-check', 'aria-hidden': 'true', text: '✓' }) : null),
|
|
245
|
+
h('span', { className: 'acct-menu-item-meta' },
|
|
246
|
+
detail ? h('span', { className: 'acct-menu-item-id', text: detail, title: detail }) : null,
|
|
247
|
+
h('span', { className: 'acct-menu-badge', dataset: { tone: item.tone }, text: badge })),
|
|
248
|
+
usageLabel ? h('span', { className: 'acct-menu-usage', title: resetTitle || usageLabel, dataset: { tone: usage.limited ? 'warn' : 'muted' }, text: usageLabel }) : null)),
|
|
249
|
+
h('button', {
|
|
250
|
+
type: 'button', className: 'acct-menu-more', role: 'menuitem', dataset: { focus: `manage:${item.id}` },
|
|
251
|
+
'aria-label': accountText('manage', { label: item.label }, p), title: accountText('manage', { label: item.label }, p),
|
|
252
|
+
onClick: () => showManage(item.id),
|
|
253
|
+
}, '⋯'));
|
|
254
|
+
});
|
|
255
|
+
const empty = !model.rows.length ? h('p', { className: 'acct-menu-footnote', text: s.error || accountText(s.loading ? 'reading' : 'emptyAccounts', {}, p) }) : null;
|
|
256
|
+
return [
|
|
257
|
+
h('div', { className: 'acct-menu-section' },
|
|
258
|
+
h('div', { className: 'acct-menu-head' }, h('p', { className: 'acct-menu-title', text: model.title }),
|
|
259
|
+
h('button', { type: 'button', className: 'acct-menu-refresh', role: 'menuitem', dataset: { focus: 'refresh' }, title: accountText('refresh', {}, p), 'aria-label': accountText('refresh', {}, p), 'aria-busy': String(ui.refreshing), disabled: ui.refreshing, onClick: () => reload(true) },
|
|
260
|
+
h('span', { className: 'acct-menu-refresh-icon', 'aria-hidden': 'true' }), h('span', { className: 'acct-menu-sr', text: accountText('refresh', {}, p) }))),
|
|
261
|
+
empty, ...rows),
|
|
262
|
+
h('div', { className: 'acct-menu-section' },
|
|
263
|
+
h('button', { type: 'button', className: 'acct-menu-action acct-menu-add', role: 'menuitem', dataset: { focus: 'add' }, disabled: ui.working, text: accountText('addAccount', {}, p), onClick: () => addAccount() }),
|
|
264
|
+
h('p', { className: 'acct-menu-footnote', text: model.note })),
|
|
265
|
+
h('p', { className: 'acct-menu-status', role: 'status', 'aria-live': 'polite', text: (model.rows.length ? s.error : '') || (ui.statusId ? '' : ui.status) }),
|
|
266
|
+
];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function manageView(row, s) {
|
|
270
|
+
const model = accountManageModel(row, p);
|
|
271
|
+
const busyHere = s.busy && row.id === serverAccountId(s.currentId);
|
|
272
|
+
const modes = model.modes.length ? h('div', { className: 'acct-menu-kv' },
|
|
273
|
+
h('span', { className: 'acct-menu-k', text: accountText('uses', {}, p) }),
|
|
274
|
+
h('span', { className: 'acct-menu-seg', role: 'radiogroup', 'aria-label': model.usesLabel },
|
|
275
|
+
...model.modes.map((m) => h('button', {
|
|
276
|
+
type: 'button', role: 'radio', 'aria-checked': String(m.current), dataset: { focus: `mode:${m.mode}` }, title: m.detail || m.label,
|
|
277
|
+
disabled: ui.working || busyHere, text: m.label, onClick: () => setMode(row, m.mode),
|
|
278
|
+
})))) : null;
|
|
279
|
+
const creds = model.credentials.map((c) => h('div', { className: 'acct-menu-kv' },
|
|
280
|
+
h('span', { className: 'acct-menu-k', text: c.name }),
|
|
281
|
+
h('span', { className: 'acct-menu-v', title: c.text }, c.text, c.inUse ? h('span', { className: 'acct-menu-inuse', text: ` · ${accountText('inUse', {}, p)}` }) : null),
|
|
282
|
+
h('button', { type: 'button', className: 'acct-menu-btn', dataset: { focus: `cred:${c.kind}` }, disabled: ui.working || busyHere, text: c.actionText, onClick: () => credentialAction(row, c) })));
|
|
283
|
+
const keyForm = ui.form === 'key' ? h('form', { className: 'acct-menu-form', onSubmit: (event) => saveKey(event, row) },
|
|
284
|
+
h('input', { className: 'acct-menu-input', type: 'password', name: 'key', autocomplete: 'off', spellcheck: 'false', required: true, placeholder: accountText('keyPlaceholder', {}, p), 'aria-label': accountText('keyLabel', { label: model.title }, p), dataset: { focus: 'key-input' }, disabled: ui.working }),
|
|
285
|
+
h('button', { type: 'submit', className: 'acct-menu-btn', disabled: ui.working, text: accountText('save', {}, p) }),
|
|
286
|
+
h('button', { type: 'button', className: 'acct-menu-btn', disabled: ui.working, text: accountText('cancel', {}, p), onClick: () => closeForm('cred:apiKey') })) : null;
|
|
287
|
+
const renameForm = ui.form === 'rename' ? h('form', { className: 'acct-menu-form', onSubmit: (event) => saveName(event, row) },
|
|
288
|
+
h('input', { className: 'acct-menu-input', type: 'text', name: 'label', maxlength: '80', autocomplete: 'off', value: row.label || '', 'aria-label': accountText('nameLabel', {}, p), dataset: { focus: 'rename-input' }, disabled: ui.working }),
|
|
289
|
+
h('button', { type: 'submit', className: 'acct-menu-btn', disabled: ui.working, text: accountText('save', {}, p) }),
|
|
290
|
+
h('button', { type: 'button', className: 'acct-menu-btn', disabled: ui.working, text: accountText('cancel', {}, p), onClick: () => closeForm('rename') })) : null;
|
|
291
|
+
const manageActions = model.canRename || model.canRemove ? h('div', { className: 'acct-menu-actions' },
|
|
292
|
+
model.canRename ? h('button', { type: 'button', className: 'acct-menu-btn', dataset: { focus: 'rename' }, disabled: ui.working, text: accountText('rename', {}, p), onClick: () => { ui.form = 'rename'; render('rename-input'); } }) : null,
|
|
293
|
+
model.canRemove ? h('button', { type: 'button', className: 'acct-menu-btn', dataset: { focus: 'remove' }, disabled: ui.working || row.id === serverAccountId(s.currentId) && s.busy, text: accountText('remove', {}, p), onClick: () => removeAccount(row) }) : null) : null;
|
|
294
|
+
return [
|
|
295
|
+
h('div', { className: 'acct-menu-section' },
|
|
296
|
+
h('div', { className: 'acct-menu-head' },
|
|
297
|
+
h('button', { type: 'button', className: 'acct-menu-back', dataset: { focus: 'back' }, onClick: () => showList(`manage:${row.id}`) }, h('span', { 'aria-hidden': 'true', text: '‹' }), accountText('back', {}, p))),
|
|
298
|
+
h('div', { className: 'acct-menu-kv' }, h('p', { className: 'acct-menu-title', text: model.title }), h('span', { className: 'acct-menu-badge', dataset: { tone: model.tone }, text: model.badge })),
|
|
299
|
+
model.identity ? h('p', { className: 'acct-menu-note', text: model.identity }) : null),
|
|
300
|
+
h('div', { className: 'acct-menu-section' }, modes, ...creds, keyForm),
|
|
301
|
+
manageActions || renameForm ? h('div', { className: 'acct-menu-section' }, renameForm, manageActions) : null,
|
|
302
|
+
h('p', { className: 'acct-menu-status', role: 'status', 'aria-live': 'polite', text: busyHere ? accountText('busyTurn', {}, p) : ui.statusId === row.id ? ui.status : '' }),
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Draw the trigger and, when open, the menu. `focus`: the data-focus key to land on (else the focused one stays). */
|
|
307
|
+
function render(focus = null) {
|
|
308
|
+
if (destroyed) return;
|
|
309
|
+
const s = state();
|
|
310
|
+
const model = renderTrigger();
|
|
311
|
+
if (!open) return;
|
|
312
|
+
// A sign-in this menu started is said until the account's subscription is signed in.
|
|
313
|
+
if (ui.untilSignedIn && rowOf(ui.untilSignedIn)?.subscription?.signedIn === true) { ui.untilSignedIn = ''; say(''); }
|
|
314
|
+
// An open form keeps what is typed in it: a change from elsewhere waits until it closes.
|
|
315
|
+
if (!focus && ui.form && popup.contains(document.activeElement) && document.activeElement?.tagName === 'INPUT') return;
|
|
316
|
+
const keep = focus || focusKey(popup.contains(document.activeElement) ? document.activeElement : null);
|
|
317
|
+
const row = ui.view === 'manage' ? rowOf(ui.manageId) : null;
|
|
318
|
+
if (ui.view === 'manage' && !row) { ui.view = 'list'; ui.form = ''; }
|
|
319
|
+
popup.dataset.view = ui.view;
|
|
320
|
+
// A section a view leaves out (null) is not a node: replaceChildren would print "null".
|
|
321
|
+
popup.replaceChildren(...(ui.view === 'manage' && row ? manageView(row, s) : listView(model, s)).filter(Boolean));
|
|
322
|
+
if (ui.view === 'manage' && row) {
|
|
323
|
+
popup.setAttribute('role', 'dialog');
|
|
324
|
+
popup.setAttribute('aria-label', accountText('manage', { label: accountManageModel(row, p).title }, p));
|
|
325
|
+
} else {
|
|
326
|
+
popup.setAttribute('role', 'menu');
|
|
327
|
+
popup.setAttribute('aria-label', model.title);
|
|
328
|
+
}
|
|
329
|
+
place();
|
|
330
|
+
restoreFocus(keep);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function place() {
|
|
334
|
+
if (!open) return;
|
|
335
|
+
let rect = trigger.getBoundingClientRect();
|
|
336
|
+
// A header too narrow for the trigger hides it (the panels' container queries); the menu,
|
|
337
|
+
// opened from the cog's Account row, then hangs from the row the trigger sits in.
|
|
338
|
+
if (!rect.width && !rect.height && trigger.parentElement) rect = trigger.parentElement.getBoundingClientRect();
|
|
339
|
+
const owner = layer?.() || trigger.closest('[class*="panel"]');
|
|
340
|
+
const ownerWidth = owner?.getBoundingClientRect?.().width;
|
|
341
|
+
popup.style.width = `${Math.max(0, Math.min(320, ownerWidth > 240 ? ownerWidth - 16 : 320, window.innerWidth - 16))}px`;
|
|
342
|
+
const width = popup.offsetWidth || 300;
|
|
343
|
+
const left = Math.max(8, Math.min(rect.right - width, window.innerWidth - width - 8));
|
|
344
|
+
const below = window.innerHeight - rect.bottom - 14;
|
|
345
|
+
const above = rect.top - 14;
|
|
346
|
+
const flip = below < 180 && above > below;
|
|
347
|
+
popup.style.maxHeight = `${Math.max(80, Math.min(520, flip ? above : below))}px`;
|
|
348
|
+
popup.style.left = `${Math.round(left)}px`;
|
|
349
|
+
popup.style.top = `${Math.round(flip ? Math.max(8, rect.top - 6 - popup.offsetHeight) : rect.bottom + 6)}px`;
|
|
350
|
+
let z = 201;
|
|
351
|
+
try { z = (parseInt(getComputedStyle(owner).zIndex, 10) || 200) + 1; } catch {}
|
|
352
|
+
popup.style.zIndex = String(z);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function showList(focus = null) { ui.view = 'list'; ui.form = ''; ui.manageId = ''; render(focus); }
|
|
356
|
+
function showManage(id, focus = 'back') { ui.view = 'manage'; ui.manageId = id; ui.form = ''; if (ui.statusId && ui.statusId !== id) say(''); render(focus); }
|
|
357
|
+
function closeForm(focus) { ui.form = ''; render(focus); }
|
|
358
|
+
|
|
359
|
+
async function reload(refresh = false) {
|
|
360
|
+
if (refresh && ui.refreshing) return;
|
|
361
|
+
if (refresh) { ui.refreshing = true; say(''); render(); }
|
|
362
|
+
try { await actions.load?.({ refresh }); } catch { say(accountText('readFailed', {}, p)); }
|
|
363
|
+
finally { if (refresh) ui.refreshing = false; }
|
|
364
|
+
render();
|
|
365
|
+
}
|
|
366
|
+
async function work(task, { id = '', done = '', focus = null, after = null } = {}) {
|
|
367
|
+
if (ui.working) return false;
|
|
368
|
+
ui.working = true;
|
|
369
|
+
render(focus);
|
|
370
|
+
let ok = false;
|
|
371
|
+
try {
|
|
372
|
+
await task();
|
|
373
|
+
say(typeof done === 'function' ? done() : done, id);
|
|
374
|
+
ok = true;
|
|
375
|
+
} catch (error) {
|
|
376
|
+
say(error?.message || accountText('failed', {}, p), id);
|
|
377
|
+
} finally {
|
|
378
|
+
ui.working = false;
|
|
379
|
+
}
|
|
380
|
+
try { await actions.load?.({ refresh: false }); } catch {}
|
|
381
|
+
after?.(ok);
|
|
382
|
+
render(focus);
|
|
383
|
+
return ok;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function pick(id) {
|
|
387
|
+
const message = actions.pick?.(id);
|
|
388
|
+
close({ restore: true });
|
|
389
|
+
if (typeof message === 'string' && message) say(message);
|
|
390
|
+
}
|
|
391
|
+
async function addAccount() {
|
|
392
|
+
let created = null;
|
|
393
|
+
const ok = await work(async () => { created = await actions.add?.(); }, { focus: 'add' });
|
|
394
|
+
if (ok && created?.id) {
|
|
395
|
+
say(accountText('freshPrompt', { label: created.label || created.id }, p), created.id);
|
|
396
|
+
showManage(created.id, 'cred:subscription');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function busyFor(row) {
|
|
400
|
+
const s = state();
|
|
401
|
+
if (s.busy && row.id === serverAccountId(s.currentId)) { say(accountText('busyTurn', {}, p), row.id); render(); return true; }
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
async function credentialAction(row, c) {
|
|
405
|
+
if (busyFor(row)) return;
|
|
406
|
+
const label = accountManageModel(row, p).title;
|
|
407
|
+
if (c.action === 'addKey') { ui.form = 'key'; say('', ''); render('key-input'); return; }
|
|
408
|
+
if (c.action === 'signIn') {
|
|
409
|
+
const ok = await work(() => actions.signIn(row.id), { id: row.id, done: accountText('signInPending', {}, p), focus: `cred:${c.kind}` });
|
|
410
|
+
if (ok) ui.untilSignedIn = row.id;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (c.action === 'signOut') {
|
|
414
|
+
if (!confirm(accountText('confirmSignOut', { label }, p))) return;
|
|
415
|
+
await work(() => actions.signOut(row.id, 'subscription'), { id: row.id, done: accountText('signedOutNote', { label }, p), focus: `cred:${c.kind}` });
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (c.action === 'removeKey') {
|
|
419
|
+
if (!confirm(accountText('confirmRemoveKey', { label }, p))) return;
|
|
420
|
+
await work(() => actions.signOut(row.id, 'apiKey'), { id: row.id, done: accountText('keyRemovedNote', { label }, p), focus: `cred:${c.kind}` });
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
async function saveKey(event, row) {
|
|
424
|
+
event.preventDefault();
|
|
425
|
+
const input = event.currentTarget.querySelector('input');
|
|
426
|
+
let key = input.value;
|
|
427
|
+
input.value = '';
|
|
428
|
+
if (!key || busyFor(row)) { key = null; return; }
|
|
429
|
+
const label = accountManageModel(row, p).title;
|
|
430
|
+
say(accountText('checkingKey', {}, p), row.id);
|
|
431
|
+
try {
|
|
432
|
+
await work(async () => {
|
|
433
|
+
try { await actions.saveKey(row.id, key); }
|
|
434
|
+
catch (error) { throw Object.assign(new Error(apiKeyErrorText(p, error?.code)), { code: error?.code }); }
|
|
435
|
+
finally { key = null; }
|
|
436
|
+
ui.form = '';
|
|
437
|
+
}, { id: row.id, done: accountText('keySavedNote', { label }, p), focus: 'cred:apiKey' });
|
|
438
|
+
} finally { key = null; }
|
|
439
|
+
}
|
|
440
|
+
async function saveName(event, row) {
|
|
441
|
+
event.preventDefault();
|
|
442
|
+
const value = event.currentTarget.querySelector('input').value.trim();
|
|
443
|
+
if (!value || value === row.label) { closeForm('rename'); return; }
|
|
444
|
+
await work(async () => { await actions.rename(row.id, value); ui.form = ''; }, { id: row.id, focus: 'rename' });
|
|
445
|
+
}
|
|
446
|
+
async function setMode(row, mode) {
|
|
447
|
+
if (row.mode === mode || busyFor(row)) return;
|
|
448
|
+
const label = accountManageModel(row, p).title;
|
|
449
|
+
await work(() => actions.setMode(row.id, mode), { id: row.id, done: accountText(mode === 'apiKey' ? 'modeSetApiKey' : 'modeSetSubscription', { label }, p), focus: `mode:${mode}` });
|
|
450
|
+
}
|
|
451
|
+
async function removeAccount(row) {
|
|
452
|
+
const label = accountManageModel(row, p).title;
|
|
453
|
+
if (!confirm(accountText('confirmRemove', { label }, p))) return;
|
|
454
|
+
const ok = await work(() => actions.remove(row.id), { id: row.id, focus: 'remove' });
|
|
455
|
+
if (ok) showList('add');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ── open / close and the keys ──
|
|
459
|
+
function onKeydown(event) {
|
|
460
|
+
if (!open) return;
|
|
461
|
+
const inForm = event.target?.tagName === 'INPUT';
|
|
462
|
+
if (event.key === 'Escape') {
|
|
463
|
+
event.preventDefault(); event.stopPropagation();
|
|
464
|
+
if (ui.form) { const back = ui.form === 'key' ? 'cred:apiKey' : 'rename'; closeForm(back); return; }
|
|
465
|
+
if (ui.view === 'manage') { showList(`manage:${ui.manageId}`); return; }
|
|
466
|
+
close({ restore: true });
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (!popup.contains(event.target)) return;
|
|
470
|
+
// Keys typed into a field belong to the field (and never reach the panel's shortcuts).
|
|
471
|
+
if (inForm) { event.stopPropagation(); return; }
|
|
472
|
+
const items = focusables();
|
|
473
|
+
const index = items.indexOf(document.activeElement);
|
|
474
|
+
if (event.key === 'Tab') {
|
|
475
|
+
if (ui.view === 'list') { event.preventDefault(); close({ restore: true }); return; }
|
|
476
|
+
event.preventDefault();
|
|
477
|
+
const next = items[(index + (event.shiftKey ? -1 : 1) + items.length) % items.length];
|
|
478
|
+
next?.focus();
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const move = { ArrowDown: 1, ArrowUp: -1 }[event.key];
|
|
482
|
+
if (move) { event.preventDefault(); (items[(index + move + items.length) % items.length] || items[0])?.focus(); return; }
|
|
483
|
+
if (event.key === 'Home') { event.preventDefault(); items[0]?.focus(); return; }
|
|
484
|
+
if (event.key === 'End') { event.preventDefault(); items[items.length - 1]?.focus(); }
|
|
485
|
+
}
|
|
486
|
+
function onPointerDown(event) {
|
|
487
|
+
if (!open || popup.contains(event.target) || trigger.contains(event.target)) return;
|
|
488
|
+
close();
|
|
489
|
+
}
|
|
490
|
+
function onViewport() { if (open) { if (!trigger.isConnected) close(); else place(); } }
|
|
491
|
+
|
|
492
|
+
function openMenu({ manage = '', fresh = '', status = '', focusLast = false } = {}) {
|
|
493
|
+
if (destroyed || !state().available) return;
|
|
494
|
+
if (!open) {
|
|
495
|
+
open = true;
|
|
496
|
+
popup.hidden = false;
|
|
497
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
498
|
+
window.addEventListener('keydown', onKeydown, true);
|
|
499
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
500
|
+
window.addEventListener('resize', onViewport);
|
|
501
|
+
window.addEventListener('scroll', onViewport, true);
|
|
502
|
+
}
|
|
503
|
+
if (status) say(status, manage || fresh || '');
|
|
504
|
+
if (fresh) say(accountText('freshPrompt', { label: rowOf(fresh)?.label || fresh }, p), fresh);
|
|
505
|
+
if (manage || fresh) showManage(manage || fresh, fresh ? 'cred:subscription' : 'back');
|
|
506
|
+
else { ui.view = 'list'; ui.form = ''; render(focusLast ? 'add' : `pick:${serverAccountId(state().currentId)}`); }
|
|
507
|
+
reload(false);
|
|
508
|
+
}
|
|
509
|
+
function close({ restore = false } = {}) {
|
|
510
|
+
if (!open) return;
|
|
511
|
+
open = false;
|
|
512
|
+
popup.hidden = true;
|
|
513
|
+
ui.form = '';
|
|
514
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
515
|
+
window.removeEventListener('keydown', onKeydown, true);
|
|
516
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
517
|
+
window.removeEventListener('resize', onViewport);
|
|
518
|
+
window.removeEventListener('scroll', onViewport, true);
|
|
519
|
+
if (restore) trigger.focus();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
trigger.addEventListener('click', (event) => { event.stopPropagation(); if (open) close({ restore: true }); else openMenu(); });
|
|
523
|
+
trigger.addEventListener('keydown', (event) => {
|
|
524
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); openMenu({ focusLast: event.key === 'ArrowUp' }); }
|
|
525
|
+
});
|
|
526
|
+
// The header moves a floating window: a press in the menu must not.
|
|
527
|
+
popup.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
528
|
+
trigger.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
529
|
+
|
|
530
|
+
renderTrigger();
|
|
531
|
+
return {
|
|
532
|
+
trigger,
|
|
533
|
+
popup,
|
|
534
|
+
open: openMenu,
|
|
535
|
+
close,
|
|
536
|
+
toggle: () => (open ? close({ restore: true }) : openMenu()),
|
|
537
|
+
isOpen: () => open,
|
|
538
|
+
render: () => render(),
|
|
539
|
+
say: (text, id = '') => { say(text, id); render(); },
|
|
540
|
+
destroy() { close(); destroyed = true; trigger.remove(); popup.remove(); },
|
|
541
|
+
};
|
|
542
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Text only: keep the account menus in their existing component/token scope.
|
|
2
|
+
function translator(t) {
|
|
3
|
+
return (key, fallback, params = {}) => {
|
|
4
|
+
const value = t?.(`assistant.accountUsage.${key}`, params);
|
|
5
|
+
return value && value !== `assistant.accountUsage.${key}` ? value : fallback.replace(/\{(\w+)\}/g, (_, k) => params[k] ?? '');
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function accountUsageText(row, t) {
|
|
9
|
+
const tr = translator(t);
|
|
10
|
+
if (row?.mode === 'apiKey' || row?.mode === 'api') return tr('notApplicable', 'Usage n/a');
|
|
11
|
+
const u = row?.usage;
|
|
12
|
+
const reset = u?.resetsAt ? new Date(u.resetsAt) : null;
|
|
13
|
+
const time = reset && Number.isFinite(reset.getTime()) ? reset.toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }) : null;
|
|
14
|
+
if (u?.limited) return time ? tr('limitedUntil', 'Limited until {time}', { time }) : tr('limited', 'Limited');
|
|
15
|
+
if (typeof u?.remainingPercent !== 'number' || !Number.isFinite(u.remainingPercent)) return tr('unknown', 'Usage unknown');
|
|
16
|
+
return [tr('left', '{percent}% left', { percent: Math.round(u.remainingPercent) }), time ? tr('resets', 'resets {time}', { time }) : ''].filter(Boolean).join(' · ');
|
|
17
|
+
}
|
|
18
|
+
export function autoAccountLabel(t) {
|
|
19
|
+
const key = 'assistant.accountUsage.auto';
|
|
20
|
+
const value = t?.(key);
|
|
21
|
+
return value && value !== key ? value : 'Auto · most usage left';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function pageLocale() {
|
|
25
|
+
try { return globalThis.document?.documentElement?.lang || undefined; } catch { return undefined; }
|
|
26
|
+
}
|
|
27
|
+
function dateFormat(locale, options) {
|
|
28
|
+
try { return new Intl.DateTimeFormat(locale, options); } catch { return new Intl.DateTimeFormat(undefined, options); }
|
|
29
|
+
}
|
|
30
|
+
const dayStart = (ms) => { const day = new Date(ms); day.setHours(0, 0, 0, 0); return day.getTime(); };
|
|
31
|
+
const bare = (text) => String(text).replace(/\.$/, '');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* When an account's usage comes back, short enough for one menu line in the page's language:
|
|
35
|
+
* "15:59" today, "Thu 15:59" within the week, "Oct 19 15:59" / "19 out 15:59" later; '' without a
|
|
36
|
+
* valid date. `long` is the full form for a tooltip ("Thursday, October 22 at 15:59").
|
|
37
|
+
*/
|
|
38
|
+
export function resetTimeText(value, { now = Date.now(), locale = pageLocale(), long = false } = {}) {
|
|
39
|
+
const at = value ? new Date(value) : null;
|
|
40
|
+
if (!at || !Number.isFinite(at.getTime())) return '';
|
|
41
|
+
if (long) return dateFormat(locale, { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(at);
|
|
42
|
+
const time = dateFormat(locale, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(at);
|
|
43
|
+
const days = Math.round((dayStart(at.getTime()) - dayStart(now)) / 86_400_000);
|
|
44
|
+
if (days === 0) return time;
|
|
45
|
+
if (days > 0 && days < 7) return `${bare(dateFormat(locale, { weekday: 'short' }).format(at))} ${time}`;
|
|
46
|
+
const date = dateFormat(locale, { day: 'numeric', month: 'short' }).formatToParts(at)
|
|
47
|
+
.filter((part) => part.type === 'day' || part.type === 'month').map((part) => bare(part.value)).join(' ');
|
|
48
|
+
return `${date} ${time}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An account's usage as one short line of a menu row: { text, tone: 'muted' | 'warn', title }
|
|
53
|
+
* ("50% left · resets Thu 15:59", "Limited until 23:10", "Usage unknown"), the title with the full
|
|
54
|
+
* reset date. null where usage does not apply: an API key, a signed-out or unchecked account.
|
|
55
|
+
*/
|
|
56
|
+
export function accountUsageLine(row, t, { now = Date.now(), locale = pageLocale() } = {}) {
|
|
57
|
+
if (!row || row.signedIn !== true || row.mode !== 'subscription') return null;
|
|
58
|
+
const tr = translator(t);
|
|
59
|
+
const u = row.usage;
|
|
60
|
+
const short = resetTimeText(u?.resetsAt, { now, locale });
|
|
61
|
+
const full = resetTimeText(u?.resetsAt, { now, locale, long: true });
|
|
62
|
+
if (u?.limited) {
|
|
63
|
+
return {
|
|
64
|
+
text: short ? tr('limitedUntil', 'Limited until {time}', { time: short }) : tr('limited', 'Limited'),
|
|
65
|
+
tone: 'warn',
|
|
66
|
+
title: full ? tr('limitedUntil', 'Limited until {time}', { time: full }) : tr('limited', 'Limited'),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (typeof u?.remainingPercent !== 'number' || !Number.isFinite(u.remainingPercent)) {
|
|
70
|
+
const text = tr('unknown', 'Usage unknown');
|
|
71
|
+
return { text, tone: 'muted', title: text };
|
|
72
|
+
}
|
|
73
|
+
const left = tr('left', '{percent}% left', { percent: Math.round(Math.max(0, Math.min(100, u.remainingPercent))) });
|
|
74
|
+
return {
|
|
75
|
+
text: [left, short ? tr('resets', 'resets {time}', { time: short }) : ''].filter(Boolean).join(' · '),
|
|
76
|
+
tone: 'muted',
|
|
77
|
+
title: [left, full ? tr('resets', 'resets {time}', { time: full }) : ''].filter(Boolean).join(' · '),
|
|
78
|
+
};
|
|
79
|
+
}
|