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

feat: Composer.unstable_on("send", callback) #1279

Merged
merged 5 commits into from
Dec 28, 2024
Merged

feat: Composer.unstable_on("send", callback) #1279

merged 5 commits into from
Dec 28, 2024

Conversation

Yonom
Copy link
Owner

@Yonom Yonom commented Dec 28, 2024

🔍 Review Summary

Purpose:

  • Enhance event management in Composer runtime and update dependencies.

Changes:

  • New Feature: Added Composer.unstable_on("send", callback) for event subscription.
  • Enhancement: Improved core file event handling with new types and methods.
  • Refactor: Renamed cancel to handleCancel for clarity.
  • Chore: Updated @assistant-ui/react to ^0.7.21 for compatibility.

Impact:

  • Improved user experience with enhanced event management and updated dependencies.
Original Description

None

Summary by CodeRabbit

  • New Features

    • Added an unstable event handler unstable_on("send", callback) to the Composer component, allowing developers to register a callback for send events.
  • Chores

    • Updated peer dependency versions across multiple packages to ^0.7.21
    • Bumped @assistant-ui/react package version to 0.7.21

Copy link

vercel bot commented Dec 28, 2024

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

Name Status Preview Comments Updated (UTC)
assistant-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 8:30am

Copy link
Contributor

coderabbitai bot commented Dec 28, 2024

Warning

Rate limit exceeded

@Yonom has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1fadbbc and 70f8451.

📒 Files selected for processing (3)
  • packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx (5 hunks)
  • packages/react/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx (1 hunks)
  • packages/react/src/runtimes/core/BaseThreadRuntimeCore.tsx (1 hunks)

Walkthrough

This pull request introduces version 0.7.21 of the @assistant-ui/react package, focusing on enhancing the event handling capabilities of the Composer component. The primary changes include adding an unstable event handler for the "send" event, modifying method visibilities, and updating peer dependencies across multiple packages. The changes are primarily centered around improving the flexibility and extensibility of the runtime components.

Changes

File Change Summary
packages/*/package.json Updated peer dependency @assistant-ui/react from ^0.7.20 to ^0.7.21 in multiple packages
packages/react/package.json Version bumped from 0.7.20 to 0.7.21
packages/react/CHANGELOG.md Added entry for version 0.7.21 with new unstable_on("send", callback) feature
packages/react/src/api/ComposerRuntime.ts Added unstable_on method to ComposerRuntimeImpl
packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx - Made setRole and setText public
- Added reset method
- Introduced event subscribers mechanism
- Added unstable_on method
packages/react/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx Renamed cancel method to handleCancel
packages/react/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx Renamed cancel method to handleCancel
packages/react/src/runtimes/core/ComposerRuntimeCore.tsx Added ComposerRuntimeEventType and unstable_on method

Sequence Diagram

sequenceDiagram
    participant Client
    participant Composer
    participant Runtime
    
    Client->>Composer: unstable_on("send", callback)
    Composer->>Runtime: Register event subscriber
    Runtime-->>Composer: Subscription confirmed
    
    Client->>Composer: Send message
    Composer->>Runtime: Handle send
    Runtime->>Runtime: Notify event subscribers
    Runtime->>Client: Trigger callback
Loading

Poem

🐰 A Rabbit's Ode to Event Handling 🎉

Hop, hop, through the runtime's grace,
Send events now find their place!
Unstable magic, callbacks bright,
Composer's power takes new flight!
Coding rabbits dance with glee! 🎈


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

Walkthrough

This update introduces a new feature, Composer.unstable_on("send", callback), enabling event subscription within the Composer runtime. The peer dependency @assistant-ui/react is updated to ^0.7.21 across multiple packages. Enhancements in the Composer runtime core files include new event types and methods for improved event handling.

Changes

File(s) Summary
packages/react-ai-sdk/package.json, packages/react-hook-form/package.json, packages/react-langgraph/package.json, packages/react-markdown/package.json, packages/react-playground/package.json, packages/react-syntax-highlighter/package.json, packages/react-trieve/package.json Updated peer dependency @assistant-ui/react to version ^0.7.21.
packages/react/CHANGELOG.md, packages/react/package.json Added entry for version 0.7.21 with new feature Composer.unstable_on("send", callback) and updated package version.
packages/react/src/api/ComposerRuntime.ts, packages/react/src/runtimes/core/ComposerRuntimeCore.tsx Added unstable_on method for subscribing to "send" events and introduced ComposerRuntimeEventType.
packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx Enhanced event handling with unstable_on and _notifyEventSubscribers methods.
packages/react/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx, packages/react/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx Refactored cancel method to handleCancel.
Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @bot + *your message*
Example: @bot Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @bot + *feedback*
Example: @bot Do not comment on `save_auth` function !

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added event subscription capabilities to the Composer component, introducing an unstable 'send' event listener and updating peer dependencies across packages to maintain compatibility.

  • Added unstable_on("send", callback) method in BaseComposerRuntimeCore with Map-based event storage
  • Renamed cancel to handleCancel in composer runtimes for consistent naming with handleSend
  • Updated peer dependency version of @assistant-ui/react from ^0.7.20 to ^0.7.21 across all packages
  • Modified send() method to notify subscribers of 'send' events before resetting state
  • Added version 0.7.21 entry in CHANGELOG.md documenting the new experimental feature

14 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@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: 3

🔭 Outside diff range comments (1)
packages/react-syntax-highlighter/package.json (1)

Line range hint 30-37: Well-structured version management approach.

The coordinated version bump across packages demonstrates good practices:

  1. Using ^0.7.21 allows for patch updates while maintaining compatibility
  2. The unstable_ prefix properly indicates experimental features
  3. The minor version bump (0.7.20 -> 0.7.21) correctly reflects the addition of a new feature
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe546b and 1fadbbc.

📒 Files selected for processing (14)
  • packages/react-ai-sdk/package.json (1 hunks)
  • packages/react-hook-form/package.json (1 hunks)
  • packages/react-langgraph/package.json (1 hunks)
  • packages/react-markdown/package.json (1 hunks)
  • packages/react-playground/package.json (1 hunks)
  • packages/react-syntax-highlighter/package.json (1 hunks)
  • packages/react-trieve/package.json (1 hunks)
  • packages/react/CHANGELOG.md (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/api/ComposerRuntime.ts (2 hunks)
  • packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx (4 hunks)
  • packages/react/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx (1 hunks)
  • packages/react/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx (1 hunks)
  • packages/react/src/runtimes/core/ComposerRuntimeCore.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx

[error] 158-158: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

🔇 Additional comments (22)
packages/react/src/runtimes/composer/BaseComposerRuntimeCore.tsx (9)

8-11: New import reference
Importing ComposerRuntimeEventType appears correct. No issues noted.


54-54: Visibility change: setRole
Elevating setRole to public is sensible if external code needs to change the role. Validate that no privacy constraints are violated.


59-59: Visibility change: setText
Making setText public aligns with providing external control over the text state. Verify no side effects in external usage.


64-64: Internal reset method
Encapsulating the reset logic in a private _resetInternal method is clear and maintainable.


71-73: Public reset method
Calling _resetInternal directly helps ensure consistent reset behavior. No problems found.


93-93: Reset on send
Resetting text, role, and attachments after sending might surprise some consumers who expect the data to remain. Confirm the design aligns with product requirements.


96-96: New send event notification
_notifyEventSubscribers("send") aligns with event-driven design. Good addition for external hooks.


99-101: Cancel method
Delegating to handleCancel is consistent. Confirm the overridden method is properly implemented in subclasses.


140-146: Event notification method
_notifyEventSubscribers uses the stored subscriber callbacks. Straightforward logic. Good job.

packages/react/src/runtimes/core/ComposerRuntimeCore.tsx (2)

4-4: New typed event
Defining "send" as ComposerRuntimeEventType helps ensure clarity and type safety in event handling.


31-34: New unstable_on method
Adding unstable_on fosters an extensible event subscription mechanism. Keep an eye on naming if this stabilizes.

packages/react/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx (1)

49-49: Renamed cancel to handleCancel
Renaming to handleCancel for clarity is consistent with the base class changes. Implementation remains straightforward.

packages/react/src/api/ComposerRuntime.ts (2)

4-4: Import event type
Importing ComposerRuntimeEventType clarifies usage in the unstable_on method.


166-171: New unstable_on method implementation
This effectively delegates to the core's unstable_on. Make sure the composer is defined before registration.

packages/react-langgraph/package.json (1)

33-33: Peer dependency version update
Upgrading @assistant-ui/react to ^0.7.21 maintains alignment with newly introduced features.

packages/react-hook-form/package.json (1)

33-33: LGTM! Version bump aligns with the new unstable feature.

The peer dependency update to ^0.7.21 is appropriate for the new Composer.unstable_on("send", callback) feature. The unstable_ prefix correctly indicates this is an experimental API that may change in future versions.

packages/react-ai-sdk/package.json (1)

37-37: LGTM! Version bump enables new event handling capabilities.

The peer dependency update to ^0.7.21 allows this AI SDK package to utilize the new Composer.unstable_on("send", callback) feature. Since this package likely integrates closely with the Composer component, this update is particularly relevant.

Let's verify if this package uses the Composer component:

✅ Verification successful

Version bump is appropriate as the package actively uses composer functionality

The package indeed relies heavily on the @assistant-ui/react package and specifically uses composer functionality, as evidenced by:

  • Direct composer state management in useInputSync.tsx
  • Multiple imports of core components and types from @assistant-ui/react
  • Recent changelog entries showing composer-related features

The version bump to ^0.7.21 is necessary to maintain compatibility with the composer's event handling capabilities.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Composer usage in the AI SDK package
rg -l "Composer" "packages/react-ai-sdk/src/"

Length of output: 43


Script:

#!/bin/bash
# Let's try a broader search for Composer usage in the package
rg -i "composer" "packages/react-ai-sdk/"

# Also search for any imports from @assistant-ui/react
rg -i "from ['|\"]@assistant-ui/react" "packages/react-ai-sdk/"

Length of output: 2608

packages/react-syntax-highlighter/package.json (1)

30-30: LGTM! Version bump maintains ecosystem consistency.

The peer dependency update to ^0.7.21 maintains version alignment across the package ecosystem, even though this syntax highlighter package may not directly utilize the new Composer event handling feature.

packages/react-markdown/package.json (1)

44-44: LGTM: Peer dependency version bump is consistent

The update to @assistant-ui/react ^0.7.21 aligns with the introduction of the new unstable_on("send") feature.

packages/react-playground/package.json (1)

50-50: LGTM: Peer dependency version bump is consistent

The update to @assistant-ui/react ^0.7.21 aligns with other packages in the monorepo.

packages/react-trieve/package.json (1)

48-48: LGTM: Peer dependency version bump is consistent

The update to @assistant-ui/react ^0.7.21 aligns with other packages. The existing @assistant-ui/react-markdown ^0.7.7 dependency remains compatible with this change.

✅ Verification successful

Version compatibility check confirms alignment across packages

The version check shows that all packages in the workspace are using compatible versions of @assistant-ui/react:

  • Most packages under /packages directory consistently use ^0.7.21
  • Example apps either use workspace:* (internal workspace dependency) or ^0.7.17 which is compatible with ^0.7.21

Let's verify the compatibility with @assistant-ui/react-markdown as well:


Version bump is consistent and compatible across dependencies

The version checks confirm that:

  1. The @assistant-ui/react peer dependency update to ^0.7.21 aligns with other packages in the workspace
  2. The existing @assistant-ui/react-markdown ^0.7.7 dependency is compatible, as other packages use either the same version or lower compatible versions (^0.7.5)
  3. No version conflicts or compatibility issues were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify version compatibility across the workspace
# Look for any potential version conflicts or mismatches

# Check all package.json files for @assistant-ui/react versions
echo "Checking @assistant-ui/react versions across workspace:"
fd package.json | xargs grep -l "@assistant-ui/react" | while read -r file; do
  echo "=== $file ==="
  cat "$file" | jq -r '.peerDependencies["@assistant-ui/react"] // .dependencies["@assistant-ui/react"] // empty'
done

Length of output: 5823


Script:

#!/bin/bash
# Check react-markdown dependency versions
echo "Checking @assistant-ui/react-markdown versions:"
fd package.json | xargs grep -l "@assistant-ui/react-markdown" | while read -r file; do
  echo "=== $file ==="
  cat "$file" | jq -r '.dependencies["@assistant-ui/react-markdown"] // .peerDependencies["@assistant-ui/react-markdown"] // empty'
done

Length of output: 2376

packages/react/package.json (1)

32-32: LGTM: Version bump to 0.7.21

The version increment aligns with the new feature addition mentioned in the changelog.

Yonom and others added 2 commits December 28, 2024 00:23
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…eCore.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Yonom Yonom merged commit 094c8f3 into main Dec 28, 2024
5 of 6 checks passed
@Yonom Yonom deleted the sf-branch-4 branch December 28, 2024 08:28
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.

1 participant