Skip to content

Conversation

@jackshen310
Copy link
Collaborator

@jackshen310 jackshen310 commented Apr 1, 2025

Summary by CodeRabbit

  • Chores

    • Updated module export paths to align with modern ECMAScript standards.
    • Upgraded the @coze/realtime-api package to a new beta version.
  • Refactor

    • Centralized event names into a dedicated structure for improved modularity and clarity.
    • Enhanced configuration for library exports to accommodate new subpaths.
    • Added new export for the event-names subpath in the @coze/realtime-api package.
    • Documented patch changes for the @coze/api and @coze/realtime-api packages.

@coderabbitai
Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

This pull request introduces patches for two packages. In the @coze/api patch, the ESM file extensions in the JSON metadata have been updated from .js to .mjs. In the @coze/realtime-api patch, the EventNames enum is moved out of the event-handler file into a new dedicated file. Additionally, the package.json for @coze/api (within packages/coze-js) has been updated to a beta pre-release version, and its export paths have been modified to use the .mjs extension. Import statements in source and test files of realtime-api have been adjusted accordingly.

Changes

Files Change Summary
common/changes/@coze/api/*json Documents patch update: change file extensions from .js to .mjs for the ESM specification in @coze/api.
common/changes/@coze/realtime-api/*json Documents patch update: relocation of the EventNames enum in @coze/realtime-api.
packages/coze-js/package.json Version updated to 1.1.1-beta.1 and export paths changed from .js to .mjs for main and auxiliary modules.
packages/realtime-api/src/client.ts, src/index.ts, test/client.spec.ts, test/event-handler.spec.ts Import statements updated to source EventNames from the new ./event-names file instead of the old location; corresponding removal of enum from event-handler.
packages/realtime-api/src/event-handler.ts Removal of the EventNames enum.
packages/realtime-api/src/event-names.ts New file added that defines the EventNames enum with associated event string constants and comments.
packages/realtime-api/package.json Version updated to 1.1.1-beta.5 and new export added for event-names.
packages/realtime-api/rslib.config.ts Function getLibShared updated to accept additional parameters and modify output paths accordingly.
common/changes/@coze/realtime-api/*json Documents addition of export for the event-names subpath in @coze/realtime-api.
common/changes/@coze/realtime-api/*json Documents patch change indicating a "Publish fix/module-error" for @coze/realtime-api.

Possibly related PRs

Suggested reviewers

  • DingGao-Devin

Poem

I'm a rabbit with a code-filled cheer,
Hopping through changes, both far and near.
.mjs hops replace the old .js with flair,
And event names now leap with a new affair.
In this code garden, I simply hop and play,
Celebrating every fix along the way.
🐇✨


📜 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 972f7eb and a5cd06d.

📒 Files selected for processing (3)
  • common/changes/@coze/realtime-api/fix-module-error_2025-04-02-11-44.json (1 hunks)
  • packages/realtime-api/package.json (3 hunks)
  • packages/realtime-api/rslib.config.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • common/changes/@coze/realtime-api/fix-module-error_2025-04-02-11-44.json
🔇 Additional comments (8)
packages/realtime-api/package.json (4)

3-3: Appropriate version bump for beta release.

The version number has been incremented from "1.1.1-beta.1" to "1.1.1-beta.5", which follows semantic versioning principles for pre-release versions.


25-26: Export path added for new event-names module.

The addition of the "./event-names" export path properly exposes the new module that contains the EventNames enum that was moved from the event-handler file.


72-76: Well-structured export paths for the new event-names module.

The cozePublishConfig correctly includes export paths for the new event-names module, providing proper configurations for CommonJS, ESM, and TypeScript types.


68-68:

❓ Verification inconclusive

File extension update from .cjs to .js.

The require path and main file have been updated from using .cjs extension to .js extension. This change aligns with modern Node.js package practices, but ensure that the build output actually produces files with these names.

Also applies to: 78-78


🏁 Script executed:

#!/bin/bash
# Check if the build actually produces files with .js extension
echo "Checking build configuration and output files..."
cat packages/realtime-api/package.json | grep -E "main|require" | grep -E "\.js|\.cjs"
ls -la packages/realtime-api/dist/cjs/ 2>/dev/null || echo "Build directory not found - verification would require building the package"

Length of output: 526


Verification Outcome: Ensure Build Output Consistency

  • The package.json entries have been correctly updated to reference .js files (e.g., "require": "./dist/cjs/index.js" and "main": "dist/cjs/index.js"), aligning with modern Node.js practices.
  • The verification script confirms that these changes exist in the configuration file.
  • However, the build output directory (packages/realtime-api/dist/cjs/) was not located during the check. This suggests that the build process may not have been executed in the verification environment or that the expected output files are not present. Please verify locally that the build generates the corresponding .js files.
packages/realtime-api/rslib.config.ts (4)

3-3: Enhanced function signature to support subpaths.

The getLibShared function signature has been improved to support TypeScript declarations and subpaths, which enables the build configuration to handle multiple entry points.


9-10: Proper configuration for output, declarations, and source entries.

The updated configuration:

  1. Sets the output JavaScript path based on the subpath
  2. Conditionally generates TypeScript declarations
  3. Dynamically sets the entry point based on the subpath

These changes correctly support the new module structure with the separated event-names module.

Also applies to: 13-18, 19-21


38-41: Comprehensive build configuration for multiple entry points.

The lib array has been updated to include separate configurations for:

  1. Main entry point with cjs format and TypeScript declarations
  2. Main entry point with esm format without TypeScript declarations
  3. event-names module with cjs format and TypeScript declarations
  4. event-names module with esm format without TypeScript declarations

This ensures proper building of both the main package and the new event-names module.


5-5:

✅ Verification successful

Verify impact of setting autoExtension to false.

Setting autoExtension to false means the build tool won't automatically add file extensions. This could potentially cause issues if imports in the codebase don't explicitly include file extensions.


🏁 Script executed:

#!/bin/bash
# Check if imports in the codebase include file extensions
echo "Checking import statements in the codebase..."
grep -r "from './" --include="*.ts" packages/realtime-api/src/ | grep -v "\.ts" | head -n 10
echo "Note: If imports don't include extensions, setting autoExtension to false might cause issues"

Length of output: 396


AutoExtension setting verified as safe

After running the verification script on import statements in packages/realtime-api/src/, no instances were found where imports omitted the .ts extension. This indicates that all import statements explicitly include their file extensions, so setting autoExtension to false does not pose an issue in this area of the codebase.

  • Verified that imports explicitly include file extensions.
  • No further changes are required.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 (1)
common/changes/@coze/realtime-api/fix-module-error_2025-04-01-06-28.json (1)

1-12: JSON Metadata: Remove Extraneous Trailing Line
The JSON metadata correctly documents the patch for moving the EventNames enum to a separate file. However, it appears that the literal "12" at the end (line 12) is an extraneous artifact that should be removed to ensure the file remains valid JSON.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f73419 and 3143571.

📒 Files selected for processing (9)
  • common/changes/@coze/api/fix-module-error_2025-04-01-05-22.json (1 hunks)
  • common/changes/@coze/realtime-api/fix-module-error_2025-04-01-06-28.json (1 hunks)
  • packages/coze-js/package.json (2 hunks)
  • packages/realtime-api/src/client.ts (1 hunks)
  • packages/realtime-api/src/event-handler.ts (1 hunks)
  • packages/realtime-api/src/event-names.ts (1 hunks)
  • packages/realtime-api/src/index.ts (1 hunks)
  • packages/realtime-api/test/client.spec.ts (1 hunks)
  • packages/realtime-api/test/event-handler.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/realtime-api/src/event-names.ts (1)
packages/realtime-api/src/index.ts (1)
  • EventNames (366-366)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Node.js v20 (ubuntu-latest)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (11)
packages/coze-js/package.json (4)

3-3: Version Update to Beta:

The version has been updated to "1.1.1-beta.1", reflecting the pre-release status. Make sure that downstream users and your changelog/documentation clearly indicate that this is a beta release.


91-91: ESM Main Export Path Update:

The main export "import" path has been changed to use the .mjs extension ("./dist/esm/index.mjs"). This update ensures compliance with the ESM specification. Confirm that your build outputs the corresponding .mjs files.


96-96: WS-Tools Export Path Update:

The export path for "./ws-tools" now uses the .mjs extension ("./dist/esm/ws-tools/index.mjs"), which aligns with the rest of the module's changes. This looks consistent—just verify that the build pipeline handles these files correctly.


101-101: Module Field Update in Publish Config:

The "module" field within the cozePublishConfig has been updated to "dist/esm/index.mjs", ensuring it adheres to the ESM convention. This change is essential for module resolution in environments supporting ESM.

common/changes/@coze/api/fix-module-error_2025-04-01-05-22.json (1)

1-12: ESM Extension Patch Documentation:

This JSON file correctly documents the patch for the @coze/api package by noting the update of ECMAScript Module (ESM) file extensions from .js to .mjs. The metadata (package name, comment, type, and email) appears complete. Ensure internal documentation references this file for clear traceability of the change.

packages/realtime-api/test/client.spec.ts (1)

5-7: Import Path Update for EventNames
The import for EventNames has been updated from the old path to ../src/event-names to reflect the module restructuring. This change promotes consistency across the codebase and aligns with the new file organization.

packages/realtime-api/src/index.ts (1)

8-11: Updated Import for EventNames
The import statement for EventNames now correctly references ./event-names instead of the older location. This update is clear and consistent with the recent refactor.

packages/realtime-api/src/client.ts (1)

14-16: Consistent Import Update in Client Module
The update on lines 15–16 adjusts the import of EventNames to ./event-names, ensuring that the client module references the enum from its new location. The change is straightforward and correctly implemented.

packages/realtime-api/test/event-handler.spec.ts (1)

1-2: Refined Imports in Event Handler Tests
The test file now imports EventNames from the new path (../src/event-names), and the ordering with RealtimeEventHandler has been updated accordingly. This ensures that the tests remain aligned with the recent module reorganization.

packages/realtime-api/src/event-names.ts (1)

1-142: Well-organized extraction of EventNames enum

The creation of a dedicated file for the EventNames enum is a good refactoring practice that improves code organization by following the single responsibility principle. The enum is comprehensive, well-documented with bilingual comments, and follows consistent naming conventions.

packages/realtime-api/src/event-handler.ts (1)

1-1: Import path correctly updated for EventNames enum

The import statement has been properly updated to reference the EventNames enum from its new location in the dedicated event-names.ts file. This maintains all functionality while improving code organization.

@codecov
Copy link

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@            Coverage Diff             @@
##             main     #177      +/-   ##
==========================================
- Coverage   91.82%   90.58%   -1.25%     
==========================================
  Files         117       77      -40     
  Lines        5469     3760    -1709     
  Branches     1106      685     -421     
==========================================
- Hits         5022     3406    -1616     
+ Misses        447      351      -96     
- Partials        0        3       +3     
Components Coverage Δ
coze-js 92.73% <ø> (-0.22%) ⬇️
realtime-api 90.11% <ø> (-1.75%) ⬇️
chat-sdk ∅ <ø> (∅)
Files with missing lines Coverage Δ
packages/realtime-api/src/client.ts 85.98% <ø> (-2.19%) ⬇️
packages/realtime-api/src/event-handler.ts 90.90% <100.00%> (-7.17%) ⬇️
packages/realtime-api/src/event-names.ts 100.00% <100.00%> (ø)
packages/realtime-api/src/index.ts 92.14% <ø> (-0.85%) ⬇️

... and 71 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jackshen310 jackshen310 added this pull request to the merge queue Apr 8, 2025
Merged via the queue into main with commit 26c005c Apr 8, 2025
13 checks passed
@jackshen310 jackshen310 deleted the fix/module-error branch April 8, 2025 13:00
@coderabbitai coderabbitai bot mentioned this pull request Oct 28, 2025
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.

3 participants