Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wf ai assistant more accurate steps #3615

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Kiryous
Copy link
Contributor

@Kiryous Kiryous commented Feb 20, 2025

Closes #3614

todo

  • separate addStep copilot action by types
  • fix: bug with step adding to react-flow, but not the definition — properly handle condition steps
  • fix: provider selected validation not triggered on generated steps
  • fix: type errors in renderAndWaitForResponse (maybe introduce fullType prop for Zod's discriminated union)

Copy link

vercel bot commented Feb 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
keep ❌ Failed (Inspect) Feb 20, 2025 8:34pm

@Kiryous
Copy link
Contributor Author

Kiryous commented Feb 20, 2025

@coderabbitai review

@Kiryous Kiryous changed the title wip: more accurate steps fix: wf ai assistant more accurate steps Feb 20, 2025
@Kiryous Kiryous self-assigned this Feb 20, 2025
Copy link

coderabbitai bot commented Feb 20, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes to the workflow management system. A new safe node insertion method, addNodeBetweenSafe, replaces the legacy addNodeBetween in tests, UI components, and the workflow store. Method signatures and return types have been updated (e.g., deleteNodes now returns a string array). Additional types are defined in the model, and several UI components are refactored to simplify props and error handling. New helper functions and action handlers have been added in the builder chat, and YAML generation for steps is now centralized.

Changes

File(s) Change Summary
keep-ui/entities/workflows/model/…/__tests__/workflow-store.test.tsx Renamed method usage from addNodeBetween to addNodeBetweenSafe in tests to verify node insertion and error handling.
keep-ui/entities/workflows/model/…/types.ts
keep-ui/entities/workflows/model/…/workflow-store.ts
Added new type definitions (V2StepConditionSchema, V2StepCondition), introduced addNodeBetweenSafe, and updated deleteNodes return type.
keep-ui/features/workflows/builder/ui/BuilderChat/AddStepUI.tsx Refactored props into distinct types and replaced legacy functions with an onAdd handler utilizing the updated store method.
keep-ui/features/workflows/builder/ui/BuilderChat/AddTriggerUI.tsx
keep-ui/features/workflows/builder/ui/WorkflowToolbox.tsx
Changed destructuring to use addNodeBetweenSafe (renamed to addNodeBetween) for safer node additions.
keep-ui/features/workflows/builder/ui/BuilderChat/StepPreview.tsx Introduced getYamlFromStep to centralize YAML generation for different step types.
keep-ui/features/workflows/builder/ui/BuilderChat/builder-chat.tsx Added new action handlers, protected step logic, helper functions for action/step/condition creation, and a skeleton loader for asynchronous operations.
keep-ui/features/workflows/builder/ui/workflow-status.tsx Replaced <div> with <span> for rendering validation error messages.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant AddStepUI
  participant WorkflowStore
  participant ErrorToast
  
  User ->> AddStepUI: Initiate add step action
  AddStepUI ->> WorkflowStore: Call addNodeBetweenSafe(nodeOrEdgeId, step, type)
  alt Insertion succeeds
      WorkflowStore -->> AddStepUI: Return new node/edge ID
  else Error occurs
      WorkflowStore -->> AddStepUI: Throw error
      AddStepUI ->> ErrorToast: Display error message
  end
Loading
sequenceDiagram
  participant User
  participant BuilderChat
  participant ProtectedChecker
  participant WorkflowStore
  
  User ->> BuilderChat: Request removal of a step
  BuilderChat ->> ProtectedChecker: isProtectedStep(stepId)
  alt Step is protected
      ProtectedChecker -->> BuilderChat: Deny removal
      BuilderChat -->> User: Show protected step error
  else
      ProtectedChecker -->> BuilderChat: Allow removal
      BuilderChat ->> WorkflowStore: removeStepNode(stepId)
      WorkflowStore -->> BuilderChat: Updated workflow state
      BuilderChat -->> User: Confirm removal
  end
Loading

Possibly related PRs

Suggested labels

Feature, size:XXL, lgtm

Poem

I’m a bunny who hops through code all day,
Refining node flow in a safe, new way.
With steps and checks, the workflow’s bright,
Type updates and fixes take flight.
I nibble through errors with a gentle touch,
Celebrating clean code—I love it so much! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

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: 0

🧹 Nitpick comments (10)
keep-ui/features/workflows/builder/ui/BuilderChat/builder-chat.tsx (5)

107-114: Consider externalizing special step IDs.
Implementation is correct, but for better maintainability and clarity, you could store these protected IDs in a dedicated constant or enum.


116-130: Optional unification of Skeleton components.
Defining your own skeleton placeholder is fine, but it might be worth unifying the pattern across the app for consistent loading states.


293-319: Improve user flow and validation for removeStepNode.
Using confirm() may interrupt the user experience. Consider a custom confirmation modal and verify that the node exists before attempting deletion.


335-365: DRY up logic between removeStepNode and removeTriggerNode.
They share similar behaviors. Consolidating them into one reusable function could avoid code duplication.


692-803: Opportunity to unify addStep and addAction logic.
They share a similar approach; refactoring could minimize duplication and improve maintainability.

keep-ui/features/workflows/builder/ui/workflow-status.tsx (1)

23-34: Switching from <div> to <span> could affect layout.
Inline elements might behave differently in various containers. Confirm this doesn't break existing styling or introduce wrapping issues.

keep-ui/features/workflows/builder/ui/BuilderChat/AddStepUI.tsx (1)

5-58: Typed approach for step addition is clearer.
Splitting props into “complete” vs. “executing” states improves code clarity. Consider further consolidating these patterns across the codebase to reduce duplication.

keep-ui/features/workflows/builder/ui/BuilderChat/StepPreview.tsx (2)

19-26: Simplify redundant conditions.

The function contains duplicate conditions that can be simplified.

Apply this diff to remove redundancy:

 function getStepIconUrl(data: V2Step | V2StepTrigger) {
   const { type } = data || {};
-  if (type === "alert" || type === "workflow" || type === "trigger" || !type)
-    return "/keep.png";
-  if (type === "incident" || type === "workflow" || type === "trigger" || !type)
+  if (!type || ["alert", "incident", "workflow", "trigger"].includes(type))
     return "/keep.png";
   return `/icons/${normalizeStepType(type)}-icon.png`;
 }

28-48: LGTM! Well-structured YAML generation with proper error handling.

The function effectively consolidates YAML generation logic for different step types with proper error handling and type guards.

Address the TODO comment about other types.

The TODO comment indicates that support for additional types needs to be implemented.

Would you like me to help identify the missing types and implement the necessary logic?

keep-ui/entities/workflows/model/workflow-store.ts (1)

268-289: Address the TODO comment for better error handling.

The error handling can be improved by extracting more meaningful error messages from ZodError. Currently, there's a TODO comment indicating this need.

Consider implementing a custom error message extractor:

-          // TODO: extract meaningful error from ZodError
-          const validationError = fromError(error);
-          showErrorToast(validationError);
+          const validationError = fromError(error);
+          const errorMessage = validationError.details
+            .map(detail => detail.message)
+            .join('. ');
+          showErrorToast(errorMessage);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1e3b39 and 2969433.

📒 Files selected for processing (9)
  • keep-ui/entities/workflows/model/__tests__/workflow-store.test.tsx (2 hunks)
  • keep-ui/entities/workflows/model/types.ts (3 hunks)
  • keep-ui/entities/workflows/model/workflow-store.ts (3 hunks)
  • keep-ui/features/workflows/builder/ui/BuilderChat/AddStepUI.tsx (2 hunks)
  • keep-ui/features/workflows/builder/ui/BuilderChat/AddTriggerUI.tsx (1 hunks)
  • keep-ui/features/workflows/builder/ui/BuilderChat/StepPreview.tsx (1 hunks)
  • keep-ui/features/workflows/builder/ui/BuilderChat/builder-chat.tsx (11 hunks)
  • keep-ui/features/workflows/builder/ui/WorkflowToolbox.tsx (1 hunks)
  • keep-ui/features/workflows/builder/ui/workflow-status.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: tests-e2e (postgres)
  • GitHub Check: tests-e2e (mysql)
🔇 Additional comments (14)
keep-ui/features/workflows/builder/ui/BuilderChat/builder-chat.tsx (7)

10-17: New imports for step and condition schemas look good.
They align well with the subsequent usage throughout the file.


47-48: Loading skeleton and AddStepUI imports look fine.
No issues identified, implementation is straightforward.


376-394: AddManualTrigger flow is consistent.
The loading and complete states match the established pattern. Implementation looks good.


419-422: Possibility of a loading fallback for alert properties.
Reading alert properties is straightforward, but ensure you have a fallback UI if data fetching takes longer.


424-485: Validate data types for alertFilters.
Currently, everything is treated as a string. If numeric or boolean values are needed, confirm the system can handle them properly.


669-689: Verify uniqueness of actionName.
Implementation looks fine, but ensure 'actionName' is unique or properly handled to avoid collisions.


805-903: Condition addition logic looks solid.
Implementation is straightforward, with clear error handling.

keep-ui/features/workflows/builder/ui/BuilderChat/AddTriggerUI.tsx (1)

59-63: LGTM! Improved error handling with addNodeBetweenSafe.

The change to use addNodeBetweenSafe aligns with the safer node addition approach, and the error handling in handleAddTrigger is comprehensive.

keep-ui/features/workflows/builder/ui/WorkflowToolbox.tsx (1)

26-30: LGTM! Consistent use of addNodeBetweenSafe.

The change to use addNodeBetweenSafe maintains consistency with the safer node addition approach across the codebase.

keep-ui/entities/workflows/model/types.ts (2)

173-178: LGTM! Well-structured condition type definitions.

The new union type properly combines condition schemas and provides a clear type definition.


376-376:

❓ Verification inconclusive

Verify the impact of deleteNodes return type change.

The return type of deleteNodes has been changed from void to string[]. Ensure all callers handle the returned array of deleted node IDs correctly.


🏁 Script executed:

#!/bin/bash
# Search for deleteNodes usage
rg -A 5 'deleteNodes\(' --type ts

Length of output: 3122


Action: Verify that all callers are intentionally handling (or intentionally ignoring) the new string[] return value from deleteNodes.

  • In the tests (workflow-store.test.tsx), the call to deleteNodes ignores the returned array. Confirm that no additional validation of the deleted node IDs is needed there.
  • In BuilderChat (builder-chat.tsx), the returned array is captured and checked, which is the expected handling.
  • In NodeMenu.tsx, the function is invoked without using its return value. Ensure this is acceptable given the new API behavior.

Please review these usages to make sure that the impact of the return type change is fully intentional and does not lead to any overlooked side effects.

keep-ui/entities/workflows/model/__tests__/workflow-store.test.tsx (1)

69-70: LGTM! Test cases updated to use the new safe method.

The test cases have been correctly updated to use addNodeBetweenSafe instead of addNodeBetween, maintaining the same test coverage and validation logic.

Also applies to: 112-113

keep-ui/entities/workflows/model/workflow-store.ts (2)

259-267: LGTM! Improved implementation of addNodeBetween.

The method has been enhanced with better return type handling and state management.


486-487: LGTM! Consistent return type in deleteNodes.

The method now consistently returns an array in all cases, improving type safety and predictability.

Also applies to: 491-492, 573-574

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.

[🐛 Bug]: make workflow ai assistant step generations more accurate
1 participant