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

Load metadata from stream instead of headers. #31

Merged
merged 3 commits into from
Jul 20, 2024
Merged

Conversation

jmoseley
Copy link
Contributor

@jmoseley jmoseley commented Jul 19, 2024

  • Pass parameter to indicate to the API to return a metadata message in the stream instead of putting user content in the headers.
  • Parse this metadata when processing the stream.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved handling of HTTP response headers by introducing base64 encoding/decoding for content headers.
    • Added support for decoding commands and title headers from base64 format.
    • Enhanced content processing by including comprehensive metadata attributes, providing additional context with processed content.
  • Chores

    • Updated package version to 0.0.5.

@jmoseley jmoseley requested a review from EvanBoyle July 19, 2024 03:41
Copy link

coderabbitai bot commented Jul 19, 2024

Walkthrough

The recent updates enhance the Content class in content.ts, improving the management of base64-encoded HTTP response headers and introducing a structured ContentMetadata type. Additionally, the processStream function now returns both content and associated metadata, enriching the data handling capabilities. The version in package.json has been updated from 0.0.4 to 0.0.5, reflecting these enhancements.

Changes

File Change Summary
content.ts Enhanced handling of base64 HTTP response headers; added ContentMetadata type and several properties for metadata.
package.json Updated package version from 0.0.4 to 0.0.5.
chat.ts Modified promise response handling in Chat class to destructure the content from an array.
utils/streaming.ts Updated processStream function signature to include metadata, changing return type to a tuple with content and metadata.

Poem

A rabbit hops through bytes and code,
To make your data light and bold.
With base64, it dances bright,
Decoding headers, day and night.
Version bumped, a new delight,
In fields of code, we take our flight.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2783a4 and 9869f1f.

Files selected for processing (2)
  • content.ts (5 hunks)
  • package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Additional comments not posted (5)
content.ts (5)

197-197: LGTM!

The addition of base64encodeContentHeaders: true ensures that headers containing user-provided content are base64 encoded.


211-212: LGTM!

The commands header is correctly decoded from base64 and parsed into JSON.


322-322: LGTM!

The addition of base64encodeContentHeaders: true ensures that headers containing user-provided content are base64 encoded.


331-332: LGTM!

The commands header is correctly decoded from base64 and parsed into JSON.


Line range hint 334-348:
LGTM!

The title header is correctly decoded from base64 and assigned to _title.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9869f1f and 2ed583d.

Files selected for processing (3)
  • chat.ts (2 hunks)
  • content.ts (3 hunks)
  • utils/streaming.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • content.ts
Additional comments not posted (6)
utils/streaming.ts (4)

13-14: Initialize metadata variable.

The metadata variable is initialized as undefined. This ensures that the function can handle cases where no metadata is present.


48-49: Capture metadata from the stream.

The logic to capture metadata from the stream is correctly implemented. The metadata variable is assigned the value of json.metadata when the message type is "metadata".


64-64: Return content and metadata.

The function now returns a tuple containing the full content and the captured metadata. This change aligns with the updated function signature and enhances the function's utility.


3-8: Update the function signature and return type.

The function signature has been updated to accept a generic type parameter Metadata and return a tuple containing a string and optional metadata. Ensure that all calls to processStream in the codebase are updated to handle the new return type.

Verification successful

Update the function signature and return type.

The function calls to processStream have been correctly updated to match the new signature and return type. No further action is required.

  • content.ts
  • chat.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `processStream` match the new signature and return type.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type js -A 5 $'processStream'

Length of output: 182


Script:

#!/bin/bash
# Description: Verify all function calls to `processStream` match the new signature and return type.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --debug -A 5 $'processStream'

Length of output: 5249

chat.ts (2)

153-153: Destructure the response from the promise.

The function signature for the .then() method has been altered to destructure the first element of the resolved array. This change ensures that the content variable correctly references the first item of the resolved array.


299-299: Destructure the response from the promise.

The function signature for the .then() method has been altered to destructure the first element of the resolved array. This change ensures that the content variable correctly references the first item of the resolved array.

@jmoseley jmoseley changed the title Handle base64 encoded content headers Load metadata from stream instead of headers. Jul 20, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ed583d and c8380a0.

Files selected for processing (1)
  • utils/streaming.ts (3 hunks)
Additional comments not posted (4)
utils/streaming.ts (4)

3-8: LGTM! The function signature change enhances functionality.

The addition of the generic type parameter Metadata and the updated return type to include metadata enhances the function's capability to handle additional data in a type-safe manner.


13-14: LGTM! The initialization of the metadata variable is appropriate.

The metadata variable is correctly initialized to undefined to store the metadata extracted from the stream.


48-49: LGTM! The handling of metadata in the stream is well-implemented.

The logic to handle messages of type "metadata" and assign the relevant data to the metadata variable enhances the function's utility by capturing additional information from the stream.


64-64: LGTM! The updated return statement is consistent with the changes.

The return statement has been correctly updated to return both the full content and the metadata, aligning with the changes made to the function signature and the handling of metadata.

@jmoseley jmoseley merged commit 9305641 into main Jul 20, 2024
3 checks passed
@jmoseley jmoseley deleted the jeremy/base64_headers branch July 20, 2024 16:25
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