-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(x): add 28 new X API v2 tool integrations and expand OAuth scopes #3365
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e10721c
feat(x): add 28 new X API v2 tool integrations and expand OAuth scopes
waleedlatif1 ec7c216
fix(x): add missing nextToken param to search tweets and fix XCreateT…
waleedlatif1 7107fbb
fix(x): correct API spec issues in retweeted_by, quote_tweets, person…
waleedlatif1 d86838e
fix(x): add missing newestId and oldestId to error meta in get_liked_…
waleedlatif1 e2804ad
fix(x): add missing newestId/oldestId to get_liked_tweets success bra…
waleedlatif1 514a56d
fix(x): add error handling to create_tweet and delete_tweet transform…
waleedlatif1 fa747e5
fix(x): add error handling and logger to all X tools
waleedlatif1 404e51b
fix(x): revert block requiredScopes to match current operations
waleedlatif1 e1c922e
feat(x): update block to support all 28 new X API v2 tools
waleedlatif1 95fbcb2
fix(x): add missing text output and fix hiddenResult output key mismatch
waleedlatif1 d0a1f25
docs(x): regenerate docs for all 28 new X API v2 tools
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import type { ToolConfig } from '@/tools/types' | ||
| import type { XCreateBookmarkParams, XCreateBookmarkResponse } from '@/tools/x/types' | ||
|
|
||
| const logger = createLogger('XCreateBookmarkTool') | ||
|
|
||
| export const xCreateBookmarkTool: ToolConfig<XCreateBookmarkParams, XCreateBookmarkResponse> = { | ||
| id: 'x_create_bookmark', | ||
| name: 'X Create Bookmark', | ||
| description: 'Bookmark a tweet for the authenticated user', | ||
| version: '1.0.0', | ||
|
|
||
| oauth: { | ||
| required: true, | ||
| provider: 'x', | ||
| }, | ||
|
|
||
| params: { | ||
| accessToken: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'hidden', | ||
| description: 'X OAuth access token', | ||
| }, | ||
| userId: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'user-or-llm', | ||
| description: 'The authenticated user ID', | ||
| }, | ||
| tweetId: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'user-or-llm', | ||
| description: 'The tweet ID to bookmark', | ||
| }, | ||
| }, | ||
|
|
||
| request: { | ||
| url: (params) => `https://api.x.com/2/users/${params.userId.trim()}/bookmarks`, | ||
| method: 'POST', | ||
| headers: (params) => ({ | ||
| Authorization: `Bearer ${params.accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }), | ||
| body: (params) => ({ | ||
| tweet_id: params.tweetId.trim(), | ||
| }), | ||
| }, | ||
|
|
||
| transformResponse: async (response) => { | ||
| const data = await response.json() | ||
|
|
||
| if (!data.data) { | ||
| logger.error('X Create Bookmark API Error:', JSON.stringify(data, null, 2)) | ||
| return { | ||
| success: false, | ||
| error: data.errors?.[0]?.detail || 'Failed to bookmark tweet', | ||
| output: { | ||
| bookmarked: false, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| output: { | ||
| bookmarked: data.data.bookmarked ?? false, | ||
| }, | ||
| } | ||
| }, | ||
|
|
||
| outputs: { | ||
| bookmarked: { | ||
| type: 'boolean', | ||
| description: 'Whether the tweet was successfully bookmarked', | ||
| }, | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import type { ToolConfig } from '@/tools/types' | ||
| import type { XCreateTweetParams, XCreateTweetResponse } from '@/tools/x/types' | ||
|
|
||
| const logger = createLogger('XCreateTweetTool') | ||
|
|
||
| export const xCreateTweetTool: ToolConfig<XCreateTweetParams, XCreateTweetResponse> = { | ||
| id: 'x_create_tweet', | ||
| name: 'X Create Tweet', | ||
| description: 'Create a new tweet, reply, or quote tweet on X', | ||
| version: '1.0.0', | ||
|
|
||
| oauth: { | ||
| required: true, | ||
| provider: 'x', | ||
| }, | ||
|
|
||
| params: { | ||
| accessToken: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'hidden', | ||
| description: 'X OAuth access token', | ||
| }, | ||
| text: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'user-or-llm', | ||
| description: 'The text content of the tweet (max 280 characters)', | ||
| }, | ||
| replyToTweetId: { | ||
| type: 'string', | ||
| required: false, | ||
| visibility: 'user-or-llm', | ||
| description: 'Tweet ID to reply to', | ||
| }, | ||
| quoteTweetId: { | ||
| type: 'string', | ||
| required: false, | ||
| visibility: 'user-or-llm', | ||
| description: 'Tweet ID to quote', | ||
| }, | ||
| mediaIds: { | ||
| type: 'string', | ||
| required: false, | ||
| visibility: 'user-or-llm', | ||
| description: 'Comma-separated media IDs to attach (up to 4)', | ||
| }, | ||
| replySettings: { | ||
| type: 'string', | ||
| required: false, | ||
| visibility: 'user-or-llm', | ||
| description: 'Who can reply: "mentionedUsers", "following", "subscribers", or "verified"', | ||
| }, | ||
| }, | ||
|
|
||
| request: { | ||
| url: 'https://api.x.com/2/tweets', | ||
| method: 'POST', | ||
| headers: (params) => ({ | ||
| Authorization: `Bearer ${params.accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }), | ||
| body: (params) => { | ||
| const body: Record<string, unknown> = { | ||
| text: params.text, | ||
| } | ||
|
|
||
| if (params.replyToTweetId) { | ||
| body.reply = { in_reply_to_tweet_id: params.replyToTweetId.trim() } | ||
| } | ||
|
|
||
| if (params.quoteTweetId) { | ||
| body.quote_tweet_id = params.quoteTweetId.trim() | ||
| } | ||
|
|
||
| if (params.mediaIds) { | ||
| const ids = params.mediaIds | ||
| .split(',') | ||
| .map((id) => id.trim()) | ||
| .filter(Boolean) | ||
| if (ids.length > 0) { | ||
| body.media = { media_ids: ids } | ||
| } | ||
| } | ||
|
|
||
| if (params.replySettings) { | ||
| body.reply_settings = params.replySettings | ||
| } | ||
|
|
||
| return body | ||
| }, | ||
| }, | ||
|
|
||
| transformResponse: async (response) => { | ||
| const data = await response.json() | ||
|
|
||
| if (!data.data) { | ||
| logger.error('X Create Tweet API Error:', JSON.stringify(data, null, 2)) | ||
| return { | ||
| success: false, | ||
| error: data.errors?.[0]?.detail || 'Failed to create tweet', | ||
| output: { | ||
| id: '', | ||
| text: '', | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| output: { | ||
| id: data.data.id ?? '', | ||
| text: data.data.text ?? '', | ||
| }, | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| outputs: { | ||
| id: { | ||
| type: 'string', | ||
| description: 'The ID of the created tweet', | ||
| }, | ||
| text: { | ||
| type: 'string', | ||
| description: 'The text of the created tweet', | ||
| }, | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import type { ToolConfig } from '@/tools/types' | ||
| import type { XDeleteBookmarkParams, XDeleteBookmarkResponse } from '@/tools/x/types' | ||
|
|
||
| const logger = createLogger('XDeleteBookmarkTool') | ||
|
|
||
| export const xDeleteBookmarkTool: ToolConfig<XDeleteBookmarkParams, XDeleteBookmarkResponse> = { | ||
| id: 'x_delete_bookmark', | ||
| name: 'X Delete Bookmark', | ||
| description: "Remove a tweet from the authenticated user's bookmarks", | ||
| version: '1.0.0', | ||
|
|
||
| oauth: { | ||
| required: true, | ||
| provider: 'x', | ||
| }, | ||
|
|
||
| params: { | ||
| accessToken: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'hidden', | ||
| description: 'X OAuth access token', | ||
| }, | ||
| userId: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'user-or-llm', | ||
| description: 'The authenticated user ID', | ||
| }, | ||
| tweetId: { | ||
| type: 'string', | ||
| required: true, | ||
| visibility: 'user-or-llm', | ||
| description: 'The tweet ID to remove from bookmarks', | ||
| }, | ||
| }, | ||
|
|
||
| request: { | ||
| url: (params) => | ||
| `https://api.x.com/2/users/${params.userId.trim()}/bookmarks/${params.tweetId.trim()}`, | ||
| method: 'DELETE', | ||
| headers: (params) => ({ | ||
| Authorization: `Bearer ${params.accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }), | ||
| }, | ||
|
|
||
| transformResponse: async (response) => { | ||
| const data = await response.json() | ||
|
|
||
| if (!data.data) { | ||
| logger.error('X Delete Bookmark API Error:', JSON.stringify(data, null, 2)) | ||
| return { | ||
| success: false, | ||
| error: data.errors?.[0]?.detail || 'Failed to remove bookmark', | ||
| output: { | ||
| bookmarked: false, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| output: { | ||
| bookmarked: data.data.bookmarked ?? false, | ||
| }, | ||
| } | ||
| }, | ||
|
|
||
| outputs: { | ||
| bookmarked: { | ||
| type: 'boolean', | ||
| description: 'Whether the tweet is still bookmarked (should be false after deletion)', | ||
| }, | ||
| }, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.