Skip to content

Commit a769c31

Browse files
committed
feat(tools): added additional reddit tools, docs
1 parent b2e583c commit a769c31

File tree

7 files changed

+481
-15
lines changed

7 files changed

+481
-15
lines changed

docs/content/docs/tools/reddit.mdx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Reddit
3-
description: Fetch popular posts from Reddit
3+
description: Access Reddit data and content
44
---
55

66
import { BlockInfoCard } from "@/components/ui/block-info-card"
@@ -44,7 +44,7 @@ In Sim Studio, the Reddit integration enables your agents to programmatically ac
4444

4545
## Usage Instructions
4646

47-
Access Reddit data to retrieve the most popular (hot) posts from any subreddit. Get post titles, content, authors, scores, and more.
47+
Access Reddit data to retrieve posts and comments from any subreddit. Get post titles, content, authors, scores, comments and more.
4848

4949

5050

@@ -67,6 +67,50 @@ Fetch the most popular (hot) posts from a specified subreddit.
6767
| --------- | ---- |
6868
| `subreddit` | string |
6969

70+
### `reddit_get_posts`
71+
72+
Fetch posts from a subreddit with different sorting options
73+
74+
#### Input
75+
76+
| Parameter | Type | Required | Description |
77+
| --------- | ---- | -------- | ----------- |
78+
| `subreddit` | string | Yes | The name of the subreddit to fetch posts from \(without the r/ prefix\) |
79+
| `sort` | string | No | Sort method for posts: |
80+
| `limit` | number | No | Maximum number of posts to return \(default: 10, max: 100\) |
81+
| `time` | string | No | Time filter for |
82+
83+
#### Output
84+
85+
| Parameter | Type |
86+
| --------- | ---- |
87+
| `subreddit` | string |
88+
89+
### `reddit_get_comments`
90+
91+
Fetch comments from a specific Reddit post
92+
93+
#### Input
94+
95+
| Parameter | Type | Required | Description |
96+
| --------- | ---- | -------- | ----------- |
97+
| `postId` | string | Yes | The ID of the Reddit post to fetch comments from |
98+
| `subreddit` | string | Yes | The subreddit where the post is located \(without the r/ prefix\) |
99+
| `sort` | string | No | Sort method for comments: |
100+
| `limit` | number | No | Maximum number of comments to return \(default: 50, max: 100\) |
101+
102+
#### Output
103+
104+
| Parameter | Type |
105+
| --------- | ---- |
106+
| `post` | string |
107+
| `title` | string |
108+
| `author` | string |
109+
| `selftext` | string |
110+
| `created_utc` | string |
111+
| `score` | string |
112+
| `permalink` | string |
113+
70114

71115

72116
## Block Configuration
@@ -75,7 +119,7 @@ Fetch the most popular (hot) posts from a specified subreddit.
75119

76120
| Parameter | Type | Required | Description |
77121
| --------- | ---- | -------- | ----------- |
78-
| `subreddit` | string | No | Subreddit - Enter subreddit name \(without r/\) |
122+
| `action` | string | No | Action |
79123

80124

81125

@@ -86,6 +130,8 @@ Fetch the most popular (hot) posts from a specified subreddit.
86130
| `response` | object | Output from response |
87131
|`subreddit` | string | subreddit of the response |
88132
|`posts` | json | posts of the response |
133+
|`post` | json | post of the response |
134+
|`comments` | json | comments of the response |
89135

90136

91137
## Notes

sim/blocks/blocks/reddit.ts

Lines changed: 171 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,217 @@
11
import { RedditIcon } from '@/components/icons'
2-
import { RedditHotPostsResponse } from '@/tools/reddit/types'
2+
import { RedditHotPostsResponse, RedditPostsResponse, RedditCommentsResponse } from '@/tools/reddit/types'
33
import { BlockConfig } from '../types'
44

5-
export const RedditBlock: BlockConfig<RedditHotPostsResponse> = {
5+
export const RedditBlock: BlockConfig<RedditHotPostsResponse | RedditPostsResponse | RedditCommentsResponse> = {
66
type: 'reddit',
77
name: 'Reddit',
8-
description: 'Fetch popular posts from Reddit',
8+
description: 'Access Reddit data and content',
99
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.',
1111
category: 'tools',
1212
bgColor: '#FF5700',
1313
icon: RedditIcon,
1414
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
1628
{
1729
id: 'subreddit',
1830
title: 'Subreddit',
1931
type: 'short-input',
2032
layout: 'full',
2133
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+
}
2277
},
23-
// Limit input
2478
{
2579
id: 'limit',
26-
title: 'Number of Top Posts',
80+
title: 'Number of Posts',
2781
type: 'short-input',
2882
layout: 'full',
2983
placeholder: '10',
84+
condition: {
85+
field: 'action',
86+
value: 'get_posts'
87+
}
3088
},
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+
}
31132
],
32133
tools: {
33-
access: ['reddit_hot_posts'],
134+
access: ['reddit_hot_posts', 'reddit_get_posts', 'reddit_get_comments'],
34135
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+
}
37165
},
38166
inputs: {
167+
action: {
168+
type: 'string',
169+
required: true,
170+
description: 'The action to perform: get_posts or get_comments',
171+
},
39172
subreddit: {
40173
type: 'string',
41174
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")',
43186
},
44187
limit: {
45188
type: 'number',
46189
required: false,
47190
description: 'Maximum number of posts to return (default: 10, max: 100)',
48191
},
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+
}
49207
},
50208
outputs: {
51209
response: {
52210
type: {
53211
subreddit: 'string',
54212
posts: 'json',
213+
post: 'json',
214+
comments: 'json'
55215
},
56216
},
57217
},

0 commit comments

Comments
 (0)