Skip to content

Commit 7107fbb

Browse files
committed
fix(x): correct API spec issues in retweeted_by, quote_tweets, personalized_trends, and usage tools
1 parent ec7c216 commit 7107fbb

File tree

5 files changed

+85
-19
lines changed

5 files changed

+85
-19
lines changed

apps/sim/tools/x/get_personalized_trends.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { createLogger } from '@sim/logger'
22
import type { ToolConfig } from '@/tools/types'
3-
import type { XGetPersonalizedTrendsParams, XTrendListResponse } from '@/tools/x/types'
4-
import { transformTrend } from '@/tools/x/types'
3+
import type { XGetPersonalizedTrendsParams, XPersonalizedTrendListResponse } from '@/tools/x/types'
4+
import { transformPersonalizedTrend } from '@/tools/x/types'
55

66
const logger = createLogger('XGetPersonalizedTrendsTool')
77

88
export const xGetPersonalizedTrendsTool: ToolConfig<
99
XGetPersonalizedTrendsParams,
10-
XTrendListResponse
10+
XPersonalizedTrendListResponse
1111
> = {
1212
id: 'x_get_personalized_trends',
1313
name: 'X Get Personalized Trends',
@@ -29,7 +29,7 @@ export const xGetPersonalizedTrendsTool: ToolConfig<
2929
},
3030

3131
request: {
32-
url: 'https://api.x.com/2/users/personalized_trends',
32+
url: 'https://api.x.com/2/users/personalized_trends?personalized_trend.fields=category,post_count,trend_name,trending_since',
3333
method: 'GET',
3434
headers: (params) => ({
3535
Authorization: `Bearer ${params.accessToken}`,
@@ -54,7 +54,7 @@ export const xGetPersonalizedTrendsTool: ToolConfig<
5454
return {
5555
success: true,
5656
output: {
57-
trends: data.data.map(transformTrend),
57+
trends: data.data.map(transformPersonalizedTrend),
5858
},
5959
}
6060
},
@@ -67,9 +67,19 @@ export const xGetPersonalizedTrendsTool: ToolConfig<
6767
type: 'object',
6868
properties: {
6969
trendName: { type: 'string', description: 'Name of the trending topic' },
70-
tweetCount: {
70+
postCount: {
7171
type: 'number',
72-
description: 'Number of tweets for this trend',
72+
description: 'Number of posts for this trend',
73+
optional: true,
74+
},
75+
category: {
76+
type: 'string',
77+
description: 'Category of the trend',
78+
optional: true,
79+
},
80+
trendingSince: {
81+
type: 'string',
82+
description: 'ISO 8601 timestamp of when the topic started trending',
7383
optional: true,
7484
},
7585
},

apps/sim/tools/x/get_quote_tweets.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ export const xGetQuoteTweetsTool: ToolConfig<XGetQuoteTweetsParams, XTweetListRe
4141
visibility: 'user-or-llm',
4242
description: 'Pagination token for next page',
4343
},
44-
exclude: {
45-
type: 'string',
46-
required: false,
47-
visibility: 'user-or-llm',
48-
description: 'Comma-separated types to exclude: "retweets", "replies"',
49-
},
5044
},
5145

5246
request: {
@@ -62,7 +56,6 @@ export const xGetQuoteTweetsTool: ToolConfig<XGetQuoteTweetsParams, XTweetListRe
6256
queryParams.append('max_results', max.toString())
6357
}
6458
if (params.paginationToken) queryParams.append('pagination_token', params.paginationToken)
65-
if (params.exclude) queryParams.append('exclude', params.exclude)
6659

6760
return `https://api.x.com/2/tweets/${params.tweetId.trim()}/quote_tweets?${queryParams.toString()}`
6861
},

apps/sim/tools/x/get_retweeted_by.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export const xGetRetweetedByTool: ToolConfig<XGetRetweetedByParams, XUserListRes
5050
})
5151

5252
if (params.maxResults) {
53-
queryParams.append('max_results', Number(params.maxResults).toString())
53+
const max = Math.max(1, Math.min(100, Number(params.maxResults)))
54+
queryParams.append('max_results', max.toString())
5455
}
5556
if (params.paginationToken) queryParams.append('pagination_token', params.paginationToken)
5657

apps/sim/tools/x/get_usage.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
3333
request: {
3434
url: (params) => {
3535
const queryParams = new URLSearchParams({
36-
'usage.fields': 'cap_reset_day,daily_project_usage,project_cap,project_id,project_usage',
36+
'usage.fields':
37+
'cap_reset_day,daily_client_app_usage,daily_project_usage,project_cap,project_id,project_usage',
3738
})
3839

3940
if (params.days) {
@@ -63,6 +64,7 @@ export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
6364
projectCap: null,
6465
projectUsage: null,
6566
dailyProjectUsage: [],
67+
dailyClientAppUsage: [],
6668
},
6769
}
6870
}
@@ -80,6 +82,15 @@ export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
8082
usage: u.usage ?? 0,
8183
})
8284
),
85+
dailyClientAppUsage: (data.data.daily_client_app_usage ?? []).map(
86+
(app: { client_app_id: string; usage: { date: string; usage: number }[] }) => ({
87+
clientAppId: String(app.client_app_id ?? ''),
88+
usage: (app.usage ?? []).map((u: { date: string; usage: number }) => ({
89+
date: u.date,
90+
usage: u.usage ?? 0,
91+
})),
92+
})
93+
),
8394
},
8495
}
8596
},
@@ -106,7 +117,7 @@ export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
106117
},
107118
dailyProjectUsage: {
108119
type: 'array',
109-
description: 'Daily usage breakdown',
120+
description: 'Daily project usage breakdown',
110121
items: {
111122
type: 'object',
112123
properties: {
@@ -115,5 +126,26 @@ export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
115126
},
116127
},
117128
},
129+
dailyClientAppUsage: {
130+
type: 'array',
131+
description: 'Daily per-app usage breakdown',
132+
items: {
133+
type: 'object',
134+
properties: {
135+
clientAppId: { type: 'string', description: 'Client application ID' },
136+
usage: {
137+
type: 'array',
138+
description: 'Daily usage entries for this app',
139+
items: {
140+
type: 'object',
141+
properties: {
142+
date: { type: 'string', description: 'Usage date in ISO 8601 format' },
143+
usage: { type: 'number', description: 'Number of tweets consumed' },
144+
},
145+
},
146+
},
147+
},
148+
},
149+
},
118150
},
119151
}

apps/sim/tools/x/types.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,41 @@ export const transformUser = (user: any): XUser => ({
186186
})
187187

188188
/**
189-
* Trend object from X API
189+
* Trend object from X API (WOEID trends)
190190
*/
191191
export interface XTrend {
192192
trendName: string
193193
tweetCount: number | null
194194
}
195195

196196
/**
197-
* Transforms raw X API trend data into the XTrend format
197+
* Personalized trend object from X API
198+
*/
199+
export interface XPersonalizedTrend {
200+
trendName: string
201+
postCount: number | null
202+
category: string | null
203+
trendingSince: string | null
204+
}
205+
206+
/**
207+
* Transforms raw X API trend data (WOEID) into the XTrend format
198208
*/
199209
export const transformTrend = (trend: any): XTrend => ({
200210
trendName: trend.trend_name ?? trend.name ?? '',
201211
tweetCount: trend.tweet_count ?? null,
202212
})
203213

214+
/**
215+
* Transforms raw X API personalized trend data into the XPersonalizedTrend format
216+
*/
217+
export const transformPersonalizedTrend = (trend: any): XPersonalizedTrend => ({
218+
trendName: trend.trend_name ?? '',
219+
postCount: trend.post_count ?? null,
220+
category: trend.category ?? null,
221+
trendingSince: trend.trending_since ?? null,
222+
})
223+
204224
// --- New Tool Parameter Interfaces ---
205225

206226
export interface XSearchTweetsParams extends XBaseParams {
@@ -432,6 +452,10 @@ export interface XGetUsageResponse extends ToolResponse {
432452
projectCap: number | null
433453
projectUsage: number | null
434454
dailyProjectUsage: Array<{ date: string; usage: number }>
455+
dailyClientAppUsage: Array<{
456+
clientAppId: string
457+
usage: Array<{ date: string; usage: number }>
458+
}>
435459
}
436460
}
437461

@@ -487,3 +511,9 @@ export interface XTrendListResponse extends ToolResponse {
487511
trends: XTrend[]
488512
}
489513
}
514+
515+
export interface XPersonalizedTrendListResponse extends ToolResponse {
516+
output: {
517+
trends: XPersonalizedTrend[]
518+
}
519+
}

0 commit comments

Comments
 (0)