waveterm icon indicating copy to clipboard operation
waveterm copied to clipboard

fix: add WebSocket polyfill for Electron main process

Open DepsCian opened this issue 8 months ago • 3 comments

Resolves ReferenceError where WebSocket was undefined in main process. Implements dual WebSocket loading strategy with proper environment detection and fallback mechanisms for Node.js contexts.

DepsCian avatar Apr 06 '25 10:04 DepsCian

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 06 '25 10:04 CLAassistant

Walkthrough

The changes update how WebSocket objects are initialized and handled in the frontend/util/wsutil.ts file. The variable NodeWebSocket now has a more flexible type (any instead of a specific type), and the environment check has been expanded to include a condition for when process.type is "browser". The module import process for the WebSocket implementation now first attempts a synchronous load using require("ws").WebSocket within a try block; if that fails, it falls back to the previous asynchronous approach while logging an error. Furthermore, the newWebSocket function has been enhanced with improved error handling, throwing an explicit error when neither the Node-specific nor the global WebSocket is available.

The changes to the frontend/app/element/markdown.scss file involve reconfiguration of the .codeblock-actions class, including the removal of the visibility property, introduction of opacity, and adjustments to positioning and spacing. The .iconbutton class is added for button styling, and hover effects are implemented for user interaction.

In frontend/app/element/markdown.tsx, new methods handleSendToTerminal and sendTextToTerminal are introduced to facilitate sending text to terminal blocks, enhancing the CodeBlock component's functionality.

The frontend/app/element/typingindicator.scss file sees a restructuring of the typing indicator styles, transitioning from a blinking effect to a typing animation, with new classes and keyframes defined.

In frontend/app/element/typingindicator.tsx, a new interface TypingIndicatorProps is exported, and the TypingIndicator component is redefined to accept additional props and a new HTML structure.

The frontend/app/view/waveai/waveai.scss file undergoes significant styling modifications, including the introduction of new classes for message types and adjustments to chat message containers and input components.

Finally, in frontend/app/view/waveai/waveai.tsx, the WaveAiModel class is updated to remove the viewText atom and introduce a new StreamingText component, enhancing message display and editing capabilities within the chat interface.

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22 [1/4] Resolving packages... info There appears to be trouble with the npm registry (returned undefined). Retrying... info There appears to be trouble with the npm registry (returned undefined). Retrying... info There appears to be trouble with the npm registry (returned undefined). Retrying... info There appears to be trouble with the npm registry (returned undefined). Retrying... /opt/yarn-v1.22.22/lib/cli.js:66663 throw new (_errors || _load_errors()).ResponseError(_this3.reporter.lang('requestFailed', description), res.statusCode); ^

ResponseError: Request failed "503 Service Unavailable" at ResponseError.ExtendableBuiltin (/opt/yarn-v1.22.22/lib/cli.js:696:66) at new ResponseError (/opt/yarn-v1.22.22/lib/cli.js:802:124) at params.callback [as _callback] (/opt/yarn-v1.22.22/lib/cli.js:66663:19) at self.callback (/opt/yarn-v1.22.22/lib/cli.js:141415:22) at Request.emit (node:events:519:28) at Request. (/opt/yarn-v1.22.22/lib/cli.js:142387:10) at Request.emit (node:events:519:28) at IncomingMessage. (/opt/yarn-v1.22.22/lib/cli.js:142309:12) at Object.onceWrapper (node:events:633:28) at IncomingMessage.emit (node:events:531:35) { responseCode: 503 }

Node.js v22.9.0

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

coderabbitai[bot] avatar Apr 06 '25 10:04 coderabbitai[bot]

I also have this issue and would love to see this fix merged.

nahoj avatar May 03 '25 05:05 nahoj