Skip to content

Conversation

@jackshen310
Copy link
Collaborator

@jackshen310 jackshen310 commented Mar 7, 2025

Summary by CodeRabbit

  • New Features

    • Added a setting that lets users specify a custom WebSocket URL for chat functionality.
  • Refactor

    • Updated the chat connection process to retrieve the WebSocket URL dynamically, enhancing flexibility in connection configuration.

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2025

Walkthrough

This change introduces a new method getBaseWsUrl within the configuration object to retrieve the WebSocket URL from local storage, defaulting to 'wss://ws.coze.cn' if no value is found. The settings form has been updated to include an input field for the WebSocket URL, and API initialization hooks now dynamically fetch the URL using the new method instead of a hardcoded constant.

Changes

Files Change Summary
examples/coze-js-web/src/pages/chat-x/config.ts Added new method getBaseWsUrl to retrieve the WebSocket URL from local storage with a fallback default of 'wss://ws.coze.cn'.
examples/coze-js-web/src/pages/chat-x/settings.tsx, .../use-coze-api.ts, .../use-ws-api.ts Updated the settings form to include a new WebSocket URL field and replaced static constant references with dynamic calls to config.getBaseWsUrl() for API initialization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsForm
    participant Config
    participant LocalStorage
    participant API

    User->>SettingsForm: Open Settings Page
    SettingsForm->>Config: Call getBaseWsUrl()
    Config->>LocalStorage: Retrieve 'chat-x_base_ws_url'
    alt URL exists in storage
        LocalStorage-->>Config: Return stored URL
    else URL not found
        LocalStorage-->>Config: Return null
        Config-->>Config: Use default 'wss://ws.coze.cn'
    end
    Config-->>SettingsForm: Return WebSocket URL
    SettingsForm->>API: Initialize client with WebSocket URL
Loading

Possibly related PRs

Suggested reviewers

  • jsongo

Poem

I'm a rabbit with code so spry,
Hopping through configs beneath the sky.
With dynamic websockets set just right,
Each setting hops into view so bright.
Celebrate changes – a hoppy new byte!
🐰✨


📜 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 a5b72d4 and 8712601.

📒 Files selected for processing (4)
  • examples/coze-js-web/src/pages/chat-x/config.ts (1 hunks)
  • examples/coze-js-web/src/pages/chat-x/settings.tsx (2 hunks)
  • examples/coze-js-web/src/pages/chat-x/use-coze-api.ts (1 hunks)
  • examples/coze-js-web/src/pages/chat-x/use-ws-api.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Node.js v20 (ubuntu-latest)
🔇 Additional comments (7)
examples/coze-js-web/src/pages/chat-x/config.ts (1)

4-5: Implementation looks clean and consistent!

This new method for retrieving the WebSocket URL follows the same pattern as the other configuration methods, making the code consistent and maintainable.

examples/coze-js-web/src/pages/chat-x/use-coze-api.ts (1)

29-29: Good refactoring from hardcoded value to configurable setting.

Using the configuration method instead of a hardcoded constant improves flexibility and maintainability.

examples/coze-js-web/src/pages/chat-x/settings.tsx (3)

17-17: Correctly retrieving the WebSocket URL from config.

This follows the same pattern as other configuration values, maintaining consistency.


21-21: Form initialized with the WebSocket URL value correctly.

The form initialization is properly updated to include the new field.


59-65: Well-structured form field for WebSocket URL.

The new form field follows the same pattern as other fields, including proper validation rules to ensure the field is required.

examples/coze-js-web/src/pages/chat-x/use-ws-api.ts (2)

213-213: Good use of configurable WebSocket URL for transcription client.

Replacing hardcoded values with the configuration method improves flexibility.


311-311: Consistent use of configurable WebSocket URL for speech client.

The implementation maintains consistency by applying the same pattern to all WebSocket clients.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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 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.

@jackshen310 jackshen310 added this pull request to the merge queue Mar 10, 2025
Merged via the queue into coze-dev:main with commit 8e3bc2f Mar 10, 2025
3 checks passed
@jackshen310 jackshen310 deleted the feat/chat-x branch March 10, 2025 04:03
@codecov
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

❌ Your project status has failed because the head coverage (0.00%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage.

@@            Coverage Diff            @@
##             main   #135       +/-   ##
=========================================
- Coverage   91.82%      0   -91.83%     
=========================================
  Files         117      0      -117     
  Lines        5469      0     -5469     
  Branches     1106      0     -1106     
=========================================
- Hits         5022      0     -5022     
+ Misses        447      0      -447     
Components Coverage Δ
coze-js ∅ <ø> (∅)
realtime-api ∅ <ø> (∅)
chat-sdk ∅ <ø> (∅)

see 117 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.

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.

2 participants