chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
import type {
|
||||
GoogleAdsAdPerformanceParams,
|
||||
GoogleAdsAdPerformanceResponse,
|
||||
} from '@/tools/google_ads/types'
|
||||
import { validateDate, validateDateRange, validateNumericId } from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsAdPerformanceTool: ToolConfig<
|
||||
GoogleAdsAdPerformanceParams,
|
||||
GoogleAdsAdPerformanceResponse
|
||||
> = {
|
||||
id: 'google_ads_ad_performance',
|
||||
name: 'Google Ads Ad Performance',
|
||||
description: 'Get performance metrics for individual ads over a date range',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
customerId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
managerCustomerId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Manager account customer ID (if accessing via manager account)',
|
||||
},
|
||||
campaignId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter by campaign ID',
|
||||
},
|
||||
adGroupId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter by ad group ID',
|
||||
},
|
||||
dateRange: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Predefined date range (LAST_7_DAYS, LAST_30_DAYS, THIS_MONTH, LAST_MONTH, TODAY, YESTERDAY)',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom start date in YYYY-MM-DD format',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom end date in YYYY-MM-DD format',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of results to return',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const customerId = validateNumericId(params.customerId, 'customerId')
|
||||
return `https://googleads.googleapis.com/v24/customers/${customerId}/googleAds:search`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params) => {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'developer-token': params.developerToken,
|
||||
}
|
||||
if (params.managerCustomerId) {
|
||||
headers['login-customer-id'] = validateNumericId(
|
||||
params.managerCustomerId,
|
||||
'managerCustomerId'
|
||||
)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
body: (params) => {
|
||||
let query =
|
||||
'SELECT ad_group_ad.ad.id, ad_group.id, ad_group.name, campaign.id, campaign.name, ad_group_ad.ad.type, metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.ctr, metrics.conversions, segments.date FROM ad_group_ad'
|
||||
|
||||
const conditions: string[] = ["ad_group_ad.status != 'REMOVED'"]
|
||||
|
||||
if (params.campaignId) {
|
||||
conditions.push(`campaign.id = ${validateNumericId(params.campaignId, 'campaignId')}`)
|
||||
}
|
||||
|
||||
if (params.adGroupId) {
|
||||
conditions.push(`ad_group.id = ${validateNumericId(params.adGroupId, 'adGroupId')}`)
|
||||
}
|
||||
|
||||
if (params.startDate && params.endDate) {
|
||||
const start = validateDate(params.startDate, 'startDate')
|
||||
const end = validateDate(params.endDate, 'endDate')
|
||||
conditions.push(`segments.date BETWEEN '${start}' AND '${end}'`)
|
||||
} else {
|
||||
const dateRange = validateDateRange(params.dateRange || 'LAST_30_DAYS')
|
||||
conditions.push(`segments.date DURING ${dateRange}`)
|
||||
}
|
||||
|
||||
query += ` WHERE ${conditions.join(' AND ')}`
|
||||
query += ' ORDER BY metrics.impressions DESC'
|
||||
|
||||
if (params.limit) {
|
||||
query += ` LIMIT ${params.limit}`
|
||||
}
|
||||
|
||||
return { query }
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: { ads: [], totalCount: 0 },
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
const results = data.results ?? []
|
||||
const ads = results.map((r: Record<string, any>) => ({
|
||||
adId: r.adGroupAd?.ad?.id ?? '',
|
||||
adGroupId: r.adGroup?.id ?? '',
|
||||
adGroupName: r.adGroup?.name ?? null,
|
||||
campaignId: r.campaign?.id ?? '',
|
||||
campaignName: r.campaign?.name ?? null,
|
||||
adType: r.adGroupAd?.ad?.type ?? null,
|
||||
impressions: r.metrics?.impressions ?? '0',
|
||||
clicks: r.metrics?.clicks ?? '0',
|
||||
costMicros: r.metrics?.costMicros ?? '0',
|
||||
ctr: r.metrics?.ctr ?? null,
|
||||
conversions: r.metrics?.conversions ?? null,
|
||||
date: r.segments?.date ?? null,
|
||||
}))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
ads,
|
||||
totalCount: ads.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
ads: {
|
||||
type: 'array',
|
||||
description: 'Ad performance data broken down by date',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
adId: { type: 'string', description: 'Ad ID' },
|
||||
adGroupId: { type: 'string', description: 'Parent ad group ID' },
|
||||
adGroupName: { type: 'string', description: 'Parent ad group name' },
|
||||
campaignId: { type: 'string', description: 'Parent campaign ID' },
|
||||
campaignName: { type: 'string', description: 'Parent campaign name' },
|
||||
adType: {
|
||||
type: 'string',
|
||||
description: 'Ad type (RESPONSIVE_SEARCH_AD, EXPANDED_TEXT_AD, etc.)',
|
||||
},
|
||||
impressions: { type: 'string', description: 'Number of impressions' },
|
||||
clicks: { type: 'string', description: 'Number of clicks' },
|
||||
costMicros: {
|
||||
type: 'string',
|
||||
description: 'Cost in micros (divide by 1,000,000 for currency value)',
|
||||
},
|
||||
ctr: { type: 'number', description: 'Click-through rate (0.0 to 1.0)' },
|
||||
conversions: { type: 'number', description: 'Number of conversions' },
|
||||
date: { type: 'string', description: 'Date for this row (YYYY-MM-DD)' },
|
||||
},
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of result rows',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import type {
|
||||
GoogleAdsCampaignPerformanceParams,
|
||||
GoogleAdsCampaignPerformanceResponse,
|
||||
} from '@/tools/google_ads/types'
|
||||
import { validateDate, validateDateRange, validateNumericId } from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsCampaignPerformanceTool: ToolConfig<
|
||||
GoogleAdsCampaignPerformanceParams,
|
||||
GoogleAdsCampaignPerformanceResponse
|
||||
> = {
|
||||
id: 'google_ads_campaign_performance',
|
||||
name: 'Google Ads Campaign Performance',
|
||||
description: 'Get performance metrics for Google Ads campaigns over a date range',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
customerId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
managerCustomerId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Manager account customer ID (if accessing via manager account)',
|
||||
},
|
||||
campaignId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter by specific campaign ID',
|
||||
},
|
||||
dateRange: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Predefined date range (LAST_7_DAYS, LAST_30_DAYS, THIS_MONTH, LAST_MONTH, TODAY, YESTERDAY)',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom start date in YYYY-MM-DD format',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Custom end date in YYYY-MM-DD format',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const customerId = validateNumericId(params.customerId, 'customerId')
|
||||
return `https://googleads.googleapis.com/v24/customers/${customerId}/googleAds:search`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params) => {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'developer-token': params.developerToken,
|
||||
}
|
||||
if (params.managerCustomerId) {
|
||||
headers['login-customer-id'] = validateNumericId(
|
||||
params.managerCustomerId,
|
||||
'managerCustomerId'
|
||||
)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
body: (params) => {
|
||||
let query =
|
||||
'SELECT campaign.id, campaign.name, campaign.status, metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.ctr, metrics.conversions, segments.date FROM campaign'
|
||||
|
||||
const conditions: string[] = ["campaign.status != 'REMOVED'"]
|
||||
|
||||
if (params.campaignId) {
|
||||
conditions.push(`campaign.id = ${validateNumericId(params.campaignId, 'campaignId')}`)
|
||||
}
|
||||
|
||||
if (params.startDate && params.endDate) {
|
||||
const start = validateDate(params.startDate, 'startDate')
|
||||
const end = validateDate(params.endDate, 'endDate')
|
||||
conditions.push(`segments.date BETWEEN '${start}' AND '${end}'`)
|
||||
} else {
|
||||
const dateRange = validateDateRange(params.dateRange || 'LAST_30_DAYS')
|
||||
conditions.push(`segments.date DURING ${dateRange}`)
|
||||
}
|
||||
|
||||
query += ` WHERE ${conditions.join(' AND ')}`
|
||||
query += ' ORDER BY metrics.impressions DESC'
|
||||
|
||||
return { query }
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: { campaigns: [], totalCount: 0 },
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
const results = data.results ?? []
|
||||
const campaigns = results.map((r: Record<string, any>) => ({
|
||||
id: r.campaign?.id ?? '',
|
||||
name: r.campaign?.name ?? '',
|
||||
status: r.campaign?.status ?? '',
|
||||
impressions: r.metrics?.impressions ?? '0',
|
||||
clicks: r.metrics?.clicks ?? '0',
|
||||
costMicros: r.metrics?.costMicros ?? '0',
|
||||
ctr: r.metrics?.ctr ?? null,
|
||||
conversions: r.metrics?.conversions ?? null,
|
||||
date: r.segments?.date ?? null,
|
||||
}))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
campaigns,
|
||||
totalCount: campaigns.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
campaigns: {
|
||||
type: 'array',
|
||||
description: 'Campaign performance data broken down by date',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Campaign ID' },
|
||||
name: { type: 'string', description: 'Campaign name' },
|
||||
status: { type: 'string', description: 'Campaign status' },
|
||||
impressions: { type: 'string', description: 'Number of impressions' },
|
||||
clicks: { type: 'string', description: 'Number of clicks' },
|
||||
costMicros: {
|
||||
type: 'string',
|
||||
description: 'Cost in micros (divide by 1,000,000 for currency value)',
|
||||
},
|
||||
ctr: { type: 'number', description: 'Click-through rate (0.0 to 1.0)' },
|
||||
conversions: { type: 'number', description: 'Number of conversions' },
|
||||
date: { type: 'string', description: 'Date for this row (YYYY-MM-DD)' },
|
||||
},
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of result rows',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { googleAdsAdPerformanceTool } from '@/tools/google_ads/ad_performance'
|
||||
import { googleAdsCampaignPerformanceTool } from '@/tools/google_ads/campaign_performance'
|
||||
import { googleAdsListAdGroupsTool } from '@/tools/google_ads/list_ad_groups'
|
||||
import { googleAdsListCampaignsTool } from '@/tools/google_ads/list_campaigns'
|
||||
import { googleAdsListCustomersTool } from '@/tools/google_ads/list_customers'
|
||||
import { googleAdsSearchTool } from '@/tools/google_ads/search'
|
||||
|
||||
export {
|
||||
googleAdsAdPerformanceTool,
|
||||
googleAdsCampaignPerformanceTool,
|
||||
googleAdsListAdGroupsTool,
|
||||
googleAdsListCampaignsTool,
|
||||
googleAdsListCustomersTool,
|
||||
googleAdsSearchTool,
|
||||
}
|
||||
|
||||
export * from './types'
|
||||
@@ -0,0 +1,167 @@
|
||||
import type {
|
||||
GoogleAdsListAdGroupsParams,
|
||||
GoogleAdsListAdGroupsResponse,
|
||||
} from '@/tools/google_ads/types'
|
||||
import { validateNumericId, validateStatus } from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsListAdGroupsTool: ToolConfig<
|
||||
GoogleAdsListAdGroupsParams,
|
||||
GoogleAdsListAdGroupsResponse
|
||||
> = {
|
||||
id: 'google_ads_list_ad_groups',
|
||||
name: 'List Google Ads Ad Groups',
|
||||
description: 'List ad groups in a Google Ads campaign',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
customerId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
managerCustomerId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Manager account customer ID (if accessing via manager account)',
|
||||
},
|
||||
campaignId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Campaign ID to list ad groups for',
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter by ad group status (ENABLED, PAUSED, REMOVED)',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of ad groups to return',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const customerId = validateNumericId(params.customerId, 'customerId')
|
||||
return `https://googleads.googleapis.com/v24/customers/${customerId}/googleAds:search`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params) => {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'developer-token': params.developerToken,
|
||||
}
|
||||
if (params.managerCustomerId) {
|
||||
headers['login-customer-id'] = validateNumericId(
|
||||
params.managerCustomerId,
|
||||
'managerCustomerId'
|
||||
)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
body: (params) => {
|
||||
let query =
|
||||
'SELECT ad_group.id, ad_group.name, ad_group.status, ad_group.type, campaign.id, campaign.name FROM ad_group'
|
||||
|
||||
const campaignId = validateNumericId(params.campaignId, 'campaignId')
|
||||
const conditions: string[] = [`campaign.id = ${campaignId}`]
|
||||
|
||||
if (params.status) {
|
||||
conditions.push(`ad_group.status = '${validateStatus(params.status)}'`)
|
||||
} else {
|
||||
conditions.push("ad_group.status != 'REMOVED'")
|
||||
}
|
||||
|
||||
query += ` WHERE ${conditions.join(' AND ')}`
|
||||
query += ' ORDER BY ad_group.name'
|
||||
|
||||
if (params.limit) {
|
||||
query += ` LIMIT ${params.limit}`
|
||||
}
|
||||
|
||||
return { query }
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: { adGroups: [], totalCount: 0 },
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
const results = data.results ?? []
|
||||
const adGroups = results.map((r: Record<string, any>) => ({
|
||||
id: r.adGroup?.id ?? '',
|
||||
name: r.adGroup?.name ?? '',
|
||||
status: r.adGroup?.status ?? '',
|
||||
type: r.adGroup?.type ?? null,
|
||||
campaignId: r.campaign?.id ?? '',
|
||||
campaignName: r.campaign?.name ?? null,
|
||||
}))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
adGroups,
|
||||
totalCount: adGroups.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
adGroups: {
|
||||
type: 'array',
|
||||
description: 'List of ad groups in the campaign',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Ad group ID' },
|
||||
name: { type: 'string', description: 'Ad group name' },
|
||||
status: { type: 'string', description: 'Ad group status (ENABLED, PAUSED, REMOVED)' },
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Ad group type (SEARCH_STANDARD, DISPLAY_STANDARD, SHOPPING_PRODUCT_ADS)',
|
||||
},
|
||||
campaignId: { type: 'string', description: 'Parent campaign ID' },
|
||||
campaignName: { type: 'string', description: 'Parent campaign name' },
|
||||
},
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of ad groups returned',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import type {
|
||||
GoogleAdsListCampaignsParams,
|
||||
GoogleAdsListCampaignsResponse,
|
||||
} from '@/tools/google_ads/types'
|
||||
import { validateNumericId, validateStatus } from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsListCampaignsTool: ToolConfig<
|
||||
GoogleAdsListCampaignsParams,
|
||||
GoogleAdsListCampaignsResponse
|
||||
> = {
|
||||
id: 'google_ads_list_campaigns',
|
||||
name: 'List Google Ads Campaigns',
|
||||
description: 'List campaigns in a Google Ads account with optional status filtering',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
customerId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
managerCustomerId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Manager account customer ID (if accessing via manager account)',
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter by campaign status (ENABLED, PAUSED, REMOVED)',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of campaigns to return',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const customerId = validateNumericId(params.customerId, 'customerId')
|
||||
return `https://googleads.googleapis.com/v24/customers/${customerId}/googleAds:search`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params) => {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'developer-token': params.developerToken,
|
||||
}
|
||||
if (params.managerCustomerId) {
|
||||
headers['login-customer-id'] = validateNumericId(
|
||||
params.managerCustomerId,
|
||||
'managerCustomerId'
|
||||
)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
body: (params) => {
|
||||
let query =
|
||||
'SELECT campaign.id, campaign.name, campaign.status, campaign.advertising_channel_type, campaign.start_date, campaign.end_date, campaign_budget.amount_micros FROM campaign'
|
||||
|
||||
const conditions: string[] = []
|
||||
if (params.status) {
|
||||
conditions.push(`campaign.status = '${validateStatus(params.status)}'`)
|
||||
} else {
|
||||
conditions.push("campaign.status != 'REMOVED'")
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
query += ` WHERE ${conditions.join(' AND ')}`
|
||||
}
|
||||
|
||||
query += ' ORDER BY campaign.name'
|
||||
|
||||
if (params.limit) {
|
||||
query += ` LIMIT ${params.limit}`
|
||||
}
|
||||
|
||||
return { query }
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: { campaigns: [], totalCount: 0 },
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
const results = data.results ?? []
|
||||
const campaigns = results.map((r: Record<string, any>) => ({
|
||||
id: r.campaign?.id ?? '',
|
||||
name: r.campaign?.name ?? '',
|
||||
status: r.campaign?.status ?? '',
|
||||
channelType: r.campaign?.advertisingChannelType ?? null,
|
||||
startDate: r.campaign?.startDate ?? null,
|
||||
endDate: r.campaign?.endDate ?? null,
|
||||
budgetAmountMicros: r.campaignBudget?.amountMicros ?? null,
|
||||
}))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
campaigns,
|
||||
totalCount: campaigns.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
campaigns: {
|
||||
type: 'array',
|
||||
description: 'List of campaigns in the account',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'string', description: 'Campaign ID' },
|
||||
name: { type: 'string', description: 'Campaign name' },
|
||||
status: { type: 'string', description: 'Campaign status (ENABLED, PAUSED, REMOVED)' },
|
||||
channelType: {
|
||||
type: 'string',
|
||||
description:
|
||||
'Advertising channel type (SEARCH, DISPLAY, SHOPPING, VIDEO, PERFORMANCE_MAX)',
|
||||
},
|
||||
startDate: { type: 'string', description: 'Campaign start date (YYYY-MM-DD)' },
|
||||
endDate: { type: 'string', description: 'Campaign end date (YYYY-MM-DD)' },
|
||||
budgetAmountMicros: {
|
||||
type: 'string',
|
||||
description: 'Daily budget in micros (divide by 1,000,000 for currency value)',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of campaigns returned',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import type {
|
||||
GoogleAdsListCustomersParams,
|
||||
GoogleAdsListCustomersResponse,
|
||||
} from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsListCustomersTool: ToolConfig<
|
||||
GoogleAdsListCustomersParams,
|
||||
GoogleAdsListCustomersResponse
|
||||
> = {
|
||||
id: 'google_ads_list_customers',
|
||||
name: 'List Google Ads Customers',
|
||||
description: 'List all Google Ads customer accounts accessible by the authenticated user',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: 'https://googleads.googleapis.com/v24/customers:listAccessibleCustomers',
|
||||
method: 'GET',
|
||||
headers: (params) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'developer-token': params.developerToken,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: { customerIds: [], totalCount: 0 },
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
const resourceNames: string[] = data.resourceNames ?? []
|
||||
const customerIds = resourceNames.map((rn: string) => rn.replace('customers/', ''))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
customerIds,
|
||||
totalCount: customerIds.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
customerIds: {
|
||||
type: 'array',
|
||||
description: 'List of accessible customer IDs',
|
||||
items: {
|
||||
type: 'string',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of accessible customer accounts',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import type { GoogleAdsSearchParams, GoogleAdsSearchResponse } from '@/tools/google_ads/types'
|
||||
import { validateNumericId } from '@/tools/google_ads/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const googleAdsSearchTool: ToolConfig<GoogleAdsSearchParams, GoogleAdsSearchResponse> = {
|
||||
id: 'google_ads_search',
|
||||
name: 'Google Ads Search (GAQL)',
|
||||
description: 'Run a custom Google Ads Query Language (GAQL) query',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-ads',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'OAuth access token for the Google Ads API',
|
||||
},
|
||||
customerId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Google Ads customer ID (numeric, no dashes)',
|
||||
},
|
||||
developerToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Google Ads API developer token',
|
||||
},
|
||||
managerCustomerId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Manager account customer ID (if accessing via manager account)',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'GAQL query to execute',
|
||||
},
|
||||
pageToken: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Page token for pagination',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const customerId = validateNumericId(params.customerId, 'customerId')
|
||||
return `https://googleads.googleapis.com/v24/customers/${customerId}/googleAds:search`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params) => {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'developer-token': params.developerToken,
|
||||
}
|
||||
if (params.managerCustomerId) {
|
||||
headers['login-customer-id'] = validateNumericId(
|
||||
params.managerCustomerId,
|
||||
'managerCustomerId'
|
||||
)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
query: params.query,
|
||||
searchSettings: {
|
||||
returnTotalResultsCount: true,
|
||||
},
|
||||
}
|
||||
if (params.pageToken) {
|
||||
body.pageToken = params.pageToken
|
||||
}
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage =
|
||||
data?.error?.message ?? data?.error?.details?.[0]?.errors?.[0]?.message ?? 'Unknown error'
|
||||
return {
|
||||
success: false,
|
||||
output: {
|
||||
results: [],
|
||||
totalResultsCount: null,
|
||||
nextPageToken: null,
|
||||
},
|
||||
error: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
results: data.results ?? [],
|
||||
totalResultsCount: data.totalResultsCount ? Number(data.totalResultsCount) : null,
|
||||
nextPageToken: data.nextPageToken ?? null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
results: {
|
||||
type: 'json',
|
||||
description: 'Array of result objects from the GAQL query',
|
||||
},
|
||||
totalResultsCount: {
|
||||
type: 'number',
|
||||
description: 'Total number of matching results',
|
||||
},
|
||||
nextPageToken: {
|
||||
type: 'string',
|
||||
description: 'Token for the next page of results',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import type { ToolResponse } from '@/tools/types'
|
||||
|
||||
const NUMERIC_ID_REGEX = /^\d+$/
|
||||
const DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/
|
||||
const VALID_STATUSES = new Set(['ENABLED', 'PAUSED', 'REMOVED'])
|
||||
const VALID_DATE_RANGES = new Set([
|
||||
'TODAY',
|
||||
'YESTERDAY',
|
||||
'LAST_7_DAYS',
|
||||
'LAST_14_DAYS',
|
||||
'LAST_30_DAYS',
|
||||
'LAST_BUSINESS_WEEK',
|
||||
'THIS_MONTH',
|
||||
'LAST_MONTH',
|
||||
'THIS_WEEK_SUN_TODAY',
|
||||
'THIS_WEEK_MON_TODAY',
|
||||
'LAST_WEEK_SUN_SAT',
|
||||
'LAST_WEEK_MON_SUN',
|
||||
])
|
||||
|
||||
/** Validates that a value is a numeric ID (digits only). */
|
||||
export function validateNumericId(value: string, fieldName: string): string {
|
||||
const cleaned = value.replace(/-/g, '')
|
||||
if (!NUMERIC_ID_REGEX.test(cleaned)) {
|
||||
throw new Error(`${fieldName} must be numeric (digits only), got: ${value}`)
|
||||
}
|
||||
return cleaned
|
||||
}
|
||||
|
||||
/** Validates that a status value is a known Google Ads status. */
|
||||
export function validateStatus(value: string): string {
|
||||
if (!VALID_STATUSES.has(value)) {
|
||||
throw new Error(`Invalid status: ${value}. Must be one of: ${[...VALID_STATUSES].join(', ')}`)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/** Validates a date string is in YYYY-MM-DD format. */
|
||||
export function validateDate(value: string, fieldName: string): string {
|
||||
if (!DATE_REGEX.test(value)) {
|
||||
throw new Error(`${fieldName} must be in YYYY-MM-DD format, got: ${value}`)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/** Validates a date range is a known Google Ads predefined range. */
|
||||
export function validateDateRange(value: string): string {
|
||||
if (!VALID_DATE_RANGES.has(value)) {
|
||||
throw new Error(
|
||||
`Invalid date range: ${value}. Must be one of: ${[...VALID_DATE_RANGES].join(', ')}`
|
||||
)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
interface GoogleAdsBaseParams {
|
||||
accessToken: string
|
||||
customerId: string
|
||||
developerToken: string
|
||||
managerCustomerId?: string
|
||||
}
|
||||
|
||||
export interface GoogleAdsListCustomersParams {
|
||||
accessToken: string
|
||||
developerToken: string
|
||||
}
|
||||
|
||||
export interface GoogleAdsSearchParams extends GoogleAdsBaseParams {
|
||||
query: string
|
||||
pageToken?: string
|
||||
}
|
||||
|
||||
export interface GoogleAdsListCampaignsParams extends GoogleAdsBaseParams {
|
||||
status?: string
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export interface GoogleAdsCampaignPerformanceParams extends GoogleAdsBaseParams {
|
||||
campaignId?: string
|
||||
dateRange?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
}
|
||||
|
||||
export interface GoogleAdsListAdGroupsParams extends GoogleAdsBaseParams {
|
||||
campaignId: string
|
||||
status?: string
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export interface GoogleAdsAdPerformanceParams extends GoogleAdsBaseParams {
|
||||
campaignId?: string
|
||||
adGroupId?: string
|
||||
dateRange?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export interface GoogleAdsListCustomersResponse extends ToolResponse {
|
||||
output: {
|
||||
customerIds: string[]
|
||||
totalCount: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleAdsSearchResponse extends ToolResponse {
|
||||
output: {
|
||||
results: Record<string, unknown>[]
|
||||
totalResultsCount: number | null
|
||||
nextPageToken: string | null
|
||||
}
|
||||
}
|
||||
|
||||
interface GoogleAdsCampaign {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
channelType: string | null
|
||||
startDate: string | null
|
||||
endDate: string | null
|
||||
budgetAmountMicros: string | null
|
||||
}
|
||||
|
||||
export interface GoogleAdsListCampaignsResponse extends ToolResponse {
|
||||
output: {
|
||||
campaigns: GoogleAdsCampaign[]
|
||||
totalCount: number
|
||||
}
|
||||
}
|
||||
|
||||
interface GoogleAdsCampaignPerformance {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
impressions: string
|
||||
clicks: string
|
||||
costMicros: string
|
||||
ctr: number | null
|
||||
conversions: number | null
|
||||
date: string | null
|
||||
}
|
||||
|
||||
export interface GoogleAdsCampaignPerformanceResponse extends ToolResponse {
|
||||
output: {
|
||||
campaigns: GoogleAdsCampaignPerformance[]
|
||||
totalCount: number
|
||||
}
|
||||
}
|
||||
|
||||
interface GoogleAdsAdGroup {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
type: string | null
|
||||
campaignId: string
|
||||
campaignName: string | null
|
||||
}
|
||||
|
||||
export interface GoogleAdsListAdGroupsResponse extends ToolResponse {
|
||||
output: {
|
||||
adGroups: GoogleAdsAdGroup[]
|
||||
totalCount: number
|
||||
}
|
||||
}
|
||||
|
||||
interface GoogleAdsAdPerformance {
|
||||
adId: string
|
||||
adGroupId: string
|
||||
adGroupName: string | null
|
||||
campaignId: string
|
||||
campaignName: string | null
|
||||
adType: string | null
|
||||
impressions: string
|
||||
clicks: string
|
||||
costMicros: string
|
||||
ctr: number | null
|
||||
conversions: number | null
|
||||
date: string | null
|
||||
}
|
||||
|
||||
export interface GoogleAdsAdPerformanceResponse extends ToolResponse {
|
||||
output: {
|
||||
ads: GoogleAdsAdPerformance[]
|
||||
totalCount: number
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user