Skip to content

feat(PromptInput): add application commands and context selections - #277

Merged
ananas7 merged 4 commits into
mainfrom
feature/prompt-commands
Oct 22, 2026
Merged

ananas7 merged 4 commits into
mainfrom
feature/prompt-commands

Conversation

@ananas7

@ananas7 ananas7 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  • Add / and @ suggestions with static or asynchronous sources, keyboard navigation, selection chips, and controlled or uncontrolled state in both prompt layouts.
  • Reset uncontrolled selections on conversation changes and active-chat deletion independently of autofocus. Preserve the draft on canceled or failed sends, and keep failed HTTP attempts and technical errors out of model history when resending.
  • Add complete Storybook examples with asynchronous document search, commands, request inspection, and failure/cancellation scenarios, plus API documentation and regression coverage.

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.

@gravity-ui

gravity-ui Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Prerelease version published!

Install this PR version:

npm i --save-dev @gravity-ui/aikit@2.24.1-beta.26b750955cb185283d5522394b1644c4b57eede6.0

@gravity-ui-bot

Copy link
Copy Markdown

Preview is ready.

@gravity-ui

gravity-ui Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

🎭 Component Tests Report is ready.

@ananas7
ananas7 marked this pull request as ready for review October 20, 2026 14:13
setSending(true);
setSendError(false);
try {
const result = await onSend(submitData);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ananas7
ananas7 added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit dc840b4 Oct 22, 2026
9 checks passed
@ananas7
ananas7 deleted the feature/prompt-commands branch October 22, 2026 08:28
@gravity-ui gravity-ui Bot mentioned this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants