-
Notifications
You must be signed in to change notification settings - Fork 514
feat: Custom encode and decode for thread messages in cloud #1745
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
base: main
Are you sure you want to change the base?
feat: Custom encode and decode for thread messages in cloud #1745
Conversation
add custom encode and decode message
@lawnzapper is attempting to deploy a commit to the assistant-ui Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Implemented custom message encoding/decoding functionality in AssistantCloud to support external cloud providers handling various data types beyond text content.
- Missing imports for
auiV0Encode
andauiV0Decode
in/packages/react/src/cloud/AssistantCloud.tsx
- Potential null reference issue with
cloudRef.current
in/packages/react/src/cloud/AssistantCloudThreadHistoryAdapter.tsx
- Type safety concerns in
AssistantCloudConfig
interface for encode/decode function definitions - Consider binding encode/decode methods in constructor to prevent context loss
- Need validation for encoded message format compatibility with 'aui/v0' standard
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
2 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
📝 Documentation updates detected! You can review documentation updates here |
WalkthroughThe changes add two new public properties, 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
packages/react/src/cloud/AssistantCloud.tsx
(1 hunks)packages/react/src/cloud/AssistantCloudThreadHistoryAdapter.tsx
(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/react/src/cloud/AssistantCloud.tsx (3)
packages/react/src/cloud/AssistantCloudAPI.tsx (2) (2)
AssistantCloudConfig
(8-21)AssistantCloudAPI
(37-121)packages/react/src/cloud/auiV0.ts (2) (2)
auiV0Encode
(63-131)auiV0Decode
(133-154)packages/react/src/cloud/AssistantCloudThreads.tsx (1) (1)
AssistantCloudThreads
(45-79)
🔇 Additional comments (5)
packages/react/src/cloud/AssistantCloudThreadHistoryAdapter.tsx (5)
18-20
: Good refactoring to improve code readabilityCreating a local variable for
this.cloudRef.current
improves readability and avoids repeated access to the same reference.
26-26
: Direct use of cloud.encodeMessage improves encapsulationSwitching from direct calls to encoding functions to using the cloud instance's methods enhances encapsulation and allows for custom encoding logic to be provided through configuration.
42-43
: Simplified message retrieval with local cloud variableUsing the local
cloud
variable streamlines the code and makes it more readable.
50-50
: Using cloud.decodeMessage allows for custom decodingThis change properly uses the cloud instance's decoding method instead of hard-coding to
auiV0Decode
, enabling custom decoding logic to be used when provided.
38-54
: Verify type safety with the decodeMessage functionThe code assumes that
cloud.decodeMessage
can be directly passed tomap()
, which requires it to maintain its function context.You should ensure that
cloud.decodeMessage
properly maintains itsthis
context when used directly in a map function. Consider using a bound function or arrow function to ensure correct behavior:- .map(cloud.decodeMessage) + .map((message) => cloud.decodeMessage(message))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
packages/react/src/cloud/AssistantCloud.tsx (1)
11-12
: 🧹 Nitpick (assertive)Missing TypeScript type annotations
The new properties
encodeMessage
anddecodeMessage
should have explicit TypeScript type annotations to ensure type safety and improve code documentation.- public readonly encodeMessage; - public readonly decodeMessage; + public readonly encodeMessage: (message: ThreadMessage) => any; + public readonly decodeMessage: (cloudMessage: CloudMessage & { format: "aui/v0" }) => ExportedMessageRepositoryItem;You'll need to import the necessary types (
ThreadMessage
,CloudMessage
, andExportedMessageRepositoryItem
) at the top of the file.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (1)
packages/react/src/cloud/AssistantCloud.tsx
(1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/react/src/cloud/AssistantCloud.tsx (3)
packages/react/src/cloud/AssistantCloudAPI.tsx (2) (2)
AssistantCloudConfig
(8-21)AssistantCloudAPI
(37-121)packages/react/src/cloud/auiV0.ts (2) (2)
auiV0Encode
(63-131)auiV0Decode
(133-154)packages/react/src/cloud/AssistantCloudThreads.tsx (1) (1)
AssistantCloudThreads
(45-79)
🔇 Additional comments (1)
packages/react/src/cloud/AssistantCloud.tsx (1)
5-5
: Import statement resolves previous issueGood addition of the missing imports for
auiV0Decode
andauiV0Encode
. This resolves the issue identified in previous reviews where these functions were being used but not imported.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (1)
packages/react/src/cloud/AssistantCloudThreadHistoryAdapter.tsx
(2 hunks)
🔇 Additional comments (4)
packages/react/src/cloud/AssistantCloudThreadHistoryAdapter.tsx (4)
18-19
: Good addition of null check for cloud reference.The initialization of a local variable and subsequent null check prevents potential runtime errors by ensuring the cloud reference is properly initialized before proceeding.
20-21
: Improved code organization with local variable.Using the local
cloud
variable makes the code more readable and maintainable by reducing repeated access to the nested property.
27-27
: Properly using the cloud instance's encodeMessage function.The code now correctly uses the custom encode function from the cloud instance, aligning with the PR objective to support custom encoding for thread messages.
51-51
: Using cloud instance's decodeMessage method properly.The code correctly leverages the cloud instance's decodeMessage method for consistent handling of thread messages.
Note: A previous review comment suggested using
.bind(cloud)
here, but as you clarified, the context is not needed for this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the changes, added some fixes and accepted a couple of suggestions
👋 Hey! As a free user, you're receiving reviews for every 5th PR. Upgrade to get reviews on every pull request and boost your code quality! Learn more here 🚀 |
Pull request summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/react/src/cloud/AssistantCloud.tsx (1)
11-12
: 🛠️ Refactor suggestionAdd TypeScript type annotations to the encode/decode properties.
These properties should have proper type annotations to maintain code quality and make the API clearer to consumers.
Based on the learning that "encodeMessage can be strictly typed but decodeMessage needs to be more flexible", I recommend:
- public readonly encodeMessage; - public readonly decodeMessage; + public readonly encodeMessage: (message: ThreadMessage) => any; + public readonly decodeMessage: (cloudMessage: CloudMessage) => ExportedMessageRepositoryItem;You'll need to add imports for the relevant types.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (1)
packages/react/src/cloud/AssistantCloud.tsx
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: lawnzapper
PR: assistant-ui/assistant-ui#1745
File: packages/react/src/cloud/AssistantCloud.tsx:18-19
Timestamp: 2025-03-21T17:11:08.624Z
Learning: In the Assistant UI codebase, when defining encode/decode functions for cloud messages, encodeMessage can be strictly typed with a specific input type (ThreadMessage), but decodeMessage needs to be more flexible to handle different message formats beyond the initial "aui/v0" format.
packages/react/src/cloud/AssistantCloud.tsx (1)
Learnt from: lawnzapper
PR: assistant-ui/assistant-ui#1745
File: packages/react/src/cloud/AssistantCloud.tsx:18-19
Timestamp: 2025-03-21T17:11:08.624Z
Learning: In the Assistant UI codebase, when defining encode/decode functions for cloud messages, encodeMessage can be strictly typed with a specific input type (ThreadMessage), but decodeMessage needs to be more flexible to handle different message formats beyond the initial "aui/v0" format.
🧬 Code Definitions (1)
packages/react/src/cloud/AssistantCloud.tsx (2)
packages/react/src/cloud/AssistantCloudAPI.tsx (2) (2)
AssistantCloudConfig
(8-21)AssistantCloudAPI
(37-121)packages/react/src/cloud/auiV0.ts (2) (2)
auiV0Encode
(63-131)auiV0Decode
(133-154)
🔇 Additional comments (2)
packages/react/src/cloud/AssistantCloud.tsx (2)
5-5
: LGTM: Import of encoding/decoding functions added.The import of
auiV0Decode
andauiV0Encode
functions has been added, which properly addresses the previous review comments about missing imports.
16-20
: Verify that AssistantCloudConfig type has been updated to include these properties.The code is accessing
config.encodeMessage
andconfig.decodeMessage
, but based on the provided relevant code snippets, theAssistantCloudConfig
type doesn't include these properties yet.#!/bin/bash # Check if AssistantCloudConfig type has been updated to include encodeMessage and decodeMessage rg "AssistantCloudConfig" --type typescript -A 25
Hello,
I have integrated a custom encoder and decoder for thread messages into the AssistantCloud constructor. This enhancement allows an external cloud provider to manage not just text content, but also attachments or various types of data that need to be stored.
Important
Adds custom encode/decode functions for thread messages in
AssistantCloud
, enhancing data handling flexibility.encodeMessage
anddecodeMessage
toAssistantCloud
constructor for custom message handling.auiV0Encode
andauiV0Decode
if no custom functions provided.AssistantCloudThreads
inAssistantCloud.tsx
now uses custom encode/decode functions.append()
andload()
inAssistantCloudThreadHistoryAdapter.tsx
usecloud.encodeMessage
andcloud.decodeMessage
for message processing.This description was created by
for 4bfc568. It will automatically update as commits are pushed.