-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(client-reddit): Eliza client for reddit #2538
base: develop
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughA new Reddit plugin for the Eliza framework has been developed, introducing comprehensive functionality for interacting with Reddit. The plugin includes actions for creating posts, managing credentials through a provider, and defining type interfaces for Reddit-related data structures. The implementation supports post creation, credential management, and provides a robust testing suite to ensure reliable functionality across different scenarios. Changes
Finishing Touches
🪧 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: 7
🧹 Nitpick comments (5)
packages/plugin-reddit/src/providers/redditProvider.ts (1)
13-15
: Improve error messaging for missing credentialsSpecify which credential is missing in the error message for better debugging.
- throw new Error("Missing Reddit credentials"); + const missing = [ + !clientId && "REDDIT_CLIENT_ID", + !clientSecret && "REDDIT_CLIENT_SECRET", + !refreshToken && "REDDIT_REFRESH_TOKEN", + !userAgent && "REDDIT_USER_AGENT" + ].filter(Boolean).join(", "); + throw new Error(`Missing Reddit credentials: ${missing}`);packages/plugin-reddit/tests/setup.ts (1)
4-9
: Enhance mock client with error scenariosAdd mock implementations for common Reddit API errors:
- Rate limiting
- Invalid credentials
- Subreddit restrictions
export const mockRedditClient = { submitSelfpost: vi.fn(), getSubreddit: vi.fn(), getSubmission: vi.fn(), getComment: vi.fn(), + // Add error scenario methods + throwRateLimitError: vi.fn().mockRejectedValue(new Error('Rate limit exceeded')), + throwAuthError: vi.fn().mockRejectedValue(new Error('Invalid credentials')), + throwSubredditError: vi.fn().mockRejectedValue(new Error('Subreddit restricted')) };packages/plugin-reddit/src/actions/post.ts (1)
25-35
: Enhance error handling with specific error types.The current error handling is too generic. Consider handling specific Reddit API errors (rate limits, permissions, etc.).
try { await reddit.submitSelfpost({ subredditName: subreddit, title: title, text: content }); return true; } catch (error) { - console.error("Failed to create Reddit post:", error); + if (error.name === 'RateLimitError') { + console.error("Rate limit exceeded:", error.message); + } else if (error.name === 'NoSuchSubredditError') { + console.error("Subreddit not found:", error.message); + } else { + console.error("Failed to create Reddit post:", error); + } return false; }packages/plugin-reddit/tests/actions/post.test.ts (1)
5-69
: Add test cases for message content validation.The test suite needs additional cases to cover message parsing and specific Reddit API errors.
+ it('should fail validation with empty message content', async () => { + const emptyMessage = { ...mockMemory, content: { text: '' } }; + const result = await createPost.validate(mockRuntime, emptyMessage); + expect(result).toBe(false); + }); + + it('should handle rate limit errors', async () => { + const rateLimitError = new Error('Rate limit exceeded'); + rateLimitError.name = 'RateLimitError'; + mockRedditClient.submitSelfpost.mockRejectedValueOnce(rateLimitError); + const result = await createPost.handler(mockRuntime, mockMemory, {}, {}); + expect(result).toBe(false); + });packages/plugin-reddit/tests/providers/redditProvider.test.ts (1)
47-59
: Add rate limit handling test cases.Include test cases for Reddit API rate limiting scenarios.
+ it('should handle rate limit errors', async () => { + const rateLimitError = new Error('Rate limit exceeded'); + rateLimitError.name = 'RateLimitError'; + vi.mock('snoowrap', () => ({ + default: vi.fn().mockImplementation(() => { + throw rateLimitError; + }), + })); + await expect( + redditProvider.get(mockRuntime) + ).rejects.toThrow('Rate limit exceeded'); + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/plugin-reddit/package.json
(1 hunks)packages/plugin-reddit/src/actions/post.ts
(1 hunks)packages/plugin-reddit/src/index.ts
(1 hunks)packages/plugin-reddit/src/providers/redditProvider.ts
(1 hunks)packages/plugin-reddit/src/types/index.ts
(1 hunks)packages/plugin-reddit/tests/actions/post.test.ts
(1 hunks)packages/plugin-reddit/tests/providers/redditProvider.test.ts
(1 hunks)packages/plugin-reddit/tests/setup.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/plugin-reddit/package.json
[error] 9-9: expected ,
but instead found // Reddit API wrapper
Remove // Reddit API wrapper
(parse)
🪛 GitHub Actions: Integration Tests
packages/plugin-reddit/package.json
[error] 9-9: JSON parse error: Expected ',' or '}' after property value at column 28
🪛 GitHub Actions: smoke-test
packages/plugin-reddit/package.json
[error] 9-9: JSON parse error: Expected ',' or '}' after property value at line 9 column 28
[warning] Unsupported engine: Node.js version mismatch. Wanted: 23.3.0, current: 23.6.0
[warning] Local package.json exists, but node_modules is missing. Dependencies need to be installed
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Freytes, @coderabbitai we moved from |
@wtfsayo i found several files using (_/) 🔗 analysis chain @wtfsayo thanks for catching that! i'll make sure to use (_/) 🏁 scripts executed the following scripts were executed for the analysis: script:
length of output: 771 ✏️ learnings added
✅ Actions performedReview triggered.
|
@elizaos/client-reddit
A powerful Reddit client plugin for the Eliza framework that enables AI agents to interact with Reddit through posting, commenting, and voting capabilities.
Features
Installation
Or using yarn:
Configuration
Required Environment Variables
Optional Configuration
Usage
As an Eliza Plugin
Direct Usage
Available Actions
Create Post
Create Comment
Vote
Error Handling
The client includes built-in error handling for common Reddit API issues:
Errors are logged and can be caught using standard try/catch blocks.
Powershell Script required to make an OAuth Key:
Please perform the following prior to generating an OAuth Key:
Summary by CodeRabbit
New Features
New Interfaces
Testing
Documentation