6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
152 lines
4.2 KiB
TypeScript
152 lines
4.2 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
import type { XGetUsageParams, XGetUsageResponse } from '@/tools/x/types'
|
|
|
|
const logger = createLogger('XGetUsageTool')
|
|
|
|
export const xGetUsageTool: ToolConfig<XGetUsageParams, XGetUsageResponse> = {
|
|
id: 'x_get_usage',
|
|
name: 'X Get Usage',
|
|
description: 'Get the API usage data for your X project',
|
|
version: '1.0.0',
|
|
|
|
oauth: {
|
|
required: true,
|
|
provider: 'x',
|
|
},
|
|
|
|
params: {
|
|
accessToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'hidden',
|
|
description: 'X OAuth access token',
|
|
},
|
|
days: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Number of days of usage data to return (1-90, default 7)',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
const queryParams = new URLSearchParams({
|
|
'usage.fields':
|
|
'cap_reset_day,daily_client_app_usage,daily_project_usage,project_cap,project_id,project_usage',
|
|
})
|
|
|
|
if (params.days) {
|
|
queryParams.append('days', Number(params.days).toString())
|
|
}
|
|
|
|
return `https://api.x.com/2/usage/tweets?${queryParams.toString()}`
|
|
},
|
|
method: 'GET',
|
|
headers: (params) => ({
|
|
Authorization: `Bearer ${params.accessToken}`,
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response) => {
|
|
const data = await response.json()
|
|
|
|
if (!data.data) {
|
|
logger.error('X Get Usage API Error:', JSON.stringify(data, null, 2))
|
|
return {
|
|
success: false,
|
|
error: data.errors?.[0]?.detail || 'Failed to get usage data',
|
|
output: {
|
|
capResetDay: null,
|
|
projectId: '',
|
|
projectCap: null,
|
|
projectUsage: null,
|
|
dailyProjectUsage: [],
|
|
dailyClientAppUsage: [],
|
|
},
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
capResetDay: data.data.cap_reset_day ?? null,
|
|
projectId: String(data.data.project_id ?? ''),
|
|
projectCap: data.data.project_cap ?? null,
|
|
projectUsage: data.data.project_usage ?? null,
|
|
dailyProjectUsage: (data.data.daily_project_usage?.usage ?? []).map(
|
|
(u: { date: string; usage: number }) => ({
|
|
date: u.date,
|
|
usage: u.usage ?? 0,
|
|
})
|
|
),
|
|
dailyClientAppUsage: (data.data.daily_client_app_usage ?? []).map(
|
|
(app: { client_app_id: string; usage: { date: string; usage: number }[] }) => ({
|
|
clientAppId: String(app.client_app_id ?? ''),
|
|
usage: (app.usage ?? []).map((u: { date: string; usage: number }) => ({
|
|
date: u.date,
|
|
usage: u.usage ?? 0,
|
|
})),
|
|
})
|
|
),
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
capResetDay: {
|
|
type: 'number',
|
|
description: 'Day of month when usage cap resets',
|
|
optional: true,
|
|
},
|
|
projectId: {
|
|
type: 'string',
|
|
description: 'The project ID',
|
|
},
|
|
projectCap: {
|
|
type: 'number',
|
|
description: 'The project tweet consumption cap',
|
|
optional: true,
|
|
},
|
|
projectUsage: {
|
|
type: 'number',
|
|
description: 'Total tweets consumed in current period',
|
|
optional: true,
|
|
},
|
|
dailyProjectUsage: {
|
|
type: 'array',
|
|
description: 'Daily project usage breakdown',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
date: { type: 'string', description: 'Usage date in ISO 8601 format' },
|
|
usage: { type: 'number', description: 'Number of tweets consumed' },
|
|
},
|
|
},
|
|
},
|
|
dailyClientAppUsage: {
|
|
type: 'array',
|
|
description: 'Daily per-app usage breakdown',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
clientAppId: { type: 'string', description: 'Client application ID' },
|
|
usage: {
|
|
type: 'array',
|
|
description: 'Daily usage entries for this app',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
date: { type: 'string', description: 'Usage date in ISO 8601 format' },
|
|
usage: { type: 'number', description: 'Number of tweets consumed' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|