|
1 | 1 | import { RedditIcon } from '@/components/icons' |
2 | | -import { RedditHotPostsResponse } from '@/tools/reddit/types' |
| 2 | +import { RedditHotPostsResponse, RedditPostsResponse, RedditCommentsResponse } from '@/tools/reddit/types' |
3 | 3 | import { BlockConfig } from '../types' |
4 | 4 |
|
5 | | -export const RedditBlock: BlockConfig<RedditHotPostsResponse> = { |
| 5 | +export const RedditBlock: BlockConfig<RedditHotPostsResponse | RedditPostsResponse | RedditCommentsResponse> = { |
6 | 6 | type: 'reddit', |
7 | 7 | name: 'Reddit', |
8 | | - description: 'Fetch popular posts from Reddit', |
| 8 | + description: 'Access Reddit data and content', |
9 | 9 | longDescription: |
10 | | - 'Access Reddit data to retrieve the most popular (hot) posts from any subreddit. Get post titles, content, authors, scores, and more.', |
| 10 | + 'Access Reddit data to retrieve posts and comments from any subreddit. Get post titles, content, authors, scores, comments and more.', |
11 | 11 | category: 'tools', |
12 | 12 | bgColor: '#FF5700', |
13 | 13 | icon: RedditIcon, |
14 | 14 | subBlocks: [ |
15 | | - // Subreddit input |
| 15 | + // Action selection |
| 16 | + { |
| 17 | + id: 'action', |
| 18 | + title: 'Action', |
| 19 | + type: 'dropdown', |
| 20 | + layout: 'full', |
| 21 | + options: [ |
| 22 | + { label: 'Get Posts', id: 'get_posts' }, |
| 23 | + { label: 'Get Comments', id: 'get_comments' } |
| 24 | + ], |
| 25 | + }, |
| 26 | + |
| 27 | + // Common fields - appear for all actions |
16 | 28 | { |
17 | 29 | id: 'subreddit', |
18 | 30 | title: 'Subreddit', |
19 | 31 | type: 'short-input', |
20 | 32 | layout: 'full', |
21 | 33 | placeholder: 'Enter subreddit name (without r/)', |
| 34 | + condition: { |
| 35 | + field: 'action', |
| 36 | + value: ['get_posts', 'get_comments'] |
| 37 | + } |
| 38 | + }, |
| 39 | + |
| 40 | + // Get Posts specific fields |
| 41 | + { |
| 42 | + id: 'sort', |
| 43 | + title: 'Sort By', |
| 44 | + type: 'dropdown', |
| 45 | + layout: 'full', |
| 46 | + options: [ |
| 47 | + { label: 'Hot', id: 'hot' }, |
| 48 | + { label: 'New', id: 'new' }, |
| 49 | + { label: 'Top', id: 'top' }, |
| 50 | + { label: 'Rising', id: 'rising' } |
| 51 | + ], |
| 52 | + condition: { |
| 53 | + field: 'action', |
| 54 | + value: 'get_posts' |
| 55 | + } |
| 56 | + }, |
| 57 | + { |
| 58 | + id: 'time', |
| 59 | + title: 'Time Filter (for Top sort)', |
| 60 | + type: 'dropdown', |
| 61 | + layout: 'full', |
| 62 | + options: [ |
| 63 | + { label: 'Day', id: 'day' }, |
| 64 | + { label: 'Week', id: 'week' }, |
| 65 | + { label: 'Month', id: 'month' }, |
| 66 | + { label: 'Year', id: 'year' }, |
| 67 | + { label: 'All Time', id: 'all' } |
| 68 | + ], |
| 69 | + condition: { |
| 70 | + field: 'action', |
| 71 | + value: 'get_posts', |
| 72 | + and: { |
| 73 | + field: 'sort', |
| 74 | + value: 'top' |
| 75 | + } |
| 76 | + } |
22 | 77 | }, |
23 | | - // Limit input |
24 | 78 | { |
25 | 79 | id: 'limit', |
26 | | - title: 'Number of Top Posts', |
| 80 | + title: 'Number of Posts', |
27 | 81 | type: 'short-input', |
28 | 82 | layout: 'full', |
29 | 83 | placeholder: '10', |
| 84 | + condition: { |
| 85 | + field: 'action', |
| 86 | + value: 'get_posts' |
| 87 | + } |
30 | 88 | }, |
| 89 | + |
| 90 | + // Get Comments specific fields |
| 91 | + { |
| 92 | + id: 'postId', |
| 93 | + title: 'Post ID', |
| 94 | + type: 'short-input', |
| 95 | + layout: 'full', |
| 96 | + placeholder: 'Enter post ID', |
| 97 | + condition: { |
| 98 | + field: 'action', |
| 99 | + value: 'get_comments' |
| 100 | + } |
| 101 | + }, |
| 102 | + { |
| 103 | + id: 'commentSort', |
| 104 | + title: 'Sort Comments By', |
| 105 | + type: 'dropdown', |
| 106 | + layout: 'full', |
| 107 | + options: [ |
| 108 | + { label: 'Confidence', id: 'confidence' }, |
| 109 | + { label: 'Top', id: 'top' }, |
| 110 | + { label: 'New', id: 'new' }, |
| 111 | + { label: 'Controversial', id: 'controversial' }, |
| 112 | + { label: 'Old', id: 'old' }, |
| 113 | + { label: 'Random', id: 'random' }, |
| 114 | + { label: 'Q&A', id: 'qa' } |
| 115 | + ], |
| 116 | + condition: { |
| 117 | + field: 'action', |
| 118 | + value: 'get_comments' |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + id: 'commentLimit', |
| 123 | + title: 'Number of Comments', |
| 124 | + type: 'short-input', |
| 125 | + layout: 'full', |
| 126 | + placeholder: '50', |
| 127 | + condition: { |
| 128 | + field: 'action', |
| 129 | + value: 'get_comments' |
| 130 | + } |
| 131 | + } |
31 | 132 | ], |
32 | 133 | tools: { |
33 | | - access: ['reddit_hot_posts'], |
| 134 | + access: ['reddit_hot_posts', 'reddit_get_posts', 'reddit_get_comments'], |
34 | 135 | config: { |
35 | | - tool: () => 'reddit_hot_posts', |
36 | | - }, |
| 136 | + tool: (inputs) => { |
| 137 | + const action = inputs.action || 'get_posts' |
| 138 | + |
| 139 | + if (action === 'get_comments') { |
| 140 | + return 'reddit_get_comments' |
| 141 | + } |
| 142 | + |
| 143 | + return 'reddit_get_posts' |
| 144 | + }, |
| 145 | + params: (inputs) => { |
| 146 | + const action = inputs.action || 'get_posts' |
| 147 | + |
| 148 | + if (action === 'get_comments') { |
| 149 | + return { |
| 150 | + postId: inputs.postId, |
| 151 | + subreddit: inputs.subreddit, |
| 152 | + sort: inputs.commentSort, |
| 153 | + limit: inputs.commentLimit ? parseInt(inputs.commentLimit) : undefined |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + return { |
| 158 | + subreddit: inputs.subreddit, |
| 159 | + sort: inputs.sort, |
| 160 | + limit: inputs.limit ? parseInt(inputs.limit) : undefined, |
| 161 | + time: inputs.sort === 'top' ? inputs.time : undefined |
| 162 | + } |
| 163 | + } |
| 164 | + } |
37 | 165 | }, |
38 | 166 | inputs: { |
| 167 | + action: { |
| 168 | + type: 'string', |
| 169 | + required: true, |
| 170 | + description: 'The action to perform: get_posts or get_comments', |
| 171 | + }, |
39 | 172 | subreddit: { |
40 | 173 | type: 'string', |
41 | 174 | required: true, |
42 | | - description: 'The name of the subreddit to fetch posts from (without the r/ prefix)', |
| 175 | + description: 'The name of the subreddit to fetch data from (without the r/ prefix)', |
| 176 | + }, |
| 177 | + sort: { |
| 178 | + type: 'string', |
| 179 | + required: true, |
| 180 | + description: 'Sort method for posts: "hot", "new", "top", or "rising" (default: "hot")', |
| 181 | + }, |
| 182 | + time: { |
| 183 | + type: 'string', |
| 184 | + required: false, |
| 185 | + description: 'Time filter for "top" sorted posts: "hour", "day", "week", "month", "year", or "all" (default: "day")', |
43 | 186 | }, |
44 | 187 | limit: { |
45 | 188 | type: 'number', |
46 | 189 | required: false, |
47 | 190 | description: 'Maximum number of posts to return (default: 10, max: 100)', |
48 | 191 | }, |
| 192 | + postId: { |
| 193 | + type: 'string', |
| 194 | + required: true, |
| 195 | + description: 'The ID of the Reddit post to fetch comments from', |
| 196 | + }, |
| 197 | + commentSort: { |
| 198 | + type: 'string', |
| 199 | + required: false, |
| 200 | + description: 'Sort method for comments: "confidence", "top", "new", "controversial", "old", "random", "qa" (default: "confidence")', |
| 201 | + }, |
| 202 | + commentLimit: { |
| 203 | + type: 'number', |
| 204 | + required: false, |
| 205 | + description: 'Maximum number of comments to return (default: 50, max: 100)', |
| 206 | + } |
49 | 207 | }, |
50 | 208 | outputs: { |
51 | 209 | response: { |
52 | 210 | type: { |
53 | 211 | subreddit: 'string', |
54 | 212 | posts: 'json', |
| 213 | + post: 'json', |
| 214 | + comments: 'json' |
55 | 215 | }, |
56 | 216 | }, |
57 | 217 | }, |
|
0 commit comments