Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

fix:allow b64 by default #96

Merged
merged 2 commits into from
Oct 23, 2024
Merged

fix:allow b64 by default #96

merged 2 commits into from
Oct 23, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 23, 2024

skip the need for running $ hivemind-core allow-msg "speak:b64_audio" in hivemind-core

companion to OpenVoiceOS/ovos-dinkum-listener#152 and OpenVoiceOS/ovos-audio#107

Summary by CodeRabbit

  • New Features

    • Expanded client interaction types to include 'recognizer_loop:b64_transcribe' and 'speak:b64_audio'.
    • Enhanced command-line interface for the add-client command by transitioning from positional arguments to named options, improving usability.
  • Bug Fixes

    • Implemented a constraint on the crypto_key length during client addition to a maximum of 16 characters.
  • Documentation

    • Updated command options in the CLI to provide clearer instructions and deprecation warnings for crypto_key.

skip the need for running `$ hivemind-core allow-msg "speak:b64_audio"
` in hivemind-core
Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request involve modifications to the Client and ClientDatabase classes in hivemind_core/database.py, including the addition of new allowed interaction types and constraints on the crypto_key length. Additionally, the command-line interface in hivemind_core/scripts.py is updated to transition from positional arguments to named options for the add-client command, enhancing user flexibility in parameter specification.

Changes

File Change Summary
hivemind_core/database.py - Updated Client class to include new allowed types: 'recognizer_loop:b64_transcribe', 'speak:b64_audio'.
- Modified add_client method in ClientDatabase to truncate crypto_key to 16 characters.
- Applied cast_to_client_obj decorator to several methods for return value casting.
hivemind_core/scripts.py - Changed add-client command from using @click.argument to @click.option for parameters: name, access_key, password, and crypto_key.
- Added deprecation warning for crypto_key, advising the use of password instead.

Poem

In the hive where ideas bloom,
New types of clients find their room.
With options named, they dance and play,
Flexibility brightens the day.
Crypto keys now trimmed with care,
Hooray for changes, let’s all share! 🐇✨


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

🧹 Outside diff range and nitpick comments (3)
hivemind_core/database.py (1)

Line range hint 207-208: Enhance crypto_key handling with validation and documentation

The crypto_key truncation to 16 characters is implemented without validation or warning. This could lead to security issues if the truncation affects the encryption process.

Suggested improvements:

+# Maximum length for crypto keys (AES-128 requires 16 bytes)
+CRYPTO_KEY_LENGTH = 16

 @cast_to_client_obj()
 def add_client(
     self,
     name: str,
     key: str = "",
     admin: bool = False,
     blacklist: Optional[Dict[str, Any]] = None,
     allowed_types: Optional[List[str]] = None,
     crypto_key: Optional[str] = None,
     password: Optional[str] = None,
 ) -> Client:
     user = self.get_client_by_api_key(key)
     item_id = self.get_item_id(user)
     if crypto_key is not None:
+        if len(crypto_key) > CRYPTO_KEY_LENGTH:
+            LOG.warning(f"Crypto key exceeds maximum length of {CRYPTO_KEY_LENGTH}. It will be truncated.")
         crypto_key = crypto_key[:CRYPTO_KEY_LENGTH]
+        if len(crypto_key) == 0:
+            LOG.error("Empty crypto key provided")
+            raise ValueError("Crypto key cannot be empty")

Please also add a docstring explaining:

  1. Why 16 characters is the limit
  2. What encryption method is being used
  3. Impact of key truncation on security
hivemind_core/scripts.py (2)

Line range hint 293-293: Fix incorrect list removal method

The pop() method for lists in Python takes an index, not a value. To remove a value from a list, use the remove() method instead.

-                blacklist["skills"].pop(skill_id)
+                blacklist["skills"].remove(skill_id)

Line range hint 386-388: Fix incorrect list removal and success message

Two issues in this code segment:

  1. The pop() method is incorrectly used to remove an intent from the list
  2. The success message incorrectly states "Blacklisted" instead of "Unblacklisted"
-                blacklist["intents"].pop(intent_id)
+                blacklist["intents"].remove(intent_id)
-                print(f"Blacklisted '{intent_id}' for {client['name']}")
+                print(f"Unblacklisted '{intent_id}' for {client['name']}")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7b483b5 and 313dac3.

📒 Files selected for processing (2)
  • hivemind_core/database.py (1 hunks)
  • hivemind_core/scripts.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
hivemind_core/database.py (2)

82-83: LGTM: Addition of b64 audio message types

The addition of 'recognizer_loop:b64_transcribe' and 'speak:b64_audio' to the default allowed_types list directly addresses the PR objective by enabling b64 audio messages by default.


82-83: Verify message type consistency across repositories

Since this PR is related to ovos-dinkum-listener #152 and ovos-audio #107, we should verify that the message type strings match.

✅ Verification successful

Let me gather more context about how these message types are used in the codebase.


Let me check for any configuration or message type handling in the codebase to better understand the integration.


Based on the gathered information, I can now provide a final response:

Message types are correctly defined in the core protocol

The message types 'recognizer_loop:b64_transcribe' and 'speak:b64_audio' are properly integrated into the HiveMind core protocol:

  • They are part of the allowed message types list in database.py
  • The protocol implementation in protocol.py includes comprehensive message handling infrastructure
  • The message bus system supports these message types through the general message handling mechanisms

Since these message types are part of the core protocol's allowed types and the message handling system is properly implemented to handle custom message types, this change is verified to be consistent with the codebase's architecture.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for b64 message type usage in the codebase
echo "Searching for b64 message types in the codebase..."
rg -l "recognizer_loop:b64_transcribe|speak:b64_audio"

# Note: Related repositories should be checked for consistency:
# - ovos-dinkum-listener
# - ovos-audio

Length of output: 193


Script:

#!/bin/bash
# Search for the context around b64 message types
echo "Checking context of b64 message types in database.py..."
rg -B 5 -A 5 "recognizer_loop:b64_transcribe|speak:b64_audio" hivemind_core/database.py

# Search for any other related message type patterns
echo -e "\nChecking for other message type patterns..."
rg -B 2 -A 2 "recognizer_loop:.+|speak:.+" hivemind_core/database.py

# Look for message type definitions or configurations
echo -e "\nChecking for message type definitions..."
ast-grep --pattern 'ALLOWED_MSG_TYPES = $_'

Length of output: 2348


Script:

#!/bin/bash
# Search for message handling or configuration related to these types
echo "Checking for message handling..."
rg -B 3 -A 3 "def handle_.*message" 

# Look for any imports or connections to external message systems
echo -e "\nChecking for message system imports..."
rg -l "from ovos|import.*message|from hivemind.*message"

# Search for any documentation about message types
echo -e "\nChecking documentation..."
fd README.md --exec cat {} \;

Length of output: 16746

hivemind_core/scripts.py (2)

18-21: LGTM: Improved CLI parameter handling

The conversion from positional arguments to named options enhances usability by:

  • Making all parameters optional with clear names
  • Allowing parameters to be specified in any order
  • Following click's best practices for command-line interfaces

Line range hint 63-117: Missing implementation for default b64_audio allowance

The PR objective is to eliminate the need for users to run hivemind-core allow-msg "speak:b64_audio", but the current implementation still requires explicit allowance. Consider:

  1. Modifying the ClientDatabase to include "speak:b64_audio" in the default allowed_types when creating new clients
  2. Adding a migration to add "speak:b64_audio" to existing clients' allowed_types

Let's verify if any default message types are currently set:

Would you like me to propose an implementation for setting default allowed message types?

@JarbasAl JarbasAl merged commit 7270ae0 into dev Oct 23, 2024
1 of 6 checks passed
@JarbasAl JarbasAl deleted the b64default branch October 23, 2024 15:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant