Repository navigation
feat(PromptInput): add application commands and context selections - #277
Conversation
|
🚀 Prerelease version published! Install this PR version: npm i --save-dev @gravity-ui/aikit@2.24.1-beta.26b750955cb185283d5522394b1644c4b57eede6.0 |
|
Preview is ready. |
|
🎭 Component Tests Report is ready. |
| setSending(true); | ||
| setSendError(false); | ||
| try { | ||
| const result = await onSend(submitData); |
There was a problem hiding this comment.
issue: The draft is now cleared only after onSend resolves, so when onSendMessage awaits the whole stream (as in FullStreamingExample), the sent text stays in the input until the answer ends and new typing is appended to it. Could we clear it right after the call, as before, and restore it only on false or a rejection?
There was a problem hiding this comment.
Fixed. Text, attachments, and command selections now clear immediately when submission starts, without waiting for the stream to finish. On false or rejection, the snapshot is restored only if the draft and conversation are unchanged. Added regression tests for pending streams, restoration, and preserving newer edits.
| }, [controller]); | ||
|
|
||
| const handleRetry = useCallback(async () => { | ||
| if (failedAttempt) { |
There was a problem hiding this comment.
issue: After a failed send the draft, selections and files stay in the prompt, and a successful Retry doesn't clear them, so the next Enter sends the same message a second time. Retry should clear the prompt like a successful send does, or the draft shouldn't be kept when Retry is offered.
There was a problem hiding this comment.
Fixed. A successful Retry now clears the retained draft, command selections, and file context through the prompt lifecycle. Cleanup is guarded so it cannot erase a newer draft or changed attachments. Failed retries preserve the draft, and the original serialized request is still reused.
| const commandsRef = useRef<ReturnType<typeof usePromptCommands> | null>(null); | ||
| const hookState = usePromptInput({ | ||
| onSend, | ||
| onSend: async (data) => { |
There was a problem hiding this comment.
Selected context is only attached in this onSend wrapper, but ChatContainer's welcome suggestions call wrappedOnSendMessage directly. Selecting a document with @ and then clicking a welcome suggestion sends the message without selections, while the selected chip remains visible. Could we route suggestion submissions through the same submission lifecycle so the selected context is included and cleared after a successful send?
There was a problem hiding this comment.
Fixed. Welcome suggestions now use the same submission lifecycle as the prompt's send button. This includes selected context, preserves suggestion metadata, and handles draft cleanup and restoration on failure. Added coverage through ChatContainer and PromptInput.
| }; | ||
|
|
||
| /** Complete application integration with request inspection and failure controls. */ | ||
| export const CommandsAndContext: Story = { |
There was a problem hiding this comment.
Please add Playwright visual tests for CommandsAndContext and CommandsSimple. The project guidelines in docs/guidelines/testing.md require a visual test for each exported story, and neither new story is covered by PromptInput.visual.spec.tsx.
There was a problem hiding this comment.
Added Playwright visual tests for both CommandsAndContext and CommandsSimple, covering the initial state and the open command picker. Portal screenshots capture the full page. Generated four baseline screenshots and verified both tests in the Linux container without updating snapshots.
Applications can now define prompt commands and context sources, let users select them from suggestions, and place their data into the outgoing request through
transformRequest./and@suggestions with static or asynchronous sources, keyboard navigation, selection chips, and controlled or uncontrolled state in both prompt layouts.Validation: all 436 tests passed; type checking, formatting, lint and build passed. Lint reports 11 existing warnings. Storybook interactions were checked manually; the two new Playwright visual tests passed in the Linux container, with four baseline screenshots.
Command integration tests exercise the real ChatContainer and PromptInput: selecting with Enter does not send, submission includes context and clears it, and cancellation/failure preserves the draft. Mutation checks detect missing selection data, missing cleanup, accidental submission, and email parsing regressions.
Production Storybook builds disable Sass charset output to prevent a BOM from corrupting the first injected CSS selector. Verified the original preview issue (checkbox inputs covering the viewport) and the corrected production build (14×14 inputs, working buttons and command menu).
Drafts now clear immediately during streaming and restore only while unchanged on failure. Welcome suggestions share the prompt submission lifecycle, and successful Retry clears only its retained draft and attachments, preserving newer edits.