@adecore/agents-react 0.0.1 → 0.17.0-beta.2
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/LICENSE +110 -0
- package/README.md +61 -0
- package/dist/agents/AccountDot.d.ts +4 -0
- package/dist/agents/AccountDot.js +8 -0
- package/dist/agents/AgentIcon.d.ts +6 -0
- package/dist/agents/AgentIcon.js +20 -0
- package/dist/agents/ModelOptionControl.d.ts +15 -0
- package/dist/agents/ModelOptionControl.js +33 -0
- package/dist/agents/ProviderLogo.d.ts +8 -0
- package/dist/agents/ProviderLogo.js +8 -0
- package/dist/agents/account-limits.d.ts +7 -0
- package/dist/agents/account-limits.js +40 -0
- package/dist/agents/accounts.d.ts +22 -0
- package/dist/agents/accounts.js +113 -0
- package/dist/agents/model-name.d.ts +12 -0
- package/dist/agents/model-name.js +56 -0
- package/dist/agents/model-options.d.ts +5 -0
- package/dist/agents/model-options.js +15 -0
- package/dist/agents/provider-paths.d.ts +2 -0
- package/dist/agents/provider-paths.js +8 -0
- package/dist/agents/status-look.d.ts +13 -0
- package/dist/agents/status-look.js +24 -0
- package/dist/chat/account-choice.d.ts +11 -0
- package/dist/chat/account-choice.js +30 -0
- package/dist/chat/actions.d.ts +6 -0
- package/dist/chat/actions.js +68 -0
- package/dist/chat/activity.d.ts +5 -0
- package/dist/chat/activity.js +6 -0
- package/dist/chat/attachments.d.ts +23 -0
- package/dist/chat/attachments.js +86 -0
- package/dist/chat/bookmarks.d.ts +14 -0
- package/dist/chat/bookmarks.js +73 -0
- package/dist/chat/chat-client.d.ts +55 -0
- package/dist/chat/chat-client.js +279 -0
- package/dist/chat/chat-references.d.ts +5 -0
- package/dist/chat/chat-references.js +5 -0
- package/dist/chat/drafts.d.ts +29 -0
- package/dist/chat/drafts.js +116 -0
- package/dist/chat/forks.d.ts +2 -0
- package/dist/chat/forks.js +28 -0
- package/dist/chat/guards.d.ts +12 -0
- package/dist/chat/guards.js +69 -0
- package/dist/chat/logic/ansi.d.ts +13 -0
- package/dist/chat/logic/ansi.js +185 -0
- package/dist/chat/logic/answers.d.ts +1 -0
- package/dist/chat/logic/answers.js +8 -0
- package/dist/chat/logic/bookmarks.d.ts +5 -0
- package/dist/chat/logic/bookmarks.js +33 -0
- package/dist/chat/logic/context-usage.d.ts +12 -0
- package/dist/chat/logic/context-usage.js +21 -0
- package/dist/chat/logic/fork.d.ts +45 -0
- package/dist/chat/logic/fork.js +148 -0
- package/dist/chat/logic/handback.d.ts +2 -0
- package/dist/chat/logic/handback.js +8 -0
- package/dist/chat/logic/json.d.ts +1 -0
- package/dist/chat/logic/json.js +4 -0
- package/dist/chat/logic/limit.d.ts +7 -0
- package/dist/chat/logic/limit.js +34 -0
- package/dist/chat/logic/resume-compaction.d.ts +14 -0
- package/dist/chat/logic/resume-compaction.js +47 -0
- package/dist/chat/logic/scrubber.d.ts +50 -0
- package/dist/chat/logic/scrubber.js +220 -0
- package/dist/chat/logic/thread-cards.d.ts +3 -0
- package/dist/chat/logic/thread-cards.js +59 -0
- package/dist/chat/logic/timeline-copy.d.ts +4 -0
- package/dist/chat/logic/timeline-copy.js +59 -0
- package/dist/chat/logic/timeline-target.d.ts +12 -0
- package/dist/chat/logic/timeline-target.js +34 -0
- package/dist/chat/logic/timeline.d.ts +115 -0
- package/dist/chat/logic/timeline.js +343 -0
- package/dist/chat/logic/tool-catalog.d.ts +10 -0
- package/dist/chat/logic/tool-catalog.js +44 -0
- package/dist/chat/logic/tools.d.ts +15 -0
- package/dist/chat/logic/tools.js +82 -0
- package/dist/chat/logic/welcome.d.ts +2 -0
- package/dist/chat/logic/welcome.js +10 -0
- package/dist/chat/logic/workflow.d.ts +14 -0
- package/dist/chat/logic/workflow.js +47 -0
- package/dist/chat/mentions.d.ts +65 -0
- package/dist/chat/mentions.js +184 -0
- package/dist/chat/persisted-json.d.ts +5 -0
- package/dist/chat/persisted-json.js +58 -0
- package/dist/chat/preferences.d.ts +27 -0
- package/dist/chat/preferences.js +139 -0
- package/dist/chat/quote.d.ts +2 -0
- package/dist/chat/quote.js +25 -0
- package/dist/chat/recent-messages.d.ts +17 -0
- package/dist/chat/recent-messages.js +36 -0
- package/dist/chat/resume-compaction-dismissals.d.ts +3 -0
- package/dist/chat/resume-compaction-dismissals.js +14 -0
- package/dist/chat/runtime-modes.d.ts +4 -0
- package/dist/chat/runtime-modes.js +15 -0
- package/dist/chat/stash.d.ts +24 -0
- package/dist/chat/stash.js +91 -0
- package/dist/chat/subagent-conversation.d.ts +41 -0
- package/dist/chat/subagent-conversation.js +167 -0
- package/dist/chat/subagent-list.d.ts +19 -0
- package/dist/chat/subagent-list.js +106 -0
- package/dist/chat/subagent-support.d.ts +6 -0
- package/dist/chat/subagent-support.js +14 -0
- package/dist/chat/subagent-view.d.ts +35 -0
- package/dist/chat/subagent-view.js +96 -0
- package/dist/chat/thumbnails.d.ts +10 -0
- package/dist/chat/thumbnails.js +89 -0
- package/dist/chat/timeline-flash.d.ts +12 -0
- package/dist/chat/timeline-flash.js +16 -0
- package/dist/chat/timeline-scroll.d.ts +27 -0
- package/dist/chat/timeline-scroll.js +152 -0
- package/dist/chat/ui/AccountPill.d.ts +3 -0
- package/dist/chat/ui/AccountPill.js +23 -0
- package/dist/chat/ui/AnsiOutput.d.ts +5 -0
- package/dist/chat/ui/AnsiOutput.js +9 -0
- package/dist/chat/ui/BookmarkMarker.d.ts +8 -0
- package/dist/chat/ui/BookmarkMarker.js +57 -0
- package/dist/chat/ui/BookmarkSubmenu.d.ts +3 -0
- package/dist/chat/ui/BookmarkSubmenu.js +33 -0
- package/dist/chat/ui/ChatActivity.d.ts +7 -0
- package/dist/chat/ui/ChatActivity.js +84 -0
- package/dist/chat/ui/ChatReferenceChip.d.ts +4 -0
- package/dist/chat/ui/ChatReferenceChip.js +16 -0
- package/dist/chat/ui/CodeBlock.d.ts +4 -0
- package/dist/chat/ui/CodeBlock.js +132 -0
- package/dist/chat/ui/Composer.d.ts +15 -0
- package/dist/chat/ui/Composer.js +856 -0
- package/dist/chat/ui/ComposerInput.d.ts +29 -0
- package/dist/chat/ui/ComposerInput.js +127 -0
- package/dist/chat/ui/DiffPool.d.ts +5 -0
- package/dist/chat/ui/DiffPool.js +26 -0
- package/dist/chat/ui/EditDiff.d.ts +4 -0
- package/dist/chat/ui/EditDiff.js +21 -0
- package/dist/chat/ui/FadingWords.d.ts +3 -0
- package/dist/chat/ui/FadingWords.js +5 -0
- package/dist/chat/ui/ImageView.d.ts +6 -0
- package/dist/chat/ui/ImageView.js +81 -0
- package/dist/chat/ui/LimitState.d.ts +8 -0
- package/dist/chat/ui/LimitState.js +112 -0
- package/dist/chat/ui/Markdown.d.ts +18 -0
- package/dist/chat/ui/Markdown.js +159 -0
- package/dist/chat/ui/MessageActions.d.ts +9 -0
- package/dist/chat/ui/MessageActions.js +53 -0
- package/dist/chat/ui/Pickers.d.ts +21 -0
- package/dist/chat/ui/Pickers.js +111 -0
- package/dist/chat/ui/PromptComposer.d.ts +13 -0
- package/dist/chat/ui/PromptComposer.js +56 -0
- package/dist/chat/ui/QuoteButton.d.ts +7 -0
- package/dist/chat/ui/QuoteButton.js +74 -0
- package/dist/chat/ui/ResumeCompactionDock.d.ts +5 -0
- package/dist/chat/ui/ResumeCompactionDock.js +14 -0
- package/dist/chat/ui/RunSettings.d.ts +28 -0
- package/dist/chat/ui/RunSettings.js +153 -0
- package/dist/chat/ui/Scrubber.d.ts +17 -0
- package/dist/chat/ui/Scrubber.js +118 -0
- package/dist/chat/ui/SubagentControls.d.ts +11 -0
- package/dist/chat/ui/SubagentControls.js +36 -0
- package/dist/chat/ui/SubagentInfo.d.ts +4 -0
- package/dist/chat/ui/SubagentInfo.js +34 -0
- package/dist/chat/ui/SubagentStopButton.d.ts +7 -0
- package/dist/chat/ui/SubagentStopButton.js +34 -0
- package/dist/chat/ui/SubagentTimeline.d.ts +4 -0
- package/dist/chat/ui/SubagentTimeline.js +107 -0
- package/dist/chat/ui/Timeline.d.ts +6 -0
- package/dist/chat/ui/Timeline.js +424 -0
- package/dist/chat/ui/TimelineMenu.d.ts +12 -0
- package/dist/chat/ui/TimelineMenu.js +54 -0
- package/dist/chat/ui/UnifiedDiff.d.ts +11 -0
- package/dist/chat/ui/UnifiedDiff.js +66 -0
- package/dist/chat/ui/UploadThumb.d.ts +4 -0
- package/dist/chat/ui/UploadThumb.js +11 -0
- package/dist/chat/ui/Welcome.d.ts +4 -0
- package/dist/chat/ui/Welcome.js +16 -0
- package/dist/chat/ui/chips.d.ts +4 -0
- package/dist/chat/ui/chips.js +11 -0
- package/dist/chat/ui/code-lines.d.ts +18 -0
- package/dist/chat/ui/code-lines.js +46 -0
- package/dist/chat/ui/code-streaming.d.ts +1 -0
- package/dist/chat/ui/code-streaming.js +3 -0
- package/dist/chat/ui/code-theme.d.ts +3 -0
- package/dist/chat/ui/code-theme.js +12 -0
- package/dist/chat/ui/composer/chips.d.ts +6 -0
- package/dist/chat/ui/composer/chips.js +31 -0
- package/dist/chat/ui/composer/editor.d.ts +11 -0
- package/dist/chat/ui/composer/editor.js +98 -0
- package/dist/chat/ui/composer/insert.d.ts +2 -0
- package/dist/chat/ui/composer/insert.js +19 -0
- package/dist/chat/ui/composer/keys.d.ts +30 -0
- package/dist/chat/ui/composer/keys.js +100 -0
- package/dist/chat/ui/diff-theme.d.ts +2 -0
- package/dist/chat/ui/diff-theme.js +20 -0
- package/dist/chat/ui/file-links.d.ts +5 -0
- package/dist/chat/ui/file-links.js +20 -0
- package/dist/chat/ui/find-reveal.d.ts +7 -0
- package/dist/chat/ui/find-reveal.js +13 -0
- package/dist/chat/ui/full-diff.d.ts +6 -0
- package/dist/chat/ui/full-diff.js +19 -0
- package/dist/chat/ui/icons.d.ts +4 -0
- package/dist/chat/ui/icons.js +20 -0
- package/dist/chat/ui/markdown-blocks.d.ts +6 -0
- package/dist/chat/ui/markdown-blocks.js +103 -0
- package/dist/chat/ui/quote-selection.d.ts +3 -0
- package/dist/chat/ui/quote-selection.js +46 -0
- package/dist/chat/ui/rehype-chips.d.ts +23 -0
- package/dist/chat/ui/rehype-chips.js +32 -0
- package/dist/chat/ui/rehype-fade.d.ts +23 -0
- package/dist/chat/ui/rehype-fade.js +36 -0
- package/dist/chat/ui/remark-html-as-text.d.ts +8 -0
- package/dist/chat/ui/remark-html-as-text.js +26 -0
- package/dist/chat/ui/reply-context.d.ts +5 -0
- package/dist/chat/ui/reply-context.js +2 -0
- package/dist/chat/ui/reveal.d.ts +13 -0
- package/dist/chat/ui/reveal.js +114 -0
- package/dist/chat/ui/rows/ForksRow.d.ts +4 -0
- package/dist/chat/ui/rows/ForksRow.js +38 -0
- package/dist/chat/ui/rows/MessageRows.d.ts +40 -0
- package/dist/chat/ui/rows/MessageRows.js +204 -0
- package/dist/chat/ui/rows/Rows.d.ts +12 -0
- package/dist/chat/ui/rows/Rows.js +61 -0
- package/dist/chat/ui/rows/SubagentRow.d.ts +17 -0
- package/dist/chat/ui/rows/SubagentRow.js +101 -0
- package/dist/chat/ui/rows/TaskRow.d.ts +8 -0
- package/dist/chat/ui/rows/TaskRow.js +63 -0
- package/dist/chat/ui/rows/WorkRows.d.ts +47 -0
- package/dist/chat/ui/rows/WorkRows.js +168 -0
- package/dist/chat/ui/rows/WorkflowRow.d.ts +8 -0
- package/dist/chat/ui/rows/WorkflowRow.js +48 -0
- package/dist/chat/ui/rows/row-rhythm.d.ts +6 -0
- package/dist/chat/ui/rows/row-rhythm.js +34 -0
- package/dist/chat/ui/useToggleSet.d.ts +6 -0
- package/dist/chat/ui/useToggleSet.js +25 -0
- package/dist/host.d.ts +195 -0
- package/dist/host.js +55 -0
- package/dist/lazy.d.ts +6 -0
- package/dist/lazy.js +57 -0
- package/dist/locales/en/agent-chat.json +446 -0
- package/dist/locales/en/agent-prompts.json +42 -0
- package/dist/locales/en/agent-providers.json +131 -0
- package/dist/locales/en/agent-usage.json +131 -0
- package/dist/locales/nl/agent-chat.json +446 -0
- package/dist/locales/nl/agent-prompts.json +42 -0
- package/dist/locales/nl/agent-providers.json +131 -0
- package/dist/locales/nl/agent-usage.json +131 -0
- package/dist/locales.d.ts +5 -0
- package/dist/locales.js +20 -0
- package/dist/mounted-registry.d.ts +7 -0
- package/dist/mounted-registry.js +39 -0
- package/dist/port-transport.d.ts +6 -0
- package/dist/port-transport.js +129 -0
- package/dist/prompts/logic/focus.d.ts +2 -0
- package/dist/prompts/logic/focus.js +23 -0
- package/dist/prompts/logic/keys.d.ts +42 -0
- package/dist/prompts/logic/keys.js +94 -0
- package/dist/prompts/logic/prompts.d.ts +34 -0
- package/dist/prompts/logic/prompts.fixtures.d.ts +5 -0
- package/dist/prompts/logic/prompts.fixtures.js +79 -0
- package/dist/prompts/logic/prompts.js +32 -0
- package/dist/prompts/logic/subjects.d.ts +50 -0
- package/dist/prompts/logic/subjects.js +63 -0
- package/dist/prompts/logic/useFocusAfterAnswer.d.ts +6 -0
- package/dist/prompts/logic/useFocusAfterAnswer.js +28 -0
- package/dist/prompts/logic/usePromptSession.d.ts +24 -0
- package/dist/prompts/logic/usePromptSession.js +87 -0
- package/dist/prompts/ui/ApprovalBody.d.ts +13 -0
- package/dist/prompts/ui/ApprovalBody.js +34 -0
- package/dist/prompts/ui/PromptActions.d.ts +27 -0
- package/dist/prompts/ui/PromptActions.js +18 -0
- package/dist/prompts/ui/PromptCard.d.ts +16 -0
- package/dist/prompts/ui/PromptCard.js +50 -0
- package/dist/prompts/ui/PromptView.d.ts +2 -0
- package/dist/prompts/ui/PromptView.js +47 -0
- package/dist/prompts/ui/QuestionBody.d.ts +9 -0
- package/dist/prompts/ui/QuestionBody.js +87 -0
- package/dist/providers/AccountColors.d.ts +5 -0
- package/dist/providers/AccountColors.js +8 -0
- package/dist/providers/AccountDetail.d.ts +12 -0
- package/dist/providers/AccountDetail.js +69 -0
- package/dist/providers/AccountVariables.d.ts +8 -0
- package/dist/providers/AccountVariables.js +43 -0
- package/dist/providers/AddAccountForm.d.ts +10 -0
- package/dist/providers/AddAccountForm.js +54 -0
- package/dist/providers/CliDetail.d.ts +12 -0
- package/dist/providers/CliDetail.js +54 -0
- package/dist/providers/ProvidersPane.d.ts +9 -0
- package/dist/providers/ProvidersPane.js +86 -0
- package/dist/providers/account-actions.d.ts +7 -0
- package/dist/providers/account-actions.js +57 -0
- package/dist/providers/parts.d.ts +9 -0
- package/dist/providers/parts.js +18 -0
- package/dist/providers/provider-abilities.d.ts +2 -0
- package/dist/providers/provider-abilities.js +7 -0
- package/dist/providers/variables.d.ts +13 -0
- package/dist/providers/variables.js +63 -0
- package/dist/scope.d.ts +11 -0
- package/dist/scope.js +10 -0
- package/dist/settings/sections.d.ts +13 -0
- package/dist/settings/sections.js +32 -0
- package/dist/state/chats.d.ts +44 -0
- package/dist/state/chats.js +199 -0
- package/dist/state/provider-accounts.d.ts +17 -0
- package/dist/state/provider-accounts.js +67 -0
- package/dist/state/providers.d.ts +17 -0
- package/dist/state/providers.js +33 -0
- package/dist/state/usage.d.ts +44 -0
- package/dist/state/usage.js +121 -0
- package/dist/storage.d.ts +20 -0
- package/dist/storage.js +89 -0
- package/dist/theme.css +212 -0
- package/dist/transport.d.ts +24 -0
- package/dist/transport.js +18 -0
- package/dist/ui/PlainTextarea.d.ts +2 -0
- package/dist/ui/PlainTextarea.js +5 -0
- package/dist/usage/LimitsList.d.ts +18 -0
- package/dist/usage/LimitsList.js +73 -0
- package/dist/usage/UsageBreakdown.d.ts +9 -0
- package/dist/usage/UsageBreakdown.js +67 -0
- package/dist/usage/UsageChart.d.ts +10 -0
- package/dist/usage/UsageChart.js +47 -0
- package/dist/usage/UsageDialog.d.ts +6 -0
- package/dist/usage/UsageDialog.js +12 -0
- package/dist/usage/UsageLimits.d.ts +1 -0
- package/dist/usage/UsageLimits.js +57 -0
- package/dist/usage/UsageLimitsCard.d.ts +4 -0
- package/dist/usage/UsageLimitsCard.js +26 -0
- package/dist/usage/UsagePage.d.ts +7 -0
- package/dist/usage/UsagePage.js +154 -0
- package/dist/usage/UsagePane.d.ts +3 -0
- package/dist/usage/UsagePane.js +21 -0
- package/dist/usage/UsageSummary.d.ts +12 -0
- package/dist/usage/UsageSummary.js +15 -0
- package/dist/usage/UsageTiles.d.ts +7 -0
- package/dist/usage/UsageTiles.js +19 -0
- package/dist/usage/format.d.ts +13 -0
- package/dist/usage/format.js +55 -0
- package/dist/usage/limit-groups.d.ts +22 -0
- package/dist/usage/limit-groups.js +86 -0
- package/dist/usage/limits.d.ts +4 -0
- package/dist/usage/limits.js +58 -0
- package/dist/usage/money.d.ts +1 -0
- package/dist/usage/money.js +13 -0
- package/dist/usage/summary.d.ts +34 -0
- package/dist/usage/summary.js +94 -0
- package/package.json +895 -3
- package/src/agents/AccountDot.tsx +14 -0
- package/src/agents/AgentIcon.tsx +26 -0
- package/src/agents/ModelOptionControl.tsx +68 -0
- package/src/agents/ProviderLogo.tsx +20 -0
- package/src/agents/account-limits.ts +61 -0
- package/src/agents/accounts.ts +137 -0
- package/src/agents/model-name.ts +70 -0
- package/src/agents/model-options.ts +21 -0
- package/src/agents/provider-paths.ts +10 -0
- package/src/agents/status-look.ts +43 -0
- package/src/chat/account-choice.ts +44 -0
- package/src/chat/actions.ts +72 -0
- package/src/chat/activity.ts +8 -0
- package/src/chat/attachments.ts +118 -0
- package/src/chat/bookmarks.ts +87 -0
- package/src/chat/chat-client.ts +345 -0
- package/src/chat/chat-references.ts +11 -0
- package/src/chat/drafts.ts +165 -0
- package/src/chat/forks.ts +33 -0
- package/src/chat/guards.ts +84 -0
- package/src/chat/logic/ansi.ts +206 -0
- package/src/chat/logic/answers.ts +8 -0
- package/src/chat/logic/bookmarks.ts +42 -0
- package/src/chat/logic/context-usage.ts +36 -0
- package/src/chat/logic/fork.ts +200 -0
- package/src/chat/logic/handback.ts +10 -0
- package/src/chat/logic/json.ts +4 -0
- package/src/chat/logic/limit.ts +46 -0
- package/src/chat/logic/resume-compaction.ts +71 -0
- package/src/chat/logic/scrubber.ts +289 -0
- package/src/chat/logic/thread-cards.ts +64 -0
- package/src/chat/logic/timeline-copy.ts +65 -0
- package/src/chat/logic/timeline-target.ts +52 -0
- package/src/chat/logic/timeline.ts +419 -0
- package/src/chat/logic/tool-catalog.ts +62 -0
- package/src/chat/logic/tools.ts +102 -0
- package/src/chat/logic/welcome.ts +13 -0
- package/src/chat/logic/workflow.ts +66 -0
- package/src/chat/mentions.ts +232 -0
- package/src/chat/persisted-json.ts +67 -0
- package/src/chat/preferences.ts +179 -0
- package/src/chat/quote.ts +26 -0
- package/src/chat/recent-messages.ts +59 -0
- package/src/chat/resume-compaction-dismissals.ts +17 -0
- package/src/chat/runtime-modes.ts +18 -0
- package/src/chat/stash.ts +122 -0
- package/src/chat/subagent-conversation.ts +203 -0
- package/src/chat/subagent-list.ts +141 -0
- package/src/chat/subagent-support.ts +21 -0
- package/src/chat/subagent-view.ts +137 -0
- package/src/chat/thumbnails.ts +108 -0
- package/src/chat/timeline-flash.ts +33 -0
- package/src/chat/timeline-scroll.ts +199 -0
- package/src/chat/ui/AccountPill.tsx +31 -0
- package/src/chat/ui/AnsiOutput.tsx +18 -0
- package/src/chat/ui/BookmarkMarker.tsx +108 -0
- package/src/chat/ui/BookmarkSubmenu.tsx +53 -0
- package/src/chat/ui/ChatActivity.tsx +198 -0
- package/src/chat/ui/ChatReferenceChip.tsx +28 -0
- package/src/chat/ui/CodeBlock.tsx +175 -0
- package/src/chat/ui/Composer.tsx +1326 -0
- package/src/chat/ui/ComposerInput.tsx +187 -0
- package/src/chat/ui/DiffPool.tsx +36 -0
- package/src/chat/ui/EditDiff.tsx +30 -0
- package/src/chat/ui/FadingWords.tsx +18 -0
- package/src/chat/ui/ImageView.tsx +159 -0
- package/src/chat/ui/LimitState.tsx +165 -0
- package/src/chat/ui/Markdown.tsx +258 -0
- package/src/chat/ui/MessageActions.tsx +88 -0
- package/src/chat/ui/Pickers.tsx +272 -0
- package/src/chat/ui/PromptComposer.tsx +119 -0
- package/src/chat/ui/QuoteButton.tsx +103 -0
- package/src/chat/ui/ResumeCompactionDock.tsx +28 -0
- package/src/chat/ui/RunSettings.tsx +546 -0
- package/src/chat/ui/Scrubber.tsx +262 -0
- package/src/chat/ui/SubagentControls.tsx +66 -0
- package/src/chat/ui/SubagentInfo.tsx +67 -0
- package/src/chat/ui/SubagentStopButton.tsx +45 -0
- package/src/chat/ui/SubagentTimeline.tsx +170 -0
- package/src/chat/ui/Timeline.tsx +628 -0
- package/src/chat/ui/TimelineMenu.tsx +124 -0
- package/src/chat/ui/UnifiedDiff.tsx +99 -0
- package/src/chat/ui/UploadThumb.tsx +13 -0
- package/src/chat/ui/Welcome.tsx +22 -0
- package/src/chat/ui/chips.ts +15 -0
- package/src/chat/ui/code-lines.ts +60 -0
- package/src/chat/ui/code-streaming.ts +4 -0
- package/src/chat/ui/code-theme.ts +15 -0
- package/src/chat/ui/composer/chips.ts +43 -0
- package/src/chat/ui/composer/editor.ts +118 -0
- package/src/chat/ui/composer/insert.ts +22 -0
- package/src/chat/ui/composer/keys.ts +144 -0
- package/src/chat/ui/diff-theme.ts +23 -0
- package/src/chat/ui/file-links.ts +24 -0
- package/src/chat/ui/find-reveal.ts +23 -0
- package/src/chat/ui/full-diff.ts +25 -0
- package/src/chat/ui/icons.tsx +24 -0
- package/src/chat/ui/markdown-blocks.ts +123 -0
- package/src/chat/ui/quote-selection.ts +53 -0
- package/src/chat/ui/rehype-chips.ts +62 -0
- package/src/chat/ui/rehype-fade.ts +64 -0
- package/src/chat/ui/remark-html-as-text.ts +36 -0
- package/src/chat/ui/reply-context.ts +4 -0
- package/src/chat/ui/reveal.ts +135 -0
- package/src/chat/ui/rows/ForksRow.tsx +79 -0
- package/src/chat/ui/rows/MessageRows.tsx +415 -0
- package/src/chat/ui/rows/Rows.tsx +81 -0
- package/src/chat/ui/rows/SubagentRow.tsx +209 -0
- package/src/chat/ui/rows/TaskRow.tsx +91 -0
- package/src/chat/ui/rows/WorkRows.tsx +445 -0
- package/src/chat/ui/rows/WorkflowRow.tsx +120 -0
- package/src/chat/ui/rows/row-rhythm.ts +37 -0
- package/src/chat/ui/useToggleSet.ts +39 -0
- package/src/host.ts +324 -0
- package/src/lazy.tsx +64 -0
- package/src/locales/en/agent-chat.json +446 -0
- package/src/locales/en/agent-prompts.json +42 -0
- package/src/locales/en/agent-providers.json +131 -0
- package/src/locales/en/agent-usage.json +131 -0
- package/src/locales/nl/agent-chat.json +446 -0
- package/src/locales/nl/agent-prompts.json +42 -0
- package/src/locales/nl/agent-providers.json +131 -0
- package/src/locales/nl/agent-usage.json +131 -0
- package/src/locales.ts +33 -0
- package/src/mounted-registry.ts +45 -0
- package/src/port-transport.ts +146 -0
- package/src/prompts/logic/focus.ts +25 -0
- package/src/prompts/logic/keys.ts +116 -0
- package/src/prompts/logic/prompts.fixtures.ts +84 -0
- package/src/prompts/logic/prompts.ts +58 -0
- package/src/prompts/logic/subjects.ts +122 -0
- package/src/prompts/logic/useFocusAfterAnswer.ts +38 -0
- package/src/prompts/logic/usePromptSession.ts +114 -0
- package/src/prompts/ui/ApprovalBody.tsx +109 -0
- package/src/prompts/ui/PromptActions.tsx +109 -0
- package/src/prompts/ui/PromptCard.tsx +101 -0
- package/src/prompts/ui/PromptView.tsx +111 -0
- package/src/prompts/ui/QuestionBody.tsx +174 -0
- package/src/providers/AccountColors.tsx +8 -0
- package/src/providers/AccountDetail.tsx +209 -0
- package/src/providers/AccountVariables.tsx +126 -0
- package/src/providers/AddAccountForm.tsx +121 -0
- package/src/providers/CliDetail.tsx +157 -0
- package/src/providers/ProvidersPane.tsx +236 -0
- package/src/providers/account-actions.ts +67 -0
- package/src/providers/parts.tsx +25 -0
- package/src/providers/provider-abilities.ts +9 -0
- package/src/providers/variables.ts +87 -0
- package/src/scope.ts +30 -0
- package/src/settings/sections.ts +47 -0
- package/src/state/chats.ts +279 -0
- package/src/state/provider-accounts.ts +87 -0
- package/src/state/providers.ts +50 -0
- package/src/state/usage.ts +196 -0
- package/src/storage.ts +113 -0
- package/src/theme.css +212 -0
- package/src/transport.ts +50 -0
- package/src/ui/PlainTextarea.tsx +6 -0
- package/src/usage/LimitsList.tsx +232 -0
- package/src/usage/UsageBreakdown.tsx +210 -0
- package/src/usage/UsageChart.tsx +113 -0
- package/src/usage/UsageDialog.tsx +20 -0
- package/src/usage/UsageLimits.tsx +145 -0
- package/src/usage/UsageLimitsCard.tsx +36 -0
- package/src/usage/UsagePage.tsx +276 -0
- package/src/usage/UsagePane.tsx +52 -0
- package/src/usage/UsageSummary.tsx +50 -0
- package/src/usage/UsageTiles.tsx +34 -0
- package/src/usage/format.ts +71 -0
- package/src/usage/limit-groups.ts +119 -0
- package/src/usage/limits.ts +71 -0
- package/src/usage/money.ts +14 -0
- package/src/usage/summary.ts +137 -0
|
@@ -0,0 +1,1326 @@
|
|
|
1
|
+
import { useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { indentLess, indentMore, insertNewline } from '@codemirror/commands';
|
|
4
|
+
import { ensureSyntaxTree, syntaxTree } from '@codemirror/language';
|
|
5
|
+
import type { EditorState } from '@codemirror/state';
|
|
6
|
+
import { EditorView } from '@codemirror/view';
|
|
7
|
+
import clsx from 'clsx';
|
|
8
|
+
import { ArrowUp, ChevronDown, Clock, Copy, FastForward, MessageSquare, Paperclip, Pencil, Plus, Square, SquareSlash, X, Zap } from 'lucide-react';
|
|
9
|
+
import type {
|
|
10
|
+
AgentKind,
|
|
11
|
+
ChatApprovalItem,
|
|
12
|
+
ChatAttachmentUpload,
|
|
13
|
+
ChatInfo,
|
|
14
|
+
ChatItem,
|
|
15
|
+
ChatQueuedMessage,
|
|
16
|
+
ChatQuestionItem,
|
|
17
|
+
ChatSkill,
|
|
18
|
+
ModelInfo,
|
|
19
|
+
ModelSelection,
|
|
20
|
+
RuntimeMode
|
|
21
|
+
} from '@adecore/agent-contracts';
|
|
22
|
+
import { chatHost } from '../../host';
|
|
23
|
+
import { useChatScope } from '../../scope';
|
|
24
|
+
import { errorCode } from '../../transport';
|
|
25
|
+
import { useAccountChoice } from '../account-choice';
|
|
26
|
+
import { useChatActions } from '../actions';
|
|
27
|
+
import type { ChatSendExtras } from '../chat-client';
|
|
28
|
+
import { checkAttachmentLimits, filesOf, formatBytes, isImageAttachment, readAttachments, readStoredAttachments, uploadBytes } from '../attachments';
|
|
29
|
+
import { chatSuggestions } from '../chat-references';
|
|
30
|
+
import { EMPTY_DRAFT, isEmptyDraft, joinDraftText, readDraft, takeBackIntoDraft, takeDraftOffers, writeDraft, type ChatDraft } from '../drafts';
|
|
31
|
+
import {
|
|
32
|
+
carriesMentions,
|
|
33
|
+
droppedMentions,
|
|
34
|
+
NO_MENTION_SEARCH,
|
|
35
|
+
dropQuery,
|
|
36
|
+
findMentionQuery,
|
|
37
|
+
findSkillQuery,
|
|
38
|
+
insertMention,
|
|
39
|
+
insertSkill,
|
|
40
|
+
mentionPick,
|
|
41
|
+
pastedMentions,
|
|
42
|
+
presentMentions,
|
|
43
|
+
presentSkills,
|
|
44
|
+
type MentionQuery,
|
|
45
|
+
type MentionSearch,
|
|
46
|
+
type TextRange
|
|
47
|
+
} from '../mentions';
|
|
48
|
+
import { RESUME_COMPACTION_TOKENS, resumeCompactionOffer } from '../logic/resume-compaction';
|
|
49
|
+
import { dismissResumeCompaction, useResumeCompactionDismissal } from '../resume-compaction-dismissals';
|
|
50
|
+
import { composerStopLabel, composerStopOf } from '../subagent-list';
|
|
51
|
+
import { PROMPT_MAX_CHARS, pasteBecomesAttachment, pastedTextName, promptGuard, usableSlashCommands } from '../guards';
|
|
52
|
+
import { withQuote } from '../quote';
|
|
53
|
+
import { rememberChatAccount, rememberChatPreferences, rememberChatSelection } from '../preferences';
|
|
54
|
+
import { STASH_SHORTCUT, stashDraft, type StashedPrompt, useStash } from '../stash';
|
|
55
|
+
import { pageTimeline, scrollTimelineToEnd, subscribeTimelineEnd, timelineAtEnd } from '../timeline-scroll';
|
|
56
|
+
import { ChatActivity } from './ChatActivity';
|
|
57
|
+
import { ChatReferenceChip } from './ChatReferenceChip';
|
|
58
|
+
import { chipDecorations } from './composer/chips';
|
|
59
|
+
import { enterAction, inCode, inFenceBody, inOpenFence, listItemAt, recallDirection, tabSpaces } from './composer/keys';
|
|
60
|
+
import { ComposerInput, type ComposerInputHandle } from './ComposerInput';
|
|
61
|
+
import { PromptComposer } from './PromptComposer';
|
|
62
|
+
import { QuoteTakerContext } from './quote-selection';
|
|
63
|
+
import { LimitDock } from './LimitState';
|
|
64
|
+
import { ResumeCompactionDock } from './ResumeCompactionDock';
|
|
65
|
+
import { StashPicker } from './Pickers';
|
|
66
|
+
import { RunSettings } from './RunSettings';
|
|
67
|
+
import { UploadThumb } from './UploadThumb';
|
|
68
|
+
import { formatNumber } from '@adecore/ui/format';
|
|
69
|
+
import {
|
|
70
|
+
ButtonGroup,
|
|
71
|
+
ContextMenu,
|
|
72
|
+
copyText,
|
|
73
|
+
ErrorBoundary,
|
|
74
|
+
FileIcon,
|
|
75
|
+
Icon,
|
|
76
|
+
IconButton,
|
|
77
|
+
isModHeld,
|
|
78
|
+
KEY_SHORTCUTS,
|
|
79
|
+
matchesShortcut,
|
|
80
|
+
Menu,
|
|
81
|
+
PromptDialog,
|
|
82
|
+
Surface,
|
|
83
|
+
Tooltip,
|
|
84
|
+
useNow
|
|
85
|
+
} from '@adecore/ui';
|
|
86
|
+
import { useChatRow, waitingRequestsOf } from '../../state/chats';
|
|
87
|
+
import { useProviders } from '../../state/providers';
|
|
88
|
+
|
|
89
|
+
const SEARCH_DEBOUNCE_MS = 80;
|
|
90
|
+
// What fits above the composer without turning the picker into a file tree.
|
|
91
|
+
const MENTION_RESULTS = 8;
|
|
92
|
+
// The chats go above the files, so a few leave the files in view.
|
|
93
|
+
const CHAT_RESULTS = 4;
|
|
94
|
+
const NOTICE_MS = 4000;
|
|
95
|
+
// How many sent prompts the arrow keys walk back through, per chat.
|
|
96
|
+
const PROMPT_HISTORY = 50;
|
|
97
|
+
|
|
98
|
+
// Commands the composer handles itself; the CLI's own ones are sent through as text.
|
|
99
|
+
const LOCAL_COMMANDS = ['model', 'compact', 'clear'];
|
|
100
|
+
|
|
101
|
+
/* Files and paths dropped on the card become attachments and chips there. CodeMirror would paste a
|
|
102
|
+
file's text, or the drag's own text, at the drop point on top of that. */
|
|
103
|
+
const LEAVE_DROPS_TO_THE_CARD = EditorView.domEventHandlers({
|
|
104
|
+
drop: (event) => event.dataTransfer !== null && (event.dataTransfer.types.includes('Files') || carriesMentions(event.dataTransfer.types))
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
interface ComposerProps {
|
|
108
|
+
chatId: string;
|
|
109
|
+
info: ChatInfo;
|
|
110
|
+
focused: boolean;
|
|
111
|
+
/*
|
|
112
|
+
* Set where the chat's prompts are answered somewhere else, such as a stack over a canvas: the
|
|
113
|
+
* composer then only points there, and this takes the person to it.
|
|
114
|
+
*/
|
|
115
|
+
answerPromptsElsewhere?: () => void;
|
|
116
|
+
disabled: boolean;
|
|
117
|
+
/* Nothing can be written, while the chat's own prompts are still answered here. */
|
|
118
|
+
readOnly?: boolean;
|
|
119
|
+
/* Opened for one CLI from a menu. The model is the remembered one and there is nothing to pick. */
|
|
120
|
+
providerFixed: boolean;
|
|
121
|
+
onSend(text: string, extras: ChatSendExtras): void;
|
|
122
|
+
/* Another provider's model was picked before the first message; whatever holds the chat has to follow. */
|
|
123
|
+
onRetarget(provider: AgentKind, selection: ModelSelection): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function usePendingRequests(chatId: string) {
|
|
127
|
+
// The structure, which a delta leaves alone. The prompts and the requests are items of their own.
|
|
128
|
+
const structure = useChatRow(chatId, (row) => row?.structure);
|
|
129
|
+
const order = useChatRow(chatId, (row) => row?.order);
|
|
130
|
+
const waitingBefore = useChatRow(chatId, (row) => row?.waitingBefore);
|
|
131
|
+
return useMemo(() => {
|
|
132
|
+
const approvals: ChatApprovalItem[] = [];
|
|
133
|
+
const questions: ChatQuestionItem[] = [];
|
|
134
|
+
for (const item of waitingRequestsOf(structure && order ? { structure, order, waitingBefore } : undefined)) {
|
|
135
|
+
if (item.kind === 'approval') {
|
|
136
|
+
approvals.push(item);
|
|
137
|
+
} else {
|
|
138
|
+
questions.push(item);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { approvals, questions };
|
|
142
|
+
}, [structure, order, waitingBefore]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* The empty box names its sigils as key caps, so they read as keys to press rather than as punctuation. */
|
|
146
|
+
function hintedPlaceholder(lead: string, joiner: string, hints: ReadonlyArray<{ key: string; label: string }>): HTMLElement {
|
|
147
|
+
const root = document.createElement('span');
|
|
148
|
+
root.className = 'composer-hints';
|
|
149
|
+
const extra = document.createElement('span');
|
|
150
|
+
extra.className = 'composer-hints-extra';
|
|
151
|
+
extra.append(joiner);
|
|
152
|
+
for (const hint of hints) {
|
|
153
|
+
const cap = document.createElement('kbd');
|
|
154
|
+
cap.textContent = hint.key;
|
|
155
|
+
extra.append(cap, hint.label);
|
|
156
|
+
}
|
|
157
|
+
root.append(lead, extra);
|
|
158
|
+
return root;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function splitPath(path: string): { name: string; dir: string } {
|
|
162
|
+
const slash = path.lastIndexOf('/');
|
|
163
|
+
return slash < 0 ? { name: path, dir: '' } : { name: path.slice(slash + 1), dir: path.slice(0, slash) };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Keep the editor mounted while a pending request takes over, so its selection and draft survive.
|
|
167
|
+
export function Composer({ chatId, info, focused, answerPromptsElsewhere, disabled, readOnly = false, providerFixed, onSend, onRetarget }: ComposerProps) {
|
|
168
|
+
const { t } = useTranslation('agent-chat');
|
|
169
|
+
const [draft, setDraft] = useState<ChatDraft>(() => readDraft(chatId));
|
|
170
|
+
const [historyIndex, setHistoryIndex] = useState<number | null>(null);
|
|
171
|
+
const [menuIndex, setMenuIndex] = useState(0);
|
|
172
|
+
const [mention, setMention] = useState<MentionQuery | null>(null);
|
|
173
|
+
const [skillQuery, setSkillQuery] = useState<MentionQuery | null>(null);
|
|
174
|
+
const [skills, setSkills] = useState<ChatSkill[]>([]);
|
|
175
|
+
const [searched, setSearched] = useState<MentionSearch>(NO_MENTION_SEARCH);
|
|
176
|
+
const configuring = useRef(false);
|
|
177
|
+
const [configurationPending, setConfigurationPending] = useState(false);
|
|
178
|
+
const [notice, setNotice] = useState<string | null>(null);
|
|
179
|
+
const [dragging, setDragging] = useState(false);
|
|
180
|
+
const [modelPickerOpen, setModelPickerOpen] = useState(false);
|
|
181
|
+
const [confirmClear, setConfirmClear] = useState(false);
|
|
182
|
+
const [takingBack, setTakingBack] = useState<string | null>(null);
|
|
183
|
+
const scope = useChatScope();
|
|
184
|
+
const actions = useChatActions();
|
|
185
|
+
const { isApplePlatform, notify } = chatHost();
|
|
186
|
+
const registerQuoteTaker = useContext(QuoteTakerContext);
|
|
187
|
+
const inputRef = useRef<ComposerInputHandle>(null);
|
|
188
|
+
// Taking a queued message back waits on the machine, and what was typed meanwhile is what it merges with.
|
|
189
|
+
const draftRef = useRef(draft);
|
|
190
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
191
|
+
const [dictationToolbar, setDictationToolbar] = useState<HTMLDivElement | null>(null);
|
|
192
|
+
// A paste event says nothing about the keys behind it, so the key that asked for text inline is remembered here.
|
|
193
|
+
const pasteInlineRef = useRef(false);
|
|
194
|
+
const providers = useProviders((s) => s.providers);
|
|
195
|
+
const { approvals, questions } = usePendingRequests(chatId);
|
|
196
|
+
const order = useChatRow(chatId, (row) => row?.order);
|
|
197
|
+
// The structure, which a delta leaves alone. The prompts and the requests are items of their own.
|
|
198
|
+
const items = useChatRow(chatId, (row) => row?.structure);
|
|
199
|
+
const chats = chatHost().useReferableChats();
|
|
200
|
+
const placeholderLead = chatHost().useComposerPlaceholder(scope.id, chatId);
|
|
201
|
+
|
|
202
|
+
const pending = useMemo(() => [...approvals, ...questions], [approvals, questions]);
|
|
203
|
+
const writable = !disabled && !readOnly;
|
|
204
|
+
const provider = providers.find((entry) => entry.kind === info.provider);
|
|
205
|
+
// Absent until the host answered `provider.list`, so only an explicit false hides anything.
|
|
206
|
+
const capabilities = provider?.capabilities;
|
|
207
|
+
const compaction = capabilities?.compaction;
|
|
208
|
+
const dismissedTurnId = useResumeCompactionDismissal(chatId);
|
|
209
|
+
/* The cheap half of the offer, so a chat that can never make one keeps no timer. */
|
|
210
|
+
const couldOfferCompaction = compaction !== undefined && compaction !== 'none' && info.usage.contextTokens >= RESUME_COMPACTION_TOKENS;
|
|
211
|
+
const now = useNow(60_000, couldOfferCompaction);
|
|
212
|
+
const compactionOffer = !couldOfferCompaction
|
|
213
|
+
? null
|
|
214
|
+
: resumeCompactionOffer({
|
|
215
|
+
info,
|
|
216
|
+
compaction,
|
|
217
|
+
items: (order ?? []).map((id) => items?.[id]).filter((item): item is ChatItem => item !== undefined),
|
|
218
|
+
dismissedTurnId,
|
|
219
|
+
now
|
|
220
|
+
});
|
|
221
|
+
const models: ModelInfo[] = provider?.models ?? [];
|
|
222
|
+
const model = models.find((entry) => entry.slug === info.selection.model);
|
|
223
|
+
const busy = info.activeTurnId !== null;
|
|
224
|
+
const queue = info.queue ?? [];
|
|
225
|
+
const text = draft.text;
|
|
226
|
+
const quote = draft.quote;
|
|
227
|
+
// The CLI announces its session on the first message, so anything before that is still a blank chat.
|
|
228
|
+
const started = info.agentSessionId !== null || info.usage.turns > 0;
|
|
229
|
+
/*
|
|
230
|
+
* A chat that has started keeps its provider (the CLI holds the thread), and one opened for a
|
|
231
|
+
* named CLI was never going to change it. Either way the models stay switchable. The CLI takes
|
|
232
|
+
* the new one on the restart the next send does anyway. With one provider in the list the
|
|
233
|
+
* picker drops its group headers on its own, so it reads as that CLI's own catalog.
|
|
234
|
+
*/
|
|
235
|
+
const accountChoice = useAccountChoice(info.provider, info.account);
|
|
236
|
+
const pickable =
|
|
237
|
+
started || providerFixed
|
|
238
|
+
? providers.filter((entry) => entry.kind === info.provider)
|
|
239
|
+
: providers.filter((entry) => entry.installed && entry.capabilities.chat);
|
|
240
|
+
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (focused) {
|
|
243
|
+
inputRef.current?.focus();
|
|
244
|
+
}
|
|
245
|
+
}, [focused]);
|
|
246
|
+
|
|
247
|
+
useEffect(() => {
|
|
248
|
+
draftRef.current = draft;
|
|
249
|
+
writeDraft(chatId, draft);
|
|
250
|
+
}, [chatId, draft]);
|
|
251
|
+
|
|
252
|
+
useEffect(
|
|
253
|
+
() =>
|
|
254
|
+
takeDraftOffers(chatId, (offered) => {
|
|
255
|
+
setDraft((current) => ({ ...current, text: joinDraftText(current.text, offered) }));
|
|
256
|
+
inputRef.current?.focus();
|
|
257
|
+
}),
|
|
258
|
+
[chatId]
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
useEffect(
|
|
262
|
+
() =>
|
|
263
|
+
registerQuoteTaker?.((selected) => {
|
|
264
|
+
setDraft((current) => ({ ...current, quote: selected }));
|
|
265
|
+
inputRef.current?.focus();
|
|
266
|
+
}),
|
|
267
|
+
[registerQuoteTaker]
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (!notice) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const timer = setTimeout(() => setNotice(null), NOTICE_MS);
|
|
275
|
+
return () => clearTimeout(timer);
|
|
276
|
+
}, [notice]);
|
|
277
|
+
|
|
278
|
+
// Every keystroke inside an `@word` searches again; a slow answer must not overwrite a newer one.
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
if (mention === null) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let stale = false;
|
|
284
|
+
const search = (): void => {
|
|
285
|
+
const search = chatHost().searchFiles;
|
|
286
|
+
if (search === null) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
search(scope.id, info.cwd, mention.query, MENTION_RESULTS)
|
|
290
|
+
.then((files) => {
|
|
291
|
+
if (!stale) {
|
|
292
|
+
setSearched({ query: mention.query, files });
|
|
293
|
+
setMenuIndex(0);
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.catch(() => undefined);
|
|
297
|
+
};
|
|
298
|
+
// A bare `@` is not a keystroke in a query. It opens the list of what is there, at once.
|
|
299
|
+
if (mention.query === '') {
|
|
300
|
+
search();
|
|
301
|
+
return () => {
|
|
302
|
+
stale = true;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const timer = setTimeout(search, SEARCH_DEBOUNCE_MS);
|
|
306
|
+
return () => {
|
|
307
|
+
stale = true;
|
|
308
|
+
clearTimeout(timer);
|
|
309
|
+
};
|
|
310
|
+
}, [scope, info.cwd, mention]);
|
|
311
|
+
|
|
312
|
+
/* The host's skill list, once per chat and again once the CLI announced its own after the first message. */
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
let stale = false;
|
|
315
|
+
scope.chats
|
|
316
|
+
.listSkills(chatId)
|
|
317
|
+
.then((found) => {
|
|
318
|
+
if (!stale) {
|
|
319
|
+
setSkills(found);
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
.catch(() => undefined);
|
|
323
|
+
return () => {
|
|
324
|
+
stale = true;
|
|
325
|
+
};
|
|
326
|
+
}, [scope, chatId, info.skills]);
|
|
327
|
+
|
|
328
|
+
const history = useMemo(() => {
|
|
329
|
+
const prompts: Array<{ text: string; mentions: string[] }> = [];
|
|
330
|
+
for (const id of order ?? []) {
|
|
331
|
+
const item = items?.[id];
|
|
332
|
+
if (item?.kind === 'user') {
|
|
333
|
+
prompts.push({ text: item.text, mentions: item.mentions ?? [] });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Walking back further than this is faster with the timeline than with the arrow key.
|
|
337
|
+
return prompts.slice(-PROMPT_HISTORY);
|
|
338
|
+
}, [order, items]);
|
|
339
|
+
|
|
340
|
+
const commandQuery = text.startsWith('/') && !text.includes('\n') ? text.slice(1).trim().toLowerCase() : null;
|
|
341
|
+
const commands = useMemo(() => {
|
|
342
|
+
if (commandQuery === null) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
const known = new Set(skills.map((skill) => skill.name));
|
|
346
|
+
const own = LOCAL_COMMANDS.map((name) => ({ name, hint: t(`composer.commands.${name}`), local: true, skill: false }));
|
|
347
|
+
const cli = usableSlashCommands(info.slashCommands)
|
|
348
|
+
.filter((name) => !LOCAL_COMMANDS.includes(name))
|
|
349
|
+
.map((name) => ({
|
|
350
|
+
name,
|
|
351
|
+
hint: known.has(name) ? t('composer.commands.skill') : t('composer.commands.cli', { cli: provider?.name ?? t('composer.commands.anyCli') }),
|
|
352
|
+
local: false,
|
|
353
|
+
skill: known.has(name)
|
|
354
|
+
}));
|
|
355
|
+
return [...own, ...cli].filter((command) => command.name.startsWith(commandQuery)).slice(0, 8);
|
|
356
|
+
}, [commandQuery, info.slashCommands, provider?.name, skills, t]);
|
|
357
|
+
|
|
358
|
+
const skillMatches = useMemo(() => {
|
|
359
|
+
if (skillQuery === null) {
|
|
360
|
+
return [];
|
|
361
|
+
}
|
|
362
|
+
const query = skillQuery.query.toLowerCase();
|
|
363
|
+
return skills.filter((skill) => skill.name.toLowerCase().includes(query)).slice(0, 8);
|
|
364
|
+
}, [skillQuery, skills]);
|
|
365
|
+
|
|
366
|
+
const commandMenuOpen = commandQuery !== null && commands.length > 0;
|
|
367
|
+
const skillMenuOpen = !commandMenuOpen && skillQuery !== null && skillMatches.length > 0;
|
|
368
|
+
const mentionMenuOpen = !commandMenuOpen && !skillMenuOpen && mention !== null;
|
|
369
|
+
// Results belong to the query that asked for them; a closed picker shows none while the next answer is on its way.
|
|
370
|
+
const files = mention === null ? [] : searched.files;
|
|
371
|
+
const chatMatches = useMemo(
|
|
372
|
+
() => (mention === null ? [] : chatSuggestions(chats, mention.query, [chatId, ...draft.chats], CHAT_RESULTS)),
|
|
373
|
+
[chatId, chats, draft.chats, mention]
|
|
374
|
+
);
|
|
375
|
+
const mentionCount = chatMatches.length + files.length;
|
|
376
|
+
const editorExtensions = useMemo(
|
|
377
|
+
() => [chipDecorations({ mentions: draft.mentions, skills: draft.skills }), LEAVE_DROPS_TO_THE_CARD],
|
|
378
|
+
[draft.mentions, draft.skills]
|
|
379
|
+
);
|
|
380
|
+
const guard = promptGuard(withQuote(quote, text));
|
|
381
|
+
|
|
382
|
+
const setText = (next: string, mentions = draft.mentions, chosen = draft.skills): void => {
|
|
383
|
+
setDraft((current) => ({ ...current, text: next, mentions, skills: chosen }));
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const clearDraft = (): void => {
|
|
387
|
+
setDraft(EMPTY_DRAFT);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const removeQuote = (): void => {
|
|
391
|
+
setDraft((current) => ({ ...current, quote: '' }));
|
|
392
|
+
inputRef.current?.focus();
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const configure = (patch: { selection?: ModelSelection; runtimeMode?: RuntimeMode; account?: string }): void => {
|
|
396
|
+
if (configuring.current) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
configuring.current = true;
|
|
400
|
+
setConfigurationPending(true);
|
|
401
|
+
void actions
|
|
402
|
+
.configure(chatId, patch)
|
|
403
|
+
.then(() => {
|
|
404
|
+
if (patch.selection) {
|
|
405
|
+
rememberChatSelection(info.provider, patch.selection);
|
|
406
|
+
}
|
|
407
|
+
if (patch.runtimeMode) {
|
|
408
|
+
rememberChatPreferences({ runtimeMode: patch.runtimeMode });
|
|
409
|
+
}
|
|
410
|
+
if (patch.account) {
|
|
411
|
+
rememberChatAccount(scope.id, info.provider, patch.account);
|
|
412
|
+
}
|
|
413
|
+
})
|
|
414
|
+
.catch((error: unknown) => setNotice(error instanceof Error ? error.message : String(error)))
|
|
415
|
+
.finally(() => {
|
|
416
|
+
configuring.current = false;
|
|
417
|
+
setConfigurationPending(false);
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
const chooseAccount = (account: string): void => configure({ account });
|
|
422
|
+
|
|
423
|
+
/* A model of another CLI re-points the whole chat; one of this CLI's own is a configure. */
|
|
424
|
+
const chooseModel = (provider: AgentKind, slug: string): void => {
|
|
425
|
+
const selection: ModelSelection = { model: slug, options: {} };
|
|
426
|
+
if (provider !== info.provider) {
|
|
427
|
+
if (configuring.current) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
configuring.current = true;
|
|
431
|
+
setConfigurationPending(true);
|
|
432
|
+
void onRetarget(provider, selection)
|
|
433
|
+
.then(() => rememberChatSelection(provider, selection))
|
|
434
|
+
.catch((error: unknown) => setNotice(error instanceof Error ? error.message : String(error)))
|
|
435
|
+
.finally(() => {
|
|
436
|
+
configuring.current = false;
|
|
437
|
+
setConfigurationPending(false);
|
|
438
|
+
});
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
configure({ selection });
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const stop = (shiftKey: boolean): void => {
|
|
445
|
+
if (composerStopOf(shiftKey) === 'turn') {
|
|
446
|
+
void actions.stopTurn(chatId, false).catch((error: unknown) => setNotice(error instanceof Error ? error.message : String(error)));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
chatHost().confirm.stopSubagents(
|
|
450
|
+
scope.id,
|
|
451
|
+
chatId,
|
|
452
|
+
() => void actions.stopTurn(chatId, true).catch((error: unknown) => setNotice(error instanceof Error ? error.message : String(error)))
|
|
453
|
+
);
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/* The host decides whether a turn is in the way; only its refusal asks the person first. */
|
|
457
|
+
const clearThread = async (): Promise<void> => {
|
|
458
|
+
try {
|
|
459
|
+
await actions.clear(chatId, false);
|
|
460
|
+
} catch (e) {
|
|
461
|
+
if (errorCode(e) === 'chat-busy') {
|
|
462
|
+
setConfirmClear(true);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
setNotice(t('composer.notice.clearFailed'));
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const forceClearThread = async (): Promise<void> => {
|
|
470
|
+
await actions.clear(chatId, true);
|
|
471
|
+
setConfirmClear(false);
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
const compact = (): void => {
|
|
475
|
+
void actions.compact(chatId).catch(() => setNotice(t('composer.notice.compactFailed')));
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const runCommand = (name: string): boolean => {
|
|
479
|
+
switch (name) {
|
|
480
|
+
case 'model':
|
|
481
|
+
setModelPickerOpen(true);
|
|
482
|
+
return true;
|
|
483
|
+
case 'compact':
|
|
484
|
+
void actions.compact(chatId).catch(() => undefined);
|
|
485
|
+
return true;
|
|
486
|
+
case 'clear':
|
|
487
|
+
void clearThread();
|
|
488
|
+
return true;
|
|
489
|
+
default:
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const same = (a: MentionQuery | null, b: MentionQuery | null): boolean => a?.start === b?.start && a?.query === b?.query;
|
|
495
|
+
|
|
496
|
+
/* Which picker the caret opens: `@` for a file, `$` for a skill, or neither. In code a sigil is just text. */
|
|
497
|
+
const trackTriggers = (value: string, selection: TextRange, state: EditorState): void => {
|
|
498
|
+
const empty = selection.from === selection.to;
|
|
499
|
+
const tree = empty ? (ensureSyntaxTree(state, selection.from, 50) ?? syntaxTree(state)) : null;
|
|
500
|
+
const caret = tree !== null && !inCode(tree, value, selection.from) ? selection.from : null;
|
|
501
|
+
const skill = caret === null ? null : findSkillQuery(value, caret);
|
|
502
|
+
setSkillQuery((current) => (same(current, skill) ? current : skill));
|
|
503
|
+
// A CLI that does not expand `@path` gets the text as it is, so the picker stays out of the way.
|
|
504
|
+
const next = caret === null || capabilities?.mentions === false ? null : findMentionQuery(value, caret);
|
|
505
|
+
setMention((current) => (same(current, next) ? current : next));
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// The inserted text reaches the editor with the render it causes, so the caret waits a frame for it.
|
|
509
|
+
const moveCaret = (caret: number): void => {
|
|
510
|
+
requestAnimationFrame(() => inputRef.current?.setCaret(caret));
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const chooseMention = (path: string): void => {
|
|
514
|
+
if (!mention) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const result = insertMention(text, mention, path);
|
|
518
|
+
setText(result.text, draft.mentions.includes(path) ? draft.mentions : [...draft.mentions, path]);
|
|
519
|
+
setMention(null);
|
|
520
|
+
moveCaret(result.caret);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/* A picked chat sits beside the text as a chip, so the `@query` that found it goes. */
|
|
524
|
+
const chooseChat = (id: string): void => {
|
|
525
|
+
if (!mention) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const result = dropQuery(text, mention);
|
|
529
|
+
setDraft((current) => ({ ...current, text: result.text, chats: current.chats.includes(id) ? current.chats : [...current.chats, id] }));
|
|
530
|
+
setMention(null);
|
|
531
|
+
moveCaret(result.caret);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const chooseMentionAt = (index: number): void => {
|
|
535
|
+
const pick = mention === null ? null : mentionPick(index, chatMatches, searched, mention.query);
|
|
536
|
+
if (pick?.kind === 'chat') {
|
|
537
|
+
chooseChat(pick.chat.id);
|
|
538
|
+
} else if (pick?.kind === 'file') {
|
|
539
|
+
chooseMention(pick.path);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const removeChat = (id: string): void => {
|
|
544
|
+
setDraft((current) => ({ ...current, chats: current.chats.filter((entry) => entry !== id) }));
|
|
545
|
+
inputRef.current?.focus();
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
/*
|
|
549
|
+
* A picked skill becomes a `$name` chip in the text and a name on the send, which is what
|
|
550
|
+
* dispatches it. The `/` menu lands here too, so both spellings end up on the same path.
|
|
551
|
+
*/
|
|
552
|
+
const chooseSkill = (name: string): void => {
|
|
553
|
+
const result = skillQuery ? insertSkill(text, skillQuery, name) : { text: `$${name} `, caret: name.length + 2 };
|
|
554
|
+
setText(result.text, draft.mentions, draft.skills.includes(name) ? draft.skills : [...draft.skills, name]);
|
|
555
|
+
setSkillQuery(null);
|
|
556
|
+
moveCaret(result.caret);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
/* Paths dragged in from a list of files. There is no mention query to insert into, so they land
|
|
560
|
+
at the end of the prompt and join the draft's mentions, which is what `chat.send` carries. */
|
|
561
|
+
const addMentions = (paths: string[]): void => {
|
|
562
|
+
const fresh = paths.filter((path) => path !== '');
|
|
563
|
+
if (fresh.length === 0 || capabilities?.mentions === false) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const appended = fresh.map((path) => `@${path}`).join(' ');
|
|
567
|
+
const before = text.replace(/\s+$/, '');
|
|
568
|
+
setText(before === '' ? `${appended} ` : `${before} ${appended} `, [...draft.mentions, ...fresh.filter((path) => !draft.mentions.includes(path))]);
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const addFiles = (incoming: File[]): void => {
|
|
572
|
+
if (incoming.length === 0) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (capabilities?.attachments === false) {
|
|
576
|
+
setNotice(t('composer.notice.noAttachments', { agent: provider?.name ?? t('composer.notice.thisAgent') }));
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const checked = checkAttachmentLimits(
|
|
580
|
+
draft.attachments.length,
|
|
581
|
+
incoming.map((file) => ({ name: file.name, mime: file.type, bytes: file.size, file })),
|
|
582
|
+
draft.attachments.reduce((bytes, attachment) => bytes + uploadBytes(attachment), 0)
|
|
583
|
+
);
|
|
584
|
+
if (checked.rejected[0]) {
|
|
585
|
+
setNotice(t('composer.notice.rejected', { name: checked.rejected[0].name || t('composer.notice.thatFile'), reason: checked.rejected[0].reason }));
|
|
586
|
+
}
|
|
587
|
+
if (checked.accepted.length === 0) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
readAttachments(checked.accepted.map((entry) => entry.file))
|
|
591
|
+
.then((attachments) => setDraft((current) => ({ ...current, attachments: [...current.attachments, ...attachments] })))
|
|
592
|
+
.catch(() => setNotice(t('composer.notice.unreadable')));
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const insertIntoDraft = (added: string): void => {
|
|
596
|
+
if (writable) {
|
|
597
|
+
inputRef.current?.insert(added);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
const removeAttachment = (index: number): void => {
|
|
602
|
+
setDraft((current) => ({ ...current, attachments: current.attachments.filter((_, i) => i !== index) }));
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const submit = (): void => {
|
|
606
|
+
const trimmed = text.trim();
|
|
607
|
+
if (isEmptyDraft(draft) || !writable || guard.tooLong) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
// Recheck restored drafts and files that finished reading concurrently.
|
|
611
|
+
const rejected = checkAttachmentLimits(
|
|
612
|
+
0,
|
|
613
|
+
draft.attachments.map((attachment) => ({ ...attachment, bytes: uploadBytes(attachment) }))
|
|
614
|
+
).rejected[0];
|
|
615
|
+
if (rejected) {
|
|
616
|
+
setNotice(`${rejected.name}: ${rejected.reason}`);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const chosen = commands[menuIndex];
|
|
620
|
+
if (commandQuery !== null && chosen?.local && runCommand(chosen.name)) {
|
|
621
|
+
clearDraft();
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (commandQuery !== null && chosen?.skill) {
|
|
625
|
+
chooseSkill(chosen.name);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
// Whoever sends wants to see what comes back, wherever they were reading.
|
|
629
|
+
scrollTimelineToEnd(chatId, 'instant');
|
|
630
|
+
if (commandQuery !== null && chosen && !chosen.local) {
|
|
631
|
+
onSend(`/${chosen.name}`, {});
|
|
632
|
+
clearDraft();
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
onSend(withQuote(quote, trimmed), {
|
|
636
|
+
mentions: presentMentions(trimmed, draft.mentions),
|
|
637
|
+
skills: presentSkills(trimmed, draft.skills),
|
|
638
|
+
chats: draft.chats,
|
|
639
|
+
attachments: draft.attachments
|
|
640
|
+
});
|
|
641
|
+
clearDraft();
|
|
642
|
+
setMention(null);
|
|
643
|
+
setSkillQuery(null);
|
|
644
|
+
setHistoryIndex(null);
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
/* A stashed prompt comes back as text, mentions and skills; its files were never kept. */
|
|
648
|
+
const restoreStashed = (prompt: StashedPrompt): void => {
|
|
649
|
+
setDraft((current) => ({ ...current, text: prompt.text, mentions: [...prompt.mentions], skills: [...prompt.skills] }));
|
|
650
|
+
setHistoryIndex(null);
|
|
651
|
+
inputRef.current?.focus();
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
/*
|
|
655
|
+
* The files come back from the machine before the message leaves the queue, since the machine only
|
|
656
|
+
* serves a file some message still holds. The machine's refusal is what says it already went out.
|
|
657
|
+
*/
|
|
658
|
+
const takeBack = async (message: ChatQueuedMessage): Promise<void> => {
|
|
659
|
+
if (takingBack !== null) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const failed = (e: unknown): void => {
|
|
663
|
+
notify({ kind: 'error', title: t('composer.queue.editFailed'), description: e instanceof Error ? e.message : String(e) });
|
|
664
|
+
};
|
|
665
|
+
const readFiles = async (): Promise<ChatAttachmentUpload[]> => {
|
|
666
|
+
const stored = message.attachments ?? [];
|
|
667
|
+
if (stored.length === 0) {
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
const files = chatHost().attachments;
|
|
671
|
+
return readStoredAttachments((attachment) => files.read(scope.id, chatId, attachment.id), stored);
|
|
672
|
+
};
|
|
673
|
+
setTakingBack(message.id);
|
|
674
|
+
try {
|
|
675
|
+
let uploads: ChatAttachmentUpload[];
|
|
676
|
+
try {
|
|
677
|
+
uploads = await readFiles();
|
|
678
|
+
} catch (e) {
|
|
679
|
+
failed(e);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const taken: Omit<ChatDraft, 'quote'> = {
|
|
683
|
+
text: message.text,
|
|
684
|
+
mentions: message.mentions ?? [],
|
|
685
|
+
skills: message.skills ?? [],
|
|
686
|
+
chats: message.chats ?? [],
|
|
687
|
+
attachments: uploads
|
|
688
|
+
};
|
|
689
|
+
// A file that would not fit is refused here, while the message still holds it on the machine.
|
|
690
|
+
const wouldReject = takeBackIntoDraft(draftRef.current, taken).rejected[0];
|
|
691
|
+
if (wouldReject) {
|
|
692
|
+
setNotice(t('composer.notice.queuedDoesNotFit', { name: wouldReject.name || t('composer.notice.thatFile'), reason: wouldReject.reason }));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
try {
|
|
696
|
+
await actions.unqueue(chatId, message.id);
|
|
697
|
+
} catch (e) {
|
|
698
|
+
if (errorCode(e) === 'request-not-found') {
|
|
699
|
+
notify({ kind: 'error', title: t('composer.queue.alreadySent') });
|
|
700
|
+
} else {
|
|
701
|
+
failed(e);
|
|
702
|
+
}
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const merged = takeBackIntoDraft(draftRef.current, taken);
|
|
706
|
+
setDraft(merged.draft);
|
|
707
|
+
if (merged.rejected[0]) {
|
|
708
|
+
setNotice(t('composer.notice.rejected', { name: merged.rejected[0].name, reason: merged.rejected[0].reason }));
|
|
709
|
+
}
|
|
710
|
+
setHistoryIndex(null);
|
|
711
|
+
inputRef.current?.focus();
|
|
712
|
+
} finally {
|
|
713
|
+
setTakingBack(null);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/* Cmd+S puts the draft away and clears the box; on an empty box the same key takes the last one back. */
|
|
718
|
+
const toggleStash = (): void => {
|
|
719
|
+
if (isEmptyDraft(draft)) {
|
|
720
|
+
const newest = useStash.getState().prompts[0];
|
|
721
|
+
if (newest) {
|
|
722
|
+
restoreStashed(newest);
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if (stashDraft(draft)) {
|
|
727
|
+
clearDraft();
|
|
728
|
+
setMention(null);
|
|
729
|
+
setSkillQuery(null);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const recall = (direction: -1 | 1): boolean => {
|
|
734
|
+
if (history.length === 0) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const next = historyIndex === null ? (direction === -1 ? history.length - 1 : null) : historyIndex + direction;
|
|
738
|
+
if (next === null || next >= history.length) {
|
|
739
|
+
setHistoryIndex(null);
|
|
740
|
+
setText('', [], []);
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
if (next < 0) {
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
setHistoryIndex(next);
|
|
747
|
+
setText(history[next]!.text, history[next]!.mentions);
|
|
748
|
+
return true;
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
/* Runs before the editor's own keymap; true means the key is handled and its default prevented. */
|
|
752
|
+
const onKeyDown = (e: KeyboardEvent, view: EditorView): boolean => {
|
|
753
|
+
// Shift with the paste shortcut pastes a large text inline after all; any other key forgets it.
|
|
754
|
+
pasteInlineRef.current = e.shiftKey && e.key.toLowerCase() === 'v' && (isApplePlatform() ? e.metaKey : e.ctrlKey);
|
|
755
|
+
// Escape leaves the node, unless it first has a recalled prompt to put back.
|
|
756
|
+
if (e.key === 'Escape' && !e.isComposing) {
|
|
757
|
+
if (historyIndex === null) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
e.stopPropagation();
|
|
761
|
+
setHistoryIndex(null);
|
|
762
|
+
setText('', [], []);
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
// The composer keeps the keyboard while you type, but the shortcuts that move between views,
|
|
766
|
+
// panels and the palette stay the app's, untouched: Mod+Shift+Enter would otherwise send as well.
|
|
767
|
+
if (chatHost().isAppShortcut(e)) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
e.stopPropagation();
|
|
771
|
+
// A key inside an IME composition belongs to the composition, Enter and the arrows included.
|
|
772
|
+
if (e.isComposing) {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
// Reading back through a long answer should not mean leaving the box you are typing in.
|
|
776
|
+
if (e.key === 'PageUp' || e.key === 'PageDown') {
|
|
777
|
+
return pageTimeline(chatId, e.key === 'PageUp' ? -1 : 1);
|
|
778
|
+
}
|
|
779
|
+
if (matchesShortcut(STASH_SHORTCUT, e, isApplePlatform())) {
|
|
780
|
+
toggleStash();
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
if (commandMenuOpen) {
|
|
784
|
+
if (e.key === 'ArrowDown') {
|
|
785
|
+
setMenuIndex((i) => (i + 1) % commands.length);
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
if (e.key === 'ArrowUp') {
|
|
789
|
+
setMenuIndex((i) => (i - 1 + commands.length) % commands.length);
|
|
790
|
+
return true;
|
|
791
|
+
}
|
|
792
|
+
if (e.key === 'Tab') {
|
|
793
|
+
const chosen = commands[menuIndex]!;
|
|
794
|
+
if (chosen.skill) {
|
|
795
|
+
chooseSkill(chosen.name);
|
|
796
|
+
} else {
|
|
797
|
+
setText(`/${chosen.name} `);
|
|
798
|
+
}
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (skillMenuOpen) {
|
|
803
|
+
if (e.key === 'ArrowDown') {
|
|
804
|
+
setMenuIndex((i) => (i + 1) % skillMatches.length);
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
if (e.key === 'ArrowUp') {
|
|
808
|
+
setMenuIndex((i) => (i - 1 + skillMatches.length) % skillMatches.length);
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
if (e.key === 'Tab' || e.key === 'Enter') {
|
|
812
|
+
chooseSkill((skillMatches[menuIndex] ?? skillMatches[0]!).name);
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (mentionMenuOpen && mentionCount > 0) {
|
|
817
|
+
if (e.key === 'ArrowDown') {
|
|
818
|
+
setMenuIndex((i) => (i + 1) % mentionCount);
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
if (e.key === 'ArrowUp') {
|
|
822
|
+
setMenuIndex((i) => (i - 1 + mentionCount) % mentionCount);
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
if (e.key === 'Tab' || e.key === 'Enter') {
|
|
826
|
+
chooseMentionAt(menuIndex);
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
// In a fence Tab indents like a code editor; anywhere else it keeps moving the focus.
|
|
831
|
+
if (e.key === 'Tab' && !e.altKey && !e.metaKey && !e.ctrlKey) {
|
|
832
|
+
const { state } = view;
|
|
833
|
+
const { from, to, head } = state.selection.main;
|
|
834
|
+
const tree = ensureSyntaxTree(state, state.doc.length, 50) ?? syntaxTree(state);
|
|
835
|
+
if (inFenceBody(tree, state.doc.toString(), head)) {
|
|
836
|
+
// Handled even when there is nothing to outdent, so Shift+Tab never throws the focus out of a block.
|
|
837
|
+
if (e.shiftKey) {
|
|
838
|
+
indentLess(view);
|
|
839
|
+
} else if (from !== to) {
|
|
840
|
+
indentMore(view);
|
|
841
|
+
} else {
|
|
842
|
+
view.dispatch(state.replaceSelection(tabSpaces(head - state.doc.lineAt(head).from)), { scrollIntoView: true, userEvent: 'input' });
|
|
843
|
+
}
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (e.key === 'Enter') {
|
|
848
|
+
const { state } = view;
|
|
849
|
+
const { from, to, head } = state.selection.main;
|
|
850
|
+
// Parsed to the end, since the fence that closes the block can sit after the caret.
|
|
851
|
+
const tree = ensureSyntaxTree(state, state.doc.length, 50) ?? syntaxTree(state);
|
|
852
|
+
const line = state.doc.lineAt(head);
|
|
853
|
+
const list = from === to && !inCode(tree, state.doc.toString(), head) ? listItemAt(line.text) : null;
|
|
854
|
+
const action = enterAction(
|
|
855
|
+
{ shift: e.shiftKey, mod: isModHeld(e, isApplePlatform()) },
|
|
856
|
+
{ inOpenFence: inOpenFence(tree, head), list, column: head - line.from }
|
|
857
|
+
);
|
|
858
|
+
if (action === 'newline') {
|
|
859
|
+
return insertNewline(view);
|
|
860
|
+
}
|
|
861
|
+
if (action === 'continue-list' && list) {
|
|
862
|
+
view.dispatch({
|
|
863
|
+
changes: { from: head, insert: `\n${list.next}` },
|
|
864
|
+
selection: { anchor: head + 1 + list.next.length },
|
|
865
|
+
scrollIntoView: true,
|
|
866
|
+
userEvent: 'input'
|
|
867
|
+
});
|
|
868
|
+
return true;
|
|
869
|
+
}
|
|
870
|
+
if (action === 'leave-list') {
|
|
871
|
+
view.dispatch({ changes: { from: line.from, to: line.to }, selection: { anchor: line.from }, userEvent: 'delete' });
|
|
872
|
+
return true;
|
|
873
|
+
}
|
|
874
|
+
submit();
|
|
875
|
+
return true;
|
|
876
|
+
}
|
|
877
|
+
const { from, to } = view.state.selection.main;
|
|
878
|
+
const recalled = historyIndex !== null && text === history[historyIndex]?.text;
|
|
879
|
+
const direction = recallDirection({ key: e.key, text, from, to, recalled });
|
|
880
|
+
return direction !== null && recall(direction);
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
/* Files become attachments and a long text a file of its own; anything else the editor pastes as plain text. */
|
|
884
|
+
const onPaste = (e: ClipboardEvent, view: EditorView): boolean => {
|
|
885
|
+
const data = e.clipboardData;
|
|
886
|
+
if (!data) {
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
const pasted = filesOf(data);
|
|
890
|
+
if (pasted.length > 0) {
|
|
891
|
+
addFiles(pasted);
|
|
892
|
+
return true;
|
|
893
|
+
}
|
|
894
|
+
const inline = pasteInlineRef.current;
|
|
895
|
+
pasteInlineRef.current = false;
|
|
896
|
+
const clip = data.getData('text/plain');
|
|
897
|
+
const mentions = capabilities?.mentions === false ? [] : pastedMentions(clip);
|
|
898
|
+
if (mentions.length > 0) {
|
|
899
|
+
// The editor's own change reads the draft as it was rendered, so the mentions join it after that change.
|
|
900
|
+
view.dispatch(view.state.replaceSelection(clip), { scrollIntoView: true, userEvent: 'input.paste' });
|
|
901
|
+
setDraft((current) => ({ ...current, mentions: [...current.mentions, ...mentions.filter((path) => !current.mentions.includes(path))] }));
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
// Without attachments there is nowhere else for the text to go, so it pastes as it always did.
|
|
905
|
+
if (inline || capabilities?.attachments === false || !pasteBecomesAttachment(clip)) {
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
// The paste still replaces what was selected; it just puts nothing in its place.
|
|
909
|
+
const { from, to } = view.state.selection.main;
|
|
910
|
+
if (from !== to) {
|
|
911
|
+
view.dispatch({ changes: { from, to }, userEvent: 'delete' });
|
|
912
|
+
}
|
|
913
|
+
const name = pastedTextName(draft.attachments.map((attachment) => attachment.name));
|
|
914
|
+
addFiles([new File([clip], name, { type: 'text/plain' })]);
|
|
915
|
+
return true;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
/* The timeline owns the scroller; this is the one bit of it the composer needs to know. */
|
|
919
|
+
const atEnd = useSyncExternalStore(
|
|
920
|
+
subscribeTimelineEnd,
|
|
921
|
+
() => timelineAtEnd(chatId),
|
|
922
|
+
() => true
|
|
923
|
+
);
|
|
924
|
+
|
|
925
|
+
const mentionable = capabilities?.mentions !== false;
|
|
926
|
+
const hasSkills = skills.length > 0;
|
|
927
|
+
const placeholder = useMemo(() => {
|
|
928
|
+
if (disabled) {
|
|
929
|
+
return t('composer.placeholder.disconnected');
|
|
930
|
+
}
|
|
931
|
+
if (readOnly) {
|
|
932
|
+
return t('composer.placeholder.readOnly');
|
|
933
|
+
}
|
|
934
|
+
return hintedPlaceholder(placeholderLead ?? t('composer.placeholder.lead'), t('composer.placeholder.joiner'), [
|
|
935
|
+
{ key: '/', label: t('composer.placeholder.commands') },
|
|
936
|
+
...(mentionable ? [{ key: '@', label: t('composer.placeholder.files') }] : []),
|
|
937
|
+
...(hasSkills ? [{ key: '$', label: t('composer.placeholder.skills') }] : [])
|
|
938
|
+
]);
|
|
939
|
+
}, [disabled, readOnly, placeholderLead, mentionable, hasSkills, t]);
|
|
940
|
+
const attachable = capabilities?.attachments !== false;
|
|
941
|
+
const Slot = chatHost().ComposerSlot;
|
|
942
|
+
|
|
943
|
+
return (
|
|
944
|
+
<div className="chat-composer-content pointer-events-none relative z-10 w-full">
|
|
945
|
+
{/* Only while there is something below the fold. It sits over the composer rather than
|
|
946
|
+
in the thread, because the composer is the one thing whose height it always clears. */}
|
|
947
|
+
{/* A read-only composer sits under something that stands in the thread's place, whose end is not this one. */}
|
|
948
|
+
{!atEnd && !readOnly && (
|
|
949
|
+
<div className="absolute inset-x-0 bottom-full mb-2 flex justify-center">
|
|
950
|
+
<Tooltip label={t('composer.jumpToEnd')} name>
|
|
951
|
+
<Surface
|
|
952
|
+
render={<button onClick={() => scrollTimelineToEnd(chatId)} />}
|
|
953
|
+
className="pointer-events-auto grid h-8 w-8 place-items-center rounded-full text-text-muted hover:text-text"
|
|
954
|
+
>
|
|
955
|
+
<Icon icon={ChevronDown} size={16} />
|
|
956
|
+
</Surface>
|
|
957
|
+
</Tooltip>
|
|
958
|
+
</div>
|
|
959
|
+
)}
|
|
960
|
+
<ChatActivity chatId={chatId} />
|
|
961
|
+
<div
|
|
962
|
+
className={clsx(
|
|
963
|
+
'@container/composer pointer-events-auto flex flex-col overflow-hidden rounded-2xl border shadow-float backdrop-blur-[14px] focus-ring-within',
|
|
964
|
+
dragging
|
|
965
|
+
? 'border-accent bg-[color-mix(in_srgb,var(--accent-soft)_60%,var(--surface-raised))]'
|
|
966
|
+
: 'border-border bg-[color-mix(in_srgb,var(--surface-raised)_92%,transparent)]'
|
|
967
|
+
)}
|
|
968
|
+
/* The whole card takes a dropped file as a mention, so a layout around it that takes drops
|
|
969
|
+
of its own leaves it alone. */
|
|
970
|
+
data-takes-drop="all"
|
|
971
|
+
onDragOver={(e) => {
|
|
972
|
+
if (writable && (e.dataTransfer.types.includes('Files') || carriesMentions(e.dataTransfer.types))) {
|
|
973
|
+
e.preventDefault();
|
|
974
|
+
e.stopPropagation();
|
|
975
|
+
setDragging(true);
|
|
976
|
+
}
|
|
977
|
+
}}
|
|
978
|
+
onDragLeave={(e) => {
|
|
979
|
+
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
|
|
980
|
+
setDragging(false);
|
|
981
|
+
}
|
|
982
|
+
}}
|
|
983
|
+
onDrop={(e) => {
|
|
984
|
+
e.preventDefault();
|
|
985
|
+
e.stopPropagation();
|
|
986
|
+
setDragging(false);
|
|
987
|
+
addMentions(droppedMentions(e.dataTransfer));
|
|
988
|
+
addFiles(filesOf(e.dataTransfer));
|
|
989
|
+
inputRef.current?.focus();
|
|
990
|
+
}}
|
|
991
|
+
>
|
|
992
|
+
<PromptComposer
|
|
993
|
+
chatId={chatId}
|
|
994
|
+
pending={pending}
|
|
995
|
+
focused={focused}
|
|
996
|
+
onShowElsewhere={answerPromptsElsewhere}
|
|
997
|
+
disabled={disabled}
|
|
998
|
+
hasDraft={!isEmptyDraft(draft)}
|
|
999
|
+
denyReason={capabilities?.denyReason === true}
|
|
1000
|
+
onAllAnswered={() => inputRef.current?.focus()}
|
|
1001
|
+
>
|
|
1002
|
+
<LimitDock chatId={chatId} info={info} />
|
|
1003
|
+
{compactionOffer && (
|
|
1004
|
+
<ResumeCompactionDock
|
|
1005
|
+
tokens={compactionOffer.tokens}
|
|
1006
|
+
onCompact={compact}
|
|
1007
|
+
onDismiss={() => dismissResumeCompaction(scope, chatId, compactionOffer.turnId)}
|
|
1008
|
+
/>
|
|
1009
|
+
)}
|
|
1010
|
+
{commandMenuOpen && (
|
|
1011
|
+
<div className="border-b border-border px-1.5 py-1.5">
|
|
1012
|
+
{commands.map((command, index) => (
|
|
1013
|
+
<button
|
|
1014
|
+
key={command.name}
|
|
1015
|
+
data-active={index === menuIndex}
|
|
1016
|
+
className="cursor-row flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-xs text-text-muted"
|
|
1017
|
+
onMouseEnter={() => setMenuIndex(index)}
|
|
1018
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
1019
|
+
onClick={() => {
|
|
1020
|
+
setMenuIndex(index);
|
|
1021
|
+
if (command.skill) {
|
|
1022
|
+
chooseSkill(command.name);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
setText(`/${command.name}`);
|
|
1026
|
+
inputRef.current?.focus();
|
|
1027
|
+
}}
|
|
1028
|
+
>
|
|
1029
|
+
<Icon
|
|
1030
|
+
icon={command.skill ? Zap : SquareSlash}
|
|
1031
|
+
size={12}
|
|
1032
|
+
className={clsx('shrink-0', command.skill ? 'text-skill' : 'text-text-faint')}
|
|
1033
|
+
/>
|
|
1034
|
+
<span className="font-mono text-text">/{command.name}</span>
|
|
1035
|
+
<span className="text-text-faint">{command.hint}</span>
|
|
1036
|
+
</button>
|
|
1037
|
+
))}
|
|
1038
|
+
</div>
|
|
1039
|
+
)}
|
|
1040
|
+
{skillMenuOpen && (
|
|
1041
|
+
<div className="border-b border-border px-1.5 py-1.5">
|
|
1042
|
+
{skillMatches.map((skill, index) => (
|
|
1043
|
+
<button
|
|
1044
|
+
key={skill.name}
|
|
1045
|
+
data-active={index === menuIndex}
|
|
1046
|
+
className="cursor-row flex w-full items-start gap-2 rounded-md px-2 py-1 text-left text-xs text-text-muted"
|
|
1047
|
+
onMouseEnter={() => setMenuIndex(index)}
|
|
1048
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
1049
|
+
onClick={() => chooseSkill(skill.name)}
|
|
1050
|
+
>
|
|
1051
|
+
<Icon icon={Zap} size={12} className="mt-0.5 shrink-0 text-skill" />
|
|
1052
|
+
<span className="flex min-w-0 flex-col">
|
|
1053
|
+
<span className="truncate font-mono text-text">${skill.name}</span>
|
|
1054
|
+
{skill.description !== '' && <span className="line-clamp-1 text-text-faint">{skill.description}</span>}
|
|
1055
|
+
</span>
|
|
1056
|
+
</button>
|
|
1057
|
+
))}
|
|
1058
|
+
</div>
|
|
1059
|
+
)}
|
|
1060
|
+
{mentionMenuOpen && (
|
|
1061
|
+
<div className="border-b border-border px-1.5 py-1.5">
|
|
1062
|
+
{chatMatches.length > 0 && <Menu.Label>{t('composer.mentions.chats')}</Menu.Label>}
|
|
1063
|
+
{chatMatches.map((chat, index) => (
|
|
1064
|
+
<button
|
|
1065
|
+
key={chat.id}
|
|
1066
|
+
data-active={index === menuIndex}
|
|
1067
|
+
className="cursor-row flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-xs text-text-muted"
|
|
1068
|
+
onMouseEnter={() => setMenuIndex(index)}
|
|
1069
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
1070
|
+
onClick={() => chooseChat(chat.id)}
|
|
1071
|
+
>
|
|
1072
|
+
<Icon icon={MessageSquare} size={14} className="shrink-0 text-text-faint" />
|
|
1073
|
+
<span className="truncate text-text">{chat.title || t('chatReference.untitled')}</span>
|
|
1074
|
+
</button>
|
|
1075
|
+
))}
|
|
1076
|
+
{files.length > 0 && (mention.query === '' || chatMatches.length > 0) && (
|
|
1077
|
+
<Menu.Label>{mention.query === '' ? t('composer.mentions.here') : t('composer.mentions.files')}</Menu.Label>
|
|
1078
|
+
)}
|
|
1079
|
+
{mentionCount === 0 && (
|
|
1080
|
+
<div className="px-2 py-1 text-xs text-text-faint">
|
|
1081
|
+
{mention.query ? t('composer.mentions.noMatch') : t('composer.mentions.empty')}
|
|
1082
|
+
</div>
|
|
1083
|
+
)}
|
|
1084
|
+
{files.map((path, index) => {
|
|
1085
|
+
const { name, dir } = splitPath(path);
|
|
1086
|
+
return (
|
|
1087
|
+
<button
|
|
1088
|
+
key={path}
|
|
1089
|
+
data-active={chatMatches.length + index === menuIndex}
|
|
1090
|
+
className="cursor-row flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-xs text-text-muted"
|
|
1091
|
+
onMouseEnter={() => setMenuIndex(chatMatches.length + index)}
|
|
1092
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
1093
|
+
onClick={() => chooseMention(path)}
|
|
1094
|
+
>
|
|
1095
|
+
<FileIcon path={path} size={14} />
|
|
1096
|
+
<span className="truncate font-mono text-text">{name}</span>
|
|
1097
|
+
{dir && <span className="min-w-0 truncate text-text-faint">{dir}</span>}
|
|
1098
|
+
</button>
|
|
1099
|
+
);
|
|
1100
|
+
})}
|
|
1101
|
+
</div>
|
|
1102
|
+
)}
|
|
1103
|
+
{queue.length > 0 && (
|
|
1104
|
+
<div className="flex flex-col gap-1 border-b border-border px-2 py-1.5">
|
|
1105
|
+
{info.queuePaused === true && <p className="px-1.5 text-xs text-text-muted">{t('composer.queue.paused')}</p>}
|
|
1106
|
+
{queue.map((message) => {
|
|
1107
|
+
const sendNow = (): void => {
|
|
1108
|
+
scrollTimelineToEnd(chatId, 'instant');
|
|
1109
|
+
void actions.sendNow(chatId, message.id).catch(() => undefined);
|
|
1110
|
+
};
|
|
1111
|
+
const unqueue = (): void => void actions.unqueue(chatId, message.id).catch(() => undefined);
|
|
1112
|
+
const edit = (): void => void takeBack(message);
|
|
1113
|
+
return (
|
|
1114
|
+
<ContextMenu.Root key={message.id}>
|
|
1115
|
+
<ContextMenu.Trigger className="group/queued flex items-center gap-2 rounded-md px-1.5 py-1 text-xs text-text-muted">
|
|
1116
|
+
<Icon icon={Clock} size={12} className="shrink-0 text-text-faint" />
|
|
1117
|
+
<span className="min-w-0 grow truncate">
|
|
1118
|
+
{message.text || t('composer.queue.attachments', { count: message.attachments?.length ?? 0 })}
|
|
1119
|
+
</span>
|
|
1120
|
+
<ButtonGroup
|
|
1121
|
+
render={<span />}
|
|
1122
|
+
className="opacity-0 transition-opacity group-hover/queued:opacity-100 focus-within:opacity-100"
|
|
1123
|
+
>
|
|
1124
|
+
<IconButton icon={FastForward} size="2xs" label={t('composer.queue.sendNow')} onClick={sendNow} />
|
|
1125
|
+
<IconButton
|
|
1126
|
+
icon={Pencil}
|
|
1127
|
+
size="2xs"
|
|
1128
|
+
label={t('common.action.edit')}
|
|
1129
|
+
disabled={takingBack !== null}
|
|
1130
|
+
onClick={edit}
|
|
1131
|
+
/>
|
|
1132
|
+
<IconButton icon={X} size="2xs" label={t('common.action.remove')} onClick={unqueue} />
|
|
1133
|
+
</ButtonGroup>
|
|
1134
|
+
</ContextMenu.Trigger>
|
|
1135
|
+
<ContextMenu.Popup>
|
|
1136
|
+
<ContextMenu.Item onClick={sendNow}>
|
|
1137
|
+
<Icon icon={FastForward} size={14} /> {t('composer.queue.sendNow')}
|
|
1138
|
+
</ContextMenu.Item>
|
|
1139
|
+
<ContextMenu.Item disabled={takingBack !== null} onClick={edit}>
|
|
1140
|
+
<Icon icon={Pencil} size={14} /> {t('common.action.edit')}
|
|
1141
|
+
</ContextMenu.Item>
|
|
1142
|
+
<ContextMenu.Item disabled={message.text === ''} onClick={() => copyText(message.text)}>
|
|
1143
|
+
<Icon icon={Copy} size={14} /> {t('common.action.copy')}
|
|
1144
|
+
</ContextMenu.Item>
|
|
1145
|
+
<ContextMenu.Separator />
|
|
1146
|
+
<ContextMenu.Item className="text-status-error" onClick={unqueue}>
|
|
1147
|
+
<Icon icon={X} size={14} /> {t('common.action.remove')}
|
|
1148
|
+
</ContextMenu.Item>
|
|
1149
|
+
</ContextMenu.Popup>
|
|
1150
|
+
</ContextMenu.Root>
|
|
1151
|
+
);
|
|
1152
|
+
})}
|
|
1153
|
+
</div>
|
|
1154
|
+
)}
|
|
1155
|
+
{quote !== '' && (
|
|
1156
|
+
<div className="flex items-center gap-2 px-5 pt-4 @max-md/composer:px-3.5 @max-md/composer:pt-3">
|
|
1157
|
+
<span className="min-w-0 grow truncate border-l-2 border-border-strong pl-2.5 text-xs text-text-muted">{quote}</span>
|
|
1158
|
+
<IconButton icon={X} size="2xs" label={t('composer.quote.remove')} onClick={removeQuote} />
|
|
1159
|
+
</div>
|
|
1160
|
+
)}
|
|
1161
|
+
{draft.chats.length > 0 && (
|
|
1162
|
+
<div className="flex flex-wrap gap-1.5 px-5 pt-4 @max-md/composer:px-3.5 @max-md/composer:pt-3">
|
|
1163
|
+
{draft.chats.map((id) => (
|
|
1164
|
+
<ChatReferenceChip key={id} chatId={id} onRemove={() => removeChat(id)} />
|
|
1165
|
+
))}
|
|
1166
|
+
</div>
|
|
1167
|
+
)}
|
|
1168
|
+
{draft.attachments.length > 0 && (
|
|
1169
|
+
<div className="flex flex-wrap gap-2 px-5 pt-4 @max-md/composer:px-3.5 @max-md/composer:pt-3">
|
|
1170
|
+
{draft.attachments.map((attachment, index) => (
|
|
1171
|
+
<div key={`${attachment.name}-${index}`} className="group/thumb relative">
|
|
1172
|
+
{isImageAttachment(attachment.mime) ? (
|
|
1173
|
+
<UploadThumb upload={attachment} />
|
|
1174
|
+
) : (
|
|
1175
|
+
<span className="flex h-14 w-36 flex-col justify-center gap-0.5 rounded-lg border border-border bg-surface-sunken px-2.5">
|
|
1176
|
+
<span className="flex items-center gap-1.5 text-xs text-text">
|
|
1177
|
+
<Icon icon={Paperclip} size={12} className="shrink-0 text-text-faint" />
|
|
1178
|
+
<span className="truncate">{attachment.name}</span>
|
|
1179
|
+
</span>
|
|
1180
|
+
<span className="pl-5 text-xs text-text-faint">{formatBytes(uploadBytes(attachment))}</span>
|
|
1181
|
+
</span>
|
|
1182
|
+
)}
|
|
1183
|
+
<IconButton
|
|
1184
|
+
icon={X}
|
|
1185
|
+
size="2xs"
|
|
1186
|
+
label={t('composer.removeAttachment', { name: attachment.name })}
|
|
1187
|
+
className="absolute -top-1.5 -right-1.5 border border-border bg-surface-raised opacity-0 transition-opacity group-hover/thumb:opacity-100 focus-visible:opacity-100"
|
|
1188
|
+
onClick={() => removeAttachment(index)}
|
|
1189
|
+
/>
|
|
1190
|
+
</div>
|
|
1191
|
+
))}
|
|
1192
|
+
</div>
|
|
1193
|
+
)}
|
|
1194
|
+
<ComposerInput
|
|
1195
|
+
ref={inputRef}
|
|
1196
|
+
dictationToolbar={dictationToolbar}
|
|
1197
|
+
className="composer-input select-text text-sm leading-normal text-text"
|
|
1198
|
+
value={text}
|
|
1199
|
+
placeholder={placeholder}
|
|
1200
|
+
disabled={!writable}
|
|
1201
|
+
tabbable={focused}
|
|
1202
|
+
extensions={editorExtensions}
|
|
1203
|
+
onChange={(value, selection, state) => {
|
|
1204
|
+
setText(value);
|
|
1205
|
+
setMenuIndex(0);
|
|
1206
|
+
trackTriggers(value, selection, state);
|
|
1207
|
+
if (historyIndex !== null && value !== history[historyIndex]?.text) {
|
|
1208
|
+
setHistoryIndex(null);
|
|
1209
|
+
}
|
|
1210
|
+
}}
|
|
1211
|
+
onSelectionChange={trackTriggers}
|
|
1212
|
+
onBlur={() => {
|
|
1213
|
+
setMention(null);
|
|
1214
|
+
setSkillQuery(null);
|
|
1215
|
+
}}
|
|
1216
|
+
onKeyDown={onKeyDown}
|
|
1217
|
+
onPaste={onPaste}
|
|
1218
|
+
/>
|
|
1219
|
+
{notice && (
|
|
1220
|
+
<div className="px-5 pb-1 text-xs text-status-error @max-md/composer:px-3.5" role="alert">
|
|
1221
|
+
{notice}
|
|
1222
|
+
</div>
|
|
1223
|
+
)}
|
|
1224
|
+
{guard.visible && (
|
|
1225
|
+
<div
|
|
1226
|
+
className={clsx(
|
|
1227
|
+
'px-5 pb-1 text-right text-xs tabular-nums @max-md/composer:px-3.5',
|
|
1228
|
+
guard.tooLong ? 'text-status-error' : 'text-text-faint'
|
|
1229
|
+
)}
|
|
1230
|
+
>
|
|
1231
|
+
{formatNumber(guard.count)} / {formatNumber(PROMPT_MAX_CHARS)}
|
|
1232
|
+
{guard.tooLong && ` ${t('composer.tooLong')}`}
|
|
1233
|
+
</div>
|
|
1234
|
+
)}
|
|
1235
|
+
{/* The composer's controls are round, from attach to send, so they keep their own shape instead of `.icon-btn`'s. */}
|
|
1236
|
+
<div className="flex items-center gap-2 pt-3 pr-3.5 pb-3.5 pl-5 @max-md/composer:gap-1.5 @max-md/composer:p-3 @max-md/composer:pt-2.5">
|
|
1237
|
+
{attachable && (
|
|
1238
|
+
<Tooltip label={t('composer.attach')} name>
|
|
1239
|
+
<button
|
|
1240
|
+
type="button"
|
|
1241
|
+
className="grid h-8 w-8 shrink-0 place-items-center rounded-full border border-border text-text-muted hover:bg-surface-hover hover:text-text disabled:opacity-50"
|
|
1242
|
+
disabled={!writable}
|
|
1243
|
+
onClick={() => fileInputRef.current?.click()}
|
|
1244
|
+
>
|
|
1245
|
+
<Icon icon={Plus} size={16} />
|
|
1246
|
+
</button>
|
|
1247
|
+
</Tooltip>
|
|
1248
|
+
)}
|
|
1249
|
+
<input
|
|
1250
|
+
ref={fileInputRef}
|
|
1251
|
+
type="file"
|
|
1252
|
+
multiple
|
|
1253
|
+
hidden
|
|
1254
|
+
onChange={(e) => {
|
|
1255
|
+
addFiles(Array.from(e.target.files ?? []));
|
|
1256
|
+
e.target.value = '';
|
|
1257
|
+
inputRef.current?.focus();
|
|
1258
|
+
}}
|
|
1259
|
+
/>
|
|
1260
|
+
<RunSettings
|
|
1261
|
+
disabled={configurationPending || !writable}
|
|
1262
|
+
providers={pickable}
|
|
1263
|
+
provider={info.provider}
|
|
1264
|
+
selection={info.selection}
|
|
1265
|
+
model={model}
|
|
1266
|
+
runtimeMode={info.runtimeMode}
|
|
1267
|
+
effectiveRuntimeMode={info.effectiveRuntimeMode}
|
|
1268
|
+
permissionMode={info.permissionMode}
|
|
1269
|
+
open={modelPickerOpen}
|
|
1270
|
+
onOpenChange={setModelPickerOpen}
|
|
1271
|
+
onModel={chooseModel}
|
|
1272
|
+
onOption={(id, value) => configure({ selection: { ...info.selection, options: { ...info.selection.options, [id]: value } } })}
|
|
1273
|
+
onMode={(runtimeMode) => configure({ runtimeMode })}
|
|
1274
|
+
usage={info.usage}
|
|
1275
|
+
compactDisabled={busy || !writable}
|
|
1276
|
+
onCompact={compact}
|
|
1277
|
+
account={accountChoice === null ? null : { choice: accountChoice, started, onPick: chooseAccount }}
|
|
1278
|
+
/>
|
|
1279
|
+
<StashPicker onRestore={restoreStashed} />
|
|
1280
|
+
{Slot !== null && (
|
|
1281
|
+
<ErrorBoundary label={t('composer.slotFailed')} resetKeys={[chatId]} compact className="relative rounded-lg">
|
|
1282
|
+
<Slot scopeId={scope.id} chatId={chatId} disabled={!writable} insert={insertIntoDraft} />
|
|
1283
|
+
</ErrorBoundary>
|
|
1284
|
+
)}
|
|
1285
|
+
<span className="grow" />
|
|
1286
|
+
<div className="flex h-9 shrink-0 items-center gap-0.5 rounded-full bg-surface-hover">
|
|
1287
|
+
<div ref={setDictationToolbar} className="flex items-center pl-1 empty:hidden [&_.icon-btn]:rounded-full" />
|
|
1288
|
+
{busy && (
|
|
1289
|
+
<Tooltip label={composerStopLabel()} name>
|
|
1290
|
+
<button
|
|
1291
|
+
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-status-error text-accent-text"
|
|
1292
|
+
onClick={(event) => stop(event.shiftKey)}
|
|
1293
|
+
>
|
|
1294
|
+
<Icon icon={Square} size={16} />
|
|
1295
|
+
</button>
|
|
1296
|
+
</Tooltip>
|
|
1297
|
+
)}
|
|
1298
|
+
{/* While a turn runs the same button queues the message instead of sending it. */}
|
|
1299
|
+
{(!busy || !isEmptyDraft(draft)) && (
|
|
1300
|
+
<Tooltip label={busy ? t('composer.queueButton') : t('composer.send')} kbd={KEY_SHORTCUTS.modEnter} name>
|
|
1301
|
+
<button
|
|
1302
|
+
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent text-accent-text hover:brightness-90 disabled:opacity-50 disabled:hover:brightness-100"
|
|
1303
|
+
disabled={isEmptyDraft(draft) || !writable || guard.tooLong}
|
|
1304
|
+
onClick={submit}
|
|
1305
|
+
>
|
|
1306
|
+
<Icon icon={ArrowUp} size={16} />
|
|
1307
|
+
</button>
|
|
1308
|
+
</Tooltip>
|
|
1309
|
+
)}
|
|
1310
|
+
</div>
|
|
1311
|
+
</div>
|
|
1312
|
+
</PromptComposer>
|
|
1313
|
+
</div>
|
|
1314
|
+
<PromptDialog
|
|
1315
|
+
open={confirmClear}
|
|
1316
|
+
title={t('composer.clear.title')}
|
|
1317
|
+
description={t('composer.clear.description')}
|
|
1318
|
+
confirmLabel={t('composer.clear.confirm')}
|
|
1319
|
+
danger
|
|
1320
|
+
fallbackMessage={t('composer.notice.clearFailed')}
|
|
1321
|
+
onConfirm={forceClearThread}
|
|
1322
|
+
onOpenChange={() => setConfirmClear(false)}
|
|
1323
|
+
/>
|
|
1324
|
+
</div>
|
|
1325
|
+
);
|
|
1326
|
+
}
|