Skip to content

MGMT-21339: Add chatbot actions#3102

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:chatbot_actions
Aug 7, 2025
Merged

MGMT-21339: Add chatbot actions#3102
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:chatbot_actions

Conversation

@rawagner
Copy link
Member

@rawagner rawagner commented Aug 7, 2025

Adds buttons for download actions

Screenshot From 2025-08-07 12-30-27

Summary by CodeRabbit

  • New Features

    • Added downloadable action buttons to bot messages, enabling direct file downloads from chat.
    • Enhanced chat streaming to support tool-related events for richer, interactive responses.
  • Improvements

    • Standardized message structure for consistent display and handling.
    • Improved feedback handling and message rendering for a smoother user experience.
  • Chores

    • Added a new dependency to support file downloads.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 7, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Aug 7, 2025

@rawagner: This pull request references MGMT-21339 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Adds buttons for download actions

Screenshot From 2025-08-07 12-30-27

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from ElayAharoni and celdrake August 7, 2025 10:34
@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

This update refactors chatbot message handling to standardize message properties using a pfProps object, introduces typed streaming event processing with new event types and type guards, and adds support for tool-generated downloadable actions in bot messages. The UI now displays download buttons for certain tool responses, and a new dependency on file-saver is added.

Changes

Cohort / File(s) Change Summary
Bot Message Download Actions and UI Refactor
libs/chatbot/lib/components/ChatBot/BotMessage.tsx
Refactored to use pfProps for message data, added logic to render download buttons for tool actions using file-saver, and updated UI imports.
Streaming Event Handling, Message Structure, and Tool Actions
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
Standardized message structure with pfProps, refactored streaming event handling to use new type guards and event types, added support for tool argument and response events, removed redundant loading state, and updated send/feedback logic.
Message Type and Tool Action Utilities
libs/chatbot/lib/components/ChatBot/helpers.ts
Updated MsgProps type to wrap message props and actions, adjusted helper functions to use pfProps, and added getToolAction for generating download actions from tool responses.
Streaming Event Types and Type Guards
libs/chatbot/lib/components/ChatBot/types.ts
Introduced new TypeScript types for streaming events and type guard functions for precise event handling.
Dependency Update
libs/chatbot/package.json
Added file-saver as a new runtime dependency for download functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBotWindow
    participant API
    participant BotMessage

    User->>ChatBotWindow: Send message
    ChatBotWindow->>API: POST user message (with model/provider)
    API-->>ChatBotWindow: Stream events (start, token, tool_call, end)
    loop Streaming
        ChatBotWindow->>ChatBotWindow: Process event (type guard)
        alt Token event
            ChatBotWindow->>ChatBotWindow: Append token to bot message content
        else Tool response event
            ChatBotWindow->>ChatBotWindow: Generate download action
            ChatBotWindow->>BotMessage: Pass action(s)
        end
    end
    ChatBotWindow->>BotMessage: Render message with actions
    User->>BotMessage: Click download button
    BotMessage->>file-saver: Trigger file download
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • ammont82
  • jgyselov

Poem

A rabbit hops through lines of code,
Bringing downloads to the chatbot's abode.
With streaming events and buttons anew,
Now bots can offer files to you!
Type guards leap, and helpers cheer—
The code is clear, the features here.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 226c63d and 8b95c39.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (4 hunks)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (8 hunks)
  • libs/chatbot/lib/components/ChatBot/helpers.ts (2 hunks)
  • libs/chatbot/lib/components/ChatBot/types.ts (1 hunks)
  • libs/chatbot/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • libs/chatbot/package.json
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx
  • libs/chatbot/lib/components/ChatBot/types.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.
📚 Learning: in the assisted-installer-ui chatbot feedback implementation, the onfeedbacksubmit callback requires...
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.

Applied to files:

  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
  • libs/chatbot/lib/components/ChatBot/helpers.ts
🪛 Biome (2.1.2)
libs/chatbot/lib/components/ChatBot/helpers.ts

[error] 63-83: This case is falling through to the next case.

Add a break or return statement to the end of this case to prevent fallthrough.

(lint/suspicious/noFallthroughSwitchClause)

🔇 Additional comments (11)
libs/chatbot/lib/components/ChatBot/helpers.ts (3)

4-7: LGTM! Well-structured type refactoring for action support.

The type restructuring to wrap PatternFly props in pfProps and add optional actions array properly supports the download functionality while maintaining type safety.


43-44: LGTM! Correctly adapted to new message structure.

The function properly accesses message properties through the new pfProps wrapper, maintaining consistency with the type refactoring.


95-100: Verify the file_name source is appropriate.

The code uses args?.file_name rather than res.file_name as suggested in a past review. Given that res is typed as { url: string } and args contains tool arguments, using args?.file_name appears correct. Please confirm this is the intended behavior.

libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (8)

38-49: LGTM! Proper imports for enhanced streaming support.

The addition of getToolAction helper and typed streaming event guards improves type safety and supports the new tool integration functionality.


123-131: LGTM! Correctly structured user message creation.

The message creation properly wraps user properties in the pfProps object, aligning with the new standardized message structure.


136-148: LGTM! Consistent bot message structure.

The bot message creation correctly uses the pfProps wrapper, maintaining consistency with the user message structure and new type definition.


177-200: LGTM! Enhanced streaming with type-safe event handling.

The replacement of string-based event type checking with type guard functions improves type safety. The toolArgs dictionary properly tracks tool arguments by event ID for later use in tool response processing.


200-216: LGTM! Properly adapted inference streaming to new structure.

The inference token handling correctly uses the type guard and properly accesses message content through the pfProps structure while maintaining the same streaming logic.


217-238: LGTM! Well-implemented tool integration for download actions.

The tool event handling correctly captures arguments and processes responses to generate downloadable actions. The logic properly maintains the relationship between tool calls and responses using event IDs, and actions are appropriately appended to messages for UI rendering.


276-276: LGTM! Correctly adapted to new message structure.

The feedback submission properly accesses message content through pfProps.content, maintaining consistency with the message structure refactoring.


369-401: LGTM! Proper rendering adaptation to new message structure.

The message rendering correctly uses pfProps.role for role checking and properly spreads pfProps into the Message component. The simplified send button logic appropriately removes dependency on the removed isLoading state.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 7, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Aug 7, 2025

@rawagner: This pull request references MGMT-21339 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Adds buttons for download actions

Screenshot From 2025-08-07 12-30-27

Summary by CodeRabbit

  • New Features

  • Added downloadable action buttons to bot messages, allowing users to download files directly from the chat interface.

  • Enhanced chat streaming to support tool-related events, providing richer and more interactive responses.

  • Improvements

  • Standardized message structure for more consistent display and handling.

  • Improved feedback handling and message rendering for a smoother user experience.

  • Chores

  • Added a new dependency to support file downloads.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (2)
libs/chatbot/package.json (1)

41-41: Add TypeScript type definitions for file-saver

Since this is a TypeScript project, consider adding the type definitions for the file-saver library to improve type safety and IDE support.

Add to devDependencies:

   "devDependencies": {
     "@tsconfig/recommended": "^1.0.2",
+    "@types/file-saver": "^2.0.5",
     "@types/node": "^18.14.6",
     "@types/react": "^18.0.0",
     "@types/react-dom": "^18.3.0"
   },

Also applies to: 44-49

libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (1)

154-155: Consider making model and provider configurable

The model and provider are hardcoded. Consider making these configurable through props or environment variables for flexibility across different deployments.

         body: JSON.stringify({
           query: `${message}`,
           conversation_id: conversationId,
-          model: 'gemini/gemini-2.5-flash',
-          provider: 'gemini',
+          model: process.env.CHATBOT_MODEL || 'gemini/gemini-2.5-flash',
+          provider: process.env.CHATBOT_PROVIDER || 'gemini',
         }),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8500c47 and c9355d5.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (4 hunks)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (8 hunks)
  • libs/chatbot/lib/components/ChatBot/helpers.ts (2 hunks)
  • libs/chatbot/lib/components/ChatBot/types.ts (1 hunks)
  • libs/chatbot/package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.
📚 Learning: in the assisted-installer-ui chatbot feedback implementation, the onfeedbacksubmit callback requires...
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.

Applied to files:

  • libs/chatbot/lib/components/ChatBot/helpers.ts
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx
🪛 Biome (2.1.2)
libs/chatbot/lib/components/ChatBot/helpers.ts

[error] 63-83: This case is falling through to the next case.

Add a break or return statement to the end of this case to prevent fallthrough.

(lint/suspicious/noFallthroughSwitchClause)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: circular-deps
  • GitHub Check: unit-tests
  • GitHub Check: tests
  • GitHub Check: translation-files
  • GitHub Check: format
  • GitHub Check: lint

@openshift-ci-robot
Copy link

openshift-ci-robot commented Aug 7, 2025

@rawagner: This pull request references MGMT-21339 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Adds buttons for download actions

Screenshot From 2025-08-07 12-30-27

Summary by CodeRabbit

  • New Features

  • Added downloadable action buttons to bot messages, enabling direct file downloads from chat.

  • Enhanced chat streaming to support tool-related events for richer, interactive responses.

  • Improvements

  • Standardized message structure for consistent display and handling.

  • Improved feedback handling and message rendering for a smoother user experience.

  • Chores

  • Added a new dependency to support file downloads.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2025
@openshift-ci
Copy link

openshift-ci bot commented Aug 7, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ammont82, rawagner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants